@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.
@@ -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"
@@ -36450,6 +36450,7 @@ var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
36450
36450
  function uncapturedTopicRefusal(topic, sessionID) {
36451
36451
  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`;
36452
36452
  }
36453
+ var MESSAGE_NOT_SENT_PREFIX = "envoy: the message was not sent, and may be sent again later";
36453
36454
 
36454
36455
  // ../contracts/src/legion-roles.ts
36455
36456
  var LEGION_ROLES = [
@@ -37284,6 +37285,25 @@ var projectKeyValidation = {
37284
37285
  message: `project is not a project key: ${PROJECT_KEY_RULE}`
37285
37286
  };
37286
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
+ }
37287
37307
  var ISSUE_STATUSES = [
37288
37308
  "triage",
37289
37309
  "icebox",
@@ -37889,6 +37909,20 @@ var dispatchToolSpecs = [
37889
37909
  arguments: () => ({}),
37890
37910
  strict: true
37891
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
+ },
37892
37926
  {
37893
37927
  name: "dispatch_handoff_write",
37894
37928
  example: {
@@ -40104,6 +40138,10 @@ function zodSchemaApi(zod) {
40104
40138
  }
40105
40139
  };
40106
40140
  }
40141
+ // ../cipher-client/src/environment.ts
40142
+ import { readFile as readFile4 } from "fs/promises";
40143
+ import { join as join4 } from "path";
40144
+
40107
40145
  // ../contracts/src/log-text.ts
40108
40146
  var URL_NOT_PRINTED = "(not printed: it carries a credential or is not a plain http(s) URL)";
40109
40147
  function isCleanUrl(raw) {
@@ -44445,6 +44483,8 @@ var BROKER_URL_VAR = "AGENT_SECRETS_URL";
44445
44483
  var IDENTITY_VAR = "AGENT_SECRETS_MACHINE_IDENTITY";
44446
44484
  var MACHINE_TOKEN_FILE_VAR = "AGENT_SECRETS_MACHINE_TOKEN_FILE";
44447
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";
44448
44488
  var SESSION_VAR = "AGENT_SECRETS_SESSION";
44449
44489
  var PROJECTS_VAR = "AGENT_SECRETS_PROJECTS";
44450
44490
  var MAX_PROJECTS = 16;
@@ -44458,6 +44498,7 @@ var BROKER_VARIABLES = [
44458
44498
  BROKER_URL_VAR,
44459
44499
  IDENTITY_VAR,
44460
44500
  MACHINE_TOKEN_FILE_VAR,
44501
+ KEY_DIR_VAR,
44461
44502
  MACHINE_AUDIENCE_VAR,
44462
44503
  SESSION_VAR,
44463
44504
  PROJECTS_VAR,
@@ -44533,6 +44574,21 @@ function tradeProjects(env) {
44533
44574
  }
44534
44575
  return sorted;
44535
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
+ }
44536
44592
  async function brokerTokenClient(env, own = "", read) {
44537
44593
  const brokerUrl = value(env, BROKER_URL_VAR);
44538
44594
  const machine = machineIdentity(env);
@@ -44560,7 +44616,7 @@ async function brokerTokenClient(env, own = "", read) {
44560
44616
  if (record === undefined) {
44561
44617
  const client = new BrokerTokenClient({
44562
44618
  brokerUrl,
44563
- key: await newDpopKey(),
44619
+ key: await machineKey(env),
44564
44620
  subject: machine,
44565
44621
  session: tradeSession(env, own),
44566
44622
  launcherCredential: false,
@@ -44591,7 +44647,7 @@ import {
44591
44647
  lstat as lstat3,
44592
44648
  mkdtemp,
44593
44649
  open as open3,
44594
- readFile as readFile5,
44650
+ readFile as readFile6,
44595
44651
  readlink as readlink2,
44596
44652
  rm as rm3,
44597
44653
  stat as stat3
@@ -44600,17 +44656,19 @@ import { homedir, tmpdir } from "os";
44600
44656
  import * as path from "path";
44601
44657
 
44602
44658
  // ../envoy-client/src/errors.ts
44603
- function dispatchCode(error) {
44604
- if (!("fromDispatch" in error) || !("code" in error))
44659
+ function dispatchField(error, field) {
44660
+ if (!("fromDispatch" in error))
44605
44661
  return;
44606
- const code = error.code;
44607
- return typeof code === "string" && code !== "" ? code : undefined;
44662
+ const value = Reflect.get(error, field);
44663
+ return typeof value === "string" && value !== "" ? value : undefined;
44608
44664
  }
44609
44665
  function messageFor(error) {
44610
44666
  if (!(error instanceof Error))
44611
44667
  return scrub(String(error));
44612
- const code = dispatchCode(error);
44613
- 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}`);
44614
44672
  }
