diff options
Diffstat (limited to 'Omni/Agent/start-worker.sh')
| -rwxr-xr-x | Omni/Agent/start-worker.sh | 171 |
1 files changed, 22 insertions, 149 deletions
diff --git a/Omni/Agent/start-worker.sh b/Omni/Agent/start-worker.sh index ad519a0..310ca56 100755 --- a/Omni/Agent/start-worker.sh +++ b/Omni/Agent/start-worker.sh @@ -34,157 +34,30 @@ if [ ! -x "$TASK_BIN" ]; then echo "Warning: Task binary not found at '$TASK_BIN'. Assuming it's in path or build it first." 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." - -# Function to sync tasks safely -sync_tasks() { - "$MAIN_REPO/Omni/Agent/sync-tasks.sh" "$@" -} +# Ensure worker has local task and agent binaries +mkdir -p "$WORKER_PATH/_/bin" -cd "$WORKER_PATH" - -# 3. The Worker Loop -while true; do - echo "----------------------------------------------------------------" - echo "$(date): Syncing and checking for work..." - - # A. Sync with Live - # We use 'git rebase' to keep history linear - # Force checkout to clean up any untracked files from previous runs - git checkout -f omni-worker-1 >/dev/null 2>&1 - - # Rebase directly on local live branch (shared repo) - if ! git rebase live >/dev/null 2>&1; then - echo "Warning: Rebase conflict at start of loop. Aborting rebase and proceeding with local state." - git rebase --abort || true - fi - - # B. Sync Tasks - sync_tasks - - # C. Find Ready Work - # We use jq to parse the first task - # Note: task ready --json returns an array [...] - TASK_JSON=$("$TASK_BIN" ready --json 2>/dev/null | jq -r '.[0] // empty') - - if [ -z "$TASK_JSON" ]; then - echo "$(date): No ready tasks. Sleeping for 60s..." - sleep 60 - continue - fi - - TASK_ID=$(echo "$TASK_JSON" | jq -r '.taskId') - TASK_TITLE=$(echo "$TASK_JSON" | jq -r '.taskTitle') - TASK_NS=$(echo "$TASK_JSON" | jq -r '.taskNamespace // "root"') - - # Verify against live state to prevent re-claiming completed work - # (This handles cases where local 'InProgress' timestamp > live 'Review' timestamp due to retries) - git show live:.tasks/tasks.jsonl > .tasks/temp-live-tasks.jsonl 2>/dev/null - LIVE_TASK=$(grep "\"taskId\":\"$TASK_ID\"" .tasks/temp-live-tasks.jsonl || true) - LIVE_STATUS=$(echo "$LIVE_TASK" | jq -r '.taskStatus // empty') - rm -f .tasks/temp-live-tasks.jsonl - - if [[ "$LIVE_STATUS" == "Review" ]] || [[ "$LIVE_STATUS" == "Done" ]]; then - echo "Task $TASK_ID is already $LIVE_STATUS in live. Skipping and updating local state." - # Force update local DB to match live for this task - # We can't easily use 'task update' because it updates timestamp. - # Instead, we just rely on the loop continuing and hopefully 'task import' eventually winning - # if we stop touching it. Or we could force import again. - sleep 60 - continue - fi - - echo "$(date): Claiming task $TASK_ID: $TASK_TITLE" - - # D. Claim Task - "$TASK_BIN" update "$TASK_ID" in-progress >/dev/null - sync_tasks --commit >/dev/null - - # E. Prepare Branch - BRANCH_NAME="task/$TASK_ID" - if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then - echo "Resuming existing branch $BRANCH_NAME" - # Force checkout to overwrite untracked files (like .tasks/counters.jsonl) - # that may have been generated by sync tools but are tracked in the branch. - git checkout -f "$BRANCH_NAME" >/dev/null - else - echo "Creating new branch $BRANCH_NAME" - git checkout -b "$BRANCH_NAME" >/dev/null - fi - - # F. Execute Agent - echo "Launching Amp to implement task..." - - TASK_DETAILS=$("$TASK_BIN" show "$TASK_ID") - - # We construct a specific prompt for the agent - PROMPT="You are a Worker Agent. -Your goal is to implement the following task: +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 -$TASK_DETAILS +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 -INSTRUCTIONS: -1. Analyze the codebase (use finder/Grep) to understand where to make changes. -2. Implement the changes by editing files. -3. Run tests to verify your work (e.g., 'bild --test Omni/Namespace'). -4. Fix any errors found during testing. -5. Do NOT update the task status or manage git branches (the system handles that). -6. When finished and tested, exit. +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." -Context: -- You are working in '$WORKER_PATH'. -- The task is in namespace '$TASK_NS'. -" +# Add amp to PATH so the agent can find it +export PATH="$MAIN_REPO/node_modules/.bin:$PATH" - mkdir -p _/llm - "$AMP_BIN" --log-level debug --log-file "_/llm/amp.log" --dangerously-allow-all -x "$PROMPT" - - AGENT_EXIT_CODE=$? - - if [ $AGENT_EXIT_CODE -eq 0 ]; then - echo "Agent finished successfully." - - # G. Submit Work - if [ -n "$(git status --porcelain)" ]; then - echo "Committing changes..." - git add . - git commit -m "feat: implement $TASK_ID" || true - else - echo "No changes to commit." - fi - - echo "Submitting for review..." - # Switch back to base - git checkout omni-worker-1 >/dev/null - - # Sync again (rebase on latest live) - # If rebase fails, we MUST abort to avoid leaving the repo in a broken state - if ! git rebase live >/dev/null 2>&1; then - echo "Warning: Rebase conflict. Aborting rebase and proceeding with local state." - git rebase --abort || true - fi - - sync_tasks - - # Update status - echo "Marking task $TASK_ID as Review..." - if "$TASK_BIN" update "$TASK_ID" review; then - sync_tasks --commit >/dev/null - echo "Task $TASK_ID submitted for review." - else - echo "Error: Failed to update task status to Review." - fi - - else - echo "Agent failed (exit code $AGENT_EXIT_CODE). Sleeping for 10s before retrying..." - sleep 10 - fi - - echo "Cooldown..." - sleep 5 -done +# Run the agent +"$WORKER_PATH/_/bin/agent" start "$TARGET" --path "$WORKER_PATH" |
