xtrm-tools 0.7.4 → 0.7.9

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 (85) hide show
  1. package/.xtrm/config/pi/extensions/custom-footer/.pi/structured-returns/83051fe4-97da-4e2c-bdaa-343b32f4e714.combined.log +7 -0
  2. package/.xtrm/config/pi/extensions/custom-footer/.pi/structured-returns/83051fe4-97da-4e2c-bdaa-343b32f4e714.stderr.log +0 -0
  3. package/.xtrm/config/pi/extensions/custom-footer/.pi/structured-returns/83051fe4-97da-4e2c-bdaa-343b32f4e714.stdout.log +7 -0
  4. package/.xtrm/registry.json +537 -565
  5. package/.xtrm/skills/default/gitnexus-cli/SKILL.md +82 -0
  6. package/.xtrm/skills/default/gitnexus-exploring/SKILL.md +78 -0
  7. package/.xtrm/skills/default/gitnexus-guide/SKILL.md +64 -0
  8. package/.xtrm/skills/default/init-session/SKILL.md +3 -0
  9. package/.xtrm/skills/default/last30days/SKILL.md +1 -1
  10. package/.xtrm/skills/default/last30days/scripts/lib/youtube_yt.py +59 -40
  11. package/.xtrm/skills/default/sync-docs/references/doc-structure.md +1 -1
  12. package/.xtrm/skills/default/sync-docs/references/schema.md +1 -1
  13. package/.xtrm/skills/default/sync-docs/scripts/doc_structure_analyzer.py +2 -2
  14. package/.xtrm/skills/default/using-specialists/SKILL.md +346 -138
  15. package/.xtrm/skills/default/using-specialists/SKILL.safe.md +1082 -0
  16. package/.xtrm/skills/default/using-specialists/SKILL.ultra.md +1082 -0
  17. package/.xtrm/skills/default/vaultctl/SKILL.md +150 -0
  18. package/CHANGELOG.md +4 -4
  19. package/cli/dist/index.cjs +392 -194
  20. package/cli/dist/index.cjs.map +1 -1
  21. package/cli/package.json +1 -1
  22. package/package.json +8 -7
  23. package/packages/pi-extensions/MIGRATION_NOTES.md +39 -0
  24. package/packages/pi-extensions/README.md +43 -0
  25. package/packages/pi-extensions/extensions/README.md +5 -0
  26. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/beads/index.ts +1 -1
  27. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/beads/package.json +1 -4
  28. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/custom-footer/index.ts +1 -1
  29. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/custom-footer/package.json +1 -4
  30. package/packages/pi-extensions/extensions/custom-provider-qwen-cli/package.json +16 -0
  31. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/pi-serena-compact/package.json +9 -2
  32. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/quality-gates/index.ts +1 -1
  33. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/quality-gates/package.json +1 -4
  34. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/service-skills/index.ts +1 -1
  35. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/service-skills/package.json +1 -4
  36. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/session-flow/index.ts +1 -1
  37. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/session-flow/package.json +1 -4
  38. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/xtrm-loader/index.ts +1 -1
  39. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/xtrm-loader/package.json +1 -4
  40. package/{.xtrm/config/pi → packages/pi-extensions}/extensions/xtrm-ui/index.ts +1 -1
  41. package/packages/pi-extensions/package.json +46 -0
  42. package/packages/pi-extensions/src/core/README.md +9 -0
  43. package/packages/pi-extensions/src/core/index.ts +5 -0
  44. package/packages/pi-extensions/src/extensions/auto-session-name.ts +3 -0
  45. package/packages/pi-extensions/src/extensions/auto-update.ts +3 -0
  46. package/packages/pi-extensions/src/extensions/beads.ts +3 -0
  47. package/packages/pi-extensions/src/extensions/compact-header.ts +3 -0
  48. package/packages/pi-extensions/src/extensions/custom-footer.ts +3 -0
  49. package/packages/pi-extensions/src/extensions/custom-provider-qwen-cli.ts +3 -0
  50. package/packages/pi-extensions/src/extensions/git-checkpoint.ts +3 -0
  51. package/packages/pi-extensions/src/extensions/lsp-bootstrap.ts +3 -0
  52. package/packages/pi-extensions/src/extensions/pi-serena-compact.ts +3 -0
  53. package/packages/pi-extensions/src/extensions/quality-gates.ts +3 -0
  54. package/packages/pi-extensions/src/extensions/service-skills.ts +3 -0
  55. package/packages/pi-extensions/src/extensions/session-flow.ts +3 -0
  56. package/packages/pi-extensions/src/extensions/xtrm-loader.ts +3 -0
  57. package/packages/pi-extensions/src/extensions/xtrm-ui.ts +3 -0
  58. package/packages/pi-extensions/src/index.ts +9 -0
  59. package/packages/pi-extensions/src/registry.ts +52 -0
  60. package/packages/pi-extensions/src/shared/index.ts +1 -0
  61. package/packages/pi-extensions/src/shared/legacy-path-map.ts +23 -0
  62. package/{.xtrm/config/pi/extensions/xtrm-ui/themes → packages/pi-extensions/themes/xtrm-ui}/pidex-dark.json +3 -7
  63. package/{.xtrm/config/pi/extensions/xtrm-ui/themes → packages/pi-extensions/themes/xtrm-ui}/pidex-light.json +0 -4
  64. package/.xtrm/config/pi/extensions/core/package.json +0 -18
  65. package/.xtrm/config/pi/extensions/custom-provider-qwen-cli/package.json +0 -1
  66. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/auto-session-name/index.ts +0 -0
  67. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/auto-session-name/package.json +0 -0
  68. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/auto-update/index.ts +0 -0
  69. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/auto-update/package.json +0 -0
  70. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/compact-header/index.ts +0 -0
  71. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/compact-header/package.json +0 -0
  72. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/custom-provider-qwen-cli/index.ts +0 -0
  73. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/git-checkpoint/index.ts +0 -0
  74. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/git-checkpoint/package.json +0 -0
  75. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/lsp-bootstrap/index.ts +0 -0
  76. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/lsp-bootstrap/package.json +0 -0
  77. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/pi-serena-compact/index.ts +0 -0
  78. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/xtrm-ui/format.ts +0 -0
  79. /package/{.xtrm/config/pi → packages/pi-extensions}/extensions/xtrm-ui/package.json +0 -0
  80. /package/{.xtrm/config/pi/extensions → packages/pi-extensions/src}/core/adapter.ts +0 -0
  81. /package/{.xtrm/config/pi/extensions → packages/pi-extensions/src}/core/guard-rules.ts +0 -0
  82. /package/{.xtrm/config/pi/extensions → packages/pi-extensions/src}/core/lib.ts +0 -0
  83. /package/{.xtrm/config/pi/extensions → packages/pi-extensions/src}/core/logger.ts +0 -0
  84. /package/{.xtrm/config/pi/extensions → packages/pi-extensions/src}/core/runner.ts +0 -0
  85. /package/{.xtrm/config/pi/extensions → packages/pi-extensions/src}/core/session-state.ts +0 -0
