@sjawhar/claude-envoy 5.27.1 → 5.28.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.
@@ -981,7 +981,7 @@ __export(exports_coerce, {
981
981
 
982
982
  // hooks/session-hook.ts
983
983
  import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync6, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
984
- import { join as join11 } from "path";
984
+ import { join as join12 } from "path";
985
985
 
986
986
  // ../cipher-client/src/device-login-file.ts
987
987
  import { createPrivateKey, randomUUID as randomUUID2 } from "crypto";
@@ -17152,6 +17152,7 @@ var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
17152
17152
  function uncapturedTopicRefusal(topic, sessionID) {
17153
17153
  return `${topic} was not registered: no stream subject captures it, so nothing would be delivered to ${sessionID} on it; follow a notifications.team.<name> topic instead`;
17154
17154
  }
17155
+ var MESSAGE_NOT_SENT_PREFIX = "envoy: the message was not sent, and may be sent again later";
17155
17156
 
17156
17157
  // ../contracts/src/legion-roles.ts
17157
17158
  var LEGION_ROLES = [
@@ -17986,6 +17987,25 @@ var projectKeyValidation = {
17986
17987
  message: `project is not a project key: ${PROJECT_KEY_RULE}`
17987
17988
  };
17988
17989
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
17990
+ var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
17991
+ var API_PATH_RULE = "path is a route under /api/v1: it begins /api/v1 and names no scheme or host, every character is printable ASCII other than a space, a backslash and #, and no segment before the query is . or ..";
17992
+ function apiPathProblem(value) {
17993
+ const { path } = value;
17994
+ if (typeof path !== "string")
17995
+ return;
17996
+ const named = JSON.stringify(path);
17997
+ if (!API_ROUTE_PATTERN.test(path)) {
17998
+ return `path ${named} is no route under /api/v1: give the route alone, beginning /api/v1, with no scheme or host (dispatch api --path /api/v1 lists every route).`;
17999
+ }
18000
+ if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
18001
+ return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
18002
+ }
18003
+ const route = path.split("?", 1)[0] ?? "";
18004
+ if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
18005
+ return `path ${named} holds a . or .. segment: name the route itself.`;
18006
+ }
18007
+ return;
18008
+ }
17989
18009
  var ISSUE_STATUSES = [
17990
18010
  "triage",
17991
18011
  "icebox",
@@ -18591,6 +18611,20 @@ var dispatchToolSpecs = [
18591
18611
  arguments: () => ({}),
18592
18612
  strict: true
18593
18613
  },
18614
+ {
18615
+ name: "dispatch_api",
18616
+ example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
18617
+ description: "Read one route of Dispatch's HTTP API that no other command reads, with this session's own credential, and print Dispatch's JSON answer, for jq to read. It sends one GET of path: a route beginning /api/v1, with its query after ?; dispatch api --path /api/v1 lists every route. It only reads: it takes no method and no body, and every write goes through the command named for it (dispatch --help lists them). When Dispatch refuses the read, the command prints Dispatch's error with its code and, where Dispatch gives one, its hint, and exits 1. Under Claude Code, an answer longer than the output limit is written to a file the output names.",
18618
+ arguments: (z) => ({
18619
+ path: z.string({ min: 1 }).describe("The route to read, beginning /api/v1, with its query after ?, such as /api/v1/issues/ACME-12/events?limit=200. No scheme or host, and no . or .. segment.")
18620
+ }),
18621
+ validation: {
18622
+ check: (value) => apiPathProblem(value) === undefined,
18623
+ message: API_PATH_RULE,
18624
+ refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
18625
+ },
18626
+ strict: true
18627
+ },
18594
18628
  {
18595
18629
  name: "dispatch_handoff_write",
18596
18630
  example: {
@@ -20807,17 +20841,19 @@ function zodSchemaApi(zod) {
20807
20841
  };
20808
20842
  }
20809
20843
  // ../envoy-client/src/errors.ts
20810
- function dispatchCode(error) {
20811
- if (!("fromDispatch" in error) || !("code" in error))
20844
+ function dispatchField(error, field) {
20845
+ if (!("fromDispatch" in error))
20812
20846
  return;
20813
- const code = error.code;
20814
- return typeof code === "string" && code !== "" ? code : undefined;
20847
+ const value = Reflect.get(error, field);
20848
+ return typeof value === "string" && value !== "" ? value : undefined;
20815
20849
  }
20816
20850
  function messageFor(error) {
20817
20851
  if (!(error instanceof Error))
20818
20852
  return scrub(String(error));
20819
- const code = dispatchCode(error);
20820
- return scrub(code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`);
20853
+ const code = dispatchField(error, "code");
20854
+ const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
20855
+ const hint = dispatchField(error, "hint");
20856
+ return scrub(hint === undefined ? message : `${message}; ${hint}`);
20821
20857
  }
20822
20858
  function hasErrnoCode(error, code) {
20823
20859
  return error instanceof Error && "code" in error && error.code === code;
@@ -24175,6 +24211,7 @@ class DispatchServiceError extends Error {
24175
24211
  mismatches;
24176
24212
  issues;
24177
24213
  changed;
24214
+ hint;
24178
24215
  constructor(code, status, message, details = {}) {
24179
24216
  super(message);
24180
24217
  this.code = code;
@@ -24184,6 +24221,7 @@ class DispatchServiceError extends Error {
24184
24221
  this.mismatches = details.mismatches;
24185
24222
  this.issues = details.issues;
24186
24223
  this.changed = details.changed;
24224
+ this.hint = details.hint;
24187
24225
  }
24188
24226
  }
24189
24227
 
@@ -24673,6 +24711,10 @@ class DispatchClient {
24673
24711
  async limits() {
24674
24712
  return this.#json("GET", ["api", "v1", "limits"]);
24675
24713
  }
24714
+ async readRoute(path) {
24715
+ const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
24716
+ return this.#response("GET", url, await this.#send("GET", url));
24717
+ }
24676
24718
  async inbox(assignee) {
24677
24719
  return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
24678
24720
  }
@@ -25361,7 +25403,7 @@ class DispatchClient {
25361
25403
  if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
25362
25404
  throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
25363
25405
  }
25364
- throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
25406
+ throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
25365
25407
  }
25366
25408
  throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
25367
25409
  }
@@ -27135,6 +27177,7 @@ var issueFreeTools = {
27135
27177
  dispatch_answers: true,
27136
27178
  dispatch_whoami: true,
27137
27179
  dispatch_limits: true,
27180
+ dispatch_api: true,
27138
27181
  dispatch_inbox: true,
27139
27182
  dispatch_send_to_agent: true,
27140
27183
  dispatch_architecture_sync: true
@@ -29541,6 +29584,16 @@ async function resultsCommand(context) {
29541
29584
  };
29542
29585
  }
29543
29586
 
29587
+ // ../envoy-client/src/dispatch-commands/api.ts
29588
+ async function apiCommand(context) {
29589
+ const path = stringArg(context.args, "path");
29590
+ const answer = await context.newClient().readRoute(path);
29591
+ return {
29592
+ text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
29593
+ details: { path }
29594
+ };
29595
+ }
29596
+
29544
29597
  // ../envoy-client/src/dispatch-commands/render-item.ts
29545
29598
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
29546
29599
  const answer = ask.answer;
@@ -32430,6 +32483,7 @@ var dispatchCommands = {
32430
32483
  dispatch_answers: onSession(answersCommand),
32431
32484
  dispatch_whoami: onSession(whoamiCommand),
32432
32485
  dispatch_limits: onSession(limitsCommand),
32486
+ dispatch_api: onSession(apiCommand),
32433
32487
  dispatch_inbox: onSession(inboxCommand)
32434
32488
  };
32435
32489
  // ../envoy-client/src/dispatch-execute.ts
@@ -32475,6 +32529,10 @@ function readDispatchFirstContext(skillFile) {
32475
32529
  `);
32476
32530
  }
32477
32531
 
32532
+ // ../cipher-client/src/environment.ts
32533
+ import { readFile as readFile6 } from "fs/promises";
32534
+ import { join as join8 } from "path";
32535
+
32478
32536
  // ../cipher-client/src/device-login.ts
32479
32537
  import { generateKeyPairSync as generateKeyPairSync2, randomUUID as randomUUID5 } from "crypto";
32480
32538
 
@@ -33436,6 +33494,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
33436
33494
  var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
33437
33495
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
33438
33496
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
33497
+ var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
33498
+ var ROLE_KEY_FILE = "key.pem";
33439
33499
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
33440
33500
  var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
33441
33501
  var MAX_PROJECTS = 16;
@@ -33449,6 +33509,7 @@ var BROKER_VARIABLES = [
33449
33509
  BROKER_URL_VAR,
33450
33510
  IDENTITY_VAR,
33451
33511
  MACHINE_TOKEN_FILE_VAR,
33512
+ KEY_DIR_VAR,
33452
33513
  MACHINE_AUDIENCE_VAR,
33453
33514
  SESSION_VAR,
33454
33515
  PROJECTS_VAR,
@@ -33524,6 +33585,21 @@ function tradeProjects(env) {
33524
33585
  }
33525
33586
  return sorted;
33526
33587
  }
33588
+ async function machineKey(env) {
33589
+ const dir = value(env, KEY_DIR_VAR);
33590
+ if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
33591
+ return await newDpopKey();
33592
+ const path = join8(dir, ROLE_KEY_FILE);
33593
+ let pem;
33594
+ try {
33595
+ pem = await readFile6(path, "utf8");
33596
+ } catch (error) {
33597
+ throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
33598
+ cause: error
33599
+ });
33600
+ }
33601
+ return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
33602
+ }
33527
33603
  async function brokerTokenClient(env, own = "", read) {
33528
33604
  const brokerUrl = value(env, BROKER_URL_VAR);
33529
33605
  const machine = machineIdentity(env);
@@ -33551,7 +33627,7 @@ async function brokerTokenClient(env, own = "", read) {
33551
33627
  if (record === undefined) {
33552
33628
  const client = new BrokerTokenClient({
33553
33629
  brokerUrl,
33554
- key: await newDpopKey(),
33630
+ key: await machineKey(env),
33555
33631
  subject: machine,
33556
33632
  session: tradeSession(env, own),
33557
33633
  launcherCredential: false,
@@ -34912,18 +34988,18 @@ function claudeProjectDirectory(environment, fallback) {
34912
34988
  // src/codex/codex-session-record.ts
34913
34989
  import { spawnSync } from "child_process";
34914
34990
  import { readFileSync as readFileSync5, readlinkSync, unwatchFile, watchFile } from "fs";
34915
- import { mkdir as mkdir4, readFile as readFile7, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
34991
+ import { mkdir as mkdir4, readFile as readFile8, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
34916
34992
  import { homedir as homedir3 } from "os";
34917
- import { basename as basename4, dirname as dirname5, join as join10 } from "path";
34993
+ import { basename as basename4, dirname as dirname5, join as join11 } from "path";
34918
34994
 
34919
34995
  // src/session-identity.ts
34920
- import { readFile as readFile6 } from "fs/promises";
34921
- import { basename as basename3, join as join9 } from "path";
34996
+ import { readFile as readFile7 } from "fs/promises";
34997
+ import { basename as basename3, join as join10 } from "path";
34922
34998
 
34923
34999
  // src/session-state.ts
34924
35000
  import { readFileSync as readFileSync4 } from "fs";
34925
35001
  import { mkdir as mkdir3, readdir as readdir3, rename as rename4, rm as rm4, stat as stat4, utimes as utimes2, writeFile as writeFile2 } from "fs/promises";
34926
- import { dirname as dirname4, join as join8 } from "path";
35002
+ import { dirname as dirname4, join as join9 } from "path";
34927
35003
  async function writeAtomicStateFile(file, contents) {
34928
35004
  await mkdir3(dirname4(file), { recursive: true, mode: 448 });
34929
35005
  const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
@@ -34941,7 +35017,7 @@ async function pruneStateDirectory(directory, isStale) {
34941
35017
  throw error;
34942
35018
  });
34943
35019
  for (const entry of entries) {
34944
- const file = join8(directory, entry);
35020
+ const file = join9(directory, entry);
34945
35021
  if (!await isStale(file))
34946
35022
  continue;
34947
35023
  await rm4(file, { recursive: true, force: true });
@@ -34956,7 +35032,7 @@ async function writtenLongAgo(file) {
34956
35032
  }
34957
35033
  var TITLES_DIRECTORY = "titles";
34958
35034
  function sessionTitleFile(stateDirectory, sessionId) {
34959
- return join8(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
35035
+ return join9(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
34960
35036
  }
34961
35037
  async function writeChosenTitle(file, title) {
34962
35038
  await writeAtomicStateFile(file, `${title}
@@ -34984,7 +35060,7 @@ async function recordChosenTitle(sessionId, title) {
34984
35060
  await writeChosenTitle(file, chosen);
34985
35061
  }
34986
35062
  async function pruneStaleSessionTitles(stateDirectory) {
34987
- await pruneStateDirectory(join8(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
35063
+ await pruneStateDirectory(join9(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
34988
35064
  }
34989
35065
 
34990
35066
  // src/session-identity.ts
@@ -35009,14 +35085,14 @@ class SessionIdentity {
35009
35085
  }
35010
35086
  }
35011
35087
  function sessionHandoffDirectory(stateDirectory, claudePid) {
35012
- return join9(stateDirectory, "sessions", String(claudePid));
35088
+ return join10(stateDirectory, "sessions", String(claudePid));
35013
35089
  }
35014
35090
  function sessionHandoffFile(stateDirectory, claudePid) {
35015
- return join9(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
35091
+ return join10(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
35016
35092
  }
35017
35093
  var ROLES_DIRECTORY = "roles";
35018
35094
  function roleStateFile(stateDirectory, sessionId) {
35019
- return join9(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
35095
+ return join10(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
35020
35096
  }
35021
35097
 
35022
35098
  class UnparseableRoleRecordError extends Error {
@@ -35028,7 +35104,7 @@ class UnparseableRoleRecordError extends Error {
35028
35104
  async function readPersistedRole(roleFile) {
35029
35105
  let bytes;
35030
35106
  try {
35031
- bytes = await readFile6(roleFile, "utf8");
35107
+ bytes = await readFile7(roleFile, "utf8");
35032
35108
  } catch (error) {
35033
35109
  if (hasErrnoCode(error, "ENOENT"))
35034
35110
  return;
@@ -35050,7 +35126,7 @@ async function writeSessionHandoff(file, sessionId) {
35050
35126
  }
35051
35127
  async function readSessionHandoff(file) {
35052
35128
  try {
35053
- const id = (await readFile6(file, "utf8")).trim();
35129
+ const id = (await readFile7(file, "utf8")).trim();
35054
35130
  return id.length === 0 ? undefined : id;
35055
35131
  } catch (error) {
35056
35132
  if (hasErrnoCode(error, "ENOENT"))
@@ -35067,14 +35143,14 @@ function processExists(pid) {
35067
35143
  }
35068
35144
  }
35069
35145
  async function pruneStaleSessionHandoffs(stateDirectory) {
35070
- await pruneStateDirectory(join9(stateDirectory, "sessions"), (file) => {
35146
+ await pruneStateDirectory(join10(stateDirectory, "sessions"), (file) => {
35071
35147
  const pid = basename3(file);
35072
35148
  return /^\d+$/.test(pid) && !processExists(Number(pid));
35073
35149
  });
35074
35150
  }
35075
35151
  async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
35076
35152
  const own = roleStateFile(stateDirectory, currentSessionId);
35077
- await pruneStateDirectory(join9(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
35153
+ await pruneStateDirectory(join10(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
35078
35154
  }
35079
35155
 
35080
35156
  // src/codex/codex-session-record.ts
@@ -35088,10 +35164,10 @@ var CodexSessionRecord = object({
35088
35164
  codex_started: string2().nullable().default(null)
35089
35165
  });
35090
35166
  function codexSessionRecordFile(stateDirectory, pid) {
35091
- return join10(stateDirectory, "codex-sessions", `${pid}.json`);
35167
+ return join11(stateDirectory, "codex-sessions", `${pid}.json`);
35092
35168
  }
35093
35169
  function codexEndedFile(stateDirectory, pid, sessionId) {
35094
- return join10(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
35170
+ return join11(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
35095
35171
  }
35096
35172
  async function markSessionEnded(stateDirectory, pid, sessionId) {
35097
35173
  const marker = codexEndedFile(stateDirectory, pid, sessionId);
@@ -35114,7 +35190,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
35114
35190
  }
35115
35191
  async function sessionEnded(file) {
35116
35192
  try {
35117
- await readFile7(file);
35193
+ await readFile8(file);
35118
35194
  return true;
35119
35195
  } catch {
35120
35196
  return false;
@@ -35128,7 +35204,7 @@ async function writeCodexSessionRecord(file, value) {
35128
35204
  }
35129
35205
  async function readCodexSessionRecord(file) {
35130
35206
  try {
35131
- const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile7(file, "utf8")));
35207
+ const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile8(file, "utf8")));
35132
35208
  return parsed.success ? parsed.data : undefined;
35133
35209
  } catch {
35134
35210
  return;
@@ -35136,7 +35212,7 @@ async function readCodexSessionRecord(file) {
35136
35212
  }
35137
35213
  function codexHome(env) {
35138
35214
  const set = env["CODEX_HOME"];
35139
- return set !== undefined && set !== "" ? set : join10(env["HOME"] || homedir3(), ".codex");
35215
+ return set !== undefined && set !== "" ? set : join11(env["HOME"] || homedir3(), ".codex");
35140
35216
  }
35141
35217
  function codexPluginDataDirectory(pluginRoot) {
35142
35218
  const version = pluginRoot;
@@ -35146,7 +35222,7 @@ function codexPluginDataDirectory(pluginRoot) {
35146
35222
  const plugins = dirname5(cache);
35147
35223
  if (basename4(cache) !== "cache" || basename4(plugins) !== "plugins")
35148
35224
  return;
35149
- return join10(plugins, "data", `${basename4(plugin)}-${basename4(marketplace)}`);
35225
+ return join11(plugins, "data", `${basename4(plugin)}-${basename4(marketplace)}`);
35150
35226
  }
35151
35227
  var MAX_ANCESTORS = 16;
35152
35228
  function codexProcessId(readComm = procComm, readParent = procParent) {
@@ -35248,11 +35324,11 @@ function codexSubcommand(args) {
35248
35324
  }
35249
35325
  var SHARED_APP_SERVER_NOTE = "Codex runs this session in its shared app server (`codex app-server`), which runs several sessions in one process, so the Envoy plugin does not register it with Envoy: it receives no Envoy messages and does not show on Dispatch's Agents page. Its `dispatch` tool works, acting as this session.";
35250
35326
  async function pruneCodexSessionRecords(stateDirectory) {
35251
- await pruneStateDirectory(join10(stateDirectory, "codex-sessions"), (file) => {
35327
+ await pruneStateDirectory(join11(stateDirectory, "codex-sessions"), (file) => {
35252
35328
  const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename4(file));
35253
35329
  return match !== null && !processExists(Number(match[1]));
35254
35330
  });
35255
- await pruneStateDirectory(join10(stateDirectory, "codex-servers"), (file) => {
35331
+ await pruneStateDirectory(join11(stateDirectory, "codex-servers"), (file) => {
35256
35332
  const name = basename4(file);
35257
35333
  return /^\d+$/.test(name) && !processExists(Number(name));
35258
35334
  });
@@ -35473,7 +35549,7 @@ async function dispatchFirst(raw) {
35473
35549
  process.stdout.write(JSON.stringify({
35474
35550
  hookSpecificOutput: {
35475
35551
  hookEventName: input.hook_event_name,
35476
- additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(join11(pluginRoot, "skills")))
35552
+ additionalContext: readDispatchFirstContext(dispatchFirstSkillFile(join12(pluginRoot, "skills")))
35477
35553
  }
35478
35554
  }));
35479
35555
  }
@@ -35532,13 +35608,13 @@ async function refreshedAnswers(session, cwd, dispatchUrl, startedAt, by) {
35532
35608
  } catch (error) {
35533
35609
  return { reason: messageFor(error) };
35534
35610
  }
35535
- const lock = join11(directory, REFRESH_LOCK);
35611
+ const lock = join12(directory, REFRESH_LOCK);
35536
35612
  if (!refreshLockHeld(lock)) {
35537
35613
  const refresher = Bun.spawn([process.execPath, Bun.main, "answers-refresh", session, cwd, "--host", HOST], { stdin: "ignore", stdout: "ignore", stderr: "ignore", detached: true });
35538
35614
  refresher.unref();
35539
35615
  nameRefresher(refresher.pid);
35540
35616
  }
35541
- const file = join11(directory, REFRESH_OUTCOME);
35617
+ const file = join12(directory, REFRESH_OUTCOME);
35542
35618
  for (;; ) {
35543
35619
  const outcome = refreshOutcome(file, startedAt);
35544
35620
  if (outcome !== undefined) {
@@ -35619,7 +35695,7 @@ async function answers(text) {
35619
35695
  async function answersRefresh(session, cwd) {
35620
35696
  const directory = sessionDirectory(process.env, session);
35621
35697
  mkdirSync2(directory, { recursive: true, mode: 448 });
35622
- const lock = join11(directory, REFRESH_LOCK);
35698
+ const lock = join12(directory, REFRESH_LOCK);
35623
35699
  if (takeRefreshLock(lock)) {
35624
35700
  try {
35625
35701
  const file = sessionConfigFile(HOST, process.env);
@@ -35637,7 +35713,7 @@ async function answersRefresh(session, cwd) {
35637
35713
  text: read.text ?? null,
35638
35714
  notice: read.notice ?? null
35639
35715
  };
35640
- writeAtomically(join11(directory, REFRESH_OUTCOME), JSON.stringify(outcome));
35716
+ writeAtomically(join12(directory, REFRESH_OUTCOME), JSON.stringify(outcome));
35641
35717
  } finally {
35642
35718
  rmSync2(lock, { force: true });
35643
35719
  }
@@ -203,17 +203,19 @@ function errorClass(error) {
203
203
  }
204
204
 
205
205
  // ../envoy-client/src/errors.ts
206
- function dispatchCode(error) {
207
- if (!("fromDispatch" in error) || !("code" in error))
206
+ function dispatchField(error, field) {
207
+ if (!("fromDispatch" in error))
208
208
  return;
209
- const code = error.code;
210
- return typeof code === "string" && code !== "" ? code : undefined;
209
+ const value = Reflect.get(error, field);
210
+ return typeof value === "string" && value !== "" ? value : undefined;
211
211
  }
212
212
  function messageFor(error) {
213
213
  if (!(error instanceof Error))
214
214
  return scrub(String(error));
215
- const code = dispatchCode(error);
216
- return scrub(code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`);
215
+ const code = dispatchField(error, "code");
216
+ const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
217
+ const hint = dispatchField(error, "hint");
218
+ return scrub(hint === undefined ? message : `${message}; ${hint}`);
217
219
  }
218
220
  function hasErrnoCode(error, code) {
219
221
  return error instanceof Error && "code" in error && error.code === code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "5.27.1",
3
+ "version": "5.28.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "AGENTS.md"
20
20
  ],
21
21
  "legion": {
22
- "daemonApiVersion": 256
22
+ "daemonApiVersion": 275
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
@@ -523,6 +523,30 @@ export async function postDispatchReply(
523
523
  await postDeliveryReply(config, identity.id, delivery, result)
524
524
  }
525
525
 
526
+ /**
527
+ * The Dispatch client a person's message, command, pick or BTW is accepted and read through
528
+ * (`UserTurnRouterOptions.dispatch`), bounded to `ms`, or undefined while nothing configures
529
+ * Dispatch. It trades under this session's id, as `postDispatchReply` does: no pod sets
530
+ * `AGENT_SECRETS_SESSION`, so a trade that named no session would write under none.
531
+ */
532
+ export async function userTurnDispatchClient(
533
+ identity: SessionIdentity,
534
+ configFile: SessionConfigFile,
535
+ ms: number,
536
+ ): Promise<DispatchClient | undefined> {
537
+ const active = activeDispatchSettings(
538
+ (
539
+ await sessionDispatchSettings(configFile, process.env, {
540
+ cwd: identity.directory,
541
+ session: () => identity.id,
542
+ })
543
+ ).dispatch,
544
+ )
545
+ return active === null
546
+ ? undefined
547
+ : new DispatchClient(active.url, active.credential, fetch, { deadlineMs: ms })
548
+ }
549
+
526
550
  /**
527
551
  * Render inbound Envoy envelopes through the shared renderer and hand each one to the session,
528
552
  * one at a time, in the order they were queued.
@@ -2798,16 +2822,7 @@ export async function runEnvoyChannelServer(): Promise<void> {
2798
2822
  */
2799
2823
  const router = (state: UserTurnState): UserTurnRouter => {
2800
2824
  const options: UserTurnRouterOptions = {
2801
- dispatch: async (ms) => {
2802
- const active = activeDispatchSettings(
2803
- (await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch,
2804
- )
2805
- return active === null
2806
- ? undefined
2807
- : new DispatchClient(active.url, active.credential, fetch, {
2808
- deadlineMs: ms,
2809
- })
2810
- },
2825
+ dispatch: (ms) => userTurnDispatchClient(identity, configFile, ms),
2811
2826
  effortPicked: (effort) => agentStream?.pickedEffort(effort),
2812
2827
  refreshSettings: () => agentStream?.refresh(),
2813
2828
  reply: (delivery, result) => postDispatchReply(identity, configFile, delivery, result),