opencode-apex 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to `opencode-apex`. Format based on
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.2.6] — 2026-11-25
9
+
10
+ ### Added
11
+
12
+ - **`tempAccess` module (on by default): OpenCode's temporary directory without asking.**
13
+ OpenCode tells the model to prefer `<tmpdir>/opencode` (`/tmp/opencode` on Linux) over
14
+ `/tmp`, "pre-created and approved for external access", but no rule approves it, so
15
+ every read or write there asked for `external_directory`. apex now allows those requests
16
+ through a `permission.evaluate` hook. It only turns `ask` into `allow`, only when every
17
+ requested path is inside that directory, and a deny you configure still wins, since
18
+ OpenCode evaluates configured denies first. It runs after the guard and before the
19
+ advisor. Turn it off with `"modules": { "tempAccess": false }`.
20
+
8
21
  ## [0.2.5] — 2026-11-24
9
22
 
10
23
  0.2.4 was never published to npm. Its changes are part of this release.
package/README.md CHANGED
@@ -48,7 +48,7 @@ A few OpenCode terms used throughout these docs:
48
48
  | **Skill** | A Markdown guide an agent can load when a task needs it. apex ships one. |
49
49
  | **RPC** | Here, an **authenticated HTTP POST to the OpenCode server** that runs a method a plugin registered: `POST <server>/api/rpc/apex/<method>`. It lets scripts and other programs talk to apex. |
50
50
 
51
- apex is one plugin with five independent modules. Each one can be switched on or off.
51
+ apex is one plugin with six independent modules. Each one can be switched on or off.
52
52
 
53
53
  ## Modules
54
54
 
@@ -59,6 +59,7 @@ apex is one plugin with five independent modules. Each one can be switched on or
59
59
  | **Advisor** | When a tool call needs permission ("ask"), a small dedicated agent decides `allow` or `deny`, so you aren't asked about every step. For `kill`/`pkill` it is told whose process each target is (read from `/proc`). | on | [docs/ADVISOR.md](docs/ADVISOR.md) |
60
60
  | **Guard** | Meta-permissions per agent, tool and path, with a report of what was attempted and decided. | **off** | [docs/GUARD.md](docs/GUARD.md) |
61
61
  | **Browser** | Serves OpenCode's `browser.*` tools against an **external** Chromium over CDP (local or remote). You can also switch to the desktop app's built-in browser. 45 actions. | on | [docs/BROWSER.md](docs/BROWSER.md) |
62
+ | **Temp access** | Allows `external_directory` in OpenCode's temporary directory (`<tmpdir>/opencode`, `/tmp/opencode` on Linux) without asking. OpenCode tells the model to use it but no rule approves it. A deny you configure for that path still wins. | on | — |
62
63
 
63
64
  Turn modules on or off in `modules`. That is the only switch: there is no `<module>.enabled`.
64
65
 
package/core/config.ts CHANGED
@@ -264,6 +264,8 @@ export const apexConfigSchema = z.object({
264
264
  guard: z.boolean().optional(),
265
265
  // Activado por defecto; en modo external puede abrir un popup de Chrome.
266
266
  browser: z.boolean().optional(),
267
+ // Activado por defecto: external_directory sin preguntar en <tmpdir>/opencode.
268
+ tempAccess: z.boolean().optional(),
267
269
  })
268
270
  .default(() => ({})),
