@tyvm/knowhow 0.0.47 → 0.0.48

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 (459) hide show
  1. package/benchmarks/results/27b0a06/2025-09-27/xai/xai-grok-code-fast-1.json +2909 -0
  2. package/benchmarks/results/4057aed/2025-08-14/anthropic/anthropic-claude-sonnet-4-20250514.json +1671 -0
  3. package/jest.config.js +2 -2
  4. package/package.json +8 -3
  5. package/src/agents/base/base.ts +30 -24
  6. package/src/agents/patcher/patcher.ts +26 -5
  7. package/src/agents/tools/agentCall.ts +4 -2
  8. package/src/agents/tools/aiClient.ts +3 -11
  9. package/src/agents/tools/ast/astAppendNode.ts +90 -0
  10. package/src/agents/tools/ast/astDeleteNode.ts +88 -0
  11. package/src/agents/tools/ast/astEditNode.ts +95 -0
  12. package/src/agents/tools/ast/astGetPathForLine.ts +73 -0
  13. package/src/agents/tools/ast/astListPaths.ts +66 -0
  14. package/src/agents/tools/ast/index.ts +7 -0
  15. package/src/agents/tools/callPlugin.ts +8 -2
  16. package/src/agents/tools/embeddingSearch.ts +2 -1
  17. package/src/agents/tools/execCommand.ts +239 -94
  18. package/src/agents/tools/fileSearch.ts +15 -17
  19. package/src/agents/tools/index.ts +1 -0
  20. package/src/agents/tools/language/definitions.ts +10 -2
  21. package/src/agents/tools/language/index.ts +3 -2
  22. package/src/agents/tools/lintFile.ts +4 -2
  23. package/src/agents/tools/list.ts +203 -62
  24. package/src/agents/tools/patch.ts +48 -14
  25. package/src/agents/tools/readBlocks.ts +34 -0
  26. package/src/agents/tools/readFile.ts +23 -0
  27. package/src/agents/tools/stringReplace.ts +33 -9
  28. package/src/agents/tools/writeFile.ts +55 -0
  29. package/src/agents/tools/ycmd/server.ts +14 -4
  30. package/src/chat/CliChatService.ts +6 -1
  31. package/src/chat/modules/AgentModule.ts +107 -64
  32. package/src/chat/modules/AskModule.ts +0 -1
  33. package/src/chat/modules/SetupModule.ts +4 -4
  34. package/src/chat/modules/SystemModule.ts +28 -5
  35. package/src/chat/types.ts +2 -0
  36. package/src/chat-old.ts +2 -2
  37. package/src/clients/anthropic.ts +22 -1
  38. package/src/clients/openai.ts +1 -1
  39. package/src/clients/xai.ts +15 -5
  40. package/src/config.ts +17 -5
  41. package/src/dataset/diffs/generate.ts +2 -2
  42. package/src/dataset/diffs/jsonl.ts +0 -1
  43. package/src/embeddings.ts +6 -4
  44. package/src/index.ts +11 -5
  45. package/src/plugins/GitPlugin.ts +530 -0
  46. package/src/plugins/LinterPlugin.ts +89 -0
  47. package/src/plugins/PluginBase.ts +4 -2
  48. package/src/plugins/asana.ts +4 -2
  49. package/src/plugins/downloader/plugin.ts +5 -2
  50. package/src/plugins/embedding.ts +24 -4
  51. package/src/plugins/figma.ts +7 -3
  52. package/src/plugins/github.ts +4 -2
  53. package/src/plugins/jira.ts +4 -2
  54. package/src/plugins/language.ts +134 -27
  55. package/src/plugins/linear.ts +4 -2
  56. package/src/plugins/notion.ts +4 -2
  57. package/src/plugins/plugins.ts +27 -16
  58. package/src/plugins/tree-sitter/editor.ts +369 -0
  59. package/src/plugins/tree-sitter/lang-packs/index.ts +23 -0
  60. package/src/plugins/tree-sitter/lang-packs/java.ts +59 -0
  61. package/src/plugins/tree-sitter/lang-packs/javascript.ts +57 -0
  62. package/src/plugins/tree-sitter/lang-packs/python.ts +45 -0
  63. package/src/plugins/tree-sitter/lang-packs/types.ts +79 -0
  64. package/src/plugins/tree-sitter/lang-packs/typescript.ts +49 -0
  65. package/src/plugins/tree-sitter/parser.ts +444 -0
  66. package/src/plugins/tree-sitter/simple-paths.ts +467 -0
  67. package/src/plugins/types.ts +11 -0
  68. package/src/plugins/url.ts +5 -3
  69. package/src/plugins/vim.ts +8 -5
  70. package/src/processors/CustomVariables.ts +19 -7
  71. package/src/processors/TokenCompressor.ts +13 -13
  72. package/src/processors/ToolResponseCache.ts +15 -6
  73. package/src/services/EmbeddingService.ts +18 -9
  74. package/src/services/EventService.ts +80 -0
  75. package/src/services/Mcp.ts +5 -0
  76. package/src/services/S3.ts +4 -3
  77. package/src/services/Tools.ts +125 -53
  78. package/src/services/index.ts +16 -11
  79. package/src/services/types.ts +3 -3
  80. package/src/types.ts +7 -2
  81. package/src/worker.ts +14 -1
  82. package/test-comprehensive.ts +31 -0
  83. package/tests/clients/AIClient.test.ts +490 -0
  84. package/tests/manual/agent-events/run-test.ts +203 -0
  85. package/tests/{integration → manual/file-edits}/figma.test.ts +1 -1
  86. package/tests/{integration → manual/file-edits}/fileblocks/readwrite.test.ts +7 -3
  87. package/tests/{integration → manual/file-edits}/patching.test.ts +11 -8
  88. package/tests/plugins/language/languagePlugin-content-triggers.test.ts +332 -0
  89. package/tests/plugins/language/languagePlugin-integration.test.ts +456 -0
  90. package/tests/plugins/language/languagePlugin.test.ts +363 -0
  91. package/tests/processors/Base64ImageDetector.test.ts +403 -0
  92. package/tests/processors/CustomVariables.test.ts +430 -0
  93. package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
  94. package/tests/processors/TokenCompressor.test.ts +391 -0
  95. package/tests/processors/ToolResponseCache.test.ts +688 -0
  96. package/tests/services/Tools.test.ts +1339 -0
  97. package/tests/test.spec.ts +162 -117
  98. package/tests/tree-sitter/editor.test.ts +113 -0
  99. package/tests/tree-sitter/invalid.test.ts +299 -0
  100. package/tests/tree-sitter/paths/common-edits.test.ts +564 -0
  101. package/tests/tree-sitter/paths/debug-exact-position.test.ts +44 -0
  102. package/tests/tree-sitter/paths/debug-line-indexing.test.ts +49 -0
  103. package/tests/tree-sitter/paths/debug-paths.test.ts +90 -0
  104. package/tests/tree-sitter/paths/paths.test.ts +170 -0
  105. package/tests/tree-sitter/paths/simple-paths.test.ts +367 -0
  106. package/tests/tree-sitter/sample-after.ts +48 -0
  107. package/tests/tree-sitter/sample-before.ts +25 -0
  108. package/tests/tree-sitter/test-files/completely-broken.ts +7 -0
  109. package/tests/tree-sitter/test-files/duplicate-braces.ts +39 -0
  110. package/tests/tree-sitter/test-files/invalid-nesting.ts +39 -0
  111. package/tests/tree-sitter/test-files/malformed-signature.ts +39 -0
  112. package/tests/tree-sitter/test-files/mismatched-parens.ts +39 -0
  113. package/tests/tree-sitter/test-files/missing-semicolon.ts +39 -0
  114. package/tests/tree-sitter/test-files/partially-broken.ts +20 -0
  115. package/tests/tree-sitter/test-files/specific-errors.ts +14 -0
  116. package/tests/tree-sitter/test-files/unclosed-string.ts +39 -0
  117. package/tests/tree-sitter/tree-sitter.test.ts +251 -0
  118. package/ts_build/package.json +8 -3
  119. package/ts_build/src/agents/base/base.d.ts +2 -2
  120. package/ts_build/src/agents/base/base.js +24 -20
  121. package/ts_build/src/agents/base/base.js.map +1 -1
  122. package/ts_build/src/agents/patcher/patcher.js +26 -5
  123. package/ts_build/src/agents/patcher/patcher.js.map +1 -1
  124. package/ts_build/src/agents/tools/agentCall.js +2 -1
  125. package/ts_build/src/agents/tools/agentCall.js.map +1 -1
  126. package/ts_build/src/agents/tools/aiClient.d.ts +7 -8
  127. package/ts_build/src/agents/tools/aiClient.js.map +1 -1
  128. package/ts_build/src/agents/tools/ast/astAppendNode.d.ts +1 -0
  129. package/ts_build/src/agents/tools/ast/astAppendNode.js +96 -0
  130. package/ts_build/src/agents/tools/ast/astAppendNode.js.map +1 -0
  131. package/ts_build/src/agents/tools/ast/astDeleteNode.d.ts +1 -0
  132. package/ts_build/src/agents/tools/ast/astDeleteNode.js +94 -0
  133. package/ts_build/src/agents/tools/ast/astDeleteNode.js.map +1 -0
  134. package/ts_build/src/agents/tools/ast/astEditNode.d.ts +1 -0
  135. package/ts_build/src/agents/tools/ast/astEditNode.js +96 -0
  136. package/ts_build/src/agents/tools/ast/astEditNode.js.map +1 -0
  137. package/ts_build/src/agents/tools/ast/astGetPathForLine.d.ts +1 -0
  138. package/ts_build/src/agents/tools/ast/astGetPathForLine.js +78 -0
  139. package/ts_build/src/agents/tools/ast/astGetPathForLine.js.map +1 -0
  140. package/ts_build/src/agents/tools/ast/astListPaths.d.ts +1 -0
  141. package/ts_build/src/agents/tools/ast/astListPaths.js +78 -0
  142. package/ts_build/src/agents/tools/ast/astListPaths.js.map +1 -0
  143. package/ts_build/src/agents/tools/ast/index.d.ts +5 -0
  144. package/ts_build/src/agents/tools/ast/index.js +14 -0
  145. package/ts_build/src/agents/tools/ast/index.js.map +1 -0
  146. package/ts_build/src/agents/tools/astAppendNode.d.ts +1 -0
  147. package/ts_build/src/agents/tools/astAppendNode.js +98 -0
  148. package/ts_build/src/agents/tools/astAppendNode.js.map +1 -0
  149. package/ts_build/src/agents/tools/astDeleteNode.d.ts +1 -0
  150. package/ts_build/src/agents/tools/astDeleteNode.js +95 -0
  151. package/ts_build/src/agents/tools/astDeleteNode.js.map +1 -0
  152. package/ts_build/src/agents/tools/astEditNode.d.ts +1 -0
  153. package/ts_build/src/agents/tools/astEditNode.js +98 -0
  154. package/ts_build/src/agents/tools/astEditNode.js.map +1 -0
  155. package/ts_build/src/agents/tools/astGetPathForLine.d.ts +1 -0
  156. package/ts_build/src/agents/tools/astGetPathForLine.js +89 -0
  157. package/ts_build/src/agents/tools/astGetPathForLine.js.map +1 -0
  158. package/ts_build/src/agents/tools/astListPaths.d.ts +1 -0
  159. package/ts_build/src/agents/tools/astListPaths.js +82 -0
  160. package/ts_build/src/agents/tools/astListPaths.js.map +1 -0
  161. package/ts_build/src/agents/tools/callPlugin.js +4 -2
  162. package/ts_build/src/agents/tools/callPlugin.js.map +1 -1
  163. package/ts_build/src/agents/tools/embeddingSearch.js +3 -2
  164. package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -1
  165. package/ts_build/src/agents/tools/execCommand.d.ts +2 -2
  166. package/ts_build/src/agents/tools/execCommand.js +201 -67
  167. package/ts_build/src/agents/tools/execCommand.js.map +1 -1
  168. package/ts_build/src/agents/tools/fileSearch.d.ts +1 -1
  169. package/ts_build/src/agents/tools/fileSearch.js +11 -15
  170. package/ts_build/src/agents/tools/fileSearch.js.map +1 -1
  171. package/ts_build/src/agents/tools/github/index.d.ts +1 -1
  172. package/ts_build/src/agents/tools/index.d.ts +1 -0
  173. package/ts_build/src/agents/tools/index.js +1 -0
  174. package/ts_build/src/agents/tools/index.js.map +1 -1
  175. package/ts_build/src/agents/tools/language/definitions.js +11 -2
  176. package/ts_build/src/agents/tools/language/definitions.js.map +1 -1
  177. package/ts_build/src/agents/tools/language/index.js +4 -3
  178. package/ts_build/src/agents/tools/language/index.js.map +1 -1
  179. package/ts_build/src/agents/tools/lintFile.js +4 -2
  180. package/ts_build/src/agents/tools/lintFile.js.map +1 -1
  181. package/ts_build/src/agents/tools/list.js +185 -49
  182. package/ts_build/src/agents/tools/list.js.map +1 -1
  183. package/ts_build/src/agents/tools/patch.js +33 -10
  184. package/ts_build/src/agents/tools/patch.js.map +1 -1
  185. package/ts_build/src/agents/tools/readBlocks.js +23 -0
  186. package/ts_build/src/agents/tools/readBlocks.js.map +1 -1
  187. package/ts_build/src/agents/tools/readFile.js +14 -0
  188. package/ts_build/src/agents/tools/readFile.js.map +1 -1
  189. package/ts_build/src/agents/tools/stringReplace.js +19 -2
  190. package/ts_build/src/agents/tools/stringReplace.js.map +1 -1
  191. package/ts_build/src/agents/tools/writeFile.js +40 -0
  192. package/ts_build/src/agents/tools/writeFile.js.map +1 -1
  193. package/ts_build/src/agents/tools/ycmd/server.js +5 -0
  194. package/ts_build/src/agents/tools/ycmd/server.js.map +1 -1
  195. package/ts_build/src/chat/CliChatService.d.ts +1 -0
  196. package/ts_build/src/chat/CliChatService.js +6 -2
  197. package/ts_build/src/chat/CliChatService.js.map +1 -1
  198. package/ts_build/src/chat/modules/AgentModule.d.ts +5 -1
  199. package/ts_build/src/chat/modules/AgentModule.js +53 -31
  200. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  201. package/ts_build/src/chat/modules/AskModule.js.map +1 -1
  202. package/ts_build/src/chat/modules/SetupModule.js +4 -3
  203. package/ts_build/src/chat/modules/SetupModule.js.map +1 -1
  204. package/ts_build/src/chat/modules/SystemModule.js +19 -4
  205. package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
  206. package/ts_build/src/chat/modules/index.d.ts +5 -0
  207. package/ts_build/src/chat/modules/index.js +14 -0
  208. package/ts_build/src/chat/modules/index.js.map +1 -0
  209. package/ts_build/src/chat/types.d.ts +2 -0
  210. package/ts_build/src/chat-old.js +3 -3
  211. package/ts_build/src/chat-old.js.map +1 -1
  212. package/ts_build/src/clients/anthropic.d.ts +1 -0
  213. package/ts_build/src/clients/anthropic.js +22 -1
  214. package/ts_build/src/clients/anthropic.js.map +1 -1
  215. package/ts_build/src/clients/openai.js +1 -1
  216. package/ts_build/src/clients/openai.js.map +1 -1
  217. package/ts_build/src/clients/xai.d.ts +7 -0
  218. package/ts_build/src/clients/xai.js +13 -4
  219. package/ts_build/src/clients/xai.js.map +1 -1
  220. package/ts_build/src/config.js +14 -3
  221. package/ts_build/src/config.js.map +1 -1
  222. package/ts_build/src/dataset/diffs/generate.js +2 -2
  223. package/ts_build/src/dataset/diffs/generate.js.map +1 -1
  224. package/ts_build/src/dataset/diffs/jsonl.js.map +1 -1
  225. package/ts_build/src/embeddings.js +7 -9
  226. package/ts_build/src/embeddings.js.map +1 -1
  227. package/ts_build/src/index.js +10 -10
  228. package/ts_build/src/index.js.map +1 -1
  229. package/ts_build/src/plugins/GitPlugin.d.ts +39 -0
  230. package/ts_build/src/plugins/GitPlugin.js +439 -0
  231. package/ts_build/src/plugins/GitPlugin.js.map +1 -0
  232. package/ts_build/src/plugins/LinterPlugin.d.ts +15 -0
  233. package/ts_build/src/plugins/LinterPlugin.js +65 -0
  234. package/ts_build/src/plugins/LinterPlugin.js.map +1 -0
  235. package/ts_build/src/plugins/PluginBase.d.ts +4 -3
  236. package/ts_build/src/plugins/PluginBase.js +3 -3
  237. package/ts_build/src/plugins/PluginBase.js.map +1 -1
  238. package/ts_build/src/plugins/asana.d.ts +3 -1
  239. package/ts_build/src/plugins/asana.js +3 -2
  240. package/ts_build/src/plugins/asana.js.map +1 -1
  241. package/ts_build/src/plugins/downloader/plugin.d.ts +3 -1
  242. package/ts_build/src/plugins/downloader/plugin.js +3 -2
  243. package/ts_build/src/plugins/downloader/plugin.js.map +1 -1
  244. package/ts_build/src/plugins/embedding.d.ts +5 -1
  245. package/ts_build/src/plugins/embedding.js +15 -3
  246. package/ts_build/src/plugins/embedding.js.map +1 -1
  247. package/ts_build/src/plugins/figma.d.ts +3 -1
  248. package/ts_build/src/plugins/figma.js +28 -4
  249. package/ts_build/src/plugins/figma.js.map +1 -1
  250. package/ts_build/src/plugins/github.d.ts +3 -1
  251. package/ts_build/src/plugins/github.js +3 -2
  252. package/ts_build/src/plugins/github.js.map +1 -1
  253. package/ts_build/src/plugins/jira.d.ts +3 -1
  254. package/ts_build/src/plugins/jira.js +3 -2
  255. package/ts_build/src/plugins/jira.js.map +1 -1
  256. package/ts_build/src/plugins/language.d.ts +7 -4
  257. package/ts_build/src/plugins/language.js +85 -20
  258. package/ts_build/src/plugins/language.js.map +1 -1
  259. package/ts_build/src/plugins/linear.d.ts +3 -1
  260. package/ts_build/src/plugins/linear.js +3 -2
  261. package/ts_build/src/plugins/linear.js.map +1 -1
  262. package/ts_build/src/plugins/notion.d.ts +3 -1
  263. package/ts_build/src/plugins/notion.js +3 -2
  264. package/ts_build/src/plugins/notion.js.map +1 -1
  265. package/ts_build/src/plugins/plugins.d.ts +4 -3
  266. package/ts_build/src/plugins/plugins.js +24 -14
  267. package/ts_build/src/plugins/plugins.js.map +1 -1
  268. package/ts_build/src/plugins/tree-sitter/editor.d.ts +34 -0
  269. package/ts_build/src/plugins/tree-sitter/editor.js +218 -0
  270. package/ts_build/src/plugins/tree-sitter/editor.js.map +1 -0
  271. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.d.ts +29 -0
  272. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js +538 -0
  273. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js.map +1 -0
  274. package/ts_build/src/plugins/tree-sitter/human-readable-paths.d.ts +22 -0
  275. package/ts_build/src/plugins/tree-sitter/human-readable-paths.js +332 -0
  276. package/ts_build/src/plugins/tree-sitter/human-readable-paths.js.map +1 -0
  277. package/ts_build/src/plugins/tree-sitter/lang-packs/index.d.ts +8 -0
  278. package/ts_build/src/plugins/tree-sitter/lang-packs/index.js +26 -0
  279. package/ts_build/src/plugins/tree-sitter/lang-packs/index.js.map +1 -0
  280. package/ts_build/src/plugins/tree-sitter/lang-packs/java.d.ts +2 -0
  281. package/ts_build/src/plugins/tree-sitter/lang-packs/java.js +61 -0
  282. package/ts_build/src/plugins/tree-sitter/lang-packs/java.js.map +1 -0
  283. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.d.ts +2 -0
  284. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js +59 -0
  285. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js.map +1 -0
  286. package/ts_build/src/plugins/tree-sitter/lang-packs/python.d.ts +2 -0
  287. package/ts_build/src/plugins/tree-sitter/lang-packs/python.js +47 -0
  288. package/ts_build/src/plugins/tree-sitter/lang-packs/python.js.map +1 -0
  289. package/ts_build/src/plugins/tree-sitter/lang-packs/types.d.ts +43 -0
  290. package/ts_build/src/plugins/tree-sitter/lang-packs/types.js +3 -0
  291. package/ts_build/src/plugins/tree-sitter/lang-packs/types.js.map +1 -0
  292. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.d.ts +2 -0
  293. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js +50 -0
  294. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js.map +1 -0
  295. package/ts_build/src/plugins/tree-sitter/parser.d.ts +75 -0
  296. package/ts_build/src/plugins/tree-sitter/parser.js +306 -0
  297. package/ts_build/src/plugins/tree-sitter/parser.js.map +1 -0
  298. package/ts_build/src/plugins/tree-sitter/simple-paths.d.ts +22 -0
  299. package/ts_build/src/plugins/tree-sitter/simple-paths.js +332 -0
  300. package/ts_build/src/plugins/tree-sitter/simple-paths.js.map +1 -0
  301. package/ts_build/src/plugins/types.d.ts +10 -0
  302. package/ts_build/src/plugins/url.d.ts +3 -2
  303. package/ts_build/src/plugins/url.js +3 -2
  304. package/ts_build/src/plugins/url.js.map +1 -1
  305. package/ts_build/src/plugins/vim.d.ts +4 -2
  306. package/ts_build/src/plugins/vim.js +6 -8
  307. package/ts_build/src/plugins/vim.js.map +1 -1
  308. package/ts_build/src/processors/CustomVariables.js +12 -3
  309. package/ts_build/src/processors/CustomVariables.js.map +1 -1
  310. package/ts_build/src/processors/TokenCompressor.js +8 -11
  311. package/ts_build/src/processors/TokenCompressor.js.map +1 -1
  312. package/ts_build/src/processors/ToolResponseCache.d.ts +2 -2
  313. package/ts_build/src/processors/ToolResponseCache.js +12 -2
  314. package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
  315. package/ts_build/src/services/EmbeddingService.d.ts +10 -1
  316. package/ts_build/src/services/EmbeddingService.js +12 -12
  317. package/ts_build/src/services/EmbeddingService.js.map +1 -1
  318. package/ts_build/src/services/EventService.d.ts +7 -0
  319. package/ts_build/src/services/EventService.js +49 -0
  320. package/ts_build/src/services/EventService.js.map +1 -1
  321. package/ts_build/src/services/Mcp.js +8 -0
  322. package/ts_build/src/services/Mcp.js.map +1 -1
  323. package/ts_build/src/services/S3.js +4 -3
  324. package/ts_build/src/services/S3.js.map +1 -1
  325. package/ts_build/src/services/Tools.d.ts +1 -0
  326. package/ts_build/src/services/Tools.js +97 -35
  327. package/ts_build/src/services/Tools.js.map +1 -1
  328. package/ts_build/src/services/index.d.ts +4 -5
  329. package/ts_build/src/services/index.js +14 -9
  330. package/ts_build/src/services/index.js.map +1 -1
  331. package/ts_build/src/services/types.js +3 -3
  332. package/ts_build/src/services/types.js.map +1 -1
  333. package/ts_build/src/types.d.ts +7 -1
  334. package/ts_build/src/types.js +4 -0
  335. package/ts_build/src/types.js.map +1 -1
  336. package/ts_build/src/worker.js +12 -1
  337. package/ts_build/src/worker.js.map +1 -1
  338. package/ts_build/tests/clients/AIClient.test.d.ts +1 -0
  339. package/ts_build/tests/clients/AIClient.test.js +377 -0
  340. package/ts_build/tests/clients/AIClient.test.js.map +1 -0
  341. package/ts_build/tests/languagePlugin.test.js +217 -11
  342. package/ts_build/tests/languagePlugin.test.js.map +1 -1
  343. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.d.ts +1 -0
  344. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js +315 -0
  345. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js.map +1 -0
  346. package/ts_build/tests/manual/agent-events/run-test.d.ts +2 -0
  347. package/ts_build/tests/manual/agent-events/run-test.js +148 -0
  348. package/ts_build/tests/manual/agent-events/run-test.js.map +1 -0
  349. package/ts_build/tests/manual/file-edits/figma.test.d.ts +1 -0
  350. package/ts_build/tests/manual/file-edits/figma.test.js +47 -0
  351. package/ts_build/tests/manual/file-edits/figma.test.js.map +1 -0
  352. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.d.ts +1 -0
  353. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js +100 -0
  354. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js.map +1 -0
  355. package/ts_build/tests/manual/file-edits/patching.test.d.ts +1 -0
  356. package/ts_build/tests/manual/file-edits/patching.test.js +119 -0
  357. package/ts_build/tests/manual/file-edits/patching.test.js.map +1 -0
  358. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.d.ts +1 -0
  359. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +277 -0
  360. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +1 -0
  361. package/ts_build/tests/plugins/language/languagePlugin-integration.test.d.ts +1 -0
  362. package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +331 -0
  363. package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +1 -0
  364. package/ts_build/tests/plugins/language/languagePlugin.test.d.ts +1 -0
  365. package/ts_build/tests/plugins/language/languagePlugin.test.js +286 -0
  366. package/ts_build/tests/plugins/language/languagePlugin.test.js.map +1 -0
  367. package/ts_build/tests/processors/Base64ImageDetector.test.d.ts +1 -0
  368. package/ts_build/tests/processors/Base64ImageDetector.test.js +351 -0
  369. package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -0
  370. package/ts_build/tests/processors/CustomVariables.test.d.ts +1 -0
  371. package/ts_build/tests/processors/CustomVariables.test.js +351 -0
  372. package/ts_build/tests/processors/CustomVariables.test.js.map +1 -0
  373. package/ts_build/tests/processors/HarmonyToolProcessor.test.d.ts +1 -0
  374. package/ts_build/tests/processors/HarmonyToolProcessor.test.js +382 -0
  375. package/ts_build/tests/processors/HarmonyToolProcessor.test.js.map +1 -0
  376. package/ts_build/tests/processors/TokenCompressor.test.d.ts +1 -0
  377. package/ts_build/tests/processors/TokenCompressor.test.js +300 -0
  378. package/ts_build/tests/processors/TokenCompressor.test.js.map +1 -0
  379. package/ts_build/tests/processors/ToolResponseCache.test.d.ts +1 -0
  380. package/ts_build/tests/processors/ToolResponseCache.test.js +539 -0
  381. package/ts_build/tests/processors/ToolResponseCache.test.js.map +1 -0
  382. package/ts_build/tests/services/Plugins/plugin-event-integration.test.d.ts +1 -0
  383. package/ts_build/tests/services/Plugins/plugin-event-integration.test.js +232 -0
  384. package/ts_build/tests/services/Plugins/plugin-event-integration.test.js.map +1 -0
  385. package/ts_build/tests/services/Tools.test.d.ts +1 -0
  386. package/ts_build/tests/services/Tools.test.js +1059 -0
  387. package/ts_build/tests/services/Tools.test.js.map +1 -0
  388. package/ts_build/tests/test.spec.js +110 -68
  389. package/ts_build/tests/test.spec.js.map +1 -1
  390. package/ts_build/tests/tree-sitter/editor.test.d.ts +1 -0
  391. package/ts_build/tests/tree-sitter/editor.test.js +85 -0
  392. package/ts_build/tests/tree-sitter/editor.test.js.map +1 -0
  393. package/ts_build/tests/tree-sitter/invalid.test.d.ts +1 -0
  394. package/ts_build/tests/tree-sitter/invalid.test.js +198 -0
  395. package/ts_build/tests/tree-sitter/invalid.test.js.map +1 -0
  396. package/ts_build/tests/tree-sitter/paths/common-edits.test.d.ts +1 -0
  397. package/ts_build/tests/tree-sitter/paths/common-edits.test.js +347 -0
  398. package/ts_build/tests/tree-sitter/paths/common-edits.test.js.map +1 -0
  399. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.d.ts +1 -0
  400. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js +35 -0
  401. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js.map +1 -0
  402. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.d.ts +1 -0
  403. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js +38 -0
  404. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js.map +1 -0
  405. package/ts_build/tests/tree-sitter/paths/debug-paths.test.d.ts +1 -0
  406. package/ts_build/tests/tree-sitter/paths/debug-paths.test.js +74 -0
  407. package/ts_build/tests/tree-sitter/paths/debug-paths.test.js.map +1 -0
  408. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.d.ts +1 -0
  409. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js +302 -0
  410. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js.map +1 -0
  411. package/ts_build/tests/tree-sitter/paths/paths.test.d.ts +1 -0
  412. package/ts_build/tests/tree-sitter/paths/paths.test.js +116 -0
  413. package/ts_build/tests/tree-sitter/paths/paths.test.js.map +1 -0
  414. package/ts_build/tests/tree-sitter/paths/simple-paths.test.d.ts +1 -0
  415. package/ts_build/tests/tree-sitter/paths/simple-paths.test.js +302 -0
  416. package/ts_build/tests/tree-sitter/paths/simple-paths.test.js.map +1 -0
  417. package/ts_build/tests/tree-sitter/sample-after.d.ts +11 -0
  418. package/ts_build/tests/tree-sitter/sample-after.js +44 -0
  419. package/ts_build/tests/tree-sitter/sample-after.js.map +1 -0
  420. package/ts_build/tests/tree-sitter/sample-before.d.ts +9 -0
  421. package/ts_build/tests/tree-sitter/sample-before.js +28 -0
  422. package/ts_build/tests/tree-sitter/sample-before.js.map +1 -0
  423. package/ts_build/tests/tree-sitter/test-files/completely-broken.d.ts +2 -0
  424. package/ts_build/tests/tree-sitter/test-files/completely-broken.js +17 -0
  425. package/ts_build/tests/tree-sitter/test-files/completely-broken.js.map +1 -0
  426. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.d.ts +8 -0
  427. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js +38 -0
  428. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js.map +1 -0
  429. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.d.ts +8 -0
  430. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js +38 -0
  431. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js.map +1 -0
  432. package/ts_build/tests/tree-sitter/test-files/malformed-signature.d.ts +8 -0
  433. package/ts_build/tests/tree-sitter/test-files/malformed-signature.js +38 -0
  434. package/ts_build/tests/tree-sitter/test-files/malformed-signature.js.map +1 -0
  435. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.d.ts +10 -0
  436. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js +38 -0
  437. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js.map +1 -0
  438. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.d.ts +8 -0
  439. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js +38 -0
  440. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js.map +1 -0
  441. package/ts_build/tests/tree-sitter/test-files/partially-broken.d.ts +6 -0
  442. package/ts_build/tests/tree-sitter/test-files/partially-broken.js +20 -0
  443. package/ts_build/tests/tree-sitter/test-files/partially-broken.js.map +1 -0
  444. package/ts_build/tests/tree-sitter/test-files/specific-errors.d.ts +7 -0
  445. package/ts_build/tests/tree-sitter/test-files/specific-errors.js +14 -0
  446. package/ts_build/tests/tree-sitter/test-files/specific-errors.js.map +1 -0
  447. package/ts_build/tests/tree-sitter/test-files/unclosed-string.d.ts +8 -0
  448. package/ts_build/tests/tree-sitter/test-files/unclosed-string.js +38 -0
  449. package/ts_build/tests/tree-sitter/test-files/unclosed-string.js.map +1 -0
  450. package/ts_build/tests/tree-sitter/tree-sitter.test.d.ts +1 -0
  451. package/ts_build/tests/tree-sitter/tree-sitter.test.js +185 -0
  452. package/ts_build/tests/tree-sitter/tree-sitter.test.js.map +1 -0
  453. package/tsconfig.json +2 -1
  454. package/tests/languagePlugin.test.ts +0 -74
  455. /package/src/chat/modules/{index.js → index.ts} +0 -0
  456. /package/tests/{integration → manual/file-edits}/patching/input.txt +0 -0
  457. /package/tests/{integration → manual/file-edits}/patching/output.txt +0 -0
  458. /package/tests/{integration → manual/file-edits}/patching/patch.txt +0 -0
  459. /package/tests/{integration → manual/file-edits}/patching/unseen.txt +0 -0
