@adhdev/daemon-standalone 1.0.49-rc.4 → 1.0.49-rc.6

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 ? "21db9be61179f54103c284dc170a085b6ae3537e" : void 0) ?? "unknown";
37060
+ const commitShort = readInjected(true ? "21db9be6" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
37061
+ const version2 = readInjected(true ? "1.0.49-rc.6" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
37062
+ const builtAt = readInjected(true ? "2026-08-14T14:46:33.356Z" : 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,10 +57767,23 @@ 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 isRetainedWindowTrustworthy(window, facts, quota, policy, now) {
57771
+ const resetsAt = Number(window?.resetsAt);
57772
+ if (!Number.isFinite(resetsAt) || resetsAt <= 0) {
57773
+ return isQuotaSnapshotFresh(facts, quota, policy, now);
57774
+ }
57775
+ const ageMs2 = quotaSnapshotAgeMs(facts, quota, now);
57776
+ if (!Number.isFinite(ageMs2)) return false;
57777
+ const reporterNowMs = Number(quota.updatedAt) + ageMs2;
57778
+ if (!Number.isFinite(reporterNowMs)) return false;
57779
+ return resetsAt > reporterNowMs;
57780
+ }
57781
+ function evaluateProviderQuotaGate(node, providerType, policy, now = Date.now(), context) {
57782
+ const entry = quotaEntryFor(node, providerType, context);
57764
57783
  if (!entry) return null;
57765
57784
  const { facts, quota } = entry;
57785
+ let sessionTrustworthy = true;
57786
+ let weeklyTrustworthy = true;
57766
57787
  if (quota.status !== "ok") {
57767
57788
  if (quota.status === "error" && quota.metadata?.failureKind === "quota-exhausted" && isQuotaSnapshotFresh(facts, quota, policy, now)) {
57768
57789
  return {
@@ -57772,12 +57793,15 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57772
57793
  thresholdPercent: 0
57773
57794
  };
57774
57795
  }
57796
+ if (quota.metadata?.lastGoodWindows !== true) return null;
57797
+ sessionTrustworthy = isRetainedWindowTrustworthy(quota.session, facts, quota, policy, now);
57798
+ weeklyTrustworthy = isRetainedWindowTrustworthy(quota.weekly, facts, quota, policy, now);
57799
+ } else if (!isQuotaSnapshotFresh(facts, quota, policy, now)) {
57775
57800
  return null;
57776
57801
  }
57777
- if (!isQuotaSnapshotFresh(facts, quota, policy, now)) return null;
57778
57802
  const resolved = resolveQuotaRoutingPolicy(policy);
57779
57803
  const session = remainingPercent(quota.session);
57780
- if (session !== void 0 && session < resolved.sessionMinRemainingPercent && !isSessionResetImminent(quota.session, facts, quota, resolved.sessionResetImminentMs, now)) {
57804
+ if (sessionTrustworthy && session !== void 0 && session < resolved.sessionMinRemainingPercent && !isSessionResetImminent(quota.session, facts, quota, resolved.sessionResetImminentMs, now)) {
57781
57805
  return {
57782
57806
  reason: PROVIDER_QUOTA_SESSION_LOW_SKIP_REASON,
57783
57807
  window: "session",
@@ -57786,7 +57810,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57786
57810
  };
57787
57811
  }
57788
57812
  const weekly = remainingPercent(quota.weekly);
57789
- if (weekly !== void 0 && weekly < resolved.weeklyMinRemainingPercent) {
57813
+ if (weeklyTrustworthy && weekly !== void 0 && weekly < resolved.weeklyMinRemainingPercent) {
57790
57814
  return {
57791
57815
  reason: PROVIDER_QUOTA_WEEKLY_LOW_SKIP_REASON,
57792
57816
  window: "weekly",
@@ -57796,8 +57820,8 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57796
57820
  }
57797
57821
  return null;
57798
57822
  }
57799
- function expiryRiskForRanking(node, providerType, axis, policy, now = Date.now()) {
57800
- const entry = quotaEntryFor(node, providerType);
57823
+ function expiryRiskForRanking(node, providerType, axis, policy, now = Date.now(), context) {
57824
+ const entry = quotaEntryFor(node, providerType, context);
57801
57825
  if (!entry) return void 0;
57802
57826
  const { facts, quota } = entry;
57803
57827
  if (quota.status !== "ok") return void 0;
@@ -57816,19 +57840,19 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57816
57840
  const elapsedFraction = Math.min(1, Math.max(0, 1 - (resetsAt - reporterNowMs) / windowMs));
57817
57841
  return { remainingPercent: remaining, risk: remaining * elapsedFraction };
57818
57842
  }
57819
- function rankProvidersByQuotaGate(node, orderedProviderTypes, policy, now = Date.now()) {
57843
+ function rankProvidersByQuotaGate(node, orderedProviderTypes, policy, now = Date.now(), context) {
57820
57844
  const clear = [];
57821
57845
  const gated = [];
57822
57846
  for (const providerType of orderedProviderTypes) {
57823
- const block2 = evaluateProviderQuotaGate(node, providerType, policy, now);
57847
+ const block2 = evaluateProviderQuotaGate(node, providerType, policy, now, context);
57824
57848
  if (block2) gated.push({ providerType, block: block2 });
57825
57849
  else clear.push(providerType);
57826
57850
  }
57827
- const weeklyByProvider = new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "weekly", policy, now)]));
57851
+ const weeklyByProvider = new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "weekly", policy, now, context)]));
57828
57852
  const headroomPercent = resolveQuotaRoutingPolicy(policy).sessionAxisWeeklyHeadroomPercent;
57829
57853
  const weeklyMeasured = [...weeklyByProvider.values()].filter((w) => w !== void 0);
57830
57854
  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;
57855
+ const sessionByProvider = sessionAxisActive ? new Map(clear.map((p) => [p, expiryRiskForRanking(node, p, "session", policy, now, context)])) : void 0;
57832
57856
  clear.sort((a, b) => {
57833
57857
  const wa = weeklyByProvider.get(a);
57834
57858
  const wb = weeklyByProvider.get(b);
@@ -57851,13 +57875,13 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57851
57875
  });
57852
57876
  return { clear, gated };
57853
57877
  }
