@jaggerxtrm/specialists 3.5.1 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +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.2
12
+ version: 4.5
13
+ synced_at: zz22-docs
13
14
  ---
14
15
 
15
16
  # Specialists Usage
@@ -35,8 +36,8 @@ Specialists are autonomous AI agents that run independently — fresh context, d
35
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.
36
37
  4. **For tracked work, the bead is the prompt.** The bead description, notes, and parent context are the instruction surface.
37
38
  5. **`--bead` and `--prompt` are mutually exclusive.** If you need to refine instructions, update the bead notes; do not add `--prompt`.
38
- 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.
39
- 7. **Merge between waves is mandatory.** Executor worktree branches must be merged into master before the next wave starts. 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.
40
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.
41
42
  9. **Executor does not run tests.** Executor runs lint + tsc only. Tests are the reviewer's and test-runner's responsibility in the chained pipeline.
42
43
 
@@ -69,18 +70,31 @@ specialists run <name> --bead <id> # foreground run (streams output)
69
70
  specialists run <name> --bead <id> --background # background run
70
71
  specialists run <name> --bead <id> --worktree # isolated worktree (edit-capable specialists)
71
72
  specialists run <name> --bead <id> --job <job-id> # reuse another job's worktree
73
+ specialists run <name> --bead <id> --epic <epic-id> # explicitly declare epic membership
72
74
  specialists run <name> --prompt "..." # ad-hoc (no bead tracking)
73
75
  specialists run <name> --bead <id> --keep-alive # keep session alive after first turn
74
76
  specialists run <name> --bead <id> --context-depth 2 # inject parent bead context
75
77
 
76
78
  # Monitoring
77
- specialists ps # list all jobs (status, specialist, elapsed, bead)
79
+ specialists ps # list all jobs (status, specialist, elapsed, bead, epic)
78
80
  specialists ps <job-id> # inspect single job (full detail + ctx% badge)
79
81
  specialists feed -f # tail merged feed (all jobs) — shows [ctx%] context window usage
80
82
  specialists feed <job-id> # events for a specific job
81
83
  specialists result <job-id> # final output text
82
84
  specialists status --job <job-id> # single-job detail view (legacy — prefer `sp ps <id>`)
83
85
 
86
+ # Epic lifecycle (canonical publication path)
87
+ specialists epic list [--unresolved] # list epics with lifecycle state
88
+ specialists epic status <epic-id> # show chains, blockers, readiness
89
+ specialists epic resolve <epic-id> # transition open -> resolving
90
+ specialists epic merge <epic-id> [--pr] # publish all epic-owned chains
91
+
92
+ # Merge (for standalone chains only)
93
+ specialists merge <chain-root-bead> [--rebuild] # publish ONE standalone chain
94
+
95
+ # Session close (chain-aware, epic-aware)
96
+ specialists end [--pr] # close session, publish via merge or PR
97
+
84
98
  # Interaction
85
99
  specialists steer <job-id> "new direction" # redirect ANY running job mid-run
86
100
  specialists resume <job-id> "next task" # resume a waiting keep-alive job
@@ -96,6 +110,62 @@ specialists init --no-xtrm-check # skip xtrm prerequisite check (CI
96
110
 
97
111
  ---
98
112
 
