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/index.cjs CHANGED
@@ -413,7 +413,7 @@ var HeadroomGlobalConfigSchema = HeadroomGlobalConfigObjectSchema.superRefine((c
413
413
  context.addIssue({ code: "custom", path: ["readMaturation"], message: "readMaturation needs rolloutChannel beta or dev" });
414
414
  }
415
415
  });
416
- var HEADROOM_DEFAULT_SOURCE = "headroom-ai[proxy] @ git+https://github.com/ExaDev/headroom@ecd1c351fcfed97499721e86852e148436ff2ee6";
416
+ var HEADROOM_DEFAULT_SOURCE = "headroom-ai[proxy] @ git+https://github.com/ExaDev/headroom@53525f479f2f48e8ef6b08cf729601feab7d2382";
417
417
  var HEADROOM_DEFAULT_IDLE_SHUTDOWN_MINUTES = 15;
418
418
  var FrontDoorGlobalConfigSchema = import_zod.z.strictObject({
419
419
  /** How long the front door may sit with no registered sessions before it closes and exits. Defaults to FRONTDOOR_DEFAULT_IDLE_SHUTDOWN_MINUTES. */
@@ -2650,7 +2650,7 @@ function providerBaseUrl(port, provider) {
2650
2650
  // src/frontdoor/state.ts
2651
2651
  var import_node_path7 = __toESM(require("node:path"), 1);
2652
2652
  var import_zod3 = require("zod");
2653
- var FRONT_DOOR_PROTOCOL = 1;
2653
+ var FRONT_DOOR_PROTOCOL = 2;
2654
2654
  var FrontDoorSessionSchema = import_zod3.z.strictObject({ pid: import_zod3.z.number().int().positive(), startedAt: import_zod3.z.number(), token: import_zod3.z.string().min(1) });
2655
2655
  var FrontDoorStateSchema = import_zod3.z.strictObject({
2656
2656
  /**
@@ -2875,8 +2875,8 @@ function parseConnectTarget(authority) {
2875
2875
  function isInterceptedHost(host, interceptHosts) {
2876
2876
  return interceptHosts.includes(host);
2877
2877
  }
2878
- function servedByPipeline(path28) {
2879
- return path28?.startsWith(ROUTED_PATH_PREFIX) === true;
2878
+ function servedByPipeline(path29) {
2879
+ return path29?.startsWith(ROUTED_PATH_PREFIX) === true;
2880
2880
  }
2881
2881
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
2882
2882
  "connection",
@@ -3209,13 +3209,63 @@ function realConnectCertStore(paths) {
3209
3209
  }
3210
3210
 
3211
3211
  // src/frontdoor/connectEffects.ts
3212
+ var dns = __toESM(require("node:dns"), 1);
3212
3213
  var http = __toESM(require("node:http"), 1);
3213
3214
  var https = __toESM(require("node:https"), 1);
3214
3215
  var net2 = __toESM(require("node:net"), 1);
3215
3216
  var tls = __toESM(require("node:tls"), 1);
3217
+ var UPSTREAM_LOCAL_PORT_START = 47900;
3218
+ var UPSTREAM_LOCAL_PORT_END = 47919;
3219
+ var nextUpstreamLocalPort = UPSTREAM_LOCAL_PORT_START;
3220
+ function upstreamLocalPort() {
3221
+ const port = nextUpstreamLocalPort;
3222
+ nextUpstreamLocalPort = nextUpstreamLocalPort === UPSTREAM_LOCAL_PORT_END ? UPSTREAM_LOCAL_PORT_START : nextUpstreamLocalPort + 1;
3223
+ return port;
3224
+ }
3225
+ var realAddressLookup = (host, _options, callback) => {
3226
+ if (net2.isIP(host) !== 0) {
3227
+ callback(null, [{ address: host, family: net2.isIP(host) }]);
3228
+ return;
3229
+ }
3230
+ dns.resolve4(host, (error, addresses) => {
3231
+ const first = addresses[0];
3232
+ if (error !== null || first === void 0) {
3233
+ callback(error ?? new Error(`no A record for ${host}`), [{ address: "", family: 4 }]);
3234
+ return;
3235
+ }
3236
+ callback(null, [{ address: first, family: 4 }]);
3237
+ });
3238
+ };
3239
+ var HTTP_PORT = 80;
3240
+ function exemptDial(options, defaultPort) {
3241
+ const host = typeof options.host === "string" ? options.host : "";
3242
+ const port = typeof options.port === "number" ? options.port : defaultPort;
3243
+ return net2.connect(net2.isIP(host) === 0 ? { host, port, localPort: upstreamLocalPort(), lookup: realAddressLookup } : { host, port });
3244
+ }
3245
+ function requestServername(options, fallback) {
3246
+ return "servername" in options && typeof options.servername === "string" && options.servername !== "" ? options.servername : fallback;
3247
+ }
3248
+ var ExemptHttpAgent = class extends http.Agent {
3249
+ createConnection(options) {
3250
+ return exemptDial(options, HTTP_PORT);
3251
+ }
3252
+ };
3253
+ var ExemptTlsAgent = class extends https.Agent {
3254
+ createConnection(options) {
3255
+ const host = typeof options.host === "string" ? options.host : "";
3256
+ const tlsOptions = { socket: exemptDial(options, HTTPS_PORT), servername: requestServername(options, host) };
3257
+ if ("ca" in options && Array.isArray(options.ca)) {
3258
+ tlsOptions.ca = options.ca;
3259
+ }
3260
+ if ("rejectUnauthorized" in options && typeof options.rejectUnauthorized === "boolean") {
3261
+ tlsOptions.rejectUnauthorized = options.rejectUnauthorized;
3262
+ }
3263
+ return tls.connect(tlsOptions);
3264
+ }
3265
+ };
3216
3266
  function realConnectEffects() {
3217
- const plainAgent = new http.Agent({ keepAlive: true });
3218
- const tlsAgent = new https.Agent({ keepAlive: true });
3267
+ const plainAgent = new ExemptHttpAgent();
3268
+ const tlsAgent = new ExemptTlsAgent();
3219
3269
  const listenOnce = async (port, onSocket) => await new Promise((resolve, reject) => {
3220
3270
  const accepted = /* @__PURE__ */ new Set();
3221
3271
  const server = net2.createServer((socket) => {
@@ -3301,11 +3351,23 @@ function realConnectEffects() {
3301
3351
  };
3302
3352
  },
3303
3353
  connectTlsUpstream: async (host, port, clientAlpn) => await new Promise((resolve, reject) => {
3304
- const socket = tls.connect({ host, port, servername: host, ...clientAlpn === void 0 ? {} : { ALPNProtocols: [clientAlpn] } });
3305
- socket.once("secureConnect", () => {
3306
- resolve(socket);
3307
- });
3308
- socket.once("error", reject);
3354
+ const dial = (localPort) => {
3355
+ const raw = net2.connect({ host, port, localPort, lookup: realAddressLookup });
3356
+ return tls.connect({ socket: raw, servername: host, ...clientAlpn === void 0 ? {} : { ALPNProtocols: [clientAlpn] } });
3357
+ };
3358
+ const settle = (candidate) => {
3359
+ candidate.once("secureConnect", () => {
3360
+ resolve(candidate);
3361
+ });
3362
+ candidate.once("error", (error) => {
3363
+ if ("code" in error && error.code === "EADDRINUSE") {
3364
+ settle(dial(upstreamLocalPort()));
3365
+ return;
3366
+ }
3367
+ reject(error);
3368
+ });
3369
+ };
3370
+ settle(dial(upstreamLocalPort()));
3309
3371
  }),
3310
3372
  connectTcp: async (host, port) => await new Promise((resolve, reject) => {
3311
3373
  const socket = net2.connect({ host, port });
@@ -3319,6 +3381,7 @@ function realConnectEffects() {
3319
3381
  const options = {
3320
3382
  host: target.host,
3321
3383
  port: target.port,
3384
+ lookup: realAddressLookup,
3322
3385
  method: request3.method,
3323
3386
  path: request3.url,
3324
3387
  headers,
@@ -3379,17 +3442,16 @@ var import_node_crypto5 = require("node:crypto");
3379
3442
  var import_node_path8 = __toESM(require("node:path"), 1);
3380
3443
  var import_zod4 = require("zod");
3381
3444
  var HEADROOM_ANTHROPIC_UPSTREAM = "https://api.anthropic.com";
3445
+ var HEADROOM_STATE_SCHEMA_VERSION = 2;
3382
3446
  var HeadroomStateSchema = import_zod4.z.strictObject({
3383
3447
  /** The supervisor process owning the daemon. Alive means someone is keeping headroom running. */
3384
3448
  supervisorPid: import_zod4.z.number().int().positive().optional(),
3385
3449
  /** The headroom proxy process itself. Absent while the supervisor is between restarts. */
3386
3450
  headroomPid: import_zod4.z.number().int().positive().optional(),
3387
- /** 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. */
3388
- port: import_zod4.z.number().int().positive().optional(),
3389
3451
  /**
3390
- * 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.
3452
+ * 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.
3391
3453
  */
3392
- lastPort: import_zod4.z.number().int().positive().optional(),
3454
+ socketPath: import_zod4.z.string().min(1).optional(),
3393
3455
  /** The `headroom --version` output of the running install. */
3394
3456
  version: import_zod4.z.string().optional(),
3395
3457
  /** Hash of the allowlist the running proxy was started with, so a provider-file change is detected as drift. */
@@ -3896,10 +3958,10 @@ function ensureHeadroom(params) {
3896
3958
  for (; ; ) {
3897
3959
  const state = readHeadroomState(ports.fs, paths.headroomStateFile);
3898
3960
  if (state?.supervisorPid !== void 0 && ports.isRunning(state.supervisorPid)) {
3899
- const daemonUp = state.port !== void 0 && state.headroomPid !== void 0 && ports.isRunning(state.headroomPid);
3900
- if (daemonUp && state.port !== void 0) {
3961
+ const daemonUp = state.socketPath !== void 0 && state.headroomPid !== void 0 && ports.isRunning(state.headroomPid);
3962
+ if (daemonUp && state.socketPath !== void 0) {
3901
3963
  writeSession(ports.fs, paths.headroomSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), supervisorPid: state.supervisorPid });
3902
- return { port: state.port };
3964
+ return { socketPath: state.socketPath };
3903
3965
  }
3904
3966
  if (state.lastError !== void 0) {
3905
3967
  throw new HeadroomStartError(
@@ -3963,6 +4025,71 @@ function hashSettings(settings) {
3963
4025
  return (0, import_node_crypto7.createHash)("sha256").update(JSON.stringify([...settingsArgs(settings), JSON.stringify(settingsEnv(settings))])).digest("hex");
3964
4026
  }
3965
4027
 
4028
+ // src/headroom/socket.ts
4029
+ var import_node_path11 = __toESM(require("node:path"), 1);
4030
+ var GROUP_OR_OTHER_BITS = 63;
4031
+ var OCTAL_RADIX = 8;
4032
+ var MODE_DIGITS = 4;
4033
+ var HEADROOM_SOCKET_SUFFIX = ".sock";
4034
+ var HEADROOM_SOCKET_NAME = /^(\d+)\.sock$/;
4035
+ var UNIX_SOCKET_PATH_MAX_BYTES = 103;
4036
+ var PLATFORMS_WITHOUT_UNIX_SOCKETS = ["win32"];
4037
+ function headroomSocketPath(paths, supervisorPid) {
4038
+ return import_node_path11.default.join(paths.headroomSocketDir, `${String(supervisorPid)}${HEADROOM_SOCKET_SUFFIX}`);
4039
+ }
4040
+ function platformRefusal(platform) {
4041
+ 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;
4042
+ }
4043
+ function ownerOnlyRefusal(label, target, stat, expected, uid) {
4044
+ if (stat === void 0) {
4045
+ return `the headroom ${label} ${target} does not exist`;
4046
+ }
4047
+ if (stat.kind === "symlink") {
4048
+ return `the headroom ${label} ${target} is a symlink; it must be the real ${expected === "dir" ? "directory" : "socket"}`;
4049
+ }
4050
+ if (stat.kind !== expected) {
4051
+ return `the headroom ${label} ${target} is not a ${expected === "dir" ? "directory" : "socket"}`;
4052
+ }
4053
+ if (stat.uid !== uid) {
4054
+ return `the headroom ${label} ${target} is owned by uid ${String(stat.uid)}, not by this user (uid ${String(uid)})`;
4055
+ }
4056
+ if ((stat.mode & GROUP_OR_OTHER_BITS) !== 0) {
4057
+ return `the headroom ${label} ${target} has mode ${stat.mode.toString(OCTAL_RADIX).padStart(MODE_DIGITS, "0")}, which lets other users reach it; it must be accessible to its owner only`;
4058
+ }
4059
+ return void 0;
4060
+ }
4061
+ function prepareHeadroomSocket(fs12, ports, paths, supervisorPid) {
4062
+ const unsupported = platformRefusal(ports.platform);
4063
+ if (unsupported !== void 0) {
4064
+ return { refused: unsupported };
4065
+ }
4066
+ const socketPath = headroomSocketPath(paths, supervisorPid);
4067
+ const length = Buffer.byteLength(socketPath, "utf8");
4068
+ if (length > UNIX_SOCKET_PATH_MAX_BYTES) {
4069
+ return {
4070
+ 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`
4071
+ };
4072
+ }
4073
+ if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
4074
+ return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
4075
+ }
4076
+ fs12.mkdirPrivate(paths.headroomSocketDir);
4077
+ const refusal = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
4078
+ return refusal === void 0 ? { socketPath } : { refused: refusal };
4079
+ }
4080
+ function pruneStaleHeadroomSockets(fs12, paths, isRunning) {
4081
+ const removed = [];
4082
+ for (const name of fs12.readdir(paths.headroomSocketDir)) {
4083
+ const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
4084
+ if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
4085
+ continue;
4086
+ }
4087
+ fs12.removeRecursive(import_node_path11.default.join(paths.headroomSocketDir, name));
4088
+ removed.push(name);
4089
+ }
4090
+ return removed;
4091
+ }
4092
+
3966
4093
  // src/headroom/source.ts
3967
4094
  var import_zod6 = require("zod");
3968
4095
  var GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
@@ -4058,8 +4185,6 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4058
4185
  return 0;
4059
4186
  }
4060
4187
  let installedSource = previousState?.installedSource;
4061
- let lastPort = previousState?.lastPort;
4062
- const sticky = () => lastPort === void 0 ? {} : { lastPort };
4063
4188
  const ownsState = () => {
4064
4189
  const owner = readHeadroomState(fs12, paths.headroomStateFile)?.supervisorPid;
4065
4190
  return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
@@ -4072,7 +4197,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4072
4197
  return true;
4073
4198
  };
4074
4199
  const fail = (message) => {
4075
- if (writeOwnState({ lastError: message, ...sticky() })) {
4200
+ if (writeOwnState({ lastError: message })) {
4076
4201
  fs12.removeRecursive(paths.headroomLockFile);
4077
4202
  }
4078
4203
  ports.log(`agent-shim headroom supervisor: ${message}`);
@@ -4095,11 +4220,17 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4095
4220
  installedSource = config.source;
4096
4221
  return true;
4097
4222
  };
4223
+ const socket = prepareHeadroomSocket(fs12, ports.socketTrust, paths, ports.ownPid);
4224
+ if (socket.refused !== void 0) {
4225
+ return fail(socket.refused);
4226
+ }
4227
+ const { socketPath } = socket;
4228
+ pruneStaleHeadroomSockets(fs12, paths, ports.isRunning);
4098
4229
  if (!ensureInstalled()) {
4099
4230
  return fail(`could not install headroom from ${config.source}: install failed (is uv installed and on PATH?)`);
4100
4231
  }
4101
4232
  const version = ports.headroomVersion() ?? "unknown";
4102
- writeOwnState({ supervisorPid: ports.ownPid, version, installedSource, ...sticky() });
4233
+ writeOwnState({ supervisorPid: ports.ownPid, version, installedSource });
4103
4234
  ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${allowlistOf(ports).join(", ")}]`);
4104
4235
  const orphanPid = previousState?.headroomPid;
4105
4236
  if (orphanPid !== void 0 && ports.isRunning(orphanPid)) {
@@ -4125,7 +4256,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4125
4256
  pruneDeadSessions(fs12, paths.headroomSessionsDir, ports.isRunning);
4126
4257
  const ownsNow = ownsState();
4127
4258
  if (!ownsNow && !superseded) {
4128
- ports.log("agent-shim headroom supervisor: another supervisor now owns state.json; serving this daemon's own sessions until they end");
4259
+ ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
4129
4260
  }
4130
4261
  superseded = !ownsNow;
4131
4262
  const crashed = headroomPid !== void 0 && !ports.isRunning(headroomPid);
@@ -4138,8 +4269,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4138
4269
  writeOwnState({
4139
4270
  supervisorPid: ports.ownPid,
4140
4271
  version,
4141
- installedSource,
4142
- ...sticky()
4272
+ installedSource
4143
4273
  });
4144
4274
  }
4145
4275
  if (consecutiveFailures >= HEADROOM_START_RETRY_BUDGET) {
@@ -4148,41 +4278,32 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4148
4278
  if (installedSource !== config.source && !ensureInstalled()) {
4149
4279
  return fail(`could not install headroom from ${config.source}: install failed (is uv installed and on PATH?)`);
4150
4280
  }
4151
- const previousSticky = lastPort;
4152
- const port = lastPort !== void 0 && await ports.isPortFree(lastPort) ? lastPort : await ports.freePort();
4153
- const pid = ports.spawnHeadroom(port, allowlist, config.settings);
4154
- const ready = await waitUntilReady(ports, port);
4281
+ const pid = ports.spawnHeadroom(socketPath, allowlist, config.settings);
4282
+ const ready = await waitUntilReady(ports, socketPath);
4155
4283
  if (ready) {
4156
4284
  consecutiveFailures = 0;
4157
4285
  headroomPid = pid;
4158
4286
  runningHash = allowlistHash;
4159
4287
  runningSettingsHash = settingsHash;
4160
- lastPort = port;
4161
- if (previousSticky !== void 0 && port !== previousSticky) {
4162
- ports.log(
4163
- `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)`
4164
- );
4165
- }
4166
4288
  const recorded = writeOwnState({
4167
4289
  supervisorPid: ports.ownPid,
4168
4290
  headroomPid: pid,
4169
- port,
4291
+ socketPath,
4170
4292
  version,
4171
4293
  allowlistHash,
4172
4294
  settingsHash,
4173
- installedSource: config.source,
4174
- ...sticky()
4295
+ installedSource: config.source
4175
4296
  });
4176
4297
  if (recorded) {
4177
4298
  fs12.removeRecursive(paths.headroomLockFile);
4178
4299
  }
4179
4300
  idleSince = void 0;
4180
- ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on 127.0.0.1:${String(port)}`);
4301
+ ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
4181
4302
  } else {
4182
4303
  ports.stopProcess(pid);
4183
4304
  consecutiveFailures += 1;
4184
4305
  ports.log(
4185
- `agent-shim headroom supervisor: headroom did not become ready on port ${String(port)} (attempt ${String(consecutiveFailures)} of ${String(HEADROOM_START_RETRY_BUDGET)})`
4306
+ `agent-shim headroom supervisor: headroom did not become ready on unix socket ${socketPath} (attempt ${String(consecutiveFailures)} of ${String(HEADROOM_START_RETRY_BUDGET)})`
4186
4307
  );
4187
4308
  await ports.sleep(backoffForAttempt(consecutiveFailures));
4188
4309
  continue;
@@ -4207,10 +4328,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
4207
4328
  `agent-shim headroom supervisor: no sessions for ${String(config.idleShutdownMinutes)} minute(s); stopping headroom and exiting`
4208
4329
  );
4209
4330
  ports.stopProcess(headroomPid);
4210
- writeOwnState({
4211
- version,
4212
- ...sticky()
4213
- });
4331
+ writeOwnState({ version });
4214
4332
  return 0;
4215
4333
  }
4216
4334
  } else {
@@ -4227,10 +4345,10 @@ function currentHeadroomAllowlist(fs12, paths) {
4227
4345
  function allowlistOf(ports) {
4228
4346
  return currentHeadroomAllowlist(ports.fs, ports.paths);
4229
4347
  }
4230
- async function waitUntilReady(ports, port) {
4348
+ async function waitUntilReady(ports, socketPath) {
4231
4349
  const deadline = ports.now() + HEADROOM_READY_TIMEOUT_MS;
4232
4350
  for (; ; ) {
4233
- if (await ports.ready(port)) {
4351
+ if (await ports.ready(socketPath)) {
4234
4352
  return true;
4235
4353
  }
4236
4354
  if (ports.now() >= deadline) {
@@ -4290,14 +4408,14 @@ function evaluateAmbientCredentialGuard(params) {
4290
4408
  // src/paths.ts
4291
4409
  var import_node_fs2 = __toESM(require("node:fs"), 1);
4292
4410
  var import_node_os = __toESM(require("node:os"), 1);
4293
- var import_node_path11 = __toESM(require("node:path"), 1);
4411
+ var import_node_path12 = __toESM(require("node:path"), 1);
4294
4412
  function resolveAgentShimHome(env = process.env, home = import_node_os.default.homedir(), isDirectory = isExistingDirectory) {
4295
4413
  const fromEnv = env.AGENT_SHIM_HOME;
4296
4414
  if (fromEnv !== void 0 && fromEnv !== "") {
4297
4415
  return fromEnv;
4298
4416
  }
4299
- const current = import_node_path11.default.join(home, HOME_DIRNAME);
4300
- const legacy = import_node_path11.default.join(home, LEGACY_HOME_DIRNAME);
4417
+ const current = import_node_path12.default.join(home, HOME_DIRNAME);
4418
+ const legacy = import_node_path12.default.join(home, LEGACY_HOME_DIRNAME);
4301
4419
  return !isDirectory(current) && isDirectory(legacy) ? legacy : current;
4302
4420
  }
4303
4421
  function isExistingDirectory(candidate) {
@@ -4308,38 +4426,39 @@ function resolveClaudeHome() {
4308
4426
  if (fromEnv !== void 0 && fromEnv !== "") {
4309
4427
  return fromEnv;
4310
4428
  }
4311
- return import_node_path11.default.join(import_node_os.default.homedir(), ".claude");
4429
+ return import_node_path12.default.join(import_node_os.default.homedir(), ".claude");
4312
4430
  }
4313
4431
  function buildLayoutPaths(root) {
4314
4432
  return {
4315
4433
  root,
4316
- identitiesDir: import_node_path11.default.join(root, "identities"),
4317
- configProfilesDir: import_node_path11.default.join(root, "config-profiles"),
4318
- providersDir: import_node_path11.default.join(root, "providers"),
4319
- directoryRulesFile: import_node_path11.default.join(root, "directory-rules.json"),
4320
- activeIdentityFile: import_node_path11.default.join(root, "active-identity"),
4321
- globalConfigFile: import_node_path11.default.join(root, "config.json"),
4322
- categoriesLocalFile: import_node_path11.default.join(root, "categories.local.json"),
4323
- claudeShimFile: import_node_path11.default.join(root, "claude-shim.json"),
4324
- headroomDir: import_node_path11.default.join(root, "headroom"),
4325
- headroomStateFile: import_node_path11.default.join(root, "headroom", "state.json"),
4326
- headroomLockFile: import_node_path11.default.join(root, "headroom", "start.lock"),
4327
- headroomSessionsDir: import_node_path11.default.join(root, "headroom", "sessions"),
4328
- logsDir: import_node_path11.default.join(root, "logs"),
4329
- headroomLogPath: import_node_path11.default.join(root, "logs", "headroom.log"),
4330
- frontdoorDir: import_node_path11.default.join(root, "frontdoor"),
4331
- frontdoorCaDir: import_node_path11.default.join(root, "frontdoor", "ca"),
4332
- frontdoorCaCertFile: import_node_path11.default.join(root, "frontdoor", "ca", "ca.pem"),
4333
- frontdoorCaKeyFile: import_node_path11.default.join(root, "frontdoor", "ca", "ca.key"),
4334
- frontdoorCaBundlesDir: import_node_path11.default.join(root, "frontdoor", "ca", "bundles"),
4335
- frontdoorStateFile: import_node_path11.default.join(root, "frontdoor", "state.json"),
4336
- frontdoorLockFile: import_node_path11.default.join(root, "frontdoor", "start.lock"),
4337
- frontdoorSessionsDir: import_node_path11.default.join(root, "frontdoor", "sessions"),
4338
- frontdoorLogPath: import_node_path11.default.join(root, "logs", "frontdoor.log"),
4339
- usageDir: import_node_path11.default.join(root, "usage"),
4340
- usageLogDir: import_node_path11.default.join(root, "usage", "log"),
4341
- usageSnapshotsDir: import_node_path11.default.join(root, "usage", "snapshots"),
4342
- usagePicksFile: import_node_path11.default.join(root, "usage", "picks.json")
4434
+ identitiesDir: import_node_path12.default.join(root, "identities"),
4435
+ configProfilesDir: import_node_path12.default.join(root, "config-profiles"),
4436
+ providersDir: import_node_path12.default.join(root, "providers"),
4437
+ directoryRulesFile: import_node_path12.default.join(root, "directory-rules.json"),
4438
+ activeIdentityFile: import_node_path12.default.join(root, "active-identity"),
4439
+ globalConfigFile: import_node_path12.default.join(root, "config.json"),
4440
+ categoriesLocalFile: import_node_path12.default.join(root, "categories.local.json"),
4441
+ claudeShimFile: import_node_path12.default.join(root, "claude-shim.json"),
4442
+ headroomDir: import_node_path12.default.join(root, "headroom"),
4443
+ headroomStateFile: import_node_path12.default.join(root, "headroom", `state.v${String(HEADROOM_STATE_SCHEMA_VERSION)}.json`),
4444
+ headroomSocketDir: import_node_path12.default.join(root, "headroom", "run"),
4445
+ headroomLockFile: import_node_path12.default.join(root, "headroom", "start.lock"),
4446
+ headroomSessionsDir: import_node_path12.default.join(root, "headroom", "sessions"),
4447
+ logsDir: import_node_path12.default.join(root, "logs"),
4448
+ headroomLogPath: import_node_path12.default.join(root, "logs", "headroom.log"),
4449
+ frontdoorDir: import_node_path12.default.join(root, "frontdoor"),
4450
+ frontdoorCaDir: import_node_path12.default.join(root, "frontdoor", "ca"),
4451
+ frontdoorCaCertFile: import_node_path12.default.join(root, "frontdoor", "ca", "ca.pem"),
4452
+ frontdoorCaKeyFile: import_node_path12.default.join(root, "frontdoor", "ca", "ca.key"),
4453
+ frontdoorCaBundlesDir: import_node_path12.default.join(root, "frontdoor", "ca", "bundles"),
4454
+ frontdoorStateFile: import_node_path12.default.join(root, "frontdoor", "state.json"),
4455
+ frontdoorLockFile: import_node_path12.default.join(root, "frontdoor", "start.lock"),
4456
+ frontdoorSessionsDir: import_node_path12.default.join(root, "frontdoor", "sessions"),
4457
+ frontdoorLogPath: import_node_path12.default.join(root, "logs", "frontdoor.log"),
4458
+ usageDir: import_node_path12.default.join(root, "usage"),
4459
+ usageLogDir: import_node_path12.default.join(root, "usage", "log"),
4460
+ usageSnapshotsDir: import_node_path12.default.join(root, "usage", "snapshots"),
4461
+ usagePicksFile: import_node_path12.default.join(root, "usage", "picks.json")
4343
4462
  };
4344
4463
  }
4345
4464
  function resolveLayoutPaths() {
@@ -4348,10 +4467,10 @@ function resolveLayoutPaths() {
4348
4467
 
4349
4468
  // src/identityStore.ts
4350
4469
  var import_node_fs4 = __toESM(require("node:fs"), 1);
4351
- var import_node_path14 = __toESM(require("node:path"), 1);
4470
+ var import_node_path15 = __toESM(require("node:path"), 1);
4352
4471
 
4353
4472
  // src/launcher/identity.ts
4354
- var import_node_path12 = __toESM(require("node:path"), 1);
4473
+ var import_node_path13 = __toESM(require("node:path"), 1);
4355
4474
  function poolNameOf(selector) {
4356
4475
  return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
4357
4476
  }
@@ -4400,12 +4519,12 @@ function decideConfigProfile(params) {
4400
4519
  return { source: "none" };
4401
4520
  }
4402
4521
  function loadIdentity(identitiesDir, name, fs12) {
4403
- return loadConfigFile(import_node_path12.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs12.readConfigFile);
4522
+ return loadConfigFile(import_node_path13.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs12.readConfigFile);
4404
4523
  }
4405
4524
 
4406
4525
  // src/configProfilesStore.ts
4407
4526
  var import_node_fs3 = __toESM(require("node:fs"), 1);
4408
- var import_node_path13 = __toESM(require("node:path"), 1);
4527
+ var import_node_path14 = __toESM(require("node:path"), 1);
4409
4528
  var ProfileNotFoundError = class extends CliError {
4410
4529
  constructor(profileName) {
4411
4530
  super(`No configuration profile named "${profileName}". Run \`agent-shim profile add ${profileName}\` first.`);
@@ -4431,7 +4550,7 @@ var InvalidCategoryNameError = class extends CliError {
4431
4550
  categoryName;
4432
4551
  };
4433
4552
  function profileJsonPath(paths, name) {
4434
- return import_node_path13.default.join(paths.configProfilesDir, `${name}.json`);
4553
+ return import_node_path14.default.join(paths.configProfilesDir, `${name}.json`);
4435
4554
  }
4436
4555
  function profileExists(paths, name) {
4437
4556
  return import_node_fs3.default.existsSync(profileJsonPath(paths, name));
@@ -4619,7 +4738,7 @@ var InvalidIdentityNameError = class extends CliError {
4619
4738
  attemptedName;
4620
4739
  };
4621
4740
  function identityJsonPath(paths, name) {
4622
- return import_node_path14.default.join(paths.identitiesDir, name, "identity.json");
4741
+ return import_node_path15.default.join(paths.identitiesDir, name, "identity.json");
4623
4742
  }
4624
4743
  function identityExists(paths, name) {
4625
4744
  return import_node_fs4.default.existsSync(identityJsonPath(paths, name));
@@ -4720,7 +4839,7 @@ function setIdentityCredential(paths, identityName, change) {
4720
4839
  });
4721
4840
  }
4722
4841
  function belongsToIdentity(entry, name) {
4723
- return entry === name || entry === import_node_path14.default.basename(identityLockPath("", name)) || entry.startsWith(`.${name}.scratch.`) || entry.startsWith(`.${name}.previous.`);
4842
+ return entry === name || entry === import_node_path15.default.basename(identityLockPath("", name)) || entry.startsWith(`.${name}.scratch.`) || entry.startsWith(`.${name}.previous.`);
4724
4843
  }
4725
4844
  function removeIdentity(paths, name) {
4726
4845
  if (!identityExists(paths, name)) {
@@ -4728,7 +4847,7 @@ function removeIdentity(paths, name) {
4728
4847
  }
4729
4848
  for (const entry of import_node_fs4.default.readdirSync(paths.identitiesDir)) {
4730
4849
  if (belongsToIdentity(entry, name)) {
4731
- import_node_fs4.default.rmSync(import_node_path14.default.join(paths.identitiesDir, entry), { recursive: true, force: true });
4850
+ import_node_fs4.default.rmSync(import_node_path15.default.join(paths.identitiesDir, entry), { recursive: true, force: true });
4732
4851
  }
4733
4852
  }
4734
4853
  if (readActiveIdentity(paths) === name) {
@@ -4738,7 +4857,7 @@ function removeIdentity(paths, name) {
4738
4857
 
4739
4858
  // src/providersStore.ts
4740
4859
  var import_node_fs5 = __toESM(require("node:fs"), 1);
4741
- var import_node_path15 = __toESM(require("node:path"), 1);
4860
+ var import_node_path16 = __toESM(require("node:path"), 1);
4742
4861
 
4743
4862
  // src/credentialCache.ts
4744
4863
  var import_zod7 = require("zod");
@@ -4775,7 +4894,7 @@ var CREDENTIAL_COMMAND_TIMEOUT_MS = 1e4;
4775
4894
  var CREDENTIAL_INTERACTIVE_TIMEOUT_MS = 12e4;
4776
4895
  var GROUP_OTHER_PERMISSION_BITS = 63;
4777
4896
  var PERMISSION_BITS = 511;
4778
- var OCTAL_RADIX = 8;
4897
+ var OCTAL_RADIX2 = 8;
4779
4898
  function commandArgv(source) {
4780
4899
  if ("command" in source) {
4781
4900
  return source.command;
@@ -4868,7 +4987,7 @@ function trySource(source, params) {
4868
4987
  }
4869
4988
  if (read.mode !== void 0 && (read.mode & GROUP_OTHER_PERMISSION_BITS) !== 0) {
4870
4989
  return none(
4871
- `is readable or writable by group or others (mode ${(read.mode & PERMISSION_BITS).toString(OCTAL_RADIX)}); run \`chmod 600 ${source.file}\``,
4990
+ `is readable or writable by group or others (mode ${(read.mode & PERMISSION_BITS).toString(OCTAL_RADIX2)}); run \`chmod 600 ${source.file}\``,
4872
4991
  true
4873
4992
  );
4874
4993
  }
@@ -4964,7 +5083,7 @@ var InvalidProviderNameError = class extends CliError {
4964
5083
  };
4965
5084
  var PROVIDER_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._@-]*$/;
4966
5085
  function providerJsonPath(paths, name) {
4967
- return import_node_path15.default.join(paths.providersDir, `${name}.json`);
5086
+ return import_node_path16.default.join(paths.providersDir, `${name}.json`);
4968
5087
  }
4969
5088
  function providerExists(paths, name) {
4970
5089
  return import_node_fs5.default.existsSync(providerJsonPath(paths, name));
@@ -5040,7 +5159,7 @@ function readProvider(paths, name) {
5040
5159
  return parseProviderFile(filePath, raw);
5041
5160
  }
5042
5161
  function loadProvider(providersDir, name, port) {
5043
- const filePath = import_node_path15.default.join(providersDir, `${name}.json`);
5162
+ const filePath = import_node_path16.default.join(providersDir, `${name}.json`);
5044
5163
  const raw = port.readConfigFile(filePath);
5045
5164
  return raw === void 0 ? void 0 : parseProviderFile(filePath, raw);
5046
5165
  }
@@ -5295,21 +5414,21 @@ function removeDirectoryRule(paths, rulePath) {
5295
5414
  var import_node_os4 = __toESM(require("node:os"), 1);
5296
5415
 
5297
5416
  // src/launcher/cascade.ts
5298
- var import_node_path17 = __toESM(require("node:path"), 1);
5417
+ var import_node_path18 = __toESM(require("node:path"), 1);
5299
5418
 
5300
5419
  // src/pathNorm.ts
5301
- var import_node_path16 = __toESM(require("node:path"), 1);
5420
+ var import_node_path17 = __toESM(require("node:path"), 1);
5302
5421
  function expandTilde(value, home) {
5303
5422
  if (value === "~") {
5304
5423
  return home;
5305
5424
  }
5306
5425
  if (value.startsWith("~/")) {
5307
- return import_node_path16.default.join(home, value.slice(2));
5426
+ return import_node_path17.default.join(home, value.slice(2));
5308
5427
  }
5309
5428
  return value;
5310
5429
  }
5311
5430
  function normaliseRulePath(rulePath, home) {
5312
- return import_node_path16.default.resolve(expandTilde(rulePath, home));
5431
+ return import_node_path17.default.resolve(expandTilde(rulePath, home));
5313
5432
  }
5314
5433
 
5315
5434
  // src/launcher/cascade.ts
@@ -5319,7 +5438,7 @@ function loadCascadeInput(params) {
5319
5438
  const globalConfig = loadConfigFile(params.paths.globalConfigFile, GlobalConfigSchema, params.read);
5320
5439
  const directoryRules = loadConfigFile(params.paths.directoryRulesFile, DirectoryRulesSchema, params.read);
5321
5440
  const loadProfile = (name) => {
5322
- const filepath = import_node_path17.default.join(params.paths.configProfilesDir, `${name}.json`);
5441
+ const filepath = import_node_path18.default.join(params.paths.configProfilesDir, `${name}.json`);
5323
5442
  const loaded = loadConfigFile(filepath, ConfigProfileSchema, params.read);
5324
5443
  if (loaded === void 0) {
5325
5444
  return void 0;
@@ -5334,8 +5453,8 @@ function loadCascadeInput(params) {
5334
5453
  });
5335
5454
  const levels = [];
5336
5455
  for (const dir of dirs) {
5337
- const portable = loadConfigFile(import_node_path17.default.join(dir, PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path17.default.join(dir, LEGACY_PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read);
5338
- const portableLocal = loadConfigFile(import_node_path17.default.join(dir, PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path17.default.join(dir, LEGACY_PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read);
5456
+ const portable = loadConfigFile(import_node_path18.default.join(dir, PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path18.default.join(dir, LEGACY_PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read);
5457
+ const portableLocal = loadConfigFile(import_node_path18.default.join(dir, PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path18.default.join(dir, LEGACY_PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read);
5339
5458
  const rules = (directoryRules?.config.rules ?? []).map((rule, index) => ({ rule, index })).filter(({ rule }) => normaliseRulePath(rule.path, params.home) === dir).map(({ rule, index }) => {
5340
5459
  const entryOrder = directoryRules?.ruleEntryOrders[index];
5341
5460
  return {
@@ -5432,7 +5551,7 @@ function quotaWarnings(snapshot, provider, nowMs) {
5432
5551
  }
5433
5552
 
5434
5553
  // src/usage/poolPick.ts
5435
- var import_node_path18 = __toESM(require("node:path"), 1);
5554
+ var import_node_path19 = __toESM(require("node:path"), 1);
5436
5555
  var import_zod9 = require("zod");
5437
5556
 
5438
5557
  // src/usage/plan.ts
@@ -5734,7 +5853,7 @@ function recordStickyPick(fs12, picksFile, directory, identity, nowMs) {
5734
5853
  const current = readPicksFile(fs12, picksFile).file.picks;
5735
5854
  const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
5736
5855
  const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
5737
- fs12.mkdirPrivate(import_node_path18.default.dirname(picksFile));
5856
+ fs12.mkdirPrivate(import_node_path19.default.dirname(picksFile));
5738
5857
  fs12.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
5739
5858
  `);
5740
5859
  }
@@ -5831,14 +5950,14 @@ var import_node_child_process = require("node:child_process");
5831
5950
  var import_node_crypto8 = require("node:crypto");
5832
5951
  var import_node_fs6 = __toESM(require("node:fs"), 1);
5833
5952
  var import_node_os3 = __toESM(require("node:os"), 1);
5834
- var import_node_path20 = __toESM(require("node:path"), 1);
5953
+ var import_node_path21 = __toESM(require("node:path"), 1);
5835
5954
  var import_node_sea = require("node:sea");
5836
5955
 
5837
5956
  // src/versionDiscovery.ts
5838
5957
  var import_node_os2 = __toESM(require("node:os"), 1);
5839
- var import_node_path19 = __toESM(require("node:path"), 1);
5958
+ var import_node_path20 = __toESM(require("node:path"), 1);
5840
5959
  function defaultVersionsDir() {
5841
- return import_node_path19.default.join(import_node_os2.default.homedir(), ".local", "share", "claude", "versions");
5960
+ return import_node_path20.default.join(import_node_os2.default.homedir(), ".local", "share", "claude", "versions");
5842
5961
  }
5843
5962
  var NUMERIC_DOTTED_VERSION_RE = /^\d+(?:\.\d+)*$/;
5844
5963
  function isNumericDottedVersion(name) {
@@ -5880,14 +5999,14 @@ function discoverClaudeBinary(options) {
5880
5999
  const highestVersion = pickHighestVersion(entries);
5881
6000
  if (highestVersion !== void 0) {
5882
6001
  return {
5883
- path: import_node_path19.default.join(versionsDir, highestVersion),
6002
+ path: import_node_path20.default.join(versionsDir, highestVersion),
5884
6003
  source: "versions-dir",
5885
6004
  version: highestVersion
5886
6005
  };
5887
6006
  }
5888
- const ownInstallDirs = new Set(options.ownInstallDirs.map((dir) => import_node_path19.default.resolve(dir)));
6007
+ const ownInstallDirs = new Set(options.ownInstallDirs.map((dir) => import_node_path20.default.resolve(dir)));
5889
6008
  for (const dir of options.pathDirs) {
5890
- if (ownInstallDirs.has(import_node_path19.default.resolve(dir))) {
6009
+ if (ownInstallDirs.has(import_node_path20.default.resolve(dir))) {
5891
6010
  continue;
5892
6011
  }
5893
6012
  const found = options.findExecutableInDir(dir, "claude");
@@ -6058,7 +6177,7 @@ var realRunPort = {
6058
6177
  }
6059
6178
  };
6060
6179
  function expandHome2(filePath) {
6061
- return filePath.startsWith("~/") ? import_node_path20.default.join(import_node_os3.default.homedir(), filePath.slice(1)) : filePath;
6180
+ return filePath.startsWith("~/") ? import_node_path21.default.join(import_node_os3.default.homedir(), filePath.slice(1)) : filePath;
6062
6181
  }
6063
6182
  var MACOS_GUI_SESSION_MANAGER = "Aqua";
6064
6183
  function hasDesktopSession() {
@@ -6131,7 +6250,7 @@ function spawnDaemonThrough(executable) {
6131
6250
  return (paths, subcommand, logPath) => spawnDetachedDaemon({ command: executable, args: [subcommand] }, paths, subcommand, logPath);
6132
6251
  }
6133
6252
  function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
6134
- import_node_fs6.default.mkdirSync(import_node_path20.default.dirname(logPath), { recursive: true });
6253
+ import_node_fs6.default.mkdirSync(import_node_path21.default.dirname(logPath), { recursive: true });
6135
6254
  const logFd = import_node_fs6.default.openSync(logPath, "a");
6136
6255
  try {
6137
6256
  const child = (0, import_node_child_process.spawn)(invocation.command, invocation.args, detachedDaemonSpawnOptions(logFd, { ...process.env, AGENT_SHIM_HOME: paths.root }));
@@ -6147,6 +6266,29 @@ function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
6147
6266
  function spawnHeadroomSupervisor(paths, spawnDaemon) {
6148
6267
  return spawnDaemon(paths, "__headroom-supervisor", paths.headroomLogPath);
6149
6268
  }
6269
+ var SOCKET_PERMISSION_BITS = 511;
6270
+ var realHeadroomSocketTrust = {
6271
+ platform: process.platform,
6272
+ currentUid: () => {
6273
+ if (process.getuid === void 0) {
6274
+ throw new Error(`no POSIX user id on ${process.platform}`);
6275
+ }
6276
+ return process.getuid();
6277
+ },
6278
+ lstat: (target) => {
6279
+ let stat;
6280
+ try {
6281
+ stat = import_node_fs6.default.lstatSync(target);
6282
+ } catch (error) {
6283
+ if (isEnoent3(error)) {
6284
+ return void 0;
6285
+ }
6286
+ throw error;
6287
+ }
6288
+ const kind = stat.isSymbolicLink() ? "symlink" : stat.isDirectory() ? "dir" : stat.isSocket() ? "socket" : "other";
6289
+ return { kind, uid: stat.uid, mode: stat.mode & SOCKET_PERMISSION_BITS };
6290
+ }
6291
+ };
6150
6292
  function realHeadroomPort(paths, options) {
6151
6293
  return {
6152
6294
  ensure: () => {
@@ -6163,7 +6305,7 @@ function realHeadroomPort(paths, options) {
6163
6305
  }
6164
6306
  });
6165
6307
  return {
6166
- port: up.port,
6308
+ socketPath: up.socketPath,
6167
6309
  projectId: resolveGitRoot(realRunPort, options.cwd) ?? options.cwd
6168
6310
  };
6169
6311
  },
@@ -6189,7 +6331,7 @@ function listVersionsDir(dir) {
6189
6331
  throw error;
6190
6332
  }
6191
6333
  return entries.filter((entry) => entry.isFile()).map((entry) => {
6192
- const fullPath = import_node_path20.default.join(dir, entry.name);
6334
+ const fullPath = import_node_path21.default.join(dir, entry.name);
6193
6335
  const stat = import_node_fs6.default.statSync(fullPath);
6194
6336
  return {
6195
6337
  name: entry.name,
@@ -6204,7 +6346,7 @@ function windowsPathExtensions(pathext) {
6204
6346
  return (pathext ?? WINDOWS_DEFAULT_PATHEXT).split(";").map((ext) => ext.trim()).filter((ext) => ext.length > 0);
6205
6347
  }
6206
6348
  function resolveExecutableCandidate(dir, name, env) {
6207
- const candidate = import_node_path20.default.join(dir, name);
6349
+ const candidate = import_node_path21.default.join(dir, name);
6208
6350
  if (env.platform === "win32") {
6209
6351
  const extensions = windowsPathExtensions(env.pathext);
6210
6352
  const alreadyHasRecognisedExtension = extensions.some((ext) => candidate.toLowerCase().endsWith(ext.toLowerCase()));
@@ -6253,13 +6395,13 @@ function resolveOwnExecutablePath(env) {
6253
6395
  if (env.argv1 !== void 0 && !env.argv1.includes("/") && !env.argv1.includes("\\")) {
6254
6396
  return searchPathForExecutable(env.pathDirs, env.argv1, env.findExecutableInDir) ?? env.execPath;
6255
6397
  }
6256
- const candidate = env.argv1 === void 0 ? env.execPath : import_node_path20.default.resolve(env.cwd, env.argv1);
6257
- const candidateDir = import_node_path20.default.dirname(candidate);
6258
- const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path20.default.resolve(dir) === candidateDir);
6398
+ const candidate = env.argv1 === void 0 ? env.execPath : import_node_path21.default.resolve(env.cwd, env.argv1);
6399
+ const candidateDir = import_node_path21.default.dirname(candidate);
6400
+ const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path21.default.resolve(dir) === candidateDir);
6259
6401
  if (candidateDirOnPath) {
6260
6402
  return candidate;
6261
6403
  }
6262
- const viaPath = searchPathForExecutable(env.pathDirs, import_node_path20.default.basename(candidate), env.findExecutableInDir);
6404
+ const viaPath = searchPathForExecutable(env.pathDirs, import_node_path21.default.basename(candidate), env.findExecutableInDir);
6263
6405
  return viaPath ?? candidate;
6264
6406
  }
6265
6407
  function realOwnExecutablePath() {
@@ -6267,21 +6409,21 @@ function realOwnExecutablePath() {
6267
6409
  argv1: process.argv[1],
6268
6410
  execPath: process.execPath,
6269
6411
  cwd: process.cwd(),
6270
- pathDirs: (process.env.PATH ?? "").split(import_node_path20.default.delimiter).filter((dir) => dir !== ""),
6412
+ pathDirs: (process.env.PATH ?? "").split(import_node_path21.default.delimiter).filter((dir) => dir !== ""),
6271
6413
  findExecutableInDir
6272
6414
  });
6273
6415
  }
6274
6416
  function realResolveClaudeBinary(ownInstallDirs) {
6275
6417
  return () => discoverClaudeBinary({
6276
6418
  listVersionsDir,
6277
- pathDirs: (process.env.PATH ?? "").split(import_node_path20.default.delimiter).filter((dir) => dir !== ""),
6419
+ pathDirs: (process.env.PATH ?? "").split(import_node_path21.default.delimiter).filter((dir) => dir !== ""),
6278
6420
  findExecutableInDir,
6279
6421
  ownInstallDirs: [...ownInstallDirs]
6280
6422
  });
6281
6423
  }
6282
6424
 
6283
6425
  // src/checkReport.ts
6284
- var import_node_path21 = __toESM(require("node:path"), 1);
6426
+ var import_node_path22 = __toESM(require("node:path"), 1);
6285
6427
  var import_zod10 = require("zod");
6286
6428
 
6287
6429
  // src/cli/bool.ts
@@ -6649,10 +6791,10 @@ function collectCheckReport(params) {
6649
6791
  }).input;
6650
6792
  const providerName = cascadeProviderName(cascade);
6651
6793
  const provider = providerName === void 0 ? void 0 : loadCheckProvider(paths, providerName);
6652
- const farmRoot = identityDecision.name === void 0 ? void 0 : import_node_path21.default.join(paths.identitiesDir, identityDecision.name);
6794
+ const farmRoot = identityDecision.name === void 0 ? void 0 : import_node_path22.default.join(paths.identitiesDir, identityDecision.name);
6653
6795
  const settingsFiles = {
6654
- "settings.json": realFsPort.readFileUtf8(import_node_path21.default.join(claudeHome, "settings.json")),
6655
- "settings.local.json": realFsPort.readFileUtf8(import_node_path21.default.join(claudeHome, "settings.local.json"))
6796
+ "settings.json": realFsPort.readFileUtf8(import_node_path22.default.join(claudeHome, "settings.json")),
6797
+ "settings.local.json": realFsPort.readFileUtf8(import_node_path22.default.join(claudeHome, "settings.local.json"))
6656
6798
  };
6657
6799
  const report = runCheck({
6658
6800
  cwd,
@@ -6682,7 +6824,7 @@ function collectCheckReport(params) {
6682
6824
 
6683
6825
  // src/claudeShim.ts
6684
6826
  var import_node_fs7 = __toESM(require("node:fs"), 1);
6685
- var import_node_path22 = __toESM(require("node:path"), 1);
6827
+ var import_node_path23 = __toESM(require("node:path"), 1);
6686
6828
  var import_zod11 = require("zod");
6687
6829
  var ClaudeShimStateSchema = import_zod11.z.strictObject({
6688
6830
  targetPath: import_zod11.z.string().min(1),
@@ -6693,29 +6835,29 @@ function commandFilename(ownExecutablePath, commandName) {
6693
6835
  return ownExecutablePath.toLowerCase().endsWith(".exe") ? `${commandName}.exe` : commandName;
6694
6836
  }
6695
6837
  function resolveOwnInstallDirs(paths, ownExecutablePath) {
6696
- const dirs = [import_node_path22.default.dirname(ownExecutablePath)];
6838
+ const dirs = [import_node_path23.default.dirname(ownExecutablePath)];
6697
6839
  const state = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
6698
6840
  if (state !== void 0) {
6699
- dirs.push(import_node_path22.default.dirname(state.targetPath));
6841
+ dirs.push(import_node_path23.default.dirname(state.targetPath));
6700
6842
  }
6701
6843
  return dirs;
6702
6844
  }
6703
6845
  var nodeLinkFs = { link: import_node_fs7.default.linkSync, copyFile: import_node_fs7.default.copyFileSync, chmod: import_node_fs7.default.chmodSync };
6704
6846
  function findPathShadow(params) {
6705
- const resolvedTargetDir = import_node_path22.default.resolve(params.targetDir);
6847
+ const resolvedTargetDir = import_node_path23.default.resolve(params.targetDir);
6706
6848
  for (const dir of params.pathDirs) {
6707
6849
  const found = params.findExecutableInDir(dir, params.targetFilename);
6708
6850
  if (found === void 0) {
6709
6851
  continue;
6710
6852
  }
6711
- return import_node_path22.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
6853
+ return import_node_path23.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
6712
6854
  }
6713
- return params.pathDirs.some((dir) => import_node_path22.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
6855
+ return params.pathDirs.some((dir) => import_node_path23.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
6714
6856
  }
6715
6857
 
6716
6858
  // src/doctorReport.ts
6717
6859
  var import_node_fs8 = __toESM(require("node:fs"), 1);
6718
- var import_node_path23 = __toESM(require("node:path"), 1);
6860
+ var import_node_path24 = __toESM(require("node:path"), 1);
6719
6861
  function refinePathShadow(status, ownExecutablePath, realpath) {
6720
6862
  if (status.status !== "shadowed") {
6721
6863
  return status;
@@ -6739,7 +6881,7 @@ function validateJson(schema, input) {
6739
6881
  return { ok: true, data: result.data };
6740
6882
  }
6741
6883
  function pushPathResolution(push, resolution) {
6742
- const ownDir = import_node_path23.default.dirname(resolution.ownExecutablePath);
6884
+ const ownDir = import_node_path24.default.dirname(resolution.ownExecutablePath);
6743
6885
  switch (resolution.agentShim.status) {
6744
6886
  case "ok":
6745
6887
  push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
@@ -6807,14 +6949,14 @@ function pushProvider(push, entry) {
6807
6949
  }
6808
6950
  function pushLegacyName(push, params) {
6809
6951
  const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
6810
- if (legacyVariables.length === 0 && import_node_path23.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
6952
+ if (legacyVariables.length === 0 && import_node_path24.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
6811
6953
  push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
6812
6954
  return;
6813
6955
  }
6814
6956
  for (const name of legacyVariables) {
6815
6957
  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);
6816
6958
  }
6817
- if (import_node_path23.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
6959
+ if (import_node_path24.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
6818
6960
  push(
6819
6961
  "legacy-name",
6820
6962
  "warn",
@@ -7004,7 +7146,7 @@ function runDoctor(params) {
7004
7146
  "warn",
7005
7147
  `Headroom state names supervisor pid ${String(state.supervisorPid)}, which is not running; the next launch through headroom will start a replacement.`
7006
7148
  );
7007
- } else if (state.headroomPid === void 0 || state.port === void 0) {
7149
+ } else if (state.headroomPid === void 0 || state.socketPath === void 0) {
7008
7150
  push(
7009
7151
  "headroom",
7010
7152
  "warn",
@@ -7020,7 +7162,7 @@ function runDoctor(params) {
7020
7162
  push(
7021
7163
  "headroom",
7022
7164
  "pass",
7023
- `Headroom daemon is up on 127.0.0.1:${String(state.port)} (supervisor ${String(state.supervisorPid)}, daemon ${String(state.headroomPid)}).`
7165
+ `Headroom daemon is up on unix socket ${state.socketPath} (supervisor ${String(state.supervisorPid)}, daemon ${String(state.headroomPid)}).`
7024
7166
  );
7025
7167
  }
7026
7168
  if (state.lastError !== void 0 && supervisorAlive) {
@@ -7122,18 +7264,18 @@ function collectDoctorReport(params) {
7122
7264
  const { paths } = params;
7123
7265
  const identityNames = import_node_fs8.default.existsSync(paths.identitiesDir) ? import_node_fs8.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
7124
7266
  const identities = identityNames.map((name) => {
7125
- const farmRoot = import_node_path23.default.join(paths.identitiesDir, name);
7126
- const identityPath = import_node_path23.default.join(farmRoot, "identity.json");
7267
+ const farmRoot = import_node_path24.default.join(paths.identitiesDir, name);
7268
+ const identityPath = import_node_path24.default.join(farmRoot, "identity.json");
7127
7269
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
7128
7270
  });
7129
7271
  const profileNames = import_node_fs8.default.existsSync(paths.configProfilesDir) ? import_node_fs8.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
7130
7272
  const configProfiles = profileNames.map((name) => {
7131
- const profilePath = import_node_path23.default.join(paths.configProfilesDir, `${name}.json`);
7273
+ const profilePath = import_node_path24.default.join(paths.configProfilesDir, `${name}.json`);
7132
7274
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
7133
7275
  });
7134
7276
  const providerNames = import_node_fs8.default.existsSync(paths.providersDir) ? import_node_fs8.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
7135
7277
  const providers = providerNames.map((name) => {
7136
- const providerPath = import_node_path23.default.join(paths.providersDir, `${name}.json`);
7278
+ const providerPath = import_node_path24.default.join(paths.providersDir, `${name}.json`);
7137
7279
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
7138
7280
  });
7139
7281
  const ownExecutablePath = realOwnExecutablePath();
@@ -7145,12 +7287,12 @@ function collectDoctorReport(params) {
7145
7287
  binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
7146
7288
  }
7147
7289
  const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
7148
- const pathDirs = (params.env.PATH ?? "").split(import_node_path23.default.delimiter).filter((dir) => dir !== "");
7290
+ const pathDirs = (params.env.PATH ?? "").split(import_node_path24.default.delimiter).filter((dir) => dir !== "");
7149
7291
  const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
7150
7292
  findPathShadow({
7151
7293
  pathDirs,
7152
- targetDir: import_node_path23.default.dirname(shimState.targetPath),
7153
- targetFilename: import_node_path23.default.basename(shimState.targetPath),
7294
+ targetDir: import_node_path24.default.dirname(shimState.targetPath),
7295
+ targetFilename: import_node_path24.default.basename(shimState.targetPath),
7154
7296
  findExecutableInDir
7155
7297
  }),
7156
7298
  shimState.targetPath,
@@ -7173,7 +7315,7 @@ function collectDoctorReport(params) {
7173
7315
  agentShim: refinePathShadow(
7174
7316
  findPathShadow({
7175
7317
  pathDirs,
7176
- targetDir: import_node_path23.default.dirname(ownExecutablePath),
7318
+ targetDir: import_node_path24.default.dirname(ownExecutablePath),
7177
7319
  targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
7178
7320
  findExecutableInDir
7179
7321
  }),
@@ -7194,7 +7336,7 @@ function collectDoctorReport(params) {
7194
7336
 
7195
7337
  // src/launcher.ts
7196
7338
  var import_node_crypto9 = require("node:crypto");
7197
- var import_node_path25 = __toESM(require("node:path"), 1);
7339
+ var import_node_path26 = __toESM(require("node:path"), 1);
7198
7340
 
7199
7341
  // src/launcher/argv.ts
7200
7342
  var ConflictingIdentityError = class extends UsageError {
@@ -7446,7 +7588,7 @@ function buildCliOverride(params) {
7446
7588
  }
7447
7589
 
7448
7590
  // src/launcher/flags.ts
7449
- var import_node_path24 = __toESM(require("node:path"), 1);
7591
+ var import_node_path25 = __toESM(require("node:path"), 1);
7450
7592
 
7451
7593
  // src/headroom/headers.ts
7452
7594
  function mergeAnthropicCustomHeaders(existing, additions) {
@@ -7516,7 +7658,7 @@ function buildEnv(params) {
7516
7658
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
7517
7659
  let providerCustomHeaders;
7518
7660
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
7519
- env.CLAUDE_CONFIG_DIR = import_node_path24.default.join(params.identitiesDir, params.resolvedIdentityName);
7661
+ env.CLAUDE_CONFIG_DIR = import_node_path25.default.join(params.identitiesDir, params.resolvedIdentityName);
7520
7662
  }
7521
7663
  if (params.provider !== void 0) {
7522
7664
  const providerEnv = params.provider.definition.env ?? {};
@@ -7537,9 +7679,6 @@ function buildEnv(params) {
7537
7679
  env[variable] = value;
7538
7680
  }
7539
7681
  }
7540
- if (params.headroom !== void 0) {
7541
- env.HEADROOM_PROXY_URL = `http://127.0.0.1:${String(params.headroom.port)}`;
7542
- }
7543
7682
  if (params.frontdoor !== void 0) {
7544
7683
  env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
7545
7684
  [
@@ -7680,7 +7819,7 @@ function prepareLaunch(params) {
7680
7819
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
7681
7820
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
7682
7821
  });
7683
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path25.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7822
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path26.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7684
7823
  log.error(
7685
7824
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
7686
7825
  );
@@ -7816,7 +7955,7 @@ function prepareLaunch(params) {
7816
7955
  if (resolvedFlags.headroom && headroomPort !== void 0) {
7817
7956
  headroom = headroomPort.ensure();
7818
7957
  const via = resolvedProvider === void 0 ? `OAuth via the door's CONNECT surface on 127.0.0.1:${String(frontDoor?.connectPort ?? 0)}` : `provider ${resolvedProvider.name}`;
7819
- 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})`);
7958
+ 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})`);
7820
7959
  } else if (resolvedFlags.headroom) {
7821
7960
  log.error("agent-shim: headroom routing was requested but this launcher has no headroom port wired; refusing to launch without it.");
7822
7961
  proc.exit(1);
@@ -7856,7 +7995,7 @@ var import_node_crypto11 = require("node:crypto");
7856
7995
  // src/realCredentialCache.ts
7857
7996
  var import_node_child_process2 = require("node:child_process");
7858
7997
  var import_node_fs9 = __toESM(require("node:fs"), 1);
7859
- var import_node_path26 = __toESM(require("node:path"), 1);
7998
+ var import_node_path27 = __toESM(require("node:path"), 1);
7860
7999
  var KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
7861
8000
  var CACHE_DIR_MODE = 448;
7862
8001
  var CACHE_FILE_MODE = 384;
@@ -7883,8 +8022,8 @@ function security(args, stdin) {
7883
8022
  return { status: result.status, stdout: result.stdout };
7884
8023
  }
7885
8024
  function createRealCredentialCache(root) {
7886
- const dir = import_node_path26.default.join(root, "credential-cache");
7887
- const filePath = (owner) => import_node_path26.default.join(dir, cacheFileNameFor(owner));
8025
+ const dir = import_node_path27.default.join(root, "credential-cache");
8026
+ const filePath = (owner) => import_node_path27.default.join(dir, cacheFileNameFor(owner));
7888
8027
  return {
7889
8028
  read(store, owner) {
7890
8029
  if (store === "file") {
@@ -8000,11 +8139,11 @@ function probeFrontDoorSync(port, caPem) {
8000
8139
 
8001
8140
  // src/frontdoor/trust.ts
8002
8141
  var import_node_crypto10 = require("node:crypto");
8003
- var import_node_path27 = __toESM(require("node:path"), 1);
8142
+ var import_node_path28 = __toESM(require("node:path"), 1);
8004
8143
  var BUNDLE_NAME_HEX_DIGITS = 16;
8005
8144
  function resolveTrustBundle(params) {
8006
8145
  const { caCertFile, bundlesDir, inherited, fs: fs12 } = params;
8007
- if (inherited === void 0 || inherited === "" || import_node_path27.default.resolve(inherited) === import_node_path27.default.resolve(caCertFile)) {
8146
+ if (inherited === void 0 || inherited === "" || import_node_path28.default.resolve(inherited) === import_node_path28.default.resolve(caCertFile)) {
8008
8147
  return { path: caCertFile };
8009
8148
  }
8010
8149
  const caPem = fs12.readFileUtf8(caCertFile);
@@ -8022,7 +8161,7 @@ function resolveTrustBundle(params) {
8022
8161
  }
8023
8162
  const combined = `${inheritedPem.trimEnd()}
8024
8163
  ${caPem}`;
8025
- const bundle = import_node_path27.default.join(bundlesDir, `${(0, import_node_crypto10.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
8164
+ const bundle = import_node_path28.default.join(bundlesDir, `${(0, import_node_crypto10.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
8026
8165
  if (!fs12.exists(bundle)) {
8027
8166
  fs12.mkdirp(bundlesDir);
8028
8167
  fs12.writeFileAtomic(bundle, combined);