claude-use 7.13.2 → 8.0.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 path40 = require("path");
3251
+ var path41 = 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 = path40.join(homedir, "Library");
3257
+ const library = path41.join(homedir, "Library");
3258
3258
  return {
3259
- data: path40.join(library, "Application Support", name),
3260
- config: path40.join(library, "Preferences", name),
3261
- cache: path40.join(library, "Caches", name),
3262
- log: path40.join(library, "Logs", name),
3263
- temp: path40.join(tmpdir, name)
3259
+ data: path41.join(library, "Application Support", name),
3260
+ config: path41.join(library, "Preferences", name),
3261
+ cache: path41.join(library, "Caches", name),
3262
+ log: path41.join(library, "Logs", name),
3263
+ temp: path41.join(tmpdir, name)
3264
3264
  };
3265
3265
  };
3266
3266
  var windows = (name) => {
3267
- const appData = env.APPDATA || path40.join(homedir, "AppData", "Roaming");
3268
- const localAppData = env.LOCALAPPDATA || path40.join(homedir, "AppData", "Local");
3267
+ const appData = env.APPDATA || path41.join(homedir, "AppData", "Roaming");
3268
+ const localAppData = env.LOCALAPPDATA || path41.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: path40.join(localAppData, name, "Data"),
3272
- config: path40.join(appData, name, "Config"),
3273
- cache: path40.join(localAppData, name, "Cache"),
3274
- log: path40.join(localAppData, name, "Log"),
3275
- temp: path40.join(tmpdir, name)
3271
+ data: path41.join(localAppData, name, "Data"),
3272
+ config: path41.join(appData, name, "Config"),
3273
+ cache: path41.join(localAppData, name, "Cache"),
3274
+ log: path41.join(localAppData, name, "Log"),
3275
+ temp: path41.join(tmpdir, name)
3276
3276
  };
3277
3277
  };
