@jaggerxtrm/specialists 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +12 -1
  2. package/config/hooks/specialists-session-start.mjs +105 -0
  3. package/config/nodes/research-multi.node.json +11 -0
  4. package/config/nodes/research.node.json +27 -0
  5. package/config/presets.json +26 -0
  6. package/config/skills/specialists-creator/SKILL.md +323 -145
  7. package/config/skills/specialists-creator/scripts/scaffold-specialist.ts +228 -0
  8. package/config/skills/using-nodes/SKILL.md +333 -0
  9. package/config/skills/using-specialists/SKILL.md +843 -173
  10. package/config/specialists/debugger.specialist.json +74 -0
  11. package/config/specialists/executor.specialist.json +117 -0
  12. package/config/specialists/explorer.specialist.json +82 -0
  13. package/config/specialists/memory-processor.specialist.json +65 -0
  14. package/config/specialists/node-coordinator.specialist.json +64 -0
  15. package/config/specialists/overthinker.specialist.json +65 -0
  16. package/config/specialists/parallel-review.specialist.json +65 -0
  17. package/config/specialists/planner.specialist.json +93 -0
  18. package/config/specialists/researcher.specialist.json +65 -0
  19. package/config/specialists/reviewer.specialist.json +60 -0
  20. package/config/specialists/specialists-creator.specialist.json +68 -0
  21. package/config/specialists/sync-docs.specialist.json +80 -0
  22. package/config/specialists/test-runner.specialist.json +67 -0
  23. package/config/specialists/xt-merge.specialist.json +60 -0
  24. package/dist/index.js +13818 -2743
  25. package/package.json +6 -3
  26. package/config/specialists/debugger.specialist.yaml +0 -121
  27. package/config/specialists/executor.specialist.yaml +0 -257
  28. package/config/specialists/explorer.specialist.yaml +0 -85
  29. package/config/specialists/memory-processor.specialist.yaml +0 -154
  30. package/config/specialists/overthinker.specialist.yaml +0 -76
  31. package/config/specialists/parallel-review.specialist.yaml +0 -75
  32. package/config/specialists/planner.specialist.yaml +0 -94
  33. package/config/specialists/reviewer.specialist.yaml +0 -142
  34. package/config/specialists/specialists-creator.specialist.yaml +0 -90
  35. package/config/specialists/sync-docs.specialist.yaml +0 -68
  36. package/config/specialists/test-runner.specialist.yaml +0 -65
  37. package/config/specialists/xt-merge.specialist.yaml +0 -159
@@ -2,89 +2,608 @@
2
2
  name: using-specialists
3
3
  description: >
4
4
  Use this skill whenever you're about to start a substantial task — pause first and
5
- ask whether to delegate. Consult before any: code review, security audit, deep bug
6
- investigation, test generation, multi-file refactor, or architecture analysis. Also
7
- use for the mechanics of delegation: --bead workflow, --context-depth, background
8
- jobs, and MCP tool (`use_specialist`). Don't wait for the user to say "use a specialist" — proactively
9
- evaluate whether delegation makes sense.
10
- version: 3.7
5
+ route the work through specialists instead of doing discovery or implementation
6
+ yourself. Consult before any: code review, security audit, deep bug investigation,
7
+ test generation, multi-file refactor, architecture analysis, or multi-chain
8
+ specialist orchestration. Also use for the mechanics of delegation: --bead
9
+ workflow, --context-depth, background jobs, MCP tool (`use_specialist`),
10
+ or specialists doctor. Don't wait for the user to say
11
+ "use a specialist" — proactively evaluate whether delegation makes sense.
12
+ version: 4.5
13
+ synced_at: zz22-docs
11
14
  ---
12
15
 
13
16
  # Specialists Usage
14
17
 
15
- When this skill is loaded, you are a **coordinator first**: delegate substantial work to specialists, monitor progress, and synthesize outcomes for the user.
18
+ When this skill is loaded, you are an **orchestrator** think CEO or CTO. You set direction, route work, unblock specialists, and synthesize outcomes. You do not implement.
16
19
 
17
- Specialists are autonomous AI agents that run independently fresh context, different
18
- model, no prior bias. Delegate when a task would take you significant effort, spans
19
- multiple files, or benefits from a dedicated focused run.
20
+ Specialists handle **99% of tasks**. The only things you do yourself are things that are genuinely trivial (one-liner, quick config) or require a global overview only you can provide. Everything else goes to a specialist. When in doubt, delegate.
20
21
 
21
- The reason isn't just speedit's quality. A specialist has no competing context,
22
- leaves a tracked record via beads, and can run in the background while you stay unblocked.
22
+ Your job is routing, sequencing, monitoring, and synthesis not exploration or implementation. Do **ZERO implementation** yourself for substantial work: no file reads, no code writing, no docs, no self-investigation. If you catch yourself doing discovery, stop and dispatch explorer instead.
23
23
 
24
- ## The Delegation Decision
24
+ > **Sleep timers**: When you dispatch a specialist for a longer task, set a sleep timer and step back. Don't poll manually — set a timer appropriate to the expected run time, sleep, then check results. This lets you work independently and iterate without babysitting jobs.
25
25
 
26
- Before starting any substantial task, ask: is this worth delegating?
26
+ Specialists are autonomous AI agents that run independently — fresh context, different model, no prior bias. The reason isn't just speed — it's quality. A specialist has no competing context, leaves a tracked record via beads, and can run in the background while you stay unblocked.
27
27
 
28
- **Delegate when:**
29
- - It would take >5 minutes of focused work
30
- - It spans multiple files or modules
31
- - A fresh perspective adds value (code review, security audit)
32
- - It can run in the background while you do other things
33
- - You have multiple independent tasks — dispatch them as a wave
34
- - It's a review/analysis loop (audit → approve/deny → resume) that benefits from interactive keep-alive
28
+ > **Session start**: Run `sp --help` once to see the full command surface. `sp` is the short alias for `specialists` — `sp run`, `sp feed`, `sp resume` etc. all work. Also useful: `sp run --help`, `sp resume --help`, `sp feed --help` for flag details.
35
29
 
36
- **Do it yourself when:**
37
- - It's a single-file edit or quick config change
38
- - It needs interactive back-and-forth
39
- - It's obviously trivial (one-liner, formatting fix)
30
+ ---
31
+
32
+ ## Hard Rules
40
33
 
41
- When in doubt, delegate. Specialists run in parallel you don't have to wait.
34
+ 1. **Zero implementation by orchestrator.** When this skill is active for substantial work, you do not implement the solution yourself.
35
+ 2. **Never explore yourself.** All discovery, codebase mapping, and read-only investigation go through **explorer** (or **debugger** for root-cause analysis).
36
+ 3. **Run explorer before executor when context is lacking.** If the bead already has clear scope — files, symbols, approach — send executor directly. Only run explorer first when the issue lacks a clear track.
37
+ 4. **For tracked work, the bead is the prompt.** The bead description, notes, and parent context are the instruction surface.
38
+ 5. **`--bead` and `--prompt` are mutually exclusive.** If you need to refine instructions, update the bead notes; do not add `--prompt`.
39
+ 6. **Chains belong to epics.** A chain is a worktree lineage (executor → reviewer → fix). An epic is the merge-gated identity that owns chains. Use `sp epic merge <epic>` to publish — never merge individual chains that belong to an unresolved epic.
40
+ 7. **Merge through epics, not manual git.** Use `sp epic merge <epic-id>` for wave-bound chains or `sp merge <chain-root-bead>` for standalone chains. Never use manual `git merge` for specialist work.
41
+ 8. **No destructive operations by specialists.** No `rm -rf`, no force pushes, no database drops, no credential rotation, no mass deletes, no history rewrites. Surface destructive requirements to the user.
42
+ 9. **Executor does not run tests.** Executor runs lint + tsc only. Tests are the reviewer's and test-runner's responsibility in the chained pipeline.
42
43
 
43
44
  ---
44
45
 
45
- ## Canonical Workflow
46
+ ## When to Use This Skill
47
+
48
+ **Default: always delegate.** Specialists handle 99% of tasks. The orchestrator only acts directly for things that are genuinely trivial (one-liner, quick config tweak) or require a global overview that only you can provide.
49
+
50
+ **Do it yourself only when:**
51
+ - It's a one-liner or formatting fix
52
+ - It's a quick config change that needs no investigation
53
+ - It genuinely requires high-level synthesis only you can do (e.g. reading results across multiple jobs and forming a next-step decision)
54
+
55
+ Everything else — investigation, implementation, review, testing, docs, planning, design — goes to a specialist.
56
+
57
+ ---
46
58
 
47
- For tracked work, always use `--bead`. This gives the specialist your issue as context,
48
- links results back to the tracker, and creates an audit trail.
59
+ ## Canonical Workflow
49
60
 
