diff --git a/internal/cmd/spawn.go b/internal/cmd/spawn.go index f90d0d48..4d243be3 100644 --- a/internal/cmd/spawn.go +++ b/internal/cmd/spawn.go @@ -337,20 +337,31 @@ func runSpawn(cmd *cobra.Command, args []string) error { style.Bold.Render("✓"), style.Dim.Render(fmt.Sprintf("gt session at %s/%s", rigName, polecatName))) - // TODO: Proper solution requires Witness/Deacon to monitor polecat startup - // and detect when Claude is ready using AI intelligence. See gt-polecat-ready issue. - // For now, use a fixed delay - SessionStart hook runs gt prime which tells polecat - // to check mail, but we also send an explicit instruction as backup. - sessionName := sessMgr.SessionName(polecatName) - time.Sleep(5 * time.Second) + // Notify Witness about the spawn - Witness will monitor startup and nudge when ready + witnessAddr := fmt.Sprintf("%s/witness", rigName) + spawnNotification := &mail.Message{ + To: witnessAddr, + From: "mayor/", + Subject: fmt.Sprintf("SPAWN: %s starting on %s", polecatName, assignmentID), + Body: fmt.Sprintf(`Polecat spawn notification. - // Send work instruction - backup in case SessionStart hook doesn't trigger action - workInstruction := "Check your inbox with `gt mail inbox` and begin working on your assigned issue." - if err := t.SendKeys(sessionName, workInstruction); err != nil { - fmt.Printf(" %s\n", style.Dim.Render(fmt.Sprintf("Warning: could not send work instruction: %v", err))) +Polecat: %s +Issue: %s +Session: %s + +Please monitor this polecat's startup. When Claude is ready (you can see the prompt +in the tmux session), send a nudge to start working: + + tmux send-keys -t %s "Check your inbox with 'gt mail inbox' and begin working." Enter + +The polecat has a work assignment in its inbox.`, polecatName, assignmentID, sessMgr.SessionName(polecatName), sessMgr.SessionName(polecatName)), } - fmt.Printf(" %s\n", style.Dim.Render("Work instruction sent to polecat")) + if err := router.Send(spawnNotification); err != nil { + fmt.Printf(" %s\n", style.Dim.Render(fmt.Sprintf("Warning: could not notify witness: %v", err))) + } else { + fmt.Printf(" %s\n", style.Dim.Render("Witness notified to monitor startup")) + } return nil } diff --git a/internal/templates/roles/witness.md.tmpl b/internal/templates/roles/witness.md.tmpl index a8917082..79604635 100644 --- a/internal/templates/roles/witness.md.tmpl +++ b/internal/templates/roles/witness.md.tmpl @@ -102,6 +102,57 @@ gt mail delete --- +## 🚀 SPAWN REQUEST PROCESSING + +When you receive a message with subject containing "SPAWN:": + +This means a new polecat was just spawned and needs monitoring until it starts working. + +### Step 1: Parse the Spawn Info +Extract from the message: +- Polecat name +- Issue ID +- Session name (e.g., `gt-{{ .RigName }}-`) + +### Step 2: Monitor Startup +Check if Claude is ready by looking at the session: +```bash +gt session capture {{ .RigName }}/ -n 20 +``` + +Look for signs Claude is ready: +- The Claude Code banner is visible +- A prompt line starting with `>` is visible +- No "loading" or initialization messages + +### Step 3: Nudge to Start Working +Once Claude appears ready, send the work instruction: +```bash +tmux send-keys -t gt-{{ .RigName }}- "Check your inbox with 'gt mail inbox' and begin working on your assigned issue." Enter +``` + +### Step 4: Verify Work Started +After nudging, check the session again: +```bash +gt session capture {{ .RigName }}/ -n 30 +``` + +Look for signs the polecat is working: +- Running `gt mail inbox` +- Reading the work assignment +- Starting to work on the issue + +### Step 5: Acknowledge +Delete the spawn notification once the polecat is working: +```bash +gt mail delete +``` + +**Note**: If the polecat doesn't respond after 2-3 nudges, it may be stuck. +Escalate to Mayor or try restarting the session. + +--- + ## 🔍 HEALTH CHECK PROTOCOL Periodically check polecat health: