opencode-apex 0.2.2 → 0.2.5

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.
@@ -11,13 +11,17 @@
11
11
  * cuando su pid es este proceso
12
12
  * 3. los argumentos `--hostname`/`--port` de `opencode serve`
13
13
  *
14
+ * La URL pública (emisores de otras máquinas) sale de: `apex_set_callback_url` (runtime) >
15
+ * `events.server.publicUrl` (config) > el acceso remoto del propio servicio
16
+ * (`opencode service set remote true`, un túnel OpenTunnel que OpenCode mantiene).
17
+ *
14
18
  * La auth es HTTP Basic `opencode:<password>`. El password NUNCA se devuelve: solo
15
19
  * dónde leerlo, para que no acabe en la conversación (ni en el proveedor del modelo).
16
20
  */
17
21
 
18
22
  import { readdirSync, readFileSync } from "node:fs"
19
23
  import { homedir } from "node:os"
20
- import { join } from "node:path"
24
+ import { basename, join } from "node:path"
21
25
 
22
26
  export const SERVER_USERNAME = "opencode"
23
27
 
@@ -35,22 +39,64 @@ export interface ServerEndpoint {
35
39
  /** URL base del servidor, alcanzable desde esta máquina (null = desconocida). */
36
40
  readonly baseUrl: string | null
37
41
  readonly source: "config" | "service" | "argv" | null
38
- /** URL para procesos FUERA de esta máquina (túnel / proxy inverso), si se declaró. */
42
+ /** URL para procesos FUERA de esta máquina (túnel / proxy inverso), si se conoce. */
39
43
  readonly publicUrl: string | null
44
+ /** De dónde salió publicUrl: runtime | config | service-remote (acceso remoto de OpenCode). */
45
+ readonly publicUrlSource: "runtime" | "config" | "service-remote" | null
40
46
  /** Directorio del proyecto al que deben ir las llamadas RPC (`location[directory]`). */
41
47
  readonly directory: string
42
48
  readonly auth: { readonly scheme: "basic"; readonly username: string; readonly password: PasswordSource | null }
43
49
  /** URLs completas de los métodos RPC de apex para este directorio. */
44
- readonly rpc: Readonly<Record<"ingest" | "toolsRun" | "status" | "ping", string>>
50
+ readonly rpc: RpcUrls
51
+ /** Las mismas URLs sobre publicUrl, para emisores de otras máquinas (null sin publicUrl). */
52
+ readonly publicRpc: RpcUrls | null
45
53
  readonly hint?: string
46
54
  }
47
55
 
56
+ type RpcUrls = Readonly<Record<"ingest" | "toolsRun" | "status" | "ping", string>>
57
+
48
58
  /** `<state>/opencode` — respeta XDG_STATE_HOME igual que OpenCode. */
49
59
  export function stateDirectory(env: NodeJS.ProcessEnv = process.env, home = homedir()): string {
50
60
  const base = env.XDG_STATE_HOME && env.XDG_STATE_HOME.length > 0 ? env.XDG_STATE_HOME : join(home, ".local", "state")
51
61
  return join(base, "opencode")
52
62
  }
53
63
 
