@mcoda/codali 0.1.66

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.
Files changed (241) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +21 -0
  3. package/README.md +111 -0
  4. package/dist/agents/AgentProtocol.d.ts +287 -0
  5. package/dist/agents/AgentProtocol.d.ts.map +1 -0
  6. package/dist/agents/AgentProtocol.js +365 -0
  7. package/dist/agents/AgentResolver.d.ts +23 -0
  8. package/dist/agents/AgentResolver.d.ts.map +1 -0
  9. package/dist/agents/AgentResolver.js +77 -0
  10. package/dist/agents/PhaseAgentSelector.d.ts +23 -0
  11. package/dist/agents/PhaseAgentSelector.d.ts.map +1 -0
  12. package/dist/agents/PhaseAgentSelector.js +287 -0
  13. package/dist/cli/EvalCommand.d.ts +37 -0
  14. package/dist/cli/EvalCommand.d.ts.map +1 -0
  15. package/dist/cli/EvalCommand.js +333 -0
  16. package/dist/cli/FeedbackCommand.d.ts +22 -0
  17. package/dist/cli/FeedbackCommand.d.ts.map +1 -0
  18. package/dist/cli/FeedbackCommand.js +163 -0
  19. package/dist/cli/RunCommand.d.ts +78 -0
  20. package/dist/cli/RunCommand.d.ts.map +1 -0
  21. package/dist/cli/RunCommand.js +2261 -0
  22. package/dist/cli.d.ts +3 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +109 -0
  25. package/dist/cognitive/ArchitectPlanner.d.ts +107 -0
  26. package/dist/cognitive/ArchitectPlanner.d.ts.map +1 -0
  27. package/dist/cognitive/ArchitectPlanner.js +1726 -0
  28. package/dist/cognitive/BuilderOutputParser.d.ts +25 -0
  29. package/dist/cognitive/BuilderOutputParser.d.ts.map +1 -0
  30. package/dist/cognitive/BuilderOutputParser.js +164 -0
  31. package/dist/cognitive/BuilderRunner.d.ts +76 -0
  32. package/dist/cognitive/BuilderRunner.d.ts.map +1 -0
  33. package/dist/cognitive/BuilderRunner.js +1159 -0
  34. package/dist/cognitive/ContextAssembler.d.ts +91 -0
  35. package/dist/cognitive/ContextAssembler.d.ts.map +1 -0
  36. package/dist/cognitive/ContextAssembler.js +4547 -0
  37. package/dist/cognitive/ContextBudget.d.ts +19 -0
  38. package/dist/cognitive/ContextBudget.d.ts.map +1 -0
  39. package/dist/cognitive/ContextBudget.js +35 -0
  40. package/dist/cognitive/ContextFileLoader.d.ts +30 -0
  41. package/dist/cognitive/ContextFileLoader.d.ts.map +1 -0
  42. package/dist/cognitive/ContextFileLoader.js +307 -0
  43. package/dist/cognitive/ContextManager.d.ts +47 -0
  44. package/dist/cognitive/ContextManager.d.ts.map +1 -0
  45. package/dist/cognitive/ContextManager.js +272 -0
  46. package/dist/cognitive/ContextRedactor.d.ts +18 -0
  47. package/dist/cognitive/ContextRedactor.d.ts.map +1 -0
  48. package/dist/cognitive/ContextRedactor.js +53 -0
  49. package/dist/cognitive/ContextSelector.d.ts +22 -0
  50. package/dist/cognitive/ContextSelector.d.ts.map +1 -0
  51. package/dist/cognitive/ContextSelector.js +431 -0
  52. package/dist/cognitive/ContextSerializer.d.ts +8 -0
  53. package/dist/cognitive/ContextSerializer.d.ts.map +1 -0
  54. package/dist/cognitive/ContextSerializer.js +882 -0
  55. package/dist/cognitive/ContextStore.d.ts +27 -0
  56. package/dist/cognitive/ContextStore.d.ts.map +1 -0
  57. package/dist/cognitive/ContextStore.js +79 -0
  58. package/dist/cognitive/ContextSummarizer.d.ts +16 -0
  59. package/dist/cognitive/ContextSummarizer.d.ts.map +1 -0
  60. package/dist/cognitive/ContextSummarizer.js +45 -0
  61. package/dist/cognitive/CostEstimator.d.ts +31 -0
  62. package/dist/cognitive/CostEstimator.d.ts.map +1 -0
  63. package/dist/cognitive/CostEstimator.js +66 -0
  64. package/dist/cognitive/CriticEvaluator.d.ts +32 -0
  65. package/dist/cognitive/CriticEvaluator.d.ts.map +1 -0
  66. package/dist/cognitive/CriticEvaluator.js +297 -0
  67. package/dist/cognitive/EvidenceGate.d.ts +9 -0
  68. package/dist/cognitive/EvidenceGate.d.ts.map +1 -0
  69. package/dist/cognitive/EvidenceGate.js +75 -0
  70. package/dist/cognitive/GoldenExampleIndexer.d.ts +12 -0
  71. package/dist/cognitive/GoldenExampleIndexer.d.ts.map +1 -0
  72. package/dist/cognitive/GoldenExampleIndexer.js +34 -0
  73. package/dist/cognitive/GoldenSetStore.d.ts +33 -0
  74. package/dist/cognitive/GoldenSetStore.d.ts.map +1 -0
  75. package/dist/cognitive/GoldenSetStore.js +159 -0
  76. package/dist/cognitive/IntentSignals.d.ts +7 -0
  77. package/dist/cognitive/IntentSignals.d.ts.map +1 -0
  78. package/dist/cognitive/IntentSignals.js +285 -0
  79. package/dist/cognitive/LearningGovernance.d.ts +100 -0
  80. package/dist/cognitive/LearningGovernance.d.ts.map +1 -0
  81. package/dist/cognitive/LearningGovernance.js +276 -0
  82. package/dist/cognitive/MemoryWriteback.d.ts +64 -0
  83. package/dist/cognitive/MemoryWriteback.d.ts.map +1 -0
  84. package/dist/cognitive/MemoryWriteback.js +287 -0
  85. package/dist/cognitive/PatchApplier.d.ts +49 -0
  86. package/dist/cognitive/PatchApplier.d.ts.map +1 -0
  87. package/dist/cognitive/PatchApplier.js +199 -0
  88. package/dist/cognitive/PatchInterpreter.d.ts +35 -0
  89. package/dist/cognitive/PatchInterpreter.d.ts.map +1 -0
  90. package/dist/cognitive/PatchInterpreter.js +100 -0
  91. package/dist/cognitive/PatchOutputNormalizer.d.ts +7 -0
  92. package/dist/cognitive/PatchOutputNormalizer.d.ts.map +1 -0
  93. package/dist/cognitive/PatchOutputNormalizer.js +59 -0
  94. package/dist/cognitive/PostMortemAnalyzer.d.ts +17 -0
  95. package/dist/cognitive/PostMortemAnalyzer.d.ts.map +1 -0
  96. package/dist/cognitive/PostMortemAnalyzer.js +131 -0
  97. package/dist/cognitive/PreferenceExtraction.d.ts +3 -0
  98. package/dist/cognitive/PreferenceExtraction.d.ts.map +1 -0
  99. package/dist/cognitive/PreferenceExtraction.js +85 -0
  100. package/dist/cognitive/Prompts.d.ts +15 -0
  101. package/dist/cognitive/Prompts.d.ts.map +1 -0
  102. package/dist/cognitive/Prompts.js +326 -0
  103. package/dist/cognitive/ProviderRouting.d.ts +16 -0
  104. package/dist/cognitive/ProviderRouting.d.ts.map +1 -0
  105. package/dist/cognitive/ProviderRouting.js +24 -0
  106. package/dist/cognitive/QueryExtraction.d.ts +12 -0
  107. package/dist/cognitive/QueryExtraction.d.ts.map +1 -0
  108. package/dist/cognitive/QueryExtraction.js +262 -0
  109. package/dist/cognitive/RunHistoryIndexer.d.ts +13 -0
  110. package/dist/cognitive/RunHistoryIndexer.d.ts.map +1 -0
  111. package/dist/cognitive/RunHistoryIndexer.js +125 -0
  112. package/dist/cognitive/SmartPipeline.d.ts +92 -0
  113. package/dist/cognitive/SmartPipeline.d.ts.map +1 -0
  114. package/dist/cognitive/SmartPipeline.js +4804 -0
  115. package/dist/cognitive/Types.d.ts +474 -0
  116. package/dist/cognitive/Types.d.ts.map +1 -0
  117. package/dist/cognitive/Types.js +7 -0
  118. package/dist/cognitive/ValidationRunner.d.ts +57 -0
  119. package/dist/cognitive/ValidationRunner.d.ts.map +1 -0
  120. package/dist/cognitive/ValidationRunner.js +515 -0
  121. package/dist/config/Config.d.ts +249 -0
  122. package/dist/config/Config.d.ts.map +1 -0
  123. package/dist/config/Config.js +200 -0
  124. package/dist/config/ConfigLoader.d.ts +56 -0
  125. package/dist/config/ConfigLoader.d.ts.map +1 -0
  126. package/dist/config/ConfigLoader.js +1246 -0
  127. package/dist/docdex/DocdexClient.d.ts +159 -0
  128. package/dist/docdex/DocdexClient.d.ts.map +1 -0
  129. package/dist/docdex/DocdexClient.js +838 -0
  130. package/dist/eval/EvalRunner.d.ts +35 -0
  131. package/dist/eval/EvalRunner.d.ts.map +1 -0
  132. package/dist/eval/EvalRunner.js +38 -0
  133. package/dist/eval/EvalTaskExecutor.d.ts +81 -0
  134. package/dist/eval/EvalTaskExecutor.d.ts.map +1 -0
  135. package/dist/eval/EvalTaskExecutor.js +371 -0
  136. package/dist/eval/GateEvaluator.d.ts +31 -0
  137. package/dist/eval/GateEvaluator.d.ts.map +1 -0
  138. package/dist/eval/GateEvaluator.js +134 -0
  139. package/dist/eval/MetricTypes.d.ts +28 -0
  140. package/dist/eval/MetricTypes.d.ts.map +1 -0
  141. package/dist/eval/MetricTypes.js +1 -0
  142. package/dist/eval/MetricsAggregator.d.ts +4 -0
  143. package/dist/eval/MetricsAggregator.d.ts.map +1 -0
  144. package/dist/eval/MetricsAggregator.js +97 -0
  145. package/dist/eval/RegressionComparator.d.ts +29 -0
  146. package/dist/eval/RegressionComparator.d.ts.map +1 -0
  147. package/dist/eval/RegressionComparator.js +155 -0
  148. package/dist/eval/ReportInputAdapter.d.ts +52 -0
  149. package/dist/eval/ReportInputAdapter.d.ts.map +1 -0
  150. package/dist/eval/ReportInputAdapter.js +229 -0
  151. package/dist/eval/ReportSerializer.d.ts +32 -0
  152. package/dist/eval/ReportSerializer.d.ts.map +1 -0
  153. package/dist/eval/ReportSerializer.js +33 -0
  154. package/dist/eval/ReportStore.d.ts +18 -0
  155. package/dist/eval/ReportStore.d.ts.map +1 -0
  156. package/dist/eval/ReportStore.js +96 -0
  157. package/dist/eval/SuiteLoader.d.ts +12 -0
  158. package/dist/eval/SuiteLoader.d.ts.map +1 -0
  159. package/dist/eval/SuiteLoader.js +51 -0
  160. package/dist/eval/SuiteSchema.d.ts +56 -0
  161. package/dist/eval/SuiteSchema.d.ts.map +1 -0
  162. package/dist/eval/SuiteSchema.js +357 -0
  163. package/dist/index.d.ts +11 -0
  164. package/dist/index.d.ts.map +1 -0
  165. package/dist/index.js +5 -0
  166. package/dist/providers/CodexCliProvider.d.ts +8 -0
  167. package/dist/providers/CodexCliProvider.d.ts.map +1 -0
  168. package/dist/providers/CodexCliProvider.js +282 -0
  169. package/dist/providers/OllamaRemoteProvider.d.ts +8 -0
  170. package/dist/providers/OllamaRemoteProvider.d.ts.map +1 -0
  171. package/dist/providers/OllamaRemoteProvider.js +300 -0
  172. package/dist/providers/OpenAiCompatibleProvider.d.ts +8 -0
  173. package/dist/providers/OpenAiCompatibleProvider.d.ts.map +1 -0
  174. package/dist/providers/OpenAiCompatibleProvider.js +192 -0
  175. package/dist/providers/ProviderRegistry.d.ts +12 -0
  176. package/dist/providers/ProviderRegistry.d.ts.map +1 -0
  177. package/dist/providers/ProviderRegistry.js +28 -0
  178. package/dist/providers/ProviderTypes.d.ts +81 -0
  179. package/dist/providers/ProviderTypes.d.ts.map +1 -0
  180. package/dist/providers/ProviderTypes.js +1 -0
  181. package/dist/runtime/CodaliRuntime.d.ts +189 -0
  182. package/dist/runtime/CodaliRuntime.d.ts.map +1 -0
  183. package/dist/runtime/CodaliRuntime.js +1435 -0
  184. package/dist/runtime/DeepInvestigationErrors.d.ts +39 -0
  185. package/dist/runtime/DeepInvestigationErrors.d.ts.map +1 -0
  186. package/dist/runtime/DeepInvestigationErrors.js +57 -0
  187. package/dist/runtime/RunContext.d.ts +27 -0
  188. package/dist/runtime/RunContext.d.ts.map +1 -0
  189. package/dist/runtime/RunContext.js +51 -0
  190. package/dist/runtime/RunLogQuery.d.ts +48 -0
  191. package/dist/runtime/RunLogQuery.d.ts.map +1 -0
  192. package/dist/runtime/RunLogQuery.js +36 -0
  193. package/dist/runtime/RunLogReader.d.ts +19 -0
  194. package/dist/runtime/RunLogReader.d.ts.map +1 -0
  195. package/dist/runtime/RunLogReader.js +361 -0
  196. package/dist/runtime/RunLogger.d.ts +71 -0
  197. package/dist/runtime/RunLogger.d.ts.map +1 -0
  198. package/dist/runtime/RunLogger.js +100 -0
  199. package/dist/runtime/RunTelemetryTypes.d.ts +117 -0
  200. package/dist/runtime/RunTelemetryTypes.d.ts.map +1 -0
  201. package/dist/runtime/RunTelemetryTypes.js +299 -0
  202. package/dist/runtime/Runner.d.ts +66 -0
  203. package/dist/runtime/Runner.d.ts.map +1 -0
  204. package/dist/runtime/Runner.js +215 -0
  205. package/dist/runtime/StoragePaths.d.ts +3 -0
  206. package/dist/runtime/StoragePaths.d.ts.map +1 -0
  207. package/dist/runtime/StoragePaths.js +19 -0
  208. package/dist/runtime/WorkspaceLock.d.ts +30 -0
  209. package/dist/runtime/WorkspaceLock.d.ts.map +1 -0
  210. package/dist/runtime/WorkspaceLock.js +141 -0
  211. package/dist/session/InstructionLoader.d.ts +14 -0
  212. package/dist/session/InstructionLoader.d.ts.map +1 -0
  213. package/dist/session/InstructionLoader.js +107 -0
  214. package/dist/session/SessionStore.d.ts +81 -0
  215. package/dist/session/SessionStore.d.ts.map +1 -0
  216. package/dist/session/SessionStore.js +244 -0
  217. package/dist/subagents/SubagentOrchestrator.d.ts +68 -0
  218. package/dist/subagents/SubagentOrchestrator.d.ts.map +1 -0
  219. package/dist/subagents/SubagentOrchestrator.js +150 -0
  220. package/dist/tools/ToolRegistry.d.ts +9 -0
  221. package/dist/tools/ToolRegistry.d.ts.map +1 -0
  222. package/dist/tools/ToolRegistry.js +293 -0
  223. package/dist/tools/ToolTypes.d.ts +66 -0
  224. package/dist/tools/ToolTypes.d.ts.map +1 -0
  225. package/dist/tools/ToolTypes.js +40 -0
  226. package/dist/tools/diff/DiffTool.d.ts +3 -0
  227. package/dist/tools/diff/DiffTool.d.ts.map +1 -0
  228. package/dist/tools/diff/DiffTool.js +34 -0
  229. package/dist/tools/docdex/DocdexTools.d.ts +4 -0
  230. package/dist/tools/docdex/DocdexTools.d.ts.map +1 -0
  231. package/dist/tools/docdex/DocdexTools.js +490 -0
  232. package/dist/tools/filesystem/FileTools.d.ts +3 -0
  233. package/dist/tools/filesystem/FileTools.d.ts.map +1 -0
  234. package/dist/tools/filesystem/FileTools.js +141 -0
  235. package/dist/tools/search/SearchTool.d.ts +3 -0
  236. package/dist/tools/search/SearchTool.d.ts.map +1 -0
  237. package/dist/tools/search/SearchTool.js +46 -0
  238. package/dist/tools/shell/ShellTool.d.ts +3 -0
  239. package/dist/tools/shell/ShellTool.d.ts.map +1 -0
  240. package/dist/tools/shell/ShellTool.js +104 -0
  241. package/package.json +44 -0
