diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.ts index fa737aaece8..3bd1915b397 100644 --- a/packages/opencode/src/tool/bash.ts +++ b/packages/opencode/src/tool/bash.ts @@ -234,13 +234,15 @@ export const BashTool = Tool.define("bash", async () => { }) const append = (chunk: Buffer) => { - output += chunk.toString() - ctx.metadata({ - metadata: { - output, - description: params.description, - }, - }) + if (output.length <= MAX_OUTPUT_LENGTH) { + output += chunk.toString() + ctx.metadata({ + metadata: { + output, + description: params.description, + }, + }) + } } proc.stdout?.on("data", append) @@ -295,7 +297,7 @@ export const BashTool = Tool.define("bash", async () => { const timeoutTimer = setTimeout(() => { timedOut = true void killTree() - }, timeout) + }, timeout + 100) await new Promise((resolve, reject) => { const cleanup = () => { @@ -320,15 +322,15 @@ export const BashTool = Tool.define("bash", async () => { if (output.length > MAX_OUTPUT_LENGTH) { output = output.slice(0, MAX_OUTPUT_LENGTH) - resultMetadata.push(`Output exceeded length limit of ${MAX_OUTPUT_LENGTH} chars`) + resultMetadata.push(`bash tool truncated output as it exceeded ${MAX_OUTPUT_LENGTH} char limit`) } if (timedOut) { - resultMetadata.push(`Command terminated after exceeding timeout ${timeout} ms`) + resultMetadata.push(`bash tool terminated commmand after exceeding timeout ${timeout} ms`) } if (aborted) { - resultMetadata.push("Command aborted by user") + resultMetadata.push("User aborted the command") } if (resultMetadata.length > 1) {