claude-use 12.0.0 → 12.0.1

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
@@ -6689,9 +6689,224 @@ var init_blockingSpawn = __esm({
6689
6689
  }
6690
6690
  });
6691
6691
 
6692
+ // src/headroom/headers.ts
6693
+ function mergeAnthropicCustomHeaders(existing, additions) {
6694
+ const merged = /* @__PURE__ */ new Map();
6695
+ for (const block of existing) {
6696
+ if (block === void 0) {
6697
+ continue;
6698
+ }
6699
+ for (const line of block.split("\n")) {
6700
+ const entry = parseCustomHeaderLine(line);
6701
+ if (entry === void 0) {
6702
+ continue;
6703
+ }
6704
+ merged.set(entry.name, entry.value);
6705
+ }
6706
+ }
6707
+ for (const entry of additions) {
6708
+ merged.set(entry.name, entry.value);
6709
+ }
6710
+ return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
6711
+ }
6712
+ function parseAnthropicCustomHeaders(block) {
6713
+ return block.split("\n").flatMap((line) => {
6714
+ const entry = parseCustomHeaderLine(line);
6715
+ return entry === void 0 ? [] : [entry];
6716
+ });
6717
+ }
6718
+ function withoutAnthropicCustomHeaders(block, remove) {
6719
+ const lines = block.split("\n");
6720
+ const kept = lines.filter((line) => {
6721
+ const entry = parseCustomHeaderLine(line);
6722
+ return entry === void 0 || !remove(entry);
6723
+ });
6724
+ return kept.length === lines.length ? block : kept.join("\n");
6725
+ }
6726
+ function parseCustomHeaderLine(line) {
6727
+ const trimmed = line.trim();
6728
+ if (trimmed === "") {
6729
+ return void 0;
6730
+ }
6731
+ const colon = trimmed.indexOf(":");
6732
+ if (colon <= 0) {
6733
+ return void 0;
6734
+ }
6735
+ return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
6736
+ }
6737
+ var init_headers = __esm({
6738
+ "src/headroom/headers.ts"() {
6739
+ "use strict";
6740
+ }
6741
+ });
6742
+
6743
+ // src/launcher/injected.ts
6744
+ function listKey(list) {
6745
+ return `${list},appended`;
6746
+ }
6747
+ function digest2(value) {
6748
+ return (0, import_node_crypto7.createHash)("sha256").update(value).digest("hex");
6749
+ }
6750
+ function recordedDigests(env) {
6751
+ const raw = env[INJECTED_ENV];
6752
+ if (raw === void 0 || raw === "") {
6753
+ return {};
6754
+ }
6755
+ let parsed;
6756
+ try {
6757
+ parsed = JSON.parse(raw);
6758
+ } catch {
6759
+ return {};
6760
+ }
6761
+ const result = InjectedSchema.safeParse(parsed);
6762
+ return result.success ? result.data : {};
6763
+ }
6764
+ function recordInjections(base) {
6765
+ const env = { ...base };
6766
+ const digests = new Map(Object.entries(recordedDigests(env)));
6767
+ return {
6768
+ env,
6769
+ set: (name, value) => {
6770
+ env[name] = value;
6771
+ digests.set(name, digest2(value));
6772
+ },
6773
+ unset: (name) => {
6774
+ env[name] = void 0;
6775
+ digests.delete(name);
6776
+ },
6777
+ recordHeaders: (names) => {
6778
+ const block = env[CUSTOM_HEADERS_ENV];
6779
+ for (const entry of block === void 0 ? [] : parseAnthropicCustomHeaders(block)) {
6780
+ if (names.includes(entry.name)) {
6781
+ digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
6782
+ }
6783
+ }
6784
+ },
6785
+ recordBypassHosts: (list, hosts) => {
6786
+ const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
6787
+ if (recordedHosts.length > 0) {
6788
+ digests.set(listKey(list), recordedHosts.join(","));
6789
+ }
6790
+ },
6791
+ finish: () => {
6792
+ if (digests.size > 0) {
6793
+ env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
6794
+ }
6795
+ }
6796
+ };
6797
+ }
6798
+ function withoutRecordedHosts(list, value, digests) {
6799
+ const recordedHosts = new Set(digests[listKey(list)]?.split(","));
6800
+ const entries = value.split(",");
6801
+ const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
6802
+ return kept.length === entries.length ? value : kept.join(",");
6803
+ }
6804
+ function launchEnvironment(env, configDirEscapeHatch) {
6805
+ return configDirEscapeHatch ? env : withoutInjected(env);
6806
+ }
6807
+ function withoutInjected(env) {
6808
+ const digests = recordedDigests(env);
6809
+ const entries = Object.entries(env).flatMap(([name, value]) => {
6810
+ if (name === INJECTED_ENV) {
6811
+ return [];
6812
+ }
6813
+ if (value === void 0) {
6814
+ return [[name, value]];
6815
+ }
6816
+ if (name === CUSTOM_HEADERS_ENV) {
6817
+ const remaining = withoutAnthropicCustomHeaders(value, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
6818
+ return remaining !== value && remaining.trim() === "" ? [] : [[name, remaining]];
6819
+ }
6820
+ if (name === "NO_PROXY" || name === "no_proxy") {
6821
+ const remaining = withoutRecordedHosts(name, value, digests);
6822
+ return remaining !== value && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
6823
+ }
6824
+ return digests[name] === digest2(value) ? [] : [[name, value]];
6825
+ });
6826
+ return Object.fromEntries(entries);
6827
+ }
6828
+ var import_node_crypto7, import_zod14, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
6829
+ var init_injected = __esm({
6830
+ "src/launcher/injected.ts"() {
6831
+ "use strict";
6832
+ import_node_crypto7 = require("node:crypto");
6833
+ import_zod14 = require("zod");
6834
+ init_headers();
6835
+ INJECTED_ENV = "AGENT_SHIM_INJECTED";
6836
+ CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
6837
+ HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
6838
+ InjectedSchema = import_zod14.z.record(import_zod14.z.string(), import_zod14.z.string());
6839
+ }
6840
+ });
6841
+
6842
+ // src/launcher/guard.ts
6843
+ function detectAmbientCredential(env, injected) {
6844
+ for (const variable of AMBIENT_CREDENTIAL_VARS) {
6845
+ const value = env[variable];
6846
+ if (value === void 0 || value === "") {
6847
+ continue;
6848
+ }
6849
+ if (injected?.variable === variable && value === injected.token) {
6850
+ continue;
6851
+ }
6852
+ return { variable };
6853
+ }
6854
+ return void 0;
6855
+ }
6856
+ function formatAmbientCredentialGuardMessage(variable, identityName) {
6857
+ const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
6858
+ return [
6859
+ `error: ${variable} is set in the environment. This identity's isolated`,
6860
+ "credential would be bypassed \u2014 every identity authenticates as this same key",
6861
+ "while it's set. Unset it, or if this is deliberate, opt in per-launch with",
6862
+ "AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
6863
+ `\`${identitySetCommand}\`.`
6864
+ ].join("\n");
6865
+ }
6866
+ function evaluateAmbientCredentialGuard(params) {
6867
+ const detected = detectAmbientCredential(params.env, params.injectedCredential);
6868
+ if (detected === void 0) {
6869
+ return { ok: true };
6870
+ }
6871
+ if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
6872
+ return { ok: true };
6873
+ }
6874
+ return {
6875
+ ok: false,
6876
+ variable: detected.variable,
6877
+ message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
6878
+ };
6879
+ }
6880
+ function ambientCredentialFinding(env) {
6881
+ const named = detectAmbientCredential(launchEnvironment(env, false));
6882
+ if (named !== void 0) {
6883
+ return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
6884
+ }
6885
+ const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
6886
+ if (bare !== void 0) {
6887
+ return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
6888
+ }
6889
+ return { severity: "pass", message: "No ambient-credential environment variable is set." };
6890
+ }
6891
+ var AMBIENT_CREDENTIAL_VARS;
6892
+ var init_guard = __esm({
6893
+ "src/launcher/guard.ts"() {
6894
+ "use strict";
6895
+ init_injected();
6896
+ AMBIENT_CREDENTIAL_VARS = [
6897
+ "ANTHROPIC_API_KEY",
6898
+ "ANTHROPIC_AUTH_TOKEN",
6899
+ "CLAUDE_CODE_OAUTH_TOKEN",
6900
+ "CLAUDE_CODE_USE_BEDROCK",
6901
+ "CLAUDE_CODE_USE_VERTEX",
6902
+ "CLAUDE_CODE_USE_FOUNDRY"
6903
+ ];
6904
+ }
6905
+ });
6906
+
6692
6907
  // src/usage/signIn.ts
