pi-spine 1.0.2 → 1.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 (129) hide show
  1. package/README.md +61 -489
  2. package/bin/get-version.mjs +1 -13
  3. package/bin/spine-batch.mjs +162 -51
  4. package/bin/spine-cli/batch.mjs +3 -3
  5. package/bin/spine-cli/lane-logs.mjs +24 -0
  6. package/bin/spine-cli/scenarios.mjs +298 -0
  7. package/bin/spine-cli/wait.mjs +30 -0
  8. package/bin/spine-cli/watch.mjs +27 -0
  9. package/bin/spine-config.mjs +1 -212
  10. package/bin/spine-doctor.mjs +2 -418
  11. package/bin/spine-init.mjs +1 -398
  12. package/bin/spine-issue.mjs +196 -0
  13. package/bin/spine-journal.mjs +1 -0
  14. package/bin/spine-preflight.mjs +1 -700
  15. package/bin/spine-review-step.mjs +6 -4
  16. package/bin/spine-run.mjs +30 -0
  17. package/bin/spine-status.mjs +19 -1
  18. package/bin/spine-tasks.mjs +112 -13
  19. package/bin/spine-worker-runner.mjs +24 -14
  20. package/bin/spine.mjs +52 -2
  21. package/extensions/spine/worker-tools.ts +14 -12
  22. package/package.json +5 -2
  23. package/skills/create-spine-tasks/SKILL.md +135 -6
  24. package/skills/create-spine-tasks/references/clarify-template.md +73 -0
  25. package/skills/create-spine-tasks/references/contract-template.md +19 -0
  26. package/skills/create-spine-tasks/references/prompt-template.md +2 -0
  27. package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
  28. package/src/batch/abort.mjs +3 -12
  29. package/src/batch/agent-session-worker.mjs +45 -5
  30. package/src/batch/attached-engine-handoff.mjs +188 -0
  31. package/src/batch/attached-runner.mjs +312 -0
  32. package/src/batch/contract-prelanded.mjs +180 -0
  33. package/src/batch/contract-verify.mjs +140 -2
  34. package/src/batch/detached-start.mjs +105 -7
  35. package/src/batch/diagnosis-alternatives.mjs +46 -0
  36. package/src/batch/diagnosis-merge-failure.mjs +79 -0
  37. package/src/batch/diagnosis-retry-limbo.mjs +34 -0
  38. package/src/batch/diagnosis-stub.mjs +109 -0
  39. package/src/batch/diagnosis-task-done.mjs +110 -0
  40. package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
  41. package/src/batch/diagnosis.mjs +174 -62
  42. package/src/batch/engine-lanes/merge.mjs +168 -77
  43. package/src/batch/engine-lanes/queue.mjs +4 -1
  44. package/src/batch/engine-lanes/review.mjs +32 -74
  45. package/src/batch/engine-lanes/watch.mjs +29 -0
  46. package/src/batch/engine-lanes.mjs +1 -0
  47. package/src/batch/engine-scope.mjs +42 -5
  48. package/src/batch/engine.mjs +115 -68
  49. package/src/batch/evidence.mjs +81 -17
  50. package/src/batch/gate.mjs +46 -17
  51. package/src/batch/git-helpers.mjs +96 -0
  52. package/src/batch/heartbeat.mjs +73 -7
  53. package/src/batch/integrate.mjs +3 -5
  54. package/src/batch/journal.mjs +25 -0
  55. package/src/batch/lane-commit.mjs +90 -5
  56. package/src/batch/lifecycle.mjs +131 -4
  57. package/src/batch/macro-phase.mjs +226 -0
  58. package/src/batch/merge/adoption-doc-merge.mjs +243 -0
  59. package/src/batch/merge/wave-merge-state.mjs +108 -0
  60. package/src/batch/metrics.mjs +74 -5
  61. package/src/batch/orphan-detect.mjs +74 -0
  62. package/src/batch/pause.mjs +223 -0
  63. package/src/batch/post-merge-limbo.mjs +345 -17
  64. package/src/batch/reconcile.mjs +473 -50
  65. package/src/batch/resume-common.mjs +6 -2
  66. package/src/batch/resume-engine.mjs +58 -1
  67. package/src/batch/resume-lane-reviews.mjs +16 -0
  68. package/src/batch/resume-multi-lanes.mjs +56 -1
  69. package/src/batch/resume-multi-validate.mjs +148 -8
  70. package/src/batch/resume-multi.mjs +45 -44
  71. package/src/batch/resume.mjs +64 -47
  72. package/src/batch/retry.mjs +56 -5
  73. package/src/batch/review-shared.mjs +196 -0
  74. package/src/batch/review-spawn.mjs +326 -0
  75. package/src/batch/review.mjs +178 -212
  76. package/src/batch/rules-manifest-drift.mjs +157 -0
  77. package/src/batch/salvage.mjs +2 -1
  78. package/src/batch/sequence.mjs +454 -0
  79. package/src/batch/state.mjs +18 -3
  80. package/src/batch/status-json.mjs +67 -0
  81. package/src/batch/task-stall-budget.mjs +94 -10
  82. package/src/batch/worker-host.mjs +185 -37
  83. package/src/batch/worker-output.mjs +196 -3
  84. package/src/batch/worktree.mjs +10 -0
  85. package/src/cli/handoff.mjs +1 -1
  86. package/src/cli/issue-draft.mjs +180 -0
  87. package/src/cli/journal-follow.mjs +239 -0
  88. package/src/cli/lane-logs.mjs +291 -0
  89. package/src/cli/rules.mjs +1 -1
  90. package/src/cli/sequence.mjs +108 -0
  91. package/src/cli/settings-set.mjs +3 -22
  92. package/src/cli/settings-slash.mjs +27 -5
  93. package/src/cli/wait.mjs +187 -0
  94. package/src/cli/watch.mjs +160 -0
  95. package/src/config/agent-model-resolve.mjs +48 -0
  96. package/src/config/cursor-rules/discover.mjs +3 -21
  97. package/src/config/defaults.mjs +7 -1
  98. package/src/config/settings-fields.mjs +48 -0
  99. package/src/config/spine-config-load.mjs +221 -0
  100. package/src/config/spine-init-constants.mjs +424 -0
  101. package/src/config/spine-preflight-lib.mjs +1180 -0
  102. package/src/dashboard/lane-throughput.mjs +351 -0
  103. package/src/dashboard/public/dashboard.css +25 -1
  104. package/src/dashboard/public/dashboard.js +224 -40
  105. package/src/dashboard/public/index.html +15 -9
  106. package/src/dashboard/server.mjs +4 -0
  107. package/src/dashboard/snapshot.mjs +387 -6
  108. package/src/dashboard/view.mjs +170 -15
  109. package/src/doctor/agent-model-inherit.mjs +61 -6
  110. package/src/doctor/run-doctor-checks.mjs +483 -0
  111. package/src/doctor/sequence-safety.mjs +57 -0
  112. package/src/doctor/stale-path.mjs +22 -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/migrate/taskplane-config.mjs +1 -1
  117. package/src/planner/file-scope.mjs +246 -0
  118. package/src/planner/format-plan.mjs +9 -7
  119. package/src/planner/index.mjs +6 -2
  120. package/src/planner/pending.mjs +92 -1
  121. package/src/planner/wave-scope.mjs +136 -0
  122. package/src/planner/waves.mjs +133 -0
  123. package/src/tasks/analyze/index.mjs +453 -0
  124. package/src/tasks/packet/index.mjs +1 -0
  125. package/src/tasks/packet/parse-prompt.mjs +42 -1
  126. package/src/tasks/packet/validate-prompt.mjs +124 -0
  127. package/src/util/command-exists.mjs +19 -0
  128. package/templates/docs/constitution.md +61 -0
  129. package/templates/spine-config.json +9 -2
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Per-task done-marker semantics for reconcile / status JSON (SP-344 / GitHub #35).
3
+ */
4
+
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { laneWorktreePath } from "./worktree.mjs";
8
+
9
+ /** Documented task done-flag field names for status JSON. */
10
+ export const TASK_DONE_FLAG_FIELD_NAMES = ["doneFileFound", "doneOnMain", "doneInLane"];
11
+
12
+ /**
13
+ * @param {string} tasksRoot
14
+ * @param {string} taskId
15
+ * @param {string|null|undefined} taskFolder
16
+ * @returns {string|null}
17
+ */
18
+ export function resolveTaskFolderPath(tasksRoot, taskId, taskFolder) {
19
+ if (taskFolder) {
20
+ const direct = path.join(tasksRoot, taskFolder);
21
+ if (fs.existsSync(direct)) return direct;
22
+ }
23
+
24
+ if (!tasksRoot || !fs.existsSync(tasksRoot)) return null;
25
+
26
+ const match = fs
27
+ .readdirSync(tasksRoot, { withFileTypes: true })
28
+ .filter((entry) => entry.isDirectory() && entry.name.startsWith(`${taskId}-`))
29
+ .map((entry) => path.join(tasksRoot, entry.name))[0];
30
+
31
+ return match ?? null;
32
+ }
33
+
34
+ /**
35
+ * @param {string} projectRoot
36
+ * @param {string} batchId
37
+ * @param {unknown[]} lanes
38
+ * @param {object} task
39
+ * @returns {string}
40
+ */
41
+ export function resolveTaskLaneWorktreePath(projectRoot, batchId, lanes, task) {
42
+ const laneNumber = Number(task.laneNumber ?? 1);
43
+ const lane = Array.isArray(lanes)
44
+ ? lanes.find((entry) => Number(entry.laneNumber) === laneNumber)
45
+ : null;
46
+ if (lane && typeof lane.worktreePath === "string" && lane.worktreePath) {
47
+ return path.isAbsolute(lane.worktreePath)
48
+ ? lane.worktreePath
49
+ : path.join(projectRoot, lane.worktreePath);
50
+ }
51
+ return laneWorktreePath(projectRoot, batchId, laneNumber);
52
+ }
53
+
54
+ /**
55
+ * @param {string|null} folderPath
56
+ * @returns {boolean}
57
+ */
58
+ function doneMarkerExists(folderPath) {
59
+ return Boolean(folderPath && fs.existsSync(path.join(folderPath, ".DONE")));
60
+ }
61
+
62
+ /**
63
+ * Classify per-task done semantics for reconcile / status JSON.
64
+ *
65
+ * - `doneFileFound`: batch-state / journal records worker completion.
66
+ * - `doneOnMain`: `.DONE` exists under the integration checkout tasks root.
67
+ * - `doneInLane`: `.DONE` exists in the lane worktree copy (pre-merge).
68
+ *
69
+ * @param {object} task
70
+ * @param {object} ctx
71
+ * @param {string|null} [ctx.tasksRoot]
72
+ * @param {string} [ctx.projectRoot]
73
+ * @param {string} [ctx.batchId]
74
+ * @param {unknown[]} [ctx.lanes]
75
+ */
76
+ export function classifyTaskDoneSemantics(task, ctx = {}) {
77
+ const { tasksRoot, projectRoot, batchId, lanes = [] } = ctx;
78
+ const mainFolderPath =
79
+ tasksRoot && task.taskId
80
+ ? resolveTaskFolderPath(tasksRoot, task.taskId, task.taskFolder ?? null)
81
+ : null;
82
+ const doneOnMain = doneMarkerExists(mainFolderPath);
83
+ const doneFileFound = Boolean(task.doneFileFound);
84
+
85
+ let doneInLane = false;
86
+ if (projectRoot && batchId && tasksRoot && task.taskId) {
87
+ const laneWorktree = resolveTaskLaneWorktreePath(projectRoot, batchId, lanes, task);
88
+ const tasksRootRel = path.relative(projectRoot, tasksRoot);
89
+ const laneTasksRoot = path.join(laneWorktree, tasksRootRel);
90
+ const laneFolderPath = resolveTaskFolderPath(
91
+ laneTasksRoot,
92
+ task.taskId,
93
+ task.taskFolder ?? null,
94
+ );
95
+ doneInLane = doneMarkerExists(laneFolderPath);
96
+ }
97
+
98
+ let classification = task.classification;
99
+ if (doneOnMain || doneInLane || doneFileFound) {
100
+ classification = "terminal-success";
101
+ }
102
+
103
+ return {
104
+ ...task,
105
+ doneFileFound,
106
+ doneOnMain,
107
+ doneInLane,
108
+ classification,
109
+ };
110
+ }
@@ -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,7 +1,33 @@
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 {
21
+ buildStubFailureHeadline,
22
+ buildStubFailureSuggestedCommand,
23
+ STUB_EXIT_REASONS,
24
+ } from "./diagnosis-stub.mjs";
25
+ export {
26
+ classifyTaskDoneSemantics,
27
+ resolveTaskFolderPath,
28
+ resolveTaskLaneWorktreePath,
29
+ TASK_DONE_FLAG_FIELD_NAMES,
30
+ } from "./diagnosis-task-done.mjs";
5
31
  /** @typedef {import("./reconcile.mjs").ReconciliationResult} ReconciliationResult */
6
32
 
7
33
  export const DIAGNOSIS_TAXONOMY = [
@@ -10,6 +36,7 @@ export const DIAGNOSIS_TAXONOMY = [
10
36
  "needs_retry",
11
37
  "state_drift",
12
38
  "worker_orphaned",
39
+ "worker_done_missing",
13
40
  "engine_orphaned",
14
41
  "needs_merge",
15
42
  "needs_integrate",
@@ -21,32 +48,16 @@ export const DIAGNOSIS_TAXONOMY = [
21
48
  "aborted",
22
49
  ];
23
50
 
24
- const NO_PAUSE_DIAGNOSES = new Set(["limbo_stale", "completed_manual", "needs_integrate"]);
25
-
51
+ const NO_PAUSE_DIAGNOSES = new Set(["limbo_stale", "completed_manual", "needs_integrate", "engine_orphaned"]);
26
52
  const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
27
-
53
+ const GITIGNORED_MERGE_FAILURE_CLASSES = new Set(["merge_failed_gitignored", "GitignoredDirtyWorktree"]);
28
54
  const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
29
55
  "code_review_spawn_failed",
56
+ "code_review_timeout",
30
57
  "final_review_spawn_failed",
58
+ "final_review_timeout",
31
59
  ]);
32
60
 
33
- /**
34
- * @param {object[]} [journalEvents]
35
- * @param {string|null} [taskId]
36
- * @returns {object|null}
37
- */
38
- function findLatestTaskFailedEvent(journalEvents, taskId) {
39
- if (!Array.isArray(journalEvents) || journalEvents.length === 0) return null;
40
- for (let index = journalEvents.length - 1; index >= 0; index -= 1) {
41
- const event = journalEvents[index];
42
- if (event.type !== "task.failed") continue;
43
- const eventTaskId = event.taskId ?? event.payload?.taskId;
44
- if (taskId && eventTaskId && eventTaskId !== taskId) continue;
45
- return event;
46
- }
47
- return null;
48
- }
49
-
50
61
  /**
51
62
  * @param {string} haystack
52
63
  * @param {object} [hints]
@@ -107,6 +118,54 @@ export function inferLaunchFailureFromWorkerOutputTail(outputText) {
107
118
  return classifyLaunchFailureHaystack(String(outputText));
108
119
  }
109
120
 
121
+ /**
122
+ * @param {object} [ctx]
123
+ * @param {string|null} [ctx.exitReason]
124
+ * @param {string|null} [ctx.failureClass]
125
+ * @param {string|null} [ctx.lastError]
126
+ * @param {object[]} [ctx.journalEvents]
127
+ * @returns {boolean}
128
+ */
129
+ export function inferMergeGitignoredFailure(ctx = {}) {
130
+ const { exitReason, failureClass, lastError, journalEvents } = ctx;
131
+ if (GITIGNORED_MERGE_FAILURE_CLASSES.has(exitReason ?? "")) return true;
132
+ if (GITIGNORED_MERGE_FAILURE_CLASSES.has(failureClass ?? "")) return true;
133
+
134
+ const haystackParts = [exitReason, failureClass, lastError];
135
+ if (Array.isArray(journalEvents)) {
136
+ for (const event of journalEvents) {
137
+ if (event.type !== "batch.merge_failed" && event.type !== "task.failed") continue;
138
+ const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
139
+ haystackParts.push(
140
+ payload.failureClass,
141
+ payload.classification,
142
+ payload.error,
143
+ payload.output,
144
+ );
145
+ }
146
+ }
147
+ const haystack = haystackParts.filter(Boolean).join("\n").toLowerCase();
148
+ return (
149
+ haystack.includes("gitignored dirty files only") ||
150
+ haystack.includes("merge_failed_gitignored") ||
151
+ haystack.includes("gitignoreddirtyworktree") ||
152
+ (haystack.includes("git add") && haystack.includes("ignored"))
153
+ );
154
+ }
155
+
156
+ /**
157
+ * @param {string|null|undefined} taskBranch
158
+ * @param {string[]|null|undefined} gitignoredPaths
159
+ */
160
+ export function buildGitignoredMergeRepairCommand(taskBranch, gitignoredPaths) {
161
+ const branchHint = taskBranch ? `git checkout ${taskBranch}` : "git checkout <task-branch>";
162
+ const pathHint =
163
+ Array.isArray(gitignoredPaths) && gitignoredPaths.length > 0
164
+ ? `git rm -r --cached -- ${gitignoredPaths.slice(0, 5).join(" ")}`
165
+ : "git rm -r --cached -- <gitignored-paths>";
166
+ return `${branchHint} && ${pathHint} && spine batch resume --force`;
167
+ }
168
+
110
169
  /**
111
170
  * @param {object} ctx
112
171
  * @param {string|null} [ctx.exitReason]
@@ -155,8 +214,22 @@ export function inferLaunchFailureKind(ctx = {}) {
155
214
  * @param {string|null} [ctx.salvageRetryCommand]
156
215
  * @param {string|null} [ctx.exitReason]
157
216
  * @param {string|null} [ctx.launchFailureKind]
217
+ * @param {boolean} [ctx.mergeGitignoredFailure]
218
+ * @param {boolean} [ctx.mergeFailed]
219
+ * @param {string|null} [ctx.taskBranch]
220
+ * @param {string[]|null} [ctx.gitignoredPaths]
158
221
  */
159
222
  export function buildSuggestedCommand(diagnosis, ctx = {}) {
223
+ if (ctx.mergeGitignoredFailure) {
224
+ return buildGitignoredMergeRepairCommand(ctx.taskBranch, ctx.gitignoredPaths);
225
+ }
226
+ if (ctx.mergeFailed && (diagnosis === "failed" || diagnosis === "needs_retry")) {
227
+ return "spine batch resume --force";
228
+ }
229
+ if (ctx.phase === "merge_blocked") {
230
+ return "spine batch resume --force";
231
+ }
232
+
160
233
  switch (diagnosis) {
161
234
  case "limbo_stale":
162
235
  case "completed_manual":
@@ -164,6 +237,9 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
164
237
  case "state_drift":
165
238
  return "spine batch retry --force";
166
239
  case "needs_retry":
240
+ if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
241
+ return buildStubFailureSuggestedCommand(ctx);
242
+ }
167
243
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
168
244
  return "spine doctor";
169
245
  }
@@ -171,10 +247,26 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
171
247
  return "spine doctor";
172
248
  }
