pi-spine 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/bin/spine-cleanup.mjs +89 -0
  2. package/bin/spine-doctor.mjs +8 -0
  3. package/bin/spine.mjs +13 -0
  4. package/package.json +4 -1
  5. package/skills/create-spine-tasks/SKILL.md +28 -0
  6. package/skills/create-spine-tasks/references/contract-template.md +11 -0
  7. package/skills/create-spine-tasks/references/prompt-template.md +7 -1
  8. package/skills/spine-autonomous-operator/SKILL.md +19 -3
  9. package/skills/spine-autonomous-operator/references/agent-shell-batch-policy.md +18 -0
  10. package/skills/spine-orchestrate-waves/SKILL.md +9 -2
  11. package/skills/spine-orchestrate-waves/references/outer-loop.md +24 -2
  12. package/skills/spine-release-operator/SKILL.md +25 -2
  13. package/skills/spine-release-operator/references/post-integrate-regression-gate.md +96 -0
  14. package/skills/spine-release-operator/references/release-manifest-template.md +7 -3
  15. package/src/batch/abort.mjs +10 -14
  16. package/src/batch/diagnosis-merge-failure.mjs +66 -0
  17. package/src/batch/diagnosis-parent-exit.mjs +125 -0
  18. package/src/batch/diagnosis.mjs +26 -73
  19. package/src/batch/lane-dirty-check.mjs +10 -0
  20. package/src/batch/lifecycle.mjs +1 -18
  21. package/src/batch/reconcile.mjs +11 -0
  22. package/src/batch/review.mjs +20 -0
  23. package/src/batch/worktree.mjs +130 -1
  24. package/src/config/preflight/git-batch.mjs +14 -3
  25. package/src/doctor/duplicate-install.mjs +148 -0
  26. package/src/doctor/pi-cli-resolution.mjs +222 -0
  27. package/src/doctor/run-doctor-checks.mjs +4 -0
  28. package/src/doctor/stale-worktrees.mjs +1 -1
  29. package/src/tasks/packet/parse-prompt.mjs +29 -0