50
61
  ### CLI commands
51
62
 
52
63
  ```bash
64
+ # Discovery
53
65
  specialists list # discover available specialists
66
+ specialists doctor # health check: hooks, MCP, zombie jobs
67
+
68
+ # Running
54
69
  specialists run <name> --bead <id> # foreground run (streams output)
70
+ specialists run <name> --bead <id> --background # background run
71
+ specialists run <name> --bead <id> --worktree # isolated worktree (edit-capable specialists)
72
+ specialists run <name> --bead <id> --job <job-id> # reuse another job's worktree
73
+ specialists run <name> --bead <id> --epic <epic-id> # explicitly declare epic membership
55
74
  specialists run <name> --prompt "..." # ad-hoc (no bead tracking)
56
- specialists feed -f # tail merged feed (all jobs)
75
+ specialists run <name> --bead <id> --keep-alive # keep session alive after first turn
76
+ specialists run <name> --bead <id> --context-depth 2 # inject parent bead context
77
+
78
+ # Monitoring
79
+ specialists ps # list all jobs (status, specialist, elapsed, bead, epic)
80
+ specialists ps <job-id> # inspect single job (full detail + ctx% badge)
81
+ specialists feed -f # tail merged feed (all jobs) — shows [ctx%] context window usage
57
82
  specialists feed <job-id> # events for a specific job
58
83
  specialists result <job-id> # final output text
84
+ specialists status --job <job-id> # single-job detail view (legacy — prefer `sp ps <id>`)
85
+
86
+ # Epic lifecycle (canonical publication path)
87
+ specialists epic list [--unresolved] # list epics with lifecycle state
88
+ specialists epic status <epic-id> # show chains, blockers, readiness
89
+ specialists epic resolve <epic-id> # transition open -> resolving
90
+ specialists epic merge <epic-id> [--pr] # publish all epic-owned chains
91
+
92
+ # Merge (for standalone chains only)
93
+ specialists merge <chain-root-bead> [--rebuild] # publish ONE standalone chain
94
+
95
+ # Session close (chain-aware, epic-aware)
96
+ specialists end [--pr] # close session, publish via merge or PR
97
+
98
+ # Interaction
59
99
  specialists steer <job-id> "new direction" # redirect ANY running job mid-run
60
100
  specialists resume <job-id> "next task" # resume a waiting keep-alive job
61
101
  specialists stop <job-id> # cancel a job
62
- specialists edit <name> # edit a specialist's YAML config
63
- specialists status --job <job-id> # single-job detail view
64
- specialists clean # purge old job directories
102
+
103
+ # Management
104
+ specialists edit <name> # edit specialist config (dot-path, --preset)
105
+ specialists clean # purge old job dirs + worktree GC
106
+ specialists clean --processes # kill all running/starting specialist jobs
107
+ specialists init --sync-skills # re-sync skills only (no full init)
108
+ specialists init --no-xtrm-check # skip xtrm prerequisite check (CI/testing)
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Taxonomy: Job | Chain | Epic
114
+
115
+ The specialists orchestration model uses three levels:
116
+
117
+ | Term | Definition | Persisted? | Merge scope |
118
+ |------|------------|:----------:|:-----------:|
119
+ | **Job** | One specialist run (atomic execution unit) | Yes (SQLite + files) | — |
120
+ | **Chain** | Worktree lineage: executor → reviewer → fix → re-review (seeded by edit-capable specialist) | Yes (`worktree_owner_job_id`) | `sp merge <chain-root>` |
121
+ | **Epic** | Top merge-gated identity that owns chains across stages | Yes (`epic_runs` table) | `sp epic merge <epic>` |
122
+ | **Wave** | Human shorthand for dispatch batches ("Wave 1", "Wave 2b") — **speech only, NOT persisted** | No | — |
123
+
124
+ ### Key relationships
125
+
126
+ - **Chains belong to epics**: When `--bead` is used, the chain defaults to the bead's parent epic. Override with `--epic <id>`.
127
+ - **Jobs belong to chains**: Jobs sharing a `worktree_owner_job_id` form one chain.
128
+ - **Merge through epics**: `sp epic merge <epic-id>` is the **canonical publication path** for wave-bound chains.
129
+ - **Standalone chains**: `sp merge <chain-root-bead>` works only for chains NOT belonging to an unresolved epic.
130
+
131
+ ### Epic lifecycle
132
+
133
+ ```
134
+ open → resolving → merge_ready → merged
135
+ ↘ failed
136
+ ↘ abandoned
137
+ ```
138
+
139
+ | State | Meaning | Chains mergeable? |
140
+ |-------|---------|:-----------------:|
141
+ | `open` | Epic created, chains not yet running | — |
142
+ | `resolving` | Chains are actively running | ✗ |
143
+ | `merge_ready` | All chains terminal, reviewer PASS | ✓ (via `sp epic merge`) |
144
+ | `merged` | Publication complete | — |
145
+ | `failed` | One or more chains failed | — |
146
+ | `abandoned` | Cancelled without merge | — |
147
+
148
+ ### Migration from "waves" vocabulary
149
+
150
+ **Old terminology → New terminology:**
151
+
152
+ | Old | New | Notes |
153
+ |-----|-----|-------|
154
+ | "Wave 1" | Stage 1 / Prep phase | Speech shorthand still works — just not persisted |
155
+ | "Wave 2" | Implementation chains | Chains are the operative unit, grouped by epic |
156
+ | "Between waves merge" | `sp epic merge` | Epic is the merge-gated identity |
157
+ | "Parallel in wave" | Parallel chains under epic | Use `--epic` to declare membership explicitly |
158
+
159
+ **Why this change?**
160
+
161
+ 1. **Waves had no identity**: "Wave 2" was just speech — no code could track it.
162
+ 2. **Merge gates were implicit**: Operators had to remember which chains to merge together.
163
+ 3. **Epics are explicit**: An epic bead ID persists, enabling `sp epic status` and `sp epic merge`.
164
+
165
+ **Backward compatibility**: All existing workflows work unchanged. The new vocabulary is additive — you can still think in waves, but the system tracks epics.
166
+
167
+ ---
168
+
169
+ ## Chained Bead Pipeline
170
+
171
+ This is the **standard for ALL tracked work**. Every specialist run gets its own child bead.
172
+ Each step's output accumulates on its bead. Downstream steps see upstream output automatically
173
+ via `--context-depth 2`. The bead chain IS the context chain — zero manual wiring needed.
174
+
175
+ ```
176
+ task-abc: "Fix auth token refresh"
177
+ └── abc-exp: explorer (READ_ONLY — auto-appends output to abc-exp notes)
178
+ └── abc-impl: executor (self-appends output to abc-impl notes, closes bead)
179
+ └── abc-rev: reviewer (READ_ONLY — auto-appends verdict via --job <exec-job>)
180
+ └── abc-fix: executor (if reviewer PARTIAL — fix bead, same worktree via --job)
65
181
  ```
66
182
 
67
- ### Typical flow
183
+ **How context flows (`--context-depth 2` = own + parent + grandparent = 3 beads):**
184
+
185
+ | Step | Specialist sees | Via |
186
+ |------|----------------|-----|
187
+ | abc-exp | abc-exp (own) + task-abc (parent) | `--bead abc-exp --context-depth 2` |
188
+ | abc-impl | abc-impl (own) + abc-exp (explorer findings in notes) + task-abc | `--bead abc-impl --context-depth 2` |
189
+ | reviewer | abc-impl bead (with executor output + reviewer verdict in notes) | `--bead abc-impl --job <exec-job>` |
190
+ | abc-fix | abc-fix (own) + abc-impl (executor output + reviewer verdict) + abc-exp | `--bead abc-fix --job <exec-job> --context-depth 2` |
191
+
192
+ - No copy-paste, no manual note injection between steps
193
+ - Every step has a full audit trail on its own bead
194
+ - The dep graph IS the context graph — self-documenting
195
+
196
+ ### Complete flow example
68
197
 
69
198
  ```bash
70
- # 1. Create a bead describing what you need
199
+ # 1. Create the task bead
71
200
  bd create --title "Fix auth token refresh bug" --type bug --priority 2
72
201
  # -> unitAI-abc
73
202
 
