nexus-agents 2.102.4 → 2.102.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.
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-S7R72HUB.js";
10
10
  import {
11
11
  executeExpert
12
- } from "./chunk-KHEQIB6P.js";
12
+ } from "./chunk-PWDIIS7L.js";
13
13
  import {
14
14
  EventTopics,
15
15
  JobStatusSchema,
@@ -30,7 +30,7 @@ import {
30
30
  writeJobComplete,
31
31
  writeJobFailed,
32
32
  writeJobPending
33
- } from "./chunk-Y5GD3LHH.js";
33
+ } from "./chunk-T32MGJMA.js";
34
34
  import {
35
35
  REGISTRY_PATH,
36
36
  getProjectRoot,
@@ -93,7 +93,7 @@ import {
93
93
  DEFAULT_TASK_TTL_MS,
94
94
  DEFAULT_TOOL_RATE_LIMITS,
95
95
  clampTaskTtl
96
- } from "./chunk-I4B6SHFH.js";
96
+ } from "./chunk-W7JCGUTA.js";
97
97
  import {
98
98
  getAvailabilityCache,
99
99
  getCliForModelId,
@@ -20810,6 +20810,13 @@ var BudgetCircuitBreaker = class {
20810
20810
  return `Budget warning: ${String(percentUsed)}% of budget will be used`;
20811
20811
  }
20812
20812
  };
20813
+ function createBudgetCircuitBreaker(maxTokens, config, logger56) {
20814
+ const mergedConfig = {
20815
+ ...DEFAULT_BUDGET_CIRCUIT_CONFIG,
20816
+ ...config
20817
+ };
20818
+ return new BudgetCircuitBreaker(maxTokens, mergedConfig, logger56);
20819
+ }
20813
20820
 
20814
20821
  // src/workflows/budget-enforcement.ts
20815
20822
  function applyBudgetEnforcement(step, contextManager, budgetEvents, config) {
@@ -42783,7 +42790,7 @@ var VALID_TEMPLATES = /* @__PURE__ */ new Set([
42783
42790
  ]);
42784
42791
  async function classifyWithLLM(task) {
42785
42792
  try {
42786
- const { executeExpert: executeExpert2 } = await import("./expert-bridge-Z7XZ7ED5.js");
42793
+ const { executeExpert: executeExpert2 } = await import("./expert-bridge-2TYPRNEE.js");
42787
42794
  const prompt = [
42788
42795
  "Classify this task into exactly one pipeline template.",
42789
42796
  "Templates: dev (implementation/bug fix/refactor), research (investigate/evaluate/compare),",
@@ -43599,6 +43606,34 @@ async function runQualityGate(stage, checks, iteration = 1) {
43599
43606
  };
43600
43607
  }
43601
43608
 
43609
+ // src/pipeline/budget-guard.ts
43610
+ var BudgetGuard = class {
43611
+ breaker;
43612
+ constructor(breaker) {
43613
+ this.breaker = breaker;
43614
+ }
43615
+ /** Record tokens consumed by a completed call (best-effort; undefined ignored). */
43616
+ record(tokensUsed) {
43617
+ if (this.breaker === void 0 || tokensUsed === void 0 || tokensUsed <= 0) return;
43618
+ this.breaker.recordUsage(tokensUsed);
43619
+ }
43620
+ /** True once the budget circuit has opened — callers should stop spending. */
43621
+ isExhausted() {
43622
+ return this.breaker?.getState() === "open";
43623
+ }
43624
+ /** Whether a budget is actually being enforced (vs the no-op default). */
43625
+ get enforced() {
43626
+ return this.breaker !== void 0;
43627
+ }
43628
+ };
43629
+ function createBudgetGuard(budget) {
43630
+ if (budget === void 0) return new BudgetGuard();
43631
+ const breaker = createBudgetCircuitBreaker(budget.maxTokens, {
43632
+ ...budget.criticalThreshold !== void 0 ? { criticalThreshold: budget.criticalThreshold } : {}
43633
+ });
43634
+ return new BudgetGuard(breaker);
43635
+ }
43636
+
43602
43637
  // src/pipeline/agent-executor.ts
43603
43638
  var logger40 = createLogger({ component: "agent-executor" });
43604
43639
  var VOTE_PROPOSAL_MAX = 4e3;
@@ -43642,6 +43677,20 @@ function recordOutcome(args) {
43642
43677
  logger40.debug("Failed to record outcome", { taskId: args.taskId, error: String(error) });
43643
43678
  }
43644
43679
  }
43680
+ async function runExpert(guard, expertType, prompt) {
43681
+ if (guard.isExhausted()) {
43682
+ return {
43683
+ success: false,
43684
+ text: "",
43685
+ expertType,
43686
+ durationMs: 0,
43687
+ error: "Budget exhausted \u2014 expert call skipped (#3395)"
43688
+ };
43689
+ }
43690
+ const result = await executeExpert(expertType, prompt);
43691
+ guard.record(result.tokensUsed);
43692
+ return result;
43693
+ }
43645
43694
  var cachedMemory = null;
43646
43695
  var memoryInitPromise = null;
43647
43696
  async function initPipelineMemory() {
@@ -43695,8 +43744,8 @@ function flushPipelineMemory() {
43695
43744
  }
43696
43745
  var routingMemoryCache = null;
43697
43746
  var routingMemoryInitPromise = null;
43698
- function recordRoutingExperience(category, success, durationMs) {
43699
- const metrics = { durationMs, tokensUsed: 0 };
43747
+ function recordRoutingExperience(category, success, durationMs, tokensUsed = 0) {
43748
+ const metrics = { durationMs, tokensUsed };
43700
43749
  const callRecord = (rm) => {
43701
43750
  rm.recordExperience(category, ["claude"], success, metrics);
43702
43751
  };
@@ -43787,18 +43836,21 @@ function getTrendContext() {
43787
43836
  }
43788
43837
  }
43789
43838
  function createAgentStages(config = {}) {
43839
+ const guard = createBudgetGuard(config.budget);
43790
43840
  return {
43791
43841
  research: async (task) => {
43792
43842
  emitStageEvent2("research", "started");
43793
43843
  await postProgress(config, "Research", "Querying memory + research tools...");
43794
43844
  const memoryCtx = await getMemoryContext(task);
43795
- const discover = await executeExpert(
43845
+ const discover = await runExpert(
43846
+ guard,
43796
43847
  "research",
43797
43848
  `Use research_discover to find papers and repos related to:
43798
43849
 
43799
43850
  ${task}${memoryCtx}`
43800
43851
  );
43801
- const analyze = await executeExpert(
43852
+ const analyze = await runExpert(
43853
+ guard,
43802
43854
  "research",
43803
43855
  `Use research_analyze focus=gaps to identify what is missing for:
43804
43856
 
@@ -43844,7 +43896,7 @@ ${task}
43844
43896
 
43845
43897
  ${contextBlock}`;
43846
43898
  await postProgress(config, "Plan", feedback !== void 0 ? "Revising..." : "Planning...");
43847
- const r = await executeExpert("architecture", prompt);
43899
+ const r = await runExpert(guard, "architecture", prompt);
43848
43900
  emitStageEvent2("plan", r.success ? "completed" : "failed", { durationMs: r.durationMs });
43849
43901
  recordOutcome({
43850
43902
  taskId: "plan",
@@ -43862,7 +43914,7 @@ ${contextBlock}`;
43862
43914
  const strategy = config.votingStrategy ?? "higher_order";
43863
43915
  await postProgress(config, "Vote", `Running consensus with ${strategy} strategy...`);
43864
43916
  try {
43865
- const { executeVoting } = await import("./consensus-vote-BW4HOYS4.js");
43917
+ const { executeVoting } = await import("./consensus-vote-7CE4JOMK.js");
43866
43918
  const votingResult = await executeVoting(
43867
43919
  {
43868
43920
  proposal: buildVoteProposal(plan, research),
@@ -43913,7 +43965,8 @@ ${contextBlock}`;
43913
43965
  decompose: async (plan) => {
43914
43966
  emitStageEvent2("decompose", "started");
43915
43967
  await postProgress(config, "PM", "PM expert decomposing...");
43916
- const r = await executeExpert(
43968
+ const r = await runExpert(
43969
+ guard,
43917
43970
  "pm",
43918
43971
  `Decompose into tasks.
43919
43972
  Return JSON: [{id,title,description,assignedTo}]
@@ -43938,7 +43991,8 @@ ${plan}`
43938
43991
  const fb = task.feedback !== void 0 ? `
43939
43992
 
43940
43993
  QA feedback: ${task.feedback}` : "";
43941
- const r = await executeExpert(
43994
+ const r = await runExpert(
43995
+ guard,
43942
43996
  "code",
43943
43997
  `Implement:
43944
43998
 
@@ -43955,14 +44009,15 @@ ${task.description}${fb}`
43955
44009
  success: r.success,
43956
44010
  durationMs: r.durationMs
43957
44011
  });
43958
- recordRoutingExperience("code_generation", r.success, r.durationMs);
44012
+ recordRoutingExperience("code_generation", r.success, r.durationMs, r.tokensUsed);
43959
44013
  await postProgress(config, `Code [${task.id}]`, `Done (${r.durationMs}ms)`);
43960
44014
  return r.text || `[Implementation failed: ${r.error}]`;
43961
44015
  },
43962
44016
  qaReview: async (task, implementation) => {
43963
44017
  emitStageEvent2(`qa-${task.id}`, "started");
43964
44018
  await postProgress(config, `QA [${task.id}]`, "QA expert reviewing...");
43965
- const r = await executeExpert(
44019
+ const r = await runExpert(
44020
+ guard,
43966
44021
  "qa",
43967
44022
  `QA:
43968
44023
 
@@ -50680,4 +50735,4 @@ export {
50680
50735
  detectBackend,
50681
50736
  createTaskTracker
50682
50737
  };
50683
- //# sourceMappingURL=chunk-XCIRYNDQ.js.map
50738
+ //# sourceMappingURL=chunk-5VMCBHRX.js.map