pi-spine 2.0.0 → 2.2.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 (36) hide show
  1. package/bin/spine-batch.mjs +74 -5
  2. package/bin/spine-cleanup.mjs +89 -0
  3. package/bin/spine-cli/verify.mjs +1 -0
  4. package/bin/spine-doctor.mjs +8 -0
  5. package/bin/spine.mjs +13 -0
  6. package/package.json +4 -1
  7. package/skills/create-spine-tasks/SKILL.md +28 -0
  8. package/skills/create-spine-tasks/references/contract-template.md +11 -0
  9. package/skills/create-spine-tasks/references/prompt-template.md +7 -1
  10. package/skills/spine-autonomous-operator/SKILL.md +19 -3
  11. package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +18 -0
  12. package/skills/spine-orchestrate-waves/SKILL.md +9 -2
  13. package/skills/spine-orchestrate-waves/references/outer-loop.md +24 -2
  14. package/skills/spine-release-operator/SKILL.md +25 -2
  15. package/skills/spine-release-operator/references/post-integrate-regression-gate.md +96 -0
  16. package/skills/spine-release-operator/references/release-manifest-template.md +7 -3
  17. package/src/batch/abort.mjs +10 -14
  18. package/src/batch/attached-runner.mjs +12 -1
  19. package/src/batch/diagnosis-merge-failure.mjs +66 -0
  20. package/src/batch/diagnosis-parent-exit.mjs +125 -0
  21. package/src/batch/diagnosis.mjs +26 -73
  22. package/src/batch/engine-lanes/merge.mjs +25 -0
  23. package/src/batch/journal-rebuild.mjs +80 -1
  24. package/src/batch/lane-dirty-check.mjs +10 -0
  25. package/src/batch/lifecycle.mjs +1 -18
  26. package/src/batch/reconcile.mjs +11 -0
  27. package/src/batch/resume-multi-lanes.mjs +38 -1
  28. package/src/batch/review.mjs +20 -0
  29. package/src/batch/salvage-batch.mjs +691 -0
  30. package/src/batch/worktree.mjs +130 -1
  31. package/src/config/preflight/git-batch.mjs +14 -3
  32. package/src/doctor/duplicate-install.mjs +148 -0
  33. package/src/doctor/pi-cli-resolution.mjs +222 -0
  34. package/src/doctor/run-doctor-checks.mjs +4 -0
  35. package/src/doctor/stale-worktrees.mjs +1 -1
  36. package/src/tasks/packet/parse-prompt.mjs +29 -0
@@ -21,6 +21,7 @@ import {
21
21
  runAttachedBatchEngine,
22
22
  } from "../src/batch/attached-runner.mjs";
23
23
  import { enforceAttachedOrphanRiskGuard } from "../src/doctor/attached-orphan-risk.mjs";
24
+ import { formatSalvageIntegrateOutput, formatSalvageListOutput, integrateSalvageableLane, listSalvageableLanes } from "../src/batch/salvage-batch.mjs";
24
25
 
25
26
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
26
27
 
@@ -29,6 +30,7 @@ const BATCH_FLAG_VALUE_TAKERS = new Set([
29
30
  "--through-wave",
30
31
  "--batch",
31
32
  "--reason",
33
+ "--lane",
32
34
  ]);
33
35
 
34
36
  /**
@@ -36,7 +38,7 @@ const BATCH_FLAG_VALUE_TAKERS = new Set([
36
38
  */
37
39
  export function printBatchHelp() {
38
40
  return (
39
- "Usage: spine batch start <scope>|pause|resume|retry <taskId>|skip <taskId>|force-merge [--wave N]|abort|dismiss|complete [--batch ID] [--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"
40
42
  );
41
43
  }
42
44
 
@@ -51,9 +53,18 @@ export function isBatchHelpRequest(args) {
51
53
  return true;
52
54
  }
53
55
  const subcommand = args.find((token) =>
54
- ["dismiss", "complete", "abort", "start", "pause", "resume", "retry", "skip", "force-merge"].includes(
55
- token,
56
- ),
56
+ [
57
+ "dismiss",
58
+ "complete",
59
+ "abort",
60
+ "start",
61
+ "pause",
62
+ "resume",
63
+ "retry",
64
+ "skip",
65
+ "force-merge",
66
+ "salvage",
67
+ ].includes(token),
57
68
  );
