@sjawhar/claude-envoy 5.25.0 → 5.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44573,17 +44573,16 @@ async function brokerTokenClient(env, own = "", read) {
44573
44573
 
44574
44574
  // ../envoy-client/src/envoy-config.ts
44575
44575
  import {
44576
- chmodSync,
44577
- closeSync as closeSync2,
44578
- existsSync,
44579
- lstatSync,
44580
- mkdtempSync,
44581
- openSync as openSync2,
44582
- readFileSync as readFileSync2,
44583
- readlinkSync,
44584
- rmSync,
44585
- statSync
44586
- } from "fs";
44576
+ access as access2,
44577
+ chmod,
44578
+ lstat as lstat3,
44579
+ mkdtemp,
44580
+ open as open3,
44581
+ readFile as readFile5,
44582
+ readlink as readlink2,
44583
+ rm as rm3,
44584
+ stat as stat3
44585
+ } from "fs/promises";
44587
44586
  import { homedir, tmpdir } from "os";
44588
44587
  import * as path from "path";
44589
44588
 
@@ -44734,15 +44733,44 @@ function jsonErrorPosition(text) {
44734
44733
  }
44735
44734
  }
44736
44735
 
44736
+ // ../envoy-client/src/process-group.ts
44737
+ function killGroup(pid) {
44738
+ try {
44739
+ process.kill(-pid, "SIGKILL");
44740
+ } catch {}
44741
+ }
44742
+ var WATCH = 'exec 3<&0; (while read -r line <&3; do :; done; kill -s KILL -- -$$) </dev/null >/dev/null 2>&1 & exec "$0" "$@" </dev/null 3<&-';
44743
+ function groupWatchedBy(argv) {
44744
+ return ["/bin/sh", "-c", WATCH, ...argv];
44745
+ }
44746
+ function spawnWatched(argv, options) {
44747
+ const child = Bun.spawn(groupWatchedBy(argv), {
44748
+ ...options,
44749
+ stdin: "pipe",
44750
+ detached: true
44751
+ });
44752
+ let closed = false;
44753
+ return {
44754
+ child,
44755
+ endGroup: () => {
44756
+ killGroup(child.pid);
44757
+ if (closed)
44758
+ return;
44759
+ closed = true;
44760
+ child.stdin.end();
44761
+ }
44762
+ };
44763
+ }
44764
+
44737
44765
  // ../envoy-client/src/secret-file.ts
44738
- import { readFileSync } from "fs";
44766
+ import { readFile as readFile4 } from "fs/promises";
44739
44767
  function sendable(value) {
44740
44768
  return !/[\s\p{Cc}]/u.test(value);
44741
44769
  }
