| 1 | |
| 2 | set -uo pipefail |
| 3 | PM="/shared/projects/zion-pm" |
| 4 | source "$PM/env.sh" |
| 5 | |
| 6 | TASK_ID="${1:?task-id required}" |
| 7 | TYPE="${2:?type required}" |
| 8 | SCOPE="${3:?scoped prompt required}" |
| 9 | MODEL_OVERRIDE="${4:-}" |
| 10 | |
| 11 | case "$TYPE" in |
| 12 | research|misc) WORKER_MODEL="${MODEL_OVERRIDE:-$ANTHROPIC_MODEL}";; |
| 13 | code|outreach|browser|ops) WORKER_MODEL="${MODEL_OVERRIDE:-$ANTHROPIC_MODEL}";; |
| 14 | *) WORKER_MODEL="${MODEL_OVERRIDE:-$ANTHROPIC_MODEL}";; |
| 15 | esac |
| 16 | |
| 17 | WDIR="$PM/workers/$TASK_ID" |
| 18 | mkdir -p "$WDIR" |
| 19 | |
| 20 | read -r -d '' CONTRACT <<EOF |
| 21 | You are a Zion-PM worker. Task id: $TASK_ID. Type: $TYPE. |
| 22 | |
| 23 | SCOPE (do exactly this, nothing more): |
| 24 | $SCOPE |
| 25 | |
| 26 | Rules: |
| 27 | - RAG-first: call homelab_context before opening broad files; for code structure use cbm-homelab; |
| 28 | for symbol-level edits use Serena. Do not sweep whole trees. |
| 29 | - Do reversible, internal work directly: read, research, scrape, write/edit code, run tests/builds. |
| 30 | - OUTWARD actions are FORBIDDEN here. Do NOT send email/DM, push to public repos, publish, deploy, |
| 31 | contact any human, or mutate infra. Instead queue a fully-previewed draft: |
| 32 | bash $PM/bin/outbox-add.sh "$TASK_ID" "<kind>" "<full preview: recipient/target + content>" |
| 33 | - Never print or transmit secrets or client PII to any non-local model. |
| 34 | |
| 35 | When done, write your result as JSON to $WDIR/result.json with EXACTLY these keys: |
| 36 | {"task":"$TASK_ID","summary":"...","artifacts":["paths/urls"],"tests":"...", |
| 37 | "blockers":"...","next_action":"...","queued_outbox":["ids if any"]} |
| 38 | Output nothing else of consequence. Be terse and frugal - metered brain. |
| 39 | EOF |
| 40 | |
| 41 | ( |
| 42 | cd "$PM" |
| 43 | ANTHROPIC_MODEL="$WORKER_MODEL" claude -p \ |
| 44 | --dangerously-skip-permissions \ |
| 45 | "$CONTRACT" >"$WDIR/worker.out" 2>"$WDIR/worker.err" |
| 46 | if [ ! -f "$WDIR/result.json" ]; then |
| 47 | printf '{"task":"%s","summary":"worker produced no result.json","artifacts":[],"tests":"","blockers":"see worker.err","next_action":"retry or escalate","queued_outbox":[]}\n' "$TASK_ID" > "$WDIR/result.json" |
| 48 | fi |
| 49 | ) & |
| 50 | |
| 51 | echo "[pm] spawned worker $TASK_ID (type=$TYPE model=$WORKER_MODEL pid=$!)" |