import { spawn } from "node:child_process"; export async function runCursorCommand(binary: string, args: string[], timeoutMs: number): Promise<{ code: number | null; stdout: string; stderr: string }> { return new Promise((resolve) => { const child = spawn(binary, args, { stdio: ["ignore", "pipe", "pipe"] }); let stdout = ""; let stderr = ""; const timer = setTimeout(() => { try { child.kill("SIGKILL"); } catch { // best effort } resolve({ code: 124, stdout, stderr }); }, timeoutMs); child.stdout?.on("data", (c: Buffer) => { stdout += c.toString("utf-8"); }); child.stderr?.on("data", (c: Buffer) => { stderr += c.toString("utf-8"); }); child.once("error", () => { clearTimeout(timer); resolve({ code: 127, stdout, stderr }); }); child.once("close", (code) => { clearTimeout(timer); resolve({ code, stdout, stderr }); }); }); }