import type { Question } from "./schema.ts";
/**
 * Escape residue in question text (oh-my-openagent#12797). Some models write non-ASCII tool-call text as
 * `\uXXXX` escapes and then drop the backslash (`ub0b4 Tailscale 쓰기` for `내 Tailscale 쓰기`) or double it, so
 * the decoded string still holds `\ub0b4`. The JSON is valid either way; only the text is wrong.
 *
 * Heuristic, applied to every header, question, option label and option description after quoted code is blanked
 * out (fenced ``` or ~~~ blocks, then ``...`` spans, then `...` spans), since quoted code may name an escape on purpose:
 * - A literal `\uXXXX` whose code point is non-ASCII is residue.
 * - A bare run of `uXXXX` tokens is a candidate only when no ASCII letter, digit, `_` or `\` precedes it and
 *   none follows it, so `menu1234`, `u1a2b3c4d` and other hex-like ids never match. A candidate is residue
 *   when it decodes to non-ASCII text and either
 *   - the run has two or more tokens (`ub0b4uc4f0`), each decoding to a letter, mark, number, punctuation or
 *     symbol (a paired surrogate counts), or
 *   - its single token decodes to a letter in a script the question set already uses outside ASCII, with
 *     Hangul, Han, Hiragana, Katakana and Bopomofo counted as one family (a wrong high digit lands a Hangul
 *     syllable in Han). `u1234` in English text, or beside Korean text, decodes to Ethiopic and stays.
 * Known gap: a token glued to a preceding ASCII letter (`cafu00e9`) is not detected.
 * Known limit: an escape named in plain prose outside code (\u00e9 with no backticks) is refused once like residue;
 * its re-call opens as written.
 */
export type EscapeResidue = {
    field: string;
    token: string;
};
export declare function findEscapeResidue(questions: readonly Question[]): EscapeResidue[];
/**
 * The one-refusal bound, scoped to assistant turns. One assistant message's tool calls run in parallel inside one turn,
 * and the model sees a refusal only after that turn ends. So every residue call in a turn with no open retry is refused,
 * and every residue call in a later turn opens as written with a warning, whether or not its text changed. The retry
 * stays open until a turn uses it, so no question set is refused twice in a row and a re-call can never loop.
 */
export type EscapeResidueRetry = {
    refusedThisTurn: boolean;
    retryOpen: boolean;
    retriedThisTurn: boolean;
};
export declare function freshEscapeResidueRetry(): EscapeResidueRetry;
/**
 * Records any call; true means refuse it. A call made while the retry is open uses it up, clean or not, so a clean
 * re-call closes the retry and a later residue set is refused once again. A residue call with no open retry is refused.
 */
export declare function refuseEscapeResidue(retry: EscapeResidueRetry, hasResidue: boolean): boolean;
export declare function endEscapeResidueTurn(retry: EscapeResidueRetry): void;
export declare class AskUserEscapeResidueError extends Error {
    readonly residue: EscapeResidue[];
    constructor(residue: EscapeResidue[]);
}
export declare function escapeResidueNote(residue: readonly EscapeResidue[]): string;
//# sourceMappingURL=escape-residue.d.ts.map