(directory, job)
| 627 | child.stdout?.on("data", (data) => stdout.push(Buffer.from(data))); |
| 628 | child.stderr?.on("data", (data) => stderr.push(Buffer.from(data))); |
| 629 | child.on("error", (error) => { |
| 630 | clearTimeout(timer); |
| 631 | resolve({ code: -1, stdout: "", stderr: String(error) }); |
| 632 | }); |
| 633 | child.on("close", (code) => { |
| 634 | clearTimeout(timer); |
| 635 | resolve({ code: code ?? 0, stdout: Buffer.concat(stdout).toString("utf8"), stderr: Buffer.concat(stderr).toString("utf8") }); |
| 636 | }); |
| 637 | }); |
| 638 | } |
| 639 | async function runShellCommand(command, cwd, timeoutMs = 120000) { |
| 640 | return await new Promise((resolve) => { |
| 641 | const child = spawn(command, [], { cwd, shell: true, windowsHide: true }); |
| 642 | const stdout = []; |
| 643 | const stderr = []; |
| 644 | const timer = setTimeout(() => { |
| 645 | try { |
| 646 | child.kill("SIGTERM"); |
| 647 | } catch {} |
| 648 | }, timeoutMs); |
| 649 | child.stdout?.on("data", (data) => stdout.push(Buffer.from(data))); |
| 650 | child.stderr?.on("data", (data) => stderr.push(Buffer.from(data))); |
| 651 | child.on("error", (error) => { |
| 652 | clearTimeout(timer); |
| 653 | resolve({ code: -1, stdout: "", stderr: String(error) }); |
| 654 | }); |
| 655 | child.on("close", (code) => { |
| 656 | clearTimeout(timer); |
| 657 | resolve({ code: code ?? 0, stdout: Buffer.concat(stdout).toString("utf8"), stderr: Buffer.concat(stderr).toString("utf8") }); |
| 658 | }); |
| 659 | }); |
| 660 | } |
| 661 | async function notifyJob(directory, job, reason) { |
| 662 | if (!job.notifyCommand) |
| 663 | return; |
| 664 | const command = String(job.notifyCommand).replace(/\{reason\}/g, String(reason || "")).replace(/\{job\}/g, String(job.name || job.id || "")); |
| 665 | await runShellCommand(command, directory, 60000); |
| 666 | } |
| 667 | |
| 668 | // src/source/opencode/sdk.js |
| 669 | function sdkError(result) { |
| 670 | if (!result || typeof result !== "object") |
| 671 | return; |
| 672 | return result.error || result.error === null ? result.error : undefined; |
no test coverage detected