nexus-agents 2.117.3 → 2.118.0

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.
@@ -115,7 +115,7 @@ import {
115
115
  DEFAULT_TASK_TTL_MS,
116
116
  DEFAULT_TOOL_RATE_LIMITS,
117
117
  clampTaskTtl
118
- } from "./chunk-KU7GX43O.js";
118
+ } from "./chunk-VPWMPJYW.js";
119
119
  import {
120
120
  resolveInsideRoot
121
121
  } from "./chunk-NUBSJGQZ.js";
@@ -41679,6 +41679,22 @@ function createBudgetGuard(budget) {
41679
41679
  });
41680
41680
  return new BudgetGuard(breaker);
41681
41681
  }
41682
+ var DEFAULT_BUDGET_TOLERANCE = 1.5;
41683
+ var BUDGET_TOLERANCE_ENV = "NEXUS_BUDGET_TOLERANCE";
41684
+ function resolveBudgetTolerance() {
41685
+ const raw = process.env[BUDGET_TOLERANCE_ENV];
41686
+ if (raw === void 0 || raw.trim() === "") return DEFAULT_BUDGET_TOLERANCE;
41687
+ const parsed = Number(raw);
41688
+ if (!Number.isFinite(parsed) || parsed < 1) return DEFAULT_BUDGET_TOLERANCE;
41689
+ return parsed;
41690
+ }
41691
+ function estimateRelativeBudget(estimateTokens2, tolerance = DEFAULT_BUDGET_TOLERANCE) {
41692
+ if (estimateTokens2 === void 0 || !Number.isFinite(estimateTokens2) || estimateTokens2 <= 0) {
41693
+ return void 0;
41694
+ }
41695
+ if (!Number.isFinite(tolerance) || tolerance < 1) return void 0;
41696
+ return { maxTokens: Math.ceil(estimateTokens2 * tolerance) };
41697
+ }
41682
41698
 
41683
41699
  // src/pipeline/agent-executor.ts
41684
41700
  var logger40 = createLogger({ component: "agent-executor" });
@@ -41725,12 +41741,21 @@ function recordOutcome(args) {
41725
41741
  }
41726
41742
  async function runExpert(guard, expertType, prompt, executionId) {
41727
41743
  if (guard.isExhausted()) {
41744
+ emitPipelineStageEvent("dev-pipeline", "budget", "failed", {
41745
+ reason: "budget_exceeded",
41746
+ expertType,
41747
+ ...executionId !== void 0 ? { executionId } : {}
41748
+ });
41749
+ logger40.warn("Budget exhausted \u2014 expert call skipped (#3262/#3395)", {
41750
+ expertType,
41751
+ ...executionId !== void 0 ? { executionId } : {}
41752
+ });
41728
41753
  return {
41729
41754
  success: false,
41730
41755
  text: "",
41731
41756
  expertType,
41732
41757
  durationMs: 0,
41733
- error: "Budget exhausted \u2014 expert call skipped (#3395)"
41758
+ error: "Budget exhausted \u2014 expert call skipped (estimate-relative cap, #3262/#3395)"
41734
41759
  };
41735
41760
  }
41736
41761
  const result = await executeExpert(expertType, prompt);
@@ -44776,6 +44801,31 @@ ${task}`;
44776
44801
  throw err2;
44777
44802
  }
44778
44803
  }
44804
+ var OUTPUT_TOKEN_RATIO = 0.6;
44805
+ var DEFAULT_STAGE_COUNT = 6;
44806
+ function resolveRunBudget(task, templateId, logger56) {
44807
+ if (process.env["NEXUS_BUDGET_ENFORCE"] !== "1") return void 0;
44808
+ const effectiveId = templateId ?? classifyTask(task).pipelineType;
44809
+ const template = getTemplate(effectiveId) ?? getTemplate("general");
44810
+ const stageCount = template?.stages.length ?? DEFAULT_STAGE_COUNT;
44811
+ const perCall = Math.round(
44812
+ createSharedTaskAnalyzer().estimateTokens(task) * (1 + OUTPUT_TOKEN_RATIO)
44813
+ );
44814
+ const budget = estimateRelativeBudget(perCall * stageCount, resolveBudgetTolerance());
44815
+ if (budget === void 0) {
44816
+ logger56.warn("Budget enforcement on but no usable token estimate \u2014 running unguarded (#3262)", {
44817
+ perCall,
44818
+ stageCount
44819
+ });
44820
+ } else {
44821
+ logger56.info("Estimate-relative token budget enforced (#3262)", {
44822
+ template: effectiveId,
44823
+ stageCount,
44824
+ maxTokens: budget.maxTokens
44825
+ });
44826
+ }
44827
+ return budget;
44828
+ }
44779
44829
  function selectStageRegistry(template, task, agentStages) {
44780
44830
  const effectiveTemplate = template ?? classifyTask(task).pipelineType;
44781
44831
  if (effectiveTemplate === "greenfield") {
@@ -44804,7 +44854,8 @@ async function runPipelineHandler(args, logger56) {
44804
44854
  const agentStages = createAgentStages({
44805
44855
  simulateVotes: input.simulateVotes,
44806
44856
  votingStrategy: input.votingStrategy,
44807
- quickMode: input.quickMode
44857
+ quickMode: input.quickMode,
44858
+ budget: resolveRunBudget(task, input.template, logger56)
44808
44859
  });
44809
44860
  const stages = selectStageRegistry(input.template, task, agentStages);
44810
44861
  const result = await runAdaptiveOrchestrator(task, {
@@ -48959,4 +49010,4 @@ export {
48959
49010
  detectBackend,
48960
49011
  createTaskTracker
48961
49012
  };
48962
- //# sourceMappingURL=chunk-KZJHMSH6.js.map
49013
+ //# sourceMappingURL=chunk-N53G2GXS.js.map