import { C as ContinuousAgreementOptions, a as ContinuousAgreement } from './judge-calibration-DilmB3Ml.js';
import { a as JudgeScore } from './types-DhqpAi_z.js';
import { D as DatasetSplit, c as DatasetManifest, a as DatasetScenario } from './dataset-B2kL-fSM.js';
import { m as GateDecision } from './summary-report-ByiOUrHj.js';
import { R as RunRecord, b as RunSplitTag } from './run-record-BgTFzO2r.js';

/**
 * Release confidence gate.
 *
 * This is the production-facing composition layer over the lower-level
 * primitives:
 *   - Dataset manifests prove corpus/version coverage.
 *   - RunRecord rows prove reproducible search/holdout outcomes.
 *   - Multi-shot trace evidence carries turn counts and ASI diagnostics.
 *   - HeldOutGate decisions remain the paired promotion authority.
 *
 * The gate is intentionally pure and conservative. Missing declared evidence
 * fails closed instead of being treated as a neutral zero.
 */

/** Severity of an actionable finding attached to a run/trace. */
type AsiSeverity = 'info' | 'warning' | 'error' | 'critical';
/** Actionable side-info — a diagnosed finding the loop can act on. */
interface ActionableSideInfo {
    /** Stable expectation/check id when available. */
    expectationId?: string;
    /** Human-readable diagnosis of what happened. */
    message: string;
    severity?: AsiSeverity;
    /** Concrete trace excerpt, file path, tool call, screenshot id, etc. */
    evidence?: string;
    /** Prompt/tool/context surface likely responsible. */
    responsibleSurface?: string;
    /** Suggested fix in natural language. */
    suggestion?: string;
    /** Whether this expectation was satisfied. Defaults to false for ASI rows. */
    matched?: boolean;
    metadata?: Record<string, unknown>;
}
type ReleaseConfidenceStatus = 'pass' | 'warn' | 'fail';
type ReleaseConfidenceAxisName = 'corpus' | 'quality' | 'generalization' | 'diagnostics' | 'efficiency';
interface ReleaseTraceEvidence {
    scenarioId: string;
    candidateId?: string;
    split?: RunSplitTag;
    score?: number;
    ok?: boolean;
    turnCount?: number;
    costUsd?: number;
    durationMs?: number;
    failureMode?: string;
    asi?: ActionableSideInfo[];
    metadata?: Record<string, unknown>;
}
interface ReleaseConfidenceThresholds {
    /** Require a Dataset manifest or explicit scenarios. Default true. */
    requireCorpus?: boolean;
    minScenarioCount?: number;
    minSearchRuns?: number;
    minHoldoutRuns?: number;
    /** Require at least one holdout scenario/run. Default true. */
    requireHoldout?: boolean;
    minPassRate?: number;
    minMeanScore?: number;
    /** Search mean may exceed holdout mean by at most this much. */
    maxOverfitGap?: number;
    maxMeanCostUsd?: number;
    maxP95WallMs?: number;
    /** Low-score/failed rows must carry ASI. Default true. */
    requireAsiForFailures?: boolean;
    /** Score below this is considered a failure for ASI coverage. Default 0.5. */
    failureScoreThreshold?: number;
}
interface ReleaseConfidenceInput {
    target: string;
    candidateId?: string;
    baselineId?: string;
    dataset?: DatasetManifest;
    scenarios?: readonly DatasetScenario[];
    runs?: readonly RunRecord[];
    traces?: readonly ReleaseTraceEvidence[];
    gateDecision?: GateDecision | null;
    thresholds?: ReleaseConfidenceThresholds;
}
interface ReleaseConfidenceAxis {
    name: ReleaseConfidenceAxisName;
    status: ReleaseConfidenceStatus;
    score: number;
    detail: string;
}
interface ReleaseConfidenceIssue {
    axis: ReleaseConfidenceAxisName;
    severity: 'critical' | 'warning';
    code: string;
    detail: string;
}
interface ReleaseConfidenceMetrics {
    scenarioCount: number;
    searchRuns: number;
    holdoutRuns: number;
    passRate: number;
    meanScore: number;
    searchMeanScore: number;
    holdoutMeanScore: number;
    overfitGap: number;
    meanCostUsd: number;
    p95WallMs: number;
    failedRows: number;
    failuresWithAsi: number;
    singleShotTraces: number;
    multiShotTraces: number;
    splitCounts: Record<DatasetSplit, number>;
    domainCounts: Record<string, number>;
    failureModeCounts: Record<string, number>;
    responsibleSurfaceCounts: Record<string, number>;
}
interface ReleaseConfidenceScorecard {
    target: string;
    candidateId: string | null;
    baselineId: string | null;
    status: ReleaseConfidenceStatus;
    promote: boolean;
    axes: ReleaseConfidenceAxis[];
    issues: ReleaseConfidenceIssue[];
    metrics: ReleaseConfidenceMetrics;
    dataset: DatasetManifest | null;
    gateDecision: GateDecision | null;
    summary: string;
}
declare function evaluateReleaseConfidence(input: ReleaseConfidenceInput): ReleaseConfidenceScorecard;
declare function assertReleaseConfidence(input: ReleaseConfidenceInput): ReleaseConfidenceScorecard;

