// `archilyzer reports bench-verdicts --models a,b,c [--report ,…] [--window 60] // [--window-mode seconds|turn] [--max-usd 5] [--limit n] [--items-from ] // [--dedupe] [--run ] [--dry] [--here] [--wait] [--json]` // (release 28 M7; release 29 V1) — the verdict bench: every ruled claim of the // registry's fact-checks asked of each model, one claim per call, and scored // against the operator's rulings (lib/report/draft/bench/). V1: `--window-mode // turn` (the cited speaker's turn, bounded by --window), a stratified `--limit` // (by the operator's verdict), `--items-from ` (that run's exact items). // `--dedupe` asks a repeated claim once (off by default: every claim is asked; // operator ruling 2026-10-17). // // --dry lists the items (key, the operator's verdict, quotes, cues — no // claim text unless --json) and the skipped claims with their // reasons, and estimates each model's cost. Reads only; asks // nothing; writes nothing. // (none) THROUGH THE EDITOR: `pnpm ops bench-verdicts` (a child), so a // local model gets the GPU arbiter's turn and is unloaded after — // the only correct path for one. `--wait` follows the job. // --here in this process, for API models only (a local model is refused: // the GPU is arbitrated in the editor alone). The day's cap and the // usage ledger hold as in the editor's job. // // The results are local-only, in `.generation/bench/verdicts//` // (items.jsonl, results.jsonl, summary.json); umtool's /bench shows them. // A `--run` that exists continues it. // // Exit 0 when the run is done (a dry run: when it has items); 1 when it // stopped early (the cap, a cancel, a failure) or the editor refused; 2 for // usage. import type { CommandContext } from "./_cli"; import type { FlagValue } from "./_parseFlags"; import { getPaths, type Paths } from "../lib/paths"; import { getSettings } from "../lib/settings"; import { diskCuesOf } from "../lib/report/convert-server"; import { BenchInputError, isBenchRunId, isWindowMode, newBenchRunId, validateBenchOptions, planVerdictBench, type BenchOptions, type BenchPlan, } from "../lib/report/draft/bench/index"; import { benchDailyCapRefusal, runBenchWithSettings } from "../controller/benchVerdicts"; import { diskDateOf, diskTurnsOf } from "../lib/report/draft/bench/disk"; import { runOpsChild } from "./gen"; type Out = { log: (s: string) => void; error: (s: string) => void }; const list = (v: FlagValue | undefined) => (typeof v === "string" ? v.split(",").map((s) => s.trim()).filter(Boolean) : []); function num(v: FlagValue | undefined, name: string): number | undefined { if (v === undefined) return undefined; const n = typeof v === "string" ? Number(v) : NaN; if (!Number.isFinite(n)) throw new BenchInputError(`--${name} takes a number`); return n; } export function benchOptionsOf(flags: Record): BenchOptions { const o: BenchOptions = { models: list(flags.models) }; const reports = list(flags.report); if (reports.length) o.reports = reports; const w = num(flags.window, "window"); if (w !== undefined) o.windowS = w; const m = num(flags["max-usd"], "max-usd"); if (m !== undefined) o.maxUsd = m; const l = num(flags.limit, "limit"); if (l !== undefined) o.limit = l; if (typeof flags["window-mode"] === "string") { if (!isWindowMode(flags["window-mode"])) throw new BenchInputError(`--window-mode is "seconds" or "turn"`); o.windowMode = flags["window-mode"]; } if (typeof flags["items-from"] === "string") o.itemsFrom = flags["items-from"]; if (typeof flags.run === "string") o.runId = flags.run; if (flags.dedupe === true) o.dedupe = true; validateBenchOptions(o); if (o.runId !== undefined && !isBenchRunId(o.runId)) throw new BenchInputError("--run is a run id: lowercase letters, digits and dashes"); return o; } export function formatBenchPlan(plan: BenchPlan): string[] { const lines: string[] = []; const window = plan.windowMode === "turn" ? `the speaker's turn within ${plan.windowS} s` : `a ${plan.windowS} s window`; lines.push( `${plan.items.length} items from ${plan.reports.length} fact-check(s)${plan.itemsFrom ? ` (run ${plan.itemsFrom}'s items)` : ""}, ${window}; ${plan.skipped.length} claims skipped, ${plan.dropped.length} citations dropped`, ); lines.push(` prompt version ${plan.promptVersion}, items ${plan.itemsHash}`); const reasons = new Map(); for (const s of plan.skipped) reasons.set(s.reason, (reasons.get(s.reason) ?? 0) + 1); for (const [r, n] of reasons) lines.push(` skipped ${n}: ${r}`); const drops = new Map(); for (const d of plan.dropped) drops.set(d.reason, (drops.get(d.reason) ?? 0) + 1); for (const [r, n] of drops) lines.push(` dropped ${n}: ${r}`); const ruled = new Map(); for (const it of plan.items) ruled.set(it.verdict, (ruled.get(it.verdict) ?? 0) + 1); lines.push(` ruled: ${[...ruled].map(([v, n]) => `${v} ${n}`).join(", ") || "none"}`); lines.push("items:"); for (const it of plan.items) { const cues = it.windows.reduce((s, w) => s + w.cues.length, 0); lines.push(` ${it.key} ${it.verdict} ${it.quotes.length} quote(s), ${cues} cues`); } for (const s of plan.skipped) lines.push(` skipped ${s.key}: ${s.reason}`); for (const d of plan.dropped) lines.push(` dropped ${d.key} ${d.citation}: ${d.reason}`); lines.push("estimate:"); for (const e of plan.estimate) { lines.push(` ${e.model} (${e.provider}): ${e.calls} calls, ~${e.inputTokens} in / ~${e.outputTokens} out tokens, ~$${e.usd.toFixed(4)}`); } lines.push(` total ~$${plan.estimateUsd.toFixed(4)} (the run stops at its --max-usd, default $5)`); return lines; } export type BenchDeps = { paths: Paths; runOps: (argv: string[]) => Promise; out?: Out; }; export async function benchMain(flags: Record, deps: BenchDeps): Promise { const out = deps.out ?? console; let opts: BenchOptions; try { opts = benchOptionsOf(flags); if (flags.dry === true) { const plan = await planVerdictBench(opts, { paths: deps.paths, cuesOf: diskCuesOf(deps.paths.channelsDir), turnsOf: diskTurnsOf(deps.paths.channelsDir), dateOf: diskDateOf(deps.paths.channelsDir), }); if (flags.json === true) out.log(JSON.stringify(plan, null, 2)); else for (const l of formatBenchPlan(plan)) out.log(l); return plan.items.length ? 0 : 1; } } catch (e) { if (e instanceof BenchInputError) { out.error(`reports bench-verdicts: ${e.message}`); return 2; } throw e; } if (flags.here === true) { const gen = getSettings().generation; const refusal = await benchDailyCapRefusal(opts, deps.paths, gen); if (refusal) { out.error(`reports bench-verdicts: ${refusal}`); return 1; } const runId = opts.runId ?? newBenchRunId(); const ac = new AbortController(); const stop = () => ac.abort(); process.once("SIGINT", stop); try { const r = await runBenchWithSettings({ ...opts, runId }, { paths: deps.paths, gen, onLog: (l) => out.error(l), signal: ac.signal, jobId: `cli-${runId}`, gpu: false }); out.log(JSON.stringify({ run: r.id, dir: r.dir, status: r.summary.status, items: r.summary.items, spentUsd: r.summary.spentUsd, ...(r.summary.stopped ? { stopped: r.summary.stopped } : {}) })); return r.summary.status === "done" ? 0 : 1; } catch (e) { if (e instanceof BenchInputError) { out.error(`reports bench-verdicts: ${e.message}`); return 2; } throw e; } finally { process.off("SIGINT", stop); } } const body: Record = { models: opts.models }; if (opts.runId) body.run = opts.runId; if (opts.reports) body.reports = opts.reports; if (opts.windowS !== undefined) body.window = opts.windowS; if (opts.maxUsd !== undefined) body.maxUsd = opts.maxUsd; if (opts.limit !== undefined) body.limit = opts.limit; if (opts.windowMode !== undefined) body.windowMode = opts.windowMode; if (opts.itemsFrom !== undefined) body.itemsFrom = opts.itemsFrom; if (opts.dedupe) body.dedupe = true; return deps.runOps(["bench-verdicts", "--json", JSON.stringify(body), ...(flags.wait === true ? ["--wait"] : [])]); } export async function benchRow(ctx: CommandContext): Promise { return benchMain(ctx.flags, { paths: getPaths(), runOps: runOpsChild }); }