@@ -0,0 +1,365 @@
1
+ const parseQuotedValue = (value) => {
2
+ const trimmed = value.trim();
3
+ if ((trimmed.startsWith("\"") && trimmed.endsWith("\"")) ||
4
+ (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
5
+ return trimmed.slice(1, -1);
6
+ }
7
+ return trimmed;
8
+ };
9
+ const parseYamlKeyValue = (line) => {
10
+ const idx = line.indexOf(":");
11
+ if (idx === -1)
12
+ return null;
13
+ const key = line.slice(0, idx).trim();
14
+ const value = line.slice(idx + 1).trim();
15
+ if (!key)
16
+ return null;
17
+ return { key, value };
18
+ };
19
+ const parseOptionalNumber = (value) => {
20
+ if (!value)
21
+ return undefined;
22
+ const parsed = Number(value);
23
+ return Number.isFinite(parsed) ? parsed : undefined;
24
+ };
25
+ const parseOptionalBoolean = (value) => {
26
+ if (value === undefined)
27
+ return undefined;
28
+ return value.trim().toLowerCase() === "true";
29
+ };
30
+ const parseOptionalStringList = (value) => {
31
+ if (!value)
32
+ return undefined;
33
+ const normalized = value.trim().replace(/^\[/, "").replace(/\]$/, "");
34
+ const parsed = normalized
35
+ .split(",")
36
+ .map((entry) => parseQuotedValue(entry.trim()))
37
+ .filter(Boolean);
38
+ return parsed.length ? parsed : undefined;
39
+ };
40
+ const coerceNeed = (need) => {
41
+ const type = need.type?.trim();
42
+ if (!type) {
43
+ throw new Error("Agent request need missing type");
44
+ }
45
+ if (type === "docdex.search") {
46
+ const query = need.query?.trim();
47
+ if (!query)
48
+ throw new Error("docdex.search requires query");
49
+ const limit = parseOptionalNumber(need.limit);
50
+ return { type, query, limit };
51
+ }
52
+ if (type === "docdex.open") {
53
+ const path = need.path?.trim();
54
+ if (!path)
55
+ throw new Error("docdex.open requires path");
56
+ const start_line = parseOptionalNumber(need.start_line);
57
+ const end_line = parseOptionalNumber(need.end_line);
58
+ const head = parseOptionalNumber(need.head);
59
+ const clamp = parseOptionalBoolean(need.clamp);
60
+ return { type, path, start_line, end_line, head, clamp };
61
+ }
62
+ if (type === "docdex.snippet") {
63
+ const doc_id = need.doc_id?.trim();
64
+ if (!doc_id)
65
+ throw new Error("docdex.snippet requires doc_id");
66
+ const window = parseOptionalNumber(need.window);
67
+ return { type, doc_id, window };
68
+ }
69
+ if (type === "docdex.symbols") {
70
+ const file = need.file?.trim();
71
+ if (!file)
72
+ throw new Error("docdex.symbols requires file");
73
+ return { type, file };
74
+ }
75
+ if (type === "docdex.ast") {
76
+ const file = need.file?.trim();
77
+ if (!file)
78
+ throw new Error("docdex.ast requires file");
79
+ const max_nodes = parseOptionalNumber(need.max_nodes);
80
+ return { type, file, max_nodes };
81
+ }
82
+ if (type === "docdex.web") {
83
+ const query = need.query?.trim();
84
+ if (!query)
85
+ throw new Error("docdex.web requires query");
86
+ const force_web = parseOptionalBoolean(need.force_web);
87
+ return { type, query, force_web };
88
+ }
89
+ if (type === "docdex.impact") {
90
+ const file = need.file?.trim();
91
+ if (!file)
92
+ throw new Error("docdex.impact requires file");
93
+ return { type, file };
94
+ }
95
+ if (type === "docdex.impact_diagnostics") {
96
+ const file = need.file?.trim();
97
+ const limit = parseOptionalNumber(need.limit);
98
+ const offset = parseOptionalNumber(need.offset);
99
+ return { type, file: file || undefined, limit, offset };
100
+ }
101
+ if (type === "docdex.tree") {
102
+ const path = need.path?.trim();
103
+ const max_depth = parseOptionalNumber(need.max_depth);
104
+ const dirs_only = parseOptionalBoolean(need.dirs_only);
105
+ const include_hidden = parseOptionalBoolean(need.include_hidden);
106
+ return { type, path: path || undefined, max_depth, dirs_only, include_hidden };
107
+ }
108
+ if (type === "docdex.dag_export") {
109
+ const session_id = need.session_id?.trim();
110
+ const formatValue = need.format?.trim();
111
+ const format = formatValue && ["json", "text", "dot"].includes(formatValue)
112
+ ? formatValue
113
+ : undefined;
114
+ if (formatValue && !format) {
115
+ throw new Error("docdex.dag_export format must be json, text, or dot");
116
+ }
117
+ const max_nodes = parseOptionalNumber(need.max_nodes);
118
+ return { type, session_id: session_id || undefined, format, max_nodes };
119
+ }
120
+ if (type === "file.read") {
121
+ const path = need.path?.trim();
122
+ if (!path)
123
+ throw new Error("file.read requires path");
124
+ return { type, path };
125
+ }
126
+ if (type === "file.list") {
127
+ const root = need.root?.trim();
128
+ if (!root)
129
+ throw new Error("file.list requires root");
130
+ const pattern = need.pattern?.trim();
131
+ return { type, root, pattern: pattern || undefined };
132
+ }
133
+ if (type === "file.diff") {
134
+ const rawPaths = need.paths?.trim();
135
+ const paths = rawPaths
136
+ ? rawPaths
137
+ .split(",")
138
+ .map((entry) => entry.trim())
139
+ .filter(Boolean)
140
+ : undefined;
141
+ return { type, paths };
142
+ }
143
+ if (type === "agent.delegate") {
144
+ const goal = need.goal?.trim();
145
+ if (!goal)
146
+ throw new Error("agent.delegate requires goal");
147
+ const roleValue = need.role?.trim();
148
+ const role = roleValue && ["explorer", "reviewer", "worker", "verifier", "custom"].includes(roleValue)
149
+ ? roleValue
150
+ : undefined;
151
+ if (roleValue && !role) {
152
+ throw new Error("agent.delegate role must be explorer, reviewer, worker, verifier, or custom");
153
+ }
154
+ return {
155
+ type,
156
+ role,
157
+ goal,
158
+ tools: parseOptionalStringList(need.tools),
159
+ allowed_paths: parseOptionalStringList(need.allowed_paths),
160
+ write_paths: parseOptionalStringList(need.write_paths),
161
+ read_only: parseOptionalBoolean(need.read_only),
162
+ max_steps: parseOptionalNumber(need.max_steps),
163
+ max_tool_calls: parseOptionalNumber(need.max_tool_calls),
164
+ timeout_ms: parseOptionalNumber(need.timeout_ms),
165
+ };
166
+ }
167
+ throw new Error(`Unsupported need type: ${type}`);
168
+ };
169
+ export const parseAgentRequest = (input, options = {}) => {
170
+ const trimmed = input.trim();
171
+ if (!trimmed) {
172
+ throw new Error("Agent request is empty");
173
+ }
174
+ if (trimmed.startsWith("{")) {
175
+ const parsed = JSON.parse(trimmed);
176
+ if (!parsed.request_id && !options.defaultRequestId)
177
+ throw new Error("Agent request missing request_id");
178
+ if (!parsed.needs || !Array.isArray(parsed.needs) || parsed.needs.length === 0) {
179
+ throw new Error("Agent request needs must be a non-empty array");
180
+ }
181
+ return {
182
+ version: "v1",
183
+ role: parsed.role ?? "unknown",
184
+ request_id: parsed.request_id ?? options.defaultRequestId,
185
+ needs: parsed.needs,
186
+ context: parsed.context,
187
+ };
188
+ }
189
+ const lines = trimmed.split(/\r?\n/);
190
+ const header = lines.shift()?.trim();
191
+ if (!header || !/^AGENT_REQUEST\s+v1$/i.test(header)) {
192
+ throw new Error("Agent request missing AGENT_REQUEST v1 header");
193
+ }
194
+ let role = "unknown";
195
+ let request_id = "";
196
+ const needs = [];
197
+ let contextSummary;
198
+ let mode = "none";
199
+ let currentNeed = null;
200
+ for (const rawLine of lines) {
201
+ const line = rawLine.trimEnd();
202
+ if (!line.trim())
203
+ continue;
204
+ const trimmedLine = line.trim();
205
+ const isTopLevel = !/^\s/.test(rawLine);
206
+ if (trimmedLine.startsWith("needs:")) {
207
+ mode = "needs";
208
+ continue;
209
+ }
210
+ if (trimmedLine.startsWith("context:")) {
211
+ if (currentNeed) {
212
+ needs.push(coerceNeed(currentNeed));
213
+ currentNeed = null;
214
+ }
215
+ mode = "context";
216
+ continue;
217
+ }
218
+ if (isTopLevel) {
219
+ const kv = parseYamlKeyValue(trimmedLine);
220
+ if (kv && (kv.key === "role" || kv.key === "request_id")) {
221
+ if (currentNeed) {
222
+ needs.push(coerceNeed(currentNeed));
223
+ currentNeed = null;
224
+ }
225
+ if (kv.key === "role")
226
+ role = parseQuotedValue(kv.value);
227
+ if (kv.key === "request_id")
228
+ request_id = parseQuotedValue(kv.value);
229
+ continue;
230
+ }
231
+ }
232
+ if (mode === "needs") {
233
+ if (trimmedLine.startsWith("-")) {
234
+ if (currentNeed) {
235
+ needs.push(coerceNeed(currentNeed));
236
+ }
237
+ currentNeed = {};
238
+ const rest = line.replace(/^\s*-\s*/, "");
239
+ if (rest) {
240
+ const kv = parseYamlKeyValue(rest);
241
+ if (kv) {
242
+ currentNeed[kv.key] = parseQuotedValue(kv.value);
243
+ }
244
+ }
245
+ continue;
246
+ }
247
+ if (currentNeed) {
248
+ const kv = parseYamlKeyValue(trimmedLine);
249
+ if (kv) {
250
+ currentNeed[kv.key] = parseQuotedValue(kv.value);
251
+ }
252
+ continue;
253
+ }
254
+ }
255
+ if (mode === "context") {
256
+ const kv = parseYamlKeyValue(trimmedLine);
257
+ if (kv && kv.key === "summary") {
258
+ contextSummary = parseQuotedValue(kv.value);
259
+ }
260
+ continue;
261
+ }
262
+ const kv = parseYamlKeyValue(trimmedLine);
263
+ if (!kv)
264
+ continue;
265
+ if (kv.key === "role")
266
+ role = parseQuotedValue(kv.value);
267
+ if (kv.key === "request_id")
268
+ request_id = parseQuotedValue(kv.value);
269
+ }
270
+ if (currentNeed) {
271
+ needs.push(coerceNeed(currentNeed));
272
+ }
273
+ if (!request_id) {
274
+ if (!options.defaultRequestId)
275
+ throw new Error("Agent request missing request_id");
276
+ request_id = options.defaultRequestId;
277
+ }
278
+ if (needs.length === 0)
279
+ throw new Error("Agent request needs must be a non-empty array");
280
+ return {
281
+ version: "v1",
282
+ role,
283
+ request_id,
284
+ needs,
285
+ context: contextSummary ? { summary: contextSummary } : undefined,
286
+ };
287
+ };
288
+ export const normalizeAgentRequest = (request) => request.needs.map((need) => {
289
+ if (need.type === "docdex.search") {
290
+ return { tool: "docdex.search", params: { query: need.query, limit: need.limit } };
291
+ }
292
+ if (need.type === "docdex.open") {
293
+ return {
294
+ tool: "docdex.open",
295
+ params: {
296
+ path: need.path,
297
+ start_line: need.start_line,
298
+ end_line: need.end_line,
299
+ head: need.head,
300
+ clamp: need.clamp,
301
+ },
302
+ };
303
+ }
304
+ if (need.type === "docdex.snippet") {
305
+ return { tool: "docdex.snippet", params: { doc_id: need.doc_id, window: need.window } };
306
+ }
307
+ if (need.type === "docdex.symbols") {
308
+ return { tool: "docdex.symbols", params: { file: need.file } };
309
+ }
310
+ if (need.type === "docdex.ast") {
311
+ return { tool: "docdex.ast", params: { file: need.file, max_nodes: need.max_nodes } };
312
+ }
313
+ if (need.type === "docdex.web") {
314
+ return { tool: "docdex.web", params: { query: need.query, force_web: need.force_web } };
315
+ }
316
+ if (need.type === "docdex.impact") {
317
+ return { tool: "docdex.impact", params: { file: need.file } };
318
+ }
319
+ if (need.type === "docdex.impact_diagnostics") {
320
+ return {
321
+ tool: "docdex.impact_diagnostics",
322
+ params: { file: need.file, limit: need.limit, offset: need.offset },
323
+ };
324
+ }
325
+ if (need.type === "docdex.tree") {
326
+ return {
327
+ tool: "docdex.tree",
328
+ params: {
329
+ path: need.path,
330
+ max_depth: need.max_depth,
331
+ dirs_only: need.dirs_only,
332
+ include_hidden: need.include_hidden,
333
+ },
334
+ };
335
+ }
336
+ if (need.type === "docdex.dag_export") {
337
+ return {
338
+ tool: "docdex.dag_export",
339
+ params: { session_id: need.session_id, format: need.format, max_nodes: need.max_nodes },
340
+ };
341
+ }
342
+ if (need.type === "file.list") {
343
+ return { tool: "file.list", params: { root: need.root, pattern: need.pattern } };
344
+ }
345
+ if (need.type === "file.diff") {
346
+ return { tool: "file.diff", params: { paths: need.paths } };
347
+ }
348
+ if (need.type === "agent.delegate") {
349
+ return {
350
+ tool: "agent.delegate",
351
+ params: {
352
+ role: need.role ?? "explorer",
353
+ goal: need.goal,
354
+ tools: need.tools,
355
+ allowed_paths: need.allowed_paths,
356
+ write_paths: need.write_paths,
357
+ read_only: need.read_only,
358
+ max_steps: need.max_steps,
359
+ max_tool_calls: need.max_tool_calls,
360
+ timeout_ms: need.timeout_ms,
361
+ },
362
+ };
363
+ }
364
+ return { tool: "file.read", params: { path: need.path } };
365
+ });
@@ -0,0 +1,23 @@
1
+ import { GlobalRepository } from "@mcoda/db";
2
+ import { type Agent } from "@mcoda/shared";
3
+ export interface AgentResolutionOverrides {
4
+ provider?: string;
5
+ model?: string;
6
+ baseUrl?: string;
7
+ apiKey?: string;
8
+ }
9
+ export interface ResolvedAgentConfig {
10
+ agent: Agent;
11
+ provider: string;
12
+ model: string;
13
+ baseUrl?: string;
14
+ apiKey?: string;
15
+ requiresApiKey: boolean;
16
+ }
17
+ export declare const resolveProviderFromAdapter: (adapter: string, explicitProvider?: string) => {
18
+ provider: string;
19
+ requiresApiKey: boolean;
20
+ };
21
+ export declare const resolveAgentConfigFromRecord: (agent: Agent, repo: GlobalRepository, overrides?: AgentResolutionOverrides) => Promise<ResolvedAgentConfig>;
22
+ export declare const resolveAgentConfig: (agentRef: string, overrides?: AgentResolutionOverrides) => Promise<ResolvedAgentConfig>;
23
+ //# sourceMappingURL=AgentResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentResolver.d.ts","sourceRoot":"","sources":["../../src/agents/AgentResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;CACzB;AAoBD,eAAO,MAAM,0BAA0B,GACrC,SAAS,MAAM,EACf,mBAAmB,MAAM,KACxB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAwB7C,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,OAAO,KAAK,EACZ,MAAM,gBAAgB,EACtB,YAAW,wBAA6B,KACvC,OAAO,CAAC,mBAAmB,CAsC7B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,YAAW,wBAA6B,KACvC,OAAO,CAAC,mBAAmB,CAY7B,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { GlobalRepository } from "@mcoda/db";
2
+ import { CryptoHelper } from "@mcoda/shared";
3
+ const PROVIDERS_REQUIRING_API_KEY = new Set(["openai-compatible"]);
4
+ const PROVIDERS_REQUIRING_BASE_URL = new Set(["ollama-remote"]);
5
+ const SESSION_AUTH_ADAPTERS = new Set(["codex-cli", "openai-cli", "gemini-cli"]);
6
+ const UNSUPPORTED_CODALI_ADAPTERS = new Set(["gemini-cli", "zhipu-api"]);
7
+ const resolveString = (value) => {
8
+ return typeof value === "string" && value.trim() ? value : undefined;
9
+ };
10
+ const resolveBaseUrl = (agent) => {
11
+ const config = (agent.config ?? {});
12
+ return (resolveString(config.baseUrl) ??
13
+ resolveString(config.endpoint) ??
14
+ resolveString(config.apiBaseUrl));
15
+ };
16
+ export const resolveProviderFromAdapter = (adapter, explicitProvider) => {
17
+ if (explicitProvider) {
18
+ const requiresApiKey = PROVIDERS_REQUIRING_API_KEY.has(explicitProvider) &&
19
+ !SESSION_AUTH_ADAPTERS.has(adapter);
20
+ return { provider: explicitProvider, requiresApiKey };
21
+ }
22
+ if (UNSUPPORTED_CODALI_ADAPTERS.has(adapter)) {
23
+ throw new Error(`CODALI_UNSUPPORTED_ADAPTER: ${adapter} is not supported; configure a codali provider explicitly or choose a different agent.`);
24
+ }
25
+ if (adapter === "openai-api") {
26
+ return { provider: "openai-compatible", requiresApiKey: true };
27
+ }
28
+ if (["openai-cli", "codex-cli"].includes(adapter)) {
29
+ return { provider: "codex-cli", requiresApiKey: false };
30
+ }
31
+ if (["ollama-remote", "ollama-cli", "local-model"].includes(adapter)) {
32
+ return { provider: "ollama-remote", requiresApiKey: false };
33
+ }
34
+ throw new Error(`CODALI_UNSUPPORTED_ADAPTER: ${adapter} is not supported; configure a codali provider explicitly or choose a different agent.`);
35
+ };
36
+ export const resolveAgentConfigFromRecord = async (agent, repo, overrides = {}) => {
37
+ const { provider, requiresApiKey } = resolveProviderFromAdapter(agent.adapter, overrides.provider);
38
+ if (provider === "openai-compatible" && agent.openaiCompatible === false) {
39
+ const label = agent.slug ?? agent.id;
40
+ throw new Error(`Agent ${label} is not marked openai-compatible; update the agent metadata or choose a different provider.`);
41
+ }
42
+ const model = overrides.model ?? agent.defaultModel;
43
+ if (!model) {
44
+ const label = agent.slug ?? agent.id;
45
+ throw new Error(`Agent ${label} has no default model`);
46
+ }
47
+ const baseUrl = overrides.baseUrl ?? resolveBaseUrl(agent);
48
+ if (PROVIDERS_REQUIRING_BASE_URL.has(provider) && !baseUrl) {
49
+ const label = agent.slug ?? agent.id;
50
+ throw new Error(`Agent ${label} is missing a baseUrl for provider ${provider}; update the agent config.`);
51
+ }
52
+ let apiKey = overrides.apiKey;
53
+ if (!apiKey && requiresApiKey) {
54
+ const secret = await repo.getAgentAuthSecret(agent.id);
55
+ if (secret?.encryptedSecret) {
56
+ apiKey = await CryptoHelper.decryptSecret(secret.encryptedSecret);
57
+ }
58
+ }
59
+ if (requiresApiKey && !apiKey) {
60
+ const label = agent.slug ?? agent.id;
61
+ throw new Error(`AUTH_REQUIRED: API key missing for agent ${label}; run \"mcoda agent auth set ${label}\".`);
62
+ }
63
+ return { agent, provider, model, baseUrl, apiKey, requiresApiKey };
64
+ };
65
+ export const resolveAgentConfig = async (agentRef, overrides = {}) => {
66
+ const repo = await GlobalRepository.create();
67
+ try {
68
+ const agent = (await repo.getAgentById(agentRef)) ?? (await repo.getAgentBySlug(agentRef));
69
+ if (!agent) {
70
+ throw new Error(`Agent ${agentRef} not found`);
71
+ }
72
+ return await resolveAgentConfigFromRecord(agent, repo, overrides);
73
+ }
74
+ finally {
75
+ await repo.close();
76
+ }
77
+ };
@@ -0,0 +1,23 @@
1
+ import type { Agent } from "@mcoda/shared";
2
+ import type { PipelinePhase } from "../cognitive/ProviderRouting.js";
3
+ import type { BuilderConfig } from "../config/Config.js";
4
+ import { type ResolvedAgentConfig } from "./AgentResolver.js";
5
+ export type PhaseAgentSource = "override" | "auto" | "fallback" | "none";
6
+ export interface PhaseAgentSelection {
7
+ phase: PipelinePhase;
8
+ agent?: Agent;
9
+ capabilities: string[];
10
+ resolved?: ResolvedAgentConfig;
11
+ source: PhaseAgentSource;
12
+ score?: number;
13
+ reason?: string;
14
+ }
15
+ export interface PhaseAgentSelectionOptions {
16
+ overrides: Partial<Record<PipelinePhase, string>>;
17
+ builderMode: BuilderConfig["mode"];
18
+ fallbackAgent?: ResolvedAgentConfig;
19
+ allowCloudModels?: boolean;
20
+ excludeAgentIds?: Partial<Record<PipelinePhase, string[]>>;
21
+ }
22
+ export declare const selectPhaseAgents: (options: PhaseAgentSelectionOptions) => Promise<Record<PipelinePhase, PhaseAgentSelection>>;
23
+ //# sourceMappingURL=PhaseAgentSelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhaseAgentSelector.d.ts","sourceRoot":"","sources":["../../src/agents/PhaseAgentSelector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;AAEzE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;CAC5D;AAuLD,eAAO,MAAM,iBAAiB,GAC5B,SAAS,0BAA0B,KAClC,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,mBAAmB,CAAC,CA6IpD,CAAC"}