import { V as ValidationError } from './errors-mje_cKOs.js';
import { F as FailureClass } from './schema-m0gsnbt3.js';

type AgentProfileCellSchemaVersion = 'agent-profile-cell/v1';
type AgentProfileJson = string | number | boolean | null | AgentProfileJson[] | {
    [key: string]: AgentProfileJson;
};
type AgentProfileDimensionValue = string | number | boolean | null;
interface AgentProfileSource {
    /** Runtime/profile contract being fingerprinted, e.g. `sandbox-agent-profile`. */
    kind: string;
    /** sha256 over the canonical source profile object. */
    hash: string;
}
interface AgentProfileSourceInput {
    kind: string;
    /** Precomputed sha256 for callers that already sign their profile artifact. */
    hash?: string;
    /** Full canonical runtime profile; hashed and then discarded from the cell. */
    profile?: AgentProfileJson;
}
interface AgentProfileHarness {
    id: string;
    version?: string;
    hash?: string;
}
interface AgentProfileCellInput {
    profileId: string;
    sourceProfile: AgentProfileSourceInput;
    harness?: AgentProfileHarness;
    model?: string;
    promptHash?: string;
    dimensions?: Record<string, AgentProfileDimensionValue>;
}
interface AgentProfileCell {
    schemaVersion: AgentProfileCellSchemaVersion;
    cellId: string;
    profileId: string;
    sourceProfile: AgentProfileSource;
    harness?: AgentProfileHarness;
    model?: string;
    promptHash?: string;
    dimensions?: Record<string, AgentProfileDimensionValue>;
}
declare class AgentProfileCellValidationError extends ValidationError {
    readonly path: string;
    constructor(message: string, path?: string);
}
declare function buildAgentProfileCell(input: AgentProfileCellInput): Promise<AgentProfileCell>;
declare function agentProfileCellHashMaterial(cell: AgentProfileCell): Omit<AgentProfileCell, 'cellId'>;
declare function verifyAgentProfileCell(cell: AgentProfileCell): Promise<boolean>;
declare function validateAgentProfileCell(input: unknown): AgentProfileCell;
declare function requireAgentProfileCell(record: {
    runId: string;
    agentProfile?: AgentProfileCell;
}): AgentProfileCell;
declare function agentProfileCellKey(record: {
    runId: string;
    agentProfile?: AgentProfileCell;
}): string;
declare function assertRunAgentProfileCell(record: {
    runId: string;
    model: string;
    promptHash: string;
    agentProfile?: AgentProfileCell;
}): Promise<AgentProfileCell>;
declare function groupRunsByAgentProfileCell<T extends {
    runId: string;
    agentProfile?: AgentProfileCell;
}>(records: readonly T[]): Map<string, T[]>;
/** Canonical `sourceProfile.kind` values. Two products fingerprinting the
 *  same canonical profile MUST use the same kind for their cells to share
 *  `sourceProfile.hash`. Extend rather than create new strings — adding a
 *  new kind is a deliberate cross-product schema change. */
declare const AGENT_PROFILE_KINDS: {
    /** A profile declared via `defineAgentProfile(...)` from
     *  `@tangle-network/sandbox`. The default kind for sandbox-hosted
     *  products (gtm-agent, blueprint-agent, sandbox, evals). */
    readonly SANDBOX_AGENT_PROFILE: "sandbox-agent-profile";
};
type AgentProfileKind = (typeof AGENT_PROFILE_KINDS)[keyof typeof AGENT_PROFILE_KINDS];
/** Canonicalize an arbitrary value into `AgentProfileJson` by JSON
 *  round-trip. Throws when the value contains anything not representable
 *  as JSON (functions, BigInt, cycles) — non-portable profiles fail loud
 *  rather than silently dropping fields. */
declare function toAgentProfileJson(value: unknown): AgentProfileJson;
/** Minimal shape required of any sandbox-SDK `AgentProfile` — anything
 *  with a non-empty `name` and `version` plus JSON-serializable contents.
 *  Compatible with `defineAgentProfile(...)` output from
 *  `@tangle-network/sandbox`; products that have not yet declared a real
 *  profile can pass a `{ name, version, ...metadata }` stub. */
interface SandboxAgentProfileLike {
    name: string;
    version: string;
    [key: string]: unknown;
}
/** Higher-level helper that hard-codes the canonical
 *  `sandbox-agent-profile` kind plus the JSON canonicalization. Equivalent
 *  to calling `buildAgentProfileCell` with `profileId = \`${name}@${version}\``
 *  and `sourceProfile = { kind: SANDBOX_AGENT_PROFILE, profile: <round-tripped> }`.
 *
 *  Use this from any product consuming a sandbox-SDK `AgentProfile`; the
 *  manual `buildAgentProfileCell` call is reserved for advanced cases
 *  (custom kinds, pre-computed source hashes, alternate profileId
 *  conventions). */
declare function buildSandboxAgentProfileCell(profile: SandboxAgentProfileLike, input: Omit<AgentProfileCellInput, 'profileId' | 'sourceProfile'>): Promise<AgentProfileCell>;