113
+ ## Taxonomy: Job | Chain | Epic
114
+
115
+ The specialists orchestration model uses three levels:
116
+
117
+ | Term | Definition | Persisted? | Merge scope |
118
+ |------|------------|:----------:|:-----------:|
119
+ | **Job** | One specialist run (atomic execution unit) | Yes (SQLite + files) | — |
120
+ | **Chain** | Worktree lineage: executor → reviewer → fix → re-review (seeded by edit-capable specialist) | Yes (`worktree_owner_job_id`) | `sp merge <chain-root>` |
121
+ | **Epic** | Top merge-gated identity that owns chains across stages | Yes (`epic_runs` table) | `sp epic merge <epic>` |
122
+ | **Wave** | Human shorthand for dispatch batches ("Wave 1", "Wave 2b") — **speech only, NOT persisted** | No | — |
123
+
124
+ ### Key relationships
125
+
126
+ - **Chains belong to epics**: When `--bead` is used, the chain defaults to the bead's parent epic. Override with `--epic <id>`.
127
+ - **Jobs belong to chains**: Jobs sharing a `worktree_owner_job_id` form one chain.
128
+ - **Merge through epics**: `sp epic merge <epic-id>` is the **canonical publication path** for wave-bound chains.
129
+ - **Standalone chains**: `sp merge <chain-root-bead>` works only for chains NOT belonging to an unresolved epic.
130
+
131
+ ### Epic lifecycle
132
+
133
+ ```
134
+ open → resolving → merge_ready → merged
135
+ ↘ failed
136
+ ↘ abandoned
137
+ ```
138
+
139
+ | State | Meaning | Chains mergeable? |
140
+ |-------|---------|:-----------------:|
141
+ | `open` | Epic created, chains not yet running | — |
142
+ | `resolving` | Chains are actively running | ✗ |
143
+ | `merge_ready` | All chains terminal, reviewer PASS | ✓ (via `sp epic merge`) |
144
+ | `merged` | Publication complete | — |
145
+ | `failed` | One or more chains failed | — |
146
+ | `abandoned` | Cancelled without merge | — |
147
+
148
+ ### Migration from "waves" vocabulary
149
+
150
+ **Old terminology → New terminology:**
151
+
152
+ | Old | New | Notes |
153
+ |-----|-----|-------|
154
+ | "Wave 1" | Stage 1 / Prep phase | Speech shorthand still works — just not persisted |
155
+ | "Wave 2" | Implementation chains | Chains are the operative unit, grouped by epic |
156
+ | "Between waves merge" | `sp epic merge` | Epic is the merge-gated identity |
157
+ | "Parallel in wave" | Parallel chains under epic | Use `--epic` to declare membership explicitly |
158
+
159
+ **Why this change?**
160
+
161
+ 1. **Waves had no identity**: "Wave 2" was just speech — no code could track it.
162
+ 2. **Merge gates were implicit**: Operators had to remember which chains to merge together.
163
+ 3. **Epics are explicit**: An epic bead ID persists, enabling `sp epic status` and `sp epic merge`.
164
+
165
+ **Backward compatibility**: All existing workflows work unchanged. The new vocabulary is additive — you can still think in waves, but the system tracks epics.
166
+
167
+ ---
168
+
99
169
  ## Chained Bead Pipeline
100
170
 
101
171
  This is the **standard for ALL tracked work**. Every specialist run gets its own child bead.
@@ -145,7 +215,8 @@ specialists run explorer --bead abc-exp --context-depth 2 --background
145
215
  # Explorer output auto-appends to abc-exp notes (READ_ONLY behavior)
146
216
  specialists result e1f2g3
147
217
 
148
- # 4. [MERGE] Merge any worktree branches from Wave 1 into master (see Merge Protocol)
218
+ # 4. [MERGE] Merge any worktree branches from Wave 1 into master
219
+ # READ_ONLY waves have no worktrees to merge
149
220
 
150
221
  # 5. Wave 2 — Executor
151
222
  specialists run executor --worktree --bead abc-impl --context-depth 2 --background
@@ -153,7 +224,8 @@ specialists run executor --worktree --bead abc-impl --context-depth 2 --backgrou
153
224
  # Executor sees: abc-impl + abc-exp (with explorer notes) + abc via context-depth
154
225
  # Executor self-appends output to abc-impl notes, closes abc-impl on completion
155
226
 
156
- # 6. [MERGE] Merge abc-impl worktree branch into master
227
+ # 6. [MERGE] Merge impl worktree branch into master
228
+ sp merge abc-impl --rebuild
157
229
 
158
230
  # 7. Wave 3 — Reviewer (no separate bead — uses --job + --prompt to enter executor's worktree)
159
231
  specialists run reviewer --job a1b2c3 --keep-alive --background --prompt "Review the token refresh fix"
@@ -185,18 +257,34 @@ bd close abc --reason "Fixed: token refresh retries on 401. Reviewer PASS."
185
257
 
186
258
  ---
187
259
 
188
- ## --job and --worktree Semantics
260
+ ## --job, --worktree, and --epic Semantics
189
261
 
190
- These flags control **workspace isolation**. Executors run in isolated git worktrees so
191
- concurrent jobs don't corrupt shared files.
262
+ These flags control **workspace isolation** and **epic membership**. Executors run in isolated git worktrees so concurrent jobs don't corrupt shared files. Chains declare epic membership to enable merge-gated publication.
192
263
 
193
- | Flag | Semantics | Creates worktree? |
194
- |------|-----------|:-:|
195
- | `--worktree` | Provision a new isolated workspace; requires `--bead` | Yes |
196
- | `--job <id>` | Reuse the workspace of an existing job | No |
264
+ | Flag | Semantics | Creates worktree? | Sets epic? |
265
+ |------|-----------|:----------------:|:----------:|
266
+ | `--worktree` | Provision a new isolated workspace; requires `--bead` | Yes | Inherited from bead.parent |
267
+ | `--job <id>` | Reuse the workspace of an existing job | No | Inherited from target job |
268
+ | `--epic <id>` | Explicitly declare epic membership | No | Yes (overrides default) |
197
269
 
