Files
gstack/lib/review-verdict.ts
T
Garry Tanandcapy-ai[bot] 3b650356f3 /ship reviewers state their blocker count in one line, and gstack checks it against their findings (GST-2495) (#4353)
* Reviewers state their blocker count in one line, and gstack checks it against the findings it parsed

Every blocking /ship reader's brief now asks for REVIEW_VERDICT: blocking=<n>. collect adds a CRITICAL row for each
declared blocker it did not parse, marks word-only CRITICAL rows as summary candidates when the count is lower, and
never lowers a row on its own except the native voice's unanchored FIXABLE raise. Ledgers rendered before this change
replay unchanged. Includes the preregistration for the no-loss replay.

Refs: GST-2495
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Add the verdict-line no-loss replay results

Refs: GST-2495
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Keep a finding line that mentions REVIEW_VERDICT instead of stripping it

Only a well-formed verdict line is removed before findings are parsed; prose that names the token, or a malformed attempt, stays in the text so its finding is still collected.

Review-Finding: p1/specialist-batched#1 reader=specialist-batched
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Check a stored summary flag against the reply on every ledger, not only ones that asked for the verdict line

verify now re-derives summary_candidate for every merged row, so a flag edited onto a real CRITICAL in an older ledger can no longer let judgment lower it while verify reports clean.

Review-Finding: v2/outside-voice#1 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Never lower a finding automatically when a reviewer's blocker count is lower than the parse

A valid verdict line used to relabel the native voice's unanchored FIXABLE prose to its own label. Beside a
denial line such as 'No other CRITICAL issues.' that let a real blocker drop to FIXABLE while the count still
agreed. Those rows now stay CRITICAL and become summary candidates the lead lowers with a written reason.

Review-Finding: v3/adversarial-native#1 reader=adversarial-native
Refs: GST-2495
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Split a run-on sentence in the verdict-line changelog entry

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-11-14 07:31:35 +00:00

52 lines
3.2 KiB
TypeScript

/**
* review-verdict: the one machine-readable line every blocking reader's reply carries (GST-2495), right under its
* REVIEWED_TREE line: `REVIEW_VERDICT: blocking=<n>[ at=<path>:<line>[,<path>:<line>...]]`, n being how many findings
* in the reply block the merge. collect reads it only when the reader's render asked for it (the `verdict: 1` render
* event), so a reply to an older brief, or an old ledger, parses exactly as before. Lines inside fenced code blocks are
* ignored, byte-identical repeats count once, and differing repeats are malformed. docs/review-policy.md#verdict-line.
*/
export type Verdict = { state: 'valid'; blocking: number; at: string[] } | { state: 'missing' } | { state: 'malformed'; why: string };
const FENCE = /^\s*(`{3,}|~{3,})/;
const LOCUS = /^[\w./-]+:\d+$/;
const GRAMMAR = /^REVIEW_VERDICT:\s*blocking=(\d+)(?:\s+at=(\S+))?$/;
/** A line that tries to be the verdict line, wrappers removed (list marker, heading mark, whole-line bold or backticks), or null. */
export function verdictAttempt(line: string): string | null {
let t = line.trim().replace(/^(?:[-*>]\s+|\d+[.)]\s+|#+\s+)/, '');
for (const w of ['**', '`']) if (t.length > 2 * w.length && t.startsWith(w) && t.endsWith(w)) t = t.slice(w.length, -w.length).trim();
t = t.replace(/^\*\*REVIEW_VERDICT:\*\*/, 'REVIEW_VERDICT:');
return /^REVIEW_VERDICT\s*(?:[:=]|blocking\b)/i.test(t) ? t : null;
}
/** Each line of a reply, marked when it is a verdict attempt outside a code fence. */
function scan(output: string): Array<{ line: string; attempt: string | null }> {
let fence: string | null = null;
return output.replace(/\r\n/g, '\n').split('\n').map(line => {
const f = FENCE.exec(line)?.[1];
if (f && (fence === null || f[0] === fence[0])) { fence = fence === null ? f : null; return { line, attempt: null }; }
return { line, attempt: fence === null ? verdictAttempt(line) : null };
});
}
export function parseVerdict(output: string): Verdict {
const attempts = [...new Set(scan(output).flatMap(l => (l.attempt === null ? [] : [l.attempt])))];
if (!attempts.length) return { state: 'missing' };
if (attempts.length > 1) return { state: 'malformed', why: `${attempts.length} different REVIEW_VERDICT lines` };
const m = GRAMMAR.exec(attempts[0]!);
if (!m) return { state: 'malformed', why: `not REVIEW_VERDICT: blocking=<n>[ at=<path>:<line>,...]: ${JSON.stringify(attempts[0]!.slice(0, 120))}` };
const blocking = Number(m[1]);
if (blocking > 99) return { state: 'malformed', why: `blocking=${blocking} is over 99` };
const at = m[2] ? m[2].split(',') : [];
if (at.some(a => !LOCUS.test(a))) return { state: 'malformed', why: `at= holds something other than <path>:<line>: ${m[2]}` };
if (at.length > blocking) return { state: 'malformed', why: `at= names ${at.length} locations for blocking=${blocking}` };
return { state: 'valid', blocking, at };
}
/**
* The reply with every well-formed verdict line outside a code fence removed, so the line never joins or colours a neighbouring
* finding. A malformed attempt stays in the text, so a finding written on that line is still parsed and never lost.
*/
export const withoutVerdictLines = (output: string) => scan(output).filter(l => l.attempt === null || !GRAMMAR.test(l.attempt)).map(l => l.line).join('\n');