64
+ /** Config de OpenCode — `OPENCODE_CONFIG_DIR`, si no `<XDG_CONFIG_HOME>/opencode`, como el CLI. */
65
+ export function configDirectory(env: NodeJS.ProcessEnv = process.env, home = homedir()): string {
66
+ if (env.OPENCODE_CONFIG_DIR && env.OPENCODE_CONFIG_DIR.length > 0) return env.OPENCODE_CONFIG_DIR
67
+ const base = env.XDG_CONFIG_HOME && env.XDG_CONFIG_HOME.length > 0 ? env.XDG_CONFIG_HOME : join(home, ".config")
68
+ return join(base, "opencode")
69
+ }
70
+
71
+ /** Identidades de OpenTunnel — `<XDG_DATA_HOME>/opentunnel`, como su SDK. */
72
+ export function tunnelDirectory(env: NodeJS.ProcessEnv = process.env, home = homedir()): string {
73
+ return join(env.XDG_DATA_HOME ?? join(home, ".local", "share"), "opentunnel")
74
+ }
75
+
76
+ /**
77
+ * URL del acceso remoto del servicio (`opencode service set remote true`), o null.
78
+ *
79
+ * El servicio sirve su ruta secreta (`remote.route` de su config, que se llama igual que su
80
+ * registro) en el túnel OpenTunnel del perfil `default`: `https://<route>.<hostname>`. Es lo
81
+ * mismo que calcula OpenCode (`RemoteTunnel.hostname`). Dice que está configurado, no que
82
+ * el túnel esté conectado en este momento.
83
+ */
84
+ export function findServiceRemoteUrl(serviceFile: string, configDir: string, tunnelDir: string): string | null {
85
+ try {
86
+ const config = JSON.parse(readFileSync(join(configDir, basename(serviceFile)), "utf8")) as {
87
+ remote?: { route?: unknown }
88
+ }
89
+ const route = config.remote?.route
90
+ if (typeof route !== "string" || !/^[a-z0-9-]+$/.test(route)) return null
91
+ // Sin tunnel.json el certificado aún no está listo: no hay URL que dar.
92
+ const tunnel = JSON.parse(readFileSync(join(tunnelDir, "default", "tunnel.json"), "utf8")) as { hostname?: unknown }
93
+ if (typeof tunnel.hostname !== "string" || tunnel.hostname.length === 0) return null
94
+ return `https://${route}.${tunnel.hostname}`
95
+ } catch {
96
+ return null
97
+ }
98
+ }
99
+
54
100
  /** Host/puerto de `opencode serve` según su argv; null si no es un serve con puerto explícito. */
55
101
  export function parseServeArgv(argv: readonly string[]): { host: string; port: number } | null {
56
102
  if (!argv.includes("serve")) return null
@@ -99,13 +145,26 @@ export function rpcUrl(base: string, method: string, directory: string): string
99
145
  return `${base.replace(/\/+$/, "")}/api/rpc/apex/${method}?location%5Bdirectory%5D=${encodeURIComponent(directory)}`
100
146
  }
101
147
 