198
270
  `--worktree` and `--job` are **mutually exclusive**. Specifying both exits with an error.
199
271
 
272
+ ### Epic membership
273
+
274
+ When `--bead` is used, the chain defaults to the bead's parent epic (if parent is an epic-type bead). Override this with `--epic <id>`:
275
+
276
+ ```bash
277
+ # Chain inherits bead.parent as epic
278
+ specialists run executor --worktree --bead unitAI-impl
279
+ # → epic_id = bead.parent (if epic-type)
280
+
281
+ # Explicit epic declaration (e.g., prep job with non-epic parent)
282
+ specialists run explorer --bead prep-task.1 --epic unitAI-3f7b
283
+ # → epic_id = unitAI-3f7b (explicit override)
284
+ ```
285
+
286
+ **Why explicit --epic?** Prep jobs (explorer, planner, overthinker) often have non-epic parents but need to belong to the epic for `sp ps` grouping and `sp epic status` visibility.
287
+
200
288
  ### `--worktree`
201
289
 
202
290
  Provisions a new git worktree + branch for the specialist run. Branch name is derived
@@ -222,9 +310,25 @@ specialists run reviewer --job 49adda --keep-alive --background
222
310
  specialists run executor --bead hgpu.3-fix --job 49adda --context-depth 2 --background
223
311
  ```
224
312
 
225
- **Concurrency guard:**
226
- - READ_ONLY specialists (explorer, reviewer): allowed while owning job is still running
227
- - MEDIUM/HIGH permission specialists (executor): **blocked** until owning job reaches terminal state
313
+ **Concurrency guard (MEDIUM/HIGH specialists):**
314
+
315
+ Blocked from entering while target job is `starting` or `running` prevents concurrent file corruption.
316
+
317
+ | Target status | MEDIUM/HIGH | READ_ONLY/LOW |
318
+ |---------------|:-----------:|:-------------:|
319
+ | `starting` | ✗ Blocked | ✓ Allowed |
320
+ | `running` | ✗ Blocked | ✓ Allowed |
321
+ | `waiting` | ✓ Allowed | ✓ Allowed |
322
+ | `done`/`error`/`cancelled` | ✓ Allowed | ✓ Allowed |
323
+ | Unknown | ✗ Blocked (conservative) | ✓ Allowed |
324
+
325
+ **Bypass with `--force-job`:**
326
+
327
+ ```bash
328
+ specialists run executor --job 49adda --force-job --bead fix-123
329
+ ```
330
+
331
+ Use when the caller explicitly accepts concurrent write risk (e.g., target job known to be stalled but not yet terminal, emergency fix entry).
228
332
 
229
333
  ### When to use each flag
230
334
 
@@ -233,11 +337,29 @@ specialists run executor --bead hgpu.3-fix --job 49adda --context-depth 2 --back
233
337
  | First executor run for a task | `--worktree --bead <impl-bead>` |
234
338
  | Reviewer on executor's output | `--job <exec-job-id>` (no `--worktree`) |
235
339
  | Fix executor after reviewer PARTIAL | `--bead <fix-bead> --job <exec-job-id>` |
340
+ | Force entry to blocked worktree | `--bead <fix-bead> --job <exec-job-id> --force-job` |
341
+ | Prep job belonging to epic (non-epic parent) | `--bead <prep-bead> --epic <epic-id>` |
236
342
  | Explorer (READ_ONLY) | Neither — explorers don't need worktrees |
237
343
  | Overthinker, planner, debugger | Neither — read-only and interactive specialists |
238
344
 
239
345
  ---
240
346
 
347
+ ### Worktree write-boundary enforcement
348
+
349
+ Specialists running in worktrees are **prevented from writing outside their boundary**. The session generates a Pi extension that hooks `tool_call` events and blocks `edit`/`write`/`multiEdit`/`notebookEdit` tools with absolute paths outside the worktree.
350
+
351
+ **What's blocked:**
352
+ - `edit` with `/absolute/path/outside/worktree/file.ts`
353
+ - `write` with `/absolute/path/outside/worktree/new-file.ts`
354
+
355
+ **What's allowed:**
356
+ - Relative paths (`src/file.ts`) — resolve within worktree cwd
357
+ - Absolute paths inside the worktree boundary
358
+
359
+ This enforcement is automatic when `--worktree` is used. No configuration required. If the extension fails to generate (tmpdir permissions), a warning is logged and the session proceeds without protection.
360
+
361
+ ---
362
+
241
363
  ## Dependency Mapping
242
364
 
243
365
  Map bead dependencies to match the execution pipeline. The dep graph IS the wave plan.
@@ -274,20 +396,19 @@ epic
274
396
  ├── child-2 → explore-2 → impl-2 (reviewer via --job impl-2-job)
275
397
  └── child-N → explore-N → impl-N (reviewer via --job impl-N-job)
276
398
  ```