@@ -4,13 +4,13 @@ description: >
4
4
  Use this skill whenever you're about to start a substantial task — pause first and
5
5
  route the work through specialists instead of doing discovery or implementation
6
6
  yourself. Consult before any: code review, security audit, deep bug investigation,
7
- test generation, multi-file refactor, architecture analysis, or multi-wave
7
+ test generation, multi-file refactor, architecture analysis, or multi-chain
8
8
  specialist orchestration. Also use for the mechanics of delegation: --bead
9
9
  workflow, --context-depth, background jobs, MCP tool (`use_specialist`),
10
10
  or specialists doctor. Don't wait for the user to say
11
11
  "use a specialist" — proactively evaluate whether delegation makes sense.
12
- version: 4.4
13
- synced_at: a1e9f935
12
+ version: 4.6
13
+ synced_at: zz22-docs
14
14
  ---
15
15
 
16
16
  # Specialists Usage
@@ -36,10 +36,11 @@ Specialists are autonomous AI agents that run independently — fresh context, d
36
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
37
  4. **For tracked work, the bead is the prompt.** The bead description, notes, and parent context are the instruction surface.
38
38
  5. **`--bead` and `--prompt` are mutually exclusive.** If you need to refine instructions, update the bead notes; do not add `--prompt`.
39
- 6. **Wave sequencing is strict.** Never start wave N+1 before wave N is complete AND merged. Within-wave parallelism is fine only for independent jobs.
40
- 7. **Merge between waves is mandatory.** Executor worktree branches must be merged into master before the next wave starts. Use `sp merge <epic-id>` or `sp merge <chain-root-bead>` never manual git merge. See "Merge Protocol" below.
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
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
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.
43
+ 10. **Keep specialists alive through the review cycle.** Never `sp stop` an executor or debugger before the reviewer delivers its verdict. The specialist stays in `waiting` so you can `resume` it — to commit changes, apply fixes from reviewer feedback, or continue work. Only stop after final reviewer PASS and confirmed commit.
43
44
 
44
45
  ---
45
46
 
@@ -70,18 +71,31 @@ specialists run <name> --bead <id> # foreground run (streams output)
70
71
  specialists run <name> --bead <id> --background # background run
71
72
  specialists run <name> --bead <id> --worktree # isolated worktree (edit-capable specialists)
72
73
  specialists run <name> --bead <id> --job <job-id> # reuse another job's worktree
74
+ specialists run <name> --bead <id> --epic <epic-id> # explicitly declare epic membership
73
75
  specialists run <name> --prompt "..." # ad-hoc (no bead tracking)
74
76
  specialists run <name> --bead <id> --keep-alive # keep session alive after first turn
75
77
  specialists run <name> --bead <id> --context-depth 2 # inject parent bead context
76
78
 
77
79
  # Monitoring
78
- specialists ps # list all jobs (status, specialist, elapsed, bead)
80
+ specialists ps # list all jobs (status, specialist, elapsed, bead, epic)
79
81
  specialists ps <job-id> # inspect single job (full detail + ctx% badge)
80
82
  specialists feed -f # tail merged feed (all jobs) — shows [ctx%] context window usage
81
83
  specialists feed <job-id> # events for a specific job
82
84
  specialists result <job-id> # final output text
83
85
  specialists status --job <job-id> # single-job detail view (legacy — prefer `sp ps <id>`)
84
86
 
87
+ # Epic lifecycle (canonical publication path)
88
+ specialists epic list [--unresolved] # list epics with lifecycle state
89
+ specialists epic status <epic-id> # show chains, blockers, readiness
90
+ specialists epic resolve <epic-id> # transition open -> resolving
91
+ specialists epic merge <epic-id> [--pr] # publish all epic-owned chains
92
+
93
+ # Merge (for standalone chains only)
94
+ specialists merge <chain-root-bead> [--rebuild] # publish ONE standalone chain
95
+
96
+ # Session close (chain-aware, epic-aware)
97
+ specialists end [--pr] # close session, publish via merge or PR
98
+
85
99
  # Interaction
86
100
  specialists steer <job-id> "new direction" # redirect ANY running job mid-run
87
101
  specialists resume <job-id> "next task" # resume a waiting keep-alive job
@@ -97,6 +111,62 @@ specialists init --no-xtrm-check # skip xtrm prerequisite check (CI
97
111
 
98
112
  ---
99
113
 
