pi-spine 1.1.0 → 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/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/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-run.mjs +30 -0
- package/bin/spine-status.mjs +19 -1
- package/bin/spine-tasks.mjs +16 -2
- package/bin/spine-worker-runner.mjs +10 -10
- package/bin/spine.mjs +49 -1
- package/package.json +1 -1
- package/skills/create-spine-tasks/references/contract-template.md +19 -0
- 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 +312 -0
- package/src/batch/contract-prelanded.mjs +180 -0
- package/src/batch/contract-verify.mjs +140 -2
- package/src/batch/detached-start.mjs +66 -2
- 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 +135 -68
- package/src/batch/engine-lanes/merge.mjs +110 -82
- package/src/batch/engine-lanes/queue.mjs +4 -1
- package/src/batch/engine-lanes/watch.mjs +29 -0
- package/src/batch/engine-lanes.mjs +1 -0
- package/src/batch/engine-scope.mjs +11 -1
- package/src/batch/engine.mjs +79 -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 +73 -7
- package/src/batch/integrate.mjs +2 -4
- package/src/batch/journal.mjs +3 -0
- package/src/batch/lane-commit.mjs +90 -5
- package/src/batch/lifecycle.mjs +130 -3
- package/src/batch/macro-phase.mjs +226 -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 +74 -5
- package/src/batch/orphan-detect.mjs +74 -0
- package/src/batch/pause.mjs +223 -0
- package/src/batch/post-merge-limbo.mjs +264 -8
- package/src/batch/reconcile.mjs +429 -54
- package/src/batch/resume-common.mjs +5 -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 +67 -6
- package/src/batch/resume-multi.mjs +9 -4
- package/src/batch/resume.mjs +52 -45
- package/src/batch/retry.mjs +56 -5
- package/src/batch/review-spawn.mjs +8 -2
- 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 +22 -10
- package/src/batch/worker-host.mjs +95 -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 +108 -0
- package/src/cli/settings-set.mjs +2 -21
- 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-init-constants.mjs +1 -0
- package/src/config/spine-preflight-lib.mjs +471 -16
- package/src/dashboard/lane-throughput.mjs +351 -0
- package/src/dashboard/public/dashboard.css +25 -1
- package/src/dashboard/public/dashboard.js +223 -18
- package/src/dashboard/public/index.html +14 -2
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +215 -1
- package/src/dashboard/view.mjs +170 -17
- package/src/doctor/agent-model-inherit.mjs +61 -6
- package/src/doctor/run-doctor-checks.mjs +26 -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/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 +42 -1
- package/src/tasks/packet/validate-prompt.mjs +124 -0
- package/templates/spine-config.json +8 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { execFileSync } from "node:child_process";
|
|
6
|
+
import { gitAddFilteredPaths, filterGitignoredPaths, isGitignoredAddError } from "../git-helpers.mjs";
|
|
6
7
|
import { gitExec } from "../git-exec.mjs";
|
|
7
8
|
import {
|
|
8
9
|
parseRulesManifestJson,
|
|
@@ -12,13 +13,18 @@ import {
|
|
|
12
13
|
loadRulesManifest,
|
|
13
14
|
fingerprintRulesManifest,
|
|
14
15
|
} from "../../config/cursor-rules/discover.mjs";
|
|
16
|
+
import { resolveRulesManifestIntegrateDrift } from "../rules-manifest-drift.mjs";
|
|
15
17
|
import { matchesContractPattern } from "../contract-verify.mjs";
|
|
16
18
|
import {
|
|
17
19
|
formatAdoptionDocMergeFailure,
|
|
20
|
+
formatPrdDocMergeFailure,
|
|
18
21
|
isAdoptionDocPath,
|
|
22
|
+
isPrdDocPath,
|
|
19
23
|
tryResolveAdoptionDocMergeConflict,
|
|
24
|
+
tryResolvePrdDocMergeConflict,
|
|
20
25
|
} from "../merge/adoption-doc-merge.mjs";
|
|
21
26
|
import { recordWaveMergeResult } from "../merge/wave-merge-state.mjs";
|
|
27
|
+
import { recordMergeBlocked } from "../lifecycle.mjs";
|
|
22
28
|
import { appendJournalEvent } from "../journal.mjs";
|
|
23
29
|
import { countCommitsAhead, gitPorcelain } from "../lane-commit.mjs";
|
|
24
30
|
import { maybeFinalizeAfterWaveMerge } from "../post-merge-limbo.mjs";
|
|
@@ -101,72 +107,7 @@ function listDirtyPaths(projectRoot) {
|
|
|
101
107
|
.filter((entry) => Boolean(entry));
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
* Before orch→main integrate, auto-resolve uncommitted generatedAt-only drift on rules-manifest.
|
|
106
|
-
*
|
|
107
|
-
* @param {object} params
|
|
108
|
-
* @param {string} params.projectRoot
|
|
109
|
-
* @param {string} params.baseBranch
|
|
110
|
-
* @param {string} params.orchBranch
|
|
111
|
-
*/
|
|
112
|
-
export function resolveRulesManifestIntegrateDrift({ projectRoot, baseBranch, orchBranch }) {
|
|
113
|
-
const dirtyPaths = listDirtyPaths(projectRoot);
|
|
114
|
-
if (dirtyPaths.length === 0) {
|
|
115
|
-
return { ok: true, resolved: false };
|
|
116
|
-
}
|
|
117
|
-
if (dirtyPaths.length !== 1 || dirtyPaths[0] !== RULES_MANIFEST_REL_PATH) {
|
|
118
|
-
return { ok: true, resolved: false };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const working = loadRulesManifest(projectRoot);
|
|
122
|
-
if (!working) {
|
|
123
|
-
return {
|
|
124
|
-
ok: false,
|
|
125
|
-
failureClass: "DirtyWorktree",
|
|
126
|
-
error: `${RULES_MANIFEST_REL_PATH} is dirty but unreadable`,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const headResult = readRulesManifestFromRef(projectRoot, baseBranch);
|
|
131
|
-
const orchResult = readRulesManifestFromRef(projectRoot, orchBranch);
|
|
132
|
-
if (!headResult.ok || !orchResult.ok) {
|
|
133
|
-
return {
|
|
134
|
-
ok: false,
|
|
135
|
-
failureClass: "DirtyWorktree",
|
|
136
|
-
error: "unable to read rules-manifest from base or orch branch",
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (fingerprintRulesManifest(working) !== fingerprintRulesManifest(headResult.manifest)) {
|
|
141
|
-
return {
|
|
142
|
-
ok: false,
|
|
143
|
-
failureClass: "DirtyWorktree",
|
|
144
|
-
error:
|
|
145
|
-
`${RULES_MANIFEST_REL_PATH} has uncommitted content changes beyond generatedAt — commit or stash before integrate`,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (fingerprintRulesManifest(headResult.manifest) !== fingerprintRulesManifest(orchResult.manifest)) {
|
|
150
|
-
const contentMerge = resolveRulesManifestGeneratedAtMerge({
|
|
151
|
-
ours: headResult.manifest,
|
|
152
|
-
theirs: orchResult.manifest,
|
|
153
|
-
});
|
|
154
|
-
if (!contentMerge.ok) {
|
|
155
|
-
return contentMerge;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
gitExec(
|
|
160
|
-
projectRoot,
|
|
161
|
-
["restore", "--source=HEAD", "--staged", "--worktree", RULES_MANIFEST_REL_PATH],
|
|
162
|
-
{ projectRoot },
|
|
163
|
-
);
|
|
164
|
-
return {
|
|
165
|
-
ok: true,
|
|
166
|
-
resolved: true,
|
|
167
|
-
action: "restored_head_for_merge",
|
|
168
|
-
};
|
|
169
|
-
}
|
|
110
|
+
export { resolveRulesManifestIntegrateDrift } from "../rules-manifest-drift.mjs";
|
|
170
111
|
|
|
171
112
|
/**
|
|
172
113
|
* @param {string} projectRoot
|
|
@@ -234,7 +175,7 @@ function resolveRulesManifestMergeConflict(projectRoot) {
|
|
|
234
175
|
}
|
|
235
176
|
|
|
236
177
|
writeRulesManifestAtomic(projectRoot, resolved.manifest);
|
|
237
|
-
|
|
178
|
+
gitAddFilteredPaths(projectRoot, [RULES_MANIFEST_REL_PATH], { projectRoot });
|
|
238
179
|
return {
|
|
239
180
|
ok: true,
|
|
240
181
|
autoResolved: true,
|
|
@@ -262,8 +203,20 @@ function tryAutoResolveOutOfScopeMergeConflict({
|
|
|
262
203
|
}
|
|
263
204
|
|
|
264
205
|
gitExec(projectRoot, ["checkout", "--ours", "--", filePath], { projectRoot });
|
|
265
|
-
|
|
266
|
-
|
|
206
|
+
const { stageable, skipped } = filterGitignoredPaths(projectRoot, [filePath]);
|
|
207
|
+
if (stageable.length > 0) {
|
|
208
|
+
gitAddFilteredPaths(projectRoot, stageable, { projectRoot });
|
|
209
|
+
} else if (skipped.includes(filePath)) {
|
|
210
|
+
gitExec(projectRoot, ["rm", "--cached", "-f", "--", filePath], {
|
|
211
|
+
projectRoot,
|
|
212
|
+
throwOnError: false,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
ok: true,
|
|
217
|
+
strategy: "prefer_orch_out_of_scope",
|
|
218
|
+
skippedGitignoredPaths: skipped,
|
|
219
|
+
};
|
|
267
220
|
}
|
|
268
221
|
|
|
269
222
|
/**
|
|
@@ -333,9 +286,11 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
333
286
|
const resolvedOutOfScope = [];
|
|
334
287
|
/** @type {string[]} */
|
|
335
288
|
const remaining = [];
|
|
289
|
+
/** @type {string[]} */
|
|
290
|
+
const skippedGitignoredPaths = [];
|
|
336
291
|
|
|
337
292
|
/** @type {string[]} */
|
|
338
|
-
const
|
|
293
|
+
const resolvedAutoMergeDocs = [];
|
|
339
294
|
|
|
340
295
|
for (const filePath of unmerged) {
|
|
341
296
|
if (filePath === RULES_MANIFEST_REL_PATH) {
|
|
@@ -349,7 +304,20 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
349
304
|
waveIndex,
|
|
350
305
|
});
|
|
351
306
|
if (adoptionResult.ok) {
|
|
352
|
-
|
|
307
|
+
resolvedAutoMergeDocs.push(filePath);
|
|
308
|
+
} else {
|
|
309
|
+
remaining.push(filePath);
|
|
310
|
+
}
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (isPrdDocPath(filePath)) {
|
|
314
|
+
const prdResult = tryResolvePrdDocMergeConflict({
|
|
315
|
+
projectRoot,
|
|
316
|
+
filePath,
|
|
317
|
+
waveIndex,
|
|
318
|
+
});
|
|
319
|
+
if (prdResult.ok) {
|
|
320
|
+
resolvedAutoMergeDocs.push(filePath);
|
|
353
321
|
} else {
|
|
354
322
|
remaining.push(filePath);
|
|
355
323
|
}
|
|
@@ -367,6 +335,9 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
367
335
|
});
|
|
368
336
|
if (resolved.ok) {
|
|
369
337
|
resolvedOutOfScope.push(filePath);
|
|
338
|
+
if (Array.isArray(resolved.skippedGitignoredPaths) && resolved.skippedGitignoredPaths.length > 0) {
|
|
339
|
+
skippedGitignoredPaths.push(...resolved.skippedGitignoredPaths);
|
|
340
|
+
}
|
|
370
341
|
} else {
|
|
371
342
|
remaining.push(filePath);
|
|
372
343
|
}
|
|
@@ -381,6 +352,7 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
381
352
|
return {
|
|
382
353
|
...manifestResult,
|
|
383
354
|
outOfScopePaths: resolvedOutOfScope,
|
|
355
|
+
skippedGitignoredPaths,
|
|
384
356
|
};
|
|
385
357
|
}
|
|
386
358
|
remaining.length = 0;
|
|
@@ -396,6 +368,7 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
396
368
|
return {
|
|
397
369
|
...manifestResult,
|
|
398
370
|
outOfScopePaths: resolvedOutOfScope,
|
|
371
|
+
skippedGitignoredPaths,
|
|
399
372
|
};
|
|
400
373
|
}
|
|
401
374
|
|
|
@@ -404,19 +377,25 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
404
377
|
ok: true,
|
|
405
378
|
autoResolved: true,
|
|
406
379
|
outOfScopePaths: resolvedOutOfScope,
|
|
407
|
-
adoptionDocPaths:
|
|
380
|
+
adoptionDocPaths: resolvedAutoMergeDocs,
|
|
381
|
+
skippedGitignoredPaths,
|
|
408
382
|
};
|
|
409
383
|
}
|
|
410
384
|
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
385
|
+
const autoMergeRemaining = remaining.filter(
|
|
386
|
+
(filePath) => isAdoptionDocPath(filePath) || isPrdDocPath(filePath),
|
|
387
|
+
);
|
|
388
|
+
if (autoMergeRemaining.length > 0) {
|
|
389
|
+
const firstAutoMerge = autoMergeRemaining[0];
|
|
390
|
+
const error = isPrdDocPath(firstAutoMerge)
|
|
391
|
+
? formatPrdDocMergeFailure({ filePath: firstAutoMerge, waveIndex })
|
|
392
|
+
: formatAdoptionDocMergeFailure({ filePath: firstAutoMerge, waveIndex });
|
|
414
393
|
return {
|
|
415
394
|
ok: false,
|
|
416
395
|
failureClass: "MergeConflict",
|
|
417
|
-
error
|
|
396
|
+
error,
|
|
418
397
|
outOfScopePaths: resolvedOutOfScope,
|
|
419
|
-
adoptionDocPaths:
|
|
398
|
+
adoptionDocPaths: resolvedAutoMergeDocs,
|
|
420
399
|
};
|
|
421
400
|
}
|
|
422
401
|
|
|
@@ -425,9 +404,10 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
|
|
|
425
404
|
failureClass: "MergeConflict",
|
|
426
405
|
error:
|
|
427
406
|
`merge conflict on ${remaining.join(", ")}; automatic resolution supports docs/adoption/*, ` +
|
|
428
|
-
|
|
407
|
+
`docs/PRD.md, ${RULES_MANIFEST_REL_PATH}, and out-of-scope dependency drift ` +
|
|
408
|
+
"(prefer orch when the lane did not commit the path)",
|
|
429
409
|
outOfScopePaths: resolvedOutOfScope,
|
|
430
|
-
adoptionDocPaths:
|
|
410
|
+
adoptionDocPaths: resolvedAutoMergeDocs,
|
|
431
411
|
};
|
|
432
412
|
}
|
|
433
413
|
|
|
@@ -559,6 +539,15 @@ export function mergeLaneToOrch({
|
|
|
559
539
|
outOfScopePaths: autoResolved.outOfScopePaths ?? [],
|
|
560
540
|
};
|
|
561
541
|
}
|
|
542
|
+
if (
|
|
543
|
+
Array.isArray(autoResolved.skippedGitignoredPaths) &&
|
|
544
|
+
autoResolved.skippedGitignoredPaths.length > 0
|
|
545
|
+
) {
|
|
546
|
+
appendJournalEvent(projectRoot, batchId, "batch.merge_gitignored_skipped", {
|
|
547
|
+
taskBranch,
|
|
548
|
+
skippedPaths: autoResolved.skippedGitignoredPaths,
|
|
549
|
+
});
|
|
550
|
+
}
|
|
562
551
|
gitStrict(projectRoot, ["commit", "--no-edit"]);
|
|
563
552
|
}
|
|
564
553
|
|
|
@@ -579,6 +568,13 @@ export function mergeLaneToOrch({
|
|
|
579
568
|
if (mergeInProgress) {
|
|
580
569
|
abortInProgressMerge(projectRoot);
|
|
581
570
|
}
|
|
571
|
+
if (isGitignoredAddError(err)) {
|
|
572
|
+
return {
|
|
573
|
+
ok: false,
|
|
574
|
+
failureClass: "merge_failed_gitignored",
|
|
575
|
+
error: err instanceof Error ? err.message : String(err),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
582
578
|
return {
|
|
583
579
|
ok: false,
|
|
584
580
|
error: err instanceof Error ? err.message : String(err),
|
|
@@ -651,15 +647,47 @@ export async function mergeWaveLanesToOrch({
|
|
|
651
647
|
waveIndex,
|
|
652
648
|
});
|
|
653
649
|
if (!merge.ok) {
|
|
650
|
+
const failureReason = merge.error ?? "merge_failed";
|
|
654
651
|
recordWaveMergeResult({
|
|
655
652
|
state,
|
|
656
653
|
waveIndex,
|
|
657
654
|
status: "failed",
|
|
658
655
|
failedLane: laneNumber,
|
|
659
|
-
failureReason
|
|
656
|
+
failureReason,
|
|
657
|
+
failureClass: merge.failureClass ?? null,
|
|
658
|
+
});
|
|
659
|
+
if (Array.isArray(merge.skippedGitignoredPaths) && merge.skippedGitignoredPaths.length > 0) {
|
|
660
|
+
appendJournalEvent(projectRoot, batchId, "batch.merge_gitignored_skipped", {
|
|
661
|
+
laneNumber,
|
|
662
|
+
waveIndex,
|
|
663
|
+
taskBranch,
|
|
664
|
+
skippedPaths: merge.skippedGitignoredPaths,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
if (merge.failureClass === "merge_failed_gitignored") {
|
|
668
|
+
appendJournalEvent(projectRoot, batchId, "batch.merge_failed", {
|
|
669
|
+
laneNumber,
|
|
670
|
+
waveIndex,
|
|
671
|
+
taskBranch,
|
|
672
|
+
failureClass: merge.failureClass,
|
|
673
|
+
error: failureReason,
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
recordMergeBlocked({
|
|
677
|
+
projectRoot,
|
|
678
|
+
state,
|
|
679
|
+
batchId,
|
|
680
|
+
error: failureReason,
|
|
681
|
+
waveIndex,
|
|
682
|
+
laneNumber,
|
|
683
|
+
failureClass: merge.failureClass ?? null,
|
|
660
684
|
});
|
|
661
|
-
|
|
662
|
-
|
|
685
|
+
return {
|
|
686
|
+
ok: false,
|
|
687
|
+
error: failureReason,
|
|
688
|
+
laneNumber,
|
|
689
|
+
failureClass: merge.failureClass ?? null,
|
|
690
|
+
};
|
|
663
691
|
}
|
|
664
692
|
lastMergeCommit = merge.mergeCommit;
|
|
665
693
|
appendJournalEvent(projectRoot, batchId, "batch.merge_completed", {
|
|
@@ -20,13 +20,14 @@ import { laneTaskBranch, laneWorktreePath } from "../worktree.mjs";
|
|
|
20
20
|
/**
|
|
21
21
|
* @param {object} params
|
|
22
22
|
*/
|
|
23
|
-
export function recordLaneTaskMetric({ projectRoot, batchId, task, config, taskFolder }) {
|
|
23
|
+
export function recordLaneTaskMetric({ projectRoot, batchId, task, config, taskFolder, lane }) {
|
|
24
24
|
recordTaskTerminalMetric({
|
|
25
25
|
projectRoot,
|
|
26
26
|
batchId,
|
|
27
27
|
task,
|
|
28
28
|
config,
|
|
29
29
|
taskFolder,
|
|
30
|
+
laneNumber: lane?.laneNumber ?? task?.laneNumber,
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -102,6 +103,7 @@ export function recordPromptParseFailure({
|
|
|
102
103
|
projectRoot,
|
|
103
104
|
batchId,
|
|
104
105
|
task,
|
|
106
|
+
lane,
|
|
105
107
|
config,
|
|
106
108
|
taskFolder: taskFolderPath,
|
|
107
109
|
});
|
|
@@ -201,6 +203,7 @@ export async function skipTaskDoneOnDisk({
|
|
|
201
203
|
projectRoot,
|
|
202
204
|
batchId,
|
|
203
205
|
task,
|
|
206
|
+
lane,
|
|
204
207
|
config,
|
|
205
208
|
taskFolder: taskFolderPath,
|
|
206
209
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lane worker watch helpers — stall anchor slides on worker_alive while running (SP-341 / #32).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** @typedef {"launching" | "pi" | "verify" | "unknown"} WorkerPhase */
|
|
6
|
+
/** @typedef {"worker_alive" | "checkpoint" | "file_scope_activity"} HeartbeatKind */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} params
|
|
10
|
+
* @param {WorkerPhase} params.workerPhase
|
|
11
|
+
* @param {HeartbeatKind} params.heartbeatKind
|
|
12
|
+
*/
|
|
13
|
+
export function shouldSlideStallAnchorOnHeartbeat({ workerPhase, heartbeatKind }) {
|
|
14
|
+
return workerPhase === "pi" && heartbeatKind === "worker_alive";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} params
|
|
19
|
+
* @param {number} params.stallAnchorAt
|
|
20
|
+
* @param {number} params.now
|
|
21
|
+
* @param {WorkerPhase} params.workerPhase
|
|
22
|
+
* @param {HeartbeatKind} params.heartbeatKind
|
|
23
|
+
*/
|
|
24
|
+
export function nextStallAnchorAt({ stallAnchorAt, now, workerPhase, heartbeatKind }) {
|
|
25
|
+
if (shouldSlideStallAnchorOnHeartbeat({ workerPhase, heartbeatKind })) {
|
|
26
|
+
return now;
|
|
27
|
+
}
|
|
28
|
+
return stallAnchorAt;
|
|
29
|
+
}
|
|
@@ -309,6 +309,7 @@ export async function runTaskOnLane({
|
|
|
309
309
|
classification: laneCommit.failureClass ?? "lane_commit_failed",
|
|
310
310
|
exitCode: 1,
|
|
311
311
|
output: laneCommit.error,
|
|
312
|
+
gitignoredPaths: laneCommit.gitignoredPaths ?? null,
|
|
312
313
|
});
|
|
313
314
|
recordLaneTaskMetric({
|
|
314
315
|
projectRoot,
|
|
@@ -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,
|
|
@@ -63,6 +79,7 @@ export { loadTaskFileScopePaths, mergeLaneToOrch } from "./engine-lanes.mjs";
|
|
|
63
79
|
* @param {boolean} [options.dryRun]
|
|
64
80
|
* @param {boolean} [options.skipPreflight]
|
|
65
81
|
* @param {boolean} [options.forceSuperseded]
|
|
82
|
+
* @param {number|null} [options.waveFilter]
|
|
66
83
|
*/
|
|
67
84
|
export async function startBatch({
|
|
68
85
|
projectRoot,
|
|
@@ -70,6 +87,7 @@ export async function startBatch({
|
|
|
70
87
|
dryRun = false,
|
|
71
88
|
skipPreflight = false,
|
|
72
89
|
forceSuperseded = false,
|
|
90
|
+
waveFilter = null,
|
|
73
91
|
}) {
|
|
74
92
|
if (!skipPreflight) {
|
|
75
93
|
const preflight = runBatchPreflight({ projectRoot, skipDoctor: false });
|
|
@@ -107,7 +125,22 @@ export async function startBatch({
|
|
|
107
125
|
const policyScope = scopeResolution.policyScope ?? effectiveScope;
|
|
108
126
|
|
|
109
127
|
const plan = buildPlan({ scope: effectiveScope, config, tasksRoot: /** @type {string} */ (tasksRoot) });
|
|
110
|
-
|
|
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);
|
|
111
144
|
if (!batchPolicy.ok) {
|
|
112
145
|
return {
|
|
113
146
|
ok: false,
|
|
@@ -118,17 +151,20 @@ export async function startBatch({
|
|
|
118
151
|
}
|
|
119
152
|
|
|
120
153
|
const taskIds = batchPolicy.taskIds;
|
|
121
|
-
const maxLaneNumber = maxLaneNumberForPlan(
|
|
154
|
+
const maxLaneNumber = maxLaneNumberForPlan(effectivePlan);
|
|
122
155
|
|
|
123
156
|
if (dryRun) {
|
|
157
|
+
const waveHint =
|
|
158
|
+
waveFilter != null ? ` (planner wave ${waveFilter} of ${plannerWaveCount})` : "";
|
|
124
159
|
return {
|
|
125
160
|
ok: true,
|
|
126
161
|
exitCode: 0,
|
|
127
162
|
dryRun: true,
|
|
128
163
|
taskIds,
|
|
129
|
-
plan,
|
|
164
|
+
plan: effectivePlan,
|
|
165
|
+
waveFilter,
|
|
130
166
|
output:
|
|
131
|
-
`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}, ` +
|
|
132
168
|
`up to ${maxLaneNumber} lane(s), maxParallel=${config.lanes?.maxParallel ?? 1}.\n`,
|
|
133
169
|
};
|
|
134
170
|
}
|
|
@@ -145,7 +181,7 @@ export async function startBatch({
|
|
|
145
181
|
}
|
|
146
182
|
|
|
147
183
|
const { tasks, lanes } = buildTasksAndLanesFromPlan({
|
|
148
|
-
plan,
|
|
184
|
+
plan: effectivePlan,
|
|
149
185
|
discovered,
|
|
150
186
|
projectRoot,
|
|
151
187
|
batchId,
|
|
@@ -157,18 +193,19 @@ export async function startBatch({
|
|
|
157
193
|
batchId,
|
|
158
194
|
baseBranch,
|
|
159
195
|
orchBranch,
|
|
160
|
-
wavePlan:
|
|
196
|
+
wavePlan: effectivePlan.waves.map((/** @type {{ taskIds: string[] }} */ wave) => wave.taskIds),
|
|
161
197
|
tasks,
|
|
162
198
|
lanes,
|
|
163
199
|
});
|
|
164
200
|
|
|
165
|
-
|
|
201
|
+
saveEngineBatchState(projectRoot, state);
|
|
166
202
|
|
|
167
203
|
try {
|
|
168
204
|
ensureOrchBranch(projectRoot, baseBranch, orchBranch);
|
|
169
205
|
transitionPhase(state, "running", { projectRoot, batchId });
|
|
170
206
|
recordBatchEnginePid(state, process.pid);
|
|
171
|
-
|
|
207
|
+
installAttachedEngineShutdownHandlers({ projectRoot });
|
|
208
|
+
saveEngineBatchState(projectRoot, state);
|
|
172
209
|
|
|
173
210
|
for (const lane of state.lanes) {
|
|
174
211
|
lane.correlationId = crypto.randomUUID();
|
|
@@ -225,15 +262,24 @@ export async function startBatch({
|
|
|
225
262
|
correlationId: lane.correlationId,
|
|
226
263
|
});
|
|
227
264
|
}
|
|
228
|
-
|
|
265
|
+
saveEngineBatchState(projectRoot, state);
|
|
229
266
|
|
|
230
267
|
let batchAborted = false;
|
|
231
268
|
|
|
232
|
-
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
|
+
|
|
233
275
|
state.currentWaveIndex = wave.index;
|
|
234
|
-
|
|
276
|
+
saveEngineBatchState(projectRoot, state);
|
|
235
277
|
|
|
236
278
|
for (const tick of wave.ticks ?? []) {
|
|
279
|
+
const pauseAtTick = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
280
|
+
if (pauseAtTick.stop) {
|
|
281
|
+
return buildEnginePausedResult(batchId);
|
|
282
|
+
}
|
|
237
283
|
/** @type {Map<number, { lane: object, runs: Array<{ taskId: string, run: () => Promise<{ ok: boolean, aborted?: boolean }> }> }>} */
|
|
238
284
|
const runsByLane = new Map();
|
|
239
285
|
|
|
@@ -316,6 +362,11 @@ export async function startBatch({
|
|
|
316
362
|
|
|
317
363
|
await Promise.all(laneExecutions);
|
|
318
364
|
if (batchAborted) break;
|
|
365
|
+
|
|
366
|
+
const pauseAfterTick = adoptPauseIfRequested({ projectRoot, state, batchId });
|
|
367
|
+
if (pauseAfterTick.stop) {
|
|
368
|
+
return buildEnginePausedResult(batchId);
|
|
369
|
+
}
|
|
319
370
|
}
|
|
320
371
|
|
|
321
372
|
if (batchAborted) {
|
|
@@ -327,7 +378,7 @@ export async function startBatch({
|
|
|
327
378
|
batchId,
|
|
328
379
|
extra: { taskId: abortedTask?.taskId },
|
|
329
380
|
});
|
|
330
|
-
|
|
381
|
+
saveEngineBatchState(projectRoot, state);
|
|
331
382
|
return {
|
|
332
383
|
ok: false,
|
|
333
384
|
exitCode: 1,
|
|
@@ -351,7 +402,7 @@ export async function startBatch({
|
|
|
351
402
|
reason: "mixed_outcome",
|
|
352
403
|
},
|
|
353
404
|
});
|
|
354
|
-
|
|
405
|
+
saveEngineBatchState(projectRoot, state);
|
|
355
406
|
appendJournalEvent(projectRoot, batchId, "batch.merge_blocked", {
|
|
356
407
|
waveIndex: wave.index,
|
|
357
408
|
failedTaskIds: mergeEligibility.failedTaskIds,
|
|
@@ -376,14 +427,6 @@ export async function startBatch({
|
|
|
376
427
|
waveIndex: wave.index,
|
|
377
428
|
});
|
|
378
429
|
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
430
|
return {
|
|
388
431
|
ok: false,
|
|
389
432
|
exitCode: 1,
|
|
@@ -413,6 +456,18 @@ export async function startBatch({
|
|
|
413
456
|
}
|
|
414
457
|
}
|
|
415
458
|
|
|
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
|
+
}
|
|
470
|
+
|
|
416
471
|
return finalizeBatchForIntegrate({
|
|
417
472
|
projectRoot,
|
|
418
473
|
state,
|
|
@@ -429,7 +484,7 @@ export async function startBatch({
|
|
|
429
484
|
batchId,
|
|
430
485
|
extra: { error: message },
|
|
431
486
|
});
|
|
432
|
-
|
|
487
|
+
saveEngineBatchState(projectRoot, state);
|
|
433
488
|
removeLaneWorktrees(projectRoot, batchId, maxLaneNumber);
|
|
434
489
|
return { ok: false, exitCode: 1, batchId, error: message };
|
|
435
490
|
}
|