pi-spine 1.0.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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +563 -0
  3. package/bin/get-version.mjs +35 -0
  4. package/bin/spine-batch.mjs +425 -0
  5. package/bin/spine-cli/batch.mjs +47 -0
  6. package/bin/spine-cli/gate.mjs +10 -0
  7. package/bin/spine-cli/integrate.mjs +10 -0
  8. package/bin/spine-cli/plan.mjs +12 -0
  9. package/bin/spine-cli/shared.mjs +73 -0
  10. package/bin/spine-cli/status.mjs +18 -0
  11. package/bin/spine-cli/verify.mjs +199 -0
  12. package/bin/spine-config.mjs +212 -0
  13. package/bin/spine-dashboard.mjs +178 -0
  14. package/bin/spine-deps.mjs +69 -0
  15. package/bin/spine-doctor.mjs +468 -0
  16. package/bin/spine-gate.mjs +137 -0
  17. package/bin/spine-init.mjs +398 -0
  18. package/bin/spine-integrate.mjs +77 -0
  19. package/bin/spine-journal.mjs +198 -0
  20. package/bin/spine-migrate-from-taskplane.mjs +136 -0
  21. package/bin/spine-plan.mjs +83 -0
  22. package/bin/spine-preflight.mjs +700 -0
  23. package/bin/spine-report-progress.d.mts +28 -0
  24. package/bin/spine-report-progress.mjs +126 -0
  25. package/bin/spine-review-step.d.mts +24 -0
  26. package/bin/spine-review-step.mjs +124 -0
  27. package/bin/spine-rules.mjs +35 -0
  28. package/bin/spine-settings.mjs +186 -0
  29. package/bin/spine-state.mjs +110 -0
  30. package/bin/spine-status.mjs +79 -0
  31. package/bin/spine-tasks.mjs +293 -0
  32. package/bin/spine-worker-runner.mjs +314 -0
  33. package/bin/spine.mjs +404 -0
  34. package/extensions/spine/settings-slash.ts +20 -0
  35. package/extensions/spine/slash-commands.ts +806 -0
  36. package/extensions/spine/worker-tools.ts +279 -0
  37. package/extensions/spine-orchestrator.ts +12 -0
  38. package/package.json +72 -0
  39. package/skills/.gitkeep +0 -0
  40. package/skills/create-spine-tasks/SKILL.md +375 -0
  41. package/skills/create-spine-tasks/references/context-template.md +25 -0
  42. package/skills/create-spine-tasks/references/contract-template.md +98 -0
  43. package/skills/create-spine-tasks/references/explore-template.md +63 -0
  44. package/skills/create-spine-tasks/references/prompt-template.md +276 -0
  45. package/src/batch/abort.mjs +272 -0
  46. package/src/batch/agent-session-worker.mjs +297 -0
  47. package/src/batch/batch-state-io.mjs +53 -0
  48. package/src/batch/contract-verify.mjs +310 -0
  49. package/src/batch/detached-start.mjs +778 -0
  50. package/src/batch/diagnosis.mjs +378 -0
  51. package/src/batch/engine-lanes/merge.mjs +632 -0
  52. package/src/batch/engine-lanes/queue.mjs +208 -0
  53. package/src/batch/engine-lanes/review.mjs +970 -0
  54. package/src/batch/engine-lanes.mjs +388 -0
  55. package/src/batch/engine-scope.mjs +251 -0
  56. package/src/batch/engine.mjs +445 -0
  57. package/src/batch/evidence-command.mjs +157 -0
  58. package/src/batch/evidence.mjs +203 -0
  59. package/src/batch/gate.mjs +359 -0
  60. package/src/batch/git-commit-env.mjs +46 -0
  61. package/src/batch/git-exec.mjs +26 -0
  62. package/src/batch/heartbeat.mjs +430 -0
  63. package/src/batch/integrate.mjs +414 -0
  64. package/src/batch/journal-rebuild.mjs +388 -0
  65. package/src/batch/journal.mjs +373 -0
  66. package/src/batch/lane-commit.mjs +153 -0
  67. package/src/batch/lifecycle.mjs +364 -0
  68. package/src/batch/metrics.mjs +265 -0
  69. package/src/batch/orphan-detect.mjs +210 -0
  70. package/src/batch/post-merge-limbo.mjs +80 -0
  71. package/src/batch/postmortem.mjs +296 -0
  72. package/src/batch/readers/spine-state.mjs +95 -0
  73. package/src/batch/readers/taskplane-state.mjs +136 -0
  74. package/src/batch/reconcile.mjs +729 -0
  75. package/src/batch/resume-common.mjs +104 -0
  76. package/src/batch/resume-engine.mjs +66 -0
  77. package/src/batch/resume-multi-lanes.mjs +479 -0
  78. package/src/batch/resume-multi-validate.mjs +187 -0
  79. package/src/batch/resume-multi.mjs +254 -0
  80. package/src/batch/resume.mjs +475 -0
  81. package/src/batch/retry.mjs +257 -0
  82. package/src/batch/review-scope.mjs +136 -0
  83. package/src/batch/review.mjs +1045 -0
  84. package/src/batch/salvage.mjs +332 -0
  85. package/src/batch/state.mjs +680 -0
  86. package/src/batch/task-stall-budget.mjs +88 -0
  87. package/src/batch/worker-host.mjs +683 -0
  88. package/src/batch/worker-output.mjs +253 -0
  89. package/src/batch/worker-prompt.mjs +84 -0
  90. package/src/batch/worktree.mjs +290 -0
  91. package/src/cli/deps.mjs +141 -0
  92. package/src/cli/handoff.mjs +364 -0
  93. package/src/cli/rules.mjs +429 -0
  94. package/src/cli/settings-set.mjs +171 -0
  95. package/src/cli/settings-show.mjs +140 -0
  96. package/src/cli/settings-slash.mjs +107 -0
  97. package/src/config/contract.mjs +56 -0
  98. package/src/config/cursor-rules/discover.mjs +416 -0
  99. package/src/config/cursor-rules/index.mjs +39 -0
  100. package/src/config/cursor-rules/match-globs.mjs +132 -0
  101. package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
  102. package/src/config/cursor-rules/priority.mjs +26 -0
  103. package/src/config/cursor-rules/profile.mjs +403 -0
  104. package/src/config/cursor-rules/select.mjs +259 -0
  105. package/src/config/defaults.mjs +36 -0
  106. package/src/config/env-overrides.mjs +207 -0
  107. package/src/config/merge-defaults.mjs +47 -0
  108. package/src/config/pi-spine-root.mjs +93 -0
  109. package/src/config/reviewer-context.mjs +243 -0
  110. package/src/config/settings-fields.mjs +265 -0
  111. package/src/config/worker-backend.mjs +116 -0
  112. package/src/config/worker-context.mjs +402 -0
  113. package/src/config/worker-launch-script.mjs +130 -0
  114. package/src/config/worktree-setup-hook.mjs +122 -0
  115. package/src/dashboard/public/dashboard.css +77 -0
  116. package/src/dashboard/public/dashboard.js +349 -0
  117. package/src/dashboard/public/index.html +80 -0
  118. package/src/dashboard/server.mjs +155 -0
  119. package/src/dashboard/snapshot.mjs +414 -0
  120. package/src/dashboard/sse.mjs +15 -0
  121. package/src/dashboard/view.mjs +292 -0
  122. package/src/doctor/agent-model-inherit.mjs +101 -0
  123. package/src/doctor/batch-size-guidance.mjs +72 -0
  124. package/src/doctor/coexistence.mjs +312 -0
  125. package/src/doctor/rules-manifest.mjs +133 -0
  126. package/src/doctor/stale-path.mjs +156 -0
  127. package/src/doctor/stall-config.mjs +108 -0
  128. package/src/doctor/suggest-max-parallel.mjs +53 -0
  129. package/src/doctor/task-packet-size.mjs +110 -0
  130. package/src/doctor/worktree-health.mjs +71 -0
  131. package/src/migrate/taskplane-config.mjs +116 -0
  132. package/src/planner/cycles.mjs +63 -0
  133. package/src/planner/format-plan.mjs +132 -0
  134. package/src/planner/graph.mjs +99 -0
  135. package/src/planner/index.mjs +125 -0
  136. package/src/planner/lanes.mjs +111 -0
  137. package/src/planner/pending.mjs +39 -0
  138. package/src/planner/scope.mjs +142 -0
  139. package/src/process/liveness.mjs +21 -0
  140. package/src/tasks/packet/discover.mjs +40 -0
  141. package/src/tasks/packet/index.mjs +81 -0
  142. package/src/tasks/packet/merge-deps.mjs +79 -0
  143. package/src/tasks/packet/parse-prompt.mjs +445 -0
  144. package/src/tasks/packet/parse-status.mjs +118 -0
  145. package/src/tasks/packet/validate-contract.mjs +115 -0
  146. package/src/tasks/packet/validate-prompt.mjs +99 -0
  147. package/src/worker-tools/report-progress.d.mts +18 -0
  148. package/src/worker-tools/report-progress.mjs +59 -0
  149. package/src/worker-tools/request-gate.d.mts +17 -0
  150. package/src/worker-tools/request-gate.mjs +54 -0
  151. package/templates/agents/reviewer.md +123 -0
  152. package/templates/agents/supervisor.md +59 -0
  153. package/templates/agents/worker.md +122 -0
  154. package/templates/rules-profile.json +27 -0
  155. package/templates/spine-config.json +64 -0
  156. package/templates/tasks/CONTEXT.md +30 -0
