agent-shim 7.1.2 → 7.2.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 path36 = require("path");
3251
+ var path38 = require("path");
3252
3252
  var os9 = require("os");
3253
3253
  var homedir = os9.homedir();
3254
3254
  var tmpdir = os9.tmpdir();
3255
3255
  var { env } = process;
3256
3256
  var macos = (name) => {
3257
- const library = path36.join(homedir, "Library");
3257
+ const library = path38.join(homedir, "Library");
3258
3258
  return {
3259
- data: path36.join(library, "Application Support", name),
3260
- config: path36.join(library, "Preferences", name),
3261
- cache: path36.join(library, "Caches", name),
3262
- log: path36.join(library, "Logs", name),
3263
- temp: path36.join(tmpdir, name)
3259
+ data: path38.join(library, "Application Support", name),
3260
+ config: path38.join(library, "Preferences", name),
3261
+ cache: path38.join(library, "Caches", name),
3262
+ log: path38.join(library, "Logs", name),
3263
+ temp: path38.join(tmpdir, name)
3264
3264
  };
3265
3265
  };
3266
3266
  var windows = (name) => {
3267
- const appData = env.APPDATA || path36.join(homedir, "AppData", "Roaming");
3268
- const localAppData = env.LOCALAPPDATA || path36.join(homedir, "AppData", "Local");
3267
+ const appData = env.APPDATA || path38.join(homedir, "AppData", "Roaming");
3268
+ const localAppData = env.LOCALAPPDATA || path38.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: path36.join(localAppData, name, "Data"),
3272
- config: path36.join(appData, name, "Config"),
3273
- cache: path36.join(localAppData, name, "Cache"),
3274
- log: path36.join(localAppData, name, "Log"),
3275
- temp: path36.join(tmpdir, name)
3271
+ data: path38.join(localAppData, name, "Data"),
3272
+ config: path38.join(appData, name, "Config"),
3273
+ cache: path38.join(localAppData, name, "Cache"),
3274
+ log: path38.join(localAppData, name, "Log"),
3275
+ temp: path38.join(tmpdir, name)
3276
3276
  };
3277
3277
  };
