import * as child_process from 'node:child_process'; import { promisify } from 'node:util'; const exec = promisify(child_process.exec); export interface ShellExecutionResult { stdout: string; stderr: string; exitCode: number; } export interface ShellOutputEvent { type: 'stdout' | 'stderr'; data: string; } export interface ShellExecutionConfig { cwd?: string; env?: Record; timeout?: number; } export class ShellExecutionService { static async execute(command: string, options: ShellExecutionConfig = {}): Promise { try { const { stdout, stderr } = await exec(command, options); return { stdout: stdout.toString(), stderr: stderr.toString(), exitCode: 0 }; } catch (err: any) { return { stdout: err.stdout?.toString() || '', stderr: err.stderr?.toString() || err.message, exitCode: err.code || 1 }; } } }