UNPKG

@code-yeongyu/senpi

Version:

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

92 lines • 4.9 kB
import { CompactSegmentStorage } from "./compact-segment-storage.ts"; import { type CompactStorageFailure, type CompactStorageIo, type CompactStorageOperation } from "./compact-storage-io.ts"; import { CompactTextRoots } from "./compact-text-roots.ts"; import type { RecoveryStorageHealth } from "./compact-storage-health.ts"; /** * Owned bounded leaves for compact current state (senpi#4272, R3.C6.4 / R3.C2.4). * * Acceptance never waits here: a leaf is created synchronously in RAM, and a spill only relocates * that immutable value. Its RAM copy is released only after the whole file was written and closed; * a failed write keeps the bytes resident, halts further spilling and is reported through * `status()`, never dropped. All storage work runs as one serial asynchronous job chain. */ /** 32,768 UTF-16 code units (64 KiB as UTF-16LE), so a split surrogate survives a leaf boundary exactly. */ export declare const COMPACT_LEAF_CODE_UNITS = 32768; export type LeafId = number; export declare class CompactWriteError extends Error { readonly reason: "size_limit" | "storage_unavailable" | "cycle" | "unsupported_value"; /** Set only on a record refused at the protocol depth limit (`compact-protocol-depth.ts`): that limit. */ readonly limit: number | undefined; constructor(reason: CompactWriteError["reason"], limit?: number); } export interface CompactStorageStatus { readonly structuredBytes: { readonly resident: number; readonly spilled: number; readonly pinned: number; }; readonly residentPayloadBytes: number; readonly pendingIoCopyBytes: number; readonly pinnedOnlyBytes: number; readonly spilledLiveBytes: number; readonly spillBytesWritten: number; readonly reclaimDebtBytes: number; /** Resident bytes above the spill target that a halted spool keeps in RAM (ruling 08 condition 1). */ readonly spillFailureRetainedBytes: number; readonly spillHalted: boolean; readonly failures: readonly CompactStorageFailure[]; } export interface CompactContentStoreOptions { readonly health?: RecoveryStorageHealth; /** Private epoch spool directory the store creates itself (0700, never an existing one; files 0600). Not a transcript. */ readonly dir: string; readonly io?: CompactStorageIo; /** Spilling starts above this many resident leaf bytes and stops at the target. */ readonly spillAboveBytes?: number; readonly spillTargetBytes?: number; } export declare class CompactContentStore extends CompactSegmentStorage { private readonly spillAboveBytes; private readonly spillTargetBytes; private readonly leaves; /** Resident leaves in creation order, so each spill takes the oldest without rescanning committed ones. */ private readonly ramLeaves; private readonly ramValues; private valueQueued; private readonly structuredBytes; private nextLeafId; private residentPayloadBytes; private pinnedOnlyBytes; private spilledLiveBytes; private readonly subscribers; readonly text: CompactTextRoots; subscribeCommitted(listener: (id: LeafId) => void): void; committed(id: LeafId): void; leafUnits(id: LeafId): number; constructor(options: CompactContentStoreOptions); /** Takes ownership of an immutable value with one live reference. */ createLeaf(text: string, value?: boolean): LeafId; /** A committed index file participates in the same ownership graph as its descriptors. */ ownFile(path: string, bytes: number): LeafId; /** Moves live and cut-pin references; the last reference drops RAM or reclaims the file. */ adjust(id: LeafId, live: number, pins: number): void; isCommitted(id: LeafId): boolean; /** Reads a leaf the caller still references, from RAM or its committed file. */ readLeaf(id: LeafId): Promise<string>; status(): CompactStorageStatus; protected scheduleSpill(): void; /** Spills one oldest resident leaf per job, so other storage work interleaves fairly. */ private spillNext; /** Commits one page-bounded batch of structural leaves ahead of a cold-index rewrite. */ flushValues(): Promise<void>; /** Serial storage jobs can flush one newly built structural page without waiting on their own queue. */ flushLeaf(id: LeafId): Promise<void>; /** * Writes the resident leaves among `ids`, all of one kind, as segment files of at most 64 KiB each, then * publishes them in one synchronous step once the last file is durable: that step is the batch's commit * record, so no leaf is committed and no file is reachable before every file of the batch exists. A * compaction round passes `node_write`; its files get the `node-` prefix. */ flushLeaves(ids: Iterable<LeafId>, operation?: CompactStorageOperation): Promise<void>; } //# sourceMappingURL=compact-content-store.d.ts.map