@sjawhar/claude-envoy 5.24.0 → 5.25.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.
@@ -20161,6 +20161,10 @@ var FORM_SESSION = "session";
20161
20161
  var FORM_LAUNCHER_CREDENTIAL = "launcher_credential";
20162
20162
  var FORM_LAUNCHER_CREDENTIAL_DECLINED = "false";
20163
20163
  var FORM_PROJECTS = "projects";
20164
+ var FORM_SCOPE = "scope";
20165
+ var SCOPE_READ = "read";
20166
+ var FORM_AS_OF = "as_of";
20167
+ var HEADER_DPOP_HOLDER = "DPoP-Holder";
20164
20168
  var SUBJECT_TOKEN_TYPE_KUBERNETES = "urn:envoy:params:oauth:token-type:kubernetes-service-account";
20165
20169
  var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identity";
20166
20170
  var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
@@ -20273,6 +20277,7 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
20273
20277
  "The machine login the subject token belongs to has ended\\.",
20274
20278
  "The machine login has ended\\.",
20275
20279
  "Another live machine login holds the key this proof was signed with\\. A (?:machine makes a key of its own|sign-in makes a box key of its own)\\.",
20280
+ "A live read token is bound to the key this proof was signed with\\. Make a new key\\.",
20276
20281
  `${PERSON_SLOT} is a restricted member, whose token names its projects: set AGENT_SECRETS_PROJECTS to the projects this session works on\\.`,
20277
20282
  `The token names a project its person cannot see: ${PROJECT_SLOT}\\.`,
20278
20283
  `The subject token was refused: its entry names the project ${PROJECT_SLOT}, which its person ${PERSON_SLOT} cannot see\\.`,
@@ -20285,6 +20290,19 @@ var KNOWN_BROKER_REFUSAL_PATTERNS = [
20285
20290
  `The session name '${SESSION_SLOT}' belongs to another daemon: a pod trades only under a session name the daemon that registered it holds\\.`,
20286
20291
  `The session name '${SESSION_SLOT}' is bound to no daemon: a pod trades only under a session name the daemon that registered it holds\\.`,
20287
20292
  `${PERSON_SLOT}'s credentials are held by Dispatch; they work again when \\k<person> signs in to Dispatch, or when Dispatch can confirm \\k<person> with Google again`,
20293
+ "The 'as_of' parameter names a cut, and only a trade that asks for the scope read may name one\\.",
20294
+ "The 'as_of' parameter is not an RFC 3339 time with at most six fractional digits\\.",
20295
+ "The 'as_of' parameter names the zero time, which is no cut: a trade that reads the present names no cut\\.",
20296
+ "The 'as_of' parameter names a time later than this trade, and a cut is a time that has passed\\.",
20297
+ "A read trade makes or moves no launcher credential, so it cannot send launcher_credential=true\\. Trade for read without the parameter\\.",
20298
+ `${PERSON_SLOT}'s sign-in on this machine holds no launcher credential yet, and a read trade makes none\\. Sign in with \`agent-secrets login\` first\\.`,
20299
+ `${PERSON_SLOT}'s sign-in on this machine holds a launcher credential that has lapsed, and a read trade renews none\\. One ordinary trade of the sign-in renews it, as \`agent-secrets\` makes; then trade for read again\\.`,
20300
+ "A person's read trade sends a DPoP-Holder proof: the box key proves the sign-in and is bound to no read token, so the token is bound to a key made for its holder\\.",
20301
+ "The DPoP-Holder header binds a read token to its holder's key, and this trade does not ask for the scope read\\. Ask for it, or send no DPoP-Holder header\\.",
20302
+ "The DPoP-Holder proof was refused: a trade sends one, a DPoP proof of this request signed with the key it embeds, spent nowhere before\\.",
20303
+ "The DPoP-Holder proof is signed with the key the DPoP proof is signed with, and the holder's key is a key of its own\\.",
20304
+ "The key this read token would be bound to signs launcher proofs: a live launcher credential is bound to it, and no read token is bound to such a key\\. Send a DPoP-Holder proof by a key made for the token's holder, and the token is bound to that key\\.",
20305
+ "The key this proof was signed with signs launcher proofs: a live launcher credential is bound to it, and no read token is bound to such a key\\. Ask for the scope read with a DPoP-Holder proof by a key made for the token's holder, or trade with a key that holds no launcher credential\\.",
20288
20306
  ...POLICY_REFUSAL_PATTERNS
20289
20307
  ].map((source) => new RegExp(`^${source}$`));