@@ -0,0 +1,96 @@
1
+ # Post-integrate regression gate
2
+
3
+ Operator-enforced full-suite check on `main` after each land loop. The spine CLI does **not** run this automatically — agents and humans must run it explicitly.
4
+
5
+ **Related:** manifest regression gate in [release-manifest-template.md](release-manifest-template.md); SP-560 / `detached-start-orphan-timeout.test.mjs` cross-file drift (v2.1.0).
6
+
7
+ ---
8
+
9
+ ## When required (blocking)
10
+
11
+ Run on current `main` after:
12
+
13
+ 1. **Standard land loop** — `spine gate approve` → `spine integrate` → `npm install` → `spine batch complete`
14
+ 2. **Manual integrate** — `git merge orch/*`, conflict resolution, `human_base_diverged` recovery, or `spine batch complete --detect-manual-merge`
15
+ 3. **Before next wave** — do not start wave N+1 until gate passes on `main`
16
+ 4. **Before first `git push origin main`** during a release cycle
17
+ 5. **Before `npm version`** — Phase 5 `release:check` (same command; re-run if `main` moved)
18
+
19
+ ---
20
+
21
+ ## Command
22
+
23
+ ```bash
24
+ cd <repo-root>
25
+ npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${WAVE:-main}.log
26
+ test "${PIPESTATUS[0]}" -eq 0
27
+ ```
28
+
29
+ Equivalent without `tee` (must capture exit code):
30
+
31
+ ```bash
32
+ npm run release:check
33
+ echo "release:check exit: $?"
34
+ ```
35
+
36
+ **If exit is non-zero:** STOP. Fix on `main`, commit, re-run gate. Do not start the next wave, push, or tag.
37
+
38
+ ---
39
+
40
+ ## Verification discipline
41
+
42
+ | Do | Do not |
43
+ |----|--------|
44
+ | Run full `npm run release:check` | Pipe through `tail` or `head` for pass/fail decisions |
45
+ | Verify exit code explicitly (`$?` or `${PIPESTATUS[0]}`) | Claim "passed" from truncated log tail |
46
+ | Save log path in manifest publish checklist | Assume scoped task `testCommand` covered full CI suite |
47
+
48
+ **Anti-pattern:** `npm run release:check 2>&1 | tail -20` — `tail` exits 0 even when `release:check` failed.
49
+
50
+ **Preferred in bash scripts:**
51
+
52
+ ```bash
53
+ set -o pipefail
54
+ npm run release:check 2>&1 | tee /tmp/pi-spine-release-check.log
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Manual merge checklist
60
+
61
+ When any of these occurred on the current wave:
62
+
63
+ - [ ] `git merge orch/spine-*` into `main` (not only `spine integrate`)
64
+ - [ ] Merge conflict resolution in production or test files
65
+ - [ ] `spine batch complete --detect-manual-merge`
66
+ - [ ] Diagnosis `human_base_diverged` before integrate
67
+
68
+ Then post-integrate regression gate is **mandatory** before next wave or push. Record log path in manifest.
69
+
70
+ ---
71
+
72
+ ## Shared-module behavior changes
73
+
74
+ When production code changes user-visible strings, errors, or diagnosis headlines in modules consumed by multiple tests:
75
+
76
+ ```bash
77
+ rg -l 'old phrase|OldErrorClass' tests/ src/
78
+ ```
79
+
80
+ Every test file that asserts on the old behavior must either:
81
+
82
+ - Appear in the task's scoped `testCommand`, or
83
+ - Be covered by this post-integrate `release:check` on `main` before push
84
+
85
+ **Example (SP-560):** Changing orphan headlines in `src/batch/diagnosis*.mjs` required updating both `diagnosis-parent-exit.test.mjs` and `detached-start-orphan-timeout.test.mjs` — scoped contract on the new test alone was insufficient until full suite ran on `main`.
86
+
87
+ ---
88
+
89
+ ## Skills that reference this doc
90
+
91
+ | Skill | Section |
92
+ |-------|---------|
93
+ | `spine-release-operator` | Phase 4.3a |
94
+ | `spine-autonomous-operator` | Phase 3.3a |
95
+ | `spine-orchestrate-waves` | Per-wave outer loop |
96
+ | `create-spine-tasks` | Shared-module contract rule |
@@ -51,12 +51,15 @@ spine status --diagnose
51
51
  spine gate approve && spine integrate && npm install && spine batch complete
52
52
  ```
53
53
 
54
- **Regression gate** (run after each integrate, before next wave):
54
+ **Regression gate** (run after each integrate, before next wave — full reference: [post-integrate-regression-gate.md](../../skills/spine-release-operator/references/post-integrate-regression-gate.md)):
55
55
 
56
56
  ```bash
57
- npm run typecheck && SPINE_WORKER_STUB=1 npm test && npm run release:check
57
+ npm run release:check 2>&1 | tee /tmp/pi-spine-post-integrate-wave-${WAVE:-main}.log
58
+ test "${PIPESTATUS[0]}" -eq 0
58
59
  ```
59
60
 
61
+ Do **not** use `| tail` alone for pass/fail — verify exit code.
62
+
60
63
  **Operator gates** (human only — sequence does not auto-approve without explicit flags):
61
64
 
62
65
  1. Approve this manifest (operator sign-off on scope)
