#!/bin/bash # Agent Context Protocol (ACP) Update Script # This script updates AGENT.md, template files, and utility scripts from the repository # Self-relocation guard: this script overwrites itself during the update # (it copies the latest version from the repo to agent/scripts/). Bash reads # files lazily by byte offset, so the overwrite garbles execution. Fix: re-exec # from a temp copy so the file on disk can safely change. if [ -z "$_ACP_UPDATE_RELOCATED" ]; then _tmp_copy=$(mktemp) cp "$0" "$_tmp_copy" export _ACP_UPDATE_RELOCATED=1 bash "$_tmp_copy" "$@" _rc=$? rm -f "$_tmp_copy" exit $_rc fi set -e # Colors for output using tput (more reliable than ANSI codes) if command -v tput >/dev/null 2>&1 && [ -t 1 ]; then RED=$(tput setaf 1) GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) BLUE=$(tput setaf 4) BOLD=$(tput bold) NC=$(tput sgr0) else RED='' GREEN='' YELLOW='' BLUE='' BOLD='' NC='' fi # Repository details REPO_URL="https://github.com/prmichaelsen/agent-context-protocol.git" BRANCH="mainline" echo "${BLUE}Agent Context Protocol (ACP) Updater${NC}" echo "======================================" echo "" # Check if AGENT.md exists if [ ! -f "AGENT.md" ]; then echo "${RED}Error: AGENT.md not found in current directory${NC}" echo "This script should be run from your project root where AGENT.md is located." exit 1 fi # Create temporary directory TEMP_DIR=$(mktemp -d) trap "rm -rf $TEMP_DIR" EXIT echo "Fetching latest ACP files..." if ! git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$TEMP_DIR" &>/dev/null; then echo "${RED}Error: Failed to fetch repository${NC}" echo "Please check your internet connection and try again." exit 1 fi echo "${GREEN}✓${NC} Latest files fetched" echo "" # Ensure reports directory exists and is ignored mkdir -p "agent/reports" if [ ! -f "agent/.gitignore" ]; then echo "Creating agent/.gitignore..." cat > "agent/.gitignore" << 'EOF' # Agent Context Protocol - Local Files # These files are generated locally and should not be committed # Reports directory - generated by @acp.report command reports/ clarifications/ feedback/ drafts/ preferences/ EOF echo "${GREEN}✓${NC} Created agent/.gitignore" fi echo "Updating ACP files..." # Update template files (only .template.md files from these directories) find "$TEMP_DIR/agent/design" -maxdepth 1 -name "*.template.md" -exec cp {} "agent/design/" \; find "$TEMP_DIR/agent/milestones" -maxdepth 1 -name "*.template.md" -exec cp {} "agent/milestones/" \; find "$TEMP_DIR/agent/patterns" -maxdepth 1 -name "*.template.md" -exec cp {} "agent/patterns/" \; find "$TEMP_DIR/agent/tasks" -maxdepth 1 -name "*.template.md" -exec cp {} "agent/tasks/" \; # Update command template mkdir -p "agent/commands" cp "$TEMP_DIR/agent/commands/command.template.md" "agent/commands/" # Update all command files (flat structure with dot notation) # Copies files like acp.init.md, acp.status.md, deploy.production.md, etc. if [ -d "$TEMP_DIR/agent/commands" ]; then find "$TEMP_DIR/agent/commands" -maxdepth 1 -name "*.*.md" -exec cp {} "agent/commands/" \; fi # Update progress template cp "$TEMP_DIR/agent/progress.template.yaml" "agent/" # Update manifest template if [ -f "$TEMP_DIR/agent/manifest.template.yaml" ]; then cp "$TEMP_DIR/agent/manifest.template.yaml" "agent/" fi # Update package template if [ -f "$TEMP_DIR/agent/package.template.yaml" ]; then cp "$TEMP_DIR/agent/package.template.yaml" "agent/" fi # Update AGENT.md cp "$TEMP_DIR/AGENT.md" "." # Update all scripts (*.sh files) # This ensures all current and future scripts are copied if [ -d "$TEMP_DIR/agent/scripts" ]; then find "$TEMP_DIR/agent/scripts" -maxdepth 1 -name "*.sh" -exec cp {} "agent/scripts/" \; chmod +x agent/scripts/*.sh fi # Clean up deprecated scripts (from versions < 2.0.0) . "agent/scripts/acp.common.sh" init_colors cleanup_deprecated_scripts echo "${GREEN}✓${NC} All files updated" echo "" # Update acp-core version in manifest if it exists if [ -f "agent/manifest.yaml" ]; then echo "Updating manifest..." # Get new ACP version NEW_VERSION=$(grep "^\*\*Version\*\*:" "AGENT.md" | sed 's/.*: //' | head -1) UPDATE_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # Update acp-core version and timestamps _sed_i "/^ acp-core:/,/^ [a-z]/ { s/package_version: .*/package_version: ${NEW_VERSION}/ s/updated_at: .*/updated_at: ${UPDATE_DATE}/ }" agent/manifest.yaml # Update manifest timestamp _sed_i "s/^last_updated: .*/last_updated: ${UPDATE_DATE}/" agent/manifest.yaml echo "${GREEN}✓${NC} Updated acp-core to v${NEW_VERSION} in manifest.yaml" echo "" fi echo "${GREEN}Update complete!${NC}" echo "" echo "${BLUE}What was updated:${NC}" echo " ✓ AGENT.md (methodology documentation)" echo " ✓ Template files (design, milestone, task, pattern)" echo " ✓ Command files (all ACP commands)" echo " ✓ Utility scripts (update, check-for-updates, version, etc.)" echo "" echo "${BLUE}Next steps:${NC}" echo "1. Review changes: git diff" echo "2. See what changed: git status" echo "3. Revert if needed: git checkout " echo "" echo "For detailed changelog:" echo " https://github.com/prmichaelsen/agent-context-protocol/blob/mainline/CHANGELOG.md" echo "" display_available_commands echo "" echo "${BLUE}For AI agents:${NC}" echo "Type '${GREEN}@acp.init${NC}' to reload context with updated files." echo ""