@mcoda/mswarm 0.1.57 → 0.1.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/README.md +19 -0
  2. package/dist/codali-executor.d.ts +278 -0
  3. package/dist/codali-executor.d.ts.map +1 -0
  4. package/dist/codali-executor.js +243 -0
  5. package/dist/codali-executor.js.map +1 -0
  6. package/dist/runtime.d.ts +46 -1
  7. package/dist/runtime.d.ts.map +1 -1
  8. package/dist/runtime.js +298 -30
  9. package/dist/runtime.js.map +1 -1
  10. package/dist/server.d.ts.map +1 -1
  11. package/dist/server.js +66 -1
  12. package/dist/server.js.map +1 -1
  13. package/dist/vendor/codali/agents/AgentProtocol.d.ts +287 -0
  14. package/dist/vendor/codali/agents/AgentProtocol.d.ts.map +1 -0
  15. package/dist/vendor/codali/agents/AgentProtocol.js +365 -0
  16. package/dist/vendor/codali/agents/AgentResolver.d.ts +23 -0
  17. package/dist/vendor/codali/agents/AgentResolver.d.ts.map +1 -0
  18. package/dist/vendor/codali/agents/AgentResolver.js +77 -0
  19. package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts +23 -0
  20. package/dist/vendor/codali/agents/PhaseAgentSelector.d.ts.map +1 -0
  21. package/dist/vendor/codali/agents/PhaseAgentSelector.js +287 -0
  22. package/dist/vendor/codali/cli/EvalCommand.d.ts +37 -0
  23. package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -0
  24. package/dist/vendor/codali/cli/EvalCommand.js +333 -0
  25. package/dist/vendor/codali/cli/FeedbackCommand.d.ts +22 -0
  26. package/dist/vendor/codali/cli/FeedbackCommand.d.ts.map +1 -0
  27. package/dist/vendor/codali/cli/FeedbackCommand.js +163 -0
  28. package/dist/vendor/codali/cli/RunCommand.d.ts +78 -0
  29. package/dist/vendor/codali/cli/RunCommand.d.ts.map +1 -0
  30. package/dist/vendor/codali/cli/RunCommand.js +2261 -0
  31. package/dist/vendor/codali/cli.d.ts +3 -0
  32. package/dist/vendor/codali/cli.d.ts.map +1 -0
  33. package/dist/vendor/codali/cli.js +109 -0
  34. package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts +107 -0
  35. package/dist/vendor/codali/cognitive/ArchitectPlanner.d.ts.map +1 -0
  36. package/dist/vendor/codali/cognitive/ArchitectPlanner.js +1726 -0
  37. package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts +25 -0
  38. package/dist/vendor/codali/cognitive/BuilderOutputParser.d.ts.map +1 -0
  39. package/dist/vendor/codali/cognitive/BuilderOutputParser.js +164 -0
  40. package/dist/vendor/codali/cognitive/BuilderRunner.d.ts +76 -0
  41. package/dist/vendor/codali/cognitive/BuilderRunner.d.ts.map +1 -0
  42. package/dist/vendor/codali/cognitive/BuilderRunner.js +1159 -0
  43. package/dist/vendor/codali/cognitive/ContextAssembler.d.ts +91 -0
  44. package/dist/vendor/codali/cognitive/ContextAssembler.d.ts.map +1 -0
  45. package/dist/vendor/codali/cognitive/ContextAssembler.js +4547 -0
  46. package/dist/vendor/codali/cognitive/ContextBudget.d.ts +19 -0
  47. package/dist/vendor/codali/cognitive/ContextBudget.d.ts.map +1 -0
  48. package/dist/vendor/codali/cognitive/ContextBudget.js +35 -0
  49. package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts +30 -0
  50. package/dist/vendor/codali/cognitive/ContextFileLoader.d.ts.map +1 -0
  51. package/dist/vendor/codali/cognitive/ContextFileLoader.js +307 -0
  52. package/dist/vendor/codali/cognitive/ContextManager.d.ts +47 -0
  53. package/dist/vendor/codali/cognitive/ContextManager.d.ts.map +1 -0
  54. package/dist/vendor/codali/cognitive/ContextManager.js +272 -0
  55. package/dist/vendor/codali/cognitive/ContextRedactor.d.ts +18 -0
  56. package/dist/vendor/codali/cognitive/ContextRedactor.d.ts.map +1 -0
  57. package/dist/vendor/codali/cognitive/ContextRedactor.js +53 -0
  58. package/dist/vendor/codali/cognitive/ContextSelector.d.ts +22 -0
  59. package/dist/vendor/codali/cognitive/ContextSelector.d.ts.map +1 -0
  60. package/dist/vendor/codali/cognitive/ContextSelector.js +431 -0
  61. package/dist/vendor/codali/cognitive/ContextSerializer.d.ts +8 -0
  62. package/dist/vendor/codali/cognitive/ContextSerializer.d.ts.map +1 -0
  63. package/dist/vendor/codali/cognitive/ContextSerializer.js +882 -0
  64. package/dist/vendor/codali/cognitive/ContextStore.d.ts +27 -0
  65. package/dist/vendor/codali/cognitive/ContextStore.d.ts.map +1 -0
  66. package/dist/vendor/codali/cognitive/ContextStore.js +79 -0
  67. package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts +16 -0
  68. package/dist/vendor/codali/cognitive/ContextSummarizer.d.ts.map +1 -0
  69. package/dist/vendor/codali/cognitive/ContextSummarizer.js +45 -0
  70. package/dist/vendor/codali/cognitive/CostEstimator.d.ts +31 -0
  71. package/dist/vendor/codali/cognitive/CostEstimator.d.ts.map +1 -0
  72. package/dist/vendor/codali/cognitive/CostEstimator.js +66 -0
  73. package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts +32 -0
  74. package/dist/vendor/codali/cognitive/CriticEvaluator.d.ts.map +1 -0
  75. package/dist/vendor/codali/cognitive/CriticEvaluator.js +297 -0
  76. package/dist/vendor/codali/cognitive/EvidenceGate.d.ts +9 -0
  77. package/dist/vendor/codali/cognitive/EvidenceGate.d.ts.map +1 -0
  78. package/dist/vendor/codali/cognitive/EvidenceGate.js +75 -0
  79. package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts +12 -0
  80. package/dist/vendor/codali/cognitive/GoldenExampleIndexer.d.ts.map +1 -0
  81. package/dist/vendor/codali/cognitive/GoldenExampleIndexer.js +34 -0
  82. package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts +33 -0
  83. package/dist/vendor/codali/cognitive/GoldenSetStore.d.ts.map +1 -0
  84. package/dist/vendor/codali/cognitive/GoldenSetStore.js +159 -0
  85. package/dist/vendor/codali/cognitive/IntentSignals.d.ts +7 -0
  86. package/dist/vendor/codali/cognitive/IntentSignals.d.ts.map +1 -0
  87. package/dist/vendor/codali/cognitive/IntentSignals.js +285 -0
  88. package/dist/vendor/codali/cognitive/LearningGovernance.d.ts +100 -0
  89. package/dist/vendor/codali/cognitive/LearningGovernance.d.ts.map +1 -0
  90. package/dist/vendor/codali/cognitive/LearningGovernance.js +276 -0
  91. package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts +64 -0
  92. package/dist/vendor/codali/cognitive/MemoryWriteback.d.ts.map +1 -0
  93. package/dist/vendor/codali/cognitive/MemoryWriteback.js +287 -0
  94. package/dist/vendor/codali/cognitive/PatchApplier.d.ts +49 -0
  95. package/dist/vendor/codali/cognitive/PatchApplier.d.ts.map +1 -0
  96. package/dist/vendor/codali/cognitive/PatchApplier.js +199 -0
  97. package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts +35 -0
  98. package/dist/vendor/codali/cognitive/PatchInterpreter.d.ts.map +1 -0
  99. package/dist/vendor/codali/cognitive/PatchInterpreter.js +100 -0
  100. package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts +7 -0
  101. package/dist/vendor/codali/cognitive/PatchOutputNormalizer.d.ts.map +1 -0
  102. package/dist/vendor/codali/cognitive/PatchOutputNormalizer.js +59 -0
  103. package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts +17 -0
  104. package/dist/vendor/codali/cognitive/PostMortemAnalyzer.d.ts.map +1 -0
  105. package/dist/vendor/codali/cognitive/PostMortemAnalyzer.js +131 -0
  106. package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts +3 -0
  107. package/dist/vendor/codali/cognitive/PreferenceExtraction.d.ts.map +1 -0
  108. package/dist/vendor/codali/cognitive/PreferenceExtraction.js +85 -0
  109. package/dist/vendor/codali/cognitive/Prompts.d.ts +15 -0
  110. package/dist/vendor/codali/cognitive/Prompts.d.ts.map +1 -0
  111. package/dist/vendor/codali/cognitive/Prompts.js +326 -0
  112. package/dist/vendor/codali/cognitive/ProviderRouting.d.ts +16 -0
  113. package/dist/vendor/codali/cognitive/ProviderRouting.d.ts.map +1 -0
  114. package/dist/vendor/codali/cognitive/ProviderRouting.js +24 -0
  115. package/dist/vendor/codali/cognitive/QueryExtraction.d.ts +12 -0
  116. package/dist/vendor/codali/cognitive/QueryExtraction.d.ts.map +1 -0
  117. package/dist/vendor/codali/cognitive/QueryExtraction.js +262 -0
  118. package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts +13 -0
  119. package/dist/vendor/codali/cognitive/RunHistoryIndexer.d.ts.map +1 -0
  120. package/dist/vendor/codali/cognitive/RunHistoryIndexer.js +125 -0
  121. package/dist/vendor/codali/cognitive/SmartPipeline.d.ts +92 -0
  122. package/dist/vendor/codali/cognitive/SmartPipeline.d.ts.map +1 -0
  123. package/dist/vendor/codali/cognitive/SmartPipeline.js +4804 -0
  124. package/dist/vendor/codali/cognitive/Types.d.ts +474 -0
  125. package/dist/vendor/codali/cognitive/Types.d.ts.map +1 -0
  126. package/dist/vendor/codali/cognitive/Types.js +7 -0
  127. package/dist/vendor/codali/cognitive/ValidationRunner.d.ts +57 -0
  128. package/dist/vendor/codali/cognitive/ValidationRunner.d.ts.map +1 -0
  129. package/dist/vendor/codali/cognitive/ValidationRunner.js +515 -0
  130. package/dist/vendor/codali/config/Config.d.ts +249 -0
  131. package/dist/vendor/codali/config/Config.d.ts.map +1 -0
  132. package/dist/vendor/codali/config/Config.js +200 -0
  133. package/dist/vendor/codali/config/ConfigLoader.d.ts +56 -0
  134. package/dist/vendor/codali/config/ConfigLoader.d.ts.map +1 -0
  135. package/dist/vendor/codali/config/ConfigLoader.js +1246 -0
  136. package/dist/vendor/codali/docdex/DocdexClient.d.ts +158 -0
  137. package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -0
  138. package/dist/vendor/codali/docdex/DocdexClient.js +785 -0
  139. package/dist/vendor/codali/eval/EvalRunner.d.ts +35 -0
  140. package/dist/vendor/codali/eval/EvalRunner.d.ts.map +1 -0
  141. package/dist/vendor/codali/eval/EvalRunner.js +38 -0
  142. package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts +81 -0
  143. package/dist/vendor/codali/eval/EvalTaskExecutor.d.ts.map +1 -0
  144. package/dist/vendor/codali/eval/EvalTaskExecutor.js +371 -0
  145. package/dist/vendor/codali/eval/GateEvaluator.d.ts +31 -0
  146. package/dist/vendor/codali/eval/GateEvaluator.d.ts.map +1 -0
  147. package/dist/vendor/codali/eval/GateEvaluator.js +134 -0
  148. package/dist/vendor/codali/eval/MetricTypes.d.ts +28 -0
  149. package/dist/vendor/codali/eval/MetricTypes.d.ts.map +1 -0
  150. package/dist/vendor/codali/eval/MetricTypes.js +1 -0
  151. package/dist/vendor/codali/eval/MetricsAggregator.d.ts +4 -0
  152. package/dist/vendor/codali/eval/MetricsAggregator.d.ts.map +1 -0
  153. package/dist/vendor/codali/eval/MetricsAggregator.js +97 -0
  154. package/dist/vendor/codali/eval/RegressionComparator.d.ts +29 -0
  155. package/dist/vendor/codali/eval/RegressionComparator.d.ts.map +1 -0
  156. package/dist/vendor/codali/eval/RegressionComparator.js +155 -0
  157. package/dist/vendor/codali/eval/ReportInputAdapter.d.ts +52 -0
  158. package/dist/vendor/codali/eval/ReportInputAdapter.d.ts.map +1 -0
  159. package/dist/vendor/codali/eval/ReportInputAdapter.js +229 -0
  160. package/dist/vendor/codali/eval/ReportSerializer.d.ts +32 -0
  161. package/dist/vendor/codali/eval/ReportSerializer.d.ts.map +1 -0
  162. package/dist/vendor/codali/eval/ReportSerializer.js +33 -0
  163. package/dist/vendor/codali/eval/ReportStore.d.ts +18 -0
  164. package/dist/vendor/codali/eval/ReportStore.d.ts.map +1 -0
  165. package/dist/vendor/codali/eval/ReportStore.js +96 -0
  166. package/dist/vendor/codali/eval/SuiteLoader.d.ts +12 -0
  167. package/dist/vendor/codali/eval/SuiteLoader.d.ts.map +1 -0
  168. package/dist/vendor/codali/eval/SuiteLoader.js +51 -0
  169. package/dist/vendor/codali/eval/SuiteSchema.d.ts +56 -0
  170. package/dist/vendor/codali/eval/SuiteSchema.d.ts.map +1 -0
  171. package/dist/vendor/codali/eval/SuiteSchema.js +357 -0
  172. package/dist/vendor/codali/index.d.ts +11 -0
  173. package/dist/vendor/codali/index.d.ts.map +1 -0
  174. package/dist/vendor/codali/index.js +5 -0
  175. package/dist/vendor/codali/providers/CodexCliProvider.d.ts +8 -0
  176. package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -0
  177. package/dist/vendor/codali/providers/CodexCliProvider.js +282 -0
  178. package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts +8 -0
  179. package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -0
  180. package/dist/vendor/codali/providers/OllamaRemoteProvider.js +300 -0
  181. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts +8 -0
  182. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -0
  183. package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +192 -0
  184. package/dist/vendor/codali/providers/ProviderRegistry.d.ts +12 -0
  185. package/dist/vendor/codali/providers/ProviderRegistry.d.ts.map +1 -0
  186. package/dist/vendor/codali/providers/ProviderRegistry.js +28 -0
  187. package/dist/vendor/codali/providers/ProviderTypes.d.ts +81 -0
  188. package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -0
  189. package/dist/vendor/codali/providers/ProviderTypes.js +1 -0
  190. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +189 -0
  191. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -0
  192. package/dist/vendor/codali/runtime/CodaliRuntime.js +1435 -0
  193. package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts +39 -0
  194. package/dist/vendor/codali/runtime/DeepInvestigationErrors.d.ts.map +1 -0
  195. package/dist/vendor/codali/runtime/DeepInvestigationErrors.js +57 -0
  196. package/dist/vendor/codali/runtime/RunContext.d.ts +27 -0
  197. package/dist/vendor/codali/runtime/RunContext.d.ts.map +1 -0
  198. package/dist/vendor/codali/runtime/RunContext.js +51 -0
  199. package/dist/vendor/codali/runtime/RunLogQuery.d.ts +48 -0
  200. package/dist/vendor/codali/runtime/RunLogQuery.d.ts.map +1 -0
  201. package/dist/vendor/codali/runtime/RunLogQuery.js +36 -0
  202. package/dist/vendor/codali/runtime/RunLogReader.d.ts +19 -0
  203. package/dist/vendor/codali/runtime/RunLogReader.d.ts.map +1 -0
  204. package/dist/vendor/codali/runtime/RunLogReader.js +361 -0
  205. package/dist/vendor/codali/runtime/RunLogger.d.ts +71 -0
  206. package/dist/vendor/codali/runtime/RunLogger.d.ts.map +1 -0
  207. package/dist/vendor/codali/runtime/RunLogger.js +100 -0
  208. package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts +117 -0
  209. package/dist/vendor/codali/runtime/RunTelemetryTypes.d.ts.map +1 -0
  210. package/dist/vendor/codali/runtime/RunTelemetryTypes.js +299 -0
  211. package/dist/vendor/codali/runtime/Runner.d.ts +66 -0
  212. package/dist/vendor/codali/runtime/Runner.d.ts.map +1 -0
  213. package/dist/vendor/codali/runtime/Runner.js +215 -0
  214. package/dist/vendor/codali/runtime/StoragePaths.d.ts +3 -0
  215. package/dist/vendor/codali/runtime/StoragePaths.d.ts.map +1 -0
  216. package/dist/vendor/codali/runtime/StoragePaths.js +19 -0
  217. package/dist/vendor/codali/runtime/WorkspaceLock.d.ts +30 -0
  218. package/dist/vendor/codali/runtime/WorkspaceLock.d.ts.map +1 -0
  219. package/dist/vendor/codali/runtime/WorkspaceLock.js +141 -0
  220. package/dist/vendor/codali/session/InstructionLoader.d.ts +14 -0
  221. package/dist/vendor/codali/session/InstructionLoader.d.ts.map +1 -0
  222. package/dist/vendor/codali/session/InstructionLoader.js +107 -0
  223. package/dist/vendor/codali/session/SessionStore.d.ts +81 -0
  224. package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -0
  225. package/dist/vendor/codali/session/SessionStore.js +244 -0
  226. package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts +68 -0
  227. package/dist/vendor/codali/subagents/SubagentOrchestrator.d.ts.map +1 -0
  228. package/dist/vendor/codali/subagents/SubagentOrchestrator.js +150 -0
  229. package/dist/vendor/codali/tools/ToolRegistry.d.ts +9 -0
  230. package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -0
  231. package/dist/vendor/codali/tools/ToolRegistry.js +293 -0
  232. package/dist/vendor/codali/tools/ToolTypes.d.ts +66 -0
  233. package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -0
  234. package/dist/vendor/codali/tools/ToolTypes.js +40 -0
  235. package/dist/vendor/codali/tools/diff/DiffTool.d.ts +3 -0
  236. package/dist/vendor/codali/tools/diff/DiffTool.d.ts.map +1 -0
  237. package/dist/vendor/codali/tools/diff/DiffTool.js +34 -0
  238. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts +4 -0
  239. package/dist/vendor/codali/tools/docdex/DocdexTools.d.ts.map +1 -0
  240. package/dist/vendor/codali/tools/docdex/DocdexTools.js +490 -0
  241. package/dist/vendor/codali/tools/filesystem/FileTools.d.ts +3 -0
  242. package/dist/vendor/codali/tools/filesystem/FileTools.d.ts.map +1 -0
  243. package/dist/vendor/codali/tools/filesystem/FileTools.js +141 -0
  244. package/dist/vendor/codali/tools/search/SearchTool.d.ts +3 -0
  245. package/dist/vendor/codali/tools/search/SearchTool.d.ts.map +1 -0
  246. package/dist/vendor/codali/tools/search/SearchTool.js +46 -0
  247. package/dist/vendor/codali/tools/shell/ShellTool.d.ts +3 -0
  248. package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -0
  249. package/dist/vendor/codali/tools/shell/ShellTool.js +104 -0
  250. package/package.json +5 -3
