/** * Session File Cache * * Tracks which file chunks have already been delivered to an LLM in the * current conversation session. Enables diff-only context delivery: * * • "new" → first time this chunk is seen; deliver full content. * • "unchanged" → already delivered, content identical; deliver a compact * reference token instead (~8 tokens vs hundreds). * • "changed" → already delivered, content differs; deliver a line-level * diff block instead of the full new content. * * Lifecycle: purely in-memory (no persistence). Sessions are evicted by * LRU after MAX_SESSIONS entries or after SESSION_TTL_MS inactivity. */ /** Approximate token cost of a single reference tag `[CACHED: path:L1-L2]`. */ export declare const REFERENCE_TOKEN_COST = 8; export type ChunkStatus = "new" | "unchanged" | "changed"; export interface ChunkCheckResult { status: ChunkStatus; /** * Only set when status === "changed". * Contains a compact "+/-" line-level diff between the previous and * current content of the chunk. */ diff?: string; /** * Approximate tokens saved by NOT delivering full content. * 0 when status === "new". */ tokensSaved: number; } export interface SessionCacheStats { trackedSessions: number; totalChecks: number; cacheHits: number; unchangedHits: number; changedHits: number; totalTokensSaved: number; } /** * Singleton session-scoped file chunk cache. */ export declare class SessionFileCache { private static instance; /** sessionId → chunkKey → ChunkRecord */ private readonly sessions; /** sessionId → last-access timestamp (ms) — used for LRU eviction */ private readonly lastAccess; private readonly stats; private constructor(); static getInstance(): SessionFileCache; /** * Build the canonical chunk key from file metadata. * * @param filePath Relative or absolute path of the file. * @param lineStart First line of the chunk (1-based). * @param lineEnd Last line of the chunk (1-based, inclusive). */ chunkKey(filePath: string, lineStart: number, lineEnd: number): string; /** * Check whether a chunk should be delivered in full, as a reference token, * or as a diff block. * * Call this once per chunk per `getOptimizedContext` invocation. The cache * is updated automatically: on a cache miss the chunk is stored; on a * "changed" hit the record is updated with the new content. * * @param sessionId Conversation / session identifier. * @param key Chunk key produced by `chunkKey()`. * @param content Current full text content of the chunk. */ check(sessionId: string, key: string, content: string): ChunkCheckResult; /** * Invalidate all tracked chunks for a session. * Useful when the caller explicitly requests a fresh context. */ invalidateSession(sessionId: string): void; /** Global statistics across all sessions. */ getStats(): SessionCacheStats; private hashContent; /** Ensure the session map exists and refresh its LRU timestamp. */ private touch; /** LRU + TTL eviction when we exceed MAX_SESSIONS. */ private evictIfNeeded; } //# sourceMappingURL=session-file-cache.d.ts.map