import { type SessionStorage, type SessionStorageStat, type SessionStorageWriter, type SessionStorageWriteOptions, type WriteTextAtomicOptions } from "./session-storage.js"; import { type SessionTitleUpdate } from "./session-title-slot.js"; export interface SessionStorageIndexEntry { path: string; size: number; mtimeMs: number; title?: string; titleSource?: SessionTitleUpdate["source"]; titleUpdatedAt?: string; } export interface SessionStorageBackend { init(): Promise; loadIndex(): Promise>; readFull(path: string): Promise; readSlices(path: string, prefixBytes: number, suffixBytes: number): Promise<[string, string]>; /** * Replace content, atomically rejecting when the shared backend's current * UTF-8 byte length differs from `expectedSize`. */ writeFull(path: string, content: string, mtimeMs: number, title?: SessionTitleUpdate, expectedSize?: number | null): Promise; append(path: string, line: string, mtimeMs: number): Promise; updateSessionTitle(path: string, title: SessionTitleUpdate, mtimeMs: number): Promise; truncate(path: string, mtimeMs: number): Promise; remove(paths: string[]): Promise; move(src: string, dst: string, mtimeMs: number): Promise; } interface IndexEntry { size: number; mtimeMs: number; title?: string; titleSource?: SessionTitleUpdate["source"]; titleUpdatedAt?: string; /** * Set on an entry restored after a failed removal: the backend may have * deleted part of the path (Redis deletes the file key before the * metadata), so only a later full write confirms it again. */ unconfirmed?: true; } /** Optimistic index entry a queued append installed, kept for failure rollback. */ interface IndexAppend { mtimeMs: number; previous: IndexEntry | undefined; /** Set when the queued op removes the path (unlink, delete, rename source). */ removal?: true; } export declare class IndexedSessionStorage implements SessionStorage { #private; /** * Sync writes only update {@link #index} and queue the remote publish, so a * caller tracking a durable byte size must wait for {@link drain}. */ readonly defersSyncPublish = true; constructor(backend: SessionStorageBackend); initialize(): Promise; refresh(): Promise; drain(): Promise; ensureDirSync(_dir: string): void; existsSync(path: string): boolean; existsConfirmedSync(path: string): boolean; /** * Resolve once the publishes queued for `path` have settled, rejecting when * one failed. The path tail is installed synchronously by `#enqueuePaths`, * so a caller confirming immediately after `writeTextSync` observes its own * write rather than a later one. */ confirmWrites(path: string): Promise; writeTextSync(path: string, content: string, options?: SessionStorageWriteOptions): void; updateSessionTitle(path: string, title: SessionTitleUpdate): Promise; statSync(path: string): SessionStorageStat; listFilesSync(dir: string, pattern: string): string[]; exists(path: string): Promise; readText(path: string): Promise; readTextSlices(path: string, prefixBytes: number, suffixBytes: number): Promise<[string, string]>; scanLines(path: string, visit: (line: string) => boolean): Promise; writeText(path: string, content: string): Promise; writeTextAtomic(path: string, content: string, options?: WriteTextAtomicOptions): Promise; rename(src: string, dst: string): Promise; unlink(path: string): Promise; deleteSessionWithArtifacts(sessionPath: string): Promise; openWriter(path: string, options?: { flags?: "a" | "w"; onError?: (err: Error) => void; }): SessionStorageWriter; _writerClosed(writer: IndexedSessionStorageWriter): void; _truncateForWriter(path: string): number; _queueTruncate(path: string, mtimeMs: number, getError?: () => Error | undefined): Promise; _appendForWriter(path: string, line: string): IndexAppend; _queueAppend(path: string, line: string, append: IndexAppend, getError?: () => Error | undefined): Promise; } declare class IndexedSessionStorageWriter implements SessionStorageWriter { #private; constructor(storage: IndexedSessionStorage, path: string, options?: { flags?: "a" | "w"; onError?: (err: Error) => void; }); appendSync(line: string): void; append(line: string): Promise; flush(): Promise; isOpen(): boolean; close(): Promise; getError(): Error | undefined; } export {};