/** * Dead Message Pruner — Phase 4 of Advanced Token Optimization * * Prunes provably obsolete messages in conversation history: * 1. Superseded errors — tool error followed by same tool succeeding on same input * 2. Permission exchanges — ask_user/ask_user_simple calls (purely procedural) * * Uses in-place content replacement (not message removal) to preserve * the tool_use/tool_result pairing required by the Anthropic API. */ import type { Message } from '../providers/types.js'; export interface PruneConfig { /** Enable superseded error pruning (default: true) */ supersededErrors: boolean; /** Enable permission exchange pruning (default: true) */ permissionExchanges: boolean; /** Tool names considered permission exchanges */ permissionTools: string[]; /** Never prune messages newer than this many turns (default: 4) */ protectedTurns: number; } export declare const DEFAULT_PRUNE_CONFIG: PruneConfig; export interface PruneResult { prunedCount: number; tokensSaved: number; } export interface PruneStats { prunedCount: number; tokensSaved: number; errorsPruned: number; permissionsPruned: number; } /** * Check if a tool result content string has been pruned. */ export declare function isPruned(content: string): boolean; export declare class DeadMessagePruner { private readonly config; private readonly stamps; private stats; constructor(config?: Partial); /** * Register a tool result for pruning analysis. * Called at the same point as ObservationMasker.stamp(). */ stamp(toolUseId: string, toolName: string, input: Record, isError: boolean, turn: number): void; /** * Prune dead messages in-place. Replaces content of dead tool_result * blocks with short placeholders and clears corresponding tool_use input. */ prune(messages: Message[], currentTurn: number): PruneResult; getStats(): PruneStats; /** * Reset all state (stamps and stats). Used when clearing history. */ reset(): void; /** * Get current configuration (for testing/inspection). */ getConfig(): PruneConfig; /** * Identify tool_use IDs that should be pruned. */ private identifyDeadMessages; }