6693
6908
  function claudeCodeKeychainService(configDir) {
6694
- return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto7.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
6909
+ return `${KEYCHAIN_SERVICE_PREFIX}-${(0, import_node_crypto8.createHash)("sha256").update(configDir).digest("hex").slice(0, KEYCHAIN_SERVICE_HASH_DIGITS)}`;
6695
6910
  }
6696
6911
  function keychainHasItem(run, configDir) {
6697
6912
  return run.run("security", ["find-generic-password", "-s", claudeCodeKeychainService(configDir)]).status === 0;
@@ -6724,15 +6939,35 @@ function identitySignIn(fs17, probe, identity) {
6724
6939
  platform: probe.platform
6725
6940
  });
6726
6941
  }
6727
- var import_node_crypto7, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS;
6942
+ function storedLoginUsable(run, claudeBin, configDir, env) {
6943
+ const childEnv = { ...env, CLAUDE_CONFIG_DIR: configDir };
6944
+ for (const variable of AMBIENT_CREDENTIAL_VARS) {
6945
+ childEnv[variable] = void 0;
6946
+ }
6947
+ const result = run.run(claudeBin, ["auth", "status"], void 0, { env: childEnv, timeoutMs: AUTH_STATUS_TIMEOUT_MS });
6948
+ if (result.status === null) {
6949
+ return void 0;
6950
+ }
6951
+ try {
6952
+ const status = JSON.parse(result.stdout);
6953
+ if (typeof status === "object" && status !== null && "loggedIn" in status && typeof status.loggedIn === "boolean") {
6954
+ return status.loggedIn;
6955
+ }
6956
+ } catch {
6957
+ }
6958
+ return void 0;
6959
+ }
6960
+ var import_node_crypto8, import_node_path19, CREDENTIALS_FILE, KEYCHAIN_SERVICE_PREFIX, KEYCHAIN_SERVICE_HASH_DIGITS, AUTH_STATUS_TIMEOUT_MS;
6728
6961
  var init_signIn = __esm({
6729
6962
  "src/usage/signIn.ts"() {
6730
6963
  "use strict";
6731
- import_node_crypto7 = require("node:crypto");
6964
+ import_node_crypto8 = require("node:crypto");
6732
6965
  import_node_path19 = __toESM(require("node:path"), 1);
6966
+ init_guard();
6733
6967
  CREDENTIALS_FILE = ".credentials.json";
6734
6968
  KEYCHAIN_SERVICE_PREFIX = "Claude Code-credentials";
6735
6969
  KEYCHAIN_SERVICE_HASH_DIGITS = 8;
6970
+ AUTH_STATUS_TIMEOUT_MS = 1e4;
6736
6971
  }
6737
6972
  });
6738
6973
 
@@ -6863,7 +7098,7 @@ function serialisedFor(entry, owner) {
6863
7098
  return JSON.stringify({ owner, ...withoutOwner(entry) });
6864
7099
  }
6865
7100
  function tempPathFor(target) {
6866
- return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto8.randomUUID)()}`);
7101
+ return import_node_path20.default.join(import_node_path20.default.dirname(target), `${TEMP_PREFIX}${String(process.pid)}-${(0, import_node_crypto9.randomUUID)()}`);
6867
7102
  }
6868
7103
  function processRuns(pid) {
6869
7104
  try {
@@ -6982,11 +7217,11 @@ function createRealCredentialCache(root, keychain = { run: security, platform: p
6982
7217
  function realCredentialCacheEnv(paths) {
6983
7218
  return { port: createRealCredentialCache(paths.root), platform: process.platform, now: () => Date.now() };
6984
7219
  }
6985
- var import_node_crypto8, import_node_fs5, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
7220
+ var import_node_crypto9, import_node_fs5, import_node_path20, CACHE_DIR_MODE, CACHE_FILE_MODE, TEMP_PREFIX, TEMP_NAME, RELEASED_TEMP_NAME;
6986
7221
  var init_realCredentialCache = __esm({
6987
7222
  "src/realCredentialCache.ts"() {
6988
7223
  "use strict";
6989
- import_node_crypto8 = require("node:crypto");
7224
+ import_node_crypto9 = require("node:crypto");
6990
7225
  import_node_fs5 = __toESM(require("node:fs"), 1);
6991
7226
  import_node_path20 = __toESM(require("node:path"), 1);
6992
7227
  init_blockingSpawn();
@@ -7143,7 +7378,7 @@ function migrateHeadroomState(fs17, files, isRunning) {
7143
7378
  fs17.removeRecursive(files.legacyStateFile);
7144
7379
  }
7145
7380
  function hashAllowlist(allowlist) {
7146
- return (0, import_node_crypto9.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
7381
+ return (0, import_node_crypto10.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
7147
7382
  }
7148
7383
  function formatAllowlistFile(allowlist) {
7149
7384
  return allowlist.map((entry) => `${entry}
@@ -7248,40 +7483,40 @@ function readStartLock(fs17, lockFile) {
7248
7483
  return void 0;
7249
7484
  }
7250
7485
  }
