summaryrefslogtreecommitdiff
path: root/Omni/Agent/start-worker.sh
blob: bf5eef3edcc35e74d53c18e51fba10870360bda9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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/amp.log"
echo "  Monitor:     tail -f $WORKER_PATH/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..."
    
    "$AMP_BIN" --log-file "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