/**
 * Propose / Verify / Review — the core multi-shot primitive.
 *
 *   shot N:  propose(state, priorReview) → new state
 *            verify(state)               → pass/fail, optional layers
 *            review(state, verification, memory) → observations + next-shot
 *                                                   instruction + shouldContinue
 *            memory.append(entry)
 *
 * Roles are strictly separated:
 *
 *   - The WORKER is whatever the caller wraps in `propose`. It is
 *     stateful — caller owns its resume/session mechanism.
 *   - The VERIFIER grades the state. It produces the ground truth.
 *     The reviewer cannot overturn or downgrade a verification layer.
 *   - The REVIEWER is stateless per call. Its continuity is the
 *     `ReviewMemoryStore` — durable JSONL by default, or any store
 *     implementing the interface. It reads memory + trace summary +
 *     verification and directs the NEXT proposer shot.
 *
 * This shape is load-bearing. The reviewer never grades; the verifier
 * never directs. Two processes, two prompts, two concerns — which is
 * what keeps the loop from confirmation-biasing itself into "all
 * passed" when it didn't.
 *
 * Short-circuits and soft-fails are both first-class:
 *   - verify.pass === true  → reviewer LLM call is skipped, memory
 *     records a success entry, loop exits.
 *   - review throws         → the shot still counts; the loop uses the
 *     last-known instruction (or `fallbackInstruction`) for the next
 *     propose call. A transient reviewer failure must NEVER abort a
 *     valid arc.
 *
 * Composable: `propose` itself can be another `runProposeReview` call.
 * That's the dogfooding path — a harness built on this primitive is in
 * turn evaluable by it.
 */
import { TraceEmitter } from './trace/emitter';
import type { FailureClass } from './trace/schema';
import type { TraceStore } from './trace/store';
export interface Verification {
    pass: boolean;
    score?: number;
    failingLayers?: string[];
    details?: unknown;
}
export interface Review {
    observations: string;
    diagnosis: string;
    nextShotInstruction: string;
    shouldContinue: boolean;
    confidence: number;
}
export interface ReviewMemoryEntry extends Review {
    shot: number;
    timestamp: number;
    verification: {
        pass: boolean;
        score?: number;
        failingLayers?: string[];
    };
}
export interface ProposeInput<State> {
    shot: number;
    goal: string;
    state: State;
    priorReview: Review | null;
    abortSignal: AbortSignal;
    emitter?: TraceEmitter;
}
export interface ProposeOutput<State, Summary = unknown> {
    state: State;
    traceSummary?: Summary;
}
export interface ReviewInput<State, Summary = unknown> {
    shot: number;
    goal: string;
    state: State;
    verification: Verification;
    traceSummary: Summary | undefined;
    memory: ReviewMemoryEntry[];
}
export type ProposeFn<State, Summary = unknown> = (input: ProposeInput<State>) => Promise<ProposeOutput<State, Summary>>;
export type VerifyFn<State> = (state: State) => Promise<Verification>;
export type ReviewFn<State, Summary = unknown> = (input: ReviewInput<State, Summary>) => Promise<Review>;
export interface ReviewMemoryStore {
    load(): Promise<ReviewMemoryEntry[]>;
    append(entry: ReviewMemoryEntry): Promise<void>;
}
export interface ProposeReviewConfig<State, Summary = unknown> {
    goal: string;
    initialState: State;
    propose: ProposeFn<State, Summary>;
    verify: VerifyFn<State>;
    review: ReviewFn<State, Summary>;
    /** Hard shot cap. Default 10. */
    maxShots?: number;
    /** Wall-clock cap in ms. Default 10 min. */
    maxWallMs?: number;
    /**
     * If the reviewer returns confidence ≤ floor on `confidenceFloorWindow`
     * consecutive shots, terminate early. Default floor 0.3, window 2.
     * Set window to 0 or floor to <0 to disable.
     */
    confidenceFloor?: number;
    confidenceFloorWindow?: number;
    /** Defaults to an in-memory store if omitted. */
    memory?: ReviewMemoryStore;
    /** If provided, emit a Run + per-shot spans. */
    store?: TraceStore;
    scenarioId?: string;
    projectId?: string;
    variantId?: string;
    /**
     * Used when the reviewer soft-fails on shot 1 (no prior instruction to
     * fall back to). Default is a generic "inspect failures and fix".
     */
    fallbackInstruction?: string;
}
export interface ProposeReviewShot<State, Summary = unknown> {
    shot: number;
    state: State;
    verification: Verification;
    traceSummary: Summary | undefined;
    review: Review;
    reviewAvailable: boolean;
    reviewError?: string;
    durationMs: number;
}
export interface ProposeReviewReport<State, Summary = unknown> {
    runId: string | null;
    completed: boolean;
    shots: ProposeReviewShot<State, Summary>[];
    finalState: State;
    finalVerification: Verification;
    failureClass?: FailureClass;
    wallMs: number;
    score: number;
}
export declare function inMemoryReviewStore(initial?: ReviewMemoryEntry[]): ReviewMemoryStore;
export declare function jsonlReviewStore(path: string): ReviewMemoryStore;
export declare function runProposeReview<State, Summary = unknown>(config: ProposeReviewConfig<State, Summary>): Promise<ProposeReviewReport<State, Summary>>;
export type LlmJsonCall = (req: {
    system: string;
    user: string;
}) => Promise<unknown>;
export interface LlmReviewerConfig<State, Summary = unknown> {
    callJson: LlmJsonCall;
    renderState?: (state: State) => string;
    renderTraceSummary?: (summary: Summary | undefined) => string;
    /** Appended to the default system prompt. */
    systemPromptAddendum?: string;
}
export declare function createLlmReviewer<State, Summary = unknown>(cfg: LlmReviewerConfig<State, Summary>): ReviewFn<State, Summary>;
//# sourceMappingURL=propose-review.d.ts.map