import { R as Run, S as Span, a as TraceEvent, F as FailureClass } from './schema-m0gsnbt3.js';
import { T as TraceStore } from './store-BcFXE6LG.js';

/**
 * Failure taxonomy — canonical classes + a default classifier.
 *
 * Every failed run should end up in a named class. The classifier here
 * is rule-based (fast, deterministic); an LLM fallback can be added by
 * the consumer for novel cases and trained into the rule base over time.
 *
 * Consumers call `classifyFailure(run, spans, events)` and persist the
 * returned class as `Run.outcome.failureClass`.
 */

interface FailureContext {
    run: Run;
    spans: Span[];
    events: TraceEvent[];
}
interface FailureClassification {
    failureClass: FailureClass;
    reason: string;
    triggerSpanId?: string;
    triggerEventId?: string;
}
/** Ordered rules — first match wins. */
interface FailureRule {
    id: string;
    match: (ctx: FailureContext) => {
        failureClass: FailureClass;
        reason: string;
        triggerSpanId?: string;
        triggerEventId?: string;
    } | null;
}
declare const DEFAULT_RULES: FailureRule[];
/** Classify the failure mode of a run using an ordered rule list. */
declare function classifyFailure(ctx: FailureContext, rules?: FailureRule[]): FailureClassification;

/**
 * FailureClusterView — groups failed runs by (failureClass, triggerTool,
 * argHash-prefix) so weekly reviews can prioritize the top-N clusters.
 *
 * Each cluster includes: N runs, scenarios affected, representative
 * error message, a proposed mitigation hint (rule → action table).
 */

interface FailureCluster {
    failureClass: FailureClass;
    /** Tool name when the trigger was a tool span, else undefined. */
    toolName?: string;
    /** First 16 chars of argHash — clusters similar args. */
    argPrefix?: string;
    /**
     * Source dimension when the trigger was a judge span (e.g. `'format'`,
     * `'safety'`, `'correctness'`). Lets cross-template aggregators
     * group failures by the dimension that fired without overloading
     * `argPrefix`. Optional — clusters without this field deserialize cleanly.
     */
    dimension?: string;
    runCount: number;
    scenarioIds: string[];
    exampleError?: string;
    exampleRunId: string;
}
interface FailureClusterReport {
    clusters: FailureCluster[];
    totalFailures: number;
    totalRuns: number;
}
declare function failureClusterView(store: TraceStore, options?: {
    rules?: FailureRule[];
    minClusterSize?: number;
}): Promise<FailureClusterReport>;

export { DEFAULT_RULES as D, type FailureClusterReport as F, type FailureCluster as a, type FailureClassification as b, type FailureContext as c, type FailureRule as d, classifyFailure as e, failureClusterView as f };
