agent-shim 8.10.0 → 8.11.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.
package/dist/cli.cjs CHANGED
@@ -3248,42 +3248,42 @@ var require_defaults = __commonJS({
3248
3248
  var require_env_paths = __commonJS({
3249
3249
  "node_modules/.pnpm/env-paths@2.2.1/node_modules/env-paths/index.js"(exports2, module2) {
3250
3250
  "use strict";
3251
- var path41 = require("path");
3251
+ var path42 = require("path");
3252
3252
  var os10 = require("os");
3253
3253
  var homedir = os10.homedir();
3254
3254
  var tmpdir = os10.tmpdir();
3255
3255
  var { env } = process;
3256
3256
  var macos = (name) => {
3257
- const library = path41.join(homedir, "Library");
3257
+ const library = path42.join(homedir, "Library");
3258
3258
  return {
3259
- data: path41.join(library, "Application Support", name),
3260
- config: path41.join(library, "Preferences", name),
3261
- cache: path41.join(library, "Caches", name),
3262
- log: path41.join(library, "Logs", name),
3263
- temp: path41.join(tmpdir, name)
3259
+ data: path42.join(library, "Application Support", name),
3260
+ config: path42.join(library, "Preferences", name),
3261
+ cache: path42.join(library, "Caches", name),
3262
+ log: path42.join(library, "Logs", name),
3263
+ temp: path42.join(tmpdir, name)
3264
3264
  };
3265
3265
  };
3266
3266
  var windows = (name) => {
3267
- const appData = env.APPDATA || path41.join(homedir, "AppData", "Roaming");
3268
- const localAppData = env.LOCALAPPDATA || path41.join(homedir, "AppData", "Local");
3267
+ const appData = env.APPDATA || path42.join(homedir, "AppData", "Roaming");
3268
+ const localAppData = env.LOCALAPPDATA || path42.join(homedir, "AppData", "Local");
3269
3269
  return {
3270
3270
  // Data/config/cache/log are invented by me as Windows isn't opinionated about this
3271
- data: path41.join(localAppData, name, "Data"),
3272
- config: path41.join(appData, name, "Config"),
3273
- cache: path41.join(localAppData, name, "Cache"),
3274
- log: path41.join(localAppData, name, "Log"),
3275
- temp: path41.join(tmpdir, name)
3271
+ data: path42.join(localAppData, name, "Data"),
3272
+ config: path42.join(appData, name, "Config"),
3273
+ cache: path42.join(localAppData, name, "Cache"),
3274
+ log: path42.join(localAppData, name, "Log"),
3275
+ temp: path42.join(tmpdir, name)
3276
3276
  };
3277
3277
  };
3278
3278
  var linux = (name) => {
3279
- const username = path41.basename(homedir);
3279
+ const username = path42.basename(homedir);
3280
3280
  return {
3281
- data: path41.join(env.XDG_DATA_HOME || path41.join(homedir, ".local", "share"), name),
3282
- config: path41.join(env.XDG_CONFIG_HOME || path41.join(homedir, ".config"), name),
3283
- cache: path41.join(env.XDG_CACHE_HOME || path41.join(homedir, ".cache"), name),
3281
+ data: path42.join(env.XDG_DATA_HOME || path42.join(homedir, ".local", "share"), name),
3282
+ config: path42.join(env.XDG_CONFIG_HOME || path42.join(homedir, ".config"), name),
3283
+ cache: path42.join(env.XDG_CACHE_HOME || path42.join(homedir, ".cache"), name),
3284
3284
  // https://wiki.debian.org/XDGBaseDirectorySpecification#state
3285
- log: path41.join(env.XDG_STATE_HOME || path41.join(homedir, ".local", "state"), name),
3286
- temp: path41.join(tmpdir, username, name)
3285
+ log: path42.join(env.XDG_STATE_HOME || path42.join(homedir, ".local", "state"), name),
3286
+ temp: path42.join(tmpdir, username, name)
3287
3287
  };
3288
3288
  };
3289
3289
  var envPaths = (name, options) => {
@@ -3351,11 +3351,11 @@ var require_util = __commonJS({
3351
3351
  return result;
3352
3352
  }
3353
3353
  exports2.emplace = emplace;
3354
- function getPropertyByPath(source, path41) {
3355
- if (typeof path41 === "string" && Object.prototype.hasOwnProperty.call(source, path41)) {
3356
- return source[path41];
3354
+ function getPropertyByPath(source, path42) {
3355
+ if (typeof path42 === "string" && Object.prototype.hasOwnProperty.call(source, path42)) {
3356
+ return source[path42];
3357
3357
  }
3358
- const parsedPath = typeof path41 === "string" ? path41.split(".") : path41;
3358
+ const parsedPath = typeof path42 === "string" ? path42.split(".") : path42;
3359
3359
  return parsedPath.reduce((previous, key) => {
3360
3360
  if (previous === void 0) {
3361
3361
  return previous;
@@ -3378,9 +3378,9 @@ var require_util = __commonJS({
3378
3378
  return Object.fromEntries(Object.entries(options).filter(([, value2]) => value2 !== void 0));
3379
3379
  }
3380
3380
  exports2.removeUndefinedValuesFromObject = removeUndefinedValuesFromObject;
3381
- async function isDirectory(path41) {
3381
+ async function isDirectory(path42) {
3382
3382
  try {
3383
- const stat = await fs_1.promises.stat(path41);
3383
+ const stat = await fs_1.promises.stat(path42);
3384
3384
  return stat.isDirectory();
3385
3385
  } catch (e) {
3386
3386
  if (e.code === "ENOENT") {
@@ -3390,9 +3390,9 @@ var require_util = __commonJS({
3390
3390
  }
3391
3391
  }
3392
3392
  exports2.isDirectory = isDirectory;
3393
- function isDirectorySync(path41) {
3393
+ function isDirectorySync(path42) {
3394
3394
  try {
3395
- const stat = fs_1.default.statSync(path41);
3395
+ const stat = fs_1.default.statSync(path42);
3396
3396
  return stat.isDirectory();
3397
3397
  } catch (e) {
3398
3398
  if (e.code === "ENOENT") {
@@ -3490,7 +3490,7 @@ var require_ExplorerBase = __commonJS({
3490
3490
  const idx = importStack.indexOf(fullPath);
3491
3491
  if (idx !== -1) {
3492
3492
  throw new Error(`Circular import detected:
3493
- ${[...importStack, fullPath].map((path41, i2) => `${i2 + 1}. ${path41}`).join("\n")} (same as ${idx + 1}.)`);
3493
+ ${[...importStack, fullPath].map((path42, i2) => `${i2 + 1}. ${path42}`).join("\n")} (same as ${idx + 1}.)`);
3494
3494
  }
3495
3495
  }
3496
3496
  }
@@ -3678,9 +3678,9 @@ var require_Explorer = __commonJS({
3678
3678
  throw error62;
3679
3679
  }
3680
3680
  }
3681
- async #fileExists(path41) {
3681
+ async #fileExists(path42) {
3682
3682
  try {
3683
- await promises_1.default.stat(path41);
3683
+ await promises_1.default.stat(path42);
3684
3684
  return true;
3685
3685
  } catch (e) {
3686
3686
  return false;
@@ -3840,9 +3840,9 @@ var require_ExplorerSync = __commonJS({
3840
3840
  throw error62;
3841
3841
  }
3842
3842
  }
3843
- #fileExists(path41) {
3843
+ #fileExists(path42) {
3844
3844
  try {
3845
- fs_1.default.statSync(path41);
3845
+ fs_1.default.statSync(path42);
3846
3846
  return true;
3847
3847
  } catch (e) {
3848
3848
  return false;
@@ -3966,7 +3966,7 @@ var require_dist = __commonJS({
3966
3966
  };
3967
3967
  }
3968
3968
  function getResolvedSearchPlaces(moduleName, toolDefinedSearchPlaces, userConfiguredOptions) {
3969
- const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path41) => path41.replace("{name}", moduleName));
3969
+ const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path42) => path42.replace("{name}", moduleName));
3970
3970
  if (userConfiguredOptions.mergeSearchPlaces) {
3971
3971
  return [...userConfiguredSearchPlaces ?? [], ...toolDefinedSearchPlaces];
3972
3972
  }
@@ -4374,8 +4374,8 @@ var require_utils = __commonJS({
4374
4374
  }
4375
4375
  return output2;
4376
4376
  };
4377
- exports2.basename = (path41, { windows } = {}) => {
4378
- const segs = path41.split(windows ? /[\\/]/ : "/");
4377
+ exports2.basename = (path42, { windows } = {}) => {
4378
+ const segs = path42.split(windows ? /[\\/]/ : "/");
4379
4379
  const last = segs[segs.length - 1];
4380
4380
  if (last === "") {
4381
4381
  return segs[segs.length - 2];
@@ -7003,14 +7003,14 @@ var require_util2 = __commonJS({
7003
7003
  }
7004
7004
  const port = url2.port != null ? url2.port : url2.protocol === "https:" ? 443 : 80;
7005
7005
  let origin = url2.origin != null ? url2.origin : `${url2.protocol || ""}//${url2.hostname || ""}:${port}`;
7006
- let path41 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
7006
+ let path42 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
7007
7007
  if (origin[origin.length - 1] === "/") {
7008
7008
  origin = origin.slice(0, origin.length - 1);
7009
7009
  }
7010
- if (path41 && path41[0] !== "/") {
7011
- path41 = `/${path41}`;
7010
+ if (path42 && path42[0] !== "/") {
7011
+ path42 = `/${path42}`;
7012
7012
  }
7013
- return new URL(`${origin}${path41}`);
7013
+ return new URL(`${origin}${path42}`);
7014
7014
  }
7015
7015
  if (!isHttpOrHttpsPrefixed(url2.origin || url2.protocol)) {
7016
7016
  throw new InvalidArgumentError2("Invalid URL protocol: the URL must start with `http:` or `https:`.");
@@ -7831,9 +7831,9 @@ var require_diagnostics = __commonJS({
7831
7831
  "undici:client:sendHeaders",
7832
7832
  (evt) => {
7833
7833
  const {
7834
- request: { method, path: path41, origin }
7834
+ request: { method, path: path42, origin }
7835
7835
  } = evt;
7836
- debugLog("sending request to %s %s%s", method, origin, path41);
7836
+ debugLog("sending request to %s %s%s", method, origin, path42);
7837
7837
  }
7838
7838
  );
7839
7839
  }
@@ -7851,14 +7851,14 @@ var require_diagnostics = __commonJS({
7851
7851
  "undici:request:headers",
7852
7852
  (evt) => {
7853
7853
  const {
7854
- request: { method, path: path41, origin },
7854
+ request: { method, path: path42, origin },
7855
7855
  response: { statusCode }
7856
7856
  } = evt;
7857
7857
  debugLog(
7858
7858
  "received response to %s %s%s - HTTP %d",
7859
7859
  method,
7860
7860
  origin,
7861
- path41,
7861
+ path42,
7862
7862
  statusCode
7863
7863
  );
7864
7864
  }
@@ -7867,23 +7867,23 @@ var require_diagnostics = __commonJS({
7867
7867
  "undici:request:trailers",
7868
7868
  (evt) => {
7869
7869
  const {
7870
- request: { method, path: path41, origin }
7870
+ request: { method, path: path42, origin }
7871
7871
  } = evt;
7872
- debugLog("trailers received from %s %s%s", method, origin, path41);
7872
+ debugLog("trailers received from %s %s%s", method, origin, path42);
7873
7873
  }
7874
7874
  );
7875
7875
  diagnosticsChannel.subscribe(
7876
7876
  "undici:request:error",
7877
7877
  (evt) => {
7878
7878
  const {
7879
- request: { method, path: path41, origin },
7879
+ request: { method, path: path42, origin },
7880
7880
  error: error62
7881
7881
  } = evt;
7882
7882
  debugLog(
7883
7883
  "request to %s %s%s errored - %s",
7884
7884
  method,
7885
7885
  origin,
7886
- path41,
7886
+ path42,
7887
7887
  error62.message
7888
7888
  );
7889
7889
  }
@@ -7998,7 +7998,7 @@ var require_request = __commonJS({
7998
7998
  var kHandler = /* @__PURE__ */ Symbol("handler");
7999
7999
  var Request2 = class {
8000
8000
  constructor(origin, {
8001
- path: path41,
8001
+ path: path42,
8002
8002
  method,
8003
8003
  body,
8004
8004
  headers,
@@ -8015,11 +8015,11 @@ var require_request = __commonJS({
8015
8015
  maxRedirections,
8016
8016
  typeOfService
8017
8017
  }, handler) {
8018
- if (typeof path41 !== "string") {
8018
+ if (typeof path42 !== "string") {
8019
8019
  throw new InvalidArgumentError2("path must be a string");
8020
- } else if (path41[0] !== "/" && !(path41.startsWith("http://") || path41.startsWith("https://")) && method !== "CONNECT") {
8020
+ } else if (path42[0] !== "/" && !(path42.startsWith("http://") || path42.startsWith("https://")) && method !== "CONNECT") {
8021
8021
  throw new InvalidArgumentError2("path must be an absolute URL or start with a slash");
8022
- } else if (invalidPathRegex.test(path41)) {
8022
+ } else if (invalidPathRegex.test(path42)) {
8023
8023
  throw new InvalidArgumentError2("invalid request path");
8024
8024
  }
8025
8025
  if (typeof method !== "string") {
@@ -8094,7 +8094,7 @@ var require_request = __commonJS({
8094
8094
  this.completed = false;
8095
8095
  this.aborted = false;
8096
8096
  this.upgrade = upgrade || null;
8097
- this.path = query ? serializePathWithQuery(path41, query) : path41;
8097
+ this.path = query ? serializePathWithQuery(path42, query) : path42;
8098
8098
  this.origin = origin;
8099
8099
  this.protocol = getProtocolFromUrlString(origin);
8100
8100
  this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
@@ -13276,7 +13276,7 @@ var require_client_h1 = __commonJS({
13276
13276
  return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
13277
13277
  }
13278
13278
  function writeH1(client, request7) {
13279
- const { method, path: path41, host, upgrade, blocking, reset } = request7;
13279
+ const { method, path: path42, host, upgrade, blocking, reset } = request7;
13280
13280
  let { body, headers, contentLength } = request7;
13281
13281
  const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
13282
13282
  if (util.isFormDataLike(body)) {
@@ -13354,7 +13354,7 @@ var require_client_h1 = __commonJS({
13354
13354
  if (socket.setTypeOfService) {
13355
13355
  socket.setTypeOfService(request7.typeOfService);
13356
13356
  }
13357
- let header = `${method} ${path41} HTTP/1.1\r
13357
+ let header = `${method} ${path42} HTTP/1.1\r
13358
13358
  `;
13359
13359
  if (typeof host === "string") {
13360
13360
  header += `host: ${host}\r
@@ -14033,7 +14033,7 @@ var require_client_h2 = __commonJS({
14033
14033
  const headersTimeout = request7.headersTimeout ?? client[kHeadersTimeout];
14034
14034
  const bodyTimeout = request7.bodyTimeout ?? client[kBodyTimeout];
14035
14035
  const session = client[kHTTP2Session];
14036
- const { method, path: path41, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request7;
14036
+ const { method, path: path42, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request7;
14037
14037
  let { body } = request7;
14038
14038
  if (upgrade != null && upgrade !== "websocket") {
14039
14039
  util.errorRequest(client, request7, new InvalidArgumentError2(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
@@ -14102,7 +14102,7 @@ var require_client_h2 = __commonJS({
14102
14102
  }
14103
14103
  headers[HTTP2_HEADER_METHOD] = "CONNECT";
14104
14104
  headers[HTTP2_HEADER_PROTOCOL] = "websocket";
14105
- headers[HTTP2_HEADER_PATH] = path41;
14105
+ headers[HTTP2_HEADER_PATH] = path42;
14106
14106
  if (protocol === "ws:" || protocol === "wss:") {
14107
14107
  headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
14108
14108
  } else {
@@ -14144,7 +14144,7 @@ var require_client_h2 = __commonJS({
14144
14144
  stream.setTimeout(headersTimeout);
14145
14145
  return true;
14146
14146
  }
14147
- headers[HTTP2_HEADER_PATH] = path41;
14147
+ headers[HTTP2_HEADER_PATH] = path42;
14148
14148
  headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
14149
14149
  const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
14150
14150
  if (body && typeof body.read === "function") {
@@ -16496,10 +16496,10 @@ var require_proxy_agent = __commonJS({
16496
16496
  };
16497
16497
  const {
16498
16498
  origin,
16499
- path: path41 = "/",
16499
+ path: path42 = "/",
16500
16500
  headers = {}
16501
16501
  } = opts;
16502
- opts.path = origin + path41;
16502
+ opts.path = origin + path42;
16503
16503
  if (!("host" in headers) && !("Host" in headers)) {
16504
16504
  const { host } = new URL(origin);
16505
16505
  headers.host = host;
@@ -18608,20 +18608,20 @@ var require_mock_utils = __commonJS({
18608
18608
  }
18609
18609
  return normalizedQp;
18610
18610
  }
18611
- function safeUrl(path41) {
18612
- if (typeof path41 !== "string") {
18613
- return path41;
18611
+ function safeUrl(path42) {
18612
+ if (typeof path42 !== "string") {
18613
+ return path42;
18614
18614
  }
18615
- const pathSegments = path41.split("?", 3);
18615
+ const pathSegments = path42.split("?", 3);
18616
18616
  if (pathSegments.length !== 2) {
18617
- return path41;
18617
+ return path42;
18618
18618
  }
18619
18619
  const qp = new URLSearchParams(pathSegments.pop());
18620
18620
  qp.sort();
18621
18621
  return [...pathSegments, qp.toString()].join("?");
18622
18622
  }
18623
- function matchKey(mockDispatch2, { path: path41, method, body, headers }) {
18624
- const pathMatch = matchValue(mockDispatch2.path, path41);
18623
+ function matchKey(mockDispatch2, { path: path42, method, body, headers }) {
18624
+ const pathMatch = matchValue(mockDispatch2.path, path42);
18625
18625
  const methodMatch = matchValue(mockDispatch2.method, method);
18626
18626
  const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
18627
18627
  const headersMatch = matchHeaders(mockDispatch2, headers);
@@ -18646,8 +18646,8 @@ var require_mock_utils = __commonJS({
18646
18646
  const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
18647
18647
  const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
18648
18648
  const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
18649
- let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path41, ignoreTrailingSlash }) => {
18650
- return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path41)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path41), resolvedPath);
18649
+ let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path42, ignoreTrailingSlash }) => {
18650
+ return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path42)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path42), resolvedPath);
18651
18651
  });
18652
18652
  if (matchedMockDispatches.length === 0) {
18653
18653
  throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
@@ -18686,19 +18686,19 @@ var require_mock_utils = __commonJS({
18686
18686
  mockDispatches.splice(index, 1);
18687
18687
  }
18688
18688
  }
18689
- function removeTrailingSlash(path41) {
18690
- while (path41.endsWith("/")) {
18691
- path41 = path41.slice(0, -1);
18689
+ function removeTrailingSlash(path42) {
18690
+ while (path42.endsWith("/")) {
18691
+ path42 = path42.slice(0, -1);
18692
18692
  }
18693
- if (path41.length === 0) {
18694
- path41 = "/";
18693
+ if (path42.length === 0) {
18694
+ path42 = "/";
18695
18695
  }
18696
- return path41;
18696
+ return path42;
18697
18697
  }
18698
18698
  function buildKey(opts) {
18699
- const { path: path41, method, body, headers, query } = opts;
18699
+ const { path: path42, method, body, headers, query } = opts;
18700
18700
  return {
18701
- path: path41,
18701
+ path: path42,
18702
18702
  method,
18703
18703
  body,
18704
18704
  headers,
@@ -19388,10 +19388,10 @@ var require_pending_interceptors_formatter = __commonJS({
19388
19388
  }
19389
19389
  format(pendingInterceptors) {
19390
19390
  const withPrettyHeaders = pendingInterceptors.map(
19391
- ({ method, path: path41, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
19391
+ ({ method, path: path42, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
19392
19392
  Method: method,
19393
19393
  Origin: origin,
19394
- Path: path41,
19394
+ Path: path42,
19395
19395
  "Status code": statusCode,
19396
19396
  Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
19397
19397
  Invocations: timesInvoked,
@@ -19473,9 +19473,9 @@ var require_mock_agent = __commonJS({
19473
19473
  const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
19474
19474
  const dispatchOpts = { ...opts };
19475
19475
  if (acceptNonStandardSearchParameters && dispatchOpts.path) {
19476
- const [path41, searchParams] = dispatchOpts.path.split("?");
19476
+ const [path42, searchParams] = dispatchOpts.path.split("?");
19477
19477
  const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
19478
- dispatchOpts.path = `${path41}?${normalizedSearchParams}`;
19478
+ dispatchOpts.path = `${path42}?${normalizedSearchParams}`;
19479
19479
  }
19480
19480
  return this[kAgent].dispatch(dispatchOpts, handler);
19481
19481
  }
@@ -19876,12 +19876,12 @@ var require_snapshot_recorder = __commonJS({
19876
19876
  * @return {Promise<void>} - Resolves when snapshots are loaded
19877
19877
  */
19878
19878
  async loadSnapshots(filePath) {
19879
- const path41 = filePath || this.#snapshotPath;
19880
- if (!path41) {
19879
+ const path42 = filePath || this.#snapshotPath;
19880
+ if (!path42) {
19881
19881
  throw new InvalidArgumentError2("Snapshot path is required");
19882
19882
  }
19883
19883
  try {
19884
- const data = await readFile(resolve(path41), "utf8");
19884
+ const data = await readFile(resolve(path42), "utf8");
19885
19885
  const parsed = JSON.parse(data);
19886
19886
  if (Array.isArray(parsed)) {
19887
19887
  this.#snapshots.clear();
@@ -19895,7 +19895,7 @@ var require_snapshot_recorder = __commonJS({
19895
19895
  if (error62.code === "ENOENT") {
19896
19896
  this.#snapshots.clear();
19897
19897
  } else {
19898
- throw new UndiciError(`Failed to load snapshots from ${path41}`, { cause: error62 });
19898
+ throw new UndiciError(`Failed to load snapshots from ${path42}`, { cause: error62 });
19899
19899
  }
19900
19900
  }
19901
19901
  }
@@ -19906,11 +19906,11 @@ var require_snapshot_recorder = __commonJS({
19906
19906
  * @returns {Promise<void>} - Resolves when snapshots are saved
19907
19907
  */
19908
19908
  async saveSnapshots(filePath) {
19909
- const path41 = filePath || this.#snapshotPath;
19910
- if (!path41) {
19909
+ const path42 = filePath || this.#snapshotPath;
19910
+ if (!path42) {
19911
19911
  throw new InvalidArgumentError2("Snapshot path is required");
19912
19912
  }
19913
- const resolvedPath = resolve(path41);
19913
+ const resolvedPath = resolve(path42);
19914
19914
  await mkdir(dirname2(resolvedPath), { recursive: true });
19915
19915
  const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
19916
19916
  hash: hash2,
@@ -20542,15 +20542,15 @@ var require_redirect_handler = __commonJS({
20542
20542
  return;
20543
20543
  }
20544
20544
  const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
20545
- const path41 = search ? `${pathname}${search}` : pathname;
20546
- const redirectUrlString = `${origin}${path41}`;
20545
+ const path42 = search ? `${pathname}${search}` : pathname;
20546
+ const redirectUrlString = `${origin}${path42}`;
20547
20547
  for (const historyUrl of this.history) {
20548
20548
  if (historyUrl.toString() === redirectUrlString) {
20549
20549
  throw new InvalidArgumentError2(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`);
20550
20550
  }
20551
20551
  }
20552
20552
  this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
20553
- this.opts.path = path41;
20553
+ this.opts.path = path42;
20554
20554
  this.opts.origin = origin;
20555
20555
  this.opts.query = null;
20556
20556
  }
@@ -22310,10 +22310,10 @@ var require_cache_handler = __commonJS({
22310
22310
  }
22311
22311
  return locationUrl.pathname + locationUrl.search;
22312
22312
  }
22313
- function deleteCachedUri(store, cacheKey, path41) {
22313
+ function deleteCachedUri(store, cacheKey, path42) {
22314
22314
  deleteCachedValue(store, {
22315
22315
  ...cacheKey,
22316
- path: path41
22316
+ path: path42
22317
22317
  });
22318
22318
  for (let i2 = 0; i2 < util.safeHTTPMethods.length; i2++) {
22319
22319
  const method = util.safeHTTPMethods[i2];
@@ -22321,7 +22321,7 @@ var require_cache_handler = __commonJS({
22321
22321
  deleteCachedValue(store, {
22322
22322
  ...cacheKey,
22323
22323
  method,
22324
- path: path41
22324
+ path: path42
22325
22325
  });
22326
22326
  }
22327
22327
  }
@@ -22332,9 +22332,9 @@ var require_cache_handler = __commonJS({
22332
22332
  }
22333
22333
  const values = Array.isArray(headerValue2) ? headerValue2 : [headerValue2];
22334
22334
  for (let i2 = 0; i2 < values.length; i2++) {
22335
- const path41 = getSameOriginPath(cacheKey, values[i2]);
22336
- if (path41 !== void 0) {
22337
- deleteCachedUri(store, cacheKey, path41);
22335
+ const path42 = getSameOriginPath(cacheKey, values[i2]);
22336
+ if (path42 !== void 0) {
22337
+ deleteCachedUri(store, cacheKey, path42);
22338
22338
  }
22339
22339
  }
22340
22340
  }
@@ -27334,11 +27334,11 @@ var require_fetch = __commonJS({
27334
27334
  function dispatch({ body }) {
27335
27335
  const url2 = requestCurrentURL(request7);
27336
27336
  const agent = fetchParams.controller.dispatcher;
27337
- const path41 = url2.pathname + url2.search;
27337
+ const path42 = url2.pathname + url2.search;
27338
27338
  const hasTrailingQuestionMark = url2.search.length === 0 && url2.href[url2.href.length - url2.hash.length - 1] === "?";
27339
27339
  return new Promise((resolve, reject) => agent.dispatch(
27340
27340
  {
27341
- path: hasTrailingQuestionMark ? `${path41}?` : path41,
27341
+ path: hasTrailingQuestionMark ? `${path42}?` : path42,
27342
27342
  origin: url2.origin,
27343
27343
  method: request7.method,
27344
27344
  body: agent.isMockActive ? request7.body && (request7.body.source || request7.body.stream) : body,
@@ -28285,9 +28285,9 @@ var require_util5 = __commonJS({
28285
28285
  }
28286
28286
  }
28287
28287
  }
28288
- function validateCookiePath(path41) {
28289
- for (let i2 = 0; i2 < path41.length; ++i2) {
28290
- const code = path41.charCodeAt(i2);
28288
+ function validateCookiePath(path42) {
28289
+ for (let i2 = 0; i2 < path42.length; ++i2) {
28290
+ const code = path42.charCodeAt(i2);
28291
28291
  if (code < 32 || // exclude CTLs (0-31)
28292
28292
  code > 126 || // exclude DEL and non-ascii
28293
28293
  code === 59) {
@@ -31635,11 +31635,11 @@ var require_undici = __commonJS({
31635
31635
  if (typeof opts.path !== "string") {
31636
31636
  throw new InvalidArgumentError2("invalid opts.path");
31637
31637
  }
31638
- let path41 = opts.path;
31638
+ let path42 = opts.path;
31639
31639
  if (!opts.path.startsWith("/")) {
31640
- path41 = `/${path41}`;
31640
+ path42 = `/${path42}`;
31641
31641
  }
31642
- url2 = new URL(util.parseOrigin(url2).origin + path41);
31642
+ url2 = new URL(util.parseOrigin(url2).origin + path42);
31643
31643
  } else {
31644
31644
  if (!opts) {
31645
31645
  opts = typeof url2 === "object" ? url2 : {};
@@ -31749,7 +31749,7 @@ ${captureLines}` : capture.stack;
31749
31749
  });
31750
31750
 
31751
31751
  // src/cli.ts
31752
- var import_node_path39 = __toESM(require("node:path"), 1);
31752
+ var import_node_path40 = __toESM(require("node:path"), 1);
31753
31753
 
31754
31754
  // node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
31755
31755
  var CommanderError = class extends Error {
@@ -34862,9 +34862,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
34862
34862
  * @param {string} [path]
34863
34863
  * @return {(string|null|Command)}
34864
34864
  */
34865
- executableDir(path41) {
34866
- if (path41 === void 0) return this._executableDir;
34867
- this._executableDir = path41;
34865
+ executableDir(path42) {
34866
+ if (path42 === void 0) return this._executableDir;
34867
+ this._executableDir = path42;
34868
34868
  return this;
34869
34869
  }
34870
34870
  /**
@@ -36002,10 +36002,10 @@ function mergeDefs(...defs) {
36002
36002
  function cloneDef(schema) {
36003
36003
  return mergeDefs(schema._zod.def);
36004
36004
  }
36005
- function getElementAtPath(obj, path41) {
36006
- if (!path41)
36005
+ function getElementAtPath(obj, path42) {
36006
+ if (!path42)
36007
36007
  return obj;
36008
- return path41.reduce((acc, key) => acc?.[key], obj);
36008
+ return path42.reduce((acc, key) => acc?.[key], obj);
36009
36009
  }
36010
36010
  function promiseAllObject(promisesObj) {
36011
36011
  const keys = Object.keys(promisesObj);
@@ -36345,11 +36345,11 @@ function explicitlyAborted(x, startIndex = 0) {
36345
36345
  }
36346
36346
  return false;
36347
36347
  }
36348
- function prefixIssues(path41, issues) {
36348
+ function prefixIssues(path42, issues) {
36349
36349
  return issues.map((iss) => {
36350
36350
  var _a3;
36351
36351
  (_a3 = iss).path ?? (_a3.path = []);
36352
- iss.path.unshift(path41);
36352
+ iss.path.unshift(path42);
36353
36353
  return iss;
36354
36354
  });
36355
36355
  }
@@ -36799,16 +36799,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
36799
36799
  }
36800
36800
  function formatError(error62, mapper = (issue2) => issue2.message) {
36801
36801
  const fieldErrors = { _errors: [] };
36802
- const processError = (error63, path41 = []) => {
36802
+ const processError = (error63, path42 = []) => {
36803
36803
  for (const issue2 of error63.issues) {
36804
36804
  if (issue2.code === "invalid_union" && issue2.errors.length) {
36805
- issue2.errors.map((issues) => processError({ issues }, [...path41, ...issue2.path]));
36805
+ issue2.errors.map((issues) => processError({ issues }, [...path42, ...issue2.path]));
36806
36806
  } else if (issue2.code === "invalid_key") {
36807
- processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36807
+ processError({ issues: issue2.issues }, [...path42, ...issue2.path]);
36808
36808
  } else if (issue2.code === "invalid_element") {
36809
- processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36809
+ processError({ issues: issue2.issues }, [...path42, ...issue2.path]);
36810
36810
  } else {
36811
- const fullpath = [...path41, ...issue2.path];
36811
+ const fullpath = [...path42, ...issue2.path];
36812
36812
  if (fullpath.length === 0) {
36813
36813
  fieldErrors._errors.push(mapper(issue2));
36814
36814
  } else {
@@ -36847,17 +36847,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
36847
36847
  }
36848
36848
  function treeifyError(error62, mapper = (issue2) => issue2.message) {
36849
36849
  const result = { errors: [] };
36850
- const processError = (error63, path41 = []) => {
36850
+ const processError = (error63, path42 = []) => {
36851
36851
  var _a3;
36852
36852
  for (const issue2 of error63.issues) {
36853
36853
  if (issue2.code === "invalid_union" && issue2.errors.length) {
36854
- issue2.errors.map((issues) => processError({ issues }, [...path41, ...issue2.path]));
36854
+ issue2.errors.map((issues) => processError({ issues }, [...path42, ...issue2.path]));
36855
36855
  } else if (issue2.code === "invalid_key") {
36856
- processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36856
+ processError({ issues: issue2.issues }, [...path42, ...issue2.path]);
36857
36857
  } else if (issue2.code === "invalid_element") {
36858
- processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36858
+ processError({ issues: issue2.issues }, [...path42, ...issue2.path]);
36859
36859
  } else {
36860
- const fullpath = [...path41, ...issue2.path];
36860
+ const fullpath = [...path42, ...issue2.path];
36861
36861
  if (fullpath.length === 0) {
36862
36862
  result.errors.push(mapper(issue2));
36863
36863
  continue;
@@ -36896,8 +36896,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
36896
36896
  }
36897
36897
  function toDotPath(_path) {
36898
36898
  const segs = [];
36899
- const path41 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
36900
- for (const seg of path41) {
36899
+ const path42 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
36900
+ for (const seg of path42) {
36901
36901
  if (typeof seg === "number")
36902
36902
  segs.push(`[${seg}]`);
36903
36903
  else if (typeof seg === "symbol")
@@ -53999,13 +53999,13 @@ function resolveRef(ref, ctx) {
53999
53999
  if (!ref.startsWith("#")) {
54000
54000
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
54001
54001
  }
54002
- const path41 = ref.slice(1).split("/").filter(Boolean);
54003
- if (path41.length === 0) {
54002
+ const path42 = ref.slice(1).split("/").filter(Boolean);
54003
+ if (path42.length === 0) {
54004
54004
  return ctx.rootSchema;
54005
54005
  }
54006
54006
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
54007
- if (path41[0] === defsKey) {
54008
- const key = path41[1] === void 0 ? void 0 : decodeJSONPointerSegment(path41[1]);
54007
+ if (path42[0] === defsKey) {
54008
+ const key = path42[1] === void 0 ? void 0 : decodeJSONPointerSegment(path42[1]);
54009
54009
  if (!key || !ctx.defs[key]) {
54010
54010
  throw new Error(`Reference not found: ${ref}`);
54011
54011
  }
@@ -60248,6 +60248,7 @@ function buildLayoutPaths(root) {
60248
60248
  frontdoorLockFile: import_node_path19.default.join(root, "frontdoor", "start.lock"),
60249
60249
  frontdoorControlTokenFile: import_node_path19.default.join(root, "frontdoor", "control-token"),
60250
60250
  frontdoorSessionsDir: import_node_path19.default.join(root, "frontdoor", "sessions"),
60251
+ frontdoorRcCredentialsDir: import_node_path19.default.join(root, "frontdoor", "rc-credentials"),
60251
60252
  frontdoorLogPath: import_node_path19.default.join(root, "logs", "frontdoor.log"),
60252
60253
  usageDir: import_node_path19.default.join(root, "usage"),
60253
60254
  usageLogDir: import_node_path19.default.join(root, "usage", "log"),
@@ -61709,7 +61710,7 @@ function registerIdentityCommand(program2, deps) {
61709
61710
  // package.json
61710
61711
  var package_default = {
61711
61712
  name: "agent-shim",
61712
- version: "8.10.0",
61713
+ version: "8.11.0",
61713
61714
  description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
61714
61715
  license: "MIT",
61715
61716
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -62139,11 +62140,11 @@ function providerBaseUrl(port, provider) {
62139
62140
  function directOrigin(port) {
62140
62141
  return `http://127.0.0.1:${String(port)}`;
62141
62142
  }
62142
- function parseProviderPath(path41) {
62143
- if (!path41.startsWith(PROVIDER_PATH_PREFIX)) {
62143
+ function parseProviderPath(path42) {
62144
+ if (!path42.startsWith(PROVIDER_PATH_PREFIX)) {
62144
62145
  return void 0;
62145
62146
  }
62146
- const tail = path41.slice(PROVIDER_PATH_PREFIX.length);
62147
+ const tail = path42.slice(PROVIDER_PATH_PREFIX.length);
62147
62148
  const slash = tail.indexOf("/");
62148
62149
  if (slash <= 0) {
62149
62150
  return void 0;
@@ -62543,9 +62544,9 @@ function decoderFor(encoding) {
62543
62544
  return void 0;
62544
62545
  }
62545
62546
  }
62546
- function destinationOf(path41) {
62547
- const scoped = parseProviderPath(path41);
62548
- return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path41 } : { provider: scoped.provider, endpoint: scoped.rest };
62547
+ function destinationOf(path42) {
62548
+ const scoped = parseProviderPath(path42);
62549
+ return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path42 } : { provider: scoped.provider, endpoint: scoped.rest };
62549
62550
  }
62550
62551
  function buildRecord(event, context) {
62551
62552
  const { scan } = context;
@@ -64445,7 +64446,7 @@ function registerCodexCommand(program2, deps) {
64445
64446
 
64446
64447
  // src/frontdoor/commands.ts
64447
64448
  var import_node_crypto12 = require("node:crypto");
64448
- var import_node_path32 = __toESM(require("node:path"), 1);
64449
+ var import_node_path33 = __toESM(require("node:path"), 1);
64449
64450
  var import_node_fs12 = __toESM(require("node:fs"), 1);
64450
64451
 
64451
64452
  // src/frontdoor/custody.ts
@@ -65175,8 +65176,8 @@ function parseConnectTarget(authority) {
65175
65176
  }
65176
65177
  return { host, port };
65177
65178
  }
65178
- function servedByPipeline(path41) {
65179
- return path41?.startsWith(ROUTED_PATH_PREFIX) === true;
65179
+ function servedByPipeline(path42) {
65180
+ return path42?.startsWith(ROUTED_PATH_PREFIX) === true;
65180
65181
  }
65181
65182
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
65182
65183
  "connection",
@@ -65689,13 +65690,18 @@ function createRcSessionTracker(deps) {
65689
65690
  entries.set(id, record2);
65690
65691
  return record2;
65691
65692
  };
65693
+ const persistCredential = (entry) => {
65694
+ if (entry.oauthAuthorization !== void 0) {
65695
+ deps.credentialStore?.write(entry.id, { authorization: entry.oauthAuthorization, anthropicVersion: entry.anthropicVersion, anthropicClientPlatform: entry.anthropicClientPlatform });
65696
+ }
65697
+ };
65692
65698
  const observeExchange = (request7) => {
65693
65699
  const method = (request7.method ?? "").toUpperCase();
65694
- const path41 = new URL(request7.url ?? "/", "http://127.0.0.1").pathname;
65695
- if (!path41.startsWith(RC_SESSIONS_PATH_PREFIX)) {
65700
+ const path42 = new URL(request7.url ?? "/", "http://127.0.0.1").pathname;
65701
+ if (!path42.startsWith(RC_SESSIONS_PATH_PREFIX)) {
65696
65702
  return void 0;
65697
65703
  }
65698
- const tail = path41.slice(RC_SESSIONS_PATH_PREFIX.length);
65704
+ const tail = path42.slice(RC_SESSIONS_PATH_PREFIX.length);
65699
65705
  const facts = {
65700
65706
  oauthAuthorization: oauthAuthorizationOf(request7.headers),
65701
65707
  anthropicVersion: singleHeader(request7.headers, "anthropic-version"),
@@ -65728,7 +65734,7 @@ function createRcSessionTracker(deps) {
65728
65734
  if (id2 === void 0) {
65729
65735
  return;
65730
65736
  }
65731
- birth(id2, facts);
65737
+ persistCredential(birth(id2, facts));
65732
65738
  }
65733
65739
  };
65734
65740
  }
@@ -65742,6 +65748,7 @@ function createRcSessionTracker(deps) {
65742
65748
  entry.oauthAuthorization = facts.oauthAuthorization ?? entry.oauthAuthorization;
65743
65749
  entry.anthropicVersion = facts.anthropicVersion ?? entry.anthropicVersion;
65744
65750
  entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
65751
+ persistCredential(entry);
65745
65752
  const bodyKind = method === "POST" && rest === `${id}/worker/events` ? "worker-events" : method === "POST" && rest === `${id}/events` ? "client-events" : method === "POST" && rest === `${id}/worker/heartbeat` ? "heartbeat" : method === "PUT" && rest === `${id}/worker` ? "worker-registration" : void 0;
65746
65753
  let chunks = [];
65747
65754
  let buffered = 0;
@@ -65795,6 +65802,7 @@ function createRcSessionTracker(deps) {
65795
65802
  },
65796
65803
  onResponse: (status, headers) => {
65797
65804
  if (singleHeader(headers, CONFLICT_REASON_HEADER) !== void 0 || archiving && isSuccessful(status)) {
65805
+ deps.credentialStore?.remove(id);
65798
65806
  expire(id);
65799
65807
  return;
65800
65808
  }
@@ -65827,7 +65835,18 @@ function createRcSessionTracker(deps) {
65827
65835
  },
65828
65836
  credentialOf: (sessionId) => {
65829
65837
  const entry = entries.get(sessionId);
65830
- return entry === void 0 ? void 0 : { authorization: entry.oauthAuthorization, anthropicVersion: entry.anthropicVersion, anthropicClientPlatform: entry.anthropicClientPlatform };
65838
+ if (entry === void 0) {
65839
+ return void 0;
65840
+ }
65841
+ if (entry.oauthAuthorization === void 0 && deps.credentialStore !== void 0) {
65842
+ const persisted = deps.credentialStore.read(sessionId);
65843
+ if (persisted?.authorization !== void 0) {
65844
+ entry.oauthAuthorization = persisted.authorization;
65845
+ entry.anthropicVersion = entry.anthropicVersion ?? persisted.anthropicVersion;
65846
+ entry.anthropicClientPlatform = entry.anthropicClientPlatform ?? persisted.anthropicClientPlatform;
65847
+ }
65848
+ }
65849
+ return { authorization: entry.oauthAuthorization, anthropicVersion: entry.anthropicVersion, anthropicClientPlatform: entry.anthropicClientPlatform };
65831
65850
  },
65832
65851
  noteSequenceNums: (sessionId, sequenceNums) => {
65833
65852
  const entry = entries.get(sessionId);
@@ -66422,9 +66441,9 @@ function sequenceNumsOfBody(body) {
66422
66441
  }
66423
66442
  function frontDoorRcControl(transport, token) {
66424
66443
  const headers = { authorization: `Bearer ${token}` };
66425
- const listAnswerOf = async (path41, what) => {
66444
+ const listAnswerOf = async (path42, what) => {
66426
66445
  try {
66427
- return await transport.request({ method: "GET", path: path41, headers });
66446
+ return await transport.request({ method: "GET", path: path42, headers });
66428
66447
  } catch (error62) {
66429
66448
  throw new Error(`${what}: could not reach the front door's control listener: ${error62 instanceof Error ? error62.message : String(error62)}`, { cause: error62 });
66430
66449
  }
@@ -66496,10 +66515,10 @@ function frontDoorRcControl(transport, token) {
66496
66515
  }
66497
66516
  return pending;
66498
66517
  };
66499
- const writeOf = async (path41, body, describeFailure) => {
66518
+ const writeOf = async (path42, body, describeFailure) => {
66500
66519
  let answer;
66501
66520
  try {
66502
- answer = await transport.request({ method: "POST", path: path41, headers: { ...headers, "content-type": "application/json" }, body });
66521
+ answer = await transport.request({ method: "POST", path: path42, headers: { ...headers, "content-type": "application/json" }, body });
66503
66522
  } catch (error62) {
66504
66523
  return { ok: false, message: `could not reach the front door's control listener: ${error62 instanceof Error ? error62.message : String(error62)}` };
66505
66524
  }
@@ -66681,15 +66700,27 @@ var SUCCESS_STATUS_MAX_EXCLUSIVE2 = 300;
66681
66700
  function isSuccessful2(status) {
66682
66701
  return status >= HTTP_STATUS.ok && status < SUCCESS_STATUS_MAX_EXCLUSIVE2;
66683
66702
  }
66684
- var UPSTREAM_LOCAL_PORT_START = 47900;
66685
- var UPSTREAM_LOCAL_PORT_END = 47919;
66686
- var UPSTREAM_LOCAL_PORT_COUNT = UPSTREAM_LOCAL_PORT_END - UPSTREAM_LOCAL_PORT_START + 1;
66687
- var nextUpstreamLocalPort = UPSTREAM_LOCAL_PORT_START;
66688
- function upstreamLocalPort() {
66689
- const port = nextUpstreamLocalPort;
66690
- nextUpstreamLocalPort = nextUpstreamLocalPort === UPSTREAM_LOCAL_PORT_END ? UPSTREAM_LOCAL_PORT_START : nextUpstreamLocalPort + 1;
66691
- return port;
66692
- }
66703
+ var SourcePortRange = class {
66704
+ constructor(start, end) {
66705
+ this.start = start;
66706
+ this.end = end;
66707
+ this.count = end - start + 1;
66708
+ this.next = start;
66709
+ }
66710
+ start;
66711
+ end;
66712
+ count;
66713
+ next;
66714
+ /** The next port in rotation, wrapping from the end back to the start. */
66715
+ take() {
66716
+ const port = this.next;
66717
+ this.next = this.next === this.end ? this.start : this.next + 1;
66718
+ return port;
66719
+ }
66720
+ };
66721
+ var DOOR_SOURCE_PORT_START = 47900;
66722
+ var DOOR_SOURCE_PORT_END = 47919;
66723
+ var DOOR_SOURCE_PORTS = new SourcePortRange(DOOR_SOURCE_PORT_START, DOOR_SOURCE_PORT_END);
66693
66724
  var realAddressLookup = (host, _options, callback) => {
66694
66725
  if (net2.isIP(host) !== 0) {
66695
66726
  callback(null, [{ address: host, family: net2.isIP(host) }]);
@@ -66727,14 +66758,14 @@ function dialTarget(options, defaultPort) {
66727
66758
  function literalDial(target) {
66728
66759
  return net2.connect({ host: target.host, port: target.port });
66729
66760
  }
66730
- async function reservedDial(target) {
66761
+ async function reservedDial(target, ports) {
66731
66762
  for (let attempt = 0; ; attempt += 1) {
66732
- const outcome = await dialOnce({ host: target.host, port: target.port, localPort: upstreamLocalPort(), lookup: realAddressLookup });
66763
+ const outcome = await dialOnce({ host: target.host, port: target.port, localPort: ports.take(), lookup: realAddressLookup });
66733
66764
  if (outcome.error === null) {
66734
66765
  return outcome;
66735
66766
  }
66736
66767
  const held = outcome.error.code !== void 0 && HELD_PORT_ERRNOS.has(outcome.error.code);
66737
- if (!held || attempt === UPSTREAM_LOCAL_PORT_COUNT - 1) {
66768
+ if (!held || attempt === ports.count - 1) {
66738
66769
  return outcome;
66739
66770
  }
66740
66771
  }
@@ -66743,26 +66774,36 @@ function requestServername(options, fallback) {
66743
66774
  return "servername" in options && typeof options.servername === "string" && options.servername !== "" ? options.servername : fallback;
66744
66775
  }
66745
66776
  var ExemptHttpAgent = class extends http2.Agent {
66777
+ constructor(ports = DOOR_SOURCE_PORTS) {
66778
+ super();
66779
+ this.ports = ports;
66780
+ }
66781
+ ports;
66746
66782
  // A reserved-port dial that has to retry cannot produce its socket synchronously, so it settles first and arrives through the callback (node's documented asynchronous createConnection form); a literal dial has nothing to retry and keeps node's own synchronous shape.
66747
66783
  createConnection(options, oncreate) {
66748
66784
  const target = dialTarget(options, HTTP_PORT);
66749
66785
  if (net2.isIP(target.host) !== 0) {
66750
66786
  return literalDial(target);
66751
66787
  }
66752
- void reservedDial(target).then((outcome) => {
66788
+ void reservedDial(target, this.ports).then((outcome) => {
66753
66789
  oncreate?.(outcome.error, outcome.socket);
66754
66790
  });
66755
66791
  return void 0;
66756
66792
  }
66757
66793
  };
66758
66794
  var ExemptTlsAgent = class extends https3.Agent {
66795
+ constructor(ports = DOOR_SOURCE_PORTS) {
66796
+ super();
66797
+ this.ports = ports;
66798
+ }
66799
+ ports;
66759
66800
  // The same split as the plain sibling: a literal dial wraps TLS around the socket node's own agent would have returned, a reserved dial settles (retries included) first and arrives through the callback, which is exactly where node's own agent wraps its own dials.
66760
66801
  createConnection(options, oncreate) {
66761
66802
  const target = dialTarget(options, HTTPS_PORT);
66762
66803
  if (net2.isIP(target.host) !== 0) {
66763
66804
  return tls.connect({ socket: literalDial(target), servername: requestServername(options, target.host), ...tlsFacts(options) });
66764
66805
  }
66765
- void reservedDial(target).then((outcome) => {
66806
+ void reservedDial(target, this.ports).then((outcome) => {
66766
66807
  if (outcome.error !== null) {
66767
66808
  oncreate?.(outcome.error, outcome.socket);
66768
66809
  return;
@@ -66823,12 +66864,12 @@ var NO_CHUNKS = {
66823
66864
  };
66824
66865
  function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
66825
66866
  const agent = new ExemptTlsAgent();
66826
- const request7 = async (method, path41, headers, body, signal) => await new Promise((resolve, reject) => {
66867
+ const request7 = async (method, path42, headers, body, signal) => await new Promise((resolve, reject) => {
66827
66868
  const options = {
66828
66869
  host: target.host,
66829
66870
  port: target.port,
66830
66871
  method,
66831
- path: path41,
66872
+ path: path42,
66832
66873
  // The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
66833
66874
  headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
66834
66875
  agent,
@@ -66865,9 +66906,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
66865
66906
  return { status, body: await readAll(response) };
66866
66907
  },
66867
66908
  openStream: async (sessionId, headers, resume, signal) => {
66868
- const path41 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
66909
+ const path42 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
66869
66910
  const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
66870
- const { status, response } = await request7("GET", path41, streamHeaders, void 0, signal);
66911
+ const { status, response } = await request7("GET", path42, streamHeaders, void 0, signal);
66871
66912
  if (!isSuccessful2(status)) {
66872
66913
  await readAll(response);
66873
66914
  return { status, chunks: NO_CHUNKS };
@@ -66876,9 +66917,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
66876
66917
  }
66877
66918
  };
66878
66919
  }
66879
- function realConnectEffects() {
66880
- const plainAgent = new ExemptHttpAgent();
66881
- const tlsAgent = new ExemptTlsAgent();
66920
+ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
66921
+ const plainAgent = new ExemptHttpAgent(ports);
66922
+ const tlsAgent = new ExemptTlsAgent(ports);
66882
66923
  const listenOnce = async (port, onSocket) => await new Promise((resolve, reject) => {
66883
66924
  const accepted = /* @__PURE__ */ new Set();
66884
66925
  const server = net2.createServer((socket) => {
@@ -66996,7 +67037,7 @@ function realConnectEffects() {
66996
67037
  };
66997
67038
  },
66998
67039
  connectTlsUpstream: async (host, port, clientAlpn) => {
66999
- const dialled = await reservedDial({ host, port });
67040
+ const dialled = await reservedDial({ host, port }, ports);
67000
67041
  if (dialled.error !== null) {
67001
67042
  throw dialled.error;
67002
67043
  }
@@ -67990,9 +68031,9 @@ function resolveFriendlyClientOptions(options) {
67990
68031
  };
67991
68032
  }
67992
68033
  function createORPCClient(link, options = {}) {
67993
- const path41 = options.path ?? [];
68034
+ const path42 = options.path ?? [];
67994
68035
  const procedureClient = async (...[input2, options2 = {}]) => {
67995
- return await link.call(path41, input2, resolveFriendlyClientOptions(options2));
68036
+ return await link.call(path42, input2, resolveFriendlyClientOptions(options2));
67996
68037
  };
67997
68038
  const recursive2 = new Proxy(procedureClient, {
67998
68039
  get(target, key) {
@@ -68001,7 +68042,7 @@ function createORPCClient(link, options = {}) {
68001
68042
  }
68002
68043
  return createORPCClient(link, {
68003
68044
  ...options,
68004
- path: [...path41, key]
68045
+ path: [...path42, key]
68005
68046
  });
68006
68047
  }
68007
68048
  });
@@ -68303,19 +68344,19 @@ var StandardLink = class {
68303
68344
  }
68304
68345
  interceptors;
68305
68346
  clientInterceptors;
68306
- call(path41, input2, options) {
68347
+ call(path42, input2, options) {
68307
68348
  return runWithSpan(
68308
- { name: `${ORPC_NAME}.${path41.join("/")}`, signal: options.signal },
68349
+ { name: `${ORPC_NAME}.${path42.join("/")}`, signal: options.signal },
68309
68350
  (span) => {
68310
68351
  span?.setAttribute("rpc.system", ORPC_NAME);
68311
- span?.setAttribute("rpc.method", path41.join("."));
68352
+ span?.setAttribute("rpc.method", path42.join("."));
68312
68353
  if (isAsyncIteratorObject(input2)) {
68313
68354
  input2 = asyncIteratorWithSpan(
68314
68355
  { name: "consume_event_iterator_input", signal: options.signal },
68315
68356
  input2
68316
68357
  );
68317
68358
  }
68318
- return intercept(this.interceptors, { ...options, path: path41, input: input2 }, async ({ path: path210, input: input22, ...options2 }) => {
68359
+ return intercept(this.interceptors, { ...options, path: path42, input: input2 }, async ({ path: path210, input: input22, ...options2 }) => {
68319
68360
  const otelConfig = getGlobalOtelConfig();
68320
68361
  let otelContext;
68321
68362
  const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
@@ -68550,8 +68591,8 @@ var StandardRPCJsonSerializer = class {
68550
68591
  return ref.data;
68551
68592
  }
68552
68593
  };
68553
- function toHttpPath(path41) {
68554
- return `/${path41.map(encodeURIComponent).join("/")}`;
68594
+ function toHttpPath(path42) {
68595
+ return `/${path42.map(encodeURIComponent).join("/")}`;
68555
68596
  }
68556
68597
  function toStandardHeaders2(headers) {
68557
68598
  if (typeof headers.forEach === "function") {
@@ -68576,18 +68617,18 @@ var StandardRPCLinkCodec = class {
68576
68617
  fallbackMethod;
68577
68618
  expectedMethod;
68578
68619
  headers;
68579
- async encode(path41, input2, options) {
68580
- let headers = toStandardHeaders2(await value(this.headers, options, path41, input2));
68620
+ async encode(path42, input2, options) {
68621
+ let headers = toStandardHeaders2(await value(this.headers, options, path42, input2));
68581
68622
  if (options.lastEventId !== void 0) {
68582
68623
  headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
68583
68624
  }
68584
- const expectedMethod = await value(this.expectedMethod, options, path41, input2);
68585
- const baseUrl = await value(this.baseUrl, options, path41, input2);
68625
+ const expectedMethod = await value(this.expectedMethod, options, path42, input2);
68626
+ const baseUrl = await value(this.baseUrl, options, path42, input2);
68586
68627
  const url2 = new URL(baseUrl);
68587
- url2.pathname = `${url2.pathname.replace(/\/$/, "")}${toHttpPath(path41)}`;
68628
+ url2.pathname = `${url2.pathname.replace(/\/$/, "")}${toHttpPath(path42)}`;
68588
68629
  const serialized = this.serializer.serialize(input2);
68589
68630
  if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
68590
- const maxUrlLength = await value(this.maxUrlLength, options, path41, input2);
68631
+ const maxUrlLength = await value(this.maxUrlLength, options, path42, input2);
68591
68632
  const getUrl = new URL(url2);
68592
68633
  getUrl.searchParams.append("data", stringifyJSON(serialized));
68593
68634
  if (getUrl.toString().length <= maxUrlLength) {
@@ -68738,11 +68779,11 @@ var LinkFetchClient = class {
68738
68779
  this.toFetchRequestOptions = options;
68739
68780
  this.adapterInterceptors = toArray(options.adapterInterceptors);
68740
68781
  }
68741
- async call(standardRequest, options, path41, input2) {
68782
+ async call(standardRequest, options, path42, input2) {
68742
68783
  const request7 = toFetchRequest(standardRequest, this.toFetchRequestOptions);
68743
68784
  const fetchResponse = await intercept(
68744
68785
  this.adapterInterceptors,
68745
- { ...options, request: request7, path: path41, input: input2, init: { redirect: "manual" } },
68786
+ { ...options, request: request7, path: path42, input: input2, init: { redirect: "manual" } },
68746
68787
  ({ request: request22, path: path210, input: input22, init, ...options2 }) => this.fetch(request22, init, options2, path210, input22)
68747
68788
  );
68748
68789
  const lazyResponse = toStandardLazyResponse(fetchResponse, { signal: request7.signal });
@@ -69142,7 +69183,7 @@ function middlewareOutputFn(output2) {
69142
69183
  function createProcedureClient(lazyableProcedure, ...rest) {
69143
69184
  const options = resolveMaybeOptionalOptions(rest);
69144
69185
  return async (...[input2, callerOptions]) => {
69145
- const path41 = toArray(options.path);
69186
+ const path42 = toArray(options.path);
69146
69187
  const { default: procedure } = await unlazy(lazyableProcedure);
69147
69188
  const clientContext = callerOptions?.context ?? {};
69148
69189
  const context = await value(options.context ?? {}, clientContext);
@@ -69157,7 +69198,7 @@ function createProcedureClient(lazyableProcedure, ...rest) {
69157
69198
  const output2 = await runWithSpan(
69158
69199
  { name: "call_procedure", signal: callerOptions?.signal },
69159
69200
  (span) => {
69160
- span?.setAttribute("procedure.path", [...path41]);
69201
+ span?.setAttribute("procedure.path", [...path42]);
69161
69202
  return intercept(
69162
69203
  toArray(options.interceptors),
69163
69204
  {
@@ -69165,7 +69206,7 @@ function createProcedureClient(lazyableProcedure, ...rest) {
69165
69206
  input: input2,
69166
69207
  // input only optional when it undefinable so we can safely cast it
69167
69208
  errors,
69168
- path: path41,
69209
+ path: path42,
69169
69210
  procedure,
69170
69211
  signal: callerOptions?.signal,
69171
69212
  lastEventId: callerOptions?.lastEventId
@@ -69287,10 +69328,10 @@ var HIDDEN_ROUTER_CONTRACT_SYMBOL = /* @__PURE__ */ Symbol("ORPC_HIDDEN_ROUTER_C
69287
69328
  function getHiddenRouterContract(router) {
69288
69329
  return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
69289
69330
  }
69290
- function getRouter(router, path41) {
69331
+ function getRouter(router, path42) {
69291
69332
  let current = router;
69292
- for (let i2 = 0; i2 < path41.length; i2++) {
69293
- const segment = path41[i2];
69333
+ for (let i2 = 0; i2 < path42.length; i2++) {
69334
+ const segment = path42[i2];
69294
69335
  if (!current) {
69295
69336
  return void 0;
69296
69337
  }
@@ -69305,7 +69346,7 @@ function getRouter(router, path41) {
69305
69346
  continue;
69306
69347
  }
69307
69348
  const lazied = current;
69308
- const rest = path41.slice(i2);
69349
+ const rest = path42.slice(i2);
69309
69350
  return lazy2(async () => {
69310
69351
  const unwrapped = await unlazy(lazied);
69311
69352
  const next = getRouter(unwrapped.default, rest);
@@ -69883,8 +69924,8 @@ function toAbortSignal(stream) {
69883
69924
  function toStandardUrl(req) {
69884
69925
  const protocol = "encrypted" in req.socket && req.socket.encrypted ? "https:" : "http:";
69885
69926
  const origin = guard(() => new URL(`${protocol}//${req.headers.host ?? "localhost"}`).origin) ?? `${protocol}//localhost`;
69886
- const path41 = req.originalUrl ?? req.url ?? "/";
69887
- return new URL(`${origin}${path41.startsWith("/") ? "" : "/"}${path41}`);
69927
+ const path42 = req.originalUrl ?? req.url ?? "/";
69928
+ return new URL(`${origin}${path42.startsWith("/") ? "" : "/"}${path42}`);
69888
69929
  }
69889
69930
  function toStandardLazyRequest(req, res) {
69890
69931
  const signal = toAbortSignal(res);
@@ -70083,8 +70124,8 @@ var StandardRPCMatcher = class {
70083
70124
  constructor(options = {}) {
70084
70125
  this.filter = options.filter ?? true;
70085
70126
  }
70086
- init(router, path41 = []) {
70087
- const laziedOptions = traverseContractProcedures({ router, path: path41 }, (traverseOptions) => {
70127
+ init(router, path42 = []) {
70128
+ const laziedOptions = traverseContractProcedures({ router, path: path42 }, (traverseOptions) => {
70088
70129
  if (!value(this.filter, traverseOptions)) {
70089
70130
  return;
70090
70131
  }
@@ -71546,8 +71587,8 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
71546
71587
  request7.body.resume();
71547
71588
  return;
71548
71589
  }
71549
- const path41 = new URL(request7.url, "http://127.0.0.1").pathname;
71550
- const translated = { method: request7.method, path: path41, body, signal: request7.signal };
71590
+ const path42 = new URL(request7.url, "http://127.0.0.1").pathname;
71591
+ const translated = { method: request7.method, path: path42, body, signal: request7.signal };
71551
71592
  const routed = await route(translated);
71552
71593
  if (request7.signal.aborted) {
71553
71594
  return;
@@ -71581,7 +71622,7 @@ function createPassthroughRoute(name, target) {
71581
71622
  headroomUpstream: target.headroomUpstream,
71582
71623
  serve: async (request7, response) => {
71583
71624
  const incoming = new URL(request7.url, "http://127.0.0.1");
71584
- const path41 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
71625
+ const path42 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
71585
71626
  const headers = forwardableHeaders(request7.headers);
71586
71627
  delete headers.host;
71587
71628
  await new Promise((resolve) => {
@@ -71589,7 +71630,7 @@ function createPassthroughRoute(name, target) {
71589
71630
  host: base.hostname,
71590
71631
  port: base.port === "" ? void 0 : Number(base.port),
71591
71632
  method: request7.method,
71592
- path: `${basePath}${path41}${incoming.search}`,
71633
+ path: `${basePath}${path42}${incoming.search}`,
71593
71634
  headers,
71594
71635
  agent
71595
71636
  };
@@ -71651,10 +71692,10 @@ function createProviderRouteResolver(deps) {
71651
71692
  return route;
71652
71693
  };
71653
71694
  const resolve = (request7) => {
71654
- const path41 = new URL(request7.url, "http://127.0.0.1").pathname;
71655
- const scoped = parseProviderPath(path41);
71695
+ const path42 = new URL(request7.url, "http://127.0.0.1").pathname;
71696
+ const scoped = parseProviderPath(path42);
71656
71697
  if (scoped === void 0) {
71657
- return path41.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path41}` };
71698
+ return path42.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path42}` };
71658
71699
  }
71659
71700
  const { provider } = scoped;
71660
71701
  let definition;
@@ -71693,6 +71734,64 @@ function createProviderRouteResolver(deps) {
71693
71734
  return async (request7) => await Promise.resolve(resolve(request7));
71694
71735
  }
71695
71736
 
71737
+ // src/frontdoor/rcCredentialStore.ts
71738
+ var import_node_path32 = __toESM(require("node:path"), 1);
71739
+ function isSafeSessionId(sessionId) {
71740
+ return /^[A-Za-z0-9_-]+$/.test(sessionId);
71741
+ }
71742
+ function isRecord4(value2) {
71743
+ return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
71744
+ }
71745
+ function credentialOfJson(parsed) {
71746
+ if (!isRecord4(parsed)) {
71747
+ return void 0;
71748
+ }
71749
+ const { authorization, anthropicVersion, anthropicClientPlatform } = parsed;
71750
+ if (typeof authorization !== "string" || authorization === "") {
71751
+ return void 0;
71752
+ }
71753
+ return {
71754
+ authorization,
71755
+ anthropicVersion: typeof anthropicVersion === "string" ? anthropicVersion : void 0,
71756
+ anthropicClientPlatform: typeof anthropicClientPlatform === "string" ? anthropicClientPlatform : void 0
71757
+ };
71758
+ }
71759
+ function createRcCredentialStore(fs19, dir) {
71760
+ fs19.mkdirPrivate(dir);
71761
+ const fileFor = (sessionId) => import_node_path32.default.join(dir, `${sessionId}.json`);
71762
+ return {
71763
+ read: (sessionId) => {
71764
+ if (!isSafeSessionId(sessionId)) {
71765
+ return void 0;
71766
+ }
71767
+ const raw = fs19.readFileUtf8(fileFor(sessionId));
71768
+ if (raw === void 0) {
71769
+ return void 0;
71770
+ }
71771
+ let parsed;
71772
+ try {
71773
+ parsed = JSON.parse(raw);
71774
+ } catch {
71775
+ return void 0;
71776
+ }
71777
+ return credentialOfJson(parsed);
71778
+ },
71779
+ write: (sessionId, credential) => {
71780
+ if (!isSafeSessionId(sessionId)) {
71781
+ return;
71782
+ }
71783
+ fs19.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(credential, null, 2)}
71784
+ `);
71785
+ },
71786
+ remove: (sessionId) => {
71787
+ if (!isSafeSessionId(sessionId)) {
71788
+ return;
71789
+ }
71790
+ fs19.removeRecursive(fileFor(sessionId));
71791
+ }
71792
+ };
71793
+ }
71794
+
71696
71795
  // src/frontdoor/rcStream.ts
71697
71796
  var RC_STREAM_EVENT_NAME = "client_event";
71698
71797
  var SSE_BYTE_ORDER_MARK = 65279;
@@ -71755,7 +71854,7 @@ function createSseParser() {
71755
71854
  }
71756
71855
  };
71757
71856
  }
71758
- function isRecord4(value2) {
71857
+ function isRecord5(value2) {
71759
71858
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
71760
71859
  }
71761
71860
  function sequenceNumOf(value2) {
@@ -71777,7 +71876,7 @@ function parseRcStreamEnvelope(parsed) {
71777
71876
  } catch {
71778
71877
  return void 0;
71779
71878
  }
71780
- if (!isRecord4(data)) {
71879
+ if (!isRecord5(data)) {
71781
71880
  return void 0;
71782
71881
  }
71783
71882
  const eventType = data.event_type;
@@ -71866,6 +71965,7 @@ function createRcStreamHub(deps) {
71866
71965
  if (!isSuccessful3(answer.status)) {
71867
71966
  throw new Error(`the client read stream answered HTTP ${String(answer.status)}`);
71868
71967
  }
71968
+ deps.log?.(`rc stream ${attachment.sessionId}: attached as client ${attachment.clientId}${resume === void 0 ? ", reading from the stream's own head" : `, resuming after sequence number ${String(resume.fromSequenceNum)}`}`);
71869
71969
  const parser = createSseParser();
71870
71970
  for await (const chunk of answer.chunks) {
71871
71971
  attachment.controller.signal.throwIfAborted();
@@ -71889,6 +71989,7 @@ function createRcStreamHub(deps) {
71889
71989
  const live = deps.trackedSessions().includes(attachment.sessionId);
71890
71990
  const credential = deps.credentialOf(attachment.sessionId);
71891
71991
  if (!live || credential?.authorization === void 0) {
71992
+ deps.log?.(`rc stream ${attachment.sessionId}: the attachment ended (${live ? "the session's client credential is no longer known" : "the tracker gave up on the session"})`);
71892
71993
  if (attachments.get(attachment.sessionId) === attachment) {
71893
71994
  attachments.delete(attachment.sessionId);
71894
71995
  }
@@ -71910,6 +72011,7 @@ function createRcStreamHub(deps) {
71910
72011
  return;
71911
72012
  }
71912
72013
  if (outcome === "dropped") {
72014
+ deps.log?.(`rc stream ${attachment.sessionId}: the stream ended of its own accord, reconnecting`);
71913
72015
  retriedUnauthorized = false;
71914
72016
  continue;
71915
72017
  }
@@ -72259,7 +72361,7 @@ function realFrontDoorSupervisorPorts(paths) {
72259
72361
  };
72260
72362
  let directPort = 0;
72261
72363
  const codexPorts = createCodexRoutePorts(log);
72262
- const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS });
72364
+ const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS, credentialStore: createRcCredentialStore(realFarmFs, paths.frontdoorRcCredentialsDir) });
72263
72365
  const rcFanout = createRcEventFanout();
72264
72366
  const rcHub = createRcStreamHub({
72265
72367
  now: () => Date.now(),
@@ -72370,7 +72472,7 @@ function realFrontDoorSupervisorPorts(paths) {
72370
72472
  const leafFor = createLeafCache(loadCa(), () => /* @__PURE__ */ new Date());
72371
72473
  const capture = captureFromEnv(process.env, paths.logsDir);
72372
72474
  if (capture !== void 0) {
72373
- log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path32.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
72475
+ log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path33.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
72374
72476
  }
72375
72477
  const server = await startConnectServer(
72376
72478
  {
@@ -73022,15 +73124,15 @@ var import_node_child_process4 = require("node:child_process");
73022
73124
 
73023
73125
  // src/identityToken.ts
73024
73126
  var import_node_fs13 = __toESM(require("node:fs"), 1);
73025
- var import_node_path33 = __toESM(require("node:path"), 1);
73127
+ var import_node_path34 = __toESM(require("node:path"), 1);
73026
73128
  var TOKEN_FILE_MODE = 384;
73027
73129
  var TOKEN_DIR_MODE = 448;
73028
73130
  var OAUTH_TOKEN_RE = /^sk-ant-oat\d+-[A-Za-z0-9_-]+$/;
73029
73131
  function identityTokenDir(paths) {
73030
- return import_node_path33.default.join(paths.root, "credentials");
73132
+ return import_node_path34.default.join(paths.root, "credentials");
73031
73133
  }
73032
73134
  function identityTokenPath(paths, identityName) {
73033
- return import_node_path33.default.join(identityTokenDir(paths), `${identityName}.token`);
73135
+ return import_node_path34.default.join(identityTokenDir(paths), `${identityName}.token`);
73034
73136
  }
73035
73137
  function storeIdentityToken(paths, identityName, raw) {
73036
73138
  const token = raw.trim();
@@ -73041,7 +73143,7 @@ function storeIdentityToken(paths, identityName, raw) {
73041
73143
  import_node_fs13.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
73042
73144
  import_node_fs13.default.chmodSync(dir, TOKEN_DIR_MODE);
73043
73145
  const target = identityTokenPath(paths, identityName);
73044
- const temp = import_node_path33.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
73146
+ const temp = import_node_path34.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
73045
73147
  import_node_fs13.default.writeFileSync(temp, `${token}
73046
73148
  `, { mode: TOKEN_FILE_MODE });
73047
73149
  import_node_fs13.default.renameSync(temp, target);
@@ -73180,7 +73282,7 @@ function subjectName(positional, provider) {
73180
73282
 
73181
73283
  // src/doctorReport.ts
73182
73284
  var import_node_fs14 = __toESM(require("node:fs"), 1);
73183
- var import_node_path34 = __toESM(require("node:path"), 1);
73285
+ var import_node_path35 = __toESM(require("node:path"), 1);
73184
73286
  function refinePathShadow(status, ownExecutablePath, realpath) {
73185
73287
  if (status.status !== "shadowed") {
73186
73288
  return status;
@@ -73204,7 +73306,7 @@ function validateJson(schema, input2) {
73204
73306
  return { ok: true, data: result.data };
73205
73307
  }
73206
73308
  function pushPathResolution(push, resolution) {
73207
- const ownDir = import_node_path34.default.dirname(resolution.ownExecutablePath);
73309
+ const ownDir = import_node_path35.default.dirname(resolution.ownExecutablePath);
73208
73310
  switch (resolution.agentShim.status) {
73209
73311
  case "ok":
73210
73312
  push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
@@ -73280,14 +73382,14 @@ function pushProvider(push, entry, cacheEnv) {
73280
73382
  }
73281
73383
  function pushLegacyName(push, params) {
73282
73384
  const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
73283
- if (legacyVariables.length === 0 && import_node_path34.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
73385
+ if (legacyVariables.length === 0 && import_node_path35.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
73284
73386
  push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
73285
73387
  return;
73286
73388
  }
73287
73389
  for (const name of legacyVariables) {
73288
73390
  push("legacy-name", "warn", `${name} is the former name of ${name.replace(LEGACY_ENV_PREFIX, ENV_PREFIX)}. Rename it; the old name still works but is only a fallback.`, name);
73289
73391
  }
73290
- if (import_node_path34.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
73392
+ if (import_node_path35.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
73291
73393
  push(
73292
73394
  "legacy-name",
73293
73395
  "warn",
@@ -73606,18 +73708,18 @@ function collectDoctorReport(params) {
73606
73708
  const { paths } = params;
73607
73709
  const identityNames = import_node_fs14.default.existsSync(paths.identitiesDir) ? import_node_fs14.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
73608
73710
  const identities = identityNames.map((name) => {
73609
- const farmRoot = import_node_path34.default.join(paths.identitiesDir, name);
73610
- const identityPath = import_node_path34.default.join(farmRoot, "identity.json");
73711
+ const farmRoot = import_node_path35.default.join(paths.identitiesDir, name);
73712
+ const identityPath = import_node_path35.default.join(farmRoot, "identity.json");
73611
73713
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
73612
73714
  });
73613
73715
  const profileNames = import_node_fs14.default.existsSync(paths.configProfilesDir) ? import_node_fs14.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
73614
73716
  const configProfiles = profileNames.map((name) => {
73615
- const profilePath = import_node_path34.default.join(paths.configProfilesDir, `${name}.json`);
73717
+ const profilePath = import_node_path35.default.join(paths.configProfilesDir, `${name}.json`);
73616
73718
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
73617
73719
  });
73618
73720
  const providerNames = import_node_fs14.default.existsSync(paths.providersDir) ? import_node_fs14.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
73619
73721
  const providers = providerNames.map((name) => {
73620
- const providerPath = import_node_path34.default.join(paths.providersDir, `${name}.json`);
73722
+ const providerPath = import_node_path35.default.join(paths.providersDir, `${name}.json`);
73621
73723
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
73622
73724
  });
73623
73725
  const ownExecutablePath = realOwnExecutablePath();
@@ -73629,12 +73731,12 @@ function collectDoctorReport(params) {
73629
73731
  binaryDiscovery = { ok: false, message: error62 instanceof Error ? error62.message : String(error62) };
73630
73732
  }
73631
73733
  const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
73632
- const pathDirs = (params.env.PATH ?? "").split(import_node_path34.default.delimiter).filter((dir) => dir !== "");
73734
+ const pathDirs = (params.env.PATH ?? "").split(import_node_path35.default.delimiter).filter((dir) => dir !== "");
73633
73735
  const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
73634
73736
  findPathShadow({
73635
73737
  pathDirs,
73636
- targetDir: import_node_path34.default.dirname(shimState.targetPath),
73637
- targetFilename: import_node_path34.default.basename(shimState.targetPath),
73738
+ targetDir: import_node_path35.default.dirname(shimState.targetPath),
73739
+ targetFilename: import_node_path35.default.basename(shimState.targetPath),
73638
73740
  findExecutableInDir
73639
73741
  }),
73640
73742
  shimState.targetPath,
@@ -73659,7 +73761,7 @@ function collectDoctorReport(params) {
73659
73761
  agentShim: refinePathShadow(
73660
73762
  findPathShadow({
73661
73763
  pathDirs,
73662
- targetDir: import_node_path34.default.dirname(ownExecutablePath),
73764
+ targetDir: import_node_path35.default.dirname(ownExecutablePath),
73663
73765
  targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
73664
73766
  findExecutableInDir
73665
73767
  }),
@@ -73702,7 +73804,7 @@ function registerDoctorCommand(program2, deps) {
73702
73804
  // src/headroom/commands.ts
73703
73805
  var import_node_fs16 = __toESM(require("node:fs"), 1);
73704
73806
  var import_node_http2 = __toESM(require("node:http"), 1);
73705
- var import_node_path36 = __toESM(require("node:path"), 1);
73807
+ var import_node_path37 = __toESM(require("node:path"), 1);
73706
73808
  var import_node_child_process5 = require("node:child_process");
73707
73809
 
73708
73810
  // src/frontdoor/realFrontDoorPort.ts
@@ -73848,11 +73950,11 @@ function probeFrontDoorSync(port, caPem) {
73848
73950
 
73849
73951
  // src/frontdoor/trust.ts
73850
73952
  var import_node_crypto14 = require("node:crypto");
73851
- var import_node_path35 = __toESM(require("node:path"), 1);
73953
+ var import_node_path36 = __toESM(require("node:path"), 1);
73852
73954
  var BUNDLE_NAME_HEX_DIGITS = 16;
73853
73955
  function resolveTrustBundle(params) {
73854
73956
  const { caCertFile, bundlesDir, variable, inherited, fs: fs19 } = params;
73855
- if (inherited === void 0 || inherited === "" || import_node_path35.default.resolve(inherited) === import_node_path35.default.resolve(caCertFile)) {
73957
+ if (inherited === void 0 || inherited === "" || import_node_path36.default.resolve(inherited) === import_node_path36.default.resolve(caCertFile)) {
73856
73958
  return { path: caCertFile };
73857
73959
  }
73858
73960
  const caPem = fs19.readFileUtf8(caCertFile);
@@ -73870,7 +73972,7 @@ function resolveTrustBundle(params) {
73870
73972
  }
73871
73973
  const combined = `${inheritedPem.trimEnd()}
73872
73974
  ${caPem}`;
73873
- const bundle = import_node_path35.default.join(bundlesDir, `${(0, import_node_crypto14.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
73975
+ const bundle = import_node_path36.default.join(bundlesDir, `${(0, import_node_crypto14.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
73874
73976
  if (!fs19.exists(bundle)) {
73875
73977
  fs19.mkdirp(bundlesDir);
73876
73978
  fs19.writeFileAtomic(bundle, combined);
@@ -74028,12 +74130,12 @@ function readInstalledHeadroomCommit() {
74028
74130
  if (toolDir.status !== 0) {
74029
74131
  return void 0;
74030
74132
  }
74031
- const libDir = import_node_path36.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
74133
+ const libDir = import_node_path37.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
74032
74134
  for (const python of realFarmFs.readdir(libDir)) {
74033
- const sitePackages = import_node_path36.default.join(libDir, python, "site-packages");
74135
+ const sitePackages = import_node_path37.default.join(libDir, python, "site-packages");
74034
74136
  for (const entry of realFarmFs.readdir(sitePackages)) {
74035
74137
  if (entry.startsWith("headroom_ai-") && entry.endsWith(".dist-info")) {
74036
- const directUrl = realFarmFs.readFileUtf8(import_node_path36.default.join(sitePackages, entry, "direct_url.json"));
74138
+ const directUrl = realFarmFs.readFileUtf8(import_node_path37.default.join(sitePackages, entry, "direct_url.json"));
74037
74139
  return directUrl === void 0 ? void 0 : parseInstalledCommit(directUrl);
74038
74140
  }
74039
74141
  }
@@ -74840,7 +74942,7 @@ var import_node_crypto16 = require("node:crypto");
74840
74942
 
74841
74943
  // src/launcher.ts
74842
74944
  var import_node_crypto15 = require("node:crypto");
74843
- var import_node_path38 = __toESM(require("node:path"), 1);
74945
+ var import_node_path39 = __toESM(require("node:path"), 1);
74844
74946
 
74845
74947
  // src/launcher/cliOverride.ts
74846
74948
  var InvalidCliCategoryError = class extends CliError {
@@ -74924,7 +75026,7 @@ function buildCliOverride(params) {
74924
75026
  }
74925
75027
 
74926
75028
  // src/launcher/flags.ts
74927
- var import_node_path37 = __toESM(require("node:path"), 1);
75029
+ var import_node_path38 = __toESM(require("node:path"), 1);
74928
75030
 
74929
75031
  // src/headroom/headers.ts
74930
75032
  function mergeAnthropicCustomHeaders(existing, additions) {
@@ -74994,7 +75096,7 @@ function buildEnv(params) {
74994
75096
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
74995
75097
  let providerCustomHeaders;
74996
75098
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
74997
- env.CLAUDE_CONFIG_DIR = import_node_path37.default.join(params.identitiesDir, params.resolvedIdentityName);
75099
+ env.CLAUDE_CONFIG_DIR = import_node_path38.default.join(params.identitiesDir, params.resolvedIdentityName);
74998
75100
  }
74999
75101
  if (params.provider !== void 0) {
75000
75102
  const providerEnv = params.provider.definition.env ?? {};
@@ -75178,7 +75280,7 @@ function prepareLaunch(params) {
75178
75280
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
75179
75281
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
75180
75282
  });
75181
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs19.readConfigFile(import_node_path38.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
75283
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs19.readConfigFile(import_node_path39.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
75182
75284
  log.error(
75183
75285
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
75184
75286
  );
@@ -75524,7 +75626,7 @@ async function runClaude(argvOverride) {
75524
75626
  // src/cli.ts
75525
75627
  async function main() {
75526
75628
  aliasLegacyEnv(process.env);
75527
- const invokedName = import_node_path39.default.basename(process.argv[1] ?? "agent-shim");
75629
+ const invokedName = import_node_path40.default.basename(process.argv[1] ?? "agent-shim");
75528
75630
  if (isInvokedAsClaude(invokedName)) {
75529
75631
  await runClaude();
75530
75632
  return;