/** * Interpreter - AST Execution Engine * * Main interpreter class that executes bash AST nodes. * Delegates to specialized modules for: * - Word expansion (expansion.ts) * - Arithmetic evaluation (arithmetic.ts) * - Conditional evaluation (conditionals.ts) * - Built-in commands (builtins.ts) * - Redirections (redirections.ts) */ import { AgenticHealer } from "../agentic/agentic-healer.js"; import type { PipelineNode, ScriptNode, StatementNode } from "../ast/types.js"; import type { IFileSystem } from "../fs/interface.js"; import type { ExecutionLimits } from "../limits.js"; import { SemanticEngine } from "../lsp/semantic-engine.js"; import type { SecureFetch } from "../network/index.js"; import type { SharedStateBus } from "../services/SharedStateBus.js"; import type { CommandRegistry, ExecResult, FeatureCoverageWriter, OutputSink, TraceCallback } from "../types.js"; import type { DebuggerBridge } from "./debugger/debugger.js"; import type { InterpreterState } from "./types.js"; export type { InterpreterContext, InterpreterState } from "./types.js"; export interface InterpreterOptions { fs: IFileSystem; commands: CommandRegistry; limits: Required; exec: (script: string, options?: { env?: Record; cwd?: string; replaceEnv?: boolean; signal?: AbortSignal; args?: string[]; }) => Promise; fetch?: SecureFetch; sleep?: (ms: number) => Promise; trace?: TraceCallback; coverage?: FeatureCoverageWriter; requireDefenseContext?: boolean; jsBootstrapCode?: string; onCommandNotFound?: (command: string, args: string[]) => Promise; /** Returns list of all registered command names */ getRegisteredCommands?: () => string[]; /** If true, enables agentic behavior for the shell */ agentic?: boolean; /** Optional debugger implementation */ debugger?: DebuggerBridge; /** Optional semantic engine implementation */ semanticEngine?: SemanticEngine; /** Optional agentic healer implementation */ agenticHealer?: AgenticHealer; /** Optional shared state bus implementation */ sharedBus?: SharedStateBus; /** Reference to the parent Bash instance */ bash?: any; /** * Optional opt-in sink for incremental (true) streaming of stdout/stderr. * When undefined, execution is byte-identical to the buffered path. */ sink?: OutputSink; } /** * Shell Interpreter * * Implements the core bash execution logic by traversing the AST. */ export declare class Interpreter { private ctx; private estimatedMemoryBytes; private statementsSinceMemoryCheck; private cachedExportedEnv; constructor(options: InterpreterOptions, state: InterpreterState); /** * Fail closed if defense is expected but async context is missing. */ private assertDefenseContext; /** * Build environment record containing only exported variables. * In bash, only exported variables are passed to child processes. * This includes both permanently exported variables (via export/declare -x) * and temporarily exported variables (prefix assignments like FOO=bar cmd). * * 2.6 — Incremental Exported Env: returns a cached record when the exported * variable set has not changed since the last call, avoiding a full rebuild * on every external command execution. */ private buildExportedEnv; executeScript(node: ScriptNode): Promise; /** * Execute a user script file found in PATH. */ private executeUserScript; executeStatement(node: StatementNode): Promise; executePipeline(node: PipelineNode): Promise; private executeCommand; /** * Estimate memory usage of the current interpreter state. */ private estimateMemoryUsage; /** * Revert prefix/temporary variable assignments (`FOO=bar cmd`) back to * their pre-command values. POSIX (and bash in `set -o posix` mode) keeps * them persistent when the command is a POSIX *special* builtin (`:`, * `.`, `break`, `continue`, `eval`, `exec`, `exit`, `export`, `readonly`, * `return`, `set`, `shift`, `trap`, `unset`) - otherwise (the common * case, and always outside posix mode) they must not leak into the * shell's environment once the command finishes. * * `hadTempEnvFrame` mirrors whether the caller pushed `tempAssignments` * onto `ctx.state.tempEnvBindings` before running the command; when true, * that same frame is popped here. `unset`/`local` may have already * mutated (even fully drained) the map in place while the command ran - * that's expected, since they share the exact same Map reference so their * tempenv-reveal and this revert never disagree about the underlying value. */ private revertTempAssignments; private executeSimpleCommand; private executeSimpleCommandInner; private runCommand; private aliasExpansionStack; private expandAlias; findCommandInPath(commandName: string): Promise; private executeSubshell; private executeGroup; private executeArithmeticCommand; private executeConditionalCommand; }