@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,263 @@
1
+ import { ToolExecutionError, toolErrorCategoryForCode, } from "./ToolTypes.js";
2
+ const isObject = (value) => {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ };
5
+ const TOOL_SCHEMA_TYPES = new Set([
6
+ "string",
7
+ "number",
8
+ "integer",
9
+ "boolean",
10
+ "object",
11
+ "array",
12
+ "null",
13
+ ]);
14
+ const buildToolError = (code, message, options = {}) => ({
15
+ code,
16
+ category: toolErrorCategoryForCode(code),
17
+ message,
18
+ retryable: options.retryable ?? code === "tool_timeout",
19
+ details: options.details,
20
+ });
21
+ const readSchemaTypes = (schema) => {
22
+ if (schema.type === undefined)
23
+ return undefined;
24
+ if (Array.isArray(schema.type))
25
+ return schema.type;
26
+ return [schema.type];
27
+ };
28
+ const schemaValidationError = (message, path, details = {}) => {
29
+ return buildToolError("tool_schema_invalid", message, {
30
+ retryable: false,
31
+ details: { path, ...details },
32
+ });
33
+ };
34
+ const validateSchema = (schema, path = "$") => {
35
+ if (!schema)
36
+ return undefined;
37
+ const types = readSchemaTypes(schema);
38
+ if (types && types.length === 0) {
39
+ return schemaValidationError("Invalid schema: empty type list", path);
40
+ }
41
+ if (types && types.some((type) => !TOOL_SCHEMA_TYPES.has(type))) {
42
+ return schemaValidationError("Invalid schema: unsupported type", path, { types });
43
+ }
44
+ if (schema.required && (!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
45
+ return schemaValidationError("Invalid schema: required must be a string array", path);
46
+ }
47
+ if (schema.properties !== undefined) {
48
+ if (!isObject(schema.properties)) {
49
+ return schemaValidationError("Invalid schema: properties must be an object", path);
50
+ }
51
+ for (const [key, child] of Object.entries(schema.properties)) {
52
+ const childError = validateSchema(child, `${path}.properties.${key}`);
53
+ if (childError)
54
+ return childError;
55
+ }
56
+ }
57
+ if (schema.items !== undefined) {
58
+ const childError = validateSchema(schema.items, `${path}.items`);
59
+ if (childError)
60
+ return childError;
61
+ }
62
+ if (schema.additionalProperties !== undefined && typeof schema.additionalProperties !== "boolean") {
63
+ return schemaValidationError("Invalid schema: additionalProperties must be boolean", path);
64
+ }
65
+ if (schema.enum !== undefined && !Array.isArray(schema.enum)) {
66
+ return schemaValidationError("Invalid schema: enum must be an array", path);
67
+ }
68
+ return undefined;
69
+ };
70
+ const runtimeTypeOf = (value) => {
71
+ if (value === null)
72
+ return "null";
73
+ if (Array.isArray(value))
74
+ return "array";
75
+ if (typeof value === "string")
76
+ return "string";
77
+ if (typeof value === "number")
78
+ return Number.isInteger(value) ? "integer" : "number";
79
+ if (typeof value === "boolean")
80
+ return "boolean";
81
+ if (isObject(value))
82
+ return "object";
83
+ return "unknown";
84
+ };
85
+ const matchesType = (value, type) => {
86
+ if (type === "string")
87
+ return typeof value === "string";
88
+ if (type === "number")
89
+ return typeof value === "number" && Number.isFinite(value);
90
+ if (type === "integer")
91
+ return typeof value === "number" && Number.isInteger(value);
92
+ if (type === "boolean")
93
+ return typeof value === "boolean";
94
+ if (type === "object")
95
+ return isObject(value);
96
+ if (type === "array")
97
+ return Array.isArray(value);
98
+ return value === null;
99
+ };
100
+ const argumentValidationError = (message, path, details = {}) => {
101
+ return buildToolError("tool_invalid_args", message, {
102
+ retryable: false,
103
+ details: { path, ...details },
104
+ });
105
+ };
106
+ const validateValue = (value, schema, path = "$") => {
107
+ const schemaTypes = readSchemaTypes(schema);
108
+ if (schemaTypes && schemaTypes.length > 0) {
109
+ const matched = schemaTypes.some((type) => matchesType(value, type));
110
+ if (!matched) {
111
+ return argumentValidationError("Invalid argument type", path, {
112
+ expected: schemaTypes,
113
+ actual: runtimeTypeOf(value),
114
+ });
115
+ }
116
+ }
117
+ if (schema.enum && !schema.enum.some((entry) => Object.is(entry, value))) {
118
+ return argumentValidationError("Invalid argument value", path, {
119
+ expected: schema.enum,
120
+ actual: value,
121
+ });
122
+ }
123
+ if (typeof value === "number") {
124
+ if (schema.minimum !== undefined && value < schema.minimum) {
125
+ return argumentValidationError("Argument is below minimum", path, {
126
+ minimum: schema.minimum,
127
+ actual: value,
128
+ });
129
+ }
130
+ if (schema.maximum !== undefined && value > schema.maximum) {
131
+ return argumentValidationError("Argument is above maximum", path, {
132
+ maximum: schema.maximum,
133
+ actual: value,
134
+ });
135
+ }
136
+ }
137
+ if (typeof value === "string") {
138
+ if (schema.minLength !== undefined && value.length < schema.minLength) {
139
+ return argumentValidationError("String argument is shorter than minimum length", path, {
140
+ minLength: schema.minLength,
141
+ actualLength: value.length,
142
+ });
143
+ }
144
+ if (schema.maxLength !== undefined && value.length > schema.maxLength) {
145
+ return argumentValidationError("String argument is longer than maximum length", path, {
146
+ maxLength: schema.maxLength,
147
+ actualLength: value.length,
148
+ });
149
+ }
150
+ }
151
+ if (Array.isArray(value) && schema.items) {
152
+ for (let index = 0; index < value.length; index += 1) {
153
+ const childError = validateValue(value[index], schema.items, `${path}[${index}]`);
154
+ if (childError)
155
+ return childError;
156
+ }
157
+ }
158
+ if (isObject(value)) {
159
+ const properties = schema.properties ?? {};
160
+ const required = schema.required ?? [];
161
+ for (const key of required) {
162
+ if (!(key in value)) {
163
+ return argumentValidationError("Missing required argument", `${path}.${key}`, {
164
+ required: key,
165
+ });
166
+ }
167
+ }
168
+ const allowUnknown = schema.additionalProperties === true;
169
+ for (const [key, entry] of Object.entries(value)) {
170
+ const propertySchema = properties[key];
171
+ if (propertySchema) {
172
+ const childError = validateValue(entry, propertySchema, `${path}.${key}`);
173
+ if (childError)
174
+ return childError;
175
+ continue;
176
+ }
177
+ if (!allowUnknown) {
178
+ return argumentValidationError("Unknown argument", `${path}.${key}`, {
179
+ unknown: key,
180
+ });
181
+ }
182
+ }
183
+ }
184
+ return undefined;
185
+ };
186
+ const PERMISSION_DENIED_PATTERNS = [
187
+ "outside the workspace",
188
+ "outside allowed",
189
+ "not allowed",
190
+ "disallowed",
191
+ "permission",
192
+ "read-only",
193
+ "disabled",
194
+ "eacces",
195
+ "eperm",
196
+ ];
197
+ const normalizeExecutionError = (error) => {
198
+ if (error instanceof ToolExecutionError) {
199
+ return error.toToolError();
200
+ }
201
+ const message = error instanceof Error ? error.message : String(error);
202
+ const normalized = message.toLowerCase();
203
+ if (normalized.includes("timeout") || normalized.includes("timed out") || normalized.includes("etimedout")) {
204
+ return buildToolError("tool_timeout", message, { retryable: true });
205
+ }
206
+ if (PERMISSION_DENIED_PATTERNS.some((pattern) => normalized.includes(pattern))) {
207
+ return buildToolError("tool_permission_denied", message, { retryable: false });
208
+ }
209
+ return buildToolError("tool_execution_failed", message, { retryable: true });
210
+ };
211
+ export class ToolRegistry {
212
+ constructor() {
213
+ this.tools = new Map();
214
+ }
215
+ register(tool) {
216
+ if (this.tools.has(tool.name)) {
217
+ throw new Error(`Tool already registered: ${tool.name}`);
218
+ }
219
+ this.tools.set(tool.name, tool);
220
+ }
221
+ list() {
222
+ return Array.from(this.tools.values());
223
+ }
224
+ describe() {
225
+ return this.list().map((tool) => ({
226
+ name: tool.name,
227
+ description: tool.description,
228
+ inputSchema: tool.inputSchema,
229
+ }));
230
+ }
231
+ async execute(name, args, context) {
232
+ const tool = this.tools.get(name);
233
+ if (!tool) {
234
+ return {
235
+ ok: false,
236
+ output: "",
237
+ error: buildToolError("tool_unknown", `Unknown tool: ${name}`, {
238
+ retryable: false,
239
+ details: { tool: name },
240
+ }),
241
+ };
242
+ }
243
+ const schemaError = validateSchema(tool.inputSchema);
244
+ if (schemaError) {
245
+ return { ok: false, output: "", error: schemaError };
246
+ }
247
+ const validationError = tool.inputSchema ? validateValue(args, tool.inputSchema) : undefined;
248
+ if (validationError) {
249
+ return { ok: false, output: "", error: validationError };
250
+ }
251
+ try {
252
+ const result = await tool.handler(args, context);
253
+ return { ok: true, output: result.output, data: result.data };
254
+ }
255
+ catch (error) {
256
+ return {
257
+ ok: false,
258
+ output: "",
259
+ error: normalizeExecutionError(error),
260
+ };
261
+ }
262
+ }
263
+ }
@@ -0,0 +1,66 @@
1
+ export interface ToolContext {
2
+ workspaceRoot: string;
3
+ runId?: string;
4
+ recordTouchedFile?: (path: string) => void;
5
+ allowOutsideWorkspace?: boolean;
6
+ allowedReadPaths?: string[];
7
+ allowedWritePaths?: string[];
8
+ allowShell?: boolean;
9
+ allowDestructiveOperations?: boolean;
10
+ shellAllowlist?: string[];
11
+ }
12
+ export type ToolSchemaPrimitiveType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
13
+ export interface ToolSchemaDefinition extends Record<string, unknown> {
14
+ type?: ToolSchemaPrimitiveType | ToolSchemaPrimitiveType[];
15
+ properties?: Record<string, ToolSchemaDefinition>;
16
+ required?: string[];
17
+ items?: ToolSchemaDefinition;
18
+ additionalProperties?: boolean;
19
+ enum?: unknown[];
20
+ minimum?: number;
21
+ maximum?: number;
22
+ minLength?: number;
23
+ maxLength?: number;
24
+ }
25
+ export interface ToolInputSchema extends ToolSchemaDefinition {
26
+ type: "object";
27
+ properties?: Record<string, ToolSchemaDefinition>;
28
+ required?: string[];
29
+ }
30
+ export type ToolErrorCode = "tool_unknown" | "tool_schema_invalid" | "tool_invalid_args" | "tool_permission_denied" | "tool_timeout" | "tool_execution_failed";
31
+ export type ToolErrorCategory = "lookup" | "schema" | "validation" | "permission" | "timeout" | "execution";
32
+ export interface ToolError {
33
+ code: ToolErrorCode;
34
+ category: ToolErrorCategory;
35
+ message: string;
36
+ retryable: boolean;
37
+ details?: Record<string, unknown>;
38
+ }
39
+ export declare class ToolExecutionError extends Error {
40
+ readonly code: ToolErrorCode;
41
+ readonly category: ToolErrorCategory;
42
+ readonly retryable: boolean;
43
+ readonly details?: Record<string, unknown>;
44
+ constructor(code: ToolErrorCode, message: string, options?: {
45
+ retryable?: boolean;
46
+ details?: Record<string, unknown>;
47
+ });
48
+ toToolError(): ToolError;
49
+ }
50
+ export declare const toolErrorCategoryForCode: (code: ToolErrorCode) => ToolErrorCategory;
51
+ export interface ToolHandlerResult {
52
+ output: string;
53
+ data?: unknown;
54
+ }
55
+ export interface ToolExecutionResult extends ToolHandlerResult {
56
+ ok: boolean;
57
+ error?: ToolError;
58
+ }
59
+ export type ToolHandler = (args: unknown, context: ToolContext) => Promise<ToolHandlerResult>;
60
+ export interface ToolDefinition {
61
+ name: string;
62
+ description: string;
63
+ inputSchema?: ToolInputSchema;
64
+ handler: ToolHandler;
65
+ }
66
+ //# sourceMappingURL=ToolTypes.d.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,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE9F,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,WAAW,CAAC;CACtB"}
@@ -0,0 +1,32 @@
1
+ export class ToolExecutionError extends Error {
2
+ constructor(code, message, options = {}) {
3
+ super(message);
4
+ this.name = "ToolExecutionError";
5
+ this.code = code;
6
+ this.category = toolErrorCategoryForCode(code);
7
+ this.retryable = options.retryable ?? code === "tool_timeout";
8
+ this.details = options.details;
9
+ }
10
+ toToolError() {
11
+ return {
12
+ code: this.code,
13
+ category: this.category,
14
+ message: this.message,
15
+ retryable: this.retryable,
16
+ details: this.details,
17
+ };
18
+ }
19
+ }
20
+ export const toolErrorCategoryForCode = (code) => {
21
+ if (code === "tool_unknown")
22
+ return "lookup";
23
+ if (code === "tool_schema_invalid")
24
+ return "schema";
25
+ if (code === "tool_invalid_args")
26
+ return "validation";
27
+ if (code === "tool_permission_denied")
28
+ return "permission";
29
+ if (code === "tool_timeout")
30
+ return "timeout";
31
+ return "execution";
32
+ };
@@ -0,0 +1,3 @@
1
+ import type { ToolDefinition } from "../ToolTypes.js";
2
+ export declare const createDiffTool: () => ToolDefinition;
3
+ //# sourceMappingURL=DiffTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DiffTool.d.ts","sourceRoot":"","sources":["../../../src/tools/diff/DiffTool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAanE,eAAO,MAAM,cAAc,QAAO,cAsBhC,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { spawnSync } from "node:child_process";
2
+ const runGitStatus = (cwd) => {
3
+ const result = spawnSync("git", ["status", "--porcelain"], { cwd, encoding: "utf8" });
4
+ if (result.error) {
5
+ return { ok: false, output: "", error: result.error.message };
6
+ }
7
+ if (result.status !== 0) {
8
+ return { ok: false, output: result.stdout ?? "", error: result.stderr ?? "git status failed" };
9
+ }
10
+ return { ok: true, output: result.stdout ?? "" };
11
+ };
12
+ export const createDiffTool = () => ({
13
+ name: "diff_summary",
14
+ description: "Show a git status summary of workspace changes.",
15
+ inputSchema: {
16
+ type: "object",
17
+ properties: {
18
+ maxLines: { type: "number" },
19
+ },
20
+ },
21
+ handler: async (args, context) => {
22
+ const { maxLines = 200 } = args ?? {};
23
+ const result = runGitStatus(context.workspaceRoot);
24
+ if (!result.ok) {
25
+ throw new Error(result.error ?? "git status failed");
26
+ }
27
+ const lines = result.output.split("\n").filter(Boolean);
28
+ const clipped = lines.slice(0, maxLines);
29
+ return {
30
+ output: clipped.join("\n"),
31
+ data: { count: clipped.length, total: lines.length },
32
+ };
33
+ },
34
+ });
@@ -0,0 +1,4 @@
1
+ import type { ToolDefinition } from "../ToolTypes.js";
2
+ import type { DocdexClient } from "../../docdex/DocdexClient.js";
3
+ export declare const createDocdexTools: (client: DocdexClient) => ToolDefinition[];
4
+ //# sourceMappingURL=DocdexTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocdexTools.d.ts","sourceRoot":"","sources":["../../../src/tools/docdex/DocdexTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAOjE,eAAO,MAAM,iBAAiB,GAAI,QAAQ,YAAY,KAAG,cAAc,EA8ftE,CAAC"}