20290
20308
  var LIBRARY_DESCRIPTIONS = [
@@ -29222,13 +29240,29 @@ async function whoamiCommand(context) {
29222
29240
  const service = identity.kind === "agent" ? identity.service ?? null : null;
29223
29241
  const proved = identity.kind === "agent" ? identity.session ?? null : null;
29224
29242
  const project = identity.kind === "agent" ? identity.project ?? null : null;
29243
+ const readOnly = identity.scopes?.includes("read") === true;
29244
+ const cut = identity.kind === "agent" ? identity.cut ?? null : null;
29225
29245
  const session = proved ?? sessionId;
29226
29246
  const unowned = "no owner, so an issue you create without an assignee takes its parent's assignee when the parent is in the same project, else the project's default assignee, which every project names, so the issue always has one.";
29227
29247
  const answered = identity.kind === "agent" ? identity.sign_in_required : undefined;
29228
29248
  const signInNeeded = answered ?? (owner === null && service !== null && proved !== null);
29229
- const acting = owner !== null ? `Session ${session} acts for ${owner}: issues you create without an assignee are assigned to ${owner}.` : service !== null ? signInNeeded ? `Session ${session} runs as service ${serviceSubjectLabel(service)} and no person, so it may read but Dispatch refuses every write it makes: run \`agent-secrets login\` on this machine to write as yourself.` : `Session ${session} runs as service ${serviceSubjectLabel(service)}: ${unowned}` : `Session ${session} runs under the shared token: ${unowned}`;
29230
- const elsewhere = proved !== null && proved !== sessionId ? ` Your credential names session ${proved}, which is not this host session (${sessionId}): Dispatch records every write you make as ${proved}.` : "";
29231
- const writable = project !== null ? ` It may write project ${project} and no other.` : "";
29249
+ const who = owner !== null ? `acts for ${owner}` : service !== null ? `runs as service ${serviceSubjectLabel(service)}` : "runs";
29250
+ const named = proved !== null && proved !== sessionId ? ` Your credential names session ${proved}, which is not this host session (${sessionId})` : "";
29251
+ let acting;
29252
+ let elsewhere = named === "" ? "" : `${named}: Dispatch records every write you make as ${proved}.`;
29253
+ if (readOnly) {
29254
+ acting = `Session ${session} ${who} with a read-only credential: it may read, and Dispatch refuses every write it makes.${cut === null ? "" : ` Its cut is ${cut}, the past time it reads Dispatch at.`}`;
29255
+ elsewhere = named === "" ? "" : `${named}.`;
29256
+ } else if (owner !== null) {
29257
+ acting = `Session ${session} ${who}: issues you create without an assignee are assigned to ${owner}.`;
29258
+ } else if (signInNeeded) {
29259
+ acting = `Session ${session} ${who} and no person, so it may read but Dispatch refuses every write it makes: run \`agent-secrets login\` on this machine to write as yourself.`;
29260
+ } else if (service !== null) {
29261
+ acting = `Session ${session} ${who}: ${unowned}`;
29262
+ } else {
29263
+ acting = `Session ${session} runs under the shared token: ${unowned}`;
29264
+ }
29265
+ const writable = project !== null && !readOnly ? ` It may write project ${project} and no other.` : "";
29232
29266
  return {
29233
29267
  text: acting + elsewhere + writable,
29234
29268
  details: { session, owner, service, project }
@@ -31481,6 +31515,64 @@ async function genericGrantRequest(config, grantType, parameters, options) {
31481
31515
  return result;
31482
31516
  }
31483
31517
 
31518
+ // ../cipher-client/src/broker-request.ts
31519
+ var BROKER_URL_SETTING = "the broker URL";
31520
+ function statusOf(error) {
31521
+ let cause = error;
31522
+ for (let depth = 0;depth < 4; depth += 1) {
31523
+ if (cause instanceof Response)
31524
+ return cause.status;
31525
+ if (cause instanceof ResponseBodyError || cause instanceof WWWAuthenticateChallengeError) {
31526
+ return cause.status;
31527
+ }
31528
+ if (typeof cause !== "object" || cause === null || !("cause" in cause))
31529
+ return 0;
31530
+ cause = cause.cause;
31531
+ }
31532
+ return 0;
31533
+ }
31534
+ function brokerRefusal(doing, refused, endpoint, error, context = {}) {
31535
+ if (error instanceof ResponseBodyError && error.status >= 400 && error.status < 500) {
31536
+ const description = error.error_description;
31537
+ return new BrokerRefusedError(error.status, error.error, typeof description === "string" ? description : "", refused, context);
31538
+ }
31539
+ const status = statusOf(error);
31540
+ const said = status === 0 ? errorClass(error) : `HTTP ${status}: ${errorClass(error)}`;
31541
+ return new BrokerTradeFailedError(`${doing} ${refused} at ${urlForText(endpoint, BROKER_URL_SETTING)}: ${said}`);
31542
+ }
31543
+ function requestInit(options, signal, headers) {
31544
+ const signals = [options.signal, signal].filter((one) => one !== undefined);
31545
+ return {
31546
+ method: options.method,
31547
+ headers,
31548
+ body: options.body,
31549
+ redirect: options.redirect,
31550
+ ...signals.length === 0 ? {} : { signal: AbortSignal.any(signals) }
31551
+ };
31552
+ }
31553
+ async function sendWithProof(proved, url, options, signal) {
31554
+ const send = async () => {
31555
+ const headers = new Headers(options.headers);
31556
+ const request = { method: options.method, url, nonce: proved.nonce.value };
31557
+ headers.set("DPoP", await proved.key.proof(request));
31558
+ if (proved.holderKey !== undefined) {
31559
+ headers.set(HEADER_DPOP_HOLDER, await proved.holderKey.proof(request));
31560
+ }
31561
+ return await proved.fetch(url, requestInit(options, signal, headers));
31562
+ };
31563
+ let answer = await send();
31564
+ const given = answer.headers.get("DPoP-Nonce") ?? "";
31565
+ if (given !== "")
31566
+ proved.nonce.value = given;
31567
+ if (answer.status === 400 && given !== "") {
31568
+ const body = await answer.clone().json().catch(() => null);
31569
+ const asked = typeof body === "object" && body !== null && "error" in body && body.error === "use_dpop_nonce";
31570
+ if (asked)
31571
+ answer = await send();
31572
+ }
31573
+ return answer;
31574
+ }
31575
+
31484
31576
  // ../cipher-client/src/device-login-file.ts
31485
31577
  import { createPrivateKey, randomUUID as randomUUID3 } from "crypto";
31486
31578
  import { constants as constants2 } from "fs";
@@ -31515,7 +31607,13 @@ import { basename as basename2, dirname as dirname2, join as join5 } from "path"
31515
31607
 
31516
31608
  // ../cipher-client/src/token-client.ts
31517
31609
  var DEFAULT_RENEW_BEFORE_MS = 5 * 60000;
31518
- var BROKER_URL_SETTING = "the broker URL";
31610
+ function renewalAt(expiresAt, now, renewBeforeMs) {
31611
+ const left = expiresAt - now;
31612
+ if (left <= 0)
31613
+ return now;
31614
+ return Math.max(expiresAt - renewBeforeMs, now + left / 2);
31615
+ }
31616
+ var EXPIRES_IN_STEP_MS = 1000;
31519
31617
  var RETRY_FIRST_WAIT_MS = 15000;
31520
31618
  var RETRY_MAX_WAIT_MS = 5 * 60000;
31521
31619
  var PENDING_FIRST_WAIT_MS = 2000;
@@ -31539,66 +31637,18 @@ function sleep2(ms, signal, holdsProcess = false) {
31539
31637
  signal?.addEventListener("abort", done, { once: true });
31540
31638
  return promise;
31541
31639
  }
31542
- function statusOf(error) {
31543
- let cause = error;
31544
- for (let depth = 0;depth < 4; depth += 1) {
31545
- if (cause instanceof Response)
31546
- return cause.status;
31547
- if (cause instanceof ResponseBodyError || cause instanceof WWWAuthenticateChallengeError) {
31548
- return cause.status;
31549
- }
31550
- if (typeof cause !== "object" || cause === null || !("cause" in cause))
31551
- return 0;
31552
- cause = cause.cause;
31553
- }
31554
- return 0;
31555
- }
31556
- function brokerRefusal(doing, refused, endpoint, error, context = {}) {
31557
- if (error instanceof ResponseBodyError && error.status >= 400 && error.status < 500) {
31558
- const description = error.error_description;
31559
- return new BrokerRefusedError(error.status, error.error, typeof description === "string" ? description : "", refused, context);
31560
- }
31561
- const status = statusOf(error);
31562
- const said = status === 0 ? errorClass(error) : `HTTP ${status}: ${errorClass(error)}`;
31563
- return new BrokerTradeFailedError(`${doing} ${refused} at ${urlForText(endpoint, BROKER_URL_SETTING)}: ${said}`);
31564
- }
31565
- function requestInit(options, signal, headers) {
31566
- const signals = [options.signal, signal].filter((one) => one !== undefined);
31567
- return {
31568
- method: options.method,
31569
- headers,
31570
- body: options.body,
31571
- redirect: options.redirect,
31572
- ...signals.length === 0 ? {} : { signal: AbortSignal.any(signals) }
31573
- };
31574
- }
31575
- async function sendWithProof(proved, url, options, signal) {
31576
- const send = async () => {
31577
- const headers = new Headers(options.headers);
31578
- headers.set("DPoP", await proved.key.proof({ method: options.method, url, nonce: proved.nonce.value }));
31579
- return await proved.fetch(url, requestInit(options, signal, headers));
31580
- };
31581
- let answer = await send();
31582
- const given = answer.headers.get("DPoP-Nonce") ?? "";
31583
- if (given !== "")
31584
- proved.nonce.value = given;
31585
- if (answer.status === 400 && given !== "") {
31586
- const body = await answer.clone().json().catch(() => null);
31587
- const asked = typeof body === "object" && body !== null && "error" in body && body.error === "use_dpop_nonce";
31588
- if (asked)
31589
- answer = await send();
31590
- }
31591
- return answer;
31592
- }
31593
31640
 
31594
31641
  class BrokerTokenClient {
31595
31642
  #brokerUrl;
31596
31643
  #key;
31644
+ #holderKey;
31597
31645
  #subject;
31598
31646
  #actor;
31599
31647
  #session;
31600
31648
  #projects;
31601
31649
  #launcherCredential;
31650
+ #scope;
31651
+ #asOf;
31602
31652
  #renewBeforeMs;
31603
31653
  #now;
31604
31654
  #attemptMs;
@@ -31627,11 +31677,14 @@ class BrokerTokenClient {
31627
31677
  throw new Error("broker client: the broker URL is not an http or https URL");
31628
31678
  this.#brokerUrl = holdUrlUserinfo(brokerUrl);
31629
31679
  this.#key = options.key;
31680
+ this.#holderKey = options.holderKey;
31630
31681
  this.#subject = options.subject;
31631
31682
  this.#actor = options.actor;
31632
31683
  this.#session = options.session ?? "";
31633
31684
  this.#projects = [...options.projects ?? []];
31634
31685
  this.#launcherCredential = options.launcherCredential ?? true;
31686
+ this.#scope = options.scope ?? "";
31687
+ this.#asOf = options.asOf ?? "";
31635
31688
  this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
31636
31689
  this.#now = options.now ?? Date.now;
31637
31690
  this.#attemptMs = options.attemptMs ?? TRADE_ATTEMPT_MS;
@@ -31641,7 +31694,7 @@ class BrokerTokenClient {
31641
31694
  this.#random = options.random ?? Math.random;
31642
31695
  }
31643
31696
  get key() {
31644
- return this.#key;
31697
+ return this.#holderKey ?? this.#key;
31645
31698
  }
31646
31699
  describe() {
31647
31700
  return this.#subject.describe();
@@ -31650,10 +31703,11 @@ class BrokerTokenClient {
31650
31703
  const waitForReady = options.waitForReady === true;
31651
31704
  const now = this.#now();
31652
31705
  const held = this.#held;
31653
- if (held !== null && now < held.expiresAt.getTime() - this.#renewBeforeMs)
31654
- return held;
31655
- if (held !== null && now < held.expiresAt.getTime() && this.#last !== null)
31656
- return held;
31706
+ if (held !== null && now < held.renewsAt)
31707
+ return held.token;
31708
+ if (held !== null && now < held.token.expiresAt.getTime() && this.#last !== null) {
31709
+ return held.token;
31710
+ }
31657
31711
  const closed = this.#closed.signal;
31658
31712
  if (closed.aborted)
31659
31713
  throw closed.reason;
@@ -31687,8 +31741,8 @@ class BrokerTokenClient {
31687
31741
  const stop = () => {
31688
31742
  this.#waiters.delete(waiter);
31689
31743
  const held = this.#held;
31690
- if (held !== null && this.#now() < held.expiresAt.getTime())
31691
- resolve(held);
31744
+ if (held !== null && this.#now() < held.token.expiresAt.getTime())
31745
+ resolve(held.token);
31692
31746
  else
31693
31747
  reject(this.#stopped(signal?.reason));
31694
31748
  };
@@ -31728,7 +31782,7 @@ class BrokerTokenClient {
31728
31782
  });
31729
31783
  }
31730
31784
  drop(accessToken) {
31731
- if (accessToken !== undefined && this.#held?.accessToken !== accessToken)
31785
+ if (accessToken !== undefined && this.#held?.token.accessToken !== accessToken)
31732
31786
  return;
31733
31787
  this.#held = null;
31734
31788
  }
@@ -31759,7 +31813,10 @@ class BrokerTokenClient {
31759
31813
  if (this.#pendingSaid !== null && this.#since !== null) {
31760
31814
  this.#log(`the secrets broker answered this pod's session ${this.#session} once it was registered, ${Math.round((this.#now() - this.#since) / 1000)} s and ${this.#failed} failed trades after the first`);
31761
31815
  }
31762
- this.#held = token;
31816
+ this.#held = {
31817
+ token,
31818
+ renewsAt: renewalAt(token.expiresAt.getTime(), this.#now(), this.#renewBeforeMs)
31819
+ };
31763
31820
  this.#last = null;
31764
31821
  this.#since = null;
31765
31822
  this.#failed = 0;
@@ -31799,8 +31856,8 @@ class BrokerTokenClient {
31799
31856
  this.#since ??= now;
31800
31857
  this.#failed += 1;
31801
31858
  const held = this.#held;
31802
- if (held !== null && now < held.expiresAt.getTime()) {
31803
- this.#tell((waiter) => waiter.resolve(held));
31859
+ if (held !== null && now < held.token.expiresAt.getTime()) {
31860
+ this.#tell((waiter) => waiter.resolve(held.token));
31804
31861
  } else {
31805
31862
  this.#held = null;
31806
31863
  if (failure.kind !== "pending") {
@@ -31852,7 +31909,8 @@ class BrokerTokenClient {
31852
31909
  async#trade(signal) {
31853
31910
  const source = this.#subject;
31854
31911
  if (source.spend !== undefined) {
31855
- return await source.spend((subject) => this.#exchange(subject, signal), signal);
31912
+ const leastLifeMs = this.#scope === SCOPE_READ ? this.#renewBeforeMs + EXPIRES_IN_STEP_MS : undefined;
31913
+ return await source.spend((subject) => this.#exchange(subject, signal), signal, leastLifeMs);
31856
31914
  }
31857
31915
  return await this.#exchange(await source.read(signal), signal);
31858
31916
  }
@@ -31866,6 +31924,10 @@ class BrokerTokenClient {
31866
31924
  form[FORM_SESSION] = this.#session;
31867
31925
  if (this.#projects.length > 0)
31868
31926
  form[FORM_PROJECTS] = this.#projects.join(" ");
31927
+ if (this.#scope !== "")
31928
+ form[FORM_SCOPE] = this.#scope;
31929
+ if (this.#asOf !== "")
31930
+ form[FORM_AS_OF] = this.#asOf;
31869
31931
  if (!this.#launcherCredential) {
31870
31932
  form[FORM_LAUNCHER_CREDENTIAL] = FORM_LAUNCHER_CREDENTIAL_DECLINED;
31871
31933
  }
@@ -31898,7 +31960,7 @@ class BrokerTokenClient {
31898
31960
  return this.#read(urlForText(endpoint, BROKER_URL_SETTING), answered, raw.body);
31899
31961
  }
31900
31962
  async#send(url, options, signal, raw) {
31901
- const answer = await sendWithProof({ key: this.#key, fetch: this.#fetch, nonce: this.#nonce }, url, options, signal);
31963
+ const answer = await sendWithProof({ key: this.#key, holderKey: this.#holderKey, fetch: this.#fetch, nonce: this.#nonce }, url, options, signal);
31902
31964
  raw.body = await answer.clone().json().catch(() => {
31903
31965
  return;
31904
31966
  });
@@ -32161,6 +32223,10 @@ function member(json, name) {
32161
32223
  const value = json[name];
32162
32224
  return typeof value === "string" ? value : "";
32163
32225
  }
32226
+ function wholeMember(json, name) {
32227
+ const value = json[name];
32228
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : null;
32229
+ }
32164
32230
  function checkPrivate(info, what, forbidden, opens, notOwned) {
32165
32231
  const mode = info.mode & 511;
32166
32232
  if ((mode & forbidden) !== 0) {
@@ -32518,7 +32584,8 @@ async function readDeviceLogin(path) {
32518
32584
  expiresAt,
32519
32585
  broker,
32520
32586
  accessToken: accessUsable ? holdSecret(accessToken, accessExpiresAt) : "",
32521
- accessExpiresAt: accessUsable ? accessExpiresAt : null
32587
+ accessExpiresAt: accessUsable ? accessExpiresAt : null,
32588
+ accessLifeSeconds: accessUsable ? wholeMember(json, "access_life_seconds") : null
32522
32589
  };
32523
32590
  }
32524
32591
  function lockLost(then = "this trade refreshes and keeps nothing, and the next one reads the login again") {
@@ -32551,7 +32618,8 @@ async function saveDeviceLogin(path, login, held, keep = false) {
32551
32618
  broker: login.broker,
32552
32619
  ...login.accessToken === "" || login.accessExpiresAt === null ? {} : {
32553
32620
  access_token: login.accessToken,
32554
- access_expires_at: login.accessExpiresAt.toISOString()
32621
+ access_expires_at: login.accessExpiresAt.toISOString(),
32622
+ ...login.accessLifeSeconds === null ? {} : { access_life_seconds: login.accessLifeSeconds }
32555
32623
  }
32556
32624
  });
32557
32625
  await deviceLoginPlace(path);
@@ -32673,6 +32741,11 @@ async function importDpopKey(pkcs8Pem, name) {
32673
32741
  // ../cipher-client/src/device-login.ts
32674
32742
  var BROKER_SETTING = "AGENT_SECRETS_URL";
32675
32743
  var ACCESS_MARGIN_MS = 2 * TRADE_ATTEMPT_MS;
32744
+ function leastAccessLifeMs(leastLifeMs, lifeSeconds) {
32745
+ if (leastLifeMs === undefined || lifeSeconds === null)
32746
+ return ACCESS_MARGIN_MS;
32747
+ return Math.max(ACCESS_MARGIN_MS, Math.min(leastLifeMs, lifeSeconds * 1000 / 2));
32748
+ }
32676
32749
  var BROKER_REQUEST_MS = TRADE_ATTEMPT_MS / 2;
32677
32750
  var DEFAULT_POLL_SECONDS = 5;
32678
32751
  var LEAST_POLL_SECONDS = 1;
@@ -32748,7 +32821,8 @@ function loginOf(key, broker, answered, now) {
32748
32821
  expiresAt,
32749
32822
  broker,
32750
32823
  accessToken: holdSecret(answered.access_token, accessExpiresAt),
32751
- accessExpiresAt
32824
+ accessExpiresAt,
32825
+ accessLifeSeconds: seconds
32752
32826
  };
32753
32827
  }
32754
32828
  async function startDeviceLogin(options) {
@@ -32880,7 +32954,7 @@ class DeviceLoginIdentity {
32880
32954
  }
32881
32955
  return this.#key;
32882
32956
  }
32883
- async spend(trade, signal) {
32957
+ async spend(trade, signal, leastLifeMs) {
32884
32958
  const { thumbprint } = await this.#loaded();
32885
32959
  return await withDeviceLoginLock(this.#path, async (held) => {
32886
32960
  let login = await readDeviceLogin(this.#path);
@@ -32892,7 +32966,8 @@ class DeviceLoginIdentity {
32892
32966
  }
32893
32967
  const refresh = () => refreshDeviceLogin(this.#path, login, { describe: this.describe(), held });
32894
32968
  const expires = login.accessExpiresAt?.getTime() ?? 0;
32895
- let refreshed = login.accessToken === "" || expires - Date.now() < ACCESS_MARGIN_MS;
32969
+ const least = leastAccessLifeMs(leastLifeMs, login.accessLifeSeconds);
32970
+ let refreshed = login.accessToken === "" || expires - Date.now() < least;
32896
32971
  if (refreshed)
32897
32972
  login = await refresh();
32898
32973
  while (true) {
@@ -33340,13 +33415,15 @@ function tradeProjects(env) {
33340
33415
  }
33341
33416
  return sorted;
33342
33417
  }
33343
- async function brokerTokenClient(env, own = "") {
33418
+ async function brokerTokenClient(env, own = "", read) {
33344
33419
  const brokerUrl = value(env, BROKER_URL_VAR);
33345
33420
  const machine = machineIdentity(env);
33346
33421
  if (brokerUrl === "" || machine === undefined)
33347
33422
  return;
33348
33423
  if (!isHttpUrl(brokerUrl))
33349
33424
  throw new Error(`${BROKER_URL_VAR} is not an http or https URL`);
33425
+ const narrowed = read === undefined ? {} : { scope: SCOPE_READ, asOf: read.asOf };
33426
+ const heldApart = async () => read === undefined ? {} : { ...narrowed, holderKey: await newDpopKey() };
33350
33427
  if (machine instanceof DeviceLoginIdentity) {
33351
33428
  if (personTradeOff(env)) {
33352
33429
  throw new Error(`${PERSON_TRADE_VAR}=off turns off every trade made as a person, and ${IDENTITY_VAR}=${IDENTITY_DEVICE_LOGIN} trades this machine's device login as the person who approved it; unset one of them`);
@@ -33356,7 +33433,8 @@ async function brokerTokenClient(env, own = "") {
33356
33433
  key: await machine.key(),
33357
33434
  subject: machine,
33358
33435
  session: tradeSession(env, own) || deviceLoginSessionName(await machine.thumbprint()),
33359
- projects: tradeProjects(env)
33436
+ projects: tradeProjects(env),
33437
+ ...await heldApart()
33360
33438
  });
33361
33439
  return { client, signIn: undefined };
33362
33440
  }
@@ -33367,7 +33445,8 @@ async function brokerTokenClient(env, own = "") {
33367
33445
  key: await newDpopKey(),
33368
33446
  subject: machine,
33369
33447
  session: tradeSession(env, own),
33370
- launcherCredential: false
33448
+ launcherCredential: false,
33449
+ ...narrowed
33371
33450
  });
33372
33451
  return { client, signIn: undefined };
33373
33452
  }
@@ -33381,7 +33460,8 @@ async function brokerTokenClient(env, own = "") {
33381
33460
  subject: personIdentity(record, flow),
33382
33461
  actor: machine,
33383
33462
  session: own.trim() || signInSessionName(record),
33384
- projects: tradeProjects(env)
33463
+ projects: tradeProjects(env),
33464
+ ...await heldApart()
33385
33465
  });
33386
33466
  return { client, signIn: { person: record.person, thumbprint: record.thumbprint } };
33387
33467
  }
@@ -33414,11 +33494,11 @@ function forgetBrokerSession(session) {
33414
33494
  function signInName(record) {
33415
33495
  return `${record.person}\x00${record.thumbprint}`;
33416
33496
  }
33417
- function keyOf(env, own) {
33418
- return {
33419
- session: own.trim(),
33420
- variables: JSON.stringify(BROKER_VARIABLES.map((name) => env[name]))
33421
- };
33497
+ function keyOf(env, own, read) {
33498
+ const values = BROKER_VARIABLES.map((name) => env[name]);
33499
+ if (read !== undefined)
33500
+ values.push({ read: true, asOf: read.asOf ?? "" });
33501
+ return { session: own.trim(), variables: JSON.stringify(values) };
33422
33502
  }
33423
33503
  function entryFor(key) {
33424
33504
  let sessions = CLIENTS.get(key.session);
@@ -33433,13 +33513,13 @@ function entryFor(key) {
33433
33513
  }
33434
33514
  return entry;
33435
33515
  }
33436
- async function make(env, own) {
33437
- const made = await brokerTokenClient(env, own);
33516
+ async function make(env, own, read) {
33517
+ const made = await brokerTokenClient(env, own, read);
33438
33518
  const signIn = made?.signIn;
33439
33519
  return { client: made?.client, signIn: signIn === undefined ? "" : signInName(signIn) };
33440
33520
  }
33441
- async function clientFor(env, own) {
33442
- const key = keyOf(env, own);
33521
+ async function clientFor(env, own, read) {
33522
+ const key = keyOf(env, own, read);
33443
33523
  const entry = entryFor(key);
33444
33524
  if (entry.refused.size > 0) {
33445
33525
  const record = await chooseSignIn(env);
@@ -33454,7 +33534,7 @@ async function clientFor(env, own) {
33454
33534
  }
33455
33535
  let making = entry.making;
33456
33536
  if (making === undefined) {
33457
- const started = make(env, key.session);
33537
+ const started = make(env, key.session, read);
33458
33538
  making = started;
33459
33539
  entry.making = started;
33460
33540
  started.then((made) => {
@@ -33484,13 +33564,13 @@ function untilAborted(promise, signal) {
33484
33564
  });
33485
33565
  });
33486
33566
  }
33487
- async function tradedToken(env, own, signal, waitForReady = false) {
33488
- const { entry, made } = await untilAborted(clientFor(env, own), signal);
33567
+ async function tradedToken(env, own, { signal, waitForReady = false, read }) {
33568
+ const { entry, made } = await untilAborted(clientFor(env, own, read), signal);
33489
33569
  const { client } = made;
33490
33570
  if (client === undefined) {
33491
33571
  throw new LoggableError("AGENT_SECRETS_URL and AGENT_SECRETS_MACHINE_IDENTITY no longer name a broker and an identity to trade");
33492
33572
  }
33493
- const { session, variables } = keyOf(env, own);
33573
+ const { session, variables } = keyOf(env, own, read);
33494
33574
  try {
33495
33575
  return {
33496
33576
  token: await client.token(signal, { waitForReady }),
@@ -33505,7 +33585,7 @@ async function tradedToken(env, own, signal, waitForReady = false) {
33505
33585
  }
33506
33586
  }
33507
33587
  function brokerTokenFor(env, session) {
33508
- return (signal, waitForReady) => tradedToken(env, sessionName(session), signal, waitForReady);
33588
+ return (signal, waitForReady) => tradedToken(env, sessionName(session), { signal, waitForReady });
33509
33589
  }
33510
33590
  function dropHeld(key, token) {
33511
33591
  CLIENTS.get(key.session)?.get(key.variables)?.made?.client?.drop(token);
@@ -33513,14 +33593,14 @@ function dropHeld(key, token) {
33513
33593
  function dropTradedToken(env, traded) {
33514
33594
  dropHeld(keyOf(env, traded.session), traded.token.accessToken);
33515
33595
  }
33516
- function brokerCredential(env, session) {
33596
+ function brokerCredential(env, session, read) {
33517
33597
  let presented = "";
33518
33598
  const presentedAs = new WeakMap;
33519
33599
  const own = (acting) => (acting ?? "").trim() || sessionName(session);
33520
33600
  return {
33521
33601
  scheme: "DPoP",
33522
33602
  async headers(method, url, acting, signal) {
33523
- const traded = await tradedToken(env, own(acting), signal);
33603
+ const traded = await tradedToken(env, own(acting), { signal, read });
33524
33604
  const { token, key, identity } = traded;
33525
33605
  presented = token.accessToken;
33526
33606
  const headers = {
@@ -33529,7 +33609,7 @@ function brokerCredential(env, session) {
33529
33609
  };
33530
33610
  presentedAs.set(headers, {
33531
33611
  identity,
33532
- key: keyOf(env, traded.session),
33612
+ key: keyOf(env, traded.session, read),
33533
33613
  token: token.accessToken
33534
33614
  });
33535
33615
  return headers;
@@ -33537,12 +33617,65 @@ function brokerCredential(env, session) {
33537
33617
  identity: (headers) => presentedAs.get(headers)?.identity,
33538
33618
  stale(acting, headers) {
33539
33619
  const told = headers === undefined ? undefined : presentedAs.get(headers);
33540
- dropHeld(told?.key ?? keyOf(env, own(acting)), told?.token);
33620
+ dropHeld(told?.key ?? keyOf(env, own(acting), read), told?.token);
33541
33621
  },
33542
33622
  secret: () => presented
33543
33623
  };
33544
33624
  }
33545
33625
 
33626
+ // ../envoy-client/src/file-token-credential.ts
33627
+ import { readFileSync as readFileSync4 } from "fs";
33628
+ var TOKEN_FILE_VAR = "DISPATCH_BROKER_TOKEN_FILE";
33629
+ var DPOP_KEY_FILE_VAR = "DISPATCH_BROKER_DPOP_KEY_FILE";
33630
+ var PKCS8_LABEL = "PRIVATE KEY";
33631
+ var PKCS8_PEM = new RegExp(`^-----BEGIN ${PKCS8_LABEL}-----\\r?\\n(?:[A-Za-z0-9+/=]+\\r?\\n)+-----END ${PKCS8_LABEL}-----$`);
33632
+ function readNamed(variable, filePath) {
33633
+ try {
33634
+ return readFileSync4(filePath, "utf8");
33635
+ } catch (error) {
33636
+ throw new Error(`${variable} names ${filePath}, which could not be read (${readErrorCode(error)})`);
33637
+ }
33638
+ }
33639
+ function tokenIn(filePath) {
33640
+ const token = readNamed(TOKEN_FILE_VAR, filePath).trim();
33641
+ if (token === "") {
33642
+ throw new Error(`${TOKEN_FILE_VAR} names ${filePath}, which holds no token: it is empty or blank`);
33643
+ }
33644
+ if (!sendable(token)) {
33645
+ throw new Error(`${TOKEN_FILE_VAR} names ${filePath}, which holds whitespace or a control character inside its token`);
33646
+ }
33647
+ return holdSecret(token);
33648
+ }
33649
+ async function keyIn(filePath) {
33650
+ const pem = readNamed(DPOP_KEY_FILE_VAR, filePath).trim();
33651
+ if (!PKCS8_PEM.test(pem)) {
33652
+ throw new Error(`${DPOP_KEY_FILE_VAR} names ${filePath}, which does not hold one P-256 private key in PKCS#8 PEM`);
33653
+ }
33654
+ return await importDpopKey(pem, `${DPOP_KEY_FILE_VAR}'s key ${filePath}`);
33655
+ }
33656
+ function fileTokenCredential(files, dispatchUrl) {
33657
+ const origin = httpUrl2(dispatchUrl)?.origin;
33658
+ let presented = "";
33659
+ return {
33660
+ scheme: "DPoP",
33661
+ async headers(method, url) {
33662
+ const target = httpUrl2(url)?.origin;
33663
+ if (origin === undefined || target !== origin) {
33664
+ throw new Error(`the token ${TOKEN_FILE_VAR} names goes to DISPATCH_URL's origin (${origin}) alone, and this request is for ${target ?? "a URL that is not http or https"}`);
33665
+ }
33666
+ const token = tokenIn(files.tokenFile);
33667
+ const key = await keyIn(files.keyFile);
33668
+ presented = token;
33669
+ return {
33670
+ Authorization: `DPoP ${token}`,
33671
+ DPoP: await key.proof({ method, url, accessToken: token })
33672
+ };
33673
+ },
33674
+ stale() {},
33675
+ secret: () => presented
33676
+ };
33677
+ }
33678
+
33546
33679
  // ../envoy-client/src/dispatch-config.ts
33547
33680
  var DEFAULT_SERVER_URL = "http://localhost:8766";
33548
33681
  function checkoutPair(checkout, serverUrl) {
@@ -33587,13 +33720,19 @@ function lostDispatchUrlNotice(env, config) {
33587
33720
  ].join("; ");
33588
33721
  }
33589
33722
  function dispatchSettings(env, config, options = {}) {
33590
- const target = dispatchTarget(env, config);
33723
+ const target = dispatchTarget(env, config, options.tokenFiles === true);
33591
33724
  if (!target.enabled)
33592
33725
  return target;
33593
33726
  const { url, urlSetting, source } = target;
33594
33727
  let credential;
33595
33728
  try {
33596
- credential = source.kind === "broker" ? brokerCredential(env, options.session) : bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
33729
+ if (source.kind === "broker")
33730
+ credential = brokerCredential(env, options.session, source.read);
33731
+ else if (source.kind === "files")
33732
+ credential = fileTokenCredential(source, url);
33733
+ else {
33734
+ credential = bearerCredential(source.kind === "variable" ? source.token : fileBearer(source, url, "DISPATCH", env, options.commands));
33735
+ }
33597
33736
  } catch (error) {
33598
33737
  return offWithError(messageFor(error));
33599
33738
  }
@@ -33616,6 +33755,63 @@ function dispatchUrl(env, config) {
33616
33755
  const target = dispatchTarget(env, config);
33617
33756
  return target.enabled ? target.url : undefined;
33618
33757
  }
33758
+ var BESIDE_TOKEN_FILES = [
33759
+ "DISPATCH_TOKEN_BROKER",
33760
+ "DISPATCH_TOKEN_BROKER_READ",
33761
+ "DISPATCH_TOKEN_BROKER_AS_OF",
33762
+ "DISPATCH_TOKEN",
33763
+ "DISPATCH_TOKEN_FILE",
33764
+ BROKER_URL_VAR,
33765
+ IDENTITY_VAR
33766
+ ];
33767
+ function tokenFilesSet(env) {
33768
+ const set = [
33769
+ ...nonEmpty(env.DISPATCH_BROKER_TOKEN_FILE) === undefined ? [] : [TOKEN_FILE_VAR],
33770
+ ...nonEmpty(env.DISPATCH_BROKER_DPOP_KEY_FILE) === undefined ? [] : [DPOP_KEY_FILE_VAR]
33771
+ ];
33772
+ if (set.length === 0)
33773
+ return;
33774
+ return `${set.join(" and ")} ${set.length === 1 ? "is" : "are"} set`;
33775
+ }
33776
+ function settingsBesideTokenFiles(env) {
33777
+ return BESIDE_TOKEN_FILES.filter((name) => nonEmpty(env[name]) !== undefined).map((name) => `${name} is set`);
33778
+ }
33779
+ function tokenFilesTarget(env, config, taken) {
33780
+ const set = tokenFilesSet(env);
33781
+ if (set === undefined)
33782
+ return;
33783
+ if (!taken) {
33784
+ return offWithError(`${set}, and only the dispatch command reads the token files: Dispatch is off here rather than written with another credential beside them`);
33785
+ }
33786
+ const tokenFile = nonEmpty(env.DISPATCH_BROKER_TOKEN_FILE);
33787
+ const keyFile = nonEmpty(env.DISPATCH_BROKER_DPOP_KEY_FILE);
33788
+ const explicitUrl = nonEmpty(env.DISPATCH_URL);
33789
+ const { checkout } = config;
33790
+ const problems = [
33791
+ ...tokenFile === undefined ? [`${TOKEN_FILE_VAR} is not set`] : [],
33792
+ ...keyFile === undefined ? [`${DPOP_KEY_FILE_VAR} is not set`] : [],
33793
+ ...explicitUrl === undefined ? ["DISPATCH_URL is not set"] : [],
33794
+ ...settingsBesideTokenFiles(env),
33795
+ ...config.dispatch.token === undefined ? [] : [`dispatch.token is set in ${config.path}`],
33796
+ ...checkout?.kind === "valid" && checkout.dispatch.token !== undefined ? [`dispatch.token is set in ${checkout.path}`] : [],
33797
+ ...checkout?.kind === "invalid" ? [`${checkout.error}, so whether it sets dispatch.token cannot be told`] : []
33798
+ ];
33799
+ if (problems.length > 0 || tokenFile === undefined || keyFile === undefined || explicitUrl === undefined) {
33800
+ return offWithError(`${TOKEN_FILE_VAR} and ${DPOP_KEY_FILE_VAR} go together, with DISPATCH_URL, as the dispatch command's only Dispatch credential: ${problems.join("; ")}`);
33801
+ }
33802
+ if (config.dispatch.enabled === false) {
33803
+ return offWithNotice(`${config.path} sets dispatch.enabled to false: Dispatch is off`);
33804
+ }
33805
+ if (httpUrl2(explicitUrl) === undefined) {
33806
+ return offWithError("DISPATCH_URL must be an http or https URL");
33807
+ }
33808
+ return {
33809
+ enabled: true,
33810
+ url: withoutTrailingSlashes(explicitUrl),
33811
+ urlSetting: "DISPATCH_URL",
33812
+ source: { kind: "files", tokenFile, keyFile }
33813
+ };
33814
+ }
33619
33815
  function brokerRouteForced(env) {
33620
33816
  const written = (env.DISPATCH_TOKEN_BROKER ?? "").trim();
33621
33817
  if (written === "")
@@ -33624,12 +33820,55 @@ function brokerRouteForced(env) {
33624
33820
  return true;
33625
33821
  return offWithError("DISPATCH_TOKEN_BROKER takes 1: set it to 1 where this session's Dispatch credential is traded at the secrets broker (the person signed in on this machine, else the machine's own identity), and leave it unset where a bearer is read as usual");
33626
33822
  }
33627
- function dispatchTarget(env, config) {
33823
+ var CUT_FORM = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
33824
+ var ZERO_TIME = Date.parse("0001-01-01T00:00:00.000Z");
33825
+ function isCut(text) {
33826
+ const parts = CUT_FORM.exec(text);
33827
+ if (parts === null)
33828
+ return false;
33829
+ const [year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0] = parts.slice(1, 7).map((part) => Number(part ?? "0"));
33830
+ const [zoneHour = 0, zoneMinute = 0] = parts.slice(9, 11).map((part) => Number(part ?? "0"));
33831
+ const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
33832
+ const exists = month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth && hour <= 23 && minute <= 59 && second <= 59 && zoneHour <= 23 && zoneMinute <= 59;
33833
+ if (!exists)
33834
+ return false;
33835
+ const offset = (parts[8] === "-" ? -1 : 1) * (zoneHour * 60 + zoneMinute);
33836
+ const instant = new Date(0);
33837
+ instant.setUTCFullYear(year, month - 1, day);
33838
+ instant.setUTCHours(hour, minute - offset, second, 0);
33839
+ return Number(parts[7] ?? "0") !== 0 || instant.getTime() !== ZERO_TIME;
33840
+ }
33841
+ function readTradeSetting(env) {
33842
+ const read = (env.DISPATCH_TOKEN_BROKER_READ ?? "").trim();
33843
+ const cut = (env.DISPATCH_TOKEN_BROKER_AS_OF ?? "").trim();
33844
+ if (read !== "" && read !== "1") {
33845
+ return offWithError("DISPATCH_TOKEN_BROKER_READ takes 1: set it to 1 where this session's Dispatch credential is a broker token that only reads, and leave it unset where it writes");
33846
+ }
33847
+ if (read === "") {
33848
+ if (cut === "")
33849
+ return;
33850
+ return offWithError("DISPATCH_TOKEN_BROKER_AS_OF names the cut a read-only token reads at, and goes only beside DISPATCH_TOKEN_BROKER_READ=1: set DISPATCH_TOKEN_BROKER_READ to 1 beside it, or unset DISPATCH_TOKEN_BROKER_AS_OF");
33851
+ }
33852
+ if (cut === "")
33853
+ return {};
33854
+ if (!isCut(cut)) {
33855
+ return offWithError("DISPATCH_TOKEN_BROKER_AS_OF is not an RFC 3339 time with at most six fractional digits and Z or a numeric offset, such as 1999-12-31T23:59:59Z");
33856
+ }
33857
+ return { asOf: cut };
33858
+ }
33859
+ function dispatchTarget(env, config, tokenFiles = false) {
33628
33860
  if (config.kind === "failed")
33629
33861
  return offWithError(config.error);
33630
- const forced = brokerRouteForced(env);
33631
- if (typeof forced !== "boolean")
33632
- return forced;
33862
+ const files = tokenFilesTarget(env, config, tokenFiles);
33863
+ if (files !== undefined)
33864
+ return files;
33865
+ const brokerOnly = brokerRouteForced(env);
33866
+ if (typeof brokerOnly !== "boolean")
33867
+ return brokerOnly;
33868
+ const read = readTradeSetting(env);
33869
+ if (read !== undefined && "enabled" in read)
33870
+ return read;
33871
+ const forced = brokerOnly || read !== undefined;
33633
33872
  const explicitUrl = nonEmpty(env.DISPATCH_URL);
33634
33873
  const checkoutFile = explicitUrl === undefined ? config.checkout : null;
33635
33874
  if (checkoutFile?.kind === "invalid")
@@ -33671,10 +33910,10 @@ function dispatchTarget(env, config) {
33671
33910
  if (route.traded) {
33672
33911
  const brokered = withoutTrailingSlashes(explicitUrl ?? own.serverUrl ?? DEFAULT_SERVER_URL);
33673
33912
  const urlSetting = explicitUrl !== undefined ? "DISPATCH_URL" : own.serverUrl !== undefined ? `dispatch.serverUrl in ${config.path}` : DEFAULT_URL_SETTING;
33674
- return { enabled: true, url: brokered, urlSetting, source: { kind: "broker" } };
33913
+ return { enabled: true, url: brokered, urlSetting, source: { kind: "broker", read } };
33675
33914
  }
33676
33915
  if (forced) {
33677
- return offWithError(`DISPATCH_TOKEN_BROKER is set, so this session's Dispatch credential is traded at the secrets broker (the person signed in on this machine, else the machine's own identity), and ${route.gap}: Dispatch is off rather than written with whatever bearer this box holds`);
33916
+ return offWithError(`${read === undefined ? "DISPATCH_TOKEN_BROKER" : "DISPATCH_TOKEN_BROKER_READ"} is set, so this session's Dispatch credential is traded at the secrets broker (the person signed in on this machine, else the machine's own identity), and ${route.gap}: Dispatch is off rather than written with whatever bearer this box holds`);
33678
33917
  }
33679
33918
  return offWithError(explicitUrl === undefined ? `${config.path}: dispatch is enabled and no token is: set dispatch.token, or DISPATCH_TOKEN or DISPATCH_TOKEN_FILE` : `DISPATCH_URL is set and no token is: set DISPATCH_TOKEN or DISPATCH_TOKEN_FILE, or dispatch.token in ${config.path}`);
33680
33919
  }
@@ -33860,7 +34099,6 @@ function brokerNatsCredential(env, session, source = NATS_AUTH_VAR, tradeDeadlin
33860
34099
  admissions: () => admissions
33861
34100
  };
33862
34101
  }
33863
- var RENEW_FLOOR_MS = 1000;
33864
34102
  var RETRY_FIRST_MS = 2000;
33865
34103
  var RETRY_LAST_MS = 60000;
33866
34104
  var WARN_AGAIN_MS = 30 * 60000;
@@ -33917,11 +34155,7 @@ function warnedEvery(warn) {
33917
34155
  };
33918
34156
  }
33919
34157
  function renewDelay(expiry, now) {
33920
- const remaining = expiry - now;
33921
- if (remaining <= 0)
33922
- return 0;
33923
- const ahead = remaining - Math.min(DEFAULT_RENEW_BEFORE_MS, remaining / 2);
33924
- return Math.max(Math.min(RENEW_FLOOR_MS, remaining / 2), ahead);
34158
+ return renewalAt(expiry, now, DEFAULT_RENEW_BEFORE_MS) - now;
33925
34159
  }
33926
34160
  function keepNatsCredential(connection, credential, warn) {
33927
34161
  let stopped = false;
@@ -34360,7 +34594,8 @@ function sessionDispatchSettings(file, env, options) {
34360
34594
  return {
34361
34595
  dispatch: dispatchSettings(env, config, {
34362
34596
  commands: options.commands,
34363
- session: options.session
34597
+ session: options.session,
34598
+ tokenFiles: options.tokenFiles
34364
34599
  }),
34365
34600
  warnings: config.kind === "read" ? config.warnings : [],
34366
34601
  missing: config.kind === "read" ? config.missing : null
@@ -34399,7 +34634,7 @@ function claudeProjectDirectory(environment, fallback) {
34399
34634
 
34400
34635
  // src/codex/codex-session-record.ts
34401
34636
  import { spawnSync } from "child_process";
34402
- import { readFileSync as readFileSync5, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
34637
+ import { readFileSync as readFileSync6, readlinkSync as readlinkSync2, unwatchFile, watchFile } from "fs";
34403
34638
  import { mkdir as mkdir3, readFile as readFile5, rename as rename4, utimes as utimes3, writeFile as writeFile2 } from "fs/promises";
34404
34639
  import { homedir as homedir3 } from "os";
34405
34640
  import { basename as basename4, dirname as dirname5, join as join9 } from "path";
@@ -34409,7 +34644,7 @@ import { readFile as readFile4 } from "fs/promises";
34409
34644
  import { basename as basename3, join as join8 } from "path";
34410
34645
 
34411
34646
  // src/session-state.ts
34412
- import { readFileSync as readFileSync4 } from "fs";
34647
+ import { readFileSync as readFileSync5 } from "fs";
34413
34648
  import { mkdir as mkdir2, readdir as readdir3, rename as rename3, rm as rm3, stat as stat3, utimes as utimes2, writeFile } from "fs/promises";
34414
34649
  import { dirname as dirname4, join as join7 } from "path";
34415
34650
  async function writeAtomicStateFile(file, contents) {
@@ -34455,7 +34690,7 @@ async function removeChosenTitle(file) {
34455
34690
  }
34456
34691
  function readChosenTitleSync(file) {
34457
34692
  try {
34458
- return readFileSync4(file, "utf8");
34693
+ return readFileSync5(file, "utf8");
34459
34694
  } catch {
34460
34695
  return;
34461
34696
  }
@@ -34648,14 +34883,14 @@ function codexProcessId(readComm = procComm, readParent = procParent) {
34648
34883
  }
34649
34884
  function procComm(pid) {
34650
34885
  try {
34651
- return readFileSync5(`/proc/${pid}/comm`, "utf8").trim();
34886
+ return readFileSync6(`/proc/${pid}/comm`, "utf8").trim();
34652
34887
  } catch {
34653
34888
  return;
34654
34889
  }
34655
34890
  }
34656
34891
  function procParent(pid) {
34657
34892
  try {
34658
- const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
34893
+ const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
34659
34894
  const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
34660
34895
  return Number.isInteger(parent) ? parent : undefined;
34661
34896
  } catch {
@@ -34669,7 +34904,7 @@ var PS_OPTIONS = {
34669
34904
  };
34670
34905
  function procStarted(pid) {
34671
34906
  try {
34672
- const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
34907
+ const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
34673
34908
  return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
34674
34909
  } catch {
34675
34910
  return;
@@ -34690,7 +34925,7 @@ function recordOfProcess(record, pid) {
34690
34925
  function sharedAppServer(pid) {
34691
34926
  let argv;
34692
34927
  try {
34693
- argv = readFileSync5(`/proc/${pid}/cmdline`, "utf8").split("\x00");
34928
+ argv = readFileSync6(`/proc/${pid}/cmdline`, "utf8").split("\x00");
34694
34929
  } catch {
34695
34930
  const ps = spawnSync("ps", ["-o", "args=", "-p", String(pid)], PS_OPTIONS);
34696
34931
  if (ps.status !== 0)