import { h as BudgetSpec, R as Run, T as ToolSpan } from '../schema-m0gsnbt3.js';
import { T as TraceStore, R as RunFilter } from '../store-BcFXE6LG.js';
export { a as FailureCluster, F as FailureClusterReport, f as failureClusterView } from '../failure-cluster-DH9Flgcf.js';
import { a as TrajectoryStep } from '../trajectory-2TkpSEVh.js';
import { B as BaselineOptions, a as BaselineReport } from '../baseline-Bbid3WoO.js';
export { c as computeToolUseMetrics } from '../baseline-Bbid3WoO.js';
import { l as llmSpans } from '../query-B7GGjRox.js';

/**
 * BudgetBreachView — aggregates breach events across the corpus.
 *
 * Answers: which dimensions get hit most often? Which scenarios are
 * underbudgeted? Which variants trigger the most breaches?
 */

interface BudgetBreachFinding {
    runId: string;
    scenarioId: string;
    variantId?: string;
    dimension: keyof BudgetSpec;
    limit: number;
    consumed: number;
    excessRatio: number;
    timestamp: number;
}
interface BudgetBreachReport {
    findings: BudgetBreachFinding[];
    byDimension: Record<string, number>;
    byScenario: Record<string, number>;
    byVariant: Record<string, number>;
    totalRuns: number;
    breachedRunRatio: number;
}
declare function budgetBreachView(store: TraceStore, options?: {
    scenarioId?: string;
    variantId?: string;
}): Promise<BudgetBreachReport>;

/**
 * FirstDivergenceView — aligns two trajectories by step index, reports
 * the first step where they differ.
 *
 * "Differ" is configurable — default is (kind, toolName if tool, model
 * if llm). Use this view to attribute "why is variant B better?" to a
 * specific step rather than an aggregate mean delta.
 */

interface DivergenceReport {
    runA: string;
    runB: string;
    firstDivergenceIndex: number | null;
    aStep?: TrajectoryStep;
    bStep?: TrajectoryStep;
    reason?: string;
    /** Common prefix length (steps that matched). */
    commonPrefixLen: number;
}
interface DivergenceOptions {
    /** Returns true if two steps are considered equal. Default: kind + tool/model match. */
    stepEquals?: (a: TrajectoryStep, b: TrajectoryStep) => boolean;
}
declare function firstDivergenceView(store: TraceStore, runA: string, runB: string, options?: DivergenceOptions): Promise<DivergenceReport>;

/**
 * JudgeAgreementView — pairwise agreement between judges across the
 * corpus, grouped by dimension.
 *
 * Output drives two workflows:
 *   - Judge robustness audit: "does Claude agree with GPT at κ ≥ 0.6?"
 *   - Calibration tracking: κ vs golden human labels over time (by
 *     providing a `humanGoldenJudgeId`).
 */

interface JudgePair {
    judgeA: string;
    judgeB: string;
    dimension: string;
    /** Number of (targetSpanId, dimension) tuples both judges scored. */
    commonItems: number;
    pearson: number;
    krippendorff: number;
}
interface JudgeAgreementReport {
    pairs: JudgePair[];
    dimensions: string[];
    judgeIds: string[];
}
declare function judgeAgreementView(store: TraceStore): Promise<JudgeAgreementReport>;

/**
 * RegressionView — compares a candidate slice to a baseline slice on a
 * named metric. Delegates the statistics (Welch's t-test, Cohen's d,
 * IQR stability) to `baseline.ts`.
 *
 * This is the entry point for CI regression gates: "given runs tagged
 * release=A and release=B, did any metric regress?"
 */

interface RegressionSpec {
    metric: string;
    higherIsBetter: boolean;
    /** Extract a scalar from a run. Default extractors handle common metrics. */
    extract?: (run: Run, store: TraceStore) => Promise<number | null>;
}
interface RegressionOptions extends BaselineOptions {
    baseline: RunFilter;
    candidate: RunFilter;
}
declare function regressionView(store: TraceStore, metrics: RegressionSpec[], options: RegressionOptions): Promise<BaselineReport>;

/**
 * StuckLoopView — detects when an agent calls the same tool with the
 * same (or structurally similar) arguments ≥ N times in a short window.
 *
 * Rationale: agents that loop are the number-one production failure
 * mode on long-horizon flows. The view returns (runId, toolName,
 * argHash, occurrences, windowMs) for each detected loop plus a
 * fraction of runs affected.
 */

interface StuckLoopFinding {
    runId: string;
    toolName: string;
    argHash: string;
    occurrences: number;
    spanIds: string[];
    /** Milliseconds between first and last call in the loop. */
    windowMs: number;
}
interface StuckLoopReport {
    findings: StuckLoopFinding[];
    affectedRunRatio: number;
    totalRuns: number;
}
interface StuckLoopOptions {
    /** Minimum call count to flag a loop (default 3). */
    minOccurrences?: number;
    /** Filter to a specific runId; omit to scan the entire corpus. */
    runId?: string;
}
declare function stuckLoopView(store: TraceStore, options?: StuckLoopOptions): Promise<StuckLoopReport>;

/**
 * ToolWasteView — fraction of tool calls whose results weren't used
 * downstream. Without a "used" signal we fall back to structural
 * proxies: error calls, duplicate calls, and tool calls followed by
 * zero subsequent LLM spans are all considered waste.
 *
 * Consumers can pass a `usageOracle` that inspects a tool span and
 * returns true iff the tool's result appears in a later LLM message,
 * artifact, or state mutation — that's the canonical definition; the
 * default heuristic is a reasonable fallback.
 */

interface ToolWasteFinding {
    runId: string;
    wastedCalls: number;
    totalCalls: number;
    wasteRate: number;
}
interface ToolWasteReport {
    byRun: ToolWasteFinding[];
    overallWasteRate: number;
}
interface ToolWasteOptions {
    runId?: string;
    usageOracle?: (tool: ToolSpan, later: {
        llm: Awaited<ReturnType<typeof llmSpans>>;
    }) => boolean;
}
declare function toolWasteView(store: TraceStore, options?: ToolWasteOptions): Promise<ToolWasteReport>;

export { type BudgetBreachFinding, type BudgetBreachReport, type DivergenceOptions, type DivergenceReport, type JudgeAgreementReport, type JudgePair, type RegressionOptions, type RegressionSpec, type StuckLoopFinding, type StuckLoopOptions, type StuckLoopReport, type ToolWasteFinding, type ToolWasteOptions, type ToolWasteReport, budgetBreachView, firstDivergenceView, judgeAgreementView, regressionView, stuckLoopView, toolWasteView };