148
+ function rpcUrls(base: string, directory: string): RpcUrls {
149
+ return {
150
+ ingest: rpcUrl(base, "events.ingest", directory),
151
+ toolsRun: rpcUrl(base, "tools.run", directory),
152
+ status: rpcUrl(base, "status", directory),
153
+ ping: rpcUrl(base, "ping", directory),
154
+ }
155
+ }
156
+
102
157
  export function resolveServerEndpoint(input: {
103
158
  readonly directory: string
104
159
  readonly configUrl?: string
105
160
  readonly publicUrl?: string | null
161
+ /** Quién fijó `publicUrl` (por defecto config). */
162
+ readonly publicUrlFrom?: "runtime" | "config"
106
163
  readonly argv?: readonly string[]
107
164
  readonly pid?: number
108
165
  readonly stateDir?: string
166
+ readonly configDir?: string
167
+ readonly tunnelDir?: string
109
168
  }): ServerEndpoint {
110
169
  const argv = input.argv ?? process.argv
111
170
  const pid = input.pid ?? process.pid
@@ -141,19 +200,24 @@ export function resolveServerEndpoint(input: {
141
200
  : null
142
201
 
143
202
  const base = baseUrl ?? "<server-url>"
144
- const publicUrl = input.publicUrl && input.publicUrl.trim().length > 0 ? input.publicUrl.trim() : null
203
+ const declared = input.publicUrl && input.publicUrl.trim().length > 0 ? input.publicUrl.trim() : null
204
+ // Solo el proceso del servicio sirve el acceso remoto; un `opencode serve` suelto no.
205
+ const remote =
206
+ declared === null && service
207
+ ? findServiceRemoteUrl(service.file, input.configDir ?? configDirectory(), input.tunnelDir ?? tunnelDirectory())
208
+ : null
209
+ const publicUrl = declared ?? remote
210
+ const publicUrlSource: ServerEndpoint["publicUrlSource"] =
211
+ declared !== null ? (input.publicUrlFrom ?? "config") : remote !== null ? "service-remote" : null
145
212
  return {
146
213
  baseUrl,
147
214
  source,
148
215
  publicUrl,
216
+ publicUrlSource,
149
217
  directory: input.directory,
150
218
  auth: { scheme: "basic", username: SERVER_USERNAME, password },
151
- rpc: {
152
- ingest: rpcUrl(base, "events.ingest", input.directory),
153
- toolsRun: rpcUrl(base, "tools.run", input.directory),
154
- status: rpcUrl(base, "status", input.directory),
155
- ping: rpcUrl(base, "ping", input.directory),
156
- },
219
+ rpc: rpcUrls(base, input.directory),
220
+ publicRpc: publicUrl ? rpcUrls(publicUrl, input.directory) : null,
157
221
  ...(baseUrl
158
222
  ? {}
159
223
  : { hint: "Server URL unknown: set events.server.url in the apex config (e.g. http://127.0.0.1:4096)" }),
package/docs/ADVISOR.md CHANGED
@@ -101,6 +101,7 @@ The advisor module is **on by default** (`modules.advisor`). Set `"advisor": fal
101
101
  "timeoutMs": 10000, // wait this long for an answer, then leave the permission as it was
102
102
  "actions": [], // tool names to judge; empty = all
103
103
  "location": "", // advisor session directory; empty = <tmp>/opencode-apex-advisor
104
+ "processContext": true, // describe the processes a kill/pkill/killall would hit (Linux)
104
105
  "system": "…", // optional: replaces the advisor's system prompt
105
106
  "promptTemplate": "…", // optional: the request text sent to the advisor
106
107
  "promptTemplateFile": "…" // optional: same, from a file (wins over promptTemplate)
@@ -109,10 +110,60 @@ The advisor module is **on by default** (`modules.advisor`). Set `"advisor": fal
109
110
 
110
111
  - **Template placeholders:** `{{requestID}}`, `{{action}}`, `{{resources}}`, `{{sessionID}}`,
111
112
  `{{agent}}`, `{{enforcement}}` (a sentence that tells the advisor whether its decision is
112
- applied) and `{{metadata.<path>}}`.
113
+ applied), `{{processes}}` (see [below](#killing-processes-whose-process-is-it)) and
114
+ `{{metadata.<path>}}`.
113
115
  - **`promptTemplateFile`** must be a relative path, inside the project or your home
114
116
  directory. If the file does not exist, it is created with the default template.
115
117
 
118
+ ## Killing processes: whose process is it?
119
+
120
+ A permission for `kill 705875` tells the advisor nothing about process 705875. It could
121
+ be the dev server the agent started a minute ago, or your browser. An advisor told to
122
+ deny "killing processes that are not ours" can only guess, and a careful one denies. (Measured
123
+ before 0.2.4: every plain `kill <PID>` was denied, while `pkill -f "n8n start"` — where
124
+ the name is visible — was allowed.)
125
+
126
+ With `processContext: true` (the default), apex reads `/proc` before asking. For every
127
+ `kill`, `pkill`, `killall` and `kill $(pgrep …)` in a `shell` permission it adds a block like
128
+ this to the request:
129
+
130
+ ```
131
+ Procesos afectados (leído de /proc por apex, no lo afirma el agente):
132
+ - PID 751365 · antonio · lanzado por un agente de ESTA conversación (o uno de sus subagentes)
133
+ sleep 60
134
+ - PID 2914 · antonio · del usuario, no lanzado por opencode
135
+ /usr/bin/kwin_wayland_wrapper --xwayland
136
+ ```
137
+
138
+ For each process it reports:
139
+
140
+ | Field | How apex knows |
141
+ | --- | --- |
142
+ | owner | `Uid` in `/proc/<pid>/status` |
143
+ | command | `/proc/<pid>/cmdline` |
144
+ | who launched it | OpenCode's `shell` tool exports `OPENCODE_SESSION_ID` to every command it runs. apex reads it from `/proc/<pid>/environ` (or from a parent's, for processes started with `nohup`/`setsid`) and checks whether that session belongs to the same session tree as the one asking |
145
+ | critical | the OpenCode server itself, any of its parents (the terminal holding it) or PID 1 |
146
+
147
+ The labels are: **this conversation** (launched by the asking session, its root or any
148
+ subagent of that tree), **another OpenCode conversation**, **the user's** (same user, not
149
+ launched by OpenCode), **another user's** (root or a different account) and **unknown**
150
+ (environment not readable). `kill -1`, `kill 0` and process groups get an explicit
151
+ warning; a `pkill` pattern that matches nothing says so.
152
+
153
+ apex only **describes**; the advisor still decides. Give it a rule that uses the block,
154
+ for example: *"Allow killing processes launched by this conversation. Deny killing
155
+ processes marked CRÍTICO, other users' processes and `kill -1`. For the user's own
156
+ processes, allow only if the command is clearly what the agent is working on."*
157
+
158
+ Notes:
159
+
160
+ - The block is part of the cache key, so an answer for `kill 1234` is not reused once
161
+ PID 1234 belongs to a different process.
162
+ - Your own `promptTemplate` does not need `{{processes}}`: if it is missing, the block is
163
+ appended at the end.
164
+ - Linux only. On other systems, or if `/proc` cannot be read, nothing is added and the
165
+ request is the same as before.
166
+
116
167
  ## Keeping the project's AGENTS.md away from the advisor
117
168
 
118
169
  OpenCode V2 has no per-agent instructions. Every session gets the instruction files found
@@ -138,8 +189,9 @@ in the session's `metadata.apexAdvisorLocation`.
138
189
  the link in `metadata.apexAdvisorFor`.
139
190
  - **Each uncached decision costs one model round trip.** With `evaluate: "all"`, every tool
140
191
  call waits for it.
141
- - **The cache key is only `(action, resources)`.** An answer given for one agent is reused
142
- for any other agent asking the same thing within 10 minutes.
192
+ - **The cache key is only `(action, resources)`**, plus the process block for kills. An
193
+ answer given for one agent is reused for any other agent asking the same thing within
194
+ 10 minutes.
143
195
  - **A missing answer never blocks you:** after `timeoutMs` the normal prompt appears.
144
196
 
145
197
  ## Working with the guard
package/docs/EVENTS.md CHANGED
@@ -189,7 +189,9 @@ outside process reaches THIS server:
189
189
  | `baseUrl` · `source` | Base URL and where it came from, in this order: `config` (`events.server.url`) > `service` (the background service record `<state>/opencode/service*.json` whose `pid` is this process; `<state>` is `$XDG_STATE_HOME` or `~/.local/state`) > `argv` (the `--hostname`/`--port` of `opencode serve`). `null` if none applies. |
190
190
  | `rpc.ingest` · `rpc.toolsRun` · `rpc.status` · `rpc.ping` | Full URLs of the methods, already carrying this project's `location[directory]`. |
191
191
  | `auth` | `{scheme:"basic", username:"opencode", password}`. `password` says **where** the password is, never the password itself: `{kind:"file", file, field:"password", shell}` for the background service (the record is a `0600` file), `{kind:"env", env:"OPENCODE_SERVER_PASSWORD", shell}` for `opencode serve`, or `null` if unknown. `shell` is a command that prints it. |
192
- | `publicUrl` | URL for senders on **other machines** (a tunnel or reverse proxy in front of the server). Runtime value (tool `apex_set_callback_url`) > `events.server.publicUrl`. The `rpc.*` URLs always use `baseUrl`: a remote sender replaces the base with `publicUrl`. |
192
+ | `publicUrl` | URL for senders on **other machines** (a tunnel or reverse proxy in front of the server). Runtime value (tool `apex_set_callback_url`) > `events.server.publicUrl` > OpenCode's remote access (`opencode service set remote true`), which is found automatically. |
193
+ | `publicUrlSource` | `runtime`, `config`, `service-remote` or `null` |
194
+ | `publicRpc` | The `rpc.*` URLs built on `publicUrl` (the `rpc.*` URLs always use `baseUrl`); `null` without `publicUrl` |
193
195
  | `examples` | Ready-to-run `curl` commands for `ingest` and `toolsRun` (they read the password at run time). Tool only; `server.info` omits them. |
194
196
  | `hint` | Present when `baseUrl` is unknown: set `events.server.url`. |
195
197
 
@@ -245,8 +247,10 @@ OpenCode can reach (an MCP server such as Easypanel, the browser tools…).
245
247
  A webhook is a callback with an **intermediate process**: the external service calls a
246
248
  relay over HTTP (n8n, a small daemon), and the relay turns that call into `events.ingest`.
247
249
  OpenCode itself does not expose a webhook URL. The `apex-callbacks` skill includes a
248
- minimal Node relay and an n8n recipe. To receive webhooks from the Internet, expose the
249
- relay (with its own token), never the OpenCode server.
250
+ minimal Node relay (token and GitHub signature checks) and an n8n recipe. To receive webhooks
251
+ from the Internet, expose the relay (with its own token), never the OpenCode server. A relay
252
+ behind NAT needs the provider's outbound mode, a tunnel, a reverse connection or a public
253
+ receiver that stores events for it: the skill's `references/reachability.md` compares them.
250
254
 
251
255
  ## Tools
252
256
 
@@ -258,5 +262,7 @@ relay (with its own token), never the OpenCode server.
258
262
  - `apex_set_callback_url` — sets/clears the server's public URL (tunnel/proxy); `null` clears it.
259
263
 
260
264
  The **`apex-callbacks`** skill ships with the package (`skills/apex-callbacks/SKILL.md`) and
261
- registers itself wherever apex loads: stateful watchers, systemd/cron, webhooks and
262
- `tools.run`.
265
+ registers itself wherever apex loads. `SKILL.md` holds the model and the steps. Its
266
+ `references/` cover relay design for any source (`relays.md`), reachability and tunnels
267
+ (`reachability.md`), running on Linux, macOS, Windows or containers (`run-anywhere.md`) and
268
+ copyable code (`examples.md`).
@@ -39,30 +39,39 @@ which config sources it found.
39
39
  | Cause in the log | Fix |
40
40
  | --- | --- |
41
41
  | `Cannot find package '@opencode/plugin'`, or OpenCode reports a 1.x version | You are on OpenCode V1. Upgrade to V2 (2.1+). |
42
- | `Schema.isStartsWith is not a function`, `missing TypeId`, or other errors from inside `effect` | Two copies of the `effect` library are mixed (see next section). Force a reinstall. |
42
+ | `Schema.isStartsWith is not a function`, `missing TypeId`, or other errors from inside `effect` | An `@opencode/*` package installed with apex is older than your OpenCode (see next section). Force a reinstall. |
43
43
  | `Plugin must export a default definition…` | You pointed `package` at a file. Point it at the plugin **directory** or at the npm name `opencode-apex`. |
44
44
  | `Plugin entrypoint not found` | The path in `package` is wrong, or the directory has no `index.ts`. |
45
45
 
46
46
  ## Version mismatch with OpenCode (`effect`)
47
47
 
48
48
  apex is written with the [`effect`](https://effect.website) library, and so is OpenCode.
49
- Every `@opencode/plugin` release pins one exact version of `effect`: 4.0.0-rc.112 up to
50
- 2.0.x, 4.0.1 in 2.1. If apex ran on a *different* copy than `@opencode/plugin`, values
51
- created by one copy would not be recognized by the other, and loading fails with errors
52
- from deep inside `effect`.
53
-
54
- **How apex avoids it (since 0.2.0):**
55
-
56
- 1. apex does **not** declare its own `effect` version. `effect` is an **optional peer
57
- dependency** (`^4.0.0`), satisfied by the copy `@opencode/plugin` brings, so npm
58
- installs **one** copy and it always matches OpenCode.
59
- 2. `@opencode/plugin` and `@opencode/plugin-browser` use caret ranges (`^2.1.1`), so a fresh
60
- install follows OpenCode 2.x releases.
61
- 3. On load, apex warns (`[apex] …` in the log) when it finds two copies of `effect`, or
62
- when OpenCode is a newer minor version than the `@opencode/plugin` installed with
63
- apex.
64
- 4. Before every publish, `scripts/check-install.mjs` installs the package the way
65
- OpenCode does and refuses to publish if it finds more than one copy of `effect`.
49
+
50
+ **What OpenCode guarantees.** Since 2.1, OpenCode serves `effect` and `@opencode/plugin` (every
51
+ subpath) to plugins **from its own copy**:
52
+ - an `import "effect"` inside a plugin always gets the host's version;
53
+ - loading those two packages from a plugin's own `node_modules` is refused, with
54
+ `… is not provided by OpenCode; plugins must use the host's "effect" and "@opencode/plugin" modules`.
55
+
56
+ **What can still drift.** The *other* `@opencode/*` packages come from apex's own
57
+ `node_modules`: `@opencode/schema` and `@opencode/client`, pulled in by `@opencode/plugin`,
58
+ and `@opencode/plugin-browser`. They run on the host's `effect`, so they must come from the
59
+ same release line as your OpenCode. When they don't, errors come from deep inside `effect`.
60
+ Example: `@opencode/schema` 2.0.14 calls `Schema.isStartsWith`, which no longer exists in the
61
+ `effect` 4.0.1 that OpenCode 2.1 serves.
62
+
63
+ **How apex keeps them aligned (since 0.2.0):**
64
+
65
+ 1. `@opencode/plugin` and `@opencode/plugin-browser` are `^2.1.1` dependencies. A fresh
66
+ install pulls the current 2.x packages.
67
+ 2. `effect` is only an **optional peer** (`^4.0.0`), for editors and tests outside OpenCode.
68
+ apex never pins its own version.
69
+ 3. On load, apex warns (`[apex] …` in the log) in two cases:
70
+ - OpenCode is a newer minor version than the `@opencode/plugin` installed with apex,
71
+ which means its `@opencode/*` packages are older than the host;
72
+ - it finds two copies of `effect` on disk.
73
+ 4. Before every publish, `scripts/check-install.mjs` installs the package the way OpenCode
74
+ does and refuses to publish if the install is inconsistent or the plugin does not import.
66
75
 
67
76
  **The one thing you have to do yourself:** OpenCode caches installed plugins and **does
68
77
  not refresh them on its own**. After upgrading OpenCode, or to move to a new apex
@@ -209,8 +218,12 @@ To watch the plugin load, run a throwaway server in the foreground:
209
218
 
210
219
  - **V2 imports only:** `@opencode/plugin` and `@opencode/plugin/effect`, never the V1
211
220
  package `@opencode-ai/plugin`.
212
- - **No own `effect` version** (see the version mismatch section above). Import `effect`
213
- freely for control flow, but never declare it as a regular dependency.
221
+ - **No own `effect` version** (see the version mismatch section above). OpenCode serves
222
+ `effect` and `@opencode/plugin` to plugins. Import them freely, but never declare `effect`
223
+ as a regular dependency.
224
+ - **Keep `@opencode/plugin` current.** It is the package that pulls the `@opencode/schema`
225
+ and `@opencode/client` matching the host. Keep its range in step with the OpenCode
226
+ versions you support.
214
227
  - **Tool and RPC schemas are plain JSON Schema**, not `Schema.Struct` from `effect`.
215
228
  OpenCode validates them with its own `effect`. A schema object built by another copy
216
229
  is not recognized, and the plugin is disabled with
package/events.ts CHANGED
@@ -463,6 +463,13 @@ function registerCallbackEndpointTool(
463
463
  baseUrl: { type: ["string", "null"], description: "Server base URL, as reachable from this machine" },
464
464
  source: { type: ["string", "null"], description: "Where baseUrl came from: config | service | argv" },
465
465
  publicUrl: { type: ["string", "null"], description: "URL for senders on other machines (tunnel/proxy)" },
466
+ publicUrlSource: {
467
+ type: ["string", "null"],
468
+ description:
469
+ "runtime (apex_set_callback_url) | config | service-remote (OpenCode remote access: " +
470
+ "`opencode service set remote true`)",
471
+ },
472
+ publicRpc: { type: ["object", "null"], description: "The rpc URLs over publicUrl, for remote senders" },
466
473
  directory: { type: "string", description: "Value of location[directory] for every call" },
467
474
  auth: { type: "object", description: "Basic opencode:<password>; password says where it is, password.shell prints it" },
468
475
  rpc: { type: "object", description: "Full URLs: ingest, toolsRun, status, ping" },
@@ -510,7 +517,8 @@ function registerSetCallbackUrlTool(
510
517
  description:
511
518
  "Sets (or clears) the public URL through which programs on OTHER machines reach this OpenCode " +
512
519
  "server, e.g. a tunnel (cloudflared/ngrok) pointing at its base URL. It is persisted and shown by " +
513
- "apex_callback_endpoint. Pass null to clear it. Precedence: runtime > config.",
520
+ "apex_callback_endpoint. Pass null to clear it. Precedence: runtime > config > OpenCode remote " +
521
+ "access (found on its own; usually there is no need to set it).",
514
522
  input: {
515
523
  type: "object",
516
524
  properties: {
@@ -865,6 +873,7 @@ export function register(
865
873
  directory: ctx.location.directory,
866
874
  configUrl: eventsConfig.server.url,
867
875
  publicUrl: state.runtimePublicUrl ?? eventsConfig.server.publicUrl ?? null,
876
+ publicUrlFrom: state.runtimePublicUrl ? "runtime" : "config",
868
877
  })
869
878
  yield* registerCallbackEndpointTool(ctx, endpoint)
870
879
  yield* registerSetCallbackUrlTool(ctx, state, endpoint)
package/index.ts CHANGED
@@ -26,7 +26,7 @@ import { registerSkills } from "./core/skills.js"
26
26
  import { compatibilityWarnings } from "./core/compat.js"
27
27
 
28
28
  // Plugin version
29
- const VERSION = "0.2.2"
29
+ const VERSION = "0.2.5"
30
30
 
31
31
  interface ModuleConfigs {
32
32
  redact: RedactConfig & { enabled: boolean }
@@ -257,9 +257,14 @@
257
257
  // injected. (The global AGENTS.md in ~/.config/opencode always applies.)
258
258
  // actions: filter by tool name (empty = all)
259
259
  // system: system prompt of the advisor agent (optional)
260
+ // processContext: before judging kill / pkill / killall, read /proc and tell the
261
+ // advisor whose process each target is: owner, command, whether an agent
262
+ // of THIS conversation launched it, and whether it is critical (OpenCode
263
+ // itself). Linux only. (default true)
260
264
  // promptTemplate: template of each request ({{requestID}}, {{action}}, {{resources}},
261
- // {{sessionID}}, {{agent}}, {{enforcement}}, {{metadata.<field>}}). A single-line JSON
262
- // string: write line breaks as \n.
265
+ // {{sessionID}}, {{agent}}, {{enforcement}}, {{processes}}, {{metadata.<field>}}).
266
+ // A template without {{processes}} gets the block appended at the end.
267
+ // A single-line JSON string: write line breaks as \n.
263
268
  // --------------------------------------------------------------------------
264
269
  "advisor": {
265
270
  "model": "opencode/big-pickle",
@@ -268,6 +273,7 @@
268
273
  "timeoutMs": 10000,
269
274
  "location": "",
270
275
  "actions": [],
276
+ "processContext": true,
271
277
  "promptTemplate": "Request {{requestID}}\nTool: {{action}}\nResources: {{resources}}\nSession: {{sessionID}} ({{agent}})\n{{enforcement}}\nDecide with apex_advisor_decide."
272
278
  }
273
279
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-apex",
3
- "version": "0.2.2",
3
+ "version": "0.2.5",
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",
62
+ "test": "bun test/events.test.ts && bun test/guard.test.ts && bun test/process-context.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"