173
249
  if (ctx.salvageRetryCommand) return ctx.salvageRetryCommand;
250
+ if (isFailedPhasePendingOnlyLimbo(ctx)) {
251
+ return buildFailedPhasePendingOnlySuggestedCommand(ctx);
252
+ }
174
253
  return ctx.failedTaskId
175
254
  ? `spine batch retry ${ctx.failedTaskId}`
176
255
  : "spine status --diagnose";
177
256
  case "worker_orphaned":
257
+ if (ctx.planReviewNestedSpawnBlocked) {
258
+ if (ctx.stalePathSpine) {
259
+ return ctx.failedTaskId
260
+ ? `node bin/spine.mjs batch retry ${ctx.failedTaskId}`
261
+ : "npm link && spine batch resume --attached";
262
+ }
263
+ if (ctx.failedTaskId) {
264
+ return `spine batch retry ${ctx.failedTaskId}`;
265
+ }
266
+ }
267
+ if (ctx.engineDead) {
268
+ return "spine batch resume --attached --force";
269
+ }
178
270
  if (ctx.ghostRunningCluster) return "spine batch abort";
179
271
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
180
272
  return "spine doctor";
@@ -186,15 +278,23 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
186
278
  return ctx.failedTaskId
187
279
  ? `spine batch retry ${ctx.failedTaskId}`