74
- # 2. Run the right specialist against the bead
75
- specialists run executor --bead unitAI-abc &
203
+ # 2. Create chained child beads (create all upfront for clarity)
204
+ bd create --title "Explore: map token refresh code paths" --type task --priority 2
205
+ # -> unitAI-abc-exp
206
+ bd dep add abc-exp abc
207
+
208
+ bd create --title "Implement: fix token refresh retry on 401" --type task --priority 2
209
+ # -> unitAI-abc-impl
210
+ bd dep add abc-impl abc-exp
211
+
212
+ # 3. Wave 1 — Explorer
213
+ specialists run explorer --bead abc-exp --context-depth 2 --background
214
+ # -> Job started: e1f2g3
215
+ # Explorer output auto-appends to abc-exp notes (READ_ONLY behavior)
216
+ specialists result e1f2g3
217
+
218
+ # 4. [MERGE] Merge any worktree branches from Wave 1 into master
219
+ # READ_ONLY waves have no worktrees to merge
220
+
221
+ # 5. Wave 2 — Executor
222
+ specialists run executor --worktree --bead abc-impl --context-depth 2 --background
76
223
  # -> Job started: a1b2c3
224
+ # Executor sees: abc-impl + abc-exp (with explorer notes) + abc via context-depth
225
+ # Executor self-appends output to abc-impl notes, closes abc-impl on completion
226
+
227
+ # 6. [MERGE] Merge impl worktree branch into master
228
+ sp merge abc-impl --rebuild
229
+
230
+ # 7. Wave 3 — Reviewer (no separate bead — uses --job + --prompt to enter executor's worktree)
231
+ specialists run reviewer --job a1b2c3 --keep-alive --background --prompt "Review the token refresh fix"
232
+ # -> Job started: r4v5w6
233
+ # Reviewer reads task bead from job a1b2c3's status.json automatically
234
+ # Reviewer auto-appends verdict to bead notes (READ_ONLY)
235
+ specialists result r4v5w6
236
+ # -> PASS: close task bead. PARTIAL/FAIL: go to step 8.
237
+
238
+ # 8. If PARTIAL — fix loop (same worktree, new child bead)
239
+ bd create --title "Fix: reviewer gaps on abc-impl" --type bug --priority 1
240
+ # -> unitAI-abc-fix
241
+ bd dep add abc-fix abc-impl
242
+
243
+ specialists run executor --bead abc-fix --job a1b2c3 --context-depth 2 --background
244
+ # Fixer runs in same worktree (via --job a1b2c3)
245
+ # Sees: abc-fix + abc-impl (executor output + reviewer verdict) + abc-exp via context-depth
246
+ # Repeat reviewer --job → fix loop until PASS
247
+
248
+ # 9. Close when reviewer says PASS
249
+ bd close abc --reason "Fixed: token refresh retries on 401. Reviewer PASS."
250
+ ```
251
+
252
+ **Why chaining matters:**
253
+ - Every step's output is preserved — full audit trail on each bead
254
+ - `--context-depth 2` gives each specialist the previous step's findings automatically
255
+ - No copy-pasting results between steps
256
+ - The orchestrator only creates beads and dispatches — zero context injection
257
+
258
+ ---
259
+
260
+ ## --job, --worktree, and --epic Semantics
261
+
262
+ These flags control **workspace isolation** and **epic membership**. Executors run in isolated git worktrees so concurrent jobs don't corrupt shared files. Chains declare epic membership to enable merge-gated publication.
263
+
264
+ | Flag | Semantics | Creates worktree? | Sets epic? |
265
+ |------|-----------|:----------------:|:----------:|
266
+ | `--worktree` | Provision a new isolated workspace; requires `--bead` | Yes | Inherited from bead.parent |
267
+ | `--job <id>` | Reuse the workspace of an existing job | No | Inherited from target job |
268
+ | `--epic <id>` | Explicitly declare epic membership | No | Yes (overrides default) |
269
+
270
+ `--worktree` and `--job` are **mutually exclusive**. Specifying both exits with an error.
271
+
272
+ ### Epic membership
273
+
274
+ When `--bead` is used, the chain defaults to the bead's parent epic (if parent is an epic-type bead). Override this with `--epic <id>`:
275
+
276
+ ```bash
277
+ # Chain inherits bead.parent as epic
278
+ specialists run executor --worktree --bead unitAI-impl
279
+ # → epic_id = bead.parent (if epic-type)
280
+
281
+ # Explicit epic declaration (e.g., prep job with non-epic parent)
282
+ specialists run explorer --bead prep-task.1 --epic unitAI-3f7b
283
+ # → epic_id = unitAI-3f7b (explicit override)
284
+ ```
285
+
286
+ **Why explicit --epic?** Prep jobs (explorer, planner, overthinker) often have non-epic parents but need to belong to the epic for `sp ps` grouping and `sp epic status` visibility.
287
+
288
+ ### `--worktree`
289
+
290
+ Provisions a new git worktree + branch for the specialist run. Branch name is derived
291
+ deterministically from the bead id: `feature/<beadId>-<specialist-slug>`.
292
+
293
+ ```bash
294
+ specialists run executor --worktree --bead hgpu.3
295
+ # stderr: [worktree created: /repo/.worktrees/hgpu.3/hgpu.3-executor branch: feature/hgpu.3-executor]
296
+ ```
297
+
298
+ If the worktree already exists (interrupted run), it is **reused**, not recreated.
299
+
300
+ ### `--job <id>`
301
+
302
+ Reads `worktree_path` from the target job's `status.json` and uses that directory as `cwd`.
303
+ The caller's own `--bead` remains authoritative — `--job` only selects the workspace.
304
+
305
+ ```bash
306
+ # Reviewer enters executor's worktree to review exactly what was written
307
+ specialists run reviewer --job 49adda --keep-alive --background
308
+
309
+ # Fix executor re-enters same worktree (--bead provides new fix bead, --job provides workspace)
310
+ specialists run executor --bead hgpu.3-fix --job 49adda --context-depth 2 --background
311
+ ```
312
+
313
+ **Concurrency guard (MEDIUM/HIGH specialists):**
314
+
315
+ Blocked from entering while target job is `starting` or `running` — prevents concurrent file corruption.
316
+
317
+ | Target status | MEDIUM/HIGH | READ_ONLY/LOW |
318
+ |---------------|:-----------:|:-------------:|
319
+ | `starting` | ✗ Blocked | ✓ Allowed |
320
+ | `running` | ✗ Blocked | ✓ Allowed |
321
+ | `waiting` | ✓ Allowed | ✓ Allowed |
322
+ | `done`/`error`/`cancelled` | ✓ Allowed | ✓ Allowed |
323
+ | Unknown | ✗ Blocked (conservative) | ✓ Allowed |
324
+
325
+ **Bypass with `--force-job`:**
326
+
327
+ ```bash
328
+ specialists run executor --job 49adda --force-job --bead fix-123
329
+ ```
330
+
331
+ Use when the caller explicitly accepts concurrent write risk (e.g., target job known to be stalled but not yet terminal, emergency fix entry).
332
+
333
+ ### When to use each flag
334
+
335
+ | Scenario | Flag to use |
336
+ |----------|------------|
337
+ | First executor run for a task | `--worktree --bead <impl-bead>` |
338
+ | Reviewer on executor's output | `--job <exec-job-id>` (no `--worktree`) |
339
+ | Fix executor after reviewer PARTIAL | `--bead <fix-bead> --job <exec-job-id>` |
340
+ | Force entry to blocked worktree | `--bead <fix-bead> --job <exec-job-id> --force-job` |
341
+ | Prep job belonging to epic (non-epic parent) | `--bead <prep-bead> --epic <epic-id>` |
342
+ | Explorer (READ_ONLY) | Neither — explorers don't need worktrees |
343
+ | Overthinker, planner, debugger | Neither — read-only and interactive specialists |
344
+
345
+ ---
346
+
347
+ ### Worktree write-boundary enforcement
348
+
349
+ Specialists running in worktrees are **prevented from writing outside their boundary**. The session generates a Pi extension that hooks `tool_call` events and blocks `edit`/`write`/`multiEdit`/`notebookEdit` tools with absolute paths outside the worktree.
350
+
351
+ **What's blocked:**
352
+ - `edit` with `/absolute/path/outside/worktree/file.ts`
353
+ - `write` with `/absolute/path/outside/worktree/new-file.ts`
354
+
355
+ **What's allowed:**
356
+ - Relative paths (`src/file.ts`) — resolve within worktree cwd
357
+ - Absolute paths inside the worktree boundary
358
+
359
+ This enforcement is automatic when `--worktree` is used. No configuration required. If the extension fails to generate (tmpdir permissions), a warning is logged and the session proceeds without protection.
360
+
361
+ ---
362
+
363
+ ## Dependency Mapping
364
+
365
+ Map bead dependencies to match the execution pipeline. The dep graph IS the wave plan.
366
+
367
+ ### Simple bug fix
368
+ ```
369
+ task → explore → impl
370
+ └── reviewer via --job (no own bead needed)
371
+ └── fix (if PARTIAL) → child of impl
372
+ ```
373
+ ```bash
374
+ bd dep add explore task
375
+ bd dep add impl explore
376
+ # reviewer: specialists run reviewer --job <impl-job>
377
+ # fix: bd dep add fix impl
378
+ ```
379
+
380
+ ### Complex feature (overthinker)
381
+ ```
382
+ task → explore → design → impl → [reviewer via --job] → [fix if PARTIAL]
383
+ ```
384
+ ```bash
385
+ bd dep add explore task
386
+ bd dep add design explore
387
+ bd dep add impl design
388
+ # reviewer: specialists run reviewer --job <impl-job>
389
+ ```
390
+
391
+ ### Epic with N children
392
+ Each child gets its own explore → impl chain. Reviewer runs via `--job` per impl.
393
+ ```
394
+ epic
395
+ ├── child-1 → explore-1 → impl-1 (reviewer via --job impl-1-job)
396
+ ├── child-2 → explore-2 → impl-2 (reviewer via --job impl-2-job)
397
+ └── child-N → explore-N → impl-N (reviewer via --job impl-N-job)
398
+ ```
399
+ Children (chains) within the same epic can run **in parallel** if they own disjoint files.
400
+
401
+ ### Parallel chains (same stage)
402
+ Chains in the same stage share no intra-stage dependencies. They depend on the previous stage's output (same epic parent), not on each other.
403
+ ```
404
+ # Stage 2 parallel executors (after shared Stage 1 explorer):
405
+ bd dep add impl-a explore # impl-a depends on explore, NOT on impl-b
406
+ bd dep add impl-b explore # impl-b depends on explore, NOT on impl-a
407
+ ```
408
+ Each runs in its own `--worktree`. Merge via `sp epic merge <epic>` before Stage 3.
409
+
410
+ ### Test beads (batched)
411
+ Tests are **batched** — one test bead covers all impls in a stage, not per-impl.
412
+ The test bead depends on **all** impl beads it covers.
413
+ ```
414
+ bd dep add tests impl-a
415
+ bd dep add tests impl-b
416
+ bd dep add tests impl-c
417
+ # specialists run test-runner --bead tests --context-depth 2
418
+ ```
419
+
420
+ ---
421
+
422
+ ## Review and Fix Loop
423
+
424
+ The review → fix loop is the mechanism for iterative quality improvement within a single worktree.
425
+
426
+ ### Standard loop
427
+
428
+ ```
429
+ 1. Executor claims impl bead, provisions --worktree, implements, closes bead.
430
+ -> Job: exec-job
431
+
432
+ 2. Reviewer enters same worktree via --job exec-job.
433
+ -> Reads task bead from exec-job status.json automatically.
434
+ -> Auto-appends verdict (PASS/PARTIAL/FAIL) to bead notes.
435
+
436
+ 3a. PASS: orchestrator closes parent task bead.
437
+
438
+ 3b. PARTIAL/FAIL:
439
+ -> Create fix bead as child of impl bead.
440
+ -> Run executor --bead fix-bead --job exec-job --context-depth 2.
441
+ -> Fix executor sees: fix-bead + impl (with reviewer verdict) + explore.
442
+ -> Fix executor closes fix-bead on completion.
443
+ -> Return to step 2 (reviewer on same job).
444
+
445
+ 4. Repeat until PASS.
446
+ ```
447
+
448
+ ### Commands
449
+
450
+ ```bash
451
+ # Step 1 — Executor with worktree
452
+ specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
453
+ # -> Job started: exec-job (e.g. 49adda)
454
+
455
+ # Step 2 — Reviewer enters same worktree (--prompt required when no --bead)
456
+ specialists run reviewer --job 49adda --keep-alive --background --prompt "Review impl changes"
457
+ # -> Job started: rev-job
458
+ specialists result rev-job
459
+ # PARTIAL → go to step 3b
460
+
461
+ # Step 3b — Create fix bead + run fix executor in same worktree
462
+ bd create --title "Fix: address reviewer findings on impl" --type bug --priority 1
463
+ # -> unitAI-fix1
464
+ bd dep add fix1 impl
465
+ specialists run executor --bead fix1 --job 49adda --context-depth 2 --background
466
+
467
+ # Re-review
468
+ specialists run reviewer --job 49adda --keep-alive --background --prompt "Re-review after fix"
469
+ # PASS → close parent
470
+ bd close unitAI-task --reason "Reviewer PASS. All findings addressed."
471
+ ```
472
+
473
+ ### Key invariants
474
+ - Reviewer never re-opens the impl bead — it was closed by the executor. The reviewer's verdict lives on the bead notes as appended output.
475
+ - Each fix iteration creates a **new child bead** — never reopen or re-claim the completed impl bead.
476
+ - The fix executor inherits the full context chain: fix-bead + impl (executor output + reviewer findings) + explore, via `--context-depth 2`.
477
+ - Multiple reviewer → fix cycles are expected for complex changes. The worktree is stable across all cycles.
478
+
479
+ ---
480
+
481
+ ## Merge Protocol — Epic Publication
482
+
483
+ The orchestrator owns merge timing, but **no longer performs manual git merges**. Use `sp epic merge` or `sp merge` instead.
484
+
485
+ ### The canonical path: `sp epic merge <epic-id>`
486
+
487
+ **This is the ONLY legal publication path for wave-bound chains.**
488
+
489
+ An epic is merge-gated: all chains must be terminal with reviewer PASS before publication. Use `sp epic merge` for:
490
+
491
+ - Publishing multiple chains under one epic (topological order)
492
+ - Ensuring merge gates are satisfied (no running jobs)
493
+ - PR mode (`--pr`) for staged publication
494
+
495
+ ```bash
496
+ # Check epic readiness
497
+ sp epic status unitAI-3f7b
498
+ # Shows: chains, blockers, readiness state, reviewer verdicts
499
+
500
+ # Publish all epic-owned chains
501
+ sp epic merge unitAI-3f7b
502
+ # → merges in topological order, tsc gate after each
503
+
504
+ # PR mode (creates PR instead of direct merge)
505
+ sp epic merge unitAI-3f7b --pr
506
+ ```
507
+
508
+ **What `sp epic merge` does:**
509
+
510
+ 1. Reads epic state from observability SQLite
511
+ 2. Checks all chains are terminal (`done`/`error`)
512
+ 3. Verifies latest reviewer verdict is PASS
513
+ 4. Topologically sorts chains by bead dependencies
514
+ 5. For each chain: `git merge <branch> --no-ff --no-edit`
515
+ 6. Runs `bunx tsc --noEmit` after each merge
516
+ 7. Optionally creates PR with `--pr` flag
517
+ 8. Updates epic state to `merged` on success
518
+
519
+ ### When NOT to merge: `sp merge <chain-root>` is blocked
520
+
521
+ **Standalone chains only.** `sp merge <chain-root-bead>` works ONLY for chains NOT belonging to an unresolved epic:
522
+
523
+ ```bash
524
+ # This FAILS if chain belongs to epic with status=open/resolving/merge_ready
525
+ sp merge unitAI-impl
526
+ # Error: Chain unitAI-impl belongs to unresolved epic unitAI-3f7b (status: resolving).
527
+ # Use 'sp epic merge unitAI-3f7b' to publish all chains together.
528
+ ```
529
+
530
+ **Why this guard exists:**
531
+
532
+ 1. **Merge gates are per-epic**: Publishing one chain without its siblings breaks the wave model.
533
+ 2. **Topological order matters**: Chain A may depend on Chain B — merging A first breaks deps.
534
+ 3. **Epics are explicit**: The epic bead ID is tracked in SQLite, enabling the guard.
535
+
536
+ ### When to merge within a chain vs NOT
537
+
538
+ **Do NOT merge within a chain.** A chain is a sequence of specialists sharing one worktree:
539
+ executor → reviewer → fix → re-review. The worktree stays live throughout. No merge until
540
+ the reviewer says PASS.
541
+
542
+ ```
543
+ executor --worktree --bead impl ← creates worktree
544
+ reviewer --job <exec-job> ← enters same worktree (no merge)
545
+ executor --bead fix --job <exec-job> ← re-enters same worktree (no merge)
546
+ reviewer --job <exec-job> ← re-enters same worktree (no merge)
547
+ PASS → NOW run sp epic merge <epic>
548
+ ```
549
+
550
+ **DO merge between stages (via epic).** When the next stage's chains depend on this stage's code existing on master, merge the epic first. The dep graph tells you: beads connected by `--job` are one chain (same worktree, no merge). Beads connected by `bd dep add` across different file scopes are separate chains under the same epic.
551
+
552
+ ### Planning context upfront
553
+
554
+ Before dispatching any chains, identify:
555
+ - **Epics** — the top merge-gated identity (create epic-type bead first)
556
+ - **Chains** — worktree lineages that belong to the epic (use `--epic` for prep jobs)
557
+ - **Stages** — batches of independent chains ("Stage 1" / "Stage 2" are orchestrator speech)
558
+
559
+ The dep graph encodes this. If bead B depends on bead A and they touch different files, they're separate chains under the same epic with a merge point between stages.
560
+
561
+ ### Epic lifecycle commands
562
+
563
+ ```bash
564
+ # List epics with state
565
+ sp epic list
566
+ sp epic list --unresolved # show non-terminal epics
567
+
568
+ # Inspect one epic
569
+ sp epic status unitAI-3f7b
570
+ # Shows: persisted_state, readiness_state, chains[], blockers[], summary
77
571
 
