nexus-agents 2.82.0 → 2.83.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.
- package/dist/{child-mcp-config-BMSYR7VV.js → child-mcp-config-XVPIO5HV.js} +2 -2
- package/dist/{chunk-OYDJ3C4N.js → chunk-2W4QJ27D.js} +3 -3
- package/dist/{chunk-BQ4YXGGQ.js → chunk-3ACDP4E6.js} +124 -2
- package/dist/chunk-3ACDP4E6.js.map +1 -0
- package/dist/{chunk-C7P2HLJX.js → chunk-3ASED5PR.js} +4 -4
- package/dist/{chunk-TXIUCEFT.js → chunk-3GJAAENS.js} +3 -3
- package/dist/{chunk-GNG7URCR.js → chunk-3WUVWZUC.js} +2 -2
- package/dist/{chunk-FTT2IYYX.js → chunk-4BXQ2OZY.js} +34 -16
- package/dist/chunk-4BXQ2OZY.js.map +1 -0
- package/dist/{chunk-SBZVRH4S.js → chunk-54UXPJVM.js} +2 -2
- package/dist/{chunk-QHL4KGNB.js → chunk-5T6SYCH2.js} +2 -2
- package/dist/{chunk-BL5IBHEY.js → chunk-6WDJ3IE4.js} +3 -3
- package/dist/{chunk-2R5UUBGA.js → chunk-AFPHR72D.js} +2 -2
- package/dist/{chunk-S36LIUV2.js → chunk-AINOJRZX.js} +7 -7
- package/dist/{chunk-HJUHDPXJ.js → chunk-BZUEUD4G.js} +3 -3
- package/dist/{chunk-2SQXJQTA.js → chunk-FHGDJKCZ.js} +16 -13
- package/dist/{chunk-2SQXJQTA.js.map → chunk-FHGDJKCZ.js.map} +1 -1
- package/dist/{chunk-XGUDCUMB.js → chunk-FI77TGBY.js} +2 -2
- package/dist/{chunk-7J7PNOJQ.js → chunk-HFOQKCD2.js} +22 -5
- package/dist/chunk-HFOQKCD2.js.map +1 -0
- package/dist/{chunk-PZESEBD3.js → chunk-L362KRSU.js} +2 -2
- package/dist/{chunk-HMXQKDUV.js → chunk-NLPMYBIV.js} +23 -7
- package/dist/chunk-NLPMYBIV.js.map +1 -0
- package/dist/{chunk-4XNVJS5A.js → chunk-PMLVZXAE.js} +763 -728
- package/dist/chunk-PMLVZXAE.js.map +1 -0
- package/dist/{chunk-JM3R267Z.js → chunk-PPBZQKRP.js} +5 -5
- package/dist/{chunk-WUUEKFKG.js → chunk-Q6PZMGLU.js} +2 -2
- package/dist/{chunk-W2AIGD35.js → chunk-RVRXKNND.js} +3 -3
- package/dist/{chunk-7VNVDFD5.js → chunk-RXVH52UI.js} +44 -18
- package/dist/{chunk-7VNVDFD5.js.map → chunk-RXVH52UI.js.map} +1 -1
- package/dist/{chunk-HVZ52LOL.js → chunk-U6LDVJS7.js} +2 -2
- package/dist/{chunk-X3JR3GMT.js → chunk-WGSRH5EQ.js} +3 -3
- package/dist/{chunk-SXL744NF.js → chunk-WJFUTRHX.js} +2 -2
- package/dist/{chunk-U7JXQSEM.js → chunk-YO27YAEX.js} +3 -3
- package/dist/{chunk-G2DZBEMU.js → chunk-Z64MSLEK.js} +2 -2
- package/dist/{chunk-NTLJ3INA.js → chunk-ZIWEEVMI.js} +2 -2
- package/dist/{chunk-SHWGK7X6.js → chunk-ZM5JKJHI.js} +2 -2
- package/dist/{cli-circuit-breaker-BIJUQRQI.js → cli-circuit-breaker-Y26NPPNO.js} +4 -4
- package/dist/cli.js +366 -344
- package/dist/cli.js.map +1 -1
- package/dist/codebase-search-ZFJUVMVR.js +8 -0
- package/dist/{composite-router-FB7P22L5.js → composite-router-X2ZYIEHH.js} +2 -2
- package/dist/{consensus-vote-KKAIFULI.js → consensus-vote-KZ6UURUI.js} +11 -11
- package/dist/{context-retriever-4JCGMWH7.js → context-retriever-QY4FNTDZ.js} +5 -5
- package/dist/{doctor-deep-7YK4BZIJ.js → doctor-deep-2E2GBMYR.js} +3 -3
- package/dist/expert-bridge-FHPWDFJX.js +13 -0
- package/dist/{factory-PK4EZL7K.js → factory-STNVY3Y3.js} +4 -4
- package/dist/{factory-DOWBGVAL.js → factory-W6KROBFN.js} +5 -5
- package/dist/index.d.ts +104 -60
- package/dist/index.js +100 -105
- package/dist/index.js.map +1 -1
- package/dist/{init-opencode-QP5CAMWN.js → init-opencode-6LVZ4CAQ.js} +5 -5
- package/dist/{issue-triage-T3SKNBH5.js → issue-triage-Y77JI7WF.js} +4 -4
- package/dist/{registry-command-TH7U6UMC.js → registry-command-P5VIAEOL.js} +2 -2
- package/dist/{repo-analyze-D2OY2QSR.js → repo-analyze-JZEMBE6R.js} +2 -2
- package/dist/{repo-security-plan-V257RYTW.js → repo-security-plan-RHSLO7H6.js} +4 -4
- package/dist/{research-helpers-synthesize-Y3O76PY4.js → research-helpers-synthesize-PVP6JRZV.js} +3 -3
- package/dist/{routing-memory-AAH7NIHD.js → routing-memory-QRIJPRVD.js} +2 -2
- package/dist/{session-memory-MY6YS2VX.js → session-memory-WARRGYY7.js} +3 -3
- package/dist/{setup-command-B6EC3OJA.js → setup-command-GMP5FI7F.js} +10 -10
- package/dist/{setup-config-HVO6ZSLW.js → setup-config-G3KKZM7O.js} +3 -3
- package/dist/{setup-custom-api-UOIKUQL4.js → setup-custom-api-B63X7ISD.js} +4 -4
- package/dist/{tool-memory-T7ZYIUJ2.js → tool-memory-E7JW4YLT.js} +4 -4
- package/dist/{weather-report-O3Z3BBAX.js → weather-report-RACZWJQL.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-4XNVJS5A.js.map +0 -1
- package/dist/chunk-7J7PNOJQ.js.map +0 -1
- package/dist/chunk-AP2FD37C.js +0 -127
- package/dist/chunk-AP2FD37C.js.map +0 -1
- package/dist/chunk-BQ4YXGGQ.js.map +0 -1
- package/dist/chunk-ED6VQWNG.js +0 -63
- package/dist/chunk-ED6VQWNG.js.map +0 -1
- package/dist/chunk-FTT2IYYX.js.map +0 -1
- package/dist/chunk-HMXQKDUV.js.map +0 -1
- package/dist/codebase-search-PIBRTGBE.js +0 -9
- package/dist/expert-bridge-DJM5GAWZ.js +0 -11
- package/dist/shared-memory-CM6T2MYE.js +0 -8
- package/dist/symbol-extractor-WYXPJH65.js +0 -10
- package/dist/tool-memory-T7ZYIUJ2.js.map +0 -1
- package/dist/weather-report-O3Z3BBAX.js.map +0 -1
- /package/dist/{child-mcp-config-BMSYR7VV.js.map → child-mcp-config-XVPIO5HV.js.map} +0 -0
- /package/dist/{chunk-OYDJ3C4N.js.map → chunk-2W4QJ27D.js.map} +0 -0
- /package/dist/{chunk-C7P2HLJX.js.map → chunk-3ASED5PR.js.map} +0 -0
- /package/dist/{chunk-TXIUCEFT.js.map → chunk-3GJAAENS.js.map} +0 -0
- /package/dist/{chunk-GNG7URCR.js.map → chunk-3WUVWZUC.js.map} +0 -0
- /package/dist/{chunk-SBZVRH4S.js.map → chunk-54UXPJVM.js.map} +0 -0
- /package/dist/{chunk-QHL4KGNB.js.map → chunk-5T6SYCH2.js.map} +0 -0
- /package/dist/{chunk-BL5IBHEY.js.map → chunk-6WDJ3IE4.js.map} +0 -0
- /package/dist/{chunk-2R5UUBGA.js.map → chunk-AFPHR72D.js.map} +0 -0
- /package/dist/{chunk-S36LIUV2.js.map → chunk-AINOJRZX.js.map} +0 -0
- /package/dist/{chunk-HJUHDPXJ.js.map → chunk-BZUEUD4G.js.map} +0 -0
- /package/dist/{chunk-XGUDCUMB.js.map → chunk-FI77TGBY.js.map} +0 -0
- /package/dist/{chunk-PZESEBD3.js.map → chunk-L362KRSU.js.map} +0 -0
- /package/dist/{chunk-JM3R267Z.js.map → chunk-PPBZQKRP.js.map} +0 -0
- /package/dist/{chunk-WUUEKFKG.js.map → chunk-Q6PZMGLU.js.map} +0 -0
- /package/dist/{chunk-W2AIGD35.js.map → chunk-RVRXKNND.js.map} +0 -0
- /package/dist/{chunk-HVZ52LOL.js.map → chunk-U6LDVJS7.js.map} +0 -0
- /package/dist/{chunk-X3JR3GMT.js.map → chunk-WGSRH5EQ.js.map} +0 -0
- /package/dist/{chunk-SXL744NF.js.map → chunk-WJFUTRHX.js.map} +0 -0
- /package/dist/{chunk-U7JXQSEM.js.map → chunk-YO27YAEX.js.map} +0 -0
- /package/dist/{chunk-G2DZBEMU.js.map → chunk-Z64MSLEK.js.map} +0 -0
- /package/dist/{chunk-NTLJ3INA.js.map → chunk-ZIWEEVMI.js.map} +0 -0
- /package/dist/{chunk-SHWGK7X6.js.map → chunk-ZM5JKJHI.js.map} +0 -0
- /package/dist/{cli-circuit-breaker-BIJUQRQI.js.map → cli-circuit-breaker-Y26NPPNO.js.map} +0 -0
- /package/dist/{codebase-search-PIBRTGBE.js.map → codebase-search-ZFJUVMVR.js.map} +0 -0
- /package/dist/{composite-router-FB7P22L5.js.map → composite-router-X2ZYIEHH.js.map} +0 -0
- /package/dist/{consensus-vote-KKAIFULI.js.map → consensus-vote-KZ6UURUI.js.map} +0 -0
- /package/dist/{context-retriever-4JCGMWH7.js.map → context-retriever-QY4FNTDZ.js.map} +0 -0
- /package/dist/{doctor-deep-7YK4BZIJ.js.map → doctor-deep-2E2GBMYR.js.map} +0 -0
- /package/dist/{expert-bridge-DJM5GAWZ.js.map → expert-bridge-FHPWDFJX.js.map} +0 -0
- /package/dist/{factory-DOWBGVAL.js.map → factory-STNVY3Y3.js.map} +0 -0
- /package/dist/{factory-PK4EZL7K.js.map → factory-W6KROBFN.js.map} +0 -0
- /package/dist/{init-opencode-QP5CAMWN.js.map → init-opencode-6LVZ4CAQ.js.map} +0 -0
- /package/dist/{issue-triage-T3SKNBH5.js.map → issue-triage-Y77JI7WF.js.map} +0 -0
- /package/dist/{registry-command-TH7U6UMC.js.map → registry-command-P5VIAEOL.js.map} +0 -0
- /package/dist/{repo-analyze-D2OY2QSR.js.map → repo-analyze-JZEMBE6R.js.map} +0 -0
- /package/dist/{repo-security-plan-V257RYTW.js.map → repo-security-plan-RHSLO7H6.js.map} +0 -0
- /package/dist/{research-helpers-synthesize-Y3O76PY4.js.map → research-helpers-synthesize-PVP6JRZV.js.map} +0 -0
- /package/dist/{routing-memory-AAH7NIHD.js.map → routing-memory-QRIJPRVD.js.map} +0 -0
- /package/dist/{session-memory-MY6YS2VX.js.map → session-memory-WARRGYY7.js.map} +0 -0
- /package/dist/{setup-command-B6EC3OJA.js.map → setup-command-GMP5FI7F.js.map} +0 -0
- /package/dist/{setup-config-HVO6ZSLW.js.map → setup-config-G3KKZM7O.js.map} +0 -0
- /package/dist/{setup-custom-api-UOIKUQL4.js.map → setup-custom-api-B63X7ISD.js.map} +0 -0
- /package/dist/{shared-memory-CM6T2MYE.js.map → tool-memory-E7JW4YLT.js.map} +0 -0
- /package/dist/{symbol-extractor-WYXPJH65.js.map → weather-report-RACZWJQL.js.map} +0 -0
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CodebaseIndex
|
|
3
|
-
} from "./chunk-AP2FD37C.js";
|
|
4
|
-
import {
|
|
5
|
-
SharedMemoryStore
|
|
6
|
-
} from "./chunk-ED6VQWNG.js";
|
|
7
1
|
import {
|
|
8
2
|
getTokenEnvVars,
|
|
9
3
|
resolveToken
|
|
10
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Z64MSLEK.js";
|
|
11
5
|
import {
|
|
12
6
|
executeExpert
|
|
13
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NLPMYBIV.js";
|
|
14
8
|
import {
|
|
15
9
|
EventTopics,
|
|
16
10
|
NOOP_NOTIFIER,
|
|
@@ -36,7 +30,7 @@ import {
|
|
|
36
30
|
withAccessPolicy,
|
|
37
31
|
withProgressHeartbeat,
|
|
38
32
|
wrapToolWithTimeout
|
|
39
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-4BXQ2OZY.js";
|
|
40
34
|
import {
|
|
41
35
|
REGISTRY_PATH,
|
|
42
36
|
getProjectRoot,
|
|
@@ -45,26 +39,27 @@ import {
|
|
|
45
39
|
normalizeTopicToCanonical,
|
|
46
40
|
savePapersRegistry,
|
|
47
41
|
synthesizeResearch
|
|
48
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-AFPHR72D.js";
|
|
49
43
|
import {
|
|
50
44
|
IssueTriage,
|
|
51
45
|
sanitizeInput
|
|
52
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-BZUEUD4G.js";
|
|
53
47
|
import {
|
|
54
48
|
generateSecurityPlan
|
|
55
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-RVRXKNND.js";
|
|
56
50
|
import {
|
|
57
51
|
analyzeGitHubRepo
|
|
58
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-HFOQKCD2.js";
|
|
59
53
|
import {
|
|
54
|
+
CodebaseIndex,
|
|
60
55
|
extractSymbolIndex,
|
|
61
56
|
extractSymbols
|
|
62
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-3ACDP4E6.js";
|
|
63
58
|
import {
|
|
64
59
|
getContextForTask,
|
|
65
60
|
inferTaskCategory,
|
|
66
61
|
summarizeContextForPrompt
|
|
67
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-3GJAAENS.js";
|
|
68
63
|
import {
|
|
69
64
|
DEFAULT_RELEVANCE_CONFIG,
|
|
70
65
|
MemoryImportance,
|
|
@@ -72,19 +67,19 @@ import {
|
|
|
72
67
|
generateHyphenId,
|
|
73
68
|
generateUUID,
|
|
74
69
|
getToolMemory
|
|
75
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-YO27YAEX.js";
|
|
76
71
|
import {
|
|
77
72
|
DEFAULT_TASK_TTL_MS,
|
|
78
73
|
DEFAULT_TOOL_RATE_LIMITS,
|
|
79
74
|
clampTaskTtl
|
|
80
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-AINOJRZX.js";
|
|
81
76
|
import {
|
|
82
77
|
getAvailabilityCache,
|
|
83
78
|
resolveFallback
|
|
84
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-3WUVWZUC.js";
|
|
85
80
|
import {
|
|
86
81
|
DEFAULTS
|
|
87
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-ZM5JKJHI.js";
|
|
88
83
|
import {
|
|
89
84
|
resolveInsideRoot
|
|
90
85
|
} from "./chunk-NUBSJGQZ.js";
|
|
@@ -100,7 +95,7 @@ import {
|
|
|
100
95
|
getAvailableClis,
|
|
101
96
|
sleep,
|
|
102
97
|
withTimeout
|
|
103
|
-
} from "./chunk-
|
|
98
|
+
} from "./chunk-FHGDJKCZ.js";
|
|
104
99
|
import {
|
|
105
100
|
BUILT_IN_EXPERTS,
|
|
106
101
|
BuiltInExpertTypeSchema,
|
|
@@ -112,12 +107,13 @@ import {
|
|
|
112
107
|
} from "./chunk-PQHVC4BD.js";
|
|
113
108
|
import {
|
|
114
109
|
createSessionMemory
|
|
115
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-U6LDVJS7.js";
|
|
116
111
|
import {
|
|
117
112
|
AGENT_ROUTER_TIMEOUTS,
|
|
118
113
|
API_TIMEOUTS,
|
|
119
114
|
ARCHITECTURE_KEYWORDS,
|
|
120
115
|
AgentError,
|
|
116
|
+
CLI_NAMES,
|
|
121
117
|
CLI_SUBPROCESS_TIMEOUTS,
|
|
122
118
|
DEFAULT_CLI,
|
|
123
119
|
EXPERT_TIMEOUTS,
|
|
@@ -182,7 +178,7 @@ import {
|
|
|
182
178
|
resolveModelIdentitySync,
|
|
183
179
|
toExpertTaskAnalysisResult,
|
|
184
180
|
withStep
|
|
185
|
-
} from "./chunk-
|
|
181
|
+
} from "./chunk-RXVH52UI.js";
|
|
186
182
|
import {
|
|
187
183
|
getNexusDataDir,
|
|
188
184
|
nexusDataPath
|
|
@@ -1105,12 +1101,12 @@ function removeItemsDirectly(items, targetTokens, manager) {
|
|
|
1105
1101
|
};
|
|
1106
1102
|
}
|
|
1107
1103
|
async function summarizeAndRemoveItems(options) {
|
|
1108
|
-
const { items, targetTokens, manager, adapter, logger:
|
|
1104
|
+
const { items, targetTokens, manager, adapter, logger: logger53, customPrompt } = options;
|
|
1109
1105
|
const content = items.map((item) => item.content).join("\n\n---\n\n");
|
|
1110
1106
|
const prompt = customPrompt ?? SLIDING_WINDOW_PROMPT;
|
|
1111
1107
|
const summaryResult = await generateSummary(content, prompt, adapter);
|
|
1112
1108
|
if (!summaryResult.ok) {
|
|
1113
|
-
|
|
1109
|
+
logger53.warn("Summarization failed, removing items without summary");
|
|
1114
1110
|
return removeItemsDirectly(items, targetTokens, manager);
|
|
1115
1111
|
}
|
|
1116
1112
|
let tokensFreed = 0;
|
|
@@ -1123,7 +1119,7 @@ async function summarizeAndRemoveItems(options) {
|
|
|
1123
1119
|
if (summaryAddResult.item !== void 0) {
|
|
1124
1120
|
tokensFreed -= summaryAddResult.tokenCount;
|
|
1125
1121
|
}
|
|
1126
|
-
|
|
1122
|
+
logger53.info("Summarization pruning completed", {
|
|
1127
1123
|
summarizedItems: items.length,
|
|
1128
1124
|
tokensFreed,
|
|
1129
1125
|
targetReached: tokensFreed >= targetTokens
|
|
@@ -1181,7 +1177,7 @@ function scoreByPriorityWeightedAge(candidates) {
|
|
|
1181
1177
|
return scores.map((s) => s.item);
|
|
1182
1178
|
}
|
|
1183
1179
|
function removeItemsToTarget(options) {
|
|
1184
|
-
const { sortedItems, targetTokens, categories, manager, minItemsPerCategory, logger:
|
|
1180
|
+
const { sortedItems, targetTokens, categories, manager, minItemsPerCategory, logger: logger53 } = options;
|
|
1185
1181
|
const categoryRemaining = /* @__PURE__ */ new Map();
|
|
1186
1182
|
for (const category of categories) {
|
|
1187
1183
|
categoryRemaining.set(category, manager.getByCategory(category).length);
|
|
@@ -1198,7 +1194,7 @@ function removeItemsToTarget(options) {
|
|
|
1198
1194
|
categoryRemaining.set(item.category, remaining - 1);
|
|
1199
1195
|
}
|
|
1200
1196
|
const targetReached = tokensFreed >= targetTokens;
|
|
1201
|
-
|
|
1197
|
+
logger53.info("Pruning completed", {
|
|
1202
1198
|
itemsRemoved: removedItems.length,
|
|
1203
1199
|
tokensFreed,
|
|
1204
1200
|
targetTokens,
|
|
@@ -1661,7 +1657,7 @@ function generateBudgetWarning(utilizationPercent, tokensUsed, budgetLimit, scop
|
|
|
1661
1657
|
scope
|
|
1662
1658
|
};
|
|
1663
1659
|
}
|
|
1664
|
-
function logBudgetWarning(warning,
|
|
1660
|
+
function logBudgetWarning(warning, logger53) {
|
|
1665
1661
|
const context = {
|
|
1666
1662
|
scope: warning.scope,
|
|
1667
1663
|
usagePercent: Math.round(warning.usagePercent),
|
|
@@ -1670,13 +1666,13 @@ function logBudgetWarning(warning, logger52) {
|
|
|
1670
1666
|
};
|
|
1671
1667
|
switch (warning.level) {
|
|
1672
1668
|
case "critical":
|
|
1673
|
-
|
|
1669
|
+
logger53.warn(warning.message, context);
|
|
1674
1670
|
break;
|
|
1675
1671
|
case "warning":
|
|
1676
|
-
|
|
1672
|
+
logger53.warn(warning.message, context);
|
|
1677
1673
|
break;
|
|
1678
1674
|
case "info":
|
|
1679
|
-
|
|
1675
|
+
logger53.info(warning.message, context);
|
|
1680
1676
|
break;
|
|
1681
1677
|
}
|
|
1682
1678
|
}
|
|
@@ -1732,8 +1728,8 @@ function createHardModeResult(params) {
|
|
|
1732
1728
|
)
|
|
1733
1729
|
};
|
|
1734
1730
|
}
|
|
1735
|
-
function logWarnModeExceeded(params,
|
|
1736
|
-
|
|
1731
|
+
function logWarnModeExceeded(params, logger53) {
|
|
1732
|
+
logger53.warn("Token budget would be exceeded (warn mode - continuing)", {
|
|
1737
1733
|
exceedsSession: params.exceedsSession,
|
|
1738
1734
|
exceedsTask: params.exceedsTask,
|
|
1739
1735
|
estimatedTokens: params.estimatedTokens,
|
|
@@ -1762,9 +1758,9 @@ var TokenBudgetTracker = class {
|
|
|
1762
1758
|
* @param config - Token budget configuration
|
|
1763
1759
|
* @param logger - Optional logger instance
|
|
1764
1760
|
*/
|
|
1765
|
-
constructor(config = {},
|
|
1761
|
+
constructor(config = {}, logger53) {
|
|
1766
1762
|
this.config = { ...DEFAULT_TOKEN_BUDGET_CONFIG, ...config };
|
|
1767
|
-
this.logger =
|
|
1763
|
+
this.logger = logger53 ?? createLogger({ component: "token-budget-tracker" });
|
|
1768
1764
|
}
|
|
1769
1765
|
/**
|
|
1770
1766
|
* Check if an operation is within budget.
|
|
@@ -1917,7 +1913,7 @@ var TokenBudgetTracker = class {
|
|
|
1917
1913
|
|
|
1918
1914
|
// src/agents/base-agent-state-helpers.ts
|
|
1919
1915
|
function transitionToState(params) {
|
|
1920
|
-
const { stateMachine, logger:
|
|
1916
|
+
const { stateMachine, logger: logger53, newState } = params;
|
|
1921
1917
|
const currentState = stateMachine.state;
|
|
1922
1918
|
if (newState === "error") {
|
|
1923
1919
|
stateMachine.forceError({ reason: "transitionToState called with error" });
|
|
@@ -1927,7 +1923,7 @@ function transitionToState(params) {
|
|
|
1927
1923
|
if (event !== void 0 && stateMachine.canTransition(event)) {
|
|
1928
1924
|
const result = stateMachine.transition(event);
|
|
1929
1925
|
if (!result.ok) {
|
|
1930
|
-
|
|
1926
|
+
logger53.warn("State transition failed", {
|
|
1931
1927
|
from: currentState,
|
|
1932
1928
|
to: newState,
|
|
1933
1929
|
event,
|
|
@@ -1935,7 +1931,7 @@ function transitionToState(params) {
|
|
|
1935
1931
|
});
|
|
1936
1932
|
}
|
|
1937
1933
|
} else if (currentState !== newState) {
|
|
1938
|
-
|
|
1934
|
+
logger53.debug("Unmapped state change", { from: currentState, to: newState });
|
|
1939
1935
|
}
|
|
1940
1936
|
}
|
|
1941
1937
|
|
|
@@ -2091,7 +2087,7 @@ function getAgentStateKey(agentId) {
|
|
|
2091
2087
|
}
|
|
2092
2088
|
|
|
2093
2089
|
// src/agents/memory-operations.ts
|
|
2094
|
-
async function persistMemoryState(backend, state,
|
|
2090
|
+
async function persistMemoryState(backend, state, logger53) {
|
|
2095
2091
|
const key = getAgentStateKey(state.agentId);
|
|
2096
2092
|
const metadata = {
|
|
2097
2093
|
importance: MemoryImportance.HIGH,
|
|
@@ -2103,12 +2099,12 @@ async function persistMemoryState(backend, state, logger52) {
|
|
|
2103
2099
|
};
|
|
2104
2100
|
const result = await backend.store(key, updatedState, metadata);
|
|
2105
2101
|
if (!result.ok) {
|
|
2106
|
-
|
|
2102
|
+
logger53.error("Failed to persist agent memory state", result.error, { agentId: state.agentId });
|
|
2107
2103
|
return err(
|
|
2108
2104
|
new AgentMemoryError("Failed to persist memory state", { error: result.error.message })
|
|
2109
2105
|
);
|
|
2110
2106
|
}
|
|
2111
|
-
|
|
2107
|
+
logger53.debug("Persisted agent memory state", {
|
|
2112
2108
|
agentId: state.agentId,
|
|
2113
2109
|
learningsCount: state.taskLearnings.length,
|
|
2114
2110
|
patternsCount: state.executionPatterns.length,
|
|
@@ -2116,16 +2112,16 @@ async function persistMemoryState(backend, state, logger52) {
|
|
|
2116
2112
|
});
|
|
2117
2113
|
return ok(void 0);
|
|
2118
2114
|
}
|
|
2119
|
-
async function loadMemoryState(backend, agentId, role,
|
|
2115
|
+
async function loadMemoryState(backend, agentId, role, logger53) {
|
|
2120
2116
|
const key = getAgentStateKey(agentId);
|
|
2121
2117
|
const result = await backend.retrieve(key);
|
|
2122
2118
|
if (!result.ok) {
|
|
2123
|
-
|
|
2119
|
+
logger53.debug("No existing memory state found, creating fresh state", { agentId });
|
|
2124
2120
|
return ok(createInitialMemoryState(agentId, role));
|
|
2125
2121
|
}
|
|
2126
2122
|
const loaded = result.value;
|
|
2127
2123
|
if (loaded === null || typeof loaded !== "object") {
|
|
2128
|
-
|
|
2124
|
+
logger53.warn("Invalid memory state format, creating fresh state", { agentId });
|
|
2129
2125
|
return ok(createInitialMemoryState(agentId, role));
|
|
2130
2126
|
}
|
|
2131
2127
|
const state = {
|
|
@@ -2136,7 +2132,7 @@ async function loadMemoryState(backend, agentId, role, logger52) {
|
|
|
2136
2132
|
executionPatterns: Array.isArray(loaded.executionPatterns) ? loaded.executionPatterns : [],
|
|
2137
2133
|
errorResolutions: Array.isArray(loaded.errorResolutions) ? loaded.errorResolutions : []
|
|
2138
2134
|
};
|
|
2139
|
-
|
|
2135
|
+
logger53.debug("Loaded agent memory state", {
|
|
2140
2136
|
agentId,
|
|
2141
2137
|
learningsCount: state.taskLearnings.length,
|
|
2142
2138
|
patternsCount: state.executionPatterns.length,
|
|
@@ -2144,13 +2140,13 @@ async function loadMemoryState(backend, agentId, role, logger52) {
|
|
|
2144
2140
|
});
|
|
2145
2141
|
return ok(state);
|
|
2146
2142
|
}
|
|
2147
|
-
async function loadRelevantTypedMemories(typedMemory, role, limit,
|
|
2143
|
+
async function loadRelevantTypedMemories(typedMemory, role, limit, logger53) {
|
|
2148
2144
|
const result = await typedMemory.filterByRelevance(role, limit);
|
|
2149
2145
|
if (!result.ok) {
|
|
2150
|
-
|
|
2146
|
+
logger53.warn("Failed to load relevant typed memories", { role, error: result.error.message });
|
|
2151
2147
|
return result;
|
|
2152
2148
|
}
|
|
2153
|
-
|
|
2149
|
+
logger53.debug("Loaded relevant typed memories", {
|
|
2154
2150
|
role,
|
|
2155
2151
|
count: result.value.length,
|
|
2156
2152
|
types: [...new Set(result.value.map((e) => e.type))]
|
|
@@ -2264,10 +2260,10 @@ function initializeMemoryInfrastructure(options) {
|
|
|
2264
2260
|
|
|
2265
2261
|
// src/agents/base-agent-constructor-helpers.ts
|
|
2266
2262
|
function setupStateMachine(params) {
|
|
2267
|
-
const { agentId, logger:
|
|
2263
|
+
const { agentId, logger: logger53, eventBus, options } = params;
|
|
2268
2264
|
const stateMachine = new AgentStateMachine(options);
|
|
2269
2265
|
stateMachine.onStateChange((transition) => {
|
|
2270
|
-
|
|
2266
|
+
logger53.debug("State transition", {
|
|
2271
2267
|
from: transition.from,
|
|
2272
2268
|
to: transition.to,
|
|
2273
2269
|
event: transition.event
|
|
@@ -2281,9 +2277,9 @@ function setupStateMachine(params) {
|
|
|
2281
2277
|
return stateMachine;
|
|
2282
2278
|
}
|
|
2283
2279
|
function initializeInfrastructure(params) {
|
|
2284
|
-
const { agentId, role, logger:
|
|
2280
|
+
const { agentId, role, logger: logger53, adapter, pruningConfig, memoryConfig } = params;
|
|
2285
2281
|
const pruningOpts = {
|
|
2286
|
-
logger:
|
|
2282
|
+
logger: logger53,
|
|
2287
2283
|
...pruningConfig !== void 0 ? { config: pruningConfig } : {},
|
|
2288
2284
|
...adapter !== void 0 ? { adapter } : {}
|
|
2289
2285
|
};
|
|
@@ -2291,7 +2287,7 @@ function initializeInfrastructure(params) {
|
|
|
2291
2287
|
const memoryOpts = {
|
|
2292
2288
|
agentId,
|
|
2293
2289
|
role,
|
|
2294
|
-
logger:
|
|
2290
|
+
logger: logger53,
|
|
2295
2291
|
...memoryConfig !== void 0 ? { config: memoryConfig } : {}
|
|
2296
2292
|
};
|
|
2297
2293
|
const memory = initializeMemoryInfrastructure(memoryOpts);
|
|
@@ -2523,14 +2519,14 @@ function transformTaskError(error, agentId, taskId) {
|
|
|
2523
2519
|
return new AgentError(`Task execution failed: ${message}`, opts);
|
|
2524
2520
|
}
|
|
2525
2521
|
function finalizeTaskSuccess(params) {
|
|
2526
|
-
const { task, result, startTime, stateMachine, budgetTracker, logger:
|
|
2522
|
+
const { task, result, startTime, stateMachine, budgetTracker, logger: logger53 } = params;
|
|
2527
2523
|
const durationMs = getTimeProvider().now() - startTime;
|
|
2528
2524
|
if (stateMachine.state === "thinking") {
|
|
2529
2525
|
stateMachine.transition("plan_completed", { taskId: task.id });
|
|
2530
2526
|
}
|
|
2531
2527
|
stateMachine.transition("task_completed", { taskId: task.id, durationMs });
|
|
2532
2528
|
const budgetStats = budgetTracker.endTask();
|
|
2533
|
-
|
|
2529
|
+
logger53.info("Task completed", {
|
|
2534
2530
|
taskId: task.id,
|
|
2535
2531
|
durationMs,
|
|
2536
2532
|
tokensUsed: result.metadata.tokensUsed,
|
|
@@ -2558,7 +2554,7 @@ function recordFailedTaskError(params) {
|
|
|
2558
2554
|
});
|
|
2559
2555
|
}
|
|
2560
2556
|
async function persistMemoryAfterTask(params) {
|
|
2561
|
-
const { memoryEnabled, memoryBackend, memoryState, persistenceMode, task, startTime, logger:
|
|
2557
|
+
const { memoryEnabled, memoryBackend, memoryState, persistenceMode, task, startTime, logger: logger53 } = params;
|
|
2562
2558
|
if (!memoryEnabled || memoryState === null) {
|
|
2563
2559
|
return memoryState;
|
|
2564
2560
|
}
|
|
@@ -2573,9 +2569,9 @@ async function persistMemoryAfterTask(params) {
|
|
|
2573
2569
|
successRate
|
|
2574
2570
|
});
|
|
2575
2571
|
if (memoryBackend !== void 0) {
|
|
2576
|
-
await persistMemoryState(memoryBackend, updatedState,
|
|
2572
|
+
await persistMemoryState(memoryBackend, updatedState, logger53);
|
|
2577
2573
|
}
|
|
2578
|
-
|
|
2574
|
+
logger53.debug("Memory persisted after task completion", {
|
|
2579
2575
|
taskId: task.id,
|
|
2580
2576
|
durationMs
|
|
2581
2577
|
});
|
|
@@ -2586,15 +2582,15 @@ function categorizeTaskType(description2) {
|
|
|
2586
2582
|
return categorizeTaskByKeywords(desc);
|
|
2587
2583
|
}
|
|
2588
2584
|
async function persistMemoryOnCleanup(params) {
|
|
2589
|
-
const { memoryEnabled, memoryBackend, memoryState, persistenceMode, logger:
|
|
2585
|
+
const { memoryEnabled, memoryBackend, memoryState, persistenceMode, logger: logger53 } = params;
|
|
2590
2586
|
if (!memoryEnabled || memoryBackend === void 0 || memoryState === null) {
|
|
2591
2587
|
return;
|
|
2592
2588
|
}
|
|
2593
2589
|
if (persistenceMode === "none") {
|
|
2594
2590
|
return;
|
|
2595
2591
|
}
|
|
2596
|
-
await persistMemoryState(memoryBackend, memoryState,
|
|
2597
|
-
|
|
2592
|
+
await persistMemoryState(memoryBackend, memoryState, logger53);
|
|
2593
|
+
logger53.debug("Memory state persisted during cleanup");
|
|
2598
2594
|
}
|
|
2599
2595
|
|
|
2600
2596
|
// src/agents/base-agent-execute-flow.ts
|
|
@@ -2720,14 +2716,14 @@ function createInitialPruningMetrics() {
|
|
|
2720
2716
|
|
|
2721
2717
|
// src/agents/base-agent-memory-ops.ts
|
|
2722
2718
|
async function flushMemoryState(params) {
|
|
2723
|
-
const { memoryEnabled, memoryBackend, memoryState, logger:
|
|
2719
|
+
const { memoryEnabled, memoryBackend, memoryState, logger: logger53 } = params;
|
|
2724
2720
|
if (!memoryEnabled) {
|
|
2725
2721
|
return ok(void 0);
|
|
2726
2722
|
}
|
|
2727
2723
|
if (memoryBackend === void 0 || memoryState === null) {
|
|
2728
2724
|
return ok(void 0);
|
|
2729
2725
|
}
|
|
2730
|
-
return persistMemoryState(memoryBackend, memoryState,
|
|
2726
|
+
return persistMemoryState(memoryBackend, memoryState, logger53);
|
|
2731
2727
|
}
|
|
2732
2728
|
function recordLearningToState(params) {
|
|
2733
2729
|
const { memoryEnabled, memoryState, learning } = params;
|
|
@@ -3976,13 +3972,13 @@ function shouldFinalize(pattern, participants, results, votes, reviews) {
|
|
|
3976
3972
|
|
|
3977
3973
|
// src/agents/collaboration/collaboration-session-helpers.ts
|
|
3978
3974
|
var MAX_EVENT_LISTENERS = 50;
|
|
3979
|
-
function emitEventToListeners(listeners, event,
|
|
3975
|
+
function emitEventToListeners(listeners, event, logger53) {
|
|
3980
3976
|
for (const listener of listeners) {
|
|
3981
3977
|
try {
|
|
3982
3978
|
listener(event);
|
|
3983
3979
|
} catch (e) {
|
|
3984
3980
|
const errorObj = e instanceof Error ? e : new Error(String(e));
|
|
3985
|
-
|
|
3981
|
+
logger53.error("Event listener error", errorObj, { eventType: event.type });
|
|
3986
3982
|
}
|
|
3987
3983
|
}
|
|
3988
3984
|
}
|
|
@@ -7657,9 +7653,9 @@ var DEFAULT_WAVE_CONFIG = {
|
|
|
7657
7653
|
var WaveScheduler = class {
|
|
7658
7654
|
config;
|
|
7659
7655
|
logger;
|
|
7660
|
-
constructor(config = {},
|
|
7656
|
+
constructor(config = {}, logger53) {
|
|
7661
7657
|
this.config = { ...DEFAULT_WAVE_CONFIG, ...config };
|
|
7662
|
-
this.logger =
|
|
7658
|
+
this.logger = logger53 ?? createLogger({ component: "wave-scheduler" });
|
|
7663
7659
|
}
|
|
7664
7660
|
/**
|
|
7665
7661
|
* Execute tasks in waves respecting dependencies and concurrency limits.
|
|
@@ -7893,8 +7889,8 @@ function chunkByDirectory(files, basePath) {
|
|
|
7893
7889
|
items
|
|
7894
7890
|
}));
|
|
7895
7891
|
}
|
|
7896
|
-
function createWaveScheduler(config = {},
|
|
7897
|
-
return new WaveScheduler(config,
|
|
7892
|
+
function createWaveScheduler(config = {}, logger53) {
|
|
7893
|
+
return new WaveScheduler(config, logger53);
|
|
7898
7894
|
}
|
|
7899
7895
|
|
|
7900
7896
|
// src/agents/experts/expert-types.ts
|
|
@@ -12755,9 +12751,9 @@ var SkillLibrary = class {
|
|
|
12755
12751
|
config;
|
|
12756
12752
|
logger;
|
|
12757
12753
|
store;
|
|
12758
|
-
constructor(config = {},
|
|
12754
|
+
constructor(config = {}, logger53) {
|
|
12759
12755
|
this.config = { ...DEFAULT_SKILL_LIBRARY_CONFIG, ...config };
|
|
12760
|
-
this.logger =
|
|
12756
|
+
this.logger = logger53 ?? createLogger({ component: "SkillLibrary" });
|
|
12761
12757
|
this.store = {
|
|
12762
12758
|
skills: /* @__PURE__ */ new Map(),
|
|
12763
12759
|
executions: /* @__PURE__ */ new Map(),
|
|
@@ -13075,8 +13071,8 @@ var SkillLibrary = class {
|
|
|
13075
13071
|
return scored.sort((a, b) => b.score - a.score).map((s) => s.skill);
|
|
13076
13072
|
}
|
|
13077
13073
|
};
|
|
13078
|
-
function createSkillLibrary(config,
|
|
13079
|
-
return new SkillLibrary(config,
|
|
13074
|
+
function createSkillLibrary(config, logger53) {
|
|
13075
|
+
return new SkillLibrary(config, logger53);
|
|
13080
13076
|
}
|
|
13081
13077
|
|
|
13082
13078
|
// src/agents/skills/skill-composer.ts
|
|
@@ -13091,10 +13087,10 @@ var SkillComposer = class {
|
|
|
13091
13087
|
config;
|
|
13092
13088
|
logger;
|
|
13093
13089
|
library;
|
|
13094
|
-
constructor(library, config = {},
|
|
13090
|
+
constructor(library, config = {}, logger53) {
|
|
13095
13091
|
this.library = library;
|
|
13096
13092
|
this.config = { ...DEFAULT_COMPOSER_CONFIG, ...config };
|
|
13097
|
-
this.logger =
|
|
13093
|
+
this.logger = logger53 ?? createLogger({ component: "SkillComposer" });
|
|
13098
13094
|
}
|
|
13099
13095
|
/**
|
|
13100
13096
|
* Creates a composition plan for a task.
|
|
@@ -13324,8 +13320,8 @@ var SkillComposer = class {
|
|
|
13324
13320
|
return errors;
|
|
13325
13321
|
}
|
|
13326
13322
|
};
|
|
13327
|
-
function createSkillComposer(library, config,
|
|
13328
|
-
return new SkillComposer(library, config,
|
|
13323
|
+
function createSkillComposer(library, config, logger53) {
|
|
13324
|
+
return new SkillComposer(library, config, logger53);
|
|
13329
13325
|
}
|
|
13330
13326
|
|
|
13331
13327
|
// src/agents/skills/skill-dependency-graph-helpers.ts
|
|
@@ -14020,10 +14016,10 @@ var SkillLoader = class {
|
|
|
14020
14016
|
library;
|
|
14021
14017
|
logger;
|
|
14022
14018
|
mappingIndex;
|
|
14023
|
-
constructor(library, config,
|
|
14019
|
+
constructor(library, config, logger53) {
|
|
14024
14020
|
this.library = library;
|
|
14025
14021
|
this.config = { ...DEFAULT_SKILL_LOADER_CONFIG, ...config };
|
|
14026
|
-
this.logger =
|
|
14022
|
+
this.logger = logger53 ?? createLogger({ component: "SkillLoader" });
|
|
14027
14023
|
this.mappingIndex = /* @__PURE__ */ new Map();
|
|
14028
14024
|
for (const mapping of this.config.mappings) {
|
|
14029
14025
|
this.mappingIndex.set(mapping.role, mapping);
|
|
@@ -14246,8 +14242,8 @@ var SkillLoader = class {
|
|
|
14246
14242
|
return ok(orderResult.value);
|
|
14247
14243
|
}
|
|
14248
14244
|
};
|
|
14249
|
-
function createSkillLoader(library, config,
|
|
14250
|
-
return new SkillLoader(library, config,
|
|
14245
|
+
function createSkillLoader(library, config, logger53) {
|
|
14246
|
+
return new SkillLoader(library, config, logger53);
|
|
14251
14247
|
}
|
|
14252
14248
|
|
|
14253
14249
|
// src/agents/skills/external-pack-loader.ts
|
|
@@ -14309,13 +14305,13 @@ function validateManifest(raw, packName, source) {
|
|
|
14309
14305
|
}
|
|
14310
14306
|
return ok(parseResult2.data);
|
|
14311
14307
|
}
|
|
14312
|
-
async function loadExternalPack(packSource,
|
|
14308
|
+
async function loadExternalPack(packSource, logger53) {
|
|
14313
14309
|
const { name, source, enabled } = packSource;
|
|
14314
14310
|
if (!enabled) {
|
|
14315
|
-
|
|
14311
|
+
logger53.debug("Skipping disabled external pack", { name, source });
|
|
14316
14312
|
return ok({ packName: name, skillCount: 0, skills: [] });
|
|
14317
14313
|
}
|
|
14318
|
-
|
|
14314
|
+
logger53.info("Loading external skill pack", { name, source });
|
|
14319
14315
|
try {
|
|
14320
14316
|
const importPath = await resolveImportPath(source);
|
|
14321
14317
|
const module = await import(importPath);
|
|
@@ -14325,7 +14321,7 @@ async function loadExternalPack(packSource, logger52) {
|
|
|
14325
14321
|
return validationResult;
|
|
14326
14322
|
}
|
|
14327
14323
|
const manifest = validationResult.value;
|
|
14328
|
-
|
|
14324
|
+
logger53.info("External pack loaded successfully", {
|
|
14329
14325
|
name: manifest.name,
|
|
14330
14326
|
version: manifest.version,
|
|
14331
14327
|
skillCount: manifest.skills.length
|
|
@@ -14346,22 +14342,22 @@ async function loadExternalPack(packSource, logger52) {
|
|
|
14346
14342
|
);
|
|
14347
14343
|
}
|
|
14348
14344
|
}
|
|
14349
|
-
async function loadAllExternalPacks(packs,
|
|
14345
|
+
async function loadAllExternalPacks(packs, logger53) {
|
|
14350
14346
|
const loaded = [];
|
|
14351
14347
|
const errors = [];
|
|
14352
14348
|
for (const pack of packs) {
|
|
14353
|
-
const result = await loadExternalPack(pack,
|
|
14349
|
+
const result = await loadExternalPack(pack, logger53);
|
|
14354
14350
|
if (result.ok) {
|
|
14355
14351
|
loaded.push(result.value);
|
|
14356
14352
|
} else {
|
|
14357
14353
|
errors.push(result.error);
|
|
14358
|
-
|
|
14354
|
+
logger53.warn("Failed to load external pack", {
|
|
14359
14355
|
name: pack.name,
|
|
14360
14356
|
error: result.error.message
|
|
14361
14357
|
});
|
|
14362
14358
|
}
|
|
14363
14359
|
}
|
|
14364
|
-
|
|
14360
|
+
logger53.info("External pack loading complete", {
|
|
14365
14361
|
loaded: loaded.length,
|
|
14366
14362
|
errors: errors.length,
|
|
14367
14363
|
totalSkills: loaded.reduce((sum, r) => sum + r.skillCount, 0)
|
|
@@ -15269,9 +15265,9 @@ var SicaVersionManager = class {
|
|
|
15269
15265
|
versions;
|
|
15270
15266
|
events;
|
|
15271
15267
|
activeVersionId;
|
|
15272
|
-
constructor(config = {},
|
|
15268
|
+
constructor(config = {}, logger53) {
|
|
15273
15269
|
this.config = { ...DEFAULT_SICA_CONFIG, ...config };
|
|
15274
|
-
this.logger =
|
|
15270
|
+
this.logger = logger53 ?? createLogger({ component: "SicaVersionManager" });
|
|
15275
15271
|
this.versions = /* @__PURE__ */ new Map();
|
|
15276
15272
|
this.events = [];
|
|
15277
15273
|
this.activeVersionId = null;
|
|
@@ -19680,9 +19676,9 @@ var TemplateRegistry = class {
|
|
|
19680
19676
|
await this.ensureInitialized();
|
|
19681
19677
|
const { templates, errors } = await loadTemplatesFromDirectory(directoryPath);
|
|
19682
19678
|
if (errors.length > 0) {
|
|
19683
|
-
const
|
|
19679
|
+
const logger53 = createLogger({ component: "TemplateRegistry" });
|
|
19684
19680
|
for (const error of errors) {
|
|
19685
|
-
|
|
19681
|
+
logger53.warn("Template loading warning", { error: error.message });
|
|
19686
19682
|
}
|
|
19687
19683
|
}
|
|
19688
19684
|
let loadedCount = 0;
|
|
@@ -19694,8 +19690,8 @@ var TemplateRegistry = class {
|
|
|
19694
19690
|
loadedCount++;
|
|
19695
19691
|
}
|
|
19696
19692
|
} catch (regError) {
|
|
19697
|
-
const
|
|
19698
|
-
|
|
19693
|
+
const logger53 = createLogger({ component: "TemplateRegistry" });
|
|
19694
|
+
logger53.warn("Template registration failed", {
|
|
19699
19695
|
template: definition.name,
|
|
19700
19696
|
error: regError instanceof Error ? regError.message : String(regError)
|
|
19701
19697
|
});
|
|
@@ -20544,11 +20540,11 @@ var BudgetCircuitError = class extends NexusError {
|
|
|
20544
20540
|
|
|
20545
20541
|
// src/workflows/budget-circuit-breaker.ts
|
|
20546
20542
|
var BudgetCircuitBreaker = class {
|
|
20547
|
-
constructor(maxTokens, config,
|
|
20543
|
+
constructor(maxTokens, config, logger53) {
|
|
20548
20544
|
this.maxTokens = maxTokens;
|
|
20549
20545
|
this.config = { ...DEFAULT_BUDGET_CIRCUIT_CONFIG, ...config };
|
|
20550
20546
|
this.lastStateChange = getTimeProvider().now();
|
|
20551
|
-
this.logger =
|
|
20547
|
+
this.logger = logger53 ?? createLogger({ component: "budget-circuit-breaker" });
|
|
20552
20548
|
}
|
|
20553
20549
|
state = "closed";
|
|
20554
20550
|
lastStateChange;
|
|
@@ -20858,10 +20854,10 @@ function createSkippedResult() {
|
|
|
20858
20854
|
circuitState: "closed"
|
|
20859
20855
|
};
|
|
20860
20856
|
}
|
|
20861
|
-
function logEnforcementResult(
|
|
20857
|
+
function logEnforcementResult(logger53, stepId, result, currentUsagePercent) {
|
|
20862
20858
|
const usagePercent = Math.round(currentUsagePercent * 100);
|
|
20863
20859
|
if (!result.allowed) {
|
|
20864
|
-
|
|
20860
|
+
logger53.warn("Budget enforcement blocked step", {
|
|
20865
20861
|
stepId,
|
|
20866
20862
|
reason: result.reason,
|
|
20867
20863
|
circuitState: result.circuitState,
|
|
@@ -20871,14 +20867,14 @@ function logEnforcementResult(logger52, stepId, result, currentUsagePercent) {
|
|
|
20871
20867
|
return;
|
|
20872
20868
|
}
|
|
20873
20869
|
if (result.warning !== void 0) {
|
|
20874
|
-
|
|
20870
|
+
logger53.warn("Budget enforcement warning", {
|
|
20875
20871
|
stepId,
|
|
20876
20872
|
warning: result.warning,
|
|
20877
20873
|
currentUsage: usagePercent
|
|
20878
20874
|
});
|
|
20879
20875
|
return;
|
|
20880
20876
|
}
|
|
20881
|
-
|
|
20877
|
+
logger53.debug("Budget enforcement passed for step", {
|
|
20882
20878
|
stepId,
|
|
20883
20879
|
currentUsage: usagePercent,
|
|
20884
20880
|
allocatedTokens: result.allocatedTokens
|
|
@@ -20914,15 +20910,15 @@ function buildFinalOutput(stepResults) {
|
|
|
20914
20910
|
}
|
|
20915
20911
|
|
|
20916
20912
|
// src/workflows/workflow-engine-execution.ts
|
|
20917
|
-
function createContextManagerForWorkflow(config, workflow,
|
|
20913
|
+
function createContextManagerForWorkflow(config, workflow, logger53) {
|
|
20918
20914
|
if (config.contextManagerConfig === void 0) return void 0;
|
|
20919
20915
|
const budget = workflow.defaultBudget ?? config.defaultBudget;
|
|
20920
|
-
return new ContextManager({ ...config.contextManagerConfig, budget, logger:
|
|
20916
|
+
return new ContextManager({ ...config.contextManagerConfig, budget, logger: logger53 });
|
|
20921
20917
|
}
|
|
20922
|
-
function createBudgetCircuitBreakerForWorkflow(contextManager, workflow, config,
|
|
20918
|
+
function createBudgetCircuitBreakerForWorkflow(contextManager, workflow, config, logger53) {
|
|
20923
20919
|
const budgetConfig = {
|
|
20924
20920
|
engineDefaultBudget: config.defaultBudget,
|
|
20925
|
-
logger:
|
|
20921
|
+
logger: logger53
|
|
20926
20922
|
};
|
|
20927
20923
|
if (workflow.defaultBudget !== void 0) {
|
|
20928
20924
|
budgetConfig.workflowDefaultBudget = workflow.defaultBudget;
|
|
@@ -20957,12 +20953,12 @@ function applyInputDefaults(workflow, inputs) {
|
|
|
20957
20953
|
return merged;
|
|
20958
20954
|
}
|
|
20959
20955
|
function initializeExecution(params) {
|
|
20960
|
-
const { workflow, inputs, config, logger:
|
|
20956
|
+
const { workflow, inputs, config, logger: logger53 } = params;
|
|
20961
20957
|
const executionId = generateUUID();
|
|
20962
20958
|
const startTime = getTimeProvider().now();
|
|
20963
20959
|
const resolvedInputs = applyInputDefaults(workflow, inputs);
|
|
20964
|
-
const contextManager = createContextManagerForWorkflow(config, workflow,
|
|
20965
|
-
const budgetCircuitBreaker = config.enableBudgetEnforcement ? createBudgetCircuitBreakerForWorkflow(contextManager, workflow, config,
|
|
20960
|
+
const contextManager = createContextManagerForWorkflow(config, workflow, logger53);
|
|
20961
|
+
const budgetCircuitBreaker = config.enableBudgetEnforcement ? createBudgetCircuitBreakerForWorkflow(contextManager, workflow, config, logger53) : void 0;
|
|
20966
20962
|
const context = {
|
|
20967
20963
|
workflowId: workflow.name,
|
|
20968
20964
|
executionId,
|
|
@@ -20982,7 +20978,7 @@ function initializeExecution(params) {
|
|
|
20982
20978
|
startTime
|
|
20983
20979
|
};
|
|
20984
20980
|
if (contextManager !== void 0) {
|
|
20985
|
-
|
|
20981
|
+
logger53.debug("Context manager initialized for workflow execution", {
|
|
20986
20982
|
executionId,
|
|
20987
20983
|
workflowName: workflow.name,
|
|
20988
20984
|
budget: workflow.defaultBudget ?? config.defaultBudget
|
|
@@ -20991,10 +20987,10 @@ function initializeExecution(params) {
|
|
|
20991
20987
|
return { executionId, context, startTime, execution };
|
|
20992
20988
|
}
|
|
20993
20989
|
function enforceStepBudgets(options) {
|
|
20994
|
-
const { steps, context, workflow, totalSteps, config, logger:
|
|
20990
|
+
const { steps, context, workflow, totalSteps, config, logger: logger53 } = options;
|
|
20995
20991
|
const budgetConfig = {
|
|
20996
20992
|
engineDefaultBudget: config.defaultBudget,
|
|
20997
|
-
logger:
|
|
20993
|
+
logger: logger53
|
|
20998
20994
|
};
|
|
20999
20995
|
if (workflow.defaultBudget !== void 0) {
|
|
21000
20996
|
budgetConfig.workflowDefaultBudget = workflow.defaultBudget;
|
|
@@ -21279,29 +21275,29 @@ function createExpertFactoryWithAdapter(adapter) {
|
|
|
21279
21275
|
};
|
|
21280
21276
|
return new ExpertFactoryAdapter(factoryWrapper);
|
|
21281
21277
|
}
|
|
21282
|
-
function adaptLoggerForStepExecutor(
|
|
21278
|
+
function adaptLoggerForStepExecutor(logger53) {
|
|
21283
21279
|
return {
|
|
21284
21280
|
debug: (message, data) => {
|
|
21285
|
-
|
|
21281
|
+
logger53.debug(message, data);
|
|
21286
21282
|
},
|
|
21287
21283
|
info: (message, data) => {
|
|
21288
|
-
|
|
21284
|
+
logger53.info(message, data);
|
|
21289
21285
|
},
|
|
21290
21286
|
warn: (message, data) => {
|
|
21291
|
-
|
|
21287
|
+
logger53.warn(message, data);
|
|
21292
21288
|
},
|
|
21293
21289
|
error: (message, data) => {
|
|
21294
21290
|
if (data !== void 0) {
|
|
21295
21291
|
const errorContext = { ...data };
|
|
21296
|
-
|
|
21292
|
+
logger53.error(message, void 0, errorContext);
|
|
21297
21293
|
} else {
|
|
21298
|
-
|
|
21294
|
+
logger53.error(message);
|
|
21299
21295
|
}
|
|
21300
21296
|
}
|
|
21301
21297
|
};
|
|
21302
21298
|
}
|
|
21303
|
-
function createRealStepExecutorCallback(expertFactory,
|
|
21304
|
-
const adaptedLogger = adaptLoggerForStepExecutor(
|
|
21299
|
+
function createRealStepExecutorCallback(expertFactory, logger53, workflowId) {
|
|
21300
|
+
const adaptedLogger = adaptLoggerForStepExecutor(logger53);
|
|
21305
21301
|
const executor = createStepExecutor({ expertFactory, logger: adaptedLogger });
|
|
21306
21302
|
return async (step, ctx) => {
|
|
21307
21303
|
const startTime = getTimeProvider().now();
|
|
@@ -21317,7 +21313,7 @@ function createRealStepExecutorCallback(expertFactory, logger52, workflowId) {
|
|
|
21317
21313
|
}
|
|
21318
21314
|
const result = await executor.execute(step, workflowCtx);
|
|
21319
21315
|
if (!result.ok) {
|
|
21320
|
-
|
|
21316
|
+
logger53.warn("Step execution failed", {
|
|
21321
21317
|
stepId: step.id,
|
|
21322
21318
|
error: result.error.message
|
|
21323
21319
|
});
|
|
@@ -21377,10 +21373,10 @@ function adaptExecutionPlan(plannerPlan) {
|
|
|
21377
21373
|
}));
|
|
21378
21374
|
return { phases };
|
|
21379
21375
|
}
|
|
21380
|
-
function createMockStepExecutor(
|
|
21376
|
+
function createMockStepExecutor(logger53) {
|
|
21381
21377
|
return (step, _ctx) => {
|
|
21382
21378
|
const startTime = getTimeProvider().now();
|
|
21383
|
-
|
|
21379
|
+
logger53.debug("Executing step (mock)", {
|
|
21384
21380
|
stepId: step.id,
|
|
21385
21381
|
agent: step.agent,
|
|
21386
21382
|
action: step.action
|
|
@@ -21389,16 +21385,16 @@ function createMockStepExecutor(logger52) {
|
|
|
21389
21385
|
};
|
|
21390
21386
|
}
|
|
21391
21387
|
function resolveStepExecutor(options) {
|
|
21392
|
-
const { logger:
|
|
21388
|
+
const { logger: logger53, expertFactory, workflowId, useMockExecutor } = options;
|
|
21393
21389
|
if (useMockExecutor === true) {
|
|
21394
|
-
|
|
21390
|
+
logger53.warn(
|
|
21395
21391
|
"useMockExecutor enabled; workflow steps will return mock results (NOT RECOMMENDED)"
|
|
21396
21392
|
);
|
|
21397
|
-
return createMockStepExecutor(
|
|
21393
|
+
return createMockStepExecutor(logger53);
|
|
21398
21394
|
}
|
|
21399
21395
|
if (expertFactory !== void 0 && workflowId !== void 0) {
|
|
21400
|
-
|
|
21401
|
-
return createRealStepExecutorCallback(expertFactory,
|
|
21396
|
+
logger53.info("Using real StepExecutor with ExpertFactory", { workflowId });
|
|
21397
|
+
return createRealStepExecutorCallback(expertFactory, logger53, workflowId);
|
|
21402
21398
|
}
|
|
21403
21399
|
if (expertFactory !== void 0 && workflowId === void 0) {
|
|
21404
21400
|
throw new WorkflowExecutionUnavailableError("expertFactory provided but workflowId missing");
|
|
@@ -21409,9 +21405,9 @@ function resolveStepExecutor(options) {
|
|
|
21409
21405
|
}
|
|
21410
21406
|
function createExecutePhase(options) {
|
|
21411
21407
|
const stepExecutor = resolveStepExecutor(options);
|
|
21412
|
-
const { logger:
|
|
21408
|
+
const { logger: logger53 } = options;
|
|
21413
21409
|
return async (steps, context, executionOptions) => {
|
|
21414
|
-
|
|
21410
|
+
logger53.debug("Executing phase", {
|
|
21415
21411
|
stepCount: steps.length,
|
|
21416
21412
|
executionId: context.executionId,
|
|
21417
21413
|
maxConcurrency: executionOptions.maxConcurrency
|
|
@@ -21462,26 +21458,26 @@ function createAdaptedExecutionPlan() {
|
|
|
21462
21458
|
return ok(adaptExecutionPlan(planResult.value));
|
|
21463
21459
|
};
|
|
21464
21460
|
}
|
|
21465
|
-
function resolveExpertFactory(config,
|
|
21461
|
+
function resolveExpertFactory(config, logger53) {
|
|
21466
21462
|
if (config?.expertFactory !== void 0) {
|
|
21467
21463
|
return config.expertFactory;
|
|
21468
21464
|
}
|
|
21469
21465
|
if (config?.modelAdapter !== void 0) {
|
|
21470
|
-
|
|
21466
|
+
logger53.info("Created ExpertFactory with provided model adapter");
|
|
21471
21467
|
return createExpertFactoryWithAdapter(config.modelAdapter);
|
|
21472
21468
|
}
|
|
21473
21469
|
return void 0;
|
|
21474
21470
|
}
|
|
21475
21471
|
function createWorkflowEngineDeps(config) {
|
|
21476
|
-
const
|
|
21472
|
+
const logger53 = config?.logger ?? createLogger({ component: "WorkflowEngine" });
|
|
21477
21473
|
const builtInTemplates = config?.builtInTemplates ?? cachedBuiltInTemplates ?? /* @__PURE__ */ new Map();
|
|
21478
|
-
const expertFactory = resolveExpertFactory(config,
|
|
21474
|
+
const expertFactory = resolveExpertFactory(config, logger53);
|
|
21479
21475
|
return {
|
|
21480
21476
|
parseWorkflow: createParseWorkflow(),
|
|
21481
21477
|
loadWorkflowFile: createLoadWorkflowFile(),
|
|
21482
21478
|
createExecutionPlan: createAdaptedExecutionPlan(),
|
|
21483
21479
|
executePhase: createExecutePhase({
|
|
21484
|
-
logger:
|
|
21480
|
+
logger: logger53,
|
|
21485
21481
|
expertFactory,
|
|
21486
21482
|
workflowId: "default",
|
|
21487
21483
|
useMockExecutor: config?.useMockExecutor
|
|
@@ -21512,32 +21508,32 @@ async function createInitializedWorkflowEngine(config) {
|
|
|
21512
21508
|
function shouldSkipAdapterDetection(config) {
|
|
21513
21509
|
return config?.modelAdapter !== void 0 || config?.expertFactory !== void 0 || config?.useMockExecutor === true;
|
|
21514
21510
|
}
|
|
21515
|
-
function tryAutoDetectAdapter(
|
|
21511
|
+
function tryAutoDetectAdapter(logger53) {
|
|
21516
21512
|
try {
|
|
21517
|
-
|
|
21518
|
-
const registry = getGlobalRegistry({ logger:
|
|
21513
|
+
logger53.info("Auto-detecting model adapter for workflow execution");
|
|
21514
|
+
const registry = getGlobalRegistry({ logger: logger53 });
|
|
21519
21515
|
const adapter = registry.getDefault();
|
|
21520
|
-
|
|
21516
|
+
logger53.info("Using unified registry default adapter");
|
|
21521
21517
|
return adapter;
|
|
21522
21518
|
} catch (error) {
|
|
21523
21519
|
const message = getErrorMessage(error);
|
|
21524
|
-
|
|
21520
|
+
logger53.warn("No model adapter available, using mock executor", { error: message });
|
|
21525
21521
|
return void 0;
|
|
21526
21522
|
}
|
|
21527
21523
|
}
|
|
21528
21524
|
function createWorkflowEngineDepsAsync(config) {
|
|
21529
|
-
const
|
|
21525
|
+
const logger53 = config?.logger ?? createLogger({ component: "WorkflowEngine" });
|
|
21530
21526
|
if (shouldSkipAdapterDetection(config)) {
|
|
21531
|
-
|
|
21527
|
+
logger53.debug("Skipping adapter detection - using provided config");
|
|
21532
21528
|
return Promise.resolve(createWorkflowEngineDeps(config));
|
|
21533
21529
|
}
|
|
21534
|
-
const adapter = tryAutoDetectAdapter(
|
|
21530
|
+
const adapter = tryAutoDetectAdapter(logger53);
|
|
21535
21531
|
if (adapter !== void 0) {
|
|
21536
|
-
return Promise.resolve(createWorkflowEngineDeps({ ...config, modelAdapter: adapter, logger:
|
|
21532
|
+
return Promise.resolve(createWorkflowEngineDeps({ ...config, modelAdapter: adapter, logger: logger53 }));
|
|
21537
21533
|
}
|
|
21538
21534
|
if (config?.useMockExecutor === true) {
|
|
21539
|
-
|
|
21540
|
-
return Promise.resolve(createWorkflowEngineDeps({ ...config, useMockExecutor: true, logger:
|
|
21535
|
+
logger53.warn("Using mock executor as explicitly configured (no real adapter available)");
|
|
21536
|
+
return Promise.resolve(createWorkflowEngineDeps({ ...config, useMockExecutor: true, logger: logger53 }));
|
|
21541
21537
|
}
|
|
21542
21538
|
return Promise.reject(
|
|
21543
21539
|
new WorkflowExecutionUnavailableError(
|
|
@@ -21619,23 +21615,23 @@ function createToolLogger(parentLogger, toolName, requestId) {
|
|
|
21619
21615
|
}
|
|
21620
21616
|
return parentLogger.child(context);
|
|
21621
21617
|
}
|
|
21622
|
-
function logToolStart(
|
|
21623
|
-
|
|
21618
|
+
function logToolStart(logger53, toolName, args) {
|
|
21619
|
+
logger53.info("Tool execution started", {
|
|
21624
21620
|
tool: toolName,
|
|
21625
21621
|
hasArgs: args !== void 0,
|
|
21626
21622
|
argKeys: args !== void 0 ? Object.keys(args) : []
|
|
21627
21623
|
});
|
|
21628
21624
|
}
|
|
21629
|
-
function logToolSuccess(
|
|
21630
|
-
|
|
21625
|
+
function logToolSuccess(logger53, toolName, durationMs, resultInfo) {
|
|
21626
|
+
logger53.info("Tool execution completed", {
|
|
21631
21627
|
tool: toolName,
|
|
21632
21628
|
durationMs,
|
|
21633
21629
|
success: true,
|
|
21634
21630
|
...resultInfo
|
|
21635
21631
|
});
|
|
21636
21632
|
}
|
|
21637
|
-
function logToolError(
|
|
21638
|
-
|
|
21633
|
+
function logToolError(logger53, toolName, error, durationMs) {
|
|
21634
|
+
logger53.error("Tool execution failed", error, {
|
|
21639
21635
|
tool: toolName,
|
|
21640
21636
|
durationMs,
|
|
21641
21637
|
success: false,
|
|
@@ -21648,8 +21644,8 @@ function createTimer() {
|
|
|
21648
21644
|
elapsed: () => getTimeProvider().now() - startTime
|
|
21649
21645
|
};
|
|
21650
21646
|
}
|
|
21651
|
-
function withLogging(toolName, handler3,
|
|
21652
|
-
const toolLogger = createToolLogger(
|
|
21647
|
+
function withLogging(toolName, handler3, logger53) {
|
|
21648
|
+
const toolLogger = createToolLogger(logger53, toolName);
|
|
21653
21649
|
return async (args) => {
|
|
21654
21650
|
const timer = createTimer();
|
|
21655
21651
|
logToolStart(toolLogger, toolName, args);
|
|
@@ -21734,9 +21730,9 @@ var AuthHandler = class {
|
|
|
21734
21730
|
config;
|
|
21735
21731
|
logger;
|
|
21736
21732
|
storedToken;
|
|
21737
|
-
constructor(config,
|
|
21733
|
+
constructor(config, logger53) {
|
|
21738
21734
|
this.config = resolveAuthConfig(config);
|
|
21739
|
-
this.logger =
|
|
21735
|
+
this.logger = logger53 ?? createLogger({ component: "AuthHandler" });
|
|
21740
21736
|
if (this.config.enabled) this.loadToken();
|
|
21741
21737
|
}
|
|
21742
21738
|
/**
|
|
@@ -21835,19 +21831,19 @@ var AuthHandler = class {
|
|
|
21835
21831
|
};
|
|
21836
21832
|
|
|
21837
21833
|
// src/mcp/middleware/tool-error-handler.ts
|
|
21838
|
-
function toolErrorResponse(prefix, error,
|
|
21834
|
+
function toolErrorResponse(prefix, error, logger53) {
|
|
21839
21835
|
const message = getErrorMessage(error);
|
|
21840
|
-
if (
|
|
21836
|
+
if (logger53 !== void 0) {
|
|
21841
21837
|
const errorObj = error instanceof Error ? error : new Error(message);
|
|
21842
|
-
|
|
21838
|
+
logger53.error(prefix, errorObj);
|
|
21843
21839
|
}
|
|
21844
21840
|
return toolStructuredError({ errorCategory: "internal", message: `${prefix}: ${message}` });
|
|
21845
21841
|
}
|
|
21846
|
-
async function withToolError(prefix,
|
|
21842
|
+
async function withToolError(prefix, logger53, fn) {
|
|
21847
21843
|
try {
|
|
21848
21844
|
return await fn();
|
|
21849
21845
|
} catch (error) {
|
|
21850
|
-
return toolErrorResponse(prefix, error,
|
|
21846
|
+
return toolErrorResponse(prefix, error, logger53);
|
|
21851
21847
|
}
|
|
21852
21848
|
}
|
|
21853
21849
|
|
|
@@ -24327,47 +24323,47 @@ function createSubscriptions(eventBus, subs, handler3) {
|
|
|
24327
24323
|
}
|
|
24328
24324
|
return subscriptions;
|
|
24329
24325
|
}
|
|
24330
|
-
function createCleanupFunction(subscriptions, eventBus,
|
|
24326
|
+
function createCleanupFunction(subscriptions, eventBus, logger53) {
|
|
24331
24327
|
return () => {
|
|
24332
|
-
|
|
24328
|
+
logger53.debug("Cleaning up EventBus bridge subscriptions");
|
|
24333
24329
|
for (const sub of subscriptions) {
|
|
24334
24330
|
sub.unsubscribe();
|
|
24335
24331
|
}
|
|
24336
|
-
|
|
24332
|
+
logger53.info("EventBus bridge cleanup complete", {
|
|
24337
24333
|
unsubscribedCount: subscriptions.length,
|
|
24338
24334
|
finalStats: eventBus.getStats()
|
|
24339
24335
|
});
|
|
24340
24336
|
};
|
|
24341
24337
|
}
|
|
24342
|
-
function initializeEventBusBridge(observer,
|
|
24338
|
+
function initializeEventBusBridge(observer, logger53, config) {
|
|
24343
24339
|
const mergedConfig = mergeConfig2(config);
|
|
24344
24340
|
if (!mergedConfig.enabled) {
|
|
24345
|
-
|
|
24341
|
+
logger53.debug("EventBus bridge disabled by configuration");
|
|
24346
24342
|
return { initialized: false, subscriptionCount: 0, cleanup: () => {
|
|
24347
24343
|
} };
|
|
24348
24344
|
}
|
|
24349
24345
|
const eventBus = getGlobalEventBus({ maxHistorySize: mergedConfig.maxHistorySize });
|
|
24350
24346
|
const logConfig = mergedConfig.logging;
|
|
24351
|
-
|
|
24347
|
+
logger53.info("Initializing EventBus bridge for MCP server", {
|
|
24352
24348
|
maxHistorySize: mergedConfig.maxHistorySize,
|
|
24353
24349
|
subscriptions: mergedConfig.subscriptions
|
|
24354
24350
|
});
|
|
24355
24351
|
const handler3 = (event) => {
|
|
24356
|
-
handleEvent(event, observer,
|
|
24352
|
+
handleEvent(event, observer, logger53, logConfig);
|
|
24357
24353
|
};
|
|
24358
24354
|
const subscriptions = createSubscriptions(eventBus, mergedConfig.subscriptions, handler3);
|
|
24359
|
-
|
|
24355
|
+
logger53.info("EventBus bridge initialized", {
|
|
24360
24356
|
subscriptionCount: subscriptions.length,
|
|
24361
24357
|
eventBusStats: eventBus.getStats()
|
|
24362
24358
|
});
|
|
24363
|
-
const cleanup = createCleanupFunction(subscriptions, eventBus,
|
|
24359
|
+
const cleanup = createCleanupFunction(subscriptions, eventBus, logger53);
|
|
24364
24360
|
return {
|
|
24365
24361
|
initialized: true,
|
|
24366
24362
|
subscriptionCount: subscriptions.length,
|
|
24367
24363
|
cleanup
|
|
24368
24364
|
};
|
|
24369
24365
|
}
|
|
24370
|
-
function handleEvent(event, observer,
|
|
24366
|
+
function handleEvent(event, observer, logger53, logConfig) {
|
|
24371
24367
|
const isImportant = IMPORTANT_TOPICS.has(event.topic);
|
|
24372
24368
|
const logLevel = isImportant ? logConfig.importantEventLevel : logConfig.frequentEventLevel;
|
|
24373
24369
|
const logContext = {
|
|
@@ -24378,9 +24374,9 @@ function handleEvent(event, observer, logger52, logConfig) {
|
|
|
24378
24374
|
timestamp: event.timestamp
|
|
24379
24375
|
};
|
|
24380
24376
|
if (logLevel === "info") {
|
|
24381
|
-
|
|
24377
|
+
logger53.info(`EventBus: ${event.topic}`, logContext);
|
|
24382
24378
|
} else {
|
|
24383
|
-
|
|
24379
|
+
logger53.debug(`EventBus: ${event.topic}`, logContext);
|
|
24384
24380
|
}
|
|
24385
24381
|
recordEventToObserver(event, observer);
|
|
24386
24382
|
}
|
|
@@ -24558,19 +24554,19 @@ var PROMPT_DEFINITIONS = [
|
|
|
24558
24554
|
];
|
|
24559
24555
|
|
|
24560
24556
|
// src/mcp/prompts/index.ts
|
|
24561
|
-
function registerPrompts(server,
|
|
24557
|
+
function registerPrompts(server, logger53) {
|
|
24562
24558
|
const registered = [];
|
|
24563
24559
|
for (const definition of PROMPT_DEFINITIONS) {
|
|
24564
|
-
registerSinglePrompt(server, definition,
|
|
24560
|
+
registerSinglePrompt(server, definition, logger53);
|
|
24565
24561
|
registered.push(definition.name);
|
|
24566
24562
|
}
|
|
24567
|
-
|
|
24563
|
+
logger53.info("Prompt templates registered", {
|
|
24568
24564
|
count: registered.length,
|
|
24569
24565
|
prompts: registered
|
|
24570
24566
|
});
|
|
24571
24567
|
return { prompts: registered };
|
|
24572
24568
|
}
|
|
24573
|
-
function registerSinglePrompt(server, definition,
|
|
24569
|
+
function registerSinglePrompt(server, definition, logger53) {
|
|
24574
24570
|
server.registerPrompt(
|
|
24575
24571
|
definition.name,
|
|
24576
24572
|
{
|
|
@@ -24578,7 +24574,7 @@ function registerSinglePrompt(server, definition, logger52) {
|
|
|
24578
24574
|
argsSchema: definition.argsSchema
|
|
24579
24575
|
},
|
|
24580
24576
|
(args) => {
|
|
24581
|
-
|
|
24577
|
+
logger53.debug("Prompt requested", { prompt: definition.name });
|
|
24582
24578
|
const messages = definition.buildMessages(args);
|
|
24583
24579
|
return {
|
|
24584
24580
|
description: definition.description,
|
|
@@ -24618,7 +24614,7 @@ function buildModelsPayload() {
|
|
|
24618
24614
|
}))
|
|
24619
24615
|
};
|
|
24620
24616
|
}
|
|
24621
|
-
function registerModelsResource(server,
|
|
24617
|
+
function registerModelsResource(server, logger53) {
|
|
24622
24618
|
server.registerResource(
|
|
24623
24619
|
MODELS_RESOURCE_NAME,
|
|
24624
24620
|
MODELS_RESOURCE_URI,
|
|
@@ -24627,7 +24623,7 @@ function registerModelsResource(server, logger52) {
|
|
|
24627
24623
|
mimeType: "application/json"
|
|
24628
24624
|
},
|
|
24629
24625
|
() => {
|
|
24630
|
-
|
|
24626
|
+
logger53.debug("Reading models resource");
|
|
24631
24627
|
const payload = buildModelsPayload();
|
|
24632
24628
|
return {
|
|
24633
24629
|
contents: [
|
|
@@ -24640,7 +24636,7 @@ function registerModelsResource(server, logger52) {
|
|
|
24640
24636
|
};
|
|
24641
24637
|
}
|
|
24642
24638
|
);
|
|
24643
|
-
|
|
24639
|
+
logger53.info("Registered models resource", { uri: MODELS_RESOURCE_URI });
|
|
24644
24640
|
}
|
|
24645
24641
|
|
|
24646
24642
|
// src/indexer/research-index/research-index-base-types.ts
|
|
@@ -25451,10 +25447,10 @@ ${topicLines}
|
|
|
25451
25447
|
// src/mcp/resources/research-resource.ts
|
|
25452
25448
|
var RESEARCH_RESOURCE_URI = "nexus://research/papers";
|
|
25453
25449
|
var RESEARCH_RESOURCE_NAME = "research-papers";
|
|
25454
|
-
function buildResearchPayload(
|
|
25450
|
+
function buildResearchPayload(logger53) {
|
|
25455
25451
|
const result = parseRegistry();
|
|
25456
25452
|
if (!result.ok) {
|
|
25457
|
-
|
|
25453
|
+
logger53.debug("Research registry not available", {
|
|
25458
25454
|
error: result.error.message
|
|
25459
25455
|
});
|
|
25460
25456
|
return {
|
|
@@ -25488,7 +25484,7 @@ function buildResearchPayload(logger52) {
|
|
|
25488
25484
|
stats: index.stats
|
|
25489
25485
|
};
|
|
25490
25486
|
}
|
|
25491
|
-
function registerResearchResource(server,
|
|
25487
|
+
function registerResearchResource(server, logger53) {
|
|
25492
25488
|
server.registerResource(
|
|
25493
25489
|
RESEARCH_RESOURCE_NAME,
|
|
25494
25490
|
RESEARCH_RESOURCE_URI,
|
|
@@ -25497,9 +25493,9 @@ function registerResearchResource(server, logger52) {
|
|
|
25497
25493
|
mimeType: "application/json"
|
|
25498
25494
|
},
|
|
25499
25495
|
() => {
|
|
25500
|
-
|
|
25496
|
+
logger53.debug("Reading research resource");
|
|
25501
25497
|
try {
|
|
25502
|
-
const payload = buildResearchPayload(
|
|
25498
|
+
const payload = buildResearchPayload(logger53);
|
|
25503
25499
|
return {
|
|
25504
25500
|
contents: [
|
|
25505
25501
|
{
|
|
@@ -25510,7 +25506,7 @@ function registerResearchResource(server, logger52) {
|
|
|
25510
25506
|
]
|
|
25511
25507
|
};
|
|
25512
25508
|
} catch (error) {
|
|
25513
|
-
|
|
25509
|
+
logger53.warn("Failed to build research payload", {
|
|
25514
25510
|
error: getErrorMessage(error)
|
|
25515
25511
|
});
|
|
25516
25512
|
return {
|
|
@@ -25525,7 +25521,7 @@ function registerResearchResource(server, logger52) {
|
|
|
25525
25521
|
}
|
|
25526
25522
|
}
|
|
25527
25523
|
);
|
|
25528
|
-
|
|
25524
|
+
logger53.info("Registered research resource", { uri: RESEARCH_RESOURCE_URI });
|
|
25529
25525
|
}
|
|
25530
25526
|
|
|
25531
25527
|
// src/mcp/tools/create-expert.ts
|
|
@@ -25626,29 +25622,29 @@ var ROLE_TO_TASK_CATEGORY = {
|
|
|
25626
25622
|
pm_expert: "planning",
|
|
25627
25623
|
ux_expert: "planning"
|
|
25628
25624
|
};
|
|
25629
|
-
function resolveAdapterForModelPreference(modelPreference, fallbackAdapter,
|
|
25630
|
-
const registry = getGlobalRegistry({ logger:
|
|
25625
|
+
function resolveAdapterForModelPreference(modelPreference, fallbackAdapter, logger53) {
|
|
25626
|
+
const registry = getGlobalRegistry({ logger: logger53 });
|
|
25631
25627
|
const adapter = registry.getAdapterForModel(modelPreference);
|
|
25632
25628
|
if (adapter === registry.getDefault() && fallbackAdapter !== void 0) {
|
|
25633
|
-
|
|
25629
|
+
logger53.debug("Model preference not in registry, using fallback adapter", { modelPreference });
|
|
25634
25630
|
return fallbackAdapter;
|
|
25635
25631
|
}
|
|
25636
|
-
|
|
25632
|
+
logger53.info("Routing expert to CLI for model preference", { modelPreference });
|
|
25637
25633
|
return adapter;
|
|
25638
25634
|
}
|
|
25639
|
-
function resolveAdapterForRole(role, fallbackAdapter,
|
|
25635
|
+
function resolveAdapterForRole(role, fallbackAdapter, logger53) {
|
|
25640
25636
|
const category = ROLE_TO_TASK_CATEGORY[role];
|
|
25641
25637
|
if (category === void 0) return fallbackAdapter;
|
|
25642
|
-
const registry = getGlobalRegistry({ logger:
|
|
25638
|
+
const registry = getGlobalRegistry({ logger: logger53 });
|
|
25643
25639
|
const adapter = registry.getAdapter(category);
|
|
25644
|
-
|
|
25640
|
+
logger53.info("Auto-routing expert to specialized CLI", {
|
|
25645
25641
|
role,
|
|
25646
25642
|
category,
|
|
25647
25643
|
preferredCli: registry.getRouting(category)?.primaryCli
|
|
25648
25644
|
});
|
|
25649
25645
|
return adapter;
|
|
25650
25646
|
}
|
|
25651
|
-
function getExpertFallbackChain(role, excludeCli,
|
|
25647
|
+
function getExpertFallbackChain(role, excludeCli, logger53) {
|
|
25652
25648
|
const category = ROLE_TO_TASK_CATEGORY[role];
|
|
25653
25649
|
if (category === void 0) return [];
|
|
25654
25650
|
const bucketType = CATEGORY_TO_FALLBACK_TYPE[category];
|
|
@@ -25657,7 +25653,7 @@ function getExpertFallbackChain(role, excludeCli, logger52) {
|
|
|
25657
25653
|
bucketType
|
|
25658
25654
|
);
|
|
25659
25655
|
const filtered = chain.filter((cli) => cli !== excludeCli);
|
|
25660
|
-
|
|
25656
|
+
logger53.debug("Expert fallback chain resolved", { role, category, excludeCli, chain: filtered });
|
|
25661
25657
|
return [...filtered];
|
|
25662
25658
|
}
|
|
25663
25659
|
|
|
@@ -25763,16 +25759,16 @@ function buildResponse(expert) {
|
|
|
25763
25759
|
};
|
|
25764
25760
|
}
|
|
25765
25761
|
function createExpertFromFactory(deps, expertType, modelPreference, role) {
|
|
25766
|
-
const
|
|
25762
|
+
const logger53 = deps.logger ?? createLogger({ tool: "create_expert" });
|
|
25767
25763
|
const options = {};
|
|
25768
25764
|
if (modelPreference !== void 0) {
|
|
25769
25765
|
options.modelOverrides = { modelId: modelPreference };
|
|
25770
25766
|
}
|
|
25771
25767
|
let adapter;
|
|
25772
25768
|
if (modelPreference !== void 0) {
|
|
25773
|
-
adapter = resolveAdapterForModelPreference(modelPreference, deps.modelAdapter,
|
|
25769
|
+
adapter = resolveAdapterForModelPreference(modelPreference, deps.modelAdapter, logger53);
|
|
25774
25770
|
} else if (role !== void 0) {
|
|
25775
|
-
adapter = resolveAdapterForRole(role, deps.modelAdapter,
|
|
25771
|
+
adapter = resolveAdapterForRole(role, deps.modelAdapter, logger53);
|
|
25776
25772
|
} else {
|
|
25777
25773
|
adapter = deps.modelAdapter;
|
|
25778
25774
|
}
|
|
@@ -25846,7 +25842,7 @@ function createCreateExpertHandler(deps) {
|
|
|
25846
25842
|
};
|
|
25847
25843
|
}
|
|
25848
25844
|
function registerCreateExpertTool(server, deps) {
|
|
25849
|
-
const
|
|
25845
|
+
const logger53 = deps.logger ?? createLogger({ tool: "create_expert" });
|
|
25850
25846
|
const toolSchema = {
|
|
25851
25847
|
role: z44.enum([
|
|
25852
25848
|
"code_expert",
|
|
@@ -25866,23 +25862,23 @@ function registerCreateExpertTool(server, deps) {
|
|
|
25866
25862
|
const secureHandler = createSecureHandler(createCreateExpertHandler(deps), {
|
|
25867
25863
|
toolName: "create_expert",
|
|
25868
25864
|
rateLimiter: deps.rateLimiter,
|
|
25869
|
-
logger:
|
|
25865
|
+
logger: logger53
|
|
25870
25866
|
});
|
|
25871
25867
|
const timeoutMs = getToolTimeout("create_expert", deps.security);
|
|
25872
|
-
const wrappedHandler = wrapToolWithTimeout("create_expert", secureHandler, { timeoutMs, logger:
|
|
25868
|
+
const wrappedHandler = wrapToolWithTimeout("create_expert", secureHandler, { timeoutMs, logger: logger53 });
|
|
25873
25869
|
server.registerTool(
|
|
25874
25870
|
"create_expert",
|
|
25875
25871
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("create_expert") },
|
|
25876
25872
|
toSdkCallback(wrappedHandler)
|
|
25877
25873
|
);
|
|
25878
|
-
|
|
25874
|
+
logger53.info("Registered create_expert tool with secure handler and timeout protection");
|
|
25879
25875
|
}
|
|
25880
|
-
function createDefaultDeps(rateLimiter,
|
|
25876
|
+
function createDefaultDeps(rateLimiter, logger53) {
|
|
25881
25877
|
return {
|
|
25882
25878
|
expertFactory: ExpertFactory,
|
|
25883
25879
|
expertRegistry: /* @__PURE__ */ new Map(),
|
|
25884
25880
|
rateLimiter,
|
|
25885
|
-
...
|
|
25881
|
+
...logger53 !== void 0 ? { logger: logger53 } : {}
|
|
25886
25882
|
};
|
|
25887
25883
|
}
|
|
25888
25884
|
function getAvailableRoles() {
|
|
@@ -25917,7 +25913,7 @@ function buildExpertsPayload() {
|
|
|
25917
25913
|
experts
|
|
25918
25914
|
};
|
|
25919
25915
|
}
|
|
25920
|
-
function registerExpertsResource(server,
|
|
25916
|
+
function registerExpertsResource(server, logger53) {
|
|
25921
25917
|
server.registerResource(
|
|
25922
25918
|
EXPERTS_RESOURCE_NAME,
|
|
25923
25919
|
EXPERTS_RESOURCE_URI,
|
|
@@ -25926,7 +25922,7 @@ function registerExpertsResource(server, logger52) {
|
|
|
25926
25922
|
mimeType: "application/json"
|
|
25927
25923
|
},
|
|
25928
25924
|
() => {
|
|
25929
|
-
|
|
25925
|
+
logger53.debug("Reading experts resource");
|
|
25930
25926
|
const payload = buildExpertsPayload();
|
|
25931
25927
|
return {
|
|
25932
25928
|
contents: [
|
|
@@ -25939,12 +25935,12 @@ function registerExpertsResource(server, logger52) {
|
|
|
25939
25935
|
};
|
|
25940
25936
|
}
|
|
25941
25937
|
);
|
|
25942
|
-
|
|
25938
|
+
logger53.info("Registered experts resource", { uri: EXPERTS_RESOURCE_URI });
|
|
25943
25939
|
}
|
|
25944
25940
|
|
|
25945
25941
|
// src/mcp/resources/index.ts
|
|
25946
|
-
function registerResources(server,
|
|
25947
|
-
const log =
|
|
25942
|
+
function registerResources(server, logger53) {
|
|
25943
|
+
const log = logger53 ?? createLogger({ component: "mcp-resources" });
|
|
25948
25944
|
log.info("Registering MCP resources");
|
|
25949
25945
|
registerModelsResource(server, log);
|
|
25950
25946
|
registerResearchResource(server, log);
|
|
@@ -26058,11 +26054,11 @@ function validateWorkflowInputs(workflow, inputs) {
|
|
|
26058
26054
|
};
|
|
26059
26055
|
}
|
|
26060
26056
|
async function loadWorkflowFromPath(deps, filePath) {
|
|
26061
|
-
const { workflowEngine, logger:
|
|
26057
|
+
const { workflowEngine, logger: logger53 } = deps;
|
|
26062
26058
|
const allowedDirs = getAllowedWorkflowDirs(deps);
|
|
26063
26059
|
const pathValidation = validateWorkflowPath(filePath, allowedDirs);
|
|
26064
26060
|
if (!pathValidation.ok) {
|
|
26065
|
-
|
|
26061
|
+
logger53?.warn("Workflow path validation failed", {
|
|
26066
26062
|
path: filePath,
|
|
26067
26063
|
error: pathValidation.error.message
|
|
26068
26064
|
});
|
|
@@ -26081,8 +26077,8 @@ async function loadWorkflowFromPath(deps, filePath) {
|
|
|
26081
26077
|
return result;
|
|
26082
26078
|
}
|
|
26083
26079
|
async function loadWorkflowFromName(deps, name) {
|
|
26084
|
-
const { workflowEngine, logger:
|
|
26085
|
-
|
|
26080
|
+
const { workflowEngine, logger: logger53 } = deps;
|
|
26081
|
+
logger53?.debug("Looking up built-in template", { name });
|
|
26086
26082
|
const templates = await workflowEngine.listTemplates();
|
|
26087
26083
|
const found = templates.find((t) => t.name === name);
|
|
26088
26084
|
if (found === void 0) {
|
|
@@ -26106,9 +26102,9 @@ async function loadWorkflowFromName(deps, name) {
|
|
|
26106
26102
|
return { ok: true, value: definition };
|
|
26107
26103
|
}
|
|
26108
26104
|
async function loadWorkflow(deps, template) {
|
|
26109
|
-
const { logger:
|
|
26105
|
+
const { logger: logger53 } = deps;
|
|
26110
26106
|
if (isFilePath(template)) {
|
|
26111
|
-
|
|
26107
|
+
logger53?.debug("Loading workflow from file", { path: template });
|
|
26112
26108
|
return loadWorkflowFromPath(deps, template);
|
|
26113
26109
|
}
|
|
26114
26110
|
return loadWorkflowFromName(deps, template);
|
|
@@ -26158,15 +26154,15 @@ function formatValidationErrors(validation) {
|
|
|
26158
26154
|
|
|
26159
26155
|
// src/mcp/tools/run-workflow.ts
|
|
26160
26156
|
async function executeWorkflow(deps, workflow, inputs) {
|
|
26161
|
-
const { workflowEngine, logger:
|
|
26162
|
-
|
|
26157
|
+
const { workflowEngine, logger: logger53 } = deps;
|
|
26158
|
+
logger53?.info("Executing workflow", {
|
|
26163
26159
|
workflowName: workflow.name,
|
|
26164
26160
|
inputCount: Object.keys(inputs).length
|
|
26165
26161
|
});
|
|
26166
26162
|
const startTime = getTimeProvider().now();
|
|
26167
26163
|
const result = await workflowEngine.execute(workflow, inputs);
|
|
26168
26164
|
if (!result.ok) {
|
|
26169
|
-
|
|
26165
|
+
logger53?.error("Workflow execution failed", result.error, {
|
|
26170
26166
|
workflowName: workflow.name
|
|
26171
26167
|
});
|
|
26172
26168
|
return {
|
|
@@ -26175,7 +26171,7 @@ async function executeWorkflow(deps, workflow, inputs) {
|
|
|
26175
26171
|
};
|
|
26176
26172
|
}
|
|
26177
26173
|
const workflowResult = result.value;
|
|
26178
|
-
|
|
26174
|
+
logger53?.info("Workflow completed", {
|
|
26179
26175
|
workflowName: workflow.name,
|
|
26180
26176
|
durationMs: getTimeProvider().now() - startTime,
|
|
26181
26177
|
stepCount: workflowResult.stepResults.length
|
|
@@ -26288,16 +26284,16 @@ function createRunWorkflowHandler(deps) {
|
|
|
26288
26284
|
};
|
|
26289
26285
|
}
|
|
26290
26286
|
function registerRunWorkflowTool(server, deps) {
|
|
26291
|
-
const
|
|
26287
|
+
const logger53 = deps.logger ?? createLogger({ tool: "run_workflow" });
|
|
26292
26288
|
const notifier = deps.notifier ?? createMcpNotifier(server);
|
|
26293
26289
|
const depsWithNotifier = { ...deps, notifier };
|
|
26294
26290
|
const secureHandler = createSecureHandler(createRunWorkflowHandler(depsWithNotifier), {
|
|
26295
26291
|
toolName: "run_workflow",
|
|
26296
26292
|
rateLimiter: deps.rateLimiter,
|
|
26297
|
-
logger:
|
|
26293
|
+
logger: logger53
|
|
26298
26294
|
});
|
|
26299
26295
|
const timeoutMs = getToolTimeout("run_workflow", deps.security);
|
|
26300
|
-
const wrappedHandler = wrapToolWithTimeout("run_workflow", secureHandler, { timeoutMs, logger:
|
|
26296
|
+
const wrappedHandler = wrapToolWithTimeout("run_workflow", secureHandler, { timeoutMs, logger: logger53 });
|
|
26301
26297
|
server.registerTool(
|
|
26302
26298
|
"run_workflow",
|
|
26303
26299
|
{
|
|
@@ -26305,9 +26301,9 @@ function registerRunWorkflowTool(server, deps) {
|
|
|
26305
26301
|
inputSchema: toolInputSchema,
|
|
26306
26302
|
annotations: getToolAnnotations("run_workflow")
|
|
26307
26303
|
},
|
|
26308
|
-
toSdkCallbackWithBudgetCheck(wrappedHandler, "run_workflow", timeoutMs,
|
|
26304
|
+
toSdkCallbackWithBudgetCheck(wrappedHandler, "run_workflow", timeoutMs, logger53)
|
|
26309
26305
|
);
|
|
26310
|
-
|
|
26306
|
+
logger53.info("Registered run_workflow tool with secure handler and timeout protection");
|
|
26311
26307
|
}
|
|
26312
26308
|
|
|
26313
26309
|
// src/orchestration/graph/graph-types.ts
|
|
@@ -26693,7 +26689,7 @@ async function populateUnifiedContextOnState(state) {
|
|
|
26693
26689
|
try {
|
|
26694
26690
|
const taskCandidate = state["task"];
|
|
26695
26691
|
if (typeof taskCandidate !== "string" || taskCandidate === "") return;
|
|
26696
|
-
const { getContextForTask: getContextForTask2, inferTaskCategory: inferTaskCategory2 } = await import("./context-retriever-
|
|
26692
|
+
const { getContextForTask: getContextForTask2, inferTaskCategory: inferTaskCategory2 } = await import("./context-retriever-QY4FNTDZ.js");
|
|
26697
26693
|
const ctx = await getContextForTask2({
|
|
26698
26694
|
task: taskCandidate,
|
|
26699
26695
|
category: inferTaskCategory2(taskCandidate),
|
|
@@ -28246,11 +28242,11 @@ var trustTierRule = {
|
|
|
28246
28242
|
evaluate(context) {
|
|
28247
28243
|
const tierVal = context.pipelineState.trustTier;
|
|
28248
28244
|
const numericTier = tierVal === void 0 ? Number.NaN : Number(tierVal);
|
|
28249
|
-
const tier = Number.isFinite(numericTier) ? numericTier :
|
|
28250
|
-
if (tier
|
|
28245
|
+
const tier = Number.isFinite(numericTier) ? numericTier : 4;
|
|
28246
|
+
if (tier >= 3 && context.stageType === "execute") {
|
|
28251
28247
|
return {
|
|
28252
28248
|
allow: false,
|
|
28253
|
-
reason: "Untrusted input cannot trigger execute stages",
|
|
28249
|
+
reason: tierVal === void 0 || !Number.isFinite(numericTier) ? `Missing or invalid trustTier on pipeline state; defaulting to untrusted (4). Producer must set TaskContract.metadata.trustTier (#2957).` : "Untrusted input cannot trigger execute stages",
|
|
28254
28250
|
escalateTo: "user"
|
|
28255
28251
|
};
|
|
28256
28252
|
}
|
|
@@ -28407,7 +28403,7 @@ function createDelegatePipeline(task) {
|
|
|
28407
28403
|
const runner = new PipelineRunner();
|
|
28408
28404
|
return runner.compile(plan);
|
|
28409
28405
|
}
|
|
28410
|
-
function delegateInputToTaskContract(input) {
|
|
28406
|
+
function delegateInputToTaskContract(input, opts = {}) {
|
|
28411
28407
|
const metadata = { source: "delegate_to_model" };
|
|
28412
28408
|
if (input.preferred_capability !== void 0) {
|
|
28413
28409
|
metadata["preferredCapability"] = input.preferred_capability;
|
|
@@ -28418,6 +28414,7 @@ function delegateInputToTaskContract(input) {
|
|
|
28418
28414
|
if (input.billing_mode !== void 0) {
|
|
28419
28415
|
metadata["billingMode"] = input.billing_mode;
|
|
28420
28416
|
}
|
|
28417
|
+
if (opts.trustTier !== void 0) metadata["trustTier"] = opts.trustTier;
|
|
28421
28418
|
return buildBaseTaskContract({
|
|
28422
28419
|
idPrefix: "delegate",
|
|
28423
28420
|
task: input.task,
|
|
@@ -28520,10 +28517,11 @@ function buildPlan(task) {
|
|
|
28520
28517
|
}
|
|
28521
28518
|
|
|
28522
28519
|
// src/pipeline/v2-orchestrate.ts
|
|
28523
|
-
function orchestrateInputToTaskContract(input) {
|
|
28520
|
+
function orchestrateInputToTaskContract(input, opts = {}) {
|
|
28524
28521
|
const metadata = { source: "orchestrate" };
|
|
28525
28522
|
if (input.context !== void 0) metadata["context"] = input.context;
|
|
28526
28523
|
if (input.maxIterations !== void 0) metadata["maxIterations"] = input.maxIterations;
|
|
28524
|
+
if (opts.trustTier !== void 0) metadata["trustTier"] = opts.trustTier;
|
|
28527
28525
|
return buildBaseTaskContract({
|
|
28528
28526
|
idPrefix: "orchestrate",
|
|
28529
28527
|
task: input.task,
|
|
@@ -28623,8 +28621,8 @@ var OrchestratorAdapter = class {
|
|
|
28623
28621
|
history = [];
|
|
28624
28622
|
logger;
|
|
28625
28623
|
agent = null;
|
|
28626
|
-
constructor(
|
|
28627
|
-
this.logger =
|
|
28624
|
+
constructor(logger53) {
|
|
28625
|
+
this.logger = logger53 ?? createLogger({ component: "OrchestratorAdapter" });
|
|
28628
28626
|
}
|
|
28629
28627
|
setOrchestrator(agent) {
|
|
28630
28628
|
this.agent = agent;
|
|
@@ -28764,10 +28762,10 @@ var WorkflowOrchestratorAdapter = class {
|
|
|
28764
28762
|
logger;
|
|
28765
28763
|
executions = /* @__PURE__ */ new Map();
|
|
28766
28764
|
history = [];
|
|
28767
|
-
constructor(engine,
|
|
28765
|
+
constructor(engine, logger53) {
|
|
28768
28766
|
this.id = `workflow-${randomUUID9().slice(0, 8)}`;
|
|
28769
28767
|
this.engine = engine;
|
|
28770
|
-
this.logger =
|
|
28768
|
+
this.logger = logger53 ?? createLogger({ component: "WorkflowOrchestratorAdapter" });
|
|
28771
28769
|
}
|
|
28772
28770
|
async execute(definition, inputs, _options) {
|
|
28773
28771
|
if (definition.type !== "workflow") {
|
|
@@ -28959,22 +28957,22 @@ var OrchestratorFactory = class {
|
|
|
28959
28957
|
}
|
|
28960
28958
|
};
|
|
28961
28959
|
async function createOrchestratorFactory(config) {
|
|
28962
|
-
const
|
|
28963
|
-
|
|
28960
|
+
const logger53 = config?.logger ?? createLogger({ component: "OrchestratorFactory" });
|
|
28961
|
+
logger53.info("Initializing OrchestratorFactory");
|
|
28964
28962
|
let workflowEngine;
|
|
28965
28963
|
try {
|
|
28966
28964
|
const workflowConfig = {
|
|
28967
28965
|
...config?.workflowConfig,
|
|
28968
|
-
logger:
|
|
28966
|
+
logger: logger53
|
|
28969
28967
|
};
|
|
28970
28968
|
if (config?.modelAdapter !== void 0) {
|
|
28971
28969
|
workflowConfig.modelAdapter = config.modelAdapter;
|
|
28972
28970
|
}
|
|
28973
28971
|
workflowEngine = await createProductionWorkflowEngine(workflowConfig);
|
|
28974
|
-
|
|
28972
|
+
logger53.info("WorkflowEngine initialized");
|
|
28975
28973
|
} catch (error) {
|
|
28976
28974
|
const message = getErrorMessage(error);
|
|
28977
|
-
|
|
28975
|
+
logger53.warn("WorkflowEngine initialization failed, workflow orchestration unavailable", {
|
|
28978
28976
|
error: message
|
|
28979
28977
|
});
|
|
28980
28978
|
}
|
|
@@ -28985,12 +28983,12 @@ async function createOrchestratorFactory(config) {
|
|
|
28985
28983
|
var MAX_OUTCOMES2 = 200;
|
|
28986
28984
|
var AMBIGUITY_THRESHOLD = 0.7;
|
|
28987
28985
|
function createWorkflowRouter(options) {
|
|
28988
|
-
const
|
|
28989
|
-
const analyzer = options?.analyzer ?? createSharedTaskAnalyzer({ logger:
|
|
28986
|
+
const logger53 = options?.logger ?? createLogger({ component: "WorkflowRouter" });
|
|
28987
|
+
const analyzer = options?.analyzer ?? createSharedTaskAnalyzer({ logger: logger53 });
|
|
28990
28988
|
const outcomes = [];
|
|
28991
28989
|
return {
|
|
28992
28990
|
route(signals, routerOpts) {
|
|
28993
|
-
return routeTask(signals, analyzer,
|
|
28991
|
+
return routeTask(signals, analyzer, logger53, routerOpts);
|
|
28994
28992
|
},
|
|
28995
28993
|
recordOutcome(outcome) {
|
|
28996
28994
|
recordPatternOutcome(outcomes, outcome);
|
|
@@ -29032,7 +29030,7 @@ function buildDecision(input) {
|
|
|
29032
29030
|
}
|
|
29033
29031
|
return base;
|
|
29034
29032
|
}
|
|
29035
|
-
function routeTask(signals, analyzer,
|
|
29033
|
+
function routeTask(signals, analyzer, logger53, _opts) {
|
|
29036
29034
|
const analysis = analyzer.analyze(signals.description);
|
|
29037
29035
|
const enriched = enrichSignals(signals, analysis);
|
|
29038
29036
|
const matchedRules = [];
|
|
@@ -29042,7 +29040,7 @@ function routeTask(signals, analyzer, logger52, _opts) {
|
|
|
29042
29040
|
if (result !== void 0) {
|
|
29043
29041
|
matchedRules.push(rule.name);
|
|
29044
29042
|
collectAlternatives(alternatives, result.pattern);
|
|
29045
|
-
|
|
29043
|
+
logger53.info("Workflow pattern selected", {
|
|
29046
29044
|
pattern: result.pattern,
|
|
29047
29045
|
rule: rule.name,
|
|
29048
29046
|
confidence: result.confidence,
|
|
@@ -29052,7 +29050,7 @@ function routeTask(signals, analyzer, logger52, _opts) {
|
|
|
29052
29050
|
return buildDecision({ result, matchedRules, alternatives, analysis });
|
|
29053
29051
|
}
|
|
29054
29052
|
}
|
|
29055
|
-
|
|
29053
|
+
logger53.info("Using fallback pattern", { pattern: "graph", taskType: analysis.taskType });
|
|
29056
29054
|
const fallback = {
|
|
29057
29055
|
pattern: "graph",
|
|
29058
29056
|
reasoning: "No specific rule matched \u2014 using Graph DAG as the most general pattern",
|
|
@@ -29352,9 +29350,7 @@ function createMockTaskExecutor() {
|
|
|
29352
29350
|
}
|
|
29353
29351
|
function createMockOrchestrator() {
|
|
29354
29352
|
const mockExecutor = createMockTaskExecutor();
|
|
29355
|
-
const factory = new OrchestratorFactory({
|
|
29356
|
-
techLead: mockExecutor
|
|
29357
|
-
});
|
|
29353
|
+
const factory = new OrchestratorFactory({ techLead: mockExecutor });
|
|
29358
29354
|
return factory.create("orchestrator");
|
|
29359
29355
|
}
|
|
29360
29356
|
|
|
@@ -29402,11 +29398,11 @@ function setAnalysis(snapshot, analysis) {
|
|
|
29402
29398
|
var globalSicaConfig;
|
|
29403
29399
|
var sicaEnabled = false;
|
|
29404
29400
|
function initializeSica(options) {
|
|
29405
|
-
const { sicaConfig, logger:
|
|
29401
|
+
const { sicaConfig, logger: logger53 } = options;
|
|
29406
29402
|
if (sicaConfig?.enabled !== true) {
|
|
29407
29403
|
sicaEnabled = false;
|
|
29408
29404
|
globalSicaConfig = void 0;
|
|
29409
|
-
|
|
29405
|
+
logger53.info("SICA self-improvement disabled by configuration");
|
|
29410
29406
|
return {
|
|
29411
29407
|
enabled: false,
|
|
29412
29408
|
reason: sicaConfig?.enabled === false ? "disabled in config" : "not enabled (opt-in feature)"
|
|
@@ -29414,7 +29410,7 @@ function initializeSica(options) {
|
|
|
29414
29410
|
}
|
|
29415
29411
|
sicaEnabled = true;
|
|
29416
29412
|
globalSicaConfig = sicaConfig;
|
|
29417
|
-
|
|
29413
|
+
logger53.info("SICA self-improvement enabled", {
|
|
29418
29414
|
improvementThreshold: sicaConfig.improvementThreshold,
|
|
29419
29415
|
maxActiveVersions: sicaConfig.maxActiveVersions,
|
|
29420
29416
|
cooldownMs: sicaConfig.improvementCooldownMs
|
|
@@ -29432,18 +29428,18 @@ function getSicaConfig() {
|
|
|
29432
29428
|
}
|
|
29433
29429
|
|
|
29434
29430
|
// src/mcp/tools/orchestrate-sica.ts
|
|
29435
|
-
function createOrchestratorWithSica(
|
|
29436
|
-
const orchestrator = new Orchestrator({ logger:
|
|
29431
|
+
function createOrchestratorWithSica(logger53, adapter) {
|
|
29432
|
+
const orchestrator = new Orchestrator({ logger: logger53, ...adapter !== void 0 ? { adapter } : {} });
|
|
29437
29433
|
if (!isSicaEnabled()) {
|
|
29438
|
-
|
|
29434
|
+
logger53.debug("SICA not enabled, using plain orchestrator");
|
|
29439
29435
|
return orchestrator;
|
|
29440
29436
|
}
|
|
29441
29437
|
const sicaConfig = getSicaConfig();
|
|
29442
29438
|
if (sicaConfig === void 0) {
|
|
29443
|
-
|
|
29439
|
+
logger53.debug("SICA config unavailable, using plain orchestrator");
|
|
29444
29440
|
return orchestrator;
|
|
29445
29441
|
}
|
|
29446
|
-
|
|
29442
|
+
logger53.info("Creating SICA-wrapped orchestrator", {
|
|
29447
29443
|
improvementThreshold: sicaConfig.improvementThreshold,
|
|
29448
29444
|
maxActiveVersions: sicaConfig.maxActiveVersions
|
|
29449
29445
|
});
|
|
@@ -29463,9 +29459,9 @@ function createOrchestratorWithSica(logger52, adapter) {
|
|
|
29463
29459
|
improvementCooldownMs: sicaConfig.improvementCooldownMs,
|
|
29464
29460
|
enableObservability: sicaConfig.enableObservability
|
|
29465
29461
|
},
|
|
29466
|
-
logger:
|
|
29462
|
+
logger: logger53
|
|
29467
29463
|
});
|
|
29468
|
-
return createSicaOrchestratorAdapter(sicaAgent,
|
|
29464
|
+
return createSicaOrchestratorAdapter(sicaAgent, logger53);
|
|
29469
29465
|
}
|
|
29470
29466
|
function createSicaOrchestratorAdapter(sicaAgent, _logger) {
|
|
29471
29467
|
return {
|
|
@@ -29519,7 +29515,7 @@ var PersistedCatalogSchema = z51.object({
|
|
|
29519
29515
|
function getCatalogPath() {
|
|
29520
29516
|
return nexusDataPath(CATALOG_SUBDIR, CATALOG_FILE);
|
|
29521
29517
|
}
|
|
29522
|
-
function loadPersistedCatalog(
|
|
29518
|
+
function loadPersistedCatalog(logger53) {
|
|
29523
29519
|
const filePath = getCatalogPath();
|
|
29524
29520
|
try {
|
|
29525
29521
|
if (!fs4.existsSync(filePath)) return [];
|
|
@@ -29527,21 +29523,21 @@ function loadPersistedCatalog(logger52) {
|
|
|
29527
29523
|
const parsed = JSON.parse(content);
|
|
29528
29524
|
const result = PersistedCatalogSchema.safeParse(parsed);
|
|
29529
29525
|
if (!result.success) {
|
|
29530
|
-
|
|
29526
|
+
logger53.warn("Invalid pending catalog file, starting fresh", {
|
|
29531
29527
|
errors: result.error.issues.map((i) => i.message)
|
|
29532
29528
|
});
|
|
29533
29529
|
return [];
|
|
29534
29530
|
}
|
|
29535
29531
|
return result.data.references;
|
|
29536
29532
|
} catch (error) {
|
|
29537
|
-
|
|
29533
|
+
logger53.debug("Could not load pending catalog, starting fresh", {
|
|
29538
29534
|
error: getErrorMessage(error),
|
|
29539
29535
|
filePath
|
|
29540
29536
|
});
|
|
29541
29537
|
return [];
|
|
29542
29538
|
}
|
|
29543
29539
|
}
|
|
29544
|
-
function savePersistedCatalog(references,
|
|
29540
|
+
function savePersistedCatalog(references, logger53) {
|
|
29545
29541
|
const dirPath = nexusDataPath(CATALOG_SUBDIR);
|
|
29546
29542
|
const filePath = getCatalogPath();
|
|
29547
29543
|
const tempPath = `${filePath}.tmp.${String(process.pid)}`;
|
|
@@ -29563,7 +29559,7 @@ function savePersistedCatalog(references, logger52) {
|
|
|
29563
29559
|
} catch {
|
|
29564
29560
|
}
|
|
29565
29561
|
const message = getErrorMessage(error);
|
|
29566
|
-
|
|
29562
|
+
logger53.warn("Failed to persist pending catalog", { error: message });
|
|
29567
29563
|
}
|
|
29568
29564
|
}
|
|
29569
29565
|
var ARXIV_PATTERN = /\b(\d{4}\.\d{4,5})\b/g;
|
|
@@ -29573,8 +29569,8 @@ var ResearchAutoCatalog = class _ResearchAutoCatalog {
|
|
|
29573
29569
|
pendingReferences = [];
|
|
29574
29570
|
/** Maximum pending references to hold in memory. */
|
|
29575
29571
|
static MAX_PENDING = 100;
|
|
29576
|
-
constructor(
|
|
29577
|
-
this.logger =
|
|
29572
|
+
constructor(logger53) {
|
|
29573
|
+
this.logger = logger53 ?? createLogger({ component: "research-auto-catalog" });
|
|
29578
29574
|
const persisted = loadPersistedCatalog(this.logger);
|
|
29579
29575
|
if (persisted.length > 0) {
|
|
29580
29576
|
this.pendingReferences.push(...persisted.slice(0, _ResearchAutoCatalog.MAX_PENDING));
|
|
@@ -29729,8 +29725,8 @@ var ResearchAutoCatalog = class _ResearchAutoCatalog {
|
|
|
29729
29725
|
}
|
|
29730
29726
|
};
|
|
29731
29727
|
var autoCatalogInstance;
|
|
29732
|
-
function getAutoCatalog(
|
|
29733
|
-
autoCatalogInstance ??= new ResearchAutoCatalog(
|
|
29728
|
+
function getAutoCatalog(logger53) {
|
|
29729
|
+
autoCatalogInstance ??= new ResearchAutoCatalog(logger53);
|
|
29734
29730
|
return autoCatalogInstance;
|
|
29735
29731
|
}
|
|
29736
29732
|
|
|
@@ -31516,12 +31512,12 @@ function computeExpertReliability() {
|
|
|
31516
31512
|
}
|
|
31517
31513
|
return reliability;
|
|
31518
31514
|
}
|
|
31519
|
-
function computeAgentPlan(task,
|
|
31515
|
+
function computeAgentPlan(task, logger53) {
|
|
31520
31516
|
try {
|
|
31521
31517
|
const analyzer = new SharedTaskAnalyzer();
|
|
31522
31518
|
const analysis = analyzer.analyze(task);
|
|
31523
31519
|
if (analysis.complexity === "simple") {
|
|
31524
|
-
|
|
31520
|
+
logger53.debug("Skipping AOrchestra planning for simple task", {
|
|
31525
31521
|
taskType: analysis.taskType
|
|
31526
31522
|
});
|
|
31527
31523
|
return void 0;
|
|
@@ -31533,9 +31529,9 @@ function computeAgentPlan(task, logger52) {
|
|
|
31533
31529
|
if (rate < 0.5) excludedExperts.push({ role, rate: Math.round(rate * 100) / 100 });
|
|
31534
31530
|
}
|
|
31535
31531
|
if (excludedExperts.length > 0) {
|
|
31536
|
-
|
|
31532
|
+
logger53.warn("Experts excluded by reliability filter", { excludedExperts });
|
|
31537
31533
|
}
|
|
31538
|
-
|
|
31534
|
+
logger53.info("AOrchestra plan", {
|
|
31539
31535
|
experts: plan.totalExperts,
|
|
31540
31536
|
taskType: plan.taskType,
|
|
31541
31537
|
complexity: plan.complexity,
|
|
@@ -31543,7 +31539,7 @@ function computeAgentPlan(task, logger52) {
|
|
|
31543
31539
|
});
|
|
31544
31540
|
return plan;
|
|
31545
31541
|
} catch (planError) {
|
|
31546
|
-
|
|
31542
|
+
logger53.warn("AOrchestra planning failed", {
|
|
31547
31543
|
error: getErrorMessage(planError)
|
|
31548
31544
|
});
|
|
31549
31545
|
return void 0;
|
|
@@ -31613,7 +31609,7 @@ async function executeOnAdapter(opts) {
|
|
|
31613
31609
|
}
|
|
31614
31610
|
}
|
|
31615
31611
|
function createWorkerExecutor(config) {
|
|
31616
|
-
const { taskDescription, modelAdapter, logger:
|
|
31612
|
+
const { taskDescription, modelAdapter, logger: logger53, learnings, perWorkerRouting } = config;
|
|
31617
31613
|
const effectiveFallbackCli = modelAdapter.providerId;
|
|
31618
31614
|
return async (entry, priorWaveResults) => {
|
|
31619
31615
|
const workerStartMs = getTimeProvider().now();
|
|
@@ -31622,7 +31618,7 @@ function createWorkerExecutor(config) {
|
|
|
31622
31618
|
modelAdapter,
|
|
31623
31619
|
effectiveFallbackCli,
|
|
31624
31620
|
perWorkerRouting === true,
|
|
31625
|
-
|
|
31621
|
+
logger53
|
|
31626
31622
|
);
|
|
31627
31623
|
return executeOnAdapter({
|
|
31628
31624
|
entry,
|
|
@@ -31796,15 +31792,15 @@ function prepareBudgetedEntries(plan, maxCalls, log) {
|
|
|
31796
31792
|
return entries;
|
|
31797
31793
|
}
|
|
31798
31794
|
async function executeWorkerDispatch(options) {
|
|
31799
|
-
const { agentPlan, taskDescription, modelAdapter, logger:
|
|
31795
|
+
const { agentPlan, taskDescription, modelAdapter, logger: logger53, maxConcurrency } = options;
|
|
31800
31796
|
const maxCalls = resolveMaxWorkerCalls(options.maxWorkerCalls);
|
|
31801
31797
|
const startMs = getTimeProvider().now();
|
|
31802
|
-
const entries = prepareBudgetedEntries(agentPlan, maxCalls,
|
|
31798
|
+
const entries = prepareBudgetedEntries(agentPlan, maxCalls, logger53);
|
|
31803
31799
|
const qualityGate = options.qualityGate === false ? void 0 : options.qualityGate;
|
|
31804
31800
|
const executorConfig = {
|
|
31805
31801
|
taskDescription,
|
|
31806
31802
|
modelAdapter,
|
|
31807
|
-
logger:
|
|
31803
|
+
logger: logger53,
|
|
31808
31804
|
...options.learnings !== void 0 ? { learnings: options.learnings } : {},
|
|
31809
31805
|
...options.perWorkerRouting !== void 0 ? { perWorkerRouting: options.perWorkerRouting } : {}
|
|
31810
31806
|
};
|
|
@@ -31825,8 +31821,8 @@ async function executeWorkerDispatch(options) {
|
|
|
31825
31821
|
};
|
|
31826
31822
|
await runSynthesisPhase(state, options, maxCalls);
|
|
31827
31823
|
const refined = await runRefinementPhase(state, entries, options, maxCalls);
|
|
31828
|
-
const base = buildDispatchResult(state.results, startMs,
|
|
31829
|
-
logDispatchInsights(state.results,
|
|
31824
|
+
const base = buildDispatchResult(state.results, startMs, logger53, state.totalModelCalls);
|
|
31825
|
+
logDispatchInsights(state.results, logger53);
|
|
31830
31826
|
return {
|
|
31831
31827
|
...base,
|
|
31832
31828
|
...refined ? { refined: true } : {},
|
|
@@ -31884,18 +31880,18 @@ function recordWorkerOutcomes(results, taskDescription) {
|
|
|
31884
31880
|
});
|
|
31885
31881
|
}
|
|
31886
31882
|
}
|
|
31887
|
-
function buildDispatchResult(results, startMs,
|
|
31883
|
+
function buildDispatchResult(results, startMs, logger53, totalModelCalls) {
|
|
31888
31884
|
const successCount = results.filter((r) => r.status === "success").length;
|
|
31889
31885
|
const errorCount = results.filter((r) => r.status === "error").length;
|
|
31890
31886
|
const conflicts = detectConflicts(results);
|
|
31891
31887
|
if (conflicts.length > 0) {
|
|
31892
|
-
|
|
31888
|
+
logger53.warn("Worker output conflicts detected \u2014 human review recommended", {
|
|
31893
31889
|
conflictCount: conflicts.length,
|
|
31894
31890
|
files: conflicts.map((c) => c.filePath)
|
|
31895
31891
|
});
|
|
31896
31892
|
}
|
|
31897
31893
|
const durationMs = getTimeProvider().now() - startMs;
|
|
31898
|
-
|
|
31894
|
+
logger53.info("Worker dispatch complete", {
|
|
31899
31895
|
totalWorkers: results.length,
|
|
31900
31896
|
successCount,
|
|
31901
31897
|
errorCount,
|
|
@@ -33050,13 +33046,10 @@ function buildOutputFromOrchestratorResult(taskId, orchResult, durationMs, routi
|
|
|
33050
33046
|
}
|
|
33051
33047
|
};
|
|
33052
33048
|
}
|
|
33053
|
-
function createOrchestratorFromDeps(deps,
|
|
33049
|
+
function createOrchestratorFromDeps(deps, logger53, orchestratorType) {
|
|
33054
33050
|
if (deps.orchestrator !== void 0) return deps.orchestrator;
|
|
33055
|
-
const techLead = createOrchestratorWithSica(
|
|
33056
|
-
const factory = new OrchestratorFactory({
|
|
33057
|
-
logger: logger52,
|
|
33058
|
-
techLead
|
|
33059
|
-
});
|
|
33051
|
+
const techLead = createOrchestratorWithSica(logger53, deps.modelAdapter);
|
|
33052
|
+
const factory = new OrchestratorFactory({ logger: logger53, techLead });
|
|
33060
33053
|
return factory.create(orchestratorType ?? "orchestrator");
|
|
33061
33054
|
}
|
|
33062
33055
|
function createErrorOptions(taskId, cause) {
|
|
@@ -33168,16 +33161,16 @@ function recordOrchestrationError(errorMessage, taskDescription, durationMs) {
|
|
|
33168
33161
|
}
|
|
33169
33162
|
}
|
|
33170
33163
|
function routeAndPrepare(input, deps, router) {
|
|
33171
|
-
const
|
|
33172
|
-
const workflowRouter = router ?? createWorkflowRouter({ logger:
|
|
33164
|
+
const logger53 = deps.logger ?? createLogger({ tool: "orchestrate" });
|
|
33165
|
+
const workflowRouter = router ?? createWorkflowRouter({ logger: logger53 });
|
|
33173
33166
|
const decision = workflowRouter.route({ description: input.task });
|
|
33174
33167
|
const orchType = mapPatternToOrchestratorType(decision.pattern);
|
|
33175
|
-
|
|
33168
|
+
logger53.info("Workflow pattern selected", {
|
|
33176
33169
|
pattern: decision.pattern,
|
|
33177
33170
|
orchestratorType: orchType
|
|
33178
33171
|
});
|
|
33179
|
-
const orchestrator = createOrchestratorFromDeps(deps,
|
|
33180
|
-
return { workflowRouter, decision, orchestrator, logger:
|
|
33172
|
+
const orchestrator = createOrchestratorFromDeps(deps, logger53, orchType);
|
|
33173
|
+
return { workflowRouter, decision, orchestrator, logger: logger53 };
|
|
33181
33174
|
}
|
|
33182
33175
|
function buildRoutingInfo(decision) {
|
|
33183
33176
|
return {
|
|
@@ -33196,10 +33189,10 @@ function recordRouterOutcome(workflowRouter, decision, success, durationMs) {
|
|
|
33196
33189
|
timestamp: getTimeProvider().now()
|
|
33197
33190
|
});
|
|
33198
33191
|
}
|
|
33199
|
-
function handleOrchestrationException(error, taskId, task,
|
|
33192
|
+
function handleOrchestrationException(error, taskId, task, logger53) {
|
|
33200
33193
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
33201
33194
|
const cause = error instanceof Error ? error : void 0;
|
|
33202
|
-
|
|
33195
|
+
logger53.error("Orchestration exception", cause, { taskId });
|
|
33203
33196
|
recordOrchestrationError(message, task);
|
|
33204
33197
|
return err(
|
|
33205
33198
|
new OrchestrationError(
|
|
@@ -33208,13 +33201,13 @@ function handleOrchestrationException(error, taskId, task, logger52) {
|
|
|
33208
33201
|
)
|
|
33209
33202
|
);
|
|
33210
33203
|
}
|
|
33211
|
-
function startHeartbeatTracking(label,
|
|
33204
|
+
function startHeartbeatTracking(label, logger53) {
|
|
33212
33205
|
const monitor = getHeartbeatMonitor();
|
|
33213
33206
|
const sessionId = monitor.startSession(label);
|
|
33214
33207
|
const timer = setInterval(() => {
|
|
33215
33208
|
monitor.heartbeat(sessionId);
|
|
33216
33209
|
if (monitor.isStalled(sessionId)) {
|
|
33217
|
-
|
|
33210
|
+
logger53.warn("Orchestration session stalled", { label, sessionId });
|
|
33218
33211
|
}
|
|
33219
33212
|
}, HEARTBEAT_TIMEOUTS.heartbeatIntervalMs);
|
|
33220
33213
|
return {
|
|
@@ -33285,8 +33278,8 @@ function handleOrchestratorSuccess(ctx) {
|
|
|
33285
33278
|
});
|
|
33286
33279
|
return ok(output2);
|
|
33287
33280
|
}
|
|
33288
|
-
async function executeOrchestration(input, deps, router, snapshot) {
|
|
33289
|
-
const { workflowRouter, decision, orchestrator, logger:
|
|
33281
|
+
async function executeOrchestration(input, deps, router, snapshot, trustTier) {
|
|
33282
|
+
const { workflowRouter, decision, orchestrator, logger: logger53 } = routeAndPrepare(input, deps, router);
|
|
33290
33283
|
const taskId = generateTaskId();
|
|
33291
33284
|
const startTime = getTimeProvider().now();
|
|
33292
33285
|
if (snapshot !== void 0) setRouting(snapshot, buildRoutingInfo(decision));
|
|
@@ -33296,18 +33289,18 @@ async function executeOrchestration(input, deps, router, snapshot) {
|
|
|
33296
33289
|
decision,
|
|
33297
33290
|
workflowRouter,
|
|
33298
33291
|
startTime,
|
|
33299
|
-
logger:
|
|
33292
|
+
logger: logger53
|
|
33300
33293
|
});
|
|
33301
33294
|
if (fastResult !== void 0) {
|
|
33302
33295
|
if (snapshot !== void 0 && fastResult.ok) setAnalysis(snapshot, fastResult.value.analysis);
|
|
33303
33296
|
return fastResult;
|
|
33304
33297
|
}
|
|
33305
|
-
|
|
33306
|
-
recordTaskStateInit(taskId, input.task,
|
|
33298
|
+
logger53.info("Starting orchestration", { taskId, taskLength: input.task.length });
|
|
33299
|
+
recordTaskStateInit(taskId, input.task, logger53);
|
|
33307
33300
|
const task = await createTaskFromInput(input, taskId);
|
|
33308
33301
|
const definition = { type: "task", task };
|
|
33309
|
-
const hb = startHeartbeatTracking(`orchestrate-${taskId}`,
|
|
33310
|
-
const policy = await deriveOrchestratePolicy(input.task, deps,
|
|
33302
|
+
const hb = startHeartbeatTracking(`orchestrate-${taskId}`, logger53);
|
|
33303
|
+
const policy = await deriveOrchestratePolicy(input.task, deps, logger53, trustTier);
|
|
33311
33304
|
try {
|
|
33312
33305
|
return await runOrchestratorWithStateTracking({
|
|
33313
33306
|
taskId,
|
|
@@ -33318,23 +33311,23 @@ async function executeOrchestration(input, deps, router, snapshot) {
|
|
|
33318
33311
|
decision,
|
|
33319
33312
|
workflowRouter,
|
|
33320
33313
|
startTime,
|
|
33321
|
-
logger:
|
|
33314
|
+
logger: logger53
|
|
33322
33315
|
});
|
|
33323
33316
|
} catch (error) {
|
|
33324
|
-
recordTaskStateBlocker(taskId, error instanceof Error ? error.message : String(error),
|
|
33325
|
-
recordTaskStateStage(taskId, "blocked",
|
|
33326
|
-
return handleOrchestrationException(error, taskId, input.task,
|
|
33317
|
+
recordTaskStateBlocker(taskId, error instanceof Error ? error.message : String(error), logger53);
|
|
33318
|
+
recordTaskStateStage(taskId, "blocked", logger53);
|
|
33319
|
+
return handleOrchestrationException(error, taskId, input.task, logger53);
|
|
33327
33320
|
} finally {
|
|
33328
33321
|
hb.cleanup();
|
|
33329
33322
|
}
|
|
33330
33323
|
}
|
|
33331
33324
|
async function runOrchestratorWithStateTracking(params) {
|
|
33332
|
-
const { taskId, taskInput, definition, orchestrator, policy, logger:
|
|
33333
|
-
recordTaskStateStage(taskId, "executing",
|
|
33325
|
+
const { taskId, taskInput, definition, orchestrator, policy, logger: logger53 } = params;
|
|
33326
|
+
recordTaskStateStage(taskId, "executing", logger53);
|
|
33334
33327
|
const result = await withAccessPolicy(policy, () => orchestrator.execute(definition, {}));
|
|
33335
33328
|
if (!result.ok) {
|
|
33336
|
-
recordTaskStateBlocker(taskId, result.error.message,
|
|
33337
|
-
recordTaskStateStage(taskId, "blocked",
|
|
33329
|
+
recordTaskStateBlocker(taskId, result.error.message, logger53);
|
|
33330
|
+
recordTaskStateStage(taskId, "blocked", logger53);
|
|
33338
33331
|
return handleOrchestratorFailure({
|
|
33339
33332
|
error: result.error,
|
|
33340
33333
|
taskId,
|
|
@@ -33342,10 +33335,10 @@ async function runOrchestratorWithStateTracking(params) {
|
|
|
33342
33335
|
decision: params.decision,
|
|
33343
33336
|
workflowRouter: params.workflowRouter,
|
|
33344
33337
|
startTime: params.startTime,
|
|
33345
|
-
logger:
|
|
33338
|
+
logger: logger53
|
|
33346
33339
|
});
|
|
33347
33340
|
}
|
|
33348
|
-
recordTaskStateStage(taskId, "complete",
|
|
33341
|
+
recordTaskStateStage(taskId, "complete", logger53);
|
|
33349
33342
|
return handleOrchestratorSuccess({
|
|
33350
33343
|
orchResult: result.value,
|
|
33351
33344
|
taskId,
|
|
@@ -33353,7 +33346,7 @@ async function runOrchestratorWithStateTracking(params) {
|
|
|
33353
33346
|
decision: params.decision,
|
|
33354
33347
|
workflowRouter: params.workflowRouter,
|
|
33355
33348
|
startTime: params.startTime,
|
|
33356
|
-
logger:
|
|
33349
|
+
logger: logger53
|
|
33357
33350
|
});
|
|
33358
33351
|
}
|
|
33359
33352
|
function isTaskStateEnabled() {
|
|
@@ -33362,7 +33355,7 @@ function isTaskStateEnabled() {
|
|
|
33362
33355
|
const normalized = raw.toLowerCase();
|
|
33363
33356
|
return normalized !== "0" && normalized !== "false";
|
|
33364
33357
|
}
|
|
33365
|
-
function recordTaskStateInit(taskId, taskText,
|
|
33358
|
+
function recordTaskStateInit(taskId, taskText, logger53) {
|
|
33366
33359
|
if (!isTaskStateEnabled()) return;
|
|
33367
33360
|
const now = getTimeProvider().nowIso();
|
|
33368
33361
|
const initial = {
|
|
@@ -33375,46 +33368,46 @@ function recordTaskStateInit(taskId, taskText, logger52) {
|
|
|
33375
33368
|
};
|
|
33376
33369
|
const result = initTaskState(initial);
|
|
33377
33370
|
if (!result.ok) {
|
|
33378
|
-
|
|
33371
|
+
logger53.warn("task-state: init failed, continuing", {
|
|
33379
33372
|
taskId,
|
|
33380
33373
|
error: result.error.message,
|
|
33381
33374
|
taskLength: taskText.length
|
|
33382
33375
|
});
|
|
33383
33376
|
}
|
|
33384
33377
|
}
|
|
33385
|
-
function recordTaskStateStage(taskId, stage,
|
|
33378
|
+
function recordTaskStateStage(taskId, stage, logger53) {
|
|
33386
33379
|
if (!isTaskStateEnabled()) return;
|
|
33387
33380
|
const result = updateStage(taskId, stage, getTimeProvider().nowIso());
|
|
33388
33381
|
if (!result.ok) {
|
|
33389
|
-
|
|
33382
|
+
logger53.warn("task-state: stage update failed", {
|
|
33390
33383
|
taskId,
|
|
33391
33384
|
stage,
|
|
33392
33385
|
error: result.error.message
|
|
33393
33386
|
});
|
|
33394
33387
|
}
|
|
33395
33388
|
}
|
|
33396
|
-
function recordTaskStateBlocker(taskId, blocker,
|
|
33389
|
+
function recordTaskStateBlocker(taskId, blocker, logger53) {
|
|
33397
33390
|
if (!isTaskStateEnabled()) return;
|
|
33398
33391
|
const ts = getTimeProvider().nowIso();
|
|
33399
33392
|
const result = appendBlocker(taskId, { ts, blocker });
|
|
33400
33393
|
if (!result.ok) {
|
|
33401
|
-
|
|
33394
|
+
logger53.warn("task-state: blocker record failed", {
|
|
33402
33395
|
taskId,
|
|
33403
33396
|
error: result.error.message
|
|
33404
33397
|
});
|
|
33405
33398
|
}
|
|
33406
33399
|
}
|
|
33407
|
-
async function deriveOrchestratePolicy(taskText, deps,
|
|
33400
|
+
async function deriveOrchestratePolicy(taskText, deps, logger53, trustTier) {
|
|
33408
33401
|
const mode = resolveAccessPolicyMode();
|
|
33409
33402
|
try {
|
|
33410
33403
|
const opts = {
|
|
33411
33404
|
mode,
|
|
33412
|
-
trustTier: "
|
|
33405
|
+
trustTier: trustTier ?? "4",
|
|
33413
33406
|
...deps.modelAdapter !== void 0 ? { adapter: deps.modelAdapter } : {}
|
|
33414
33407
|
};
|
|
33415
33408
|
const policy = await deriveAccessPolicy(taskText, opts);
|
|
33416
33409
|
if (mode !== "off") {
|
|
33417
|
-
|
|
33410
|
+
logger53.info("access-policy: derived", {
|
|
33418
33411
|
mode,
|
|
33419
33412
|
source: policy.source,
|
|
33420
33413
|
allowedToolsWildcard: policy.allowedTools === "*"
|
|
@@ -33422,7 +33415,7 @@ async function deriveOrchestratePolicy(taskText, deps, logger52) {
|
|
|
33422
33415
|
}
|
|
33423
33416
|
return policy;
|
|
33424
33417
|
} catch (error) {
|
|
33425
|
-
|
|
33418
|
+
logger53.warn("access-policy: derivation failed", {
|
|
33426
33419
|
mode,
|
|
33427
33420
|
error: getErrorMessage(error),
|
|
33428
33421
|
failClosed: mode === "enforce" || mode === "confirm_risky"
|
|
@@ -33449,22 +33442,22 @@ async function deriveOrchestratePolicy(taskText, deps, logger52) {
|
|
|
33449
33442
|
};
|
|
33450
33443
|
}
|
|
33451
33444
|
}
|
|
33452
|
-
function instrumentV2Orchestrate(input,
|
|
33453
|
-
const tc = orchestrateInputToTaskContract(input);
|
|
33445
|
+
function instrumentV2Orchestrate(input, logger53, trustTier) {
|
|
33446
|
+
const tc = orchestrateInputToTaskContract(input, trustTier !== void 0 ? { trustTier } : {});
|
|
33454
33447
|
void executeOrchestratePipeline(tc).then((m) => {
|
|
33455
|
-
|
|
33448
|
+
logger53.info("V2 orchestrate pipeline", { ...m });
|
|
33456
33449
|
}).catch((error) => {
|
|
33457
|
-
|
|
33450
|
+
logger53.debug("V2 orchestrate pipeline failed", { error: getErrorMessage(error) });
|
|
33458
33451
|
});
|
|
33459
33452
|
}
|
|
33460
|
-
async function tryWorkerDispatch(agentPlan, task, deps,
|
|
33453
|
+
async function tryWorkerDispatch(agentPlan, task, deps, logger53, notifier) {
|
|
33461
33454
|
const adapter = deps.modelAdapter;
|
|
33462
33455
|
if (agentPlan === void 0 || !isWorkerDispatchEnabled() || adapter === void 0) {
|
|
33463
33456
|
return void 0;
|
|
33464
33457
|
}
|
|
33465
33458
|
const abortSignal = abortSignalStorage.getStore();
|
|
33466
33459
|
if (abortSignal?.aborted === true) {
|
|
33467
|
-
|
|
33460
|
+
logger53.info("Worker dispatch aborted before start (client cancelled)");
|
|
33468
33461
|
return void 0;
|
|
33469
33462
|
}
|
|
33470
33463
|
try {
|
|
@@ -33475,14 +33468,14 @@ async function tryWorkerDispatch(agentPlan, task, deps, logger52, notifier) {
|
|
|
33475
33468
|
agentPlan,
|
|
33476
33469
|
taskDescription: task,
|
|
33477
33470
|
modelAdapter: adapter,
|
|
33478
|
-
logger:
|
|
33471
|
+
logger: logger53,
|
|
33479
33472
|
synthesize: true,
|
|
33480
33473
|
refine: true,
|
|
33481
33474
|
perWorkerRouting: true
|
|
33482
33475
|
})
|
|
33483
33476
|
);
|
|
33484
33477
|
} catch (dispatchError) {
|
|
33485
|
-
|
|
33478
|
+
logger53.warn("Worker dispatch failed, continuing with standard orchestration", {
|
|
33486
33479
|
error: dispatchError instanceof Error ? dispatchError.message : String(dispatchError)
|
|
33487
33480
|
});
|
|
33488
33481
|
return void 0;
|
|
@@ -33543,7 +33536,7 @@ function buildTimeoutOrchestrationResult(taskId, elapsedMs, reason, snapshot) {
|
|
|
33543
33536
|
return ok(output2);
|
|
33544
33537
|
}
|
|
33545
33538
|
async function executeOrchestrationWithDeadline(params) {
|
|
33546
|
-
const { input, deps, notifier, logger:
|
|
33539
|
+
const { input, deps, notifier, logger: logger53, trustTier } = params;
|
|
33547
33540
|
const overallDeadlineMs = getMcpSafeDeadlineMs(
|
|
33548
33541
|
MCP_TIMEOUTS.perTool["orchestrate"] ?? MCP_TIMEOUTS.defaultMs,
|
|
33549
33542
|
"orchestrate"
|
|
@@ -33554,11 +33547,11 @@ async function executeOrchestrationWithDeadline(params) {
|
|
|
33554
33547
|
withProgressHeartbeat(
|
|
33555
33548
|
"orchestrate",
|
|
33556
33549
|
notifier,
|
|
33557
|
-
() => executeOrchestration(input, deps, void 0, snapshot)
|
|
33550
|
+
() => executeOrchestration(input, deps, void 0, snapshot, trustTier)
|
|
33558
33551
|
),
|
|
33559
33552
|
overallDeadlineMs,
|
|
33560
33553
|
(elapsedMs) => {
|
|
33561
|
-
|
|
33554
|
+
logger53.warn("Orchestration overall deadline reached; returning partial result", {
|
|
33562
33555
|
overallDeadlineMs,
|
|
33563
33556
|
elapsedMs,
|
|
33564
33557
|
stage: snapshot.stage
|
|
@@ -33573,23 +33566,29 @@ async function executeOrchestrationWithDeadline(params) {
|
|
|
33573
33566
|
);
|
|
33574
33567
|
}
|
|
33575
33568
|
async function runOrchestratePipeline(params) {
|
|
33576
|
-
const { input, deps, notifier, logger:
|
|
33577
|
-
|
|
33569
|
+
const { input, deps, notifier, logger: logger53, trustTier } = params;
|
|
33570
|
+
logger53.debug("Starting orchestration", { taskLength: input.task.length });
|
|
33578
33571
|
notifier.info("orchestrate", { event: "orchestrate_start", taskLength: input.task.length });
|
|
33579
33572
|
const startMs = getTimeProvider().now();
|
|
33580
33573
|
const v2Config = resolveV2Config();
|
|
33581
|
-
if (v2Config.orchestrateEnabled) instrumentV2Orchestrate(input,
|
|
33582
|
-
await injectMemoryContextForOrchestrate(input,
|
|
33583
|
-
const agentPlan = v2Config.aorchestraEnabled ? computeAgentPlan(input.task,
|
|
33574
|
+
if (v2Config.orchestrateEnabled) instrumentV2Orchestrate(input, logger53, trustTier);
|
|
33575
|
+
await injectMemoryContextForOrchestrate(input, logger53);
|
|
33576
|
+
const agentPlan = v2Config.aorchestraEnabled ? computeAgentPlan(input.task, logger53) : void 0;
|
|
33584
33577
|
const workerDispatchResult = await tryWorkerDispatch(
|
|
33585
33578
|
agentPlan,
|
|
33586
33579
|
input.task,
|
|
33587
33580
|
deps,
|
|
33588
|
-
|
|
33581
|
+
logger53,
|
|
33589
33582
|
notifier
|
|
33590
33583
|
);
|
|
33591
33584
|
recordAndReflect(workerDispatchResult, input.task, deps);
|
|
33592
|
-
const result = await executeOrchestrationWithDeadline({
|
|
33585
|
+
const result = await executeOrchestrationWithDeadline({
|
|
33586
|
+
input,
|
|
33587
|
+
deps,
|
|
33588
|
+
notifier,
|
|
33589
|
+
logger: logger53,
|
|
33590
|
+
...trustTier !== void 0 ? { trustTier } : {}
|
|
33591
|
+
});
|
|
33593
33592
|
if (!result.ok) {
|
|
33594
33593
|
return toolStructuredError({
|
|
33595
33594
|
errorCategory: "internal",
|
|
@@ -33603,15 +33602,15 @@ async function runOrchestratePipeline(params) {
|
|
|
33603
33602
|
});
|
|
33604
33603
|
return assembleOrchestrateOutput(result.value, agentPlan, workerDispatchResult);
|
|
33605
33604
|
}
|
|
33606
|
-
async function injectMemoryContextForOrchestrate(input,
|
|
33605
|
+
async function injectMemoryContextForOrchestrate(input, logger53) {
|
|
33607
33606
|
try {
|
|
33608
33607
|
const ctx = await getContextForTask({
|
|
33609
33608
|
task: input.task,
|
|
33610
33609
|
category: inferTaskCategory(input.task),
|
|
33611
|
-
logger:
|
|
33610
|
+
logger: logger53
|
|
33612
33611
|
});
|
|
33613
33612
|
const summary = summarizeContextForPrompt(ctx);
|
|
33614
|
-
|
|
33613
|
+
logger53.debug("orchestrate: unified memory context", {
|
|
33615
33614
|
beliefs: ctx.beliefs.length,
|
|
33616
33615
|
similarMemories: ctx.similarMemories.length,
|
|
33617
33616
|
recentLearnings: ctx.recentLearnings.length,
|
|
@@ -33624,7 +33623,7 @@ async function injectMemoryContextForOrchestrate(input, logger52) {
|
|
|
33624
33623
|
mutable.context = { ...mutable.context ?? {}, priorMemorySummary: summary };
|
|
33625
33624
|
}
|
|
33626
33625
|
} catch (error) {
|
|
33627
|
-
|
|
33626
|
+
logger53.debug("orchestrate: context retrieval failed", { error: getErrorMessage(error) });
|
|
33628
33627
|
}
|
|
33629
33628
|
}
|
|
33630
33629
|
function createOrchestrateHandler(deps) {
|
|
@@ -33645,7 +33644,9 @@ function createOrchestrateHandler(deps) {
|
|
|
33645
33644
|
input: validated.data,
|
|
33646
33645
|
deps,
|
|
33647
33646
|
notifier,
|
|
33648
|
-
logger: ctx.logger
|
|
33647
|
+
logger: ctx.logger,
|
|
33648
|
+
// Threaded from the secure-handler RequestContext (#2957).
|
|
33649
|
+
trustTier: ctx.requestContext.trustTier
|
|
33649
33650
|
})
|
|
33650
33651
|
);
|
|
33651
33652
|
} catch (depthError) {
|
|
@@ -33656,7 +33657,7 @@ function createOrchestrateHandler(deps) {
|
|
|
33656
33657
|
};
|
|
33657
33658
|
}
|
|
33658
33659
|
function registerOrchestrateTool(server, deps) {
|
|
33659
|
-
const
|
|
33660
|
+
const logger53 = deps.logger ?? createLogger({ tool: "orchestrate" });
|
|
33660
33661
|
const notifier = deps.notifier ?? createMcpNotifier(server);
|
|
33661
33662
|
const depsWithNotifier = { ...deps, notifier };
|
|
33662
33663
|
const description2 = "Orchestrate a task by analyzing it, breaking it into subtasks if needed, and coordinating expert agents";
|
|
@@ -33664,12 +33665,12 @@ function registerOrchestrateTool(server, deps) {
|
|
|
33664
33665
|
toolName: "orchestrate",
|
|
33665
33666
|
securityTier: "user-facing",
|
|
33666
33667
|
rateLimiter: deps.rateLimiter,
|
|
33667
|
-
logger:
|
|
33668
|
+
logger: logger53
|
|
33668
33669
|
});
|
|
33669
33670
|
const configuredTimeoutMs = MCP_TIMEOUTS.perTool["orchestrate"] ?? MCP_TIMEOUTS.defaultMs;
|
|
33670
33671
|
const wrappedHandler = wrapToolWithTimeout("orchestrate", secureHandler, {
|
|
33671
33672
|
timeoutMs: configuredTimeoutMs,
|
|
33672
|
-
logger:
|
|
33673
|
+
logger: logger53
|
|
33673
33674
|
});
|
|
33674
33675
|
server.registerTool(
|
|
33675
33676
|
"orchestrate",
|
|
@@ -33678,9 +33679,9 @@ function registerOrchestrateTool(server, deps) {
|
|
|
33678
33679
|
inputSchema: ORCHESTRATE_TOOL_SCHEMA,
|
|
33679
33680
|
annotations: getToolAnnotations("orchestrate")
|
|
33680
33681
|
},
|
|
33681
|
-
toSdkCallbackWithBudgetCheck(wrappedHandler, "orchestrate", configuredTimeoutMs,
|
|
33682
|
+
toSdkCallbackWithBudgetCheck(wrappedHandler, "orchestrate", configuredTimeoutMs, logger53)
|
|
33682
33683
|
);
|
|
33683
|
-
|
|
33684
|
+
logger53.info("Registered orchestrate tool with secure handler and timeout protection");
|
|
33684
33685
|
}
|
|
33685
33686
|
|
|
33686
33687
|
// src/mcp/tools/delegate-to-model-types.ts
|
|
@@ -34043,21 +34044,21 @@ function mapCompositeDecisionToOutput(decision, estimatedTokens) {
|
|
|
34043
34044
|
}))
|
|
34044
34045
|
};
|
|
34045
34046
|
}
|
|
34046
|
-
async function routeViaCompositeRouter(task, router, feedbackIntegration,
|
|
34047
|
+
async function routeViaCompositeRouter(task, router, feedbackIntegration, logger53) {
|
|
34047
34048
|
const result = await router.route({ content: task });
|
|
34048
34049
|
if (!result.ok) {
|
|
34049
|
-
|
|
34050
|
+
logger53.warn("CompositeRouter routing failed", { error: result.error.message });
|
|
34050
34051
|
return null;
|
|
34051
34052
|
}
|
|
34052
34053
|
const decision = result.value;
|
|
34053
34054
|
let routingId;
|
|
34054
34055
|
if (feedbackIntegration) {
|
|
34055
34056
|
routingId = feedbackIntegration.recordRoutingDecision(decision);
|
|
34056
|
-
|
|
34057
|
+
logger53.debug("Recorded routing decision", { routingId, cliName: decision.cliName });
|
|
34057
34058
|
}
|
|
34058
34059
|
return { decision, routingId, feedbackIntegration };
|
|
34059
34060
|
}
|
|
34060
|
-
function recordRoutingOutcome(result, durationMs,
|
|
34061
|
+
function recordRoutingOutcome(result, durationMs, logger53) {
|
|
34061
34062
|
if (result.routingId === void 0 || result.feedbackIntegration === void 0) return;
|
|
34062
34063
|
try {
|
|
34063
34064
|
const topsisScore = result.decision.topsisScore ?? 0;
|
|
@@ -34070,13 +34071,13 @@ function recordRoutingOutcome(result, durationMs, logger52) {
|
|
|
34070
34071
|
tokenUsage: 0
|
|
34071
34072
|
// delegate-to-model is a recommendation, not execution
|
|
34072
34073
|
});
|
|
34073
|
-
|
|
34074
|
+
logger53.debug("Recorded routing outcome", {
|
|
34074
34075
|
routingId: result.routingId,
|
|
34075
34076
|
topsisScore,
|
|
34076
34077
|
success: topsisScore >= TOPSIS_CONFIDENCE_THRESHOLD
|
|
34077
34078
|
});
|
|
34078
34079
|
} catch (error) {
|
|
34079
|
-
|
|
34080
|
+
logger53.warn("Failed to record routing outcome", { error: getErrorMessage(error) });
|
|
34080
34081
|
}
|
|
34081
34082
|
}
|
|
34082
34083
|
|
|
@@ -34097,9 +34098,9 @@ function classifyWithGovernance(toolName, params, overrides) {
|
|
|
34097
34098
|
const promotionReason = promoted ? buildPromotionReason(domain, params) : null;
|
|
34098
34099
|
return { tier, promoted, domain, votingThreshold, promotionReason };
|
|
34099
34100
|
}
|
|
34100
|
-
function auditGovernancePromotion(classification, toolName,
|
|
34101
|
+
function auditGovernancePromotion(classification, toolName, logger53) {
|
|
34101
34102
|
if (!classification.promoted) return;
|
|
34102
|
-
const log =
|
|
34103
|
+
const log = logger53 ?? createLogger({ component: "governance" });
|
|
34103
34104
|
log.warn("Governance promotion", {
|
|
34104
34105
|
tool: toolName,
|
|
34105
34106
|
domain: classification.domain,
|
|
@@ -34170,9 +34171,9 @@ function recordToMemory(task, model, usedRouter) {
|
|
|
34170
34171
|
});
|
|
34171
34172
|
}
|
|
34172
34173
|
}
|
|
34173
|
-
function classifyDelegateGovernance(input,
|
|
34174
|
+
function classifyDelegateGovernance(input, logger53) {
|
|
34174
34175
|
const classification = classifyWithGovernance("delegate_to_model", { task: input.task });
|
|
34175
|
-
auditGovernancePromotion(classification, "delegate_to_model",
|
|
34176
|
+
auditGovernancePromotion(classification, "delegate_to_model", logger53);
|
|
34176
34177
|
return classification;
|
|
34177
34178
|
}
|
|
34178
34179
|
function enrichWithGovernance(output2, governance) {
|
|
@@ -34186,12 +34187,12 @@ function enrichWithGovernance(output2, governance) {
|
|
|
34186
34187
|
}
|
|
34187
34188
|
};
|
|
34188
34189
|
}
|
|
34189
|
-
function instrumentV2Pipeline(input,
|
|
34190
|
-
const tc = delegateInputToTaskContract(input);
|
|
34190
|
+
function instrumentV2Pipeline(input, logger53, trustTier) {
|
|
34191
|
+
const tc = delegateInputToTaskContract(input, trustTier !== void 0 ? { trustTier } : {});
|
|
34191
34192
|
void executeDelegatePipeline(tc).then((m) => {
|
|
34192
|
-
|
|
34193
|
+
logger53.info("V2 delegate pipeline", { ...m });
|
|
34193
34194
|
}).catch((error) => {
|
|
34194
|
-
|
|
34195
|
+
logger53.warn("V2 delegate instrumentation failed", { error: getErrorMessage(error) });
|
|
34195
34196
|
});
|
|
34196
34197
|
}
|
|
34197
34198
|
function notifyAndRecord(opts) {
|
|
@@ -34241,7 +34242,9 @@ function createDelegateHandler(deps) {
|
|
|
34241
34242
|
notifier.info("delegate", { event: "routing_start", taskLength: input.task.length });
|
|
34242
34243
|
ctx.logger.info("Analyzing task for model routing", { taskLength: input.task.length });
|
|
34243
34244
|
const governance = classifyDelegateGovernance(input, ctx.logger);
|
|
34244
|
-
if (resolveV2Config().delegateEnabled)
|
|
34245
|
+
if (resolveV2Config().delegateEnabled) {
|
|
34246
|
+
instrumentV2Pipeline(input, ctx.logger, ctx.requestContext.trustTier);
|
|
34247
|
+
}
|
|
34245
34248
|
const baseOpts = {
|
|
34246
34249
|
notifier,
|
|
34247
34250
|
task: input.task,
|
|
@@ -34265,18 +34268,18 @@ function createDelegateHandler(deps) {
|
|
|
34265
34268
|
};
|
|
34266
34269
|
}
|
|
34267
34270
|
function registerDelegateToModelTool(server, deps) {
|
|
34268
|
-
const
|
|
34271
|
+
const logger53 = deps.logger ?? createLogger({ tool: "delegate_to_model" });
|
|
34269
34272
|
const notifier = deps.notifier ?? createMcpNotifier(server);
|
|
34270
34273
|
const depsWithNotifier = { ...deps, notifier };
|
|
34271
34274
|
const secureHandler = createSecureHandler(createDelegateHandler(depsWithNotifier), {
|
|
34272
34275
|
toolName: "delegate_to_model",
|
|
34273
34276
|
rateLimiter: deps.rateLimiter,
|
|
34274
|
-
logger:
|
|
34277
|
+
logger: logger53
|
|
34275
34278
|
});
|
|
34276
34279
|
const timeoutMs = getToolTimeout("delegate_to_model", deps.security);
|
|
34277
34280
|
const wrappedHandler = wrapToolWithTimeout("delegate_to_model", secureHandler, {
|
|
34278
34281
|
timeoutMs,
|
|
34279
|
-
logger:
|
|
34282
|
+
logger: logger53
|
|
34280
34283
|
});
|
|
34281
34284
|
server.registerTool(
|
|
34282
34285
|
"delegate_to_model",
|
|
@@ -34288,7 +34291,7 @@ function registerDelegateToModelTool(server, deps) {
|
|
|
34288
34291
|
},
|
|
34289
34292
|
toSdkCallback(wrappedHandler)
|
|
34290
34293
|
);
|
|
34291
|
-
|
|
34294
|
+
logger53.info("Registered delegate_to_model tool with secure handler and timeout protection");
|
|
34292
34295
|
}
|
|
34293
34296
|
|
|
34294
34297
|
// src/mcp/tools/run-graph-workflow-multicli-templates.ts
|
|
@@ -35230,7 +35233,7 @@ function listExpertsHandler(args, ctx) {
|
|
|
35230
35233
|
return Promise.resolve(toolSuccessStructured(data));
|
|
35231
35234
|
}
|
|
35232
35235
|
function registerListExpertsTool(server, deps) {
|
|
35233
|
-
const
|
|
35236
|
+
const logger53 = deps.logger ?? createLogger({ tool: "list_experts" });
|
|
35234
35237
|
const toolSchema = {
|
|
35235
35238
|
format: z57.enum(["full", "names"]).optional().describe("Output format: full (with details) or names (just role names)")
|
|
35236
35239
|
};
|
|
@@ -35238,10 +35241,10 @@ function registerListExpertsTool(server, deps) {
|
|
|
35238
35241
|
const secureHandler = createSecureHandler(listExpertsHandler, {
|
|
35239
35242
|
toolName: "list_experts",
|
|
35240
35243
|
rateLimiter: deps.rateLimiter,
|
|
35241
|
-
logger:
|
|
35244
|
+
logger: logger53
|
|
35242
35245
|
});
|
|
35243
35246
|
const timeoutMs = getToolTimeout("list_experts", deps.security);
|
|
35244
|
-
const wrappedHandler = wrapToolWithTimeout("list_experts", secureHandler, { timeoutMs, logger:
|
|
35247
|
+
const wrappedHandler = wrapToolWithTimeout("list_experts", secureHandler, { timeoutMs, logger: logger53 });
|
|
35245
35248
|
const outputSchema = {
|
|
35246
35249
|
experts: z57.array(
|
|
35247
35250
|
z57.object({
|
|
@@ -35263,7 +35266,7 @@ function registerListExpertsTool(server, deps) {
|
|
|
35263
35266
|
},
|
|
35264
35267
|
toSdkCallback(wrappedHandler)
|
|
35265
35268
|
);
|
|
35266
|
-
|
|
35269
|
+
logger53.info("Registered list_experts tool with secure handler and timeout protection");
|
|
35267
35270
|
}
|
|
35268
35271
|
|
|
35269
35272
|
// src/mcp/tools/list-workflows.ts
|
|
@@ -35322,7 +35325,7 @@ function createListWorkflowsHandler(workflowEngine) {
|
|
|
35322
35325
|
};
|
|
35323
35326
|
}
|
|
35324
35327
|
function registerListWorkflowsTool(server, deps) {
|
|
35325
|
-
const
|
|
35328
|
+
const logger53 = deps.logger ?? createLogger({ tool: "list_workflows" });
|
|
35326
35329
|
const toolSchema = {
|
|
35327
35330
|
category: z58.string().optional().describe("Filter by category (e.g., development, security)"),
|
|
35328
35331
|
format: z58.enum(["full", "names"]).optional().describe("Output format: full (with details) or names (just template names)")
|
|
@@ -35331,13 +35334,13 @@ function registerListWorkflowsTool(server, deps) {
|
|
|
35331
35334
|
const secureHandler = createSecureHandler(createListWorkflowsHandler(deps.workflowEngine), {
|
|
35332
35335
|
toolName: "list_workflows",
|
|
35333
35336
|
rateLimiter: deps.rateLimiter,
|
|
35334
|
-
logger:
|
|
35337
|
+
logger: logger53
|
|
35335
35338
|
});
|
|
35336
35339
|
const timeoutMs = deps.security?.timeout?.defaultTimeoutMs;
|
|
35337
35340
|
const wrappedHandler = wrapToolWithTimeout(
|
|
35338
35341
|
"list_workflows",
|
|
35339
35342
|
secureHandler,
|
|
35340
|
-
timeoutMs !== void 0 ? { timeoutMs, logger:
|
|
35343
|
+
timeoutMs !== void 0 ? { timeoutMs, logger: logger53 } : { logger: logger53 }
|
|
35341
35344
|
);
|
|
35342
35345
|
const outputSchema = {
|
|
35343
35346
|
workflows: z58.array(
|
|
@@ -35361,7 +35364,7 @@ function registerListWorkflowsTool(server, deps) {
|
|
|
35361
35364
|
},
|
|
35362
35365
|
toSdkCallback(wrappedHandler)
|
|
35363
35366
|
);
|
|
35364
|
-
|
|
35367
|
+
logger53.info("Registered list_workflows tool with secure handler and timeout protection");
|
|
35365
35368
|
}
|
|
35366
35369
|
|
|
35367
35370
|
// src/mcp/tools/execute-expert.ts
|
|
@@ -35445,12 +35448,12 @@ function recordExpertError2(expertId, role, errorMessage) {
|
|
|
35445
35448
|
});
|
|
35446
35449
|
}
|
|
35447
35450
|
}
|
|
35448
|
-
function autoCatalogScan(output2, expertId,
|
|
35451
|
+
function autoCatalogScan(output2, expertId, logger53) {
|
|
35449
35452
|
try {
|
|
35450
35453
|
const catalog = getAutoCatalog();
|
|
35451
35454
|
catalog.scanAndRecord(output2, "execute_expert");
|
|
35452
35455
|
} catch (error) {
|
|
35453
|
-
|
|
35456
|
+
logger53?.debug("Best-effort auto-catalog scan failed", {
|
|
35454
35457
|
error: getErrorMessage(error),
|
|
35455
35458
|
expertId
|
|
35456
35459
|
});
|
|
@@ -35509,11 +35512,11 @@ function computeExpertContextUtilization(observation, threshold = DEFAULT_CONTEX
|
|
|
35509
35512
|
threshold
|
|
35510
35513
|
};
|
|
35511
35514
|
}
|
|
35512
|
-
function observeExpertContext(observation,
|
|
35515
|
+
function observeExpertContext(observation, logger53, threshold = resolveContextWarnThreshold()) {
|
|
35513
35516
|
try {
|
|
35514
35517
|
const util = computeExpertContextUtilization(observation, threshold);
|
|
35515
35518
|
if (util.warned) {
|
|
35516
|
-
|
|
35519
|
+
logger53?.warn("context_warning", {
|
|
35517
35520
|
event: "context_warning",
|
|
35518
35521
|
expertId: observation.expertId,
|
|
35519
35522
|
role: observation.role,
|
|
@@ -35526,7 +35529,7 @@ function observeExpertContext(observation, logger52, threshold = resolveContextW
|
|
|
35526
35529
|
taskLength: observation.taskDescription.length
|
|
35527
35530
|
});
|
|
35528
35531
|
} else {
|
|
35529
|
-
|
|
35532
|
+
logger53?.debug("context_utilization", {
|
|
35530
35533
|
event: "context_utilization",
|
|
35531
35534
|
expertId: observation.expertId,
|
|
35532
35535
|
role: observation.role,
|
|
@@ -35614,7 +35617,7 @@ function buildSuccessResponse(params) {
|
|
|
35614
35617
|
}
|
|
35615
35618
|
return response;
|
|
35616
35619
|
}
|
|
35617
|
-
function observeExpertContextIfOk(result, expert, task, durationMs,
|
|
35620
|
+
function observeExpertContextIfOk(result, expert, task, durationMs, logger53) {
|
|
35618
35621
|
if (!result.ok) return;
|
|
35619
35622
|
const expertModelId = expert.expertConfig.modelPreference?.modelId;
|
|
35620
35623
|
const observation = {
|
|
@@ -35625,24 +35628,24 @@ function observeExpertContextIfOk(result, expert, task, durationMs, logger52) {
|
|
|
35625
35628
|
taskDescription: task.description,
|
|
35626
35629
|
durationMs
|
|
35627
35630
|
};
|
|
35628
|
-
observeExpertContext(observation,
|
|
35631
|
+
observeExpertContext(observation, logger53);
|
|
35629
35632
|
}
|
|
35630
|
-
async function deriveExpertAccessPolicy(task,
|
|
35633
|
+
async function deriveExpertAccessPolicy(task, logger53, trustTier) {
|
|
35631
35634
|
const mode = resolveAccessPolicyMode();
|
|
35632
35635
|
try {
|
|
35633
35636
|
const policy = await deriveAccessPolicy(task.description, {
|
|
35634
35637
|
mode,
|
|
35635
|
-
trustTier: "
|
|
35638
|
+
trustTier: trustTier ?? "4"
|
|
35636
35639
|
});
|
|
35637
35640
|
if (mode !== "off") {
|
|
35638
|
-
|
|
35641
|
+
logger53?.info("access-policy: derived (expert)", {
|
|
35639
35642
|
mode,
|
|
35640
35643
|
source: policy.source
|
|
35641
35644
|
});
|
|
35642
35645
|
}
|
|
35643
35646
|
return policy;
|
|
35644
35647
|
} catch (error) {
|
|
35645
|
-
|
|
35648
|
+
logger53?.warn("access-policy: derivation failed (expert)", {
|
|
35646
35649
|
mode,
|
|
35647
35650
|
error: getErrorMessage(error),
|
|
35648
35651
|
failClosed: mode === "enforce" || mode === "confirm_risky"
|
|
@@ -35701,11 +35704,11 @@ function isExpertDegraded(role) {
|
|
|
35701
35704
|
}
|
|
35702
35705
|
return consecutive >= DEGRADATION_CONSECUTIVE_THRESHOLD;
|
|
35703
35706
|
}
|
|
35704
|
-
async function tryExpertFallback(expert, task,
|
|
35707
|
+
async function tryExpertFallback(expert, task, logger53) {
|
|
35705
35708
|
const roleKey = `${expert.role}_expert`;
|
|
35706
35709
|
const category = ROLE_TO_TASK_CATEGORY[roleKey];
|
|
35707
35710
|
if (category === void 0) return void 0;
|
|
35708
|
-
const effectiveLogger =
|
|
35711
|
+
const effectiveLogger = logger53 ?? createLogger({ tool: "execute_expert" });
|
|
35709
35712
|
const registry = getGlobalRegistry({ logger: effectiveLogger });
|
|
35710
35713
|
const routing = registry.getRouting(category);
|
|
35711
35714
|
const primaryCli = routing?.primaryCli ?? "unknown";
|
|
@@ -35714,7 +35717,7 @@ async function tryExpertFallback(expert, task, logger52) {
|
|
|
35714
35717
|
const fallbackCli = chain[0];
|
|
35715
35718
|
if (fallbackCli === void 0) return void 0;
|
|
35716
35719
|
const fallbackAdapter = registry.getAdapterForCli(fallbackCli);
|
|
35717
|
-
|
|
35720
|
+
logger53?.info("Retrying expert with fallback CLI", { role: expert.role, fallbackCli });
|
|
35718
35721
|
const fallbackResult = createExpert(expert.expertConfig, { adapter: fallbackAdapter });
|
|
35719
35722
|
if (!fallbackResult.ok) return void 0;
|
|
35720
35723
|
const fallbackStart = getTimeProvider().now();
|
|
@@ -35734,7 +35737,7 @@ async function tryExpertFallback(expert, task, logger52) {
|
|
|
35734
35737
|
};
|
|
35735
35738
|
}
|
|
35736
35739
|
async function classifyExpertResult(opts) {
|
|
35737
|
-
const { result, expert, task, args, durationMs, logger:
|
|
35740
|
+
const { result, expert, task, args, durationMs, logger: logger53 } = opts;
|
|
35738
35741
|
const modelId = expert.expertConfig.modelPreference?.modelId;
|
|
35739
35742
|
const info = {
|
|
35740
35743
|
expertId: args.expertId,
|
|
@@ -35743,19 +35746,19 @@ async function classifyExpertResult(opts) {
|
|
|
35743
35746
|
};
|
|
35744
35747
|
if (!result.ok) {
|
|
35745
35748
|
if (isRateLimitFailure(result.error.message)) {
|
|
35746
|
-
const fallback = await tryExpertFallback(expert, task,
|
|
35749
|
+
const fallback = await tryExpertFallback(expert, task, logger53);
|
|
35747
35750
|
if (fallback !== void 0) return fallback;
|
|
35748
35751
|
}
|
|
35749
|
-
|
|
35752
|
+
logger53?.warn("Expert execution failed", {
|
|
35750
35753
|
expertId: args.expertId,
|
|
35751
35754
|
error: result.error.message
|
|
35752
35755
|
});
|
|
35753
35756
|
return handleExpertFailure(args.task, info, result.error.message, durationMs);
|
|
35754
35757
|
}
|
|
35755
|
-
|
|
35758
|
+
logger53?.info("Expert execution completed", { expertId: args.expertId, durationMs });
|
|
35756
35759
|
handleExpertSuccess(args.task, info, durationMs);
|
|
35757
35760
|
if (typeof result.value.output === "string") {
|
|
35758
|
-
autoCatalogScan(result.value.output, args.expertId,
|
|
35761
|
+
autoCatalogScan(result.value.output, args.expertId, logger53);
|
|
35759
35762
|
}
|
|
35760
35763
|
return {
|
|
35761
35764
|
ok: true,
|
|
@@ -35792,7 +35795,7 @@ async function runExpertTask(deps, args, expert) {
|
|
|
35792
35795
|
}, HEARTBEAT_TIMEOUTS.heartbeatIntervalMs);
|
|
35793
35796
|
let result;
|
|
35794
35797
|
try {
|
|
35795
|
-
const policy = await deriveExpertAccessPolicy(task, deps.logger);
|
|
35798
|
+
const policy = await deriveExpertAccessPolicy(task, deps.logger, void 0);
|
|
35796
35799
|
result = await withAccessPolicy(policy, () => expert.execute(task));
|
|
35797
35800
|
} finally {
|
|
35798
35801
|
clearInterval(heartbeatTimer);
|
|
@@ -35843,7 +35846,7 @@ var EXECUTE_EXPERT_TOOL_SCHEMA = {
|
|
|
35843
35846
|
context: z59.record(z59.string(), z59.unknown()).optional().describe("Additional context metadata for the task"),
|
|
35844
35847
|
timeoutMs: z59.number().int().min(EXPERT_TIMEOUT_FLOOR_MS).max(EXPERT_TIMEOUTS.maxMs).optional().describe("Optional timeout in ms (120s-900s). Overrides auto-detected timeout.")
|
|
35845
35848
|
};
|
|
35846
|
-
function createTaskHandler(deps,
|
|
35849
|
+
function createTaskHandler(deps, logger53) {
|
|
35847
35850
|
const notifier = deps.notifier ?? NOOP_NOTIFIER;
|
|
35848
35851
|
return {
|
|
35849
35852
|
createTask: (args, extra) => {
|
|
@@ -35855,7 +35858,7 @@ function createTaskHandler(deps, logger52) {
|
|
|
35855
35858
|
const { taskStore } = extra;
|
|
35856
35859
|
const ttl = clampTaskTtl(DEFAULT_TASK_TTL_MS);
|
|
35857
35860
|
const taskPromise = taskStore.createTask({ ttl, pollInterval: 5e3 }).then((task) => {
|
|
35858
|
-
|
|
35861
|
+
logger53.info("Task created for execute_expert", {
|
|
35859
35862
|
taskId: task.taskId,
|
|
35860
35863
|
expertId: validatedArgs.expertId
|
|
35861
35864
|
});
|
|
@@ -35880,7 +35883,7 @@ function createTaskHandler(deps, logger52) {
|
|
|
35880
35883
|
}
|
|
35881
35884
|
async function runBackgroundExpertTask(opts) {
|
|
35882
35885
|
const { deps, args, taskId, taskStore, notifier } = opts;
|
|
35883
|
-
const
|
|
35886
|
+
const logger53 = deps.logger ?? createLogger({ tool: "execute_expert" });
|
|
35884
35887
|
try {
|
|
35885
35888
|
notifier.info("execute_expert", {
|
|
35886
35889
|
event: "expert_start",
|
|
@@ -35913,7 +35916,7 @@ async function runBackgroundExpertTask(opts) {
|
|
|
35913
35916
|
});
|
|
35914
35917
|
} catch (error) {
|
|
35915
35918
|
const message = getErrorMessage(error);
|
|
35916
|
-
|
|
35919
|
+
logger53.warn("Background expert task failed", { taskId, error: message });
|
|
35917
35920
|
try {
|
|
35918
35921
|
await taskStore.storeTaskResult(taskId, "failed", {
|
|
35919
35922
|
...toolStructuredError({
|
|
@@ -35922,7 +35925,7 @@ async function runBackgroundExpertTask(opts) {
|
|
|
35922
35925
|
})
|
|
35923
35926
|
});
|
|
35924
35927
|
} catch (storeError) {
|
|
35925
|
-
|
|
35928
|
+
logger53.warn("Failed to store task failure result", {
|
|
35926
35929
|
taskId,
|
|
35927
35930
|
error: getErrorMessage(storeError)
|
|
35928
35931
|
});
|
|
@@ -35930,7 +35933,7 @@ async function runBackgroundExpertTask(opts) {
|
|
|
35930
35933
|
}
|
|
35931
35934
|
}
|
|
35932
35935
|
function registerExecuteExpertTool(server, deps) {
|
|
35933
|
-
const
|
|
35936
|
+
const logger53 = deps.logger ?? createLogger({ tool: "execute_expert" });
|
|
35934
35937
|
const notifier = deps.notifier ?? createMcpNotifier(server);
|
|
35935
35938
|
const depsWithNotifier = { ...deps, notifier };
|
|
35936
35939
|
const description2 = "Run a task through an expert YOU PREVIOUSLY CREATED via `create_expert`. Requires the expertId returned by create_expert; not for ad-hoc execution. Returns the expert analysis including output, confidence, and token usage.";
|
|
@@ -35942,9 +35945,9 @@ function registerExecuteExpertTool(server, deps) {
|
|
|
35942
35945
|
execution: { taskSupport: "optional" },
|
|
35943
35946
|
annotations: getToolAnnotations("execute_expert")
|
|
35944
35947
|
},
|
|
35945
|
-
createTaskHandler(depsWithNotifier,
|
|
35948
|
+
createTaskHandler(depsWithNotifier, logger53)
|
|
35946
35949
|
);
|
|
35947
|
-
|
|
35950
|
+
logger53.info("Registered execute_expert tool with MCP Tasks support (taskSupport: optional)");
|
|
35948
35951
|
}
|
|
35949
35952
|
|
|
35950
35953
|
// src/mcp/tools/research-query.ts
|
|
@@ -37343,15 +37346,15 @@ function createResearchQueryHandler(deps) {
|
|
|
37343
37346
|
});
|
|
37344
37347
|
}
|
|
37345
37348
|
ctx.logger.debug("Executing research query", { action: validationResult.data.action });
|
|
37346
|
-
const
|
|
37347
|
-
return withToolError("Research query failed",
|
|
37349
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_query" });
|
|
37350
|
+
return withToolError("Research query failed", logger53, async () => {
|
|
37348
37351
|
const result = await executeQuery(validationResult.data);
|
|
37349
37352
|
return toolSuccessStructured(result);
|
|
37350
37353
|
});
|
|
37351
37354
|
};
|
|
37352
37355
|
}
|
|
37353
37356
|
function registerResearchQueryTool(server, deps) {
|
|
37354
|
-
const
|
|
37357
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_query" });
|
|
37355
37358
|
const toolSchema = {
|
|
37356
37359
|
action: z62.enum(["status", "overlap", "stats", "search"]).describe("Query action: status, overlap, stats, or search"),
|
|
37357
37360
|
techniqueId: z62.string().optional().describe("Technique ID for status/overlap queries"),
|
|
@@ -37363,12 +37366,12 @@ function registerResearchQueryTool(server, deps) {
|
|
|
37363
37366
|
const secureHandler = createSecureHandler(createResearchQueryHandler(deps), {
|
|
37364
37367
|
toolName: "research_query",
|
|
37365
37368
|
rateLimiter: deps.rateLimiter,
|
|
37366
|
-
logger:
|
|
37369
|
+
logger: logger53
|
|
37367
37370
|
});
|
|
37368
37371
|
const timeoutMs = getToolTimeout("research_query", deps.security);
|
|
37369
37372
|
const wrappedHandler = wrapToolWithTimeout("research_query", secureHandler, {
|
|
37370
37373
|
timeoutMs,
|
|
37371
|
-
logger:
|
|
37374
|
+
logger: logger53
|
|
37372
37375
|
});
|
|
37373
37376
|
const outputSchema = {
|
|
37374
37377
|
action: z62.string(),
|
|
@@ -37385,7 +37388,7 @@ function registerResearchQueryTool(server, deps) {
|
|
|
37385
37388
|
},
|
|
37386
37389
|
toSdkCallback(wrappedHandler)
|
|
37387
37390
|
);
|
|
37388
|
-
|
|
37391
|
+
logger53.info("Registered research_query tool with secure handler and timeout protection");
|
|
37389
37392
|
}
|
|
37390
37393
|
|
|
37391
37394
|
// src/mcp/tools/research-add.ts
|
|
@@ -37396,7 +37399,7 @@ var ResearchAddInputSchema = z63.object({
|
|
|
37396
37399
|
priority: z63.enum(["P1", "P2", "P3", "P4"]).optional().describe("Priority level for the paper"),
|
|
37397
37400
|
dryRun: z63.boolean().optional().default(false).describe("Preview what would be added without persisting")
|
|
37398
37401
|
});
|
|
37399
|
-
async function executeResearchAdd(input,
|
|
37402
|
+
async function executeResearchAdd(input, logger53) {
|
|
37400
37403
|
const exists = await paperExists(input.arxivId);
|
|
37401
37404
|
if (exists) {
|
|
37402
37405
|
return {
|
|
@@ -37416,7 +37419,7 @@ async function executeResearchAdd(input, logger52) {
|
|
|
37416
37419
|
});
|
|
37417
37420
|
if (result.success && !input.dryRun) {
|
|
37418
37421
|
try {
|
|
37419
|
-
const memory = getToolMemory(
|
|
37422
|
+
const memory = getToolMemory(logger53);
|
|
37420
37423
|
memory.recordLearning({
|
|
37421
37424
|
pattern: `Added paper: ${result.title} (${result.paperId})`,
|
|
37422
37425
|
context: `topic=${input.topic ?? "general"}, priority=${input.priority ?? "unset"}`,
|
|
@@ -37424,7 +37427,7 @@ async function executeResearchAdd(input, logger52) {
|
|
|
37424
37427
|
source: "research_add"
|
|
37425
37428
|
});
|
|
37426
37429
|
} catch {
|
|
37427
|
-
|
|
37430
|
+
logger53.debug("Failed to record learning in session memory");
|
|
37428
37431
|
}
|
|
37429
37432
|
}
|
|
37430
37433
|
const qualityNote = result.success && !input.dryRun ? " [evidence_tier=low \u2014 arXiv preprint, no citation data yet. Run backfill-research-quality.ts to enrich.]" : "";
|
|
@@ -37446,9 +37449,9 @@ function createResearchAddHandler(deps) {
|
|
|
37446
37449
|
});
|
|
37447
37450
|
}
|
|
37448
37451
|
ctx.logger.debug("Adding research paper", { arxivId: validationResult.data.arxivId });
|
|
37449
|
-
const
|
|
37450
|
-
return withToolError("Failed to add paper",
|
|
37451
|
-
const result = await executeResearchAdd(validationResult.data,
|
|
37452
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_add" });
|
|
37453
|
+
return withToolError("Failed to add paper", logger53, async () => {
|
|
37454
|
+
const result = await executeResearchAdd(validationResult.data, logger53);
|
|
37452
37455
|
if (!result.success) {
|
|
37453
37456
|
return toolStructuredError({
|
|
37454
37457
|
errorCategory: result.errorCategory ?? "internal",
|
|
@@ -37460,7 +37463,7 @@ function createResearchAddHandler(deps) {
|
|
|
37460
37463
|
};
|
|
37461
37464
|
}
|
|
37462
37465
|
function registerResearchAddTool(server, deps) {
|
|
37463
|
-
const
|
|
37466
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_add" });
|
|
37464
37467
|
const toolSchema = {
|
|
37465
37468
|
arxivId: z63.string().regex(/^\d{4}\.\d{4,5}$/).describe('arXiv paper ID (e.g., "2401.12345")'),
|
|
37466
37469
|
topic: z63.string().optional().describe("Research topic to categorize the paper under"),
|
|
@@ -37471,12 +37474,12 @@ function registerResearchAddTool(server, deps) {
|
|
|
37471
37474
|
const secureHandler = createSecureHandler(createResearchAddHandler(deps), {
|
|
37472
37475
|
toolName: "research_add",
|
|
37473
37476
|
rateLimiter: deps.rateLimiter,
|
|
37474
|
-
logger:
|
|
37477
|
+
logger: logger53
|
|
37475
37478
|
});
|
|
37476
37479
|
const timeoutMs = getToolTimeout("research_add", deps.security);
|
|
37477
37480
|
const wrappedHandler = wrapToolWithTimeout("research_add", secureHandler, {
|
|
37478
37481
|
timeoutMs,
|
|
37479
|
-
logger:
|
|
37482
|
+
logger: logger53
|
|
37480
37483
|
});
|
|
37481
37484
|
const outputSchema = {
|
|
37482
37485
|
success: z63.boolean(),
|
|
@@ -37495,7 +37498,7 @@ function registerResearchAddTool(server, deps) {
|
|
|
37495
37498
|
},
|
|
37496
37499
|
toSdkCallback(wrappedHandler)
|
|
37497
37500
|
);
|
|
37498
|
-
|
|
37501
|
+
logger53.info("Registered research_add tool with secure handler and timeout protection");
|
|
37499
37502
|
}
|
|
37500
37503
|
|
|
37501
37504
|
// src/mcp/tools/research-add-source.ts
|
|
@@ -37573,9 +37576,9 @@ function buildResponse2(params) {
|
|
|
37573
37576
|
...params.errorCategory !== void 0 ? { errorCategory: params.errorCategory } : {}
|
|
37574
37577
|
};
|
|
37575
37578
|
}
|
|
37576
|
-
function recordAddSourceLearning(
|
|
37579
|
+
function recordAddSourceLearning(logger53, name, sourceId, type, qualityScore) {
|
|
37577
37580
|
try {
|
|
37578
|
-
const memory = getToolMemory(
|
|
37581
|
+
const memory = getToolMemory(logger53);
|
|
37579
37582
|
memory.recordLearning({
|
|
37580
37583
|
pattern: `Added source: ${name} (${sourceId})`,
|
|
37581
37584
|
context: `type=${type}, quality=${String(qualityScore)}`,
|
|
@@ -37583,7 +37586,7 @@ function recordAddSourceLearning(logger52, name, sourceId, type, qualityScore) {
|
|
|
37583
37586
|
source: "research_add_source"
|
|
37584
37587
|
});
|
|
37585
37588
|
} catch {
|
|
37586
|
-
|
|
37589
|
+
logger53.debug("Failed to record learning in session memory");
|
|
37587
37590
|
}
|
|
37588
37591
|
}
|
|
37589
37592
|
function prepareSource(input) {
|
|
@@ -37591,7 +37594,7 @@ function prepareSource(input) {
|
|
|
37591
37594
|
const score = computeSourceQualityScore(entry);
|
|
37592
37595
|
return { entry, score };
|
|
37593
37596
|
}
|
|
37594
|
-
async function executeResearchAddSource(input,
|
|
37597
|
+
async function executeResearchAddSource(input, logger53) {
|
|
37595
37598
|
const sourceId = generateSourceId(input.url);
|
|
37596
37599
|
const exists = await sourceExistsInRegistry(input.url);
|
|
37597
37600
|
if (exists) {
|
|
@@ -37628,8 +37631,8 @@ async function executeResearchAddSource(input, logger52) {
|
|
|
37628
37631
|
errorCategory: "internal"
|
|
37629
37632
|
});
|
|
37630
37633
|
}
|
|
37631
|
-
recordAddSourceLearning(
|
|
37632
|
-
|
|
37634
|
+
recordAddSourceLearning(logger53, input.name, sourceId, input.type, score);
|
|
37635
|
+
logger53.info("Added research source", { sourceId, name: input.name, qualityScore: score });
|
|
37633
37636
|
return buildResponse2({
|
|
37634
37637
|
success: true,
|
|
37635
37638
|
sourceId,
|
|
@@ -37649,9 +37652,9 @@ function createResearchAddSourceHandler(deps) {
|
|
|
37649
37652
|
});
|
|
37650
37653
|
}
|
|
37651
37654
|
ctx.logger.debug("Adding research source", { url: validationResult.data.url });
|
|
37652
|
-
const
|
|
37653
|
-
return withToolError("Failed to add source",
|
|
37654
|
-
const result = await executeResearchAddSource(validationResult.data,
|
|
37655
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_add_source" });
|
|
37656
|
+
return withToolError("Failed to add source", logger53, async () => {
|
|
37657
|
+
const result = await executeResearchAddSource(validationResult.data, logger53);
|
|
37655
37658
|
if (!result.success) {
|
|
37656
37659
|
return toolStructuredError({
|
|
37657
37660
|
errorCategory: result.errorCategory ?? "internal",
|
|
@@ -37663,7 +37666,7 @@ function createResearchAddSourceHandler(deps) {
|
|
|
37663
37666
|
};
|
|
37664
37667
|
}
|
|
37665
37668
|
function registerResearchAddSourceTool(server, deps) {
|
|
37666
|
-
const
|
|
37669
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_add_source" });
|
|
37667
37670
|
const toolSchema = {
|
|
37668
37671
|
url: z64.string().min(1).describe("Source URL"),
|
|
37669
37672
|
name: z64.string().min(1).describe("Display name"),
|
|
@@ -37688,12 +37691,12 @@ function registerResearchAddSourceTool(server, deps) {
|
|
|
37688
37691
|
toolName: "research_add_source",
|
|
37689
37692
|
securityTier: "external",
|
|
37690
37693
|
rateLimiter: deps.rateLimiter,
|
|
37691
|
-
logger:
|
|
37694
|
+
logger: logger53
|
|
37692
37695
|
});
|
|
37693
37696
|
const timeoutMs = getToolTimeout("research_add_source", deps.security);
|
|
37694
37697
|
const wrappedHandler = wrapToolWithTimeout("research_add_source", secureHandler, {
|
|
37695
37698
|
timeoutMs,
|
|
37696
|
-
logger:
|
|
37699
|
+
logger: logger53
|
|
37697
37700
|
});
|
|
37698
37701
|
server.registerTool(
|
|
37699
37702
|
"research_add_source",
|
|
@@ -37760,7 +37763,7 @@ function toDiscoveredItems(sources) {
|
|
|
37760
37763
|
discoveredAt: s.discoveredAt
|
|
37761
37764
|
}));
|
|
37762
37765
|
}
|
|
37763
|
-
async function discoverFromExtendedSource(source, topic, maxResults,
|
|
37766
|
+
async function discoverFromExtendedSource(source, topic, maxResults, logger53, sinceDate) {
|
|
37764
37767
|
let result;
|
|
37765
37768
|
switch (source) {
|
|
37766
37769
|
case "google_ai":
|
|
@@ -37788,7 +37791,7 @@ async function discoverFromExtendedSource(source, topic, maxResults, logger52, s
|
|
|
37788
37791
|
return { items: [], failed: true };
|
|
37789
37792
|
}
|
|
37790
37793
|
if (!result.ok) {
|
|
37791
|
-
|
|
37794
|
+
logger53.warn(`${source} discovery failed`, {
|
|
37792
37795
|
source,
|
|
37793
37796
|
errorCode: result.error.code,
|
|
37794
37797
|
error: result.error.message
|
|
@@ -37828,24 +37831,24 @@ function markExistingItems(items, existingIds) {
|
|
|
37828
37831
|
}
|
|
37829
37832
|
var ARXIV_ORG_SOURCES = /* @__PURE__ */ new Set(["google_ai", "meta_fair", "microsoft", "deepmind"]);
|
|
37830
37833
|
var INDEPENDENT_SOURCES = ["semantic_scholar", "papers_with_code", "openalex"];
|
|
37831
|
-
async function queryExtendedSource(src, input,
|
|
37834
|
+
async function queryExtendedSource(src, input, logger53, acc) {
|
|
37832
37835
|
acc.sources.push(src);
|
|
37833
37836
|
try {
|
|
37834
37837
|
const result = await discoverFromExtendedSource(
|
|
37835
37838
|
src,
|
|
37836
37839
|
input.topic,
|
|
37837
37840
|
input.maxResults,
|
|
37838
|
-
|
|
37841
|
+
logger53,
|
|
37839
37842
|
input.sinceDate
|
|
37840
37843
|
);
|
|
37841
37844
|
if (result.failed) acc.failedSources.push(src);
|
|
37842
37845
|
acc.items = acc.items.concat(result.items);
|
|
37843
37846
|
} catch (error) {
|
|
37844
37847
|
acc.failedSources.push(src);
|
|
37845
|
-
|
|
37848
|
+
logger53.warn("Source discovery failed", { source: src, error: getErrorMessage(error) });
|
|
37846
37849
|
}
|
|
37847
37850
|
}
|
|
37848
|
-
async function queryAllSources(input,
|
|
37851
|
+
async function queryAllSources(input, logger53) {
|
|
37849
37852
|
const acc = { sources: [], failedSources: [], items: [] };
|
|
37850
37853
|
const isAll = input.source === "all";
|
|
37851
37854
|
const shouldQuery = (src) => isAll || input.source === src;
|
|
@@ -37855,11 +37858,11 @@ async function queryAllSources(input, logger52) {
|
|
|
37855
37858
|
if (r.ok) acc.items = acc.items.concat(toDiscoveredItems(r.value));
|
|
37856
37859
|
else {
|
|
37857
37860
|
acc.failedSources.push("arxiv");
|
|
37858
|
-
|
|
37861
|
+
logger53.warn("arxiv discovery failed", { error: r.error.message });
|
|
37859
37862
|
}
|
|
37860
37863
|
}
|
|
37861
37864
|
for (const src of ARXIV_ORG_SOURCES) {
|
|
37862
|
-
if (!isAll && input.source === src) await queryExtendedSource(src, input,
|
|
37865
|
+
if (!isAll && input.source === src) await queryExtendedSource(src, input, logger53, acc);
|
|
37863
37866
|
}
|
|
37864
37867
|
if (shouldQuery("github")) {
|
|
37865
37868
|
acc.sources.push("github");
|
|
@@ -37867,15 +37870,15 @@ async function queryAllSources(input, logger52) {
|
|
|
37867
37870
|
if (r.ok) acc.items = acc.items.concat(toDiscoveredItems(r.value));
|
|
37868
37871
|
else {
|
|
37869
37872
|
acc.failedSources.push("github");
|
|
37870
|
-
|
|
37873
|
+
logger53.warn("github discovery failed", { error: r.error.message });
|
|
37871
37874
|
}
|
|
37872
37875
|
}
|
|
37873
37876
|
for (const src of INDEPENDENT_SOURCES) {
|
|
37874
|
-
if (shouldQuery(src)) await queryExtendedSource(src, input,
|
|
37877
|
+
if (shouldQuery(src)) await queryExtendedSource(src, input, logger53, acc);
|
|
37875
37878
|
}
|
|
37876
37879
|
return acc;
|
|
37877
37880
|
}
|
|
37878
|
-
async function executeDiscovery(rawInput,
|
|
37881
|
+
async function executeDiscovery(rawInput, logger53) {
|
|
37879
37882
|
const input = {
|
|
37880
37883
|
...rawInput,
|
|
37881
37884
|
topic: normalizeTopicToCanonical(rawInput.topic)
|
|
@@ -37885,7 +37888,7 @@ async function executeDiscovery(rawInput, logger52) {
|
|
|
37885
37888
|
sources: sourcesToQuery,
|
|
37886
37889
|
failedSources,
|
|
37887
37890
|
items: allItems
|
|
37888
|
-
} = await queryAllSources(input,
|
|
37891
|
+
} = await queryAllSources(input, logger53);
|
|
37889
37892
|
markExistingItems(allItems, existingIds);
|
|
37890
37893
|
const totalFound = allItems.length;
|
|
37891
37894
|
const inRegistry = allItems.filter((i) => i.alreadyInRegistry).length;
|
|
@@ -37897,7 +37900,7 @@ async function executeDiscovery(rawInput, logger52) {
|
|
|
37897
37900
|
).slice(0, input.maxResults);
|
|
37898
37901
|
const filteredOut = totalFound - inRegistry - relevantItems.length;
|
|
37899
37902
|
if (filteredOut > 0) {
|
|
37900
|
-
|
|
37903
|
+
logger53.debug("Filtered out irrelevant results", {
|
|
37901
37904
|
threshold,
|
|
37902
37905
|
filteredOut,
|
|
37903
37906
|
remaining: relevantItems.length
|
|
@@ -37982,10 +37985,10 @@ function createResearchDiscoverHandler(deps) {
|
|
|
37982
37985
|
topic: validationResult.data.topic,
|
|
37983
37986
|
source: validationResult.data.source
|
|
37984
37987
|
});
|
|
37985
|
-
const
|
|
37988
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_discover" });
|
|
37986
37989
|
const startMs = Date.now();
|
|
37987
|
-
const response = await withToolError("Discovery failed",
|
|
37988
|
-
const result = await executeDiscovery(validationResult.data,
|
|
37990
|
+
const response = await withToolError("Discovery failed", logger53, async () => {
|
|
37991
|
+
const result = await executeDiscovery(validationResult.data, logger53);
|
|
37989
37992
|
return toolSuccessStructured(result);
|
|
37990
37993
|
});
|
|
37991
37994
|
const durationMs = Date.now() - startMs;
|
|
@@ -37999,7 +38002,7 @@ function createResearchDiscoverHandler(deps) {
|
|
|
37999
38002
|
};
|
|
38000
38003
|
}
|
|
38001
38004
|
function registerResearchDiscoverTool(server, deps) {
|
|
38002
|
-
const
|
|
38005
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_discover" });
|
|
38003
38006
|
const toolSchema = {
|
|
38004
38007
|
topic: z65.string().min(1).max(200).describe("Research topic to search for"),
|
|
38005
38008
|
source: z65.enum([
|
|
@@ -38022,12 +38025,12 @@ function registerResearchDiscoverTool(server, deps) {
|
|
|
38022
38025
|
const secureHandler = createSecureHandler(createResearchDiscoverHandler(deps), {
|
|
38023
38026
|
toolName: "research_discover",
|
|
38024
38027
|
rateLimiter: deps.rateLimiter,
|
|
38025
|
-
logger:
|
|
38028
|
+
logger: logger53
|
|
38026
38029
|
});
|
|
38027
38030
|
const timeoutMs = getToolTimeout("research_discover", deps.security);
|
|
38028
38031
|
const wrappedHandler = wrapToolWithTimeout("research_discover", secureHandler, {
|
|
38029
38032
|
timeoutMs,
|
|
38030
|
-
logger:
|
|
38033
|
+
logger: logger53
|
|
38031
38034
|
});
|
|
38032
38035
|
server.registerTool(
|
|
38033
38036
|
"research_discover",
|
|
@@ -38039,7 +38042,7 @@ function registerResearchDiscoverTool(server, deps) {
|
|
|
38039
38042
|
},
|
|
38040
38043
|
toSdkCallback(wrappedHandler)
|
|
38041
38044
|
);
|
|
38042
|
-
|
|
38045
|
+
logger53.info("Registered research_discover tool with secure handler and timeout protection");
|
|
38043
38046
|
}
|
|
38044
38047
|
var RESEARCH_DISCOVER_OUTPUT_SCHEMA = {
|
|
38045
38048
|
topic: z65.string().optional(),
|
|
@@ -38293,15 +38296,15 @@ function createResearchAnalyzeHandler(deps) {
|
|
|
38293
38296
|
ctx.logger.debug("Analyzing research registry", {
|
|
38294
38297
|
focus: validationResult.data.focus
|
|
38295
38298
|
});
|
|
38296
|
-
const
|
|
38297
|
-
return withToolError("Analysis failed",
|
|
38299
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_analyze" });
|
|
38300
|
+
return withToolError("Analysis failed", logger53, async () => {
|
|
38298
38301
|
const result = await executeAnalysis(validationResult.data);
|
|
38299
38302
|
return toolSuccessStructured(result);
|
|
38300
38303
|
});
|
|
38301
38304
|
};
|
|
38302
38305
|
}
|
|
38303
38306
|
function registerResearchAnalyzeTool(server, deps) {
|
|
38304
|
-
const
|
|
38307
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_analyze" });
|
|
38305
38308
|
const toolSchema = {
|
|
38306
38309
|
focus: z66.enum(["gaps", "trends", "priorities", "stale", "coverage"]).describe("Analysis focus area"),
|
|
38307
38310
|
topic: z66.string().optional().describe("Optional topic filter")
|
|
@@ -38310,12 +38313,12 @@ function registerResearchAnalyzeTool(server, deps) {
|
|
|
38310
38313
|
const secureHandler = createSecureHandler(createResearchAnalyzeHandler(deps), {
|
|
38311
38314
|
toolName: "research_analyze",
|
|
38312
38315
|
rateLimiter: deps.rateLimiter,
|
|
38313
|
-
logger:
|
|
38316
|
+
logger: logger53
|
|
38314
38317
|
});
|
|
38315
38318
|
const timeoutMs = getToolTimeout("research_analyze", deps.security);
|
|
38316
38319
|
const wrappedHandler = wrapToolWithTimeout("research_analyze", secureHandler, {
|
|
38317
38320
|
timeoutMs,
|
|
38318
|
-
logger:
|
|
38321
|
+
logger: logger53
|
|
38319
38322
|
});
|
|
38320
38323
|
const outputSchema = {
|
|
38321
38324
|
focus: z66.string().optional(),
|
|
@@ -38333,7 +38336,7 @@ function registerResearchAnalyzeTool(server, deps) {
|
|
|
38333
38336
|
},
|
|
38334
38337
|
toSdkCallback(wrappedHandler)
|
|
38335
38338
|
);
|
|
38336
|
-
|
|
38339
|
+
logger53.info("Registered research_analyze tool with secure handler and timeout protection");
|
|
38337
38340
|
}
|
|
38338
38341
|
|
|
38339
38342
|
// src/mcp/tools/research-catalog-review.ts
|
|
@@ -38356,7 +38359,7 @@ function handleList() {
|
|
|
38356
38359
|
data: { pending, count: pending.length }
|
|
38357
38360
|
};
|
|
38358
38361
|
}
|
|
38359
|
-
async function approveArxivRef(identifier, topic, shouldCreateIssue,
|
|
38362
|
+
async function approveArxivRef(identifier, topic, shouldCreateIssue, logger53) {
|
|
38360
38363
|
const catalog = getAutoCatalog();
|
|
38361
38364
|
const exists = await paperExists(identifier);
|
|
38362
38365
|
if (exists) {
|
|
@@ -38368,7 +38371,7 @@ async function approveArxivRef(identifier, topic, shouldCreateIssue, logger52) {
|
|
|
38368
38371
|
if (!result.success) {
|
|
38369
38372
|
return { action: "approve", success: false, message: `Failed: ${result.message}` };
|
|
38370
38373
|
}
|
|
38371
|
-
|
|
38374
|
+
logger53.info("Approved paper", { paperId: result.paperId });
|
|
38372
38375
|
if (shouldCreateIssue) {
|
|
38373
38376
|
const body = formatResearchIssueBody([
|
|
38374
38377
|
{
|
|
@@ -38392,11 +38395,11 @@ async function approveArxivRef(identifier, topic, shouldCreateIssue, logger52) {
|
|
|
38392
38395
|
data: { ...result, issueUrl: issueResult.value.url }
|
|
38393
38396
|
};
|
|
38394
38397
|
}
|
|
38395
|
-
|
|
38398
|
+
logger53.warn("Issue creation failed after approve", { error: issueResult.error.message });
|
|
38396
38399
|
}
|
|
38397
38400
|
return { action: "approve", success: true, message: `Added: ${result.title}`, data: result };
|
|
38398
38401
|
}
|
|
38399
|
-
async function handleApprove(input,
|
|
38402
|
+
async function handleApprove(input, logger53) {
|
|
38400
38403
|
if (input.identifier === void 0 || input.identifier === "") {
|
|
38401
38404
|
return { action: "approve", success: false, message: "identifier is required" };
|
|
38402
38405
|
}
|
|
@@ -38410,7 +38413,7 @@ async function handleApprove(input, logger52) {
|
|
|
38410
38413
|
};
|
|
38411
38414
|
}
|
|
38412
38415
|
if (ref.type === "arxiv") {
|
|
38413
|
-
return approveArxivRef(ref.identifier, input.topic, input.createIssue,
|
|
38416
|
+
return approveArxivRef(ref.identifier, input.topic, input.createIssue, logger53);
|
|
38414
38417
|
}
|
|
38415
38418
|
catalog.markReviewed(ref.identifier);
|
|
38416
38419
|
return { action: "approve", success: true, message: `Reviewed: ${ref.identifier}` };
|
|
@@ -38441,12 +38444,12 @@ function handleFlush() {
|
|
|
38441
38444
|
message: `Flushed ${String(count)} references from catalog`
|
|
38442
38445
|
};
|
|
38443
38446
|
}
|
|
38444
|
-
async function executeCatalogReview(input,
|
|
38447
|
+
async function executeCatalogReview(input, logger53) {
|
|
38445
38448
|
switch (input.action) {
|
|
38446
38449
|
case "list":
|
|
38447
38450
|
return handleList();
|
|
38448
38451
|
case "approve":
|
|
38449
|
-
return handleApprove(input,
|
|
38452
|
+
return handleApprove(input, logger53);
|
|
38450
38453
|
case "dismiss":
|
|
38451
38454
|
return handleDismiss(input);
|
|
38452
38455
|
case "flush":
|
|
@@ -38463,9 +38466,9 @@ function createCatalogReviewHandler(deps) {
|
|
|
38463
38466
|
});
|
|
38464
38467
|
}
|
|
38465
38468
|
ctx.logger.debug("Catalog review", { action: validationResult.data.action });
|
|
38466
|
-
const
|
|
38467
|
-
return withToolError("Catalog review failed",
|
|
38468
|
-
const result = await executeCatalogReview(validationResult.data,
|
|
38469
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_catalog_review" });
|
|
38470
|
+
return withToolError("Catalog review failed", logger53, async () => {
|
|
38471
|
+
const result = await executeCatalogReview(validationResult.data, logger53);
|
|
38469
38472
|
if (!result.success) {
|
|
38470
38473
|
return toolStructuredError({ errorCategory: "validation", message: result.message });
|
|
38471
38474
|
}
|
|
@@ -38474,7 +38477,7 @@ function createCatalogReviewHandler(deps) {
|
|
|
38474
38477
|
};
|
|
38475
38478
|
}
|
|
38476
38479
|
function registerResearchCatalogReviewTool(server, deps) {
|
|
38477
|
-
const
|
|
38480
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_catalog_review" });
|
|
38478
38481
|
const toolSchema = {
|
|
38479
38482
|
action: z67.enum(["list", "approve", "dismiss", "flush"]).describe("Action to perform on cataloged references"),
|
|
38480
38483
|
identifier: z67.string().optional().describe("Reference identifier for approve/dismiss"),
|
|
@@ -38485,12 +38488,12 @@ function registerResearchCatalogReviewTool(server, deps) {
|
|
|
38485
38488
|
const secureHandler = createSecureHandler(createCatalogReviewHandler(deps), {
|
|
38486
38489
|
toolName: "research_catalog_review",
|
|
38487
38490
|
rateLimiter: deps.rateLimiter,
|
|
38488
|
-
logger:
|
|
38491
|
+
logger: logger53
|
|
38489
38492
|
});
|
|
38490
38493
|
const timeoutMs = getToolTimeout("research_catalog_review", deps.security);
|
|
38491
38494
|
const wrappedHandler = wrapToolWithTimeout("research_catalog_review", secureHandler, {
|
|
38492
38495
|
timeoutMs,
|
|
38493
|
-
logger:
|
|
38496
|
+
logger: logger53
|
|
38494
38497
|
});
|
|
38495
38498
|
const outputSchema = {
|
|
38496
38499
|
action: z67.string().optional(),
|
|
@@ -38508,7 +38511,7 @@ function registerResearchCatalogReviewTool(server, deps) {
|
|
|
38508
38511
|
},
|
|
38509
38512
|
toSdkCallback(wrappedHandler)
|
|
38510
38513
|
);
|
|
38511
|
-
|
|
38514
|
+
logger53.info("Registered research_catalog_review tool");
|
|
38512
38515
|
}
|
|
38513
38516
|
|
|
38514
38517
|
// src/mcp/tools/research-synthesize.ts
|
|
@@ -38525,8 +38528,8 @@ function createResearchSynthesizeHandler(deps) {
|
|
|
38525
38528
|
message: `Validation error: ${formatZodError(validationResult.error)}`
|
|
38526
38529
|
});
|
|
38527
38530
|
}
|
|
38528
|
-
const
|
|
38529
|
-
return withToolError("Synthesis failed",
|
|
38531
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_synthesize" });
|
|
38532
|
+
return withToolError("Synthesis failed", logger53, async () => {
|
|
38530
38533
|
const result = await synthesizeResearch(validationResult.data.topic);
|
|
38531
38534
|
if (!result.ok) {
|
|
38532
38535
|
return toolStructuredError({
|
|
@@ -38539,7 +38542,7 @@ function createResearchSynthesizeHandler(deps) {
|
|
|
38539
38542
|
};
|
|
38540
38543
|
}
|
|
38541
38544
|
function registerResearchSynthesizeTool(server, deps) {
|
|
38542
|
-
const
|
|
38545
|
+
const logger53 = deps.logger ?? createLogger({ tool: "research_synthesize" });
|
|
38543
38546
|
const toolSchema = {
|
|
38544
38547
|
topic: z68.string().optional().describe("Optional topic filter for single-cluster synthesis")
|
|
38545
38548
|
};
|
|
@@ -38547,12 +38550,12 @@ function registerResearchSynthesizeTool(server, deps) {
|
|
|
38547
38550
|
const secureHandler = createSecureHandler(createResearchSynthesizeHandler(deps), {
|
|
38548
38551
|
toolName: "research_synthesize",
|
|
38549
38552
|
rateLimiter: deps.rateLimiter,
|
|
38550
|
-
logger:
|
|
38553
|
+
logger: logger53
|
|
38551
38554
|
});
|
|
38552
38555
|
const timeoutMs = getToolTimeout("research_synthesize", deps.security);
|
|
38553
38556
|
const wrappedHandler = wrapToolWithTimeout("research_synthesize", secureHandler, {
|
|
38554
38557
|
timeoutMs,
|
|
38555
|
-
logger:
|
|
38558
|
+
logger: logger53
|
|
38556
38559
|
});
|
|
38557
38560
|
const outputSchema = {
|
|
38558
38561
|
clusters: z68.array(z68.unknown()).optional(),
|
|
@@ -38570,7 +38573,7 @@ function registerResearchSynthesizeTool(server, deps) {
|
|
|
38570
38573
|
},
|
|
38571
38574
|
toSdkCallback(wrappedHandler)
|
|
38572
38575
|
);
|
|
38573
|
-
|
|
38576
|
+
logger53.info("Registered research_synthesize tool");
|
|
38574
38577
|
}
|
|
38575
38578
|
|
|
38576
38579
|
// src/mcp/tools/issue-triage-tool.ts
|
|
@@ -38630,7 +38633,7 @@ function createIssueTriageHandler(_deps) {
|
|
|
38630
38633
|
};
|
|
38631
38634
|
}
|
|
38632
38635
|
function registerIssueTriageTool(server, deps) {
|
|
38633
|
-
const
|
|
38636
|
+
const logger53 = deps.logger ?? createLogger({ tool: "issue_triage" });
|
|
38634
38637
|
const toolSchema = {
|
|
38635
38638
|
issueUrl: z69.string().min(1).describe("GitHub issue URL (e.g., https://github.com/owner/repo/issues/123)"),
|
|
38636
38639
|
dryRun: z69.boolean().optional().default(true).describe("Read-only mode (default: true)")
|
|
@@ -38640,19 +38643,19 @@ function registerIssueTriageTool(server, deps) {
|
|
|
38640
38643
|
toolName: "issue_triage",
|
|
38641
38644
|
securityTier: "external",
|
|
38642
38645
|
rateLimiter: deps.rateLimiter,
|
|
38643
|
-
logger:
|
|
38646
|
+
logger: logger53
|
|
38644
38647
|
});
|
|
38645
38648
|
const timeoutMs = getToolTimeout("issue_triage", deps.security);
|
|
38646
38649
|
const wrappedHandler = wrapToolWithTimeout("issue_triage", secureHandler, {
|
|
38647
38650
|
timeoutMs,
|
|
38648
|
-
logger:
|
|
38651
|
+
logger: logger53
|
|
38649
38652
|
});
|
|
38650
38653
|
server.registerTool(
|
|
38651
38654
|
"issue_triage",
|
|
38652
38655
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("issue_triage") },
|
|
38653
38656
|
toSdkCallback(wrappedHandler)
|
|
38654
38657
|
);
|
|
38655
|
-
|
|
38658
|
+
logger53.info("Registered issue_triage tool with secure handler and timeout protection");
|
|
38656
38659
|
}
|
|
38657
38660
|
var triageLogger = createLogger({ tool: "issue-triage" });
|
|
38658
38661
|
function recordTriageSuccess(category, confidence, durationMs) {
|
|
@@ -38890,7 +38893,7 @@ function createEventCollector(events, enableAuditTrail) {
|
|
|
38890
38893
|
auditBridge?.(event);
|
|
38891
38894
|
};
|
|
38892
38895
|
}
|
|
38893
|
-
async function handleRunGraphWorkflow(input,
|
|
38896
|
+
async function handleRunGraphWorkflow(input, logger53) {
|
|
38894
38897
|
const startTime = getTimeProvider().now();
|
|
38895
38898
|
const resolved = resolveGraph(input.workflow, startTime);
|
|
38896
38899
|
if (!resolved.ok) return resolved.error;
|
|
@@ -38898,7 +38901,7 @@ async function handleRunGraphWorkflow(input, logger52) {
|
|
|
38898
38901
|
const checkpointStore = input.enableCheckpointing ? createCheckpointStore() : void 0;
|
|
38899
38902
|
const onEvent = createEventCollector(events, input.enableAuditTrail);
|
|
38900
38903
|
const executionId = `graph-${input.workflow}-${String(Date.now())}`;
|
|
38901
|
-
|
|
38904
|
+
logger53.info("Executing graph workflow", {
|
|
38902
38905
|
workflow: input.workflow,
|
|
38903
38906
|
executionId,
|
|
38904
38907
|
checkpointing: input.enableCheckpointing,
|
|
@@ -38941,7 +38944,7 @@ var GRAPH_WORKFLOW_SCHEMA = {
|
|
|
38941
38944
|
enableCheckpointing: z70.boolean().optional().describe("Enable checkpoint saving"),
|
|
38942
38945
|
enableAuditTrail: z70.boolean().optional().describe("Enable audit trail logging")
|
|
38943
38946
|
};
|
|
38944
|
-
function createGraphWorkflowHandler(
|
|
38947
|
+
function createGraphWorkflowHandler(logger53, notifier) {
|
|
38945
38948
|
return async (args, _ctx) => {
|
|
38946
38949
|
const parsed = RunGraphWorkflowInputSchema.safeParse(args);
|
|
38947
38950
|
if (!parsed.success) {
|
|
@@ -38957,7 +38960,7 @@ function createGraphWorkflowHandler(logger52, notifier) {
|
|
|
38957
38960
|
event: "graph_workflow_start",
|
|
38958
38961
|
workflow: parsed.data.workflow
|
|
38959
38962
|
});
|
|
38960
|
-
const result = await handleRunGraphWorkflow(parsed.data,
|
|
38963
|
+
const result = await handleRunGraphWorkflow(parsed.data, logger53);
|
|
38961
38964
|
const succeeded = result.status === "completed";
|
|
38962
38965
|
notifier.info("run_graph_workflow", {
|
|
38963
38966
|
event: succeeded ? "graph_workflow_complete" : "graph_workflow_failed",
|
|
@@ -38971,16 +38974,16 @@ function createGraphWorkflowHandler(logger52, notifier) {
|
|
|
38971
38974
|
};
|
|
38972
38975
|
}
|
|
38973
38976
|
function registerRunGraphWorkflowTool(server, deps) {
|
|
38974
|
-
const
|
|
38977
|
+
const logger53 = deps.logger ?? createLogger({ tool: "run_graph_workflow" });
|
|
38975
38978
|
const notifier = deps.notifier ?? createMcpNotifier(server);
|
|
38976
|
-
const handler3 = createGraphWorkflowHandler(
|
|
38979
|
+
const handler3 = createGraphWorkflowHandler(logger53, notifier);
|
|
38977
38980
|
const secureHandler = createSecureHandler(handler3, {
|
|
38978
38981
|
toolName: "run_graph_workflow",
|
|
38979
38982
|
rateLimiter: deps.rateLimiter,
|
|
38980
|
-
logger:
|
|
38983
|
+
logger: logger53
|
|
38981
38984
|
});
|
|
38982
38985
|
const timeoutMs = getToolTimeout("run_graph_workflow", deps.security);
|
|
38983
|
-
const wrapped = wrapToolWithTimeout("run_graph_workflow", secureHandler, { timeoutMs, logger:
|
|
38986
|
+
const wrapped = wrapToolWithTimeout("run_graph_workflow", secureHandler, { timeoutMs, logger: logger53 });
|
|
38984
38987
|
server.registerTool(
|
|
38985
38988
|
"run_graph_workflow",
|
|
38986
38989
|
{
|
|
@@ -38990,7 +38993,7 @@ function registerRunGraphWorkflowTool(server, deps) {
|
|
|
38990
38993
|
},
|
|
38991
38994
|
toSdkCallback(wrapped)
|
|
38992
38995
|
);
|
|
38993
|
-
|
|
38996
|
+
logger53.info("Registered run_graph_workflow tool");
|
|
38994
38997
|
}
|
|
38995
38998
|
function toEventSummary(event) {
|
|
38996
38999
|
const hasNodeId = "nodeId" in event;
|
|
@@ -39542,7 +39545,7 @@ var ExecuteSpecInputSchema = z71.object({
|
|
|
39542
39545
|
spec: z71.string().min(1).max(5e4).describe("Markdown specification to execute"),
|
|
39543
39546
|
dryRun: z71.boolean().optional().default(false).describe("Parse and decompose only")
|
|
39544
39547
|
});
|
|
39545
|
-
function createDryRunResponse(input,
|
|
39548
|
+
function createDryRunResponse(input, logger53) {
|
|
39546
39549
|
const parseResult2 = parseSpec(input.spec);
|
|
39547
39550
|
if (!parseResult2.ok) {
|
|
39548
39551
|
return toolStructuredError({
|
|
@@ -39557,14 +39560,14 @@ function createDryRunResponse(input, logger52) {
|
|
|
39557
39560
|
message: `Decompose error: ${dagResult.error.message}`
|
|
39558
39561
|
});
|
|
39559
39562
|
}
|
|
39560
|
-
|
|
39563
|
+
logger53.info("Dry run completed", {
|
|
39561
39564
|
title: parseResult2.value.title,
|
|
39562
39565
|
nodes: dagResult.value.nodes.length
|
|
39563
39566
|
});
|
|
39564
39567
|
const output2 = { mode: "dry_run", spec: parseResult2.value, dag: dagResult.value };
|
|
39565
39568
|
return toolSuccess(JSON.stringify(output2, null, 2));
|
|
39566
39569
|
}
|
|
39567
|
-
async function createFullResponse(input,
|
|
39570
|
+
async function createFullResponse(input, logger53) {
|
|
39568
39571
|
const startMs = Date.now();
|
|
39569
39572
|
const result = await executeSpec(input.spec);
|
|
39570
39573
|
const durationMs = Date.now() - startMs;
|
|
@@ -39577,7 +39580,7 @@ async function createFullResponse(input, logger52) {
|
|
|
39577
39580
|
}
|
|
39578
39581
|
const analysis = analyzeFailures(result.value);
|
|
39579
39582
|
const satisfaction = result.value.validation.satisfaction;
|
|
39580
|
-
|
|
39583
|
+
logger53.info("Spec execution completed", {
|
|
39581
39584
|
satisfaction,
|
|
39582
39585
|
passed: analysis.ok ? analysis.value.passed : false
|
|
39583
39586
|
});
|
|
@@ -39591,7 +39594,7 @@ async function createFullResponse(input, logger52) {
|
|
|
39591
39594
|
return toolSuccess(JSON.stringify(output2, null, 2));
|
|
39592
39595
|
}
|
|
39593
39596
|
function registerExecuteSpecTool(server, deps) {
|
|
39594
|
-
const
|
|
39597
|
+
const logger53 = deps.logger ?? createLogger({ tool: "execute_spec" });
|
|
39595
39598
|
const handler3 = async (args, _ctx) => {
|
|
39596
39599
|
const parsed = ExecuteSpecInputSchema.safeParse(args);
|
|
39597
39600
|
if (!parsed.success) {
|
|
@@ -39601,17 +39604,17 @@ function registerExecuteSpecTool(server, deps) {
|
|
|
39601
39604
|
});
|
|
39602
39605
|
}
|
|
39603
39606
|
if (parsed.data.dryRun) {
|
|
39604
|
-
return createDryRunResponse(parsed.data,
|
|
39607
|
+
return createDryRunResponse(parsed.data, logger53);
|
|
39605
39608
|
}
|
|
39606
|
-
return createFullResponse(parsed.data,
|
|
39609
|
+
return createFullResponse(parsed.data, logger53);
|
|
39607
39610
|
};
|
|
39608
39611
|
const secureHandler = createSecureHandler(handler3, {
|
|
39609
39612
|
toolName: "execute_spec",
|
|
39610
39613
|
rateLimiter: deps.rateLimiter,
|
|
39611
|
-
logger:
|
|
39614
|
+
logger: logger53
|
|
39612
39615
|
});
|
|
39613
39616
|
const timeoutMs = getToolTimeout("execute_spec", deps.security);
|
|
39614
|
-
const wrapped = wrapToolWithTimeout("execute_spec", secureHandler, { timeoutMs, logger:
|
|
39617
|
+
const wrapped = wrapToolWithTimeout("execute_spec", secureHandler, { timeoutMs, logger: logger53 });
|
|
39615
39618
|
const toolSchema = {
|
|
39616
39619
|
spec: z71.string().min(1).max(5e4).describe(
|
|
39617
39620
|
'Markdown specification to execute. Must contain "## Requirements" and "## Acceptance Criteria" sections.'
|
|
@@ -39624,7 +39627,7 @@ function registerExecuteSpecTool(server, deps) {
|
|
|
39624
39627
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("execute_spec") },
|
|
39625
39628
|
toSdkCallback(wrapped)
|
|
39626
39629
|
);
|
|
39627
|
-
|
|
39630
|
+
logger53.info("Registered execute_spec tool");
|
|
39628
39631
|
}
|
|
39629
39632
|
var specLogger = createLogger({ tool: "execute-spec" });
|
|
39630
39633
|
function recordSpecSuccess(satisfaction, durationMs) {
|
|
@@ -39686,29 +39689,29 @@ var MemoryQueryInputSchema = z72.object({
|
|
|
39686
39689
|
});
|
|
39687
39690
|
var reflectionCache;
|
|
39688
39691
|
var reflectionAdapter;
|
|
39689
|
-
function getReflectiveRetriever(
|
|
39692
|
+
function getReflectiveRetriever(logger53) {
|
|
39690
39693
|
const enabled = isReflectiveMemoryEnabled();
|
|
39691
39694
|
const shadow = isReflectiveShadowMode();
|
|
39692
39695
|
if (!enabled && !shadow) return void 0;
|
|
39693
39696
|
if (reflectionAdapter === void 0) {
|
|
39694
39697
|
try {
|
|
39695
|
-
const registry = getGlobalRegistry({ logger:
|
|
39698
|
+
const registry = getGlobalRegistry({ logger: logger53 });
|
|
39696
39699
|
reflectionAdapter = registry.getDefault();
|
|
39697
39700
|
} catch {
|
|
39698
|
-
|
|
39701
|
+
logger53.warn("No adapter for reflection, using keyword retrieval");
|
|
39699
39702
|
return void 0;
|
|
39700
39703
|
}
|
|
39701
39704
|
}
|
|
39702
39705
|
reflectionCache ??= new ReflectionCache();
|
|
39703
39706
|
return new ReflectiveRetriever({
|
|
39704
39707
|
adapter: reflectionAdapter,
|
|
39705
|
-
logger:
|
|
39708
|
+
logger: logger53,
|
|
39706
39709
|
shadowMode: shadow,
|
|
39707
39710
|
cache: reflectionCache
|
|
39708
39711
|
});
|
|
39709
39712
|
}
|
|
39710
|
-
async function resolveReflection(query,
|
|
39711
|
-
const retriever = getReflectiveRetriever(
|
|
39713
|
+
async function resolveReflection(query, logger53) {
|
|
39714
|
+
const retriever = getReflectiveRetriever(logger53);
|
|
39712
39715
|
if (retriever === void 0) return { effectiveQuery: query };
|
|
39713
39716
|
const reflection = await retriever.enhance(query);
|
|
39714
39717
|
const reflected = reflection.reflected;
|
|
@@ -39720,14 +39723,14 @@ async function resolveReflection(query, logger52) {
|
|
|
39720
39723
|
reflection
|
|
39721
39724
|
};
|
|
39722
39725
|
}
|
|
39723
|
-
async function executeMemoryQuery(input,
|
|
39726
|
+
async function executeMemoryQuery(input, logger53) {
|
|
39724
39727
|
const toolMemory = getToolMemory();
|
|
39725
39728
|
const { effectiveQuery, expandedQuery, reflection } = await resolveReflection(
|
|
39726
39729
|
input.query,
|
|
39727
|
-
|
|
39730
|
+
logger53
|
|
39728
39731
|
);
|
|
39729
39732
|
const results = await toolMemory.queryBySource(input.source, effectiveQuery, input.limit);
|
|
39730
|
-
|
|
39733
|
+
logger53.debug("Memory query executed", {
|
|
39731
39734
|
query: input.query,
|
|
39732
39735
|
effectiveQuery: effectiveQuery !== input.query ? effectiveQuery : void 0,
|
|
39733
39736
|
resultCount: results.length,
|
|
@@ -39757,7 +39760,7 @@ async function memoryQueryHandler(args, ctx) {
|
|
|
39757
39760
|
});
|
|
39758
39761
|
}
|
|
39759
39762
|
function registerMemoryQueryTool(server, deps) {
|
|
39760
|
-
const
|
|
39763
|
+
const logger53 = deps.logger ?? createLogger({ tool: "memory_query" });
|
|
39761
39764
|
const toolSchema = {
|
|
39762
39765
|
query: z72.string().min(1).max(500).describe("Search query to match against memory contents"),
|
|
39763
39766
|
limit: z72.number().int().min(1).max(50).optional().describe("Maximum results to return (default: 10, max: 50)"),
|
|
@@ -39767,10 +39770,10 @@ function registerMemoryQueryTool(server, deps) {
|
|
|
39767
39770
|
const secureHandler = createSecureHandler(memoryQueryHandler, {
|
|
39768
39771
|
toolName: "memory_query",
|
|
39769
39772
|
rateLimiter: deps.rateLimiter,
|
|
39770
|
-
logger:
|
|
39773
|
+
logger: logger53
|
|
39771
39774
|
});
|
|
39772
39775
|
const timeoutMs = getToolTimeout("memory_query", deps.security);
|
|
39773
|
-
const wrappedHandler = wrapToolWithTimeout("memory_query", secureHandler, { timeoutMs, logger:
|
|
39776
|
+
const wrappedHandler = wrapToolWithTimeout("memory_query", secureHandler, { timeoutMs, logger: logger53 });
|
|
39774
39777
|
const outputSchema = {
|
|
39775
39778
|
query: z72.string(),
|
|
39776
39779
|
expandedQuery: z72.string().optional(),
|
|
@@ -39788,7 +39791,7 @@ function registerMemoryQueryTool(server, deps) {
|
|
|
39788
39791
|
},
|
|
39789
39792
|
toSdkCallback(wrappedHandler)
|
|
39790
39793
|
);
|
|
39791
|
-
|
|
39794
|
+
logger53.info("Registered memory_query tool");
|
|
39792
39795
|
}
|
|
39793
39796
|
|
|
39794
39797
|
// src/mcp/tools/memory-stats.ts
|
|
@@ -39796,7 +39799,7 @@ import { z as z73 } from "zod";
|
|
|
39796
39799
|
var MemoryStatsInputSchema = z73.object({
|
|
39797
39800
|
includeDecay: z73.boolean().optional().default(true).describe("Include decay statistics (default: true)")
|
|
39798
39801
|
});
|
|
39799
|
-
async function collectMemoryStats(input,
|
|
39802
|
+
async function collectMemoryStats(input, logger53) {
|
|
39800
39803
|
const toolMemory = getToolMemory();
|
|
39801
39804
|
const sessionStats = {
|
|
39802
39805
|
learningsCount: 0,
|
|
@@ -39833,8 +39836,8 @@ async function collectMemoryStats(input, logger52) {
|
|
|
39833
39836
|
mobimem: toolMemory.isMobiMemAvailable(),
|
|
39834
39837
|
decay: toolMemory.isDecayManagerAvailable()
|
|
39835
39838
|
};
|
|
39836
|
-
const registry = await collectRegistryStats(
|
|
39837
|
-
|
|
39839
|
+
const registry = await collectRegistryStats(logger53);
|
|
39840
|
+
logger53.debug("Memory stats collected", { backends, registryDomains: registry.length });
|
|
39838
39841
|
return {
|
|
39839
39842
|
backends,
|
|
39840
39843
|
session: sessionStats,
|
|
@@ -39846,7 +39849,7 @@ async function collectMemoryStats(input, logger52) {
|
|
|
39846
39849
|
collectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
39847
39850
|
};
|
|
39848
39851
|
}
|
|
39849
|
-
async function collectRegistryStats(
|
|
39852
|
+
async function collectRegistryStats(logger53) {
|
|
39850
39853
|
const registry = getMemoryRegistry();
|
|
39851
39854
|
const rows = [];
|
|
39852
39855
|
for (const domain of registry.domains()) {
|
|
@@ -39857,7 +39860,7 @@ async function collectRegistryStats(logger52) {
|
|
|
39857
39860
|
rows.push({ domain, count: s.count, error: null });
|
|
39858
39861
|
} catch (error) {
|
|
39859
39862
|
const message = error instanceof Error ? error.message : String(error);
|
|
39860
|
-
|
|
39863
|
+
logger53.debug("Registry domain stats failed", { domain, error: message });
|
|
39861
39864
|
rows.push({ domain, count: null, error: message });
|
|
39862
39865
|
}
|
|
39863
39866
|
}
|
|
@@ -39877,7 +39880,7 @@ async function memoryStatsHandler(args, ctx) {
|
|
|
39877
39880
|
});
|
|
39878
39881
|
}
|
|
39879
39882
|
function registerMemoryStatsTool(server, deps) {
|
|
39880
|
-
const
|
|
39883
|
+
const logger53 = deps.logger ?? createLogger({ tool: "memory_stats" });
|
|
39881
39884
|
const toolSchema = {
|
|
39882
39885
|
includeDecay: z73.boolean().optional().describe("Include decay statistics (default: true)")
|
|
39883
39886
|
};
|
|
@@ -39885,10 +39888,10 @@ function registerMemoryStatsTool(server, deps) {
|
|
|
39885
39888
|
const secureHandler = createSecureHandler(memoryStatsHandler, {
|
|
39886
39889
|
toolName: "memory_stats",
|
|
39887
39890
|
rateLimiter: deps.rateLimiter,
|
|
39888
|
-
logger:
|
|
39891
|
+
logger: logger53
|
|
39889
39892
|
});
|
|
39890
39893
|
const timeoutMs = getToolTimeout("memory_stats", deps.security);
|
|
39891
|
-
const wrappedHandler = wrapToolWithTimeout("memory_stats", secureHandler, { timeoutMs, logger:
|
|
39894
|
+
const wrappedHandler = wrapToolWithTimeout("memory_stats", secureHandler, { timeoutMs, logger: logger53 });
|
|
39892
39895
|
const outputSchema = {
|
|
39893
39896
|
backends: z73.unknown(),
|
|
39894
39897
|
session: z73.unknown().optional(),
|
|
@@ -39909,7 +39912,7 @@ function registerMemoryStatsTool(server, deps) {
|
|
|
39909
39912
|
},
|
|
39910
39913
|
toSdkCallback(wrappedHandler)
|
|
39911
39914
|
);
|
|
39912
|
-
|
|
39915
|
+
logger53.info("Registered memory_stats tool");
|
|
39913
39916
|
}
|
|
39914
39917
|
|
|
39915
39918
|
// src/mcp/tools/memory-write.ts
|
|
@@ -40079,12 +40082,12 @@ function isDuplicateWrite(key, content) {
|
|
|
40079
40082
|
recentWriteKeys.set(cacheKey, (/* @__PURE__ */ new Date()).toISOString());
|
|
40080
40083
|
return false;
|
|
40081
40084
|
}
|
|
40082
|
-
async function executeMemoryWrite(input,
|
|
40085
|
+
async function executeMemoryWrite(input, logger53) {
|
|
40083
40086
|
if (isDuplicateWrite(input.key, input.content)) {
|
|
40084
|
-
|
|
40087
|
+
logger53.debug("Skipping duplicate memory write", { key: input.key, backend: input.backend });
|
|
40085
40088
|
return { success: true, backend: input.backend, key: input.key, deduplicated: true };
|
|
40086
40089
|
}
|
|
40087
|
-
|
|
40090
|
+
logger53.debug("Writing to memory", {
|
|
40088
40091
|
backend: input.backend,
|
|
40089
40092
|
key: input.key,
|
|
40090
40093
|
contentLength: input.content.length
|
|
@@ -40122,7 +40125,7 @@ async function memoryWriteHandler(args, ctx) {
|
|
|
40122
40125
|
});
|
|
40123
40126
|
}
|
|
40124
40127
|
function registerMemoryWriteTool(server, deps) {
|
|
40125
|
-
const
|
|
40128
|
+
const logger53 = deps.logger ?? createLogger({ tool: "memory_write" });
|
|
40126
40129
|
const toolSchema = {
|
|
40127
40130
|
key: z74.string().min(1).max(200).describe("Memory identifier or subject"),
|
|
40128
40131
|
content: z74.string().min(1).max(5e3).describe("Memory content to store"),
|
|
@@ -40136,11 +40139,11 @@ function registerMemoryWriteTool(server, deps) {
|
|
|
40136
40139
|
const secureHandler = createSecureHandler(memoryWriteHandler, {
|
|
40137
40140
|
toolName: "memory_write",
|
|
40138
40141
|
rateLimiter: deps.rateLimiter,
|
|
40139
|
-
logger:
|
|
40142
|
+
logger: logger53
|
|
40140
40143
|
});
|
|
40141
40144
|
const guardedHandler = withPrerequisite("memory_write", secureHandler);
|
|
40142
40145
|
const timeoutMs = getToolTimeout("memory_write", deps.security);
|
|
40143
|
-
const wrappedHandler = wrapToolWithTimeout("memory_write", guardedHandler, { timeoutMs, logger:
|
|
40146
|
+
const wrappedHandler = wrapToolWithTimeout("memory_write", guardedHandler, { timeoutMs, logger: logger53 });
|
|
40144
40147
|
const outputSchema = {
|
|
40145
40148
|
success: z74.boolean(),
|
|
40146
40149
|
backend: z74.string(),
|
|
@@ -40158,7 +40161,7 @@ function registerMemoryWriteTool(server, deps) {
|
|
|
40158
40161
|
},
|
|
40159
40162
|
toSdkCallback(wrappedHandler)
|
|
40160
40163
|
);
|
|
40161
|
-
|
|
40164
|
+
logger53.info("Registered memory_write tool");
|
|
40162
40165
|
}
|
|
40163
40166
|
|
|
40164
40167
|
// src/mcp/tools/weather-report-tool.ts
|
|
@@ -40208,7 +40211,7 @@ function weatherReportHandler(args, ctx) {
|
|
|
40208
40211
|
}
|
|
40209
40212
|
}
|
|
40210
40213
|
function registerWeatherReportTool(server, deps) {
|
|
40211
|
-
const
|
|
40214
|
+
const logger53 = deps.logger ?? createLogger({ tool: "weather_report" });
|
|
40212
40215
|
const toolSchema = {
|
|
40213
40216
|
cli: z75.enum(["claude", "gemini", "codex", "opencode"]).optional().describe("Filter by CLI"),
|
|
40214
40217
|
category: z75.enum([
|
|
@@ -40229,19 +40232,19 @@ function registerWeatherReportTool(server, deps) {
|
|
|
40229
40232
|
const secureHandler = createSecureHandler(weatherReportHandler, {
|
|
40230
40233
|
toolName: "weather_report",
|
|
40231
40234
|
rateLimiter: deps.rateLimiter,
|
|
40232
|
-
logger:
|
|
40235
|
+
logger: logger53
|
|
40233
40236
|
});
|
|
40234
40237
|
const timeoutMs = getToolTimeout("weather_report", deps.security);
|
|
40235
40238
|
const wrappedHandler = wrapToolWithTimeout("weather_report", secureHandler, {
|
|
40236
40239
|
timeoutMs,
|
|
40237
|
-
logger:
|
|
40240
|
+
logger: logger53
|
|
40238
40241
|
});
|
|
40239
40242
|
server.registerTool(
|
|
40240
40243
|
"weather_report",
|
|
40241
40244
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("weather_report") },
|
|
40242
40245
|
toSdkCallback(wrappedHandler)
|
|
40243
40246
|
);
|
|
40244
|
-
|
|
40247
|
+
logger53.info("Registered weather_report tool");
|
|
40245
40248
|
}
|
|
40246
40249
|
|
|
40247
40250
|
// src/mcp/tools/registry-import-types.ts
|
|
@@ -40364,7 +40367,7 @@ function registryImportHandler(args, ctx) {
|
|
|
40364
40367
|
}
|
|
40365
40368
|
}
|
|
40366
40369
|
function registerRegistryImportTool(server, deps) {
|
|
40367
|
-
const
|
|
40370
|
+
const logger53 = deps.logger ?? createLogger({ tool: "registry_import" });
|
|
40368
40371
|
const toolSchema = {
|
|
40369
40372
|
provider: z77.enum(["anthropic", "google", "openai"]).describe("Model provider (anthropic, google, openai)"),
|
|
40370
40373
|
modelId: z77.string().min(1).describe("Provider model identifier"),
|
|
@@ -40374,20 +40377,20 @@ function registerRegistryImportTool(server, deps) {
|
|
|
40374
40377
|
const secureHandler = createSecureHandler(registryImportHandler, {
|
|
40375
40378
|
toolName: "registry_import",
|
|
40376
40379
|
rateLimiter: deps.rateLimiter,
|
|
40377
|
-
logger:
|
|
40380
|
+
logger: logger53
|
|
40378
40381
|
});
|
|
40379
40382
|
const guardedHandler = withPrerequisite("registry_import", secureHandler);
|
|
40380
40383
|
const timeoutMs = getToolTimeout("registry_import", deps.security);
|
|
40381
40384
|
const wrappedHandler = wrapToolWithTimeout("registry_import", guardedHandler, {
|
|
40382
40385
|
timeoutMs,
|
|
40383
|
-
logger:
|
|
40386
|
+
logger: logger53
|
|
40384
40387
|
});
|
|
40385
40388
|
server.registerTool(
|
|
40386
40389
|
"registry_import",
|
|
40387
40390
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("registry_import") },
|
|
40388
40391
|
toSdkCallback(wrappedHandler)
|
|
40389
40392
|
);
|
|
40390
|
-
|
|
40393
|
+
logger53.info("Registered registry_import tool");
|
|
40391
40394
|
}
|
|
40392
40395
|
|
|
40393
40396
|
// src/mcp/tools/repo-analyze-types.ts
|
|
@@ -40420,7 +40423,7 @@ async function repoAnalyzeHandler(args, ctx) {
|
|
|
40420
40423
|
}
|
|
40421
40424
|
}
|
|
40422
40425
|
function registerRepoAnalyzeTool(server, deps) {
|
|
40423
|
-
const
|
|
40426
|
+
const logger53 = deps.logger ?? createLogger({ tool: "repo_analyze" });
|
|
40424
40427
|
const toolSchema = {
|
|
40425
40428
|
repo: z79.string().min(1).describe('GitHub repository in "owner/name" format or full URL'),
|
|
40426
40429
|
depth: z79.enum(["shallow", "deep"]).optional().describe("Analysis depth: shallow (tree + README) or deep")
|
|
@@ -40429,19 +40432,19 @@ function registerRepoAnalyzeTool(server, deps) {
|
|
|
40429
40432
|
const secureHandler = createSecureHandler(repoAnalyzeHandler, {
|
|
40430
40433
|
toolName: "repo_analyze",
|
|
40431
40434
|
rateLimiter: deps.rateLimiter,
|
|
40432
|
-
logger:
|
|
40435
|
+
logger: logger53
|
|
40433
40436
|
});
|
|
40434
40437
|
const timeoutMs = getToolTimeout("repo_analyze", deps.security);
|
|
40435
40438
|
const wrappedHandler = wrapToolWithTimeout("repo_analyze", secureHandler, {
|
|
40436
40439
|
timeoutMs,
|
|
40437
|
-
logger:
|
|
40440
|
+
logger: logger53
|
|
40438
40441
|
});
|
|
40439
40442
|
server.registerTool(
|
|
40440
40443
|
"repo_analyze",
|
|
40441
40444
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("repo_analyze") },
|
|
40442
40445
|
toSdkCallback(wrappedHandler)
|
|
40443
40446
|
);
|
|
40444
|
-
|
|
40447
|
+
logger53.info("Registered repo_analyze tool");
|
|
40445
40448
|
}
|
|
40446
40449
|
|
|
40447
40450
|
// src/mcp/tools/repo-security-plan-types.ts
|
|
@@ -40473,7 +40476,7 @@ async function handler(args, ctx) {
|
|
|
40473
40476
|
}
|
|
40474
40477
|
}
|
|
40475
40478
|
function registerRepoSecurityPlanTool(server, deps) {
|
|
40476
|
-
const
|
|
40479
|
+
const logger53 = deps.logger ?? createLogger({ tool: "repo_security_plan" });
|
|
40477
40480
|
const toolSchema = {
|
|
40478
40481
|
repo: z81.string().min(1).describe('GitHub repository in "owner/name" format or full URL'),
|
|
40479
40482
|
categories: z81.array(z81.string().max(50)).max(10).optional().describe('Filter to specific categories (e.g., ["sast", "sca", "secrets"])'),
|
|
@@ -40483,19 +40486,19 @@ function registerRepoSecurityPlanTool(server, deps) {
|
|
|
40483
40486
|
const secureHandler = createSecureHandler(handler, {
|
|
40484
40487
|
toolName: "repo_security_plan",
|
|
40485
40488
|
rateLimiter: deps.rateLimiter,
|
|
40486
|
-
logger:
|
|
40489
|
+
logger: logger53
|
|
40487
40490
|
});
|
|
40488
40491
|
const timeoutMs = getToolTimeout("repo_security_plan", deps.security);
|
|
40489
40492
|
const wrappedHandler = wrapToolWithTimeout("repo_security_plan", secureHandler, {
|
|
40490
40493
|
timeoutMs,
|
|
40491
|
-
logger:
|
|
40494
|
+
logger: logger53
|
|
40492
40495
|
});
|
|
40493
40496
|
server.registerTool(
|
|
40494
40497
|
"repo_security_plan",
|
|
40495
40498
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("repo_security_plan") },
|
|
40496
40499
|
toSdkCallback(wrappedHandler)
|
|
40497
40500
|
);
|
|
40498
|
-
|
|
40501
|
+
logger53.info("Registered repo_security_plan tool");
|
|
40499
40502
|
}
|
|
40500
40503
|
|
|
40501
40504
|
// src/mcp/tools/search-codebase-tool.ts
|
|
@@ -40611,7 +40614,7 @@ ${output2}`);
|
|
|
40611
40614
|
}
|
|
40612
40615
|
}
|
|
40613
40616
|
function registerSearchCodebaseTool(server, deps) {
|
|
40614
|
-
const
|
|
40617
|
+
const logger53 = deps.logger ?? createLogger({ tool: "search_codebase" });
|
|
40615
40618
|
const toolSchema = {
|
|
40616
40619
|
query: z82.string().min(1).max(200).describe("Search query or file path"),
|
|
40617
40620
|
directory: z82.string().max(500).optional().describe("Directory to index"),
|
|
@@ -40622,16 +40625,16 @@ function registerSearchCodebaseTool(server, deps) {
|
|
|
40622
40625
|
const secureHandler = createSecureHandler(searchCodebaseHandler, {
|
|
40623
40626
|
toolName: "search_codebase",
|
|
40624
40627
|
rateLimiter: deps.rateLimiter,
|
|
40625
|
-
logger:
|
|
40628
|
+
logger: logger53
|
|
40626
40629
|
});
|
|
40627
40630
|
const timeoutMs = getToolTimeout("search_codebase", deps.security);
|
|
40628
|
-
const wrapped = wrapToolWithTimeout("search_codebase", secureHandler, { timeoutMs, logger:
|
|
40631
|
+
const wrapped = wrapToolWithTimeout("search_codebase", secureHandler, { timeoutMs, logger: logger53 });
|
|
40629
40632
|
server.registerTool(
|
|
40630
40633
|
"search_codebase",
|
|
40631
40634
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("search_codebase") },
|
|
40632
40635
|
toSdkCallback(wrapped)
|
|
40633
40636
|
);
|
|
40634
|
-
|
|
40637
|
+
logger53.info("Registered search_codebase tool");
|
|
40635
40638
|
}
|
|
40636
40639
|
|
|
40637
40640
|
// src/mcp/tools/extract-symbols-tool.ts
|
|
@@ -40698,7 +40701,7 @@ async function extractSymbolsHandler(args, ctx) {
|
|
|
40698
40701
|
}
|
|
40699
40702
|
}
|
|
40700
40703
|
function registerExtractSymbolsTool(server, deps) {
|
|
40701
|
-
const
|
|
40704
|
+
const logger53 = deps.logger ?? createLogger({ tool: "extract_symbols" });
|
|
40702
40705
|
const toolSchema = {
|
|
40703
40706
|
filePath: z83.string().min(1).max(500).describe("Path to TypeScript/JavaScript file"),
|
|
40704
40707
|
mode: z83.enum(["index", "full"]).optional().describe("index (default): names+lines. full: includes source text")
|
|
@@ -40707,19 +40710,19 @@ function registerExtractSymbolsTool(server, deps) {
|
|
|
40707
40710
|
const secureHandler = createSecureHandler(extractSymbolsHandler, {
|
|
40708
40711
|
toolName: "extract_symbols",
|
|
40709
40712
|
rateLimiter: deps.rateLimiter,
|
|
40710
|
-
logger:
|
|
40713
|
+
logger: logger53
|
|
40711
40714
|
});
|
|
40712
40715
|
const timeoutMs = getToolTimeout("extract_symbols", deps.security);
|
|
40713
40716
|
const wrapped = wrapToolWithTimeout("extract_symbols", secureHandler, {
|
|
40714
40717
|
timeoutMs,
|
|
40715
|
-
logger:
|
|
40718
|
+
logger: logger53
|
|
40716
40719
|
});
|
|
40717
40720
|
server.registerTool(
|
|
40718
40721
|
"extract_symbols",
|
|
40719
40722
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("extract_symbols") },
|
|
40720
40723
|
toSdkCallback(wrapped)
|
|
40721
40724
|
);
|
|
40722
|
-
|
|
40725
|
+
logger53.info("Registered extract_symbols tool");
|
|
40723
40726
|
}
|
|
40724
40727
|
|
|
40725
40728
|
// src/mcp/tools/query-trace-tool.ts
|
|
@@ -40832,7 +40835,7 @@ function queryTraceHandler(args, ctx) {
|
|
|
40832
40835
|
});
|
|
40833
40836
|
}
|
|
40834
40837
|
function registerQueryTraceTool(server, deps) {
|
|
40835
|
-
const
|
|
40838
|
+
const logger53 = deps.logger ?? createLogger({ tool: "query_trace" });
|
|
40836
40839
|
const toolSchema = {
|
|
40837
40840
|
runId: z84.string().min(1).max(128).regex(/^[a-zA-Z0-9_-]+$/, "runId must be alphanumeric, hyphens, or underscores").describe("Run ID to query traces for"),
|
|
40838
40841
|
eventType: z84.string().max(100).regex(/^[a-zA-Z0-9._-]+$/).optional().describe("Filter by event type (e.g., model.called)"),
|
|
@@ -40842,16 +40845,16 @@ function registerQueryTraceTool(server, deps) {
|
|
|
40842
40845
|
const secureHandler = createSecureHandler(queryTraceHandler, {
|
|
40843
40846
|
toolName: "query_trace",
|
|
40844
40847
|
rateLimiter: deps.rateLimiter,
|
|
40845
|
-
logger:
|
|
40848
|
+
logger: logger53
|
|
40846
40849
|
});
|
|
40847
40850
|
const timeoutMs = getToolTimeout("query_trace", deps.security);
|
|
40848
|
-
const wrappedHandler = wrapToolWithTimeout("query_trace", secureHandler, { timeoutMs, logger:
|
|
40851
|
+
const wrappedHandler = wrapToolWithTimeout("query_trace", secureHandler, { timeoutMs, logger: logger53 });
|
|
40849
40852
|
server.registerTool(
|
|
40850
40853
|
"query_trace",
|
|
40851
40854
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("query_trace") },
|
|
40852
40855
|
toSdkCallback(wrappedHandler)
|
|
40853
40856
|
);
|
|
40854
|
-
|
|
40857
|
+
logger53.info("Registered query_trace tool");
|
|
40855
40858
|
}
|
|
40856
40859
|
|
|
40857
40860
|
// src/audit/audit-types.ts
|
|
@@ -41155,7 +41158,7 @@ var FileAuditStorage = class _FileAuditStorage {
|
|
|
41155
41158
|
* @param logger - Optional logger instance
|
|
41156
41159
|
* @returns Result with FileAuditStorage or SecurityError
|
|
41157
41160
|
*/
|
|
41158
|
-
static create(config,
|
|
41161
|
+
static create(config, logger53) {
|
|
41159
41162
|
const validation = config.allowedRoot !== void 0 ? validateLogDir(config.logDir, config.allowedRoot) : validateLogDirBasic(config.logDir);
|
|
41160
41163
|
if (!validation.ok) {
|
|
41161
41164
|
return { ok: false, error: validation.error };
|
|
@@ -41164,7 +41167,7 @@ var FileAuditStorage = class _FileAuditStorage {
|
|
|
41164
41167
|
...config,
|
|
41165
41168
|
logDir: validation.value
|
|
41166
41169
|
};
|
|
41167
|
-
return { ok: true, value: new _FileAuditStorage(validatedConfig,
|
|
41170
|
+
return { ok: true, value: new _FileAuditStorage(validatedConfig, logger53, true) };
|
|
41168
41171
|
}
|
|
41169
41172
|
/**
|
|
41170
41173
|
* Constructor for FileAuditStorage.
|
|
@@ -41177,8 +41180,8 @@ var FileAuditStorage = class _FileAuditStorage {
|
|
|
41177
41180
|
* @param skipValidation - Internal flag, set by create() after validation
|
|
41178
41181
|
* @throws SecurityError if path validation fails and skipValidation is false
|
|
41179
41182
|
*/
|
|
41180
|
-
constructor(config,
|
|
41181
|
-
this.logger =
|
|
41183
|
+
constructor(config, logger53, skipValidation = false) {
|
|
41184
|
+
this.logger = logger53 ?? createLogger({ component: "FileAuditStorage" });
|
|
41182
41185
|
if (!skipValidation) {
|
|
41183
41186
|
const validation = validateLogDirBasic(config.logDir);
|
|
41184
41187
|
if (!validation.ok) {
|
|
@@ -41407,13 +41410,13 @@ var AuditLogger = class {
|
|
|
41407
41410
|
closed = false;
|
|
41408
41411
|
inFlightFlush = null;
|
|
41409
41412
|
droppedEventCount = 0;
|
|
41410
|
-
constructor(config, storage,
|
|
41413
|
+
constructor(config, storage, logger53) {
|
|
41411
41414
|
const validated = AuditLogConfigSchema.safeParse(config);
|
|
41412
41415
|
if (!validated.success) {
|
|
41413
41416
|
const issues = validated.error.issues.map((i) => i.path.join(".") + ": " + i.message).join("; ");
|
|
41414
41417
|
throw new AuditError("Invalid AuditLogConfig: " + issues);
|
|
41415
41418
|
}
|
|
41416
|
-
this.logger =
|
|
41419
|
+
this.logger = logger53 ?? createLogger({ component: "AuditLogger" });
|
|
41417
41420
|
this.enableHashChain = validated.data.enableHashChain;
|
|
41418
41421
|
this.minSeverity = validated.data.minSeverity;
|
|
41419
41422
|
this.categories = validated.data.categories;
|
|
@@ -41614,8 +41617,8 @@ var AuditLogger = class {
|
|
|
41614
41617
|
this.logger.info("AuditLogger closed");
|
|
41615
41618
|
}
|
|
41616
41619
|
};
|
|
41617
|
-
function createAuditLogger(config, storage,
|
|
41618
|
-
return new AuditLogger(config, storage,
|
|
41620
|
+
function createAuditLogger(config, storage, logger53) {
|
|
41621
|
+
return new AuditLogger(config, storage, logger53);
|
|
41619
41622
|
}
|
|
41620
41623
|
|
|
41621
41624
|
// src/pipeline/stage-types.ts
|
|
@@ -41635,8 +41638,7 @@ var PIPELINE_STATE_KEYS = {
|
|
|
41635
41638
|
DELIVERABLES: "deliverables",
|
|
41636
41639
|
PARSED_SPEC: "parsedSpec",
|
|
41637
41640
|
SCAFFOLD_OUTPUT: "scaffoldOutput",
|
|
41638
|
-
COMPLETED: "completed"
|
|
41639
|
-
SHARED_MEMORY: "__sharedMemory__"
|
|
41641
|
+
COMPLETED: "completed"
|
|
41640
41642
|
};
|
|
41641
41643
|
|
|
41642
41644
|
// src/pipeline/pipeline-graph.ts
|
|
@@ -41693,15 +41695,11 @@ function registerNodes(builder, template, stages) {
|
|
|
41693
41695
|
}
|
|
41694
41696
|
function createNodeHandler(stage, template) {
|
|
41695
41697
|
return async (state) => {
|
|
41696
|
-
const existingStore = state[PIPELINE_STATE_KEYS.SHARED_MEMORY];
|
|
41697
|
-
const { SharedMemoryStore: SharedMemoryStore2 } = await import("./shared-memory-CM6T2MYE.js");
|
|
41698
|
-
const sharedMemory = existingStore instanceof SharedMemoryStore2 ? existingStore : new SharedMemoryStore2();
|
|
41699
41698
|
const context = {
|
|
41700
41699
|
executionId: `${template.id}-${stage.id}`,
|
|
41701
41700
|
task: typeof state[PIPELINE_STATE_KEYS.TASK] === "string" ? state[PIPELINE_STATE_KEYS.TASK] : "",
|
|
41702
41701
|
templateId: template.id,
|
|
41703
|
-
state
|
|
41704
|
-
sharedMemory
|
|
41702
|
+
state
|
|
41705
41703
|
};
|
|
41706
41704
|
const output2 = await stage.execute(context);
|
|
41707
41705
|
return { [output2.stateKey]: output2.value };
|
|
@@ -41763,10 +41761,9 @@ async function executeAndReport(task, template, graph, options, startTime) {
|
|
|
41763
41761
|
dryRun: options?.dryRun === true
|
|
41764
41762
|
});
|
|
41765
41763
|
emitPipelineStageEvent(template.id, "pipeline", "started");
|
|
41766
|
-
const sharedMemory = new SharedMemoryStore();
|
|
41767
41764
|
const result = await executeGraph(
|
|
41768
41765
|
graph,
|
|
41769
|
-
{ [PIPELINE_STATE_KEYS.TASK]: task
|
|
41766
|
+
{ [PIPELINE_STATE_KEYS.TASK]: task },
|
|
41770
41767
|
{
|
|
41771
41768
|
maxSteps: options?.maxSteps ?? DEFAULT_MAX_STEPS2
|
|
41772
41769
|
}
|
|
@@ -42003,7 +42000,7 @@ async function tryIssueTriage(task) {
|
|
|
42003
42000
|
try {
|
|
42004
42001
|
const issueMatch = task.match(/github\.com\/([^/]+\/[^/]+)\/issues\/(\d+)/);
|
|
42005
42002
|
if (issueMatch === null) return null;
|
|
42006
|
-
const { createIssueTriage } = await import("./issue-triage-
|
|
42003
|
+
const { createIssueTriage } = await import("./issue-triage-Y77JI7WF.js");
|
|
42007
42004
|
const triage = createIssueTriage();
|
|
42008
42005
|
const owner = issueMatch[1] ?? "";
|
|
42009
42006
|
const num = issueMatch[2] ?? "";
|
|
@@ -42031,7 +42028,7 @@ var VALID_TEMPLATES = /* @__PURE__ */ new Set([
|
|
|
42031
42028
|
]);
|
|
42032
42029
|
async function classifyWithLLM(task) {
|
|
42033
42030
|
try {
|
|
42034
|
-
const { executeExpert: executeExpert2 } = await import("./expert-bridge-
|
|
42031
|
+
const { executeExpert: executeExpert2 } = await import("./expert-bridge-FHPWDFJX.js");
|
|
42035
42032
|
const prompt = [
|
|
42036
42033
|
"Classify this task into exactly one pipeline template.",
|
|
42037
42034
|
"Templates: dev (implementation/bug fix/refactor), research (investigate/evaluate/compare),",
|
|
@@ -42813,7 +42810,7 @@ var memoryInitPromise = null;
|
|
|
42813
42810
|
async function initPipelineMemory() {
|
|
42814
42811
|
if (cachedMemory !== null) return cachedMemory;
|
|
42815
42812
|
try {
|
|
42816
|
-
const { createSessionMemory: createSessionMemory2 } = await import("./session-memory-
|
|
42813
|
+
const { createSessionMemory: createSessionMemory2 } = await import("./session-memory-WARRGYY7.js");
|
|
42817
42814
|
const { getLearningDir } = await import("./learning-persistence-NX2KHL5T.js");
|
|
42818
42815
|
const mem = createSessionMemory2(getLearningDir());
|
|
42819
42816
|
mem.startSession(`pipeline-${String(getTimeProvider().now())}`);
|
|
@@ -42870,7 +42867,7 @@ function recordRoutingExperience(category, success, durationMs) {
|
|
|
42870
42867
|
callRecord(routingMemoryCache);
|
|
42871
42868
|
return;
|
|
42872
42869
|
}
|
|
42873
|
-
routingMemoryInitPromise ??= import("./routing-memory-
|
|
42870
|
+
routingMemoryInitPromise ??= import("./routing-memory-QRIJPRVD.js").then(({ createRoutingMemory }) => {
|
|
42874
42871
|
routingMemoryCache ??= createRoutingMemory();
|
|
42875
42872
|
return routingMemoryCache;
|
|
42876
42873
|
}).catch((error) => {
|
|
@@ -42904,7 +42901,7 @@ ${text}` : "";
|
|
|
42904
42901
|
}
|
|
42905
42902
|
async function getWeatherContext() {
|
|
42906
42903
|
try {
|
|
42907
|
-
const { generateWeatherReport: generateWeatherReport2 } = await import("./weather-report-
|
|
42904
|
+
const { generateWeatherReport: generateWeatherReport2 } = await import("./weather-report-RACZWJQL.js");
|
|
42908
42905
|
const report = generateWeatherReport2({ includeAdaptive: true });
|
|
42909
42906
|
const mappings = "recommendedMappings" in report ? report.recommendedMappings : [];
|
|
42910
42907
|
if (!Array.isArray(mappings) || mappings.length === 0) return "";
|
|
@@ -42922,7 +42919,7 @@ ${lines}
|
|
|
42922
42919
|
}
|
|
42923
42920
|
async function getMemoryContext(task) {
|
|
42924
42921
|
try {
|
|
42925
|
-
const { createSessionMemory: createSessionMemory2 } = await import("./session-memory-
|
|
42922
|
+
const { createSessionMemory: createSessionMemory2 } = await import("./session-memory-WARRGYY7.js");
|
|
42926
42923
|
const { getLearningDir } = await import("./learning-persistence-NX2KHL5T.js");
|
|
42927
42924
|
const memory = createSessionMemory2(getLearningDir(), { maxLearningsInContext: 10 });
|
|
42928
42925
|
const learnings = memory.searchLearnings(task.slice(0, 200));
|
|
@@ -43028,7 +43025,7 @@ ${contextBlock}`;
|
|
|
43028
43025
|
const strategy = config.votingStrategy ?? "higher_order";
|
|
43029
43026
|
await postProgress(config, "Vote", `Running consensus with ${strategy} strategy...`);
|
|
43030
43027
|
try {
|
|
43031
|
-
const { executeVoting } = await import("./consensus-vote-
|
|
43028
|
+
const { executeVoting } = await import("./consensus-vote-KZ6UURUI.js");
|
|
43032
43029
|
const votingResult = await executeVoting(
|
|
43033
43030
|
{
|
|
43034
43031
|
proposal: plan.slice(0, 4e3),
|
|
@@ -43547,7 +43544,7 @@ async function runPlanningPhase(task, stages, sid, prior) {
|
|
|
43547
43544
|
)
|
|
43548
43545
|
);
|
|
43549
43546
|
if (sid !== void 0) saveStageCheckpoint(sid, "research", { type: "research", text: research });
|
|
43550
|
-
const planResult = await runPlanOrResume(prior, task, research, stages);
|
|
43547
|
+
const planResult = await runPlanOrResume(prior, task, research, stages, sid);
|
|
43551
43548
|
if (sid !== void 0) {
|
|
43552
43549
|
saveStageCheckpoint(sid, "plan", {
|
|
43553
43550
|
type: "plan",
|
|
@@ -43607,9 +43604,9 @@ async function runOrResume(prior, stage, run) {
|
|
|
43607
43604
|
}
|
|
43608
43605
|
return run();
|
|
43609
43606
|
}
|
|
43610
|
-
async function runPlanOrResume(prior, task, research, stages) {
|
|
43607
|
+
async function runPlanOrResume(prior, task, research, stages, sessionId) {
|
|
43611
43608
|
if (prior?.plan !== void 0) {
|
|
43612
|
-
logger41.info("Resuming from checkpoint", { stage: "plan" });
|
|
43609
|
+
logger41.info("Resuming from checkpoint", { stage: "plan", sessionId });
|
|
43613
43610
|
return {
|
|
43614
43611
|
plan: prior.plan,
|
|
43615
43612
|
iterations: prior.voteIterations ?? 0,
|
|
@@ -43618,7 +43615,7 @@ async function runPlanOrResume(prior, task, research, stages) {
|
|
|
43618
43615
|
caveats: prior.voteCaveats ?? []
|
|
43619
43616
|
};
|
|
43620
43617
|
}
|
|
43621
|
-
return planVoteLoop(task, research, stages);
|
|
43618
|
+
return planVoteLoop(task, research, stages, sessionId);
|
|
43622
43619
|
}
|
|
43623
43620
|
async function runOrResumeDecompose(prior, plan, stages, meta) {
|
|
43624
43621
|
if (prior?.tasks !== void 0) {
|
|
@@ -43645,7 +43642,7 @@ function extractConditionalMeta(vote) {
|
|
|
43645
43642
|
}
|
|
43646
43643
|
return { conditional: false, conditions: [], caveats: [] };
|
|
43647
43644
|
}
|
|
43648
|
-
async function planVoteLoop(task, research, stages) {
|
|
43645
|
+
async function planVoteLoop(task, research, stages, sessionId) {
|
|
43649
43646
|
let feedback;
|
|
43650
43647
|
let plan = "";
|
|
43651
43648
|
for (let i = 1; i <= MAX_VOTE_ITERATIONS; i++) {
|
|
@@ -43665,13 +43662,22 @@ async function planVoteLoop(task, research, stages) {
|
|
|
43665
43662
|
);
|
|
43666
43663
|
if (isApproved(vote)) {
|
|
43667
43664
|
const meta = extractConditionalMeta(vote);
|
|
43668
|
-
logger41.info("Plan approved", {
|
|
43665
|
+
logger41.info("Plan approved", {
|
|
43666
|
+
iteration: i,
|
|
43667
|
+
approval: vote.approvalPercentage,
|
|
43668
|
+
sessionId,
|
|
43669
|
+
...meta
|
|
43670
|
+
});
|
|
43669
43671
|
return { plan, iterations: i, ...meta };
|
|
43670
43672
|
}
|
|
43671
43673
|
feedback = getVoteFeedback(vote);
|
|
43672
|
-
logger41.warn("Plan rejected, iterating", {
|
|
43674
|
+
logger41.warn("Plan rejected, iterating", {
|
|
43675
|
+
iteration: i,
|
|
43676
|
+
feedback: feedback.slice(0, 200),
|
|
43677
|
+
sessionId
|
|
43678
|
+
});
|
|
43673
43679
|
}
|
|
43674
|
-
logger41.warn("Max vote iterations reached, proceeding with last plan");
|
|
43680
|
+
logger41.warn("Max vote iterations reached, proceeding with last plan", { sessionId });
|
|
43675
43681
|
return { plan, iterations: MAX_VOTE_ITERATIONS, conditional: false, conditions: [], caveats: [] };
|
|
43676
43682
|
}
|
|
43677
43683
|
async function implementSingleTask(task, stages) {
|
|
@@ -43793,7 +43799,6 @@ function createResearchStageWrapper(stages) {
|
|
|
43793
43799
|
${codeContext}`;
|
|
43794
43800
|
}
|
|
43795
43801
|
const result = await stages.research(enrichedTask);
|
|
43796
|
-
ctx.sharedMemory.write("research", "discovery", result);
|
|
43797
43802
|
return output(PIPELINE_STATE_KEYS.RESEARCH, result, getTimeProvider().now() - start, true);
|
|
43798
43803
|
} catch (e) {
|
|
43799
43804
|
return failOutput(PIPELINE_STATE_KEYS.RESEARCH, String(e), getTimeProvider().now() - start);
|
|
@@ -43816,7 +43821,6 @@ function createPlanStageWrapper(stages) {
|
|
|
43816
43821
|
## Prior Art (Research Registry)
|
|
43817
43822
|
${priorArt}` : research;
|
|
43818
43823
|
const result = await stages.plan(ctx.task, enrichedResearch, feedback);
|
|
43819
|
-
ctx.sharedMemory.write("plan", "decision", result);
|
|
43820
43824
|
return output(PIPELINE_STATE_KEYS.PLAN, result, getTimeProvider().now() - start, true);
|
|
43821
43825
|
} catch (e) {
|
|
43822
43826
|
return failOutput(PIPELINE_STATE_KEYS.PLAN, String(e), getTimeProvider().now() - start);
|
|
@@ -43871,12 +43875,7 @@ function createImplementStageWrapper(stages) {
|
|
|
43871
43875
|
const start = getTimeProvider().now();
|
|
43872
43876
|
const tasks = Array.isArray(ctx.state[PIPELINE_STATE_KEYS.TASKS]) ? ctx.state[PIPELINE_STATE_KEYS.TASKS] : [];
|
|
43873
43877
|
try {
|
|
43874
|
-
const symbolContext = await extractSymbolsForTask(ctx.task);
|
|
43875
|
-
if (symbolContext !== null && symbolContext !== "") {
|
|
43876
|
-
ctx.sharedMemory.write("implement", "context", symbolContext);
|
|
43877
|
-
}
|
|
43878
43878
|
const results = await Promise.all(tasks.map((t) => stages.implement(t)));
|
|
43879
|
-
classifyImplementationTrust(results, ctx);
|
|
43880
43879
|
return output(PIPELINE_STATE_KEYS.IMPLEMENTATIONS, results, getTimeProvider().now() - start, true);
|
|
43881
43880
|
} catch (e) {
|
|
43882
43881
|
return failOutput(PIPELINE_STATE_KEYS.IMPLEMENTATIONS, String(e), getTimeProvider().now() - start);
|
|
@@ -43938,7 +43937,7 @@ function createScaffoldStageWrapper() {
|
|
|
43938
43937
|
}
|
|
43939
43938
|
async function searchCodebaseForTask(task) {
|
|
43940
43939
|
try {
|
|
43941
|
-
const { CodebaseIndex: CodebaseIndex2 } = await import("./codebase-search-
|
|
43940
|
+
const { CodebaseIndex: CodebaseIndex2 } = await import("./codebase-search-ZFJUVMVR.js");
|
|
43942
43941
|
const index = new CodebaseIndex2(process.cwd());
|
|
43943
43942
|
const terms = task.toLowerCase().split(/\s+/).filter((w) => w.length > 4).slice(0, 3);
|
|
43944
43943
|
if (terms.length === 0) return null;
|
|
@@ -43951,32 +43950,9 @@ async function searchCodebaseForTask(task) {
|
|
|
43951
43950
|
return null;
|
|
43952
43951
|
}
|
|
43953
43952
|
}
|
|
43954
|
-
async function extractSymbolsForTask(task) {
|
|
43955
|
-
try {
|
|
43956
|
-
const fileRefs = task.match(/(?:src|lib|packages)\/[^\s,)]+\.ts/g);
|
|
43957
|
-
if (fileRefs === null || fileRefs.length === 0) return null;
|
|
43958
|
-
const { extractSymbols: extractSymbols2 } = await import("./symbol-extractor-WYXPJH65.js");
|
|
43959
|
-
const path14 = await import("path");
|
|
43960
|
-
const summaries = [];
|
|
43961
|
-
for (const ref of fileRefs.slice(0, 3)) {
|
|
43962
|
-
try {
|
|
43963
|
-
const resolved = path14.resolve(ref);
|
|
43964
|
-
const result = await extractSymbols2(resolved);
|
|
43965
|
-
const exported = result.symbols.filter((s) => s.exported);
|
|
43966
|
-
if (exported.length > 0) {
|
|
43967
|
-
summaries.push(`${ref}: ${exported.map((s) => `${s.kind} ${s.name}`).join(", ")}`);
|
|
43968
|
-
}
|
|
43969
|
-
} catch {
|
|
43970
|
-
}
|
|
43971
|
-
}
|
|
43972
|
-
return summaries.length > 0 ? summaries.join("\n") : null;
|
|
43973
|
-
} catch {
|
|
43974
|
-
return null;
|
|
43975
|
-
}
|
|
43976
|
-
}
|
|
43977
43953
|
async function queryResearchRegistry(task) {
|
|
43978
43954
|
try {
|
|
43979
|
-
const { synthesizeResearch: synthesizeResearch2 } = await import("./research-helpers-synthesize-
|
|
43955
|
+
const { synthesizeResearch: synthesizeResearch2 } = await import("./research-helpers-synthesize-PVP6JRZV.js");
|
|
43980
43956
|
const topic = task.split(/[.!?\n]/).filter((s) => s.trim().length > 10)[0]?.trim();
|
|
43981
43957
|
if (topic === void 0) return null;
|
|
43982
43958
|
const result = await synthesizeResearch2(topic.slice(0, 50));
|
|
@@ -43988,19 +43964,6 @@ async function queryResearchRegistry(task) {
|
|
|
43988
43964
|
return null;
|
|
43989
43965
|
}
|
|
43990
43966
|
}
|
|
43991
|
-
function classifyImplementationTrust(results, ctx) {
|
|
43992
|
-
try {
|
|
43993
|
-
const implCount = results.length;
|
|
43994
|
-
const trustLevel = implCount > 0 ? "semi-trusted" : "unknown";
|
|
43995
|
-
ctx.sharedMemory.write("implement", "risk", {
|
|
43996
|
-
trustLevel,
|
|
43997
|
-
source: "pipeline-agent",
|
|
43998
|
-
requiresReview: true,
|
|
43999
|
-
count: implCount
|
|
44000
|
-
});
|
|
44001
|
-
} catch {
|
|
44002
|
-
}
|
|
44003
|
-
}
|
|
44004
43967
|
function createDevStageRegistry(stages) {
|
|
44005
43968
|
return /* @__PURE__ */ new Map([
|
|
44006
43969
|
["research", createResearchStageWrapper(stages)],
|
|
@@ -44041,10 +44004,9 @@ function createAnalyzeStageWrapper() {
|
|
|
44041
44004
|
true
|
|
44042
44005
|
);
|
|
44043
44006
|
}
|
|
44044
|
-
const { analyzeGitHubRepo: analyzeGitHubRepo2 } = await import("./repo-analyze-
|
|
44007
|
+
const { analyzeGitHubRepo: analyzeGitHubRepo2 } = await import("./repo-analyze-JZEMBE6R.js");
|
|
44045
44008
|
const analysis = await analyzeGitHubRepo2({ repo: slug, depth: "deep" });
|
|
44046
44009
|
const summary = `Language: ${String(analysis.language)}, Framework: ${String(analysis.framework)}, CI: ${String(analysis.ciProvider)}, Security: ${analysis.securityTooling.join(", ") || "none"}`;
|
|
44047
|
-
ctx.sharedMemory.write("analyze", "discovery", { slug, analysis: summary });
|
|
44048
44010
|
return output(PIPELINE_STATE_KEYS.RESEARCH, summary, getTimeProvider().now() - start, true);
|
|
44049
44011
|
} catch (e) {
|
|
44050
44012
|
return failOutput(PIPELINE_STATE_KEYS.RESEARCH, String(e), getTimeProvider().now() - start);
|
|
@@ -44061,10 +44023,9 @@ function createScanStageWrapper() {
|
|
|
44061
44023
|
try {
|
|
44062
44024
|
const slug = ctx.task.match(/([a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+)/)?.[1];
|
|
44063
44025
|
if (slug !== void 0) {
|
|
44064
|
-
const { generateSecurityPlan: generateSecurityPlan2 } = await import("./repo-security-plan-
|
|
44026
|
+
const { generateSecurityPlan: generateSecurityPlan2 } = await import("./repo-security-plan-RHSLO7H6.js");
|
|
44065
44027
|
const plan = await generateSecurityPlan2({ repo: slug, maxScanners: 10 });
|
|
44066
44028
|
const recs = plan.recommendations.slice(0, 5).map((r) => `${r.priority}: ${r.displayName} (${r.category})`).join("; ");
|
|
44067
|
-
ctx.sharedMemory.write("scan", "decision", { recommendations: recs });
|
|
44068
44029
|
return output(PIPELINE_STATE_KEYS.FINDINGS, recs, getTimeProvider().now() - start, true);
|
|
44069
44030
|
}
|
|
44070
44031
|
return output(PIPELINE_STATE_KEYS.FINDINGS, "No repository to scan", getTimeProvider().now() - start, true);
|
|
@@ -44345,15 +44306,15 @@ async function prReviewHandler(args, ctx) {
|
|
|
44345
44306
|
}
|
|
44346
44307
|
}
|
|
44347
44308
|
function registerPrReviewTool(server, deps) {
|
|
44348
|
-
const
|
|
44309
|
+
const logger53 = deps.logger ?? createLogger({ tool: "pr_review" });
|
|
44349
44310
|
const description2 = "Run multi-voter consensus review on a PR diff (#2233). 5 voters (architect, security, devex, catfish, scope_steward) each emit approve/request_changes/abstain with reasoning and citations. Reuses consensus_vote infra; experimental.";
|
|
44350
44311
|
const secureHandler = createSecureHandler(prReviewHandler, {
|
|
44351
44312
|
toolName: "pr_review",
|
|
44352
44313
|
rateLimiter: deps.rateLimiter,
|
|
44353
|
-
logger:
|
|
44314
|
+
logger: logger53
|
|
44354
44315
|
});
|
|
44355
44316
|
const timeoutMs = getToolTimeout("pr_review", deps.security);
|
|
44356
|
-
const wrappedHandler = wrapToolWithTimeout("pr_review", secureHandler, { timeoutMs, logger:
|
|
44317
|
+
const wrappedHandler = wrapToolWithTimeout("pr_review", secureHandler, { timeoutMs, logger: logger53 });
|
|
44357
44318
|
server.registerTool(
|
|
44358
44319
|
"pr_review",
|
|
44359
44320
|
{
|
|
@@ -44363,7 +44324,7 @@ function registerPrReviewTool(server, deps) {
|
|
|
44363
44324
|
},
|
|
44364
44325
|
toSdkCallback(wrappedHandler)
|
|
44365
44326
|
);
|
|
44366
|
-
|
|
44327
|
+
logger53.info("Registered pr_review tool");
|
|
44367
44328
|
}
|
|
44368
44329
|
|
|
44369
44330
|
// src/mcp/tools/survey-oss-landscape.ts
|
|
@@ -44424,7 +44385,7 @@ function parseCandidates(data) {
|
|
|
44424
44385
|
});
|
|
44425
44386
|
return { totalFound: data.total_count ?? candidates.length, candidates };
|
|
44426
44387
|
}
|
|
44427
|
-
async function fetchGithubCandidates(input,
|
|
44388
|
+
async function fetchGithubCandidates(input, logger53) {
|
|
44428
44389
|
const query = encodeURIComponent(buildGithubQuery(input));
|
|
44429
44390
|
const perPage = String(input.maxResults);
|
|
44430
44391
|
const url = `${GITHUB_SEARCH_BASE}?q=${query}&sort=stars&order=desc&per_page=${perPage}`;
|
|
@@ -44436,7 +44397,7 @@ async function fetchGithubCandidates(input, logger52) {
|
|
|
44436
44397
|
if (tokenResult.ok) {
|
|
44437
44398
|
headers["Authorization"] = `Bearer ${tokenResult.value.value}`;
|
|
44438
44399
|
} else {
|
|
44439
|
-
|
|
44400
|
+
logger53.debug("No GitHub token; using unauthenticated rate limit (60/hr)");
|
|
44440
44401
|
}
|
|
44441
44402
|
const fetchResult = await fetchSource({ url, source: "github", headers });
|
|
44442
44403
|
if (!fetchResult.ok) return fetchResult;
|
|
@@ -44467,12 +44428,12 @@ async function fetchGithubCandidates(input, logger52) {
|
|
|
44467
44428
|
}
|
|
44468
44429
|
return { ok: true, value: parseCandidates(parsed.data) };
|
|
44469
44430
|
}
|
|
44470
|
-
async function executeSurvey(input,
|
|
44431
|
+
async function executeSurvey(input, logger53) {
|
|
44471
44432
|
const sourcesQueried = ["github"];
|
|
44472
44433
|
const sourcesFailed = [];
|
|
44473
|
-
const githubResult = await fetchGithubCandidates(input,
|
|
44434
|
+
const githubResult = await fetchGithubCandidates(input, logger53);
|
|
44474
44435
|
if (!githubResult.ok) {
|
|
44475
|
-
|
|
44436
|
+
logger53.warn("GitHub source failed", {
|
|
44476
44437
|
code: githubResult.error.code,
|
|
44477
44438
|
message: githubResult.error.message
|
|
44478
44439
|
});
|
|
@@ -44502,13 +44463,13 @@ function createSurveyHandler(deps) {
|
|
|
44502
44463
|
message: `Validation error: ${formatZodError(validation.error)}`
|
|
44503
44464
|
});
|
|
44504
44465
|
}
|
|
44505
|
-
const
|
|
44466
|
+
const logger53 = deps.logger ?? createLogger({ tool: "survey_oss_landscape" });
|
|
44506
44467
|
ctx.logger.debug("Surveying OSS landscape", {
|
|
44507
44468
|
query: validation.data.query,
|
|
44508
44469
|
maxResults: validation.data.maxResults
|
|
44509
44470
|
});
|
|
44510
|
-
return withToolError("Survey failed",
|
|
44511
|
-
const result = await executeSurvey(validation.data,
|
|
44471
|
+
return withToolError("Survey failed", logger53, async () => {
|
|
44472
|
+
const result = await executeSurvey(validation.data, logger53);
|
|
44512
44473
|
return toolSuccessStructured(result);
|
|
44513
44474
|
});
|
|
44514
44475
|
};
|
|
@@ -44522,16 +44483,16 @@ var SURVEY_OUTPUT_SCHEMA = {
|
|
|
44522
44483
|
};
|
|
44523
44484
|
var SURVEY_DESCRIPTION = 'Transient OSS project search. Returns a ranked list of GitHub repositories with license, last-commit, star-count, and one-line description. Does NOT persist to the research registry \u2014 use `research_add_source` for that. Best for one-off engineering decisions like "what tools exist in this space?".';
|
|
44524
44485
|
function registerSurveyOssLandscapeTool(server, deps) {
|
|
44525
|
-
const
|
|
44486
|
+
const logger53 = deps.logger ?? createLogger({ tool: "survey_oss_landscape" });
|
|
44526
44487
|
const secureHandler = createSecureHandler(createSurveyHandler(deps), {
|
|
44527
44488
|
toolName: "survey_oss_landscape",
|
|
44528
44489
|
rateLimiter: deps.rateLimiter,
|
|
44529
|
-
logger:
|
|
44490
|
+
logger: logger53
|
|
44530
44491
|
});
|
|
44531
44492
|
const timeoutMs = getToolTimeout("survey_oss_landscape", deps.security);
|
|
44532
44493
|
const wrappedHandler = wrapToolWithTimeout("survey_oss_landscape", secureHandler, {
|
|
44533
44494
|
timeoutMs,
|
|
44534
|
-
logger:
|
|
44495
|
+
logger: logger53
|
|
44535
44496
|
});
|
|
44536
44497
|
server.registerTool(
|
|
44537
44498
|
"survey_oss_landscape",
|
|
@@ -44543,7 +44504,7 @@ function registerSurveyOssLandscapeTool(server, deps) {
|
|
|
44543
44504
|
},
|
|
44544
44505
|
toSdkCallback(wrappedHandler)
|
|
44545
44506
|
);
|
|
44546
|
-
|
|
44507
|
+
logger53.info("Registered survey_oss_landscape tool");
|
|
44547
44508
|
}
|
|
44548
44509
|
|
|
44549
44510
|
// src/mcp/tools/vendor-publishing-audit.ts
|
|
@@ -44644,9 +44605,9 @@ function createVendorPublishingAuditHandler(deps) {
|
|
|
44644
44605
|
message: `Validation error: ${formatZodError(validation.error)}`
|
|
44645
44606
|
});
|
|
44646
44607
|
}
|
|
44647
|
-
const
|
|
44608
|
+
const logger53 = deps.logger ?? createLogger({ tool: "vendor_publishing_audit" });
|
|
44648
44609
|
ctx.logger.debug("Vendor publishing audit", { vendor: validation.data.vendor });
|
|
44649
|
-
return withToolError("Vendor publishing audit failed",
|
|
44610
|
+
return withToolError("Vendor publishing audit failed", logger53, () => {
|
|
44650
44611
|
const result = lookupVendor(validation.data.vendor);
|
|
44651
44612
|
return Promise.resolve(toolSuccessStructured(result));
|
|
44652
44613
|
});
|
|
@@ -44670,16 +44631,16 @@ var VENDOR_PUBLISHING_OUTPUT_SCHEMA = {
|
|
|
44670
44631
|
};
|
|
44671
44632
|
var VENDOR_PUBLISHING_DESCRIPTION = "Look up a vendor's published-artifact signing infrastructure: GPG key fingerprints, SHA256SUMS URL pattern, signature shape (clearsigned / detached / detached-on-iso), release cadence, key rotation notes, and the vendor doc citation. Static lookup against a curated seed dataset; the vendor doc URL is the authoritative source. Returns `{known: false, knownVendors: [...]}` for vendors without a seed entry. v1 covers ubuntu, debian, fedora.";
|
|
44672
44633
|
function registerVendorPublishingAuditTool(server, deps) {
|
|
44673
|
-
const
|
|
44634
|
+
const logger53 = deps.logger ?? createLogger({ tool: "vendor_publishing_audit" });
|
|
44674
44635
|
const secureHandler = createSecureHandler(createVendorPublishingAuditHandler(deps), {
|
|
44675
44636
|
toolName: "vendor_publishing_audit",
|
|
44676
44637
|
rateLimiter: deps.rateLimiter,
|
|
44677
|
-
logger:
|
|
44638
|
+
logger: logger53
|
|
44678
44639
|
});
|
|
44679
44640
|
const timeoutMs = getToolTimeout("vendor_publishing_audit", deps.security);
|
|
44680
44641
|
const wrappedHandler = wrapToolWithTimeout("vendor_publishing_audit", secureHandler, {
|
|
44681
44642
|
timeoutMs,
|
|
44682
|
-
logger:
|
|
44643
|
+
logger: logger53
|
|
44683
44644
|
});
|
|
44684
44645
|
server.registerTool(
|
|
44685
44646
|
"vendor_publishing_audit",
|
|
@@ -44691,7 +44652,7 @@ function registerVendorPublishingAuditTool(server, deps) {
|
|
|
44691
44652
|
},
|
|
44692
44653
|
toSdkCallback(wrappedHandler)
|
|
44693
44654
|
);
|
|
44694
|
-
|
|
44655
|
+
logger53.info("Registered vendor_publishing_audit tool");
|
|
44695
44656
|
}
|
|
44696
44657
|
|
|
44697
44658
|
// src/mcp/tools/compare-data-feeds.ts
|
|
@@ -44877,12 +44838,12 @@ function createCompareDataFeedsHandler(deps) {
|
|
|
44877
44838
|
message: `Validation error: ${formatZodError(validation.error)}`
|
|
44878
44839
|
});
|
|
44879
44840
|
}
|
|
44880
|
-
const
|
|
44841
|
+
const logger53 = deps.logger ?? createLogger({ tool: "compare_data_feeds" });
|
|
44881
44842
|
ctx.logger.debug("Comparing data feeds", {
|
|
44882
44843
|
feedAPath: validation.data.feedAPath,
|
|
44883
44844
|
feedBPath: validation.data.feedBPath
|
|
44884
44845
|
});
|
|
44885
|
-
return withToolError("Compare data feeds failed",
|
|
44846
|
+
return withToolError("Compare data feeds failed", logger53, () => {
|
|
44886
44847
|
const result = executeCompare(validation.data);
|
|
44887
44848
|
return Promise.resolve(toolSuccessStructured(result));
|
|
44888
44849
|
});
|
|
@@ -44910,16 +44871,16 @@ var COMPARE_OUTPUT_SCHEMA = {
|
|
|
44910
44871
|
};
|
|
44911
44872
|
var COMPARE_DESCRIPTION = "Diff two upstream data feeds (YAML or JSON files) along coverage and per-field axes. Returns which entries exist in A, B, both, plus optional field-level diffs across matched entries. v1 takes file paths only (no URL fetch \u2014 that needs an SSRF design pass). Both feeds must be a top-level array OR a top-level object with exactly one array field.";
|
|
44912
44873
|
function registerCompareDataFeedsTool(server, deps) {
|
|
44913
|
-
const
|
|
44874
|
+
const logger53 = deps.logger ?? createLogger({ tool: "compare_data_feeds" });
|
|
44914
44875
|
const secureHandler = createSecureHandler(createCompareDataFeedsHandler(deps), {
|
|
44915
44876
|
toolName: "compare_data_feeds",
|
|
44916
44877
|
rateLimiter: deps.rateLimiter,
|
|
44917
|
-
logger:
|
|
44878
|
+
logger: logger53
|
|
44918
44879
|
});
|
|
44919
44880
|
const timeoutMs = getToolTimeout("compare_data_feeds", deps.security);
|
|
44920
44881
|
const wrappedHandler = wrapToolWithTimeout("compare_data_feeds", secureHandler, {
|
|
44921
44882
|
timeoutMs,
|
|
44922
|
-
logger:
|
|
44883
|
+
logger: logger53
|
|
44923
44884
|
});
|
|
44924
44885
|
server.registerTool(
|
|
44925
44886
|
"compare_data_feeds",
|
|
@@ -44931,7 +44892,7 @@ function registerCompareDataFeedsTool(server, deps) {
|
|
|
44931
44892
|
},
|
|
44932
44893
|
toSdkCallback(wrappedHandler)
|
|
44933
44894
|
);
|
|
44934
|
-
|
|
44895
|
+
logger53.info("Registered compare_data_feeds tool");
|
|
44935
44896
|
}
|
|
44936
44897
|
|
|
44937
44898
|
// src/mcp/tools/improvement-review.ts
|
|
@@ -45009,8 +44970,8 @@ function clamp2(score, max) {
|
|
|
45009
44970
|
var FitnessScoreCalculator = class {
|
|
45010
44971
|
logger;
|
|
45011
44972
|
checks = [];
|
|
45012
|
-
constructor(
|
|
45013
|
-
this.logger =
|
|
44973
|
+
constructor(logger53) {
|
|
44974
|
+
this.logger = logger53 ?? createLogger({ component: "FitnessScoreCalculator" });
|
|
45014
44975
|
this.registerDefaultChecks();
|
|
45015
44976
|
}
|
|
45016
44977
|
/** Register default fitness checks. */
|
|
@@ -45504,8 +45465,8 @@ var FitnessScoreCalculator = class {
|
|
|
45504
45465
|
return base;
|
|
45505
45466
|
}
|
|
45506
45467
|
};
|
|
45507
|
-
function createFitnessScoreCalculator(
|
|
45508
|
-
return new FitnessScoreCalculator(
|
|
45468
|
+
function createFitnessScoreCalculator(logger53) {
|
|
45469
|
+
return new FitnessScoreCalculator(logger53);
|
|
45509
45470
|
}
|
|
45510
45471
|
function calculateFitnessScore(version) {
|
|
45511
45472
|
const calculator = createFitnessScoreCalculator();
|
|
@@ -45753,20 +45714,20 @@ async function fileSignalsAsIssues(signals, ctx) {
|
|
|
45753
45714
|
return { issuesFiled, issuesSkipped };
|
|
45754
45715
|
}
|
|
45755
45716
|
async function runImprovementReview(input, deps = {}) {
|
|
45756
|
-
const
|
|
45717
|
+
const logger53 = deps.logger ?? createLogger({ component: "improvement_review" });
|
|
45757
45718
|
const { lookbackDays, fileIssues, minSampleSize, fitnessFloor } = input;
|
|
45758
45719
|
const now = Date.now();
|
|
45759
45720
|
const windowLabel = `${String(lookbackDays)}d`;
|
|
45760
45721
|
const allOutcomes = getOutcomeStore().query();
|
|
45761
45722
|
const windowed = filterByLookback(allOutcomes, lookbackDays, now);
|
|
45762
|
-
const audit = safeFitnessAudit(now, { logger:
|
|
45723
|
+
const audit = safeFitnessAudit(now, { logger: logger53 });
|
|
45763
45724
|
const signals = [
|
|
45764
45725
|
...detectCliPerformanceFloor(windowed, minSampleSize, windowLabel),
|
|
45765
45726
|
...detectFailureCategoryConcentration(windowed, windowLabel),
|
|
45766
45727
|
...detectFitnessSignals(audit, fitnessFloor)
|
|
45767
45728
|
];
|
|
45768
45729
|
signals.sort((a, b) => SEVERITY_ORDER3[a.severity] - SEVERITY_ORDER3[b.severity]);
|
|
45769
|
-
const { issuesFiled, issuesSkipped } = fileIssues ? await fileSignalsAsIssues(signals, { logger:
|
|
45730
|
+
const { issuesFiled, issuesSkipped } = fileIssues ? await fileSignalsAsIssues(signals, { logger: logger53 }) : { issuesFiled: [], issuesSkipped: [] };
|
|
45770
45731
|
return {
|
|
45771
45732
|
window: windowLabel,
|
|
45772
45733
|
totalOutcomes: windowed.length,
|
|
@@ -45796,17 +45757,17 @@ var TOOL_INPUT_SCHEMA = {
|
|
|
45796
45757
|
fitnessFloor: z95.number().int().min(0).max(100).optional().describe("Fitness score below this threshold triggers a tech-debt signal (default 90).")
|
|
45797
45758
|
};
|
|
45798
45759
|
function registerImprovementReviewTool(server, deps) {
|
|
45799
|
-
const
|
|
45760
|
+
const logger53 = deps.logger ?? createLogger({ tool: "improvement_review" });
|
|
45800
45761
|
const secureHandler = createSecureHandler(reviewHandler, {
|
|
45801
45762
|
toolName: "improvement_review",
|
|
45802
45763
|
rateLimiter: deps.rateLimiter,
|
|
45803
|
-
logger:
|
|
45764
|
+
logger: logger53
|
|
45804
45765
|
});
|
|
45805
45766
|
const guardedHandler = withPrerequisite("improvement_review", secureHandler);
|
|
45806
45767
|
const timeoutMs = getToolTimeout("improvement_review", deps.security);
|
|
45807
45768
|
const wrappedHandler = wrapToolWithTimeout("improvement_review", guardedHandler, {
|
|
45808
45769
|
timeoutMs,
|
|
45809
|
-
logger:
|
|
45770
|
+
logger: logger53
|
|
45810
45771
|
});
|
|
45811
45772
|
server.registerTool(
|
|
45812
45773
|
"improvement_review",
|
|
@@ -45817,7 +45778,7 @@ function registerImprovementReviewTool(server, deps) {
|
|
|
45817
45778
|
},
|
|
45818
45779
|
toSdkCallback(wrappedHandler)
|
|
45819
45780
|
);
|
|
45820
|
-
|
|
45781
|
+
logger53.info("Registered improvement_review tool");
|
|
45821
45782
|
}
|
|
45822
45783
|
|
|
45823
45784
|
// src/mcp/tools/query-task-state-tool.ts
|
|
@@ -45856,7 +45817,7 @@ function queryTaskStateHandler(args, ctx) {
|
|
|
45856
45817
|
return Promise.resolve(toolSuccess(JSON.stringify(response, null, 2)));
|
|
45857
45818
|
}
|
|
45858
45819
|
function registerQueryTaskStateTool(server, deps) {
|
|
45859
|
-
const
|
|
45820
|
+
const logger53 = deps.logger ?? createLogger({ tool: "query_task_state" });
|
|
45860
45821
|
const toolSchema = {
|
|
45861
45822
|
taskId: z96.string().min(1).max(128).describe("Task ID whose structured state log should be read")
|
|
45862
45823
|
};
|
|
@@ -45864,19 +45825,19 @@ function registerQueryTaskStateTool(server, deps) {
|
|
|
45864
45825
|
const secureHandler = createSecureHandler(queryTaskStateHandler, {
|
|
45865
45826
|
toolName: "query_task_state",
|
|
45866
45827
|
rateLimiter: deps.rateLimiter,
|
|
45867
|
-
logger:
|
|
45828
|
+
logger: logger53
|
|
45868
45829
|
});
|
|
45869
45830
|
const timeoutMs = getToolTimeout("query_task_state", deps.security);
|
|
45870
45831
|
const wrappedHandler = wrapToolWithTimeout("query_task_state", secureHandler, {
|
|
45871
45832
|
timeoutMs,
|
|
45872
|
-
logger:
|
|
45833
|
+
logger: logger53
|
|
45873
45834
|
});
|
|
45874
45835
|
server.registerTool(
|
|
45875
45836
|
"query_task_state",
|
|
45876
45837
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("query_task_state") },
|
|
45877
45838
|
toSdkCallback(wrappedHandler)
|
|
45878
45839
|
);
|
|
45879
|
-
|
|
45840
|
+
logger53.info("Registered query_task_state tool");
|
|
45880
45841
|
}
|
|
45881
45842
|
|
|
45882
45843
|
// src/mcp/tools/verify-audit-chain-tool.ts
|
|
@@ -45888,7 +45849,7 @@ var VerifyAuditChainInputSchema = z97.object({
|
|
|
45888
45849
|
"Filesystem path to the FileAuditStorage log directory. Tool reads all `audit-*.jsonl` files in lexicographic order and verifies the combined chain."
|
|
45889
45850
|
)
|
|
45890
45851
|
});
|
|
45891
|
-
async function loadAuditEvents(dir,
|
|
45852
|
+
async function loadAuditEvents(dir, logger53) {
|
|
45892
45853
|
const entries = await fs12.readdir(dir);
|
|
45893
45854
|
const auditFiles = entries.filter((name) => name.startsWith("audit-") && name.endsWith(".jsonl")).sort();
|
|
45894
45855
|
const events = [];
|
|
@@ -45899,7 +45860,7 @@ async function loadAuditEvents(dir, logger52) {
|
|
|
45899
45860
|
content = await fs12.readFile(fullPath, "utf-8");
|
|
45900
45861
|
} catch (cause) {
|
|
45901
45862
|
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
45902
|
-
|
|
45863
|
+
logger53.warn("Skipping unreadable audit log file", { filename, error: msg });
|
|
45903
45864
|
continue;
|
|
45904
45865
|
}
|
|
45905
45866
|
for (const line of content.split("\n")) {
|
|
@@ -45910,14 +45871,14 @@ async function loadAuditEvents(dir, logger52) {
|
|
|
45910
45871
|
if (validated.success) {
|
|
45911
45872
|
events.push(validated.data);
|
|
45912
45873
|
} else {
|
|
45913
|
-
|
|
45874
|
+
logger53.warn("Skipping malformed audit event", {
|
|
45914
45875
|
filename,
|
|
45915
45876
|
error: validated.error.message
|
|
45916
45877
|
});
|
|
45917
45878
|
}
|
|
45918
45879
|
} catch (cause) {
|
|
45919
45880
|
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
45920
|
-
|
|
45881
|
+
logger53.warn("Skipping unparseable audit event", { filename, error: msg });
|
|
45921
45882
|
}
|
|
45922
45883
|
}
|
|
45923
45884
|
}
|
|
@@ -45959,7 +45920,7 @@ async function handler2(args, ctx) {
|
|
|
45959
45920
|
return toolSuccess(JSON.stringify(response, null, 2));
|
|
45960
45921
|
}
|
|
45961
45922
|
function registerVerifyAuditChainTool(server, deps) {
|
|
45962
|
-
const
|
|
45923
|
+
const logger53 = deps.logger ?? createLogger({ tool: "verify_audit_chain" });
|
|
45963
45924
|
const toolSchema = {
|
|
45964
45925
|
logDir: z97.string().min(1).max(512).describe(
|
|
45965
45926
|
"Filesystem path to the FileAuditStorage log directory. Tool reads all `audit-*.jsonl` files and verifies the combined hash chain."
|
|
@@ -45969,19 +45930,19 @@ function registerVerifyAuditChainTool(server, deps) {
|
|
|
45969
45930
|
const secureHandler = createSecureHandler(handler2, {
|
|
45970
45931
|
toolName: "verify_audit_chain",
|
|
45971
45932
|
rateLimiter: deps.rateLimiter,
|
|
45972
|
-
logger:
|
|
45933
|
+
logger: logger53
|
|
45973
45934
|
});
|
|
45974
45935
|
const timeoutMs = getToolTimeout("verify_audit_chain", deps.security);
|
|
45975
45936
|
const wrappedHandler = wrapToolWithTimeout("verify_audit_chain", secureHandler, {
|
|
45976
45937
|
timeoutMs,
|
|
45977
|
-
logger:
|
|
45938
|
+
logger: logger53
|
|
45978
45939
|
});
|
|
45979
45940
|
server.registerTool(
|
|
45980
45941
|
"verify_audit_chain",
|
|
45981
45942
|
{ description: description2, inputSchema: toolSchema, annotations: getToolAnnotations("verify_audit_chain") },
|
|
45982
45943
|
toSdkCallback(wrappedHandler)
|
|
45983
45944
|
);
|
|
45984
|
-
|
|
45945
|
+
logger53.info("Registered verify_audit_chain tool");
|
|
45985
45946
|
}
|
|
45986
45947
|
|
|
45987
45948
|
// src/mcp/tools/pipeline-tool.ts
|
|
@@ -46060,7 +46021,7 @@ function selectStageRegistry(template, task, agentStages) {
|
|
|
46060
46021
|
return createDevStageRegistry(agentStages);
|
|
46061
46022
|
}
|
|
46062
46023
|
var RUN_PIPELINE_DESCRIPTION = `Single unified entry point for all pipeline templates (${listTemplateIds().join("/")}). Auto-detects template from task content or accepts an explicit override.`;
|
|
46063
|
-
async function runPipelineHandler(args,
|
|
46024
|
+
async function runPipelineHandler(args, logger53) {
|
|
46064
46025
|
const parsed = PipelineInputSchema.safeParse(args);
|
|
46065
46026
|
if (!parsed.success) {
|
|
46066
46027
|
return toolStructuredError({
|
|
@@ -46070,7 +46031,7 @@ async function runPipelineHandler(args, logger52) {
|
|
|
46070
46031
|
}
|
|
46071
46032
|
const input = parsed.data;
|
|
46072
46033
|
if (input.simulateVotes) {
|
|
46073
|
-
warnIfSimulatedOutsideTests("run_pipeline",
|
|
46034
|
+
warnIfSimulatedOutsideTests("run_pipeline", logger53);
|
|
46074
46035
|
}
|
|
46075
46036
|
try {
|
|
46076
46037
|
const task = await resolveTask(input.task, input.specFile);
|
|
@@ -46094,14 +46055,14 @@ async function runPipelineHandler(args, logger52) {
|
|
|
46094
46055
|
}
|
|
46095
46056
|
}
|
|
46096
46057
|
function registerPipelineTool(server, deps) {
|
|
46097
|
-
const
|
|
46098
|
-
const secureHandler = createSecureHandler((args) => runPipelineHandler(args,
|
|
46058
|
+
const logger53 = deps.logger ?? createLogger({ tool: "run_pipeline" });
|
|
46059
|
+
const secureHandler = createSecureHandler((args) => runPipelineHandler(args, logger53), {
|
|
46099
46060
|
toolName: "run_pipeline",
|
|
46100
46061
|
rateLimiter: deps.rateLimiter,
|
|
46101
|
-
logger:
|
|
46062
|
+
logger: logger53
|
|
46102
46063
|
});
|
|
46103
46064
|
const timeoutMs = getToolTimeout("run_pipeline", deps.security);
|
|
46104
|
-
const wrapped = wrapToolWithTimeout("run_pipeline", secureHandler, { timeoutMs, logger:
|
|
46065
|
+
const wrapped = wrapToolWithTimeout("run_pipeline", secureHandler, { timeoutMs, logger: logger53 });
|
|
46105
46066
|
server.registerTool(
|
|
46106
46067
|
"run_pipeline",
|
|
46107
46068
|
{
|
|
@@ -46111,7 +46072,7 @@ function registerPipelineTool(server, deps) {
|
|
|
46111
46072
|
},
|
|
46112
46073
|
toSdkCallback(wrapped)
|
|
46113
46074
|
);
|
|
46114
|
-
|
|
46075
|
+
logger53.info("Registered run_pipeline tool");
|
|
46115
46076
|
}
|
|
46116
46077
|
|
|
46117
46078
|
// src/mcp/tools/supply-chain-tradeoff-panel.ts
|
|
@@ -46366,17 +46327,17 @@ async function tradeoffPanelHandler(args, ctx) {
|
|
|
46366
46327
|
}
|
|
46367
46328
|
}
|
|
46368
46329
|
function registerSupplyChainTradeoffPanelTool(server, deps) {
|
|
46369
|
-
const
|
|
46330
|
+
const logger53 = deps.logger ?? createLogger({ tool: "supply_chain_tradeoff_panel" });
|
|
46370
46331
|
const description2 = "Run a structured per-axis tradeoff vote on an engineering proposal (#2294). Default axes: build_time_determinism / supply_chain_risk / update_cadence. Voters answer EACH axis independently; aggregator surfaces per-axis verdicts so legitimate tradeoffs are not masked by a single approve/reject.";
|
|
46371
46332
|
const secureHandler = createSecureHandler(tradeoffPanelHandler, {
|
|
46372
46333
|
toolName: "supply_chain_tradeoff_panel",
|
|
46373
46334
|
rateLimiter: deps.rateLimiter,
|
|
46374
|
-
logger:
|
|
46335
|
+
logger: logger53
|
|
46375
46336
|
});
|
|
46376
46337
|
const timeoutMs = getToolTimeout("supply_chain_tradeoff_panel", deps.security);
|
|
46377
46338
|
const wrappedHandler = wrapToolWithTimeout("supply_chain_tradeoff_panel", secureHandler, {
|
|
46378
46339
|
timeoutMs,
|
|
46379
|
-
logger:
|
|
46340
|
+
logger: logger53
|
|
46380
46341
|
});
|
|
46381
46342
|
server.registerTool(
|
|
46382
46343
|
"supply_chain_tradeoff_panel",
|
|
@@ -46387,7 +46348,7 @@ function registerSupplyChainTradeoffPanelTool(server, deps) {
|
|
|
46387
46348
|
},
|
|
46388
46349
|
toSdkCallback(wrappedHandler)
|
|
46389
46350
|
);
|
|
46390
|
-
|
|
46351
|
+
logger53.info("Registered supply_chain_tradeoff_panel tool");
|
|
46391
46352
|
}
|
|
46392
46353
|
|
|
46393
46354
|
// src/mcp/tools/tool-annotations.ts
|
|
@@ -47008,13 +46969,13 @@ var REGISTERED_TOOL_NAMES = [
|
|
|
47008
46969
|
"improvement_review"
|
|
47009
46970
|
];
|
|
47010
46971
|
function registerTools(server, options) {
|
|
47011
|
-
const
|
|
47012
|
-
const rateLimiter = options?.rateLimiter ?? createDefaultRateLimiter("mcp-tools",
|
|
47013
|
-
|
|
46972
|
+
const logger53 = options?.logger ?? createMcpLogger({ component: "tools" });
|
|
46973
|
+
const rateLimiter = options?.rateLimiter ?? createDefaultRateLimiter("mcp-tools", logger53);
|
|
46974
|
+
logger53.info("Tool registration infrastructure initialized");
|
|
47014
46975
|
void server;
|
|
47015
46976
|
return {
|
|
47016
46977
|
tools: [...REGISTERED_TOOL_NAMES],
|
|
47017
|
-
logger:
|
|
46978
|
+
logger: logger53,
|
|
47018
46979
|
rateLimiter
|
|
47019
46980
|
};
|
|
47020
46981
|
}
|
|
@@ -47027,32 +46988,32 @@ var TIER_NAMES = {
|
|
|
47027
46988
|
};
|
|
47028
46989
|
function createGateway(config = {}) {
|
|
47029
46990
|
const enabled = config.enabled !== false;
|
|
47030
|
-
const
|
|
46991
|
+
const logger53 = config.logger ?? createLogger({ component: "gateway" });
|
|
47031
46992
|
const overrides = config.tierOverrides;
|
|
47032
46993
|
return {
|
|
47033
46994
|
enabled,
|
|
47034
46995
|
wrapTool(toolName, handler3) {
|
|
47035
46996
|
if (!enabled) return handler3;
|
|
47036
|
-
return createGatewayHandler(toolName, handler3,
|
|
46997
|
+
return createGatewayHandler(toolName, handler3, logger53, overrides);
|
|
47037
46998
|
}
|
|
47038
46999
|
};
|
|
47039
47000
|
}
|
|
47040
|
-
function createGatewayHandler(toolName, handler3,
|
|
47001
|
+
function createGatewayHandler(toolName, handler3, logger53, overrides) {
|
|
47041
47002
|
return async (args) => {
|
|
47042
47003
|
const params = asRecord2(args);
|
|
47043
47004
|
const tier = classifyRequestTier(toolName, params, overrides);
|
|
47044
47005
|
const tierName = TIER_NAMES[tier];
|
|
47045
47006
|
const startMs = getTimeProvider().now();
|
|
47046
|
-
|
|
47007
|
+
logger53.debug("Gateway dispatch", { tool: toolName, tier, tierName });
|
|
47047
47008
|
try {
|
|
47048
47009
|
const result = await handler3(args);
|
|
47049
47010
|
const durationMs = getTimeProvider().now() - startMs;
|
|
47050
47011
|
const success = result.isError !== true;
|
|
47051
47012
|
const entry = { tool: toolName, tier, tierName, durationMs, success };
|
|
47052
47013
|
if (success) {
|
|
47053
|
-
|
|
47014
|
+
logger53.info("Gateway completed", { ...entry });
|
|
47054
47015
|
} else {
|
|
47055
|
-
|
|
47016
|
+
logger53.warn("Gateway completed with error", { ...entry });
|
|
47056
47017
|
}
|
|
47057
47018
|
return result;
|
|
47058
47019
|
} catch (error) {
|
|
@@ -47064,7 +47025,7 @@ function createGatewayHandler(toolName, handler3, logger52, overrides) {
|
|
|
47064
47025
|
durationMs,
|
|
47065
47026
|
success: false
|
|
47066
47027
|
};
|
|
47067
|
-
|
|
47028
|
+
logger53.error("Gateway handler threw", error instanceof Error ? error : void 0, {
|
|
47068
47029
|
...entry
|
|
47069
47030
|
});
|
|
47070
47031
|
throw error;
|
|
@@ -49940,8 +49901,78 @@ function getSandboxMode() {
|
|
|
49940
49901
|
return actualMode;
|
|
49941
49902
|
}
|
|
49942
49903
|
|
|
49904
|
+
// src/pipeline/feedback-subscriber.ts
|
|
49905
|
+
var logger49 = createLogger({ component: "FeedbackSubscriber" });
|
|
49906
|
+
var VALID_CLIS = new Set(CLI_NAMES);
|
|
49907
|
+
function createFeedbackSubscriber(bus, store) {
|
|
49908
|
+
return bus.subscribe({ type: ["model.called", "stage.failed"] }, (event) => {
|
|
49909
|
+
try {
|
|
49910
|
+
handleEvent2(event, store);
|
|
49911
|
+
} catch (error) {
|
|
49912
|
+
const msg = getErrorMessage(error);
|
|
49913
|
+
logger49.warn("Feedback subscriber error", { error: msg });
|
|
49914
|
+
}
|
|
49915
|
+
});
|
|
49916
|
+
}
|
|
49917
|
+
var cachedFeedbackUnsubscribe = null;
|
|
49918
|
+
function startFeedbackSubscriber(bus, store) {
|
|
49919
|
+
if (cachedFeedbackUnsubscribe !== null) return;
|
|
49920
|
+
cachedFeedbackUnsubscribe = createFeedbackSubscriber(bus, store);
|
|
49921
|
+
}
|
|
49922
|
+
function shutdownFeedbackSubscriber() {
|
|
49923
|
+
if (cachedFeedbackUnsubscribe !== null) {
|
|
49924
|
+
cachedFeedbackUnsubscribe();
|
|
49925
|
+
cachedFeedbackUnsubscribe = null;
|
|
49926
|
+
}
|
|
49927
|
+
}
|
|
49928
|
+
function handleEvent2(event, store) {
|
|
49929
|
+
if (event.type === "model.called") {
|
|
49930
|
+
recordModelCall(event, store);
|
|
49931
|
+
} else if (event.type === "stage.failed") {
|
|
49932
|
+
recordStageFailed(event, store);
|
|
49933
|
+
}
|
|
49934
|
+
}
|
|
49935
|
+
function recordModelCall(event, store) {
|
|
49936
|
+
const cli = normalizeCli(event.cli);
|
|
49937
|
+
if (cli === void 0) return;
|
|
49938
|
+
const outcome = {
|
|
49939
|
+
id: `fb-${event.executionId}-${String(event.timestamp)}`,
|
|
49940
|
+
cli,
|
|
49941
|
+
category: "code_generation",
|
|
49942
|
+
model: event.model,
|
|
49943
|
+
success: true,
|
|
49944
|
+
durationMs: event.durationMs,
|
|
49945
|
+
timestamp: new Date(event.timestamp).toISOString(),
|
|
49946
|
+
source: "delegate"
|
|
49947
|
+
};
|
|
49948
|
+
store.append(outcome);
|
|
49949
|
+
}
|
|
49950
|
+
function recordStageFailed(event, store) {
|
|
49951
|
+
const outcome = {
|
|
49952
|
+
id: `fb-fail-${event.executionId}-${String(event.timestamp)}`,
|
|
49953
|
+
cli: DEFAULT_CLI,
|
|
49954
|
+
// Stage failures don't carry CLI info; default to canonical fallback
|
|
49955
|
+
category: "code_generation",
|
|
49956
|
+
model: "unknown",
|
|
49957
|
+
success: false,
|
|
49958
|
+
durationMs: 0,
|
|
49959
|
+
timestamp: new Date(event.timestamp).toISOString(),
|
|
49960
|
+
source: "delegate",
|
|
49961
|
+
failureCategory: categorizeOutcomeErrorMessage(event.error),
|
|
49962
|
+
errorMessage: event.error.slice(0, 500)
|
|
49963
|
+
};
|
|
49964
|
+
store.append(outcome);
|
|
49965
|
+
}
|
|
49966
|
+
function normalizeCli(cli) {
|
|
49967
|
+
if (VALID_CLIS.has(cli)) {
|
|
49968
|
+
return cli;
|
|
49969
|
+
}
|
|
49970
|
+
logger49.warn("Unknown CLI in event", { cli });
|
|
49971
|
+
return void 0;
|
|
49972
|
+
}
|
|
49973
|
+
|
|
49943
49974
|
// src/pipeline/event-bus-bridge.ts
|
|
49944
|
-
var
|
|
49975
|
+
var logger50 = createLogger({ component: "EventBusBridge" });
|
|
49945
49976
|
function toV1Topic(prefix, event) {
|
|
49946
49977
|
return `${prefix}.${event.type}`;
|
|
49947
49978
|
}
|
|
@@ -49973,10 +50004,10 @@ function createEventBusBridge(options) {
|
|
|
49973
50004
|
forwardCount++;
|
|
49974
50005
|
} catch (error) {
|
|
49975
50006
|
const msg = getErrorMessage(error);
|
|
49976
|
-
|
|
50007
|
+
logger50.warn("Failed to forward pipeline event", { type: event.type, error: msg });
|
|
49977
50008
|
}
|
|
49978
50009
|
});
|
|
49979
|
-
|
|
50010
|
+
logger50.info("EventBus bridge initialized", { prefix });
|
|
49980
50011
|
return {
|
|
49981
50012
|
forwarded: () => forwardCount,
|
|
49982
50013
|
dispose: unsub
|
|
@@ -49984,7 +50015,7 @@ function createEventBusBridge(options) {
|
|
|
49984
50015
|
}
|
|
49985
50016
|
|
|
49986
50017
|
// src/adapters/stdin-lifecycle.ts
|
|
49987
|
-
var
|
|
50018
|
+
var logger51 = createLogger({ component: "StdinLifecycleMonitor" });
|
|
49988
50019
|
var DEFAULT_PPID_POLL_MS = 3e4;
|
|
49989
50020
|
var StdinLifecycleMonitor = class {
|
|
49990
50021
|
callbacks = /* @__PURE__ */ new Set();
|
|
@@ -50034,7 +50065,7 @@ var StdinLifecycleMonitor = class {
|
|
|
50034
50065
|
clearInterval(this.ppidTimer);
|
|
50035
50066
|
this.ppidTimer = void 0;
|
|
50036
50067
|
}
|
|
50037
|
-
|
|
50068
|
+
logger51.warn("Parent process gone \u2014 shutting down MCP server", { reason });
|
|
50038
50069
|
await this.fireCallbacks();
|
|
50039
50070
|
}
|
|
50040
50071
|
async fireCallbacks() {
|
|
@@ -50042,7 +50073,7 @@ var StdinLifecycleMonitor = class {
|
|
|
50042
50073
|
try {
|
|
50043
50074
|
await cb();
|
|
50044
50075
|
} catch (error) {
|
|
50045
|
-
|
|
50076
|
+
logger51.warn("Stdin shutdown callback failed", { error: String(error) });
|
|
50046
50077
|
}
|
|
50047
50078
|
}
|
|
50048
50079
|
}
|
|
@@ -50056,7 +50087,7 @@ function getStdinLifecycleMonitor() {
|
|
|
50056
50087
|
// src/pipeline/task-tracker.ts
|
|
50057
50088
|
import * as fs14 from "fs";
|
|
50058
50089
|
import * as path13 from "path";
|
|
50059
|
-
var
|
|
50090
|
+
var logger52 = createLogger({ component: "task-tracker" });
|
|
50060
50091
|
async function exec(cmd, args, timeout = 15e3) {
|
|
50061
50092
|
const { execFile: execFile5 } = await import("child_process");
|
|
50062
50093
|
const { promisify: promisify5 } = await import("util");
|
|
@@ -50071,7 +50102,7 @@ var GitHubTaskTracker = class {
|
|
|
50071
50102
|
cachedProvider = null;
|
|
50072
50103
|
async getProvider() {
|
|
50073
50104
|
if (this.cachedProvider !== null) return this.cachedProvider;
|
|
50074
|
-
const { createScmProvider } = await import("./factory-
|
|
50105
|
+
const { createScmProvider } = await import("./factory-W6KROBFN.js");
|
|
50075
50106
|
const result = await createScmProvider({ repo: this.config.repo ?? "" });
|
|
50076
50107
|
if (!result.ok) throw new Error(`SCM provider error: ${result.error.message}`);
|
|
50077
50108
|
this.cachedProvider = result.value;
|
|
@@ -50082,7 +50113,7 @@ var GitHubTaskTracker = class {
|
|
|
50082
50113
|
const result = await provider.createIssue(title, body, this.config.labels);
|
|
50083
50114
|
if (!result.ok) throw new Error("Failed to create issue");
|
|
50084
50115
|
const id = String(result.value.number);
|
|
50085
|
-
|
|
50116
|
+
logger52.info("Created GitHub issue via SCM provider", { id });
|
|
50086
50117
|
return { id, title, status: "open", url: result.value.url };
|
|
50087
50118
|
}
|
|
50088
50119
|
async updateStatus(taskId, status) {
|
|
@@ -50110,7 +50141,7 @@ var GitLabTaskTracker = class {
|
|
|
50110
50141
|
);
|
|
50111
50142
|
const match = /\/(\d+)$/.exec(url);
|
|
50112
50143
|
const id = match?.[1] ?? url;
|
|
50113
|
-
|
|
50144
|
+
logger52.info("Created GitLab issue", { id, url });
|
|
50114
50145
|
return { id, title, status: "open", url };
|
|
50115
50146
|
}
|
|
50116
50147
|
async updateStatus(taskId, status) {
|
|
@@ -50745,6 +50776,7 @@ export {
|
|
|
50745
50776
|
registerSupplyChainTradeoffPanelTool,
|
|
50746
50777
|
createAnnotationsProxy,
|
|
50747
50778
|
createToolObservabilityProxy,
|
|
50779
|
+
REGISTERED_TOOL_NAMES,
|
|
50748
50780
|
registerTools,
|
|
50749
50781
|
createGatewayServerProxy,
|
|
50750
50782
|
analyzeTools,
|
|
@@ -50773,8 +50805,11 @@ export {
|
|
|
50773
50805
|
createSandboxExecutor,
|
|
50774
50806
|
initializeSandbox,
|
|
50775
50807
|
getSandboxMode,
|
|
50808
|
+
createFeedbackSubscriber,
|
|
50809
|
+
startFeedbackSubscriber,
|
|
50810
|
+
shutdownFeedbackSubscriber,
|
|
50776
50811
|
createEventBusBridge,
|
|
50777
50812
|
detectBackend,
|
|
50778
50813
|
createTaskTracker
|
|
50779
50814
|
};
|
|
50780
|
-
//# sourceMappingURL=chunk-
|
|
50815
|
+
//# sourceMappingURL=chunk-PMLVZXAE.js.map
|