44615
44673
  function hasErrnoCode(error, code) {
44616
44674
  return error instanceof Error && "code" in error && error.code === code;
@@ -44776,14 +44834,14 @@ function spawnWatched(argv, options) {
44776
44834
  }
44777
44835
 
44778
44836
  // ../envoy-client/src/secret-file.ts
44779
- import { readFile as readFile4 } from "fs/promises";
44837
+ import { readFile as readFile5 } from "fs/promises";
44780
44838
  function sendable(value) {
44781
44839
  return !/[\s\p{Cc}]/u.test(value);
44782
44840
  }
44783
44841
  async function readSecretFile(variable, filePath) {
44784
44842
  let contents;
44785
44843
  try {
44786
- contents = await readFile4(filePath, "utf8");
44844
+ contents = await readFile5(filePath, "utf8");
44787
44845
  } catch (error) {
44788
44846
  throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
44789
44847
  }
@@ -44936,7 +44994,7 @@ async function exists(file) {
44936
44994
  async function parseFile(filePath, schema, checkout) {
44937
44995
  let raw;
44938
44996
  try {
44939
- raw = await readFile5(filePath, "utf-8");
44997
+ raw = await readFile6(filePath, "utf-8");
44940
44998
  } catch (error) {
44941
44999
  if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
44942
45000
  return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
@@ -45849,6 +45907,7 @@ class DispatchServiceError extends Error {
45849
45907
  mismatches;
45850
45908
  issues;
45851
45909
  changed;
45910
+ hint;
45852
45911
  constructor(code, status, message, details = {}) {
45853
45912
  super(message);
45854
45913
  this.code = code;
@@ -45858,6 +45917,7 @@ class DispatchServiceError extends Error {
45858
45917
  this.mismatches = details.mismatches;
45859
45918
  this.issues = details.issues;
45860
45919
  this.changed = details.changed;
45920
+ this.hint = details.hint;
45861
45921
  }
45862
45922
  }
45863
45923
 
@@ -46347,6 +46407,10 @@ class DispatchClient {
46347
46407
  async limits() {
46348
46408
  return this.#json("GET", ["api", "v1", "limits"]);
46349
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
+ }
46350
46414
  async inbox(assignee) {
46351
46415
  return this.#json("GET", ["api", "v1", "inbox"], undefined, { assignee });
46352
46416
  }
@@ -47035,7 +47099,7 @@ class DispatchClient {
47035
47099
  if (response.status === 409 && error.code === IDEMPOTENCY_KEY_COMMITTED) {
47036
47100
  throw new DispatchWriteLandedError(IDEMPOTENCY_KEY_COMMITTED, response.status, method, requestForText(this.#baseUrl, url, DISPATCH_URL_SETTING));
47037
47101
  }
47038
- 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 });
47039
47103
  }
47040
47104
  throw this.#gatewayError(method, url, response, text, "Dispatch's error JSON");
47041
47105
  }
@@ -47071,20 +47135,20 @@ class DispatchClient {
47071
47135
  import { randomUUID as randomUUID5 } from "crypto";
47072
47136
  import { renameSync, rmSync, writeFileSync } from "fs";
47073
47137
  import { homedir as homedir2 } from "os";
47074
- import { join as join5 } from "path";
47138
+ import { join as join6 } from "path";
47075
47139
  var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
47076
47140
  var PRIVATE_FILE = 384;
47077
47141
  function sessionStateRoot(env) {
47078
47142
  const stateDir = env["DISPATCH_STATE_DIR"];
47079
47143
  if (stateDir)
47080
47144
  return stateDir;
47081
- return join5(env["XDG_STATE_HOME"] || join5(homedir2(), ".local", "state"), "dispatch");
47145
+ return join6(env["XDG_STATE_HOME"] || join6(homedir2(), ".local", "state"), "dispatch");
47082
47146
  }
47083
47147
  function sessionDirectory(env, sessionId) {
47084
47148
  if (!SESSION_ID_PATH_SEGMENT.test(sessionId) || sessionId === "." || sessionId === "..") {
47085
47149
  throw new Error(`dispatch: the session id ${JSON.stringify(sessionId)} is not 1-128 letters, digits, ".", "_" or "-"`);
47086
47150
  }
47087
- return join5(sessionStateRoot(env), "sessions", sessionId);
47151
+ return join6(sessionStateRoot(env), "sessions", sessionId);
47088
47152
  }
47089
47153
  function writeAtomically(path, text) {
47090
47154
  const temporary = `${path}.${process.pid}.${randomUUID5()}.tmp`;
@@ -47112,7 +47176,7 @@ import {
47112
47176
  statSync as statSync2,
47113
47177
  writeFileSync as writeFileSync3
47114
47178
  } from "fs";
47115
- import { join as join8 } from "path";
47179
+ import { join as join9 } from "path";
47116
47180
 
47117
47181
  // ../envoy-client/src/askgate-marker.ts
47118
47182
  import { createHash as createHash2, randomBytes } from "crypto";
@@ -47131,7 +47195,7 @@ import {
47131
47195
  utimesSync,
47132
47196
  writeFileSync as writeFileSync2
47133
47197
  } from "fs";
47134
- 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";
47135
47199
  var ASKGATE_RECORD = "askgate";
47136
47200
  var MARKER_MAX_AGE_MS = 2 * 60 * 60000;
47137
47201
  var STORE_BEAT_MS = 10 * 60000;
@@ -47257,7 +47321,7 @@ var STORE_NAME = /^([1-9][0-9]*)(?:-([0-9]+)(?:-([0-9]+))?)?$/;
47257
47321
  function storeTouched(store) {
47258
47322
  const own = statSync(store).mtimeMs;
47259
47323
  try {
47260
- return Math.max(own, statSync(join6(store, MARKERS)).mtimeMs);
47324
+ return Math.max(own, statSync(join7(store, MARKERS)).mtimeMs);
47261
47325
  } catch (error) {
47262
47326
  if (hasErrnoCode(error, "ENOENT"))
47263
47327
  return own;
@@ -47266,7 +47330,7 @@ function storeTouched(store) {
47266
47330
  }
47267
47331
  var UNNAMESPACED_STORE_MAX_AGE_MS = 14 * 86400000;
47268
47332
  function sweepStores(root, now) {
47269
- const parent = join6(root, "askgate");
47333
+ const parent = join7(root, "askgate");
47270
47334
  let names;
47271
47335
  try {
47272
47336
  names = readdirSync(parent);
@@ -47277,7 +47341,7 @@ function sweepStores(root, now) {
47277
47341
  const match = STORE_NAME.exec(name);
47278
47342
  if (match === null)
47279
47343
  continue;
47280
- const store = join6(parent, name);
47344
+ const store = join7(parent, name);
47281
47345
  try {
47282
47346
  const owner = { pid: Number(match[1]), start: match[2] ?? null, ns: match[3] ?? null, store };
47283
47347
  if (ownerLive(owner, now))
@@ -47291,7 +47355,7 @@ function sweepStores(root, now) {
47291
47355
  }
47292
47356
  }
47293
47357
  function recordNamesStore(dir) {
47294
- const record = join6(dir, ASKGATE_RECORD);
47358
+ const record = join7(dir, ASKGATE_RECORD);
47295
47359
  let names;
47296
47360
  try {
47297
47361
  names = readdirSync(record);
@@ -47302,7 +47366,7 @@ function recordNamesStore(dir) {
47302
47366
  if (!name.endsWith(OWNER_FILE))
47303
47367
  continue;
47304
47368
  try {
47305
- const parsed = parseOwner(readFileSync2(join6(record, name), "utf-8"));
47369
+ const parsed = parseOwner(readFileSync2(join7(record, name), "utf-8"));
47306
47370
  if (parsed === undefined)
47307
47371
  return true;
47308
47372
  statSync(parsed.owner.store);
@@ -47315,7 +47379,7 @@ function recordNamesStore(dir) {
47315
47379
  return false;
47316
47380
  }
47317
47381
  function askgateState(dir, now = Date.now()) {
47318
- const record = join6(dir, ASKGATE_RECORD);
47382
+ const record = join7(dir, ASKGATE_RECORD);
47319
47383
  let names;
47320
47384
  try {
47321
47385
  names = readdirSync(record);
@@ -47328,7 +47392,7 @@ function askgateState(dir, now = Date.now()) {
47328
47392
  for (const name of names) {
47329
47393
  if (!name.endsWith(OWNER_FILE))
47330
47394
  continue;
47331
- const file = join6(record, name);
47395
+ const file = join7(record, name);
47332
47396
  let text;
47333
47397
  try {
47334
47398
  text = readFileSync2(file, "utf-8");
@@ -47348,7 +47412,7 @@ function askgateState(dir, now = Date.now()) {
47348
47412
  return { kind: "off" };
47349
47413
  for (const { file, store } of live) {
47350
47414
  try {
47351
- if (!statSync(join6(store, MARKERS)).isDirectory())
47415
+ if (!statSync(join7(store, MARKERS)).isDirectory())
47352
47416
  throw new Error("not a directory");
47353
47417
  } catch (error) {
47354
47418
  return {
@@ -47400,11 +47464,11 @@ function consumeMarker(stores, argv, args, files, now) {
47400
47464
  let expired = false;
47401
47465
  const usable = [];
47402
47466
  for (const store of stores) {
47403
- const dir = join6(store, MARKERS);
47467
+ const dir = join7(store, MARKERS);
47404
47468
  for (const name of readdirSync(dir)) {
47405
47469
  if (!name.startsWith(`${key}.`))
47406
47470
  continue;
47407
- const file = join6(dir, name);
47471
+ const file = join7(dir, name);
47408
47472
  const marker = readMarker(file);
47409
47473
  if (marker === undefined || marker.argv !== key)
47410
47474
  continue;
@@ -51764,6 +51828,7 @@ var issueFreeTools = {
51764
51828
  dispatch_answers: true,
51765
51829
  dispatch_whoami: true,
51766
51830
  dispatch_limits: true,
51831
+ dispatch_api: true,
51767
51832
  dispatch_inbox: true,
51768
51833
  dispatch_send_to_agent: true,
51769
51834
  dispatch_architecture_sync: true
@@ -54170,6 +54235,16 @@ async function resultsCommand(context) {
54170
54235
  };
54171
54236
  }
54172
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
+
54173
54248
  // ../envoy-client/src/dispatch-commands/render-item.ts
54174
54249
  function askSummary({ ask, replies, answers }, askRef, pictures, incoming, outgoing) {
54175
54250
  const answer = ask.answer;
@@ -56417,7 +56492,7 @@ async function reviewCommand(context) {
56417
56492
 
56418
56493
  // ../envoy-client/src/session-answers.ts
56419
56494
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
56420
- import { join as join7 } from "path";
56495
+ import { join as join8 } from "path";
56421
56496
 
56422
56497
  // ../envoy-client/src/json-line-record.ts
56423
56498
  import { appendFileSync } from "fs";
@@ -56557,7 +56632,7 @@ processGlobal2[STATE_KEY] = state;
56557
56632
  var CACHE_FILE = "answers.json";
56558
56633
  function readCacheFile(directory, url) {
56559
56634
  try {
56560
- const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
56635
+ const value = JSON.parse(readFileSync3(join8(directory, CACHE_FILE), "utf-8"));
56561
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)) {
56562
56637
  return {
56563
56638
  dispatch_url: value.dispatch_url,
@@ -56678,7 +56753,7 @@ async function readSessionAnswers(options) {
56678
56753
  if (directory !== undefined) {
56679
56754
  try {
56680
56755
  mkdirSync2(directory, { recursive: true, mode: 448 });
56681
- writeAtomically(join7(directory, CACHE_FILE), JSON.stringify(cache));
56756
+ writeAtomically(join8(directory, CACHE_FILE), JSON.stringify(cache));
56682
56757
  } catch {}
56683
56758
  }
56684
56759
  return { cache };
@@ -57029,6 +57104,7 @@ var dispatchCommands = {
57029
57104
  dispatch_answers: onSession(answersCommand),
57030
57105
  dispatch_whoami: onSession(whoamiCommand),
57031
57106
  dispatch_limits: onSession(limitsCommand),
57107
+ dispatch_api: onSession(apiCommand),
57032
57108
  dispatch_inbox: onSession(inboxCommand)
57033
57109
  };
57034
57110
  // ../envoy-client/src/dispatch-execute.ts
@@ -57077,7 +57153,7 @@ function stringList(value) {
57077
57153
  return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
57078
57154
  }
57079
57155
  function loadSessionMemory(dir, sessionId) {
57080
- const path = join8(dir, "state.json");
57156
+ const path = join9(dir, "state.json");
57081
57157
  const text = readIfPresent(path);
57082
57158
  if (text === undefined)
57083
57159
  return new Set;
@@ -57101,7 +57177,7 @@ function writeMemory(dir, sessionId, follows) {
57101
57177
  pictures: [...shownPictures(sessionId)],
57102
57178
  follows: [...follows]
57103
57179
  };
57104
- writeAtomically(join8(dir, "state.json"), `${JSON.stringify(state)}
57180
+ writeAtomically(join9(dir, "state.json"), `${JSON.stringify(state)}
57105
57181
  `);
57106
57182
  }
57107
57183
  function appendResult(dir, entry) {
@@ -57110,7 +57186,7 @@ function appendResult(dir, entry) {
57110
57186
  }
57111
57187
  function writeResult(dir, entry) {
57112
57188
  const line = { at: new Date().toISOString(), ...entry };
57113
- appendFileSync2(join8(dir, "results.jsonl"), `${JSON.stringify(line)}
57189
+ appendFileSync2(join9(dir, "results.jsonl"), `${JSON.stringify(line)}
57114
57190
  `, { mode: PRIVATE_FILE2 });
57115
57191
  }
57116
57192
  function recordOutcome(dir, sessionId, follows, entry) {
@@ -57121,8 +57197,8 @@ function recordOutcome(dir, sessionId, follows, entry) {
57121
57197
  function writePicture(dir, image) {
57122
57198
  const bytes = Buffer.from(image.data, "base64");
57123
57199
  const name = createHash3("sha256").update(bytes).digest("hex").slice(0, 16);
57124
- const pictures = join8(dir, "pictures");
57125
- 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]}`);
57126
57202
  ensureDirectory(pictures);
57127
57203
  try {
57128
57204
  writeFileSync3(path, bytes, { mode: PRIVATE_FILE2, flag: "wx" });
@@ -57133,21 +57209,21 @@ function writePicture(dir, image) {
57133
57209
  return { path, bytes: bytes.length };
57134
57210
  }
57135
57211
  function writeLongOutput(dir, text) {
57136
- const out = join8(dir, "out");
57212
+ const out = join9(dir, "out");
57137
57213
  ensureDirectory(out);
57138
- const path = join8(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
57214
+ const path = join9(out, `${new Date().toISOString().replaceAll(":", "-")}-${process.pid}.md`);
57139
57215
  writeFileSync3(path, text, { mode: PRIVATE_FILE2 });
57140
57216
  return path;
57141
57217
  }
57142
57218
  function writeSessionTitle(dir, title) {
57143
57219
  ensureDirectory(dir);
57144
- writeAtomically(join8(dir, "title"), title);
57220
+ writeAtomically(join9(dir, "title"), title);
57145
57221
  }
57146
57222
  function readSessionTitle(dir) {
57147
- return readIfPresent(join8(dir, "title")) || undefined;
57223
+ return readIfPresent(join9(dir, "title")) || undefined;
57148
57224
  }
57149
57225
  function pruneSessions(root, now) {
57150
- const stamp = join8(root, PRUNED_STAMP);
57226
+ const stamp = join9(root, PRUNED_STAMP);
57151
57227
  try {
57152
57228
  if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
57153
57229
  return;
@@ -57155,7 +57231,7 @@ function pruneSessions(root, now) {
57155
57231
  if (!hasErrnoCode(error, "ENOENT"))
57156
57232
  throw error;
57157
57233
  }
57158
- const sessions = join8(root, "sessions");
57234
+ const sessions = join9(root, "sessions");
57159
57235
  let entries = [];
57160
57236
  try {
57161
57237
  entries = readdirSync2(sessions, { withFileTypes: true });
@@ -57166,7 +57242,7 @@ function pruneSessions(root, now) {
57166
57242
  for (const entry of entries) {
57167
57243
  if (!entry.isDirectory())
57168
57244
  continue;
57169
- const dir = join8(sessions, entry.name);
57245
+ const dir = join9(sessions, entry.name);
57170
57246
  try {
57171
57247
  const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
57172
57248
  if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
@@ -58145,6 +58221,7 @@ class EnvoyApiError extends Error {
58145
58221
  claimReleased;
58146
58222
  retryAfterSeconds;
58147
58223
  refused;
58224
+ notSent;
58148
58225
  constructor(details, shown = {}) {
58149
58226
  let parsed;
58150
58227
  try {
@@ -58153,7 +58230,9 @@ class EnvoyApiError extends Error {
58153
58230
  parsed = result.data;
58154
58231
  } catch {}
58155
58232
  const redirected = shown.redirectTo === undefined ? "" : ` (a redirect to ${shown.redirectTo}, which this client does not follow)`;
58156
- super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}${redirected}: ${bodyForText(details.responseBody, shown.tokens ?? "", "the listener's error JSON")}` : `${parsed.error}${parsed.reason === undefined ? "" : ` (reason: ${parsed.reason})`}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}`);
58233
+ const notSentAnswer = details.status === 503 && parsed?.error.startsWith(`${MESSAGE_NOT_SENT_PREFIX}: `) === true;
58234
+ const earlier = notSentAnswer && shown.afterUnanswered === true ? " An earlier attempt got no answer or a 5xx, so that attempt may have stored the message." : "";
58235
+ super(parsed === undefined ? `${details.method} ${details.url} failed with ${details.status}${redirected}: ${bodyForText(details.responseBody, shown.tokens ?? "", "the listener's error JSON")}` : `${parsed.error}${parsed.reason === undefined ? "" : ` (reason: ${parsed.reason})`}${parsed.expected === undefined ? "" : ` (expected: ${parsed.expected.join(", ")})`}${refusalStateText(parsed)}${earlier}`);
58157
58236
  this.details = details;
58158
58237
  this.expected = parsed?.expected;
58159
58238
  this.code = parsed?.code;
@@ -58164,6 +58243,7 @@ class EnvoyApiError extends Error {
58164
58243
  this.claimReleased = parsed?.claim_released;
58165
58244
  this.retryAfterSeconds = parsed?.retry_after_seconds;
58166
58245
  this.refused = parsed?.refused;
58246
+ this.notSent = notSentAnswer && shown.afterUnanswered !== true;
58167
58247
  }
58168
58248
  }
58169
58249
  var mintedDedupeKey2 = new RegExp(MINTED_DEDUPE_KEY_PATTERN);
@@ -58257,10 +58337,12 @@ function createEnvoyClient(config) {
58257
58337
  const request = async (path, init, options = {}) => {
58258
58338
  const url = `${baseUrl}${path}`;
58259
58339
  const tries = options.retry === false ? 1 : attempts;
58340
+ let unanswered = false;
58260
58341
  for (let attempt = 0;attempt < tries; attempt += 1) {
58261
58342
  options.onAttempt?.();
58262
58343
  const outcome = await attemptOnce(url, init, options.timeoutMs ?? timeoutMs, options.actingSession);
58263
58344
  if ("unanswered" in outcome) {
58345
+ unanswered = true;
58264
58346
  options.onUnanswered?.();
58265
58347
  if (attempt + 1 < tries) {
58266
58348
  await waitForRetry(retryDelayMs);
@@ -58285,9 +58367,16 @@ function createEnvoyClient(config) {
58285
58367
  url: shown(url),
58286
58368
  status: response.status,
58287
58369
  responseBody: body
58288
- }, { tokens: redacted, redirectTo: redirectOrigin(response, url, redacted) });
58370
+ }, {
58371
+ tokens: redacted,
58372
+ redirectTo: redirectOrigin(response, url, redacted),
58373
+ afterUnanswered: unanswered
58374
+ });
58289
58375
  if (response.status >= 500) {
58290
- options.onUnanswered?.();
58376
+ if (!error.notSent) {
58377
+ unanswered = true;
58378
+ options.onUnanswered?.();
58379
+ }
58291
58380
  if (attempt + 1 < tries) {
58292
58381
  await waitForRetry(retryDelayMs);
58293
58382
  continue;
@@ -58363,7 +58452,7 @@ function createEnvoyClient(config) {
58363
58452
  return taken;
58364
58453
  response = EnvelopeResponseSchema.parse(raw);
58365
58454
  } catch (error) {
58366
- const refused = notSent || error instanceof EnvoyApiError && error.details.status < 500;
58455
+ const refused = notSent || error instanceof EnvoyApiError && (error.details.status < 500 || error.notSent);
58367
58456
  if (refused && !unanswered)
58368
58457
  throw error;
58369
58458
  throw new EnvoySendUnconfirmedError(input.targetSessionID, idempotencyKey, made, error);
@@ -62998,6 +63087,7 @@ var SESSION_STATE_GUIDE = "A session is live, unresponsive or gone, by how long
62998
63087
  var DELIVERY_CONTRACT = "Delivery is at-least-once, possibly out of order across topics; use id for dedupe and at for freshness.";
62999
63088
  var PUBLISH_COUNTS = "The answer counts who gets it: recipients is every session other than you that the message " + `goes to, one that is stopped and gets it when it runs again within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours included, and ` + "recipients_connected is how many of those are running now. A listener that counts neither " + "sends neither, and a role topic names its holder instead.";
63000
63089
  var STORED_DELIVERY = "Every notification topic is stored (agent, dispatch, github, slack, legion, ghostwispr, " + "whatsapp, team; a role message reaches its holder as a stored copy on the holder's agent " + "topic), and reaches each subscribed session once from the durable consumer its listener " + "relays to it, also one that was away or restarted. A 200 means the stream stored the message " + "for each subscribed session's consumer, not that any recipient has read it.";
63090
+ var NOT_SENT_GUIDE = "An error that says the message was not sent means nothing was stored, so the same message may " + "be sent again later.";
63001
63091
  var TOPIC_GUIDE = "Topic guide (all are under notifications.): agent.<session_id> (subscribe: own inbox); role.<role> " + "(publish-to; holders claim via envoy_role_set). > matches one or more trailing tokens and does not " + "match the base subject. Envoy registers the concrete base when you subscribe to <subject>.>, so " + "the recommended default remains github.<owner>.<repo>.pr.<n>.>. <owner> and <repo> are one token " + "each, with every dot in the name written _ (sjawhar/.github is github.sjawhar._github; " + "acme/site.io is github.acme.site_io), and a topic spelled with the dot receives nothing. " + "Default PR subscription: " + "github.<owner>.<repo>.pr.<n>.> (it receives the quiet PR family): pr.<n> (lifecycle: " + "opened/synchronize/closed; closed carries merged, merge_commit_sha, merged_by, head_sha), " + "pr.<n>.comment, pr.<n>.review, pr.<n>.mention, pr.<n>.checks (one settlement event per commit whose checks settle, the head or not, naming its sha: " + "passed/failed/cancelled/skipped check runs with failing names and URLs, check_runs, each check's latest run as " + "{name, id, conclusion} with conclusion GitHub's own word for that run where one is recorded (for example " + "success, skipped, neutral or timed_out; a skipped check ran nothing on that commit), and statuses, each commit status as " + "{context, state, created_at} with state success, failure or error and created_at the time GitHub created it, " + "left out when none is recorded; for each context keep the entry with the later created_at, and keep a context " + 'that a settlement leaves out as it was; re-fires with superseded_settlement: "true" ' + "when new runs appear, or a commit status is new or changes state, for the same commit). Other GitHub: issue.<n>, issue.<n>.comment, " + "issue.<n>.mention, mention, push.branch.<name>, push.tag.<name>, workflow.<file>.<action> (only " + "runs without an associated PR); slack.<team>.<channel>.message|mention and " + "slack.<team>.<channel>.thread.<ts>.message|mention; ghostwispr.<session>.<kind>; " + "whatsapp.<phone>.<jid>.<kind>; envoy.exceptions.<original-topic>.";
63002
63092
  var URGENCY_VALUES = EnvelopeSchema.shape.urgency.unwrap().options;
63003
63093
  function messageMetadataShape(schema) {
@@ -63064,7 +63154,7 @@ var envoyToolSpecs = [
63064
63154
  },
63065
63155
  {
63066
63156
  name: "envoy_send",
63067
- description: `Send an Envoy agent-to-agent message directly to another session by session ID. The confirmation names the recipient's state. A message to an unresponsive session is stored and reaches it when it answers again, so an unresponsive recipient is not a failed send and no reason to send to someone else instead. ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT} A send that is not confirmed delivered errs naming its idempotency_key; send the same message again with that idempotency_key within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours, and Envoy drops it as a repeat if the first copy arrived.`,
63157
+ description: `Send an Envoy agent-to-agent message directly to another session by session ID. The confirmation names the recipient's state. A message to an unresponsive session is stored and reaches it when it answers again, so an unresponsive recipient is not a failed send and no reason to send to someone else instead. ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT} A send that is not confirmed delivered errs naming its idempotency_key; send the same message again with that idempotency_key within ${DELIVERY_DUPLICATE_WINDOW_HOURS} hours, and Envoy drops it as a repeat if the first copy arrived. ${NOT_SENT_GUIDE}`,
63068
63158
  arguments: (schema) => ({
63069
63159
  session_id: schema.string().describe("Target session ID; find it with envoy_sessions or envoy_whoami."),
63070
63160
  ...messageArguments(schema),
@@ -63074,7 +63164,7 @@ var envoyToolSpecs = [
63074
63164
  },
63075
63165
  {
63076
63166
  name: "envoy_publish",
63077
- description: `Publish an Envoy message to a notifications. topic. ${STORED_DELIVERY} A role or built-in topic is delivered as its guide says. A role message has three possible answers. First, a live session holds the role, and the stream stores the forward for that holder's consumer. Its 200 says the stream stored it. It does not say that the holder read it. It names the holder and the state the listener resolved the holder in. Second, no live session holds the role: nobody claims it, or its holder is unresponsive or gone. The listener then keeps the message for one hour. This is a success. The result says that the listener kept the message, and its kept_until is the time that hour ends. For a holder that is not live, the result also names that holder and its state. The next session to hold the role live before kept_until gets the message. That can be the same holder when it answers again. If no session takes the message by kept_until, Envoy drops it. If the publish named your session as its source, Envoy then sends your session a message that names the dropped message, unless it dropped it more than an hour late. Third, the listener keeps nothing and errs, which tells you to reach the agent some other way: the holder refuses the message, or the forward is not stored within four seconds. A team topic (such as notifications.team.deploy-squad.all) is stored like every other, so a session subscribed to it that was away still receives it when it returns, and one that subscribes after you publish does not. A notifications. topic no stream subject captures is refused by name: nothing would store it. ${PUBLISH_COUNTS} ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT}`,
63167
+ description: `Publish an Envoy message to a notifications. topic. ${STORED_DELIVERY} A role or built-in topic is delivered as its guide says. A role message has three possible answers. First, a live session holds the role, and the stream stores the forward for that holder's consumer. Its 200 says the stream stored it. It does not say that the holder read it. It names the holder and the state the listener resolved the holder in. Second, no live session holds the role: nobody claims it, or its holder is unresponsive or gone. The listener then keeps the message for one hour. This is a success. The result says that the listener kept the message, and its kept_until is the time that hour ends. For a holder that is not live, the result also names that holder and its state. The next session to hold the role live before kept_until gets the message. That can be the same holder when it answers again. If no session takes the message by kept_until, Envoy drops it. If the publish named your session as its source, Envoy then sends your session a message that names the dropped message, unless it dropped it more than an hour late. Third, the listener keeps nothing and errs, which tells you to reach the agent some other way: the holder refuses the message, or the forward is not stored within four seconds. A team topic (such as notifications.team.deploy-squad.all) is stored like every other, so a session subscribed to it that was away still receives it when it returns, and one that subscribes after you publish does not. A notifications. topic no stream subject captures is refused by name: nothing would store it. ${NOT_SENT_GUIDE} ${PUBLISH_COUNTS} ${SESSION_STATE_GUIDE} ${DELIVERY_CONTRACT}`,
63078
63168
  arguments: (schema) => ({ topic: schema.string(), ...messageArguments(schema) }),
63079
63169
  operation: EnvoyToolOperation.publish
63080
63170
  },
@@ -63408,9 +63498,9 @@ var import_nats5 = __toESM(require_mod4(), 1);
63408
63498
 
63409
63499
  // package.json
63410
63500
  var name2 = "@sjawhar/claude-envoy";
63411
- var version2 = "5.27.1";
63501
+ var version2 = "5.28.0";
63412
63502
  var legion = {
63413
- daemonApiVersion: 256
63503
+ daemonApiVersion: 275
63414
63504
  };
63415
63505
  var package_default = {
63416
63506
  name: name2,
@@ -64608,13 +64698,13 @@ function createChannelTopics(connection, options = {}) {
64608
64698
  }
64609
64699
 
64610
64700
  // src/session-identity.ts
64611
- import { readFile as readFile6 } from "fs/promises";
64612
- 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";
64613
64703
 
64614
64704
  // src/session-state.ts
64615
64705
  import { readFileSync as readFileSync6 } from "fs";
64616
64706
  import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
64617
- import { dirname as dirname4, join as join9 } from "path";
64707
+ import { dirname as dirname4, join as join10 } from "path";
64618
64708
  async function writeAtomicStateFile(file, contents) {
64619
64709
  await mkdir2(dirname4(file), { recursive: true, mode: 448 });
64620
64710
  const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
@@ -64632,7 +64722,7 @@ async function pruneStateDirectory(directory, isStale) {
64632
64722
  throw error;
64633
64723
  });
64634
64724
  for (const entry of entries) {
64635
- const file = join9(directory, entry);
64725
+ const file = join10(directory, entry);
64636
64726
  if (!await isStale(file))
64637
64727
  continue;
64638
64728
  await rm4(file, { recursive: true, force: true });
@@ -64647,7 +64737,7 @@ async function writtenLongAgo(file) {
64647
64737
  }
64648
64738
  var TITLES_DIRECTORY = "titles";
64649
64739
  function sessionTitleFile(stateDirectory, sessionId) {
64650
- return join9(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
64740
+ return join10(stateDirectory, TITLES_DIRECTORY, `${encodeURIComponent(sessionId)}.txt`);
64651
64741
  }
64652
64742
  async function writeChosenTitle(file, title) {
64653
64743
  await writeAtomicStateFile(file, `${title}
@@ -64675,7 +64765,7 @@ async function recordChosenTitle(sessionId, title) {
64675
64765
  await writeChosenTitle(file, chosen);
64676
64766
  }
64677
64767
  async function pruneStaleSessionTitles(stateDirectory) {
64678
- await pruneStateDirectory(join9(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
64768
+ await pruneStateDirectory(join10(stateDirectory, TITLES_DIRECTORY), writtenLongAgo);
64679
64769
  }
64680
64770
 
64681
64771
  // src/session-identity.ts
@@ -64700,14 +64790,14 @@ class SessionIdentity {
64700
64790
  }
64701
64791
  }
64702
64792
  function sessionHandoffDirectory(stateDirectory, claudePid) {
64703
- return join10(stateDirectory, "sessions", String(claudePid));
64793
+ return join11(stateDirectory, "sessions", String(claudePid));
64704
64794
  }
64705
64795
  function sessionHandoffFile(stateDirectory, claudePid) {
64706
- return join10(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
64796
+ return join11(sessionHandoffDirectory(stateDirectory, claudePid), "session-id");
64707
64797
  }
64708
64798
  var ROLES_DIRECTORY = "roles";
64709
64799
  function roleStateFile(stateDirectory, sessionId) {
64710
- return join10(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
64800
+ return join11(stateDirectory, ROLES_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
64711
64801
  }
64712
64802
 
64713
64803
  class UnparseableRoleRecordError extends Error {
@@ -64719,7 +64809,7 @@ class UnparseableRoleRecordError extends Error {
64719
64809
  async function readPersistedRole(roleFile) {
64720
64810
  let bytes;
64721
64811
  try {
64722
- bytes = await readFile6(roleFile, "utf8");
64812
+ bytes = await readFile7(roleFile, "utf8");
64723
64813
  } catch (error) {
64724
64814
  if (hasErrnoCode(error, "ENOENT"))
64725
64815
  return;
@@ -64741,7 +64831,7 @@ async function writeSessionHandoff(file, sessionId) {
64741
64831
  }
64742
64832
  async function readSessionHandoff(file) {
64743
64833
  try {
64744
- const id = (await readFile6(file, "utf8")).trim();
64834
+ const id = (await readFile7(file, "utf8")).trim();
64745
64835
  return id.length === 0 ? undefined : id;
64746
64836
  } catch (error) {
64747
64837
  if (hasErrnoCode(error, "ENOENT"))
@@ -64758,14 +64848,14 @@ function processExists(pid) {
64758
64848
  }
64759
64849
  }
64760
64850
  async function pruneStaleSessionHandoffs(stateDirectory) {
64761
- await pruneStateDirectory(join10(stateDirectory, "sessions"), (file) => {
64851
+ await pruneStateDirectory(join11(stateDirectory, "sessions"), (file) => {
64762
64852
  const pid = basename3(file);
64763
64853
  return /^\d+$/.test(pid) && !processExists(Number(pid));
64764
64854
  });
64765
64855
  }
64766
64856
  async function pruneStaleSessionRoles(stateDirectory, currentSessionId) {
64767
64857
  const own = roleStateFile(stateDirectory, currentSessionId);
64768
- 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));
64769
64859
  }
64770
64860
 
64771
64861
  // src/envoy-off.ts
@@ -64823,7 +64913,7 @@ async function serveEnvoyOff(serverInfo, refusal) {
64823
64913
  }
64824
64914
 
64825
64915
  // src/installed-build.ts
64826
- import { dirname as dirname5, join as join11, sep } from "path";
64916
+ import { dirname as dirname5, join as join12, sep } from "path";
64827
64917
  function pluginCacheSegments(bundlePath) {
64828
64918
  const parts = bundlePath.split(sep);
64829
64919
  for (let index = 0;index + 1 < parts.length; index++) {
@@ -64837,12 +64927,12 @@ function installedPluginVersion(bundlePath) {
64837
64927
  }
64838
64928
  function channelConnectionName(name, bundlePath, packageName) {
64839
64929
  const version = installedPluginVersion(bundlePath);
64840
- 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 }));
64841
64931
  }
64842
64932
 
64843
64933
  // src/legion-claim.ts
64844
64934
  import { readdir as readdir4, stat as stat5 } from "fs/promises";
64845
- import { join as join13 } from "path";
64935
+ import { join as join14 } from "path";
64846
64936
  import { setTimeout as delay2 } from "timers/promises";
64847
64937
 
64848
64938
  // ../pi-shared/src/stall-limits.ts
@@ -65300,6 +65390,12 @@ var legionControllerLocator = object({
65300
65390
  var legionAgentSecretsLoginView = object({
65301
65391
  state: string2().optional()
65302
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
+ });
65303
65399
  var legionCapabilityState = object({
65304
65400
  name: nonEmptyString2.optional(),
65305
65401
  status: _enum2(["present", "unchecked", "withheld", "decided", "open"]).optional(),
@@ -65434,6 +65530,7 @@ var LegionStateResponse = object({
65434
65530
  lastPause: legionEndedPause.optional(),
65435
65531
  controllerLocator: legionControllerLocator.optional(),
65436
65532
  agentSecretsLogin: legionAgentSecretsLoginView.optional(),
65533
+ dispatchCredential: legionDispatchCredentialView.optional(),
65437
65534
  capabilities: array(legionCapabilityState).optional(),
65438
65535
  repositories: legionRepositories.optional(),
65439
65536
  settings: legionSettings.optional(),
@@ -66329,7 +66426,7 @@ function listenerAskedToClaimAgain(error) {
66329
66426
  // src/legion-phase-hook.ts
66330
66427
  import { randomUUID as randomUUID7 } from "crypto";
66331
66428
  import { readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
66332
- import { dirname as dirname6, join as join12 } from "path";
66429
+ import { dirname as dirname6, join as join13 } from "path";
66333
66430
 
66334
66431
  // ../pi-shared/src/phase-reminder.ts
66335
66432
  import { randomUUID as randomUUID6 } from "crypto";
@@ -66794,7 +66891,7 @@ function phaseHookToolDefinition() {
66794
66891
  };
66795
66892
  }
66796
66893
  function phaseStallFile(configDir, sessionID) {
66797
- return join12(configDir, `legion-phase-stall-${sessionID}.json`);
66894
+ return join13(configDir, `legion-phase-stall-${sessionID}.json`);
66798
66895
  }
66799
66896
  function paneReminderLog(write) {
66800
66897
  const line = (level, message, context) => {
@@ -66847,7 +66944,7 @@ function readPhaseStallRecord(file, log) {
66847
66944
  };
66848
66945
  }
66849
66946
  function writePhaseStallRecord(file, entry, recreatedNoticeSent, log) {
66850
- const temporary = join12(dirname6(file), `.legion-phase-stall-${randomUUID7()}`);
66947
+ const temporary = join13(dirname6(file), `.legion-phase-stall-${randomUUID7()}`);
66851
66948
  try {
66852
66949
  writeFileSync4(temporary, JSON.stringify({ ...entry, ...recreatedNoticeSent ? { recreatedNoticeSent } : {} }), { mode: 384 });
66853
66950
  renameSync3(temporary, file);
@@ -67055,12 +67152,12 @@ function stopPane(why) {
67055
67152
  endPane();
67056
67153
  }
67057
67154
  async function waitForTranscript(configDir, sessionID, signal, pollMs = 100) {
67058
- const projects = join13(configDir, "projects");
67155
+ const projects = join14(configDir, "projects");
67059
67156
  const name = `${sessionID}.jsonl`;
67060
67157
  for (;; ) {
67061
67158
  signal.throwIfAborted();
67062
67159
  for (const directory of await readdir4(projects).catch(() => [])) {
67063
- const file = join13(projects, directory, name);
67160
+ const file = join14(projects, directory, name);
67064
67161
  if (await isFile(file))
67065
67162
  return file;
67066
67163
  }
@@ -68260,14 +68357,14 @@ function modSession(options) {
68260
68357
  }
68261
68358
 
68262
68359
  // src/replay-state.ts
68263
- import { join as join14 } from "path";
68360
+ import { join as join15 } from "path";
68264
68361
 
68265
68362
  // src/state-file.ts
68266
- import { readFile as readFile7 } from "fs/promises";
68363
+ import { readFile as readFile8 } from "fs/promises";
68267
68364
  async function readStateFile(file, schema, empty, refusal) {
68268
68365
  let text;
68269
68366
  try {
68270
- text = await readFile7(file, "utf8");
68367
+ text = await readFile8(file, "utf8");
68271
68368
  } catch (error) {
68272
68369
  if (hasErrnoCode(error, "ENOENT"))
68273
68370
  return empty;
@@ -68290,7 +68387,7 @@ var ReplayStateFileSchema = LedgerSnapshotSchema.extend({
68290
68387
  consumer: ConsumerDeliverySnapshotSchema.optional()
68291
68388
  });
68292
68389
  function replayStateFile(stateDirectory, sessionId) {
68293
- return join14(stateDirectory, `replay-${encodeURIComponent(sessionId)}.json`);
68390
+ return join15(stateDirectory, `replay-${encodeURIComponent(sessionId)}.json`);
68294
68391
  }
68295
68392
  async function readReplayState(file) {
68296
68393
  return await readStateFile(file, ReplayStateFileSchema, { ledger: [] }, "holds no delivery state");
@@ -68838,7 +68935,7 @@ function createUserTurnRouter(options) {
68838
68935
  }
68839
68936
 
68840
68937
  // src/user-turn-state.ts
68841
- import { join as join15 } from "path";
68938
+ import { join as join16 } from "path";
68842
68939
  var TURNS_DIRECTORY = "turns";
68843
68940
  var HANDLED_ATTEMPTS_MAX = 1000;
68844
68941
  var DELIVERED_ROWS_MAX = 1000;
@@ -68848,7 +68945,7 @@ var UserTurnStateSchema = object({
68848
68945
  rows: array(DeliveredRowSchema).default([])
68849
68946
  });
68850
68947
  function userTurnStateFile(stateDirectory, sessionId) {
68851
- return join15(stateDirectory, TURNS_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
68948
+ return join16(stateDirectory, TURNS_DIRECTORY, `${encodeURIComponent(sessionId)}.json`);
68852
68949
  }
68853
68950
  async function readUserTurnState(file) {
68854
68951
  return await readStateFile(file, UserTurnStateSchema, { handled: [], rows: [] }, "holds no record of this session's turns");
@@ -68886,7 +68983,7 @@ function userTurnState(file, restored) {
68886
68983
  };
68887
68984
  }
68888
68985
  async function pruneStaleSessionTurns(stateDirectory) {
68889
- await pruneStateDirectory(join15(stateDirectory, TURNS_DIRECTORY), writtenLongAgo);
68986
+ await pruneStateDirectory(join16(stateDirectory, TURNS_DIRECTORY), writtenLongAgo);
68890
68987
  }
68891
68988
 
68892
68989
  // src/envoy-channel-server.ts
@@ -68960,6 +69057,13 @@ async function postDispatchReply(identity, configFile, delivery, result) {
68960
69057
  throw new Error(config.error ?? config.notice);
68961
69058
  await postDeliveryReply(config, identity.id, delivery, result);
68962
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
+ }
68963
69067
  function createChannelDelivery(input) {
68964
69068
  const inbox = [];
68965
69069
  let tail = Promise.resolve();
@@ -70299,12 +70403,7 @@ async function runEnvoyChannelServer() {
70299
70403
  });
70300
70404
  const router = (state) => {
70301
70405
  const options = {
70302
- dispatch: async (ms) => {
70303
- const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch);
70304
- return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, {
70305
- deadlineMs: ms
70306
- });
70307
- },
70406
+ dispatch: (ms) => userTurnDispatchClient(identity, configFile, ms),
70308
70407
  effortPicked: (effort) => agentStream?.pickedEffort(effort),
70309
70408
  refreshSettings: () => agentStream?.refresh(),
70310
70409
  reply: (delivery, result) => postDispatchReply(identity, configFile, delivery, result),
@@ -70619,7 +70718,7 @@ function startCodexAgentStream(options) {
70619
70718
  import { spawn } from "child_process";
70620
70719
  import { randomBytes as randomBytes2 } from "crypto";
70621
70720
  import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
70622
- import { join as join16 } from "path";
70721
+ import { join as join17 } from "path";
70623
70722
  var QUEUE_TIMEOUT_MS = 30000;
70624
70723
  function codexProcessEnv(pid, fallback, read = (path) => readFileSync9(path, "utf8")) {
70625
70724
  let raw;
@@ -70688,7 +70787,7 @@ function fitArgument(text, spillDirectory) {
70688
70787
  throw new Error(`the message is ${Buffer.byteLength(text)} bytes, over what codex queue takes`);
70689
70788
  }
70690
70789
  mkdirSync4(spillDirectory, { mode: 448, recursive: true });
70691
- const file = join16(spillDirectory, `${Date.now()}-${randomBytes2(4).toString("hex")}.txt`);
70790
+ const file = join17(spillDirectory, `${Date.now()}-${randomBytes2(4).toString("hex")}.txt`);
70692
70791
  writeFileSync5(file, text, { mode: 384 });
70693
70792
  return `${text.slice(0, QUEUE_HEAD_CHARS)}
70694
70793
 
@@ -70813,11 +70912,11 @@ function askSideQuestion(command, threadId, question, timeoutMs = SIDE_QUESTION_
70813
70912
 
70814
70913
  // src/codex/codex-inbox.ts
70815
70914
  import { randomBytes as randomBytes3 } from "crypto";
70816
- import { mkdir as mkdir4, readdir as readdir5, readFile as readFile8, rename as rename4, rm as rm6, writeFile as writeFile2 } from "fs/promises";
70817
- 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";
70818
70917
  var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
70819
70918
  function codexInboxDirectory(stateDirectory, sessionId) {
70820
- return join17(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
70919
+ return join18(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
70821
70920
  }
70822
70921
  var lastOrder = 0;
70823
70922
  function inboxItemName() {
@@ -70826,17 +70925,17 @@ function inboxItemName() {
70826
70925
  return `${String(order).padStart(15, "0")}-${randomBytes3(4).toString("hex")}.json`;
70827
70926
  }
70828
70927
  async function putInbox(directory, item, name = inboxItemName()) {
70829
- const waiting = join17(directory, "waiting");
70928
+ const waiting = join18(directory, "waiting");
70830
70929
  await mkdir4(waiting, { recursive: true, mode: 448 });
70831
- const temporary = join17(directory, `.${name}.tmp`);
70930
+ const temporary = join18(directory, `.${name}.tmp`);
70832
70931
  await writeFile2(temporary, JSON.stringify(item), { mode: 384 });
70833
- await rename4(temporary, join17(waiting, name));
70932
+ await rename4(temporary, join18(waiting, name));
70834
70933
  return name;
70835
70934
  }
70836
70935
  async function takenBy(directory, name) {
70837
70936
  for (const taker of ["hook", "server"]) {
70838
70937
  try {
70839
- await readFile8(join17(directory, TAKEN_DIRECTORY[taker], name));
70938
+ await readFile9(join18(directory, TAKEN_DIRECTORY[taker], name));
70840
70939
  return taker;
70841
70940
  } catch {}
70842
70941
  }
@@ -70844,14 +70943,14 @@ async function takenBy(directory, name) {
70844
70943
  }
70845
70944
  async function withdrawWaiting(directory, name) {
70846
70945
  try {
70847
- await rm6(join17(directory, "waiting", name));
70946
+ await rm6(join18(directory, "waiting", name));
70848
70947
  return true;
70849
70948
  } catch {
70850
70949
  return false;
70851
70950
  }
70852
70951
  }
70853
70952
  async function discardWaiting(directory, keep = () => false) {
70854
- const waiting = join17(directory, "waiting");
70953
+ const waiting = join18(directory, "waiting");
70855
70954
  let names;
70856
70955
  try {
70857
70956
  names = await readdir5(waiting);
@@ -70863,7 +70962,7 @@ async function discardWaiting(directory, keep = () => false) {
70863
70962
  if (!name.endsWith(".json") || keep(name))
70864
70963
  continue;
70865
70964
  try {
70866
- await rm6(join17(waiting, name));
70965
+ await rm6(join18(waiting, name));
70867
70966
  removed++;
70868
70967
  } catch {}
70869
70968
  }
@@ -70871,7 +70970,7 @@ async function discardWaiting(directory, keep = () => false) {
70871
70970
  }
70872
70971
  var HOOK_CONTEXT_MAX_BYTES = 8000;
70873
70972
  async function takeInbox(directory, taker, maxContextBytes) {
70874
- const waiting = join17(directory, "waiting");
70973
+ const waiting = join18(directory, "waiting");
70875
70974
  let names;
70876
70975
  try {
70877
70976
  names = (await readdir5(waiting)).filter((name) => name.endsWith(".json")).sort();
@@ -70880,14 +70979,14 @@ async function takeInbox(directory, taker, maxContextBytes) {
70880
70979
  }
70881
70980
  if (names.length === 0)
70882
70981
  return [];
70883
- const destination = join17(directory, TAKEN_DIRECTORY[taker]);
70982
+ const destination = join18(directory, TAKEN_DIRECTORY[taker]);
70884
70983
  await mkdir4(destination, { recursive: true, mode: 448 });
70885
70984
  const taken = [];
70886
70985
  for (const name of names) {
70887
70986
  if (maxContextBytes !== undefined) {
70888
70987
  let waitingItem;
70889
70988
  try {
70890
- waitingItem = JSON.parse(await readFile8(join17(waiting, name), "utf8"));
70989
+ waitingItem = JSON.parse(await readFile9(join18(waiting, name), "utf8"));
70891
70990
  } catch {
70892
70991
  continue;
70893
70992
  }
@@ -70898,12 +70997,12 @@ async function takeInbox(directory, taker, maxContextBytes) {
70898
70997
  break;
70899
70998
  }
70900
70999
  try {
70901
- await rename4(join17(waiting, name), join17(destination, name));
71000
+ await rename4(join18(waiting, name), join18(destination, name));
70902
71001
  } catch {
70903
71002
  continue;
70904
71003
  }
70905
71004
  try {
70906
- const parsed = JSON.parse(await readFile8(join17(destination, name), "utf8"));
71005
+ const parsed = JSON.parse(await readFile9(join18(destination, name), "utf8"));
70907
71006
  if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
70908
71007
  taken.push({ item: parsed, name });
70909
71008
  }
@@ -71060,15 +71159,15 @@ function createCodexDelivery(options) {
71060
71159
  }
71061
71160
 
71062
71161
  // src/codex/codex-owner.ts
71063
- 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";
71064
- 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";
71065
71164
 
71066
71165
  // src/codex/codex-session-record.ts
71067
71166
  import { spawnSync } from "child_process";
71068
71167
  import { readFileSync as readFileSync10, readlinkSync as readlinkSync2, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
71069
- 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";
71070
71169
  import { homedir as homedir3 } from "os";
71071
- 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";
71072
71171
  var CodexSessionRecord = object({
71073
71172
  session_id: string2().min(1),
71074
71173
  transcript_path: string2().nullable(),
@@ -71079,10 +71178,10 @@ var CodexSessionRecord = object({
71079
71178
  codex_started: string2().nullable().default(null)
71080
71179
  });
71081
71180
  function codexSessionRecordFile(stateDirectory, pid) {
71082
- return join18(stateDirectory, "codex-sessions", `${pid}.json`);
71181
+ return join19(stateDirectory, "codex-sessions", `${pid}.json`);
71083
71182
  }
71084
71183
  function codexEndedFile(stateDirectory, pid, sessionId) {
71085
- return join18(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
71184
+ return join19(stateDirectory, "codex-sessions", `${pid}.${encodeURIComponent(sessionId)}.ended`);
71086
71185
  }
71087
71186
  async function markSessionEnded(stateDirectory, pid, sessionId) {
71088
71187
  const marker = codexEndedFile(stateDirectory, pid, sessionId);
@@ -71105,7 +71204,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
71105
71204
  }
71106
71205
  async function sessionEnded(file) {
71107
71206
  try {
71108
- await readFile9(file);
71207
+ await readFile10(file);
71109
71208
  return true;
71110
71209
  } catch {
71111
71210
  return false;
@@ -71119,7 +71218,7 @@ async function writeCodexSessionRecord(file, value) {
71119
71218
  }
71120
71219
  async function readCodexSessionRecord(file) {
71121
71220
  try {
71122
- const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile9(file, "utf8")));
71221
+ const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile10(file, "utf8")));
71123
71222
  return parsed.success ? parsed.data : undefined;
71124
71223
  } catch {
71125
71224
  return;
@@ -71127,7 +71226,7 @@ async function readCodexSessionRecord(file) {
71127
71226
  }
71128
71227
  function codexHome(env) {
71129
71228
  const set = env["CODEX_HOME"];
71130
- return set !== undefined && set !== "" ? set : join18(env["HOME"] || homedir3(), ".codex");
71229
+ return set !== undefined && set !== "" ? set : join19(env["HOME"] || homedir3(), ".codex");
71131
71230
  }
71132
71231
  function codexPluginDataDirectory(pluginRoot) {
71133
71232
  const version = pluginRoot;
@@ -71137,7 +71236,7 @@ function codexPluginDataDirectory(pluginRoot) {
71137
71236
  const plugins = dirname8(cache);
71138
71237
  if (basename5(cache) !== "cache" || basename5(plugins) !== "plugins")
71139
71238
  return;
71140
- return join18(plugins, "data", `${basename5(plugin)}-${basename5(marketplace)}`);
71239
+ return join19(plugins, "data", `${basename5(plugin)}-${basename5(marketplace)}`);
71141
71240
  }
71142
71241
  var MAX_ANCESTORS2 = 16;
71143
71242
  function codexProcessId(readComm = procComm, readParent = procParent) {
@@ -71239,11 +71338,11 @@ function codexSubcommand(args) {
71239
71338
  }
71240
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.";
71241
71340
  async function pruneCodexSessionRecords(stateDirectory) {
71242
- await pruneStateDirectory(join18(stateDirectory, "codex-sessions"), (file) => {
71341
+ await pruneStateDirectory(join19(stateDirectory, "codex-sessions"), (file) => {
71243
71342
  const match = /^(\d+)\.(?:json|.+\.ended)$/.exec(basename5(file));
71244
71343
  return match !== null && !processExists(Number(match[1]));
71245
71344
  });
71246
- await pruneStateDirectory(join18(stateDirectory, "codex-servers"), (file) => {
71345
+ await pruneStateDirectory(join19(stateDirectory, "codex-servers"), (file) => {
71247
71346
  const name = basename5(file);
71248
71347
  return /^\d+$/.test(name) && !processExists(Number(name));
71249
71348
  });
@@ -71258,7 +71357,7 @@ function codexExecutable(pid) {
71258
71357
 
71259
71358
  // src/codex/codex-owner.ts
71260
71359
  function codexServersDirectory(stateDirectory, codexPid) {
71261
- return join19(stateDirectory, "codex-servers", String(codexPid));
71360
+ return join20(stateDirectory, "codex-servers", String(codexPid));
71262
71361
  }
71263
71362
  var ENTRY_NAME = /^(\d+)\.json$/;
71264
71363
  var TEMPORARY_NAME = /^\.\d+\.\d+\.tmp$/;
@@ -71267,13 +71366,13 @@ function entryName(entry) {
71267
71366
  }
71268
71367
  async function registerServer(directory, pid, started, list = (path) => readdir6(path)) {
71269
71368
  await mkdir6(directory, { mode: 448, recursive: true });
71270
- const temporary = join19(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
71369
+ const temporary = join20(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
71271
71370
  await writeFile4(temporary, JSON.stringify({ pid, started }), { mode: 384 });
71272
71371
  try {
71273
71372
  let seq = Math.max(0, ...numbered(await list(directory)).map(({ seq: taken }) => taken)) + 1;
71274
71373
  for (;; ) {
71275
71374
  try {
71276
- await place(temporary, join19(directory, entryName({ seq })), pid, started);
71375
+ await place(temporary, join20(directory, entryName({ seq })), pid, started);
71277
71376
  return { pid, seq, started };
71278
71377
  } catch (error) {
71279
71378
  if (error.code !== "EEXIST")
@@ -71301,8 +71400,8 @@ async function place(temporary, target, pid, started) {
71301
71400
  await writeFile4(target, JSON.stringify({ pid, started }), { flag: "wx", mode: 384 });
71302
71401
  }
71303
71402
  async function unregisterServer(directory, self2) {
71304
- const file = join19(directory, entryName(self2));
71305
- const named = await readFile10(file, "utf8").then(serverOf, () => {
71403
+ const file = join20(directory, entryName(self2));
71404
+ const named = await readFile11(file, "utf8").then(serverOf, () => {
71306
71405
  return;
71307
71406
  });
71308
71407
  if (named?.pid === self2.pid && named.started === self2.started)
@@ -71365,7 +71464,7 @@ async function readEntries(directory, probe, now = Date.now) {
71365
71464
  for (const name of names.filter((each) => TEMPORARY_NAME.test(each))) {
71366
71465
  let text;
71367
71466
  try {
71368
- text = await readFile10(join19(directory, name), "utf8");
71467
+ text = await readFile11(join20(directory, name), "utf8");
71369
71468
  } catch {
71370
71469
  publishing = true;
71371
71470
  break;
@@ -71381,13 +71480,13 @@ async function readEntries(directory, probe, now = Date.now) {
71381
71480
  for (const { name, seq } of numbered(names)) {
71382
71481
  let text;
71383
71482
  try {
71384
- text = await readFile10(join19(directory, name), "utf8");
71483
+ text = await readFile11(join20(directory, name), "utf8");
71385
71484
  } catch {
71386
71485
  continue;
71387
71486
  }
71388
71487
  const server = serverOf(text);
71389
71488
  if (server === undefined) {
71390
- const written = await stat7(join19(directory, name)).then((info) => info.mtimeMs, () => {
71489
+ const written = await stat7(join20(directory, name)).then((info) => info.mtimeMs, () => {
71391
71490
  return;
71392
71491
  });
71393
71492
  if (written === undefined)
@@ -71415,7 +71514,7 @@ async function currentOwner(directory, probe = SYSTEM_PROBE) {
71415
71514
  const text = seen.held.get(seq);
71416
71515
  if (text === undefined)
71417
71516
  return;
71418
- const now = await readFile10(join19(directory, entryName({ seq })), "utf8").catch(() => {
71517
+ const now = await readFile11(join20(directory, entryName({ seq })), "utf8").catch(() => {
71419
71518
  return;
71420
71519
  });
71421
71520
  if (now !== text)
@@ -71476,7 +71575,7 @@ async function stillOwner(directory, self2, probe = SYSTEM_PROBE) {
71476
71575
  // src/codex/codex-transcript.ts
71477
71576
  import { watch } from "fs";
71478
71577
  import { open as open4 } from "fs/promises";
71479
- import { join as join20 } from "path";
71578
+ import { join as join21 } from "path";
71480
71579
  function record3(value) {
71481
71580
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
71482
71581
  }
@@ -71746,7 +71845,7 @@ async function findTranscript(home, threadId) {
71746
71845
  const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
71747
71846
  const found = [];
71748
71847
  try {
71749
- 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") })) {
71750
71849
  found.push(file);
71751
71850
  }
71752
71851
  } catch {
@@ -71887,7 +71986,7 @@ function runDispatchCommand(script, args, stdin, options) {
71887
71986
  });
71888
71987
  }
71889
71988
  function stateDirectoryFor(pluginRoot) {
71890
- 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");
71891
71990
  }
71892
71991
  function waitForRecord(file, pid, signal, ended) {
71893
71992
  return new Promise((done) => {
@@ -71975,7 +72074,7 @@ async function runCodexEnvoyServer() {
71975
72074
  env["DISPATCH_HOST"] = "codex";
71976
72075
  if (configFile.path !== null)
71977
72076
  env["ENVOY_CONFIG_FILE"] = configFile.path;
71978
- 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 });
71979
72078
  return `${output}${output.endsWith(`
71980
72079
  `) || output === "" ? "" : `
71981
72080
  `}[exit ${code}]`;
@@ -72115,7 +72214,7 @@ async function runCodexEnvoyServer() {
72115
72214
  const runningSession = () => record?.session_id ?? bound.session_id;
72116
72215
  const codexDelivery = createCodexDelivery({
72117
72216
  inboxDirectory: (sessionId) => codexInboxDirectory(stateDirectory, sessionId),
72118
- queue: (text) => queueMessage(command(), runningSession(), text, join21(stateDirectory, "codex-long-messages")),
72217
+ queue: (text) => queueMessage(command(), runningSession(), text, join22(stateDirectory, "codex-long-messages")),
72119
72218
  sessionId: runningSession,
72120
72219
  taken: (item) => stream?.delivered(item.content, item.dispatchMessageId),
72121
72220
  warn