/**
 * Normalize scores so all dimensions follow "higher = better".
 * Inverted dimensions (hallucination, false_confidence, worst_failure)
 * already use inverted scoring in the prompt (10 = no hallucination),
 * but this function ensures consistency if raw scores leak through.
 */
declare function normalizeScores(scores: JudgeScore[]): JudgeScore[];
/** Weighted mean — falls back to uniform weights when omitted */
declare function weightedMean(scores: {
    score: number;
    weight?: number;
}[]): number;
/** Bootstrap confidence interval */
declare function confidenceInterval(scores: number[], confidence?: number, opts?: {
    seed?: number;
    resamples?: number;
}): {
    mean: number;
    lower: number;
    upper: number;
};
/**
 * Inter-rater reliability — simplified Krippendorff's alpha.
 *
 * Each inner array is one judge's scores for all items.
 * All arrays must have the same length (same items scored).
 */
declare function interRaterReliability(judgeScores: JudgeScore[][]): number;
/**
 * Mann-Whitney U test for comparing two independent groups.
 * Returns U statistic and approximate p-value (normal approximation).
 */
declare function mannWhitneyU(a: number[], b: number[]): {
    u: number;
    p: number;
};
/** Partial credit: returns 0-1 ratio of current toward target */
declare function partialCredit(current: number, target: number): number;
/**
 * Paired t-test — before/after measurements on the SAME items.
 * Pairing removes inter-item variance, giving tighter significance than
 * an unpaired test when comparing prompt v1 vs prompt v2 on identical
 * scenarios.
 */
declare function pairedTTest(before: number[], after: number[]): {
    t: number;
    df: number;
    p: number;
};
/**
 * Wilcoxon signed-rank test — paired non-parametric alternative.
 * Use when the differences aren't normally distributed.
 */
declare function wilcoxonSignedRank(before: number[], after: number[]): {
    w: number;
    p: number;
};
/**
 * Cohen's d — standardized effect size for two independent groups.
 * Positive d means group b has higher mean than group a.
 * Rule of thumb: |d| < 0.2 negligible, 0.2–0.5 small, 0.5–0.8 medium, > 0.8 large.
 */
declare function cohensD(a: number[], b: number[]): number;
type CliffsMagnitude = 'negligible' | 'small' | 'medium' | 'large';
/**
 * Cliff's delta — a non-parametric effect size for two independent samples.
 * `δ = (#(after > before) − #(after < before)) / (n_before · n_after)`,
 * ranging [-1, 1]. Positive ⇒ `after` tends to exceed `before` (improvement).
 *
 * Distribution-free counterpart to Cohen's d: no normality assumption, robust
 * to the bounded/skewed score distributions judges produce. Pairs with
 * `pairedBootstrap` / `wilcoxonSignedRank` for the non-parametric reporting
 * path. Returns 0 when either sample is empty.
 */
declare function cliffsDelta(before: number[], after: number[]): number;
/**
 * Map a Cliff's delta to a qualitative magnitude using the standard
 * Romano et al. thresholds (|δ|): <0.147 negligible, <0.33 small,
 * <0.474 medium, else large.
 */
