claude-use 11.80.0 → 11.82.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/README.md CHANGED
@@ -85,7 +85,7 @@ agent-shim <noun> <verb> [name] [options] # nouns: identity, profile, pool,
85
85
  agent-shim identity add <name> [--json]
86
86
  agent-shim identity list [--json]
87
87
  agent-shim identity show <name> [--json]
88
- agent-shim identity set <name> [--default-profile <profile> | --no-default-profile] [--provider <provider> | --no-provider] [--[no-]allow-ambient-credential] [--json]
88
+ agent-shim identity set <name> [--label <text> | --no-label] [--default-profile <profile> | --no-default-profile] [--provider <provider> | --no-provider] [--[no-]allow-ambient-credential] [--json]
89
89
  agent-shim identity set <name> [--credential <source>]... [--credential-target <bearer|apiKey|oauthToken>] [--no-credential] [--json]
90
90
  agent-shim identity set <name> [--anchor <days>@<HH:MM>[/<zone>]]... [--no-anchor] [--json]
91
91
  agent-shim identity remove <name> [--yes] [--json]
package/dist/cli.cjs CHANGED
@@ -25123,7 +25123,7 @@ function providerFilePath(directory, name, source) {
25123
25123
  }
25124
25124
  return import_node_path4.default.join(directory, `${name}.json`);
25125
25125
  }