277
- Children within the same wave can run **in parallel** if they own disjoint files.
399
+ Children (chains) within the same epic can run **in parallel** if they own disjoint files.
278
400
 
279
- ### Parallel beads (same wave)
280
- Beads in the same wave share no intra-wave dependencies. They depend on the previous wave's
281
- output (same parent), not on each other.
401
+ ### Parallel chains (same stage)
402
+ Chains in the same stage share no intra-stage dependencies. They depend on the previous stage's output (same epic parent), not on each other.
282
403
  ```
283
- # Wave 2 parallel executors (after shared Wave 1 explorer):
404
+ # Stage 2 parallel executors (after shared Stage 1 explorer):
284
405
  bd dep add impl-a explore # impl-a depends on explore, NOT on impl-b
285
406
  bd dep add impl-b explore # impl-b depends on explore, NOT on impl-a
286
407
  ```
287
- Each runs in its own `--worktree`. Merge both branches before Wave 3.
408
+ Each runs in its own `--worktree`. Merge via `sp epic merge <epic>` before Stage 3.
288
409
 
289
410
  ### Test beads (batched)
290
- Tests are **batched** — one test bead covers all impls in a wave, not per-impl.
411
+ Tests are **batched** — one test bead covers all impls in a stage, not per-impl.
291
412
  The test bead depends on **all** impl beads it covers.
292
413
  ```
293
414
  bd dep add tests impl-a
@@ -357,12 +478,62 @@ bd close unitAI-task --reason "Reviewer PASS. All findings addressed."
357
478
 
358
479
  ---
359
480
 
360
- ## Merge Protocol — Orchestrator Responsibility
481
+ ## Merge Protocol — Epic Publication
482
+
483
+ The orchestrator owns merge timing, but **no longer performs manual git merges**. Use `sp epic merge` or `sp merge` instead.
361
484
 
362
- The orchestrator owns merge timing. This is not optional — failing to merge at the right
363
- time means downstream specialists branch from stale master and miss upstream code.
485
+ ### The canonical path: `sp epic merge <epic-id>`
364
486
 
365
- ### When to merge vs when NOT to merge
487
+ **This is the ONLY legal publication path for wave-bound chains.**
488
+
489
+ An epic is merge-gated: all chains must be terminal with reviewer PASS before publication. Use `sp epic merge` for:
490
+
491
+ - Publishing multiple chains under one epic (topological order)
492
+ - Ensuring merge gates are satisfied (no running jobs)
493
+ - PR mode (`--pr`) for staged publication
494
+
495
+ ```bash
496
+ # Check epic readiness
497
+ sp epic status unitAI-3f7b
498
+ # Shows: chains, blockers, readiness state, reviewer verdicts
499
+
500
+ # Publish all epic-owned chains
501
+ sp epic merge unitAI-3f7b
502
+ # → merges in topological order, tsc gate after each
503
+
504
+ # PR mode (creates PR instead of direct merge)
505
+ sp epic merge unitAI-3f7b --pr
506
+ ```
507
+
508
+ **What `sp epic merge` does:**
509
+
510
+ 1. Reads epic state from observability SQLite
511
+ 2. Checks all chains are terminal (`done`/`error`)
512
+ 3. Verifies latest reviewer verdict is PASS
513
+ 4. Topologically sorts chains by bead dependencies
514
+ 5. For each chain: `git merge <branch> --no-ff --no-edit`
515
+ 6. Runs `bunx tsc --noEmit` after each merge
516
+ 7. Optionally creates PR with `--pr` flag
517
+ 8. Updates epic state to `merged` on success
518
+
519
+ ### When NOT to merge: `sp merge <chain-root>` is blocked
520
+
521
+ **Standalone chains only.** `sp merge <chain-root-bead>` works ONLY for chains NOT belonging to an unresolved epic:
522
+
523
+ ```bash
524
+ # This FAILS if chain belongs to epic with status=open/resolving/merge_ready
525
+ sp merge unitAI-impl
526
+ # Error: Chain unitAI-impl belongs to unresolved epic unitAI-3f7b (status: resolving).
527
+ # Use 'sp epic merge unitAI-3f7b' to publish all chains together.
528
+ ```
529
+
530
+ **Why this guard exists:**
531
+
532
+ 1. **Merge gates are per-epic**: Publishing one chain without its siblings breaks the wave model.
533
+ 2. **Topological order matters**: Chain A may depend on Chain B — merging A first breaks deps.
534
+ 3. **Epics are explicit**: The epic bead ID is tracked in SQLite, enabling the guard.
535
+
536
+ ### When to merge within a chain vs NOT
366
537
 
367
538
  **Do NOT merge within a chain.** A chain is a sequence of specialists sharing one worktree:
368
539
  executor → reviewer → fix → re-review. The worktree stays live throughout. No merge until
@@ -373,68 +544,49 @@ executor --worktree --bead impl ← creates worktree
373
544
  reviewer --job <exec-job> ← enters same worktree (no merge)
374
545
  executor --bead fix --job <exec-job> ← re-enters same worktree (no merge)
375
546
  reviewer --job <exec-job> ← re-enters same worktree (no merge)
376
- PASS → NOW merge the worktree branch into master
547
+ PASS → NOW run sp epic merge <epic>
377
548
  ```
