/** * Result of a shell command execution. */ export interface ShellResult { /** Exit code of the process, or null if terminated by signal. */ code: number | null; /** Signal that terminated the process, or null if exited normally. */ signal: string | null; /** Captured standard output. */ stdout: string; /** Captured standard error. */ stderr: string; } /** * Result of an interactive shell command execution. */ export interface ShellInteractiveResult { /** Exit code of the process, or null if terminated by signal. */ code: number | null; /** Signal that terminated the process, or null if exited normally. */ signal: string | null; } /** * A utility class for executing shell commands in a specified working directory. * Provides methods for running commands with captured output, interactive commands, * and convenience methods for common patterns. * * @example * ```ts * const shell = new Shell('/path/to/project'); * const output = await shell.stdout('git status'); * const success = await shell.ok('npm test'); * ``` */ export declare class Shell { /** The working directory for all commands. */ private cwd; /** * Creates a new Shell instance. * * @param cwd - The working directory for executing commands. */ constructor(cwd: string); /** * Runs a shell command through bash and captures its output. * * @remarks * **⚠️ SECURITY WARNING: Command Injection Risk** * * This method passes the command string directly to `bash -c`, which means * shell metacharacters (`;`, `|`, `$()`, `` ` ``, etc.) are interpreted. * * **NEVER** pass unsanitized user input to this method: * ```ts * // DANGEROUS - command injection vulnerability! * shell.run(`git checkout ${userInput}`); // userInput could be "; rm -rf /" * * // SAFE - use exec() with array arguments instead * shell.exec('git', ['checkout', userInput]); * ``` * * Only use this method with: * - Hardcoded command strings * - Values that have been strictly validated (e.g., version numbers matching `/^\d+\.\d+\.\d+$/`) * * For commands with dynamic arguments, prefer {@link Shell.exec} which passes * arguments directly without shell interpretation. * * @param command - The shell command to execute. Must be a trusted string. * @param errorOnCodeNonZero - If true (default), rejects the promise on non-zero exit code. * @returns A promise resolving to the command result with exit code, signal, stdout, and stderr. * @throws Rejects with the result object if errorOnCodeNonZero is true and exit code is non-zero. */ run(command: string, errorOnCodeNonZero?: boolean): Promise; /** * Executes a command with arguments directly, avoiding shell escaping issues. * Preferred over `run()` when dealing with arguments that may contain special characters. * * @param command - The command executable to run. * @param args - Array of arguments to pass to the command. * @param errorOnCodeNonZero - If true (default), rejects the promise on non-zero exit code. * @param skipLog - If true, suppresses debug logging of the command. * @returns A promise resolving to the command result with exit code, signal, stdout, and stderr. * @throws Rejects with the result object if errorOnCodeNonZero is true and exit code is non-zero. */ exec(command: string, args: string[], errorOnCodeNonZero?: boolean, skipLog?: boolean): Promise; /** * Runs a command interactively with full TTY passthrough. * The user can interact with the command's stdin/stdout/stderr directly. * Useful for commands that require user input (e.g., npm publish with OTP). * * @remarks * **⚠️ SECURITY WARNING:** Same command injection risks as {@link Shell.run}. * Never pass unsanitized user input. See {@link Shell.run} for details. * * @param command - The shell command to execute. Must be a trusted string. * @param errorOnCodeNonZero - If true (default), rejects the promise on non-zero exit code. * @returns A promise resolving to the exit code and signal (no captured output). * @throws Rejects with the result object if errorOnCodeNonZero is true and exit code is non-zero. */ runInteractive(command: string, errorOnCodeNonZero?: boolean): Promise; /** * Runs a command and returns only the trimmed stderr output. * * @remarks * **⚠️ SECURITY WARNING:** Uses {@link Shell.run} internally. * Never pass unsanitized user input. See {@link Shell.run} for details. * * @param command - The shell command to execute. Must be a trusted string. * @param errorOnCodeZero - If true (default), rejects on non-zero exit code. * @returns A promise resolving to the trimmed stderr string. */ stderr(command: string, errorOnCodeZero?: boolean): Promise; /** * Runs a command and returns only the trimmed stdout output. * * @remarks * **⚠️ SECURITY WARNING:** Uses {@link Shell.run} internally. * Never pass unsanitized user input. See {@link Shell.run} for details. * * @param command - The shell command to execute. Must be a trusted string. * @param errorOnCodeZero - If true (default), rejects on non-zero exit code. * @returns A promise resolving to the trimmed stdout string. */ stdout(command: string, errorOnCodeZero?: boolean): Promise; /** * Runs a command and returns whether it succeeded (exit code 0). * Never throws on non-zero exit codes. * * @remarks * **⚠️ SECURITY WARNING:** Uses {@link Shell.run} internally. * Never pass unsanitized user input. See {@link Shell.run} for details. * * @param command - The shell command to execute. Must be a trusted string. * @returns A promise resolving to true if exit code is 0, false otherwise. */ ok(command: string): Promise; }