@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
53 lines • 2.88 kB
TypeScript
import { type SessionSummary } from "./session-summary.ts";
import { type FileStamp } from "./session-summary-lru.ts";
/**
* Upper bound on cached session files, evicted least-recently-used rather than
* grown with the sessions directory.
*/
export declare const SESSION_SUMMARY_CACHE_LIMIT = 4096;
/**
* Upper bound on retained transcript text across the whole cache.
*
* A cached summary's footprint is its `allMessagesText`, which grows with the
* session, so the entry ceiling alone bounds nothing: 4096 large sessions would
* pin gigabytes for the life of the process. 64 MiB is deliberately conservative
* — it holds a normal user's entire sessions directory (a heavy 2 MB session
* file yields well under 2 MB of visible text, so hundreds of them fit) while
* capping the worst case at a fraction of a Node heap. Exceeding it evicts the
* least recently listed sessions, which then cost one streaming re-read.
*/
export declare const SESSION_SUMMARY_CACHE_MAX_TEXT_BYTES: number;
export type CachedSessionSummary = {
readonly summary: SessionSummary;
readonly mtime: Date;
};
/**
* A second cache level consulted on an in-memory miss, such as the persistent
* per-directory summary index. `record` receives every summary served from
* memory or streamed, so the store can persist what it lacks.
*/
export type SessionSummaryStore = {
lookup(filePath: string, stamp: FileStamp): Promise<SessionSummary | undefined>;
record(filePath: string, stamp: FileStamp, summary: SessionSummary): void;
};
/**
* Exact summary of one session file, reusing the cached summary when the file's
* size and mtime are unchanged since it was read.
*
* A cache hit deserializes nothing: the whole point is that listing an unchanged
* sessions directory costs one `stat` per file. A file that cannot be stat'ed or
* read drops its cache entry, so a truncated or replaced file is never served
* from stale bytes. A summary too large for the cache's byte budget is returned
* to the caller without being retained. On a miss, `store` is consulted before
* the file is streamed.
*/
export declare function readCachedSessionSummary(filePath: string, store?: SessionSummaryStore): Promise<CachedSessionSummary | null>;
/** Session files streamed since process start. Test-only seam for index-hit assertions. */
export declare function sessionSummaryStreamCount(): number;
/** Drop every cached summary and index snapshot. Test-only seam for cold-read assertions. */
export declare function clearSessionSummaryCache(): void;
/** Number of cached summaries. Test-only seam for eviction assertions. */
export declare function sessionSummaryCacheSize(): number;
/** Retained transcript bytes across the cache. Test-only seam for budget assertions. */
export declare function sessionSummaryCacheTextBytes(): number;
//# sourceMappingURL=session-summary-cache.d.ts.map