/** * Cut point detection for compaction. * * Pure functions for finding valid compaction cut points and turn boundaries. */ import type { SessionEntry } from "../session-manager.js"; /** * Find the user message (or bashExecution) that starts the turn containing the given entry index. * Returns -1 if no turn start found before the index. * BashExecutionMessage is treated like a user message for turn boundaries. */ export declare function findTurnStartIndex(entries: SessionEntry[], entryIndex: number, startIndex: number): number; export interface CutPointResult { /** Index of first entry to keep */ firstKeptEntryIndex: number; /** Index of user message that starts the turn being split, or -1 if not splitting */ turnStartIndex: number; /** Whether this cut splits a turn (cut point is not a user message) */ isSplitTurn: boolean; } export interface FindCutPointOptions { /** * Explicit phase-boundary compaction should prefer the newest safe boundary * over retaining a large just-finished turn as the recent raw suffix. */ phaseBoundary?: boolean; /** * When provided, use this entry id as a fixed cut point instead of walking * backwards from the newest entry. This lets request-time adapters freeze a * previously-computed cut without regenerating the summary. */ anchorEntryId?: string; /** * When true, ensure the most recent user message is never folded into the * compaction summary — the cut point is pulled back to (or before) the * latest user message so it survives verbatim. This protects the current * task/brief from being reduced to a truncated excerpt mid-run. */ pinLatestUserMessage?: boolean; } /** * Find the cut point in session entries that keeps approximately `keepRecentTokens`. * * Algorithm: Walk backwards from newest, accumulating estimated message sizes. * Stop when we've accumulated >= keepRecentTokens. Cut at that point. * * Can cut at user OR assistant messages (never tool results). When cutting at an * assistant message with tool calls, its tool results come after and will be kept. * * Returns CutPointResult with: * - firstKeptEntryIndex: the entry index to start keeping from * - turnStartIndex: if cutting mid-turn, the user message that started that turn * - isSplitTurn: whether we're cutting in the middle of a turn * * Only considers entries between `startIndex` and `endIndex` (exclusive). */ export declare function findCutPoint(entries: SessionEntry[], startIndex: number, endIndex: number, keepRecentTokens: number, options?: FindCutPointOptions): CutPointResult; //# sourceMappingURL=cut-points.d.ts.map