UNPKG

@code-yeongyu/senpi

Version:

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

91 lines • 4.36 kB
/** * One payload permit, and the fixed initial credit of every permit block: ONE S11 page envelope in bytes (RULING-63 Q3, * RULING-69 (1)), derived from the page budget, never a second literal. One permit pays for one physical frame of at * most D stored payload bytes, which the envelope always covers. */ export declare const WORKER_PERMIT_BYTES: number; /** Ledger slots kept for control progress: data permits never take them (S12 design section 3, RULING-80 (1)). */ export declare const WORKER_CONTROL_SLOTS = 1; /** * The Int32 words of a permit block (RULING-63 Q3 (1)): `credit` bytes, which only the host adds to and only the worker * takes from; the host's tagged word (granted, denied, closed), which only the host writes; the worker's tagged word * (idle, waiting), which only the worker writes; and `wake`, a count only the host adds to on every signal, the one * word the worker waits on (#5591). Every read is an `Atomics.load`. */ export declare const PERMIT_WORD: { readonly credit: 0; readonly host: 1; readonly worker: 2; readonly wake: 3; }; /** The size of one permit block: one Int32 per word of {@link PERMIT_WORD}. */ export declare const PERMIT_BLOCK_BYTES: number; export declare const PERMIT_TAG: { readonly idle: 0; readonly granted: 1; readonly denied: 2; readonly closed: 3; readonly waiting: 4; }; /** How one permit request ended; anything but `granted` leaves the worker with no payload built. */ export type PermitOutcome = "granted" | "denied" | "timeout" | "closed"; /** * The host's payload capacity for every session worker (S12 design section 3): B_worker bytes in whole permits, one of * them kept for control progress, so data frames never take the room the bounded control exchanges (write * reservations, capabilities, results, failures) travel in. A request past the ceiling is refused before anything is * allocated and queued; a release hands its permit to the oldest queued request. */ export declare class WorkerPermitLedger { readonly ceiling: number; private granted; private readonly waiting; constructor(capacity?: number); request(grant: () => void): boolean; release(): void; withdraw(grant: () => void): void; status(): { readonly granted: number; readonly waiting: number; readonly ceiling: number; }; } /** The one ledger of this host process, shared by every worker it starts (never one per worker). */ export declare const hostWorkerPermits: WorkerPermitLedger; /** * The host half of one worker incarnation's permit block. It grants or denies before the worker builds any payload, * also while that worker is blocked in `Atomics.wait`, and holds at most one permit for it: granted and unspent, or * spent on the one frame in flight. */ export declare class HostPermits { readonly block: SharedArrayBuffer; private readonly state; private readonly ledger; private holding; private closed; private readonly grant; constructor(ledger: WorkerPermitLedger); /** The worker spent its permit on a frame the host now holds: the capacity returns and the next permit follows. */ returned(): void; /** Wakes every waiter with `closed`; the held permit, or the queued request, leaves the ledger exactly once. */ close(): void; private request; /** * Every signal changes `wake` after its own writes, so a worker that read `wake` before deciding to wait sees the * change when its wait starts, even if the notify ran before the worker was parked (#5591). */ private signal; } /** * The worker half of a permit block: takes one permit before the worker builds any payload. The wait loops, re-checking * after every wake, until a permit is taken, the host closes, or the deadline passes (RULING-63 Q3 (2)). A deny keeps * the request alive, so a later grant still ends the wait (recoverable); it only names the outcome at the deadline. * Each pass reads `wake` first and waits on that value, so a host signal between the checks and the wait ends it. */ export declare class WorkerPermitGate { private readonly state; private readonly timeoutMs; constructor(block: SharedArrayBuffer, timeoutMs: number); acquire(): PermitOutcome; private mark; } //# sourceMappingURL=session-worker-permits.d.ts.map