summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/opencode/src/tool/bash.ts2
-rw-r--r--packages/opencode/test/tool/bash.test.ts30
2 files changed, 31 insertions, 1 deletions
diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.ts
index 6671c939c..46058b665 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 ee82813fb..2eb17a9fc 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({