44742
- function readSecretFile(variable, filePath) {
44770
+ async function readSecretFile(variable, filePath) {
44743
44771
  let contents;
44744
44772
  try {
44745
- contents = readFileSync(filePath, "utf8");
44773
+ contents = await readFile4(filePath, "utf8");
44746
44774
  } catch (error) {
44747
44775
  throw new Error(`${variable} names a file that could not be read (${readErrorCode(error)})`);
44748
44776
  }
@@ -44877,20 +44905,28 @@ function describeSchemaIssue(filePath, error) {
44877
44905
  }
44878
44906
  return `${filePath}: ${issue.path.join(".")}: ${issue.message}`;
44879
44907
  }
44880
- function danglingLink(filePath) {
44908
+ async function danglingLink(filePath) {
44881
44909
  try {
44882
- return lstatSync(filePath).isSymbolicLink() ? readlinkSync(filePath) : null;
44910
+ return (await lstat3(filePath)).isSymbolicLink() ? await readlink2(filePath) : null;
44883
44911
  } catch {
44884
44912
  return null;
44885
44913
  }
44886
44914
  }
44887
- function parseFile(filePath, schema, checkout) {
44915
+ async function exists(file) {
44916
+ try {
44917
+ await access2(file);
44918
+ return true;
44919
+ } catch {
44920
+ return false;
44921
+ }
44922
+ }
44923
+ async function parseFile(filePath, schema, checkout) {
44888
44924
  let raw;
44889
44925
  try {
44890
- raw = readFileSync2(filePath, "utf-8");
44926
+ raw = await readFile5(filePath, "utf-8");
44891
44927
  } catch (error) {
44892
44928
  if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
44893
- return { kind: "absent", link: danglingLink(filePath) };
44929
+ return { kind: "absent", link: checkout ? null : await danglingLink(filePath) };
44894
44930
  }
44895
44931
  return { kind: "invalid", reason: `${filePath}: could not be read (${messageFor(error)})` };
44896
44932
  }
@@ -44918,53 +44954,77 @@ function parseFile(filePath, schema, checkout) {
44918
44954
  }
44919
44955
  var FAILURE_KEPT_MS = 60000;
44920
44956
  var COMMAND_OUTCOMES = Symbol.for("legion.envoy-config.commands.v1");
44957
+ var COMMAND_RUNS = Symbol.for("legion.envoy-config.command-runs.v1");
44921
44958
  var processGlobal = globalThis;
44922
44959
  var commandOutcomes = processGlobal[COMMAND_OUTCOMES] ?? new Map;
44923
44960
  processGlobal[COMMAND_OUTCOMES] = commandOutcomes;
44924
- function runCommand(command, env, cwd) {
44961
+ var commandRuns = processGlobal[COMMAND_RUNS] ?? new Map;
44962
+ processGlobal[COMMAND_RUNS] = commandRuns;
44963
+ async function unnamedFile() {
44964
+ const directory = await mkdtemp(path.join(tmpdir(), "envoy-command-"));
44965
+ try {
44966
+ await chmod(directory, 448);
44967
+ return await open3(path.join(directory, "stdout"), "wx+", 384);
44968
+ } finally {
44969
+ await rm3(directory, { recursive: true, force: true });
44970
+ }
44971
+ }
44972
+ async function readOutput(file) {
44973
+ const output = Buffer.alloc((await file.stat()).size);
44974
+ let read = 0;
44975
+ while (read < output.length) {
44976
+ const { bytesRead } = await file.read(output, read, output.length - read, read);
44977
+ if (bytesRead === 0)
44978
+ break;
44979
+ read += bytesRead;
44980
+ }
44981
+ return output.toString("utf-8", 0, read);
44982
+ }
44983
+ async function runCommand(command, env, cwd) {
44925
44984
  const timeoutMs = commandTimeoutMs(env);
44926
44985
  const childEnv = {};
44927
44986
  for (const [name, variable] of Object.entries(env)) {
44928
44987
  if (variable !== undefined)
44929
44988
  childEnv[name] = variable;
44930
44989
  }
44931
- const directory = mkdtempSync(path.join(tmpdir(), "envoy-command-"));
44990
+ const file = await unnamedFile();
44932
44991
  try {
44933
- chmodSync(directory, 448);
44934
- const output = path.join(directory, "stdout");
44935
- const fd = openSync2(output, "wx", 384);
44936
- let result;
44992
+ let watched;
44937
44993
  try {
44938
- result = Bun.spawnSync(["/bin/sh", "-c", command], {
44994
+ watched = spawnWatched(["/bin/sh", "-c", command], {
44939
44995
  cwd,
44940
44996
  env: childEnv,
44941
- stdin: "ignore",
44942
- stdout: fd,
44943
- stderr: "ignore",
44944
- timeout: timeoutMs,
44945
- detached: true
44997
+ stdout: file.fd,
44998
+ stderr: "ignore"
44946
44999
  });
44947
45000
  } catch (error) {
44948
45001
  return { failure: `could not start: ${messageFor(error)}`, timedOut: false };
44949
- } finally {
44950
- closeSync2(fd);
44951
45002
  }
45003
+ const { child, endGroup } = watched;
45004
+ let timedOut = false;
45005
+ const timer = setTimeout(() => {
45006
+ timedOut = true;
45007
+ endGroup();
45008
+ }, timeoutMs);
44952
45009
  try {
44953
- process.kill(-result.pid, "SIGKILL");
44954
- } catch {}
44955
- if (result.exitedDueToTimeout) {
45010
+ await child.exited;
45011
+ } finally {
45012
+ clearTimeout(timer);
45013
+ }
45014
+ endGroup();
45015
+ if (timedOut) {
44956
45016
  return {
44957
45017
  failure: `did not finish within ${timeoutMs / 1000} s, and does not run again in this process`,
44958
45018
  timedOut: true
44959
45019
  };
44960
45020
  }
44961
- if (!result.success) {
45021
+ if (child.exitCode !== 0) {
44962
45022
  return {
44963
- failure: `exited with ${result.signalCode ?? `status ${result.exitCode}`}`,
45023
+ failure: `exited with ${child.signalCode ?? `status ${child.exitCode}`}`,
44964
45024
  timedOut: false
44965
45025
  };
44966
45026
  }
44967
- const value = readFileSync2(output, "utf-8").trim();
45027
+ const value = (await readOutput(file)).trim();
44968
45028
  if (value.length === 0)
44969
45029
  return { failure: "printed nothing", timedOut: false };
44970
45030
  if (!sendable(value)) {
@@ -44975,10 +45035,10 @@ function runCommand(command, env, cwd) {
44975
45035
  }
44976
45036
  return { value };
44977
45037
  } finally {
44978
- rmSync(directory, { recursive: true, force: true });
45038
+ await file.close();
44979
45039
  }
44980
45040
  }
44981
- function fileValue(value, field, filePath, env, commands = "run") {
45041
+ async function fileValue(value, field, filePath, env, commands = "run") {
44982
45042
  if (!value.startsWith("!")) {
44983
45043
  if (!sendable(value)) {
44984
45044
  throw new Error(`${filePath}: ${field} holds whitespace or a control character`);
@@ -44994,42 +45054,50 @@ function fileValue(value, field, filePath, env, commands = "run") {
44994
45054
  throw new Error(`${filePath}: ${field}'s command has not run in this process yet, and this read does not run it`);
44995
45055
  }
44996
45056
  } else if (outcome === undefined || "failure" in outcome && !outcome.timedOut && Date.now() - outcome.at >= FAILURE_KEPT_MS) {
44997
- outcome = { ...runCommand(command, env, cwd), at: Date.now() };
44998
- commandOutcomes.set(key, outcome);
45057
+ let run = commandRuns.get(key);
45058
+ if (run === undefined) {
45059
+ run = runCommand(command, env, cwd).then((ran) => {
45060
+ const kept = { ...ran, at: Date.now() };
45061
+ commandOutcomes.set(key, kept);
45062
+ return kept;
45063
+ }).finally(() => commandRuns.delete(key));
45064
+ commandRuns.set(key, run);
45065
+ }
45066
+ outcome = await run;
44999
45067
  }
45000
45068
  if ("failure" in outcome)
45001
45069
  throw new Error(`${filePath}: ${field}'s command ${outcome.failure}`);
45002
45070
  return outcome.value;
45003
45071
  }
45004
- function statDevice(directory) {
45072
+ async function statDevice(directory) {
45005
45073
  try {
45006
- return statSync(directory).dev;
45074
+ return (await stat3(directory)).dev;
45007
45075
  } catch {
45008
45076
  return;
45009
45077
  }
45010
45078
  }
45011
- function moveNotice(oldFile, newFile, move, deviceOf) {
45012
- const oldDevice = deviceOf(path.dirname(oldFile));
45079
+ async function moveNotice(oldFile, newFile, move, deviceOf) {
45080
+ const oldDevice = await deviceOf(path.dirname(oldFile));
45013
45081
  let ancestor = path.dirname(newFile);
45014
- let newDevice = deviceOf(ancestor);
45082
+ let newDevice = await deviceOf(ancestor);
45015
45083
  while (newDevice === undefined && path.dirname(ancestor) !== ancestor) {
45016
45084
  ancestor = path.dirname(ancestor);
45017
- newDevice = deviceOf(ancestor);
45085
+ newDevice = await deviceOf(ancestor);
45018
45086
  }
45019
45087
  if (oldDevice !== undefined && newDevice !== undefined && oldDevice !== newDevice) {
45020
45088
  return `${oldFile} is not read, and is on another filesystem than ${newFile} (a mount): create ${newFile}, and move ${oldFile} on the machine that owns it`;
45021
45089
  }
45022
45090
  return `${oldFile} is not read: ${move}`;
45023
45091
  }
45024
- function oldUserFileNotice(filePath, env, deviceOf) {
45092
+ async function oldUserFileNotice(filePath, env, deviceOf) {
45025
45093
  const home = nonEmpty(env.HOME) ?? homedir();
45026
45094
  const old = path.join(home, ".config", "opencode", "envoy.json");
45027
- if (!existsSync(old))
45095
+ if (!await exists(old))
45028
45096
  return;
45029
45097
  const selected = path.resolve(filePath);
45030
45098
  const userFile = path.resolve(home, ".config", "legion", "envoy.json");
45031
45099
  if (selected === userFile) {
45032
- return moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
45100
+ return await moveNotice(old, userFile, "mkdir -p ~/.config/legion && mv ~/.config/opencode/envoy.json ~/.config/legion/", deviceOf);
45033
45101
  }
45034
45102
  const profileFile = PLUGIN_HARNESSES.map((harness) => namedDirectory(harness, env)).some((directory) => directory !== undefined && path.isAbsolute(directory) && selected === path.resolve(directory, "envoy.json"));
45035
45103
  if (profileFile) {
@@ -45047,14 +45115,18 @@ function missingConfigNotice(filePath, missing, off) {
45047
45115
  const old = missing.oldUserFileNotice === undefined ? "" : `; ${missing.oldUserFileNotice}`;
45048
45116
  return `no envoy.json at ${filePath}${link}: ${off}${old}`;
45049
45117
  }
45050
- function readEnvoyConfig(filePath, env, options) {
45118
+ async function readEnvoyConfig(filePath, env, options) {
45051
45119
  const deviceOf = options.deviceOf ?? statDevice;
45052
- const chosen = parseFile(filePath, EnvoyFileSchema, false);
45053
- if (chosen.kind === "invalid")
45054
- return { kind: "failed", path: filePath, error: chosen.reason };
45055
45120
  const resolvedChosen = path.resolve(filePath);
45056
45121
  const checkoutPath = path.resolve(options.cwd, ".envoy", "envoy.json");
45057
- const checkoutFile = checkoutPath === resolvedChosen ? { kind: "absent", link: null } : parseFile(checkoutPath, CheckoutFileSchema, true);
45122
+ const oldCheckout = path.resolve(options.cwd, ".opencode", "envoy.json");
45123
+ const [chosen, checkoutFile, oldCheckoutThere] = await Promise.all([
45124
+ parseFile(filePath, EnvoyFileSchema, false),
45125
+ checkoutPath === resolvedChosen ? Promise.resolve({ kind: "absent", link: null }) : parseFile(checkoutPath, CheckoutFileSchema, true),
45126
+ oldCheckout === resolvedChosen ? Promise.resolve(false) : exists(oldCheckout)
45127
+ ]);
45128
+ if (chosen.kind === "invalid")
45129
+ return { kind: "failed", path: filePath, error: chosen.reason };
45058
45130
  const own = chosen.kind === "valid" ? chosen.settings : {};
45059
45131
  let checkout = null;
45060
45132
  if (checkoutFile.kind === "invalid") {
@@ -45068,11 +45140,11 @@ function readEnvoyConfig(filePath, env, options) {
45068
45140
  askgateError: Object.hasOwn(checkoutFile.settings, "askgate") ? `askgate in ${checkoutPath} is not read; set it in ${filePath}` : null
45069
45141
  };
45070
45142
  }
45071
- const oldCheckout = path.resolve(options.cwd, ".opencode", "envoy.json");
45072
- const warnings = oldCheckout !== resolvedChosen && !existsSync(checkoutPath) && existsSync(oldCheckout) ? [
45073
- moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
45143
+ const checkoutMissing = checkoutPath === resolvedChosen ? chosen.kind === "absent" : checkoutFile.kind === "absent" || checkoutFile.kind === "invalid" && !await exists(checkoutPath);
45144
+ const warnings = oldCheckout !== resolvedChosen && checkoutMissing && oldCheckoutThere ? [
45145
+ await moveNotice(oldCheckout, checkoutPath, `mkdir -p ${path.dirname(checkoutPath)} && mv ${oldCheckout} ${checkoutPath}`, deviceOf)
45074
45146
  ] : [];
45075
- const unreadOldUserFile = chosen.kind === "absent" ? oldUserFileNotice(filePath, env, deviceOf) : undefined;
45147
+ const unreadOldUserFile = chosen.kind === "absent" ? await oldUserFileNotice(filePath, env, deviceOf) : undefined;
45076
45148
  return {
45077
45149
  kind: "read",
45078
45150
  path: filePath,
@@ -45100,10 +45172,10 @@ function bearerCredential(token) {
45100
45172
  secret: () => token
45101
45173
  };
45102
45174
  }
45103
- function bearerSource(env, section, written) {
45175
+ async function bearerSource(env, section, written) {
45104
45176
  const pointer = nonEmpty(env[`${section}_TOKEN_FILE`]);
45105
45177
  if (pointer !== undefined) {
45106
- return { kind: "variable", token: readSecretFile(`${section}_TOKEN_FILE`, pointer) };
45178
+ return { kind: "variable", token: await readSecretFile(`${section}_TOKEN_FILE`, pointer) };
45107
45179
  }
45108
45180
  const plain = nonEmpty(env[`${section}_TOKEN`]);
45109
45181
  if (plain !== undefined) {
@@ -45115,7 +45187,7 @@ function bearerSource(env, section, written) {
45115
45187
  const bearer = written();
45116
45188
  return bearer === undefined ? { kind: "none" } : { kind: "file", ...bearer };
45117
45189
  }
45118
- function fileBearer(bearer, url, section, env, commands = "run") {
45190
+ async function fileBearer(bearer, url, section, env, commands = "run") {
45119
45191
  const named = httpUrl2(url)?.origin;
45120
45192
  const paired = httpUrl2(bearer.server)?.origin;
45121
45193
  if (named !== paired) {
@@ -45288,14 +45360,14 @@ function brokerCredential(env, session, read) {
45288
45360
  }
45289
45361
 
45290
45362
  // ../envoy-client/src/file-token-credential.ts
45291
- import { readFileSync as readFileSync3 } from "fs";
45363
+ import { readFileSync } from "fs";
45292
45364
  var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
45293
45365
  var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
45294
45366
  var PKCS8_LABEL = "PRIVATE KEY";
45295
45367
  var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
45296
45368
  function readNamed(variable, filePath) {
45297
45369
  try {
45298
- return readFileSync3(filePath, "utf8");
45370
+ return readFileSync(filePath, "utf8");
45299
45371
  } catch (error) {
45300
45372
  throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
45301
45373
  }
@@ -45383,8 +45455,8 @@ function lostDispatchUrlNotice(env, config) {
45383
45455
  ...old === undefined ? [] : [old]
45384
45456
  ].join("; ");
45385
45457
  }
45386
- function dispatchSettings(env, config, options = {}) {
45387
- const target = dispatchTarget(env, config, options.tokenFiles === true);
45458
+ async function dispatchSettings(env, config, options = {}) {
45459
+ const target = await dispatchTarget(env, config, options.tokenFiles === true);
45388
45460
  if (!target.enabled)
45389
45461
  return target;
45390
45462
  const { url, urlSetting, source } = target;
@@ -45395,7 +45467,7 @@ function dispatchSettings(env, config, options = {}) {
45395
45467
  else if (source.kind === "files")
45396
45468
  credential = fileTokenCredential(source, url);
45397
45469
  else {
45398
- credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
45470
+ credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "DISPATCH", env, options.commands));
45399
45471
  }
45400
45472
  } catch (error) {
45401
45473
  return offWithError(messageFor(error));
@@ -45415,8 +45487,8 @@ function dispatchSettings(env, config, options = {}) {
45415
45487
  ...linkNotice === undefined ? {} : { linkNotice }
45416
45488
  };
45417
45489
  }
45418
- function dispatchUrl(env, config) {
45419
- const target = dispatchTarget(env, config);
45490
+ async function dispatchUrl(env, config) {
45491
+ const target = await dispatchTarget(env, config);
45420
45492
  return target.enabled ? target.url : undefined;
45421
45493
  }
45422
45494
  var BESIDE_TOKEN_FILES = [
@@ -45520,7 +45592,7 @@ function readTradeSetting(env) {
45520
45592
  }
45521
45593
  return { asOf: cut };
45522
45594
  }
45523
- function dispatchTarget(env, config, tokenFiles = false) {
45595
+ async function dispatchTarget(env, config, tokenFiles = false) {
45524
45596
  if (config.kind === "failed")
45525
45597
  return offWithError(config.error);
45526
45598
  const files = tokenFilesTarget(env, config, tokenFiles);
@@ -45559,7 +45631,7 @@ function dispatchTarget(env, config, tokenFiles = false) {
45559
45631
  let source = { kind: "none" };
45560
45632
  if (!forced) {
45561
45633
  try {
45562
- source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
45634
+ source = checkout !== null && checkoutServer !== undefined ? checkoutPair(checkout, checkoutServer) : await bearerSource(env, "DISPATCH", () => writtenToken(config, checkout));
45563
45635
  } catch (error) {
45564
45636
  return offWithError(messageFor(error));
45565
45637
  }
@@ -46984,7 +47056,7 @@ class DispatchClient {
46984
47056
 
46985
47057
  // ../envoy-client/src/dispatch-session-directory.ts
46986
47058
  import { randomUUID as randomUUID5 } from "crypto";
46987
- import { renameSync, rmSync as rmSync2, writeFileSync } from "fs";
47059
+ import { renameSync, rmSync, writeFileSync } from "fs";
46988
47060
  import { homedir as homedir2 } from "os";
46989
47061
  import { join as join5 } from "path";
46990
47062
  var SESSION_ID_PATH_SEGMENT = /^[A-Za-z0-9._-]{1,128}$/;
@@ -47007,7 +47079,7 @@ function writeAtomically(path, text) {
47007
47079
  writeFileSync(temporary, text, { mode: PRIVATE_FILE });
47008
47080
  renameSync(temporary, path);
47009
47081
  } catch (error) {
47010
- rmSync2(temporary, { force: true });
47082
+ rmSync(temporary, { force: true });
47011
47083
  throw error;
47012
47084
  }
47013
47085
  }
@@ -47016,15 +47088,15 @@ function writeAtomically(path, text) {
47016
47088
  import { createHash as createHash3 } from "crypto";
47017
47089
  import {
47018
47090
  appendFileSync as appendFileSync2,
47019
- closeSync as closeSync4,
47091
+ closeSync as closeSync3,
47020
47092
  fstatSync as fstatSync2,
47021
47093
  mkdirSync as mkdirSync3,
47022
- openSync as openSync4,
47094
+ openSync as openSync3,
47023
47095
  readdirSync as readdirSync2,
47024
- readFileSync as readFileSync6,
47096
+ readFileSync as readFileSync4,
47025
47097
  readSync as readSync2,
47026
- rmSync as rmSync4,
47027
- statSync as statSync3,
47098
+ rmSync as rmSync3,
47099
+ statSync as statSync2,
47028
47100
  writeFileSync as writeFileSync3
47029
47101
  } from "fs";
47030
47102
  import { join as join8 } from "path";
@@ -47032,16 +47104,16 @@ import { join as join8 } from "path";
47032
47104
  // ../envoy-client/src/askgate-marker.ts
47033
47105
  import { createHash as createHash2, randomBytes } from "crypto";
47034
47106
  import {
47035
- closeSync as closeSync3,
47107
+ closeSync as closeSync2,
47036
47108
  constants as constants3,
47037
47109
  mkdirSync,
47038
- openSync as openSync3,
47110
+ openSync as openSync2,
47039
47111
  readdirSync,
47040
- readFileSync as readFileSync4,
47041
- readlinkSync as readlinkSync2,
47112
+ readFileSync as readFileSync2,
47113
+ readlinkSync,
47042
47114
  renameSync as renameSync2,
47043
- rmSync as rmSync3,
47044
- statSync as statSync2,
47115
+ rmSync as rmSync2,
47116
+ statSync,
47045
47117
  unlinkSync,
47046
47118
  utimesSync,
47047
47119
  writeFileSync as writeFileSync2
@@ -47112,7 +47184,7 @@ function bytesDigest(bytes) {
47112
47184
  }
47113
47185
  function processStart(pid) {
47114
47186
  try {
47115
- const stat = readFileSync4(`/proc/${pid}/stat`, "utf-8");
47187
+ const stat = readFileSync2(`/proc/${pid}/stat`, "utf-8");
47116
47188
  return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? null;
47117
47189
  } catch {
47118
47190
  return null;
@@ -47122,7 +47194,7 @@ var ownNamespace;
47122
47194
  function pidNamespace() {
47123
47195
  if (ownNamespace === undefined) {
47124
47196
  try {
47125
- ownNamespace = /^pid:\[([0-9]+)\]$/.exec(readlinkSync2("/proc/self/ns/pid"))?.[1] ?? null;
47197
+ ownNamespace = /^pid:\[([0-9]+)\]$/.exec(readlinkSync("/proc/self/ns/pid"))?.[1] ?? null;
47126
47198
  } catch {
47127
47199
  ownNamespace = null;
47128
47200
  }
@@ -47170,9 +47242,9 @@ function parseOwner(text) {
47170
47242
  var OWNER_FILE = ".json";
47171
47243
  var STORE_NAME = /^([1-9][0-9]*)(?:-([0-9]+)(?:-([0-9]+))?)?$/;
47172
47244
  function storeTouched(store) {
47173
- const own = statSync2(store).mtimeMs;
47245
+ const own = statSync(store).mtimeMs;
47174
47246
  try {
47175
- return Math.max(own, statSync2(join6(store, MARKERS)).mtimeMs);
47247
+ return Math.max(own, statSync(join6(store, MARKERS)).mtimeMs);
47176
47248
  } catch (error) {
47177
47249
  if (hasErrnoCode(error, "ENOENT"))
47178
47250
  return own;
@@ -47201,7 +47273,7 @@ function sweepStores(root, now) {
47201
47273
  const keep = unnamespaced ? UNNAMESPACED_STORE_MAX_AGE_MS : MARKER_MAX_AGE_MS;
47202
47274
  if (now - storeTouched(store) <= keep)
47203
47275
  continue;
47204
- rmSync3(store, { recursive: true, force: true });
47276
+ rmSync2(store, { recursive: true, force: true });
47205
47277
  } catch {}
47206
47278
  }
47207
47279
  }
@@ -47217,10 +47289,10 @@ function recordNamesStore(dir) {
47217
47289
  if (!name.endsWith(OWNER_FILE))
47218
47290
  continue;
47219
47291
  try {
47220
- const parsed = parseOwner(readFileSync4(join6(record, name), "utf-8"));
47292
+ const parsed = parseOwner(readFileSync2(join6(record, name), "utf-8"));
47221
47293
  if (parsed === undefined)
47222
47294
  return true;
47223
- statSync2(parsed.owner.store);
47295
+ statSync(parsed.owner.store);
47224
47296
  return true;
47225
47297
  } catch (error) {
47226
47298
  if (!hasErrnoCode(error, "ENOENT"))
@@ -47246,7 +47318,7 @@ function askgateState(dir, now = Date.now()) {
47246
47318
  const file = join6(record, name);
47247
47319
  let text;
47248
47320
  try {
47249
- text = readFileSync4(file, "utf-8");
47321
+ text = readFileSync2(file, "utf-8");
47250
47322
  } catch (error) {
47251
47323
  if (hasErrnoCode(error, "ENOENT"))
47252
47324
  continue;
@@ -47263,7 +47335,7 @@ function askgateState(dir, now = Date.now()) {
47263
47335
  return { kind: "off" };
47264
47336
  for (const { file, store } of live) {
47265
47337
  try {
47266
- if (!statSync2(join6(store, MARKERS)).isDirectory())
47338
+ if (!statSync(join6(store, MARKERS)).isDirectory())
47267
47339
  throw new Error("not a directory");
47268
47340
  } catch (error) {
47269
47341
  return {
@@ -47282,11 +47354,11 @@ var isFileDigest = (value) => typeof value === "object" && value !== null && typ
47282
47354
  function readMarker(file) {
47283
47355
  let text;
47284
47356
  try {
47285
- const fd = openSync3(file, constants3.O_RDONLY | constants3.O_NOFOLLOW);
47357
+ const fd = openSync2(file, constants3.O_RDONLY | constants3.O_NOFOLLOW);
47286
47358
  try {
47287
- text = readFileSync4(fd, "utf-8");
47359
+ text = readFileSync2(fd, "utf-8");
47288
47360
  } finally {
47289
- closeSync3(fd);
47361
+ closeSync2(fd);
47290
47362
  }
47291
47363
  } catch {
47292
47364
  return;
@@ -47325,7 +47397,7 @@ function consumeMarker(stores, argv, args, files, now) {
47325
47397
  continue;
47326
47398
  if (now - marker.createdAt > MARKER_MAX_AGE_MS) {
47327
47399
  expired = true;
47328
- rmSync3(file, { force: true });
47400
+ rmSync2(file, { force: true });
47329
47401
  continue;
47330
47402
  }
47331
47403
  if (marker.args !== null) {
@@ -56331,7 +56403,7 @@ async function reviewCommand(context) {
56331
56403
  }
56332
56404
 
56333
56405
  // ../envoy-client/src/session-answers.ts
56334
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync5 } from "fs";
56406
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3 } from "fs";
56335
56407
  import { join as join7 } from "path";
56336
56408
 
56337
56409
  // ../envoy-client/src/json-line-record.ts
@@ -56472,7 +56544,7 @@ processGlobal2[STATE_KEY] = state;
56472
56544
  var CACHE_FILE = "answers.json";
56473
56545
  function readCacheFile(directory, url) {
56474
56546
  try {
56475
- const value = JSON.parse(readFileSync5(join7(directory, CACHE_FILE), "utf-8"));
56547
+ const value = JSON.parse(readFileSync3(join7(directory, CACHE_FILE), "utf-8"));
56476
56548
  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)) {
56477
56549
  return {
56478
56550
  dispatch_url: value.dispatch_url,
@@ -56981,7 +57053,7 @@ function ensureDirectory(dir) {
56981
57053
  }
56982
57054
  function readIfPresent(path) {
56983
57055
  try {
56984
- return readFileSync6(path, "utf-8");
57056
+ return readFileSync4(path, "utf-8");
56985
57057
  } catch (error) {
56986
57058
  if (hasErrnoCode(error, "ENOENT"))
56987
57059
  return;
@@ -57064,7 +57136,7 @@ function readSessionTitle(dir) {
57064
57136
  function pruneSessions(root, now) {
57065
57137
  const stamp = join8(root, PRUNED_STAMP);
57066
57138
  try {
57067
- if (now - statSync3(stamp).mtimeMs < PRUNE_INTERVAL_MS)
57139
+ if (now - statSync2(stamp).mtimeMs < PRUNE_INTERVAL_MS)
57068
57140
  return;
57069
57141
  } catch (error) {
57070
57142
  if (!hasErrnoCode(error, "ENOENT"))
@@ -57083,9 +57155,9 @@ function pruneSessions(root, now) {
57083
57155
  continue;
57084
57156
  const dir = join8(sessions, entry.name);
57085
57157
  try {
57086
- const idle = now - statSync3(dir).mtimeMs > IDLE_SESSION_MS;
57158
+ const idle = now - statSync2(dir).mtimeMs > IDLE_SESSION_MS;
57087
57159
  if (idle && askgateState(dir, now).kind === "off" && !recordNamesStore(dir)) {
57088
- rmSync4(dir, { recursive: true, force: true });
57160
+ rmSync3(dir, { recursive: true, force: true });
57089
57161
  }
57090
57162
  } catch (error) {
57091
57163
  if (!hasErrnoCode(error, "ENOENT"))
@@ -57491,13 +57563,13 @@ function resolvedInterval(raw, fallback) {
57491
57563
  return named === undefined ? fallback : Math.min(Math.max(named, MIN_INTERVAL_MS), MAX_INTERVAL_MS);
57492
57564
  }
57493
57565
  var ENVOY_INBOUND_VAR = "ENVOY_INBOUND";
57494
- function natsSeedFromEnvironment(env) {
57566
+ async function natsSeedFromEnvironment(env) {
57495
57567
  const { NATS_NKEY_SEED_FILE: file, NATS_NKEY_SEED: plain } = env;
57496
57568
  if (file !== undefined) {
57497
57569
  if (file === "")
57498
57570
  throw new Error("NATS_NKEY_SEED_FILE is set but empty");
57499
57571
  return {
57500
- value: readSecretFile("NATS_NKEY_SEED_FILE", file),
57572
+ value: await readSecretFile("NATS_NKEY_SEED_FILE", file),
57501
57573
  source: "the file NATS_NKEY_SEED_FILE names"
57502
57574
  };
57503
57575
  }
@@ -57526,23 +57598,23 @@ function requireFileServers(section, namedNatsUrls, filePath, remedy) {
57526
57598
  throw new Error(`ENVOY_NATS_URL names other servers than ${filePath}'s envoy.natsUrls; set ${remedy} for them`);
57527
57599
  }
57528
57600
  }
57529
- function natsSeed(env, section, namedNatsUrls, filePath) {
57530
- const fromEnvironment = natsSeedFromEnvironment(env);
57601
+ async function natsSeed(env, section, namedNatsUrls, filePath) {
57602
+ const fromEnvironment = await natsSeedFromEnvironment(env);
57531
57603
  if (fromEnvironment !== undefined || section.natsSeed === undefined)
57532
57604
  return fromEnvironment;
57533
57605
  requireFileServers(section, namedNatsUrls, filePath, "NATS_NKEY_SEED_FILE");
57534
57606
  return {
57535
- value: fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
57607
+ value: await fileValue(section.natsSeed, "envoy.natsSeed", filePath, env),
57536
57608
  source: `envoy.natsSeed in ${filePath}`
57537
57609
  };
57538
57610
  }
57539
- function natsCredential(env, section, namedNatsUrls, filePath, session) {
57611
+ async function natsCredential(env, section, namedNatsUrls, filePath, session) {
57540
57612
  const named = nonEmpty(env.NATS_AUTH);
57541
57613
  const auth = named !== undefined ? { value: named, source: NATS_AUTH_VAR } : section.natsAuth === undefined ? undefined : { value: section.natsAuth, source: `envoy.natsAuth in ${filePath}` };
57542
57614
  if (auth !== undefined && auth.value !== "broker" && auth.value !== "none") {
57543
57615
  throw new Error(`${auth.source} is neither broker nor none`);
57544
57616
  }
57545
- const seed = natsSeed(env, section, namedNatsUrls, filePath);
57617
+ const seed = await natsSeed(env, section, namedNatsUrls, filePath);
57546
57618
  if (seed !== undefined) {
57547
57619
  if (auth?.value === "broker") {
57548
57620
  throw new Error(`${auth.source} is ${auth.value}, and ${seed.source} names an nkey seed: set one of the two`);
@@ -57587,7 +57659,7 @@ function plainHttpOffMachine(url) {
57587
57659
  const host = URL.canParse(url) ? new URL(url) : undefined;
57588
57660
  return host?.protocol === "http:" && !LOOPBACK_HOST2.test(host.hostname) ? host.hostname : undefined;
57589
57661
  }
57590
- function envoySettings(env, config, options = {}) {
57662
+ async function envoySettings(env, config, options = {}) {
57591
57663
  if (config.kind === "failed")
57592
57664
  return offWithError(config.error);
57593
57665
  const section = config.envoy;
@@ -57618,7 +57690,7 @@ function envoySettings(env, config, options = {}) {
57618
57690
  let credential;
57619
57691
  let noBrokerRoute = "";
57620
57692
  try {
57621
- const source = bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
57693
+ const source = await bearerSource(env, "ENVOY", () => section.token === undefined ? undefined : {
57622
57694
  token: section.token,
57623
57695
  field: "envoy.token",
57624
57696
  path: config.path,
@@ -57631,7 +57703,7 @@ function envoySettings(env, config, options = {}) {
57631
57703
  if (!route.traded)
57632
57704
  noBrokerRoute = route.gap;
57633
57705
  } else {
57634
- credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "ENVOY", env));
57706
+ credential = bearerCredential(source.kind === "variable" ? source.token : await fileBearer(source, url, "ENVOY", env));
57635
57707
  }
57636
57708
  } catch (error) {
57637
57709
  return offWithError(messageFor(error));
@@ -57651,7 +57723,7 @@ function envoySettings(env, config, options = {}) {
57651
57723
  inbound = {
57652
57724
  natsUrls,
57653
57725
  natsServersSetting: natsSetting,
57654
- natsCredential: natsCredential(env, section, namedNatsUrls, config.path, options.session)
57726
+ natsCredential: await natsCredential(env, section, namedNatsUrls, config.path, options.session)
57655
57727
  };
57656
57728
  } catch (error) {
57657
57729
  inbound = error instanceof NoSessionNamedError ? { off: messageFor(error), noSessionNamed: true } : { off: messageFor(error) };
@@ -57735,26 +57807,28 @@ function startNotice(config, dispatch, envoy, nats, lost) {
57735
57807
  }
57736
57808
  return parts.length === 0 ? null : parts.join("; ");
57737
57809
  }
57738
- function sessionSettings(file, env, options) {
57810
+ async function sessionSettings(file, env, options) {
57739
57811
  if (file.path === null) {
57740
57812
  const off = offWithError(file.error);
57741
57813
  return { dispatch: off, envoy: off, notice: `${file.error}: Dispatch and Envoy are off` };
57742
57814
  }
57743
- const config = readEnvoyConfig(file.path, env, options);
57744
- const dispatch = dispatchSettings(env, config, { session: options.session });
57745
- const envoy = envoySettings(env, config, { nats: options.nats, session: options.session });
57815
+ const config = await readEnvoyConfig(file.path, env, options);
57816
+ const [dispatch, envoy] = await Promise.all([
57817
+ dispatchSettings(env, config, { session: options.session }),
57818
+ envoySettings(env, config, { nats: options.nats, session: options.session })
57819
+ ]);
57746
57820
  return {
57747
57821
  dispatch,
57748
57822
  envoy,
57749
57823
  notice: startNotice(config, dispatch, envoy, options.nats !== false, config.kind === "read" ? lostDispatchUrlNotice(env, config) : undefined)
57750
57824
  };
57751
57825
  }
57752
- function sessionDispatchSettings(file, env, options) {
57826
+ async function sessionDispatchSettings(file, env, options) {
57753
57827
  if (file.path === null)
57754
57828
  return { dispatch: offWithError(file.error), warnings: [], missing: null };
57755
- const config = readEnvoyConfig(file.path, env, options);
57829
+ const config = await readEnvoyConfig(file.path, env, options);
57756
57830
  return {
57757
- dispatch: dispatchSettings(env, config, {
57831
+ dispatch: await dispatchSettings(env, config, {
57758
57832
  commands: options.commands,
57759
57833
  session: options.session,
57760
57834
  tokenFiles: options.tokenFiles
@@ -57763,15 +57837,15 @@ function sessionDispatchSettings(file, env, options) {
57763
57837
  missing: config.kind === "read" ? config.missing : null
57764
57838
  };
57765
57839
  }
57766
- function sessionDispatchUrl(file, env, options) {
57840
+ async function sessionDispatchUrl(file, env, options) {
57767
57841
  if (file.path === null)
57768
57842
  return;
57769
- return dispatchUrl(env, readEnvoyConfig(file.path, env, options));
57843
+ return dispatchUrl(env, await readEnvoyConfig(file.path, env, options));
57770
57844
  }
57771
- function sessionEnvoySettings(file, env, options) {
57845
+ async function sessionEnvoySettings(file, env, options) {
57772
57846
  if (file.path === null)
57773
57847
  return offWithError(file.error);
57774
- return envoySettings(env, readEnvoyConfig(file.path, env, options), {
57848
+ return envoySettings(env, await readEnvoyConfig(file.path, env, options), {
57775
57849
  nats: options.nats,
57776
57850
  session: options.session
57777
57851
  });
@@ -61498,7 +61572,7 @@ function inboundUnavailable(tell, restored) {
61498
61572
  var import_nats2 = __toESM(require_mod4(), 1);
61499
61573
  var import_nats3 = __toESM(require_nats(), 1);
61500
61574
  var import_servers = __toESM(require_servers(), 1);
61501
- import { readFileSync as readFileSync7 } from "fs";
61575
+ import { readFileSync as readFileSync5 } from "fs";
61502
61576
  import { setTimeout as delay } from "timers/promises";
61503
61577
 
61504
61578
  // ../envoy-client/src/nats-auth.ts
@@ -61536,7 +61610,7 @@ var RELEASE_VERSION = /^\d+\.\d+\.\d+$/;
61536
61610
  function clientBuild(stampFile, release) {
61537
61611
  let stamp = "";
61538
61612
  try {
61539
- stamp = readFileSync7(stampFile, "utf8").trim();
61613
+ stamp = readFileSync5(stampFile, "utf8").trim();
61540
61614
  } catch {}
61541
61615
  if (FULL_COMMIT.test(stamp))
61542
61616
  return `legion@${stamp}`;
@@ -62547,7 +62621,7 @@ function claudeProjectDirectory(environment, fallback) {
62547
62621
 
62548
62622
  // src/envoy-channel-server.ts
62549
62623
  import { unwatchFile, watchFile } from "fs";
62550
- import { rm as rm4 } from "fs/promises";
62624
+ import { rm as rm5 } from "fs/promises";
62551
62625
  import { setImmediate as nextTurn } from "timers/promises";
62552
62626
 
62553
62627
  // ../envoy-client/src/relay-registration.ts
@@ -63118,7 +63192,7 @@ import { execFile as execFile2 } from "child_process";
63118
63192
  import { promisify as promisify2 } from "util";
63119
63193
 
63120
63194
  // ../pi-shared/src/git-lock.ts
63121
- import { lstat as lstat3 } from "fs/promises";
63195
+ import { lstat as lstat4 } from "fs/promises";
63122
63196
  var GIT_LOCK_REPORTS = [
63123
63197
  ["The lockfile at '", "' might need manual deletion"],
63124
63198
  ["Unable to create '", "': File exists"]
@@ -63160,7 +63234,7 @@ async function staleGitLockNote(output, now = Date.now()) {
63160
63234
  }
63161
63235
  const notes = [];
63162
63236
  for (const lock of locks) {
63163
- const written = await lstat3(lock).then((info) => info.mtimeMs, () => {
63237
+ const written = await lstat4(lock).then((info) => info.mtimeMs, () => {
63164
63238
  return;
63165
63239
  });
63166
63240
  if (written === undefined)
@@ -63195,7 +63269,7 @@ ${note}`}`);
63195
63269
  };
63196
63270
  function paneLatestHandoff(file, env, cwd, session, fetchImpl = fetch) {
63197
63271
  return async (issue, word) => {
63198
- const { dispatch } = sessionDispatchSettings(file, env, { cwd, session });
63272
+ const { dispatch } = await sessionDispatchSettings(file, env, { cwd, session });
63199
63273
  if (!dispatch.enabled) {
63200
63274
  throw new Error(`Dispatch is off for this pane: ${dispatch.error ?? dispatch.notice}`);
63201
63275
  }
@@ -63321,7 +63395,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
63321
63395
 
63322
63396
  // package.json
63323
63397
  var name2 = "@sjawhar/claude-envoy";
63324
- var version2 = "5.25.0";
63398
+ var version2 = "5.25.1";
63325
63399
  var legion = {
63326
63400
  daemonApiVersion: 256
63327
63401
  };
@@ -64521,12 +64595,12 @@ function createChannelTopics(connection, options = {}) {
64521
64595
  }
64522
64596
 
64523
64597
  // src/session-identity.ts
64524
- import { readFile as readFile4 } from "fs/promises";
64598
+ import { readFile as readFile6 } from "fs/promises";
64525
64599
  import { basename as basename3, join as join10 } from "path";
64526
64600
 
64527
64601
  // src/session-state.ts
64528
- import { readFileSync as readFileSync8 } from "fs";
64529
- import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm3, stat as stat3, utimes as utimes2, writeFile } from "fs/promises";
64602
+ import { readFileSync as readFileSync6 } from "fs";
64603
+ import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm4, stat as stat4, utimes as utimes2, writeFile } from "fs/promises";
64530
64604
  import { dirname as dirname4, join as join9 } from "path";
64531
64605
  async function writeAtomicStateFile(file, contents) {
64532
64606
  await mkdir2(dirname4(file), { recursive: true, mode: 448 });
@@ -64548,12 +64622,12 @@ async function pruneStateDirectory(directory, isStale) {
64548
64622
  const file = join9(directory, entry);
64549
64623
  if (!await isStale(file))
64550
64624
  continue;
64551
- await rm3(file, { recursive: true, force: true });
64625
+ await rm4(file, { recursive: true, force: true });
64552
64626
  }
64553
64627
  }
64554
64628
  var STATE_FILE_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
64555
64629
  async function writtenLongAgo(file) {
64556
- const modified = await stat3(file).then((stats) => stats.mtimeMs, () => {
64630
+ const modified = await stat4(file).then((stats) => stats.mtimeMs, () => {
64557
64631
  return;
64558
64632
  });
64559
64633
  return modified !== undefined && Date.now() - modified > STATE_FILE_MAX_AGE_MS;
@@ -64567,11 +64641,11 @@ async function writeChosenTitle(file, title) {
64567
64641
  `);
64568
64642
  }
64569
64643
  async function removeChosenTitle(file) {
64570
- await rm3(file, { force: true });
64644
+ await rm4(file, { force: true });
64571
64645
  }
64572
64646
  function readChosenTitleSync(file) {
64573
64647
  try {
64574
- return readFileSync8(file, "utf8");
64648
+ return readFileSync6(file, "utf8");
64575
64649
  } catch {
64576
64650
  return;
64577
64651
  }
@@ -64632,7 +64706,7 @@ class UnparseableRoleRecordError extends Error {
64632
64706
  async function readPersistedRole(roleFile) {
64633
64707
  let bytes;
64634
64708
  try {
64635
- bytes = await readFile4(roleFile, "utf8");
64709
+ bytes = await readFile6(roleFile, "utf8");
64636
64710
  } catch (error) {
64637
64711
  if (hasErrnoCode(error, "ENOENT"))
64638
64712
  return;
@@ -64654,7 +64728,7 @@ async function writeSessionHandoff(file, sessionId) {
64654
64728
  }
64655
64729
  async function readSessionHandoff(file) {
64656
64730
  try {
64657
- const id = (await readFile4(file, "utf8")).trim();
64731
+ const id = (await readFile6(file, "utf8")).trim();
64658
64732
  return id.length === 0 ? undefined : id;
64659
64733
  } catch (error) {
64660
64734
  if (hasErrnoCode(error, "ENOENT"))
@@ -64754,7 +64828,7 @@ function channelConnectionName(name, bundlePath, packageName) {
64754
64828
  }
64755
64829
 
64756
64830
  // src/legion-claim.ts
64757
- import { readdir as readdir4, stat as stat4 } from "fs/promises";
64831
+ import { readdir as readdir4, stat as stat5 } from "fs/promises";
64758
64832
  import { join as join13 } from "path";
64759
64833
  import { setTimeout as delay2 } from "timers/promises";
64760
64834
 
@@ -66241,7 +66315,7 @@ function listenerAskedToClaimAgain(error) {
66241
66315
 
66242
66316
  // src/legion-phase-hook.ts
66243
66317
  import { randomUUID as randomUUID7 } from "crypto";
66244
- import { readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "fs";
66318
+ import { readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
66245
66319
  import { dirname as dirname6, join as join12 } from "path";
66246
66320
 
66247
66321
  // ../pi-shared/src/phase-reminder.ts
@@ -66432,11 +66506,16 @@ function createPhaseReminder(deps) {
66432
66506
  }
66433
66507
  return { reminds: true, record };
66434
66508
  };
66509
+ const architectDue = () => !reported && stall.count >= deps.limits.architectAfter;
66435
66510
  const tellArchitect = async (record) => {
66511
+ if (deps.claim() === undefined)
66512
+ return;
66513
+ const publish = await deps.publisher();
66514
+ if (!architectDue())
66515
+ return;
66436
66516
  const claim = deps.claim();
66437
66517
  if (claim === undefined)
66438
66518
  return;
66439
- const publish = deps.publisher();
66440
66519
  if (publish === undefined) {
66441
66520
  deps.log.debug("legion: Envoy is off for this session; the architect is not told", {
66442
66521
  issue: claim.issue,
@@ -66525,7 +66604,7 @@ function createPhaseReminder(deps) {
66525
66604
  armReminder(reminder, deps.limits.reminderMs);
66526
66605
  return;
66527
66606
  }
66528
- if (reported || stall.count < deps.limits.architectAfter)
66607
+ if (!architectDue())
66529
66608
  return;
66530
66609
  await tellArchitect(record);
66531
66610
  };
@@ -66717,7 +66796,7 @@ var NO_RECORD = { entry: undefined, recreatedNoticeSent: false };
66717
66796
  function readPhaseStallRecord(file, log) {
66718
66797
  let raw;
66719
66798
  try {
66720
- raw = readFileSync9(file, "utf8");
66799
+ raw = readFileSync7(file, "utf8");
66721
66800
  } catch (error) {
66722
66801
  const missing = typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
66723
66802
  if (!missing) {
@@ -66760,7 +66839,7 @@ function writePhaseStallRecord(file, entry, recreatedNoticeSent, log) {
66760
66839
  writeFileSync4(temporary, JSON.stringify({ ...entry, ...recreatedNoticeSent ? { recreatedNoticeSent } : {} }), { mode: 384 });
66761
66840
  renameSync3(temporary, file);
66762
66841
  } catch (error) {
66763
- rmSync5(temporary, { force: true });
66842
+ rmSync4(temporary, { force: true });
66764
66843
  log.warn("legion: the phase-stall state is not recorded for a relaunch", {
66765
66844
  file,
66766
66845
  error: messageFor(error)
@@ -66824,7 +66903,7 @@ function createPhaseHookEndpoint(deps) {
66824
66903
  saveEntry: saveRecord,
66825
66904
  claim: deps.claim,
66826
66905
  readRecord: deps.readRecord,
66827
- publisher: () => deps.publish,
66906
+ publisher: async () => deps.publish,
66828
66907
  project: configuredValue(deps.env["LEGION_PROJECT"]),
66829
66908
  limits,
66830
66909
  log: deps.log
@@ -66929,7 +67008,7 @@ function createPhaseHookEndpoint(deps) {
66929
67008
  }
66930
67009
 
66931
67010
  // src/legion-claim.ts
66932
- function legionPane(env) {
67011
+ async function legionPane(env) {
66933
67012
  const pointer = env["LEGION_BOOT_TOKEN_FILE"];
66934
67013
  if (pointer === undefined && configuredValue(env["LEGION_BOOT_TOKEN"]) === undefined) {
66935
67014
  return;
@@ -66944,7 +67023,7 @@ function legionPane(env) {
66944
67023
  return {
66945
67024
  daemonUrl: required("LEGION_DAEMON_URL"),
66946
67025
  configDir: required("CLAUDE_CONFIG_DIR"),
66947
- bootToken: pointer === undefined ? required("LEGION_BOOT_TOKEN") : readSecretFile("LEGION_BOOT_TOKEN_FILE", pointer),
67026
+ bootToken: pointer === undefined ? required("LEGION_BOOT_TOKEN") : await readSecretFile("LEGION_BOOT_TOKEN_FILE", pointer),
66948
67027
  launcherSaves: configuredValue(env["LEGION_CLAUDE_SESSION_ID"]) !== undefined
66949
67028
  };
66950
67029
  }
@@ -66986,7 +67065,7 @@ async function waitForSavedTranscript(transcript, signal, pollMs = 100) {
66986
67065
  }
66987
67066
  }
66988
67067
  function isFile(file) {
66989
- return stat4(file).then((info) => info.isFile(), () => false);
67068
+ return stat5(file).then((info) => info.isFile(), () => false);
66990
67069
  }
66991
67070
  var ROLE_CLAIM_RETRY_MS = 1e4;
66992
67071
  var ROLE_CLAIM_WAIT_MS = SESSION_LIVE_WINDOW_MS + ROLE_CLAIM_RETRY_MS;
@@ -67550,7 +67629,7 @@ async function executeLegionTool(runtime, input, signal) {
67550
67629
 
67551
67630
  // src/mod-link.ts
67552
67631
  import { randomUUID as randomUUID9 } from "crypto";
67553
- import { chmod, lstat as lstat4, mkdir as mkdir3, stat as stat5, unlink } from "fs/promises";
67632
+ import { chmod as chmod2, lstat as lstat5, mkdir as mkdir3, stat as stat6, unlink } from "fs/promises";
67554
67633
  import {
67555
67634
  createServer,
67556
67635
  request as httpRequest
@@ -67754,9 +67833,9 @@ function createEventStream(limit) {
67754
67833
  }
67755
67834
  };
67756
67835
  }
67757
- async function exists(path) {
67836
+ async function exists2(path) {
67758
67837
  try {
67759
- await stat5(path);
67838
+ await stat6(path);
67760
67839
  return true;
67761
67840
  } catch {
67762
67841
  return false;
@@ -67764,7 +67843,7 @@ async function exists(path) {
67764
67843
  }
67765
67844
  async function privateDirectory(path) {
67766
67845
  await mkdir3(path, { recursive: true, mode: 448 });
67767
- const directory = await lstat4(path);
67846
+ const directory = await lstat5(path);
67768
67847
  if (!directory.isDirectory()) {
67769
67848
  throw new Error(`${path} is not a directory of its own, so the socket has no private home`);
67770
67849
  }
@@ -67778,7 +67857,7 @@ async function privateDirectory(path) {
67778
67857
  }
67779
67858
  async function bind(server, socketPath) {
67780
67859
  await privateDirectory(dirname7(socketPath));
67781
- if (await exists(socketPath)) {
67860
+ if (await exists2(socketPath)) {
67782
67861
  if (await probeHealth(socketPath, MOD_PROBE_TIMEOUT_MS)) {
67783
67862
  throw new Error(`another claude-envoy server already serves this session at ${socketPath}`);
67784
67863
  }
@@ -67793,7 +67872,7 @@ async function bind(server, socketPath) {
67793
67872
  resolve();
67794
67873
  });
67795
67874
  await promise;
67796
- await chmod(socketPath, 384);
67875
+ await chmod2(socketPath, 384);
67797
67876
  }
67798
67877
  async function startModLink(options) {
67799
67878
  const resolved = resolveModSocketPath(options.sessionId, options.env);
@@ -68171,11 +68250,11 @@ function modSession(options) {
68171
68250
  import { join as join14 } from "path";
68172
68251
 
68173
68252
  // src/state-file.ts
68174
- import { readFile as readFile5 } from "fs/promises";
68253
+ import { readFile as readFile7 } from "fs/promises";
68175
68254
  async function readStateFile(file, schema, empty, refusal) {
68176
68255
  let text;
68177
68256
  try {
68178
- text = await readFile5(file, "utf8");
68257
+ text = await readFile7(file, "utf8");
68179
68258
  } catch (error) {
68180
68259
  if (hasErrnoCode(error, "ENOENT"))
68181
68260
  return empty;
@@ -68230,12 +68309,12 @@ import { basename as basename4 } from "path";
68230
68309
 
68231
68310
  // ../envoy-client/src/process-ancestry.ts
68232
68311
  import { execFileSync } from "child_process";
68233
- import { readFileSync as readFileSync10 } from "fs";
68312
+ import { readFileSync as readFileSync8 } from "fs";
68234
68313
  var MAX_ANCESTORS = 64;
68235
68314
  var PARENT_LOOKUP_MS = 1000;
68236
68315
  function procParentPid(pid) {
68237
68316
  try {
68238
- const stat = readFileSync10(`/proc/${pid}/stat`, "utf8");
68317
+ const stat = readFileSync8(`/proc/${pid}/stat`, "utf8");
68239
68318
  const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
68240
68319
  return Number.isInteger(parent) ? parent : undefined;
68241
68320
  } catch {
@@ -68277,7 +68356,7 @@ function isAncestor(candidate, pid = process.pid) {
68277
68356
  }
68278
68357
  function procCommand(pid) {
68279
68358
  try {
68280
- return readFileSync10(`/proc/${pid}/comm`, "utf8").trim();
68359
+ return readFileSync8(`/proc/${pid}/comm`, "utf8").trim();
68281
68360
  } catch {
68282
68361
  return;
68283
68362
  }
@@ -68442,7 +68521,7 @@ async function acceptUserTurn(options) {
68442
68521
  }
68443
68522
  await options.handle(key, delivery);
68444
68523
  try {
68445
- const dispatch = options.dispatch();
68524
+ const dispatch = await options.dispatch();
68446
68525
  if (dispatch === undefined)
68447
68526
  return;
68448
68527
  const accepted = await dispatch.acceptMessageDelivery(delivery.id, delivery.attempt, {
@@ -68467,7 +68546,7 @@ async function withDeliveredPictures(text, addresses, client, named, shown) {
68467
68546
  return textAlone;
68468
68547
  let dispatch;
68469
68548
  try {
68470
- dispatch = client();
68549
+ dispatch = await client();
68471
68550
  } catch {
68472
68551
  return textAlone;
68473
68552
  }
@@ -68860,10 +68939,10 @@ class UnsupportedEnvoyToolError extends Error {
68860
68939
  }
68861
68940
  }
68862
68941
  async function postDispatchReply(identity, configFile, delivery, result) {
68863
- const config = sessionDispatchSettings(configFile, process.env, {
68942
+ const config = (await sessionDispatchSettings(configFile, process.env, {
68864
68943
  cwd: identity.directory,
68865
68944
  session: () => identity.id
68866
- }).dispatch;
68945
+ })).dispatch;
68867
68946
  if (!config.enabled)
68868
68947
  throw new Error(config.error ?? config.notice);
68869
68948
  await postDeliveryReply(config, identity.id, delivery, result);
@@ -69445,13 +69524,13 @@ async function startChannelSession(options) {
69445
69524
  if (claim.holder === identity.id)
69446
69525
  return "pending";
69447
69526
  if (claim.holder !== persisted.session_id)
69448
- await rm4(previousFile, { force: true });
69527
+ await rm5(previousFile, { force: true });
69449
69528
  return "settled";
69450
69529
  }
69451
69530
  heldRole = persisted.role;
69452
69531
  const currentFile = roleStateFile(options.stateDirectory, identity.id);
69453
69532
  if (previousFile !== currentFile)
69454
- await rm4(previousFile, { force: true });
69533
+ await rm5(previousFile, { force: true });
69455
69534
  await writeRoleRecord(currentFile, persisted.role);
69456
69535
  return "settled";
69457
69536
  };
@@ -69499,7 +69578,7 @@ async function startChannelSession(options) {
69499
69578
  if (!result.claimed) {
69500
69579
  if (result.holder !== identity.id) {
69501
69580
  heldRole = undefined;
69502
- await rm4(roleStateFile(options.stateDirectory, identity.id), { force: true });
69581
+ await rm5(roleStateFile(options.stateDirectory, identity.id), { force: true });
69503
69582
  return;
69504
69583
  }
69505
69584
  await refreshRoleRecord();
@@ -70010,10 +70089,10 @@ function pluginStateDirectory() {
70010
70089
  }
70011
70090
  async function runEnvoyChannelServer() {
70012
70091
  const directory = projectDirectory();
70013
- const pane = legionPane(process.env);
70092
+ const pane = await legionPane(process.env);
70014
70093
  const configFile = sessionConfigFile("claude", process.env);
70015
70094
  const currentSessionId = () => identity.id;
70016
- const { dispatch, envoy, notice } = sessionSettings(configFile, process.env, {
70095
+ const { dispatch, envoy, notice } = await sessionSettings(configFile, process.env, {
70017
70096
  cwd: directory,
70018
70097
  session: currentSessionId
70019
70098
  });
@@ -70207,8 +70286,8 @@ async function runEnvoyChannelServer() {
70207
70286
  });
70208
70287
  const router = (state) => {
70209
70288
  const options = {
70210
- dispatch: (ms) => {
70211
- const active = activeDispatchSettings(sessionDispatchSettings(configFile, process.env, { cwd: directory }).dispatch);
70289
+ dispatch: async (ms) => {
70290
+ const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch);
70212
70291
  return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, {
70213
70292
  deadlineMs: ms
70214
70293
  });
@@ -70526,10 +70605,10 @@ function startCodexAgentStream(options) {
70526
70605
  // src/codex/codex-cli.ts
70527
70606
  import { spawn } from "child_process";
70528
70607
  import { randomBytes as randomBytes2 } from "crypto";
70529
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync11, writeFileSync as writeFileSync5 } from "fs";
70608
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
70530
70609
  import { join as join16 } from "path";
70531
70610
  var QUEUE_TIMEOUT_MS = 30000;
70532
- function codexProcessEnv(pid, fallback, read = (path) => readFileSync11(path, "utf8")) {
70611
+ function codexProcessEnv(pid, fallback, read = (path) => readFileSync9(path, "utf8")) {
70533
70612
  let raw;
70534
70613
  try {
70535
70614
  raw = read(`/proc/${pid}/environ`);
@@ -70721,7 +70800,7 @@ function askSideQuestion(command, threadId, question, timeoutMs = SIDE_QUESTION_
70721
70800
 
70722
70801
  // src/codex/codex-inbox.ts
70723
70802
  import { randomBytes as randomBytes3 } from "crypto";
70724
- import { mkdir as mkdir4, readdir as readdir5, readFile as readFile6, rename as rename4, rm as rm5, writeFile as writeFile2 } from "fs/promises";
70803
+ import { mkdir as mkdir4, readdir as readdir5, readFile as readFile8, rename as rename4, rm as rm6, writeFile as writeFile2 } from "fs/promises";
70725
70804
  import { join as join17 } from "path";
70726
70805
  var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
70727
70806
  function codexInboxDirectory(stateDirectory, sessionId) {
@@ -70744,7 +70823,7 @@ async function putInbox(directory, item, name = inboxItemName()) {
70744
70823
  async function takenBy(directory, name) {
70745
70824
  for (const taker of ["hook", "server"]) {
70746
70825
  try {
70747
- await readFile6(join17(directory, TAKEN_DIRECTORY[taker], name));
70826
+ await readFile8(join17(directory, TAKEN_DIRECTORY[taker], name));
70748
70827
  return taker;
70749
70828
  } catch {}
70750
70829
  }
@@ -70752,7 +70831,7 @@ async function takenBy(directory, name) {
70752
70831
  }
70753
70832
  async function withdrawWaiting(directory, name) {
70754
70833
  try {
70755
- await rm5(join17(directory, "waiting", name));
70834
+ await rm6(join17(directory, "waiting", name));
70756
70835
  return true;
70757
70836
  } catch {
70758
70837
  return false;
@@ -70771,7 +70850,7 @@ async function discardWaiting(directory, keep = () => false) {
70771
70850
  if (!name.endsWith(".json") || keep(name))
70772
70851
  continue;
70773
70852
  try {
70774
- await rm5(join17(waiting, name));
70853
+ await rm6(join17(waiting, name));
70775
70854
  removed++;
70776
70855
  } catch {}
70777
70856
  }
@@ -70795,7 +70874,7 @@ async function takeInbox(directory, taker, maxContextBytes) {
70795
70874
  if (maxContextBytes !== undefined) {
70796
70875
  let waitingItem;
70797
70876
  try {
70798
- waitingItem = JSON.parse(await readFile6(join17(waiting, name), "utf8"));
70877
+ waitingItem = JSON.parse(await readFile8(join17(waiting, name), "utf8"));
70799
70878
  } catch {
70800
70879
  continue;
70801
70880
  }
@@ -70811,7 +70890,7 @@ async function takeInbox(directory, taker, maxContextBytes) {
70811
70890
  continue;
70812
70891
  }
70813
70892
  try {
70814
- const parsed = JSON.parse(await readFile6(join17(destination, name), "utf8"));
70893
+ const parsed = JSON.parse(await readFile8(join17(destination, name), "utf8"));
70815
70894
  if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
70816
70895
  taken.push({ item: parsed, name });
70817
70896
  }
@@ -70968,13 +71047,13 @@ function createCodexDelivery(options) {
70968
71047
  }
70969
71048
 
70970
71049
  // src/codex/codex-owner.ts
70971
- import { link as link2, mkdir as mkdir6, readdir as readdir6, readFile as readFile8, rm as rm6, stat as stat6, writeFile as writeFile4 } from "fs/promises";
71050
+ 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";
70972
71051
  import { join as join19 } from "path";
70973
71052
 
70974
71053
  // src/codex/codex-session-record.ts
70975
71054
  import { spawnSync } from "child_process";
70976
- import { readFileSync as readFileSync12, readlinkSync as readlinkSync3, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
70977
- import { mkdir as mkdir5, readFile as readFile7, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
71055
+ import { readFileSync as readFileSync10, readlinkSync as readlinkSync2, unwatchFile as unwatchFile2, watchFile as watchFile2 } from "fs";
71056
+ import { mkdir as mkdir5, readFile as readFile9, rename as rename5, utimes as utimes3, writeFile as writeFile3 } from "fs/promises";
70978
71057
  import { homedir as homedir3 } from "os";
70979
71058
  import { basename as basename5, dirname as dirname8, join as join18 } from "path";
70980
71059
  var CodexSessionRecord = object({
@@ -71013,7 +71092,7 @@ function watchRecord(file, pid, ended, changed, intervalMs) {
71013
71092
  }
71014
71093
  async function sessionEnded(file) {
71015
71094
  try {
71016
- await readFile7(file);
71095
+ await readFile9(file);
71017
71096
  return true;
71018
71097
  } catch {
71019
71098
  return false;
@@ -71027,7 +71106,7 @@ async function writeCodexSessionRecord(file, value) {
71027
71106
  }
71028
71107
  async function readCodexSessionRecord(file) {
71029
71108
  try {
71030
- const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile7(file, "utf8")));
71109
+ const parsed = CodexSessionRecord.safeParse(JSON.parse(await readFile9(file, "utf8")));
71031
71110
  return parsed.success ? parsed.data : undefined;
71032
71111
  } catch {
71033
71112
  return;
@@ -71059,14 +71138,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
71059
71138
  }
71060
71139
  function procComm(pid) {
71061
71140
  try {
71062
- return readFileSync12(`/proc/${pid}/comm`, "utf8").trim();
71141
+ return readFileSync10(`/proc/${pid}/comm`, "utf8").trim();
71063
71142
  } catch {
71064
71143
  return;
71065
71144
  }
71066
71145
  }
71067
71146
  function procParent(pid) {
71068
71147
  try {
71069
- const stat = readFileSync12(`/proc/${pid}/stat`, "utf8");
71148
+ const stat = readFileSync10(`/proc/${pid}/stat`, "utf8");
71070
71149
  const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
71071
71150
  return Number.isInteger(parent) ? parent : undefined;
71072
71151
  } catch {
@@ -71080,7 +71159,7 @@ var PS_OPTIONS = {
71080
71159
  };
71081
71160
  function procStarted(pid) {
71082
71161
  try {
71083
- const stat = readFileSync12(`/proc/${pid}/stat`, "utf8");
71162
+ const stat = readFileSync10(`/proc/${pid}/stat`, "utf8");
71084
71163
  return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
71085
71164
  } catch {
71086
71165
  return;
@@ -71101,7 +71180,7 @@ function recordOfProcess(record, pid) {
71101
71180
  function sharedAppServer(pid) {
71102
71181
  let argv;
71103
71182
  try {
71104
- argv = readFileSync12(`/proc/${pid}/cmdline`, "utf8").split("\x00");
71183
+ argv = readFileSync10(`/proc/${pid}/cmdline`, "utf8").split("\x00");
71105
71184
  } catch {
71106
71185
  const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
71107
71186
  if (ps.status !== 0)
@@ -71158,7 +71237,7 @@ async function pruneCodexSessionRecords(stateDirectory) {
71158
71237
  }
71159
71238
  function codexExecutable(pid) {
71160
71239
  try {
71161
- return readlinkSync3(`/proc/${pid}/exe`);
71240
+ return readlinkSync2(`/proc/${pid}/exe`);
71162
71241
  } catch {
71163
71242
  return;
71164
71243
  }
@@ -71190,7 +71269,7 @@ async function registerServer(directory, pid, started, list = (path) => readdir6
71190
71269
  }
71191
71270
  }
71192
71271
  } finally {
71193
- await rm6(temporary, { force: true });
71272
+ await rm7(temporary, { force: true });
71194
71273
  }
71195
71274
  }
71196
71275
  var linkRefused = false;
@@ -71210,11 +71289,11 @@ async function place(temporary, target, pid, started) {
71210
71289
  }
71211
71290
  async function unregisterServer(directory, self2) {
71212
71291
  const file = join19(directory, entryName(self2));
71213
- const named = await readFile8(file, "utf8").then(serverOf, () => {
71292
+ const named = await readFile10(file, "utf8").then(serverOf, () => {
71214
71293
  return;
71215
71294
  });
71216
71295
  if (named?.pid === self2.pid && named.started === self2.started)
71217
- await rm6(file, { force: true });
71296
+ await rm7(file, { force: true });
71218
71297
  }
71219
71298
  var startedOf = new Map;
71220
71299
  var SYSTEM_PROBE = {
@@ -71273,7 +71352,7 @@ async function readEntries(directory, probe, now = Date.now) {
71273
71352
  for (const name of names.filter((each) => TEMPORARY_NAME.test(each))) {
71274
71353
  let text;
71275
71354
  try {
71276
- text = await readFile8(join19(directory, name), "utf8");
71355
+ text = await readFile10(join19(directory, name), "utf8");
71277
71356
  } catch {
71278
71357
  publishing = true;
71279
71358
  break;
@@ -71289,13 +71368,13 @@ async function readEntries(directory, probe, now = Date.now) {
71289
71368
  for (const { name, seq } of numbered(names)) {
71290
71369
  let text;
71291
71370
  try {
71292
- text = await readFile8(join19(directory, name), "utf8");
71371
+ text = await readFile10(join19(directory, name), "utf8");
71293
71372
  } catch {
71294
71373
  continue;
71295
71374
  }
71296
71375
  const server = serverOf(text);
71297
71376
  if (server === undefined) {
71298
- const written = await stat6(join19(directory, name)).then((info) => info.mtimeMs, () => {
71377
+ const written = await stat7(join19(directory, name)).then((info) => info.mtimeMs, () => {
71299
71378
  return;
71300
71379
  });
71301
71380
  if (written === undefined)
@@ -71323,7 +71402,7 @@ async function currentOwner(directory, probe = SYSTEM_PROBE) {
71323
71402
  const text = seen.held.get(seq);
71324
71403
  if (text === undefined)
71325
71404
  return;
71326
- const now = await readFile8(join19(directory, entryName({ seq })), "utf8").catch(() => {
71405
+ const now = await readFile10(join19(directory, entryName({ seq })), "utf8").catch(() => {
71327
71406
  return;
71328
71407
  });
71329
71408
  if (now !== text)
@@ -71383,7 +71462,7 @@ async function stillOwner(directory, self2, probe = SYSTEM_PROBE) {
71383
71462
 
71384
71463
  // src/codex/codex-transcript.ts
71385
71464
  import { watch } from "fs";
71386
- import { open as open3 } from "fs/promises";
71465
+ import { open as open4 } from "fs/promises";
71387
71466
  import { join as join20 } from "path";
71388
71467
  function record3(value) {
71389
71468
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
@@ -71521,7 +71600,7 @@ function followTranscript(path, onLine, options = {}) {
71521
71600
  again = false;
71522
71601
  let handle;
71523
71602
  try {
71524
- handle = await open3(path, "r");
71603
+ handle = await open4(path, "r");
71525
71604
  } catch {
71526
71605
  return;
71527
71606
  }
@@ -71588,7 +71667,7 @@ async function latestTurnCwd(transcriptPath) {
71588
71667
  return;
71589
71668
  let handle;
71590
71669
  try {
71591
- handle = await open3(transcriptPath, "r");
71670
+ handle = await open4(transcriptPath, "r");
71592
71671
  let end = (await handle.stat()).size;
71593
71672
  let carry = Buffer.alloc(0);
71594
71673
  let dropping = false;
@@ -71985,7 +72064,7 @@ async function runCodexEnvoyServer() {
71985
72064
  moveTo(next);
71986
72065
  }, RECORD_POLL_MS);
71987
72066
  const id = new SessionIdentity(bound.session_id, bound.cwd);
71988
- const { dispatch, envoy, notice } = sessionSettings(configFile, process.env, {
72067
+ const { dispatch, envoy, notice } = await sessionSettings(configFile, process.env, {
71989
72068
  cwd: bound.cwd,
71990
72069
  session: () => id.id
71991
72070
  });
@@ -72107,8 +72186,8 @@ async function runCodexEnvoyServer() {
72107
72186
  router: (state) => createCodexUserTurnRouter({
72108
72187
  ask: (question) => askSideQuestion(command(), id.id, question),
72109
72188
  deliver: (item) => codexDelivery.deliver(item),
72110
- dispatch: (ms) => {
72111
- const active = activeDispatchSettings(sessionDispatchSettings(configFile, process.env, { cwd: bound.cwd }).dispatch);
72189
+ dispatch: async (ms) => {
72190
+ const active = activeDispatchSettings((await sessionDispatchSettings(configFile, process.env, { cwd: bound.cwd })).dispatch);
72112
72191
  return active === null ? undefined : new DispatchClient(active.url, active.credential, fetch, {
72113
72192
  signal: AbortSignal.timeout(ms)
72114
72193
  });