3278
3278
  var linux = (name) => {
3279
- const username = path40.basename(homedir);
3279
+ const username = path41.basename(homedir);
3280
3280
  return {
3281
- data: path40.join(env.XDG_DATA_HOME || path40.join(homedir, ".local", "share"), name),
3282
- config: path40.join(env.XDG_CONFIG_HOME || path40.join(homedir, ".config"), name),
3283
- cache: path40.join(env.XDG_CACHE_HOME || path40.join(homedir, ".cache"), name),
3281
+ data: path41.join(env.XDG_DATA_HOME || path41.join(homedir, ".local", "share"), name),
3282
+ config: path41.join(env.XDG_CONFIG_HOME || path41.join(homedir, ".config"), name),
3283
+ cache: path41.join(env.XDG_CACHE_HOME || path41.join(homedir, ".cache"), name),
3284
3284
  // https://wiki.debian.org/XDGBaseDirectorySpecification#state
3285
- log: path40.join(env.XDG_STATE_HOME || path40.join(homedir, ".local", "state"), name),
3286
- temp: path40.join(tmpdir, username, name)
3285
+ log: path41.join(env.XDG_STATE_HOME || path41.join(homedir, ".local", "state"), name),
3286
+ temp: path41.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, path40) {
3355
- if (typeof path40 === "string" && Object.prototype.hasOwnProperty.call(source, path40)) {
3356
- return source[path40];
3354
+ function getPropertyByPath(source, path41) {
3355
+ if (typeof path41 === "string" && Object.prototype.hasOwnProperty.call(source, path41)) {
3356
+ return source[path41];
3357
3357
  }
3358
- const parsedPath = typeof path40 === "string" ? path40.split(".") : path40;
3358
+ const parsedPath = typeof path41 === "string" ? path41.split(".") : path41;
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(path40) {
3381
+ async function isDirectory(path41) {
3382
3382
  try {
3383
- const stat = await fs_1.promises.stat(path40);
3383
+ const stat = await fs_1.promises.stat(path41);
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(path40) {
3393
+ function isDirectorySync(path41) {
3394
3394
  try {
3395
- const stat = fs_1.default.statSync(path40);
3395
+ const stat = fs_1.default.statSync(path41);
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((path40, i2) => `${i2 + 1}. ${path40}`).join("\n")} (same as ${idx + 1}.)`);
3493
+ ${[...importStack, fullPath].map((path41, i2) => `${i2 + 1}. ${path41}`).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(path40) {
3681
+ async #fileExists(path41) {
3682
3682
  try {
3683
- await promises_1.default.stat(path40);
3683
+ await promises_1.default.stat(path41);
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(path40) {
3843
+ #fileExists(path41) {
3844
3844
  try {
3845
- fs_1.default.statSync(path40);
3845
+ fs_1.default.statSync(path41);
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((path40) => path40.replace("{name}", moduleName));
3969
+ const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path41) => path41.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 = (path40, { windows } = {}) => {
4378
- const segs = path40.split(windows ? /[\\/]/ : "/");
4377
+ exports2.basename = (path41, { windows } = {}) => {
4378
+ const segs = path41.split(windows ? /[\\/]/ : "/");
4379
4379
  const last = segs[segs.length - 1];
4380
4380
  if (last === "") {
4381
4381
  return segs[segs.length - 2];
@@ -6891,7 +6891,7 @@ var require_util2 = __commonJS({
6891
6891
  var { kDestroyed, kBodyUsed, kListeners, kBody } = require_symbols();
6892
6892
  var { IncomingMessage } = require("node:http");
6893
6893
  var stream = require("node:stream");
6894
- var net5 = require("node:net");
6894
+ var net3 = require("node:net");
6895
6895
  var { stringify } = require("node:querystring");
6896
6896
  var { EventEmitter: EE } = require("node:events");
6897
6897
  var timers = require_timers();
@@ -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 path40 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
7006
+ let path41 = 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 (path40 && path40[0] !== "/") {
7011
- path40 = `/${path40}`;
7010
+ if (path41 && path41[0] !== "/") {
7011
+ path41 = `/${path41}`;
7012
7012
  }
7013
- return new URL(`${origin}${path40}`);
7013
+ return new URL(`${origin}${path41}`);
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:`.");
@@ -7040,7 +7040,7 @@ var require_util2 = __commonJS({
7040
7040
  }
7041
7041
  assert2(typeof host === "string");
7042
7042
  const servername = getHostname(host);
7043
- if (net5.isIP(servername)) {
7043
+ if (net3.isIP(servername)) {
7044
7044
  return "";
7045
7045
  }
7046
7046
  return servername;
@@ -7831,9 +7831,9 @@ var require_diagnostics = __commonJS({
7831
7831
  "undici:client:sendHeaders",
7832
7832
  (evt) => {
7833
7833
  const {
7834
- request: { method, path: path40, origin }
7834
+ request: { method, path: path41, origin }
7835
7835
  } = evt;
7836
- debugLog("sending request to %s %s%s", method, origin, path40);
7836
+ debugLog("sending request to %s %s%s", method, origin, path41);
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: path40, origin },
7854
+ request: { method, path: path41, 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
- path40,
7861
+ path41,
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: path40, origin }
7870
+ request: { method, path: path41, origin }
7871
7871
  } = evt;
7872
- debugLog("trailers received from %s %s%s", method, origin, path40);
7872
+ debugLog("trailers received from %s %s%s", method, origin, path41);
7873
7873
  }
7874
7874
  );
7875
7875
  diagnosticsChannel.subscribe(
7876
7876
  "undici:request:error",
7877
7877
  (evt) => {
7878
7878
  const {
7879
- request: { method, path: path40, origin },
7879
+ request: { method, path: path41, 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
- path40,
7886
+ path41,
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: path40,
8001
+ path: path41,
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 path40 !== "string") {
8018
+ if (typeof path41 !== "string") {
8019
8019
  throw new InvalidArgumentError2("path must be a string");
8020
- } else if (path40[0] !== "/" && !(path40.startsWith("http://") || path40.startsWith("https://")) && method !== "CONNECT") {
8020
+ } else if (path41[0] !== "/" && !(path41.startsWith("http://") || path41.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(path40)) {
8022
+ } else if (invalidPathRegex.test(path41)) {
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(path40, query) : path40;
8097
+ this.path = query ? serializePathWithQuery(path41, query) : path41;
8098
8098
  this.origin = origin;
8099
8099
  this.protocol = getProtocolFromUrlString(origin);
8100
8100
  this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
@@ -8703,7 +8703,7 @@ var require_dispatcher_base = __commonJS({
8703
8703
  var require_connect = __commonJS({
8704
8704
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/core/connect.js"(exports2, module2) {
8705
8705
  "use strict";
8706
- var net5 = require("node:net");
8706
+ var net3 = require("node:net");
8707
8707
  var assert2 = require("node:assert");
8708
8708
  var util = require_util2();
8709
8709
  var { InvalidArgumentError: InvalidArgumentError2 } = require_errors();
@@ -8786,7 +8786,7 @@ var require_connect = __commonJS({
8786
8786
  } else {
8787
8787
  assert2(!httpSocket, "httpSocket can only be sent on TLS update");
8788
8788
  port = port || 80;
8789
- socket = net5.connect({
8789
+ socket = net3.connect({
8790
8790
  highWaterMark: 64 * 1024,
8791
8791
  // Same as nodejs fs streams.
8792
8792
  ...options,
@@ -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: path40, host, upgrade, blocking, reset } = request6;
13279
+ const { method, path: path41, 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} ${path40} HTTP/1.1\r
13357
+ let header = `${method} ${path41} 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: path40, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request6;
14036
+ const { method, path: path41, 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] = path40;
14105
+ headers[HTTP2_HEADER_PATH] = path41;
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] = path40;
14147
+ headers[HTTP2_HEADER_PATH] = path41;
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") {
@@ -14463,8 +14463,8 @@ var require_client = __commonJS({
14463
14463
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/dispatcher/client.js"(exports2, module2) {
14464
14464
  "use strict";
14465
14465
  var assert2 = require("node:assert");
14466
- var net5 = require("node:net");
14467
- var http5 = require("node:http");
14466
+ var net3 = require("node:net");
14467
+ var http6 = require("node:http");
14468
14468
  var util = require_util2();
14469
14469
  var { ClientStats } = require_stats();
14470
14470
  var { channels } = require_diagnostics();
@@ -14522,7 +14522,7 @@ var require_client = __commonJS({
14522
14522
  var connectH1 = require_client_h1();
14523
14523
  var connectH2 = require_client_h2();
14524
14524
  var kClosedResolve = /* @__PURE__ */ Symbol("kClosedResolve");
14525
- var getDefaultNodeMaxHeaderSize = http5 && http5.maxHeaderSize && Number.isInteger(http5.maxHeaderSize) && http5.maxHeaderSize > 0 ? () => http5.maxHeaderSize : () => {
14525
+ var getDefaultNodeMaxHeaderSize = http6 && http6.maxHeaderSize && Number.isInteger(http6.maxHeaderSize) && http6.maxHeaderSize > 0 ? () => http6.maxHeaderSize : () => {
14526
14526
  throw new InvalidArgumentError2("http module not available or http.maxHeaderSize invalid");
14527
14527
  };
14528
14528
  var noop = () => {
@@ -14618,7 +14618,7 @@ var require_client = __commonJS({
14618
14618
  if (maxRequestsPerClient != null && (!Number.isInteger(maxRequestsPerClient) || maxRequestsPerClient < 0)) {
14619
14619
  throw new InvalidArgumentError2("maxRequestsPerClient must be a positive number");
14620
14620
  }
14621
- if (localAddress != null && (typeof localAddress !== "string" || net5.isIP(localAddress) === 0)) {
14621
+ if (localAddress != null && (typeof localAddress !== "string" || net3.isIP(localAddress) === 0)) {
14622
14622
  throw new InvalidArgumentError2("localAddress must be valid string IP address");
14623
14623
  }
14624
14624
  if (maxResponseSize != null && (!Number.isInteger(maxResponseSize) || maxResponseSize < -1)) {
@@ -14798,7 +14798,7 @@ var require_client = __commonJS({
14798
14798
  const idx = hostname3.indexOf("]");
14799
14799
  assert2(idx !== -1);
14800
14800
  const ip = hostname3.substring(1, idx);
14801
- assert2(net5.isIPv6(ip));
14801
+ assert2(net3.isIPv6(ip));
14802
14802
  hostname3 = ip;
14803
14803
  }
14804
14804
  client[kConnecting] = true;
@@ -15625,7 +15625,7 @@ var require_agent = __commonJS({
15625
15625
  function defaultFactory(origin, opts) {
15626
15626
  return opts && opts.connections === 1 ? new Client(origin, opts) : new Pool(origin, opts);
15627
15627
  }
15628
- var Agent7 = class extends DispatcherBase {
15628
+ var Agent5 = class extends DispatcherBase {
15629
15629
  constructor({ factory = defaultFactory, maxOrigins = Infinity, connect: connect3, ...options } = {}) {
15630
15630
  if (typeof factory !== "function") {
15631
15631
  throw new InvalidArgumentError2("factory must be a function.");
@@ -15734,7 +15734,7 @@ var require_agent = __commonJS({
15734
15734
  return allClientStats;
15735
15735
  }
15736
15736
  };
15737
- module2.exports = Agent7;
15737
+ module2.exports = Agent5;
15738
15738
  }
15739
15739
  });
15740
15740
 
@@ -15743,10 +15743,10 @@ var require_socks5_utils = __commonJS({
15743
15743
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/core/socks5-utils.js"(exports2, module2) {
15744
15744
  "use strict";
15745
15745
  var { Buffer: Buffer2 } = require("node:buffer");
15746
- var net5 = require("node:net");
15746
+ var net3 = require("node:net");
15747
15747
  var { InvalidArgumentError: InvalidArgumentError2 } = require_errors();
15748
15748
  function parseAddress(address) {
15749
- if (net5.isIPv4(address)) {
15749
+ if (net3.isIPv4(address)) {
15750
15750
  const parts = address.split(".").map(Number);
15751
15751
  return {
15752
15752
  type: 1,
@@ -15754,7 +15754,7 @@ var require_socks5_utils = __commonJS({
15754
15754
  buffer: Buffer2.from(parts)
15755
15755
  };
15756
15756
  }
15757
- if (net5.isIPv6(address)) {
15757
+ if (net3.isIPv6(address)) {
15758
15758
  return {
15759
15759
  type: 4,
15760
15760
  // IPv6
@@ -15777,7 +15777,7 @@ var require_socks5_utils = __commonJS({
15777
15777
  if (address.includes(".")) {
15778
15778
  const lastColonIndex = address.lastIndexOf(":");
15779
15779
  const ipv4Part = address.slice(lastColonIndex + 1);
15780
- if (net5.isIPv4(ipv4Part)) {
15780
+ if (net3.isIPv4(ipv4Part)) {
15781
15781
  const octets = ipv4Part.split(".").map(Number);
15782
15782
  const high = (octets[0] << 8 | octets[1]).toString(16);
15783
15783
  const low = (octets[2] << 8 | octets[3]).toString(16);
@@ -16440,7 +16440,7 @@ var require_proxy_agent = __commonJS({
16440
16440
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/dispatcher/proxy-agent.js"(exports2, module2) {
16441
16441
  "use strict";
16442
16442
  var { kProxy, kClose, kDestroy, kDispatch } = require_symbols();
16443
- var Agent7 = require_agent();
16443
+ var Agent5 = require_agent();
16444
16444
  var Pool = require_pool();
16445
16445
  var DispatcherBase = require_dispatcher_base();
16446
16446
  var { InvalidArgumentError: InvalidArgumentError2, RequestAbortedError, SecureProxyConnectionError } = require_errors();
@@ -16496,10 +16496,10 @@ var require_proxy_agent = __commonJS({
16496
16496
  };
16497
16497
  const {
16498
16498
  origin,
16499
- path: path40 = "/",
16499
+ path: path41 = "/",
16500
16500
  headers = {}
16501
16501
  } = opts;
16502
- opts.path = origin + path40;
16502
+ opts.path = origin + path41;
16503
16503
  if (!("host" in headers) && !("Host" in headers)) {
16504
16504
  const { host } = new URL(origin);
16505
16505
  headers.host = host;
@@ -16571,7 +16571,7 @@ var require_proxy_agent = __commonJS({
16571
16571
  } else {
16572
16572
  this[kClient] = clientFactory(url2, { connect: connect3 });
16573
16573
  }
16574
- this[kAgent] = new Agent7({
16574
+ this[kAgent] = new Agent5({
16575
16575
  ...opts,
16576
16576
  factory,
16577
16577
  connect: async (opts2, callback) => {
@@ -16699,7 +16699,7 @@ var require_env_http_proxy_agent = __commonJS({
16699
16699
  var DispatcherBase = require_dispatcher_base();
16700
16700
  var { kClose, kDestroy, kClosed, kDestroyed, kDispatch, kNoProxyAgent, kHttpProxyAgent, kHttpsProxyAgent } = require_symbols();
16701
16701
  var ProxyAgent = require_proxy_agent();
16702
- var Agent7 = require_agent();
16702
+ var Agent5 = require_agent();
16703
16703
  var DEFAULT_PORTS = {
16704
16704
  "http:": 80,
16705
16705
  "https:": 443
@@ -16712,7 +16712,7 @@ var require_env_http_proxy_agent = __commonJS({
16712
16712
  super();
16713
16713
  this.#opts = opts;
16714
16714
  const { httpProxy, httpsProxy, noProxy, ...agentOpts } = opts;
16715
- this[kNoProxyAgent] = new Agent7(agentOpts);
16715
+ this[kNoProxyAgent] = new Agent5(agentOpts);
16716
16716
  const HTTP_PROXY = httpProxy ?? process.env.http_proxy ?? process.env.HTTP_PROXY;
16717
16717
  if (HTTP_PROXY) {
16718
16718
  this[kHttpProxyAgent] = new ProxyAgent({ ...agentOpts, uri: HTTP_PROXY });
@@ -18608,20 +18608,20 @@ var require_mock_utils = __commonJS({
18608
18608
  }
18609
18609
  return normalizedQp;
18610
18610
  }
18611
- function safeUrl(path40) {
18612
- if (typeof path40 !== "string") {
18613
- return path40;
18611
+ function safeUrl(path41) {
18612
+ if (typeof path41 !== "string") {
18613
+ return path41;
18614
18614
  }
18615
- const pathSegments = path40.split("?", 3);
18615
+ const pathSegments = path41.split("?", 3);
18616
18616
  if (pathSegments.length !== 2) {
18617
- return path40;
18617
+ return path41;
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: path40, method, body, headers }) {
18624
- const pathMatch = matchValue(mockDispatch2.path, path40);
18623
+ function matchKey(mockDispatch2, { path: path41, method, body, headers }) {
18624
+ const pathMatch = matchValue(mockDispatch2.path, path41);
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: path40, ignoreTrailingSlash }) => {
18650
- return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path40)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path40), resolvedPath);
18649
+ let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path41, ignoreTrailingSlash }) => {
18650
+ return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path41)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path41), 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(path40) {
18690
- while (path40.endsWith("/")) {
18691
- path40 = path40.slice(0, -1);
18689
+ function removeTrailingSlash(path41) {
18690
+ while (path41.endsWith("/")) {
18691
+ path41 = path41.slice(0, -1);
18692
18692
  }
18693
- if (path40.length === 0) {
18694
- path40 = "/";
18693
+ if (path41.length === 0) {
18694
+ path41 = "/";
18695
18695
  }
18696
- return path40;
18696
+ return path41;
18697
18697
  }
18698
18698
  function buildKey(opts) {
18699
- const { path: path40, method, body, headers, query } = opts;
18699
+ const { path: path41, method, body, headers, query } = opts;
18700
18700
  return {
18701
- path: path40,
18701
+ path: path41,
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: path40, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
19391
+ ({ method, path: path41, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
19392
19392
  Method: method,
19393
19393
  Origin: origin,
19394
- Path: path40,
19394
+ Path: path41,
19395
19395
  "Status code": statusCode,
19396
19396
  Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
19397
19397
  Invocations: timesInvoked,
@@ -19410,7 +19410,7 @@ var require_mock_agent = __commonJS({
19410
19410
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/mock/mock-agent.js"(exports2, module2) {
19411
19411
  "use strict";
19412
19412
  var { kClients } = require_symbols();
19413
- var Agent7 = require_agent();
19413
+ var Agent5 = require_agent();
19414
19414
  var {
19415
19415
  kAgent,
19416
19416
  kMockAgentSet,
@@ -19448,7 +19448,7 @@ var require_mock_agent = __commonJS({
19448
19448
  if (opts?.agent && typeof opts.agent.dispatch !== "function") {
19449
19449
  throw new InvalidArgumentError2("Argument opts.agent must implement Agent");
19450
19450
  }
19451
- const agent = opts?.agent ? opts.agent : new Agent7(opts);
19451
+ const agent = opts?.agent ? opts.agent : new Agent5(opts);
19452
19452
  this[kAgent] = agent;
19453
19453
  this[kClients] = agent[kClients];
19454
19454
  this[kOptions] = mockOptions;
@@ -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 [path40, searchParams] = dispatchOpts.path.split("?");
19476
+ const [path41, searchParams] = dispatchOpts.path.split("?");
19477
19477
  const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
19478
- dispatchOpts.path = `${path40}?${normalizedSearchParams}`;
19478
+ dispatchOpts.path = `${path41}?${normalizedSearchParams}`;
19479
19479
  }
19480
19480
  return this[kAgent].dispatch(dispatchOpts, handler);
19481
19481
  }
@@ -19876,12 +19876,12 @@ var require_snapshot_recorder = __commonJS({
19876
19876
  * @return {Promise<void>} - Resolves when snapshots are loaded
19877
19877
  */
19878
19878
  async loadSnapshots(filePath) {
19879
- const path40 = filePath || this.#snapshotPath;
19880
- if (!path40) {
19879
+ const path41 = filePath || this.#snapshotPath;
19880
+ if (!path41) {
19881
19881
  throw new InvalidArgumentError2("Snapshot path is required");
19882
19882
  }
19883
19883
  try {
19884
- const data = await readFile(resolve(path40), "utf8");
19884
+ const data = await readFile(resolve(path41), "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 ${path40}`, { cause: error62 });
19898
+ throw new UndiciError(`Failed to load snapshots from ${path41}`, { cause: error62 });
19899
19899
  }
19900
19900
  }
19901
19901
  }
@@ -19906,11 +19906,11 @@ var require_snapshot_recorder = __commonJS({
19906
19906
  * @returns {Promise<void>} - Resolves when snapshots are saved
19907
19907
  */
19908
19908
  async saveSnapshots(filePath) {
19909
- const path40 = filePath || this.#snapshotPath;
19910
- if (!path40) {
19909
+ const path41 = filePath || this.#snapshotPath;
19910
+ if (!path41) {
19911
19911
  throw new InvalidArgumentError2("Snapshot path is required");
19912
19912
  }
19913
- const resolvedPath = resolve(path40);
19913
+ const resolvedPath = resolve(path41);
19914
19914
  await mkdir(dirname2(resolvedPath), { recursive: true });
19915
19915
  const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
19916
19916
  hash: hash2,
@@ -20055,7 +20055,7 @@ var require_snapshot_recorder = __commonJS({
20055
20055
  var require_snapshot_agent = __commonJS({
20056
20056
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/mock/snapshot-agent.js"(exports2, module2) {
20057
20057
  "use strict";
20058
- var Agent7 = require_agent();
20058
+ var Agent5 = require_agent();
20059
20059
  var MockAgent = require_mock_agent();
20060
20060
  var { SnapshotRecorder } = require_snapshot_recorder();
20061
20061
  var WrapHandler = require_wrap_handler();
@@ -20106,7 +20106,7 @@ var require_snapshot_agent = __commonJS({
20106
20106
  });
20107
20107
  this[kSnapshotLoaded] = false;
20108
20108
  if (this[kSnapshotMode] === "record" || this[kSnapshotMode] === "update" || this[kSnapshotMode] === "playback" && opts.excludeUrls && opts.excludeUrls.length > 0) {
20109
- this[kRealAgent] = new Agent7(opts);
20109
+ this[kRealAgent] = new Agent5(opts);
20110
20110
  }
20111
20111
  if ((this[kSnapshotMode] === "playback" || this[kSnapshotMode] === "update") && this[kSnapshotPath]) {
20112
20112
  this.loadSnapshots().catch(() => {
@@ -20345,9 +20345,9 @@ var require_global2 = __commonJS({
20345
20345
  var globalDispatcher = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.2");
20346
20346
  var legacyGlobalDispatcher = /* @__PURE__ */ Symbol.for("undici.globalDispatcher.1");
20347
20347
  var { InvalidArgumentError: InvalidArgumentError2 } = require_errors();
20348
- var Agent7 = require_agent();
20348
+ var Agent5 = require_agent();
20349
20349
  if (getGlobalDispatcher() === void 0) {
20350
- setGlobalDispatcher(new Agent7());
20350
+ setGlobalDispatcher(new Agent5());
20351
20351
  }
20352
20352
  function setGlobalDispatcher(agent) {
20353
20353
  if (!agent || typeof agent.dispatch !== "function") {
@@ -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 path40 = search ? `${pathname}${search}` : pathname;
20546
- const redirectUrlString = `${origin}${path40}`;
20545
+ const path41 = search ? `${pathname}${search}` : pathname;
20546
+ const redirectUrlString = `${origin}${path41}`;
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 = path40;
20553
+ this.opts.path = path41;
20554
20554
  this.opts.origin = origin;
20555
20555
  this.opts.query = null;
20556
20556
  }
@@ -20817,7 +20817,7 @@ var require_dump = __commonJS({
20817
20817
  var require_dns = __commonJS({
20818
20818
  "node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/interceptor/dns.js"(exports2, module2) {
20819
20819
  "use strict";
20820
- var { isIP } = require("node:net");
20820
+ var { isIP: isIP2 } = require("node:net");
20821
20821
  var { lookup } = require("node:dns");
20822
20822
  var DecoratorHandler = require_decorator_handler();
20823
20823
  var { InvalidArgumentError: InvalidArgumentError2, InformationalError } = require_errors();
@@ -21223,7 +21223,7 @@ var require_dns = __commonJS({
21223
21223
  return (dispatch) => {
21224
21224
  return function dnsInterceptor(origDispatchOpts, handler) {
21225
21225
  const origin = origDispatchOpts.origin.constructor === URL ? origDispatchOpts.origin : new URL(origDispatchOpts.origin);
21226
- if (isIP(origin.hostname) !== 0) {
21226
+ if (isIP2(origin.hostname) !== 0) {
21227
21227
  return dispatch(origDispatchOpts, handler);
21228
21228
  }
21229
21229
  instance.runLookup(origin, origDispatchOpts, (err, newOrigin) => {
@@ -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, path40) {
22313
+ function deleteCachedUri(store, cacheKey, path41) {
22314
22314
  deleteCachedValue(store, {
22315
22315
  ...cacheKey,
22316
- path: path40
22316
+ path: path41
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: path40
22324
+ path: path41
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 path40 = getSameOriginPath(cacheKey, values[i2]);
22336
- if (path40 !== void 0) {
22337
- deleteCachedUri(store, cacheKey, path40);
22335
+ const path41 = getSameOriginPath(cacheKey, values[i2]);
22336
+ if (path41 !== void 0) {
22337
+ deleteCachedUri(store, cacheKey, path41);
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 path40 = url2.pathname + url2.search;
27337
+ const path41 = 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 ? `${path40}?` : path40,
27341
+ path: hasTrailingQuestionMark ? `${path41}?` : path41,
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(path40) {
28289
- for (let i2 = 0; i2 < path40.length; ++i2) {
28290
- const code = path40.charCodeAt(i2);
28288
+ function validateCookiePath(path41) {
28289
+ for (let i2 = 0; i2 < path41.length; ++i2) {
28290
+ const code = path41.charCodeAt(i2);
28291
28291
  if (code < 32 || // exclude CTLs (0-31)
28292
28292
  code > 126 || // exclude DEL and non-ascii
28293
28293
  code === 59) {
@@ -31562,7 +31562,7 @@ var require_undici = __commonJS({
31562
31562
  var Pool = require_pool();
31563
31563
  var BalancedPool = require_balanced_pool();
31564
31564
  var RoundRobinPool = require_round_robin_pool();
31565
- var Agent7 = require_agent();
31565
+ var Agent5 = require_agent();
31566
31566
  var ProxyAgent = require_proxy_agent();
31567
31567
  var Socks5ProxyAgent = require_socks5_proxy_agent();
31568
31568
  var EnvHttpProxyAgent = require_env_http_proxy_agent();
@@ -31589,7 +31589,7 @@ var require_undici = __commonJS({
31589
31589
  module2.exports.Pool = Pool;
31590
31590
  module2.exports.BalancedPool = BalancedPool;
31591
31591
  module2.exports.RoundRobinPool = RoundRobinPool;
31592
- module2.exports.Agent = Agent7;
31592
+ module2.exports.Agent = Agent5;
31593
31593
  module2.exports.ProxyAgent = ProxyAgent;
31594
31594
  module2.exports.Socks5ProxyAgent = Socks5ProxyAgent;
31595
31595
  module2.exports.EnvHttpProxyAgent = EnvHttpProxyAgent;
@@ -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 path40 = opts.path;
31638
+ let path41 = opts.path;
31639
31639
  if (!opts.path.startsWith("/")) {
31640
- path40 = `/${path40}`;
31640
+ path41 = `/${path41}`;
31641
31641
  }
31642
- url2 = new URL(util.parseOrigin(url2).origin + path40);
31642
+ url2 = new URL(util.parseOrigin(url2).origin + path41);
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_path38 = __toESM(require("node:path"), 1);
31752
+ var import_node_path39 = __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(path40) {
34866
- if (path40 === void 0) return this._executableDir;
34867
- this._executableDir = path40;
34865
+ executableDir(path41) {
34866
+ if (path41 === void 0) return this._executableDir;
34867
+ this._executableDir = path41;
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, path40) {
36006
- if (!path40)
36005
+ function getElementAtPath(obj, path41) {
36006
+ if (!path41)
36007
36007
  return obj;
36008
- return path40.reduce((acc, key) => acc?.[key], obj);
36008
+ return path41.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(path40, issues) {
36348
+ function prefixIssues(path41, issues) {
36349
36349
  return issues.map((iss) => {
36350
36350
  var _a3;
36351
36351
  (_a3 = iss).path ?? (_a3.path = []);
36352
- iss.path.unshift(path40);
36352
+ iss.path.unshift(path41);
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, path40 = []) => {
36802
+ const processError = (error63, path41 = []) => {
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 }, [...path40, ...issue2.path]));
36805
+ issue2.errors.map((issues) => processError({ issues }, [...path41, ...issue2.path]));
36806
36806
  } else if (issue2.code === "invalid_key") {
36807
- processError({ issues: issue2.issues }, [...path40, ...issue2.path]);
36807
+ processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36808
36808
  } else if (issue2.code === "invalid_element") {
36809
- processError({ issues: issue2.issues }, [...path40, ...issue2.path]);
36809
+ processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36810
36810
  } else {
36811
- const fullpath = [...path40, ...issue2.path];
36811
+ const fullpath = [...path41, ...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, path40 = []) => {
36850
+ const processError = (error63, path41 = []) => {
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 }, [...path40, ...issue2.path]));
36854
+ issue2.errors.map((issues) => processError({ issues }, [...path41, ...issue2.path]));
36855
36855
  } else if (issue2.code === "invalid_key") {
36856
- processError({ issues: issue2.issues }, [...path40, ...issue2.path]);
36856
+ processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36857
36857
  } else if (issue2.code === "invalid_element") {
36858
- processError({ issues: issue2.issues }, [...path40, ...issue2.path]);
36858
+ processError({ issues: issue2.issues }, [...path41, ...issue2.path]);
36859
36859
  } else {
36860
- const fullpath = [...path40, ...issue2.path];
36860
+ const fullpath = [...path41, ...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 path40 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
36900
- for (const seg of path40) {
36899
+ const path41 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
36900
+ for (const seg of path41) {
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 path40 = ref.slice(1).split("/").filter(Boolean);
54003
- if (path40.length === 0) {
54002
+ const path41 = ref.slice(1).split("/").filter(Boolean);
54003
+ if (path41.length === 0) {
54004
54004
  return ctx.rootSchema;
54005
54005
  }
54006
54006
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
54007
- if (path40[0] === defsKey) {
54008
- const key = path40[1] === void 0 ? void 0 : decodeJSONPointerSegment(path40[1]);
54007
+ if (path41[0] === defsKey) {
54008
+ const key = path41[1] === void 0 ? void 0 : decodeJSONPointerSegment(path41[1]);
54009
54009
  if (!key || !ctx.defs[key]) {
54010
54010
  throw new Error(`Reference not found: ${ref}`);
54011
54011
  }
@@ -55052,7 +55052,6 @@ function applyPatch(filePath, schema, patch, options = {}) {
55052
55052
  var import_node_child_process2 = require("node:child_process");
55053
55053
  var import_node_crypto3 = require("node:crypto");
55054
55054
  var import_node_fs3 = __toESM(require("node:fs"), 1);
55055
- var import_node_net = __toESM(require("node:net"), 1);
55056
55055
  var import_node_os2 = __toESM(require("node:os"), 1);
55057
55056
  var import_node_path6 = __toESM(require("node:path"), 1);
55058
55057
  var import_node_sea = require("node:sea");
@@ -55324,7 +55323,7 @@ var HeadroomGlobalConfigSchema = HeadroomGlobalConfigObjectSchema.superRefine((c
55324
55323
  context.addIssue({ code: "custom", path: ["readMaturation"], message: "readMaturation needs rolloutChannel beta or dev" });
55325
55324
  }
55326
55325
  });
55327
- var HEADROOM_DEFAULT_SOURCE = "headroom-ai[proxy] @ git+https://github.com/ExaDev/headroom@ecd1c351fcfed97499721e86852e148436ff2ee6";
55326
+ var HEADROOM_DEFAULT_SOURCE = "headroom-ai[proxy] @ git+https://github.com/ExaDev/headroom@53525f479f2f48e8ef6b08cf729601feab7d2382";
55328
55327
  var HEADROOM_DEFAULT_IDLE_SHUTDOWN_MINUTES = 15;
55329
55328
  var FRONTDOOR_DEFAULT_IDLE_SHUTDOWN_MINUTES = 15;
55330
55329
  var FrontDoorGlobalConfigSchema = external_exports.strictObject({
@@ -55375,17 +55374,16 @@ var SHIPPED_CATEGORY_DEFAULTS = Object.freeze({
55375
55374
 
55376
55375
  // src/headroom/state.ts
55377
55376
  var HEADROOM_ANTHROPIC_UPSTREAM = "https://api.anthropic.com";
55377
+ var HEADROOM_STATE_SCHEMA_VERSION = 2;
55378
55378
  var HeadroomStateSchema = external_exports.strictObject({
55379
55379
  /** The supervisor process owning the daemon. Alive means someone is keeping headroom running. */
55380
55380
  supervisorPid: external_exports.number().int().positive().optional(),
55381
55381
  /** The headroom proxy process itself. Absent while the supervisor is between restarts. */
55382
55382
  headroomPid: external_exports.number().int().positive().optional(),
55383
- /** The loopback port the proxy listens on. Absent until the proxy has passed its readiness check, so "port is set" is itself the ready signal a launcher polls for. */
55384
- port: external_exports.number().int().positive().optional(),
55385
55383
  /**
55386
- * The sticky port preference: the address the daemon last served on, kept across crashes, restarts, and idle shutdowns so the next start reuses it. Distinct from `port` on purpose: `port` is the ready signal (absent whenever nothing is serving), while `lastPort` survives every shutdown, because the front door (which routes sessions through this daemon) reads it live and follows a restart to whichever address it lands on.
55384
+ * The unix socket the proxy serves on, inside the owner-only socket directory. Absent until the proxy has passed its readiness check, so "socketPath is set" is itself the ready signal a launcher polls for. The front door reads it on every hop, so a restart (which keeps the generation's path) is followed without anything being relaunched.
55387
55385
  */
55388
- lastPort: external_exports.number().int().positive().optional(),
55386
+ socketPath: external_exports.string().min(1).optional(),
55389
55387
  /** The `headroom --version` output of the running install. */
55390
55388
  version: external_exports.string().optional(),
55391
55389
  /** Hash of the allowlist the running proxy was started with, so a provider-file change is detected as drift. */
@@ -55514,10 +55512,10 @@ function ensureHeadroom(params) {
55514
55512
  for (; ; ) {
55515
55513
  const state = readHeadroomState(ports.fs, paths.headroomStateFile);
55516
55514
  if (state?.supervisorPid !== void 0 && ports.isRunning(state.supervisorPid)) {
55517
- const daemonUp = state.port !== void 0 && state.headroomPid !== void 0 && ports.isRunning(state.headroomPid);
55518
- if (daemonUp && state.port !== void 0) {
55515
+ const daemonUp = state.socketPath !== void 0 && state.headroomPid !== void 0 && ports.isRunning(state.headroomPid);
55516
+ if (daemonUp && state.socketPath !== void 0) {
55519
55517
  writeSession(ports.fs, paths.headroomSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), supervisorPid: state.supervisorPid });
55520
- return { port: state.port };
55518
+ return { socketPath: state.socketPath };
55521
55519
  }
55522
55520
  if (state.lastError !== void 0) {
55523
55521
  throw new HeadroomStartError(
@@ -55802,21 +55800,29 @@ function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
55802
55800
  function spawnHeadroomSupervisor(paths, spawnDaemon) {
55803
55801
  return spawnDaemon(paths, "__headroom-supervisor", paths.headroomLogPath);
55804
55802
  }
55805
- async function realIsPortFree(port) {
55806
- return await new Promise((resolve) => {
55807
- const server = import_node_net.default.createServer();
55808
- server.unref();
55809
- server.once("error", () => {
55810
- resolve(false);
55811
- });
55812
- server.once("close", () => {
55813
- resolve(true);
55814
- });
55815
- server.listen(port, "127.0.0.1", () => {
55816
- server.close();
55817
- });
55818
- });
55819
- }
55803
+ var SOCKET_PERMISSION_BITS = 511;
55804
+ var realHeadroomSocketTrust = {
55805
+ platform: process.platform,
55806
+ currentUid: () => {
55807
+ if (process.getuid === void 0) {
55808
+ throw new Error(`no POSIX user id on ${process.platform}`);
55809
+ }
55810
+ return process.getuid();
55811
+ },
55812
+ lstat: (target) => {
55813
+ let stat;
55814
+ try {
55815
+ stat = import_node_fs3.default.lstatSync(target);
55816
+ } catch (error62) {
55817
+ if (isEnoent2(error62)) {
55818
+ return void 0;
55819
+ }
55820
+ throw error62;
55821
+ }
55822
+ const kind = stat.isSymbolicLink() ? "symlink" : stat.isDirectory() ? "dir" : stat.isSocket() ? "socket" : "other";
55823
+ return { kind, uid: stat.uid, mode: stat.mode & SOCKET_PERMISSION_BITS };
55824
+ }
55825
+ };
55820
55826
  function realHeadroomPort(paths, options) {
55821
55827
  return {
55822
55828
  ensure: () => {
@@ -55833,7 +55839,7 @@ function realHeadroomPort(paths, options) {
55833
55839
  }
55834
55840
  });
55835
55841
  return {
55836
- port: up.port,
55842
+ socketPath: up.socketPath,
55837
55843
  projectId: resolveGitRoot(realRunPort, options.cwd) ?? options.cwd
55838
55844
  };
55839
55845
  },
@@ -59648,7 +59654,8 @@ function buildLayoutPaths(root) {
59648
59654
  categoriesLocalFile: import_node_path17.default.join(root, "categories.local.json"),
59649
59655
  claudeShimFile: import_node_path17.default.join(root, "claude-shim.json"),
59650
59656
  headroomDir: import_node_path17.default.join(root, "headroom"),
59651
- headroomStateFile: import_node_path17.default.join(root, "headroom", "state.json"),
59657
+ headroomStateFile: import_node_path17.default.join(root, "headroom", `state.v${String(HEADROOM_STATE_SCHEMA_VERSION)}.json`),
59658
+ headroomSocketDir: import_node_path17.default.join(root, "headroom", "run"),
59652
59659
  headroomLockFile: import_node_path17.default.join(root, "headroom", "start.lock"),
59653
59660
  headroomSessionsDir: import_node_path17.default.join(root, "headroom", "sessions"),
59654
59661
  logsDir: import_node_path17.default.join(root, "logs"),
@@ -61032,7 +61039,7 @@ function registerIdentityCommand(program2, deps) {
61032
61039
  // package.json
61033
61040
  var package_default = {
61034
61041
  name: "claude-use",
61035
- version: "7.13.2",
61042
+ version: "8.0.0",
61036
61043
  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.",
61037
61044
  license: "MIT",
61038
61045
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -61493,11 +61500,11 @@ function providerBaseUrl(port, provider) {
61493
61500
  function directOrigin(port) {
61494
61501
  return `http://127.0.0.1:${String(port)}`;
61495
61502
  }
61496
- function parseProviderPath(path40) {
61497
- if (!path40.startsWith(PROVIDER_PATH_PREFIX)) {
61503
+ function parseProviderPath(path41) {
61504
+ if (!path41.startsWith(PROVIDER_PATH_PREFIX)) {
61498
61505
  return void 0;
61499
61506
  }
61500
- const tail = path40.slice(PROVIDER_PATH_PREFIX.length);
61507
+ const tail = path41.slice(PROVIDER_PATH_PREFIX.length);
61501
61508
  const slash = tail.indexOf("/");
61502
61509
  if (slash <= 0) {
61503
61510
  return void 0;
@@ -61897,9 +61904,9 @@ function decoderFor(encoding) {
61897
61904
  return void 0;
61898
61905
  }
61899
61906
  }
61900
- function destinationOf(path40) {
61901
- const scoped = parseProviderPath(path40);
61902
- return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path40 } : { provider: scoped.provider, endpoint: scoped.rest };
61907
+ function destinationOf(path41) {
61908
+ const scoped = parseProviderPath(path41);
61909
+ return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path41 } : { provider: scoped.provider, endpoint: scoped.rest };
61903
61910
  }
61904
61911
  function buildRecord(event, context) {
61905
61912
  const { scan } = context;
@@ -63302,7 +63309,7 @@ var import_node_path29 = __toESM(require("node:path"), 1);
63302
63309
 
63303
63310
  // src/frontdoor/state.ts
63304
63311
  var import_node_path28 = __toESM(require("node:path"), 1);
63305
- var FRONT_DOOR_PROTOCOL = 1;
63312
+ var FRONT_DOOR_PROTOCOL = 2;
63306
63313
  var FrontDoorSessionSchema = external_exports.strictObject({ pid: external_exports.number().int().positive(), startedAt: external_exports.number(), token: external_exports.string().min(1) });
63307
63314
  var FrontDoorStateSchema = external_exports.strictObject({
63308
63315
  /**
@@ -63768,9 +63775,84 @@ function registerCodexCommand(program2, deps) {
63768
63775
 
63769
63776
  // src/frontdoor/commands.ts
63770
63777
  var import_node_crypto11 = require("node:crypto");
63771
- var import_node_path30 = __toESM(require("node:path"), 1);
63778
+ var import_node_path31 = __toESM(require("node:path"), 1);
63772
63779
  var import_node_fs11 = __toESM(require("node:fs"), 1);
63773
63780
 
63781
+ // src/headroom/socket.ts
63782
+ var import_node_path30 = __toESM(require("node:path"), 1);
63783
+ var GROUP_OR_OTHER_BITS = 63;
63784
+ var OCTAL_RADIX2 = 8;
63785
+ var MODE_DIGITS = 4;
63786
+ var HEADROOM_SOCKET_SUFFIX = ".sock";
63787
+ var HEADROOM_SOCKET_NAME = /^(\d+)\.sock$/;
63788
+ var UNIX_SOCKET_PATH_MAX_BYTES = 103;
63789
+ var PLATFORMS_WITHOUT_UNIX_SOCKETS = ["win32"];
63790
+ function headroomSocketPath(paths, supervisorPid) {
63791
+ return import_node_path30.default.join(paths.headroomSocketDir, `${String(supervisorPid)}${HEADROOM_SOCKET_SUFFIX}`);
63792
+ }
63793
+ function platformRefusal(platform) {
63794
+ return PLATFORMS_WITHOUT_UNIX_SOCKETS.includes(platform) ? `headroom routing needs a unix domain socket, which headroom cannot serve on ${platform}; agent-shim never falls back to a TCP port for this hop` : void 0;
63795
+ }
63796
+ function ownerOnlyRefusal(label, target, stat, expected, uid) {
63797
+ if (stat === void 0) {
63798
+ return `the headroom ${label} ${target} does not exist`;
63799
+ }
63800
+ if (stat.kind === "symlink") {
63801
+ return `the headroom ${label} ${target} is a symlink; it must be the real ${expected === "dir" ? "directory" : "socket"}`;
63802
+ }
63803
+ if (stat.kind !== expected) {
63804
+ return `the headroom ${label} ${target} is not a ${expected === "dir" ? "directory" : "socket"}`;
63805
+ }
63806
+ if (stat.uid !== uid) {
63807
+ return `the headroom ${label} ${target} is owned by uid ${String(stat.uid)}, not by this user (uid ${String(uid)})`;
63808
+ }
63809
+ if ((stat.mode & GROUP_OR_OTHER_BITS) !== 0) {
63810
+ return `the headroom ${label} ${target} has mode ${stat.mode.toString(OCTAL_RADIX2).padStart(MODE_DIGITS, "0")}, which lets other users reach it; it must be accessible to its owner only`;
63811
+ }
63812
+ return void 0;
63813
+ }
63814
+ function verifyHeadroomSocket(socketPath, ports) {
63815
+ const unsupported = platformRefusal(ports.platform);
63816
+ if (unsupported !== void 0) {
63817
+ return { refused: unsupported };
63818
+ }
63819
+ const uid = ports.currentUid();
63820
+ const directory = import_node_path30.default.dirname(socketPath);
63821
+ const refusal = ownerOnlyRefusal("socket directory", directory, ports.lstat(directory), "dir", uid) ?? ownerOnlyRefusal("socket", socketPath, ports.lstat(socketPath), "socket", uid);
63822
+ return refusal === void 0 ? { socketPath } : { refused: refusal };
63823
+ }
63824
+ function prepareHeadroomSocket(fs19, ports, paths, supervisorPid) {
63825
+ const unsupported = platformRefusal(ports.platform);
63826
+ if (unsupported !== void 0) {
63827
+ return { refused: unsupported };
63828
+ }
63829
+ const socketPath = headroomSocketPath(paths, supervisorPid);
63830
+ const length = Buffer.byteLength(socketPath, "utf8");
63831
+ if (length > UNIX_SOCKET_PATH_MAX_BYTES) {
63832
+ return {
63833
+ refused: `the headroom socket path ${socketPath} is ${String(length)} bytes, longer than the ${String(UNIX_SOCKET_PATH_MAX_BYTES)} a unix socket path can hold; set AGENT_SHIM_HOME to a shorter directory`
63834
+ };
63835
+ }
63836
+ if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
63837
+ return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
63838
+ }
63839
+ fs19.mkdirPrivate(paths.headroomSocketDir);
63840
+ const refusal = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
63841
+ return refusal === void 0 ? { socketPath } : { refused: refusal };
63842
+ }
63843
+ function pruneStaleHeadroomSockets(fs19, paths, isRunning) {
63844
+ const removed = [];
63845
+ for (const name of fs19.readdir(paths.headroomSocketDir)) {
63846
+ const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
63847
+ if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
63848
+ continue;
63849
+ }
63850
+ fs19.removeRecursive(import_node_path30.default.join(paths.headroomSocketDir, name));
63851
+ removed.push(name);
63852
+ }
63853
+ return removed;
63854
+ }
63855
+
63774
63856
  // src/frontdoor/custody.ts
63775
63857
  var CREDENTIAL_HEADERS = ["authorization", "x-api-key"];
63776
63858
  var SEQUESTERED_CREDENTIAL = "agent-shim-sequestered";
@@ -63857,7 +63939,7 @@ function createDoorPipelines(deps) {
63857
63939
  // The response middleware hook point, where usage tracking registers. The direct listener registers none, because its responses are consumed by headroom, not by the client: the entry the client sees is where observation belongs, and observing both would record every hopped request twice.
63858
63940
  responseObservers: deps.responseObservers,
63859
63941
  admit: admitLaunch(deps.isLiveToken),
63860
- headroom: { headroomPort: deps.headroomPort, hopSecret: deps.hopSecret, custody: deps.custody, log: deps.log },
63942
+ headroom: { headroomSocket: deps.headroomSocket, hopSecret: deps.hopSecret, custody: deps.custody, log: deps.log },
63861
63943
  now: deps.now,
63862
63944
  log: deps.log
63863
63945
  },
@@ -63908,7 +63990,7 @@ function isLiveCapability(presented, live) {
63908
63990
 
63909
63991
  // src/frontdoor/capture.ts
63910
63992
  var fs11 = __toESM(require("node:fs"), 1);
63911
- var path30 = __toESM(require("node:path"), 1);
63993
+ var path31 = __toESM(require("node:path"), 1);
63912
63994
  var SECRET_HEADER_NAME = /authorization|cookie|token|secret|credential|api[-_]key/i;
63913
63995
  var SECRET_JSON_KEY = /token|secret|password|credential|authorization|api[-_]key/i;
63914
63996
  var SECRET_BODY_PATTERNS = [
@@ -63952,10 +64034,10 @@ function redactBody(chunk) {
63952
64034
  }
63953
64035
  var CAPTURE_ENV = "AGENT_SHIM_FRONTDOOR_CAPTURE";
63954
64036
  function captureFromEnv(env, logsDir) {
63955
- return env[CAPTURE_ENV] === "1" ? createFileCapture(path30.join(logsDir, "frontdoor-capture.jsonl")) : void 0;
64037
+ return env[CAPTURE_ENV] === "1" ? createFileCapture(path31.join(logsDir, "frontdoor-capture.jsonl")) : void 0;
63956
64038
  }
63957
64039
  function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
63958
- fs11.mkdirSync(path30.dirname(file2), { recursive: true });
64040
+ fs11.mkdirSync(path31.dirname(file2), { recursive: true });
63959
64041
  let nextId = 0;
63960
64042
  const append = (record2) => {
63961
64043
  fs11.appendFileSync(file2, `${JSON.stringify({ ts: now().toISOString(), ...record2 })}
@@ -64049,7 +64131,7 @@ var fs12 = __toESM(require("node:fs"), 1);
64049
64131
 
64050
64132
  // src/frontdoor/x509.ts
64051
64133
  var import_node_crypto8 = require("node:crypto");
64052
- var import_node_net2 = __toESM(require("node:net"), 1);
64134
+ var import_node_net = __toESM(require("node:net"), 1);
64053
64135
  var TAG_BOOLEAN = 1;
64054
64136
  var TAG_INTEGER = 2;
64055
64137
  var TAG_BIT_STRING = 3;
@@ -64175,7 +64257,7 @@ function ipv6Groups(address) {
64175
64257
  const [head = "", tail] = address.split("::");
64176
64258
  const split = (text2) => text2 === "" ? [] : text2.split(":");
64177
64259
  const expand = (groups) => groups.flatMap((group) => {
64178
- if (!import_node_net2.default.isIPv4(group)) {
64260
+ if (!import_node_net.default.isIPv4(group)) {
64179
64261
  return [Number.parseInt(group, HEX_RADIX)];
64180
64262
  }
64181
64263
  const [a2 = 0, b = 0, c2 = 0, d = 0] = group.split(".").map(Number);
@@ -64187,10 +64269,10 @@ function ipv6Groups(address) {
64187
64269
  return [...before, ...filler, ...after];
64188
64270
  }
64189
64271
  function ipBytes(address) {
64190
- if (import_node_net2.default.isIPv4(address)) {
64272
+ if (import_node_net.default.isIPv4(address)) {
64191
64273
  return Buffer.from(address.split(".").map(Number));
64192
64274
  }
64193
- if (!import_node_net2.default.isIPv6(address)) {
64275
+ if (!import_node_net.default.isIPv6(address)) {
64194
64276
  throw new Error(`${address} is not an IP address`);
64195
64277
  }
64196
64278
  const bytes = Buffer.alloc(IPV6_GROUPS * BYTES_PER_IPV6_GROUP);
@@ -64298,7 +64380,7 @@ function issueLeafCertificate(ca, names, notBefore, notAfter) {
64298
64380
  const caCertificate = new import_node_crypto8.X509Certificate(ca.certPem);
64299
64381
  const caPrivateKey = (0, import_node_crypto8.createPrivateKey)(ca.keyPem);
64300
64382
  const { publicKey, privateKey } = rsaKeyPair();
64301
- const generalNames = names.map((name) => import_node_net2.default.isIP(name) === 0 ? tlv(TAG_GENERAL_NAME_DNS, Buffer.from(name, "ascii")) : tlv(TAG_GENERAL_NAME_IP, ipBytes(name)));
64383
+ const generalNames = names.map((name) => import_node_net.default.isIP(name) === 0 ? tlv(TAG_GENERAL_NAME_DNS, Buffer.from(name, "ascii")) : tlv(TAG_GENERAL_NAME_IP, ipBytes(name)));
64302
64384
  const der = assemble({
64303
64385
  subjectPublicKey: publicKey,
64304
64386
  subjectName: commonNameOnly(commonName),
@@ -64392,22 +64474,22 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
64392
64474
  };
64393
64475
  writeFrontDoorState(fs19, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
64394
64476
  const previousSticky = lastPort;
64395
- let http5;
64477
+ let http6;
64396
64478
  try {
64397
- http5 = await ports.startProviderListener(lastPort);
64479
+ http6 = await ports.startProviderListener(lastPort);
64398
64480
  } catch (error62) {
64399
64481
  return fail(`could not start the provider listener: ${error62 instanceof Error ? error62.message : String(error62)}`);
64400
64482
  }
64401
- if (previousSticky !== void 0 && http5.port !== previousSticky) {
64402
- ports.log(`agent-shim frontdoor supervisor: sticky port ${String(previousSticky)} was occupied; moving to ${String(http5.port)} (sessions launched against the old port are stale until they relaunch)`);
64483
+ if (previousSticky !== void 0 && http6.port !== previousSticky) {
64484
+ ports.log(`agent-shim frontdoor supervisor: sticky port ${String(previousSticky)} was occupied; moving to ${String(http6.port)} (sessions launched against the old port are stale until they relaunch)`);
64403
64485
  }
64404
- lastPort = http5.port;
64486
+ lastPort = http6.port;
64405
64487
  const previousStickyConnect = lastConnectPort;
64406
64488
  let connect3;
64407
64489
  try {
64408
64490
  connect3 = await ports.startConnectListener(lastConnectPort);
64409
64491
  } catch (error62) {
64410
- await http5.close();
64492
+ await http6.close();
64411
64493
  return fail(`could not start the CONNECT surface: ${error62 instanceof Error ? error62.message : String(error62)}`);
64412
64494
  }
64413
64495
  if (previousStickyConnect !== void 0 && connect3.port !== previousStickyConnect) {
@@ -64420,16 +64502,16 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
64420
64502
  direct = await ports.startDirectListener(lastDirectPort);
64421
64503
  } catch (error62) {
64422
64504
  await connect3.close();
64423
- await http5.close();
64505
+ await http6.close();
64424
64506
  return fail(`could not start the direct listener: ${error62 instanceof Error ? error62.message : String(error62)}`);
64425
64507
  }
64426
64508
  if (previousStickyDirect !== void 0 && direct.port !== previousStickyDirect) {
64427
64509
  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)`);
64428
64510
  }
64429
64511
  lastDirectPort = direct.port;
64430
- writeFrontDoorState(fs19, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http5.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
64512
+ writeFrontDoorState(fs19, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http6.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
64431
64513
  fs19.removeRecursive(paths.frontdoorLockFile);
64432
- 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(connect3.port)}`);
64514
+ ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http6.port)}, CONNECT surface on 127.0.0.1:${String(connect3.port)}`);
64433
64515
  let idleSince;
64434
64516
  let ticks = 0;
64435
64517
  for (; ; ) {
@@ -64444,7 +64526,7 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
64444
64526
  ports.log(`agent-shim frontdoor supervisor: no sessions for ${String(idleShutdownMinutes)} minute(s); closing the front door and exiting`);
64445
64527
  await direct.close();
64446
64528
  await connect3.close();
64447
- await http5.close();
64529
+ await http6.close();
64448
64530
  writeFrontDoorState(fs19, paths.frontdoorStateFile, sticky());
64449
64531
  return 0;
64450
64532
  }
@@ -64498,8 +64580,8 @@ function parseConnectTarget(authority) {
64498
64580
  }
64499
64581
  return { host, port };
64500
64582
  }
64501
- function servedByPipeline(path40) {
64502
- return path40?.startsWith(ROUTED_PATH_PREFIX) === true;
64583
+ function servedByPipeline(path41) {
64584
+ return path41?.startsWith(ROUTED_PATH_PREFIX) === true;
64503
64585
  }
64504
64586
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
64505
64587
  "connection",
@@ -64833,16 +64915,66 @@ function realConnectCertStore(paths) {
64833
64915
  }
64834
64916
 
64835
64917
  // src/frontdoor/connectEffects.ts
64918
+ var dns = __toESM(require("node:dns"), 1);
64836
64919
  var http = __toESM(require("node:http"), 1);
64837
64920
  var https = __toESM(require("node:https"), 1);
64838
- var net3 = __toESM(require("node:net"), 1);
64921
+ var net2 = __toESM(require("node:net"), 1);
64839
64922
  var tls = __toESM(require("node:tls"), 1);
64923
+ var UPSTREAM_LOCAL_PORT_START = 47900;
64924
+ var UPSTREAM_LOCAL_PORT_END = 47919;
64925
+ var nextUpstreamLocalPort = UPSTREAM_LOCAL_PORT_START;
64926
+ function upstreamLocalPort() {
64927
+ const port = nextUpstreamLocalPort;
64928
+ nextUpstreamLocalPort = nextUpstreamLocalPort === UPSTREAM_LOCAL_PORT_END ? UPSTREAM_LOCAL_PORT_START : nextUpstreamLocalPort + 1;
64929
+ return port;
64930
+ }
64931
+ var realAddressLookup = (host, _options, callback) => {
64932
+ if (net2.isIP(host) !== 0) {
64933
+ callback(null, [{ address: host, family: net2.isIP(host) }]);
64934
+ return;
64935
+ }
64936
+ dns.resolve4(host, (error62, addresses) => {
64937
+ const first = addresses[0];
64938
+ if (error62 !== null || first === void 0) {
64939
+ callback(error62 ?? new Error(`no A record for ${host}`), [{ address: "", family: 4 }]);
64940
+ return;
64941
+ }
64942
+ callback(null, [{ address: first, family: 4 }]);
64943
+ });
64944
+ };
64945
+ var HTTP_PORT = 80;
64946
+ function exemptDial(options, defaultPort) {
64947
+ const host = typeof options.host === "string" ? options.host : "";
64948
+ const port = typeof options.port === "number" ? options.port : defaultPort;
64949
+ return net2.connect(net2.isIP(host) === 0 ? { host, port, localPort: upstreamLocalPort(), lookup: realAddressLookup } : { host, port });
64950
+ }
64951
+ function requestServername(options, fallback) {
64952
+ return "servername" in options && typeof options.servername === "string" && options.servername !== "" ? options.servername : fallback;
64953
+ }
64954
+ var ExemptHttpAgent = class extends http.Agent {
64955
+ createConnection(options) {
64956
+ return exemptDial(options, HTTP_PORT);
64957
+ }
64958
+ };
64959
+ var ExemptTlsAgent = class extends https.Agent {
64960
+ createConnection(options) {
64961
+ const host = typeof options.host === "string" ? options.host : "";
64962
+ const tlsOptions = { socket: exemptDial(options, HTTPS_PORT), servername: requestServername(options, host) };
64963
+ if ("ca" in options && Array.isArray(options.ca)) {
64964
+ tlsOptions.ca = options.ca;
64965
+ }
64966
+ if ("rejectUnauthorized" in options && typeof options.rejectUnauthorized === "boolean") {
64967
+ tlsOptions.rejectUnauthorized = options.rejectUnauthorized;
64968
+ }
64969
+ return tls.connect(tlsOptions);
64970
+ }
64971
+ };
64840
64972
  function realConnectEffects() {
64841
- const plainAgent = new http.Agent({ keepAlive: true });
64842
- const tlsAgent = new https.Agent({ keepAlive: true });
64973
+ const plainAgent = new ExemptHttpAgent();
64974
+ const tlsAgent = new ExemptTlsAgent();
64843
64975
  const listenOnce = async (port, onSocket) => await new Promise((resolve, reject) => {
64844
64976
  const accepted = /* @__PURE__ */ new Set();
64845
- const server = net3.createServer((socket) => {
64977
+ const server = net2.createServer((socket) => {
64846
64978
  accepted.add(socket);
64847
64979
  socket.on("close", () => {
64848
64980
  accepted.delete(socket);
@@ -64925,14 +65057,26 @@ function realConnectEffects() {
64925
65057
  };
64926
65058
  },
64927
65059
  connectTlsUpstream: async (host, port, clientAlpn) => await new Promise((resolve, reject) => {
64928
- const socket = tls.connect({ host, port, servername: host, ...clientAlpn === void 0 ? {} : { ALPNProtocols: [clientAlpn] } });
64929
- socket.once("secureConnect", () => {
64930
- resolve(socket);
64931
- });
64932
- socket.once("error", reject);
65060
+ const dial = (localPort) => {
65061
+ const raw = net2.connect({ host, port, localPort, lookup: realAddressLookup });
65062
+ return tls.connect({ socket: raw, servername: host, ...clientAlpn === void 0 ? {} : { ALPNProtocols: [clientAlpn] } });
65063
+ };
65064
+ const settle2 = (candidate) => {
65065
+ candidate.once("secureConnect", () => {
65066
+ resolve(candidate);
65067
+ });
65068
+ candidate.once("error", (error62) => {
65069
+ if ("code" in error62 && error62.code === "EADDRINUSE") {
65070
+ settle2(dial(upstreamLocalPort()));
65071
+ return;
65072
+ }
65073
+ reject(error62);
65074
+ });
65075
+ };
65076
+ settle2(dial(upstreamLocalPort()));
64933
65077
  }),
64934
65078
  connectTcp: async (host, port) => await new Promise((resolve, reject) => {
64935
- const socket = net3.connect({ host, port });
65079
+ const socket = net2.connect({ host, port });
64936
65080
  socket.once("connect", () => {
64937
65081
  resolve(socket);
64938
65082
  });
@@ -64943,6 +65087,7 @@ function realConnectEffects() {
64943
65087
  const options = {
64944
65088
  host: target.host,
64945
65089
  port: target.port,
65090
+ lookup: realAddressLookup,
64946
65091
  method: request6.method,
64947
65092
  path: request6.url,
64948
65093
  headers,
@@ -65139,13 +65284,17 @@ function responseHeaders(headers) {
65139
65284
  return result;
65140
65285
  }
65141
65286
  async function applyHeadroomHop(request6, response, upstream, deps) {
65142
- const port = deps.headroomPort();
65143
- if (port === void 0) {
65144
- response.start(HTTP_BAD_GATEWAY2, { "Content-Type": "application/json" });
65145
- await response.write(JSON.stringify({ type: "error", error: { type: "api_error", message: "agent-shim front door: the headroom daemon is restarting" } }));
65146
- response.end();
65287
+ const target = deps.headroomSocket();
65288
+ if (target === void 0) {
65289
+ await answerBadGateway(response, "agent-shim front door: the headroom daemon is restarting");
65290
+ return;
65291
+ }
65292
+ if (target.refused !== void 0) {
65293
+ deps.log(`front door: refusing the headroom hop (${request6.method} ${new URL(request6.url, "http://127.0.0.1").pathname}): ${target.refused}`);
65294
+ await answerBadGateway(response, `agent-shim front door: refusing to send this request to headroom: ${target.refused}`);
65147
65295
  return;
65148
65296
  }
65297
+ const { socketPath } = target;
65149
65298
  let headers = forwardableHeaders(request6.headers);
65150
65299
  let hopId;
65151
65300
  if (upstream !== void 0) {
@@ -65164,16 +65313,21 @@ async function applyHeadroomHop(request6, response, upstream, deps) {
65164
65313
  }
65165
65314
  headers[HOP_SECRET_HEADER] = deps.hopSecret;
65166
65315
  try {
65167
- await forwardThroughHeadroom(request6, response, { port, headers, log: deps.log });
65316
+ await forwardThroughHeadroom(request6, response, { socketPath, headers, log: deps.log });
65168
65317
  } finally {
65169
65318
  if (hopId !== void 0) {
65170
65319
  deps.custody.release(hopId);
65171
65320
  }
65172
65321
  }
65173
65322
  }
65323
+ async function answerBadGateway(response, message) {
65324
+ response.start(HTTP_BAD_GATEWAY2, { "Content-Type": "application/json" });
65325
+ await response.write(JSON.stringify({ type: "error", error: { type: "api_error", message } }));
65326
+ response.end();
65327
+ }
65174
65328
  var HOP_AGENT = new http3.Agent({ keepAlive: false });
65175
65329
  async function forwardThroughHeadroom(request6, response, target) {
65176
- const { port, headers } = target;
65330
+ const { socketPath, headers } = target;
65177
65331
  await new Promise((resolve) => {
65178
65332
  const onUpstreamResponse = (upstreamResponse) => {
65179
65333
  response.start(upstreamResponse.statusCode ?? HTTP_BAD_GATEWAY2, responseHeaders(upstreamResponse.headers));
@@ -65191,7 +65345,7 @@ async function forwardThroughHeadroom(request6, response, target) {
65191
65345
  }
65192
65346
  } catch (error62) {
65193
65347
  if (!request6.signal.aborted) {
65194
- target.log(`front door: headroom hop to 127.0.0.1:${String(port)} ended mid-stream (${request6.method} ${new URL(request6.url, "http://127.0.0.1").pathname}): ${error62 instanceof Error ? error62.message : String(error62)}`);
65348
+ target.log(`front door: headroom hop to ${socketPath} ended mid-stream (${request6.method} ${new URL(request6.url, "http://127.0.0.1").pathname}): ${error62 instanceof Error ? error62.message : String(error62)}`);
65195
65349
  }
65196
65350
  response.destroy();
65197
65351
  }
@@ -65199,11 +65353,11 @@ async function forwardThroughHeadroom(request6, response, target) {
65199
65353
  };
65200
65354
  void stream();
65201
65355
  };
65202
- const hop = http3.request({ host: "127.0.0.1", port, method: request6.method, path: request6.url, headers, agent: HOP_AGENT }, onUpstreamResponse);
65356
+ const hop = http3.request({ socketPath, method: request6.method, path: request6.url, headers, agent: HOP_AGENT }, onUpstreamResponse);
65203
65357
  hop.on("error", (error62) => {
65204
65358
  const phase = response.headersSent ? "mid-stream" : "before the response started";
65205
65359
  const code = "code" in error62 && typeof error62.code === "string" ? ` ${error62.code}` : "";
65206
- target.log(`front door: headroom hop to 127.0.0.1:${String(port)} failed (${request6.method} ${new URL(request6.url, "http://127.0.0.1").pathname}, ${phase}): ${error62.message}${code}`);
65360
+ target.log(`front door: headroom hop to ${socketPath} failed (${request6.method} ${new URL(request6.url, "http://127.0.0.1").pathname}, ${phase}): ${error62.message}${code}`);
65207
65361
  if (!response.headersSent) {
65208
65362
  response.start(HTTP_BAD_GATEWAY2, { "Content-Type": "application/json" });
65209
65363
  void response.write(JSON.stringify({ type: "error", error: { type: "api_error", message: `agent-shim front door: the headroom daemon is unreachable (${error62.message})` } })).then(() => {
@@ -66194,8 +66348,8 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
66194
66348
  request6.body.resume();
66195
66349
  return;
66196
66350
  }
66197
- const path40 = new URL(request6.url, "http://127.0.0.1").pathname;
66198
- const translated = { method: request6.method, path: path40, body, signal: request6.signal };
66351
+ const path41 = new URL(request6.url, "http://127.0.0.1").pathname;
66352
+ const translated = { method: request6.method, path: path41, body, signal: request6.signal };
66199
66353
  const routed = await route(translated);
66200
66354
  if (request6.signal.aborted) {
66201
66355
  return;
@@ -66222,14 +66376,14 @@ function createPassthroughRoute(name, target) {
66222
66376
  const base = new URL(target.baseUrl);
66223
66377
  const tls2 = base.protocol === "https:";
66224
66378
  const basePath = base.pathname.replace(/\/+$/, "");
66225
- const agent = tls2 ? new https3.Agent({ keepAlive: true }) : new http4.Agent({ keepAlive: true });
66379
+ const agent = tls2 ? new ExemptTlsAgent() : new ExemptHttpAgent();
66226
66380
  return {
66227
66381
  name,
66228
66382
  headroomEligible: true,
66229
66383
  headroomUpstream: target.headroomUpstream,
66230
66384
  serve: async (request6, response) => {
66231
66385
  const incoming = new URL(request6.url, "http://127.0.0.1");
66232
- const path40 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
66386
+ const path41 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
66233
66387
  const headers = forwardableHeaders(request6.headers);
66234
66388
  delete headers.host;
66235
66389
  await new Promise((resolve) => {
@@ -66237,7 +66391,7 @@ function createPassthroughRoute(name, target) {
66237
66391
  host: base.hostname,
66238
66392
  port: base.port === "" ? void 0 : Number(base.port),
66239
66393
  method: request6.method,
66240
- path: `${basePath}${path40}${incoming.search}`,
66394
+ path: `${basePath}${path41}${incoming.search}`,
66241
66395
  headers,
66242
66396
  agent
66243
66397
  };
@@ -66299,10 +66453,10 @@ function createProviderRouteResolver(deps) {
66299
66453
  return route;
66300
66454
  };
66301
66455
  const resolve = (request6) => {
66302
- const path40 = new URL(request6.url, "http://127.0.0.1").pathname;
66303
- const scoped = parseProviderPath(path40);
66456
+ const path41 = new URL(request6.url, "http://127.0.0.1").pathname;
66457
+ const scoped = parseProviderPath(path41);
66304
66458
  if (scoped === void 0) {
66305
- return path40.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path40}` };
66459
+ return path41.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path41}` };
66306
66460
  }
66307
66461
  const { provider } = scoped;
66308
66462
  let definition;
@@ -66394,8 +66548,8 @@ function zaiWindow(limit) {
66394
66548
  var zaiQuotaAdapter = {
66395
66549
  source: ZAI_SOURCE,
66396
66550
  matches: (baseUrl) => URL.canParse(baseUrl) && new URL(baseUrl).hostname === ZAI_HOST,
66397
- fetch: async (apiKey, http5, signal, nowMs) => {
66398
- const response = await http5(ZAI_QUOTA_URL, { authorization: apiKey, accept: "application/json" }, signal);
66551
+ fetch: async (apiKey, http6, signal, nowMs) => {
66552
+ const response = await http6(ZAI_QUOTA_URL, { authorization: apiKey, accept: "application/json" }, signal);
66399
66553
  if (response.status !== HTTP_OK) {
66400
66554
  throw new ProviderQuotaError(ZAI_SOURCE, `answered HTTP ${String(response.status)}`);
66401
66555
  }
@@ -66436,8 +66590,8 @@ var OpenRouterKeySchema = external_exports.object({
66436
66590
  })
66437
66591
  });
66438
66592
  var OpenRouterCreditsSchema = external_exports.object({ data: external_exports.object({ total_credits: external_exports.number().nonnegative(), total_usage: external_exports.number().nonnegative() }) });
66439
- async function openRouterGet(url2, schema, apiKey, http5, signal) {
66440
- const response = await http5(url2, { authorization: `Bearer ${apiKey}`, accept: "application/json" }, signal);
66593
+ async function openRouterGet(url2, schema, apiKey, http6, signal) {
66594
+ const response = await http6(url2, { authorization: `Bearer ${apiKey}`, accept: "application/json" }, signal);
66441
66595
  if (response.status === HTTP_FORBIDDEN) {
66442
66596
  return "forbidden";
66443
66597
  }
@@ -66462,12 +66616,12 @@ function nextUtcMidnight(nowMs) {
66462
66616
  var openRouterQuotaAdapter = {
66463
66617
  source: OPENROUTER_SOURCE,
66464
66618
  matches: (baseUrl) => URL.canParse(baseUrl) && new URL(baseUrl).hostname === OPENROUTER_HOST,
66465
- fetch: async (apiKey, http5, signal, nowMs) => {
66466
- const key = await openRouterGet(OPENROUTER_KEY_URL, OpenRouterKeySchema, apiKey, http5, signal);
66619
+ fetch: async (apiKey, http6, signal, nowMs) => {
66620
+ const key = await openRouterGet(OPENROUTER_KEY_URL, OpenRouterKeySchema, apiKey, http6, signal);
66467
66621
  if (key === "forbidden") {
66468
66622
  throw new ProviderQuotaError(OPENROUTER_SOURCE, "/api/v1/key refused the key (HTTP 403)");
66469
66623
  }
66470
- const credits = await openRouterGet(OPENROUTER_CREDITS_URL, OpenRouterCreditsSchema, apiKey, http5, signal);
66624
+ const credits = await openRouterGet(OPENROUTER_CREDITS_URL, OpenRouterCreditsSchema, apiKey, http6, signal);
66471
66625
  const { limit, limit_remaining: limitRemaining, limit_reset: limitReset, free_model_daily_requests: free, is_free_tier: isFreeTier } = key.data;
66472
66626
  const windows = [];
66473
66627
  if (limit !== null && limit > 0) {
@@ -66628,8 +66782,9 @@ function appendLog(paths, line) {
66628
66782
  import_node_fs11.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
66629
66783
  `);
66630
66784
  }
66631
- function liveHeadroomPort(paths) {
66632
- return readHeadroomState(realFarmFs, paths.headroomStateFile)?.port;
66785
+ function headroomSocketTarget(fsPort, trust, paths) {
66786
+ const socketPath = readHeadroomState(fsPort, paths.headroomStateFile)?.socketPath;
66787
+ return socketPath === void 0 ? void 0 : verifyHeadroomSocket(socketPath, trust);
66633
66788
  }
66634
66789
  function realFrontDoorSupervisorPorts(paths) {
66635
66790
  const log = (line) => {
@@ -66661,7 +66816,7 @@ function realFrontDoorSupervisorPorts(paths) {
66661
66816
  isLiveToken,
66662
66817
  responseObservers: [usageMiddleware],
66663
66818
  now: () => Date.now(),
66664
- headroomPort: () => liveHeadroomPort(paths),
66819
+ headroomSocket: () => headroomSocketTarget(realFarmFs, realHeadroomSocketTrust, paths),
66665
66820
  // The per-generation capability the direct listener demands: held only in this process's memory, so a loopback process that discovers the direct port still cannot use it.
66666
66821
  hopSecret: (0, import_node_crypto11.randomUUID)(),
66667
66822
  custody: createCredentialCustody(() => (0, import_node_crypto11.randomUUID)()),
@@ -66708,7 +66863,7 @@ function realFrontDoorSupervisorPorts(paths) {
66708
66863
  const leafFor = createLeafCache(loadCa(), () => /* @__PURE__ */ new Date());
66709
66864
  const capture = captureFromEnv(process.env, paths.logsDir);
66710
66865
  if (capture !== void 0) {
66711
- log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path30.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
66866
+ log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path31.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
66712
66867
  }
66713
66868
  const server = await startConnectServer(
66714
66869
  {
@@ -66764,13 +66919,13 @@ function realFrontDoorSupervisorPorts(paths) {
66764
66919
  }
66765
66920
  };
66766
66921
  }
66767
- function collectFrontDoorStatus(fsPort, paths, isRunning) {
66922
+ function collectFrontDoorStatus(fsPort, socketTrust, paths, isRunning) {
66768
66923
  const state = readFrontDoorState(fsPort, paths.frontdoorStateFile) ?? {};
66769
66924
  return {
66770
66925
  state,
66771
66926
  supervisorAlive: state.supervisorPid !== void 0 && isRunning(state.supervisorPid),
66772
66927
  sessions: listFrontDoorSessions(fsPort, paths.frontdoorSessionsDir).map((session) => ({ ...session, alive: isRunning(session.pid) })),
66773
- headroomPort: readHeadroomState(fsPort, paths.headroomStateFile)?.port,
66928
+ headroomSocket: headroomSocketTarget(fsPort, socketTrust, paths),
66774
66929
  logPath: paths.frontdoorLogPath,
66775
66930
  logExists: fsPort.readFileUtf8(paths.frontdoorLogPath) !== void 0
66776
66931
  };
@@ -66792,9 +66947,13 @@ function formatFrontDoorStatus(status, caCertPath) {
66792
66947
  } else {
66793
66948
  lines.push(`connect surface: listening on 127.0.0.1:${String(status.state.connectPort)}, CA ${caCertPath}`);
66794
66949
  }
66795
- lines.push(
66796
- status.headroomPort === void 0 ? "headroom hop: the daemon is not serving (sessions asking for headroom fail until it is up)" : `headroom hop: daemon on 127.0.0.1:${String(status.headroomPort)}`
66797
- );
66950
+ if (status.headroomSocket === void 0) {
66951
+ lines.push("headroom hop: the daemon is not serving (sessions asking for headroom fail until it is up)");
66952
+ } else if (status.headroomSocket.refused === void 0) {
66953
+ lines.push(`headroom hop: daemon on unix socket ${status.headroomSocket.socketPath}`);
66954
+ } else {
66955
+ lines.push(`headroom hop: REFUSING the daemon's socket (sessions asking for headroom fail until it is fixed): ${status.headroomSocket.refused}`);
66956
+ }
66798
66957
  if (status.sessions.length === 0) {
66799
66958
  lines.push("sessions: none");
66800
66959
  } else {
@@ -66814,7 +66973,7 @@ function registerFrontDoorCommand(program2, deps) {
66814
66973
  ]);
66815
66974
  withExamples(
66816
66975
  frontdoor.command("status").description("Report the front door's supervisor, listeners, sessions, and last error. Read-only.").option("--json", "Print the status as JSON.").action((options) => {
66817
- const status = collectFrontDoorStatus(realFarmFs, paths, realIsProcessRunning);
66976
+ const status = collectFrontDoorStatus(realFarmFs, realHeadroomSocketTrust, paths, realIsProcessRunning);
66818
66977
  if (options.json === true) {
66819
66978
  printJson(status);
66820
66979
  return;
@@ -67116,15 +67275,15 @@ var import_node_child_process4 = require("node:child_process");
67116
67275
 
67117
67276
  // src/identityToken.ts
67118
67277
  var import_node_fs12 = __toESM(require("node:fs"), 1);
67119
- var import_node_path31 = __toESM(require("node:path"), 1);
67278
+ var import_node_path32 = __toESM(require("node:path"), 1);
67120
67279
  var TOKEN_FILE_MODE = 384;
67121
67280
  var TOKEN_DIR_MODE = 448;
67122
67281
  var OAUTH_TOKEN_RE = /^sk-ant-oat\d+-[A-Za-z0-9_-]+$/;
67123
67282
  function identityTokenDir(paths) {
67124
- return import_node_path31.default.join(paths.root, "credentials");
67283
+ return import_node_path32.default.join(paths.root, "credentials");
67125
67284
  }
67126
67285
  function identityTokenPath(paths, identityName) {
67127
- return import_node_path31.default.join(identityTokenDir(paths), `${identityName}.token`);
67286
+ return import_node_path32.default.join(identityTokenDir(paths), `${identityName}.token`);
67128
67287
  }
67129
67288
  function storeIdentityToken(paths, identityName, raw) {
67130
67289
  const token = raw.trim();
@@ -67135,7 +67294,7 @@ function storeIdentityToken(paths, identityName, raw) {
67135
67294
  import_node_fs12.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
67136
67295
  import_node_fs12.default.chmodSync(dir, TOKEN_DIR_MODE);
67137
67296
  const target = identityTokenPath(paths, identityName);
67138
- const temp = import_node_path31.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
67297
+ const temp = import_node_path32.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
67139
67298
  import_node_fs12.default.writeFileSync(temp, `${token}
67140
67299
  `, { mode: TOKEN_FILE_MODE });
67141
67300
  import_node_fs12.default.renameSync(temp, target);
@@ -67145,7 +67304,7 @@ function storeIdentityToken(paths, identityName, raw) {
67145
67304
  // src/realCredentialCache.ts
67146
67305
  var import_node_child_process3 = require("node:child_process");
67147
67306
  var import_node_fs13 = __toESM(require("node:fs"), 1);
67148
- var import_node_path32 = __toESM(require("node:path"), 1);
67307
+ var import_node_path33 = __toESM(require("node:path"), 1);
67149
67308
  var KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
67150
67309
  var CACHE_DIR_MODE = 448;
67151
67310
  var CACHE_FILE_MODE = 384;
@@ -67172,8 +67331,8 @@ function security(args, stdin2) {
67172
67331
  return { status: result.status, stdout: result.stdout };
67173
67332
  }
67174
67333
  function createRealCredentialCache(root) {
67175
- const dir = import_node_path32.default.join(root, "credential-cache");
67176
- const filePath = (owner) => import_node_path32.default.join(dir, cacheFileNameFor(owner));
67334
+ const dir = import_node_path33.default.join(root, "credential-cache");
67335
+ const filePath = (owner) => import_node_path33.default.join(dir, cacheFileNameFor(owner));
67177
67336
  return {
67178
67337
  read(store, owner) {
67179
67338
  if (store === "file") {
@@ -67352,7 +67511,7 @@ function subjectName(positional, provider) {
67352
67511
 
67353
67512
  // src/doctorReport.ts
67354
67513
  var import_node_fs14 = __toESM(require("node:fs"), 1);
67355
- var import_node_path33 = __toESM(require("node:path"), 1);
67514
+ var import_node_path34 = __toESM(require("node:path"), 1);
67356
67515
 
67357
67516
  // src/headroom/source.ts
67358
67517
  var GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
@@ -67403,7 +67562,7 @@ function validateJson(schema, input2) {
67403
67562
  return { ok: true, data: result.data };
67404
67563
  }
67405
67564
  function pushPathResolution(push, resolution) {
67406
- const ownDir = import_node_path33.default.dirname(resolution.ownExecutablePath);
67565
+ const ownDir = import_node_path34.default.dirname(resolution.ownExecutablePath);
67407
67566
  switch (resolution.agentShim.status) {
67408
67567
  case "ok":
67409
67568
  push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
@@ -67471,14 +67630,14 @@ function pushProvider(push, entry) {
67471
67630
  }
67472
67631
  function pushLegacyName(push, params) {
67473
67632
  const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
67474
- if (legacyVariables.length === 0 && import_node_path33.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
67633
+ if (legacyVariables.length === 0 && import_node_path34.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
67475
67634
  push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
67476
67635
  return;
67477
67636
  }
67478
67637
  for (const name of legacyVariables) {
67479
67638
  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);
67480
67639
  }
67481
- if (import_node_path33.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
67640
+ if (import_node_path34.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
67482
67641
  push(
67483
67642
  "legacy-name",
67484
67643
  "warn",
@@ -67668,7 +67827,7 @@ function runDoctor(params) {
67668
67827
  "warn",
67669
67828
  `Headroom state names supervisor pid ${String(state.supervisorPid)}, which is not running; the next launch through headroom will start a replacement.`
67670
67829
  );
67671
- } else if (state.headroomPid === void 0 || state.port === void 0) {
67830
+ } else if (state.headroomPid === void 0 || state.socketPath === void 0) {
67672
67831
  push(
67673
67832
  "headroom",
67674
67833
  "warn",
@@ -67684,7 +67843,7 @@ function runDoctor(params) {
67684
67843
  push(
67685
67844
  "headroom",
67686
67845
  "pass",
67687
- `Headroom daemon is up on 127.0.0.1:${String(state.port)} (supervisor ${String(state.supervisorPid)}, daemon ${String(state.headroomPid)}).`
67846
+ `Headroom daemon is up on unix socket ${state.socketPath} (supervisor ${String(state.supervisorPid)}, daemon ${String(state.headroomPid)}).`
67688
67847
  );
67689
67848
  }
67690
67849
  if (state.lastError !== void 0 && supervisorAlive) {
@@ -67786,18 +67945,18 @@ function collectDoctorReport(params) {
67786
67945
  const { paths } = params;
67787
67946
  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() : [];
67788
67947
  const identities = identityNames.map((name) => {
67789
- const farmRoot = import_node_path33.default.join(paths.identitiesDir, name);
67790
- const identityPath = import_node_path33.default.join(farmRoot, "identity.json");
67948
+ const farmRoot = import_node_path34.default.join(paths.identitiesDir, name);
67949
+ const identityPath = import_node_path34.default.join(farmRoot, "identity.json");
67791
67950
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
67792
67951
  });
67793
67952
  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() : [];
67794
67953
  const configProfiles = profileNames.map((name) => {
67795
- const profilePath = import_node_path33.default.join(paths.configProfilesDir, `${name}.json`);
67954
+ const profilePath = import_node_path34.default.join(paths.configProfilesDir, `${name}.json`);
67796
67955
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
67797
67956
  });
67798
67957
  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() : [];
67799
67958
  const providers = providerNames.map((name) => {
67800
- const providerPath = import_node_path33.default.join(paths.providersDir, `${name}.json`);
67959
+ const providerPath = import_node_path34.default.join(paths.providersDir, `${name}.json`);
67801
67960
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
67802
67961
  });
67803
67962
  const ownExecutablePath = realOwnExecutablePath();
@@ -67809,12 +67968,12 @@ function collectDoctorReport(params) {
67809
67968
  binaryDiscovery = { ok: false, message: error62 instanceof Error ? error62.message : String(error62) };
67810
67969
  }
67811
67970
  const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
67812
- const pathDirs = (params.env.PATH ?? "").split(import_node_path33.default.delimiter).filter((dir) => dir !== "");
67971
+ const pathDirs = (params.env.PATH ?? "").split(import_node_path34.default.delimiter).filter((dir) => dir !== "");
67813
67972
  const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
67814
67973
  findPathShadow({
67815
67974
  pathDirs,
67816
- targetDir: import_node_path33.default.dirname(shimState.targetPath),
67817
- targetFilename: import_node_path33.default.basename(shimState.targetPath),
67975
+ targetDir: import_node_path34.default.dirname(shimState.targetPath),
67976
+ targetFilename: import_node_path34.default.basename(shimState.targetPath),
67818
67977
  findExecutableInDir
67819
67978
  }),
67820
67979
  shimState.targetPath,
@@ -67837,7 +67996,7 @@ function collectDoctorReport(params) {
67837
67996
  agentShim: refinePathShadow(
67838
67997
  findPathShadow({
67839
67998
  pathDirs,
67840
- targetDir: import_node_path33.default.dirname(ownExecutablePath),
67999
+ targetDir: import_node_path34.default.dirname(ownExecutablePath),
67841
68000
  targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
67842
68001
  findExecutableInDir
67843
68002
  }),
@@ -67879,8 +68038,8 @@ function registerDoctorCommand(program2, deps) {
67879
68038
 
67880
68039
  // src/headroom/commands.ts
67881
68040
  var import_node_fs15 = __toESM(require("node:fs"), 1);
67882
- var import_node_net3 = __toESM(require("node:net"), 1);
67883
- var import_node_path34 = __toESM(require("node:path"), 1);
68041
+ var import_node_http2 = __toESM(require("node:http"), 1);
68042
+ var import_node_path35 = __toESM(require("node:path"), 1);
67884
68043
  var import_node_child_process5 = require("node:child_process");
67885
68044
 
67886
68045
  // src/headroom/settings.ts
@@ -68019,8 +68178,6 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68019
68178
  return 0;
68020
68179
  }
68021
68180
  let installedSource = previousState?.installedSource;
68022
- let lastPort = previousState?.lastPort;
68023
- const sticky = () => lastPort === void 0 ? {} : { lastPort };
68024
68181
  const ownsState = () => {
68025
68182
  const owner = readHeadroomState(fs19, paths.headroomStateFile)?.supervisorPid;
68026
68183
  return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
@@ -68033,7 +68190,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68033
68190
  return true;
68034
68191
  };
68035
68192
  const fail = (message) => {
68036
- if (writeOwnState({ lastError: message, ...sticky() })) {
68193
+ if (writeOwnState({ lastError: message })) {
68037
68194
  fs19.removeRecursive(paths.headroomLockFile);
68038
68195
  }
68039
68196
  ports.log(`agent-shim headroom supervisor: ${message}`);
@@ -68056,11 +68213,17 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68056
68213
  installedSource = config2.source;
68057
68214
  return true;
68058
68215
  };
68216
+ const socket = prepareHeadroomSocket(fs19, ports.socketTrust, paths, ports.ownPid);
68217
+ if (socket.refused !== void 0) {
68218
+ return fail(socket.refused);
68219
+ }
68220
+ const { socketPath } = socket;
68221
+ pruneStaleHeadroomSockets(fs19, paths, ports.isRunning);
68059
68222
  if (!ensureInstalled()) {
68060
68223
  return fail(`could not install headroom from ${config2.source}: install failed (is uv installed and on PATH?)`);
68061
68224
  }
68062
68225
  const version2 = ports.headroomVersion() ?? "unknown";
68063
- writeOwnState({ supervisorPid: ports.ownPid, version: version2, installedSource, ...sticky() });
68226
+ writeOwnState({ supervisorPid: ports.ownPid, version: version2, installedSource });
68064
68227
  ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${allowlistOf(ports).join(", ")}]`);
68065
68228
  const orphanPid = previousState?.headroomPid;
68066
68229
  if (orphanPid !== void 0 && ports.isRunning(orphanPid)) {
@@ -68086,7 +68249,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68086
68249
  pruneDeadSessions(fs19, paths.headroomSessionsDir, ports.isRunning);
68087
68250
  const ownsNow = ownsState();
68088
68251
  if (!ownsNow && !superseded) {
68089
- ports.log("agent-shim headroom supervisor: another supervisor now owns state.json; serving this daemon's own sessions until they end");
68252
+ ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
68090
68253
  }
68091
68254
  superseded = !ownsNow;
68092
68255
  const crashed = headroomPid !== void 0 && !ports.isRunning(headroomPid);
@@ -68099,8 +68262,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68099
68262
  writeOwnState({
68100
68263
  supervisorPid: ports.ownPid,
68101
68264
  version: version2,
68102
- installedSource,
68103
- ...sticky()
68265
+ installedSource
68104
68266
  });
68105
68267
  }
68106
68268
  if (consecutiveFailures >= HEADROOM_START_RETRY_BUDGET) {
@@ -68109,41 +68271,32 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68109
68271
  if (installedSource !== config2.source && !ensureInstalled()) {
68110
68272
  return fail(`could not install headroom from ${config2.source}: install failed (is uv installed and on PATH?)`);
68111
68273
  }
68112
- const previousSticky = lastPort;
68113
- const port = lastPort !== void 0 && await ports.isPortFree(lastPort) ? lastPort : await ports.freePort();
68114
- const pid = ports.spawnHeadroom(port, allowlist, config2.settings);
68115
- const ready = await waitUntilReady(ports, port);
68274
+ const pid = ports.spawnHeadroom(socketPath, allowlist, config2.settings);
68275
+ const ready = await waitUntilReady(ports, socketPath);
68116
68276
  if (ready) {
68117
68277
  consecutiveFailures = 0;
68118
68278
  headroomPid = pid;
68119
68279
  runningHash = allowlistHash;
68120
68280
  runningSettingsHash = settingsHash;
68121
- lastPort = port;
68122
- if (previousSticky !== void 0 && port !== previousSticky) {
68123
- ports.log(
68124
- `agent-shim headroom supervisor: sticky port ${String(previousSticky)} was occupied; moving to ${String(port)} (sessions launched against the old port are stale until they relaunch)`
68125
- );
68126
- }
68127
68281
  const recorded = writeOwnState({
68128
68282
  supervisorPid: ports.ownPid,
68129
68283
  headroomPid: pid,
68130
- port,
68284
+ socketPath,
68131
68285
  version: version2,
68132
68286
  allowlistHash,
68133
68287
  settingsHash,
68134
- installedSource: config2.source,
68135
- ...sticky()
68288
+ installedSource: config2.source
68136
68289
  });
68137
68290
  if (recorded) {
68138
68291
  fs19.removeRecursive(paths.headroomLockFile);
68139
68292
  }
68140
68293
  idleSince = void 0;
68141
- ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on 127.0.0.1:${String(port)}`);
68294
+ ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
68142
68295
  } else {
68143
68296
  ports.stopProcess(pid);
68144
68297
  consecutiveFailures += 1;
68145
68298
  ports.log(
68146
- `agent-shim headroom supervisor: headroom did not become ready on port ${String(port)} (attempt ${String(consecutiveFailures)} of ${String(HEADROOM_START_RETRY_BUDGET)})`
68299
+ `agent-shim headroom supervisor: headroom did not become ready on unix socket ${socketPath} (attempt ${String(consecutiveFailures)} of ${String(HEADROOM_START_RETRY_BUDGET)})`
68147
68300
  );
68148
68301
  await ports.sleep(backoffForAttempt(consecutiveFailures));
68149
68302
  continue;
@@ -68168,10 +68321,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
68168
68321
  `agent-shim headroom supervisor: no sessions for ${String(config2.idleShutdownMinutes)} minute(s); stopping headroom and exiting`
68169
68322
  );
68170
68323
  ports.stopProcess(headroomPid);
68171
- writeOwnState({
68172
- version: version2,
68173
- ...sticky()
68174
- });
68324
+ writeOwnState({ version: version2 });
68175
68325
  return 0;
68176
68326
  }
68177
68327
  } else {
@@ -68188,10 +68338,10 @@ function currentHeadroomAllowlist(fs19, paths) {
68188
68338
  function allowlistOf(ports) {
68189
68339
  return currentHeadroomAllowlist(ports.fs, ports.paths);
68190
68340
  }
68191
- async function waitUntilReady(ports, port) {
68341
+ async function waitUntilReady(ports, socketPath) {
68192
68342
  const deadline = ports.now() + HEADROOM_READY_TIMEOUT_MS;
68193
68343
  for (; ; ) {
68194
- if (await ports.ready(port)) {
68344
+ if (await ports.ready(socketPath)) {
68195
68345
  return true;
68196
68346
  }
68197
68347
  if (ports.now() >= deadline) {
@@ -68231,11 +68381,11 @@ function formatHeadroomStatus(status) {
68231
68381
  `supervisor: pid ${String(status.state.supervisorPid)} (${status.supervisorAlive ? "alive" : "NOT running"})`
68232
68382
  );
68233
68383
  }
68234
- if (status.state.headroomPid === void 0 || status.state.port === void 0) {
68384
+ if (status.state.headroomPid === void 0 || status.state.socketPath === void 0) {
68235
68385
  lines.push("headroom: not running");
68236
68386
  } else {
68237
68387
  lines.push(
68238
- `headroom: pid ${String(status.state.headroomPid)} (${status.headroomAlive ? "alive" : "NOT running"}), listening on 127.0.0.1:${String(status.state.port)}` + (status.state.version === void 0 ? "" : `, ${status.state.version}`)
68388
+ `headroom: pid ${String(status.state.headroomPid)} (${status.headroomAlive ? "alive" : "NOT running"}), listening on unix socket ${status.state.socketPath}` + (status.state.version === void 0 ? "" : `, ${status.state.version}`)
68239
68389
  );
68240
68390
  }
68241
68391
  const drift = status.allowlistDrifted ? " (DRIFTED: current provider files differ from the running daemon's allowlist; a restart is pending)" : "";
@@ -68257,50 +68407,54 @@ function formatHeadroomStatus(status) {
68257
68407
  lines.push(`daemon log: ${status.logPath}${status.logExists ? "" : " (not created yet)"}`);
68258
68408
  return lines;
68259
68409
  }
68260
- async function realFreePort() {
68261
- return await new Promise((resolve, reject) => {
68262
- const server = import_node_net3.default.createServer();
68263
- server.unref();
68264
- server.on("error", reject);
68265
- server.listen(0, "127.0.0.1", () => {
68266
- const address = server.address();
68267
- const port = typeof address === "object" && address !== null ? address.port : 0;
68268
- server.close(() => {
68269
- if (port === 0) {
68270
- reject(new Error("could not reserve a loopback port"));
68271
- return;
68272
- }
68273
- resolve(port);
68274
- });
68275
- });
68276
- });
68277
- }
68278
68410
  var ownedHeadroom = /* @__PURE__ */ new Map();
68279
68411
  var exitedHeadroom = /* @__PURE__ */ new Set();
68280
68412
  var READY_FETCH_TIMEOUT_MS = 2e3;
68281
68413
  function headroomPidRunning(pid) {
68282
68414
  return !exitedHeadroom.has(pid) && realIsProcessRunning(pid);
68283
68415
  }
68284
- function headroomSpawnEnv(parentEnv, allowlist, settings2) {
68416
+ function headroomSpawnEnv(parentEnv, allowlist, settings2, caBundle) {
68417
+ const inherited = { ...parentEnv };
68418
+ delete inherited.HEADROOM_HOST;
68419
+ delete inherited.HEADROOM_PORT;
68285
68420
  return {
68286
- ...parentEnv,
68421
+ ...inherited,
68287
68422
  HEADROOM_ALLOWED_BASE_URLS: allowlist.join(","),
68288
68423
  HEADROOM_HTTP2: parentEnv.HEADROOM_HTTP2 ?? "0",
68424
+ // A transparent-interception deployment redirects the API host's address machine-wide, so headroom's own Python dials reach the front door's leaf instead of the origin's public certificate, and Python trusts only the system store: point its two trust variables (urllib3/httpx read both) at the door's combined bundle, which carries the system-equivalent anchors alongside the door's CA. An explicit value in the parent environment always wins, exactly like HEADROOM_HTTP2.
68425
+ ...caBundle === void 0 || parentEnv.REQUESTS_CA_BUNDLE !== void 0 || parentEnv.SSL_CERT_FILE !== void 0 ? {} : { REQUESTS_CA_BUNDLE: caBundle, SSL_CERT_FILE: caBundle },
68289
68426
  ...settingsEnv(settings2)
68290
68427
  };
68291
68428
  }
68429
+ function headroomProxyArgs(socketPath, settings2) {
68430
+ return ["proxy", "--uds", socketPath, ...settingsArgs(settings2)];
68431
+ }
68432
+ async function readyOverSocket(socketPath) {
68433
+ return await new Promise((resolve) => {
68434
+ const probe = import_node_http2.default.get({ socketPath, path: "/readyz", timeout: READY_FETCH_TIMEOUT_MS }, (response) => {
68435
+ response.resume();
68436
+ resolve(response.statusCode === HTTP_STATUS.ok);
68437
+ });
68438
+ probe.on("timeout", () => {
68439
+ probe.destroy();
68440
+ });
68441
+ probe.on("error", () => {
68442
+ resolve(false);
68443
+ });
68444
+ });
68445
+ }
68292
68446
  var HEADROOM_TOOL_NAME = "headroom-ai";
68293
68447
  function readInstalledHeadroomCommit() {
68294
68448
  const toolDir = (0, import_node_child_process5.spawnSync)("uv", ["tool", "dir"], { encoding: "utf8" });
68295
68449
  if (toolDir.status !== 0) {
68296
68450
  return void 0;
68297
68451
  }
68298
- const libDir = import_node_path34.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
68452
+ const libDir = import_node_path35.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
68299
68453
  for (const python of realFarmFs.readdir(libDir)) {
68300
- const sitePackages = import_node_path34.default.join(libDir, python, "site-packages");
68454
+ const sitePackages = import_node_path35.default.join(libDir, python, "site-packages");
68301
68455
  for (const entry of realFarmFs.readdir(sitePackages)) {
68302
68456
  if (entry.startsWith("headroom_ai-") && entry.endsWith(".dist-info")) {
68303
- const directUrl = realFarmFs.readFileUtf8(import_node_path34.default.join(sitePackages, entry, "direct_url.json"));
68457
+ const directUrl = realFarmFs.readFileUtf8(import_node_path35.default.join(sitePackages, entry, "direct_url.json"));
68304
68458
  return directUrl === void 0 ? void 0 : parseInstalledCommit(directUrl);
68305
68459
  }
68306
68460
  }
@@ -68320,17 +68474,17 @@ function realSupervisorPorts(paths) {
68320
68474
  });
68321
68475
  },
68322
68476
  isRunning: headroomPidRunning,
68323
- freePort: realFreePort,
68324
- isPortFree: realIsPortFree,
68477
+ socketTrust: realHeadroomSocketTrust,
68325
68478
  readConfig: () => resolveSupervisorConfig(readGlobalConfig(paths)?.headroom ?? {}),
68326
- spawnHeadroom: (port, allowlist, settings2) => {
68479
+ spawnHeadroom: (socketPath, allowlist, settings2) => {
68480
+ const caBundle = import_node_fs15.default.existsSync(paths.frontdoorCaCertFile) ? import_node_fs15.default.readFileSync(paths.frontdoorCaCertFile, "utf8") : void 0;
68327
68481
  import_node_fs15.default.mkdirSync(paths.logsDir, { recursive: true });
68328
68482
  const logFd = import_node_fs15.default.openSync(paths.headroomLogPath, "a");
68329
68483
  try {
68330
- const child = (0, import_node_child_process5.spawn)("headroom", ["proxy", "--host", "127.0.0.1", "--port", String(port), ...settingsArgs(settings2)], {
68484
+ const child = (0, import_node_child_process5.spawn)("headroom", headroomProxyArgs(socketPath, settings2), {
68331
68485
  detached: true,
68332
68486
  stdio: ["ignore", logFd, logFd],
68333
- env: headroomSpawnEnv(process.env, allowlist, settings2)
68487
+ env: headroomSpawnEnv(process.env, allowlist, settings2, caBundle)
68334
68488
  });
68335
68489
  if (child.pid === void 0) {
68336
68490
  throw new Error("spawning headroom returned no pid");
@@ -68365,14 +68519,7 @@ function realSupervisorPorts(paths) {
68365
68519
  );
68366
68520
  }
68367
68521
  },
68368
- ready: async (port) => {
68369
- try {
68370
- const response = await fetch(`http://127.0.0.1:${String(port)}/readyz`, { signal: AbortSignal.timeout(READY_FETCH_TIMEOUT_MS) });
68371
- return response.ok;
68372
- } catch {
68373
- return false;
68374
- }
68375
- },
68522
+ ready: readyOverSocket,
68376
68523
  install: (spec) => {
68377
68524
  const result = (0, import_node_child_process5.spawnSync)("uv", ["tool", "install", spec], { encoding: "utf8" });
68378
68525
  if (result.error !== void 0) {
@@ -68404,7 +68551,7 @@ function registerHeadroomCommand(program2, deps) {
68404
68551
  "agent-shim headroom status"
68405
68552
  ]);
68406
68553
  withExamples(
68407
- headroom.command("status").description("Report the headroom daemon's supervisor, process, port, sessions, and last error. Read-only.").option("--json", "Print the status as JSON.").action((options) => {
68554
+ headroom.command("status").description("Report the headroom daemon's supervisor, process, socket, sessions, and last error. Read-only.").option("--json", "Print the status as JSON.").action((options) => {
68408
68555
  const status = collectHeadroomStatus(realFarmFs, paths, realIsProcessRunning);
68409
68556
  if (options.json === true) {
68410
68557
  printJson(status);
@@ -69249,11 +69396,11 @@ function probeFrontDoorSync(port, caPem) {
69249
69396
 
69250
69397
  // src/frontdoor/trust.ts
69251
69398
  var import_node_crypto14 = require("node:crypto");
69252
- var import_node_path35 = __toESM(require("node:path"), 1);
69399
+ var import_node_path36 = __toESM(require("node:path"), 1);
69253
69400
  var BUNDLE_NAME_HEX_DIGITS = 16;
69254
69401
  function resolveTrustBundle(params) {
69255
69402
  const { caCertFile, bundlesDir, inherited, fs: fs19 } = params;
69256
- if (inherited === void 0 || inherited === "" || import_node_path35.default.resolve(inherited) === import_node_path35.default.resolve(caCertFile)) {
69403
+ if (inherited === void 0 || inherited === "" || import_node_path36.default.resolve(inherited) === import_node_path36.default.resolve(caCertFile)) {
69257
69404
  return { path: caCertFile };
69258
69405
  }
69259
69406
  const caPem = fs19.readFileUtf8(caCertFile);
@@ -69271,7 +69418,7 @@ function resolveTrustBundle(params) {
69271
69418
  }
69272
69419
  const combined = `${inheritedPem.trimEnd()}
69273
69420
  ${caPem}`;
69274
- const bundle = import_node_path35.default.join(bundlesDir, `${(0, import_node_crypto14.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
69421
+ const bundle = import_node_path36.default.join(bundlesDir, `${(0, import_node_crypto14.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
69275
69422
  if (!fs19.exists(bundle)) {
69276
69423
  fs19.mkdirp(bundlesDir);
69277
69424
  fs19.writeFileAtomic(bundle, combined);
@@ -69326,7 +69473,7 @@ function realFrontDoorPort(paths, spawnDaemon) {
69326
69473
 
69327
69474
  // src/launcher.ts
69328
69475
  var import_node_crypto15 = require("node:crypto");
69329
- var import_node_path37 = __toESM(require("node:path"), 1);
69476
+ var import_node_path38 = __toESM(require("node:path"), 1);
69330
69477
 
69331
69478
  // src/launcher/cliOverride.ts
69332
69479
  var InvalidCliCategoryError = class extends CliError {
@@ -69410,7 +69557,7 @@ function buildCliOverride(params) {
69410
69557
  }
69411
69558
 
69412
69559
  // src/launcher/flags.ts
69413
- var import_node_path36 = __toESM(require("node:path"), 1);
69560
+ var import_node_path37 = __toESM(require("node:path"), 1);
69414
69561
 
69415
69562
  // src/headroom/headers.ts
69416
69563
  function mergeAnthropicCustomHeaders(existing, additions) {
@@ -69480,7 +69627,7 @@ function buildEnv(params) {
69480
69627
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
69481
69628
  let providerCustomHeaders;
69482
69629
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
69483
- env.CLAUDE_CONFIG_DIR = import_node_path36.default.join(params.identitiesDir, params.resolvedIdentityName);
69630
+ env.CLAUDE_CONFIG_DIR = import_node_path37.default.join(params.identitiesDir, params.resolvedIdentityName);
69484
69631
  }
69485
69632
  if (params.provider !== void 0) {
69486
69633
  const providerEnv = params.provider.definition.env ?? {};
@@ -69501,9 +69648,6 @@ function buildEnv(params) {
69501
69648
  env[variable] = value;
69502
69649
  }
69503
69650
  }
69504
- if (params.headroom !== void 0) {
69505
- env.HEADROOM_PROXY_URL = `http://127.0.0.1:${String(params.headroom.port)}`;
69506
- }
69507
69651
  if (params.frontdoor !== void 0) {
69508
69652
  env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
69509
69653
  [
@@ -69667,7 +69811,7 @@ function prepareLaunch(params) {
69667
69811
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
69668
69812
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
69669
69813
  });
69670
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs19.readConfigFile(import_node_path37.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
69814
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs19.readConfigFile(import_node_path38.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
69671
69815
  log.error(
69672
69816
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
69673
69817
  );
@@ -69803,7 +69947,7 @@ function prepareLaunch(params) {
69803
69947
  if (resolvedFlags.headroom && headroomPort !== void 0) {
69804
69948
  headroom = headroomPort.ensure();
69805
69949
  const via = resolvedProvider === void 0 ? `OAuth via the door's CONNECT surface on 127.0.0.1:${String(frontDoor?.connectPort ?? 0)}` : `provider ${resolvedProvider.name}`;
69806
- log.info(`agent-shim: routing through the front door on 127.0.0.1:${String(frontDoor?.port ?? 0)} with headroom on 127.0.0.1:${String(headroom.port)} (${via}, project ${headroom.projectId})`);
69950
+ log.info(`agent-shim: routing through the front door on 127.0.0.1:${String(frontDoor?.port ?? 0)} with headroom on unix socket ${headroom.socketPath} (${via}, project ${headroom.projectId})`);
69807
69951
  } else if (resolvedFlags.headroom) {
69808
69952
  log.error("agent-shim: headroom routing was requested but this launcher has no headroom port wired; refusing to launch without it.");
69809
69953
  proc.exit(1);
@@ -69967,7 +70111,7 @@ async function runClaude(argvOverride) {
69967
70111
  // src/cli.ts
69968
70112
  async function main() {
69969
70113
  aliasLegacyEnv(process.env);
69970
- const invokedName = import_node_path38.default.basename(process.argv[1] ?? "agent-shim");
70114
+ const invokedName = import_node_path39.default.basename(process.argv[1] ?? "agent-shim");
69971
70115
  if (isInvokedAsClaude(invokedName)) {
69972
70116
  await runClaude();
69973
70117
  return;