agent-shim 8.6.0 → 8.7.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
@@ -6026,6 +6026,56 @@ var import_node_path16 = __toESM(require("node:path"), 1);
6026
6026
 
6027
6027
  // src/credentialCache.ts
6028
6028
  var import_zod7 = require("zod");
6029
+
6030
+ // src/usage/preflight.ts
6031
+ var MS_PER_SECOND2 = 1e3;
6032
+ var SECONDS_PER_MINUTE = 60;
6033
+ var MINUTES_PER_HOUR = 60;
6034
+ var HOURS_PER_DAY = 24;
6035
+ var WARNING_STATUSES = /* @__PURE__ */ new Set(["allowed_warning", "rejected"]);
6036
+ function formatAge(ms) {
6037
+ const minutes = Math.floor(ms / (MS_PER_SECOND2 * SECONDS_PER_MINUTE));
6038
+ if (minutes < MINUTES_PER_HOUR) {
6039
+ return `${String(Math.max(minutes, 0))}m`;
6040
+ }
6041
+ const hours = Math.floor(minutes / MINUTES_PER_HOUR);
6042
+ return hours < HOURS_PER_DAY ? `${String(hours)}h` : `${String(Math.floor(hours / HOURS_PER_DAY))}d`;
6043
+ }
6044
+ function effectiveWindow(window, nowMs) {
6045
+ const resetsAtMs = window.resetsAt === void 0 ? void 0 : Date.parse(window.resetsAt);
6046
+ if (resetsAtMs !== void 0 && resetsAtMs <= nowMs) {
6047
+ return { reset: true, utilization: 0 };
6048
+ }
6049
+ return {
6050
+ reset: false,
6051
+ ...window.utilization === void 0 ? {} : { utilization: window.utilization },
6052
+ ...resetsAtMs === void 0 ? {} : { resetsAtMs },
6053
+ ...window.status === void 0 ? {} : { status: window.status }
6054
+ };
6055
+ }
6056
+ function quotaWarnings(snapshot, provider, nowMs) {
6057
+ const rateLimit = snapshot?.providers[provider]?.rateLimit;
6058
+ const unified = rateLimit?.unified;
6059
+ if (snapshot === void 0 || rateLimit === void 0 || unified === void 0) {
6060
+ return [];
6061
+ }
6062
+ const age = formatAge(nowMs - Date.parse(rateLimit.observedAt));
6063
+ const windows = [
6064
+ { name: "five-hour", window: unified.fiveHour },
6065
+ { name: "seven-day", window: unified.sevenDay }
6066
+ ];
6067
+ return windows.flatMap(({ name, window }) => {
6068
+ const effective = window === void 0 ? void 0 : effectiveWindow(window, nowMs);
6069
+ if (window === void 0 || effective?.status === void 0 || !WARNING_STATUSES.has(effective.status)) {
6070
+ return [];
6071
+ }
6072
+ const reset = window.resetsAt === void 0 ? "" : `, resets ${window.resetsAt}`;
6073
+ const verdict = effective.status === "rejected" ? "exhausted" : "nearly used";
6074
+ return [`agent-shim: identity ${snapshot.identity}: the ${name} quota is ${verdict}${reset} (last seen ${age} ago)`];
6075
+ });
6076
+ }
6077
+
6078
+ // src/credentialCache.ts
6029
6079
  var MS_PER_UNIT = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
6030
6080
  var CachedCredentialSchema = import_zod7.z.strictObject({
6031
6081
  token: import_zod7.z.string().min(1),
@@ -6052,6 +6102,45 @@ function isFresh(entry, cache, now) {
6052
6102
  }
6053
6103
  return limit === void 0 || now - entry.fetchedAt < limit;
6054
6104
  }
6105
+ function cacheAgeMs(entry, now) {
6106
+ return Math.max(0, now - entry.fetchedAt);
6107
+ }
6108
+ function describeCachedCredential(params) {
6109
+ const store = effectiveStore(params.cache, params.platform);
6110
+ let entry;
6111
+ try {
6112
+ entry = params.port.read(store, params.owner);
6113
+ } catch (error) {
6114
+ return { store, status: "unreadable", reason: error instanceof Error ? error.message : String(error) };
6115
+ }
6116
+ if (entry === void 0) {
6117
+ return { store, status: "empty" };
6118
+ }
6119
+ const limit = ttlMs(params.cache);
6120
+ const ageMs = cacheAgeMs(entry, params.nowMs);
6121
+ return {
6122
+ store,
6123
+ status: isFresh(entry, params.cache, params.nowMs) ? "fresh" : "expired",
6124
+ ageMs,
6125
+ ...limit === void 0 ? {} : { expiresInMs: limit - ageMs }
6126
+ };
6127
+ }
6128
+ function formatCachedCredentialState(state) {
6129
+ if (state.status === "empty") {
6130
+ return `no cached entry in the ${state.store} store yet`;
6131
+ }
6132
+ if (state.status === "unreadable") {
6133
+ return `the ${state.store} store cannot be read here: ${state.reason}`;
6134
+ }
6135
+ if (state.status === "expired" && (state.expiresInMs === void 0 || state.expiresInMs > 0)) {
6136
+ return "cached with a timestamp in the future, treated as expired";
6137
+ }
6138
+ const age = `cached ${formatAge(state.ageMs)} ago`;
6139
+ if (state.expiresInMs === void 0) {
6140
+ return `${age}, no expiry`;
6141
+ }
6142
+ return state.status === "fresh" ? `${age}, expires in ${formatAge(state.expiresInMs)}` : `${age}, expired ${formatAge(-state.expiresInMs)} ago`;
6143
+ }
6055
6144
 
6056
6145
  // src/credential.ts
6057
6146
  var CREDENTIAL_UNAVAILABLE_EXIT = 64;
@@ -6667,54 +6756,6 @@ function readDirectorySelections(loaded) {
6667
6756
  return { ...identity === void 0 ? {} : { identity }, ...configProfile === void 0 ? {} : { configProfile } };
6668
6757
  }
6669
6758
 
6670
- // src/usage/preflight.ts
6671
- var MS_PER_SECOND2 = 1e3;
6672
- var SECONDS_PER_MINUTE = 60;
6673
- var MINUTES_PER_HOUR = 60;
6674
- var HOURS_PER_DAY = 24;
6675
- var WARNING_STATUSES = /* @__PURE__ */ new Set(["allowed_warning", "rejected"]);
6676
- function formatAge(ms) {
6677
- const minutes = Math.floor(ms / (MS_PER_SECOND2 * SECONDS_PER_MINUTE));
6678
- if (minutes < MINUTES_PER_HOUR) {
6679
- return `${String(Math.max(minutes, 0))}m`;
6680
- }
6681
- const hours = Math.floor(minutes / MINUTES_PER_HOUR);
6682
- return hours < HOURS_PER_DAY ? `${String(hours)}h` : `${String(Math.floor(hours / HOURS_PER_DAY))}d`;
6683
- }
6684
- function effectiveWindow(window, nowMs) {
6685
- const resetsAtMs = window.resetsAt === void 0 ? void 0 : Date.parse(window.resetsAt);
6686
- if (resetsAtMs !== void 0 && resetsAtMs <= nowMs) {
6687
- return { reset: true, utilization: 0 };
6688
- }
6689
- return {
6690
- reset: false,
6691
- ...window.utilization === void 0 ? {} : { utilization: window.utilization },
6692
- ...resetsAtMs === void 0 ? {} : { resetsAtMs },
6693
- ...window.status === void 0 ? {} : { status: window.status }
6694
- };
6695
- }
6696
- function quotaWarnings(snapshot, provider, nowMs) {
6697
- const rateLimit = snapshot?.providers[provider]?.rateLimit;
6698
- const unified = rateLimit?.unified;
6699
- if (snapshot === void 0 || rateLimit === void 0 || unified === void 0) {
6700
- return [];
6701
- }
6702
- const age = formatAge(nowMs - Date.parse(rateLimit.observedAt));
6703
- const windows = [
6704
- { name: "five-hour", window: unified.fiveHour },
6705
- { name: "seven-day", window: unified.sevenDay }
6706
- ];
6707
- return windows.flatMap(({ name, window }) => {
6708
- const effective = window === void 0 ? void 0 : effectiveWindow(window, nowMs);
6709
- if (window === void 0 || effective?.status === void 0 || !WARNING_STATUSES.has(effective.status)) {
6710
- return [];
6711
- }
6712
- const reset = window.resetsAt === void 0 ? "" : `, resets ${window.resetsAt}`;
6713
- const verdict = effective.status === "rejected" ? "exhausted" : "nearly used";
6714
- return [`agent-shim: identity ${snapshot.identity}: the ${name} quota is ${verdict}${reset} (last seen ${age} ago)`];
6715
- });
6716
- }
6717
-
6718
6759
  // src/usage/poolPick.ts
6719
6760
  var import_node_path19 = __toESM(require("node:path"), 1);
6720
6761
  var import_zod9 = require("zod");
@@ -7110,19 +7151,97 @@ function collectPoolPick(params) {
7110
7151
  };
7111
7152
  }
