pi-spine 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/bin/spine-cli/verify.mjs +6 -0
- package/bin/spine-deps.mjs +0 -2
- package/bin/spine-plan.mjs +49 -1
- package/bin/spine-rules.mjs +0 -2
- package/bin/spine-settings.mjs +0 -2
- package/bin/spine-worker-runner.mjs +136 -4
- package/bin/spine.mjs +2 -5
- package/package.json +2 -2
- package/skills/create-spine-tasks/SKILL.md +7 -2
- package/skills/create-spine-tasks/references/contract-template.md +95 -3
- package/src/batch/attached-engine-handoff.mjs +0 -1
- package/src/batch/attached-runner.mjs +81 -5
- package/src/batch/contract-stub-delivery.mjs +110 -0
- package/src/batch/contract-task-start.mjs +204 -0
- package/src/batch/contract-verify.mjs +160 -16
- package/src/batch/detached-start.mjs +72 -2
- package/src/batch/diagnosis-launch-failure.mjs +114 -0
- package/src/batch/diagnosis-primary-failure.mjs +89 -0
- package/src/batch/diagnosis-retry-limbo.mjs +1 -1
- package/src/batch/diagnosis-tail-state.mjs +57 -0
- package/src/batch/diagnosis.mjs +22 -114
- package/src/batch/engine-lanes/commit.mjs +145 -0
- package/src/batch/engine-lanes/merge.mjs +1 -2
- package/src/batch/engine-lanes/review.mjs +124 -121
- package/src/batch/engine-lanes.mjs +21 -81
- package/src/batch/engine.mjs +46 -1
- package/src/batch/evidence.mjs +1 -2
- package/src/batch/git-exec.mjs +5 -2
- package/src/batch/heartbeat.mjs +2 -2
- package/src/batch/integrate-assert.mjs +69 -0
- package/src/batch/integrate-worktree.mjs +354 -0
- package/src/batch/integrate.mjs +195 -102
- package/src/batch/journal-rebuild.mjs +158 -3
- package/src/batch/journal.mjs +63 -0
- package/src/batch/lane-commit.mjs +6 -5
- package/src/batch/lane-dirty-check.mjs +513 -0
- package/src/batch/limbo-detect.mjs +34 -0
- package/src/batch/macro-phase.mjs +76 -0
- package/src/batch/metrics.mjs +2 -0
- package/src/batch/pause.mjs +18 -7
- package/src/batch/post-merge-limbo.mjs +3 -28
- package/src/batch/reconcile.mjs +79 -10
- package/src/batch/resume-common.mjs +27 -0
- package/src/batch/resume-multi-lanes.mjs +11 -0
- package/src/batch/resume-multi.mjs +3 -1
- package/src/batch/resume.mjs +8 -4
- package/src/batch/retry.mjs +41 -10
- package/src/batch/review-spawn.mjs +1 -1
- package/src/batch/review.mjs +0 -4
- package/src/batch/rules-manifest-drift.mjs +43 -2
- package/src/batch/sequence-state.mjs +290 -0
- package/src/batch/sequence.mjs +113 -51
- package/src/batch/state.mjs +16 -0
- package/src/batch/worker-host.mjs +14 -5
- package/src/cli/deps.mjs +0 -2
- package/src/cli/sequence.mjs +14 -1
- package/src/cli/settings-set.mjs +33 -3
- package/src/config/contract.mjs +10 -0
- package/src/config/model-id.mjs +103 -0
- package/src/config/spine-init-constants.mjs +1 -0
- package/src/config/spine-preflight-lib.mjs +23 -1
- package/src/dashboard/public/dashboard.css +8 -0
- package/src/dashboard/public/dashboard.js +36 -9
- package/src/dashboard/running-tail-state.mjs +31 -0
- package/src/dashboard/server.mjs +4 -0
- package/src/dashboard/snapshot.mjs +260 -29
- package/src/dashboard/view.mjs +112 -2
- package/src/doctor/agent-models.mjs +53 -0
- package/src/doctor/batch-size-guidance.mjs +30 -2
- package/src/doctor/pi-extension-conflict.mjs +169 -0
- package/src/doctor/run-doctor-checks.mjs +6 -0
- package/src/planner/scope.mjs +5 -1
- package/src/tasks/packet/parse-prompt.mjs +31 -1
- package/src/tasks/packet/validate-contract.mjs +108 -0
- package/src/tasks/packet/validate-prompt.mjs +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lane commit and post-commit dirty validation (SP-427 / #73).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { appendJournalEvent } from "../journal.mjs";
|
|
6
|
+
import { commitLaneWorktree, gitPorcelain } from "../lane-commit.mjs";
|
|
7
|
+
import {
|
|
8
|
+
resolvePostLaneCommitPorcelain,
|
|
9
|
+
sanitizeOutOfScopeCoverageBeforeLaneCommit,
|
|
10
|
+
} from "../lane-dirty-check.mjs";
|
|
11
|
+
import {
|
|
12
|
+
recomputeTaskCounters,
|
|
13
|
+
saveSpineBatchState,
|
|
14
|
+
updateSegmentForTask,
|
|
15
|
+
} from "../state.mjs";
|
|
16
|
+
import { recordLaneTaskMetric } from "./queue.mjs";
|
|
17
|
+
|
|
18
|
+
const DIRTY_AFTER_COMMIT_MESSAGE =
|
|
19
|
+
"Lane worktree still has uncommitted changes after auto-commit — commit manually or fix worker output";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {object} params
|
|
23
|
+
* @param {string} params.worktreePath
|
|
24
|
+
* @param {string} params.taskBranch
|
|
25
|
+
* @param {string} params.taskId
|
|
26
|
+
* @param {string} params.batchId
|
|
27
|
+
* @param {string} params.taskFolder
|
|
28
|
+
* @param {string} [params.projectRoot]
|
|
29
|
+
* @param {string[]} [params.fileScopePaths]
|
|
30
|
+
* @param {string[]} [params.ignorePatterns]
|
|
31
|
+
* @param {object} params.task
|
|
32
|
+
* @param {object} params.lane
|
|
33
|
+
* @param {number} params.laneNumber
|
|
34
|
+
* @param {string} params.laneCorrelationId
|
|
35
|
+
* @param {object} params.state
|
|
36
|
+
* @param {object} params.config
|
|
37
|
+
* @returns {{ ok: true, laneCommit: object } | { ok: false, error: string, output?: string }}
|
|
38
|
+
*/
|
|
39
|
+
export function commitLaneAndValidateWorktree({
|
|
40
|
+
worktreePath,
|
|
41
|
+
taskBranch,
|
|
42
|
+
taskId,
|
|
43
|
+
batchId,
|
|
44
|
+
taskFolder,
|
|
45
|
+
projectRoot,
|
|
46
|
+
fileScopePaths,
|
|
47
|
+
ignorePatterns = [],
|
|
48
|
+
task,
|
|
49
|
+
lane,
|
|
50
|
+
laneNumber,
|
|
51
|
+
laneCorrelationId,
|
|
52
|
+
state,
|
|
53
|
+
config,
|
|
54
|
+
}) {
|
|
55
|
+
const preCommitPorcelain = gitPorcelain(worktreePath);
|
|
56
|
+
sanitizeOutOfScopeCoverageBeforeLaneCommit(worktreePath, fileScopePaths, {
|
|
57
|
+
projectRoot,
|
|
58
|
+
porcelain: preCommitPorcelain,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const laneCommit = commitLaneWorktree({
|
|
62
|
+
worktreePath,
|
|
63
|
+
taskBranch,
|
|
64
|
+
taskId,
|
|
65
|
+
batchId,
|
|
66
|
+
taskFolder,
|
|
67
|
+
projectRoot,
|
|
68
|
+
});
|
|
69
|
+
if (!laneCommit.ok) {
|
|
70
|
+
task.status = "failed";
|
|
71
|
+
task.endedAt = Date.now();
|
|
72
|
+
task.exitReason = laneCommit.failureClass ?? "lane_commit_failed";
|
|
73
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
74
|
+
recomputeTaskCounters(state);
|
|
75
|
+
saveSpineBatchState(projectRoot, state);
|
|
76
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
77
|
+
taskId,
|
|
78
|
+
laneNumber,
|
|
79
|
+
laneId: lane.laneId,
|
|
80
|
+
correlationId: laneCorrelationId,
|
|
81
|
+
classification: laneCommit.failureClass ?? "lane_commit_failed",
|
|
82
|
+
exitCode: 1,
|
|
83
|
+
output: laneCommit.error,
|
|
84
|
+
gitignoredPaths: laneCommit.gitignoredPaths ?? null,
|
|
85
|
+
});
|
|
86
|
+
recordLaneTaskMetric({
|
|
87
|
+
projectRoot,
|
|
88
|
+
batchId,
|
|
89
|
+
task,
|
|
90
|
+
config,
|
|
91
|
+
taskFolder,
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
error: "lane_commit_failed",
|
|
96
|
+
output: laneCommit.error,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (laneCommit.committed) {
|
|
101
|
+
appendJournalEvent(projectRoot, batchId, "lane.committed", {
|
|
102
|
+
taskId,
|
|
103
|
+
laneNumber,
|
|
104
|
+
commitSha: laneCommit.commitSha,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const remainingDirty = resolvePostLaneCommitPorcelain(worktreePath, {
|
|
109
|
+
fileScopePaths,
|
|
110
|
+
ignorePatterns,
|
|
111
|
+
projectRoot,
|
|
112
|
+
porcelain: gitPorcelain(worktreePath),
|
|
113
|
+
});
|
|
114
|
+
if (remainingDirty) {
|
|
115
|
+
task.status = "failed";
|
|
116
|
+
task.endedAt = Date.now();
|
|
117
|
+
task.exitReason = "DirtyWorktree";
|
|
118
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
119
|
+
recomputeTaskCounters(state);
|
|
120
|
+
saveSpineBatchState(projectRoot, state);
|
|
121
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
122
|
+
taskId,
|
|
123
|
+
laneNumber,
|
|
124
|
+
laneId: lane.laneId,
|
|
125
|
+
correlationId: laneCorrelationId,
|
|
126
|
+
classification: "DirtyWorktree",
|
|
127
|
+
exitCode: 1,
|
|
128
|
+
output: DIRTY_AFTER_COMMIT_MESSAGE,
|
|
129
|
+
});
|
|
130
|
+
recordLaneTaskMetric({
|
|
131
|
+
projectRoot,
|
|
132
|
+
batchId,
|
|
133
|
+
task,
|
|
134
|
+
config,
|
|
135
|
+
taskFolder,
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
error: "dirty_after_lane_commit",
|
|
140
|
+
output: DIRTY_AFTER_COMMIT_MESSAGE,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return { ok: true, laneCommit };
|
|
145
|
+
}
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
loadRulesManifest,
|
|
14
14
|
fingerprintRulesManifest,
|
|
15
15
|
} from "../../config/cursor-rules/discover.mjs";
|
|
16
|
-
import { resolveRulesManifestIntegrateDrift } from "../rules-manifest-drift.mjs";
|
|
17
16
|
import { matchesContractPattern } from "../contract-verify.mjs";
|
|
18
17
|
import {
|
|
19
18
|
formatAdoptionDocMergeFailure,
|
|
@@ -196,7 +195,7 @@ function tryAutoResolveOutOfScopeMergeConflict({
|
|
|
196
195
|
projectRoot,
|
|
197
196
|
filePath,
|
|
198
197
|
laneFileScopePaths,
|
|
199
|
-
|
|
198
|
+
_laneChangedFiles,
|
|
200
199
|
}) {
|
|
201
200
|
if (pathInLaneFileScope(filePath, laneFileScopePaths)) {
|
|
202
201
|
return { ok: false, reason: "in_lane_file_scope" };
|
|
@@ -7,7 +7,8 @@ import path from "node:path";
|
|
|
7
7
|
import { recordLaneTaskMetric } from "./queue.mjs";
|
|
8
8
|
import { REVIEW_DEFAULTS } from "../../config/defaults.mjs";
|
|
9
9
|
import { parseContract } from "../../tasks/packet/parse-prompt.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { resolveTaskStartCommit } from "../contract-task-start.mjs";
|
|
11
|
+
import { shouldRunContractVerifyForWorker, verifyContract } from "../contract-verify.mjs";
|
|
11
12
|
import { appendJournalEvent, readJournalEvents } from "../journal.mjs";
|
|
12
13
|
import {
|
|
13
14
|
recomputeTaskCounters,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
buildReviewArtifactPath,
|
|
21
22
|
normalizeCodeVerdict,
|
|
22
23
|
normalizeFinalVerdict,
|
|
23
|
-
parseFinalReviewVerdict,
|
|
24
24
|
shouldRunCodeReview,
|
|
25
25
|
shouldRunFinalReview,
|
|
26
26
|
} from "../review-shared.mjs";
|
|
@@ -264,6 +264,56 @@ function removeDoneFile(taskFolder) {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
/**
|
|
268
|
+
* @param {object} params
|
|
269
|
+
*/
|
|
270
|
+
function recordContractVerifyTaskFailure({
|
|
271
|
+
projectRoot,
|
|
272
|
+
state,
|
|
273
|
+
batchId,
|
|
274
|
+
task,
|
|
275
|
+
lane,
|
|
276
|
+
laneCorrelationId,
|
|
277
|
+
contractVerifyResult,
|
|
278
|
+
config,
|
|
279
|
+
taskFolder,
|
|
280
|
+
}) {
|
|
281
|
+
const taskId = task.taskId;
|
|
282
|
+
const laneNumber = lane.laneNumber;
|
|
283
|
+
task.status = "failed";
|
|
284
|
+
task.endedAt = Date.now();
|
|
285
|
+
task.exitReason = "contract_failed";
|
|
286
|
+
task.contractOk = false;
|
|
287
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
288
|
+
recomputeTaskCounters(state);
|
|
289
|
+
saveSpineBatchState(projectRoot, state);
|
|
290
|
+
appendJournalEvent(projectRoot, batchId, "contract.failed", {
|
|
291
|
+
taskId,
|
|
292
|
+
laneNumber,
|
|
293
|
+
laneId: lane.laneId,
|
|
294
|
+
correlationId: laneCorrelationId,
|
|
295
|
+
checks: contractVerifyResult?.checks ?? [],
|
|
296
|
+
});
|
|
297
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
298
|
+
taskId,
|
|
299
|
+
laneNumber,
|
|
300
|
+
laneId: lane.laneId,
|
|
301
|
+
correlationId: laneCorrelationId,
|
|
302
|
+
classification: "contract_failed",
|
|
303
|
+
exitCode: 1,
|
|
304
|
+
contractOk: false,
|
|
305
|
+
failureKind: "contract",
|
|
306
|
+
});
|
|
307
|
+
recordLaneTaskMetric({
|
|
308
|
+
projectRoot,
|
|
309
|
+
batchId,
|
|
310
|
+
task,
|
|
311
|
+
config,
|
|
312
|
+
taskFolder,
|
|
313
|
+
lane,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
267
317
|
/**
|
|
268
318
|
* @param {object} params
|
|
269
319
|
*/
|
|
@@ -376,30 +426,40 @@ async function runCodeReviewPhase({
|
|
|
376
426
|
const maxCodeReviewAttempts = config?.review?.maxFinalAttempts ?? REVIEW_DEFAULTS.maxFinalAttempts;
|
|
377
427
|
let codeReviewAttempt = task.codeReviewAttempts ?? 0;
|
|
378
428
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (
|
|
386
|
-
appendJournalEvent(projectRoot, batchId, "
|
|
429
|
+
const honored = findCompletedCodeReview({
|
|
430
|
+
taskFolder: taskFolderInWorktree,
|
|
431
|
+
journalEvents: readJournalEvents(projectRoot, batchId),
|
|
432
|
+
taskId,
|
|
433
|
+
});
|
|
434
|
+
if (honored?.verdict === "APPROVE") {
|
|
435
|
+
if (codeReviewAttempt > 0) {
|
|
436
|
+
appendJournalEvent(projectRoot, batchId, "review.crash_recovered", {
|
|
387
437
|
taskId,
|
|
388
438
|
laneNumber,
|
|
389
439
|
laneId: lane.laneId,
|
|
390
440
|
correlationId: laneCorrelationId,
|
|
391
441
|
reviewType: "code",
|
|
392
|
-
|
|
393
|
-
feedback: honored.feedback,
|
|
442
|
+
codeReviewAttempt,
|
|
394
443
|
artifactPath: honored.artifactPath,
|
|
395
|
-
codeReviewAttempt: 1,
|
|
396
|
-
honored: true,
|
|
397
444
|
honorSource: honored.source,
|
|
398
445
|
});
|
|
399
|
-
task.codeReviewAttempts = 1;
|
|
400
|
-
saveSpineBatchState(projectRoot, state);
|
|
401
|
-
return { ok: true, verdict: "APPROVE", codeReviewAttempt: 1, honored: true };
|
|
402
446
|
}
|
|
447
|
+
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
448
|
+
taskId,
|
|
449
|
+
laneNumber,
|
|
450
|
+
laneId: lane.laneId,
|
|
451
|
+
correlationId: laneCorrelationId,
|
|
452
|
+
reviewType: "code",
|
|
453
|
+
verdict: "APPROVE",
|
|
454
|
+
feedback: honored.feedback,
|
|
455
|
+
artifactPath: honored.artifactPath,
|
|
456
|
+
codeReviewAttempt: codeReviewAttempt + 1,
|
|
457
|
+
honored: true,
|
|
458
|
+
honorSource: honored.source,
|
|
459
|
+
});
|
|
460
|
+
task.codeReviewAttempts = codeReviewAttempt + 1;
|
|
461
|
+
saveSpineBatchState(projectRoot, state);
|
|
462
|
+
return { ok: true, verdict: "APPROVE", codeReviewAttempt: codeReviewAttempt + 1, honored: true };
|
|
403
463
|
}
|
|
404
464
|
|
|
405
465
|
const journal = {
|
|
@@ -597,30 +657,40 @@ async function runFinalReviewPhase({
|
|
|
597
657
|
const maxFinalAttempts = config?.review?.maxFinalAttempts ?? REVIEW_DEFAULTS.maxFinalAttempts;
|
|
598
658
|
let finalAttempt = task.finalAttempts ?? 0;
|
|
599
659
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
if (
|
|
607
|
-
appendJournalEvent(projectRoot, batchId, "
|
|
660
|
+
const honoredFinal = findCompletedFinalReview({
|
|
661
|
+
taskFolder: taskFolderInWorktree,
|
|
662
|
+
journalEvents: readJournalEvents(projectRoot, batchId),
|
|
663
|
+
taskId,
|
|
664
|
+
});
|
|
665
|
+
if (honoredFinal?.verdict === "PASS") {
|
|
666
|
+
if (finalAttempt > 0) {
|
|
667
|
+
appendJournalEvent(projectRoot, batchId, "review.crash_recovered", {
|
|
608
668
|
taskId,
|
|
609
669
|
laneNumber,
|
|
610
670
|
laneId: lane.laneId,
|
|
611
671
|
correlationId: laneCorrelationId,
|
|
612
672
|
reviewType: "final",
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
finalAttempt: 1,
|
|
617
|
-
honored: true,
|
|
618
|
-
honorSource: honored.source,
|
|
673
|
+
finalAttempt,
|
|
674
|
+
artifactPath: honoredFinal.artifactPath,
|
|
675
|
+
honorSource: honoredFinal.source,
|
|
619
676
|
});
|
|
620
|
-
task.finalAttempts = 1;
|
|
621
|
-
saveSpineBatchState(projectRoot, state);
|
|
622
|
-
return { ok: true, verdict: "PASS", finalAttempt: 1, honored: true };
|
|
623
677
|
}
|
|
678
|
+
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
679
|
+
taskId,
|
|
680
|
+
laneNumber,
|
|
681
|
+
laneId: lane.laneId,
|
|
682
|
+
correlationId: laneCorrelationId,
|
|
683
|
+
reviewType: "final",
|
|
684
|
+
verdict: "PASS",
|
|
685
|
+
feedback: honoredFinal.feedback,
|
|
686
|
+
artifactPath: honoredFinal.artifactPath,
|
|
687
|
+
finalAttempt: finalAttempt + 1,
|
|
688
|
+
honored: true,
|
|
689
|
+
honorSource: honoredFinal.source,
|
|
690
|
+
});
|
|
691
|
+
task.finalAttempts = finalAttempt + 1;
|
|
692
|
+
saveSpineBatchState(projectRoot, state);
|
|
693
|
+
return { ok: true, verdict: "PASS", finalAttempt: finalAttempt + 1, honored: true };
|
|
624
694
|
}
|
|
625
695
|
|
|
626
696
|
const journal = {
|
|
@@ -636,9 +706,22 @@ async function runFinalReviewPhase({
|
|
|
636
706
|
const promptMarkdown = fs.readFileSync(path.join(taskFolderInWorktree, "PROMPT.md"), "utf-8");
|
|
637
707
|
const parsedContract = parseContract(promptMarkdown);
|
|
638
708
|
if (shouldRunContractVerifyForWorker(promptMarkdown, parsedContract, config)) {
|
|
709
|
+
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
710
|
+
const sinceCommit = resolveTaskStartCommit({
|
|
711
|
+
journal: journalEvents,
|
|
712
|
+
taskId,
|
|
713
|
+
laneId: lane.laneId,
|
|
714
|
+
batchId,
|
|
715
|
+
worktreePath: wt,
|
|
716
|
+
});
|
|
639
717
|
contractVerifyResult = verifyContract(wt, parsedContract, {
|
|
640
718
|
...config,
|
|
641
719
|
baseBranch,
|
|
720
|
+
sinceCommit: sinceCommit ?? undefined,
|
|
721
|
+
projectRoot,
|
|
722
|
+
batchId,
|
|
723
|
+
taskId,
|
|
724
|
+
taskFolder: taskFolderInWorktree,
|
|
642
725
|
});
|
|
643
726
|
task.contractOk = contractVerifyResult.ok;
|
|
644
727
|
saveSpineBatchState(projectRoot, state);
|
|
@@ -651,99 +734,19 @@ async function runFinalReviewPhase({
|
|
|
651
734
|
checks: contractVerifyResult.checks,
|
|
652
735
|
});
|
|
653
736
|
if (!contractVerifyResult.ok) {
|
|
654
|
-
finalAttempt++;
|
|
655
|
-
task.finalAttempts = finalAttempt;
|
|
656
|
-
saveSpineBatchState(projectRoot, state);
|
|
657
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
658
|
-
taskId,
|
|
659
|
-
laneNumber,
|
|
660
|
-
laneId: lane.laneId,
|
|
661
|
-
correlationId: laneCorrelationId,
|
|
662
|
-
reviewType: "final",
|
|
663
|
-
verdict: "REVISE",
|
|
664
|
-
feedback: contractVerifyResult.checks
|
|
665
|
-
.filter((check) => !check.ok)
|
|
666
|
-
.map((check) => check.message)
|
|
667
|
-
.join("; "),
|
|
668
|
-
finalAttempt,
|
|
669
|
-
contractOk: false,
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
if (finalAttempt >= maxFinalAttempts) {
|
|
673
|
-
removeDoneFile(taskFolderInWorktree);
|
|
674
|
-
appendJournalEvent(projectRoot, batchId, "review.exhausted", {
|
|
675
|
-
taskId,
|
|
676
|
-
laneNumber,
|
|
677
|
-
laneId: lane.laneId,
|
|
678
|
-
correlationId: laneCorrelationId,
|
|
679
|
-
finalAttempt,
|
|
680
|
-
maxFinalAttempts,
|
|
681
|
-
});
|
|
682
|
-
recordFinalReviewTaskFailure({
|
|
683
|
-
projectRoot,
|
|
684
|
-
state,
|
|
685
|
-
batchId,
|
|
686
|
-
task,
|
|
687
|
-
lane,
|
|
688
|
-
laneCorrelationId,
|
|
689
|
-
exitReason: "review_exhausted",
|
|
690
|
-
verdict: "REVISE",
|
|
691
|
-
finalAttempt,
|
|
692
|
-
config,
|
|
693
|
-
taskFolder: taskFolderInWorktree,
|
|
694
|
-
});
|
|
695
|
-
return { ok: false, exitReason: "review_exhausted", verdict: "REVISE" };
|
|
696
|
-
}
|
|
697
|
-
|
|
698
737
|
removeDoneFile(taskFolderInWorktree);
|
|
699
|
-
|
|
700
|
-
worktreePath: wt,
|
|
701
|
-
taskFolder: taskFolderInWorktree,
|
|
738
|
+
recordContractVerifyTaskFailure({
|
|
702
739
|
projectRoot,
|
|
740
|
+
state,
|
|
703
741
|
batchId,
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
laneBranch: taskBranch,
|
|
742
|
+
task,
|
|
743
|
+
lane,
|
|
707
744
|
laneCorrelationId,
|
|
708
|
-
|
|
745
|
+
contractVerifyResult,
|
|
709
746
|
config,
|
|
710
|
-
|
|
711
|
-
lane.lastHeartbeatAt = timestamp;
|
|
712
|
-
saveSpineBatchState(projectRoot, state);
|
|
713
|
-
},
|
|
714
|
-
onWorkerPid: (pid) => {
|
|
715
|
-
if (pid > 0) {
|
|
716
|
-
lane.workerPid = pid;
|
|
717
|
-
saveSpineBatchState(projectRoot, state);
|
|
718
|
-
}
|
|
719
|
-
},
|
|
720
|
-
});
|
|
721
|
-
if (!reworkResult.ok) {
|
|
722
|
-
const aborted = reworkResult.classification === "aborted";
|
|
723
|
-
task.status = aborted ? "aborted" : "failed";
|
|
724
|
-
task.endedAt = Date.now();
|
|
725
|
-
task.exitReason = reworkResult.classification ?? "worker_failed";
|
|
726
|
-
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
727
|
-
recomputeTaskCounters(state);
|
|
728
|
-
saveSpineBatchState(projectRoot, state);
|
|
729
|
-
recordLaneTaskMetric({
|
|
730
|
-
projectRoot,
|
|
731
|
-
batchId,
|
|
732
|
-
task,
|
|
733
|
-
config,
|
|
734
|
-
taskFolder: taskFolderInWorktree,
|
|
735
|
-
});
|
|
736
|
-
return { ok: false, aborted, workerResult: reworkResult };
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
740
|
-
laneNumber,
|
|
741
|
-
laneId: lane.laneId,
|
|
742
|
-
taskId,
|
|
743
|
-
correlationId: laneCorrelationId,
|
|
744
|
-
phase: "final_rework",
|
|
747
|
+
taskFolder: taskFolderInWorktree,
|
|
745
748
|
});
|
|
746
|
-
|
|
749
|
+
return { ok: false, exitReason: "contract_failed", verdict: "CONTRACT_FAIL" };
|
|
747
750
|
}
|
|
748
751
|
}
|
|
749
752
|
|
|
@@ -5,24 +5,18 @@
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import {
|
|
8
|
-
buildTasksAndLanesFromPlan,
|
|
9
8
|
loadTaskFileScopePaths,
|
|
10
9
|
recordLaneTaskMetric,
|
|
11
10
|
recordPromptParseFailure,
|
|
12
|
-
skipTaskDoneOnDisk,
|
|
13
11
|
} from "./engine-lanes/queue.mjs";
|
|
14
12
|
import { appendJournalEvent } from "./journal.mjs";
|
|
15
|
-
import {
|
|
16
|
-
commitLaneWorktree,
|
|
17
|
-
filterPorcelain,
|
|
18
|
-
gitPorcelain,
|
|
19
|
-
} from "./lane-commit.mjs";
|
|
13
|
+
import { commitLaneAndValidateWorktree } from "./engine-lanes/commit.mjs";
|
|
20
14
|
import { recordTaskFailureSalvage } from "./salvage.mjs";
|
|
15
|
+
import { saveEngineBatchState } from "./pause.mjs";
|
|
21
16
|
import {
|
|
22
17
|
recordTaskSucceeded,
|
|
23
18
|
recordTaskTransition,
|
|
24
19
|
recomputeTaskCounters,
|
|
25
|
-
saveSpineBatchState,
|
|
26
20
|
updateSegmentForTask,
|
|
27
21
|
} from "./state.mjs";
|
|
28
22
|
import { runWorker } from "./worker-host.mjs";
|
|
@@ -129,7 +123,7 @@ export async function runTaskOnLane({
|
|
|
129
123
|
task.status = "running";
|
|
130
124
|
if (!task.startedAt) task.startedAt = Date.now();
|
|
131
125
|
updateSegmentForTask(state, taskId, "running");
|
|
132
|
-
|
|
126
|
+
saveEngineBatchState(projectRoot, state);
|
|
133
127
|
appendJournalEvent(projectRoot, batchId, "task.started", {
|
|
134
128
|
taskId,
|
|
135
129
|
laneNumber,
|
|
@@ -150,12 +144,12 @@ export async function runTaskOnLane({
|
|
|
150
144
|
config,
|
|
151
145
|
onHeartbeat: (timestamp) => {
|
|
152
146
|
lane.lastHeartbeatAt = timestamp;
|
|
153
|
-
|
|
147
|
+
saveEngineBatchState(projectRoot, state);
|
|
154
148
|
},
|
|
155
149
|
onWorkerPid: (pid) => {
|
|
156
150
|
if (pid > 0) {
|
|
157
151
|
lane.workerPid = pid;
|
|
158
|
-
|
|
152
|
+
saveEngineBatchState(projectRoot, state);
|
|
159
153
|
}
|
|
160
154
|
},
|
|
161
155
|
});
|
|
@@ -176,7 +170,7 @@ export async function runTaskOnLane({
|
|
|
176
170
|
});
|
|
177
171
|
if (lane.workerPid) {
|
|
178
172
|
delete lane.workerPid;
|
|
179
|
-
|
|
173
|
+
saveEngineBatchState(projectRoot, state);
|
|
180
174
|
}
|
|
181
175
|
} else {
|
|
182
176
|
const aborted = workerResult.classification === "aborted";
|
|
@@ -192,7 +186,7 @@ export async function runTaskOnLane({
|
|
|
192
186
|
task.exitReason = workerResult.classification ?? "worker_failed";
|
|
193
187
|
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
194
188
|
recomputeTaskCounters(state);
|
|
195
|
-
|
|
189
|
+
saveEngineBatchState(projectRoot, state);
|
|
196
190
|
if (!aborted) {
|
|
197
191
|
const salvageFields = recordTaskFailureSalvage({
|
|
198
192
|
projectRoot,
|
|
@@ -231,7 +225,7 @@ export async function runTaskOnLane({
|
|
|
231
225
|
|
|
232
226
|
if (lane.workerPid) {
|
|
233
227
|
delete lane.workerPid;
|
|
234
|
-
|
|
228
|
+
saveEngineBatchState(projectRoot, state);
|
|
235
229
|
}
|
|
236
230
|
|
|
237
231
|
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
@@ -286,84 +280,30 @@ export async function runTaskOnLane({
|
|
|
286
280
|
const ignorePatterns = Array.isArray(config?.worktreeSetupIgnorePaths)
|
|
287
281
|
? config.worktreeSetupIgnorePaths
|
|
288
282
|
: [];
|
|
289
|
-
const
|
|
283
|
+
const commitResult = commitLaneAndValidateWorktree({
|
|
290
284
|
worktreePath: wt,
|
|
291
285
|
taskBranch,
|
|
292
286
|
taskId,
|
|
293
287
|
batchId,
|
|
294
288
|
taskFolder: taskFolderInWorktree,
|
|
295
289
|
projectRoot,
|
|
290
|
+
fileScopePaths,
|
|
291
|
+
ignorePatterns,
|
|
292
|
+
task,
|
|
293
|
+
lane,
|
|
294
|
+
laneNumber,
|
|
295
|
+
laneCorrelationId,
|
|
296
|
+
state,
|
|
297
|
+
config,
|
|
296
298
|
});
|
|
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
|
-
gitignoredPaths: laneCommit.gitignoredPaths ?? null,
|
|
313
|
-
});
|
|
314
|
-
recordLaneTaskMetric({
|
|
315
|
-
projectRoot,
|
|
316
|
-
batchId,
|
|
317
|
-
task,
|
|
318
|
-
config,
|
|
319
|
-
taskFolder: taskFolderInWorktree,
|
|
320
|
-
});
|
|
321
|
-
return {
|
|
322
|
-
ok: false,
|
|
323
|
-
error: "lane_commit_failed",
|
|
324
|
-
output: laneCommit.error,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
if (laneCommit.committed) {
|
|
328
|
-
appendJournalEvent(projectRoot, batchId, "lane.committed", {
|
|
329
|
-
taskId,
|
|
330
|
-
laneNumber,
|
|
331
|
-
commitSha: laneCommit.commitSha,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const remainingDirty = filterPorcelain(gitPorcelain(wt), ignorePatterns);
|
|
336
|
-
if (remainingDirty) {
|
|
337
|
-
const dirtyOutput =
|
|
338
|
-
"Lane worktree still has uncommitted changes after auto-commit — commit manually or fix worker output";
|
|
339
|
-
task.status = "failed";
|
|
340
|
-
task.endedAt = Date.now();
|
|
341
|
-
task.exitReason = "DirtyWorktree";
|
|
342
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
343
|
-
recomputeTaskCounters(state);
|
|
344
|
-
saveSpineBatchState(projectRoot, state);
|
|
345
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
346
|
-
taskId,
|
|
347
|
-
laneNumber,
|
|
348
|
-
laneId: lane.laneId,
|
|
349
|
-
correlationId: laneCorrelationId,
|
|
350
|
-
classification: "DirtyWorktree",
|
|
351
|
-
exitCode: 1,
|
|
352
|
-
output: dirtyOutput,
|
|
353
|
-
});
|
|
354
|
-
recordLaneTaskMetric({
|
|
355
|
-
projectRoot,
|
|
356
|
-
batchId,
|
|
357
|
-
task,
|
|
358
|
-
config,
|
|
359
|
-
taskFolder: taskFolderInWorktree,
|
|
360
|
-
});
|
|
299
|
+
if (!commitResult.ok) {
|
|
361
300
|
return {
|
|
362
301
|
ok: false,
|
|
363
|
-
error:
|
|
364
|
-
output:
|
|
302
|
+
error: commitResult.error,
|
|
303
|
+
output: commitResult.output,
|
|
365
304
|
};
|
|
366
305
|
}
|
|
306
|
+
const { laneCommit } = commitResult;
|
|
367
307
|
|
|
368
308
|
recordTaskSucceeded(state, taskId, { exitReason: "done", doneFileFound: true });
|
|
369
309
|
recordTaskTransition({
|