@adhdev/daemon-standalone 1.0.49-rc.4 → 1.0.49-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.js CHANGED
@@ -37056,10 +37056,10 @@ var require_dist3 = __commonJS({
37056
37056
  }
37057
37057
  function getDaemonBuildInfo() {
37058
37058
  if (cached2) return cached2;
37059
- const commit = readInjected(true ? "9884122c80eb621bb1e4da9f0269c9bb2e8421fe" : void 0) ?? "unknown";
37060
- const commitShort = readInjected(true ? "9884122c" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
37061
- const version2 = readInjected(true ? "1.0.49-rc.4" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
37062
- const builtAt = readInjected(true ? "2026-08-14T10:06:01.458Z" : void 0);
37059
+ const commit = readInjected(true ? "0b3c203b7ae08f860c52a4dd7ee88edddd48d8cb" : void 0) ?? "unknown";
37060
+ const commitShort = readInjected(true ? "0b3c203b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
37061
+ const version2 = readInjected(true ? "1.0.49-rc.5" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
37062
+ const builtAt = readInjected(true ? "2026-08-14T13:19:52.123Z" : void 0);
37063
37063
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
37064
37064
  return cached2;
37065
37065
  }
@@ -57728,7 +57728,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57728
57728
  init_mesh_work_queue();
57729
57729
  }
57730
57730
  });
57731
- function quotaEntryFor(node, providerType) {
57731
+ function directQuotaEntryFor(node, providerType) {
57732
57732
  const facts = node?.nodeFacts;
57733
57733
  if (!facts || typeof facts !== "object") return null;
57734
57734
  const reportedAt = Number(facts.reportedAt);
@@ -57737,6 +57737,14 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57737
57737
  if (!quota || typeof quota !== "object") return null;
57738
57738
  return { facts: { reportedAt }, quota };
57739
57739
  }
57740
+ function quotaEntryFor(node, providerType, context) {
57741
+ const direct = directQuotaEntryFor(node, providerType);
57742
+ if (direct) return direct;
57743
+ const sourceNodeId = typeof node?.clonedFromNodeId === "string" ? node.clonedFromNodeId.trim() : "";
57744
+ if (!sourceNodeId || !Array.isArray(context?.nodes)) return null;
57745
+ const sourceNode = context.nodes.find((candidate) => candidate !== node && meshNodeIdMatches(candidate, sourceNodeId));
57746
+ return sourceNode ? directQuotaEntryFor(sourceNode, providerType) : null;
57747
+ }
57740
57748
  function quotaSnapshotAgeMs(facts, quota, now = Date.now()) {
57741
57749
  const updatedAt = Number(quota.updatedAt);
57742
57750
  if (!Number.isFinite(updatedAt) || updatedAt <= 0) return Number.POSITIVE_INFINITY;
@@ -57759,8 +57767,8 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57759
57767
  const reporterNowMs = Number(quota.updatedAt) + ageMs2;
57760
57768
  return resetsAt - reporterNowMs < imminentMs;
57761
57769
  }
57762
- function evaluateProviderQuotaGate(node, providerType, policy, now = Date.now()) {
57763
- const entry = quotaEntryFor(node, providerType);
57770
+ function evaluateProviderQuotaGate(node, providerType, policy, now = Date.now(), context) {
57771
+ const entry = quotaEntryFor(node, providerType, context);
57764
57772
  if (!entry) return null;
57765
57773
  const { facts, quota } = entry;
57766
57774
  if (quota.status !== "ok") {
@@ -57772,9 +57780,12 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57772
57780
  thresholdPercent: 0
57773
57781
  };
57774
57782
  }
57783
+ if (quota.metadata?.lastGoodWindows !== true || !isQuotaSnapshotFresh(facts, quota, policy, now)) {
57784
+ return null;
57785
+ }
57786
+ } else if (!isQuotaSnapshotFresh(facts, quota, policy, now)) {
57775
57787
  return null;
57776
57788
  }
57777
- if (!isQuotaSnapshotFresh(facts, quota, policy, now)) return null;
57778
57789
  const resolved = resolveQuotaRoutingPolicy(policy);
57779
57790
  const session = remainingPercent(quota.session);
57780
57791
  if (session !== void 0 && session < resolved.sessionMinRemainingPercent && !isSessionResetImminent(quota.session, facts, quota, resolved.sessionResetImminentMs, now)) {
@@ -57796,8 +57807,8 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57796
57807
  }
57797
57808
  return null;
57798
57809
  }
57799
- function expiryRiskForRanking(node, providerType, axis, policy, now = Date.now()) {
57800
- const entry = quotaEntryFor(node, providerType);
57810
+ function expiryRiskForRanking(node, providerType, axis, policy, now = Date.now(), context) {
57811
+ const entry = quotaEntryFor(node, providerType, context);
57801
57812
  if (!entry) return void 0;
57802
57813
  const { facts, quota } = entry;
57803
57814
  if (quota.status !== "ok") return void 0;
@@ -57816,19 +57827,19 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57816
57827
  const elapsedFraction = Math.min(1, Math.max(0, 1 - (resetsAt - reporterNowMs) / windowMs));
57817
57828
  return { remainingPercent: remaining, risk: remaining * elapsedFraction };
57818
57829
  }
57819
- function rankProvidersByQuotaGate(node, orderedProviderTypes, policy, now = Date.now()) {
57830
+ function rankProvidersByQuotaGate(node, orderedProviderTypes, policy, now = Date.now(), context) {
57820
57831
  const clear = [];
57821
57832
  const gated = [];
57822
57833
  for (const providerType of orderedProviderTypes) {
57823
- const block2 = evaluateProviderQuotaGate(node, providerType, policy, now);
57834
+ const block2 = evaluateProviderQuotaGate(node, providerType, policy, now, context);
57824
57835
  if (block2) gated.push({ providerType, block: block2 });
57825
57836
  else clear.push(providerType);
57826
57837
  }
57827
- const weeklyByProvider = new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "weekly", policy, now)]));
57838
+ const weeklyByProvider = new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "weekly", policy, now, context)]));
57828
57839
  const headroomPercent = resolveQuotaRoutingPolicy(policy).sessionAxisWeeklyHeadroomPercent;
