#!/usr/bin/env bash set -e # Omni/Agent/start-worker.sh # Launches an Amp worker agent in the specified worktree in a loop. # Usage: ./Omni/Agent/start-worker.sh [worker-directory-name-or-path] # Example: ./Omni/Agent/start-worker.sh omni-worker-1 TARGET="${1:-omni-worker-1}" # 1. Find the Main Repo (where node_modules lives) # The first worktree listed is always the main one MAIN_REPO="$(git worktree list --porcelain | grep '^worktree ' | head -n 1 | cut -d ' ' -f 2)" AMP_BIN="$MAIN_REPO/node_modules/.bin/amp" # 2. Resolve Worker Path # If TARGET is a directory, use it. Otherwise assume it's a sibling of MAIN_REPO. if [ -d "$TARGET" ]; then WORKER_PATH="$(realpath "$TARGET")" elif [ -d "$MAIN_REPO/../$TARGET" ]; then WORKER_PATH="$(realpath "$MAIN_REPO/../$TARGET")" else echo "Error: Worker directory for '$TARGET' not found." exit 1 fi if [ ! -x "$AMP_BIN" ]; then echo "Error: Amp binary not found at '$AMP_BIN'." echo "Please ensure npm dependencies are installed in the main repository." exit 1 fi echo "Starting Worker Agent Loop" echo " Worker Path: $WORKER_PATH" echo " Amp Binary: $AMP_BIN" echo " Log File: $WORKER_PATH/_/llm/amp.log" echo " Monitor: tail -f $WORKER_PATH/_/llm/amp.log" echo " Press Ctrl+C to stop." cd "$WORKER_PATH" # 3. The Worker Loop while true; do echo "----------------------------------------------------------------" echo "$(date): Starting new agent session..." mkdir -p _/llm "$AMP_BIN" --log-file "_/llm/amp.log" --dangerously-allow-all -x "You are a Worker Agent. Your goal is to process tasks from the task manager. Step 1: Read 'Omni/Agent/WORKER_AGENT_GUIDE.md' to understand your workflow. Step 2: Follow the 'Worker Loop' instructions exactly. Start by syncing tasks and checking for ready work. If no work is ready, exit." EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then echo "Agent exited with error code $EXIT_CODE. Sleeping for 10s..." sleep 10 else echo "Agent session finished. Sleeping for 5s..." sleep 5 fi done