@@ -104,8 +107,9 @@ Filled example: [`docs/release/manifest-v1.10.0-example.md`](../../../docs/relea
104
107
  ## Publish checklist (Phase 5–6)
105
108
 
106
109
  - [ ] All release-scoped tasks `.DONE` on `main`
110
+ - [ ] Post-integrate `release:check` green after **each wave** (log paths recorded)
107
111
  - [ ] `spine preflight` green
108
- - [ ] `npm run release:check` green (typecheck, lint, tests, coverage — CI parity)
112
+ - [ ] `npm run release:check` green on final `HEAD` (typecheck, lint, tests, coverage — CI parity)
109
113
  - [ ] `git status` clean
110
114
  - [ ] Operator approved publish bump type: patch | minor | major
111
115
  - [ ] `npm version <bump>` + `git push && git push --tags`
@@ -10,7 +10,7 @@ import { archiveBatchStatePath } from "./lifecycle.mjs";
10
10
  import { appendJournalEvent, journalPath, readJournalEvents, readJournalTail } from "./journal.mjs";
11
11
  import { loadBatchStateFile } from "./reconcile.mjs";
12
12
  import { appendBatchHistoryEntry } from "./state.mjs";
13
- import { removeLaneWorktree } from "./worktree.mjs";
13
+ import { removeLaneWorktrees, maxLaneNumberFromBatchState } from "./worktree.mjs";
14
14
  import { terminateLaneWorkers } from "./worker-host.mjs";
15
15
 
16
16
  /**
@@ -230,19 +230,15 @@ export function abortBatch(ctx) {
230
230
 
231
231
  if (hard) {
232
232
  const configResult = loadSpineConfig(projectRoot);
233
- if (shouldCleanupWorktreesOnHardAbort(configResult.config ?? {})) {
234
- for (const lane of snapshot.lanes ?? []) {
235
- const laneNumber = Number(
236
- lane && typeof lane === "object"
237
- ? /** @type {{ laneNumber?: number }} */ (lane).laneNumber
238
- : 1,
239
- );
240
- try {
241
- removeLaneWorktree(projectRoot, batchId, laneNumber || 1);
242
- } catch {
243
- // best-effort cleanup
244
- }
245
- }
233
+ const config = configResult.config ?? {};
234
+ if (shouldCleanupWorktreesOnHardAbort(config)) {
235
+ const laneCount = maxLaneNumberFromBatchState(snapshot);
236
+ removeLaneWorktrees(projectRoot, batchId, laneCount);
237
+ appendJournalEvent(projectRoot, batchId, "batch.worktrees_cleaned", {
238
+ batchId,
239
+ laneCount,
240
+ reason: "hard_abort",
241
+ });
246
242
  }
247
243
  }
248
244
 
