pi-spine 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/spine-cli/verify.mjs +3 -0
- package/bin/spine-plan.mjs +49 -1
- package/bin/spine-worker-runner.mjs +136 -4
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +7 -2
- package/skills/create-spine-tasks/references/contract-template.md +95 -3
- package/src/batch/attached-runner.mjs +81 -5
- package/src/batch/contract-stub-delivery.mjs +110 -0
- package/src/batch/contract-task-start.mjs +204 -0
- package/src/batch/contract-verify.mjs +55 -8
- package/src/batch/detached-start.mjs +72 -2
- package/src/batch/diagnosis-launch-failure.mjs +114 -0
- package/src/batch/diagnosis-primary-failure.mjs +89 -0
- package/src/batch/diagnosis-tail-state.mjs +57 -0
- package/src/batch/diagnosis.mjs +22 -113
- package/src/batch/engine-lanes/commit.mjs +145 -0
- package/src/batch/engine-lanes/review.mjs +67 -87
- package/src/batch/engine-lanes.mjs +21 -79
- package/src/batch/engine.mjs +46 -0
- package/src/batch/heartbeat.mjs +2 -2
- package/src/batch/integrate-assert.mjs +69 -0
- package/src/batch/integrate-worktree.mjs +354 -0
- package/src/batch/integrate.mjs +195 -102
- package/src/batch/journal-rebuild.mjs +48 -2
- package/src/batch/journal.mjs +63 -0
- package/src/batch/lane-dirty-check.mjs +437 -0
- package/src/batch/limbo-detect.mjs +34 -0
- package/src/batch/macro-phase.mjs +76 -0
- package/src/batch/metrics.mjs +2 -0
- package/src/batch/pause.mjs +18 -7
- package/src/batch/post-merge-limbo.mjs +3 -28
- package/src/batch/reconcile.mjs +79 -9
- package/src/batch/resume-common.mjs +27 -0
- package/src/batch/resume-multi-lanes.mjs +11 -0
- package/src/batch/resume-multi.mjs +2 -0
- package/src/batch/resume.mjs +8 -1
- package/src/batch/retry.mjs +41 -10
- package/src/batch/rules-manifest-drift.mjs +43 -2
- package/src/batch/sequence-state.mjs +290 -0
- package/src/batch/sequence.mjs +113 -51
- package/src/batch/state.mjs +16 -0
- package/src/batch/worker-host.mjs +1 -0
- package/src/cli/sequence.mjs +14 -1
- package/src/cli/settings-set.mjs +33 -3
- package/src/config/model-id.mjs +103 -0
- package/src/config/spine-init-constants.mjs +1 -0
- package/src/config/spine-preflight-lib.mjs +23 -1
- package/src/dashboard/public/dashboard.js +14 -3
- package/src/dashboard/running-tail-state.mjs +31 -0
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +260 -28
- package/src/dashboard/view.mjs +112 -2
- package/src/doctor/agent-models.mjs +53 -0
- package/src/doctor/batch-size-guidance.mjs +30 -2
- package/src/doctor/pi-extension-conflict.mjs +169 -0
- package/src/doctor/run-doctor-checks.mjs +6 -0
- package/src/planner/scope.mjs +5 -1
- package/src/tasks/packet/parse-prompt.mjs +31 -1
- package/src/tasks/packet/validate-contract.mjs +108 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planner wave sequence runtime state (GitHub #54 Tier 2 SP-D).
|
|
3
|
+
* Persists progress under `.spine/runtime/sequence/` for `--resume`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { writeJsonAtomic } from "../fs/atomic-write.mjs";
|
|
9
|
+
|
|
10
|
+
export const SEQUENCE_STATE_VERSION = 1;
|
|
11
|
+
export const SEQUENCE_STATE_REL = path.join(".spine", "runtime", "sequence", "state.json");
|
|
12
|
+
|
|
13
|
+
/** @typedef {{ waveIndex: number, batchId: string|null, diagnosis: string|null }} SequenceCompletedWave */
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} projectRoot
|
|
17
|
+
*/
|
|
18
|
+
export function sequenceStatePath(projectRoot) {
|
|
19
|
+
return path.join(projectRoot, SEQUENCE_STATE_REL);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {Date} [now]
|
|
24
|
+
*/
|
|
25
|
+
export function generateSequenceId(now = new Date()) {
|
|
26
|
+
const y = now.getUTCFullYear();
|
|
27
|
+
const m = String(now.getUTCMonth() + 1).padStart(2, "0");
|
|
28
|
+
const d = String(now.getUTCDate()).padStart(2, "0");
|
|
29
|
+
const h = String(now.getUTCHours()).padStart(2, "0");
|
|
30
|
+
const min = String(now.getUTCMinutes()).padStart(2, "0");
|
|
31
|
+
const s = String(now.getUTCSeconds()).padStart(2, "0");
|
|
32
|
+
return `seq-${y}${m}${d}T${h}${min}${s}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {object} params
|
|
37
|
+
* @param {string} params.scope
|
|
38
|
+
* @param {number} params.fromWave
|
|
39
|
+
* @param {number|null} [params.throughWave]
|
|
40
|
+
*/
|
|
41
|
+
export function createInitialSequenceState({ scope, fromWave, throughWave = null }) {
|
|
42
|
+
return {
|
|
43
|
+
version: SEQUENCE_STATE_VERSION,
|
|
44
|
+
sequenceId: generateSequenceId(),
|
|
45
|
+
scope,
|
|
46
|
+
fromWave,
|
|
47
|
+
throughWave,
|
|
48
|
+
completedWaves: /** @type {SequenceCompletedWave[]} */ ([]),
|
|
49
|
+
lastBatchId: null,
|
|
50
|
+
status: "active",
|
|
51
|
+
updatedAt: new Date().toISOString(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} projectRoot
|
|
57
|
+
* @returns {{ ok: true, state: object } | { ok: false, error: string, output?: string }}
|
|
58
|
+
*/
|
|
59
|
+
export function loadSequenceState(projectRoot) {
|
|
60
|
+
const filePath = sequenceStatePath(projectRoot);
|
|
61
|
+
if (!fs.existsSync(filePath)) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
error: "no_sequence_state",
|
|
65
|
+
output: "No saved sequence state — start a sequence or pass --from-wave.\n",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const state = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
71
|
+
return { ok: true, state };
|
|
72
|
+
} catch (err) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
error: "sequence_state_corrupt",
|
|
76
|
+
output: `Sequence state is unreadable: ${err instanceof Error ? err.message : String(err)}\n`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {string} projectRoot
|
|
83
|
+
* @param {object} state
|
|
84
|
+
*/
|
|
85
|
+
export function saveSequenceState(projectRoot, state) {
|
|
86
|
+
const filePath = sequenceStatePath(projectRoot);
|
|
87
|
+
writeJsonAtomic(filePath, {
|
|
88
|
+
...state,
|
|
89
|
+
version: SEQUENCE_STATE_VERSION,
|
|
90
|
+
updatedAt: new Date().toISOString(),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {string} projectRoot
|
|
96
|
+
*/
|
|
97
|
+
export function clearSequenceState(projectRoot) {
|
|
98
|
+
const filePath = sequenceStatePath(projectRoot);
|
|
99
|
+
if (fs.existsSync(filePath)) {
|
|
100
|
+
fs.unlinkSync(filePath);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {object|null|undefined} state
|
|
106
|
+
*/
|
|
107
|
+
export function resolveResumeFromWave(state) {
|
|
108
|
+
const completed = state?.completedWaves ?? [];
|
|
109
|
+
if (completed.length === 0) {
|
|
110
|
+
return Number.isInteger(state?.fromWave) ? state.fromWave : 0;
|
|
111
|
+
}
|
|
112
|
+
const maxCompleted = Math.max(...completed.map((wave) => wave.waveIndex));
|
|
113
|
+
return maxCompleted + 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @param {object} state
|
|
118
|
+
* @param {string} scope
|
|
119
|
+
*/
|
|
120
|
+
export function validateSequenceStateForResume(state, scope) {
|
|
121
|
+
if (!state || typeof state !== "object") {
|
|
122
|
+
return { ok: false, error: "no_sequence_state", output: "No saved sequence state.\n" };
|
|
123
|
+
}
|
|
124
|
+
if (state.status === "completed") {
|
|
125
|
+
return {
|
|
126
|
+
ok: false,
|
|
127
|
+
error: "sequence_already_completed",
|
|
128
|
+
output: "Saved sequence already completed — start a new sequence without --resume.\n",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (String(state.scope ?? "") !== String(scope)) {
|
|
132
|
+
return {
|
|
133
|
+
ok: false,
|
|
134
|
+
error: "sequence_scope_mismatch",
|
|
135
|
+
output: `Saved sequence scope is "${state.scope ?? ""}" but command scope is "${scope}".\n`,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return { ok: true };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {object} state
|
|
143
|
+
* @param {SequenceCompletedWave[]} completedWaves
|
|
144
|
+
* @param {string|null} lastBatchId
|
|
145
|
+
* @param {"active"|"halted"|"completed"} status
|
|
146
|
+
*/
|
|
147
|
+
export function buildSequenceStateSnapshot(state, { completedWaves, lastBatchId, status }) {
|
|
148
|
+
return {
|
|
149
|
+
...state,
|
|
150
|
+
completedWaves,
|
|
151
|
+
lastBatchId,
|
|
152
|
+
status,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {object} params
|
|
158
|
+
* @param {number} params.waveIndex
|
|
159
|
+
* @param {string} [params.error]
|
|
160
|
+
* @param {string|null} [params.diagnosis]
|
|
161
|
+
* @param {string|null} [params.batchId]
|
|
162
|
+
* @param {SequenceCompletedWave[]} params.completedWaves
|
|
163
|
+
*/
|
|
164
|
+
export function buildSequenceHaltResult({
|
|
165
|
+
waveIndex,
|
|
166
|
+
error,
|
|
167
|
+
diagnosis = null,
|
|
168
|
+
batchId = null,
|
|
169
|
+
completedWaves,
|
|
170
|
+
}) {
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
exitCode: 1,
|
|
174
|
+
halted: true,
|
|
175
|
+
waveIndex,
|
|
176
|
+
error,
|
|
177
|
+
diagnosis,
|
|
178
|
+
batchId,
|
|
179
|
+
completedWaves,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {string} projectRoot
|
|
185
|
+
* @param {object|null} sequenceState
|
|
186
|
+
* @param {SequenceCompletedWave[]} completedWaves
|
|
187
|
+
* @param {object} haltParams
|
|
188
|
+
* @param {object} [extra]
|
|
189
|
+
*/
|
|
190
|
+
export function haltSequenceAndPersist(projectRoot, sequenceState, completedWaves, haltParams, extra = {}) {
|
|
191
|
+
const halt = { ...buildSequenceHaltResult(haltParams), ...extra };
|
|
192
|
+
persistSequenceState(projectRoot, sequenceState, completedWaves, {
|
|
193
|
+
lastBatchId: haltParams.batchId ?? sequenceState?.lastBatchId ?? null,
|
|
194
|
+
status: "halted",
|
|
195
|
+
});
|
|
196
|
+
return halt;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @param {string} projectRoot
|
|
201
|
+
* @param {object|null} sequenceState
|
|
202
|
+
* @param {SequenceCompletedWave[]} completedWaves
|
|
203
|
+
* @param {string|null} [lastBatchId]
|
|
204
|
+
* @param {"active"|"halted"} [status]
|
|
205
|
+
*/
|
|
206
|
+
export function persistSequenceState(
|
|
207
|
+
projectRoot,
|
|
208
|
+
sequenceState,
|
|
209
|
+
completedWaves,
|
|
210
|
+
{ lastBatchId = null, status = "active" } = {},
|
|
211
|
+
) {
|
|
212
|
+
if (!sequenceState) return;
|
|
213
|
+
saveSequenceState(
|
|
214
|
+
projectRoot,
|
|
215
|
+
buildSequenceStateSnapshot(sequenceState, {
|
|
216
|
+
completedWaves,
|
|
217
|
+
lastBatchId: lastBatchId ?? sequenceState.lastBatchId ?? null,
|
|
218
|
+
status,
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @param {string} projectRoot
|
|
225
|
+
* @param {object} params
|
|
226
|
+
* @param {boolean} params.resume
|
|
227
|
+
* @param {string} params.scope
|
|
228
|
+
* @param {number} params.fromWave
|
|
229
|
+
* @param {number|null} [params.throughWave]
|
|
230
|
+
* @param {boolean} params.dryRun
|
|
231
|
+
*/
|
|
232
|
+
export function prepareSequenceRunState(projectRoot, { resume, scope, fromWave, throughWave, dryRun }) {
|
|
233
|
+
if (resume) {
|
|
234
|
+
const loaded = loadSequenceState(projectRoot);
|
|
235
|
+
if (!loaded.ok) {
|
|
236
|
+
return { ok: false, error: loaded.error, output: loaded.output };
|
|
237
|
+
}
|
|
238
|
+
const resumeCheck = validateSequenceStateForResume(loaded.state, scope);
|
|
239
|
+
if (!resumeCheck.ok) {
|
|
240
|
+
return { ok: false, error: resumeCheck.error, output: resumeCheck.output };
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
ok: true,
|
|
244
|
+
sequenceState: loaded.state,
|
|
245
|
+
effectiveFromWave: resolveResumeFromWave(loaded.state),
|
|
246
|
+
persistedCompletedWaves: [...(loaded.state.completedWaves ?? [])],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (dryRun) {
|
|
251
|
+
return {
|
|
252
|
+
ok: true,
|
|
253
|
+
sequenceState: null,
|
|
254
|
+
effectiveFromWave: fromWave,
|
|
255
|
+
persistedCompletedWaves: [],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
ok: true,
|
|
261
|
+
sequenceState: createInitialSequenceState({ scope, fromWave, throughWave }),
|
|
262
|
+
effectiveFromWave: fromWave,
|
|
263
|
+
persistedCompletedWaves: [],
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @param {string} projectRoot
|
|
269
|
+
* @param {object|null} sequenceState
|
|
270
|
+
* @param {SequenceCompletedWave[]} completedWaves
|
|
271
|
+
* @param {object} plan
|
|
272
|
+
*/
|
|
273
|
+
export function finalizeSequenceState(projectRoot, sequenceState, completedWaves, plan) {
|
|
274
|
+
if (!sequenceState) return;
|
|
275
|
+
|
|
276
|
+
const lastCompletedWave =
|
|
277
|
+
completedWaves.length > 0 ? Math.max(...completedWaves.map((wave) => wave.waveIndex)) : -1;
|
|
278
|
+
const planLastWave = (plan?.waves?.length ?? 0) - 1;
|
|
279
|
+
const allPlanWavesComplete = lastCompletedWave >= planLastWave;
|
|
280
|
+
|
|
281
|
+
if (allPlanWavesComplete) {
|
|
282
|
+
clearSequenceState(projectRoot);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
persistSequenceState(projectRoot, sequenceState, completedWaves, {
|
|
287
|
+
lastBatchId: sequenceState.lastBatchId ?? null,
|
|
288
|
+
status: "active",
|
|
289
|
+
});
|
|
290
|
+
}
|
package/src/batch/sequence.mjs
CHANGED
|
@@ -4,19 +4,31 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
formatPreflightHuman,
|
|
9
|
+
runBatchPreflight,
|
|
10
|
+
resolveTasksRoot,
|
|
11
|
+
} from "../config/spine-preflight-lib.mjs";
|
|
8
12
|
import { buildPlan } from "../planner/index.mjs";
|
|
9
13
|
import { resolveWaveTaskIds } from "../planner/wave-scope.mjs";
|
|
10
14
|
|
|
11
15
|
export { resolveWaveTaskIds };
|
|
12
16
|
import { startBatch } from "./engine.mjs";
|
|
13
17
|
import { startBatchDetached } from "./detached-start.mjs";
|
|
18
|
+
import { isProcessAlive } from "../process/liveness.mjs";
|
|
14
19
|
import { approveIntegrateGate, loadGateRecord } from "./gate.mjs";
|
|
15
20
|
import { integrateOrchToBase } from "./integrate.mjs";
|
|
16
21
|
import { completeBatch } from "./lifecycle.mjs";
|
|
17
22
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
18
23
|
import { loadSpineBatchState } from "./state.mjs";
|
|
19
24
|
import { validateSequenceAutoApproveGate } from "../doctor/sequence-safety.mjs";
|
|
25
|
+
import {
|
|
26
|
+
buildSequenceStateSnapshot,
|
|
27
|
+
finalizeSequenceState,
|
|
28
|
+
haltSequenceAndPersist,
|
|
29
|
+
persistSequenceState,
|
|
30
|
+
prepareSequenceRunState,
|
|
31
|
+
} from "./sequence-state.mjs";
|
|
20
32
|
|
|
21
33
|
const WAVE_BATCH_SETTLED_DIAGNOSES = new Set([
|
|
22
34
|
"completed",
|
|
@@ -56,9 +68,10 @@ export async function waitForSequenceBatchTerminal({
|
|
|
56
68
|
projectRoot,
|
|
57
69
|
pollIntervalMs = 250,
|
|
58
70
|
timeoutMs = 120_000,
|
|
71
|
+
enginePid = null,
|
|
59
72
|
}) {
|
|
60
73
|
const deadline = Date.now() + timeoutMs;
|
|
61
|
-
while (Date.now() < deadline) {
|
|
74
|
+
while (Date.now() < deadline || isEngineStillRunning(enginePid, projectRoot)) {
|
|
62
75
|
const reconciliation = reconcileBatch({ projectRoot });
|
|
63
76
|
const diagnosis = reconciliation.diagnosis;
|
|
64
77
|
if (isSequenceBatchFailure(diagnosis)) {
|
|
@@ -90,6 +103,18 @@ export async function waitForSequenceBatchTerminal({
|
|
|
90
103
|
};
|
|
91
104
|
}
|
|
92
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Returns true when a detached engine PID is alive or the batch phase is active,
|
|
108
|
+
* preventing sequence timeout while work is still in progress.
|
|
109
|
+
*/
|
|
110
|
+
function isEngineStillRunning(enginePid, projectRoot) {
|
|
111
|
+
if (enginePid && isProcessAlive(enginePid)) return true;
|
|
112
|
+
const { raw } = loadSpineBatchState(projectRoot);
|
|
113
|
+
const pid = raw?.enginePid ?? null;
|
|
114
|
+
if (pid && isProcessAlive(pid)) return true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
93
118
|
/**
|
|
94
119
|
* @param {object} plan
|
|
95
120
|
* @param {object} [options]
|
|
@@ -265,27 +290,6 @@ export function runSequenceWaveLandLoop({ projectRoot, batchId, autoApproveGate
|
|
|
265
290
|
};
|
|
266
291
|
}
|
|
267
292
|
|
|
268
|
-
/**
|
|
269
|
-
* @param {object} params
|
|
270
|
-
* @param {number} params.waveIndex
|
|
271
|
-
* @param {string} [params.error]
|
|
272
|
-
* @param {string|null} [params.diagnosis]
|
|
273
|
-
* @param {string|null} [params.batchId]
|
|
274
|
-
* @param {Array<{ waveIndex: number, batchId: string|null, diagnosis: string|null }>} params.completedWaves
|
|
275
|
-
*/
|
|
276
|
-
function sequenceHalt({ waveIndex, error, diagnosis = null, batchId = null, completedWaves }) {
|
|
277
|
-
return {
|
|
278
|
-
ok: false,
|
|
279
|
-
exitCode: 1,
|
|
280
|
-
halted: true,
|
|
281
|
-
waveIndex,
|
|
282
|
-
error,
|
|
283
|
-
diagnosis,
|
|
284
|
-
batchId,
|
|
285
|
-
completedWaves,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
293
|
/**
|
|
290
294
|
* @param {object} ctx
|
|
291
295
|
*/
|
|
@@ -293,8 +297,10 @@ export async function runSequence(ctx) {
|
|
|
293
297
|
const {
|
|
294
298
|
projectRoot,
|
|
295
299
|
plan,
|
|
300
|
+
scope = "pending",
|
|
296
301
|
fromWave = 0,
|
|
297
302
|
throughWave = null,
|
|
303
|
+
resume = false,
|
|
298
304
|
attached = false,
|
|
299
305
|
autoApproveGate = false,
|
|
300
306
|
force = false,
|
|
@@ -307,7 +313,26 @@ export async function runSequence(ctx) {
|
|
|
307
313
|
startBatchFn = startBatch,
|
|
308
314
|
} = ctx;
|
|
309
315
|
|
|
310
|
-
|
|
316
|
+
let sequenceState = null;
|
|
317
|
+
let effectiveFromWave = fromWave;
|
|
318
|
+
/** @type {Array<{ waveIndex: number, batchId: string|null, diagnosis: string|null }>} */
|
|
319
|
+
let persistedCompletedWaves = [];
|
|
320
|
+
|
|
321
|
+
const prepared = prepareSequenceRunState(projectRoot, {
|
|
322
|
+
resume,
|
|
323
|
+
scope,
|
|
324
|
+
fromWave,
|
|
325
|
+
throughWave,
|
|
326
|
+
dryRun,
|
|
327
|
+
});
|
|
328
|
+
if (!prepared.ok) {
|
|
329
|
+
return { ok: false, exitCode: 1, error: prepared.error, output: prepared.output };
|
|
330
|
+
}
|
|
331
|
+
sequenceState = prepared.sequenceState;
|
|
332
|
+
effectiveFromWave = prepared.effectiveFromWave;
|
|
333
|
+
persistedCompletedWaves = prepared.persistedCompletedWaves;
|
|
334
|
+
|
|
335
|
+
const wavePlan = resolveSequenceWaves(plan, { fromWave: effectiveFromWave, throughWave });
|
|
311
336
|
if (!wavePlan.ok) {
|
|
312
337
|
return { ok: false, exitCode: 1, error: wavePlan.error, output: wavePlan.output };
|
|
313
338
|
}
|
|
@@ -342,17 +367,22 @@ export async function runSequence(ctx) {
|
|
|
342
367
|
ok: false,
|
|
343
368
|
exitCode: preflight.exitCode ?? 1,
|
|
344
369
|
error: "preflight_failed",
|
|
345
|
-
output: preflight
|
|
370
|
+
output: formatPreflightHuman(preflight),
|
|
346
371
|
};
|
|
347
372
|
}
|
|
348
373
|
}
|
|
349
374
|
|
|
375
|
+
if (sequenceState) {
|
|
376
|
+
persistSequenceState(projectRoot, sequenceState, persistedCompletedWaves);
|
|
377
|
+
}
|
|
378
|
+
|
|
350
379
|
/** @type {Array<{ waveIndex: number, batchId: string|null, diagnosis: string|null }>} */
|
|
351
|
-
const completedWaves = [];
|
|
380
|
+
const completedWaves = [...persistedCompletedWaves];
|
|
352
381
|
|
|
353
382
|
for (const wave of wavePlan.waves) {
|
|
354
383
|
const taskScope = wave.taskIds.join(" ");
|
|
355
384
|
let batchId = null;
|
|
385
|
+
let detachedEnginePid = null;
|
|
356
386
|
|
|
357
387
|
if (attached) {
|
|
358
388
|
const startResult = await startBatchFn({
|
|
@@ -362,14 +392,17 @@ export async function runSequence(ctx) {
|
|
|
362
392
|
});
|
|
363
393
|
if (!startResult.ok) {
|
|
364
394
|
if (!stopOnFailure) continue;
|
|
365
|
-
return
|
|
366
|
-
|
|
395
|
+
return haltSequenceAndPersist(
|
|
396
|
+
projectRoot,
|
|
397
|
+
sequenceState,
|
|
398
|
+
completedWaves,
|
|
399
|
+
{
|
|
367
400
|
waveIndex: wave.waveIndex,
|
|
368
401
|
error: startResult.error ?? "batch_start_failed",
|
|
369
402
|
completedWaves,
|
|
370
|
-
}
|
|
371
|
-
output: startResult.output,
|
|
372
|
-
|
|
403
|
+
},
|
|
404
|
+
{ output: startResult.output },
|
|
405
|
+
);
|
|
373
406
|
}
|
|
374
407
|
batchId = startResult.batchId ?? loadSpineBatchState(projectRoot).raw?.batchId ?? null;
|
|
375
408
|
} else {
|
|
@@ -386,20 +419,33 @@ export async function runSequence(ctx) {
|
|
|
386
419
|
spineBin,
|
|
387
420
|
scope: taskScope,
|
|
388
421
|
skipPreflight: true,
|
|
389
|
-
waitTerminal:
|
|
422
|
+
waitTerminal: false,
|
|
390
423
|
});
|
|
424
|
+
detachedEnginePid = detached.result?.enginePid ?? null;
|
|
391
425
|
if (!detached.ok) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
426
|
+
const engineStartedButTimeout =
|
|
427
|
+
detached.result?.status === "engine_started" &&
|
|
428
|
+
detached.result?.batchId &&
|
|
429
|
+
isProcessAlive(detachedEnginePid);
|
|
430
|
+
if (engineStartedButTimeout) {
|
|
431
|
+
batchId = detached.result.batchId;
|
|
432
|
+
} else {
|
|
433
|
+
if (!stopOnFailure) continue;
|
|
434
|
+
return haltSequenceAndPersist(
|
|
435
|
+
projectRoot,
|
|
436
|
+
sequenceState,
|
|
397
437
|
completedWaves,
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
438
|
+
{
|
|
439
|
+
waveIndex: wave.waveIndex,
|
|
440
|
+
error: detached.result?.error ?? "batch_start_failed",
|
|
441
|
+
completedWaves,
|
|
442
|
+
},
|
|
443
|
+
{ output: detached.output },
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
} else {
|
|
447
|
+
batchId = detached.result?.batchId ?? null;
|
|
401
448
|
}
|
|
402
|
-
batchId = detached.result?.batchId ?? null;
|
|
403
449
|
}
|
|
404
450
|
|
|
405
451
|
const wait = attached
|
|
@@ -408,11 +454,11 @@ export async function runSequence(ctx) {
|
|
|
408
454
|
batchId,
|
|
409
455
|
diagnosis: reconcileBatch({ projectRoot }).diagnosis ?? null,
|
|
410
456
|
}
|
|
411
|
-
: await waitForSequenceBatchTerminal({ projectRoot, pollIntervalMs, timeoutMs });
|
|
457
|
+
: await waitForSequenceBatchTerminal({ projectRoot, pollIntervalMs, timeoutMs, enginePid: detachedEnginePid ?? null });
|
|
412
458
|
|
|
413
459
|
if (!wait.ok || isSequenceBatchFailure(wait.diagnosis)) {
|
|
414
460
|
if (!stopOnFailure) continue;
|
|
415
|
-
return
|
|
461
|
+
return haltSequenceAndPersist(projectRoot, sequenceState, completedWaves, {
|
|
416
462
|
waveIndex: wave.waveIndex,
|
|
417
463
|
error: wait.error ?? "batch_failed",
|
|
418
464
|
diagnosis: wait.diagnosis ?? null,
|
|
@@ -424,31 +470,47 @@ export async function runSequence(ctx) {
|
|
|
424
470
|
const land = runSequenceWaveLandLoop({ projectRoot, batchId: wait.batchId ?? batchId, autoApproveGate });
|
|
425
471
|
if (!land.ok) {
|
|
426
472
|
if (!stopOnFailure) continue;
|
|
427
|
-
return
|
|
428
|
-
|
|
473
|
+
return haltSequenceAndPersist(
|
|
474
|
+
projectRoot,
|
|
475
|
+
sequenceState,
|
|
476
|
+
completedWaves,
|
|
477
|
+
{
|
|
429
478
|
waveIndex: wave.waveIndex,
|
|
430
479
|
error: land.error ?? "land_loop_failed",
|
|
431
480
|
diagnosis: land.diagnosis ?? wait.diagnosis ?? null,
|
|
432
481
|
batchId: land.batchId ?? wait.batchId ?? batchId,
|
|
433
482
|
completedWaves,
|
|
434
|
-
}
|
|
435
|
-
step: land.step,
|
|
436
|
-
|
|
437
|
-
};
|
|
483
|
+
},
|
|
484
|
+
{ step: land.step, headline: land.headline },
|
|
485
|
+
);
|
|
438
486
|
}
|
|
439
487
|
|
|
440
|
-
|
|
488
|
+
const waveResult = {
|
|
441
489
|
waveIndex: wave.waveIndex,
|
|
442
490
|
batchId: land.batchId ?? wait.batchId ?? batchId,
|
|
443
491
|
diagnosis: wait.diagnosis ?? null,
|
|
444
|
-
}
|
|
492
|
+
};
|
|
493
|
+
completedWaves.push(waveResult);
|
|
494
|
+
|
|
495
|
+
if (sequenceState) {
|
|
496
|
+
const lastBatchId = waveResult.batchId ?? sequenceState.lastBatchId ?? null;
|
|
497
|
+
sequenceState = buildSequenceStateSnapshot(sequenceState, {
|
|
498
|
+
completedWaves,
|
|
499
|
+
lastBatchId,
|
|
500
|
+
status: "active",
|
|
501
|
+
});
|
|
502
|
+
persistSequenceState(projectRoot, sequenceState, completedWaves, { lastBatchId });
|
|
503
|
+
}
|
|
445
504
|
}
|
|
446
505
|
|
|
506
|
+
finalizeSequenceState(projectRoot, sequenceState, completedWaves, plan);
|
|
507
|
+
|
|
447
508
|
return {
|
|
448
509
|
ok: true,
|
|
449
510
|
exitCode: 0,
|
|
450
511
|
completedWaves,
|
|
451
512
|
waveCount: wavePlan.waves.length,
|
|
513
|
+
resumed: resume,
|
|
452
514
|
output: `Sequence completed ${completedWaves.length} wave(s).\n`,
|
|
453
515
|
};
|
|
454
516
|
}
|
package/src/batch/state.mjs
CHANGED
|
@@ -156,6 +156,22 @@ export function recordBatchEnginePid(state, enginePid) {
|
|
|
156
156
|
state.resilience.engineStartedAt = Date.now();
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Reset lane stall clocks at resume handoff so dashboard does not show pre-resume heartbeats as stale.
|
|
161
|
+
*
|
|
162
|
+
* @param {object} state
|
|
163
|
+
*/
|
|
164
|
+
export function refreshLaneHeartbeatsOnResume(state) {
|
|
165
|
+
const resilience =
|
|
166
|
+
state.resilience && typeof state.resilience === "object" ? state.resilience : {};
|
|
167
|
+
const reference =
|
|
168
|
+
Number(resilience.engineStartedAt) > 0 ? Number(resilience.engineStartedAt) : Date.now();
|
|
169
|
+
for (const lane of state.lanes ?? []) {
|
|
170
|
+
if (!lane || typeof lane !== "object") continue;
|
|
171
|
+
lane.lastHeartbeatAt = reference;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
159
175
|
/**
|
|
160
176
|
* @param {object} state
|
|
161
177
|
*/
|
|
@@ -136,6 +136,7 @@ export function buildWorkerChildEnv({
|
|
|
136
136
|
SPINE_TASK_FOLDER: taskFolder,
|
|
137
137
|
SPINE_WORKTREE: worktreePath,
|
|
138
138
|
SPINE_WORKER_RUNNER: runner,
|
|
139
|
+
SPINE_IS_WORKER: "1",
|
|
139
140
|
PI_SPINE_ROOT: resolvePiSpineRoot(config, projectRoot ?? process.cwd()),
|
|
140
141
|
};
|
|
141
142
|
if (projectRoot) env.SPINE_PROJECT_ROOT = projectRoot;
|
package/src/cli/sequence.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { resolveDefaultSpineBin } from "../batch/post-merge-limbo.mjs";
|
|
|
10
10
|
* @param {string[]} argv
|
|
11
11
|
*/
|
|
12
12
|
export function parseSequenceArgs(argv) {
|
|
13
|
-
/** @type {{ scope: string, fromWave: number, throughWave: number|null, attached: boolean, stopOnFailure: boolean, dryRun: boolean, json: boolean, skipPreflight: boolean }} */
|
|
13
|
+
/** @type {{ scope: string, fromWave: number, throughWave: number|null, attached: boolean, stopOnFailure: boolean, dryRun: boolean, json: boolean, skipPreflight: boolean, resume: boolean, autoApproveGate: boolean, force: boolean }} */
|
|
14
14
|
const parsed = {
|
|
15
15
|
scope: "pending",
|
|
16
16
|
fromWave: 0,
|
|
@@ -20,6 +20,9 @@ export function parseSequenceArgs(argv) {
|
|
|
20
20
|
dryRun: false,
|
|
21
21
|
json: false,
|
|
22
22
|
skipPreflight: false,
|
|
23
|
+
resume: false,
|
|
24
|
+
autoApproveGate: false,
|
|
25
|
+
force: false,
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
/** @type {string[]} */
|
|
@@ -42,6 +45,12 @@ export function parseSequenceArgs(argv) {
|
|
|
42
45
|
parsed.json = true;
|
|
43
46
|
} else if (arg === "--skip-preflight") {
|
|
44
47
|
parsed.skipPreflight = true;
|
|
48
|
+
} else if (arg === "--resume") {
|
|
49
|
+
parsed.resume = true;
|
|
50
|
+
} else if (arg === "--auto-approve-gate") {
|
|
51
|
+
parsed.autoApproveGate = true;
|
|
52
|
+
} else if (arg === "--force") {
|
|
53
|
+
parsed.force = true;
|
|
45
54
|
} else if (!arg.startsWith("--")) {
|
|
46
55
|
positional.push(arg);
|
|
47
56
|
}
|
|
@@ -91,9 +100,13 @@ export async function runSpineSequence({ projectRoot, args = [], spineBin = null
|
|
|
91
100
|
const result = await runSequence({
|
|
92
101
|
projectRoot,
|
|
93
102
|
plan: built.plan,
|
|
103
|
+
scope: parsed.scope,
|
|
94
104
|
fromWave: parsed.fromWave,
|
|
95
105
|
throughWave: parsed.throughWave,
|
|
106
|
+
resume: parsed.resume,
|
|
96
107
|
attached: parsed.attached,
|
|
108
|
+
autoApproveGate: parsed.autoApproveGate,
|
|
109
|
+
force: parsed.force,
|
|
97
110
|
stopOnFailure: parsed.stopOnFailure,
|
|
98
111
|
dryRun: parsed.dryRun,
|
|
99
112
|
skipPreflight: parsed.skipPreflight,
|