378
549
 
379
- **DO merge between waves.** When the next wave's beads depend on this wave's code existing
380
- on master, you must merge first. The dep graph tells you: beads connected by `--job` are
381
- one chain (same worktree, no merge). Beads connected by `bd dep add` across different
382
- file scopes are separate waves (different worktrees, merge between them).
550
+ **DO merge between stages (via epic).** When the next stage's chains depend on this stage's code existing on master, merge the epic first. The dep graph tells you: beads connected by `--job` are one chain (same worktree, no merge). Beads connected by `bd dep add` across different file scopes are separate chains under the same epic.
383
551
 
384
552
  ### Planning context upfront
385
553
 
386
- Before dispatching any wave, identify:
387
- - **Chains** — beads that share a worktree via `--job` (executor reviewer → fix → re-review)
388
- - **Waves** — groups of independent chains that can run in parallel
389
- - **Merge points** — between waves, after all chains in the wave reach PASS
390
-
391
- The dep graph encodes this. If bead B depends on bead A and they touch different files,
392
- they're separate waves with a merge point between them.
554
+ Before dispatching any chains, identify:
555
+ - **Epics** — the top merge-gated identity (create epic-type bead first)
556
+ - **Chains** — worktree lineages that belong to the epic (use `--epic` for prep jobs)
557
+ - **Stages** — batches of independent chains ("Stage 1" / "Stage 2" are orchestrator speech)
393
558
 
394
- ### FIFO dependency order
559
+ The dep graph encodes this. If bead B depends on bead A and they touch different files, they're separate chains under the same epic with a merge point between stages.
395
560
 
396
- Merge in **dependency order** (first dep first), not completion order.
397
- Parallel beads (disjoint files) can merge in any order within their wave.
561
+ ### Epic lifecycle commands
398
562
 
399
563
  ```bash
400
- # After Wave N — all beads closed, all jobs terminal:
401
-
402
- # 1. Move to main checkout
403
- cd /path/to/main/repo
564
+ # List epics with state
565
+ sp epic list
566
+ sp epic list --unresolved # show non-terminal epics
404
567
 
405
- # 2. Merge in dependency order
406
- git merge feature/bead-a-executor # first dep in chain
407
- npm run lint && npx tsc --noEmit # verify after each merge
408
- git merge feature/bead-b-executor # second dep (parallel, disjoint files)
409
- npm run lint && npx tsc --noEmit
568
+ # Inspect one epic
569
+ sp epic status unitAI-3f7b
570
+ # Shows: persisted_state, readiness_state, chains[], blockers[], summary
410
571
 
411
- # 3. Resolve conflicts if any
412
- # Expected conflict: parallel executors creating the same utility file
413
- # (e.g. job-root.ts created by two parallel beads)
414
- # → Keep the version from the earlier dep, discard the duplicate
415
- # → Re-run lint + tsc after resolution
572
+ # Transition states (manual)
573
+ sp epic resolve unitAI-3f7b # open resolving
416
574
 
417
- # 4. Rebuild dist if project uses a bundled output
418
- npm run build
419
-
420
- # 5. Start Wave N+1
575
+ # Publish
576
+ sp epic merge unitAI-3f7b # merge_ready → merged
577
+ sp epic merge unitAI-3f7b --pr # PR mode
421
578
  ```
422
579
 
423
- **Why FIFO matters:**
424
- - Bead A blocks bead B → A's code must land in master before B's worktree branches from it
425
- - Merging B before A: broken imports, missing symbols, silent type errors
426
- - Parallel beads (disjoint files): order doesn't matter within the wave, but ALL must merge before the next wave
580
+ ### Conflict handling
581
+
582
+ If merge hits a conflict:
427
583
 
