@adhdev/mesh-shared 1.0.82-rc.4 → 1.0.82-rc.5

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.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './git-normalize';
15
15
  export * from './session-normalize';
16
16
  export * from './node-normalize';
17
17
  export * from './node-facts';
18
+ export * from './quota-freshness';
18
19
  export * from './workspace-normalize';
19
20
  export * from './daemon-normalize';
20
21
  export * from './git-summarize';
package/dist/index.js CHANGED
@@ -97,6 +97,8 @@ __export(index_exports, {
97
97
  OUTBOUND_MESSAGE_ORIGINS: () => OUTBOUND_MESSAGE_ORIGINS,
98
98
  P2P_SIGNAL_TYPES: () => P2P_SIGNAL_TYPES,
99
99
  PROVIDER_FAILURES: () => PROVIDER_FAILURES,
100
+ QUOTA_BACKFILL_HORIZON_MS: () => QUOTA_BACKFILL_HORIZON_MS,
101
+ QUOTA_RETRY_INFLIGHT_GRACE_MS: () => QUOTA_RETRY_INFLIGHT_GRACE_MS,
100
102
  QUOTA_SUPPORTED_PROVIDERS: () => QUOTA_SUPPORTED_PROVIDERS,
101
103
  RECENT_SESSION_BUCKETS: () => RECENT_SESSION_BUCKETS,
102
104
  RECLAIMING_SEND_REFUSALS: () => RECLAIMING_SEND_REFUSALS,
@@ -145,6 +147,7 @@ __export(index_exports, {
145
147
  WORKER_TOOLS: () => WORKER_TOOLS,
146
148
  appendWorkerProtocolFooter: () => appendWorkerProtocolFooter,
147
149
  argsCarryStatusProbeMarker: () => argsCarryStatusProbeMarker,
150
+ assessQuotaFreshness: () => assessQuotaFreshness,
148
151
  buildSlotProposal: () => buildSlotProposal,
149
152
  canonicalDaemonId: () => canonicalDaemonId,
150
153
  classifySessionStatus: () => classifySessionStatus,
@@ -303,6 +306,7 @@ __export(index_exports, {
303
306
  meshUtf8ByteLength: () => meshUtf8ByteLength,
304
307
  meshWorkspacesEquivalent: () => meshWorkspacesEquivalent,
305
308
  mintMessageId: () => mintMessageId,
309
+ minutesUntilQuotaCheck: () => minutesUntilQuotaCheck,
306
310
  normalizeAuthOkLimits: () => normalizeAuthOkLimits,
307
311
  normalizeBrainSlot: () => normalizeBrainSlot,
308
312
  normalizeDifficultyBrainMap: () => normalizeDifficultyBrainMap,
@@ -656,6 +660,44 @@ function defaultProviderPriorityFromNodeFacts(facts) {
656
660
  return orderProvidersByBuiltinPreference(detected.length ? detected : enabled);
657
661
  }
658
662
 
663
+ // src/quota-freshness.ts
664
+ var QUOTA_RETRY_INFLIGHT_GRACE_MS = 6e4;
665
+ var QUOTA_BACKFILL_HORIZON_MS = 60 * 60 * 1e3;
666
+ function hasUsableWindow(window) {
667
+ return !!window && typeof window.usedPercent === "number" && Number.isFinite(window.usedPercent);
668
+ }
669
+ function hasReading(quota) {
670
+ if (hasUsableWindow(quota.session) || hasUsableWindow(quota.weekly)) return true;
671
+ return Array.isArray(quota.buckets) && quota.buckets.some((b) => !!b && typeof b.usedPercent === "number" && Number.isFinite(b.usedPercent));
672
+ }
673
+ function finiteMs(value) {
674
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
675
+ }
676
+ function backfillCheckAt(quota, now) {
677
+ const dataDue = finiteMs(quota.updatedAt);
678
+ const attempted = finiteMs(quota.metadata?.fetchedAt);
679
+ const dueAt = Math.max(
680
+ dataDue === void 0 ? Number.NEGATIVE_INFINITY : dataDue + QUOTA_BACKFILL_HORIZON_MS,
681
+ attempted === void 0 ? Number.NEGATIVE_INFINITY : attempted + QUOTA_BACKFILL_HORIZON_MS
682
+ );
683
+ return Number.isFinite(dueAt) && dueAt > now ? dueAt : void 0;
684
+ }
685
+ function assessQuotaFreshness(quota, now = Date.now()) {
686
+ const meta = quota.metadata;
687
+ const kind = meta?.failureKind;
688
+ const userMustAct = kind === "no-data" && quota.provider !== "codex-cli" || kind === "expired-token" && quota.provider === "antigravity-cli";
689
+ if (userMustAct && hasReading(quota)) return { cue: "stale", userMustAct: true };
690
+ if (meta?.lastGoodWindows !== true) return { userMustAct };
691
+ const retryAtMs = finiteMs(meta?.retryAtMs);
692
+ const retryStopped = meta?.retryExhausted === true || retryAtMs !== void 0 && retryAtMs + QUOTA_RETRY_INFLIGHT_GRACE_MS < now;
693
+ if (kind !== "no-data" && !retryStopped) return { cue: "refreshing", userMustAct: false };
694
+ const nextCheckAt = backfillCheckAt(quota, now);
695
+ return nextCheckAt === void 0 ? { cue: "stale", userMustAct: false } : { cue: "stale", userMustAct: false, nextCheckAt };
696
+ }
697
+ function minutesUntilQuotaCheck(nextCheckAt, now = Date.now()) {
698
+ return Math.max(1, Math.round((nextCheckAt - now) / 6e4));
699
+ }
700
+
659
701
  // src/workspace-normalize.ts
660
702
  function normalizeMeshWorkspaceForCompare(dir) {
661
703
  if (typeof dir !== "string") return "";
@@ -3828,6 +3870,8 @@ function stableMeshNodeRow(row) {
3828
3870
  OUTBOUND_MESSAGE_ORIGINS,
3829
3871
  P2P_SIGNAL_TYPES,
3830
3872
  PROVIDER_FAILURES,
3873
+ QUOTA_BACKFILL_HORIZON_MS,
3874
+ QUOTA_RETRY_INFLIGHT_GRACE_MS,
3831
3875
  QUOTA_SUPPORTED_PROVIDERS,
3832
3876
  RECENT_SESSION_BUCKETS,
3833
3877
  RECLAIMING_SEND_REFUSALS,
@@ -3876,6 +3920,7 @@ function stableMeshNodeRow(row) {
3876
3920
  WORKER_TOOLS,
3877
3921
  appendWorkerProtocolFooter,
3878
3922
  argsCarryStatusProbeMarker,
3923
+ assessQuotaFreshness,
3879
3924
  buildSlotProposal,
3880
3925
  canonicalDaemonId,
3881
3926
  classifySessionStatus,
@@ -4034,6 +4079,7 @@ function stableMeshNodeRow(row) {
4034
4079
  meshUtf8ByteLength,
4035
4080
  meshWorkspacesEquivalent,
4036
4081
  mintMessageId,
4082
+ minutesUntilQuotaCheck,
4037
4083
  normalizeAuthOkLimits,
4038
4084
  normalizeBrainSlot,
4039
4085
  normalizeDifficultyBrainMap,