/**
 * CliScriptRunner — isolated execution of provider CLI scripts
 *
 * Responsible solely for invoking provider-supplied JavaScript functions
 * (detectStatus, parseApproval, parseSession, etc.) and managing the
 * per-session script state created by createState().
 *
 * The runner is stateless with respect to PTY / buffer content — all
 * input data is passed explicitly by the caller so that the adapter can
 * remain a pure transport layer without embedding parsing logic.
 */
import { type CliApprovalInput, type CliScripts, type CliScriptInput, type CliScreenSnapshot, type CliStatusInput, type ParsedSession } from './provider-cli-shared.js';
/**
 * One entry per script invocation, kept in a ring buffer so debug
 * tooling can answer "what did the script see, and what did it return?"
 * without having to re-run the daemon with custom logs. This is the
 * trace that would have answered the codex-cli #102 regression in one
 * pass instead of a dozen guesses.
 *
 * Body fields are bounded: input is reduced to a small summary (sizes
 * + a salted hash + the first few normalized chars of screenText), and
 * result is JSON-serialized then capped. Full PTY frames are NOT
 * captured here — they live in CliBufferSnapshot and are exposed by
 * the chat debug bundle separately.
 */
export interface CliScriptInvocationTrace {
    at: number;
    scriptName: string;
    arity: number;
    inputSummary: {
        screenTextLen: number;
        rawBufferLen: number;
        tailLen: number;
        isWaitingForResponse?: boolean;
        screenTextHead?: string;
    };
    ok: boolean;
    elapsedUs: number;
    resultSummary?: string;
    error?: string;
    /**
     * True when the invocation's elapsed time exceeded the runner's
     * `scriptCallBudgetMs`. The script is NOT aborted (Node CJS can't
     * interrupt sync code without a worker thread) — this flag plus the
     * trace ring lets an operator identify which provider is hanging the
     * settle loop. A throttled WARN is emitted alongside.
     */
    timedOut?: boolean;
}
export declare class CliScriptRunner {
    private scripts;
    private scriptState;
    private _parseErrorMessage;
    private readonly cliType;
    private sdk;
    private invocationTrace;
    /** Per-invocation wall-clock budget (ms). Configurable via setScriptCallBudget. */
    private scriptCallBudgetMs;
    /** Last WARN emit time per scriptName, used to throttle repeated budget violations. */
    private lastBudgetWarnAt;
    constructor(cliType: string);
    /** Returns the most-recent script invocation traces (oldest → newest). */
    getInvocationTrace(): CliScriptInvocationTrace[];
    /** Clear the trace ring — used by tests and after PTY reset. */
    clearInvocationTrace(): void;
    /**
     * Configure the wall-clock budget (ms) applied to every script invocation.
     *
     * Out-of-range or non-finite values are clamped to [1, 5000] and the
     * default (50ms) is used as a fallback. The budget is enforced per-call,
     * not aggregated — it does not abort a runaway script (Node CJS cannot
     * interrupt synchronous code without a worker thread). Instead, an
     * exceeded budget flags the trace entry with `timedOut: true` and emits
     * a throttled WARN naming the script and elapsed time so an operator
     * can identify which provider is hanging the settle loop.
     */
    setScriptCallBudget(ms: number): void;
    /** Test/debug accessor — current effective budget in ms. */
    getScriptCallBudgetMs(): number;
    private recordTrace;
    setScripts(scripts: CliScripts, providerTui?: Record<string, unknown> | undefined): void;
    private buildSdk;
    /** Reset per-session state — called when the PTY process exits. */
    resetSessionState(): void;
    /** Returns the live scripts object. Direct property assignment on this object
     *  patches individual scripts without replacing others (used in tests). */
    get cliScripts(): CliScripts;
    hasDetectStatus(): boolean;
    hasParseSession(): boolean;
    getScriptNames(): string[];
    get parseErrorMessage(): string | null;
    clearParseError(): void;
    detectStatus(input: CliStatusInput): string | null;
    parseApproval(input: CliApprovalInput): {
        message: string;
        buttons: string[];
    } | null;
    parseSession(input: CliScriptInput & {
        tail?: string;
        tailScreen?: CliScreenSnapshot;
    }): ParsedSession | null;
    /**
     * Invoke an arbitrary named script (e.g. setModel, openModelPicker).
     * Throws if the script is not available.
     */
    invokeByName(name: string, input: any): any;
    private invoke;
    /**
     * Returns true when `elapsedUs` exceeded the configured budget. On the
     * first violation per script (or after the throttle window expires) we
     * emit a single WARN so the operator learns which provider is slow.
     *
     * We deliberately throttle per-scriptName so a chronically-slow
     * detectStatus doesn't spam the log on every PTY frame settle.
     */
    private checkBudget;
}
