/** * Compaction controller for AgentSession. * * Owns manual compaction (the /compact flow) and automatic compaction (overflow * recovery and threshold-triggered). It runs the shared apply pipeline — the * `session_before_compact` extension hook, summary generation, persistence, * agent-context refresh, and the `session_compact` event — and manages the * abort controllers and one-shot overflow-recovery guard. Extracted from * agent-session.ts behind a narrow CompactionControllerDeps interface. */ import type { AgentMessage, CompactionResult, ThinkingLevel } from "@kolisachint/hoocode-agent-core"; import type { AssistantMessage, Model } from "@kolisachint/hoocode-ai"; import type { AgentSessionEvent } from "./agent-session.js"; import type { ExtensionRunner } from "./extensions/index.js"; import type { ModelRegistry } from "./model-registry.js"; import type { SessionManager } from "./session-manager.js"; import type { SettingsManager } from "./settings-manager.js"; /** Narrow dependencies the compaction controller needs from AgentSession. */ export interface CompactionControllerDeps { sessionManager: SessionManager; settingsManager: SettingsManager; modelRegistry: ModelRegistry; getModel(): Model | undefined; getThinkingLevel(): ThinkingLevel; /** Read at call time; the extension runner is swapped on reload. */ getExtensionRunner(): ExtensionRunner; getAgentMessages(): AgentMessage[]; setAgentMessages(messages: AgentMessage[]): void; getRequiredRequestAuth(model: Model): Promise<{ apiKey: string; headers?: Record; }>; emit(event: AgentSessionEvent): void; disconnectFromAgent(): void; reconnectToAgent(): void; /** Abort the current agent operation and wait for idle (AgentSession.abort). */ abortSession(): Promise; /** Fire-and-forget continue() on the agent. */ continueAgent(): void; hasQueuedMessages(): boolean; } export declare class CompactionController { private readonly deps; private _compactionAbortController; private _autoCompactionAbortController; private _overflowRecoveryAttempted; constructor(deps: CompactionControllerDeps); /** Whether manual or auto compaction is currently running */ get isCompacting(): boolean; /** Whether auto-compaction is enabled */ get autoCompactionEnabled(): boolean; /** Toggle auto-compaction setting. */ setAutoCompactionEnabled(enabled: boolean): void; /** Clear the one-shot overflow-recovery guard (on new user input / successful response). */ resetOverflowRecovery(): void; /** Cancel in-progress compaction (manual or auto). */ abortCompaction(): void; private _applyCompaction; /** * Manually compact the session context. * Aborts current agent operation first. * @param customInstructions Optional instructions for the compaction summary */ compact(customInstructions?: string): Promise; /** * Check if compaction is needed and run it. * Called after agent_end and before prompt submission. * * Two cases: * 1. Overflow: LLM returned context overflow error, remove error message from agent state, compact, auto-retry * 2. Threshold: Context over threshold, compact, NO auto-retry (user continues manually) * * @param assistantMessage The assistant message to check * @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true */ checkCompaction(assistantMessage: AssistantMessage, skipAbortedCheck?: boolean): Promise; private _runAutoCompaction; } //# sourceMappingURL=agent-session-compaction.d.ts.map