@@ -3,6 +3,72 @@
3
3
  * Wave merge failure diagnosis helpers (SP-338 / GitHub #29).
4
4
  */
5
5
 
6
+ import {
7
+ isGitignoredArtifactPath,
8
+ listGitignoredArtifactRoots,
9
+ } from "./lane-dirty-check.mjs";
10
+
11
+ const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
12
+
13
+ /**
14
+ * @param {object} [ctx]
15
+ * @param {string|null} [ctx.exitReason]
16
+ * @param {string|null} [ctx.failureClass]
17
+ * @param {string|null} [ctx.lastError]
18
+ * @param {object[]} [ctx.journalEvents]
19
+ * @returns {boolean}
20
+ */
21
+ export function inferMergeGitignoredFailure(ctx = {}) {
22
+ const { exitReason, failureClass, lastError, journalEvents } = ctx;
23
+ if (GITIGNORED_MERGE_FAILURE_CLASSES.has(exitReason ?? "")) return true;
24
+ if (GITIGNORED_MERGE_FAILURE_CLASSES.has(failureClass ?? "")) return true;
25
+
26
+ const haystackParts = [exitReason, failureClass, lastError];
27
+ if (Array.isArray(journalEvents)) {
28
+ for (const event of journalEvents) {
29
+ if (event.type !== "batch.merge_failed" && event.type !== "task.failed") continue;
30
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
31
+ haystackParts.push(
32
+ payload.failureClass,
33
+ payload.classification,
34
+ payload.error,
35
+ payload.output,
36
+ );
37
+ }
38
+ }
39
+ const haystack = haystackParts.filter(Boolean).join("\n").toLowerCase();
40
+ return (
41
+ haystack.includes("gitignored dirty files only") ||
42
+ haystack.includes("merge_failed_gitignored") ||
43
+ haystack.includes("gitignoreddirtyworktree") ||
44
+ (haystack.includes("git add") && haystack.includes("ignored"))
45
+ );
46
+ }
47
+
48
+ /**
49
+ * @param {string|null|undefined} taskBranch
50
+ * @param {string[]|null|undefined} gitignoredPaths
51
+ */
52
+ export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
53
+ const branchHint = taskBranch ? `git checkout ${taskBranch}` : "git checkout <task-branch>";
54
+ const stetRuntimeCleanRoots = new Set([".review", ".spine/runtime"]);
55
+ if (Array.isArray(gitignoredPaths) && gitignoredPaths.length > 0) {
56
+ const artifactRoots = listGitignoredArtifactRoots(gitignoredPaths);
57
+ const stetRuntimeOnly =
58
+ artifactRoots.length > 0 &&
59
+ artifactRoots.every((root) => stetRuntimeCleanRoots.has(root)) &&
60
+ gitignoredPaths.every((p) => isGitignoredArtifactPath(p));
61
+ if (stetRuntimeOnly) {
62
+ const cleanHint = `git clean -fdX -- ${artifactRoots.join(" ")}`;
63
+ return `${branchHint} && ${cleanHint} && spine batch resume --force`;
64
+ }
65
+ const pathHint = `git rm -r --cached -- ${gitignoredPaths.slice(0, 5).join(" ")}`;
66
+ return `${branchHint} && ${pathHint} && spine batch resume --force`;
67
+ }
68
+ const pathHint = "git rm -r --cached -- <gitignored-paths>";
69
+ return `${branchHint} && ${pathHint} && spine batch resume --force`;
70
+ }
71
+
6
72
  /**
7
73
  * @param {unknown[]} mergeResults
8
74
  * @param {string|null|undefined} lastError
@@ -0,0 +1,125 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Parent-shell exit vs engine crash hints for engine_orphaned diagnosis (SP-560 / #185).
4
+ */
5
+
6
+ import { DETACHED_ENGINE_LOG_REL } from "./detached-spawn.mjs";
7
+
8
+ /** Journal types that indicate an uncaught engine crash (not parent shell exit). */
9
+ const ENGINE_CRASH_JOURNAL_TYPES = new Set(["engine.crash", "engine.uncaught_exception"]);
10
+
11
+ /**
12
+ * @param {object[]} [journalEvents]
13
+ * @returns {boolean}
14
+ */
15
+ export function journalHasEngineCrash(journalEvents) {
16
+ if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
17
+ return journalEvents.some((event) => ENGINE_CRASH_JOURNAL_TYPES.has(event.type));
18
+ }
19
+
20
+ /**
21
+ * @param {object[]} [journalEvents]
22
+ * @returns {boolean}
23
+ */
24
+ export function journalIndicatesParentExit(journalEvents) {
25
+ if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
26
+ return journalEvents.some((event) => {
27
+ if (event.type !== "engine.parent_died") return false;
28
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
29
+ return payload.signal === "parent_exit" || event.signal === "parent_exit";
30
+ });
31
+ }
32
+
33
+ /**
34
+ * @param {object[]} [journalEvents]
35
+ * @returns {boolean}
36
+ */
37
+ export function journalHasBatchResumed(journalEvents) {
38
+ if (!Array.isArray(journalEvents) || journalEvents.length === 0) return false;
39
+ return journalEvents.some((event) => event.type === "batch.resumed");
40
+ }
41
+
42
+ /**
43
+ * Infer whether engine_orphaned is likely parent shell exit vs engine crash.
44
+ *
45
+ * @param {object} [ctx]
46
+ * @param {object[]} [ctx.journalEvents]
47
+ * @param {boolean} [ctx.staleEnginePid]
48
+ * @returns {{ kind: "parent_exit" | "parent_exit_likely" | "crash" | "unknown", detachedEngineLogRef: string|null }}
49
+ */
50
+ export function inferEngineOrphanCause(ctx = {}) {
51
+ const { journalEvents, staleEnginePid } = ctx;
52
+ const logRef = staleEnginePid === true ? DETACHED_ENGINE_LOG_REL : null;
53
+
54
+ if (journalHasEngineCrash(journalEvents)) {
55
+ return { kind: "crash", detachedEngineLogRef: logRef };
56
+ }
57
+
58
+ if (journalIndicatesParentExit(journalEvents)) {
59
+ return { kind: "parent_exit", detachedEngineLogRef: logRef };
60
+ }
61
+
62
+ // Detached resume stall (SP-297) — not parent shell exit from attached mode.
63
+ if (journalHasBatchResumed(journalEvents)) {
64
+ return { kind: "unknown", detachedEngineLogRef: logRef };
65
+ }
66
+
67
+ // Attached start orphan without crash journal (#185).
68
+ if (
69
+ Array.isArray(journalEvents) &&
70
+ journalEvents.some((event) => event.type === "batch.started")
71
+ ) {
72
+ return { kind: "parent_exit_likely", detachedEngineLogRef: logRef };
73
+ }
74
+
75
+ return { kind: "unknown", detachedEngineLogRef: logRef };
76
+ }
77
+
78
+ /**
79
+ * @param {string} batchLabel
80
+ * @param {object} ctx
81
+ * @param {string|null} [ctx.failedTaskId]
82
+ * @param {{ kind: string, detachedEngineLogRef?: string|null }} [ctx.engineOrphanCause]
83
+ * @returns {string|null}
84
+ */
85
+ export function buildEngineOrphanParentExitHeadline(batchLabel, ctx = {}) {
86
+ const cause = ctx.engineOrphanCause;
87
+ if (!cause) return null;
88
+
89
+ const taskHint = ctx.failedTaskId ? ` (task ${ctx.failedTaskId} still running)` : "";
90
+ const logHint = cause.detachedEngineLogRef ? ` — see ${cause.detachedEngineLogRef}` : "";
91
+
92
+ if (cause.kind === "parent_exit") {
93
+ return `${batchLabel} attached engine parent shell exited${taskHint} — use detached resume, not a crash${logHint}`;
94
+ }
95
+
96
+ if (cause.kind === "parent_exit_likely") {
97
+ return `${batchLabel} engine likely orphaned by parent shell exit${taskHint} — use detached resume (no engine.crash in journal)${logHint}`;
98
+ }
99
+
100
+ if (cause.kind === "crash") {
101
+ return null;
102
+ }
103
+
104
+ return null;
105
+ }
106
+
107
+ /**
108
+ * @param {object} ctx
109
+ * @param {string|null} [ctx.failedTaskId]
110
+ * @param {{ kind: string }} [ctx.engineOrphanCause]
111
+ * @returns {string|null}
112
+ */
113
+ export function buildEngineOrphanParentExitSuggestedCommand(ctx = {}) {
114
+ const cause = ctx.engineOrphanCause;
115
+ if (!cause) return null;
116
+
117
+ if (cause.kind === "parent_exit" || cause.kind === "parent_exit_likely") {
118
+ if (ctx.failedTaskId) {
119
+ return `spine batch retry ${ctx.failedTaskId}`;
120
+ }
121
+ return "spine batch resume --force";
122
+ }
123
+
124
+ return null;
125
+ }
@@ -15,11 +15,17 @@ import { buildAlternatives } from "./diagnosis-alternatives.mjs";
15
15
  export { buildAlternatives } from "./diagnosis-alternatives.mjs";
