import type { Message } from "@kenkaiiii/gg-ai"; /** * Cheap context pruning for stale tool payloads (opencode-style, no LLM call). * * Three signals, one pass: * 1. Superseded reads — an old `read` of a file that was re-read later carries * zero information; the newest read wins. * 2. Old tool-output overflow — walking backwards, the most recent * `protectTokens` worth of tool output plus the last `protectToolBatches` * provider tool batches are kept verbatim; anything older is stubbed. * 3. Large completed tool arguments — old write/edit payloads are capped once * their result has returned; the files and tool result are the durable truth. * * `PROTECTED_TOOLS` output is never pruned: it is behavioural instruction rather * than reproducible data, so a "re-run the tool" stub is not recoverable — the * agent has no signal that it ever loaded the skill. * * Tool batches—not human turns—are the protection boundary. Autonomous research * can execute dozens of provider/tool cycles for one user prompt; protecting the * whole human turn lets reproducible reads refill the context immediately after * compaction. * * Cache stability: pruning mutates history, which invalidates the provider's * prompt-cache prefix. To limit churn, nothing is pruned unless at least * `minimumTokens` would be freed in one batch. Stubs and compacted arguments are * idempotent, so later passes leave the rewritten prefix stable. */ export declare const PRUNE_PROTECT_TOKENS = 40000; export declare const PRUNE_MINIMUM_TOKENS = 20000; export declare const PRUNE_PROTECT_TOOL_BATCHES = 2; /** Tools whose output is instruction, not reproducible data — never pruned. */ export declare const PRUNE_PROTECTED_TOOLS: Set; export interface PruneOptions { /** Recent tool-output token budget kept verbatim. Default 40k. */ protectTokens?: number; /** Minimum freed tokens required to apply a prune batch. Default 20k. */ minimumTokens?: number; /** Number of most-recent provider tool batches never pruned. Default 2. */ protectToolBatches?: number; } export interface PruneResult { pruned: boolean; prunedResults: number; compactedToolCalls: number; freedTokens: number; } /** Mutates `messages` in place; message/array identity is preserved so usage * anchors and React refs stay valid. Returns what was freed. */ export declare function pruneStaleToolResults(messages: Message[], opts?: PruneOptions): PruneResult; //# sourceMappingURL=tool-result-pruner.d.ts.map