UNPKG

@code-yeongyu/senpi

Version:

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

90 lines • 4.02 kB
/** * Host budget for extension event handlers (senpi#3650). Past `warnMs` the host reports a handler as stalled; at * `timeoutMs`, or when the turn deadline releases the turn it belongs to, the host stops waiting on it and moves on * (the handler keeps running detached). A value of 0 disables that limit. */ export interface ExtensionHandlerBudget { readonly warnMs: number; readonly timeoutMs: number; } export type ExtensionHandlerStallStage = "warn" | "timeout" | "released" | "late_failure"; export interface ExtensionHandlerStall { readonly extensionPath: string; readonly event: string; readonly stage: ExtensionHandlerStallStage; readonly elapsedMs: number; readonly timeoutMs: number; readonly error?: string; } /** * Why the host stopped waiting on a handler: its hard cap ran out, the turn was stopped (deadline or Esc), or a person's * next input moved on from a settled run whose notification-only handler was still running (omo#11419). */ export type HandlerStopVerdict = "timed_out" | "released" | "yielded"; export type BudgetedHandlerOutcome<T> = { readonly kind: "settled"; readonly value: T; } | { readonly kind: "failed"; readonly error: unknown; } | { readonly kind: "timed_out"; } | { readonly kind: "released"; } | { readonly kind: "yielded"; }; /** Waits on running handlers, tagged with the turn that owns them so a deadline releases only its own turn's waits. */ export declare class HeldHandlerWaits { private readonly releases; hold(scope: number, release: (verdict: HandlerStopVerdict) => void): () => void; release(scope: number, verdict?: HandlerStopVerdict): number; } export interface HeldHandlerSlot { readonly waits: HeldHandlerWaits; readonly scope: () => number; } export interface BudgetedHandlerRun<T> { readonly extensionPath: string; readonly event: string; readonly budget: ExtensionHandlerBudget; readonly run: (signal: AbortSignal) => Promise<T> | T; readonly onStall?: (stall: ExtensionHandlerStall) => void; readonly now?: () => number; } /** One handler under the budget, with an abort signal it can observe (the `session_shutdown` path). */ export declare function runBudgetedHandler<T>(options: BudgetedHandlerRun<T>): Promise<BudgetedHandlerOutcome<T>>; export type HandlerCallOutcome = { readonly ok: true; readonly value: unknown; } | { readonly ok: false; readonly error: unknown; }; export interface BudgetedSequence<R> { readonly event: string; readonly length: number; extensionPath(index: number): string; /** Calls handler `index`; returns its result or promise, unwrapped by the sequence with a plain `await`. */ start(index: number): unknown; /** Applies a handler's outcome; may return a promise only when it has async host work of its own. */ settle(index: number, outcome: HandlerCallOutcome): void | Promise<void>; skip(index: number, verdict: HandlerStopVerdict, budget: ExtensionHandlerBudget): void; /** Ends the walk early (for example a retired runner); the sequence then resolves with `finish()`. */ halted?(): boolean; finish(): R; } export interface SequenceOptions { readonly budget: ExtensionHandlerBudget; readonly held?: HeldHandlerSlot; readonly onStall?: (stall: ExtensionHandlerStall) => void; readonly now?: () => number; } /** * Walks an emission's handlers under the budget. A handler that settles in time is awaited exactly as a direct * `await handler()` would be, so a timely emission keeps its microtask timing. A handler past its cap, or released * by the turn deadline, is skipped: the walk resumes at the next handler in a new run that settles the emission, * and the abandoned run stops when its handler ever returns. A failure after the host stopped waiting is reported. */ export declare function runBudgetedSequence<R>(sequence: BudgetedSequence<R>, options: SequenceOptions): Promise<R>; //# sourceMappingURL=handler-budget.d.ts.map