@@ -0,0 +1,357 @@
1
+ export const EVAL_COMMANDS = ["run", "fix", "review", "explain", "test"];
2
+ export const EVAL_VERIFICATION_EXPECTATIONS = [
3
+ "verified_passed",
4
+ "verified_failed",
5
+ "unverified_with_reason",
6
+ "any",
7
+ ];
8
+ export class SuiteValidationError extends Error {
9
+ constructor(message, issues) {
10
+ super(message);
11
+ this.name = "SuiteValidationError";
12
+ this.issues = issues;
13
+ }
14
+ }
15
+ const asRecord = (value) => {
16
+ if (!value || typeof value !== "object" || Array.isArray(value))
17
+ return undefined;
18
+ return value;
19
+ };
20
+ const readAliased = (source, aliases) => {
21
+ for (const alias of aliases) {
22
+ if (Object.prototype.hasOwnProperty.call(source, alias))
23
+ return source[alias];
24
+ }
25
+ return undefined;
26
+ };
27
+ const readString = (source, aliases) => {
28
+ const value = readAliased(source, aliases);
29
+ if (typeof value !== "string")
30
+ return undefined;
31
+ const normalized = value.trim();
32
+ return normalized.length ? normalized : undefined;
33
+ };
34
+ const readBoolean = (source, aliases) => {
35
+ const value = readAliased(source, aliases);
36
+ return typeof value === "boolean" ? value : undefined;
37
+ };
38
+ const readNumber = (source, aliases) => {
39
+ const value = readAliased(source, aliases);
40
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
41
+ };
42
+ const readInteger = (source, aliases) => {
43
+ const value = readNumber(source, aliases);
44
+ return value !== undefined && Number.isInteger(value) ? value : undefined;
45
+ };
46
+ const normalizeRateField = (source, aliases, issues, pathLabel) => {
47
+ const value = readNumber(source, aliases);
48
+ if (value === undefined)
49
+ return undefined;
50
+ if (value < 0 || value > 1) {
51
+ issues.push({
52
+ path: pathLabel,
53
+ code: "invalid_rate_range",
54
+ message: "Expected a number between 0 and 1.",
55
+ });
56
+ return undefined;
57
+ }
58
+ return value;
59
+ };
60
+ const normalizeVerificationExpectation = (source, issues, pathLabel) => {
61
+ const value = readString(source, ["expect_verification", "expectVerification"]);
62
+ if (!value)
63
+ return undefined;
64
+ if (EVAL_VERIFICATION_EXPECTATIONS.includes(value)) {
65
+ return value;
66
+ }
67
+ if (["verified_passed", "verified_failed", "unverified_with_reason"].includes(value)) {
68
+ return value;
69
+ }
70
+ issues.push({
71
+ path: pathLabel,
72
+ code: "invalid_verification_expectation",
73
+ message: `Expected one of: ${EVAL_VERIFICATION_EXPECTATIONS.join(", ")}.`,
74
+ });
75
+ return undefined;
76
+ };
77
+ const normalizeTaskAssertions = (rawValue, taskPath, taskMode, issues) => {
78
+ const source = asRecord(rawValue) ?? {};
79
+ if (!asRecord(rawValue) && rawValue !== undefined) {
80
+ issues.push({
81
+ path: `${taskPath}.assertions`,
82
+ code: "invalid_object",
83
+ message: "Expected an object for assertions.",
84
+ });
85
+ }
86
+ const expectSuccess = readBoolean(source, ["expect_success", "expectSuccess"]) ?? (taskMode !== "failure");
87
+ const explicitExitCode = readInteger(source, ["expect_exit_code", "expectExitCode"]);
88
+ const expectExitCode = explicitExitCode ?? (expectSuccess ? 0 : undefined);
89
+ if (explicitExitCode !== undefined && explicitExitCode < 0) {
90
+ issues.push({
91
+ path: `${taskPath}.assertions.expect_exit_code`,
92
+ code: "invalid_exit_code",
93
+ message: "Expected a non-negative integer.",
94
+ });
95
+ }
96
+ const maxLatencyMs = readNumber(source, ["max_latency_ms", "maxLatencyMs"]);
97
+ if (maxLatencyMs !== undefined && maxLatencyMs <= 0) {
98
+ issues.push({
99
+ path: `${taskPath}.assertions.max_latency_ms`,
100
+ code: "invalid_latency",
101
+ message: "Expected max latency to be greater than 0.",
102
+ });
103
+ }
104
+ const maxCostUsd = readNumber(source, ["max_cost_usd", "maxCostUsd"]);
105
+ if (maxCostUsd !== undefined && maxCostUsd < 0) {
106
+ issues.push({
107
+ path: `${taskPath}.assertions.max_cost_usd`,
108
+ code: "invalid_cost",
109
+ message: "Expected max cost to be greater than or equal to 0.",
110
+ });
111
+ }
112
+ return {
113
+ expect_success: expectSuccess,
114
+ expect_exit_code: expectExitCode,
115
+ expect_patch_apply: readBoolean(source, ["expect_patch_apply", "expectPatchApply"]),
116
+ expect_verification: normalizeVerificationExpectation(source, issues, `${taskPath}.assertions.expect_verification`),
117
+ max_latency_ms: maxLatencyMs !== undefined && maxLatencyMs > 0 ? maxLatencyMs : undefined,
118
+ max_cost_usd: maxCostUsd !== undefined && maxCostUsd >= 0 ? maxCostUsd : undefined,
119
+ allow_hallucination: readBoolean(source, ["allow_hallucination", "allowHallucination"]) ?? false,
120
+ allow_scope_violation: readBoolean(source, ["allow_scope_violation", "allowScopeViolation"]) ?? false,
121
+ };
122
+ };
123
+ const normalizeTask = (value, index, issues) => {
124
+ const taskPath = `tasks[${index}]`;
125
+ const source = asRecord(value);
126
+ if (!source) {
127
+ issues.push({
128
+ path: taskPath,
129
+ code: "invalid_object",
130
+ message: "Expected task to be an object.",
131
+ });
132
+ }
133
+ const taskSource = source ?? {};
134
+ const id = readString(taskSource, ["id"]) ?? `task-${index + 1}`;
135
+ if (!readString(taskSource, ["id"])) {
136
+ issues.push({
137
+ path: `${taskPath}.id`,
138
+ code: "missing_required",
139
+ message: "Task id is required.",
140
+ });
141
+ }
142
+ const title = readString(taskSource, ["title"]) ?? id;
143
+ const modeValue = readString(taskSource, ["mode"]);
144
+ const mode = modeValue === "success" || modeValue === "failure"
145
+ ? modeValue
146
+ : (readBoolean(asRecord(readAliased(taskSource, ["assertions"])) ?? {}, ["expect_success", "expectSuccess"])
147
+ === false
148
+ ? "failure"
149
+ : "success");
150
+ if (modeValue && modeValue !== "success" && modeValue !== "failure") {
151
+ issues.push({
152
+ path: `${taskPath}.mode`,
153
+ code: "invalid_mode",
154
+ message: "Expected task mode to be success|failure.",
155
+ });
156
+ }
157
+ const commandValue = readString(taskSource, ["command"]);
158
+ const command = commandValue && EVAL_COMMANDS.includes(commandValue)
159
+ ? commandValue
160
+ : "run";
161
+ if (commandValue && !EVAL_COMMANDS.includes(commandValue)) {
162
+ issues.push({
163
+ path: `${taskPath}.command`,
164
+ code: "invalid_command",
165
+ message: `Expected command to be one of: ${EVAL_COMMANDS.join(", ")}.`,
166
+ });
167
+ }
168
+ const taskFile = readString(taskSource, ["task_file", "taskFile"]);
169
+ const inlineTask = readString(taskSource, ["inline_task", "inlineTask"]);
170
+ if (!taskFile && !inlineTask) {
171
+ issues.push({
172
+ path: taskPath,
173
+ code: "missing_task_input",
174
+ message: "Expected exactly one of task_file or inline_task.",
175
+ });
176
+ }
177
+ if (taskFile && inlineTask) {
178
+ issues.push({
179
+ path: taskPath,
180
+ code: "ambiguous_task_input",
181
+ message: "Provide only one of task_file or inline_task.",
182
+ });
183
+ }
184
+ const argsValue = readAliased(taskSource, ["args"]);
185
+ const args = [];
186
+ if (Array.isArray(argsValue)) {
187
+ for (let argIndex = 0; argIndex < argsValue.length; argIndex += 1) {
188
+ const entry = argsValue[argIndex];
189
+ if (typeof entry !== "string") {
190
+ issues.push({
191
+ path: `${taskPath}.args[${argIndex}]`,
192
+ code: "invalid_arg",
193
+ message: "Expected every task arg to be a string.",
194
+ });
195
+ continue;
196
+ }
197
+ const normalized = entry.trim();
198
+ if (normalized)
199
+ args.push(normalized);
200
+ }
201
+ }
202
+ else if (argsValue !== undefined) {
203
+ issues.push({
204
+ path: `${taskPath}.args`,
205
+ code: "invalid_args",
206
+ message: "Expected args to be an array of strings.",
207
+ });
208
+ }
209
+ return {
210
+ id,
211
+ title,
212
+ description: readString(taskSource, ["description"]),
213
+ mode,
214
+ command,
215
+ task_file: taskFile,
216
+ inline_task: inlineTask,
217
+ args,
218
+ assertions: normalizeTaskAssertions(readAliased(taskSource, ["assertions"]), taskPath, mode, issues),
219
+ };
220
+ };
221
+ const normalizeThresholds = (value, issues) => {
222
+ if (value === undefined)
223
+ return undefined;
224
+ const source = asRecord(value);
225
+ if (!source) {
226
+ issues.push({
227
+ path: "thresholds",
228
+ code: "invalid_object",
229
+ message: "Expected thresholds to be an object.",
230
+ });
231
+ return undefined;
232
+ }
233
+ const thresholds = {};
234
+ const patchApplyDropMax = normalizeRateField(source, ["patch_apply_drop_max", "patchApplyDropMax"], issues, "thresholds.patch_apply_drop_max");
235
+ if (patchApplyDropMax !== undefined)
236
+ thresholds.patch_apply_drop_max = patchApplyDropMax;
237
+ const verificationPassRateMin = normalizeRateField(source, ["verification_pass_rate_min", "verificationPassRateMin"], issues, "thresholds.verification_pass_rate_min");
238
+ if (verificationPassRateMin !== undefined) {
239
+ thresholds.verification_pass_rate_min = verificationPassRateMin;
240
+ }
241
+ const hallucinationRateMax = normalizeRateField(source, ["hallucination_rate_max", "hallucinationRateMax"], issues, "thresholds.hallucination_rate_max");
242
+ if (hallucinationRateMax !== undefined)
243
+ thresholds.hallucination_rate_max = hallucinationRateMax;
244
+ const scopeViolationRateMax = normalizeRateField(source, ["scope_violation_rate_max", "scopeViolationRateMax"], issues, "thresholds.scope_violation_rate_max");
245
+ if (scopeViolationRateMax !== undefined) {
246
+ thresholds.scope_violation_rate_max = scopeViolationRateMax;
247
+ }
248
+ return Object.keys(thresholds).length ? thresholds : undefined;
249
+ };
250
+ const normalizeBaseline = (value, issues) => {
251
+ if (value === undefined)
252
+ return undefined;
253
+ const source = asRecord(value);
254
+ if (!source) {
255
+ issues.push({
256
+ path: "baseline",
257
+ code: "invalid_object",
258
+ message: "Expected baseline to be an object.",
259
+ });
260
+ return undefined;
261
+ }
262
+ const modeValue = readString(source, ["mode"]);
263
+ let mode = "previous";
264
+ if (modeValue === "previous" || modeValue === "none") {
265
+ mode = modeValue;
266
+ }
267
+ else if (modeValue) {
268
+ issues.push({
269
+ path: "baseline.mode",
270
+ code: "invalid_baseline_mode",
271
+ message: "Expected baseline.mode to be previous|none.",
272
+ });
273
+ }
274
+ return {
275
+ mode,
276
+ report_path: readString(source, ["report_path", "reportPath"]),
277
+ };
278
+ };
279
+ export const normalizeSuiteDefinition = (raw, label = "suite") => {
280
+ const issues = [];
281
+ const source = asRecord(raw);
282
+ if (!source) {
283
+ throw new SuiteValidationError(`${label} is invalid.`, [
284
+ {
285
+ path: label,
286
+ code: "invalid_object",
287
+ message: "Expected suite root to be an object.",
288
+ },
289
+ ]);
290
+ }
291
+ const schemaVersion = readInteger(source, ["schema_version", "schemaVersion"]) ?? 1;
292
+ if (schemaVersion !== 1) {
293
+ issues.push({
294
+ path: "schema_version",
295
+ code: "unsupported_schema_version",
296
+ message: "Only schema_version=1 is supported.",
297
+ });
298
+ }
299
+ const suiteId = readString(source, ["suite_id", "suiteId"]);
300
+ if (!suiteId) {
301
+ issues.push({
302
+ path: "suite_id",
303
+ code: "missing_required",
304
+ message: "suite_id is required.",
305
+ });
306
+ }
307
+ const tasksValue = readAliased(source, ["tasks"]);
308
+ if (!Array.isArray(tasksValue) || tasksValue.length === 0) {
309
+ issues.push({
310
+ path: "tasks",
311
+ code: "missing_tasks",
312
+ message: "tasks must be a non-empty array.",
313
+ });
314
+ }
315
+ const tasksRaw = Array.isArray(tasksValue) ? tasksValue : [];
316
+ const tasks = tasksRaw.map((entry, index) => normalizeTask(entry, index, issues));
317
+ const seenTaskIds = new Set();
318
+ for (const task of tasks) {
319
+ if (seenTaskIds.has(task.id)) {
320
+ issues.push({
321
+ path: `tasks.${task.id}`,
322
+ code: "duplicate_task_id",
323
+ message: `Task id "${task.id}" is duplicated.`,
324
+ });
325
+ continue;
326
+ }
327
+ seenTaskIds.add(task.id);
328
+ }
329
+ if (issues.length > 0) {
330
+ throw new SuiteValidationError(`${label} validation failed.`, issues);
331
+ }
332
+ const normalized = {
333
+ schema_version: 1,
334
+ suite_id: suiteId ?? "unknown-suite",
335
+ name: readString(source, ["name"]) ?? (suiteId ?? "unnamed-suite"),
336
+ description: readString(source, ["description"]),
337
+ thresholds: normalizeThresholds(readAliased(source, ["thresholds"]), issues),
338
+ baseline: normalizeBaseline(readAliased(source, ["baseline"]), issues),
339
+ tasks,
340
+ };
341
+ if (issues.length > 0) {
342
+ throw new SuiteValidationError(`${label} validation failed.`, issues);
343
+ }
344
+ return normalized;
345
+ };
346
+ const stableSort = (value) => {
347
+ if (Array.isArray(value))
348
+ return value.map(stableSort);
349
+ if (!value || typeof value !== "object")
350
+ return value;
351
+ const source = value;
352
+ const sortedEntries = Object.keys(source)
353
+ .sort((left, right) => left.localeCompare(right))
354
+ .map((key) => [key, stableSort(source[key])]);
355
+ return Object.fromEntries(sortedEntries);
356
+ };
357
+ export const stableJsonStringify = (value) => JSON.stringify(stableSort(value));
@@ -0,0 +1,11 @@
1
+ export { runCli } from "./cli.js";
2
+ export { codaliEventToOpenAIChatCompletionChunk, codaliEventToOpenAISseData, createCodaliRuntime, runCodaliTask, } from "./runtime/CodaliRuntime.js";
3
+ export { loadInstructionBlocks, formatInstructionBlocks } from "./session/InstructionLoader.js";
4
+ export { SessionStore } from "./session/SessionStore.js";
5
+ export { SubagentOrchestrator } from "./subagents/SubagentOrchestrator.js";
6
+ export type { ProviderMessage, ProviderUsage, } from "./providers/ProviderTypes.js";
7
+ export type { CodaliRuntime, CodaliOpenAIChunkOptions, CodaliRuntimeAgentInput, CodaliRuntimeDocdexInput, CodaliRuntimeEvent, CodaliRuntimeInput, CodaliRuntimePolicy, CodaliRuntimeProviderInput, CodaliRuntimeSessionInput, CodaliRuntimeSubagentsInput, CodaliRuntimeResult, CodaliRuntimeWorkspace, } from "./runtime/CodaliRuntime.js";
8
+ export type { InstructionBlock, InstructionLoadOptions, } from "./session/InstructionLoader.js";
9
+ export type { CodaliResumeBundle, CodaliSessionMetadata, CodaliSessionStatus, CodaliSessionSummary, CodaliSessionTranscriptEvent, } from "./session/SessionStore.js";
10
+ export type { SubagentPermissions, SubagentResult, SubagentRole, SubagentSpec, SubagentStatus, } from "./subagents/SubagentOrchestrator.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,sCAAsC,EACtC,0BAA0B,EAC1B,mBAAmB,EACnB,aAAa,GACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,YAAY,EACV,eAAe,EACf,aAAa,GACd,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,aAAa,EACb,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,MAAM,qCAAqC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { runCli } from "./cli.js";
2
+ export { codaliEventToOpenAIChatCompletionChunk, codaliEventToOpenAISseData, createCodaliRuntime, runCodaliTask, } from "./runtime/CodaliRuntime.js";
3
+ export { loadInstructionBlocks, formatInstructionBlocks } from "./session/InstructionLoader.js";
4
+ export { SessionStore } from "./session/SessionStore.js";
5
+ export { SubagentOrchestrator } from "./subagents/SubagentOrchestrator.js";
@@ -0,0 +1,8 @@
1
+ import type { Provider, ProviderConfig, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
2
+ export declare class CodexCliProvider implements Provider {
3
+ private config;
4
+ name: string;
5
+ constructor(config: ProviderConfig);
6
+ generate(request: ProviderRequest): Promise<ProviderResponse>;
7
+ }
8
+ //# sourceMappingURL=CodexCliProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodexCliProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CodexCliProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAmB,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAqHvH,qBAAa,gBAAiB,YAAW,QAAQ;IAGnC,OAAO,CAAC,MAAM;IAF1B,IAAI,SAAe;gBAEC,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoKpE"}
@@ -0,0 +1,282 @@
1
+ import { spawn } from "node:child_process";
2
+ const CODEX_NO_SANDBOX_ENV = "MCODA_CODEX_NO_SANDBOX";
3
+ const CODEX_REASONING_ENV = "MCODA_CODEX_REASONING_EFFORT";
4
+ const CODEX_REASONING_ENV_FALLBACK = "CODEX_REASONING_EFFORT";
5
+ const CODEX_STUB_ENV = "MCODA_CLI_STUB";
6
+ const CODEX_COMMAND_ENV = "MCODA_CODEX_COMMAND";
7
+ const CODEX_COMMAND_ARGS_ENV = "MCODA_CODEX_COMMAND_ARGS";
8
+ const ALLOWED_REASONING_EFFORTS = new Set(["low", "medium", "high"]);
9
+ const DEFAULT_REASONING_EFFORT = "high";
10
+ const normalizeReasoningEffort = (raw) => {
11
+ const normalized = raw.trim().toLowerCase();
12
+ if (!normalized)
13
+ return undefined;
14
+ const compact = normalized.replace(/[\s_-]+/g, "");
15
+ if (compact === "xhigh" || compact === "veryhigh" || compact === "max")
16
+ return "high";
17
+ if (compact === "xmedium" || compact === "med")
18
+ return "medium";
19
+ if (compact === "xlow" || compact === "min")
20
+ return "low";
21
+ if (ALLOWED_REASONING_EFFORTS.has(normalized))
22
+ return normalized;
23
+ return undefined;
24
+ };
25
+ const resolveSandboxArgs = () => {
26
+ const raw = process.env[CODEX_NO_SANDBOX_ENV];
27
+ if (raw === undefined || raw.trim() === "") {
28
+ return { args: ["--dangerously-bypass-approvals-and-sandbox"], bypass: true };
29
+ }
30
+ const normalized = raw.trim().toLowerCase();
31
+ if (normalized === "0") {
32
+ return { args: [], bypass: false };
33
+ }
34
+ return { args: ["--dangerously-bypass-approvals-and-sandbox"], bypass: true };
35
+ };
36
+ const resolveReasoningEffort = () => {
37
+ const raw = process.env[CODEX_REASONING_ENV] ?? process.env[CODEX_REASONING_ENV_FALLBACK];
38
+ if (!raw)
39
+ return DEFAULT_REASONING_EFFORT;
40
+ return normalizeReasoningEffort(raw) ?? DEFAULT_REASONING_EFFORT;
41
+ };
42
+ const parseCommandArgs = (raw) => {
43
+ const trimmed = raw?.trim();
44
+ if (!trimmed)
45
+ return [];
46
+ if (trimmed.startsWith("[")) {
47
+ try {
48
+ const parsed = JSON.parse(trimmed);
49
+ if (Array.isArray(parsed)) {
50
+ return parsed
51
+ .map((entry) => (typeof entry === "string" ? entry.trim() : ""))
52
+ .filter((entry) => entry.length > 0);
53
+ }
54
+ }
55
+ catch {
56
+ // fall through to whitespace parsing
57
+ }
58
+ }
59
+ return trimmed.split(/\s+/).filter(Boolean);
60
+ };
61
+ const resolveCodexCommand = () => {
62
+ const command = process.env[CODEX_COMMAND_ENV]?.trim() || "codex";
63
+ const preArgs = parseCommandArgs(process.env[CODEX_COMMAND_ARGS_ENV]);
64
+ return { command, preArgs };
65
+ };
66
+ const formatMessages = (messages) => {
67
+ return messages
68
+ .map((message) => {
69
+ const name = message.name ? `(${message.name})` : "";
70
+ return `${message.role}${name}: ${message.content}`;
71
+ })
72
+ .join("\n\n");
73
+ };
74
+ const extractAssistantText = (parsed) => {
75
+ if (!parsed || typeof parsed !== "object")
76
+ return null;
77
+ const type = typeof parsed.type === "string" ? parsed.type : "";
78
+ const isDelta = type.includes("delta");
79
+ const item = parsed.item ?? parsed;
80
+ const contentParts = Array.isArray(item?.content)
81
+ ? item.content.map((entry) => entry?.text ?? entry?.content ?? "").filter(Boolean)
82
+ : [];
83
+ const text = (typeof item?.text === "string" && item.text) ||
84
+ (typeof item?.content === "string" && item.content) ||
85
+ (contentParts.length ? contentParts.join("") : "") ||
86
+ (typeof parsed.text === "string" && parsed.text) ||
87
+ (typeof parsed.delta === "string" && parsed.delta);
88
+ if (!text)
89
+ return null;
90
+ return { text, isDelta };
91
+ };
92
+ const parseCodexOutput = (raw) => {
93
+ const lines = raw.split(/\r?\n/).filter((line) => line.trim().length > 0);
94
+ let message = "";
95
+ for (const line of lines) {
96
+ try {
97
+ const parsed = JSON.parse(line);
98
+ const event = extractAssistantText(parsed);
99
+ if (!event)
100
+ continue;
101
+ if (event.isDelta) {
102
+ message += event.text;
103
+ }
104
+ else {
105
+ message = event.text;
106
+ }
107
+ }
108
+ catch {
109
+ // ignore parse errors
110
+ }
111
+ }
112
+ if (!message) {
113
+ return lines[lines.length - 1] ?? "";
114
+ }
115
+ return message;
116
+ };
117
+ const isIgnorableStdinError = (error) => error.code === "EPIPE" || error.code === "ERR_STREAM_DESTROYED";
118
+ export class CodexCliProvider {
119
+ constructor(config) {
120
+ this.config = config;
121
+ this.name = "codex-cli";
122
+ }
123
+ async generate(request) {
124
+ const last = request.messages[request.messages.length - 1];
125
+ const emitToken = (token) => {
126
+ if (request.onEvent) {
127
+ request.onEvent({ type: "token", content: token });
128
+ return;
129
+ }
130
+ request.onToken?.(token);
131
+ };
132
+ if (process.env[CODEX_STUB_ENV] === "1") {
133
+ const stubContent = `codex-stub:${last?.content ?? ""}`;
134
+ if (request.stream) {
135
+ emitToken(stubContent);
136
+ }
137
+ return {
138
+ message: {
139
+ role: "assistant",
140
+ content: stubContent,
141
+ },
142
+ };
143
+ }
144
+ const prompt = formatMessages(request.messages);
145
+ const resolvedModel = this.config.model?.trim();
146
+ if (!resolvedModel) {
147
+ throw new Error("AUTH_ERROR: codex-cli provider requires model from selected mcoda agent/config.");
148
+ }
149
+ const sandbox = resolveSandboxArgs();
150
+ const codexCommand = resolveCodexCommand();
151
+ const args = [...codexCommand.preArgs, ...sandbox.args, "exec", "--model", resolvedModel, "--json"];
152
+ if (!sandbox.bypass) {
153
+ args.push("--full-auto");
154
+ }
155
+ const reasoningEffort = resolveReasoningEffort();
156
+ if (reasoningEffort) {
157
+ args.push("-c", `reasoning_effort=${reasoningEffort}`);
158
+ args.push("-c", `model_reasoning_effort=${reasoningEffort}`);
159
+ }
160
+ const timeoutMs = Math.max(1, this.config.timeoutMs ?? 300000);
161
+ const childEnv = { ...process.env };
162
+ if (reasoningEffort) {
163
+ childEnv[CODEX_REASONING_ENV] = reasoningEffort;
164
+ childEnv[CODEX_REASONING_ENV_FALLBACK] = reasoningEffort;
165
+ }
166
+ else {
167
+ delete childEnv[CODEX_REASONING_ENV];
168
+ delete childEnv[CODEX_REASONING_ENV_FALLBACK];
169
+ }
170
+ return await new Promise((resolve, reject) => {
171
+ const child = spawn(codexCommand.command, args, { stdio: ["pipe", "pipe", "pipe"], env: childEnv });
172
+ let raw = "";
173
+ let stderr = "";
174
+ let lineBuffer = "";
175
+ let message = "";
176
+ let settled = false;
177
+ const finishResolve = (response) => {
178
+ if (settled)
179
+ return;
180
+ settled = true;
181
+ clearTimeout(timeoutHandle);
182
+ resolve(response);
183
+ };
184
+ const finishReject = (error) => {
185
+ if (settled)
186
+ return;
187
+ settled = true;
188
+ clearTimeout(timeoutHandle);
189
+ reject(error);
190
+ };
191
+ const timeoutHandle = setTimeout(() => {
192
+ if (settled)
193
+ return;
194
+ const reason = `AUTH_ERROR: codex CLI timed out after ${timeoutMs}ms` +
195
+ (stderr.trim().length > 0 ? `: ${stderr.trim()}` : "");
196
+ child.kill("SIGTERM");
197
+ setTimeout(() => {
198
+ if (!settled) {
199
+ child.kill("SIGKILL");
200
+ }
201
+ }, 500).unref();
202
+ finishReject(new Error(reason));
203
+ }, timeoutMs);
204
+ timeoutHandle.unref();
205
+ const handleLine = (line) => {
206
+ const trimmed = line.trim();
207
+ if (!trimmed)
208
+ return;
209
+ const parsedLine = (() => {
210
+ try {
211
+ return JSON.parse(trimmed);
212
+ }
213
+ catch {
214
+ return null;
215
+ }
216
+ })();
217
+ const event = extractAssistantText(parsedLine);
218
+ if (!event)
219
+ return;
220
+ if (event.isDelta) {
221
+ message += event.text;
222
+ if (request.stream)
223
+ emitToken(event.text);
224
+ return;
225
+ }
226
+ message = event.text;
227
+ if (request.stream)
228
+ emitToken(event.text);
229
+ };
230
+ child.stdout.on("data", (chunk) => {
231
+ const text = chunk.toString();
232
+ raw += text;
233
+ lineBuffer += text;
234
+ const lines = lineBuffer.split(/\r?\n/);
235
+ lineBuffer = lines.pop() ?? "";
236
+ for (const line of lines) {
237
+ handleLine(line);
238
+ }
239
+ });
240
+ child.stderr.on("data", (chunk) => {
241
+ stderr += chunk.toString();
242
+ });
243
+ child.stdin.on("error", (error) => {
244
+ if (settled || isIgnorableStdinError(error))
245
+ return;
246
+ finishReject(new Error(`AUTH_ERROR: codex CLI stdin failed (${error.message})`));
247
+ });
248
+ child.on("error", (error) => {
249
+ finishReject(new Error(`AUTH_ERROR: codex CLI failed (${error.message})`));
250
+ });
251
+ child.on("close", (code) => {
252
+ if (settled)
253
+ return;
254
+ if (lineBuffer.trim()) {
255
+ handleLine(lineBuffer);
256
+ }
257
+ if (code !== 0) {
258
+ finishReject(new Error(`AUTH_ERROR: codex CLI failed (exit ${code}): ${stderr || raw}`.trim()));
259
+ return;
260
+ }
261
+ const output = message.trim() || parseCodexOutput(raw).trim();
262
+ finishResolve({ message: { role: "assistant", content: output }, raw });
263
+ });
264
+ setImmediate(() => {
265
+ if (settled)
266
+ return;
267
+ const stdin = child.stdin;
268
+ if (!stdin || stdin.destroyed || !stdin.writable)
269
+ return;
270
+ try {
271
+ stdin.end(prompt);
272
+ }
273
+ catch (error) {
274
+ const err = error;
275
+ if (!isIgnorableStdinError(err)) {
276
+ finishReject(new Error(`AUTH_ERROR: codex CLI stdin failed (${err.message})`));
277
+ }
278
+ }
279
+ });
280
+ });
281
+ }
282
+ }
@@ -0,0 +1,8 @@
1
+ import type { Provider, ProviderConfig, ProviderRequest, ProviderResponse } from "./ProviderTypes.js";
2
+ export declare class OllamaRemoteProvider implements Provider {
3
+ private config;
4
+ name: string;
5
+ constructor(config: ProviderConfig);
6
+ generate(request: ProviderRequest): Promise<ProviderResponse>;
7
+ }
8
+ //# sourceMappingURL=OllamaRemoteProvider.d.ts.map