78
- # 3. Monitor (pick one)
79
- specialists feed a1b2c3 # check events so far
80
- specialists feed -f # tail all active jobs
572
+ # Transition states (manual)
573
+ sp epic resolve unitAI-3f7b # open resolving
81
574
 
82
- # 4. Read results and close
83
- specialists result a1b2c3
84
- bd close unitAI-abc --reason "Fixed: token refresh now retries on 401"
575
+ # Publish
576
+ sp epic merge unitAI-3f7b # merge_ready → merged
577
+ sp epic merge unitAI-3f7b --pr # PR mode
85
578
  ```
86
579
 
87
- ### Giving specialists extra context via bead notes
580
+ ### Conflict handling
581
+
582
+ If merge hits a conflict:
583
+
584
+ 1. Command fails with list of conflicting files
585
+ 2. Resolve conflicts manually in your editor
586
+ 3. Run `bunx tsc --noEmit` to verify
587
+ 4. Continue with next chain (or re-run `sp epic merge <epic>` to resume)
588
+
589
+ **Common conflict pattern:** Parallel chains in the same stage may both create the same utility file (e.g. `job-root.ts`). This is expected — implementations should be identical. Keep one, delete the duplicate during conflict resolution.
590
+
591
+ ---
592
+
593
+ ## Bead-First Workflow (`--bead` is the prompt)
594
+
595
+ For tracked work, the bead is not just bookkeeping — it is the specialist's prompt.
596
+ The specialist reads:
597
+ - the bead title + description
598
+ - bead notes (including output appended by previous specialists in the chain)
599
+ - parent/ancestor bead context (controlled by `--context-depth`)
600
+
601
+ **Automatic context injection**: Runner injects ~3800 tokens of project memory at spawn:
602
+ - `.xtrm/memory.md` (SSOT: Do Not Repeat, How This Project Works, Active Context)
603
+ - `bd prime` output (workflow rules + all bd memories dump)
604
+ - GitNexus cheatsheet (when `.gitnexus/meta.json` exists — ~100 tokens)
605
+
606
+ This prevents specialists from rediscovering known gotchas on every run.
88
607
 
89
608
  `--prompt` and `--bead` cannot be combined. When you need to give a specialist
90
609
  specific instructions beyond what's in the bead description, update the bead notes first:
@@ -93,15 +612,18 @@ specific instructions beyond what's in the bead description, update the bead not
93
612
  bd update unitAI-abc --notes "INSTRUCTION: Rewrite docs/cli-reference.md from current
94
613
  source. Read every command in src/cli/ and src/index.ts. Document all flags and examples."
95
614
 
96
- specialists run executor --bead unitAI-abc &
615
+ specialists run executor --bead unitAI-abc --context-depth 2 --background
97
616
  ```
