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,427 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Shared review poll-loop mechanics for the engine lane review phases
|
|
4
|
+
* (SP-727 / #262). Extracted from review.mjs so the plan, code, and final
|
|
5
|
+
* phases share one honor fast-path and one while(true) review/rework poll.
|
|
6
|
+
* Behavior-preserving: phase-specific policy (gates, caps, verdict sets,
|
|
7
|
+
* contract verify) stays in review.mjs and is injected via callbacks.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { recordLaneTaskMetric } from "./queue.mjs";
|
|
13
|
+
import { appendJournalEvent } 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
|
+
REVIEW_TIMEOUT_REASON,
|
|
22
|
+
resolveReviewHonorJournalEvent,
|
|
23
|
+
resolveReviewPassKind,
|
|
24
|
+
shouldEmitReviewResumed,
|
|
25
|
+
} from "../review.mjs";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} taskFolder
|
|
29
|
+
*/
|
|
30
|
+
export function removeDoneFile(taskFolder) {
|
|
31
|
+
const donePath = path.join(taskFolder, ".DONE");
|
|
32
|
+
if (fs.existsSync(donePath)) {
|
|
33
|
+
fs.unlinkSync(donePath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {object} params
|
|
39
|
+
* @param {string} params.projectRoot
|
|
40
|
+
* @param {string} params.batchId
|
|
41
|
+
* @param {object} params.task
|
|
42
|
+
* @param {object} params.lane
|
|
43
|
+
* @param {string} params.laneCorrelationId
|
|
44
|
+
* @param {"plan"|"code"|"final"} params.reviewType
|
|
45
|
+
* @param {number} params.reviewAttempt
|
|
46
|
+
* @param {object} params.honored
|
|
47
|
+
* @param {"review.crash_recovered"|"review.skipped_fresh_artifact"|null} params.honorJournalEvent
|
|
48
|
+
*/
|
|
49
|
+
export function appendReviewHonorJournalEvents({
|
|
50
|
+
projectRoot,
|
|
51
|
+
batchId,
|
|
52
|
+
task,
|
|
53
|
+
lane,
|
|
54
|
+
laneCorrelationId,
|
|
55
|
+
reviewType,
|
|
56
|
+
reviewAttempt,
|
|
57
|
+
honored,
|
|
58
|
+
honorJournalEvent,
|
|
59
|
+
}) {
|
|
60
|
+
const taskId = task.taskId;
|
|
61
|
+
const laneNumber = lane.laneNumber;
|
|
62
|
+
if (!honorJournalEvent) return;
|
|
63
|
+
|
|
64
|
+
const basePayload = {
|
|
65
|
+
taskId,
|
|
66
|
+
laneNumber,
|
|
67
|
+
laneId: lane.laneId,
|
|
68
|
+
correlationId: laneCorrelationId,
|
|
69
|
+
reviewType,
|
|
70
|
+
artifactPath: honored.artifactPath,
|
|
71
|
+
honorSource: honored.source,
|
|
72
|
+
reviewPassKind: resolveReviewPassKind(honorJournalEvent),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (reviewType === "plan") {
|
|
76
|
+
appendJournalEvent(projectRoot, batchId, honorJournalEvent, {
|
|
77
|
+
...basePayload,
|
|
78
|
+
planReviewAttempt: reviewAttempt,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (reviewType === "code") {
|
|
84
|
+
appendJournalEvent(projectRoot, batchId, honorJournalEvent, {
|
|
85
|
+
...basePayload,
|
|
86
|
+
codeReviewAttempt: reviewAttempt,
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
appendJournalEvent(projectRoot, batchId, honorJournalEvent, {
|
|
92
|
+
...basePayload,
|
|
93
|
+
finalAttempt: reviewAttempt,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Honor fast-path shared by the three review phases: when a completed review
|
|
99
|
+
* with the pass verdict already exists in the journal or artifacts, record it
|
|
100
|
+
* and skip the poll loop. Returns the phase result, or null when not honored.
|
|
101
|
+
*
|
|
102
|
+
* @param {object} params
|
|
103
|
+
* @param {"plan"|"code"|"final"} params.reviewType
|
|
104
|
+
* @param {"APPROVE"|"PASS"} params.passVerdict
|
|
105
|
+
* @param {string} params.attemptField Task state field, e.g. "codeReviewAttempts".
|
|
106
|
+
* @param {string} params.attemptKey Journal payload key, e.g. "codeReviewAttempt".
|
|
107
|
+
* @param {Function} params.findCompletedReview ({ taskFolder, journalEvents, taskId }) => honored|null
|
|
108
|
+
*/
|
|
109
|
+
export function honorCompletedReview({
|
|
110
|
+
reviewType,
|
|
111
|
+
passVerdict,
|
|
112
|
+
attemptField,
|
|
113
|
+
attemptKey,
|
|
114
|
+
findCompletedReview,
|
|
115
|
+
projectRoot,
|
|
116
|
+
state,
|
|
117
|
+
batchId,
|
|
118
|
+
task,
|
|
119
|
+
lane,
|
|
120
|
+
laneCorrelationId,
|
|
121
|
+
taskFolder,
|
|
122
|
+
journalEvents,
|
|
123
|
+
}) {
|
|
124
|
+
const taskId = task.taskId;
|
|
125
|
+
const laneNumber = lane.laneNumber;
|
|
126
|
+
const reviewAttempt = task[attemptField] ?? 0;
|
|
127
|
+
const honored = findCompletedReview({ taskFolder, journalEvents, taskId });
|
|
128
|
+
if (honored?.verdict !== passVerdict) return null;
|
|
129
|
+
|
|
130
|
+
const honorJournalEvent = resolveReviewHonorJournalEvent({
|
|
131
|
+
journalEvents,
|
|
132
|
+
taskId,
|
|
133
|
+
reviewType,
|
|
134
|
+
honorSource: honored.source,
|
|
135
|
+
reviewAttempt,
|
|
136
|
+
});
|
|
137
|
+
appendReviewHonorJournalEvents({
|
|
138
|
+
projectRoot,
|
|
139
|
+
batchId,
|
|
140
|
+
task,
|
|
141
|
+
lane,
|
|
142
|
+
laneCorrelationId,
|
|
143
|
+
reviewType,
|
|
144
|
+
reviewAttempt,
|
|
145
|
+
honored,
|
|
146
|
+
honorJournalEvent,
|
|
147
|
+
});
|
|
148
|
+
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
149
|
+
taskId,
|
|
150
|
+
laneNumber,
|
|
151
|
+
laneId: lane.laneId,
|
|
152
|
+
correlationId: laneCorrelationId,
|
|
153
|
+
reviewType,
|
|
154
|
+
verdict: passVerdict,
|
|
155
|
+
feedback: honored.feedback,
|
|
156
|
+
artifactPath: honored.artifactPath,
|
|
157
|
+
[attemptKey]: reviewAttempt + 1,
|
|
158
|
+
honored: true,
|
|
159
|
+
honorSource: honored.source,
|
|
160
|
+
reviewPassKind: resolveReviewPassKind(honorJournalEvent),
|
|
161
|
+
});
|
|
162
|
+
task[attemptField] = reviewAttempt + 1;
|
|
163
|
+
saveSpineBatchState(projectRoot, state);
|
|
164
|
+
return { ok: true, verdict: passVerdict, [attemptKey]: reviewAttempt + 1, honored: true };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Generic review/rework poll loop shared by the plan, code, and final phases.
|
|
169
|
+
* Runs the injected engine review, records verdicts, respawns the worker on
|
|
170
|
+
* REVISE until the per-phase attempt cap, and fails closed on spawn failure,
|
|
171
|
+
* exhaustion, or an invalid verdict. The optional `beforeReview` hook runs at
|
|
172
|
+
* the top of each iteration (final phase uses it for contract verification)
|
|
173
|
+
* and may abort the loop or pass extra params to the engine review.
|
|
174
|
+
*
|
|
175
|
+
* @param {object} params
|
|
176
|
+
* @param {"plan"|"code"|"final"} params.reviewType
|
|
177
|
+
* @param {"APPROVE"|"PASS"} params.passVerdict
|
|
178
|
+
* @param {string} params.attemptField Task state field, e.g. "codeReviewAttempts".
|
|
179
|
+
* @param {string} params.attemptKey Journal payload key, e.g. "codeReviewAttempt".
|
|
180
|
+
* @param {number} params.maxAttempts
|
|
181
|
+
* @param {Function} params.runEngineReview Async engine review fn (e.g. runEngineCodeReview).
|
|
182
|
+
* @param {Function} params.recordReviewTaskFailure Phase-specific failure recorder.
|
|
183
|
+
* @param {string} params.invalidVerdictOutput Output message for the invalid-verdict failure.
|
|
184
|
+
* @param {boolean} [params.allowReplan] Final phase only: handle REPLAN as needs_replan.
|
|
185
|
+
* @param {Function} [params.beforeReview] Async hook per iteration; returns
|
|
186
|
+
* { abort: result } to stop the loop or { extraReviewParams: object } to continue.
|
|
187
|
+
*/
|
|
188
|
+
export async function runReviewPollLoop({
|
|
189
|
+
reviewType,
|
|
190
|
+
passVerdict,
|
|
191
|
+
attemptField,
|
|
192
|
+
attemptKey,
|
|
193
|
+
maxAttempts,
|
|
194
|
+
runEngineReview,
|
|
195
|
+
recordReviewTaskFailure,
|
|
196
|
+
invalidVerdictOutput,
|
|
197
|
+
allowReplan = false,
|
|
198
|
+
beforeReview = null,
|
|
199
|
+
journalEvents,
|
|
200
|
+
projectRoot,
|
|
201
|
+
state,
|
|
202
|
+
batchId,
|
|
203
|
+
config,
|
|
204
|
+
task,
|
|
205
|
+
lane,
|
|
206
|
+
taskFolderInWorktree,
|
|
207
|
+
wt,
|
|
208
|
+
taskBranch,
|
|
209
|
+
laneCorrelationId,
|
|
210
|
+
fileScopePaths,
|
|
211
|
+
}) {
|
|
212
|
+
const taskId = task.taskId;
|
|
213
|
+
const laneNumber = lane.laneNumber;
|
|
214
|
+
let reviewAttempt = task[attemptField] ?? 0;
|
|
215
|
+
const maxAttemptsKey = `max${attemptKey[0].toUpperCase()}${attemptKey.slice(1)}s`;
|
|
216
|
+
|
|
217
|
+
const journal = {
|
|
218
|
+
projectRoot,
|
|
219
|
+
batchId,
|
|
220
|
+
taskId,
|
|
221
|
+
laneNumber,
|
|
222
|
+
correlationId: laneCorrelationId,
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
let reviewResumedEmitted = false;
|
|
226
|
+
|
|
227
|
+
while (true) {
|
|
228
|
+
if (
|
|
229
|
+
!reviewResumedEmitted &&
|
|
230
|
+
shouldEmitReviewResumed({ journalEvents, taskId })
|
|
231
|
+
) {
|
|
232
|
+
appendJournalEvent(projectRoot, batchId, "review.resumed", {
|
|
233
|
+
taskId,
|
|
234
|
+
laneNumber,
|
|
235
|
+
laneId: lane.laneId,
|
|
236
|
+
correlationId: laneCorrelationId,
|
|
237
|
+
reviewType,
|
|
238
|
+
[attemptKey]: reviewAttempt + 1,
|
|
239
|
+
});
|
|
240
|
+
reviewResumedEmitted = true;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let extraReviewParams = {};
|
|
244
|
+
if (beforeReview) {
|
|
245
|
+
const gate = await beforeReview({ attempt: reviewAttempt });
|
|
246
|
+
if (gate?.abort) return gate.abort;
|
|
247
|
+
extraReviewParams = gate?.extraReviewParams ?? {};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const reviewResult = await runEngineReview({
|
|
251
|
+
taskFolder: taskFolderInWorktree,
|
|
252
|
+
worktreePath: wt,
|
|
253
|
+
config,
|
|
254
|
+
attempt: reviewAttempt + 1,
|
|
255
|
+
journal,
|
|
256
|
+
...extraReviewParams,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
if (reviewResult.spawnFailed) {
|
|
260
|
+
const spawnExitReason =
|
|
261
|
+
reviewResult.reason === REVIEW_TIMEOUT_REASON
|
|
262
|
+
? `${reviewType}_review_timeout`
|
|
263
|
+
: `${reviewType}_review_spawn_failed`;
|
|
264
|
+
recordReviewTaskFailure({
|
|
265
|
+
projectRoot,
|
|
266
|
+
state,
|
|
267
|
+
batchId,
|
|
268
|
+
task,
|
|
269
|
+
lane,
|
|
270
|
+
laneCorrelationId,
|
|
271
|
+
exitReason: spawnExitReason,
|
|
272
|
+
verdict: null,
|
|
273
|
+
[attemptKey]: reviewAttempt,
|
|
274
|
+
config,
|
|
275
|
+
taskFolder: taskFolderInWorktree,
|
|
276
|
+
});
|
|
277
|
+
return {
|
|
278
|
+
ok: false,
|
|
279
|
+
error: spawnExitReason,
|
|
280
|
+
output: reviewResult.error ?? `${reviewType} review spawn failed`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (reviewResult.skipped) {
|
|
285
|
+
return { ok: true, skipped: true };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
appendJournalEvent(projectRoot, batchId, "task.verdict_recorded", {
|
|
289
|
+
taskId,
|
|
290
|
+
laneNumber,
|
|
291
|
+
laneId: lane.laneId,
|
|
292
|
+
correlationId: laneCorrelationId,
|
|
293
|
+
reviewType,
|
|
294
|
+
verdict: reviewResult.verdict,
|
|
295
|
+
feedback: reviewResult.feedback,
|
|
296
|
+
artifactPath: reviewResult.artifactPath,
|
|
297
|
+
[attemptKey]: reviewAttempt + 1,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
if (reviewResult.verdict === passVerdict) {
|
|
301
|
+
task[attemptField] = reviewAttempt + 1;
|
|
302
|
+
saveSpineBatchState(projectRoot, state);
|
|
303
|
+
return { ok: true, verdict: passVerdict, [attemptKey]: reviewAttempt + 1 };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (allowReplan && reviewResult.verdict === "REPLAN") {
|
|
307
|
+
removeDoneFile(taskFolderInWorktree);
|
|
308
|
+
task[attemptField] = reviewAttempt + 1;
|
|
309
|
+
recordReviewTaskFailure({
|
|
310
|
+
projectRoot,
|
|
311
|
+
state,
|
|
312
|
+
batchId,
|
|
313
|
+
task,
|
|
314
|
+
lane,
|
|
315
|
+
laneCorrelationId,
|
|
316
|
+
exitReason: "needs_replan",
|
|
317
|
+
verdict: "REPLAN",
|
|
318
|
+
[attemptKey]: reviewAttempt + 1,
|
|
319
|
+
config,
|
|
320
|
+
taskFolder: taskFolderInWorktree,
|
|
321
|
+
});
|
|
322
|
+
return { ok: false, exitReason: "needs_replan", verdict: "REPLAN" };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (reviewResult.verdict === "REVISE") {
|
|
326
|
+
reviewAttempt++;
|
|
327
|
+
task[attemptField] = reviewAttempt;
|
|
328
|
+
saveSpineBatchState(projectRoot, state);
|
|
329
|
+
|
|
330
|
+
if (reviewAttempt >= maxAttempts) {
|
|
331
|
+
removeDoneFile(taskFolderInWorktree);
|
|
332
|
+
appendJournalEvent(projectRoot, batchId, "review.exhausted", {
|
|
333
|
+
taskId,
|
|
334
|
+
laneNumber,
|
|
335
|
+
laneId: lane.laneId,
|
|
336
|
+
correlationId: laneCorrelationId,
|
|
337
|
+
[attemptKey]: reviewAttempt,
|
|
338
|
+
[maxAttemptsKey]: maxAttempts,
|
|
339
|
+
reviewType,
|
|
340
|
+
});
|
|
341
|
+
recordReviewTaskFailure({
|
|
342
|
+
projectRoot,
|
|
343
|
+
state,
|
|
344
|
+
batchId,
|
|
345
|
+
task,
|
|
346
|
+
lane,
|
|
347
|
+
laneCorrelationId,
|
|
348
|
+
exitReason: "review_exhausted",
|
|
349
|
+
verdict: "REVISE",
|
|
350
|
+
[attemptKey]: reviewAttempt,
|
|
351
|
+
config,
|
|
352
|
+
taskFolder: taskFolderInWorktree,
|
|
353
|
+
});
|
|
354
|
+
return { ok: false, exitReason: "review_exhausted", verdict: "REVISE" };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
removeDoneFile(taskFolderInWorktree);
|
|
358
|
+
const reworkResult = await runWorker({
|
|
359
|
+
worktreePath: wt,
|
|
360
|
+
taskFolder: taskFolderInWorktree,
|
|
361
|
+
projectRoot,
|
|
362
|
+
batchId,
|
|
363
|
+
laneNumber,
|
|
364
|
+
taskId,
|
|
365
|
+
laneBranch: taskBranch,
|
|
366
|
+
laneCorrelationId,
|
|
367
|
+
fileScopePaths,
|
|
368
|
+
config,
|
|
369
|
+
onHeartbeat: (timestamp) => {
|
|
370
|
+
lane.lastHeartbeatAt = timestamp;
|
|
371
|
+
saveSpineBatchState(projectRoot, state);
|
|
372
|
+
},
|
|
373
|
+
onWorkerPid: (pid) => {
|
|
374
|
+
if (pid > 0) {
|
|
375
|
+
lane.workerPid = pid;
|
|
376
|
+
saveSpineBatchState(projectRoot, state);
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
if (!reworkResult.ok) {
|
|
381
|
+
const aborted = reworkResult.classification === "aborted";
|
|
382
|
+
task.status = aborted ? "aborted" : "failed";
|
|
383
|
+
task.endedAt = Date.now();
|
|
384
|
+
task.exitReason = reworkResult.classification ?? "worker_failed";
|
|
385
|
+
updateSegmentForTask(state, taskId, aborted ? "aborted" : "failed");
|
|
386
|
+
recomputeTaskCounters(state);
|
|
387
|
+
saveSpineBatchState(projectRoot, state);
|
|
388
|
+
recordLaneTaskMetric({
|
|
389
|
+
projectRoot,
|
|
390
|
+
batchId,
|
|
391
|
+
task,
|
|
392
|
+
config,
|
|
393
|
+
taskFolder: taskFolderInWorktree,
|
|
394
|
+
});
|
|
395
|
+
return { ok: false, aborted, workerResult: reworkResult };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
appendJournalEvent(projectRoot, batchId, "lane.completed", {
|
|
399
|
+
laneNumber,
|
|
400
|
+
laneId: lane.laneId,
|
|
401
|
+
taskId,
|
|
402
|
+
correlationId: laneCorrelationId,
|
|
403
|
+
phase: `${reviewType}_rework`,
|
|
404
|
+
});
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
recordReviewTaskFailure({
|
|
409
|
+
projectRoot,
|
|
410
|
+
state,
|
|
411
|
+
batchId,
|
|
412
|
+
task,
|
|
413
|
+
lane,
|
|
414
|
+
laneCorrelationId,
|
|
415
|
+
exitReason: `${reviewType}_review_invalid_verdict`,
|
|
416
|
+
verdict: reviewResult.verdict,
|
|
417
|
+
[attemptKey]: reviewAttempt,
|
|
418
|
+
config,
|
|
419
|
+
taskFolder: taskFolderInWorktree,
|
|
420
|
+
});
|
|
421
|
+
return {
|
|
422
|
+
ok: false,
|
|
423
|
+
error: `${reviewType}_review_invalid_verdict`,
|
|
424
|
+
output: invalidVerdictOutput,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Engine lane review stub verdict queues (SP-728 / #262).
|
|
4
|
+
*
|
|
5
|
+
* Stub verdicts come from env (`SPINE_ENGINE_*_STUB_VERDICTS` comma-separated
|
|
6
|
+
* queues or the singular `SPINE_ENGINE_*_STUB_VERDICT`), but the queue is
|
|
7
|
+
* materialized once into an in-memory array and popped via function params —
|
|
8
|
+
* `process.env` is read, never mutated. This keeps stub state safe when
|
|
9
|
+
* multiple lanes run review phases in the same process.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import {
|
|
15
|
+
normalizeCodeVerdict,
|
|
16
|
+
normalizeFinalVerdict,
|
|
17
|
+
} from "../review-shared.mjs";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Whether engine reviews should use stub verdicts instead of spawning a
|
|
21
|
+
* reviewer. Shared by the plan, code, and final engine review entry points.
|
|
22
|
+
*
|
|
23
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
24
|
+
*/
|
|
25
|
+
export function shouldUseReviewStub(env = process.env) {
|
|
26
|
+
return (
|
|
27
|
+
env.SPINE_REVIEW_STUB === "1" ||
|
|
28
|
+
env.SPINE_REVIEW_STUB === "true" ||
|
|
29
|
+
env.SPINE_WORKER_STUB === "1"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create an in-memory stub verdict queue. `next()` pops the head entry while
|
|
35
|
+
* entries remain, then falls back to `singleValue`, then `defaultVerdict`.
|
|
36
|
+
* Every result is passed through `normalize`; unrecognized entries fall back
|
|
37
|
+
* to `defaultVerdict`. Pure — no env reads or writes.
|
|
38
|
+
*
|
|
39
|
+
* @param {object} params
|
|
40
|
+
* @param {string} [params.queueValue] Raw comma-separated queue value.
|
|
41
|
+
* @param {string} [params.singleValue] Single-verdict fallback value.
|
|
42
|
+
* @param {(raw: string) => string|null} params.normalize Verdict normalizer.
|
|
43
|
+
* @param {string} params.defaultVerdict Fallback when nothing else resolves.
|
|
44
|
+
*/
|
|
45
|
+
export function createStubVerdictQueue({ queueValue, singleValue, normalize, defaultVerdict }) {
|
|
46
|
+
const entries = String(queueValue ?? "")
|
|
47
|
+
.split(",")
|
|
48
|
+
.map((entry) => entry.trim())
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
let index = 0;
|
|
51
|
+
return {
|
|
52
|
+
next() {
|
|
53
|
+
const raw = index < entries.length ? entries[index++] : (singleValue ?? defaultVerdict);
|
|
54
|
+
return normalize(raw) ?? defaultVerdict;
|
|
55
|
+
},
|
|
56
|
+
get remaining() {
|
|
57
|
+
return entries.length - index;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Read a stub verdict queue from env once and return the in-memory queue.
|
|
64
|
+
* Reads `env[queueEnv]` / `env[singleEnv]` a single time; subsequent pops
|
|
65
|
+
* mutate only the returned queue, never `process.env`.
|
|
66
|
+
*
|
|
67
|
+
* @param {object} params
|
|
68
|
+
* @param {string} params.queueEnv Env var holding the comma-separated queue.
|
|
69
|
+
* @param {string} params.singleEnv Env var holding the single-verdict fallback.
|
|
70
|
+
* @param {(raw: string) => string|null} params.normalize Verdict normalizer.
|
|
71
|
+
* @param {string} params.defaultVerdict Fallback when nothing else resolves.
|
|
72
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
73
|
+
*/
|
|
74
|
+
export function createStubVerdictQueueFromEnv({
|
|
75
|
+
queueEnv,
|
|
76
|
+
singleEnv,
|
|
77
|
+
normalize,
|
|
78
|
+
defaultVerdict,
|
|
79
|
+
env = process.env,
|
|
80
|
+
}) {
|
|
81
|
+
return createStubVerdictQueue({
|
|
82
|
+
queueValue: env[queueEnv],
|
|
83
|
+
singleValue: env[singleEnv],
|
|
84
|
+
normalize,
|
|
85
|
+
defaultVerdict,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Build the in-memory stub verdict queue for a review phase (SP-728 / #262).
|
|
91
|
+
* Env is read once here; the queue is passed down via params and popped
|
|
92
|
+
* in-memory — `process.env` is never mutated.
|
|
93
|
+
*
|
|
94
|
+
* @param {"plan"|"code"|"final"} reviewType
|
|
95
|
+
*/
|
|
96
|
+
export function createPhaseStubVerdictQueue(reviewType) {
|
|
97
|
+
if (reviewType === "final") {
|
|
98
|
+
return createStubVerdictQueueFromEnv({
|
|
99
|
+
queueEnv: "SPINE_ENGINE_FINAL_STUB_VERDICTS",
|
|
100
|
+
singleEnv: "SPINE_ENGINE_FINAL_STUB_VERDICT",
|
|
101
|
+
normalize: normalizeFinalVerdict,
|
|
102
|
+
defaultVerdict: "PASS",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (reviewType === "plan") {
|
|
106
|
+
return createStubVerdictQueueFromEnv({
|
|
107
|
+
queueEnv: "SPINE_ENGINE_PLAN_STUB_VERDICTS",
|
|
108
|
+
singleEnv: "SPINE_ENGINE_PLAN_STUB_VERDICT",
|
|
109
|
+
normalize: normalizeCodeVerdict,
|
|
110
|
+
defaultVerdict: "APPROVE",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return createStubVerdictQueueFromEnv({
|
|
114
|
+
queueEnv: "SPINE_ENGINE_CODE_STUB_VERDICTS",
|
|
115
|
+
singleEnv: "SPINE_ENGINE_CODE_STUB_VERDICT",
|
|
116
|
+
normalize: normalizeCodeVerdict,
|
|
117
|
+
defaultVerdict: "APPROVE",
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Write a stub review artifact markdown body (verdict heading + JSON block).
|
|
123
|
+
*
|
|
124
|
+
* @param {object} params
|
|
125
|
+
* @param {string} params.artifactPath
|
|
126
|
+
* @param {string} params.title Artifact heading, e.g. "Final Review".
|
|
127
|
+
* @param {string} params.verdict
|
|
128
|
+
* @param {string} params.feedback
|
|
129
|
+
*/
|
|
130
|
+
export function writeStubReviewArtifact({ artifactPath, title, verdict, feedback }) {
|
|
131
|
+
fs.mkdirSync(path.dirname(artifactPath), { recursive: true });
|
|
132
|
+
const body = [
|
|
133
|
+
`## ${title}`,
|
|
134
|
+
"",
|
|
135
|
+
`### Verdict: ${verdict}`,
|
|
136
|
+
"",
|
|
137
|
+
"### Summary",
|
|
138
|
+
feedback,
|
|
139
|
+
"",
|
|
140
|
+
"```json",
|
|
141
|
+
JSON.stringify({ verdict, feedback }, null, 2),
|
|
142
|
+
"```",
|
|
143
|
+
"",
|
|
144
|
+
].join("\n");
|
|
145
|
+
fs.writeFileSync(artifactPath, body, "utf-8");
|
|
146
|
+
}
|