pi-spine 1.4.0 → 1.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-batch.mjs +3 -2
- package/bin/spine.mjs +12 -0
- package/extensions/spine/slash-commands.ts +170 -1
- package/package.json +6 -3
- package/skills/create-spine-tasks/SKILL.md +13 -1
- package/skills/create-spine-tasks/references/contract-template.md +6 -3
- package/skills/create-spine-tasks/references/requirements-checklist-template.md +1 -0
- package/skills/spine-orchestrate-waves/SKILL.md +200 -0
- package/skills/spine-orchestrate-waves/references/outer-loop.md +165 -0
- package/skills/spine-release-operator/SKILL.md +341 -0
- package/skills/spine-release-operator/references/issue-intake-checklist.md +107 -0
- package/skills/spine-release-operator/references/issue-template.md +51 -0
- package/skills/spine-release-operator/references/release-manifest-template.md +76 -0
- package/skills/spine-release-operator/references/release-profiles.md +100 -0
- package/src/batch/batch-state-io.mjs +137 -0
- package/src/batch/contract-prelanded.mjs +116 -14
- package/src/batch/contract-verify.mjs +48 -2
- package/src/batch/diagnosis-alternatives.mjs +8 -0
- package/src/batch/diagnosis.mjs +28 -2
- package/src/batch/engine-lanes/commit.mjs +6 -0
- package/src/batch/engine.mjs +10 -1
- package/src/batch/integrate-worktree.mjs +65 -15
- package/src/batch/lane-dirty-check.mjs +124 -0
- package/src/batch/lifecycle.mjs +10 -6
- package/src/batch/reconcile.mjs +254 -0
- package/src/batch/sequence-waves.mjs +221 -0
- package/src/batch/sequence.mjs +117 -4
- package/src/batch/state.mjs +18 -1
- package/src/cli/batch-complete.mjs +16 -0
- package/src/cli/sync-base.mjs +354 -0
- package/src/config/defaults.mjs +8 -1
- package/src/config/spine-preflight-lib.mjs +146 -2
- package/src/doctor/agents-model-inherit.mjs +318 -0
- package/src/doctor/run-doctor-checks.mjs +14 -0
- package/templates/spine-config.json +4 -0
- package/templates/spine-worktree-setup-flutter.sh +44 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planner sequence wave policy after merge_blocked (GitHub #82, SP-437).
|
|
3
|
+
* Evaluates whether later waves can run per dependencies.json / plan.tasks deps.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {object|null|undefined} batchState
|
|
8
|
+
* @returns {{ succeeded: string[], failed: string[], skipped: string[], pending: string[] }}
|
|
9
|
+
*/
|
|
10
|
+
export function collectWaveTaskOutcomes(batchState) {
|
|
11
|
+
const tasks = batchState?.tasks ?? [];
|
|
12
|
+
/** @type {string[]} */
|
|
13
|
+
const succeeded = [];
|
|
14
|
+
/** @type {string[]} */
|
|
15
|
+
const failed = [];
|
|
16
|
+
/** @type {string[]} */
|
|
17
|
+
const skipped = [];
|
|
18
|
+
/** @type {string[]} */
|
|
19
|
+
const pending = [];
|
|
20
|
+
|
|
21
|
+
for (const task of tasks) {
|
|
22
|
+
const taskId = String(task?.taskId ?? "");
|
|
23
|
+
if (!taskId) continue;
|
|
24
|
+
const status = String(task?.status ?? "");
|
|
25
|
+
if (status === "succeeded") succeeded.push(taskId);
|
|
26
|
+
else if (status === "failed") failed.push(taskId);
|
|
27
|
+
else if (status === "skipped") skipped.push(taskId);
|
|
28
|
+
else if (status === "pending" || status === "running") pending.push(taskId);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { succeeded, failed, skipped, pending };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {object} [params]
|
|
36
|
+
* @param {object|null} [params.startResult]
|
|
37
|
+
* @param {object|null} [params.reconciliation]
|
|
38
|
+
*/
|
|
39
|
+
export function isMergeBlockedBatchOutcome({ startResult = null, reconciliation = null } = {}) {
|
|
40
|
+
if (startResult?.error === "mixed_outcome_merge_blocked") return true;
|
|
41
|
+
const phase = reconciliation?.phase ?? reconciliation?.signals?.raw?.phase ?? null;
|
|
42
|
+
if (phase === "merge_blocked") return true;
|
|
43
|
+
const lastError = String(reconciliation?.signals?.raw?.lastError ?? "");
|
|
44
|
+
if (phase === "failed" && lastError.includes("§17.4")) return true;
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {Iterable<string>} doneOnMainTaskIds
|
|
50
|
+
* @param {Array<{ succeeded?: string[], skipped?: string[] }>} priorOutcomes
|
|
51
|
+
*/
|
|
52
|
+
export function buildSequenceSatisfiedTaskIds(doneOnMainTaskIds = [], priorOutcomes = []) {
|
|
53
|
+
const satisfied = new Set(doneOnMainTaskIds);
|
|
54
|
+
for (const outcome of priorOutcomes) {
|
|
55
|
+
for (const taskId of outcome.succeeded ?? []) satisfied.add(taskId);
|
|
56
|
+
for (const taskId of outcome.skipped ?? []) satisfied.add(taskId);
|
|
57
|
+
}
|
|
58
|
+
return satisfied;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {object} params
|
|
63
|
+
* @param {object} params.plan
|
|
64
|
+
* @param {string[]} params.waveTaskIds
|
|
65
|
+
* @param {Set<string>} params.satisfiedTaskIds
|
|
66
|
+
*/
|
|
67
|
+
export function evaluateWaveTaskDependencies({ plan, waveTaskIds, satisfiedTaskIds }) {
|
|
68
|
+
const tasks = plan?.tasks ?? {};
|
|
69
|
+
/** @type {string[]} */
|
|
70
|
+
const runnable = [];
|
|
71
|
+
/** @type {Array<{ taskId: string, unsatisfiedDeps: string[] }>} */
|
|
72
|
+
const blocked = [];
|
|
73
|
+
|
|
74
|
+
for (const taskId of waveTaskIds) {
|
|
75
|
+
const deps = tasks[taskId]?.dependencies ?? [];
|
|
76
|
+
const unsatisfiedDeps = deps.filter((depId) => !satisfiedTaskIds.has(depId));
|
|
77
|
+
if (unsatisfiedDeps.length === 0) {
|
|
78
|
+
runnable.push(taskId);
|
|
79
|
+
} else {
|
|
80
|
+
blocked.push({ taskId, unsatisfiedDeps });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { runnable, blocked };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {object} params
|
|
89
|
+
* @param {number} params.waveIndex
|
|
90
|
+
* @param {Array<{ taskId: string, unsatisfiedDeps: string[] }>} params.blocked
|
|
91
|
+
* @param {number} params.mergeBlockedWaveIndex
|
|
92
|
+
* @param {string[]} [params.failedTaskIds]
|
|
93
|
+
* @param {string[]} [params.succeededTaskIds]
|
|
94
|
+
*/
|
|
95
|
+
export function formatSequenceWaveSkipMessage({
|
|
96
|
+
waveIndex,
|
|
97
|
+
blocked,
|
|
98
|
+
mergeBlockedWaveIndex,
|
|
99
|
+
failedTaskIds = [],
|
|
100
|
+
succeededTaskIds = [],
|
|
101
|
+
}) {
|
|
102
|
+
const lines = [
|
|
103
|
+
`Sequence wave ${waveIndex} skipped (§17.4 mixed-outcome policy — wave ${mergeBlockedWaveIndex} merge blocked).`,
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
if (succeededTaskIds.length > 0) {
|
|
107
|
+
lines.push(`Prior wave succeeded task(s): ${succeededTaskIds.join(", ")}.`);
|
|
108
|
+
}
|
|
109
|
+
if (failedTaskIds.length > 0) {
|
|
110
|
+
lines.push(`Prior wave failed task(s): ${failedTaskIds.join(", ")}.`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const entry of blocked) {
|
|
114
|
+
lines.push(
|
|
115
|
+
` ${entry.taskId}: blocked by unsatisfied dependencies ${entry.unsatisfiedDeps.join(", ")}.`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (blocked.length === 0) {
|
|
120
|
+
lines.push(` No runnable tasks in wave ${waveIndex}.`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
lines.push(
|
|
124
|
+
"Retry or skip failed tasks on the blocked wave, or land succeeded lanes before dependencies unblock.",
|
|
125
|
+
);
|
|
126
|
+
return lines.join("\n");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {object} params
|
|
131
|
+
* @param {object} params.plan
|
|
132
|
+
* @param {number} params.waveIndex
|
|
133
|
+
* @param {string[]} params.waveTaskIds
|
|
134
|
+
* @param {Set<string>} params.satisfiedTaskIds
|
|
135
|
+
* @param {number} params.mergeBlockedWaveIndex
|
|
136
|
+
* @param {string[]} [params.failedTaskIds]
|
|
137
|
+
* @param {string[]} [params.succeededTaskIds]
|
|
138
|
+
*/
|
|
139
|
+
export function resolveWaveAfterMergeBlocked({
|
|
140
|
+
plan,
|
|
141
|
+
waveIndex,
|
|
142
|
+
waveTaskIds,
|
|
143
|
+
satisfiedTaskIds,
|
|
144
|
+
mergeBlockedWaveIndex,
|
|
145
|
+
failedTaskIds = [],
|
|
146
|
+
succeededTaskIds = [],
|
|
147
|
+
}) {
|
|
148
|
+
const { runnable, blocked } = evaluateWaveTaskDependencies({
|
|
149
|
+
plan,
|
|
150
|
+
waveTaskIds,
|
|
151
|
+
satisfiedTaskIds,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (runnable.length === 0) {
|
|
155
|
+
return {
|
|
156
|
+
action: "skip",
|
|
157
|
+
runnableTaskIds: [],
|
|
158
|
+
blocked,
|
|
159
|
+
message: formatSequenceWaveSkipMessage({
|
|
160
|
+
waveIndex,
|
|
161
|
+
blocked,
|
|
162
|
+
mergeBlockedWaveIndex,
|
|
163
|
+
failedTaskIds,
|
|
164
|
+
succeededTaskIds,
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
action: "continue",
|
|
171
|
+
runnableTaskIds: runnable,
|
|
172
|
+
blocked,
|
|
173
|
+
skippedTaskIds: blocked.map((entry) => entry.taskId),
|
|
174
|
+
message:
|
|
175
|
+
blocked.length > 0
|
|
176
|
+
? formatSequenceWaveSkipMessage({
|
|
177
|
+
waveIndex,
|
|
178
|
+
blocked,
|
|
179
|
+
mergeBlockedWaveIndex,
|
|
180
|
+
failedTaskIds,
|
|
181
|
+
succeededTaskIds,
|
|
182
|
+
})
|
|
183
|
+
: null,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {object} params
|
|
189
|
+
* @param {object} params.plan
|
|
190
|
+
* @param {number} params.waveIndex
|
|
191
|
+
* @param {string[]} params.waveTaskIds
|
|
192
|
+
* @param {Set<string>} params.satisfiedTaskIds
|
|
193
|
+
*/
|
|
194
|
+
export function planSequenceWaveTasks({ plan, waveIndex, waveTaskIds, satisfiedTaskIds }) {
|
|
195
|
+
const { runnable, blocked } = evaluateWaveTaskDependencies({
|
|
196
|
+
plan,
|
|
197
|
+
waveTaskIds,
|
|
198
|
+
satisfiedTaskIds,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
if (runnable.length === 0) {
|
|
202
|
+
return {
|
|
203
|
+
action: "skip",
|
|
204
|
+
runnableTaskIds: [],
|
|
205
|
+
blocked,
|
|
206
|
+
message: `Sequence wave ${waveIndex} skipped — no tasks with satisfied dependencies.`,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
action: "continue",
|
|
212
|
+
runnableTaskIds: runnable,
|
|
213
|
+
blocked,
|
|
214
|
+
partialSkipMessage:
|
|
215
|
+
blocked.length > 0
|
|
216
|
+
? `Sequence wave ${waveIndex}: skipping tasks with unsatisfied dependencies: ${blocked
|
|
217
|
+
.map((entry) => entry.taskId)
|
|
218
|
+
.join(", ")}.`
|
|
219
|
+
: null,
|
|
220
|
+
};
|
|
221
|
+
}
|
package/src/batch/sequence.mjs
CHANGED
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
runBatchPreflight,
|
|
10
10
|
resolveTasksRoot,
|
|
11
11
|
} from "../config/spine-preflight-lib.mjs";
|
|
12
|
+
import { filterPendingTaskIds } from "../planner/pending.mjs";
|
|
12
13
|
import { buildPlan } from "../planner/index.mjs";
|
|
13
14
|
import { resolveWaveTaskIds } from "../planner/wave-scope.mjs";
|
|
15
|
+
import { discoverTasks } from "../tasks/packet/discover.mjs";
|
|
14
16
|
|
|
15
17
|
export { resolveWaveTaskIds };
|
|
16
18
|
import { startBatch } from "./engine.mjs";
|
|
@@ -22,6 +24,13 @@ import { completeBatch } from "./lifecycle.mjs";
|
|
|
22
24
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
23
25
|
import { loadSpineBatchState } from "./state.mjs";
|
|
24
26
|
import { validateSequenceAutoApproveGate } from "../doctor/sequence-safety.mjs";
|
|
27
|
+
import {
|
|
28
|
+
buildSequenceSatisfiedTaskIds,
|
|
29
|
+
collectWaveTaskOutcomes,
|
|
30
|
+
isMergeBlockedBatchOutcome,
|
|
31
|
+
planSequenceWaveTasks,
|
|
32
|
+
resolveWaveAfterMergeBlocked,
|
|
33
|
+
} from "./sequence-waves.mjs";
|
|
25
34
|
import {
|
|
26
35
|
buildSequenceStateSnapshot,
|
|
27
36
|
finalizeSequenceState,
|
|
@@ -379,8 +388,81 @@ export async function runSequence(ctx) {
|
|
|
379
388
|
/** @type {Array<{ waveIndex: number, batchId: string|null, diagnosis: string|null }>} */
|
|
380
389
|
const completedWaves = [...persistedCompletedWaves];
|
|
381
390
|
|
|
391
|
+
const tasksRoot = plan?.metadata?.tasksRoot ?? null;
|
|
392
|
+
const discoveredTasks = tasksRoot ? discoverTasks(tasksRoot) : [];
|
|
393
|
+
const pendingTaskIds = tasksRoot ? filterPendingTaskIds(discoveredTasks, tasksRoot) : [];
|
|
394
|
+
const doneOnMainTaskIds = discoveredTasks
|
|
395
|
+
.map((task) => task.taskId)
|
|
396
|
+
.filter((taskId) => !pendingTaskIds.includes(taskId));
|
|
397
|
+
/** @type {Array<{ succeeded?: string[], skipped?: string[], failed?: string[] }>} */
|
|
398
|
+
const priorMergeOutcomes = [];
|
|
399
|
+
let satisfiedTaskIds = buildSequenceSatisfiedTaskIds(doneOnMainTaskIds, priorMergeOutcomes);
|
|
400
|
+
let mergeBlockedWaveIndex = null;
|
|
401
|
+
let sequenceHadMergeBlocked = false;
|
|
402
|
+
/** @type {string[]} */
|
|
403
|
+
const sequenceOutputLines = [];
|
|
404
|
+
/** @type {Array<{ waveIndex: number, message: string }>} */
|
|
405
|
+
const skippedWaves = [];
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @param {number} waveIndex
|
|
409
|
+
* @param {string[]} waveTaskIds
|
|
410
|
+
*/
|
|
411
|
+
function resolveRunnableWaveTasks(waveIndex, waveTaskIds) {
|
|
412
|
+
if (mergeBlockedWaveIndex != null && waveIndex > mergeBlockedWaveIndex) {
|
|
413
|
+
const lastOutcome = priorMergeOutcomes[priorMergeOutcomes.length - 1] ?? {};
|
|
414
|
+
return resolveWaveAfterMergeBlocked({
|
|
415
|
+
plan,
|
|
416
|
+
waveIndex,
|
|
417
|
+
waveTaskIds,
|
|
418
|
+
satisfiedTaskIds,
|
|
419
|
+
mergeBlockedWaveIndex,
|
|
420
|
+
failedTaskIds: lastOutcome.failed ?? [],
|
|
421
|
+
succeededTaskIds: lastOutcome.succeeded ?? [],
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
return planSequenceWaveTasks({ plan, waveIndex, waveTaskIds, satisfiedTaskIds });
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @param {number} waveIndex
|
|
429
|
+
* @param {object|null} batchState
|
|
430
|
+
* @param {string} [fallbackMessage]
|
|
431
|
+
*/
|
|
432
|
+
function absorbMergeBlockedWave(waveIndex, batchState, fallbackMessage = "") {
|
|
433
|
+
const outcomes = collectWaveTaskOutcomes(batchState);
|
|
434
|
+
priorMergeOutcomes.push(outcomes);
|
|
435
|
+
satisfiedTaskIds = buildSequenceSatisfiedTaskIds(doneOnMainTaskIds, priorMergeOutcomes);
|
|
436
|
+
mergeBlockedWaveIndex = waveIndex;
|
|
437
|
+
sequenceHadMergeBlocked = true;
|
|
438
|
+
const message =
|
|
439
|
+
String(fallbackMessage ?? "").trim() ||
|
|
440
|
+
String(batchState?.lastError ?? "").trim() ||
|
|
441
|
+
`Wave merge blocked (§17.4 mixed-outcome policy) at wave ${waveIndex}.`;
|
|
442
|
+
sequenceOutputLines.push(message);
|
|
443
|
+
}
|
|
444
|
+
|
|
382
445
|
for (const wave of wavePlan.waves) {
|
|
383
|
-
const
|
|
446
|
+
const wavePlanResolution = resolveRunnableWaveTasks(wave.waveIndex, wave.taskIds);
|
|
447
|
+
if (wavePlanResolution.action === "skip") {
|
|
448
|
+
skippedWaves.push({
|
|
449
|
+
waveIndex: wave.waveIndex,
|
|
450
|
+
message: wavePlanResolution.message ?? `Sequence wave ${wave.waveIndex} skipped.`,
|
|
451
|
+
});
|
|
452
|
+
sequenceOutputLines.push(
|
|
453
|
+
wavePlanResolution.message ?? `Sequence wave ${wave.waveIndex} skipped.`,
|
|
454
|
+
);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (wavePlanResolution.message) {
|
|
458
|
+
sequenceOutputLines.push(wavePlanResolution.message);
|
|
459
|
+
} else if (wavePlanResolution.partialSkipMessage) {
|
|
460
|
+
sequenceOutputLines.push(wavePlanResolution.partialSkipMessage);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const taskScope = wavePlanResolution.runnableTaskIds.join(" ");
|
|
464
|
+
if (!taskScope) continue;
|
|
465
|
+
|
|
384
466
|
let batchId = null;
|
|
385
467
|
let detachedEnginePid = null;
|
|
386
468
|
|
|
@@ -391,6 +473,15 @@ export async function runSequence(ctx) {
|
|
|
391
473
|
skipPreflight: true,
|
|
392
474
|
});
|
|
393
475
|
if (!startResult.ok) {
|
|
476
|
+
const reconciliation = reconcileBatch({ projectRoot });
|
|
477
|
+
if (isMergeBlockedBatchOutcome({ startResult, reconciliation })) {
|
|
478
|
+
absorbMergeBlockedWave(
|
|
479
|
+
wave.waveIndex,
|
|
480
|
+
loadSpineBatchState(projectRoot).raw,
|
|
481
|
+
startResult.output ?? "",
|
|
482
|
+
);
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
394
485
|
if (!stopOnFailure) continue;
|
|
395
486
|
return haltSequenceAndPersist(
|
|
396
487
|
projectRoot,
|
|
@@ -457,6 +548,15 @@ export async function runSequence(ctx) {
|
|
|
457
548
|
: await waitForSequenceBatchTerminal({ projectRoot, pollIntervalMs, timeoutMs, enginePid: detachedEnginePid ?? null });
|
|
458
549
|
|
|
459
550
|
if (!wait.ok || isSequenceBatchFailure(wait.diagnosis)) {
|
|
551
|
+
const reconciliation = wait.reconciliation ?? reconcileBatch({ projectRoot });
|
|
552
|
+
if (isMergeBlockedBatchOutcome({ reconciliation })) {
|
|
553
|
+
absorbMergeBlockedWave(
|
|
554
|
+
wave.waveIndex,
|
|
555
|
+
reconciliation.signals?.raw ?? loadSpineBatchState(projectRoot).raw,
|
|
556
|
+
reconciliation.headline ?? "",
|
|
557
|
+
);
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
460
560
|
if (!stopOnFailure) continue;
|
|
461
561
|
return haltSequenceAndPersist(projectRoot, sequenceState, completedWaves, {
|
|
462
562
|
waveIndex: wave.waveIndex,
|
|
@@ -492,6 +592,10 @@ export async function runSequence(ctx) {
|
|
|
492
592
|
};
|
|
493
593
|
completedWaves.push(waveResult);
|
|
494
594
|
|
|
595
|
+
for (const taskId of wavePlanResolution.runnableTaskIds) {
|
|
596
|
+
satisfiedTaskIds.add(taskId);
|
|
597
|
+
}
|
|
598
|
+
|
|
495
599
|
if (sequenceState) {
|
|
496
600
|
const lastBatchId = waveResult.batchId ?? sequenceState.lastBatchId ?? null;
|
|
497
601
|
sequenceState = buildSequenceStateSnapshot(sequenceState, {
|
|
@@ -505,12 +609,21 @@ export async function runSequence(ctx) {
|
|
|
505
609
|
|
|
506
610
|
finalizeSequenceState(projectRoot, sequenceState, completedWaves, plan);
|
|
507
611
|
|
|
612
|
+
if (completedWaves.length > 0) {
|
|
613
|
+
sequenceOutputLines.push(`Sequence completed ${completedWaves.length} wave(s).`);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const partialMergeBlocked = sequenceHadMergeBlocked && completedWaves.length < wavePlan.waves.length;
|
|
617
|
+
|
|
508
618
|
return {
|
|
509
|
-
ok:
|
|
510
|
-
exitCode: 0,
|
|
619
|
+
ok: !sequenceHadMergeBlocked,
|
|
620
|
+
exitCode: sequenceHadMergeBlocked ? 1 : 0,
|
|
511
621
|
completedWaves,
|
|
622
|
+
skippedWaves,
|
|
623
|
+
mergeBlocked: sequenceHadMergeBlocked,
|
|
624
|
+
partial: partialMergeBlocked,
|
|
512
625
|
waveCount: wavePlan.waves.length,
|
|
513
626
|
resumed: resume,
|
|
514
|
-
output:
|
|
627
|
+
output: `${sequenceOutputLines.join("\n")}\n`,
|
|
515
628
|
};
|
|
516
629
|
}
|
package/src/batch/state.mjs
CHANGED
|
@@ -6,7 +6,10 @@ import fs from "node:fs";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { writeJsonAtomic } from "../fs/atomic-write.mjs";
|
|
8
8
|
import { appendJournalEvent } from "./journal.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
clearStaleTerminalBatchStateForStart,
|
|
11
|
+
loadBatchStateFile,
|
|
12
|
+
} from "./batch-state-io.mjs";
|
|
10
13
|
import { isProcessAlive } from "../process/liveness.mjs";
|
|
11
14
|
|
|
12
15
|
export const SPINE_BATCH_STATE_REL = path.join(".spine", "batch-state.json");
|
|
@@ -85,7 +88,19 @@ export function evaluateBatchStateWriteGuard(projectRoot, state) {
|
|
|
85
88
|
if (fs.existsSync(filePath)) {
|
|
86
89
|
try {
|
|
87
90
|
const onDisk = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
91
|
+
const onDiskBatchId = String(onDisk.batchId ?? "");
|
|
92
|
+
const incomingBatchId = String(state.batchId ?? "");
|
|
93
|
+
const onDiskPhase = String(onDisk.phase ?? "");
|
|
88
94
|
const ownerPid = readBatchEnginePid(onDisk);
|
|
95
|
+
if (
|
|
96
|
+
incomingBatchId &&
|
|
97
|
+
onDiskBatchId &&
|
|
98
|
+
incomingBatchId !== onDiskBatchId &&
|
|
99
|
+
TERMINAL_BATCH_PHASES.has(onDiskPhase) &&
|
|
100
|
+
(!ownerPid || !isProcessAlive(ownerPid))
|
|
101
|
+
) {
|
|
102
|
+
return { allowed: true };
|
|
103
|
+
}
|
|
89
104
|
if (ownerPid && ownerPid !== process.pid && isProcessAlive(ownerPid)) {
|
|
90
105
|
return { allowed: false, reason: "stale_engine_pid" };
|
|
91
106
|
}
|
|
@@ -251,6 +266,8 @@ export function failBatchFromEngineError({
|
|
|
251
266
|
* @param {string} projectRoot
|
|
252
267
|
*/
|
|
253
268
|
export function assertNoActiveBatch(projectRoot) {
|
|
269
|
+
clearStaleTerminalBatchStateForStart(projectRoot);
|
|
270
|
+
|
|
254
271
|
const spine = loadSpineBatchState(projectRoot);
|
|
255
272
|
if (spine.path && spine.raw) {
|
|
256
273
|
const phase = String(spine.raw.phase ?? "");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `spine batch complete` handler — archive-first lifecycle with SP-441 handoff guards.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { completeBatch } from "../batch/lifecycle.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} ctx
|
|
9
|
+
* @param {string} ctx.projectRoot
|
|
10
|
+
* @param {boolean} [ctx.detectManualMerge]
|
|
11
|
+
* @param {string|null} [ctx.batchId]
|
|
12
|
+
* @param {string|null} [ctx.batchStatePath]
|
|
13
|
+
*/
|
|
14
|
+
export function runBatchComplete(ctx) {
|
|
15
|
+
return completeBatch(ctx);
|
|
16
|
+
}
|