instar 1.3.545 → 1.3.546

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgCH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAS3D,OAAO,EAAE,eAAe,EAAiC,MAAM,iCAAiC,CAAC;AAuBjG,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAiH7D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAsBtD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC1C,OAAO,CAUT;AAyID,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAm3CD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,eAAe,EACzB,cAAc,EAAE,cAAc,EAC9B,YAAY,CAAC,EAAE,YAAY,EAC3B,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,WAAW,EACzB,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAGvE,UAAU,CAAC,EAAE,MAAM,OAAO,8BAA8B,EAAE,WAAW,GAAG,IAAI,EAK5E,qBAAqB,CAAC,EAAE,MAAM,OAAO,gCAAgC,EAAE,kBAAkB,GAAG,IAAI,EAKhG,mBAAmB,CAAC,EAAE,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AE,WAAW,EACzB,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAGvE,UAAU,CAAC,EAAE,MAAM,OAAO,8BAA8B,EAAE,WAAW,GAAG,IAAI,EAK5E,qBAAqB,CAAC,EAAE,MAAM,OAAO,gCAAgC,EAAE,kBAAkB,GAAG,IAAI,EAKhG,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,GACpD,IAAI,CA8eN;AA2lBD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA4lbtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
@@ -8645,6 +8645,48 @@ export async function startServer(options) {
8645
8645
  maxForcedPerWindow: config.subscriptionPool?.credentialRepointing?.maxForcedManualSwapsPerWindow,
8646
8646
  forcedWindowMs: config.subscriptionPool?.credentialRepointing?.forcedManualSwapWindowMs,
8647
8647
  });
8648
+ // B3b — the autonomous balancer (Increment B). Wraps the pure §2.4 decision core in a pass
8649
+ // loop and actuates via the SAME gated swap executor. isEnabled mirrors the location gate
8650
+ // (dev-gate-resolved AND the §2.10 env-token gate), and the executor's own dryRun keeps it a
8651
+ // dry-run dogfood on a dev agent (full decision loop + audit, ZERO writes) until dryRun:false.
8652
+ const { CredentialRebalancer } = await import('../core/CredentialRebalancer.js');
8653
+ const { mapSlots: credMapSlots, mapAccounts: credMapAccounts, resolveRebalancerConfig: credResolveBalancerConfig } = await import('../core/CredentialRebalancerSnapshot.js');
8654
+ const CRED_DEFAULT_SLOT = '~/.claude';
8655
+ const credentialRebalancer = new CredentialRebalancer({
8656
+ // Same gate as the location gate: dev-gate-resolved AND not env-token-refused.
8657
+ isEnabled: () => resolveDevAgentGate(config.subscriptionPool?.credentialRepointing?.enabled, config) &&
8658
+ !credentialEnvTokenGate.evaluate().refused,
8659
+ isDryRun: () => config.subscriptionPool?.credentialRepointing?.dryRun !== false,
8660
+ listSlots: () => credMapSlots(credentialLocationLedger.getAssignments(), { defaultSlot: CRED_DEFAULT_SLOT }),
8661
+ listAccounts: () => credMapAccounts(subscriptionPool.list(), Date.now()),
8662
+ resolveConfig: () => credResolveBalancerConfig({
8663
+ ...(config.subscriptionPool?.credentialRepointing?.balancer ?? {}),
8664
+ slotCount: credentialLocationLedger.getAssignments().length,
8665
+ // Dry-run dogfood defaults: keep the account currently in ~/.claude as the desired
8666
+ // default (objective-0 keeps it alive). An explicit operator default-account config +
8667
+ // tmux-activity busyness for the drain target are refinements <!-- tracked: 20905 -->.
8668
+ desiredDefaultAccountId: credentialLocationLedger.tenantOf(CRED_DEFAULT_SLOT) ?? null,
8669
+ }),
8670
+ swap: async (a, b) => {
8671
+ const r = await credentialSwapExecutor.swap(a, b);
8672
+ return { ok: r.outcome === 'swapped' || r.outcome === 'dry-run', detail: r.reason };
8673
+ },
8674
+ emitDegraded: (m) => {
8675
+ try {
8676
+ DegradationReporter.getInstance().report({
8677
+ feature: 'CredentialRebalancer', primary: 'autonomous balancer pass',
8678
+ fallback: 'pass suspended (breaker / floor)', reason: m, impact: 'credential rebalancing degraded',
8679
+ });
8680
+ }
8681
+ catch { /* @silent-fallback-ok: degradation report is best-effort observability; a throwing reporter must never break the dark/dry-run pass */ }
8682
+ },
8683
+ emitAttention: (m) => {
8684
+ void credentialAuditEmit.attention({
8685
+ id: `credential-rebalancer-${credentialLocationLedger.version}`,
8686
+ title: 'Credential rebalancer', summary: m, category: 'credential-repointing', priority: 'NORMAL',
8687
+ });
8688
+ },
8689
+ });
8648
8690
  const credentialRepointing = {
8649
8691
  ledger: credentialLocationLedger,
8650
8692
  swapExecutor: credentialSwapExecutor,
@@ -8652,6 +8694,7 @@ export async function startServer(options) {
8652
8694
  audit: credentialAuditEmit,
8653
8695
  levers: credentialManualLevers,
8654
8696
  envTokenGate: credentialEnvTokenGate,
8697
+ rebalancer: credentialRebalancer,
8655
8698
  readBlob: async (slot) => {
8656
8699
  const raw = await defaultKeychainExec.readService(credSwapService(slot));
8657
8700
  if (!raw)
@@ -8666,6 +8709,22 @@ export async function startServer(options) {
8666
8709
  }
8667
8710
  },
8668
8711
  };
8712
+ // B3b — the periodic balancer pass. tick() is a strict no-op while the feature resolves dark
8713
+ // (so the timer can always run; the gate lives INSIDE tick()), and on a dev agent it runs the
8714
+ // full decision loop in dry-run (zero writes). REENTRANCY-GUARDED: a slow tick never overlaps
8715
+ // its successor. unref()'d so it never holds the process open. Interval clamped [1min, 60min].
8716
+ let credRebalancerTickInFlight = false;
8717
+ const credRebalancerPassMs = Math.min(3_600_000, Math.max(60_000, config.subscriptionPool?.credentialRepointing?.balancer?.passIntervalMs ?? 300_000));
8718
+ const credRebalancerTimer = setInterval(() => {
8719
+ if (credRebalancerTickInFlight)
8720
+ return; // reentrancy guard — skip if the prior tick is still running
8721
+ credRebalancerTickInFlight = true;
8722
+ void credentialRebalancer
8723
+ .tick()
8724
+ .catch((e) => console.warn(`[CredentialRebalancer] tick error: ${e instanceof Error ? e.message : String(e)}`))
8725
+ .finally(() => { credRebalancerTickInFlight = false; });
8726
+ }, credRebalancerPassMs);
8727
+ credRebalancerTimer.unref?.();
8669
8728
  // QuotaPoller — per-account live quota reader (P1.2 of the Subscription &
8670
8729
  // Auth Standard). Reads each account's 5h/weekly utilization + reset dates
8671
8730
  // via the OAuth usage endpoint (transient per-account token, never persisted)