428
- **Common conflict pattern:** Parallel executors in the same wave may both create the same
429
- utility file (e.g. `job-root.ts`). This is expected implementations should be identical.
430
- Keep one, delete the duplicate during conflict resolution.
584
+ 1. Command fails with list of conflicting files
585
+ 2. Resolve conflicts manually in your editor
586
+ 3. Run `bunx tsc --noEmit` to verify
587
+ 4. Continue with next chain (or re-run `sp epic merge <epic>` to resume)
431
588
 
432
- **File overlap conflict:** If two parallel executors modify the **same file** (e.g. both touch
433
- `init.ts`), their worktree branches will conflict on merge. Either sequence them as separate
434
- waves, or accept manual conflict resolution. When resolving: copy the incoming version from
435
- the worktree (`cat /path/to/.worktrees/.../file > main/file`), then re-apply missing changes
436
- from the other branch. **Always verify your cwd is the main repo** — shell state can drift
437
- into a worktree directory after merge operations.
589
+ **Common conflict pattern:** Parallel chains in the same stage may both create the same utility file (e.g. `job-root.ts`). This is expected — implementations should be identical. Keep one, delete the duplicate during conflict resolution.
438
590
 
439
591
  ---
440
592
 
@@ -446,6 +598,13 @@ The specialist reads:
446
598
  - bead notes (including output appended by previous specialists in the chain)
447
599
  - parent/ancestor bead context (controlled by `--context-depth`)
448
600
 
601
+ **Automatic context injection**: Runner injects ~3800 tokens of project memory at spawn:
602
+ - `.xtrm/memory.md` (SSOT: Do Not Repeat, How This Project Works, Active Context)
603
+ - `bd prime` output (workflow rules + all bd memories dump)
604
+ - GitNexus cheatsheet (when `.gitnexus/meta.json` exists — ~100 tokens)
605
+
606
+ This prevents specialists from rediscovering known gotchas on every run.
607
+
449
608
  `--prompt` and `--bead` cannot be combined. When you need to give a specialist
450
609
  specific instructions beyond what's in the bead description, update the bead notes first:
451
610
 
@@ -462,6 +621,9 @@ own bead + the immediate predecessor's output + one more level of context.
462
621
 
463
622
  **`--no-beads`** — skip creating an auto-tracking sub-bead, but still reads the `--bead` input.
464
623
 
624
+ **Edit gate access**: Specialists with `--bead` automatically set `bead-claim:<id>` KV key,
625
+ enabling write access in worktrees without session-scoped claims. Cleared on run completion.
626
+
465
627
  ---
466
628
 
467
629
  ## Choosing the Right Specialist
@@ -538,7 +700,7 @@ specialists stop <job-id> # when satisfied
538
700
  specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
539
701
  ```
540
702
 
541
- ### Monitoring with `sp ps`
703
+ ### Monitoring with `sp ps` and `sp list --live`
542
704
 
543
705
  Use `specialists ps` (alias `sp ps`) for job monitoring instead of manual JSON polling:
544
706
 
@@ -558,6 +720,23 @@ specialists ps <job-id>
558
720
  # - >80% = CRITICAL (▲ indicator shown)
559
721
  ```
560
722
 
723
+ **Live tmux session selector (`sp list --live`):**
724
+
725
+ ```bash
726
+ # Interactive selector for running/waiting tmux sessions
727
+ specialists list --live
728
+ # Shows: tmux session name, specialist, elapsed, status
729
+ # Arrow keys to select, Enter to attach
730
+
731
+ # Include dead sessions (PID or tmux gone)
732
+ specialists list --live --show-dead
733
+ # Dead sessions shown with 'dead' status instead of filtered out
734
+ ```
735
+
736
+ Dead job detection (`is_dead`) is computed at read time — never persisted to avoid stale state. A job is dead when:
737
+ - PID no longer exists (`kill -0 <pid>` fails)
738
+ - tmux session gone (`tmux has-session -t <name>` fails or times out)
739
+
561
740
  ---
562
741
 
563
742
  ### Pi extensions and packages
@@ -617,88 +796,108 @@ specialists stop d4e5f6 # only when truly done iterating
617
796
 
618
797
  ---
619
798
 
620
- ## Wave Orchestration
799
+ ## Chain and Epic Orchestration
621
800
 
622
- For multi-step work, dispatch specialists in **waves**.
801
+ For multi-step work, dispatch chains under an **epic**.
623
802
 
