pi-spine 2.3.1 → 2.3.2

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.
@@ -38,7 +38,8 @@ const BATCH_FLAG_VALUE_TAKERS = new Set([
38
38
  */
39
39
  export function printBatchHelp() {
40
40
  return (
41
- "Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|salvage|abort|dismiss|complete [--batch ID] [--lane N] [--integrate] [--yes] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--wave N] [--through-wave N] [--skip-preflight] [--detect-manual-merge] [--json]\n"
41
+ "Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|salvage|abort|dismiss|complete [--batch ID] [--lane N] [--integrate] [--yes] [--reason TEXT] [--hard] [--force] [--force-superseded] [--attached] [--dry-run] [--wave N] [--through-wave N] [--skip-preflight] [--detect-manual-merge] [--json]\n" +
42
+ " abort --dry-run Preview abort (reason/archive target); does not archive, journal, or clear live batch\n"
42
43
  );
43
44
  }
44
45
 
@@ -113,8 +114,14 @@ export function formatLifecycleHuman(result, json = false) {
113
114
  if (result.diagnosis) {
114
115
  lines.push(` Diagnosis: ${result.diagnosis}`);
115
116
  }
117
+ if (result.dryRun) {
118
+ lines.push(` Dry-run: true (no mutation)`);
119
+ }
116
120
  if (result.archivePath) {
117
- lines.push(` Archive: ${result.archivePath}`);
121
+ lines.push(result.dryRun ? ` Would archive: ${result.archivePath}` : ` Archive: ${result.archivePath}`);
122
+ }
123
+ if (result.reason) {
124
+ lines.push(` Reason: ${result.reason}`);
118
125
  }
119
126
 
120
127
  lines.push("", ` → ${result.suggestedCommand}`);
@@ -300,6 +307,7 @@ export async function runSpineBatch(options) {
300
307
  batchId: parsed.batchId,
301
308
  reason: parsed.reason,
302
309
  hard: parsed.hard,
310
+ dryRun: parsed.dryRun,
303
311
  });
304
312
  return {
305
313
  exitCode: result.exitCode ?? (result.ok ? 0 : 1),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -191,6 +191,7 @@ Run **after Step A.5 — Clarify** and **before Step B — Slice**. Authoring-on
191
191
  | **Step numbering** | Number steps sequentially starting at 0 with **no duplicates** (`### Step N:`). `spine tasks validate` rejects duplicate step numbers (see issue #148 / SP-435). |
192
192
  | **Two-deliverable test** | If your Steps can be grouped into two clusters with no data dependency between them, split into separate tasks even if the step count is ≤4. The #1 sizing mistake is bundling two independent deliverables in one M task. |
193
193
  | **Parallel waves** | Prefer **≤4** M-sized tasks per wave; 8-task mega-waves stall pi workers (see Phase 15 / SP-086–088). |
194
+ | **False deps** | Edge only for **real data deps** (B needs A's output on disk). Preference-order or "nice to finish first" is **not** a dep — it forces size-1 waves and empty parallel lanes. Independent deliverables → same wave + disjoint File Scope. |
194
195
  | **Scope** | One deliverable per task; disjoint **File Scope** when tasks can run in parallel. |
195
196
  | **IDs** | Use `Next Task ID` from CONTEXT.md; increment after each new task. Greenfield spine projects typically use `SP-###`; Taskplane migrants may keep `TP-###`. |
196
197
  | **Waves** | Order via `## Dependencies` and `{tasksRoot}/dependencies.json`. |
@@ -246,7 +247,7 @@ After creating packets:
246
247
  2. **`{tasksRoot}/dependencies.json`** — add edges for every dependency (machine-parseable)
247
248
  3. Report launch commands: `spine tasks validate pending` (fix contract/PROMPT errors first), `spine tasks analyze pending` (structural checks — wave sizing, deps drift, explore refs), `spine plan pending`, then `spine batch start <id>`
248
249
 
249
- **Example decomposition** (feature brief → three tasks):
250
+ **Example — serial when data deps are real** (handlers import schema; tests call handlers):
250
251
 
251
252
  | Task | Mission | Deps |
252
253
  |------|---------|------|
@@ -254,6 +255,17 @@ After creating packets:
254
255
  | `SP-011-api-handlers` | Implement routes using schema | SP-010 |
255
256
  | `SP-012-api-tests` | Integration tests + docs | SP-011 |
256
257
 
258
+ `spine plan` correctly shows one lane per wave here — serial is required.
259
+
260
+ **Counter-example — parallel when deliverables are independent** (no shared output; disjoint File Scope):
261
+
262
+ | Task | Mission | Deps | File Scope |
263
+ |------|---------|------|------------|
264
+ | `SP-020-skill-dor` | Tighten skill DoR checklist | None | `skills/create-spine-tasks/SKILL.md` |
265
+ | `SP-021-runbook-note` | Add operator recovery note | None | `docs/adoption/operator-runbook.md` |
266
+
267
+ Same wave, no edges → `spine plan` should report **`2 lanes in parallel`**. If it collapses to `1 lane`, check overlapping scopes or accidental deps — do not "fix" with preference-order edges.
268
+
257
269
  ---
258
270
 
259
271
  ## Single-Task Creation Workflow
@@ -461,6 +473,8 @@ Task IDs in JSON use the **folder slug** (full `SP-011-api-handlers`) or bare ID
461
473
 
462
474
  When decomposing a PRD, assign non-overlapping file scopes to tasks that should run in parallel.
463
475
 
476
+ **Shared docs / hot files collapse lanes:** Shared `CONTEXT.md`, `README.md`, area docs, or hot modules (e.g. `bin/spine.mjs`, `src/batch/engine.mjs`) in multiple same-wave File Scopes pack those tasks onto one virtual lane. Keep shared-doc edits **serial** (dependency edge or separate wave) or **out of** parallel mates' scopes — do not list the same shared path on two intended-parallel tasks.
477
+
464
478
  **`fileScopeMustNotChange` (parallel lanes only):** When a packet includes `fileScopeMustNotChange` in `## Contract`, use it only to guard **product paths that concurrent tasks on different lanes** must not edit in the same wave — not to isolate paths touched by **prior serialized tasks** on the same lane. When `spine plan` reports `File scope overlaps (tasks serialized to the same lane)`, those tasks run sequentially on one lane; use disjoint `fileScopeMustChange` paths instead of relying on must-not-change. Full semantics and examples: [references/contract-template.md](references/contract-template.md#filescopemustnotchange-semantics).
465
479
 
466
480
  **Never ban `spine-tasks/**`:** Do **not** list `spine-tasks/**` or the **current task folder** in `fileScopeMustNotChange`. Workers must update `STATUS.md`, create `.DONE`, and may write `.reviews/` — banning those paths causes `contract.verified` failures even when implementation is correct.
@@ -544,6 +558,8 @@ Before reporting launch commands:
544
558
  - [ ] 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)
545
559
  - [ ] Shared-module behavior change: `rg` old strings in `tests/`; all hit files in `testCommand` or documented for post-integrate `release:check` ([post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md))
546
560
  - [ ] Plan waves ≤8 tasks when possible — `spine plan` warns when exceeded ([#143](https://github.com/beettlle/pi-spine/issues/143), SP-524)
561
+ - [ ] When parallelism is intended: `spine plan` shows `N lanes in parallel` for that wave — or document why overlapping scopes / real deps forced serial collapse ([#193](https://github.com/beettlle/pi-spine/issues/193))
562
+ - [ ] No false deps: edges only for real data dependencies; preference-order edges that force size-1 waves are rejected ([#193](https://github.com/beettlle/pi-spine/issues/193))
547
563
  - [ ] `### Step N: Testing & Verification` present inside `## Steps` before `## Completion Criteria` (required even for docs-only Review Level 0)
548
564
  - [ ] STATUS.md with matching steps (hydration markers where needed)
549
565
  - [ ] `dependencies.json` updated when task has deps
@@ -575,6 +591,7 @@ Hydration commits (STATUS.md expansions) may happen mid-step for crash recovery.
575
591
  - **Testing step required (never omit)** — every task packet needs `### Step N: Testing & Verification` inside `## Steps`, before `## Completion Criteria`. **Do not skip this for docs-only or Review Level 0 tasks** — the worker rejects packets without a Testing step. Use `testing.test` from spine config; for **code deliverables**, also include `testing.testWithCoverage` and a **≥77% line coverage** checkbox (see prompt template). Docs-only tasks may omit the coverage checkbox.
576
592
  - **Documentation in every task** — "Must Update" / "Check If Affected" prevent doc drift.
577
593
  - **Concrete deliverables** — name files to create/modify; avoid shortcuttable vague steps.
594
+ - **False deps defeat parallelism** — edge only when B needs A's output; independent work gets disjoint File Scope and no edge. Verify intended parallel waves with `spine plan` (`N lanes in parallel`) before handoff ([#193](https://github.com/beettlle/pi-spine/issues/193)).
578
595
  - **Local install** — skill ships with pi-spine; `pi install /path/to/pi-spine -l` loads `./skills`.
579
596
 
580
597
  ---
@@ -84,7 +84,9 @@ For each pending `spine-tasks/{SP-###-slug}/PROMPT.md`:
84
84
 
85
85
  - [ ] `dependencies.json` matches PROMPT `## Dependencies`
86
86
  - [ ] Same-wave tasks have **disjoint** `fileScopeMustChange`
87
- - [ ] Hot shared files are serial (e.g. `src/batch/heartbeat.mjs`, `bin/spine.mjs`)
87
+ - [ ] Hot shared files / shared docs are serial (e.g. `src/batch/heartbeat.mjs`, `bin/spine.mjs`, `CONTEXT.md`) — overlapping shared paths collapse lanes
88
+ - [ ] No false (preference-order) deps that force size-1 waves when deliverables are independent
89
+ - [ ] When parallelism is intended: `spine plan` shows `N lanes in parallel` for that wave — or explain why scopes/deps forced serial collapse
88
90
  - [ ] No directory paths with trailing `/` in contracts — use explicit files
89
91
  - [ ] No parenthetical comments in contract paths (e.g. `file.ts (Step 2 only)`)
90
92
  - [ ] Pre-landed code on `main` → point `fileScopeMustChange` at `spine-tasks/{task}/STATUS.md` + `## Amendments`
@@ -131,12 +131,13 @@ function buildAbortedSnapshot(raw, reason) {
131
131
  * @param {object} ctx
132
132
  * @param {string} ctx.projectRoot
133
133
  * @param {boolean} [ctx.hard]
134
+ * @param {boolean} [ctx.dryRun]
134
135
  * @param {string|null} [ctx.reason]
135
136
  * @param {string|null} [ctx.batchId]
136
137
  * @param {string|null} [ctx.batchStatePath]
137
138
  */
138
139
  export function abortBatch(ctx) {
139
- const { projectRoot, hard = false, reason = null } = ctx;
140
+ const { projectRoot, hard = false, reason = null, dryRun = false } = ctx;
140
141
  const loaded = loadBatchStateFile(projectRoot, ctx.batchStatePath ?? null);
141
142
 
142
143
  if (!loaded.path || !loaded.raw) {
@@ -147,6 +148,7 @@ export function abortBatch(ctx) {
147
148
  suggestedCommand: "spine preflight",
148
149
  alternatives: ["spine status --diagnose"],
149
150
  batchId: null,
151
+ dryRun,
150
152
  };
151
153
  }
152
154
 
@@ -158,6 +160,7 @@ export function abortBatch(ctx) {
158
160
  headline: `Cannot parse batch state: ${loaded.parseError}`,
159
161
  suggestedCommand: "spine status --diagnose",
160
162
  batchId: null,
163
+ dryRun,
161
164
  };
162
165
  }
163
166
 
@@ -170,6 +173,7 @@ export function abortBatch(ctx) {
170
173
  headline: "Active batch state has no batchId",
171
174
  suggestedCommand: "spine status --diagnose",
172
175
  batchId: null,
176
+ dryRun,
173
177
  };
174
178
  }
175
179
 
@@ -181,6 +185,29 @@ export function abortBatch(ctx) {
181
185
  headline: `Batch ID mismatch — active batch is ${batchId}`,
182
186
  suggestedCommand: "spine status --diagnose",
183
187
  batchId,
188
+ dryRun,
189
+ };
190
+ }
191
+
192
+ const previewArchivePath = archiveBatchStatePath(projectRoot, batchId);
193
+
194
+ // Dry-run previews abort without writing archive, journal, signal, or clearing live state.
195
+ if (dryRun) {
196
+ const abortCmd = hard ? "spine batch abort --hard" : "spine batch abort";
197
+ return {
198
+ ok: true,
199
+ exitCode: 0,
200
+ dryRun: true,
201
+ batchId,
202
+ hard,
203
+ reason: reason ?? null,
204
+ diagnosis: "abort_preview",
205
+ archivePath: previewArchivePath,
206
+ headline: hard
207
+ ? `Would hard-abort and archive batch ${batchId}`
208
+ : `Would abort and archive batch ${batchId}`,
209
+ suggestedCommand: abortCmd,
210
+ alternatives: ["spine status --diagnose"],
184
211
  };
185
212
  }
186
213
 
@@ -265,6 +265,8 @@ export async function resumeBatchDetached({
265
265
  }
266
266
 
267
267
  prepareDetachedResumeEngineHandoff(projectRoot);
268
+ // SP-613: validateMultiTaskResume already admits pidless terminal-success + pending
269
+ // wave merge (#196); spawn the attached engine argv in detached mode (no --attached).
268
270
  const argv = buildAttachedBatchResumeArgv({ force });
269
271
  const { enginePid, logPath } = spawnDetachedBatchEngine({ projectRoot, spineBin, argv });
270
272
  releaseResumeLock?.();
@@ -161,9 +161,18 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
161
161
  case "completed_manual":
162
162
  return "spine batch dismiss";
163
163
  case "state_drift":
164
+ // Agent-safe detached recovery (#196 / SP-613) — never suggest --attached.
165
+ if (
166
+ ctx.phase === "running" ||
167
+ ctx.staleEnginePid === true ||
168
+ ctx.engineDead === true ||
169
+ ctx.allTasksTerminalSuccess === true
170
+ ) {
171
+ return "spine batch resume --force";
172
+ }
164
173
  if (ctx.failedTaskId) {
165
174
  const driftStatus = String(ctx.driftTaskStatus ?? "").toLowerCase();
166
- if (driftStatus === "running" || ctx.phase === "running") {
175
+ if (driftStatus === "running") {
167
176
  return "spine batch resume --force";
168
177
  }
169
178
  return `spine batch retry ${ctx.failedTaskId}`;
@@ -224,12 +233,16 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
224
233
  case "engine_orphaned": {
225
234
  const parentExitCommand = buildEngineOrphanParentExitSuggestedCommand(ctx);
226
235
  if (parentExitCommand) return parentExitCommand;
236
+ // Terminal-success / doneInLane heal with dead engine — detached resume (#196 / #163).
237
+ if (ctx.allTasksTerminalSuccess === true) {
238
+ return "spine batch resume --force";
239
+ }
227
240
  return ctx.failedTaskId
228
241
  ? `spine batch retry ${ctx.failedTaskId}`
229
242
  : "spine batch resume --attached";
230
243
  }
231
244
  case "needs_merge":
232
- return "/spine-resume --force";
245
+ return "spine batch resume --force";
233
246
  case "needs_integrate":
234
247
  if (ctx.postMergeLimbo && ctx.phase === "running") {
235
248
  if (ctx.integrateGateOpen) {
@@ -59,9 +59,26 @@ export function detectPostMergeLimboForResume({ projectRoot, state }) {
59
59
 
60
60
  export { hasPendingWaveMerge } from "./merge/wave-merge-state.mjs";
61
61
 
62
+ /**
63
+ * Whether every task is terminal-success (or skipped) for #196 drift recovery.
64
+ *
65
+ * @param {object|null|undefined} state
66
+ */
67
+ function allTasksTerminalSuccessForResume(state) {
68
+ const tasks = state?.tasks ?? [];
69
+ if (tasks.length < 1) return false;
70
+ return tasks.every((task) => {
71
+ const status = String(task?.status ?? "").toLowerCase();
72
+ return status === "succeeded" || status === "skipped";
73
+ });
74
+ }
75
+
62
76
  /**
63
77
  * Assess whether a running-phase batch may resume after a dead detached engine (SP-296).
64
78
  *
79
+ * Also covers SP-613 / #196: pidless engine + all tasks terminal-success + pending wave
80
+ * merge (doneInLane healed, enginePid cleared) must not dead-end on phase=running.
81
+ *
65
82
  * @param {object} params
66
83
  * @param {string} params.projectRoot
67
84
  * @param {object} params.state
@@ -83,17 +100,25 @@ export function assessRunningPhaseResumeEligibility({ projectRoot, state }) {
83
100
  const enginePid = readBatchEnginePid(state);
84
101
  const enginePidDead = enginePid != null && !isProcessAlive(enginePid);
85
102
  const pidlessEngineOrphan = enginePid == null && orphanRunning?.kind === "engine";
86
- const engineConfirmedDead = enginePidDead || pidlessEngineOrphan;
103
+ // Dead/missing engine with work finished but merge not landed — agent-safe detached resume (#196).
104
+ const pidlessTerminalSuccessPendingMerge =
105
+ enginePid == null &&
106
+ allTasksTerminalSuccessForResume(state) &&
107
+ hasPendingWaveMerge(state);
108
+ const engineConfirmedDead =
109
+ enginePidDead || pidlessEngineOrphan || pidlessTerminalSuccessPendingMerge;
87
110
 
88
111
  const allowOrphanResume =
89
112
  engineConfirmedDead &&
90
- orphanRunning != null &&
91
- (orphanRunning.kind === "engine" || orphanRunning.kind === "lane");
113
+ ((orphanRunning != null &&
114
+ (orphanRunning.kind === "engine" || orphanRunning.kind === "lane")) ||
115
+ pidlessTerminalSuccessPendingMerge);
92
116
 
93
117
  return {
94
118
  engineConfirmedDead,
95
119
  allowOrphanResume,
96
- orphanKind: orphanRunning?.kind ?? null,
120
+ orphanKind: orphanRunning?.kind ?? (pidlessTerminalSuccessPendingMerge ? "engine" : null),
121
+ terminalSuccessPendingMerge: pidlessTerminalSuccessPendingMerge,
97
122
  };
98
123
  }
99
124
 
@@ -115,19 +115,52 @@ function laneNumbersFromTasks(tasks) {
115
115
  return lanes;
116
116
  }
117
117
 
118
+ /**
119
+ * Journal rebuild may drop seed done* flags; merge them for salvage discovery (#196).
120
+ *
121
+ * @param {object} rebuiltTask
122
+ * @param {object[]|undefined} seedTasks
123
+ */
124
+ function enrichTaskWithSeedEvidence(rebuiltTask, seedTasks) {
125
+ const taskId = String(rebuiltTask?.taskId ?? "");
126
+ if (!taskId || !Array.isArray(seedTasks)) return rebuiltTask;
127
+ const seed = seedTasks.find((task) => String(task?.taskId ?? "") === taskId);
128
+ if (!seed) return rebuiltTask;
129
+ return {
130
+ ...rebuiltTask,
131
+ doneInLane: rebuiltTask?.doneInLane === true || seed.doneInLane === true,
132
+ doneFileFound: rebuiltTask?.doneFileFound === true || seed.doneFileFound === true,
133
+ doneOnMain: rebuiltTask?.doneOnMain === true || seed.doneOnMain === true,
134
+ classification:
135
+ rebuiltTask?.classification ??
136
+ seed.classification ??
137
+ undefined,
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Terminal-success / lane `.DONE` evidence — journal `lane.committed` is optional (#196 / FR-REL232-02).
143
+ * Git commits-ahead on the lane task branch remains the hard gate in `listSalvageableLanes`.
144
+ *
145
+ * @param {object} task
146
+ */
147
+ function isTerminalSuccessTask(task) {
148
+ const status = String(task?.status ?? "").toLowerCase();
149
+ if (status === "succeeded" || status === "skipped") return true;
150
+ if (task?.doneInLane === true || task?.doneFileFound === true || task?.doneOnMain === true) {
151
+ return true;
152
+ }
153
+ return String(task?.classification ?? "").toLowerCase() === "terminal-success";
154
+ }
155
+
118
156
  /**
119
157
  * @param {object} task
120
- * @param {Set<string>} committedTaskIds
121
158
  */
122
- function isSalvageableTask(task, committedTaskIds) {
159
+ function isSalvageableTask(task) {
123
160
  const taskId = String(task?.taskId ?? "");
124
161
  if (!taskId) return false;
125
- if (!committedTaskIds.has(taskId)) return false;
126
-
127
- const status = String(task?.status ?? "").toLowerCase();
128
- if (status !== "succeeded" && status !== "skipped") return false;
129
162
  if (isNonSalvageableExitReason(task?.exitReason)) return false;
130
- return true;
163
+ return isTerminalSuccessTask(task);
131
164
  }
132
165
 
133
166
  /**
@@ -165,11 +198,13 @@ export function listSalvageableLanes(projectRoot, batchId) {
165
198
  const rebuilt = rebuildBatchStateFromJournal(seedState, journalEvents);
166
199
  const baseBranch = String(rebuilt.baseBranch ?? seedState?.baseBranch ?? "main");
167
200
  const committedTaskIds = laneCommittedTaskIds(journalEvents);
201
+ const seedTasks = seedState?.tasks;
168
202
 
169
203
  /** @type {Map<number, { laneNumber: number, salvageableTasks: string[], excludedTasks: string[] }>} */
170
204
  const laneMap = new Map();
171
205
 
172
- for (const task of rebuilt.tasks ?? []) {
206
+ for (const rawTask of rebuilt.tasks ?? []) {
207
+ const task = enrichTaskWithSeedEvidence(rawTask, seedTasks);
173
208
  const laneNumber = Number(task?.laneNumber);
174
209
  if (!Number.isFinite(laneNumber) || laneNumber <= 0) continue;
175
210
 
@@ -182,17 +217,15 @@ export function listSalvageableLanes(projectRoot, batchId) {
182
217
  const status = String(task.status ?? "").toLowerCase();
183
218
  const hasLaneCommit = committedTaskIds.has(taskId);
184
219
 
185
- if (hasLaneCommit && isNonSalvageableExitReason(task.exitReason)) {
220
+ // Exclude non-salvageable exit reasons even when journal lacks lane.committed (#196).
221
+ if (isNonSalvageableExitReason(task.exitReason)) {
186
222
  laneEntry.excludedTasks.push(taskId);
187
223
  continue;
188
224
  }
189
225
 
190
- if (isSalvageableTask(task, committedTaskIds)) {
226
+ if (isSalvageableTask(task)) {
191
227
  laneEntry.salvageableTasks.push(taskId);
192
- } else if (
193
- hasLaneCommit &&
194
- (status === "failed" || isNonSalvageableExitReason(task.exitReason))
195
- ) {
228
+ } else if (hasLaneCommit && status === "failed") {
196
229
  laneEntry.excludedTasks.push(taskId);
197
230
  }
198
231
  }