UNPKG

@code-yeongyu/senpi

Version:

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

108 lines • 5.71 kB
import { type CatalogEntry } from "./compact-catalog-codec.ts"; import { type CompactContentStore, type CompactStorageStatus, type LeafId } from "./compact-content-store.ts"; import { type FrozenBytes } from "./compact-recovery-bytes.ts"; import type { BoundedId, ContentDigest } from "./compact-recovery-ids.ts"; /** * The stored bytes one staging owner may hold staged and not yet adopted: B_worker (S12 design section 3), the host's * capacity for worker transfers. `begin` reserves a transfer's whole declared length before any leaf exists, so a * refusal allocates nothing; the bytes leave the bound when the content is adopted, released or aborted. */ export declare const TRANSFER_STAGING_MAX_BYTES: number; export type StagingRefusal = "staging_over_byte_limit" | "fragment_over_limit" | "length_mismatch" | "staging_closed"; export declare class TransferStagingError extends Error { readonly reason: StagingRefusal; constructor(reason: StagingRefusal); } /** A read by identity found its segment gone (`segment_missing`) or holding other bytes (`segment_mismatch`). */ export declare class StagedReadError extends Error { readonly reason: "segment_missing" | "segment_mismatch"; constructor(reason: StagedReadError["reason"], options?: ErrorOptions); } /** * A frozen reference (RULING-46 item 2, RULING-63 Q2): content named by an S11a catalog entry, encoded only by that * codec (`CatalogNodeWriter` / `decodeCatalogNode`); `length` and `digest` are those of its exact stored UTF-16LE * bytes in the `leaf` domain. `staged` content lives in a host staging store; S13's lease variant extends this union * beside it and never reshapes it. */ export type FrozenRef = { readonly variant: "staged"; readonly entry: CatalogEntry; }; /** * Committed staged content: its frozen ref and the immutable leaves holding it, one live reference owned, with each * leaf's codec `leaf` digest so every read verifies a leaf before returning any of it (RULING-78 (2)). */ export interface StagedContent { readonly ref: FrozenRef; readonly leaves: readonly LeafId[]; readonly leafDigests: readonly ContentDigest[]; } export interface StagingStatus extends CompactStorageStatus { readonly stagedBytes: number; readonly openTransfers: number; } /** * One logical value arriving in fragments (S12 design section 3): its stored length is declared up front, each * fragment becomes owned immutable leaves as it arrives, and nothing is visible until `commit`. A refusal aborts the * transfer and releases what it staged; `abort` is idempotent. */ declare class StagedTransfer { private readonly store; private readonly entry; private readonly settle; private readonly digester; private readonly leaves; private readonly leafDigests; private fed; private open; constructor(store: CompactContentStore, entry: Pick<CatalogEntry, "kind" | "id" | "length">, settle: (content: StagedContent | undefined) => void); append(text: string): void; commit(): StagedContent; abort(): void; private assertOpen; private refuse; } /** * The shared bounded staging substrate (S12a; S12b's worker transfers and S13's leases reuse it): content is staged in * bounded fragments into one content store, which spills it like any payload leaf, and named by a `FrozenRef`. Staged * content stays unaccepted until its owner adopts it; `close` aborts every open transfer and releases everything never * adopted before the store retires. */ export declare class TransferStaging { readonly store: CompactContentStore; private readonly maxBytes; private readonly transfers; private readonly staged; private reserved; private closed; constructor(store: CompactContentStore, maxBytes?: number); /** Stored bytes reserved by open transfers and committed content not yet adopted. */ get stagedBytes(): number; /** Stored bytes of this store resident in RAM, staged and adopted alike. */ get residentBytes(): number; begin(kind: BoundedId, id: BoundedId, length: number): StagedTransfer; /** One whole text staged as fragments of at most D stored bytes; a refusal leaves nothing staged. */ stage(kind: BoundedId, id: BoundedId, text: string): StagedContent; /** The acceptor takes the content: its bytes leave the staging bound and its leaves stay owned by the acceptor. */ adopt(content: StagedContent): void; /** Drops the owner's live reference; content never adopted also leaves the staging bound. */ release(content: StagedContent): void; /** Releases content only while it is still staged; adopted content is its acceptor's to release. */ abandon(content: StagedContent): void; /** A reader's pin: the leaves outlive every owner's release until the pin is returned. */ pin(content: StagedContent, pins: 1 | -1): void; /** The content as S11a byte pages, its digest verified against the stored leaves before any range is served. */ open(content: StagedContent, valid?: () => void): Promise<FrozenBytes>; /** * The content's text leaf by leaf (at most 64 KiB stored, under D), each leaf verified against its digest before it * is yielded: a missing or changed segment is a typed `StagedReadError` and no other bytes are ever returned. */ chunks(content: StagedContent, valid?: () => void): AsyncGenerator<string>; /** Moves the content's resident leaves to the spool, so content kept only for readers holds no RAM. */ spill(content: StagedContent): void; status(): StagingStatus; idle(): Promise<void>; close(): Promise<void>; } export {}; //# sourceMappingURL=compact-transfer-staging.d.ts.map