@sjawhar/claude-envoy 2.32.4 → 2.33.1

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": "2.32.4"
5
+ "version": "2.33.1"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "2.32.4",
3
+ "version": "2.33.1",
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/AGENTS.md CHANGED
@@ -118,7 +118,7 @@ Dispatch asks stay on Dispatch.
118
118
  | Oh My Pi plugin manifest | `.omp-plugin/plugin.json` | Empty `mcpServers`, which is how omp is told this plugin has no MCP server: the channel server exits without Claude Code's session identity, and omp gets Envoy and Dispatch from `@sjawhar/pi-envoy`. omp reads this file before `.claude-plugin/plugin.json` and a manifest `mcpServers` replaces `.mcp.json` rather than merging; omitting the key falls through to `.mcp.json` and relaunches the server. Claude Code never reads it. Its `version` equals `package.json`'s (tested); omp reads only the file's `mcpServers` and that it exists, never its `version`. |
119
119
  | Skills | `skills/agent-secrets`, `skills/asd-ste100`, `skills/envoy`, `skills/dispatch`, `skills/dispatch-first`, `skills/dispatch-writing-specs`, `skills/outside-message`, `skills/plain-words`, `skills/approval-review`, `skills/thermonuclear-code-quality`, `skills/thermonuclear-deep-review` | Relative symlinks into the root `skills/`; the plugin ships these eleven and no other — the eight a standalone Claude Code session uses, `approval-review`, which only a session judging an approval request reads, and the reviewer's pair, which ships in both plugins so one copy of each rubric reaches both harnesses (the rest belong to Legion roles on Oh My Pi; README "Skills"). The pack resolves them, not the install: `bun pm pack` packs a link as nothing at all, so `package.json`'s `prepack` (`scripts/pack-skills.sh`) replaces each link with the skill's own files, which `files`' `skills/**` then packs, and its `postpack` puts the links back. `scripts/check-packed-skills.sh` reads them back out of the tarball for `release.yaml`'s `claude_envoy_build`, and `tests/packed-skills.test.ts` packs a tarball of its own. |
120
120
  | Built bundle | `dist/`, `scripts/build.ts`, `scripts/verify-build.sh` | Built, never committed: `release.yaml`'s `claude_envoy_build` builds it and packs it into the tarball it publishes to npm (its `bun run verify-build <tar>` builds it twice in a scratch directory, checks it as the release will and packs it, writing no file of the checkout, and nothing a person runs locally writes `dist/` or `legion/`; the jobs that run `verify-build` are named in its header and the jobs that run `release-push.sh extract-built` in that subcommand's paragraph; convention below), and `bun scripts/build.ts --out <dir>` builds a runnable copy outside the repository. The plugin cache has no `node_modules`, so the four executables (the channel server, the session hook, the title hook and the `dispatch` CLI, `BUNDLE_ENTRYPOINTS`) ship bundled, with `dist/THIRD_PARTY_NOTICES` (the inlined packages' licenses, from Bun's metafile through the root `scripts/third-party-notices.ts`); the build runs only on the pinned Bun (`.bun-version`). A mode folded into an existing bundle is paid for by that bundle's every other mode: an ESM entrypoint evaluates its whole module graph before it reads `argv`, which is why the title hook has an entrypoint of its own and why a hook on a blocking event is weighed by what its bundle imports, not by what its mode runs. |
