import type { ClassifierApi, ClassifierContext, ClassifierModel, ClassifierOptions, ClassifierResult, RetryCallbacks, RetryPolicy } from "@bastani/pi-ai"; import type { Api, Model, Usage } from "@bastani/pi-ai/compat"; import type { StreamFn, ThinkingLevel } from "@earendil-works/pi-agent-core"; import type { SessionEntry } from "../session-manager-types.ts"; import type { CompactedTranscript, CompactionPlannerModel, CompactionUrgency, PlannerAuth, VerbatimCompactionPreparation } from "./compaction-types.js"; import { type FallbackPlannerContext } from "./fallback-planner.js"; import type { CompactionModelSelection } from "./model-resolver.js"; export interface CompactionPlanOptions { streamFn: StreamFn; /** Absolute path of the persisted session file. Undefined for in-memory sessions. */ sessionFilePath?: string; retry?: RetryPolicy; callbacks?: RetryCallbacks; } /** One compaction run's request. Urgency is required; there is no default. */ export interface CompactionRunRequest extends CompactionPlanOptions { /** Per-model credentials; a borrowed candidate uses its own, never the session model's. */ resolveAuth: (model: Model) => Promise; signal?: AbortSignal; /** Inherited by the planner and never modified across attempts. */ thinkingLevel: ThinkingLevel | undefined; urgency: CompactionUrgency; /** Configured fallback candidates. Omitted means borrowing is impossible. */ fallback?: FallbackPlannerContext; compactionModel?: CompactionModelSelection; resolveMorphApiKey?: () => Promise; morphFetchFn?: typeof fetch; classify?: (model: ClassifierModel, context: ClassifierContext, options?: ClassifierOptions) => Promise; summaryEntries?: SessionEntry[]; cwd?: string; } export type CompactionRungResult = CompactedTranscript & { rung: "planned" | "fresh"; /** Present only when a borrowed fallback model ranked the lines. */ plannerModel?: CompactionPlannerModel; /** False only when the fresh rung had to drop the protected tail. */ keptTail: boolean; /** Aggregate usage across every planner request and retry in this run. */ usage?: Usage; backend?: "planner" | "classifier" | "morph" | "summary"; model?: string; summary?: { readFiles: string[]; modifiedFiles: string[]; }; summaryFirstKeptEntryId?: string; summaryTokensBefore?: number; }; /** * Calculate the single global line threshold from the prepared setting. * * Protected lines count *against* this target rather than raising it: keeping 40% under a 0.5 * ratio leaves the remaining 60% to compress harder to hit the same total. That keeps the * compression ratio a real bound on output size, so protection can never enlarge the result. * * This is the untrimmed target. Overflow trimming does NOT reuse it: * `planWithTrimming` recomputes the threshold against each trimmed view, so the * planner is always asked to keep a proportion of the lines it actually * received rather than a proportion of a region it never saw. * * Retained as an exported helper for tests and consumers that need the * pre-trim target; production planning goes through `planWithTrimming`. */ export declare function targetKeepLines(preparation: VerbatimCompactionPreparation): number; /** * Discard every compactable line and start a fresh context window. * * TOTAL. No provider, no credentials, no network, no signal, no failure mode, * no `Promise`. Port of codex `compact_token_budget` → * `Session::start_new_context_window`. Atomic's system prompt, context files, * and skills are rebuilt per request and were never in the transcript, so they * survive automatically. * * The whole region is emitted as one deletion range and handed to the unchanged * `validateDeletedRanges` → `reconstructCompactedTranscript` path, which splits * around protected spans and folds prior markers. * * Returns exactly a `CompactedTranscript` — `text`, `ranges`, `stats` and * nothing else. Whether the `preserve_recent` tail survives is a persistence * concern and travels on `CompactionRungResult.keptTail`, not on this door. */ export declare function startNewContextWindow(preparation: VerbatimCompactionPreparation): CompactedTranscript; /** * Produce one compacted transcript, tagged with the rung that produced it. * * The ladder is: the session model, then each configured fallback model * borrowed for one planner request, then — only under `load_bearing` urgency — * a fresh context window. A manual `/compact` runs at `recoverable` urgency and * therefore cannot reach the context-destroying rung; it fails honestly instead. * * Unavailable credentials are ladder control flow, not an early throw: a * borrowed candidate with its own working credentials can still rank the lines, * and a load-bearing caller still reaches the credential-free fresh rung. */ export declare function runVerbatimCompaction(preparation: VerbatimCompactionPreparation, model: Model, request: CompactionRunRequest): Promise; //# sourceMappingURL=compaction-runner.d.ts.map