@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
@@ -1,4 +1,5 @@
1
1
  import * as fs from "fs";
2
+ import { services, ToolsService } from "../../services";
2
3
 
3
4
  // Tool to write the full contents of a file
4
5
  export function writeFile(filePath: string, content: string): string {
@@ -16,12 +17,39 @@ export async function writeFileChunk(
16
17
  isContinuing: boolean,
17
18
  isDone: boolean
18
19
  ) {
20
+ // Get context from bound ToolsService
21
+ const toolService = (
22
+ this instanceof ToolsService ? this : services().Tools
23
+ ) as ToolsService;
24
+ const context = toolService.getContext();
25
+
19
26
  if (!filePath || content === undefined) {
20
27
  throw new Error(
21
28
  "File path and content are both required. Make sure you write small chunks of content, otherwise you may hit output limits."
22
29
  );
23
30
  }
24
31
 
32
+ // Read original content for event emission
33
+ let originalContent = "";
34
+ try {
35
+ if (fs.existsSync(filePath)) {
36
+ originalContent = fs.readFileSync(filePath, "utf8");
37
+ }
38
+ } catch (error) {
39
+ // If we can't read the original file, continue with empty string
40
+ originalContent = "";
41
+ }
42
+
43
+ // Emit pre-edit blocking event
44
+ if (context.Events) {
45
+ await context.Events.emitBlocking("file:pre-edit", {
46
+ filePath,
47
+ operation: isContinuing ? "append" : "write",
48
+ content,
49
+ originalContent,
50
+ });
51
+ }
52
+
25
53
  if (!isContinuing) {
26
54
  fs.writeFileSync(filePath, content);
27
55
  }
@@ -42,6 +70,33 @@ export async function writeFileChunk(
42
70
 
43
71
  if (isDone) {
44
72
  message = " File write complete. Use readFile to verify";
73
+
74
+ // Emit post-edit blocking event to get event results
75
+ let eventResults: any[] = [];
76
+ if (context.Events) {
77
+ // Read updated content for event emission
78
+ const updatedContent = fs.readFileSync(filePath, "utf8");
79
+
80
+ eventResults = await context.Events.emitBlocking("file:post-edit", {
81
+ filePath,
82
+ operation: "write",
83
+ content,
84
+ originalContent,
85
+ updatedContent,
86
+ });
87
+ }
88
+
89
+ // Format event results
90
+ let eventResultsText = "";
91
+ if (eventResults && eventResults.length > 0) {
92
+ if (eventResults.length > 0) {
93
+ eventResultsText =
94
+ "\n\nAdditional Information:\n" +
95
+ JSON.stringify(eventResults, null, 2);
96
+ }
97
+ }
98
+
99
+ message += eventResultsText;
45
100
  }
46
101
 
47
102
  return message;
@@ -364,11 +364,13 @@ export class YcmdServer {
364
364
  */
365
365
  private async waitForServerStart(): Promise<YcmdServerInfo> {
366
366
  return new Promise((resolve, reject) => {
367
+ let timedOut = false;
367
368
  const timeout = setTimeout(() => {
368
369
  console.log(
369
370
  "ycmd server startup timeout - server failed to start within 30 seconds"
370
371
  );
371
372
  reject(new Error("ycmd server failed to start within timeout"));
373
+ timedOut = true;
372
374
  }, 30000);
373
375
 
374
376
  const host = "127.0.0.1";
@@ -378,6 +380,10 @@ export class YcmdServer {
378
380
  // Check for server readiness
379
381
  const checkReady = async () => {
380
382
  try {
383
+ if (timedOut) {
384
+ return;
385
+ }
386
+
381
387
  const port = getPort();
382
388
  console.log(`Checking ycmd server health on port ${port}`);
383
389
 
@@ -450,18 +456,22 @@ export class YcmdServer {
450
456
  private setupExitHandler(): void {
451
457
  // Handle normal process exit
452
458
  process.on("exit", () => this.forceCleanup());
453
-
459
+
454
460
  // Handle Ctrl+C (SIGINT)
455
461
  process.on("SIGINT", () => {
456
- console.log("\nReceived SIGINT (Ctrl+C), shutting down ycmd server gracefully...");
462
+ console.log(
463
+ "\nReceived SIGINT (Ctrl+C), shutting down ycmd server gracefully..."
464
+ );
457
465
  this.gracefulShutdown().finally(() => {
458
466
  process.exit(0);
459
467
  });
460
468
  });
461
-
469
+
462
470
  // Handle SIGTERM (termination signal)
463
471
  process.on("SIGTERM", () => {
464
- console.log("\nReceived SIGTERM, shutting down ycmd server gracefully...");
472
+ console.log(
473
+ "\nReceived SIGTERM, shutting down ycmd server gracefully..."
474
+ );
465
475
  this.gracefulShutdown().finally(() => {
466
476
  process.exit(0);
467
477
  });
@@ -17,7 +17,7 @@ import { recordAudio, voiceToText } from "../microphone";
17
17
  import editor from "@inquirer/editor";
18
18
  import fs from "fs";
19
19
  import path from "path";
20
- import { Plugins } from "../plugins/plugins";
20
+ import { services } from "../services";
21
21
 
22
22
  export class CliChatService implements ChatService {
23
23
  private context: ChatContext;
@@ -44,6 +44,10 @@ export class CliChatService implements ChatService {
44
44
  this.loadInputHistory();
45
45
  }
46
46
 
47
+ getModuleByName(name: string) {
48
+ return this.modules.find((module) => module.name === "agent");
49
+ }
50
+
47
51
  /**
48
52
  * Load input history from disk for scrollback functionality
49
53
  */
@@ -239,6 +243,7 @@ export class CliChatService implements ChatService {
239
243
  plugins: string[] = [],
240
244
  chatHistory: ChatInteraction[] = []
241
245
  ) {
246
+ const { Plugins } = services();
242
247
  const pluginText = await Plugins.callMany(plugins, input);
243
248
  const historyMessage = `<PreviousChats>
244
249
  This information is provided as historical context and is likely not related to the current task:
@@ -20,6 +20,7 @@ import {
20
20
  } from "../../processors/index";
21
21
  import { TaskInfo, ChatSession } from "../types";
22
22
  import { agents } from "../../agents";
23
+ import { ToolCallEvent } from "src/agents/base/base";
23
24
 
24
25
  export class AgentModule extends BaseChatModule {
25
26
  name = "agent";
@@ -535,9 +536,9 @@ ${reason}
535
536
  messageId: session.knowhowMessageId,
536
537
  existingKnowhowTaskId: session.knowhowTaskId,
537
538
  chatHistory: [],
538
- run: true,
539
+ run: false, // Don't run yet, we need to set up event listeners first
539
540
  });
540
- await this.attachedAgentChatLoop(taskId, agent);
541
+ await this.attachedAgentChatLoop(taskId, agent, resumePrompt);
541
542
  } catch (error) {
542
543
  console.error(
543
544
  `Failed to resume session ${sessionId}:`,
@@ -549,11 +550,26 @@ ${reason}
549
550
  async handleInput(input: string, context: ChatContext): Promise<boolean> {
550
551
  // If in agent mode, start agent with the input as initial task (like original chat.ts)
551
552
  if (context.agentMode && context.selectedAgent) {
552
- const result = await this.startAgent(
553
+ // Create initial interaction for the chatHistory
554
+ const initialInteraction: ChatInteraction = {
555
+ input,
556
+ output: "", // Will be filled after agent completion
557
+ summaries: [],
558
+ lastThread: [],
559
+ };
560
+
561
+ const { result, finalOutput } = await this.startAgent(
553
562
  context.selectedAgent,
554
563
  input,
555
564
  context.chatHistory || []
556
565
  );
566
+
567
+ // Update the chatHistory with the completed interaction
568
+ if (result && finalOutput) {
569
+ initialInteraction.output = finalOutput;
570
+ context.chatHistory.push(initialInteraction);
571
+ }
572
+
557
573
  return result;
558
574
  }
559
575
  return false;
@@ -593,6 +609,17 @@ ${reason}
593
609
  let knowhowTaskId: string | undefined;
594
610
 
595
611
  try {
612
+ // Get context for plugins
613
+ const context = this.chatService?.getContext();
614
+ const plugins = context?.plugins || [];
615
+
616
+ // Format the prompt with plugins and chat history
617
+ const formattedPrompt = await this.chatService.formatChatInput(
618
+ input,
619
+ plugins,
620
+ chatHistory
621
+ );
622
+
596
623
  // Create task info object
597
624
  let taskInfo: TaskInfo = {
598
625
  taskId,
@@ -601,6 +628,7 @@ ${reason}
601
628
  agentName,
602
629
  agent,
603
630
  initialInput: input,
631
+ formattedPrompt,
604
632
  status: "running",
605
633
  startTime: Date.now(),
606
634
  totalCost: 0,
@@ -637,25 +665,28 @@ ${reason}
637
665
  }
638
666
 
639
667
  // Set up session update listener
640
- agent.agentEvents.on("threadUpdate", async (threadState) => {
641
- // Update task cost from agent's current total cost
642
- taskInfo.totalCost = agent.getTotalCostUsd();
643
- this.updateSession(taskId, threadState);
644
-
645
- // Update Knowhow chat task if created
646
- if (knowhowTaskId && options.messageId && baseUrl) {
647
- await client
648
- .updateChatTask(knowhowTaskId, {
649
- threads: agent.getThreads(),
650
- totalCostUsd: agent.getTotalCostUsd(),
651
- inProgress: true,
652
- })
653
- .catch((error) => {
654
- console.error(`❌ Failed to update Knowhow chat task:`, error);
655
- });
656
- console.log(`✅ Updated Knowhow chat task: ${knowhowTaskId}`);
668
+ agent.agentEvents.on(
669
+ agent.eventTypes.threadUpdate,
670
+ async (threadState) => {
671
+ // Update task cost from agent's current total cost
672
+ taskInfo.totalCost = agent.getTotalCostUsd();
673
+ this.updateSession(taskId, threadState);
674
+
675
+ // Update Knowhow chat task if created
676
+ if (knowhowTaskId && options.messageId && baseUrl) {
677
+ await client
678
+ .updateChatTask(knowhowTaskId, {
679
+ threads: agent.getThreads(),
680
+ totalCostUsd: agent.getTotalCostUsd(),
681
+ inProgress: true,
682
+ })
683
+ .catch((error) => {
684
+ console.error(`❌ Failed to update Knowhow chat task:`, error);
685
+ });
686
+ console.log(`✅ Updated Knowhow chat task: ${knowhowTaskId}`);
687
+ }
657
688
  }
658
- });
689
+ );
659
690
 
660
691
  console.log(
661
692
  Marked.parse(`**Starting ${agent.name} with task ID: ${taskId}...**`)
@@ -663,7 +694,7 @@ ${reason}
663
694
  console.log(Marked.parse(`**Task:** ${input}`));
664
695
 
665
696
  // Initialize new task
666
- await agent.newTask();
697
+ await agent.newTask(taskId);
667
698
 
668
699
  if (options.model) {
669
700
  console.log("Setting model:", options.model);
@@ -673,17 +704,6 @@ ${reason}
673
704
  ]);
674
705
  }
675
706
 
676
- // Get context for plugins
677
- const context = this.chatService?.getContext();
678
- const plugins = context?.plugins || [];
679
-
680
- // Format the prompt with plugins and chat history
681
- const formattedPrompt = await this.chatService.formatChatInput(
682
- input,
683
- plugins,
684
- chatHistory
685
- );
686
-
687
707
  // Set up message processors like in original startAgent
688
708
 
689
709
  agent.messageProcessor.setProcessors("pre_call", [
@@ -700,15 +720,33 @@ ${reason}
700
720
  ]);
701
721
 
702
722
  // Set up event listeners
723
+ if (!agent.agentEvents.listenerCount(agent.eventTypes.toolCall)) {
724
+ agent.agentEvents.on(
725
+ agent.eventTypes.toolCall,
726
+ (responseMsg: ToolCallEvent) => {
727
+ console.time(JSON.stringify(responseMsg.toolCall.function.name));
728
+ console.log(
729
+ ` 🔨 Tool: ${responseMsg.toolCall.function.name}\n Args: ${responseMsg.toolCall.function.arguments}\n`
730
+ );
731
+ }
732
+ );
733
+ }
703
734
  if (!agent.agentEvents.listenerCount(agent.eventTypes.toolUsed)) {
704
- agent.agentEvents.on(agent.eventTypes.toolUsed, (responseMsg) => {
705
- console.log(` 🔨 Tool used: ${JSON.stringify(responseMsg, null, 2)}`);
706
- });
735
+ agent.agentEvents.on(
736
+ agent.eventTypes.toolUsed,
737
+ (responseMsg: ToolCallEvent) => {
738
+ console.timeEnd(JSON.stringify(responseMsg.toolCall.function.name));
739
+ console.log(
740
+ ` 🔨 Tool Response:
741
+ ${JSON.stringify(responseMsg.functionResp, null, 2)}`
742
+ );
743
+ }
744
+ );
707
745
  }
708
746
 
709
747
  const taskCompleted = new Promise<string>((resolve) => {
710
748
  agent.agentEvents.once(agent.eventTypes.done, async (doneMsg) => {
711
- console.log("Agent has finished.");
749
+ console.log("Agent has completed the task.");
712
750
  done = true;
713
751
  output = doneMsg || "No response from the AI";
714
752
  // Update task info
@@ -767,7 +805,13 @@ ${reason}
767
805
  agent.call(formattedPrompt);
768
806
  }
769
807
 
770
- return { agent, taskId, formattedPrompt, taskCompleted };
808
+ return {
809
+ agent,
810
+ taskId,
811
+ formattedPrompt,
812
+ initialInput: input,
813
+ taskCompleted,
814
+ };
771
815
  } catch (error) {
772
816
  console.error("Agent setup failed:", error);
773
817
  this.taskRegistry.delete(taskId);
@@ -809,11 +853,11 @@ ${reason}
809
853
  .replace(/[^\w\s]/g, "")
810
854
  .split(/\s+/)
811
855
  .filter((word) => word.length > 2)
812
- .slice(0, 3);
856
+ .slice(0, 9);
813
857
 
814
858
  const wordPart = words.join("-") || "task";
815
- const timestamp = Date.now().toString().slice(-6);
816
- return `${wordPart}-${timestamp}`;
859
+ const epochSeconds = Math.floor(Date.now() / 1000);
860
+ return `${epochSeconds}-${wordPart}`;
817
861
  }
818
862
 
819
863
  /**
@@ -887,47 +931,67 @@ ${reason}
887
931
  selectedAgent: BaseAgent,
888
932
  initialInput: string,
889
933
  chatHistory: ChatInteraction[] = []
890
- ): Promise<boolean> {
934
+ ): Promise<{ result: boolean; finalOutput?: string }> {
891
935
  try {
892
- const { agent, taskId } = await this.setupAgent({
936
+ const { agent, taskId, formattedPrompt } = await this.setupAgent({
893
937
  agentName: selectedAgent.name,
894
938
  input: initialInput,
895
939
  chatHistory,
896
- run: true,
940
+ run: false, // Don't run yet, we need to set up event listeners first
897
941
  });
898
- return await this.attachedAgentChatLoop(taskId, agent);
942
+ const result = await this.attachedAgentChatLoop(
943
+ taskId,
944
+ agent,
945
+ formattedPrompt
946
+ );
947
+ return result;
899
948
  } catch (error) {
900
949
  console.error("Error starting agent:", error);
901
- return false;
950
+ return { result: false, finalOutput: "Error starting agent" };
902
951
  }
903
952
  }
904
953
 
905
- async attachedAgentChatLoop(taskId: string, agent: BaseAgent) {
954
+ async attachedAgentChatLoop(
955
+ taskId: string,
956
+ agent: BaseAgent,
957
+ initialInput?: string
958
+ ): Promise<{ result: boolean; finalOutput?: string }> {
906
959
  try {
907
960
  let done = false;
908
961
  let output = "Done";
962
+ let agentFinalOutput: string | undefined;
909
963
 
910
964
  // Define available commands
911
- const commands = ["pause", "unpause", "kill", "detach"];
965
+ const commands = ["/pause", "/unpause", "/kill", "/detach", "/done"];
912
966
  const history: string[] = [];
913
967
 
914
- let input =
915
- (await this.chatService?.getInput(
916
- `Enter command or message for ${agent.name}: `,
917
- commands
918
- )) || "";
919
-
920
- history.push(input);
921
-
968
+ // Set up the event listener BEFORE starting the agent to avoid race condition
922
969
  let finished = false;
923
970
  const donePromise = new Promise<string>((resolve) => {
924
971
  agent.agentEvents.once(agent.eventTypes.done, (doneMsg) => {
925
- console.log("Agent has completed the task.");
972
+ // Capture the agent's final output
973
+ agentFinalOutput = doneMsg || "No response from the AI";
926
974
  finished = true;
927
975
  resolve("done");
928
976
  });
929
977
  });
930
978
 
979
+ // Now start the agent if we have an initial input (this means we're starting, not just attaching)
980
+ if (initialInput) {
981
+ const taskInfo = this.taskRegistry.get(taskId);
982
+ agent.call(
983
+ taskInfo?.formattedPrompt || taskInfo?.initialInput || initialInput
984
+ );
985
+ }
986
+
987
+ let input =
988
+ (await this.chatService?.getInput(
989
+ `Enter command or message for ${agent.name}: `,
990
+ commands
991
+ )) || "";
992
+
993
+ history.push(input);
994
+
931
995
  while (!done) {
932
996
  switch (input) {
933
997
  case "":
@@ -936,26 +1000,26 @@ ${reason}
936
1000
  done = true;
937
1001
  }
938
1002
  break;
939
- case "done":
1003
+ case "/done":
940
1004
  output = "Exited agent interaction.";
941
1005
  done = true;
942
1006
  break;
943
- case "pause":
1007
+ case "/pause":
944
1008
  await agent.pause();
945
1009
  console.log("Agent paused.");
946
1010
  break;
947
- case "unpause":
1011
+ case "/unpause":
948
1012
  await agent.unpause();
949
1013
  console.log("Agent unpaused.");
950
1014
  break;
951
- case "kill":
1015
+ case "/kill":
952
1016
  await agent.kill();
953
1017
  console.log("Agent terminated.");
954
1018
  done = true;
955
1019
  break;
956
- case "detach":
1020
+ case "/detach":
957
1021
  console.log("Detached from agent");
958
- return true;
1022
+ return { result: true, finalOutput: agentFinalOutput };
959
1023
  default:
960
1024
  agent.addPendingUserMessage({
961
1025
  role: "user",
@@ -981,12 +1045,10 @@ ${reason}
981
1045
  finalTaskInfo.endTime = Date.now();
982
1046
  }
983
1047
  }
984
-
985
- return true;
1048
+ return { result: true, finalOutput: agentFinalOutput };
986
1049
  } catch (error) {
987
1050
  console.error("Agent execution failed:", error);
988
- this.taskRegistry.delete(taskId);
989
- return false;
1051
+ return { result: false, finalOutput: "Error during agent execution" };
990
1052
  }
991
1053
  }
992
1054
  }
@@ -7,7 +7,6 @@ import { ChatCommand, ChatMode, ChatContext } from "../types";
7
7
  import { ChatInteraction } from "../../types";
8
8
  import { Models } from "../../ai";
9
9
  import { services } from "../../services/index";
10
- import { Plugins } from "../../plugins/plugins";
11
10
  import { Marked } from "../../utils/index";
12
11
 
13
12
  export class AskModule extends BaseChatModule {
@@ -167,13 +167,13 @@ export class SetupModule extends BaseChatModule {
167
167
  ) {
168
168
  // Launch Setup agent to guide user through configuration
169
169
  if (this.agentModule) {
170
+ const initialInput = "Help me set up my Knowhow configuration with the missing features and optimize my setup.";
170
171
  const { taskId, agent } = await this.agentModule.setupAgent({
171
172
  agentName: "Setup",
172
- run: true,
173
- input:
174
- "Help me set up my Knowhow configuration with the missing features and optimize my setup.",
173
+ run: false,
174
+ input: initialInput,
175
175
  });
176
- await this.agentModule.attachedAgentChatLoop(taskId, agent);
176
+ await this.agentModule.attachedAgentChatLoop(taskId, agent, initialInput);
177
177
  }
178
178
  }
179
179
  } else {
@@ -3,6 +3,7 @@ import { CliChatService } from "../CliChatService";
3
3
  import { ChatCommand, ChatMode, ChatContext } from "../types";
4
4
  import { ask } from "../../utils";
5
5
  import { services } from "../../services";
6
+ import { Models } from "../../types";
6
7
 
7
8
  export class SystemModule extends BaseChatModule {
8
9
  name = "system";
@@ -56,8 +57,18 @@ export class SystemModule extends BaseChatModule {
56
57
  currentModel: selectedModel,
57
58
  currentProvider,
58
59
  });
59
-
60
60
  console.log(`Model set to: ${selectedModel}`);
61
+
62
+ // Update currently active agent if any
63
+ if (context?.selectedAgent) {
64
+ console.log(
65
+ `Updating active agent ${context.currentAgent} model to: ${selectedModel}`
66
+ );
67
+ context?.selectedAgent?.updatePreferences({
68
+ model: selectedModel,
69
+ provider: currentProvider as any,
70
+ });
71
+ }
61
72
  }
62
73
 
63
74
  async handleProviderCommand(args: string[]): Promise<void> {
@@ -77,10 +88,10 @@ export class SystemModule extends BaseChatModule {
77
88
 
78
89
  // Get default model for new provider
79
90
  const ChatModelDefaults = {
80
- openai: "gpt-4o",
81
- anthropic: "claude-3-5-sonnet-20241022",
82
- google: "gemini-2.0-flash-exp",
83
- xai: "grok-beta",
91
+ openai: Models.openai.GPT_5,
92
+ anthropic: Models.anthropic.Sonnet4,
93
+ google: Models.google.Gemini_25_Flash_Preview,
94
+ xai: Models.xai.GrokCodeFast,
84
95
  };
85
96
 
86
97
  const newModel =
@@ -95,6 +106,18 @@ export class SystemModule extends BaseChatModule {
95
106
  console.log(
96
107
  `Provider set to: ${selectedProvider}, Model set to: ${newModel}`
97
108
  );
109
+
110
+ // Update currently active agent if any
111
+ if (context?.selectedAgent) {
112
+ console.log(
113
+ `Updating active agent ${context.currentAgent} provider to: ${selectedProvider} and model to: ${newModel}`
114
+ );
115
+
116
+ context?.selectedAgent?.updatePreferences({
117
+ model: newModel,
118
+ provider: selectedProvider as any,
119
+ });
120
+ }
98
121
  }
99
122
 
100
123
  async handleDebugCommand(args: string[]): Promise<void> {
package/src/chat/types.ts CHANGED
@@ -14,6 +14,7 @@ export interface ChatContext {
14
14
  currentModel?: string;
15
15
  currentProvider?: string;
16
16
  inputMethod?: InputMethod;
17
+ selectedAgent?: BaseAgent;
17
18
  [key: string]: any;
18
19
  }
19
20
 
@@ -68,6 +69,7 @@ export interface TaskInfo {
68
69
  agentName: string;
69
70
  agent: BaseAgent;
70
71
  initialInput: string;
72
+ formattedPrompt: string;
71
73
  status: "running" | "paused" | "completed" | "failed";
72
74
  startTime: number;
73
75
  endTime?: number;
package/src/chat-old.ts CHANGED
@@ -10,9 +10,8 @@ import {
10
10
  } from "./types";
11
11
  import { Marked } from "./utils";
12
12
  import { ask } from "./utils";
13
- import { Plugins } from "./plugins/plugins";
13
+ import { services } from "./services";
14
14
  import { queryEmbedding, getConfiguredEmbeddingMap } from "./embeddings";
15
- import { services } from "./services/";
16
15
  import { FlagsService } from "./services/flags";
17
16
  import { IAgent } from "./agents/interface";
18
17
  import { Message } from "./clients";
@@ -165,6 +164,7 @@ export async function formatChatInput(
165
164
  plugins: string[] = [],
166
165
  chatHistory: ChatInteraction[] = []
167
166
  ) {
167
+ const { Plugins } = services();
168
168
  const pluginText = await Plugins.callMany(plugins, input);
169
169
  const historyMessage = `<PreviousChats>
170
170
  This information is provided as historical context and is likely not related to the current task:
@@ -151,6 +151,15 @@ export class GenericAnthropicClient implements GenericClient {
151
151
  }
152
152
  }
153
153
 
154
+ tryParse(str: string): any {
155
+ try {
156
+ return JSON.parse(str);
157
+ } catch (e) {
158
+ console.error("Invalid JSON from tool call", str);
159
+ return {};
160
+ }
161
+ }
162
+
154
163
  transformMessages(messages: Message[]): MessageParam[] {
155
164
  const toolCalls = messages.flatMap((msg) => msg.tool_calls || []);
156
165
  const claudeMessages: MessageParam[] = messages
@@ -173,7 +182,7 @@ export class GenericAnthropicClient implements GenericClient {
173
182
  type: "tool_use",
174
183
  id: msg.tool_call_id,
175
184
  name: toolCall.function.name,
176
- input: JSON.parse(toolCall.function.arguments),
185
+ input: this.tryParse(toolCall.function.arguments),
177
186
  },
178
187
  ],
179
188
  });
@@ -332,6 +341,18 @@ export class GenericAnthropicClient implements GenericClient {
332
341
  cache_hit: 0.3,
333
342
  output: 15.0,
334
343
  },
344
+ [Models.anthropic.Sonnet4_5]: {
345
+ input: 3.0,
346
+ cache_write: 3.75,
347
+ cache_hit: 0.3,
348
+ output: 15.0,
349
+ },
350
+ [Models.anthropic.Haiku4_5]: {
351
+ input: 1,
352
+ cache_write: 1.25,
353
+ cache_hit: 0.1,
354
+ output: 5,
355
+ },
335
356
  [Models.anthropic.Sonnet3_7]: {
336
357
  input: 3.0,
337
358
  cache_write: 3.75,
@@ -29,7 +29,7 @@ export class GenericOpenAiClient implements GenericClient {
29
29
  this.apiKey = apiKey;
30
30
  this.client = new OpenAI({
31
31
  apiKey,
32
- ...(config.openaiBaseUrl && { baseURL: config.openaiBaseUrl }),
32
+ ...(config?.openaiBaseUrl && { baseURL: config.openaiBaseUrl }),
33
33
  });
34
34
  }
35
35