/** * Scoring gates (`score`) — deterministic, composable output scorers. * * A `gate` phase may declare `score`: a list of zero-token deterministic * scorers (exact-match, contains, regex, json-schema, length-range, * code-compiles) evaluated against a target string, combined via * `all`/`any`/`weighted` against a threshold. When the deterministic * combination passes, the gate auto-passes with NO LLM call (mirroring the * `eval` fast-path); when it fails, control falls to the optional `llm-judge` * (`score.judge`) or the gate's regular `task`. * * This module is the PURE half (mirrors contract.ts): shape validation, * the 5 string scorers, combination, and report formatting. The impure * `code-compiles` scorer (spawns a compiler) lives in scorer-runtime.ts and * is dispatched by the runtime — never imported here. */ export declare const SCORER_TYPES: readonly ["exact-match", "contains", "regex", "json-schema", "length-range", "code-compiles"]; export type ScorerType = (typeof SCORER_TYPES)[number]; export declare const SCORE_COMBINE_MODES: readonly ["all", "any", "weighted"]; export type ScoreCombineMode = (typeof SCORE_COMBINE_MODES)[number]; /** Default weighted-combine threshold (used when `score.threshold` is omitted). */ export declare const SCORE_DEFAULT_THRESHOLD = 0.5; /** Languages the code-compiles scorer can check (see scorer-runtime.ts). */ export declare const CODE_COMPILES_LANGUAGES: readonly ["javascript", "typescript"]; export interface Scorer { type: ScorerType; /** Result label; defaults to `-`. */ name?: string; /** [exact-match|contains] The string to compare/find. */ value?: string; /** [regex] JS RegExp source. An invalid pattern fails the scorer (with detail). */ pattern?: string; /** [regex] Invert the match result. */ negate?: boolean; /** [json-schema] An `expect`-style contract for the parsed target. */ schema?: unknown; /** [length-range] Inclusive bounds on target length (chars). */ min?: number; max?: number; /** [code-compiles] Which compiler to run. */ language?: (typeof CODE_COMPILES_LANGUAGES)[number]; } export interface ScorerResult { name: string; type: ScorerType; passed: boolean; /** 0 or 1 for deterministic scorers; the judge's [0,1] score when present. */ score: number; detail?: string; } /** The `score` field's shape (validated by scorerShapeErrors, not TypeBox — * keeps diagnostics precise and the surface documented in one place). */ export interface ScoreConfig { /** Interpolation ref for the scored string. Default: "{previous.output}". */ target?: string; scorers: Scorer[]; combine?: ScoreCombineMode; /** [weighted] Aligned to scorers (+1 trailing judge weight when judge present). */ weights?: number[]; /** [weighted] Combined score cutoff in (0, 1]. Default 0.5. */ threshold?: number; /** Optional LLM-as-judge fallback, run only when the deterministics fail. */ judge?: { agent?: string; task: string; }; } /** * Statically check an author-written `score` value. Returns human-readable * shape errors ([] = valid). Total: never throws on arbitrary JSON-valid * input. Mirrors contractShapeErrors (the `expect` validator). */ export declare function scorerShapeErrors(score: unknown, path?: string): string[]; /** Default result label for a scorer. */ export declare function scorerName(s: Scorer, index: number): string; /** * Evaluate one PURE scorer against the target string. Total: never throws — * an invalid configuration (e.g. a bad regex) fails the scorer with a detail. * `code-compiles` is NOT handled here (impure — see scorer-runtime.ts). */ export declare function evaluatePureScorer(scorer: Scorer, index: number, target: string): ScorerResult; /** * Combine deterministic scorer results per the combine mode. `judgeWeight` * (weighted mode, judge configured but NOT yet run) enlarges the denominator * so the deterministic-only combination is a LOWER BOUND: when it already * clears the threshold, the judge's score could not change the outcome and * the gate may auto-pass without spending judge tokens. */ export declare function combineScores(results: ScorerResult[], combine: ScoreCombineMode, weights?: number[], threshold?: number, judgeWeight?: number): { combined: number; passed: boolean; }; /** Fold a completed judge result into a weighted combination (judge = last weight). */ export declare function combineWithJudge(results: ScorerResult[], weights: number[] | undefined, threshold: number, judgeScore: number): { combined: number; passed: boolean; }; /** Human-readable scorer report — appended to the judge/gate prompt so the * LLM sees exactly which deterministic checks failed and why. */ export declare function formatScorerReport(results: ScorerResult[], combined: number, threshold?: number): string; /** The structured score result stored as the gate's `ps.json` — reachable * downstream via `{steps..json.combined}` / `...json.results.0.passed`. */ export declare function scoreResultJSON(results: ScorerResult[], combined: number, verdict: "pass" | "block", threshold?: number, judge?: { score: number; reason?: string; }): Record; /** Matches `VERDICT: PASS|BLOCK|FAIL|STOP|OK|REJECT|HALT` (last occurrence wins). */ export declare const VERDICT_TOKEN_RE: RegExp; /** Matches `SCORE: 0.x` (last occurrence wins), emphasis-tolerant. */ export declare const SCORE_TOKEN_RE: RegExp; /** Matches `WINNER: n` (last occurrence wins), emphasis-tolerant; `#n` allowed. */ export declare const WINNER_TOKEN_RE: RegExp; /** * Parse an LLM judge's output into a score + verdict. Accepts JSON * ({score: 0..1, verdict?, reason?}), bare {verdict}, or a text * `SCORE: 0.x` / `VERDICT: PASS|BLOCK` marker. **Fail-closed** per the gate * safety stance (issue #54): unparseable *model* output BLOCKS with score 0. * Config/resolution errors (unresolved score.target, malformed scorers) are a * different path and remain fail-open with a warning — they are authoring * slips, not a judge that could not reach a verdict. */ export declare function parseJudgeOutput(output: string): { score: number; verdict: "pass" | "block"; reason?: string; parsed: boolean; }; //# sourceMappingURL=scorers.d.ts.map