16
16
  import {
17
17
  buildMergeFailureHeadline,
18
+ buildGitignoredMergeRepairCommand,
19
+ } from "./diagnosis-merge-failure.mjs";
20
+ export {
21
+ buildMergeFailureHeadline,
22
+ buildGitignoredMergeRepairCommand,
23
+ inferMergeGitignoredFailure,
24
+ summarizeMergeFailures,
18
25
  } from "./diagnosis-merge-failure.mjs";
19
- export { buildMergeFailureHeadline, summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
20
26
  import { buildRunningTailHeadline } from "./diagnosis-tail-state.mjs";
21
27
  export { buildRunningTailHeadline, isRunningWithoutActiveWorkers } from "./diagnosis-tail-state.mjs";
22
- export { findLatestReviewHonorSignal } from "./review.mjs";
28
+ export { buildReviewHonorHeadlineSuffix, findLatestReviewHonorSignal } from "./review.mjs";
23
29
  import {
24
30
  buildStubFailureHeadline,
25
31
  buildStubFailureSuggestedCommand,
@@ -36,6 +42,16 @@ import {
36
42
  buildPrimaryFailureHeadline,
37
43
  buildPrimaryFailureSuggestedCommand,
38
44
  } from "./diagnosis-primary-failure.mjs";
45
+ import {
46
+ buildEngineOrphanParentExitHeadline,
47
+ buildEngineOrphanParentExitSuggestedCommand,
48
+ } from "./diagnosis-parent-exit.mjs";
49
+ export {
50
+ inferEngineOrphanCause,
51
+ journalHasEngineCrash,
52
+ journalIndicatesParentExit,
53
+ } from "./diagnosis-parent-exit.mjs";
54
+ import { buildReviewHonorHeadlineSuffix } from "./review.mjs";
39
55
  export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
40
56
 
41
57
  const INVALID_BARE_RETRY_FORCE = /^spine batch retry --force$/;
@@ -84,7 +100,6 @@ const NO_PAUSE_DIAGNOSES = new Set([
84
100
  "engine_orphaned",
85
101
  "integrate_isolated_ok",
86
102
  ]);
87
- const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
88
103
  const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
89
104
  "code_review_spawn_failed",
90
105
  "code_review_timeout",
@@ -92,74 +107,6 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
92
107
  "final_review_timeout",
93
108
  ]);
