import type { HostEffect, HostEffectResult, RuntimeDiagnostic, RuntimeOutput } from './execution-contracts.js'; /** Terminal result or single-use continuation exposed to a host-independent runtime driver. */ export type ExecutionMachineStep = { readonly state: 'completed'; readonly value: T; readonly outputs: readonly RuntimeOutput[]; } | { readonly state: 'effect'; readonly effect: HostEffect; readonly frame?: ExecutionSequenceFrame; readonly frames?: readonly ExecutionFrame[]; resume(result: HostEffectResult): ExecutionMachineStep; fail(error: unknown): ExecutionMachineStep; cancel(reason?: unknown): ExecutionMachineStep; } | { readonly state: 'progress'; readonly completed: number; readonly total?: number; readonly frames?: readonly ExecutionFrame[]; continue(): ExecutionMachineStep; cancel(reason?: unknown): ExecutionMachineStep; } | { readonly state: 'cancelled'; readonly reason?: unknown; } | { readonly state: 'control'; readonly transfer: ExecutionControlTransfer; } | { readonly state: 'error'; readonly diagnostics: readonly RuntimeDiagnostic[]; }; /** Evaluator-owned return, break or continue signal crossing a retained execution boundary. */ export interface ExecutionControlTransfer { readonly kind: 'return' | 'break' | 'continue'; readonly signal: unknown; } /** Values are opaque to the driver. The cursor points at the next instruction. */ export interface ExecutionSequenceFrame { readonly kind: 'sequence'; readonly nextInstruction: number; readonly previousValue: unknown; } /** The machine keeps scope and values opaque; evaluator-owned frames expose progress. */ export interface ExecutionFrame { readonly kind: 'sequence' | 'block' | 'loop' | 'call' | 'expression'; readonly nodeType: string; readonly scope: unknown; readonly cursor: number; readonly phase: string; } /** Cancellation is a driver transfer, not a catchable language exception. */ export declare class ExecutionCancellation extends Error { readonly reason: unknown; constructor(reason: unknown); } /** Generator yield containing either a host effect or a cooperative progress checkpoint. */ export type ExecutionYieldRequest = ExecutionEffectRequest | { readonly checkpoint: true; readonly completed: number; readonly frames: readonly ExecutionFrame[]; }; /** Host effect and opaque evaluator frames retained until the request settles. */ export interface ExecutionEffectRequest { readonly effect: HostEffect; readonly frame: ExecutionSequenceFrame; readonly frames?: readonly ExecutionFrame[]; } /** * Host-independent execution boundary for synchronous operations and retained * evaluator generators. Drivers consume single-use progress/effect steps; * cancellation unwinds retained frames without replaying completed work. */ export declare class ExecutionMachine { private readonly operation; private readonly outputs; private finished; private readonly initialStep?; constructor(operation: () => T, outputs?: (value: T) => readonly RuntimeOutput[], initialStep?: () => ExecutionMachineStep); /** Drives a retained generator with single-use continuations and cancellation through its cleanup frames. */ static sequence(execution: Generator, outputs?: (value: T) => readonly RuntimeOutput[], control?: (error: unknown) => ExecutionControlTransfer | undefined): ExecutionMachine; static effect(effect: HostEffect, resume: (result: HostEffectResult) => T, outputs?: (value: T) => readonly RuntimeOutput[]): ExecutionMachine; /** Preserve the synchronous API; waiting is never silently skipped. */ runSynchronously(): T; runUntilYield(): ExecutionMachineStep; }