agent-shim 8.42.0 → 8.44.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
@@ -2643,7 +2643,7 @@ var init_package = __esm({
2643
2643
  "package.json"() {
2644
2644
  package_default = {
2645
2645
  name: "agent-shim",
2646
- version: "8.42.0",
2646
+ version: "8.44.0",
2647
2647
  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.",
2648
2648
  license: "MIT",
2649
2649
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -2761,7 +2761,7 @@ function readHeadroomState(fs12, stateFile) {
2761
2761
  }
2762
2762
  }
2763
2763
  function writeHeadroomState(fs12, stateFile, state) {
2764
- fs12.mkdirp(import_node_path10.default.dirname(stateFile));
2764
+ fs12.mkdirp(import_node_path11.default.dirname(stateFile));
2765
2765
  fs12.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
2766
2766
  `);
2767
2767
  }
@@ -2789,7 +2789,7 @@ function readAllProviders(fs12, providersDir) {
2789
2789
  continue;
2790
2790
  }
2791
2791
  try {
2792
- const parsed = parseJson(fs12.readFileUtf8(import_node_path10.default.join(providersDir, name)), ProviderSchema);
2792
+ const parsed = parseJson(fs12.readFileUtf8(import_node_path11.default.join(providersDir, name)), ProviderSchema);
2793
2793
  if (parsed !== void 0) {
2794
2794
  result.push({ name: name.slice(0, -".json".length), provider: parsed });
2795
2795
  }
@@ -2801,11 +2801,11 @@ function readAllProviders(fs12, providersDir) {
2801
2801
  }
2802
2802
  function writeSession(fs12, sessionsDir, session) {
2803
2803
  fs12.mkdirp(sessionsDir);
2804
- fs12.writeFileUtf8(import_node_path10.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
2804
+ fs12.writeFileUtf8(import_node_path11.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
2805
2805
  `);
2806
2806
  }
2807
2807
  function removeSession(fs12, sessionsDir, pid) {
2808
- fs12.removeRecursive(import_node_path10.default.join(sessionsDir, `${String(pid)}.json`));
2808
+ fs12.removeRecursive(import_node_path11.default.join(sessionsDir, `${String(pid)}.json`));
2809
2809
  }
2810
2810
  function listSessions(fs12, sessionsDir) {
2811
2811
  const sessions = [];
@@ -2814,7 +2814,7 @@ function listSessions(fs12, sessionsDir) {
2814
2814
  continue;
2815
2815
  }
2816
2816
  try {
2817
- const parsed = parseJson(fs12.readFileUtf8(import_node_path10.default.join(sessionsDir, name)), HeadroomSessionSchema);
2817
+ const parsed = parseJson(fs12.readFileUtf8(import_node_path11.default.join(sessionsDir, name)), HeadroomSessionSchema);
2818
2818
  if (parsed !== void 0) {
2819
2819
  sessions.push(parsed);
2820
2820
  }
@@ -2844,12 +2844,12 @@ function readStartLock(fs12, lockFile) {
2844
2844
  return void 0;
2845
2845
  }
2846
2846
  }
2847
- var import_node_crypto6, import_node_path10, import_zod5, HEADROOM_ANTHROPIC_UPSTREAM, HEADROOM_STATE_SCHEMA_VERSION, HeadroomStateSchema, HeadroomSessionSchema, HeadroomLockSchema;
2847
+ var import_node_crypto6, import_node_path11, import_zod5, HEADROOM_ANTHROPIC_UPSTREAM, HEADROOM_STATE_SCHEMA_VERSION, HeadroomStateSchema, HeadroomSessionSchema, HeadroomLockSchema;
2848
2848
  var init_state2 = __esm({
2849
2849
  "src/headroom/state.ts"() {
2850
2850
  "use strict";
2851
2851
  import_node_crypto6 = require("node:crypto");
2852
- import_node_path10 = __toESM(require("node:path"), 1);
2852
+ import_node_path11 = __toESM(require("node:path"), 1);
2853
2853
  import_zod5 = require("zod");
2854
2854
  init_schema();
2855
2855
  HEADROOM_ANTHROPIC_UPSTREAM = "https://api.anthropic.com";
@@ -2989,7 +2989,7 @@ var init_settings = __esm({
2989
2989
 
2990
2990
  // src/headroom/socket.ts
2991
2991
  function headroomSocketPath(paths, supervisorPid) {
2992
- return import_node_path11.default.join(paths.headroomSocketDir, `${String(supervisorPid)}${HEADROOM_SOCKET_SUFFIX}`);
2992
+ return import_node_path12.default.join(paths.headroomSocketDir, `${String(supervisorPid)}${HEADROOM_SOCKET_SUFFIX}`);
2993
2993
  }
2994
2994
  function platformRefusal(platform) {
2995
2995
  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;
@@ -3018,7 +3018,7 @@ function verifyHeadroomSocket(socketPath, ports) {
3018
3018
  return { refused: unsupported };
3019
3019
  }
3020
3020
  const uid = ports.currentUid();
3021
- const directory = import_node_path11.default.dirname(socketPath);
3021
+ const directory = import_node_path12.default.dirname(socketPath);
3022
3022
  const refusal = ownerOnlyRefusal("socket directory", directory, ports.lstat(directory), "dir", uid) ?? ownerOnlyRefusal("socket", socketPath, ports.lstat(socketPath), "socket", uid);
3023
3023
  return refusal === void 0 ? { socketPath } : { refused: refusal };
3024
3024
  }
@@ -3048,16 +3048,16 @@ function pruneStaleHeadroomSockets(fs12, paths, isRunning) {
3048
3048
  if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
3049
3049
  continue;
3050
3050
  }
3051
- fs12.removeRecursive(import_node_path11.default.join(paths.headroomSocketDir, name));
3051
+ fs12.removeRecursive(import_node_path12.default.join(paths.headroomSocketDir, name));
3052
3052
  removed.push(name);
3053
3053
  }
3054
3054
  return removed;
3055
3055
  }
3056
- var import_node_path11, GROUP_OR_OTHER_BITS, OCTAL_RADIX, MODE_DIGITS, HEADROOM_SOCKET_SUFFIX, HEADROOM_SOCKET_NAME, UNIX_SOCKET_PATH_MAX_BYTES, PLATFORMS_WITHOUT_UNIX_SOCKETS;
3056
+ var import_node_path12, GROUP_OR_OTHER_BITS, OCTAL_RADIX, MODE_DIGITS, HEADROOM_SOCKET_SUFFIX, HEADROOM_SOCKET_NAME, UNIX_SOCKET_PATH_MAX_BYTES, PLATFORMS_WITHOUT_UNIX_SOCKETS;
3057
3057
  var init_socket = __esm({
3058
3058
  "src/headroom/socket.ts"() {
3059
3059
  "use strict";
3060
- import_node_path11 = __toESM(require("node:path"), 1);
3060
+ import_node_path12 = __toESM(require("node:path"), 1);
3061
3061
  GROUP_OR_OTHER_BITS = 63;
3062
3062
  OCTAL_RADIX = 8;
3063
3063
  MODE_DIGITS = 4;
@@ -3380,7 +3380,7 @@ function realIsProcessRunning(pid) {
3380
3380
  return realIsProcessAlive(pid) && !realIsProcessZombie(pid);
3381
3381
  }
3382
3382
  function expandHome2(filePath) {
3383
- return filePath.startsWith("~/") ? import_node_path12.default.join(import_node_os2.default.homedir(), filePath.slice(1)) : filePath;
3383
+ return filePath.startsWith("~/") ? import_node_path13.default.join(import_node_os2.default.homedir(), filePath.slice(1)) : filePath;
3384
3384
  }
3385
3385
  function hasDesktopSession() {
3386
3386
  if (process.platform === "darwin") {
@@ -3424,7 +3424,7 @@ function spawnDaemonThroughScript(script) {
3424
3424
  return (paths, subcommand, logPath) => spawnDetachedDaemon({ command: process.execPath, args: [script, subcommand] }, paths, subcommand, logPath);
3425
3425
  }
3426
3426
  function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
3427
- import_node_fs2.default.mkdirSync(import_node_path12.default.dirname(logPath), { recursive: true });
3427
+ import_node_fs2.default.mkdirSync(import_node_path13.default.dirname(logPath), { recursive: true });
3428
3428
  const logFd = import_node_fs2.default.openSync(logPath, "a");
3429
3429
  try {
3430
3430
  const child = (0, import_node_child_process.spawn)(invocation.command, invocation.args, detachedDaemonSpawnOptions(logFd, { ...process.env, AGENT_SHIM_HOME: paths.root }));
@@ -3477,7 +3477,7 @@ function listVersionsDir(dir) {
3477
3477
  throw error;
3478
3478
  }
3479
3479
  return entries.filter((entry) => entry.isFile()).map((entry) => {
3480
- const fullPath = import_node_path12.default.join(dir, entry.name);
3480
+ const fullPath = import_node_path13.default.join(dir, entry.name);
3481
3481
  const stat = import_node_fs2.default.statSync(fullPath);
3482
3482
  return {
3483
3483
  name: entry.name,
@@ -3491,7 +3491,7 @@ function windowsPathExtensions(pathext) {
3491
3491
  return (pathext ?? WINDOWS_DEFAULT_PATHEXT).split(";").map((ext) => ext.trim()).filter((ext) => ext.length > 0);
3492
3492
  }
3493
3493
  function resolveExecutableCandidate(dir, name, env) {
3494
- const candidate = import_node_path12.default.join(dir, name);
3494
+ const candidate = import_node_path13.default.join(dir, name);
3495
3495
  if (env.platform === "win32") {
3496
3496
  const extensions = windowsPathExtensions(env.pathext);
3497
3497
  const alreadyHasRecognisedExtension = extensions.some((ext) => candidate.toLowerCase().endsWith(ext.toLowerCase()));
@@ -3540,13 +3540,13 @@ function resolveOwnExecutablePath(env) {
3540
3540
  if (env.argv1 !== void 0 && !env.argv1.includes("/") && !env.argv1.includes("\\")) {
3541
3541
  return searchPathForExecutable(env.pathDirs, env.argv1, env.findExecutableInDir) ?? env.execPath;
3542
3542
  }
3543
- const candidate = env.argv1 === void 0 ? env.execPath : import_node_path12.default.resolve(env.cwd, env.argv1);
3544
- const candidateDir = import_node_path12.default.dirname(candidate);
3545
- const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path12.default.resolve(dir) === candidateDir);
3543
+ const candidate = env.argv1 === void 0 ? env.execPath : import_node_path13.default.resolve(env.cwd, env.argv1);
3544
+ const candidateDir = import_node_path13.default.dirname(candidate);
3545
+ const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path13.default.resolve(dir) === candidateDir);
3546
3546
  if (candidateDirOnPath) {
3547
3547
  return candidate;
3548
3548
  }
3549
- const viaPath = searchPathForExecutable(env.pathDirs, import_node_path12.default.basename(candidate), env.findExecutableInDir);
3549
+ const viaPath = searchPathForExecutable(env.pathDirs, import_node_path13.default.basename(candidate), env.findExecutableInDir);
3550
3550
  return viaPath ?? candidate;
3551
3551
  }
3552
3552
  function realOwnExecutablePath() {
@@ -3554,7 +3554,7 @@ function realOwnExecutablePath() {
3554
3554
  argv1: process.argv[1],
3555
3555
  execPath: process.execPath,
3556
3556
  cwd: process.cwd(),
3557
- pathDirs: (process.env.PATH ?? "").split(import_node_path12.default.delimiter).filter((dir) => dir !== ""),
3557
+ pathDirs: (process.env.PATH ?? "").split(import_node_path13.default.delimiter).filter((dir) => dir !== ""),
3558
3558
  findExecutableInDir
3559
3559
  });
3560
3560
  }
@@ -3567,7 +3567,7 @@ function realContentSourcePath() {
3567
3567
  function realResolveClaudeBinary(isOwnBinary) {
3568
3568
  return (request4) => discoverClaudeBinary({
3569
3569
  listVersionsDir,
3570
- pathDirs: (process.env.PATH ?? "").split(import_node_path12.default.delimiter).filter((dir) => dir !== ""),
3570
+ pathDirs: (process.env.PATH ?? "").split(import_node_path13.default.delimiter).filter((dir) => dir !== ""),
3571
3571
  findExecutableInDir,
3572
3572
  isOwnBinary,
3573
3573
  ...request4?.version === void 0 ? {} : { version: request4.version }
@@ -3576,7 +3576,7 @@ function realResolveClaudeBinary(isOwnBinary) {
3576
3576
  function realInstalledClaudeVersions() {
3577
3577
  return installedVersions(listVersionsDir(defaultVersionsDir()));
3578
3578
  }
3579
- var import_node_child_process, import_node_crypto8, import_node_fs2, import_node_os2, import_node_path12, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS, realFarmFs, INT32_BYTE_LENGTH, realRunPort, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
3579
+ var import_node_child_process, import_node_crypto8, import_node_fs2, import_node_os2, import_node_path13, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS, realFarmFs, INT32_BYTE_LENGTH, realRunPort, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
3580
3580
  var init_realPorts = __esm({
3581
3581
  "src/realPorts.ts"() {
3582
3582
  "use strict";
@@ -3584,7 +3584,7 @@ var init_realPorts = __esm({
3584
3584
  import_node_crypto8 = require("node:crypto");
3585
3585
  import_node_fs2 = __toESM(require("node:fs"), 1);
3586
3586
  import_node_os2 = __toESM(require("node:os"), 1);
3587
- import_node_path12 = __toESM(require("node:path"), 1);
3587
+ import_node_path13 = __toESM(require("node:path"), 1);
3588
3588
  import_node_sea = require("node:sea");
3589
3589
  init_load();
3590
3590
  init_versionDiscovery();
@@ -3800,18 +3800,18 @@ function expandTilde(value, home) {
3800
3800
  return home;
3801
3801
  }
3802
3802
  if (value.startsWith("~/")) {
3803
- return import_node_path13.default.join(home, value.slice(2));
3803
+ return import_node_path14.default.join(home, value.slice(2));
3804
3804
  }
3805
3805
  return value;
3806
3806
  }
3807
3807
  function normaliseRulePath(rulePath, home) {
3808
- return import_node_path13.default.resolve(expandTilde(rulePath, home));
3808
+ return import_node_path14.default.resolve(expandTilde(rulePath, home));
3809
3809
  }
3810
- var import_node_path13;
3810
+ var import_node_path14;
3811
3811
  var init_pathNorm = __esm({
3812
3812
  "src/pathNorm.ts"() {
3813
3813
  "use strict";
3814
- import_node_path13 = __toESM(require("node:path"), 1);
3814
+ import_node_path14 = __toESM(require("node:path"), 1);
3815
3815
  }
3816
3816
  });
3817
3817
 
@@ -3820,7 +3820,7 @@ function loadCascadeInput(params) {
3820
3820
  const globalConfig = loadConfigFile(params.paths.globalConfigFile, GlobalConfigSchema, params.read);
3821
3821
  const directoryRules = loadConfigFile(params.paths.directoryRulesFile, DirectoryRulesSchema, params.read);
3822
3822
  const loadProfile = (name) => {
3823
- const filepath = import_node_path14.default.join(params.paths.configProfilesDir, `${name}.json`);
3823
+ const filepath = import_node_path15.default.join(params.paths.configProfilesDir, `${name}.json`);
3824
3824
  const loaded = loadConfigFile(filepath, ConfigProfileSchema, params.read);
3825
3825
  if (loaded === void 0) {
3826
3826
  return void 0;
@@ -3835,8 +3835,8 @@ function loadCascadeInput(params) {
3835
3835
  });
3836
3836
  const levels = [];
3837
3837
  for (const dir of dirs) {
3838
- const portable = loadConfigFile(import_node_path14.default.join(dir, PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path14.default.join(dir, LEGACY_PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read);
3839
- const portableLocal = loadConfigFile(import_node_path14.default.join(dir, PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path14.default.join(dir, LEGACY_PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read);
3838
+ const portable = loadConfigFile(import_node_path15.default.join(dir, PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path15.default.join(dir, LEGACY_PORTABLE_CONFIG_FILENAME), PortableConfigSchema, params.read);
3839
+ const portableLocal = loadConfigFile(import_node_path15.default.join(dir, PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read) ?? loadConfigFile(import_node_path15.default.join(dir, LEGACY_PORTABLE_LOCAL_CONFIG_FILENAME), PortableConfigSchema, params.read);
3840
3840
  const rules = (directoryRules?.config.rules ?? []).map((rule, index) => ({ rule, index })).filter(({ rule }) => normaliseRulePath(rule.path, params.home) === dir).map(({ rule, index }) => {
3841
3841
  const entryOrder = directoryRules?.ruleEntryOrders[index];
3842
3842
  return {
@@ -3883,11 +3883,11 @@ function readDirectorySelections(loaded) {
3883
3883
  }
3884
3884
  return { ...identity === void 0 ? {} : { identity }, ...configProfile === void 0 ? {} : { configProfile } };
3885
3885
  }
3886
- var import_node_path14, PORTABLE_CONFIG_FILENAME, PORTABLE_LOCAL_CONFIG_FILENAME;
3886
+ var import_node_path15, PORTABLE_CONFIG_FILENAME, PORTABLE_LOCAL_CONFIG_FILENAME;
3887
3887
  var init_cascade = __esm({
3888
3888
  "src/launcher/cascade.ts"() {
3889
3889
  "use strict";
3890
- import_node_path14 = __toESM(require("node:path"), 1);
3890
+ import_node_path15 = __toESM(require("node:path"), 1);
3891
3891
  init_load();
3892
3892
  init_schema();
3893
3893
  init_pathNorm();
@@ -3951,13 +3951,13 @@ function decideConfigProfile(params) {
3951
3951
  return { source: "none" };
3952
3952
  }
3953
3953
  function loadIdentity(identitiesDir, name, fs12) {
3954
- return loadConfigFile(import_node_path15.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs12.readConfigFile);
3954
+ return loadConfigFile(import_node_path16.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs12.readConfigFile);
3955
3955
  }
3956
- var import_node_path15, IDENTITY_DECISION_SOURCES, CONFIG_PROFILE_DECISION_SOURCES;
3956
+ var import_node_path16, IDENTITY_DECISION_SOURCES, CONFIG_PROFILE_DECISION_SOURCES;
3957
3957
  var init_identity = __esm({
3958
3958
  "src/launcher/identity.ts"() {
3959
3959
  "use strict";
3960
- import_node_path15 = __toESM(require("node:path"), 1);
3960
+ import_node_path16 = __toESM(require("node:path"), 1);
3961
3961
  init_load();
3962
3962
  init_schema();
3963
3963
  IDENTITY_DECISION_SOURCES = [
@@ -4153,7 +4153,7 @@ function isIdentityName(name) {
4153
4153
  return IdentitySchema.shape.name.safeParse(name).success;
4154
4154
  }
4155
4155
  function claudeJsonPath(identitiesDir, identity) {
4156
- return import_node_path16.default.join(identitiesDir, identity, CLAUDE_JSON);
4156
+ return import_node_path17.default.join(identitiesDir, identity, CLAUDE_JSON);
4157
4157
  }
4158
4158
  function readAccountMetadata(fs12, identitiesDir, identity) {
4159
4159
  if (!isIdentityName(identity)) {
@@ -4207,11 +4207,11 @@ function createAccountReader(fs12, identitiesDir) {
4207
4207
  return account;
4208
4208
  };
4209
4209
  }
4210
- var import_node_path16, CLAUDE_JSON, AccountMetadataError;
4210
+ var import_node_path17, CLAUDE_JSON, AccountMetadataError;
4211
4211
  var init_account = __esm({
4212
4212
  "src/usage/account.ts"() {
4213
4213
  "use strict";
4214
- import_node_path16 = __toESM(require("node:path"), 1);
4214
+ import_node_path17 = __toESM(require("node:path"), 1);
4215
4215
  init_cliError();
4216
4216
  init_schema();
4217
4217
  init_schema2();
@@ -4677,7 +4677,7 @@ function readUsageLog(fs12, logDir, options = {}) {
4677
4677
  if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
4678
4678
  continue;
4679
4679
  }
4680
- const contents = fs12.readFileUtf8(import_node_path17.default.join(logDir, segment.name));
4680
+ const contents = fs12.readFileUtf8(import_node_path18.default.join(logDir, segment.name));
4681
4681
  if (contents === void 0) {
4682
4682
  continue;
4683
4683
  }
@@ -4711,7 +4711,7 @@ function snapshotPath(snapshotsDir, identity) {
4711
4711
  if (!isIdentityName(identity)) {
4712
4712
  throw new Error(`"${identity}" is not a valid identity name.`);
4713
4713
  }
4714
- return import_node_path17.default.join(snapshotsDir, `${identity}.json`);
4714
+ return import_node_path18.default.join(snapshotsDir, `${identity}.json`);
4715
4715
  }
4716
4716
  function readUsageSnapshot(fs12, snapshotsDir, identity) {
4717
4717
  const file = snapshotPath(snapshotsDir, identity);
@@ -4744,11 +4744,11 @@ function listUsageSnapshots(fs12, snapshotsDir) {
4744
4744
  return snapshot === void 0 ? [] : [snapshot];
4745
4745
  }).sort((left, right) => left.identity.localeCompare(right.identity));
4746
4746
  }
4747
- var import_node_path17, SEGMENT_RE, DAY_MS, UsageSnapshotError;
4747
+ var import_node_path18, SEGMENT_RE, DAY_MS, UsageSnapshotError;
4748
4748
  var init_read = __esm({
4749
4749
  "src/usage/read.ts"() {
4750
4750
  "use strict";
4751
- import_node_path17 = __toESM(require("node:path"), 1);
4751
+ import_node_path18 = __toESM(require("node:path"), 1);
4752
4752
  init_account();
4753
4753
  init_schema2();
4754
4754
  SEGMENT_RE = /^(\d{4}-\d{2}-\d{2})\.(\d+)\.jsonl$/;
@@ -4769,7 +4769,7 @@ function pruneUsageLog(fs12, logDir, nowMs) {
4769
4769
  const cutoff = nowMs - USAGE_RETENTION_MS;
4770
4770
  for (const segment of listLogSegments(fs12, logDir)) {
4771
4771
  if (segment.endsAt <= cutoff) {
4772
- fs12.removeRecursive(import_node_path18.default.join(logDir, segment.name));
4772
+ fs12.removeRecursive(import_node_path19.default.join(logDir, segment.name));
4773
4773
  }
4774
4774
  }
4775
4775
  }
@@ -4851,7 +4851,7 @@ function createUsageStore(deps) {
4851
4851
  pruneUsageLog(fs12, paths.usageLogDir, nowMs);
4852
4852
  prunedDay = day;
4853
4853
  }
4854
- fs12.appendFilePrivate(import_node_path18.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
4854
+ fs12.appendFilePrivate(import_node_path19.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
4855
4855
  `);
4856
4856
  if (record.identity !== void 0) {
4857
4857
  rewriteSnapshot(record.identity, (current) => ({ ...current?.providers, [record.provider]: foldProviderState(current?.providers[record.provider], record) }));
@@ -4874,11 +4874,11 @@ function createUsageStore(deps) {
4874
4874
  })
4875
4875
  };
4876
4876
  }
4877
- var import_node_path18, DAY_MS2, DAYS_IN_WEEK, USAGE_RETENTION_MS;
4877
+ var import_node_path19, DAY_MS2, DAYS_IN_WEEK, USAGE_RETENTION_MS;
4878
4878
  var init_store2 = __esm({
4879
4879
  "src/usage/store.ts"() {
4880
4880
  "use strict";
4881
- import_node_path18 = __toESM(require("node:path"), 1);
4881
+ import_node_path19 = __toESM(require("node:path"), 1);
4882
4882
  init_account();
4883
4883
  init_rateLimit();
4884
4884
  init_read();
@@ -5016,15 +5016,15 @@ function recordStickyPick(fs12, picksFile, directory, identity, nowMs) {
5016
5016
  const current = readPicksFile(fs12, picksFile).file.picks;
5017
5017
  const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
5018
5018
  const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
5019
- fs12.mkdirPrivate(import_node_path19.default.dirname(picksFile));
5019
+ fs12.mkdirPrivate(import_node_path20.default.dirname(picksFile));
5020
5020
  fs12.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
5021
5021
  `);
5022
5022
  }
5023
- var import_node_path19, import_zod10, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
5023
+ var import_node_path20, import_zod10, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
5024
5024
  var init_poolPick = __esm({
5025
5025
  "src/usage/poolPick.ts"() {
5026
5026
  "use strict";
5027
- import_node_path19 = __toESM(require("node:path"), 1);
5027
+ import_node_path20 = __toESM(require("node:path"), 1);
5028
5028
  import_zod10 = require("zod");
5029
5029
  init_cliError();
5030
5030
  init_identity();
@@ -5055,8 +5055,8 @@ function resolveAgentShimHome(env = process.env, home = import_node_os4.default.
5055
5055
  if (fromEnv !== void 0 && fromEnv !== "") {
5056
5056
  return fromEnv;
5057
5057
  }
5058
- const current = import_node_path21.default.join(home, HOME_DIRNAME);
5059
- const legacy = import_node_path21.default.join(home, LEGACY_HOME_DIRNAME);
5058
+ const current = import_node_path22.default.join(home, HOME_DIRNAME);
5059
+ const legacy = import_node_path22.default.join(home, LEGACY_HOME_DIRNAME);
5060
5060
  return !isDirectory(current) && isDirectory(legacy) ? legacy : current;
5061
5061
  }
5062
5062
  function isExistingDirectory(candidate) {
@@ -5067,54 +5067,54 @@ function resolveClaudeHome() {
5067
5067
  if (fromEnv !== void 0 && fromEnv !== "") {
5068
5068
  return fromEnv;
5069
5069
  }
5070
- return import_node_path21.default.join(import_node_os4.default.homedir(), ".claude");
5070
+ return import_node_path22.default.join(import_node_os4.default.homedir(), ".claude");
5071
5071
  }
5072
5072
  function buildLayoutPaths(root) {
5073
5073
  return {
5074
5074
  root,
5075
- identitiesDir: import_node_path21.default.join(root, "identities"),
5076
- configProfilesDir: import_node_path21.default.join(root, "config-profiles"),
5077
- providersDir: import_node_path21.default.join(root, "providers"),
5078
- directoryRulesFile: import_node_path21.default.join(root, "directory-rules.json"),
5079
- activeIdentityFile: import_node_path21.default.join(root, "active-identity"),
5080
- globalConfigFile: import_node_path21.default.join(root, "config.json"),
5081
- categoriesLocalFile: import_node_path21.default.join(root, "categories.local.json"),
5082
- claudeShimFile: import_node_path21.default.join(root, "claude-shim.json"),
5083
- headroomDir: import_node_path21.default.join(root, "headroom"),
5084
- headroomStateFile: import_node_path21.default.join(root, "headroom", `state.v${String(HEADROOM_STATE_SCHEMA_VERSION)}.json`),
5085
- headroomSocketDir: import_node_path21.default.join(root, "headroom", "run"),
5086
- headroomLockFile: import_node_path21.default.join(root, "headroom", "start.lock"),
5087
- headroomSessionsDir: import_node_path21.default.join(root, "headroom", "sessions"),
5088
- logsDir: import_node_path21.default.join(root, "logs"),
5089
- headroomLogPath: import_node_path21.default.join(root, "logs", "headroom.log"),
5090
- frontdoorDir: import_node_path21.default.join(root, "frontdoor"),
5091
- frontdoorCaDir: import_node_path21.default.join(root, "frontdoor", "ca"),
5092
- frontdoorCaCertFile: import_node_path21.default.join(root, "frontdoor", "ca", "ca.pem"),
5093
- frontdoorCaKeyFile: import_node_path21.default.join(root, "frontdoor", "ca", "ca.key"),
5094
- frontdoorCaBundlesDir: import_node_path21.default.join(root, "frontdoor", "ca", "bundles"),
5095
- chatgptSignInFile: import_node_path21.default.join(root, "codex", "chatgpt-sign-in.json"),
5096
- frontdoorStateFile: import_node_path21.default.join(root, "frontdoor", "state.json"),
5097
- frontdoorLockFile: import_node_path21.default.join(root, "frontdoor", "start.lock"),
5098
- frontdoorControlTokenFile: import_node_path21.default.join(root, "frontdoor", "control-token"),
5099
- frontdoorSessionsDir: import_node_path21.default.join(root, "frontdoor", "sessions"),
5100
- frontdoorRcCredentialsDir: import_node_path21.default.join(root, "frontdoor", "rc-credentials"),
5101
- frontdoorLogPath: import_node_path21.default.join(root, "logs", "frontdoor.log"),
5102
- usageDir: import_node_path21.default.join(root, "usage"),
5103
- usageLogDir: import_node_path21.default.join(root, "usage", "log"),
5104
- usageSnapshotsDir: import_node_path21.default.join(root, "usage", "snapshots"),
5105
- usagePicksFile: import_node_path21.default.join(root, "usage", "picks.json")
5075
+ identitiesDir: import_node_path22.default.join(root, "identities"),
5076
+ configProfilesDir: import_node_path22.default.join(root, "config-profiles"),
5077
+ providersDir: import_node_path22.default.join(root, "providers"),
5078
+ directoryRulesFile: import_node_path22.default.join(root, "directory-rules.json"),
5079
+ activeIdentityFile: import_node_path22.default.join(root, "active-identity"),
5080
+ globalConfigFile: import_node_path22.default.join(root, "config.json"),
5081
+ categoriesLocalFile: import_node_path22.default.join(root, "categories.local.json"),
5082
+ claudeShimFile: import_node_path22.default.join(root, "claude-shim.json"),
5083
+ headroomDir: import_node_path22.default.join(root, "headroom"),
5084
+ headroomStateFile: import_node_path22.default.join(root, "headroom", `state.v${String(HEADROOM_STATE_SCHEMA_VERSION)}.json`),
5085
+ headroomSocketDir: import_node_path22.default.join(root, "headroom", "run"),
5086
+ headroomLockFile: import_node_path22.default.join(root, "headroom", "start.lock"),
5087
+ headroomSessionsDir: import_node_path22.default.join(root, "headroom", "sessions"),
5088
+ logsDir: import_node_path22.default.join(root, "logs"),
5089
+ headroomLogPath: import_node_path22.default.join(root, "logs", "headroom.log"),
5090
+ frontdoorDir: import_node_path22.default.join(root, "frontdoor"),
5091
+ frontdoorCaDir: import_node_path22.default.join(root, "frontdoor", "ca"),
5092
+ frontdoorCaCertFile: import_node_path22.default.join(root, "frontdoor", "ca", "ca.pem"),
5093
+ frontdoorCaKeyFile: import_node_path22.default.join(root, "frontdoor", "ca", "ca.key"),
5094
+ frontdoorCaBundlesDir: import_node_path22.default.join(root, "frontdoor", "ca", "bundles"),
5095
+ chatgptSignInFile: import_node_path22.default.join(root, "codex", "chatgpt-sign-in.json"),
5096
+ frontdoorStateFile: import_node_path22.default.join(root, "frontdoor", "state.json"),
5097
+ frontdoorLockFile: import_node_path22.default.join(root, "frontdoor", "start.lock"),
5098
+ frontdoorControlTokenFile: import_node_path22.default.join(root, "frontdoor", "control-token"),
5099
+ frontdoorSessionsDir: import_node_path22.default.join(root, "frontdoor", "sessions"),
5100
+ frontdoorRcCredentialsDir: import_node_path22.default.join(root, "frontdoor", "rc-credentials"),
5101
+ frontdoorLogPath: import_node_path22.default.join(root, "logs", "frontdoor.log"),
5102
+ usageDir: import_node_path22.default.join(root, "usage"),
5103
+ usageLogDir: import_node_path22.default.join(root, "usage", "log"),
5104
+ usageSnapshotsDir: import_node_path22.default.join(root, "usage", "snapshots"),
5105
+ usagePicksFile: import_node_path22.default.join(root, "usage", "picks.json")
5106
5106
  };
5107
5107
  }
5108
5108
  function resolveLayoutPaths() {
5109
5109
  return buildLayoutPaths(resolveAgentShimHome());
5110
5110
  }
5111
- var import_node_fs4, import_node_os4, import_node_path21;
5111
+ var import_node_fs4, import_node_os4, import_node_path22;
5112
5112
  var init_paths = __esm({
5113
5113
  "src/paths.ts"() {
5114
5114
  "use strict";
5115
5115
  import_node_fs4 = __toESM(require("node:fs"), 1);
5116
5116
  import_node_os4 = __toESM(require("node:os"), 1);
5117
- import_node_path21 = __toESM(require("node:path"), 1);
5117
+ import_node_path22 = __toESM(require("node:path"), 1);
5118
5118
  init_state2();
5119
5119
  init_legacy();
5120
5120
  }
@@ -5220,8 +5220,8 @@ function security(args, stdin) {
5220
5220
  return { status: result.status, stdout: result.stdout };
5221
5221
  }
5222
5222
  function createRealCredentialCache(root) {
5223
- const dir = import_node_path22.default.join(root, "credential-cache");
5224
- const filePath = (owner) => import_node_path22.default.join(dir, cacheFileNameFor(owner));
5223
+ const dir = import_node_path23.default.join(root, "credential-cache");
5224
+ const filePath = (owner) => import_node_path23.default.join(dir, cacheFileNameFor(owner));
5225
5225
  return {
5226
5226
  read(store, owner) {
5227
5227
  if (store === "file") {
@@ -5267,13 +5267,13 @@ function createRealCredentialCache(root) {
5267
5267
  function realCredentialCacheEnv(paths) {
5268
5268
  return { port: createRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
5269
5269
  }
5270
- var import_node_child_process2, import_node_fs5, import_node_path22, KEYCHAIN_CACHE_SERVICE, CACHE_DIR_MODE, CACHE_FILE_MODE;
5270
+ var import_node_child_process2, import_node_fs5, import_node_path23, KEYCHAIN_CACHE_SERVICE, CACHE_DIR_MODE, CACHE_FILE_MODE;
5271
5271
  var init_realCredentialCache = __esm({
5272
5272
  "src/realCredentialCache.ts"() {
5273
5273
  "use strict";
5274
5274
  import_node_child_process2 = require("node:child_process");
5275
5275
  import_node_fs5 = __toESM(require("node:fs"), 1);
5276
- import_node_path22 = __toESM(require("node:path"), 1);
5276
+ import_node_path23 = __toESM(require("node:path"), 1);
5277
5277
  init_credentialCache();
5278
5278
  KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
5279
5279
  CACHE_DIR_MODE = 448;
@@ -5456,7 +5456,7 @@ var init_credential = __esm({
5456
5456
 
5457
5457
  // src/providersStore.ts
5458
5458
  function providerJsonPath(paths, name) {
5459
- return import_node_path23.default.join(paths.providersDir, `${name}.json`);
5459
+ return import_node_path24.default.join(paths.providersDir, `${name}.json`);
5460
5460
  }
5461
5461
  function providerExists(paths, name) {
5462
5462
  return import_node_fs6.default.existsSync(providerJsonPath(paths, name));
@@ -5516,7 +5516,7 @@ function readProvider(paths, name) {
5516
5516
  return parseProviderFile(filePath, raw);
5517
5517
  }
5518
5518
  function loadProvider(providersDir, name, port) {
5519
- const filePath = import_node_path23.default.join(providersDir, `${name}.json`);
5519
+ const filePath = import_node_path24.default.join(providersDir, `${name}.json`);
5520
5520
  const raw = port.readConfigFile(filePath);
5521
5521
  return raw === void 0 ? void 0 : parseProviderFile(filePath, raw);
5522
5522
  }
@@ -5670,12 +5670,12 @@ function resolveProvider(params) {
5670
5670
  }
5671
5671
  return { ok: true, provider: { name, definition, credential: resolution.credential }, warnings: resolution.credential.warnings };
5672
5672
  }
5673
- var import_node_fs6, import_node_path23, ProviderNotFoundError, ProviderAlreadyExistsError, InvalidProviderNameError, PROVIDER_NAME_RE, LEGACY_PROVIDER_FIELDS, LEGACY_ENV_CREDENTIAL_KEYS, LEGACY_LITERAL_PLACEHOLDER, LegacyProviderFileError, ProviderKindMismatchError;
5673
+ var import_node_fs6, import_node_path24, ProviderNotFoundError, ProviderAlreadyExistsError, InvalidProviderNameError, PROVIDER_NAME_RE, LEGACY_PROVIDER_FIELDS, LEGACY_ENV_CREDENTIAL_KEYS, LEGACY_LITERAL_PLACEHOLDER, LegacyProviderFileError, ProviderKindMismatchError;
5674
5674
  var init_providersStore = __esm({
5675
5675
  "src/providersStore.ts"() {
5676
5676
  "use strict";
5677
5677
  import_node_fs6 = __toESM(require("node:fs"), 1);
5678
- import_node_path23 = __toESM(require("node:path"), 1);
5678
+ import_node_path24 = __toESM(require("node:path"), 1);
5679
5679
  init_load();
5680
5680
  init_store();
5681
5681
  init_schema();
@@ -5887,10 +5887,10 @@ function commandFilename(ownExecutablePath, commandName) {
5887
5887
  }
5888
5888
  function resolveOwnBinaryCheck(paths, contentSourcePath) {
5889
5889
  const state = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
5890
- const recordedTarget = state === void 0 ? void 0 : import_node_path25.default.resolve(state.targetPath);
5890
+ const recordedTarget = state === void 0 ? void 0 : import_node_path26.default.resolve(state.targetPath);
5891
5891
  let ownStat;
5892
5892
  return (candidate) => {
5893
- if (recordedTarget !== void 0 && import_node_path25.default.resolve(candidate) === recordedTarget) {
5893
+ if (recordedTarget !== void 0 && import_node_path26.default.resolve(candidate) === recordedTarget) {
5894
5894
  return true;
5895
5895
  }
5896
5896
  ownStat ??= statOrUndefined(contentSourcePath);
@@ -5913,22 +5913,22 @@ function statOrUndefined(target) {
5913
5913
  }
5914
5914
  }
5915
5915
  function findPathShadow(params) {
5916
- const resolvedTargetDir = import_node_path25.default.resolve(params.targetDir);
5916
+ const resolvedTargetDir = import_node_path26.default.resolve(params.targetDir);
5917
5917
  for (const dir of params.pathDirs) {
5918
5918
  const found = params.findExecutableInDir(dir, params.targetFilename);
5919
5919
  if (found === void 0) {
5920
5920
  continue;
5921
5921
  }
5922
- return import_node_path25.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
5922
+ return import_node_path26.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
5923
5923
  }
5924
- return params.pathDirs.some((dir) => import_node_path25.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
5924
+ return params.pathDirs.some((dir) => import_node_path26.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
5925
5925
  }
5926
- var import_node_fs7, import_node_path25, import_zod15, ClaudeShimStateSchema, nodeLinkFs;
5926
+ var import_node_fs7, import_node_path26, import_zod15, ClaudeShimStateSchema, nodeLinkFs;
5927
5927
  var init_claudeShim = __esm({
5928
5928
  "src/claudeShim.ts"() {
5929
5929
  "use strict";
5930
5930
  import_node_fs7 = __toESM(require("node:fs"), 1);
5931
- import_node_path25 = __toESM(require("node:path"), 1);
5931
+ import_node_path26 = __toESM(require("node:path"), 1);
5932
5932
  import_zod15 = require("zod");
5933
5933
  init_commandDeps();
5934
5934
  init_store();
@@ -6378,7 +6378,7 @@ function buildEnv(params) {
6378
6378
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
6379
6379
  let providerCustomHeaders;
6380
6380
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
6381
- env.CLAUDE_CONFIG_DIR = import_node_path30.default.join(params.identitiesDir, params.resolvedIdentityName);
6381
+ env.CLAUDE_CONFIG_DIR = import_node_path31.default.join(params.identitiesDir, params.resolvedIdentityName);
6382
6382
  }
6383
6383
  if (params.provider !== void 0) {
6384
6384
  const providerEnv = params.provider.definition.env ?? {};
@@ -6422,11 +6422,11 @@ function buildEnv(params) {
6422
6422
  }
6423
6423
  return env;
6424
6424
  }
6425
- var import_node_path30, LOOPBACK_HOSTS;
6425
+ var import_node_path31, LOOPBACK_HOSTS;
6426
6426
  var init_flags = __esm({
6427
6427
  "src/launcher/flags.ts"() {
6428
6428
  "use strict";
6429
- import_node_path30 = __toESM(require("node:path"), 1);
6429
+ import_node_path31 = __toESM(require("node:path"), 1);
6430
6430
  init_envBool();
6431
6431
  init_credential();
6432
6432
  init_headers();
@@ -6772,7 +6772,7 @@ function prepareLaunch(params) {
6772
6772
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
6773
6773
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
6774
6774
  });
6775
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path31.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
6775
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path32.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
6776
6776
  log.error(
6777
6777
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
6778
6778
  );
@@ -6835,7 +6835,7 @@ function prepareLaunch(params) {
6835
6835
  );
6836
6836
  const updateCheck = runLaunchUpdateCheck({
6837
6837
  mode: params.updateMode ?? "off",
6838
- checkPath: import_node_path31.default.join(paths.root, "update.check"),
6838
+ checkPath: import_node_path32.default.join(paths.root, "update.check"),
6839
6839
  currentVersion: package_default.version,
6840
6840
  port: params.update
6841
6841
  });
@@ -6972,12 +6972,12 @@ function runLaunchPlan(plan, spawn2) {
6972
6972
  function runLauncher(params) {
6973
6973
  params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
6974
6974
  }
6975
- var import_node_crypto10, import_node_path31;
6975
+ var import_node_crypto10, import_node_path32;
6976
6976
  var init_launcher = __esm({
6977
6977
  "src/launcher.ts"() {
6978
6978
  "use strict";
6979
6979
  import_node_crypto10 = require("node:crypto");
6980
- import_node_path31 = __toESM(require("node:path"), 1);
6980
+ import_node_path32 = __toESM(require("node:path"), 1);
6981
6981
  init_package();
6982
6982
  init_envBool();
6983
6983
  init_argv();
@@ -7008,13 +7008,13 @@ function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string"
7008
7008
  if (distDir === void 0) {
7009
7009
  throw new OwnCliPathUnknownError();
7010
7010
  }
7011
- return import_node_path32.default.join(distDir, OWN_CLI_FILE_NAME);
7011
+ return import_node_path33.default.join(distDir, OWN_CLI_FILE_NAME);
7012
7012
  }
7013
- var import_node_path32, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
7013
+ var import_node_path33, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
7014
7014
  var init_ownCli = __esm({
7015
7015
  "src/ownCli.ts"() {
7016
7016
  "use strict";
7017
- import_node_path32 = __toESM(require("node:path"), 1);
7017
+ import_node_path33 = __toESM(require("node:path"), 1);
7018
7018
  init_cliError();
7019
7019
  OWN_CLI_FILE_NAME = "cli.cjs";
7020
7020
  OwnCliPathUnknownError = class extends CliError {
@@ -7099,7 +7099,7 @@ request.on("error", (error) => finish(failed, (error.code ? error.code + ": " :
7099
7099
  // src/frontdoor/trust.ts
7100
7100
  function resolveTrustBundle(params) {
7101
7101
  const { caCertFile, bundlesDir, variable, inherited, fs: fs12 } = params;
7102
- if (inherited === void 0 || inherited === "" || import_node_path33.default.resolve(inherited) === import_node_path33.default.resolve(caCertFile)) {
7102
+ if (inherited === void 0 || inherited === "" || import_node_path34.default.resolve(inherited) === import_node_path34.default.resolve(caCertFile)) {
7103
7103
  return { path: caCertFile };
7104
7104
  }
7105
7105
  const caPem = fs12.readFileUtf8(caCertFile);
@@ -7117,19 +7117,19 @@ function resolveTrustBundle(params) {
7117
7117
  }
7118
7118
  const combined = `${inheritedPem.trimEnd()}
7119
7119
  ${caPem}`;
7120
- const bundle = import_node_path33.default.join(bundlesDir, `${(0, import_node_crypto11.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
7120
+ const bundle = import_node_path34.default.join(bundlesDir, `${(0, import_node_crypto11.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
7121
7121
  if (!fs12.exists(bundle)) {
7122
7122
  fs12.mkdirp(bundlesDir);
7123
7123
  fs12.writeFileAtomic(bundle, combined);
7124
7124
  }
7125
7125
  return { path: bundle };
7126
7126
  }
7127
- var import_node_crypto11, import_node_path33, BUNDLE_NAME_HEX_DIGITS;
7127
+ var import_node_crypto11, import_node_path34, BUNDLE_NAME_HEX_DIGITS;
7128
7128
  var init_trust = __esm({
7129
7129
  "src/frontdoor/trust.ts"() {
7130
7130
  "use strict";
7131
7131
  import_node_crypto11 = require("node:crypto");
7132
- import_node_path33 = __toESM(require("node:path"), 1);
7132
+ import_node_path34 = __toESM(require("node:path"), 1);
7133
7133
  BUNDLE_NAME_HEX_DIGITS = 16;
7134
7134
  }
7135
7135
  });
@@ -7882,6 +7882,7 @@ __export(index_exports, {
7882
7882
  updateDirectoryRule: () => updateDirectoryRule,
7883
7883
  updateProvider: () => updateProvider,
7884
7884
  useIdentity: () => useIdentity,
7885
+ watchedInstallEntry: () => watchedInstallEntry,
7885
7886
  writeDirectoryRules: () => writeDirectoryRules
7886
7887
  });
7887
7888
  module.exports = __toCommonJS(index_exports);
@@ -8219,12 +8220,22 @@ init_capability();
8219
8220
  init_route();
8220
8221
 
8221
8222
  // src/frontdoor/supervisor.ts
8223
+ var import_node_path9 = __toESM(require("node:path"), 1);
8222
8224
  init_state();
8225
+ function watchedInstallEntry(resolvedOwnExecutablePath, siblingExists) {
8226
+ const parsed = import_node_path9.default.parse(resolvedOwnExecutablePath);
8227
+ if (parsed.name === "agent-shim") {
8228
+ return resolvedOwnExecutablePath;
8229
+ }
8230
+ const sibling = import_node_path9.default.join(parsed.dir, `agent-shim${parsed.ext}`);
8231
+ return siblingExists(sibling) ? sibling : resolvedOwnExecutablePath;
8232
+ }
8223
8233
  var FRONTDOOR_SUPERVISOR_STILL_RUNNING = -1;
8224
8234
  var FRONTDOOR_POLL_MS = 1e3;
8225
8235
  var MS_PER_MINUTE = 6e4;
8226
8236
  async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {}) {
8227
8237
  const { fs: fs12, paths } = ports;
8238
+ const servingBinary = ports.statOwnExecutable();
8228
8239
  const previous = readFrontDoorState(fs12, paths.frontdoorStateFile);
8229
8240
  let lastPort = previous?.lastPort;
8230
8241
  let lastConnectPort = previous?.lastConnectPort;
@@ -8287,6 +8298,18 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
8287
8298
  ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http3.port)}, CONNECT surface on 127.0.0.1:${String(connect3.port)}`);
8288
8299
  let idleSince;
8289
8300
  let ticks = 0;
8301
+ const binaryReplaced = () => {
8302
+ const current = ports.statOwnExecutable();
8303
+ return current !== void 0 && servingBinary !== void 0 && (current.dev !== servingBinary.dev || current.ino !== servingBinary.ino || current.size !== servingBinary.size || current.mtimeMs !== servingBinary.mtimeMs);
8304
+ };
8305
+ const shutdown = async () => {
8306
+ await direct.close();
8307
+ await connect3.close();
8308
+ await http3.close();
8309
+ ports.closeRcStreamHub();
8310
+ writeFrontDoorState(fs12, paths.frontdoorStateFile, sticky());
8311
+ return 0;
8312
+ };
8290
8313
  for (; ; ) {
8291
8314
  if (options.tickLimit !== void 0 && ticks >= options.tickLimit) {
8292
8315
  return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
@@ -8298,16 +8321,16 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
8298
8321
  ports.checkQuotaExpiry();
8299
8322
  const prunedPids = new Set(pruned);
8300
8323
  if (listed.filter((session) => !prunedPids.has(session.pid)).length === 0) {
8324
+ if (ticks > 1 && binaryReplaced()) {
8325
+ ports.log("agent-shim frontdoor supervisor: the installed binary changed and no sessions are live; turning the door over for the next launch");
8326
+ ports.doorHealth.binaryTurnover();
8327
+ return await shutdown();
8328
+ }
8301
8329
  idleSince ??= ports.now();
8302
8330
  if (ports.now() - idleSince >= idleShutdownMinutes * MS_PER_MINUTE) {
8303
8331
  ports.log(`agent-shim frontdoor supervisor: no sessions for ${String(idleShutdownMinutes)} minute(s); closing the front door and exiting`);
8304
8332
  ports.doorHealth.idleShutdown();
8305
- await direct.close();
8306
- await connect3.close();
8307
- await http3.close();
8308
- ports.closeRcStreamHub();
8309
- writeFrontDoorState(fs12, paths.frontdoorStateFile, sticky());
8310
- return 0;
8333
+ return await shutdown();
8311
8334
  }
8312
8335
  } else {
8313
8336
  idleSince = void 0;
@@ -8361,8 +8384,8 @@ function parseConnectTarget(authority) {
8361
8384
  function isInterceptedHost(host, interceptHosts) {
8362
8385
  return interceptHosts.includes(host);
8363
8386
  }
8364
- function servedByPipeline(path34) {
8365
- return path34?.startsWith(ROUTED_PATH_PREFIX) === true;
8387
+ function servedByPipeline(path35) {
8388
+ return path35?.startsWith(ROUTED_PATH_PREFIX) === true;
8366
8389
  }
8367
8390
  var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
8368
8391
  "connection",
@@ -8896,11 +8919,11 @@ function createRcSessionTracker(deps) {
8896
8919
  };
8897
8920
  const observeExchange = (request4) => {
8898
8921
  const method = (request4.method ?? "").toUpperCase();
8899
- const path34 = new URL(request4.url ?? "/", "http://127.0.0.1").pathname;
8900
- if (!path34.startsWith(RC_SESSIONS_PATH_PREFIX)) {
8922
+ const path35 = new URL(request4.url ?? "/", "http://127.0.0.1").pathname;
8923
+ if (!path35.startsWith(RC_SESSIONS_PATH_PREFIX)) {
8901
8924
  return void 0;
8902
8925
  }
8903
- const tail = path34.slice(RC_SESSIONS_PATH_PREFIX.length);
8926
+ const tail = path35.slice(RC_SESSIONS_PATH_PREFIX.length);
8904
8927
  const facts = {
8905
8928
  oauthAuthorization: oauthAuthorizationOf(request4.headers),
8906
8929
  anthropicVersion: singleHeader(request4.headers, "anthropic-version"),
@@ -9282,8 +9305,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
9282
9305
  function isRcReadFileEncoding(value) {
9283
9306
  return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
9284
9307
  }
9285
- function buildRcReadFilePayload(requestId, path34, options) {
9286
- return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path34, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
9308
+ function buildRcReadFilePayload(requestId, path35, options) {
9309
+ return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path35, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
9287
9310
  }
9288
9311
  function buildRcFileSuggestionsPayload(requestId, query) {
9289
9312
  return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
@@ -9385,15 +9408,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
9385
9408
  const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
9386
9409
  return result.ok ? { ...result, requestId } : result;
9387
9410
  }
9388
- async function readRcSessionFile(deps, sessionId, path34, options) {
9389
- if (path34 === "") {
9411
+ async function readRcSessionFile(deps, sessionId, path35, options) {
9412
+ if (path35 === "") {
9390
9413
  return { ok: false, message: "a read-file write needs a non-empty path: the SDK's own field names the file the worker resolves against the session's cwd, and an empty string names none" };
9391
9414
  }
9392
9415
  if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
9393
9416
  return { ok: false, message: "a read-file write's max-bytes is a positive whole number of bytes: the SDK's own field caps the read, and a zero or negative cap reads nothing" };
9394
9417
  }
9395
9418
  const requestId = deps.newUuid();
9396
- const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path34, options), `read ${path34} from session ${sessionId}`);
9419
+ const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path35, options), `read ${path35} from session ${sessionId}`);
9397
9420
  return result.ok ? { ...result, requestId } : result;
9398
9421
  }
9399
9422
  async function suggestRcSessionFiles(deps, sessionId, query) {
@@ -9562,11 +9585,11 @@ function createRcControlHandler(deps) {
9562
9585
  path: "read-file",
9563
9586
  read: (body) => {
9564
9587
  const session = bodyString(body, "session");
9565
- const path34 = bodyString(body, "path");
9588
+ const path35 = bodyString(body, "path");
9566
9589
  const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
9567
9590
  const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
9568
- const refused2 = session === void 0 || path34 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
9569
- return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session, path34, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
9591
+ const refused2 = session === void 0 || path35 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
9592
+ return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session, path35, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
9570
9593
  }
9571
9594
  },
9572
9595
  {
@@ -9876,9 +9899,9 @@ function requestIdOfBody(body) {
9876
9899
  }
9877
9900
  function frontDoorRcControl(transport, token) {
9878
9901
  const headers = { authorization: `Bearer ${token}` };
9879
- const listAnswerOf = async (path34, what) => {
9902
+ const listAnswerOf = async (path35, what) => {
9880
9903
  try {
9881
- return await transport.request({ method: "GET", path: path34, headers });
9904
+ return await transport.request({ method: "GET", path: path35, headers });
9882
9905
  } catch (error) {
9883
9906
  throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
9884
9907
  }
@@ -9950,10 +9973,10 @@ function frontDoorRcControl(transport, token) {
9950
9973
  }
9951
9974
  return pending;
9952
9975
  };
9953
- const writeOf = async (path34, body, describeFailure) => {
9976
+ const writeOf = async (path35, body, describeFailure) => {
9954
9977
  let answer;
9955
9978
  try {
9956
- answer = await transport.request({ method: "POST", path: path34, headers: { ...headers, "content-type": "application/json" }, body });
9979
+ answer = await transport.request({ method: "POST", path: path35, headers: { ...headers, "content-type": "application/json" }, body });
9957
9980
  } catch (error) {
9958
9981
  return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
9959
9982
  }
@@ -9984,10 +10007,10 @@ function frontDoorRcControl(transport, token) {
9984
10007
  endSession: async (sessionId, reason) => await writeOf(`${CONTROL_PATH_PREFIX}/end-session`, JSON.stringify({ session: sessionId, ...reason === void 0 ? {} : { reason } }), (status, message) => `ending ${sessionId} failed (HTTP ${String(status)}): ${message}`),
9985
10008
  getUsage: async (sessionId, skipBehaviors) => await writeOf(`${CONTROL_PATH_PREFIX}/get-usage`, JSON.stringify({ session: sessionId, ...skipBehaviors === void 0 ? {} : { skipBehaviors } }), (status, message) => `requesting the usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
9986
10009
  getContextUsage: async (sessionId, detail) => await writeOf(`${CONTROL_PATH_PREFIX}/get-context-usage`, JSON.stringify({ session: sessionId, ...detail === void 0 ? {} : { detail } }), (status, message) => `requesting the context usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
9987
- readFile: async (sessionId, path34, options) => await writeOf(
10010
+ readFile: async (sessionId, path35, options) => await writeOf(
9988
10011
  `${CONTROL_PATH_PREFIX}/read-file`,
9989
- JSON.stringify({ session: sessionId, path: path34, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
9990
- (status, message) => `reading ${path34} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
10012
+ JSON.stringify({ session: sessionId, path: path35, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
10013
+ (status, message) => `reading ${path35} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
9991
10014
  ),
9992
10015
  fileSuggestions: async (sessionId, query) => await writeOf(`${CONTROL_PATH_PREFIX}/file-suggestions`, JSON.stringify({ session: sessionId, query }), (status, message) => `requesting file suggestions from ${sessionId} failed (HTTP ${String(status)}): ${message}`),
9993
10016
  keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
@@ -10142,12 +10165,12 @@ function tlsFacts(options) {
10142
10165
  }
10143
10166
  function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
10144
10167
  const agent = new ExemptTlsAgent();
10145
- const post = async (path34, headers, body) => await new Promise((resolve, reject) => {
10168
+ const post = async (path35, headers, body) => await new Promise((resolve, reject) => {
10146
10169
  const options = {
10147
10170
  host: target.host,
10148
10171
  port: target.port,
10149
10172
  method: "POST",
10150
- path: path34,
10173
+ path: path35,
10151
10174
  // The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
10152
10175
  headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
10153
10176
  agent
@@ -10212,12 +10235,12 @@ function lateRcStreamDial(resolve) {
10212
10235
  }
10213
10236
  function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
10214
10237
  const agent = new ExemptTlsAgent();
10215
- const request4 = async (method, path34, headers, body, signal) => await new Promise((resolve, reject) => {
10238
+ const request4 = async (method, path35, headers, body, signal) => await new Promise((resolve, reject) => {
10216
10239
  const options = {
10217
10240
  host: target.host,
10218
10241
  port: target.port,
10219
10242
  method,
10220
- path: path34,
10243
+ path: path35,
10221
10244
  // The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
10222
10245
  headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
10223
10246
  agent,
@@ -10259,9 +10282,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
10259
10282
  return { status, body: await readAll(response) };
10260
10283
  },
10261
10284
  openStream: async (sessionId, headers, resume, signal) => {
10262
- const path34 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
10285
+ const path35 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
10263
10286
  const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
10264
- const { status, response } = await request4("GET", path34, streamHeaders, void 0, signal);
10287
+ const { status, response } = await request4("GET", path35, streamHeaders, void 0, signal);
10265
10288
  if (!isSuccessful2(status)) {
10266
10289
  await readAll(response);
10267
10290
  return { status, chunks: NO_CHUNKS };
@@ -10473,7 +10496,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
10473
10496
  }
10474
10497
 
10475
10498
  // src/frontdoor/rcCredentialStore.ts
10476
- var import_node_path9 = __toESM(require("node:path"), 1);
10499
+ var import_node_path10 = __toESM(require("node:path"), 1);
10477
10500
  function isSafeSessionId(sessionId) {
10478
10501
  return /^[A-Za-z0-9_-]+$/.test(sessionId);
10479
10502
  }
@@ -10499,7 +10522,7 @@ function sequenceNumOfJson(value) {
10499
10522
  }
10500
10523
  function createRcCredentialStore(fs12, dir) {
10501
10524
  fs12.mkdirPrivate(dir);
10502
- const fileFor = (sessionId) => import_node_path9.default.join(dir, `${sessionId}.json`);
10525
+ const fileFor = (sessionId) => import_node_path10.default.join(dir, `${sessionId}.json`);
10503
10526
  const readParsed = (sessionId) => {
10504
10527
  const raw = fs12.readFileUtf8(fileFor(sessionId));
10505
10528
  if (raw === void 0) {
@@ -10955,7 +10978,7 @@ init_cliError();
10955
10978
 
10956
10979
  // src/configProfilesStore.ts
10957
10980
  var import_node_fs3 = __toESM(require("node:fs"), 1);
10958
- var import_node_path20 = __toESM(require("node:path"), 1);
10981
+ var import_node_path21 = __toESM(require("node:path"), 1);
10959
10982
  init_store();
10960
10983
  init_schema();
10961
10984
  init_cliError();
@@ -10985,7 +11008,7 @@ var InvalidCategoryNameError = class extends CliError {
10985
11008
  categoryName;
10986
11009
  };
10987
11010
  function profileJsonPath(paths, name) {
10988
- return import_node_path20.default.join(paths.configProfilesDir, `${name}.json`);
11011
+ return import_node_path21.default.join(paths.configProfilesDir, `${name}.json`);
10989
11012
  }
10990
11013
  function profileExists(paths, name) {
10991
11014
  return import_node_fs3.default.existsSync(profileJsonPath(paths, name));
@@ -11125,19 +11148,19 @@ function writePools(paths, pools) {
11125
11148
  applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
11126
11149
  }
11127
11150
  function poolCycleOf(pools, name) {
11128
- const walk = (current, path34) => {
11151
+ const walk = (current, path35) => {
11129
11152
  for (const entry of pools[current]?.identities ?? []) {
11130
11153
  const nested = poolNameOf(poolMemberIdentity(entry));
11131
11154
  if (nested === void 0) {
11132
11155
  continue;
11133
11156
  }
11134
11157
  if (nested === name) {
11135
- return [...path34, nested];
11158
+ return [...path35, nested];
11136
11159
  }
11137
- if (path34.includes(nested)) {
11160
+ if (path35.includes(nested)) {
11138
11161
  continue;
11139
11162
  }
11140
- const found = walk(nested, [...path34, nested]);
11163
+ const found = walk(nested, [...path35, nested]);
11141
11164
  if (found !== void 0) {
11142
11165
  return found;
11143
11166
  }
@@ -11236,7 +11259,7 @@ init_paths();
11236
11259
  init_realCredentialCache();
11237
11260
  init_providersStore();
11238
11261
  init_realPorts();
11239
- var import_node_path24 = __toESM(require("node:path"), 1);
11262
+ var import_node_path25 = __toESM(require("node:path"), 1);
11240
11263
  var import_zod12 = require("zod");
11241
11264
  init_envBool();
11242
11265
  init_load();
@@ -11585,10 +11608,10 @@ function collectCheckReport(params) {
11585
11608
  }).input;
11586
11609
  const providerName = cascadeProviderName(cascade);
11587
11610
  const provider = providerName === void 0 ? void 0 : loadCheckProvider(paths, providerName);
11588
- const farmRoot = identityDecision.name === void 0 ? void 0 : import_node_path24.default.join(paths.identitiesDir, identityDecision.name);
11611
+ const farmRoot = identityDecision.name === void 0 ? void 0 : import_node_path25.default.join(paths.identitiesDir, identityDecision.name);
11589
11612
  const settingsFiles = {
11590
- "settings.json": realFsPort.readFileUtf8(import_node_path24.default.join(claudeHome, "settings.json")),
11591
- "settings.local.json": realFsPort.readFileUtf8(import_node_path24.default.join(claudeHome, "settings.local.json"))
11613
+ "settings.json": realFsPort.readFileUtf8(import_node_path25.default.join(claudeHome, "settings.json")),
11614
+ "settings.local.json": realFsPort.readFileUtf8(import_node_path25.default.join(claudeHome, "settings.local.json"))
11592
11615
  };
11593
11616
  const report = runCheck({
11594
11617
  cwd,
@@ -11808,7 +11831,7 @@ init_middleware();
11808
11831
  init_preflight();
11809
11832
 
11810
11833
  // src/frontdoor/controlSchemas.ts
11811
- var import_node_path28 = __toESM(require("node:path"), 1);
11834
+ var import_node_path29 = __toESM(require("node:path"), 1);
11812
11835
  var import_zod19 = require("zod");
11813
11836
 
11814
11837
  // src/doctorReport.ts
@@ -11817,7 +11840,7 @@ init_store();
11817
11840
 
11818
11841
  // src/identityStore.ts
11819
11842
  var import_node_fs8 = __toESM(require("node:fs"), 1);
11820
- var import_node_path26 = __toESM(require("node:path"), 1);
11843
+ var import_node_path27 = __toESM(require("node:path"), 1);
11821
11844
  init_load();
11822
11845
  init_store();
11823
11846
  init_schema();
@@ -11851,7 +11874,7 @@ var InvalidIdentityNameError = class extends CliError {
11851
11874
  attemptedName;
11852
11875
  };
11853
11876
  function identityJsonPath(paths, name) {
11854
- return import_node_path26.default.join(paths.identitiesDir, name, "identity.json");
11877
+ return import_node_path27.default.join(paths.identitiesDir, name, "identity.json");
11855
11878
  }
11856
11879
  function identityExists(paths, name) {
11857
11880
  return import_node_fs8.default.existsSync(identityJsonPath(paths, name));
@@ -11952,7 +11975,7 @@ function setIdentityCredential(paths, identityName, change) {
11952
11975
  });
11953
11976
  }
11954
11977
  function belongsToIdentity(entry, name) {
11955
- return entry === name || entry === import_node_path26.default.basename(identityLockPath("", name)) || entry.startsWith(`.${name}.scratch.`) || entry.startsWith(`.${name}.previous.`);
11978
+ return entry === name || entry === import_node_path27.default.basename(identityLockPath("", name)) || entry.startsWith(`.${name}.scratch.`) || entry.startsWith(`.${name}.previous.`);
11956
11979
  }
11957
11980
  function removeIdentity(paths, name) {
11958
11981
  if (!identityExists(paths, name)) {
@@ -11960,7 +11983,7 @@ function removeIdentity(paths, name) {
11960
11983
  }
11961
11984
  for (const entry of import_node_fs8.default.readdirSync(paths.identitiesDir)) {
11962
11985
  if (belongsToIdentity(entry, name)) {
11963
- import_node_fs8.default.rmSync(import_node_path26.default.join(paths.identitiesDir, entry), { recursive: true, force: true });
11986
+ import_node_fs8.default.rmSync(import_node_path27.default.join(paths.identitiesDir, entry), { recursive: true, force: true });
11964
11987
  }
11965
11988
  }
11966
11989
  if (readActiveIdentity2(paths) === name) {
@@ -11971,7 +11994,7 @@ function removeIdentity(paths, name) {
11971
11994
  // src/doctorReport.ts
11972
11995
  init_realPorts();
11973
11996
  var import_node_fs9 = __toESM(require("node:fs"), 1);
11974
- var import_node_path27 = __toESM(require("node:path"), 1);
11997
+ var import_node_path28 = __toESM(require("node:path"), 1);
11975
11998
 
11976
11999
  // src/codex/siwcStore.ts
11977
12000
  var import_zod18 = require("zod");
@@ -12104,7 +12127,7 @@ function validateJson(schema, input) {
12104
12127
  return { ok: true, data: result.data };
12105
12128
  }
12106
12129
  function pushPathResolution(push, resolution) {
12107
- const ownDir = import_node_path27.default.dirname(resolution.ownExecutablePath);
12130
+ const ownDir = import_node_path28.default.dirname(resolution.ownExecutablePath);
12108
12131
  switch (resolution.agentShim.status) {
12109
12132
  case "ok":
12110
12133
  push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
@@ -12203,14 +12226,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
12203
12226
  }
12204
12227
  function pushLegacyName(push, params) {
12205
12228
  const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
12206
- if (legacyVariables.length === 0 && import_node_path27.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
12229
+ if (legacyVariables.length === 0 && import_node_path28.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
12207
12230
  push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
12208
12231
  return;
12209
12232
  }
12210
12233
  for (const name of legacyVariables) {
12211
12234
  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);
12212
12235
  }
12213
- if (import_node_path27.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
12236
+ if (import_node_path28.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
12214
12237
  push(
12215
12238
  "legacy-name",
12216
12239
  "warn",
@@ -12550,18 +12573,18 @@ function collectDoctorReport(params) {
12550
12573
  const { paths } = params;
12551
12574
  const identityNames = import_node_fs9.default.existsSync(paths.identitiesDir) ? import_node_fs9.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
12552
12575
  const identities = identityNames.map((name) => {
12553
- const farmRoot = import_node_path27.default.join(paths.identitiesDir, name);
12554
- const identityPath = import_node_path27.default.join(farmRoot, "identity.json");
12576
+ const farmRoot = import_node_path28.default.join(paths.identitiesDir, name);
12577
+ const identityPath = import_node_path28.default.join(farmRoot, "identity.json");
12555
12578
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
12556
12579
  });
12557
12580
  const profileNames = import_node_fs9.default.existsSync(paths.configProfilesDir) ? import_node_fs9.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
12558
12581
  const configProfiles = profileNames.map((name) => {
12559
- const profilePath = import_node_path27.default.join(paths.configProfilesDir, `${name}.json`);
12582
+ const profilePath = import_node_path28.default.join(paths.configProfilesDir, `${name}.json`);
12560
12583
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
12561
12584
  });
12562
12585
  const providerNames = import_node_fs9.default.existsSync(paths.providersDir) ? import_node_fs9.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
12563
12586
  const providers = providerNames.map((name) => {
12564
- const providerPath = import_node_path27.default.join(paths.providersDir, `${name}.json`);
12587
+ const providerPath = import_node_path28.default.join(paths.providersDir, `${name}.json`);
12565
12588
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
12566
12589
  });
12567
12590
  const ownExecutablePath = realOwnExecutablePath();
@@ -12573,12 +12596,12 @@ function collectDoctorReport(params) {
12573
12596
  binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
12574
12597
  }
12575
12598
  const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
12576
- const pathDirs = (params.env.PATH ?? "").split(import_node_path27.default.delimiter).filter((dir) => dir !== "");
12599
+ const pathDirs = (params.env.PATH ?? "").split(import_node_path28.default.delimiter).filter((dir) => dir !== "");
12577
12600
  const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
12578
12601
  findPathShadow({
12579
12602
  pathDirs,
12580
- targetDir: import_node_path27.default.dirname(shimState.targetPath),
12581
- targetFilename: import_node_path27.default.basename(shimState.targetPath),
12603
+ targetDir: import_node_path28.default.dirname(shimState.targetPath),
12604
+ targetFilename: import_node_path28.default.basename(shimState.targetPath),
12582
12605
  findExecutableInDir
12583
12606
  }),
12584
12607
  shimState.targetPath,
@@ -12604,7 +12627,7 @@ function collectDoctorReport(params) {
12604
12627
  agentShim: refinePathShadow(
12605
12628
  findPathShadow({
12606
12629
  pathDirs,
12607
- targetDir: import_node_path27.default.dirname(ownExecutablePath),
12630
+ targetDir: import_node_path28.default.dirname(ownExecutablePath),
12608
12631
  targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
12609
12632
  findExecutableInDir
12610
12633
  }),
@@ -12673,11 +12696,11 @@ var FrontDoorSessionsOutputSchema = import_zod19.z.strictObject({ sessions: impo
12673
12696
  var CheckRunInputSchema = import_zod19.z.strictObject({
12674
12697
  path: import_zod19.z.string().min(1),
12675
12698
  identity: import_zod19.z.string().min(1).optional()
12676
- }).refine((input) => import_node_path28.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
12699
+ }).refine((input) => import_node_path29.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
12677
12700
  var PoolPickInputSchema = import_zod19.z.strictObject({
12678
12701
  pool: import_zod19.z.string().min(1),
12679
12702
  path: import_zod19.z.string().min(1)
12680
- }).refine((input) => import_node_path28.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
12703
+ }).refine((input) => import_node_path29.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
12681
12704
  var DoctorFindingSchema = import_zod19.z.strictObject({
12682
12705
  section: import_zod19.z.enum(DOCTOR_SECTIONS),
12683
12706
  subject: import_zod19.z.string().optional(),
@@ -12719,6 +12742,7 @@ var LaunchLifecycleEventSchema = import_zod20.z.strictObject({
12719
12742
  var DoorHealthEventSchema = import_zod20.z.discriminatedUnion("kind", [
12720
12743
  import_zod20.z.strictObject({ kind: import_zod20.z.literal("generation"), pid: import_zod20.z.number().int().positive(), providerPort: import_zod20.z.number().int().positive(), connectPort: import_zod20.z.number().int().positive(), directPort: import_zod20.z.number().int().positive(), observedAt: import_zod20.z.number() }),
12721
12744
  import_zod20.z.strictObject({ kind: import_zod20.z.literal("listenerFailed"), pid: import_zod20.z.number().int().positive(), listener: import_zod20.z.enum(["provider", "connect", "direct"]), message: import_zod20.z.string(), observedAt: import_zod20.z.number() }),
12745
+ import_zod20.z.strictObject({ kind: import_zod20.z.literal("binaryTurnover"), pid: import_zod20.z.number().int().positive(), observedAt: import_zod20.z.number() }),
12722
12746
  import_zod20.z.strictObject({ kind: import_zod20.z.literal("idleShutdown"), pid: import_zod20.z.number().int().positive(), observedAt: import_zod20.z.number() })
12723
12747
  ]);
12724
12748
  var QuotaExpiringEventSchema = import_zod20.z.strictObject({
@@ -13090,6 +13114,9 @@ function createDoorHealthPublisher(hub, now, pid) {
13090
13114
  },
13091
13115
  idleShutdown: () => {
13092
13116
  publisher.publish({ kind: "idleShutdown", pid, observedAt: now() });
13117
+ },
13118
+ binaryTurnover: () => {
13119
+ publisher.publish({ kind: "binaryTurnover", pid, observedAt: now() });
13093
13120
  }
13094
13121
  };
13095
13122
  }
@@ -14784,7 +14811,7 @@ data: ${JSON.stringify(envelope)}
14784
14811
  }
14785
14812
 
14786
14813
  // src/frontdoor/rcSelfHostMint.ts
14787
- var import_node_path29 = __toESM(require("node:path"), 1);
14814
+ var import_node_path30 = __toESM(require("node:path"), 1);
14788
14815
  init_account();
14789
14816
  var CREDENTIALS_FILE = ".credentials.json";
14790
14817
  var CLAUDE_JSON2 = ".claude.json";
@@ -14809,7 +14836,7 @@ function readJsonObject(fs12, file) {
14809
14836
  return isRecord11(parsed) ? parsed : void 0;
14810
14837
  }
14811
14838
  function readRcSelfHostRecord(fs12, frontdoorDir) {
14812
- const parsed = readJsonObject(fs12, import_node_path29.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
14839
+ const parsed = readJsonObject(fs12, import_node_path30.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
14813
14840
  if (parsed === void 0) {
14814
14841
  return void 0;
14815
14842
  }
@@ -14823,11 +14850,11 @@ function mintRcSelfHostCredential(deps) {
14823
14850
  if (!isIdentityName(deps.identity)) {
14824
14851
  throw new Error(`"${deps.identity}" is not a valid identity name.`);
14825
14852
  }
14826
- const identityDir = import_node_path29.default.join(deps.identitiesDir, deps.identity);
14827
- const credentialsFile = import_node_path29.default.join(identityDir, CREDENTIALS_FILE);
14828
- const claudeJsonFile = import_node_path29.default.join(identityDir, CLAUDE_JSON2);
14829
- const recordDir = import_node_path29.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
14830
- const recordFile = import_node_path29.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
14853
+ const identityDir = import_node_path30.default.join(deps.identitiesDir, deps.identity);
14854
+ const credentialsFile = import_node_path30.default.join(identityDir, CREDENTIALS_FILE);
14855
+ const claudeJsonFile = import_node_path30.default.join(identityDir, CLAUDE_JSON2);
14856
+ const recordDir = import_node_path30.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
14857
+ const recordFile = import_node_path30.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
14831
14858
  const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
14832
14859
  const existingCredentials = readJsonObject(deps.fs, credentialsFile);
14833
14860
  const existingOauth = isRecord11(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
@@ -14843,7 +14870,7 @@ function mintRcSelfHostCredential(deps) {
14843
14870
  const organizationUuid = deps.newUuid();
14844
14871
  const accountUuid = deps.newUuid();
14845
14872
  const mintedAt = new Date(deps.now()).toISOString();
14846
- deps.fs.mkdirPrivate(import_node_path29.default.dirname(credentialsFile));
14873
+ deps.fs.mkdirPrivate(import_node_path30.default.dirname(credentialsFile));
14847
14874
  deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
14848
14875
  `);
14849
14876
  const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
@@ -15376,5 +15403,6 @@ init_ownCli();
15376
15403
  updateDirectoryRule,
15377
15404
  updateProvider,
15378
15405
  useIdentity,
15406
+ watchedInstallEntry,
15379
15407
  writeDirectoryRules
15380
15408
  });