#!/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" TASK_BIN="$MAIN_REPO/_/bin/task" # 2. Resolve Worker Path 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'." exit 1 fi # Ensure task binary is built/available if [ ! -x "$TASK_BIN" ]; then echo "Warning: Task binary not found at '$TASK_BIN'. Assuming it's in path or build it first." fi # Ensure worker has local task and agent binaries mkdir -p "$WORKER_PATH/_/bin" echo "Building 'task' in worker..." if ! (cd "$WORKER_PATH" && bild Omni/Task.hs); then echo "Error: Failed to build 'task' in worker directory." exit 1 fi echo "Building 'agent' in worker..." if ! (cd "$WORKER_PATH" && bild Omni/Agent.hs); then echo "Error: Failed to build 'agent' in worker directory." exit 1 fi echo "Starting Worker Agent (Haskell)" echo " Worker Path: $WORKER_PATH" echo " Agent Bin: $WORKER_PATH/_/bin/agent" echo " Log File: $WORKER_PATH/_/llm/amp.log" echo " Monitor: ./Omni/Agent/monitor.sh $TARGET" echo " Press Ctrl+C to stop." # Add amp to PATH so the agent can find it export PATH="$MAIN_REPO/node_modules/.bin:$PATH" # Run the agent "$WORKER_PATH/_/bin/agent" start "$TARGET" --path "$WORKER_PATH"