/** * [WHO]: Provides CompactionController — manual context-window compaction + its abort state * [FROM]: Depends on session/compaction (compact, prepareCompaction, CompactionResult), * session-manager (CompactionEntry), extensions-host (SessionBeforeCompactResult), * platform/abort-slot, and ./session-context (CompactionControllerContext) * [TO]: Consumed by core/runtime/agent-session.ts (constructs one, delegates compact()/abortCompaction()) * [HERE]: core/runtime/agent-session.ts split (P4.x-a) — owns the manual-compaction abort slot * * Extracted from AgentSession (AS04). Owns the manual compaction flow and its cancellation state. * Auto-compaction (loop-driven) is a later slice (P4.x-b). Session state is reached through the * narrow CompactionControllerContext; behavior is identical to the former AgentSession.compact(). * * Circuit breaker: tracks consecutive auto-compaction failures. After * MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES (3), auto-compaction is disabled for the session * to prevent infinite retry loops. Resets on success. */ import type { AgentMessage } from "@catui/agent-core"; import { type CompactionResult } from "../session/compaction/index.js"; import type { CompactionControllerContext } from "./session-context.js"; export declare class CompactionController { private readonly ctx; /** Cancellation slot for the in-flight manual compaction. */ private readonly _slot; /** Cancellation slot for the in-flight auto (loop-driven) compaction. */ private readonly _autoSlot; /** Consecutive auto-compaction failure counter (circuit breaker). */ private _consecutiveAutoFailures; /** Whether the circuit breaker has tripped (auto-compaction disabled). */ private _circuitBroken; constructor(ctx: CompactionControllerContext); /** Whether a manual or auto compaction is currently running. */ get isCompacting(): boolean; /** Cancel an in-progress compaction (manual or auto). */ abort(): void; /** Whether auto-compaction is enabled. */ get autoCompactionEnabled(): boolean; /** Toggle auto-compaction. */ setAutoCompactionEnabled(enabled: boolean): void; /** * Compact the current branch: summarize older entries and rebuild agent messages. * Detaches the agent during the operation and reconnects in finally. */ compact(customInstructions?: string): Promise; /** * Run auto-compaction (loop-driven). Performs the compaction + emits * auto_compaction_start/end, and returns the rebuilt messages on success (or undefined when * compaction was skipped/aborted/failed). The loop-continuation decision (retry / kick the * queue) stays in AgentSession — this only owns the compaction itself. * * Circuit breaker: after MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES consecutive failures, * auto-compaction is disabled for the session to prevent infinite retry loops. */ runAuto(reason: "overflow" | "threshold", willRetry: boolean): Promise; }