98
617
 
99
- This pattern was used extensively in Wave 5 of a real session — 4 executors all received
100
- writing instructions via bead notes and successfully produced doc files.
101
-
102
618
  **`--context-depth N`** — how many levels of parent-bead context to inject (default: 1).
619
+ Use **`--context-depth 2`** for all chained bead workflows. This gives each specialist its
620
+ own bead + the immediate predecessor's output + one more level of context.
621
+
103
622
  **`--no-beads`** — skip creating an auto-tracking sub-bead, but still reads the `--bead` input.
104
623
 
624
+ **Edit gate access**: Specialists with `--bead` automatically set `bead-claim:<id>` KV key,
625
+ enabling write access in worktrees without session-scoped claims. Cleared on run completion.
626
+
105
627
  ---
106
628
 
107
629
  ## Choosing the Right Specialist
@@ -110,37 +632,126 @@ Run `specialists list` to see what's available. Match by task type:
110
632
 
111
633
  | Task type | Best specialist | Why |
112
634
  |-----------|----------------|-----|
113
- | Bug fix / implementation | **executor** (gpt-5.3-codex) | HIGH perms, writes code + tests autonomously |
114
- | Bug investigation / "why is X broken" | **debugger** (claude-sonnet-4-6) | GitNexus-first triage, 5-phase investigation, hypothesis ranking, evidence-backed remediation. Use for ANY root cause analysis. |
115
- | Design decisions / tradeoffs | **overthinker** (gpt-5.4) | 4-phase reasoning: analysis, devil's advocate, synthesis, conclusion. Interactive by default (`execution.interactive: true`). |
116
- | Code review / compliance | **reviewer** (claude-sonnet-4-6) | Post-run compliance checks, verdict contract (PASS/PARTIAL/FAIL). Interactive by default (`execution.interactive: true`). |
117
- | Multi-backend review | **parallel-review** (claude-sonnet-4-6) | Concurrent review across multiple AI backends |
118
- | Architecture exploration | **explorer** (claude-haiku-4-5) | Fast codebase mapping, READ_ONLY |
119
- | Reference docs / dense schemas | **explorer** (claude-haiku-4-5) | Better than sync-docs for reference-heavy output |
120
- | Planning / scoping | **planner** (claude-sonnet-4-6) | Structured issue breakdown with deps |
121
- | Doc audit / drift detection | **sync-docs** (claude-sonnet-4-6) | Interactive by default (`execution.interactive: true`): audits first, then approve/deny via `resume` |
122
- | Doc drift / audit | **sync-docs** (claude-sonnet-4-6) | Detects stale docs, restructures content |
123
- | Doc writing / updates | **executor** (gpt-5.3-codex) | sync-docs defaults to audit mode; executor writes files |
124
- | Test generation | **test-runner** (claude-haiku-4-5) | Runs suites, interprets failures |
125
- | Specialist authoring | **specialists-creator** (claude-sonnet-4-6) | Guides YAML creation against schema |
126
-
127
- ### Specialist selection lessons (from real sessions)
128
-
129
- - **debugger** is the most powerful investigation specialist. Uses GitNexus call-chain tracing (when available) for 5-phase root cause analysis with ranked hypotheses. Use for ANY "why is X broken" question don't do the investigation yourself.
130
- - **sync-docs** is an interactive specialist it audits first, then waits for approval before executing. This is correct behavior, not a bug.
131
- - **overthinker** and **reviewer** are also interactive.
132
- - Canonical pattern: orchestration is CLI-first (`specialists run/feed/result/steer/resume/stop`); use MCP only for one-shot `use_specialist` runs.
133
- - Use `--no-keep-alive` only when you explicitly want a one-shot run.
134
- - **explorer** is fast and cheap (Haiku) but READ_ONLY output auto-appends to the input bead's notes. Use for investigation, not implementation.
135
- - **executor** is the workhorse HIGH permissions, writes code and docs, runs tests, closes beads. Best for any task that needs files written.
136
- - **use_specialist MCP** is best for quick foreground runs where you need the result immediately in your context.
137
-
138
- ### Pi extensions availability (known gap)
139
-
140
- GitNexus and Serena are **pi extensions** (not MCP servers) at `~/.pi/agent/extensions/`.
141
- Specialists run with `--no-extensions` and only selectively re-enable `quality-gates` and
142
- `service-skills`. GitNexus (call-chain tracing for debugger/planner) and Serena LSP
143
- (token-efficient reads for explorer/executor) are NOT currently wired. Tracked as `unitAI-4abv`.
635
+ | Architecture exploration / initial discovery | **explorer** (claude-haiku) | Fast codebase mapping, READ_ONLY. Output auto-appends to bead. |
636
+ | Live docs / library lookup / code discovery | **researcher** (claude-haiku) | Targeted (ctx7/deepwiki) or discovery (ghgrep deepwiki) modes. `--keep-alive`. |
637
+ | Bug fix / feature implementation | **executor** (gpt-codex) | HIGH perms, writes code, runs lint+tsc, closes beads. `interactive: true` by default — enters `waiting` after first turn, orchestrator must stop explicitly. |
638
+ | Bug investigation / "why is X broken" | **debugger** (claude-sonnet) | 4-phase debug-fix-verify cycle. HIGH perms, keep-alive. GitNexus-first. |
639
+ | Complex design / tradeoff analysis | **overthinker** (gpt-4) | 4-phase: analysis devil's advocate synthesis → conclusion. `--keep-alive`. |
640
+ | Code review / compliance | **reviewer** (claude-sonnet) | PASS/PARTIAL/FAIL verdict. Use via `--job <exec-job>`. `--keep-alive`. |
641
+ | Multi-backend review | **parallel-review** (claude-sonnet) | Concurrent review across multiple backends |
642
+ | Planning / scoping | **planner** (claude-sonnet) | Structured issue breakdown with deps |
643
+ | Doc audit / drift detection / targeted sync | **sync-docs** (qwen3.5-plus) | 3-mode: targeted (named docs), area (time-window), full audit. MEDIUM perms, `--keep-alive`. |
644
+ | Doc writing / updates | **executor** (gpt-codex) | For heavy doc rewrites; sync-docs handles targeted updates directly |
645
+ | Test generation / suite execution | **test-runner** (claude-haiku) | Runs suites, interprets failures |
646
+ | Specialist authoring | **specialists-creator** (claude-sonnet) | Guides JSON creation against schema |
647
+
648
+ ### Specialist selection notes
649
+
650
+ - **executor does not run tests** — it runs `lint + tsc` only. Tests belong to the reviewer or test-runner phase.
651
+ - **executor enters `waiting` after first turn** `interactive: true` is now default. If executor bails early (e.g. GitNexus CRITICAL risk warning), orchestrator can `resume` with "proceed, this is additive" instead of re-dispatching. Always `stop` executor explicitly when work is complete.
652
+ - **explorer** is READ_ONLYits output auto-appends to the input bead's notes. No implementation.
653
+ - **reviewer** is best dispatched via `--job <exec-job> --prompt "..."` — it enters the same worktree to see exactly what was written. `--job` alone is not enough; `--prompt` or `--bead` is always required.
654
+ - **debugger** over **explorer** when you need root cause analysis GitNexus call-chain tracing, ranked hypotheses, evidence-backed remediation.
655
+ - **overthinker** before **executor** for any non-trivial task surfaces edge cases, challenges assumptions, produces solution direction. Cheap relative to wrong implementation.
656
+ - **researcher** is the docs specialistnever look up library docs yourself, delegate to researcher.
657
+ - **sync-docs** is interactivealways `--keep-alive`, use `resume` to approve/deny after audit.
658
+
659
+ ### Example dispatches
660
+
661
+ ```bash
662
+ specialists run explorer --bead unitAI-exp --context-depth 2 --background
663
+ specialists run researcher --bead unitAI-research --context-depth 2 --keep-alive --background
664
+ specialists run debugger --bead unitAI-bug --context-depth 2 --background
665
+ specialists run planner --bead unitAI-scope --context-depth 2 --background
666
+ specialists run overthinker --bead unitAI-design --context-depth 2 --keep-alive --background
667
+ specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
668
+ specialists run reviewer --job <exec-job-id> --keep-alive --background --prompt "Review the <feature> implementation"
669
+ specialists run sync-docs --bead unitAI-docs --context-depth 2 --keep-alive --background
670
+ specialists run test-runner --bead unitAI-tests --context-depth 2 --background
671
+ specialists run specialists-creator --bead unitAI-skill --context-depth 2 --background
672
+ ```
673
+
674
+ ### Overthinker-first pattern for complex tasks
675
+
676
+ ```bash
677
+ # Full chain: task → explore → design → impl
678
+ bd create --title "Redesign auth middleware" --type feature --priority 2 # -> unitAI-task
679
+ bd create --title "Explore: map auth middleware" --type task --priority 2 # -> unitAI-exp
680
+ bd dep add exp task
681
+ bd create --title "Design: auth middleware approach" --type task --priority 2 # -> unitAI-design
682
+ bd dep add design exp
683
+ bd create --title "Implement: auth middleware redesign" --type task --priority 2 # -> unitAI-impl
684
+ bd dep add impl design
685
+
686
+ # Wave 1: Explorer
687
+ specialists run explorer --bead unitAI-exp --context-depth 2 --background
688
+ # (output auto-appends to exp notes)
689
+
690
+ # Wave 2: Overthinker (sees exp findings via context-depth)
691
+ specialists run overthinker --bead unitAI-design --context-depth 2 --keep-alive --background
692
+ # enters waiting after Phase 4
693
+
694
+ specialists resume <job-id> "What about the edge case where X?"
695
+ specialists resume <job-id> "Is option B safer than option A here?"
696
+ specialists stop <job-id> # when satisfied
697
+ # (overthinker output is on unitAI-design notes)
698
+
699
+ # Wave 3: Executor (sees design + exp + task via context-depth — no manual wiring)
700
+ specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
701
+ ```
702
+
703
+ ### Monitoring with `sp ps` and `sp list --live`
704
+
705
+ Use `specialists ps` (alias `sp ps`) for job monitoring instead of manual JSON polling:
706
+
707
+ ```bash
708
+ # Quick overview — all jobs
709
+ specialists ps
710
+ # Output: ID, status, specialist, elapsed, bead, [ctx%] badge
711
+
712
+ # Inspect specific job
713
+ specialists ps <job-id>
714
+ # Shows: full status, worktree path, chain, ctx% (context window utilization)
715
+
716
+ # The ctx% in `sp feed` and `sp ps` shows context window utilization:
717
+ # - 0-40% = OK (plenty of room)
718
+ # - 40-65% = MONITOR
719
+ # - 65-80% = WARN (▲ indicator shown)
720
+ # - >80% = CRITICAL (▲ indicator shown)
721
+ ```
722
+
723
+ **Live tmux session selector (`sp list --live`):**
724
+
725
+ ```bash
726
+ # Interactive selector for running/waiting tmux sessions
727
+ specialists list --live
728
+ # Shows: tmux session name, specialist, elapsed, status
729
+ # Arrow keys to select, Enter to attach
730
+
731
+ # Include dead sessions (PID or tmux gone)
732
+ specialists list --live --show-dead
733
+ # Dead sessions shown with 'dead' status instead of filtered out
734
+ ```
735
+
736
+ Dead job detection (`is_dead`) is computed at read time — never persisted to avoid stale state. A job is dead when:
737
+ - PID no longer exists (`kill -0 <pid>` fails)
738
+ - tmux session gone (`tmux has-session -t <name>` fails or times out)
739
+
740
+ ---
741
+
742
+ ### Pi extensions and packages
743
+
744
+ Pi extensions are global at `~/.pi/agent/extensions/`. Pi packages are global npm installs.
745
+ Specialists run with `--no-extensions` and selectively re-enable:
746
+
747
+ - `quality-gates` — lint/typecheck enforcement (non-READ_ONLY only)
748
+ - `service-skills` — service catalog activation
749
+ - `pi-gitnexus` — call-chain tracing, blast radius analysis (resolved from global npm)
750
+ - `pi-serena-tools` — token-efficient LSP reads/edits (resolved from global npm)
751
+
752
+ When gitnexus tools are used during a run, the supervisor accumulates a `gitnexus_summary`
753
+ in the `run_complete` event: `files_touched`, `symbols_analyzed`, `highest_risk`,
754
+ `tool_invocations`.
144
755
 