94
109
 
95
- /**
96
- * @param {object|null|undefined} reviewHonorSignal
97
- * @returns {string|null}
98
- */
99
- export function buildReviewHonorHeadlineSuffix(reviewHonorSignal) {
100
- if (!reviewHonorSignal?.kind) return null;
101
- const reviewLabel =
102
- reviewHonorSignal.reviewType === "final" ? "final review" : "code review";
103
- if (reviewHonorSignal.kind === "review.crash_recovered") {
104
- return `recovered ${reviewLabel} crash — prior verdict honored from ${reviewHonorSignal.honorSource ?? "artifact"}`;
105
- }
106
- if (reviewHonorSignal.kind === "review.skipped_fresh_artifact") {
107
- return `skipped redundant ${reviewLabel} — fresh artifact honored`;
108
- }
109
- if (reviewHonorSignal.kind === "review.resumed") {
110
- return `${reviewLabel} resumed after operator retry`;
111
- }
112
- return null;
113
- }
114
-
115
- /**
116
- * @param {object} [ctx]
117
- * @param {string|null} [ctx.exitReason]
118
- * @param {string|null} [ctx.failureClass]
119
- * @param {string|null} [ctx.lastError]
120
- * @param {object[]} [ctx.journalEvents]
121
- * @returns {boolean}
122
- */
123
- export function inferMergeGitignoredFailure(ctx = {}) {
124
- const { exitReason, failureClass, lastError, journalEvents } = ctx;
125
- if (GITIGNORED_MERGE_FAILURE_CLASSES.has(exitReason ?? "")) return true;
126
- if (GITIGNORED_MERGE_FAILURE_CLASSES.has(failureClass ?? "")) return true;
127
-
128
- const haystackParts = [exitReason, failureClass, lastError];
129
- if (Array.isArray(journalEvents)) {
130
- for (const event of journalEvents) {
131
- if (event.type !== "batch.merge_failed" && event.type !== "task.failed") continue;
132
- const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
133
- haystackParts.push(
134
- payload.failureClass,
135
- payload.classification,
136
- payload.error,
137
- payload.output,
138
- );
139
- }
140
- }
141
- const haystack = haystackParts.filter(Boolean).join("\n").toLowerCase();
142
- return (
143
- haystack.includes("gitignored dirty files only") ||
144
- haystack.includes("merge_failed_gitignored") ||
145
- haystack.includes("gitignoreddirtyworktree") ||
146
- (haystack.includes("git add") && haystack.includes("ignored"))
147
- );
148
- }
149
-
150
- /**
151
- * @param {string|null|undefined} taskBranch
152
- * @param {string[]|null|undefined} gitignoredPaths
153
- */
154
- export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
155
- const branchHint = taskBranch ? `git checkout ${taskBranch}` : "git checkout <task-branch>";
156
- const pathHint =
157
- Array.isArray(gitignoredPaths) && gitignoredPaths.length > 0
158
- ? `git rm -r --cached -- ${gitignoredPaths.slice(0, 5).join(" ")}`
159
- : "git rm -r --cached -- <gitignored-paths>";
160
- return `${branchHint} && ${pathHint} && spine batch resume --force`;
161
- }
162
-
163
110
  /**
164
111
  * @param {string} diagnosis
165
112
  * @param {object} [ctx]
@@ -249,10 +196,13 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
249
196
  : "spine batch abort";
250
197
  case "worker_done_missing":
251
198
  return buildWorkerDoneMissingSuggestedCommand(ctx);
252
- case "engine_orphaned":
199
+ case "engine_orphaned": {
200
+ const parentExitCommand = buildEngineOrphanParentExitSuggestedCommand(ctx);
201
+ if (parentExitCommand) return parentExitCommand;
253
202
  return ctx.failedTaskId
254
203
  ? `spine batch retry ${ctx.failedTaskId}`
255
204
  : "spine batch resume --attached";
205
+ }
256
206
  case "needs_merge":
257
207
  return "/spine-resume --force";
258
208
  case "needs_integrate":
@@ -391,10 +341,13 @@ export function buildHeadline(diagnosis, ctx = {}) {
391
341
  : `${batchLabel} lane worker orphaned — retry or abort`;
392
342
  case "worker_done_missing":
393
343
  return buildWorkerDoneMissingHeadline(batchLabel, ctx);
394
- case "engine_orphaned":
344
+ case "engine_orphaned": {
345
+ const parentExitHeadline = buildEngineOrphanParentExitHeadline(batchLabel, ctx);
346
+ if (parentExitHeadline) return parentExitHeadline;
395
347
  return ctx.failedTaskId
396
348
  ? `${batchLabel} engine died mid-run (task ${ctx.failedTaskId} still running) — retry or abort`
397
349
  : `${batchLabel} batch engine died while running — retry or abort`;
350
+ }
398
351
  case "needs_merge":
399
352
  if (ctx.mergeGitignoredFailure) {
400
353
  return `${batchLabel} merge blocked by gitignored paths committed on a lane branch`;
@@ -32,6 +32,10 @@ export const GITIGNORED_ARTIFACT_MARKERS = [
32
32
  "__pycache__/",
33
33
  "/graphify-out/",
34
34
  "graphify-out/",
35
+ "/.review/",
36
+ ".review/",
37
+ "/.spine/runtime/",
38
+ ".spine/runtime/",
35
39
  ];
36
40
 
37
41
  /** Flutter build output dir that can pollute unscoped `flutter analyze` (#78). */
