fix bash tool not showing stderr
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { spawn } from "child_process"
|
import { exec } from "child_process"
|
||||||
import { text } from "stream/consumers"
|
import { text } from "stream/consumers"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION from "./bash.txt"
|
import DESCRIPTION from "./bash.txt"
|
||||||
@@ -12,7 +12,7 @@ import { Log } from "../util/log"
|
|||||||
import { Wildcard } from "../util/wildcard"
|
import { Wildcard } from "../util/wildcard"
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
|
|
||||||
// const MAX_OUTPUT_LENGTH = 30000
|
const MAX_OUTPUT_LENGTH = 30000
|
||||||
const DEFAULT_TIMEOUT = 1 * 60 * 1000
|
const DEFAULT_TIMEOUT = 1 * 60 * 1000
|
||||||
const MAX_TIMEOUT = 10 * 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], {
|
const process = exec(params.command, {
|
||||||
stdio: "pipe",
|
|
||||||
cwd: app.path.cwd,
|
cwd: app.path.cwd,
|
||||||
signal: ctx.abort,
|
signal: ctx.abort,
|
||||||
|
maxBuffer: MAX_OUTPUT_LENGTH,
|
||||||
timeout,
|
timeout,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const stdoutPromise = text(process.stdout!)
|
||||||
|
const stderrPromise = text(process.stderr!)
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
process.on("close", () => {
|
process.on("close", () => {
|
||||||
resolve()
|
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 {
|
return {
|
||||||
title: params.command,
|
title: params.command,
|
||||||
|
|||||||
Reference in New Issue
Block a user