@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,27 @@
1
+ import type { ProviderMessage } from "../providers/ProviderTypes.js";
2
+ export interface ContextMessageRecord extends ProviderMessage {
3
+ ts: number;
4
+ model?: string;
5
+ tokens?: number;
6
+ }
7
+ export interface ContextLaneSnapshot {
8
+ laneId: string;
9
+ messages: ContextMessageRecord[];
10
+ messageCount: number;
11
+ byteSize: number;
12
+ updatedAt: number;
13
+ }
14
+ export interface ContextStoreOptions {
15
+ workspaceRoot: string;
16
+ storageDir: string;
17
+ }
18
+ export declare class ContextStore {
19
+ private options;
20
+ constructor(options: ContextStoreOptions);
21
+ private lanePath;
22
+ loadLane(laneId: string): Promise<ContextLaneSnapshot>;
23
+ append(laneId: string, messages: ContextMessageRecord[] | ContextMessageRecord): Promise<ContextLaneSnapshot>;
24
+ replace(laneId: string, messages: ContextMessageRecord[]): Promise<ContextLaneSnapshot>;
25
+ truncate(laneId: string, maxMessages: number): Promise<ContextLaneSnapshot>;
26
+ }
27
+ //# sourceMappingURL=ContextStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextStore.d.ts","sourceRoot":"","sources":["../../src/cognitive/ContextStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,oBAAoB,EAAE,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAqCD,qBAAa,YAAY;IACX,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,mBAAmB;IAEhD,OAAO,CAAC,QAAQ;IAIV,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IActD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAW7G,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAQvF,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAWlF"}
@@ -0,0 +1,79 @@
1
+ import { promises as fs } from "node:fs";
2
+ import path from "node:path";
3
+ const safeLaneId = (laneId) => laneId.replace(/[^a-zA-Z0-9._-]+/g, "_");
4
+ const resolveLanePath = (workspaceRoot, storageDir, laneId) => {
5
+ const resolvedDir = path.resolve(workspaceRoot, storageDir);
6
+ const fileName = `${safeLaneId(laneId)}.jsonl`;
7
+ const resolvedPath = path.join(resolvedDir, fileName);
8
+ const relative = path.relative(workspaceRoot, resolvedPath);
9
+ if (relative.startsWith("..") || path.isAbsolute(relative)) {
10
+ throw new Error("Path is outside workspace root");
11
+ }
12
+ return resolvedPath;
13
+ };
14
+ const parseJsonLines = (content) => {
15
+ if (!content.trim())
16
+ return [];
17
+ return content
18
+ .split("\n")
19
+ .map((line) => line.trim())
20
+ .filter(Boolean)
21
+ .map((line) => JSON.parse(line));
22
+ };
23
+ const buildSnapshot = (laneId, messages, byteSize, updatedAt) => ({
24
+ laneId,
25
+ messages,
26
+ messageCount: messages.length,
27
+ byteSize,
28
+ updatedAt,
29
+ });
30
+ export class ContextStore {
31
+ constructor(options) {
32
+ this.options = options;
33
+ }
34
+ lanePath(laneId) {
35
+ return resolveLanePath(this.options.workspaceRoot, this.options.storageDir, laneId);
36
+ }
37
+ async loadLane(laneId) {
38
+ const filePath = this.lanePath(laneId);
39
+ try {
40
+ const [content, stats] = await Promise.all([fs.readFile(filePath, "utf8"), fs.stat(filePath)]);
41
+ const messages = parseJsonLines(content);
42
+ return buildSnapshot(laneId, messages, Buffer.byteLength(content, "utf8"), stats.mtimeMs);
43
+ }
44
+ catch (error) {
45
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
46
+ return buildSnapshot(laneId, [], 0, 0);
47
+ }
48
+ throw error;
49
+ }
50
+ }
51
+ async append(laneId, messages) {
52
+ const filePath = this.lanePath(laneId);
53
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
54
+ const items = Array.isArray(messages) ? messages : [messages];
55
+ if (items.length) {
56
+ const payload = `${items.map((item) => JSON.stringify(item)).join("\n")}\n`;
57
+ await fs.appendFile(filePath, payload, "utf8");
58
+ }
59
+ return this.loadLane(laneId);
60
+ }
61
+ async replace(laneId, messages) {
62
+ const filePath = this.lanePath(laneId);
63
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
64
+ const payload = messages.length ? `${messages.map((item) => JSON.stringify(item)).join("\n")}\n` : "";
65
+ await fs.writeFile(filePath, payload, "utf8");
66
+ return this.loadLane(laneId);
67
+ }
68
+ async truncate(laneId, maxMessages) {
69
+ const snapshot = await this.loadLane(laneId);
70
+ if (maxMessages < 0) {
71
+ throw new Error("maxMessages must be non-negative");
72
+ }
73
+ if (snapshot.messages.length <= maxMessages) {
74
+ return snapshot;
75
+ }
76
+ const trimmed = maxMessages === 0 ? [] : snapshot.messages.slice(-maxMessages);
77
+ return this.replace(laneId, trimmed);
78
+ }
79
+ }
@@ -0,0 +1,16 @@
1
+ import type { Provider, ProviderMessage } from "../providers/ProviderTypes.js";
2
+ import type { RunLogger } from "../runtime/RunLogger.js";
3
+ export interface ContextSummarizerOptions {
4
+ temperature?: number;
5
+ maxTokens?: number;
6
+ logger?: RunLogger;
7
+ }
8
+ export declare class ContextSummarizer {
9
+ private provider;
10
+ private temperature?;
11
+ private maxTokens?;
12
+ private logger?;
13
+ constructor(provider: Provider, options?: ContextSummarizerOptions);
14
+ summarize(messages: ProviderMessage[]): Promise<ProviderMessage>;
15
+ }
16
+ //# sourceMappingURL=ContextSummarizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextSummarizer.d.ts","sourceRoot":"","sources":["../../src/cognitive/ContextSummarizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD,MAAM,WAAW,wBAAwB;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAUD,qBAAa,iBAAiB;IAKhB,OAAO,CAAC,QAAQ;IAJ5B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAC,CAAY;gBAEP,QAAQ,EAAE,QAAQ,EAAE,OAAO,GAAE,wBAA6B;IAMxE,SAAS,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;CAgCvE"}
@@ -0,0 +1,45 @@
1
+ import { CONTEXT_SUMMARY_PROMPT } from "./Prompts.js";
2
+ const formatHistory = (messages) => messages
3
+ .map((message) => {
4
+ const header = message.name ? `${message.role}(${message.name})` : message.role;
5
+ return `${header}: ${message.content}`;
6
+ })
7
+ .join("\n\n");
8
+ export class ContextSummarizer {
9
+ constructor(provider, options = {}) {
10
+ this.provider = provider;
11
+ this.temperature = options.temperature;
12
+ this.maxTokens = options.maxTokens;
13
+ this.logger = options.logger;
14
+ }
15
+ async summarize(messages) {
16
+ const requestMessages = [
17
+ { role: "system", content: CONTEXT_SUMMARY_PROMPT },
18
+ { role: "user", content: formatHistory(messages) },
19
+ ];
20
+ if (this.logger) {
21
+ await this.logger.log("provider_request", {
22
+ provider: this.provider.name,
23
+ messages: requestMessages,
24
+ temperature: this.temperature,
25
+ maxTokens: this.maxTokens,
26
+ });
27
+ }
28
+ const response = await this.provider.generate({
29
+ messages: requestMessages,
30
+ temperature: this.temperature,
31
+ maxTokens: this.maxTokens,
32
+ });
33
+ if (response.usage && this.logger) {
34
+ await this.logger.log("context_summarize_usage", { usage: response.usage });
35
+ }
36
+ const content = response.message.content?.trim() ?? "";
37
+ if (!content) {
38
+ throw new Error("Context summarizer response is empty");
39
+ }
40
+ return {
41
+ role: "system",
42
+ content: `Context summary: ${content}`,
43
+ };
44
+ }
45
+ }
@@ -0,0 +1,31 @@
1
+ import type { ProviderUsage } from "../providers/ProviderTypes.js";
2
+ export type PricingSpec = {
3
+ inputPer1K?: number;
4
+ outputPer1K?: number;
5
+ per1K?: number;
6
+ };
7
+ export type PricingOverrides = Record<string, PricingSpec>;
8
+ export interface PricingResolution {
9
+ pricing?: PricingSpec;
10
+ source?: string;
11
+ }
12
+ export interface CostEstimate {
13
+ charCount: number;
14
+ estimatedInputTokens: number;
15
+ estimatedOutputTokens: number;
16
+ estimatedTotalTokens: number;
17
+ estimatedCost?: number;
18
+ pricingSource?: string;
19
+ }
20
+ export type UsageCostSource = "actual_usage" | "unknown";
21
+ export type UsageCostReasonCode = "usage_missing" | "pricing_unavailable";
22
+ export interface UsageCostTelemetry {
23
+ costUsd?: number;
24
+ source: UsageCostSource;
25
+ reasonCode?: UsageCostReasonCode;
26
+ }
27
+ export declare const resolvePricing: (overrides: PricingOverrides, provider: string, model: string) => PricingResolution;
28
+ export declare const estimateCostFromChars: (charCount: number, charPerToken: number, pricing?: PricingSpec, pricingSource?: string, outputTokenRatio?: number) => CostEstimate;
29
+ export declare const estimateCostFromUsage: (usage: ProviderUsage | undefined, pricing?: PricingSpec) => number | undefined;
30
+ export declare const estimateUsageCostTelemetry: (usage: ProviderUsage | undefined, pricing?: PricingSpec) => UsageCostTelemetry;
31
+ //# sourceMappingURL=CostEstimator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CostEstimator.d.ts","sourceRoot":"","sources":["../../src/cognitive/CostEstimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,SAAS,CAAC;AAEzD,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG,qBAAqB,CAAC;AAE1E,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,CAAC,EAAE,mBAAmB,CAAC;CAClC;AAID,eAAO,MAAM,cAAc,GACzB,WAAW,gBAAgB,EAC3B,UAAU,MAAM,EAChB,OAAO,MAAM,KACZ,iBAcF,CAAC;AAmBF,eAAO,MAAM,qBAAqB,GAChC,WAAW,MAAM,EACjB,cAAc,MAAM,EACpB,UAAU,WAAW,EACrB,gBAAgB,MAAM,EACtB,mBAAkB,MAA6B,KAC9C,YAgBF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,OAAO,aAAa,GAAG,SAAS,EAChC,UAAU,WAAW,KACpB,MAAM,GAAG,SAKX,CAAC;AAEF,eAAO,MAAM,0BAA0B,GACrC,OAAO,aAAa,GAAG,SAAS,EAChC,UAAU,WAAW,KACpB,kBAYF,CAAC"}
@@ -0,0 +1,66 @@
1
+ const DEFAULT_OUTPUT_RATIO = 0.25;
2
+ export const resolvePricing = (overrides, provider, model) => {
3
+ const candidates = [
4
+ `${provider}:${model}`,
5
+ model,
6
+ provider,
7
+ "default",
8
+ ];
9
+ for (const key of candidates) {
10
+ const pricing = overrides[key];
11
+ if (pricing) {
12
+ return { pricing, source: key };
13
+ }
14
+ }
15
+ return {};
16
+ };
17
+ const computeCost = (inputTokens, outputTokens, pricing) => {
18
+ if (!pricing)
19
+ return undefined;
20
+ if (pricing.per1K !== undefined) {
21
+ return ((inputTokens + outputTokens) / 1000) * pricing.per1K;
22
+ }
23
+ if (pricing.inputPer1K !== undefined || pricing.outputPer1K !== undefined) {
24
+ const inputRate = pricing.inputPer1K ?? 0;
25
+ const outputRate = pricing.outputPer1K ?? 0;
26
+ return (inputTokens / 1000) * inputRate + (outputTokens / 1000) * outputRate;
27
+ }
28
+ return undefined;
29
+ };
30
+ export const estimateCostFromChars = (charCount, charPerToken, pricing, pricingSource, outputTokenRatio = DEFAULT_OUTPUT_RATIO) => {
31
+ if (charPerToken <= 0) {
32
+ throw new Error("charPerToken must be greater than zero");
33
+ }
34
+ const estimatedInputTokens = Math.ceil(charCount / charPerToken);
35
+ const estimatedOutputTokens = Math.ceil(estimatedInputTokens * outputTokenRatio);
36
+ const estimatedTotalTokens = estimatedInputTokens + estimatedOutputTokens;
37
+ const estimatedCost = computeCost(estimatedInputTokens, estimatedOutputTokens, pricing);
38
+ return {
39
+ charCount,
40
+ estimatedInputTokens,
41
+ estimatedOutputTokens,
42
+ estimatedTotalTokens,
43
+ estimatedCost,
44
+ pricingSource,
45
+ };
46
+ };
47
+ export const estimateCostFromUsage = (usage, pricing) => {
48
+ if (!usage)
49
+ return undefined;
50
+ const inputTokens = usage.inputTokens ?? 0;
51
+ const outputTokens = usage.outputTokens ?? Math.max((usage.totalTokens ?? 0) - inputTokens, 0);
52
+ return computeCost(inputTokens, outputTokens, pricing);
53
+ };
54
+ export const estimateUsageCostTelemetry = (usage, pricing) => {
55
+ if (!usage) {
56
+ return { source: "unknown", reasonCode: "usage_missing" };
57
+ }
58
+ if (!pricing) {
59
+ return { source: "unknown", reasonCode: "pricing_unavailable" };
60
+ }
61
+ const costUsd = estimateCostFromUsage(usage, pricing);
62
+ if (costUsd === undefined) {
63
+ return { source: "unknown", reasonCode: "pricing_unavailable" };
64
+ }
65
+ return { source: "actual_usage", costUsd };
66
+ };
@@ -0,0 +1,32 @@
1
+ import type { Plan, CriticResult } from "./Types.js";
2
+ import type { ValidationRunner } from "./ValidationRunner.js";
3
+ import type { ContextManager } from "./ContextManager.js";
4
+ import type { RunLogger } from "../runtime/RunLogger.js";
5
+ export interface CriticEvaluatorOptions {
6
+ contextManager?: ContextManager;
7
+ laneId?: string;
8
+ model?: string;
9
+ logger?: RunLogger;
10
+ }
11
+ export declare class CriticEvaluator {
12
+ private validator;
13
+ private contextManager?;
14
+ private laneId?;
15
+ private model?;
16
+ private logger?;
17
+ constructor(validator: ValidationRunner, options?: CriticEvaluatorOptions);
18
+ evaluate(plan: Plan, builderOutput: string, touchedFiles?: string[], options?: {
19
+ contextManager?: ContextManager;
20
+ laneId?: string;
21
+ model?: string;
22
+ allowedPaths?: string[];
23
+ readOnlyPaths?: string[];
24
+ allowProtocolRequest?: boolean;
25
+ logger?: RunLogger;
26
+ verificationPolicyName?: string;
27
+ minimumVerificationChecks?: number;
28
+ enforceHighConfidence?: boolean;
29
+ }): Promise<CriticResult>;
30
+ private appendCriticResult;
31
+ }
32
+ //# sourceMappingURL=CriticEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CriticEvaluator.d.ts","sourceRoot":"","sources":["../../src/cognitive/CriticEvaluator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,IAAI,EAEJ,YAAY,EAEb,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,MAAM,WAAW,sBAAsB;IACrC,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,SAAS,CAAC;CACpB;AAsDD,qBAAa,eAAe;IAMd,OAAO,CAAC,SAAS;IAL7B,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,MAAM,CAAC,CAAY;gBAEP,SAAS,EAAE,gBAAgB,EAAE,OAAO,GAAE,sBAA2B;IAO/E,QAAQ,CACZ,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,MAAM,EACrB,YAAY,CAAC,EAAE,MAAM,EAAE,EACvB,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,cAAc,CAAC;QAChC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;QACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;QAC/B,MAAM,CAAC,EAAE,SAAS,CAAC;QACnB,sBAAsB,CAAC,EAAE,MAAM,CAAC;QAChC,yBAAyB,CAAC,EAAE,MAAM,CAAC;QACnC,qBAAqB,CAAC,EAAE,OAAO,CAAC;KAC5B,GACL,OAAO,CAAC,YAAY,CAAC;YA0RV,kBAAkB;CAajC"}
@@ -0,0 +1,297 @@
1
+ const GUARDRAIL_REASON_PATTERNS = [
2
+ {
3
+ code: "scope_violation",
4
+ pattern: /\b(scope_violation|patch_outside_allowed_scope|patch_outside_workspace)\b/i,
5
+ },
6
+ {
7
+ code: "doc_edit_guard",
8
+ pattern: /\b(doc_edit_guard|patch_read_only_path)\b/i,
9
+ },
10
+ {
11
+ code: "destructive_operation_guard",
12
+ pattern: /\b(destructive_operation_guard|destructive_operation_blocked)\b/i,
13
+ },
14
+ { code: "merge_conflict", pattern: /\bmerge_conflict\b/i },
15
+ ];
16
+ const NON_RETRYABLE_GUARDRAIL_CODES = new Set([
17
+ "scope_violation",
18
+ "doc_edit_guard",
19
+ "merge_conflict",
20
+ "destructive_operation_guard",
21
+ ]);
22
+ const normalizePath = (value) => value.replace(/\\/g, "/").replace(/^\.?\//, "");
23
+ const dedupe = (values) => Array.from(new Set(values));
24
+ const matchesPathRule = (target, rules) => rules.some((entry) => target === entry || target.startsWith(`${entry}/`));
25
+ const detectGuardrailReasonCode = (reasons) => {
26
+ for (const reason of reasons) {
27
+ for (const candidate of GUARDRAIL_REASON_PATTERNS) {
28
+ if (candidate.pattern.test(reason)) {
29
+ return candidate.code;
30
+ }
31
+ }
32
+ }
33
+ return undefined;
34
+ };
35
+ const buildGuardrailClassification = (reasonCode) => {
36
+ if (!reasonCode)
37
+ return undefined;
38
+ return {
39
+ reason_code: reasonCode,
40
+ disposition: NON_RETRYABLE_GUARDRAIL_CODES.has(reasonCode) ? "non_retryable" : "retryable",
41
+ };
42
+ };
43
+ export class CriticEvaluator {
44
+ constructor(validator, options = {}) {
45
+ this.validator = validator;
46
+ this.contextManager = options.contextManager;
47
+ this.laneId = options.laneId;
48
+ this.model = options.model;
49
+ this.logger = options.logger;
50
+ }
51
+ async evaluate(plan, builderOutput, touchedFiles, options = {}) {
52
+ if (options.contextManager)
53
+ this.contextManager = options.contextManager;
54
+ if (options.laneId)
55
+ this.laneId = options.laneId;
56
+ if (options.model)
57
+ this.model = options.model;
58
+ if (options.logger)
59
+ this.logger = options.logger;
60
+ const verificationPolicyName = options.verificationPolicyName;
61
+ const minimumVerificationChecks = options.minimumVerificationChecks;
62
+ const enforceHighConfidence = options.enforceHighConfidence;
63
+ let verification = {
64
+ schema_version: 1,
65
+ outcome: "unverified_with_reason",
66
+ reason_codes: ["verification_not_executed"],
67
+ policy: {
68
+ policy_name: verificationPolicyName ?? "general",
69
+ minimum_checks: Math.max(0, Math.floor(minimumVerificationChecks ?? 0)),
70
+ enforce_high_confidence: enforceHighConfidence ?? false,
71
+ },
72
+ checks: [],
73
+ totals: {
74
+ configured: 0,
75
+ runnable: 0,
76
+ attempted: 0,
77
+ passed: 0,
78
+ failed: 0,
79
+ unverified: 0,
80
+ },
81
+ touched_files: touchedFiles,
82
+ language_signals: [],
83
+ };
84
+ const targetFiles = (plan.target_files ?? []).filter((file) => file !== "unknown");
85
+ const normalizedTargetFiles = dedupe(targetFiles.map(normalizePath).filter(Boolean));
86
+ if (this.logger?.writePhaseArtifact) {
87
+ await this.logger.writePhaseArtifact("verify", "plan", {
88
+ schema_version: 1,
89
+ policy_name: verification.policy.policy_name,
90
+ source: "pre_validation",
91
+ touched_files: touchedFiles ?? [],
92
+ plan_targets: normalizedTargetFiles,
93
+ configured_steps: plan.verification ?? [],
94
+ });
95
+ }
96
+ const buildAlignmentEvidence = (touched) => {
97
+ const normalizedTouched = dedupe((touched ?? []).map(normalizePath).filter(Boolean));
98
+ const matchedTargets = normalizedTargetFiles.filter((target) => normalizedTouched.includes(target));
99
+ const unmatchedTargets = normalizedTargetFiles.filter((target) => !normalizedTouched.includes(target));
100
+ const unrelatedTouched = normalizedTouched.filter((file) => !normalizedTargetFiles.includes(file));
101
+ return {
102
+ touched_files: normalizedTouched,
103
+ plan_targets: normalizedTargetFiles,
104
+ matched_targets: matchedTargets,
105
+ unmatched_targets: unmatchedTargets,
106
+ unrelated_touched_files: unrelatedTouched,
107
+ };
108
+ };
109
+ const buildReport = (status, reasons, touched, guardrail, alignmentEvidence, highConfidence) => ({
110
+ status,
111
+ reasons,
112
+ suggested_fixes: reasons.map((reason) => `Address: ${reason}`),
113
+ touched_files: touched,
114
+ plan_targets: targetFiles.length ? targetFiles : undefined,
115
+ alignment_evidence: alignmentEvidence,
116
+ guardrail,
117
+ high_confidence: highConfidence,
118
+ verification,
119
+ });
120
+ const buildFailure = (reasons, touched, failureOptions = {}) => {
121
+ const inferredReasonCode = failureOptions.reasonCode ?? detectGuardrailReasonCode(reasons);
122
+ const guardrail = buildGuardrailClassification(inferredReasonCode);
123
+ const retryable = guardrail
124
+ ? guardrail.disposition === "retryable"
125
+ : (failureOptions.retryable ?? true);
126
+ return {
127
+ status: "FAIL",
128
+ reasons,
129
+ retryable,
130
+ guardrail,
131
+ high_confidence: false,
132
+ report: buildReport("FAIL", reasons, touched, guardrail, buildAlignmentEvidence(touched), false),
133
+ };
134
+ };
135
+ const emitSafetyTelemetry = async (result) => {
136
+ if (!result.guardrail || !this.logger?.logSafetyEvent)
137
+ return;
138
+ await this.logger.logSafetyEvent({
139
+ phase: "verify",
140
+ category: "critic",
141
+ code: result.guardrail.reason_code,
142
+ disposition: result.guardrail.disposition,
143
+ source: "critic_evaluator",
144
+ message: result.reasons.join("; ") || "critic guardrail triggered",
145
+ details: {
146
+ reasons: result.reasons,
147
+ },
148
+ });
149
+ };
150
+ const finalizeFailure = async (reasons, touched, failureOptions = {}) => {
151
+ const result = buildFailure(reasons, touched, failureOptions);
152
+ await emitSafetyTelemetry(result);
153
+ await this.appendCriticResult(result);
154
+ return result;
155
+ };
156
+ const buildRequest = () => ({
157
+ version: "v1",
158
+ role: "critic",
159
+ request_id: `critic-${Date.now()}`,
160
+ needs: targetFiles.map((file) => ({ type: "file.read", path: file })),
161
+ context: { summary: "Need target file contents to validate changes." },
162
+ });
163
+ if (!builderOutput.trim()) {
164
+ return finalizeFailure(["builder output is empty"], touchedFiles);
165
+ }
166
+ const inferTouchedFiles = (output) => {
167
+ const trimmed = output.trim();
168
+ if (!trimmed || !(trimmed.startsWith("{") || trimmed.startsWith("["))) {
169
+ return undefined;
170
+ }
171
+ try {
172
+ const payload = JSON.parse(trimmed);
173
+ const patches = Array.isArray(payload.patches) ? payload.patches : [];
174
+ if (patches.length > 0) {
175
+ return patches
176
+ .map((patch) => patch.file)
177
+ .filter((file) => typeof file === "string" && file.length > 0);
178
+ }
179
+ const files = Array.isArray(payload.files) ? payload.files : [];
180
+ if (files.length > 0) {
181
+ return files
182
+ .map((entry) => entry.path)
183
+ .filter((file) => typeof file === "string" && file.length > 0);
184
+ }
185
+ }
186
+ catch {
187
+ return undefined;
188
+ }
189
+ return undefined;
190
+ };
191
+ let effectiveTouched = touchedFiles;
192
+ if ((!effectiveTouched || effectiveTouched.length === 0) && targetFiles.length > 0) {
193
+ const inferred = inferTouchedFiles(builderOutput);
194
+ if (inferred && inferred.length > 0) {
195
+ effectiveTouched = inferred;
196
+ }
197
+ }
198
+ const allowedPaths = dedupe((options.allowedPaths ?? []).map(normalizePath).filter(Boolean));
199
+ const readOnlyPaths = dedupe((options.readOnlyPaths ?? []).map(normalizePath).filter(Boolean));
200
+ if (effectiveTouched && effectiveTouched.length > 0) {
201
+ const normalizedTouched = effectiveTouched.map(normalizePath);
202
+ const readOnlyHits = readOnlyPaths.length
203
+ ? normalizedTouched.filter((file) => matchesPathRule(file, readOnlyPaths))
204
+ : [];
205
+ if (readOnlyHits.length) {
206
+ return finalizeFailure([`touched read-only paths: ${readOnlyHits.join(", ")}`], effectiveTouched, { reasonCode: "doc_edit_guard" });
207
+ }
208
+ if (allowedPaths.length) {
209
+ const invalid = normalizedTouched.filter((file) => !matchesPathRule(file, allowedPaths));
210
+ if (invalid.length) {
211
+ return finalizeFailure([`touched files outside allowed paths: ${invalid.join(", ")}`], effectiveTouched, { reasonCode: "scope_violation" });
212
+ }
213
+ }
214
+ }
215
+ if (targetFiles.length === 0) {
216
+ const reasons = ["alignment_missing_plan_targets"];
217
+ const result = await finalizeFailure(reasons, effectiveTouched, {
218
+ reasonCode: "scope_violation",
219
+ retryable: false,
220
+ });
221
+ const request = options.allowProtocolRequest ? buildRequest() : undefined;
222
+ return { ...result, request };
223
+ }
224
+ if (!effectiveTouched || effectiveTouched.length === 0) {
225
+ const reasons = [
226
+ "alignment_missing_evidence_no_touched_files",
227
+ "no files were touched for planned targets",
228
+ ];
229
+ const result = await finalizeFailure(reasons, effectiveTouched);
230
+ const request = options.allowProtocolRequest ? buildRequest() : undefined;
231
+ return { ...result, request };
232
+ }
233
+ if (targetFiles.length > 0) {
234
+ const normalizedTouched = new Set(effectiveTouched.map(normalizePath));
235
+ const normalizedTargets = targetFiles.map(normalizePath);
236
+ const matched = normalizedTargets.some((target) => normalizedTouched.has(target));
237
+ if (!matched) {
238
+ const reasons = [
239
+ "alignment_mismatch_plan_targets",
240
+ `touched files do not match plan targets (touched: ${effectiveTouched.join(", ")})`,
241
+ ];
242
+ const result = await finalizeFailure(reasons, effectiveTouched, {
243
+ reasonCode: "scope_violation",
244
+ });
245
+ const request = options.allowProtocolRequest ? buildRequest() : undefined;
246
+ return { ...result, request };
247
+ }
248
+ }
249
+ const validation = await this.validator.run(plan.verification ?? [], {
250
+ policyName: verificationPolicyName,
251
+ minimumChecks: minimumVerificationChecks,
252
+ enforceHighConfidence,
253
+ touchedFiles: effectiveTouched,
254
+ onResolvedPlan: async (resolvedPlan) => {
255
+ if (!this.logger?.writePhaseArtifact)
256
+ return;
257
+ await this.logger.writePhaseArtifact("verify", "plan", {
258
+ ...resolvedPlan,
259
+ plan_targets: normalizedTargetFiles,
260
+ });
261
+ },
262
+ });
263
+ verification = validation.report;
264
+ if (verification.outcome === "verified_failed") {
265
+ return finalizeFailure(validation.errors, effectiveTouched);
266
+ }
267
+ if (verification.outcome === "unverified_with_reason" && verification.policy.enforce_high_confidence) {
268
+ const reasons = verification.reason_codes.map((code) => `verification_${code}`);
269
+ return finalizeFailure(reasons.length > 0 ? reasons : ["verification_unverified_with_reason"], effectiveTouched, { retryable: false });
270
+ }
271
+ const highConfidence = verification.outcome === "verified_passed";
272
+ const result = {
273
+ status: "PASS",
274
+ reasons: [],
275
+ retryable: false,
276
+ high_confidence: highConfidence,
277
+ verification,
278
+ report: buildReport("PASS", [], effectiveTouched, undefined, buildAlignmentEvidence(effectiveTouched), highConfidence),
279
+ };
280
+ await this.appendCriticResult(result);
281
+ return result;
282
+ }
283
+ async appendCriticResult(result) {
284
+ if (!this.contextManager || !this.laneId)
285
+ return;
286
+ const payload = result.report ?? {
287
+ status: result.status,
288
+ reasons: result.reasons,
289
+ suggested_fixes: [],
290
+ };
291
+ const message = {
292
+ role: "assistant",
293
+ content: `CRITIC_RESULT v1\n${JSON.stringify(payload, null, 2)}`,
294
+ };
295
+ await this.contextManager.append(this.laneId, message, { role: "critic", model: this.model });
296
+ }
297
+ }
@@ -0,0 +1,9 @@
1
+ import type { DeepInvestigationEvidenceConfig } from "../config/Config.js";
2
+ import type { ContextResearchEvidence, ContextResearchToolUsage, EvidenceGateAssessment } from "./Types.js";
3
+ export declare const evaluateEvidenceGate: ({ config, evidence, toolUsage, warnings, }: {
4
+ config: DeepInvestigationEvidenceConfig;
5
+ evidence?: ContextResearchEvidence;
6
+ toolUsage?: ContextResearchToolUsage;
7
+ warnings?: string[];
8
+ }) => EvidenceGateAssessment;
9
+ //# sourceMappingURL=EvidenceGate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvidenceGate.d.ts","sourceRoot":"","sources":["../../src/cognitive/EvidenceGate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EAGvB,MAAM,YAAY,CAAC;AA4EpB,eAAO,MAAM,oBAAoB,GAAI,4CAKlC;IACD,MAAM,EAAE,+BAA+B,CAAC;IACxC,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,KAAG,sBAwBH,CAAC"}