121
- | The `dispatch` CLI | `bin/dispatch` (the shim, mode 755), `dist/dispatch.js` (built from `../envoy-client/bin/dispatch.ts`), `hooks/session-hook.ts` | Claude Code puts the plugin's `bin/` on the Bash tool's `PATH`. The `open-asks` hook writes `export DISPATCH_HOST=claude` and `export ENVOY_CONFIG_FILE='<path>'` (the envoy.json Claude Code's rule picks, `$CLAUDE_CONFIG_DIR/envoy.json` when that is set; single-quoted, which Claude Code's PowerShell bridge reads for a value holding no quote; `singleQuoted` in `hooks/session-hook.ts` gives the rest) to `CLAUDE_ENV_FILE`, each unless the file already holds that line, since every `SessionStart` of a session runs it; with no workable file location (a relative `CLAUDE_CONFIG_DIR`, `ENVOY_CONFIG_FILE` or `XDG_CONFIG_HOME`) it writes no `ENVOY_CONFIG_FILE` line. For a Legion pane (`LEGION_STATE_DIR` set) it writes the pane's jj attribution overlay too, and keeps exactly one `export JJ_CONFIG='<chain>'` line in that file: the line replaces an earlier one in its place rather than joining it, since a resume or a compaction of the same session id runs the hook again over the file it already wrote and the chain it resolves can differ, where two such lines in one sourced file would leave which overlay wins to the order they were written in. When no overlay could be written the file is left as it is, no line written and none removed: `CLAUDE_ENV_FILE` is `<config>/session-env/<session id>/sessionstart-hook-<n>.sh` (read on the pinned 2.1.311), one file per session id, so a `/clear` gets a new and empty one and a line already there names this same session's own overlay, still on disk — removing it would leave the session with no trailer, where keeping it leaves it the trailers it had. The command reads the file `ENVOY_CONFIG_FILE` names whenever `DISPATCH_HOST` is set. A Bash that takes nothing from that file, as a subagent's can (anthropics/claude-code#46696), has `DISPATCH_HOST` unset and the `CLAUDE_CODE_CHILD_SESSION=1` Claude Code sets in every Bash, so its `dispatch` command takes host `claude` and reads `CLAUDE_CONFIG_DIR` itself, by the plugin's own rule. The command reads the session id from `CLAUDE_CODE_SESSION_ID`, which Claude Code sets fresh in every Bash command and moves on `/clear`. The command prints the follow notice itself, once per ask. |
121
+ | The `dispatch` CLI | `bin/dispatch` (the shim, mode 755), `dist/dispatch.js` (built from `../envoy-client/bin/dispatch.ts`), `hooks/session-hook.ts` | Claude Code puts the plugin's `bin/` on the Bash tool's `PATH`. The `open-asks` hook writes `export DISPATCH_HOST=claude` and `export ENVOY_CONFIG_FILE='<path>'` (the envoy.json Claude Code's rule picks, `$CLAUDE_CONFIG_DIR/envoy.json` when that is set; single-quoted, which Claude Code's PowerShell bridge reads for a value holding no quote; `singleQuoted` in `hooks/session-hook.ts` gives the rest) to `CLAUDE_ENV_FILE`, each unless the file already holds that line, since every `SessionStart` of a session runs it; with no workable file location (a relative `CLAUDE_CONFIG_DIR`, `ENVOY_CONFIG_FILE` or `XDG_CONFIG_HOME`) it writes no `ENVOY_CONFIG_FILE` line. For a Legion pane (`LEGION_STATE_DIR` set) it writes the pane's jj attribution overlay too, and keeps exactly one `export JJ_CONFIG='<chain>'` line in that file: the line replaces an earlier one in its place rather than joining it, since a resume or a compaction of the same session id runs the hook again over the file it already wrote and the chain it resolves can differ, where two such lines in one sourced file would leave which overlay wins to the order they were written in. When no overlay could be written the file is left as it is, no line written and none removed: `CLAUDE_ENV_FILE` is `<config>/session-env/<session id>/sessionstart-hook-<n>.sh` (read on the pinned 2.1.311), one file per session id, so a `/clear` gets a new and empty one and a line already there names this same session's own overlay, still on disk — removing it would leave the session with no trailer, where keeping it leaves it the trailers it had. The command reads the file `ENVOY_CONFIG_FILE` names whenever `DISPATCH_HOST` is set. A Bash that takes nothing from that file, as a subagent's can (Claude Code issue 46696), has `DISPATCH_HOST` unset and the `CLAUDE_CODE_CHILD_SESSION=1` Claude Code sets in every Bash, so its `dispatch` command takes host `claude` and reads `CLAUDE_CONFIG_DIR` itself, by the plugin's own rule. The command reads the session id from `CLAUDE_CODE_SESSION_ID`, which Claude Code sets fresh in every Bash command and moves on `/clear`. The command prints the follow notice itself, once per ask. |
122
122
  | Channel configuration | `.mcp.json`, `bin/envoy-channel.ts` | Launch is `bun ${CLAUDE_PLUGIN_ROOT}/dist/envoy-channel.js`; stdout remains pure MCP protocol. The `env` block passes through `CLAUDE_PROJECT_DIR` only — an unset `${VAR}` is substituted literally, so optional inputs are inherited, never listed. |