3278
3278
  var linux = (name) => {
3279
- const username = path36.basename(homedir);
3279
+ const username = path38.basename(homedir);
3280
3280
  return {
3281
- data: path36.join(env.XDG_DATA_HOME || path36.join(homedir, ".local", "share"), name),
3282
- config: path36.join(env.XDG_CONFIG_HOME || path36.join(homedir, ".config"), name),
3283
- cache: path36.join(env.XDG_CACHE_HOME || path36.join(homedir, ".cache"), name),
3281
+ data: path38.join(env.XDG_DATA_HOME || path38.join(homedir, ".local", "share"), name),
3282
+ config: path38.join(env.XDG_CONFIG_HOME || path38.join(homedir, ".config"), name),
3283
+ cache: path38.join(env.XDG_CACHE_HOME || path38.join(homedir, ".cache"), name),
3284
3284
  // https://wiki.debian.org/XDGBaseDirectorySpecification#state
3285
- log: path36.join(env.XDG_STATE_HOME || path36.join(homedir, ".local", "state"), name),
3286
- temp: path36.join(tmpdir, username, name)
3285
+ log: path38.join(env.XDG_STATE_HOME || path38.join(homedir, ".local", "state"), name),
3286
+ temp: path38.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, path36) {
3355
- if (typeof path36 === "string" && Object.prototype.hasOwnProperty.call(source, path36)) {
3356
- return source[path36];
3354
+ function getPropertyByPath(source, path38) {
3355
+ if (typeof path38 === "string" && Object.prototype.hasOwnProperty.call(source, path38)) {
3356
+ return source[path38];
3357
3357
  }
3358
- const parsedPath = typeof path36 === "string" ? path36.split(".") : path36;
3358
+ const parsedPath = typeof path38 === "string" ? path38.split(".") : path38;
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(([, value]) => value !== void 0));
3379
3379
  }
3380
3380
  exports2.removeUndefinedValuesFromObject = removeUndefinedValuesFromObject;
3381
- async function isDirectory(path36) {
3381
+ async function isDirectory(path38) {
3382
3382
  try {
3383
- const stat = await fs_1.promises.stat(path36);
3383
+ const stat = await fs_1.promises.stat(path38);
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(path36) {
3393
+ function isDirectorySync(path38) {
3394
3394
  try {
3395
- const stat = fs_1.default.statSync(path36);
3395
+ const stat = fs_1.default.statSync(path38);
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((path36, i2) => `${i2 + 1}. ${path36}`).join("\n")} (same as ${idx + 1}.)`);
3493
+ ${[...importStack, fullPath].map((path38, i2) => `${i2 + 1}. ${path38}`).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(path36) {
3681
+ async #fileExists(path38) {
3682
3682
  try {
3683
- await promises_1.default.stat(path36);
3683
+ await promises_1.default.stat(path38);
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(path36) {
3843
+ #fileExists(path38) {
3844
3844
  try {
3845
- fs_1.default.statSync(path36);
3845
+ fs_1.default.statSync(path38);
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((path36) => path36.replace("{name}", moduleName));
3969
+ const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path38) => path38.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 = (path36, { windows } = {}) => {
4378
- const segs = path36.split(windows ? /[\\/]/ : "/");
4377
+ exports2.basename = (path38, { windows } = {}) => {
4378
+ const segs = path38.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 path36 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
7006
+ let path38 = 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 (path36 && path36[0] !== "/") {
7011
- path36 = `/${path36}`;
7010
+ if (path38 && path38[0] !== "/") {
7011
+ path38 = `/${path38}`;
7012
7012
  }
7013
- return new URL(`${origin}${path36}`);
7013
+ return new URL(`${origin}${path38}`);
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: path36, origin }
7834
+ request: { method, path: path38, origin }
7835
7835
  } = evt;
7836
- debugLog("sending request to %s %s%s", method, origin, path36);
7836
+ debugLog("sending request to %s %s%s", method, origin, path38);
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: path36, origin },
7854
+ request: { method, path: path38, 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
- path36,
7861
+ path38,
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: path36, origin }
7870
+ request: { method, path: path38, origin }
7871
7871
  } = evt;
7872
- debugLog("trailers received from %s %s%s", method, origin, path36);
7872
+ debugLog("trailers received from %s %s%s", method, origin, path38);
7873
7873
  }
7874
7874
  );
7875
7875
  diagnosticsChannel.subscribe(
7876
7876
  "undici:request:error",
7877
7877
  (evt) => {
7878
7878
  const {
7879
- request: { method, path: path36, origin },
7879
+ request: { method, path: path38, 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
- path36,
7886
+ path38,
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 Request = class {
8000
8000
  constructor(origin, {
8001
- path: path36,
8001
+ path: path38,
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 path36 !== "string") {
8018
+ if (typeof path38 !== "string") {
8019
8019
  throw new InvalidArgumentError2("path must be a string");
8020
- } else if (path36[0] !== "/" && !(path36.startsWith("http://") || path36.startsWith("https://")) && method !== "CONNECT") {
8020
+ } else if (path38[0] !== "/" && !(path38.startsWith("http://") || path38.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(path36)) {
8022
+ } else if (invalidPathRegex.test(path38)) {
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(path36, query) : path36;
8097
+ this.path = query ? serializePathWithQuery(path38, query) : path38;
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, request6) {
13279
- const { method, path: path36, host, upgrade, blocking, reset } = request6;
13279
+ const { method, path: path38, host, upgrade, blocking, reset } = request6;
13280
13280
  let { body, headers, contentLength } = request6;
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(request6.typeOfService);
13356
13356
  }
13357
- let header = `${method} ${path36} HTTP/1.1\r
13357
+ let header = `${method} ${path38} 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 = request6.headersTimeout ?? client[kHeadersTimeout];
14034
14034
  const bodyTimeout = request6.bodyTimeout ?? client[kBodyTimeout];
14035
14035
  const session = client[kHTTP2Session];
14036
- const { method, path: path36, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request6;
14036
+ const { method, path: path38, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request6;
14037
14037
  let { body } = request6;
14038
14038
  if (upgrade != null && upgrade !== "websocket") {
14039
14039
  util.errorRequest(client, request6, 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] = path36;
14105
+ headers[HTTP2_HEADER_PATH] = path38;
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] = path36;
14147
+ headers[HTTP2_HEADER_PATH] = path38;
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: path36 = "/",
16499
+ path: path38 = "/",
16500
16500
  headers = {}
16501
16501
  } = opts;
16502
- opts.path = origin + path36;
16502
+ opts.path = origin + path38;
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(path36) {
18612
- if (typeof path36 !== "string") {
18613
- return path36;
18611
+ function safeUrl(path38) {
18612
+ if (typeof path38 !== "string") {
18613
+ return path38;
18614
18614
  }
18615
- const pathSegments = path36.split("?", 3);
18615
+ const pathSegments = path38.split("?", 3);
18616
18616
  if (pathSegments.length !== 2) {
18617
- return path36;
18617
+ return path38;
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: path36, method, body, headers }) {
18624
- const pathMatch = matchValue(mockDispatch2.path, path36);
18623
+ function matchKey(mockDispatch2, { path: path38, method, body, headers }) {
18624
+ const pathMatch = matchValue(mockDispatch2.path, path38);
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: path36, ignoreTrailingSlash }) => {
18650
- return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path36)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path36), resolvedPath);
18649
+ let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path38, ignoreTrailingSlash }) => {
18650
+ return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path38)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path38), 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(path36) {
18690
- while (path36.endsWith("/")) {
18691
- path36 = path36.slice(0, -1);
18689
+ function removeTrailingSlash(path38) {
18690
+ while (path38.endsWith("/")) {
18691
+ path38 = path38.slice(0, -1);
18692
18692
  }
18693
- if (path36.length === 0) {
18694
- path36 = "/";
18693
+ if (path38.length === 0) {
18694
+ path38 = "/";
18695
18695
  }
18696
- return path36;
18696
+ return path38;
18697
18697
  }
18698
18698
  function buildKey(opts) {
18699
- const { path: path36, method, body, headers, query } = opts;
18699
+ const { path: path38, method, body, headers, query } = opts;
18700
18700
  return {
18701
- path: path36,
18701
+ path: path38,
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: path36, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
19391
+ ({ method, path: path38, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
19392
19392
  Method: method,
19393
19393
  Origin: origin,
19394
- Path: path36,
19394
+ Path: path38,
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 [path36, searchParams] = dispatchOpts.path.split("?");
19476
+ const [path38, searchParams] = dispatchOpts.path.split("?");
19477
19477
  const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
19478
- dispatchOpts.path = `${path36}?${normalizedSearchParams}`;
19478
+ dispatchOpts.path = `${path38}?${normalizedSearchParams}`;
19479
19479
  }
19480
19480
  return this[kAgent].dispatch(dispatchOpts, handler);
19481
19481
  }
@@ -19680,7 +19680,7 @@ var require_snapshot_recorder = __commonJS({
19680
19680
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
19681
19681
  "use strict";
19682
19682
  var { writeFile, readFile, mkdir } = require("node:fs/promises");
19683
- var { dirname, resolve } = require("node:path");
19683
+ var { dirname: dirname2, resolve } = require("node:path");
19684
19684
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = require("node:timers");
19685
19685
  var { InvalidArgumentError: InvalidArgumentError2, UndiciError } = require_errors();
19686
19686
  var { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require_snapshot_utils();
@@ -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 path36 = filePath || this.#snapshotPath;
19880
- if (!path36) {
19879
+ const path38 = filePath || this.#snapshotPath;
19880
+ if (!path38) {
19881
19881
  throw new InvalidArgumentError2("Snapshot path is required");
19882
19882
  }
19883
19883
  try {
19884
- const data = await readFile(resolve(path36), "utf8");
19884
+ const data = await readFile(resolve(path38), "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 ${path36}`, { cause: error62 });
19898
+ throw new UndiciError(`Failed to load snapshots from ${path38}`, { cause: error62 });
19899
19899
  }
19900
19900
  }
19901
19901
  }
@@ -19906,12 +19906,12 @@ var require_snapshot_recorder = __commonJS({
19906
19906
  * @returns {Promise<void>} - Resolves when snapshots are saved
19907
19907
  */
19908
19908
  async saveSnapshots(filePath) {
19909
- const path36 = filePath || this.#snapshotPath;
19910
- if (!path36) {
19909
+ const path38 = filePath || this.#snapshotPath;
19910
+ if (!path38) {
19911
19911
  throw new InvalidArgumentError2("Snapshot path is required");
19912
19912
  }
19913
- const resolvedPath = resolve(path36);
19914
- await mkdir(dirname(resolvedPath), { recursive: true });
19913
+ const resolvedPath = resolve(path38);
19914
+ await mkdir(dirname2(resolvedPath), { recursive: true });
19915
19915
  const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
19916
19916
  hash: hash2,
19917
19917
  snapshot
@@ -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 path36 = search ? `${pathname}${search}` : pathname;
20546
- const redirectUrlString = `${origin}${path36}`;
20545
+ const path38 = search ? `${pathname}${search}` : pathname;
20546
+ const redirectUrlString = `${origin}${path38}`;
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 = path36;
20553
+ this.opts.path = path38;
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, path36) {
22313
+ function deleteCachedUri(store, cacheKey, path38) {
22314
22314
  deleteCachedValue(store, {
22315
22315
  ...cacheKey,
22316
- path: path36
22316
+ path: path38
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: path36
22324
+ path: path38
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 path36 = getSameOriginPath(cacheKey, values[i2]);
22336
- if (path36 !== void 0) {
22337
- deleteCachedUri(store, cacheKey, path36);
22335
+ const path38 = getSameOriginPath(cacheKey, values[i2]);
22336
+ if (path38 !== void 0) {
22337
+ deleteCachedUri(store, cacheKey, path38);
22338
22338
  }
22339
22339
  }
22340
22340
  }
@@ -27334,11 +27334,11 @@ var require_fetch = __commonJS({
27334
27334
  function dispatch({ body }) {
27335
27335
  const url2 = requestCurrentURL(request6);
27336
27336
  const agent = fetchParams.controller.dispatcher;
27337
- const path36 = url2.pathname + url2.search;
27337
+ const path38 = 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 ? `${path36}?` : path36,
27341
+ path: hasTrailingQuestionMark ? `${path38}?` : path38,
27342
27342
  origin: url2.origin,
27343
27343
  method: request6.method,
27344
27344
  body: agent.isMockActive ? request6.body && (request6.body.source || request6.body.stream) : body,
@@ -28285,9 +28285,9 @@ var require_util5 = __commonJS({
28285
28285
  }
28286
28286
  }
28287
28287
  }
28288
- function validateCookiePath(path36) {
28289
- for (let i2 = 0; i2 < path36.length; ++i2) {
28290
- const code = path36.charCodeAt(i2);
28288
+ function validateCookiePath(path38) {
28289
+ for (let i2 = 0; i2 < path38.length; ++i2) {
28290
+ const code = path38.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 path36 = opts.path;
31638
+ let path38 = opts.path;
31639
31639
  if (!opts.path.startsWith("/")) {
31640
- path36 = `/${path36}`;
31640
+ path38 = `/${path38}`;
31641
31641
  }
31642
- url2 = new URL(util.parseOrigin(url2).origin + path36);
31642
+ url2 = new URL(util.parseOrigin(url2).origin + path38);
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_path35 = __toESM(require("node:path"), 1);
31752
+ var import_node_path36 = __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(path36) {
34866
- if (path36 === void 0) return this._executableDir;
34867
- this._executableDir = path36;
34865
+ executableDir(path38) {
34866
+ if (path38 === void 0) return this._executableDir;
34867
+ this._executableDir = path38;
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, path36) {
36006
- if (!path36)
36005
+ function getElementAtPath(obj, path38) {
36006
+ if (!path38)
36007
36007
  return obj;
36008
- return path36.reduce((acc, key) => acc?.[key], obj);
36008
+ return path38.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(path36, issues) {
36348
+ function prefixIssues(path38, issues) {
36349
36349
  return issues.map((iss) => {
36350
36350
  var _a3;
36351
36351
  (_a3 = iss).path ?? (_a3.path = []);
36352
- iss.path.unshift(path36);
36352
+ iss.path.unshift(path38);
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, path36 = []) => {
36802
+ const processError = (error63, path38 = []) => {
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 }, [...path36, ...issue2.path]));
36805
+ issue2.errors.map((issues) => processError({ issues }, [...path38, ...issue2.path]));
36806
36806
  } else if (issue2.code === "invalid_key") {
36807
- processError({ issues: issue2.issues }, [...path36, ...issue2.path]);
36807
+ processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
36808
36808
  } else if (issue2.code === "invalid_element") {
36809
- processError({ issues: issue2.issues }, [...path36, ...issue2.path]);
36809
+ processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
36810
36810
  } else {
36811
- const fullpath = [...path36, ...issue2.path];
36811
+ const fullpath = [...path38, ...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, path36 = []) => {
36850
+ const processError = (error63, path38 = []) => {
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 }, [...path36, ...issue2.path]));
36854
+ issue2.errors.map((issues) => processError({ issues }, [...path38, ...issue2.path]));
36855
36855
  } else if (issue2.code === "invalid_key") {
36856
- processError({ issues: issue2.issues }, [...path36, ...issue2.path]);
36856
+ processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
36857
36857
  } else if (issue2.code === "invalid_element") {
36858
- processError({ issues: issue2.issues }, [...path36, ...issue2.path]);
36858
+ processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
36859
36859
  } else {
36860
- const fullpath = [...path36, ...issue2.path];
36860
+ const fullpath = [...path38, ...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 path36 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
36900
- for (const seg of path36) {
36899
+ const path38 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
36900
+ for (const seg of path38) {
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 path36 = ref.slice(1).split("/").filter(Boolean);
54003
- if (path36.length === 0) {
54002
+ const path38 = ref.slice(1).split("/").filter(Boolean);
54003
+ if (path38.length === 0) {
54004
54004
  return ctx.rootSchema;
54005
54005
  }
54006
54006
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
54007
- if (path36[0] === defsKey) {
54008
- const key = path36[1] === void 0 ? void 0 : decodeJSONPointerSegment(path36[1]);
54007
+ if (path38[0] === defsKey) {
54008
+ const key = path38[1] === void 0 ? void 0 : decodeJSONPointerSegment(path38[1]);
54009
54009
  if (!key || !ctx.defs[key]) {
54010
54010
  throw new Error(`Reference not found: ${ref}`);
54011
54011
  }
@@ -55399,16 +55399,16 @@ function parseJson(raw, schema) {
55399
55399
  const parsed = schema.safeParse(JSON.parse(raw));
55400
55400
  return parsed.success ? parsed.data : void 0;
55401
55401
  }
55402
- function readHeadroomState(fs17, stateFile) {
55402
+ function readHeadroomState(fs18, stateFile) {
55403
55403
  try {
55404
- return parseJson(fs17.readFileUtf8(stateFile), HeadroomStateSchema);
55404
+ return parseJson(fs18.readFileUtf8(stateFile), HeadroomStateSchema);
55405
55405
  } catch {
55406
55406
  return void 0;
55407
55407
  }
55408
55408
  }
55409
- function writeHeadroomState(fs17, stateFile, state) {
55410
- fs17.mkdirp(import_node_path5.default.dirname(stateFile));
55411
- fs17.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
55409
+ function writeHeadroomState(fs18, stateFile, state) {
55410
+ fs18.mkdirp(import_node_path5.default.dirname(stateFile));
55411
+ fs18.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
55412
55412
  `);
55413
55413
  }
55414
55414
  function headroomAllowlist(providers) {
@@ -55428,14 +55428,14 @@ function headroomUpstreams(providers, frontDoorOrigin2) {
55428
55428
  function hashAllowlist(allowlist) {
55429
55429
  return (0, import_node_crypto2.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
55430
55430
  }
55431
- function readAllProviders(fs17, providersDir) {
55431
+ function readAllProviders(fs18, providersDir) {
55432
55432
  const result = [];
55433
- for (const name of fs17.readdir(providersDir)) {
55433
+ for (const name of fs18.readdir(providersDir)) {
55434
55434
  if (!name.endsWith(".json")) {
55435
55435
  continue;
55436
55436
  }
55437
55437
  try {
55438
- const parsed = parseJson(fs17.readFileUtf8(import_node_path5.default.join(providersDir, name)), ProviderSchema);
55438
+ const parsed = parseJson(fs18.readFileUtf8(import_node_path5.default.join(providersDir, name)), ProviderSchema);
55439
55439
  if (parsed !== void 0) {
55440
55440
  result.push({ name: name.slice(0, -".json".length), provider: parsed });
55441
55441
  }
@@ -55445,22 +55445,22 @@ function readAllProviders(fs17, providersDir) {
55445
55445
  }
55446
55446
  return result;
55447
55447
  }
55448
- function writeSession(fs17, sessionsDir, session) {
55449
- fs17.mkdirp(sessionsDir);
55450
- fs17.writeFileUtf8(import_node_path5.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
55448
+ function writeSession(fs18, sessionsDir, session) {
55449
+ fs18.mkdirp(sessionsDir);
55450
+ fs18.writeFileUtf8(import_node_path5.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
55451
55451
  `);
55452
55452
  }
55453
- function removeSession(fs17, sessionsDir, pid) {
55454
- fs17.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
55453
+ function removeSession(fs18, sessionsDir, pid) {
55454
+ fs18.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
55455
55455
  }
55456
- function listSessions(fs17, sessionsDir) {
55456
+ function listSessions(fs18, sessionsDir) {
55457
55457
  const sessions = [];
55458
- for (const name of fs17.readdir(sessionsDir)) {
55458
+ for (const name of fs18.readdir(sessionsDir)) {
55459
55459
  if (!name.endsWith(".json")) {
55460
55460
  continue;
55461
55461
  }
55462
55462
  try {
55463
- const parsed = parseJson(fs17.readFileUtf8(import_node_path5.default.join(sessionsDir, name)), HeadroomSessionSchema);
55463
+ const parsed = parseJson(fs18.readFileUtf8(import_node_path5.default.join(sessionsDir, name)), HeadroomSessionSchema);
55464
55464
  if (parsed !== void 0) {
55465
55465
  sessions.push(parsed);
55466
55466
  }
@@ -55470,22 +55470,22 @@ function listSessions(fs17, sessionsDir) {
55470
55470
  }
55471
55471
  return sessions.sort((a2, b) => a2.pid - b.pid);
55472
55472
  }
55473
- function sessionsForSupervisor(fs17, sessionsDir, supervisorPid) {
55474
- return listSessions(fs17, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
55473
+ function sessionsForSupervisor(fs18, sessionsDir, supervisorPid) {
55474
+ return listSessions(fs18, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
55475
55475
  }
55476
- function pruneDeadSessions(fs17, sessionsDir, isRunning) {
55476
+ function pruneDeadSessions(fs18, sessionsDir, isRunning) {
55477
55477
  const removed = [];
55478
- for (const session of listSessions(fs17, sessionsDir)) {
55478
+ for (const session of listSessions(fs18, sessionsDir)) {
55479
55479
  if (!isRunning(session.pid)) {
55480
- removeSession(fs17, sessionsDir, session.pid);
55480
+ removeSession(fs18, sessionsDir, session.pid);
55481
55481
  removed.push(session.pid);
55482
55482
  }
55483
55483
  }
55484
55484
  return removed;
55485
55485
  }
55486
- function readStartLock(fs17, lockFile) {
55486
+ function readStartLock(fs18, lockFile) {
55487
55487
  try {
55488
- return parseJson(fs17.readFileUtf8(lockFile), HeadroomLockSchema);
55488
+ return parseJson(fs18.readFileUtf8(lockFile), HeadroomLockSchema);
55489
55489
  } catch {
55490
55490
  return void 0;
55491
55491
  }
@@ -58797,8 +58797,8 @@ var FarmManifestSchema = external_exports.strictObject({
58797
58797
  materialised: external_exports.array(external_exports.string()),
58798
58798
  links: external_exports.array(external_exports.strictObject({ rel: external_exports.string(), target: external_exports.string() }))
58799
58799
  });
58800
- function readFarmManifest(fs17, farmRoot) {
58801
- const raw = fs17.readFileUtf8(import_node_path11.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs17.readFileUtf8(import_node_path11.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
58800
+ function readFarmManifest(fs18, farmRoot) {
58801
+ const raw = fs18.readFileUtf8(import_node_path11.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs18.readFileUtf8(import_node_path11.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
58802
58802
  if (raw === void 0) {
58803
58803
  return void 0;
58804
58804
  }
@@ -58856,9 +58856,9 @@ function buildEntryFacts(params) {
58856
58856
  entries
58857
58857
  };
58858
58858
  }
58859
- function listSubtree(fs17, root, rel) {
58859
+ function listSubtree(fs18, root, rel) {
58860
58860
  const absolute = import_node_path11.default.join(root, rel);
58861
- const stat = fs17.lstat(absolute);
58861
+ const stat = fs18.lstat(absolute);
58862
58862
  if (stat === void 0) {
58863
58863
  return [];
58864
58864
  }
@@ -58866,10 +58866,10 @@ function listSubtree(fs17, root, rel) {
58866
58866
  return [{ rel, kind: "symlink" }];
58867
58867
  }
58868
58868
  if (stat.kind === "dir") {
58869
- const children = [...fs17.readdir(absolute)].sort().flatMap((name) => listSubtree(fs17, root, `${rel}/${name}`));
58869
+ const children = [...fs18.readdir(absolute)].sort().flatMap((name) => listSubtree(fs18, root, `${rel}/${name}`));
58870
58870
  return [{ rel, kind: "dir" }, ...children];
58871
58871
  }
58872
- const contentHash = fs17.hashFile(absolute);
58872
+ const contentHash = fs18.hashFile(absolute);
58873
58873
  return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
58874
58874
  }
58875
58875
  function topLevelScopeRoots(roots) {
@@ -58883,25 +58883,25 @@ function topLevelScopeRoots(roots) {
58883
58883
  }
58884
58884
  return kept;
58885
58885
  }
58886
- function reconciliationScope(fs17, farmRoot, manifest) {
58886
+ function reconciliationScope(fs18, farmRoot, manifest) {
58887
58887
  if (manifest !== void 0) {
58888
58888
  return topLevelScopeRoots(manifest.materialised);
58889
58889
  }
58890
- return [...fs17.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs17.lstat(import_node_path11.default.join(farmRoot, name))?.kind === "dir").sort();
58890
+ return [...fs18.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs18.lstat(import_node_path11.default.join(farmRoot, name))?.kind === "dir").sort();
58891
58891
  }
58892
- function collectFarmListing(fs17, farmRoot, scopeRoots) {
58893
- return scopeRoots.flatMap((root) => listSubtree(fs17, farmRoot, root));
58892
+ function collectFarmListing(fs18, farmRoot, scopeRoots) {
58893
+ return scopeRoots.flatMap((root) => listSubtree(fs18, farmRoot, root));
58894
58894
  }
58895
- function collectCanonicalCounterparts(fs17, claudeHome, farmListing) {
58895
+ function collectCanonicalCounterparts(fs18, claudeHome, farmListing) {
58896
58896
  const out = [];
58897
58897
  for (const entry of farmListing) {
58898
58898
  const absolute = import_node_path11.default.join(claudeHome, entry.rel);
58899
- const stat = fs17.lstat(absolute);
58899
+ const stat = fs18.lstat(absolute);
58900
58900
  if (stat === void 0) {
58901
58901
  continue;
58902
58902
  }
58903
58903
  if (stat.kind === "file") {
58904
- const contentHash = fs17.hashFile(absolute);
58904
+ const contentHash = fs18.hashFile(absolute);
58905
58905
  out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
58906
58906
  continue;
58907
58907
  }
@@ -59741,8 +59741,8 @@ function decideConfigProfile(params) {
59741
59741
  }
59742
59742
  return { source: "none" };
59743
59743
  }
59744
- function loadIdentity(identitiesDir, name, fs17) {
59745
- return loadConfigFile(import_node_path14.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs17.readConfigFile);
59744
+ function loadIdentity(identitiesDir, name, fs18) {
59745
+ return loadConfigFile(import_node_path14.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs18.readConfigFile);
59746
59746
  }
59747
59747
 
59748
59748
  // src/poolStore.ts
@@ -61051,7 +61051,7 @@ function resolveLaunchIdentity(paths, cwd) {
61051
61051
  // package.json
61052
61052
  var package_default = {
61053
61053
  name: "agent-shim",
61054
- version: "7.1.2",
61054
+ version: "7.2.0",
61055
61055
  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.",
61056
61056
  license: "MIT",
61057
61057
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -61418,12 +61418,12 @@ function isIdentityName(name) {
61418
61418
  function claudeJsonPath(identitiesDir, identity) {
61419
61419
  return import_node_path20.default.join(identitiesDir, identity, CLAUDE_JSON);
61420
61420
  }
61421
- function readAccountMetadata(fs17, identitiesDir, identity) {
61421
+ function readAccountMetadata(fs18, identitiesDir, identity) {
61422
61422
  if (!isIdentityName(identity)) {
61423
61423
  throw new Error(`"${identity}" is not a valid identity name.`);
61424
61424
  }
61425
61425
  const file2 = claudeJsonPath(identitiesDir, identity);
61426
- const raw = fs17.readFileUtf8(file2);
61426
+ const raw = fs18.readFileUtf8(file2);
61427
61427
  if (raw === void 0) {
61428
61428
  return void 0;
61429
61429
  }
@@ -61453,19 +61453,19 @@ function readAccountMetadata(fs17, identitiesDir, identity) {
61453
61453
  }
61454
61454
  return account.data;
61455
61455
  }
61456
- function createAccountReader(fs17, identitiesDir) {
61456
+ function createAccountReader(fs18, identitiesDir) {
61457
61457
  const cache = /* @__PURE__ */ new Map();
61458
61458
  return (identity) => {
61459
61459
  if (!isIdentityName(identity)) {
61460
61460
  throw new Error(`"${identity}" is not a valid identity name.`);
61461
61461
  }
61462
- const stat = fs17.lstat(claudeJsonPath(identitiesDir, identity));
61462
+ const stat = fs18.lstat(claudeJsonPath(identitiesDir, identity));
61463
61463
  const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
61464
61464
  const cached2 = cache.get(identity);
61465
61465
  if (cached2?.stamp === stamp) {
61466
61466
  return cached2.account;
61467
61467
  }
61468
- const account = readAccountMetadata(fs17, identitiesDir, identity);
61468
+ const account = readAccountMetadata(fs18, identitiesDir, identity);
61469
61469
  cache.set(identity, { stamp, account });
61470
61470
  return account;
61471
61471
  };
@@ -61555,11 +61555,11 @@ function providerBaseUrl(port, provider) {
61555
61555
  function directOrigin(port) {
61556
61556
  return `http://127.0.0.1:${String(port)}`;
61557
61557
  }
61558
- function parseProviderPath(path36) {
61559
- if (!path36.startsWith(PROVIDER_PATH_PREFIX)) {
61558
+ function parseProviderPath(path38) {
61559
+ if (!path38.startsWith(PROVIDER_PATH_PREFIX)) {
61560
61560
  return void 0;
61561
61561
  }
61562
- const tail = path36.slice(PROVIDER_PATH_PREFIX.length);
61562
+ const tail = path38.slice(PROVIDER_PATH_PREFIX.length);
61563
61563
  const slash = tail.indexOf("/");
61564
61564
  if (slash <= 0) {
61565
61565
  return void 0;
@@ -61959,9 +61959,9 @@ function decoderFor(encoding) {
61959
61959
  return void 0;
61960
61960
  }
61961
61961
  }
61962
- function destinationOf(path36) {
61963
- const scoped = parseProviderPath(path36);
61964
- return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path36 } : { provider: scoped.provider, endpoint: scoped.rest };
61962
+ function destinationOf(path38) {
61963
+ const scoped = parseProviderPath(path38);
61964
+ return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path38 } : { provider: scoped.provider, endpoint: scoped.rest };
61965
61965
  }
61966
61966
  function buildRecord(event, context) {
61967
61967
  const { scan } = context;
@@ -62233,8 +62233,8 @@ function segmentDay(epochMs) {
62233
62233
  function segmentName(day, pid) {
62234
62234
  return `${day}.${String(pid)}.jsonl`;
62235
62235
  }
62236
- function listLogSegments(fs17, logDir) {
62237
- return fs17.readdir(logDir).flatMap((name) => {
62236
+ function listLogSegments(fs18, logDir) {
62237
+ return fs18.readdir(logDir).flatMap((name) => {
62238
62238
  const match = SEGMENT_RE.exec(name);
62239
62239
  const day = match?.[1];
62240
62240
  if (day === void 0) {
@@ -62243,15 +62243,15 @@ function listLogSegments(fs17, logDir) {
62243
62243
  return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
62244
62244
  }).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
62245
62245
  }
62246
- function readUsageLog(fs17, logDir, options = {}) {
62246
+ function readUsageLog(fs18, logDir, options = {}) {
62247
62247
  const { sinceMs } = options;
62248
62248
  const records = [];
62249
62249
  let invalidLines = 0;
62250
- for (const segment of listLogSegments(fs17, logDir)) {
62250
+ for (const segment of listLogSegments(fs18, logDir)) {
62251
62251
  if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
62252
62252
  continue;
62253
62253
  }
62254
- const contents = fs17.readFileUtf8(import_node_path21.default.join(logDir, segment.name));
62254
+ const contents = fs18.readFileUtf8(import_node_path21.default.join(logDir, segment.name));
62255
62255
  if (contents === void 0) {
62256
62256
  continue;
62257
62257
  }
@@ -62295,9 +62295,9 @@ function snapshotPath(snapshotsDir, identity) {
62295
62295
  }
62296
62296
  return import_node_path21.default.join(snapshotsDir, `${identity}.json`);
62297
62297
  }
62298
- function readUsageSnapshot(fs17, snapshotsDir, identity) {
62298
+ function readUsageSnapshot(fs18, snapshotsDir, identity) {
62299
62299
  const file2 = snapshotPath(snapshotsDir, identity);
62300
- const raw = fs17.readFileUtf8(file2);
62300
+ const raw = fs18.readFileUtf8(file2);
62301
62301
  if (raw === void 0) {
62302
62302
  return void 0;
62303
62303
  }
@@ -62313,8 +62313,8 @@ function readUsageSnapshot(fs17, snapshotsDir, identity) {
62313
62313
  }
62314
62314
  return snapshot.data;
62315
62315
  }
62316
- function listUsageSnapshots(fs17, snapshotsDir) {
62317
- return fs17.readdir(snapshotsDir).flatMap((name) => {
62316
+ function listUsageSnapshots(fs18, snapshotsDir) {
62317
+ return fs18.readdir(snapshotsDir).flatMap((name) => {
62318
62318
  if (!name.endsWith(".json")) {
62319
62319
  return [];
62320
62320
  }
@@ -62322,7 +62322,7 @@ function listUsageSnapshots(fs17, snapshotsDir) {
62322
62322
  if (!isIdentityName(identity)) {
62323
62323
  return [];
62324
62324
  }
62325
- const snapshot = readUsageSnapshot(fs17, snapshotsDir, identity);
62325
+ const snapshot = readUsageSnapshot(fs18, snapshotsDir, identity);
62326
62326
  return snapshot === void 0 ? [] : [snapshot];
62327
62327
  }).sort((left, right) => left.identity.localeCompare(right.identity));
62328
62328
  }
@@ -62381,11 +62381,11 @@ var import_node_path22 = __toESM(require("node:path"), 1);
62381
62381
  var DAY_MS2 = 864e5;
62382
62382
  var DAYS_IN_WEEK = 7;
62383
62383
  var USAGE_RETENTION_MS = DAYS_IN_WEEK * DAY_MS2;
62384
- function pruneUsageLog(fs17, logDir, nowMs) {
62384
+ function pruneUsageLog(fs18, logDir, nowMs) {
62385
62385
  const cutoff = nowMs - USAGE_RETENTION_MS;
62386
- for (const segment of listLogSegments(fs17, logDir)) {
62386
+ for (const segment of listLogSegments(fs18, logDir)) {
62387
62387
  if (segment.endsAt <= cutoff) {
62388
- fs17.removeRecursive(import_node_path22.default.join(logDir, segment.name));
62388
+ fs18.removeRecursive(import_node_path22.default.join(logDir, segment.name));
62389
62389
  }
62390
62390
  }
62391
62391
  }
@@ -62414,7 +62414,7 @@ function foldProviderState(current, record2) {
62414
62414
  };
62415
62415
  }
62416
62416
  function createUsageStore(deps) {
62417
- const { fs: fs17, paths } = deps;
62417
+ const { fs: fs18, paths } = deps;
62418
62418
  let prunedDay;
62419
62419
  const rewriteSnapshot = (identity, fold) => {
62420
62420
  if (!isIdentityName(identity)) {
@@ -62423,7 +62423,7 @@ function createUsageStore(deps) {
62423
62423
  }
62424
62424
  let current;
62425
62425
  try {
62426
- current = readUsageSnapshot(fs17, paths.usageSnapshotsDir, identity);
62426
+ current = readUsageSnapshot(fs18, paths.usageSnapshotsDir, identity);
62427
62427
  } catch (error62) {
62428
62428
  if (!(error62 instanceof UsageSnapshotError)) {
62429
62429
  throw error62;
@@ -62450,8 +62450,8 @@ function createUsageStore(deps) {
62450
62450
  ...account === void 0 ? {} : { account },
62451
62451
  providers
62452
62452
  });
62453
- fs17.mkdirPrivate(paths.usageSnapshotsDir);
62454
- fs17.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
62453
+ fs18.mkdirPrivate(paths.usageSnapshotsDir);
62454
+ fs18.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
62455
62455
  `);
62456
62456
  return true;
62457
62457
  };
@@ -62459,14 +62459,14 @@ function createUsageStore(deps) {
62459
62459
  record: (input2) => {
62460
62460
  const record2 = UsageRecordSchema.parse(input2);
62461
62461
  const nowMs = deps.now();
62462
- fs17.mkdirPrivate(paths.usageDir);
62463
- fs17.mkdirPrivate(paths.usageLogDir);
62462
+ fs18.mkdirPrivate(paths.usageDir);
62463
+ fs18.mkdirPrivate(paths.usageLogDir);
62464
62464
  const day = segmentDay(nowMs);
62465
62465
  if (prunedDay !== day) {
62466
- pruneUsageLog(fs17, paths.usageLogDir, nowMs);
62466
+ pruneUsageLog(fs18, paths.usageLogDir, nowMs);
62467
62467
  prunedDay = day;
62468
62468
  }
62469
- fs17.appendFilePrivate(import_node_path22.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
62469
+ fs18.appendFilePrivate(import_node_path22.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
62470
62470
  `);
62471
62471
  if (record2.identity !== void 0) {
62472
62472
  rewriteSnapshot(record2.identity, (current) => ({ ...current?.providers, [record2.provider]: foldProviderState(current?.providers[record2.provider], record2) }));
@@ -62493,14 +62493,14 @@ var PicksFileSchema = external_exports.strictObject({
62493
62493
  function errorMessage(error62) {
62494
62494
  return error62 instanceof Error ? error62.message : String(error62);
62495
62495
  }
62496
- function loadPoolMembers(fs17, paths, identities, nowMs) {
62496
+ function loadPoolMembers(fs18, paths, identities, nowMs) {
62497
62497
  const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
62498
- const log = readUsageLog(fs17, paths.usageLogDir, { sinceMs: windowStartMs });
62498
+ const log = readUsageLog(fs18, paths.usageLogDir, { sinceMs: windowStartMs });
62499
62499
  return identities.map((identity) => {
62500
62500
  const records = log.records.filter((record2) => record2.identity === identity && record2.provider === ANTHROPIC_PROVIDER && Date.parse(record2.at) >= windowStartMs);
62501
62501
  try {
62502
- const snapshot = readUsageSnapshot(fs17, paths.usageSnapshotsDir, identity);
62503
- const account = readAccountMetadata(fs17, paths.identitiesDir, identity) ?? snapshot?.account;
62502
+ const snapshot = readUsageSnapshot(fs18, paths.usageSnapshotsDir, identity);
62503
+ const account = readAccountMetadata(fs18, paths.identitiesDir, identity) ?? snapshot?.account;
62504
62504
  return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
62505
62505
  } catch (error62) {
62506
62506
  if (error62 instanceof UsageSnapshotError || error62 instanceof AccountMetadataError) {
@@ -62518,9 +62518,9 @@ function rankPoolFromStore(params) {
62518
62518
  ...params.sticky === void 0 ? {} : { sticky: params.sticky }
62519
62519
  });
62520
62520
  }
62521
- function readPicksFile(fs17, file2) {
62521
+ function readPicksFile(fs18, file2) {
62522
62522
  const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
62523
- const raw = fs17.readFileUtf8(file2);
62523
+ const raw = fs18.readFileUtf8(file2);
62524
62524
  if (raw === void 0) {
62525
62525
  return { file: empty };
62526
62526
  }
@@ -62533,17 +62533,17 @@ function readPicksFile(fs17, file2) {
62533
62533
  const result = PicksFileSchema.safeParse(parsed);
62534
62534
  return result.success ? { file: result.data } : { file: empty, problem: `${file2} is not a picks file this agent-shim can read` };
62535
62535
  }
62536
- function readStickyPick(fs17, picksFile, directory) {
62537
- const read = readPicksFile(fs17, picksFile);
62536
+ function readStickyPick(fs18, picksFile, directory) {
62537
+ const read = readPicksFile(fs18, picksFile);
62538
62538
  const entry = read.file.picks[directory];
62539
62539
  return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
62540
62540
  }
62541
- function recordStickyPick(fs17, picksFile, directory, identity, nowMs) {
62542
- const current = readPicksFile(fs17, picksFile).file.picks;
62541
+ function recordStickyPick(fs18, picksFile, directory, identity, nowMs) {
62542
+ const current = readPicksFile(fs18, picksFile).file.picks;
62543
62543
  const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
62544
62544
  const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
62545
- fs17.mkdirPrivate(import_node_path23.default.dirname(picksFile));
62546
- fs17.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
62545
+ fs18.mkdirPrivate(import_node_path23.default.dirname(picksFile));
62546
+ fs18.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
62547
62547
  `);
62548
62548
  }
62549
62549
 
@@ -62551,8 +62551,8 @@ function recordStickyPick(fs17, picksFile, directory, identity, nowMs) {
62551
62551
  var RESUME_FLAGS = /* @__PURE__ */ new Set(["--continue", "-c", "--resume", "-r"]);
62552
62552
  var TERMINATOR = "--";
62553
62553
  var REASONS_LOGGED = 3;
62554
- function splitMembers(pool, paths, fs17) {
62555
- const exists = (name) => loadIdentity(paths.identitiesDir, name, fs17) !== void 0;
62554
+ function splitMembers(pool, paths, fs18) {
62555
+ const exists = (name) => loadIdentity(paths.identitiesDir, name, fs18) !== void 0;
62556
62556
  return { present: pool.identities.filter(exists), missing: pool.identities.filter((name) => !exists(name)) };
62557
62557
  }
62558
62558
  function isResuming(passthrough) {
@@ -63816,10 +63816,10 @@ var FrontDoorStateSchema = external_exports.strictObject({
63816
63816
  /** The last fatal error, kept across shutdowns so `frontdoor status` can explain a front door that is not running. */
63817
63817
  lastError: external_exports.string().optional()
63818
63818
  });
63819
- function readFrontDoorState(fs17, stateFile) {
63819
+ function readFrontDoorState(fs18, stateFile) {
63820
63820
  let raw;
63821
63821
  try {
63822
- raw = fs17.readFileUtf8(stateFile);
63822
+ raw = fs18.readFileUtf8(stateFile);
63823
63823
  } catch {
63824
63824
  return void 0;
63825
63825
  }
@@ -63833,28 +63833,28 @@ function readFrontDoorState(fs17, stateFile) {
63833
63833
  return void 0;
63834
63834
  }
63835
63835
  }
63836
- function writeFrontDoorState(fs17, stateFile, state) {
63837
- fs17.mkdirp(import_node_path26.default.dirname(stateFile));
63838
- fs17.writeFileUtf8(stateFile, `${JSON.stringify(state, null, 2)}
63836
+ function writeFrontDoorState(fs18, stateFile, state) {
63837
+ fs18.mkdirp(import_node_path26.default.dirname(stateFile));
63838
+ fs18.writeFileUtf8(stateFile, `${JSON.stringify(state, null, 2)}
63839
63839
  `);
63840
63840
  }
63841
63841
  function frontDoorOrigin(state) {
63842
63842
  const port = state?.directPort ?? state?.lastDirectPort;
63843
63843
  return port === void 0 ? void 0 : `http://127.0.0.1:${String(port)}`;
63844
63844
  }
63845
- function writeFrontDoorSession(fs17, sessionsDir, session) {
63846
- fs17.mkdirPrivate(sessionsDir);
63847
- fs17.writeFilePrivate(import_node_path26.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
63845
+ function writeFrontDoorSession(fs18, sessionsDir, session) {
63846
+ fs18.mkdirPrivate(sessionsDir);
63847
+ fs18.writeFilePrivate(import_node_path26.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
63848
63848
  `);
63849
63849
  }
63850
- function listFrontDoorSessions(fs17, sessionsDir) {
63850
+ function listFrontDoorSessions(fs18, sessionsDir) {
63851
63851
  const sessions = [];
63852
- for (const name of fs17.readdir(sessionsDir)) {
63852
+ for (const name of fs18.readdir(sessionsDir)) {
63853
63853
  if (!name.endsWith(".json")) {
63854
63854
  continue;
63855
63855
  }
63856
63856
  try {
63857
- const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs17.readFileUtf8(import_node_path26.default.join(sessionsDir, name)) ?? ""));
63857
+ const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs18.readFileUtf8(import_node_path26.default.join(sessionsDir, name)) ?? ""));
63858
63858
  if (parsed.success) {
63859
63859
  sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt });
63860
63860
  }
@@ -63864,27 +63864,27 @@ function listFrontDoorSessions(fs17, sessionsDir) {
63864
63864
  }
63865
63865
  return sessions.sort((a2, b) => a2.pid - b.pid);
63866
63866
  }
63867
- function removeFrontDoorSession(fs17, sessionsDir, pid) {
63868
- fs17.removeRecursive(import_node_path26.default.join(sessionsDir, `${String(pid)}.json`));
63867
+ function removeFrontDoorSession(fs18, sessionsDir, pid) {
63868
+ fs18.removeRecursive(import_node_path26.default.join(sessionsDir, `${String(pid)}.json`));
63869
63869
  }
63870
- function pruneDeadFrontDoorSessions(fs17, sessionsDir, isRunning) {
63870
+ function pruneDeadFrontDoorSessions(fs18, sessionsDir, isRunning) {
63871
63871
  const removed = [];
63872
- for (const session of listFrontDoorSessions(fs17, sessionsDir)) {
63872
+ for (const session of listFrontDoorSessions(fs18, sessionsDir)) {
63873
63873
  if (!isRunning(session.pid)) {
63874
- removeFrontDoorSession(fs17, sessionsDir, session.pid);
63874
+ removeFrontDoorSession(fs18, sessionsDir, session.pid);
63875
63875
  removed.push(session.pid);
63876
63876
  }
63877
63877
  }
63878
63878
  return removed;
63879
63879
  }
63880
- function liveSessionTokens(fs17, sessionsDir) {
63880
+ function liveSessionTokens(fs18, sessionsDir) {
63881
63881
  const tokens = /* @__PURE__ */ new Set();
63882
- for (const name of fs17.readdir(sessionsDir)) {
63882
+ for (const name of fs18.readdir(sessionsDir)) {
63883
63883
  if (!name.endsWith(".json")) {
63884
63884
  continue;
63885
63885
  }
63886
63886
  try {
63887
- const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs17.readFileUtf8(import_node_path26.default.join(sessionsDir, name)) ?? ""));
63887
+ const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs18.readFileUtf8(import_node_path26.default.join(sessionsDir, name)) ?? ""));
63888
63888
  if (parsed.success) {
63889
63889
  tokens.add(parsed.data.token);
63890
63890
  }
@@ -64250,6 +64250,7 @@ function registerCodexCommand(program2, deps) {
64250
64250
 
64251
64251
  // src/frontdoor/commands.ts
64252
64252
  var import_node_crypto13 = require("node:crypto");
64253
+ var import_node_path29 = __toESM(require("node:path"), 1);
64253
64254
  var import_node_fs11 = __toESM(require("node:fs"), 1);
64254
64255
 
64255
64256
  // src/frontdoor/custody.ts
@@ -64387,9 +64388,109 @@ function isLiveCapability(presented, live) {
64387
64388
  return matched;
64388
64389
  }
64389
64390
 
64391
+ // src/frontdoor/capture.ts
64392
+ var fs11 = __toESM(require("node:fs"), 1);
64393
+ var path28 = __toESM(require("node:path"), 1);
64394
+ var SECRET_HEADER_NAME = /authorization|cookie|token|secret|credential|api[-_]key/i;
64395
+ var SECRET_JSON_KEY = /token|secret|password|credential|authorization|api[-_]key/i;
64396
+ var SECRET_BODY_PATTERNS = [
64397
+ { pattern: /sk-ant-[A-Za-z0-9_-]{8,}/g, replacement: "<redacted>" },
64398
+ { pattern: /Bearer\s+[A-Za-z0-9._~+/=-]{8,}/gi, replacement: "Bearer <redacted>" },
64399
+ { pattern: /eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{8,}/g, replacement: "<redacted>" }
64400
+ ];
64401
+ var CHUNK_LOG_CAP_BYTES = 8192;
64402
+ var STREAM_LOG_CAP_BYTES = 262144;
64403
+ var CAPTURE_FILE_MODE = 384;
64404
+ function redactHeaders(headers) {
64405
+ const result = {};
64406
+ for (const [name, value] of Object.entries(headers)) {
64407
+ result[name] = value !== void 0 && SECRET_HEADER_NAME.test(name) ? "<redacted>" : value;
64408
+ }
64409
+ return result;
64410
+ }
64411
+ function redactText(text2) {
64412
+ return SECRET_BODY_PATTERNS.reduce((accumulated, { pattern, replacement }) => accumulated.replace(pattern, replacement), text2);
64413
+ }
64414
+ function redactJsonValue(value) {
64415
+ if (typeof value === "string") {
64416
+ return redactText(value);
64417
+ }
64418
+ if (Array.isArray(value)) {
64419
+ return value.map(redactJsonValue);
64420
+ }
64421
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
64422
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, SECRET_JSON_KEY.test(key) ? "<redacted>" : redactJsonValue(entry)]));
64423
+ }
64424
+ return value;
64425
+ }
64426
+ function redactBody(chunk) {
64427
+ const text2 = chunk.toString("utf8");
64428
+ try {
64429
+ const parsed = JSON.parse(text2);
64430
+ return JSON.stringify(redactJsonValue(parsed));
64431
+ } catch {
64432
+ return redactText(text2);
64433
+ }
64434
+ }
64435
+ function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
64436
+ fs11.mkdirSync(path28.dirname(file2), { recursive: true });
64437
+ let nextId = 0;
64438
+ const append = (record2) => {
64439
+ fs11.appendFileSync(file2, `${JSON.stringify({ ts: now().toISOString(), ...record2 })}
64440
+ `, { mode: CAPTURE_FILE_MODE });
64441
+ };
64442
+ return {
64443
+ connect: (target, intercepted) => {
64444
+ append({ kind: "connect", host: target.host, port: target.port, intercepted });
64445
+ },
64446
+ upgrade: (request6) => {
64447
+ append({ kind: "upgrade", method: request6.method ?? "?", url: request6.url ?? "?", headers: redactHeaders(request6.headers) });
64448
+ },
64449
+ observePassthrough: (request6) => {
64450
+ nextId += 1;
64451
+ const id = nextId;
64452
+ append({ kind: "request", id, method: request6.method ?? "?", url: request6.url ?? "?", headers: redactHeaders(request6.headers) });
64453
+ const logged = { request: 0, response: 0 };
64454
+ const sequences = { request: 0, response: 0 };
64455
+ const chunk = (direction, incoming) => {
64456
+ sequences[direction] += 1;
64457
+ const budget = STREAM_LOG_CAP_BYTES - logged[direction];
64458
+ if (budget <= 0) {
64459
+ return;
64460
+ }
64461
+ const excerpt = incoming.subarray(0, Math.min(CHUNK_LOG_CAP_BYTES, budget));
64462
+ logged[direction] += excerpt.length;
64463
+ append({
64464
+ kind: `${direction}-chunk`,
64465
+ id,
64466
+ seq: sequences[direction],
64467
+ bytes: incoming.length,
64468
+ stored: excerpt.length,
64469
+ truncated: excerpt.length < incoming.length,
64470
+ body: redactBody(excerpt)
64471
+ });
64472
+ };
64473
+ return {
64474
+ onRequestChunk: (incoming) => {
64475
+ chunk("request", incoming);
64476
+ },
64477
+ onResponse: (status, headers) => {
64478
+ append({ kind: "response", id, status, headers: redactHeaders(headers) });
64479
+ },
64480
+ onResponseChunk: (incoming) => {
64481
+ chunk("response", incoming);
64482
+ },
64483
+ onEnd: () => {
64484
+ append({ kind: "end", id, requestBytesCapped: logged.request >= STREAM_LOG_CAP_BYTES, responseBytesCapped: logged.response >= STREAM_LOG_CAP_BYTES });
64485
+ }
64486
+ };
64487
+ }
64488
+ };
64489
+ }
64490
+
64390
64491
  // src/frontdoor/connect.ts
64391
64492
  var import_node_crypto10 = require("node:crypto");
64392
- var fs11 = __toESM(require("node:fs"), 1);
64493
+ var fs12 = __toESM(require("node:fs"), 1);
64393
64494
  var http = __toESM(require("node:http"), 1);
64394
64495
  var https = __toESM(require("node:https"), 1);
64395
64496
  var net3 = __toESM(require("node:net"), 1);
@@ -64671,8 +64772,8 @@ var FRONTDOOR_SUPERVISOR_STILL_RUNNING = -1;
64671
64772
  var FRONTDOOR_POLL_MS = 1e3;
64672
64773
  var MS_PER_MINUTE = 6e4;
64673
64774
  async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {}) {
64674
- const { fs: fs17, paths } = ports;
64675
- const previous = readFrontDoorState(fs17, paths.frontdoorStateFile);
64775
+ const { fs: fs18, paths } = ports;
64776
+ const previous = readFrontDoorState(fs18, paths.frontdoorStateFile);
64676
64777
  let lastPort = previous?.lastPort;
64677
64778
  let lastConnectPort = previous?.lastConnectPort;
64678
64779
  let lastDirectPort = previous?.lastDirectPort;
@@ -64682,12 +64783,12 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
64682
64783
  ...lastDirectPort === void 0 ? {} : { lastDirectPort }
64683
64784
  });
64684
64785
  const fail = (message) => {
64685
- writeFrontDoorState(fs17, paths.frontdoorStateFile, { lastError: message, ...sticky() });
64686
- fs17.removeRecursive(paths.frontdoorLockFile);
64786
+ writeFrontDoorState(fs18, paths.frontdoorStateFile, { lastError: message, ...sticky() });
64787
+ fs18.removeRecursive(paths.frontdoorLockFile);
64687
64788
  ports.log(`agent-shim frontdoor supervisor: ${message}`);
64688
64789
  return 1;
64689
64790
  };
64690
- writeFrontDoorState(fs17, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
64791
+ writeFrontDoorState(fs18, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
64691
64792
  const previousSticky = lastPort;
64692
64793
  let http5;
64693
64794
  try {
@@ -64724,8 +64825,8 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
64724
64825
  ports.log(`agent-shim frontdoor supervisor: sticky direct port ${String(previousStickyDirect)} was occupied; moving to ${String(direct.port)} (headroom must be restarted to admit the new address)`);
64725
64826
  }
64726
64827
  lastDirectPort = direct.port;
64727
- writeFrontDoorState(fs17, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, port: http5.port, connectPort: connect2.port, directPort: direct.port, ...sticky() });
64728
- fs17.removeRecursive(paths.frontdoorLockFile);
64828
+ writeFrontDoorState(fs18, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, port: http5.port, connectPort: connect2.port, directPort: direct.port, ...sticky() });
64829
+ fs18.removeRecursive(paths.frontdoorLockFile);
64729
64830
  ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http5.port)}, CONNECT surface on 127.0.0.1:${String(connect2.port)}`);
64730
64831
  let idleSince;
64731
64832
  let ticks = 0;
@@ -64734,15 +64835,15 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
64734
64835
  return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
64735
64836
  }
64736
64837
  ticks += 1;
64737
- pruneDeadFrontDoorSessions(fs17, paths.frontdoorSessionsDir, ports.isRunning);
64738
- if (listFrontDoorSessions(fs17, paths.frontdoorSessionsDir).length === 0) {
64838
+ pruneDeadFrontDoorSessions(fs18, paths.frontdoorSessionsDir, ports.isRunning);
64839
+ if (listFrontDoorSessions(fs18, paths.frontdoorSessionsDir).length === 0) {
64739
64840
  idleSince ??= ports.now();
64740
64841
  if (ports.now() - idleSince >= idleShutdownMinutes * MS_PER_MINUTE) {
64741
64842
  ports.log(`agent-shim frontdoor supervisor: no sessions for ${String(idleShutdownMinutes)} minute(s); closing the front door and exiting`);
64742
64843
  await direct.close();
64743
64844
  await connect2.close();
64744
64845
  await http5.close();
64745
- writeFrontDoorState(fs17, paths.frontdoorStateFile, sticky());
64846
+ writeFrontDoorState(fs18, paths.frontdoorStateFile, sticky());
64746
64847
  return 0;
64747
64848
  }
64748
64849
  } else {
@@ -64796,8 +64897,8 @@ function parseConnectTarget(authority) {
64796
64897
  function isInterceptedHost(host, interceptHost) {
64797
64898
  return host === interceptHost;
64798
64899
  }
64799
- function servedByPipeline(path36) {
64800
- return path36?.startsWith(ROUTED_PATH_PREFIX) === true;
64900
+ function servedByPipeline(path38) {
64901
+ return path38?.startsWith(ROUTED_PATH_PREFIX) === true;
64801
64902
  }
64802
64903
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
64803
64904
  "connection",
@@ -64870,9 +64971,9 @@ async function startConnectServer(config2, effects, preferredPort) {
64870
64971
  config2.serveRouted(request6, response);
64871
64972
  return;
64872
64973
  }
64873
- effects.forwardHttp(config2.upstream, request6, response);
64974
+ effects.forwardHttp(config2.upstream, request6, response, config2.capture?.observePassthrough(request6));
64874
64975
  };
64875
- const httpSession = effects.createHttpSession(handler);
64976
+ const httpSession = effects.createHttpSession(handler, config2.capture === void 0 ? void 0 : (request6) => config2.capture?.upgrade(request6));
64876
64977
  const tlsAcceptor = effects.createTlsAcceptor(config2.leafFor(config2.interceptHost), (secure) => {
64877
64978
  httpSession.serve(secure);
64878
64979
  });
@@ -65025,6 +65126,7 @@ function routeConnect(socket, head, context) {
65025
65126
  refuse(socket, REFUSAL.serviceUnavailable);
65026
65127
  return;
65027
65128
  }
65129
+ config2.capture?.connect(target, isInterceptedHost(target.host, config2.interceptHost));
65028
65130
  socket.write(CONNECT_ESTABLISHED);
65029
65131
  if (isInterceptedHost(target.host, config2.interceptHost)) {
65030
65132
  tlsAcceptor.accept(socket);
@@ -65121,11 +65223,17 @@ function realConnectEffects() {
65121
65223
  }
65122
65224
  };
65123
65225
  },
65124
- createHttpSession: (handler) => {
65226
+ createHttpSession: (handler, onUpgrade) => {
65125
65227
  const server = http.createServer(handler);
65126
65228
  server.on("clientError", (_error, socket) => {
65127
65229
  socket.destroy();
65128
65230
  });
65231
+ if (onUpgrade !== void 0) {
65232
+ server.on("upgrade", (request6, socket) => {
65233
+ onUpgrade(request6);
65234
+ socket.destroy();
65235
+ });
65236
+ }
65129
65237
  return {
65130
65238
  serve: (socket) => {
65131
65239
  server.emit("connection", socket);
@@ -65143,7 +65251,7 @@ function realConnectEffects() {
65143
65251
  });
65144
65252
  socket.once("error", reject);
65145
65253
  }),
65146
- forwardHttp: (target, request6, response) => {
65254
+ forwardHttp: (target, request6, response, observer) => {
65147
65255
  const headers = forwardableHeaders(request6.headers);
65148
65256
  const options = {
65149
65257
  host: target.host,
@@ -65163,8 +65271,14 @@ function realConnectEffects() {
65163
65271
  }
65164
65272
  }
65165
65273
  const onUpstreamResponse = (upstreamResponse) => {
65274
+ observer?.onResponse(upstreamResponse.statusCode ?? HTTP_BAD_GATEWAY, upstreamResponse.headers);
65166
65275
  response.writeHead(upstreamResponse.statusCode ?? HTTP_BAD_GATEWAY, forwardableHeaders(upstreamResponse.headers));
65167
65276
  response.flushHeaders();
65277
+ if (observer !== void 0) {
65278
+ upstreamResponse.on("data", (chunk) => {
65279
+ observer.onResponseChunk(chunk);
65280
+ });
65281
+ }
65168
65282
  upstreamResponse.pipe(response);
65169
65283
  };
65170
65284
  const upstream = target.tls ? https.request(options, onUpstreamResponse) : http.request(options, onUpstreamResponse);
@@ -65177,6 +65291,14 @@ function realConnectEffects() {
65177
65291
  response.writeHead(HTTP_BAD_GATEWAY, { "content-type": "text/plain", "content-length": String(body.length) });
65178
65292
  response.end(body);
65179
65293
  });
65294
+ if (observer !== void 0) {
65295
+ request6.on("data", (chunk) => {
65296
+ observer.onRequestChunk(chunk);
65297
+ });
65298
+ response.on("close", () => {
65299
+ observer.onEnd();
65300
+ });
65301
+ }
65180
65302
  request6.pipe(upstream);
65181
65303
  request6.socket.setNoDelay(true);
65182
65304
  upstream.on("socket", (socket) => {
@@ -65191,7 +65313,7 @@ function isEnoent5(error62) {
65191
65313
  function realConnectCertStore(paths) {
65192
65314
  const read = (file2) => {
65193
65315
  try {
65194
- return fs11.readFileSync(file2, "utf8");
65316
+ return fs12.readFileSync(file2, "utf8");
65195
65317
  } catch (error62) {
65196
65318
  if (isEnoent5(error62)) {
65197
65319
  return void 0;
@@ -65206,10 +65328,10 @@ function realConnectCertStore(paths) {
65206
65328
  return certPem === void 0 || keyPem2 === void 0 ? void 0 : { certPem, keyPem: keyPem2 };
65207
65329
  },
65208
65330
  writeCa: (ca) => {
65209
- fs11.mkdirSync(paths.frontdoorCaDir, { recursive: true });
65210
- fs11.writeFileSync(paths.frontdoorCaCertFile, ca.certPem, "utf8");
65211
- fs11.writeFileSync(paths.frontdoorCaKeyFile, ca.keyPem, { encoding: "utf8", mode: CA_KEY_FILE_MODE });
65212
- fs11.chmodSync(paths.frontdoorCaKeyFile, CA_KEY_FILE_MODE);
65331
+ fs12.mkdirSync(paths.frontdoorCaDir, { recursive: true });
65332
+ fs12.writeFileSync(paths.frontdoorCaCertFile, ca.certPem, "utf8");
65333
+ fs12.writeFileSync(paths.frontdoorCaKeyFile, ca.keyPem, { encoding: "utf8", mode: CA_KEY_FILE_MODE });
65334
+ fs12.chmodSync(paths.frontdoorCaKeyFile, CA_KEY_FILE_MODE);
65213
65335
  }
65214
65336
  };
65215
65337
  }
@@ -66296,8 +66418,8 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
66296
66418
  request6.body.resume();
66297
66419
  return;
66298
66420
  }
66299
- const path36 = new URL(request6.url, "http://127.0.0.1").pathname;
66300
- const translated = { method: request6.method, path: path36, body, signal: request6.signal };
66421
+ const path38 = new URL(request6.url, "http://127.0.0.1").pathname;
66422
+ const translated = { method: request6.method, path: path38, body, signal: request6.signal };
66301
66423
  const routed = await route(translated);
66302
66424
  if (request6.signal.aborted) {
66303
66425
  return;
@@ -66331,7 +66453,7 @@ function createPassthroughRoute(name, target) {
66331
66453
  headroomUpstream: target.headroomUpstream,
66332
66454
  serve: async (request6, response) => {
66333
66455
  const incoming = new URL(request6.url, "http://127.0.0.1");
66334
- const path36 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
66456
+ const path38 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
66335
66457
  const headers = forwardableHeaders(request6.headers);
66336
66458
  delete headers.host;
66337
66459
  await new Promise((resolve) => {
@@ -66339,7 +66461,7 @@ function createPassthroughRoute(name, target) {
66339
66461
  host: base.hostname,
66340
66462
  port: base.port === "" ? void 0 : Number(base.port),
66341
66463
  method: request6.method,
66342
- path: `${basePath}${path36}${incoming.search}`,
66464
+ path: `${basePath}${path38}${incoming.search}`,
66343
66465
  headers,
66344
66466
  agent
66345
66467
  };
@@ -66401,10 +66523,10 @@ function createProviderRouteResolver(deps) {
66401
66523
  return route;
66402
66524
  };
66403
66525
  const resolve = (request6) => {
66404
- const path36 = new URL(request6.url, "http://127.0.0.1").pathname;
66405
- const scoped = parseProviderPath(path36);
66526
+ const path38 = new URL(request6.url, "http://127.0.0.1").pathname;
66527
+ const scoped = parseProviderPath(path38);
66406
66528
  if (scoped === void 0) {
66407
- return path36.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path36}` };
66529
+ return path38.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path38}` };
66408
66530
  }
66409
66531
  const { provider } = scoped;
66410
66532
  let definition;
@@ -66448,14 +66570,14 @@ var import_node_crypto12 = require("node:crypto");
66448
66570
  var import_node_path28 = __toESM(require("node:path"), 1);
66449
66571
  var BUNDLE_NAME_HEX_DIGITS = 16;
66450
66572
  function resolveTrustBundle(params) {
66451
- const { caCertFile, bundlesDir, inherited, fs: fs17 } = params;
66573
+ const { caCertFile, bundlesDir, inherited, fs: fs18 } = params;
66452
66574
  if (inherited === void 0 || inherited === "" || import_node_path28.default.resolve(inherited) === import_node_path28.default.resolve(caCertFile)) {
66453
66575
  return { path: caCertFile };
66454
66576
  }
66455
- const caPem = fs17.readFileUtf8(caCertFile);
66577
+ const caPem = fs18.readFileUtf8(caCertFile);
66456
66578
  let inheritedPem;
66457
66579
  try {
66458
- inheritedPem = fs17.readFileUtf8(inherited);
66580
+ inheritedPem = fs18.readFileUtf8(inherited);
66459
66581
  } catch (error62) {
66460
66582
  return {
66461
66583
  path: caCertFile,
@@ -66468,9 +66590,9 @@ function resolveTrustBundle(params) {
66468
66590
  const combined = `${inheritedPem.trimEnd()}
66469
66591
  ${caPem}`;
66470
66592
  const bundle = import_node_path28.default.join(bundlesDir, `${(0, import_node_crypto12.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
66471
- if (!fs17.exists(bundle)) {
66472
- fs17.mkdirp(bundlesDir);
66473
- fs17.writeFileAtomic(bundle, combined);
66593
+ if (!fs18.exists(bundle)) {
66594
+ fs18.mkdirp(bundlesDir);
66595
+ fs18.writeFileAtomic(bundle, combined);
66474
66596
  }
66475
66597
  return { path: bundle };
66476
66598
  }
@@ -66835,6 +66957,10 @@ function realFrontDoorSupervisorPorts(paths) {
66835
66957
  },
66836
66958
  startConnectListener: async (preferredPort) => {
66837
66959
  const leafFor = createLeafCache(loadCa(), () => /* @__PURE__ */ new Date());
66960
+ const capture = process.env.AGENT_SHIM_FRONTDOOR_CAPTURE === "1" ? createFileCapture(import_node_path29.default.join(paths.logsDir, "frontdoor-capture.jsonl")) : void 0;
66961
+ if (capture !== void 0) {
66962
+ log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path29.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
66963
+ }
66838
66964
  const server = await startConnectServer(
66839
66965
  {
66840
66966
  interceptHost: CONNECT_INTERCEPT_HOST,
@@ -66860,7 +66986,8 @@ function realFrontDoorSupervisorPorts(paths) {
66860
66986
  leafFor,
66861
66987
  upstream: { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT, tls: true },
66862
66988
  isLiveCapability: isLiveToken,
66863
- limits: CONNECT_LIMITS
66989
+ limits: CONNECT_LIMITS,
66990
+ ...capture === void 0 ? {} : { capture }
66864
66991
  },
66865
66992
  realConnectEffects(),
66866
66993
  preferredPort
@@ -67277,15 +67404,15 @@ var import_node_child_process4 = require("node:child_process");
67277
67404
 
67278
67405
  // src/identityToken.ts
67279
67406
  var import_node_fs12 = __toESM(require("node:fs"), 1);
67280
- var import_node_path29 = __toESM(require("node:path"), 1);
67407
+ var import_node_path30 = __toESM(require("node:path"), 1);
67281
67408
  var TOKEN_FILE_MODE = 384;
67282
67409
  var TOKEN_DIR_MODE = 448;
67283
67410
  var OAUTH_TOKEN_RE = /^sk-ant-oat\d+-[A-Za-z0-9_-]+$/;
67284
67411
  function identityTokenDir(paths) {
67285
- return import_node_path29.default.join(paths.root, "credentials");
67412
+ return import_node_path30.default.join(paths.root, "credentials");
67286
67413
  }
67287
67414
  function identityTokenPath(paths, identityName) {
67288
- return import_node_path29.default.join(identityTokenDir(paths), `${identityName}.token`);
67415
+ return import_node_path30.default.join(identityTokenDir(paths), `${identityName}.token`);
67289
67416
  }
67290
67417
  function storeIdentityToken(paths, identityName, raw) {
67291
67418
  const token = raw.trim();
@@ -67296,7 +67423,7 @@ function storeIdentityToken(paths, identityName, raw) {
67296
67423
  import_node_fs12.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
67297
67424
  import_node_fs12.default.chmodSync(dir, TOKEN_DIR_MODE);
67298
67425
  const target = identityTokenPath(paths, identityName);
67299
- const temp = import_node_path29.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
67426
+ const temp = import_node_path30.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
67300
67427
  import_node_fs12.default.writeFileSync(temp, `${token}
67301
67428
  `, { mode: TOKEN_FILE_MODE });
67302
67429
  import_node_fs12.default.renameSync(temp, target);
@@ -67306,7 +67433,7 @@ function storeIdentityToken(paths, identityName, raw) {
67306
67433
  // src/realCredentialCache.ts
67307
67434
  var import_node_child_process3 = require("node:child_process");
67308
67435
  var import_node_fs13 = __toESM(require("node:fs"), 1);
67309
- var import_node_path30 = __toESM(require("node:path"), 1);
67436
+ var import_node_path31 = __toESM(require("node:path"), 1);
67310
67437
  var KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
67311
67438
  var CACHE_DIR_MODE = 448;
67312
67439
  var CACHE_FILE_MODE = 384;
@@ -67333,8 +67460,8 @@ function security(args, stdin2) {
67333
67460
  return { status: result.status, stdout: result.stdout };
67334
67461
  }
67335
67462
  function createRealCredentialCache(root) {
67336
- const dir = import_node_path30.default.join(root, "credential-cache");
67337
- const filePath = (owner) => import_node_path30.default.join(dir, cacheFileNameFor(owner));
67463
+ const dir = import_node_path31.default.join(root, "credential-cache");
67464
+ const filePath = (owner) => import_node_path31.default.join(dir, cacheFileNameFor(owner));
67338
67465
  return {
67339
67466
  read(store, owner) {
67340
67467
  if (store === "file") {
@@ -67513,7 +67640,7 @@ function subjectName(positional, provider) {
67513
67640
 
67514
67641
  // src/doctor.ts
67515
67642
  var import_node_fs14 = __toESM(require("node:fs"), 1);
67516
- var import_node_path31 = __toESM(require("node:path"), 1);
67643
+ var import_node_path32 = __toESM(require("node:path"), 1);
67517
67644
 
67518
67645
  // src/headroom/source.ts
67519
67646
  var GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
@@ -67564,7 +67691,7 @@ function validateJson(schema, input2) {
67564
67691
  return { ok: true, data: result.data };
67565
67692
  }
67566
67693
  function pushPathResolution(push, resolution) {
67567
- const ownDir = import_node_path31.default.dirname(resolution.ownExecutablePath);
67694
+ const ownDir = import_node_path32.default.dirname(resolution.ownExecutablePath);
67568
67695
  switch (resolution.agentShim.status) {
67569
67696
  case "ok":
67570
67697
  push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
@@ -67632,14 +67759,14 @@ function pushProvider(push, entry) {
67632
67759
  }
67633
67760
  function pushLegacyName(push, params) {
67634
67761
  const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
67635
- if (legacyVariables.length === 0 && import_node_path31.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
67762
+ if (legacyVariables.length === 0 && import_node_path32.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
67636
67763
  push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
67637
67764
  return;
67638
67765
  }
67639
67766
  for (const name of legacyVariables) {
67640
67767
  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);
67641
67768
  }
67642
- if (import_node_path31.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
67769
+ if (import_node_path32.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
67643
67770
  push(
67644
67771
  "legacy-name",
67645
67772
  "warn",
@@ -67950,18 +68077,18 @@ function registerDoctorCommand(program2, deps) {
67950
68077
  ).option("--json", "Print the report as JSON.").action((options) => {
67951
68078
  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() : [];
67952
68079
  const identities = identityNames.map((name) => {
67953
- const farmRoot = import_node_path31.default.join(paths.identitiesDir, name);
67954
- const identityPath = import_node_path31.default.join(farmRoot, "identity.json");
68080
+ const farmRoot = import_node_path32.default.join(paths.identitiesDir, name);
68081
+ const identityPath = import_node_path32.default.join(farmRoot, "identity.json");
67955
68082
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
67956
68083
  });
67957
68084
  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() : [];
67958
68085
  const configProfiles = profileNames.map((name) => {
67959
- const profilePath = import_node_path31.default.join(paths.configProfilesDir, `${name}.json`);
68086
+ const profilePath = import_node_path32.default.join(paths.configProfilesDir, `${name}.json`);
67960
68087
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
67961
68088
  });
67962
68089
  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() : [];
67963
68090
  const providers = providerNames.map((name) => {
67964
- const providerPath = import_node_path31.default.join(paths.providersDir, `${name}.json`);
68091
+ const providerPath = import_node_path32.default.join(paths.providersDir, `${name}.json`);
67965
68092
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
67966
68093
  });
67967
68094
  const ownExecutablePath = realOwnExecutablePath();
@@ -67973,12 +68100,12 @@ function registerDoctorCommand(program2, deps) {
67973
68100
  binaryDiscovery = { ok: false, message: error62 instanceof Error ? error62.message : String(error62) };
67974
68101
  }
67975
68102
  const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
67976
- const pathDirs = (process.env.PATH ?? "").split(import_node_path31.default.delimiter).filter((dir) => dir !== "");
68103
+ const pathDirs = (process.env.PATH ?? "").split(import_node_path32.default.delimiter).filter((dir) => dir !== "");
67977
68104
  const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
67978
68105
  findPathShadow({
67979
68106
  pathDirs,
67980
- targetDir: import_node_path31.default.dirname(shimState.targetPath),
67981
- targetFilename: import_node_path31.default.basename(shimState.targetPath),
68107
+ targetDir: import_node_path32.default.dirname(shimState.targetPath),
68108
+ targetFilename: import_node_path32.default.basename(shimState.targetPath),
67982
68109
  findExecutableInDir
67983
68110
  }),
67984
68111
  shimState.targetPath,
@@ -68001,7 +68128,7 @@ function registerDoctorCommand(program2, deps) {
68001
68128
  agentShim: refinePathShadow(
68002
68129
  findPathShadow({
68003
68130
  pathDirs,
68004
- targetDir: import_node_path31.default.dirname(ownExecutablePath),
68131
+ targetDir: import_node_path32.default.dirname(ownExecutablePath),
68005
68132
  targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
68006
68133
  findExecutableInDir
68007
68134
  }),
@@ -68034,7 +68161,7 @@ function registerDoctorCommand(program2, deps) {
68034
68161
  // src/headroom/commands.ts
68035
68162
  var import_node_fs15 = __toESM(require("node:fs"), 1);
68036
68163
  var import_node_net3 = __toESM(require("node:net"), 1);
68037
- var import_node_path32 = __toESM(require("node:path"), 1);
68164
+ var import_node_path33 = __toESM(require("node:path"), 1);
68038
68165
  var import_node_child_process5 = require("node:child_process");
68039
68166
 
68040
68167
  // src/headroom/settings.ts
@@ -68165,9 +68292,9 @@ function compareVersions2(a2, b) {
68165
68292
  }
68166
68293
  var HEADROOM_SUPERVISOR_STILL_RUNNING = -1;
68167
68294
  async function runSupervisor(initialConfig, ports, options = {}) {
68168
- const { fs: fs17, paths } = ports;
68295
+ const { fs: fs18, paths } = ports;
68169
68296
  let config2 = initialConfig;
68170
- const previousState = readHeadroomState(fs17, paths.headroomStateFile);
68297
+ const previousState = readHeadroomState(fs18, paths.headroomStateFile);
68171
68298
  if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
68172
68299
  ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
68173
68300
  return 0;
@@ -68176,19 +68303,19 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68176
68303
  let lastPort = previousState?.lastPort;
68177
68304
  const sticky = () => lastPort === void 0 ? {} : { lastPort };
68178
68305
  const ownsState = () => {
68179
- const owner = readHeadroomState(fs17, paths.headroomStateFile)?.supervisorPid;
68306
+ const owner = readHeadroomState(fs18, paths.headroomStateFile)?.supervisorPid;
68180
68307
  return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
68181
68308
  };
68182
68309
  const writeOwnState = (state) => {
68183
68310
  if (!ownsState()) {
68184
68311
  return false;
68185
68312
  }
68186
- writeHeadroomState(fs17, paths.headroomStateFile, state);
68313
+ writeHeadroomState(fs18, paths.headroomStateFile, state);
68187
68314
  return true;
68188
68315
  };
68189
68316
  const fail = (message) => {
68190
68317
  if (writeOwnState({ lastError: message, ...sticky() })) {
68191
- fs17.removeRecursive(paths.headroomLockFile);
68318
+ fs18.removeRecursive(paths.headroomLockFile);
68192
68319
  }
68193
68320
  ports.log(`agent-shim headroom supervisor: ${message}`);
68194
68321
  return 1;
@@ -68237,7 +68364,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68237
68364
  const settingsHash = hashSettings(config2.settings);
68238
68365
  const allowlist = allowlistOf(ports);
68239
68366
  const allowlistHash = hashAllowlist(allowlist);
68240
- pruneDeadSessions(fs17, paths.headroomSessionsDir, ports.isRunning);
68367
+ pruneDeadSessions(fs18, paths.headroomSessionsDir, ports.isRunning);
68241
68368
  const ownsNow = ownsState();
68242
68369
  if (!ownsNow && !superseded) {
68243
68370
  ports.log("agent-shim headroom supervisor: another supervisor now owns state.json; serving this daemon's own sessions until they end");
@@ -68289,7 +68416,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68289
68416
  ...sticky()
68290
68417
  });
68291
68418
  if (recorded) {
68292
- fs17.removeRecursive(paths.headroomLockFile);
68419
+ fs18.removeRecursive(paths.headroomLockFile);
68293
68420
  }
68294
68421
  idleSince = void 0;
68295
68422
  ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on 127.0.0.1:${String(port)}`);
@@ -68304,7 +68431,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68304
68431
  }
68305
68432
  } else {
68306
68433
  if (runningHash !== allowlistHash || runningSettingsHash !== settingsHash || installedSource !== config2.source) {
68307
- if (sessionsForSupervisor(fs17, paths.headroomSessionsDir, ports.ownPid).length === 0) {
68434
+ if (sessionsForSupervisor(fs18, paths.headroomSessionsDir, ports.ownPid).length === 0) {
68308
68435
  ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
68309
68436
  ports.stopProcess(headroomPid);
68310
68437
  headroomPid = void 0;
@@ -68313,7 +68440,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68313
68440
  continue;
68314
68441
  }
68315
68442
  }
68316
- const sessions = sessionsForSupervisor(fs17, paths.headroomSessionsDir, ports.ownPid);
68443
+ const sessions = sessionsForSupervisor(fs18, paths.headroomSessionsDir, ports.ownPid);
68317
68444
  if (sessions.length === 0) {
68318
68445
  idleSince ??= ports.now();
68319
68446
  const idleMs = ports.now() - idleSince;
@@ -68335,9 +68462,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68335
68462
  await ports.sleep(HEADROOM_POLL_MS);
68336
68463
  }
68337
68464
  }
68338
- function currentHeadroomAllowlist(fs17, paths) {
68339
- const providers = readAllProviders(fs17, paths.providersDir).map((entry) => entry.provider);
68340
- return headroomAllowlist(headroomUpstreams(providers, frontDoorOrigin(readFrontDoorState(fs17, paths.frontdoorStateFile))));
68465
+ function currentHeadroomAllowlist(fs18, paths) {
68466
+ const providers = readAllProviders(fs18, paths.providersDir).map((entry) => entry.provider);
68467
+ return headroomAllowlist(headroomUpstreams(providers, frontDoorOrigin(readFrontDoorState(fs18, paths.frontdoorStateFile))));
68341
68468
  }
68342
68469
  function allowlistOf(ports) {
68343
68470
  return currentHeadroomAllowlist(ports.fs, ports.paths);
@@ -68449,12 +68576,12 @@ function readInstalledHeadroomCommit() {
68449
68576
  if (toolDir.status !== 0) {
68450
68577
  return void 0;
68451
68578
  }
68452
- const libDir = import_node_path32.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
68579
+ const libDir = import_node_path33.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
68453
68580
  for (const python of realFarmFs.readdir(libDir)) {
68454
- const sitePackages = import_node_path32.default.join(libDir, python, "site-packages");
68581
+ const sitePackages = import_node_path33.default.join(libDir, python, "site-packages");
68455
68582
  for (const entry of realFarmFs.readdir(sitePackages)) {
68456
68583
  if (entry.startsWith("headroom_ai-") && entry.endsWith(".dist-info")) {
68457
- const directUrl = realFarmFs.readFileUtf8(import_node_path32.default.join(sitePackages, entry, "direct_url.json"));
68584
+ const directUrl = realFarmFs.readFileUtf8(import_node_path33.default.join(sitePackages, entry, "direct_url.json"));
68458
68585
  return directUrl === void 0 ? void 0 : parseInstalledCommit(directUrl);
68459
68586
  }
68460
68587
  }
@@ -68608,14 +68735,14 @@ function requireIdentity(paths, name) {
68608
68735
  throw new IdentityNotFoundError(name);
68609
68736
  }
68610
68737
  }
68611
- function collectUsageReport(fs17, paths, filters) {
68738
+ function collectUsageReport(fs18, paths, filters) {
68612
68739
  const { identity, provider, sinceMs } = filters;
68613
68740
  if (identity !== void 0) {
68614
68741
  requireIdentity(paths, identity);
68615
68742
  }
68616
- const log = readUsageLog(fs17, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
68743
+ const log = readUsageLog(fs18, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
68617
68744
  const records = log.records.filter((record2) => (identity === void 0 || record2.identity === identity) && (provider === void 0 || record2.provider === provider));
68618
- const snapshots = (identity === void 0 ? listUsageSnapshots(fs17, paths.usageSnapshotsDir) : [readUsageSnapshot(fs17, paths.usageSnapshotsDir, identity)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0);
68745
+ const snapshots = (identity === void 0 ? listUsageSnapshots(fs18, paths.usageSnapshotsDir) : [readUsageSnapshot(fs18, paths.usageSnapshotsDir, identity)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0);
68619
68746
  return {
68620
68747
  since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
68621
68748
  logDir: paths.usageLogDir,
@@ -68711,15 +68838,15 @@ function formatUsageReport(report) {
68711
68838
  }
68712
68839
  return lines;
68713
68840
  }
68714
- function collectAccounts(fs17, paths, identity) {
68841
+ function collectAccounts(fs18, paths, identity) {
68715
68842
  if (identity !== void 0) {
68716
68843
  requireIdentity(paths, identity);
68717
68844
  }
68718
68845
  const names = identity === void 0 ? listIdentities(paths).map((entry) => entry.name) : [identity];
68719
68846
  return names.map((name) => ({
68720
68847
  identity: name,
68721
- account: readAccountMetadata(fs17, paths.identitiesDir, name),
68722
- usage: readUsageSnapshot(fs17, paths.usageSnapshotsDir, name)
68848
+ account: readAccountMetadata(fs18, paths.identitiesDir, name),
68849
+ usage: readUsageSnapshot(fs18, paths.usageSnapshotsDir, name)
68723
68850
  }));
68724
68851
  }
68725
68852
  function formatAccounts(views) {
@@ -68886,7 +69013,7 @@ var import_node_crypto16 = require("node:crypto");
68886
69013
 
68887
69014
  // src/launcher.ts
68888
69015
  var import_node_crypto15 = require("node:crypto");
68889
- var import_node_path34 = __toESM(require("node:path"), 1);
69016
+ var import_node_path35 = __toESM(require("node:path"), 1);
68890
69017
 
68891
69018
  // src/launcher/cliOverride.ts
68892
69019
  var InvalidCliCategoryError = class extends CliError {
@@ -68970,7 +69097,7 @@ function buildCliOverride(params) {
68970
69097
  }
68971
69098
 
68972
69099
  // src/launcher/flags.ts
68973
- var import_node_path33 = __toESM(require("node:path"), 1);
69100
+ var import_node_path34 = __toESM(require("node:path"), 1);
68974
69101
 
68975
69102
  // src/headroom/headers.ts
68976
69103
  function mergeAnthropicCustomHeaders(existing, additions) {
@@ -69040,7 +69167,7 @@ function buildEnv(params) {
69040
69167
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
69041
69168
  let providerCustomHeaders;
69042
69169
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
69043
- env.CLAUDE_CONFIG_DIR = import_node_path33.default.join(params.identitiesDir, params.resolvedIdentityName);
69170
+ env.CLAUDE_CONFIG_DIR = import_node_path34.default.join(params.identitiesDir, params.resolvedIdentityName);
69044
69171
  }
69045
69172
  if (params.provider !== void 0) {
69046
69173
  const providerEnv = params.provider.definition.env ?? {};
@@ -69132,7 +69259,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
69132
69259
  return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
69133
69260
  }
69134
69261
  function pickFromPool(decided, params, parsedArgv) {
69135
- const { paths, fs: fs17, proc, log } = params;
69262
+ const { paths, fs: fs18, proc, log } = params;
69136
69263
  if (decided.pool === void 0) {
69137
69264
  return { identityDecision: decided };
69138
69265
  }
@@ -69146,7 +69273,7 @@ function pickFromPool(decided, params, parsedArgv) {
69146
69273
  selectedVia: decided.source,
69147
69274
  pools: params.pools,
69148
69275
  paths,
69149
- fs: fs17,
69276
+ fs: fs18,
69150
69277
  usageFs: farmRuntime.fs,
69151
69278
  cwd: farmRuntime.cwd,
69152
69279
  now: farmRuntime.now,
@@ -69162,7 +69289,7 @@ function pickFromPool(decided, params, parsedArgv) {
69162
69289
  return { identityDecision: { ...decided, name: resolution.identity }, poolExplanation: resolution.explanation };
69163
69290
  }
69164
69291
  function runLauncher(params) {
69165
- const { paths, fs: fs17, spawn: spawn3, proc, log } = params;
69292
+ const { paths, fs: fs18, spawn: spawn3, proc, log } = params;
69166
69293
  const { env, argv } = proc;
69167
69294
  const parsedArgv = parseLauncherArgv(argv);
69168
69295
  const cliOverride = buildCliOverride({
@@ -69177,7 +69304,7 @@ function runLauncher(params) {
69177
69304
  argv0Identity: parsedArgv.identity,
69178
69305
  directoryPinnedIdentity: params.directoryPinnedIdentity,
69179
69306
  readActiveIdentityFile: () => {
69180
- const raw = fs17.readFileUtf8(paths.activeIdentityFile);
69307
+ const raw = fs18.readFileUtf8(paths.activeIdentityFile);
69181
69308
  if (raw === void 0) {
69182
69309
  return void 0;
69183
69310
  }
@@ -69212,7 +69339,7 @@ function runLauncher(params) {
69212
69339
  }
69213
69340
  let loadedIdentity;
69214
69341
  if (identityDecision.name !== void 0) {
69215
- loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs17);
69342
+ loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs18);
69216
69343
  if (loadedIdentity === void 0) {
69217
69344
  log.error(
69218
69345
  `agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
@@ -69227,7 +69354,7 @@ function runLauncher(params) {
69227
69354
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
69228
69355
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
69229
69356
  });
69230
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs17.readConfigFile(import_node_path34.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
69357
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs18.readConfigFile(import_node_path35.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
69231
69358
  log.error(
69232
69359
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
69233
69360
  );
@@ -69236,7 +69363,7 @@ function runLauncher(params) {
69236
69363
  const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
69237
69364
  const provider = parsedArgv.provider === false ? void 0 : resolveProvider({
69238
69365
  paths,
69239
- port: fs17,
69366
+ port: fs18,
69240
69367
  env,
69241
69368
  ...params.credentials === void 0 ? {} : { credentials: params.credentials },
69242
69369
  ...parsedArgv.provider === void 0 ? {} : { cliProvider: parsedArgv.provider },
@@ -69520,7 +69647,7 @@ async function runClaude(argvOverride) {
69520
69647
  // src/cli.ts
69521
69648
  async function main() {
69522
69649
  aliasLegacyEnv(process.env);
69523
- const invokedName = import_node_path35.default.basename(process.argv[1] ?? "agent-shim");
69650
+ const invokedName = import_node_path36.default.basename(process.argv[1] ?? "agent-shim");
69524
69651
  if (isInvokedAsClaude(invokedName)) {
69525
69652
  await runClaude();
69526
69653
  return;