/**
 * Paper-grade RunRecord schema + runtime validator.
 *
 * Every run that participates in a promotion gate, paper table, or
 * researcher loop SHOULD be recorded as a `RunRecord`. The mandatory
 * fields are exactly those the paper "Two Loops, Three Roles" requires
 * for reproducibility: who/what/when/cost/seed/hash, plus the search vs
 * holdout split tag and either a `searchScore` or a `holdoutScore`.
 *
 * This is intentionally NOT a replacement for the rich `Run` /
 * `ProposeReviewReport` / `ScenarioResult` types already in the
 * package. Those are runtime structures with full provenance. A
 * `RunRecord` is the analysis-time projection — the JSON-friendly
 * row you'd put in a parquet file or paste into a notebook.
 *
 * Validate at the boundary:
 *
 *   const rec = validateRunRecord(rawJson)         // throws on missing
 *   const ok  = isRunRecord(rawJson)               // boolean check
 *   const rec = parseRunRecordSafe(rawJson)        // { ok, value | error }
 *
 * The validator runs in pure TS — zod is intentionally NOT a
 * dependency. Round-trip tested in `tests/run-record.test.ts`.
 */

/** Search/dev/holdout split tag. 'search' is the paper-grade alias for the
 *  combined train+test pool that the optimizer is allowed to read. */
type RunSplitTag = 'search' | 'dev' | 'holdout';
interface RunTokenUsage {
    input: number;
    output: number;
    cached?: number;
}
interface RunJudgeMetadata {
    model: string;
    promptVersion: string;
    /** [0,1] confidence the judge declared. Constant judge confidence
     *  across many runs is a fallback signal (see `canary.ts`). */
    confidence: number;
    /** True if the judge degraded to a fallback path (rules-only,
     *  prior-call cache, etc.). The canary uses this to alert. */
    fallback: boolean;
}
/**
 * Per-judge / per-dimension breakdown for runs scored by an ensemble of
 * judges over a multi-dimensional rubric.
 *
 * The collapsed `outcome.searchScore` / `holdoutScore` carries the
 * composite the gate uses. The full breakdown belongs here so consumers
 * can answer "which judge disagreed?", "which dimension dragged the
 * composite down?", and "did half the panel fail?" without re-running.
 *
 * `perJudge[judgeId][dim]` is the canonical source; `perDimMean` and
 * `composite` are convenience projections — derivable but precomputed so
 * downstream IRR primitives (`interRaterReliability`,
 * `corpusInterRaterAgreement`) and reporters don't pay the same
 * aggregation twice.
 *
 * Fail-loud discipline: judges that errored out land in `failedJudges`
 * by id. A missing key in `perJudge` is ambiguous (silent zero vs not
 * run); the explicit list makes a partial-failure recorded as such.
 */
interface JudgeScoresRecord {
    /** Per-judge per-dimension scores. `{ "kimi-k2.6": { helpfulness: 0.8, clarity: 0.7 }, ... }`. */
    perJudge: Record<string, Record<string, number>>;
    /** Per-dim mean across judges. Convenience — derivable from `perJudge`. */
    perDimMean: Record<string, number>;
    /** Composite mean across all dims and judges. Mirrors the score
     *  the gate sees on `outcome.searchScore` / `holdoutScore`. */
    composite: number;
    /** Judges that errored or returned an unparseable verdict. Recorded
     *  by id (e.g. `['glm-5.1']`) so a partial-failure case is explicit,
     *  not inferred from missing keys in `perJudge`. */
    failedJudges?: string[];
    /** Free-form notes the judges emitted (joined across judges or
     *  first-judge only — consumer's choice). */
    notes?: string;
}
interface RunOutcome {
    /** Score on the search/optimization split. Optional because a
     *  holdout-only evaluation only fills `holdoutScore`. */
    searchScore?: number;
    /** Score on the held-out split. Optional because a search-only run
     *  only fills `searchScore`. At least one must be present. */
    holdoutScore?: number;
    /** Bag of any other metric the run produced — judge dimensions,
     *  pass/fail counters, latency stats, etc. Numeric only — keeps
     *  reporters honest. */
    raw: Record<string, number>;
    /** Per-judge / per-dim breakdown. Consumers writing ensemble
     *  judgements populate this; substrate primitives like
     *  `interRaterReliability` and `corpusInterRaterAgreement` accept
     *  these records as input. Optional — single-judge or scalar-only
     *  runs leave it unset. */
    judgeScores?: JudgeScoresRecord;
}
/**
 * Mandatory paper-grade fields for a single evaluation run. Optional
 * fields are extension points; mandatory fields throw if missing.
 *
 * Hash discipline:
 *   - `promptHash` is the sha256 of the EFFECTIVE prompt sent to the
 *     model (after any steering bundle merge).
 *   - `configHash` is the sha256 of the effective run config (model,
 *     temperature, tools, judges, splits). The pair (promptHash,
 *     configHash) uniquely identifies an experimental cell.
 *
 * Model snapshot discipline:
 *   - `model` MUST encode a snapshot version. Bare aliases like
 *     `claude-sonnet-4` or `gpt-4o` are banned — they remap silently.
 *     Use `claude-sonnet-4-6@2025-04-15` or `gpt-4o-2024-11-20`.
 */