114
+ ## Taxonomy: Job | Chain | Epic
115
+
116
+ The specialists orchestration model uses three levels:
117
+
118
+ | Term | Definition | Persisted? | Merge scope |
119
+ |------|------------|:----------:|:-----------:|
120
+ | **Job** | One specialist run (atomic execution unit) | Yes (SQLite + files) | — |
121
+ | **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>` |
122
+ | **Epic** | Top merge-gated identity that owns chains across stages | Yes (`epic_runs` table) | `sp epic merge <epic>` |
123
+ | **Wave** | Human shorthand for dispatch batches ("Wave 1", "Wave 2b") — **speech only, NOT persisted** | No | — |
124
+
125
+ ### Key relationships
126
+
127
+ - **Chains belong to epics**: When `--bead` is used, the chain defaults to the bead's parent epic. Override with `--epic <id>`.
128
+ - **Jobs belong to chains**: Jobs sharing a `worktree_owner_job_id` form one chain.
129
+ - **Merge through epics**: `sp epic merge <epic-id>` is the **canonical publication path** for wave-bound chains.
130
+ - **Standalone chains**: `sp merge <chain-root-bead>` works only for chains NOT belonging to an unresolved epic.
131
+
132
+ ### Epic lifecycle
133
+
134
+ ```
135
+ open → resolving → merge_ready → merged
136
+ ↘ failed
137
+ ↘ abandoned
138
+ ```
139
+
140
+ | State | Meaning | Chains mergeable? |
141
+ |-------|---------|:-----------------:|
142
+ | `open` | Epic created, chains not yet running | — |
143
+ | `resolving` | Chains are actively running | ✗ |
144
+ | `merge_ready` | All chains terminal, reviewer PASS | ✓ (via `sp epic merge`) |
145
+ | `merged` | Publication complete | — |
146
+ | `failed` | One or more chains failed | — |
147
+ | `abandoned` | Cancelled without merge | — |
148
+
149
+ ### Migration from "waves" vocabulary
150
+
151
+ **Old terminology → New terminology:**
152
+
153
+ | Old | New | Notes |
154
+ |-----|-----|-------|
155
+ | "Wave 1" | Stage 1 / Prep phase | Speech shorthand still works — just not persisted |
156
+ | "Wave 2" | Implementation chains | Chains are the operative unit, grouped by epic |
157
+ | "Between waves merge" | `sp epic merge` | Epic is the merge-gated identity |
158
+ | "Parallel in wave" | Parallel chains under epic | Use `--epic` to declare membership explicitly |
159
+
160
+ **Why this change?**
161
+
162
+ 1. **Waves had no identity**: "Wave 2" was just speech — no code could track it.
163
+ 2. **Merge gates were implicit**: Operators had to remember which chains to merge together.
164
+ 3. **Epics are explicit**: An epic bead ID persists, enabling `sp epic status` and `sp epic merge`.
165
+
166
+ **Backward compatibility**: All existing workflows work unchanged. The new vocabulary is additive — you can still think in waves, but the system tracks epics.
167
+
168
+ ---
169
+
100
170
  ## Chained Bead Pipeline
101
171
 
102
172
  This is the **standard for ALL tracked work**. Every specialist run gets its own child bead.
@@ -188,18 +258,34 @@ bd close abc --reason "Fixed: token refresh retries on 401. Reviewer PASS."
188
258
 
189
259
  ---
190
260
 
191
- ## --job and --worktree Semantics
261
+ ## --job, --worktree, and --epic Semantics
192
262
 
193
- These flags control **workspace isolation**. Executors run in isolated git worktrees so
194
- concurrent jobs don't corrupt shared files.
263
+ 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.
195
264
 
196
- | Flag | Semantics | Creates worktree? |
197
- |------|-----------|:-:|
198
- | `--worktree` | Provision a new isolated workspace; requires `--bead` | Yes |
199
- | `--job <id>` | Reuse the workspace of an existing job | No |
265
+ | Flag | Semantics | Creates worktree? | Sets epic? |
266
+ |------|-----------|:----------------:|:----------:|
267
+ | `--worktree` | Provision a new isolated workspace; requires `--bead` | Yes | Inherited from bead.parent |
268
+ | `--job <id>` | Reuse the workspace of an existing job | No | Inherited from target job |
269
+ | `--epic <id>` | Explicitly declare epic membership | No | Yes (overrides default) |
200
270
 
201
271
  `--worktree` and `--job` are **mutually exclusive**. Specifying both exits with an error.
202
272
 
273
+ ### Epic membership
274
+
275
+ 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>`:
276
+
277
+ ```bash
278
+ # Chain inherits bead.parent as epic
279
+ specialists run executor --worktree --bead unitAI-impl
280
+ # → epic_id = bead.parent (if epic-type)
281
+
282
+ # Explicit epic declaration (e.g., prep job with non-epic parent)
283
+ specialists run explorer --bead prep-task.1 --epic unitAI-3f7b
284
+ # → epic_id = unitAI-3f7b (explicit override)
285
+ ```
286
+
287
+ **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.
288
+
203
289
  ### `--worktree`
204
290
 
205
291
  Provisions a new git worktree + branch for the specialist run. Branch name is derived
