import { Value } from '../utils'; import { Environment, Frame } from '../index'; import { Statement, Arg, DefineFunction, OnBlock, DecoratorCall, Expression } from '../types/Ast.type'; import { RobinPathThread } from './RobinPathThread'; export declare class Executor { private environment; private callStack; private parentThread; private sourceCode; private recursionDepth; private currentStatement; private static readonly MAX_RECURSION_DEPTH; /** The nodeKey of the currently executing top-level block (for log attribution) */ private _currentBlockKey; /** Get the current top-level block key (used by log/say for per-block attribution) */ getCurrentBlockKey(): string | null; private _executionId; /** Get the unique execution ID for the current run */ getExecutionId(): string | null; private _paused; private _cancelled; private _stepping; private _pauseResolve; /** Pause execution between blocks. Resolves when resume() is called. */ pause(): Promise; /** Resume paused execution. */ resume(): void; /** Cancel execution. The current block finishes, then execution stops. */ cancel(): void; /** Execute one block then auto-pause (step-through debugging). */ step(): void; /** Check if execution is paused */ get isPaused(): boolean; /** Check if execution was cancelled */ get isCancelled(): boolean; /** Wait if paused. Call this between blocks. */ private checkPausePoint; /** Extract a numeric decorator value from a statement (e.g. @retry 3, @timeout 5000) */ private getDecoratorValue; /** Check if a block has a @when decorator and evaluate if it should run */ private checkWhenCondition; /** Emit a flow event if the state tracker has a block callback */ private emitFlow; /** * Debug mode flag - set to true to enable logging * Can be controlled via VITE_DEBUG environment variable or set programmatically */ static debug: boolean; constructor(environment: Environment, parentThread?: RobinPathThread | null, sourceCode?: string | null); getCurrentFrame(frameOverride?: Frame): Frame; getCurrentStatement(): Statement | null; getEnvironment(): Environment; getCallStack(): Frame[]; /** * Compute Levenshtein distance between two strings */ private levenshteinDistance; /** * Find similar function names for "did you mean?" suggestions */ private findSimilarFunctions; /** * Format "Unknown function" error with suggestions */ private unknownFunctionError; /** * Creates a new Executor instance that shares the same environment and call stack, * but has its own call stack array to allow parallel execution without stack corruption. * The frames themselves (locals Maps) are shared. */ spawnChild(): Executor; /** * Execute an event handler with the provided arguments * Arguments are available as $1, $2, $3, etc. in the handler body */ executeEventHandler(handler: OnBlock, args: Value[]): Promise; /** * Execute a single statement (public method for state tracking) */ executeStatementPublic(stmt: Statement): Promise; /** * Execute a function call and return the result (public method for expression evaluation) */ executeFunctionCall(funcName: string, args: Arg[]): Promise; execute(statements: Statement[]): Promise; private executeStatement; /** * Get all variables visible in the current frame */ private getVariableStateInternal; /** * Reconstructs the original input string from an Arg object. * This is useful for commands that need to preserve the original input * (e.g., variable/function names) rather than evaluating them. * * Examples: * - { type: 'var', name: 'a' } -> '$a' * - { type: 'var', name: 'a', path: [{ type: 'property', name: 'b' }] } -> '$a.b' * - { type: 'var', name: 'a', path: [{ type: 'index', index: 0 }] } -> '$a[0]' * - { type: 'string', value: 'hello' } -> 'hello' * * @param arg The Arg object to reconstruct * @returns The original input string, or null if the arg type cannot be reconstructed */ private reconstructOriginalInput; private executeCommand; /** * Execute decorators for a target (function or variable) * @param decorators Array of decorator calls * @param targetName Name of the target (function or variable) * @param func Function object (null for variables) * @param originalArgs Original arguments (for functions, empty array for variables) * @returns Modified arguments (for functions) or original args unchanged */ executeDecorators(decorators: DecoratorCall[], targetName: string, func: DefineFunction | null, originalArgs: Value[], frameOverride?: Frame): Promise; private callFunction; private executeAssignment; private executeShorthandAssignment; private executeInlineIf; private executeIfBlock; private executeIfTrue; private executeIfFalse; private executeReturn; private executeBreak; private executeContinue; private registerFunction; private registerEventHandler; private executeScope; private executeThink; /** Strip common AI preamble/postamble from responses */ private cleanThinkResponse; /** Parse think output based on outputType */ private parseThinkOutput; /** Validate think output against guard constraint */ private validateThinkGuard; /** Validate think JSON output against a simple schema string like {name: string, price: number} */ private validateThinkSchema; /** Build OpenAI-style tool definitions from registered module metadata */ private buildToolDefinitions; /** Get a catalog of @known functions for plan mode prompts */ private getKnownFunctionCatalog; /** Build tool definitions from @known user-defined functions */ private buildKnownFunctionToolDefinitions; private executeRemember; private executeUnremember; private executeTogether; /** * Set a variable at a path in the parent scope (for together blocks) */ private setVariableAtPathInParentScope; private executeForLoop; private executeWhileLoop; private evaluateArg; /** * Interpolate variables and subexpressions in object literal code * Replaces $var, $(expr), $ (last value), and [$key] with their actual values * * TODO: AST Refactor - This method will be removed once ObjectLiteralExpression * is used. Object literals will be evaluated by walking the properties AST nodes. */ private interpolateObjectLiteral; /** * Execute a subexpression from code string with frame override support * * @param code - The subexpression code to execute * @param frameOverride - Optional frame override for variable resolution */ private executeSubexpressionWithFrame; /** * Execute a subexpression from code string * * TODO: AST Refactor - This will be replaced with executeSubexpressionStatements() * which takes Statement[] directly, eliminating runtime parsing. */ executeSubexpression(code: string): Promise; /** * Execute subexpression statements directly (for Expression-based AST) * * @param statements - Pre-parsed statements from SubexpressionExpression.body * @param frameOverride - Optional frame override for parallel execution * @returns The lastValue after executing the statements */ executeSubexpressionStatements(statements: Statement[], frameOverride?: Frame): Promise; /** * Evaluate an Expression node * * @param expr - The Expression node to evaluate * @param frameOverride - Optional frame override * @returns The evaluated value */ evaluateExpression(expr: Expression, frameOverride?: Frame): Promise; /** * Evaluate an ObjectLiteralExpression * * @param expr - The ObjectLiteralExpression node * @param frameOverride - Optional frame override * @returns The evaluated object */ evaluateObjectLiteral(expr: import('../types/Ast.type').ObjectLiteralExpression, frameOverride?: Frame): Promise>; /** * Evaluate an ArrayLiteralExpression * * @param expr - The ArrayLiteralExpression node * @param frameOverride - Optional frame override * @returns The evaluated array */ evaluateArrayLiteral(expr: import('../types/Ast.type').ArrayLiteralExpression, frameOverride?: Frame): Promise; /** * Evaluate a BinaryExpression * * @param expr - The BinaryExpression node * @param frameOverride - Optional frame override * @returns The evaluated value */ evaluateBinaryExpression(expr: import('../types/Ast.type').BinaryExpression, frameOverride?: Frame): Promise; /** * Evaluate a UnaryExpression * * @param expr - The UnaryExpression node * @param frameOverride - Optional frame override * @returns The evaluated value */ evaluateUnaryExpression(expr: import('../types/Ast.type').UnaryExpression, frameOverride?: Frame): Promise; /** * Evaluate a CallExpression * * @param expr - The CallExpression node * @param frameOverride - Optional frame override * @returns The evaluated value */ evaluateCallExpression(expr: import('../types/Ast.type').CallExpression, frameOverride?: Frame): Promise; private resolveVariable; private setVariable; /** * Set a value at an attribute path (e.g., $animal.cat = 5 or $.property = value) */ private setVariableAtPath; /** * Resolve a dynamic key segment to its actual key value */ private resolveDynamicKey; }