declare function interpretCliffs(delta: number): CliffsMagnitude;
interface WeightedCompositeInput {
    /** Per-dimension scores (typically 0..1). */
    dims: Record<string, number>;
    /** Weight per dimension. Every weighted dimension MUST be present in
     *  `dims` — a weight for an absent dimension is a config error and throws,
     *  because silently dropping it would renormalise the composite onto a
     *  different denominator than intended. */
    weights: Record<string, number>;
    /** Optional pass threshold; when set, the result reports `pass`. */
    threshold?: number;
}
interface WeightedCompositeResult {
    composite: number;
    pass?: boolean;
}
/**
 * Weighted composite over judge dimensions: `Σ(score_d · w_d) / Σ(w_d)` across
 * the weighted dimensions. The canonical replacement for the per-consumer
 * hand-rolled composite math (tax/legal/creative/gtm each ship a copy).
 *
 * Fail-loud: throws if a weighted dimension is missing from `dims`, if any
 * weight is negative, or if the weights sum to 0 — none of which can produce
 * a meaningful composite.
 */
declare function weightedComposite(input: WeightedCompositeInput): WeightedCompositeResult;
interface CorpusScoreRecord {
    /** Stable identifier for the rated item (scenario, span, turn, …). */
    itemId: string;
    /** Identifier for the judge that produced this score. */
    judgeName: string;
    /** Dimension name (matches `JudgeScore.dimension`). */
    dimension: string;
    /** Numeric score; must be finite. */
    score: number;
}
interface CorpusAgreementPerDimension extends ContinuousAgreement {
    dimension: string;
    /** Item IDs that contributed to this dimension's matrix (every judge scored them). */
    itemIds: string[];
    /** Judge IDs that contributed to this dimension's matrix. */
    judgeIds: string[];
}
interface CorpusAgreementReport {
    /** Per-dimension ICC(2,1) + κ_w + Pearson + Spearman + bootstrap CIs. */
    perDimension: CorpusAgreementPerDimension[];
    /** Mean ICC across dimensions (NaN if no dimension yielded a finite ICC). */
    overallIcc: number;
    /** Mean weighted κ across dimensions (NaN if none finite). */
    overallWeightedKappa: number;
    /** Dimensions evaluated (sorted). */
    dimensions: string[];
    /** Judges seen across the corpus (sorted). */
    judgeIds: string[];
}
interface CorpusAgreementOptions extends ContinuousAgreementOptions {
    /**
     * Restrict the audit to these dimensions. Default = every dimension
     * that appears in the input. A dimension named here but absent from
     * the input throws — silent omission would corrupt the overall metric.
     */
    dimensions?: string[];
    /**
     * Restrict the audit to these judges. Default = every judge that
     * appears in the input. A judge named here but absent from a
     * dimension throws (see "fail loud" below).
     */
    judges?: string[];
}
/**
 * Corpus-wide inter-rater agreement across N items × M judges × D dimensions.
 *
 * For each dimension, builds the [n_items][n_judges] matrix of scores
 * (keeping only items every judge rated on that dimension), then runs
 * `continuousAgreement` to get ICC(2,1), κ_w, Pearson, Spearman, and
 * bootstrap CIs. Reports a pooled mean across dimensions as a single
 * "is this judge panel reliable on this corpus?" number.
 *
 * Fail-loud contract:
 *   - Empty input throws.
 *   - Fewer than 2 judges or fewer than 2 items per dimension throws.
 *   - A judge present in some dimensions but with zero scored items on
 *     another dimension throws (would silently shrink the matrix).
 *   - Duplicate (itemId, judgeName, dimension) records throw.
 */
declare function corpusInterRaterAgreement(records: CorpusScoreRecord[], opts?: CorpusAgreementOptions): CorpusAgreementReport;
/**
 * Convenience adapter for `JudgeScore[]` data keyed externally by item.
 *
 * Use when you have per-item arrays of `JudgeScore[]` (e.g. one
 * `ScenarioResult.judgeScores` per scenario) and want corpus-wide
 * agreement without manually flattening. `itemId` must be unique per
 * row of `itemsScores`.
 */
declare function corpusInterRaterAgreementFromJudgeScores(itemsScores: Array<{
    itemId: string;
    scores: JudgeScore[];
}>, opts?: CorpusAgreementOptions): CorpusAgreementReport;
/**
 * Required N per arm for a two-sample comparison at target effect size,
 * alpha, and power. Normal-approximation formula:
 *   n = 2 * ( (z_{1-α/2} + z_{1-β}) / d )^2
 * where d is Cohen's d. Returns Infinity for effect ≤ 0.
 */
