pi-spine 1.1.0 → 1.3.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 (126) hide show
  1. package/README.md +4 -4
  2. package/bin/spine-batch.mjs +160 -53
  3. package/bin/spine-cli/batch.mjs +3 -3
  4. package/bin/spine-cli/lane-logs.mjs +24 -0
  5. package/bin/spine-cli/scenarios.mjs +298 -0
  6. package/bin/spine-cli/verify.mjs +3 -0
  7. package/bin/spine-cli/wait.mjs +30 -0
  8. package/bin/spine-cli/watch.mjs +27 -0
  9. package/bin/spine-issue.mjs +196 -0
  10. package/bin/spine-journal.mjs +1 -0
  11. package/bin/spine-plan.mjs +49 -1
  12. package/bin/spine-run.mjs +30 -0
  13. package/bin/spine-status.mjs +19 -1
  14. package/bin/spine-tasks.mjs +16 -2
  15. package/bin/spine-worker-runner.mjs +144 -12
  16. package/bin/spine.mjs +49 -1
  17. package/package.json +1 -1
  18. package/skills/create-spine-tasks/SKILL.md +7 -2
  19. package/skills/create-spine-tasks/references/contract-template.md +114 -3
  20. package/src/batch/abort.mjs +2 -11
  21. package/src/batch/agent-session-worker.mjs +45 -5
  22. package/src/batch/attached-engine-handoff.mjs +188 -0
  23. package/src/batch/attached-runner.mjs +388 -0
  24. package/src/batch/contract-prelanded.mjs +180 -0
  25. package/src/batch/contract-stub-delivery.mjs +110 -0
  26. package/src/batch/contract-task-start.mjs +204 -0
  27. package/src/batch/contract-verify.mjs +195 -10
  28. package/src/batch/detached-start.mjs +137 -3
  29. package/src/batch/diagnosis-alternatives.mjs +46 -0
  30. package/src/batch/diagnosis-launch-failure.mjs +114 -0
  31. package/src/batch/diagnosis-merge-failure.mjs +79 -0
  32. package/src/batch/diagnosis-primary-failure.mjs +89 -0
  33. package/src/batch/diagnosis-retry-limbo.mjs +34 -0
  34. package/src/batch/diagnosis-stub.mjs +109 -0
  35. package/src/batch/diagnosis-tail-state.mjs +57 -0
  36. package/src/batch/diagnosis-task-done.mjs +110 -0
  37. package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
  38. package/src/batch/diagnosis.mjs +140 -164
  39. package/src/batch/engine-lanes/commit.mjs +145 -0
  40. package/src/batch/engine-lanes/merge.mjs +110 -82
  41. package/src/batch/engine-lanes/queue.mjs +4 -1
  42. package/src/batch/engine-lanes/review.mjs +67 -87
  43. package/src/batch/engine-lanes/watch.mjs +29 -0
  44. package/src/batch/engine-lanes.mjs +21 -78
  45. package/src/batch/engine-scope.mjs +11 -1
  46. package/src/batch/engine.mjs +125 -24
  47. package/src/batch/evidence.mjs +78 -15
  48. package/src/batch/gate.mjs +43 -14
  49. package/src/batch/git-helpers.mjs +96 -0
  50. package/src/batch/heartbeat.mjs +75 -9
  51. package/src/batch/integrate-assert.mjs +69 -0
  52. package/src/batch/integrate-worktree.mjs +354 -0
  53. package/src/batch/integrate.mjs +193 -102
  54. package/src/batch/journal-rebuild.mjs +48 -2
  55. package/src/batch/journal.mjs +66 -0
  56. package/src/batch/lane-commit.mjs +90 -5
  57. package/src/batch/lane-dirty-check.mjs +437 -0
  58. package/src/batch/lifecycle.mjs +130 -3
  59. package/src/batch/limbo-detect.mjs +34 -0
  60. package/src/batch/macro-phase.mjs +302 -0
  61. package/src/batch/merge/adoption-doc-merge.mjs +93 -10
  62. package/src/batch/merge/wave-merge-state.mjs +3 -0
  63. package/src/batch/metrics.mjs +76 -5
  64. package/src/batch/orphan-detect.mjs +74 -0
  65. package/src/batch/pause.mjs +234 -0
  66. package/src/batch/post-merge-limbo.mjs +259 -28
  67. package/src/batch/reconcile.mjs +508 -63
  68. package/src/batch/resume-common.mjs +32 -1
  69. package/src/batch/resume-lane-reviews.mjs +16 -0
  70. package/src/batch/resume-multi-lanes.mjs +67 -1
  71. package/src/batch/resume-multi-validate.mjs +67 -6
  72. package/src/batch/resume-multi.mjs +11 -4
  73. package/src/batch/resume.mjs +59 -45
  74. package/src/batch/retry.mjs +97 -15
  75. package/src/batch/review-spawn.mjs +8 -2
  76. package/src/batch/rules-manifest-drift.mjs +198 -0
  77. package/src/batch/salvage.mjs +2 -1
  78. package/src/batch/sequence-state.mjs +290 -0
  79. package/src/batch/sequence.mjs +516 -0
  80. package/src/batch/state.mjs +34 -3
  81. package/src/batch/status-json.mjs +67 -0
  82. package/src/batch/task-stall-budget.mjs +22 -10
  83. package/src/batch/worker-host.mjs +96 -7
  84. package/src/batch/worker-output.mjs +196 -3
  85. package/src/cli/issue-draft.mjs +180 -0
  86. package/src/cli/journal-follow.mjs +239 -0
  87. package/src/cli/lane-logs.mjs +291 -0
  88. package/src/cli/sequence.mjs +121 -0
  89. package/src/cli/settings-set.mjs +35 -24
  90. package/src/cli/wait.mjs +187 -0
  91. package/src/cli/watch.mjs +160 -0
  92. package/src/config/agent-model-resolve.mjs +48 -0
  93. package/src/config/cursor-rules/discover.mjs +3 -21
  94. package/src/config/defaults.mjs +7 -1
  95. package/src/config/model-id.mjs +103 -0
  96. package/src/config/settings-fields.mjs +48 -0
  97. package/src/config/spine-init-constants.mjs +2 -0
  98. package/src/config/spine-preflight-lib.mjs +494 -17
  99. package/src/dashboard/lane-throughput.mjs +351 -0
  100. package/src/dashboard/public/dashboard.css +25 -1
  101. package/src/dashboard/public/dashboard.js +234 -18
  102. package/src/dashboard/public/index.html +14 -2
  103. package/src/dashboard/running-tail-state.mjs +31 -0
  104. package/src/dashboard/server.mjs +8 -0
  105. package/src/dashboard/snapshot.mjs +472 -26
  106. package/src/dashboard/view.mjs +282 -19
  107. package/src/doctor/agent-model-inherit.mjs +61 -6
  108. package/src/doctor/agent-models.mjs +53 -0
  109. package/src/doctor/batch-size-guidance.mjs +30 -2
  110. package/src/doctor/pi-extension-conflict.mjs +169 -0
  111. package/src/doctor/run-doctor-checks.mjs +32 -1
  112. package/src/doctor/sequence-safety.mjs +57 -0
  113. package/src/doctor/stale-worktrees.mjs +102 -0
  114. package/src/fixtures/scenario-registry.mjs +194 -0
  115. package/src/fs/atomic-write.mjs +49 -0
  116. package/src/planner/file-scope.mjs +246 -0
  117. package/src/planner/format-plan.mjs +9 -7
  118. package/src/planner/index.mjs +6 -2
  119. package/src/planner/scope.mjs +5 -1
  120. package/src/planner/wave-scope.mjs +136 -0
  121. package/src/planner/waves.mjs +133 -0
  122. package/src/tasks/packet/index.mjs +1 -0
  123. package/src/tasks/packet/parse-prompt.mjs +73 -2
  124. package/src/tasks/packet/validate-contract.mjs +108 -0
  125. package/src/tasks/packet/validate-prompt.mjs +124 -0
  126. package/templates/spine-config.json +8 -1
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Worker exited without `.DONE` diagnosis helpers (SP-313 / issue #18).
3
+ */
4
+
5
+ /** Worker exited cleanly but never wrote `.DONE`. */
6
+ export const WORKER_DONE_MISSING_OUTPUT_MARKERS = [
7
+ "pi exited but .DONE was not created",
8
+ "agent session finished but .DONE was not created",
9
+ ];
10
+
11
+ /**
12
+ * @param {string|null|undefined} outputText
13
+ * @returns {boolean}
14
+ */
15
+ export function outputIndicatesWorkerDoneMissing(outputText) {
16
+ if (!outputText || !String(outputText).trim()) return false;
17
+ const normalized = String(outputText).toLowerCase();
18
+ return WORKER_DONE_MISSING_OUTPUT_MARKERS.some((marker) =>
19
+ normalized.includes(marker.toLowerCase()),
20
+ );
21
+ }
22
+
23
+ /**
24
+ * @param {object} [ctx]
25
+ * @param {object[]} [ctx.journalEvents]
26
+ * @param {string|null} [ctx.failedTaskId]
27
+ * @returns {object|null}
28
+ */
29
+ export function inferWorkerDoneMissingFailure(ctx = {}) {
30
+ const { journalEvents, failedTaskId } = ctx;
31
+ if (!Array.isArray(journalEvents) || journalEvents.length === 0) return null;
32
+
33
+ for (let index = journalEvents.length - 1; index >= 0; index -= 1) {
34
+ const event = journalEvents[index];
35
+ if (event.type !== "task.failed") continue;
36
+ const eventTaskId = event.taskId ?? event.payload?.taskId;
37
+ if (failedTaskId && eventTaskId && eventTaskId !== failedTaskId) continue;
38
+
39
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
40
+ if (payload.doneFound === true) continue;
41
+
42
+ const outputText = [payload.output, payload.error].filter(Boolean).join("\n");
43
+ if (!outputIndicatesWorkerDoneMissing(outputText)) continue;
44
+
45
+ const changedFileCount = Number(payload.changedFileCount);
46
+
47
+ return {
48
+ taskId: eventTaskId ?? failedTaskId ?? null,
49
+ output: outputText || null,
50
+ workerOutputLogRef:
51
+ typeof payload.workerOutputLogRef === "string" ? payload.workerOutputLogRef : null,
52
+ workerOutputLogPath:
53
+ typeof payload.workerOutputLogPath === "string" ? payload.workerOutputLogPath : null,
54
+ changedFileCount: Number.isFinite(changedFileCount) ? changedFileCount : null,
55
+ exitCode: payload.exitCode ?? null,
56
+ doneFound: payload.doneFound === false,
57
+ };
58
+ }
59
+
60
+ return null;
61
+ }
62
+
63
+ /**
64
+ * @param {string} batchLabel
65
+ * @param {object} ctx
66
+ */
67
+ export function buildWorkerDoneMissingHeadline(batchLabel, ctx = {}) {
68
+ const taskLabel = ctx.failedTaskId ? `task ${ctx.failedTaskId}` : "worker";
69
+ const fileHint =
70
+ ctx.changedFileCount === 0
71
+ ? " (0 scoped files)"
72
+ : ctx.changedFileCount != null
73
+ ? ` (${ctx.changedFileCount} scoped file(s))`
74
+ : "";
75
+ const logRef = ctx.workerOutputLogRef ?? ctx.workerOutputLogPath ?? null;
76
+ const logHint = logRef ? ` — see ${logRef}` : "";
77
+ const tail = ctx.workerOutputTail?.trim();
78
+ const tailHint = tail
79
+ ? `: ${tail.split("\n").filter(Boolean).slice(-3).join(" | ")}`
80
+ : ctx.workerOutputSnippet
81
+ ? `: ${ctx.workerOutputSnippet}`
82
+ : "";
83
+ return `${batchLabel} ${taskLabel} exited without .DONE${fileHint}${logHint}${tailHint}`;
84
+ }
85
+
86
+ /** @param {object} ctx */
87
+ export function buildWorkerDoneMissingSuggestedCommand(ctx = {}) {
88
+ return ctx.failedTaskId ? `spine batch retry ${ctx.failedTaskId}` : "spine status --diagnose";
89
+ }
90
+
91
+ /** @param {object} ctx @param {string[]} common */
92
+ export function buildWorkerDoneMissingAlternatives(ctx = {}, common = []) {
93
+ return ctx.failedTaskId
94
+ ? [`spine batch retry ${ctx.failedTaskId}`, "spine status --diagnose", ...common]
95
+ : common;
96
+ }
@@ -1,8 +1,41 @@
1
1
  /**
2
2
  * FR-BATCH-13 diagnosis taxonomy and operator messaging (§18.3).
3
3
  */
4
-
4
+ import {
5
+ buildWorkerDoneMissingHeadline,
6
+ buildWorkerDoneMissingSuggestedCommand,
7
+ } from "./diagnosis-worker-done-missing.mjs";
8
+ import {
9
+ buildFailedPhasePendingOnlyHeadline,
10
+ buildFailedPhasePendingOnlySuggestedCommand,
11
+ isFailedPhasePendingOnlyLimbo,
12
+ } from "./diagnosis-retry-limbo.mjs";
13
+ import { buildAlternatives } from "./diagnosis-alternatives.mjs";
14
+ export { buildAlternatives } from "./diagnosis-alternatives.mjs";
15
+ import {
16
+ buildMergeFailureHeadline,
17
+ summarizeMergeFailures,
18
+ } from "./diagnosis-merge-failure.mjs";
19
+ export { buildMergeFailureHeadline, summarizeMergeFailures } from "./diagnosis-merge-failure.mjs";
20
+ import { buildRunningTailHeadline } from "./diagnosis-tail-state.mjs";
21
+ export { buildRunningTailHeadline, isRunningWithoutActiveWorkers } from "./diagnosis-tail-state.mjs";
22
+ import {
23
+ buildStubFailureHeadline,
24
+ buildStubFailureSuggestedCommand,
25
+ STUB_EXIT_REASONS,
26
+ } from "./diagnosis-stub.mjs";
5
27
  /** @typedef {import("./reconcile.mjs").ReconciliationResult} ReconciliationResult */
28
+ export {
29
+ classifyTaskDoneSemantics,
30
+ resolveTaskFolderPath,
31
+ resolveTaskLaneWorktreePath,
32
+ TASK_DONE_FLAG_FIELD_NAMES,
33
+ } from "./diagnosis-task-done.mjs";
34
+ import {
35
+ buildPrimaryFailureHeadline,
36
+ buildPrimaryFailureSuggestedCommand,
37
+ } from "./diagnosis-primary-failure.mjs";
38
+ export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
6
39
 
7
40
  export const DIAGNOSIS_TAXONOMY = [
8
41
  "running",
@@ -10,6 +43,7 @@ export const DIAGNOSIS_TAXONOMY = [
10
43
  "needs_retry",
11
44
  "state_drift",
12
45
  "worker_orphaned",
46
+ "worker_done_missing",
13
47
  "engine_orphaned",
14
48
  "needs_merge",
15
49
  "needs_integrate",
@@ -21,15 +55,8 @@ export const DIAGNOSIS_TAXONOMY = [
21
55
  "aborted",
22
56
  ];
23
57
 
24
- const NO_PAUSE_DIAGNOSES = new Set([
25
- "limbo_stale",
26
- "completed_manual",
27
- "needs_integrate",
28
- "engine_orphaned",
29
- ]);
30
-
31
- const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
32
-
58
+ const NO_PAUSE_DIAGNOSES = new Set(["limbo_stale", "completed_manual", "needs_integrate", "engine_orphaned"]);
59
+ const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
33
60
  const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
34
61
  "code_review_spawn_failed",
35
62
  "code_review_timeout",
@@ -38,120 +65,51 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
38
65
  ]);
39
66
 
40
67
  /**
41
- * @param {object[]} [journalEvents]
42
- * @param {string|null} [taskId]
43
- * @returns {object|null}
44
- */
45
- function findLatestTaskFailedEvent(journalEvents, taskId) {
46
- if (!Array.isArray(journalEvents) || journalEvents.length === 0) return null;
47
- for (let index = journalEvents.length - 1; index >= 0; index -= 1) {
48
- const event = journalEvents[index];
49
- if (event.type !== "task.failed") continue;
50
- const eventTaskId = event.taskId ?? event.payload?.taskId;
51
- if (taskId && eventTaskId && eventTaskId !== taskId) continue;
52
- return event;
53
- }
54
- return null;
55
- }
56
-
57
- /**
58
- * @param {string} haystack
59
- * @param {object} [hints]
60
- * @param {boolean} [hints.launchingPhase]
61
- * @returns {string|null}
62
- */
63
- function classifyLaunchFailureHaystack(haystack, hints = {}) {
64
- const normalized = haystack.toLowerCase();
65
-
66
- if (hints.launchingPhase) {
67
- if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
68
- return "pi_spine_root";
69
- }
70
- return "launch_failed";
71
- }
72
-
73
- if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
74
- return "pi_spine_root";
75
- }
76
-
77
- if (
78
- normalized.includes("not a git repository") ||
79
- normalized.includes("worktree") ||
80
- normalized.includes("worktreeunhealthy")
81
- ) {
82
- return "worktree_unhealthy";
83
- }
84
-
85
- return null;
86
- }
87
-
88
- /**
89
- * @param {object|null} failedEvent
90
- * @param {string|null} exitReason
91
- * @returns {string|null}
92
- */
93
- function classifyLaunchFailureFromEvent(failedEvent, exitReason) {
94
- const payload = failedEvent?.payload && typeof failedEvent.payload === "object" ? failedEvent.payload : {};
95
- const haystack = [
96
- exitReason,
97
- payload.classification,
98
- payload.output,
99
- payload.exitReason,
100
- ].filter(Boolean).join("\n");
101
-
102
- return classifyLaunchFailureHaystack(haystack, {
103
- launchingPhase:
104
- payload.workerPhase === "launching" || payload.classification === "launch_failed",
105
- });
106
- }
107
-
108
- /**
109
- * @param {string|null|undefined} outputText
110
- * @returns {string|null}
111
- */
112
- export function inferLaunchFailureFromWorkerOutputTail(outputText) {
113
- if (!outputText || !String(outputText).trim()) return null;
114
- return classifyLaunchFailureHaystack(String(outputText));
115
- }
116
-
117
- /**
118
- * @param {object} ctx
68
+ * @param {object} [ctx]
119
69
  * @param {string|null} [ctx.exitReason]
120
- * @param {string|null} [ctx.launchFailureKind]
70
+ * @param {string|null} [ctx.failureClass]
71
+ * @param {string|null} [ctx.lastError]
121
72
  * @param {object[]} [ctx.journalEvents]
122
- * @param {string|null} [ctx.failedTaskId]
123
- * @returns {string|null}
73
+ * @returns {boolean}
124
74
  */
