import type { Digest, HeldoutAttempt, HeldoutBundle, HeldoutCalibration, HeldoutCalibrationPhase, HeldoutRow } from '../heldout/types.js'; import { CalibrationRegistry } from '../calibration/registry.js'; import type { CalibrationArtifact, CompatibilityDecision, CompatibilityPolicy } from '../calibration/types.js'; import type { prepareD17StagedStudy } from './staged.js'; import { type D17Review } from './artifacts.js'; /** * Staged D09 calibration for the D17 ensemble study (#2611). * * Calibration-phase observations are read only through the verified collector seal. The member * calibrator maps one fresh call's native P(yes); the aggregate calibrator maps the raw mean P(yes) * of the three ensemble members. Both are monotone (isotonic, pool-adjacent-violators) step * functions with Laplace-smoothed block frequencies, fitted on calibration-split rows only. Fitting * produces `CalibrationArtifact.v1` records in the `observed` state; only a separately anchored * operator review can approve them, and only an approved, D09-qualified pair can bind a test phase. */ type Prepared = ReturnType; type Role = 'member' | 'aggregate'; export interface D17CalibrationBlock { lower: number; upper: number; n: number; yes: number; probability: number; } export interface D17CalibrationMapping { schemaVersion: 'decision-d17-calibration-mapping/v1'; role: Role; calibrator: { id: string; version: '1'; }; method: 'isotonic-pav-laplace-v1'; model: 'jev-1.13.0'; splitDigest: Digest; definitionDigest: Digest; evidenceDigest: Digest; n: number; rows: number; blocks: D17CalibrationBlock[]; qualification: { method: 'slice-stratified-k-fold-out-of-fold'; folds: 5; outOfFold: D17CalibrationMetrics; inSample: D17CalibrationMetrics; }; } export interface D17CalibrationPin { artifactId: string; artifactDigest: Digest; mappingDigest: Digest; } export interface D17CalibrationSet { schemaVersion: 'decision-d17-calibration-set/v1'; corpusDigest: Digest; preregistrationDigest: Digest; calibrationPhaseRecordDigest: Digest; priorApprovalDigest: Digest; member: D17CalibrationPin; aggregate: D17CalibrationPin; } export interface D17CalibrationReview { schemaVersion: 'decision-d17-calibration-review/v1'; approved: true; reviewer: string; calibrationSetDigest: Digest; memberArtifactDigest: Digest; aggregateArtifactDigest: Digest; approvalReference: string; reviewedAt: string; } export interface D17SealedPhase { bundle: HeldoutBundle; source: 'provider' | 'injected-transport'; record: HeldoutCalibrationPhase; attempts: HeldoutAttempt[]; } export declare class D17CalibrationError extends Error { readonly reason: string; constructor(reason: string); } export declare const D17_COMPATIBILITY_POLICY: CompatibilityPolicy; /** The staged scope is preregistered; no other scope may fit, register or apply a D17 calibration. */ export declare function assertD17Staged(prepared: Prepared): void; /** Native P(yes) from the terminal successful attempt of one request, or null when it has no usable distribution. */ export declare function d17NativeYes(attempts: readonly HeldoutAttempt[], rowId: string, requestId: string): number | null; /** Attempts grouped by row, so per-row reads stay linear in the journal size. */ export declare function d17AttemptsByRow(attempts: readonly HeldoutAttempt[]): Map; /** Raw inputs of both calibrators for one row; null when a required call is unusable. */ export declare function d17RawProbabilities(attempts: readonly HeldoutAttempt[], row: Pick): { champion: number | null; members: (number | null)[]; mean: number | null; }; /** Deterministic isotonic fit: PAV on raw frequencies, minimum block support, then monotone Laplace smoothing. */ export declare function fitD17Isotonic(samples: ReadonlyArray<{ score: number; label: 0 | 1; }>, minimumBlockN?: number): D17CalibrationBlock[]; /** Step-function application: the last block whose lower score is at or below the input, else the first block. */ export declare function applyD17Mapping(mapping: Pick, score: number): number; export interface D17CalibrationMetrics { totalSamples: number; perSliceSamples: number; calibrationError: number; selectiveRisk: number; confidenceIntervals: { selectiveRisk: { lower: number; upper: number; }; coverage: { lower: number; upper: number; }; }; } /** Deterministic slice-stratified folds: calibration rows in record-ID order within each slice, index modulo folds. */ export declare function d17CalibrationFolds(rows: readonly HeldoutRow[], folds?: number): Map; /** * Fits both preregistered calibrators from calibration-split rows only. Tuning and test rows never contribute. The final * mapping uses the full calibration split; its qualification metrics are slice-stratified 5-fold out-of-fold, so a * calibrator is gated on rows it was not fitted on (in-sample metrics are recorded alongside, for comparison only). */ export declare function fitD17Calibration(prepared: Prepared, attempts: readonly HeldoutAttempt[]): Record; /** * The 40 development assessments must be complete, unambiguous and agree with both the generator gold and the * independent text oracle. `before` bounds every development review time; `testStagesBlank` refuses any test audit * recorded before the test phase (a blind test audit belongs after test collection). */ export declare function validateD17DevelopmentReview(prepared: Prepared, review: unknown, trustedDigest: unknown, options?: { before?: string; testStagesBlank?: boolean; }): D17Review; /** * Approvals carry no timestamp, so ordering is proved by digest: the calibration-phase approval reference must cite the * completed development review digest, which therefore existed before the approval that authorized any spend. */ export declare function assertD17ReviewBoundToApproval(approval: { approvalReference?: unknown; }, trustedDevelopmentReviewDigest: unknown): void; /** Fit both calibrators from a verified seal and emit observed artifacts plus unapproved operator forms. */ export declare function d17CalibrationHandoffFromSealed(input: { sealed: D17SealedPhase; prepared: Prepared; trustedApprovalDigest: Digest; trustedCalibrationPhaseRecordDigest: Digest; developmentReview: unknown; trustedDevelopmentReviewDigest: unknown; }): { mappings: Record; artifacts: { member: CalibrationArtifact; aggregate: CalibrationArtifact; }; set: D17CalibrationSet; calibrationSetDigest: `sha256:${string}`; reviewTemplate: { schemaVersion: string; approved: null; reviewer: null; calibrationSetDigest: `sha256:${string}`; memberArtifactDigest: `sha256:${string}`; aggregateArtifactDigest: `sha256:${string}`; approvalReference: null; reviewedAt: null; }; approval: { approved: boolean; runId: null; approvalReference: null; exactHeadCi: null; sourceCommit: null; calibration: { mode: string; phase: string; calibrationArtifactDigest: `sha256:${string}`; calibrationPhaseRecordDigest: `sha256:${string}`; priorApprovalDigest: `sha256:${string}`; }; schemaVersion: "decision-heldout-approval/v1"; study: import("../heldout/types.js").Study; reviewer: string; stagingHost: "titan"; stagingWorkspace: string; model: "jev-1.13.0"; servedModel: "jev-1.13.0"; region: string; credentialRef: string; credentialResolverDigest: Digest; corpusDigest: Digest; preregistrationDigest: Digest; executionDigest: Digest; providerTermsReference: string; priceBound: { inputUsdPerMTok: number; outputUsdPerMTok: number; perRequestUsd: number; outputTokenBound?: number; evidenceReferences: string[]; approvalReference: string; }; budget: { calls: number; tokens: number; usd: number; }; priorStudySpendUsd: number; priorPortfolioSpendUsd: number; }; }; /** D09 qualification at `at`: approved, compatible, unexpired, within the frozen profile and its selective-risk interval. */ export declare function qualifyD17Calibration(artifact: CalibrationArtifact, at: string, registry?: CalibrationRegistry): CompatibilityDecision; /** Operator review approves both observed artifacts; the approved pair forms a new set that binds the test phase. */ export declare function registerD17CalibrationFromHandoff(handoff: ReturnType, review: unknown, trustedReviewDigest: unknown): { artifacts: { member: CalibrationArtifact; aggregate: CalibrationArtifact; }; compatibility: { member: CompatibilityDecision; aggregate: CompatibilityDecision; }; set: D17CalibrationSet & Record; calibrationSetDigest: `sha256:${string}`; approval: { calibration: { calibrationArtifactDigest: `sha256:${string}`; mode: string; phase: string; calibrationPhaseRecordDigest: `sha256:${string}`; priorApprovalDigest: `sha256:${string}`; }; approved: boolean; runId: null; approvalReference: null; exactHeadCi: null; sourceCommit: null; schemaVersion: "decision-heldout-approval/v1"; study: import("../heldout/types.js").Study; reviewer: string; stagingHost: "titan"; stagingWorkspace: string; model: "jev-1.13.0"; servedModel: "jev-1.13.0"; region: string; credentialRef: string; credentialResolverDigest: Digest; corpusDigest: Digest; preregistrationDigest: Digest; executionDigest: Digest; providerTermsReference: string; priceBound: { inputUsdPerMTok: number; outputUsdPerMTok: number; perRequestUsd: number; outputTokenBound?: number; evidenceReferences: string[]; approvalReference: string; }; budget: { calls: number; tokens: number; usd: number; }; priorStudySpendUsd: number; priorPortfolioSpendUsd: number; }; mappings: Record; reviewTemplate: { schemaVersion: string; approved: null; reviewer: null; calibrationSetDigest: `sha256:${string}`; memberArtifactDigest: `sha256:${string}`; aggregateArtifactDigest: `sha256:${string}`; approvalReference: null; reviewedAt: null; }; }; export interface D17CalibrationContext { /** The calibration phase, re-read through the verified collector seal (`readHeldoutCalibrationPhase`). */ sealed: D17SealedPhase; /** Registered files as anchored by the operator; they must equal the deterministic re-derivation exactly. */ registered: { set: unknown; artifacts: Record; mappings: Record; }; trustedCalibrationSetDigest: Digest; calibrationReview: unknown; trustedCalibrationReviewDigest: Digest; developmentReview: unknown; trustedDevelopmentReviewDigest: Digest; /** First test access recorded by the collector (`frozen.testPhaseAccessAt`); null only before the test phase. */ testPhaseAccessAt: string | null; /** The scoring clock; qualification (approval, expiry, bounds) is evaluated at this instant. */ nowEpochMs: number; } /** * Test-phase verification. Nothing in the registered files is trusted: the calibration set is re-derived from the sealed * calibration phase (re-fit, out-of-fold metrics, operator review, approval), and the registered set, artifacts and * mappings must be canonically identical to that derivation and to the approved binding. The scoring clock cannot * precede the calibration review or the recorded first test access, and both artifacts must qualify at that clock. */ export declare function verifyD17CalibrationSet(prepared: Prepared, approvedCalibration: HeldoutCalibration, context: D17CalibrationContext): { set: D17CalibrationSet & Record; setDigest: `sha256:${string}`; member: { artifact: CalibrationArtifact; mapping: D17CalibrationMapping; compatibility: CompatibilityDecision; }; aggregate: { artifact: CalibrationArtifact; mapping: D17CalibrationMapping; compatibility: CompatibilityDecision; }; qualifiedAt: string; developmentReviewDigest: `sha256:${string}`; calibrationReviewDigest: `sha256:${string}`; }; export {}; //# sourceMappingURL=calibration.d.ts.map