@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,7 @@
1
+ export declare const normalizePatchOutput: (raw: string) => string | undefined;
2
+ export declare const __test__: {
3
+ stripCodeFences: (input: string) => string;
4
+ stripJsonPrefix: (input: string) => string;
5
+ findJsonSubstring: (input: string) => string | undefined;
6
+ };
7
+ //# sourceMappingURL=PatchOutputNormalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PatchOutputNormalizer.d.ts","sourceRoot":"","sources":["../../src/cognitive/PatchOutputNormalizer.ts"],"names":[],"mappings":"AAqCA,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAe3D,CAAC;AAEF,eAAO,MAAM,QAAQ;6BAtDW,MAAM,KAAG,MAAM;6BAQf,MAAM,KAAG,MAAM;+BAIb,MAAM,KAAG,MAAM,GAAG,SAAS;CA8C5D,CAAC"}
@@ -0,0 +1,59 @@
1
+ const stripCodeFences = (input) => {
2
+ const match = input.match(/```(?:json)?\s*([\s\S]*?)```/i);
3
+ if (match?.[1]) {
4
+ return match[1].trim();
5
+ }
6
+ return input.trim();
7
+ };
8
+ const stripJsonPrefix = (input) => {
9
+ return input.replace(/^json\s*:/i, "").trim();
10
+ };
11
+ const findJsonSubstring = (input) => {
12
+ const startBrace = input.indexOf("{");
13
+ const startBracket = input.indexOf("[");
14
+ const start = startBrace === -1
15
+ ? startBracket
16
+ : startBracket === -1
17
+ ? startBrace
18
+ : Math.min(startBrace, startBracket);
19
+ if (start === -1)
20
+ return undefined;
21
+ for (let end = input.length - 1; end > start; end -= 1) {
22
+ const char = input[end];
23
+ if (char !== "}" && char !== "]")
24
+ continue;
25
+ const candidate = input.slice(start, end + 1).trim();
26
+ try {
27
+ JSON.parse(candidate);
28
+ return candidate;
29
+ }
30
+ catch {
31
+ // keep searching shorter candidates
32
+ }
33
+ }
34
+ return undefined;
35
+ };
36
+ export const normalizePatchOutput = (raw) => {
37
+ if (!raw)
38
+ return undefined;
39
+ const fenced = stripCodeFences(raw);
40
+ const stripped = stripJsonPrefix(fenced);
41
+ const direct = stripped.trim();
42
+ if (!direct)
43
+ return undefined;
44
+ if (direct.startsWith("{") || direct.startsWith("[")) {
45
+ try {
46
+ JSON.parse(direct);
47
+ return direct;
48
+ }
49
+ catch {
50
+ return findJsonSubstring(direct);
51
+ }
52
+ }
53
+ return findJsonSubstring(direct);
54
+ };
55
+ export const __test__ = {
56
+ stripCodeFences,
57
+ stripJsonPrefix,
58
+ findJsonSubstring,
59
+ };
@@ -0,0 +1,17 @@
1
+ import type { Provider } from "../providers/ProviderTypes.js";
2
+ import { type LearningEvidenceReference, type LearningRuleProposal } from "./LearningGovernance.js";
3
+ export interface PostMortemAnalysisResult {
4
+ runId: string;
5
+ status: "rule_extracted" | "no_change";
6
+ message: string;
7
+ rule?: string;
8
+ rules: LearningRuleProposal[];
9
+ evidence: LearningEvidenceReference[];
10
+ }
11
+ export declare class PostMortemAnalyzer {
12
+ private provider;
13
+ private workspaceRoot;
14
+ constructor(provider: Provider, workspaceRoot: string);
15
+ analyze(filePath: string): Promise<PostMortemAnalysisResult>;
16
+ }
17
+ //# sourceMappingURL=PostMortemAnalyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostMortemAnalyzer.d.ts","sourceRoot":"","sources":["../../src/cognitive/PostMortemAnalyzer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,gBAAgB,GAAG,WAAW,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,oBAAoB,EAAE,CAAC;IAC9B,QAAQ,EAAE,yBAAyB,EAAE,CAAC;CACvC;AA+BD,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;gBADb,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM;IAGzB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;CA8GnE"}
@@ -0,0 +1,131 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { RunLogReader } from "../runtime/RunLogReader.js";
3
+ import { scoreLearningConfidence, } from "./LearningGovernance.js";
4
+ const normalizeRuleText = (value) => value.trim().replace(/^["'`]+|["'`]+$/g, "").trim();
5
+ const inferRuleCategory = (rule) => {
6
+ const normalized = rule.trim().toLowerCase();
7
+ if (normalized.startsWith("prefer")
8
+ || normalized.startsWith("use ")
9
+ || normalized.startsWith("always use")) {
10
+ return "preference";
11
+ }
12
+ if (normalized.startsWith("avoid")
13
+ || normalized.startsWith("do not ")
14
+ || normalized.startsWith("don't ")
15
+ || normalized.startsWith("never ")
16
+ || normalized.includes("do not ")
17
+ || normalized.includes("don't ")
18
+ || normalized.includes("avoid ")) {
19
+ return "constraint";
20
+ }
21
+ return "constraint";
22
+ };
23
+ const inferExplicitDirective = (rule) => /^(prefer|avoid|do not|don't|never|must|always)\b/i.test(rule.trim());
24
+ export class PostMortemAnalyzer {
25
+ constructor(provider, workspaceRoot) {
26
+ this.provider = provider;
27
+ this.workspaceRoot = workspaceRoot;
28
+ }
29
+ async analyze(filePath) {
30
+ const reader = new RunLogReader(this.workspaceRoot);
31
+ const runId = await reader.findLastRunForFile(filePath);
32
+ if (!runId) {
33
+ throw new Error(`No recent Codali run found for ${filePath}`);
34
+ }
35
+ const patchContent = await reader.getRunArtifact(runId, "builder-patch");
36
+ if (!patchContent) {
37
+ throw new Error(`Could not find builder patch for run ${runId}`);
38
+ }
39
+ let currentContent = "";
40
+ try {
41
+ currentContent = await readFile(filePath, "utf8");
42
+ }
43
+ catch {
44
+ throw new Error(`Could not read current file ${filePath}`);
45
+ }
46
+ const intent = await reader.getRunIntent(runId);
47
+ const evidence = [
48
+ { kind: "run", ref: runId, note: "post_mortem_comparison" },
49
+ { kind: "file", ref: filePath },
50
+ { kind: "artifact", ref: `phase/builder-patch:${runId}` },
51
+ ];
52
+ if (intent?.trim()) {
53
+ evidence.push({ kind: "request", ref: intent.trim() });
54
+ }
55
+ const prompt = `
56
+ ROLE: Post-Mortem Analyst
57
+ TASK: Compare the "CODALI PATCH" (what the agent attempted) against "CURRENT FILE" (user-adjusted result).
58
+ GOAL: Extract one concise, durable coding rule that prevents this mismatch in future runs.
59
+
60
+ RUN ID:
61
+ ${runId}
62
+
63
+ CODALI PATCH ARTIFACT:
64
+ ${patchContent}
65
+
66
+ CURRENT FILE CONTENT:
67
+ ${currentContent}
68
+
69
+ INSTRUCTIONS:
70
+ 1. Determine whether the user materially changed/reverted the proposed patch.
71
+ 2. If yes, return one concise rule string.
72
+ 3. If no meaningful difference exists, return exactly: NO_CHANGE
73
+
74
+ OUTPUT FORMAT:
75
+ Return ONLY a single line rule string or NO_CHANGE.
76
+ `;
77
+ const response = await this.provider.generate({
78
+ messages: [{ role: "user", content: prompt }],
79
+ temperature: 0.1,
80
+ });
81
+ const rawRule = response.message.content?.trim() ?? "";
82
+ if (!rawRule || rawRule.toUpperCase() === "NO_CHANGE") {
83
+ return {
84
+ runId,
85
+ status: "no_change",
86
+ message: "No meaningful user deviation detected; no rule persisted.",
87
+ rules: [],
88
+ evidence,
89
+ };
90
+ }
91
+ const rule = normalizeRuleText(rawRule);
92
+ if (!rule) {
93
+ return {
94
+ runId,
95
+ status: "no_change",
96
+ message: "Analyzer did not produce a valid rule.",
97
+ rules: [],
98
+ evidence,
99
+ };
100
+ }
101
+ const category = inferRuleCategory(rule);
102
+ const explicit = inferExplicitDirective(rule);
103
+ const confidence = scoreLearningConfidence({
104
+ source: "post_mortem_inferred_rule",
105
+ content: rule,
106
+ explicit,
107
+ evidence_count: evidence.length,
108
+ has_revert_signal: true,
109
+ });
110
+ return {
111
+ runId,
112
+ status: "rule_extracted",
113
+ message: "Extracted post-mortem learning rule.",
114
+ rule,
115
+ evidence,
116
+ rules: [
117
+ {
118
+ category,
119
+ content: rule,
120
+ source: "post_mortem_inferred_rule",
121
+ scope: "profile_memory",
122
+ confidence_score: confidence.score,
123
+ confidence_band: confidence.band,
124
+ confidence_reasons: confidence.reasons,
125
+ evidence,
126
+ explicit_confirmation: false,
127
+ },
128
+ ],
129
+ };
130
+ }
131
+ }
@@ -0,0 +1,3 @@
1
+ import type { ContextPreferenceDetected } from "./Types.js";
2
+ export declare const extractPreferences: (request: string) => ContextPreferenceDetected[];
3
+ //# sourceMappingURL=PreferenceExtraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreferenceExtraction.d.ts","sourceRoot":"","sources":["../../src/cognitive/PreferenceExtraction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AA6F5D,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,yBAAyB,EAK7E,CAAC"}
@@ -0,0 +1,85 @@
1
+ import { scoreLearningConfidence } from "./LearningGovernance.js";
2
+ const uniquePreferences = (entries) => {
3
+ const seen = new Set();
4
+ const result = [];
5
+ for (const entry of entries) {
6
+ const key = `${entry.category}:${entry.content}`.toLowerCase();
7
+ if (seen.has(key))
8
+ continue;
9
+ seen.add(key);
10
+ result.push(entry);
11
+ }
12
+ return result;
13
+ };
14
+ const toDetectedPreference = (candidate) => {
15
+ const confidence = scoreLearningConfidence({
16
+ source: candidate.source,
17
+ content: candidate.content,
18
+ explicit: candidate.explicit,
19
+ evidence_count: 1,
20
+ has_revert_signal: false,
21
+ });
22
+ return {
23
+ category: candidate.category,
24
+ content: candidate.content,
25
+ source: candidate.source,
26
+ scope: "profile_memory",
27
+ confidence_score: confidence.score,
28
+ confidence_band: confidence.band,
29
+ confidence_reasons: confidence.reasons,
30
+ };
31
+ };
32
+ const extractFromLine = (line) => {
33
+ const trimmed = line.trim();
34
+ if (!trimmed)
35
+ return [];
36
+ const matches = [];
37
+ const preferMatch = trimmed.match(/^(?:preference|prefer)\s*:?\s*(.+)$/i);
38
+ if (preferMatch?.[1]) {
39
+ matches.push({
40
+ category: "preference",
41
+ content: preferMatch[1].trim(),
42
+ source: "request_directive_explicit_preference",
43
+ explicit: true,
44
+ });
45
+ }
46
+ const mustUseMatch = trimmed.match(/^(?:always use|must use)\s*:?\s*(.+)$/i);
47
+ if (mustUseMatch?.[1]) {
48
+ matches.push({
49
+ category: "constraint",
50
+ content: mustUseMatch[1].trim(),
51
+ source: "request_directive_explicit_constraint",
52
+ explicit: true,
53
+ });
54
+ }
55
+ const avoidMatch = trimmed.match(/^(?:avoid|do not use|don't use|never use)\s*:?\s*(.+)$/i);
56
+ if (avoidMatch?.[1]) {
57
+ matches.push({
58
+ category: "constraint",
59
+ content: avoidMatch[1].trim(),
60
+ source: "request_directive_explicit_constraint",
61
+ explicit: true,
62
+ });
63
+ }
64
+ if (!avoidMatch) {
65
+ const inlineAvoid = trimmed.match(/(?:do not use|don't use|avoid)\s+([^.;]+)/i);
66
+ if (inlineAvoid?.[1]) {
67
+ matches.push({
68
+ category: "constraint",
69
+ content: inlineAvoid[1].trim(),
70
+ source: "request_directive_inline_constraint",
71
+ explicit: false,
72
+ });
73
+ }
74
+ }
75
+ return matches
76
+ .filter((entry) => entry.content.length > 0)
77
+ .map((entry) => toDetectedPreference(entry));
78
+ };
79
+ export const extractPreferences = (request) => {
80
+ if (!request.trim())
81
+ return [];
82
+ const lines = request.split(/\r?\n/);
83
+ const entries = lines.flatMap(extractFromLine).filter((entry) => entry.content.length > 0);
84
+ return uniquePreferences(entries);
85
+ };
@@ -0,0 +1,15 @@
1
+ export declare const ARCHITECT_PROMPT: string;
2
+ export declare const ARCHITECT_GBNF: string;
3
+ export declare const ARCHITECT_REVIEW_PROMPT: string;
4
+ export declare const ARCHITECT_REVIEW_GBNF: string;
5
+ export declare const ARCHITECT_VALIDATE_PROMPT: string;
6
+ export declare const ARCHITECT_VALIDATE_GBNF: string;
7
+ export declare const BUILDER_PATCH_GBNF_SEARCH_REPLACE: string;
8
+ export declare const BUILDER_PATCH_GBNF_FILE_WRITES: string;
9
+ export declare const buildBuilderPrompt: (mode: "tool_calls" | "patch_json" | "freeform", patchFormat?: "search_replace" | "file_writes") => string;
10
+ export declare const buildInterpreterPrompt: (patchFormat?: "search_replace" | "file_writes") => string;
11
+ export declare const buildInterpreterRetryPrompt: (patchFormat?: "search_replace" | "file_writes") => string;
12
+ export declare const BUILDER_PROMPT: string;
13
+ export declare const CRITIC_PROMPT: string;
14
+ export declare const CONTEXT_SUMMARY_PROMPT: string;
15
+ //# sourceMappingURL=Prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Prompts.d.ts","sourceRoot":"","sources":["../../src/cognitive/Prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,QAiEjB,CAAC;AAEb,eAAO,MAAM,cAAc,QAWf,CAAC;AAEb,eAAO,MAAM,uBAAuB,QAgBxB,CAAC;AAEb,eAAO,MAAM,qBAAqB,QAQtB,CAAC;AAEb,eAAO,MAAM,yBAAyB,QA4B1B,CAAC;AAEb,eAAO,MAAM,uBAAuB,QAAiB,CAAC;AAEtD,eAAO,MAAM,iCAAiC,QAalC,CAAC;AAEb,eAAO,MAAM,8BAA8B,QAW/B,CAAC;AA6Fb,eAAO,MAAM,kBAAkB,GAC7B,MAAM,YAAY,GAAG,YAAY,GAAG,UAAU,EAC9C,cAAa,gBAAgB,GAAG,aAAgC,KAC/D,MAUF,CAAC;AAyDF,eAAO,MAAM,sBAAsB,GACjC,cAAa,gBAAgB,GAAG,aAAgC,KAC/D,MAGoC,CAAC;AAExC,eAAO,MAAM,2BAA2B,GACtC,cAAa,gBAAgB,GAAG,aAAgC,KAC/D,MAGmC,CAAC;AAEvC,eAAO,MAAM,cAAc,QAA4B,CAAC;AAExD,eAAO,MAAM,aAAa,QAMd,CAAC;AAEb,eAAO,MAAM,sBAAsB,QAIvB,CAAC"}