pi-spine 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +64 -480
  2. package/bin/get-version.mjs +1 -13
  3. package/bin/spine-batch.mjs +5 -1
  4. package/bin/spine-config.mjs +1 -212
  5. package/bin/spine-doctor.mjs +2 -418
  6. package/bin/spine-init.mjs +1 -398
  7. package/bin/spine-preflight.mjs +1 -700
  8. package/bin/spine-review-step.mjs +6 -4
  9. package/bin/spine-tasks.mjs +96 -11
  10. package/bin/spine-worker-runner.mjs +14 -4
  11. package/bin/spine.mjs +3 -1
  12. package/extensions/spine/worker-tools.ts +14 -12
  13. package/package.json +10 -3
  14. package/skills/create-spine-tasks/SKILL.md +136 -7
  15. package/skills/create-spine-tasks/references/clarify-template.md +73 -0
  16. package/skills/create-spine-tasks/references/prompt-template.md +2 -0
  17. package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
  18. package/src/batch/abort.mjs +1 -1
  19. package/src/batch/detached-start.mjs +41 -7
  20. package/src/batch/diagnosis.mjs +51 -6
  21. package/src/batch/engine-lanes/merge.mjs +70 -7
  22. package/src/batch/engine-lanes/review.mjs +32 -74
  23. package/src/batch/engine-scope.mjs +31 -4
  24. package/src/batch/engine.mjs +40 -48
  25. package/src/batch/evidence.mjs +3 -2
  26. package/src/batch/gate.mjs +3 -3
  27. package/src/batch/integrate.mjs +1 -1
  28. package/src/batch/journal.mjs +22 -0
  29. package/src/batch/lifecycle.mjs +1 -1
  30. package/src/batch/merge/adoption-doc-merge.mjs +160 -0
  31. package/src/batch/merge/wave-merge-state.mjs +105 -0
  32. package/src/batch/post-merge-limbo.mjs +87 -15
  33. package/src/batch/reconcile.mjs +50 -2
  34. package/src/batch/resume-common.mjs +1 -1
  35. package/src/batch/resume-engine.mjs +58 -1
  36. package/src/batch/resume-multi-validate.mjs +82 -3
  37. package/src/batch/resume-multi.mjs +36 -40
  38. package/src/batch/resume.mjs +20 -10
  39. package/src/batch/review-shared.mjs +196 -0
  40. package/src/batch/review-spawn.mjs +320 -0
  41. package/src/batch/review.mjs +178 -212
  42. package/src/batch/task-stall-budget.mjs +72 -0
  43. package/src/batch/worker-host.mjs +94 -34
  44. package/src/batch/worktree.mjs +10 -0
  45. package/src/cli/handoff.mjs +1 -1
  46. package/src/cli/rules.mjs +1 -1
  47. package/src/cli/settings-set.mjs +1 -1
  48. package/src/cli/settings-slash.mjs +27 -5
  49. package/src/config/spine-config-load.mjs +221 -0
  50. package/src/config/spine-init-constants.mjs +423 -0
  51. package/src/config/spine-preflight-lib.mjs +725 -0
  52. package/src/dashboard/public/dashboard.js +4 -25
  53. package/src/dashboard/public/index.html +1 -7
  54. package/src/dashboard/snapshot.mjs +172 -5
  55. package/src/dashboard/view.mjs +2 -0
  56. package/src/doctor/run-doctor-checks.mjs +458 -0
  57. package/src/doctor/stale-path.mjs +22 -0
  58. package/src/migrate/taskplane-config.mjs +1 -1
  59. package/src/planner/pending.mjs +92 -1
  60. package/src/tasks/analyze/index.mjs +453 -0
  61. package/src/util/command-exists.mjs +19 -0
  62. package/templates/docs/constitution.md +61 -0
  63. package/templates/spine-config.json +1 -1
package/README.md CHANGED
@@ -4,27 +4,7 @@
4
4
 
5
5
  **Orchestration spine for long-running pi development.**
6
6
 
