/** * A cache entry tracking file read history and content state. */ export interface CacheEntry { /** SHA-256 hash of the file content at last read/update. */ contentHash: string; /** Stored content (only in with_content mode). */ content?: string | undefined; lineCount: number; byteSize: number; firstReadAt: number; lastReadAt: number; readCount: number; /** Estimated LLM tokens: Math.ceil(byteSize / 4). */ tokenEstimate: number; /** Cumulative tokens saved by cache hits. */ tokensSaved: number; /** OCC version counter, increments on every external modification. */ version: number; } export interface ConflictInfo { yourVersion: number; currentVersion: number; diffSinceRead?: string | undefined; } export type CacheStatus = 'miss' | 'unchanged' | 'modified'; /** * FileStateCache, File state tracking with Optimistic Concurrency Control. * * Tracks files that have been read by tools/agents, detects external modifications, * and provides conflict information for OCC workflows. */ export declare class FileStateCache { private readonly mode; private readonly maxMemoryBytes; private cache; private totalMemBytes; private totalReads; private cacheHits; constructor(options?: { mode?: 'hash_only' | 'with_content'; maxMemoryMB?: number; }); /** * Look up the current state of a file. * * - miss: file has never been cached * - unchanged: content hash matches what we last saw * - modified: content hash differs (external modification) * * In `with_content` mode, a unified diff is included when status is 'modified'. */ lookup(filePath: string): { status: CacheStatus; entry?: CacheEntry | undefined; diff?: string | undefined; }; /** * Record that a file was read or written by a tool/agent. * Creates or updates the cache entry. */ update(filePath: string, content: string, metadata?: { tool?: string; agent?: string; }): void; /** * Check for an OCC conflict: has the file been modified since `expectedVersion`? * Returns null if no conflict, or ConflictInfo if the version has advanced. */ checkConflict(filePath: string, expectedVersion: number): ConflictInfo | null; /** * Remove a file from the cache. */ invalidate(filePath: string): void; /** * Return cache statistics. */ getStats(): { uniqueFiles: number; totalReads: number; hitRate: number; tokensSaved: number; memoryMB: number; }; /** * Clear all cached entries. */ clear(): void; private hash; private evictIfNeeded; } /** * Generate a simple unified diff between two strings. * Uses line-by-line LCS diff, not the Myers algorithm. */ export declare function unifiedDiff(oldContent: string, newContent: string, label: string, contextLines?: number): string; //# sourceMappingURL=file-cache.d.ts.map