@mcoda/mswarm 0.1.56 → 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 +20 -1
  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 +47 -1
  7. package/dist/runtime.d.ts.map +1 -1
  8. package/dist/runtime.js +248 -30
  9. package/dist/runtime.js.map +1 -1
  10. package/dist/server.d.ts.map +1 -1
  11. package/dist/server.js +83 -3
  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,39 @@
1
+ import type { DeepInvestigationToolQuotaConfig } from "../config/Config.js";
2
+ import type { EvidenceGateMetrics } from "../cognitive/Types.js";
3
+ export type DeepInvestigationErrorCode = "deep_investigation_docdex_unavailable" | "deep_investigation_quota_unmet" | "deep_investigation_budget_unmet" | "deep_investigation_evidence_unmet";
4
+ export type DeepInvestigationErrorDetails = Record<string, unknown>;
5
+ type DeepInvestigationErrorInput = {
6
+ code: DeepInvestigationErrorCode;
7
+ message: string;
8
+ remediation: string[];
9
+ details?: DeepInvestigationErrorDetails;
10
+ name?: string;
11
+ };
12
+ export declare class DeepInvestigationError extends Error {
13
+ readonly code: DeepInvestigationErrorCode;
14
+ readonly remediation: string[];
15
+ readonly details?: DeepInvestigationErrorDetails;
16
+ constructor({ code, message, remediation, details, name }: DeepInvestigationErrorInput);
17
+ }
18
+ export declare const createDeepInvestigationDocdexError: (missing: string[], remediation: string[]) => DeepInvestigationError;
19
+ export declare const createDeepInvestigationQuotaError: (input: {
20
+ missing: string[];
21
+ required: DeepInvestigationToolQuotaConfig;
22
+ observed: DeepInvestigationToolQuotaConfig;
23
+ }) => DeepInvestigationError;
24
+ export declare const createDeepInvestigationBudgetError: (input: {
25
+ minCycles: number;
26
+ minSeconds: number;
27
+ maxCycles: number;
28
+ cycles: number;
29
+ elapsedMs: number;
30
+ }) => DeepInvestigationError;
31
+ export declare const createDeepInvestigationEvidenceError: (input: {
32
+ missing: string[];
33
+ required: EvidenceGateMetrics | Record<string, number>;
34
+ observed: EvidenceGateMetrics | Record<string, number>;
35
+ warnings: string[];
36
+ gaps: string[];
37
+ }) => DeepInvestigationError;
38
+ export {};
39
+ //# sourceMappingURL=DeepInvestigationErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepInvestigationErrors.d.ts","sourceRoot":"","sources":["../../src/runtime/DeepInvestigationErrors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,MAAM,MAAM,0BAA0B,GAClC,uCAAuC,GACvC,gCAAgC,GAChC,iCAAiC,GACjC,mCAAmC,CAAC;AAExC,MAAM,MAAM,6BAA6B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpE,KAAK,2BAA2B,GAAG;IACjC,IAAI,EAAE,0BAA0B,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,6BAA6B,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,6BAA6B,CAAC;gBAErC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,2BAA2B;CAOvF;AAED,eAAO,MAAM,kCAAkC,GAC7C,SAAS,MAAM,EAAE,EACjB,aAAa,MAAM,EAAE,KACpB,sBAaF,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAAI,OAAO;IACvD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,gCAAgC,CAAC;IAC3C,QAAQ,EAAE,gCAAgC,CAAC;CAC5C,KAAG,sBAeH,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAAI,OAAO;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,KAAG,sBAUA,CAAC;AAEL,eAAO,MAAM,oCAAoC,GAAI,OAAO;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvD,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,KAAG,sBAUA,CAAC"}
@@ -0,0 +1,57 @@
1
+ export class DeepInvestigationError extends Error {
2
+ constructor({ code, message, remediation, details, name }) {
3
+ super(message);
4
+ this.name = name ?? "DeepInvestigationError";
5
+ this.code = code;
6
+ this.remediation = remediation;
7
+ this.details = details;
8
+ }
9
+ }
10
+ export const createDeepInvestigationDocdexError = (missing, remediation) => {
11
+ const message = [
12
+ "Deep investigation requires docdex health, stats, and file coverage.",
13
+ `Missing: ${missing.join(", ")}`,
14
+ `Remediation: ${remediation.join(" | ")}`,
15
+ ].join(" ");
16
+ return new DeepInvestigationError({
17
+ code: "deep_investigation_docdex_unavailable",
18
+ message,
19
+ remediation,
20
+ details: { missing },
21
+ name: "DeepInvestigationDocdexError",
22
+ });
23
+ };
24
+ export const createDeepInvestigationQuotaError = (input) => {
25
+ const missingList = input.missing.join(", ");
26
+ return new DeepInvestigationError({
27
+ code: "deep_investigation_quota_unmet",
28
+ message: `Deep investigation tool quota unmet. Missing categories: ${missingList}`,
29
+ remediation: [
30
+ "Increase deepInvestigation.toolQuota requirements.",
31
+ "Ensure the research phase executes the required docdex tools.",
32
+ ],
33
+ details: {
34
+ missing: input.missing,
35
+ required: input.required,
36
+ observed: input.observed,
37
+ },
38
+ });
39
+ };
40
+ export const createDeepInvestigationBudgetError = (input) => new DeepInvestigationError({
41
+ code: "deep_investigation_budget_unmet",
42
+ message: "Deep investigation budget unmet. Increase min cycles/time or reduce requirements.",
43
+ remediation: [
44
+ "Increase deepInvestigation.investigationBudget minCycles/minSeconds.",
45
+ "Reduce research requirements if budget is intentionally smaller.",
46
+ ],
47
+ details: { ...input },
48
+ });
49
+ export const createDeepInvestigationEvidenceError = (input) => new DeepInvestigationError({
50
+ code: "deep_investigation_evidence_unmet",
51
+ message: "Deep investigation evidence gate unmet. Increase research depth or relax evidence thresholds.",
52
+ remediation: [
53
+ "Increase research depth or add more docdex tool coverage.",
54
+ "Relax deepInvestigation.evidenceGate thresholds if necessary.",
55
+ ],
56
+ details: { ...input },
57
+ });
@@ -0,0 +1,27 @@
1
+ import type { RunContractFingerprint } from "../cognitive/Types.js";
2
+ export interface RunFingerprintInput {
3
+ request: string;
4
+ command?: string;
5
+ workspaceRoot: string;
6
+ smart?: boolean;
7
+ provider?: string;
8
+ model?: string;
9
+ builderMode?: string;
10
+ maxRetries?: number;
11
+ maxContextRefreshes?: number;
12
+ maxSteps?: number;
13
+ maxToolCalls?: number;
14
+ maxTokens?: number;
15
+ timeoutMs?: number;
16
+ }
17
+ export declare class RunContext {
18
+ readonly runId: string;
19
+ readonly workspaceRoot: string;
20
+ readonly startedAt: number;
21
+ readonly fingerprint?: RunContractFingerprint;
22
+ private touchedFiles;
23
+ constructor(runId: string, workspaceRoot: string, fingerprintInput?: RunFingerprintInput);
24
+ recordTouchedFile(filePath: string): void;
25
+ getTouchedFiles(): string[];
26
+ }
27
+ //# sourceMappingURL=RunContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunContext.d.ts","sourceRoot":"","sources":["../../src/runtime/RunContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAsCD,qBAAa,UAAU;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,sBAAsB,CAAC;IAC9C,OAAO,CAAC,YAAY,CAAqB;gBAE7B,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,mBAAmB;IAOxF,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIzC,eAAe,IAAI,MAAM,EAAE;CAG5B"}
@@ -0,0 +1,51 @@
1
+ import { createHash } from "node:crypto";
2
+ const stableSort = (value) => {
3
+ if (Array.isArray(value)) {
4
+ return value.map((entry) => stableSort(entry));
5
+ }
6
+ if (!value || typeof value !== "object")
7
+ return value;
8
+ const entries = Object.entries(value)
9
+ .sort(([left], [right]) => left.localeCompare(right))
10
+ .map(([key, entry]) => [key, stableSort(entry)]);
11
+ return Object.fromEntries(entries);
12
+ };
13
+ const buildFingerprint = (input) => {
14
+ const normalized = stableSort({
15
+ request: input.request,
16
+ command: input.command ?? "",
17
+ workspaceRoot: input.workspaceRoot,
18
+ smart: input.smart ?? false,
19
+ provider: input.provider ?? "",
20
+ model: input.model ?? "",
21
+ builderMode: input.builderMode ?? "",
22
+ maxRetries: input.maxRetries ?? null,
23
+ maxContextRefreshes: input.maxContextRefreshes ?? null,
24
+ maxSteps: input.maxSteps ?? null,
25
+ maxToolCalls: input.maxToolCalls ?? null,
26
+ maxTokens: input.maxTokens ?? null,
27
+ timeoutMs: input.timeoutMs ?? null,
28
+ });
29
+ const digest = createHash("sha256")
30
+ .update(JSON.stringify(normalized))
31
+ .digest("hex");
32
+ return {
33
+ algorithm: "sha256",
34
+ value: digest,
35
+ };
36
+ };
37
+ export class RunContext {
38
+ constructor(runId, workspaceRoot, fingerprintInput) {
39
+ this.touchedFiles = new Set();
40
+ this.runId = runId;
41
+ this.workspaceRoot = workspaceRoot;
42
+ this.startedAt = Date.now();
43
+ this.fingerprint = fingerprintInput ? buildFingerprint(fingerprintInput) : undefined;
44
+ }
45
+ recordTouchedFile(filePath) {
46
+ this.touchedFiles.add(filePath);
47
+ }
48
+ getTouchedFiles() {
49
+ return Array.from(this.touchedFiles).sort();
50
+ }
51
+ }
@@ -0,0 +1,48 @@
1
+ import type { RunFailureClass } from "./RunTelemetryTypes.js";
2
+ export declare const RUN_LOG_QUERY_SCHEMA_VERSION: 1;
3
+ export declare const DEFAULT_RUN_LOG_QUERY_LIMIT = 100;
4
+ export declare const MAX_RUN_LOG_QUERY_LIMIT = 2000;
5
+ export type RunLogQuerySort = "asc" | "desc";
6
+ export interface RunLogQueryFilters {
7
+ run_id?: string;
8
+ task_id?: string;
9
+ phase?: string;
10
+ event_type?: string;
11
+ failure_class?: RunFailureClass | string;
12
+ }
13
+ export interface RunLogQueryInput {
14
+ schema_version?: number;
15
+ filters?: RunLogQueryFilters;
16
+ limit?: number;
17
+ offset?: number;
18
+ sort?: RunLogQuerySort;
19
+ }
20
+ export interface RunLogQueryEvent {
21
+ event_index: number;
22
+ file: string;
23
+ line: number;
24
+ type: string;
25
+ timestamp: string;
26
+ run_id?: string;
27
+ task_id?: string;
28
+ phase?: string;
29
+ failure_class?: string;
30
+ data: Record<string, unknown>;
31
+ }
32
+ export interface NormalizedRunLogQuery {
33
+ schema_version: typeof RUN_LOG_QUERY_SCHEMA_VERSION;
34
+ filters: RunLogQueryFilters;
35
+ limit: number;
36
+ offset: number;
37
+ sort: RunLogQuerySort;
38
+ }
39
+ export interface RunLogQueryResult {
40
+ schema_version: typeof RUN_LOG_QUERY_SCHEMA_VERSION;
41
+ query: NormalizedRunLogQuery;
42
+ total: number;
43
+ returned: number;
44
+ next_offset: number | null;
45
+ events: RunLogQueryEvent[];
46
+ }
47
+ export declare const normalizeRunLogQueryInput: (input?: RunLogQueryInput) => NormalizedRunLogQuery;
48
+ //# sourceMappingURL=RunLogQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunLogQuery.d.ts","sourceRoot":"","sources":["../../src/runtime/RunLogQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,eAAO,MAAM,4BAA4B,EAAG,CAAU,CAAC;AACvD,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAC/C,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC;CAC1C;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,qBAAqB;IACpC,cAAc,EAAE,OAAO,4BAA4B,CAAC;IACpD,OAAO,EAAE,kBAAkB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,eAAe,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,OAAO,4BAA4B,CAAC;IACpD,KAAK,EAAE,qBAAqB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAcD,eAAO,MAAM,yBAAyB,GAAI,QAAO,gBAAqB,KAAG,qBAmBxE,CAAC"}
@@ -0,0 +1,36 @@
1
+ export const RUN_LOG_QUERY_SCHEMA_VERSION = 1;
2
+ export const DEFAULT_RUN_LOG_QUERY_LIMIT = 100;
3
+ export const MAX_RUN_LOG_QUERY_LIMIT = 2000;
4
+ const normalizeString = (value) => {
5
+ if (typeof value !== "string")
6
+ return undefined;
7
+ const trimmed = value.trim();
8
+ return trimmed.length > 0 ? trimmed : undefined;
9
+ };
10
+ const normalizeNonNegativeInteger = (value, fallback) => {
11
+ if (typeof value !== "number" || !Number.isFinite(value))
12
+ return fallback;
13
+ if (value < 0)
14
+ return fallback;
15
+ return Math.floor(value);
16
+ };
17
+ export const normalizeRunLogQueryInput = (input = {}) => {
18
+ const filters = input.filters ?? {};
19
+ const limitRaw = normalizeNonNegativeInteger(input.limit, DEFAULT_RUN_LOG_QUERY_LIMIT);
20
+ const limit = Math.min(Math.max(limitRaw, 1), MAX_RUN_LOG_QUERY_LIMIT);
21
+ const offset = normalizeNonNegativeInteger(input.offset, 0);
22
+ const sort = input.sort === "desc" ? "desc" : "asc";
23
+ return {
24
+ schema_version: RUN_LOG_QUERY_SCHEMA_VERSION,
25
+ filters: {
26
+ run_id: normalizeString(filters.run_id),
27
+ task_id: normalizeString(filters.task_id),
28
+ phase: normalizeString(filters.phase),
29
+ event_type: normalizeString(filters.event_type),
30
+ failure_class: normalizeString(filters.failure_class),
31
+ },
32
+ limit,
33
+ offset,
34
+ sort,
35
+ };
36
+ };
@@ -0,0 +1,19 @@
1
+ import { type RunLogQueryInput, type RunLogQueryResult } from "./RunLogQuery.js";
2
+ import { type SafetyTelemetryEventData } from "./RunTelemetryTypes.js";
3
+ import type { PhaseArtifactV1, VerificationReport } from "../cognitive/Types.js";
4
+ export declare class RunLogReader {
5
+ private logDir;
6
+ constructor(workspaceRoot: string, logDirName?: string);
7
+ private resolveLogFiles;
8
+ queryEvents(input?: RunLogQueryInput): Promise<RunLogQueryResult>;
9
+ findLastRunForFile(filePath: string): Promise<string | undefined>;
10
+ getRunArtifact(runId: string, kind: string): Promise<string | undefined>;
11
+ getRunIntent(runId: string): Promise<string | undefined>;
12
+ getPhaseArtifacts(runId: string, phase?: string): Promise<PhaseArtifactV1[]>;
13
+ getSafetyEvents(runId: string, filters?: {
14
+ code?: string;
15
+ phase?: string;
16
+ }): Promise<SafetyTelemetryEventData[]>;
17
+ getVerificationReports(runId: string): Promise<VerificationReport[]>;
18
+ }
19
+ //# sourceMappingURL=RunLogReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunLogReader.d.ts","sourceRoot":"","sources":["../../src/runtime/RunLogReader.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAyB,KAAK,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAwEjF,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,aAAa,EAAE,MAAM,EAAE,UAAU,SAAS;YAKxC,eAAe;IAqBvB,WAAW,CAAC,KAAK,GAAE,gBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA+ErE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAuCjE,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiBxE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAsCxD,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAsB5E,eAAe,CACnB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC9C,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAwBhC,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CA8D3E"}
@@ -0,0 +1,361 @@
1
+ import { promises as fs } from "node:fs";
2
+ import path from "node:path";
3
+ import { getGlobalWorkspaceDir } from "./StoragePaths.js";
4
+ import { normalizeRunLogQueryInput, RUN_LOG_QUERY_SCHEMA_VERSION, } from "./RunLogQuery.js";
5
+ import { normalizeFailureClass } from "./RunTelemetryTypes.js";
6
+ const parseJsonSafe = (value) => {
7
+ try {
8
+ return JSON.parse(value);
9
+ }
10
+ catch {
11
+ return undefined;
12
+ }
13
+ };
14
+ const normalizeCandidatePath = (value) => path.normalize(value).replace(/\\/g, "/");
15
+ const asRecord = (value) => {
16
+ if (!value || typeof value !== "object" || Array.isArray(value))
17
+ return undefined;
18
+ return value;
19
+ };
20
+ const asString = (value) => {
21
+ if (typeof value !== "string")
22
+ return undefined;
23
+ const trimmed = value.trim();
24
+ return trimmed.length > 0 ? trimmed : undefined;
25
+ };
26
+ const asStringArray = (value) => {
27
+ if (!Array.isArray(value))
28
+ return [];
29
+ return value
30
+ .filter((entry) => typeof entry === "string")
31
+ .map((entry) => entry.trim())
32
+ .filter((entry) => entry.length > 0);
33
+ };
34
+ const inferRunIdFromEvent = (data, fallbackRunId) => asString(data.run_id) ?? asString(data.runId) ?? fallbackRunId;
35
+ const inferTaskIdFromEvent = (data) => asString(data.task_id) ?? asString(data.taskId);
36
+ const inferPhaseFromEvent = (data) => {
37
+ const direct = asString(data.phase);
38
+ if (direct)
39
+ return direct;
40
+ const disposition = asRecord(data.final_disposition);
41
+ const dispositionStage = asString(disposition?.stage);
42
+ if (dispositionStage)
43
+ return dispositionStage;
44
+ const telemetry = asRecord(data.phase_telemetry);
45
+ return asString(telemetry?.phase);
46
+ };
47
+ const inferFailureClassFromEvent = (data) => {
48
+ const direct = normalizeFailureClass(data.failure_class ?? data.failureClass);
49
+ if (direct)
50
+ return direct;
51
+ const finalDisposition = asRecord(data.final_disposition);
52
+ const fromDisposition = normalizeFailureClass(finalDisposition?.failure_class ?? finalDisposition?.failureClass);
53
+ if (fromDisposition)
54
+ return fromDisposition;
55
+ const reasonCodes = asStringArray(data.reason_codes ?? data.reasons);
56
+ if (reasonCodes.some((reason) => reason.includes("verification")))
57
+ return "verification_failure";
58
+ if (reasonCodes.some((reason) => reason.includes("policy") || reason.includes("guardrail"))) {
59
+ return "policy_failure";
60
+ }
61
+ if (reasonCodes.some((reason) => reason.includes("patch")))
62
+ return "patch_failure";
63
+ if (reasonCodes.some((reason) => reason.includes("provider")))
64
+ return "provider_failure";
65
+ return undefined;
66
+ };
67
+ export class RunLogReader {
68
+ constructor(workspaceRoot, logDirName = "logs") {
69
+ const storageRoot = getGlobalWorkspaceDir(workspaceRoot);
70
+ this.logDir = path.resolve(storageRoot, logDirName);
71
+ }
72
+ async resolveLogFiles(runId) {
73
+ if (runId) {
74
+ const file = path.join(this.logDir, `${runId}.jsonl`);
75
+ try {
76
+ await fs.access(file);
77
+ return [file];
78
+ }
79
+ catch {
80
+ return [];
81
+ }
82
+ }
83
+ try {
84
+ const files = await fs.readdir(this.logDir);
85
+ return files
86
+ .filter((entry) => entry.endsWith(".jsonl"))
87
+ .sort((left, right) => left.localeCompare(right))
88
+ .map((entry) => path.join(this.logDir, entry));
89
+ }
90
+ catch {
91
+ return [];
92
+ }
93
+ }
94
+ async queryEvents(input = {}) {
95
+ const query = normalizeRunLogQueryInput(input);
96
+ const files = await this.resolveLogFiles(query.filters.run_id);
97
+ const matches = [];
98
+ let eventIndex = 0;
99
+ for (const filePath of files) {
100
+ const fallbackRunId = path.basename(filePath, ".jsonl");
101
+ let content = "";
102
+ try {
103
+ content = await fs.readFile(filePath, "utf8");
104
+ }
105
+ catch {
106
+ continue;
107
+ }
108
+ const lines = content.split("\n");
109
+ for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
110
+ const line = lines[lineNumber];
111
+ if (!line.trim())
112
+ continue;
113
+ const parsed = parseJsonSafe(line);
114
+ const event = asRecord(parsed);
115
+ if (!event)
116
+ continue;
117
+ const type = asString(event.type);
118
+ if (!type)
119
+ continue;
120
+ const data = asRecord(event.data) ?? {};
121
+ const timestamp = asString(event.timestamp) ?? "";
122
+ const runId = inferRunIdFromEvent(data, fallbackRunId);
123
+ const taskId = inferTaskIdFromEvent(data);
124
+ const phase = inferPhaseFromEvent(data);
125
+ const failureClass = inferFailureClassFromEvent(data);
126
+ if (query.filters.event_type && type !== query.filters.event_type)
127
+ continue;
128
+ if (query.filters.run_id && runId !== query.filters.run_id)
129
+ continue;
130
+ if (query.filters.task_id && taskId !== query.filters.task_id)
131
+ continue;
132
+ if (query.filters.phase && phase !== query.filters.phase)
133
+ continue;
134
+ if (query.filters.failure_class && failureClass !== query.filters.failure_class)
135
+ continue;
136
+ matches.push({
137
+ event_index: eventIndex,
138
+ file: filePath,
139
+ line: lineNumber + 1,
140
+ type,
141
+ timestamp,
142
+ run_id: runId,
143
+ task_id: taskId,
144
+ phase,
145
+ failure_class: failureClass,
146
+ data,
147
+ });
148
+ eventIndex += 1;
149
+ }
150
+ }
151
+ const compare = (left, right) => {
152
+ const byTimestamp = left.timestamp.localeCompare(right.timestamp);
153
+ if (byTimestamp !== 0)
154
+ return byTimestamp;
155
+ const byRun = (left.run_id ?? "").localeCompare(right.run_id ?? "");
156
+ if (byRun !== 0)
157
+ return byRun;
158
+ const byFile = left.file.localeCompare(right.file);
159
+ if (byFile !== 0)
160
+ return byFile;
161
+ const byLine = left.line - right.line;
162
+ if (byLine !== 0)
163
+ return byLine;
164
+ return left.event_index - right.event_index;
165
+ };
166
+ matches.sort((left, right) => (query.sort === "asc" ? compare(left, right) : compare(right, left)));
167
+ const total = matches.length;
168
+ const events = matches.slice(query.offset, query.offset + query.limit);
169
+ const nextOffset = query.offset + events.length;
170
+ return {
171
+ schema_version: RUN_LOG_QUERY_SCHEMA_VERSION,
172
+ query,
173
+ total,
174
+ returned: events.length,
175
+ next_offset: nextOffset >= total ? null : nextOffset,
176
+ events,
177
+ };
178
+ }
179
+ async findLastRunForFile(filePath) {
180
+ try {
181
+ const files = await fs.readdir(this.logDir);
182
+ const jsonlFiles = files.filter((entry) => entry.endsWith(".jsonl"));
183
+ const sortedFiles = await Promise.all(jsonlFiles.map(async (entry) => {
184
+ const stat = await fs.stat(path.join(this.logDir, entry));
185
+ return { file: entry, mtime: stat.mtimeMs };
186
+ }));
187
+ sortedFiles.sort((left, right) => right.mtime - left.mtime);
188
+ for (const { file } of sortedFiles) {
189
+ const content = await fs.readFile(path.join(this.logDir, file), "utf8");
190
+ const lines = content.split("\n").filter(Boolean);
191
+ for (const line of lines) {
192
+ const event = parseJsonSafe(line);
193
+ if (!event || event.type !== "run_summary")
194
+ continue;
195
+ const touched = event.data?.touchedFiles ?? [];
196
+ const normalizedTarget = normalizeCandidatePath(filePath);
197
+ const hit = touched.find((entry) => {
198
+ const normalizedTouched = normalizeCandidatePath(entry);
199
+ return (normalizedTouched.endsWith(normalizedTarget)
200
+ || normalizedTarget.endsWith(normalizedTouched));
201
+ });
202
+ if (hit)
203
+ return event.data?.run_id ?? event.data?.runId;
204
+ }
205
+ }
206
+ }
207
+ catch {
208
+ // ignore
209
+ }
210
+ return undefined;
211
+ }
212
+ async getRunArtifact(runId, kind) {
213
+ const phaseDir = path.join(this.logDir, "phase");
214
+ try {
215
+ const files = await fs.readdir(phaseDir);
216
+ const candidates = files.filter((entry) => entry.startsWith(runId) && entry.includes(kind));
217
+ if (candidates.length === 0)
218
+ return undefined;
219
+ const last = candidates.sort().pop();
220
+ if (last) {
221
+ return fs.readFile(path.join(phaseDir, last), "utf8");
222
+ }
223
+ }
224
+ catch {
225
+ return undefined;
226
+ }
227
+ return undefined;
228
+ }
229
+ async getRunIntent(runId) {
230
+ const logFile = path.join(this.logDir, `${runId}.jsonl`);
231
+ try {
232
+ const content = await fs.readFile(logFile, "utf8");
233
+ const lines = content.split("\n").filter(Boolean);
234
+ for (const line of lines) {
235
+ const event = parseJsonSafe(line);
236
+ if (!event)
237
+ continue;
238
+ if (event.type === "phase_input" && event.data?.phase === "librarian") {
239
+ const artifactPath = event.data.path;
240
+ if (artifactPath && typeof artifactPath === "string") {
241
+ try {
242
+ const artifact = parseJsonSafe(await fs.readFile(artifactPath, "utf8"));
243
+ if (!artifact)
244
+ continue;
245
+ if (typeof artifact.request === "string") {
246
+ return artifact.request;
247
+ }
248
+ const payloadRequest = artifact.payload;
249
+ if (typeof payloadRequest?.request === "string")
250
+ return payloadRequest.request;
251
+ }
252
+ catch {
253
+ // ignore
254
+ }
255
+ }
256
+ }
257
+ }
258
+ }
259
+ catch {
260
+ // ignore
261
+ }
262
+ return undefined;
263
+ }
264
+ async getPhaseArtifacts(runId, phase) {
265
+ const phaseDir = path.join(this.logDir, "phase");
266
+ try {
267
+ const files = await fs.readdir(phaseDir);
268
+ const artifacts = [];
269
+ for (const file of files) {
270
+ if (!file.startsWith(`${runId}-`))
271
+ continue;
272
+ const parsed = parseJsonSafe(await fs.readFile(path.join(phaseDir, file), "utf8"));
273
+ if (!parsed || parsed.schema_version !== 1)
274
+ continue;
275
+ if (phase && parsed.phase !== phase)
276
+ continue;
277
+ artifacts.push(parsed);
278
+ }
279
+ return artifacts.sort((left, right) => (left.ended_at_ms ?? 0) - (right.ended_at_ms ?? 0));
280
+ }
281
+ catch {
282
+ return [];
283
+ }
284
+ }
285
+ async getSafetyEvents(runId, filters = {}) {
286
+ const logFile = path.join(this.logDir, `${runId}.jsonl`);
287
+ try {
288
+ const content = await fs.readFile(logFile, "utf8");
289
+ const lines = content.split("\n").filter(Boolean);
290
+ const events = [];
291
+ for (const line of lines) {
292
+ const parsed = parseJsonSafe(line);
293
+ if (!parsed || parsed.type !== "safety_event" || !parsed.data)
294
+ continue;
295
+ const data = parsed.data;
296
+ if (data.schema_version !== 1)
297
+ continue;
298
+ if (data.run_id !== runId)
299
+ continue;
300
+ if (filters.code && data.code !== filters.code)
301
+ continue;
302
+ if (filters.phase && data.phase !== filters.phase)
303
+ continue;
304
+ events.push(data);
305
+ }
306
+ return events;
307
+ }
308
+ catch {
309
+ return [];
310
+ }
311
+ }
312
+ async getVerificationReports(runId) {
313
+ const reports = [];
314
+ const seen = new Set();
315
+ const addReport = (candidate) => {
316
+ if (!candidate || typeof candidate !== "object")
317
+ return;
318
+ const value = candidate;
319
+ if (value.schema_version !== 1)
320
+ return;
321
+ if (value.outcome !== "verified_passed"
322
+ && value.outcome !== "verified_failed"
323
+ && value.outcome !== "unverified_with_reason") {
324
+ return;
325
+ }
326
+ const key = JSON.stringify(value);
327
+ if (seen.has(key))
328
+ return;
329
+ seen.add(key);
330
+ reports.push(value);
331
+ };
332
+ const artifacts = await this.getPhaseArtifacts(runId, "verify");
333
+ for (const artifact of artifacts) {
334
+ if (artifact.kind === "verification_report") {
335
+ addReport(artifact.payload);
336
+ }
337
+ }
338
+ const logFile = path.join(this.logDir, `${runId}.jsonl`);
339
+ try {
340
+ const content = await fs.readFile(logFile, "utf8");
341
+ const lines = content.split("\n").filter(Boolean);
342
+ for (const line of lines) {
343
+ const parsed = parseJsonSafe(line);
344
+ if (!parsed || !parsed.data)
345
+ continue;
346
+ if (parsed.type === "verification_report"
347
+ && (parsed.data.run_id === runId || parsed.data.runId === runId)) {
348
+ addReport(parsed.data.report);
349
+ }
350
+ if (parsed.type === "run_summary") {
351
+ addReport(parsed.data.verification);
352
+ addReport(parsed.data.smartRuntime?.verification);
353
+ }
354
+ }
355
+ }
356
+ catch {
357
+ // ignore
358
+ }
359
+ return reports;
360
+ }
361
+ }