/** * Context Squeezer - Token Compactor for AI Prompts and Logs * * This utility compresses source code snippets and logs to their absolute * semantic minimum by stripping comments, excessive whitespace, and boilerplate, * saving up to 80% of token consumption in LLM context windows. */ export interface SqueezeResult { squeezed: string; originalSize: number; squeezedSize: number; compressionRatio: number; } /** * Remove single-line and multi-line comments from JavaScript/TypeScript/JSON/CSS code */ export declare function stripComments(code: string): string; /** * Compress code structure by removing redundant whitespace and blank lines */ export declare function compactWhitespace(code: string): string; export declare function detectFunctionDeclaration(context: string): string | null; /** * Compresses very long TypeScript/JavaScript files by keeping only the function/class signatures * and removing function body implementation details for functions that are not mentioned in the query! */ export declare function treeShakeCode(code: string, query: string): string; /** * Squeezes a block of source code */ export declare function squeezeCode(code: string): string; /** * Detects the file path from the first line comment inside a code block */ export declare function detectFilePath(code: string): string | null; /** * Squeezes all markdown code blocks (``` ... ```) inside a prompt string */ export declare function squeezePrompt(prompt: string, query?: string, fileHistory?: Map): SqueezeResult; /** * Extract plain text string content from message formats (string or content block arrays) */ export declare function extractContentText(content: any): string; /** * Decimates older conversational history turns by replacing them with high-density, * single-line structured summaries of what was asked and what was resolved. */ export declare function decimateHistory(messages: any[]): any[]; export interface PruneHistoryResult { messages: any[]; tokensSavedEstimate: number; /** * Estimated tokens that lose prompt-cache-hit status because pruning mutates message * content earlier in the conversation, breaking the cached prefix from that point on. * The whole conversation has to be reprocessed at full (non-cached) price on the next * turn — same reasoning `tool-profiles.ts` already applies to the tool schema prefix. */ cacheInvalidationEstimate: number; /** False when the guard refused to mutate history — `messages` is then the input, untouched. */ applied: boolean; reason?: string; } /** * Prunes conversational message history to compress large repeated codeblocks in historical messages. * Keeps only the most recent message's codeblocks fully intact, and prunes older historical messages * if they are extremely large and contain redundant code blocks. * * T7 guard: pruning contradicts the prompt-cache reasoning applied everywhere else in this * codebase — it mutates earlier messages, which invalidates the cached prefix and re-charges * the ENTIRE conversation at full price on the next turn. That is very often a net loss even * when the mechanical squeeze looks like a win in isolation. So this refuses to mutate * anything by default; pass `{ force: true }` to actually apply it (e.g. when the provider * has no prompt caching, or the conversation is about to blow the context window outright). */ export declare function pruneHistoryMessages(messages: any[], options?: { force?: boolean; }): PruneHistoryResult; /** * Strip import statements and require declarations from JavaScript, TypeScript, Python and CSS code */ export declare function stripImports(code: string): string; /** * Generate a highly compact, unified line-by-line diff between two versions of code blocks */ export declare function generateAstDiff(oldCode: string, newCode: string): string; /** * Filters large codebase search results / RAG dumps in the prompt, keeping only the most * semantically relevant snippets based on keyword intersection (Jaccard similarity). */ export declare function filterHighDensityRAG(prompt: string, query: string): string; /** * Detects and collapses consecutive repeating lines in logs, stack traces or terminal dumps. */ export declare function collapseRepetitiveLogs(text: string): string; //# sourceMappingURL=ContextSqueezer.d.ts.map