pi-spine 2.5.0 → 2.6.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.
- package/bin/spine.mjs +22 -0
- package/package.json +1 -1
- package/src/batch/attached-runner-promote.mjs +95 -11
- package/src/batch/diagnosis-alternatives.mjs +18 -0
- package/src/batch/diagnosis-gate-ready.mjs +23 -0
- package/src/batch/diagnosis-pending-lane.mjs +63 -0
- package/src/batch/diagnosis-retry-command.mjs +23 -0
- package/src/batch/diagnosis-tail-state.mjs +68 -0
- package/src/batch/diagnosis.mjs +69 -52
- package/src/batch/engine-lanes/commit.mjs +2 -0
- package/src/batch/engine-lanes.mjs +2 -3
- package/src/batch/evidence-command.mjs +125 -4
- package/src/batch/lane-commit.mjs +77 -8
- package/src/batch/lifecycle-archive.mjs +71 -0
- package/src/batch/lifecycle.mjs +27 -67
- package/src/batch/orphan-detect.mjs +68 -5
- package/src/batch/post-merge-limbo.mjs +137 -22
- package/src/batch/reconcile-batch.mjs +40 -43
- package/src/batch/reconcile-diagnosis-context.mjs +88 -0
- package/src/batch/reconcile-diagnosis.mjs +14 -32
- package/src/batch/resume-multi-validate.mjs +51 -9
- package/src/batch/retry.mjs +18 -2
- package/src/config/pi-spine-root.mjs +22 -0
- package/src/config/spine-config-load.mjs +26 -0
- package/src/doctor/duplicate-install.mjs +100 -0
- package/src/doctor/run-doctor-checks.mjs +10 -1
- package/src/doctor/worktree-health.mjs +4 -0
- package/templates/spine-config.json +3 -2
package/bin/spine.mjs
CHANGED
|
@@ -38,6 +38,11 @@ import { loadSpineConfig } from "./spine-config.mjs";
|
|
|
38
38
|
import { cmdInit } from "./spine-init.mjs";
|
|
39
39
|
import { cmdMigrateFromTaskplane } from "./spine-migrate-from-taskplane.mjs";
|
|
40
40
|
import { cmdDoctor } from "./spine-doctor.mjs";
|
|
41
|
+
import { ensureDefaultPiSpineRootEnv } from "../src/config/pi-spine-root.mjs";
|
|
42
|
+
import {
|
|
43
|
+
detectPathSpineVersionSkew,
|
|
44
|
+
formatCheckoutVersionSkewRemediation,
|
|
45
|
+
} from "../src/doctor/duplicate-install.mjs";
|
|
41
46
|
|
|
42
47
|
export { runDoctorChecks } from "./spine-doctor.mjs";
|
|
43
48
|
|
|
@@ -243,6 +248,20 @@ function cmdVersion() {
|
|
|
243
248
|
const piVersion = getVersion("pi");
|
|
244
249
|
if (piVersion) console.log(` Pi: ${piVersion}`);
|
|
245
250
|
console.log(` Node: v${process.versions.node}`);
|
|
251
|
+
|
|
252
|
+
const skew = detectPathSpineVersionSkew({
|
|
253
|
+
runningPackageRoot: PACKAGE_ROOT,
|
|
254
|
+
projectRoot,
|
|
255
|
+
});
|
|
256
|
+
if (skew.skewed) {
|
|
257
|
+
console.log(
|
|
258
|
+
`\n ${c.yellow}⚠️ Version skew:${c.reset} running v${skew.cliVersion} ≠ checkout v${skew.checkoutVersion}`,
|
|
259
|
+
);
|
|
260
|
+
console.log(
|
|
261
|
+
` ${c.dim}→ Use: ${formatCheckoutVersionSkewRemediation()}${c.reset}`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
246
265
|
console.log();
|
|
247
266
|
}
|
|
248
267
|
|
|
@@ -355,6 +374,9 @@ ${c.bold}Examples:${c.reset}
|
|
|
355
374
|
}
|
|
356
375
|
|
|
357
376
|
if (isCliEntrypoint(import.meta.url)) {
|
|
377
|
+
// Dogfood/checkout: unset PI_SPINE_ROOT + worktreeSetupHook must not fail
|
|
378
|
+
// doctor/preflight solely for a missing env var (SP-643 / #203).
|
|
379
|
+
ensureDefaultPiSpineRootEnv();
|
|
358
380
|
const [command = "help", ...args] = process.argv.slice(2);
|
|
359
381
|
|
|
360
382
|
const runCli = async () => {
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
ensureLandLoopFinalizedAfterGateOrIntegrate,
|
|
8
9
|
finalizeAttachedLandLoopBeforeExit,
|
|
9
10
|
finalizeResumedBatchForIntegrate,
|
|
10
11
|
isPostMergeLimbo,
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
import { detectPostMergeLimboForResume } from "./resume-multi-validate.mjs";
|
|
13
14
|
import { terminateStaleDetachedEngine } from "./resume-engine.mjs";
|
|
14
15
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
15
|
-
import { readJournalEventsCached } from "./journal.mjs";
|
|
16
|
+
import { readJournalEvents, readJournalEventsCached } from "./journal.mjs";
|
|
16
17
|
import { enforceOperatorPauseOnDisk } from "./pause.mjs";
|
|
17
18
|
import { loadSpineBatchState, saveSpineBatchState } from "./state.mjs";
|
|
18
19
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
@@ -25,6 +26,75 @@ import {
|
|
|
25
26
|
|
|
26
27
|
export { DEFAULT_ATTACHED_MILESTONE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
27
28
|
|
|
29
|
+
/** Journal types that mean the land loop is done and a stuck resume engine should exit (#198). */
|
|
30
|
+
const HOST_LAND_LOOP_EXIT_TYPES = new Set([
|
|
31
|
+
"integrate.completed",
|
|
32
|
+
"gate.approved",
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
/** Journal types that mean gate/integrate artifacts exist and finalize should run. */
|
|
36
|
+
const LAND_LOOP_ENSURE_TYPES = new Set([
|
|
37
|
+
"gate.opened",
|
|
38
|
+
"gate.approved",
|
|
39
|
+
"integrate.completed",
|
|
40
|
+
"batch.land_loop_finalized",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* When host opens/approves the gate or integrates while this engine is mid-evidence,
|
|
45
|
+
* finalize land-loop artifacts and exit so we are not a zombie PID (#198 / SP-636).
|
|
46
|
+
*
|
|
47
|
+
* @param {object} params
|
|
48
|
+
* @param {string} params.projectRoot
|
|
49
|
+
* @param {object} params.event
|
|
50
|
+
* @param {(code?: number) => void} [params.exitProcess]
|
|
51
|
+
*/
|
|
52
|
+
export function maybeFinalizeAttachedEngineAfterHostLandLoop({
|
|
53
|
+
projectRoot,
|
|
54
|
+
event,
|
|
55
|
+
exitProcess = (code) => process.exit(code),
|
|
56
|
+
}) {
|
|
57
|
+
const type = String(event?.type ?? "");
|
|
58
|
+
if (!LAND_LOOP_ENSURE_TYPES.has(type)) {
|
|
59
|
+
return { handled: false, reason: "not_land_loop_event" };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const loaded = loadSpineBatchState(projectRoot);
|
|
63
|
+
if (!loaded.raw?.batchId) {
|
|
64
|
+
return { handled: false, reason: "no_active_batch" };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const state = loaded.raw;
|
|
68
|
+
const batchId = String(state.batchId);
|
|
69
|
+
const resumed = readJournalEvents(projectRoot, batchId).some(
|
|
70
|
+
(entry) => entry.type === "batch.resumed",
|
|
71
|
+
);
|
|
72
|
+
const ensured = ensureLandLoopFinalizedAfterGateOrIntegrate({
|
|
73
|
+
projectRoot,
|
|
74
|
+
state,
|
|
75
|
+
batchId,
|
|
76
|
+
resumed,
|
|
77
|
+
resumeForced: Boolean(state.resilience?.resumeForced),
|
|
78
|
+
source: "attached_milestone_host_land_loop",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!ensured) {
|
|
82
|
+
return { handled: false, reason: "ensure_not_applicable" };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (HOST_LAND_LOOP_EXIT_TYPES.has(type) || ensured.shouldExit) {
|
|
86
|
+
exitProcess(0);
|
|
87
|
+
return { handled: true, action: "exited_after_host_land_loop", batchId, result: ensured };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
handled: true,
|
|
92
|
+
action: ensured.changed ? "finalized_after_gate_opened" : "already_finalized",
|
|
93
|
+
batchId,
|
|
94
|
+
result: ensured,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
28
98
|
/** @type {boolean} */
|
|
29
99
|
let attachedExitHandlersInstalled = false;
|
|
30
100
|
|
|
@@ -109,12 +179,14 @@ export function formatAttachedMilestoneLine(event) {
|
|
|
109
179
|
* @param {string} params.projectRoot
|
|
110
180
|
* @param {(line: string) => void} [params.write]
|
|
111
181
|
* @param {number} [params.pollIntervalMs]
|
|
182
|
+
* @param {(code?: number) => void} [params.exitProcess]
|
|
112
183
|
* @returns {Promise<{ stop: () => Promise<void> }>}
|
|
113
184
|
*/
|
|
114
185
|
export async function startAttachedMilestoneReporter({
|
|
115
186
|
projectRoot,
|
|
116
187
|
write = (line) => process.stdout.write(line),
|
|
117
188
|
pollIntervalMs,
|
|
189
|
+
exitProcess = (code) => process.exit(code),
|
|
118
190
|
}) {
|
|
119
191
|
const configResult = loadSpineConfig(projectRoot);
|
|
120
192
|
const resolvedPollMs =
|
|
@@ -125,6 +197,26 @@ export async function startAttachedMilestoneReporter({
|
|
|
125
197
|
let batchId = null;
|
|
126
198
|
let stopped = false;
|
|
127
199
|
|
|
200
|
+
const emitAndMaybeFinalize = (event) => {
|
|
201
|
+
const key = milestoneEventKey(event);
|
|
202
|
+
if (printed.has(key)) return;
|
|
203
|
+
const type = String(event.type ?? "");
|
|
204
|
+
const isMilestone = ATTACHED_LAND_LOOP_MILESTONE_TYPES.has(type);
|
|
205
|
+
const isLandLoopEnsure = LAND_LOOP_ENSURE_TYPES.has(type);
|
|
206
|
+
if (!isMilestone && !isLandLoopEnsure) return;
|
|
207
|
+
printed.add(key);
|
|
208
|
+
if (isMilestone) {
|
|
209
|
+
write(formatAttachedMilestoneLine(event));
|
|
210
|
+
}
|
|
211
|
+
if (isLandLoopEnsure) {
|
|
212
|
+
maybeFinalizeAttachedEngineAfterHostLandLoop({
|
|
213
|
+
projectRoot,
|
|
214
|
+
event,
|
|
215
|
+
exitProcess,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
128
220
|
const loop = async () => {
|
|
129
221
|
while (!stopped) {
|
|
130
222
|
enforceOperatorPauseOnDisk(projectRoot);
|
|
@@ -135,11 +227,7 @@ export async function startAttachedMilestoneReporter({
|
|
|
135
227
|
if (batchId) {
|
|
136
228
|
const events = readJournalEventsCached(projectRoot, batchId);
|
|
137
229
|
for (const event of events) {
|
|
138
|
-
|
|
139
|
-
if (printed.has(key)) continue;
|
|
140
|
-
if (!ATTACHED_LAND_LOOP_MILESTONE_TYPES.has(String(event.type ?? ""))) continue;
|
|
141
|
-
printed.add(key);
|
|
142
|
-
write(formatAttachedMilestoneLine(event));
|
|
230
|
+
emitAndMaybeFinalize(event);
|
|
143
231
|
}
|
|
144
232
|
}
|
|
145
233
|
await sleep(resolvedPollMs);
|
|
@@ -155,11 +243,7 @@ export async function startAttachedMilestoneReporter({
|
|
|
155
243
|
if (batchId) {
|
|
156
244
|
const events = readJournalEventsCached(projectRoot, batchId);
|
|
157
245
|
for (const event of events) {
|
|
158
|
-
|
|
159
|
-
if (printed.has(key)) continue;
|
|
160
|
-
if (!ATTACHED_LAND_LOOP_MILESTONE_TYPES.has(String(event.type ?? ""))) continue;
|
|
161
|
-
printed.add(key);
|
|
162
|
-
write(formatAttachedMilestoneLine(event));
|
|
246
|
+
emitAndMaybeFinalize(event);
|
|
163
247
|
}
|
|
164
248
|
}
|
|
165
249
|
},
|
|
@@ -7,11 +7,29 @@ import { buildWorkerDoneMissingAlternatives } from "./diagnosis-worker-done-miss
|
|
|
7
7
|
* @param {string} diagnosis
|
|
8
8
|
* @param {object} [ctx]
|
|
9
9
|
* @param {string|null} [ctx.failedTaskId]
|
|
10
|
+
* @param {string|null} [ctx.batchId]
|
|
11
|
+
* @param {object[]} [ctx.pendingLaneLandTasks]
|
|
10
12
|
*/
|
|
11
13
|
export function buildAlternatives(diagnosis, ctx = {}) {
|
|
12
14
|
const common = ["spine status --diagnose"];
|
|
13
15
|
|
|
16
|
+
if ((ctx.pendingLaneLandTasks?.length ?? 0) > 0) {
|
|
17
|
+
return [
|
|
18
|
+
ctx.batchId
|
|
19
|
+
? `spine batch salvage --batch ${ctx.batchId} --dry-run`
|
|
20
|
+
: "spine batch salvage --batch <batchId> --dry-run",
|
|
21
|
+
...common,
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
switch (diagnosis) {
|
|
26
|
+
case "pending_lane_land":
|
|
27
|
+
return [
|
|
28
|
+
ctx.batchId
|
|
29
|
+
? `spine batch salvage --batch ${ctx.batchId} --dry-run`
|
|
30
|
+
: "spine batch salvage --batch <batchId> --dry-run",
|
|
31
|
+
...common,
|
|
32
|
+
];
|
|
15
33
|
case "limbo_stale":
|
|
16
34
|
return ["spine batch complete --detect-manual-merge", ...common];
|
|
17
35
|
case "completed_manual":
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Gate-ready headline context — demote historical merge blockers (#195 / FR-REL231-01).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gate-ready batches must not headline historical merge/gitignored blockers (#195 / FR-REL231-01).
|
|
8
|
+
*
|
|
9
|
+
* @param {string} diagnosis
|
|
10
|
+
* @param {object} [ctx]
|
|
11
|
+
* @param {boolean} [ctx.allTasksTerminalSuccess]
|
|
12
|
+
* @param {boolean} [ctx.integrateGateOpen]
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
export function isGateReadyHeadlineContext(diagnosis, ctx = {}) {
|
|
16
|
+
if (diagnosis === "needs_integrate") {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (ctx.allTasksTerminalSuccess === true && ctx.integrateGateOpen === true) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Pending lane land diagnosis — lane `.DONE` without main land (#201 / SP-645).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tasks with lane `.DONE` but not on main — lane commits never landed (#201 / SP-645).
|
|
8
|
+
*
|
|
9
|
+
* @param {object[]|undefined} tasks
|
|
10
|
+
* @returns {object[]}
|
|
11
|
+
*/
|
|
12
|
+
export function findPendingLaneLandTasks(tasks) {
|
|
13
|
+
if (!Array.isArray(tasks)) return [];
|
|
14
|
+
return tasks.filter((task) => task?.doneInLane === true && task?.doneOnMain !== true);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} signals
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
export function shouldDiagnosePendingLaneLand(signals) {
|
|
22
|
+
const pending = findPendingLaneLandTasks(signals.tasks);
|
|
23
|
+
if (pending.length === 0) return false;
|
|
24
|
+
// Only when orch already appears merged — otherwise healthy pre-integrate
|
|
25
|
+
// waves (doneInLane, awaiting integrate) must stay needs_integrate / settled.
|
|
26
|
+
if (signals.git?.orchMergedToBase !== true) return false;
|
|
27
|
+
if (signals.stateDrift?.drifted === true) return true;
|
|
28
|
+
if (signals.allTasksTerminalSuccess !== true) return false;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {string|null|undefined} batchId
|
|
34
|
+
* @param {object[]} pendingTasks
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
export function buildPendingLaneLandSuggestedCommand(batchId, pendingTasks) {
|
|
38
|
+
const laneNumber = Number(pendingTasks[0]?.laneNumber);
|
|
39
|
+
if (batchId && Number.isFinite(laneNumber) && laneNumber > 0) {
|
|
40
|
+
return `spine batch salvage --batch ${batchId} --lane ${laneNumber} --integrate`;
|
|
41
|
+
}
|
|
42
|
+
if (batchId) {
|
|
43
|
+
return `spine batch salvage --batch ${batchId} --dry-run`;
|
|
44
|
+
}
|
|
45
|
+
return "spine batch salvage --batch <batchId> --dry-run";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} batchLabel
|
|
50
|
+
* @param {object} ctx
|
|
51
|
+
* @param {string|null|undefined} [ctx.batchId]
|
|
52
|
+
* @param {object[]} [ctx.pendingLaneLandTasks]
|
|
53
|
+
* @param {string|null|undefined} [ctx.baseBranch]
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
export function buildPendingLaneLandHeadline(batchLabel, ctx = {}) {
|
|
57
|
+
const pendingTaskIds = (ctx.pendingLaneLandTasks ?? [])
|
|
58
|
+
.map((task) => String(task.taskId ?? ""))
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
const baseBranch = ctx.baseBranch ?? "main";
|
|
61
|
+
const taskSuffix = pendingTaskIds.length > 0 ? ` (${pendingTaskIds.join(", ")})` : "";
|
|
62
|
+
return `${batchLabel} has lane work not on ${baseBranch}${taskSuffix} — salvage integrate`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Retry suggestion sanitization — journal salvage payloads may be stale.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const INVALID_BARE_RETRY_FORCE = /^spine batch retry --force$/;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Retry suggestions must include a task id; journal salvage payloads may be stale.
|
|
10
|
+
*
|
|
11
|
+
* @param {string|null|undefined} command
|
|
12
|
+
* @param {string|null|undefined} taskId
|
|
13
|
+
* @returns {string|null}
|
|
14
|
+
*/
|
|
15
|
+
export function sanitizeRetrySuggestedCommand(command, taskId) {
|
|
16
|
+
if (typeof command !== "string" || command.length === 0) {
|
|
17
|
+
return command ?? null;
|
|
18
|
+
}
|
|
19
|
+
if (INVALID_BARE_RETRY_FORCE.test(command.trim())) {
|
|
20
|
+
return taskId ? `spine batch retry ${taskId}` : "spine status --diagnose";
|
|
21
|
+
}
|
|
22
|
+
return command;
|
|
23
|
+
}
|
|
@@ -7,12 +7,77 @@ import { macroPhaseLabel } from "./macro-phase.mjs";
|
|
|
7
7
|
|
|
8
8
|
export { isRunningWithoutActiveWorkers };
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Whether batch-state records a live resume/batch engine PID (#198 / SP-637).
|
|
12
|
+
*
|
|
13
|
+
* @param {object} ctx
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export function isEngineStillRunning(ctx = {}) {
|
|
17
|
+
if (ctx.engineStillRunning === true) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const enginePid = ctx.enginePid;
|
|
21
|
+
if (enginePid == null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (ctx.staleEnginePid === true) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Post-integrate limbo: orch merged, tasks terminal-success, engine PID still alive.
|
|
32
|
+
* Stale segment pending must not mask limbo when lane workers are idle (#198 / SP-637).
|
|
33
|
+
*
|
|
34
|
+
* @param {object} ctx
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
export function isPostIntegrateEngineLimbo(ctx = {}) {
|
|
38
|
+
if (ctx.allTasksTerminalSuccess !== true) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (ctx.gitMerged !== true) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!isEngineStillRunning(ctx)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (ctx.hasRunningTasks === true) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const phase = ctx.phase ?? "";
|
|
51
|
+
if (phase !== "running" && phase !== "merging") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} batchLabel
|
|
59
|
+
* @param {object} ctx
|
|
60
|
+
* @returns {string|null}
|
|
61
|
+
*/
|
|
62
|
+
export function buildPostIntegrateEngineLimboHeadline(batchLabel, ctx = {}) {
|
|
63
|
+
const enginePid = ctx.enginePid;
|
|
64
|
+
const pidSuffix =
|
|
65
|
+
enginePid != null && Number.isFinite(Number(enginePid))
|
|
66
|
+
? ` (PID ${enginePid})`
|
|
67
|
+
: "";
|
|
68
|
+
return `${batchLabel} resume engine still running after integrate${pidSuffix} — wait, abort, or batch complete after exit`;
|
|
69
|
+
}
|
|
70
|
+
|
|
10
71
|
/**
|
|
11
72
|
* @param {string} batchLabel
|
|
12
73
|
* @param {object} ctx
|
|
13
74
|
* @returns {string|null}
|
|
14
75
|
*/
|
|
15
76
|
export function buildRunningTailHeadline(batchLabel, ctx = {}) {
|
|
77
|
+
if (isPostIntegrateEngineLimbo(ctx)) {
|
|
78
|
+
return buildPostIntegrateEngineLimboHeadline(batchLabel, ctx);
|
|
79
|
+
}
|
|
80
|
+
|
|
16
81
|
if (!isRunningWithoutActiveWorkers(ctx)) {
|
|
17
82
|
return null;
|
|
18
83
|
}
|
|
@@ -38,6 +103,9 @@ export function buildRunningTailHeadline(batchLabel, ctx = {}) {
|
|
|
38
103
|
}
|
|
39
104
|
|
|
40
105
|
if (macroPhase === "reviewing") {
|
|
106
|
+
if (ctx.allTasksTerminalSuccess === true && isEngineStillRunning(ctx)) {
|
|
107
|
+
return buildPostIntegrateEngineLimboHeadline(batchLabel, ctx);
|
|
108
|
+
}
|
|
41
109
|
return `${batchLabel} running reviews — no workers scheduled`;
|
|
42
110
|
}
|
|
43
111
|
|
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -23,8 +23,14 @@ export {
|
|
|
23
23
|
inferMergeGitignoredFailure,
|
|
24
24
|
summarizeMergeFailures,
|
|
25
25
|
} from "./diagnosis-merge-failure.mjs";
|
|
26
|
-
import { buildRunningTailHeadline } from "./diagnosis-tail-state.mjs";
|
|
27
|
-
export {
|
|
26
|
+
import { buildRunningTailHeadline, isPostIntegrateEngineLimbo, buildPostIntegrateEngineLimboHeadline } from "./diagnosis-tail-state.mjs";
|
|
27
|
+
export {
|
|
28
|
+
buildPostIntegrateEngineLimboHeadline,
|
|
29
|
+
buildRunningTailHeadline,
|
|
30
|
+
isEngineStillRunning,
|
|
31
|
+
isPostIntegrateEngineLimbo,
|
|
32
|
+
isRunningWithoutActiveWorkers,
|
|
33
|
+
} from "./diagnosis-tail-state.mjs";
|
|
28
34
|
export { buildReviewHonorHeadlineSuffix, findLatestReviewHonorSignal } from "./review.mjs";
|
|
29
35
|
import {
|
|
30
36
|
buildStubFailureHeadline,
|
|
@@ -53,44 +59,20 @@ export {
|
|
|
53
59
|
} from "./diagnosis-parent-exit.mjs";
|
|
54
60
|
import { buildReviewHonorHeadlineSuffix } from "./review.mjs";
|
|
55
61
|
export { inferLaunchFailureFromWorkerOutputTail, inferLaunchFailureKind } from "./diagnosis-launch-failure.mjs";
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
if (ctx.allTasksTerminalSuccess === true && ctx.integrateGateOpen === true) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Retry suggestions must include a task id; journal salvage payloads may be stale.
|
|
80
|
-
*
|
|
81
|
-
* @param {string|null|undefined} command
|
|
82
|
-
* @param {string|null|undefined} taskId
|
|
83
|
-
* @returns {string|null}
|
|
84
|
-
*/
|
|
85
|
-
export function sanitizeRetrySuggestedCommand(command, taskId) {
|
|
86
|
-
if (typeof command !== "string" || command.length === 0) {
|
|
87
|
-
return command ?? null;
|
|
88
|
-
}
|
|
89
|
-
if (INVALID_BARE_RETRY_FORCE.test(command.trim())) {
|
|
90
|
-
return taskId ? `spine batch retry ${taskId}` : "spine status --diagnose";
|
|
91
|
-
}
|
|
92
|
-
return command;
|
|
93
|
-
}
|
|
62
|
+
import { isGateReadyHeadlineContext } from "./diagnosis-gate-ready.mjs";
|
|
63
|
+
export { isGateReadyHeadlineContext };
|
|
64
|
+
import { sanitizeRetrySuggestedCommand } from "./diagnosis-retry-command.mjs";
|
|
65
|
+
export { sanitizeRetrySuggestedCommand };
|
|
66
|
+
import {
|
|
67
|
+
buildPendingLaneLandHeadline,
|
|
68
|
+
buildPendingLaneLandSuggestedCommand,
|
|
69
|
+
} from "./diagnosis-pending-lane.mjs";
|
|
70
|
+
export {
|
|
71
|
+
buildPendingLaneLandHeadline,
|
|
72
|
+
buildPendingLaneLandSuggestedCommand,
|
|
73
|
+
findPendingLaneLandTasks,
|
|
74
|
+
shouldDiagnosePendingLaneLand,
|
|
75
|
+
} from "./diagnosis-pending-lane.mjs";
|
|
94
76
|
|
|
95
77
|
export const DIAGNOSIS_TAXONOMY = [
|
|
96
78
|
"running",
|
|
@@ -108,6 +90,8 @@ export const DIAGNOSIS_TAXONOMY = [
|
|
|
108
90
|
"limbo_stale",
|
|
109
91
|
"human_base_diverged",
|
|
110
92
|
"integrate_isolated_ok",
|
|
93
|
+
"pending_lane_land",
|
|
94
|
+
"engine_still_running",
|
|
111
95
|
"failed",
|
|
112
96
|
"aborted",
|
|
113
97
|
];
|
|
@@ -118,6 +102,7 @@ const NO_PAUSE_DIAGNOSES = new Set([
|
|
|
118
102
|
"needs_integrate",
|
|
119
103
|
"engine_orphaned",
|
|
120
104
|
"integrate_isolated_ok",
|
|
105
|
+
"engine_still_running",
|
|
121
106
|
]);
|
|
122
107
|
const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
|
|
123
108
|
"code_review_spawn_failed",
|
|
@@ -138,6 +123,7 @@ const REVIEW_SPAWN_FAILURE_EXIT_REASONS = new Set([
|
|
|
138
123
|
* @param {boolean} [ctx.mergeFailed]
|
|
139
124
|
* @param {string|null} [ctx.taskBranch]
|
|
140
125
|
* @param {string[]|null} [ctx.gitignoredPaths]
|
|
126
|
+
* @param {object[]} [ctx.pendingLaneLandTasks]
|
|
141
127
|
*/
|
|
142
128
|
export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
143
129
|
const preferGateReady = isGateReadyHeadlineContext(diagnosis, ctx);
|
|
@@ -157,6 +143,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
157
143
|
}
|
|
158
144
|
|
|
159
145
|
switch (diagnosis) {
|
|
146
|
+
case "engine_still_running":
|
|
147
|
+
return "spine wait --until completed,failed,needs_integrate --timeout 2h";
|
|
160
148
|
case "limbo_stale":
|
|
161
149
|
case "completed_manual":
|
|
162
150
|
return "spine batch dismiss";
|
|
@@ -182,10 +170,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
182
170
|
if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
|
|
183
171
|
return buildStubFailureSuggestedCommand(ctx);
|
|
184
172
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (primaryCommand) return primaryCommand;
|
|
188
|
-
}
|
|
173
|
+
const primaryCommand = buildPrimaryFailureSuggestedCommand(ctx);
|
|
174
|
+
if (primaryCommand) return primaryCommand;
|
|
189
175
|
if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
|
|
190
176
|
return "spine doctor";
|
|
191
177
|
}
|
|
@@ -274,6 +260,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
274
260
|
return "spine sync-base";
|
|
275
261
|
case "integrate_isolated_ok":
|
|
276
262
|
return "spine sync-base";
|
|
263
|
+
case "pending_lane_land":
|
|
264
|
+
return buildPendingLaneLandSuggestedCommand(ctx.batchId, ctx.pendingLaneLandTasks ?? []);
|
|
277
265
|
default:
|
|
278
266
|
return "spine status --diagnose";
|
|
279
267
|
}
|
|
@@ -298,6 +286,8 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
298
286
|
* @param {string|null} [ctx.lastError]
|
|
299
287
|
* @param {number} [ctx.succeededTasks]
|
|
300
288
|
* @param {number} [ctx.totalTasks]
|
|
289
|
+
* @param {object[]} [ctx.pendingLaneLandTasks]
|
|
290
|
+
* @param {string|null|undefined} [ctx.baseBranch]
|
|
301
291
|
*/
|
|
302
292
|
export function buildHeadline(diagnosis, ctx = {}) {
|
|
303
293
|
const batchLabel = ctx.batchId ? `Batch ${ctx.batchId}` : "Batch";
|
|
@@ -317,6 +307,17 @@ export function buildHeadline(diagnosis, ctx = {}) {
|
|
|
317
307
|
}
|
|
318
308
|
|
|
319
309
|
switch (diagnosis) {
|
|
310
|
+
case "engine_still_running": {
|
|
311
|
+
const enginePid = ctx.enginePid;
|
|
312
|
+
const pidSuffix =
|
|
313
|
+
enginePid != null && Number.isFinite(Number(enginePid))
|
|
314
|
+
? ` (PID ${enginePid})`
|
|
315
|
+
: "";
|
|
316
|
+
if (ctx.gitMerged === true) {
|
|
317
|
+
return `${batchLabel} resume engine still running after integrate${pidSuffix} — wait, abort, or batch complete after exit`;
|
|
318
|
+
}
|
|
319
|
+
return `${batchLabel} engine still running${pidSuffix} — complete refused`;
|
|
320
|
+
}
|
|
320
321
|
case "limbo_stale":
|
|
321
322
|
return `${batchLabel} finished but state is stale — dismiss to clear`;
|
|
322
323
|
case "completed_manual":
|
|
@@ -325,10 +326,8 @@ export function buildHeadline(diagnosis, ctx = {}) {
|
|
|
325
326
|
if (STUB_EXIT_REASONS.has(ctx.exitReason ?? "")) {
|
|
326
327
|
return buildStubFailureHeadline(batchLabel, ctx);
|
|
327
328
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (primaryHeadline) return primaryHeadline;
|
|
331
|
-
}
|
|
329
|
+
const primaryHeadline = buildPrimaryFailureHeadline(batchLabel, ctx);
|
|
330
|
+
if (primaryHeadline) return primaryHeadline;
|
|
332
331
|
if (ctx.launchFailureKind === "pi_spine_root" || ctx.launchFailureKind === "launch_failed") {
|
|
333
332
|
return `${batchLabel} failed at worker launch — fix PI_SPINE_ROOT/devcontainer, then retry`;
|
|
334
333
|
}
|
|
@@ -413,6 +412,9 @@ export function buildHeadline(diagnosis, ctx = {}) {
|
|
|
413
412
|
? `Task ${ctx.failedTaskId} needs replan — edit PROMPT.md before retry`
|
|
414
413
|
: `${batchLabel} has tasks needing replan — edit PROMPT.md before retry`;
|
|
415
414
|
case "running": {
|
|
415
|
+
if (isPostIntegrateEngineLimbo(ctx)) {
|
|
416
|
+
return buildPostIntegrateEngineLimboHeadline(batchLabel, ctx);
|
|
417
|
+
}
|
|
416
418
|
const reviewHonorSuffix = buildReviewHonorHeadlineSuffix(ctx.reviewHonorSignal);
|
|
417
419
|
if (reviewHonorSuffix && ctx.reviewHonorSignal?.taskId) {
|
|
418
420
|
return `${batchLabel} task ${ctx.reviewHonorSignal.taskId}: ${reviewHonorSuffix}`;
|
|
@@ -444,6 +446,8 @@ export function buildHeadline(diagnosis, ctx = {}) {
|
|
|
444
446
|
}
|
|
445
447
|
case "integrate_isolated_ok":
|
|
446
448
|
return `${batchLabel} — isolated integrate landed; sync human checkout with base`;
|
|
449
|
+
case "pending_lane_land":
|
|
450
|
+
return buildPendingLaneLandHeadline(batchLabel, ctx);
|
|
447
451
|
default:
|
|
448
452
|
return `${batchLabel} requires attention (phase: ${ctx.phase ?? "unknown"})`;
|
|
449
453
|
}
|
|
@@ -456,16 +460,29 @@ export function shouldNeverSuggestPause(diagnosis) {
|
|
|
456
460
|
return NO_PAUSE_DIAGNOSES.has(diagnosis);
|
|
457
461
|
}
|
|
458
462
|
|
|
463
|
+
/**
|
|
464
|
+
* @param {string} diagnosis
|
|
465
|
+
* @param {object} ctx
|
|
466
|
+
* @returns {string}
|
|
467
|
+
*/
|
|
468
|
+
export function resolveEffectiveDiagnosis(diagnosis, ctx = {}) {
|
|
469
|
+
if (diagnosis === "running" && isPostIntegrateEngineLimbo(ctx)) {
|
|
470
|
+
return "engine_still_running";
|
|
471
|
+
}
|
|
472
|
+
return diagnosis;
|
|
473
|
+
}
|
|
474
|
+
|
|
459
475
|
/**
|
|
460
476
|
* @param {string} diagnosis
|
|
461
477
|
* @param {object} ctx
|
|
462
478
|
* @returns {Pick<ReconciliationResult, "diagnosis" | "headline" | "suggestedCommand" | "alternatives">}
|
|
463
479
|
*/
|
|
464
480
|
export function buildDiagnosisOutput(diagnosis, ctx = {}) {
|
|
481
|
+
const effectiveDiagnosis = resolveEffectiveDiagnosis(diagnosis, ctx);
|
|
465
482
|
return {
|
|
466
|
-
diagnosis,
|
|
467
|
-
headline: buildHeadline(
|
|
468
|
-
suggestedCommand: buildSuggestedCommand(
|
|
469
|
-
alternatives: buildAlternatives(
|
|
483
|
+
diagnosis: effectiveDiagnosis,
|
|
484
|
+
headline: buildHeadline(effectiveDiagnosis, ctx),
|
|
485
|
+
suggestedCommand: buildSuggestedCommand(effectiveDiagnosis, ctx),
|
|
486
|
+
alternatives: buildAlternatives(effectiveDiagnosis, ctx),
|
|
470
487
|
};
|
|
471
488
|
}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import { runWorker } from "./worker-host.mjs";
|
|
24
24
|
import { runCodeReviewPhase, runFinalReviewPhase } from "./engine-lanes/review.mjs";
|
|
25
25
|
import { ensureLaneSyncedForSharedScopeDeps } from "./engine-lanes/orch-sync.mjs";
|
|
26
|
+
import { resolveWorktreeSetupIgnorePaths } from "../config/spine-config-load.mjs";
|
|
26
27
|
|
|
27
28
|
export {
|
|
28
29
|
buildTasksAndLanesFromPlan,
|
|
@@ -347,9 +348,7 @@ export async function runTaskOnLane({
|
|
|
347
348
|
}
|
|
348
349
|
}
|
|
349
350
|
|
|
350
|
-
const ignorePatterns =
|
|
351
|
-
? config.worktreeSetupIgnorePaths
|
|
352
|
-
: [];
|
|
351
|
+
const ignorePatterns = resolveWorktreeSetupIgnorePaths(config);
|
|
353
352
|
const commitResult = commitLaneAndValidateWorktree({
|
|
354
353
|
worktreePath: wt,
|
|
355
354
|
taskBranch,
|