@@ -516,6 +520,12 @@ function gitignoredArtifactRootForPath(filePath) {
516
520
  if (normalized === "graphify-out" || normalized.startsWith("graphify-out/")) {
517
521
  return "graphify-out";
518
522
  }
523
+ if (normalized === ".review" || normalized.startsWith(".review/")) {
524
+ return ".review";
525
+ }
526
+ if (normalized === ".spine/runtime" || normalized.startsWith(".spine/runtime/")) {
527
+ return ".spine/runtime";
528
+ }
519
529
  return null;
520
530
  }
521
531
 
@@ -18,7 +18,7 @@ import {
18
18
  readAliveBatchEnginePid,
19
19
  } from "./batch-state-io.mjs";
20
20
  import { terminateLaneWorkers } from "./worker-host.mjs";
21
- import { removeLaneWorktrees } from "./worktree.mjs";
21
+ import { removeLaneWorktrees, maxLaneNumberFromBatchState } from "./worktree.mjs";
22
22
  import { terminateSupervisorIfRunning } from "./supervisor-spawn.mjs";
23
23
  import { bumpDashboardInvalidateSignal } from "../dashboard/cache-invalidate.mjs";
24
24
 
@@ -117,23 +117,6 @@ function clearCompletedBatchState(batchStatePath, batchId) {
117
117
  clearActiveBatchStateIfMatches(batchStatePath, batchId);
118
118
  }
