pi-spine 1.0.2 → 1.2.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 +61 -489
- package/bin/get-version.mjs +1 -13
- package/bin/spine-batch.mjs +162 -51
- 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/wait.mjs +30 -0
- package/bin/spine-cli/watch.mjs +27 -0
- package/bin/spine-config.mjs +1 -212
- package/bin/spine-doctor.mjs +2 -418
- package/bin/spine-init.mjs +1 -398
- package/bin/spine-issue.mjs +196 -0
- package/bin/spine-journal.mjs +1 -0
- package/bin/spine-preflight.mjs +1 -700
- package/bin/spine-review-step.mjs +6 -4
- package/bin/spine-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +112 -13
- package/bin/spine-worker-runner.mjs +24 -14
- package/bin/spine.mjs +52 -2
- package/extensions/spine/worker-tools.ts +14 -12
- package/package.json +5 -2
- package/skills/create-spine-tasks/SKILL.md +135 -6
- package/skills/create-spine-tasks/references/clarify-template.md +73 -0
- package/skills/create-spine-tasks/references/contract-template.md +19 -0
- package/skills/create-spine-tasks/references/prompt-template.md +2 -0
- package/skills/create-spine-tasks/references/requirements-checklist-template.md +94 -0
- package/src/batch/abort.mjs +3 -12
- package/src/batch/agent-session-worker.mjs +45 -5
- package/src/batch/attached-engine-handoff.mjs +188 -0
- package/src/batch/attached-runner.mjs +312 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-verify.mjs +140 -2
- package/src/batch/detached-start.mjs +105 -7
- package/src/batch/diagnosis-alternatives.mjs +46 -0
- package/src/batch/diagnosis-merge-failure.mjs +79 -0
- package/src/batch/diagnosis-retry-limbo.mjs +34 -0
- package/src/batch/diagnosis-stub.mjs +109 -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 +174 -62
- package/src/batch/engine-lanes/merge.mjs +168 -77
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/review.mjs +32 -74
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +1 -0
- package/src/batch/engine-scope.mjs +42 -5
- package/src/batch/engine.mjs +115 -68
- package/src/batch/evidence.mjs +81 -17
- package/src/batch/gate.mjs +46 -17
- package/src/batch/git-helpers.mjs +96 -0
- package/src/batch/heartbeat.mjs +73 -7
- package/src/batch/integrate.mjs +3 -5
- package/src/batch/journal.mjs +25 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lifecycle.mjs +131 -4
- package/src/batch/macro-phase.mjs +226 -0
- package/src/batch/merge/adoption-doc-merge.mjs +243 -0
- package/src/batch/merge/wave-merge-state.mjs +108 -0
- package/src/batch/metrics.mjs +74 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +223 -0
- package/src/batch/post-merge-limbo.mjs +345 -17
- package/src/batch/reconcile.mjs +473 -50
- package/src/batch/resume-common.mjs +6 -2
- package/src/batch/resume-engine.mjs +58 -1
- package/src/batch/resume-lane-reviews.mjs +16 -0
- package/src/batch/resume-multi-lanes.mjs +56 -1
- package/src/batch/resume-multi-validate.mjs +148 -8
- package/src/batch/resume-multi.mjs +45 -44
- package/src/batch/resume.mjs +64 -47
- package/src/batch/retry.mjs +56 -5
- package/src/batch/review-shared.mjs +196 -0
- package/src/batch/review-spawn.mjs +326 -0
- package/src/batch/review.mjs +178 -212
- package/src/batch/rules-manifest-drift.mjs +157 -0
- package/src/batch/salvage.mjs +2 -1
- package/src/batch/sequence.mjs +454 -0
- package/src/batch/state.mjs +18 -3
- package/src/batch/status-json.mjs +67 -0
- package/src/batch/task-stall-budget.mjs +94 -10
- package/src/batch/worker-host.mjs +185 -37
- package/src/batch/worker-output.mjs +196 -3
- package/src/batch/worktree.mjs +10 -0
- package/src/cli/handoff.mjs +1 -1
- 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/rules.mjs +1 -1
- package/src/cli/sequence.mjs +108 -0
- package/src/cli/settings-set.mjs +3 -22
- package/src/cli/settings-slash.mjs +27 -5
- 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/settings-fields.mjs +48 -0
- package/src/config/spine-config-load.mjs +221 -0
- package/src/config/spine-init-constants.mjs +424 -0
- package/src/config/spine-preflight-lib.mjs +1180 -0
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +224 -40
- package/src/dashboard/public/index.html +15 -9
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +387 -6
- package/src/dashboard/view.mjs +170 -15
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/run-doctor-checks.mjs +483 -0
- package/src/doctor/sequence-safety.mjs +57 -0
- package/src/doctor/stale-path.mjs +22 -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/migrate/taskplane-config.mjs +1 -1
- 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/pending.mjs +92 -1
- package/src/planner/wave-scope.mjs +136 -0
- package/src/planner/waves.mjs +133 -0
- package/src/tasks/analyze/index.mjs +453 -0
- package/src/tasks/packet/index.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +42 -1
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/src/util/command-exists.mjs +19 -0
- package/templates/docs/constitution.md +61 -0
- package/templates/spine-config.json +9 -2
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { discoverTasks } from "../tasks/packet/discover.mjs";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
assertBatchStartTasksNotSuperseded,
|
|
8
|
+
filterPendingTaskIds,
|
|
9
|
+
} from "../planner/pending.mjs";
|
|
10
|
+
import { NO_PENDING_TASKS_ERROR, parseScope } from "../planner/scope.mjs";
|
|
11
|
+
import { filterPlanToWave } from "../planner/wave-scope.mjs";
|
|
8
12
|
import { appendJournalEvent } from "./journal.mjs";
|
|
9
13
|
import {
|
|
10
14
|
loadSpineBatchState,
|
|
@@ -51,13 +55,14 @@ export function isExplicitBatchScope(scope) {
|
|
|
51
55
|
*
|
|
52
56
|
* @param {string} scope
|
|
53
57
|
* @param {string} tasksRoot
|
|
58
|
+
* @param {{ forceSuperseded?: boolean }} [options]
|
|
54
59
|
*/
|
|
55
|
-
export function resolveBatchStartScope(scope, tasksRoot) {
|
|
60
|
+
export function resolveBatchStartScope(scope, tasksRoot, options = {}) {
|
|
56
61
|
const trimmed = String(scope ?? "").trim();
|
|
57
62
|
const normalized = trimmed.toLowerCase();
|
|
63
|
+
const discovered = discoverTasks(tasksRoot);
|
|
58
64
|
|
|
59
65
|
if (!trimmed || normalized === "all") {
|
|
60
|
-
const discovered = discoverTasks(tasksRoot);
|
|
61
66
|
const pendingIds = filterPendingTaskIds(discovered, tasksRoot);
|
|
62
67
|
if (pendingIds.length === 0) {
|
|
63
68
|
return {
|
|
@@ -77,13 +82,45 @@ export function resolveBatchStartScope(scope, tasksRoot) {
|
|
|
77
82
|
return { ok: true, scope: "pending", policyScope: "pending" };
|
|
78
83
|
}
|
|
79
84
|
|
|
85
|
+
let resolvedTaskIds = [];
|
|
86
|
+
try {
|
|
87
|
+
const scopeResult = parseScope(trimmed, { tasksRoot, discoveredTasks: discovered });
|
|
88
|
+
resolvedTaskIds = scopeResult.taskIds;
|
|
89
|
+
} catch {
|
|
90
|
+
// Scope parsing errors surface again during buildPlan; still guard bare task ID tokens.
|
|
91
|
+
resolvedTaskIds = trimmed.split(/\s+/).filter((token) => /^[A-Z][A-Z0-9]*-\d{3,}$/.test(token));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const supersededGuard = assertBatchStartTasksNotSuperseded(
|
|
95
|
+
resolvedTaskIds,
|
|
96
|
+
tasksRoot,
|
|
97
|
+
discovered,
|
|
98
|
+
options,
|
|
99
|
+
);
|
|
100
|
+
if (!supersededGuard.ok) {
|
|
101
|
+
return {
|
|
102
|
+
ok: false,
|
|
103
|
+
error: supersededGuard.error,
|
|
104
|
+
output: supersededGuard.output,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
80
108
|
return { ok: true, scope: trimmed, policyScope: trimmed };
|
|
81
109
|
}
|
|
82
110
|
|
|
83
111
|
/**
|
|
84
112
|
* @param {object} plan
|
|
85
|
-
* @param {
|
|
113
|
+
* @param {number|null|undefined} waveFilter
|
|
86
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
|
+
|
|
87
124
|
export function canStartMultiTaskBatch(plan, scope) {
|
|
88
125
|
const taskIds = countPlanTasks(plan);
|
|
89
126
|
if (taskIds.length <= 1) {
|
package/src/batch/engine.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* pi-spine batch engine (Phase 2 single-lane, Phase 3 multi-lane + §17.4 merge policy).
|
|
3
4
|
*/
|
|
@@ -7,17 +8,19 @@ import path from "node:path";
|
|
|
7
8
|
import crypto from "node:crypto";
|
|
8
9
|
import { discoverTasks } from "../tasks/packet/discover.mjs";
|
|
9
10
|
import { buildPlan } from "../planner/index.mjs";
|
|
10
|
-
import { runBatchPreflight, resolveTasksRoot } from "
|
|
11
|
-
import { loadSpineConfig } from "
|
|
12
|
-
import { openIntegrateGateAfterBatchComplete } from "./gate.mjs";
|
|
11
|
+
import { runBatchPreflight, resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
12
|
+
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
13
13
|
import { integrateOrchToBase } from "./integrate.mjs";
|
|
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";
|
|
14
17
|
import { appendJournalEvent } from "./journal.mjs";
|
|
18
|
+
import { adoptPauseIfRequested, saveEngineBatchState } from "./pause.mjs";
|
|
15
19
|
import {
|
|
16
20
|
assertNoActiveBatch,
|
|
17
21
|
createInitialBatchState,
|
|
18
22
|
generateBatchId,
|
|
19
23
|
recordBatchEnginePid,
|
|
20
|
-
saveSpineBatchState,
|
|
21
24
|
} from "./state.mjs";
|
|
22
25
|
import {
|
|
23
26
|
ensureOrchBranch,
|
|
@@ -34,6 +37,7 @@ import {
|
|
|
34
37
|
resolveBatchStartScope,
|
|
35
38
|
shouldAutoIntegrateAfterWave,
|
|
36
39
|
} from "./engine-scope.mjs";
|
|
40
|
+
import { filterPlanToWave } from "../planner/wave-scope.mjs";
|
|
37
41
|
import {
|
|
38
42
|
buildTasksAndLanesFromPlan,
|
|
39
43
|
mergeWaveLanesToOrch,
|
|
@@ -42,6 +46,19 @@ import {
|
|
|
42
46
|
transitionPhase,
|
|
43
47
|
} from "./engine-lanes.mjs";
|
|
44
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
|
+
|
|
45
62
|
export {
|
|
46
63
|
assessWaveMergeEligibility,
|
|
47
64
|
buildTaskLaneAssignments,
|
|
@@ -61,12 +78,16 @@ export { loadTaskFileScopePaths, mergeLaneToOrch } from "./engine-lanes.mjs";
|
|
|
61
78
|
* @param {string} [options.scope]
|
|
62
79
|
* @param {boolean} [options.dryRun]
|
|
63
80
|
* @param {boolean} [options.skipPreflight]
|
|
81
|
+
* @param {boolean} [options.forceSuperseded]
|
|
82
|
+
* @param {number|null} [options.waveFilter]
|
|
64
83
|
*/
|
|
65
84
|
export async function startBatch({
|
|
66
85
|
projectRoot,
|
|
67
86
|
scope = "all",
|
|
68
87
|
dryRun = false,
|
|
69
88
|
skipPreflight = false,
|
|
89
|
+
forceSuperseded = false,
|
|
90
|
+
waveFilter = null,
|
|
70
91
|
}) {
|
|
71
92
|
if (!skipPreflight) {
|
|
72
93
|
const preflight = runBatchPreflight({ projectRoot, skipDoctor: false });
|
|
@@ -75,7 +96,7 @@ export async function startBatch({
|
|
|
75
96
|
ok: false,
|
|
76
97
|
exitCode: preflight.exitCode ?? 1,
|
|
77
98
|
error: "preflight_failed",
|
|
78
|
-
output: preflight.output,
|
|
99
|
+
output: /** @type {string | undefined} */ (/** @type {any} */ (preflight).output),
|
|
79
100
|
};
|
|
80
101
|
}
|
|
81
102
|
}
|
|
@@ -83,13 +104,14 @@ export async function startBatch({
|
|
|
83
104
|
assertNoActiveBatch(projectRoot);
|
|
84
105
|
|
|
85
106
|
const configResult = loadSpineConfig(projectRoot);
|
|
107
|
+
/** @type {Record<string, any>} */
|
|
86
108
|
const config = configResult.config ?? {};
|
|
87
109
|
const tasksRoot = resolveTasksRoot(projectRoot, configResult);
|
|
88
110
|
if (!tasksRoot) {
|
|
89
111
|
return { ok: false, exitCode: 1, error: "tasks_root_missing" };
|
|
90
112
|
}
|
|
91
113
|
|
|
92
|
-
const scopeResolution = resolveBatchStartScope(scope, tasksRoot);
|
|
114
|
+
const scopeResolution = resolveBatchStartScope(scope, tasksRoot, { forceSuperseded });
|
|
93
115
|
if (!scopeResolution.ok) {
|
|
94
116
|
return {
|
|
95
117
|
ok: false,
|
|
@@ -99,11 +121,26 @@ export async function startBatch({
|
|
|
99
121
|
};
|
|
100
122
|
}
|
|
101
123
|
|
|
102
|
-
const effectiveScope = scopeResolution.scope;
|
|
124
|
+
const effectiveScope = /** @type {string} */ (scopeResolution.scope);
|
|
103
125
|
const policyScope = scopeResolution.policyScope ?? effectiveScope;
|
|
104
126
|
|
|
105
|
-
const plan = buildPlan({ scope: effectiveScope, config, tasksRoot });
|
|
106
|
-
|
|
127
|
+
const plan = buildPlan({ scope: effectiveScope, config, tasksRoot: /** @type {string} */ (tasksRoot) });
|
|
128
|
+
let effectivePlan = plan;
|
|
129
|
+
let plannerWaveCount = plan.waves?.length ?? 0;
|
|
130
|
+
if (waveFilter != null) {
|
|
131
|
+
const filtered = filterPlanToWave(plan, waveFilter);
|
|
132
|
+
if (filtered.ok !== true) {
|
|
133
|
+
return {
|
|
134
|
+
ok: false,
|
|
135
|
+
exitCode: 1,
|
|
136
|
+
error: filtered.error,
|
|
137
|
+
output: `${filtered.output}\n`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
effectivePlan = /** @type {typeof plan} */ (filtered.plan);
|
|
141
|
+
plannerWaveCount = filtered.waveCount;
|
|
142
|
+
}
|
|
143
|
+
const batchPolicy = canStartMultiTaskBatch(effectivePlan, policyScope ?? effectiveScope);
|
|
107
144
|
if (!batchPolicy.ok) {
|
|
108
145
|
return {
|
|
109
146
|
ok: false,
|
|
@@ -114,17 +151,20 @@ export async function startBatch({
|
|
|
114
151
|
}
|
|
115
152
|
|
|
116
153
|
const taskIds = batchPolicy.taskIds;
|
|
117
|
-
const maxLaneNumber = maxLaneNumberForPlan(
|
|
154
|
+
const maxLaneNumber = maxLaneNumberForPlan(effectivePlan);
|
|
118
155
|
|
|
119
156
|
if (dryRun) {
|
|
157
|
+
const waveHint =
|
|
158
|
+
waveFilter != null ? ` (planner wave ${waveFilter} of ${plannerWaveCount})` : "";
|
|
120
159
|
return {
|
|
121
160
|
ok: true,
|
|
122
161
|
exitCode: 0,
|
|
123
162
|
dryRun: true,
|
|
124
163
|
taskIds,
|
|
125
|
-
plan,
|
|
164
|
+
plan: effectivePlan,
|
|
165
|
+
waveFilter,
|
|
126
166
|
output:
|
|
127
|
-
`Dry run: would start batch for ${taskIds.length} task(s) across ${
|
|
167
|
+
`Dry run: would start batch for ${taskIds.length} task(s) across ${effectivePlan.waves.length} wave(s)${waveHint}, ` +
|
|
128
168
|
`up to ${maxLaneNumber} lane(s), maxParallel=${config.lanes?.maxParallel ?? 1}.\n`,
|
|
129
169
|
};
|
|
130
170
|
}
|
|
@@ -141,29 +181,31 @@ export async function startBatch({
|
|
|
141
181
|
}
|
|
142
182
|
|
|
143
183
|
const { tasks, lanes } = buildTasksAndLanesFromPlan({
|
|
144
|
-
plan,
|
|
184
|
+
plan: effectivePlan,
|
|
145
185
|
discovered,
|
|
146
186
|
projectRoot,
|
|
147
187
|
batchId,
|
|
148
188
|
maxLaneNumber,
|
|
149
189
|
});
|
|
150
190
|
|
|
191
|
+
/** @type {ReturnType<typeof createInitialBatchState>} */
|
|
151
192
|
let state = createInitialBatchState({
|
|
152
193
|
batchId,
|
|
153
194
|
baseBranch,
|
|
154
195
|
orchBranch,
|
|
155
|
-
wavePlan:
|
|
196
|
+
wavePlan: effectivePlan.waves.map((/** @type {{ taskIds: string[] }} */ wave) => wave.taskIds),
|
|
156
197
|
tasks,
|
|
157
198
|
lanes,
|
|
158
199
|
});
|
|
159
200
|
|
|
160
|
-
|
|
201
|
+
saveEngineBatchState(projectRoot, state);
|
|
161
202
|
|
|
162
203
|
try {
|
|
163
204
|
ensureOrchBranch(projectRoot, baseBranch, orchBranch);
|
|
164
205
|
transitionPhase(state, "running", { projectRoot, batchId });
|
|
165
206
|
recordBatchEnginePid(state, process.pid);
|
|
166
|
-
|
|
207
|
+
installAttachedEngineShutdownHandlers({ projectRoot });
|
|
208
|
+
saveEngineBatchState(projectRoot, state);
|
|
167
209
|
|
|
168
210
|
for (const lane of state.lanes) {
|
|
169
211
|
lane.correlationId = crypto.randomUUID();
|
|
@@ -220,15 +262,24 @@ export async function startBatch({
|
|
|
220
262
|
correlationId: lane.correlationId,
|
|
221
263
|
});
|
|
222
264
|
}
|
|
223
|
-
|
|
265
|
+
saveEngineBatchState(projectRoot, state);
|
|
224
266
|
|
|
225
267
|
let batchAborted = false;
|
|
226
268
|
|
|
227
|
-
for (const wave of
|
|
269
|
+
for (const wave of effectivePlan.waves) {
|
|
270
|
+
const pauseAtWave = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
271
|
+
if (pauseAtWave.stop) {
|
|
272
|
+
return buildEnginePausedResult(batchId);
|
|
273
|
+
}
|
|
274
|
+
|
|
228
275
|
state.currentWaveIndex = wave.index;
|
|
229
|
-
|
|
276
|
+
saveEngineBatchState(projectRoot, state);
|
|
230
277
|
|
|
231
278
|
for (const tick of wave.ticks ?? []) {
|
|
279
|
+
const pauseAtTick = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
280
|
+
if (pauseAtTick.stop) {
|
|
281
|
+
return buildEnginePausedResult(batchId);
|
|
282
|
+
}
|
|
232
283
|
/** @type {Map<number, { lane: object, runs: Array<{ taskId: string, run: () => Promise<{ ok: boolean, aborted?: boolean }> }> }>} */
|
|
233
284
|
const runsByLane = new Map();
|
|
234
285
|
|
|
@@ -237,7 +288,7 @@ export async function startBatch({
|
|
|
237
288
|
if (tickTaskIds.length === 0) continue;
|
|
238
289
|
|
|
239
290
|
const laneNumber = laneInTick + 1;
|
|
240
|
-
const lane = state.lanes.find((entry) => entry.laneNumber === laneNumber);
|
|
291
|
+
const lane = state.lanes.find((/** @type {{ laneNumber: number }} */ entry) => entry.laneNumber === laneNumber);
|
|
241
292
|
if (!lane) continue;
|
|
242
293
|
|
|
243
294
|
if (!runsByLane.has(laneNumber)) {
|
|
@@ -246,8 +297,8 @@ export async function startBatch({
|
|
|
246
297
|
const laneQueue = runsByLane.get(laneNumber);
|
|
247
298
|
|
|
248
299
|
for (const taskId of tickTaskIds) {
|
|
249
|
-
const task = state.tasks.find((entry) => entry.taskId === taskId);
|
|
250
|
-
const entry = discovered.find((item) => item.taskId === taskId);
|
|
300
|
+
const task = state.tasks.find((/** @type {{ taskId: string }} */ entry) => entry.taskId === taskId);
|
|
301
|
+
const entry = discovered.find((/** @type {{ taskId: string }} */ item) => item.taskId === taskId);
|
|
251
302
|
if (!task || !entry) continue;
|
|
252
303
|
|
|
253
304
|
const taskFolderRel = path.relative(projectRoot, entry.folderPath);
|
|
@@ -277,23 +328,26 @@ export async function startBatch({
|
|
|
277
328
|
taskFolderRel,
|
|
278
329
|
laneCorrelationId,
|
|
279
330
|
}).then((result) => {
|
|
280
|
-
if (result.aborted) batchAborted = true;
|
|
331
|
+
if ("aborted" in result && result.aborted) batchAborted = true;
|
|
281
332
|
return result;
|
|
282
333
|
});
|
|
283
334
|
|
|
284
|
-
laneQueue
|
|
335
|
+
if (laneQueue) {
|
|
336
|
+
laneQueue.runs.push({ taskId, run });
|
|
337
|
+
}
|
|
285
338
|
}
|
|
286
339
|
}
|
|
287
340
|
|
|
288
341
|
const laneExecutions = [...runsByLane.entries()].map(async ([laneNumber, { lane, runs }]) => {
|
|
342
|
+
const laneMeta = /** @type {{ laneId?: string; correlationId?: string }} */ (lane);
|
|
289
343
|
if (runs.length > 1) {
|
|
290
344
|
appendJournalEvent(projectRoot, batchId, "lane.tasks_serialized", {
|
|
291
345
|
laneNumber,
|
|
292
|
-
laneId:
|
|
346
|
+
laneId: laneMeta.laneId,
|
|
293
347
|
waveIndex: wave.index,
|
|
294
348
|
tickIndex: tick.index,
|
|
295
349
|
taskIds: runs.map((entry) => entry.taskId),
|
|
296
|
-
correlationId:
|
|
350
|
+
correlationId: laneMeta.correlationId ?? null,
|
|
297
351
|
});
|
|
298
352
|
}
|
|
299
353
|
|
|
@@ -308,18 +362,23 @@ export async function startBatch({
|
|
|
308
362
|
|
|
309
363
|
await Promise.all(laneExecutions);
|
|
310
364
|
if (batchAborted) break;
|
|
365
|
+
|
|
366
|
+
const pauseAfterTick = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
367
|
+
if (pauseAfterTick.stop) {
|
|
368
|
+
return buildEnginePausedResult(batchId);
|
|
369
|
+
}
|
|
311
370
|
}
|
|
312
371
|
|
|
313
372
|
if (batchAborted) {
|
|
314
|
-
const abortedTask = state.tasks.find((task) => task.status === "aborted");
|
|
315
|
-
state.endedAt = Date.now();
|
|
316
|
-
state.lastError = "batch aborted";
|
|
373
|
+
const abortedTask = state.tasks.find((/** @type {{ status: string }} */ task) => task.status === "aborted");
|
|
374
|
+
/** @type {any} */ (state).endedAt = Date.now();
|
|
375
|
+
/** @type {any} */ (state).lastError = "batch aborted";
|
|
317
376
|
transitionPhase(state, "aborted", {
|
|
318
377
|
projectRoot,
|
|
319
378
|
batchId,
|
|
320
379
|
extra: { taskId: abortedTask?.taskId },
|
|
321
380
|
});
|
|
322
|
-
|
|
381
|
+
saveEngineBatchState(projectRoot, state);
|
|
323
382
|
return {
|
|
324
383
|
ok: false,
|
|
325
384
|
exitCode: 1,
|
|
@@ -331,8 +390,8 @@ export async function startBatch({
|
|
|
331
390
|
|
|
332
391
|
const mergeEligibility = assessWaveMergeEligibility(state, wave.index);
|
|
333
392
|
if (!mergeEligibility.ok) {
|
|
334
|
-
state.endedAt = Date.now();
|
|
335
|
-
state.lastError = mergeEligibility.message?.slice(0, 500) ?? "mixed_outcome";
|
|
393
|
+
/** @type {any} */ (state).endedAt = Date.now();
|
|
394
|
+
/** @type {any} */ (state).lastError = mergeEligibility.message?.slice(0, 500) ?? "mixed_outcome";
|
|
336
395
|
transitionPhase(state, "failed", {
|
|
337
396
|
projectRoot,
|
|
338
397
|
batchId,
|
|
@@ -343,7 +402,7 @@ export async function startBatch({
|
|
|
343
402
|
reason: "mixed_outcome",
|
|
344
403
|
},
|
|
345
404
|
});
|
|
346
|
-
|
|
405
|
+
saveEngineBatchState(projectRoot, state);
|
|
347
406
|
appendJournalEvent(projectRoot, batchId, "batch.merge_blocked", {
|
|
348
407
|
waveIndex: wave.index,
|
|
349
408
|
failedTaskIds: mergeEligibility.failedTaskIds,
|
|
@@ -368,14 +427,6 @@ export async function startBatch({
|
|
|
368
427
|
waveIndex: wave.index,
|
|
369
428
|
});
|
|
370
429
|
if (!mergeResult.ok) {
|
|
371
|
-
state.endedAt = Date.now();
|
|
372
|
-
state.lastError = mergeResult.error ?? "merge failed";
|
|
373
|
-
transitionPhase(state, "failed", {
|
|
374
|
-
projectRoot,
|
|
375
|
-
batchId,
|
|
376
|
-
extra: { reason: "merge", waveIndex: wave.index },
|
|
377
|
-
});
|
|
378
|
-
saveSpineBatchState(projectRoot, state);
|
|
379
430
|
return {
|
|
380
431
|
ok: false,
|
|
381
432
|
exitCode: 1,
|
|
@@ -385,6 +436,10 @@ export async function startBatch({
|
|
|
385
436
|
};
|
|
386
437
|
}
|
|
387
438
|
|
|
439
|
+
if (mergeResult.finalized && mergeResult.finalizeResult) {
|
|
440
|
+
return mergeResult.finalizeResult;
|
|
441
|
+
}
|
|
442
|
+
|
|
388
443
|
if (
|
|
389
444
|
shouldAutoIntegrateAfterWave({
|
|
390
445
|
config,
|
|
@@ -401,43 +456,35 @@ export async function startBatch({
|
|
|
401
456
|
}
|
|
402
457
|
}
|
|
403
458
|
|
|
404
|
-
state
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
saveSpineBatchState(projectRoot, state);
|
|
459
|
+
if (detectPostMergeLimboForResume({ projectRoot, state })) {
|
|
460
|
+
const limboResult = tryFinalizePostMergeLimbo({
|
|
461
|
+
projectRoot,
|
|
462
|
+
state,
|
|
463
|
+
batchId,
|
|
464
|
+
orchBranch,
|
|
465
|
+
});
|
|
466
|
+
if (limboResult) {
|
|
467
|
+
return limboResult;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
416
470
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
ok: true,
|
|
421
|
-
exitCode: 0,
|
|
471
|
+
return finalizeBatchForIntegrate({
|
|
472
|
+
projectRoot,
|
|
473
|
+
state,
|
|
422
474
|
batchId,
|
|
423
|
-
taskId: taskIds.length === 1 ? taskIds[0] : undefined,
|
|
424
|
-
taskIds,
|
|
425
475
|
orchBranch,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
`Batch ${batchId} completed: ${summaryTask} succeeded; merged to ${orchBranch}.\n` +
|
|
429
|
-
` → spine gate status\n → spine gate approve\n → spine integrate\n → spine batch complete\n`,
|
|
430
|
-
};
|
|
476
|
+
resumed: false,
|
|
477
|
+
});
|
|
431
478
|
} catch (err) {
|
|
432
479
|
const message = err instanceof Error ? err.message : String(err);
|
|
433
|
-
state.endedAt = Date.now();
|
|
434
|
-
state.lastError = message;
|
|
480
|
+
/** @type {any} */ (state).endedAt = Date.now();
|
|
481
|
+
/** @type {any} */ (state).lastError = message;
|
|
435
482
|
transitionPhase(state, "failed", {
|
|
436
483
|
projectRoot,
|
|
437
484
|
batchId,
|
|
438
485
|
extra: { error: message },
|
|
439
486
|
});
|
|
440
|
-
|
|
487
|
+
saveEngineBatchState(projectRoot, state);
|
|
441
488
|
removeLaneWorktrees(projectRoot, batchId, maxLaneNumber);
|
|
442
489
|
return { ok: false, exitCode: 1, batchId, error: message };
|
|
443
490
|
}
|
package/src/batch/evidence.mjs
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
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";
|
|
11
12
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
13
|
+
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
12
14
|
|
|
13
15
|
const TASKPLANE_CONFIG_PATH = ".pi/taskplane-config.json";
|
|
14
16
|
|
|
@@ -36,7 +38,7 @@ function readTaskplaneTestingCommands(projectRoot) {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
|
-
* @param {
|
|
41
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} config
|
|
40
42
|
* @param {string} projectRoot
|
|
41
43
|
*/
|
|
42
44
|
export function resolveTestingCommands(config, projectRoot) {
|
|
@@ -116,14 +118,30 @@ export function buildTaskScorecard(batchState) {
|
|
|
116
118
|
return `${lines.join("\n")}\n`;
|
|
117
119
|
}
|
|
118
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
|
+
|
|
119
137
|
/**
|
|
120
138
|
* @param {object} ctx
|
|
121
139
|
* @param {string} ctx.projectRoot
|
|
122
140
|
* @param {string} ctx.batchId
|
|
123
141
|
* @param {object|null} [ctx.batchState]
|
|
124
|
-
* @param {
|
|
142
|
+
* @param {ReturnType<typeof loadSpineConfig>["config"]} [ctx.config]
|
|
125
143
|
*/
|
|
126
|
-
export function
|
|
144
|
+
export function collectCoreEvidenceBundle(ctx) {
|
|
127
145
|
const { projectRoot, batchId, batchState = null, config = null } = ctx;
|
|
128
146
|
const dir = evidenceDir(projectRoot, batchId);
|
|
129
147
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -134,17 +152,46 @@ export function collectEvidenceBundle(ctx) {
|
|
|
134
152
|
const reconciliation = reconcileBatch({ projectRoot, batchState, verbose: true });
|
|
135
153
|
const journalTail = readJournalTail(readJournalEvents(projectRoot, batchId));
|
|
136
154
|
const summary = generateBatchPostMortem(batchState, journalTail, reconciliation, projectRoot);
|
|
137
|
-
|
|
155
|
+
writeTextAtomic(path.join(dir, "summary.md"), summary);
|
|
138
156
|
evidenceRefs.push("evidence/summary.md");
|
|
139
157
|
|
|
140
158
|
const baseBranch = batchState?.baseBranch ?? config?.baseBranch ?? "main";
|
|
141
159
|
const orchBranch = batchState?.orchBranch ?? null;
|
|
142
160
|
if (orchBranch) {
|
|
143
161
|
const diffStat = collectDiffStat(projectRoot, baseBranch, orchBranch);
|
|
144
|
-
|
|
162
|
+
writeTextAtomic(path.join(dir, "diff-stat.txt"), `${diffStat}\n`);
|
|
145
163
|
evidenceRefs.push("evidence/diff-stat.txt");
|
|
146
164
|
}
|
|
147
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
|
+
|
|
148
195
|
const gates = config?.gates ?? {};
|
|
149
196
|
const testing = resolveTestingCommands(config, projectRoot);
|
|
150
197
|
const collectTest = gates.collectTestEvidence !== false;
|
|
@@ -152,33 +199,50 @@ export function collectEvidenceBundle(ctx) {
|
|
|
152
199
|
|
|
153
200
|
if (collectTest && testing.test) {
|
|
154
201
|
const result = runEvidenceCommand(projectRoot, testing.test);
|
|
155
|
-
|
|
202
|
+
writeTextAtomic(path.join(dir, "test-output.txt"), `${result.output}\n`);
|
|
156
203
|
evidenceRefs.push("evidence/test-output.txt");
|
|
157
204
|
}
|
|
158
205
|
|
|
159
206
|
if (collectBuild && testing.build) {
|
|
160
207
|
const result = runEvidenceCommand(projectRoot, testing.build);
|
|
161
|
-
|
|
208
|
+
writeTextAtomic(path.join(dir, "build-output.txt"), `${result.output}\n`);
|
|
162
209
|
evidenceRefs.push("evidence/build-output.txt");
|
|
163
210
|
}
|
|
164
211
|
|
|
165
212
|
if (testing.testWithCoverage) {
|
|
166
213
|
const result = runEvidenceCommand(projectRoot, testing.testWithCoverage);
|
|
167
|
-
|
|
214
|
+
writeTextAtomic(path.join(dir, "coverage-output.txt"), `${result.output}\n`);
|
|
168
215
|
evidenceRefs.push("evidence/coverage-output.txt");
|
|
169
216
|
}
|
|
170
217
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
218
|
+
return { evidenceDir: dir, evidenceRefs };
|
|
219
|
+
}
|
|
174
220
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
+
}
|
|
180
233
|
|
|
181
|
-
|
|
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 };
|
|
182
246
|
}
|
|
183
247
|
|
|
184
248
|
/**
|