Skip to content

Commit 2283979

Browse files
authored
Preapprove agent tmp directory access (#25226)
1 parent 33f7f59 commit 2283979

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/core/src/global.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const data = path.join(xdgData!, app)
1111
const cache = path.join(xdgCache!, app)
1212
const config = path.join(xdgConfig!, app)
1313
const state = path.join(xdgState!, app)
14+
const tmp = path.join(os.tmpdir(), app)
1415

1516
const paths = {
1617
get home() {
@@ -22,6 +23,7 @@ const paths = {
2223
cache,
2324
config,
2425
state,
26+
tmp,
2527
}
2628

2729
export const Path = paths
@@ -32,6 +34,7 @@ await Promise.all([
3234
fs.mkdir(Path.data, { recursive: true }),
3335
fs.mkdir(Path.config, { recursive: true }),
3436
fs.mkdir(Path.state, { recursive: true }),
37+
fs.mkdir(Path.tmp, { recursive: true }),
3538
fs.mkdir(Path.log, { recursive: true }),
3639
fs.mkdir(Path.bin, { recursive: true }),
3740
])
@@ -44,6 +47,7 @@ export interface Interface {
4447
readonly cache: string
4548
readonly config: string
4649
readonly state: string
50+
readonly tmp: string
4751
readonly bin: string
4852
readonly log: string
4953
}
@@ -55,6 +59,7 @@ export function make(input: Partial<Interface> = {}): Interface {
5559
cache: Path.cache,
5660
config: Flag.OPENCODE_CONFIG_DIR ?? Path.config,
5761
state: Path.state,
62+
tmp: Path.tmp,
5863
bin: Path.bin,
5964
log: Path.log,
6065
...input,

packages/opencode/src/agent/agent.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ export const layer = Layer.effect(
8181
Effect.fn("Agent.state")(function* (ctx) {
8282
const cfg = yield* config.get()
8383
const skillDirs = yield* skill.dirs()
84-
const whitelistedDirs = [Truncate.GLOB, ...skillDirs.map((dir) => path.join(dir, "*"))]
84+
const whitelistedDirs = [
85+
Truncate.GLOB,
86+
path.join(Global.Path.tmp, "*"),
87+
...skillDirs.map((dir) => path.join(dir, "*")),
88+
]
8589

8690
const defaults = Permission.fromConfig({
8791
"*": "allow",

packages/opencode/src/tool/bash.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { AppFileSystem } from "@opencode-ai/core/filesystem"
1414
import { fileURLToPath } from "url"
1515
import { Config } from "@/config/config"
1616
import { Flag } from "@opencode-ai/core/flag/flag"
17+
import { Global } from "@opencode-ai/core/global"
1718
import { Shell } from "@/shell/shell"
1819

1920
import { BashArity } from "@/permission/arity"
@@ -587,6 +588,7 @@ export const BashTool = Tool.define(
587588

588589
return {
589590
description: DESCRIPTION.replaceAll("${directory}", instance.directory)
591+
.replaceAll("${tmp}", Global.Path.tmp)
590592
.replaceAll("${os}", process.platform)
591593
.replaceAll("${shell}", name)
592594
.replaceAll("${chaining}", chain)

packages/opencode/src/tool/bash.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Be aware: OS: ${os}, Shell: ${shell}
44

55
All commands run in the current working directory by default. Use the `workdir` parameter if you need to run a command in a different directory. AVOID using `cd <directory> && <command>` patterns - use `workdir` instead.
66

7+
Use `${tmp}` for temporary work outside the workspace. This directory is pre-approved for external directory access.
8+
79
IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO NOT use it for file operations (reading, writing, editing, searching, finding files) - use the specialized tools for this instead.
810

911
Before executing the command, please follow these steps:

0 commit comments

Comments
 (0)