UNPKG

@code-yeongyu/senpi

Version:

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

108 lines • 5.83 kB
import { type PendingInputProjection } from "./pending-input-projection.ts"; import type { DeliveryToken, PendingInput, PendingInputEvent, PendingInputHandle, PendingInputOperationResult, SubmitEvent } from "./pending-input-types.ts"; export declare const PENDING_INPUT_TRANSITION = "pending_input_transition"; /** One complete, durable transition: the input after it and the answer it gave, appended before anything else. */ export interface PendingInputJournalRecord { readonly type: typeof PENDING_INPUT_TRANSITION; readonly cursor: number; readonly input: PendingInput; readonly result?: PendingInputOperationResult; /** Further inputs changed in the same step (a consumer's batch), recorded atomically with `input`. */ readonly batch?: readonly PendingInput[]; } export interface PendingInputJournal { append(record: PendingInputJournalRecord): Promise<void>; read(): Promise<readonly PendingInputJournalRecord[]>; } export interface PendingInputStoreOptions { readonly journal: PendingInputJournal; readonly lifetimeId: string; readonly nextQueuedId: () => string; readonly dispatch?: (token: DeliveryToken, input: PendingInput) => void; readonly restoreToDraft?: (text: string) => void; /** Passed to every reopen rebind; see the `rebind` event (senpi#3549). */ readonly uncommittedAttemptsAreUnsent?: boolean; /** * Receives a listener's throw; an owner should always supply it, since the default rethrow is uncaught. A committed transition is not undone by a failing observer, and its dispatch * still runs; by default the error is rethrown on a later microtask so it is never silently lost. */ readonly onListenerError?: (error: unknown) => void; } /** Called after each committed transition with its projection and the journal cursor it was written at. */ export type PendingInputListener = (projections: readonly PendingInputProjection[], cursor: number) => void; /** Transitions inside one gated step: each is committed directly, since the caller already holds the gate. */ export interface PendingInputTransaction { submit(event: Omit<SubmitEvent, "type" | "handle">): Promise<PendingInputOperationResult | undefined>; apply(clientMessageId: string, event: Exclude<PendingInputEvent, SubmitEvent>): Promise<PendingInputOperationResult | undefined>; /** Applies every change in one journal record: all of them land or none does. */ applyAll(changes: readonly { readonly clientMessageId: string; readonly event: Exclude<PendingInputEvent, SubmitEvent>; }[]): Promise<(PendingInputOperationResult | undefined)[]>; current(clientMessageId: string): PendingInput | undefined; } export type PendingInputRead = { readonly status: "admitted"; readonly projection: PendingInputProjection; } | { readonly status: "not_admitted"; readonly clientMessageId: string; }; export interface StopItem { readonly clientMessageId: string; readonly handle: PendingInputHandle; readonly expectedRevision: number; } export interface StopReceipt { readonly removed: readonly string[]; readonly conflicts: readonly { readonly clientMessageId: string; readonly currentRevision: number; }[]; readonly retained: readonly string[]; /** Named with a handle of another lifetime or queue slot: the caller saw another version and must refresh. */ readonly stale: readonly string[]; } /** The one owner of every pending input in a session: reduce, commit, then publish and dispatch (senpi#3549). */ export declare class PendingInputStore { private readonly inputs; private readonly listeners; private gate; private cursor; private unavailable; private readonly options; private constructor(); /** Rebuilds from the complete journal, then gives every still-pending input a handle of this lifetime. */ static open(options: PendingInputStoreOptions): Promise<PendingInputStore>; submit(event: Omit<SubmitEvent, "type" | "handle">): Promise<PendingInputOperationResult | undefined>; apply(clientMessageId: string, event: Exclude<PendingInputEvent, SubmitEvent>): Promise<PendingInputOperationResult | undefined>; /** Explicit Stop over the inputs the caller saw: each named revision is removed or reported, never guessed. */ stop(items: readonly StopItem[], consumerFenced: boolean): Promise<StopReceipt>; /** * Runs `work` under the gate every command shares, so a consumer can change its native buffer and the * journal in one step that no edit, removal or other consumer can interleave with. */ transaction<T>(work: (tx: PendingInputTransaction) => Promise<T>): Promise<T>; /** The full record of one input, for the session that owns this store. */ current(clientMessageId: string): PendingInput | undefined; read(clientMessageId: string): PendingInputRead; /** The cursor of the newest committed transition; a snapshot taken now covers everything through it. */ get throughCursor(): number; snapshot(): readonly PendingInputProjection[]; subscribe(listener: PendingInputListener): () => void; private serialize; private admit; private commit; /** * Reduces every change, then records all that changed in ONE journal record, so a crash or a failed write * keeps either all of them or none (a consumer committing a batch never sees half of it delivered). */ private commitMany; private reportListenerError; } /** A previous write may have landed without being synced; only a reopen can say what the journal holds. */ export declare class PendingInputStoreUnavailableError extends Error { readonly code = "pending_input_store_unavailable"; constructor(cause: Error); } //# sourceMappingURL=pending-input-store.d.ts.map