const MAX_OUTPUT_LENGTH = 30000; const TIMEOUT = 2 * 60 * 1000; export async function executeBash(bashCommand: string): Promise { try { const command = new Deno.Command('bash', { args: ['-c', bashCommand], cwd: Deno.cwd(), signal: AbortSignal.timeout(TIMEOUT), stdout: 'piped', stderr: 'piped', }); const process = await command.output(); const stdout = new TextDecoder().decode(process.stdout); const stderr = new TextDecoder().decode(process.stderr); return [``, stdout.slice(0, MAX_OUTPUT_LENGTH), ``, ``, stderr.slice(0, MAX_OUTPUT_LENGTH), ``].join('\n'); } catch (error) { if (error instanceof DOMException && (error.name === 'AbortError' || error.name === 'TimeoutError')) { const stderr = `Command timed out or was aborted after ${TIMEOUT}ms.`; return [``, stderr, ``].join('\n'); } throw error; } }