@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
54 lines • 3.61 kB
TypeScript
import { type CatalogEntry } from "./compact-catalog-codec.ts";
import type { LeafId } from "./compact-content-store.ts";
import type { ContentDigest } from "./compact-recovery-ids.ts";
/** D (R4.B3): the most raw bytes one fragment carries; its base64 (174,764) plus H (16,384) fits F (262,144). */
export declare const FRAGMENT_MAX_BYTES = 131072;
/**
* The page budget on the wire (RULING-69 (1)): the base64 envelope of a full fragment, derived from D (four characters
* per three raw bytes, the last group padded); S12's initial worker credit is one such envelope (RULING-63).
*/
export declare const FRAGMENT_ENVELOPE_MAX_BYTES: number;
/**
* One frozen component as the byte stream the recovery pages address (S11a, RULING-46 item 2: the one byte
* representation S11b, S12a and S13 reuse): its EXACT stored UTF-16LE bytes in leaf order (RULING-58 (1)), addressed by
* raw byte offset, never by code unit or base64 character. For a catalog component, `digest` is the catalog entry's
* `leaf` digest of the whole stream, verified against the stored bytes before this exists (RULING-57 Q1 (3)); a range
* is served from the same immutable leaves with at most one stored leaf resident beside the result. For the loaded
* base stream (`compact-recovery-base.ts`) it is the cut's `idFingerprint` (RULING-71 (4)), the anchor a client
* re-derives from the rows' `kind` and `id`, never a digest of the stream's bytes.
*/
export interface FrozenBytes {
readonly length: number;
readonly digest: ContentDigest;
/** The most stored leaves resident at once across every range read; a test instrument for RULING-59 A. */
readonly peakResidentLeaves: number;
range(offset: number, length: number, valid?: () => void): Promise<Buffer>;
}
/** One bounded page of a component's bytes: `digest` is the `fragment`-domain digest of exactly `bytes`. */
export interface RecoveryPage {
readonly offset: number;
readonly length: number;
readonly bytes: Buffer;
readonly digest: ContentDigest;
readonly next: number | null;
readonly complete: boolean;
}
type ReadLeaf = (leaf: LeafId) => Promise<string>;
/** The checks every `FrozenBytes.range` makes before touching a byte: shape, the D bound, then the stream's end. */
export declare function assertRange(offset: number, length: number, total: number): void;
/** The index of the last of `count` ascending starts at or before `offset`: the unit whose byte range holds it. */
export declare function startAtOrBefore(starts: ArrayLike<number>, count: number, offset: number): number;
/**
* Opens a component's stored leaves as `FrozenBytes` after verifying them, one leaf resident, against the catalog
* entry's length and digest; a mismatch is `integrity` and no byte source exists. `valid` runs after every leaf read.
* The verification belongs to the request that asked for it (RULING-69 (2)): once `signal` aborts, no further leaf is
* read and the open is the typed `aborted`, holding nothing.
*/
export declare function openFrozenBytes(entry: Pick<CatalogEntry, "length" | "digest">, leaves: readonly LeafId[], read: ReadLeaf, valid: () => void, signal?: AbortSignal): Promise<FrozenBytes>;
/**
* The page at a raw byte offset: at most `FRAGMENT_MAX_BYTES` bytes, `next` the offset the following page starts at
* (null once the stream is complete). An offset past the last byte is `range`; an empty component is one empty page.
*/
export declare function producePage(bytes: FrozenBytes, offset: number, valid?: () => void): Promise<RecoveryPage>;
export {};
//# sourceMappingURL=compact-recovery-bytes.d.ts.map