123
123
  | Hook command | `hooks/hooks.json`, `hooks/session-hook.ts`, `hooks/session-title-hook.ts` | Two bundles. `dist/session-hook.js` takes its mode as an argument — `open-asks`, `dispatch-first` or `answers`, plus `answers-refresh`, which only the `answers` mode starts and hooks.json never names; an argument naming none of them throws — and each mode is a hook of its own, because Claude Code caps each hook's output at 10,000 characters. `open-asks` (every `SessionStart`) names the `dispatch` command's host and hands on the session's envoy.json in `CLAUDE_ENV_FILE`, records the current session id per Claude process, records the session's chosen title and injects the open-asks summary; always exits 0. For a Legion pane (`LEGION_STATE_DIR` set) it writes the pane's jj attribution overlay under that directory too, and keeps exactly one `export JJ_CONFIG='<chain>'` line in `CLAUDE_ENV_FILE`: the line replaces an earlier one in its place rather than joining it, since a resume or a compaction of the same session id runs the hook again over the file it already wrote and the chain it resolves can differ; when no overlay could be written the file is left as it is, no line written and none removed, since `CLAUDE_ENV_FILE` is one file per session id (`<config>/session-env/<session id>/sessionstart-hook-<n>.sh`, read on the pinned 2.1.311) — a `/clear` gets a new and empty one, and a line already there names this same session's own overlay, still on disk and still correct. `dispatch-first` (every `SessionStart`, and every `SubagentStart`, since a subagent runs the same `dispatch` command) injects the `dispatch-first` skill as `hookSpecificOutput.additionalContext` under the input's `hook_event_name` when Dispatch is configured, reading `${CLAUDE_PLUGIN_ROOT}/skills/dispatch-first/SKILL.md` at run time and exiting non-zero naming it when it is missing. On a resume or fork Claude Code adds a SessionStart hook's context only when the transcript does not already hold the same text (measured on 2.1.283), so a resumed session keeps one copy and one opened without the skill gets it; the hook itself checks nothing. `answers` (every `SessionStart`, and every `SubagentStart`) injects what people wrote to the session in the last 72 hours as `hookSpecificOutput.additionalContext`: `readSessionAnswers` from `@legion/envoy-client/session-answers` for the input's `session_id` (at `SubagentStart` the parent's, which `tests/answers-claude.test.ts` checks on the real binary), the list pi-envoy puts on every model request, or its failure line naming why when a read failed and no list read before has an item to show, and nothing when there is nothing to show, Dispatch answered its own `404 NOT_FOUND` "no route for …" (`isNoAnswersRoute`, which `dispatch answers` cannot read past either; the hook then writes the read's `notice`, naming that Dispatch, to stderr, one line per process), or Dispatch is not configured; a proxy's 404 page or a 200 that is no answers list is a failed read. Its bound is counted from its process's start, Bun's start-up included: it prints by `ANSWERS_BY_MS` (800 ms, `SESSION_ANSWERS_DEADLINE_MS`), or `ANSWERS_LEAST_WAIT_MS` (150 ms) after its code begins when the start-up took longer, carrying the last list read from `answers.json` in the session's Dispatch state directory (`readSessionAnswers` works it out from `env`) when Dispatch has not answered, then waits on `sessionAnswersSettled` for `ANSWERS_SETTLE_MS` (50 ms) more so a read that answered late still writes that file for the next hook, and calls `process.exit(0)` whatever happened, a malformed input included (stderr names why), so nothing still in flight holds it. Dispatch is resolved with `commands: "kept"` first; a fresh process has kept no `!` command's outcome, so when that resolution is off with an error the mode starts the refresher: this bundle again (`process.execPath`, `Bun.main`) in mode `answers-refresh` with the session id and project directory, detached (its own session, so a signal to the hook's process group does not reach it), stdio ignored (so it holds none of the hook's pipes) and `unref()`ed, unless `answers-refresh.lock` in the session's state directory names a live refresher (its pid; a lock older than 30 s, or whose pid is gone, is stale). The refresher takes that lock (`wx`; a second one exits at once, so a burst of `SubagentStart` hooks runs the command once), resolves Dispatch with commands run, so `envoy-config`'s run of the command ends in its own process with its own clean-up (the group killed at the 10 s timeout, the stdout file's directory removed), reads with a 12 s deadline (which writes `answers.json`), writes `{finished_at, dispatch_url, text, notice}` to `answers-refresh.json` and removes the lock. The hook polls that file every 20 ms until its print deadline and carries its `text`, and reports its `notice` on stderr, when it finished after the hook started; otherwise it carries the last list read from the Dispatch URL envoy.json names now (`sessionDispatchUrl`, resolved before the wait without reading the token, passed as `readSessionAnswers`' `dispatchUrl`; a list another Dispatch answered never stands in) or the failure line naming that the command had not finished, and exits, so the next hook carries the list the refresher read. Its `timeout` is 5. Measured with Dispatch hanging: about 870 ms wall from spawn to exit; healthy, about 220 ms. `dist/session-title-hook.js` (every `UserPromptSubmit`, no argument) records the payload's `session_title` — the name a person gave the session, which Claude Code hands a hook and the plugin nowhere else — under `${CLAUDE_PLUGIN_DATA}/titles/`, and removes that file when the field is absent or blank, which is how a rename is undone. It writes nothing to stdout and exits 0 whatever happens, a payload that is not JSON included (`open-asks` and `dispatch-first` still fail loudly on one), because Claude Code adds a `UserPromptSubmit` hook's stdout to the model's context and reads its exit code 2 as a block of the prompt, and a cosmetic title may do neither; a failure goes to stderr. Claude Code blocks the user's prompt on it, so it is a bundle apart from the other two and keeps zod, the Dispatch client and `session-settings` out of its import graph (`src/session-state.ts` holds the file helpers for that reason, `src/session-identity.ts` imports zod and is not reachable from here): 5 kB and ~68 ms against the shared bundle's 811 kB and ~165 ms, the latter all but 3 ms of it bare `bun` start-up. It checks the payload itself — a non-empty string `session_id`, an optional string `session_title` — rather than carry a schema library. Its `timeout` is 5, not the 20 the `open-asks` and `dispatch-first` hooks carry. |
124
124
  | Real Claude Code test | `tests/answers-claude.test.ts`, `/.claude-code-pin`, `/.github/actions/install-claude-code` | The `answers` hook on the real binary: Claude Code runs with this package as `--plugin-dir`, an isolated HOME and `CLAUDE_CONFIG_DIR`, and one stand-in as its Messages endpoint (`ANTHROPIC_BASE_URL`, server-sent events as the API streams them) and Dispatch (`DISPATCH_URL`); each case reads the list off the Messages request after the moment: startup (`claude -p --session-id`), `--resume <id>`, `/compact` sent in stream-json as `legion claude-bridge` sends turns, and a subagent (the stand-in answers with an `Agent` tool call, the API name of Claude Code's Task tool). `LEGION_TEST_CLAUDE` names the binary; the test skips without it, except on GitHub Actions, where the claude-envoy job installs the release `.claude-code-pin` pins (`bun add` into the runner's temp directory). A pin bump that changes a request shape is fixed in that file. |
package/README.md CHANGED
@@ -37,7 +37,7 @@ message from Dispatch's Agents page as that person's own turn.
37
37
  `.opencode/envoy.json`, which is not read, is one `envoy: <file> is not read: mkdir -p … && mv …`
38
38
  line while the checkout has no `.envoy/envoy.json`. The `dispatch` command reads the file
39
39
  `ENVOY_CONFIG_FILE` names whenever `DISPATCH_HOST` is set. A subagent's Bash can lack what the
40
- hook writes there (anthropics/claude-code#46696); its `dispatch` command, finding no
40
+ hook writes there (Claude Code issue 46696); its `dispatch` command, finding no
41
41
  `DISPATCH_HOST`, then takes host `claude` from the `CLAUDE_CODE_CHILD_SESSION=1` Claude Code sets
42
42
  in every Bash, and reads `CLAUDE_CONFIG_DIR` itself. With Dispatch configured,
43
43
  `dist/session-hook.js dispatch-first` puts the `dispatch-first` skill into the context of every
package/dist/dispatch.js CHANGED
@@ -27848,6 +27848,7 @@ var EXCHANGE_CLIENT_ID = "dispatch-token-exchange";
27848
27848
  var FORM_SESSION = "session";
27849
27849
  var FORM_LAUNCHER_CREDENTIAL = "launcher_credential";
27850
27850
  var FORM_LAUNCHER_CREDENTIAL_DECLINED = "false";
27851
+ var FORM_PROJECTS = "projects";
27851
27852
  var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
27852
27853
  var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
27853
27854
  var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
@@ -29341,6 +29342,7 @@ class BrokerTokenClient {
29341
29342
  #subject;
29342
29343
  #actor;
29343
29344
  #session;
29345
+ #projects;
29344
29346
  #launcherCredential;
29345
29347
  #renewBeforeMs;
29346
29348
  #now;
@@ -29357,6 +29359,7 @@ class BrokerTokenClient {
29357
29359
  this.#subject = options.subject;
29358
29360
  this.#actor = options.actor;
29359
29361
  this.#session = options.session ?? "";
29362
+ this.#projects = [...options.projects ?? []];
29360
29363
  this.#launcherCredential = options.launcherCredential ?? true;
29361
29364
  this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
29362
29365
  this.#now = options.now ?? Date.now;
@@ -29407,6 +29410,8 @@ class BrokerTokenClient {
29407
29410
  };
29408
29411
  if (this.#session !== "")
29409
29412
  form[FORM_SESSION] = this.#session;
29413
+ if (this.#projects.length > 0)
29414
+ form[FORM_PROJECTS] = this.#projects.join(" ");
29410
29415
  if (!this.#launcherCredential) {
29411
29416
  form[FORM_LAUNCHER_CREDENTIAL] = FORM_LAUNCHER_CREDENTIAL_DECLINED;
29412
29417
  }
@@ -29711,6 +29716,8 @@ var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
29711
29716
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
29712
29717
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
29713
29718
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
29719
+ var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
29720
+ var MAX_PROJECTS = 16;
29714
29721
  var POOL_AUDIENCE_VAR = "AGENT_SECRETS_POOL_AUDIENCE";
29715
29722
  var POOL_ACCOUNT_VAR = "AGENT_SECRETS_POOL_ACCOUNT";
29716
29723
  var IDENTITY_KUBERNETES = "kubernetes";
@@ -29722,6 +29729,7 @@ var BROKER_VARIABLES = [
29722
29729
  MACHINE_TOKEN_FILE_VAR,
29723
29730
  MACHINE_AUDIENCE_VAR,
29724
29731
  SESSION_VAR,
29732
+ PROJECTS_VAR,
29725
29733
  POOL_AUDIENCE_VAR,
29726
29734
  POOL_ACCOUNT_VAR,
29727
29735
  SIGNIN_DIR_VAR,
@@ -29771,6 +29779,24 @@ function tradeSession(env, own = "") {
29771
29779
  const acting = own.trim();
29772
29780
  return acting !== "" ? acting : value(env, SESSION_VAR);
29773
29781
  }
29782
+ function tradeProjects(env) {
29783
+ const keys = value(env, PROJECTS_VAR).split(/\s+/).filter((key) => key !== "");
29784
+ if (keys.length > MAX_PROJECTS) {
29785
+ throw new Error(`${PROJECTS_VAR}: ${keys.length} projects are named, and a token names at most ${MAX_PROJECTS}`);
29786
+ }
29787
+ for (const key of keys) {
29788
+ if (!PROJECT_KEY_PATTERN.test(key)) {
29789
+ throw new Error(`${PROJECTS_VAR}: "${key}" is not a project key: ${PROJECT_KEY_RULE}`);
29790
+ }
29791
+ }
29792
+ const sorted = keys.sort();
29793
+ for (let at = 1;at < sorted.length; at += 1) {
29794
+ if (sorted[at] === sorted[at - 1]) {
29795
+ throw new Error(`${PROJECTS_VAR}: ${sorted[at]} is named twice, and a list names each project once`);
29796
+ }
29797
+ }
29798
+ return sorted;
29799
+ }
29774
29800
  async function brokerTokenClient(env, own = "") {
29775
29801
  const brokerUrl = value(env, BROKER_URL_VAR);
29776
29802
  const machine = machineIdentity(env);
@@ -29796,7 +29822,8 @@ async function brokerTokenClient(env, own = "") {
29796
29822
  key: await importDpopKey(record.box_key, `${record.person}'s box key`),
29797
29823
  subject: personIdentity(record, flow),
29798
29824
  actor: machine,
29799
- session: own.trim() || signInSessionName(record)
29825
+ session: own.trim() || signInSessionName(record),
29826
+ projects: tradeProjects(env)
29800
29827
  });
29801
29828
  return { client, signIn: { person: record.person, thumbprint: record.thumbprint } };
29802
29829
  }
@@ -40579,6 +40579,7 @@ var EXCHANGE_CLIENT_ID = "dispatch-token-exchange";
40579
40579
  var FORM_SESSION = "session";
40580
40580
  var FORM_LAUNCHER_CREDENTIAL = "launcher_credential";
40581
40581
  var FORM_LAUNCHER_CREDENTIAL_DECLINED = "false";
40582
+ var FORM_PROJECTS = "projects";
40582
40583
  var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
40583
40584
  var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
40584
40585
  var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
@@ -42082,6 +42083,7 @@ class BrokerTokenClient {
42082
42083
  #subject;
42083
42084
  #actor;
42084
42085
  #session;
42086
+ #projects;
42085
42087
  #launcherCredential;
42086
42088
  #renewBeforeMs;
42087
42089
  #now;
@@ -42098,6 +42100,7 @@ class BrokerTokenClient {
42098
42100
  this.#subject = options.subject;
42099
42101
  this.#actor = options.actor;
42100
42102
  this.#session = options.session ?? "";
42103
+ this.#projects = [...options.projects ?? []];
42101
42104
  this.#launcherCredential = options.launcherCredential ?? true;
42102
42105
  this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
42103
42106
  this.#now = options.now ?? Date.now;
@@ -42148,6 +42151,8 @@ class BrokerTokenClient {
42148
42151
  };
42149
42152
  if (this.#session !== "")
42150
42153
  form[FORM_SESSION] = this.#session;
42154
+ if (this.#projects.length > 0)
42155
+ form[FORM_PROJECTS] = this.#projects.join(" ");
42151
42156
  if (!this.#launcherCredential) {
42152
42157
  form[FORM_LAUNCHER_CREDENTIAL] = FORM_LAUNCHER_CREDENTIAL_DECLINED;
42153
42158
  }
@@ -42452,6 +42457,8 @@ var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
42452
42457
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
42453
42458
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
42454
42459
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
42460
+ var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
42461
+ var MAX_PROJECTS = 16;
42455
42462
  var POOL_AUDIENCE_VAR = "AGENT_SECRETS_POOL_AUDIENCE";
42456
42463
  var POOL_ACCOUNT_VAR = "AGENT_SECRETS_POOL_ACCOUNT";
42457
42464
  var IDENTITY_KUBERNETES = "kubernetes";
@@ -42463,6 +42470,7 @@ var BROKER_VARIABLES = [
42463
42470
  MACHINE_TOKEN_FILE_VAR,
42464
42471
  MACHINE_AUDIENCE_VAR,
42465
42472
  SESSION_VAR,
42473
+ PROJECTS_VAR,
42466
42474
  POOL_AUDIENCE_VAR,
42467
42475
  POOL_ACCOUNT_VAR,
42468
42476
  SIGNIN_DIR_VAR,
@@ -42512,6 +42520,24 @@ function tradeSession(env, own = "") {
42512
42520
  const acting = own.trim();
42513
42521
  return acting !== "" ? acting : value(env, SESSION_VAR);
42514
42522
  }
42523
+ function tradeProjects(env) {
42524
+ const keys = value(env, PROJECTS_VAR).split(/\s+/).filter((key) => key !== "");
42525
+ if (keys.length > MAX_PROJECTS) {
42526
+ throw new Error(`${PROJECTS_VAR}: ${keys.length} projects are named, and a token names at most ${MAX_PROJECTS}`);
42527
+ }
42528
+ for (const key of keys) {
42529
+ if (!PROJECT_KEY_PATTERN.test(key)) {
42530
+ throw new Error(`${PROJECTS_VAR}: "${key}" is not a project key: ${PROJECT_KEY_RULE}`);
42531
+ }
42532
+ }
42533
+ const sorted = keys.sort();
42534
+ for (let at = 1;at < sorted.length; at += 1) {
42535
+ if (sorted[at] === sorted[at - 1]) {
42536
+ throw new Error(`${PROJECTS_VAR}: ${sorted[at]} is named twice, and a list names each project once`);
42537
+ }
42538
+ }
42539
+ return sorted;
42540
+ }
42515
42541
  async function brokerTokenClient(env, own = "") {
42516
42542
  const brokerUrl = value(env, BROKER_URL_VAR);
42517
42543
  const machine = machineIdentity(env);
@@ -42537,7 +42563,8 @@ async function brokerTokenClient(env, own = "") {
42537
42563
  key: await importDpopKey(record.box_key, `${record.person}'s box key`),
42538
42564
  subject: personIdentity(record, flow),
42539
42565
  actor: machine,
42540
- session: own.trim() || signInSessionName(record)
42566
+ session: own.trim() || signInSessionName(record),
42567
+ projects: tradeProjects(env)
42541
42568
  });
42542
42569
  return { client, signIn: { person: record.person, thumbprint: record.thumbprint } };
42543
42570
  }
@@ -57476,7 +57503,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
57476
57503
 
57477
57504
  // package.json
57478
57505
  var name = "@sjawhar/claude-envoy";
57479
- var version2 = "2.32.4";
57506
+ var version2 = "2.33.1";
57480
57507
  var legion = {
57481
57508
  daemonApiVersion: 144
57482
57509
  };
@@ -26691,6 +26691,7 @@ var EXCHANGE_CLIENT_ID = "dispatch-token-exchange";
26691
26691
  var FORM_SESSION = "session";
26692
26692
  var FORM_LAUNCHER_CREDENTIAL = "launcher_credential";
26693
26693
  var FORM_LAUNCHER_CREDENTIAL_DECLINED = "false";
26694
+ var FORM_PROJECTS = "projects";
26694
26695
  var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
26695
26696
  var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
26696
26697
  var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
@@ -28184,6 +28185,7 @@ class BrokerTokenClient {
28184
28185
  #subject;
28185
28186
  #actor;
28186
28187
  #session;
28188
+ #projects;
28187
28189
  #launcherCredential;
28188
28190
  #renewBeforeMs;
28189
28191
  #now;
@@ -28200,6 +28202,7 @@ class BrokerTokenClient {
28200
28202
  this.#subject = options.subject;
28201
28203
  this.#actor = options.actor;
28202
28204
  this.#session = options.session ?? "";
28205
+ this.#projects = [...options.projects ?? []];
28203
28206
  this.#launcherCredential = options.launcherCredential ?? true;
28204
28207
  this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
28205
28208
  this.#now = options.now ?? Date.now;
@@ -28250,6 +28253,8 @@ class BrokerTokenClient {
28250
28253
  };
28251
28254
  if (this.#session !== "")
28252
28255
  form[FORM_SESSION] = this.#session;
28256
+ if (this.#projects.length > 0)
28257
+ form[FORM_PROJECTS] = this.#projects.join(" ");
28253
28258
  if (!this.#launcherCredential) {
28254
28259
  form[FORM_LAUNCHER_CREDENTIAL] = FORM_LAUNCHER_CREDENTIAL_DECLINED;
28255
28260
  }
@@ -28554,6 +28559,8 @@ var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
28554
28559
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
28555
28560
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
28556
28561
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
28562
+ var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
28563
+ var MAX_PROJECTS = 16;
28557
28564
  var POOL_AUDIENCE_VAR = "AGENT_SECRETS_POOL_AUDIENCE";
28558
28565
  var POOL_ACCOUNT_VAR = "AGENT_SECRETS_POOL_ACCOUNT";
28559
28566
  var IDENTITY_KUBERNETES = "kubernetes";
@@ -28565,6 +28572,7 @@ var BROKER_VARIABLES = [
28565
28572
  MACHINE_TOKEN_FILE_VAR,
28566
28573
  MACHINE_AUDIENCE_VAR,
28567
28574
  SESSION_VAR,
28575
+ PROJECTS_VAR,
28568
28576
  POOL_AUDIENCE_VAR,
28569
28577
  POOL_ACCOUNT_VAR,
28570
28578
  SIGNIN_DIR_VAR,
@@ -28614,6 +28622,24 @@ function tradeSession(env, own = "") {
28614
28622
  const acting = own.trim();
28615
28623
  return acting !== "" ? acting : value(env, SESSION_VAR);
28616
28624
  }
28625
+ function tradeProjects(env) {
28626
+ const keys = value(env, PROJECTS_VAR).split(/\s+/).filter((key) => key !== "");
28627
+ if (keys.length > MAX_PROJECTS) {
28628
+ throw new Error(`${PROJECTS_VAR}: ${keys.length} projects are named, and a token names at most ${MAX_PROJECTS}`);
28629
+ }
28630
+ for (const key of keys) {
28631
+ if (!PROJECT_KEY_PATTERN.test(key)) {
28632
+ throw new Error(`${PROJECTS_VAR}: "${key}" is not a project key: ${PROJECT_KEY_RULE}`);
28633
+ }
28634
+ }
28635
+ const sorted = keys.sort();
28636
+ for (let at = 1;at < sorted.length; at += 1) {
28637
+ if (sorted[at] === sorted[at - 1]) {
28638
+ throw new Error(`${PROJECTS_VAR}: ${sorted[at]} is named twice, and a list names each project once`);
28639
+ }
28640
+ }
28641
+ return sorted;
28642
+ }
28617
28643
  async function brokerTokenClient(env, own = "") {
28618
28644
  const brokerUrl = value(env, BROKER_URL_VAR);
28619
28645
  const machine = machineIdentity(env);
@@ -28639,7 +28665,8 @@ async function brokerTokenClient(env, own = "") {
28639
28665
  key: await importDpopKey(record.box_key, `${record.person}'s box key`),
28640
28666
  subject: personIdentity(record, flow),
28641
28667
  actor: machine,
28642
- session: own.trim() || signInSessionName(record)
28668
+ session: own.trim() || signInSessionName(record),
28669
+ projects: tradeProjects(env)
28643
28670
  });
28644
28671
  return { client, signIn: { person: record.person, thumbprint: record.thumbprint } };
28645
28672
  }
@@ -10,7 +10,7 @@
10
10
  // `CLAUDE_ENV_FILE`, which Claude Code sources into every later Bash command of the session,
11
11
  // each unless an earlier SessionStart already wrote that line there. The `dispatch` command
12
12
  // reads the file ENVOY_CONFIG_FILE names whenever DISPATCH_HOST is set. A subagent's Bash can
13
- // lack what that file holds (anthropics/claude-code#46696); the `dispatch` command it runs then
13
+ // lack what that file holds (Claude Code issue 46696); the `dispatch` command it runs then
14
14
  // takes host `claude` from `CLAUDE_CODE_CHILD_SESSION=1` and reads `CLAUDE_CONFIG_DIR` itself.
15
15
  // The path is single-quoted (`singleQuoted`, whose doc gives what Claude Code's
16
16
  // PowerShell bridge reads of that form). The command reads the session id from `CLAUDE_CODE_SESSION_ID`, which
@@ -53,7 +53,7 @@ Read each by its `skill://` link: a read by path stops at 300 lines.
53
53
 
54
54
  ## Every role pushes its own commits
55
55
 
56
- - Before a push, run the trailer check (`skill://legion-worker/references/default-branch-check.md`) and then, with the `$default` it set, read your branch's own commit messages: `jj -R "$LEGION_WORKSPACE" log -r "${default}@origin..@" -T 'description ++ "\n"'` — earlier phases' commits in it are expected; never `ancestors(@, 5)`, which stops at five commits while a branch can hold more, and never `description.first_line()`, which shows no trailer. Invent no trailer of your own: the pane's jj appends `Omp-Session:` and `Legion-Role:` to every commit the pane's shell makes, in any jj repository, and, for a repository the deployment names, the issue line `Dispatch: <KEY>` beside them, that one scoped to the pane's own workspace. A `git commit` gets the same two lines, and no issue line, from the git wrapper. A jj repository you clone or create under that workspace is stamped like the workspace, so a commit you make in one carries this deployment's issue key: clone a repository you will push elsewhere outside `$LEGION_WORKSPACE`, and push no commit made under it to a repository that takes no issue key. Four kinds of commit get none of these lines added: one that another process made outside the pane's shell with no overlay, one that a git command made without `git commit` (a merge, a revert, a cherry-pick, a rebase), a `git commit` where the git whose version the wrapper reads is older than 2.32 (the first git with `git commit --trailer`; cybermonklabs/legion `docs/deployment.md` says which git that is), and, on the Claude harness, a jj commit of a subagent's bash that lacks the session's environment file (anthropics/claude-code#46696, which `packages/claude-envoy/hooks/session-hook.ts` records and ships a `dispatch` fallback for). That subagent's `git commit` still carries the role line. A commit of yours that shows a line short is cured by describing it again, since the trailers are appended when a description is set. A re-describe appends the issue line only where the shell it runs in has the pane's jj config overlay, so it adds nothing in a shell that carries none — a subagent's bash, or a pane whose overlay the writer could not make. Where it adds nothing, write the line yourself: put `Dispatch: $LEGION_ISSUE_TRAILER` into the description as a trailer line of its own, and only when `LEGION_ISSUE_TRAILER` is set, since that variable is the deployment's own name for the key this repository takes, and an unset one means the repository takes no key and the line belongs in no commit of it. Look because a base branch can require the issue line in the commit that lands: a squash builds that message from the branch's commit messages, and it leaves a merge commit's message out, so the line belongs in an ordinary commit.
56
+ - Before a push, run the trailer check (`skill://legion-worker/references/default-branch-check.md`) and then, with the `$default` it set, read your branch's own commit messages: `jj -R "$LEGION_WORKSPACE" log -r "${default}@origin..@" -T 'description ++ "\n"'` — earlier phases' commits in it are expected; never `ancestors(@, 5)`, which stops at five commits while a branch can hold more, and never `description.first_line()`, which shows no trailer. Invent no trailer of your own: the pane's jj appends `Omp-Session:` and `Legion-Role:` to every commit the pane's shell makes, in any jj repository, and, for a repository the deployment names, the issue line `Dispatch: <KEY>` beside them, that one scoped to the pane's own workspace. A `git commit` gets the same two lines, and no issue line, from the git wrapper. A jj repository you clone or create under that workspace is stamped like the workspace, so a commit you make in one carries this deployment's issue key: clone a repository you will push elsewhere outside `$LEGION_WORKSPACE`, and push no commit made under it to a repository that takes no issue key. Four kinds of commit get none of these lines added: one that another process made outside the pane's shell with no overlay, one that a git command made without `git commit` (a merge, a revert, a cherry-pick, a rebase), a `git commit` where the git whose version the wrapper reads is older than 2.32 (the first git with `git commit --trailer`; cybermonklabs/legion `docs/deployment.md` says which git that is), and, on the Claude harness, a jj commit of a subagent's bash that lacks the session's environment file (Claude Code issue 46696, which `packages/claude-envoy/hooks/session-hook.ts` records and ships a `dispatch` fallback for). That subagent's `git commit` still carries the role line. A commit of yours that shows a line short is cured by describing it again, since the trailers are appended when a description is set. A re-describe appends the issue line only where the shell it runs in has the pane's jj config overlay, so it adds nothing in a shell that carries none — a subagent's bash, or a pane whose overlay the writer could not make. Where it adds nothing, write the line yourself: put `Dispatch: $LEGION_ISSUE_TRAILER` into the description as a trailer line of its own, and only when `LEGION_ISSUE_TRAILER` is set, since that variable is the deployment's own name for the key this repository takes, and an unset one means the repository takes no key and the line belongs in no commit of it. Look because a base branch can require the issue line in the commit that lands: a squash builds that message from the branch's commit messages, and it leaves a merge commit's message out, so the line belongs in an ordinary commit.
57
57
  - Only work is pushed: code, red tests, a forward merge, and the empty commit that carries the pull request onto the commit you pushed (the bullet below). No commit message carries a line or bracket keyword that stops GitHub's workflows (`[skip ci]` and its kin), since every head needs its own checks and a base that requires a check will not merge a head whose checks never ran. Retro pushes nothing: it records what the work taught with `dispatch comment` on the issue.
58
58
  - **After a push, read the pull request's head and check that it is your commit.** A branch and a pull request are two objects on GitHub: the push moves the branch, and GitHub then moves the pull request onto the new commit, which is what starts its checks, and a push GitHub does not follow leaves the newer commit with no checks while Legion reads and tests the older one. The step applies once the branch has an open pull request, whose number your task's `Pull request:` line names (`gh pr list --repo <the issue's repository> --head legion/<KEY> --state open --json number --jq '.[0].number'` when it names none): run `gh pr view <n> --repo <the issue's repository> --json headRefOid --jq .headRefOid` about ten seconds after your push, again about ten seconds later, and a last time about thirty seconds after that, with a read that gives the pushed commit ending the step there and only the last read deciding a mismatch, and compare each answer with the commit you pushed, which `jj -R "$LEGION_WORKSPACE" log -r legion/<KEY>@origin --no-graph -T commit_id` prints in the 40 characters `headRefOid` answers in. This read is of the pull request's own head and of no check, so the wait it makes is not a wait on CI (`skill://legion-worker/references/pr-body.md#never-waiting-on-ci`). When the last read still is not your commit, carry the pull request with a commit of its own, an empty one when your work is complete and an empty one just as much when `@` holds work of yours, since a push of a commit the branch already holds moves no ref; the push section of your role prompt gives the one `jj` recipe, which leaves `@` and everything in it where it is. A new head is a different commit, so record each `before_merge` check again at the new head. A check carrying `ci_check` is CI's, so skip it. When that second push does not carry the pull request either, tell your architect the commit you pushed, the head each read gave and the time of each, and end the turn with a WAITING line naming that answer rather than completing: a phase completed here hands the next role a commit the pull request does not name. The push you make to answer an update message is the exception: that message has you answer the daemon and end the turn at once, so make this read in your next turn, before your phase completes. The merger pushes nothing, so this step never falls to it; it reports a mismatch it sees to the architect.
59
59
  - A planner whose issue moved back from implementing starts on the remote tip, `jj -R "$LEGION_WORKSPACE" new legion/<KEY>@origin`, so a commit it makes never sits on the implementer's unpushed commits.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "2.32.4",
3
+ "version": "2.33.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -178,9 +178,10 @@ after it means the command could not start, and the status is 1.
178
178
  Without the grant line the status is the client's own:
179
179
 
180
180
  - **1** — a refusal or a failure that the message names: a name the broker does not serve
181
- (`UNKNOWN_SECRET`), a broker it cannot reach, a machine that is not logged in to the broker, a
182
- request cancelled or expired, `REQUEST_PENDING`, a grant that is no longer live, or a command
183
- that is not on `PATH`.
181
+ (`UNKNOWN_SECRET`), a secret that waits for its first value (`PENDING_VALUE`), a broker it cannot
182
+ reach, a machine that is not logged in to the broker, a request cancelled or expired,
183
+ `REQUEST_PENDING`, a grant that is no longer live, or a command that is not on `PATH`, which is
184
+ refused before the broker is asked anything, so it reaches no approver.
184
185
  - **2** — a usage error: no broker identity at all (no key in the key dir and no helper socket), no
185
186
  `AGENT_SECRETS_URL`, no `--`, no `NAME`, or a flag value the client refuses.
186
187
  - **75** — the request still waits for a person. The message names who decides it, where, and the
@@ -234,6 +235,17 @@ prompt, a skill, or the issue you work on. There is no list to browse and nothin
234
235
  secret exists is recorded against your session with the reason you signed, and it reaches a
235
236
  person's Inbox unless the model judge decides it first.
236
237
  - `UNKNOWN_SECRET` and a denial are final. Do not ask again, and do not try a name of your own.
238
+ - `PENDING_VALUE` is not final: the secret exists, and its owner is storing its value with
239
+ `agent-secrets secret create` now. No request was made and no approver asked. Ask again in a few
240
+ minutes. After ten minutes the broker stops calling it pending and refuses the name
241
+ `UNKNOWN_SECRET`: the create that made it deletes it when its prompt ends, at ten minutes or,
242
+ where its owner was still typing then, when that entry ends; a create that was killed deletes
243
+ nothing, and the secret stays in the store with no value. Tell its
244
+ owner, who sees it as `versions: none` in `agent-secrets secret show NAME`. The owner frees the
245
+ name with `gcloud secrets delete <id> --project <project number>` (`<id>` is the part after
246
+ `secrets/` of the `secret_name` that `show` prints), or stores the value with
247
+ `agent-secrets secret set NAME`. `agent-secrets secret delete NAME` only schedules the deletion
248
+ 30 days out, and until then the name stays taken, so the next `secret create` of it is refused.
237
249
  - A secret that a service owns goes to that service's own pods and VMs and to nothing else:
238
250
  `Evaluate` in `packages/envoy/internal/broker/policy/policy.go` grants a service-owned secret at
239
251
  once when the session's own service is the secret's owner, and denies every other session, with
@@ -276,7 +288,10 @@ the Application Default Credentials, else the gcloud login; on AWS, `--profile`,
276
288
  the email of the person the credential names, and is refused where it names none, as a token
277
289
  minted for `cloud-platform` alone does: give `--owner <email>` there. Both read the value from
278
290
  standard input or from a prompt with echo off, never from an argument. Type it at the prompt, so it
279
- reaches no shell history.
291
+ reaches no shell history. On Google Cloud, `create` makes the secret before it asks for the value,
292
+ so a store that refuses the create asks for none. Until the value is added, a failure or a signal
293
+ deletes that empty secret again, except where the store's answer leaves open whether it stored the
294
+ value: then `create` keeps the secret, exits 1, and names `agent-secrets secret show NAME` to check.
280
295
 
281
296
  ## A worked example: one page of a Slack thread
282
297