fix bash tool getting stuck on interactive commands
This commit is contained in:
@@ -737,7 +737,7 @@ export namespace Session {
|
|||||||
)
|
)
|
||||||
const result = await item.execute(args, {
|
const result = await item.execute(args, {
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
abort: abort.signal,
|
abort: options.abortSignal!,
|
||||||
messageID: assistantMsg.id,
|
messageID: assistantMsg.id,
|
||||||
callID: options.toolCallId,
|
callID: options.toolCallId,
|
||||||
metadata: async (val) => {
|
metadata: async (val) => {
|
||||||
@@ -779,7 +779,7 @@ export namespace Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, item] of Object.entries(await MCP.tools())) {
|
for (const [key, item] of Object.entries(await MCP.tools())) {
|
||||||
if (mode.tools[key] === false) continue
|
if (enabledTools[key] === false) continue
|
||||||
const execute = item.execute
|
const execute = item.execute
|
||||||
if (!execute) continue
|
if (!execute) continue
|
||||||
item.execute = async (args, opts) => {
|
item.execute = async (args, opts) => {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
import { spawn } from "child_process"
|
||||||
|
import { text } from "stream/consumers"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION from "./bash.txt"
|
import DESCRIPTION from "./bash.txt"
|
||||||
import { App } from "../app/app"
|
import { App } from "../app/app"
|
||||||
@@ -10,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
|
||||||
|
|
||||||
@@ -116,19 +118,19 @@ export const BashTool = Tool.define("bash", {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const process = Bun.spawn({
|
const process = spawn("bash", ["-c", params.command], {
|
||||||
cmd: ["bash", "-c", params.command],
|
stdio: "pipe",
|
||||||
cwd: app.path.cwd,
|
cwd: app.path.cwd,
|
||||||
maxBuffer: MAX_OUTPUT_LENGTH,
|
|
||||||
signal: ctx.abort,
|
signal: ctx.abort,
|
||||||
timeout: timeout,
|
timeout,
|
||||||
stdin: "pipe",
|
|
||||||
stdout: "pipe",
|
|
||||||
stderr: "pipe",
|
|
||||||
})
|
})
|
||||||
await process.exited
|
await new Promise<void>((resolve) => {
|
||||||
const stdout = await new Response(process.stdout).text()
|
process.on("close", () => {
|
||||||
const stderr = await new Response(process.stderr).text()
|
resolve()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const stdout = await text(process.stdout)
|
||||||
|
const stderr = await text(process.stderr)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: params.command,
|
title: params.command,
|
||||||
|
|||||||
Reference in New Issue
Block a user