188
280
  : "spine batch abort";
281
+ case "worker_done_missing":
282
+ return buildWorkerDoneMissingSuggestedCommand(ctx);
189
283
  case "engine_orphaned":
190
284
  return ctx.failedTaskId
191
285
  ? `spine batch retry ${ctx.failedTaskId}`
192
- : "spine batch abort";
286
+ : "spine batch resume --attached";
193
287
  case "needs_merge":
194
288
  return "/spine-resume --force";
195
289
  case "needs_integrate":
196
290
  if (ctx.postMergeLimbo && ctx.phase === "running") {
197
- return "spine batch resume";
291
+ if (ctx.integrateGateOpen) {
292
+ return "spine gate approve";
293
+ }
294
+ if (ctx.stalePathSpine) {
295
+ return "node bin/spine.mjs batch resume --attached";
296
+ }
297
+ return "spine batch resume --force";
198
298
  }
199
299
  return "spine integrate";
200
300
  case "needs_replan": {
@@ -230,16 +330,34 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
230
330
  * @param {number} [ctx.salvageChangedFileCount]
231
331
  * @param {string|null} [ctx.exitReason]
232
332
  * @param {string|null} [ctx.launchFailureKind]
333
+ * @param {boolean} [ctx.mergeGitignoredFailure]
334
+ * @param {boolean} [ctx.mergeFailed]
335
+ * @param {number|null} [ctx.failedWaveIndex]
336
+ * @param {number|null} [ctx.failedLane]
337
+ * @param {string|null} [ctx.lastError]
338
+ * @param {number} [ctx.succeededTasks]
339
+ * @param {number} [ctx.totalTasks]
233
340
  */
234
341
  export function buildHeadline(diagnosis, ctx = {}) {
235
342
  const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
236
343
 
344
+ if (ctx.mergeGitignoredFailure) {
345
+ return `${batchLabel} merge blocked by gitignored paths on a lane branch — drop cached ignored files, then resume`;
346
+ }
347
+
348
+ if (ctx.mergeFailed && (diagnosis === "failed" || diagnosis === "needs_retry")) {
349
+ return buildMergeFailureHeadline(batchLabel, ctx);
350
+ }
351
+
237
352
  switch (diagnosis) {
238
353
  case "limbo_stale":
239
354
  return `${batchLabel} finished but state is stale — dismiss to clear`;
240
355
  case "completed_manual":
241
356
  return `${batchLabel} work is on main but batch record is still active`;
242
357
  case "needs_retry":
358
+ if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
359
+ return buildStubFailureHeadline(batchLabel, ctx);
360
+ }
243
361
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
244
362
  return `${batchLabel} failed at worker launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
245
363
  }
@@ -247,13 +365,21 @@ export function buildHeadline(diagnosis, ctx = {}) {
247
365
  return `${batchLabel} failed at worker launch — repair lane worktree git, then retry`;
248
366
  }
249
367
  if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
368
+ if (ctx.exitReason === "GitignoredDirtyWorktree" || ctx.mergeGitignoredFailure) {
369
+ return ctx.failedTaskId
370
+ ? `${batchLabel} task ${ctx.failedTaskId} left gitignored dirty files on the lane branch`
371
+ : `${batchLabel} lane commit refused gitignored-only dirty files`;
372
+ }
250
373
  return ctx.failedTaskId
251
374
  ? `${batchLabel} task ${ctx.failedTaskId} completed but lane commit failed`
252
375
  : `${batchLabel} completed but lane commit failed`;
253
376
  }
254
377
  if (REVIEW_SPAWN_FAILURE_EXIT_REASONS.has(ctx.exitReason ?? "")) {
255
378
  const reviewKind =
256
- ctx.exitReason === "final_review_spawn_failed" ? "final review" : "code review";
379
+ ctx.exitReason === "final_review_spawn_failed" ||
380
+ ctx.exitReason === "final_review_timeout"
381
+ ? "final review"
382
+ : "code review";
257
383
  return ctx.failedTaskId
258
384
  ? `${batchLabel} ${reviewKind} timed out for task ${ctx.failedTaskId} — retry or increase SPINE_REVIEW_TIMEOUT_MS`
259
385
  : `${batchLabel} reviewer spawn timed out — retry`;
@@ -261,6 +387,9 @@ export function buildHeadline(diagnosis, ctx = {}) {
261
387
  if (ctx.salvageChangedFileCount > 0 && ctx.failedTaskId) {
262
388
  return `${batchLabel} failed (${ctx.failedTaskId}): ${ctx.salvageChangedFileCount} uncommitted file(s) in scope`;
263
389
  }
390
+ if (isFailedPhasePendingOnlyLimbo(ctx)) {
391
+ return buildFailedPhasePendingOnlyHeadline(batchLabel, ctx);
392
+ }
264
393
  return ctx.failedTaskId
265
394
  ? `${batchLabel} worker died while task ${ctx.failedTaskId} was running — retry or abort`
266
395
  : `${batchLabel} has failed tasks — retry before resume`;
@@ -269,6 +398,16 @@ export function buildHeadline(diagnosis, ctx = {}) {
269
398
  ? `${batchLabel} batch-state drift for task ${ctx.failedTaskId} — journal disagrees with cache`
270
399
  : `${batchLabel} batch-state drift — journal disagrees with cache`;
271
400
  case "worker_orphaned":
401
+ if (ctx.planReviewNestedSpawnBlocked) {
402
+ return ctx.failedTaskId
403
+ ? `${batchLabel} plan review nested_spawn_blocked (stale PATH spine or pre-SP-278) — retry task ${ctx.failedTaskId}`
404
+ : `${batchLabel} plan review nested_spawn_blocked — retry after npm link or use node bin/spine.mjs`;
405
+ }
406
+ if (ctx.engineDead) {
407
+ return ctx.failedTaskId
408
+ ? `${batchLabel} engine and worker died while task ${ctx.failedTaskId} was running — resume attached with --force`
409
+ : `${batchLabel} engine and worker died while running — resume attached with --force`;
410
+ }
272
411
  if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
273
412
  return `${batchLabel} lane worker orphaned during launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
274
413
  }
@@ -283,14 +422,25 @@ export function buildHeadline(diagnosis, ctx = {}) {
283
422
  return ctx.failedTaskId
284
423
  ? `${batchLabel} lane worker orphaned while task ${ctx.failedTaskId} was running — retry or abort`
285
424
  : `${batchLabel} lane worker orphaned — retry or abort`;
425
+ case "worker_done_missing":
426
+ return buildWorkerDoneMissingHeadline(batchLabel, ctx);
286
427
  case "engine_orphaned":
287
428
  return ctx.failedTaskId
288
429
  ? `${batchLabel} engine died mid-run (task ${ctx.failedTaskId} still running) — retry or abort`
289
430
  : `${batchLabel} batch engine died while running — retry or abort`;
290
431
  case "needs_merge":
432
+ if (ctx.mergeGitignoredFailure) {
433
+ return `${batchLabel} merge blocked by gitignored paths committed on a lane branch`;
434
+ }
291
435
  return `${batchLabel} tasks done — lane merges pending`;
292
436
  case "needs_integrate":
293
437
  if (ctx.postMergeLimbo && ctx.phase === "running") {
438
+ if (ctx.integrateGateOpen) {
439
+ return `${batchLabel} gate opened — approve to continue land loop`;
440
+ }
441
+ if (ctx.stalePathSpine) {
442
+ return `${batchLabel} merged but gate not opened — use node bin/spine.mjs batch resume --attached (PATH spine may be stale)`;
443
+ }
294
444
  return `${batchLabel} merged but gate not opened — resume to complete land loop`;
295
445
  }
296
446
  return `${batchLabel} ready to integrate orch branch to main`;
@@ -318,44 +468,6 @@ export function buildHeadline(diagnosis, ctx = {}) {
318
468
  }
319
469
  }
320
470
 
321
- /**
322
- * @param {string} diagnosis
323
- * @param {object} [ctx]
324
- * @param {string|null} [ctx.failedTaskId]
325
- */
326
- export function buildAlternatives(diagnosis, ctx = {}) {
327
- const common = ["spine status --diagnose"];
328
-
329
- switch (diagnosis) {
330
- case "limbo_stale":
331
- return ["spine batch complete --detect-manual-merge", ...common];
332
- case "completed_manual":
333
- return ["spine batch complete --detect-manual-merge", "spine batch dismiss", ...common];
334
- case "needs_retry":
335
- return ["spine batch abort", "/spine-skip-task", "/spine-resume --force", ...common];
336
- case "worker_orphaned":
337
- return ["spine batch abort", "spine batch resume --force", ...common];
338
- case "engine_orphaned":
339
- return ["spine batch abort", "spine batch resume --force", ...common];
340
- case "needs_merge":
341
- return ["/spine-status --diagnose", ...common];
342
- case "needs_integrate":
343
- return ["/spine-integrate", "/spine-gate", ...common];
344
- case "needs_replan":
345
- return ctx.failedTaskId
346
- ? [`spine batch skip ${ctx.failedTaskId}`, "spine handoff", ...common]
347
- : ["spine handoff", ...common];
348
- case "running":
349
- return ["/spine-pause", "/spine-abort", ...common];
350
- case "paused":
351
- return ["spine batch resume --force", "spine status --diagnose", ...common];
352
- case "failed":
353
- return ["/spine-retry-task", ...common];
354
- default:
355
- return common;
356
- }
357
- }
358
-
359
471
  /**
360
472
  * @param {string} diagnosis
361
473
  */