/** * Bash command execution with streaming support and cancellation. * * This module provides a unified bash execution implementation used by: * - AgentSession.executeBash() for interactive and RPC modes * - Direct calls from modes that need bash execution */ import { type BashOperations } from "./tools/bash.js"; export interface BashExecutorOptions { /** Callback for streaming output chunks (already sanitized) */ onChunk?: (chunk: string) => void; /** AbortSignal for cancellation */ signal?: AbortSignal; /** Timeout in seconds (optional). When exceeded, the process tree is killed. */ timeout?: number; } /** * Evidence metadata for every shell command execution. * * All commands receive this evidence block, not just pipelines. The exit code * returned by Bash represents the final status of the supplied source, but for * compound commands (sequences, functions, subshells, recovery operators) it * does not prove that every internal command succeeded. * * Stage exit codes are never captured from shared file descriptors because * those channels are observable and writable by the executed command itself. */ export interface BashEvidence { /** Whether the exit status is known. False for timeout, cancellation, and spawn errors. */ exitStatusKnown: boolean; /** Whether the reported exit status faithfully reflects what Bash returned for the supplied source. */ exitStatusAuthoritative: boolean; /** * Authority scope for the exit code. * - "final_shell_exit_status": command completed — exit code represents the final Bash status. * - "final_pipeline_stage_only": pipeline suspected — exit code may represent only the last stage. * - "no_exit_status": no exit code produced (timeout/cancellation). * - "no_process_started": shell never spawned (spawn error). */ authorityScope: "final_shell_exit_status" | "final_pipeline_stage_only" | "no_exit_status" | "no_process_started"; /** Always false: the internal status of each command within compound source is not tracked. */ internalCommandStatusesKnown: false; /** * Whether the evidence can be used for validation decisions. * False for pipelines (stage exit codes unknown) and error states. */ validationEvidenceAuthoritative: boolean; /** Whether the command is suspected to contain a pipeline (contains | outside of quoting) */ pipelineSuspected: boolean; /** Always false: stage exit codes are never known from untrusted channels */ stageExitCodesKnown: false; /** The final shell exit code */ finalShellExitCode: number | undefined; /** Warning message for the model when evidence is non-authoritative */ warning?: string; } /** * Public result of a bash command execution. * * All fields added after 1.1.6 are optional in the public type for backward * compatibility with consumers that construct mocks, adapters, or fixtures * using the 1.1.6 shape. The runtime always produces every field. */ export interface BashResult { /** Combined stdout + stderr output (sanitized, possibly truncated) */ output: string; /** Process exit code (undefined if killed/cancelled/timedOut/spawnError) */ exitCode: number | undefined; /** Whether the command was cancelled via signal */ cancelled: boolean; /** Whether the output was truncated */ truncated: boolean; /** Path to temp file containing full output (if output exceeded truncation threshold) */ fullOutputPath?: string; /** Separate stdout stream (empty string if no stdout was produced) */ stdout?: string; /** Separate stderr stream (empty string if no stderr was produced) */ stderr?: string; /** Whether the command timed out */ timedOut?: boolean; /** ISO timestamp when command execution started */ startedAt?: string; /** ISO timestamp when command execution finished */ finishedAt?: string; /** Spawn error message if the process failed to start (e.g., executable not found) */ spawnError?: string; /** Evidence metadata for every execution (exit status, authority scope, pipeline flag) */ evidence?: BashEvidence; } /** * Internal resolved type: every runtime-produced BashResult satisfies this * contract. The formatter and other internal consumers use this type so they * can rely on the fields being present without optional chaining, while the * public BashResult remains backward-compatible with the 1.1.6 surface. */ export interface ResolvedBashResult extends BashResult { stdout: string; stderr: string; timedOut: boolean; startedAt: string; finishedAt: string; evidence: BashEvidence; } /** * Execute a bash command with optional streaming and cancellation support. * * Uses the same local BashOperations backend as createBashTool() so interactive * user bash and tool-invoked bash share the same process spawning behavior. * Sanitization, newline normalization, temp-file capture, and truncation still * happen in executeBashWithOperations(), so reusing the local backend does not * change output processing behavior. * * @param command - The bash command to execute * @param options - Optional streaming callback and abort signal * @returns Promise resolving to execution result */ export declare function executeBash(command: string, options?: BashExecutorOptions): Promise; /** * Execute a bash command using custom BashOperations. * Used for remote execution (SSH, containers, etc.). */ export declare function executeBashWithOperations(command: string, cwd: string, operations: BashOperations, options?: BashExecutorOptions): Promise; //# sourceMappingURL=bash-executor.d.ts.map