agent-shim 14.12.4 → 14.13.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.mjs CHANGED
@@ -27,6 +27,8 @@ var init_categories_default = __esm({
27
27
  "mcp-needs-auth-cache.json",
28
28
  "codex-quota.json",
29
29
  "file-transfers",
30
+ "bridge-spawn",
31
+ "child-logs",
30
32
  "shell-snapshots",
31
33
  "statsig",
32
34
  "telemetry",
@@ -902,6 +904,35 @@ var init_versionDiscovery = __esm({
902
904
  }
903
905
  });
904
906
 
907
+ // src/identityGrants.ts
908
+ function canonicalFeatures(features) {
909
+ return GRANT_FEATURES.filter((feature) => features.includes(feature));
910
+ }
911
+ function withGrant(grants, borrowerId, features) {
912
+ const held = grants.find((grant) => grant.to === borrowerId)?.features ?? [];
913
+ const added = { to: borrowerId, features: canonicalFeatures([...held, ...features]) };
914
+ return [...grants.filter((grant) => grant.to !== borrowerId), added].sort((first, second) => first.to.localeCompare(second.to));
915
+ }
916
+ function withoutGrant(grants, borrowerId, features) {
917
+ return grants.flatMap((grant) => {
918
+ if (grant.to !== borrowerId) {
919
+ return [grant];
920
+ }
921
+ const kept = features === void 0 ? [] : grant.features.filter((feature) => !features.includes(feature));
922
+ return kept.length === 0 ? [] : [{ to: grant.to, features: kept }];
923
+ });
924
+ }
925
+ function loginsLentTo(identities, borrowerId) {
926
+ return identities.flatMap((identity) => identity.id === borrowerId ? [] : (identity.grants ?? []).filter((grant) => grant.to === borrowerId).map((grant) => ({ from: identity.name, features: grant.features })));
927
+ }
928
+ var GRANT_FEATURES;
929
+ var init_identityGrants = __esm({
930
+ "src/identityGrants.ts"() {
931
+ "use strict";
932
+ GRANT_FEATURES = ["remote-control", "artifacts", "connectors", "server-tools"];
933
+ }
934
+ });
935
+
905
936
  // src/config/schema.ts
906
937
  import path3 from "node:path";
907
938
  import { z as z3 } from "zod";
@@ -943,7 +974,7 @@ function isTimeZone(name) {
943
974
  return false;
944
975
  }
945
976
  }
