pi-spine 2.15.0 → 2.16.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/package.json +1 -1
- package/skills/spine-release-operator/SKILL.md +60 -7
- package/skills/spine-release-operator/references/issue-intake-checklist.md +1 -1
- package/skills/spine-release-operator/references/post-integrate-regression-gate.md +1 -0
- package/src/batch/abort.mjs +82 -68
- package/src/batch/batch-state-lock.mjs +357 -0
- package/src/batch/contract-exec.mjs +12 -8
- package/src/batch/engine-lanes/review-code.mjs +224 -0
- package/src/batch/engine-lanes/review-final.mjs +318 -0
- package/src/batch/engine-lanes/review-plan.mjs +315 -0
- package/src/batch/engine-lanes/review-poll.mjs +427 -0
- package/src/batch/engine-lanes/review-stub.mjs +146 -0
- package/src/batch/engine-lanes/review.mjs +4 -1532
- package/src/batch/lifecycle.mjs +106 -95
- package/src/batch/state-io.mjs +55 -41
- package/src/config/cursor-rules/profile.mjs +5 -1
- package/src/config/defaults.mjs +10 -1
- package/src/config/settings-fields.mjs +14 -0
- package/src/planner/file-scope.mjs +109 -7
- package/src/tasks/analyze/index.mjs +14 -27
- package/src/tasks/packet/parse-prompt.mjs +138 -3
|
@@ -1,46 +1,8 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
/**
|
|
3
|
-
* Engine lane review-phase
|
|
3
|
+
* Engine lane review-phase coordinator — re-exports phase modules (SP-729/730 / #262).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { recordLaneTaskMetric } from "./queue.mjs";
|
|
9
|
-
import { REVIEW_DEFAULTS } from "../../config/defaults.mjs";
|
|
10
|
-
import { parseContract } from "../../tasks/packet/parse-prompt.mjs";
|
|
11
|
-
import { resolveTaskStartCommit } from "../contract-task-start.mjs";
|
|
12
|
-
import { shouldRunContractVerifyForWorker, verifyContract } from "../contract-verify.mjs";
|
|
13
|
-
import { appendJournalEvent, readJournalEvents } from "../journal.mjs";
|
|
14
|
-
import {
|
|
15
|
-
recomputeTaskCounters,
|
|
16
|
-
saveSpineBatchState,
|
|
17
|
-
updateSegmentForTask,
|
|
18
|
-
} from "../state.mjs";
|
|
19
|
-
import { runWorker } from "../worker-host.mjs";
|
|
20
|
-
import {
|
|
21
|
-
buildFinalReviewArtifactPath,
|
|
22
|
-
buildReviewArtifactPath,
|
|
23
|
-
isReviewTypeRequired,
|
|
24
|
-
normalizeCodeVerdict,
|
|
25
|
-
normalizeFinalVerdict,
|
|
26
|
-
parseReviewVerdict,
|
|
27
|
-
shouldRunCodeReview,
|
|
28
|
-
shouldRunFinalReview,
|
|
29
|
-
} from "../review-shared.mjs";
|
|
30
|
-
import {
|
|
31
|
-
findCodeReviewStepNumber,
|
|
32
|
-
findCompletedCodeReview,
|
|
33
|
-
findCompletedFinalReview,
|
|
34
|
-
findFinalReviewStepNumber,
|
|
35
|
-
findLatestStepReviewArtifact,
|
|
36
|
-
readReviewLevel,
|
|
37
|
-
REVIEW_TIMEOUT_REASON,
|
|
38
|
-
resolveReviewHonorJournalEvent,
|
|
39
|
-
resolveReviewPassKind,
|
|
40
|
-
shouldEmitReviewResumed,
|
|
41
|
-
runStepReview,
|
|
42
|
-
} from "../review.mjs";
|
|
43
|
-
|
|
44
6
|
export {
|
|
45
7
|
buildFinalReviewArtifactPath,
|
|
46
8
|
parseFinalReviewVerdict,
|
|
@@ -48,1496 +10,6 @@ export {
|
|
|
48
10
|
shouldRunFinalReview,
|
|
49
11
|
} from "../review-shared.mjs";
|
|
50
12
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
function resolveFinalStubVerdict() {
|
|
55
|
-
const queue = process.env.SPINE_ENGINE_FINAL_STUB_VERDICTS;
|
|
56
|
-
if (queue) {
|
|
57
|
-
const parts = queue.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
58
|
-
const verdict = parts.shift() ?? "PASS";
|
|
59
|
-
process.env.SPINE_ENGINE_FINAL_STUB_VERDICTS = parts.join(",");
|
|
60
|
-
return normalizeFinalVerdict(verdict) ?? "PASS";
|
|
61
|
-
}
|
|
62
|
-
const single = process.env.SPINE_ENGINE_FINAL_STUB_VERDICT ?? "PASS";
|
|
63
|
-
return normalizeFinalVerdict(single) ?? "PASS";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @returns {"APPROVE"|"REVISE"}
|
|
68
|
-
*/
|
|
69
|
-
function resolveCodeStubVerdict() {
|
|
70
|
-
const queue = process.env.SPINE_ENGINE_CODE_STUB_VERDICTS;
|
|
71
|
-
if (queue) {
|
|
72
|
-
const parts = queue.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
73
|
-
const verdict = parts.shift() ?? "APPROVE";
|
|
74
|
-
process.env.SPINE_ENGINE_CODE_STUB_VERDICTS = parts.join(",");
|
|
75
|
-
return normalizeCodeVerdict(verdict) ?? "APPROVE";
|
|
76
|
-
}
|
|
77
|
-
const single = process.env.SPINE_ENGINE_CODE_STUB_VERDICT ?? "APPROVE";
|
|
78
|
-
return normalizeCodeVerdict(single) ?? "APPROVE";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @param {object} params
|
|
83
|
-
*/
|
|
84
|
-
function writeFinalStubReviewArtifact({ artifactPath, verdict, feedback }) {
|
|
85
|
-
fs.mkdirSync(path.dirname(artifactPath), { recursive: true });
|
|
86
|
-
const body = [
|
|
87
|
-
"## Final Review",
|
|
88
|
-
"",
|
|
89
|
-
`### Verdict: ${verdict}`,
|
|
90
|
-
"",
|
|
91
|
-
"### Summary",
|
|
92
|
-
feedback || `Stub final review returned ${verdict}.`,
|
|
93
|
-
"",
|
|
94
|
-
"```json",
|
|
95
|
-
JSON.stringify({ verdict, feedback: feedback || "" }, null, 2),
|
|
96
|
-
"```",
|
|
97
|
-
"",
|
|
98
|
-
].join("\n");
|
|
99
|
-
fs.writeFileSync(artifactPath, body, "utf-8");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @param {object} params
|
|
104
|
-
*/
|
|
105
|
-
export async function runEngineFinalReview({
|
|
106
|
-
taskFolder,
|
|
107
|
-
worktreePath,
|
|
108
|
-
config = {},
|
|
109
|
-
attempt = 1,
|
|
110
|
-
contractVerifyResult = null,
|
|
111
|
-
journal,
|
|
112
|
-
}) {
|
|
113
|
-
const reviewLevel = readReviewLevel(taskFolder);
|
|
114
|
-
if (!shouldRunFinalReview({ config, reviewLevel })) {
|
|
115
|
-
return {
|
|
116
|
-
ok: true,
|
|
117
|
-
skipped: true,
|
|
118
|
-
reviewLevel,
|
|
119
|
-
verdict: null,
|
|
120
|
-
feedback: "",
|
|
121
|
-
artifactPath: "",
|
|
122
|
-
spawnFailed: false,
|
|
123
|
-
exitCode: 0,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const artifactPath = buildFinalReviewArtifactPath(taskFolder);
|
|
128
|
-
const useStub =
|
|
129
|
-
process.env.SPINE_REVIEW_STUB === "1" ||
|
|
130
|
-
process.env.SPINE_REVIEW_STUB === "true" ||
|
|
131
|
-
process.env.SPINE_WORKER_STUB === "1";
|
|
132
|
-
|
|
133
|
-
if (useStub) {
|
|
134
|
-
const verdict = resolveFinalStubVerdict();
|
|
135
|
-
const feedback =
|
|
136
|
-
verdict === "REVISE"
|
|
137
|
-
? "Stub reviewer requested changes."
|
|
138
|
-
: verdict === "REPLAN"
|
|
139
|
-
? "Stub reviewer requested replan."
|
|
140
|
-
: "Stub reviewer passed.";
|
|
141
|
-
writeFinalStubReviewArtifact({ artifactPath, verdict, feedback });
|
|
142
|
-
return {
|
|
143
|
-
ok: verdict === "PASS",
|
|
144
|
-
skipped: false,
|
|
145
|
-
reviewLevel,
|
|
146
|
-
verdict,
|
|
147
|
-
feedback,
|
|
148
|
-
artifactPath,
|
|
149
|
-
spawnFailed: false,
|
|
150
|
-
exitCode: verdict === "PASS" ? 0 : 2,
|
|
151
|
-
attempt,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const stepNumber = findFinalReviewStepNumber(taskFolder);
|
|
156
|
-
return await runStepReview({
|
|
157
|
-
taskFolder,
|
|
158
|
-
worktreePath,
|
|
159
|
-
stepNumber,
|
|
160
|
-
reviewType: "final",
|
|
161
|
-
config,
|
|
162
|
-
journal,
|
|
163
|
-
contractVerifyResult,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @returns {"APPROVE"|"REVISE"}
|
|
169
|
-
*/
|
|
170
|
-
function resolvePlanStubVerdict() {
|
|
171
|
-
const queue = process.env.SPINE_ENGINE_PLAN_STUB_VERDICTS;
|
|
172
|
-
if (queue) {
|
|
173
|
-
const parts = queue.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
174
|
-
const verdict = parts.shift() ?? "APPROVE";
|
|
175
|
-
process.env.SPINE_ENGINE_PLAN_STUB_VERDICTS = parts.join(",");
|
|
176
|
-
return normalizeCodeVerdict(verdict) ?? "APPROVE";
|
|
177
|
-
}
|
|
178
|
-
const single = process.env.SPINE_ENGINE_PLAN_STUB_VERDICT ?? "APPROVE";
|
|
179
|
-
return normalizeCodeVerdict(single) ?? "APPROVE";
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Step number containing a plan review checkpoint marker, else the lowest step.
|
|
184
|
-
* Local mirror of findCodeReviewStepNumber for the engine plan phase (SP-695).
|
|
185
|
-
*
|
|
186
|
-
* @param {string} taskFolder
|
|
187
|
-
*/
|
|
188
|
-
function findPlanReviewStepNumber(taskFolder) {
|
|
189
|
-
const promptPath = path.join(taskFolder, "PROMPT.md");
|
|
190
|
-
if (!fs.existsSync(promptPath)) return 0;
|
|
191
|
-
const content = fs.readFileSync(promptPath, "utf-8");
|
|
192
|
-
const stepBlocks = [...content.matchAll(/###\s+Step\s+(\d+)[:\s][\s\S]*?(?=###\s+Step\s+\d+|$)/g)];
|
|
193
|
-
for (const match of stepBlocks) {
|
|
194
|
-
if (/plan[-\s]review\s+checkpoint/i.test(match[0])) {
|
|
195
|
-
return Number(match[1]);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (stepBlocks.length === 0) return 0;
|
|
199
|
-
return Math.min(...stepBlocks.map((match) => Number(match[1])));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Resolve an existing worker or lane plan review from journal and/or artifacts.
|
|
204
|
-
* Mirrors findCompletedCodeReview with reviewType "plan" (SP-695).
|
|
205
|
-
*
|
|
206
|
-
* @param {object} params
|
|
207
|
-
* @param {string} params.taskFolder
|
|
208
|
-
* @param {object[]} [params.journalEvents]
|
|
209
|
-
* @param {string} [params.taskId]
|
|
210
|
-
* @returns {{ verdict: "APPROVE"|"REVISE", feedback: string, artifactPath: string, source: "journal"|"artifact" }|null}
|
|
211
|
-
*/
|
|
212
|
-
function findCompletedPlanReview({ taskFolder, journalEvents = [], taskId }) {
|
|
213
|
-
/** @type {{ verdict: "APPROVE"|"REVISE", feedback: string, artifactPath: string, source: "journal"|"artifact", seq: number }|null} */
|
|
214
|
-
let journalMatch = null;
|
|
215
|
-
for (let index = 0; index < journalEvents.length; index += 1) {
|
|
216
|
-
const event = journalEvents[index];
|
|
217
|
-
if (taskId && event.taskId !== taskId) continue;
|
|
218
|
-
if (event.type !== "review.completed") continue;
|
|
219
|
-
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
220
|
-
if (payload.reviewType !== "plan") continue;
|
|
221
|
-
const verdict = normalizeCodeVerdict(payload.verdict);
|
|
222
|
-
if (!verdict) continue;
|
|
223
|
-
journalMatch = {
|
|
224
|
-
verdict,
|
|
225
|
-
feedback: typeof payload.feedback === "string" ? payload.feedback : "",
|
|
226
|
-
artifactPath: typeof payload.artifactPath === "string" ? payload.artifactPath : "",
|
|
227
|
-
source: "journal",
|
|
228
|
-
seq: index,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (journalMatch?.verdict === "APPROVE") {
|
|
233
|
-
const { seq: _seq, ...result } = journalMatch;
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const stepNumber = findPlanReviewStepNumber(taskFolder);
|
|
238
|
-
const latestArtifact = findLatestStepReviewArtifact(taskFolder, stepNumber);
|
|
239
|
-
if (latestArtifact) {
|
|
240
|
-
const reviewContent = fs.readFileSync(latestArtifact.artifactPath, "utf-8");
|
|
241
|
-
const { verdict, feedback } = parseReviewVerdict(reviewContent, { reviewType: "plan" });
|
|
242
|
-
if (verdict) {
|
|
243
|
-
const artifactMatch = {
|
|
244
|
-
verdict,
|
|
245
|
-
feedback,
|
|
246
|
-
artifactPath: latestArtifact.artifactPath,
|
|
247
|
-
source: /** @type {"artifact"} */ ("artifact"),
|
|
248
|
-
};
|
|
249
|
-
if (verdict === "APPROVE") return artifactMatch;
|
|
250
|
-
if (!journalMatch) return artifactMatch;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (!journalMatch) return null;
|
|
255
|
-
const { seq: _seq, ...result } = journalMatch;
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Engine-owned plan review — mirror of runEngineCodeReview with reviewType "plan".
|
|
261
|
-
* Uses agents.reviewer.plan pins via runStepReview → buildReviewerPiArgs (SP-695 / #250).
|
|
262
|
-
*
|
|
263
|
-
* @param {object} params
|
|
264
|
-
*/
|
|
265
|
-
export async function runEnginePlanReview({
|
|
266
|
-
taskFolder,
|
|
267
|
-
worktreePath,
|
|
268
|
-
config = {},
|
|
269
|
-
attempt = 1,
|
|
270
|
-
journal,
|
|
271
|
-
}) {
|
|
272
|
-
const reviewLevel = readReviewLevel(taskFolder);
|
|
273
|
-
if (!isReviewTypeRequired(reviewLevel, "plan")) {
|
|
274
|
-
return {
|
|
275
|
-
ok: true,
|
|
276
|
-
skipped: true,
|
|
277
|
-
reviewLevel,
|
|
278
|
-
verdict: null,
|
|
279
|
-
feedback: "",
|
|
280
|
-
artifactPath: "",
|
|
281
|
-
spawnFailed: false,
|
|
282
|
-
exitCode: 0,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const stepNumber = findPlanReviewStepNumber(taskFolder);
|
|
287
|
-
const artifactPath = buildReviewArtifactPath(taskFolder, stepNumber);
|
|
288
|
-
const useStub =
|
|
289
|
-
process.env.SPINE_REVIEW_STUB === "1" ||
|
|
290
|
-
process.env.SPINE_REVIEW_STUB === "true" ||
|
|
291
|
-
process.env.SPINE_WORKER_STUB === "1";
|
|
292
|
-
|
|
293
|
-
if (useStub) {
|
|
294
|
-
const verdict = resolvePlanStubVerdict();
|
|
295
|
-
const feedback =
|
|
296
|
-
verdict === "REVISE" ? "Stub reviewer requested changes." : "Stub reviewer approved.";
|
|
297
|
-
if (journal?.projectRoot && journal?.batchId) {
|
|
298
|
-
appendJournalEvent(journal.projectRoot, journal.batchId, "review.started", {
|
|
299
|
-
taskId: journal.taskId,
|
|
300
|
-
laneNumber: journal.laneNumber,
|
|
301
|
-
correlationId: journal.correlationId,
|
|
302
|
-
stepNumber,
|
|
303
|
-
reviewType: "plan",
|
|
304
|
-
reviewLevel,
|
|
305
|
-
artifactPath,
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
fs.mkdirSync(path.dirname(artifactPath), { recursive: true });
|
|
309
|
-
const body = [
|
|
310
|
-
"## Plan Review",
|
|
311
|
-
"",
|
|
312
|
-
`### Verdict: ${verdict}`,
|
|
313
|
-
"",
|
|
314
|
-
"### Summary",
|
|
315
|
-
feedback,
|
|
316
|
-
"",
|
|
317
|
-
"```json",
|
|
318
|
-
JSON.stringify({ verdict, feedback }, null, 2),
|
|
319
|
-
"```",
|
|
320
|
-
"",
|
|
321
|
-
].join("\n");
|
|
322
|
-
fs.writeFileSync(artifactPath, body, "utf-8");
|
|
323
|
-
if (journal?.projectRoot && journal?.batchId) {
|
|
324
|
-
appendJournalEvent(journal.projectRoot, journal.batchId, "review.completed", {
|
|
325
|
-
taskId: journal.taskId,
|
|
326
|
-
laneNumber: journal.laneNumber,
|
|
327
|
-
correlationId: journal.correlationId,
|
|
328
|
-
stepNumber,
|
|
329
|
-
reviewType: "plan",
|
|
330
|
-
reviewLevel,
|
|
331
|
-
verdict,
|
|
332
|
-
artifactPath,
|
|
333
|
-
stub: true,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
return {
|
|
337
|
-
ok: verdict === "APPROVE",
|
|
338
|
-
skipped: false,
|
|
339
|
-
reviewLevel,
|
|
340
|
-
verdict,
|
|
341
|
-
feedback,
|
|
342
|
-
artifactPath,
|
|
343
|
-
spawnFailed: false,
|
|
344
|
-
exitCode: verdict === "APPROVE" ? 0 : 2,
|
|
345
|
-
attempt,
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return await runStepReview({
|
|
350
|
-
taskFolder,
|
|
351
|
-
worktreePath,
|
|
352
|
-
stepNumber,
|
|
353
|
-
reviewType: "plan",
|
|
354
|
-
config,
|
|
355
|
-
journal,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* @param {object} params
|
|
361
|
-
*/
|
|
362
|
-
export async function runEngineCodeReview({
|
|
363
|
-
taskFolder,
|
|
364
|
-
worktreePath,
|
|
365
|
-
config = {},
|
|
366
|
-
attempt = 1,
|
|
367
|
-
journal,
|
|
368
|
-
}) {
|
|
369
|
-
const reviewLevel = readReviewLevel(taskFolder);
|
|
370
|
-
if (!shouldRunCodeReview({ reviewLevel })) {
|
|
371
|
-
return {
|
|
372
|
-
ok: true,
|
|
373
|
-
skipped: true,
|
|
374
|
-
reviewLevel,
|
|
375
|
-
verdict: null,
|
|
376
|
-
feedback: "",
|
|
377
|
-
artifactPath: "",
|
|
378
|
-
spawnFailed: false,
|
|
379
|
-
exitCode: 0,
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const stepNumber = findCodeReviewStepNumber(taskFolder);
|
|
384
|
-
const artifactPath = buildReviewArtifactPath(taskFolder, stepNumber);
|
|
385
|
-
const useStub =
|
|
386
|
-
process.env.SPINE_REVIEW_STUB === "1" ||
|
|
387
|
-
process.env.SPINE_REVIEW_STUB === "true" ||
|
|
388
|
-
process.env.SPINE_WORKER_STUB === "1";
|
|
389
|
-
|
|
390
|
-
if (useStub) {
|
|
391
|
-
const verdict = resolveCodeStubVerdict();
|
|
392
|
-
const feedback =
|
|
393
|
-
verdict === "REVISE" ? "Stub reviewer requested changes." : "Stub reviewer approved.";
|
|
394
|
-
if (journal?.projectRoot && journal?.batchId) {
|
|
395
|
-
appendJournalEvent(journal.projectRoot, journal.batchId, "review.started", {
|
|
396
|
-
taskId: journal.taskId,
|
|
397
|
-
laneNumber: journal.laneNumber,
|
|
398
|
-
correlationId: journal.correlationId,
|
|
399
|
-
stepNumber,
|
|
400
|
-
reviewType: "code",
|
|
401
|
-
reviewLevel,
|
|
402
|
-
artifactPath,
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
fs.mkdirSync(path.dirname(artifactPath), { recursive: true });
|
|
406
|
-
const body = [
|
|
407
|
-
"## Code Review",
|
|
408
|
-
"",
|
|
409
|
-
`### Verdict: ${verdict}`,
|
|
410
|
-
"",
|
|
411
|
-
"### Summary",
|
|
412
|
-
feedback,
|
|
413
|
-
"",
|
|
414
|
-
"```json",
|
|
415
|
-
JSON.stringify({ verdict, feedback }, null, 2),
|
|
416
|
-
"```",
|
|
417
|
-
"",
|
|
418
|
-
].join("\n");
|
|
419
|
-
fs.writeFileSync(artifactPath, body, "utf-8");
|
|
420
|
-
if (journal?.projectRoot && journal?.batchId) {
|
|
421
|
-
appendJournalEvent(journal.projectRoot, journal.batchId, "review.completed", {
|
|
422
|
-
taskId: journal.taskId,
|
|
423
|
-
laneNumber: journal.laneNumber,
|
|
424
|
-
correlationId: journal.correlationId,
|
|
425
|
-
stepNumber,
|
|
426
|
-
reviewType: "code",
|
|
427
|
-
reviewLevel,
|
|
428
|
-
verdict,
|
|
429
|
-
artifactPath,
|
|
430
|
-
stub: true,
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
return {
|
|
434
|
-
ok: verdict === "APPROVE",
|
|
435
|
-
skipped: false,
|
|
436
|
-
reviewLevel,
|
|
437
|
-
verdict,
|
|
438
|
-
feedback,
|
|
439
|
-
artifactPath,
|
|
440
|
-
spawnFailed: false,
|
|
441
|
-
exitCode: verdict === "APPROVE" ? 0 : 2,
|
|
442
|
-
attempt,
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
return await runStepReview({
|
|
447
|
-
taskFolder,
|
|
448
|
-
worktreePath,
|
|
449
|
-
stepNumber,
|
|
450
|
-
reviewType: "code",
|
|
451
|
-
config,
|
|
452
|
-
journal,
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* @param {string} taskFolder
|
|
458
|
-
*/
|
|
459
|
-
function removeDoneFile(taskFolder) {
|
|
460
|
-
const donePath = path.join(taskFolder, ".DONE");
|
|
461
|
-
if (fs.existsSync(donePath)) {
|
|
462
|
-
fs.unlinkSync(donePath);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* @param {object} params
|
|
468
|
-
*/
|
|
469
|
-
function recordContractVerifyTaskFailure({
|
|
470
|
-
projectRoot,
|
|
471
|
-
state,
|
|
472
|
-
batchId,
|
|
473
|
-
task,
|
|
474
|
-
lane,
|
|
475
|
-
laneCorrelationId,
|
|
476
|
-
contractVerifyResult,
|
|
477
|
-
config,
|
|
478
|
-
taskFolder,
|
|
479
|
-
}) {
|
|
480
|
-
const taskId = task.taskId;
|
|
481
|
-
const laneNumber = lane.laneNumber;
|
|
482
|
-
task.status = "failed";
|
|
483
|
-
task.endedAt = Date.now();
|
|
484
|
-
task.exitReason = "contract_failed";
|
|
485
|
-
task.contractOk = false;
|
|
486
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
487
|
-
recomputeTaskCounters(state);
|
|
488
|
-
saveSpineBatchState(projectRoot, state);
|
|
489
|
-
appendJournalEvent(projectRoot, batchId, "contract.failed", {
|
|
490
|
-
taskId,
|
|
491
|
-
laneNumber,
|
|
492
|
-
laneId: lane.laneId,
|
|
493
|
-
correlationId: laneCorrelationId,
|
|
494
|
-
checks: contractVerifyResult?.checks ?? [],
|
|
495
|
-
});
|
|
496
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
497
|
-
taskId,
|
|
498
|
-
laneNumber,
|
|
499
|
-
laneId: lane.laneId,
|
|
500
|
-
correlationId: laneCorrelationId,
|
|
501
|
-
classification: "contract_failed",
|
|
502
|
-
exitCode: 1,
|
|
503
|
-
contractOk: false,
|
|
504
|
-
failureKind: "contract",
|
|
505
|
-
});
|
|
506
|
-
recordLaneTaskMetric({
|
|
507
|
-
projectRoot,
|
|
508
|
-
batchId,
|
|
509
|
-
task,
|
|
510
|
-
config,
|
|
511
|
-
taskFolder,
|
|
512
|
-
lane,
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* @param {object} params
|
|
518
|
-
*/
|
|
519
|
-
function recordFinalReviewTaskFailure({
|
|
520
|
-
projectRoot,
|
|
521
|
-
state,
|
|
522
|
-
batchId,
|
|
523
|
-
task,
|
|
524
|
-
lane,
|
|
525
|
-
laneCorrelationId,
|
|
526
|
-
exitReason,
|
|
527
|
-
verdict,
|
|
528
|
-
finalAttempt,
|
|
529
|
-
config,
|
|
530
|
-
taskFolder,
|
|
531
|
-
}) {
|
|
532
|
-
const taskId = task.taskId;
|
|
533
|
-
const laneNumber = lane.laneNumber;
|
|
534
|
-
task.status = "failed";
|
|
535
|
-
task.endedAt = Date.now();
|
|
536
|
-
task.exitReason = exitReason;
|
|
537
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
538
|
-
recomputeTaskCounters(state);
|
|
539
|
-
saveSpineBatchState(projectRoot, state);
|
|
540
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
541
|
-
taskId,
|
|
542
|
-
laneNumber,
|
|
543
|
-
laneId: lane.laneId,
|
|
544
|
-
correlationId: laneCorrelationId,
|
|
545
|
-
classification: exitReason,
|
|
546
|
-
exitCode: 1,
|
|
547
|
-
finalVerdict: verdict ?? null,
|
|
548
|
-
finalAttempt,
|
|
549
|
-
});
|
|
550
|
-
recordLaneTaskMetric({
|
|
551
|
-
projectRoot,
|
|
552
|
-
batchId,
|
|
553
|
-
task,
|
|
554
|
-
config,
|
|
555
|
-
taskFolder,
|
|
556
|
-
});
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* @param {object} params
|
|
561
|
-
*/
|
|
562
|
-
function recordPlanReviewTaskFailure({
|
|
563
|
-
projectRoot,
|
|
564
|
-
state,
|
|
565
|
-
batchId,
|
|
566
|
-
task,
|
|
567
|
-
lane,
|
|
568
|
-
laneCorrelationId,
|
|
569
|
-
exitReason,
|
|
570
|
-
verdict,
|
|
571
|
-
planReviewAttempt,
|
|
572
|
-
config,
|
|
573
|
-
taskFolder,
|
|
574
|
-
}) {
|
|
575
|
-
const taskId = task.taskId;
|
|
576
|
-
const laneNumber = lane.laneNumber;
|
|
577
|
-
task.status = "failed";
|
|
578
|
-
task.endedAt = Date.now();
|
|
579
|
-
task.exitReason = exitReason;
|
|
580
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
581
|
-
recomputeTaskCounters(state);
|
|
582
|
-
saveSpineBatchState(projectRoot, state);
|
|
583
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
584
|
-
taskId,
|
|
585
|
-
laneNumber,
|
|
586
|
-
laneId: lane.laneId,
|
|
587
|
-
correlationId: laneCorrelationId,
|
|
588
|
-
classification: exitReason,
|
|
589
|
-
exitCode: 1,
|
|
590
|
-
planVerdict: verdict ?? null,
|
|
591
|
-
planReviewAttempt,
|
|
592
|
-
});
|
|
593
|
-
recordLaneTaskMetric({
|
|
594
|
-
projectRoot,
|
|
595
|
-
batchId,
|
|
596
|
-
task,
|
|
597
|
-
config,
|
|
598
|
-
taskFolder,
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* @param {object} params
|
|
604
|
-
*/
|
|
605
|
-
function recordCodeReviewTaskFailure({
|
|
606
|
-
projectRoot,
|
|
607
|
-
state,
|
|
608
|
-
batchId,
|
|
609
|
-
task,
|
|
610
|
-
lane,
|
|
611
|
-
laneCorrelationId,
|
|
612
|
-
exitReason,
|
|
613
|
-
verdict,
|
|
614
|
-
codeReviewAttempt,
|
|
615
|
-
config,
|
|
616
|
-
taskFolder,
|
|
617
|
-
}) {
|
|
618
|
-
const taskId = task.taskId;
|
|
619
|
-
const laneNumber = lane.laneNumber;
|
|
620
|
-
task.status = "failed";
|
|
621
|
-
task.endedAt = Date.now();
|
|
622
|
-
task.exitReason = exitReason;
|
|
623
|
-
updateSegmentForTask(state, taskId, "failed");
|
|
624
|
-
recomputeTaskCounters(state);
|
|
625
|
-
saveSpineBatchState(projectRoot, state);
|
|
626
|
-
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
627
|
-
taskId,
|
|
628
|
-
laneNumber,
|
|
629
|
-
laneId: lane.laneId,
|
|
630
|
-
correlationId: laneCorrelationId,
|
|
631
|
-
classification: exitReason,
|
|
632
|
-
exitCode: 1,
|
|
633
|
-
codeVerdict: verdict ?? null,
|
|
634
|
-
codeReviewAttempt,
|
|
635
|
-
});
|
|
636
|
-
recordLaneTaskMetric({
|
|
637
|
-
projectRoot,
|
|
638
|
-
batchId,
|
|
639
|
-
task,
|
|
640
|
-
config,
|
|
641
|
-
taskFolder,
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* @param {object} params
|
|
647
|
-
* @param {string} params.projectRoot
|
|
648
|
-
* @param {string} params.batchId
|
|
649
|
-
* @param {object} params.task
|
|
650
|
-
* @param {object} params.lane
|
|
651
|
-
* @param {string} params.laneCorrelationId
|
|
652
|
-
* @param {"code"|"final"} params.reviewType
|
|
653
|
-
* @param {number} params.reviewAttempt
|
|
654
|
-
* @param {object} params.honored
|
|
655
|
-
* @param {"review.crash_recovered"|"review.skipped_fresh_artifact"|null} params.honorJournalEvent
|
|
656
|
-
*/
|
|
657
|
-
function appendReviewHonorJournalEvents({
|
|
658
|
-
projectRoot,
|
|
659
|
-
batchId,
|
|
660
|
-
task,
|
|
661
|
-
lane,
|
|
662
|
-
laneCorrelationId,
|
|
663
|
-
reviewType,
|
|
664
|
-
reviewAttempt,
|
|
665
|
-
honored,
|
|
666
|
-
honorJournalEvent,
|
|
667
|
-
}) {
|
|
668
|
-
const taskId = task.taskId;
|
|
669
|
-
const laneNumber = lane.laneNumber;
|
|
670
|
-
if (!honorJournalEvent) return;
|
|
671
|
-
|
|
672
|
-
const basePayload = {
|
|
673
|
-
taskId,
|
|
674
|
-
laneNumber,
|
|
675
|
-
laneId: lane.laneId,
|
|
676
|
-
correlationId: laneCorrelationId,
|
|
677
|
-
reviewType,
|
|
678
|
-
artifactPath: honored.artifactPath,
|
|
679
|
-
honorSource: honored.source,
|
|
680
|
-
reviewPassKind: resolveReviewPassKind(honorJournalEvent),
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
if (reviewType === "plan") {
|
|
684
|
-
appendJournalEvent(projectRoot, batchId, honorJournalEvent, {
|
|
685
|
-
...basePayload,
|
|
686
|
-
planReviewAttempt: reviewAttempt,
|
|
687
|
-
});
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
if (reviewType === "code") {
|
|
692
|
-
appendJournalEvent(projectRoot, batchId, honorJournalEvent, {
|
|
693
|
-
...basePayload,
|
|
694
|
-
codeReviewAttempt: reviewAttempt,
|
|
695
|
-
});
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
appendJournalEvent(projectRoot, batchId, honorJournalEvent, {
|
|
700
|
-
...basePayload,
|
|
701
|
-
finalAttempt: reviewAttempt,
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* @param {object} params
|
|
707
|
-
*/
|
|
708
|
-
async function runCodeReviewPhase({
|
|
709
|
-
projectRoot,
|
|
710
|
-
state,
|
|
711
|
-
batchId,
|
|
712
|
-
config,
|
|
713
|
-
task,
|
|
714
|
-
lane,
|
|
715
|
-
taskFolderInWorktree,
|
|
716
|
-
wt,
|
|
717
|
-
taskBranch,
|
|
718
|
-
laneCorrelationId,
|
|
719
|
-
fileScopePaths,
|
|
720
|
-
}) {
|
|
721
|
-
const taskId = task.taskId;
|
|
722
|
-
const laneNumber = lane.laneNumber;
|
|
723
|
-
const reviewLevel = readReviewLevel(taskFolderInWorktree);
|
|
724
|
-
if (!shouldRunCodeReview({ reviewLevel })) {
|
|
725
|
-
return { ok: true, skipped: true };
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
const maxCodeReviewAttempts = config?.review?.maxFinalAttempts ?? REVIEW_DEFAULTS.maxFinalAttempts;
|
|
729
|
-
let codeReviewAttempt = task.codeReviewAttempts ?? 0;
|
|
730
|
-
|
|
731
|
-
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
732
|
-
const honored = findCompletedCodeReview({
|
|
733
|
-
taskFolder: taskFolderInWorktree,
|
|
734
|
-
journalEvents,
|
|
735
|
-
taskId,
|
|
736
|
-
});
|
|
737
|
-
if (honored?.verdict === "APPROVE") {
|
|
738
|
-
const honorJournalEvent = resolveReviewHonorJournalEvent({
|
|
739
|
-
journalEvents,
|
|
740
|
-
taskId,
|
|
741
|
-
reviewType: "code",
|
|
742
|
-
honorSource: honored.source,
|
|
743
|
-
reviewAttempt: codeReviewAttempt,
|
|
744
|
-
});
|
|
745
|
-
appendReviewHonorJournalEvents({
|
|
746
|
-
projectRoot,
|
|
747
|
-
batchId,
|
|
748
|
-
task,
|
|
749
|
-
lane,
|
|
750
|
-
laneCorrelationId,
|
|
751
|
-
reviewType: "code",
|
|
752
|
-
reviewAttempt: codeReviewAttempt,
|
|
753
|
-
honored,
|
|
754
|
-
honorJournalEvent,
|
|
755
|
-
});
|
|
756
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
757
|
-
taskId,
|
|
758
|
-
laneNumber,
|
|
759
|
-
laneId: lane.laneId,
|
|
760
|
-
correlationId: laneCorrelationId,
|
|
761
|
-
reviewType: "code",
|
|
762
|
-
verdict: "APPROVE",
|
|
763
|
-
feedback: honored.feedback,
|
|
764
|
-
artifactPath: honored.artifactPath,
|
|
765
|
-
codeReviewAttempt: codeReviewAttempt + 1,
|
|
766
|
-
honored: true,
|
|
767
|
-
honorSource: honored.source,
|
|
768
|
-
reviewPassKind: resolveReviewPassKind(honorJournalEvent),
|
|
769
|
-
});
|
|
770
|
-
task.codeReviewAttempts = codeReviewAttempt + 1;
|
|
771
|
-
saveSpineBatchState(projectRoot, state);
|
|
772
|
-
return { ok: true, verdict: "APPROVE", codeReviewAttempt: codeReviewAttempt + 1, honored: true };
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
const journal = {
|
|
776
|
-
projectRoot,
|
|
777
|
-
batchId,
|
|
778
|
-
taskId,
|
|
779
|
-
laneNumber,
|
|
780
|
-
correlationId: laneCorrelationId,
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
let reviewResumedEmitted = false;
|
|
784
|
-
|
|
785
|
-
while (true) {
|
|
786
|
-
if (
|
|
787
|
-
!reviewResumedEmitted &&
|
|
788
|
-
shouldEmitReviewResumed({ journalEvents, taskId })
|
|
789
|
-
) {
|
|
790
|
-
appendJournalEvent(projectRoot, batchId, "review.resumed", {
|
|
791
|
-
taskId,
|
|
792
|
-
laneNumber,
|
|
793
|
-
laneId: lane.laneId,
|
|
794
|
-
correlationId: laneCorrelationId,
|
|
795
|
-
reviewType: "code",
|
|
796
|
-
codeReviewAttempt: codeReviewAttempt + 1,
|
|
797
|
-
});
|
|
798
|
-
reviewResumedEmitted = true;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
const reviewResult = await runEngineCodeReview({
|
|
802
|
-
taskFolder: taskFolderInWorktree,
|
|
803
|
-
worktreePath: wt,
|
|
804
|
-
config,
|
|
805
|
-
attempt: codeReviewAttempt + 1,
|
|
806
|
-
journal,
|
|
807
|
-
});
|
|
808
|
-
|
|
809
|
-
if (reviewResult.spawnFailed) {
|
|
810
|
-
const spawnExitReason =
|
|
811
|
-
reviewResult.reason === REVIEW_TIMEOUT_REASON
|
|
812
|
-
? "code_review_timeout"
|
|
813
|
-
: "code_review_spawn_failed";
|
|
814
|
-
recordCodeReviewTaskFailure({
|
|
815
|
-
projectRoot,
|
|
816
|
-
state,
|
|
817
|
-
batchId,
|
|
818
|
-
task,
|
|
819
|
-
lane,
|
|
820
|
-
laneCorrelationId,
|
|
821
|
-
exitReason: spawnExitReason,
|
|
822
|
-
verdict: null,
|
|
823
|
-
codeReviewAttempt,
|
|
824
|
-
config,
|
|
825
|
-
taskFolder: taskFolderInWorktree,
|
|
826
|
-
});
|
|
827
|
-
return {
|
|
828
|
-
ok: false,
|
|
829
|
-
error: spawnExitReason,
|
|
830
|
-
output: reviewResult.error ?? "code review spawn failed",
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
if (reviewResult.skipped) {
|
|
835
|
-
return { ok: true, skipped: true };
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
839
|
-
taskId,
|
|
840
|
-
laneNumber,
|
|
841
|
-
laneId: lane.laneId,
|
|
842
|
-
correlationId: laneCorrelationId,
|
|
843
|
-
reviewType: "code",
|
|
844
|
-
verdict: reviewResult.verdict,
|
|
845
|
-
feedback: reviewResult.feedback,
|
|
846
|
-
artifactPath: reviewResult.artifactPath,
|
|
847
|
-
codeReviewAttempt: codeReviewAttempt + 1,
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
if (reviewResult.verdict === "APPROVE") {
|
|
851
|
-
task.codeReviewAttempts = codeReviewAttempt + 1;
|
|
852
|
-
saveSpineBatchState(projectRoot, state);
|
|
853
|
-
return { ok: true, verdict: "APPROVE", codeReviewAttempt: codeReviewAttempt + 1 };
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
if (reviewResult.verdict === "REVISE") {
|
|
857
|
-
codeReviewAttempt++;
|
|
858
|
-
task.codeReviewAttempts = codeReviewAttempt;
|
|
859
|
-
saveSpineBatchState(projectRoot, state);
|
|
860
|
-
|
|
861
|
-
if (codeReviewAttempt >= maxCodeReviewAttempts) {
|
|
862
|
-
removeDoneFile(taskFolderInWorktree);
|
|
863
|
-
appendJournalEvent(projectRoot, batchId, "review.exhausted", {
|
|
864
|
-
taskId,
|
|
865
|
-
laneNumber,
|
|
866
|
-
laneId: lane.laneId,
|
|
867
|
-
correlationId: laneCorrelationId,
|
|
868
|
-
codeReviewAttempt,
|
|
869
|
-
maxCodeReviewAttempts,
|
|
870
|
-
reviewType: "code",
|
|
871
|
-
});
|
|
872
|
-
recordCodeReviewTaskFailure({
|
|
873
|
-
projectRoot,
|
|
874
|
-
state,
|
|
875
|
-
batchId,
|
|
876
|
-
task,
|
|
877
|
-
lane,
|
|
878
|
-
laneCorrelationId,
|
|
879
|
-
exitReason: "review_exhausted",
|
|
880
|
-
verdict: "REVISE",
|
|
881
|
-
codeReviewAttempt,
|
|
882
|
-
config,
|
|
883
|
-
taskFolder: taskFolderInWorktree,
|
|
884
|
-
});
|
|
885
|
-
return { ok: false, exitReason: "review_exhausted", verdict: "REVISE" };
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
removeDoneFile(taskFolderInWorktree);
|
|
889
|
-
const reworkResult = await runWorker({
|
|
890
|
-
worktreePath: wt,
|
|
891
|
-
taskFolder: taskFolderInWorktree,
|
|
892
|
-
projectRoot,
|
|
893
|
-
batchId,
|
|
894
|
-
laneNumber,
|
|
895
|
-
taskId,
|
|
896
|
-
laneBranch: taskBranch,
|
|
897
|
-
laneCorrelationId,
|
|
898
|
-
fileScopePaths,
|
|
899
|
-
config,
|
|
900
|
-
onHeartbeat: (timestamp) => {
|
|
901
|
-
lane.lastHeartbeatAt = timestamp;
|
|
902
|
-
saveSpineBatchState(projectRoot, state);
|
|
903
|
-
},
|
|
904
|
-
onWorkerPid: (pid) => {
|
|
905
|
-
if (pid > 0) {
|
|
906
|
-
lane.workerPid = pid;
|
|
907
|
-
saveSpineBatchState(projectRoot, state);
|
|
908
|
-
}
|
|
909
|
-
},
|
|
910
|
-
});
|
|
911
|
-
if (!reworkResult.ok) {
|
|
912
|
-
const aborted = reworkResult.classification === "aborted";
|
|
913
|
-
task.status = aborted ? "aborted" : "failed";
|
|
914
|
-
task.endedAt = Date.now();
|
|
915
|
-
task.exitReason = reworkResult.classification ?? "worker_failed";
|
|
916
|
-
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
917
|
-
recomputeTaskCounters(state);
|
|
918
|
-
saveSpineBatchState(projectRoot, state);
|
|
919
|
-
recordLaneTaskMetric({
|
|
920
|
-
projectRoot,
|
|
921
|
-
batchId,
|
|
922
|
-
task,
|
|
923
|
-
config,
|
|
924
|
-
taskFolder: taskFolderInWorktree,
|
|
925
|
-
});
|
|
926
|
-
return { ok: false, aborted, workerResult: reworkResult };
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
930
|
-
laneNumber,
|
|
931
|
-
laneId: lane.laneId,
|
|
932
|
-
taskId,
|
|
933
|
-
correlationId: laneCorrelationId,
|
|
934
|
-
phase: "code_rework",
|
|
935
|
-
});
|
|
936
|
-
continue;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
recordCodeReviewTaskFailure({
|
|
940
|
-
projectRoot,
|
|
941
|
-
state,
|
|
942
|
-
batchId,
|
|
943
|
-
task,
|
|
944
|
-
lane,
|
|
945
|
-
laneCorrelationId,
|
|
946
|
-
exitReason: "code_review_invalid_verdict",
|
|
947
|
-
verdict: reviewResult.verdict,
|
|
948
|
-
codeReviewAttempt,
|
|
949
|
-
config,
|
|
950
|
-
taskFolder: taskFolderInWorktree,
|
|
951
|
-
});
|
|
952
|
-
return {
|
|
953
|
-
ok: false,
|
|
954
|
-
error: "code_review_invalid_verdict",
|
|
955
|
-
output: "code review artifact missing APPROVE or REVISE verdict",
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* @param {object} params
|
|
962
|
-
*/
|
|
963
|
-
async function runFinalReviewPhase({
|
|
964
|
-
projectRoot,
|
|
965
|
-
state,
|
|
966
|
-
batchId,
|
|
967
|
-
config,
|
|
968
|
-
task,
|
|
969
|
-
lane,
|
|
970
|
-
taskFolderInWorktree,
|
|
971
|
-
wt,
|
|
972
|
-
taskBranch,
|
|
973
|
-
laneCorrelationId,
|
|
974
|
-
fileScopePaths,
|
|
975
|
-
baseBranch = "main",
|
|
976
|
-
}) {
|
|
977
|
-
const taskId = task.taskId;
|
|
978
|
-
const laneNumber = lane.laneNumber;
|
|
979
|
-
const reviewLevel = readReviewLevel(taskFolderInWorktree);
|
|
980
|
-
if (!shouldRunFinalReview({ config, reviewLevel })) {
|
|
981
|
-
return { ok: true, skipped: true };
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
const maxFinalAttempts = config?.review?.maxFinalAttempts ?? REVIEW_DEFAULTS.maxFinalAttempts;
|
|
985
|
-
let finalAttempt = task.finalAttempts ?? 0;
|
|
986
|
-
|
|
987
|
-
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
988
|
-
const honoredFinal = findCompletedFinalReview({
|
|
989
|
-
taskFolder: taskFolderInWorktree,
|
|
990
|
-
journalEvents,
|
|
991
|
-
taskId,
|
|
992
|
-
});
|
|
993
|
-
if (honoredFinal?.verdict === "PASS") {
|
|
994
|
-
const honorJournalEvent = resolveReviewHonorJournalEvent({
|
|
995
|
-
journalEvents,
|
|
996
|
-
taskId,
|
|
997
|
-
reviewType: "final",
|
|
998
|
-
honorSource: honoredFinal.source,
|
|
999
|
-
reviewAttempt: finalAttempt,
|
|
1000
|
-
});
|
|
1001
|
-
appendReviewHonorJournalEvents({
|
|
1002
|
-
projectRoot,
|
|
1003
|
-
batchId,
|
|
1004
|
-
task,
|
|
1005
|
-
lane,
|
|
1006
|
-
laneCorrelationId,
|
|
1007
|
-
reviewType: "final",
|
|
1008
|
-
reviewAttempt: finalAttempt,
|
|
1009
|
-
honored: honoredFinal,
|
|
1010
|
-
honorJournalEvent,
|
|
1011
|
-
});
|
|
1012
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
1013
|
-
taskId,
|
|
1014
|
-
laneNumber,
|
|
1015
|
-
laneId: lane.laneId,
|
|
1016
|
-
correlationId: laneCorrelationId,
|
|
1017
|
-
reviewType: "final",
|
|
1018
|
-
verdict: "PASS",
|
|
1019
|
-
feedback: honoredFinal.feedback,
|
|
1020
|
-
artifactPath: honoredFinal.artifactPath,
|
|
1021
|
-
finalAttempt: finalAttempt + 1,
|
|
1022
|
-
honored: true,
|
|
1023
|
-
honorSource: honoredFinal.source,
|
|
1024
|
-
reviewPassKind: resolveReviewPassKind(honorJournalEvent),
|
|
1025
|
-
});
|
|
1026
|
-
task.finalAttempts = finalAttempt + 1;
|
|
1027
|
-
saveSpineBatchState(projectRoot, state);
|
|
1028
|
-
return { ok: true, verdict: "PASS", finalAttempt: finalAttempt + 1, honored: true };
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
const journal = {
|
|
1032
|
-
projectRoot,
|
|
1033
|
-
batchId,
|
|
1034
|
-
taskId,
|
|
1035
|
-
laneNumber,
|
|
1036
|
-
correlationId: laneCorrelationId,
|
|
1037
|
-
};
|
|
1038
|
-
|
|
1039
|
-
let reviewResumedEmitted = false;
|
|
1040
|
-
|
|
1041
|
-
while (true) {
|
|
1042
|
-
if (
|
|
1043
|
-
!reviewResumedEmitted &&
|
|
1044
|
-
shouldEmitReviewResumed({ journalEvents, taskId })
|
|
1045
|
-
) {
|
|
1046
|
-
appendJournalEvent(projectRoot, batchId, "review.resumed", {
|
|
1047
|
-
taskId,
|
|
1048
|
-
laneNumber,
|
|
1049
|
-
laneId: lane.laneId,
|
|
1050
|
-
correlationId: laneCorrelationId,
|
|
1051
|
-
reviewType: "final",
|
|
1052
|
-
finalAttempt: finalAttempt + 1,
|
|
1053
|
-
});
|
|
1054
|
-
reviewResumedEmitted = true;
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
let contractVerifyResult = null;
|
|
1058
|
-
const promptMarkdown = fs.readFileSync(path.join(taskFolderInWorktree, "PROMPT.md"), "utf-8");
|
|
1059
|
-
const parsedContract = parseContract(promptMarkdown);
|
|
1060
|
-
if (shouldRunContractVerifyForWorker(promptMarkdown, parsedContract, config)) {
|
|
1061
|
-
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
1062
|
-
const sinceCommit = resolveTaskStartCommit({
|
|
1063
|
-
journal: journalEvents,
|
|
1064
|
-
taskId,
|
|
1065
|
-
laneId: lane.laneId,
|
|
1066
|
-
batchId,
|
|
1067
|
-
worktreePath: wt,
|
|
1068
|
-
});
|
|
1069
|
-
contractVerifyResult = verifyContract(wt, parsedContract, {
|
|
1070
|
-
...config,
|
|
1071
|
-
baseBranch,
|
|
1072
|
-
sinceCommit: sinceCommit ?? undefined,
|
|
1073
|
-
projectRoot,
|
|
1074
|
-
batchId,
|
|
1075
|
-
taskId,
|
|
1076
|
-
taskFolder: taskFolderInWorktree,
|
|
1077
|
-
});
|
|
1078
|
-
task.contractOk = contractVerifyResult.ok;
|
|
1079
|
-
saveSpineBatchState(projectRoot, state);
|
|
1080
|
-
appendJournalEvent(projectRoot, batchId, "contract.verified", {
|
|
1081
|
-
taskId,
|
|
1082
|
-
laneNumber,
|
|
1083
|
-
laneId: lane.laneId,
|
|
1084
|
-
correlationId: laneCorrelationId,
|
|
1085
|
-
ok: contractVerifyResult.ok,
|
|
1086
|
-
checks: contractVerifyResult.checks,
|
|
1087
|
-
});
|
|
1088
|
-
if (!contractVerifyResult.ok) {
|
|
1089
|
-
removeDoneFile(taskFolderInWorktree);
|
|
1090
|
-
recordContractVerifyTaskFailure({
|
|
1091
|
-
projectRoot,
|
|
1092
|
-
state,
|
|
1093
|
-
batchId,
|
|
1094
|
-
task,
|
|
1095
|
-
lane,
|
|
1096
|
-
laneCorrelationId,
|
|
1097
|
-
contractVerifyResult,
|
|
1098
|
-
config,
|
|
1099
|
-
taskFolder: taskFolderInWorktree,
|
|
1100
|
-
});
|
|
1101
|
-
return { ok: false, exitReason: "contract_failed", verdict: "CONTRACT_FAIL" };
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
const reviewResult = await runEngineFinalReview({
|
|
1106
|
-
taskFolder: taskFolderInWorktree,
|
|
1107
|
-
worktreePath: wt,
|
|
1108
|
-
config,
|
|
1109
|
-
attempt: finalAttempt + 1,
|
|
1110
|
-
contractVerifyResult,
|
|
1111
|
-
journal,
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
|
-
if (reviewResult.spawnFailed) {
|
|
1115
|
-
const spawnExitReason =
|
|
1116
|
-
reviewResult.reason === REVIEW_TIMEOUT_REASON
|
|
1117
|
-
? "final_review_timeout"
|
|
1118
|
-
: "final_review_spawn_failed";
|
|
1119
|
-
recordFinalReviewTaskFailure({
|
|
1120
|
-
projectRoot,
|
|
1121
|
-
state,
|
|
1122
|
-
batchId,
|
|
1123
|
-
task,
|
|
1124
|
-
lane,
|
|
1125
|
-
laneCorrelationId,
|
|
1126
|
-
exitReason: spawnExitReason,
|
|
1127
|
-
verdict: null,
|
|
1128
|
-
finalAttempt,
|
|
1129
|
-
config,
|
|
1130
|
-
taskFolder: taskFolderInWorktree,
|
|
1131
|
-
});
|
|
1132
|
-
return {
|
|
1133
|
-
ok: false,
|
|
1134
|
-
error: spawnExitReason,
|
|
1135
|
-
output: reviewResult.error ?? "final review spawn failed",
|
|
1136
|
-
};
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
if (reviewResult.skipped) {
|
|
1140
|
-
return { ok: true, skipped: true };
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
1144
|
-
taskId,
|
|
1145
|
-
laneNumber,
|
|
1146
|
-
laneId: lane.laneId,
|
|
1147
|
-
correlationId: laneCorrelationId,
|
|
1148
|
-
reviewType: "final",
|
|
1149
|
-
verdict: reviewResult.verdict,
|
|
1150
|
-
feedback: reviewResult.feedback,
|
|
1151
|
-
artifactPath: reviewResult.artifactPath,
|
|
1152
|
-
finalAttempt: finalAttempt + 1,
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
if (reviewResult.verdict === "PASS") {
|
|
1156
|
-
task.finalAttempts = finalAttempt + 1;
|
|
1157
|
-
saveSpineBatchState(projectRoot, state);
|
|
1158
|
-
return { ok: true, verdict: "PASS", finalAttempt: finalAttempt + 1 };
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
if (reviewResult.verdict === "REPLAN") {
|
|
1162
|
-
removeDoneFile(taskFolderInWorktree);
|
|
1163
|
-
task.finalAttempts = finalAttempt + 1;
|
|
1164
|
-
recordFinalReviewTaskFailure({
|
|
1165
|
-
projectRoot,
|
|
1166
|
-
state,
|
|
1167
|
-
batchId,
|
|
1168
|
-
task,
|
|
1169
|
-
lane,
|
|
1170
|
-
laneCorrelationId,
|
|
1171
|
-
exitReason: "needs_replan",
|
|
1172
|
-
verdict: "REPLAN",
|
|
1173
|
-
finalAttempt: finalAttempt + 1,
|
|
1174
|
-
config,
|
|
1175
|
-
taskFolder: taskFolderInWorktree,
|
|
1176
|
-
});
|
|
1177
|
-
return { ok: false, exitReason: "needs_replan", verdict: "REPLAN" };
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
if (reviewResult.verdict === "REVISE") {
|
|
1181
|
-
finalAttempt++;
|
|
1182
|
-
task.finalAttempts = finalAttempt;
|
|
1183
|
-
saveSpineBatchState(projectRoot, state);
|
|
1184
|
-
|
|
1185
|
-
if (finalAttempt >= maxFinalAttempts) {
|
|
1186
|
-
removeDoneFile(taskFolderInWorktree);
|
|
1187
|
-
appendJournalEvent(projectRoot, batchId, "review.exhausted", {
|
|
1188
|
-
taskId,
|
|
1189
|
-
laneNumber,
|
|
1190
|
-
laneId: lane.laneId,
|
|
1191
|
-
correlationId: laneCorrelationId,
|
|
1192
|
-
finalAttempt,
|
|
1193
|
-
maxFinalAttempts,
|
|
1194
|
-
});
|
|
1195
|
-
recordFinalReviewTaskFailure({
|
|
1196
|
-
projectRoot,
|
|
1197
|
-
state,
|
|
1198
|
-
batchId,
|
|
1199
|
-
task,
|
|
1200
|
-
lane,
|
|
1201
|
-
laneCorrelationId,
|
|
1202
|
-
exitReason: "review_exhausted",
|
|
1203
|
-
verdict: "REVISE",
|
|
1204
|
-
finalAttempt,
|
|
1205
|
-
config,
|
|
1206
|
-
taskFolder: taskFolderInWorktree,
|
|
1207
|
-
});
|
|
1208
|
-
return { ok: false, exitReason: "review_exhausted", verdict: "REVISE" };
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
removeDoneFile(taskFolderInWorktree);
|
|
1212
|
-
const reworkResult = await runWorker({
|
|
1213
|
-
worktreePath: wt,
|
|
1214
|
-
taskFolder: taskFolderInWorktree,
|
|
1215
|
-
projectRoot,
|
|
1216
|
-
batchId,
|
|
1217
|
-
laneNumber,
|
|
1218
|
-
taskId,
|
|
1219
|
-
laneBranch: taskBranch,
|
|
1220
|
-
laneCorrelationId,
|
|
1221
|
-
fileScopePaths,
|
|
1222
|
-
config,
|
|
1223
|
-
onHeartbeat: (timestamp) => {
|
|
1224
|
-
lane.lastHeartbeatAt = timestamp;
|
|
1225
|
-
saveSpineBatchState(projectRoot, state);
|
|
1226
|
-
},
|
|
1227
|
-
onWorkerPid: (pid) => {
|
|
1228
|
-
if (pid > 0) {
|
|
1229
|
-
lane.workerPid = pid;
|
|
1230
|
-
saveSpineBatchState(projectRoot, state);
|
|
1231
|
-
}
|
|
1232
|
-
},
|
|
1233
|
-
});
|
|
1234
|
-
if (!reworkResult.ok) {
|
|
1235
|
-
const aborted = reworkResult.classification === "aborted";
|
|
1236
|
-
task.status = aborted ? "aborted" : "failed";
|
|
1237
|
-
task.endedAt = Date.now();
|
|
1238
|
-
task.exitReason = reworkResult.classification ?? "worker_failed";
|
|
1239
|
-
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
1240
|
-
recomputeTaskCounters(state);
|
|
1241
|
-
saveSpineBatchState(projectRoot, state);
|
|
1242
|
-
recordLaneTaskMetric({
|
|
1243
|
-
projectRoot,
|
|
1244
|
-
batchId,
|
|
1245
|
-
task,
|
|
1246
|
-
config,
|
|
1247
|
-
taskFolder: taskFolderInWorktree,
|
|
1248
|
-
});
|
|
1249
|
-
return { ok: false, aborted, workerResult: reworkResult };
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
1253
|
-
laneNumber,
|
|
1254
|
-
laneId: lane.laneId,
|
|
1255
|
-
taskId,
|
|
1256
|
-
correlationId: laneCorrelationId,
|
|
1257
|
-
phase: "final_rework",
|
|
1258
|
-
});
|
|
1259
|
-
continue;
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
recordFinalReviewTaskFailure({
|
|
1263
|
-
projectRoot,
|
|
1264
|
-
state,
|
|
1265
|
-
batchId,
|
|
1266
|
-
task,
|
|
1267
|
-
lane,
|
|
1268
|
-
laneCorrelationId,
|
|
1269
|
-
exitReason: "final_review_invalid_verdict",
|
|
1270
|
-
verdict: reviewResult.verdict,
|
|
1271
|
-
finalAttempt,
|
|
1272
|
-
config,
|
|
1273
|
-
taskFolder: taskFolderInWorktree,
|
|
1274
|
-
});
|
|
1275
|
-
return {
|
|
1276
|
-
ok: false,
|
|
1277
|
-
error: "final_review_invalid_verdict",
|
|
1278
|
-
output: "final review artifact missing PASS, REVISE, or REPLAN verdict",
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* Engine-owned plan review phase after worker success (SP-695 / #250).
|
|
1285
|
-
* Mirrors runCodeReviewPhase: RL gate (plan required for RL≥1), honor of an
|
|
1286
|
-
* existing plan artifact/journal verdict, rework loop on REVISE, fail-closed
|
|
1287
|
-
* on exhaustion or invalid verdict.
|
|
1288
|
-
*
|
|
1289
|
-
* @param {object} params
|
|
1290
|
-
*/
|
|
1291
|
-
async function runPlanReviewPhase({
|
|
1292
|
-
projectRoot,
|
|
1293
|
-
state,
|
|
1294
|
-
batchId,
|
|
1295
|
-
config,
|
|
1296
|
-
task,
|
|
1297
|
-
lane,
|
|
1298
|
-
taskFolderInWorktree,
|
|
1299
|
-
wt,
|
|
1300
|
-
taskBranch,
|
|
1301
|
-
laneCorrelationId,
|
|
1302
|
-
fileScopePaths,
|
|
1303
|
-
}) {
|
|
1304
|
-
const taskId = task.taskId;
|
|
1305
|
-
const laneNumber = lane.laneNumber;
|
|
1306
|
-
const reviewLevel = readReviewLevel(taskFolderInWorktree);
|
|
1307
|
-
if (!isReviewTypeRequired(reviewLevel, "plan")) {
|
|
1308
|
-
return { ok: true, skipped: true };
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
const maxPlanReviewAttempts = config?.review?.maxFinalAttempts ?? REVIEW_DEFAULTS.maxFinalAttempts;
|
|
1312
|
-
let planReviewAttempt = task.planReviewAttempts ?? 0;
|
|
1313
|
-
|
|
1314
|
-
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
1315
|
-
const honored = findCompletedPlanReview({
|
|
1316
|
-
taskFolder: taskFolderInWorktree,
|
|
1317
|
-
journalEvents,
|
|
1318
|
-
taskId,
|
|
1319
|
-
});
|
|
1320
|
-
if (honored?.verdict === "APPROVE") {
|
|
1321
|
-
const honorJournalEvent = resolveReviewHonorJournalEvent({
|
|
1322
|
-
journalEvents,
|
|
1323
|
-
taskId,
|
|
1324
|
-
reviewType: "plan",
|
|
1325
|
-
honorSource: honored.source,
|
|
1326
|
-
reviewAttempt: planReviewAttempt,
|
|
1327
|
-
});
|
|
1328
|
-
appendReviewHonorJournalEvents({
|
|
1329
|
-
projectRoot,
|
|
1330
|
-
batchId,
|
|
1331
|
-
task,
|
|
1332
|
-
lane,
|
|
1333
|
-
laneCorrelationId,
|
|
1334
|
-
reviewType: "plan",
|
|
1335
|
-
reviewAttempt: planReviewAttempt,
|
|
1336
|
-
honored,
|
|
1337
|
-
honorJournalEvent,
|
|
1338
|
-
});
|
|
1339
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
1340
|
-
taskId,
|
|
1341
|
-
laneNumber,
|
|
1342
|
-
laneId: lane.laneId,
|
|
1343
|
-
correlationId: laneCorrelationId,
|
|
1344
|
-
reviewType: "plan",
|
|
1345
|
-
verdict: "APPROVE",
|
|
1346
|
-
feedback: honored.feedback,
|
|
1347
|
-
artifactPath: honored.artifactPath,
|
|
1348
|
-
planReviewAttempt: planReviewAttempt + 1,
|
|
1349
|
-
honored: true,
|
|
1350
|
-
honorSource: honored.source,
|
|
1351
|
-
reviewPassKind: resolveReviewPassKind(honorJournalEvent),
|
|
1352
|
-
});
|
|
1353
|
-
task.planReviewAttempts = planReviewAttempt + 1;
|
|
1354
|
-
saveSpineBatchState(projectRoot, state);
|
|
1355
|
-
return { ok: true, verdict: "APPROVE", planReviewAttempt: planReviewAttempt + 1, honored: true };
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
const journal = {
|
|
1359
|
-
projectRoot,
|
|
1360
|
-
batchId,
|
|
1361
|
-
taskId,
|
|
1362
|
-
laneNumber,
|
|
1363
|
-
correlationId: laneCorrelationId,
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
|
-
let reviewResumedEmitted = false;
|
|
1367
|
-
|
|
1368
|
-
while (true) {
|
|
1369
|
-
if (
|
|
1370
|
-
!reviewResumedEmitted &&
|
|
1371
|
-
shouldEmitReviewResumed({ journalEvents, taskId })
|
|
1372
|
-
) {
|
|
1373
|
-
appendJournalEvent(projectRoot, batchId, "review.resumed", {
|
|
1374
|
-
taskId,
|
|
1375
|
-
laneNumber,
|
|
1376
|
-
laneId: lane.laneId,
|
|
1377
|
-
correlationId: laneCorrelationId,
|
|
1378
|
-
reviewType: "plan",
|
|
1379
|
-
planReviewAttempt: planReviewAttempt + 1,
|
|
1380
|
-
});
|
|
1381
|
-
reviewResumedEmitted = true;
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
const reviewResult = await runEnginePlanReview({
|
|
1385
|
-
taskFolder: taskFolderInWorktree,
|
|
1386
|
-
worktreePath: wt,
|
|
1387
|
-
config,
|
|
1388
|
-
attempt: planReviewAttempt + 1,
|
|
1389
|
-
journal,
|
|
1390
|
-
});
|
|
1391
|
-
|
|
1392
|
-
if (reviewResult.spawnFailed) {
|
|
1393
|
-
const spawnExitReason =
|
|
1394
|
-
reviewResult.reason === REVIEW_TIMEOUT_REASON
|
|
1395
|
-
? "plan_review_timeout"
|
|
1396
|
-
: "plan_review_spawn_failed";
|
|
1397
|
-
recordPlanReviewTaskFailure({
|
|
1398
|
-
projectRoot,
|
|
1399
|
-
state,
|
|
1400
|
-
batchId,
|
|
1401
|
-
task,
|
|
1402
|
-
lane,
|
|
1403
|
-
laneCorrelationId,
|
|
1404
|
-
exitReason: spawnExitReason,
|
|
1405
|
-
verdict: null,
|
|
1406
|
-
planReviewAttempt,
|
|
1407
|
-
config,
|
|
1408
|
-
taskFolder: taskFolderInWorktree,
|
|
1409
|
-
});
|
|
1410
|
-
return {
|
|
1411
|
-
ok: false,
|
|
1412
|
-
error: spawnExitReason,
|
|
1413
|
-
output: reviewResult.error ?? "plan review spawn failed",
|
|
1414
|
-
};
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
if (reviewResult.skipped) {
|
|
1418
|
-
return { ok: true, skipped: true };
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
1422
|
-
taskId,
|
|
1423
|
-
laneNumber,
|
|
1424
|
-
laneId: lane.laneId,
|
|
1425
|
-
correlationId: laneCorrelationId,
|
|
1426
|
-
reviewType: "plan",
|
|
1427
|
-
verdict: reviewResult.verdict,
|
|
1428
|
-
feedback: reviewResult.feedback,
|
|
1429
|
-
artifactPath: reviewResult.artifactPath,
|
|
1430
|
-
planReviewAttempt: planReviewAttempt + 1,
|
|
1431
|
-
});
|
|
1432
|
-
|
|
1433
|
-
if (reviewResult.verdict === "APPROVE") {
|
|
1434
|
-
task.planReviewAttempts = planReviewAttempt + 1;
|
|
1435
|
-
saveSpineBatchState(projectRoot, state);
|
|
1436
|
-
return { ok: true, verdict: "APPROVE", planReviewAttempt: planReviewAttempt + 1 };
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
if (reviewResult.verdict === "REVISE") {
|
|
1440
|
-
planReviewAttempt++;
|
|
1441
|
-
task.planReviewAttempts = planReviewAttempt;
|
|
1442
|
-
saveSpineBatchState(projectRoot, state);
|
|
1443
|
-
|
|
1444
|
-
if (planReviewAttempt >= maxPlanReviewAttempts) {
|
|
1445
|
-
removeDoneFile(taskFolderInWorktree);
|
|
1446
|
-
appendJournalEvent(projectRoot, batchId, "review.exhausted", {
|
|
1447
|
-
taskId,
|
|
1448
|
-
laneNumber,
|
|
1449
|
-
laneId: lane.laneId,
|
|
1450
|
-
correlationId: laneCorrelationId,
|
|
1451
|
-
planReviewAttempt,
|
|
1452
|
-
maxPlanReviewAttempts,
|
|
1453
|
-
reviewType: "plan",
|
|
1454
|
-
});
|
|
1455
|
-
recordPlanReviewTaskFailure({
|
|
1456
|
-
projectRoot,
|
|
1457
|
-
state,
|
|
1458
|
-
batchId,
|
|
1459
|
-
task,
|
|
1460
|
-
lane,
|
|
1461
|
-
laneCorrelationId,
|
|
1462
|
-
exitReason: "review_exhausted",
|
|
1463
|
-
verdict: "REVISE",
|
|
1464
|
-
planReviewAttempt,
|
|
1465
|
-
config,
|
|
1466
|
-
taskFolder: taskFolderInWorktree,
|
|
1467
|
-
});
|
|
1468
|
-
return { ok: false, exitReason: "review_exhausted", verdict: "REVISE" };
|
|
1469
|
-
}
|
|
1470
|
-
|
|
1471
|
-
removeDoneFile(taskFolderInWorktree);
|
|
1472
|
-
const reworkResult = await runWorker({
|
|
1473
|
-
worktreePath: wt,
|
|
1474
|
-
taskFolder: taskFolderInWorktree,
|
|
1475
|
-
projectRoot,
|
|
1476
|
-
batchId,
|
|
1477
|
-
laneNumber,
|
|
1478
|
-
taskId,
|
|
1479
|
-
laneBranch: taskBranch,
|
|
1480
|
-
laneCorrelationId,
|
|
1481
|
-
fileScopePaths,
|
|
1482
|
-
config,
|
|
1483
|
-
onHeartbeat: (timestamp) => {
|
|
1484
|
-
lane.lastHeartbeatAt = timestamp;
|
|
1485
|
-
saveSpineBatchState(projectRoot, state);
|
|
1486
|
-
},
|
|
1487
|
-
onWorkerPid: (pid) => {
|
|
1488
|
-
if (pid > 0) {
|
|
1489
|
-
lane.workerPid = pid;
|
|
1490
|
-
saveSpineBatchState(projectRoot, state);
|
|
1491
|
-
}
|
|
1492
|
-
},
|
|
1493
|
-
});
|
|
1494
|
-
if (!reworkResult.ok) {
|
|
1495
|
-
const aborted = reworkResult.classification === "aborted";
|
|
1496
|
-
task.status = aborted ? "aborted" : "failed";
|
|
1497
|
-
task.endedAt = Date.now();
|
|
1498
|
-
task.exitReason = reworkResult.classification ?? "worker_failed";
|
|
1499
|
-
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
1500
|
-
recomputeTaskCounters(state);
|
|
1501
|
-
saveSpineBatchState(projectRoot, state);
|
|
1502
|
-
recordLaneTaskMetric({
|
|
1503
|
-
projectRoot,
|
|
1504
|
-
batchId,
|
|
1505
|
-
task,
|
|
1506
|
-
config,
|
|
1507
|
-
taskFolder: taskFolderInWorktree,
|
|
1508
|
-
});
|
|
1509
|
-
return { ok: false, aborted, workerResult: reworkResult };
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
1513
|
-
laneNumber,
|
|
1514
|
-
laneId: lane.laneId,
|
|
1515
|
-
taskId,
|
|
1516
|
-
correlationId: laneCorrelationId,
|
|
1517
|
-
phase: "plan_rework",
|
|
1518
|
-
});
|
|
1519
|
-
continue;
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
recordPlanReviewTaskFailure({
|
|
1523
|
-
projectRoot,
|
|
1524
|
-
state,
|
|
1525
|
-
batchId,
|
|
1526
|
-
task,
|
|
1527
|
-
lane,
|
|
1528
|
-
laneCorrelationId,
|
|
1529
|
-
exitReason: "plan_review_invalid_verdict",
|
|
1530
|
-
verdict: reviewResult.verdict,
|
|
1531
|
-
planReviewAttempt,
|
|
1532
|
-
config,
|
|
1533
|
-
taskFolder: taskFolderInWorktree,
|
|
1534
|
-
});
|
|
1535
|
-
return {
|
|
1536
|
-
ok: false,
|
|
1537
|
-
error: "plan_review_invalid_verdict",
|
|
1538
|
-
output: "plan review artifact missing APPROVE or REVISE verdict",
|
|
1539
|
-
};
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
export { runCodeReviewPhase, runFinalReviewPhase, runPlanReviewPhase };
|
|
13
|
+
export { runEngineCodeReview, runCodeReviewPhase } from "./review-code.mjs";
|
|
14
|
+
export { runEngineFinalReview, runFinalReviewPhase } from "./review-final.mjs";
|
|
15
|
+
export { runEnginePlanReview, runPlanReviewPhase } from "./review-plan.mjs";
|