/** * Benchmark domain contracts: fixed cases, reference/candidate snapshots, and * the pure lifecycle functions that construct and validate them. The snapshot * constructor is deliberately named `buildSnapshot` (a pure structured-clone * capture) so the persisting `HarnessStore.captureSnapshot` method does not * collide with it. Atomic persistence for the `/benchmark/` store * lives in `benchmark-store.ts` (split out 2026-09-29). * @module dsh-continual-harness */ import type { HarnessState } from './types.ts'; /** A fixed benchmark case. Only `draft` cases may change; `frozen` cases are immutable. */ export interface BenchmarkCase { id: string; title: string; statement: string; /** Plaintext MVP rubric; only ever handed to the reviewer. */ rubric: string; /** * Binary-scored dimensions. When present they are authoritative for scoring * and `rubric` is the human-readable summary; when absent the reviewer * supplies a 0..100 score directly (legacy path). */ criteria?: BenchmarkCriterion[]; capability?: string; state: 'draft' | 'frozen'; createdAt: string; frozenAt?: string; } /** * One pre-declared, binary-scored dimension of a case. Declaring the dimensions * and their weights in code (rather than in the reviewer's prose) is what keeps * the model to judging and the arithmetic to the harness: the reviewer answers * `met` per criterion and `scoreFromVerdicts` produces the number. */ export interface BenchmarkCriterion { /** Stable id the reviewer echoes back in its per-dimension verdict. */ id: string; /** Relative weight; the total is `Σ weight·met / Σ weight · 100`. */ weight: number; /** What the evidence must show for this dimension to count as met. */ check: string; } /** Input fields for creating a draft case; lifecycle fields are stamped. */ export type BenchmarkCaseInput = Omit; /** * A read-only capture of the merged local/global harness state. `state` is a * structured-clone copy; `stateHash` is the canonical projection hash of that * copy; `refinementId` marks a candidate as "reference plus this refinement". * When `layers` is present (captured by the store), the two source layers are * retained so a candidate can be derived by applying a refinement to its own * layer and re-merging — a shadowed global entry must never be overwritten. */ export interface HarnessSnapshot { snapshotId: string; state: HarnessState; stateHash: string; refinementId?: string; capturedAt: string; /** The local/global layers at capture time; `state` is their merge. */ layers?: { local: HarnessState; global: HarnessState; }; } /** Structured executor output for one cell; unknown fields are rejected by the evaluator. */ export interface ExecutorEvidence { completed: boolean; summary: string; actions: string[]; observations: string[]; artifacts?: Array<{ name: string; content: string; }>; } /** * One A/B cell result. `score` is `0..100` (integer or finite decimal) for an * `ok` cell and `null` for a `failed` cell — failure is never counted as 0. */ export interface CellScore { runId: string; side: 'reference' | 'candidate'; caseId: string; iteration: number; score: number | null; status: 'ok' | 'failed'; failureReason?: string; /** * Bounded diagnostic for a failed cell: the specific parser error plus the * reply's length and tail. Without it a malformed executor reply is * indistinguishable after the fact from an oversized or wrongly-shaped one. */ failureDetail?: string; feedback?: string; snapshotId: string; stateHash: string; caseHash: string; executorProvider?: string; executorModel?: string; reviewerProvider?: string; reviewerModel?: string; durationMs?: number; recordedAt: string; } /** * Why a run could not be decided. Each value names one distinct blocker, so an * INCONCLUSIVE verdict says what to change instead of being a dead end. */ export type InconclusiveReason = 'empty-measurement-side' | 'insufficient-paired-observations' | 'no-noise-estimate' | 'difference-not-beyond-noise' | 'improvement-not-consistent'; /** Code-owned acceptance decision; the model never decides this. */ export interface BenchmarkDecision { runId: string; refinementId: string; /** * ACCEPTED requires an improvement that exceeds the observed run-to-run * noise; INCONCLUSIVE means the comparison cannot distinguish the candidate * from the reference — including when a side produced no usable cells at all, * which is a missing measurement rather than evidence against the candidate. * REJECTED therefore covers two measured outcomes: a regression, or a * comparison with nothing left to pair. */ status: 'ACCEPTED' | 'REJECTED' | 'INCONCLUSIVE'; /** Present only when `status` is INCONCLUSIVE: why the run could not decide. */ inconclusiveReason?: InconclusiveReason; /** Mean paired difference (candidate − reference); the decision's statistic. */ pairedDelta: number | null; /** Iterations scored on both sides — the decision's real sample size. */ pairs: number; referenceOverall: number | null; candidateOverall: number | null; /** Observed spread the candidate had to beat; `null` when unestimable. */ noiseFloor: number | null; regressionCases: string[]; failedCells: number; feedback: string[]; autoRollback: false; createdAt: string; } /** Why a candidate snapshot failed the unique-delta check. */ export type CandidateDeltaFailureReason = 'candidate-delta-mismatch' | 'history-mismatch' | 'refinement-not-found'; /** Structured result of {@link validateCandidateDelta}. */ export type CandidateDeltaResult = { ok: true; } | { ok: false; reason: CandidateDeltaFailureReason; }; /** Why a cell score failed validation. */ export type CellScoreFailureReason = 'score-non-finite' | 'score-out-of-range' | 'failed-cell-score-not-null' | 'ok-cell-score-required'; /** Structured result of {@link validateCellScore}. */ export type CellScoreValidationResult = { ok: true; } | { ok: false; reason: CellScoreFailureReason; }; /** Hard caps guarding model-driven benchmark growth (spec item 7). */ export declare const MAX_BENCH_CASES = 50; export declare const MAX_CASE_FIELD_CHARS = 20000; /** Create a mutable draft case; rejects empty material and duplicate ids. */ export declare function createBenchmarkCase(input: BenchmarkCaseInput, existingIds?: ReadonlySet): BenchmarkCase; /** * Freeze a draft case: stamps `frozenAt` and deep-freezes the result so the * evaluation material (`statement`, `rubric`, `capability`) can never change. * Refuses non-draft input, so re-freezing a mutated frozen case throws. */ export declare function freezeBenchmarkCase(benchmarkCase: BenchmarkCase): BenchmarkCase; /** * Hash only the frozen evaluation material — `id`, `statement`, `rubric`, * `capability` — in stable key order. Non-material fields (`title`, * `createdAt`, `frozenAt`) never affect the hash. Refuses drafts, whose * material is not yet stable. */ export declare function hashBenchmarkCase(benchmarkCase: BenchmarkCase): string; /** * Build a read-only snapshot from a merged state without persisting anything: * structured-clones the state, hashes the clone's canonical projection, and * stamps `snapshotId`, optional `refinementId`, and `capturedAt`. When the * source layers are passed, they are stored as structured clones and the * merged `state` must be their merge (the caller builds it that way). */ export declare function buildSnapshot(state: HarnessState, snapshotId: string, refinementId?: string, layers?: { local: HarnessState; global: HarnessState; }): HarnessSnapshot; /** The two source layers retained by a snapshot. */ export type SnapshotLayers = NonNullable; /** Resolve the scope/other layer pair for a refinement scope. */ export declare function scopeLayerPair(scope: 'local' | 'global'): { scope: 'local' | 'global'; other: 'local' | 'global'; }; /** Whether the merged view of the layers canonical-equals the given state. */ export declare function layersMergeToState(layers: SnapshotLayers, state: HarnessState): boolean; /** * Prove that `candidate` is exactly `reference` plus the one refinement * `refinementId` — never a drifted state. When both snapshots carry `layers`, * the proof runs per layer: the refinement's own layer (by `result.scope`) * must differ by exactly its applied edits with matching before/after entries, * the other layer must be canonical-identical, and the candidate's merged * `state` must equal the merge of its layers. Legacy single-layer snapshots * (no `layers`) fall back to the merged-state comparison. Returns a * structured failure reason; a drifted candidate is never silently accepted. */ export declare function validateCandidateDelta(reference: HarnessSnapshot, candidate: HarnessSnapshot, refinementId: string): CandidateDeltaResult; /** * Validate a cell score: an `ok` cell needs a finite score in `0..100` * (integer or finite decimal); a `failed` cell must carry `null` — failure is * never counted as 0 or any other number. */ export declare function validateCellScore(cell: CellScore): CellScoreValidationResult; /** Stable deterministic serialization: object keys sorted, arrays kept in order. */ export declare function canonicalJson(value: unknown): string; export declare function sha256(text: string): string; //# sourceMappingURL=benchmark.d.ts.map