119
119
 
120
- /**
121
- * @param {unknown} raw
122
- */
123
- function maxLaneNumberFromBatchState(raw) {
124
- const lanes = /** @type {{ lanes?: unknown }} */ (raw)?.lanes;
125
- if (!Array.isArray(lanes) || lanes.length === 0) return 1;
126
- let max = 1;
127
- for (const lane of lanes) {
128
- if (!lane || typeof lane !== "object") continue;
129
- const laneNumber = Number(/** @type {{ laneNumber?: number }} */ (lane).laneNumber);
130
- if (Number.isFinite(laneNumber) && laneNumber > max) {
131
- max = laneNumber;
132
- }
133
- }
134
- return max;
135
- }
136
-
137
120
  /**
138
121
  * @param {object|null|undefined} config
139
122
  */
@@ -23,6 +23,7 @@ import {
23
23
  import { findLatestReviewHonorSignal } from "./review.mjs";
24
24
  import { summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
25
25
  import { inferWorkerDoneMissingFailure } from "./diagnosis-worker-done-missing.mjs";
26
+ import { inferEngineOrphanCause } from "./diagnosis-parent-exit.mjs";
26
27
  import {
27
28
  findStubMarkedSucceededTask,
28
29
  inferStubExitReasonForTask,
@@ -1434,6 +1435,14 @@ export function reconcileBatch(ctx, _lightRetry = false) {
1434
1435
  signals.reviewHonor = reviewHonorSignal;
1435
1436
  }
1436
1437
 
1438
+ const enginePid = readBatchEnginePid(batch.raw);
1439
+ const staleEnginePid =
1440
+ enginePid != null && !isProcessAlive(enginePid);
1441
+ const engineOrphanCause =
1442
+ diagnosis === "engine_orphaned"
1443
+ ? inferEngineOrphanCause({ journalEvents, staleEnginePid })
1444
+ : null;
1445
+
1437
1446
  const output = buildDiagnosisOutput(diagnosis, {
1438
1447
  batchId: batch.batchId,
1439
1448
  phase: batch.phase,
@@ -1467,6 +1476,8 @@ export function reconcileBatch(ctx, _lightRetry = false) {
1467
1476
  macroPhase,
1468
1477
  reviewHonorSignal,
1469
1478
  ...(doneMissingContext ?? {}),
1479
+ engineOrphanCause,
1480
+ staleEnginePid,
1470
1481
  humanBaseSync,
1471
1482
  overlapPaths: humanBaseSync?.overlapPaths ?? [],
1472
1483
  });
@@ -363,6 +363,26 @@ export function findLatestReviewHonorSignal(journalEvents, activeTaskId = null)
363
363
  return null;
364
364
  }
365
365
 
366
+ /**
367
+ * @param {object|null|undefined} reviewHonorSignal
368
+ * @returns {string|null}
369
+ */
370
+ export function buildReviewHonorHeadlineSuffix(reviewHonorSignal) {
371
+ if (!reviewHonorSignal?.kind) return null;
372
+ const reviewLabel =
373
+ reviewHonorSignal.reviewType === "final" ? "final review" : "code review";
374
+ if (reviewHonorSignal.kind === "review.crash_recovered") {
375
+ return `recovered ${reviewLabel} crash — prior verdict honored from ${reviewHonorSignal.honorSource ?? "artifact"}`;
376
+ }
377
+ if (reviewHonorSignal.kind === "review.skipped_fresh_artifact") {
378
+ return `skipped redundant ${reviewLabel} — fresh artifact honored`;
379
+ }
380
+ if (reviewHonorSignal.kind === "review.resumed") {
381
+ return `${reviewLabel} resumed after operator retry`;
382
+ }
383
+ return null;
384
+ }
385
+
366
386
  /**
367
387
  * Latest `.reviews/final-*.md` by mtime, if any.
368
388
  * @param {string} taskFolder