import { T as TraceEmitter } from './emitter-C2rqGH_l.js';
import { T as TraceStore } from './store-BcFXE6LG.js';
import { T as Trajectory, a as TrajectoryStep } from './trajectory-2TkpSEVh.js';

/**
 * Counterfactual replay — "what would have happened if we'd changed
 * exactly one thing at turn N?"
 *
 * The framework does NOT drive the agent — it sets up the replay
 * context (prior spans, prior state, mutation spec) and records the
 * resulting divergence. Consumers supply an `executeFrom(ctx)` callback
 * that runs their agent starting from turn N with the mutation applied.
 *
 * Counterfactual runs are recorded as a new Run with `layer='meta'` and
 * `parentRunId = originalRunId`, so downstream diff + correlation
 * pipelines see them natively.
 */

type CounterfactualMutation = {
    kind: 'swap-model';
    at: number;
    newModel: string;
} | {
    kind: 'swap-tool-result';
    at: number;
    newResult: unknown;
} | {
    kind: 'truncate-after';
    at: number;
} | {
    kind: 'inject-system-message';
    at: number;
    content: string;
} | {
    kind: 'custom';
    at: number;
    describe: string;
    apply: (step: TrajectoryStep) => TrajectoryStep;
};
interface CounterfactualContext {
    originalRunId: string;
    originalTrajectory: Trajectory;
    /** Steps up to (but not including) the mutation point — the prefix the
     *  replayed agent inherits as its prior conversation/tool history. */
    prefix: TrajectoryStep[];
    mutation: CounterfactualMutation;
    /** Pre-applied mutation on the step at `mutation.at`. Consumers use this
     *  as the FIRST step the replayed agent emits (they decide whether to
     *  re-emit it or continue from there). */
    mutatedStep: TrajectoryStep;
}
interface CounterfactualResult {
    counterfactualRunId: string;
    originalRunId: string;
    mutation: CounterfactualMutation;
    /** Structured delta summary — caller can extend via scoring. */
    delta: {
        originalOutcomeScore: number | null;
        counterfactualOutcomeScore: number | null;
        deltaScore: number | null;
    };
}
interface CounterfactualRunner {
    /**
     * Execute the agent from `ctx.prefix` with the mutation applied.
     * MUST emit spans into the provided emitter so they become part of
     * the counterfactual run. MUST call emitter.endRun() with a verdict.
     */
    executeFrom: (ctx: CounterfactualContext, emitter: TraceEmitter) => Promise<void>;
}
declare function runCounterfactual(store: TraceStore, originalRunId: string, mutation: CounterfactualMutation, runner: CounterfactualRunner): Promise<CounterfactualResult>;
/**
 * Aggregate a batch of counterfactuals into a simple attribution table:
 * which mutation kinds move outcomes most? (Useful when you run a grid
 * over the same trajectory — swap-model at every llm span, swap-tool
 * at every tool span — and want a ranked summary.)
 */
declare function attributeCounterfactuals(results: CounterfactualResult[]): Array<{
    mutationKind: CounterfactualMutation['kind'];
    n: number;
    meanAbsDelta: number;
    meanSignedDelta: number;
}>;

export { type CounterfactualMutation as C, attributeCounterfactuals as a, type CounterfactualRunner as b, type CounterfactualContext as c, type CounterfactualResult as d, runCounterfactual as r };