25126
- var import_node_path4, FILESYSTEM_COMPONENT_BYTES, MAX_PID_DIGITS, UUID_CHARS, ATOMIC_WRITE_OVERHEAD_BYTES, FARM_SWAP_OVERHEAD_BYTES, MAX_NAME_BYTES, FILE_NAME_PATTERN, FILE_NAME, FILE_NAME_RULE, STORED_NAME_RULE, FileNameSchema, StoredNameSchema, UnsafeNameError, InvalidProviderNameError;
25126
+ var import_node_path4, FILESYSTEM_COMPONENT_BYTES, MAX_PID_DIGITS, UUID_CHARS, ATOMIC_WRITE_OVERHEAD_BYTES, FARM_SWAP_OVERHEAD_BYTES, MAX_NAME_BYTES, FILE_NAME_PATTERN, FILE_NAME, FILE_NAME_RULE, STORED_NAME_RULE, FileNameSchema, StoredNameSchema, LABEL_FORBIDDEN, IDENTITY_LABEL_RULE, IdentityLabelSchema, UnsafeNameError, InvalidProviderNameError;
25127
25127
  var init_names = __esm({
25128
25128
  "src/config/names.ts"() {
25129
25129
  "use strict";
@@ -25142,6 +25142,9 @@ var init_names = __esm({
25142
25142
  STORED_NAME_RULE = `must be non-empty, at most ${String(MAX_NAME_BYTES)} bytes, not "." or "..", and contain no path separator or NUL`;
25143
25143
  FileNameSchema = external_exports.string().min(1).regex(FILE_NAME, FILE_NAME_RULE);
25144
25144
  StoredNameSchema = external_exports.string().min(1).max(MAX_NAME_BYTES).refine(isStoredName, STORED_NAME_RULE);
25145
+ LABEL_FORBIDDEN = /[\p{Cc}\p{Zl}\p{Zp}]/u;
25146
+ IDENTITY_LABEL_RULE = `must be non-empty single-line text of at most ${String(MAX_NAME_BYTES)} characters, with no control characters and no leading or trailing whitespace`;
25147
+ IdentityLabelSchema = external_exports.string().min(1).max(MAX_NAME_BYTES).refine((label2) => label2 === label2.trim() && !LABEL_FORBIDDEN.test(label2), IDENTITY_LABEL_RULE);
25145
25148
  UnsafeNameError = class extends CliError {
25146
25149
  constructor(attemptedName, kind, rule = STORED_NAME_RULE, source) {
25147
25150
  super(`${source === void 0 ? "" : `${source}: `}${JSON.stringify(attemptedName)} is not a valid ${kind} name: a name ${rule}.`);
@@ -28385,7 +28388,7 @@ var init_schema = __esm({
28385
28388
  resumeOnLimit: external_exports.boolean().optional(),
28386
28389
  /** Whether a supervised session's context is compacted before its identity's quota is spent, so the resume on the next member writes a small context instead of a large one. Needs `resumeOnLimit`. Absent means false. */
28387
28390
  compactBeforeLimit: external_exports.boolean().optional(),
28388
- /** The share of a quota window, in whole percent, at which sessions are compacted. Absent means the launcher decides from what compacting every session on the member would cost against what its five-hour window has left. Needs `compactBeforeLimit`. */
28391
+ /** The share of a quota window, in whole percent, at which sessions are compacted. Absent means the launcher decides from what compacting every session on the member would cost against what its tightest quota window has left. Needs `compactBeforeLimit`. */
28389
28392
  compactAtUtilisation: CompactAtUtilisationSchema.optional()
28390
28393
  }).refine((pool) => pool.compactBeforeLimit !== true || pool.resumeOnLimit === true, { message: "compactBeforeLimit needs resumeOnLimit, since a session that is not moved has no cold cache to avoid", path: ["compactBeforeLimit"] }).refine((pool) => pool.compactAtUtilisation === void 0 || pool.compactBeforeLimit === true, { message: "compactAtUtilisation needs compactBeforeLimit", path: ["compactAtUtilisation"] });
28391
28394
  WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
@@ -28489,6 +28492,8 @@ var init_schema = __esm({
28489
28492
  IdentitySchema = external_exports.strictObject({
28490
28493
  $schema: external_exports.string().optional(),
28491
28494
  name: FileNameSchema,
28495
+ /** What the identity is for, in the person's words, drawn beside its name in `identity list` and `show`, the launch banner and the statusline. Display only: the name stays the key for lookup, paths, keychain service names and pools. */
28496
+ label: IdentityLabelSchema.optional(),
28492
28497
  defaultConfigProfile: StoredNameSchema.optional(),
28493
28498
  /** The provider this identity exists for: a launch on the identity routes through it unless `--provider`, `--no-provider` or a cascade layer's `launch.provider` says otherwise. Its sessions run on the provider's credential, so the identity needs no stored login. */
28494
28499
  provider: StoredNameSchema.optional(),
@@ -38280,7 +38285,7 @@ var init_package = __esm({
38280
38285
  "package.json"() {
38281
38286
  package_default = {
38282
38287
  name: "claude-use",
38283
- version: "11.80.0",
38288
+ version: "11.82.0",
38284
38289
  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.",
38285
38290
  license: "MIT",
38286
38291
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -38947,10 +38952,10 @@ function billedTokensOf(record2) {
38947
38952
  const usage = record2.usage;
38948
38953
  return (usage?.inputTokens ?? 0) + (usage?.cacheCreationInputTokens ?? 0) + (usage?.outputTokens ?? 0);
38949
38954
  }
38950
- function utilisationPerBilledToken(records) {
38955
+ function utilisationPerBilledToken(records, which) {
38951
38956
  const points = [];
38952
38957
  for (const record2 of records) {
38953
- const window = record2.rateLimitHeaders === void 0 ? void 0 : parseUnifiedRateLimit(record2.rateLimitHeaders)?.fiveHour;
38958
+ const window = record2.rateLimitHeaders === void 0 ? void 0 : parseUnifiedRateLimit(record2.rateLimitHeaders)?.[which];
38954
38959
  if (window?.utilization !== void 0 && window.resetsAt !== void 0) {
38955
38960
  points.push({ resetsAt: window.resetsAt, utilization: window.utilization, billed: billedTokensOf(record2) });
38956
38961
  }
@@ -39135,14 +39140,17 @@ function rankPool(input2) {
39135
39140
  }
39136
39141
  const { sticky: sticky2 } = input2;
39137
39142
  const warmHere = sticky2?.identity === candidate.identity && nowMs - Date.parse(sticky2.at) <= PROMPT_CACHE_TTL_MS;
39138
- if (input2.resuming && input2.resumeContextTokens !== void 0 && fiveHour !== void 0 && !warmHere) {
39139
- const perToken = utilisationPerBilledToken(assessment.member.records);
39143
+ const resumeTokens = input2.resumeContextTokens;
39144
+ if (input2.resuming && resumeTokens !== void 0 && !warmHere) {
39140
39145
  const committed = input2.committedContextTokens?.[candidate.identity] ?? 0;
39141
- const cost = perToken === void 0 ? void 0 : (input2.resumeContextTokens + committed) * perToken;
39142
- if (cost !== void 0 && cost > fiveHour.remaining) {
39143
- dryAfterMs.push(0);
39144
- const alongside = committed === 0 ? "" : ` (with ${String(committed)} tokens of other conversations already moving here)`;
39145
- drySpots.push(`resuming a ${String(input2.resumeContextTokens)}-token conversation here${alongside} would cost about ${percent(cost)} of the 5h window, which has ${percent(fiveHour.remaining)} left`);
39146
+ const alongside = committed === 0 ? "" : ` (with ${String(committed)} tokens of other conversations already moving here)`;
39147
+ for (const [name, label2, window] of [["fiveHour", "5h", fiveHour], ["sevenDay", "7d", sevenDay]]) {
39148
+ const perToken = window === void 0 ? void 0 : utilisationPerBilledToken(assessment.member.records, name);
39149
+ const cost = perToken === void 0 ? void 0 : (resumeTokens + committed) * perToken;
39150
+ if (window !== void 0 && cost !== void 0 && cost > window.remaining) {
39151
+ dryAfterMs.push(0);
39152
+ drySpots.push(`resuming a ${String(resumeTokens)}-token conversation here${alongside} would cost about ${percent(cost)} of the ${label2} window, which has ${percent(window.remaining)} left`);
39153
+ }
39146
39154
  }
39147
39155
  }
39148
39156
  if (drySpots.length === 0) {
@@ -68108,9 +68116,15 @@ function movedRows(facts) {
68108
68116
  }
68109
68117
  return [];
68110
68118
  }
68119
+ function identityText(facts) {
68120
+ if (facts.identity === void 0) {
68121
+ return "(none)";
68122
+ }
68123
+ return facts.identityLabel === void 0 ? facts.identity : `${facts.identity} (${facts.identityLabel})`;
68124
+ }
68111
68125
  function decisionRows(facts) {
68112
68126
  return [
68113
- { label: "identity", value: facts.identity ?? "(none)", detail: facts.identitySource },
68127
+ { label: "identity", value: identityText(facts), detail: facts.identitySource },
68114
68128
  ...facts.pool === void 0 ? [] : [
68115
68129
  {
68116
68130
  label: "pool",
@@ -70276,6 +70290,7 @@ function decideLaunch(params, readOnly) {
70276
70290
  return {
70277
70291
  parsedArgv,
70278
70292
  identityDecision,
70293
+ identityLabel: loadedIdentity?.config.label,
70279
70294
  poolPick,
70280
70295
  poolRanking,
70281
70296
  lastRanAs,
@@ -70306,6 +70321,7 @@ function prepareLaunch(params) {
70306
70321
  const rows = [
70307
70322
  ...decisionRows({
70308
70323
  identity: identityDecision.name,
70324
+ identityLabel: decided.identityLabel,
70309
70325
  identitySource: identityDecision.source,
70310
70326
  pool: poolPick,
70311
70327
  ranking: resolvedFlags.explain ? poolRanking : void 0,
@@ -116668,6 +116684,12 @@ function setIdentityProvider(paths, identityName, providerName) {
116668
116684
  }
116669
116685
  return applyPatch(identityJsonPath(paths, identityName), IdentitySchema, { provider: providerName });
116670
116686
  }
116687
+ function setIdentityLabel(paths, identityName, label2) {
116688
+ if (!identityExists(paths, identityName)) {
116689
+ throw new IdentityNotFoundError(identityName);
116690
+ }
116691
+ return applyPatch(identityJsonPath(paths, identityName), IdentitySchema, { label: label2 });
116692
+ }
116671
116693
  function setAllowAmbientCredential(paths, identityName, allow) {
116672
116694
  if (!identityExists(paths, identityName)) {
116673
116695
  throw new IdentityNotFoundError(identityName);
@@ -117812,6 +117834,7 @@ function registerProfileCommand(program2, deps) {
117812
117834
  }
117813
117835
 
117814
117836
  // src/identityManager.ts
117837
+ init_names();
117815
117838
  init_providersStore();
117816
117839
  init_identity();
117817
117840
  init_realPorts();
@@ -117887,6 +117910,7 @@ function toIdentityView(paths, { entry, read }, sharesLoginWith) {
117887
117910
  active: entry.isActive,
117888
117911
  directory: import_node_path25.default.join(paths.identitiesDir, entry.name),
117889
117912
  ...entry.problem === void 0 ? {
117913
+ ...entry.identity.label === void 0 ? {} : { label: entry.identity.label },
117890
117914
  ...entry.identity.defaultConfigProfile === void 0 ? {} : { defaultConfigProfile: entry.identity.defaultConfigProfile },
117891
117915
  ...entry.identity.provider === void 0 ? {} : { provider: entry.identity.provider },
117892
117916
  allowAmbientCredential: entry.identity.allowAmbientCredential,
@@ -117914,11 +117938,12 @@ function formatIdentityLine(entry, view) {
117914
117938
  if (entry.problem !== void 0) {
117915
117939
  return `${marker}${entry.name} [unreadable: ${entry.problem}]${account}${accountProblem}`;
117916
117940
  }
117941
+ const label2 = entry.identity.label === void 0 ? "" : ` (label: ${entry.identity.label})`;
117917
117942
  const defaultProfile = entry.identity.defaultConfigProfile === void 0 ? "" : ` (default profile: ${entry.identity.defaultConfigProfile})`;
117918
117943
  const provider = entry.identity.provider === void 0 ? "" : ` (provider: ${entry.identity.provider})`;
117919
117944
  const ambient = entry.identity.allowAmbientCredential ? " [allows ambient credential]" : "";
117920
117945
  const credential = entry.identity.credential === void 0 ? "" : ` [credential ${describeCredential(entry.identity.credential)}]`;
117921
- return `${marker}${entry.name}${defaultProfile}${provider}${ambient}${credential}${account}${accountProblem}`;
117946
+ return `${marker}${entry.name}${label2}${defaultProfile}${provider}${ambient}${credential}${account}${accountProblem}`;
117922
117947
  }
117923
117948
  function registerIdentityCommand(program2, deps) {
117924
117949
  const { paths } = deps;
@@ -117990,6 +118015,7 @@ function registerIdentityCommand(program2, deps) {
117990
118015
  console.log(`Unreadable: ${view.problem}`);
117991
118016
  return;
117992
118017
  }
118018
+ console.log(`Label: ${view.label ?? "(none)"}`);
117993
118019
  console.log(`Default configuration profile: ${view.defaultConfigProfile ?? "(none)"}`);
117994
118020
  console.log(`Provider: ${view.provider ?? "(none)"}`);
117995
118021
  console.log(`Allows ambient credential: ${view.allowAmbientCredential === true ? "yes" : "no"}`);
@@ -117998,7 +118024,7 @@ function registerIdentityCommand(program2, deps) {
117998
118024
  }),
117999
118025
  ["agent-shim identity show work", "agent-shim identity show work --json"]
118000
118026
  );
118001
- const identitySet = identity.command("set <name>").description("Update an identity's settings.").option("--json", "Print the result as JSON.").option("--default-profile <profile>", "Configuration profile this identity uses when nothing more specific selects one.").option("--no-default-profile", "Clear this identity's default configuration profile.").option("--provider <provider>", "Provider this identity exists for: a launch on it routes through the provider unless a flag, directory rule or profile selects another, and doctor expects no stored login.").option("--no-provider", "Clear this identity's provider.").option("--allow-ambient-credential", "Allow this identity to launch even with an ambient credential env var set.").option("--no-allow-ambient-credential", "Disallow ambient credential env vars for this identity (the default).").option(
118027
+ const identitySet = identity.command("set <name>").description("Update an identity's settings.").option("--json", "Print the result as JSON.").option("--label <text>", "Free text shown beside this identity's name in `identity list` and `show`, the launch banner and the statusline. Display only: the name stays the key.").option("--no-label", "Clear this identity's label.").option("--default-profile <profile>", "Configuration profile this identity uses when nothing more specific selects one.").option("--no-default-profile", "Clear this identity's default configuration profile.").option("--provider <provider>", "Provider this identity exists for: a launch on it routes through the provider unless a flag, directory rule or profile selects another, and doctor expects no stored login.").option("--no-provider", "Clear this identity's provider.").option("--allow-ambient-credential", "Allow this identity to launch even with an ambient credential env var set.").option("--no-allow-ambient-credential", "Disallow ambient credential env vars for this identity (the default).").option(
118002
118028
  "--credential <source>",
118003
118029
  `Authenticate this identity from a token instead of its stored login, replacing any existing sources (repeatable, in the order tried): ${CREDENTIAL_SOURCE_SYNTAX}.`,
118004
118030
  collectCredentialSource
@@ -118018,16 +118044,25 @@ function registerIdentityCommand(program2, deps) {
118018
118044
  const { json: json2, ...options } = allOptions;
118019
118045
  if (Object.entries(allOptions).every(([key, value2]) => key === "json" || value2 === void 0)) {
118020
118046
  throw new UsageError(
118021
- "Nothing to change: pass --default-profile, --no-default-profile, --provider, --no-provider, --allow-ambient-credential, --no-allow-ambient-credential, --credential, --no-credential, --credential-target, --anchor, --no-anchor or a --credential-cache option."
118047
+ "Nothing to change: pass --label, --no-label, --default-profile, --no-default-profile, --provider, --no-provider, --allow-ambient-credential, --no-allow-ambient-credential, --credential, --no-credential, --credential-target, --anchor, --no-anchor or a --credential-cache option."
118022
118048
  );
118023
118049
  }
118024
118050
  if (!identityExists(paths, name)) {
118025
118051
  throw new IdentityNotFoundError(name);
118026
118052
  }
118053
+ const label2 = typeof options.label === "string" ? IdentityLabelSchema.safeParse(options.label) : void 0;
118054
+ if (label2?.success === false) {
118055
+ throw new UsageError(`Identity label ${JSON.stringify(options.label)} ${IDENTITY_LABEL_RULE}.`);
118056
+ }
118027
118057
  if (typeof options.provider === "string") {
118028
118058
  requireProviderExists(paths, options.provider);
118029
118059
  }
118030
118060
  const messages = [];
118061
+ if (options.label !== void 0) {
118062
+ const labelText = options.label === false ? void 0 : options.label;
118063
+ setIdentityLabel(paths, name, labelText);
118064
+ messages.push(labelText === void 0 ? `Identity "${name}" no longer has a label.` : `Identity "${name}" is now labelled ${JSON.stringify(labelText)}.`);
118065
+ }
118031
118066
  if (options.defaultProfile !== void 0) {
118032
118067
  const profileName = options.defaultProfile === false ? void 0 : options.defaultProfile;
118033
118068
  if (profileName !== void 0) {
@@ -118072,6 +118107,7 @@ function registerIdentityCommand(program2, deps) {
118072
118107
  });
118073
118108
  }),
118074
118109
  [
118110
+ 'agent-shim identity set work --label "Example Org"',
118075
118111
  "agent-shim identity set work --default-profile client-acme",
118076
118112
  "agent-shim identity set minimax --provider minimax",
118077
118113
  "agent-shim identity set work --allow-ambient-credential",
@@ -120731,7 +120767,11 @@ function reasonNotToOpen(identity, snapshot, nowMs) {
120731
120767
  if (five?.resetsAtMs !== void 0) {
120732
120768
  return `a five-hour window is already open, resetting in ${formatAge(five.resetsAtMs - nowMs)}`;
120733
120769
  }
120734
- return refusalReason(identity, snapshot, nowMs);
120770
+ const refusal2 = refusalReason(identity, snapshot, nowMs);
120771
+ if (refusal2 !== void 0 || five !== void 0) {
120772
+ return refusal2;
120773
+ }
120774
+ return "it reports a seven-day window and no five-hour one, so there is no five-hour window to anchor";
120735
120775
  }
120736
120776
  async function runWindowKeeper(ports) {
120737
120777
  const nowMs = ports.nowMs();
@@ -123277,6 +123317,7 @@ var import_node_fs20 = __toESM(require("node:fs"), 1);
123277
123317
  var import_node_path47 = __toESM(require("node:path"), 1);
123278
123318
  init_signIn();
123279
123319
  init_identityAccounts();
123320
+ init_read();
123280
123321
  init_load();
123281
123322
  init_unrecognisedKeys();
123282
123323
  init_schema();
@@ -123571,6 +123612,82 @@ function describeSharedLoginMembers(poolName, shared) {
123571
123612
  return `Pool "${poolName}" lists ${joinNames(shared.members)}, which hold the same login${holder === void 0 ? "" : ` (${holder})`}, so they share one quota window. A launch ranks them as one candidate and never fails over from one to another; keep one of them in the pool.`;
123572
123613
  }
123573
123614
 
123615
+ // src/poolWindowReads.ts
123616
+ init_schema();
123617
+ init_identity();
123618
+ init_conditions();
123619
+ init_middleware();
123620
+ init_rateLimit();
123621
+ var WINDOW_NAMES = ["fiveHour", "sevenDay", "extraUsage"];
123622
+ var WINDOW_PROSE = { fiveHour: "five-hour", sevenDay: "seven-day", extraUsage: "extra-usage" };
123623
+ var WINDOW_FACTS = ["remaining", "utilization", "hoursUntilReset"];
123624
+ var DERIVED_FACTS = [{ key: "quota.burnPerHour", window: "fiveHour" }];
123625
+ function receivedWindows(snapshot) {
123626
+ const unified = snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
123627
+ if (unified === void 0) {
123628
+ return void 0;
123629
+ }
123630
+ return /* @__PURE__ */ new Set([...unified.fiveHour === void 0 ? [] : ["fiveHour"], ...unified.sevenDay === void 0 ? [] : ["sevenDay"], ...soleOverageWindow(unified) === void 0 ? [] : ["extraUsage"]]);
123631
+ }
123632
+ function conditionReads(when) {
123633
+ const direct = WINDOW_NAMES.flatMap((window) => WINDOW_FACTS.some((fact) => referencesFact(when, `quota.${window}.${fact}`)) ? [{ window, reference: `quota.${window}` }] : []);
123634
+ const derived2 = DERIVED_FACTS.flatMap(({ key, window }) => referencesFact(when, key) ? [{ window, reference: key }] : []);
123635
+ return [...direct, ...derived2];
123636
+ }
123637
+ function identitiesOf(selector, pools, visited = /* @__PURE__ */ new Set()) {
123638
+ const nested = poolNameOf(selector);
123639
+ if (nested === void 0) {
123640
+ return [selector];
123641
+ }
123642
+ const pool = pools[nested];
123643
+ if (pool === void 0 || visited.has(nested)) {
123644
+ return [];
123645
+ }
123646
+ visited.add(nested);
123647
+ return [...new Set(pool.identities.flatMap((member) => identitiesOf(poolMemberIdentity(member), pools, visited)))];
123648
+ }
123649
+ function poolWindowReadFindings(pools, windowsOf2) {
123650
+ const findings = [];
123651
+ for (const [poolName, pool] of Object.entries(pools)) {
123652
+ for (const member of pool.identities) {
123653
+ if (typeof member === "string") {
123654
+ continue;
123655
+ }
123656
+ const reads = conditionReads(member.when);
123657
+ for (const identity of identitiesOf(member.identity, pools)) {
123658
+ const received = windowsOf2(identity);
123659
+ for (const { window, reference } of reads) {
123660
+ if (received !== void 0 && !received.has(window)) {
123661
+ findings.push({ subject: poolName, message: `Pool "${poolName}" guards ${member.identity} with a condition that reads ${reference}, but ${identity} reports no ${WINDOW_PROSE[window]} window, so the condition is undecided for it and it always ranks last within its class.` });
123662
+ }
123663
+ }
123664
+ }
123665
+ }
123666
+ if (pool.compactBeforeLimit === true) {
123667
+ for (const identity of identitiesOf(`pool:${poolName}`, pools)) {
123668
+ const received = windowsOf2(identity);
123669
+ if (received !== void 0 && !received.has("fiveHour") && !received.has("sevenDay")) {
123670
+ findings.push({ subject: poolName, message: `Pool "${poolName}" compacts before the limit, but ${identity} reports no five-hour or seven-day window, so its sessions are never compacted before the limit.` });
123671
+ }
123672
+ }
123673
+ }
123674
+ }
123675
+ return findings;
123676
+ }
123677
+ function jobWindowReadFindings(jobs, pools, windowsOf2) {
123678
+ return Object.entries(jobs).flatMap(([jobName, job]) => {
123679
+ const { trigger, target } = job;
123680
+ if (!("beforeReset" in trigger)) {
123681
+ return [];
123682
+ }
123683
+ const identities = "pool" in target ? identitiesOf(`pool:${target.pool}`, pools) : identitiesOf(target.identity, pools);
123684
+ return identities.flatMap((identity) => {
123685
+ const received = windowsOf2(identity);
123686
+ return received === void 0 || received.has(trigger.beforeReset) ? [] : [{ subject: jobName, message: `Job "${jobName}" runs before the ${WINDOW_PROSE[trigger.beforeReset]} window resets, but ${identity} reports no ${WINDOW_PROSE[trigger.beforeReset]} window, so the job is skipped whenever it runs as ${identity}.` }];
123687
+ });
123688
+ });
123689
+ }
123690
+
123574
123691
  // src/doctorReport.ts
123575
123692
  init_extends();
123576
123693
  var DOCTOR_SEVERITIES = ["pass", "warn", "fail"];
@@ -123939,6 +124056,17 @@ function runDoctor(params) {
123939
124056
  reportedCycles.add(key);
123940
124057
  push("pool", "fail", `Pool cycle: ${chain.join(" -> ")}. A pool cannot nest itself, directly or through another pool.`, chain[0]);
123941
124058
  }
124059
+ const { usageSnapshots } = params;
124060
+ if (usageSnapshots !== void 0) {
124061
+ const windowsOf2 = (identityName) => receivedWindows(usageSnapshots[identityName]);
124062
+ for (const finding of poolWindowReadFindings(pools, windowsOf2)) {
124063
+ push("pool", "warn", finding.message, finding.subject);
124064
+ }
124065
+ const jobs = validatedGlobalConfig?.ok === true ? validatedGlobalConfig.data.jobs ?? {} : {};
124066
+ for (const finding of jobWindowReadFindings(jobs, pools, windowsOf2)) {
124067
+ push("global-config", "warn", finding.message, finding.subject);
124068
+ }
124069
+ }
123942
124070
  const selectionExists = (selector) => {
123943
124071
  const poolName = poolNameOf(selector);
123944
124072
  return poolName === void 0 ? validIdentityNames.has(selector) : poolName in pools;
@@ -124197,6 +124325,19 @@ function collectDoctorReport(params) {
124197
124325
  const identityPath = import_node_path47.default.join(farmRoot, "identity.json");
124198
124326
  return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs20.default.existsSync(credentialsFilePath(farmRoot)), account: readIdentityAccount(realFsPort, paths.identitiesDir, name)?.account };
124199
124327
  });
124328
+ const usageSnapshots = {};
124329
+ for (const name of identityNames) {
124330
+ try {
124331
+ const snapshot = readUsageSnapshot(realFsPort, paths.usageSnapshotsDir, name);
124332
+ if (snapshot !== void 0) {
124333
+ usageSnapshots[name] = snapshot;
124334
+ }
124335
+ } catch (error63) {
124336
+ if (!(error63 instanceof UsageSnapshotError)) {
124337
+ throw error63;
124338
+ }
124339
+ }
124340
+ }
124200
124341
  const profileNames = import_node_fs20.default.existsSync(paths.configProfilesDir) ? import_node_fs20.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
124201
124342
  const configProfiles = profileNames.map((name) => {
124202
124343
  const profilePath = import_node_path47.default.join(paths.configProfilesDir, `${name}.json`);
@@ -124240,6 +124381,7 @@ function collectDoctorReport(params) {
124240
124381
  chatgptSignIn: { path: paths.chatgptSignInFile, raw: realFsPort.readFileUtf8(paths.chatgptSignInFile) },
124241
124382
  installedClaudeVersions: realInstalledClaudeVersions(),
124242
124383
  identities,
124384
+ usageSnapshots,
124243
124385
  configProfiles,
124244
124386
  providers,
124245
124387
  providerAliases: readProviderAliases(paths),
@@ -133252,6 +133394,7 @@ init_providersStore();
133252
133394
  // src/frontdoor/configSchemas.ts
133253
133395
  init_zod();
133254
133396
  init_schema();
133397
+ init_names();
133255
133398
  init_statusline();
133256
133399
  var RemovalConfirmationSchema = external_exports.boolean();
133257
133400
  var CredentialWriteSchema = (targets) => external_exports.strictObject({
@@ -133277,6 +133420,7 @@ var mutationOutput = (kind, action) => external_exports.strictObject({ action: e
133277
133420
  var storedMutationOutput = (kind, action, value2) => external_exports.strictObject({ action: external_exports.literal(action), kind: external_exports.literal(kind), name: external_exports.string(), value: value2 });
133278
133421
  var IdentityValueSchema = external_exports.strictObject({
133279
133422
  name: external_exports.string(),
133423
+ label: external_exports.string().optional(),
133280
133424
  defaultConfigProfile: external_exports.string().optional(),
133281
133425
  provider: external_exports.string().optional(),
133282
133426
  allowAmbientCredential: external_exports.boolean(),
@@ -133297,6 +133441,8 @@ var ConfigNameInputSchema = external_exports.strictObject({ name: external_expor
133297
133441
  var ConfigIdentityAddOutputSchema = storedMutationOutput("identity", "created", IdentityValueSchema);
133298
133442
  var ConfigIdentitySetInputSchema = external_exports.strictObject({
133299
133443
  name: external_exports.string().min(1),
133444
+ /** The identity's display label; `false` clears it. */
133445
+ label: external_exports.union([IdentityLabelSchema, external_exports.literal(false)]).optional(),
133300
133446
  defaultConfigProfile: external_exports.union([external_exports.string().min(1), external_exports.literal(false)]).optional(),
133301
133447
  /** The provider the identity exists for; `false` clears it. */
133302
133448
  provider: external_exports.union([external_exports.string().min(1), external_exports.literal(false)]).optional(),
@@ -133443,6 +133589,7 @@ function identityValue(name, paths) {
133443
133589
  }
133444
133590
  return {
133445
133591
  name: identity.name,
133592
+ ...identity.label === void 0 ? {} : { label: identity.label },
133446
133593
  ...identity.defaultConfigProfile === void 0 ? {} : { defaultConfigProfile: identity.defaultConfigProfile },
133447
133594
  ...identity.provider === void 0 ? {} : { provider: identity.provider },
133448
133595
  allowAmbientCredential: identity.allowAmbientCredential,
@@ -133477,9 +133624,9 @@ function createConfigApiRouter(deps) {
133477
133624
  return { action: "created", kind: "identity", name: input2.name, value: identityValue(input2.name, paths) };
133478
133625
  })
133479
133626
  ),
133480
- set: route("/rest/config/identity/set", "Update an identity's default profile, provider, ambient-credential setting, credential or anchors").input(ConfigIdentitySetInputSchema).output(ConfigIdentitySetOutputSchema).handler(
133627
+ set: route("/rest/config/identity/set", "Update an identity's label, default profile, provider, ambient-credential setting, credential or anchors").input(ConfigIdentitySetInputSchema).output(ConfigIdentitySetOutputSchema).handler(
133481
133628
  ({ input: input2 }) => guarded(() => {
133482
- requireChange(input2.defaultConfigProfile !== void 0 || input2.provider !== void 0 || input2.allowAmbientCredential !== void 0 || input2.credential !== void 0 || input2.anchors !== void 0, "defaultConfigProfile, provider, allowAmbientCredential, credential or anchors");
133629
+ requireChange(input2.label !== void 0 || input2.defaultConfigProfile !== void 0 || input2.provider !== void 0 || input2.allowAmbientCredential !== void 0 || input2.credential !== void 0 || input2.anchors !== void 0, "label, defaultConfigProfile, provider, allowAmbientCredential, credential or anchors");
133483
133630
  if (!identityExists(paths, input2.name)) {
133484
133631
  throw new IdentityNotFoundError(input2.name);
133485
133632
  }
@@ -133489,6 +133636,9 @@ function createConfigApiRouter(deps) {
133489
133636
  if (typeof input2.provider === "string") {
133490
133637
  requireProviderExists(paths, input2.provider);
133491
133638
  }
133639
+ if (input2.label !== void 0) {
133640
+ setIdentityLabel(paths, input2.name, input2.label === false ? void 0 : input2.label);
133641
+ }
133492
133642
  if (input2.defaultConfigProfile !== void 0) {
133493
133643
  setDefaultConfigProfile(paths, input2.name, input2.defaultConfigProfile === false ? void 0 : input2.defaultConfigProfile);
133494
133644
  }
@@ -141027,6 +141177,7 @@ function enrichStatuslinePayload(params) {
141027
141177
  const account = clientEmail === void 0 ? params.account : void 0;
141028
141178
  let summary = {
141029
141179
  identity,
141180
+ identityLabel: params.identityLabel,
141030
141181
  provider: params.env.AGENT_SHIM_PROVIDER === void 0 || params.env.AGENT_SHIM_PROVIDER === "" ? void 0 : params.env.AGENT_SHIM_PROVIDER,
141031
141182
  providerAccountEmail: void 0,
141032
141183
  providerAccountSub: void 0,
@@ -142349,7 +142500,13 @@ function headroomSegment({ summary, t: t10 }) {
142349
142500
 
142350
142501
  // src/statusline/elements/header/identity.ts
142351
142502
  function identitySegment({ summary }) {
142352
- if (summary.identity !== void 0 && summary.provider !== void 0 && summary.identity !== summary.providerAccountEmail && summary.identity !== summary.loginAccountEmail) {
142503
+ if (summary.identity === void 0) {
142504
+ return void 0;
142505
+ }
142506
+ if (summary.identityLabel !== void 0) {
142507
+ return `${summary.identity} (${summary.identityLabel})`;
142508
+ }
142509
+ if (summary.provider !== void 0 && summary.identity !== summary.providerAccountEmail && summary.identity !== summary.loginAccountEmail) {
142353
142510
  return summary.identity;
142354
142511
  }
142355
142512
  return void 0;
@@ -145383,7 +145540,13 @@ function registerStatuslineCommand(program2, deps) {
145383
145540
  const identity = identityOf(process.env);
145384
145541
  let snapshot;
145385
145542
  let account;
145543
+ let identityLabel;
145386
145544
  if (identity !== void 0) {
145545
+ try {
145546
+ identityLabel = readIdentity(deps.paths, identity)?.label;
145547
+ } catch {
145548
+ identityLabel = void 0;
145549
+ }
145387
145550
  try {
145388
145551
  snapshot = readUsageSnapshot(realFarmFs, deps.paths.usageSnapshotsDir, identity);
145389
145552
  } catch {
@@ -145435,7 +145598,7 @@ function registerStatuslineCommand(program2, deps) {
145435
145598
  }
145436
145599
  }
145437
145600
  const clientPayload = parseClientPayload(payload);
145438
- const enrichParams = { payload, env: process.env, snapshot, account, providerName, nowMs, headroom, routedTarget, ...modelChoice === void 0 ? {} : { modelChoice } };
145601
+ const enrichParams = { payload, env: process.env, identityLabel, snapshot, account, providerName, nowMs, headroom, routedTarget, ...modelChoice === void 0 ? {} : { modelChoice } };
145439
145602
  const renderer = process.env.AGENT_SHIM_STATUSLINE_CMD;
145440
145603
  if (renderer !== void 0 && renderer !== "") {
145441
145604
  const child = (0, import_node_child_process9.spawn)("/bin/sh", ["-c", renderer], { stdio: ["pipe", "inherit", "inherit"] });
@@ -156470,7 +156633,7 @@ function membersOf(options) {
156470
156633
  }
156471
156634
  var RESUME_ON_LIMIT_DESCRIPTION = "Keep an interactive session of this pool going when its identity runs out of quota: the launcher stops it and resumes the same conversation under the next ranked member, on the same terminal.";
156472
156635
  var COMPACT_BEFORE_LIMIT_DESCRIPTION = "Compact each supervised session's context while its member can still afford it, so the resume on the next member writes a small context instead of a large one. Needs --resume-on-limit.";
156473
- var COMPACT_AT_UTILISATION_DESCRIPTION = "Compact when either quota window of the member passes this share, in whole percent. Without it, a session is compacted when compacting every session on its member would cost more than the five-hour window has left. Needs --compact-before-limit.";
156636
+ var COMPACT_AT_UTILISATION_DESCRIPTION = "Compact when either quota window of the member passes this share, in whole percent. Without it, a session is compacted when compacting every session on its member would cost more than the member's tightest quota window has left. Needs --compact-before-limit.";
156474
156637
  var PREFERENCE_DESCRIPTION = "How a launch picks a member: score (the default) picks the member whose remaining quota expires soonest; listed tries the members in the order the pool lists them, skipping any that is refused right now.";
156475
156638
  function registerPoolCommand(program2, deps) {
156476
156639
  const { paths } = deps;
@@ -156544,7 +156707,7 @@ function registerPoolCommand(program2, deps) {
156544
156707
  console.log("Resume on limit: yes");
156545
156708
  }
156546
156709
  if (entry.compactBeforeLimit === true) {
156547
- console.log(`Compact before limit: ${entry.compactAtUtilisation === void 0 ? "when compacting would cost more than the five-hour window has left" : `at ${String(entry.compactAtUtilisation)}% of a window`}`);
156710
+ console.log(`Compact before limit: ${entry.compactAtUtilisation === void 0 ? "when compacting would cost more than the member's tightest quota window has left" : `at ${String(entry.compactAtUtilisation)}% of a window`}`);
156548
156711
  }
156549
156712
  }),
156550
156713
  ["agent-shim pool show subs"]
@@ -158191,25 +158354,34 @@ var asPercent = (fraction) => `${String(Math.round(fraction * PERCENT6))}%`;
158191
158354
  function compactableTokens(state) {
158192
158355
  return state?.mark === "idle" && state.compacted !== true && state.contextTokens !== void 0 && state.contextTokens > 0 ? state.contextTokens : void 0;
158193
158356
  }
158194
- function triggerReason(input2) {
158357
+ function presentWindows(input2) {
158195
158358
  const unified = input2.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
158196
- const five = unified?.fiveHour === void 0 ? void 0 : effectiveWindow(unified.fiveHour, input2.nowMs);
158359
+ return [["fiveHour", "5h"], ["sevenDay", "7d"]].flatMap(([name, label2]) => {
158360
+ const recorded = unified?.[name];
158361
+ return recorded === void 0 ? [] : [{ name, label: label2, window: effectiveWindow(recorded, input2.nowMs) }];
158362
+ });
158363
+ }
158364
+ function triggerReason(input2) {
158365
+ const windows = presentWindows(input2);
158197
158366
  if (input2.atUtilisation !== void 0) {
158198
- const seven = unified?.sevenDay === void 0 ? void 0 : effectiveWindow(unified.sevenDay, input2.nowMs);
158199
- for (const [name, window] of [["5h", five], ["7d", seven]]) {
158200
- if (window?.utilization !== void 0 && window.utilization * PERCENT6 >= input2.atUtilisation) {
158201
- return `the ${name} window is at ${asPercent(window.utilization)}, past ${String(input2.atUtilisation)}%`;
158367
+ for (const { label: label2, window } of windows) {
158368
+ if (window.utilization !== void 0 && window.utilization * PERCENT6 >= input2.atUtilisation) {
158369
+ return `the ${label2} window is at ${asPercent(window.utilization)}, past ${String(input2.atUtilisation)}%`;
158202
158370
  }
158203
158371
  }
158204
158372
  return void 0;
158205
158373
  }
158206
- const perToken = utilisationPerBilledToken(input2.records());
158207
- if (five?.utilization === void 0 || perToken === void 0) {
158374
+ const measured = windows.flatMap(({ name, label: label2, window }) => window.utilization === void 0 ? [] : [{ name, label: label2, remaining: Math.max(0, 1 - window.utilization) }]);
158375
+ const tightest = measured.reduce((least, entry) => least === void 0 || entry.remaining < least.remaining ? entry : least, void 0);
158376
+ if (tightest === void 0) {
158377
+ return void 0;
158378
+ }
158379
+ const perToken = utilisationPerBilledToken(input2.records(), tightest.name);
158380
+ if (perToken === void 0) {
158208
158381
  return void 0;
158209
158382
  }
158210
- const remaining = Math.max(0, 1 - five.utilization);
158211
158383
  const cost = input2.sessions.reduce((sum2, session) => sum2 + (session.state?.contextTokens ?? 0), 0) * perToken;
158212
- return remaining < cost ? `the 5h window has ${asPercent(remaining)} left, and compacting every session on this member would use about ${asPercent(cost)}` : void 0;
158384
+ return tightest.remaining < cost ? `the ${tightest.label} window has ${asPercent(tightest.remaining)} left, and compacting every session on this member would use about ${asPercent(cost)}` : void 0;
158213
158385
  }
158214
158386
  function decideCompaction(input2) {
158215
158387
  const own2 = input2.sessions.find((session) => session.sessionId === input2.sessionId);