@sjawhar/claude-envoy 5.27.2 → 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.
@@ -23780,7 +23780,7 @@ function scrubProcessStreams() {
23780
23780
  import { spawn as spawn2 } from "child_process";
23781
23781
  import { unwatchFile as unwatchFile3, watchFile as watchFile3 } from "fs";
23782
23782
  import { homedir as homedir4 } from "os";
23783
- import { join as join21, resolve as resolve3 } from "path";
23783
+ import { join as join22, resolve as resolve3 } from "path";
23784
23784
  // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/core/core.js
23785
23785
  var NEVER = Object.freeze({
23786
23786
  status: "aborted"
@@ -37285,6 +37285,25 @@ var projectKeyValidation = {
37285
37285
  message: `project is not a project key: ${PROJECT_KEY_RULE}`
37286
37286
  };
37287
37287
  var ARCHITECTURE_SOURCE_REPO_PATTERN = /^[A-Za-z0-9_-]+\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
37288
+ var API_ROUTE_PATTERN = /^\/api\/v1(?=[/?]|$)/;
37289
+ 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 ..";
37290
+ function apiPathProblem(value) {
37291
+ const { path } = value;
37292
+ if (typeof path !== "string")
37293
+ return;
37294
+ const named = JSON.stringify(path);
37295
+ if (!API_ROUTE_PATTERN.test(path)) {
37296
+ 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).`;
37297
+ }
37298
+ if (!/^[!-~]*$/.test(path) || /[\\#]/.test(path)) {
37299
+ return `path ${named} holds a space, a backslash, a # or a character outside printable ASCII: percent-encode it.`;
37300
+ }
37301
+ const route = path.split("?", 1)[0] ?? "";
37302
+ if (route.split("/").some((segment) => /^(?:\.|%2e){1,2}$/i.test(segment))) {
37303
+ return `path ${named} holds a . or .. segment: name the route itself.`;
37304
+ }
37305
+ return;
37306
+ }
37288
37307
  var ISSUE_STATUSES = [
37289
37308
  "triage",
37290
37309
  "icebox",
@@ -37890,6 +37909,20 @@ var dispatchToolSpecs = [
37890
37909
  arguments: () => ({}),
37891
37910
  strict: true
37892
37911
  },
37912
+ {
37913
+ name: "dispatch_api",
37914
+ example: { path: "/api/v1/issues/DSP-1/events?limit=200" },
37915
+ 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.",
37916
+ arguments: (z) => ({
37917
+ 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.")
37918
+ }),
37919
+ validation: {
37920
+ check: (value) => apiPathProblem(value) === undefined,
37921
+ message: API_PATH_RULE,
37922
+ refusal: (value) => apiPathProblem(value) ?? API_PATH_RULE
37923
+ },
37924
+ strict: true
37925
+ },
37893
37926
  {
37894
37927
  name: "dispatch_handoff_write",
37895
37928
  example: {
@@ -40105,6 +40138,10 @@ function zodSchemaApi(zod) {
40105
40138
  }
40106
40139
  };
40107
40140
  }
40141
+ // ../cipher-client/src/environment.ts
40142
+ import { readFile as readFile4 } from "fs/promises";
40143
+ import { join as join4 } from "path";
40144
+
40108
40145
  // ../contracts/src/log-text.ts
40109
40146
  var URL_NOT_PRINTED = "(not printed: it carries a credential or is not a plain http(s) URL)";
40110
40147
  function isCleanUrl(raw) {
@@ -44446,6 +44483,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
44446
44483
  var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
44447
44484
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
44448
44485
  var MACHINE_AUDIENCE_VAR = "AGENT_SECRETS_MACHINE_AUDIENCE";
44486
+ var KEY_DIR_VAR = "AGENT_SECRETS_KEY_DIR";
44487
+ var ROLE_KEY_FILE = "key.pem";
44449
44488
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
44450
44489
  var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
44451
44490
  var MAX_PROJECTS = 16;
@@ -44459,6 +44498,7 @@ var BROKER_VARIABLES = [
44459
44498
  BROKER_URL_VAR,
44460
44499
  IDENTITY_VAR,
44461
44500
  MACHINE_TOKEN_FILE_VAR,
44501
+ KEY_DIR_VAR,
44462
44502
  MACHINE_AUDIENCE_VAR,
44463
44503
  SESSION_VAR,
44464
44504
  PROJECTS_VAR,
@@ -44534,6 +44574,21 @@ function tradeProjects(env) {
44534
44574
  }
44535
44575
  return sorted;
44536
44576
  }
44577
+ async function machineKey(env) {
44578
+ const dir = value(env, KEY_DIR_VAR);
44579
+ if (value(env, IDENTITY_VAR) !== IDENTITY_KUBERNETES || dir === "")
44580
+ return await newDpopKey();
44581
+ const path = join4(dir, ROLE_KEY_FILE);
44582
+ let pem;
44583
+ try {
44584
+ pem = await readFile4(path, "utf8");
44585
+ } catch (error) {
44586
+ throw new Error(`read this role's agent-secrets key ${path}: ${messageOf(error)}`, {
44587
+ cause: error
44588
+ });
44589
+ }
44590
+ return await importDpopKey(pem, `this role's agent-secrets key ${path}`);
44591
+ }
44537
44592
  async function brokerTokenClient(env, own = "", read) {
44538
44593
  const brokerUrl = value(env, BROKER_URL_VAR);
44539
44594
  const machine = machineIdentity(env);
@@ -44561,7 +44616,7 @@ async function brokerTokenClient(env, own = "", read) {
44561
44616
  if (record === undefined) {
44562
44617
  const client = new BrokerTokenClient({
44563
44618
  brokerUrl,
44564
- key: await newDpopKey(),
44619
+ key: await machineKey(env),
44565
44620
  subject: machine,
44566
44621
  session: tradeSession(env, own),
44567
44622
  launcherCredential: false,
@@ -44592,7 +44647,7 @@ import {
44592
44647
  lstat as lstat3,
44593
44648
  mkdtemp,
44594
44649
  open as open3,
44595
- readFile as readFile5,
44650
+ readFile as readFile6,
44596
44651
  readlink as readlink2,
44597
44652
  rm as rm3,
44598
44653
  stat as stat3
@@ -44601,17 +44656,19 @@ import { homedir, tmpdir } from "os";
44601
44656
  import * as path from "path";
44602
44657
 
44603
44658
  // ../envoy-client/src/errors.ts
44604
- function dispatchCode(error) {
44605
- if (!("fromDispatch" in error) || !("code" in error))
44659
+ function dispatchField(error, field) {
44660
+ if (!("fromDispatch" in error))
44606
44661
  return;
44607
- const code = error.code;
44608
- return typeof code === "string" && code !== "" ? code : undefined;
44662
+ const value = Reflect.get(error, field);
44663
+ return typeof value === "string" && value !== "" ? value : undefined;
44609
44664
  }
44610
44665
  function messageFor(error) {
44611
44666
  if (!(error instanceof Error))
44612
44667
  return scrub(String(error));
44613
- const code = dispatchCode(error);
44614
- return scrub(code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`);
44668
+ const code = dispatchField(error, "code");
44669
+ const message = code === undefined || error.message.startsWith(code) ? error.message : `${code}: ${error.message}`;
44670
+ const hint = dispatchField(error, "hint");
44671
+ return scrub(hint === undefined ? message : `${message}; ${hint}`);
44615
44672
  }
44616
44673
  function hasErrnoCode(error, code) {
44617
44674
  return error instanceof Error && "code" in error && error.code === code;
@@ -44777,14 +44834,14 @@ function spawnWatched(argv, options) {
44777
44834
  }
44778
44835
 
44779
44836
  // ../envoy-client/src/secret-file.ts
44780
- import { readFile as readFile4 } from "fs/promises";
44837
+ import { readFile as readFile5 } from "fs/promises";
44781
44838
  function sendable(value) {
44782
44839
  return !/[\s\p{Cc}]/u.test(value);
44783
44840
  }
44784
44841
  async function readSecretFile(variable, filePath) {
44785
44842
  let contents;
44786
44843
  try {
44787
- contents = await readFile4(filePath, "utf8");
44844
+ contents = await readFile5(filePath, "utf8");
44788
44845
  } catch (error) {
44789
44846
  throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
44790
44847
  }
@@ -44937,7 +44994,7 @@ async function exists(file) {
44937
44994
  async function parseFile(filePath, schema, checkout) {
44938
44995
  let raw;
44939
44996
  try {
44940
- raw = await readFile5(filePath, "utf-8");
44997
+ raw = await readFile6(filePath, "utf-8");
44941
44998
  } catch (error) {
44942
44999
  if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
44943
45000
  return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
@@ -45850,6 +45907,7 @@ class DispatchServiceError extends Error {
45850
45907
  mismatches;
45851
45908
  issues;
45852
45909
  changed;
45910
+ hint;
45853
45911
  constructor(code, status, message, details = {}) {
45854
45912
  super(message);
45855
45913
  this.code = code;
@@ -45859,6 +45917,7 @@ class DispatchServiceError extends Error {
45859
45917
  this.mismatches = details.mismatches;
45860
45918
  this.issues = details.issues;
45861
45919
  this.changed = details.changed;
45920
+ this.hint = details.hint;
45862
45921
  }
45863
45922
  }
45864
45923
 
@@ -46348,6 +46407,10 @@ class DispatchClient {
46348
46407
  async limits() {
46349
46408
  return this.#json("GET", ["api", "v1", "limits"]);
46350
46409
  }
46410
+ async readRoute(path) {
46411
+ const url = new URL(path.slice(1), `${this.#baseUrl}/`).toString();
46412
+ return this.#response("GET", url, await this.#send("GET", url));
46413
+ }
46351
46414
  async inbox(assignee) {
46352
46415
  return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
46353
46416
  }
@@ -47036,7 +47099,7 @@ class DispatchClient {
47036
47099
  if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
47037
47100
  throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
47038
47101
  }
47039
- throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, error);
47102
+ throw new DispatchServiceError(error.code ?? `HTTP_${response.status}`, response.status, error.error, { ...error, hint: typeof error.hint === "string" ? error.hint : undefined });
47040
47103
  }
47041
47104
  throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
47042
47105
  }
@@ -47072,20 +47135,20 @@ class DispatchClient {
47072
47135
  import { randomUUID as randomUUID5 } from "crypto";
47073
47136
  import { renameSync, rmSync, writeFileSync } from "fs";
47074
47137
  import { homedir as homedir2 } from "os";
47075
- import { join as join5 } from "path";
47138
+ import { join as join6 } from "path";
47076
47139
  var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
47077
47140
  var PRIVATE_FILE = 384;
47078
47141
  function sessionStateRoot(env) {
47079
47142
  const stateDir = env["DISPATCH_STATE_DIR"];
47080
47143
  if (stateDir)
47081
47144
  return stateDir;
47082
- return join5(env["XDG_STATE_HOME"] || join5(homedir2(), ".local", "state"), "dispatch");
47145
+ return join6(env["XDG_STATE_HOME"] || join6(homedir2(), ".local", "state"), "dispatch");
47083
47146
  }
47084
47147
  function sessionDirectory(env, sessionId) {
47085
47148
  if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
47086
47149
  throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
47087
47150
  }
47088
- return join5(sessionStateRoot(env), "sessions", sessionId);
47151
+ return join6(sessionStateRoot(env), "sessions", sessionId);
47089
47152
  }
47090
47153
  function writeAtomically(path, text) {
47091
47154
  const temporary = `${path}.${process.pid}.${randomUUID5()}.tmp`;
@@ -47113,7 +47176,7 @@ import {
47113
47176
  statSync as statSync2,
47114
47177
  writeFileSync as writeFileSync3
47115
47178
  } from "fs";
47116
- import { join as join8 } from "path";
47179
+ import { join as join9 } from "path";
47117
47180
 
47118
47181
  // ../envoy-client/src/askgate-marker.ts
47119
47182
  import { createHash as createHash2, randomBytes } from "crypto";
@@ -47132,7 +47195,7 @@ import {
47132
47195
  utimesSync,
47133
47196
  writeFileSync as writeFileSync2
47134
47197
  } from "fs";
47135
- import { isAbsolute as isAbsolute3, join as join6, resolve as resolve2 } from "path";
47198
+ import { isAbsolute as isAbsolute3, join as join7, resolve as resolve2 } from "path";
47136
47199
  var ASKGATE_RECORD = "askgate";
47137
47200
  var MARKER_MAX_AGE_MS = 2 * 60 * 60000;
47138
47201
  var STORE_BEAT_MS = 10 * 60000;
@@ -47258,7 +47321,7 @@ var STORE_NAME = /^([1-9][0-9]*)(?:-([0-9]+)(?:-([0-9]+))?)?$/;
47258
47321
  function storeTouched(store) {
47259
47322
  const own = statSync(store).mtimeMs;
47260
47323
  try {
47261
- return Math.max(own, statSync(join6(store, MARKERS)).mtimeMs);
47324
+ return Math.max(own, statSync(join7(store, MARKERS)).mtimeMs);
47262
47325
  } catch (error) {
47263
47326
  if (hasErrnoCode(error, "ENOENT"))
47264
47327
  return own;
@@ -47267,7 +47330,7 @@ function storeTouched(store) {
47267
47330
  }
47268
47331
  var UNNAMESPACED_STORE_MAX_AGE_MS = 14 * 86400000;
47269
47332
  function sweepStores(root, now) {
47270
- const parent = join6(root, "askgate");
47333
+ const parent = join7(root, "askgate");
47271
47334
  let names;
47272
47335
  try {
47273
47336
  names = readdirSync(parent);
@@ -47278,7 +47341,7 @@ function sweepStores(root, now) {
47278
47341
  const match = STORE_NAME.exec(name);
47279
47342
  if (match === null)
47280
47343
  continue;
47281
- const store = join6(parent, name);
47344
+ const store = join7(parent, name);
47282
47345
  try {
47283
47346
  const owner = { pid: Number(match[1]), start: match[2] ?? null, ns: match[3] ?? null, store };
47284
47347
  if (ownerLive(owner, now))
@@ -47292,7 +47355,7 @@ function sweepStores(root, now) {
47292
47355
  }
47293
47356
  }
47294
47357
  function recordNamesStore(dir) {
47295
- const record = join6(dir, ASKGATE_RECORD);
47358
+ const record = join7(dir, ASKGATE_RECORD);
47296
47359
  let names;
47297
47360
  try {
47298
47361
  names = readdirSync(record);
@@ -47303,7 +47366,7 @@ function recordNamesStore(dir) {
47303
47366
  if (!name.endsWith(OWNER_FILE))
47304
47367
  continue;
47305
47368
  try {
47306
- const parsed = parseOwner(readFileSync2(join6(record, name), "utf-8"));
47369
+ const parsed = parseOwner(readFileSync2(join7(record, name), "utf-8"));
47307
47370
  if (parsed === undefined)
47308
47371
  return true;
47309
47372
  statSync(parsed.owner.store);
@@ -47316,7 +47379,7 @@ function recordNamesStore(dir) {
47316
47379
  return false;
47317
47380
  }
47318
47381
  function askgateState(dir, now = Date.now()) {
47319
- const record = join6(dir, ASKGATE_RECORD);
47382
+ const record = join7(dir, ASKGATE_RECORD);
47320
47383
  let names;
47321
47384
  try {
47322
47385
  names = readdirSync(record);
@@ -47329,7 +47392,7 @@ function askgateState(dir, now = Date.now()) {
47329
47392
  for (const name of names) {
47330
47393
  if (!name.endsWith(OWNER_FILE))
47331
47394
  continue;
47332
- const file = join6(record, name);
47395
+ const file = join7(record, name);
47333
47396
  let text;
47334
47397
  try {
47335
47398
  text = readFileSync2(file, "utf-8");
@@ -47349,7 +47412,7 @@ function askgateState(dir, now = Date.now()) {
47349
47412
  return { kind: "off" };
47350
47413
  for (const { file, store } of live) {
47351
47414
  try {
47352
- if (!statSync(join6(store, MARKERS)).isDirectory())
47415
+ if (!statSync(join7(store, MARKERS)).isDirectory())
47353
47416
  throw new Error("not a directory");
47354
47417
  } catch (error) {
47355
47418
  return {
@@ -47401,11 +47464,11 @@ function consumeMarker(stores, argv, args, files, now) {
47401
47464
  let expired = false;
47402
47465
  const usable = [];
47403
47466
  for (const store of stores) {
47404
- const dir = join6(store, MARKERS);
47467
+ const dir = join7(store, MARKERS);
47405
47468
  for (const name of readdirSync(dir)) {
47406
47469
  if (!name.startsWith(`${key}.`))
47407
47470
  continue;
47408
- const file = join6(dir, name);
47471
+ const file = join7(dir, name);
47409
47472
  const marker = readMarker(file);
47410
47473
  if (marker === undefined || marker.argv !== key)
47411
47474
  continue;
@@ -51765,6 +51828,7 @@ var issueFreeTools = {
51765
51828
  dispatch_answers: true,
51766
51829
  dispatch_whoami: true,
51767
51830
  dispatch_limits: true,
51831
+ dispatch_api: true,
51768
51832
  dispatch_inbox: true,
51769
51833
  dispatch_send_to_agent: true,
51770
51834
  dispatch_architecture_sync: true
@@ -54171,6 +54235,16 @@ async function resultsCommand(context) {
54171
54235
  };
54172
54236
  }
54173
54237
 
54238
+ // ../envoy-client/src/dispatch-commands/api.ts
54239
+ async function apiCommand(context) {
54240
+ const path = stringArg(context.args, "path");
54241
+ const answer = await context.newClient().readRoute(path);
54242
+ return {
54243
+ text: typeof answer === "string" ? answer : JSON.stringify(answer, null, 2),
54244
+ details: { path }
54245
+ };
54246
+ }
54247
+
54174
54248
  // ../envoy-client/src/dispatch-commands/render-item.ts
54175
54249
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
54176
54250
  const answer = ask.answer;
@@ -56418,7 +56492,7 @@ async function reviewCommand(context) {
56418
56492
 
56419
56493
  // ../envoy-client/src/session-answers.ts
56420
56494
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
56421
- import { join as join7 } from "path";
56495
+ import { join as join8 } from "path";
56422
56496
 
56423
56497
  // ../envoy-client/src/json-line-record.ts
56424
56498
  import { appendFileSync } from "fs";
@@ -56558,7 +56632,7 @@ processGlobal2[STATE_KEY] = state;
56558
56632
  var CACHE_FILE = "answers.json";
56559
56633
  function readCacheFile(directory, url) {
56560
56634
  try {
56561
- const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
56635
+ const value = JSON.parse(readFileSync3(join8(directory, CACHE_FILE), "utf-8"));
56562
56636
  if (typeof value === "object" && value !== null && "dispatch_url" in value && typeof value.dispatch_url === "string" && value.dispatch_url === url && "read_at" in value && typeof value.read_at === "string" && "total" in value && typeof value.total === "number" && "items" in value && Array.isArray(value.items)) {
56563
56637
  return {
56564
56638
  dispatch_url: value.dispatch_url,
@@ -56679,7 +56753,7 @@ async function readSessionAnswers(options) {
56679
56753
  if (directory !== undefined) {
56680
56754
  try {
56681
56755
  mkdirSync2(directory, { recursive: true, mode: 448 });
56682
- writeAtomically(join7(directory, CACHE_FILE), JSON.stringify(cache));
56756
+ writeAtomically(join8(directory, CACHE_FILE), JSON.stringify(cache));
56683
56757
  } catch {}
56684
56758
  }
56685
56759
  return { cache };
@@ -57030,6 +57104,7 @@ var dispatchCommands = {
57030
57104
  dispatch_answers: onSession(answersCommand),
57031
57105
  dispatch_whoami: onSession(whoamiCommand),
57032
57106
  dispatch_limits: onSession(limitsCommand),
57107
+ dispatch_api: onSession(apiCommand),
57033
57108
  dispatch_inbox: onSession(inboxCommand)
57034
57109
  };
57035
57110
  // ../envoy-client/src/dispatch-execute.ts
@@ -57078,7 +57153,7 @@ function stringList(value) {
57078
57153
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
57079
57154
  }
57080
57155
  function loadSessionMemory(dir, sessionId) {
57081
- const path = join8(dir, "state.json");
57156
+ const path = join9(dir, "state.json");
57082
57157
  const text = readIfPresent(path);
57083
57158
  if (text === undefined)
57084
57159
  return new Set;
@@ -57102,7 +57177,7 @@ function writeMemory(dir, sessionId, follows) {
57102
57177
  pictures: [...shownPictures(sessionId)],
57103
57178
  follows: [...follows]
57104
57179
  };
57105
- writeAtomically(join8(dir, "state.json"), `${JSON.stringify(state)}
57180
+ writeAtomically(join9(dir, "state.json"), `${JSON.stringify(state)}
57106
57181
  `);
57107
57182
  }
57108
57183
  function appendResult(dir, entry) {
@@ -57111,7 +57186,7 @@ function appendResult(dir, entry) {
57111
57186
  }
57112
57187
  function writeResult(dir, entry) {
57113
57188
  const line = { at: new Date().toISOString(), ...entry };
57114
- appendFileSync2(join8(dir, "results.jsonl"), `${JSON.stringify(line)}
57189
+ appendFileSync2(join9(dir, "results.jsonl"), `${JSON.stringify(line)}
57115
57190
  `, { mode: PRIVATE_FILE2 });
57116
57191
  }
57117
57192
  function recordOutcome(dir, sessionId, follows, entry) {
@@ -57122,8 +57197,8 @@ function recordOutcome(dir, sessionId, follows, entry) {
57122
57197
  function writePicture(dir, image) {
57123
57198
  const bytes = Buffer.from(image.data, "base64");
57124
57199
  const name = createHash3("sha256").update(bytes).digest("hex").slice(0, 16);
57125
- const pictures = join8(dir, "pictures");
57126
- const path = join8(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
57200
+ const pictures = join9(dir, "pictures");
57201
+ const path = join9(pictures, `${name}.${PICTURE_EXTENSIONS[image.mimeType]}`);
57127
57202
  ensureDirectory(pictures);
57128
57203
  try {
57129
57204
  writeFileSync3(path, bytes, { mode: PRIVATE_FILE2, flag: "wx" });
@@ -57134,21 +57209,21 @@ function writePicture(dir, image) {
57134
57209
  return { path, bytes: bytes.length };
57135
57210
  }
57136
57211
  function writeLongOutput(dir, text) {
57137
- const out = join8(dir, "out");
57212
+ const out = join9(dir, "out");
57138
57213
  ensureDirectory(out);
57139
- const path = join8(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
57214
+ const path = join9(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
57140
57215
  writeFileSync3(path, text, { mode: PRIVATE_FILE2 });
57141
57216
  return path;
57142
57217
  }
57143
57218
  function writeSessionTitle(dir, title) {
57144
57219
  ensureDirectory(dir);
57145
- writeAtomically(join8(dir, "title"), title);
57220
+ writeAtomically(join9(dir, "title"), title);
57146
57221
  }
57147
57222
  function readSessionTitle(dir) {
57148
- return readIfPresent(join8(dir, "title")) || undefined;
57223
+ return readIfPresent(join9(dir, "title")) || undefined;
57149
57224
  }
57150
57225
  function pruneSessions(root, now) {
57151
- const stamp = join8(root, PRUNED_STAMP);
57226
+ const stamp = join9(root, PRUNED_STAMP);
57152
57227
  try {
57153
57228
  if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
57154
57229
  return;
@@ -57156,7 +57231,7 @@ function pruneSessions(root, now) {
57156
57231
  if (!hasErrnoCode(error, "ENOENT"))
57157
57232
  throw error;
57158
57233
  }
57159
- const sessions = join8(root, "sessions");
57234
+ const sessions = join9(root, "sessions");
57160
57235
  let entries = [];
57161
57236
  try {
57162
57237
  entries = readdirSync2(sessions, { withFileTypes: true });
@@ -57167,7 +57242,7 @@ function pruneSessions(root, now) {
57167
57242
  for (const entry of entries) {
57168
57243
  if (!entry.isDirectory())
57169
57244
  continue;
57170
- const dir = join8(sessions, entry.name);
57245
+ const dir = join9(sessions, entry.name);
57171
57246
  try {
57172
57247
  const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
57173
57248
  if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
@@ -63423,9 +63498,9 @@ var import_nats5 = __toESM(require_mod4(), 1);
63423
63498
 
63424
63499
  // package.json
63425
63500
  var name2 = "@sjawhar/claude-envoy";
63426
- var version2 = "5.27.2";
63501
+ var version2 = "5.28.0";
63427
63502
  var legion = {
63428
- daemonApiVersion: 256
63503
+ daemonApiVersion: 275
63429
63504
  };
63430
63505
  var package_default = {
63431
63506
  name: name2,
@@ -64623,13 +64698,13 @@ function createChannelTopics(connection, options = {}) {
64623
64698
  }
64624
64699
 
64625
64700
  // src/session-identity.ts
64626
- import { readFile as readFile6 } from "fs/promises";
64627
- import { basename as basename3, join as join10 } from "path";
64701
+ import { readFile as readFile7 } from "fs/promises";
64702
+ import { basename as basename3, join as join11 } from "path";
64628
64703
 
64629
64704
  // src/session-state.ts
64630
64705
  import { readFileSync as readFileSync6 } from "fs";
64631
64706
  import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
64632
- import { dirname as dirname4, join as join9 } from "path";
64707
+ import { dirname as dirname4, join as join10 } from "path";
64633
64708
  async function writeAtomicStateFile(file, contents) {
64634
64709
  await mkdir2(dirname4(file), { recursive: true, mode: 448 });
64635
64710
  const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
@@ -64647,7 +64722,7 @@ async function pruneStateDirectory(directory, isStale) {
64647
64722
  throw error;
64648
64723
  });
64649
64724
  for (const entry of entries) {
64650
- const file = join9(directory, entry);
64725
+ const file = join10(directory, entry);
64651
64726
  if (!await isStale(file))
64652
64727
  continue;
64653
64728
  await rm4(file, { recursive: true, force: true });
@@ -64662,7 +64737,7 @@ async function writtenLongAgo(file) {
64662
64737
  }
64663
64738
  var TITLES_DIRECTORY = "titles";
64664
64739
  function sessionTitleFile(stateDirectory, sessionId) {
64665
- return join9(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
64740
+ return join10(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
64666
64741
  }
64667
64742
  async function writeChosenTitle(file, title) {
64668
64743
  await writeAtomicStateFile(file, `${title}
@@ -64690,7 +64765,7 @@ async function recordChosenTitle(sessionId, title) {
64690
64765
  await writeChosenTitle(file, chosen);
64691
64766
  }
64692
64767
  async function pruneStaleSessionTitles(stateDirectory) {
64693
- await pruneStateDirectory(join9(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
64768
+ await pruneStateDirectory(join10(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
64694
64769
  }
64695
64770
 
64696
64771
  // src/session-identity.ts
@@ -64715,14 +64790,14 @@ class SessionIdentity {
64715
64790
  }
64716
64791
  }
64717
64792
  function sessionHandoffDirectory(stateDirectory, claudePid) {
64718
- return join10(stateDirectory, "sessions", String(claudePid));
64793
+ return join11(stateDirectory, "sessions", String(claudePid));
64719
64794
  }
64720
64795
  function sessionHandoffFile(stateDirectory, claudePid) {
64721
- return join10(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
64796
+ return join11(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
64722
64797
  }
64723
64798
  var ROLES_DIRECTORY = "roles";
64724
64799
  function roleStateFile(stateDirectory, sessionId) {
64725
- return join10(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
64800
+ return join11(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
64726
64801
  }
64727
64802
 
64728
64803
  class UnparseableRoleRecordError extends Error {
@@ -64734,7 +64809,7 @@ class UnparseableRoleRecordError extends Error {
64734
64809
  async function readPersistedRole(roleFile) {
64735
64810
  let bytes;
64736
64811
  try {
64737
- bytes = await readFile6(roleFile, "utf8");
64812
+ bytes = await readFile7(roleFile, "utf8");
64738
64813
  } catch (error) {
64739
64814
  if (hasErrnoCode(error, "ENOENT"))
64740
64815
  return;
@@ -64756,7 +64831,7 @@ async function writeSessionHandoff(file, sessionId) {
64756
64831
  }
64757
64832
  async function readSessionHandoff(file) {
64758
64833
  try {
64759
- const id = (await readFile6(file, "utf8")).trim();
64834
+ const id = (await readFile7(file, "utf8")).trim();
64760
64835
  return id.length === 0 ? undefined : id;
64761
64836
  } catch (error) {
64762
64837
  if (hasErrnoCode(error, "ENOENT"))
@@ -64773,14 +64848,14 @@ function processExists(pid) {
64773
64848
  }
64774
64849
  }
64775
64850
  async function pruneStaleSessionHandoffs(stateDirectory) {
64776
- await pruneStateDirectory(join10(stateDirectory, "sessions"), (file) => {
64851
+ await pruneStateDirectory(join11(stateDirectory, "sessions"), (file) => {
64777
64852
  const pid = basename3(file);
64778
64853
  return /^\d+$/.test(pid) && !processExists(Number(pid));
64779
64854
  });
64780
64855
  }
64781
64856
  async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
64782
64857
  const own = roleStateFile(stateDirectory, currentSessionId);
64783
- await pruneStateDirectory(join10(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
64858
+ await pruneStateDirectory(join11(stateDirectory, ROLES_DIRECTORY), async (file) => file !== own && await writtenLongAgo(file));
64784
64859
  }
64785
64860
 
64786
64861
  // src/envoy-off.ts
@@ -64838,7 +64913,7 @@ async function serveEnvoyOff(serverInfo, refusal) {
64838
64913
  }
64839
64914
 
64840
64915
  // src/installed-build.ts
64841
- import { dirname as dirname5, join as join11, sep } from "path";
64916
+ import { dirname as dirname5, join as join12, sep } from "path";
64842
64917
  function pluginCacheSegments(bundlePath) {
64843
64918
  const parts = bundlePath.split(sep);
64844
64919
  for (let index = 0;index + 1 < parts.length; index++) {
@@ -64852,12 +64927,12 @@ function installedPluginVersion(bundlePath) {
64852
64927
  }
64853
64928
  function channelConnectionName(name, bundlePath, packageName) {
64854
64929
  const version = installedPluginVersion(bundlePath);
64855
- return clientConnectionName(name, clientBuild(join11(dirname5(bundlePath), "build-commit"), version === undefined ? undefined : { name: packageName, version }));
64930
+ return clientConnectionName(name, clientBuild(join12(dirname5(bundlePath), "build-commit"), version === undefined ? undefined : { name: packageName, version }));
64856
64931
  }
64857
64932
 
64858
64933
  // src/legion-claim.ts
64859
64934
  import { readdir as readdir4, stat as stat5 } from "fs/promises";
64860
- import { join as join13 } from "path";
64935
+ import { join as join14 } from "path";
64861
64936
  import { setTimeout as delay2 } from "timers/promises";
64862
64937
 
64863
64938
  // ../pi-shared/src/stall-limits.ts
@@ -65315,6 +65390,12 @@ var legionControllerLocator = object({
65315
65390
  var legionAgentSecretsLoginView = object({
65316
65391
  state: string2().optional()
65317
65392
  });
65393
+ var legionDispatchCredentialView = object({
65394
+ session: nonEmptyString2.optional(),
65395
+ transitionLaunches: number2().int().nonnegative().optional(),
65396
+ lastTransitionLaunchAt: timestamp.nullable().optional(),
65397
+ liveLaunchesWithDispatchToken: number2().int().nonnegative().optional()
65398
+ });
65318
65399
  var legionCapabilityState = object({
65319
65400
  name: nonEmptyString2.optional(),
65320
65401
  status: _enum2(["present", "unchecked", "withheld", "decided", "open"]).optional(),
@@ -65449,6 +65530,7 @@ var LegionStateResponse = object({
65449
65530
  lastPause: legionEndedPause.optional(),
65450
65531
  controllerLocator: legionControllerLocator.optional(),
65451
65532
  agentSecretsLogin: legionAgentSecretsLoginView.optional(),
65533
+ dispatchCredential: legionDispatchCredentialView.optional(),
65452
65534
  capabilities: array(legionCapabilityState).optional(),
65453
65535
  repositories: legionRepositories.optional(),
65454
65536
  settings: legionSettings.optional(),
@@ -66344,7 +66426,7 @@ function listenerAskedToClaimAgain(error) {
66344
66426
  // src/legion-phase-hook.ts
66345
66427
  import { randomUUID as randomUUID7 } from "crypto";
66346
66428
  import { readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
66347
- import { dirname as dirname6, join as join12 } from "path";
66429
+ import { dirname as dirname6, join as join13 } from "path";
66348
66430
 
66349
66431
  // ../pi-shared/src/phase-reminder.ts
66350
66432
  import { randomUUID as randomUUID6 } from "crypto";
@@ -66809,7 +66891,7 @@ function phaseHookToolDefinition() {
66809
66891
  };
66810
66892
  }
66811
66893
  function phaseStallFile(configDir, sessionID) {
66812
- return join12(configDir, `legion-phase-stall-${sessionID}.json`);
66894
+ return join13(configDir, `legion-phase-stall-${sessionID}.json`);
66813
66895
  }
66814
66896
  function paneReminderLog(write) {
66815
66897
  const line = (level, message, context) => {
@@ -66862,7 +66944,7 @@ function readPhaseStallRecord(file, log) {
66862
66944
  };
66863
66945
  }
66864
66946
  function writePhaseStallRecord(file, entry, recreatedNoticeSent, log) {
66865
- const temporary = join12(dirname6(file), `.legion-phase-stall-${randomUUID7()}`);
66947
+ const temporary = join13(dirname6(file), `.legion-phase-stall-${randomUUID7()}`);
66866
66948
  try {
66867
66949
  writeFileSync4(temporary, JSON.stringify({ ...entry, ...recreatedNoticeSent ? { recreatedNoticeSent } : {} }), { mode: 384 });
66868
66950
  renameSync3(temporary, file);
@@ -67070,12 +67152,12 @@ function stopPane(why) {
67070
67152
  endPane();
67071
67153
  }
67072
67154
  async function waitForTranscript(configDir, sessionID, signal, pollMs = 100) {
67073
- const projects = join13(configDir, "projects");
67155
+ const projects = join14(configDir, "projects");
67074
67156
  const name = `${sessionID}.jsonl`;
67075
67157
  for (;; ) {
67076
67158
  signal.throwIfAborted();
67077
67159
  for (const directory of await readdir4(projects).catch(() => [])) {
67078
- const file = join13(projects, directory, name);
67160
+ const file = join14(projects, directory, name);
67079
67161
  if (await isFile(file))
67080
67162
  return file;
67081
67163
  }
@@ -68275,14 +68357,14 @@ function modSession(options) {
68275
68357
  }
68276
68358
 
68277
68359
  // src/replay-state.ts
68278
- import { join as join14 } from "path";
68360
+ import { join as join15 } from "path";
68279
68361
 
68280
68362
  // src/state-file.ts
68281
- import { readFile as readFile7 } from "fs/promises";
68363
+ import { readFile as readFile8 } from "fs/promises";
68282
68364
  async function readStateFile(file, schema, empty, refusal) {
68283
68365
  let text;
68284
68366
  try {
68285
- text = await readFile7(file, "utf8");
68367
+ text = await readFile8(file, "utf8");
68286
68368
  } catch (error) {
68287
68369
  if (hasErrnoCode(error, "ENOENT"))
68288
68370
  return empty;
@@ -68305,7 +68387,7 @@ var ReplayStateFileSchema = LedgerSnapshotSchema.extend({
68305
68387
  consumer: ConsumerDeliverySnapshotSchema.optional()
68306
68388
  });
68307
68389
  function replayStateFile(stateDirectory, sessionId) {
68308
- return join14(stateDirectory, `replay-${encodeURIComponent(sessionId)}.json`);
68390
+ return join15(stateDirectory, `replay-${encodeURIComponent(sessionId)}.json`);
68309
68391
  }
68310
68392
  async function readReplayState(file) {
68311
68393
  return await readStateFile(file, ReplayStateFileSchema, { ledger: [] }, "holds no delivery state");
@@ -68853,7 +68935,7 @@ function createUserTurnRouter(options) {
68853
68935
  }
68854
68936
 
68855
68937
  // src/user-turn-state.ts
68856
- import { join as join15 } from "path";
68938
+ import { join as join16 } from "path";
68857
68939
  var TURNS_DIRECTORY = "turns";
68858
68940
  var HANDLED_ATTEMPTS_MAX = 1000;
68859
68941
  var DELIVERED_ROWS_MAX = 1000;
@@ -68863,7 +68945,7 @@ var UserTurnStateSchema = object({
68863
68945
  rows: array(DeliveredRowSchema).default([])
68864
68946
  });
68865
68947
  function userTurnStateFile(stateDirectory, sessionId) {
68866
- return join15(stateDirectory, TURNS_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
68948
+ return join16(stateDirectory, TURNS_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
68867
68949
  }
68868
68950
  async function readUserTurnState(file) {
68869
68951
  return await readStateFile(file, UserTurnStateSchema, { handled: [], rows: [] }, "holds no record of this session's turns");
@@ -68901,7 +68983,7 @@ function userTurnState(file, restored) {
68901
68983
  };
68902
68984
  }
68903
68985
  async function pruneStaleSessionTurns(stateDirectory) {
68904
- await pruneStateDirectory(join15(stateDirectory, TURNS_DIRECTORY), writtenLongAgo);
68986
+ await pruneStateDirectory(join16(stateDirectory, TURNS_DIRECTORY), writtenLongAgo);
68905
68987
  }
68906
68988
 
68907
68989
  // src/envoy-channel-server.ts
@@ -68975,6 +69057,13 @@ async function postDispatchReply(identity, configFile, delivery, result) {
68975
69057
  throw new Error(config.error ?? config.notice);
68976
69058
  await postDeliveryReply(config, identity.id, delivery, result);
68977
69059
  }
69060
+ async function userTurnDispatchClient(identity, configFile, ms) {
69061
+ const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, {
69062
+ cwd: identity.directory,
69063
+ session: () => identity.id
69064
+ })).dispatch);
69065
+ return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, { deadlineMs: ms });
69066
+ }
68978
69067
  function createChannelDelivery(input) {
68979
69068
  const inbox = [];
68980
69069
  let tail = Promise.resolve();
@@ -70314,12 +70403,7 @@ async function runEnvoyChannelServer() {
70314
70403
  });
70315
70404
  const router = (state) => {
70316
70405
  const options = {
70317
- dispatch: async (ms) => {
70318
- const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch);
70319
- return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, {
70320
- deadlineMs: ms
70321
- });
70322
- },
70406
+ dispatch: (ms) => userTurnDispatchClient(identity, configFile, ms),
70323
70407
  effortPicked: (effort) => agentStream?.pickedEffort(effort),
70324
70408
  refreshSettings: () => agentStream?.refresh(),
70325
70409
  reply: (delivery, result) => postDispatchReply(identity, configFile, delivery, result),
@@ -70634,7 +70718,7 @@ function startCodexAgentStream(options) {
70634
70718
  import { spawn } from "child_process";
70635
70719
  import { randomBytes as randomBytes2 } from "crypto";
70636
70720
  import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
70637
- import { join as join16 } from "path";
70721
+ import { join as join17 } from "path";
70638
70722
  var QUEUE_TIMEOUT_MS = 30000;
70639
70723
  function codexProcessEnv(pid, fallback, read = (path) => readFileSync9(path, "utf8")) {
70640
70724
  let raw;
@@ -70703,7 +70787,7 @@ function fitArgument(text, spillDirectory) {
70703
70787
  throw new Error(`the message is ${Buffer.byteLength(text)} bytes, over what codex queue takes`);
70704
70788
  }
70705
70789
  mkdirSync4(spillDirectory, { mode: 448, recursive: true });
70706
- const file = join16(spillDirectory, `${Date.now()}-${randomBytes2(4).toString("hex")}.txt`);
70790
+ const file = join17(spillDirectory, `${Date.now()}-${randomBytes2(4).toString("hex")}.txt`);
70707
70791
  writeFileSync5(file, text, { mode: 384 });
70708
70792
  return `${text.slice(0, QUEUE_HEAD_CHARS)}
70709
70793
 
@@ -70828,11 +70912,11 @@ function askSideQuestion(command, threadId, question, timeoutMs = SIDE_QUESTION_
70828
70912
 
70829
70913
  // src/codex/codex-inbox.ts
70830
70914
  import { randomBytes as randomBytes3 } from "crypto";
70831
- import { mkdir as mkdir4, readdir as readdir5, readFile as readFile8, rename as rename4, rm as rm6, writeFile as writeFile2 } from "fs/promises";
70832
- import { join as join17 } from "path";
70915
+ import { mkdir as mkdir4, readdir as readdir5, readFile as readFile9, rename as rename4, rm as rm6, writeFile as writeFile2 } from "fs/promises";
70916
+ import { join as join18 } from "path";
70833
70917
  var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
70834
70918
  function codexInboxDirectory(stateDirectory, sessionId) {
70835
- return join17(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
70919
+ return join18(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
70836
70920
  }
70837
70921
  var lastOrder = 0;
70838
70922
  function inboxItemName() {
@@ -70841,17 +70925,17 @@ function inboxItemName() {
70841
70925
  return `${String(order).padStart(15, "0")}-${randomBytes3(4).toString("hex")}.json`;
70842
70926
  }
70843
70927
  async function putInbox(directory, item, name = inboxItemName()) {
70844
- const waiting = join17(directory, "waiting");
70928
+ const waiting = join18(directory, "waiting");
70845
70929
  await mkdir4(waiting, { recursive: true, mode: 448 });
70846
- const temporary = join17(directory, `.${name}.tmp`);
70930
+ const temporary = join18(directory, `.${name}.tmp`);
70847
70931
  await writeFile2(temporary, JSON.stringify(item), { mode: 384 });
70848
- await rename4(temporary, join17(waiting, name));
70932
+ await rename4(temporary, join18(waiting, name));
70849
70933
  return name;
70850
70934
  }
70851
70935
  async function takenBy(directory, name) {
70852
70936
  for (const taker of ["hook", "server"]) {
70853
70937
  try {
70854
- await readFile8(join17(directory, TAKEN_DIRECTORY[taker], name));
70938
+ await readFile9(join18(directory, TAKEN_DIRECTORY[taker], name));
70855
70939
  return taker;
70856
70940
  } catch {}
70857
70941
  }
@@ -70859,14 +70943,14 @@ async function takenBy(directory, name) {
70859
70943
  }
70860
70944
  async function withdrawWaiting(directory, name) {
70861
70945
  try {
70862
- await rm6(join17(directory, "waiting", name));
70946
+ await rm6(join18(directory, "waiting", name));
70863
70947
  return true;
70864
70948
  } catch {
70865
70949
  return false;
70866
70950
  }
70867
70951
  }
70868
70952
  async function discardWaiting(directory, keep = () => false) {
70869
- const waiting = join17(directory, "waiting");
70953
+ const waiting = join18(directory, "waiting");
70870
70954
  let names;
70871
70955
  try {
70872
70956
  names = await readdir5(waiting);
@@ -70878,7 +70962,7 @@ async function discardWaiting(directory, keep = () => false) {
70878
70962
  if (!name.endsWith(".json") || keep(name))
70879
70963
  continue;
70880
70964
  try {
70881
- await rm6(join17(waiting, name));
70965
+ await rm6(join18(waiting, name));
70882
70966
  removed++;
70883
70967
  } catch {}
70884
70968
  }
@@ -70886,7 +70970,7 @@ async function discardWaiting(directory, keep = () => false) {
70886
70970
  }
70887
70971
  var HOOK_CONTEXT_MAX_BYTES = 8000;
70888
70972
  async function takeInbox(directory, taker, maxContextBytes) {
70889
- const waiting = join17(directory, "waiting");
70973
+ const waiting = join18(directory, "waiting");
70890
70974
  let names;
70891
70975
  try {
70892
70976
  names = (await readdir5(waiting)).filter((name) => name.endsWith(".json")).sort();
@@ -70895,14 +70979,14 @@ async function takeInbox(directory, taker, maxContextBytes) {
70895
70979
  }
70896
70980
  if (names.length === 0)
70897
70981
  return [];
70898
- const destination = join17(directory, TAKEN_DIRECTORY[taker]);
70982
+ const destination = join18(directory, TAKEN_DIRECTORY[taker]);
70899
70983
  await mkdir4(destination, { recursive: true, mode: 448 });
70900
70984
  const taken = [];
70901
70985
  for (const name of names) {
70902
70986
  if (maxContextBytes !== undefined) {
70903
70987
  let waitingItem;
70904
70988
  try {
70905
- waitingItem = JSON.parse(await readFile8(join17(waiting, name), "utf8"));
70989
+ waitingItem = JSON.parse(await readFile9(join18(waiting, name), "utf8"));
70906
70990
  } catch {
70907
70991
  continue;
70908
70992
  }
@@ -70913,12 +70997,12 @@ async function takeInbox(directory, taker, maxContextBytes) {
70913
70997
  break;
70914
70998
  }
70915
70999
  try {
70916
- await rename4(join17(waiting, name), join17(destination, name));
71000
+ await rename4(join18(waiting, name), join18(destination, name));
70917
71001
  } catch {
70918
71002
  continue;
70919
71003
  }
70920
71004
  try {
70921
- const parsed = JSON.parse(await readFile8(join17(destination, name), "utf8"));
71005
+ const parsed = JSON.parse(await readFile9(join18(destination, name), "utf8"));
70922
71006
  if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
70923
71007
  taken.push({ item: parsed, name });
70924
71008
  }
@@ -71075,15 +71159,15 @@ function createCodexDelivery(options) {
71075
71159
  }
71076
71160
 
71077
71161
  // src/codex/codex-owner.ts
71078
- import { link as link2, mkdir as mkdir6, readdir as readdir6, readFile as readFile10, rm as rm7, stat as stat7, writeFile as writeFile4 } from "fs/promises";
71079
- import { join as join19 } from "path";
71162
+ import { link as link2, mkdir as mkdir6, readdir as readdir6, readFile as readFile11, rm as rm7, stat as stat7, writeFile as writeFile4 } from "fs/promises";
71163
+ import { join as join20 } from "path";
71080
71164
 
71081
71165
  // src/codex/codex-session-record.ts
71082
71166
  import { spawnSync } from "child_process";
71083
71167
  import { readFileSync as readFileSync10, readlinkSync as readlinkSync2, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
71084
- import { mkdir as mkdir5, readFile as readFile9, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
71168
+ import { mkdir as mkdir5, readFile as readFile10, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
71085
71169
  import { homedir as homedir3 } from "os";
71086
- import { basename as basename5, dirname as dirname8, join as join18 } from "path";
71170
+ import { basename as basename5, dirname as dirname8, join as join19 } from "path";
71087
71171
  var CodexSessionRecord = object({
71088
71172
  session_id: string2().min(1),
71089
71173
  transcript_path: string2().nullable(),
@@ -71094,10 +71178,10 @@ var CodexSessionRecord = object({
71094
71178
  codex_started: string2().nullable().default(null)
71095
71179
  });
71096
71180
  function codexSessionRecordFile(stateDirectory, pid) {
71097
- return join18(stateDirectory, "codex-sessions", `${pid}.json`);
71181
+ return join19(stateDirectory, "codex-sessions", `${pid}.json`);
71098
71182
  }
71099
71183
  function codexEndedFile(stateDirectory, pid, sessionId) {
71100
- return join18(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
71184
+ return join19(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
71101
71185
  }
71102
71186
  async function markSessionEnded(stateDirectory, pid, sessionId) {
71103
71187
  const marker = codexEndedFile(stateDirectory, pid, sessionId);
@@ -71120,7 +71204,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
71120
71204
  }
71121
71205
  async function sessionEnded(file) {
71122
71206
  try {
71123
- await readFile9(file);
71207
+ await readFile10(file);
71124
71208
  return true;
71125
71209
  } catch {
71126
71210
  return false;
@@ -71134,7 +71218,7 @@ async function writeCodexSessionRecord(file, value) {
71134
71218
  }
71135
71219
  async function readCodexSessionRecord(file) {
71136
71220
  try {
71137
- const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile9(file, "utf8")));
71221
+ const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile10(file, "utf8")));
71138
71222
  return parsed.success ? parsed.data : undefined;
71139
71223
  } catch {
71140
71224
  return;
@@ -71142,7 +71226,7 @@ async function readCodexSessionRecord(file) {
71142
71226
  }
71143
71227
  function codexHome(env) {
71144
71228
  const set = env["CODEX_HOME"];
71145
- return set !== undefined && set !== "" ? set : join18(env["HOME"] || homedir3(), ".codex");
71229
+ return set !== undefined && set !== "" ? set : join19(env["HOME"] || homedir3(), ".codex");
71146
71230
  }
71147
71231
  function codexPluginDataDirectory(pluginRoot) {
71148
71232
  const version = pluginRoot;
@@ -71152,7 +71236,7 @@ function codexPluginDataDirectory(pluginRoot) {
71152
71236
  const plugins = dirname8(cache);
71153
71237
  if (basename5(cache) !== "cache" || basename5(plugins) !== "plugins")
71154
71238
  return;
71155
- return join18(plugins, "data", `${basename5(plugin)}-${basename5(marketplace)}`);
71239
+ return join19(plugins, "data", `${basename5(plugin)}-${basename5(marketplace)}`);
71156
71240
  }
71157
71241
  var MAX_ANCESTORS2 = 16;
71158
71242
  function codexProcessId(readComm = procComm, readParent = procParent) {
@@ -71254,11 +71338,11 @@ function codexSubcommand(args) {
71254
71338
  }
71255
71339
  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.";
71256
71340
  async function pruneCodexSessionRecords(stateDirectory) {
71257
- await pruneStateDirectory(join18(stateDirectory, "codex-sessions"), (file) => {
71341
+ await pruneStateDirectory(join19(stateDirectory, "codex-sessions"), (file) => {
71258
71342
  const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename5(file));
71259
71343
  return match !== null && !processExists(Number(match[1]));
71260
71344
  });
71261
- await pruneStateDirectory(join18(stateDirectory, "codex-servers"), (file) => {
71345
+ await pruneStateDirectory(join19(stateDirectory, "codex-servers"), (file) => {
71262
71346
  const name = basename5(file);
71263
71347
  return /^\d+$/.test(name) && !processExists(Number(name));
71264
71348
  });
@@ -71273,7 +71357,7 @@ function codexExecutable(pid) {
71273
71357
 
71274
71358
  // src/codex/codex-owner.ts
71275
71359
  function codexServersDirectory(stateDirectory, codexPid) {
71276
- return join19(stateDirectory, "codex-servers", String(codexPid));
71360
+ return join20(stateDirectory, "codex-servers", String(codexPid));
71277
71361
  }
71278
71362
  var ENTRY_NAME = /^(\d+)\.json$/;
71279
71363
  var TEMPORARY_NAME = /^\.\d+\.\d+\.tmp$/;
@@ -71282,13 +71366,13 @@ function entryName(entry) {
71282
71366
  }
71283
71367
  async function registerServer(directory, pid, started, list = (path) => readdir6(path)) {
71284
71368
  await mkdir6(directory, { mode: 448, recursive: true });
71285
- const temporary = join19(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
71369
+ const temporary = join20(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
71286
71370
  await writeFile4(temporary, JSON.stringify({ pid, started }), { mode: 384 });
71287
71371
  try {
71288
71372
  let seq = Math.max(0, ...numbered(await list(directory)).map(({ seq: taken }) => taken)) + 1;
71289
71373
  for (;; ) {
71290
71374
  try {
71291
- await place(temporary, join19(directory, entryName({ seq })), pid, started);
71375
+ await place(temporary, join20(directory, entryName({ seq })), pid, started);
71292
71376
  return { pid, seq, started };
71293
71377
  } catch (error) {
71294
71378
  if (error.code !== "EEXIST")
@@ -71316,8 +71400,8 @@ async function place(temporary, target, pid, started) {
71316
71400
  await writeFile4(target, JSON.stringify({ pid, started }), { flag: "wx", mode: 384 });
71317
71401
  }
71318
71402
  async function unregisterServer(directory, self2) {
71319
- const file = join19(directory, entryName(self2));
71320
- const named = await readFile10(file, "utf8").then(serverOf, () => {
71403
+ const file = join20(directory, entryName(self2));
71404
+ const named = await readFile11(file, "utf8").then(serverOf, () => {
71321
71405
  return;
71322
71406
  });
71323
71407
  if (named?.pid === self2.pid && named.started === self2.started)
@@ -71380,7 +71464,7 @@ async function readEntries(directory, probe, now = Date.now) {
71380
71464
  for (const name of names.filter((each) => TEMPORARY_NAME.test(each))) {
71381
71465
  let text;
71382
71466
  try {
71383
- text = await readFile10(join19(directory, name), "utf8");
71467
+ text = await readFile11(join20(directory, name), "utf8");
71384
71468
  } catch {
71385
71469
  publishing = true;
71386
71470
  break;
@@ -71396,13 +71480,13 @@ async function readEntries(directory, probe, now = Date.now) {
71396
71480
  for (const { name, seq } of numbered(names)) {
71397
71481
  let text;
71398
71482
  try {
71399
- text = await readFile10(join19(directory, name), "utf8");
71483
+ text = await readFile11(join20(directory, name), "utf8");
71400
71484
  } catch {
71401
71485
  continue;
71402
71486
  }
71403
71487
  const server = serverOf(text);
71404
71488
  if (server === undefined) {
71405
- const written = await stat7(join19(directory, name)).then((info) => info.mtimeMs, () => {
71489
+ const written = await stat7(join20(directory, name)).then((info) => info.mtimeMs, () => {
71406
71490
  return;
71407
71491
  });
71408
71492
  if (written === undefined)
@@ -71430,7 +71514,7 @@ async function currentOwner(directory, probe = SYSTEM_PROBE) {
71430
71514
  const text = seen.held.get(seq);
71431
71515
  if (text === undefined)
71432
71516
  return;
71433
- const now = await readFile10(join19(directory, entryName({ seq })), "utf8").catch(() => {
71517
+ const now = await readFile11(join20(directory, entryName({ seq })), "utf8").catch(() => {
71434
71518
  return;
71435
71519
  });
71436
71520
  if (now !== text)
@@ -71491,7 +71575,7 @@ async function stillOwner(directory, self2, probe = SYSTEM_PROBE) {
71491
71575
  // src/codex/codex-transcript.ts
71492
71576
  import { watch } from "fs";
71493
71577
  import { open as open4 } from "fs/promises";
71494
- import { join as join20 } from "path";
71578
+ import { join as join21 } from "path";
71495
71579
  function record3(value) {
71496
71580
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
71497
71581
  }
@@ -71761,7 +71845,7 @@ async function findTranscript(home, threadId) {
71761
71845
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
71762
71846
  const found = [];
71763
71847
  try {
71764
- for await (const file of glob.scan({ absolute: true, cwd: join20(home, "sessions") })) {
71848
+ for await (const file of glob.scan({ absolute: true, cwd: join21(home, "sessions") })) {
71765
71849
  found.push(file);
71766
71850
  }
71767
71851
  } catch {
@@ -71902,7 +71986,7 @@ function runDispatchCommand(script, args, stdin, options) {
71902
71986
  });
71903
71987
  }
71904
71988
  function stateDirectoryFor(pluginRoot) {
71905
- return configuredValue(process.env["PLUGIN_DATA"]) ?? codexPluginDataDirectory(pluginRoot) ?? join21(configuredValue(process.env["XDG_STATE_HOME"]) ?? join21(homedir4(), ".local", "state"), "claude-envoy", "codex");
71989
+ return configuredValue(process.env["PLUGIN_DATA"]) ?? codexPluginDataDirectory(pluginRoot) ?? join22(configuredValue(process.env["XDG_STATE_HOME"]) ?? join22(homedir4(), ".local", "state"), "claude-envoy", "codex");
71906
71990
  }
71907
71991
  function waitForRecord(file, pid, signal, ended) {
71908
71992
  return new Promise((done) => {
@@ -71990,7 +72074,7 @@ async function runCodexEnvoyServer() {
71990
72074
  env["DISPATCH_HOST"] = "codex";
71991
72075
  if (configFile.path !== null)
71992
72076
  env["ENVOY_CONFIG_FILE"] = configFile.path;
71993
- const { code, output } = await runDispatchCommand(join21(pluginRoot, "dist", "dispatch.js"), parsed.data.args, parsed.data.stdin ?? "", { cwd: await latestTurnCwd(transcript) ?? own?.cwd ?? current?.cwd ?? homedir4(), env });
72077
+ const { code, output } = await runDispatchCommand(join22(pluginRoot, "dist", "dispatch.js"), parsed.data.args, parsed.data.stdin ?? "", { cwd: await latestTurnCwd(transcript) ?? own?.cwd ?? current?.cwd ?? homedir4(), env });
71994
72078
  return `${output}${output.endsWith(`
71995
72079
  `) || output === "" ? "" : `
71996
72080
  `}[exit ${code}]`;
@@ -72130,7 +72214,7 @@ async function runCodexEnvoyServer() {
72130
72214
  const runningSession = () => record?.session_id ?? bound.session_id;
72131
72215
  const codexDelivery = createCodexDelivery({
72132
72216
  inboxDirectory: (sessionId) => codexInboxDirectory(stateDirectory, sessionId),
72133
- queue: (text) => queueMessage(command(), runningSession(), text, join21(stateDirectory, "codex-long-messages")),
72217
+ queue: (text) => queueMessage(command(), runningSession(), text, join22(stateDirectory, "codex-long-messages")),
72134
72218
  sessionId: runningSession,
72135
72219
  taken: (item) => stream?.delivered(item.content, item.dispatchMessageId),
72136
72220
  warn