145
756
  ---
146
757
 
@@ -149,135 +760,178 @@ Specialists run with `--no-extensions` and only selectively re-enable `quality-g
149
760
  ### Steer — redirect any running job
150
761
 
151
762
  `steer` sends a message to a running specialist. Delivered after the current tool call
152
- finishes, before the next LLM call. Works for **all running jobs**.
763
+ finishes, before the next LLM call.
153
764
 
154
765
  ```bash
155
- # Specialist is going off track — redirect it
156
766
  specialists steer a1b2c3 "STOP what you are doing. Focus only on supervisor.ts"
157
-
158
- # Specialist is auditing when it should be writing
159
767
  specialists steer a1b2c3 "Do NOT audit. Write the actual file to disk now."
160
768
  ```
161
769
 
162
- Real example from today: an explorer was reading every file in src/cli/ when we only needed
163
- confirmation that steering worked. Sent `specialists steer 763ff4 "STOP. Just output:
164
- STEERING WORKS"` — message delivered, output confirmed in 2 seconds.
770
+ ### Resume continue a keep-alive session
165
771
 
166
- ### Resume continue an interactive session
772
+ `resume` sends a new prompt to a specialist in `waiting` state. Retains full conversation history.
167
773
 
168
- `resume` sends a new prompt to a specialist that has finished its turn and is `waiting`.
169
- Works for jobs started with keep-alive behavior (including specialists with `execution.interactive: true`).
170
- The session retains full conversation history.
774
+ **Specialists that always use `--keep-alive`:**
171
775
 