125
- export function inferLaunchFailureKind(ctx = {}) {
126
- const { exitReason, journalEvents, failedTaskId } = ctx;
127
- if (exitReason === "launch_failed" || exitReason === "worker_launch_failed") {
128
- return "launch_failed";
129
- }
75
+ export function inferMergeGitignoredFailure(ctx = {}) {
76
+ const { exitReason, failureClass, lastError, journalEvents } = ctx;
77
+ if (GITIGNORED_MERGE_FAILURE_CLASSES.has(exitReason ?? "")) return true;
78
+ if (GITIGNORED_MERGE_FAILURE_CLASSES.has(failureClass ?? "")) return true;
130
79
 
131
- const kinds = [];
80
+ const haystackParts = [exitReason, failureClass, lastError];
132
81
  if (Array.isArray(journalEvents)) {
133
- const taskFailedEvents = journalEvents.filter((event) => event.type === "task.failed");
134
- const prioritized = failedTaskId
135
- ? [
136
- ...taskFailedEvents.filter(
137
- (event) => (event.taskId ?? event.payload?.taskId) === failedTaskId,
138
- ),
139
- ...taskFailedEvents.filter(
140
- (event) => (event.taskId ?? event.payload?.taskId) !== failedTaskId,
141
- ),
142
- ]
143
- : taskFailedEvents;
144
-
145
- for (const failedEvent of prioritized) {
146
- const kind = classifyLaunchFailureFromEvent(failedEvent, exitReason);
147
- if (kind) kinds.push(kind);
82
+ for (const event of journalEvents) {
83
+ if (event.type !== "batch.merge_failed" && event.type !== "task.failed") continue;
84
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
85
+ haystackParts.push(
86
+ payload.failureClass,
87
+ payload.classification,
88
+ payload.error,
89
+ payload.output,
90
+ );
148
91
  }
149
92
  }
93
+ const haystack = haystackParts.filter(Boolean).join("\n").toLowerCase();
94
+ return (
95
+ haystack.includes("gitignored dirty files only") ||
96
+ haystack.includes("merge_failed_gitignored") ||
97
+ haystack.includes("gitignoreddirtyworktree") ||
98
+ (haystack.includes("git add") && haystack.includes("ignored"))
99
+ );
100
+ }
150
101
 
151
- if (kinds.includes("pi_spine_root")) return "pi_spine_root";
152
- if (kinds.includes("launch_failed")) return "launch_failed";
153
- if (kinds.includes("worktree_unhealthy")) return "worktree_unhealthy";
154
- return null;
102
+ /**
103
+ * @param {string|null|undefined} taskBranch
104
+ * @param {string[]|null|undefined} gitignoredPaths
105
+ */
106
+ export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
107
+ const branchHint = taskBranch ? `git checkout ${taskBranch}` : "git checkout <task-branch>";
108
+ const pathHint =
109
+ Array.isArray(gitignoredPaths) && gitignoredPaths.length > 0
110
+ ? `git rm -r --cached -- ${gitignoredPaths.slice(0, 5).join(" ")}`
111
+ : "git rm -r --cached -- <gitignored-paths>";
112
+ return `${branchHint} && ${pathHint} && spine batch resume --force`;
155
113
  }
156
114
 
157
115
  /**
@@ -162,8 +120,22 @@ export function inferLaunchFailureKind(ctx = {}) {
162
120
  * @param {string|null} [ctx.salvageRetryCommand]
163
121
  * @param {string|null} [ctx.exitReason]
164
122
  * @param {string|null} [ctx.launchFailureKind]
123
+ * @param {boolean} [ctx.mergeGitignoredFailure]
124
+ * @param {boolean} [ctx.mergeFailed]
125
+ * @param {string|null} [ctx.taskBranch]
126
+ * @param {string[]|null} [ctx.gitignoredPaths]
165
127
  */
166
128
  export function buildSuggestedCommand(diagnosis, ctx = {}) {
129
+ if (ctx.mergeGitignoredFailure) {
130
+ return buildGitignoredMergeRepairCommand(ctx.taskBranch, ctx.gitignoredPaths);
131
+ }
132
+ if (ctx.mergeFailed && (diagnosis === "failed" || diagnosis === "needs_retry")) {
133
+ return "spine batch resume --force";
134
+ }
135
+ if (ctx.phase === "merge_blocked") {
136
+ return "spine batch resume --force";
137
+ }
138
+
167
139
  switch (diagnosis) {
168
140
  case "limbo_stale":
169
141
  case "completed_manual":
@@ -171,6 +143,13 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
171
143
  case "state_drift":
172
144
  return "spine batch retry --force";
173
145
  case "needs_retry":
146
+ if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
147
+ return buildStubFailureSuggestedCommand(ctx);
148
+ }
149
+ {
150
+ const primaryCommand = buildPrimaryFailureSuggestedCommand(ctx);
151
+ if (primaryCommand) return primaryCommand;
152
+ }
174
153
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
175
154
  return "spine doctor";
176
155
  }
@@ -178,6 +157,9 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
178
157
  return "spine doctor";
179
158
  }
