UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

62 lines • 2.71 kB
/** * Generic atomic, versioned, per-session sidecar store. * * Extracted from the loop store's persistence discipline: a module-level per-file * promise tail serializes read-modify-write cycles, writes go through a temp file * with 0600 permissions and a rename, and parsing fails closed on version or * session mismatches so a corrupt or foreign file never silently resets state. */ export declare class InvalidSidecarStoreError extends Error { constructor(message: string, options?: { cause?: unknown; }); } export declare class UnsupportedSidecarStoreVersionError extends Error { constructor(message: string); } /** Location identity of one sidecar file: a directory plus the session it belongs to. */ export interface SidecarStoreRef { baseDir: string; sessionId: string; } /** Validates the domain fields of an already version- and session-checked payload. */ export type SidecarPayloadParser<T> = (raw: unknown, ref: SidecarStoreRef) => T; export interface CreateSidecarStoreOptions<T> { baseDir: string; sessionId: string; version: number; tempPrefix: string; parse: SidecarPayloadParser<T>; } export interface SidecarStore<T> { filePath: string; read(): Promise<T | null>; write(state: T): Promise<void>; mutate(fn: (current: T | null) => T | Promise<T>): Promise<T>; snapshot(): T | undefined; clear(): void; } export declare function encodedSessionId(sessionId: string): string; export declare function sidecarFilePath(ref: SidecarStoreRef): string; /** * Creates a per-session store bound to `baseDir/<encoded session id>.json`. * Two stores for the same file share the mutation tail and snapshot cache. */ export declare function createSidecarStore<T>(options: CreateSidecarStoreOptions<T>): SidecarStore<T>; /** * Writes `contents` to `filePath` atomically: a hidden temp file (0600) next to the * target, then a rename over it. On failure the temp file is removed; if that * cleanup also fails, both errors surface as one AggregateError. */ export declare function writeAtomic(filePath: string, contents: string, tempPrefix: string): Promise<void>; /** * Serializes read-modify-write cycles per key across every sidecar consumer. * * `key` must be the resolved absolute file path of the sidecar (the same string * `createSidecarStore` uses for that file). Callers that own their own writer * (goal) call this directly around that writer. Callers that want the whole * store (loop) go through `createSidecarStore`, whose `mutate` already uses * this tail. */ export declare function serializeByKey<T>(key: string, operation: () => Promise<T>): Promise<T>; //# sourceMappingURL=session-sidecar-store.d.ts.map