946
- var CATEGORY_NAMES, OVERRIDABLE_CATEGORIES, CategoryMapSchema, DURATION_RE, DurationSchema, WhenConditionObjectSchema, WhenSchema, EntryValueSchema, ENTRY_KEY_RE, EntriesSchema, LaunchSchema, CREDENTIAL_TARGETS, PROVIDER_CREDENTIAL_TARGETS, CREDENTIAL_TARGET_VARS, ArgvSchema, CommandSourceOptions, EnvCredentialSourceSchema, FileCredentialSourceSchema, CommandCredentialSourceSchema, OpCredentialSourceSchema, KeychainCredentialSourceSchema, LiteralCredentialSourceSchema, CredentialSourceSchema, RemoteCredentialSourceSchema, CREDENTIAL_CACHE_STORES, CredentialCacheSchema, CredentialSchema, ProviderCredentialSchema, RESERVED_PROVIDER_ENV_KEYS, TIER_MODEL_ENV_VARIABLES, OTHER_MODEL_ENV_VARIABLES, MODEL_ENV_VARIABLES, ProviderEnvSchema, PROVIDER_KINDS, ANTIGRAVITY_MODES, CLAUDE_TIERS, ANTIGRAVITY_EFFORTS, ANTIGRAVITY_DEFAULT_MODE, ANTIGRAVITY_DEFAULT_MODEL, ANTIGRAVITY_DEFAULT_TIER_MODELS, ANTIGRAVITY_DEFAULT_EFFORT, AntigravityModelTargetSchema, AntigravityProviderConfigSchema, CODEX_EFFORTS, CODEX_LOGINS, CODEX_DEFAULT_LOGIN, CODEX_DEFAULT_MODEL, CODEX_DEFAULT_TIER_MODELS, CODEX_DEFAULT_EFFORT, CodexProviderConfigSchema, ProviderRouteSchema, PickerModelSchema, PickerModelsSchema, ProviderCatalogueSchema, MAX_TIMER_DELAY_MS, HttpBaseUrlSchema, SERVER_TOOLS_MODES, HttpProviderSchema, CodexProviderSchema, RouterProviderSchema, AntigravityProviderSchema, ProviderSchema, SELECTION_MODES, VirtualModelSchema, ModelPricesSchema, FamilySettingsSchema, ModelsConfigSchema, ModelsLayerSchema, ConfigProfileSchema, POOL_SELECTOR_PREFIX, POOL_NAME_PATTERN, PoolNameSchema, SELECTOR_RE, IdentitySelectorSchema, PoolMemberSchema, POOL_PREFERENCES, PoolPreferenceSchema, WHOLE_PERCENT_MAX, CompactAtUtilisationSchema, PoolSchema, WEEKDAYS, AnchorSchema, JOB_WINDOWS, JobTriggerSchema, JobTargetSchema, JobSchema, DirectoryRuleSchema, DirectoryRulesSchema, PortableConfigSchema, HEADROOM_MODES, HEADROOM_CCR_MODES, HEADROOM_ROLLOUT_CHANNELS, INTERCEPT_CHANNELS, READ_MATURATION_CHANNELS, HeadroomGlobalConfigObjectSchema, HeadroomGlobalConfigSchema, HEADROOM_DEFAULT_SOURCE, HEADROOM_DEFAULT_IDLE_SHUTDOWN_MINUTES, FrontDoorGlobalConfigSchema, UPDATE_MODES, UpdateGlobalConfigSchema, GlobalConfigSchema, IdentitySchema, CategoryClassificationSchema, CategoryClassificationOverlaySchema, SHIPPED_CATEGORY_DEFAULTS;
977
+ var CATEGORY_NAMES, OVERRIDABLE_CATEGORIES, CategoryMapSchema, DURATION_RE, DurationSchema, WhenConditionObjectSchema, WhenSchema, EntryValueSchema, ENTRY_KEY_RE, EntriesSchema, LaunchSchema, CREDENTIAL_TARGETS, PROVIDER_CREDENTIAL_TARGETS, CREDENTIAL_TARGET_VARS, ArgvSchema, CommandSourceOptions, EnvCredentialSourceSchema, FileCredentialSourceSchema, CommandCredentialSourceSchema, OpCredentialSourceSchema, KeychainCredentialSourceSchema, LiteralCredentialSourceSchema, CredentialSourceSchema, RemoteCredentialSourceSchema, CREDENTIAL_CACHE_STORES, CredentialCacheSchema, CredentialSchema, ProviderCredentialSchema, RESERVED_PROVIDER_ENV_KEYS, TIER_MODEL_ENV_VARIABLES, OTHER_MODEL_ENV_VARIABLES, MODEL_ENV_VARIABLES, ProviderEnvSchema, PROVIDER_KINDS, ANTIGRAVITY_MODES, CLAUDE_TIERS, ANTIGRAVITY_EFFORTS, ANTIGRAVITY_DEFAULT_MODE, ANTIGRAVITY_DEFAULT_MODEL, ANTIGRAVITY_DEFAULT_TIER_MODELS, ANTIGRAVITY_DEFAULT_EFFORT, AntigravityModelTargetSchema, AntigravityProviderConfigSchema, CODEX_EFFORTS, CODEX_LOGINS, CODEX_DEFAULT_LOGIN, CODEX_DEFAULT_MODEL, CODEX_DEFAULT_TIER_MODELS, CODEX_DEFAULT_EFFORT, CodexProviderConfigSchema, ProviderRouteSchema, PickerModelSchema, PickerModelsSchema, ProviderCatalogueSchema, MAX_TIMER_DELAY_MS, HttpBaseUrlSchema, SERVER_TOOLS_MODES, HttpProviderSchema, CodexProviderSchema, RouterProviderSchema, AntigravityProviderSchema, ProviderSchema, SELECTION_MODES, VirtualModelSchema, ModelPricesSchema, FamilySettingsSchema, ModelsConfigSchema, ModelsLayerSchema, ConfigProfileSchema, POOL_SELECTOR_PREFIX, POOL_NAME_PATTERN, PoolNameSchema, SELECTOR_RE, IdentitySelectorSchema, PoolMemberSchema, POOL_PREFERENCES, PoolPreferenceSchema, WHOLE_PERCENT_MAX, CompactAtUtilisationSchema, PoolSchema, WEEKDAYS, AnchorSchema, JOB_WINDOWS, JobTriggerSchema, JobTargetSchema, JobSchema, DirectoryRuleSchema, DirectoryRulesSchema, PortableConfigSchema, HEADROOM_MODES, HEADROOM_CCR_MODES, HEADROOM_ROLLOUT_CHANNELS, INTERCEPT_CHANNELS, READ_MATURATION_CHANNELS, HeadroomGlobalConfigObjectSchema, HeadroomGlobalConfigSchema, HEADROOM_DEFAULT_SOURCE, HEADROOM_DEFAULT_IDLE_SHUTDOWN_MINUTES, FrontDoorGlobalConfigSchema, UPDATE_MODES, UpdateGlobalConfigSchema, GlobalConfigSchema, IdentityGrantSchema, IdentitySchema, CategoryClassificationSchema, CategoryClassificationOverlaySchema, SHIPPED_CATEGORY_DEFAULTS;
947
978
  var init_schema = __esm({
948
979
  "src/config/schema.ts"() {
949
980
  "use strict";
@@ -953,6 +984,7 @@ var init_schema = __esm({
953
984
  init_identity();
954
985
  init_versionDiscovery();
955
986
  init_ownEntry();
987
+ init_identityGrants();
956
988
  CATEGORY_NAMES = ["secret", "runtime", "history", "knowledge", "settings"];
957
989
  OVERRIDABLE_CATEGORIES = ["runtime", "history", "knowledge", "settings"];
958
990
  CategoryMapSchema = z3.strictObject({
@@ -1401,6 +1433,10 @@ var init_schema = __esm({
1401
1433
  models: ModelsConfigSchema.optional(),
1402
1434
  jobs: z3.record(PoolNameSchema, JobSchema).optional()
1403
1435
  });
1436
+ IdentityGrantSchema = z3.strictObject({
1437
+ to: FileNameSchema,
1438
+ features: z3.array(z3.enum(GRANT_FEATURES)).min(1)
1439
+ });
1404
1440
  IdentitySchema = z3.strictObject({
1405
1441
  /** The CLI this login belongs to; absent means Claude Code for backwards compatibility. */
1406
1442
  agent: z3.enum(["claude", "codex"]).optional(),
@@ -1413,6 +1449,8 @@ var init_schema = __esm({
1413
1449
  provider: StoredNameSchema.optional(),
1414
1450
  allowAmbientCredential: z3.boolean().default(false),
1415
1451
  credential: CredentialSchema.optional(),
1452
+ /** Which other identities may use this identity's claude.ai login, and for what (`identity grant`). Absent: none may. */
1453
+ grants: z3.array(IdentityGrantSchema).min(1).optional(),
1416
1454
  /** When this identity's five-hour window should be open: the front door opens one at each anchor if none is. Absent, nothing is opened on a schedule. */
1417
1455
  anchors: z3.array(AnchorSchema).min(1).optional()
1418
1456
  });
@@ -15010,6 +15048,35 @@ function setAllowAmbientCredential(paths, identityName, allow) {
15010
15048
  allowAmbientCredential: allow
15011
15049
  });
15012
15050
  }
15051
+ function changeIdentityGrants(paths, parties, change, namesLock) {
15052
+ return withIdentityNamesLock(paths, namesLock, () => {
15053
+ const lenderId = requireStoredIdentityId(paths, parties.lender);
15054
+ const borrowerId = requireStoredIdentityId(paths, parties.borrower);
15055
+ if (lenderId === borrowerId) {
15056
+ throw new UsageError(`Identity "${parties.lender}" already uses its own login, so there is nothing to grant to itself.`);
15057
+ }
15058
+ const lender = readIdentityById(paths, lenderId);
15059
+ const borrower = readIdentityById(paths, borrowerId);
15060
+ if (lender === void 0) {
15061
+ throw identityNotFound(paths, parties.lender);
15062
+ }
15063
+ for (const identity of [lender, borrower]) {
15064
+ if (identity?.agent === "codex") {
15065
+ throw new UsageError(`Identity "${identity.name}" runs Codex, which has no claude.ai login to lend or borrow.`);
15066
+ }
15067
+ }
15068
+ return writeIdentityGrants(paths, lenderId, change(lender.grants ?? [], borrowerId));
15069
+ });
15070
+ }
15071
+ function writeIdentityGrants(paths, id, grants) {
15072
+ return applyPatch(identityJsonPath(paths, id), IdentitySchema, { grants: grants.length === 0 ? void 0 : grants.map((grant) => ({ to: grant.to, features: [...grant.features] })) });
15073
+ }
15074
+ function grantIdentityLogin(paths, parties, features, namesLock = realIdentityNamesLockPorts) {
15075
+ return changeIdentityGrants(paths, parties, (grants, borrowerId) => withGrant(grants, borrowerId, features), namesLock);
15076
+ }
15077
+ function revokeIdentityLogin(paths, parties, features, namesLock = realIdentityNamesLockPorts) {
15078
+ return changeIdentityGrants(paths, parties, (grants, borrowerId) => withoutGrant(grants, borrowerId, features), namesLock);
15079
+ }
15013
15080
  function setIdentityCredential(paths, identityName, change) {
15014
15081
  const id = requireStoredIdentityId(paths, identityName);
15015
15082
  const existing = readIdentityById(paths, id);
@@ -15092,6 +15159,11 @@ function removeIdentityWithLockHeld(paths, name, namesLock) {
15092
15159
  if (readActiveIdentity2(paths) === name) {
15093
15160
  fs9.rmSync(paths.activeIdentityFile);
15094
15161
  }
15162
+ for (const listing of listIdentities(paths)) {
15163
+ if (listing.problem === void 0 && listing.identity.grants?.some((grant) => grant.to === id) === true) {
15164
+ writeIdentityGrants(paths, listing.id, withoutGrant(listing.identity.grants, id, void 0));
15165
+ }
15166
+ }
15095
15167
  return id;
15096
15168
  } finally {
15097
15169
  resync.release();
@@ -15121,6 +15193,7 @@ var init_identityStore = __esm({
15121
15193
  init_sameDirectory();
15122
15194
  init_identityRecords();
15123
15195
  init_launchRecords();
15196
+ init_identityGrants();
15124
15197
  IdentityNotFoundError = class extends CliError {
15125
15198
  constructor(name, remedy2 = `Run \`agent-shim identity add ${name}\` first.`) {
15126
15199
  super(`No identity named "${name}". ${remedy2}`);
@@ -15181,7 +15254,7 @@ var init_package = __esm({
15181
15254
  "package.json"() {
15182
15255
  package_default = {
15183
15256
  name: "agent-shim",
15184
- version: "14.12.4",
15257
+ version: "14.13.0",
15185
15258
  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.",
15186
15259
  license: "MIT",
15187
15260
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -21797,6 +21870,7 @@ var PoolPickReportSchema = z28.strictObject({
21797
21870
  });
21798
21871
 
21799
21872
  // src/checkReportSchema.ts
21873
+ init_identityGrants();
21800
21874
  var CHECK_CREDENTIAL_APPLIES = ["provider", "identity", "stored-login"];
21801
21875
  var CheckLayerViewSchema = z29.strictObject({
21802
21876
  id: z29.int(),
@@ -21872,6 +21946,8 @@ var CheckClaudeVersionSchema = z29.strictObject({
21872
21946
  });
21873
21947
  var CheckReportJsonSchema = z29.strictObject({
21874
21948
  identity: z29.strictObject({ name: z29.string().nullable(), source: z29.enum(IDENTITY_DECISION_SOURCES) }),
21949
+ /** The logins other identities lend this one through the front door; absent when none does. */
21950
+ borrowedLogins: z29.readonly(z29.array(z29.strictObject({ from: z29.string(), features: z29.readonly(z29.array(z29.enum(GRANT_FEATURES))) }))).optional(),
21875
21951
  /** The pool ranking, when the launch named a pool instead of an identity. */
21876
21952
  pool: PoolPickReportSchema.optional(),
21877
21953
  configProfile: z29.strictObject({ name: z29.string().nullable(), source: z29.enum(CONFIG_PROFILE_DECISION_SOURCES) }),
@@ -22222,6 +22298,7 @@ init_schema();
22222
22298
  init_baseUrlDisplay();
22223
22299
  init_providerReachability();
22224
22300
  init_identityStore();
22301
+ init_identityGrants();
22225
22302
  init_credential();
22226
22303
  init_claudeVersion();
22227
22304
  init_credentialCache();
@@ -22419,6 +22496,7 @@ function runCheck(params) {
22419
22496
  return {
22420
22497
  ...params.identityName === void 0 ? {} : { identityName: params.identityName },
22421
22498
  identitySource: params.identitySource,
22499
+ ...params.borrowedLogins === void 0 || params.borrowedLogins.length === 0 ? {} : { borrowedLogins: params.borrowedLogins },
22422
22500
  ...params.poolPick === void 0 ? {} : { poolPick: params.poolPick },
22423
22501
  ...params.configProfileName === void 0 ? {} : { configProfileName: params.configProfileName },
22424
22502
  configProfileSource: params.configProfileSource,
@@ -22445,6 +22523,9 @@ function buildProviderReachability(provider, probe) {
22445
22523
  function formatCheckReport(report) {
22446
22524
  const lines = [];
22447
22525
  lines.push(`Identity: ${report.identityName ?? "(none)"} (${report.identitySource})`);
22526
+ for (const loan of report.borrowedLogins ?? []) {
22527
+ lines.push(`Borrows the login of ${loan.from} for ${loan.features.join(", ")}.`);
22528
+ }
22448
22529
  if (report.poolPick !== void 0) {
22449
22530
  const top = report.poolPick.candidates.find((candidate) => candidate.identity === report.poolPick?.pick);
22450
22531
  lines.push(`Pool: ${report.poolPick.pool}${top === void 0 ? ", every member is refused right now" : `, would pick ${top.identity} (${top.reasons.join("; ")})`}`);
@@ -22539,6 +22620,7 @@ function checkReportToJson(report) {
22539
22620
  const decisions = [...report.resolved.decisions.values()].sort((a, b) => a.relPath < b.relPath ? -1 : a.relPath > b.relPath ? 1 : 0);
22540
22621
  return {
22541
22622
  identity: { name: report.identityName ?? null, source: report.identitySource },
22623
+ ...report.borrowedLogins === void 0 ? {} : { borrowedLogins: report.borrowedLogins },
22542
22624
  ...report.poolPick === void 0 ? {} : { pool: report.poolPick },
22543
22625
  configProfile: { name: report.configProfileName ?? null, source: report.configProfileSource },
22544
22626
  layers: report.resolved.assembled.layers.map((layer) => ({ id: layer.id, kind: layer.kind, source: layer.source })),
@@ -22619,6 +22701,7 @@ function collectCheckReport(params) {
22619
22701
  ...identityDecision.name === void 0 ? {} : { identityName: identityDecision.name },
22620
22702
  ...identityId === void 0 ? {} : { identityId },
22621
22703
  identitySource: identityDecision.source,
22704
+ ...identityId === void 0 ? {} : { borrowedLogins: loginsLentTo(listIdentities(paths).flatMap((entry) => entry.problem === void 0 ? [{ id: entry.id, name: entry.name, grants: entry.identity.grants }] : []), identityId) },
22622
22705
  ...poolPick === void 0 ? {} : { poolPick },
22623
22706
  ...configProfileDecision.name === void 0 ? {} : { configProfileName: configProfileDecision.name },
22624
22707
  configProfileSource: configProfileDecision.source,
@@ -24330,11 +24413,20 @@ function runDoctor(params) {
24330
24413
  `${entry.name} is valid and authenticates with ${authenticatesWith}${cache.text}.`,
24331
24414
  entry.name
24332
24415
  );
24416
+ const keychainItem = params.platform === "darwin" && params.run !== void 0 ? keychainHasItem(params.run, entry.farmRoot) : void 0;
24417
+ for (const grant of validated3.data.grants ?? []) {
24418
+ if (!identityIds.has(grant.to)) {
24419
+ push("identity", "warn", `${entry.name} lends its login to identity id "${grant.to}", which does not exist. Remove that entry from its identity.json.`, entry.name);
24420
+ }
24421
+ }
24422
+ if (validated3.data.grants !== void 0 && keychainItem !== true && !entry.credentialsFilePresent) {
24423
+ push("sign-in", "warn", `${entry.name} lends its login but has none stored, so every borrowed request fails. Run \`agent-shim run @${entry.name}\` and sign in.`, entry.name);
24424
+ }
24333
24425
  const standing = credential !== void 0 ? "uses a credential block" : identityProvider !== void 0 ? `exists for provider "${identityProvider}"` : "is signed in";
24334
24426
  const signIn = decideSignIn({
24335
24427
  hasCredentialBlock: credential !== void 0,
24336
24428
  provider: identityProvider,
24337
- keychainItem: params.platform === "darwin" && params.run !== void 0 ? keychainHasItem(params.run, entry.farmRoot) : void 0,
24429
+ keychainItem,
24338
24430
  credentialsFile: entry.credentialsFilePresent,
24339
24431
  platform: params.platform
24340
24432
  });
@@ -24905,7 +24997,8 @@ function identityWriteView(identity) {
24905
24997
  ...identity.provider === void 0 ? {} : { provider: identity.provider },
24906
24998
  allowAmbientCredential: identity.allowAmbientCredential,
24907
24999
  ...identity.credential === void 0 ? {} : { credential: summariseCredential(identity.credential) },
24908
- ...identity.anchors === void 0 ? {} : { anchors: identity.anchors }
25000
+ ...identity.anchors === void 0 ? {} : { anchors: identity.anchors },
25001
+ ...identity.grants === void 0 ? {} : { grants: identity.grants }
24909
25002
  };
24910
25003
  }
24911
25004
 
@@ -24978,7 +25071,9 @@ var IdentityValueSchema = z43.strictObject({
24978
25071
  provider: z43.string().optional(),
24979
25072
  allowAmbientCredential: z43.boolean(),
24980
25073
  credential: CredentialSummarySchema2.optional(),
24981
- anchors: z43.array(AnchorSchema).optional()
25074
+ anchors: z43.array(AnchorSchema).optional(),
25075
+ /** Read only here: a grant is made and revoked from the command line alone, so a program driving the door cannot widen what it may reach. */
25076
+ grants: z43.array(IdentityGrantSchema).optional()
24982
25077
  });
24983
25078
  var ProfileValueSchema = ConfigProfileSchema.omit({ $schema: true });
24984
25079
  var ProviderValueSchema = z43.strictObject({
@@ -29046,6 +29141,7 @@ export {
29046
29141
  getRcSessionContextUsage,
29047
29142
  getRcSessionMcpStatus,
29048
29143
  getRcSessionUsage,
29144
+ grantIdentityLogin,
29049
29145
  headroomSocketTarget,
29050
29146
  identityExists,
29051
29147
  identityIdOf,
@@ -29141,6 +29237,7 @@ export {
29141
29237
  resolveLayoutPaths,
29142
29238
  resolveSupervisorConfig,
29143
29239
  resyncFarm,
29240
+ revokeIdentityLogin,
29144
29241
  runCheck,
29145
29242
  runClaudeLaunch,
29146
29243
  runDoctor,