Skip to content

The open source coding agent.

TypeScript

fix: ensure new permissions changes work for special case bash commands like rm, cd, etc

Aiden Cline76186d19f3d4
diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.ts
index 6671c939c40..46058b6658e 100644
--- a/packages/opencode/src/tool/bash.ts
+++ b/packages/opencode/src/tool/bash.ts
@@ -119,7 +119,7 @@ export const BashTool = Tool.define("bash", async () => {
process.platform === "win32" && resolved.match(/^\/[a-z]\//)
? resolved.replace(/^\/([a-z])\//, (_, drive) => `${drive.toUpperCase()}:\\`).replace(/\//g, "\\")
: resolved
- directories.add(normalized)
+ if (!Filesystem.contains(Instance.directory, normalized)) directories.add(normalized)
}
}
}
diff --git a/packages/opencode/test/tool/bash.test.ts b/packages/opencode/test/tool/bash.test.ts
index ee82813fb5a..2eb17a9fc94 100644
--- a/packages/opencode/test/tool/bash.test.ts
+++ b/packages/opencode/test/tool/bash.test.ts
@@ -147,6 +147,36 @@ describe("tool.bash permissions", () => {
})
})
+ test("does not ask for external_directory permission when rm inside project", async () => {
+ await using tmp = await tmpdir({ git: true })
+ await Instance.provide({
+ directory: tmp.path,
+ fn: async () => {
+ const bash = await BashTool.init()
+ const requests: Array<Omit<PermissionNext.Request, "id" | "sessionID" | "tool">> = []
+ const testCtx = {
+ ...ctx,
+ ask: async (req: Omit<PermissionNext.Request, "id" | "sessionID" | "tool">) => {
+ requests.push(req)
+ },
+ }
+
+ await Bun.write(path.join(tmp.path, "tmpfile"), "x")
+
+ await bash.execute(
+ {
+ command: "rm tmpfile",
+ description: "Remove tmpfile",
+ },
+ testCtx,
+ )
+
+ const extDirReq = requests.find((r) => r.permission === "external_directory")
+ expect(extDirReq).toBeUndefined()
+ },
+ })
+ })
+
test("includes always patterns for auto-approval", async () => {
await using tmp = await tmpdir({ git: true })
await Instance.provide({