diff --git a/.beads/formulas/mol-witness-patrol.formula.toml b/.beads/formulas/mol-witness-patrol.formula.toml index ad30b862..0e638fe2 100644 --- a/.beads/formulas/mol-witness-patrol.formula.toml +++ b/.beads/formulas/mol-witness-patrol.formula.toml @@ -21,7 +21,7 @@ inbox-check ─► process-cleanups ─► check-refinery ─► survey-workers │ ┌──────────────────────────────────────────────────┘ ▼ - ping-deacon ─► context-check ─► loop-or-exit + check-swarm ─► ping-deacon ─► context-check ─► loop-or-exit ``` No dynamic arms. No fanout gates. No persistent nudge counters. @@ -266,10 +266,40 @@ gt mail send mayor/ -s "Escalation: stuck" \\ **ZFC Principle**: Trust agent_state from beads. Don't infer state from PID/tmux.""" +[[steps]] +id = "check-swarm-completion" +title = "Check if active swarm is complete" +needs = ["survey-workers"] +description = """ +If Mayor started a batch (SWARM_START), check if all polecats have completed. + +**Step 1: Find active swarm tracking wisps** +```bash +bd list --wisp --labels=swarm --status=open +``` +If no active swarm, skip this step. + +**Step 2: Count completed polecats for this swarm** + +Extract from wisp labels: swarm_id, total, completed, start timestamp. +Check how many cleanup wisps have been closed for this swarm's polecats. + +**Step 3: If all complete, notify Mayor** +```bash +gt mail send mayor/ -s "SWARM_COMPLETE: " -m "All polecats merged. +Duration: minutes +Swarm: " + +# Close the swarm tracking wisp +bd close --reason "All polecats merged" +``` + +Note: Runs every patrol cycle. Notification sent exactly once when all complete.""" + [[steps]] id = "ping-deacon" title = "Ping Deacon for health check" -needs = ["survey-workers"] +needs = ["check-swarm-completion"] description = """ Send WITNESS_PING to Deacon for second-order monitoring.