pi-spine 1.1.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-batch.mjs +160 -53
- package/bin/spine-cli/batch.mjs +3 -3
- package/bin/spine-cli/lane-logs.mjs +24 -0
- package/bin/spine-cli/scenarios.mjs +298 -0
- package/bin/spine-cli/verify.mjs +3 -0
- package/bin/spine-cli/wait.mjs +30 -0
- package/bin/spine-cli/watch.mjs +27 -0
- package/bin/spine-issue.mjs +196 -0
- package/bin/spine-journal.mjs +1 -0
- package/bin/spine-plan.mjs +49 -1
- package/bin/spine-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +16 -2
- package/bin/spine-worker-runner.mjs +144 -12
- package/bin/spine.mjs +49 -1
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +7 -2
- package/skills/create-spine-tasks/references/contract-template.md +114 -3
- package/src/batch/abort.mjs +2 -11
- package/src/batch/agent-session-worker.mjs +45 -5
- package/src/batch/attached-engine-handoff.mjs +188 -0
- package/src/batch/attached-runner.mjs +388 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-stub-delivery.mjs +110 -0
- package/src/batch/contract-task-start.mjs +204 -0
- package/src/batch/contract-verify.mjs +195 -10
- package/src/batch/detached-start.mjs +137 -3
- package/src/batch/diagnosis-alternatives.mjs +46 -0
- package/src/batch/diagnosis-launch-failure.mjs +114 -0
- package/src/batch/diagnosis-merge-failure.mjs +79 -0
- package/src/batch/diagnosis-primary-failure.mjs +89 -0
- package/src/batch/diagnosis-retry-limbo.mjs +34 -0
- package/src/batch/diagnosis-stub.mjs +109 -0
- package/src/batch/diagnosis-tail-state.mjs +57 -0
- package/src/batch/diagnosis-task-done.mjs +110 -0
- package/src/batch/diagnosis-worker-done-missing.mjs +96 -0
- package/src/batch/diagnosis.mjs +140 -164
- package/src/batch/engine-lanes/commit.mjs +145 -0
- package/src/batch/engine-lanes/merge.mjs +110 -82
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/review.mjs +67 -87
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +21 -78
- package/src/batch/engine-scope.mjs +11 -1
- package/src/batch/engine.mjs +125 -24
- package/src/batch/evidence.mjs +78 -15
- package/src/batch/gate.mjs +43 -14
- package/src/batch/git-helpers.mjs +96 -0
- package/src/batch/heartbeat.mjs +75 -9
- package/src/batch/integrate-assert.mjs +69 -0
- package/src/batch/integrate-worktree.mjs +354 -0
- package/src/batch/integrate.mjs +193 -102
- package/src/batch/journal-rebuild.mjs +48 -2
- package/src/batch/journal.mjs +66 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lane-dirty-check.mjs +437 -0
- package/src/batch/lifecycle.mjs +130 -3
- package/src/batch/limbo-detect.mjs +34 -0
- package/src/batch/macro-phase.mjs +302 -0
- package/src/batch/merge/adoption-doc-merge.mjs +93 -10
- package/src/batch/merge/wave-merge-state.mjs +3 -0
- package/src/batch/metrics.mjs +76 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +234 -0
- package/src/batch/post-merge-limbo.mjs +259 -28
- package/src/batch/reconcile.mjs +508 -63
- package/src/batch/resume-common.mjs +32 -1
- package/src/batch/resume-lane-reviews.mjs +16 -0
- package/src/batch/resume-multi-lanes.mjs +67 -1
- package/src/batch/resume-multi-validate.mjs +67 -6
- package/src/batch/resume-multi.mjs +11 -4
- package/src/batch/resume.mjs +59 -45
- package/src/batch/retry.mjs +97 -15
- package/src/batch/review-spawn.mjs +8 -2
- package/src/batch/rules-manifest-drift.mjs +198 -0
- package/src/batch/salvage.mjs +2 -1
- package/src/batch/sequence-state.mjs +290 -0
- package/src/batch/sequence.mjs +516 -0
- package/src/batch/state.mjs +34 -3
- package/src/batch/status-json.mjs +67 -0
- package/src/batch/task-stall-budget.mjs +22 -10
- package/src/batch/worker-host.mjs +96 -7
- package/src/batch/worker-output.mjs +196 -3
- package/src/cli/issue-draft.mjs +180 -0
- package/src/cli/journal-follow.mjs +239 -0
- package/src/cli/lane-logs.mjs +291 -0
- package/src/cli/sequence.mjs +121 -0
- package/src/cli/settings-set.mjs +35 -24
- package/src/cli/wait.mjs +187 -0
- package/src/cli/watch.mjs +160 -0
- package/src/config/agent-model-resolve.mjs +48 -0
- package/src/config/cursor-rules/discover.mjs +3 -21
- package/src/config/defaults.mjs +7 -1
- package/src/config/model-id.mjs +103 -0
- package/src/config/settings-fields.mjs +48 -0
- package/src/config/spine-init-constants.mjs +2 -0
- package/src/config/spine-preflight-lib.mjs +494 -17
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +234 -18
- package/src/dashboard/public/index.html +14 -2
- package/src/dashboard/running-tail-state.mjs +31 -0
- package/src/dashboard/server.mjs +8 -0
- package/src/dashboard/snapshot.mjs +472 -26
- package/src/dashboard/view.mjs +282 -19
- package/src/doctor/agent-model-inherit.mjs +61 -6
- 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 +32 -1
- package/src/doctor/sequence-safety.mjs +57 -0
- package/src/doctor/stale-worktrees.mjs +102 -0
- package/src/fixtures/scenario-registry.mjs +194 -0
- package/src/fs/atomic-write.mjs +49 -0
- package/src/planner/file-scope.mjs +246 -0
- package/src/planner/format-plan.mjs +9 -7
- package/src/planner/index.mjs +6 -2
- package/src/planner/scope.mjs +5 -1
- package/src/planner/wave-scope.mjs +136 -0
- package/src/planner/waves.mjs +133 -0
- package/src/tasks/packet/index.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +73 -2
- package/src/tasks/packet/validate-contract.mjs +108 -0
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/templates/spine-config.json +8 -1
|
@@ -12,17 +12,13 @@ import {
|
|
|
12
12
|
skipTaskDoneOnDisk,
|
|
13
13
|
} from "./engine-lanes/queue.mjs";
|
|
14
14
|
import { appendJournalEvent } from "./journal.mjs";
|
|
15
|
-
import {
|
|
16
|
-
commitLaneWorktree,
|
|
17
|
-
filterPorcelain,
|
|
18
|
-
gitPorcelain,
|
|
19
|
-
} from "./lane-commit.mjs";
|
|
15
|
+
import { commitLaneAndValidateWorktree } from "./engine-lanes/commit.mjs";
|
|
20
16
|
import { recordTaskFailureSalvage } from "./salvage.mjs";
|
|
17
|
+
import { saveEngineBatchState } from "./pause.mjs";
|
|
21
18
|
import {
|
|
22
19
|
recordTaskSucceeded,
|
|
23
20
|
recordTaskTransition,
|
|
24
21
|
recomputeTaskCounters,
|
|
25
|
-
saveSpineBatchState,
|
|
26
22
|
updateSegmentForTask,
|
|
27
23
|
} from "./state.mjs";
|
|
28
24
|
import { runWorker } from "./worker-host.mjs";
|
|
@@ -129,7 +125,7 @@ export async function runTaskOnLane({
|
|
|
129
125
|
task.status = "running";
|
|
130
126
|
if (!task.startedAt) task.startedAt = Date.now();
|
|
131
127
|
updateSegmentForTask(state, taskId, "running");
|
|
132
|
-
|
|
128
|
+
saveEngineBatchState(projectRoot, state);
|
|
133
129
|
appendJournalEvent(projectRoot, batchId, "task.started", {
|
|
134
130
|
taskId,
|
|
135
131
|
laneNumber,
|
|
@@ -150,12 +146,12 @@ export async function runTaskOnLane({
|
|
|
150
146
|
config,
|
|
151
147
|
onHeartbeat: (timestamp) => {
|
|
152
148
|
lane.lastHeartbeatAt = timestamp;
|
|
153
|
-
|
|
149
|
+
saveEngineBatchState(projectRoot, state);
|
|
154
150
|
},
|
|
155
151
|
onWorkerPid: (pid) => {
|
|
156
152
|
if (pid > 0) {
|
|
157
153
|
lane.workerPid = pid;
|
|
158
|
-
|
|
154
|
+
saveEngineBatchState(projectRoot, state);
|
|
159
155
|
}
|
|
160
156
|
},
|
|
161
157
|
});
|
|
@@ -176,7 +172,7 @@ export async function runTaskOnLane({
|
|
|
176
172
|
});
|
|
177
173
|
if (lane.workerPid) {
|
|
178
174
|
delete lane.workerPid;
|
|
179
|
-
|
|
175
|
+
saveEngineBatchState(projectRoot, state);
|
|
180
176
|
}
|
|
181
177
|
} else {
|
|
182
178
|
const aborted = workerResult.classification === "aborted";
|
|
@@ -192,7 +188,7 @@ export async function runTaskOnLane({
|
|
|
192
188
|
task.exitReason = workerResult.classification ?? "worker_failed";
|
|
193
189
|
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
194
190
|
recomputeTaskCounters(state);
|
|
195
|
-
|
|
191
|
+
saveEngineBatchState(projectRoot, state);
|
|
196
192
|
if (!aborted) {
|
|
197
193
|
const salvageFields = recordTaskFailureSalvage({
|
|
198
194
|
projectRoot,
|
|
@@ -231,7 +227,7 @@ export async function runTaskOnLane({
|
|
|
231
227
|
|
|
232
228
|
if (lane.workerPid) {
|
|
233
229
|
delete lane.workerPid;
|
|
234
|
-
|
|
230
|
+
saveEngineBatchState(projectRoot, state);
|
|
235
231
|
}
|
|
236
232
|
|
|
237
233
|
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
@@ -286,83 +282,30 @@ export async function runTaskOnLane({
|
|
|
286
282
|
const ignorePatterns = Array.isArray(config?.worktreeSetupIgnorePaths)
|
|
287
283
|
? config.worktreeSetupIgnorePaths
|
|
288
284
|
: [];
|
|
289
|
-
const
|
|
285
|
+
const commitResult = commitLaneAndValidateWorktree({
|
|
290
286
|
worktreePath: wt,
|
|
291
287
|
taskBranch,
|
|
292
288
|
taskId,
|
|
293
289
|
batchId,
|
|
294
290
|
taskFolder: taskFolderInWorktree,
|
|
295
291
|
projectRoot,
|
|
292
|
+
fileScopePaths,
|
|
293
|
+
ignorePatterns,
|
|
294
|
+
task,
|
|
295
|
+
lane,
|
|
296
|
+
laneNumber,
|
|
297
|
+
laneCorrelationId,
|
|
298
|
+
state,
|
|
299
|
+
config,
|
|
296
300
|
});
|
|
297
|
-
if (!
|
|
298
|
-
task.status = "failed";
|
|
299
|
-
task.endedAt = Date.now();
|
|
300
|
-
task.exitReason = laneCommit.failureClass ?? "lane_commit_failed";
|
|
301
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
302
|
-
recomputeTaskCounters(state);
|
|
303
|
-
saveSpineBatchState(projectRoot, state);
|
|
304
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
305
|
-
taskId,
|
|
306
|
-
laneNumber,
|
|
307
|
-
laneId: lane.laneId,
|
|
308
|
-
correlationId: laneCorrelationId,
|
|
309
|
-
classification: laneCommit.failureClass ?? "lane_commit_failed",
|
|
310
|
-
exitCode: 1,
|
|
311
|
-
output: laneCommit.error,
|
|
312
|
-
});
|
|
313
|
-
recordLaneTaskMetric({
|
|
314
|
-
projectRoot,
|
|
315
|
-
batchId,
|
|
316
|
-
task,
|
|
317
|
-
config,
|
|
318
|
-
taskFolder: taskFolderInWorktree,
|
|
319
|
-
});
|
|
320
|
-
return {
|
|
321
|
-
ok: false,
|
|
322
|
-
error: "lane_commit_failed",
|
|
323
|
-
output: laneCommit.error,
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
if (laneCommit.committed) {
|
|
327
|
-
appendJournalEvent(projectRoot, batchId, "lane.committed", {
|
|
328
|
-
taskId,
|
|
329
|
-
laneNumber,
|
|
330
|
-
commitSha: laneCommit.commitSha,
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const remainingDirty = filterPorcelain(gitPorcelain(wt), ignorePatterns);
|
|
335
|
-
if (remainingDirty) {
|
|
336
|
-
const dirtyOutput =
|
|
337
|
-
"Lane worktree still has uncommitted changes after auto-commit — commit manually or fix worker output";
|
|
338
|
-
task.status = "failed";
|
|
339
|
-
task.endedAt = Date.now();
|
|
340
|
-
task.exitReason = "DirtyWorktree";
|
|
341
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
342
|
-
recomputeTaskCounters(state);
|
|
343
|
-
saveSpineBatchState(projectRoot, state);
|
|
344
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
345
|
-
taskId,
|
|
346
|
-
laneNumber,
|
|
347
|
-
laneId: lane.laneId,
|
|
348
|
-
correlationId: laneCorrelationId,
|
|
349
|
-
classification: "DirtyWorktree",
|
|
350
|
-
exitCode: 1,
|
|
351
|
-
output: dirtyOutput,
|
|
352
|
-
});
|
|
353
|
-
recordLaneTaskMetric({
|
|
354
|
-
projectRoot,
|
|
355
|
-
batchId,
|
|
356
|
-
task,
|
|
357
|
-
config,
|
|
358
|
-
taskFolder: taskFolderInWorktree,
|
|
359
|
-
});
|
|
301
|
+
if (!commitResult.ok) {
|
|
360
302
|
return {
|
|
361
303
|
ok: false,
|
|
362
|
-
error:
|
|
363
|
-
output:
|
|
304
|
+
error: commitResult.error,
|
|
305
|
+
output: commitResult.output,
|
|
364
306
|
};
|
|
365
307
|
}
|
|
308
|
+
const { laneCommit } = commitResult;
|
|
366
309
|
|
|
367
310
|
recordTaskSucceeded(state, taskId, { exitReason: "done", doneFileFound: true });
|
|
368
311
|
recordTaskTransition({
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
filterPendingTaskIds,
|
|
9
9
|
} from "../planner/pending.mjs";
|
|
10
10
|
import { NO_PENDING_TASKS_ERROR, parseScope } from "../planner/scope.mjs";
|
|
11
|
+
import { filterPlanToWave } from "../planner/wave-scope.mjs";
|
|
11
12
|
import { appendJournalEvent } from "./journal.mjs";
|
|
12
13
|
import {
|
|
13
14
|
loadSpineBatchState,
|
|
@@ -109,8 +110,17 @@ export function resolveBatchStartScope(scope, tasksRoot, options = {}) {
|
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
112
|
* @param {object} plan
|
|
112
|
-
* @param {
|
|
113
|
+
* @param {number|null|undefined} waveFilter
|
|
113
114
|
*/
|
|
115
|
+
export function applyBatchStartWaveFilter(plan, waveFilter) {
|
|
116
|
+
if (waveFilter == null) {
|
|
117
|
+
return { ok: /** @type {const} */ (true), plan };
|
|
118
|
+
}
|
|
119
|
+
return filterPlanToWave(plan, waveFilter);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { filterPlanToWave };
|
|
123
|
+
|
|
114
124
|
export function canStartMultiTaskBatch(plan, scope) {
|
|
115
125
|
const taskIds = countPlanTasks(plan);
|
|
116
126
|
if (taskIds.length <= 1) {
|
package/src/batch/engine.mjs
CHANGED
|
@@ -11,14 +11,16 @@ import { buildPlan } from "../planner/index.mjs";
|
|
|
11
11
|
import { runBatchPreflight, resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
12
12
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
13
13
|
import { integrateOrchToBase } from "./integrate.mjs";
|
|
14
|
-
import {
|
|
14
|
+
import { installAttachedEngineShutdownHandlers } from "./attached-engine-handoff.mjs";
|
|
15
|
+
import { finalizeBatchForIntegrate, tryFinalizePostMergeLimbo } from "./post-merge-limbo.mjs";
|
|
16
|
+
import { detectPostMergeLimboForResume } from "./resume-multi-validate.mjs";
|
|
15
17
|
import { appendJournalEvent } from "./journal.mjs";
|
|
18
|
+
import { adoptPauseIfRequested, saveEngineBatchState } from "./pause.mjs";
|
|
16
19
|
import {
|
|
17
20
|
assertNoActiveBatch,
|
|
18
21
|
createInitialBatchState,
|
|
19
22
|
generateBatchId,
|
|
20
23
|
recordBatchEnginePid,
|
|
21
|
-
saveSpineBatchState,
|
|
22
24
|
} from "./state.mjs";
|
|
23
25
|
import {
|
|
24
26
|
ensureOrchBranch,
|
|
@@ -35,6 +37,7 @@ import {
|
|
|
35
37
|
resolveBatchStartScope,
|
|
36
38
|
shouldAutoIntegrateAfterWave,
|
|
37
39
|
} from "./engine-scope.mjs";
|
|
40
|
+
import { filterPlanToWave } from "../planner/wave-scope.mjs";
|
|
38
41
|
import {
|
|
39
42
|
buildTasksAndLanesFromPlan,
|
|
40
43
|
mergeWaveLanesToOrch,
|
|
@@ -43,6 +46,19 @@ import {
|
|
|
43
46
|
transitionPhase,
|
|
44
47
|
} from "./engine-lanes.mjs";
|
|
45
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} batchId
|
|
51
|
+
*/
|
|
52
|
+
function buildEnginePausedResult(batchId) {
|
|
53
|
+
return {
|
|
54
|
+
ok: true,
|
|
55
|
+
exitCode: 0,
|
|
56
|
+
batchId,
|
|
57
|
+
paused: true,
|
|
58
|
+
output: "Batch paused.\n",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
export {
|
|
47
63
|
assessWaveMergeEligibility,
|
|
48
64
|
buildTaskLaneAssignments,
|
|
@@ -56,6 +72,29 @@ export {
|
|
|
56
72
|
} from "./engine-scope.mjs";
|
|
57
73
|
export { loadTaskFileScopePaths, mergeLaneToOrch } from "./engine-lanes.mjs";
|
|
58
74
|
|
|
75
|
+
const WORKTREE_SPINE_PATTERN = /[/\\]\.worktrees[/\\]spine-/;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Detect whether the current process is running inside a spine worker context.
|
|
79
|
+
* Returns a human-readable reason string if nested, or null if safe to proceed.
|
|
80
|
+
*
|
|
81
|
+
* Two guards: (1) SPINE_IS_WORKER env set by worker-host, and
|
|
82
|
+
* (2) projectRoot inside a .worktrees/spine-* directory (catches cases where
|
|
83
|
+
* the env was not inherited but the target is clearly a lane worktree).
|
|
84
|
+
*
|
|
85
|
+
* @param {string} projectRoot — the directory where the batch would run
|
|
86
|
+
* @returns {string | null}
|
|
87
|
+
*/
|
|
88
|
+
export function detectNestedWorkerContext(projectRoot) {
|
|
89
|
+
if (process.env.SPINE_IS_WORKER === "1") {
|
|
90
|
+
return "SPINE_IS_WORKER=1 is set (running inside a worker process)";
|
|
91
|
+
}
|
|
92
|
+
if (WORKTREE_SPINE_PATTERN.test(projectRoot)) {
|
|
93
|
+
return "projectRoot is inside a .worktrees/spine-* lane directory";
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
59
98
|
/**
|
|
60
99
|
* @param {object} options
|
|
61
100
|
* @param {string} options.projectRoot
|
|
@@ -63,6 +102,7 @@ export { loadTaskFileScopePaths, mergeLaneToOrch } from "./engine-lanes.mjs";
|
|
|
63
102
|
* @param {boolean} [options.dryRun]
|
|
64
103
|
* @param {boolean} [options.skipPreflight]
|
|
65
104
|
* @param {boolean} [options.forceSuperseded]
|
|
105
|
+
* @param {number|null} [options.waveFilter]
|
|
66
106
|
*/
|
|
67
107
|
export async function startBatch({
|
|
68
108
|
projectRoot,
|
|
@@ -70,7 +110,31 @@ export async function startBatch({
|
|
|
70
110
|
dryRun = false,
|
|
71
111
|
skipPreflight = false,
|
|
72
112
|
forceSuperseded = false,
|
|
113
|
+
waveFilter = null,
|
|
73
114
|
}) {
|
|
115
|
+
const nestedReason = detectNestedWorkerContext(projectRoot);
|
|
116
|
+
if (nestedReason) {
|
|
117
|
+
const parentBatchId = process.env.SPINE_BATCH_ID ?? "unknown";
|
|
118
|
+
try {
|
|
119
|
+
appendJournalEvent(projectRoot, parentBatchId, "engine.nested_spawn_blocked", {
|
|
120
|
+
projectRoot,
|
|
121
|
+
parentBatchId,
|
|
122
|
+
reason: nestedReason,
|
|
123
|
+
});
|
|
124
|
+
} catch {
|
|
125
|
+
// Journal may not be writable from a worker worktree; best-effort.
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
exitCode: 1,
|
|
130
|
+
error: "nested_batch_spawn_blocked",
|
|
131
|
+
output:
|
|
132
|
+
`Nested batch start blocked: ${nestedReason}. ` +
|
|
133
|
+
`Workers must not spawn batch engines. ` +
|
|
134
|
+
`Parent batch: ${parentBatchId}, projectRoot: ${projectRoot}\n`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
74
138
|
if (!skipPreflight) {
|
|
75
139
|
const preflight = runBatchPreflight({ projectRoot, skipDoctor: false });
|
|
76
140
|
if (!preflight.ok) {
|
|
@@ -107,7 +171,22 @@ export async function startBatch({
|
|
|
107
171
|
const policyScope = scopeResolution.policyScope ?? effectiveScope;
|
|
108
172
|
|
|
109
173
|
const plan = buildPlan({ scope: effectiveScope, config, tasksRoot: /** @type {string} */ (tasksRoot) });
|
|
110
|
-
|
|
174
|
+
let effectivePlan = plan;
|
|
175
|
+
let plannerWaveCount = plan.waves?.length ?? 0;
|
|
176
|
+
if (waveFilter != null) {
|
|
177
|
+
const filtered = filterPlanToWave(plan, waveFilter);
|
|
178
|
+
if (filtered.ok !== true) {
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
exitCode: 1,
|
|
182
|
+
error: filtered.error,
|
|
183
|
+
output: `${filtered.output}\n`,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
effectivePlan = /** @type {typeof plan} */ (filtered.plan);
|
|
187
|
+
plannerWaveCount = filtered.waveCount;
|
|
188
|
+
}
|
|
189
|
+
const batchPolicy = canStartMultiTaskBatch(effectivePlan, policyScope ?? effectiveScope);
|
|
111
190
|
if (!batchPolicy.ok) {
|
|
112
191
|
return {
|
|
113
192
|
ok: false,
|
|
@@ -118,17 +197,20 @@ export async function startBatch({
|
|
|
118
197
|
}
|
|
119
198
|
|
|
120
199
|
const taskIds = batchPolicy.taskIds;
|
|
121
|
-
const maxLaneNumber = maxLaneNumberForPlan(
|
|
200
|
+
const maxLaneNumber = maxLaneNumberForPlan(effectivePlan);
|
|
122
201
|
|
|
123
202
|
if (dryRun) {
|
|
203
|
+
const waveHint =
|
|
204
|
+
waveFilter != null ? ` (planner wave ${waveFilter} of ${plannerWaveCount})` : "";
|
|
124
205
|
return {
|
|
125
206
|
ok: true,
|
|
126
207
|
exitCode: 0,
|
|
127
208
|
dryRun: true,
|
|
128
209
|
taskIds,
|
|
129
|
-
plan,
|
|
210
|
+
plan: effectivePlan,
|
|
211
|
+
waveFilter,
|
|
130
212
|
output:
|
|
131
|
-
`Dry run: would start batch for ${taskIds.length} task(s) across ${
|
|
213
|
+
`Dry run: would start batch for ${taskIds.length} task(s) across ${effectivePlan.waves.length} wave(s)${waveHint}, ` +
|
|
132
214
|
`up to ${maxLaneNumber} lane(s), maxParallel=${config.lanes?.maxParallel ?? 1}.\n`,
|
|
133
215
|
};
|
|
134
216
|
}
|
|
@@ -145,7 +227,7 @@ export async function startBatch({
|
|
|
145
227
|
}
|
|
146
228
|
|
|
147
229
|
const { tasks, lanes } = buildTasksAndLanesFromPlan({
|
|
148
|
-
plan,
|
|
230
|
+
plan: effectivePlan,
|
|
149
231
|
discovered,
|
|
150
232
|
projectRoot,
|
|
151
233
|
batchId,
|
|
@@ -157,18 +239,19 @@ export async function startBatch({
|
|
|
157
239
|
batchId,
|
|
158
240
|
baseBranch,
|
|
159
241
|
orchBranch,
|
|
160
|
-
wavePlan:
|
|
242
|
+
wavePlan: effectivePlan.waves.map((/** @type {{ taskIds: string[] }} */ wave) => wave.taskIds),
|
|
161
243
|
tasks,
|
|
162
244
|
lanes,
|
|
163
245
|
});
|
|
164
246
|
|
|
165
|
-
|
|
247
|
+
saveEngineBatchState(projectRoot, state);
|
|
166
248
|
|
|
167
249
|
try {
|
|
168
250
|
ensureOrchBranch(projectRoot, baseBranch, orchBranch);
|
|
169
251
|
transitionPhase(state, "running", { projectRoot, batchId });
|
|
170
252
|
recordBatchEnginePid(state, process.pid);
|
|
171
|
-
|
|
253
|
+
installAttachedEngineShutdownHandlers({ projectRoot });
|
|
254
|
+
saveEngineBatchState(projectRoot, state);
|
|
172
255
|
|
|
173
256
|
for (const lane of state.lanes) {
|
|
174
257
|
lane.correlationId = crypto.randomUUID();
|
|
@@ -225,15 +308,24 @@ export async function startBatch({
|
|
|
225
308
|
correlationId: lane.correlationId,
|
|
226
309
|
});
|
|
227
310
|
}
|
|
228
|
-
|
|
311
|
+
saveEngineBatchState(projectRoot, state);
|
|
229
312
|
|
|
230
313
|
let batchAborted = false;
|
|
231
314
|
|
|
232
|
-
for (const wave of
|
|
315
|
+
for (const wave of effectivePlan.waves) {
|
|
316
|
+
const pauseAtWave = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
317
|
+
if (pauseAtWave.stop) {
|
|
318
|
+
return buildEnginePausedResult(batchId);
|
|
319
|
+
}
|
|
320
|
+
|
|
233
321
|
state.currentWaveIndex = wave.index;
|
|
234
|
-
|
|
322
|
+
saveEngineBatchState(projectRoot, state);
|
|
235
323
|
|
|
236
324
|
for (const tick of wave.ticks ?? []) {
|
|
325
|
+
const pauseAtTick = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
326
|
+
if (pauseAtTick.stop) {
|
|
327
|
+
return buildEnginePausedResult(batchId);
|
|
328
|
+
}
|
|
237
329
|
/** @type {Map<number, { lane: object, runs: Array<{ taskId: string, run: () => Promise<{ ok: boolean, aborted?: boolean }> }> }>} */
|
|
238
330
|
const runsByLane = new Map();
|
|
239
331
|
|
|
@@ -316,6 +408,11 @@ export async function startBatch({
|
|
|
316
408
|
|
|
317
409
|
await Promise.all(laneExecutions);
|
|
318
410
|
if (batchAborted) break;
|
|
411
|
+
|
|
412
|
+
const pauseAfterTick = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
413
|
+
if (pauseAfterTick.stop) {
|
|
414
|
+
return buildEnginePausedResult(batchId);
|
|
415
|
+
}
|
|
319
416
|
}
|
|
320
417
|
|
|
321
418
|
if (batchAborted) {
|
|
@@ -327,7 +424,7 @@ export async function startBatch({
|
|
|
327
424
|
batchId,
|
|
328
425
|
extra: { taskId: abortedTask?.taskId },
|
|
329
426
|
});
|
|
330
|
-
|
|
427
|
+
saveEngineBatchState(projectRoot, state);
|
|
331
428
|
return {
|
|
332
429
|
ok: false,
|
|
333
430
|
exitCode: 1,
|
|
@@ -351,7 +448,7 @@ export async function startBatch({
|
|
|
351
448
|
reason: "mixed_outcome",
|
|
352
449
|
},
|
|
353
450
|
});
|
|
354
|
-
|
|
451
|
+
saveEngineBatchState(projectRoot, state);
|
|
355
452
|
appendJournalEvent(projectRoot, batchId, "batch.merge_blocked", {
|
|
356
453
|
waveIndex: wave.index,
|
|
357
454
|
failedTaskIds: mergeEligibility.failedTaskIds,
|
|
@@ -376,14 +473,6 @@ export async function startBatch({
|
|
|
376
473
|
waveIndex: wave.index,
|
|
377
474
|
});
|
|
378
475
|
if (!mergeResult.ok) {
|
|
379
|
-
/** @type {any} */ (state).endedAt = Date.now();
|
|
380
|
-
/** @type {any} */ (state).lastError = mergeResult.error ?? "merge failed";
|
|
381
|
-
transitionPhase(state, "failed", {
|
|
382
|
-
projectRoot,
|
|
383
|
-
batchId,
|
|
384
|
-
extra: { reason: "merge", waveIndex: wave.index },
|
|
385
|
-
});
|
|
386
|
-
saveSpineBatchState(projectRoot, state);
|
|
387
476
|
return {
|
|
388
477
|
ok: false,
|
|
389
478
|
exitCode: 1,
|
|
@@ -413,6 +502,18 @@ export async function startBatch({
|
|
|
413
502
|
}
|
|
414
503
|
}
|
|
415
504
|
|
|
505
|
+
if (detectPostMergeLimboForResume({ projectRoot, state })) {
|
|
506
|
+
const limboResult = tryFinalizePostMergeLimbo({
|
|
507
|
+
projectRoot,
|
|
508
|
+
state,
|
|
509
|
+
batchId,
|
|
510
|
+
orchBranch,
|
|
511
|
+
});
|
|
512
|
+
if (limboResult) {
|
|
513
|
+
return limboResult;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
416
517
|
return finalizeBatchForIntegrate({
|
|
417
518
|
projectRoot,
|
|
418
519
|
state,
|
|
@@ -429,7 +530,7 @@ export async function startBatch({
|
|
|
429
530
|
batchId,
|
|
430
531
|
extra: { error: message },
|
|
431
532
|
});
|
|
432
|
-
|
|
533
|
+
saveEngineBatchState(projectRoot, state);
|
|
433
534
|
removeLaneWorktrees(projectRoot, batchId, maxLaneNumber);
|
|
434
535
|
return { ok: false, exitCode: 1, batchId, error: message };
|
|
435
536
|
}
|
package/src/batch/evidence.mjs
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { writeTextAtomic } from "../fs/atomic-write.mjs";
|
|
8
9
|
import { runEvidenceCommand } from "./evidence-command.mjs";
|
|
9
10
|
import { readJournalEvents, readJournalTail } from "./journal.mjs";
|
|
10
11
|
import { generateBatchPostMortem } from "./postmortem.mjs";
|
|
@@ -117,6 +118,22 @@ export function buildTaskScorecard(batchState) {
|
|
|
117
118
|
return `${lines.join("\n")}\n`;
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
/**
|
|
122
|
+
* @param {string} projectRoot
|
|
123
|
+
* @param {string} batchId
|
|
124
|
+
*/
|
|
125
|
+
export function evidenceCompletePath(projectRoot, batchId) {
|
|
126
|
+
return path.join(evidenceDir(projectRoot, batchId), ".complete");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} projectRoot
|
|
131
|
+
* @param {string} batchId
|
|
132
|
+
*/
|
|
133
|
+
export function isEvidenceBundleComplete(projectRoot, batchId) {
|
|
134
|
+
return fs.existsSync(evidenceCompletePath(projectRoot, batchId));
|
|
135
|
+
}
|
|
136
|
+
|
|
120
137
|
/**
|
|
121
138
|
* @param {object} ctx
|
|
122
139
|
* @param {string} ctx.projectRoot
|
|
@@ -124,7 +141,7 @@ export function buildTaskScorecard(batchState) {
|
|
|
124
141
|
* @param {object|null} [ctx.batchState]
|
|
125
142
|
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
126
143
|
*/
|
|
127
|
-
export function
|
|
144
|
+
export function collectCoreEvidenceBundle(ctx) {
|
|
128
145
|
const { projectRoot, batchId, batchState = null, config = null } = ctx;
|
|
129
146
|
const dir = evidenceDir(projectRoot, batchId);
|
|
130
147
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -135,17 +152,46 @@ export function collectEvidenceBundle(ctx) {
|
|
|
135
152
|
const reconciliation = reconcileBatch({ projectRoot, batchState, verbose: true });
|
|
136
153
|
const journalTail = readJournalTail(readJournalEvents(projectRoot, batchId));
|
|
137
154
|
const summary = generateBatchPostMortem(batchState, journalTail, reconciliation, projectRoot);
|
|
138
|
-
|
|
155
|
+
writeTextAtomic(path.join(dir, "summary.md"), summary);
|
|
139
156
|
evidenceRefs.push("evidence/summary.md");
|
|
140
157
|
|
|
141
158
|
const baseBranch = batchState?.baseBranch ?? config?.baseBranch ?? "main";
|
|
142
159
|
const orchBranch = batchState?.orchBranch ?? null;
|
|
143
160
|
if (orchBranch) {
|
|
144
161
|
const diffStat = collectDiffStat(projectRoot, baseBranch, orchBranch);
|
|
145
|
-
|
|
162
|
+
writeTextAtomic(path.join(dir, "diff-stat.txt"), `${diffStat}\n`);
|
|
146
163
|
evidenceRefs.push("evidence/diff-stat.txt");
|
|
147
164
|
}
|
|
148
165
|
|
|
166
|
+
for (const ref of collectWorkerOutputEvidenceRefs(projectRoot, batchId)) {
|
|
167
|
+
evidenceRefs.push(ref);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const name of fs.readdirSync(dir)) {
|
|
171
|
+
if (name.startsWith("salvage-") && name.endsWith(".json")) {
|
|
172
|
+
evidenceRefs.push(`evidence/${name}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param {object} ctx
|
|
181
|
+
* @param {string} ctx.projectRoot
|
|
182
|
+
* @param {string} ctx.batchId
|
|
183
|
+
* @param {object|null} [ctx.batchState]
|
|
184
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
185
|
+
* @param {string[]} [ctx.evidenceRefs]
|
|
186
|
+
*/
|
|
187
|
+
export function collectExtendedEvidenceBundle(ctx) {
|
|
188
|
+
const { projectRoot, batchId, batchState = null, config = null } = ctx;
|
|
189
|
+
const dir = evidenceDir(projectRoot, batchId);
|
|
190
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
191
|
+
|
|
192
|
+
/** @type {string[]} */
|
|
193
|
+
const evidenceRefs = [...(ctx.evidenceRefs ?? [])];
|
|
194
|
+
|
|
149
195
|
const gates = config?.gates ?? {};
|
|
150
196
|
const testing = resolveTestingCommands(config, projectRoot);
|
|
151
197
|
const collectTest = gates.collectTestEvidence !== false;
|
|
@@ -153,33 +199,50 @@ export function collectEvidenceBundle(ctx) {
|
|
|
153
199
|
|
|
154
200
|
if (collectTest && testing.test) {
|
|
155
201
|
const result = runEvidenceCommand(projectRoot, testing.test);
|
|
156
|
-
|
|
202
|
+
writeTextAtomic(path.join(dir, "test-output.txt"), `${result.output}\n`);
|
|
157
203
|
evidenceRefs.push("evidence/test-output.txt");
|
|
158
204
|
}
|
|
159
205
|
|
|
160
206
|
if (collectBuild && testing.build) {
|
|
161
207
|
const result = runEvidenceCommand(projectRoot, testing.build);
|
|
162
|
-
|
|
208
|
+
writeTextAtomic(path.join(dir, "build-output.txt"), `${result.output}\n`);
|
|
163
209
|
evidenceRefs.push("evidence/build-output.txt");
|
|
164
210
|
}
|
|
165
211
|
|
|
166
212
|
if (testing.testWithCoverage) {
|
|
167
213
|
const result = runEvidenceCommand(projectRoot, testing.testWithCoverage);
|
|
168
|
-
|
|
214
|
+
writeTextAtomic(path.join(dir, "coverage-output.txt"), `${result.output}\n`);
|
|
169
215
|
evidenceRefs.push("evidence/coverage-output.txt");
|
|
170
216
|
}
|
|
171
217
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
218
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
219
|
+
}
|
|
175
220
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
221
|
+
/**
|
|
222
|
+
* @param {string} projectRoot
|
|
223
|
+
* @param {string} batchId
|
|
224
|
+
* @param {string[]} evidenceRefs
|
|
225
|
+
*/
|
|
226
|
+
export function finalizeEvidenceBundleComplete(projectRoot, batchId, evidenceRefs) {
|
|
227
|
+
const completePayload = `${JSON.stringify({
|
|
228
|
+
completedAt: new Date().toISOString(),
|
|
229
|
+
evidenceRefs,
|
|
230
|
+
})}\n`;
|
|
231
|
+
writeTextAtomic(evidenceCompletePath(projectRoot, batchId), completePayload);
|
|
232
|
+
}
|
|
181
233
|
|
|
182
|
-
|
|
234
|
+
/**
|
|
235
|
+
* @param {object} ctx
|
|
236
|
+
* @param {string} ctx.projectRoot
|
|
237
|
+
* @param {string} ctx.batchId
|
|
238
|
+
* @param {object|null} [ctx.batchState]
|
|
239
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
240
|
+
*/
|
|
241
|
+
export function collectEvidenceBundle(ctx) {
|
|
242
|
+
const core = collectCoreEvidenceBundle(ctx);
|
|
243
|
+
const extended = collectExtendedEvidenceBundle({ ...ctx, evidenceRefs: core.evidenceRefs });
|
|
244
|
+
finalizeEvidenceBundleComplete(ctx.projectRoot, ctx.batchId, extended.evidenceRefs);
|
|
245
|
+
return { evidenceDir: extended.evidenceDir, evidenceRefs: extended.evidenceRefs };
|
|
183
246
|
}
|
|
184
247
|
|
|
185
248
|
/**
|