Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opencode/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,18 @@ export namespace Agent {
}

// Ensure Truncate.DIR is allowed unless explicitly configured
// The pattern must include /* because external-directory.ts creates glob patterns like "dir/*"
const truncateDirGlob = `${Truncate.DIR}/*`
for (const name in result) {
const agent = result[name]
const explicit = agent.permission.some(
(r) => r.permission === "external_directory" && r.pattern === Truncate.DIR && r.action === "deny",
(r) => r.permission === "external_directory" && r.pattern === truncateDirGlob && r.action === "deny",
)
if (explicit) continue

result[name].permission = PermissionNext.merge(
result[name].permission,
PermissionNext.fromConfig({ external_directory: { [Truncate.DIR]: "allow" } }),
PermissionNext.fromConfig({ external_directory: { [truncateDirGlob]: "allow" } }),
)
}

Expand Down
11 changes: 7 additions & 4 deletions packages/opencode/test/agent/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ test("Truncate.DIR is allowed even when user denies external_directory globally"
directory: tmp.path,
fn: async () => {
const build = await Agent.get("build")
expect(PermissionNext.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("allow")
// The pattern must include /* because external-directory.ts creates glob patterns like "dir/*"
expect(PermissionNext.evaluate("external_directory", `${Truncate.DIR}/*`, build!.permission).action).toBe("allow")
expect(PermissionNext.evaluate("external_directory", "/some/other/path", build!.permission).action).toBe("deny")
},
})
Expand All @@ -483,7 +484,8 @@ test("Truncate.DIR is allowed even when user denies external_directory per-agent
directory: tmp.path,
fn: async () => {
const build = await Agent.get("build")
expect(PermissionNext.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("allow")
// The pattern must include /* because external-directory.ts creates glob patterns like "dir/*"
expect(PermissionNext.evaluate("external_directory", `${Truncate.DIR}/*`, build!.permission).action).toBe("allow")
expect(PermissionNext.evaluate("external_directory", "/some/other/path", build!.permission).action).toBe("deny")
},
})
Expand All @@ -496,7 +498,7 @@ test("explicit Truncate.DIR deny is respected", async () => {
permission: {
external_directory: {
"*": "deny",
[Truncate.DIR]: "deny",
[`${Truncate.DIR}/*`]: "deny",
},
},
},
Expand All @@ -505,7 +507,8 @@ test("explicit Truncate.DIR deny is respected", async () => {
directory: tmp.path,
fn: async () => {
const build = await Agent.get("build")
expect(PermissionNext.evaluate("external_directory", Truncate.DIR, build!.permission).action).toBe("deny")
// The pattern must include /* because external-directory.ts creates glob patterns like "dir/*"
expect(PermissionNext.evaluate("external_directory", `${Truncate.DIR}/*`, build!.permission).action).toBe("deny")
},
})
})