import type { Checkpoint } from "./state/checkpointStore.js"; import type { MessageJSON } from "smoltalk"; export type RestoreOptions = { messages?: MessageJSON[]; args?: Record; /** Override global variables on restore. Applied to the checkpoint's module. * Only affects globals defined in the same file as the checkpoint. * Globals in other imported files are restored from checkpoint state. */ globals?: Record; /** Maximum number of times this checkpoint's source location may be restored. * Once the limit is reached, the restore is skipped (returns instead of throwing). * The count is keyed by the checkpoint's source location (moduleId:scopeName#stepPath), * so it persists across checkpoint ID changes caused by restore cycles. */ maxRestores?: number; }; export declare class CheckpointError extends Error { constructor(message: string); } export declare class RestoreSignal extends Error { checkpoint: Checkpoint; options?: RestoreOptions; constructor(checkpoint: Checkpoint, options?: RestoreOptions); } export declare class ConcurrentInterruptError extends Error { constructor(message: string); } /** * Structured reason carried by every abort — on `AbortController.abort(cause)` * (so it surfaces as `signal.reason`) and on the `agencyCause` field of a * thrown `AgencyCancelledError`. The `kind` discriminant lets every * catch/boundary READ the intent instead of re-deriving it (which is what the * runner's guard-sniff and the leaf bare-throws used to do). See * docs/superpowers/specs/2026-06-21-abort-taxonomy-design.md. */ export type AbortCause = { kind: "userInterrupt"; } | { kind: "userKill"; reason?: string; } | { kind: "guardTrip"; dimension: "cost" | "time"; limit: number; spent: number; guardId: string; /** User-facing name from `guard(label: "...")`. Absent when the * guard was not labeled. Rides the cause so failure messages and * future trip interrupts can say WHICH guard tripped. */ label?: string; /** * Mutable de-dup flag. A time-guard trip can be delivered by EITHER * an aborted leaf op (→ `__tryCall` converts to a Failure) OR the * runner's `shouldSkip` (→ throws `GuardExceededError`). Whichever * fires first sets this; the other then knows the trip is already * handled and must not re-deliver. The cause object has stable * identity across the composed signal (`AbortSignal.any` adopts the * source's reason object), so this single flag is visible to both * paths. See docs/superpowers/specs/2026-06-21-abort-taxonomy-design.md §3.4. */ delivered?: boolean; } | { kind: "raceLoser"; } | { kind: "cleanup"; } | { kind: "callDepthExceeded"; limit: number; observed: number; } | { kind: "callTimeout"; limitMs: number; }; /** Brand so a plain object on `signal.reason` is recognizable as ours. */ declare const ABORT_CAUSE_BRAND = "__agencyAbortCause"; export declare function makeAbortCause(cause: AbortCause): AbortCause & { [ABORT_CAUSE_BRAND]: true; }; /** * Read the structured `AbortCause` off an `AbortSignal` (its `reason`), a * thrown `AgencyCancelledError` (its `agencyCause`), or a bare cause value. * Returns `undefined` when no structured cause is present — callers keep * their existing heuristics as a fallback for that case. * * Note: this uses `instanceof AgencyAbort`, NOT the name-based fallback that * `isAbortError` adds for errors that cross module instances (the resolver * shim — see below). Every abort producer and consumer lives in one runtime * module instance, so `instanceof` holds. If a cause ever needs reading * across that boundary, `readCause` returns `undefined` where `isAbortError` * would still recognize the error — the in-process sibling of the subprocess * cause-payload risk noted in the abort-taxonomy spec. */ export declare function readCause(source: unknown): AbortCause | undefined; /** * The single unified abort type. EVERY abort — a user cancellation * (`AgencyCancelledError`) AND a guard trip (`GuardExceededError`) — is an * `AgencyAbort` carrying a structured `AbortCause`. Generated code catches * exactly one thing in its abort rung (`__error instanceof AgencyAbort`) and * re-throws it untouched; the owning guard's boundary converts its own * `guardTrip`, everything else unwinds. `RestoreSignal` stays separate (it is * not an abort). See docs/superpowers/specs/2026-06-21-abort-taxonomy-design.md §5. */ export declare class AgencyAbort extends Error { /** Structured intent for this abort. */ readonly agencyCause: AbortCause; constructor(message: string, cause: AbortCause); } /** A short, human-readable description of an abort cause. Used when an * AbortedResult is converted back into an exception at the places that * still speak exceptions (the graph engine, runBatch join points). */ export declare function describeAbortCause(cause: AbortCause): string; export declare class AgencyCancelledError extends AgencyAbort { constructor(reason?: string, cause?: AbortCause); } /** Thrown by the call-depth guard (lib/runtime/callDepth.ts, invoked from * every `AgencyFunction.invoke()`) when the logical function-call nesting * depth exceeds `maxCallDepth`. Almost always indicates unbounded recursion — * most dangerously the async kind, which flattens V8's stack and grows the * promise chain until the process OOMs with no useful diagnostic. Modeled as * an `AgencyAbort` (like `GuardExceededError`) so it propagates untouched * through every generated catch rung and halts the run rather than being * converted to a Failure and silently re-descending into the recursion. */ export declare class CallDepthExceededError extends AgencyAbort { readonly limit: number; readonly observed: number; constructor(limit: number, observed: number, recentFrames: string[]); } /** Thrown by `runHandlerChain` (lib/runtime/interrupts.ts) when nested * handler-chain dispatch depth exceeds `MAX_HANDLER_CHAIN_DEPTH`. Almost * always indicates a handler raised an interrupt that re-enters the same * handler (directly or via the chain dispatcher visiting every handler). * Carries the interrupt effect that tripped the limit so the diagnostic * points at the right place. */ export declare class HandlerRecursionError extends Error { readonly effect: string; readonly depth: number; constructor(effect: string, depth: number); } export declare function isAbortError(error: unknown): boolean; export {};