opencode-apex 0.2.5 → 0.3.0

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,32 @@ All notable changes to `opencode-apex`. Format based on
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.3.0] — 2026-11-25
9
+
10
+ ### Deprecated
11
+
12
+ - **The browser module is deprecated and now off by default.** OpenCode's own
13
+ [browse](https://opencode.ai/product/browse) (an MCP server plus a Chromium extension)
14
+ lets agents use your real browser: your tabs and logins, no remote debugging and no
15
+ consent prompt, handoffs for logins and 2FA, tab recordings. With both on, the agent
16
+ got two browser toolsets that overlapped. The module stays for what browse does not do:
17
+ serving OpenCode's `browser.*` tools from a headless or remote Chromium over CDP, and the
18
+ `browser.*` performance captures. Turn it back on with `"modules": { "browser": true }`;
19
+ it logs a deprecation warning. It may be removed in a later release.
20
+
21
+ ## [0.2.6] — 2026-11-25
22
+
23
+ ### Added
24
+
25
+ - **`tempAccess` module (on by default): OpenCode's temporary directory without asking.**
26
+ OpenCode tells the model to prefer `<tmpdir>/opencode` (`/tmp/opencode` on Linux) over
27
+ `/tmp`, "pre-created and approved for external access", but no rule approves it, so
28
+ every read or write there asked for `external_directory`. apex now allows those requests
29
+ through a `permission.evaluate` hook. It only turns `ask` into `allow`, only when every
30
+ requested path is inside that directory, and a deny you configure still wins, since
31
+ OpenCode evaluates configured denies first. It runs after the guard and before the
32
+ advisor. Turn it off with `"modules": { "tempAccess": false }`.
33
+
8
34
  ## [0.2.5] — 2026-11-24
9
35
 
10
36
  0.2.4 was never published to npm. Its changes are part of this release.
package/README.md CHANGED
@@ -5,7 +5,9 @@
5
5
  - event-driven automations (callbacks, webhooks, scheduled watchers that wake an agent up);
6
6
  - AI-assisted permission decisions;
7
7
  - per-agent meta-permissions;
8
- - `browser.*` tools driven by your own Chromium.
8
+ - access to OpenCode's temporary directory without prompts;
9
+ - (deprecated) `browser.*` tools driven by a headless or remote Chromium over CDP. To let
10
+ agents use your own browser, use OpenCode's [browse](https://opencode.ai/product/browse).
9
11
 
10
12
  > [!IMPORTANT]
11
13
  > **OpenCode V2 only (OpenCode ≥ 2.1).** apex is written against the V2 plugin runtime
@@ -48,7 +50,7 @@ A few OpenCode terms used throughout these docs:
48
50
  | **Skill** | A Markdown guide an agent can load when a task needs it. apex ships one. |
49
51
  | **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
52
 
51
- apex is one plugin with five independent modules. Each one can be switched on or off.
53
+ apex is one plugin with six independent modules. Each one can be switched on or off.
52
54
 
53
55
  ## Modules
54
56
 
@@ -58,12 +60,13 @@ apex is one plugin with five independent modules. Each one can be switched on or
58
60
  | **Events** | Lets programs outside OpenCode (scripts, cron jobs, webhooks, n8n…) notify an agent. **Subscriptions** decide which session receives what. `tools.run` lets those programs use OpenCode tools. | on | [docs/EVENTS.md](docs/EVENTS.md) |
59
61
  | **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
62
  | **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
- | **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) |
63
+ | **Browser** *(deprecated)* | Serves OpenCode's `browser.*` tools against an **external** Chromium over CDP. Superseded by OpenCode's [browse](https://opencode.ai/product/browse) for your own browser; kept for a headless or remote Chromium and for `browser.*` performance captures. | **off** | [docs/BROWSER.md](docs/BROWSER.md) |
64
+ | **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
65
 
63
66
  Turn modules on or off in `modules`. That is the only switch: there is no `<module>.enabled`.
64
67
 
65
68
  ```jsonc
66
- "modules": { "redact": true, "events": true, "advisor": true, "guard": false, "browser": true }
69
+ "modules": { "redact": true, "events": true, "advisor": true, "guard": false, "browser": false, "tempAccess": true }
67
70
  ```
68
71
 
69
72
  ## Requirements
@@ -71,7 +74,9 @@ Turn modules on or off in `modules`. That is the only switch: there is no `<modu
71
74
  - **OpenCode ≥ 2.1** (V2). Nothing else: OpenCode downloads the plugin and its dependencies
72
75
  itself.
73
76
  - For the automation examples, a shell with `curl` and `sed`.
74
- - Optional: Chromium/Chrome for the Browser module, and `bun` if you want to hack on apex.
77
+ - Optional: `bun` if you want to hack on apex. For browsers, OpenCode's
78
+ [browse](https://opencode.ai/product/browse); apex's deprecated Browser module needs a
79
+ Chromium with remote debugging.
75
80
 
76
81
  ## Install
77
82
 
@@ -86,7 +91,7 @@ Add apex to the `plugins` list of your OpenCode config:
86
91
  {
87
92
  "package": "opencode-apex",
88
93
  "options": {
89
- "modules": { "redact": true, "events": true, "advisor": true, "guard": false, "browser": true }
94
+ "modules": { "redact": true, "events": true, "advisor": true, "guard": false }
90
95
  }
91
96
  }
92
97
  ]
@@ -237,7 +242,7 @@ curl -sS -u "opencode:$PW" -H 'content-type: application/json' \
237
242
  | `apex_set_callback_url` | events | Sets or clears the server's public URL (tunnel / reverse proxy), for senders on other machines |
238
243
  | `apex_advisor_decide` | advisor | The advisor agent's only tool: `allow` / `deny` + reason |
239
244
  | `apex_guard_report` | guard | Report of what each agent attempted and what was decided |
240
- | `browser_target` | browser | Chooses which browser serves `browser.*`: `external` (CDP), `in-app` (desktop app) or `auto` |
245
+ | `browser_target` | browser (deprecated, off by default) | Chooses which browser serves `browser.*`: `external` (CDP), `in-app` (desktop app) or `auto` |
241
246
 
242
247
  apex also registers two hidden agents: `apex-advisor` for the Advisor and `apex-runner`, the
243
248
  technical session behind `tools.run`.
package/core/config.ts CHANGED
@@ -262,8 +262,10 @@ export const apexConfigSchema = z.object({
262
262
  events: z.boolean().optional(),
263
263
  advisor: z.boolean().optional(),
264
264
  guard: z.boolean().optional(),
265
- // Activado por defecto; en modo external puede abrir un popup de Chrome.
265
+ // Obsoleto, desactivado por defecto: para tu navegador, `browse` de OpenCode.
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/docs/BROWSER.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Browser module — drive an external Chromium with OpenCode's `browser` tools
2
2
 
3
+ > [!WARNING]
4
+ > **Deprecated since 0.3.0, and off by default.** To let agents use **your own browser**,
5
+ > with its tabs and logins, use OpenCode's [browse](https://opencode.ai/product/browse): an
6
+ > MCP server and a Chromium extension made by the OpenCode team. It needs no remote
7
+ > debugging and no consent prompt, hands the tab back to you for logins and 2FA, and works
8
+ > in any MCP client.
9
+ >
10
+ > This module remains for what browse does not do: serving OpenCode's own `browser.*` tools
11
+ > from a **headless or remote Chromium over CDP** (a server, CI, a tunnel), and the
12
+ > `browser.*` performance captures (trace, CPU, heap). Turn it on with
13
+ > `"modules": { "browser": true }`. It may be removed in a later release.
14
+
3
15
  > **OpenCode V2 only (2.1 or newer).** OpenCode V1 has a different plugin system and
4
16
  > cannot load apex.
5
17
 
@@ -40,7 +52,7 @@ descriptions are still OpenCode's own. apex only provides the browser behind the
40
52
  Port 9333 rather than the usual 9222: a stale `DevToolsActivePort` file from your
41
53
  everyday Chrome often still claims 9222.
42
54
 
43
- 2. Make sure the module is on (it is by default) and point it at that port:
55
+ 2. Turn the module on (it is off by default since 0.3.0) and point it at that port:
44
56
 
45
57
  ```jsonc
46
58
  // in the apex options (see docs/CONFIG.md)
@@ -205,7 +217,7 @@ fewer items, a shallower snapshot, or only the needed fields.
205
217
 
206
218
  ```jsonc
207
219
  {
208
- "modules": { "browser": true }, // on by default
220
+ "modules": { "browser": true }, // off by default since 0.3.0
209
221
  "browser": {
210
222
  "mode": "auto", // in-app | external | auto
211
223
  "cdpUrl": "auto", // "auto" | "9222" | "ws://…" | "wss://…"
package/docs/CONFIG.md CHANGED
@@ -81,7 +81,7 @@ but are overridden by the local file.
81
81
  Each module has exactly one switch, under `modules`:
82
82
 
83
83
  ```jsonc
84
- "modules": { "redact": true, "events": true, "advisor": true, "guard": false, "browser": true }
84
+ "modules": { "redact": true, "events": true, "advisor": true, "guard": false, "browser": false, "tempAccess": true }
85
85
  ```
86
86
 
87
87
  | Module | Default when the key is omitted |
@@ -90,7 +90,8 @@ Each module has exactly one switch, under `modules`:
90
90
  | `events` | on |
91
91
  | `advisor` | on |
92
92
  | `guard` | **off** (it can block the agent if its rules are wrong, so you opt in) |
93
- | `browser` | on |
93
+ | `browser` | **off** since 0.3.0 (deprecated: use OpenCode's [browse](https://opencode.ai/product/browse)) |
94
+ | `tempAccess` | on |
94
95
 
95
96
  There is no `<module>.enabled` key. A legacy `events.enabled` is ignored and logs a
96
97
  warning. So does `events.listener`: the HTTP listener was removed in 0.2.0, see
@@ -181,8 +181,11 @@ apex merges three sources. Each one overrides the previous:
181
181
 
182
182
  ## The browser tools say "No desktop browser is connected"
183
183
 
184
- See [BROWSER.md](BROWSER.md): a session only gets a browser after `browser_target` or
185
- `/browser-target` asks for one.
184
+ To let agents use your own browser, install OpenCode's
185
+ [browse](https://opencode.ai/product/browse) and use its `browse` tools instead. For a
186
+ headless or remote Chromium, turn on apex's deprecated browser module (`"modules":
187
+ { "browser": true }`, see [BROWSER.md](BROWSER.md)): a session only gets a browser after
188
+ `browser_target` or `/browser-target` asks for one.
186
189
 
187
190
  ---
188
191
 
package/index.ts CHANGED
@@ -6,7 +6,9 @@
6
6
  * - events: RPC event ingestion (callbacks/webhooks), subscriptions, delivery, tools.run
7
7
  * - advisor: allow/deny permission decisions via a dedicated agent + side session
8
8
  * - guard: meta-permissions per agent/tool/path (opt-in)
9
- * - browser: browser.* tools against an external Chromium over CDP (attach on request)
9
+ * - browser: (deprecated, off by default; OpenCode's browse replaces it) browser.* tools
10
+ * against a headless or remote Chromium over CDP (attach on request)
11
+ * - tempAccess: external_directory without prompts in OpenCode's temp directory
10
12
  *
11
13
  * Built on the official Effect plugin API: https://opencode.ai/v2/docs/build/plugins/effect/
12
14
  */
@@ -24,9 +26,10 @@ import { register as registerBrowser, createDefaultBrowserConfig, type BrowserCo
24
26
  import { registerCentralRpc } from "./core/rpc.js"
25
27
  import { registerSkills } from "./core/skills.js"
26
28
  import { compatibilityWarnings } from "./core/compat.js"
29
+ import { registerTempAccess } from "./core/temp-access.js"
27
30
 
28
31
  // Plugin version
29
- const VERSION = "0.2.5"
32
+ const VERSION = "0.3.0"
30
33
 
31
34
  interface ModuleConfigs {
32
35
  redact: RedactConfig & { enabled: boolean }
@@ -54,11 +57,13 @@ function getModuleConfigs(userConfig: ApexConfig): ModuleConfigs {
54
57
  agents: { ...createDefaultGuardConfig().agents, ...userConfig.guard?.agents },
55
58
  enabled: userConfig.modules?.guard ?? false,
56
59
  },
57
- // Activado por defecto; en modo `external` puede abrir un popup de Chrome por conexión.
60
+ // Obsoleto desde 0.3.0, desactivado por defecto: para usar tu navegador está `browse`
61
+ // de OpenCode (https://opencode.ai/product/browse). Queda para Chromium headless o
62
+ // remoto por CDP y para las capturas de rendimiento de `browser.*`.
58
63
  browser: {
59
64
  ...createDefaultBrowserConfig(),
60
65
  ...userConfig.browser,
61
- enabled: userConfig.modules?.browser ?? true,
66
+ enabled: userConfig.modules?.browser ?? false,
62
67
  },
63
68
  }
64
69
  }
@@ -139,11 +144,19 @@ export default Plugin.define({
139
144
  yield* registerGuard(ctx, moduleConfigs.guard)
140
145
  }
141
146
 
147
+ // Después del guard (sus deny se respetan) y antes del advisor (no ve lo ya resuelto).
148
+ if (validatedConfig.modules?.tempAccess ?? true) {
149
+ yield* registerTempAccess(ctx)
150
+ }
151
+
142
152
  if (moduleConfigs.advisor.enabled) {
143
153
  yield* registerAdvisor(ctx, moduleConfigs.advisor)
144
154
  }
145
155
 
146
156
  if (moduleConfigs.browser.enabled) {
157
+ yield* Effect.logWarning(
158
+ "[apex.browser] deprecated: use OpenCode's browse (https://opencode.ai/product/browse) to drive your browser; keep this module only for a headless or remote Chromium over CDP",
159
+ )
147
160
  yield* registerBrowser(ctx, moduleConfigs.browser)
148
161
  }
149
162
 
@@ -30,14 +30,17 @@
30
30
  // --------------------------------------------------------------------------
31
31
  // Modules: turn each one on or off.
32
32
  // SINGLE SWITCH: it lives ONLY here — there is no <module>.enabled.
33
- // An omitted key means the module's default: all ON except guard (OFF).
33
+ // An omitted key means the module's default: all ON except guard and browser (OFF).
34
34
  // --------------------------------------------------------------------------
35
35
  "modules": {
36
36
  "redact": true,
37
37
  "events": false,
38
38
  "advisor": true,
39
39
  "guard": false,
40
- "browser": true
40
+ // Deprecated: use OpenCode's browse for your browser (docs/BROWSER.md)
41
+ "browser": false,
42
+ // external_directory without asking in <tmpdir>/opencode (OpenCode's temp dir)
43
+ "tempAccess": true
41
44
  },
42
45
 
43
46
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-apex",
3
- "version": "0.2.5",
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",
3
+ "version": "0.3.0",
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, temp-directory access, (deprecated) headless browser over CDP",
5
5
  "license": "MIT",
6
6
  "author": "Antonio Orizondo Leyva",
7
7
  "repository": {
@@ -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"