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
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Engine lane final review phase (SP-729 / #262).
|
|
4
|
+
*/
|
|
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 {
|
|
20
|
+
buildFinalReviewArtifactPath,
|
|
21
|
+
shouldRunFinalReview,
|
|
22
|
+
} from "../review-shared.mjs";
|
|
23
|
+
import {
|
|
24
|
+
findCompletedFinalReview,
|
|
25
|
+
findFinalReviewStepNumber,
|
|
26
|
+
readReviewLevel,
|
|
27
|
+
runStepReview,
|
|
28
|
+
} from "../review.mjs";
|
|
29
|
+
import {
|
|
30
|
+
honorCompletedReview,
|
|
31
|
+
removeDoneFile,
|
|
32
|
+
runReviewPollLoop,
|
|
33
|
+
} from "./review-poll.mjs";
|
|
34
|
+
import {
|
|
35
|
+
createPhaseStubVerdictQueue,
|
|
36
|
+
shouldUseReviewStub,
|
|
37
|
+
writeStubReviewArtifact,
|
|
38
|
+
} from "./review-stub.mjs";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {object} params
|
|
42
|
+
*/
|
|
43
|
+
export async function runEngineFinalReview({
|
|
44
|
+
taskFolder,
|
|
45
|
+
worktreePath,
|
|
46
|
+
config = {},
|
|
47
|
+
attempt = 1,
|
|
48
|
+
contractVerifyResult = null,
|
|
49
|
+
journal,
|
|
50
|
+
stubVerdicts = null,
|
|
51
|
+
}) {
|
|
52
|
+
const reviewLevel = readReviewLevel(taskFolder);
|
|
53
|
+
if (!shouldRunFinalReview({ config, reviewLevel })) {
|
|
54
|
+
return {
|
|
55
|
+
ok: true,
|
|
56
|
+
skipped: true,
|
|
57
|
+
reviewLevel,
|
|
58
|
+
verdict: null,
|
|
59
|
+
feedback: "",
|
|
60
|
+
artifactPath: "",
|
|
61
|
+
spawnFailed: false,
|
|
62
|
+
exitCode: 0,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const artifactPath = buildFinalReviewArtifactPath(taskFolder);
|
|
67
|
+
const useStub = shouldUseReviewStub();
|
|
68
|
+
|
|
69
|
+
if (useStub) {
|
|
70
|
+
const queue = stubVerdicts ?? createPhaseStubVerdictQueue("final");
|
|
71
|
+
const verdict = queue.next();
|
|
72
|
+
const feedback =
|
|
73
|
+
verdict === "REVISE"
|
|
74
|
+
? "Stub reviewer requested changes."
|
|
75
|
+
: verdict === "REPLAN"
|
|
76
|
+
? "Stub reviewer requested replan."
|
|
77
|
+
: "Stub reviewer passed.";
|
|
78
|
+
writeStubReviewArtifact({ artifactPath, title: "Final Review", verdict, feedback });
|
|
79
|
+
return {
|
|
80
|
+
ok: verdict === "PASS",
|
|
81
|
+
skipped: false,
|
|
82
|
+
reviewLevel,
|
|
83
|
+
verdict,
|
|
84
|
+
feedback,
|
|
85
|
+
artifactPath,
|
|
86
|
+
spawnFailed: false,
|
|
87
|
+
exitCode: verdict === "PASS" ? 0 : 2,
|
|
88
|
+
attempt,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const stepNumber = findFinalReviewStepNumber(taskFolder);
|
|
93
|
+
return await runStepReview({
|
|
94
|
+
taskFolder,
|
|
95
|
+
worktreePath,
|
|
96
|
+
stepNumber,
|
|
97
|
+
reviewType: "final",
|
|
98
|
+
config,
|
|
99
|
+
journal,
|
|
100
|
+
contractVerifyResult,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {object} params
|
|
106
|
+
*/
|
|
107
|
+
function recordContractVerifyTaskFailure({
|
|
108
|
+
projectRoot,
|
|
109
|
+
state,
|
|
110
|
+
batchId,
|
|
111
|
+
task,
|
|
112
|
+
lane,
|
|
113
|
+
laneCorrelationId,
|
|
114
|
+
contractVerifyResult,
|
|
115
|
+
config,
|
|
116
|
+
taskFolder,
|
|
117
|
+
}) {
|
|
118
|
+
const taskId = task.taskId;
|
|
119
|
+
const laneNumber = lane.laneNumber;
|
|
120
|
+
task.status = "failed";
|
|
121
|
+
task.endedAt = Date.now();
|
|
122
|
+
task.exitReason = "contract_failed";
|
|
123
|
+
task.contractOk = false;
|
|
124
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
125
|
+
recomputeTaskCounters(state);
|
|
126
|
+
saveSpineBatchState(projectRoot, state);
|
|
127
|
+
appendJournalEvent(projectRoot, batchId, "contract.failed", {
|
|
128
|
+
taskId,
|
|
129
|
+
laneNumber,
|
|
130
|
+
laneId: lane.laneId,
|
|
131
|
+
correlationId: laneCorrelationId,
|
|
132
|
+
checks: contractVerifyResult?.checks ?? [],
|
|
133
|
+
});
|
|
134
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
135
|
+
taskId,
|
|
136
|
+
laneNumber,
|
|
137
|
+
laneId: lane.laneId,
|
|
138
|
+
correlationId: laneCorrelationId,
|
|
139
|
+
classification: "contract_failed",
|
|
140
|
+
exitCode: 1,
|
|
141
|
+
contractOk: false,
|
|
142
|
+
failureKind: "contract",
|
|
143
|
+
});
|
|
144
|
+
recordLaneTaskMetric({
|
|
145
|
+
projectRoot,
|
|
146
|
+
batchId,
|
|
147
|
+
task,
|
|
148
|
+
config,
|
|
149
|
+
taskFolder,
|
|
150
|
+
lane,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {object} params
|
|
156
|
+
*/
|
|
157
|
+
function recordFinalReviewTaskFailure({
|
|
158
|
+
projectRoot,
|
|
159
|
+
state,
|
|
160
|
+
batchId,
|
|
161
|
+
task,
|
|
162
|
+
lane,
|
|
163
|
+
laneCorrelationId,
|
|
164
|
+
exitReason,
|
|
165
|
+
verdict,
|
|
166
|
+
finalAttempt,
|
|
167
|
+
config,
|
|
168
|
+
taskFolder,
|
|
169
|
+
}) {
|
|
170
|
+
const taskId = task.taskId;
|
|
171
|
+
const laneNumber = lane.laneNumber;
|
|
172
|
+
task.status = "failed";
|
|
173
|
+
task.endedAt = Date.now();
|
|
174
|
+
task.exitReason = exitReason;
|
|
175
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
176
|
+
recomputeTaskCounters(state);
|
|
177
|
+
saveSpineBatchState(projectRoot, state);
|
|
178
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
179
|
+
taskId,
|
|
180
|
+
laneNumber,
|
|
181
|
+
laneId: lane.laneId,
|
|
182
|
+
correlationId: laneCorrelationId,
|
|
183
|
+
classification: exitReason,
|
|
184
|
+
exitCode: 1,
|
|
185
|
+
finalVerdict: verdict ?? null,
|
|
186
|
+
finalAttempt,
|
|
187
|
+
});
|
|
188
|
+
recordLaneTaskMetric({
|
|
189
|
+
projectRoot,
|
|
190
|
+
batchId,
|
|
191
|
+
task,
|
|
192
|
+
config,
|
|
193
|
+
taskFolder,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @param {object} params
|
|
199
|
+
*/
|
|
200
|
+
export async function runFinalReviewPhase({
|
|
201
|
+
projectRoot,
|
|
202
|
+
state,
|
|
203
|
+
batchId,
|
|
204
|
+
config,
|
|
205
|
+
task,
|
|
206
|
+
lane,
|
|
207
|
+
taskFolderInWorktree,
|
|
208
|
+
wt,
|
|
209
|
+
taskBranch,
|
|
210
|
+
laneCorrelationId,
|
|
211
|
+
fileScopePaths,
|
|
212
|
+
baseBranch = "main",
|
|
213
|
+
}) {
|
|
214
|
+
const taskId = task.taskId;
|
|
215
|
+
const laneNumber = lane.laneNumber;
|
|
216
|
+
const reviewLevel = readReviewLevel(taskFolderInWorktree);
|
|
217
|
+
if (!shouldRunFinalReview({ config, reviewLevel })) {
|
|
218
|
+
return { ok: true, skipped: true };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const maxFinalAttempts = config?.review?.maxFinalAttempts ?? REVIEW_DEFAULTS.maxFinalAttempts;
|
|
222
|
+
|
|
223
|
+
// Materialize the stub queue once per phase and pass it via params so
|
|
224
|
+
// parallel lanes never share or mutate process.env stub state (SP-728).
|
|
225
|
+
const stubVerdicts = shouldUseReviewStub() ? createPhaseStubVerdictQueue("final") : null;
|
|
226
|
+
|
|
227
|
+
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
228
|
+
const honoredResult = honorCompletedReview({
|
|
229
|
+
reviewType: "final",
|
|
230
|
+
passVerdict: "PASS",
|
|
231
|
+
attemptField: "finalAttempts",
|
|
232
|
+
attemptKey: "finalAttempt",
|
|
233
|
+
findCompletedReview: findCompletedFinalReview,
|
|
234
|
+
projectRoot,
|
|
235
|
+
state,
|
|
236
|
+
batchId,
|
|
237
|
+
task,
|
|
238
|
+
lane,
|
|
239
|
+
laneCorrelationId,
|
|
240
|
+
taskFolder: taskFolderInWorktree,
|
|
241
|
+
journalEvents,
|
|
242
|
+
});
|
|
243
|
+
if (honoredResult) return honoredResult;
|
|
244
|
+
|
|
245
|
+
return await runReviewPollLoop({
|
|
246
|
+
reviewType: "final",
|
|
247
|
+
passVerdict: "PASS",
|
|
248
|
+
attemptField: "finalAttempts",
|
|
249
|
+
attemptKey: "finalAttempt",
|
|
250
|
+
maxAttempts: maxFinalAttempts,
|
|
251
|
+
runEngineReview: (params) => runEngineFinalReview({ ...params, stubVerdicts }),
|
|
252
|
+
recordReviewTaskFailure: recordFinalReviewTaskFailure,
|
|
253
|
+
invalidVerdictOutput: "final review artifact missing PASS, REVISE, or REPLAN verdict",
|
|
254
|
+
allowReplan: true,
|
|
255
|
+
beforeReview: async () => {
|
|
256
|
+
let contractVerifyResult = null;
|
|
257
|
+
const promptMarkdown = fs.readFileSync(path.join(taskFolderInWorktree, "PROMPT.md"), "utf-8");
|
|
258
|
+
const parsedContract = parseContract(promptMarkdown);
|
|
259
|
+
if (shouldRunContractVerifyForWorker(promptMarkdown, parsedContract, config)) {
|
|
260
|
+
const events = readJournalEvents(projectRoot, batchId);
|
|
261
|
+
const sinceCommit = resolveTaskStartCommit({
|
|
262
|
+
journal: events,
|
|
263
|
+
taskId,
|
|
264
|
+
laneId: lane.laneId,
|
|
265
|
+
batchId,
|
|
266
|
+
worktreePath: wt,
|
|
267
|
+
});
|
|
268
|
+
contractVerifyResult = verifyContract(wt, parsedContract, {
|
|
269
|
+
...config,
|
|
270
|
+
baseBranch,
|
|
271
|
+
sinceCommit: sinceCommit ?? undefined,
|
|
272
|
+
projectRoot,
|
|
273
|
+
batchId,
|
|
274
|
+
taskId,
|
|
275
|
+
taskFolder: taskFolderInWorktree,
|
|
276
|
+
});
|
|
277
|
+
task.contractOk = contractVerifyResult.ok;
|
|
278
|
+
saveSpineBatchState(projectRoot, state);
|
|
279
|
+
appendJournalEvent(projectRoot, batchId, "contract.verified", {
|
|
280
|
+
taskId,
|
|
281
|
+
laneNumber,
|
|
282
|
+
laneId: lane.laneId,
|
|
283
|
+
correlationId: laneCorrelationId,
|
|
284
|
+
ok: contractVerifyResult.ok,
|
|
285
|
+
checks: contractVerifyResult.checks,
|
|
286
|
+
});
|
|
287
|
+
if (!contractVerifyResult.ok) {
|
|
288
|
+
removeDoneFile(taskFolderInWorktree);
|
|
289
|
+
recordContractVerifyTaskFailure({
|
|
290
|
+
projectRoot,
|
|
291
|
+
state,
|
|
292
|
+
batchId,
|
|
293
|
+
task,
|
|
294
|
+
lane,
|
|
295
|
+
laneCorrelationId,
|
|
296
|
+
contractVerifyResult,
|
|
297
|
+
config,
|
|
298
|
+
taskFolder: taskFolderInWorktree,
|
|
299
|
+
});
|
|
300
|
+
return { abort: { ok: false, exitReason: "contract_failed", verdict: "CONTRACT_FAIL" } };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return { extraReviewParams: { contractVerifyResult } };
|
|
304
|
+
},
|
|
305
|
+
journalEvents,
|
|
306
|
+
projectRoot,
|
|
307
|
+
state,
|
|
308
|
+
batchId,
|
|
309
|
+
config,
|
|
310
|
+
task,
|
|
311
|
+
lane,
|
|
312
|
+
taskFolderInWorktree,
|
|
313
|
+
wt,
|
|
314
|
+
taskBranch,
|
|
315
|
+
laneCorrelationId,
|
|
316
|
+
fileScopePaths,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Engine lane plan review phase (SP-730 / #262).
|
|
4
|
+
*/
|
|
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 { appendJournalEvent, readJournalEvents } from "../journal.mjs";
|
|
11
|
+
import {
|
|
12
|
+
recomputeTaskCounters,
|
|
13
|
+
saveSpineBatchState,
|
|
14
|
+
updateSegmentForTask,
|
|
15
|
+
} from "../state.mjs";
|
|
16
|
+
import {
|
|
17
|
+
buildReviewArtifactPath,
|
|
18
|
+
isReviewTypeRequired,
|
|
19
|
+
normalizeCodeVerdict,
|
|
20
|
+
parseReviewVerdict,
|
|
21
|
+
} from "../review-shared.mjs";
|
|
22
|
+
import {
|
|
23
|
+
findLatestStepReviewArtifact,
|
|
24
|
+
readReviewLevel,
|
|
25
|
+
runStepReview,
|
|
26
|
+
} from "../review.mjs";
|
|
27
|
+
import { honorCompletedReview, runReviewPollLoop } from "./review-poll.mjs";
|
|
28
|
+
import {
|
|
29
|
+
createPhaseStubVerdictQueue,
|
|
30
|
+
shouldUseReviewStub,
|
|
31
|
+
writeStubReviewArtifact,
|
|
32
|
+
} from "./review-stub.mjs";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Step number containing a plan review checkpoint marker, else the lowest step.
|
|
36
|
+
* Local mirror of findCodeReviewStepNumber for the engine plan phase (SP-695).
|
|
37
|
+
*
|
|
38
|
+
* @param {string} taskFolder
|
|
39
|
+
*/
|
|
40
|
+
function findPlanReviewStepNumber(taskFolder) {
|
|
41
|
+
const promptPath = path.join(taskFolder, "PROMPT.md");
|
|
42
|
+
if (!fs.existsSync(promptPath)) return 0;
|
|
43
|
+
const content = fs.readFileSync(promptPath, "utf-8");
|
|
44
|
+
const stepBlocks = [...content.matchAll(/###\s+Step\s+(\d+)[:\s][\s\S]*?(?=###\s+Step\s+\d+|$)/g)];
|
|
45
|
+
for (const match of stepBlocks) {
|
|
46
|
+
if (/plan[-\s]review\s+checkpoint/i.test(match[0])) {
|
|
47
|
+
return Number(match[1]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (stepBlocks.length === 0) return 0;
|
|
51
|
+
return Math.min(...stepBlocks.map((match) => Number(match[1])));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Resolve an existing worker or lane plan review from journal and/or artifacts.
|
|
56
|
+
* Mirrors findCompletedCodeReview with reviewType "plan" (SP-695).
|
|
57
|
+
*
|
|
58
|
+
* @param {object} params
|
|
59
|
+
* @param {string} params.taskFolder
|
|
60
|
+
* @param {object[]} [params.journalEvents]
|
|
61
|
+
* @param {string} [params.taskId]
|
|
62
|
+
* @returns {{ verdict: "APPROVE"|"REVISE", feedback: string, artifactPath: string, source: "journal"|"artifact" }|null}
|
|
63
|
+
*/
|
|
64
|
+
function findCompletedPlanReview({ taskFolder, journalEvents = [], taskId }) {
|
|
65
|
+
/** @type {{ verdict: "APPROVE"|"REVISE", feedback: string, artifactPath: string, source: "journal"|"artifact", seq: number }|null} */
|
|
66
|
+
let journalMatch = null;
|
|
67
|
+
for (let index = 0; index < journalEvents.length; index += 1) {
|
|
68
|
+
const event = journalEvents[index];
|
|
69
|
+
if (taskId && event.taskId !== taskId) continue;
|
|
70
|
+
if (event.type !== "review.completed") continue;
|
|
71
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
72
|
+
if (payload.reviewType !== "plan") continue;
|
|
73
|
+
const verdict = normalizeCodeVerdict(payload.verdict);
|
|
74
|
+
if (!verdict) continue;
|
|
75
|
+
journalMatch = {
|
|
76
|
+
verdict,
|
|
77
|
+
feedback: typeof payload.feedback === "string" ? payload.feedback : "",
|
|
78
|
+
artifactPath: typeof payload.artifactPath === "string" ? payload.artifactPath : "",
|
|
79
|
+
source: "journal",
|
|
80
|
+
seq: index,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (journalMatch?.verdict === "APPROVE") {
|
|
85
|
+
const { seq: _seq, ...result } = journalMatch;
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const stepNumber = findPlanReviewStepNumber(taskFolder);
|
|
90
|
+
const latestArtifact = findLatestStepReviewArtifact(taskFolder, stepNumber);
|
|
91
|
+
if (latestArtifact) {
|
|
92
|
+
const reviewContent = fs.readFileSync(latestArtifact.artifactPath, "utf-8");
|
|
93
|
+
const { verdict, feedback } = parseReviewVerdict(reviewContent, { reviewType: "plan" });
|
|
94
|
+
if (verdict) {
|
|
95
|
+
const artifactMatch = {
|
|
96
|
+
verdict,
|
|
97
|
+
feedback,
|
|
98
|
+
artifactPath: latestArtifact.artifactPath,
|
|
99
|
+
source: /** @type {"artifact"} */ ("artifact"),
|
|
100
|
+
};
|
|
101
|
+
if (verdict === "APPROVE") return artifactMatch;
|
|
102
|
+
if (!journalMatch) return artifactMatch;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!journalMatch) return null;
|
|
107
|
+
const { seq: _seq, ...result } = journalMatch;
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Engine-owned plan review — mirror of runEngineCodeReview with reviewType "plan".
|
|
113
|
+
* Uses agents.reviewer.plan pins via runStepReview → buildReviewerPiArgs (SP-695 / #250).
|
|
114
|
+
*
|
|
115
|
+
* @param {object} params
|
|
116
|
+
*/
|
|
117
|
+
export async function runEnginePlanReview({
|
|
118
|
+
taskFolder,
|
|
119
|
+
worktreePath,
|
|
120
|
+
config = {},
|
|
121
|
+
attempt = 1,
|
|
122
|
+
journal,
|
|
123
|
+
stubVerdicts = null,
|
|
124
|
+
}) {
|
|
125
|
+
const reviewLevel = readReviewLevel(taskFolder);
|
|
126
|
+
if (!isReviewTypeRequired(reviewLevel, "plan")) {
|
|
127
|
+
return {
|
|
128
|
+
ok: true,
|
|
129
|
+
skipped: true,
|
|
130
|
+
reviewLevel,
|
|
131
|
+
verdict: null,
|
|
132
|
+
feedback: "",
|
|
133
|
+
artifactPath: "",
|
|
134
|
+
spawnFailed: false,
|
|
135
|
+
exitCode: 0,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const stepNumber = findPlanReviewStepNumber(taskFolder);
|
|
140
|
+
const artifactPath = buildReviewArtifactPath(taskFolder, stepNumber);
|
|
141
|
+
const useStub = shouldUseReviewStub();
|
|
142
|
+
|
|
143
|
+
if (useStub) {
|
|
144
|
+
const queue = stubVerdicts ?? createPhaseStubVerdictQueue("plan");
|
|
145
|
+
const verdict = queue.next();
|
|
146
|
+
const feedback =
|
|
147
|
+
verdict === "REVISE" ? "Stub reviewer requested changes." : "Stub reviewer approved.";
|
|
148
|
+
if (journal?.projectRoot && journal?.batchId) {
|
|
149
|
+
appendJournalEvent(journal.projectRoot, journal.batchId, "review.started", {
|
|
150
|
+
taskId: journal.taskId,
|
|
151
|
+
laneNumber: journal.laneNumber,
|
|
152
|
+
correlationId: journal.correlationId,
|
|
153
|
+
stepNumber,
|
|
154
|
+
reviewType: "plan",
|
|
155
|
+
reviewLevel,
|
|
156
|
+
artifactPath,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
writeStubReviewArtifact({ artifactPath, title: "Plan Review", verdict, feedback });
|
|
160
|
+
if (journal?.projectRoot && journal?.batchId) {
|
|
161
|
+
appendJournalEvent(journal.projectRoot, journal.batchId, "review.completed", {
|
|
162
|
+
taskId: journal.taskId,
|
|
163
|
+
laneNumber: journal.laneNumber,
|
|
164
|
+
correlationId: journal.correlationId,
|
|
165
|
+
stepNumber,
|
|
166
|
+
reviewType: "plan",
|
|
167
|
+
reviewLevel,
|
|
168
|
+
verdict,
|
|
169
|
+
artifactPath,
|
|
170
|
+
stub: true,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
ok: verdict === "APPROVE",
|
|
175
|
+
skipped: false,
|
|
176
|
+
reviewLevel,
|
|
177
|
+
verdict,
|
|
178
|
+
feedback,
|
|
179
|
+
artifactPath,
|
|
180
|
+
spawnFailed: false,
|
|
181
|
+
exitCode: verdict === "APPROVE" ? 0 : 2,
|
|
182
|
+
attempt,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return await runStepReview({
|
|
187
|
+
taskFolder,
|
|
188
|
+
worktreePath,
|
|
189
|
+
stepNumber,
|
|
190
|
+
reviewType: "plan",
|
|
191
|
+
config,
|
|
192
|
+
journal,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {object} params
|
|
198
|
+
*/
|
|
199
|
+
function recordPlanReviewTaskFailure({
|
|
200
|
+
projectRoot,
|
|
201
|
+
state,
|
|
202
|
+
batchId,
|
|
203
|
+
task,
|
|
204
|
+
lane,
|
|
205
|
+
laneCorrelationId,
|
|
206
|
+
exitReason,
|
|
207
|
+
verdict,
|
|
208
|
+
planReviewAttempt,
|
|
209
|
+
config,
|
|
210
|
+
taskFolder,
|
|
211
|
+
}) {
|
|
212
|
+
const taskId = task.taskId;
|
|
213
|
+
const laneNumber = lane.laneNumber;
|
|
214
|
+
task.status = "failed";
|
|
215
|
+
task.endedAt = Date.now();
|
|
216
|
+
task.exitReason = exitReason;
|
|
217
|
+
updateSegmentForTask(state, taskId, "failed");
|
|
218
|
+
recomputeTaskCounters(state);
|
|
219
|
+
saveSpineBatchState(projectRoot, state);
|
|
220
|
+
appendJournalEvent(projectRoot, batchId, "task.failed", {
|
|
221
|
+
taskId,
|
|
222
|
+
laneNumber,
|
|
223
|
+
laneId: lane.laneId,
|
|
224
|
+
correlationId: laneCorrelationId,
|
|
225
|
+
classification: exitReason,
|
|
226
|
+
exitCode: 1,
|
|
227
|
+
planVerdict: verdict ?? null,
|
|
228
|
+
planReviewAttempt,
|
|
229
|
+
});
|
|
230
|
+
recordLaneTaskMetric({
|
|
231
|
+
projectRoot,
|
|
232
|
+
batchId,
|
|
233
|
+
task,
|
|
234
|
+
config,
|
|
235
|
+
taskFolder,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Engine-owned plan review phase after worker success (SP-695 / #250).
|
|
241
|
+
* Mirrors runCodeReviewPhase: RL gate (plan required for RL≥1), honor of an
|
|
242
|
+
* existing plan artifact/journal verdict, rework loop on REVISE, fail-closed
|
|
243
|
+
* on exhaustion or invalid verdict.
|
|
244
|
+
*
|
|
245
|
+
* @param {object} params
|
|
246
|
+
*/
|
|
247
|
+
export async function runPlanReviewPhase({
|
|
248
|
+
projectRoot,
|
|
249
|
+
state,
|
|
250
|
+
batchId,
|
|
251
|
+
config,
|
|
252
|
+
task,
|
|
253
|
+
lane,
|
|
254
|
+
taskFolderInWorktree,
|
|
255
|
+
wt,
|
|
256
|
+
taskBranch,
|
|
257
|
+
laneCorrelationId,
|
|
258
|
+
fileScopePaths,
|
|
259
|
+
}) {
|
|
260
|
+
const reviewLevel = readReviewLevel(taskFolderInWorktree);
|
|
261
|
+
if (!isReviewTypeRequired(reviewLevel, "plan")) {
|
|
262
|
+
return { ok: true, skipped: true };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Per-phase cap with fallback to maxFinalAttempts when the dedicated key is unset (SP-725 / #265).
|
|
266
|
+
const maxPlanReviewAttempts =
|
|
267
|
+
config?.review?.maxPlanReviewAttempts ??
|
|
268
|
+
config?.review?.maxFinalAttempts ??
|
|
269
|
+
REVIEW_DEFAULTS.maxFinalAttempts;
|
|
270
|
+
|
|
271
|
+
// Materialize the stub queue once per phase and pass it via params so
|
|
272
|
+
// parallel lanes never share or mutate process.env stub state (SP-728).
|
|
273
|
+
const stubVerdicts = shouldUseReviewStub() ? createPhaseStubVerdictQueue("plan") : null;
|
|
274
|
+
|
|
275
|
+
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
276
|
+
const honoredResult = honorCompletedReview({
|
|
277
|
+
reviewType: "plan",
|
|
278
|
+
passVerdict: "APPROVE",
|
|
279
|
+
attemptField: "planReviewAttempts",
|
|
280
|
+
attemptKey: "planReviewAttempt",
|
|
281
|
+
findCompletedReview: findCompletedPlanReview,
|
|
282
|
+
projectRoot,
|
|
283
|
+
state,
|
|
284
|
+
batchId,
|
|
285
|
+
task,
|
|
286
|
+
lane,
|
|
287
|
+
laneCorrelationId,
|
|
288
|
+
taskFolder: taskFolderInWorktree,
|
|
289
|
+
journalEvents,
|
|
290
|
+
});
|
|
291
|
+
if (honoredResult) return honoredResult;
|
|
292
|
+
|
|
293
|
+
return await runReviewPollLoop({
|
|
294
|
+
reviewType: "plan",
|
|
295
|
+
passVerdict: "APPROVE",
|
|
296
|
+
attemptField: "planReviewAttempts",
|
|
297
|
+
attemptKey: "planReviewAttempt",
|
|
298
|
+
maxAttempts: maxPlanReviewAttempts,
|
|
299
|
+
runEngineReview: (params) => runEnginePlanReview({ ...params, stubVerdicts }),
|
|
300
|
+
recordReviewTaskFailure: recordPlanReviewTaskFailure,
|
|
301
|
+
invalidVerdictOutput: "plan review artifact missing APPROVE or REVISE verdict",
|
|
302
|
+
journalEvents,
|
|
303
|
+
projectRoot,
|
|
304
|
+
state,
|
|
305
|
+
batchId,
|
|
306
|
+
config,
|
|
307
|
+
task,
|
|
308
|
+
lane,
|
|
309
|
+
taskFolderInWorktree,
|
|
310
|
+
wt,
|
|
311
|
+
taskBranch,
|
|
312
|
+
laneCorrelationId,
|
|
313
|
+
fileScopePaths,
|
|
314
|
+
});
|
|
315
|
+
}
|