180
159
  if (ctx.salvageRetryCommand) return ctx.salvageRetryCommand;
160
+ if (isFailedPhasePendingOnlyLimbo(ctx)) {
161
+ return buildFailedPhasePendingOnlySuggestedCommand(ctx);
162
+ }
181
163
  return ctx.failedTaskId
182
164
  ? `spine batch retry ${ctx.failedTaskId}`
183
165
  : "spine status --diagnose";
@@ -206,8 +188,12 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
206
188
  return ctx.failedTaskId
207
189
  ? `spine batch retry ${ctx.failedTaskId}`
208
190
  : "spine batch abort";
191
+ case "worker_done_missing":
192
+ return buildWorkerDoneMissingSuggestedCommand(ctx);
209
193
  case "engine_orphaned":
210
- return "spine batch resume --attached";
194
+ return ctx.failedTaskId
195
+ ? `spine batch retry ${ctx.failedTaskId}`
196
+ : "spine batch resume --attached";
211
197
  case "needs_merge":
212
198
  return "/spine-resume --force";
213
199
  case "needs_integrate":
@@ -218,7 +204,7 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
218
204
  if (ctx.stalePathSpine) {
219
205
  return "node bin/spine.mjs batch resume --attached";
220
206
  }
221
- return "spine batch resume";
207
+ return "spine batch resume --force";
222
208
  }
