/** * [WHO]: SessionCompactionCoordinator — loop-driven compaction decisions + in-loop model-error recovery * [FROM]: Depends on agent-core, ai/overflow, session/compaction (calculateContextTokens, shouldCompact), * session-manager (getLatestCompactionEntry), ./session-recovery (pruneRecoverableErrorTail), * ./session-context (SessionCompactionCoordinatorContext) * [TO]: Consumed by agent-session.ts (delegates check()/recoverModelErrorInLoop()/runAuto()) * [HERE]: core/runtime/agent-session.ts split (AS04) — owns WHEN to compact (overflow/threshold) and the * recoverable-tail retry decision; the compaction flow itself stays in compaction-controller.ts * * Extracted from AgentSession (AS04). Decision logic moved line-by-line; session state is reached through * the narrow SessionCompactionCoordinatorContext. Loop continuation (agent.continue kicks) remains owned * by AgentSession and is requested via the continueAgentLoop capability. */ import type { AgentMessage, AgentModelErrorRecoveryResult } from "@catui/agent-core"; import type { AssistantMessage } from "@catui/ai/types"; import type { SessionCompactionCoordinatorContext } from "./session-context.js"; export declare class SessionCompactionCoordinator { private readonly ctx; constructor(ctx: SessionCompactionCoordinatorContext); /** * 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 */ check(assistantMessage: AssistantMessage, skipAbortedCheck?: boolean): Promise; recoverModelErrorInLoop(event: { message: AgentMessage; messages: AgentMessage[]; errorSubtype: string; attempt: number; }): Promise; /** * Internal: Run auto-compaction with events. */ runAuto(reason: "overflow" | "threshold", willRetry: boolean, options?: { triggerContinue?: boolean; }): Promise; }