@@ -253,6 +339,7 @@ Use when the caller explicitly accepts concurrent write risk (e.g., target job k
253
339
  | Reviewer on executor's output | `--job <exec-job-id>` (no `--worktree`) |
254
340
  | Fix executor after reviewer PARTIAL | `--bead <fix-bead> --job <exec-job-id>` |
255
341
  | Force entry to blocked worktree | `--bead <fix-bead> --job <exec-job-id> --force-job` |
342
+ | Prep job belonging to epic (non-epic parent) | `--bead <prep-bead> --epic <epic-id>` |
256
343
  | Explorer (READ_ONLY) | Neither — explorers don't need worktrees |
257
344
  | Overthinker, planner, debugger | Neither — read-only and interactive specialists |
258
345
 
@@ -310,20 +397,19 @@ epic
310
397
  ├── child-2 → explore-2 → impl-2 (reviewer via --job impl-2-job)
311
398
  └── child-N → explore-N → impl-N (reviewer via --job impl-N-job)
312
399
  ```
313
- Children within the same wave can run **in parallel** if they own disjoint files.
400
+ Children (chains) within the same epic can run **in parallel** if they own disjoint files.
314
401
 
315
- ### Parallel beads (same wave)
316
- Beads in the same wave share no intra-wave dependencies. They depend on the previous wave's
317
- output (same parent), not on each other.
402
+ ### Parallel chains (same stage)
403
+ 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.
318
404
  ```
319
- # Wave 2 parallel executors (after shared Wave 1 explorer):
405
+ # Stage 2 parallel executors (after shared Stage 1 explorer):
320
406
  bd dep add impl-a explore # impl-a depends on explore, NOT on impl-b
321
407
  bd dep add impl-b explore # impl-b depends on explore, NOT on impl-a
322
408
  ```
323
- Each runs in its own `--worktree`. Merge both branches before Wave 3.
409
+ Each runs in its own `--worktree`. Merge via `sp epic merge <epic>` before Stage 3.
324
410
 
325
411
  ### Test beads (batched)
326
- Tests are **batched** — one test bead covers all impls in a wave, not per-impl.
412
+ Tests are **batched** — one test bead covers all impls in a stage, not per-impl.
327
413
  The test bead depends on **all** impl beads it covers.
328
414
  ```
329
415
  bd dep add tests impl-a
@@ -341,21 +427,27 @@ The review → fix loop is the mechanism for iterative quality improvement withi
341
427
  ### Standard loop
342
428
 
343
429
  ```
344
- 1. Executor claims impl bead, provisions --worktree, implements, closes bead.
345
- -> Job: exec-job
430
+ 1. Executor provisions --worktree, implements, enters waiting.
431
+ -> Job: exec-job (KEEP ALIVE — do not stop)
346
432
 
347
433
  2. Reviewer enters same worktree via --job exec-job.
348
- -> Reads task bead from exec-job status.json automatically.
434
+ -> sp ps shows the chain:
435
+ feature/unitAI-impl-executor · unitAI-impl
436
+ ◐ exec-job executor waiting
437
+ └ ◐ rev-job reviewer starting
349
438
  -> Auto-appends verdict (PASS/PARTIAL/FAIL) to bead notes.
350
439
 
351
- 3a. PASS: orchestrator closes parent task bead.
440
+ 3a. PASS:
441
+ -> Resume executor: "Reviewer PASS. Commit your changes."
442
+ -> Verify commit landed on branch (git log)
443
+ -> Stop reviewer, then stop executor
444
+ -> Merge via sp merge
352
445
 
353
446
  3b. PARTIAL/FAIL:
354
- -> Create fix bead as child of impl bead.
355
- -> Run executor --bead fix-bead --job exec-job --context-depth 2.
356
- -> Fix executor sees: fix-bead + impl (with reviewer verdict) + explore.
357
- -> Fix executor closes fix-bead on completion.
358
- -> Return to step 2 (reviewer on same job).
447
+ -> Resume the SAME executor: "Reviewer PARTIAL. Fix: <specific findings>"
448
+ -> Executor retains full conversation context no re-dispatch needed
449
+ -> Executor applies fixes, enters waiting again
450
+ -> Return to step 2 (new reviewer on same --job)
359
451
 
360
452
  4. Repeat until PASS.
361
453
  ```
@@ -363,41 +455,151 @@ The review → fix loop is the mechanism for iterative quality improvement withi
363
455
  ### Commands
364
456
 
365
457
  ```bash
366
- # Step 1 — Executor with worktree
458
+ # Step 1 — Executor with worktree (enters waiting after first turn)
367
459
  specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
368
460
  # -> Job started: exec-job (e.g. 49adda)
461
+ # DO NOT sp stop — executor stays alive for the entire review cycle
369
462
 
370
- # Step 2 — Reviewer enters same worktree (--prompt required when no --bead)
463
+ # Step 2 — Reviewer enters same worktree
371
464
  specialists run reviewer --job 49adda --keep-alive --background --prompt "Review impl changes"
372
465
  # -> Job started: rev-job
373
466
  specialists result rev-job
374
- # PARTIAL → go to step 3b
375
467
 
376
- # Step 3bCreate fix bead + run fix executor in same worktree
377
- bd create --title "Fix: address reviewer findings on impl" --type bug --priority 1
378
- # -> unitAI-fix1
379
- bd dep add fix1 impl
380
- specialists run executor --bead fix1 --job 49adda --context-depth 2 --background
468
+ # Step 3aPASS: resume executor to commit, then stop both
469
+ specialists resume 49adda "Reviewer PASS. Git add and commit your changes."
470
+ # Wait for commit, verify with: git log feature/unitAI-impl-executor --oneline -1
471
+ specialists stop rev-job
472
+ specialists stop 49adda
473
+ sp merge unitAI-impl --rebuild
381
474
 
382
- # Re-review
475
+ # Step 3b — PARTIAL: resume executor with fix instructions (same session, full context)
476
+ specialists resume 49adda "Reviewer PARTIAL. Fix: <paste specific findings here>"
477
+ # Executor applies fixes, enters waiting again
478
+ # Dispatch new reviewer:
383
479
  specialists run reviewer --job 49adda --keep-alive --background --prompt "Re-review after fix"
384
- # PASS close parent
480
+ # Repeat until PASS
481
+
482
+ # After final PASS + commit + stop:
385
483
  bd close unitAI-task --reason "Reviewer PASS. All findings addressed."
386
484
  ```
387
485
 
486
+ ### Why resume instead of re-dispatch
487
+
488
+ Resuming the original executor/debugger is **always preferred** over dispatching a new fix executor:
489
+
490
+ - **Full context**: the specialist remembers what it changed and why — no re-discovery
491
+ - **No new bead needed**: no fix bead creation, no dep wiring overhead
492
+ - **Same worktree**: no `--job` coordination needed, it's already there
493
+ - **Cheaper**: one resumed turn vs a full new specialist session with context injection
494
+
495
+ Only dispatch a new fix executor when the original specialist is dead (crashed, stopped prematurely, or context exhausted at >80%).
496
+
388
497
  ### Key invariants
389
- - 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.
390
- - Each fix iteration creates a **new child bead** never reopen or re-claim the completed impl bead.
391
- - The fix executor inherits the full context chain: fix-bead + impl (executor output + reviewer findings) + explore, via `--context-depth 2`.
392
- - Multiple reviewer → fix cycles are expected for complex changes. The worktree is stable across all cycles.
498
+ - **Never stop the executor/debugger before reviewer verdict.** The specialist stays in `waiting` throughout the review cycle. Stopping prematurely kills the resume path and risks uncommitted changes.
499
+ - **Executors do not auto-commit.** After reviewer PASS, you must resume the executor with explicit commit instructions. Verify the commit landed before stopping.
500
+ - Each fix iteration uses `resume` on the same specialist not a new child bead or new executor.
501
+ - Multiple reviewer → resume → re-review cycles are expected. The worktree and specialist session are stable across all cycles.
502
+ - Only stop after: (1) reviewer PASS, (2) executor committed, (3) commit verified on branch.
503
+
504
+ ---
505
+
506
+ ## Chain Lifecycle — Members Are Alive Until Merge
507
+
508
+ A chain is not just a worktree — it is a **living group of specialists** sharing one workspace. All members of a chain are alive (running or waiting) until the chain is merged or abandoned. Treat chain members as a unit.
509
+
510
+ ### Rules
511
+
512
+ 1. **Never kill individual chain members prematurely.** A chain may include explorer, overthinker, executor, reviewer — all sharing one worktree via `--job`. Do not `sp stop` any member while the chain is active, unless the member has crashed or is context-exhausted (>80%).
513
+ 2. **The chain is alive until merge.** From first dispatch (even if it's a READ_ONLY explorer) through reviewer PASS and executor commit — the chain is one living unit. Members stay in `waiting` between turns.
514
+ 3. **Resume, don't re-dispatch.** When a chain member needs to act again (executor fixing reviewer findings, overthinker answering follow-ups), use `sp resume` on the existing member. Only dispatch a replacement if the original is dead.
515
+ 4. **Merge kills the chain.** When `sp merge` or `sp epic merge` publishes a chain's branch, all chain members become obsolete. *(Future: `sp merge` will auto-stop all chain members on successful merge — no manual cleanup needed.)*
516
+ 5. **Stop order matters (until auto-cleanup).** When manually stopping chain members after merge: stop dependents first (reviewer), then the chain owner (executor/explorer). This prevents race conditions with resume paths.
517
+
518
+ ### Chain member states
519
+
520
+ | Member state | Meaning | Action |
521
+ |-------------|---------|--------|
522
+ | `running` | Actively working | Wait or steer |
523
+ | `waiting` | Idle, retains full context | Resume when needed |
524
+ | `done` | Finished its turn, output appended | Leave alone — chain may still need it |
525
+ | `error` | Crashed or failed | May need replacement dispatch |
526
+
527
+ ### What "don't kill" means in practice
528
+
529
+ ```bash
530
+ # BAD — killing executor before review cycle completes
531
+ sp stop exec-job # ✗ kills resume path, risks uncommitted work
532
+
533
+ # BAD — killing overthinker before executor uses its output
534
+ sp stop overthinker-job # ✗ loses context if follow-up questions arise
535
+
536
+ # GOOD — chain completes naturally
537
+ sp resume exec-job "Reviewer PASS. Commit your changes."
538
+ # verify commit...
539
+ sp merge unitAI-impl # publishes branch
540
+ # THEN stop members (future: auto-stopped by merge)
541
+ sp stop rev-job
542
+ sp stop exec-job
543
+ ```
393
544
 
394
545
  ---
395
546
 
396
- ## Merge Protocol — `sp merge`
547
+ ## Merge Protocol — Epic Publication
548
+
549
+ The orchestrator owns merge timing, but **no longer performs manual git merges**. Use `sp epic merge` or `sp merge` instead.
550
+
551
+ ### The canonical path: `sp epic merge <epic-id>`
552
+
553
+ **This is the ONLY legal publication path for wave-bound chains.**
397
554
 
398
- The orchestrator owns merge timing, but **no longer performs manual git merges**. Use `sp merge <target>` instead.
555
+ An epic is merge-gated: all chains must be terminal with reviewer PASS before publication. Use `sp epic merge` for:
556
+
557
+ - Publishing multiple chains under one epic (topological order)
558
+ - Ensuring merge gates are satisfied (no running jobs)
559
+ - PR mode (`--pr`) for staged publication
560
+
561
+ ```bash
562
+ # Check epic readiness
563
+ sp epic status unitAI-3f7b
564
+ # Shows: chains, blockers, readiness state, reviewer verdicts
565
+
566
+ # Publish all epic-owned chains
567
+ sp epic merge unitAI-3f7b
568
+ # → merges in topological order, tsc gate after each
569
+
570
+ # PR mode (creates PR instead of direct merge)
571
+ sp epic merge unitAI-3f7b --pr
572
+ ```
399
573
 
400
- ### When to merge vs when NOT to merge
574
+ **What `sp epic merge` does:**
575
+
576
+ 1. Reads epic state from observability SQLite
577
+ 2. Checks all chains are terminal (`done`/`error`)
578
+ 3. Verifies latest reviewer verdict is PASS
579
+ 4. Topologically sorts chains by bead dependencies
580
+ 5. For each chain: `git merge <branch> --no-ff --no-edit`
581
+ 6. Runs `bunx tsc --noEmit` after each merge
582
+ 7. Optionally creates PR with `--pr` flag
583
+ 8. Updates epic state to `merged` on success
584
+
585
+ ### When NOT to merge: `sp merge <chain-root>` is blocked
586
+
587
+ **Standalone chains only.** `sp merge <chain-root-bead>` works ONLY for chains NOT belonging to an unresolved epic:
588
+
589
+ ```bash
590
+ # This FAILS if chain belongs to epic with status=open/resolving/merge_ready
591
+ sp merge unitAI-impl
592
+ # Error: Chain unitAI-impl belongs to unresolved epic unitAI-3f7b (status: resolving).
593
+ # Use 'sp epic merge unitAI-3f7b' to publish all chains together.
594
+ ```
595
+
596
+ **Why this guard exists:**
597
+
598
+ 1. **Merge gates are per-epic**: Publishing one chain without its siblings breaks the wave model.
599
+ 2. **Topological order matters**: Chain A may depend on Chain B — merging A first breaks deps.
600
+ 3. **Epics are explicit**: The epic bead ID is tracked in SQLite, enabling the guard.
601
+
602
+ ### When to merge within a chain vs NOT
401
603
 
402
604
  **Do NOT merge within a chain.** A chain is a sequence of specialists sharing one worktree:
403
605
  executor → reviewer → fix → re-review. The worktree stays live throughout. No merge until
@@ -408,68 +610,49 @@ executor --worktree --bead impl ← creates worktree
408
610
  reviewer --job <exec-job> ← enters same worktree (no merge)
409
611
  executor --bead fix --job <exec-job> ← re-enters same worktree (no merge)
410
612
  reviewer --job <exec-job> ← re-enters same worktree (no merge)
411
- PASS → NOW run sp merge <impl-bead>
613
+ PASS → NOW run sp epic merge <epic>
412
614
  ```
413
615
 
414
- **DO merge between waves.** When the next wave's beads depend on this wave's code existing
415
- on master, you must merge first. The dep graph tells you: beads connected by `--job` are
416
- one chain (same worktree, no merge). Beads connected by `bd dep add` across different
417
- file scopes are separate waves (different worktrees, merge between them).
418
-
419
- ### `sp merge <target>` — the canonical path
420
-
421
- `sp merge` handles the full merge workflow:
616
+ **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.
422
617
 
423
- ```bash
424
- # Merge a single chain (one executor's worktree branch)
425
- sp merge unitAI-impl-bead
426
-
427
- # Merge all chains under an epic (topological order, tsc gate after each)
428
- sp merge unitAI-epic
618
+ ### Planning context upfront
429
619
 
430
- # With rebuild after all merges complete
431
- sp merge unitAI-epic --rebuild
432
- ```
620
+ Before dispatching any chains, identify:
621
+ - **Epics** — the top merge-gated identity (create epic-type bead first)
622
+ - **Chains** — worktree lineages that belong to the epic (use `--epic` for prep jobs)
623
+ - **Stages** — batches of independent chains ("Stage 1" / "Stage 2" are orchestrator speech)
433
624
 
434
- **What `sp merge` does:**
625
+ 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.
435
626
 
436
- 1. Validates all target jobs are terminal (`done`/`error`/`cancelled`)
437
- 2. Resolves chain-root jobs with worktree metadata
438
- 3. Topologically sorts by bead dependencies (FIFO)
439
- 4. For each branch: `git merge <branch> --no-ff --no-edit`
440
- 5. Runs `bunx tsc --noEmit` after each merge (stops on type errors)
441
- 6. Optionally rebuilds with `--rebuild` flag
627
+ ### Epic lifecycle commands
442
628
 
443
- **Why use `sp merge` instead of manual git:**
629
+ ```bash
630
+ # List epics with state
631
+ sp epic list
632
+ sp epic list --unresolved # show non-terminal epics
444
633
 
445
- - Guarantees correct dependency order (bead deps → merge order)
446
- - Catches type errors immediately after each merge
447
- - Refuses merge if any chain job is still running
448
- - Handles epic-level batch merge with one command
634
+ # Inspect one epic
635
+ sp epic status unitAI-3f7b
636
+ # Shows: persisted_state, readiness_state, chains[], blockers[], summary
449
637
 
450
- ### Planning context upfront
638
+ # Transition states (manual)
639
+ sp epic resolve unitAI-3f7b # open → resolving
451
640
 
452
- Before dispatching any wave, identify:
453
- - **Chains** beads that share a worktree via `--job` (executor reviewer → fix → re-review)
454
- - **Waves** groups of independent chains that can run in parallel ("Wave 1" / "Wave 2b" are orchestrator speech for dispatch batches)
455
- - **Merge points** — between waves, after all chains in the wave reach PASS
456
- - **Epics** — the top merge-gated identity (bead epic) that owns chains across multiple waves
457
-
458
- The dep graph encodes this. If bead B depends on bead A and they touch different files,
459
- they're separate waves with a merge point between them.
641
+ # Publish
642
+ sp epic merge unitAI-3f7b # merge_readymerged
643
+ sp epic merge unitAI-3f7b --pr # PR mode
644
+ ```
460
645
 
461
646
  ### Conflict handling
462
647
 
463
- If `sp merge` hits a conflict:
648
+ If merge hits a conflict:
464
649
 
465
650
  1. Command fails with list of conflicting files
466
651
  2. Resolve conflicts manually in your editor
467
652
  3. Run `bunx tsc --noEmit` to verify
468
- 4. Continue with next chain (or re-run `sp merge <epic>` to resume)
653
+ 4. Continue with next chain (or re-run `sp epic merge <epic>` to resume)
469
654
 
470
- **Common conflict pattern:** Parallel executors in the same wave may both create the same
471
- utility file (e.g. `job-root.ts`). This is expected — implementations should be identical.
472
- Keep one, delete the duplicate during conflict resolution.
655
+ **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.
473
656
 
474
657
  ---
475
658
 
@@ -531,7 +714,7 @@ Run `specialists list` to see what's available. Match by task type:
531
714
  ### Specialist selection notes
532
715
 
533
716
  - **executor does not run tests** — it runs `lint + tsc` only. Tests belong to the reviewer or test-runner phase.
534
- - **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.
717
+ - **executor enters `waiting` after first turn** — `interactive: true` is now default. **Never stop the executor before reviewer verdict.** Keep it alive so you can: (1) resume with fix instructions if reviewer says PARTIAL, (2) resume with "commit your changes" after reviewer PASS. Executors do not auto-commit — you must explicitly resume them to commit. Only `sp stop` after the commit is verified on the branch.
535
718
  - **explorer** is READ_ONLY — its output auto-appends to the input bead's notes. No implementation.
536
719
  - **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.
537
720
  - **debugger** over **explorer** when you need root cause analysis — GitNexus call-chain tracing, ranked hypotheses, evidence-backed remediation.
@@ -658,108 +841,133 @@ specialists steer a1b2c3 "Do NOT audit. Write the actual file to disk now."
658
841
 
659
842
  | Specialist | Enters `waiting` after | What to send via `resume` |
660
843
  |-----------|----------------------|--------------------------|
661
- | **executor** | First turn completion (may be partial if bailed early) | "proceed, this is additive", "address the risk warning and continue", or "done, close bead" |
844
+ | **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." |
662
845
  | **researcher** | Delivering research findings | Follow-up question, new angle, or "done, thanks" |
663
846
  | **reviewer** | Delivering verdict (PASS/PARTIAL/FAIL) | Your response, clarification, or "accepted, close out" |
664
847
  | **overthinker** | Phase 4 conclusion | Follow-up question, counter-argument, or "done, thanks" |
665
- | **debugger** | Phase 3 fix attempt or Phase 4 verify result | Follow-up fix, "try different approach", or "done" |
848
+ | **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" |
666
849
  | **sync-docs** | Audit report or targeted update result | "approve", "deny", or specific instructions |
667
850
 
668
851
  > **Warning:** A job in `waiting` looks identical to a stalled job. **Always check with `sp ps`
669
852
  > before killing a keep-alive job.**
670
853
 
854
+ > **Critical:** Never stop an executor or debugger before the reviewer delivers its verdict.
855
+ > Stopping prematurely: (1) kills the resume path for fix loops, (2) risks uncommitted changes
856
+ > (executors don't auto-commit), and (3) forces dispatching a new specialist instead of resuming.
857
+
671
858
  ```bash
672
859
  # Check before stopping
673
860
  specialists ps d4e5f6
674
861
  # -> status: waiting ← healthy, expecting input
675
862
 
676
863
  specialists resume d4e5f6 "What about backward compatibility?"
677
- specialists stop d4e5f6 # only when truly done iterating
864
+ specialists stop d4e5f6 # only when truly done iterating — after reviewer PASS + commit verified
678
865
  ```
679
866
 
680
867
  ---
681
868
 
682
- ## Wave Orchestration
869
+ ## Chain and Epic Orchestration
683
870
 
684
- For multi-step work, dispatch specialists in **waves**.
871
+ For multi-step work, dispatch chains under an **epic**.
685
872
 
686
- A **wave** is a set of specialist jobs that may run in parallel **only if they are independent**.
687
- Waves are strictly sequential: **never start wave N+1 before wave N completes AND is merged**.
873
+ 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`**.
688
874
 
689
- ### Wave rules
875
+ ### Chain rules
690
876
 
691
- 1. **Sequence between waves.** Exploration → implementation → review → doc sync.
692
- 2. **Parallelize only within a wave.** Jobs that don't depend on each other may run together.
693
- 3. **Do not overlap waves.** Wait for every job, read results, update beads, merge.
694
- 4. **Bead deps encode the pipeline.** The dependency graph should match wave order.
877
+ 1. **Sequence between stages.** Prep (explorer/planner) → implementation chains → review → tests → doc sync.
878
+ 2. **Parallelize only within a stage.** Chains that don't depend on each other may run together.
879
+ 3. **Do not overlap stages.** Wait for every chain job, read results, update beads, merge epic.
880
+ 4. **Bead deps encode the pipeline.** The dependency graph should match stage order.
695
881
  5. **`--context-depth 2` for all chained runs.** Each specialist sees parent + predecessor.
696
- 6. **Merge between waves is mandatory.** See Merge Protocol above.
882
+ 6. **Merge via `sp epic merge` is mandatory.** See Merge Protocol above.
697
883
 
698
- ### Polling a wave
884
+ ### Polling chains
699
885
 
700
886
  ```bash
701
- specialists ps # list all jobs — shows status, specialist, elapsed, bead
887
+ specialists ps # list all jobs — shows epic grouping, status, elapsed
702
888
  specialists ps abc123 # inspect specific job (full detail)
703
- specialists ps abc123 def456 ghi789 # inspect multiple jobs
889
+ specialists ps --follow # live dashboard with epic grouping
890
+ ```
891
+
892
+ `sp ps` shows epic-level grouping:
893
+
894
+ ```
895
+ ◆ epic:unitAI-3f7b · merge_ready · state:resolving · prep done=2/2 · chains pass=3/3
896
+ prep:exp-1 · done
897
+ prep:plan-2 · done
898
+ chain:impl-a (reviewer PASS) · branch:feature/unitAI-impl-a-executor
899
+ chain:impl-b (reviewer PASS) · branch:feature/unitAI-impl-b-executor
900
+ chain:impl-c (reviewer PASS) · branch:feature/unitAI-impl-c-executor
704
901
  ```
705
902
 
706
- A wave is complete when every job is `completed` or `error` AND you have:
903
+ A stage is complete when every chain is terminal AND you have:
707
904
  1. Read results: `specialists result <job-id>` for each
708
905
  2. Updated/closed beads as needed
709
- 3. Merged all worktree branches into master
906
+ 3. Published via `sp epic merge <epic-id>`
710
907
 
711
- ### Canonical multi-wave example
908
+ ### Canonical multi-stage example
712
909
 
713
910
  ```bash
714
- # 0. Parent bead
715
- bd create --title "Add worktree isolation to executor" --type feature --priority 1
716
- # -> unitAI-root
911
+ # 0. Create epic bead (top merge-gated identity)
912
+ bd create --title "Add worktree isolation to executor" --type epic --priority 1
913
+ # -> unitAI-3f7b
717
914
 
718
- # 1. Chained child beads
915
+ # 1. Create prep and impl beads as children of the epic
719
916
  bd create --title "Explore: map job run architecture" --type task --priority 2 # -> unitAI-exp
720
- bd dep add exp root
917
+ bd dep add exp 3f7b
721
918
  bd create --title "Implement: worktree isolation" --type task --priority 2 # -> unitAI-impl
722
919
  bd dep add impl exp
723
- # Note: reviewer runs via --job, test-runner gets its own bead
920
+ # Note: reviewer runs via --job, inherits epic from impl bead.parent
724
921
 
725
- # Wave 1 — Explorer
726
- specialists run explorer --bead unitAI-exp --context-depth 2 --background
922
+ # Stage 1 — Explorer (prep job, declares epic explicitly)
923
+ specialists run explorer --bead unitAI-exp --epic unitAI-3f7b --context-depth 2 --background
727
924
  # -> Job started: job1
728
925
  specialists result job1
729
926
 
730
- # [MERGE] Nothing to merge from READ_ONLY wave
927
+ # [NO MERGE] Prep stage has no worktrees to merge
731
928
 
732
- # Wave 2 — Executor
929
+ # Stage 2 — Executor (chain inherits epic from bead.parent)
733
930
  specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
734
931
  # -> Job started: job2 (worktree: .worktrees/unitAI-impl/unitAI-impl-executor)
932
+ # epic_id = bead.parent (unitAI-3f7b)
735
933
  specialists result job2
736
934
 
737
- # [MERGE] Merge worktree branch into master (sp merge handles topological order + tsc gate)
738
- sp merge unitAI-impl --rebuild
739
-
740
- # Wave 3 — Reviewer (no bead, uses --job)
741
- specialists run reviewer --job job2 --keep-alive --background
935
+ # Stage 3 Reviewer (uses --job, same worktree)
936
+ specialists run reviewer --job job2 --keep-alive --background --prompt "Review implementation"
742
937
  # -> Job started: job3
743
938
  specialists result job3
744
- # PASS → Wave 4. PARTIAL → fix loop.
939
+ # PASS → ready for epic merge. PARTIAL → fix loop.
745
940
 
746
- # Wave 4 — Tests (if needed)
747
- bd create --title "Test: worktree isolation" --type task --priority 2 # -> unitAI-tests
748
- bd dep add tests impl
749
- specialists run test-runner --bead unitAI-tests --context-depth 2 --background
941
+ # Stage 4 — Fix loop (if PARTIAL)
942
+ bd create --title "Fix: reviewer gaps on impl" --type bug --priority 1 # -> unitAI-fix1
943
+ bd dep add fix1 impl
944
+ specialists run executor --bead fix1 --job job2 --context-depth 2 --background
945
+ # Re-review
946
+ specialists run reviewer --job job2 --keep-alive --background --prompt "Re-review after fix"
947
+
948
+ # [MERGE] Publish epic
949
+ sp epic status unitAI-3f7b # verify readiness: merge_ready, all chains PASS
950
+ sp epic merge unitAI-3f7b --rebuild
750
951
 
751
952
  # Close
752
- bd close root --reason "Worktree isolation implemented. Reviewer PASS. Tests green."
953
+ bd close 3f7b --reason "Worktree isolation implemented. Reviewer PASS. Epic merged."
753
954
  ```
754
955
 
755
- ### Within-wave parallelism
956
+ ### Within-stage parallelism (multiple chains)
756
957
 
757
958
  ```bash
758
- # Parallel executors — disjoint files, same parent explorer
959
+ # Parallel executors — disjoint files, same parent epic
960
+ bd create --title "Implement: component A" --type task --priority 2 # -> unitAI-impl-a
961
+ bd dep add impl-a exp
962
+ bd create --title "Implement: component B" --type task --priority 2 # -> unitAI-impl-b
963
+ bd dep add impl-b exp
964
+
759
965
  specialists run executor --worktree --bead unitAI-impl-a --context-depth 2 --background
760
966
  specialists run executor --worktree --bead unitAI-impl-b --context-depth 2 --background
761
- # Each runs in its own worktree.
762
- # Do NOT start next wave until BOTH complete AND BOTH are merged.
967
+ # Each runs in its own worktree, both belong to unitAI-3f7b (via bead.parent)
968
+
969
+ # Do NOT start next stage until BOTH complete AND epic is merged
970
+ sp epic merge unitAI-3f7b
763
971
  ```
764
972
 
765
973
  ---
@@ -769,7 +977,7 @@ specialists run executor --worktree --bead unitAI-impl-b --context-depth 2 --bac
769
977
  ### 1. Route work — don't explore or implement yourself
770
978
  Discovery goes to **explorer** first; implementation goes to **executor** only after discovery is done.
771
979
 
772
- ### 2. Validate combined output after each wave
980
+ ### 2. Validate combined output after each stage
773
981
  ```bash
774
982
  npm run lint # project quality gate
775
983
  npx tsc --noEmit # type check
@@ -787,8 +995,8 @@ Options when a specialist fails:
787
995
  - **Switch**: e.g. sync-docs stalls → try executor
788
996
  - **Stop and report** to the user before doing it yourself
789
997
 
790
- ### 4. Merge between waves (CRITICAL)
791
- See Merge Protocol above. No exceptions.
998
+ ### 4. Merge via epic (CRITICAL)
999
+ See Merge Protocol above. Use `sp epic merge <epic-id>` — no exceptions.
792
1000
 
793
1001
  ### 5. Run drift detection after doc-heavy sessions
794
1002
  ```bash