summaryrefslogtreecommitdiff
path: root/Omni/Agent/start-worker.sh
blob: 457c83c7cd766135bab3442bee12e67567c8ad64 (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
64
65
66
67
68
69
#!/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 "Syncing worker repo..."
if ! (cd "$WORKER_PATH" && git sync); then
    echo "Error: Failed to run 'git sync' in worker directory."
    exit 1
fi

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"