pi-spine 1.8.1 → 1.10.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 (38) hide show
  1. package/bin/spine-cli/verify.mjs +2 -0
  2. package/bin/spine-run.mjs +2 -0
  3. package/extensions/spine/slash-commands.ts +1 -1
  4. package/package.json +1 -1
  5. package/skills/create-spine-tasks/SKILL.md +41 -0
  6. package/skills/create-spine-tasks/references/contract-template.md +30 -2
  7. package/skills/create-spine-tasks/references/prompt-template.md +3 -1
  8. package/skills/spine-autonomous-operator/SKILL.md +14 -2
  9. package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +91 -0
  10. package/skills/spine-orchestrate-waves/SKILL.md +10 -6
  11. package/skills/spine-orchestrate-waves/references/outer-loop.md +22 -5
  12. package/skills/spine-release-operator/SKILL.md +70 -11
  13. package/skills/spine-release-operator/references/pi-async-orchestration.md +2 -2
  14. package/skills/spine-release-operator/references/release-manifest-template.md +38 -1
  15. package/src/batch/attached-runner.mjs +128 -1
  16. package/src/batch/batch-state-io.mjs +12 -0
  17. package/src/batch/contract-prelanded.mjs +83 -0
  18. package/src/batch/contract-verify.mjs +19 -5
  19. package/src/batch/detached-start.mjs +8 -1
  20. package/src/batch/diagnosis.mjs +25 -0
  21. package/src/batch/engine-lanes/review.mjs +131 -26
  22. package/src/batch/journal.mjs +5 -0
  23. package/src/batch/lifecycle.mjs +18 -0
  24. package/src/batch/reconcile.mjs +11 -0
  25. package/src/batch/resume.mjs +10 -1
  26. package/src/batch/review.mjs +196 -0
  27. package/src/batch/sequence.mjs +155 -5
  28. package/src/cli/sequence.mjs +5 -1
  29. package/src/config/preflight/integrate-plan.mjs +31 -7
  30. package/src/config/spine-preflight-lib.mjs +1 -0
  31. package/src/dashboard/cache-invalidate.mjs +91 -0
  32. package/src/dashboard/server.mjs +7 -0
  33. package/src/dashboard/snapshot.mjs +3 -0
  34. package/src/doctor/sequence-safety.mjs +40 -5
  35. package/src/planner/format-plan.mjs +5 -1
  36. package/src/planner/index.mjs +3 -1
  37. package/src/planner/waves.mjs +41 -0
  38. package/src/tasks/validate-contract-warn.mjs +38 -1
@@ -26,6 +26,8 @@ export const PHASE23_GRANDFATHERED_OVER_500 = [
26
26
  "src/batch/contract-verify.mjs",
27
27
  "src/batch/journal-rebuild.mjs",
28
28
  "src/batch/lane-dirty-check.mjs",
29
+ "src/batch/attached-runner.mjs",
30
+ "src/batch/lifecycle.mjs",
29
31
  ];
30
32
 
31
33
  const PHASE23_ENGINE_LANES_MAX = 500;