@@ -0,0 +1,378 @@
1
+ /**
2
+ * FR-BATCH-13 diagnosis taxonomy and operator messaging (§18.3).
3
+ */
4
+
5
+ /** @typedef {import("./reconcile.mjs").ReconciliationResult} ReconciliationResult */
6
+
7
+ export const DIAGNOSIS_TAXONOMY = [
8
+ "running",
9
+ "paused",
10
+ "needs_retry",
11
+ "state_drift",
12
+ "worker_orphaned",
13
+ "engine_orphaned",
14
+ "needs_merge",
15
+ "needs_integrate",
16
+ "needs_replan",
17
+ "completed",
18
+ "completed_manual",
19
+ "limbo_stale",
20
+ "failed",
21
+ "aborted",
22
+ ];
23
+
24
+ const NO_PAUSE_DIAGNOSES = new Set(["limbo_stale", "completed_manual", "needs_integrate"]);
25
+
26
+ const LANE_COMMIT_EXIT_REASONS = new Set(["DirtyWorktree", "lane_commit_failed"]);
27
+
28
+ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
29
+ "code_review_spawn_failed",
30
+ "final_review_spawn_failed",
31
+ ]);
32
+
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
+ /**
51
+ * @param {string} haystack
52
+ * @param {object} [hints]
53
+ * @param {boolean} [hints.launchingPhase]
54
+ * @returns {string|null}
55
+ */
56
+ function classifyLaunchFailureHaystack(haystack, hints = {}) {
57
+ const normalized = haystack.toLowerCase();
58
+
59
+ if (hints.launchingPhase) {
60
+ if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
61
+ return "pi_spine_root";
62
+ }
63
+ return "launch_failed";
64
+ }
65
+
66
+ if (normalized.includes("pi_spine_root") || normalized.includes("config_pi_spine_root")) {
67
+ return "pi_spine_root";
68
+ }
69
+
70
+ if (
71
+ normalized.includes("not a git repository") ||
72
+ normalized.includes("worktree") ||
73
+ normalized.includes("worktreeunhealthy")
74
+ ) {
75
+ return "worktree_unhealthy";
76
+ }
77
+
78
+ return null;
79
+ }
80
+
81
+ /**
82
+ * @param {object|null} failedEvent
83
+ * @param {string|null} exitReason
84
+ * @returns {string|null}
85
+ */
86
+ function classifyLaunchFailureFromEvent(failedEvent, exitReason) {
87
+ const payload = failedEvent?.payload && typeof failedEvent.payload === "object" ? failedEvent.payload : {};
88
+ const haystack = [
89
+ exitReason,
90
+ payload.classification,
91
+ payload.output,
92
+ payload.exitReason,
93
+ ].filter(Boolean).join("\n");
94
+
95
+ return classifyLaunchFailureHaystack(haystack, {
96
+ launchingPhase:
97
+ payload.workerPhase === "launching" || payload.classification === "launch_failed",
98
+ });
99
+ }
100
+
101
+ /**
102
+ * @param {string|null|undefined} outputText
103
+ * @returns {string|null}
104
+ */
105
+ export function inferLaunchFailureFromWorkerOutputTail(outputText) {
106
+ if (!outputText || !String(outputText).trim()) return null;
107
+ return classifyLaunchFailureHaystack(String(outputText));
108
+ }
109
+
110
+ /**
111
+ * @param {object} ctx
112
+ * @param {string|null} [ctx.exitReason]
113
+ * @param {string|null} [ctx.launchFailureKind]
114
+ * @param {object[]} [ctx.journalEvents]
115
+ * @param {string|null} [ctx.failedTaskId]
116
+ * @returns {string|null}
117
+ */
118
+ export function inferLaunchFailureKind(ctx = {}) {
119
+ const { exitReason, journalEvents, failedTaskId } = ctx;
120
+ if (exitReason === "launch_failed" || exitReason === "worker_launch_failed") {
121
+ return "launch_failed";
122
+ }
123
+
124
+ const kinds = [];
125
+ if (Array.isArray(journalEvents)) {
126
+ const taskFailedEvents = journalEvents.filter((event) => event.type === "task.failed");
127
+ const prioritized = failedTaskId
128
+ ? [
129
+ ...taskFailedEvents.filter(
130
+ (event) => (event.taskId ?? event.payload?.taskId) === failedTaskId,
131
+ ),
132
+ ...taskFailedEvents.filter(
133
+ (event) => (event.taskId ?? event.payload?.taskId) !== failedTaskId,
134
+ ),
135
+ ]
136
+ : taskFailedEvents;
137
+
138
+ for (const failedEvent of prioritized) {
139
+ const kind = classifyLaunchFailureFromEvent(failedEvent, exitReason);
140
+ if (kind) kinds.push(kind);
141
+ }
142
+ }
143
+
144
+ if (kinds.includes("pi_spine_root")) return "pi_spine_root";
145
+ if (kinds.includes("launch_failed")) return "launch_failed";
146
+ if (kinds.includes("worktree_unhealthy")) return "worktree_unhealthy";
147
+ return null;
148
+ }
149
+
150
+ /**
151
+ * @param {string} diagnosis
152
+ * @param {object} [ctx]
153
+ * @param {string|null} [ctx.failedTaskId]
154
+ * @param {string|null} [ctx.batchId]
155
+ * @param {string|null} [ctx.salvageRetryCommand]
156
+ * @param {string|null} [ctx.exitReason]
157
+ * @param {string|null} [ctx.launchFailureKind]
158
+ */
159
+ export function buildSuggestedCommand(diagnosis, ctx = {}) {
160
+ switch (diagnosis) {
161
+ case "limbo_stale":
162
+ case "completed_manual":
163
+ return "spine batch dismiss";
164
+ case "state_drift":
165
+ return "spine batch retry --force";
166
+ case "needs_retry":
167
+ if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
168
+ return "spine doctor";
169
+ }
170
+ if (ctx.launchFailureKind === "worktree_unhealthy") {
171
+ return "spine doctor";
172
+ }
173
+ if (ctx.salvageRetryCommand) return ctx.salvageRetryCommand;
174
+ return ctx.failedTaskId
175
+ ? `spine batch retry ${ctx.failedTaskId}`
176
+ : "spine status --diagnose";
177
+ case "worker_orphaned":
178
+ if (ctx.ghostRunningCluster) return "spine batch abort";
179
+ if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
180
+ return "spine doctor";
181
+ }
182
+ if (ctx.launchFailureKind === "worktree_unhealthy") {
183
+ return "spine doctor";
184
+ }
185
+ if (ctx.salvageRetryCommand) return ctx.salvageRetryCommand;
186
+ return ctx.failedTaskId
187
+ ? `spine batch retry ${ctx.failedTaskId}`
188
+ : "spine batch abort";
189
+ case "engine_orphaned":
190
+ return ctx.failedTaskId
191
+ ? `spine batch retry ${ctx.failedTaskId}`
192
+ : "spine batch abort";
193
+ case "needs_merge":
194
+ return "/spine-resume --force";
195
+ case "needs_integrate":
196
+ if (ctx.postMergeLimbo && ctx.phase === "running") {
197
+ return "spine batch resume";
198
+ }
199
+ return "spine integrate";
200
+ case "needs_replan": {
201
+ const tasksRoot = ctx.tasksRoot ?? "spine-tasks";
202
+ return ctx.failedTaskId
203
+ ? `edit ${tasksRoot}/${ctx.failedTaskId}/PROMPT.md then spine batch retry ${ctx.failedTaskId}`
204
+ : "spine status --diagnose";
205
+ }
206
+ case "running":
207
+ return "/spine-status --diagnose";
208
+ case "paused":
209
+ return "spine batch resume";
210
+ case "failed":
211
+ return "spine status --diagnose";
212
+ case "aborted":
213
+ return "spine batch dismiss";
214
+ case "completed":
215
+ return "spine preflight";
216
+ default:
217
+ return "spine status --diagnose";
218
+ }
219
+ }
220
+
221
+ /**
222
+ * @param {string} diagnosis
223
+ * @param {object} ctx
224
+ * @param {string|null} [ctx.batchId]
225
+ * @param {string|null} [ctx.phase]
226
+ * @param {number} [ctx.failedTasks]
227
+ * @param {string|null} [ctx.failedTaskId]
228
+ * @param {boolean} [ctx.gitMerged]
229
+ * @param {number} [ctx.pendingTaskCount]
230
+ * @param {number} [ctx.salvageChangedFileCount]
231
+ * @param {string|null} [ctx.exitReason]
232
+ * @param {string|null} [ctx.launchFailureKind]
233
+ */
234
+ export function buildHeadline(diagnosis, ctx = {}) {
235
+ const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
236
+
237
+ switch (diagnosis) {
238
+ case "limbo_stale":
239
+ return `${batchLabel} finished but state is stale — dismiss to clear`;
240
+ case "completed_manual":
241
+ return `${batchLabel} work is on main but batch record is still active`;
242
+ case "needs_retry":
243
+ if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
244
+ return `${batchLabel} failed at worker launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
245
+ }
246
+ if (ctx.launchFailureKind === "worktree_unhealthy") {
247
+ return `${batchLabel} failed at worker launch — repair lane worktree git, then retry`;
248
+ }
249
+ if (LANE_COMMIT_EXIT_REASONS.has(ctx.exitReason ?? "")) {
250
+ return ctx.failedTaskId
251
+ ? `${batchLabel} task ${ctx.failedTaskId} completed but lane commit failed`
252
+ : `${batchLabel} completed but lane commit failed`;
253
+ }
254
+ if (REVIEW_SPAWN_FAILURE_EXIT_REASONS.has(ctx.exitReason ?? "")) {
255
+ const reviewKind =
256
+ ctx.exitReason === "final_review_spawn_failed" ? "final review" : "code review";
257
+ return ctx.failedTaskId
258
+ ? `${batchLabel} ${reviewKind} timed out for task ${ctx.failedTaskId} — retry or increase SPINE_REVIEW_TIMEOUT_MS`
259
+ : `${batchLabel} reviewer spawn timed out — retry`;
260
+ }
261
+ if (ctx.salvageChangedFileCount > 0 && ctx.failedTaskId) {
262
+ return `${batchLabel} failed (${ctx.failedTaskId}): ${ctx.salvageChangedFileCount} uncommitted file(s) in scope`;
263
+ }
264
+ return ctx.failedTaskId
265
+ ? `${batchLabel} worker died while task ${ctx.failedTaskId} was running — retry or abort`
266
+ : `${batchLabel} has failed tasks — retry before resume`;
267
+ case "state_drift":
268
+ return ctx.failedTaskId
269
+ ? `${batchLabel} batch-state drift for task ${ctx.failedTaskId} — journal disagrees with cache`
270
+ : `${batchLabel} batch-state drift — journal disagrees with cache`;
271
+ case "worker_orphaned":
272
+ if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
273
+ return `${batchLabel} lane worker orphaned during launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
274
+ }
275
+ if (ctx.launchFailureKind === "worktree_unhealthy") {
276
+ return `${batchLabel} lane worker orphaned during launch — repair lane worktree git, then retry`;
277
+ }
278
+ if (ctx.ghostRunningCluster) {
279
+ return ctx.failedTaskId
280
+ ? `${batchLabel} lane worker orphaned with multiple ghost running tasks (task ${ctx.failedTaskId}) — abort or retry`
281
+ : `${batchLabel} lane worker orphaned with multiple ghost running tasks — abort or retry`;
282
+ }
283
+ return ctx.failedTaskId
284
+ ? `${batchLabel} lane worker orphaned while task ${ctx.failedTaskId} was running — retry or abort`
285
+ : `${batchLabel} lane worker orphaned — retry or abort`;
286
+ case "engine_orphaned":
287
+ return ctx.failedTaskId
288
+ ? `${batchLabel} engine died mid-run (task ${ctx.failedTaskId} still running) — retry or abort`
289
+ : `${batchLabel} batch engine died while running — retry or abort`;
290
+ case "needs_merge":
291
+ return `${batchLabel} tasks done — lane merges pending`;
292
+ case "needs_integrate":
293
+ if (ctx.postMergeLimbo && ctx.phase === "running") {
294
+ return `${batchLabel} merged but gate not opened — resume to complete land loop`;
295
+ }
296
+ return `${batchLabel} ready to integrate orch branch to main`;
297
+ case "needs_replan":
298
+ return ctx.failedTaskId
299
+ ? `Task ${ctx.failedTaskId} needs replan — edit PROMPT.md before retry`
300
+ : `${batchLabel} has tasks needing replan — edit PROMPT.md before retry`;
301
+ case "running":
302
+ return `${batchLabel} is running`;
303
+ case "paused": {
304
+ const pending = ctx.pendingTaskCount ?? 0;
305
+ if (pending > 1) {
306
+ return `${batchLabel} is paused with ${pending} tasks pending — use spine batch resume (multi-task)`;
307
+ }
308
+ return `${batchLabel} is paused`;
309
+ }
310
+ case "failed":
311
+ return `${batchLabel} failed (${ctx.failedTasks ?? 0} failed task(s))`;
312
+ case "aborted":
313
+ return `${batchLabel} was aborted`;
314
+ case "completed":
315
+ return `${batchLabel} completed successfully`;
316
+ default:
317
+ return `${batchLabel} requires attention (phase: ${ctx.phase ?? "unknown"})`;
318
+ }
319
+ }
320
+
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
+ /**
360
+ * @param {string} diagnosis
361
+ */
362
+ export function shouldNeverSuggestPause(diagnosis) {
363
+ return NO_PAUSE_DIAGNOSES.has(diagnosis);
364
+ }
365
+
366
+ /**
367
+ * @param {string} diagnosis
368
+ * @param {object} ctx
369
+ * @returns {Pick<ReconciliationResult, "diagnosis" | "headline" | "suggestedCommand" | "alternatives">}
370
+ */
371
+ export function buildDiagnosisOutput(diagnosis, ctx = {}) {
372
+ return {
373
+ diagnosis,
374
+ headline: buildHeadline(diagnosis, ctx),
375
+ suggestedCommand: buildSuggestedCommand(diagnosis, ctx),
376
+ alternatives: buildAlternatives(diagnosis, ctx),
377
+ };
378
+ }