/** * Process management utilities for validation runner * * Provides reliable process group cleanup for spawned child processes. * Used by validation runner for signal handling and fail-fast behavior. */ import { type ChildProcess } from 'node:child_process'; import type { CapturedOutput } from './output-capture-schema.js'; /** * Get git repository root directory * * @returns Absolute path to git root, or null if not in a git repository */ export declare function getGitRoot(): string | null; /** * Resolve working directory relative to git root * * @param cwd - Working directory path (relative to git root) * @returns Absolute path to working directory * @throws Error if cwd escapes git root (security) or not in git repo */ export declare function resolveGitRelativePath(cwd: string): string; /** * Stop a child process and its entire process group (cross-platform) * * **Windows Implementation:** * - Uses `taskkill /pid /T /F` to terminate process tree * - /T flag kills child processes * - /F flag forces termination * * **Unix Implementation:** * - Uses negative PID to kill process group (-PID) * - Graceful shutdown: SIGTERM to process group * - Force kill after 1s: SIGKILL to process group * * @param childProcess - The child process to stop * @param processName - Optional name for logging (e.g., "TypeScript", "ESLint") * @returns Promise that resolves when process is stopped * * @example * ```typescript * const proc = spawn('tsc --noEmit', [], { shell: true }); * await stopProcessGroup(proc, 'TypeScript'); * ``` */ export declare function stopProcessGroup(childProcess: ChildProcess, processName?: string): Promise; /** * Re-exported from `@vibe-validate/git`, where the hazard knowledge now lives. * * The blacklist is git-specific (which `GIT_*` vars redirect a child away from * the repository it was handed), so it belongs with the rest of this project's * git expertise rather than in the process-plumbing layer that happens to be its * busiest caller. `core` already depends on `git`, so the move is downward. * * @public */ export { stripGitEnv } from '@vibe-validate/git'; /** * Spawn a command with consistent, secure defaults for validation * * **Key Features:** * - **No stdin**: Commands cannot block waiting for user input * - **Shell mode**: Supports operators (&&, ||, |) and cross-platform compatibility * - **Process groups**: Proper cleanup on Unix (detached mode) * - **Captured output**: stdout/stderr piped for extraction * * **Security:** * - Commands from user config files only (same trust as npm scripts) * - See SECURITY.md for full threat model * * @param command - Command string to execute (e.g., "npm test", "tsc --noEmit") * @param options - Optional spawn configuration * @returns ChildProcess instance for monitoring/cleanup * * @example * ```typescript * // Simple command * const proc = spawnCommand('npm test'); * * // With custom environment * const proc = spawnCommand('npm run build', { * env: { NODE_ENV: 'production' } * }); * * // Command with timeout * const proc = spawnCommand('npm', { * args: ['install'], * timeout: 30000 * }); * ``` */ export declare function spawnCommand(command: string, options?: { /** Command arguments (when command is executable name, not shell string) */ args?: string[]; /** Timeout in milliseconds */ timeout?: number; /** Run detached (defaults to true on Unix, false on Windows) */ detached?: boolean; /** Environment variables (merged with process.env) */ env?: Record; /** Working directory (defaults to current directory) */ cwd?: string; /** Stdio mode. 'pipe' (default) captures stdout/stderr; 'inherit' attaches to parent's streams. */ stdio?: 'pipe' | 'inherit'; }): ChildProcess; /** * Options for capturing command output */ export interface CaptureCommandOptions { /** Command to execute */ command: string; /** Output directory for log files */ outputDir: string; /** Command arguments (optional) */ args?: string[]; /** Timeout in milliseconds (optional) */ timeout?: number; /** Environment variables (optional) */ env?: Record; } /** * Capture command output with organized file structure * * Executes a command and captures stdout/stderr with proper separation: * - stdout.log: Raw stdout with ANSI codes (omitted if empty) * - stderr.log: Raw stderr with ANSI codes (omitted if empty) * - combined.jsonl: Chronological output with ANSI codes stripped * * @param options - Capture options * @returns Captured output with file paths * * @example * ```typescript * const output = await captureCommandOutput({ * command: 'npm test', * outputDir: '/tmp/vibe-validate/runs/2025-11-05/abc123-17-30-45' * }); * * console.log(output.exitCode); // 0 or 1 * console.log(output.stdout.file); // Path to stdout.log (if non-empty) * console.log(output.combined.file); // Path to combined.jsonl * ``` */ export declare function captureCommandOutput(options: CaptureCommandOptions): Promise; //# sourceMappingURL=process-utils.d.ts.map