57854
- function resolveRecoveryRelaunchProvider(node, failedProviderType, nodeProviderTypes = [], policy, now = Date.now()) {
57878
+ function resolveRecoveryRelaunchProvider(node, failedProviderType, nodeProviderTypes = [], policy, now = Date.now(), context) {
57855
57879
  if (!failedProviderType) return { action: "block" };
57856
- const block2 = evaluateProviderQuotaGate(node, failedProviderType, policy, now);
57880
+ const block2 = evaluateProviderQuotaGate(node, failedProviderType, policy, now, context);
57857
57881
  if (!block2) return { action: "keep", providerType: failedProviderType };
57858
57882
  const alternatives = nodeProviderTypes.filter((p) => p && p !== failedProviderType);
57859
57883
  if (alternatives.length) {
57860
- const ranked = rankProvidersByQuotaGate(node, alternatives, policy, now);
57884
+ const ranked = rankProvidersByQuotaGate(node, alternatives, policy, now, context);
57861
57885
  if (ranked.clear.length) {
57862
57886
  return { action: "fallback", providerType: ranked.clear[0], block: block2 };
57863
57887
  }
@@ -57872,9 +57896,9 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57872
57896
  }
57873
57897
  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
57898
  }
57875
- function quotaRiskSnapshotForCandidates(node, orderedProviderTypes, policy, now = Date.now()) {
57899
+ function quotaRiskSnapshotForCandidates(node, orderedProviderTypes, policy, now = Date.now(), context) {
57876
57900
  return orderedProviderTypes.map((providerType) => {
57877
- const w = expiryRiskForRanking(node, providerType, "weekly", policy, now);
57901
+ const w = expiryRiskForRanking(node, providerType, "weekly", policy, now, context);
57878
57902
  return {
57879
57903
  providerType,
57880
57904
  ...w ? { remainingPercent: w.remainingPercent, risk: w.risk } : {}
@@ -57918,6 +57942,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
57918
57942
  var init_mesh_quota_routing = __esm2({
57919
57943
  "src/mesh/mesh-quota-routing.ts"() {
57920
57944
  "use strict";
57945
+ init_dist();
57921
57946
  init_repo_mesh_types();
57922
57947
  PROVIDER_QUOTA_SESSION_LOW_SKIP_REASON = "provider_quota_session_low";
57923
57948
  PROVIDER_QUOTA_WEEKLY_LOW_SKIP_REASON = "provider_quota_weekly_low";
@@ -61957,7 +61982,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
61957
61982
  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
61983
  return false;
61959
61984
  }
61960
- const quotaClaimBlock = evaluateProviderQuotaGate(node, providerType, mesh?.policy?.quotaRouting ?? null);
61985
+ const quotaClaimBlock = evaluateProviderQuotaGate(node, providerType, mesh?.policy?.quotaRouting ?? null, Date.now(), mesh);
61961
61986
  if (quotaClaimBlock) {
61962
61987
  if (quotaClaimBlock.reason === PROVIDER_QUOTA_EXHAUSTED_SKIP_REASON) {
61963
61988
  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 +62459,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
62434
62459
  retractActionableSkipIfPreviouslyNotified(meshId, taskId);
62435
62460
  }
62436
62461
  }
62437
- async function resolveUsableProvider(components, nodeId, node, meshId, requiredTags, task, quotaRouting) {
62462
+ async function resolveUsableProvider(components, nodeId, node, meshId, requiredTags, task, quotaRouting, quotaFactsContext) {
62438
62463
  const providerLoader = components.providerLoader;
62439
62464
  if (!providerLoader) return { reason: "provider_loader_unavailable" };
62440
62465
  const slots = resolveNodeCapabilitySlots(node, meshId);
@@ -62482,8 +62507,8 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
62482
62507
  if (!candidates.length) {
62483
62508
  return { reason: `provider_priority_unusable: ${failed.join("; ") || nodeId}` };
62484
62509
  }
62485
- const ranked = rankProvidersByQuotaGate(node, candidates.map((c) => c.providerType), quotaRouting);
62486
- const riskSnapshot = quotaRiskSnapshotForCandidates(node, ranked.clear, quotaRouting);
62510
+ const ranked = rankProvidersByQuotaGate(node, candidates.map((c) => c.providerType), quotaRouting, Date.now(), quotaFactsContext);
62511
+ const riskSnapshot = quotaRiskSnapshotForCandidates(node, ranked.clear, quotaRouting, Date.now(), quotaFactsContext);
62487
62512
  if (!ranked.clear.length) {
62488
62513
  const detail = ranked.gated.map((g) => `${g.providerType}: ${g.block.reason}`).join("; ");
62489
62514
  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 +62759,7 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
62734
62759
  }
62735
62760
  autoLaunchInProgress.add(launchKey);
62736
62761
  try {
62737
- const resolved = await resolveUsableProvider(components, nodeId, node, meshId, task.requiredTags, { difficulty: task.difficulty, requiredTags: task.requiredTags }, mesh?.policy?.quotaRouting ?? null);
62762
+ const resolved = await resolveUsableProvider(components, nodeId, node, meshId, task.requiredTags, { difficulty: task.difficulty, requiredTags: task.requiredTags }, mesh?.policy?.quotaRouting ?? null, mesh);
62738
62763
  if (!resolved.providerType) {
62739
62764
  markSkip(nodeId, resolved.reason || "provider_unusable");
62740
62765
  continue;
@@ -66409,7 +66434,9 @@ ${cleanBody}`;
66409
66434
  node,
66410
66435
  recoveryContext.failedProviderType,
66411
66436
  resolveNodeCapabilitySlots(node, args.meshId).map((s2) => s2.provider),
66412
- mesh?.policy?.quotaRouting ?? null
66437
+ mesh?.policy?.quotaRouting ?? null,
66438
+ Date.now(),
66439
+ mesh
66413
66440
  ) : { action: "block" };
66414
66441
  const relaunchProviderType = relaunch.action === "block" ? null : relaunch.providerType;
66415
66442
  if (node) {