UNPKG

@code-yeongyu/senpi

Version:

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

54 lines • 3.29 kB
import type { LeafId } from "./compact-content-store.ts"; import { CompactSpoolStorage } from "./compact-spool-storage.ts"; import type { CompactStorageOperation } from "./compact-storage-io.ts"; /** Where a committed leaf's bytes are; a rewrite moves the slot while the leaf stays committed. */ export interface CompactSlot { segment: CompactSegment; offset: number; readonly bytes: number; } /** Byte bound of every segment file, value batches and compaction-round node sets alike (RULING-54). */ export declare const COMPACT_SEGMENT_BYTES = 65536; /** Where one text of a flush batch landed: its segment file and its offset in it. */ export type CompactPlacement = readonly [segment: CompactSegment, offset: number]; /** One flush batch in one spool file, with the leaves still live in it. */ export interface CompactSegment { readonly path: string; readonly bytes: number; readonly operation: CompactStorageOperation; readonly live: Map<LeafId, CompactSlot>; liveBytes: number; readers: number; rewritten: boolean; } /** * Segment packing of compact current-state storage (senpi#4272, RULING-47): a flush batch is a run of * spool files of at most `COMPACT_SEGMENT_BYTES` each (RULING-54), and each leaf is read back by offset * from the one file holding it. A segment is deleted once its last live leaf is * released and no read of it is in flight. When its live bytes fall below half its size it is * rewritten once, so dead bytes on disk stay at most the live bytes of the segments holding them; * a failed rewrite halts spilling and keeps the old segment readable. */ export declare abstract class CompactSegmentStorage extends CompactSpoolStorage { /** Writes the texts back to back as one new file; undefined when the write failed and was reported. */ protected writeSegment(texts: readonly string[], operation: CompactStorageOperation): Promise<CompactSegment | undefined>; /** Splits sized entries, in order, into runs of at most `COMPACT_SEGMENT_BYTES`; a larger entry runs alone. */ protected segmentRuns<T>(entries: Iterable<readonly [T, number]>): T[][]; /** * Writes the texts as one run of bounded segment files, in order, and returns each text's placement * once EVERY file is durable; nothing is registered before then. A failed write discards the files * the run already wrote and returns undefined, so a batch becomes visible as a whole or not at all. */ protected writeSegments(texts: readonly string[], operation: CompactStorageOperation): Promise<readonly CompactPlacement[] | undefined>; protected place(segment: CompactSegment, id: LeafId, offset: number, bytes: number): CompactSlot; protected leave(id: LeafId, slot: CompactSlot): void; protected readSlot(slot: CompactSlot): Promise<Buffer>; /** Deletes an empty segment no read holds, or queues the one rewrite of a mostly dead segment. */ protected settle(segment: CompactSegment): void; /** * Copies the live leaves into a new segment, then repoints their slots; the old file goes when unread. * Only live bytes are read (one range per adjacent run) and they count as I/O copy bytes until the end. */ private rewrite; } //# sourceMappingURL=compact-segment-storage.d.ts.map