/** * AXError - Structured errors with recovery actions * * Per AX-CONTRACT.md v0.1, Guarantee 2.3: Recoverable Errors * * When something fails, an AI knows what went wrong and what to try next. * All structured errors MUST follow this shape. * * @module shared/errors */ import { z } from "zod"; /** * AXError schema - the canonical shape for structured errors * * @example * ```json * { * "code": "FRAME_NOT_FOUND", * "message": "Frame with ID 'abc123' not found", * "context": { "frameId": "abc123" }, * "nextActions": ["Run 'lex timeline' to see recent Frames"] * } * ``` */ export declare const AXErrorSchema: z.ZodObject<{ code: z.ZodString; message: z.ZodString; context: z.ZodOptional>; nextActions: z.ZodArray; }, z.core.$strip>; /** * TypeScript type for AXError */ export type AXError = z.infer; /** * Type guard to check if a value is an AXError * * @example * ```typescript * if (isAXError(error)) { * console.log(error.nextActions[0]); * } * ``` */ export declare function isAXError(value: unknown): value is AXError; /** * Create a validated AXError * * @throws {ZodError} if inputs don't match schema * * @example * ```typescript * const error = createAXError( * 'FRAME_NOT_FOUND', * 'Frame not found', * ['Run "lex timeline" to see recent Frames'], * { frameId: 'abc123' } * ); * ``` */ export declare function createAXError(code: string, message: string, nextActions: string[], context?: Record): AXError; /** * Wrap a standard Error as an AXError * * Useful for catching exceptions and converting them to structured form. * * @example * ```typescript * try { * await riskyOperation(); * } catch (err) { * return wrapAsAXError( * err as Error, * 'OPERATION_FAILED', * ['Check logs for details', 'Retry the operation'] * ); * } * ``` */ export declare function wrapAsAXError(error: Error, code: string, nextActions: string[], additionalContext?: Record): AXError; /** * AXError class for throwing structured errors * * Extends Error so it can be thrown and caught normally, * but carries the structured AXError data. * * @example * ```typescript * throw new AXErrorException( * 'POLICY_NOT_FOUND', * 'No policy file found', * ['Run "lex init" to create a workspace'], * { searchedPaths: ['.smartergpt/', 'canon/'] } * ); * ``` */ export declare class AXErrorException extends Error { readonly axError: AXError; constructor(code: string, message: string, nextActions: string[], context?: Record); /** * Get the structured error for JSON output */ toAXError(): AXError; /** * Serialize to JSON (for CLI --json output) */ toJSON(): AXError; } /** * Check if an error is an AXErrorException */ export declare function isAXErrorException(error: unknown): error is AXErrorException;