import type { Context } from '../core/context.js'; import type { Logger } from '../types/logger.js'; import { type CompactionSummaryCache } from './compaction-summary-cache.js'; import type { CompactReport, Compactor } from '../types/compactor.js'; import type { Provider } from '../types/provider.js'; import type { MessageSelector } from '../types/selector.js'; /** * Options for SelectiveCompactor — the most configurable compactor. */ export interface SelectiveCompactorOptions { /** Provider for LLM calls (selector + summarizer). Required. */ provider: Provider; /** Selector for LLM-driven importance analysis. */ selector?: MessageSelector | undefined; /** Fraction of maxContext that triggers a warning (default 0.5). */ warnThreshold?: number | undefined; /** Fraction of maxContext that triggers soft compaction (default 0.65). */ softThreshold?: number | undefined; /** Fraction of maxContext that triggers hard compaction (default 0.8). */ hardThreshold?: number | undefined; /** Max context window in tokens (used for threshold fraction math). */ maxContext?: number | undefined; /** How many recent (user+assistant) pairs to always preserve (default 4). */ preserveK?: number | undefined; /** Token threshold below which tool results are not elided (default 300). */ eliseThreshold?: number | undefined; /** Model for selector LLM calls (default: same as provider default). */ selectorModel?: string | undefined; /** Max output tokens for the selector LLM call (default: 1024). */ selectorMaxOutputTokens?: number | undefined; /** Summarizer model for collapsed ranges (default: same as selectorModel). */ summarizerModel?: string | undefined; /** Structured logger. Defaults to noOpLogger (silent). */ logger?: Logger | undefined; /** Prompt for the summarizer sub-LLM. */ summarizerPrompt?: string | undefined; /** Shared cache for successful semantic summaries. */ summaryCache?: CompactionSummaryCache | undefined; } /** * SelectiveCompactor uses an LLM-driven MessageSelector to make * surgical decisions about which message ranges to keep vs collapse. * * Compared to HybridCompactor / IntelligentCompactor: * - HybridCompactor: rule-based (preserveK + elision), no LLM calls * - IntelligentCompactor: LLM summarization but no structured selection * - SelectiveCompactor: full LLM-driven selection + optional summarization */ export declare class SelectiveCompactor implements Compactor { private readonly provider; private readonly selector; private readonly warnThreshold; private readonly softThreshold; private readonly hardThreshold; private readonly maxContext; private readonly preserveK; private readonly eliseThreshold; private readonly summarizerModel; private readonly summarizerPrompt; private readonly summaryCache; private readonly logger; constructor(opts: SelectiveCompactorOptions); compact(ctx: Context, opts?: { aggressive?: boolean | undefined; }): Promise; /** * Compute after-tokens, run the shared quality check, inject the evidence * floor when compaction dropped the intent/path anchor, and assemble the * report — shared by both exit paths so every SelectiveCompactor run reports * quality and carries a `[context_state]` evidence digest like the others. */ private finalize; /** * Estimate the full API request token count: messages + systemPrompt + toolDefs. * This is the accurate figure for context-window pressure monitoring. */ private estimateFullRequest; private repairProtocolAdjacency; /** * Run the LLM selector to decide what to keep vs collapse. * Returns the token savings achieved. */ private runSelector; /** * Execute a SelectorResult plan: collapse/remove ranges and * insert summaries where the selector provided them. */ private executePlan; private summarizeRange; private messagePreview; private toolEvidence; /** * Fallback when selector fails: aggressively trim from the oldest end * until we hit targetBudget. */ private aggressiveRecencyTrim; private computeTargetBudget; private eliseOldToolResults; /** Collapse superseded repeated reads that slipped under the elise threshold. */ private dedupStaleReads; private hasTextContent; /** * Estimate message-array tokens via the shared `estimateMessages` primitive * so SelectiveCompactor's before/after/load figures agree with the * middleware threshold math and the other compactors. Previously this used a * private `ceil(len/3.5)` walk that diverged from the calibrated shared * estimator, causing the selective `load`/`targetBudget` comparison to mix * two incompatible token scales. */ private estimateTokens; } //# sourceMappingURL=selective-compactor.d.ts.map