Skip to content

Commit c2609cb

Browse files
committed
core: allow agents to access global tmp directory without permission prompts
Agents can now create temporary files in the global tmp directory without triggering external_directory permission prompts. This enables agents to freely use temporary storage for intermediate files during builds and other operations.
1 parent 2115df5 commit c2609cb

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/core/test/global.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, test } from "bun:test"
2+
import fs from "fs/promises"
3+
import os from "os"
4+
import path from "path"
5+
import { Global } from "@opencode-ai/core/global"
6+
7+
describe("global paths", () => {
8+
test("tmp path is under the system temp directory", () => {
9+
expect(Global.Path.tmp).toBe(path.join(os.tmpdir(), "opencode"))
10+
expect(Global.make().tmp).toBe(Global.Path.tmp)
11+
})
12+
13+
test("tmp path is created on module load", async () => {
14+
expect((await fs.stat(Global.Path.tmp)).isDirectory()).toBe(true)
15+
})
16+
})

packages/opencode/test/agent/agent.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { provideInstance, tmpdir } from "../fixture/fixture"
55
import { Instance } from "../../src/project/instance"
66
import { Agent } from "../../src/agent/agent"
77
import { Permission } from "../../src/permission"
8+
import { Global } from "@opencode-ai/core/global"
89

910
// Helper to evaluate permission for a tool with wildcard pattern
1011
function evalPerm(agent: Agent.Info | undefined, permission: string): Permission.Action | undefined {
@@ -83,7 +84,7 @@ test("explore agent denies edit and write", async () => {
8384
})
8485
})
8586

86-
test("explore agent asks for external directories and allows Truncate.GLOB", async () => {
87+
test("explore agent asks for external directories and allows whitelisted external paths", async () => {
8788
const { Truncate } = await import("../../src/tool/truncate")
8889
await using tmp = await tmpdir()
8990
await Instance.provide({
@@ -93,6 +94,9 @@ test("explore agent asks for external directories and allows Truncate.GLOB", asy
9394
expect(explore).toBeDefined()
9495
expect(Permission.evaluate("external_directory", "/some/other/path", explore!.permission).action).toBe("ask")
9596
expect(Permission.evaluate("external_directory", Truncate.GLOB, explore!.permission).action).toBe("allow")
97+
expect(Permission.evaluate("external_directory", path.join(Global.Path.tmp, "agent-work"), explore!.permission).action).toBe(
98+
"allow",
99+
)
96100
},
97101
})
98102
})
@@ -515,6 +519,20 @@ test("Truncate.GLOB is allowed even when user denies external_directory globally
515519
})
516520
})
517521

522+
test("global tmp directory children are allowed for external_directory", async () => {
523+
await using tmp = await tmpdir()
524+
await Instance.provide({
525+
directory: tmp.path,
526+
fn: async () => {
527+
const build = await load(tmp.path, (svc) => svc.get("build"))
528+
expect(Permission.evaluate("external_directory", path.join(Global.Path.tmp, "scratch"), build!.permission).action).toBe(
529+
"allow",
530+
)
531+
expect(Permission.evaluate("external_directory", "/some/other/path", build!.permission).action).toBe("ask")
532+
},
533+
})
534+
})
535+
518536
test("Truncate.GLOB is allowed even when user denies external_directory per-agent", async () => {
519537
const { Truncate } = await import("../../src/tool/truncate")
520538
await using tmp = await tmpdir({

0 commit comments

Comments
 (0)