@adhdev/mesh-shared 1.0.82-rc.1 → 1.0.82-rc.11

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
@@ -300,6 +300,44 @@ function defaultProviderPriorityFromNodeFacts(facts) {
300
300
  return orderProvidersByBuiltinPreference(detected.length ? detected : enabled);
301
301
  }
302
302
 
303
+ // src/quota-freshness.ts
304
+ var QUOTA_RETRY_INFLIGHT_GRACE_MS = 6e4;
305
+ var QUOTA_BACKFILL_HORIZON_MS = 60 * 60 * 1e3;
306
+ function hasUsableWindow(window) {
307
+ return !!window && typeof window.usedPercent === "number" && Number.isFinite(window.usedPercent);
308
+ }
309
+ function hasReading(quota) {
310
+ if (hasUsableWindow(quota.session) || hasUsableWindow(quota.weekly)) return true;
311
+ return Array.isArray(quota.buckets) && quota.buckets.some((b) => !!b && typeof b.usedPercent === "number" && Number.isFinite(b.usedPercent));
312
+ }
313
+ function finiteMs(value) {
314
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
315
+ }
316
+ function backfillCheckAt(quota, now) {
317
+ const dataDue = finiteMs(quota.updatedAt);
318
+ const attempted = finiteMs(quota.metadata?.fetchedAt);
319
+ const dueAt = Math.max(
320
+ dataDue === void 0 ? Number.NEGATIVE_INFINITY : dataDue + QUOTA_BACKFILL_HORIZON_MS,
321
+ attempted === void 0 ? Number.NEGATIVE_INFINITY : attempted + QUOTA_BACKFILL_HORIZON_MS
322
+ );
323
+ return Number.isFinite(dueAt) && dueAt > now ? dueAt : void 0;
324
+ }
325
+ function assessQuotaFreshness(quota, now = Date.now()) {
326
+ const meta = quota.metadata;
327
+ const kind = meta?.failureKind;
328
+ const userMustAct = kind === "no-data" && quota.provider !== "codex-cli" || kind === "expired-token" && quota.provider === "antigravity-cli";
329
+ if (userMustAct && hasReading(quota)) return { cue: "stale", userMustAct: true };
330
+ if (meta?.lastGoodWindows !== true) return { userMustAct };
331
+ const retryAtMs = finiteMs(meta?.retryAtMs);
332
+ const retryStopped = meta?.retryExhausted === true || retryAtMs !== void 0 && retryAtMs + QUOTA_RETRY_INFLIGHT_GRACE_MS < now;
333
+ if (kind !== "no-data" && !retryStopped) return { cue: "refreshing", userMustAct: false };
334
+ const nextCheckAt = backfillCheckAt(quota, now);
335
+ return nextCheckAt === void 0 ? { cue: "stale", userMustAct: false } : { cue: "stale", userMustAct: false, nextCheckAt };
336
+ }
337
+ function minutesUntilQuotaCheck(nextCheckAt, now = Date.now()) {
338
+ return Math.max(1, Math.round((nextCheckAt - now) / 6e4));
339
+ }
340
+
303
341
  // src/workspace-normalize.ts
304
342
  function normalizeMeshWorkspaceForCompare(dir) {
305
343
  if (typeof dir !== "string") return "";
@@ -3050,14 +3088,11 @@ function normalizeOwnedPaths(input) {
3050
3088
  }
3051
3089
  function entryContains(base, path) {
3052
3090
  if (path === base.path) return true;
3053
- if (base.subtree && (path === base.path || path.startsWith(`${base.path}/`))) return true;
3091
+ if (base.subtree && (base.path === "" || path.startsWith(`${base.path}/`))) return true;
3054
3092
  return false;
3055
3093
  }
3056
3094
  function entriesOverlap(a, b) {
3057
- if (a.path === b.path) return true;
3058
- if (a.subtree && (b.path === a.path || b.path.startsWith(`${a.path}/`))) return true;
3059
- if (b.subtree && (a.path === b.path || a.path.startsWith(`${b.path}/`))) return true;
3060
- return false;
3095
+ return entryContains(a, b.path) || entryContains(b, a.path);
3061
3096
  }
3062
3097
  function pathsOverlap(a, b) {
3063
3098
  if (a.paths.length === 0 || b.paths.length === 0) return false;
@@ -3329,7 +3364,15 @@ function foldKeyedDoc(held, delta, spec) {
3329
3364
  const heldList = heldCollections.get(path);
3330
3365
  if (change?.absent) {
3331
3366
  const [head2, tail2] = splitPath(path);
3332
- if (!tail2) delete next[head2];
3367
+ if (!tail2) {
3368
+ delete next[head2];
3369
+ continue;
3370
+ }
3371
+ const parent2 = next[head2];
3372
+ if (!isRecord3(parent2) || !(tail2 in parent2)) continue;
3373
+ const copy = { ...parent2 };
3374
+ delete copy[tail2];
3375
+ next[head2] = copy;
3333
3376
  continue;
3334
3377
  }
3335
3378
  if (!change && heldList === void 0) continue;
@@ -3471,6 +3514,8 @@ export {
3471
3514
  OUTBOUND_MESSAGE_ORIGINS,
3472
3515
  P2P_SIGNAL_TYPES,
3473
3516
  PROVIDER_FAILURES,
3517
+ QUOTA_BACKFILL_HORIZON_MS,
3518
+ QUOTA_RETRY_INFLIGHT_GRACE_MS,
3474
3519
  QUOTA_SUPPORTED_PROVIDERS,
3475
3520
  RECENT_SESSION_BUCKETS,
3476
3521
  RECLAIMING_SEND_REFUSALS,
@@ -3519,6 +3564,7 @@ export {
3519
3564
  WORKER_TOOLS,
3520
3565
  appendWorkerProtocolFooter,
3521
3566
  argsCarryStatusProbeMarker,
3567
+ assessQuotaFreshness,
3522
3568
  buildSlotProposal,
3523
3569
  canonicalDaemonId,
3524
3570
  classifySessionStatus,
@@ -3677,6 +3723,7 @@ export {
3677
3723
  meshUtf8ByteLength,
3678
3724
  meshWorkspacesEquivalent,
3679
3725
  mintMessageId,
3726
+ minutesUntilQuotaCheck,
3680
3727
  normalizeAuthOkLimits,
3681
3728
  normalizeBrainSlot,
3682
3729
  normalizeDifficultyBrainMap,