|
|
@@ -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<void>((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,
|