export type ResultValue = ResultSuccess | ResultFailure; export type ResultSuccess = { __type: "resultType"; success: true; value: any; }; export type FailureOpts = { checkpoint?: any; /** The call failed before its function body began (argument binding, * arity, schema). Its only producer is the tool loop, from the invoke * layer's pre-execution tag — trust-the-producer, because nothing can * correct a wrongly-true claim. */ neverStarted?: boolean; /** Execution entered a destructive region — a `destructive def` body (which * commits at entry) or a `destructive { }` region. */ destructiveRan?: boolean; functionName?: string; args?: Record; /** The guard ids this `try` boundary OWNS. A `guardTrip` cause is * converted to a Failure ONLY when its `guardId` is in this list; * any other guard's trip (an outer guard, or a plain `try` that owns * no guards) re-throws so it reaches its owning boundary. Set by the * stdlib `guard`'s `_runGuarded`. Absent for a plain `try`. */ ownedGuardIds?: string[]; }; /** One hop in a propagated failure's journey: the function whose body was * skipped and the parameter that rejected the failure. */ export type SkippedFunction = { name: string; param: string; }; export type ResultFailure = { __type: "resultType"; success: false; error: any; checkpoint: any; /** The call failed before its function body began. Birth default false; * set only by the tool loop from the invoke layer's pre-execution tag. * Trust-the-producer: there is no correcting machinery, so nothing else * may set it. */ neverStarted: boolean; /** Execution had entered a destructive region — a `destructive def` body * (commits at function entry) or a `destructive { }` region (commits at * region entry) — when this failure was produced. Birth default false; * boundaries OR the activation's flag in via stampFailureBoundary. */ destructiveRan: boolean; functionName: string | null; args: Record | null; skippedFunctions: SkippedFunction[]; }; export declare function success(value: any): ResultSuccess; export declare function failure(error: any, opts?: FailureOpts): ResultFailure; /** Fold an activation's destructive flag into a failure crossing a * boundary (function exit, block halt, block join). OR: once destructive * work started anywhere below, the failure reports it. */ export declare function stampFailureBoundary(f: ResultFailure, destructiveRan: boolean): ResultFailure; /** Record that destructive work ran in the given activation. Writes the * slot the codegen flag lives in (frame.locals IS the generated * function's __self — see lib/runtime/node.ts), so the exit stamp picks * it up with no second source. Sole caller: the tool loop, when a * destructive-marked tool executed or a tool failed destructively. */ export declare function markDestructiveWork(frame: { locals: Record; } | undefined): void; /** Shallow-clone a failure with one more skip entry. Used by the * failure-propagation check when a call short-circuits: the ORIGINAL * failure's error/functionName/args survive untouched so the origin is * never hidden. `failure()` is the single initializer of * skippedFunctions — no `?? []` fallback here (spec: no backward-compat * handling for pre-feature serialized failures). */ export declare function propagateFailure(orig: ResultFailure, skipped: SkippedFunction): ResultFailure; export declare function isSuccess(result: unknown): result is ResultSuccess; export declare function isFailure(result: unknown): result is ResultFailure; /** Wrap a function call in try-catch, returning a Result. * If the function already returns a Result, pass it through (no double-wrapping). */ export declare function __tryCall(fn: () => any, opts?: FailureOpts): Promise; /** Unwrap a Result: return value on success, evaluate fallback on failure. * If the input is not a valid Result, returns it as-is. */ export declare function __catchResult(result: any, fallback: () => any): any; export declare function __pipeBind(result: any, fn: (value: any) => any): Promise;