@@ -198,22 +198,19 @@ git fetch origin
198198git worktree add ~ /workspace/worktrees/$BRANCH -b $BRANCH origin/main
199199
200200# 2. Launch the agent IN the worktree
201- mkdir -p ~ /.pi/agent/logs
202- nohup bash -lc " cd ~/workspace/worktrees/$BRANCH && \
203- export PATH=\$ HOME/.varlock/bin:\$ HOME/opt/node-v22.14.0-linux-x64/bin:\$ PATH && \
204- export PI_SESSION_NAME=$SESSION_NAME && \
205- exec varlock run --path ~/.config/ -- pi --session-control --skill ~/.pi/agent/skills/dev-agent --model <MODEL_FROM_TABLE_ABOVE>" \
206- > ~ /.pi/agent/logs/$SESSION_NAME .log 2>&1 &
207- DEV_PID=$!
208- echo $DEV_PID > ~ /.pi/agent/$SESSION_NAME .pid
201+ tmux new-session -d -s $SESSION_NAME \
202+ " cd ~/workspace/worktrees/$BRANCH && \
203+ export PATH=\$ HOME/.varlock/bin:\$ HOME/opt/node-v22.14.0-linux-x64/bin:\$ PATH && \
204+ export PI_SESSION_NAME=$SESSION_NAME && \
205+ exec varlock run --path ~/.config/ -- pi --session-control --skill ~/.pi/agent/skills/dev-agent --model <MODEL_FROM_TABLE_ABOVE>"
209206```
210207
211208** Important notes:**
212209- ` cd ` into the worktree BEFORE launching pi — this ensures pi discovers project context from the repo's CWD
210+ - Use ` exec ` so the tmux session exits when pi exits
213211- Use ` varlock run --path ~/.config/ ` to validate and inject env vars
214212- Set ` PI_SESSION_NAME ` so the auto-name extension registers it
215213- Include ` --session-control ` for ` send_to_session ` / ` list_sessions `
216- - Read logs with ` tail -f ~/.pi/agent/logs/$SESSION_NAME.log `
217214- Wait ** ~ 10 seconds** after spawning before sending messages (agent needs time to initialize)
218215- Do NOT use ` --name ` (not a real pi CLI flag)
219216
@@ -228,13 +225,8 @@ SESSION_NAME=dev-agent-myapp-a8b7b331
228225REPO=myapp
229226BRANCH=fix/some-descriptive-name
230227
231- # 1. Kill the process if still running
232- PID_FILE=~ /.pi/agent/$SESSION_NAME .pid
233- if [ -f " $PID_FILE " ]; then
234- PID=$( cat " $PID_FILE " 2> /dev/null || true)
235- [ -n " $PID " ] && kill " $PID " 2> /dev/null || true
236- rm -f " $PID_FILE "
237- fi
228+ # 1. Kill the tmux session (agent should have already exited, but ensure it)
229+ tmux kill-session -t $SESSION_NAME 2> /dev/null || true
238230
239231# 2. Remove the worktree
240232cd ~ /workspace/$REPO
@@ -317,10 +309,10 @@ This removes stale `.sock` files, cleans dead aliases, and restarts the Slack br
317309- [ ] Find or create sentry-agent:
318310 1 . Use ` list_sessions ` to look for a session named ` sentry-agent `
319311 2 . If found, use that session
320- 3 . If not found, launch as a normal background process (see Sentry Agent section)
312+ 3 . If not found, launch with tmux (see Sentry Agent section)
321313 4 . Wait ~ 8 seconds, then send role assignment
322314- [ ] Send role assignment to the ` sentry-agent ` session
323- - [ ] Clean up any stale dev-agent worktrees/background processes from previous runs
315+ - [ ] Clean up any stale dev-agent worktrees/tmux sessions from previous runs
324316
325317** Note** : Dev agents are NOT started at startup. They are spawned on-demand when tasks arrive.
326318
@@ -338,9 +330,7 @@ The sentry-agent triages Sentry alerts and investigates critical issues via the
338330| ` OPENCODE_ZEN_API_KEY ` | ` opencode-zen/claude-haiku-4-5 ` |
339331
340332``` bash
341- mkdir -p ~ /.pi/agent/logs
342- nohup bash -lc " export PATH=\$ HOME/.varlock/bin:\$ HOME/opt/node-v22.14.0-linux-x64/bin:\$ PATH && export PI_SESSION_NAME=sentry-agent && exec varlock run --path ~/.config/ -- pi --session-control --skill ~/.pi/agent/skills/sentry-agent --model <MODEL_FROM_TABLE_ABOVE>" > ~ /.pi/agent/logs/sentry-agent.log 2>&1 &
343- echo $! > ~ /.pi/agent/sentry-agent.pid
333+ tmux new-session -d -s sentry-agent " export PATH=\$ HOME/.varlock/bin:\$ HOME/opt/node-v22.14.0-linux-x64/bin:\$ PATH && export PI_SESSION_NAME=sentry-agent && varlock run --path ~/.config/ -- pi --session-control --skill ~/.pi/agent/skills/sentry-agent --model <MODEL_FROM_TABLE_ABOVE>"
344334```
345335
346336** Model note** : ` github-copilot/* ` models reject Personal Access Tokens and will fail in non-interactive sessions.
@@ -351,12 +341,13 @@ The sentry-agent operates in **on-demand mode** — it does NOT poll. Sentry ale
351341
352342The ` startup-cleanup.sh ` script handles bridge (re)start automatically — it detects broker vs Socket Mode, reads the control-agent UUID, and starts the bridge as a normal background process.
353343
354- If you need to restart the bridge manually, run ` startup-cleanup.sh ` again and then inspect logs:
344+ If you need to restart the bridge manually, rerun startup cleanup and then inspect logs:
355345``` bash
346+ bash ~ /.pi/agent/skills/control-agent/startup-cleanup.sh UUID1 UUID2 UUID3
356347tail -n 200 ~ /.pi/agent/logs/slack-bridge.log
357348```
358349
359- Verify API readiness : ` curl -s -o /dev/null -w '%{http_code}' -X POST http://127.0.0.1:7890/send -H 'Content-Type: application/json' -d '{}' ` → should return ` 400 ` .
350+ Verify: ` curl -s -o /dev/null -w '%{http_code}' -X POST http://127.0.0.1:7890/send -H 'Content-Type: application/json' -d '{}' ` → should return ` 400 ` .
360351
361352The bridge forwards:
362353- ** Human @mentions and DMs** from allowed users → delivered to you with security boundaries for handling
@@ -369,9 +360,9 @@ Health checks run automatically every ~10 minutes via the `heartbeat.ts` extensi
369360If you need to check manually, use ` heartbeat trigger ` to run all checks immediately.
370361
371362When the heartbeat reports a failure, take the appropriate action:
372- 1 . ** Missing sentry-agent** : Respawn as a background process and re-send role assignment.
373- 2 . ** Orphaned dev-agents** : Kill stale process + remove worktree.
374- 3 . ** Bridge down** : Restart via ` startup-cleanup.sh ` and read ` ~/.pi/agent/logs/slack-bridge.log ` .
363+ 1 . ** Missing sentry-agent** : Respawn with tmux and re-send role assignment.
364+ 2 . ** Orphaned dev-agents** : Kill tmux session and remove worktree.
365+ 3 . ** Bridge down** : Restart via ` startup-cleanup.sh ` , then check ` ~/.pi/agent/logs/slack-bridge.log ` .
3753664 . ** Stale worktrees** : ` git worktree remove --force ` + ` rmdir ` empty parents.
3763675 . ** Stuck todos** : Escalate to user via Slack.
377368
0 commit comments