@sjawhar/claude-envoy 4.21.2 → 4.22.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.21.2"
5
+ "version": "4.22.0"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "4.21.2",
3
+ "version": "4.22.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
@@ -532,15 +532,28 @@ token beside it, and its token only beside its own server. An `envoy` section in
532
532
  file is not read, which the channel server's notice says, and a checkout's file that is not valid
533
533
  refuses Dispatch alone, only while `DISPATCH_URL` is unset. The chosen file's `dispatch` section
534
534
  (`enabled`, `serverUrl`, `token`) and `envoy` section (`enabled`, `url`, `natsUrls`, `token`,
535
- `natsSeed`, `natsAuth`) are resolved each on its own; `enabled: false` turns one off, a missing file
536
- contributes nothing (each section is then on only when its variables name it), and a `token` or
537
- `natsSeed` starting with `!` is a command whose trimmed output is the value. `DISPATCH_URL`,
538
- `DISPATCH_TOKEN_FILE`, `DISPATCH_TOKEN`, `ENVOY_URL`, `ENVOY_NATS_URL`, `ENVOY_TOKEN_FILE`,
539
- `ENVOY_TOKEN`, `NATS_NKEY_SEED_FILE`, `NATS_NKEY_SEED` and `NATS_AUTH` each override their own
540
- field; a file's token or seed goes with a variable's server only when it is the file's own. With
535
+ `natsSeed`, `natsAuth`, `inbound`) are resolved each on its own; `enabled: false` turns one off, a
536
+ missing file contributes nothing (each section is then on only when its variables name it), and a
537
+ `token` or `natsSeed` starting with `!` is a command whose trimmed output is the value.
538
+ `DISPATCH_URL`, `DISPATCH_TOKEN_FILE`, `DISPATCH_TOKEN`, `ENVOY_URL`, `ENVOY_NATS_URL`,
539
+ `ENVOY_TOKEN_FILE`, `ENVOY_TOKEN`, `NATS_NKEY_SEED_FILE`, `NATS_NKEY_SEED`, `NATS_AUTH` and
540
+ `ENVOY_INBOUND` each override their own field; a file's token or seed goes with a variable's server
541
+ only when it is the file's own. With
541
542
  `NATS_AUTH=broker` and no seed the NATS connection presents the session's own broker token, which
542
543
  a hub's NATS auth service admits to that session's subjects alone, and a `/clear` moves it to the
543
- new id's token before the new id's relay subject is subscribed. The `open-asks` hook
544
+ new id's token before the new id's relay subject is subscribed. With `ENVOY_INBOUND=listener` (or
545
+ `"inbound": "listener"`), a Claude Code or Codex session takes its inbound messages through the
546
+ listener's relay socket, `<ENVOY_URL>/v1/sessions/<id>/relay`, over HTTPS alone, with the session's
547
+ own broker token, rather than over NATS, and a `/clear` or `/new` opens the socket again for the
548
+ new id; it is refused beside `ENVOY_NATS_URL` or `envoy.natsUrls`, naming both, with a bearer for
549
+ the listener, with no broker route, and for a process that names no session. With the setting, a
550
+ listener at a plain http address of another machine turns Envoy off as a whole, its tools
551
+ included, a NATS server named or not (the token would cross the network unencrypted; a conflict
552
+ with a NATS server is named first; this machine's own listener may be plain http, and a session
553
+ not set to `listener` keeps plain http). The
554
+ socket carries no agent stream, so neither live view
555
+ takes its control subject and the Agents page shows nothing of the session's turns, which the
556
+ start notice says. The `open-asks` hook
544
557
  hands the file on to the session's Bash as `ENVOY_CONFIG_FILE` beside `DISPATCH_HOST=claude`, and
545
558
  the `dispatch` command reads the file `ENVOY_CONFIG_FILE` names whenever `DISPATCH_HOST` is set; a
546
559
  Bash with neither, as a subagent's can be, has `CLAUDE_CODE_CHILD_SESSION=1` and takes this plugin's
