import type { VisionClawConfig } from "../config/types.js";
import type { MessageQueue } from "../channels/queue.js";
import type { SessionManager } from "./session-manager.js";
import type { AgentState } from "./state.js";
export interface PerformContextRefreshDeps {
    session: SessionManager;
    config: VisionClawConfig;
    messageQueue: MessageQueue;
}
export interface PerformContextRefreshOptions {
    /** Short reason for logs (e.g. "manual" or "compaction-timeout-streak"). */
    reason: string;
    /**
     * System message enqueued for the next wake cycle so the new session knows
     * a refresh happened. Defaults to the manual-refresh wording.
     */
    systemMessage?: string;
}
export interface PerformContextRefreshResult {
    /** True when the session was summarized and reset. False if there was no
     * active session id to refresh. */
    refreshed: boolean;
    summary: string | null;
}
/**
 * Pure decision for whether the wake loop should force an automatic refresh.
 * Kept separate from the side-effecting refresh so the gating logic is unit
 * testable in isolation.
 */
export declare function shouldAutoRefresh(cfg: {
    enabled: boolean;
    timeoutStreak: number;
    cooldownMs: number;
}, timeoutStreak: number, lastAutoRefreshAtMs: number, nowMs: number): boolean;
/**
 * Core of a context refresh, shared by the manual `/refresh` command handler
 * and the automatic compaction-timeout trigger:
 *   1. summarize the current transcript (tail summary with fallback),
 *   2. reset the active session (rotating its id and injecting the summary),
 *   3. enqueue a system message so the next wake cycle has continuity.
 *
 * Callers are responsible for the `agentState.compacting` mutex and any
 * channel-specific user messaging — this function only performs the reset and
 * returns whether it ran.
 */
export declare function performContextRefresh(deps: PerformContextRefreshDeps, options: PerformContextRefreshOptions): Promise<PerformContextRefreshResult>;
export interface RunContextRefreshDeps extends PerformContextRefreshDeps {
    /** Shared compaction mutex; held for the duration of the refresh so the main
     * loop's idle gate can't start a new turn on the session being reset. */
    agentState: Pick<AgentState, "compacting" | "busy" | "stopRequested" | "requestStop">;
}
export interface RunContextRefreshHooks {
    /** Fired when the agent was busy and we've signalled it to stop (manual UX). */
    onBusyStopping?: () => Promise<void> | void;
    /** Fired once we've committed to refreshing, just before summarization. */
    onRefreshing?: () => Promise<void> | void;
    /** Fired after a successful refresh — used for owner/requester notification. */
    onRefreshed?: (result: PerformContextRefreshResult) => Promise<void> | void;
}
export interface RunContextRefreshOptions extends PerformContextRefreshOptions {
    /**
     * When true, stop any in-flight turn and wait for the agent to go idle
     * before refreshing. Used by the manual `/refresh` command (a user can
     * invoke it mid-turn). The automatic path runs only at the loop's idle gate
     * and leaves this false.
     */
    stopActiveTurn?: boolean;
    /** Max ms to wait for the active turn to stop (default 30s). */
    stopTimeoutMs?: number;
    hooks?: RunContextRefreshHooks;
}
export type RunContextRefreshOutcome = {
    status: "refreshed";
    summary: string | null;
} | {
    status: "no_session";
} | {
    status: "stop_timeout";
};
/**
 * Single orchestration path for a context refresh, shared by the manual
 * `/refresh` command handler and the automatic compaction-timeout-streak gate.
 *
 * Owns the `agentState.compacting` mutex and (optionally) stopping an in-flight
 * turn, then delegates the actual summarize/reset/enqueue to
 * {@link performContextRefresh}. Channel-specific messaging is supplied via
 * {@link RunContextRefreshHooks} so callers keep their own locale/recipient
 * logic without re-implementing the mutex and refresh sequence.
 *
 * The automatic path passes no requester hooks and simply notifies the owner —
 * it never re-emits a `/refresh` command; it only runs at the idle gate.
 */
export declare function runContextRefresh(deps: RunContextRefreshDeps, options: RunContextRefreshOptions): Promise<RunContextRefreshOutcome>;
//# sourceMappingURL=context-refresh.d.ts.map