@tyvm/knowhow 0.0.46 → 0.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (461) hide show
  1. package/benchmarks/results/27b0a06/2025-09-27/xai/xai-grok-code-fast-1.json +2909 -0
  2. package/benchmarks/results/4057aed/2025-08-14/anthropic/anthropic-claude-sonnet-4-20250514.json +1671 -0
  3. package/jest.config.js +2 -2
  4. package/package.json +8 -3
  5. package/src/agents/base/base.ts +30 -24
  6. package/src/agents/patcher/patcher.ts +26 -5
  7. package/src/agents/tools/agentCall.ts +4 -2
  8. package/src/agents/tools/aiClient.ts +3 -11
  9. package/src/agents/tools/ast/astAppendNode.ts +90 -0
  10. package/src/agents/tools/ast/astDeleteNode.ts +88 -0
  11. package/src/agents/tools/ast/astEditNode.ts +95 -0
  12. package/src/agents/tools/ast/astGetPathForLine.ts +73 -0
  13. package/src/agents/tools/ast/astListPaths.ts +66 -0
  14. package/src/agents/tools/ast/index.ts +7 -0
  15. package/src/agents/tools/callPlugin.ts +8 -2
  16. package/src/agents/tools/embeddingSearch.ts +2 -1
  17. package/src/agents/tools/execCommand.ts +239 -94
  18. package/src/agents/tools/fileSearch.ts +15 -17
  19. package/src/agents/tools/index.ts +1 -0
  20. package/src/agents/tools/language/definitions.ts +10 -2
  21. package/src/agents/tools/language/index.ts +3 -2
  22. package/src/agents/tools/lintFile.ts +4 -2
  23. package/src/agents/tools/list.ts +203 -62
  24. package/src/agents/tools/patch.ts +48 -14
  25. package/src/agents/tools/readBlocks.ts +34 -0
  26. package/src/agents/tools/readFile.ts +23 -0
  27. package/src/agents/tools/stringReplace.ts +33 -9
  28. package/src/agents/tools/writeFile.ts +55 -0
  29. package/src/agents/tools/ycmd/server.ts +14 -4
  30. package/src/chat/CliChatService.ts +6 -1
  31. package/src/chat/modules/AgentModule.ts +107 -64
  32. package/src/chat/modules/AskModule.ts +0 -1
  33. package/src/chat/modules/SetupModule.ts +4 -4
  34. package/src/chat/modules/SystemModule.ts +28 -5
  35. package/src/chat/types.ts +2 -0
  36. package/src/chat-old.ts +2 -2
  37. package/src/clients/anthropic.ts +22 -1
  38. package/src/clients/openai.ts +1 -1
  39. package/src/clients/types.ts +1 -1
  40. package/src/clients/xai.ts +15 -5
  41. package/src/config.ts +17 -5
  42. package/src/dataset/diffs/generate.ts +2 -2
  43. package/src/dataset/diffs/jsonl.ts +0 -1
  44. package/src/embeddings.ts +6 -4
  45. package/src/index.ts +11 -5
  46. package/src/plugins/GitPlugin.ts +530 -0
  47. package/src/plugins/LinterPlugin.ts +89 -0
  48. package/src/plugins/PluginBase.ts +4 -2
  49. package/src/plugins/asana.ts +4 -2
  50. package/src/plugins/downloader/plugin.ts +5 -2
  51. package/src/plugins/embedding.ts +24 -4
  52. package/src/plugins/figma.ts +7 -3
  53. package/src/plugins/github.ts +4 -2
  54. package/src/plugins/jira.ts +4 -2
  55. package/src/plugins/language.ts +134 -27
  56. package/src/plugins/linear.ts +4 -2
  57. package/src/plugins/notion.ts +4 -2
  58. package/src/plugins/plugins.ts +27 -16
  59. package/src/plugins/tree-sitter/editor.ts +369 -0
  60. package/src/plugins/tree-sitter/lang-packs/index.ts +23 -0
  61. package/src/plugins/tree-sitter/lang-packs/java.ts +59 -0
  62. package/src/plugins/tree-sitter/lang-packs/javascript.ts +57 -0
  63. package/src/plugins/tree-sitter/lang-packs/python.ts +45 -0
  64. package/src/plugins/tree-sitter/lang-packs/types.ts +79 -0
  65. package/src/plugins/tree-sitter/lang-packs/typescript.ts +49 -0
  66. package/src/plugins/tree-sitter/parser.ts +444 -0
  67. package/src/plugins/tree-sitter/simple-paths.ts +467 -0
  68. package/src/plugins/types.ts +11 -0
  69. package/src/plugins/url.ts +5 -3
  70. package/src/plugins/vim.ts +8 -5
  71. package/src/processors/CustomVariables.ts +19 -7
  72. package/src/processors/TokenCompressor.ts +13 -13
  73. package/src/processors/ToolResponseCache.ts +15 -6
  74. package/src/services/EmbeddingService.ts +18 -9
  75. package/src/services/EventService.ts +80 -0
  76. package/src/services/Mcp.ts +5 -0
  77. package/src/services/S3.ts +4 -3
  78. package/src/services/Tools.ts +125 -53
  79. package/src/services/index.ts +16 -11
  80. package/src/services/types.ts +3 -3
  81. package/src/types.ts +7 -2
  82. package/src/worker.ts +14 -1
  83. package/test-comprehensive.ts +31 -0
  84. package/tests/clients/AIClient.test.ts +490 -0
  85. package/tests/manual/agent-events/run-test.ts +203 -0
  86. package/tests/{integration → manual/file-edits}/figma.test.ts +1 -1
  87. package/tests/{integration → manual/file-edits}/fileblocks/readwrite.test.ts +7 -3
  88. package/tests/{integration → manual/file-edits}/patching.test.ts +11 -8
  89. package/tests/plugins/language/languagePlugin-content-triggers.test.ts +332 -0
  90. package/tests/plugins/language/languagePlugin-integration.test.ts +456 -0
  91. package/tests/plugins/language/languagePlugin.test.ts +363 -0
  92. package/tests/processors/Base64ImageDetector.test.ts +403 -0
  93. package/tests/processors/CustomVariables.test.ts +430 -0
  94. package/tests/processors/HarmonyToolProcessor.test.ts +490 -0
  95. package/tests/processors/TokenCompressor.test.ts +391 -0
  96. package/tests/processors/ToolResponseCache.test.ts +688 -0
  97. package/tests/services/Tools.test.ts +1339 -0
  98. package/tests/test.spec.ts +162 -117
  99. package/tests/tree-sitter/editor.test.ts +113 -0
  100. package/tests/tree-sitter/invalid.test.ts +299 -0
  101. package/tests/tree-sitter/paths/common-edits.test.ts +564 -0
  102. package/tests/tree-sitter/paths/debug-exact-position.test.ts +44 -0
  103. package/tests/tree-sitter/paths/debug-line-indexing.test.ts +49 -0
  104. package/tests/tree-sitter/paths/debug-paths.test.ts +90 -0
  105. package/tests/tree-sitter/paths/paths.test.ts +170 -0
  106. package/tests/tree-sitter/paths/simple-paths.test.ts +367 -0
  107. package/tests/tree-sitter/sample-after.ts +48 -0
  108. package/tests/tree-sitter/sample-before.ts +25 -0
  109. package/tests/tree-sitter/test-files/completely-broken.ts +7 -0
  110. package/tests/tree-sitter/test-files/duplicate-braces.ts +39 -0
  111. package/tests/tree-sitter/test-files/invalid-nesting.ts +39 -0
  112. package/tests/tree-sitter/test-files/malformed-signature.ts +39 -0
  113. package/tests/tree-sitter/test-files/mismatched-parens.ts +39 -0
  114. package/tests/tree-sitter/test-files/missing-semicolon.ts +39 -0
  115. package/tests/tree-sitter/test-files/partially-broken.ts +20 -0
  116. package/tests/tree-sitter/test-files/specific-errors.ts +14 -0
  117. package/tests/tree-sitter/test-files/unclosed-string.ts +39 -0
  118. package/tests/tree-sitter/tree-sitter.test.ts +251 -0
  119. package/ts_build/package.json +8 -3
  120. package/ts_build/src/agents/base/base.d.ts +2 -2
  121. package/ts_build/src/agents/base/base.js +24 -20
  122. package/ts_build/src/agents/base/base.js.map +1 -1
  123. package/ts_build/src/agents/patcher/patcher.js +26 -5
  124. package/ts_build/src/agents/patcher/patcher.js.map +1 -1
  125. package/ts_build/src/agents/tools/agentCall.js +2 -1
  126. package/ts_build/src/agents/tools/agentCall.js.map +1 -1
  127. package/ts_build/src/agents/tools/aiClient.d.ts +7 -8
  128. package/ts_build/src/agents/tools/aiClient.js.map +1 -1
  129. package/ts_build/src/agents/tools/ast/astAppendNode.d.ts +1 -0
  130. package/ts_build/src/agents/tools/ast/astAppendNode.js +96 -0
  131. package/ts_build/src/agents/tools/ast/astAppendNode.js.map +1 -0
  132. package/ts_build/src/agents/tools/ast/astDeleteNode.d.ts +1 -0
  133. package/ts_build/src/agents/tools/ast/astDeleteNode.js +94 -0
  134. package/ts_build/src/agents/tools/ast/astDeleteNode.js.map +1 -0
  135. package/ts_build/src/agents/tools/ast/astEditNode.d.ts +1 -0
  136. package/ts_build/src/agents/tools/ast/astEditNode.js +96 -0
  137. package/ts_build/src/agents/tools/ast/astEditNode.js.map +1 -0
  138. package/ts_build/src/agents/tools/ast/astGetPathForLine.d.ts +1 -0
  139. package/ts_build/src/agents/tools/ast/astGetPathForLine.js +78 -0
  140. package/ts_build/src/agents/tools/ast/astGetPathForLine.js.map +1 -0
  141. package/ts_build/src/agents/tools/ast/astListPaths.d.ts +1 -0
  142. package/ts_build/src/agents/tools/ast/astListPaths.js +78 -0
  143. package/ts_build/src/agents/tools/ast/astListPaths.js.map +1 -0
  144. package/ts_build/src/agents/tools/ast/index.d.ts +5 -0
  145. package/ts_build/src/agents/tools/ast/index.js +14 -0
  146. package/ts_build/src/agents/tools/ast/index.js.map +1 -0
  147. package/ts_build/src/agents/tools/astAppendNode.d.ts +1 -0
  148. package/ts_build/src/agents/tools/astAppendNode.js +98 -0
  149. package/ts_build/src/agents/tools/astAppendNode.js.map +1 -0
  150. package/ts_build/src/agents/tools/astDeleteNode.d.ts +1 -0
  151. package/ts_build/src/agents/tools/astDeleteNode.js +95 -0
  152. package/ts_build/src/agents/tools/astDeleteNode.js.map +1 -0
  153. package/ts_build/src/agents/tools/astEditNode.d.ts +1 -0
  154. package/ts_build/src/agents/tools/astEditNode.js +98 -0
  155. package/ts_build/src/agents/tools/astEditNode.js.map +1 -0
  156. package/ts_build/src/agents/tools/astGetPathForLine.d.ts +1 -0
  157. package/ts_build/src/agents/tools/astGetPathForLine.js +89 -0
  158. package/ts_build/src/agents/tools/astGetPathForLine.js.map +1 -0
  159. package/ts_build/src/agents/tools/astListPaths.d.ts +1 -0
  160. package/ts_build/src/agents/tools/astListPaths.js +82 -0
  161. package/ts_build/src/agents/tools/astListPaths.js.map +1 -0
  162. package/ts_build/src/agents/tools/callPlugin.js +4 -2
  163. package/ts_build/src/agents/tools/callPlugin.js.map +1 -1
  164. package/ts_build/src/agents/tools/embeddingSearch.js +3 -2
  165. package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -1
  166. package/ts_build/src/agents/tools/execCommand.d.ts +2 -2
  167. package/ts_build/src/agents/tools/execCommand.js +201 -67
  168. package/ts_build/src/agents/tools/execCommand.js.map +1 -1
  169. package/ts_build/src/agents/tools/fileSearch.d.ts +1 -1
  170. package/ts_build/src/agents/tools/fileSearch.js +11 -15
  171. package/ts_build/src/agents/tools/fileSearch.js.map +1 -1
  172. package/ts_build/src/agents/tools/github/index.d.ts +1 -1
  173. package/ts_build/src/agents/tools/index.d.ts +1 -0
  174. package/ts_build/src/agents/tools/index.js +1 -0
  175. package/ts_build/src/agents/tools/index.js.map +1 -1
  176. package/ts_build/src/agents/tools/language/definitions.js +11 -2
  177. package/ts_build/src/agents/tools/language/definitions.js.map +1 -1
  178. package/ts_build/src/agents/tools/language/index.js +4 -3
  179. package/ts_build/src/agents/tools/language/index.js.map +1 -1
  180. package/ts_build/src/agents/tools/lintFile.js +4 -2
  181. package/ts_build/src/agents/tools/lintFile.js.map +1 -1
  182. package/ts_build/src/agents/tools/list.js +185 -49
  183. package/ts_build/src/agents/tools/list.js.map +1 -1
  184. package/ts_build/src/agents/tools/patch.js +33 -10
  185. package/ts_build/src/agents/tools/patch.js.map +1 -1
  186. package/ts_build/src/agents/tools/readBlocks.js +23 -0
  187. package/ts_build/src/agents/tools/readBlocks.js.map +1 -1
  188. package/ts_build/src/agents/tools/readFile.js +14 -0
  189. package/ts_build/src/agents/tools/readFile.js.map +1 -1
  190. package/ts_build/src/agents/tools/stringReplace.js +19 -2
  191. package/ts_build/src/agents/tools/stringReplace.js.map +1 -1
  192. package/ts_build/src/agents/tools/writeFile.js +40 -0
  193. package/ts_build/src/agents/tools/writeFile.js.map +1 -1
  194. package/ts_build/src/agents/tools/ycmd/server.js +5 -0
  195. package/ts_build/src/agents/tools/ycmd/server.js.map +1 -1
  196. package/ts_build/src/chat/CliChatService.d.ts +1 -0
  197. package/ts_build/src/chat/CliChatService.js +6 -2
  198. package/ts_build/src/chat/CliChatService.js.map +1 -1
  199. package/ts_build/src/chat/modules/AgentModule.d.ts +5 -1
  200. package/ts_build/src/chat/modules/AgentModule.js +53 -31
  201. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  202. package/ts_build/src/chat/modules/AskModule.js.map +1 -1
  203. package/ts_build/src/chat/modules/SetupModule.js +4 -3
  204. package/ts_build/src/chat/modules/SetupModule.js.map +1 -1
  205. package/ts_build/src/chat/modules/SystemModule.js +19 -4
  206. package/ts_build/src/chat/modules/SystemModule.js.map +1 -1
  207. package/ts_build/src/chat/modules/index.d.ts +5 -0
  208. package/ts_build/src/chat/modules/index.js +14 -0
  209. package/ts_build/src/chat/modules/index.js.map +1 -0
  210. package/ts_build/src/chat/types.d.ts +2 -0
  211. package/ts_build/src/chat-old.js +3 -3
  212. package/ts_build/src/chat-old.js.map +1 -1
  213. package/ts_build/src/clients/anthropic.d.ts +1 -0
  214. package/ts_build/src/clients/anthropic.js +22 -1
  215. package/ts_build/src/clients/anthropic.js.map +1 -1
  216. package/ts_build/src/clients/openai.js +1 -1
  217. package/ts_build/src/clients/openai.js.map +1 -1
  218. package/ts_build/src/clients/types.d.ts +1 -1
  219. package/ts_build/src/clients/xai.d.ts +7 -0
  220. package/ts_build/src/clients/xai.js +13 -4
  221. package/ts_build/src/clients/xai.js.map +1 -1
  222. package/ts_build/src/config.js +14 -3
  223. package/ts_build/src/config.js.map +1 -1
  224. package/ts_build/src/dataset/diffs/generate.js +2 -2
  225. package/ts_build/src/dataset/diffs/generate.js.map +1 -1
  226. package/ts_build/src/dataset/diffs/jsonl.js.map +1 -1
  227. package/ts_build/src/embeddings.js +7 -9
  228. package/ts_build/src/embeddings.js.map +1 -1
  229. package/ts_build/src/index.js +10 -10
  230. package/ts_build/src/index.js.map +1 -1
  231. package/ts_build/src/plugins/GitPlugin.d.ts +39 -0
  232. package/ts_build/src/plugins/GitPlugin.js +439 -0
  233. package/ts_build/src/plugins/GitPlugin.js.map +1 -0
  234. package/ts_build/src/plugins/LinterPlugin.d.ts +15 -0
  235. package/ts_build/src/plugins/LinterPlugin.js +65 -0
  236. package/ts_build/src/plugins/LinterPlugin.js.map +1 -0
  237. package/ts_build/src/plugins/PluginBase.d.ts +4 -3
  238. package/ts_build/src/plugins/PluginBase.js +3 -3
  239. package/ts_build/src/plugins/PluginBase.js.map +1 -1
  240. package/ts_build/src/plugins/asana.d.ts +3 -1
  241. package/ts_build/src/plugins/asana.js +3 -2
  242. package/ts_build/src/plugins/asana.js.map +1 -1
  243. package/ts_build/src/plugins/downloader/plugin.d.ts +3 -1
  244. package/ts_build/src/plugins/downloader/plugin.js +3 -2
  245. package/ts_build/src/plugins/downloader/plugin.js.map +1 -1
  246. package/ts_build/src/plugins/embedding.d.ts +5 -1
  247. package/ts_build/src/plugins/embedding.js +15 -3
  248. package/ts_build/src/plugins/embedding.js.map +1 -1
  249. package/ts_build/src/plugins/figma.d.ts +3 -1
  250. package/ts_build/src/plugins/figma.js +28 -4
  251. package/ts_build/src/plugins/figma.js.map +1 -1
  252. package/ts_build/src/plugins/github.d.ts +3 -1
  253. package/ts_build/src/plugins/github.js +3 -2
  254. package/ts_build/src/plugins/github.js.map +1 -1
  255. package/ts_build/src/plugins/jira.d.ts +3 -1
  256. package/ts_build/src/plugins/jira.js +3 -2
  257. package/ts_build/src/plugins/jira.js.map +1 -1
  258. package/ts_build/src/plugins/language.d.ts +7 -4
  259. package/ts_build/src/plugins/language.js +85 -20
  260. package/ts_build/src/plugins/language.js.map +1 -1
  261. package/ts_build/src/plugins/linear.d.ts +3 -1
  262. package/ts_build/src/plugins/linear.js +3 -2
  263. package/ts_build/src/plugins/linear.js.map +1 -1
  264. package/ts_build/src/plugins/notion.d.ts +3 -1
  265. package/ts_build/src/plugins/notion.js +3 -2
  266. package/ts_build/src/plugins/notion.js.map +1 -1
  267. package/ts_build/src/plugins/plugins.d.ts +4 -3
  268. package/ts_build/src/plugins/plugins.js +24 -14
  269. package/ts_build/src/plugins/plugins.js.map +1 -1
  270. package/ts_build/src/plugins/tree-sitter/editor.d.ts +34 -0
  271. package/ts_build/src/plugins/tree-sitter/editor.js +218 -0
  272. package/ts_build/src/plugins/tree-sitter/editor.js.map +1 -0
  273. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.d.ts +29 -0
  274. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js +538 -0
  275. package/ts_build/src/plugins/tree-sitter/human-readable-paths-new.js.map +1 -0
  276. package/ts_build/src/plugins/tree-sitter/human-readable-paths.d.ts +22 -0
  277. package/ts_build/src/plugins/tree-sitter/human-readable-paths.js +332 -0
  278. package/ts_build/src/plugins/tree-sitter/human-readable-paths.js.map +1 -0
  279. package/ts_build/src/plugins/tree-sitter/lang-packs/index.d.ts +8 -0
  280. package/ts_build/src/plugins/tree-sitter/lang-packs/index.js +26 -0
  281. package/ts_build/src/plugins/tree-sitter/lang-packs/index.js.map +1 -0
  282. package/ts_build/src/plugins/tree-sitter/lang-packs/java.d.ts +2 -0
  283. package/ts_build/src/plugins/tree-sitter/lang-packs/java.js +61 -0
  284. package/ts_build/src/plugins/tree-sitter/lang-packs/java.js.map +1 -0
  285. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.d.ts +2 -0
  286. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js +59 -0
  287. package/ts_build/src/plugins/tree-sitter/lang-packs/javascript.js.map +1 -0
  288. package/ts_build/src/plugins/tree-sitter/lang-packs/python.d.ts +2 -0
  289. package/ts_build/src/plugins/tree-sitter/lang-packs/python.js +47 -0
  290. package/ts_build/src/plugins/tree-sitter/lang-packs/python.js.map +1 -0
  291. package/ts_build/src/plugins/tree-sitter/lang-packs/types.d.ts +43 -0
  292. package/ts_build/src/plugins/tree-sitter/lang-packs/types.js +3 -0
  293. package/ts_build/src/plugins/tree-sitter/lang-packs/types.js.map +1 -0
  294. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.d.ts +2 -0
  295. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js +50 -0
  296. package/ts_build/src/plugins/tree-sitter/lang-packs/typescript.js.map +1 -0
  297. package/ts_build/src/plugins/tree-sitter/parser.d.ts +75 -0
  298. package/ts_build/src/plugins/tree-sitter/parser.js +306 -0
  299. package/ts_build/src/plugins/tree-sitter/parser.js.map +1 -0
  300. package/ts_build/src/plugins/tree-sitter/simple-paths.d.ts +22 -0
  301. package/ts_build/src/plugins/tree-sitter/simple-paths.js +332 -0
  302. package/ts_build/src/plugins/tree-sitter/simple-paths.js.map +1 -0
  303. package/ts_build/src/plugins/types.d.ts +10 -0
  304. package/ts_build/src/plugins/url.d.ts +3 -2
  305. package/ts_build/src/plugins/url.js +3 -2
  306. package/ts_build/src/plugins/url.js.map +1 -1
  307. package/ts_build/src/plugins/vim.d.ts +4 -2
  308. package/ts_build/src/plugins/vim.js +6 -8
  309. package/ts_build/src/plugins/vim.js.map +1 -1
  310. package/ts_build/src/processors/CustomVariables.js +12 -3
  311. package/ts_build/src/processors/CustomVariables.js.map +1 -1
  312. package/ts_build/src/processors/TokenCompressor.js +8 -11
  313. package/ts_build/src/processors/TokenCompressor.js.map +1 -1
  314. package/ts_build/src/processors/ToolResponseCache.d.ts +2 -2
  315. package/ts_build/src/processors/ToolResponseCache.js +12 -2
  316. package/ts_build/src/processors/ToolResponseCache.js.map +1 -1
  317. package/ts_build/src/services/EmbeddingService.d.ts +10 -1
  318. package/ts_build/src/services/EmbeddingService.js +12 -12
  319. package/ts_build/src/services/EmbeddingService.js.map +1 -1
  320. package/ts_build/src/services/EventService.d.ts +7 -0
  321. package/ts_build/src/services/EventService.js +49 -0
  322. package/ts_build/src/services/EventService.js.map +1 -1
  323. package/ts_build/src/services/Mcp.js +8 -0
  324. package/ts_build/src/services/Mcp.js.map +1 -1
  325. package/ts_build/src/services/S3.js +4 -3
  326. package/ts_build/src/services/S3.js.map +1 -1
  327. package/ts_build/src/services/Tools.d.ts +1 -0
  328. package/ts_build/src/services/Tools.js +97 -35
  329. package/ts_build/src/services/Tools.js.map +1 -1
  330. package/ts_build/src/services/index.d.ts +4 -5
  331. package/ts_build/src/services/index.js +14 -9
  332. package/ts_build/src/services/index.js.map +1 -1
  333. package/ts_build/src/services/types.js +3 -3
  334. package/ts_build/src/services/types.js.map +1 -1
  335. package/ts_build/src/types.d.ts +7 -1
  336. package/ts_build/src/types.js +4 -0
  337. package/ts_build/src/types.js.map +1 -1
  338. package/ts_build/src/worker.js +12 -1
  339. package/ts_build/src/worker.js.map +1 -1
  340. package/ts_build/tests/clients/AIClient.test.d.ts +1 -0
  341. package/ts_build/tests/clients/AIClient.test.js +377 -0
  342. package/ts_build/tests/clients/AIClient.test.js.map +1 -0
  343. package/ts_build/tests/languagePlugin.test.js +217 -11
  344. package/ts_build/tests/languagePlugin.test.js.map +1 -1
  345. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.d.ts +1 -0
  346. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js +315 -0
  347. package/ts_build/tests/manual/agent-events/event-handler-reliability.test.js.map +1 -0
  348. package/ts_build/tests/manual/agent-events/run-test.d.ts +2 -0
  349. package/ts_build/tests/manual/agent-events/run-test.js +148 -0
  350. package/ts_build/tests/manual/agent-events/run-test.js.map +1 -0
  351. package/ts_build/tests/manual/file-edits/figma.test.d.ts +1 -0
  352. package/ts_build/tests/manual/file-edits/figma.test.js +47 -0
  353. package/ts_build/tests/manual/file-edits/figma.test.js.map +1 -0
  354. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.d.ts +1 -0
  355. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js +100 -0
  356. package/ts_build/tests/manual/file-edits/fileblocks/readwrite.test.js.map +1 -0
  357. package/ts_build/tests/manual/file-edits/patching.test.d.ts +1 -0
  358. package/ts_build/tests/manual/file-edits/patching.test.js +119 -0
  359. package/ts_build/tests/manual/file-edits/patching.test.js.map +1 -0
  360. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.d.ts +1 -0
  361. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js +277 -0
  362. package/ts_build/tests/plugins/language/languagePlugin-content-triggers.test.js.map +1 -0
  363. package/ts_build/tests/plugins/language/languagePlugin-integration.test.d.ts +1 -0
  364. package/ts_build/tests/plugins/language/languagePlugin-integration.test.js +331 -0
  365. package/ts_build/tests/plugins/language/languagePlugin-integration.test.js.map +1 -0
  366. package/ts_build/tests/plugins/language/languagePlugin.test.d.ts +1 -0
  367. package/ts_build/tests/plugins/language/languagePlugin.test.js +286 -0
  368. package/ts_build/tests/plugins/language/languagePlugin.test.js.map +1 -0
  369. package/ts_build/tests/processors/Base64ImageDetector.test.d.ts +1 -0
  370. package/ts_build/tests/processors/Base64ImageDetector.test.js +351 -0
  371. package/ts_build/tests/processors/Base64ImageDetector.test.js.map +1 -0
  372. package/ts_build/tests/processors/CustomVariables.test.d.ts +1 -0
  373. package/ts_build/tests/processors/CustomVariables.test.js +351 -0
  374. package/ts_build/tests/processors/CustomVariables.test.js.map +1 -0
  375. package/ts_build/tests/processors/HarmonyToolProcessor.test.d.ts +1 -0
  376. package/ts_build/tests/processors/HarmonyToolProcessor.test.js +382 -0
  377. package/ts_build/tests/processors/HarmonyToolProcessor.test.js.map +1 -0
  378. package/ts_build/tests/processors/TokenCompressor.test.d.ts +1 -0
  379. package/ts_build/tests/processors/TokenCompressor.test.js +300 -0
  380. package/ts_build/tests/processors/TokenCompressor.test.js.map +1 -0
  381. package/ts_build/tests/processors/ToolResponseCache.test.d.ts +1 -0
  382. package/ts_build/tests/processors/ToolResponseCache.test.js +539 -0
  383. package/ts_build/tests/processors/ToolResponseCache.test.js.map +1 -0
  384. package/ts_build/tests/services/Plugins/plugin-event-integration.test.d.ts +1 -0
  385. package/ts_build/tests/services/Plugins/plugin-event-integration.test.js +232 -0
  386. package/ts_build/tests/services/Plugins/plugin-event-integration.test.js.map +1 -0
  387. package/ts_build/tests/services/Tools.test.d.ts +1 -0
  388. package/ts_build/tests/services/Tools.test.js +1059 -0
  389. package/ts_build/tests/services/Tools.test.js.map +1 -0
  390. package/ts_build/tests/test.spec.js +110 -68
  391. package/ts_build/tests/test.spec.js.map +1 -1
  392. package/ts_build/tests/tree-sitter/editor.test.d.ts +1 -0
  393. package/ts_build/tests/tree-sitter/editor.test.js +85 -0
  394. package/ts_build/tests/tree-sitter/editor.test.js.map +1 -0
  395. package/ts_build/tests/tree-sitter/invalid.test.d.ts +1 -0
  396. package/ts_build/tests/tree-sitter/invalid.test.js +198 -0
  397. package/ts_build/tests/tree-sitter/invalid.test.js.map +1 -0
  398. package/ts_build/tests/tree-sitter/paths/common-edits.test.d.ts +1 -0
  399. package/ts_build/tests/tree-sitter/paths/common-edits.test.js +347 -0
  400. package/ts_build/tests/tree-sitter/paths/common-edits.test.js.map +1 -0
  401. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.d.ts +1 -0
  402. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js +35 -0
  403. package/ts_build/tests/tree-sitter/paths/debug-exact-position.test.js.map +1 -0
  404. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.d.ts +1 -0
  405. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js +38 -0
  406. package/ts_build/tests/tree-sitter/paths/debug-line-indexing.test.js.map +1 -0
  407. package/ts_build/tests/tree-sitter/paths/debug-paths.test.d.ts +1 -0
  408. package/ts_build/tests/tree-sitter/paths/debug-paths.test.js +74 -0
  409. package/ts_build/tests/tree-sitter/paths/debug-paths.test.js.map +1 -0
  410. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.d.ts +1 -0
  411. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js +302 -0
  412. package/ts_build/tests/tree-sitter/paths/human-readable-paths.test.js.map +1 -0
  413. package/ts_build/tests/tree-sitter/paths/paths.test.d.ts +1 -0
  414. package/ts_build/tests/tree-sitter/paths/paths.test.js +116 -0
  415. package/ts_build/tests/tree-sitter/paths/paths.test.js.map +1 -0
  416. package/ts_build/tests/tree-sitter/paths/simple-paths.test.d.ts +1 -0
  417. package/ts_build/tests/tree-sitter/paths/simple-paths.test.js +302 -0
  418. package/ts_build/tests/tree-sitter/paths/simple-paths.test.js.map +1 -0
  419. package/ts_build/tests/tree-sitter/sample-after.d.ts +11 -0
  420. package/ts_build/tests/tree-sitter/sample-after.js +44 -0
  421. package/ts_build/tests/tree-sitter/sample-after.js.map +1 -0
  422. package/ts_build/tests/tree-sitter/sample-before.d.ts +9 -0
  423. package/ts_build/tests/tree-sitter/sample-before.js +28 -0
  424. package/ts_build/tests/tree-sitter/sample-before.js.map +1 -0
  425. package/ts_build/tests/tree-sitter/test-files/completely-broken.d.ts +2 -0
  426. package/ts_build/tests/tree-sitter/test-files/completely-broken.js +17 -0
  427. package/ts_build/tests/tree-sitter/test-files/completely-broken.js.map +1 -0
  428. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.d.ts +8 -0
  429. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js +38 -0
  430. package/ts_build/tests/tree-sitter/test-files/duplicate-braces.js.map +1 -0
  431. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.d.ts +8 -0
  432. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js +38 -0
  433. package/ts_build/tests/tree-sitter/test-files/invalid-nesting.js.map +1 -0
  434. package/ts_build/tests/tree-sitter/test-files/malformed-signature.d.ts +8 -0
  435. package/ts_build/tests/tree-sitter/test-files/malformed-signature.js +38 -0
  436. package/ts_build/tests/tree-sitter/test-files/malformed-signature.js.map +1 -0
  437. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.d.ts +10 -0
  438. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js +38 -0
  439. package/ts_build/tests/tree-sitter/test-files/mismatched-parens.js.map +1 -0
  440. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.d.ts +8 -0
  441. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js +38 -0
  442. package/ts_build/tests/tree-sitter/test-files/missing-semicolon.js.map +1 -0
  443. package/ts_build/tests/tree-sitter/test-files/partially-broken.d.ts +6 -0
  444. package/ts_build/tests/tree-sitter/test-files/partially-broken.js +20 -0
  445. package/ts_build/tests/tree-sitter/test-files/partially-broken.js.map +1 -0
  446. package/ts_build/tests/tree-sitter/test-files/specific-errors.d.ts +7 -0
  447. package/ts_build/tests/tree-sitter/test-files/specific-errors.js +14 -0
  448. package/ts_build/tests/tree-sitter/test-files/specific-errors.js.map +1 -0
  449. package/ts_build/tests/tree-sitter/test-files/unclosed-string.d.ts +8 -0
  450. package/ts_build/tests/tree-sitter/test-files/unclosed-string.js +38 -0
  451. package/ts_build/tests/tree-sitter/test-files/unclosed-string.js.map +1 -0
  452. package/ts_build/tests/tree-sitter/tree-sitter.test.d.ts +1 -0
  453. package/ts_build/tests/tree-sitter/tree-sitter.test.js +185 -0
  454. package/ts_build/tests/tree-sitter/tree-sitter.test.js.map +1 -0
  455. package/tsconfig.json +2 -1
  456. package/tests/languagePlugin.test.ts +0 -74
  457. /package/src/chat/modules/{index.js → index.ts} +0 -0
  458. /package/tests/{integration → manual/file-edits}/patching/input.txt +0 -0
  459. /package/tests/{integration → manual/file-edits}/patching/output.txt +0 -0
  460. /package/tests/{integration → manual/file-edits}/patching/patch.txt +0 -0
  461. /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:
@@ -535,9 +535,9 @@ ${reason}
535
535
  messageId: session.knowhowMessageId,
536
536
  existingKnowhowTaskId: session.knowhowTaskId,
537
537
  chatHistory: [],
538
- run: true,
538
+ run: false, // Don't run yet, we need to set up event listeners first
539
539
  });
540
- await this.attachedAgentChatLoop(taskId, agent);
540
+ await this.attachedAgentChatLoop(taskId, agent, resumePrompt);
541
541
  } catch (error) {
542
542
  console.error(
543
543
  `Failed to resume session ${sessionId}:`,
@@ -549,11 +549,26 @@ ${reason}
549
549
  async handleInput(input: string, context: ChatContext): Promise<boolean> {
550
550
  // If in agent mode, start agent with the input as initial task (like original chat.ts)
551
551
  if (context.agentMode && context.selectedAgent) {
552
- const result = await this.startAgent(
552
+ // Create initial interaction for the chatHistory
553
+ const initialInteraction: ChatInteraction = {
554
+ input,
555
+ output: "", // Will be filled after agent completion
556
+ summaries: [],
557
+ lastThread: [],
558
+ };
559
+
560
+ const { result, finalOutput } = await this.startAgent(
553
561
  context.selectedAgent,
554
562
  input,
555
563
  context.chatHistory || []
556
564
  );
565
+
566
+ // Update the chatHistory with the completed interaction
567
+ if (result && finalOutput) {
568
+ initialInteraction.output = finalOutput;
569
+ context.chatHistory.push(initialInteraction);
570
+ }
571
+
557
572
  return result;
558
573
  }
559
574
  return false;
@@ -593,6 +608,17 @@ ${reason}
593
608
  let knowhowTaskId: string | undefined;
594
609
 
595
610
  try {
611
+ // Get context for plugins
612
+ const context = this.chatService?.getContext();
613
+ const plugins = context?.plugins || [];
614
+
615
+ // Format the prompt with plugins and chat history
616
+ const formattedPrompt = await this.chatService.formatChatInput(
617
+ input,
618
+ plugins,
619
+ chatHistory
620
+ );
621
+
596
622
  // Create task info object
597
623
  let taskInfo: TaskInfo = {
598
624
  taskId,
@@ -601,6 +627,7 @@ ${reason}
601
627
  agentName,
602
628
  agent,
603
629
  initialInput: input,
630
+ formattedPrompt,
604
631
  status: "running",
605
632
  startTime: Date.now(),
606
633
  totalCost: 0,
@@ -637,25 +664,28 @@ ${reason}
637
664
  }
638
665
 
639
666
  // 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}`);
667
+ agent.agentEvents.on(
668
+ agent.eventTypes.threadUpdate,
669
+ async (threadState) => {
670
+ // Update task cost from agent's current total cost
671
+ taskInfo.totalCost = agent.getTotalCostUsd();
672
+ this.updateSession(taskId, threadState);
673
+
674
+ // Update Knowhow chat task if created
675
+ if (knowhowTaskId && options.messageId && baseUrl) {
676
+ await client
677
+ .updateChatTask(knowhowTaskId, {
678
+ threads: agent.getThreads(),
679
+ totalCostUsd: agent.getTotalCostUsd(),
680
+ inProgress: true,
681
+ })
682
+ .catch((error) => {
683
+ console.error(`❌ Failed to update Knowhow chat task:`, error);
684
+ });
685
+ console.log(`✅ Updated Knowhow chat task: ${knowhowTaskId}`);
686
+ }
657
687
  }
658
- });
688
+ );
659
689
 
660
690
  console.log(
661
691
  Marked.parse(`**Starting ${agent.name} with task ID: ${taskId}...**`)
@@ -663,7 +693,7 @@ ${reason}
663
693
  console.log(Marked.parse(`**Task:** ${input}`));
664
694
 
665
695
  // Initialize new task
666
- await agent.newTask();
696
+ await agent.newTask(taskId);
667
697
 
668
698
  if (options.model) {
669
699
  console.log("Setting model:", options.model);
@@ -673,17 +703,6 @@ ${reason}
673
703
  ]);
674
704
  }
675
705
 
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
706
  // Set up message processors like in original startAgent
688
707
 
689
708
  agent.messageProcessor.setProcessors("pre_call", [
@@ -708,7 +727,7 @@ ${reason}
708
727
 
709
728
  const taskCompleted = new Promise<string>((resolve) => {
710
729
  agent.agentEvents.once(agent.eventTypes.done, async (doneMsg) => {
711
- console.log("Agent has finished.");
730
+ console.log("Agent has completed the task.");
712
731
  done = true;
713
732
  output = doneMsg || "No response from the AI";
714
733
  // Update task info
@@ -767,7 +786,13 @@ ${reason}
767
786
  agent.call(formattedPrompt);
768
787
  }
769
788
 
770
- return { agent, taskId, formattedPrompt, taskCompleted };
789
+ return {
790
+ agent,
791
+ taskId,
792
+ formattedPrompt,
793
+ initialInput: input,
794
+ taskCompleted,
795
+ };
771
796
  } catch (error) {
772
797
  console.error("Agent setup failed:", error);
773
798
  this.taskRegistry.delete(taskId);
@@ -809,11 +834,11 @@ ${reason}
809
834
  .replace(/[^\w\s]/g, "")
810
835
  .split(/\s+/)
811
836
  .filter((word) => word.length > 2)
812
- .slice(0, 3);
837
+ .slice(0, 9);
813
838
 
814
839
  const wordPart = words.join("-") || "task";
815
- const timestamp = Date.now().toString().slice(-6);
816
- return `${wordPart}-${timestamp}`;
840
+ const epochSeconds = Math.floor(Date.now() / 1000);
841
+ return `${epochSeconds}-${wordPart}`;
817
842
  }
818
843
 
819
844
  /**
@@ -887,47 +912,67 @@ ${reason}
887
912
  selectedAgent: BaseAgent,
888
913
  initialInput: string,
889
914
  chatHistory: ChatInteraction[] = []
890
- ): Promise<boolean> {
915
+ ): Promise<{ result: boolean; finalOutput?: string }> {
891
916
  try {
892
- const { agent, taskId } = await this.setupAgent({
917
+ const { agent, taskId, formattedPrompt } = await this.setupAgent({
893
918
  agentName: selectedAgent.name,
894
919
  input: initialInput,
895
920
  chatHistory,
896
- run: true,
921
+ run: false, // Don't run yet, we need to set up event listeners first
897
922
  });
898
- return await this.attachedAgentChatLoop(taskId, agent);
923
+ const result = await this.attachedAgentChatLoop(
924
+ taskId,
925
+ agent,
926
+ formattedPrompt
927
+ );
928
+ return result;
899
929
  } catch (error) {
900
930
  console.error("Error starting agent:", error);
901
- return false;
931
+ return { result: false, finalOutput: "Error starting agent" };
902
932
  }
903
933
  }
904
934
 
905
- async attachedAgentChatLoop(taskId: string, agent: BaseAgent) {
935
+ async attachedAgentChatLoop(
936
+ taskId: string,
937
+ agent: BaseAgent,
938
+ initialInput?: string
939
+ ): Promise<{ result: boolean; finalOutput?: string }> {
906
940
  try {
907
941
  let done = false;
908
942
  let output = "Done";
943
+ let agentFinalOutput: string | undefined;
909
944
 
910
945
  // Define available commands
911
- const commands = ["pause", "unpause", "kill", "detach"];
946
+ const commands = ["/pause", "/unpause", "/kill", "/detach", "/done"];
912
947
  const history: string[] = [];
913
948
 
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
-
949
+ // Set up the event listener BEFORE starting the agent to avoid race condition
922
950
  let finished = false;
923
951
  const donePromise = new Promise<string>((resolve) => {
924
952
  agent.agentEvents.once(agent.eventTypes.done, (doneMsg) => {
925
- console.log("Agent has completed the task.");
953
+ // Capture the agent's final output
954
+ agentFinalOutput = doneMsg || "No response from the AI";
926
955
  finished = true;
927
956
  resolve("done");
928
957
  });
929
958
  });
930
959
 
960
+ // Now start the agent if we have an initial input (this means we're starting, not just attaching)
961
+ if (initialInput) {
962
+ const taskInfo = this.taskRegistry.get(taskId);
963
+ agent.call(
964
+ taskInfo?.formattedPrompt || taskInfo?.initialInput || initialInput
965
+ );
966
+ }
967
+
968
+ let input =
969
+ (await this.chatService?.getInput(
970
+ `Enter command or message for ${agent.name}: `,
971
+ commands
972
+ )) || "";
973
+
974
+ history.push(input);
975
+
931
976
  while (!done) {
932
977
  switch (input) {
933
978
  case "":
@@ -936,26 +981,26 @@ ${reason}
936
981
  done = true;
937
982
  }
938
983
  break;
939
- case "done":
984
+ case "/done":
940
985
  output = "Exited agent interaction.";
941
986
  done = true;
942
987
  break;
943
- case "pause":
988
+ case "/pause":
944
989
  await agent.pause();
945
990
  console.log("Agent paused.");
946
991
  break;
947
- case "unpause":
992
+ case "/unpause":
948
993
  await agent.unpause();
949
994
  console.log("Agent unpaused.");
950
995
  break;
951
- case "kill":
996
+ case "/kill":
952
997
  await agent.kill();
953
998
  console.log("Agent terminated.");
954
999
  done = true;
955
1000
  break;
956
- case "detach":
1001
+ case "/detach":
957
1002
  console.log("Detached from agent");
958
- return true;
1003
+ return { result: true, finalOutput: agentFinalOutput };
959
1004
  default:
960
1005
  agent.addPendingUserMessage({
961
1006
  role: "user",
@@ -981,12 +1026,10 @@ ${reason}
981
1026
  finalTaskInfo.endTime = Date.now();
982
1027
  }
983
1028
  }
984
-
985
- return true;
1029
+ return { result: true, finalOutput: agentFinalOutput };
986
1030
  } catch (error) {
987
1031
  console.error("Agent execution failed:", error);
988
- this.taskRegistry.delete(taskId);
989
- return false;
1032
+ return { result: false, finalOutput: "Error during agent execution" };
990
1033
  }
991
1034
  }
992
1035
  }
@@ -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
 
@@ -4,7 +4,7 @@ export type MessageContent =
4
4
 
5
5
  export interface Message {
6
6
  role: "system" | "user" | "assistant" | "tool";
7
- content: string | MessageContent[];
7
+ content?: string | MessageContent[];
8
8
 
9
9
  name?: string;
10
10
  tool_call_id?: string;