import type { RunOutcome } from "./session-manager.js"; export type RunState = "idle" | "running" | "cancelling"; /** * Durable record of run boundaries. `RunLifecycle` already owns generation * identity, so hanging the journal off it makes the on-disk pair inherit that * generation-safety for free — a stale run cannot close a newer one's entry. * * Both hooks are fire-and-forget: journalling must never delay a run or fail * one. Implementations swallow their own write errors. */ export interface RunJournalWriter { started(generation: number): void; finished(generation: number, outcome: RunOutcome): void; } export type CancelResult = { status: "cancelled"; generation: number; } | { status: "idle"; generation: number; } | { status: "failed"; generation: number; reason: "timeout"; }; export interface RunLease { generation: number; } export declare class RunBusyError extends Error { constructor(state: RunState); } /** Generation-safe ownership and acknowledged bounded cancellation. */ export declare class RunLifecycle { private readonly onStateChange?; private readonly journal?; private currentState; private nextGeneration; private active?; constructor(onStateChange?: ((state: RunState) => void) | undefined, journal?: RunJournalWriter | undefined); get state(): RunState; get running(): boolean; get generation(): number; begin(abort: () => void): RunLease; isCancellationRequested(generation: number): boolean; /** * Settle only the matching owner; stale generations cannot release a new run. * * `outcome` defaults to `completed`; a cancelled run always records `aborted` * regardless, since cancellation is the authoritative signal here. */ settle(generation: number, outcome?: RunOutcome): { settled: boolean; cancelled: boolean; }; /** Abort once, then acknowledge only after the owning operation settles. */ cancel(timeoutMs: number): Promise; private setState; } //# sourceMappingURL=run-lifecycle.d.ts.map