172
- ```bash
173
- # Start an overthinker for multi-turn design work
174
- # overthinker is interactive by default, so no extra flag is required
175
- specialists run overthinker --bead unitAI-xyz &
176
- # -> Job started: d4e5f6 (completes Phase 4, enters waiting state)
776
+ | Specialist | Enters `waiting` after | What to send via `resume` |
777
+ |-----------|----------------------|--------------------------|
778
+ | **executor** | First turn completion (may be partial if bailed early) | "proceed, this is additive", "address the risk warning and continue", or "done, close bead" |
779
+ | **researcher** | Delivering research findings | Follow-up question, new angle, or "done, thanks" |
780
+ | **reviewer** | Delivering verdict (PASS/PARTIAL/FAIL) | Your response, clarification, or "accepted, close out" |
781
+ | **overthinker** | Phase 4 conclusion | Follow-up question, counter-argument, or "done, thanks" |
782
+ | **debugger** | Phase 3 fix attempt or Phase 4 verify result | Follow-up fix, "try different approach", or "done" |
783
+ | **sync-docs** | Audit report or targeted update result | "approve", "deny", or specific instructions |
177
784
 
178
- # Read the design output
179
- specialists result d4e5f6
785
+ > **Warning:** A job in `waiting` looks identical to a stalled job. **Always check with `sp ps`
786
+ > before killing a keep-alive job.**
180
787
 
181
- # Ask follow-up questions
182
- specialists resume d4e5f6 "What about backward compatibility with existing YAML files?"
183
- specialists resume d4e5f6 "How would you handle migration from the old schema?"
184
- ```
788
+ ```bash
789
+ # Check before stopping
790
+ specialists ps d4e5f6
791
+ # -> status: waiting ← healthy, expecting input
185
792
 
186
- Use interactive specialists when you plan to iterate: design reviews, multi-phase analysis,
187
- investigation that may need follow-up questions based on findings.
188
- Use `--no-keep-alive` only when you want to force single-turn behavior.
793
+ specialists resume d4e5f6 "What about backward compatibility?"
794
+ specialists stop d4e5f6 # only when truly done iterating
795
+ ```
189
796
 
190
797
  ---
191
798
 
192
- ## Wave Orchestration
799
+ ## Chain and Epic Orchestration
800
+
801
+ For multi-step work, dispatch chains under an **epic**.
193
802
 
194
- For multiple independent tasks, dispatch specialists in parallel waves.
803
+ A **chain** is a worktree lineage (executor → reviewer → fix → re-review). Chains within the same epic may run in parallel **only if they are independent** (disjoint file scopes). Stages are strictly sequential: **never start Stage N+1 before Stage N completes AND is merged via `sp epic merge`**.
195
804
 
196
- ### Planning a wave
805
+ ### Chain rules
197
806
 
198
- Group tasks by dependency:
199
- 1. **Wave 1**: Bug fixes and blockers (unblock downstream work)
200
- 2. **Wave 2**: Features and design (now that the surface is stable)
201
- 3. **Wave 3**: Documentation (after code changes land use executors, not sync-docs)
807
+ 1. **Sequence between stages.** Prep (explorer/planner) → implementation chains → review → tests → doc sync.
808
+ 2. **Parallelize only within a stage.** Chains that don't depend on each other may run together.
809
+ 3. **Do not overlap stages.** Wait for every chain job, read results, update beads, merge epic.
810
+ 4. **Bead deps encode the pipeline.** The dependency graph should match stage order.
811
+ 5. **`--context-depth 2` for all chained runs.** Each specialist sees parent + predecessor.
812
+ 6. **Merge via `sp epic merge` is mandatory.** See Merge Protocol above.
202
813
 
203
- ### Dispatching a wave
814
+ ### Polling chains
204
815
 
205
816
  ```bash
206
- # Fire multiple specialists in parallel (--background for reliable detach)
207
- specialists run executor --bead unitAI-abc --background
208
- specialists run executor --bead unitAI-def --background
209
- specialists run overthinker --bead unitAI-ghi --background
817
+ specialists ps # list all jobs shows epic grouping, status, elapsed
818
+ specialists ps abc123 # inspect specific job (full detail)
819
+ specialists ps --follow # live dashboard with epic grouping
210
820
  ```
211
821
 
212
- ### Monitoring a wave
822
+ `sp ps` shows epic-level grouping:
213
823
 
214
- ```bash
215
- # Quick status check on all jobs
216
- for job in abc123 def456 ghi789; do
217
- python3 -c "import json; d=json.load(open('.specialists/jobs/$job/status.json')); \
218
- print(f'$job {d[\"specialist\"]:12} {d[\"status\"]:10} {d.get(\"elapsed_s\",\"?\")}s')"
219
- done
220
-
221
- # Or use feed for event-level detail
222
- specialists feed <job-id>
824
+ ```
825
+ epic:unitAI-3f7b · merge_ready · state:resolving · prep done=2/2 · chains pass=3/3
826
+ prep:exp-1 · done
827
+ prep:plan-2 · done
828
+ chain:impl-a (reviewer PASS) · branch:feature/unitAI-impl-a-executor
829
+ chain:impl-b (reviewer PASS) · branch:feature/unitAI-impl-b-executor
830
+ chain:impl-c (reviewer PASS) · branch:feature/unitAI-impl-c-executor
223
831
  ```
224
832
 
225
- ### Between waves
226
-
227
- After each wave completes:
228
- 1. **Read results**: `specialists result <job-id>` for each
229
- 2. **Validate**: run lint + tests on the combined output
230
- 3. **Commit**: stage, commit, push — clean git before next wave
231
- 4. **Close beads**: `bd close <id> --reason "..."`
833
+ A stage is complete when every chain is terminal AND you have:
834
+ 1. Read results: `specialists result <job-id>` for each
835
+ 2. Updated/closed beads as needed
836
+ 3. Published via `sp epic merge <epic-id>`
232
837
 
233
- ### Real wave example (from a 6-wave session)
838
+ ### Canonical multi-stage example
234
839
 
235
- ```
236
- Wave 1: 2x executor stabilized background job execution and supervisor lifecycle
237
- Wave 2: overthinker + 2x executor output contract design + retry logic + footer fix
238
- Wave 3: 4x sync-docs + 3x explorer → docs audit (produced reports, not files)
239
- Wave 4: 5x executor + 2x explorer → output contract impl + READ_ONLY auto-append + 4 fixes
240
- Wave 5: 4x executor rewrote 4 doc files (executors write files, sync-docs only audits)
241
- Wave 6: 4x executor + overthinker (interactive) cleanup + manifest design with follow-ups
840
+ ```bash
841
+ # 0. Create epic bead (top merge-gated identity)
842
+ bd create --title "Add worktree isolation to executor" --type epic --priority 1
843
+ # -> unitAI-3f7b
844
+
845
+ # 1. Create prep and impl beads as children of the epic
846
+ bd create --title "Explore: map job run architecture" --type task --priority 2 # -> unitAI-exp
847
+ bd dep add exp 3f7b
848
+ bd create --title "Implement: worktree isolation" --type task --priority 2 # -> unitAI-impl
849
+ bd dep add impl exp
850
+ # Note: reviewer runs via --job, inherits epic from impl bead.parent
851
+
852
+ # Stage 1 — Explorer (prep job, declares epic explicitly)
853
+ specialists run explorer --bead unitAI-exp --epic unitAI-3f7b --context-depth 2 --background
854
+ # -> Job started: job1
855
+ specialists result job1
856
+
857
+ # [NO MERGE] Prep stage has no worktrees to merge
858
+
859
+ # Stage 2 — Executor (chain inherits epic from bead.parent)
860
+ specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
861
+ # -> Job started: job2 (worktree: .worktrees/unitAI-impl/unitAI-impl-executor)
862
+ # epic_id = bead.parent (unitAI-3f7b)
863
+ specialists result job2
864
+
865
+ # Stage 3 — Reviewer (uses --job, same worktree)
866
+ specialists run reviewer --job job2 --keep-alive --background --prompt "Review implementation"
867
+ # -> Job started: job3
868
+ specialists result job3
869
+ # PASS → ready for epic merge. PARTIAL → fix loop.
870
+
871
+ # Stage 4 — Fix loop (if PARTIAL)
872
+ bd create --title "Fix: reviewer gaps on impl" --type bug --priority 1 # -> unitAI-fix1
873
+ bd dep add fix1 impl
874
+ specialists run executor --bead fix1 --job job2 --context-depth 2 --background
875
+ # Re-review
876
+ specialists run reviewer --job job2 --keep-alive --background --prompt "Re-review after fix"
877
+
878
+ # [MERGE] Publish epic
879
+ sp epic status unitAI-3f7b # verify readiness: merge_ready, all chains PASS
880
+ sp epic merge unitAI-3f7b --rebuild
881
+
882
+ # Close
883
+ bd close 3f7b --reason "Worktree isolation implemented. Reviewer PASS. Epic merged."
242
884
  ```