interface RunRecord {
    /** UUID for the run. */
    runId: string;
    /** Logical experiment grouping (a treatment vs a baseline within
     *  the same sweep should share `experimentId`). */
    experimentId: string;
    /** Stable identifier for the candidate (variant) being run. The
     *  promotion gate compares two `candidateId`s on matched items. */
    candidateId: string;
    /** RNG seed for the run. Always recorded — silent re-seeding is
     *  the most common cause of non-reproducible numbers. */
    seed: number;
    /** Model identifier WITH snapshot version. */
    model: string;
    /** sha256 of the effective prompt (post-steering). */
    promptHash: string;
    /** sha256 of the effective config. */
    configHash: string;
    /** Git SHA the harness was run from. */
    commitSha: string;
    /** End-to-end wall-clock duration in milliseconds. */
    wallMs: number;
    /** Time spent queued before execution started, if known. */
    queueMs?: number;
    /** Total USD cost. Mandatory — runs without a cost number are
     *  unbounded by definition and must not be admitted into the gate. */
    costUsd: number;
    /** Token usage breakdown. */
    tokenUsage: RunTokenUsage;
    /** Judge-side metadata, if a judge was used. */
    judgeMetadata?: RunJudgeMetadata;
    /** Per-split scores + raw bag. */
    outcome: RunOutcome;
    /** Canonical, cross-agent failure class drawn from the shared
     *  `FAILURE_CLASSES` taxonomy. This is the aggregation key that makes
     *  "which failure dominates across the whole fleet" answerable in ONE
     *  vocabulary — every agent classifies against the same enum. Producers
     *  set it via the substrate classifier; leave unset only when the failure
     *  genuinely can't be classified. */
    failureClass?: FailureClass;
    /** Free-form domain-specific failure detail, scoped UNDER `failureClass`
     *  (e.g. failureClass='tool_recovery_failure', failureMode='forge_build_unsatisfied').
     *  The within-agent drill-down; `failureClass` is the cross-agent key. */
    failureMode?: string;
    /** Which split this run was drawn from. */
    splitTag: RunSplitTag;
    /**
     * Stable scenario identifier the run was scored against. Optional for
     * backwards compatibility, but **strongly recommended**: every primitive
     * that pairs runs by scenario (preferences, paired stats, BT tournament)
     * keys on this. The campaign artifact populates it canonically; legacy
     * runs without it fall back to inference from `outcome.raw.scenario_id`
     * or `experimentId`.
     */
    scenarioId?: string;
    /**
     * Canonical identity for the agent profile cell that produced this row:
     * profile artifact hash plus optional harness/model/prompt/reporting
     * dimensions. Use `agentProfile.cellId` to group persona sweeps and
     * longitudinal reports by the complete source profile, not by a loose
     * candidate label or opaque config hash.
     */
    agentProfile?: AgentProfileCell;
}
declare class RunRecordValidationError extends ValidationError {
    readonly path: string;
    constructor(message: string, path?: string);
}
/**
 * Strict validator. Throws `RunRecordValidationError` on the first
 * missing or wrongly-typed field. Returns the input cast to
 * `RunRecord` on success — the validator does not coerce.
 */
declare function validateRunRecord(input: unknown): RunRecord;
/** Boolean validator — convenience for filtering arrays. */
declare function isRunRecord(input: unknown): input is RunRecord;
/** Non-throwing validator — returns a discriminated union. */
declare function parseRunRecordSafe(input: unknown): {
    ok: true;
    value: RunRecord;
} | {
    ok: false;
    error: RunRecordValidationError;
};
/** Round-trip helper — `JSON.parse(JSON.stringify(record))` then validate. */
declare function roundTripRunRecord(record: RunRecord): RunRecord;

export { type AgentProfileCell as A, validateAgentProfileCell as B, validateRunRecord as C, verifyAgentProfileCell as D, type JudgeScoresRecord as J, type RunRecord as R, type SandboxAgentProfileLike as S, type RunSplitTag as a, type RunTokenUsage as b, type RunJudgeMetadata as c, type AgentProfileCellInput as d, AGENT_PROFILE_KINDS as e, type AgentProfileCellSchemaVersion as f, AgentProfileCellValidationError as g, type AgentProfileDimensionValue as h, type AgentProfileHarness as i, type AgentProfileJson as j, type AgentProfileKind as k, type AgentProfileSource as l, type AgentProfileSourceInput as m, type RunOutcome as n, RunRecordValidationError as o, agentProfileCellHashMaterial as p, agentProfileCellKey as q, assertRunAgentProfileCell as r, buildAgentProfileCell as s, buildSandboxAgentProfileCell as t, groupRunsByAgentProfileCell as u, isRunRecord as v, parseRunRecordSafe as w, requireAgentProfileCell as x, roundTripRunRecord as y, toAgentProfileJson as z };