7112
7153
 
7113
- // src/realPorts.ts
7154
+ // src/realCredentialCache.ts
7114
7155
  var import_node_child_process = require("node:child_process");
7115
- var import_node_crypto9 = require("node:crypto");
7116
7156
  var import_node_fs6 = __toESM(require("node:fs"), 1);
7157
+ var import_node_path20 = __toESM(require("node:path"), 1);
7158
+ var KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
7159
+ var CACHE_DIR_MODE = 448;
7160
+ var CACHE_FILE_MODE = 384;
7161
+ function cacheFileNameFor(owner) {
7162
+ return `${owner.replace(/[^A-Za-z0-9._-]/g, "_")}.json`;
7163
+ }
7164
+ function parseEntry(raw) {
7165
+ let json;
7166
+ try {
7167
+ json = JSON.parse(raw);
7168
+ } catch {
7169
+ return void 0;
7170
+ }
7171
+ const parsed = CachedCredentialSchema.safeParse(json);
7172
+ return parsed.success ? parsed.data : void 0;
7173
+ }
7174
+ function requireKeychain() {
7175
+ if (process.platform !== "darwin") {
7176
+ throw new Error("the keychain credential store needs macOS; use --credential-cache-store file");
7177
+ }
7178
+ }
7179
+ function security(args, stdin) {
7180
+ const result = (0, import_node_child_process.spawnSync)("security", args, { encoding: "utf8", ...stdin === void 0 ? {} : { input: stdin }, stdio: ["pipe", "pipe", "ignore"] });
7181
+ return { status: result.status, stdout: result.stdout };
7182
+ }
7183
+ function createRealCredentialCache(root) {
7184
+ const dir = import_node_path20.default.join(root, "credential-cache");
7185
+ const filePath = (owner) => import_node_path20.default.join(dir, cacheFileNameFor(owner));
7186
+ return {
7187
+ read(store, owner) {
7188
+ if (store === "file") {
7189
+ try {
7190
+ return parseEntry(import_node_fs6.default.readFileSync(filePath(owner), "utf8"));
7191
+ } catch {
7192
+ return void 0;
7193
+ }
7194
+ }
7195
+ requireKeychain();
7196
+ const result = security(["find-generic-password", "-s", KEYCHAIN_CACHE_SERVICE, "-a", owner, "-w"]);
7197
+ return result.status === 0 ? parseEntry(Buffer.from(result.stdout.trim(), "base64").toString("utf8")) : void 0;
7198
+ },
7199
+ write(store, owner, entry) {
7200
+ const serialised = JSON.stringify(entry);
7201
+ if (store === "file") {
7202
+ import_node_fs6.default.mkdirSync(dir, { recursive: true, mode: CACHE_DIR_MODE });
7203
+ import_node_fs6.default.chmodSync(dir, CACHE_DIR_MODE);
7204
+ const target = filePath(owner);
7205
+ const temp = `${target}.${String(process.pid)}.tmp`;
7206
+ import_node_fs6.default.writeFileSync(temp, serialised, { mode: CACHE_FILE_MODE });
7207
+ import_node_fs6.default.renameSync(temp, target);
7208
+ return;
7209
+ }
7210
+ requireKeychain();
7211
+ const encoded = Buffer.from(serialised, "utf8").toString("base64");
7212
+ const result = security(["-i"], `add-generic-password -U -s ${KEYCHAIN_CACHE_SERVICE} -a ${JSON.stringify(owner)} -w ${encoded}
7213
+ `);
7214
+ if (result.status !== 0) {
7215
+ throw new Error(`could not write the keychain credential cache for ${owner}`);
7216
+ }
7217
+ },
7218
+ remove(store, owner) {
7219
+ if (store === "file") {
7220
+ import_node_fs6.default.rmSync(filePath(owner), { force: true });
7221
+ return;
7222
+ }
7223
+ requireKeychain();
7224
+ security(["delete-generic-password", "-s", KEYCHAIN_CACHE_SERVICE, "-a", owner]);
7225
+ }
7226
+ };
7227
+ }
7228
+ function realCredentialCacheEnv(paths) {
7229
+ return { port: createRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
7230
+ }
7231
+
7232
+ // src/realPorts.ts
7233
+ var import_node_child_process2 = require("node:child_process");
7234
+ var import_node_crypto9 = require("node:crypto");
7235
+ var import_node_fs7 = __toESM(require("node:fs"), 1);
7117
7236
  var import_node_os3 = __toESM(require("node:os"), 1);
7118
- var import_node_path21 = __toESM(require("node:path"), 1);
7237
+ var import_node_path22 = __toESM(require("node:path"), 1);
7119
7238
  var import_node_sea = require("node:sea");
7120
7239
 
7121
7240
  // src/versionDiscovery.ts
7122
7241
  var import_node_os2 = __toESM(require("node:os"), 1);
7123
- var import_node_path20 = __toESM(require("node:path"), 1);
7242
+ var import_node_path21 = __toESM(require("node:path"), 1);
7124
7243
  function defaultVersionsDir() {
7125
- return import_node_path20.default.join(import_node_os2.default.homedir(), ".local", "share", "claude", "versions");
7244
+ return import_node_path21.default.join(import_node_os2.default.homedir(), ".local", "share", "claude", "versions");
7126
7245
  }
7127
7246
  var NUMERIC_DOTTED_VERSION_RE = /^\d+(?:\.\d+)*$/;
7128
7247
  function isNumericDottedVersion(name) {
@@ -7164,7 +7283,7 @@ function discoverClaudeBinary(options) {
7164
7283
  const highestVersion = pickHighestVersion(entries);
7165
7284
  if (highestVersion !== void 0) {
7166
7285
  return {
7167
- path: import_node_path20.default.join(versionsDir, highestVersion),
7286
+ path: import_node_path21.default.join(versionsDir, highestVersion),
7168
7287
  source: "versions-dir",
7169
7288
  version: highestVersion
7170
7289
  };
@@ -7187,7 +7306,7 @@ function isEnoent3(error) {
7187
7306
  var realFsPort = {
7188
7307
  readFileUtf8(filePath) {
7189
7308
  try {
7190
- return import_node_fs6.default.readFileSync(filePath, "utf8");
7309
+ return import_node_fs7.default.readFileSync(filePath, "utf8");
7191
7310
  } catch (error) {
7192
7311
  if (isEnoent3(error)) {
7193
7312
  return void 0;
@@ -7198,7 +7317,7 @@ var realFsPort = {
7198
7317
  readConfigFile: cosmiconfigReader(),
7199
7318
  readdir(dirPath) {
7200
7319
  try {
7201
- return import_node_fs6.default.readdirSync(dirPath);
7320
+ return import_node_fs7.default.readdirSync(dirPath);
7202
7321
  } catch (error) {
7203
7322
  if (isEnoent3(error)) {
7204
7323
  return [];
@@ -7217,7 +7336,7 @@ var realFarmFs = {
7217
7336
  lstat(filePath) {
7218
7337
  let stat;
7219
7338
  try {
7220
- stat = import_node_fs6.default.lstatSync(filePath);
7339
+ stat = import_node_fs7.default.lstatSync(filePath);
7221
7340
  } catch (error) {
7222
7341
  if (isEnoent3(error)) {
7223
7342
  return void 0;
@@ -7229,7 +7348,7 @@ var realFarmFs = {
7229
7348
  },
7230
7349
  readdir(dirPath) {
7231
7350
  try {
7232
- return import_node_fs6.default.readdirSync(dirPath);
7351
+ return import_node_fs7.default.readdirSync(dirPath);
7233
7352
  } catch (error) {
7234
7353
  if (isEnoent3(error) || isErrorWithCode(error, "ENOTDIR")) {
7235
7354
  return [];
@@ -7238,23 +7357,23 @@ var realFarmFs = {
7238
7357
  }
7239
7358
  },
7240
7359
  mkdirp(dirPath) {
7241
- import_node_fs6.default.mkdirSync(dirPath, { recursive: true });
7360
+ import_node_fs7.default.mkdirSync(dirPath, { recursive: true });
7242
7361
  },
7243
7362
  symlink(target, linkPath) {
7244
- import_node_fs6.default.symlinkSync(target, linkPath);
7363
+ import_node_fs7.default.symlinkSync(target, linkPath);
7245
7364
  },
7246
7365
  rename(from, to) {
7247
- import_node_fs6.default.renameSync(from, to);
7366
+ import_node_fs7.default.renameSync(from, to);
7248
7367
  },
7249
7368
  removeRecursive(targetPath) {
7250
- import_node_fs6.default.rmSync(targetPath, { recursive: true, force: true });
7369
+ import_node_fs7.default.rmSync(targetPath, { recursive: true, force: true });
7251
7370
  },
7252
7371
  copyRecursive(from, to) {
7253
- import_node_fs6.default.cpSync(from, to, { recursive: true, force: true, verbatimSymlinks: true });
7372
+ import_node_fs7.default.cpSync(from, to, { recursive: true, force: true, verbatimSymlinks: true });
7254
7373
  },
7255
7374
  readFileUtf8(filePath) {
7256
7375
  try {
7257
- return import_node_fs6.default.readFileSync(filePath, "utf8");
7376
+ return import_node_fs7.default.readFileSync(filePath, "utf8");
7258
7377
  } catch (error) {
7259
7378
  if (isEnoent3(error)) {
7260
7379
  return void 0;
@@ -7263,36 +7382,36 @@ var realFarmFs = {
7263
7382
  }
7264
7383
  },
7265
7384
  writeFileUtf8(filePath, contents) {
7266
- import_node_fs6.default.writeFileSync(filePath, contents, "utf8");
7385
+ import_node_fs7.default.writeFileSync(filePath, contents, "utf8");
7267
7386
  },
7268
7387
  mkdirPrivate(dirPath) {
7269
- import_node_fs6.default.mkdirSync(dirPath, { recursive: true, mode: OWNER_ONLY_DIR_MODE });
7270
- import_node_fs6.default.chmodSync(dirPath, OWNER_ONLY_DIR_MODE);
7388
+ import_node_fs7.default.mkdirSync(dirPath, { recursive: true, mode: OWNER_ONLY_DIR_MODE });
7389
+ import_node_fs7.default.chmodSync(dirPath, OWNER_ONLY_DIR_MODE);
7271
7390
  },
7272
7391
  writeFilePrivate(filePath, contents) {
7273
7392
  const temp = `${filePath}.${String(process.pid)}.tmp`;
7274
- import_node_fs6.default.writeFileSync(temp, contents, { encoding: "utf8", mode: OWNER_ONLY_FILE_MODE });
7275
- import_node_fs6.default.chmodSync(temp, OWNER_ONLY_FILE_MODE);
7276
- import_node_fs6.default.renameSync(temp, filePath);
7393
+ import_node_fs7.default.writeFileSync(temp, contents, { encoding: "utf8", mode: OWNER_ONLY_FILE_MODE });
7394
+ import_node_fs7.default.chmodSync(temp, OWNER_ONLY_FILE_MODE);
7395
+ import_node_fs7.default.renameSync(temp, filePath);
7277
7396
  },
7278
7397
  appendFilePrivate(filePath, contents) {
7279
- const descriptor = import_node_fs6.default.openSync(filePath, "a", OWNER_ONLY_FILE_MODE);
7398
+ const descriptor = import_node_fs7.default.openSync(filePath, "a", OWNER_ONLY_FILE_MODE);
7280
7399
  try {
7281
- if ((import_node_fs6.default.fstatSync(descriptor).mode & PERMISSION_BITS2) !== OWNER_ONLY_FILE_MODE) {
7282
- import_node_fs6.default.fchmodSync(descriptor, OWNER_ONLY_FILE_MODE);
7400
+ if ((import_node_fs7.default.fstatSync(descriptor).mode & PERMISSION_BITS2) !== OWNER_ONLY_FILE_MODE) {
7401
+ import_node_fs7.default.fchmodSync(descriptor, OWNER_ONLY_FILE_MODE);
7283
7402
  }
7284
7403
  const bytes = Buffer.from(contents, "utf8");
7285
7404
  let written = 0;
7286
7405
  while (written < bytes.length) {
7287
- written += import_node_fs6.default.writeSync(descriptor, bytes, written, bytes.length - written);
7406
+ written += import_node_fs7.default.writeSync(descriptor, bytes, written, bytes.length - written);
7288
7407
  }
7289
7408
  } finally {
7290
- import_node_fs6.default.closeSync(descriptor);
7409
+ import_node_fs7.default.closeSync(descriptor);
7291
7410
  }
7292
7411
  },
7293
7412
  writeFileExclusive(filePath, contents) {
7294
7413
  try {
7295
- import_node_fs6.default.writeFileSync(filePath, contents, { encoding: "utf8", flag: "wx" });
7414
+ import_node_fs7.default.writeFileSync(filePath, contents, { encoding: "utf8", flag: "wx" });
7296
7415
  return true;
7297
7416
  } catch (error) {
7298
7417
  if (isErrorWithCode(error, "EEXIST")) {
@@ -7303,7 +7422,7 @@ var realFarmFs = {
7303
7422
  },
7304
7423
  hashFile(filePath) {
7305
7424
  try {
7306
- return (0, import_node_crypto9.createHash)("sha256").update(import_node_fs6.default.readFileSync(filePath)).digest("hex");
7425
+ return (0, import_node_crypto9.createHash)("sha256").update(import_node_fs7.default.readFileSync(filePath)).digest("hex");
7307
7426
  } catch (error) {
7308
7427
  if (isEnoent3(error) || isErrorWithCode(error, "EISDIR")) {
7309
7428
  return void 0;
@@ -7325,7 +7444,7 @@ function realIsProcessAlive(pid) {
7325
7444
  }
7326
7445
  }
7327
7446
  function realIsProcessZombie(pid) {
7328
- const result = (0, import_node_child_process.spawnSync)("ps", ["-o", "stat=", "-p", String(pid)], { encoding: "utf8" });
7447
+ const result = (0, import_node_child_process2.spawnSync)("ps", ["-o", "stat=", "-p", String(pid)], { encoding: "utf8" });
7329
7448
  return result.status === 0 && result.stdout.trim().startsWith("Z");
7330
7449
  }
7331
7450
  function realIsProcessRunning(pid) {
@@ -7333,17 +7452,17 @@ function realIsProcessRunning(pid) {
7333
7452
  }
7334
7453
  var realRunPort = {
7335
7454
  run(command, args) {
7336
- const result = (0, import_node_child_process.spawnSync)(command, [...args], { encoding: "utf8" });
7455
+ const result = (0, import_node_child_process2.spawnSync)(command, [...args], { encoding: "utf8" });
7337
7456
  return { status: result.status, stdout: result.stdout, stderr: result.stderr };
7338
7457
  }
7339
7458
  };
7340
7459
  function expandHome2(filePath) {
7341
- return filePath.startsWith("~/") ? import_node_path21.default.join(import_node_os3.default.homedir(), filePath.slice(1)) : filePath;
7460
+ return filePath.startsWith("~/") ? import_node_path22.default.join(import_node_os3.default.homedir(), filePath.slice(1)) : filePath;
7342
7461
  }
7343
7462
  var MACOS_GUI_SESSION_MANAGER = "Aqua";
7344
7463
  function hasDesktopSession() {
7345
7464
  if (process.platform === "darwin") {
7346
- const result = (0, import_node_child_process.spawnSync)("launchctl", ["managername"], { encoding: "utf8" });
7465
+ const result = (0, import_node_child_process2.spawnSync)("launchctl", ["managername"], { encoding: "utf8" });
7347
7466
  return result.status === 0 && result.stdout.trim() === MACOS_GUI_SESSION_MANAGER;
7348
7467
  }
7349
7468
  if (process.platform === "win32") {
@@ -7357,8 +7476,8 @@ var realCredentialPort = {
7357
7476
  let content;
7358
7477
  let stat;
7359
7478
  try {
7360
- stat = import_node_fs6.default.statSync(resolved);
7361
- content = import_node_fs6.default.readFileSync(resolved, "utf8");
7479
+ stat = import_node_fs7.default.statSync(resolved);
7480
+ content = import_node_fs7.default.readFileSync(resolved, "utf8");
7362
7481
  } catch (error) {
7363
7482
  if (isEnoent3(error)) {
7364
7483
  return { found: false };
@@ -7369,7 +7488,7 @@ var realCredentialPort = {
7369
7488
  },
7370
7489
  runCommand(argv, options) {
7371
7490
  const [command, ...args] = argv;
7372
- const result = (0, import_node_child_process.spawnSync)(command, args, {
7491
+ const result = (0, import_node_child_process2.spawnSync)(command, args, {
7373
7492
  encoding: "utf8",
7374
7493
  timeout: options.timeoutMs,
7375
7494
  stdio: options.interactive ? ["inherit", "pipe", "inherit"] : ["ignore", "pipe", "pipe"]
@@ -7411,17 +7530,17 @@ function spawnDaemonThrough(executable) {
7411
7530
  return (paths, subcommand, logPath) => spawnDetachedDaemon({ command: executable, args: [subcommand] }, paths, subcommand, logPath);
7412
7531
  }
7413
7532
  function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
7414
- import_node_fs6.default.mkdirSync(import_node_path21.default.dirname(logPath), { recursive: true });
7415
- const logFd = import_node_fs6.default.openSync(logPath, "a");
7533
+ import_node_fs7.default.mkdirSync(import_node_path22.default.dirname(logPath), { recursive: true });
7534
+ const logFd = import_node_fs7.default.openSync(logPath, "a");
7416
7535
  try {
7417
- const child = (0, import_node_child_process.spawn)(invocation.command, invocation.args, detachedDaemonSpawnOptions(logFd, { ...process.env, AGENT_SHIM_HOME: paths.root }));
7536
+ const child = (0, import_node_child_process2.spawn)(invocation.command, invocation.args, detachedDaemonSpawnOptions(logFd, { ...process.env, AGENT_SHIM_HOME: paths.root }));
7418
7537
  child.unref();
7419
7538
  if (child.pid === void 0) {
7420
7539
  throw new Error(`spawning ${subcommand} returned no pid`);
7421
7540
  }
7422
7541
  return child.pid;
7423
7542
  } finally {
7424
- import_node_fs6.default.closeSync(logFd);
7543
+ import_node_fs7.default.closeSync(logFd);
7425
7544
  }
7426
7545
  }
7427
7546
  function spawnHeadroomSupervisor(paths, spawnDaemon) {
@@ -7439,7 +7558,7 @@ var realHeadroomSocketTrust = {
7439
7558
  lstat: (target) => {
7440
7559
  let stat;
7441
7560
  try {
7442
- stat = import_node_fs6.default.lstatSync(target);
7561
+ stat = import_node_fs7.default.lstatSync(target);
7443
7562
  } catch (error) {
7444
7563
  if (isEnoent3(error)) {
7445
7564
  return void 0;
@@ -7485,7 +7604,7 @@ var EXECUTE_BITS_MASK = 73;
7485
7604
  function listVersionsDir(dir) {
7486
7605
  let entries;
7487
7606
  try {
7488
- entries = import_node_fs6.default.readdirSync(dir, { withFileTypes: true });
7607
+ entries = import_node_fs7.default.readdirSync(dir, { withFileTypes: true });
7489
7608
  } catch (error) {
7490
7609
  if (isEnoent3(error)) {
7491
7610
  return [];
@@ -7493,8 +7612,8 @@ function listVersionsDir(dir) {
7493
7612
  throw error;
7494
7613
  }
7495
7614
  return entries.filter((entry) => entry.isFile()).map((entry) => {
7496
- const fullPath = import_node_path21.default.join(dir, entry.name);
7497
- const stat = import_node_fs6.default.statSync(fullPath);
7615
+ const fullPath = import_node_path22.default.join(dir, entry.name);
7616
+ const stat = import_node_fs7.default.statSync(fullPath);
7498
7617
  return {
7499
7618
  name: entry.name,
7500
7619
  isFile: true,
@@ -7508,7 +7627,7 @@ function windowsPathExtensions(pathext) {
7508
7627
  return (pathext ?? WINDOWS_DEFAULT_PATHEXT).split(";").map((ext) => ext.trim()).filter((ext) => ext.length > 0);
7509
7628
  }
7510
7629
  function resolveExecutableCandidate(dir, name, env) {
7511
- const candidate = import_node_path21.default.join(dir, name);
7630
+ const candidate = import_node_path22.default.join(dir, name);
7512
7631
  if (env.platform === "win32") {
7513
7632
  const extensions = windowsPathExtensions(env.pathext);
7514
7633
  const alreadyHasRecognisedExtension = extensions.some((ext) => candidate.toLowerCase().endsWith(ext.toLowerCase()));
@@ -7528,7 +7647,7 @@ function resolveExecutableCandidate(dir, name, env) {
7528
7647
  }
7529
7648
  function realStatFileMode(candidate) {
7530
7649
  try {
7531
- const stat = import_node_fs6.default.statSync(candidate);
7650
+ const stat = import_node_fs7.default.statSync(candidate);
7532
7651
  return stat.isFile() ? stat.mode : void 0;
7533
7652
  } catch (error) {
7534
7653
  if (isEnoent3(error)) {
@@ -7557,13 +7676,13 @@ function resolveOwnExecutablePath(env) {
7557
7676
  if (env.argv1 !== void 0 && !env.argv1.includes("/") && !env.argv1.includes("\\")) {
7558
7677
  return searchPathForExecutable(env.pathDirs, env.argv1, env.findExecutableInDir) ?? env.execPath;
7559
7678
  }
7560
- const candidate = env.argv1 === void 0 ? env.execPath : import_node_path21.default.resolve(env.cwd, env.argv1);
7561
- const candidateDir = import_node_path21.default.dirname(candidate);
7562
- const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path21.default.resolve(dir) === candidateDir);
7679
+ const candidate = env.argv1 === void 0 ? env.execPath : import_node_path22.default.resolve(env.cwd, env.argv1);
7680
+ const candidateDir = import_node_path22.default.dirname(candidate);
7681
+ const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path22.default.resolve(dir) === candidateDir);
7563
7682
  if (candidateDirOnPath) {
7564
7683
  return candidate;
7565
7684
  }
7566
- const viaPath = searchPathForExecutable(env.pathDirs, import_node_path21.default.basename(candidate), env.findExecutableInDir);
7685
+ const viaPath = searchPathForExecutable(env.pathDirs, import_node_path22.default.basename(candidate), env.findExecutableInDir);
7567
7686
  return viaPath ?? candidate;
7568
7687
  }
7569
7688
  function realOwnExecutablePath() {
@@ -7571,7 +7690,7 @@ function realOwnExecutablePath() {
7571
7690
  argv1: process.argv[1],
7572
7691
  execPath: process.execPath,
7573
7692
  cwd: process.cwd(),
7574
- pathDirs: (process.env.PATH ?? "").split(import_node_path21.default.delimiter).filter((dir) => dir !== ""),
7693
+ pathDirs: (process.env.PATH ?? "").split(import_node_path22.default.delimiter).filter((dir) => dir !== ""),
7575
7694
  findExecutableInDir
7576
7695
  });
7577
7696
  }
@@ -7584,14 +7703,14 @@ function realContentSourcePath() {
7584
7703
  function realResolveClaudeBinary(isOwnBinary) {
7585
7704
  return () => discoverClaudeBinary({
7586
7705
  listVersionsDir,
7587
- pathDirs: (process.env.PATH ?? "").split(import_node_path21.default.delimiter).filter((dir) => dir !== ""),
7706
+ pathDirs: (process.env.PATH ?? "").split(import_node_path22.default.delimiter).filter((dir) => dir !== ""),
7588
7707
  findExecutableInDir,
7589
7708
  isOwnBinary
7590
7709
  });
7591
7710
  }
7592
7711
 
7593
7712
  // src/checkReport.ts
7594
- var import_node_path22 = __toESM(require("node:path"), 1);
7713
+ var import_node_path23 = __toESM(require("node:path"), 1);
7595
7714
  var import_zod10 = require("zod");
7596
7715
 
7597
7716
  // src/cli/bool.ts
@@ -7761,14 +7880,23 @@ function inspectSettingsExposure(params) {
7761
7880
  }
7762
7881
  return reports;
7763
7882
  }
7764
- function buildCredentialReport(provider, identity) {
7883
+ function cachedState(cacheEnv, owner, block) {
7884
+ if (cacheEnv === void 0 || block.cache === void 0) {
7885
+ return void 0;
7886
+ }
7887
+ return describeCachedCredential({ port: cacheEnv.port, platform: cacheEnv.platform, owner, cache: block.cache, nowMs: cacheEnv.now() });
7888
+ }
7889
+ function buildCredentialReport(provider, identity, identityName, cacheEnv) {
7765
7890
  const identityCredential = identity?.credential === void 0 ? void 0 : summariseCredential(identity.credential);
7891
+ const identityCached = identity?.credential === void 0 || identityName === void 0 ? void 0 : cachedState(cacheEnv, `identity ${identityName}`, identity.credential);
7892
+ const providerCached = provider?.definition === void 0 ? void 0 : cachedState(cacheEnv, `provider ${provider.name}`, provider.definition.credential);
7766
7893
  return {
7767
7894
  applies: provider !== void 0 ? "provider" : identityCredential !== void 0 ? "identity" : "stored-login",
7768
7895
  ...provider === void 0 ? {} : {
7769
- provider: provider.problem === void 0 ? { name: provider.name, credential: summariseCredential(provider.definition.credential) } : { name: provider.name, problem: provider.problem }
7896
+ provider: provider.problem === void 0 ? { name: provider.name, credential: summariseCredential(provider.definition.credential), ...providerCached === void 0 ? {} : { cached: providerCached } } : { name: provider.name, problem: provider.problem }
7770
7897
  },
7771
- ...identityCredential === void 0 ? {} : { identity: identityCredential }
7898
+ ...identityCredential === void 0 ? {} : { identity: identityCredential },
7899
+ ...identityCached === void 0 ? {} : { identityCached }
7772
7900
  };
7773
7901
  }
7774
7902
  function runCheck(params) {
@@ -7807,7 +7935,7 @@ function runCheck(params) {
7807
7935
  ambientCredential,
7808
7936
  ...keychain === void 0 ? {} : { keychain },
7809
7937
  settingsExposure,
7810
- credential: buildCredentialReport(params.provider, params.identity)
7938
+ credential: buildCredentialReport(params.provider, params.identity, params.identityName, params.credentialCache)
7811
7939
  };
7812
7940
  }
7813
7941
  function formatCheckReport(report) {
@@ -7845,12 +7973,12 @@ function formatCheckReport(report) {
7845
7973
  const { credential } = report;
7846
7974
  if (credential.provider !== void 0) {
7847
7975
  lines.push(
7848
- ` Provider ${credential.provider.name}: ${credential.provider.credential === void 0 ? `unusable: ${credential.provider.problem ?? ""}` : formatCredentialSummary(credential.provider.credential)}`
7976
+ ` Provider ${credential.provider.name}: ${credential.provider.credential === void 0 ? `unusable: ${credential.provider.problem ?? ""}` : formatCredentialSummary(credential.provider.credential)}${credential.provider.cached === void 0 ? "" : `; ${formatCachedCredentialState(credential.provider.cached)}`}`
7849
7977
  );
7850
7978
  }
7851
7979
  if (credential.identity !== void 0) {
7852
7980
  lines.push(
7853
- ` Identity ${report.identityName ?? "(none)"}: ${formatCredentialSummary(credential.identity)}${credential.applies === "provider" ? " (not used: the provider's credential applies)" : ""}`
7981
+ ` Identity ${report.identityName ?? "(none)"}: ${formatCredentialSummary(credential.identity)}${credential.identityCached === void 0 ? "" : `; ${formatCachedCredentialState(credential.identityCached)}`}${credential.applies === "provider" ? " (not used: the provider's credential applies)" : ""}`
7854
7982
  );
7855
7983
  }
7856
7984
  if (credential.applies === "stored-login") {
@@ -7959,10 +8087,10 @@ function collectCheckReport(params) {
7959
8087
  }).input;
7960
8088
  const providerName = cascadeProviderName(cascade);
7961
8089
  const provider = providerName === void 0 ? void 0 : loadCheckProvider(paths, providerName);
7962
- const farmRoot = identityDecision.name === void 0 ? void 0 : import_node_path22.default.join(paths.identitiesDir, identityDecision.name);
8090
+ const farmRoot = identityDecision.name === void 0 ? void 0 : import_node_path23.default.join(paths.identitiesDir, identityDecision.name);
7963
8091
  const settingsFiles = {
7964
- "settings.json": realFsPort.readFileUtf8(import_node_path22.default.join(claudeHome, "settings.json")),
7965
- "settings.local.json": realFsPort.readFileUtf8(import_node_path22.default.join(claudeHome, "settings.local.json"))
8092
+ "settings.json": realFsPort.readFileUtf8(import_node_path23.default.join(claudeHome, "settings.json")),
8093
+ "settings.local.json": realFsPort.readFileUtf8(import_node_path23.default.join(claudeHome, "settings.local.json"))
7966
8094
  };
7967
8095
  const report = runCheck({
7968
8096
  cwd,
@@ -7983,6 +8111,7 @@ function collectCheckReport(params) {
7983
8111
  ...loadedIdentity === void 0 ? {} : { identity: loadedIdentity.config },
7984
8112
  settingsFiles,
7985
8113
  run: realRunPort,
8114
+ credentialCache: realCredentialCacheEnv(paths),
7986
8115
  ...farmRoot === void 0 ? {} : { farmRoot },
7987
8116
  platform: process.platform,
7988
8117
  ...provider === void 0 ? {} : { provider }
@@ -7991,8 +8120,8 @@ function collectCheckReport(params) {
7991
8120
  }
7992
8121
 
7993
8122
  // src/claudeShim.ts
7994
- var import_node_fs7 = __toESM(require("node:fs"), 1);
7995
- var import_node_path23 = __toESM(require("node:path"), 1);
8123
+ var import_node_fs8 = __toESM(require("node:fs"), 1);
8124
+ var import_node_path24 = __toESM(require("node:path"), 1);
7996
8125
  var import_zod11 = require("zod");
7997
8126
  var ClaudeShimStateSchema = import_zod11.z.strictObject({
7998
8127
  targetPath: import_zod11.z.string().min(1),
@@ -8004,10 +8133,10 @@ function commandFilename(ownExecutablePath, commandName) {
8004
8133
  }
8005
8134
  function resolveOwnBinaryCheck(paths, contentSourcePath) {
8006
8135
  const state = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
8007
- const recordedTarget = state === void 0 ? void 0 : import_node_path23.default.resolve(state.targetPath);
8136
+ const recordedTarget = state === void 0 ? void 0 : import_node_path24.default.resolve(state.targetPath);
8008
8137
  let ownStat;
8009
8138
  return (candidate) => {
8010
- if (recordedTarget !== void 0 && import_node_path23.default.resolve(candidate) === recordedTarget) {
8139
+ if (recordedTarget !== void 0 && import_node_path24.default.resolve(candidate) === recordedTarget) {
8011
8140
  return true;
8012
8141
  }
8013
8142
  ownStat ??= statOrUndefined(contentSourcePath);
@@ -8021,7 +8150,7 @@ function isEnoent4(error) {
8021
8150
  }
8022
8151
  function statOrUndefined(target) {
8023
8152
  try {
8024
- return import_node_fs7.default.statSync(target);
8153
+ return import_node_fs8.default.statSync(target);
8025
8154
  } catch (error) {
8026
8155
  if (isEnoent4(error)) {
8027
8156
  return void 0;
@@ -8029,22 +8158,22 @@ function statOrUndefined(target) {
8029
8158
  throw error;
8030
8159
  }
8031
8160
  }
8032
- var nodeLinkFs = { link: import_node_fs7.default.linkSync, copyFile: import_node_fs7.default.copyFileSync, chmod: import_node_fs7.default.chmodSync };
8161
+ var nodeLinkFs = { link: import_node_fs8.default.linkSync, copyFile: import_node_fs8.default.copyFileSync, chmod: import_node_fs8.default.chmodSync };
8033
8162
  function findPathShadow(params) {
8034
- const resolvedTargetDir = import_node_path23.default.resolve(params.targetDir);
8163
+ const resolvedTargetDir = import_node_path24.default.resolve(params.targetDir);
8035
8164
  for (const dir of params.pathDirs) {
8036
8165
  const found = params.findExecutableInDir(dir, params.targetFilename);
8037
8166
  if (found === void 0) {
8038
8167
  continue;
8039
8168
  }
8040
- return import_node_path23.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
8169
+ return import_node_path24.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
8041
8170
  }
8042
- return params.pathDirs.some((dir) => import_node_path23.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
8171
+ return params.pathDirs.some((dir) => import_node_path24.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
8043
8172
  }
8044
8173
 
8045
8174
  // src/doctorReport.ts
8046
- var import_node_fs8 = __toESM(require("node:fs"), 1);
8047
- var import_node_path24 = __toESM(require("node:path"), 1);
8175
+ var import_node_fs9 = __toESM(require("node:fs"), 1);
8176
+ var import_node_path25 = __toESM(require("node:path"), 1);
8048
8177
  function refinePathShadow(status, ownExecutablePath, realpath) {
8049
8178
  if (status.status !== "shadowed") {
8050
8179
  return status;
@@ -8068,7 +8197,7 @@ function validateJson(schema, input) {
8068
8197
  return { ok: true, data: result.data };
8069
8198
  }
8070
8199
  function pushPathResolution(push, resolution) {
8071
- const ownDir = import_node_path24.default.dirname(resolution.ownExecutablePath);
8200
+ const ownDir = import_node_path25.default.dirname(resolution.ownExecutablePath);
8072
8201
  switch (resolution.agentShim.status) {
8073
8202
  case "ok":
8074
8203
  push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
@@ -8110,7 +8239,14 @@ function pushPathResolution(push, resolution) {
8110
8239
  break;
8111
8240
  }
8112
8241
  }
8113
- function pushProvider(push, entry) {
8242
+ function cacheClause(cacheEnv, owner, block) {
8243
+ if (cacheEnv === void 0 || block.cache === void 0) {
8244
+ return { text: "", unreadable: false };
8245
+ }
8246
+ const state = describeCachedCredential({ port: cacheEnv.port, platform: cacheEnv.platform, owner, cache: block.cache, nowMs: cacheEnv.now() });
8247
+ return { text: `; ${formatCachedCredentialState(state)}`, unreadable: state.status === "unreadable" };
8248
+ }
8249
+ function pushProvider(push, entry, cacheEnv) {
8114
8250
  if (entry.raw === void 0) {
8115
8251
  push("provider", "fail", `${entry.path} is missing.`, entry.name);
8116
8252
  return;
@@ -8132,18 +8268,19 @@ function pushProvider(push, entry) {
8132
8268
  push("provider", "fail", new ConfigValidationError(entry.path, validated.error.issues).message, entry.name);
8133
8269
  return;
8134
8270
  }
8135
- push("provider", "pass", `${entry.name} is valid (${describeProviderEndpoint(validated.data)}, credential ${describeCredential(validated.data.credential)}).`, entry.name);
8271
+ const cache = cacheClause(cacheEnv, `provider ${entry.name}`, validated.data.credential);
8272
+ push("provider", cache.unreadable ? "fail" : "pass", `${entry.name} is valid (${describeProviderEndpoint(validated.data)}, credential ${describeCredential(validated.data.credential)})${cache.text}.`, entry.name);
8136
8273
  }
8137
8274
  function pushLegacyName(push, params) {
8138
8275
  const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
8139
- if (legacyVariables.length === 0 && import_node_path24.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
8276
+ if (legacyVariables.length === 0 && import_node_path25.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
8140
8277
  push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
8141
8278
  return;
8142
8279
  }
8143
8280
  for (const name of legacyVariables) {
8144
8281
  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);
8145
8282
  }
8146
- if (import_node_path24.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
8283
+ if (import_node_path25.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
8147
8284
  push(
8148
8285
  "legacy-name",
8149
8286
  "warn",
@@ -8225,10 +8362,11 @@ function runDoctor(params) {
8225
8362
  );
8226
8363
  } else {
8227
8364
  const credential = validated.data.credential;
8365
+ const cache = credential === void 0 ? { text: "", unreadable: false } : cacheClause(params.credentialCache, `identity ${entry.name}`, credential);
8228
8366
  push(
8229
8367
  "identity",
8230
- "pass",
8231
- `${entry.name} is valid and authenticates with ${credential === void 0 ? "its stored login" : `credential ${describeCredential(credential)}`}.`,
8368
+ cache.unreadable ? "fail" : "pass",
8369
+ `${entry.name} is valid and authenticates with ${credential === void 0 ? "its stored login" : `credential ${describeCredential(credential)}`}${cache.text}.`,
8232
8370
  entry.name
8233
8371
  );
8234
8372
  }
@@ -8248,7 +8386,7 @@ function runDoctor(params) {
8248
8386
  return poolName === void 0 ? validIdentityNames.has(selector) : poolName in pools;
8249
8387
  };
8250
8388
  for (const entry of params.providers) {
8251
- pushProvider(push, entry);
8389
+ pushProvider(push, entry, params.credentialCache);
8252
8390
  }
8253
8391
  if (params.platform !== "darwin" || params.run === void 0) {
8254
8392
  push("keychain", "pass", "Skipped (not macOS).");
@@ -8442,27 +8580,27 @@ function formatDoctorReport(report) {
8442
8580
  }
8443
8581
  function realpathOrSelf(target) {
8444
8582
  try {
8445
- return import_node_fs8.default.realpathSync(target);
8583
+ return import_node_fs9.default.realpathSync(target);
8446
8584
  } catch {
8447
8585
  return target;
8448
8586
  }
8449
8587
  }
8450
8588
  function collectDoctorReport(params) {
8451
8589
  const { paths } = params;
8452
- 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() : [];
8590
+ 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() : [];
8453
8591
  const identities = identityNames.map((name) => {
8454
- const farmRoot = import_node_path24.default.join(paths.identitiesDir, name);
8455
- const identityPath = import_node_path24.default.join(farmRoot, "identity.json");
8592
+ const farmRoot = import_node_path25.default.join(paths.identitiesDir, name);
8593
+ const identityPath = import_node_path25.default.join(farmRoot, "identity.json");
8456
8594
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
8457
8595
  });
8458
- 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() : [];
8596
+ 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() : [];
8459
8597
  const configProfiles = profileNames.map((name) => {
8460
- const profilePath = import_node_path24.default.join(paths.configProfilesDir, `${name}.json`);
8598
+ const profilePath = import_node_path25.default.join(paths.configProfilesDir, `${name}.json`);
8461
8599
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
8462
8600
  });
8463
- 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() : [];
8601
+ 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() : [];
8464
8602
  const providers = providerNames.map((name) => {
8465
- const providerPath = import_node_path24.default.join(paths.providersDir, `${name}.json`);
8603
+ const providerPath = import_node_path25.default.join(paths.providersDir, `${name}.json`);
8466
8604
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
8467
8605
  });
8468
8606
  const ownExecutablePath = realOwnExecutablePath();
@@ -8474,12 +8612,12 @@ function collectDoctorReport(params) {
8474
8612
  binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
8475
8613
  }
8476
8614
  const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
8477
- const pathDirs = (params.env.PATH ?? "").split(import_node_path24.default.delimiter).filter((dir) => dir !== "");
8615
+ const pathDirs = (params.env.PATH ?? "").split(import_node_path25.default.delimiter).filter((dir) => dir !== "");
8478
8616
  const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
8479
8617
  findPathShadow({
8480
8618
  pathDirs,
8481
- targetDir: import_node_path24.default.dirname(shimState.targetPath),
8482
- targetFilename: import_node_path24.default.basename(shimState.targetPath),
8619
+ targetDir: import_node_path25.default.dirname(shimState.targetPath),
8620
+ targetFilename: import_node_path25.default.basename(shimState.targetPath),
8483
8621
  findExecutableInDir
8484
8622
  }),
8485
8623
  shimState.targetPath,
@@ -8487,6 +8625,7 @@ function collectDoctorReport(params) {
8487
8625
  );
8488
8626
  const report = runDoctor({
8489
8627
  env: params.env,
8628
+ credentialCache: realCredentialCacheEnv(paths),
8490
8629
  identities,
8491
8630
  configProfiles,
8492
8631
  providers,
@@ -8495,14 +8634,14 @@ function collectDoctorReport(params) {
8495
8634
  categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
8496
8635
  activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
8497
8636
  binaryDiscovery,
8498
- claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs8.default.existsSync(shimState.targetPath) },
8637
+ claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs9.default.existsSync(shimState.targetPath) },
8499
8638
  rootPath: paths.root,
8500
8639
  pathResolution: {
8501
8640
  ownExecutablePath,
8502
8641
  agentShim: refinePathShadow(
8503
8642
  findPathShadow({
8504
8643
  pathDirs,
8505
- targetDir: import_node_path24.default.dirname(ownExecutablePath),
8644
+ targetDir: import_node_path25.default.dirname(ownExecutablePath),
8506
8645
  targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
8507
8646
  findExecutableInDir
8508
8647
  }),
@@ -8523,7 +8662,7 @@ function collectDoctorReport(params) {
8523
8662
 
8524
8663
  // src/launcher.ts
8525
8664
  var import_node_crypto10 = require("node:crypto");
8526
- var import_node_path26 = __toESM(require("node:path"), 1);
8665
+ var import_node_path27 = __toESM(require("node:path"), 1);
8527
8666
 
8528
8667
  // src/launcher/argv.ts
8529
8668
  var ConflictingIdentityError = class extends UsageError {
@@ -8775,7 +8914,7 @@ function buildCliOverride(params) {
8775
8914
  }
8776
8915
 
8777
8916
  // src/launcher/flags.ts
8778
- var import_node_path25 = __toESM(require("node:path"), 1);
8917
+ var import_node_path26 = __toESM(require("node:path"), 1);
8779
8918
 
8780
8919
  // src/headroom/headers.ts
8781
8920
  function mergeAnthropicCustomHeaders(existing, additions) {
@@ -8845,7 +8984,7 @@ function buildEnv(params) {
8845
8984
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
8846
8985
  let providerCustomHeaders;
8847
8986
  if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
8848
- env.CLAUDE_CONFIG_DIR = import_node_path25.default.join(params.identitiesDir, params.resolvedIdentityName);
8987
+ env.CLAUDE_CONFIG_DIR = import_node_path26.default.join(params.identitiesDir, params.resolvedIdentityName);
8849
8988
  }
8850
8989
  if (params.provider !== void 0) {
8851
8990
  const providerEnv = params.provider.definition.env ?? {};
@@ -9006,7 +9145,7 @@ function prepareLaunch(params) {
9006
9145
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
9007
9146
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
9008
9147
  });
9009
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path26.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
9148
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path27.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
9010
9149
  log.error(
9011
9150
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
9012
9151
  );
@@ -9179,84 +9318,6 @@ function prepareLaunch(params) {
9179
9318
  var import_node_os5 = __toESM(require("node:os"), 1);
9180
9319
  var import_node_crypto12 = require("node:crypto");
9181
9320
 
9182
- // src/realCredentialCache.ts
9183
- var import_node_child_process2 = require("node:child_process");
9184
- var import_node_fs9 = __toESM(require("node:fs"), 1);
9185
- var import_node_path27 = __toESM(require("node:path"), 1);
9186
- var KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
9187
- var CACHE_DIR_MODE = 448;
9188
- var CACHE_FILE_MODE = 384;
9189
- function cacheFileNameFor(owner) {
9190
- return `${owner.replace(/[^A-Za-z0-9._-]/g, "_")}.json`;
9191
- }
9192
- function parseEntry(raw) {
9193
- let json;
9194
- try {
9195
- json = JSON.parse(raw);
9196
- } catch {
9197
- return void 0;
9198
- }
9199
- const parsed = CachedCredentialSchema.safeParse(json);
9200
- return parsed.success ? parsed.data : void 0;
9201
- }
9202
- function requireKeychain() {
9203
- if (process.platform !== "darwin") {
9204
- throw new Error("the keychain credential store needs macOS; use --credential-cache-store file");
9205
- }
9206
- }
9207
- function security(args, stdin) {
9208
- const result = (0, import_node_child_process2.spawnSync)("security", args, { encoding: "utf8", ...stdin === void 0 ? {} : { input: stdin }, stdio: ["pipe", "pipe", "ignore"] });
9209
- return { status: result.status, stdout: result.stdout };
9210
- }
9211
- function createRealCredentialCache(root) {
9212
- const dir = import_node_path27.default.join(root, "credential-cache");
9213
- const filePath = (owner) => import_node_path27.default.join(dir, cacheFileNameFor(owner));
9214
- return {
9215
- read(store, owner) {
9216
- if (store === "file") {
9217
- try {
9218
- return parseEntry(import_node_fs9.default.readFileSync(filePath(owner), "utf8"));
9219
- } catch {
9220
- return void 0;
9221
- }
9222
- }
9223
- requireKeychain();
9224
- const result = security(["find-generic-password", "-s", KEYCHAIN_CACHE_SERVICE, "-a", owner, "-w"]);
9225
- return result.status === 0 ? parseEntry(Buffer.from(result.stdout.trim(), "base64").toString("utf8")) : void 0;
9226
- },
9227
- write(store, owner, entry) {
9228
- const serialised = JSON.stringify(entry);
9229
- if (store === "file") {
9230
- import_node_fs9.default.mkdirSync(dir, { recursive: true, mode: CACHE_DIR_MODE });
9231
- import_node_fs9.default.chmodSync(dir, CACHE_DIR_MODE);
9232
- const target = filePath(owner);
9233
- const temp = `${target}.${String(process.pid)}.tmp`;
9234
- import_node_fs9.default.writeFileSync(temp, serialised, { mode: CACHE_FILE_MODE });
9235
- import_node_fs9.default.renameSync(temp, target);
9236
- return;
9237
- }
9238
- requireKeychain();
9239
- const encoded = Buffer.from(serialised, "utf8").toString("base64");
9240
- const result = security(["-i"], `add-generic-password -U -s ${KEYCHAIN_CACHE_SERVICE} -a ${JSON.stringify(owner)} -w ${encoded}
9241
- `);
9242
- if (result.status !== 0) {
9243
- throw new Error(`could not write the keychain credential cache for ${owner}`);
9244
- }
9245
- },
9246
- remove(store, owner) {
9247
- if (store === "file") {
9248
- import_node_fs9.default.rmSync(filePath(owner), { force: true });
9249
- return;
9250
- }
9251
- requireKeychain();
9252
- security(["delete-generic-password", "-s", KEYCHAIN_CACHE_SERVICE, "-a", owner]);
9253
- }
9254
- };
9255
- }
9256
- function realCredentialCacheEnv(paths) {
9257
- return { port: createRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
9258
- }
9259
-
9260
9321
  // src/frontdoor/realFrontDoorPort.ts
9261
9322
  var import_node_fs10 = __toESM(require("node:fs"), 1);
9262
9323