@tyvm/knowhow 0.0.47 → 0.0.49

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 +39 -25
  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 +129 -67
  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 +8 -8
  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 +60 -70
  71. package/src/processors/TokenCompressor.ts +15 -14
  72. package/src/processors/ToolResponseCache.ts +20 -14
  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 +485 -0
  93. package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
  94. package/tests/processors/TokenCompressor.test.ts +390 -0
  95. package/tests/processors/ToolResponseCache.test.ts +736 -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 +7 -2
  120. package/ts_build/src/agents/base/base.js +27 -21
  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 +62 -32
  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 +9 -13
  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 +45 -47
  309. package/ts_build/src/processors/CustomVariables.js.map +1 -1
  310. package/ts_build/src/processors/TokenCompressor.js +10 -13
  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 +18 -10
  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 +354 -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 +299 -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 +550 -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
@@ -101,18 +101,24 @@ export class CustomVariables {
101
101
  */
102
102
  private listVariables(): string {
103
103
  const variableNames = Object.keys(this.variables);
104
-
104
+
105
105
  if (variableNames.length === 0) {
106
106
  return "No variables are currently stored.";
107
107
  }
108
108
 
109
- const variableList = variableNames.map(name => {
110
- const value = this.variables[name];
111
- const preview = typeof value === "string"
112
- ? (value.length > 50 ? value.substring(0, 50) + "..." : value)
113
- : JSON.stringify(value).substring(0, 50) + (JSON.stringify(value).length > 50 ? "..." : "");
114
- return `- ${name}: ${preview}`;
115
- }).join("\n");
109
+ const variableList = variableNames
110
+ .map((name) => {
111
+ const value = this.variables[name];
112
+ const preview =
113
+ typeof value === "string"
114
+ ? value.length > 50
115
+ ? value.substring(0, 50) + "..."
116
+ : value
117
+ : JSON.stringify(value).substring(0, 50) +
118
+ (JSON.stringify(value).length > 50 ? "..." : "");
119
+ return `- ${name}: ${preview}`;
120
+ })
121
+ .join("\n");
116
122
 
117
123
  return `Currently stored variables (${variableNames.length}):\n${variableList}`;
118
124
  }
@@ -136,14 +142,28 @@ export class CustomVariables {
136
142
  }
137
143
 
138
144
  /**
139
- * Recursively processes a value to substitute {{variable}} patterns
145
+ * Processes a value to substitute {{variableName}} patterns
140
146
  */
141
147
  private substituteVariables(
142
148
  value: any,
143
149
  processedVars: Set<string> = new Set()
144
150
  ): any {
145
151
  if (typeof value === "string") {
146
- // Find all {{variable}} patterns
152
+ // Check if ALL variables are undefined - if so, return just the error message for the first one
153
+ const variableMatches = value.match(/\{\{([a-zA-Z0-9_]+)\}\}/g);
154
+ if (variableMatches) {
155
+ const allUndefined = variableMatches.every((match) => {
156
+ const varName = match.replace(/[{}]/g, "");
157
+ return !(varName in this.variables);
158
+ });
159
+
160
+ if (allUndefined && variableMatches.length > 0) {
161
+ const firstUndefinedVar = variableMatches[0].replace(/[{}]/g, "");
162
+ return `{{ERROR: Variable "${firstUndefinedVar}" is not defined}}`;
163
+ }
164
+ }
165
+
166
+ // Otherwise, proceed with partial substitution
147
167
  return value.replace(/\{\{([a-zA-Z0-9_]+)\}\}/g, (match, varName) => {
148
168
  // Prevent infinite recursion
149
169
  if (processedVars.has(varName)) {
@@ -156,11 +176,9 @@ export class CustomVariables {
156
176
 
157
177
  const varValue = this.variables[varName];
158
178
 
159
- // If the variable value is a string, recursively process it
179
+ // For nested variables, return the raw value without further processing
160
180
  if (typeof varValue === "string") {
161
- const newProcessedVars = new Set(processedVars);
162
- newProcessedVars.add(varName);
163
- return this.substituteVariables(varValue, newProcessedVars);
181
+ return varValue;
164
182
  }
165
183
 
166
184
  // For non-string values, convert to JSON
@@ -239,62 +257,34 @@ export class CustomVariables {
239
257
  */
240
258
  private registerTools(toolsService: ToolsService): void {
241
259
  // Register setVariable tool
242
- if (!toolsService.getTool(this.setVariableToolName)) {
243
- toolsService.addTool(setVariableToolDefinition);
244
- toolsService.addFunctions({
245
- [this.setVariableToolName]: (name: string, contents: any) => {
246
- return this.setVariable(name, contents);
247
- },
248
- });
249
- }
250
-
251
- // Register getVariable tool
252
- if (!toolsService.getTool(this.getVariableToolName)) {
253
- toolsService.addTool(getVariableToolDefinition);
254
- toolsService.addFunctions({
255
- [this.getVariableToolName]: (varName: string) => {
256
- return this.getVariable(varName);
257
- },
258
- });
259
- }
260
-
261
- // Register storeToolCallToVariable tool
262
- if (!toolsService.getTool(this.storeToolCallToolName)) {
263
- toolsService.addTool(storeToolCallToVariableDefinition);
264
- toolsService.addFunctions({
265
- [this.storeToolCallToolName]: async (
266
- varName: string,
267
- toolName: string,
268
- toolArgs: string
269
- ) => {
270
- return await this.storeToolCallToVariable(
271
- varName,
272
- toolName,
273
- toolArgs
274
- );
275
- },
276
- });
277
- }
278
-
279
- // Register listVariables tool
280
- if (!toolsService.getTool(this.listVariablesToolName)) {
281
- toolsService.addTool(listVariablesToolDefinition);
282
- toolsService.addFunctions({
283
- [this.listVariablesToolName]: () => {
284
- return this.listVariables();
285
- },
286
- });
287
- }
288
-
289
- // Register deleteVariable tool
290
- if (!toolsService.getTool(this.deleteVariableToolName)) {
291
- toolsService.addTool(deleteVariableToolDefinition);
292
- toolsService.addFunctions({
293
- [this.deleteVariableToolName]: (varName: string) => {
294
- return this.deleteVariable(varName);
295
- },
296
- });
297
- }
260
+ toolsService.addTools([
261
+ setVariableToolDefinition,
262
+ getVariableToolDefinition,
263
+ storeToolCallToVariableDefinition,
264
+ listVariablesToolDefinition,
265
+ deleteVariableToolDefinition,
266
+ ]);
267
+ toolsService.addFunctions({
268
+ [this.setVariableToolName]: (name: string, contents: any) => {
269
+ return this.setVariable(name, contents);
270
+ },
271
+ [this.getVariableToolName]: (varName: string) => {
272
+ return this.getVariable(varName);
273
+ },
274
+ [this.storeToolCallToolName]: async (
275
+ varName: string,
276
+ toolName: string,
277
+ toolArgs: string
278
+ ) => {
279
+ return await this.storeToolCallToVariable(varName, toolName, toolArgs);
280
+ },
281
+ [this.listVariablesToolName]: () => {
282
+ return this.listVariables();
283
+ },
284
+ [this.deleteVariableToolName]: (varName: string) => {
285
+ return this.deleteVariable(varName);
286
+ },
287
+ });
298
288
  }
299
289
 
300
290
  /**
@@ -54,10 +54,6 @@ export class TokenCompressor {
54
54
  * Compresses a string into chunks from the end, creating a chain of references
55
55
  */
56
56
  public compressStringInChunks(content: string, path: string = ""): string {
57
- if (path === "" && this.estimateTokens(content) <= this.maxTokens) {
58
- return content;
59
- }
60
-
61
57
  if (content.length <= this.characterLimit) {
62
58
  return content;
63
59
  }
@@ -80,10 +76,14 @@ export class TokenCompressor {
80
76
  }
81
77
 
82
78
  // Store chunks and create chain of references
83
- for (let i = chunks.length - 1; i >= 0; i--) {
79
+ // First, generate all keys
80
+ for (let i = 0; i < chunks.length; i++) {
84
81
  const key = this.generateKey();
85
- chunkKeys.unshift(key);
82
+ chunkKeys.push(key);
83
+ }
86
84
 
85
+ // Then store chunks with proper linking
86
+ for (let i = 0; i < chunks.length; i++) {
87
87
  let chunkContent = chunks[i];
88
88
 
89
89
  // Add reference to next chunk if it exists
@@ -92,7 +92,7 @@ export class TokenCompressor {
92
92
  chunkContent += `\n\n[NEXT_CHUNK_KEY: ${nextKey}]`;
93
93
  }
94
94
 
95
- this.storeString(key, chunkContent);
95
+ this.storeString(chunkKeys[i], chunkContent);
96
96
  }
97
97
 
98
98
  // Return reference to the first chunk
@@ -114,11 +114,12 @@ export class TokenCompressor {
114
114
  public compressContent(content: string, path: string = ""): string {
115
115
  const tokens = this.estimateTokens(content);
116
116
 
117
- if (path === "" && tokens <= this.maxTokens) {
118
- return content;
119
- }
117
+ // For nested properties (path !== ""), use maxTokens to avoid recompressing stored data
118
+ // For top-level content (path === ""), use compressionThreshold to determine compression
119
+ const thresholdToUse =
120
+ path === "" ? this.compressionThreshold : this.maxTokens;
120
121
 
121
- if (tokens <= this.compressionThreshold) {
122
+ if (tokens <= thresholdToUse) {
122
123
  return content;
123
124
  }
124
125
 
@@ -239,7 +240,7 @@ export class TokenCompressor {
239
240
 
240
241
  // If not JSON or compression wasn't effective, handle as regular string
241
242
  const tokens = this.estimateTokens(obj);
242
- if (tokens > this.characterLimit * 4) {
243
+ if (tokens > this.compressionThreshold) {
243
244
  const key = this.generateKey();
244
245
  this.storeString(key, obj);
245
246
 
@@ -320,8 +321,8 @@ export class TokenCompressor {
320
321
  }
321
322
 
322
323
  registerTool(toolsService?: ToolsService): void {
323
- if (toolsService && !toolsService.getTool(this.toolName)) {
324
- toolsService.addTool(expandTokensDefinition);
324
+ if (toolsService) {
325
+ toolsService.addTools([expandTokensDefinition]);
325
326
  toolsService.addFunctions({
326
327
  [this.toolName]: (key: string) => {
327
328
  const data = this.retrieveString(key);
@@ -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,25 @@ 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
+ // First parse the stored string as JSON, then handle nested JSON strings
134
+ const jsonData = this.tryParseJson(data);
135
+ if (!jsonData) {
136
+ return `Error: Tool response data is not valid JSON for toolCallId "${toolCallId}"`;
137
+ }
138
+ const parsedData = this.parseNestedJsonStrings(jsonData);
135
139
 
136
140
  // Execute JQ query
137
141
  const result = await jq.run(jqQuery, parsedData, { input: "json" });
138
142
 
139
- // Return the result as a string
143
+ // Handle the result based on its type
140
144
  if (typeof result === "string") {
141
145
  return result;
146
+ } else if (typeof result === "number" || typeof result === "boolean") {
147
+ return String(result);
148
+ } else if (result === null) {
149
+ return "null";
142
150
  } else {
143
- return JSON.stringify(result, null, 2);
151
+ return JSON.stringify(result);
144
152
  }
145
153
  } catch (error: any) {
146
154
  // If JQ fails, try to provide helpful error message
@@ -198,14 +206,12 @@ export class ToolResponseCache {
198
206
  * Registers the jqToolResponse tool with the ToolsService
199
207
  */
200
208
  registerTool(toolsService: ToolsService): void {
201
- if (!toolsService.getTool(this.toolName)) {
202
- toolsService.addTool(jqToolResponseDefinition);
203
- toolsService.addFunctions({
204
- [this.toolName]: async (toolCallId: string, jqQuery: string) => {
205
- return await this.queryToolResponse(toolCallId, jqQuery);
206
- },
207
- });
208
- }
209
+ toolsService.addTools([jqToolResponseDefinition]);
210
+ toolsService.addFunctions({
211
+ [this.toolName]: async (toolCallId: string, jqQuery: string) => {
212
+ return await this.queryToolResponse(toolCallId, jqQuery);
213
+ },
214
+ });
209
215
  }
210
216
  }
211
217
 
@@ -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: {