223
209
  return "spine integrate";
224
210
  case "needs_replan": {
@@ -254,27 +240,44 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
254
240
  * @param {number} [ctx.salvageChangedFileCount]
255
241
  * @param {string|null} [ctx.exitReason]
256
242
  * @param {string|null} [ctx.launchFailureKind]
243
+ * @param {boolean} [ctx.mergeGitignoredFailure]
244
+ * @param {boolean} [ctx.mergeFailed]
245
+ * @param {number|null} [ctx.failedWaveIndex]
246
+ * @param {number|null} [ctx.failedLane]
247
+ * @param {string|null} [ctx.lastError]
248
+ * @param {number} [ctx.succeededTasks]
249
+ * @param {number} [ctx.totalTasks]
257
250
  */
258
251
  export function buildHeadline(diagnosis, ctx = {}) {
259
252
  const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
260
253
 
254
+ if (ctx.mergeGitignoredFailure) {
255
+ return `${batchLabel} merge blocked by gitignored paths on a lane branch — drop cached ignored files, then resume`;
256
+ }
257
+
258
+ if (ctx.mergeFailed && (diagnosis === "failed" || diagnosis === "needs_retry")) {
259
+ return buildMergeFailureHeadline(batchLabel, ctx);
260
+ }
261
+
261
262
  switch (diagnosis) {
262
263
  case "limbo_stale":
263
264
  return `${batchLabel} finished but state is stale — dismiss to clear`;
264
265
  case "completed_manual":
265
266
  return `${batchLabel} work is on main but batch record is still active`;
266
267
  case "needs_retry":
268
+ if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
269
+ return buildStubFailureHeadline(batchLabel, ctx);
270
+ }
271
+ {
272
+ const primaryHeadline = buildPrimaryFailureHeadline(batchLabel, ctx);
273
+ if (primaryHeadline) return primaryHeadline;
274
+ }
267
275
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
268
276
  return `${batchLabel} failed at worker launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
269
277
  }
270
278
  if (ctx.launchFailureKind === "worktree_unhealthy") {
271
279
  return `${batchLabel} failed at worker launch — repair lane worktree git, then retry`;
272
280
  }
273
- if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
274
- return ctx.failedTaskId
275
- ? `${batchLabel} task ${ctx.failedTaskId} completed but lane commit failed`
276
- : `${batchLabel} completed but lane commit failed`;
277
- }
278
281
  if (REVIEW_SPAWN_FAILURE_EXIT_REASONS.has(ctx.exitReason ?? "")) {
279
282
  const reviewKind =
280
283
  ctx.exitReason === "final_review_spawn_failed" ||
@@ -288,6 +291,9 @@ export function buildHeadline(diagnosis, ctx = {}) {
288
291
  if (ctx.salvageChangedFileCount > 0 && ctx.failedTaskId) {
289
292
  return `${batchLabel} failed (${ctx.failedTaskId}): ${ctx.salvageChangedFileCount} uncommitted file(s) in scope`;
290
293
  }
294
+ if (isFailedPhasePendingOnlyLimbo(ctx)) {
295
+ return buildFailedPhasePendingOnlyHeadline(batchLabel, ctx);
296
+ }
291
297
  return ctx.failedTaskId
292
298
  ? `${batchLabel} worker died while task ${ctx.failedTaskId} was running — retry or abort`
293
299
  : `${batchLabel} has failed tasks — retry before resume`;
@@ -320,11 +326,16 @@ export function buildHeadline(diagnosis, ctx = {}) {
320
326
  return ctx.failedTaskId
321
327
  ? `${batchLabel} lane worker orphaned while task ${ctx.failedTaskId} was running — retry or abort`
322
328
  : `${batchLabel} lane worker orphaned — retry or abort`;
329
+ case "worker_done_missing":
330
+ return buildWorkerDoneMissingHeadline(batchLabel, ctx);
323
331
  case "engine_orphaned":
324
332
  return ctx.failedTaskId
325
333
  ? `${batchLabel} engine died mid-run (task ${ctx.failedTaskId} still running) — retry or abort`
326
334
  : `${batchLabel} batch engine died while running — retry or abort`;
327
335
  case "needs_merge":
336
+ if (ctx.mergeGitignoredFailure) {
337
+ return `${batchLabel} merge blocked by gitignored paths committed on a lane branch`;
338
+ }
328
339
  return `${batchLabel} tasks done — lane merges pending`;
329
340
  case "needs_integrate":
330
341
  if (ctx.postMergeLimbo && ctx.phase === "running") {
@@ -341,8 +352,13 @@ export function buildHeadline(diagnosis, ctx = {}) {
341
352
  return ctx.failedTaskId
342
353
  ? `Task ${ctx.failedTaskId} needs replan — edit PROMPT.md before retry`
343
354
  : `${batchLabel} has tasks needing replan — edit PROMPT.md before retry`;
344
- case "running":
355
+ case "running": {
356
+ const tailHeadline = buildRunningTailHeadline(batchLabel, ctx);
357
+ if (tailHeadline) {
358
+ return tailHeadline;
359
+ }
345
360
  return `${batchLabel} is running`;
361
+ }
346
362
  case "paused": {
347
363
  const pending = ctx.pendingTaskCount ?? 0;
348
364
  if (pending > 1) {
@@ -361,46 +377,6 @@ export function buildHeadline(diagnosis, ctx = {}) {
361
377
  }
362
378
  }
363
379
 
364
- /**
365
- * @param {string} diagnosis
366
- * @param {object} [ctx]
367
- * @param {string|null} [ctx.failedTaskId]
368
- */
369
- export function buildAlternatives(diagnosis, ctx = {}) {
370
- const common = ["spine status --diagnose"];
371
-
372
- switch (diagnosis) {
373
- case "limbo_stale":
374
- return ["spine batch complete --detect-manual-merge", ...common];
375
- case "completed_manual":
376
- return ["spine batch complete --detect-manual-merge", "spine batch dismiss", ...common];
377
- case "needs_retry":
378
- return ["spine batch abort", "/spine-skip-task", "/spine-resume --force", ...common];
379
- case "worker_orphaned":
380
- return ["spine batch abort", "spine batch resume --force", ...common];
381
- case "engine_orphaned":
382
- return ctx.failedTaskId
383
- ? [`spine batch retry ${ctx.failedTaskId}`, "spine batch abort", ...common]
384
- : ["spine batch abort", "spine batch resume --force", ...common];
385
- case "needs_merge":
386
- return ["/spine-status --diagnose", ...common];
387
- case "needs_integrate":
388
- return ["/spine-integrate", "/spine-gate", ...common];
389
- case "needs_replan":
390
- return ctx.failedTaskId
391
- ? [`spine batch skip ${ctx.failedTaskId}`, "spine handoff", ...common]
392
- : ["spine handoff", ...common];
393
- case "running":
394
- return ["/spine-pause", "/spine-abort", ...common];
395
- case "paused":
396
- return ["spine batch resume --force", "spine status --diagnose", ...common];
397
- case "failed":
398
- return ["/spine-retry-task", ...common];
399
- default:
400
- return common;
401
- }
402
- }
403
-
404
380
  /**
405
381
  * @param {string} diagnosis
406
382
  */
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Lane commit and post-commit dirty validation (SP-427 / #73).
3
+ */
4
+
5
+ import { appendJournalEvent } from "../journal.mjs";
6
+ import { commitLaneWorktree, gitPorcelain } from "../lane-commit.mjs";
7
+ import {
8
+ resolvePostLaneCommitPorcelain,
9
+ sanitizeOutOfScopeCoverageBeforeLaneCommit,
10
+ } from "../lane-dirty-check.mjs";
11
+ import {
12
+ recomputeTaskCounters,
13
+ saveSpineBatchState,
14
+ updateSegmentForTask,
15
+ } from "../state.mjs";
16
+ import { recordLaneTaskMetric } from "./queue.mjs";
17
+
18
+ const DIRTY_AFTER_COMMIT_MESSAGE =
19
+ "Lane worktree still has uncommitted changes after auto-commit — commit manually or fix worker output";
20
+
21
+ /**
22
+ * @param {object} params
23
+ * @param {string} params.worktreePath
24
+ * @param {string} params.taskBranch
25
+ * @param {string} params.taskId
26
+ * @param {string} params.batchId
27
+ * @param {string} params.taskFolder
28
+ * @param {string} [params.projectRoot]
29
+ * @param {string[]} [params.fileScopePaths]
30
+ * @param {string[]} [params.ignorePatterns]
31
+ * @param {object} params.task
32
+ * @param {object} params.lane
33
+ * @param {number} params.laneNumber
34
+ * @param {string} params.laneCorrelationId
35
+ * @param {object} params.state
36
+ * @param {object} params.config
37
+ * @returns {{ ok: true, laneCommit: object } | { ok: false, error: string, output?: string }}
38
+ */
39
+ export function commitLaneAndValidateWorktree({
40
+ worktreePath,
41
+ taskBranch,
42
+ taskId,
43
+ batchId,
44
+ taskFolder,
45
+ projectRoot,
46
+ fileScopePaths,
47
+ ignorePatterns = [],
48
+ task,
49
+ lane,
50
+ laneNumber,
51
+ laneCorrelationId,
52
+ state,
53
+ config,
54
+ }) {
55
+ const preCommitPorcelain = gitPorcelain(worktreePath);
56
+ sanitizeOutOfScopeCoverageBeforeLaneCommit(worktreePath, fileScopePaths, {
57
+ projectRoot,
58
+ porcelain: preCommitPorcelain,
59
+ });
60
+
61
+ const laneCommit = commitLaneWorktree({
62
+ worktreePath,
63
+ taskBranch,
64
+ taskId,
65
+ batchId,
66
+ taskFolder,
67
+ projectRoot,
68
+ });
69
+ if (!laneCommit.ok) {
70
+ task.status = "failed";
71
+ task.endedAt = Date.now();
72
+ task.exitReason = laneCommit.failureClass ?? "lane_commit_failed";
73
+ updateSegmentForTask(state, taskId, "failed");
74
+ recomputeTaskCounters(state);
75
+ saveSpineBatchState(projectRoot, state);
76
+ appendJournalEvent(projectRoot, batchId, "task.failed", {
77
+ taskId,
78
+ laneNumber,
79
+ laneId: lane.laneId,
80
+ correlationId: laneCorrelationId,
81
+ classification: laneCommit.failureClass ?? "lane_commit_failed",
82
+ exitCode: 1,
83
+ output: laneCommit.error,
84
+ gitignoredPaths: laneCommit.gitignoredPaths ?? null,
85
+ });
86
+ recordLaneTaskMetric({
87
+ projectRoot,
88
+ batchId,
89
+ task,
90
+ config,
91
+ taskFolder,
92
+ });
93
+ return {
94
+ ok: false,
95
+ error: "lane_commit_failed",
96
+ output: laneCommit.error,
97
+ };
98
+ }
99
+
100
+ if (laneCommit.committed) {
101
+ appendJournalEvent(projectRoot, batchId, "lane.committed", {
102
+ taskId,
103
+ laneNumber,
104
+ commitSha: laneCommit.commitSha,
105
+ });
106
+ }
107
+
108
+ const remainingDirty = resolvePostLaneCommitPorcelain(worktreePath, {
109
+ fileScopePaths,
110
+ ignorePatterns,
111
+ projectRoot,
112
+ porcelain: gitPorcelain(worktreePath),
113
+ });
114
+ if (remainingDirty) {
115
+ task.status = "failed";
116
+ task.endedAt = Date.now();
117
+ task.exitReason = "DirtyWorktree";
118
+ updateSegmentForTask(state, taskId, "failed");
119
+ recomputeTaskCounters(state);
120
+ saveSpineBatchState(projectRoot, state);
121
+ appendJournalEvent(projectRoot, batchId, "task.failed", {
122
+ taskId,
123
+ laneNumber,
124
+ laneId: lane.laneId,
125
+ correlationId: laneCorrelationId,
126
+ classification: "DirtyWorktree",
127
+ exitCode: 1,
128
+ output: DIRTY_AFTER_COMMIT_MESSAGE,
129
+ });
130
+ recordLaneTaskMetric({
131
+ projectRoot,
132
+ batchId,
133
+ task,
134
+ config,
135
+ taskFolder,
136
+ });
137
+ return {
138
+ ok: false,
139
+ error: "dirty_after_lane_commit",
140
+ output: DIRTY_AFTER_COMMIT_MESSAGE,
141
+ };
142
+ }
143
+
144
+ return { ok: true, laneCommit };
145
+ }