summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-11-20 16:35:01 -0500
committerBen Sima <ben@bsima.me>2025-11-20 16:35:01 -0500
commit93731a88d859280bd048808794c92575dce84734 (patch)
tree598955d7278c737eaee737f71215335656852ef1 /Omni
parentacbe2a0bf8de038556beb33701129fb3ca4580df (diff)
fix: improve start-worker.sh script
- Use 'git worktree list' to reliably find main repo and amp binary - Run amp in a loop with -x flag for autonomous execution - Support flexible worker path resolution
Diffstat (limited to 'Omni')
-rwxr-xr-xOmni/Agent/start-worker.sh57
1 files changed, 42 insertions, 15 deletions
diff --git a/Omni/Agent/start-worker.sh b/Omni/Agent/start-worker.sh
index 2c5eee4..ce01004 100755
--- a/Omni/Agent/start-worker.sh
+++ b/Omni/Agent/start-worker.sh
@@ -2,18 +2,25 @@
set -e
# Omni/Agent/start-worker.sh
-# Launches an Amp worker agent in the specified worktree.
-# Usage: ./Omni/Agent/start-worker.sh [worker-directory-name]
+# 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
-WORKER_NAME="${1:-omni-worker-1}"
-REPO_ROOT="$(git rev-parse --show-toplevel)"
-WORKER_PATH="$REPO_ROOT/../$WORKER_NAME"
-AMP_BIN="$REPO_ROOT/node_modules/.bin/amp"
+TARGET="${1:-omni-worker-1}"
-if [ ! -d "$WORKER_PATH" ]; then
- echo "Error: Worker directory '$WORKER_PATH' does not exist."
- echo "Please run './Omni/Agent/setup-worker.sh $WORKER_NAME' first."
+# 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
@@ -23,12 +30,32 @@ if [ ! -x "$AMP_BIN" ]; then
exit 1
fi
-echo "Starting Worker Agent in '$WORKER_PATH'..."
-echo "Using Amp binary: $AMP_BIN"
+echo "Starting Worker Agent Loop"
+echo " Worker Path: $WORKER_PATH"
+echo " Amp Binary: $AMP_BIN"
+echo " Press Ctrl+C to stop."
cd "$WORKER_PATH"
-# Launch Amp with the worker persona and instructions
-"$AMP_BIN" -- "You are a Worker Agent. Your goal is to process tasks from the task manager.
-Please read Omni/Agent/WORKER_AGENT_GUIDE.md and follow the 'Worker Loop' instructions exactly.
-Start by syncing tasks and checking for ready work."
+# 3. The Worker Loop
+while true; do
+ echo "----------------------------------------------------------------"
+ echo "$(date): Starting new agent session..."
+
+ "$AMP_BIN" -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