UNPKG

@code-yeongyu/senpi

Version:

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

94 lines • 3.9 kB
import type { DurableStore, StoreValue } from "@earendil-works/pi-agent-core/conformance"; export type JsonlFileStamp = { size: number; mtimeMs: number; ctimeMs: number; }; type HatchMarker = { size: number; mtimeMs: number; }; type HighWaterMark = { id: string; hash: string; offset: number; end: number; }; type Divergence = { kind: "k9f2"; parentSessionId: string; note: string; }; export type JsonlImportLedger = JsonlFileStamp & { path: string; sourceSessionId: string; sessionId: string; highWaterMark: HighWaterMark; /** The chained digest of every line through the high-water mark; absent in ledgers written before it existed. */ prefixDigest?: string; writerKind: "store" | "hatch" | "other"; checkedAt: number; }; export interface JsonlFiles { stat(path: string): Promise<JsonlFileStamp>; /** Byte range [start, end), not characters. No read may include bytes beyond the captured size. */ read(path: string, start: number, end: number): Promise<Uint8Array>; marker(path: string): Promise<HatchMarker | undefined>; } export declare const jsonlFiles: JsonlFiles; /** * S21b writes this after its fenced hatch write, using that write's stamp, never a later observer's stamp. * Contract: S21b holds the importer's admission line across the hatch write AND this marker. An import admitted between * them would see the write without its marker, adopt it in place as `other`, and then settle on the fast path, so the * fork would never happen. */ export declare function writeHatchMarker(path: string, written: HatchMarker): Promise<void>; export interface JsonlImporterOptions { store: DurableStore; epoch: number; /** The same admission line S20 uses for session mutations and projection writes. */ admission: { admit<T>(mutation: () => Promise<T>): Promise<T>; }; files?: JsonlFiles; now?: () => number; /** Resolution of the source filesystem's mtime, in milliseconds. */ mtimeTickMs?: number; } export type JsonlImportResult = { outcome: "imported" | "extended" | "forked" | "adopted" | "unchanged"; sessionId: string; imported: number; }; /** * S07's import boundary. All mutations are atomic with their ledger record and serialized with the caller's * session admission. It deliberately has no default-store/CLI wiring until S20/S21b. */ export declare function createJsonlImporter(options: JsonlImporterOptions): { open: (paths: readonly string[]) => Promise<JsonlImportResult[]>; importFile: (path: string) => Promise<JsonlImportResult>; getLedger: (path: string) => Promise<JsonlImportLedger | undefined>; getSession: (id: string) => Promise<{ id: string; header: import("@earendil-works/pi-agent-core").SessionHeader; entries: StoreValue[]; divergence: Divergence | undefined; } | undefined>; /** * Record the appends the store projected since the last record, in file order: only the bytes it wrote, so a file * that grew by more keeps the extra bytes unrecorded for the next import. Nothing is re-parsed: the last tail is the * new high-water mark, and the chain runs through every tail, so a burst of appends recorded at once keeps it. */ recordProjectedTail(path: string, sessionId: string, tails: readonly { readonly key: string; readonly line: string; readonly offset: number; }[], written: JsonlFileStamp): Promise<void>; /** * Record only the snapshot S20 wrote, never bytes an interleaving writer added afterward. S20 must pass a * captured stamp and the exact written image, under its projection admission (do not nest admissions). */ recordProjection(path: string, contents: string, written: JsonlFileStamp): Promise<void>; }; export {}; //# sourceMappingURL=jsonl-import.d.ts.map