package/bin/spine-run.mjs CHANGED
@@ -6,6 +6,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
6
  /**
7
7
  * Route `spine run` subcommands.
8
8
  * - `spine run sequence <scope>` — planner wave sequence (GitHub #54 Tier 2)
9
+ * Release scope: comma-separated SP-IDs or `--profile release` (FR-STA-25 / SP-536).
10
+ * Dry-run: `spine run sequence <scope> --dry-run` — see docs/release/manifest-v1.10.0-example.md
9
11
  * - `spine run <scope>` — alias for `spine batch start <scope>` (TP-024)
10
12
  *
11
13
  * @param {object} options
@@ -284,7 +284,7 @@ export function formatOrchestratePrompt(
284
284
  "## Outer loop (per wave — you decide gate/integrate)",
285
285
  "",
286
286
  "1. spine preflight",
287
- `2. spine batch start ${scope} --wave W --attached`,
287
+ `2. spine batch start ${scope} --wave W # detached — monitor with spine wait`,
288
288
  "3. spine wait --until completed,needs_integrate,failed,aborted,needs_retry --timeout 4h",
289
289
  "4. spine status --diagnose",
290
290
  "5. spine gate status # review .spine/runtime/<batchId>/evidence/",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "1.8.1",
3
+ "version": "1.10.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -457,6 +457,43 @@ When decomposing a PRD, assign non-overlapping file scopes to tasks that should
457
457
 
458
458
  **Reviewer rules (FR-REV-08):** Plan reviews use the same File Scope for glob matching; code reviews use changed paths from `git diff`. Final reviews load always-on rules only. Worker-only packs (`taskplane-worker-cursor.mdc`) are excluded from reviewer context by default.
459
459
 
460
+ **Documentation paths in File Scope ([#144](https://github.com/beettlle/pi-spine/issues/144)):** Every path under **Must Update** in `## Documentation Requirements` **must** also appear in `## File Scope`. If a doc is advisory only, move it to **Check If Affected** — do not require workers to edit paths outside File Scope. Mismatches (e.g. SP-435, SP-451) caused out-of-scope edits and merge dirty-file failures.
461
+
462
+ ---
463
+
464
+ ## Docs-only contract pattern (FR-STA-12)
465
+
466
+ Use when the task delivers **documentation only** — no application code changes. Pair with Review Level 0 and Size S when appropriate.
467
+
468
+ ### Required fields
469
+
470
+ | Field | Value |
471
+ |-------|-------|
472
+ | `testCommand` | `` `true` `` |
473
+ | `fileScopeMustChange` | At least one documentation deliverable path (same paths in `## File Scope`) |
474
+
475
+ Without `fileScopeMustChange`, workers can pass contract by creating only `.DONE` (SP-214 batch `20260612T204048`, SP-457 batch `20260703T022335`).
476
+
477
+ ### Recommended scope guard ([#142](https://github.com/beettlle/pi-spine/issues/142))
478
+
479
+ Add `fileScopeMustNotChange` on product-code directories so accidental edits fail contract verify before merge:
480
+
481
+ ```markdown
482
+ | fileScopeMustNotChange | `src/**`, `bin/**` |
483
+ ```
484
+
485
+ Never ban `spine-tasks/**` — workers must update `STATUS.md` and create `.DONE`. Full example: [references/contract-template.md](references/contract-template.md#docs-only-with-scope-guard-recommended).
486
+
487
+ ### Docs-only vs scoped `node --test`
488
+
489
+ | Use docs-only (`testCommand: true`) | Use scoped `node --test` instead |
490
+ |-------------------------------------|----------------------------------|
491
+ | Skill, runbook, or README edits only | Any `src/**`, `bin/**`, or test file change |
492
+ | Review Level 0, Size S, no code deliverable | Size S/M patch with an existing targeted test |
493
+ | Contract proof is doc mtime, not test output | Contract must prove code behavior |
494
+
495
+ Docs-only tasks still include `### Step N: Testing & Verification` (full suite in the Testing step) — Contract `` `true` `` only means final verify does not re-run tests. See [contract-template decision table](references/contract-template.md#docs-only-vs-scoped-node---test).
496
+
460
497
  ---
461
498
 
462
499
  ## Unsupported (spine v1)
@@ -476,6 +513,10 @@ Before reporting launch commands:
476
513
  - [ ] Size S/M/L — split if XL
477
514
  - [ ] PROMPT.md from template: Mission, Dependencies, Context, File Scope, Contract (SP-\*), Steps, Do NOT, Git Commit Convention, Amendments
478
515
  - [ ] If `testCommand` is `` `true` ``, `fileScopeMustChange` MUST list at least one deliverable path
516
+ - [ ] Every **Must Update** doc path also appears in `## File Scope` ([#144](https://github.com/beettlle/pi-spine/issues/144))
517
+ - [ ] Docs-only tasks: consider `fileScopeMustNotChange` on `src/**`, `bin/**` ([#142](https://github.com/beettlle/pi-spine/issues/142)); see [Docs-only contract pattern](#docs-only-contract-pattern-fr-sta-12)
518
+ - [ ] S/M patch Contract uses scoped `node --test` — not `npm test` or `npm test -- path` ([#141](https://github.com/beettlle/pi-spine/issues/141), SP-522)
519
+ - [ ] Plan waves ≤8 tasks when possible — `spine plan` warns when exceeded ([#143](https://github.com/beettlle/pi-spine/issues/143), SP-524)
479
520
  - [ ] `### Step N: Testing & Verification` present inside `## Steps` before `## Completion Criteria` (required even for docs-only Review Level 0)
480
521
  - [ ] STATUS.md with matching steps (hydration markers where needed)
481
522
  - [ ] `dependencies.json` updated when task has deps
@@ -120,6 +120,21 @@ Symptom in journal: `testCommand` passes but `fileScopeMustNotChange` fails with
120
120
 
121
121
  When `testCommand` is `` `true` ``, **always** include `fileScopeMustChange` listing at least one documentation file the task must modify. Without it, workers can pass contract by creating only `.DONE` — two batches were rejected for this reason (SP-214 batch `20260612T204048`, SP-457 batch `20260703T022335`).
122
122
 
123
+ Every path in `fileScopeMustChange` **must** also appear in PROMPT `## File Scope` ([#144](https://github.com/beettlle/pi-spine/issues/144)) — workers cannot edit out-of-scope deliverables without merge dirty-file failures.
124
+
125
+ ```markdown
126
+ ## Contract
127
+
128
+ | Field | Value |
129
+ |-------|-------|
130
+ | testCommand | `true` |
131
+ | fileScopeMustChange | `docs/adoption/operator-runbook.md` |
132
+ ```
133
+
134
+ ### Docs-only with scope guard (recommended)
135
+
136
+ For docs-only tasks, add `fileScopeMustNotChange` on product-code directories so accidental worker edits to `src/**` or `bin/**` fail contract verify before merge — SP-457 post-mortem `20260703T051629` landed docs in-worker but merge failed on dirty `src/batch/`, `bin/`, `.spine/` paths ([#142](https://github.com/beettlle/pi-spine/issues/142)). Do **not** list `spine-tasks/**` here (workers must update `STATUS.md` and `.DONE`).
137
+
123
138
  ```markdown
124
139
  ## Contract
125
140
 
@@ -127,8 +142,19 @@ When `testCommand` is `` `true` ``, **always** include `fileScopeMustChange` lis
127
142
  |-------|-------|
128
143
  | testCommand | `true` |
129
144
  | fileScopeMustChange | `docs/adoption/operator-runbook.md` |
145
+ | fileScopeMustNotChange | `src/**`, `bin/**` |
130
146
  ```
131
147
 
148
+ ### Docs-only vs scoped `node --test`
149
+
150
+ | Situation | Contract pattern |
151
+ |-----------|------------------|
152
+ | No application code changes; documentation or skill text only | `` `true` `` + `fileScopeMustChange` on deliverable doc paths (+ optional `fileScopeMustNotChange` on `src/**`, `bin/**`) |
153
+ | Small code change with an existing targeted test file | `` `node --test tests/feature.test.mjs` `` (see [scoped testCommand](#scoped-testcommand) below) |
154
+ | Code change but no narrow test yet; full suite unsafe in lane | Scoped command matching the Testing step, or split into a code task + docs task |
155
+
156
+ Use docs-only when the worker's only product deliverable is documentation. Use scoped `node --test` when the task changes application code — even Size S/M patches should not use bare `` `npm test` `` or `` `npm test -- path` `` in Contract ([#141](https://github.com/beettlle/pi-spine/issues/141)).
157
+
132
158
  ### Scope guard for parallel wave
133
159
 
134
160
  ```markdown
@@ -167,13 +193,15 @@ When the worker model differs from the reviewer model (e.g. worker `cursor/auto`
167
193
 
168
194
  ### Scoped `testCommand`
169
195
 
196
+ Prefer `` `node --test tests/feature.test.mjs` `` for targeted proof in Contract. `` `npm test -- path` `` runs the full npm test script in lane worktrees — `spine tasks validate` warns or errors (FR-STA-10 / SP-522).
197
+
170
198
  Lane worktrees are **not** identical to the developer checkout. Worktree setup hooks, missing assets, pre-existing test failures, and Flutter/monorepo full-suite pollution can cause a scoped worker to pass targeted tests while the unscoped `testCommand` in Contract fails at final verify.
171
199
 
172
200
  | Avoid | Prefer |
173
201
  |-------|--------|
174
202
  | `` `flutter test` `` / `` `npm test` `` (full suite in lane worktree) | Targeted command matching the Testing step: `` `flutter test test/unit/services/foo_test.dart` `` |
175
203
  | Same command in Contract and global `testing.test` without verifying lane compatibility | Document when to use `` `true` `` (docs-only) vs scoped shell proof |
176
- | Unscoped command producing >10 MB stdout (SP-426 `maxBuffer`) | Narrow test scope; prefer `npm test -- tests/feature.test.mjs` |
204
+ | Unscoped command producing >10 MB stdout (SP-426 `maxBuffer`) | Narrow test scope; prefer `` `node --test tests/feature.test.mjs` `` |
177
205
 
178
206
  **Engine-side lane fixes:** [#78](https://github.com/beettlle/pi-spine/issues/78), [#80](https://github.com/beettlle/pi-spine/issues/80) track worktree setup hook and analyzer hygiene — docs alone cannot fix lane environment drift.
179
207
 
@@ -194,7 +222,7 @@ Reviewers spawn as **fresh sessions** with no memory of the worker session (FR-R
194
222
  | Task type | Recommended `testCommand` |
195
223
  |-----------|---------------------------|
196
224
  | Docs-only, no code changes | `` `true` `` **and** `fileScopeMustChange` with at least one deliverable doc path |
197
- | Single module, targeted tests exist | `` `npm test -- tests/feature.test.mjs` `` or `` `flutter test test/unit/services/foo_test.dart` `` |
225
+ | Single module, targeted tests exist | `` `node --test tests/feature.test.mjs` `` or `` `flutter test test/unit/services/foo_test.dart` `` |
198
226
  | Full-suite safe in lane worktree | `` `npm run typecheck && SPINE_WORKER_STUB=1 npm test` `` |
199
227
  | Coverage gate required (pi-spine ≥77%) | `` `npm run coverage:check` `` |
200
228
  | Long external job (>2h) | Scoped command + `stallTimeoutMinutes` and `extendGraceOnFileScope` in Contract (see SP-314 example above) |
@@ -118,7 +118,9 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
118
118
 
119
119
  > **Required for every task** — including docs-only and Review Level 0 packets.
120
120
  > ZERO test failures allowed. This step runs the FULL test suite as a quality gate.
121
- > (Earlier steps should use targeted tests for fast feedback — see worker prompt.)
121
+ > Earlier steps should use **targeted** tests for fast feedback — e.g.
122
+ > `node --experimental-strip-types --test tests/feature.test.mjs` (not `npm test -- path`,
123
+ > which runs the full suite in lane worktrees; see SP-522).
122
124
  >
123
125
  > **Docs-only tasks:** keep this step; run the full test suite. Omit the coverage-gate
124
126
  > checkbox below when the task does not change application code.
@@ -32,6 +32,7 @@ Invoke explicitly: `/skill:spine-autonomous-operator`
32
32
  - **Do not** use unattended `spine run sequence --auto-approve-gate --force` without monitoring
33
33
  - **Do not** start a second batch while another batch is **running** on the same repo
34
34
  - **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
35
+ - **Cursor Agent shell (~120s background timeout):** use **detached** `spine batch start|resume` (omit `--attached`); monitor with `spine status --diagnose` and `spine wait` — see [references/agent-shell-batch-policy.md](references/agent-shell-batch-policy.md)
35
36
  - **Release and agent batches:** use **detached** `spine batch start|resume` (omit `--attached`) unless the operator shell blocks until batch completion; then `spine wait --until …` ([#163](https://github.com/beettlle/pi-spine/issues/163), [#185](https://github.com/beettlle/pi-spine/issues/185)). `spine doctor` warns in non-interactive and agent-harness contexts.
36
37
 
37
38
  ## Phase 0 — Baseline
@@ -123,7 +124,9 @@ spine run sequence pending --dry-run
123
124
 
124
125
  For each wave `N` until `spine plan pending` shows 0 tasks:
125
126
 
126
- ### 3.1 Start
127
+ ### 3.1 Start (detached default)
128
+
129
+ See [references/agent-shell-batch-policy.md](references/agent-shell-batch-policy.md). **Omit `--attached`** unless you are in a persistent interactive human terminal that stays foreground for the full batch.
127
130
 
128
131
  **pi async (preferred in pi sessions)** — see [pi-async-orchestration.md](../spine-release-operator/references/pi-async-orchestration.md):
129
132
 
@@ -137,7 +140,15 @@ MonitorCreate:
137
140
 
138
141
  After detached start, monitor with `spine wait --until completed,needs_integrate,failed,aborted --timeout 4h` or `spine status --diagnose`.
139
142
 
140
- **Foreground fallback** (interactive terminal only — keep shell in foreground for full batch):
143
+ **Detached shell fallback** (Cursor Agent, non-pi, CI — parent may return before batch finishes):
144
+
145
+ ```bash
146
+ spine batch start pending --wave N
147
+ spine status --diagnose
148
+ spine wait --until completed,needs_integrate,failed,aborted --timeout 4h
149
+ ```
150
+
151
+ **`--attached`** (persistent interactive human terminal only — shell stays foreground for full batch duration):
141
152
 
142
153
  ```bash
143
154
  spine batch start pending --wave N --attached
@@ -254,6 +265,7 @@ In pi sessions, `MonitorCreate` for `npm run release:check` is allowed (see pi-a
254
265
  - **Tasks root:** `spine-tasks/`
255
266
  - **Config:** `.spine/spine-config.json`
256
267
  - **Test gate:** `npm run release:check` (typecheck → lint → tests → coverage)
268
+ - **Agent shell policy:** [references/agent-shell-batch-policy.md](references/agent-shell-batch-policy.md)
257
269
  - **Known upstream issues:** #114 (integrate hang, fixed), #118 (trailing-slash contracts), #130 (`coverage/` restore), #163 (`engine_orphaned`)
258
270
 
259
271
  ## Short prompt (resume mid-batch)
@@ -0,0 +1,91 @@
1
+ # Agent shell batch policy
2
+
3
+ When an **external agent** (Cursor Agent, pi MonitorCreate, CI script, OpenCode) drives spine batches, the parent shell may return or be killed before the batch engine finishes. Use **detached** start/resume and monitor separately.
4
+
5
+ **Related:** [#163](https://github.com/beettlle/pi-spine/issues/163) (attached orphan / exit 137), [#185](https://github.com/beettlle/pi-spine/issues/185) (detached default for release/agent batches), [operator-runbook §Detached-first](../../../docs/adoption/operator-runbook.md#detached-first-policy-default).
6
+
7
+ ---
8
+
9
+ ## Default for agents
10
+
11
+ Omit `--attached`. Detached is the CLI default for `spine batch start` and `spine batch resume`.
12
+
13
+ ```bash
14
+ spine batch start pending --wave 0 # detached — engine survives parent shell exit
15
+ spine status --diagnose # always after detached start/resume return
16
+ spine wait --until completed,needs_integrate,failed,aborted --timeout 4h # optional block
17
+ ```
18
+
19
+ Detached start/resume returns when the engine **starts**, not when work completes.
20
+
21
+ ---
22
+
23
+ ## Cursor Agent shell
24
+
25
+ Cursor Agent shells may background long-running commands after **~120 seconds** even when started from the IDE terminal. An `--attached` engine is tied to that parent process — when the shell backgrounds or exits, the engine is orphaned (`engine_orphaned`, exit 137) and tasks stick in `running`.
26
+
27
+ **Do not** use `spine batch start … --attached` from Cursor Agent. Use detached start + monitor.
28
+
29
+ `spine doctor` detects Cursor agent shells (`CURSOR_TRACE_ID`, `CURSOR_SESSION_ID`) and warns with a detached `suggestedCommand`. Run `spine doctor` during Phase 0 baseline and heed the warning.
30
+
31
+ ---
32
+
33
+ ## Monitor pattern (per wave)
34
+
35
+ ```bash
36
+ spine preflight
37
+ spine batch start pending --wave N
38
+ spine status --diagnose
39
+ spine wait --until completed,needs_integrate,failed,aborted,needs_retry --timeout 4h
40
+ spine status --diagnose
41
+ # → land loop or recovery per diagnosis
42
+ ```
43
+
44
+ Optional: `spine watch --once`, `spine dashboard`, `spine journal follow`.
45
+
46
+ ---
47
+
48
+ ## When `--attached` is OK
49
+
50
+ Use `--attached` only when **all** of the following hold:
51
+
52
+ - Persistent **interactive** terminal (human operator: iTerm, Terminal.app, etc.)
53
+ - Shell stays in the **foreground** for the full batch duration (often 30+ minutes for real `pi` workers)
54
+ - Short smoke batches where total runtime is well under shell harness limits
55
+
56
+ ```bash
57
+ spine batch start SP-042 --attached # human terminal — blocks until engine finishes
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Recovery
63
+
64
+ | Situation | Rule |
65
+ |-----------|------|
66
+ | Default resume after retry | `spine batch resume` (detached) |
67
+ | Diagnose suggests `--attached --force` | Run in **foreground** only — never background |
68
+ | `resume --attached` or `resume --attached --force` | **Never** MonitorCreate or background ([#163](https://github.com/beettlle/pi-spine/issues/163)) |
69
+ | After detached start/resume | Always `spine status --diagnose` before leaving session |
70
+
71
+ Follow `suggestedCommand` from `spine status --diagnose` when unsure.
72
+
73
+ ---
74
+
75
+ ## Preflight
76
+
77
+ ```bash
78
+ spine doctor
79
+ ```
80
+
81
+ If `batch --attached orphan risk (#163)` shows a warning, use detached start/resume for this session.
82
+
83
+ ---
84
+
85
+ ## Skills that reference this doc
86
+
87
+ | Skill | Use |
88
+ |-------|-----|
89
+ | `spine-autonomous-operator` | Full pending backlog operator |
90
+ | `spine-orchestrate-waves` | Multi-wave outer loop |
91
+ | `spine-release-operator` | Curated release batches |
@@ -21,6 +21,7 @@ Invoke explicitly: `/skill:spine-orchestrate-waves`, `/spine-orchestrate pending
21
21
  |---------|-------------|
22
22
  | Task packet authoring | `create-spine-tasks` skill |
23
23
  | Curated release subset | `spine-release-operator` skill |
24
+ | Agent shell batch policy (detached vs attached) | [spine-autonomous-operator/references/agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md) |
24
25
  | Pi async batch/verify (MonitorCreate) | [spine-release-operator/references/pi-async-orchestration.md](../spine-release-operator/references/pi-async-orchestration.md) |
25
26
  | Canonical how-to prose | [references/outer-loop.md](references/outer-loop.md) (synced from `docs/adoption/agent-orchestrated-waves.md`) |
26
27
  | Slash entry (`/spine-orchestrate`) | pi-spine extension — wave plan + outer loop checklist |
@@ -50,7 +51,8 @@ START
50
51
  │
51
52
  └─ FOR each wave W (from --from-wave or 0):
52
53
  │
53
- ├─ spine batch start <scope> --wave W --attached
54
+ ├─ spine batch start <scope> --wave W # detached — omit --attached
55
+ ├─ spine status --diagnose
54
56
  ├─ spine wait --until completed,needs_integrate,failed,aborted,needs_retry --timeout 4h
55
57
  ├─ spine status --diagnose
56
58
  │
@@ -92,7 +94,8 @@ From consumer repo root:
92
94
  spine preflight
93
95
  WAVE=0 # or next index from plan
94
96
 
95
- spine batch start pending --wave $WAVE --attached
97
+ spine batch start pending --wave $WAVE # detached — omit --attached
98
+ spine status --diagnose
96
99
  spine wait --until completed,needs_integrate,failed,aborted,needs_retry --timeout 4h
97
100
 
98
101
  spine status --diagnose
@@ -133,17 +136,17 @@ Inspect `.spine/runtime/<batchId>/evidence/`:
133
136
  | Diagnosis | Agent action |
134
137
  |-----------|--------------|
135
138
  | `needs_integrate` | Evidence checklist → `spine gate approve` → `spine integrate` → `spine batch complete` → push |
136
- | `needs_retry` | `spine batch retry <taskId>` then `spine batch resume --attached`; amend PROMPT contract if scope wrong |
139
+ | `needs_retry` | `spine batch retry <taskId>` then `spine batch resume` (detached); amend PROMPT contract if scope wrong |
137
140
  | `needs_retry` + `review_exhausted` | Inspect `.reviews/` feedback; fix implementation or packet scope, then retry |
138
141
  | `needs_retry` + `contract_failed` | Edit `PROMPT.md` `testCommand` or file scope, then retry |
139
142
  | `failed` | Inspect journal (`spine journal follow`); fix contract/env before retry |
140
143
  | `needs_replan` | Read `{taskFolder}/.reviews/final-*.md`; edit PROMPT scope, then retry |
141
144
  | `merge_blocked` | Resolve conflicts on orch branch or lane worktree; `spine batch resume --force` |
142
- | `engine_orphaned` | Do **not** start a second attached engine; `spine batch retry <taskId>` or `spine batch resume --attached --force` after confirming dead PIDs |
145
+ | `engine_orphaned` | Do **not** start a second attached engine; `spine batch retry <taskId>` or follow `suggestedCommand` (`resume --attached --force` only in **foreground** after confirming dead PIDs) |
143
146
  | `worker_orphaned` | `spine batch retry <taskId>` (reconciles orphan running → failed) |
144
147
  | `worker_done_missing` | Read worker output log from headline; fix blocker, then `spine batch retry <taskId>` |
145
148
  | `completed` | Run `spine batch complete` if not archived, then push |
146
- | `state_drift` | `spine batch retry <taskId>`; then `spine batch resume --attached --force` |
149
+ | `state_drift` | `spine batch retry <taskId>`; then follow `suggestedCommand` (`resume --attached --force` in **foreground** if diagnose requires) |
147
150
 
148
151
  ---
149
152
 
@@ -151,6 +154,7 @@ Inspect `.spine/runtime/<batchId>/evidence/`:
151
154
 
152
155
  | Anti-pattern | Correct approach |
153
156
  |--------------|------------------|
157
+ | `spine batch start … --attached` from Cursor Agent or non-TTY shell | Detached start + `spine wait` / `spine status --diagnose` — see [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md) |
154
158
  | `spine batch resume --attached` while `spine run sequence --attached` is active | One entry point; kill stale engines first (`spine status --diagnose`) |
155
159
  | Approving gate without reading evidence | Always inspect evidence directory before `spine gate approve` |
156
160
  | Expecting workers to call `spine_request_gate` for integrate | Agent drives gate approval from host shell |
@@ -195,7 +199,7 @@ When all waves finish, report:
195
199
 
196
200
  ```text
197
201
  Resume spine wave orchestration: spine plan pending --json → pick next wave W →
198
- spine batch start pending --wave W --attached → spine wait → spine status --diagnose →
202
+ spine batch start pending --wave W (detached) → spine status --diagnose → spine wait →
199
203
  branch on diagnosis (evidence checklist before gate approve) → integrate → batch complete → push →
200
204
  repeat until plan shows 0 waves. Post completion report.
201
205
  ```
@@ -16,6 +16,16 @@ Run all pending tasks across multiple dependency waves without manual interventi
16
16
 
17
17
  ---
18
18
 
19
+ ## Agent shell policy
20
+
21
+ For agent-driven batches (Cursor Agent, pi MonitorCreate, CI), use **detached** start/resume — omit `--attached`. The engine survives parent shell exit; monitor with `spine status --diagnose` and `spine wait`.
22
+
23
+ Cursor Agent shells may background long commands after **~120 seconds**; an attached engine dies with the parent shell (`engine_orphaned`, exit 137). Run `spine doctor` and heed the `batch --attached orphan risk (#163)` warning.
24
+
25
+ Full policy: [agent-shell-batch-policy.md](../../spine-autonomous-operator/references/agent-shell-batch-policy.md). Use `--attached` only from a persistent interactive terminal kept in foreground for the full batch.
26
+
27
+ ---
28
+
19
29
  ## Responsibility split
20
30
 
21
31
  | Layer | Owns |
@@ -35,7 +45,8 @@ Run this sequence once per wave from the consumer repo root:
35
45
  spine preflight
36
46
  WAVE=0 # agent picks the next wave index from plan output
37
47
 
38
- spine batch start pending --wave $WAVE --attached
48
+ spine batch start pending --wave $WAVE # detached — omit --attached
49
+ spine status --diagnose
39
50
  spine wait --until completed,needs_integrate,failed,aborted,needs_retry --timeout 4h
40
51
 
41
52
  spine status --diagnose
@@ -68,7 +79,7 @@ Increment `$WAVE` and repeat until `spine plan pending` shows no remaining waves
68
79
  spine run sequence pending --attached --dry-run
69
80
  ```
70
81
 
71
- The agent can execute each printed block manually with judgment between steps.
82
+ The agent can execute each printed block manually with judgment between steps. Use **detached** start for real execution (omit `--attached`).
72
83
 
73
84
  **Not recommended for real pi:** `spine run sequence pending --auto-approve-gate --force` bypasses evidence review and is restricted to stub/CI environments by safety gates.
74
85
 
@@ -81,16 +92,17 @@ After `spine wait` returns or `spine status --diagnose` reports a non-running st
81
92
  | Diagnosis | Agent action |
82
93
  |-----------|--------------|
83
94
  | `needs_integrate` | Review evidence under `.spine/runtime/<batchId>/evidence/` → `spine gate approve` → `spine integrate` → `spine batch complete` → push |
84
- | `needs_retry` | `spine batch retry <taskId>` then `spine batch resume --attached`; amend PROMPT contract if scope is wrong |
95
+ | `needs_retry` | `spine batch retry <taskId>` then `spine batch resume` (detached); amend PROMPT contract if scope is wrong |
85
96
  | `needs_retry` + `review_exhausted` | Inspect `.reviews/` feedback; fix implementation or packet scope, then retry |
86
97
  | `needs_retry` + `contract_failed` | Edit `PROMPT.md` `testCommand` or file scope, then retry |
87
98
  | `failed` | Inspect journal (`spine journal follow`); fix contract/env before retry |
88
99
  | `needs_replan` | Read reviewer feedback in `{taskFolder}/.reviews/final-*.md`; edit PROMPT scope, then retry |
89
100
  | `merge_blocked` | Resolve conflicts on orch branch or lane worktree; `spine batch resume --force` |
90
- | `engine_orphaned` | Do **not** start a second attached engine; `spine batch retry <taskId>` or `spine batch resume --attached --force` after confirming dead PIDs |
101
+ | `engine_orphaned` | Do **not** start a second attached engine; `spine batch retry <taskId>` or follow `suggestedCommand` (`resume --attached --force` only in **foreground** after confirming dead PIDs) |
91
102
  | `worker_orphaned` | `spine batch retry <taskId>` (reconciles orphan running → failed) |
92
103
  | `worker_done_missing` | Read worker output log from headline; fix blocker, then `spine batch retry <taskId>` |
93
104
  | `completed` | Already landed — run `spine batch complete` if not archived, then push |
105
+ | `state_drift` | `spine batch retry <taskId>`; then follow `suggestedCommand` (`resume --attached --force` in **foreground** if diagnose requires) |
94
106
 
95
107
  ---
96
108
 
@@ -98,6 +110,7 @@ After `spine wait` returns or `spine status --diagnose` reports a non-running st
98
110
 
99
111
  | Anti-pattern | Why it fails | Correct approach |
100
112
  |--------------|-------------|------------------|
113
+ | `spine batch start … --attached` from Cursor Agent or non-TTY shell | Parent shell backgrounds (~120s) or exits; engine orphaned | Detached start + `spine wait` / `spine status --diagnose` |
101
114
  | Running `spine batch resume --attached` while `spine run sequence --attached` is active | Two engines on the same batch causes state corruption | Use one entry point; kill stale engines first (`spine status --diagnose` to check PIDs) |
102
115
  | Approving gate without reading evidence | Merges untested or broken code to main | Always inspect `.spine/runtime/<batchId>/evidence/` before `spine gate approve` |
103
116
  | Expecting workers to call `spine_request_gate` for integrate | Workers always receive `not_supported` (FR-SHIP-13) | Agent drives gate approval from the host shell |
@@ -120,7 +133,8 @@ WAVES=$(spine plan pending --json | jq '.waveCount')
120
133
  for ((WAVE=0; WAVE<WAVES; WAVE++)); do
121
134
  echo "=== Wave $WAVE ==="
122
135
 
123
- spine batch start pending --wave "$WAVE" --attached
136
+ spine batch start pending --wave "$WAVE"
137
+ spine status --diagnose
124
138
  spine wait --until completed,needs_integrate,failed,aborted,needs_retry --timeout 4h
125
139
 
126
140
  DIAG=$(spine status --json | jq -r '.diagnosis')
@@ -150,6 +164,7 @@ Adapt for agent sessions: replace the bash loop with agent tool calls (`spine st
150
164
  | Doc | Relevance |
151
165
  |-----|-----------|
152
166
  | [operator-runbook.md §4](../../../docs/adoption/operator-runbook.md#4-land-loop) | Land loop copy-paste sequence |
167
+ | [agent-shell-batch-policy.md](../../spine-autonomous-operator/references/agent-shell-batch-policy.md) | Detached default for agent shells |
153
168
  | [bootstrap-checklist.md](../../../docs/adoption/bootstrap-checklist.md) | First batch setup |
154
169
  | [upstream-execution-workflow.md](../../../docs/adoption/upstream-execution-workflow.md) | PRD → task packets → batch |
155
170
  | [QUICK-REFERENCE.md](../../../docs/QUICK-REFERENCE.md) | Command reference |
@@ -163,3 +178,5 @@ Adapt for agent sessions: replace the bash loop with agent tool calls (`spine st
163
178
  - [#84](https://github.com/beettlle/pi-spine/issues/84) — PROMPT authoring for cross-model
164
179
  - [#71](https://github.com/beettlle/pi-spine/issues/71) — built-in supervisor (future; agent outer loop bridges gap)
165
180
  - [#54](https://github.com/beettlle/pi-spine/issues/54) — `spine run sequence` (complementary, not replacement)
181
+ - [#163](https://github.com/beettlle/pi-spine/issues/163) — attached orphan risk in short-lived shells
182
+ - [#185](https://github.com/beettlle/pi-spine/issues/185) — detached default for release/agent batches
@@ -18,6 +18,7 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
18
18
  |---------|-------------|
19
19
  | PROMPT/STATUS/Contract authoring | `create-spine-tasks` skill + templates |
20
20
  | Batch land loop / recovery | [`spine-autonomous-operator`](../spine-autonomous-operator/SKILL.md) Phase 3–4 + [pi-async-orchestration.md](references/pi-async-orchestration.md) |
21
+ | Agent shell batch policy (detached vs attached) | [spine-autonomous-operator/references/agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md) |
21
22
  | Wave evidence / diagnosis tree | [`spine-orchestrate-waves`](../spine-orchestrate-waves/SKILL.md) |
22
23
  | Semver scope budgets | [references/release-profiles.md](references/release-profiles.md) |
23
24
  | Issue intake queries | [references/issue-intake-checklist.md](references/issue-intake-checklist.md) |
@@ -30,9 +31,10 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
30
31
  1. GitNexus index refreshed (`gitnexus status` up-to-date with HEAD)
31
32
  2. Release manifest written and operator-approved
32
33
  3. All **release-scoped** tasks `.DONE` and integrated on `main`
33
- 4. `spine preflight` green; local test/coverage gates pass
34
- 5. Operator explicitly approved publish; version bumped and tag pushed (if approved)
35
- 6. Final report with composition table, issues closed/deferred, verification output
34
+ 4. `spine preflight` green; **`npm run release:check` green (blocking gate)** on current `main`
35
+ 5. **CI workflow green on release commit** (release-safe profile — parity with `ci.yml`) before tag push
36
+ 6. Operator explicitly approved publish; version bumped and tag pushed (if approved)
37
+ 7. Final report with composition table, issues closed/deferred, verification output
36
38
 
37
39
  ## Hard rules
38
40
 
@@ -40,6 +42,8 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
40
42
  - **Never** implement product code in task folders while a batch owns that scope
41
43
  - **Never** claim batch/test/publish success without CLI output
42
44
  - **Never** run `npm version` or `git push --tags` without explicit operator approval
45
+ - **Never** run `npm version` or `git push --tags` when `npm run release:check` exits non-zero on current `main` ([#175](https://github.com/beettlle/pi-spine/issues/175))
46
+ - **Never** run `npm version` or `git push --tags` when the **CI** workflow is not green on current `HEAD` — release-safe profile: typecheck + lint + tests + coverage (parity with `ci.yml`) ([#156](https://github.com/beettlle/pi-spine/issues/156))
43
47
  - **Always** parse target version / bump type **before** task selection (Phase 2)
44
48
  - **Always** prioritize documentation issues over enhancements
45
49
  - **Always** run `spine gate approve` before `spine integrate`
@@ -47,6 +51,7 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
47
51
  - **Do not** execute tasks outside the approved manifest scope
48
52
  - **Do not** start a second batch while another batch is **running** on this repo
49
53
  - **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
54
+ - **Release and agent batches:** use **detached** `spine batch start|resume` (omit `--attached`); monitor with MonitorCreate, `spine wait`, or `spine status --diagnose` ([#163](https://github.com/beettlle/pi-spine/issues/163), [#185](https://github.com/beettlle/pi-spine/issues/185)) — see [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md)
50
55
  - **Always** run `/gitnexus analyze` (Pre-work) before Phase 0 — do not start intake, authoring, or batches on a stale index
51
56
 
52
57
  ---
@@ -236,6 +241,8 @@ git commit -m "chore(spine): release v{TARGET} task packets"
236
241
 
237
242
  ## Phase 4 — Execute release scope
238
243
 
244
+ **Detached-first:** See [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md). Omit `--attached` for release waves unless the operator shell is a persistent interactive terminal that blocks until batch completion.
245
+
239
246
  **Scope:** manifest tasks only — build a comma-separated release scope ID list.
240
247
 
241
248
  ```bash
@@ -253,13 +260,21 @@ See [references/pi-async-orchestration.md](references/pi-async-orchestration.md)
253
260
 
254
261
  ```text
255
262
  MonitorCreate:
256
- command: spine batch start <release-scope> --wave N --attached
263
+ command: spine batch start <release-scope> --wave N # detached — omit --attached (#163)
257
264
  description: Release wave N
258
265
  timeout: 0
259
266
  onDone: spine status --diagnose → §4.3 land loop or §4.4 recovery
260
267
  ```
261
268
 
262
- **Foreground fallback** (non-pi, or after #163 orphan on MonitorCreate):
269
+ **Blocking fallback** (Cursor Agent, non-pi, or after MonitorCreate orphan — see [agent-shell-batch-policy.md](../spine-autonomous-operator/references/agent-shell-batch-policy.md)):
270
+
271
+ ```bash
272
+ spine batch start <release-scope> --wave N
273
+ spine status --diagnose
274
+ spine wait --until completed,failed,needs_integrate,needs_retry,aborted --timeout 4h
275
+ ```
276
+
277
+ **Foreground `--attached`** (persistent interactive human terminal only):
263
278
 
264
279
  ```bash
265
280
  spine batch start <release-scope> --wave N --attached
@@ -328,28 +343,71 @@ git status
328
343
  npm run release:check # typecheck → lint → tests → coverage (CI parity)
329
344
  ```
330
345
 
346
+ ### `release:check` gate (HARD STOP — blocking)
347
+
348
+ `npm run release:check` is **not advisory**. It is a **blocking gate** before any publish checklist or Phase 6.
349
+
350
+ **If `npm run release:check` exits non-zero:**
351
+
352
+ 1. **STOP immediately.** Do not present the pre-publish checklist as passable.
353
+ 2. Do not ask for publish approval. Do not run `npm version` or `git push --tags`.
354
+ 3. Record the failure output in the release manifest publish checklist (paste log tail or path to `/tmp/pi-spine-release-check.log`).
355
+ 4. **Recovery:** fix failures on `main` (commit fixes), re-run `npm run release:check` until green, then **re-attempt Phase 5** from the top.
356
+
357
+ Only after `npm run release:check` exits **0** may you present the checklist below.
358
+
331
359
  Present checklist from `docs/release/npm-publish.md`:
332
360
 
333
361
  - [ ] All release-scoped tasks done
334
362
  - [ ] Preflight green
335
- - [ ] `npm run release:check` green (includes lint; ≥77% coverage)
363
+ - [ ] `npm run release:check` green (includes lint; ≥77% coverage) — **verified exit 0**
364
+ - [ ] CI workflow green on `HEAD` (release-safe profile — parity with `ci.yml`) — **verified via `gh run list`**
336
365
  - [ ] Clean git tree
337
366
  - [ ] Bump type matches profile: patch | minor | major
367
+ - [ ] `release:check` output recorded in manifest publish checklist
338
368
 
339
- **Human gate (required):** **STOP HERE.** Do not bump or push until operator explicitly approves publish and confirms bump type.
369
+ **Human gate (required):** **STOP HERE.** Do not bump or push until operator explicitly approves publish, confirms bump type, **and** Phase 5 `release:check` passed on current `main`.
340
370
 
341
371
  ---
342
372
 
343
373
  ## Phase 6 — Publish (after approval only)
344
374
 
345
- Only after operator says "approve publish" / "bump and push":
375
+ **Prerequisites (all required — no bypass):**
376
+
377
+ - Phase 5 `npm run release:check` exited **0** on current `main` (re-run if `main` moved since Phase 5)
378
+ - **CI workflow green on current `HEAD`** (pre-tag gate — see below)
379
+ - Operator explicitly said "approve publish" / "bump and push"
380
+ - Operator confirmed bump type matches Phase 2 profile
381
+
382
+ **Do not skip the release:check gate.** Operator approval alone does not authorize `npm version` or tag push when `release:check` would fail. If unsure, re-run `npm run release:check` before bumping.
383
+
384
+ ### Pre-tag CI gate (HARD STOP — blocking)
385
+
386
+ Before `npm version` or `git push --tags`, verify the **CI** workflow succeeded on current `HEAD` (the commit you are about to tag). **Release-safe CI profile** matches `ci.yml`: typecheck → lint → tests with coverage (≥77% line minimum) → CLI smoke checks. Local parity: `npm run release:check` (Phase 5).
387
+
388
+ **If CI is not green on `HEAD`, STOP.** Push to `main` and wait for CI before tagging — do not retag after a failed release.
389
+
390
+ ```bash
391
+ COMMIT=$(git rev-parse HEAD)
392
+ gh run list --workflow ci.yml --commit "$COMMIT" --json databaseId,conclusion,status --limit 5
393
+ ```
394
+
395
+ **Fail closed** when no run has `conclusion: success`. If the latest run is `in_progress` or `queued`, wait:
396
+
397
+ ```bash
398
+ gh run watch --exit-status <run-id>
399
+ ```
400
+
401
+ If CI **failed** or **no CI run** exists for `HEAD`, **STOP** — fix CI on `main`, re-run Phase 5, then re-attempt this gate. Do not `npm version` or `git push --tags`.
402
+
403
+ Only after Phase 5 **and** pre-tag CI gate pass:
346
404
 
347
405
  ```bash
348
406
  npm version patch # or minor / major — must match Phase 2 profile
349
407
  git push && git push --tags
350
408
  ```
351
409
 
352
- Monitor CI:
410
+ Monitor Release workflow (tag publish):
353
411
 
354
412
  ```bash
355
413
  gh run list --workflow release.yml --limit 3
@@ -379,7 +437,7 @@ Close GitHub issues where tasks had `Closes: #NNN` and work shipped.
379
437
  4. **Authoring changes** — new SP-* created, splits/fixes in Phase 3
380
438
  5. **Issues filed** — pi-spine GitHub links or "none"
381
439
  6. **Recovery actions** — aborts, retries, contract fixes
382
- 7. **Verification** — paste `spine preflight` tail, test/coverage output
440
+ 7. **Verification** — paste `spine preflight` tail, **`npm run release:check` output** (or log path), test/coverage output
383
441
  8. **Publish** — version bumped (Y/N), tag pushed (Y/N), workflow URL, or "awaiting operator approval"
384
442
 
385
443
  ---
@@ -391,6 +449,7 @@ Close GitHub issues where tasks had `Closes: #NNN` and work shipped.
391
449
  | Tasks root | `spine-tasks/` |
392
450
  | Issues repo | `beettlle/pi-spine` |
393
451
  | Pre-publish gate | `npm run release:check` (typecheck → lint → tests → coverage; CI parity) |
452
+ | Pre-tag CI gate | `ci.yml` green on `HEAD` via `gh run list` / `gh run watch` before `npm version` ([#156](https://github.com/beettlle/pi-spine/issues/156)) |
394
453
  | Publish | Tag-triggered `.github/workflows/release.yml` |
395
454
  | Pending backlog | Run `spine plan pending` — release executes **subset only** |
396
455
 
@@ -402,6 +461,6 @@ check manifest at spine-tasks/_authoring/release-v{TARGET}/manifest.md →
402
461
  spine status --diagnose (do not collide with running batch) →
403
462
  preflight → for each wave: MonitorCreate batch start (or foreground) → onDone diagnose →
404
463
  gate approve → integrate → npm install → batch complete →
405
- MonitorCreate release:check → STOP for publish approval.
464
+ MonitorCreate release:check → HARD STOP if non-zero (fix on main, re-run) → only if exit 0: verify ci.yml green on HEAD (gh run list/watch) → HARD STOP if not green → only then: STOP for publish approval.
406
465
  resume --attached --force stays foreground. Post final report with composition table.
407
466
  ```