mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-20 01:04:22 +01:00
fix: ensure timeout param passed to bash tool is positive
This commit is contained in:
@@ -27,7 +27,9 @@ const parser = lazy(async () => {
|
|||||||
return p
|
return p
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const { default: Parser } = await import("web-tree-sitter")
|
const { default: Parser } = await import("web-tree-sitter")
|
||||||
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, { with: { type: "wasm" } })
|
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, {
|
||||||
|
with: { type: "wasm" },
|
||||||
|
})
|
||||||
await Parser.init({
|
await Parser.init({
|
||||||
locateFile() {
|
locateFile() {
|
||||||
return treeWasm
|
return treeWasm
|
||||||
@@ -55,6 +57,11 @@ export const BashTool = Tool.define("bash", {
|
|||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
async execute(params, ctx) {
|
async execute(params, ctx) {
|
||||||
|
if (params.timeout !== undefined && params.timeout < 0) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid timeout value: ${params.timeout}. Timeout must be a positive number.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
const timeout = Math.min(params.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT)
|
const timeout = Math.min(params.timeout ?? DEFAULT_TIMEOUT, MAX_TIMEOUT)
|
||||||
const tree = await parser().then((p) => p.parse(params.command))
|
const tree = await parser().then((p) => p.parse(params.command))
|
||||||
const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)
|
const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)
|
||||||
@@ -97,7 +104,10 @@ export const BashTool = Tool.define("bash", {
|
|||||||
|
|
||||||
// always allow cd if it passes above check
|
// always allow cd if it passes above check
|
||||||
if (command[0] !== "cd") {
|
if (command[0] !== "cd") {
|
||||||
const action = Wildcard.allStructured({ head: command[0], tail: command.slice(1) }, permissions)
|
const action = Wildcard.allStructured(
|
||||||
|
{ head: command[0], tail: command.slice(1) },
|
||||||
|
permissions,
|
||||||
|
)
|
||||||
if (action === "deny") {
|
if (action === "deny") {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The user has specifically restricted access to this command, you are not allowed to execute it. Here is the configuration: ${JSON.stringify(permissions)}`,
|
`The user has specifically restricted access to this command, you are not allowed to execute it. Here is the configuration: ${JSON.stringify(permissions)}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user