declare function requiredSampleSize(opts: {
    effect: number;
    alpha?: number;
    power?: number;
    twoSided?: boolean;
}): number;
/**
 * Minimum detectable paired effect (standardised units) for a target paired
 * sample size: d_min = (z_{1-α/2} + z_β) / sqrt(n_paired). Multiply by
 * sd(deltas) for score units; treat as a lower bound — Wilcoxon and bootstrap
 * have asymptotic relative efficiency below 1 vs the t-test on heavy tails.
 */
declare function pairedMde(opts: {
    nPaired: number;
    alpha?: number;
    power?: number;
    twoSided?: boolean;
}): number;
/** Bonferroni adjustment: multiply every p-value by the test count, clamp at 1. */
declare function bonferroni(pValues: number[], alpha?: number): {
    adjusted: number[];
    significant: boolean[];
};
/**
 * Benjamini–Hochberg false discovery rate. Returns adjusted q-values and
 * significance at the target FDR; handles ties and preserves q monotonicity.
 */
declare function benjaminiHochberg(pValues: number[], fdr?: number): {
    qValues: number[];
    significant: boolean[];
};
interface PairedBootstrapResult {
    /** Number of paired observations. */
    n: number;
    /** Median of paired deltas (after − before). */
    median: number;
    /** Mean of paired deltas. */
    mean: number;
    /** Lower bound of the bootstrap CI on the chosen statistic. */
    low: number;
    /** Upper bound of the bootstrap CI on the chosen statistic. */
    high: number;
    /** Confidence level used (e.g. 0.95). */
    confidence: number;
    /** Number of bootstrap resamples used. */
    resamples: number;
}
interface PairedBootstrapOptions {
    /** Confidence level. Default 0.95. */
    confidence?: number;
    /** Bootstrap resample count. Default 2000. */
    resamples?: number;
    /** Statistic to bootstrap. Default 'median'. */
    statistic?: 'median' | 'mean';
    /** Deterministic seed. If omitted, uses Math.random(). */
    seed?: number;
}
/**
 * Paired bootstrap on (after − before) deltas. Returns a CI on the chosen
 * statistic (median by default); pairs are resampled with replacement. The
 * lower bound is what the promotion gate checks — `low > threshold` means the
 * gain is real at the confidence level. Throws on unequal sample sizes.
 */
declare function pairedBootstrap(before: number[], after: number[], opts?: PairedBootstrapOptions): PairedBootstrapResult;

/**
 * Bootstrap-CI promotion gate.
 *
 * In any iterative-improvement loop (GEPA, prompt evolution, dataset
 * curation), the question is "did this generation actually improve, or are
 * we celebrating noise?". With small N and noisy outcomes, point-estimate
 * deltas lie. Bootstrap confidence intervals tell the operator whether the
 * delta is real before code or prompts get promoted.
 *
 * This module is pure functions — no I/O, no model calls. Easy to unit-test
 * and to compose into any verdict gate.
 *
 * Default gate:
 *   - Bootstrap mean baseline vs candidate (1k resamples).
 *   - Compute the delta distribution; pass if the lower CI bound > 0.
 *   - Tunable confidence (default 95%) and resample count.
 *
 * Verdict semantics intentionally match the existing `experiments.jsonl`
 * vocabulary:
 *   - ADVANCE: candidate's CI lower bound > baseline mean (real win)
 *   - KEEP:    overlap, but candidate point estimate >= baseline (neutral)
 *   - REVERT:  candidate's CI upper bound < baseline mean (real regression)
 *   - INCONCLUSIVE: not enough samples or CI straddles zero with no signal
 */
