@sjawhar/claude-envoy 4.0.0 → 4.1.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.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "4.0.0"
5
+ "version": "4.1.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
package/README.md CHANGED
@@ -226,6 +226,87 @@ Dispatch asks remain on native Dispatch.
226
226
  An Envoy delivery is one-way ingress, not a remote
227
227
  human approval surface.
228
228
 
229
+ ## Codex CLI
230
+
231
+ The Codex CLI plugin is a package of its own, `@sjawhar/codex-envoy`, built from
232
+ this package's source and released with it at the same version. One package cannot be both:
233
+ Codex's plugin validator refuses a manifest that names its hooks file, so Codex's hooks sit at
234
+ `hooks/hooks.json`, where Claude Code reads its own, and an npm install takes a package's root.
235
+ Codex reads the repository's `.agents/plugins/marketplace.json`, which names that package:
236
+
237
+ ```bash
238
+ codex plugin marketplace add cybermonklabs/legion
239
+ codex plugin add codex-envoy@legion-plugins
240
+ ```
241
+
242
+ `bun scripts/build.ts --codex-out <dir>` builds it from this tree into a directory outside the
243
+ repository: `codex/`'s manifests, hooks and README, this package's skills and a fresh `dist/`.
244
+ A skill that sets `disable-model-invocation: true`, which Codex's validator refuses, is shipped
245
+ with Codex's own form of it, an `agents/openai.yaml` whose `policy.allow_implicit_invocation`
246
+ is `false`: the skill stays out of the model's context until a person names it as `$<skill>`.
247
+
248
+ Start `codex` as usual and trust the plugin's hooks when Codex asks (it asks again after an update
249
+ that changes them; an untrusted hook does not run). The session reads the same envoy.json as every
250
+ other session on the machine: the file `ENVOY_CONFIG_FILE` names, else
251
+ `${XDG_CONFIG_HOME:-~/.config}/legion/envoy.json`. Under the Codex home (`CODEX_HOME`, else
252
+ `~/.codex`) the plugin reads the session's transcript, writes only to the state directory Codex
253
+ gives each plugin (`plugins/data/`), and adds to Codex's message queue through `codex queue`;
254
+ it never touches Codex's configuration.
255
+ Measured on Codex CLI 0.154.0.
256
+
257
+ Which sessions get Envoy depends on how Codex runs them.
258
+ A session in a `codex` process of its own (the terminal on 0.154.0, `codex exec`) registers with
259
+ Envoy and gets everything below.
260
+ Codex's shared app server runs several sessions in one process: `codex agents` (with or without `--no-daemon`), a plain `codex` that joins a running app server, and on 0.170.0 every terminal session, which runs in a background `codex app-server --managed-daemon`.
261
+ The plugin cannot tell those sessions' Envoy traffic apart, so there it registers none of them:
262
+ they get no Envoy messages and do not show on the Agents page, and the hook tells the model so.
263
+ Everything else still runs there: the `dispatch` tool, as the session that calls it, and the
264
+ `SessionStart` hooks (the open-asks summary, the dispatch-first skill and the answers list).
265
+ A fork (`/side`, `/btw`) is never registered: its session's registration stays where it was.
266
+ Neither is an ephemeral session (`codex exec --ephemeral`), which no message could reach.
267
+
268
+ - `codex/.codex-plugin/plugin.json` names the skills and one MCP server,
269
+ `bun ./dist/envoy-channel.js --host codex`, run in the plugin's own directory (`"cwd": "./"`;
270
+ Codex expands no `${PLUGIN_ROOT}` in a server's arguments). Codex hands a plugin's server only
271
+ `HOME`, `PATH` and a few more, so `env_vars` names the ones the server reads.
272
+ - The session appears on the Agents page at its first prompt, not when the terminal opens: Codex
273
+ gives the MCP server no session id, and its `SessionStart` hook, which runs at the first prompt
274
+ and again after `/new`, records the id under the `codex` process both are children of
275
+ (`hooks/codex-hook.ts`, `src/codex/codex-session-record.ts`). Codex starts one MCP server per
276
+ thread, so a `/new` or a fork starts another; one server per `codex` process owns the session
277
+ (`src/codex/codex-owner.ts`) and the others stand by, serving only their thread's `dispatch`
278
+ calls. After `/new`, the owner moves the registration to the new session at its first prompt.
279
+ Until then, a message to the old session can still be queued into it, since Codex runs the old
280
+ thread's `SessionEnd` hook only when it unloads that thread: `thread_unload_delay` (60 s by
281
+ default, and configurable) after the thread is idle with no subscriber, and after it has
282
+ stopped that thread's servers. Until every server started before the new thread's has exited,
283
+ the new thread's own Envoy tools (`envoy_send` and the rest) answer that another server serves
284
+ the session; messages to it arrive meanwhile, and its `dispatch` tool works.
285
+ A fork or an ephemeral session (`codex exec --ephemeral`) keeps no transcript and is never
286
+ registered, since Codex refuses `codex queue` for an ephemeral thread.
287
+ - The `dispatch` tool acts as the thread whose turn called it, which Codex names on every tool
288
+ call (`_meta.threadId`), and runs in the directory that thread's newest turn ran in.
289
+ - A message reaches an idle session through `codex queue`, which Codex takes as a new turn a few
290
+ seconds later. One that arrives during a turn waits in the plugin's inbox, and the
291
+ `PostToolUse` hook (`hooks/codex-tool-hook.ts`) hands it to the model in the turn's next
292
+ request; one no tool call took is queued when the turn ends (`src/codex/codex-delivery.ts`).
293
+ A person's Send or Aside is accepted on Dispatch and arrives as their own words; a `/` message
294
+ is answered that it was not run.
295
+ - A BTW is answered by a separate `codex app-server` that forks the session's conversation
296
+ ephemerally with plugins and hooks off, a read-only sandbox and no approvals
297
+ (`src/codex/codex-cli.ts`); the session's own conversation is left as it was.
298
+ - The live view reads the session's transcript file into the frames the Agents page draws
299
+ (`src/codex/codex-transcript.ts`, `src/codex/codex-agent-stream.ts`).
300
+ - Agents reach Dispatch through the server's `dispatch` tool, which takes the command's words as
301
+ `args` and its standard input as `stdin` and runs `dist/dispatch.js` as the session: Codex puts no
302
+ plugin command on the shell's `PATH`, and its default sandbox keeps shell commands off the
303
+ network. The manifest pre-approves that one tool, since Codex asks before every call of a
304
+ plugin's tool; the Envoy tools are asked about as usual. The `dispatch` command itself takes host
305
+ `codex` from `CODEX_THREAD_ID`, for a shell that can reach Dispatch.
306
+
307
+ `tests/codex-real.test.ts` runs the real binary (`LEGION_TEST_CODEX=<path to codex>`) against a
308
+ stand-in model; it skips without one, and nothing in CI installs Codex.
309
+
229
310
  ## Skills
230
311
 
231
312
  The plugin ships eleven skills, `claude-envoy:envoy`, `claude-envoy:dispatch`,
@@ -1,9 +1,14 @@
1
+ import { runCodexEnvoyServer } from "../src/codex/codex-server"
1
2
  import { runEnvoyChannelServer } from "../src/envoy-channel-server"
2
3
 
4
+ // `codex/.codex-plugin/plugin.json` starts this bundle with `--host codex`; Claude Code's
5
+ // `.mcp.json` starts it with no argument.
6
+ const codex = process.argv.slice(2).join(" ") === "--host codex"
7
+
3
8
  try {
4
- await runEnvoyChannelServer()
9
+ await (codex ? runCodexEnvoyServer() : runEnvoyChannelServer())
5
10
  } catch (error) {
6
11
  const message = error instanceof Error ? error.message : "unknown channel server failure"
7
- process.stderr.write(`Claude Envoy channel server failed: ${message}\n`)
12
+ process.stderr.write(`${codex ? "Codex" : "Claude"} Envoy channel server failed: ${message}\n`)
8
13
  process.exitCode = 1
9
14
  }