57829
57840
  const weeklyMeasured = [...weeklyByProvider.values()].filter((w) => w !== void 0);
57830
57841
  const sessionAxisActive = weeklyMeasured.length > 0 && weeklyMeasured.every((w) => w.remainingPercent > headroomPercent);
57831
- const sessionByProvider = sessionAxisActive ? new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "session", policy, now)])) : void 0;
57842
+ const sessionByProvider = sessionAxisActive ? new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "session", policy, now, context)])) : void 0;
57832
57843
  clear.sort((a, b) => {
57833
57844
  const wa = weeklyByProvider.get(a);
57834
57845
  const wb = weeklyByProvider.get(b);
@@ -57851,13 +57862,13 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57851
57862
  });
57852
57863
  return { clear, gated };
57853
57864
  }
57854
- function resolveRecoveryRelaunchProvider(node, failedProviderType, nodeProviderTypes = [], policy, now = Date.now()) {
57865
+ function resolveRecoveryRelaunchProvider(node, failedProviderType, nodeProviderTypes = [], policy, now = Date.now(), context) {
57855
57866
  if (!failedProviderType) return { action: "block" };
57856
- const block2 = evaluateProviderQuotaGate(node, failedProviderType, policy, now);
57867
+ const block2 = evaluateProviderQuotaGate(node, failedProviderType, policy, now, context);
57857
57868
  if (!block2) return { action: "keep", providerType: failedProviderType };
57858
57869
  const alternatives = nodeProviderTypes.filter((p) => p && p !== failedProviderType);
57859
57870
  if (alternatives.length) {
57860
- const ranked = rankProvidersByQuotaGate(node, alternatives, policy, now);
57871
+ const ranked = rankProvidersByQuotaGate(node, alternatives, policy, now, context);
57861
57872
  if (ranked.clear.length) {
57862
57873
  return { action: "fallback", providerType: ranked.clear[0], block: block2 };
57863
57874
  }
@@ -57872,9 +57883,9 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57872
57883
  }
57873
57884
  return `QUOTA GATE: skipping recovery relaunch for node ${nodeId} \u2014 ${cause} and the node has no gate-clear alternative${taskId ? `; task ${taskId}` : ""} stays queued until a quota window resets`;
57874
57885
  }
57875
- function quotaRiskSnapshotForCandidates(node, orderedProviderTypes, policy, now = Date.now()) {
57886
+ function quotaRiskSnapshotForCandidates(node, orderedProviderTypes, policy, now = Date.now(), context) {
57876
57887
  return orderedProviderTypes.map((providerType) => {
57877
- const w = expiryRiskForRanking(node, providerType, "weekly", policy, now);
57888
+ const w = expiryRiskForRanking(node, providerType, "weekly", policy, now, context);
57878
57889
  return {
57879
57890
  providerType,
57880
57891
  ...w ? { remainingPercent: w.remainingPercent, risk: w.risk } : {}
@@ -57918,6 +57929,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57918
57929
  var init_mesh_quota_routing = __esm2({
57919
57930
  "src/mesh/mesh-quota-routing.ts"() {
57920
57931
  "use strict";
57932
+ init_dist();
57921
57933
  init_repo_mesh_types();
57922
57934
  PROVIDER_QUOTA_SESSION_LOW_SKIP_REASON = "provider_quota_session_low";
57923
57935
  PROVIDER_QUOTA_WEEKLY_LOW_SKIP_REASON = "provider_quota_weekly_low";
@@ -61957,7 +61969,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
61957
61969
  LOG2.info("MeshQueue", `Deferring queue claim for node ${nodeId} (${sessionId}): an auto fast-forward is mutating its workspace \u2014 task left pending, claim re-fires next tick`);
61958
61970
  return false;
61959
61971
  }
61960
- const quotaClaimBlock = evaluateProviderQuotaGate(node, providerType, mesh?.policy?.quotaRouting ?? null);
61972
+ const quotaClaimBlock = evaluateProviderQuotaGate(node, providerType, mesh?.policy?.quotaRouting ?? null, Date.now(), mesh);
61961
61973
  if (quotaClaimBlock) {
61962
61974
  if (quotaClaimBlock.reason === PROVIDER_QUOTA_EXHAUSTED_SKIP_REASON) {
61963
61975
  LOG2.info("MeshQueue", `QUOTA GATE: deferring queue claim for node ${nodeId} (${sessionId}): provider '${providerType}' reported its quota EXHAUSTED \u2014 task left pending until the quota resets`);
@@ -62434,7 +62446,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
62434
62446
  retractActionableSkipIfPreviouslyNotified(meshId, taskId);
62435
62447
  }
62436
62448
  }
62437
- async function resolveUsableProvider(components, nodeId, node, meshId, requiredTags, task, quotaRouting) {
62449
+ async function resolveUsableProvider(components, nodeId, node, meshId, requiredTags, task, quotaRouting, quotaFactsContext) {
62438
62450
  const providerLoader = components.providerLoader;
62439
62451
  if (!providerLoader) return { reason: "provider_loader_unavailable" };
62440
62452
  const slots = resolveNodeCapabilitySlots(node, meshId);
@@ -62482,8 +62494,8 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
62482
62494
  if (!candidates.length) {
62483
62495
  return { reason: `provider_priority_unusable: ${failed.join("; ") || nodeId}` };
62484
62496
  }
62485
- const ranked = rankProvidersByQuotaGate(node, candidates.map((c) => c.providerType), quotaRouting);
62486
- const riskSnapshot = quotaRiskSnapshotForCandidates(node, ranked.clear, quotaRouting);
62497
+ const ranked = rankProvidersByQuotaGate(node, candidates.map((c) => c.providerType), quotaRouting, Date.now(), quotaFactsContext);
62498
+ const riskSnapshot = quotaRiskSnapshotForCandidates(node, ranked.clear, quotaRouting, Date.now(), quotaFactsContext);
62487
62499
  if (!ranked.clear.length) {
62488
62500
  const detail = ranked.gated.map((g) => `${g.providerType}: ${g.block.reason}`).join("; ");
62489
62501
  LOG2.info("MeshQueue", `QUOTA GATE: every usable provider on node ${nodeId} is quota-gated (${detail}); leaving the task queued until a quota window resets`);
@@ -62734,7 +62746,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
62734
62746
  }
62735
62747
  autoLaunchInProgress.add(launchKey);
62736
62748
  try {
62737
- const resolved = await resolveUsableProvider(components, nodeId, node, meshId, task.requiredTags, { difficulty: task.difficulty, requiredTags: task.requiredTags }, mesh?.policy?.quotaRouting ?? null);
62749
+ const resolved = await resolveUsableProvider(components, nodeId, node, meshId, task.requiredTags, { difficulty: task.difficulty, requiredTags: task.requiredTags }, mesh?.policy?.quotaRouting ?? null, mesh);
62738
62750
  if (!resolved.providerType) {
62739
62751
  markSkip(nodeId, resolved.reason || "provider_unusable");
62740
62752
  continue;
@@ -66409,7 +66421,9 @@ ${cleanBody}`;
66409
66421
  node,
66410
66422
  recoveryContext.failedProviderType,
66411
66423
  resolveNodeCapabilitySlots(node, args.meshId).map((s2) => s2.provider),
66412
- mesh?.policy?.quotaRouting ?? null
66424
+ mesh?.policy?.quotaRouting ?? null,
66425
+ Date.now(),
66426
+ mesh
66413
66427
  ) : { action: "block" };
66414
66428
  const relaunchProviderType = relaunch.action === "block" ? null : relaunch.providerType;
66415
66429
  if (node) {