UNPKG

@code-yeongyu/senpi

Version:

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

108 lines • 5.83 kB
import { CompactReadLease } from "./compact-read-lease.ts"; import { type FrozenBytes, type RecoveryPage } from "./compact-recovery-bytes.ts"; import { type RecordContent } from "./compact-record-staging.ts"; export type { RecordContent } from "./compact-record-staging.ts"; import { type EventLease, type RecoveryCaller, type RecoveryOutcome } from "./compact-recovery-types.ts"; import { type StagedContent } from "./compact-transfer-staging.ts"; /** F (R4.A3): the largest compact physical record, its newline included; two D-byte fragments. */ export declare const COMPACT_RECORD_MAX_BYTES: number; export type EventLeaseRefusal = "lease_limit" | "storage_unavailable"; /** The record's legacy line when a destination already built it, else its stored size to stream it at (RULING-81 X06). */ export type ReleaseOutcome = "released" | "held" | "duplicate"; export interface ReleaseReceipt { readonly lease: { readonly kind: "event"; readonly id: string; }; readonly outcome: ReleaseOutcome; readonly remaining: number; } export interface EventLeaseCounters { readonly open: number; readonly peers: number; readonly minted: number; readonly released: number; readonly duplicates: number; /** Leases whose envelope the socket actor dropped before it reached the peer. */ readonly abandoned: number; /** Stored bytes of accepted records still pinned by a lease. */ readonly contentBytes: number; readonly refused: Readonly<Partial<Record<EventLeaseRefusal, number>>>; } /** One accepted record's staged text, shared by every peer's lease on it and released with the last of them. */ interface SharedContent { readonly content: StagedContent; holders: number; opened?: Promise<FrozenBytes>; } /** A peer's lease: its sessions scope, the admissions still referencing it and the operation lease its reads run under. */ export interface HeldLease { readonly lease: EventLease; readonly sessionId: string; readonly shared: SharedContent; readonly admissions: Set<string>; readonly reads: CompactReadLease; } /** * The ordinary-event leases of one host (S13, R4.B6; RULING-65 S13-Q1/Q2 = A). A record past F for a peer that selected * compact events is staged once, as its exact JSON text, into this owner's own spillable store and leased to each such * peer at the record's accepted sequence. A lease is scoped like a checkpoint token (another peer or session is * `unknown_token`, with no state), never mints a generation and holds no lane root, so a checkpoint's lifetime and a * superseded root are untouched by it. It is released only by its consumer's receipt, sent after the consumer * committed the content (the named commit point: desktop's successful command-transaction dispatch); transport drain, * worker credit or staging every page release nothing. Per (peer, lease) the referencing admissions are counted, * released at zero, never below; a retried receipt is the typed `duplicate`. A peer's end releases all of its leases. */ export declare class EventLeases { readonly peerLimit: number; private readonly peers; private readonly shared; private readonly ended; private readonly refusals; private staging; private open; private minted; private released; private duplicates; private abandoned; private contentBytes; constructor(peerLimit?: number); /** Runs once per lease when it ends, however it ended (a receipt or its peer's end). */ onLeaseEnd(listener: (leaseId: string) => void): void; /** * A lease for one peer admission on the record `line` serializes (keyed by `record`, so every peer shares one staged * copy), taken synchronously at acceptance: later mutation of the provider object cannot reach the staged text. */ mint(caller: RecoveryCaller & { readonly admissionId: string; }, at: Pick<EventLease, "sessionEpoch" | "sequence">, record: object, content: RecordContent): { readonly ok: true; readonly value: EventLease; } | { readonly ok: false; readonly reason: EventLeaseRefusal; }; /** The caller's own live lease, or `unknown_token` with no state. */ claim(caller: RecoveryCaller, leaseId: string, admissionId: string): RecoveryOutcome<HeldLease>; /** One bounded page of the leased record, its whole digest verified once before any page is served. */ page(held: HeldLease, componentRef: string, offset: number, signal?: AbortSignal): Promise<RecoveryOutcome<RecoveryPage>>; /** The consumer's receipt for one admission's reference (RULING-65 S13-Q2): idempotent, identity-bound, never below 0. */ release(caller: RecoveryCaller, leaseId: string, admissionId: string): RecoveryOutcome<ReleaseReceipt>; /** * The envelope naming this lease never reached its peer (superseded, shed or cut by the socket actor, S13a review): * the lease ends with no receipt, at once and only once; an unknown or already ended lease is a no-op. */ abandon(socketEpoch: string, leaseId: string): void; /** A retired admission can no longer send receipts; drop only its references, preserving other holders. */ forgetAdmission(caller: RecoveryCaller, admissionId: string): void; /** A peer incarnation is gone: every lease it holds ends once the reads in flight on it unwind. */ forgetPeer(socketEpoch: string): void; status(): EventLeaseCounters; /** The record's text staged once and adopted by this owner; undefined when the store could not take it. */ private stage; private remember; /** The lease's last operation unwound after its release: its content goes with the last lease sharing it. */ private dispose; private refuse; } //# sourceMappingURL=compact-event-leases.d.ts.map