@@ -41,7 +41,7 @@ export class ToolResponseCache {
41
41
  /**
42
42
  * Recursively searches for JSON strings within an object and parses them
43
43
  */
44
- private parseNestedJsonStrings(obj: any): any {
44
+ public parseNestedJsonStrings(obj: any): any {
45
45
  if (typeof obj === "string") {
46
46
  const parsed = this.tryParseJson(obj);
47
47
  if (parsed) {
@@ -68,7 +68,7 @@ export class ToolResponseCache {
68
68
  /**
69
69
  * Stores a tool response for later manipulation
70
70
  */
71
- private storeToolResponse(content: string, toolCallId: string): void {
71
+ public storeToolResponse(content: string, toolCallId: string): void {
72
72
  // Always store the original content for later JQ manipulation
73
73
  this.storage[toolCallId] = content;
74
74
 
@@ -130,17 +130,26 @@ export class ToolResponseCache {
130
130
  }
131
131
 
132
132
  try {
133
- // Parse the data as JSON (handles nested JSON strings)
134
- const parsedData = this.parseNestedJsonStrings(data);
133
+
134
+ // First parse the stored string as JSON, then handle nested JSON strings
135
+ const jsonData = this.tryParseJson(data);
136
+ if (!jsonData) {
137
+ return `Error: Tool response data is not valid JSON for toolCallId "${toolCallId}"`;
138
+ }
139
+ const parsedData = this.parseNestedJsonStrings(jsonData);
135
140
 
136
141
  // Execute JQ query
137
142
  const result = await jq.run(jqQuery, parsedData, { input: "json" });
138
143
 
139
- // Return the result as a string
144
+ // Handle the result based on its type
140
145
  if (typeof result === "string") {
141
146
  return result;
147
+ } else if (typeof result === "number" || typeof result === "boolean") {
148
+ return String(result);
149
+ } else if (result === null) {
150
+ return "null";
142
151
  } else {
143
- return JSON.stringify(result, null, 2);
152
+ return JSON.stringify(result);
144
153
  }
145
154
  } catch (error: any) {
146
155
  // If JQ fails, try to provide helpful error message
@@ -1,3 +1,6 @@
1
+ import * as path from "path";
2
+ import { globSync } from "glob";
3
+
1
4
  import {
2
5
  Config,
3
6
  Embeddable,
@@ -13,10 +16,8 @@ import {
13
16
  cosineSimilarity,
14
17
  } from "../utils";
15
18
  import { summarizeTexts, chunkText } from "../ai";
16
- import { Plugins } from "../plugins/plugins";
17
19
  import { Clients, GenericClient } from "../clients";
18
- import * as path from "path";
19
- import glob from "glob";
20
+ import { PluginService } from "..//plugins/plugins";
20
21
 
21
22
  export type CreateEmbeddingOptions = {
22
23
  provider?: string;
@@ -31,13 +32,21 @@ export type EmbedOptions = {
31
32
  minLength?: number;
32
33
  };
33
34
 
35
+ interface EmbeddingServiceContext {
36
+ config: Config;
37
+ embeddingClient?: GenericClient;
38
+ plugins: PluginService;
39
+ }
40
+
34
41
  export class EmbeddingService {
35
42
  private config: Config;
36
43
  private embeddingClient: GenericClient;
44
+ private plugins: PluginService;
37
45
 
38
- constructor(config: Config, embeddingClient: GenericClient) {
39
- this.config = config;
40
- this.embeddingClient = embeddingClient;
46
+ constructor(protected context: EmbeddingServiceContext) {
47
+ this.config = context.config;
48
+ this.embeddingClient = context.embeddingClient;
49
+ this.plugins = context.plugins;
41
50
  }
42
51
 
43
52
  setEmbeddingClient(client: GenericClient) {
@@ -102,7 +111,7 @@ export class EmbeddingService {
102
111
  }
103
112
 
104
113
  console.log("Embedding", source.input, "to", source.output);
105
- let files = await glob.sync(source.input, { ignore: ignorePattern });
114
+ let files = await globSync(source.input, { ignore: ignorePattern });
106
115
 
107
116
  if (source.kind && files.length === 0) {
108
117
  files = [source.input];
@@ -193,9 +202,9 @@ export class EmbeddingService {
193
202
  const contents = "";
194
203
  const ids = [];
195
204
 
196
- if (Plugins.isPlugin(kind)) {
205
+ if (this.plugins.isPlugin(kind)) {
197
206
  console.log("Embedding with plugin", kind);
198
- return Plugins.embed(kind, input);
207
+ return this.plugins.embed(kind, input);
199
208
  }
200
209
  switch (kind) {
201
210
  case "text":
@@ -1,11 +1,91 @@
1
1
  import { EventEmitter } from "events";
2
2
  import { IAgent } from "../agents/interface";
3
3
 
4
+ export interface EventHandler {
5
+ handler: (...args: any[]) => any;
6
+ }
7
+
4
8
  export class EventService extends EventEmitter {
9
+ private blockingHandlers: Map<string, EventHandler[]> = new Map();
10
+
5
11
  constructor() {
6
12
  super();
7
13
  }
8
14
 
15
+ /**
16
+ * Register an event handler as blocking or non-blocking
17
+ * @param event The event name
18
+ * @param handler The event handler function
19
+ * @param isBlocking Whether this handler should be blocking
20
+ */
21
+ onBlocking(event: string, handler: (...args: any[]) => any): void {
22
+ if (!this.blockingHandlers.has(event)) {
23
+ this.blockingHandlers.set(event, []);
24
+ }
25
+
26
+ this.blockingHandlers.get(event)!.push({ handler });
27
+ }
28
+
29
+ /**
30
+ * Emit a blocking event - if any blocking handler throws, execution stops
31
+ * @param event The event name
32
+ * @param args Arguments to pass to handlers
33
+ * @returns Promise that resolves with array of handler results when all handlers complete, or rejects if any blocking handler throws
34
+ */
35
+ async emitBlocking(event: string, ...args: any[]): Promise<any[]> {
36
+ const results: any[] = [];
37
+
38
+ const handlers = this.blockingHandlers.get(event) || [];
39
+
40
+ for (const { handler } of handlers) {
41
+ try {
42
+ const result = handler(...args);
43
+ if (result instanceof Promise) {
44
+ const awaitedResult = await result;
45
+ results.push(awaitedResult);
46
+ } else {
47
+ results.push(result);
48
+ }
49
+ } catch (error) {
50
+ // If this is a blocking handler and it throws, stop execution
51
+ throw error;
52
+ }
53
+ }
54
+
55
+ this.emit(event, ...args);
56
+ return results.filter((r) => Boolean(r));
57
+ }
58
+
59
+ /**
60
+ * Emit a non-blocking event - all handlers run, errors are logged but don't stop execution
61
+ * @param event The event name
62
+ * @param args Arguments to pass to handlers
63
+ * @returns Promise that resolves with array of handler results when all handlers complete
64
+ */
65
+ async emitNonBlocking(event: string, ...args: any[]): Promise<any[]> {
66
+ const handlers = this.blockingHandlers.get(event) || [];
67
+ const results: any[] = [];
68
+ for (const { handler } of handlers) {
69
+ try {
70
+ const result = handler(...args);
71
+ if (result instanceof Promise) {
72
+ const awaitedResult = await result;
73
+ results.push(awaitedResult);
74
+ } else {
75
+ results.push(result);
76
+ }
77
+ } catch (error) {
78
+ console.error(
79
+ `Non-blocking handler error for event '${event}':`,
80
+ error
81
+ );
82
+ }
83
+ }
84
+
85
+ this.emit(event, ...args);
86
+ return results.filter((r) => Boolean(r));
87
+ }
88
+
9
89
  registerAgent(agent: IAgent): void {
10
90
  this.emit("agents:register", { name: agent.name, agent });
11
91
  }
@@ -2,6 +2,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
2
2
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
3
  import Anthropic from "@anthropic-ai/sdk";
4
4
 
5
+ import fs from "fs";
5
6
  import { McpConfig } from "../types";
6
7
  import { Tool } from "../clients";
7
8
  import { getConfig } from "../config";
@@ -79,6 +80,10 @@ export class McpService {
79
80
  }
80
81
  if (mcp.url) {
81
82
  // TODO: also support refresh tokens
83
+ if (mcp.authorization_token_file) {
84
+ const token = fs.readFileSync(mcp.authorization_token_file, "utf-8");
85
+ mcp.authorization_token = token.trim();
86
+ }
82
87
  return new StreamableHTTPClientTransport(new URL(mcp.url), {
83
88
  requestInit: {
84
89
  headers: {
@@ -8,7 +8,8 @@ import {
8
8
  PutObjectCommandInput,
9
9
  } from "@aws-sdk/client-s3";
10
10
 
11
- import fs from "fs/promises";
11
+ import * as fs from "fs";
12
+ const fsPromises = fs.promises;
12
13
  import { createWriteStream } from "fs";
13
14
  import * as path from "path";
14
15
  import { pipeline } from "stream";
@@ -30,7 +31,7 @@ export class S3Service {
30
31
  bucketName: string,
31
32
  key: string
32
33
  ): Promise<void> {
33
- const fileContent = await fs.readFile(filePath);
34
+ const fileContent = await fsPromises.readFile(filePath);
34
35
 
35
36
  const params = {
36
37
  Bucket: bucketName,
@@ -80,7 +81,7 @@ export class S3Service {
80
81
  ): Promise<void> {
81
82
  try {
82
83
  const fileStream = createReadStream(filePath);
83
- const fileStats = await fs.stat(filePath);
84
+ const fileStats = await fsPromises.stat(filePath);
84
85
 
85
86
  const response = await axios.put(presignedUrl, fileStream, {
86
87
  headers: {
@@ -82,49 +82,30 @@ export class ToolsService {
82
82
  }
83
83
 
84
84
  getFunction(name: string) {
85
- // return this.functions[name] || allTools.addInternalTools(allTools)[name];
85
+ // Apply overrides and wrappers before returning (even if no base function exists)
86
+ if (this.functions[name] || this.originalFunctions[name]) {
87
+ this.applyOverridesAndWrappers(name);
88
+ } else {
89
+ // Check if there are overrides for this name even without a base function
90
+ const matchingOverride = this.findMatchingOverride(name);
91
+ if (matchingOverride) {
92
+ this.functions[name] = matchingOverride.override;
93
+ } else {
94
+ return undefined;
95
+ }
96
+ }
86
97
  return this.functions[name];
87
98
  }
88
99
 
89
100
  setFunction(name: string, func: (...args: any) => any) {
90
101
  // Store original function if not already stored
91
102
  if (!this.originalFunctions[name]) {
92
- this.originalFunctions[name] = func;
93
- }
94
-
95
- // Auto-bind function to this ToolsService instance
96
- const boundFunc = func.bind(this);
97
-
98
- // Check for overrides first
99
- const override = this.findMatchingOverride(name);
100
- if (override) {
101
- this.functions[name] = async (...args: any[]) => {
102
- const tool = this.getTool(name);
103
- return await override.override(args, tool);
104
- };
105
- return;
106
- }
107
-
108
- // Check for wrappers
109
- const wrappers = this.findMatchingWrappers(name);
110
- if (wrappers.length > 0) {
111
- let wrappedFunction = boundFunc;
112
-
113
- // Apply wrappers in priority order
114
- for (const wrapperReg of wrappers) {
115
- const currentFunction = wrappedFunction;
116
- wrappedFunction = async (...args: any[]) => {
117
- const tool = this.getTool(name);
118
- return await wrapperReg.wrapper(currentFunction, args, tool);
119
- };
120
- }
121
-
122
- this.functions[name] = wrappedFunction;
123
- return;
103
+ this.originalFunctions[name] = func.bind(this);
124
104
  }
125
105
 
126
- // No overrides or wrappers, use bound function
127
- this.functions[name] = boundFunc;
106
+ // Set the function (bound) and apply any overrides/wrappers
107
+ this.functions[name] = func.bind(this);
108
+ this.applyOverridesAndWrappers(name);
128
109
  }
129
110
 
130
111
  setFunctions(names: string[], funcs: ((...args: any) => any)[]) {
@@ -167,12 +148,20 @@ export class ToolsService {
167
148
 
168
149
  async callTool(toolCall: ToolCall, enabledTools = this.getToolNames()) {
169
150
  const functionName = toolCall.function.name;
170
- const functionArgs =
171
- typeof toolCall.function.arguments === "string"
172
- ? JSON.parse(restoreEscapedNewLines(toolCall.function.arguments))
173
- : toolCall.function.arguments;
151
+ let functionArgs: any;
174
152
 
175
153
  try {
154
+ try {
155
+ functionArgs =
156
+ typeof toolCall.function.arguments === "string"
157
+ ? JSON.parse(restoreEscapedNewLines(toolCall.function.arguments))
158
+ : toolCall.function.arguments;
159
+ } catch (error) {
160
+ throw new Error(
161
+ `Invalid JSON in tool call arguments: ${error.message}`
162
+ );
163
+ }
164
+
176
165
  // Check if tool is enabled
177
166
  if (!enabledTools.includes(functionName)) {
178
167
  const options = enabledTools.join(", ");
@@ -204,20 +193,22 @@ export class ToolsService {
204
193
  ? Object.keys(properties).map((p) => functionArgs[p])
205
194
  : functionArgs;
206
195
 
207
- console.log(
208
- `Calling function ${functionName} with args:`,
209
- JSON.stringify(fnArgs, null, 2)
210
- );
211
-
212
196
  // Execute the function
213
- const functionResponse = await Promise.resolve(
214
- isPositional ? functionToCall(...fnArgs) : functionToCall(fnArgs)
215
- ).catch((e) => {
197
+ const rawResponse = isPositional
198
+ ? functionToCall.call(this, ...fnArgs)
199
+ : functionToCall.call(this, fnArgs);
200
+ const functionResponse = await Promise.resolve(rawResponse).catch((e) => {
216
201
  throw new Error("ERROR: " + e.message);
217
202
  });
218
203
 
219
204
  // Helper function to convert objects to JSON
220
205
  const toJsonIfObject = (arg: any) => {
206
+ if (arg === null) {
207
+ return "null";
208
+ }
209
+ if (arg === undefined) {
210
+ return "undefined";
211
+ }
221
212
  if (typeof arg === "object") {
222
213
  return JSON.stringify(arg, null, 2);
223
214
  }
@@ -228,14 +219,18 @@ export class ToolsService {
228
219
 
229
220
  // Handle special case for parallel tool use
230
221
  if (functionName === "multi_tool_use.parallel") {
231
- const args = fnArgs[0] as {
222
+ // Extract tool_calls array from arguments
223
+ const toolCallsArg = Array.isArray(fnArgs) ? fnArgs : [fnArgs];
224
+ const toolCalls = Array.isArray(toolCallsArg) ? toolCallsArg : [];
225
+
226
+ const calls = toolCalls as {
232
227
  recipient_name: string;
233
228
  parameters: any;
234
229
  }[];
235
230
 
236
- toolMessages = args.map((call, index) => {
231
+ toolMessages = calls.map((call, index) => {
237
232
  return {
238
- tool_call_id: toolCall.id + "_" + index,
233
+ tool_call_id: `call_parallel_${index}`,
239
234
  role: "tool",
240
235
  name: call.recipient_name.split(".").pop(),
241
236
  content: toJsonIfObject(functionResponse[index]) || "Done",
@@ -257,7 +252,7 @@ export class ToolsService {
257
252
  toolCallId: toolCall.id,
258
253
  functionName,
259
254
  functionArgs,
260
- functionResp: functionResponse,
255
+ functionResp: functionResponse || "Done",
261
256
  };
262
257
  } catch (error) {
263
258
  console.log(error.message);
@@ -288,6 +283,13 @@ export class ToolsService {
288
283
  ): void {
289
284
  this.overrides.push({ pattern, override, priority });
290
285
  this.overrides.sort((a, b) => b.priority - a.priority);
286
+
287
+ // Re-apply overrides to existing functions
288
+ for (const toolName of this.getToolNames()) {
289
+ if (this.functions[toolName]) {
290
+ this.applyOverridesAndWrappers(toolName);
291
+ }
292
+ }
291
293
  }
292
294
 
293
295
  registerWrapper(
@@ -296,27 +298,97 @@ export class ToolsService {
296
298
  priority: number = 0
297
299
  ): void {
298
300
  this.wrappers.push({ pattern, wrapper, priority });
301
+
302
+ // Sort wrappers by priority first
299
303
  this.wrappers.sort((a, b) => b.priority - a.priority);
304
+
305
+ // Re-apply wrappers to existing functions
306
+ for (const toolName of this.getToolNames()) {
307
+ if (this.functions[toolName]) {
308
+ this.applyOverridesAndWrappers(toolName);
309
+ }
310
+ }
300
311
  }
301
312
 
302
313
  removeOverride(pattern: string | RegExp): void {
303
314
  this.overrides = this.overrides.filter((reg) => reg.pattern !== pattern);
315
+ // Re-apply functions after removing override
316
+ for (const toolName of this.getToolNames()) {
317
+ if (this.originalFunctions[toolName]) {
318
+ this.setFunction(toolName, this.originalFunctions[toolName]);
319
+ }
320
+ }
304
321
  }
305
322
 
306
323
  removeWrapper(pattern: string | RegExp): void {
307
324
  this.wrappers = this.wrappers.filter((reg) => reg.pattern !== pattern);
325
+ // Re-apply functions after removing wrapper
326
+ for (const toolName of this.getToolNames()) {
327
+ if (this.originalFunctions[toolName]) {
328
+ this.setFunction(toolName, this.originalFunctions[toolName]);
329
+ }
330
+ }
331
+ }
332
+
333
+ private applyOverridesAndWrappers(name: string): void {
334
+ if (!this.originalFunctions[name]) {
335
+ // Store original function if not already stored
336
+ this.originalFunctions[name] = this.functions[name];
337
+ }
338
+
339
+ const originalFunc = this.originalFunctions[name];
340
+
341
+ // Check for overrides first
342
+ const matchingOverride = this.findMatchingOverride(name);
343
+ if (matchingOverride) {
344
+ // Create a wrapper function that calls the override with correct arguments
345
+ this.functions[name] = ((...args: any[]) => {
346
+ // Call the override function with originalArgs array and tool definition
347
+ const toolDefinition = this.getTool(name);
348
+ // Override functions expect (originalArgs: any[], originalTool: Tool)
349
+ return matchingOverride.override.call(this, args, toolDefinition);
350
+ }).bind(this);
351
+ return;
352
+ }
353
+
354
+ // Check for wrappers
355
+ const wrappers = this.findMatchingWrappers(name);
356
+ if (wrappers.length > 0) {
357
+ let wrappedFunction = originalFunc;
358
+
359
+ // Apply wrappers in priority order
360
+ for (const wrapperReg of wrappers) {
361
+ const innerFunc = wrappedFunction;
362
+ wrappedFunction = ((args: any) => {
363
+ const toolDefinition = this.getTool(name);
364
+ return wrapperReg.wrapper(innerFunc, args, toolDefinition);
365
+ }).bind(this);
366
+ }
367
+
368
+ this.functions[name] = wrappedFunction.bind(this);
369
+ } else {
370
+ // No wrappers, use current function (might be override or original)
371
+ this.functions[name] = originalFunc;
372
+ }
308
373
  }
309
374
 
310
375
  private findMatchingOverride(
311
376
  toolName: string
312
377
  ): ToolOverrideRegistration | null {
378
+ let bestMatch: ToolOverrideRegistration | null = null;
379
+ let highestPriority = -1;
380
+
313
381
  for (const registration of this.overrides) {
314
382
  const matcher = createPatternMatcher(registration.pattern);
315
383
  if (matcher.matches(toolName)) {
316
- return registration;
384
+ if (registration.priority > highestPriority) {
385
+ highestPriority = registration.priority;
386
+ bestMatch = registration;
387
+ }
317
388
  }
318
389
  }
319
- return null;
390
+
391
+ return bestMatch;
320
392
  }
321
393
 
322
394
  private findMatchingWrappers(toolName: string): ToolWrapperRegistration[] {
@@ -1,6 +1,5 @@
1
1
  import { DownloaderService } from "../plugins/downloader/downloader";
2
- import { Clients } from "../clients";
3
- import { Plugins } from "../plugins/plugins";
2
+ import { AIClient, Clients } from "../clients";
4
3
  import { AgentService } from "./AgentService";
5
4
  import { EventService } from "./EventService";
6
5
  import { FlagsService } from "./flags";
@@ -9,6 +8,7 @@ import { KnowhowSimpleClient } from "./KnowhowClient";
9
8
  import { McpService } from "./Mcp";
10
9
  import { S3Service } from "./S3";
11
10
  import { ToolsService } from "./Tools";
11
+ import { PluginService } from "../plugins/plugins";
12
12
 
13
13
  export * from "./AgentService";
14
14
  export * from "./EventService";
@@ -19,7 +19,6 @@ export * from "./Tools";
19
19
  export * as MCP from "./Mcp";
20
20
  export * from "./EmbeddingService";
21
21
  export { Clients } from "../clients";
22
- export { Plugins };
23
22
 
24
23
  let Singletons = {} as {
25
24
  Tools: ToolsService;
@@ -30,8 +29,8 @@ let Singletons = {} as {
30
29
  Mcp: McpService;
31
30
  AwsS3: S3Service;
32
31
  knowhowApiClient: KnowhowSimpleClient;
33
- Plugins: typeof Plugins;
34
- Clients: typeof Clients;
32
+ Plugins: PluginService;
33
+ Clients: AIClient;
35
34
  Downloader: DownloaderService;
36
35
  };
37
36
 
@@ -41,19 +40,25 @@ export const services = (): typeof Singletons => {
41
40
  const Events = new EventService();
42
41
  const Agents = new AgentService(Tools, Events);
43
42
  const Downloader = new DownloaderService(Clients);
44
- Singletons = {
45
- Tools,
43
+ const Plugins = new PluginService({
44
+ Agents,
46
45
  Events,
46
+ Tools,
47
+ Clients,
48
+ });
49
+
50
+ Singletons = {
47
51
  Agents,
52
+ AwsS3: new S3Service(),
53
+ Clients,
48
54
  Downloader,
49
-
55
+ Events,
50
56
  Flags: new FlagsService(),
51
57
  GitHub: new GitHubService(),
52
58
  Mcp: new McpService(),
53
- AwsS3: new S3Service(),
54
- knowhowApiClient: new KnowhowSimpleClient(process.env.KNOWHOW_API_URL),
55
59
  Plugins,
56
- Clients,
60
+ Tools,
61
+ knowhowApiClient: new KnowhowSimpleClient(process.env.KNOWHOW_API_URL),
57
62
  };
58
63
 
59
64
  Singletons.Tools.setContext({
@@ -34,9 +34,9 @@ export class StringPatternMatcher implements PatternMatcher {
34
34
  matches(toolName: string): boolean {
35
35
  // Convert glob pattern to regex
36
36
  const regexPattern = this.pattern
37
- .replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // Escape special regex chars
38
- .replace(/\\\*/g, ".*") // Convert * to .*
39
- .replace(/\\\?/g, "."); // Convert ? to .
37
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&") // Escape special regex chars except * and ?
38
+ .replace(/\*/g, ".*") // Convert * to .*
39
+ .replace(/\?/g, "."); // Convert ? to .
40
40
 
41
41
  const regex = new RegExp(`^${regexPattern}$`);
42
42
  return regex.test(toolName);
package/src/types.ts CHANGED
@@ -57,7 +57,7 @@ export type Config = {
57
57
  enabled?: boolean;
58
58
  installPath?: string;
59
59
  port?: number;
60
- logLevel?: 'debug' | 'info' | 'warning' | 'error';
60
+ logLevel?: "debug" | "info" | "warning" | "error";
61
61
  completionTimeout?: number;
62
62
  };
63
63
 
@@ -82,6 +82,7 @@ export type McpConfig = {
82
82
  env?: { [key: string]: string };
83
83
  params?: Partial<{ socket: WebSocket }>;
84
84
  authorization_token?: string;
85
+ authorization_token_file?: string;
85
86
  };
86
87
 
87
88
  export type ModelProvider = {
@@ -122,6 +123,7 @@ export interface IDatasource {
122
123
 
123
124
  export type Language = {
124
125
  [term: string]: {
126
+ events: string[];
125
127
  sources: IDatasource[];
126
128
  context?: string;
127
129
  };
@@ -137,6 +139,9 @@ export type ChatInteraction = {
137
139
  export const Models = {
138
140
  anthropic: {
139
141
  Opus4: "claude-opus-4-20250514",
142
+ Opus4_1: "claude-opus-4-1-20250805",
143
+ Sonnet4_5: "claude-sonnet-4-5-20250929",
144
+ Haiku4_5: "claude-haiku-4-5-20251001",
140
145
  Sonnet4: "claude-sonnet-4-20250514",
141
146
  Sonnet3_7: "claude-3-7-sonnet-20250219",
142
147
  Sonnet3_5: "claude-3-5-sonnet-20241022",
@@ -145,6 +150,7 @@ export const Models = {
145
150
  Haiku3: "claude-3-haiku-20240307",
146
151
  },
147
152
  xai: {
153
+ GrokCodeFast: "grok-code-fast-1",
148
154
  Grok4: "grok-4-0709",
149
155
  Grok3Beta: "grok-3-beta",
150
156
  Grok3MiniBeta: "grok-3-mini-beta",
@@ -248,4 +254,3 @@ export const GoogleImageModels = [
248
254
  export const GoogleVideoModels = [Models.google.Veo_2];
249
255
 
250
256
  export const GoogleEmbeddingModels = [EmbeddingModels.google.Gemini_Embedding];
251
-
package/src/worker.ts CHANGED
@@ -68,12 +68,25 @@ export async function worker() {
68
68
  });
69
69
 
70
70
  mcpServer.runWsServer(ws);
71
+
72
+ return { ws, mcpServer };
71
73
  }
72
74
 
73
75
  while (true) {
76
+ let connection: { ws: WebSocket; mcpServer: McpServerService } | null =
77
+ null;
78
+
74
79
  if (!connected) {
75
80
  console.log("Attempting to connect...");
76
- connectWebSocket();
81
+ connection = await connectWebSocket();
82
+ }
83
+ if (connection && connected) {
84
+ try {
85
+ await connection.ws.ping();
86
+ } catch (error) {
87
+ console.error("WebSocket ping failed:", error);
88
+ connected = false;
89
+ }
77
90
  }
78
91
  await wait(5000);
79
92
  }