@mcoda/mswarm 0.1.57 → 0.1.61

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 (250) hide show
  1. package/README.md +19 -0
  2. package/dist/codali-executor.d.ts +278 -0
  3. package/dist/codali-executor.d.ts.map +1 -0
  4. package/dist/codali-executor.js +243 -0
  5. package/dist/codali-executor.js.map +1 -0
  6. package/dist/runtime.d.ts +46 -1
  7. package/dist/runtime.d.ts.map +1 -1
  8. package/dist/runtime.js +298 -30
  9. package/dist/runtime.js.map +1 -1
  10. package/dist/server.d.ts.map +1 -1
  11. package/dist/server.js +66 -1
  12. package/dist/server.js.map +1 -1
  13. package/dist/vendor/codali/agents/AgentProtocol.d.ts +287 -0
  14. package/dist/vendor/codali/agents/AgentProtocol.d.ts.map +1 -0
  15. package/dist/vendor/codali/agents/AgentProtocol.js +365 -0
  16. package/dist/vendor/codali/agents/AgentResolver.d.ts +23 -0
  17. package/dist/vendor/codali/agents/AgentResolver.d.ts.map +1 -0
  18. package/dist/vendor/codali/agents/AgentResolver.js +77 -0
  19. package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts +23 -0
  20. package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts.map +1 -0
  21. package/dist/vendor/codali/agents/PhaseAgentSelector.js +287 -0
  22. package/dist/vendor/codali/cli/EvalCommand.d.ts +37 -0
  23. package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -0
  24. package/dist/vendor/codali/cli/EvalCommand.js +333 -0
  25. package/dist/vendor/codali/cli/FeedbackCommand.d.ts +22 -0
  26. package/dist/vendor/codali/cli/FeedbackCommand.d.ts.map +1 -0
  27. package/dist/vendor/codali/cli/FeedbackCommand.js +163 -0
  28. package/dist/vendor/codali/cli/RunCommand.d.ts +78 -0
  29. package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -0
  30. package/dist/vendor/codali/cli/RunCommand.js +2261 -0
  31. package/dist/vendor/codali/cli.d.ts +3 -0
  32. package/dist/vendor/codali/cli.d.ts.map +1 -0
  33. package/dist/vendor/codali/cli.js +109 -0
  34. package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts +107 -0
  35. package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts.map +1 -0
  36. package/dist/vendor/codali/cognitive/ArchitectPlanner.js +1726 -0
  37. package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts +25 -0
  38. package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts.map +1 -0
  39. package/dist/vendor/codali/cognitive/BuilderOutputParser.js +164 -0
  40. package/dist/vendor/codali/cognitive/BuilderRunner.d.ts +76 -0
  41. package/dist/vendor/codali/cognitive/BuilderRunner.d.ts.map +1 -0
  42. package/dist/vendor/codali/cognitive/BuilderRunner.js +1159 -0
  43. package/dist/vendor/codali/cognitive/ContextAssembler.d.ts +91 -0
  44. package/dist/vendor/codali/cognitive/ContextAssembler.d.ts.map +1 -0
  45. package/dist/vendor/codali/cognitive/ContextAssembler.js +4547 -0
  46. package/dist/vendor/codali/cognitive/ContextBudget.d.ts +19 -0
  47. package/dist/vendor/codali/cognitive/ContextBudget.d.ts.map +1 -0
  48. package/dist/vendor/codali/cognitive/ContextBudget.js +35 -0
  49. package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts +30 -0
  50. package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts.map +1 -0
  51. package/dist/vendor/codali/cognitive/ContextFileLoader.js +307 -0
  52. package/dist/vendor/codali/cognitive/ContextManager.d.ts +47 -0
  53. package/dist/vendor/codali/cognitive/ContextManager.d.ts.map +1 -0
  54. package/dist/vendor/codali/cognitive/ContextManager.js +272 -0
  55. package/dist/vendor/codali/cognitive/ContextRedactor.d.ts +18 -0
  56. package/dist/vendor/codali/cognitive/ContextRedactor.d.ts.map +1 -0
  57. package/dist/vendor/codali/cognitive/ContextRedactor.js +53 -0
  58. package/dist/vendor/codali/cognitive/ContextSelector.d.ts +22 -0
  59. package/dist/vendor/codali/cognitive/ContextSelector.d.ts.map +1 -0
  60. package/dist/vendor/codali/cognitive/ContextSelector.js +431 -0
  61. package/dist/vendor/codali/cognitive/ContextSerializer.d.ts +8 -0
  62. package/dist/vendor/codali/cognitive/ContextSerializer.d.ts.map +1 -0
  63. package/dist/vendor/codali/cognitive/ContextSerializer.js +882 -0
  64. package/dist/vendor/codali/cognitive/ContextStore.d.ts +27 -0
  65. package/dist/vendor/codali/cognitive/ContextStore.d.ts.map +1 -0
  66. package/dist/vendor/codali/cognitive/ContextStore.js +79 -0
  67. package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts +16 -0
  68. package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts.map +1 -0
  69. package/dist/vendor/codali/cognitive/ContextSummarizer.js +45 -0
  70. package/dist/vendor/codali/cognitive/CostEstimator.d.ts +31 -0
  71. package/dist/vendor/codali/cognitive/CostEstimator.d.ts.map +1 -0
  72. package/dist/vendor/codali/cognitive/CostEstimator.js +66 -0
  73. package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts +32 -0
  74. package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts.map +1 -0
  75. package/dist/vendor/codali/cognitive/CriticEvaluator.js +297 -0
  76. package/dist/vendor/codali/cognitive/EvidenceGate.d.ts +9 -0
  77. package/dist/vendor/codali/cognitive/EvidenceGate.d.ts.map +1 -0
  78. package/dist/vendor/codali/cognitive/EvidenceGate.js +75 -0
  79. package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts +12 -0
  80. package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts.map +1 -0
  81. package/dist/vendor/codali/cognitive/GoldenExampleIndexer.js +34 -0
  82. package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts +33 -0
  83. package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts.map +1 -0
  84. package/dist/vendor/codali/cognitive/GoldenSetStore.js +159 -0
  85. package/dist/vendor/codali/cognitive/IntentSignals.d.ts +7 -0
  86. package/dist/vendor/codali/cognitive/IntentSignals.d.ts.map +1 -0
  87. package/dist/vendor/codali/cognitive/IntentSignals.js +285 -0
  88. package/dist/vendor/codali/cognitive/LearningGovernance.d.ts +100 -0
  89. package/dist/vendor/codali/cognitive/LearningGovernance.d.ts.map +1 -0
  90. package/dist/vendor/codali/cognitive/LearningGovernance.js +276 -0
  91. package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts +64 -0
  92. package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts.map +1 -0
  93. package/dist/vendor/codali/cognitive/MemoryWriteback.js +287 -0
  94. package/dist/vendor/codali/cognitive/PatchApplier.d.ts +49 -0
  95. package/dist/vendor/codali/cognitive/PatchApplier.d.ts.map +1 -0
  96. package/dist/vendor/codali/cognitive/PatchApplier.js +199 -0
  97. package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts +35 -0
  98. package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts.map +1 -0
  99. package/dist/vendor/codali/cognitive/PatchInterpreter.js +100 -0
  100. package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts +7 -0
  101. package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts.map +1 -0
  102. package/dist/vendor/codali/cognitive/PatchOutputNormalizer.js +59 -0
  103. package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts +17 -0
  104. package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts.map +1 -0
  105. package/dist/vendor/codali/cognitive/PostMortemAnalyzer.js +131 -0
  106. package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts +3 -0
  107. package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts.map +1 -0
  108. package/dist/vendor/codali/cognitive/PreferenceExtraction.js +85 -0
  109. package/dist/vendor/codali/cognitive/Prompts.d.ts +15 -0
  110. package/dist/vendor/codali/cognitive/Prompts.d.ts.map +1 -0
  111. package/dist/vendor/codali/cognitive/Prompts.js +326 -0
  112. package/dist/vendor/codali/cognitive/ProviderRouting.d.ts +16 -0
  113. package/dist/vendor/codali/cognitive/ProviderRouting.d.ts.map +1 -0
  114. package/dist/vendor/codali/cognitive/ProviderRouting.js +24 -0
  115. package/dist/vendor/codali/cognitive/QueryExtraction.d.ts +12 -0
  116. package/dist/vendor/codali/cognitive/QueryExtraction.d.ts.map +1 -0
  117. package/dist/vendor/codali/cognitive/QueryExtraction.js +262 -0
  118. package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts +13 -0
  119. package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts.map +1 -0
  120. package/dist/vendor/codali/cognitive/RunHistoryIndexer.js +125 -0
  121. package/dist/vendor/codali/cognitive/SmartPipeline.d.ts +92 -0
  122. package/dist/vendor/codali/cognitive/SmartPipeline.d.ts.map +1 -0
  123. package/dist/vendor/codali/cognitive/SmartPipeline.js +4804 -0
  124. package/dist/vendor/codali/cognitive/Types.d.ts +474 -0
  125. package/dist/vendor/codali/cognitive/Types.d.ts.map +1 -0
  126. package/dist/vendor/codali/cognitive/Types.js +7 -0
  127. package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +57 -0
  128. package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -0
  129. package/dist/vendor/codali/cognitive/ValidationRunner.js +515 -0
  130. package/dist/vendor/codali/config/Config.d.ts +249 -0
  131. package/dist/vendor/codali/config/Config.d.ts.map +1 -0
  132. package/dist/vendor/codali/config/Config.js +200 -0
  133. package/dist/vendor/codali/config/ConfigLoader.d.ts +56 -0
  134. package/dist/vendor/codali/config/ConfigLoader.d.ts.map +1 -0
  135. package/dist/vendor/codali/config/ConfigLoader.js +1246 -0
  136. package/dist/vendor/codali/docdex/DocdexClient.d.ts +158 -0
  137. package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
  138. package/dist/vendor/codali/docdex/DocdexClient.js +785 -0
  139. package/dist/vendor/codali/eval/EvalRunner.d.ts +35 -0
  140. package/dist/vendor/codali/eval/EvalRunner.d.ts.map +1 -0
  141. package/dist/vendor/codali/eval/EvalRunner.js +38 -0
  142. package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts +81 -0
  143. package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts.map +1 -0
  144. package/dist/vendor/codali/eval/EvalTaskExecutor.js +371 -0
  145. package/dist/vendor/codali/eval/GateEvaluator.d.ts +31 -0
  146. package/dist/vendor/codali/eval/GateEvaluator.d.ts.map +1 -0
  147. package/dist/vendor/codali/eval/GateEvaluator.js +134 -0
  148. package/dist/vendor/codali/eval/MetricTypes.d.ts +28 -0
  149. package/dist/vendor/codali/eval/MetricTypes.d.ts.map +1 -0
  150. package/dist/vendor/codali/eval/MetricTypes.js +1 -0
  151. package/dist/vendor/codali/eval/MetricsAggregator.d.ts +4 -0
  152. package/dist/vendor/codali/eval/MetricsAggregator.d.ts.map +1 -0
  153. package/dist/vendor/codali/eval/MetricsAggregator.js +97 -0
  154. package/dist/vendor/codali/eval/RegressionComparator.d.ts +29 -0
  155. package/dist/vendor/codali/eval/RegressionComparator.d.ts.map +1 -0
  156. package/dist/vendor/codali/eval/RegressionComparator.js +155 -0
  157. package/dist/vendor/codali/eval/ReportInputAdapter.d.ts +52 -0
  158. package/dist/vendor/codali/eval/ReportInputAdapter.d.ts.map +1 -0
  159. package/dist/vendor/codali/eval/ReportInputAdapter.js +229 -0
  160. package/dist/vendor/codali/eval/ReportSerializer.d.ts +32 -0
  161. package/dist/vendor/codali/eval/ReportSerializer.d.ts.map +1 -0
  162. package/dist/vendor/codali/eval/ReportSerializer.js +33 -0
  163. package/dist/vendor/codali/eval/ReportStore.d.ts +18 -0
  164. package/dist/vendor/codali/eval/ReportStore.d.ts.map +1 -0
  165. package/dist/vendor/codali/eval/ReportStore.js +96 -0
  166. package/dist/vendor/codali/eval/SuiteLoader.d.ts +12 -0
  167. package/dist/vendor/codali/eval/SuiteLoader.d.ts.map +1 -0
  168. package/dist/vendor/codali/eval/SuiteLoader.js +51 -0
  169. package/dist/vendor/codali/eval/SuiteSchema.d.ts +56 -0
  170. package/dist/vendor/codali/eval/SuiteSchema.d.ts.map +1 -0
  171. package/dist/vendor/codali/eval/SuiteSchema.js +357 -0
  172. package/dist/vendor/codali/index.d.ts +11 -0
  173. package/dist/vendor/codali/index.d.ts.map +1 -0
  174. package/dist/vendor/codali/index.js +5 -0
  175. package/dist/vendor/codali/providers/CodexCliProvider.d.ts +8 -0
  176. package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -0
  177. package/dist/vendor/codali/providers/CodexCliProvider.js +282 -0
  178. package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts +8 -0
  179. package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -0
  180. package/dist/vendor/codali/providers/OllamaRemoteProvider.js +300 -0
  181. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts +8 -0
  182. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -0
  183. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +192 -0
  184. package/dist/vendor/codali/providers/ProviderRegistry.d.ts +12 -0
  185. package/dist/vendor/codali/providers/ProviderRegistry.d.ts.map +1 -0
  186. package/dist/vendor/codali/providers/ProviderRegistry.js +28 -0
  187. package/dist/vendor/codali/providers/ProviderTypes.d.ts +81 -0
  188. package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -0
  189. package/dist/vendor/codali/providers/ProviderTypes.js +1 -0
  190. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +189 -0
  191. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
  192. package/dist/vendor/codali/runtime/CodaliRuntime.js +1435 -0
  193. package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts +39 -0
  194. package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts.map +1 -0
  195. package/dist/vendor/codali/runtime/DeepInvestigationErrors.js +57 -0
  196. package/dist/vendor/codali/runtime/RunContext.d.ts +27 -0
  197. package/dist/vendor/codali/runtime/RunContext.d.ts.map +1 -0
  198. package/dist/vendor/codali/runtime/RunContext.js +51 -0
  199. package/dist/vendor/codali/runtime/RunLogQuery.d.ts +48 -0
  200. package/dist/vendor/codali/runtime/RunLogQuery.d.ts.map +1 -0
  201. package/dist/vendor/codali/runtime/RunLogQuery.js +36 -0
  202. package/dist/vendor/codali/runtime/RunLogReader.d.ts +19 -0
  203. package/dist/vendor/codali/runtime/RunLogReader.d.ts.map +1 -0
  204. package/dist/vendor/codali/runtime/RunLogReader.js +361 -0
  205. package/dist/vendor/codali/runtime/RunLogger.d.ts +71 -0
  206. package/dist/vendor/codali/runtime/RunLogger.d.ts.map +1 -0
  207. package/dist/vendor/codali/runtime/RunLogger.js +100 -0
  208. package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts +117 -0
  209. package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts.map +1 -0
  210. package/dist/vendor/codali/runtime/RunTelemetryTypes.js +299 -0
  211. package/dist/vendor/codali/runtime/Runner.d.ts +66 -0
  212. package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -0
  213. package/dist/vendor/codali/runtime/Runner.js +215 -0
  214. package/dist/vendor/codali/runtime/StoragePaths.d.ts +3 -0
  215. package/dist/vendor/codali/runtime/StoragePaths.d.ts.map +1 -0
  216. package/dist/vendor/codali/runtime/StoragePaths.js +19 -0
  217. package/dist/vendor/codali/runtime/WorkspaceLock.d.ts +30 -0
  218. package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -0
  219. package/dist/vendor/codali/runtime/WorkspaceLock.js +141 -0
  220. package/dist/vendor/codali/session/InstructionLoader.d.ts +14 -0
  221. package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -0
  222. package/dist/vendor/codali/session/InstructionLoader.js +107 -0
  223. package/dist/vendor/codali/session/SessionStore.d.ts +81 -0
  224. package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -0
  225. package/dist/vendor/codali/session/SessionStore.js +244 -0
  226. package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts +68 -0
  227. package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts.map +1 -0
  228. package/dist/vendor/codali/subagents/SubagentOrchestrator.js +150 -0
  229. package/dist/vendor/codali/tools/ToolRegistry.d.ts +9 -0
  230. package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -0
  231. package/dist/vendor/codali/tools/ToolRegistry.js +293 -0
  232. package/dist/vendor/codali/tools/ToolTypes.d.ts +66 -0
  233. package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -0
  234. package/dist/vendor/codali/tools/ToolTypes.js +40 -0
  235. package/dist/vendor/codali/tools/diff/DiffTool.d.ts +3 -0
  236. package/dist/vendor/codali/tools/diff/DiffTool.d.ts.map +1 -0
  237. package/dist/vendor/codali/tools/diff/DiffTool.js +34 -0
  238. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +4 -0
  239. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -0
  240. package/dist/vendor/codali/tools/docdex/DocdexTools.js +490 -0
  241. package/dist/vendor/codali/tools/filesystem/FileTools.d.ts +3 -0
  242. package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -0
  243. package/dist/vendor/codali/tools/filesystem/FileTools.js +141 -0
  244. package/dist/vendor/codali/tools/search/SearchTool.d.ts +3 -0
  245. package/dist/vendor/codali/tools/search/SearchTool.d.ts.map +1 -0
  246. package/dist/vendor/codali/tools/search/SearchTool.js +46 -0
  247. package/dist/vendor/codali/tools/shell/ShellTool.d.ts +3 -0
  248. package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -0
  249. package/dist/vendor/codali/tools/shell/ShellTool.js +104 -0
  250. package/package.json +5 -3