269
271
  })
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Acceso al directorio temporal de OpenCode sin preguntar.
3
+ *
4
+ * OpenCode le dice al modelo que use `<tmpdir>/opencode` en vez de `/tmp` ("pre-created
5
+ * and approved for external access", core/instructions/builtins.ts), pero ninguna regla
6
+ * lo aprueba: cada lectura o escritura ahí acaba en una petición `external_directory`.
7
+ * Este módulo es esa regla.
8
+ *
9
+ * Va como hook de `permission.evaluate` y no como regla en los agentes:
10
+ * - vale para todos, también los que otros plugins crean después (claude-*);
11
+ * - el host evalúa ANTES los deny configurados, así que un deny del usuario sobre
12
+ * esa ruta sigue ganando, y aquí solo se pasa `ask` → `allow`.
13
+ * Se registra después del guard (un deny suyo se respeta) y antes del advisor (que
14
+ * deja de recibir lo que ya está resuelto).
15
+ */
16
+
17
+ import { Effect } from "effect"
18
+ import type { Scope } from "effect"
19
+ import type { Plugin } from "@opencode/plugin/effect"
20
+ import { tmpdir } from "node:os"
21
+ import { join } from "node:path"
22
+
23
+ /** El `Global.Path.tmp` de OpenCode: `path.join(os.tmpdir(), "opencode")`. */
24
+ export function opencodeTempDir(): string {
25
+ return join(tmpdir(), "opencode").replaceAll("\\", "/")
26
+ }
27
+
28
+ /**
29
+ * Recursos de `external_directory` que caen dentro de `dir`. OpenCode los pide como
30
+ * `<directorio>/*`, con barras `/` (file-access.ts); se acepta el propio `dir` por si
31
+ * acaso, nunca un prefijo como `/tmp/opencode-otra`.
32
+ */
33
+ export function insideDir(resource: string, dir: string): boolean {
34
+ const r = resource.replaceAll("\\", "/")
35
+ const base = dir.replace(/\/+$/, "")
36
+ return r === base || r === `${base}/*` || r.startsWith(`${base}/`)
37
+ }
38
+
39
+ interface PermissionEvaluationEvent {
40
+ readonly action: string
41
+ readonly resources: readonly string[]
42
+ effect: "allow" | "deny" | "ask"
43
+ }
44
+
45
+ /** `ask` → `allow` cuando todo lo pedido está en el directorio temporal. */
46
+ export function applyTempAccess(event: PermissionEvaluationEvent, dir = opencodeTempDir()): boolean {
47
+ if (event.effect !== "ask" || event.action !== "external_directory") return false
48
+ if (event.resources.length === 0 || !event.resources.every((resource) => insideDir(resource, dir))) return false
49
+ event.effect = "allow"
50
+ return true
51
+ }
52
+
53
+ export function registerTempAccess(ctx: Plugin.Context): Effect.Effect<void, never, Scope.Scope> {
54
+ return Effect.gen(function* () {
55
+ const dir = opencodeTempDir()
56
+ yield* Effect.logInfo(`[apex.tempAccess] external_directory permitido en ${dir}`)
57
+ // Envuelto como en guard.ts: un fallo aquí no debe cortar los hooks de detrás.
58
+ yield* ctx.permission.hook("evaluate", (event) =>
59
+ Effect.sync(() => {
60
+ try {
61
+ applyTempAccess(event as unknown as PermissionEvaluationEvent, dir)
62
+ } catch (error) {
63
+ console.error(`[apex.tempAccess] fallo evaluando un permiso, se deja como estaba: ${String(error)}`)
64
+ }
65
+ }),
66
+ )
67
+ })
68
+ }
package/index.ts CHANGED
@@ -24,9 +24,10 @@ import { register as registerBrowser, createDefaultBrowserConfig, type BrowserCo
24
24
  import { registerCentralRpc } from "./core/rpc.js"
25
25
  import { registerSkills } from "./core/skills.js"
26
26
  import { compatibilityWarnings } from "./core/compat.js"
27
+ import { registerTempAccess } from "./core/temp-access.js"
27
28
 
28
29
  // Plugin version
29
- const VERSION = "0.2.5"
30
+ const VERSION = "0.2.6"
30
31
 
31
32
  interface ModuleConfigs {
32
33
  redact: RedactConfig & { enabled: boolean }
@@ -139,6 +140,11 @@ export default Plugin.define({
139
140
  yield* registerGuard(ctx, moduleConfigs.guard)
140
141
  }
141
142
 
143
+ // Después del guard (sus deny se respetan) y antes del advisor (no ve lo ya resuelto).
144
+ if (validatedConfig.modules?.tempAccess ?? true) {
145
+ yield* registerTempAccess(ctx)
146
+ }
147
+
142
148
  if (moduleConfigs.advisor.enabled) {
143
149
  yield* registerAdvisor(ctx, moduleConfigs.advisor)
144
150
  }
@@ -37,7 +37,9 @@
37
37
  "events": false,
38
38
  "advisor": true,
39
39
  "guard": false,
40
- "browser": true
40
+ "browser": true,
41
+ // external_directory without asking in <tmpdir>/opencode (OpenCode's temp dir)
42
+ "tempAccess": true
41
43
  },
42
44
 
43
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-apex",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Modular plugin for OpenCode V2 (>= 2.1): secret redaction, RPC callbacks/webhooks/watchers that wake agents, tools.run, AI permission advisor, guard meta-permissions, external browser over CDP",
5
5
  "license": "MIT",
6
6
  "author": "Antonio Orizondo Leyva",
@@ -59,7 +59,7 @@
59
59
  "bun-types": "^1.1.0"
60
60
  },
61
61
  "scripts": {
62
- "test": "bun test/events.test.ts && bun test/guard.test.ts && bun test/process-context.test.ts",
62
+ "test": "bun test/events.test.ts && bun test/guard.test.ts && bun test/process-context.test.ts && bun test/temp-access.test.ts",
63
63
  "typecheck": "tsc --noEmit -p .",
64
64
  "check:install": "node scripts/check-install.mjs",
65
65
  "prepublishOnly": "npm test && npm run typecheck && npm run check:install"