type Verdict = 'ADVANCE' | 'KEEP' | 'REVERT' | 'INCONCLUSIVE';
interface BootstrapResult {
    baselineMean: number;
    candidateMean: number;
    /** candidateMean - baselineMean, point estimate. */
    delta: number;
    /** Lower bound of the (1 - alpha) CI on the delta. */
    ciLower: number;
    /** Upper bound of the (1 - alpha) CI on the delta. */
    ciUpper: number;
    /** Number of bootstrap resamples used. */
    iterations: number;
    alpha: number;
    verdict: Verdict;
}
interface BootstrapOptions {
    /** Confidence level alpha (default 0.05 → 95% CI). */
    alpha?: number;
    /** Number of resamples (default 1000). */
    iterations?: number;
    /**
     * Minimum total samples (baseline + candidate) below which we always
     * return INCONCLUSIVE — bootstrap with too few samples is meaningless.
     * Default 6 (combined).
     */
    minTotalSamples?: number;
    /** RNG seed for reproducibility. Default: Math.random. */
    seed?: number;
}
/**
 * Compute the bootstrap CI on (candidateMean - baselineMean) and a verdict.
 *
 * Uses simple percentile bootstrap on the difference of resampled means.
 * That's the standard non-parametric primitive — no distributional
 * assumptions, robust to skew, easy to reason about.
 */
declare function bootstrapCi(baseline: number[], candidate: number[], options?: BootstrapOptions): BootstrapResult;
/**
 * Judge-replay promotion gate.
 *
 * The cheap inner-loop judge that drives an evolution run is by definition
 * fast and noisy. When you're about to promote a winning variant to the
 * canonical default, you want a STRONGER judge (a more expensive model, a
 * human grader, a separately-trained reward model) to confirm the win
 * generalises beyond the inner loop.
 *
 * This helper takes raw winner + baseline outputs, scores both through the
 * stronger judge, and applies `bootstrapCi`. ADVANCE means the stronger
 * judge agrees the winner is real with the configured confidence. Doesn't
 * matter what shape your "output" is — pass a string, an object, anything
 * the judge can read.
 */
interface JudgeReplayGateArgs<TOutput> {
    baselineOutputs: TOutput[];
    candidateOutputs: TOutput[];
    /** Stronger judge — async to allow LLM calls. Return a 0..N scalar score. */
    judge: (output: TOutput) => Promise<number> | number;
    alpha?: number;
    iterations?: number;
    /** RNG seed for reproducibility. */
    seed?: number;
    /** Maximum concurrent judge calls. Default 4. */
    judgeConcurrency?: number;
}
declare function judgeReplayGate<TOutput>(args: JudgeReplayGateArgs<TOutput>): Promise<BootstrapResult & {
    baselineSamples: number;
    candidateSamples: number;
}>;

interface RenderReleaseReportOptions {
    title?: string;
    runs?: readonly RunRecord[];
    comparator?: string;
    traceAnalystFindings?: readonly string[];
    nextActions?: readonly string[];
}
declare function renderReleaseReport(scorecard: ReleaseConfidenceScorecard, options?: RenderReleaseReportOptions): string;

export { type ActionableSideInfo as A, type BootstrapOptions as B, type CliffsMagnitude as C, cliffsDelta as D, cohensD as E, confidenceInterval as F, corpusInterRaterAgreement as G, corpusInterRaterAgreementFromJudgeScores as H, interRaterReliability as I, type JudgeReplayGateArgs as J, interpretCliffs as K, mannWhitneyU as L, normalizeScores as M, pairedMde as N, pairedTTest as O, type PairedBootstrapOptions as P, partialCredit as Q, type ReleaseConfidenceAxis as R, requiredSampleSize as S, weightedComposite as T, weightedMean as U, type Verdict as V, type WeightedCompositeInput as W, type BootstrapResult as a, type PairedBootstrapResult as b, type ReleaseConfidenceAxisName as c, type ReleaseConfidenceInput as d, type ReleaseConfidenceIssue as e, type ReleaseConfidenceMetrics as f, type ReleaseConfidenceScorecard as g, type ReleaseConfidenceStatus as h, type ReleaseConfidenceThresholds as i, type ReleaseTraceEvidence as j, type RenderReleaseReportOptions as k, assertReleaseConfidence as l, benjaminiHochberg as m, bootstrapCi as n, evaluateReleaseConfidence as o, judgeReplayGate as p, pairedBootstrap as q, renderReleaseReport as r, type AsiSeverity as s, type CorpusAgreementOptions as t, type CorpusAgreementPerDimension as u, type CorpusAgreementReport as v, wilcoxonSignedRank as w, type CorpusScoreRecord as x, type WeightedCompositeResult as y, bonferroni as z };