624
- A **wave** is a set of specialist jobs that may run in parallel **only if they are independent**.
625
- Waves are strictly sequential: **never start wave N+1 before wave N completes AND is merged**.
803
+ A **chain** is a worktree lineage (executor reviewer → fix → re-review). Chains within the same epic may run in parallel **only if they are independent** (disjoint file scopes). Stages are strictly sequential: **never start Stage N+1 before Stage N completes AND is merged via `sp epic merge`**.
626
804
 
627
- ### Wave rules
805
+ ### Chain rules
628
806
 
629
- 1. **Sequence between waves.** Exploration → implementation → review → doc sync.
630
- 2. **Parallelize only within a wave.** Jobs that don't depend on each other may run together.
631
- 3. **Do not overlap waves.** Wait for every job, read results, update beads, merge.
632
- 4. **Bead deps encode the pipeline.** The dependency graph should match wave order.
807
+ 1. **Sequence between stages.** Prep (explorer/planner) → implementation chains → review → tests → doc sync.
808
+ 2. **Parallelize only within a stage.** Chains that don't depend on each other may run together.
809
+ 3. **Do not overlap stages.** Wait for every chain job, read results, update beads, merge epic.
810
+ 4. **Bead deps encode the pipeline.** The dependency graph should match stage order.
633
811
  5. **`--context-depth 2` for all chained runs.** Each specialist sees parent + predecessor.
634
- 6. **Merge between waves is mandatory.** See Merge Protocol above.
812
+ 6. **Merge via `sp epic merge` is mandatory.** See Merge Protocol above.
635
813
 
636
- ### Polling a wave
814
+ ### Polling chains
637
815
 
638
816
  ```bash
639
- specialists ps # list all jobs — shows status, specialist, elapsed, bead
817
+ specialists ps # list all jobs — shows epic grouping, status, elapsed
640
818
  specialists ps abc123 # inspect specific job (full detail)
641
- specialists ps abc123 def456 ghi789 # inspect multiple jobs
819
+ specialists ps --follow # live dashboard with epic grouping
642
820
  ```
643
821
 
644
- A wave is complete when every job is `completed` or `error` AND you have:
822
+ `sp ps` shows epic-level grouping:
823
+
824
+ ```
825
+ ◆ epic:unitAI-3f7b · merge_ready · state:resolving · prep done=2/2 · chains pass=3/3
826
+ prep:exp-1 · done
827
+ prep:plan-2 · done
828
+ chain:impl-a (reviewer PASS) · branch:feature/unitAI-impl-a-executor
829
+ chain:impl-b (reviewer PASS) · branch:feature/unitAI-impl-b-executor
830
+ chain:impl-c (reviewer PASS) · branch:feature/unitAI-impl-c-executor
831
+ ```
832
+
833
+ A stage is complete when every chain is terminal AND you have:
645
834
  1. Read results: `specialists result <job-id>` for each
646
835
  2. Updated/closed beads as needed
647
- 3. Merged all worktree branches into master
836
+ 3. Published via `sp epic merge <epic-id>`
648
837
 
649
- ### Canonical multi-wave example
838
+ ### Canonical multi-stage example
650
839
 
