UNPKG

@code-yeongyu/senpi

Version:

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

93 lines • 5.13 kB
import type { DeliveryTicketId, ObligationKind, ObligationToken, WorkObligations } from "./session-lifecycle-types.ts"; import type { SessionEntry } from "./session-manager.ts"; import { type CustodyPayload, type WorkCustodyRecord } from "./work-custody-record.ts"; /** Custody keys the engine opens itself (senpi#3986): queued deliveries and published wake sources. */ export declare const ENGINE_DELIVERY_KEY_PREFIX = "delivery:"; export declare const WAKE_SOURCE_KEY_PREFIX = "wake-source:"; export declare const ENGINE_CUSTODY_KEY_PREFIXES: readonly ["delivery:", "wake-source:"]; /** Why a delivery ticket may not take a new delivery now (senpi#3864); "admitted" when it may. */ export type TicketAdmission = "admitted" | "unknown" | "closed" | "consumed" | "delivering"; /** Why a send's ticket was refused: its admission, or a re-send whose items differ from the queued message's. */ export type DeliveryTicketRefusal = Exclude<TicketAdmission, "admitted"> | "different_items"; /** A send whose delivery ticket was refused before anything was written. */ export declare class DeliveryTicketRefused extends Error { readonly ticketId: string; readonly reason: DeliveryTicketRefusal; constructor(ticketId: string, reason: DeliveryTicketRefusal); } export declare class CustodyViolation extends Error { readonly key: string; constructor(key: string); } export interface CustodyStore { readonly entries: readonly SessionEntry[]; append(record: WorkCustodyRecord): void; changed(): void; } /** One session's durable registry. A token never acknowledges its own delivery. */ export declare class SessionWorkObligations implements WorkObligations { private readonly records; private readonly unpersisted; private readonly delivering; /** Engine delivery custody a send opened in this process and has not queued yet (senpi#6810). */ private readonly sending; private readonly publishedSources; private readonly store; constructor(store: CustodyStore); get active(): readonly WorkCustodyRecord[]; get activeCount(): number; get persisted(): boolean; open(key: string, kind: ObligationKind, detail?: string): ObligationToken; /** * An engine delivery's own custody while its send is in flight (senpi#6810): the session is starting or joining a * turn for that delivery, so this custody is never background work the session waits on. */ isDeliveryInFlight(record: WorkCustodyRecord): boolean; /** * An engine delivery's own custody that the given run consumed: that run's own work until `settleRun`, so never a * background wait, even after its delivery ended (senpi#6814 review). */ isConsumedBy(record: WorkCustodyRecord, runId: string | undefined): boolean; syncSource(source: string, kind: ObligationKind, activeCount: number, items?: unknown): void; /** After a restart, a restored wake source stays open only if its producer published again. */ retireRestoredSources(): void; /** * The single ticket admission check every send branch runs before it writes anything (held notices, a queued * message, a delivery): an unknown, closed, consumed or in-delivery ticket takes no new delivery. */ admission(ticketId: DeliveryTicketId): TicketAdmission; queue(ticketId: DeliveryTicketId, payload: CustodyPayload): boolean; /** The item ids a queued ticket's batch was recorded with, if any. */ queuedItemIds(ticketId: DeliveryTicketId): readonly string[] | undefined; /** * A delivery whose custody is still open and unconsumed (kept for a later turn) is background work again: recompute. * A delivery its turn consumed stays that run's own work until `settleRun`, so ending it publishes nothing (senpi#6814). */ endDelivery(ticketId: DeliveryTicketId): void; passive(ticketId: DeliveryTicketId): void; consumed(ticketId: DeliveryTicketId, run: { readonly runId: string; readonly transcriptEntryId: string; }): void; failed(ticketId: DeliveryTicketId): void; held(ticketId: DeliveryTicketId, noticeId: string): void; retire(ticketId: DeliveryTicketId): void; cancel(ticketId: DeliveryTicketId): void; settleRun(runId: string): void; /** * At restoration, a consumed delivery of any run other than the restored current one belongs to a run that ended: * its message is already in the conversation, so it settles as `idle()` would have (senpi#4848). The current run's * consumed custody stays for crash recovery and `startRun`, unless the transcript holds that run's end * (`currentRunEnded`, senpi#7016). With no recorded run nothing proves the consuming run ended, so crash recovery * keeps all of it. */ settleEndedRuns(currentRunId: string | undefined, currentRunEnded: boolean): void; private install; /** A lifecycle publication cannot claim durability before its live custody is durable. */ flush(): void; private owned; private ticketRecord; private close; private token; } //# sourceMappingURL=work-obligations.d.ts.map