xtrm-tools 0.7.17 → 0.7.18

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