243
885
 
244
- Key insight: **executors write files, sync-docs audits**. When you need docs written
245
- to disk, use executor with bead notes containing "INSTRUCTION: Write <file>...".
886
+ ### Within-stage parallelism (multiple chains)
887
+
888
+ ```bash
889
+ # Parallel executors — disjoint files, same parent epic
890
+ bd create --title "Implement: component A" --type task --priority 2 # -> unitAI-impl-a
891
+ bd dep add impl-a exp
892
+ bd create --title "Implement: component B" --type task --priority 2 # -> unitAI-impl-b
893
+ bd dep add impl-b exp
894
+
895
+ specialists run executor --worktree --bead unitAI-impl-a --context-depth 2 --background
896
+ specialists run executor --worktree --bead unitAI-impl-b --context-depth 2 --background
897
+ # Each runs in its own worktree, both belong to unitAI-3f7b (via bead.parent)
898
+
899
+ # Do NOT start next stage until BOTH complete AND epic is merged
900
+ sp epic merge unitAI-3f7b
901
+ ```
246
902
 
247
903
  ---
248
904
 
249
905
  ## Coordinator Responsibilities
250
906
 
251
- As the orchestrator, you own things specialists cannot do:
907
+ ### 1. Route work don't explore or implement yourself
908
+ Discovery goes to **explorer** first; implementation goes to **executor** only after discovery is done.
252
909
 
253
- ### 1. Validate combined output across specialists
254
- Multiple specialists writing to the same worktree can conflict. After each wave:
910
+ ### 2. Validate combined output after each stage
255
911
  ```bash
256
- npm run lint # or project-specific quality gate
257
- bun test # run affected tests
912
+ npm run lint # project quality gate
913
+ npx tsc --noEmit # type check
258
914
  git diff --stat # review what changed
259
915
  ```
260
916
 
261
- ### 2. Handle failures — don't silently fall back
262
- If a specialist stalls or errors, surface it. Don't quietly do the work yourself.
917
+ ### 3. Handle failures — don't silently fall back
263
918
  ```bash
264
919
  specialists feed <job-id> # see what happened
920
+ specialists doctor # check for systemic issues
265
921
  ```
266
922
 
267
923
  Options when a specialist fails:
268
- - **Steer** it back on track: `specialists steer <id> "Focus on X instead"`
269
- - **Switch specialist** (e.g., sync-docs stalls → try explorer or executor)
924
+ - **Steer**: `specialists steer <id> "Focus on X instead"`
925
+ - **Switch**: e.g. sync-docs stalls → try executor
270
926
  - **Stop and report** to the user before doing it yourself
271
927
 
272
- ### 3. Close beads and commit between waves
273
- Keep git clean between waves. Specialists write to the same worktree, so stacking
274
- uncommitted changes from multiple waves creates merge pain.
928
+ ### 4. Merge via epic (CRITICAL)
929
+ See Merge Protocol above. Use `sp epic merge <epic-id>` no exceptions.
275
930
 
276
- ### 4. Run drift detection after doc-heavy sessions
931
+ ### 5. Run drift detection after doc-heavy sessions
277
932
  ```bash
278
- python3 .agents/skills/sync-docs/scripts/drift_detector.py scan --json
279
- # Then dispatch executor for any stale docs, stamp synced_at on fresh ones:
280
- python3 .agents/skills/sync-docs/scripts/drift_detector.py update-sync <file>
933
+ python3 .xtrm/skills/default/sync-docs/scripts/drift_detector.py scan --json
934
+ python3 .xtrm/skills/default/sync-docs/scripts/drift_detector.py update-sync <file>
281
935
  ```
282
936
 
283
937
  ---
@@ -286,31 +940,47 @@ python3 .agents/skills/sync-docs/scripts/drift_detector.py update-sync <file>
286
940
 
287
941
  | Tool | Purpose |
288
942
  |------|---------|
289
- | `use_specialist` | Foreground run; pass `bead_id` for tracked work and get final output directly in conversation context |
290
-
291
- MCP is intentionally minimal. Use CLI commands for orchestration, monitoring, steering,
292
- resume, and cancellation.
293
- If you encounter legacy `start_specialist`, treat it as deprecated and migrate to
294
- `specialists run <name> --prompt "..." --background`.
943
+ | `use_specialist` | Foreground run; pass `bead_id` for tracked work, get final output in conversation context |
295
944
 
296
- ---
945
+ MCP is intentionally minimal. Use CLI for orchestration, monitoring, steering, resume, and cancellation.
297
946
 
298
947
  ---
299
948
 
300
949
  ## Known Issues
301
950
 
302
- - **sync-docs audit-first behavior is expected** for interactive review/audit flow.
303
- Start normally, read the audit output, then `specialists resume <job-id> "approved: execute phase 4-5"`
304
- if you want it to apply fixes.
305
- - **READ_ONLY output auto-appends** to the input bead after completion. No manual piping
306
- needed (fixed in the Supervisor). But the output also lives in `specialists result`.
951
+ - **READ_ONLY output auto-appends** to the input bead after completion (via Supervisor). Output also available via `specialists result`.
952
+ - **`--bead` and `--prompt` conflict** by design. For tracked work, update bead notes: `bd update <id> --notes "INSTRUCTION: ..."` then `--bead` only.
953
+ - **Job in `waiting` now shows magenta status** with resume hint in `status`, WAIT banner in `feed`, and resume footer in `result`. Always check before stopping a keep-alive job.
954
+ - **Explorer (qwen) may produce empty output** the model sometimes completes tool calls but fails to emit a final text summary. The bead notes will be empty. If this happens, either re-run with a different model or do the investigation yourself.
955
+ - **`specialists init` requires xtrm** `.xtrm/` directory and `xt` CLI must exist. Use `--no-xtrm-check` to bypass in CI/testing.
956
+ - **`specialists doctor` now detects skill drift** — compares `config/skills/` hashes against `.xtrm/skills/default/` and validates symlink chains.
307
957
 
308
958
  ---
309
959
 
310
960
  ## Troubleshooting
311
961
 
962
+ ```bash
963
+ specialists doctor # health check: hooks, MCP, zombie jobs, skill drift detection
964
+ specialists edit <name> # edit specialist config (dot-path, --preset)
965
+ specialists clean --processes # kill stale/zombie specialist processes
966
+ ```
967
+
968
+ - **RPC timeout on worktree job start** (30s, `command id=1`) → pi runs `npm install` in fresh
969
+ worktrees if `.pi/settings.json` lists local packages. Root cause: worktree gets a stale copy
970
+ of `.pi/settings.json` from the branch point. Fix: ensure `.pi/settings.json` has
971
+ `"packages": []` (packages are global now). `provisionWorktree()` also symlinks
972
+ `.pi/npm/node_modules` to the main repo's as a safety net.
973
+ - **RPC timeout on non-worktree job** → check for: (1) zombie vitest/tinypool processes
974
+ (`ps aux | grep vitest`, then `kill`), (2) stale dist (`npm run build`),
975
+ (3) model provider issues (try a different model to isolate).
312
976
  - **"specialist not found"** → `specialists list` (project-scope only)
313
977
  - **Job hangs** → `specialists steer <id> "finish up"` or `specialists stop <id>`
314
- - **YAML skipped** → stderr shows `[specialists] skipping <file>: <reason>`
315
- - **Stall timeout** → specialist hit 120s inactivity. Check `specialists feed <id>`, then retry or switch specialist.
978
+ - **Config skipped** → stderr shows `[specialists] skipping <file>: <reason>`
979
+ - **Stall timeout** → specialist hit 120s inactivity. Check `specialists feed <id>`, then retry or switch.
316
980
  - **`--prompt` and `--bead` conflict** → use bead notes: `bd update <id> --notes "INSTRUCTION: ..."` then `--bead` only.
981
+ - **Worktree already exists** → it will be reused (not recreated). Safe to re-run.
982
+ - **`--job` fails: worktree_path missing** → target job was not started with `--worktree`. Use `--worktree` on the next run.
983
+ - **`--job` without `--prompt` or `--bead`** → reviewer/executor requires one of these. Use `--prompt "Review the X implementation"` with `--job`.
984
+ - **Stale specialist processes** → SessionStart hook warns about old binary versions. Run `specialists clean --processes` to kill them all.
985
+ - **`specialists init` fails with xtrm error** → xtrm must be installed first: `npm install -g xtrm-tools && xt install`. Use `--no-xtrm-check` in CI.
986
+ - **Skill drift detected by doctor** → Run `specialists init --sync-skills` to re-sync canonical skills to `.xtrm/skills/default/` and refresh active symlinks.