58
69
  if (subcommand && args.includes("help")) {
59
70
  const helpIdx = args.indexOf("help");
@@ -143,6 +154,12 @@ export function parseBatchArgs(args) {
143
154
  waveIndex = Number(args[waveIdx + 1]);
144
155
  }
145
156
 
157
+ let laneNumber = null;
158
+ const laneIdx = args.indexOf("--lane");
159
+ if (laneIdx >= 0 && args[laneIdx + 1]) {
160
+ laneNumber = Number(args[laneIdx + 1]);
161
+ }
162
+
146
163
  const subcommand =
147
164
  args.find(
148
165
  (t) =>
@@ -154,7 +171,8 @@ export function parseBatchArgs(args) {
154
171
  t === "resume" ||
155
172
  t === "retry" ||
156
173
  t === "skip" ||
157
- t === "force-merge",
174
+ t === "force-merge" ||
175
+ t === "salvage",
158
176
  ) ?? null;
159
177
 
160
178
  let waveFilter = null;
@@ -175,6 +193,8 @@ export function parseBatchArgs(args) {
175
193
  const dryRun = flags.has("--dry-run");
176
194
  const skipPreflight = flags.has("--skip-preflight");
177
195
  const forceSuperseded = flags.has("--force-superseded");
196
+ const integrate = flags.has("--integrate");
197
+ const yes = flags.has("--yes");
178
198
 
179
199
  return {
180
200
  json: flags.has("--json"),
@@ -187,9 +207,12 @@ export function parseBatchArgs(args) {
187
207
  dryRun,
188
208
  skipPreflight,
189
209
  forceSuperseded,
210
+ integrate,
211
+ yes,
190
212
  batchId,
191
213
  reason,
192
214
  waveIndex,
215
+ laneNumber,
193
216
  waveFilter,
194
217
  waveFilterError,
195
218
  subcommand,
@@ -225,6 +248,52 @@ export async function runSpineBatch(options) {
225
248
  };
226
249
  }
227
250
 
251
+ if (parsed.subcommand === "salvage") {
252
+ if (!parsed.batchId) {
253
+ return {
254
+ exitCode: 1,
255
+ output:
256
+ "Usage: spine batch salvage --batch <batchId> --dry-run [--json]\n" +
257
+ " spine batch salvage --batch <batchId> --lane <n> --integrate [--yes] [--json]\n",
258
+ };
259
+ }
260
+
261
+ if (parsed.integrate) {
262
+ if (!Number.isFinite(parsed.laneNumber) || parsed.laneNumber <= 0) {
263
+ return {
264
+ exitCode: 1,
265
+ output: "Usage: spine batch salvage --batch <batchId> --lane <n> --integrate [--yes] [--json]\n",
266
+ };
267
+ }
268
+
269
+ const result = await integrateSalvageableLane(projectRoot, parsed.batchId, parsed.laneNumber, {
270
+ yes: parsed.yes,
271
+ forceIntegrate: parsed.force,
272
+ });
273
+ return {
274
+ exitCode: result.exitCode ?? (result.ok ? 0 : 1),
275
+ output: formatSalvageIntegrateOutput(result, { json: parsed.json }),
276
+ result,
277
+ };
278
+ }
279
+
280
+ if (!parsed.dryRun) {
281
+ return {
282
+ exitCode: 1,
283
+ output:
284
+ "Usage: spine batch salvage --batch <batchId> --dry-run [--json]\n" +
285
+ " spine batch salvage --batch <batchId> --lane <n> --integrate [--yes] [--json]\n",
286
+ };
287
+ }
288
+
289
+ const result = listSalvageableLanes(projectRoot, parsed.batchId);
290
+ return {
291
+ exitCode: result.exitCode ?? (result.ok ? 0 : 1),
292
+ output: formatSalvageListOutput(result, { json: parsed.json }),
293
+ result,
294
+ };
295
+ }
296
+
228
297
  if (parsed.subcommand === "abort") {
229
298
  const result = abortBatch({
230
299
  projectRoot,
@@ -0,0 +1,89 @@
1
+ /**
2
+ * `spine cleanup worktrees` — prune stale batch dirs and dangling git worktree refs (#169).
3
+ */
4
+
5
+ import { pruneStaleWorktrees, scanStaleWorktrees } from "../src/batch/worktree.mjs";
6
+
7
+ /**
8
+ * @param {object} params
9
+ * @param {string} params.projectRoot
10
+ * @param {string[]} params.args
11
+ */
12
+ export function runSpineCleanup({ projectRoot, args }) {
13
+ const subcommand = args[0];
14
+ if (subcommand !== "worktrees") {
15
+ return {
16
+ exitCode: 1,
17
+ output:
18
+ "Usage: spine cleanup worktrees [--dry-run] [--yes] [--json]\n" +
19
+ " --dry-run List stale batch dirs and dangling worktree refs (default without --yes)\n" +
20
+ " --yes Remove empty batch shells and run git worktree prune\n" +
21
+ " --json Emit machine-readable output\n",
22
+ };
23
+ }
24
+
25
+ const dryRun = args.includes("--dry-run") || !args.includes("--yes");
26
+ const json = args.includes("--json");
27
+
28
+ if (dryRun) {
29
+ const scan = scanStaleWorktrees(projectRoot);
30
+ if (json) {
31
+ return {
32
+ exitCode: 0,
33
+ output: `${JSON.stringify({ action: "dry-run", ...scan }, null, 2)}\n`,
34
+ };
35
+ }
36
+
37
+ const lines = [];
38
+ if (scan.batchIds.length === 0) {
39
+ lines.push("No stale spine batch worktree dirs found.");
40
+ } else {
41
+ lines.push(`Stale batch dirs (${scan.batchIds.length}):`);
42
+ for (const batchId of scan.batchIds) {
43
+ const suffix = scan.emptyShells.includes(batchId) ? " (empty shell)" : "";
44
+ lines.push(` .worktrees/spine-${batchId}${suffix}`);
45
+ }
46
+ }
47
+
48
+ if (scan.danglingWorktrees.length > 0) {
49
+ lines.push(`Dangling worktree refs (${scan.danglingWorktrees.length}):`);
50
+ for (const entry of scan.danglingWorktrees) {
51
+ lines.push(` ${entry}`);
52
+ }
53
+ } else {
54
+ lines.push("No dangling worktree refs to prune.");
55
+ }
56
+
57
+ lines.push("Run with --yes to remove empty shells and git worktree prune.");
58
+ return { exitCode: 0, output: `${lines.join("\n")}\n` };
59
+ }
60
+
61
+ const result = pruneStaleWorktrees(projectRoot, { dryRun: false });
62
+ if (json) {
63
+ return {
64
+ exitCode: 0,
65
+ output: `${JSON.stringify({ action: "prune", ...result }, null, 2)}\n`,
66
+ };
67
+ }
68
+
69
+ const lines = [];
70
+ if (result.removedShells.length === 0) {
71
+ lines.push("No empty batch shells removed.");
72
+ } else {
73
+ lines.push(`Removed empty batch shells (${result.removedShells.length}):`);
74
+ for (const batchId of result.removedShells) {
75
+ lines.push(` .worktrees/spine-${batchId}/`);
76
+ }
77
+ }
78
+
79
+ if (result.prunedWorktrees.length === 0) {
80
+ lines.push("git worktree prune: nothing to prune.");
81
+ } else {
82
+ lines.push(`git worktree prune (${result.prunedWorktrees.length}):`);
83
+ for (const entry of result.prunedWorktrees) {
84
+ lines.push(` ${entry}`);
85
+ }
86
+ }
87
+
88
+ return { exitCode: 0, output: `${lines.join("\n")}\n` };
89
+ }
@@ -28,6 +28,7 @@ export const PHASE23_GRANDFATHERED_OVER_500 = [
28
28
  "src/batch/lane-dirty-check.mjs",
29
29
  "src/batch/attached-runner.mjs",
30
30
  "src/batch/lifecycle.mjs",
31
+ "src/batch/salvage-batch.mjs",
31
32
  ];
32
33
 
33
34
  const PHASE23_ENGINE_LANES_MAX = 500;
@@ -15,6 +15,14 @@ export {
15
15
  buildAttachedOrphanRiskDoctorCheck,
16
16
  detectAttachedOrphanRiskPatterns,
17
17
  } from "../src/doctor/attached-orphan-risk.mjs";
18
+ export {
19
+ buildDuplicateInstallDoctorCheck,
20
+ detectDuplicatePiSpineInstall,
21
+ } from "../src/doctor/duplicate-install.mjs";
22
+ export {
23
+ buildPiCliResolutionDoctorCheck,
24
+ resolveAuthoritativePiCliPath,
25
+ } from "../src/doctor/pi-cli-resolution.mjs";
18
26
  export { buildTestingEvidenceDoctorChecks, runDoctorChecks } from "../src/doctor/run-doctor-checks.mjs";
19
27
 
20
28
  export function cmdDoctor() {
package/bin/spine.mjs CHANGED
@@ -95,6 +95,13 @@ async function cmdSyncBase(args) {
95
95
  if (result.exitCode !== 0) process.exit(result.exitCode);
96
96
  }
97
97
 
98
+ async function cmdCleanup(args) {
99
+ const { runSpineCleanup } = await import("./spine-cleanup.mjs");
100
+ const result = runSpineCleanup({ projectRoot: process.cwd(), args });
101
+ process.stdout.write(result.output ?? "");
102
+ if (result.exitCode !== 0) process.exit(result.exitCode);
103
+ }
104
+
98
105
  async function cmdVerify(args) {
99
106
  const { runSpineVerify } = await import("./spine-cli/verify.mjs");
100
107
  const result = runSpineVerify({ projectRoot: process.cwd(), args });
@@ -267,6 +274,7 @@ ${c.bold}Commands:${c.reset}
267
274
  ${c.cyan}report progress${c.reset} Emit task.step_completed to batch journal (FR-WORK-09)
268
275
  ${c.cyan}gate${c.reset} Inspect or resolve integrate gate (FR-GATE)
269
276
  ${c.cyan}integrate${c.reset} Merge orch branch into base (FR-INT-01)
277
+ ${c.cyan}cleanup${c.reset} Prune stale worktree dirs and dangling refs
270
278
  ${c.cyan}sync-base${c.reset} Sync human checkout after isolated integrate (FR-WT-08)
271
279
  ${c.cyan}verify${c.reset} Phase exit verification checklists
272
280
  ${c.cyan}journal${c.reset} Replay orchestration journal timeline
@@ -326,6 +334,8 @@ ${c.bold}Examples:${c.reset}
326
334
  spine gate [approve|reject|status] # integrate gate FSM
327
335
  spine integrate [--dry-run] [--force-integrate] # merge orch branch into main
328
336
  spine sync-base [--dry-run] [--json] # sync checkout after isolated land
337
+ spine cleanup worktrees --dry-run # list stale batch dirs / dangling refs
338
+ spine cleanup worktrees --yes # remove empty shells + git worktree prune
329
339
  spine journal replay --batch 20260601T120000 # audit timeline for a batch
330
340
  spine state validate # validate active batch-state.json
331
341
  spine next # suggested next command (dry-run)
@@ -427,6 +437,9 @@ if (isCliEntrypoint(import.meta.url)) {
427
437
  case "integrate":
428
438
  await handleIntegrate(args);
429
439
  break;
440
+ case "cleanup":
441
+ await cmdCleanup(args);
442
+ break;
430
443
  case "sync-base":
431
444
  await cmdSyncBase(args);
432
445
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -32,12 +32,15 @@
32
32
  "doctor": "node bin/spine.mjs doctor",
33
33
  "lint": "eslint --max-warnings 0 src bin tests scripts",
34
34
  "typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.batch.json --noEmit",
35
+ "verify:reconcile-fixtures": "node scripts/verify-reconcile-test-fixtures.mjs",
36
+ "pretest": "npm run verify:reconcile-fixtures",
35
37
  "test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
36
38
  "test:batch": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/batch/*.test.mjs",
37
39
  "test:core": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs",
38
40
  "test:coverage": "node scripts/run-coverage.mjs --report-only",
39
41
  "coverage:check": "node scripts/run-coverage.mjs",
40
42
  "release:check": "npm run typecheck && npm run lint && SPINE_WORKER_STUB=1 npm test && npm run coverage:check",
43
+ "preversion": "npm run release:check",
41
44
  "prepublishOnly": "npm run release:check"
42
45
  },
43
46
  "repository": {
@@ -188,6 +188,7 @@ Run **after Step A.5 — Clarify** and **before Step B — Slice**. Authoring-on
188
188
  |------|----------|
189
189
  | **Size** | Target **M** (2–4 h). **L** → split when possible. **XL** → **must** split into multiple S/M tasks with dependencies. |
190
190
  | **Steps** | Max **4** implementation steps per task (exclude Testing & Verification / Documentation & Delivery). More steps → split. |
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). |
191
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. |
192
193
  | **Parallel waves** | Prefer **≤4** M-sized tasks per wave; 8-task mega-waves stall pi workers (see Phase 15 / SP-086–088). |
193
194
  | **Scope** | One deliverable per task; disjoint **File Scope** when tasks can run in parallel. |
@@ -337,6 +338,8 @@ In pi: `/spine-plan pending` then `/spine SP-042` (single-task) or `spine batch
337
338
  | 2 | Plan + Code | Plan + code review at step boundaries |
338
339
  | 3 | Full | Plan + code + test review |
339
340
 
341
+ **Environment compatibility ([#150](https://github.com/beettlle/pi-spine/issues/150)):** Review Level **2+** requires cross-model reviewer support in the execution environment. If running `SPINE_WORKER_STUB=1`, reviews are simulated — do not assign Level 2+ for tasks that need real cross-model review unless the operator has verified environment capability (preflight / batch config). Level 2+ in an unsupported environment can stall or kill lanes (e.g. SP-190 review spawn failure).
342
+
340
343
  Workers call **`spine_review_step`** (Pi tool) or `spine review step --step N [--type plan|code]`.
341
344
 
342
345
  When Review Level ≥ 1 (v1.3), workers also run a **final** review (`--type final`) before `.DONE`. Verdicts: `PASS`, `REVISE`, or `REPLAN` (scope wrong — operator edits PROMPT then retries). See [PRD v1.3](../docs/PRD-v1.3-upstream-execution-bridge.md) FR-UXB-04.
@@ -397,6 +400,14 @@ Individual steps can override the task-level review:
397
400
 
398
401
  Populate "Context to Read First" from `referenceDocs` in spine config. Never list docs in `neverLoad`.
399
402
 
403
+ **Parent split (successor tasks — [#146](https://github.com/beettlle/pi-spine/issues/146)):** When this task is a child of a superseded parent (e.g. SP-419 split into SP-466 + SP-467), add a line in **Context to Read First**:
404
+
405
+ ```markdown
406
+ - `Parent split: SP-### — [what was split out]`
407
+ ```
408
+
409
+ Example: SP-466 lists `Parent split: SP-419 — API schema types` so reviewers can trace decomposition history.
410
+
400
411
  When authoring tasks for Cursor-based repos, **File Scope drives glob-matched worker rules** — include concrete paths (e.g. `src/**/*.mjs`, not only `src/`) so language packs activate. The same File Scope applies to **plan review** rule matching; code reviews match globs against changed diff paths instead. Preview worker selection with `spine rules select --task <id>`; preview reviewer selection with `spine rules select --role reviewer --review-type plan|code|final --task <id>`. See [docs/design/cursor-rules-discovery.md](../../docs/design/cursor-rules-discovery.md).
401
412
 
402
413
  ---
@@ -501,6 +512,16 @@ Docs-only tasks still include `### Step N: Testing & Verification` (full suite i
501
512
 
502
513
  Do **not** generate Taskplane polyrepo **`#### Segment: <repoId>`** markers — pi-spine is monorepo-only (PRD §13.2). Split multi-repo work into separate tasks with dependencies instead.
503
514
 
515
+ ## Do NOT (worker scope — include in every PROMPT)
516
+
517
+ Workers must **not** modify paths maintained by other processes ([#149](https://github.com/beettlle/pi-spine/issues/149)):
518
+
519
+ - `.spine/` — spine engine config, runtime, rules manifest
520
+ - `AGENTS.md`, `CLAUDE.md` — GitNexus / agent harness indexes
521
+ - `.gitnexus/` — code intelligence index
522
+
523
+ Include these in every packet's `## Do NOT` section. Workers editing these paths cause merge dirty-file failures (e.g. batch `20260703T051629`).
524
+
504
525
  ---
505
526
 
506
527
  ## Checklist (Definition of Ready)
@@ -513,10 +534,15 @@ Before reporting launch commands:
513
534
  - [ ] Complexity scored; review level assigned (0–3)
514
535
  - [ ] Size S/M/L — split if XL
515
536
  - [ ] PROMPT.md from template: Mission, Dependencies, Context, File Scope, Contract (SP-\*), Steps, Do NOT, Git Commit Convention, Amendments
537
+ - [ ] Mission uses `Closes #N` or `Partial #N` on first line when tracking GitHub issues ([#147](https://github.com/beettlle/pi-spine/issues/147))
538
+ - [ ] Split-successor tasks include `Parent split: SP-###` in Context to Read First ([#146](https://github.com/beettlle/pi-spine/issues/146))
539
+ - [ ] `## Do NOT` bans `.spine/`, `AGENTS.md`, `CLAUDE.md`, `.gitnexus/` ([#149](https://github.com/beettlle/pi-spine/issues/149))
540
+ - [ ] Level 2+ only when operator environment supports cross-model review ([#150](https://github.com/beettlle/pi-spine/issues/150))
516
541
  - [ ] If `testCommand` is `` `true` ``, `fileScopeMustChange` MUST list at least one deliverable path
517
542
  - [ ] Every **Must Update** doc path also appears in `## File Scope` ([#144](https://github.com/beettlle/pi-spine/issues/144))
518
543
  - [ ] 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)
519
544
  - [ ] 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
+ - [ ] 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))
520
546
  - [ ] Plan waves ≤8 tasks when possible — `spine plan` warns when exceeded ([#143](https://github.com/beettlle/pi-spine/issues/143), SP-524)
521
547
  - [ ] `### Step N: Testing & Verification` present inside `## Steps` before `## Completion Criteria` (required even for docs-only Review Level 0)
522
548
  - [ ] STATUS.md with matching steps (hydration markers where needed)
@@ -542,7 +568,9 @@ Hydration commits (STATUS.md expansions) may happen mid-step for crash recovery.
542
568
  ## Key Principles
543
569
 
544
570
  - **Self-contained PROMPT.md** — the worker has no memory of this conversation. Cross-model reviewers receive a **fresh spawn** (FR-REV-04) with only the review request, diff, and Contract — not `referenceDocs` or worker rules. Place acceptance criteria and spec references in PROMPT `## Mission`, `## Contract`, and step checkboxes.
571
+ - **Issue links in Mission ([#147](https://github.com/beettlle/pi-spine/issues/147))** — Use `Closes #N` when this task fully resolves the issue. Use `Partial #N` when this task is one of several addressing the issue. Place on the first line of `## Mission` (not `Closes: [#N]` or `GitHub: [#N]` variants).
545
572
  - **Scoped `testCommand` for cross-model batches** — lane worktrees differ from dev checkouts; broad `flutter test` / `npm test` can fail in lanes even when targeted tests pass. See [cross-model authoring guidance](references/contract-template.md#cross-model-authoring-worker--reviewer) for the `testCommand` decision table.
573
+ - **Scoped contract ≠ full regression** — changing shared modules (diagnosis, reconcile, parse-prompt) can break tests outside the task's scoped `testCommand`. Authors must `rg` old strings in `tests/` and include related test files in Contract, or rely on operator post-integrate `release:check` on `main` ([post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md)).
546
574
  - **S/M patch tasks: no coverage gate in Contract** — do not chain `npm run coverage:check` or bare `npm test` in `## Contract` `testCommand` on Size S/M tasks; integrate gate owns full coverage at merge. Use scoped `node --test path/to.test.mjs` (SP-521 / [#141](https://github.com/beettlle/pi-spine/issues/141)). `spine tasks validate` warns when violated.
547
575
  - **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.
548
576
  - **Documentation in every task** — "Must Update" / "Check If Affected" prevent doc drift.
@@ -223,10 +223,21 @@ Reviewers spawn as **fresh sessions** with no memory of the worker session (FR-R
223
223
  |-----------|---------------------------|
224
224
  | Docs-only, no code changes | `` `true` `` **and** `fileScopeMustChange` with at least one deliverable doc path |
225
225
  | Single module, targeted tests exist | `` `node --test tests/feature.test.mjs` `` or `` `flutter test test/unit/services/foo_test.dart` `` |
226
+ | **Shared-module behavior change** (diagnosis, reconcile, parse-prompt, worktree, doctor) | Chain **all** related `tests/**/*.test.mjs` from `rg` for old strings — not only the new test file (see below) |
226
227
  | Full-suite safe in lane worktree | `` `npm run typecheck && SPINE_WORKER_STUB=1 npm test` `` |
227
228
  | Coverage gate required (pi-spine ≥77%) | `` `npm run coverage:check` `` |
228
229
  | Long external job (>2h) | Scoped command + `stallTimeoutMinutes` and `extendGraceOnFileScope` in Contract (see SP-314 example above) |
229
230
 
231
+ ### Shared-module behavior changes
232
+
233
+ When `fileScopeMustChange` touches modules whose output is asserted across multiple test files (e.g. `src/batch/diagnosis*.mjs`, `src/batch/reconcile.mjs`, `src/tasks/packet/parse-prompt.mjs`, `src/batch/worktree.mjs`, `bin/spine-doctor.mjs`):
234
+
235
+ 1. Before finalizing Contract, run `rg -l 'old headline|old error phrase' tests/` for strings being replaced.
236
+ 2. Include **every** hit file in `testCommand` (chain with `&&`), or document why post-integrate `release:check` on `main` will cover them ([post-integrate-regression-gate.md](../../spine-release-operator/references/post-integrate-regression-gate.md)).
237
+ 3. List discovered test files in the Testing step checkboxes.
238
+
239
+ **Anti-pattern:** New test file only in `testCommand` while older tests still assert previous behavior (SP-560 / `detached-start-orphan-timeout.test.mjs` vs `diagnosis-parent-exit.test.mjs`).
240
+
230
241
  ---
231
242
 
232
243
  ## Validate before plan
@@ -20,9 +20,13 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
20
20
 
21
21
  > **Real-pi batches (SP-195/SP-278):** Do **not** add per-step "Call `spine_review_step`" checkboxes for Review Level ≥ 1. The batch engine runs plan, code, and final reviews after worker `.DONE`. Stub batches (`SPINE_WORKER_STUB=1`) may still use in-worker stub plan review via the tool when a checkpoint marker requires it.
22
22
 
23
+ > **Environment ([#150](https://github.com/beettlle/pi-spine/issues/150)):** Review Level **2+** requires cross-model reviewer support. `SPINE_WORKER_STUB=1` simulates reviews only — verify operator environment before assigning Level 2+.
24
+
23
25
  ## Mission
24
26
 
25
- [One paragraph: what you're building and why it matters]
27
+ > **Issue links ([#147](https://github.com/beettlle/pi-spine/issues/147)):** Use `Closes #N` when this task fully resolves the issue. Use `Partial #N` when this task is one of several addressing the issue. Place on the first line below (not `Closes: [#N]` or `GitHub: [#N]` variants).
28
+
29
+ [Closes #N | Partial #N] — [One paragraph: what you're building and why it matters]
26
30
 
27
31
  ## Dependencies
28
32
 
@@ -42,6 +46,7 @@ Review Level 0 is ONLY for trivial changes. Most M+ tasks need Level ≥1.
42
46
 
43
47
  - `[path/to/CONTEXT.md]`
44
48
  - `[path/to/specific-doc.md]` — [why needed]
49
+ - `Parent split: SP-### — [what was split out]` — **successor tasks only** ([#146](https://github.com/beettlle/pi-spine/issues/146)); omit when not a split child
45
50
 
46
51
  ## Environment
47
52
 
@@ -156,6 +161,7 @@ for this task MUST include the task ID for traceability:
156
161
  - Modify framework/standards docs without explicit user approval
157
162
  - Load docs not listed in "Context to Read First"
158
163
  - Commit without the task ID prefix in the commit message
164
+ - Modify `.spine/`, `AGENTS.md`, `CLAUDE.md`, or `.gitnexus/` — maintained by spine engine / GitNexus ([#149](https://github.com/beettlle/pi-spine/issues/149))
159
165
 
160
166
  ---
161
167
 
@@ -29,6 +29,8 @@ Invoke explicitly: `/skill:spine-autonomous-operator`
29
29
  - **Always** use `spine status --diagnose` for recovery; follow `suggestedCommand`
30
30
  - **Always** run `spine gate approve` before `spine integrate`
31
31
  - **Always** run `npm install` on `main` after successful integrate
32
+ - **Always** run post-integrate `npm run release:check` on `main` after each wave land loop before the next wave — see [post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md)
33
+ - **Never** use `| tail` or `| head` alone to judge `release:check` pass/fail — verify exit code
32
34
  - **Do not** use unattended `spine run sequence --auto-approve-gate --force` without monitoring
33
35
  - **Do not** start a second batch while another batch is **running** on the same repo
34
36
  - **Never** background `spine batch resume --attached` or `resume --attached --force` ([#163](https://github.com/beettlle/pi-spine/issues/163))
@@ -190,6 +192,19 @@ git add spine-tasks/*/.DONE 2>/dev/null; git commit -m "chore: track .DONE for w
190
192
 
191
193
  Verify: `git status` clean, `.DONE` count increased.
192
194
 
195
+ ### 3.3a Post-integrate regression gate (blocking)
196
+
197
+ After **every** land loop (including manual merge), on current `main`:
198
+
199
+ ```bash
200
+ npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${N}.log
201
+ test "${PIPESTATUS[0]}" -eq 0
202
+ ```
203
+
204
+ Full reference: [post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md).
205
+
206
+ **If non-zero:** fix on `main`, commit, re-run. Do **not** start wave N+1 until green.
207
+
193
208
  ### 3.4 Advance
194
209
 
195
210
  Increment `N` and repeat.
@@ -245,11 +260,12 @@ See [references/issue-template.md](references/issue-template.md) for a full temp
245
260
  spine plan pending
246
261
  spine preflight
247
262
  git status
248
- npm run release:check
263
+ npm run release:check 2>&1 | tee /tmp/pi-spine-release-check.log
264
+ test "${PIPESTATUS[0]}" -eq 0
249
265
  find spine-tasks -name '.DONE' | wc -l
250
266
  ```
251
267
 
252
- In pi sessions, `MonitorCreate` for `npm run release:check` is allowed (see pi-async-orchestration).
268
+ In pi sessions, `MonitorCreate` for `npm run release:check` is allowed (see pi-async-orchestration). Verify exit 0 from full log — not `tail` alone.
253
269
 
254
270
  ## Final report (required)
255
271
 
@@ -273,7 +289,7 @@ In pi sessions, `MonitorCreate` for `npm run release:check` is allowed (see pi-a
273
289
  ```text
274
290
  Run pending spine tasks: validate/analyze/plan → fix packets → preflight →
275
291
  for each wave: MonitorCreate batch start (or foreground) → diagnose →
276
- gate approve → integrate → npm install → batch complete.
292
+ gate approve → integrate → npm install → batch complete → post-integrate release:check (exit 0).
277
293
  Resume --attached --force stays foreground. File pi-spine bugs on engine faults.
278
294
  Done when 0 pending, preflight green, release:check passes. Post final report.
279
295
  ```
@@ -72,6 +72,24 @@ Follow `suggestedCommand` from `spine status --diagnose` when unsure.
72
72
 
73
73
  ---
74
74
 
75
+ ## Post-integrate verification
76
+
77
+ After each wave land loop (`integrate` + `batch complete`), before the next wave or `git push`:
78
+
79
+ ```bash
80
+ npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${N}.log
81
+ test "${PIPESTATUS[0]}" -eq 0
82
+ ```
83
+
84
+ Full reference: [post-integrate-regression-gate.md](../../spine-release-operator/references/post-integrate-regression-gate.md).
85
+
86
+ | Do | Do not |
87
+ |----|--------|
88
+ | Verify `$?` or `${PIPESTATUS[0]}` after `release:check` | Use `\| tail` alone for pass/fail |
89
+ | Re-run after manual merge / conflict resolution | Assume scoped task `testCommand` covered full CI |
90
+
91
+ ---
92
+
75
93
  ## Preflight
76
94
 
77
95
  ```bash
@@ -23,6 +23,7 @@ Invoke explicitly: `/skill:spine-orchestrate-waves`, `/spine-orchestrate pending
23
23
  | Curated release subset | `spine-release-operator` skill |
24
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) |
25
25
  | Pi async batch/verify (MonitorCreate) | [spine-release-operator/references/pi-async-orchestration.md](../spine-release-operator/references/pi-async-orchestration.md) |
26
+ | Post-integrate regression gate | [spine-release-operator/references/post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md) |
26
27
  | Canonical how-to prose | [references/outer-loop.md](references/outer-loop.md) (synced from `docs/adoption/agent-orchestrated-waves.md`) |
27
28
  | Slash entry (`/spine-orchestrate`) | pi-spine extension — wave plan + outer loop checklist |
28
29
  | Single-task suggested command | `/spine-next` inside land loop |
@@ -69,6 +70,7 @@ START
69
70
  **Hard stops before next wave:**
70
71
 
71
72
  - Land loop incomplete (`integrate` + `batch complete` + push when remote sync desired)
73
+ - Post-integrate `npm run release:check` not green on `main` — see [post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md)
72
74
  - Unresolved `failed`, `aborted`, or `needs_retry` on current wave
73
75
  - Active `spine run sequence --attached` on same batch (state corruption risk)
74
76
 
@@ -106,7 +108,10 @@ spine gate status
106
108
 
107
109
  spine gate approve # only after evidence checklist passes
108
110
  spine integrate
111
+ npm install
109
112
  spine batch complete
113
+ npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${WAVE}.log
114
+ test "${PIPESTATUS[0]}" -eq 0 # blocking — see post-integrate-regression-gate.md
110
115
  git push origin <baseBranch> # when remote sync desired
111
116
  ```
112
117
 
@@ -142,7 +147,7 @@ Inspect `.spine/runtime/<batchId>/evidence/`:
142
147
  | `failed` | Inspect journal (`spine journal follow`); fix contract/env before retry |
143
148
  | `needs_replan` | Read `{taskFolder}/.reviews/final-*.md`; edit PROMPT scope, then retry |
144
149
  | `merge_blocked` | Resolve conflicts on orch branch or lane worktree; `spine batch resume --force` |
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) |
150
+ | `engine_orphaned` | Do **not** start a second attached engine; follow recovery recipe in [outer-loop.md](references/outer-loop.md#orphan-recovery-recipe) — `spine batch retry <taskId>` then `spine batch resume --force` (detached). Headline distinguishes parent shell exit from crash when journal has no `engine.crash` |
146
151
  | `worker_orphaned` | `spine batch retry <taskId>` (reconciles orphan running → failed) |
147
152
  | `worker_done_missing` | Read worker output log from headline; fix blocker, then `spine batch retry <taskId>` |
148
153
  | `completed` | Run `spine batch complete` if not archived, then push |
@@ -155,12 +160,14 @@ Inspect `.spine/runtime/<batchId>/evidence/`:
155
160
  | Anti-pattern | Correct approach |
156
161
  |--------------|------------------|
157
162
  | `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) |
163
+ | Cursor background shell + `--attached` (`block_until_ms` backgrounds tool shell) | Parent exits in ~15–120s; `engine_orphaned` misread as crash — detached start/resume + recovery recipe (retry → resume --force → diagnose) |
158
164
  | `spine batch resume --attached` while `spine run sequence --attached` is active | One entry point; kill stale engines first (`spine status --diagnose`) |
159
165
  | Approving gate without reading evidence | Always inspect evidence directory before `spine gate approve` |
160
166
  | Expecting workers to call `spine_request_gate` for integrate | Agent drives gate approval from host shell |
161
167
  | `--auto-approve-gate` with real pi workers | Per-wave agent loop with explicit gate approval |
162
- | Starting next wave before land loop completes | Complete integrate + batch complete + push before next wave |
168
+ | Starting next wave before land loop completes | Complete integrate + batch complete + post-integrate release:check + push before next wave |
163
169
  | Bare full-suite `testCommand` with large output | Scope `testCommand` to relevant test files |
170
+ | `release:check \| tail` for pass/fail | Verify exit code; use `tee` + `${PIPESTATUS[0]}` — see [post-integrate-regression-gate.md](../spine-release-operator/references/post-integrate-regression-gate.md) |
164
171
 
165
172
  ---
166
173