@@ -0,0 +1,431 @@
1
+ const FRONTEND_EXTENSIONS = new Set([
2
+ ".html",
3
+ ".htm",
4
+ ".css",
5
+ ".scss",
6
+ ".sass",
7
+ ".less",
8
+ ".styl",
9
+ ".jsx",
10
+ ".tsx",
11
+ ".vue",
12
+ ".svelte",
13
+ ]);
14
+ const HTML_EXTENSIONS = new Set([".html", ".htm"]);
15
+ const STYLE_EXTENSIONS = new Set([
16
+ ".css",
17
+ ".scss",
18
+ ".sass",
19
+ ".less",
20
+ ".styl",
21
+ ]);
22
+ const FRONTEND_SCRIPT_EXTENSIONS = new Set([
23
+ ".js",
24
+ ".jsx",
25
+ ".ts",
26
+ ".tsx",
27
+ ".mjs",
28
+ ".cjs",
29
+ ]);
30
+ const FRONTEND_DIR_HINT_PATTERN = /(^|\/)(public|frontend|client|web|ui)(\/|$)/i;
31
+ const INFRA_PATH_PATTERN = /(^|\/)(\.github\/workflows|\.github\/actions|\.circleci|buildkite|jenkins|infra|deploy|ops|k8s|kubernetes|helm|terraform|ansible)(\/|$)/i;
32
+ const INFRA_FILE_PATTERN = /(dockerfile|docker-compose|compose\.ya?ml|makefile|\.gitlab-ci\.ya?ml)$/i;
33
+ const SECURITY_PATH_PATTERN = /(^|\/)(auth|security|permissions?|rbac|acl|policy|oauth|jwt|sso|crypto|secrets?)(\/|$|[._-])/i;
34
+ const PERFORMANCE_PATH_PATTERN = /(^|\/)(perf|performance|benchmark|profil(e|ing)|cache|rate[-_]?limit|throttle|batch|queue)(\/|$|[._-])/i;
35
+ const OBSERVABILITY_PATH_PATTERN = /(^|\/)(log|logger|metrics?|monitor|monitoring|trace|tracing|otel|sentry|datadog|prometheus|grafana|alert)(\/|$|[._-])/i;
36
+ const isFrontendFile = (value) => {
37
+ const normalized = value.toLowerCase();
38
+ const dot = normalized.lastIndexOf(".");
39
+ if (dot === -1)
40
+ return false;
41
+ const ext = normalized.slice(dot);
42
+ if (FRONTEND_EXTENSIONS.has(ext))
43
+ return true;
44
+ return FRONTEND_SCRIPT_EXTENSIONS.has(ext) && FRONTEND_DIR_HINT_PATTERN.test(normalized);
45
+ };
46
+ const isHtmlPath = (value) => {
47
+ const normalized = value.toLowerCase();
48
+ const dot = normalized.lastIndexOf(".");
49
+ if (dot === -1)
50
+ return false;
51
+ return HTML_EXTENSIONS.has(normalized.slice(dot));
52
+ };
53
+ const isStylePath = (value) => {
54
+ const normalized = value.toLowerCase();
55
+ const dot = normalized.lastIndexOf(".");
56
+ if (dot === -1)
57
+ return false;
58
+ return STYLE_EXTENSIONS.has(normalized.slice(dot));
59
+ };
60
+ const isDocPath = (value) => {
61
+ const normalized = value.toLowerCase();
62
+ return (normalized.startsWith("docs/") ||
63
+ normalized.endsWith(".md") ||
64
+ normalized.endsWith(".mdx") ||
65
+ normalized.endsWith(".rst") ||
66
+ normalized.endsWith(".txt"));
67
+ };
68
+ const isTestPath = (value) => {
69
+ const normalized = value.toLowerCase();
70
+ return (normalized.includes("/tests/") ||
71
+ normalized.includes("/test/") ||
72
+ normalized.includes("__tests__") ||
73
+ normalized.endsWith(".test.ts") ||
74
+ normalized.endsWith(".test.js") ||
75
+ normalized.endsWith(".spec.ts") ||
76
+ normalized.endsWith(".spec.js"));
77
+ };
78
+ const isInfraPath = (value) => {
79
+ const normalized = value.toLowerCase();
80
+ return INFRA_PATH_PATTERN.test(normalized) || INFRA_FILE_PATTERN.test(normalized);
81
+ };
82
+ const isSecurityPath = (value) => {
83
+ const normalized = value.toLowerCase();
84
+ return SECURITY_PATH_PATTERN.test(normalized);
85
+ };
86
+ const isPerformancePath = (value) => {
87
+ const normalized = value.toLowerCase();
88
+ return PERFORMANCE_PATH_PATTERN.test(normalized);
89
+ };
90
+ const isObservabilityPath = (value) => {
91
+ const normalized = value.toLowerCase();
92
+ return OBSERVABILITY_PATH_PATTERN.test(normalized);
93
+ };
94
+ const unique = (values) => {
95
+ const seen = new Set();
96
+ const result = [];
97
+ for (const value of values) {
98
+ if (seen.has(value))
99
+ continue;
100
+ seen.add(value);
101
+ result.push(value);
102
+ }
103
+ return result;
104
+ };
105
+ const buildImpactMap = (impact) => {
106
+ const map = new Map();
107
+ for (const entry of impact) {
108
+ map.set(entry.file, entry);
109
+ }
110
+ return map;
111
+ };
112
+ const addReason = (reasonMap, path, reason) => {
113
+ const normalized = path.trim();
114
+ if (!normalized)
115
+ return;
116
+ const existing = reasonMap.get(normalized);
117
+ if (existing) {
118
+ existing.add(reason);
119
+ return;
120
+ }
121
+ reasonMap.set(normalized, new Set([reason]));
122
+ };
123
+ const buildReasonSummary = (entries) => {
124
+ const counts = new Map();
125
+ for (const entry of entries) {
126
+ for (const reason of entry.inclusion_reasons) {
127
+ counts.set(reason, (counts.get(reason) ?? 0) + 1);
128
+ }
129
+ }
130
+ return Array.from(counts.entries())
131
+ .sort((left, right) => left[0].localeCompare(right[0]))
132
+ .map(([code, count]) => ({ code, count }));
133
+ };
134
+ const rankCandidates = (hitPaths, hitScores, preferred, input) => {
135
+ const uiIntent = input.intent?.intents.includes("ui") ?? false;
136
+ const contentIntent = input.intent?.intents.includes("content") ?? false;
137
+ const behaviorIntent = input.intent?.intents.includes("behavior") ?? false;
138
+ const dataIntent = input.intent?.intents.includes("data") ?? false;
139
+ const testingIntent = input.intent?.intents.includes("testing") ?? false;
140
+ const infraIntent = input.intent?.intents.includes("infra") ?? false;
141
+ const securityIntent = input.intent?.intents.includes("security") ?? false;
142
+ const performanceIntent = input.intent?.intents.includes("performance") ?? false;
143
+ const observabilityIntent = input.intent?.intents.includes("observability") ?? false;
144
+ const docTask = input.docTask ?? false;
145
+ const ranked = hitPaths.map((path, index) => {
146
+ let score = 0;
147
+ if (preferred.has(path))
148
+ score += 500;
149
+ score += hitScores.get(path) ?? 0;
150
+ if (uiIntent && isFrontendFile(path))
151
+ score += 120;
152
+ if (behaviorIntent && !isDocPath(path) && !isFrontendFile(path))
153
+ score += 30;
154
+ if (dataIntent && !isDocPath(path) && !isFrontendFile(path))
155
+ score += 20;
156
+ if (testingIntent && isTestPath(path))
157
+ score += 120;
158
+ if (infraIntent && isInfraPath(path))
159
+ score += 120;
160
+ if (securityIntent && isSecurityPath(path))
161
+ score += 80;
162
+ if (performanceIntent && isPerformancePath(path))
163
+ score += 80;
164
+ if (observabilityIntent && isObservabilityPath(path))
165
+ score += 80;
166
+ if (contentIntent && isDocPath(path))
167
+ score += 20;
168
+ if (!docTask && isDocPath(path))
169
+ score -= 80;
170
+ if (!docTask && isTestPath(path) && !behaviorIntent && !dataIntent && !testingIntent) {
171
+ score -= 30;
172
+ }
173
+ return { path, score, index };
174
+ });
175
+ ranked.sort((a, b) => {
176
+ if (a.score === b.score)
177
+ return a.index - b.index;
178
+ return b.score - a.score;
179
+ });
180
+ return ranked.map((entry) => entry.path);
181
+ };
182
+ export const selectContextFiles = (input, options) => {
183
+ const reasonMap = new Map();
184
+ const dropped = [];
185
+ const maxFiles = Math.max(1, options.maxFiles);
186
+ const focusCount = Math.max(1, options.focusCount ?? 2);
187
+ const uiIntent = input.intent?.intents.includes("ui") ?? false;
188
+ const preferred = unique(input.preferredFiles ?? []);
189
+ for (const path of preferred)
190
+ addReason(reasonMap, path, "preferred_file");
191
+ for (const path of input.recentFiles ?? [])
192
+ addReason(reasonMap, path, "recent_file");
193
+ const hitScores = new Map();
194
+ for (const hit of input.hits) {
195
+ if (typeof hit.path !== "string" || hit.path.length === 0)
196
+ continue;
197
+ addReason(reasonMap, hit.path, "search_hit");
198
+ if (typeof hit.score === "number" && Number.isFinite(hit.score)) {
199
+ const existing = hitScores.get(hit.path);
200
+ hitScores.set(hit.path, existing === undefined ? hit.score : Math.max(existing, hit.score));
201
+ }
202
+ }
203
+ let hitPaths = unique([
204
+ ...preferred,
205
+ ...input.hits
206
+ .map((hit) => hit.path)
207
+ .filter((path) => typeof path === "string" && path.length > 0),
208
+ ]);
209
+ hitPaths = rankCandidates(hitPaths, hitScores, new Set(preferred), input);
210
+ const minHitCount = Math.max(1, options.minHitCount ?? focusCount);
211
+ const lowConfidence = hitPaths.length < minHitCount && preferred.length === 0;
212
+ let focus = hitPaths.slice(0, Math.min(focusCount, maxFiles));
213
+ if (!input.docTask) {
214
+ const hasNonDoc = focus.some((entry) => !isDocPath(entry));
215
+ if (!hasNonDoc) {
216
+ const nonDocCandidate = hitPaths.find((entry) => !isDocPath(entry));
217
+ if (nonDocCandidate) {
218
+ focus = unique([nonDocCandidate, ...focus]).slice(0, Math.min(focusCount, maxFiles));
219
+ addReason(reasonMap, nonDocCandidate, "fallback_inserted_candidate");
220
+ }
221
+ }
222
+ }
223
+ if (uiIntent && !input.docTask && !focus.some((entry) => isFrontendFile(entry))) {
224
+ const frontendCandidate = unique([
225
+ ...hitPaths,
226
+ ...(input.recentFiles ?? []),
227
+ ...(input.preferredFiles ?? []),
228
+ ]).find((entry) => isFrontendFile(entry));
229
+ if (frontendCandidate) {
230
+ focus = unique([frontendCandidate, ...focus]).slice(0, Math.min(focusCount, maxFiles));
231
+ addReason(reasonMap, frontendCandidate, "ui_scaffold");
232
+ }
233
+ }
234
+ if (uiIntent && !input.docTask) {
235
+ const pool = unique([
236
+ ...hitPaths,
237
+ ...(input.recentFiles ?? []),
238
+ ...(input.preferredFiles ?? []),
239
+ ]);
240
+ const needsHtml = !focus.some((entry) => isHtmlPath(entry));
241
+ const needsStyle = !focus.some((entry) => isStylePath(entry));
242
+ const pickCandidate = (predicate) => pool.find((entry) => predicate(entry) && !focus.includes(entry));
243
+ const injectFocusCandidate = (candidate) => {
244
+ if (!candidate)
245
+ return;
246
+ if (focus.includes(candidate))
247
+ return;
248
+ addReason(reasonMap, candidate, "ui_scaffold");
249
+ if (focus.length < focusCount) {
250
+ focus = unique([candidate, ...focus]).slice(0, Math.min(focusCount, maxFiles));
251
+ return;
252
+ }
253
+ const replaceIndex = focus.findIndex((entry) => isDocPath(entry) || isTestPath(entry));
254
+ const targetIndex = replaceIndex >= 0 ? replaceIndex : Math.max(0, focus.length - 1);
255
+ focus = [...focus];
256
+ focus[targetIndex] = candidate;
257
+ };
258
+ if (needsHtml || needsStyle) {
259
+ if (focusCount <= 1) {
260
+ injectFocusCandidate(pickCandidate(isHtmlPath) ?? pickCandidate(isStylePath));
261
+ }
262
+ else {
263
+ if (needsHtml)
264
+ injectFocusCandidate(pickCandidate(isHtmlPath));
265
+ if (needsStyle)
266
+ injectFocusCandidate(pickCandidate(isStylePath));
267
+ }
268
+ }
269
+ }
270
+ for (const entry of focus) {
271
+ if (!reasonMap.has(entry))
272
+ addReason(reasonMap, entry, "fallback_inserted_candidate");
273
+ }
274
+ const impactMap = buildImpactMap(input.impact);
275
+ const peripheryCandidates = [];
276
+ for (const focusFile of focus) {
277
+ const impact = impactMap.get(focusFile);
278
+ if (!impact)
279
+ continue;
280
+ const neighbors = [...impact.outbound, ...impact.inbound];
281
+ for (const neighbor of neighbors) {
282
+ addReason(reasonMap, neighbor, "impact_neighbor");
283
+ }
284
+ peripheryCandidates.push(...neighbors);
285
+ }
286
+ const periphery = unique(peripheryCandidates).filter((path) => !focus.includes(path));
287
+ const combined = [...focus];
288
+ for (const candidate of periphery) {
289
+ if (combined.length >= maxFiles)
290
+ break;
291
+ combined.push(candidate);
292
+ }
293
+ if (combined.length < maxFiles) {
294
+ for (const candidate of hitPaths) {
295
+ if (combined.length >= maxFiles)
296
+ break;
297
+ if (!combined.includes(candidate)) {
298
+ combined.push(candidate);
299
+ addReason(reasonMap, candidate, "fallback_inserted_candidate");
300
+ }
301
+ }
302
+ }
303
+ if (input.recentFiles && combined.length < maxFiles) {
304
+ for (const candidate of input.recentFiles) {
305
+ if (combined.length >= maxFiles)
306
+ break;
307
+ if (!combined.includes(candidate)) {
308
+ combined.push(candidate);
309
+ addReason(reasonMap, candidate, "recent_file");
310
+ }
311
+ }
312
+ }
313
+ if (uiIntent && !input.docTask) {
314
+ const hasNonFrontendCodeCandidate = combined.some((path) => !isFrontendFile(path) && !isDocPath(path) && !isTestPath(path));
315
+ if (!hasNonFrontendCodeCandidate) {
316
+ const crossSurfaceCandidate = unique([
317
+ ...hitPaths,
318
+ ...(input.recentFiles ?? []),
319
+ ...(input.preferredFiles ?? []),
320
+ ]).find((path) => !isFrontendFile(path) && !isDocPath(path) && !isTestPath(path));
321
+ if (crossSurfaceCandidate && !combined.includes(crossSurfaceCandidate)) {
322
+ if (combined.length < maxFiles) {
323
+ combined.push(crossSurfaceCandidate);
324
+ addReason(reasonMap, crossSurfaceCandidate, "fallback_inserted_candidate");
325
+ }
326
+ else {
327
+ const replaceIndex = [...combined]
328
+ .reverse()
329
+ .findIndex((entry) => isDocPath(entry) || isTestPath(entry));
330
+ if (replaceIndex >= 0) {
331
+ const targetIndex = combined.length - 1 - replaceIndex;
332
+ const displaced = combined[targetIndex];
333
+ if (displaced) {
334
+ dropped.push({
335
+ path: displaced,
336
+ category: isDocPath(displaced) ? "doc_heavy_demotion" : "low_signal_candidate",
337
+ reason_code: isDocPath(displaced) ? "doc_heavy_demotion" : "low_signal_candidate",
338
+ detail: "replaced_for_cross_surface_coverage",
339
+ });
340
+ }
341
+ combined[targetIndex] = crossSurfaceCandidate;
342
+ addReason(reasonMap, crossSurfaceCandidate, "fallback_inserted_candidate");
343
+ }
344
+ }
345
+ }
346
+ }
347
+ }
348
+ if (!input.docTask) {
349
+ const maxDocPeriphery = 1;
350
+ const maxTestPeriphery = 1;
351
+ const filtered = [...focus];
352
+ let docCount = 0;
353
+ let testCount = 0;
354
+ const rankedRemainder = combined
355
+ .filter((path) => !focus.includes(path))
356
+ .sort((a, b) => {
357
+ const category = (value) => {
358
+ if (uiIntent) {
359
+ if (isFrontendFile(value))
360
+ return 0;
361
+ if (!isDocPath(value) && !isTestPath(value))
362
+ return 1;
363
+ if (isTestPath(value))
364
+ return 2;
365
+ if (isDocPath(value))
366
+ return 3;
367
+ }
368
+ return 0;
369
+ };
370
+ return category(a) - category(b);
371
+ });
372
+ for (const candidate of rankedRemainder) {
373
+ if (isDocPath(candidate)) {
374
+ if (docCount >= maxDocPeriphery) {
375
+ dropped.push({
376
+ path: candidate,
377
+ category: "doc_heavy_demotion",
378
+ reason_code: "doc_heavy_demotion",
379
+ detail: "non_doc_task_doc_cap",
380
+ });
381
+ continue;
382
+ }
383
+ docCount += 1;
384
+ }
385
+ if (isTestPath(candidate)) {
386
+ if (testCount >= maxTestPeriphery) {
387
+ dropped.push({
388
+ path: candidate,
389
+ category: "test_doc_cap",
390
+ reason_code: "test_doc_cap",
391
+ detail: "non_doc_task_test_cap",
392
+ });
393
+ continue;
394
+ }
395
+ testCount += 1;
396
+ }
397
+ filtered.push(candidate);
398
+ if (filtered.length >= maxFiles)
399
+ break;
400
+ }
401
+ combined.splice(0, combined.length, ...filtered.slice(0, maxFiles));
402
+ }
403
+ for (const candidate of hitPaths) {
404
+ if (!combined.includes(candidate)) {
405
+ dropped.push({
406
+ path: candidate,
407
+ category: "low_signal_candidate",
408
+ reason_code: "low_signal_candidate",
409
+ });
410
+ }
411
+ }
412
+ const entries = combined.map((path) => {
413
+ const inclusion_reasons = Array.from(reasonMap.get(path) ?? new Set());
414
+ if (inclusion_reasons.length === 0)
415
+ inclusion_reasons.push("fallback_inserted_candidate");
416
+ return {
417
+ path,
418
+ role: focus.includes(path) ? "focus" : "periphery",
419
+ inclusion_reasons,
420
+ };
421
+ });
422
+ return {
423
+ focus,
424
+ periphery: combined.filter((path) => !focus.includes(path)),
425
+ all: combined,
426
+ low_confidence: lowConfidence,
427
+ entries,
428
+ dropped,
429
+ reason_summary: buildReasonSummary(entries),
430
+ };
431
+ };
@@ -0,0 +1,8 @@
1
+ import type { ContextBundle, SerializedContext } from "./Types.js";
2
+ export interface ContextSerializerOptions {
3
+ mode: "bundle_text" | "json";
4
+ audience?: "librarian" | "builder";
5
+ }
6
+ export declare const sanitizeContextBundleForOutput: (bundle: ContextBundle) => ContextBundle;
7
+ export declare const serializeContext: (bundle: ContextBundle, options: ContextSerializerOptions) => SerializedContext;
8
+ //# sourceMappingURL=ContextSerializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextSerializer.d.ts","sourceRoot":"","sources":["../../src/cognitive/ContextSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGb,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CACpC;AAmwBD,eAAO,MAAM,8BAA8B,GAAI,QAAQ,aAAa,KAAG,aAOtE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,aAAa,EACrB,SAAS,wBAAwB,KAChC,iBA6IF,CAAC"}