@@ -19217,7 +19217,8 @@ var EnvoySectionSchema = strictObject({
19217
19217
  natsUrls: array(string2().trim().min(1, "must not be empty")).optional(),
19218
19218
  token: string2().optional(),
19219
19219
  natsSeed: string2().optional(),
19220
- natsAuth: string2().optional()
19220
+ natsAuth: string2().optional(),
19221
+ inbound: string2().optional()
19221
19222
  });
19222
19223
  var EnvoyFileSchema = looseObject({
19223
19224
  $schema: string2().optional(),
@@ -29778,6 +29779,7 @@ function resolvedInterval(raw, fallback) {
29778
29779
  const named = namedInterval(raw);
29779
29780
  return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
29780
29781
  }
29782
+ var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
29781
29783
  function natsSeedFromEnvironment(env) {
29782
29784
  const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
29783
29785
  if (file !== undefined) {
@@ -29847,6 +29849,33 @@ function natsCredential(env, section, namedNatsUrls, filePath, session) {
29847
29849
  throw new NoSessionNamedError(auth.source);
29848
29850
  return { kind: "broker", broker: brokerNatsCredential(env, session, auth.source) };
29849
29851
  }
29852
+ var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
29853
+ function natsConflictText(source, natsSetting) {
29854
+ return `${source} is listener, and ${natsSetting} names NATS servers: set one of the two`;
29855
+ }
29856
+ function listenerInbound(source, natsSetting, credential, session) {
29857
+ if (natsSetting !== undefined)
29858
+ return { off: natsConflictText(source, natsSetting) };
29859
+ if ("noBrokerRoute" in credential) {
29860
+ return { off: `${source} is listener, but ${credential.noBrokerRoute}` };
29861
+ }
29862
+ if (credential.scheme !== "DPoP") {
29863
+ return {
29864
+ off: `${source} is listener, but the listener's credential is a bearer (ENVOY_TOKEN, ENVOY_TOKEN_FILE or envoy.token), and the relay socket admits only the session's broker token`
29865
+ };
29866
+ }
29867
+ if (session === undefined) {
29868
+ return {
29869
+ off: `${source} is listener, but this process names no session for its relay socket's token`,
29870
+ noSessionNamed: true
29871
+ };
29872
+ }
29873
+ return { relaySetting: source, relayCredential: credential };
29874
+ }
29875
+ function plainHttpOffMachine(url) {
29876
+ const host = URL.canParse(url) ? new URL(url) : undefined;
29877
+ return host?.protocol === "http:" && !LOOPBACK_HOST.test(host.hostname) ? host.hostname : undefined;
29878
+ }
29850
29879
  function envoySettings(env, config, options = {}) {
29851
29880
  if (config.kind === "failed")
29852
29881
  return offWithError(config.error);
@@ -29865,7 +29894,18 @@ function envoySettings(env, config, options = {}) {
29865
29894
  }
29866
29895
  const listener = section.url ?? DEFAULT_ENVOY_URL;
29867
29896
  const url = namedUrl ?? listener;
29897
+ const namedInbound = nonEmpty(env.ENVOY_INBOUND);
29898
+ const choice = namedInbound !== undefined ? { value: namedInbound, source: ENVOY_INBOUND_VAR } : section.inbound === undefined ? undefined : { value: section.inbound, source: `envoy.inbound in ${config.path}` };
29899
+ const natsSetting = namedNatsUrls.length > 0 ? "ENVOY_NATS_URL" : (section.natsUrls ?? []).length > 0 ? `envoy.natsUrls in ${config.path}` : undefined;
29900
+ if (choice?.value === "listener") {
29901
+ const host = plainHttpOffMachine(url);
29902
+ if (host !== undefined) {
29903
+ const plainHttp = `the listener's address is plain http to ${host}, which is not this machine, so the session's token would cross the network unencrypted; use an https address`;
29904
+ return offWithError(natsSetting === undefined ? `${choice.source} is listener, but ${plainHttp}` : `${natsConflictText(choice.source, natsSetting)}. And ${plainHttp}`);
29905
+ }
29906
+ }
29868
29907
  let credential;
29908
+ let noBrokerRoute = "";
29869
29909
  try {
29870
29910
  const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
29871
29911
  token: section.token,
@@ -29875,7 +29915,10 @@ function envoySettings(env, config, options = {}) {
29875
29915
  checkout: false
29876
29916
  });
29877
29917
  if (source.kind === "none") {
29878
- credential = brokerRouteConfigured(env).traded ? brokerCredential(env, options.session) : undefined;
29918
+ const route = brokerRouteConfigured(env);
29919
+ credential = route.traded ? brokerCredential(env, options.session) : undefined;
29920
+ if (!route.traded)
29921
+ noBrokerRoute = route.gap;
29879
29922
  } else {
29880
29923
  credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
29881
29924
  }
@@ -29886,13 +29929,17 @@ function envoySettings(env, config, options = {}) {
29886
29929
  let inbound;
29887
29930
  if (options.nats === false)
29888
29931
  inbound = { off: NO_NATS_CONNECTION };
29889
- else if (natsUrls.length === 0)
29932
+ else if (choice !== undefined && choice.value !== "nats" && choice.value !== "listener") {
29933
+ inbound = { off: `${choice.source} is neither nats nor listener` };
29934
+ } else if (choice?.value === "listener") {
29935
+ inbound = listenerInbound(choice.source, natsSetting, credential ?? { noBrokerRoute }, options.session);
29936
+ } else if (natsSetting === undefined)
29890
29937
  inbound = { off: NO_NATS_SERVER };
29891
29938
  else {
29892
29939
  try {
29893
29940
  inbound = {
29894
29941
  natsUrls,
29895
- natsServersSetting: namedNatsUrls.length > 0 ? "ENVOY_NATS_URL" : `envoy.natsUrls in ${config.path}`,
29942
+ natsServersSetting: natsSetting,
29896
29943
  natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
29897
29944
  };
29898
29945
  } catch (error) {
@@ -29969,6 +30016,9 @@ function startNotice(config, dispatch, envoy, nats, lost) {
29969
30016
  if (envoy.enabled && nats && "off" in envoy.inbound) {
29970
30017
  parts.push(`Envoy's inbound messages are off: ${envoy.inbound.off}; the Envoy tools still work`);
29971
30018
  }
30019
+ if (envoy.enabled && nats && "relaySetting" in envoy.inbound) {
30020
+ parts.push(`Envoy's inbound messages come through the listener's relay socket (${envoy.inbound.relaySetting} is listener), which carries no live view: the Agents page shows nothing of this session's turns`);
30021
+ }
29972
30022
  if (envoy.enabled && envoy.passDeadlineRaisedFrom !== undefined) {
29973
30023
  parts.push(`Envoy's pass deadline is ${envoy.passDeadlineMs} ms, not the ${envoy.passDeadlineRaisedFrom} ms ENVOY_PASS_DEADLINE_MS names: a deadline inside one ${envoy.heartbeatMs} ms heartbeat interval would abandon every pass before the next tick, so the registration refresh the heartbeat posts for a stalled pass would never run`);
29974
30024
  }
package/dist/dispatch.js CHANGED
@@ -19470,7 +19470,8 @@ var EnvoySectionSchema = strictObject({
19470
19470
  natsUrls: array(string2().trim().min(1, "must not be empty")).optional(),
19471
19471
  token: string2().optional(),
19472
19472
  natsSeed: string2().optional(),
19473
- natsAuth: string2().optional()
19473
+ natsAuth: string2().optional(),
19474
+ inbound: string2().optional()
19474
19475
  });
19475
19476
  var EnvoyFileSchema = looseObject({
19476
19477
  $schema: string2().optional(),
@@ -31027,6 +31028,7 @@ function resolvedInterval(raw, fallback) {
31027
31028
  const named = namedInterval(raw);
31028
31029
  return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
31029
31030
  }
31031
+ var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
31030
31032
  function natsSeedFromEnvironment(env) {
31031
31033
  const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
31032
31034
  if (file !== undefined) {
@@ -31096,6 +31098,33 @@ function natsCredential(env, section, namedNatsUrls, filePath, session) {
31096
31098
  throw new NoSessionNamedError(auth.source);
31097
31099
  return { kind: "broker", broker: brokerNatsCredential(env, session, auth.source) };
31098
31100
  }
31101
+ var LOOPBACK_HOST = /^(localhost|127(\.\d{1,3}){3}|\[::1\])$/i;
31102
+ function natsConflictText(source, natsSetting) {
31103
+ return `${source} is listener, and ${natsSetting} names NATS servers: set one of the two`;
31104
+ }
31105
+ function listenerInbound(source, natsSetting, credential, session) {
31106
+ if (natsSetting !== undefined)
31107
+ return { off: natsConflictText(source, natsSetting) };
31108
+ if ("noBrokerRoute" in credential) {
31109
+ return { off: `${source} is listener, but ${credential.noBrokerRoute}` };
31110
+ }
31111
+ if (credential.scheme !== "DPoP") {
31112
+ return {
31113
+ off: `${source} is listener, but the listener's credential is a bearer (ENVOY_TOKEN, ENVOY_TOKEN_FILE or envoy.token), and the relay socket admits only the session's broker token`
31114
+ };
31115
+ }
31116
+ if (session === undefined) {
31117
+ return {
31118
+ off: `${source} is listener, but this process names no session for its relay socket's token`,
31119
+ noSessionNamed: true
31120
+ };
31121
+ }
31122
+ return { relaySetting: source, relayCredential: credential };
31123
+ }
31124
+ function plainHttpOffMachine(url) {
31125
+ const host = URL.canParse(url) ? new URL(url) : undefined;
31126
+ return host?.protocol === "http:" && !LOOPBACK_HOST.test(host.hostname) ? host.hostname : undefined;
31127
+ }
31099
31128
  function envoySettings(env, config, options = {}) {
31100
31129
  if (config.kind === "failed")
31101
31130
  return offWithError(config.error);
@@ -31114,7 +31143,18 @@ function envoySettings(env, config, options = {}) {
31114
31143
  }
31115
31144
  const listener = section.url ?? DEFAULT_ENVOY_URL;
31116
31145
  const url = namedUrl ?? listener;
31146
+ const namedInbound = nonEmpty(env.ENVOY_INBOUND);
31147
+ const choice = namedInbound !== undefined ? { value: namedInbound, source: ENVOY_INBOUND_VAR } : section.inbound === undefined ? undefined : { value: section.inbound, source: `envoy.inbound in ${config.path}` };
31148
+ const natsSetting = namedNatsUrls.length > 0 ? "ENVOY_NATS_URL" : (section.natsUrls ?? []).length > 0 ? `envoy.natsUrls in ${config.path}` : undefined;
31149
+ if (choice?.value === "listener") {
31150
+ const host = plainHttpOffMachine(url);
31151
+ if (host !== undefined) {
31152
+ const plainHttp = `the listener's address is plain http to ${host}, which is not this machine, so the session's token would cross the network unencrypted; use an https address`;
31153
+ return offWithError(natsSetting === undefined ? `${choice.source} is listener, but ${plainHttp}` : `${natsConflictText(choice.source, natsSetting)}. And ${plainHttp}`);
31154
+ }
31155
+ }
31117
31156
  let credential;
31157
+ let noBrokerRoute = "";
31118
31158
  try {
31119
31159
  const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
31120
31160
  token: section.token,
@@ -31124,7 +31164,10 @@ function envoySettings(env, config, options = {}) {
31124
31164
  checkout: false
31125
31165
  });
31126
31166
  if (source.kind === "none") {
31127
- credential = brokerRouteConfigured(env).traded ? brokerCredential(env, options.session) : undefined;
31167
+ const route = brokerRouteConfigured(env);
31168
+ credential = route.traded ? brokerCredential(env, options.session) : undefined;
31169
+ if (!route.traded)
31170
+ noBrokerRoute = route.gap;
31128
31171
  } else {
31129
31172
  credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
31130
31173
  }
@@ -31135,13 +31178,17 @@ function envoySettings(env, config, options = {}) {
31135
31178
  let inbound;
31136
31179
  if (options.nats === false)
31137
31180
  inbound = { off: NO_NATS_CONNECTION };
31138
- else if (natsUrls.length === 0)
31181
+ else if (choice !== undefined && choice.value !== "nats" && choice.value !== "listener") {
31182
+ inbound = { off: `${choice.source} is neither nats nor listener` };
31183
+ } else if (choice?.value === "listener") {
31184
+ inbound = listenerInbound(choice.source, natsSetting, credential ?? { noBrokerRoute }, options.session);
31185
+ } else if (natsSetting === undefined)
31139
31186
  inbound = { off: NO_NATS_SERVER };
31140
31187
  else {
31141
31188
  try {
31142
31189
  inbound = {
31143
31190
  natsUrls,
31144
- natsServersSetting: namedNatsUrls.length > 0 ? "ENVOY_NATS_URL" : `envoy.natsUrls in ${config.path}`,
31191
+ natsServersSetting: natsSetting,
31145
31192
  natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
31146
31193
  };
31147
31194
  } catch (error) {
@@ -31218,6 +31265,9 @@ function startNotice(config, dispatch, envoy, nats, lost) {
31218
31265
  if (envoy.enabled && nats && "off" in envoy.inbound) {
31219
31266
  parts.push(`Envoy's inbound messages are off: ${envoy.inbound.off}; the Envoy tools still work`);
31220
31267
  }
31268
+ if (envoy.enabled && nats && "relaySetting" in envoy.inbound) {
31269
+ parts.push(`Envoy's inbound messages come through the listener's relay socket (${envoy.inbound.relaySetting} is listener), which carries no live view: the Agents page shows nothing of this session's turns`);
31270
+ }
31221
31271
  if (envoy.enabled && envoy.passDeadlineRaisedFrom !== undefined) {
31222
31272
  parts.push(`Envoy's pass deadline is ${envoy.passDeadlineMs} ms, not the ${envoy.passDeadlineRaisedFrom} ms ENVOY_PASS_DEADLINE_MS names: a deadline inside one ${envoy.heartbeatMs} ms heartbeat interval would abandon every pass before the next tick, so the registration refresh the heartbeat posts for a stalled pass would never run`);
31223
31273
  }
@@ -31404,6 +31454,7 @@ var ErrorWireSchema = object({
31404
31454
  error: string2(),
31405
31455
  code: string2().optional(),
31406
31456
  reason: string2().optional(),
31457
+ refused: array(string2()).optional(),
31407
31458
  expected: array(string2()).optional(),
31408
31459
  state: SessionStateSchema.optional(),
31409
31460
  holder: string2().optional(),
@@ -31520,6 +31571,7 @@ class EnvoyApiError extends Error {
31520
31571
  lastSeen;
31521
31572
  claimReleased;
31522
31573
  retryAfterSeconds;
31574
+ refused;
31523
31575
  constructor(details, shown = {}) {
31524
31576
  let parsed;
31525
31577
  try {
@@ -31538,6 +31590,7 @@ class EnvoyApiError extends Error {
31538
31590
  this.lastSeen = parsed?.last_seen;
31539
31591
  this.claimReleased = parsed?.claim_released;
31540
31592
  this.retryAfterSeconds = parsed?.retry_after_seconds;
31593
+ this.refused = parsed?.refused;
31541
31594
  }
31542
31595
  }
31543
31596
  var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);