@mcoda/mswarm 0.1.57 → 0.1.60

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 +266 -0
  3. package/dist/codali-executor.d.ts.map +1 -0
  4. package/dist/codali-executor.js +227 -0
  5. package/dist/codali-executor.js.map +1 -0
  6. package/dist/runtime.d.ts +36 -1
  7. package/dist/runtime.d.ts.map +1 -1
  8. package/dist/runtime.js +219 -30
  9. package/dist/runtime.js.map +1 -1
  10. package/dist/server.d.ts.map +1 -1
  11. package/dist/server.js +54 -0
  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 +113 -0
  137. package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
  138. package/dist/vendor/codali/docdex/DocdexClient.js +524 -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 +183 -0
  191. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
  192. package/dist/vendor/codali/runtime/CodaliRuntime.js +1363 -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 +263 -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 +32 -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 +453 -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,515 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ const DEFAULT_SHELL_TIMEOUT_MS = 120000;
5
+ const parseHookFiles = (step) => {
6
+ const parts = step.split(":");
7
+ if (parts.length < 2)
8
+ return [];
9
+ return parts
10
+ .slice(1)
11
+ .join(":")
12
+ .split(",")
13
+ .map((entry) => entry.trim())
14
+ .filter(Boolean);
15
+ };
16
+ const detectCheckType = (step) => {
17
+ if (step.startsWith("docdex:hooks") || step.startsWith("hooks:"))
18
+ return "docdex_hooks";
19
+ if (!step.trim())
20
+ return "unknown";
21
+ return "shell";
22
+ };
23
+ const detectTargetedStep = (step) => {
24
+ if (!step.trim())
25
+ return false;
26
+ if (/\b(--filter|--grep|--testPathPattern|--findRelatedTests)\b/i.test(step))
27
+ return true;
28
+ return /(^|\s)(?:\.{0,2}\/)?[\w./-]+\.[\w-]+(\s|$)/.test(step);
29
+ };
30
+ const checkTypeOrder = (value) => {
31
+ if (value === "docdex_hooks")
32
+ return 0;
33
+ if (value === "shell")
34
+ return 1;
35
+ return 2;
36
+ };
37
+ const compactText = (value, maxLength = 240) => {
38
+ const trimmed = (value ?? "").trim();
39
+ if (!trimmed)
40
+ return undefined;
41
+ if (trimmed.length <= maxLength)
42
+ return trimmed;
43
+ return `${trimmed.slice(0, maxLength - 1)}…`;
44
+ };
45
+ const detectLanguageSignals = (touchedFiles) => {
46
+ const signals = new Set();
47
+ for (const file of touchedFiles) {
48
+ const ext = path.extname(file).toLowerCase();
49
+ if (ext === ".ts" || ext === ".tsx")
50
+ signals.add("typescript");
51
+ else if (ext === ".js" || ext === ".jsx" || ext === ".mjs" || ext === ".cjs")
52
+ signals.add("javascript");
53
+ else if (ext === ".py")
54
+ signals.add("python");
55
+ else if (ext === ".go")
56
+ signals.add("go");
57
+ else if (ext === ".rs")
58
+ signals.add("rust");
59
+ else if (ext === ".java")
60
+ signals.add("java");
61
+ else if (ext === ".rb")
62
+ signals.add("ruby");
63
+ else if (ext === ".cs")
64
+ signals.add("dotnet");
65
+ }
66
+ return [...signals].sort();
67
+ };
68
+ const detectProjectSignals = (workspaceRoot) => {
69
+ const has = (file) => existsSync(path.join(workspaceRoot, file));
70
+ const signals = new Set();
71
+ if (has(".git"))
72
+ signals.add("git_repo");
73
+ if (has("package.json"))
74
+ signals.add("package_json");
75
+ if (has("pnpm-lock.yaml") || has("pnpm-workspace.yaml"))
76
+ signals.add("pnpm");
77
+ if (has("yarn.lock"))
78
+ signals.add("yarn");
79
+ if (has("package-lock.json"))
80
+ signals.add("npm_lock");
81
+ if (has("pyproject.toml"))
82
+ signals.add("pyproject");
83
+ if (has("requirements.txt"))
84
+ signals.add("requirements_txt");
85
+ if (has("go.mod"))
86
+ signals.add("go_mod");
87
+ if (has("Cargo.toml"))
88
+ signals.add("cargo_toml");
89
+ if (has("pom.xml"))
90
+ signals.add("maven");
91
+ if (has("build.gradle") || has("build.gradle.kts"))
92
+ signals.add("gradle");
93
+ if (has(".pre-commit-config.yaml"))
94
+ signals.add("pre_commit");
95
+ return [...signals].sort();
96
+ };
97
+ const detectCategoryFromStep = (step) => {
98
+ if (step.startsWith("docdex:hooks") || step.startsWith("hooks:"))
99
+ return "hook";
100
+ if (/\b(test|jest|vitest|pytest|go test|cargo test)\b/i.test(step))
101
+ return "test";
102
+ if (/\b(lint|ruff|eslint)\b/i.test(step))
103
+ return "lint";
104
+ if (/\b(build|tsc|webpack|vite build|cargo build|go build)\b/i.test(step))
105
+ return "build";
106
+ return "unknown";
107
+ };
108
+ const normalizeExplicitChecks = (steps) => [...(Array.isArray(steps) ? steps : [])]
109
+ .map((entry) => entry.trim())
110
+ .filter((entry, index, all) => entry.length > 0 && all.indexOf(entry) === index)
111
+ .map((step) => ({
112
+ step,
113
+ check_type: detectCheckType(step),
114
+ category: detectCategoryFromStep(step),
115
+ targeted: detectTargetedStep(step),
116
+ source: "explicit",
117
+ rationale: "plan_verification_step",
118
+ }));
119
+ const chooseNodePackageManager = (projectSignals) => {
120
+ if (projectSignals.includes("pnpm"))
121
+ return "pnpm";
122
+ if (projectSignals.includes("yarn"))
123
+ return "yarn";
124
+ return "npm";
125
+ };
126
+ const deriveVerificationChecks = (input) => {
127
+ const checks = [];
128
+ const touchedFiles = input.touchedFiles.slice(0, 12);
129
+ const projectSignals = new Set(input.projectSignals);
130
+ const canRunDocdexHooks = projectSignals.has("git_repo");
131
+ if (touchedFiles.length > 0 && canRunDocdexHooks) {
132
+ checks.push({
133
+ step: `docdex:hooks:${touchedFiles.join(",")}`,
134
+ check_type: "docdex_hooks",
135
+ category: "hook",
136
+ targeted: true,
137
+ source: "derived",
138
+ rationale: "touched_files_hook_validation",
139
+ });
140
+ }
141
+ const languageSignals = new Set(input.languageSignals);
142
+ const nodeTouched = input.touchedFiles
143
+ .filter((file) => /\.(ts|tsx|js|jsx|mjs|cjs)$/i.test(file))
144
+ .slice(0, 6);
145
+ const pythonTouched = input.touchedFiles.filter((file) => /\.py$/i.test(file)).slice(0, 6);
146
+ if (input.includeShellChecks
147
+ && (languageSignals.has("typescript")
148
+ || languageSignals.has("javascript")
149
+ || projectSignals.has("package_json"))) {
150
+ const manager = chooseNodePackageManager(input.projectSignals);
151
+ const testStep = manager === "pnpm"
152
+ ? nodeTouched.length > 0
153
+ ? `pnpm test -- --findRelatedTests ${nodeTouched.join(" ")}`
154
+ : "pnpm test"
155
+ : manager === "yarn"
156
+ ? nodeTouched.length > 0
157
+ ? `yarn test ${nodeTouched.join(" ")}`
158
+ : "yarn test"
159
+ : nodeTouched.length > 0
160
+ ? `npm test -- ${nodeTouched.join(" ")}`
161
+ : "npm test";
162
+ checks.push({
163
+ step: testStep,
164
+ check_type: "shell",
165
+ category: "test",
166
+ targeted: nodeTouched.length > 0,
167
+ source: "derived",
168
+ rationale: "language_or_project_signal_node",
169
+ });
170
+ checks.push({
171
+ step: manager === "pnpm" ? "pnpm lint" : manager === "yarn" ? "yarn lint" : "npm run lint",
172
+ check_type: "shell",
173
+ category: "lint",
174
+ targeted: false,
175
+ source: "derived",
176
+ rationale: "language_or_project_signal_node",
177
+ });
178
+ checks.push({
179
+ step: manager === "pnpm" ? "pnpm build" : manager === "yarn" ? "yarn build" : "npm run build",
180
+ check_type: "shell",
181
+ category: "build",
182
+ targeted: false,
183
+ source: "derived",
184
+ rationale: "language_or_project_signal_node",
185
+ });
186
+ }
187
+ if (input.includeShellChecks && (languageSignals.has("python") || projectSignals.has("pyproject"))) {
188
+ checks.push({
189
+ step: pythonTouched.length > 0 ? `pytest ${pythonTouched.join(" ")}` : "pytest",
190
+ check_type: "shell",
191
+ category: "test",
192
+ targeted: pythonTouched.length > 0,
193
+ source: "derived",
194
+ rationale: "language_or_project_signal_python",
195
+ });
196
+ checks.push({
197
+ step: pythonTouched.length > 0 ? `ruff check ${pythonTouched.join(" ")}` : "ruff check .",
198
+ check_type: "shell",
199
+ category: "lint",
200
+ targeted: pythonTouched.length > 0,
201
+ source: "derived",
202
+ rationale: "language_or_project_signal_python",
203
+ });
204
+ }
205
+ if (input.includeShellChecks && (languageSignals.has("go") || projectSignals.has("go_mod"))) {
206
+ checks.push({
207
+ step: "go test ./...",
208
+ check_type: "shell",
209
+ category: "test",
210
+ targeted: false,
211
+ source: "derived",
212
+ rationale: "language_or_project_signal_go",
213
+ });
214
+ checks.push({
215
+ step: "go build ./...",
216
+ check_type: "shell",
217
+ category: "build",
218
+ targeted: false,
219
+ source: "derived",
220
+ rationale: "language_or_project_signal_go",
221
+ });
222
+ }
223
+ if (input.includeShellChecks && (languageSignals.has("rust") || projectSignals.has("cargo_toml"))) {
224
+ checks.push({
225
+ step: "cargo test",
226
+ check_type: "shell",
227
+ category: "test",
228
+ targeted: false,
229
+ source: "derived",
230
+ rationale: "language_or_project_signal_rust",
231
+ });
232
+ checks.push({
233
+ step: "cargo build",
234
+ check_type: "shell",
235
+ category: "build",
236
+ targeted: false,
237
+ source: "derived",
238
+ rationale: "language_or_project_signal_rust",
239
+ });
240
+ }
241
+ if (checks.length === 0
242
+ && input.policyName.toLowerCase().includes("test")
243
+ && canRunDocdexHooks) {
244
+ checks.push({
245
+ step: "docdex:hooks",
246
+ check_type: "docdex_hooks",
247
+ category: "hook",
248
+ targeted: false,
249
+ source: "derived",
250
+ rationale: "policy_fallback_test_profile",
251
+ });
252
+ }
253
+ return checks;
254
+ };
255
+ const mergeResolvedChecks = (explicitChecks, derivedChecks) => {
256
+ const merged = new Map();
257
+ for (const check of [...explicitChecks, ...derivedChecks]) {
258
+ if (!merged.has(check.step)) {
259
+ merged.set(check.step, check);
260
+ }
261
+ }
262
+ return Array.from(merged.values());
263
+ };
264
+ export class ValidationRunner {
265
+ constructor(options) {
266
+ this.options = options;
267
+ }
268
+ async run(steps, runOptions = {}) {
269
+ const errors = [];
270
+ const touchedFiles = (runOptions.touchedFiles ?? []).map((entry) => entry.trim()).filter(Boolean);
271
+ const languageSignals = detectLanguageSignals(touchedFiles);
272
+ const projectSignals = detectProjectSignals(this.options.workspaceRoot);
273
+ const minimumChecks = Math.max(0, Math.floor(runOptions.minimumChecks
274
+ ?? this.options.defaultMinimumChecks
275
+ ?? 0));
276
+ const policy = {
277
+ policy_name: runOptions.policyName ?? this.options.defaultPolicyName ?? "general",
278
+ minimum_checks: minimumChecks,
279
+ enforce_high_confidence: runOptions.enforceHighConfidence
280
+ ?? this.options.defaultEnforceHighConfidence
281
+ ?? false,
282
+ };
283
+ const rawSteps = Array.isArray(steps) ? steps : [];
284
+ const explicitChecks = normalizeExplicitChecks(rawSteps);
285
+ const derivedChecks = deriveVerificationChecks({
286
+ touchedFiles,
287
+ languageSignals,
288
+ projectSignals,
289
+ policyName: policy.policy_name,
290
+ includeShellChecks: explicitChecks.length === 0,
291
+ });
292
+ const mergedChecks = mergeResolvedChecks(explicitChecks, derivedChecks);
293
+ const checks = mergedChecks
294
+ .map((entry) => ({
295
+ ...entry,
296
+ check_type: detectCheckType(entry.step),
297
+ targeted: detectTargetedStep(entry.step) || entry.targeted,
298
+ }))
299
+ .sort((left, right) => Number(right.targeted) - Number(left.targeted)
300
+ || checkTypeOrder(left.check_type) - checkTypeOrder(right.check_type)
301
+ || left.step.localeCompare(right.step));
302
+ const resolvedPlan = {
303
+ schema_version: 1,
304
+ policy_name: policy.policy_name,
305
+ source: explicitChecks.length > 0 && derivedChecks.length > 0
306
+ ? "mixed"
307
+ : explicitChecks.length > 0
308
+ ? "explicit"
309
+ : "derived",
310
+ touched_files: touchedFiles,
311
+ language_signals: languageSignals,
312
+ project_signals: projectSignals,
313
+ checks: checks.map((entry) => ({
314
+ step: entry.step,
315
+ check_type: entry.check_type,
316
+ category: entry.category,
317
+ targeted: entry.targeted,
318
+ source: entry.source,
319
+ rationale: entry.rationale,
320
+ })),
321
+ };
322
+ if (runOptions.onResolvedPlan) {
323
+ await runOptions.onResolvedPlan(resolvedPlan);
324
+ }
325
+ const checkResults = [];
326
+ const pushResult = (entry) => {
327
+ checkResults.push(entry);
328
+ if (entry.status === "failed") {
329
+ errors.push(entry.message ?? entry.reason_code ?? entry.step);
330
+ }
331
+ };
332
+ for (const check of checks) {
333
+ const startedAt = Date.now();
334
+ const step = check.step;
335
+ if (!step) {
336
+ pushResult({
337
+ ...check,
338
+ status: "unverified",
339
+ reason_code: "verification_step_empty",
340
+ message: "verification step is empty",
341
+ duration_ms: Date.now() - startedAt,
342
+ });
343
+ continue;
344
+ }
345
+ if (check.check_type === "docdex_hooks") {
346
+ const files = parseHookFiles(step);
347
+ if (!this.options.docdexClient) {
348
+ pushResult({
349
+ ...check,
350
+ status: "unverified",
351
+ reason_code: "verification_docdex_unavailable",
352
+ message: `docdex hooks unavailable for step: ${step}`,
353
+ duration_ms: Date.now() - startedAt,
354
+ });
355
+ continue;
356
+ }
357
+ try {
358
+ await this.options.docdexClient.hooksValidate(files);
359
+ pushResult({
360
+ ...check,
361
+ status: "passed",
362
+ evidence: files.length > 0 ? `Validated hooks for ${files.length} file(s).` : "Validated hooks.",
363
+ duration_ms: Date.now() - startedAt,
364
+ });
365
+ }
366
+ catch (error) {
367
+ pushResult({
368
+ ...check,
369
+ status: "failed",
370
+ reason_code: "verification_hooks_failed",
371
+ message: error instanceof Error ? error.message : String(error),
372
+ duration_ms: Date.now() - startedAt,
373
+ });
374
+ }
375
+ continue;
376
+ }
377
+ if (!this.options.allowShell) {
378
+ pushResult({
379
+ ...check,
380
+ status: "unverified",
381
+ reason_code: "verification_shell_disabled",
382
+ message: `shell validation disabled for step: ${step}`,
383
+ duration_ms: Date.now() - startedAt,
384
+ });
385
+ continue;
386
+ }
387
+ const [command, ...args] = step.split(" ").filter(Boolean);
388
+ if (!command) {
389
+ pushResult({
390
+ ...check,
391
+ status: "unverified",
392
+ reason_code: "verification_step_empty",
393
+ message: "validation step is empty",
394
+ duration_ms: Date.now() - startedAt,
395
+ });
396
+ continue;
397
+ }
398
+ if (!this.options.shellAllowlist.includes(command)) {
399
+ pushResult({
400
+ ...check,
401
+ status: "unverified",
402
+ reason_code: "verification_command_not_allowlisted",
403
+ message: `command not allowlisted: ${command}`,
404
+ duration_ms: Date.now() - startedAt,
405
+ });
406
+ continue;
407
+ }
408
+ const result = spawnSync(command, args, {
409
+ cwd: this.options.workspaceRoot,
410
+ encoding: "utf8",
411
+ timeout: this.options.shellTimeoutMs ?? DEFAULT_SHELL_TIMEOUT_MS,
412
+ });
413
+ if (result.error) {
414
+ const errorMessage = result.error.message;
415
+ const timeoutHit = result.error.name === "TimeoutError"
416
+ || result.error.code === "ETIMEDOUT"
417
+ || result.error.message.toLowerCase().includes("timed out");
418
+ pushResult({
419
+ ...check,
420
+ status: "failed",
421
+ reason_code: timeoutHit
422
+ ? "verification_command_timeout"
423
+ : "verification_tool_unavailable",
424
+ message: errorMessage,
425
+ duration_ms: Date.now() - startedAt,
426
+ });
427
+ continue;
428
+ }
429
+ if (result.status === null && result.signal === "SIGTERM") {
430
+ pushResult({
431
+ ...check,
432
+ status: "failed",
433
+ reason_code: "verification_command_timeout",
434
+ message: `command timed out: ${command}`,
435
+ duration_ms: Date.now() - startedAt,
436
+ });
437
+ continue;
438
+ }
439
+ if (result.status !== 0) {
440
+ pushResult({
441
+ ...check,
442
+ status: "failed",
443
+ reason_code: "verification_command_failed",
444
+ message: result.stderr?.toString().trim() || `command failed: ${command}`,
445
+ evidence: compactText(result.stdout?.toString()),
446
+ duration_ms: Date.now() - startedAt,
447
+ });
448
+ continue;
449
+ }
450
+ pushResult({
451
+ ...check,
452
+ status: "passed",
453
+ evidence: compactText(result.stdout?.toString()) ?? `command succeeded: ${command}`,
454
+ duration_ms: Date.now() - startedAt,
455
+ });
456
+ }
457
+ const totals = {
458
+ configured: checks.length,
459
+ runnable: checkResults.filter((entry) => entry.status === "passed" || entry.status === "failed").length,
460
+ attempted: checkResults.filter((entry) => entry.status === "passed" || entry.status === "failed").length,
461
+ passed: checkResults.filter((entry) => entry.status === "passed").length,
462
+ failed: checkResults.filter((entry) => entry.status === "failed").length,
463
+ unverified: checkResults.filter((entry) => entry.status === "unverified").length,
464
+ };
465
+ const reasonCodes = new Set();
466
+ for (const entry of checkResults) {
467
+ if (entry.reason_code)
468
+ reasonCodes.add(entry.reason_code);
469
+ }
470
+ if (totals.configured === 0) {
471
+ reasonCodes.add("verification_no_steps");
472
+ }
473
+ if (totals.runnable === 0 && totals.configured > 0) {
474
+ reasonCodes.add("verification_no_runnable_checks");
475
+ }
476
+ if (totals.passed < policy.minimum_checks) {
477
+ reasonCodes.add("verification_policy_minimum_unmet");
478
+ }
479
+ let outcome;
480
+ if (totals.failed > 0) {
481
+ outcome = "verified_failed";
482
+ }
483
+ else if (totals.passed === 0 || totals.passed < policy.minimum_checks) {
484
+ outcome = "unverified_with_reason";
485
+ }
486
+ else {
487
+ outcome = "verified_passed";
488
+ }
489
+ const reason_codes = [...reasonCodes].sort();
490
+ const report = {
491
+ schema_version: 1,
492
+ outcome,
493
+ reason_codes,
494
+ policy,
495
+ checks: checkResults,
496
+ totals,
497
+ touched_files: touchedFiles,
498
+ language_signals: languageSignals,
499
+ project_signals: projectSignals,
500
+ resolved_checks_source: resolvedPlan.source,
501
+ };
502
+ return {
503
+ ok: outcome !== "verified_failed",
504
+ errors,
505
+ outcome,
506
+ reason_codes,
507
+ checks: checkResults,
508
+ policy,
509
+ touched_files: touchedFiles,
510
+ language_signals: languageSignals,
511
+ totals,
512
+ report,
513
+ };
514
+ }
515
+ }