651
840
  ```bash
652
- # 0. Parent bead
653
- bd create --title "Add worktree isolation to executor" --type feature --priority 1
654
- # -> unitAI-root
841
+ # 0. Create epic bead (top merge-gated identity)
842
+ bd create --title "Add worktree isolation to executor" --type epic --priority 1
843
+ # -> unitAI-3f7b
655
844
 
656
- # 1. Chained child beads
845
+ # 1. Create prep and impl beads as children of the epic
657
846
  bd create --title "Explore: map job run architecture" --type task --priority 2 # -> unitAI-exp
658
- bd dep add exp root
847
+ bd dep add exp 3f7b
659
848
  bd create --title "Implement: worktree isolation" --type task --priority 2 # -> unitAI-impl
660
849
  bd dep add impl exp
661
- # Note: reviewer runs via --job, test-runner gets its own bead
850
+ # Note: reviewer runs via --job, inherits epic from impl bead.parent
662
851
 
663
- # Wave 1 — Explorer
664
- specialists run explorer --bead unitAI-exp --context-depth 2 --background
852
+ # Stage 1 — Explorer (prep job, declares epic explicitly)
853
+ specialists run explorer --bead unitAI-exp --epic unitAI-3f7b --context-depth 2 --background
665
854
  # -> Job started: job1
666
855
  specialists result job1
667
856
 
668
- # [MERGE] Nothing to merge from READ_ONLY wave
857
+ # [NO MERGE] Prep stage has no worktrees to merge
669
858
 
670
- # Wave 2 — Executor
859
+ # Stage 2 — Executor (chain inherits epic from bead.parent)
671
860
  specialists run executor --worktree --bead unitAI-impl --context-depth 2 --background
672
861
  # -> Job started: job2 (worktree: .worktrees/unitAI-impl/unitAI-impl-executor)
862
+ # epic_id = bead.parent (unitAI-3f7b)
673
863
  specialists result job2
674
864
 
675
- # [MERGE] Merge worktree branch into master (FIFO)
676
- git merge feature/unitAI-impl-executor
677
- npm run lint && npx tsc --noEmit && npm run build
678
-
679
- # Wave 3 — Reviewer (no bead, uses --job)
680
- specialists run reviewer --job job2 --keep-alive --background
865
+ # Stage 3 Reviewer (uses --job, same worktree)
866
+ specialists run reviewer --job job2 --keep-alive --background --prompt "Review implementation"
681
867
  # -> Job started: job3
682
868
  specialists result job3
683
- # PASS → Wave 4. PARTIAL → fix loop.
869
+ # PASS → ready for epic merge. PARTIAL → fix loop.
684
870
 
685
- # Wave 4 — Tests (if needed)
686
- bd create --title "Test: worktree isolation" --type task --priority 2 # -> unitAI-tests
687
- bd dep add tests impl
688
- specialists run test-runner --bead unitAI-tests --context-depth 2 --background
871
+ # Stage 4 — Fix loop (if PARTIAL)
872
+ bd create --title "Fix: reviewer gaps on impl" --type bug --priority 1 # -> unitAI-fix1
873
+ bd dep add fix1 impl
874
+ specialists run executor --bead fix1 --job job2 --context-depth 2 --background
875
+ # Re-review
876
+ specialists run reviewer --job job2 --keep-alive --background --prompt "Re-review after fix"
877
+
878
+ # [MERGE] Publish epic
879
+ sp epic status unitAI-3f7b # verify readiness: merge_ready, all chains PASS
880
+ sp epic merge unitAI-3f7b --rebuild
689
881
 
690
882
  # Close
691
- bd close root --reason "Worktree isolation implemented. Reviewer PASS. Tests green."
883
+ bd close 3f7b --reason "Worktree isolation implemented. Reviewer PASS. Epic merged."
692
884
  ```
693
885
 
694
- ### Within-wave parallelism
886
+ ### Within-stage parallelism (multiple chains)
695
887
 
696
888
  ```bash
697
- # Parallel executors — disjoint files, same parent explorer
889
+ # Parallel executors — disjoint files, same parent epic
890
+ bd create --title "Implement: component A" --type task --priority 2 # -> unitAI-impl-a
891
+ bd dep add impl-a exp
892
+ bd create --title "Implement: component B" --type task --priority 2 # -> unitAI-impl-b
893
+ bd dep add impl-b exp
894
+
698
895
  specialists run executor --worktree --bead unitAI-impl-a --context-depth 2 --background
699
896
  specialists run executor --worktree --bead unitAI-impl-b --context-depth 2 --background
700
- # Each runs in its own worktree.
701
- # Do NOT start next wave until BOTH complete AND BOTH are merged.
897
+ # Each runs in its own worktree, both belong to unitAI-3f7b (via bead.parent)
898
+
899
+ # Do NOT start next stage until BOTH complete AND epic is merged
900
+ sp epic merge unitAI-3f7b
702
901
  ```
703
902
 
704
903
  ---
@@ -708,7 +907,7 @@ specialists run executor --worktree --bead unitAI-impl-b --context-depth 2 --bac
708
907
  ### 1. Route work — don't explore or implement yourself
709
908
  Discovery goes to **explorer** first; implementation goes to **executor** only after discovery is done.
710
909
 
711
- ### 2. Validate combined output after each wave
910
+ ### 2. Validate combined output after each stage
712
911
  ```bash
713
912
  npm run lint # project quality gate
714
913
  npx tsc --noEmit # type check
@@ -726,8 +925,8 @@ Options when a specialist fails:
726
925
  - **Switch**: e.g. sync-docs stalls → try executor
727
926
  - **Stop and report** to the user before doing it yourself
728
927
 
729
- ### 4. Merge between waves (CRITICAL)
730
- See Merge Protocol above. No exceptions.
928
+ ### 4. Merge via epic (CRITICAL)
929
+ See Merge Protocol above. Use `sp epic merge <epic-id>` — no exceptions.
731
930
 
732
931
  ### 5. Run drift detection after doc-heavy sessions
733
932
  ```bash