/** * compaction.ts — Dual-phase conversation compaction. * * Phase 1 (prune): Remove tool outputs older than N turns to free context * window without losing conversation structure. * Phase 2 (summary): Rely on the upstream LLM to summarize (handled by * pi-coding-agent's built-in compaction). */ /** Default number of conversation turns to keep fully intact during pruning. */ export declare const DEFAULT_KEEP_TURNS = 5; /** Minimum number of turns that can be kept — protects against overly aggressive pruning. */ export declare const MIN_KEEP_TURNS = 2; /** Result of a compaction operation with token reduction metrics. */ export interface CompactResult { originalTokens: number; compactedTokens: number; reductionPercent: number; turnCount: number; } /** Minimal message shape needed for compaction — works with any message-like object. */ export interface CompactableMessage { role: "user" | "assistant" | "toolResult"; content: string | unknown[]; toolName?: string; } /** * Prune old tool outputs from a conversation while keeping the last N turns intact. * * Walks messages in reverse. Each assistant message counts as one turn boundary. * Keeps the last `keepLastNTurns` turns fully intact (all message roles). * For older turns, removes tool result messages while preserving user and assistant messages. * Never removes user messages regardless of their position. */ export declare function pruneOldToolOutputs(messages: readonly CompactableMessage[], keepLastNTurns: number): CompactableMessage[]; /** * Estimate the reduction achieved by compaction. */ export declare function estimateReduction(original: readonly CompactableMessage[], compacted: readonly CompactableMessage[]): CompactResult; /** Check whether a conversation exceeds a given token threshold. */ export declare function shouldCompact(messages: readonly CompactableMessage[], thresholdTokens: number): boolean;