7
- pi-spine is a [pi](https://pi.dev) package that helps you run parallel, multi-day agent batches on real codebases. It combines the strongest ideas from [Taskplane](https://pi.dev/packages/taskplane), [Babysitter](https://github.com/a5c-ai/babysitter), and [pi-conductor](https://www.npmjs.com/package/@feniix/pi-conductor) without asking you to operate three separate orchestrators—or pick one and miss what the others do well.
8
-
9
- ---
10
-
11
- ## Why this exists
12
-
13
- Long-running agent development fails for the same reasons repeatedly:
14
-
15
- - **Context loss** when sessions compact or crash
16
- - **Parallel collisions** when multiple agents edit one checkout
17
- - **Opaque recovery** when a batch pauses and you cannot tell whether to resume, force-resume, or abort
18
- - **Premature integration** when lane work merges without explicit approval or test evidence
19
- - **Tool fragmentation** when each orchestrator owns state differently and none covers the full workflow
20
-
21
- Taskplane, Babysitter, and pi-conductor each solve important slices of this problem. None of them, used alone, gives you **Taskplane-style task packets**, **Babysitter-grade audit history**, and **pi-conductor-style human gates** in one pi-native flow.
22
-
23
- pi-spine exists to be that spine: a thin, composable layer you install once and run from your pi session.
24
-
25
- ---
26
-
27
- ## What pi-spine is (and is not)
7
+ pi-spine is a [pi](https://pi.dev) package for parallel, multi-day agent batches on real codebases. It combines Taskplane-style task packets, Babysitter-grade audit history, and pi-conductor-style human gates in one pi-native flow — **compose, don't merge** three orchestrators into a fourth monolith.
28
8
 
29
9
  | pi-spine is | pi-spine is not |
30
10
  |-------------|-----------------|
@@ -34,70 +14,6 @@ pi-spine exists to be that spine: a thin, composable layer you install once and
34
14
  | **Human gates** before integrate/merge | A clone of pi-conductor's external control-plane DB |
35
15
  | Worktree-isolated parallel lanes | Cross-harness routing (Cursor, Codex, etc.) in v1 |
36
16
 
37
- Design philosophy: **compose, don't merge.** pi-spine adopts patterns; it does not reimplement three products as a fourth monolith.
38
-
39
- ---
40
-
41
- ## Advantages over using the others directly
42
-
43
- ### vs Taskplane alone
44
-
45
- Taskplane is the best pi-native batch orchestrator today: dependency waves, worktree lanes, cross-model review, dashboard, and orch-branch integration. pi-spine builds on that foundation rather than competing with it.
46
-
47
- | You get with pi-spine | Gap when using Taskplane only |
48
- |-----------------------|-------------------------------|
49
- | **Orchestration journal** — append-only timeline of batch, lane, task, gate, and integrate events | Batch state and diagnostics exist, but post-mortem replay across lane death is harder to reconstruct |
50
- | **Explicit integrate gates** — merge blocked until you approve an evidence bundle (tests, diff stat, task scorecard) | Integration is powerful; human approval is less formalized |
51
- | **Journal-driven reconciliation** — resume hints grounded in event history | Resume works, but stale or partial lane recovery can be opaque in long batches |
52
- | **Same task packets** — point `--tasks-root` at existing `taskplane-tasks/` | No migration rewrite required |
53
-
54
- **When to stay on Taskplane only:** You are happy with its dashboard, supervisor, and merge flow and do not need formal gates or a dedicated audit journal.
55
-
56
- ### vs Babysitter alone
57
-
58
- Babysitter excels at **deterministic, event-sourced workflow orchestration** and cross-harness portability. Its pi plugin is experimental and thin; the heavy lifting lives in the SDK and harness adapters.
59
-
60
- | You get with pi-spine | Gap when using Babysitter only |
61
- |-----------------------|----------------------------------|
62
- | **pi-native first-class UX** — slash commands, skills, worker sessions in pi | Pi integration is experimental; not the primary Babysitter surface |
63
- | **File-based task packets** — `PROMPT.md` / `STATUS.md` as agent memory | Process definitions in JavaScript; different authoring model |
64
- | **Git worktree lanes** tuned for coding batches | Not the core Babysitter story |
65
- | **Lighter mental model** — journal at orchestration boundaries, not full process replay | Full replay engine is powerful but heavier for solo pi batch work |
66
-
67
- **When to stay on Babysitter only:** You need one workflow engine across many harnesses (Codex, Cursor, Gemini) and want JS process definitions with full deterministic replay.
68
-
69
- ### vs pi-conductor alone
70
-
71
- pi-conductor is an actively developed **agent-native control plane**: durable workers, gates, artifacts, and PR-oriented flows via model-callable tools.
72
-
73
- | You get with pi-spine | Gap when using pi-conductor only |
74
- |-----------------------|----------------------------------|
75
- | **Taskplane-compatible packets** — reuse existing `TP-*` / `SP-*` folders | Objectives and tool-native orchestration; different task contract |
76
- | **Wave + lane batch model** — familiar `/spine-plan all` → parallel worktrees | Scheduler and conductor tools; different UX paradigm |
77
- | **Opinionated worker/reviewer pipeline** — step checkpoints, `.DONE`, inline review | More flexible control plane; you assemble more yourself |
78
- | **In-repo task folders** as the handoff artifact for humans and agents | State largely outside the repo |
79
-
80
- **When to stay on pi-conductor only:** You want tool-driven orchestration (`conductor_run_work`, gate dashboard, PR readiness) and prefer objectives over folder-based packets.
81
-
82
- ### The combined picture
83
-
84
- ```text
85
- Audit / replay clarity
86
- ▲
87
- │
88
- Babysitter │ pi-spine
89
- │
90
- ──────────────────┼──────────────────► Batch orchestration
91
- │
92
- pi-conductor │ Taskplane
93
- │
94
- Gates │ Packets + dashboard
95
- ```
96
-
97
- pi-spine targets the upper-right: **batch orchestration with strong audit trail and human gates**, using task packets you may already have.
98
-
99
- ---
100
-
101
17
  ## Feature summary
102
18
 
103
19
  - **Taskplane-compatible tasks** — `PROMPT.md`, `STATUS.md`, `dependencies.json`
@@ -108,32 +24,22 @@ pi-spine targets the upper-right: **batch orchestration with strong audit trail
108
24
  - **Orchestration journal** — JSONL event log for debugging and resume context
109
25
  - **Human gates** — approve or reject integrate with test/build evidence
110
26
  - **Local dashboard** — batch, lane, and gate visibility (SSE)
111
- - **`create-spine-tasks` skill** — decompose PRDs into `spine-tasks/` packets (local install; no npm publish)
112
-
113
- See `docs/PRD.md` for the full specification.
114
-
115
- ---
116
-
117
- ## Honest limits (v2.2)
27
+ - **`create-spine-tasks` skill** — decompose PRDs into `spine-tasks/` packets (local install)
118
28
 
119
- pi-spine v2.2 ships operator-driven batch monitoring, not Taskplane-style autonomous supervision.
29
+ ## Inspired by
120
30
 
121
- | Out of v2.2 | What to use instead |
122
- |-------------|---------------------|
123
- | **Supervisor mail** — conversational nudges between orchestrator and workers | `spine status --diagnose`, dashboard diagnosis banner, runbook recovery paths |
124
- | **Autonomous monitor agent** — background Pi session polling batch health | Same CLI + dashboard surfaces; human operator runs suggested commands |
31
+ pi-spine builds on ideas from [Taskplane](https://pi.dev/packages/taskplane), [Babysitter](https://github.com/a5c-ai/babysitter), and [pi-conductor](https://www.npmjs.com/package/@feniix/pi-conductor). For comparisons, trade-offs, and when to use each tool alone, see **[Why pi-spine?](docs/adoption/why-pi-spine.md)**.
125
32
 
126
- **Primary monitor surfaces:**
33
+ ## Honest limits
127
34
 
128
- - **`spine status --diagnose`** — diagnosis, headline, `suggestedCommand`, lane health (use daily after detached start/resume)
129
- - **Dashboard** — `spine dashboard` / `/spine-dashboard`; diagnosis banner and action chips match `--diagnose` reconciliation (default port 8109)
130
- - **[Operator runbook](docs/adoption/operator-runbook.md)** — stall recovery, orphan handling, land loop, gate races
35
+ pi-spine ships operator-driven batch monitoring, not autonomous supervision.
131
36
 
132
- The `.spine/agents/supervisor.md` template (from `spine init`) documents this no-agent reality; the batch engine does not spawn it.
37
+ | Out of scope | What to use instead |
38
+ |--------------|---------------------|
39
+ | **Supervisor mail** — conversational nudges between orchestrator and workers | `spine status --diagnose`, dashboard diagnosis banner |
40
+ | **Autonomous monitor agent** — background session polling batch health | CLI + dashboard surfaces; human operator runs suggested commands |
133
41
 
134
- **Optional stretch (not blocking v2.2 publish):** a minimal supervisor session journaling `supervisor.nudge` events — deferred unless consumer pilot feedback shows dashboard + diagnose are insufficient ([FR-SHIP-11](docs/PRD-v2.2-ship-readiness-handoff.md#fr-ship-11-design-decision)).
135
-
136
- ---
42
+ Primary monitor surfaces: **`spine status --diagnose`**, **`spine dashboard`** / `/spine-dashboard`, and the **[operator runbook](docs/adoption/operator-runbook.md)**. The `.spine/agents/supervisor.md` template documents this no-agent reality; the batch engine does not spawn it.
137
43
 
138
44
  ## Prerequisites
139
45
 
@@ -143,421 +49,99 @@ The `.spine/agents/supervisor.md` template (from `spine init`) documents this no
143
49
  | [pi](https://pi.dev) coding agent | Yes |
144
50
  | Git (worktree support) | Yes |
145
51
 
146
- ---
52
+ ## Install
147
53
 
148
- ## Adoption (pre-publish)
54
+ ```bash
55
+ pi install npm:pi-spine
56
+ # or: npm install -g pi-spine
57
+ ```
149
58
 
150
- pi-spine is not on npm yet. To use it on a real project from a git checkout or local path (slash commands, `spine` CLI, file dependency), see **[docs/adoption/local-install.md](docs/adoption/local-install.md)**. After install, `spine doctor` warns when a stale global `spine` on PATH does not match your checkout.
59
+ For git/path development installs, see **[local-install.md](docs/adoption/local-install.md)**. After install, `spine doctor` warns when a stale global `spine` on PATH does not match your checkout.
151
60
 
152
61
  | Doc | Purpose |
153
62
  |-----|---------|
154
- | [local-install.md](docs/adoption/local-install.md) | Git/path install before npm publish |
155
63
  | [bootstrap-checklist.md](docs/adoption/bootstrap-checklist.md) | First-time consumer setup |
156
- | [operator-runbook.md](docs/adoption/operator-runbook.md) | Daily operator procedures (preflight, land loop, recovery) |
157
- | [real-project-readiness.md](docs/adoption/real-project-readiness.md) | Phase 9 adoption plan |
158
-
159
- ### Task authoring (`create-spine-tasks` skill)
160
-
161
- After `pi install /path/to/pi-spine -l`, the **`create-spine-tasks`** skill is available in pi. Use it to decompose a PRD or feature brief into `spine-tasks/<ID>-<slug>/` folders (`PROMPT.md`, `STATUS.md`, `dependencies.json` updates).
162
-
163
- Example prompt in pi:
164
-
165
- ```text
166
- Use the create-spine-tasks skill to break docs/PRD.md into M-sized SP-* tasks
167
- under spine-tasks/. Update CONTEXT.md and dependencies.json.
168
- ```
169
-
170
- Skill source: [`skills/create-spine-tasks/SKILL.md`](skills/create-spine-tasks/SKILL.md). See [bootstrap-checklist.md](docs/adoption/bootstrap-checklist.md) for the greenfield flow.
171
-
172
- ### Cursor rules (contributors)
173
-
174
- The repo ships [`.cursor/rules/`](.cursor/rules/) for Cursor IDE sessions. Rules are versioned in git (no secrets or machine-local paths).
175
-
176
- **Primary subset for pi-spine** (Node.js CLI / `.mjs` codebase):
177
-
178
- | Rule | Role |
179
- |------|------|
180
- | [`critical-rules-quick-reference.mdc`](.cursor/rules/critical-rules-quick-reference.mdc) | Always-on condensed anti-patterns |
181
- | [`general-llm-anti-patterns.mdc`](.cursor/rules/general-llm-anti-patterns.mdc) | Universal LLM coding pitfalls |
182
- | [`javascript-3-development-standards.mdc`](.cursor/rules/javascript-3-development-standards.mdc) | JS/TS/MJS standards (globs on `**/*.{js,mjs,cjs,ts,tsx}`) |
183
- | [`owasp-secure-coding-practices.mdc`](.cursor/rules/owasp-secure-coding-practices.mdc) | Security baseline (evidence exec, CLI) |
184
- | [`git-workflow-and-pr.mdc`](.cursor/rules/git-workflow-and-pr.mdc) | Commits, PRs, CI expectations |
185
- | [`documentation-policy.mdc`](.cursor/rules/documentation-policy.mdc) | When to write docs vs task packets |
186
- | [`taskplane-task-authoring.mdc`](.cursor/rules/taskplane-task-authoring.mdc) | Authoring `PROMPT.md` / `STATUS.md` |
187
- | [`taskplane-worker-cursor.mdc`](.cursor/rules/taskplane-worker-cursor.mdc) | Executing task packets in Cursor |
188
- | [`engineering-philosophy.mdc`](.cursor/rules/engineering-philosophy.mdc) | Design trade-offs |
189
- | [`cursor-integration.mdc`](.cursor/rules/cursor-integration.mdc) | Rules vs skills in Cursor |
190
-
191
- **Phase / milestone audits:** follow [`.cursor/rules/audit-workflow.mdc`](.cursor/rules/audit-workflow.mdc). For pi-spine, invoke the JavaScript audit ([`javascript-3-brutal-audit.mdc`](.cursor/rules/javascript-3-brutal-audit.mdc)) after major phases.
192
-
193
- **Spine batch workers:** When `.cursor/rules/` exists, pi-spine auto-selects rules per task (PROMPT File Scope + committed manifest) and injects them into worker prompts (FR-WORK-05). Glob-triggered language packs (Swift, Python, Java, Go, Rust, AWS, iOS, Obsidian) load when File Scope matches their frontmatter globs. **`taskplane-worker-cursor.mdc`** is always included via the default rules profile. Explicit `config.standards` paths **append** after auto-selection. See [docs/design/cursor-rules-discovery.md](docs/design/cursor-rules-discovery.md).
194
-
195
- **CLI:** `spine rules discover`, `spine rules sync`, `spine rules select --task <id>` — run `sync` after rule changes and commit `.spine/rules-manifest.json`.
196
-
197
- ---
64
+ | [operator-runbook.md](docs/adoption/operator-runbook.md) | Daily operator procedures |
65
+ | [cursor-rules-discovery.md](docs/design/cursor-rules-discovery.md) | Contributor Cursor rules (contributors) |
198
66
 
199
67
  ## Quick start
200
68
 
201
- ```bash
202
- # Install the pi package (when published)
203
- pi install npm:pi-spine
204
-
205
- # In your project repo
206
- cd my-project
207
- spine init
208
- spine doctor
209
- spine plan all
210
- spine preflight
211
- ```
212
-
213
- Run **`spine preflight`** before every batch (FR-BATCH-11). It verifies:
214
-
215
- | Check | Requirement |
216
- |-------|-------------|
217
- | Doctor | `spine doctor` passes (Node, git, pi, config, agents, model provider) |
218
- | Git clean | No uncommitted changes in the working tree |
219
- | No active batch | No healthy active batch in `.spine/batch-state.json` (or Taskplane `.pi/batch-state.json`) |
220
- | Tasks root | Configured tasks folder exists with discoverable `PROMPT.md` task folders |
221
- | Dependencies | `{tasksRoot}/dependencies.json` parses and references valid task IDs |
222
- | Wave plan | Dependency waves and lane assignment (same output as `spine plan all`) |
223
-
224
- `spine doctor` also prints an advisory **lanes.maxParallel sizing** line when config is valid: configured value vs a conservative suggestion from CPU count (`floor(cpus/2)`, capped at 4). Lanes are parallel agents and git worktrees, not CPU threads — the hint never fails doctor; it may warn when `configured > suggested + 1` so you can lower `.spine/spine-config.json` → `lanes.maxParallel` if API cost or supervision feels high.
225
-
226
- Use `spine preflight --json` for automation. Exit code is non-zero when any check fails.
227
-
228
- ### Settings (FR-CFG-03)
229
-
230
- Inspect and update registered `.spine/spine-config.json` fields:
231
-
232
- ```bash
233
- spine settings show # all editable fields
234
- spine settings show lanes.maxParallel --json # single value
235
- spine settings set lanes.maxParallel 2 # validate and persist
236
- spine settings set dashboard.port 8110 --dry-run # preview without writing
237
- ```
238
-
239
- Only paths in the editable registry can be changed; invalid values exit non-zero with actionable errors. Writes use atomic tmp + rename.
69
+ 1. **Install and init** — `pi install npm:pi-spine` then `cd my-project && spine init && spine doctor`
70
+ 2. **Plan and preflight** — `spine preflight && spine plan all` (pi: `/spine-plan all`)
71
+ 3. **Start a batch** — `spine batch start pending` (pi: `/spine pending`)
72
+ 4. **Monitor** — `spine status --diagnose` (pi: `/spine-status`)
73
+ 5. **Land on main** — `spine gate status` → `spine gate approve` → `spine integrate` (pi: `/spine-gate` → `/spine-integrate`)
240
74
 
241
- ### Batch status and reconciliation
75
+ Full command reference: **[docs/QUICK-REFERENCE.md](docs/QUICK-REFERENCE.md)**.
242
76
 
243
- Reconciled batch diagnosis (FR-BATCH-12–14) derives operator-facing state from task records, git, `.DONE` files, and batch-state — not from raw `phase` alone:
77
+ ## Commands at a glance
244
78
 
245
- ```bash
246
- spine status # headline + suggested next command
247
- spine status --diagnose # verbose signal breakdown
248
- spine status --json # automation-friendly output
249
- spine status --verbose # include segment frontier (NFR-OBS-05)
250
- ```
79
+ ### CLI
251
80
 
252
- Output includes `diagnosis`, `headline`, `suggestedCommand`, and optional `alternatives[]` per PRD §18.3. Diagnosis taxonomy (FR-BATCH-13): `running`, `paused`, `needs_retry`, `needs_merge`, `needs_integrate`, `completed`, `completed_manual`, `limbo_stale`, `failed`, `aborted`.
81
+ | Command | Purpose |
82
+ |---------|---------|
83
+ | `spine init` | Create `.spine/` config and agent stubs |
84
+ | `spine doctor` | Validate Node, git, pi, config |
85
+ | `spine preflight` | Required checks before batch start |
86
+ | `spine plan all` / `pending` | Preview dependency waves and lanes |
87
+ | `spine batch start pending` | Run unfinished tasks in dependency order |
88
+ | `spine status --diagnose` | Reconciled batch diagnosis + next action |
89
+ | `spine batch pause` / `resume` | Stop or continue scheduling |
90
+ | `spine gate status` / `approve` | Review evidence; approve integrate |
91
+ | `spine integrate` | Merge orch branch → main |
92
+ | `spine dashboard` | Local SSE dashboard (default port 8109) |
253
93
 
254
- Reads `.spine/batch-state.json` first, then Taskplane `.pi/batch-state.json` during dogfood. When no batch exists, status reports a healthy idle state with `spine preflight` or `spine plan all` as the suggested next action.
94
+ ### pi slash commands
255
95
 
256
- ### Batch dismiss, complete, and next action
96
+ | Command | Purpose |
97
+ |---------|---------|
98
+ | `/spine-plan all` | Preview waves and lanes |
99
+ | `/spine pending` | Start batch for pending tasks |
100
+ | `/spine-status` | Batch diagnosis + lane health |
101
+ | `/spine-gate` | Gate inspection and resolution |
102
+ | `/spine-integrate` | Merge orch branch after gate approval |
103
+ | `/spine-dashboard` | Start dashboard in background |
257
104
 
258
- Archive-first lifecycle for terminal limbo (FR-BATCH-15–16, §18.6):
259
-
260
- ```bash
261
- spine batch dismiss --reason "manual recovery" # limbo_stale, completed_manual, aborted
262
- spine batch complete --detect-manual-merge # after manual merge to main
263
- spine batch complete --batch ID # orch on main + merge satisfied (FR-BATCH-16)
264
- spine integrate [--dry-run] # merge orch branch → main (FR-INT-01)
265
- spine next # print suggestedCommand from reconciliation
266
- spine next --execute # run suggested command (dismiss, preflight, etc.)
267
- ```
268
-
269
- **Post-batch landing on `main`** (after `spine batch start` succeeds):
270
-
271
- 1. `spine status --diagnose` — expect `needs_integrate` when orch has commits not on `main`
272
- 2. `spine gate status` — review evidence under `.spine/runtime/{batchId}/evidence/`
273
- 3. `spine gate approve` — required when `gates.requireBeforeIntegrate` is true
274
- 4. `spine integrate` — local `--no-ff` merge of `orchBranch` → `baseBranch` (journal `integrate.started` / `integrate.completed`)
275
- 5. `spine batch complete` — archive batch record (refuses if orch is ahead of `main` but not merged; refuses **empty orch** when `mergeResults` claim success)
276
- 4. Push `main` to your remote when ready (pi-spine never auto-pushes)
277
-
278
- `spine batch complete` validates orch integration using `countCommitsAhead` (same guard family as lane **EmptyMerge** at merge time). When `gates.requireBeforeIntegrate` is true, integrate is blocked until you approve the evidence bundle.
279
-
280
- ```bash
281
- spine gate status # pending integrate gate + evidence paths
282
- spine gate approve # required before integrate (exit 2 if skipped)
283
- spine gate reject --reason "…" # refuse merge; journals gate.rejected
284
- spine integrate # merge after approval
285
- spine integrate --force-integrate # bypass only with SPINE_ALLOW_FORCE=1 (journaled)
286
- ```
287
-
288
- Evidence is collected under `.spine/runtime/{batchId}/evidence/` (`summary.md` is an honest post-mortem per NFR-OBS-03, plus `diff-stat.txt` and optional test/build output from `spine-config.json` or `.pi/taskplane-config.json`). `spine batch dismiss` / `complete` also write `.spine/runtime/{batchId}/post-mortem.md` and record the path in `batch-history.json`.
289
-
290
- In pi: `/spine-gate` and `/spine-integrate` delegate to `spine gate` and `spine integrate`.
291
-
292
- **Limbo recovery playbook** (Taskplane batch red, all tasks green, empty `mergeResults`):
293
-
294
- 1. `spine status --diagnose` — expect `limbo_stale` or `completed_manual`
295
- 2. If work is already on `main`: `spine batch complete --detect-manual-merge`
296
- 3. If batch should be cleared without claiming merge: `spine batch dismiss --reason …`
297
- 4. Do not hand-edit `.pi/batch-state.json`; pi-spine archives to `.spine/runtime/{batchId}/archive/` first
298
-
299
- In pi: `/spine-dismiss`, `/spine-next`, and `/spine` route to the same reconciliation (never suggest pause for terminal limbo).
300
-
301
- ### Wave planning
302
-
303
- Preview dependency waves and parallel lanes before starting a batch (FR-SCHED-01–06):
304
-
305
- ```bash
306
- spine plan all # all discovered tasks (full backlog)
307
- spine plan pending # tasks without `.DONE` marker
308
- spine plan TP-008 # explicit task ID(s)
309
- spine plan 'taskplane-tasks/TP-008-*' # glob on task folder paths
310
- spine plan pending --json # JSON plan; scope.mode pending + excluded count
311
- ```
312
-
313
- Each `spine plan` run writes a plan artifact to `.spine/runtime/plan-{timestamp}.json`.
314
-
315
- **Waves, lanes, and ticks:** A **wave** is a dependency group — tasks in wave *N* start only after wave *N−1* merges. Within a wave, the planner assigns **virtual lanes** from file-scope overlap: disjoint scopes get separate lanes (parallel up to `lanes.maxParallel`); overlapping scopes share one lane (serialized on one worktree). A **tick** queues virtual lanes when there are more lanes than `maxParallel` (tick 0 runs lanes 0…`maxParallel−1`, tick 1 runs the rest, and so on). The batch engine runs **one worker at a time per physical lane/worktree** and parallelizes only across distinct lane numbers in the same tick. The dashboard **Lanes** table shows **Active tasks** (running/pending in the current wave on that lane) separately from **Batch assignment** (all tasks ever bound to the lane).
316
-
317
- ### Running a batch (Phase 2–5)
318
-
319
- pi-spine runs batches without Taskplane `/orch`. **Single-task** batches always work. **Multi-task** batches are allowed when the plan has one wave with multiple virtual lanes (disjoint file scopes), when scope is explicit (task IDs), or when scope is **`pending`** (unfinished tasks only). **`spine batch start all`** resolves to the same pending-filtered set as `pending` (unlike `spine plan all`, which previews the full backlog):
320
-
321
- ```bash
322
- spine preflight # required (FR-BATCH-11)
323
- spine batch start TP-012 # one task (detached engine; returns immediately)
324
- spine batch start TP-012 --attached # foreground engine (blocks until batch completes)
325
- spine batch start TP-997 TP-998 # explicit multi-task (one wave, parallel lanes)
326
- spine batch start pending # all tasks without `.DONE`, dependency order
327
- spine batch start all # same as pending (not full backlog)
328
- spine run pending # alias for batch start (PRD §15.2 automation)
329
- spine run pending --dry-run --skip-preflight # flag passthrough
330
- spine batch start TP-012 --dry-run # preflight + plan only
331
- spine batch start TP-012 --json # machine-readable result
332
- ```
333
-
334
- If every discovered task has a `.DONE` marker, `pending` / `all` batch start fails fast: `No pending tasks (all discovered tasks have .DONE).` Tasks that already have `.DONE` on disk are skipped before the worker runs (journal event `task.skipped_done_on_disk`). Wave integrate / `batch complete` between waves is still manual — pi-spine does not auto-integrate mid-batch.
335
-
336
- **What happens:** preflight → planner waves + lane ticks (`lanes.maxParallel`, FR-SCHED-03/04) → `.spine/batch-state.json` (schema v1, includes `segments[]`) → one git worktree per physical lane (`.worktrees/spine-{batchId}/lane-N`, branch `task/spine-lane-N-{batchId}`) → workers run in parallel across lanes per tick, serialized within a lane when multiple tasks share it → `.DONE` → **lane auto-commit** → after each wave, **sequential merges** into `orch/spine-{batchId}` (FR-BATCH-08) only when every wave task is `succeeded` or `skipped` (§17.4 mixed-outcome policy; GAP-MERGE-01).
337
-
338
- **Detached by default:** `spine batch start` and `spine batch resume` spawn the batch engine in the background (like `/orch`) and return once `.spine/batch-state.json` shows the batch running again. Monitor with `spine status --diagnose`; engine logs append to `.spine/runtime/detached-engine.log`. Use `--attached` to run the engine in the foreground (previous behavior).
339
-
340
- **Mixed outcomes:** if any task in a wave is `failed` or still `pending`, merge is blocked, phase becomes `failed`, and messaging names failed IDs with `/spine-retry-task` / `/spine-skip-task` hints (never “batch ran smoothly”). Operator override: `spine batch force-merge --wave 0` then `spine batch resume --force`.
341
-
342
- Workers should still **commit at step boundaries** (see `.spine/agents/worker.md`); auto-commit is a safety net for pi sessions that finish with `.DONE` but forgot to commit.
343
-
344
- ### Step review (FR-REV, TP-020)
345
-
346
- When a task `PROMPT.md` has **Review Level > 0**, workers call the reviewer after step boundaries:
347
-
348
- ```bash
349
- spine review step --step 1 --type plan # level >= 1
350
- spine review step --step 1 --type code # level >= 2 (optional --baseline <sha>)
351
- ```
352
-
353
- - Verdicts: structured JSON `{ "verdict": "APPROVE"|"REVISE", "feedback": "..." }` (also written in the review artifact)
354
- - Artifacts: `{taskFolder}/.reviews/{step}-{timestamp}.md`
355
- - Journal: `review.started`, `review.completed`, `review.failed`
356
- - **Fail closed (FR-REV-06):** if review spawn fails at level > 0, the worker stops (non-zero exit) — no silent skip
357
-
358
- Reviewer model is configured separately in `.spine/spine-config.json` (`agents.reviewer`).
359
-
360
- ### Worker Pi tools (PRD §14.5)
361
-
362
- Lane workers register three spine tools via `registerSpineWorkerTools`: `spine_review_step`, `spine_report_progress`, and `spine_request_gate`.
363
-
364
- **`spine_request_gate` limitation (v2.2):** Permanent `not_supported` for all gate kinds (`integrate`, `manual`, `conflict`). Workers cannot open or refresh human gates; the tool returns structured JSON with `suggestedCommand: spine gate approve` so models do not invent host commands. **Operator workaround:** run `spine gate status` and `spine gate approve` from a **host shell** — not from inside a worker session. Integrate gates still open automatically when the batch engine completes a wave.
365
-
366
- See [operator runbook §5.1](docs/adoption/operator-runbook.md#51-worker-spine_request_gate-fr-ship-13--v22) and [worker-gate-inventory.md](docs/design/worker-gate-inventory.md).
367
-
368
- ### Pause and resume (Phase 3 — single and multi lane)
369
-
370
- ```bash
371
- spine batch pause # stop scheduling; journal batch.paused
372
- spine batch resume # continue paused batch (detached; returns immediately)
373
- spine batch resume --attached # foreground resume (blocks until batch completes)
374
- spine batch resume --force # resume failed batch after stale lane state
375
- spine batch pause --json
376
- ```
377
-
378
- Resume skips tasks already marked complete via `.DONE` or journal `task.completed`, respawns workers in existing lane worktrees for pending segments across all lanes, logs `batch.resumed` with `{ resumeForced, pendingSegments }`, then runs lane commit + merge per wave.
379
-
380
- Multi-task batches (more than one task or lane) use the same commands; validation and execution resume pending tasks in parallel within each wave, then merge succeeded lane branches into the orch branch.
381
-
382
- In pi: `/spine-pause` and `/spine-resume` delegate to `spine batch pause|resume`. When `spine status` reports `diagnosis: paused`, the suggested command is `spine batch resume` (not Taskplane pause).
383
-
384
- ### Abort (Phase 3 — archive-first, §18.6)
385
-
386
- Stop a batch without losing recoverable state (closes GAP-ABORT-01):
387
-
388
- ```bash
389
- spine batch abort # graceful: abort signal; worker may finish step boundary
390
- spine batch abort --hard # SIGKILL lane workers; remove worktrees (configurable)
391
- spine batch abort --reason "stall kill" # journal reason on batch.aborted
392
- spine batch abort --hard --json
393
- ```
394
-
395
- **Archive-first:** pi-spine always writes `.spine/runtime/{batchId}/archive/batch-state.json` (including `segments[]`) **before** clearing `.spine/batch-state.json` or Taskplane `.pi/batch-state.json`. The journal append-only log is preserved; `batch.aborted` is appended with reason and prior tail metadata.
396
-
397
- Graceful abort writes `.spine/runtime/{batchId}/abort-signal.json` (`hard: false`). The worker host polls this signal and sends SIGTERM so the worker can exit at the next poll boundary. Hard abort sets `hard: true`, kills `lane.workerPid` when recorded, and removes lane worktrees unless `lanes.cleanupWorktreesOnHardAbort` is `false` in `.spine/spine-config.json`.
398
-
399
- In pi: `/spine-abort` and `/spine-abort --hard` delegate to `spine batch abort`. When a batch was aborted, `spine status` reports `diagnosis: aborted` — use `spine batch dismiss` to clear limbo if needed.
400
-
401
- ### Retry and skip (Phase 3)
402
-
403
- When a task fails or segment state drifts (Taskplane GAP-RETRY-01), reset task + segments atomically before resume:
404
-
405
- ```bash
406
- spine batch retry TP-012 # reset task + segments; journal pendingSegments
407
- spine batch skip TP-012 # skip failed task; unblock wave merge (FR-BATCH-10)
408
- spine batch force-merge --wave 0 # operator override for §17.4 (then resume --force)
409
- spine batch retry TP-012 --json
410
- ```
411
-
412
- Retry clears task timestamps, resets all segment records for the task to `pending`, decrements `failedTasks`, and journals `task.retry_requested` with `{ taskId, previousClassification, pendingSegments }`. Resume refuses segment drift (`RetrySegmentDrift`) until retry or `--force`.
413
-
414
- In pi: `/spine-retry-task <taskId>` and `/spine-skip-task <taskId>` delegate to `spine batch retry|skip`. When `spine status` reports `diagnosis: needs_retry`, the suggested command is `/spine-retry-task {id}`.
415
-
416
- **Runtime layout:**
417
-
418
- | Path | Purpose |
419
- |------|---------|
420
- | `.spine/batch-state.json` | Active batch (pi-spine native; not `.pi/batch-state.json`) |
421
- | `.spine/batch-history.json` | Terminal batch summaries (complete/dismiss/aborted) |
422
- | `.spine/runtime/{batchId}/archive/batch-state.json` | Archived batch snapshot after abort/dismiss/complete |
423
- | `.spine/runtime/{batchId}/abort-signal.json` | In-flight abort request (graceful or hard) |
424
- | `.spine/runtime/{batchId}/journal/events.jsonl` | Append-only journal |
425
- | `.worktrees/spine-{batchId}/lane-N` | Lane worktree (N = 1 … `lanes.maxParallel`) |
426
-
427
- **Recovery:** `spine status --diagnose` → `spine batch dismiss` or `spine batch complete` (same as Phase 1b lifecycle).
428
-
429
- **Multi-task paused batch:** when more than one task is still pending, `spine status --diagnose` reports `diagnosis: paused` with a headline naming how many tasks remain (for example, “2 tasks pending — use spine batch resume (multi-task)”). Run `spine batch resume` (detached by default) to continue all lanes; use `--attached` to block until the batch finishes. This replaces the Phase 8 workaround of starting a fresh single-task batch after a multi-task pause (batch `20260602T181027`).
430
-
431
- ### Journal replay and state validation (TP-014)
432
-
433
- Audit orchestration timelines and validate batch-state cache integrity:
434
-
435
- ```bash
436
- spine journal replay --batch 20260601T120000 # human table: time | type | lane | task | summary
437
- spine journal replay --batch 20260601T120000 --json
438
- spine state validate # active .spine/batch-state.json
439
- spine state validate --batch 20260601T120000 # archived runtime copy
440
- spine state validate --diagnose # extra context on validation failure
441
- ```
442
-
443
- Journal events use **schema v1** (`schemaVersion`, `eventId`, ISO `timestamp`, optional `correlationId`, `payload`). Legacy JSONL lines without `schemaVersion` remain readable.
444
-
445
- On **complete** or **dismiss**, pi-spine appends a summary entry to `.spine/batch-history.json` and writes terminal journal events (`batch.completed` / `batch.dismissed`).
446
-
447
- **CI / tests without `pi`:** set `SPINE_WORKER_STUB=1` so the worker runner touches `.DONE` instead of spawning `pi` (see `bin/spine-worker-runner.mjs`). Use `SPINE_WORKER_STUB_FAIL_TASKS=TP-998` (comma-separated) to simulate task failure for mixed-outcome tests.
448
-
449
- **Heartbeat and stall (TP-013):** during a batch, the engine polls lane progress (STATUS.md mtime, lane-branch commits) and appends `lane.heartbeat` to the journal on an interval (default 10 minutes). Stall kill uses §18.4 grace after progress. Configure in `.spine/spine-config.json`:
450
-
451
- ```json
452
- "lanes": {
453
- "stallTimeoutMinutes": 60,
454
- "stallGraceAfterProgressMinutes": 15,
455
- "heartbeatIntervalMinutes": 10
456
- }
457
- ```
458
-
459
- With `pi` on PATH, `spine batch start` runs `pi -p` against the task `PROMPT.md` (disable via `SPINE_WORKER_PI_AGENT=0`).
460
-
461
- Do **not** run `spine batch start` and Taskplane `/orch` on the same repo concurrently.
462
-
463
- In a pi session (`/spine` runs preflight before batch guidance; `/spine-plan` invokes the planner):
464
-
465
- | Command | Status |
466
- |---------|--------|
467
- | `/spine` | Preflight + `spine batch start` for a **single** task ID (Phase 2) |
468
- | `/spine-plan` | Preview waves and lanes (usage: `/spine-plan <all\|paths>`) |
469
- | `/spine-status` | Reconciled batch diagnosis + lane health (FR-BATCH-14) |
470
- | `/spine-dismiss` | `spine batch dismiss` (limbo / completed_manual) |
471
- | `/spine-next` | `spine next` — suggested next command |
472
- | `/spine-pause` | `spine batch pause` — stop scheduling |
473
- | `/spine-resume` | `spine batch resume` — continue paused or failed batch |
474
- | `/spine-abort` | `spine batch abort` — archive-first abort (`--hard` kills workers) |
475
- | `/spine-gate` | Stub — gate inspection and resolution |
476
- | `/spine-integrate` | Merge orch branch → `main` (`spine integrate`; gate stub in Phase 3) |
477
- | `/spine-settings` | Editable config menu + inline `set` (delegates to `spine settings`) |
478
- | `/spine-deps` | Show dependency graph (`spine deps`; usage: `/spine-deps <all\|paths>`) |
479
- | `/spine-dashboard` | Start local SSE dashboard (`spine dashboard` in background) |
480
-
481
- Most slash commands remain stubs; **`/spine`**, **`/spine-plan`**, **`/spine-status`**, **`/spine-dismiss`**, **`/spine-next`**, **`/spine-deps`**, **`/spine-settings`**, and **`/spine-dashboard`** are implemented. **`/spine <task-id>`** starts a Phase 2 single-task batch when preflight passes (stub worker unless `SPINE_WORKER_STUB=0` and `pi` is on PATH). Stubs reply with a notification pointing to `spine help` and a future phase. **`/spine`** runs `spine preflight` first and blocks batch guidance when preflight fails. Example flow:
105
+ ## How it works
482
106
 
483
107
  ```text
484
- spine preflight # required before batch (FR-BATCH-11)
485
- /spine-plan all # preview waves and lanes
486
- /spine all # run the batch
487
- /spine-status # monitor progress
488
- /spine-gate # review evidence before merge
489
- /spine-integrate # merge orch branch (after gate approval)
490
- ```
491
-
492
- Optional: run the dashboard in another terminal or from pi with `/spine-dashboard`:
493
-
494
- ```bash
495
- spine dashboard # default http://127.0.0.1:8109
496
- spine dashboard --port 8110 # override CLI port
108
+ preflight → plan waves → batch start (worktree lanes)
109
+ → workers (PROMPT/STATUS, .DONE) → lane merge → orch branch
110
+ → gate approve → integrate → main
497
111
  ```
498
112
 
499
- As soon as the server is listening, the CLI prints the browser URL, listen address, SSE note, suggested `spine status` / `spine batch start` commands, and API paths (keep the terminal open while the dashboard runs).
500
-
501
- Set `dashboard.port` in `.spine/spine-config.json` (default **8109**, avoids Taskplane port 8099). Example from `spine init`:
502
-
503
- ```json
504
- "dashboard": {
505
- "port": 8109
506
- }
507
- ```
113
+ Waves serialize dependency groups; lanes parallelize disjoint file scopes within a wave. See **[EXECUTION-FLOW-DIAGRAMS.md](docs/EXECUTION-FLOW-DIAGRAMS.md)** and **[EXECUTION-FLOW.md](docs/EXECUTION-FLOW.md)** for lifecycle detail.
508
114
 
509
- The browser UI streams reconciled snapshots over SSE (`/api/events`, **2s** poll interval per NFR-OBS-02). Panels: batch summary, **diagnosis banner** (badge color from `diagnosis`, not raw `phase`), copyable CLI action chips (primary + `alternatives[]` — run commands in your terminal; no HTTP mutations), wave progress (with a lane ≠ wave reminder), lane table (**Active tasks** vs **Batch assignment**), integrate gate, and journal tail. Diagnosis fields match `spine status --json` and `buildDashboardSnapshot()` (NFR-OBS-04 / GAP-UX-03).
115
+ ## Best-of-N (dev script)
510
116
 
511
- ---
117
+ `scripts/best-of-n.mjs` runs the same prompt through multiple pi models in parallel worktrees — for comparing outputs, not production batches. Git checkout only; not shipped on npm. See **[docs/QUICK-REFERENCE.md](docs/QUICK-REFERENCE.md)** (dev scripts) and `scripts/best-of-n.mjs`.
512
118
 
513
119
  ## Migrating from Taskplane
514
120
 
515
- If you already use Taskplane task folders:
516
-
517
121
  1. Install pi-spine in the same or a new repo.
518
122
  2. `spine init` then `spine doctor`
519
- 3. Migrate config from `.pi/taskplane-config.json` (see `spine migrate-from-taskplane`).
123
+ 3. Migrate config from `.pi/taskplane-config.json` (`spine migrate-from-taskplane`).
520
124
  4. Run `/spine-plan all` and compare to your last Taskplane plan.
521
125
 
522
- Do **not** run Taskplane and pi-spine batches on the same repo at the same time.
523
-
524
- ---
126
+ Do **not** run Taskplane and pi-spine batches on the same repo concurrently. See **[bootstrap-checklist.md](docs/adoption/bootstrap-checklist.md)**.
525
127
 
526
128
  ## Project status
527
129
 
528
- **Early development.** pi-spine is designed as a personal orchestration spine first, publishable as `npm:pi-spine` when stable. API and behavior may change before v1.0.
529
-
530
- ## Continuous integration
531
-
532
- Every push and pull request to `main` runs [GitHub Actions CI](.github/workflows/ci.yml): `npm ci`, `npm run typecheck`, `npm test` (when defined), **`npm run coverage:check`** (≥77% line coverage on `src/`, `bin/`, `extensions/`), and CLI smoke checks (`spine version`, `help`, `doctor`). `spine init` sets `testing.testWithCoverage` to the same command by default.
130
+ **v1.1.0** on [npm](https://www.npmjs.com/package/pi-spine) and [pi.dev](https://pi.dev/packages/pi-spine). API may still evolve in patch releases; see git tags and **[docs/release/](docs/release/)**.
533
131
 
534
- ---
132
+ CI runs on every push and PR: typecheck, tests, coverage, and CLI smoke checks — see **[.github/workflows/ci.yml](.github/workflows/ci.yml)** and **[npm-publish.md](docs/release/npm-publish.md)**.
535
133
 
536
134
  ## Documentation
537
135
 
538
136
  | Document | Purpose |
539
137
  |----------|---------|
540
- | [docs/PRD.md](docs/PRD.md) | Product requirements and implementation contract (v1.2) |
541
- | [docs/PRD-v1.3-upstream-execution-bridge.md](docs/PRD-v1.3-upstream-execution-bridge.md) | v1.3 addendum: validate, explore, final verdict, handoff, metrics |
542
- | [docs/adoption/upstream-execution-workflow.md](docs/adoption/upstream-execution-workflow.md) | Authoring → validation → batch (optional zero-pi upstream) |
543
- | [docs/adoption/local-install.md](docs/adoption/local-install.md) | Git/path install before npm publish |
138
+ | [docs/PRD.md](docs/PRD.md) | Product requirements and implementation contract |
139
+ | [docs/QUICK-REFERENCE.md](docs/QUICK-REFERENCE.md) | Operator command reference |
140
+ | [docs/EXECUTION-FLOW.md](docs/EXECUTION-FLOW.md) | Batch lifecycle and scheduling |
141
+ | [docs/adoption/why-pi-spine.md](docs/adoption/why-pi-spine.md) | Positioning vs Taskplane, Babysitter, pi-conductor |
544
142
  | [docs/adoption/operator-runbook.md](docs/adoption/operator-runbook.md) | Daily operator procedures |
545
- | [docs/adoption/real-project-readiness.md](docs/adoption/real-project-readiness.md) | Phase 9 adoption plan |
546
- | pi.dev package page | Install and package manifest (when published) |
547
-
548
- ---
143
+ | [docs/adoption/bootstrap-checklist.md](docs/adoption/bootstrap-checklist.md) | First-time setup |
549
144
 
550
145
  ## License
551
146
 
552
147
  MIT (intended).
553
-
554
- ---
555
-
556
- ## Related projects
557
-
558
- - [Taskplane](https://pi.dev/packages/taskplane) — parallel task orchestration for pi
559
- - [Babysitter](https://github.com/a5c-ai/babysitter) — event-sourced workflow SDK
560
- - [pi-conductor](https://www.npmjs.com/package/@feniix/pi-conductor) — durable agent control plane for pi
561
- - [pi-subagents](https://www.npmjs.com/package/pi-subagents) — optional delegation layer (planned v1.1 backend)
562
-
563
- pi-spine respects these tools: it composes their best patterns rather than replacing them outright.