The open source coding agent.
TypeScript
fix: make bash tool use external_directory perm
Aiden Cline1ff5d888c287
diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.tsindex 3f502fe1add..d74a8d83d60 100644--- a/packages/opencode/src/tool/bash.ts+++ b/packages/opencode/src/tool/bash.ts@@ -12,6 +12,7 @@ import { Filesystem } from "@/util/filesystem"import { Wildcard } from "@/util/wildcard"import { Permission } from "@/permission"import { fileURLToPath } from "url"+import path from "path"const MAX_OUTPUT_LENGTH = 30_000const DEFAULT_TIMEOUT = 1 * 60 * 1000@@ -68,7 +69,8 @@ export const BashTool = Tool.define("bash", {if (!tree) {throw new Error("Failed to parse command")}- const permissions = await Agent.get(ctx.agent).then((x) => x.permission.bash)+ const agent = await Agent.get(ctx.agent)+ const permissions = agent.permission.bashconst askPatterns = new Set<string>()for (const node of tree.rootNode.descendantsOfType("command")) {@@ -107,9 +109,30 @@ export const BashTool = Tool.define("bash", {: resolvedif (!Filesystem.contains(Instance.directory, normalized)) {- throw new Error(- `This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,- )+ const parentDir = path.dirname(normalized)+ if (agent.permission.external_directory === "ask") {+ await Permission.ask({+ type: "external_directory",+ pattern: parentDir,+ sessionID: ctx.sessionID,+ messageID: ctx.messageID,+ callID: ctx.callID,+ title: `This command references paths outside of ${Instance.directory}`,+ metadata: {+ command: params.command,+ },+ })+ } else if (agent.permission.external_directory === "deny") {+ throw new Permission.RejectedError(+ ctx.sessionID,+ "external_directory",+ ctx.callID,+ {+ command: params.command,+ },+ `This command references paths outside of ${Instance.directory} so it is not allowed to be executed.`,+ )+ }}}}