mandrel 2.111.0 → 2.112.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/.agents/agents/acceptance-critic.md +14 -0
- package/.agents/agents/auditor.md +14 -0
- package/.agents/agents/plan-critic.md +5 -0
- package/.agents/agents/story-worker.md +4 -1
- package/.agents/docs/agentrc-reference.json +22 -10
- package/.agents/docs/configuration.md +351 -37
- package/.agents/docs/execution-reference.md +11 -0
- package/.agents/rules/git-conventions-reference.md +7 -0
- package/.agents/schemas/agentrc.schema.json +174 -14
- package/.agents/schemas/baselines/baseline-envelope.schema.json +16 -4
- package/.agents/schemas/baselines/bundle-size.schema.json +1 -0
- package/.agents/schemas/baselines/coverage.schema.json +1 -0
- package/.agents/schemas/baselines/crap.schema.json +37 -10
- package/.agents/schemas/baselines/duplication.schema.json +1 -0
- package/.agents/schemas/baselines/maintainability.schema.json +1 -0
- package/.agents/schemas/baselines/mutation.schema.json +1 -0
- package/.agents/schemas/crap-report.schema.json +6 -5
- package/.agents/schemas/story-deliver-terminal.schema.json +41 -2
- package/.agents/schemas/story-progress.schema.json +1 -1
- package/.agents/schemas/validation-evidence.schema.json +2 -2
- package/.agents/scripts/boot-sweep.js +41 -3
- package/.agents/scripts/coverage-capture.js +37 -3
- package/.agents/scripts/coverage-ratchet.js +106 -0
- package/.agents/scripts/evidence-gate.js +84 -21
- package/.agents/scripts/lib/audit-baselines/read.js +8 -1
- package/.agents/scripts/lib/audit-baselines/trend.js +2 -1
- package/.agents/scripts/lib/baseline-loader.js +4 -2
- package/.agents/scripts/lib/baselines/codec.js +57 -0
- package/.agents/scripts/lib/baselines/crap-preview-incremental.js +8 -3
- package/.agents/scripts/lib/baselines/crap-preview-scan.js +10 -16
- package/.agents/scripts/lib/baselines/crap-updater-cli.js +4 -13
- package/.agents/scripts/lib/baselines/kernel.js +19 -1
- package/.agents/scripts/lib/baselines/kinds/_crap-codec.js +171 -0
- package/.agents/scripts/lib/baselines/kinds/_crap-read.js +56 -16
- package/.agents/scripts/lib/baselines/kinds/_shared-metric.js +0 -59
- package/.agents/scripts/lib/baselines/kinds/crap.js +283 -319
- package/.agents/scripts/lib/baselines/preview-gates.js +29 -10
- package/.agents/scripts/lib/baselines/reader.js +36 -9
- package/.agents/scripts/lib/baselines/refresh-service.js +79 -18
- package/.agents/scripts/lib/baselines/seat-missing.js +173 -7
- package/.agents/scripts/lib/baselines/writer.js +36 -21
- package/.agents/scripts/lib/changed-files.js +70 -6
- package/.agents/scripts/lib/child-exec.js +10 -0
- package/.agents/scripts/lib/claude/agents-projection.js +5 -5
- package/.agents/scripts/lib/close-lock-events.js +8 -3
- package/.agents/scripts/lib/close-validation/ci-deferral.js +40 -0
- package/.agents/scripts/lib/close-validation/gates.js +111 -35
- package/.agents/scripts/lib/close-validation/process.js +16 -7
- package/.agents/scripts/lib/close-validation/projections/crap.js +43 -10
- package/.agents/scripts/lib/close-validation/runner.js +55 -23
- package/.agents/scripts/lib/close-validation/skip-branch-test.js +144 -0
- package/.agents/scripts/lib/close-validation/test-delta.js +33 -8
- package/.agents/scripts/lib/codex/agents-projection.js +6 -0
- package/.agents/scripts/lib/config/agentrc-overlay.js +9 -5
- package/.agents/scripts/lib/config/explain.js +5 -2
- package/.agents/scripts/lib/config/gates/coverage.schema.js +45 -1
- package/.agents/scripts/lib/config/gates/crap-incremental-coverage.schema.js +1 -1
- package/.agents/scripts/lib/config/git-roots.js +38 -4
- package/.agents/scripts/lib/config/handoff.js +24 -0
- package/.agents/scripts/lib/config/quality.js +26 -13
- package/.agents/scripts/lib/config/worktree-isolation.js +2 -5
- package/.agents/scripts/lib/config-resolver.js +22 -2
- package/.agents/scripts/lib/config-settings-schema-delivery.js +87 -4
- package/.agents/scripts/lib/config-settings-schema-quality.js +36 -1
- package/.agents/scripts/lib/config-settings-schema.js +1 -1
- package/.agents/scripts/lib/coverage-capture-affected.js +1 -0
- package/.agents/scripts/lib/coverage-capture-delta.js +164 -32
- package/.agents/scripts/lib/coverage-capture-own-fix.js +232 -0
- package/.agents/scripts/lib/coverage-capture-usage.js +2 -2
- package/.agents/scripts/lib/coverage-capture.js +15 -0
- package/.agents/scripts/lib/coverage-deferral.js +96 -0
- package/.agents/scripts/lib/coverage-ratchet.js +187 -0
- package/.agents/scripts/lib/crap-baseline-join.js +5 -5
- package/.agents/scripts/lib/crap-engine.js +3 -3
- package/.agents/scripts/lib/crap-method-identity.js +104 -48
- package/.agents/scripts/lib/escomplex-anchor.js +135 -0
- package/.agents/scripts/lib/escomplex-kernel.js +30 -1
- package/.agents/scripts/lib/failure-rows.js +121 -0
- package/.agents/scripts/lib/full-suite-lock.js +44 -4
- package/.agents/scripts/lib/full-suite-queue.js +89 -13
- package/.agents/scripts/lib/generated/agentrc-validator.js +8 -2
- package/.agents/scripts/lib/gh-env.js +3 -6
- package/.agents/scripts/lib/gh-pr-rest.js +1 -0
- package/.agents/scripts/lib/git/base-sync-probe.js +182 -0
- package/.agents/scripts/lib/git-branch-lifecycle.js +9 -0
- package/.agents/scripts/lib/observability/close-telemetry.js +37 -2
- package/.agents/scripts/lib/observability/handoff-telemetry.js +170 -0
- package/.agents/scripts/lib/observability/review-dispositions.js +23 -6
- package/.agents/scripts/lib/observability/runtime-friction.js +17 -4
- package/.agents/scripts/lib/observability/source-classifier.js +3 -0
- package/.agents/scripts/lib/observability/story-outcome.js +393 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/compare.js +2 -1
- package/.agents/scripts/lib/orchestration/check-baselines/phases/evaluate.js +19 -1
- package/.agents/scripts/lib/orchestration/check-baselines/phases/fail-detail.js +84 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/pipeline.js +14 -5
- package/.agents/scripts/lib/orchestration/check-baselines/phases/refresh-ack.js +3 -2
- package/.agents/scripts/lib/orchestration/check-baselines/phases/report.js +26 -6
- package/.agents/scripts/lib/orchestration/code-review.js +223 -19
- package/.agents/scripts/lib/orchestration/handoff-gates.js +129 -62
- package/.agents/scripts/lib/orchestration/handoff-rescore.js +169 -0
- package/.agents/scripts/lib/orchestration/handoff-suite-of-record.js +45 -0
- package/.agents/scripts/lib/orchestration/preflight-lanes.js +208 -0
- package/.agents/scripts/lib/orchestration/review-base-ref.js +40 -17
- package/.agents/scripts/lib/orchestration/review-deposit.js +38 -12
- package/.agents/scripts/lib/orchestration/review-depth.js +21 -0
- package/.agents/scripts/lib/orchestration/review-history.js +124 -20
- package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +23 -8
- package/.agents/scripts/lib/orchestration/review-providers/code-review.js +82 -39
- package/.agents/scripts/lib/orchestration/review-providers/critical-verifier.js +64 -11
- package/.agents/scripts/lib/orchestration/review-providers/degraded-gates.js +98 -3
- package/.agents/scripts/lib/orchestration/review-providers/finding-identity.js +6 -2
- package/.agents/scripts/lib/orchestration/review-providers/findings-renderer.js +55 -8
- package/.agents/scripts/lib/orchestration/review-providers/review-guidance.js +1 -0
- package/.agents/scripts/lib/orchestration/review-providers/review-provider-factory.js +42 -15
- package/.agents/scripts/lib/orchestration/review-providers/types.js +6 -0
- package/.agents/scripts/lib/orchestration/single-story-close/failed-terminal.js +10 -1
- package/.agents/scripts/lib/orchestration/single-story-close/gate-log.js +10 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +7 -4
- package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +15 -3
- package/.agents/scripts/lib/orchestration/single-story-close/phases/code-review.js +59 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +6 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/finish.js +15 -4
- package/.agents/scripts/lib/orchestration/single-story-close/phases/land-review-record.js +213 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/normalize-pr-title.js +9 -12
- package/.agents/scripts/lib/orchestration/single-story-close/phases/open-pr.js +26 -12
- package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +51 -26
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-push.js +3 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +50 -17
- package/.agents/scripts/lib/orchestration/single-story-close/phases/push.js +59 -11
- package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +1 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-block.js +31 -13
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-halt.js +29 -6
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-outcome.js +10 -12
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-override.js +19 -4
- package/.agents/scripts/lib/orchestration/single-story-close/result.js +30 -13
- package/.agents/scripts/lib/orchestration/single-story-close/review-overlap.js +73 -39
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +11 -3
- package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +3 -2
- package/.agents/scripts/lib/orchestration/story-close/duplication-close-rescore.js +20 -8
- package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +7 -0
- package/.agents/scripts/lib/orchestration/story-handoff.js +774 -196
- package/.agents/scripts/lib/orchestration/ticketing/reads.js +2 -0
- package/.agents/scripts/lib/pr-body-lines.js +32 -0
- package/.agents/scripts/lib/single-story/ci-ratchet-gate.js +140 -0
- package/.agents/scripts/lib/single-story/confirm-and-land.js +17 -7
- package/.agents/scripts/lib/single-story/confirm-merge.js +12 -3
- package/.agents/scripts/lib/single-story-sweep/report-stalled-executing.js +202 -0
- package/.agents/scripts/lib/standalone-ratchets.js +37 -0
- package/.agents/scripts/lib/suite-admission.js +20 -8
- package/.agents/scripts/lib/suite-sizing.js +146 -0
- package/.agents/scripts/lib/workspace-provisioner.js +2 -2
- package/.agents/scripts/merge-baseline.js +14 -3
- package/.agents/scripts/providers/github/comments.js +19 -3
- package/.agents/scripts/providers/github.js +1 -0
- package/.agents/scripts/review-dispositions-report.js +1 -1
- package/.agents/scripts/role-scope-guard.js +267 -0
- package/.agents/scripts/single-story-close.js +4 -4
- package/.agents/scripts/single-story-confirm-merge.js +31 -5
- package/.agents/scripts/single-story-init.js +24 -4
- package/.agents/scripts/story-handoff.js +3 -3
- package/.agents/scripts/story-outcomes-report.js +231 -0
- package/.agents/scripts/story-review-compute.js +9 -5
- package/.agents/scripts/update-coverage-baseline.js +12 -2
- package/.agents/scripts/update-crap-baseline.js +9 -1
- package/.agents/workflows/helpers/code-review.md +63 -9
- package/.agents/workflows/helpers/deliver-digest.md +53 -54
- package/.agents/workflows/helpers/deliver-reference.md +233 -67
- package/.agents/workflows/helpers/deliver-story-reference.md +19 -8
- package/.agents/workflows/helpers/deliver-story.md +7 -2
- package/.agents/workflows/helpers/parallel-tooling.md +29 -0
- package/docs/CHANGELOG.md +46 -0
- package/lib/cli/doctor-checks/coverage-ratchet.js +54 -0
- package/lib/cli/doctor-checks/effective-agentrc.js +23 -0
- package/lib/cli/doctor-checks/llm-review.js +2 -11
- package/lib/cli/doctor-checks/sync-parity.js +5 -1
- package/lib/cli/doctor-checks/test-credit-path.js +7 -2
- package/lib/cli/registry.js +5 -0
- package/package.json +1 -1
|
@@ -7,9 +7,16 @@
|
|
|
7
7
|
* @typedef {import('./review-providers/types.js').Finding} Finding
|
|
8
8
|
* @typedef {{ id: string, severity: string, provider: string|null,
|
|
9
9
|
* class: string|null, instances: { file: string, line?: number }[],
|
|
10
|
-
* ungrounded?: string, unverified?: string
|
|
11
|
-
*
|
|
10
|
+
* ungrounded?: string, unverified?: string, carried?: string,
|
|
11
|
+
* title?: string, body?: string, file?: string, line?: number,
|
|
12
|
+
* claim?: object }} HistoryFinding
|
|
13
|
+
* @typedef {{ id: string, status: 'still-open'|'fixed'|'refuted',
|
|
14
|
+
* reason?: string }} EarlierOutcome
|
|
15
|
+
* @typedef {{ runs: { headSha: string, findings: HistoryFinding[],
|
|
16
|
+
* earlierCriticals?: EarlierOutcome[] }[],
|
|
12
17
|
* overridden: string[], overrideReason?: string }} ReviewHistory
|
|
18
|
+
* @typedef {{ id: string, finding: HistoryFinding, headSha: string,
|
|
19
|
+
* status: 'open'|'fixed'|'refuted'|'overridden', reason?: string }} EarlierCritical
|
|
13
20
|
*/
|
|
14
21
|
|
|
15
22
|
import nodeFs from 'node:fs';
|
|
@@ -28,6 +35,8 @@ const KIND = 'story-review-history';
|
|
|
28
35
|
const LINE_WINDOW = 10;
|
|
29
36
|
/** Same bound as the `review-block-overridden` friction signal. */
|
|
30
37
|
const OVERRIDE_REASON_LIMIT = 500;
|
|
38
|
+
/** A stored CRITICAL body is clipped to this many characters. */
|
|
39
|
+
const BODY_LIMIT = 4000;
|
|
31
40
|
|
|
32
41
|
/**
|
|
33
42
|
* @param {number} storyId
|
|
@@ -86,6 +95,31 @@ function updateReviewHistory(storyId, update, deps = {}) {
|
|
|
86
95
|
);
|
|
87
96
|
}
|
|
88
97
|
|
|
98
|
+
/** Keep the set entries of `fields`; an empty string is unset. */
|
|
99
|
+
const present = (fields) =>
|
|
100
|
+
Object.fromEntries(
|
|
101
|
+
Object.entries(fields).filter(([, v]) => v != null && v !== ''),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const flags = (f) =>
|
|
105
|
+
present({
|
|
106
|
+
ungrounded: f.ungrounded,
|
|
107
|
+
unverified: f.unverified,
|
|
108
|
+
carried: f.carried,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/** What the verifier needs to re-check a CRITICAL without its original run. */
|
|
112
|
+
const criticalContent = (f) =>
|
|
113
|
+
f.severity === 'critical'
|
|
114
|
+
? present({
|
|
115
|
+
title: f.title,
|
|
116
|
+
body: typeof f.body === 'string' ? f.body.slice(0, BODY_LIMIT) : null,
|
|
117
|
+
file: f.file,
|
|
118
|
+
line: f.line,
|
|
119
|
+
claim: f.claim,
|
|
120
|
+
})
|
|
121
|
+
: {};
|
|
122
|
+
|
|
89
123
|
/** @param {Finding} f @returns {HistoryFinding} */
|
|
90
124
|
function toHistoryFinding(f) {
|
|
91
125
|
return {
|
|
@@ -94,27 +128,89 @@ function toHistoryFinding(f) {
|
|
|
94
128
|
provider: f.provider ?? null,
|
|
95
129
|
class: f.class ?? null,
|
|
96
130
|
instances: findingInstances(f),
|
|
97
|
-
...(f
|
|
98
|
-
...(f
|
|
131
|
+
...flags(f),
|
|
132
|
+
...criticalContent(f),
|
|
99
133
|
};
|
|
100
134
|
}
|
|
101
135
|
|
|
102
136
|
/**
|
|
103
137
|
* @param {number} storyId
|
|
104
|
-
* @param {{ headSha: string, findings: Finding[]
|
|
138
|
+
* @param {{ headSha: string, findings: Finding[],
|
|
139
|
+
* earlierCriticals?: EarlierOutcome[] }} run
|
|
105
140
|
* @param {{ config?: object, fsImpl?: typeof nodeFs }} [deps]
|
|
106
141
|
*/
|
|
107
|
-
export function appendReviewRun(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
142
|
+
export function appendReviewRun(
|
|
143
|
+
storyId,
|
|
144
|
+
{ headSha, findings, earlierCriticals },
|
|
145
|
+
deps,
|
|
146
|
+
) {
|
|
147
|
+
const run = toHistoryRun(headSha, findings, earlierCriticals);
|
|
148
|
+
updateReviewHistory(storyId, (h) => ({ ...h, runs: [...h.runs, run] }), deps);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function toHistoryRun(headSha, findings, earlierCriticals) {
|
|
152
|
+
const run = { headSha, findings: findings.map(toHistoryFinding) };
|
|
153
|
+
if (Array.isArray(earlierCriticals)) run.earlierCriticals = earlierCriticals;
|
|
154
|
+
return run;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
158
|
+
const RESOLVED = new Set(['fixed', 'refuted']);
|
|
159
|
+
|
|
160
|
+
/** Raised as `critical` and survived grounding and verification. */
|
|
161
|
+
const survived = (f) =>
|
|
162
|
+
f?.severity === 'critical' && !f.unverified && !f.ungrounded;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Every CRITICAL that survived grounding and verification in some run, in
|
|
166
|
+
* first-raised order, with its current status. A run's `fixed`/`refuted`
|
|
167
|
+
* outcome closes it; surviving again re-opens it; overridden ids end
|
|
168
|
+
* `overridden`. A carried record keeps the head it was first raised at.
|
|
169
|
+
*
|
|
170
|
+
* @param {ReviewHistory} history
|
|
171
|
+
* @returns {EarlierCritical[]}
|
|
172
|
+
*/
|
|
173
|
+
export function earlierCriticals(history) {
|
|
174
|
+
const byId = new Map();
|
|
175
|
+
for (const run of list(history?.runs)) {
|
|
176
|
+
list(run?.earlierCriticals).forEach((o) => {
|
|
177
|
+
resolveEntry(byId, o);
|
|
178
|
+
});
|
|
179
|
+
list(run?.findings)
|
|
180
|
+
.filter(survived)
|
|
181
|
+
.forEach((f) => {
|
|
182
|
+
openEntry(byId, f, run.headSha);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return markOverridden([...byId.values()], list(history?.overridden));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Overridden ids end `overridden`. */
|
|
189
|
+
function markOverridden(entries, ids) {
|
|
190
|
+
const overridden = new Set(ids);
|
|
191
|
+
return entries.map((e) =>
|
|
192
|
+
overridden.has(e.id) ? { ...e, status: 'overridden' } : e,
|
|
115
193
|
);
|
|
116
194
|
}
|
|
117
195
|
|
|
196
|
+
/** A run's `fixed`/`refuted` outcome closes an entry. */
|
|
197
|
+
function resolveEntry(byId, outcome) {
|
|
198
|
+
const entry = byId.get(outcome?.id);
|
|
199
|
+
if (!entry || !RESOLVED.has(outcome.status)) return;
|
|
200
|
+
Object.assign(entry, { status: outcome.status, reason: outcome.reason });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** A surviving CRITICAL (re-)opens its entry; carried keeps the first head. */
|
|
204
|
+
function openEntry(byId, finding, headSha) {
|
|
205
|
+
const prev = byId.get(finding.id);
|
|
206
|
+
byId.set(finding.id, {
|
|
207
|
+
id: finding.id,
|
|
208
|
+
finding,
|
|
209
|
+
headSha: finding.carried && prev ? prev.headSha : headSha,
|
|
210
|
+
status: 'open',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
118
214
|
/**
|
|
119
215
|
* @param {number} storyId
|
|
120
216
|
* @param {string[]} ids - the overridden CRITICALs.
|
|
@@ -148,6 +244,19 @@ function overlaps(now, before) {
|
|
|
148
244
|
return now.some((a) => before.some((b) => sameLocation(a, b)));
|
|
149
245
|
}
|
|
150
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Whether `finding` is `earlier` raised again: same id, overlapping location.
|
|
249
|
+
*
|
|
250
|
+
* @param {Finding} finding
|
|
251
|
+
* @param {HistoryFinding} earlier
|
|
252
|
+
*/
|
|
253
|
+
export function raisedAgain(finding, earlier) {
|
|
254
|
+
return (
|
|
255
|
+
findingId(finding) === earlier?.id &&
|
|
256
|
+
overlaps(findingInstances(finding), earlier.instances ?? [])
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
151
260
|
/**
|
|
152
261
|
* Mark each finding an earlier run raised (same id, overlapping location) as
|
|
153
262
|
* a `repeat`. A repeat of an overridden CRITICAL is downgraded so it does not
|
|
@@ -163,13 +272,8 @@ export function markRepeats(findings, history) {
|
|
|
163
272
|
);
|
|
164
273
|
const overridden = new Set(history.overridden);
|
|
165
274
|
return findings.map((f) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const seen = earlier.some(
|
|
169
|
-
(e) => e?.id === id && overlaps(instances, e.instances ?? []),
|
|
170
|
-
);
|
|
171
|
-
if (!seen) return f;
|
|
172
|
-
if (f.severity === 'critical' && overridden.has(id)) {
|
|
275
|
+
if (!earlier.some((e) => raisedAgain(f, e))) return f;
|
|
276
|
+
if (f.severity === 'critical' && overridden.has(findingId(f))) {
|
|
173
277
|
return {
|
|
174
278
|
...f,
|
|
175
279
|
severity: 'suggestion',
|
|
@@ -187,11 +187,21 @@ function toFindings(entries) {
|
|
|
187
187
|
.filter(Boolean);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
const resultTextOf = (envelope) =>
|
|
191
|
+
typeof envelope?.result === 'string' ? envelope.result : '';
|
|
192
|
+
|
|
193
|
+
function isUsageLimited(result, envelope) {
|
|
194
|
+
const text = [result.stderr, resultTextOf(envelope), result.stdout];
|
|
195
|
+
return USAGE_LIMIT_RE.test(text.join('\n'));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function isRetryable(result, envelope) {
|
|
199
|
+
return Number.isInteger(result.status) && !isUsageLimited(result, envelope);
|
|
200
|
+
}
|
|
201
|
+
|
|
190
202
|
function failureReason(result, envelope) {
|
|
191
|
-
const resultText =
|
|
192
|
-
|
|
193
|
-
const text = [result.stderr, resultText, result.stdout].join('\n');
|
|
194
|
-
if (USAGE_LIMIT_RE.test(text)) {
|
|
203
|
+
const resultText = resultTextOf(envelope);
|
|
204
|
+
if (isUsageLimited(result, envelope)) {
|
|
195
205
|
return 'the claude CLI account is out of quota (usage limit reached)';
|
|
196
206
|
}
|
|
197
207
|
if (result.status !== 0) {
|
|
@@ -237,19 +247,24 @@ function resultTextFindings(text) {
|
|
|
237
247
|
/**
|
|
238
248
|
* Verdict resolution: (a) a successful envelope's `structured_output`,
|
|
239
249
|
* (b) the fallback parser over its `result` text, (c) no verdict.
|
|
250
|
+
* `retryable` excludes a usage limit and a `status: null` timeout.
|
|
240
251
|
*
|
|
241
|
-
* @param {{ status: number, stdout: string, stderr: string }} result
|
|
242
|
-
* @returns {{ findings: Finding[] } | { reason: string }}
|
|
252
|
+
* @param {{ status: number|null, stdout: string, stderr: string }} result
|
|
253
|
+
* @returns {{ findings: Finding[] } | { reason: string, retryable: boolean }}
|
|
243
254
|
*/
|
|
244
255
|
export function resolveVerdict(result) {
|
|
245
256
|
const envelope = parseEnvelope(result.stdout);
|
|
257
|
+
const retryable = isRetryable(result, envelope);
|
|
246
258
|
if (!isSuccess(result, envelope)) {
|
|
247
|
-
return { reason: noVerdictReason(result, envelope) };
|
|
259
|
+
return { reason: noVerdictReason(result, envelope), retryable };
|
|
248
260
|
}
|
|
249
261
|
const entries =
|
|
250
262
|
structuredFindings(envelope.structured_output) ??
|
|
251
263
|
resultTextFindings(envelope.result);
|
|
252
264
|
return entries
|
|
253
265
|
? { findings: toFindings(entries) }
|
|
254
|
-
: {
|
|
266
|
+
: {
|
|
267
|
+
reason: 'the reviewer output did not parse as a findings verdict',
|
|
268
|
+
retryable,
|
|
269
|
+
};
|
|
255
270
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* review-providers/code-review.js — a
|
|
3
|
-
*
|
|
2
|
+
* review-providers/code-review.js — a model bug review of the Story diff
|
|
3
|
+
* through `claude --print --effort <input.effort ?? low>`. It asks only for
|
|
4
4
|
* merge-blocking problems, so every parsed finding is `critical` and halts
|
|
5
5
|
* close before auto-merge. The reviewer is handed the diff range, the Story
|
|
6
6
|
* id and the diff text — never `acceptance[]` or the self-eval verdict: this
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
* OS temp cwd (no CLAUDE.md discovery), user-only settings, no MCP, no tools.
|
|
11
11
|
*
|
|
12
12
|
* A missing CLI throws at construction (the chain entry is optional). A
|
|
13
|
-
* review with no verdict records
|
|
14
|
-
*
|
|
13
|
+
* transient failure is retried once; a review still with no verdict records
|
|
14
|
+
* one degraded gate via `getDegradations()` and returns no findings.
|
|
15
15
|
* A diff over the cap is reviewed chunk by chunk (file-aligned, sequential,
|
|
16
16
|
* findings merged). Source sections pack before tests and docs, and every
|
|
17
17
|
* chunk is told it is a slice and handed the whole changed-file manifest so
|
|
18
|
-
* a file changed in another chunk never reads as unchanged. What went
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* a file changed in another chunk never reads as unchanged. What went
|
|
19
|
+
* unchecked — a truncated file, files past the chunk bound, a chunk with no
|
|
20
|
+
* verdict (`coverage-partial`), a capped `<callers>` block
|
|
21
|
+
* (`context-reduced`) — is recorded beside the findings, naming the files.
|
|
21
22
|
*
|
|
22
23
|
* @typedef {import('./types.js').Finding} Finding
|
|
23
24
|
* @typedef {import('./types.js').ReviewInput} ReviewInput
|
|
@@ -28,7 +29,10 @@
|
|
|
28
29
|
import fs from 'node:fs';
|
|
29
30
|
import os from 'node:os';
|
|
30
31
|
import path from 'node:path';
|
|
31
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
spawnCaptureAsync,
|
|
34
|
+
spawnCaptureNullableAsync,
|
|
35
|
+
} from '../../child-exec.js';
|
|
32
36
|
import { gitSpawn } from '../../git-utils.js';
|
|
33
37
|
import { PROJECT_ROOT } from '../../project-root.js';
|
|
34
38
|
import { buildCallersSection } from './callers-context.js';
|
|
@@ -43,10 +47,11 @@ import { renderDepthDirective } from './review-depth.js';
|
|
|
43
47
|
import { renderGuidanceBlock } from './review-guidance.js';
|
|
44
48
|
import { probeClaudeCli } from './security-review.js';
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
/** @param {string} effort */
|
|
51
|
+
const claudeArgs = (effort) => [
|
|
47
52
|
'--print',
|
|
48
53
|
'--effort',
|
|
49
|
-
|
|
54
|
+
effort,
|
|
50
55
|
'--output-format',
|
|
51
56
|
'json',
|
|
52
57
|
'--json-schema',
|
|
@@ -56,7 +61,7 @@ const CLAUDE_ARGS = Object.freeze([
|
|
|
56
61
|
'--strict-mcp-config',
|
|
57
62
|
'--tools',
|
|
58
63
|
'',
|
|
59
|
-
]
|
|
64
|
+
];
|
|
60
65
|
const AUTH_ARGS = Object.freeze(['auth', 'status', '--json']);
|
|
61
66
|
const INVOKE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
62
67
|
const AUTH_TIMEOUT_MS = 15 * 1000;
|
|
@@ -239,19 +244,22 @@ function quoteWindowsArg(arg) {
|
|
|
239
244
|
* @param {{ cwd: string, input?: string, timeout: number, run?: Function, platform: string }} opts
|
|
240
245
|
* @returns {Promise<{ status: number, stdout: string, stderr: string }>}
|
|
241
246
|
*/
|
|
242
|
-
export function runClaude(args,
|
|
247
|
+
export function runClaude(args, opts) {
|
|
248
|
+
return spawnCaptureAsync('claude', ...claudeSpawn(args, opts));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** `runClaude`, but a timeout, kill or spawn error stays `status: null`. */
|
|
252
|
+
function runClaudeNullable(args, opts) {
|
|
253
|
+
return spawnCaptureNullableAsync('claude', ...claudeSpawn(args, opts));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The argv and spawn options both runners share. */
|
|
257
|
+
function claudeSpawn(args, { cwd, input, timeout, run, platform }) {
|
|
243
258
|
const shell = platform === 'win32';
|
|
244
|
-
return
|
|
245
|
-
'claude',
|
|
259
|
+
return [
|
|
246
260
|
shell ? args.map(quoteWindowsArg) : [...args],
|
|
247
|
-
{
|
|
248
|
-
|
|
249
|
-
input: input ?? '',
|
|
250
|
-
shell,
|
|
251
|
-
timeout,
|
|
252
|
-
...(run ? { run } : {}),
|
|
253
|
-
},
|
|
254
|
-
);
|
|
261
|
+
{ cwd, input: input ?? '', shell, timeout, ...(run ? { run } : {}) },
|
|
262
|
+
];
|
|
255
263
|
}
|
|
256
264
|
|
|
257
265
|
/**
|
|
@@ -280,8 +288,8 @@ function runAuthStatus(runDir, deps) {
|
|
|
280
288
|
});
|
|
281
289
|
}
|
|
282
290
|
|
|
283
|
-
function runReviewer(runDir, prompt, deps) {
|
|
284
|
-
return
|
|
291
|
+
function runReviewer(runDir, prompt, effort, deps) {
|
|
292
|
+
return runClaudeNullable(claudeArgs(effort), {
|
|
285
293
|
cwd: runDir,
|
|
286
294
|
input: prompt,
|
|
287
295
|
timeout: INVOKE_TIMEOUT_MS,
|
|
@@ -293,22 +301,35 @@ function runReviewer(runDir, prompt, deps) {
|
|
|
293
301
|
/**
|
|
294
302
|
* Preflight, then the review, both from a fresh OS temp dir removed after.
|
|
295
303
|
*
|
|
296
|
-
* @returns {Promise<{ findings: Finding[] } | { reason: string }>}
|
|
304
|
+
* @returns {Promise<{ findings: Finding[] } | { reason: string, retryable?: boolean }>}
|
|
297
305
|
*/
|
|
298
|
-
async function reviewInTempDir(prompt, deps) {
|
|
306
|
+
async function reviewInTempDir(prompt, effort, deps) {
|
|
299
307
|
const runDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mandrel-code-review-'));
|
|
300
308
|
try {
|
|
301
309
|
const auth = readAuthStatus(await runAuthStatus(runDir, deps));
|
|
302
310
|
if (!auth.ok) return auth;
|
|
303
311
|
deps.logger?.info?.(
|
|
304
|
-
`[code-review] Invoking claude --print --effort
|
|
312
|
+
`[code-review] Invoking claude --print --effort ${effort} (${auth.detail})...`,
|
|
305
313
|
);
|
|
306
|
-
return resolveVerdict(await runReviewer(runDir, prompt, deps));
|
|
314
|
+
return resolveVerdict(await runReviewer(runDir, prompt, effort, deps));
|
|
307
315
|
} finally {
|
|
308
316
|
fs.rmSync(runDir, { recursive: true, force: true });
|
|
309
317
|
}
|
|
310
318
|
}
|
|
311
319
|
|
|
320
|
+
/** One invocation, re-run once when its failure is transient-shaped. */
|
|
321
|
+
async function reviewWithRetry(prompt, effort, deps) {
|
|
322
|
+
const first = await reviewInTempDir(prompt, effort, deps);
|
|
323
|
+
if (!first.retryable) return first;
|
|
324
|
+
deps.logger?.warn?.(
|
|
325
|
+
`[code-review] No verdict (${first.reason}); retrying once.`,
|
|
326
|
+
);
|
|
327
|
+
return reviewInTempDir(prompt, effort, deps);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** @param {ReviewInput} input */
|
|
331
|
+
const effortOf = (input) => input.effort ?? 'low';
|
|
332
|
+
|
|
312
333
|
function assertCliPresent(probeFn) {
|
|
313
334
|
if (probeFn()) return;
|
|
314
335
|
throw new Error(
|
|
@@ -339,18 +360,38 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
339
360
|
let degradations = [];
|
|
340
361
|
|
|
341
362
|
/** Record a not-checked slice without replacing the findings. */
|
|
342
|
-
function noteDegradation(reason) {
|
|
343
|
-
degradations.push({ ...DEGRADATION_BASE, reason });
|
|
363
|
+
function noteDegradation(reason, kind) {
|
|
364
|
+
degradations.push({ ...DEGRADATION_BASE, kind, reason });
|
|
344
365
|
deps.logger?.warn?.(`[code-review] Not checked: ${reason}.`);
|
|
345
366
|
}
|
|
346
367
|
|
|
347
368
|
function settle(verdict) {
|
|
348
369
|
if (!('reason' in verdict)) return verdict.findings;
|
|
349
|
-
degradations.push({
|
|
370
|
+
degradations.push({
|
|
371
|
+
...DEGRADATION_BASE,
|
|
372
|
+
kind: 'verdict-missing',
|
|
373
|
+
reason: verdict.reason,
|
|
374
|
+
});
|
|
350
375
|
deps.logger?.warn?.(`[code-review] No verdict: ${verdict.reason}.`);
|
|
351
376
|
return [];
|
|
352
377
|
}
|
|
353
378
|
|
|
379
|
+
/**
|
|
380
|
+
* No chunk with a verdict is a review with none: one record naming every
|
|
381
|
+
* file. Otherwise each chunk without one is a partial gap.
|
|
382
|
+
*/
|
|
383
|
+
function noteChunkGaps(failed, total) {
|
|
384
|
+
if (failed.length > 0 && failed.length === total) {
|
|
385
|
+
const reasons = [...new Set(failed.map((f) => f.reason))].join('; ');
|
|
386
|
+
const files = failed.map((f) => f.files).join(', ');
|
|
387
|
+
noteDegradation(`no verdict for ${files}: ${reasons}`, 'verdict-missing');
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
for (const { files, reason } of failed) {
|
|
391
|
+
noteDegradation(`no verdict for ${files}: ${reason}`, 'coverage-partial');
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
354
395
|
/**
|
|
355
396
|
* The `<callers>` block, guidance, the slice note and the manifest ride every chunk,
|
|
356
397
|
* so they come out of the budget; chunk numbers are one digit, so the
|
|
@@ -376,15 +417,18 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
376
417
|
noteDegradation(
|
|
377
418
|
`review bounded at ${MAX_REVIEW_CHUNKS} chunks: ${overflow.length} ` +
|
|
378
419
|
`file(s) not reviewed: ${overflow.join(', ')}`,
|
|
420
|
+
'coverage-partial',
|
|
379
421
|
);
|
|
380
422
|
}
|
|
381
423
|
const findings = [];
|
|
424
|
+
const failed = [];
|
|
382
425
|
for (const [index, chunk] of chunks.entries()) {
|
|
383
426
|
const files = chunk.sections.map((s) => s.file).join(', ');
|
|
384
427
|
if (chunk.size > budget) {
|
|
385
428
|
noteDegradation(
|
|
386
429
|
`${files} truncated at ${budget} characters: ` +
|
|
387
430
|
`${chunk.size - budget} characters not reviewed`,
|
|
431
|
+
'coverage-partial',
|
|
388
432
|
);
|
|
389
433
|
}
|
|
390
434
|
const prompt = buildPrompt(
|
|
@@ -394,13 +438,11 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
394
438
|
budget,
|
|
395
439
|
sliceNote(index + 1, chunks.length) + manifest,
|
|
396
440
|
);
|
|
397
|
-
const verdict = await
|
|
398
|
-
if ('reason' in verdict) {
|
|
399
|
-
|
|
400
|
-
} else {
|
|
401
|
-
findings.push(...verdict.findings);
|
|
402
|
-
}
|
|
441
|
+
const verdict = await reviewWithRetry(prompt, effortOf(input), runDeps);
|
|
442
|
+
if ('reason' in verdict) failed.push({ files, reason: verdict.reason });
|
|
443
|
+
else findings.push(...verdict.findings);
|
|
403
444
|
}
|
|
445
|
+
noteChunkGaps(failed, chunks.length);
|
|
404
446
|
return dedupeFindings(findings);
|
|
405
447
|
}
|
|
406
448
|
|
|
@@ -417,13 +459,14 @@ export function createCodeReviewProviderForRegistry(deps = {}) {
|
|
|
417
459
|
cwd: PROJECT_ROOT,
|
|
418
460
|
gitSpawnFn,
|
|
419
461
|
});
|
|
420
|
-
if (callers.reason) noteDegradation(callers.reason);
|
|
462
|
+
if (callers.reason) noteDegradation(callers.reason, 'context-reduced');
|
|
421
463
|
if (diff.text.length > MAX_DIFF_CHARS) {
|
|
422
464
|
return reviewInChunks(input, diff.text, callers.text);
|
|
423
465
|
}
|
|
424
466
|
return settle(
|
|
425
|
-
await
|
|
467
|
+
await reviewWithRetry(
|
|
426
468
|
buildPrompt(input, diff.text, callers.text),
|
|
469
|
+
effortOf(input),
|
|
427
470
|
runDeps,
|
|
428
471
|
),
|
|
429
472
|
);
|
|
@@ -256,6 +256,18 @@ function boundDegradation(skipped) {
|
|
|
256
256
|
];
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
+
function voterContext(args) {
|
|
260
|
+
return {
|
|
261
|
+
baseRef: args.baseRef,
|
|
262
|
+
headRef: args.headRef,
|
|
263
|
+
cwd: args.cwd ?? PROJECT_ROOT,
|
|
264
|
+
spawnFn: args.spawnFn,
|
|
265
|
+
platform: args.platform ?? process.platform,
|
|
266
|
+
gitSpawnFn: args.gitSpawnFn ?? gitSpawn,
|
|
267
|
+
cliPresent: (args.probeFn ?? probeClaudeCli)(),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
259
271
|
/**
|
|
260
272
|
* Verify every `critical` finding; findings below critical are never sent.
|
|
261
273
|
* One verifier at `light`/`standard`, three at `deep`.
|
|
@@ -278,15 +290,7 @@ async function verifyCriticals(args) {
|
|
|
278
290
|
}
|
|
279
291
|
const checked = criticals.slice(0, MAX_VERIFIED_CRITICALS);
|
|
280
292
|
const voters = args.depth === 'deep' ? 3 : 1;
|
|
281
|
-
const ctx =
|
|
282
|
-
baseRef: args.baseRef,
|
|
283
|
-
headRef: args.headRef,
|
|
284
|
-
cwd: args.cwd ?? PROJECT_ROOT,
|
|
285
|
-
spawnFn: args.spawnFn,
|
|
286
|
-
platform: args.platform ?? process.platform,
|
|
287
|
-
gitSpawnFn: args.gitSpawnFn ?? gitSpawn,
|
|
288
|
-
cliPresent: (args.probeFn ?? probeClaudeCli)(),
|
|
289
|
-
};
|
|
293
|
+
const ctx = voterContext(args);
|
|
290
294
|
args.logger?.info?.(
|
|
291
295
|
`[code-review] Verifying ${checked.length} critical(s) with ${voters} verifier(s) each...`,
|
|
292
296
|
);
|
|
@@ -313,6 +317,56 @@ async function verifyCriticals(args) {
|
|
|
313
317
|
};
|
|
314
318
|
}
|
|
315
319
|
|
|
320
|
+
/** Whether the review gets a verifier: built-in, or injected seams. */
|
|
321
|
+
const hasVerifier = (opts) => Boolean(opts.verifier || !opts.reviewProvider);
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Re-check earlier CRITICALs at the current head: one call each whatever the
|
|
325
|
+
* depth, the same pool and cap as `verifyCriticals`. Each result is the voter
|
|
326
|
+
* outcome; past the cap or with no verifier the outcome is `skipped`.
|
|
327
|
+
*
|
|
328
|
+
* @param {{ findings: Finding[], reviewInput: { baseRef: string,
|
|
329
|
+
* headRef: string }, opts: object }} args
|
|
330
|
+
* @returns {Promise<{ results: { outcome: string, reason: string }[],
|
|
331
|
+
* degradations: GateDegradation[], verification: VerificationSummary }>}
|
|
332
|
+
*/
|
|
333
|
+
export async function recheckCriticals({ findings, reviewInput, opts }) {
|
|
334
|
+
const verification = emptyVerification();
|
|
335
|
+
if (findings.length === 0 || !hasVerifier(opts)) {
|
|
336
|
+
const reason = 'no verifier for this review';
|
|
337
|
+
return {
|
|
338
|
+
results: findings.map(() => ({ outcome: 'skipped', reason })),
|
|
339
|
+
degradations: [],
|
|
340
|
+
verification,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const checked = findings.slice(0, MAX_VERIFIED_CRITICALS);
|
|
344
|
+
const ctx = voterContext({
|
|
345
|
+
baseRef: reviewInput.baseRef,
|
|
346
|
+
headRef: reviewInput.headRef,
|
|
347
|
+
cwd: opts.cwd,
|
|
348
|
+
gitSpawnFn: opts.gitSpawnFn,
|
|
349
|
+
...opts.verifier,
|
|
350
|
+
});
|
|
351
|
+
const votes = await runPooled(
|
|
352
|
+
checked.map((f) => () => runVoter(f, ctx)),
|
|
353
|
+
MAX_IN_FLIGHT,
|
|
354
|
+
);
|
|
355
|
+
for (const v of votes) verification[v.outcome] += 1;
|
|
356
|
+
verification.attempted = votes.length;
|
|
357
|
+
return {
|
|
358
|
+
results: findings.map(
|
|
359
|
+
(_, i) =>
|
|
360
|
+
votes[i] ?? { outcome: 'skipped', reason: 'verification cap reached' },
|
|
361
|
+
),
|
|
362
|
+
degradations: [
|
|
363
|
+
...checked.flatMap((f, i) => voteDegradations(f, [votes[i]])),
|
|
364
|
+
...boundDegradation(findings.slice(MAX_VERIFIED_CRITICALS)),
|
|
365
|
+
],
|
|
366
|
+
verification,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
316
370
|
/**
|
|
317
371
|
* The pipeline step: ground every finding, then verify the CRITICALs left.
|
|
318
372
|
* An injected review provider gets no verifier unless `opts.verifier` (the
|
|
@@ -337,8 +391,7 @@ export async function vetFindings({
|
|
|
337
391
|
degradations,
|
|
338
392
|
gitSpawnFn: opts.gitSpawnFn,
|
|
339
393
|
});
|
|
340
|
-
const verify =
|
|
341
|
-
opts.verifier || !opts.reviewProvider ? verifyCriticals : skipVerification;
|
|
394
|
+
const verify = hasVerifier(opts) ? verifyCriticals : skipVerification;
|
|
342
395
|
const verified = await verify({
|
|
343
396
|
findings: grounded.findings,
|
|
344
397
|
baseRef,
|