From ea85fdf3cd8ba8c8f6a5d38e9f319d32abc87208 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Sun, 3 Aug 2025 15:34:37 -0400 Subject: [PATCH] fix bash tool not showing stderr --- packages/opencode/src/tool/bash.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.ts index 99cad0a1..b696657e 100644 --- a/packages/opencode/src/tool/bash.ts +++ b/packages/opencode/src/tool/bash.ts @@ -1,5 +1,5 @@ import { z } from "zod" -import { spawn } from "child_process" +import { exec } from "child_process" import { text } from "stream/consumers" import { Tool } from "./tool" import DESCRIPTION from "./bash.txt" @@ -12,7 +12,7 @@ import { Log } from "../util/log" import { Wildcard } from "../util/wildcard" import { $ } from "bun" -// const MAX_OUTPUT_LENGTH = 30000 +const MAX_OUTPUT_LENGTH = 30000 const DEFAULT_TIMEOUT = 1 * 60 * 1000 const MAX_TIMEOUT = 10 * 60 * 1000 @@ -118,19 +118,25 @@ export const BashTool = Tool.define("bash", { }) } - const process = spawn("bash", ["-c", params.command], { - stdio: "pipe", + const process = exec(params.command, { cwd: app.path.cwd, signal: ctx.abort, + maxBuffer: MAX_OUTPUT_LENGTH, timeout, }) + + const stdoutPromise = text(process.stdout!) + const stderrPromise = text(process.stderr!) + await new Promise((resolve) => { process.on("close", () => { resolve() }) }) - const stdout = await text(process.stdout) - const stderr = await text(process.stderr) + + const stdout = await stdoutPromise + const stderr = await stderrPromise + console.log({ stderr, stdout }) return { title: params.command,