7251
- var import_node_crypto9, import_node_path21, import_zod14, HeadroomStateSchema, HeadroomSessionSchema, HeadroomLockSchema, HEADROOM_ALLOWLIST_FILE_FLAG, ALLOWLIST_LINE_BREAKS, ALLOWLIST_WHITESPACE, ALLOWLIST_FILE_SEPARATORS, ALLOWLIST_FILE_COMMENT, ALLOWLIST_ENTRY_WHITESPACE, ALLOWLIST_SURROUNDING_WHITESPACE, ALLOWLIST_SAFE_SCHEMES;
7486
+ var import_node_crypto10, import_node_path21, import_zod15, HeadroomStateSchema, HeadroomSessionSchema, HeadroomLockSchema, HEADROOM_ALLOWLIST_FILE_FLAG, ALLOWLIST_LINE_BREAKS, ALLOWLIST_WHITESPACE, ALLOWLIST_FILE_SEPARATORS, ALLOWLIST_FILE_COMMENT, ALLOWLIST_ENTRY_WHITESPACE, ALLOWLIST_SURROUNDING_WHITESPACE, ALLOWLIST_SAFE_SCHEMES;
7252
7487
  var init_state2 = __esm({
7253
7488
  "src/headroom/state.ts"() {
7254
7489
  "use strict";
7255
- import_node_crypto9 = require("node:crypto");
7490
+ import_node_crypto10 = require("node:crypto");
7256
7491
  import_node_path21 = __toESM(require("node:path"), 1);
7257
- import_zod14 = require("zod");
7492
+ import_zod15 = require("zod");
7258
7493
  init_schema();
7259
- HeadroomStateSchema = import_zod14.z.strictObject({
7494
+ HeadroomStateSchema = import_zod15.z.strictObject({
7260
7495
  /** The supervisor process owning the daemon. Alive means someone is keeping headroom running. */
7261
- supervisorPid: import_zod14.z.number().int().positive().optional(),
7496
+ supervisorPid: import_zod15.z.number().int().positive().optional(),
7262
7497
  /** The headroom proxy process itself, recorded as soon as it is spawned (before it is ready, which `socketPath` signals) so a successor can find a daemon whose supervisor died during its start. Absent while the supervisor is between restarts. */
7263
- headroomPid: import_zod14.z.number().int().positive().optional(),
7498
+ headroomPid: import_zod15.z.number().int().positive().optional(),
7264
7499
  /**
7265
7500
  * The unix socket the proxy serves on, inside the owner-only socket directory. Absent until the proxy has passed its readiness check, so "socketPath is set" is itself the ready signal a launcher polls for. The front door reads it on every hop, so a restart (which keeps the generation's path) is followed without anything being relaunched.
7266
7501
  */
7267
- socketPath: import_zod14.z.string().min(1).optional(),
7502
+ socketPath: import_zod15.z.string().min(1).optional(),
7268
7503
  /** The `headroom --version` output of the running install. */
7269
- version: import_zod14.z.string().optional(),
7504
+ version: import_zod15.z.string().optional(),
7270
7505
  /**
7271
7506
  * Hash of the allowlist the running proxy serves. The supervisor records it in the same tick it writes that allowlist to `LayoutPaths.headroomAllowlistFile`, which the proxy re-reads on its next request, so a provider launch, whose requests come back through its front door's direct origin, waits until this names an allowlist holding that origin. A supervisor from an earlier release records here the hash of the allowlist its daemon was started with instead (see `earlierRelease.ts`).
7272
7507
  */
7273
- allowlistHash: import_zod14.z.string().optional(),
7508
+ allowlistHash: import_zod15.z.string().optional(),
7274
7509
  /** Hash of the token-saving settings the running proxy was started with, so a settings change is detected as drift. */
7275
- settingsHash: import_zod14.z.string().optional(),
7510
+ settingsHash: import_zod15.z.string().optional(),
7276
7511
  /** The install spec the running install was last installed from, so a `source` config change is detected as drift. */
7277
- installedSource: import_zod14.z.string().optional(),
7512
+ installedSource: import_zod15.z.string().optional(),
7278
7513
  /** The install spec the supervisor is installing right now, present only while `uv tool install` runs, so a launcher that finds a live supervisor with no daemon yet keeps waiting for the install instead of counting it against its start bound. Cleared by the write that follows the install, whatever its outcome. */
7279
- installing: import_zod14.z.string().optional(),
7514
+ installing: import_zod15.z.string().optional(),
7280
7515
  /** The last fatal error, kept across shutdowns so `headroom status` can explain a daemon that is not running. */
7281
- lastError: import_zod14.z.string().optional()
7516
+ lastError: import_zod15.z.string().optional()
7282
7517
  });
7283
- HeadroomSessionSchema = import_zod14.z.strictObject({ pid: import_zod14.z.number().int().positive(), startedAt: import_zod14.z.number(), supervisorPid: import_zod14.z.number().int().positive() });
7284
- HeadroomLockSchema = import_zod14.z.strictObject({ pid: import_zod14.z.number().int().positive(), at: import_zod14.z.number() });
7518
+ HeadroomSessionSchema = import_zod15.z.strictObject({ pid: import_zod15.z.number().int().positive(), startedAt: import_zod15.z.number(), supervisorPid: import_zod15.z.number().int().positive() });
7519
+ HeadroomLockSchema = import_zod15.z.strictObject({ pid: import_zod15.z.number().int().positive(), at: import_zod15.z.number() });
7285
7520
  HEADROOM_ALLOWLIST_FILE_FLAG = "--allowed-base-urls-file";
7286
7521
  ALLOWLIST_LINE_BREAKS = "\\n\\r\\u000b\\u000c\\u001c\\u001d\\u001e\\u0085\\u2028\\u2029";
7287
7522
  ALLOWLIST_WHITESPACE = "\\t\\n\\u000b\\u000c\\r\\u001c-\\u001f \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
@@ -7495,13 +7730,13 @@ function settingsEnv(settings) {
7495
7730
  return settings.rolloutChannel === void 0 ? {} : { HEADROOM_ROLLOUT_CHANNEL: settings.rolloutChannel };
7496
7731
  }
7497
7732
  function hashSettings(settings) {
7498
- return (0, import_node_crypto10.createHash)("sha256").update(JSON.stringify([...settingsArgs(settings), JSON.stringify(settingsEnv(settings))])).digest("hex");
7733
+ return (0, import_node_crypto11.createHash)("sha256").update(JSON.stringify([...settingsArgs(settings), JSON.stringify(settingsEnv(settings))])).digest("hex");
7499
7734
  }
7500
- var import_node_crypto10;
7735
+ var import_node_crypto11;
7501
7736
  var init_settings = __esm({
7502
7737
  "src/headroom/settings.ts"() {
7503
7738
  "use strict";
7504
- import_node_crypto10 = require("node:crypto");
7739
+ import_node_crypto11 = require("node:crypto");
7505
7740
  }
7506
7741
  });
7507
7742
 
@@ -7701,14 +7936,14 @@ function pinnedGitCommit(spec) {
7701
7936
  const ref = GIT_SPEC_RE.exec(spec)?.[1];
7702
7937
  return ref !== void 0 && COMMIT_SHA_RE.test(ref) ? ref.toLowerCase() : void 0;
7703
7938
  }
7704
- var import_zod15, GIT_SPEC_RE, COMMIT_SHA_RE, DirectUrlSchema;
7939
+ var import_zod16, GIT_SPEC_RE, COMMIT_SHA_RE, DirectUrlSchema;
7705
7940
  var init_source = __esm({
7706
7941
  "src/headroom/source.ts"() {
7707
7942
  "use strict";
7708
- import_zod15 = require("zod");
7943
+ import_zod16 = require("zod");
7709
7944
  GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
7710
7945
  COMMIT_SHA_RE = /^[0-9a-f]{40}$/i;
7711
- DirectUrlSchema = import_zod15.z.object({ vcs_info: import_zod15.z.object({ commit_id: import_zod15.z.string() }) });
7946
+ DirectUrlSchema = import_zod16.z.object({ vcs_info: import_zod16.z.object({ commit_id: import_zod16.z.string() }) });
7712
7947
  }
7713
7948
  });
7714
7949
 
@@ -8214,6 +8449,9 @@ function realFrontDoorLiveness(pids) {
8214
8449
  return { status: result.status, stdout: result.stdout, stderr: result.stderr, ...result.error === void 0 ? {} : { error: result.error } };
8215
8450
  });
8216
8451
  }
8452
+ function definedEntries(env) {
8453
+ return Object.fromEntries(Object.entries(env).filter((entry) => entry[1] !== void 0));
8454
+ }
8217
8455
  function realRunAsyncWithin(timeoutMs) {
8218
8456
  return async (command, args) => await new Promise((resolve) => {
8219
8457
  (0, import_node_child_process2.execFile)(command, [...args], { encoding: "utf8", timeout: timeoutMs }, (error, stdout, stderr) => {
@@ -8422,14 +8660,14 @@ function realResolveClaudeBinary(isOwnBinary) {
8422
8660
  function realInstalledClaudeVersions() {
8423
8661
  return installedVersions(listVersionsDir(defaultVersionsDir()));
8424
8662
  }
8425
- var import_node_child_process2, import_node_crypto11, import_node_fs6, import_node_os2, import_node_path24, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS2, DIRECTORY_FLUSH_UNSUPPORTED_CODES, realFarmFs, INT32_BYTE_LENGTH, KEY_POLL_MS, CTRL_C_BYTE, realHoldPort, PS_TIMEOUT_MS, RUN_OUTPUT_LIMIT_MIB, BYTES_PER_MIB2, RUN_OUTPUT_LIMIT_BYTES, realRunPort, ASYNC_RUN_TIMEOUT_MS, realRunAsync, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
8663
+ var import_node_child_process2, import_node_crypto12, import_node_fs6, import_node_os2, import_node_path24, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS2, DIRECTORY_FLUSH_UNSUPPORTED_CODES, realFarmFs, INT32_BYTE_LENGTH, KEY_POLL_MS, CTRL_C_BYTE, realHoldPort, PS_TIMEOUT_MS, RUN_OUTPUT_LIMIT_MIB, BYTES_PER_MIB2, RUN_OUTPUT_LIMIT_BYTES, realRunPort, ASYNC_RUN_TIMEOUT_MS, realRunAsync, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
8426
8664
  var init_realPorts = __esm({
8427
8665
  "src/realPorts.ts"() {
8428
8666
  "use strict";
8429
8667
  init_blockingSpawn();
8430
8668
  init_processRole();
8431
8669
  import_node_child_process2 = require("node:child_process");
8432
- import_node_crypto11 = require("node:crypto");
8670
+ import_node_crypto12 = require("node:crypto");
8433
8671
  import_node_fs6 = __toESM(require("node:fs"), 1);
8434
8672
  import_node_os2 = __toESM(require("node:os"), 1);
8435
8673
  import_node_path24 = __toESM(require("node:path"), 1);
@@ -8580,7 +8818,7 @@ var init_realPorts = __esm({
8580
8818
  },
8581
8819
  hashFile(filePath) {
8582
8820
  try {
8583
- return (0, import_node_crypto11.createHash)("sha256").update(import_node_fs6.default.readFileSync(filePath)).digest("hex");
8821
+ return (0, import_node_crypto12.createHash)("sha256").update(import_node_fs6.default.readFileSync(filePath)).digest("hex");
8584
8822
  } catch (error) {
8585
8823
  if (isEnoent3(error) || isErrorWithCode(error, "EISDIR")) {
8586
8824
  return void 0;
@@ -8620,8 +8858,14 @@ var init_realPorts = __esm({
8620
8858
  BYTES_PER_MIB2 = 1048576;
8621
8859
  RUN_OUTPUT_LIMIT_BYTES = RUN_OUTPUT_LIMIT_MIB * BYTES_PER_MIB2;
8622
8860
  realRunPort = {
8623
- run(command, args, input) {
8624
- const result = spawnSyncBlocking("an external command", command, args, { encoding: "utf8", maxBuffer: RUN_OUTPUT_LIMIT_BYTES, ...input === void 0 ? {} : { input } });
8861
+ run(command, args, input, options) {
8862
+ const result = spawnSyncBlocking("an external command", command, args, {
8863
+ encoding: "utf8",
8864
+ maxBuffer: RUN_OUTPUT_LIMIT_BYTES,
8865
+ ...input === void 0 ? {} : { input },
8866
+ ...options?.env === void 0 ? {} : { env: definedEntries(options.env) },
8867
+ ...options?.timeoutMs === void 0 ? {} : { timeout: options.timeoutMs }
8868
+ });
8625
8869
  return { status: result.status, stdout: result.stdout, stderr: result.stderr };
8626
8870
  }
8627
8871
  };
@@ -9041,24 +9285,24 @@ function planOf(account) {
9041
9285
  }
9042
9286
  return { kind: "subscription", capacity: 1, recognised: BASE_TIER.test(tier), ...tierField };
9043
9287
  }
9044
- var import_zod16, PlanClassSchema, TIER_MULTIPLIER, ZERO_TIER, BASE_TIER;
9288
+ var import_zod17, PlanClassSchema, TIER_MULTIPLIER, ZERO_TIER, BASE_TIER;
9045
9289
  var init_plan2 = __esm({
9046
9290
  "src/usage/plan.ts"() {
9047
9291
  "use strict";
9048
- import_zod16 = require("zod");
9049
- PlanClassSchema = import_zod16.z.union([
9050
- import_zod16.z.strictObject({
9051
- kind: import_zod16.z.literal("subscription"),
9292
+ import_zod17 = require("zod");
9293
+ PlanClassSchema = import_zod17.z.union([
9294
+ import_zod17.z.strictObject({
9295
+ kind: import_zod17.z.literal("subscription"),
9052
9296
  /** The plan's size as a multiple of the smallest subscription tier (Max is 5, Ultra is 20). */
9053
- capacity: import_zod16.z.number().positive(),
9297
+ capacity: import_zod17.z.number().positive(),
9054
9298
  /** False when the tier string named no multiplier and no tier this project knows, so `capacity` is the neutral 1 rather than a reading. */
9055
- recognised: import_zod16.z.boolean(),
9299
+ recognised: import_zod17.z.boolean(),
9056
9300
  /** The tier string the classification rests on, when the account had one. */
9057
- tier: import_zod16.z.string().optional()
9301
+ tier: import_zod17.z.string().optional()
9058
9302
  }),
9059
- import_zod16.z.strictObject({
9060
- kind: import_zod16.z.literal("pay-per-use"),
9061
- tier: import_zod16.z.string().optional()
9303
+ import_zod17.z.strictObject({
9304
+ kind: import_zod17.z.literal("pay-per-use"),
9305
+ tier: import_zod17.z.string().optional()
9062
9306
  })
9063
9307
  ]);
9064
9308
  TIER_MULTIPLIER = /(?:^|_)(\d+)x$/;
@@ -9068,21 +9312,21 @@ var init_plan2 = __esm({
9068
9312
  });
9069
9313
 
9070
9314
  // src/usage/scan.ts
9071
- var import_zod17, AnthropicUsageSchema, ErrorObjectSchema;
9315
+ var import_zod18, AnthropicUsageSchema, ErrorObjectSchema;
9072
9316
  var init_scan = __esm({
9073
9317
  "src/usage/scan.ts"() {
9074
9318
  "use strict";
9075
- import_zod17 = require("zod");
9076
- AnthropicUsageSchema = import_zod17.z.looseObject({
9077
- input_tokens: import_zod17.z.number().int().nonnegative().nullish(),
9078
- output_tokens: import_zod17.z.number().int().nonnegative().nullish(),
9079
- cache_creation_input_tokens: import_zod17.z.number().int().nonnegative().nullish(),
9080
- cache_read_input_tokens: import_zod17.z.number().int().nonnegative().nullish()
9319
+ import_zod18 = require("zod");
9320
+ AnthropicUsageSchema = import_zod18.z.looseObject({
9321
+ input_tokens: import_zod18.z.number().int().nonnegative().nullish(),
9322
+ output_tokens: import_zod18.z.number().int().nonnegative().nullish(),
9323
+ cache_creation_input_tokens: import_zod18.z.number().int().nonnegative().nullish(),
9324
+ cache_read_input_tokens: import_zod18.z.number().int().nonnegative().nullish()
9081
9325
  });
9082
- ErrorObjectSchema = import_zod17.z.looseObject({
9083
- type: import_zod17.z.string().optional(),
9084
- code: import_zod17.z.union([import_zod17.z.string(), import_zod17.z.number()]).optional(),
9085
- message: import_zod17.z.string().optional()
9326
+ ErrorObjectSchema = import_zod18.z.looseObject({
9327
+ type: import_zod18.z.string().optional(),
9328
+ code: import_zod18.z.union([import_zod18.z.string(), import_zod18.z.number()]).optional(),
9329
+ message: import_zod18.z.string().optional()
9086
9330
  });
9087
9331
  }
9088
9332
  });
@@ -9732,12 +9976,12 @@ function recordStickyPick(fs17, picksFile, directory, identity, nowMs) {
9732
9976
  fs17.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
9733
9977
  `);
9734
9978
  }
9735
- var import_node_path26, import_zod18, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
9979
+ var import_node_path26, import_zod19, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
9736
9980
  var init_poolPick = __esm({
9737
9981
  "src/usage/poolPick.ts"() {
9738
9982
  "use strict";
9739
9983
  import_node_path26 = __toESM(require("node:path"), 1);
9740
- import_zod18 = require("zod");
9984
+ import_zod19 = require("zod");
9741
9985
  init_cliError();
9742
9986
  init_identity();
9743
9987
  init_schema();
@@ -9754,17 +9998,17 @@ var init_poolPick = __esm({
9754
9998
  }
9755
9999
  };
9756
10000
  SCHEMA_VERSION = 1;
9757
- PickEntrySchema = import_zod18.z.strictObject({ identity: import_zod18.z.string().min(1), at: import_zod18.z.iso.datetime() });
9758
- PicksFileSchema = import_zod18.z.strictObject({
9759
- schemaVersion: import_zod18.z.literal(SCHEMA_VERSION),
9760
- picks: import_zod18.z.record(import_zod18.z.string().min(1), PickEntrySchema)
10001
+ PickEntrySchema = import_zod19.z.strictObject({ identity: import_zod19.z.string().min(1), at: import_zod19.z.iso.datetime() });
10002
+ PicksFileSchema = import_zod19.z.strictObject({
10003
+ schemaVersion: import_zod19.z.literal(SCHEMA_VERSION),
10004
+ picks: import_zod19.z.record(import_zod19.z.string().min(1), PickEntrySchema)
9761
10005
  });
9762
10006
  }
9763
10007
  });
9764
10008
 
9765
10009
  // src/identityRenameJournal.ts
9766
10010
  function renamePairFileName(from, to, suffix) {
9767
- return `${(0, import_node_crypto12.createHash)("sha256").update(`${from}\0${to}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
10011
+ return `${(0, import_node_crypto13.createHash)("sha256").update(`${from}\0${to}`).digest("hex").slice(0, FILE_NAME_HASH_DIGITS)}${suffix}`;
9768
10012
  }
9769
10013
  function readRenameJournal(fs17, file) {
9770
10014
  const raw = fs17.readFileUtf8(file);
@@ -9835,28 +10079,28 @@ function requireNameFreeOfUnfinishedRename(fs17, directory, name, action, sameNa
9835
10079
  throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
9836
10080
  }
9837
10081
  }
9838
- var import_node_crypto12, import_node_path27, import_zod19, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
10082
+ var import_node_crypto13, import_node_path27, import_zod20, RenameJournalSchema, FILE_NAME_HASH_DIGITS, JOURNAL_SUFFIX, RenameJournalUnreadableError, NameHeldByUnfinishedRenameError;
9839
10083
  var init_identityRenameJournal = __esm({
9840
10084
  "src/identityRenameJournal.ts"() {
9841
10085
  "use strict";
9842
- import_node_crypto12 = require("node:crypto");
10086
+ import_node_crypto13 = require("node:crypto");
9843
10087
  import_node_path27 = __toESM(require("node:path"), 1);
9844
- import_zod19 = require("zod");
10088
+ import_zod20 = require("zod");
9845
10089
  init_cliError();
9846
- RenameJournalSchema = import_zod19.z.strictObject({
9847
- version: import_zod19.z.literal(1),
9848
- from: import_zod19.z.string().min(1),
9849
- to: import_zod19.z.string().min(1),
9850
- startedAt: import_zod19.z.iso.datetime(),
10090
+ RenameJournalSchema = import_zod20.z.strictObject({
10091
+ version: import_zod20.z.literal(1),
10092
+ from: import_zod20.z.string().min(1),
10093
+ to: import_zod20.z.string().min(1),
10094
+ startedAt: import_zod20.z.iso.datetime(),
9851
10095
  /** The process that began the rename, for a person reading the file. Whether it is still running is told by the locks, not by this. */
9852
- pid: import_zod19.z.number().int().positive(),
9853
- steps: import_zod19.z.array(
9854
- import_zod19.z.strictObject({
9855
- description: import_zod19.z.string().min(1),
10096
+ pid: import_zod20.z.number().int().positive(),
10097
+ steps: import_zod20.z.array(
10098
+ import_zod20.z.strictObject({
10099
+ description: import_zod20.z.string().min(1),
9856
10100
  /** Whether the step has been applied and marked so. */
9857
- done: import_zod19.z.boolean(),
10101
+ done: import_zod20.z.boolean(),
9858
10102
  /** Whether the step was begun: written ahead of the step, before it runs, so a process that dies after the step took effect and before `done` was written still leaves a record that it may have. */
9859
- started: import_zod19.z.boolean()
10103
+ started: import_zod20.z.boolean()
9860
10104
  })
9861
10105
  )
9862
10106
  });
@@ -9961,13 +10205,13 @@ function requireNoInterruptedNameRename(paths, name, action, except) {
9961
10205
  throw new InterruptedNameRenameError(action, describeInterruptedNameRename(paths, held));
9962
10206
  }
9963
10207
  }
9964
- var import_node_fs7, import_node_path28, import_zod20, NameRenameRecordSchema, RECORD_SUFFIX, InterruptedNameRenameError;
10208
+ var import_node_fs7, import_node_path28, import_zod21, NameRenameRecordSchema, RECORD_SUFFIX, InterruptedNameRenameError;
9965
10209
  var init_identityNameRenameRecord = __esm({
9966
10210
  "src/identityNameRenameRecord.ts"() {
9967
10211
  "use strict";
9968
10212
  import_node_fs7 = __toESM(require("node:fs"), 1);
9969
10213
  import_node_path28 = __toESM(require("node:path"), 1);
9970
- import_zod20 = require("zod");
10214
+ import_zod21 = require("zod");
9971
10215
  init_cliError();
9972
10216
  init_configProfilesStore();
9973
10217
  init_directoryRulesStore();
@@ -9977,12 +10221,12 @@ var init_identityNameRenameRecord = __esm({
9977
10221
  init_poolPick();
9978
10222
  init_identityRecords();
9979
10223
  init_identityRenameJournal();
9980
- NameRenameRecordSchema = import_zod20.z.strictObject({
9981
- version: import_zod20.z.literal(1),
9982
- id: import_zod20.z.string().min(1),
9983
- from: import_zod20.z.string().min(1),
9984
- to: import_zod20.z.string().min(1),
9985
- startedAt: import_zod20.z.iso.datetime()
10224
+ NameRenameRecordSchema = import_zod21.z.strictObject({
10225
+ version: import_zod21.z.literal(1),
10226
+ id: import_zod21.z.string().min(1),
10227
+ from: import_zod21.z.string().min(1),
10228
+ to: import_zod21.z.string().min(1),
10229
+ startedAt: import_zod21.z.iso.datetime()
9986
10230
  });
9987
10231
  RECORD_SUFFIX = ".json";
9988
10232
  InterruptedNameRenameError = class extends CliError {
@@ -9996,7 +10240,7 @@ var init_identityNameRenameRecord = __esm({
9996
10240
 
9997
10241
  // src/launcher/launchRecords.ts
9998
10242
  function recordFile(directory, pid) {
9999
- return import_node_path29.default.join(directory, `${String(pid)}.${(0, import_node_crypto13.randomUUID)()}${RECORD_SUFFIX2}`);
10243
+ return import_node_path29.default.join(directory, `${String(pid)}.${(0, import_node_crypto14.randomUUID)()}${RECORD_SUFFIX2}`);
10000
10244
  }
10001
10245
  function readRecord(fs17, directory, name) {
10002
10246
  if (!name.endsWith(RECORD_SUFFIX2)) {
@@ -10037,18 +10281,18 @@ function liveLaunchesOn(fs17, directory, identity, isRunning) {
10037
10281
  return record?.identity === identity && isRunning(record.pid) ? [record.pid] : [];
10038
10282
  }).sort((left, right) => left - right);
10039
10283
  }
10040
- var import_node_path29, import_node_crypto13, import_zod21, LaunchRecordSchema, RECORD_SUFFIX2;
10284
+ var import_node_path29, import_node_crypto14, import_zod22, LaunchRecordSchema, RECORD_SUFFIX2;
10041
10285
  var init_launchRecords = __esm({
10042
10286
  "src/launcher/launchRecords.ts"() {
10043
10287
  "use strict";
10044
10288
  import_node_path29 = __toESM(require("node:path"), 1);
10045
- import_node_crypto13 = require("node:crypto");
10046
- import_zod21 = require("zod");
10047
- LaunchRecordSchema = import_zod21.z.strictObject({
10289
+ import_node_crypto14 = require("node:crypto");
10290
+ import_zod22 = require("zod");
10291
+ LaunchRecordSchema = import_zod22.z.strictObject({
10048
10292
  /** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
10049
- pid: import_zod21.z.number().int().positive(),
10050
- identity: import_zod21.z.string().min(1),
10051
- startedAt: import_zod21.z.iso.datetime()
10293
+ pid: import_zod22.z.number().int().positive(),
10294
+ identity: import_zod22.z.string().min(1),
10295
+ startedAt: import_zod22.z.iso.datetime()
10052
10296
  });
10053
10297
  RECORD_SUFFIX2 = ".json";
10054
10298
  }
@@ -10519,7 +10763,7 @@ var init_package = __esm({
10519
10763
  "package.json"() {
10520
10764
  package_default = {
10521
10765
  name: "claude-use",
10522
- version: "12.0.0",
10766
+ version: "12.0.1",
10523
10767
  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.",
10524
10768
  license: "MIT",
10525
10769
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -10898,15 +11142,15 @@ function aliasFindings(aliases, providerNames) {
10898
11142
  return { level: "pass", alias, message: `${alias} is a former name of ${target}, still honoured for sessions launched under it. Run \`agent-shim provider unalias ${alias}\` once none is running.` };
10899
11143
  });
10900
11144
  }
10901
- var import_zod25, ProviderAliasesSchema;
11145
+ var import_zod26, ProviderAliasesSchema;
10902
11146
  var init_providerAliases = __esm({
10903
11147
  "src/providerAliases.ts"() {
10904
11148
  "use strict";
10905
- import_zod25 = require("zod");
11149
+ import_zod26 = require("zod");
10906
11150
  init_cliError();
10907
11151
  init_load();
10908
11152
  init_store();
10909
- ProviderAliasesSchema = import_zod25.z.record(import_zod25.z.string().min(1), import_zod25.z.string().min(1));
11153
+ ProviderAliasesSchema = import_zod26.z.record(import_zod26.z.string().min(1), import_zod26.z.string().min(1));
10910
11154
  }
10911
11155
  });
10912
11156
 
@@ -11568,221 +11812,6 @@ var init_claudeVersion = __esm({
11568
11812
  }
11569
11813
  });
11570
11814
 
11571
- // src/headroom/headers.ts
11572
- function mergeAnthropicCustomHeaders(existing, additions) {
11573
- const merged = /* @__PURE__ */ new Map();
11574
- for (const block of existing) {
11575
- if (block === void 0) {
11576
- continue;
11577
- }
11578
- for (const line of block.split("\n")) {
11579
- const entry = parseCustomHeaderLine(line);
11580
- if (entry === void 0) {
11581
- continue;
11582
- }
11583
- merged.set(entry.name, entry.value);
11584
- }
11585
- }
11586
- for (const entry of additions) {
11587
- merged.set(entry.name, entry.value);
11588
- }
11589
- return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
11590
- }
11591
- function parseAnthropicCustomHeaders(block) {
11592
- return block.split("\n").flatMap((line) => {
11593
- const entry = parseCustomHeaderLine(line);
11594
- return entry === void 0 ? [] : [entry];
11595
- });
11596
- }
11597
- function withoutAnthropicCustomHeaders(block, remove) {
11598
- const lines = block.split("\n");
11599
- const kept = lines.filter((line) => {
11600
- const entry = parseCustomHeaderLine(line);
11601
- return entry === void 0 || !remove(entry);
11602
- });
11603
- return kept.length === lines.length ? block : kept.join("\n");
11604
- }
11605
- function parseCustomHeaderLine(line) {
11606
- const trimmed = line.trim();
11607
- if (trimmed === "") {
11608
- return void 0;
11609
- }
11610
- const colon = trimmed.indexOf(":");
11611
- if (colon <= 0) {
11612
- return void 0;
11613
- }
11614
- return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
11615
- }
11616
- var init_headers = __esm({
11617
- "src/headroom/headers.ts"() {
11618
- "use strict";
11619
- }
11620
- });
11621
-
11622
- // src/launcher/injected.ts
11623
- function listKey(list) {
11624
- return `${list},appended`;
11625
- }
11626
- function digest2(value) {
11627
- return (0, import_node_crypto14.createHash)("sha256").update(value).digest("hex");
11628
- }
11629
- function recordedDigests(env) {
11630
- const raw = env[INJECTED_ENV];
11631
- if (raw === void 0 || raw === "") {
11632
- return {};
11633
- }
11634
- let parsed;
11635
- try {
11636
- parsed = JSON.parse(raw);
11637
- } catch {
11638
- return {};
11639
- }
11640
- const result = InjectedSchema.safeParse(parsed);
11641
- return result.success ? result.data : {};
11642
- }
11643
- function recordInjections(base) {
11644
- const env = { ...base };
11645
- const digests = new Map(Object.entries(recordedDigests(env)));
11646
- return {
11647
- env,
11648
- set: (name, value) => {
11649
- env[name] = value;
11650
- digests.set(name, digest2(value));
11651
- },
11652
- unset: (name) => {
11653
- env[name] = void 0;
11654
- digests.delete(name);
11655
- },
11656
- recordHeaders: (names) => {
11657
- const block = env[CUSTOM_HEADERS_ENV];
11658
- for (const entry of block === void 0 ? [] : parseAnthropicCustomHeaders(block)) {
11659
- if (names.includes(entry.name)) {
11660
- digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
11661
- }
11662
- }
11663
- },
11664
- recordBypassHosts: (list, hosts) => {
11665
- const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
11666
- if (recordedHosts.length > 0) {
11667
- digests.set(listKey(list), recordedHosts.join(","));
11668
- }
11669
- },
11670
- finish: () => {
11671
- if (digests.size > 0) {
11672
- env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
11673
- }
11674
- }
11675
- };
11676
- }
11677
- function withoutRecordedHosts(list, value, digests) {
11678
- const recordedHosts = new Set(digests[listKey(list)]?.split(","));
11679
- const entries = value.split(",");
11680
- const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
11681
- return kept.length === entries.length ? value : kept.join(",");
11682
- }
11683
- function launchEnvironment(env, configDirEscapeHatch) {
11684
- return configDirEscapeHatch ? env : withoutInjected(env);
11685
- }
11686
- function withoutInjected(env) {
11687
- const digests = recordedDigests(env);
11688
- const entries = Object.entries(env).flatMap(([name, value]) => {
11689
- if (name === INJECTED_ENV) {
11690
- return [];
11691
- }
11692
- if (value === void 0) {
11693
- return [[name, value]];
11694
- }
11695
- if (name === CUSTOM_HEADERS_ENV) {
11696
- const remaining = withoutAnthropicCustomHeaders(value, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
11697
- return remaining !== value && remaining.trim() === "" ? [] : [[name, remaining]];
11698
- }
11699
- if (name === "NO_PROXY" || name === "no_proxy") {
11700
- const remaining = withoutRecordedHosts(name, value, digests);
11701
- return remaining !== value && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
11702
- }
11703
- return digests[name] === digest2(value) ? [] : [[name, value]];
11704
- });
11705
- return Object.fromEntries(entries);
11706
- }
11707
- var import_node_crypto14, import_zod26, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
11708
- var init_injected = __esm({
11709
- "src/launcher/injected.ts"() {
11710
- "use strict";
11711
- import_node_crypto14 = require("node:crypto");
11712
- import_zod26 = require("zod");
11713
- init_headers();
11714
- INJECTED_ENV = "AGENT_SHIM_INJECTED";
11715
- CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
11716
- HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
11717
- InjectedSchema = import_zod26.z.record(import_zod26.z.string(), import_zod26.z.string());
11718
- }
11719
- });
11720
-
11721
- // src/launcher/guard.ts
11722
- function detectAmbientCredential(env, injected) {
11723
- for (const variable of AMBIENT_CREDENTIAL_VARS) {
11724
- const value = env[variable];
11725
- if (value === void 0 || value === "") {
11726
- continue;
11727
- }
11728
- if (injected?.variable === variable && value === injected.token) {
11729
- continue;
11730
- }
11731
- return { variable };
11732
- }
11733
- return void 0;
11734
- }
11735
- function formatAmbientCredentialGuardMessage(variable, identityName) {
11736
- const identitySetCommand = identityName === void 0 ? "agent-shim identity set <name> --allow-ambient-credential" : `agent-shim identity set ${identityName} --allow-ambient-credential`;
11737
- return [
11738
- `error: ${variable} is set in the environment. This identity's isolated`,
11739
- "credential would be bypassed \u2014 every identity authenticates as this same key",
11740
- "while it's set. Unset it, or if this is deliberate, opt in per-launch with",
11741
- "AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL=1, or persistently for this identity with",
11742
- `\`${identitySetCommand}\`.`
11743
- ].join("\n");
11744
- }
11745
- function evaluateAmbientCredentialGuard(params) {
11746
- const detected = detectAmbientCredential(params.env, params.injectedCredential);
11747
- if (detected === void 0) {
11748
- return { ok: true };
11749
- }
11750
- if (params.allowAmbientCredentialOverride || params.allowAmbientCredential || params.providerSelected === true) {
11751
- return { ok: true };
11752
- }
11753
- return {
11754
- ok: false,
11755
- variable: detected.variable,
11756
- message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
11757
- };
11758
- }
11759
- function ambientCredentialFinding(env) {
11760
- const named = detectAmbientCredential(launchEnvironment(env, false));
11761
- if (named !== void 0) {
11762
- return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
11763
- }
11764
- const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
11765
- if (bare !== void 0) {
11766
- return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
11767
- }
11768
- return { severity: "pass", message: "No ambient-credential environment variable is set." };
11769
- }
11770
- var AMBIENT_CREDENTIAL_VARS;
11771
- var init_guard = __esm({
11772
- "src/launcher/guard.ts"() {
11773
- "use strict";
11774
- init_injected();
11775
- AMBIENT_CREDENTIAL_VARS = [
11776
- "ANTHROPIC_API_KEY",
11777
- "ANTHROPIC_AUTH_TOKEN",
11778
- "CLAUDE_CODE_OAUTH_TOKEN",
11779
- "CLAUDE_CODE_USE_BEDROCK",
11780
- "CLAUDE_CODE_USE_VERTEX",
11781
- "CLAUDE_CODE_USE_FOUNDRY"
11782
- ];
11783
- }
11784
- });
11785
-
11786
11815
  // src/usage/resets.ts
11787
11816
  function formatPeriod(window) {
11788
11817
  if (window.periodMs === void 0) {
@@ -14331,10 +14360,22 @@ function decideLaunch(params, readOnly, onRecorded) {
14331
14360
  ...parsedArgv.delay === void 0 ? {} : { delay: parsedArgv.delay }
14332
14361
  }
14333
14362
  });
14334
- const loginlessProvider = requestedFlags.remoteControl && selectedProvider !== void 0 && farmIdentity !== void 0 && identityDecision.name !== void 0 && params.hasStoredLogin?.(farmIdentity) === false ? { identity: identityDecision.name, provider: selectedProvider.name } : void 0;
14363
+ const loginlessProvider = (() => {
14364
+ if (!requestedFlags.remoteControl || selectedProvider === void 0 || farmIdentity === void 0 || identityDecision.name === void 0) {
14365
+ return void 0;
14366
+ }
14367
+ const stored = params.hasStoredLogin?.(farmIdentity);
14368
+ if (stored === false) {
14369
+ return { identity: identityDecision.name, provider: selectedProvider.name, why: "has no stored login" };
14370
+ }
14371
+ if (stored === true && params.hasUsableLogin?.(farmIdentity, discovered.path) === false) {
14372
+ return { identity: identityDecision.name, provider: selectedProvider.name, why: "has a stored login that is no longer usable" };
14373
+ }
14374
+ return void 0;
14375
+ })();
14335
14376
  const notes = [];
14336
14377
  if (loginlessProvider !== void 0) {
14337
- notes.push(`${loginlessProvider.identity} has no stored login, so Remote Control is off; provider ${loginlessProvider.provider} runs without it`);
14378
+ notes.push(`${loginlessProvider.identity} ${loginlessProvider.why}, so Remote Control is off; provider ${loginlessProvider.provider} runs without it`);
14338
14379
  }
14339
14380
  const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
14340
14381
  const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
@@ -14969,6 +15010,7 @@ function realPrepareLaunchParams(paths, options) {
14969
15010
  credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
14970
15011
  hold: realHoldPort,
14971
15012
  hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: import_node_path54.default.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
15013
+ hasUsableLogin: (identity, claudeBin) => storedLoginUsable(options.run ?? realRunPort, claudeBin, import_node_path54.default.join(paths.identitiesDir, identity), options.proc.env),
14972
15014
  ...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
14973
15015
  ...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
14974
15016
  ...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
@@ -18424,20 +18466,20 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
18424
18466
 
18425
18467
  // src/frontdoor/rcSessionRegistry.ts
18426
18468
  var import_node_path31 = __toESM(require("node:path"), 1);
18427
- var import_zod22 = require("zod");
18469
+ var import_zod23 = require("zod");
18428
18470
  init_identityStore();
18429
18471
  var REGISTRY_BRIDGE_PREFIX = "session_";
18430
18472
  var DOOR_SESSION_PREFIX = "cse_";
18431
18473
  var REGISTRY_DIR = "sessions";
18432
18474
  var ENTRY_SUFFIX = ".json";
18433
18475
  var RC_REGISTRY_ENTRY_MAX_BYTES = 8192;
18434
- var RegistryEntrySchema = import_zod22.z.looseObject({
18435
- sessionId: import_zod22.z.string().min(1),
18436
- pid: import_zod22.z.int().positive(),
18437
- bridgeSessionId: import_zod22.z.union([import_zod22.z.string().startsWith(REGISTRY_BRIDGE_PREFIX), import_zod22.z.string().startsWith(DOOR_SESSION_PREFIX)]),
18438
- cwd: import_zod22.z.string().optional(),
18439
- name: import_zod22.z.string().optional(),
18440
- updatedAt: import_zod22.z.number().optional()
18476
+ var RegistryEntrySchema = import_zod23.z.looseObject({
18477
+ sessionId: import_zod23.z.string().min(1),
18478
+ pid: import_zod23.z.int().positive(),
18479
+ bridgeSessionId: import_zod23.z.union([import_zod23.z.string().startsWith(REGISTRY_BRIDGE_PREFIX), import_zod23.z.string().startsWith(DOOR_SESSION_PREFIX)]),
18480
+ cwd: import_zod23.z.string().optional(),
18481
+ name: import_zod23.z.string().optional(),
18482
+ updatedAt: import_zod23.z.number().optional()
18441
18483
  });
18442
18484
  function supersedes(candidate, kept) {
18443
18485
  return candidate.updatedAt > kept.updatedAt || candidate.updatedAt === kept.updatedAt && candidate.session.pid > kept.session.pid;
@@ -18644,7 +18686,7 @@ var COMPACT_TIMEOUT_MS = 9e5;
18644
18686
  init_capability();
18645
18687
 
18646
18688
  // src/frontdoor/rcSlashCommandSchemas.ts
18647
- var import_zod23 = require("zod");
18689
+ var import_zod24 = require("zod");
18648
18690
 
18649
18691
  // src/frontdoor/rcSessionCommands.ts
18650
18692
  var import_promises = require("node:timers/promises");
@@ -19032,47 +19074,47 @@ function createRcSessionCommands(deps) {
19032
19074
  }
19033
19075
 
19034
19076
  // src/frontdoor/rcSlashCommandSchemas.ts
19035
- var WaitMsSchema = import_zod23.z.int().positive().max(RC_SESSION_COMMAND_MAX_WAIT_MS).optional();
19036
- var RcGoalSessionInputSchema = import_zod23.z.strictObject({
19037
- session: import_zod23.z.string().min(1),
19077
+ var WaitMsSchema = import_zod24.z.int().positive().max(RC_SESSION_COMMAND_MAX_WAIT_MS).optional();
19078
+ var RcGoalSessionInputSchema = import_zod24.z.strictObject({
19079
+ session: import_zod24.z.string().min(1),
19038
19080
  waitMs: WaitMsSchema
19039
19081
  });
19040
- var RcGoalSetInputSchema = import_zod23.z.strictObject({
19041
- session: import_zod23.z.string().min(1),
19042
- condition: import_zod23.z.string().trim().min(1).max(RC_GOAL_CONDITION_MAX_CHARS).regex(/^[^\r\n]*$/u, "a goal condition is one line"),
19082
+ var RcGoalSetInputSchema = import_zod24.z.strictObject({
19083
+ session: import_zod24.z.string().min(1),
19084
+ condition: import_zod24.z.string().trim().min(1).max(RC_GOAL_CONDITION_MAX_CHARS).regex(/^[^\r\n]*$/u, "a goal condition is one line"),
19043
19085
  waitMs: WaitMsSchema
19044
19086
  });
19045
- var RcCompactInputSchema = import_zod23.z.strictObject({
19046
- session: import_zod23.z.string().min(1),
19087
+ var RcCompactInputSchema = import_zod24.z.strictObject({
19088
+ session: import_zod24.z.string().min(1),
19047
19089
  waitMs: WaitMsSchema
19048
19090
  });
19049
- var RcCompactWithInstructionsInputSchema = import_zod23.z.strictObject({
19050
- session: import_zod23.z.string().min(1),
19051
- instructions: import_zod23.z.string().trim().min(1).max(RC_COMPACT_INSTRUCTIONS_MAX_CHARS),
19091
+ var RcCompactWithInstructionsInputSchema = import_zod24.z.strictObject({
19092
+ session: import_zod24.z.string().min(1),
19093
+ instructions: import_zod24.z.string().trim().min(1).max(RC_COMPACT_INSTRUCTIONS_MAX_CHARS),
19052
19094
  waitMs: WaitMsSchema
19053
19095
  });
19054
19096
  var commandAnswerShape = {
19055
- session: import_zod23.z.string(),
19056
- route: import_zod23.z.enum(["supervised", "self-hosted"])
19097
+ session: import_zod24.z.string(),
19098
+ route: import_zod24.z.enum(["supervised", "self-hosted"])
19057
19099
  };
19058
- var RcGoalGetOutputSchema = import_zod23.z.strictObject({
19100
+ var RcGoalGetOutputSchema = import_zod24.z.strictObject({
19059
19101
  ...commandAnswerShape,
19060
- goal: import_zod23.z.strictObject({ condition: import_zod23.z.string(), iterations: import_zod23.z.int().nonnegative(), lastCheck: import_zod23.z.string().optional() }).nullable()
19102
+ goal: import_zod24.z.strictObject({ condition: import_zod24.z.string(), iterations: import_zod24.z.int().nonnegative(), lastCheck: import_zod24.z.string().optional() }).nullable()
19061
19103
  });
19062
- var RcGoalSetOutputSchema = import_zod23.z.strictObject({
19104
+ var RcGoalSetOutputSchema = import_zod24.z.strictObject({
19063
19105
  ...commandAnswerShape,
19064
- condition: import_zod23.z.string(),
19065
- superseded: import_zod23.z.string().nullable()
19106
+ condition: import_zod24.z.string(),
19107
+ superseded: import_zod24.z.string().nullable()
19066
19108
  });
19067
- var RcGoalClearOutputSchema = import_zod23.z.strictObject({
19109
+ var RcGoalClearOutputSchema = import_zod24.z.strictObject({
19068
19110
  ...commandAnswerShape,
19069
- cleared: import_zod23.z.string().nullable()
19111
+ cleared: import_zod24.z.string().nullable()
19070
19112
  });
19071
- var RcCompactOutputSchema = import_zod23.z.strictObject({
19113
+ var RcCompactOutputSchema = import_zod24.z.strictObject({
19072
19114
  ...commandAnswerShape,
19073
- trigger: import_zod23.z.string(),
19074
- preTokens: import_zod23.z.number().optional(),
19075
- postTokens: import_zod23.z.number().optional()
19115
+ trigger: import_zod24.z.string(),
19116
+ preTokens: import_zod24.z.number().optional(),
19117
+ postTokens: import_zod24.z.number().optional()
19076
19118
  });
19077
19119
 
19078
19120
  // src/frontdoor/rcApi.ts
@@ -19293,48 +19335,48 @@ init_cliError();
19293
19335
  init_package();
19294
19336
 
19295
19337
  // src/codex/appServerSchemas.ts
19296
- var import_zod24 = require("zod");
19338
+ var import_zod25 = require("zod");
19297
19339
  var CODEX_APP_SERVER_GENERATED_AGAINST = "0.160.0";
19298
- var RateLimitWindowSchema = import_zod24.z.object({
19299
- usedPercent: import_zod24.z.number(),
19300
- resetsAt: import_zod24.z.number().nullish(),
19301
- windowDurationMins: import_zod24.z.number().nullish()
19302
- });
19303
- var RateLimitSnapshotSchema = import_zod24.z.object({
19304
- limitId: import_zod24.z.string().nullish(),
19305
- limitName: import_zod24.z.string().nullish(),
19306
- planType: import_zod24.z.string().nullish(),
19340
+ var RateLimitWindowSchema = import_zod25.z.object({
19341
+ usedPercent: import_zod25.z.number(),
19342
+ resetsAt: import_zod25.z.number().nullish(),
19343
+ windowDurationMins: import_zod25.z.number().nullish()
19344
+ });
19345
+ var RateLimitSnapshotSchema = import_zod25.z.object({
19346
+ limitId: import_zod25.z.string().nullish(),
19347
+ limitName: import_zod25.z.string().nullish(),
19348
+ planType: import_zod25.z.string().nullish(),
19307
19349
  primary: RateLimitWindowSchema.nullish(),
19308
19350
  secondary: RateLimitWindowSchema.nullish(),
19309
- rateLimitReachedType: import_zod24.z.string().nullish(),
19310
- spendControlReached: import_zod24.z.boolean().nullish()
19311
- });
19312
- var RateLimitResetCreditSchema = import_zod24.z.object({
19313
- id: import_zod24.z.string(),
19314
- grantedAt: import_zod24.z.number(),
19315
- expiresAt: import_zod24.z.number().nullish(),
19316
- resetType: import_zod24.z.string(),
19317
- status: import_zod24.z.string(),
19318
- title: import_zod24.z.string().nullish(),
19319
- description: import_zod24.z.string().nullish()
19320
- });
19321
- var CodexAccountSchema = import_zod24.z.discriminatedUnion("type", [
19322
- import_zod24.z.object({ type: import_zod24.z.literal("apiKey") }),
19323
- import_zod24.z.object({ type: import_zod24.z.literal("chatgpt"), email: import_zod24.z.string().nullable(), planType: import_zod24.z.string() }),
19324
- import_zod24.z.object({ type: import_zod24.z.literal("amazonBedrock"), usesCodexManagedCredentials: import_zod24.z.boolean().default(false) })
19351
+ rateLimitReachedType: import_zod25.z.string().nullish(),
19352
+ spendControlReached: import_zod25.z.boolean().nullish()
19353
+ });
19354
+ var RateLimitResetCreditSchema = import_zod25.z.object({
19355
+ id: import_zod25.z.string(),
19356
+ grantedAt: import_zod25.z.number(),
19357
+ expiresAt: import_zod25.z.number().nullish(),
19358
+ resetType: import_zod25.z.string(),
19359
+ status: import_zod25.z.string(),
19360
+ title: import_zod25.z.string().nullish(),
19361
+ description: import_zod25.z.string().nullish()
19362
+ });
19363
+ var CodexAccountSchema = import_zod25.z.discriminatedUnion("type", [
19364
+ import_zod25.z.object({ type: import_zod25.z.literal("apiKey") }),
19365
+ import_zod25.z.object({ type: import_zod25.z.literal("chatgpt"), email: import_zod25.z.string().nullable(), planType: import_zod25.z.string() }),
19366
+ import_zod25.z.object({ type: import_zod25.z.literal("amazonBedrock"), usesCodexManagedCredentials: import_zod25.z.boolean().default(false) })
19325
19367
  ]);
19326
- var CodexAccountReadSchema = import_zod24.z.object({
19368
+ var CodexAccountReadSchema = import_zod25.z.object({
19327
19369
  account: CodexAccountSchema.nullable(),
19328
- requiresOpenaiAuth: import_zod24.z.boolean()
19370
+ requiresOpenaiAuth: import_zod25.z.boolean()
19329
19371
  });
19330
- var CodexRateLimitsReadSchema = import_zod24.z.object({
19372
+ var CodexRateLimitsReadSchema = import_zod25.z.object({
19331
19373
  rateLimits: RateLimitSnapshotSchema,
19332
- rateLimitsByLimitId: import_zod24.z.record(import_zod24.z.string(), RateLimitSnapshotSchema).nullish(),
19333
- rateLimitResetCredits: import_zod24.z.object({ availableCount: import_zod24.z.number(), credits: import_zod24.z.array(RateLimitResetCreditSchema).nullish() }).nullish(),
19334
- accountId: import_zod24.z.string().nullish(),
19335
- ordinaryUsageAllowed: import_zod24.z.boolean().nullish()
19374
+ rateLimitsByLimitId: import_zod25.z.record(import_zod25.z.string(), RateLimitSnapshotSchema).nullish(),
19375
+ rateLimitResetCredits: import_zod25.z.object({ availableCount: import_zod25.z.number(), credits: import_zod25.z.array(RateLimitResetCreditSchema).nullish() }).nullish(),
19376
+ accountId: import_zod25.z.string().nullish(),
19377
+ ordinaryUsageAllowed: import_zod25.z.boolean().nullish()
19336
19378
  });
19337
- var CodexInitializeResultSchema = import_zod24.z.object({ userAgent: import_zod24.z.string() });
19379
+ var CodexInitializeResultSchema = import_zod25.z.object({ userAgent: import_zod25.z.string() });
19338
19380
 
19339
19381
  // src/codex/appServer.ts
19340
19382
  var CodexAppServerUnavailableError = class extends CliError {