/**
 * Turn Loop Guard — Abort signal + token budget warning for preventive termination.
 *
 * Aligned with Claude Code's multi-condition termination:
 * 1. AbortSignal from user cancellation
 * 2. Token budget pre-check (don't send API call if over budget)
 * 3. max_output_tokens escalation on truncation
 * 4. Prompt-too-long reactive compact trigger
 */
export interface TurnLoopGuardConfig {
    /** Context window size in tokens. */
    contextWindowTokens: number;
    /** Buffer reserved for response (default: 13000). */
    responseBufferTokens: number;
    /** Max output tokens for current model. */
    maxOutputTokens: number;
    /** Abort signal for user cancellation. */
    abortSignal?: AbortSignal;
    /** Whether reactive compact is available. */
    reactiveCompactEnabled: boolean;
    /** Whether max_output_tokens escalation is allowed. */
    outputEscalationEnabled: boolean;
}
export type TokenWarningState = {
    level: "ok";
} | {
    level: "warning";
    usagePercent: number;
    remainingTokens: number;
} | {
    level: "blocking";
    usagePercent: number;
    reason: "prompt_too_long" | "budget_exhausted";
};
export interface TurnLoopGuardState {
    /** Current accumulated prompt tokens. */
    promptTokens: number;
    /** Whether reactive compact has already been attempted this turn. */
    hasAttemptedReactiveCompact: boolean;
    /** Current max_output_tokens (may escalate). */
    currentMaxOutputTokens: number;
    /** Number of consecutive max_tokens truncations. */
    consecutiveTruncations: number;
    /** Whether the turn has been aborted. */
    aborted: boolean;
}
/** Initial guard state. */
export declare function createTurnLoopGuardState(config: TurnLoopGuardConfig): TurnLoopGuardState;
/**
 * Calculate token warning state before making an API call.
 * If level is "blocking", do NOT send the API call.
 */
export declare function calculateTokenWarningState(state: TurnLoopGuardState, config: TurnLoopGuardConfig): TokenWarningState;
/**
 * Handle API error and determine recovery action.
 */
export type ApiErrorRecovery = {
    action: "reactive_compact";
} | {
    action: "escalate_output_tokens";
    newMax: number;
} | {
    action: "retry";
    reason: string;
} | {
    action: "abort";
    reason: string;
};
export declare function resolveApiErrorRecovery(error: {
    type?: string;
    status?: number;
    message?: string;
}, state: TurnLoopGuardState, config: TurnLoopGuardConfig): ApiErrorRecovery;
/**
 * Handle finish_reason === "max_tokens" — escalate max_output_tokens.
 *
 * CC pattern: double the output token budget up to model max.
 */
export declare function resolveOutputTokenEscalation(state: TurnLoopGuardState, config: TurnLoopGuardConfig, modelMaxOutput: number): {
    shouldEscalate: boolean;
    newMax: number;
};
/**
 * Check if the turn should be aborted (user cancellation).
 */
export declare function shouldAbortTurn(state: TurnLoopGuardState, config: TurnLoopGuardConfig): boolean;
