Skip to content

Commit fc8db6c

Browse files
committed
fix: ensure timeout param passed to bash tool is positive
1 parent 5cc37c4 commit fc8db6c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/opencode/src/tool/bash.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const parser = lazy(async () => {
2727
return p
2828
} catch (e) {
2929
const { default: Parser } = await import("web-tree-sitter")
30-
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, { with: { type: "wasm" } })
30+
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, {
31+
with: { type: "wasm" },
32+
})
3133
await Parser.init({
3234
locateFile() {
3335
return treeWasm
@@ -55,6 +57,11 @@ export const BashTool = Tool.define("bash", {
5557
),
5658
}),
5759
async execute(params, ctx) {
60+
if (params.timeout !== undefined && params.timeout < 0) {
61+
throw new Error(
62+
`Invalid timeout value: ${params.timeout}. Timeout must be a positive number.`,
63+
)
64+
}
5865
const timeout = Math.min(params.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT)
5966
const tree = await parser().then((p) => p.parse(params.command))
6067
const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)
@@ -97,7 +104,10 @@ export const BashTool = Tool.define("bash", {
97104

98105
// always allow cd if it passes above check
99106
if (command[0] !== "cd") {
100-
const action = Wildcard.allStructured({ head: command[0], tail: command.slice(1) }, permissions)
107+
const action = Wildcard.allStructured(
108+
{ head: command[0], tail: command.slice(1) },
109+
permissions,
110+
)
101111
if (action === "deny") {
102112
throw new Error(
103113
`The user has specifically restricted access to this command, you are not allowed to execute it. Here is the configuration: ${JSON.stringify(permissions)}`,

0 commit comments

Comments
 (0)