import type { RuleStore } from "../corpus/store.ts"; /** * Grading an answer, as pure functions. * * Nothing here calls a model. That is the point: the checks that decide whether * an answer may ship are deterministic, free, and testable without spending * anything, so they can be trusted and re-run. * * TWO FAILURES DISQUALIFY AN ANSWER, and they are the same lie told two ways. * * A cited rule number the corpus does not hold was invented. A confidently * cited wrong rule reads exactly like a correct one, and a reader has no way to * tell them apart without going and looking, which is the work they came here to * avoid. * * A quoted passage that appears nowhere in the corpus was also invented. This is * the worse of the two and the one a number-only check misses entirely: a real * rule number attached to made-up text is the same lie wearing a citation. * * Recall is REPORTED AND NEVER A GATE. An answer can cite four of seven expected * rules and be completely right, so failing it on recall would reject good work. */ export type EvalQuestion = { id: string; question: string; category: string; difficulty: string; expected_rule_numbers: string[]; rubric: string; }; /** * What counts as a rule citation in an answer. * * At least one dot segment is required, so "25 life" and "2026-03-01" are not * mistaken for rule numbers. Games number rules differently, so a corpus can * override it. */ export declare const DEFAULT_RULE_PATTERN: string; /** * Fold text so two renderings of the same sentence compare equal. * * Corpus text is plain; an answer is Markdown, and it arrives with emphasis * markers, curly quotation marks, and dashes a keyboard did not produce. Folding * both sides is what stops a correctly quoted rule reading as invented. */ export declare function foldWhitespace(text: string): string; /** * Whether a quoted passage is really in the corpus. * * A model frames a quote with its citation, and it frames it differently every * time: `**430.4.a**: "..."`, `**430.4.a** "..."`, `Rule 100.1 — ...`. The first * version of this parsed the framing off, and every framing it had not * anticipated marked a correctly quoted rule as invented. Four real quotes were * flagged on the grader's first live run. * * So this does not parse framing. It asks whether the quote, or the quote with a * few leading words dropped, appears in the corpus. Dropping leading words * cannot hide a fabrication: whatever remains still has to be text somebody * really wrote, and it still has to be long enough to mean something. */ /** * The share of a quotation that is really corpus text. * * Walks the quotation greedily: at each word, take the longest run from there * that appears in the corpus, count it, and continue after it. A quotation made * of two real rules therefore scores as two covered runs rather than as one * failed match, which is right — the model quoted two rules, it did not invent * anything. * * Returns a number between 0 and 1. */ export declare function quoteCoverage(quote: string, haystack: string): { ratio: number; uncovered: number; }; /** * Whether a quotation is grounded in the corpus. * * See MIN_QUOTE_COVERAGE for why this is a share and not an exact match. */ export declare function quoteIsGrounded(quote: string, haystack: string): boolean; /** Every rule-number-shaped token in an answer, de-duplicated, in order. */ export declare function extractRuleNumbers(answer: string, pattern?: string): string[]; /** * Every quoted passage in an answer, one per blockquote line. * * LINE BY LINE, NOT BLOCK BY BLOCK. The check is a substring test against the * whole corpus, so a line that is genuinely part of a rule matches even when the * sentence wraps across several lines. Joining a block first would instead fail * whenever a model puts two different rules in one blockquote, which it does. * * Short lines are dropped: a handful of words appears in almost any corpus by * chance, so checking them produces noise rather than signal. That errs toward * not flagging, which is right for a gate that blocks a release. */ export declare function extractQuotes(answer: string, minChars?: number): string[]; /** * Every piece of corpus text, folded, as one searchable haystack. * * `listRules` caps at 200 per call, so the whole corpus is paged. This is built * ONCE per evaluation run and reused for every question: a rulebook of a few * thousand rules is a few megabytes of text, and rebuilding it per answer would * dominate the run. */ export declare function buildHaystack(store: RuleStore): Promise; export type Grade = { id: string; category: string; difficulty: string; /** Rule numbers cited that the corpus does not hold. Any is a failure. */ fabricatedRules: string[]; /** Quoted passages found nowhere in the corpus. Any is a failure. */ fabricatedQuotes: string[]; /** Expected rules the answer cited, of those that exist in this corpus. */ recalled: string[]; /** Expected rules the answer did not cite. */ missed: string[]; /** Expected rules the corpus does not hold. An EVAL-SET bug, not a model one. */ staleExpectations: string[]; citedCount: number; quoteCount: number; answerChars: number; /** True when nothing was fabricated. This is the gate. */ clean: boolean; }; /** * Grade one answer. * * `haystack` comes from `buildHaystack`, built once for the run. */ export declare function gradeAnswer(question: EvalQuestion, answer: string, store: RuleStore, haystack: string, pattern?: string): Promise; export type Summary = { questions: number; clean: number; fabricatedRuleCount: number; fabricatedQuoteCount: number; /** Recall over every expected rule that exists in this corpus. */ recall: number; staleExpectationCount: number; }; export declare function summarise(grades: Grade[]): Summary; //# sourceMappingURL=grade.d.ts.map