claude-use 12.0.1 → 12.2.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
@@ -990,6 +990,8 @@ var init_schema = __esm({
990
990
  kind: z3.literal("http").optional(),
991
991
  displayName: z3.string().min(1),
992
992
  baseUrl: z3.url(),
993
+ /** How long opening a TCP connection to `baseUrl` may take before the provider counts as unreachable: the door's forwarding gives up and answers naming the provider, and `doctor`, `check` and a launch's probe are bounded by it. Defaults to `DEFAULT_PROVIDER_CONNECT_TIMEOUT_MS`. Bounds the connect only, never the wait for the answer. */
994
+ connectTimeoutMs: z3.int().positive().optional(),
993
995
  credential: ProviderCredentialSchema,
994
996
  env: ProviderEnvSchema.optional(),
995
997
  /** Extra models `/model` lists beside the ones the tier settings name. */
@@ -5245,6 +5247,23 @@ function identityIdResolver(identitiesDir, fs17) {
5245
5247
  return identityIdIn(records, name);
5246
5248
  };
5247
5249
  }
5250
+ function identityReader(identitiesDir, fs17) {
5251
+ const read = /* @__PURE__ */ new Map();
5252
+ const readOnce = (file) => {
5253
+ if (!read.has(file)) {
5254
+ read.set(file, fs17.readConfigFile(file));
5255
+ }
5256
+ return read.get(file);
5257
+ };
5258
+ const idOf = identityIdResolver(identitiesDir, { readdir: fs17.readdir, readConfigFile: readOnce });
5259
+ return {
5260
+ idOf,
5261
+ load: (name) => {
5262
+ const id = idOf(name);
5263
+ return id === void 0 ? void 0 : loadConfigFile(path15.join(identitiesDir, id, IDENTITY_FILE), IdentitySchema, readOnce)?.config;
5264
+ }
5265
+ };
5266
+ }
5248
5267
  function loadIdentity(identitiesDir, name, fs17) {
5249
5268
  if (!isFileName(name)) {
5250
5269
  throw new UnsafeNameError(name, "identity", FILE_NAME_RULE);
@@ -9216,7 +9235,8 @@ var init_identityAccounts = __esm({
9216
9235
  function candidateHeading(candidate) {
9217
9236
  const score = candidate.score === void 0 ? "" : ` score ${candidate.score.toFixed(2)}${candidate.scoreWindow === "fiveHour" ? " by 5h reset" : " by 7d reset"}`;
9218
9237
  const dry = candidate.feasible ? "" : " (5h would run dry)";
9219
- return `[${candidate.class}${score}]${dry}`;
9238
+ const onProvider = candidate.provider === void 0 ? "" : ` on provider ${candidate.provider}`;
9239
+ return `[${candidate.class}${score}]${dry}${onProvider}`;
9220
9240
  }
9221
9241
  function percent(fraction) {
9222
9242
  return `${String(Math.round(fraction * PERCENT))}%`;
@@ -9259,6 +9279,9 @@ function planOf(account) {
9259
9279
  }
9260
9280
  return { kind: "subscription", capacity: 1, recognised: BASE_TIER.test(tier), ...tierField };
9261
9281
  }
9282
+ function planOfProviderQuota(quota) {
9283
+ return planOf(quota?.level === void 0 ? void 0 : { organizationRateLimitTier: quota.level });
9284
+ }
9262
9285
  var PlanClassSchema, TIER_MULTIPLIER, ZERO_TIER, BASE_TIER;
9263
9286
  var init_plan2 = __esm({
9264
9287
  "src/usage/plan.ts"() {
@@ -9317,12 +9340,58 @@ var init_middleware = __esm({
9317
9340
  }
9318
9341
  });
9319
9342
 
9343
+ // src/usage/windowLengths.ts
9344
+ var MS_PER_HOUR2, HOURS_PER_DAY3, FIVE_HOURS, SEVEN_DAYS, FIVE_HOUR_WINDOW_MS, SEVEN_DAY_WINDOW_MS;
9345
+ var init_windowLengths = __esm({
9346
+ "src/usage/windowLengths.ts"() {
9347
+ "use strict";
9348
+ MS_PER_HOUR2 = 36e5;
9349
+ HOURS_PER_DAY3 = 24;
9350
+ FIVE_HOURS = 5;
9351
+ SEVEN_DAYS = 7;
9352
+ FIVE_HOUR_WINDOW_MS = FIVE_HOURS * MS_PER_HOUR2;
9353
+ SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY3 * MS_PER_HOUR2;
9354
+ }
9355
+ });
9356
+
9357
+ // src/usage/providerWindows.ts
9358
+ function bindingWindow(quota, periodMs) {
9359
+ const same = quota.windows.filter((window) => window.periodMs === periodMs);
9360
+ const tightest = same.reduce((binding, window) => binding === void 0 || window.utilization > binding.utilization ? window : binding, void 0);
9361
+ if (tightest === void 0) {
9362
+ return void 0;
9363
+ }
9364
+ return { utilization: tightest.utilization, ...tightest.resetsAt === void 0 ? {} : { resetsAt: tightest.resetsAt }, status: tightest.utilization >= 1 ? "rejected" : "allowed" };
9365
+ }
9366
+ function unifiedFromQuota(quota) {
9367
+ const fiveHour = bindingWindow(quota, FIVE_HOUR_WINDOW_MS);
9368
+ const sevenDay = bindingWindow(quota, SEVEN_DAY_WINDOW_MS);
9369
+ return fiveHour === void 0 && sevenDay === void 0 ? void 0 : { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay } };
9370
+ }
9371
+ function rankingWindowsOf(provider, state) {
9372
+ const recorded = state?.rateLimit;
9373
+ if (provider === void 0) {
9374
+ return recorded?.unified === void 0 ? void 0 : { unified: recorded.unified, observedAt: recorded.observedAt };
9375
+ }
9376
+ if (recorded?.unified !== void 0 && (recorded.unified.fiveHour !== void 0 || recorded.unified.sevenDay !== void 0)) {
9377
+ return { unified: recorded.unified, observedAt: recorded.observedAt };
9378
+ }
9379
+ const pulled = state?.quota === void 0 ? void 0 : unifiedFromQuota(state.quota);
9380
+ return state?.quota === void 0 || pulled === void 0 ? void 0 : { unified: pulled, observedAt: state.quota.observedAt };
9381
+ }
9382
+ var init_providerWindows = __esm({
9383
+ "src/usage/providerWindows.ts"() {
9384
+ "use strict";
9385
+ init_windowLengths();
9386
+ }
9387
+ });
9388
+
9320
9389
  // src/usage/quotaFacts.ts
9321
9390
  function windowFacts(window, nowMs) {
9322
9391
  if (window?.utilization === void 0 || window.resetsAt === void 0) {
9323
9392
  return void 0;
9324
9393
  }
9325
- return { remaining: Math.max(0, 1 - window.utilization), utilization: window.utilization, hoursUntilReset: Math.max(0, (Date.parse(window.resetsAt) - nowMs) / MS_PER_HOUR2) };
9394
+ return { remaining: Math.max(0, 1 - window.utilization), utilization: window.utilization, hoursUntilReset: Math.max(0, (Date.parse(window.resetsAt) - nowMs) / MS_PER_HOUR3) };
9326
9395
  }
9327
9396
  function quotaFactsOf(unified, nowMs) {
9328
9397
  const fiveHour = windowFacts(unified?.fiveHour, nowMs);
@@ -9330,19 +9399,16 @@ function quotaFactsOf(unified, nowMs) {
9330
9399
  const extraUsage = windowFacts(unified === void 0 ? void 0 : soleOverageWindow(unified), nowMs);
9331
9400
  return { ...fiveHour === void 0 ? {} : { fiveHour }, ...sevenDay === void 0 ? {} : { sevenDay }, ...extraUsage === void 0 ? {} : { extraUsage } };
9332
9401
  }
9333
- var MS_PER_HOUR2;
9402
+ var MS_PER_HOUR3;
9334
9403
  var init_quotaFacts = __esm({
9335
9404
  "src/usage/quotaFacts.ts"() {
9336
9405
  "use strict";
9337
9406
  init_rateLimit();
9338
- MS_PER_HOUR2 = 36e5;
9407
+ MS_PER_HOUR3 = 36e5;
9339
9408
  }
9340
9409
  });
9341
9410
 
9342
9411
  // src/usage/pick.ts
9343
- function unifiedOf(state) {
9344
- return state?.rateLimit?.unified;
9345
- }
9346
9412
  function limitBlockedUntil(state, nowMs) {
9347
9413
  const limit = state?.lastLimit;
9348
9414
  if (state === void 0 || limit === void 0) {
@@ -9432,6 +9498,10 @@ function assessRefusedNested(member, nested, nowMs) {
9432
9498
  };
9433
9499
  }
9434
9500
  function assess(member, nowMs) {
9501
+ const assessment = assessMember(member, nowMs);
9502
+ return member.provider === void 0 ? assessment : { ...assessment, candidate: { ...assessment.candidate, provider: member.provider } };
9503
+ }
9504
+ function assessMember(member, nowMs) {
9435
9505
  if (member.sameLoginAs !== void 0) {
9436
9506
  return { candidate: { identity: member.identity, class: "ineligible", plan: planOf(member.account), reasons: [`same login as ${member.sameLoginAs}`] } };
9437
9507
  }
@@ -9445,22 +9515,43 @@ function assess(member, nowMs) {
9445
9515
  const assessment = assessIdentity(member, nowMs);
9446
9516
  return { ...assessment, candidate: { ...assessment.candidate, reasons: [`picked by pool "${nested.pool}"`, ...nested.reasons] } };
9447
9517
  }
9518
+ function sliceOf(member) {
9519
+ return member.snapshot?.providers[member.provider ?? ANTHROPIC_PROVIDER];
9520
+ }
9521
+ function assessProviderWithoutWindows(member, provider, state, base, planReasons, nowMs) {
9522
+ const blockedUntil = limitBlockedUntil(state, nowMs);
9523
+ if (blockedUntil !== void 0) {
9524
+ return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...planReasons] } };
9525
+ }
9526
+ if (base.plan.kind === "pay-per-use") {
9527
+ return { candidate: { ...base, class: "pay-per-use", usageUnrecorded: true, reasons: [...planReasons, `provider ${provider} reports no plan windows, so its spend is not tracked`] } };
9528
+ }
9529
+ const why = state === void 0 ? `no usage recorded for provider ${provider} yet, so its quota is unknown` : `provider ${provider} reports no plan windows, so its quota is unknown`;
9530
+ return { candidate: { ...base, class: "unknown", reasons: [why, ...planReasons] } };
9531
+ }
9448
9532
  function assessIdentity(member, nowMs) {
9449
- const plan = planOf(member.account);
9533
+ const state = sliceOf(member);
9534
+ const plan = member.provider === void 0 ? planOf(member.account) : planOfProviderQuota(state?.quota);
9450
9535
  const planReasons = plan.kind === "pay-per-use" ? ["billed by use (no plan allowance)"] : plan.recognised ? [`${String(plan.capacity)}x plan`] : [`plan tier ${plan.tier === void 0 ? "not known" : `"${plan.tier}" not recognised`}, counted as 1x`];
9451
9536
  const base = { identity: member.identity, plan };
9452
9537
  if (member.readError !== void 0) {
9453
9538
  return { candidate: { ...base, class: "unknown", reasons: [`usage state unreadable: ${member.readError}`, ...planReasons] } };
9454
9539
  }
9455
- const state = member.snapshot?.providers[ANTHROPIC_PROVIDER];
9456
- const unified = unifiedOf(state);
9457
- if (member.snapshot === void 0 || state === void 0 || unified === void 0) {
9540
+ if (member.providerError !== void 0) {
9541
+ return { candidate: { ...base, class: "unknown", reasons: [`provider configuration unreadable: ${member.providerError}`, ...planReasons] } };
9542
+ }
9543
+ const windows = rankingWindowsOf(member.provider, state);
9544
+ if (member.snapshot === void 0 || state === void 0 || windows === void 0) {
9545
+ if (member.provider !== void 0) {
9546
+ return assessProviderWithoutWindows(member, member.provider, state, base, planReasons, nowMs);
9547
+ }
9458
9548
  if (plan.kind === "pay-per-use") {
9459
9549
  return { candidate: { ...base, class: "pay-per-use", usageUnrecorded: true, reasons: [...planReasons, "no usage recorded yet, so its spend is not tracked (turn on trackUsage for it)"] } };
9460
9550
  }
9461
9551
  return { candidate: { ...base, class: "unknown", reasons: ["no usage recorded yet, so its quota is unknown (turn on trackUsage for it)", ...planReasons] } };
9462
9552
  }
9463
- const observedAgo = state.rateLimit === void 0 ? "" : ` (last seen ${formatAge(nowMs - Date.parse(state.rateLimit.observedAt))} ago)`;
9553
+ const { unified } = windows;
9554
+ const observedAgo = ` (last seen ${formatAge(nowMs - Date.parse(windows.observedAt))} ago)`;
9464
9555
  const fiveHourWindow = unified.fiveHour;
9465
9556
  const sevenDayWindow = unified.sevenDay;
9466
9557
  const five = fiveHourWindow === void 0 ? void 0 : effectiveWindow(fiveHourWindow, nowMs);
@@ -9472,6 +9563,15 @@ function assessIdentity(member, nowMs) {
9472
9563
  const overageWindow = soleOverageWindow(unified);
9473
9564
  const overage = overageWindow === void 0 ? void 0 : effectiveWindow(overageWindow, nowMs);
9474
9565
  const overageReasons = overageWindow === void 0 || overage === void 0 ? [] : [describeWindow("extra usage", overageWindow, overage, nowMs)];
9566
+ if (member.provider !== void 0) {
9567
+ const spent = [
9568
+ { name: "5h", window: five },
9569
+ { name: "7d", window: seven }
9570
+ ].filter(({ window }) => window?.status === "rejected" && window.resetsAtMs === void 0).map(({ name }) => name);
9571
+ if (spent.length > 0) {
9572
+ return { candidate: { ...base, class: "ineligible", reasons: [`provider ${member.provider} ${spent.join(" and ")} window used in full with no reset time reported, so it is refused until it reports one`, ...windowReasons, ...planReasons] } };
9573
+ }
9574
+ }
9475
9575
  const blockedUntil = Math.max(
9476
9576
  windowBlockedUntil([five, seven, overage].flatMap((window) => window === void 0 ? [] : [window])) ?? 0,
9477
9577
  limitBlockedUntil(state, nowMs) ?? 0
@@ -9492,11 +9592,11 @@ function assessIdentity(member, nowMs) {
9492
9592
  }
9493
9593
  const remaining = Math.max(0, 1 - basis.window.utilization);
9494
9594
  const untilResetMs = basis.window.resetsAtMs === void 0 ? basis.windowMs : Math.max(basis.window.resetsAtMs - nowMs, MS_PER_SECOND5);
9495
- const weeklyScore = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR3);
9595
+ const weeklyScore = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR4);
9496
9596
  const fiveRemaining = five?.utilization === void 0 ? void 0 : Math.max(0, 1 - five.utilization);
9497
9597
  const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs, MS_PER_SECOND5);
9498
9598
  const ratio = windowRatio(member.records);
9499
- const fiveHourScore = basis.name === "sevenDay" && fiveRemaining !== void 0 && ratio !== void 0 ? Math.min(fiveRemaining * ratio, remaining) * plan.capacity / (fiveUntil / MS_PER_HOUR3) : void 0;
9599
+ const fiveHourScore = basis.name === "sevenDay" && fiveRemaining !== void 0 && ratio !== void 0 ? Math.min(fiveRemaining * ratio, remaining) * plan.capacity / (fiveUntil / MS_PER_HOUR4) : void 0;
9500
9600
  const fiveHourLeads = fiveHourScore !== void 0 && fiveHourScore > weeklyScore;
9501
9601
  const score = fiveHourLeads ? fiveHourScore : weeklyScore;
9502
9602
  const scoreWindow = fiveHourLeads ? "fiveHour" : basis.name;
@@ -9514,15 +9614,15 @@ function assessIdentity(member, nowMs) {
9514
9614
  };
9515
9615
  }
9516
9616
  function poolFactsOf(member, nowMs, resuming, sticky) {
9517
- const { fiveHour, sevenDay, extraUsage } = quotaFactsOf(member.snapshot?.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified, nowMs);
9617
+ const { fiveHour, sevenDay, extraUsage } = quotaFactsOf(rankingWindowsOf(member.provider, sliceOf(member))?.unified, nowMs);
9518
9618
  const burn = windowBurn(member.records, "fiveHour");
9519
9619
  return {
9520
9620
  ...fiveHour === void 0 ? {} : { fiveHour },
9521
9621
  ...sevenDay === void 0 ? {} : { sevenDay },
9522
9622
  ...extraUsage === void 0 ? {} : { extraUsage },
9523
- ...burn === void 0 ? {} : { burnPerHour: burn * MS_PER_HOUR3 },
9623
+ ...burn === void 0 ? {} : { burnPerHour: burn * MS_PER_HOUR4 },
9524
9624
  resuming,
9525
- ...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) / MS_PER_HOUR3) } : {}
9625
+ ...sticky?.identity === member.identity ? { lastPickHoursAgo: Math.max(0, (nowMs - Date.parse(sticky.at)) / MS_PER_HOUR4) } : {}
9526
9626
  };
9527
9627
  }
9528
9628
  function rankPool(input) {
@@ -9617,7 +9717,7 @@ function rankPool(input) {
9617
9717
  ...holdForReturn === void 0 ? {} : { holdForReturn }
9618
9718
  };
9619
9719
  }
9620
- var MS_PER_SECOND5, MS_PER_HOUR3, HOURS_PER_DAY3, FIVE_HOURS, PROMPT_CACHE_TTL_HOURS, SEVEN_DAYS, FIVE_HOUR_WINDOW_MS, SEVEN_DAY_WINDOW_MS, PROMPT_CACHE_TTL_MS, CLASS_ORDER;
9720
+ var MS_PER_SECOND5, MS_PER_HOUR4, PROMPT_CACHE_TTL_HOURS, PROMPT_CACHE_TTL_MS, CLASS_ORDER;
9621
9721
  var init_pick = __esm({
9622
9722
  "src/usage/pick.ts"() {
9623
9723
  "use strict";
@@ -9626,17 +9726,14 @@ var init_pick = __esm({
9626
9726
  init_plan2();
9627
9727
  init_middleware();
9628
9728
  init_preflight();
9729
+ init_providerWindows();
9629
9730
  init_quotaFacts();
9731
+ init_windowLengths();
9630
9732
  init_rateLimit();
9631
9733
  MS_PER_SECOND5 = 1e3;
9632
- MS_PER_HOUR3 = 36e5;
9633
- HOURS_PER_DAY3 = 24;
9634
- FIVE_HOURS = 5;
9734
+ MS_PER_HOUR4 = 36e5;
9635
9735
  PROMPT_CACHE_TTL_HOURS = 1;
9636
- SEVEN_DAYS = 7;
9637
- FIVE_HOUR_WINDOW_MS = FIVE_HOURS * MS_PER_HOUR3;
9638
- SEVEN_DAY_WINDOW_MS = SEVEN_DAYS * HOURS_PER_DAY3 * MS_PER_HOUR3;
9639
- PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS * MS_PER_HOUR3;
9736
+ PROMPT_CACHE_TTL_MS = PROMPT_CACHE_TTL_HOURS * MS_PER_HOUR4;
9640
9737
  CLASS_ORDER = { scored: 0, unknown: 1, "pay-per-use": 2, ineligible: 3 };
9641
9738
  }
9642
9739
  });
@@ -9773,7 +9870,7 @@ import { z as z19 } from "zod";
9773
9870
  function errorMessage(error) {
9774
9871
  return error instanceof Error ? error.message : String(error);
9775
9872
  }
9776
- function loadPoolMembers(fs17, paths, identities, nowMs, idOf) {
9873
+ function loadPoolMembers(fs17, paths, identities, nowMs, idOf, providerOf) {
9777
9874
  const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
9778
9875
  const log = readUsageLog(fs17, paths.usageLogDir, { sinceMs: windowStartMs });
9779
9876
  return identities.map((identity) => {
@@ -9781,14 +9878,20 @@ function loadPoolMembers(fs17, paths, identities, nowMs, idOf) {
9781
9878
  if (id === void 0) {
9782
9879
  return { identity, records: [] };
9783
9880
  }
9784
- const records = log.records.filter((record) => record.identity === id && record.provider === ANTHROPIC_PROVIDER && Date.parse(record.at) >= windowStartMs);
9881
+ const resolved = providerOf?.(identity);
9882
+ const provider = typeof resolved === "object" ? resolved.named : resolved;
9883
+ const providerField = {
9884
+ ...provider === void 0 ? {} : { provider },
9885
+ ...typeof resolved === "object" ? { providerError: resolved.reason } : {}
9886
+ };
9887
+ const records = log.records.filter((record) => record.identity === id && record.provider === (provider ?? ANTHROPIC_PROVIDER) && Date.parse(record.at) >= windowStartMs);
9785
9888
  try {
9786
9889
  const snapshot = readUsageSnapshot(fs17, paths.usageSnapshotsDir, id);
9787
9890
  const account = readAccountMetadata(fs17, paths.identitiesDir, id) ?? snapshot?.account;
9788
- return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
9891
+ return { identity, records, ...providerField, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
9789
9892
  } catch (error) {
9790
9893
  if (error instanceof UsageSnapshotError || error instanceof AccountMetadataError) {
9791
- return { identity, records, readError: errorMessage(error) };
9894
+ return { identity, records, ...providerField, readError: errorMessage(error) };
9792
9895
  }
9793
9896
  throw error;
9794
9897
  }
@@ -9798,7 +9901,7 @@ function snapshotAgeKey(member) {
9798
9901
  return member.snapshot === void 0 ? Number.NEGATIVE_INFINITY : Date.parse(member.snapshot.updatedAt);
9799
9902
  }
9800
9903
  function collapseSharedLogins(members) {
9801
- const groups = groupSharedLogins(members, (member) => member.nested === void 0 && member.account !== void 0 ? loginKeyOf(member.account) : void 0);
9904
+ const groups = groupSharedLogins(members, (member) => member.nested === void 0 && member.provider === void 0 && member.account !== void 0 ? loginKeyOf(member.account) : void 0);
9802
9905
  const representativeOf = /* @__PURE__ */ new Map();
9803
9906
  for (const group of groups) {
9804
9907
  const representative = group.reduce((freshest, member) => snapshotAgeKey(member) > snapshotAgeKey(freshest) ? member : freshest);
@@ -9828,7 +9931,7 @@ function rankNamedPool(input, poolName, stack, sticky) {
9828
9931
  const childStack = [...stack, poolName];
9829
9932
  const direct = pool.identities.filter((entry) => poolNameOf(poolMemberIdentity(entry)) === void 0);
9830
9933
  const missing = direct.filter((entry) => input.identityIdOf(poolMemberIdentity(entry)) === void 0).map((entry) => ({ pool: poolName, identity: poolMemberIdentity(entry) }));
9831
- const loaded = new Map(loadPoolMembers(input.fs, input.paths, direct.filter((entry) => input.identityIdOf(poolMemberIdentity(entry)) !== void 0).map(poolMemberIdentity), input.nowMs, input.identityIdOf).map((member) => [member.identity, member]));
9934
+ const loaded = new Map(loadPoolMembers(input.fs, input.paths, direct.filter((entry) => input.identityIdOf(poolMemberIdentity(entry)) !== void 0).map(poolMemberIdentity), input.nowMs, input.identityIdOf, input.providerOf).map((member) => [member.identity, member]));
9832
9935
  const members = [];
9833
9936
  for (const entry of pool.identities) {
9834
9937
  const nestedName = poolNameOf(poolMemberIdentity(entry));
@@ -9869,7 +9972,7 @@ function nestedMember(input, nestedName, childStack, sticky) {
9869
9972
  const nested = rankNamedPool(input, nestedName, childStack, sticky);
9870
9973
  const pick = nested.ranking.pick;
9871
9974
  if (pick !== void 0) {
9872
- const [member] = loadPoolMembers(input.fs, input.paths, [pick.identity], input.nowMs, input.identityIdOf);
9975
+ const [member] = loadPoolMembers(input.fs, input.paths, [pick.identity], input.nowMs, input.identityIdOf, input.providerOf);
9873
9976
  return { member: { ...member ?? { identity: pick.identity, records: [] }, nested: { kind: "pick", pool: nestedName, reasons: pick.reasons } }, missing: nested.missing };
9874
9977
  }
9875
9978
  const earliestReturn = nested.ranking.earliestReturn;
@@ -9964,6 +10067,7 @@ var init_poolPick = __esm({
9964
10067
  init_read();
9965
10068
  init_middleware();
9966
10069
  init_store2();
10070
+ init_windowLengths();
9967
10071
  PoolGraphError = class extends CliError {
9968
10072
  constructor(message) {
9969
10073
  super(message);
@@ -10736,7 +10840,7 @@ var init_package = __esm({
10736
10840
  "package.json"() {
10737
10841
  package_default = {
10738
10842
  name: "claude-use",
10739
- version: "12.0.1",
10843
+ version: "12.2.0",
10740
10844
  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.",
10741
10845
  license: "MIT",
10742
10846
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -10995,92 +11099,6 @@ var init_cascade = __esm({
10995
11099
  }
10996
11100
  });
10997
11101
 
10998
- // src/paths.ts
10999
- import fs9 from "node:fs";
11000
- import os5 from "node:os";
11001
- import path36 from "node:path";
11002
- function resolveAgentShimHome(env = process.env, home = os5.homedir(), isDirectory = isExistingDirectory) {
11003
- const fromEnv = env.AGENT_SHIM_HOME;
11004
- if (fromEnv !== void 0 && fromEnv !== "") {
11005
- return fromEnv;
11006
- }
11007
- const current = path36.join(home, HOME_DIRNAME);
11008
- const legacy = path36.join(home, LEGACY_HOME_DIRNAME);
11009
- return !isDirectory(current) && isDirectory(legacy) ? legacy : current;
11010
- }
11011
- function isExistingDirectory(candidate) {
11012
- return fs9.statSync(candidate, { throwIfNoEntry: false })?.isDirectory() ?? false;
11013
- }
11014
- function resolveClaudeHome() {
11015
- const fromEnv = process.env.AGENT_SHIM_CLAUDE_HOME;
11016
- if (fromEnv !== void 0 && fromEnv !== "") {
11017
- return fromEnv;
11018
- }
11019
- return path36.join(os5.homedir(), ".claude");
11020
- }
11021
- function buildLayoutPaths(root) {
11022
- return {
11023
- root,
11024
- identitiesDir: path36.join(root, "identities"),
11025
- configProfilesDir: path36.join(root, "config-profiles"),
11026
- providersDir: path36.join(root, "providers"),
11027
- providerAliasesFile: path36.join(root, "provider-aliases.json"),
11028
- directoryRulesFile: path36.join(root, "directory-rules.json"),
11029
- activeIdentityFile: path36.join(root, "active-identity"),
11030
- globalConfigFile: path36.join(root, "config.json"),
11031
- categoriesLocalFile: path36.join(root, "categories.local.json"),
11032
- claudeShimFile: path36.join(root, "claude-shim.json"),
11033
- headroomDir: path36.join(root, "headroom"),
11034
- headroomStateFile: path36.join(root, "headroom", "state.json"),
11035
- headroomRoutingFile: path36.join(root, "headroom", "routing.json"),
11036
- headroomLegacyStateFile: path36.join(root, "headroom", "state.v2.json"),
11037
- headroomAllowlistFile: path36.join(root, "headroom", "run", "allowlist.txt"),
11038
- headroomSocketDir: path36.join(root, "headroom", "run"),
11039
- headroomLockFile: path36.join(root, "headroom", "start.lock"),
11040
- headroomSessionsDir: path36.join(root, "headroom", "sessions"),
11041
- logsDir: path36.join(root, "logs"),
11042
- headroomLogPath: path36.join(root, "logs", "headroom.log"),
11043
- frontdoorDir: path36.join(root, "frontdoor"),
11044
- frontdoorCaDir: path36.join(root, "frontdoor", "ca"),
11045
- frontdoorCaCertFile: path36.join(root, "frontdoor", "ca", "ca.pem"),
11046
- frontdoorCaKeyFile: path36.join(root, "frontdoor", "ca", "ca.key"),
11047
- frontdoorCaBundlesDir: path36.join(root, "frontdoor", "ca", "bundles"),
11048
- chatgptSignInFile: path36.join(root, "codex", "chatgpt-sign-in.json"),
11049
- frontdoorStateFile: path36.join(root, "frontdoor", "state.json"),
11050
- frontdoorLockFile: path36.join(root, "frontdoor", "start.lock"),
11051
- frontdoorControlTokenFile: path36.join(root, "frontdoor", "control-token"),
11052
- frontdoorSessionsDir: path36.join(root, "frontdoor", "sessions"),
11053
- frontdoorDirectRecordsDir: path36.join(root, "frontdoor", "direct"),
11054
- frontdoorDrainingDir: path36.join(root, "frontdoor", "draining"),
11055
- frontdoorRcCredentialsDir: path36.join(root, "frontdoor", "rc-credentials"),
11056
- frontdoorLogPath: path36.join(root, "logs", "frontdoor.log"),
11057
- usageDir: path36.join(root, "usage"),
11058
- usageLogDir: path36.join(root, "usage", "log"),
11059
- usageSnapshotsDir: path36.join(root, "usage", "snapshots"),
11060
- statuslineDir: path36.join(root, "statusline"),
11061
- catalogueDir: path36.join(root, "catalogues"),
11062
- usagePicksFile: path36.join(root, "usage", "picks.json"),
11063
- usageAnchorsFile: path36.join(root, "usage", "anchors.json"),
11064
- usageJobsFile: path36.join(root, "usage", "jobs.json"),
11065
- jobLogsDir: path36.join(root, "logs", "jobs"),
11066
- identityRenamesDir: path36.join(root, "identity-renames"),
11067
- identityNameRenamesDir: path36.join(root, "identity-name-renames"),
11068
- launchesDir: path36.join(root, "launches"),
11069
- superviseDir: path36.join(root, "supervise"),
11070
- modelMovesDir: path36.join(root, "model-moves"),
11071
- mcpPermissionsFile: path36.join(root, "mcp", "permissions.json")
11072
- };
11073
- }
11074
- function resolveLayoutPaths() {
11075
- return buildLayoutPaths(resolveAgentShimHome());
11076
- }
11077
- var init_paths = __esm({
11078
- "src/paths.ts"() {
11079
- "use strict";
11080
- init_legacy();
11081
- }
11082
- });
11083
-
11084
11102
  // src/providerAliases.ts
11085
11103
  import { z as z26 } from "zod";
11086
11104
  function parseAliases(file, raw) {
@@ -11333,12 +11351,12 @@ var init_families = __esm({
11333
11351
  });
11334
11352
 
11335
11353
  // src/providersStore.ts
11336
- import fs10 from "node:fs";
11354
+ import fs9 from "node:fs";
11337
11355
  function providerJsonPath(paths, name) {
11338
11356
  return providerFilePath(paths.providersDir, name);
11339
11357
  }
11340
11358
  function providerExists(paths, name) {
11341
- return fs10.existsSync(providerJsonPath(paths, name));
11359
+ return fs9.existsSync(providerJsonPath(paths, name));
11342
11360
  }
11343
11361
  function requireProviderExists(paths, name) {
11344
11362
  const canonical = canonicalProviderName(name, (candidate) => providerExists(paths, candidate), () => readProviderAliases(paths));
@@ -11395,12 +11413,12 @@ function parseProviderFile(filePath, raw) {
11395
11413
  }
11396
11414
  function readProvider(paths, name) {
11397
11415
  const filePath = providerJsonPath(paths, name);
11398
- if (!fs10.existsSync(filePath)) {
11416
+ if (!fs9.existsSync(filePath)) {
11399
11417
  return void 0;
11400
11418
  }
11401
11419
  let raw;
11402
11420
  try {
11403
- raw = JSON.parse(fs10.readFileSync(filePath, "utf8"));
11421
+ raw = JSON.parse(fs9.readFileSync(filePath, "utf8"));
11404
11422
  } catch (error) {
11405
11423
  throw error instanceof SyntaxError ? new ConfigFileNotJsonError(filePath) : error;
11406
11424
  }
@@ -11416,7 +11434,7 @@ function reportInvalidProvider(name, message) {
11416
11434
  }
11417
11435
  function listProviders(paths, onInvalid = reportInvalidProvider) {
11418
11436
  const names = listProviderNames(
11419
- (dir) => fs10.readdirSync(dir),
11437
+ (dir) => fs9.readdirSync(dir),
11420
11438
  paths.providersDir
11421
11439
  );
11422
11440
  const result = [];
@@ -11485,6 +11503,9 @@ function addProvider(paths, name, input) {
11485
11503
  if (kind !== "http" && kind !== "router" && input.catalogue !== void 0) {
11486
11504
  throw new ProviderKindMismatchError("A model catalogue applies only to an http provider.");
11487
11505
  }
11506
+ if (kind !== "http" && input.connectTimeoutMs !== void 0) {
11507
+ throw new ProviderKindMismatchError("A connect timeout applies only to an http provider, the one kind that dials a base URL.");
11508
+ }
11488
11509
  if (kind !== "codex" && !isEmptyCodexConfig(input.codex)) {
11489
11510
  throw new ProviderKindMismatchError("Codex settings apply only to a codex provider (--kind codex).");
11490
11511
  }
@@ -11498,7 +11519,7 @@ function addProvider(paths, name, input) {
11498
11519
  ...input.pickerModels === void 0 || input.pickerModels.length === 0 ? {} : { pickerModels: input.pickerModels }
11499
11520
  };
11500
11521
  const parsed = ProviderSchema.safeParse(
11501
- kind === "router" ? { kind, displayName: input.displayName } : kind === "codex" ? { kind, ...shared, ...isEmptyCodexConfig(input.codex) ? {} : { codex: input.codex } } : kind === "antigravity" ? { kind, ...shared, ...isEmptyAntigravityConfig(input.antigravity) ? {} : { antigravity: input.antigravity } } : { ...shared, baseUrl: input.baseUrl, ...input.catalogue === void 0 ? {} : { catalogue: input.catalogue } }
11522
+ kind === "router" ? { kind, displayName: input.displayName } : kind === "codex" ? { kind, ...shared, ...isEmptyCodexConfig(input.codex) ? {} : { codex: input.codex } } : kind === "antigravity" ? { kind, ...shared, ...isEmptyAntigravityConfig(input.antigravity) ? {} : { antigravity: input.antigravity } } : { ...shared, baseUrl: input.baseUrl, ...input.connectTimeoutMs === void 0 ? {} : { connectTimeoutMs: input.connectTimeoutMs }, ...input.catalogue === void 0 ? {} : { catalogue: input.catalogue } }
11502
11523
  );
11503
11524
  if (!parsed.success) {
11504
11525
  throw new ConfigValidationError(providerJsonPath(paths, name), parsed.error.issues);
@@ -11530,6 +11551,9 @@ function updateProvider(paths, name, input) {
11530
11551
  if (isAntigravityProvider(existing) && input.baseUrl !== void 0) {
11531
11552
  throw new ProviderKindMismatchError(`Provider "${name}" is an antigravity provider, which has no base URL.`);
11532
11553
  }
11554
+ if (!isHttpProvider(existing) && input.connectTimeoutMs !== void 0) {
11555
+ throw new ProviderKindMismatchError(`Provider "${name}" is not an http provider; a connect timeout applies only to an http provider, the one kind that dials a base URL.`);
11556
+ }
11533
11557
  if ((isCodexProvider(existing) || isAntigravityProvider(existing)) && input.catalogue !== void 0 && input.catalogue !== false) {
11534
11558
  throw new ProviderKindMismatchError(`Provider "${name}" is not an http provider; a model catalogue applies only to an http provider.`);
11535
11559
  }
@@ -11570,7 +11594,8 @@ function updateProvider(paths, name, input) {
11570
11594
  candidate = { kind: "router", ...shared };
11571
11595
  } else {
11572
11596
  const catalogue = input.catalogue === void 0 ? existing.catalogue : input.catalogue === false ? void 0 : input.catalogue;
11573
- candidate = { ...existing, ...shared, catalogue, ...input.baseUrl === void 0 ? {} : { baseUrl: input.baseUrl } };
11597
+ const connectTimeoutMs = input.connectTimeoutMs === void 0 ? existing.connectTimeoutMs : input.connectTimeoutMs === false ? void 0 : input.connectTimeoutMs;
11598
+ candidate = { ...existing, ...shared, catalogue, connectTimeoutMs, ...input.baseUrl === void 0 ? {} : { baseUrl: input.baseUrl } };
11574
11599
  }
11575
11600
  const parsed = ProviderSchema.safeParse(candidate);
11576
11601
  if (!parsed.success) {
@@ -11583,7 +11608,7 @@ function removeProvider(paths, name) {
11583
11608
  if (!providerExists(paths, name)) {
11584
11609
  throw new ProviderNotFoundError(name);
11585
11610
  }
11586
- fs10.rmSync(providerJsonPath(paths, name));
11611
+ fs9.rmSync(providerJsonPath(paths, name));
11587
11612
  createRealCredentialCache(paths.root).remove("file", `provider ${name}`);
11588
11613
  }
11589
11614
  function cascadeProviderName(cascade, identityProvider) {
@@ -11595,13 +11620,19 @@ function cascadeProviderName(cascade, identityProvider) {
11595
11620
  }
11596
11621
  return name ?? identityProvider;
11597
11622
  }
11598
- function selectProvider(params) {
11623
+ function selectedProviderName(params) {
11599
11624
  const cliName = params.cliProvider !== void 0 && params.cliProvider !== "" ? params.cliProvider : void 0;
11600
11625
  const named = cliName ?? (params.cascade === void 0 ? params.identityProvider : cascadeProviderName(params.cascade, params.identityProvider));
11601
11626
  if (named === void 0) {
11602
11627
  return void 0;
11603
11628
  }
11604
- const name = canonicalProviderName(named, (candidate) => loadProvider(params.paths.providersDir, candidate, params.port) !== void 0, () => loadProviderAliases(params.paths.providerAliasesFile, params.port));
11629
+ return canonicalProviderName(named, (candidate) => loadProvider(params.paths.providersDir, candidate, params.port) !== void 0, () => loadProviderAliases(params.paths.providerAliasesFile, params.port));
11630
+ }
11631
+ function selectProvider(params) {
11632
+ const name = selectedProviderName(params);
11633
+ if (name === void 0) {
11634
+ return void 0;
11635
+ }
11605
11636
  const definition = loadProvider(params.paths.providersDir, name, params.port);
11606
11637
  if (definition === void 0) {
11607
11638
  const known = listProviderNames(params.port.readdir, params.paths.providersDir);
@@ -11698,50 +11729,390 @@ var init_providersStore = __esm({
11698
11729
  init_store();
11699
11730
  init_unrecognisedKeys();
11700
11731
  init_schema();
11701
- init_cliError();
11702
- init_providerAliases();
11703
- init_credential();
11704
- init_realCredentialCache();
11705
- init_walk();
11706
- init_families();
11707
- init_names();
11708
- ProviderNotFoundError = class extends CliError {
11709
- constructor(name) {
11710
- super(`No provider named "${name}". Run \`agent-shim provider add ${name}\` first.`);
11711
- this.name = name;
11712
- this.name = "ProviderNotFoundError";
11713
- }
11714
- name;
11715
- };
11716
- ProviderAlreadyExistsError = class extends CliError {
11717
- constructor(providerName) {
11718
- super(`A provider named "${providerName}" already exists.`);
11719
- this.providerName = providerName;
11720
- this.name = "ProviderAlreadyExistsError";
11721
- }
11722
- providerName;
11723
- };
11724
- LEGACY_PROVIDER_FIELDS = ["tokenEnv", "tokenCommand", "authScheme"];
11725
- LEGACY_ENV_CREDENTIAL_KEYS = Object.values(CREDENTIAL_TARGET_VARS);
11726
- LEGACY_LITERAL_PLACEHOLDER = "<the value of env.ANTHROPIC_AUTH_TOKEN>";
11727
- LegacyProviderFileError = class extends CliError {
11728
- constructor(filePath, conversion) {
11729
- super(
11730
- `${filePath} uses ${conversion.fields.join(", ")}, which a credential block replaced. Rewrite it as:
11731
- ` + JSON.stringify(conversion.replacement, null, 2)
11732
- );
11733
- this.filePath = filePath;
11734
- this.conversion = conversion;
11735
- this.name = "LegacyProviderFileError";
11736
- }
11737
- filePath;
11738
- conversion;
11739
- };
11740
- ProviderKindMismatchError = class extends UsageError {
11741
- constructor(message) {
11742
- super(message);
11743
- this.name = "ProviderKindMismatchError";
11744
- }
11732
+ init_cliError();
11733
+ init_providerAliases();
11734
+ init_credential();
11735
+ init_realCredentialCache();
11736
+ init_walk();
11737
+ init_families();
11738
+ init_names();
11739
+ ProviderNotFoundError = class extends CliError {
11740
+ constructor(name) {
11741
+ super(`No provider named "${name}". Run \`agent-shim provider add ${name}\` first.`);
11742
+ this.name = name;
11743
+ this.name = "ProviderNotFoundError";
11744
+ }
11745
+ name;
11746
+ };
11747
+ ProviderAlreadyExistsError = class extends CliError {
11748
+ constructor(providerName) {
11749
+ super(`A provider named "${providerName}" already exists.`);
11750
+ this.providerName = providerName;
11751
+ this.name = "ProviderAlreadyExistsError";
11752
+ }
11753
+ providerName;
11754
+ };
11755
+ LEGACY_PROVIDER_FIELDS = ["tokenEnv", "tokenCommand", "authScheme"];
11756
+ LEGACY_ENV_CREDENTIAL_KEYS = Object.values(CREDENTIAL_TARGET_VARS);
11757
+ LEGACY_LITERAL_PLACEHOLDER = "<the value of env.ANTHROPIC_AUTH_TOKEN>";
11758
+ LegacyProviderFileError = class extends CliError {
11759
+ constructor(filePath, conversion) {
11760
+ super(
11761
+ `${filePath} uses ${conversion.fields.join(", ")}, which a credential block replaced. Rewrite it as:
11762
+ ` + JSON.stringify(conversion.replacement, null, 2)
11763
+ );
11764
+ this.filePath = filePath;
11765
+ this.conversion = conversion;
11766
+ this.name = "LegacyProviderFileError";
11767
+ }
11768
+ filePath;
11769
+ conversion;
11770
+ };
11771
+ ProviderKindMismatchError = class extends UsageError {
11772
+ constructor(message) {
11773
+ super(message);
11774
+ this.name = "ProviderKindMismatchError";
11775
+ }
11776
+ };
11777
+ }
11778
+ });
11779
+
11780
+ // src/launcher/memberProvider.ts
11781
+ function unreadableFileReason(error) {
11782
+ if (error instanceof ConfigValidationError) {
11783
+ return `${error.filepath} is invalid`;
11784
+ }
11785
+ if (error instanceof ConfigFileNotJsonError) {
11786
+ return error.message.replace(/\.$/, "");
11787
+ }
11788
+ if (error instanceof LegacyProviderFileError) {
11789
+ return `${error.filePath} uses ${error.conversion.fields.join(", ")}, which a credential block replaced`;
11790
+ }
11791
+ return void 0;
11792
+ }
11793
+ function memberProviderResolver(params) {
11794
+ if (params.cliProvider === false) {
11795
+ return () => void 0;
11796
+ }
11797
+ const cliProvider = params.cliProvider;
11798
+ const identities = identityReader(params.paths.identitiesDir, params.fs);
11799
+ const cascades = /* @__PURE__ */ new Map();
11800
+ const cascadeOver = (baseConfigProfile) => {
11801
+ const cached = cascades.get(baseConfigProfile);
11802
+ if (cached !== void 0) {
11803
+ return cached;
11804
+ }
11805
+ const loaded = params.loadCascade(baseConfigProfile);
11806
+ cascades.set(baseConfigProfile, loaded);
11807
+ return loaded;
11808
+ };
11809
+ return (name) => {
11810
+ let declared;
11811
+ try {
11812
+ declared = identities.load(name);
11813
+ } catch (error) {
11814
+ if (!(error instanceof ConfigValidationError)) {
11815
+ throw error;
11816
+ }
11817
+ }
11818
+ const profile = decideConfigProfile({
11819
+ env: params.env,
11820
+ ...params.cliFlagConfigProfile === void 0 ? {} : { cliFlagConfigProfile: params.cliFlagConfigProfile },
11821
+ ...params.directoryRuleConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: params.directoryRuleConfigProfile },
11822
+ ...declared?.defaultConfigProfile === void 0 ? {} : { identityDefaultConfigProfile: declared.defaultConfigProfile },
11823
+ ...params.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: params.globalDefaultConfigProfile }
11824
+ });
11825
+ const flagged = cliProvider !== void 0 && cliProvider !== "" ? cliProvider : void 0;
11826
+ let named = flagged ?? declared?.provider;
11827
+ try {
11828
+ const cascade = cascadeOver(profile.name);
11829
+ named = flagged ?? cascadeProviderName(cascade, declared?.provider);
11830
+ return selectedProviderName({
11831
+ paths: params.paths,
11832
+ port: params.fs,
11833
+ ...cliProvider === void 0 ? {} : { cliProvider },
11834
+ cascade,
11835
+ ...declared?.provider === void 0 ? {} : { identityProvider: declared.provider }
11836
+ });
11837
+ } catch (error) {
11838
+ const reason = unreadableFileReason(error);
11839
+ if (reason === void 0) {
11840
+ throw error;
11841
+ }
11842
+ return { ...named === void 0 ? {} : { named }, reason };
11843
+ }
11844
+ };
11845
+ }
11846
+ var init_memberProvider = __esm({
11847
+ "src/launcher/memberProvider.ts"() {
11848
+ "use strict";
11849
+ init_load();
11850
+ init_providersStore();
11851
+ init_identity();
11852
+ }
11853
+ });
11854
+
11855
+ // src/paths.ts
11856
+ import fs10 from "node:fs";
11857
+ import os6 from "node:os";
11858
+ import path36 from "node:path";
11859
+ function resolveAgentShimHome(env = process.env, home = os6.homedir(), isDirectory = isExistingDirectory) {
11860
+ const fromEnv = env.AGENT_SHIM_HOME;
11861
+ if (fromEnv !== void 0 && fromEnv !== "") {
11862
+ return fromEnv;
11863
+ }
11864
+ const current = path36.join(home, HOME_DIRNAME);
11865
+ const legacy = path36.join(home, LEGACY_HOME_DIRNAME);
11866
+ return !isDirectory(current) && isDirectory(legacy) ? legacy : current;
11867
+ }
11868
+ function isExistingDirectory(candidate) {
11869
+ return fs10.statSync(candidate, { throwIfNoEntry: false })?.isDirectory() ?? false;
11870
+ }
11871
+ function resolveClaudeHome() {
11872
+ const fromEnv = process.env.AGENT_SHIM_CLAUDE_HOME;
11873
+ if (fromEnv !== void 0 && fromEnv !== "") {
11874
+ return fromEnv;
11875
+ }
11876
+ return path36.join(os6.homedir(), ".claude");
11877
+ }
11878
+ function buildLayoutPaths(root) {
11879
+ return {
11880
+ root,
11881
+ identitiesDir: path36.join(root, "identities"),
11882
+ configProfilesDir: path36.join(root, "config-profiles"),
11883
+ providersDir: path36.join(root, "providers"),
11884
+ providerAliasesFile: path36.join(root, "provider-aliases.json"),
11885
+ directoryRulesFile: path36.join(root, "directory-rules.json"),
11886
+ activeIdentityFile: path36.join(root, "active-identity"),
11887
+ globalConfigFile: path36.join(root, "config.json"),
11888
+ categoriesLocalFile: path36.join(root, "categories.local.json"),
11889
+ claudeShimFile: path36.join(root, "claude-shim.json"),
11890
+ headroomDir: path36.join(root, "headroom"),
11891
+ headroomStateFile: path36.join(root, "headroom", "state.json"),
11892
+ headroomRoutingFile: path36.join(root, "headroom", "routing.json"),
11893
+ headroomLegacyStateFile: path36.join(root, "headroom", "state.v2.json"),
11894
+ headroomAllowlistFile: path36.join(root, "headroom", "run", "allowlist.txt"),
11895
+ headroomSocketDir: path36.join(root, "headroom", "run"),
11896
+ headroomLockFile: path36.join(root, "headroom", "start.lock"),
11897
+ headroomSessionsDir: path36.join(root, "headroom", "sessions"),
11898
+ logsDir: path36.join(root, "logs"),
11899
+ headroomLogPath: path36.join(root, "logs", "headroom.log"),
11900
+ frontdoorDir: path36.join(root, "frontdoor"),
11901
+ frontdoorCaDir: path36.join(root, "frontdoor", "ca"),
11902
+ frontdoorCaCertFile: path36.join(root, "frontdoor", "ca", "ca.pem"),
11903
+ frontdoorCaKeyFile: path36.join(root, "frontdoor", "ca", "ca.key"),
11904
+ frontdoorCaBundlesDir: path36.join(root, "frontdoor", "ca", "bundles"),
11905
+ chatgptSignInFile: path36.join(root, "codex", "chatgpt-sign-in.json"),
11906
+ frontdoorStateFile: path36.join(root, "frontdoor", "state.json"),
11907
+ frontdoorLockFile: path36.join(root, "frontdoor", "start.lock"),
11908
+ frontdoorControlTokenFile: path36.join(root, "frontdoor", "control-token"),
11909
+ frontdoorSessionsDir: path36.join(root, "frontdoor", "sessions"),
11910
+ frontdoorDirectRecordsDir: path36.join(root, "frontdoor", "direct"),
11911
+ frontdoorDrainingDir: path36.join(root, "frontdoor", "draining"),
11912
+ frontdoorRcCredentialsDir: path36.join(root, "frontdoor", "rc-credentials"),
11913
+ frontdoorLogPath: path36.join(root, "logs", "frontdoor.log"),
11914
+ usageDir: path36.join(root, "usage"),
11915
+ usageLogDir: path36.join(root, "usage", "log"),
11916
+ usageSnapshotsDir: path36.join(root, "usage", "snapshots"),
11917
+ statuslineDir: path36.join(root, "statusline"),
11918
+ catalogueDir: path36.join(root, "catalogues"),
11919
+ usagePicksFile: path36.join(root, "usage", "picks.json"),
11920
+ usageAnchorsFile: path36.join(root, "usage", "anchors.json"),
11921
+ usageJobsFile: path36.join(root, "usage", "jobs.json"),
11922
+ jobLogsDir: path36.join(root, "logs", "jobs"),
11923
+ identityRenamesDir: path36.join(root, "identity-renames"),
11924
+ identityNameRenamesDir: path36.join(root, "identity-name-renames"),
11925
+ launchesDir: path36.join(root, "launches"),
11926
+ superviseDir: path36.join(root, "supervise"),
11927
+ modelMovesDir: path36.join(root, "model-moves"),
11928
+ mcpPermissionsFile: path36.join(root, "mcp", "permissions.json")
11929
+ };
11930
+ }
11931
+ function resolveLayoutPaths() {
11932
+ return buildLayoutPaths(resolveAgentShimHome());
11933
+ }
11934
+ var init_paths = __esm({
11935
+ "src/paths.ts"() {
11936
+ "use strict";
11937
+ init_legacy();
11938
+ }
11939
+ });
11940
+
11941
+ // src/frontdoor/probe.ts
11942
+ import { Worker } from "node:worker_threads";
11943
+ function requestCatalogueRefreshSync(port, caPem, token, timeoutMs = PROBE_TIMEOUT_MS) {
11944
+ refuseToBlockInRole("a synchronous catalogue refresh request");
11945
+ return runProbeWorker(CATALOGUE_REQUEST_SOURCE, { port, ca: caPem, token }, timeoutMs);
11946
+ }
11947
+ function probeFrontDoorSync(port, caPem, timeoutMs = PROBE_TIMEOUT_MS) {
11948
+ refuseToBlockInRole("a synchronous probe of the front door");
11949
+ return runProbeWorker(PROBE_SOURCE, { port, ca: caPem }, timeoutMs);
11950
+ }
11951
+ function probeListenerAcceptSync(port, timeoutMs = PROBE_TIMEOUT_MS) {
11952
+ refuseToBlockInRole("a synchronous probe of a front door listener");
11953
+ return runProbeWorker(ACCEPT_PROBE_SOURCE, { host: "127.0.0.1", port }, timeoutMs);
11954
+ }
11955
+ function probeAddressAcceptSync(host, port, timeoutMs) {
11956
+ refuseToBlockInRole("a synchronous probe of a provider's address");
11957
+ return runProbeWorker(ACCEPT_PROBE_SOURCE, { host, port }, timeoutMs);
11958
+ }
11959
+ function runProbeWorker(source, data, timeoutMs) {
11960
+ const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
11961
+ const header = new Int32Array(shared, 0, HEADER_SLOTS);
11962
+ const worker = new Worker(source, {
11963
+ eval: true,
11964
+ workerData: { ...data, timeoutMs, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
11965
+ });
11966
+ worker.unref();
11967
+ try {
11968
+ const waited = Atomics.wait(header, 0, VERDICT_PENDING, timeoutMs + PROBE_WAIT_MARGIN_MS);
11969
+ const verdict = Atomics.load(header, 0);
11970
+ if (waited === "timed-out" || verdict === VERDICT_PENDING) {
11971
+ return { ok: false, reason: `the probe did not finish within ${String(timeoutMs + PROBE_WAIT_MARGIN_MS)}ms` };
11972
+ }
11973
+ if (verdict === VERDICT_OK) {
11974
+ return { ok: true };
11975
+ }
11976
+ const length = Atomics.load(header, 1);
11977
+ return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
11978
+ } finally {
11979
+ void worker.terminate();
11980
+ }
11981
+ }
11982
+ var PROBE_TIMEOUT_MS, PROBE_WAIT_MARGIN_MS, REASON_BYTES, HEADER_SLOTS, INT32_BYTES, VERDICT_PENDING, VERDICT_OK, VERDICT_FAILED, PROBE_SOURCE, CATALOGUE_REQUEST_SOURCE, ACCEPT_PROBE_SOURCE;
11983
+ var init_probe = __esm({
11984
+ "src/frontdoor/probe.ts"() {
11985
+ "use strict";
11986
+ init_processRole();
11987
+ PROBE_TIMEOUT_MS = 2e3;
11988
+ PROBE_WAIT_MARGIN_MS = 1e3;
11989
+ REASON_BYTES = 1024;
11990
+ HEADER_SLOTS = 2;
11991
+ INT32_BYTES = 4;
11992
+ VERDICT_PENDING = 0;
11993
+ VERDICT_OK = 1;
11994
+ VERDICT_FAILED = 2;
11995
+ PROBE_SOURCE = `
11996
+ const { workerData } = require("node:worker_threads");
11997
+ const https = require("node:https");
11998
+ const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
11999
+ const header = new Int32Array(shared, 0, headerSlots);
12000
+ const reason = new Uint8Array(shared, headerSlots * 4);
12001
+ let done = false;
12002
+ const finish = (verdict, message) => {
12003
+ if (done) return;
12004
+ done = true;
12005
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
12006
+ reason.set(bytes);
12007
+ Atomics.store(header, 1, bytes.length);
12008
+ Atomics.store(header, 0, verdict);
12009
+ Atomics.notify(header, 0);
12010
+ };
12011
+ const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
12012
+ let body = "";
12013
+ response.setEncoding("utf8");
12014
+ response.on("data", (chunk) => { body += chunk; });
12015
+ response.on("end", () => {
12016
+ if (response.statusCode === 200 && body === "ok") finish(ok, "");
12017
+ else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
12018
+ });
12019
+ response.on("error", (error) => finish(failed, error.message));
12020
+ });
12021
+ // A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
12022
+ setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
12023
+ request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
12024
+ `;
12025
+ CATALOGUE_REQUEST_SOURCE = `
12026
+ const { workerData } = require("node:worker_threads");
12027
+ const https = require("node:https");
12028
+ const { port, ca, token, timeoutMs, shared, ok, failed, headerSlots } = workerData;
12029
+ const header = new Int32Array(shared, 0, headerSlots);
12030
+ const reason = new Uint8Array(shared, headerSlots * 4);
12031
+ let done = false;
12032
+ const finish = (verdict, message) => {
12033
+ if (done) return;
12034
+ done = true;
12035
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
12036
+ reason.set(bytes);
12037
+ Atomics.store(header, 1, bytes.length);
12038
+ Atomics.store(header, 0, verdict);
12039
+ Atomics.notify(header, 0);
12040
+ };
12041
+ const request = https.request({ host: "127.0.0.1", port, path: "/__agent-shim/orpc/rest/frontdoor/catalogues/refresh", method: "POST", headers: { authorization: "Bearer " + token }, ca: [ca], agent: false }, (response) => {
12042
+ response.resume();
12043
+ response.on("end", () => response.statusCode === 200 ? finish(ok, "") : finish(failed, "catalogue refresh request returned HTTP " + String(response.statusCode)));
12044
+ response.on("error", (error) => finish(failed, error.message));
12045
+ });
12046
+ setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
12047
+ request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
12048
+ request.end();
12049
+ `;
12050
+ ACCEPT_PROBE_SOURCE = `
12051
+ const { workerData } = require("node:worker_threads");
12052
+ const net = require("node:net");
12053
+ const { host, port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
12054
+ const header = new Int32Array(shared, 0, headerSlots);
12055
+ const reason = new Uint8Array(shared, headerSlots * 4);
12056
+ let done = false;
12057
+ const finish = (verdict, message) => {
12058
+ if (done) return;
12059
+ done = true;
12060
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
12061
+ reason.set(bytes);
12062
+ Atomics.store(header, 1, bytes.length);
12063
+ Atomics.store(header, 0, verdict);
12064
+ Atomics.notify(header, 0);
12065
+ };
12066
+ const socket = net.connect({ host, port });
12067
+ socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
12068
+ socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
12069
+ setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
12070
+ `;
12071
+ }
12072
+ });
12073
+
12074
+ // src/providerReachability.ts
12075
+ function providerConnectTimeoutMs(provider) {
12076
+ return provider.connectTimeoutMs ?? DEFAULT_PROVIDER_CONNECT_TIMEOUT_MS;
12077
+ }
12078
+ function dialTargetOf(baseUrl) {
12079
+ const url = new URL(baseUrl);
12080
+ const defaultPort = DEFAULT_PORTS[url.protocol];
12081
+ if (defaultPort === void 0) {
12082
+ return void 0;
12083
+ }
12084
+ return { host: url.hostname.replace(/^\[(.*)\]$/, "$1"), port: url.port === "" ? defaultPort : Number(url.port) };
12085
+ }
12086
+ function couldNotConnectMessage(subject, baseUrl, reason) {
12087
+ return `${subject} could not connect to ${baseUrl}: ${reason}`;
12088
+ }
12089
+ function probeProviderReachability(name, provider, probe) {
12090
+ const verdict = probe(provider.baseUrl, providerConnectTimeoutMs(provider));
12091
+ return verdict.ok ? { ok: true } : { ok: false, message: couldNotConnectMessage(`provider ${name}`, provider.baseUrl, verdict.reason) };
12092
+ }
12093
+ function unreachableProviderLine(name, provider, probe) {
12094
+ if (probe === void 0 || !isHttpProvider(provider)) {
12095
+ return void 0;
12096
+ }
12097
+ const reachability = probeProviderReachability(name, provider, probe);
12098
+ return reachability.ok ? void 0 : reachability.message;
12099
+ }
12100
+ var TCP_INITIAL_RETRANSMISSION_TIMEOUT_MS, CONNECT_SYN_RETRANSMISSIONS_TOLERATED, DEFAULT_PROVIDER_CONNECT_TIMEOUT_MS, DEFAULT_PORTS, realBaseUrlProbe;
12101
+ var init_providerReachability = __esm({
12102
+ "src/providerReachability.ts"() {
12103
+ "use strict";
12104
+ init_schema();
12105
+ init_probe();
12106
+ TCP_INITIAL_RETRANSMISSION_TIMEOUT_MS = 1e3;
12107
+ CONNECT_SYN_RETRANSMISSIONS_TOLERATED = 2;
12108
+ DEFAULT_PROVIDER_CONNECT_TIMEOUT_MS = TCP_INITIAL_RETRANSMISSION_TIMEOUT_MS * (2 ** (CONNECT_SYN_RETRANSMISSIONS_TOLERATED + 1) - 1);
12109
+ DEFAULT_PORTS = { "http:": 80, "https:": 443 };
12110
+ realBaseUrlProbe = (baseUrl, timeoutMs) => {
12111
+ const target = dialTargetOf(baseUrl);
12112
+ if (target === void 0) {
12113
+ return { ok: false, reason: "the base URL is neither http nor https" };
12114
+ }
12115
+ return probeAddressAcceptSync(target.host, target.port, timeoutMs);
11745
12116
  };
11746
12117
  }
11747
12118
  });
@@ -11788,7 +12159,7 @@ function formatPeriod(window) {
11788
12159
  if (window.periodMs === void 0) {
11789
12160
  return window.period ?? "unknown period";
11790
12161
  }
11791
- const hours = window.periodMs / MS_PER_HOUR4;
12162
+ const hours = window.periodMs / MS_PER_HOUR5;
11792
12163
  return hours >= HOURS_PER_DAY4 && Number.isInteger(hours / HOURS_PER_DAY4) ? `${String(hours / HOURS_PER_DAY4)}d` : `${String(hours)}h`;
11793
12164
  }
11794
12165
  function groupOf(row) {
@@ -11828,13 +12199,13 @@ function collectResets(snapshots, nowMs) {
11828
12199
  );
11829
12200
  return { resets: rows.sort(compareRows) };
11830
12201
  }
11831
- var MS_PER_HOUR4, HOURS_PER_DAY4;
12202
+ var MS_PER_HOUR5, HOURS_PER_DAY4;
11832
12203
  var init_resets = __esm({
11833
12204
  "src/usage/resets.ts"() {
11834
12205
  "use strict";
11835
12206
  init_preflight();
11836
12207
  init_rateLimit();
11837
- MS_PER_HOUR4 = 36e5;
12208
+ MS_PER_HOUR5 = 36e5;
11838
12209
  HOURS_PER_DAY4 = 24;
11839
12210
  }
11840
12211
  });
@@ -12436,7 +12807,7 @@ var init_modelPicker = __esm({
12436
12807
  });
12437
12808
 
12438
12809
  // src/models/targets.ts
12439
- import os7 from "node:os";
12810
+ import os8 from "node:os";
12440
12811
  function providerModels(paths) {
12441
12812
  const door = readFrontDoorState(realFarmFs, paths.frontdoorStateFile);
12442
12813
  const recordedPid = door?.port === void 0 ? void 0 : door.supervisorPid;
@@ -12449,7 +12820,7 @@ function providerModels(paths) {
12449
12820
  if (entry.provider.kind === "codex") {
12450
12821
  if (catalogue !== void 0 && catalogue.supervisorPid !== supervisorPid) return [];
12451
12822
  const env = doorHome === void 0 ? process.env : { ...process.env, CODEX_HOME: doorHome };
12452
- const fingerprint = savedCatalogueFingerprint(entry.provider, paths, env, os7.homedir(), realFsPort.readFileUtf8);
12823
+ const fingerprint = savedCatalogueFingerprint(entry.provider, paths, env, os8.homedir(), realFsPort.readFileUtf8);
12453
12824
  if (fingerprint === void 0 || catalogue?.credentialFingerprint !== fingerprint) return [];
12454
12825
  }
12455
12826
  return providerModelRows(entry.provider, catalogue?.models).map((row) => ({ provider: entry.name, model: row.model }));
@@ -12470,135 +12841,6 @@ var init_targets = __esm({
12470
12841
  }
12471
12842
  });
12472
12843
 
12473
- // src/frontdoor/probe.ts
12474
- import { Worker } from "node:worker_threads";
12475
- function requestCatalogueRefreshSync(port, caPem, token, timeoutMs = PROBE_TIMEOUT_MS) {
12476
- refuseToBlockInRole("a synchronous catalogue refresh request");
12477
- return runProbeWorker(CATALOGUE_REQUEST_SOURCE, { port, ca: caPem, token }, timeoutMs);
12478
- }
12479
- function probeFrontDoorSync(port, caPem, timeoutMs = PROBE_TIMEOUT_MS) {
12480
- refuseToBlockInRole("a synchronous probe of the front door");
12481
- return runProbeWorker(PROBE_SOURCE, { port, ca: caPem }, timeoutMs);
12482
- }
12483
- function probeListenerAcceptSync(port, timeoutMs = PROBE_TIMEOUT_MS) {
12484
- refuseToBlockInRole("a synchronous probe of a front door listener");
12485
- return runProbeWorker(ACCEPT_PROBE_SOURCE, { port }, timeoutMs);
12486
- }
12487
- function runProbeWorker(source, data, timeoutMs) {
12488
- const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
12489
- const header = new Int32Array(shared, 0, HEADER_SLOTS);
12490
- const worker = new Worker(source, {
12491
- eval: true,
12492
- workerData: { ...data, timeoutMs, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
12493
- });
12494
- worker.unref();
12495
- try {
12496
- const waited = Atomics.wait(header, 0, VERDICT_PENDING, timeoutMs + PROBE_WAIT_MARGIN_MS);
12497
- const verdict = Atomics.load(header, 0);
12498
- if (waited === "timed-out" || verdict === VERDICT_PENDING) {
12499
- return { ok: false, reason: `the probe did not finish within ${String(timeoutMs + PROBE_WAIT_MARGIN_MS)}ms` };
12500
- }
12501
- if (verdict === VERDICT_OK) {
12502
- return { ok: true };
12503
- }
12504
- const length = Atomics.load(header, 1);
12505
- return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
12506
- } finally {
12507
- void worker.terminate();
12508
- }
12509
- }
12510
- var PROBE_TIMEOUT_MS, PROBE_WAIT_MARGIN_MS, REASON_BYTES, HEADER_SLOTS, INT32_BYTES, VERDICT_PENDING, VERDICT_OK, VERDICT_FAILED, PROBE_SOURCE, CATALOGUE_REQUEST_SOURCE, ACCEPT_PROBE_SOURCE;
12511
- var init_probe = __esm({
12512
- "src/frontdoor/probe.ts"() {
12513
- "use strict";
12514
- init_processRole();
12515
- PROBE_TIMEOUT_MS = 2e3;
12516
- PROBE_WAIT_MARGIN_MS = 1e3;
12517
- REASON_BYTES = 1024;
12518
- HEADER_SLOTS = 2;
12519
- INT32_BYTES = 4;
12520
- VERDICT_PENDING = 0;
12521
- VERDICT_OK = 1;
12522
- VERDICT_FAILED = 2;
12523
- PROBE_SOURCE = `
12524
- const { workerData } = require("node:worker_threads");
12525
- const https = require("node:https");
12526
- const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
12527
- const header = new Int32Array(shared, 0, headerSlots);
12528
- const reason = new Uint8Array(shared, headerSlots * 4);
12529
- let done = false;
12530
- const finish = (verdict, message) => {
12531
- if (done) return;
12532
- done = true;
12533
- const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
12534
- reason.set(bytes);
12535
- Atomics.store(header, 1, bytes.length);
12536
- Atomics.store(header, 0, verdict);
12537
- Atomics.notify(header, 0);
12538
- };
12539
- const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
12540
- let body = "";
12541
- response.setEncoding("utf8");
12542
- response.on("data", (chunk) => { body += chunk; });
12543
- response.on("end", () => {
12544
- if (response.statusCode === 200 && body === "ok") finish(ok, "");
12545
- else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
12546
- });
12547
- response.on("error", (error) => finish(failed, error.message));
12548
- });
12549
- // A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
12550
- setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
12551
- request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
12552
- `;
12553
- CATALOGUE_REQUEST_SOURCE = `
12554
- const { workerData } = require("node:worker_threads");
12555
- const https = require("node:https");
12556
- const { port, ca, token, timeoutMs, shared, ok, failed, headerSlots } = workerData;
12557
- const header = new Int32Array(shared, 0, headerSlots);
12558
- const reason = new Uint8Array(shared, headerSlots * 4);
12559
- let done = false;
12560
- const finish = (verdict, message) => {
12561
- if (done) return;
12562
- done = true;
12563
- const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
12564
- reason.set(bytes);
12565
- Atomics.store(header, 1, bytes.length);
12566
- Atomics.store(header, 0, verdict);
12567
- Atomics.notify(header, 0);
12568
- };
12569
- const request = https.request({ host: "127.0.0.1", port, path: "/__agent-shim/orpc/rest/frontdoor/catalogues/refresh", method: "POST", headers: { authorization: "Bearer " + token }, ca: [ca], agent: false }, (response) => {
12570
- response.resume();
12571
- response.on("end", () => response.statusCode === 200 ? finish(ok, "") : finish(failed, "catalogue refresh request returned HTTP " + String(response.statusCode)));
12572
- response.on("error", (error) => finish(failed, error.message));
12573
- });
12574
- setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
12575
- request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
12576
- request.end();
12577
- `;
12578
- ACCEPT_PROBE_SOURCE = `
12579
- const { workerData } = require("node:worker_threads");
12580
- const net = require("node:net");
12581
- const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
12582
- const header = new Int32Array(shared, 0, headerSlots);
12583
- const reason = new Uint8Array(shared, headerSlots * 4);
12584
- let done = false;
12585
- const finish = (verdict, message) => {
12586
- if (done) return;
12587
- done = true;
12588
- const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
12589
- reason.set(bytes);
12590
- Atomics.store(header, 1, bytes.length);
12591
- Atomics.store(header, 0, verdict);
12592
- Atomics.notify(header, 0);
12593
- };
12594
- const socket = net.connect({ host: "127.0.0.1", port });
12595
- socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
12596
- socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
12597
- setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
12598
- `;
12599
- }
12600
- });
12601
-
12602
12844
  // src/launcher/proxyBypass.ts
12603
12845
  function checkedProxyBypass(entries, source) {
12604
12846
  const seen = /* @__PURE__ */ new Set();
@@ -13756,7 +13998,10 @@ var init_hold = __esm({
13756
13998
  // src/launcher/launchReport.ts
13757
13999
  function poolDetail(pool) {
13758
14000
  const [reason] = pool.reasons;
13759
- return reason === void 0 ? {} : { detail: reason };
14001
+ if (reason === void 0) {
14002
+ return {};
14003
+ }
14004
+ return { detail: pool.provider === void 0 ? reason : `${reason} (ranked on provider ${pool.provider})` };
13760
14005
  }
13761
14006
  function rankingNotes(ranking, picked) {
13762
14007
  return ranking.flatMap((candidate, index) => [
@@ -13918,6 +14163,7 @@ function resolvePoolLaunch(params) {
13918
14163
  resuming,
13919
14164
  ...params.resumeContextTokens === void 0 ? {} : { resumeContextTokens: params.resumeContextTokens },
13920
14165
  ...params.committedContextTokens === void 0 ? {} : { committedContextTokens: params.committedContextTokens },
14166
+ ...params.providerOf === void 0 ? {} : { providerOf: params.providerOf },
13921
14167
  identityIdOf: identityIdResolver(params.paths.identitiesDir, params.fs),
13922
14168
  ...stickyRead.sticky === void 0 ? {} : { sticky: stickyRead.sticky }
13923
14169
  });
@@ -13959,6 +14205,7 @@ function resolvePoolLaunch(params) {
13959
14205
  explanation: `pool ${poolName}: ${move}${pick.reasons.slice(0, REASONS_LOGGED).join("; ")}`,
13960
14206
  reasons: pick.reasons,
13961
14207
  candidates: graph.ranking.candidates,
14208
+ ...pick.provider === void 0 ? {} : { provider: pick.provider },
13962
14209
  ...movedOff === void 0 ? {} : { movedOff },
13963
14210
  ...stickyRead.sticky === void 0 ? {} : { lastRanAs: stickyRead.sticky }
13964
14211
  };
@@ -13991,13 +14238,13 @@ var init_pool = __esm({
13991
14238
  });
13992
14239
 
13993
14240
  // src/launcher/spawn.ts
13994
- import os8 from "node:os";
14241
+ import os9 from "node:os";
13995
14242
  function childExitCode(result) {
13996
14243
  if (result.status !== null) {
13997
14244
  return result.status;
13998
14245
  }
13999
14246
  if (result.signal !== null) {
14000
- return SIGNAL_EXIT_CODE_OFFSET + os8.constants.signals[result.signal];
14247
+ return SIGNAL_EXIT_CODE_OFFSET + os9.constants.signals[result.signal];
14001
14248
  }
14002
14249
  return 1;
14003
14250
  }
@@ -14090,7 +14337,7 @@ var init_launchHook = __esm({
14090
14337
 
14091
14338
  // src/launcher.ts
14092
14339
  import { randomUUID as randomUUID6 } from "node:crypto";
14093
- import os9 from "node:os";
14340
+ import os10 from "node:os";
14094
14341
  import { isDeepStrictEqual } from "node:util";
14095
14342
  import path51 from "node:path";
14096
14343
  function resolveIdentityCredential(identity, credential, env, port) {
@@ -14100,7 +14347,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
14100
14347
  const resolution = resolveCredential({ credential, env, port, subject: `identity ${identity.name}`, cacheKey: identityCacheKey(identity.id) });
14101
14348
  return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: `agent-shim: ${resolution.message}` };
14102
14349
  }
14103
- function pickFromPool(decided, params, parsedArgv, readOnly) {
14350
+ function pickFromPool(decided, params, parsedArgv, readOnly, providerSelections) {
14104
14351
  const { paths, fs: fs17, proc, log } = params;
14105
14352
  if (decided.pool === void 0) {
14106
14353
  return { identityDecision: decided };
@@ -14115,6 +14362,17 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
14115
14362
  return proc.exit(1);
14116
14363
  }
14117
14364
  const resumeContextTokens = resumedContextTokens(farmRuntime.fs, { claudeHome: farmRuntime.claudeHome, cwd: farmRuntime.cwd, passthrough: parsedArgv.rest });
14365
+ const cliFlagConfigProfile = params.cliFlagConfigProfile ?? parsedArgv.configProfile;
14366
+ const providerOf = memberProviderResolver({
14367
+ paths,
14368
+ fs: fs17,
14369
+ env: providerSelections.env,
14370
+ cliProvider: parsedArgv.provider,
14371
+ ...cliFlagConfigProfile === void 0 ? {} : { cliFlagConfigProfile },
14372
+ ...params.directoryRuleConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: params.directoryRuleConfigProfile },
14373
+ ...params.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: params.globalDefaultConfigProfile },
14374
+ loadCascade: (baseConfigProfile) => farmRuntime.loadCascade(baseConfigProfile, providerSelections.cliOverride)
14375
+ });
14118
14376
  const resolution = resolvePoolLaunch({
14119
14377
  poolName: decided.pool,
14120
14378
  selectedVia: decided.source,
@@ -14126,6 +14384,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
14126
14384
  now: farmRuntime.now,
14127
14385
  sleep: farmRuntime.lock.sleep,
14128
14386
  passthrough: parsedArgv.rest,
14387
+ providerOf,
14129
14388
  ...resumeContextTokens === void 0 ? {} : { resumeContextTokens },
14130
14389
  // A read-only decision never sleeps for a refused pool and never records its pick, so asking what a launch would pick leaves the next real launch's keep-warm preference as it was.
14131
14390
  wait: !readOnly && parsedArgv.wait === true,
@@ -14138,7 +14397,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
14138
14397
  }
14139
14398
  return {
14140
14399
  identityDecision: { ...decided, name: resolution.identity },
14141
- poolPick: { name: decided.pool, reasons: resolution.reasons, ...resolution.movedOff === void 0 ? {} : { movedOff: resolution.movedOff } },
14400
+ poolPick: { name: decided.pool, reasons: resolution.reasons, ...resolution.provider === void 0 ? {} : { provider: resolution.provider }, ...resolution.movedOff === void 0 ? {} : { movedOff: resolution.movedOff } },
14142
14401
  poolRanking: resolution.candidates,
14143
14402
  ...resolution.lastRanAs === void 0 ? {} : { lastRanAs: { identity: resolution.lastRanAs.identity, agoMs: farmRuntime.now() - Date.parse(resolution.lastRanAs.at) } }
14144
14403
  };
@@ -14174,7 +14433,7 @@ function decideLaunch(params, readOnly, onRecorded) {
14174
14433
  shareFlags: parsedArgv.shareFlags,
14175
14434
  hideFlags: parsedArgv.hideFlags
14176
14435
  });
14177
- const { identityDecision, poolPick, poolRanking, lastRanAs } = pickFromPool(decidedIdentity, params, parsedArgv, readOnly);
14436
+ const { identityDecision, poolPick, poolRanking, lastRanAs } = pickFromPool(decidedIdentity, params, parsedArgv, readOnly, { env, cliOverride });
14178
14437
  const lockFarm = !readOnly && !configDirEscapeHatchApplies && identityDecision.name !== void 0 ? params.farm : void 0;
14179
14438
  const lockPorts = params.namesLock ?? (lockFarm === void 0 ? realIdentityNamesLockPorts : { fs: lockFarm.fs, nowMs: lockFarm.now, ...lockFarm.lock });
14180
14439
  const namesLock = readOnly || configDirEscapeHatchApplies || identityDecision.name === void 0 ? void 0 : acquireIdentityNamesLock(paths, lockPorts);
@@ -14375,12 +14634,12 @@ function decideLaunch(params, readOnly, onRecorded) {
14375
14634
  if (definition.kind === "codex" && readOnly && cache !== void 0) {
14376
14635
  const binding = parseCatalogueBinding(params.fs.readFileUtf8(catalogueBindingPath(paths, name, catalogueOwner, generation)));
14377
14636
  const configuredHome = catalogueEnv.CODEX_HOME;
14378
- const home = configuredHome === void 0 || configuredHome === "" ? path51.join(os9.homedir(), ".codex") : configuredHome;
14637
+ const home = configuredHome === void 0 || configuredHome === "" ? path51.join(os10.homedir(), ".codex") : configuredHome;
14379
14638
  const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile : path51.resolve(home, "auth.json");
14380
14639
  const revision = params.fs.fileRevision?.(source);
14381
14640
  if (binding === void 0 || binding.fingerprint !== cache.credentialFingerprint || binding.source !== source || revision === void 0 || revision !== binding.revision) return [];
14382
14641
  }
14383
- const fingerprint = definition.kind === "codex" && !readOnly ? savedCatalogueFingerprint(definition, paths, catalogueEnv, os9.homedir(), params.fs.readFileUtf8) : void 0;
14642
+ const fingerprint = definition.kind === "codex" && !readOnly ? savedCatalogueFingerprint(definition, paths, catalogueEnv, os10.homedir(), params.fs.readFileUtf8) : void 0;
14384
14643
  if (definition.kind === "codex" && !readOnly && cache !== void 0 && (fingerprint === void 0 || cache.credentialFingerprint !== fingerprint)) return [];
14385
14644
  return [[name, definition, cache?.models ?? []]];
14386
14645
  } catch {
@@ -14534,6 +14793,11 @@ function prepareRegisteredLaunch(params, onRecorded) {
14534
14793
  proc.exit(check.status);
14535
14794
  }
14536
14795
  }
14796
+ const unreachable = resolvedProvider === void 0 ? void 0 : unreachableProviderLine(resolvedProvider.name, resolvedProvider.definition, params.probeBaseUrl);
14797
+ if (unreachable !== void 0) {
14798
+ log.error(`agent-shim: ${unreachable}`);
14799
+ proc.exit(1);
14800
+ }
14537
14801
  const frontDoorPort = params.frontdoor;
14538
14802
  const frontDoorEngaged = resolvedProvider !== void 0 || resolvedFlags.headroom || resolvedFlags.trackUsage;
14539
14803
  if (frontDoorEngaged && frontDoorPort === void 0) {
@@ -14674,6 +14938,7 @@ var init_launcher = __esm({
14674
14938
  init_state();
14675
14939
  init_providerCatalogue();
14676
14940
  init_providersStore();
14941
+ init_memberProvider();
14677
14942
  init_pool();
14678
14943
  init_resumeContext();
14679
14944
  init_lock();
@@ -14683,6 +14948,7 @@ var init_launcher = __esm({
14683
14948
  init_flatten();
14684
14949
  init_walk();
14685
14950
  init_schema();
14951
+ init_providerReachability();
14686
14952
  init_schema();
14687
14953
  init_credential();
14688
14954
  init_middleware();
@@ -14797,7 +15063,7 @@ var init_trust = __esm({
14797
15063
 
14798
15064
  // src/frontdoor/realFrontDoorPort.ts
14799
15065
  import fs16 from "node:fs";
14800
- import os10 from "node:os";
15066
+ import os11 from "node:os";
14801
15067
  function realEnsurePorts(paths, spawnDaemon) {
14802
15068
  return {
14803
15069
  fs: realFarmFs,
@@ -14844,7 +15110,7 @@ function realFrontDoorPort(paths, spawnDaemon) {
14844
15110
  const cache2 = parseCatalogueCache(realFarmFs.readFileUtf8(catalogueCachePath(paths, name, supervisorPid, owner.generation)));
14845
15111
  let fingerprint;
14846
15112
  try {
14847
- fingerprint = savedCatalogueFingerprint(provider, paths, { ...process.env, CODEX_HOME: owner.codexHome }, os10.homedir(), realFarmFs.readFileUtf8);
15113
+ fingerprint = savedCatalogueFingerprint(provider, paths, { ...process.env, CODEX_HOME: owner.codexHome }, os11.homedir(), realFarmFs.readFileUtf8);
14848
15114
  } catch (error) {
14849
15115
  warnings.add(`Cannot read catalogue credentials for ${name}: ${error instanceof Error ? error.message : String(error)}`);
14850
15116
  return false;
@@ -14923,11 +15189,11 @@ var init_realFrontDoorPort = __esm({
14923
15189
  });
14924
15190
 
14925
15191
  // src/launchWiring.ts
14926
- import os11 from "node:os";
15192
+ import os12 from "node:os";
14927
15193
  import path54 from "node:path";
14928
15194
  import { randomUUID as randomUUID7 } from "node:crypto";
14929
15195
  function buildFarmRuntime(paths, cwd, run = realRunPort) {
14930
- const home = os11.homedir();
15196
+ const home = os12.homedir();
14931
15197
  const read = cosmiconfigReader();
14932
15198
  const classification = loadClassification(paths);
14933
15199
  const loaded = loadCascadeInput({ paths, home, cwd, read });
@@ -14978,6 +15244,7 @@ function realPrepareLaunchParams(paths, options) {
14978
15244
  headroom: realHeadroomPort(paths, { spawnDaemon: options.spawnDaemon, cwd: farm.runtime.cwd }),
14979
15245
  frontdoor: realFrontDoorPort(paths, options.spawnDaemon),
14980
15246
  credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
15247
+ probeBaseUrl: realBaseUrlProbe,
14981
15248
  hold: realHoldPort,
14982
15249
  hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: path54.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
14983
15250
  hasUsableLogin: (identity, claudeBin) => storedLoginUsable(options.run ?? realRunPort, claudeBin, path54.join(paths.identitiesDir, identity), options.proc.env),
@@ -15058,6 +15325,7 @@ var init_launchWiring = __esm({
15058
15325
  init_replayRun();
15059
15326
  init_paths();
15060
15327
  init_signIn();
15328
+ init_providerReachability();
15061
15329
  init_realPorts();
15062
15330
  LaunchRefusedError = class extends CliError {
15063
15331
  exitCode;
@@ -15200,7 +15468,7 @@ var init_anthropicUsageRefresh = __esm({
15200
15468
  init_schema();
15201
15469
  init_identity();
15202
15470
  init_middleware();
15203
- init_pick();
15471
+ init_windowLengths();
15204
15472
  init_plan2();
15205
15473
  PERCENT2 = 100;
15206
15474
  ANTHROPIC_USAGE_FRESHNESS_MS = FIVE_HOUR_WINDOW_MS / PERCENT2;
@@ -19126,7 +19394,7 @@ import { openapi as openapi9 } from "@orpc/openapi";
19126
19394
 
19127
19395
  // src/checkReport.ts
19128
19396
  init_cliError();
19129
- import os6 from "node:os";
19397
+ import os7 from "node:os";
19130
19398
 
19131
19399
  // src/codex/categories.ts
19132
19400
  var CODEX_CATEGORIES = {
@@ -19158,7 +19426,7 @@ init_load();
19158
19426
  init_load();
19159
19427
  init_cascade();
19160
19428
  init_identity();
19161
- import os4 from "node:os";
19429
+ import os5 from "node:os";
19162
19430
 
19163
19431
  // src/poolPickReport.ts
19164
19432
  init_identity();
@@ -19172,6 +19440,7 @@ function candidateView(candidate) {
19172
19440
  feasible: candidate.feasible,
19173
19441
  ...candidate.blockedUntilMs === void 0 ? {} : { blockedUntil: new Date(candidate.blockedUntilMs).toISOString() },
19174
19442
  plan: candidate.plan,
19443
+ ...candidate.provider === void 0 ? {} : { provider: candidate.provider },
19175
19444
  reasons: [...candidate.reasons]
19176
19445
  };
19177
19446
  }
@@ -19185,6 +19454,7 @@ function collectPoolPick(params) {
19185
19454
  nowMs: params.nowMs,
19186
19455
  resuming: false,
19187
19456
  identityIdOf: identityIdResolver(params.paths.identitiesDir, params.fs),
19457
+ ...params.providerOf === void 0 ? {} : { providerOf: params.providerOf },
19188
19458
  ...sticky.sticky === void 0 ? {} : { sticky: sticky.sticky }
19189
19459
  });
19190
19460
  return {
@@ -19199,6 +19469,29 @@ function collectPoolPick(params) {
19199
19469
  };
19200
19470
  }
19201
19471
 
19472
+ // src/poolProviderWiring.ts
19473
+ init_load();
19474
+ init_cascade();
19475
+ init_memberProvider();
19476
+ init_realPorts();
19477
+ import os4 from "node:os";
19478
+ function realMemberProviderResolver(params) {
19479
+ const home = os4.homedir();
19480
+ const read = cosmiconfigReader();
19481
+ const loaded = params.loaded ?? loadCascadeInput({ paths: params.paths, home, cwd: params.cwd, read });
19482
+ const selections = readDirectorySelections(loaded);
19483
+ return memberProviderResolver({
19484
+ paths: params.paths,
19485
+ fs: realFsPort,
19486
+ env: params.env,
19487
+ cliProvider: params.cliProvider,
19488
+ ...params.cliFlagConfigProfile === void 0 ? {} : { cliFlagConfigProfile: params.cliFlagConfigProfile },
19489
+ ...selections.configProfile === void 0 ? {} : { directoryRuleConfigProfile: selections.configProfile },
19490
+ ...loaded.globalConfig?.defaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: loaded.globalConfig.defaultConfigProfile },
19491
+ loadCascade: (baseConfigProfile) => loadCascadeInput({ paths: params.paths, home, cwd: params.cwd, read, ...baseConfigProfile === void 0 ? {} : { baseConfigProfile } }).input
19492
+ });
19493
+ }
19494
+
19202
19495
  // src/launchSelection.ts
19203
19496
  init_poolStore();
19204
19497
  init_realPorts();
@@ -19224,7 +19517,8 @@ function selectLaunch(params, loaded) {
19224
19517
  if (pools[decidedIdentity.pool] === void 0) {
19225
19518
  throw new PoolNotFoundError(decidedIdentity.pool);
19226
19519
  }
19227
- poolPick = collectPoolPick({ paths, fs: realFsPort, usageFs: realFarmFs, poolName: decidedIdentity.pool, pools, directory: cwd, nowMs: Date.now() });
19520
+ const providerOf = realMemberProviderResolver({ paths, cwd, env: params.env, ...params.configProfile === void 0 ? {} : { cliFlagConfigProfile: params.configProfile }, loaded });
19521
+ poolPick = collectPoolPick({ paths, fs: realFsPort, usageFs: realFarmFs, poolName: decidedIdentity.pool, pools, directory: cwd, nowMs: Date.now(), providerOf });
19228
19522
  }
19229
19523
  const identity = poolPick?.pick === void 0 ? decidedIdentity : { ...decidedIdentity, name: poolPick.pick };
19230
19524
  const loadedIdentity = identity.name === void 0 ? void 0 : loadIdentity(paths.identitiesDir, identity.name, realFsPort);
@@ -19241,7 +19535,7 @@ function selectLaunch(params, loaded) {
19241
19535
  };
19242
19536
  }
19243
19537
  function resolveLaunchSelection(params) {
19244
- const loaded = loadCascadeInput({ paths: params.paths, home: os4.homedir(), cwd: params.cwd, read: cosmiconfigReader() });
19538
+ const loaded = loadCascadeInput({ paths: params.paths, home: os5.homedir(), cwd: params.cwd, read: cosmiconfigReader() });
19245
19539
  return selectLaunch(params, loaded).selection;
19246
19540
  }
19247
19541
 
@@ -19255,6 +19549,7 @@ init_realPorts();
19255
19549
  init_envBool();
19256
19550
  init_load();
19257
19551
  init_schema();
19552
+ init_providerReachability();
19258
19553
  init_identityStore();
19259
19554
  init_credential();
19260
19555
  init_claudeVersion();
@@ -19449,6 +19744,7 @@ function runCheck(params) {
19449
19744
  const settingsExposure = inspectSettingsExposure({ settingsShared, files: params.settingsFiles });
19450
19745
  const keychain = !isCodex && params.platform === "darwin" && params.run !== void 0 && params.farmRoot !== void 0 ? lookupKeychainService(params.run, params.farmRoot) : void 0;
19451
19746
  const claudeVersion = isCodex ? void 0 : buildClaudeVersionReport(params, resolved.flattened.launch.claudeVersion);
19747
+ const providerReachability = buildProviderReachability(params.provider, params.probeBaseUrl);
19452
19748
  return {
19453
19749
  ...params.identityName === void 0 ? {} : { identityName: params.identityName },
19454
19750
  identitySource: params.identitySource,
@@ -19462,9 +19758,18 @@ function runCheck(params) {
19462
19758
  ...keychain === void 0 ? {} : { keychain },
19463
19759
  settingsExposure,
19464
19760
  credential: buildCredentialReport(params.provider, params.identity, params.identityId, params.credentialCache),
19465
- ...claudeVersion === void 0 ? {} : { claudeVersion }
19761
+ ...claudeVersion === void 0 ? {} : { claudeVersion },
19762
+ ...providerReachability === void 0 ? {} : { providerReachability }
19466
19763
  };
19467
19764
  }
19765
+ function buildProviderReachability(provider, probe) {
19766
+ if (provider?.definition === void 0 || probe === void 0 || !isHttpProvider(provider.definition)) {
19767
+ return void 0;
19768
+ }
19769
+ const { baseUrl } = provider.definition;
19770
+ const reachability = probeProviderReachability(provider.name, provider.definition, probe);
19771
+ return reachability.ok ? { name: provider.name, baseUrl, ok: true } : { name: provider.name, baseUrl, ok: false, message: reachability.message };
19772
+ }
19468
19773
  function formatCheckReport(report) {
19469
19774
  const lines = [];
19470
19775
  lines.push(`Identity: ${report.identityName ?? "(none)"} (${report.identitySource})`);
@@ -19511,6 +19816,11 @@ function formatCheckReport(report) {
19511
19816
  if (credential.applies === "stored-login") {
19512
19817
  lines.push(" The identity's stored login (no credential block applies).");
19513
19818
  }
19819
+ if (report.providerReachability !== void 0) {
19820
+ lines.push("", "Provider reachability:");
19821
+ const reachability = report.providerReachability;
19822
+ lines.push(reachability.ok ? ` Provider ${reachability.name}: ${reachability.baseUrl} accepts connections` : ` [FAIL] ${reachability.message}`);
19823
+ }
19514
19824
  if (report.claudeVersion !== void 0) {
19515
19825
  lines.push("", "Claude Code version:");
19516
19826
  const { pinned, highestInstalled, installed } = report.claudeVersion;
@@ -19561,11 +19871,12 @@ function checkReportToJson(report) {
19561
19871
  ...report.keychain === void 0 ? {} : { keychain: report.keychain },
19562
19872
  settingsExposure: report.settingsExposure,
19563
19873
  credential: report.credential,
19564
- ...report.claudeVersion === void 0 ? {} : { claudeVersion: report.claudeVersion }
19874
+ ...report.claudeVersion === void 0 ? {} : { claudeVersion: report.claudeVersion },
19875
+ ...report.providerReachability === void 0 ? {} : { providerReachability: report.providerReachability }
19565
19876
  };
19566
19877
  }
19567
19878
  function checkReportHasWarnings(report) {
19568
- return report.resolved.diagnostics.some((diagnostic) => diagnostic.severity !== "info") || report.projectEncodingAmbiguities.length > 0 || !report.ambientCredential.ok || report.credential.provider?.problem !== void 0 || report.claudeVersion?.pinned?.installed === false;
19879
+ return report.resolved.diagnostics.some((diagnostic) => diagnostic.severity !== "info") || report.projectEncodingAmbiguities.length > 0 || !report.ambientCredential.ok || report.credential.provider?.problem !== void 0 || report.providerReachability?.ok === false || report.claudeVersion?.pinned?.installed === false;
19569
19880
  }
19570
19881
  function loadCheckProvider(paths, name) {
19571
19882
  let definition;
@@ -19581,7 +19892,7 @@ function loadCheckProvider(paths, name) {
19581
19892
  }
19582
19893
  function collectCheckReport(params) {
19583
19894
  const { paths, cwd } = params;
19584
- const home = os6.homedir();
19895
+ const home = os7.homedir();
19585
19896
  const read = cosmiconfigReader();
19586
19897
  const loaded = loadCascadeInput({ paths, home, cwd, read });
19587
19898
  const git = resolveGitBranch(realRunPort, cwd);
@@ -19632,7 +19943,8 @@ function collectCheckReport(params) {
19632
19943
  ...isCodex ? {} : { installedClaudeVersions: realInstalledClaudeVersions() },
19633
19944
  ...farmRoot === void 0 ? {} : { farmRoot },
19634
19945
  platform: process.platform,
19635
- ...provider === void 0 ? {} : { provider }
19946
+ ...provider === void 0 ? {} : { provider },
19947
+ probeBaseUrl: realBaseUrlProbe
19636
19948
  });
19637
19949
  return report;
19638
19950
  }
@@ -19717,6 +20029,8 @@ var PoolPickCandidateViewSchema = z28.strictObject({
19717
20029
  /** When an `ineligible` member can be used again, as an ISO instant. */
19718
20030
  blockedUntil: z28.iso.datetime().optional(),
19719
20031
  plan: PlanClassSchema,
20032
+ /** The provider the member was ranked on, when its launch spends one in place of its Claude account: its windows, refusals and plan are the provider's own. Absent when ranked on the Claude account. */
20033
+ provider: z28.string().optional(),
19720
20034
  /** The facts behind the class and score, in the order they matter. */
19721
20035
  reasons: z28.array(z28.string())
19722
20036
  });
@@ -19795,6 +20109,10 @@ var CheckCredentialProviderSchema = z29.union([
19795
20109
  z29.strictObject({ name: z29.string(), credential: CredentialSummarySchema.optional(), cached: CachedCredentialStateSchema.optional() }),
19796
20110
  z29.strictObject({ name: z29.string(), problem: z29.string() })
19797
20111
  ]);
20112
+ var CheckProviderReachabilitySchema = z29.union([
20113
+ z29.strictObject({ name: z29.string(), baseUrl: z29.string(), ok: z29.literal(true) }),
20114
+ z29.strictObject({ name: z29.string(), baseUrl: z29.string(), ok: z29.literal(false), message: z29.string() })
20115
+ ]);
19798
20116
  var CheckCredentialSchema = z29.strictObject({
19799
20117
  applies: z29.enum(CHECK_CREDENTIAL_APPLIES),
19800
20118
  provider: CheckCredentialProviderSchema.optional(),
@@ -19821,7 +20139,8 @@ var CheckReportJsonSchema = z29.strictObject({
19821
20139
  keychain: CheckKeychainSchema.optional(),
19822
20140
  settingsExposure: z29.readonly(z29.array(CheckSettingsExposureSchema)),
19823
20141
  credential: CheckCredentialSchema,
19824
- claudeVersion: CheckClaudeVersionSchema.optional()
20142
+ claudeVersion: CheckClaudeVersionSchema.optional(),
20143
+ providerReachability: CheckProviderReachabilitySchema.optional()
19825
20144
  });
19826
20145
 
19827
20146
  // src/frontdoor/controlApi.ts
@@ -19865,7 +20184,6 @@ function codexIdentityFindings(entry, identity) {
19865
20184
  // src/doctorReport.ts
19866
20185
  init_claudeShim();
19867
20186
  init_readableConfig();
19868
- init_names();
19869
20187
  init_store();
19870
20188
  init_identityStore();
19871
20189
  init_identityRecords();
@@ -19940,6 +20258,28 @@ import path42 from "node:path";
19940
20258
  init_signIn();
19941
20259
  init_identityAccounts();
19942
20260
  init_read();
20261
+ init_providerReachability();
20262
+
20263
+ // src/doctorNameFinding.ts
20264
+ init_names();
20265
+ function pushNameFinding(push, section, kind, entry) {
20266
+ if (isFileName(entry.name)) {
20267
+ return true;
20268
+ }
20269
+ if (!isStoredName(entry.name)) {
20270
+ push(section, "fail", `${entry.path} cannot be used as a ${kind}: its name is ${JSON.stringify(entry.name)}, and a name ${FILE_NAME_RULE}. Rename or remove the file.`, entry.name);
20271
+ return false;
20272
+ }
20273
+ push(
20274
+ section,
20275
+ "warn",
20276
+ `The ${kind} ${JSON.stringify(entry.name)} is stored under a name that does not fit the shape names are given now (a name ${FILE_NAME_RULE}). It still works from your own configuration, but a project file cannot name it. Rename ${entry.path} to a name that fits, and change what names it.`,
20277
+ entry.name
20278
+ );
20279
+ return true;
20280
+ }
20281
+
20282
+ // src/doctorReport.ts
19943
20283
  init_siwcStore();
19944
20284
  init_siwc();
19945
20285
  init_load();
@@ -20434,23 +20774,7 @@ function signInProblem(signIn) {
20434
20774
  return error instanceof Error ? error.message : String(error);
20435
20775
  }
20436
20776
  }
20437
- function pushNameFinding(push, section, kind, entry) {
20438
- if (isFileName(entry.name)) {
20439
- return true;
20440
- }
20441
- if (!isStoredName(entry.name)) {
20442
- push(section, "fail", `${entry.path} cannot be used as a ${kind}: its name is ${JSON.stringify(entry.name)}, and a name ${FILE_NAME_RULE}. Rename or remove the file.`, entry.name);
20443
- return false;
20444
- }
20445
- push(
20446
- section,
20447
- "warn",
20448
- `The ${kind} ${JSON.stringify(entry.name)} is stored under a name that does not fit the shape names are given now (a name ${FILE_NAME_RULE}). It still works from your own configuration, but a project file cannot name it. Rename ${entry.path} to a name that fits, and change what names it.`,
20449
- entry.name
20450
- );
20451
- return true;
20452
- }
20453
- function pushProvider(push, entry, cacheEnv, signIn) {
20777
+ function pushProvider(push, entry, cacheEnv, signIn, probeBaseUrl) {
20454
20778
  if (entry.raw === void 0) {
20455
20779
  push("provider", "fail", `${entry.path} is missing.`, entry.name);
20456
20780
  return;
@@ -20482,6 +20806,10 @@ function pushProvider(push, entry, cacheEnv, signIn) {
20482
20806
  if (!router && validated3.data.env?.ENABLE_TOOL_SEARCH === void 0) {
20483
20807
  push("provider", "warn", `${entry.name} does not set ENABLE_TOOL_SEARCH: a session on this provider keeps Claude Code's own API as its base URL, so it defers MCP tool loading and sends tool_reference payloads the upstream backend must understand. Set ENABLE_TOOL_SEARCH=false in the provider's env block to load tools upfront instead, when the backend does not support them.`, entry.name);
20484
20808
  }
20809
+ const unreachable = unreachableProviderLine(entry.name, validated3.data, probeBaseUrl);
20810
+ if (unreachable !== void 0) {
20811
+ push("provider", "fail", unreachable, entry.name);
20812
+ }
20485
20813
  if (signIn !== void 0 && isCodexProvider(validated3.data) && validated3.data.codex?.login === "chatgpt-sign-in") {
20486
20814
  const problem = signInProblem(signIn);
20487
20815
  if (problem !== void 0) {
@@ -20712,7 +21040,7 @@ function runDoctor(params) {
20712
21040
  if (!pushNameFinding(push, "provider", "provider", entry)) {
20713
21041
  continue;
20714
21042
  }
20715
- pushProvider(push, entry, params.credentialCache, params.chatgptSignIn);
21043
+ pushProvider(push, entry, params.credentialCache, params.chatgptSignIn, params.probeBaseUrl);
20716
21044
  }
20717
21045
  const providerNames = new Set(params.providers.map((entry) => entry.name));
20718
21046
  for (const finding of aliasFindings(params.providerAliases ?? {}, providerNames)) {
@@ -21019,6 +21347,7 @@ function collectDoctorReport(params) {
21019
21347
  configProfiles,
21020
21348
  providers,
21021
21349
  providerAliases: readProviderAliases(paths),
21350
+ probeBaseUrl: realBaseUrlProbe,
21022
21351
  renameJournals: listRenameJournals(realFarmFs, paths.identityRenamesDir),
21023
21352
  unreachableIdentities,
21024
21353
  identityRecords: { all: records, displaced: displacedIdentities.map((record) => ({ ...record, directoryPresent: fs14.existsSync(path42.join(paths.identitiesDir, record.id)) })), nameRenames: unfinishedNameRenames(paths).map((record) => ({ from: record.from, description: describeInterruptedNameRename(paths, record) })), strayNameRenameFiles: strayNameRenameRecordFiles(paths) },
@@ -21884,6 +22213,8 @@ var LaunchResolveInputSchema = z41.strictObject({
21884
22213
  var LaunchPoolDecisionSchema = z41.strictObject({
21885
22214
  name: z41.string(),
21886
22215
  reasons: z41.readonly(z41.array(z41.string())),
22216
+ /** The provider the ranking read for the chosen member, when the launch spends one in place of the member's Claude account. */
22217
+ provider: z41.string().optional(),
21887
22218
  movedOff: z41.strictObject({ identity: z41.string(), reason: z41.string() }).optional()
21888
22219
  });
21889
22220
  var LaunchDecisionSchema = z41.strictObject({
@@ -22634,7 +22965,7 @@ function createDoorHealthPublisher(hub, now, pid) {
22634
22965
  }
22635
22966
 
22636
22967
  // src/frontdoor/quotaExpiringEvents.ts
22637
- init_pick();
22968
+ init_windowLengths();
22638
22969
  var FINAL_SPAN_DENOMINATOR = 30;
22639
22970
  var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
22640
22971
  function createQuotaExpiringPublisher(hub, deps) {
@@ -24940,7 +25271,7 @@ init_launchWiring();
24940
25271
  init_argv();
24941
25272
  init_cascade();
24942
25273
  init_identity();
24943
- import os12 from "node:os";
25274
+ import os13 from "node:os";
24944
25275
 
24945
25276
  // src/launcher/poolRefresh.ts
24946
25277
  init_anthropicUsageRefresh();
@@ -24949,7 +25280,8 @@ async function refreshStalePoolMembers(params) {
24949
25280
  if (identities.size === 0) {
24950
25281
  return;
24951
25282
  }
24952
- await params.refresher.refreshStale(params.loadMembers([...identities]));
25283
+ const members = params.loadMembers([...identities]).filter((member) => member.provider === void 0 && member.providerError === void 0);
25284
+ await params.refresher.refreshStale(members);
24953
25285
  }
24954
25286
 
24955
25287
  // src/poolUsageRefresh.ts
@@ -24969,7 +25301,7 @@ async function refreshPools(params) {
24969
25301
  await refreshStalePoolMembers({
24970
25302
  poolNames: params.poolNames,
24971
25303
  pools: readPools(paths),
24972
- loadMembers: (identities) => loadPoolMembers(realFarmFs, paths, identities, Date.now(), (name) => identityIdOf(paths, name)),
25304
+ loadMembers: (identities) => loadPoolMembers(realFarmFs, paths, identities, Date.now(), (name) => identityIdOf(paths, name), params.providerOf),
24973
25305
  refresher
24974
25306
  });
24975
25307
  }
@@ -24991,12 +25323,13 @@ async function refreshPoolUsage(params) {
24991
25323
  poolNames: params.poolNames,
24992
25324
  spawnDaemon: daemonSpawnerFor(params.agentShim),
24993
25325
  log: params.log ?? (() => void 0),
24994
- ...params.refresher === void 0 ? {} : { refresher: params.refresher }
25326
+ ...params.refresher === void 0 ? {} : { refresher: params.refresher },
25327
+ ...params.providerOf === void 0 ? {} : { providerOf: params.providerOf }
24995
25328
  });
24996
25329
  }
24997
25330
  function poolSelectedByLaunch(options) {
24998
25331
  const paths = options.paths ?? resolveLayoutPaths();
24999
- const loaded = loadCascadeInput({ paths, home: os12.homedir(), cwd: options.cwd, read: cosmiconfigReader() });
25332
+ const loaded = loadCascadeInput({ paths, home: os13.homedir(), cwd: options.cwd, read: cosmiconfigReader() });
25000
25333
  return decideIdentity({
25001
25334
  env: options.env,
25002
25335
  argv0Identity: parseLauncherArgv(options.argv).identity,
@@ -25006,8 +25339,12 @@ function poolSelectedByLaunch(options) {
25006
25339
  }
25007
25340
  async function refreshLaunchPoolUsage(options) {
25008
25341
  const pool = poolSelectedByLaunch(options);
25342
+ const paths = options.paths ?? resolveLayoutPaths();
25343
+ const parsed = parseLauncherArgv(options.argv);
25009
25344
  await refreshPoolUsage({
25010
- ...options.paths === void 0 ? {} : { paths: options.paths },
25345
+ paths,
25346
+ // The provider each member's launch will spend, resolved as the launch resolves it, so a launch through a provider probes no Claude account.
25347
+ ...pool === void 0 ? {} : { providerOf: realMemberProviderResolver({ paths, cwd: options.cwd, env: options.env, ...parsed.provider === void 0 ? {} : { cliProvider: parsed.provider }, ...parsed.configProfile === void 0 ? {} : { cliFlagConfigProfile: parsed.configProfile } }) },
25011
25348
  cwd: options.cwd,
25012
25349
  poolNames: pool === void 0 ? [] : [pool],
25013
25350
  ...options.agentShim === void 0 ? {} : { agentShim: options.agentShim },
@@ -25379,6 +25716,7 @@ export {
25379
25716
  realCodexAppServerPort,
25380
25717
  realConnectCertStore,
25381
25718
  realConnectEffects,
25719
+ realMemberProviderResolver,
25382
25720
  realRcControlTransport,
25383
25721
  realRcEventDial,
25384
25722
  realRcStreamDial,