@travisennis/acai 0.0.1

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 (439) hide show
  1. package/.acai/acai.json +9 -0
  2. package/.acai/prompts/add-openrouter-model.md +13 -0
  3. package/.acai/prompts/project-status.md +4 -0
  4. package/.acai/prompts/update-architecture-document.md +9 -0
  5. package/.acai/rules/learned-rules.md +9 -0
  6. package/.ai/docs/available-tools.txt +3 -0
  7. package/.ai/docs/cognitive_complexity_refactoring_progress.md +65 -0
  8. package/.ai/docs/deleted_tools.md +168 -0
  9. package/.ai/docs/deleted_tools_88ced9ef.md +56 -0
  10. package/.ai/docs/image-pasting.md +46 -0
  11. package/.ai/docs/initialize-app.md +117 -0
  12. package/.ai/docs/issue-4-plan.md +44 -0
  13. package/.ai/docs/marked-renderer-debug.md +15 -0
  14. package/.ai/docs/marked-renderer-refactor-plan.md +64 -0
  15. package/.ai/docs/memory-use-cases.md +55 -0
  16. package/.ai/docs/prompt-consistency.md +31 -0
  17. package/.ai/docs/refactoring-tools.md +98 -0
  18. package/.ai/docs/system-prompt-update.md +174 -0
  19. package/.ai/docs/system_prompt.txt +210 -0
  20. package/.ai/docs/tasks.md +49 -0
  21. package/.ai/plan.md +131 -0
  22. package/.ai/prompt.md +1 -0
  23. package/.ai/scripts/fetch_models.js +27 -0
  24. package/.ai/scripts/generateSystemPrompt.ts +15 -0
  25. package/.ai/scripts/list-tools.mjs +4 -0
  26. package/.ai/scripts/p5_geometric_shapes.js +149 -0
  27. package/.husky/commit-msg +1 -0
  28. package/.husky/pre-commit +3 -0
  29. package/.husky/pre-push +1 -0
  30. package/.ignore +4 -0
  31. package/AGENTS.md +25 -0
  32. package/ARCHITECTURE.md +304 -0
  33. package/LICENSE +21 -0
  34. package/README.md +392 -0
  35. package/TODO.md +2 -0
  36. package/biome.json +61 -0
  37. package/commitlint.config.js +3 -0
  38. package/dist/cli.d.ts +19 -0
  39. package/dist/cli.js +116 -0
  40. package/dist/commands/application-log-command.d.ts +2 -0
  41. package/dist/commands/application-log-command.js +43 -0
  42. package/dist/commands/clear-command.d.ts +2 -0
  43. package/dist/commands/clear-command.js +12 -0
  44. package/dist/commands/compact-command.d.ts +2 -0
  45. package/dist/commands/compact-command.js +51 -0
  46. package/dist/commands/copy-command.d.ts +2 -0
  47. package/dist/commands/copy-command.js +51 -0
  48. package/dist/commands/edit-command.d.ts +2 -0
  49. package/dist/commands/edit-command.js +53 -0
  50. package/dist/commands/edit-prompt-command.d.ts +2 -0
  51. package/dist/commands/edit-prompt-command.js +25 -0
  52. package/dist/commands/exit-command.d.ts +2 -0
  53. package/dist/commands/exit-command.js +14 -0
  54. package/dist/commands/files-command.d.ts +2 -0
  55. package/dist/commands/files-command.js +63 -0
  56. package/dist/commands/generate-rules-command.d.ts +2 -0
  57. package/dist/commands/generate-rules-command.js +61 -0
  58. package/dist/commands/help-command.d.ts +2 -0
  59. package/dist/commands/help-command.js +19 -0
  60. package/dist/commands/init-command.d.ts +2 -0
  61. package/dist/commands/init-command.js +40 -0
  62. package/dist/commands/last-log-command.d.ts +2 -0
  63. package/dist/commands/last-log-command.js +76 -0
  64. package/dist/commands/manager.d.ts +22 -0
  65. package/dist/commands/manager.js +123 -0
  66. package/dist/commands/model-command.d.ts +2 -0
  67. package/dist/commands/model-command.js +84 -0
  68. package/dist/commands/paste-command.d.ts +2 -0
  69. package/dist/commands/paste-command.js +40 -0
  70. package/dist/commands/prompt-command.d.ts +2 -0
  71. package/dist/commands/prompt-command.js +111 -0
  72. package/dist/commands/reset-command.d.ts +2 -0
  73. package/dist/commands/reset-command.js +16 -0
  74. package/dist/commands/rules-command.d.ts +2 -0
  75. package/dist/commands/rules-command.js +68 -0
  76. package/dist/commands/save-command.d.ts +2 -0
  77. package/dist/commands/save-command.js +14 -0
  78. package/dist/commands/types.d.ts +26 -0
  79. package/dist/commands/types.js +1 -0
  80. package/dist/commands/usage-command.d.ts +2 -0
  81. package/dist/commands/usage-command.js +21 -0
  82. package/dist/config.d.ts +60 -0
  83. package/dist/config.js +193 -0
  84. package/dist/conversation-analyzer.d.ts +10 -0
  85. package/dist/conversation-analyzer.js +88 -0
  86. package/dist/dedent.d.ts +3 -0
  87. package/dist/dedent.js +38 -0
  88. package/dist/formatting.d.ts +17 -0
  89. package/dist/formatting.js +103 -0
  90. package/dist/index.d.ts +18 -0
  91. package/dist/index.js +213 -0
  92. package/dist/logger.d.ts +2 -0
  93. package/dist/logger.js +24 -0
  94. package/dist/mentions.d.ts +9 -0
  95. package/dist/mentions.js +182 -0
  96. package/dist/messages.d.ts +69 -0
  97. package/dist/messages.js +261 -0
  98. package/dist/middleware/audit-message.d.ts +5 -0
  99. package/dist/middleware/audit-message.js +95 -0
  100. package/dist/middleware/index.d.ts +2 -0
  101. package/dist/middleware/index.js +2 -0
  102. package/dist/middleware/rate-limit.d.ts +4 -0
  103. package/dist/middleware/rate-limit.js +17 -0
  104. package/dist/models/ai-config.d.ts +12 -0
  105. package/dist/models/ai-config.js +87 -0
  106. package/dist/models/anthropic-provider.d.ts +25 -0
  107. package/dist/models/anthropic-provider.js +184 -0
  108. package/dist/models/deepseek-provider.d.ts +20 -0
  109. package/dist/models/deepseek-provider.js +42 -0
  110. package/dist/models/google-provider.d.ts +19 -0
  111. package/dist/models/google-provider.js +56 -0
  112. package/dist/models/manager.d.ts +15 -0
  113. package/dist/models/manager.js +48 -0
  114. package/dist/models/openai-provider.d.ts +22 -0
  115. package/dist/models/openai-provider.js +70 -0
  116. package/dist/models/openrouter-provider.d.ts +36 -0
  117. package/dist/models/openrouter-provider.js +276 -0
  118. package/dist/models/providers.d.ts +33 -0
  119. package/dist/models/providers.js +116 -0
  120. package/dist/models/xai-provider.d.ts +20 -0
  121. package/dist/models/xai-provider.js +47 -0
  122. package/dist/parsing.d.ts +2 -0
  123. package/dist/parsing.js +18 -0
  124. package/dist/prompts/manager.d.ts +19 -0
  125. package/dist/prompts/manager.js +71 -0
  126. package/dist/prompts.d.ts +4 -0
  127. package/dist/prompts.js +158 -0
  128. package/dist/repl-prompt.d.ts +14 -0
  129. package/dist/repl-prompt.js +147 -0
  130. package/dist/repl.d.ts +27 -0
  131. package/dist/repl.js +431 -0
  132. package/dist/source/cli.d.ts +19 -0
  133. package/dist/source/cli.js +116 -0
  134. package/dist/source/commands/application-log-command.d.ts +2 -0
  135. package/dist/source/commands/application-log-command.js +43 -0
  136. package/dist/source/commands/clear-command.d.ts +2 -0
  137. package/dist/source/commands/clear-command.js +12 -0
  138. package/dist/source/commands/compact-command.d.ts +2 -0
  139. package/dist/source/commands/compact-command.js +51 -0
  140. package/dist/source/commands/copy-command.d.ts +2 -0
  141. package/dist/source/commands/copy-command.js +51 -0
  142. package/dist/source/commands/edit-command.d.ts +2 -0
  143. package/dist/source/commands/edit-command.js +53 -0
  144. package/dist/source/commands/edit-prompt-command.d.ts +2 -0
  145. package/dist/source/commands/edit-prompt-command.js +25 -0
  146. package/dist/source/commands/exit-command.d.ts +2 -0
  147. package/dist/source/commands/exit-command.js +14 -0
  148. package/dist/source/commands/files-command.d.ts +2 -0
  149. package/dist/source/commands/files-command.js +63 -0
  150. package/dist/source/commands/generate-rules-command.d.ts +2 -0
  151. package/dist/source/commands/generate-rules-command.js +61 -0
  152. package/dist/source/commands/help-command.d.ts +2 -0
  153. package/dist/source/commands/help-command.js +19 -0
  154. package/dist/source/commands/init-command.d.ts +2 -0
  155. package/dist/source/commands/init-command.js +40 -0
  156. package/dist/source/commands/last-log-command.d.ts +2 -0
  157. package/dist/source/commands/last-log-command.js +76 -0
  158. package/dist/source/commands/manager.d.ts +22 -0
  159. package/dist/source/commands/manager.js +123 -0
  160. package/dist/source/commands/model-command.d.ts +2 -0
  161. package/dist/source/commands/model-command.js +84 -0
  162. package/dist/source/commands/paste-command.d.ts +2 -0
  163. package/dist/source/commands/paste-command.js +40 -0
  164. package/dist/source/commands/prompt-command.d.ts +2 -0
  165. package/dist/source/commands/prompt-command.js +111 -0
  166. package/dist/source/commands/reset-command.d.ts +2 -0
  167. package/dist/source/commands/reset-command.js +16 -0
  168. package/dist/source/commands/rules-command.d.ts +2 -0
  169. package/dist/source/commands/rules-command.js +68 -0
  170. package/dist/source/commands/save-command.d.ts +2 -0
  171. package/dist/source/commands/save-command.js +14 -0
  172. package/dist/source/commands/types.d.ts +26 -0
  173. package/dist/source/commands/types.js +1 -0
  174. package/dist/source/commands/usage-command.d.ts +2 -0
  175. package/dist/source/commands/usage-command.js +21 -0
  176. package/dist/source/config.d.ts +60 -0
  177. package/dist/source/config.js +193 -0
  178. package/dist/source/conversation-analyzer.d.ts +10 -0
  179. package/dist/source/conversation-analyzer.js +88 -0
  180. package/dist/source/dedent.d.ts +3 -0
  181. package/dist/source/dedent.js +38 -0
  182. package/dist/source/formatting.d.ts +17 -0
  183. package/dist/source/formatting.js +103 -0
  184. package/dist/source/index.d.ts +18 -0
  185. package/dist/source/index.js +213 -0
  186. package/dist/source/logger.d.ts +2 -0
  187. package/dist/source/logger.js +24 -0
  188. package/dist/source/mentions.d.ts +9 -0
  189. package/dist/source/mentions.js +182 -0
  190. package/dist/source/messages.d.ts +69 -0
  191. package/dist/source/messages.js +261 -0
  192. package/dist/source/middleware/audit-message.d.ts +5 -0
  193. package/dist/source/middleware/audit-message.js +95 -0
  194. package/dist/source/middleware/index.d.ts +2 -0
  195. package/dist/source/middleware/index.js +2 -0
  196. package/dist/source/middleware/rate-limit.d.ts +4 -0
  197. package/dist/source/middleware/rate-limit.js +17 -0
  198. package/dist/source/models/ai-config.d.ts +12 -0
  199. package/dist/source/models/ai-config.js +87 -0
  200. package/dist/source/models/anthropic-provider.d.ts +25 -0
  201. package/dist/source/models/anthropic-provider.js +184 -0
  202. package/dist/source/models/deepseek-provider.d.ts +20 -0
  203. package/dist/source/models/deepseek-provider.js +42 -0
  204. package/dist/source/models/google-provider.d.ts +19 -0
  205. package/dist/source/models/google-provider.js +56 -0
  206. package/dist/source/models/manager.d.ts +15 -0
  207. package/dist/source/models/manager.js +48 -0
  208. package/dist/source/models/openai-provider.d.ts +22 -0
  209. package/dist/source/models/openai-provider.js +70 -0
  210. package/dist/source/models/openrouter-provider.d.ts +36 -0
  211. package/dist/source/models/openrouter-provider.js +276 -0
  212. package/dist/source/models/providers.d.ts +33 -0
  213. package/dist/source/models/providers.js +116 -0
  214. package/dist/source/models/xai-provider.d.ts +20 -0
  215. package/dist/source/models/xai-provider.js +47 -0
  216. package/dist/source/parsing.d.ts +2 -0
  217. package/dist/source/parsing.js +18 -0
  218. package/dist/source/prompts/manager.d.ts +19 -0
  219. package/dist/source/prompts/manager.js +71 -0
  220. package/dist/source/prompts.d.ts +4 -0
  221. package/dist/source/prompts.js +158 -0
  222. package/dist/source/repl-prompt.d.ts +14 -0
  223. package/dist/source/repl-prompt.js +147 -0
  224. package/dist/source/repl.d.ts +27 -0
  225. package/dist/source/repl.js +431 -0
  226. package/dist/source/terminal/formatting.d.ts +37 -0
  227. package/dist/source/terminal/formatting.js +106 -0
  228. package/dist/source/terminal/index.d.ts +94 -0
  229. package/dist/source/terminal/index.js +420 -0
  230. package/dist/source/terminal/markdown-utils.d.ts +2 -0
  231. package/dist/source/terminal/markdown-utils.js +81 -0
  232. package/dist/source/terminal/markdown.d.ts +1 -0
  233. package/dist/source/terminal/markdown.js +111 -0
  234. package/dist/source/terminal/types.d.ts +71 -0
  235. package/dist/source/terminal/types.js +1 -0
  236. package/dist/source/terminal-output.d.ts +8 -0
  237. package/dist/source/terminal-output.js +213 -0
  238. package/dist/source/terminal-output.test.d.ts +8 -0
  239. package/dist/source/terminal-output.test.js +213 -0
  240. package/dist/source/token-tracker.d.ts +14 -0
  241. package/dist/source/token-tracker.js +53 -0
  242. package/dist/source/token-utils.d.ts +7 -0
  243. package/dist/source/token-utils.js +13 -0
  244. package/dist/source/tools/agent.d.ts +17 -0
  245. package/dist/source/tools/agent.js +87 -0
  246. package/dist/source/tools/bash.d.ts +19 -0
  247. package/dist/source/tools/bash.js +294 -0
  248. package/dist/source/tools/code-interpreter.d.ts +12 -0
  249. package/dist/source/tools/code-interpreter.js +131 -0
  250. package/dist/source/tools/command-validation.d.ts +8 -0
  251. package/dist/source/tools/command-validation.js +69 -0
  252. package/dist/source/tools/delete-file.d.ts +12 -0
  253. package/dist/source/tools/delete-file.js +56 -0
  254. package/dist/source/tools/directory-tree.d.ts +12 -0
  255. package/dist/source/tools/directory-tree.js +38 -0
  256. package/dist/source/tools/edit-file.d.ts +19 -0
  257. package/dist/source/tools/edit-file.js +107 -0
  258. package/dist/source/tools/filesystem-utils.d.ts +22 -0
  259. package/dist/source/tools/filesystem-utils.js +191 -0
  260. package/dist/source/tools/git-utils.d.ts +14 -0
  261. package/dist/source/tools/git-utils.js +64 -0
  262. package/dist/source/tools/grep.d.ts +17 -0
  263. package/dist/source/tools/grep.js +138 -0
  264. package/dist/source/tools/index.d.ts +161 -0
  265. package/dist/source/tools/index.js +209 -0
  266. package/dist/source/tools/memory-read.d.ts +13 -0
  267. package/dist/source/tools/memory-read.js +135 -0
  268. package/dist/source/tools/memory-write.d.ts +12 -0
  269. package/dist/source/tools/memory-write.js +83 -0
  270. package/dist/source/tools/move-file.d.ts +13 -0
  271. package/dist/source/tools/move-file.js +44 -0
  272. package/dist/source/tools/read-file.d.ts +17 -0
  273. package/dist/source/tools/read-file.js +86 -0
  274. package/dist/source/tools/read-multiple-files.d.ts +14 -0
  275. package/dist/source/tools/read-multiple-files.js +55 -0
  276. package/dist/source/tools/save-file.d.ts +17 -0
  277. package/dist/source/tools/save-file.js +98 -0
  278. package/dist/source/tools/think.d.ts +11 -0
  279. package/dist/source/tools/think.js +45 -0
  280. package/dist/source/tools/types.d.ts +29 -0
  281. package/dist/source/tools/types.js +14 -0
  282. package/dist/source/tools/web-fetch.d.ts +47 -0
  283. package/dist/source/tools/web-fetch.js +246 -0
  284. package/dist/source/tools/web-search.d.ts +13 -0
  285. package/dist/source/tools/web-search.js +80 -0
  286. package/dist/source/utils/process.d.ts +36 -0
  287. package/dist/source/utils/process.js +75 -0
  288. package/dist/source/version.d.ts +1 -0
  289. package/dist/source/version.js +21 -0
  290. package/dist/terminal/formatting.d.ts +37 -0
  291. package/dist/terminal/formatting.js +106 -0
  292. package/dist/terminal/index.d.ts +94 -0
  293. package/dist/terminal/index.js +420 -0
  294. package/dist/terminal/markdown-utils.d.ts +2 -0
  295. package/dist/terminal/markdown-utils.js +81 -0
  296. package/dist/terminal/markdown.d.ts +1 -0
  297. package/dist/terminal/markdown.js +111 -0
  298. package/dist/terminal/types.d.ts +71 -0
  299. package/dist/terminal/types.js +1 -0
  300. package/dist/terminal-output.d.ts +8 -0
  301. package/dist/terminal-output.js +213 -0
  302. package/dist/token-tracker.d.ts +14 -0
  303. package/dist/token-tracker.js +53 -0
  304. package/dist/token-utils.d.ts +7 -0
  305. package/dist/token-utils.js +13 -0
  306. package/dist/tools/agent.d.ts +17 -0
  307. package/dist/tools/agent.js +87 -0
  308. package/dist/tools/bash.d.ts +19 -0
  309. package/dist/tools/bash.js +294 -0
  310. package/dist/tools/code-interpreter.d.ts +12 -0
  311. package/dist/tools/code-interpreter.js +131 -0
  312. package/dist/tools/command-validation.d.ts +8 -0
  313. package/dist/tools/command-validation.js +69 -0
  314. package/dist/tools/delete-file.d.ts +12 -0
  315. package/dist/tools/delete-file.js +56 -0
  316. package/dist/tools/directory-tree.d.ts +12 -0
  317. package/dist/tools/directory-tree.js +38 -0
  318. package/dist/tools/edit-file.d.ts +19 -0
  319. package/dist/tools/edit-file.js +107 -0
  320. package/dist/tools/filesystem-utils.d.ts +22 -0
  321. package/dist/tools/filesystem-utils.js +191 -0
  322. package/dist/tools/git-utils.d.ts +14 -0
  323. package/dist/tools/git-utils.js +64 -0
  324. package/dist/tools/grep.d.ts +17 -0
  325. package/dist/tools/grep.js +138 -0
  326. package/dist/tools/index.d.ts +161 -0
  327. package/dist/tools/index.js +209 -0
  328. package/dist/tools/memory-read.d.ts +13 -0
  329. package/dist/tools/memory-read.js +135 -0
  330. package/dist/tools/memory-write.d.ts +12 -0
  331. package/dist/tools/memory-write.js +83 -0
  332. package/dist/tools/move-file.d.ts +13 -0
  333. package/dist/tools/move-file.js +44 -0
  334. package/dist/tools/read-file.d.ts +17 -0
  335. package/dist/tools/read-file.js +86 -0
  336. package/dist/tools/read-multiple-files.d.ts +14 -0
  337. package/dist/tools/read-multiple-files.js +55 -0
  338. package/dist/tools/save-file.d.ts +17 -0
  339. package/dist/tools/save-file.js +98 -0
  340. package/dist/tools/think.d.ts +11 -0
  341. package/dist/tools/think.js +45 -0
  342. package/dist/tools/types.d.ts +29 -0
  343. package/dist/tools/types.js +14 -0
  344. package/dist/tools/web-fetch.d.ts +47 -0
  345. package/dist/tools/web-fetch.js +246 -0
  346. package/dist/tools/web-search.d.ts +13 -0
  347. package/dist/tools/web-search.js +80 -0
  348. package/dist/utils/process.d.ts +36 -0
  349. package/dist/utils/process.js +75 -0
  350. package/dist/version.d.ts +1 -0
  351. package/dist/version.js +21 -0
  352. package/knip.json +5 -0
  353. package/package.json +83 -0
  354. package/source/cli.ts +172 -0
  355. package/source/commands/application-log-command.ts +53 -0
  356. package/source/commands/clear-command.ts +14 -0
  357. package/source/commands/compact-command.ts +64 -0
  358. package/source/commands/copy-command.ts +55 -0
  359. package/source/commands/edit-command.ts +63 -0
  360. package/source/commands/edit-prompt-command.ts +31 -0
  361. package/source/commands/exit-command.ts +18 -0
  362. package/source/commands/files-command.ts +85 -0
  363. package/source/commands/generate-rules-command.ts +82 -0
  364. package/source/commands/help-command.ts +27 -0
  365. package/source/commands/init-command.ts +48 -0
  366. package/source/commands/last-log-command.ts +88 -0
  367. package/source/commands/manager.ts +151 -0
  368. package/source/commands/model-command.ts +123 -0
  369. package/source/commands/paste-command.ts +62 -0
  370. package/source/commands/prompt-command.ts +150 -0
  371. package/source/commands/reset-command.ts +22 -0
  372. package/source/commands/rules-command.ts +76 -0
  373. package/source/commands/save-command.ts +20 -0
  374. package/source/commands/types.ts +28 -0
  375. package/source/commands/usage-command.ts +26 -0
  376. package/source/config.ts +223 -0
  377. package/source/conversation-analyzer.ts +115 -0
  378. package/source/dedent.ts +53 -0
  379. package/source/formatting.ts +132 -0
  380. package/source/index.ts +240 -0
  381. package/source/logger.ts +29 -0
  382. package/source/mentions.ts +227 -0
  383. package/source/messages.ts +360 -0
  384. package/source/middleware/audit-message.ts +133 -0
  385. package/source/middleware/index.ts +2 -0
  386. package/source/middleware/rate-limit.ts +24 -0
  387. package/source/models/ai-config.ts +109 -0
  388. package/source/models/anthropic-provider.ts +199 -0
  389. package/source/models/deepseek-provider.ts +53 -0
  390. package/source/models/google-provider.ts +68 -0
  391. package/source/models/manager.ts +84 -0
  392. package/source/models/openai-provider.ts +81 -0
  393. package/source/models/openrouter-provider.ts +288 -0
  394. package/source/models/providers.ts +197 -0
  395. package/source/models/xai-provider.ts +59 -0
  396. package/source/parsing.ts +20 -0
  397. package/source/prompts/manager.ts +90 -0
  398. package/source/prompts.ts +172 -0
  399. package/source/repl-prompt.ts +196 -0
  400. package/source/repl.ts +572 -0
  401. package/source/terminal/formatting.ts +121 -0
  402. package/source/terminal/index.ts +518 -0
  403. package/source/terminal/markdown-utils.ts +89 -0
  404. package/source/terminal/markdown.ts +155 -0
  405. package/source/terminal/types.ts +84 -0
  406. package/source/terminal-output.test.ts +266 -0
  407. package/source/token-tracker.ts +78 -0
  408. package/source/token-utils.ts +17 -0
  409. package/source/tools/agent.ts +107 -0
  410. package/source/tools/bash.ts +367 -0
  411. package/source/tools/code-interpreter.ts +172 -0
  412. package/source/tools/command-validation.ts +81 -0
  413. package/source/tools/delete-file.ts +71 -0
  414. package/source/tools/directory-tree.ts +54 -0
  415. package/source/tools/edit-file.ts +155 -0
  416. package/source/tools/filesystem-utils.ts +265 -0
  417. package/source/tools/git-utils.ts +70 -0
  418. package/source/tools/grep.ts +184 -0
  419. package/source/tools/index.ts +278 -0
  420. package/source/tools/memory-read.ts +174 -0
  421. package/source/tools/memory-write.ts +105 -0
  422. package/source/tools/move-file.ts +59 -0
  423. package/source/tools/read-file.ts +129 -0
  424. package/source/tools/read-multiple-files.ts +80 -0
  425. package/source/tools/save-file.ts +147 -0
  426. package/source/tools/think.ts +51 -0
  427. package/source/tools/types.ts +58 -0
  428. package/source/tools/web-fetch.ts +327 -0
  429. package/source/tools/web-search.ts +101 -0
  430. package/source/utils/process.ts +121 -0
  431. package/source/version.ts +21 -0
  432. package/test/commands/copy-command.test.ts +69 -0
  433. package/test/config.test.ts +200 -0
  434. package/test/terminal/markdown-utils.test.ts +124 -0
  435. package/test/tools/bash-tool.test.ts +58 -0
  436. package/test/tools/code-interpreter.test.ts +91 -0
  437. package/test/tools/command-validation.test.ts +48 -0
  438. package/tsconfig.build.json +9 -0
  439. package/tsconfig.json +30 -0
@@ -0,0 +1,161 @@
1
+ import type { ModelManager } from "../models/manager.ts";
2
+ import type { Terminal } from "../terminal/index.ts";
3
+ import type { TokenTracker } from "../token-tracker.ts";
4
+ import type { TokenCounter } from "../token-utils.ts";
5
+ import type { Message } from "./types.ts";
6
+ export declare function initTools({ terminal, tokenCounter, events, autoAcceptAll, }: {
7
+ terminal: Terminal;
8
+ tokenCounter: TokenCounter;
9
+ events: Map<string, Message[]>;
10
+ autoAcceptAll: boolean;
11
+ }): Promise<{
12
+ readonly memoryWrite: import("ai").Tool<{
13
+ filePath: string;
14
+ content: string;
15
+ }, string>;
16
+ readonly memoryRead: import("ai").Tool<{
17
+ filePath: string | null;
18
+ }, string | {
19
+ content: string;
20
+ }>;
21
+ readonly webSearch: import("ai").Tool<{
22
+ query: string;
23
+ }, string>;
24
+ readonly bash: import("ai").Tool<{
25
+ cwd: string | null;
26
+ timeout: number | null;
27
+ command: string;
28
+ }, string>;
29
+ readonly webFetch: import("ai").Tool<{
30
+ url: string;
31
+ }, string>;
32
+ readonly think: import("ai").Tool<{
33
+ thought: string;
34
+ }, string>;
35
+ readonly grepFiles: import("ai").Tool<{
36
+ path: string;
37
+ pattern: string;
38
+ recursive: boolean | null;
39
+ ignoreCase: boolean | null;
40
+ filePattern: string | null;
41
+ contextLines: number | null;
42
+ searchIgnored: boolean | null;
43
+ }, string>;
44
+ readonly codeInterpreter: import("ai").Tool<{
45
+ code: string;
46
+ timeoutSeconds: number | null;
47
+ }, string>;
48
+ readonly deleteFile: import("ai").Tool<{
49
+ path: string;
50
+ }, string>;
51
+ readonly directoryTree: import("ai").Tool<{
52
+ path: string;
53
+ }, string>;
54
+ readonly moveFile: import("ai").Tool<{
55
+ source: string;
56
+ destination: string;
57
+ }, string>;
58
+ readonly saveFile: import("ai").Tool<{
59
+ path: string;
60
+ content: string;
61
+ encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
62
+ }, string>;
63
+ readonly editFile: import("ai").Tool<{
64
+ path: string;
65
+ edits: {
66
+ oldText: string;
67
+ newText: string;
68
+ }[];
69
+ }, string>;
70
+ readonly readMultipleFiles: import("ai").Tool<{
71
+ paths: string[];
72
+ }, string>;
73
+ readonly readFile: import("ai").Tool<{
74
+ path: string;
75
+ encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
76
+ startLine: number | null;
77
+ lineCount: number | null;
78
+ }, string>;
79
+ }>;
80
+ export declare function initCliTools({ tokenCounter, }: {
81
+ tokenCounter: TokenCounter;
82
+ }): Promise<{
83
+ readonly memoryWrite: import("ai").Tool<{
84
+ filePath: string;
85
+ content: string;
86
+ }, string>;
87
+ readonly memoryRead: import("ai").Tool<{
88
+ filePath: string | null;
89
+ }, string | {
90
+ content: string;
91
+ }>;
92
+ readonly webSearch: import("ai").Tool<{
93
+ query: string;
94
+ }, string>;
95
+ readonly bash: import("ai").Tool<{
96
+ cwd: string | null;
97
+ timeout: number | null;
98
+ command: string;
99
+ }, string>;
100
+ readonly webFetch: import("ai").Tool<{
101
+ url: string;
102
+ }, string>;
103
+ readonly think: import("ai").Tool<{
104
+ thought: string;
105
+ }, string>;
106
+ readonly grepFiles: import("ai").Tool<{
107
+ path: string;
108
+ pattern: string;
109
+ recursive: boolean | null;
110
+ ignoreCase: boolean | null;
111
+ filePattern: string | null;
112
+ contextLines: number | null;
113
+ searchIgnored: boolean | null;
114
+ }, string>;
115
+ readonly codeInterpreter: import("ai").Tool<{
116
+ code: string;
117
+ timeoutSeconds: number | null;
118
+ }, string>;
119
+ readonly deleteFile: import("ai").Tool<{
120
+ path: string;
121
+ }, string>;
122
+ readonly directoryTree: import("ai").Tool<{
123
+ path: string;
124
+ }, string>;
125
+ readonly moveFile: import("ai").Tool<{
126
+ source: string;
127
+ destination: string;
128
+ }, string>;
129
+ readonly saveFile: import("ai").Tool<{
130
+ path: string;
131
+ content: string;
132
+ encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
133
+ }, string>;
134
+ readonly editFile: import("ai").Tool<{
135
+ path: string;
136
+ edits: {
137
+ oldText: string;
138
+ newText: string;
139
+ }[];
140
+ }, string>;
141
+ readonly readMultipleFiles: import("ai").Tool<{
142
+ paths: string[];
143
+ }, string>;
144
+ readonly readFile: import("ai").Tool<{
145
+ path: string;
146
+ encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
147
+ startLine: number | null;
148
+ lineCount: number | null;
149
+ }, string>;
150
+ }>;
151
+ export declare function initAgents({ modelManager, tokenTracker, tokenCounter, events, }: {
152
+ terminal: Terminal;
153
+ modelManager: ModelManager;
154
+ tokenTracker: TokenTracker;
155
+ tokenCounter: TokenCounter;
156
+ events: Map<string, Message[]>;
157
+ }): Promise<{
158
+ agent: import("ai").Tool<{
159
+ prompt: string;
160
+ }, string>;
161
+ }>;
@@ -0,0 +1,209 @@
1
+ import { createAgentTools } from "./agent.js";
2
+ import { createBashTool } from "./bash.js";
3
+ import { createCodeInterpreterTool } from "./code-interpreter.js";
4
+ import { createDeleteFileTool } from "./delete-file.js";
5
+ import { createDirectoryTreeTool } from "./directory-tree.js";
6
+ import { createEditFileTool } from "./edit-file.js";
7
+ import { createGrepTool } from "./grep.js";
8
+ import { createMemoryReadTool } from "./memory-read.js";
9
+ import { createMemoryWriteTool } from "./memory-write.js";
10
+ import { createMoveFileTool } from "./move-file.js";
11
+ import { createReadFileTool } from "./read-file.js";
12
+ import { createReadMultipleFilesTool } from "./read-multiple-files.js";
13
+ import { createSaveFileTool } from "./save-file.js";
14
+ import { createThinkTool } from "./think.js";
15
+ import { createWebFetchTool } from "./web-fetch.js";
16
+ import { createWebSearchTool } from "./web-search.js";
17
+ const sendDataHandler = (events) => {
18
+ const msgStore = events;
19
+ return (msg) => {
20
+ if (msgStore.has(msg.id)) {
21
+ msgStore.get(msg.id)?.push(msg);
22
+ }
23
+ else {
24
+ msgStore.set(msg.id, [msg]);
25
+ }
26
+ };
27
+ };
28
+ export async function initTools({ terminal, tokenCounter, events, autoAcceptAll, }) {
29
+ const sendDataFn = sendDataHandler(events);
30
+ const readFileTool = await createReadFileTool({
31
+ workingDir: process.cwd(),
32
+ sendData: sendDataFn,
33
+ tokenCounter,
34
+ });
35
+ const readMultipleFilesTool = await createReadMultipleFilesTool({
36
+ workingDir: process.cwd(),
37
+ sendData: sendDataFn,
38
+ tokenCounter,
39
+ });
40
+ const editFileTool = await createEditFileTool({
41
+ workingDir: process.cwd(),
42
+ terminal,
43
+ sendData: sendDataFn,
44
+ autoAcceptAll,
45
+ });
46
+ const saveFileTool = await createSaveFileTool({
47
+ workingDir: process.cwd(),
48
+ sendData: sendDataFn,
49
+ terminal,
50
+ autoAcceptAll,
51
+ });
52
+ const moveFileTool = await createMoveFileTool({
53
+ workingDir: process.cwd(),
54
+ sendData: sendDataFn,
55
+ });
56
+ const directoryTreeTool = await createDirectoryTreeTool({
57
+ workingDir: process.cwd(),
58
+ sendData: sendDataFn,
59
+ });
60
+ const deleteFileTool = await createDeleteFileTool({
61
+ workingDir: process.cwd(),
62
+ sendData: sendDataFn,
63
+ });
64
+ const codeInterpreterTool = createCodeInterpreterTool({
65
+ sendData: sendDataFn,
66
+ });
67
+ const grepTool = createGrepTool({
68
+ sendData: sendDataFn,
69
+ });
70
+ const thinkTool = createThinkTool({
71
+ sendData: sendDataFn,
72
+ });
73
+ const webFetchTool = createWebFetchTool({
74
+ sendData: sendDataFn,
75
+ tokenCounter,
76
+ });
77
+ const webSearchTool = createWebSearchTool({
78
+ sendData: sendDataFn,
79
+ tokenCounter,
80
+ });
81
+ const bashTool = createBashTool({
82
+ baseDir: process.cwd(),
83
+ sendData: sendDataFn,
84
+ tokenCounter,
85
+ terminal,
86
+ autoAcceptAll,
87
+ });
88
+ const memoryReadTool = createMemoryReadTool({
89
+ sendData: sendDataFn,
90
+ });
91
+ const memoryWriteTool = createMemoryWriteTool({
92
+ sendData: sendDataFn,
93
+ });
94
+ const tools = {
95
+ ...readFileTool,
96
+ ...readMultipleFilesTool,
97
+ ...editFileTool,
98
+ ...saveFileTool,
99
+ ...moveFileTool,
100
+ ...directoryTreeTool,
101
+ ...deleteFileTool,
102
+ ...codeInterpreterTool,
103
+ ...grepTool,
104
+ ...thinkTool,
105
+ ...webFetchTool,
106
+ ...bashTool,
107
+ ...webSearchTool,
108
+ ...memoryReadTool,
109
+ ...memoryWriteTool,
110
+ };
111
+ return tools;
112
+ }
113
+ export async function initCliTools({ tokenCounter, }) {
114
+ const readFileTool = await createReadFileTool({
115
+ workingDir: process.cwd(),
116
+ sendData: undefined,
117
+ tokenCounter,
118
+ });
119
+ const readMultipleFilesTool = await createReadMultipleFilesTool({
120
+ workingDir: process.cwd(),
121
+ sendData: undefined,
122
+ tokenCounter,
123
+ });
124
+ const editFileTool = await createEditFileTool({
125
+ workingDir: process.cwd(),
126
+ terminal: undefined,
127
+ sendData: undefined,
128
+ autoAcceptAll: true,
129
+ });
130
+ const saveFileTool = await createSaveFileTool({
131
+ workingDir: process.cwd(),
132
+ sendData: undefined,
133
+ terminal: undefined,
134
+ autoAcceptAll: true,
135
+ });
136
+ const moveFileTool = await createMoveFileTool({
137
+ workingDir: process.cwd(),
138
+ sendData: undefined,
139
+ });
140
+ const directoryTreeTool = await createDirectoryTreeTool({
141
+ workingDir: process.cwd(),
142
+ sendData: undefined,
143
+ });
144
+ const deleteFileTool = await createDeleteFileTool({
145
+ workingDir: process.cwd(),
146
+ sendData: undefined,
147
+ });
148
+ const codeInterpreterTool = createCodeInterpreterTool({
149
+ sendData: undefined,
150
+ });
151
+ const grepTool = createGrepTool({
152
+ sendData: undefined,
153
+ });
154
+ const thinkTool = createThinkTool({
155
+ sendData: undefined,
156
+ });
157
+ const webFetchTool = createWebFetchTool({
158
+ sendData: undefined,
159
+ tokenCounter,
160
+ });
161
+ const webSearchTool = createWebSearchTool({
162
+ sendData: undefined,
163
+ tokenCounter,
164
+ });
165
+ const bashTool = createBashTool({
166
+ baseDir: process.cwd(),
167
+ sendData: undefined,
168
+ tokenCounter,
169
+ terminal: undefined,
170
+ autoAcceptAll: true,
171
+ });
172
+ const memoryReadTool = createMemoryReadTool({
173
+ sendData: undefined,
174
+ });
175
+ const memoryWriteTool = createMemoryWriteTool({
176
+ sendData: undefined,
177
+ });
178
+ const tools = {
179
+ ...readFileTool,
180
+ ...readMultipleFilesTool,
181
+ ...editFileTool,
182
+ ...saveFileTool,
183
+ ...moveFileTool,
184
+ ...directoryTreeTool,
185
+ ...deleteFileTool,
186
+ ...codeInterpreterTool,
187
+ ...grepTool,
188
+ ...thinkTool,
189
+ ...webFetchTool,
190
+ ...bashTool,
191
+ ...webSearchTool,
192
+ ...memoryReadTool,
193
+ ...memoryWriteTool,
194
+ };
195
+ return tools;
196
+ }
197
+ export async function initAgents({ modelManager, tokenTracker, tokenCounter, events, }) {
198
+ const sendDataFn = sendDataHandler(events);
199
+ const agentTools = createAgentTools({
200
+ modelManager,
201
+ tokenTracker,
202
+ tokenCounter,
203
+ sendData: sendDataFn,
204
+ });
205
+ const tools = {
206
+ ...agentTools,
207
+ };
208
+ return tools;
209
+ }
@@ -0,0 +1,13 @@
1
+ import type { SendData } from "./types.ts";
2
+ export declare const MemoryReadTool: {
3
+ name: "memoryRead";
4
+ };
5
+ export declare const createMemoryReadTool: (options?: {
6
+ sendData?: SendData | undefined;
7
+ }) => {
8
+ memoryRead: import("ai").Tool<{
9
+ filePath: string | null;
10
+ }, string | {
11
+ content: string;
12
+ }>;
13
+ };
@@ -0,0 +1,135 @@
1
+ import { access, lstat, mkdir, readdir, readFile } from "node:fs/promises";
2
+ import { isAbsolute, join, normalize, resolve, sep } from "node:path";
3
+ import { tool } from "ai";
4
+ import { z } from "zod";
5
+ import { config } from "../config.js";
6
+ export const MemoryReadTool = {
7
+ name: "memoryRead",
8
+ };
9
+ const MEMORY_DIR = config.app.ensurePathSync("memory");
10
+ // Helper to check if a file exists
11
+ // Moved to module level as it does not use sendData
12
+ async function fileExists(filePath) {
13
+ try {
14
+ await access(filePath);
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ // Helper function, does not use sendData directly
22
+ const _readSpecificMemoryFile = async (resolvedMemoryDir, filePath) => {
23
+ const normalizedRelativePath = normalize(filePath);
24
+ if (normalizedRelativePath.startsWith("..") ||
25
+ normalizedRelativePath.includes("..") ||
26
+ isAbsolute(normalizedRelativePath)) {
27
+ throw new Error(`Error: Invalid filePath "${filePath}". Must be a relative path and cannot use '..'.`);
28
+ }
29
+ const fullPath = join(resolvedMemoryDir, normalizedRelativePath);
30
+ if (!fullPath.startsWith(resolvedMemoryDir + sep) &&
31
+ fullPath !== resolvedMemoryDir) {
32
+ throw new Error(`Error: Path "${filePath}" resolves outside the allowed memory directory.`);
33
+ }
34
+ if (!(await fileExists(fullPath))) {
35
+ throw new Error(`Error: Memory file '${filePath}' does not exist.`);
36
+ }
37
+ const stats = await lstat(fullPath);
38
+ if (stats.isDirectory()) {
39
+ throw new Error(`Error: '${filePath}' is a directory. Please provide a path to a file to read.`);
40
+ }
41
+ const content = await readFile(fullPath, "utf-8");
42
+ return { filePath, content };
43
+ };
44
+ // Helper function, does not use sendData directly
45
+ const _listMemoryFilesAndIndex = async (resolvedMemoryDir) => {
46
+ const entries = await readdir(resolvedMemoryDir, {
47
+ recursive: true,
48
+ withFileTypes: true,
49
+ });
50
+ const filesOnly = entries
51
+ .filter((entry) => entry.isFile())
52
+ .map((entry) => join(entry.parentPath ?? resolvedMemoryDir, entry.name)); // entry.path is available with recursive
53
+ const fileListString = filesOnly.length > 0
54
+ ? filesOnly
55
+ .map((p) => `- ${normalize(p.replace(resolvedMemoryDir + sep, ""))}`)
56
+ .join("\n") // Show relative paths
57
+ : "No files in memory.";
58
+ const indexPath = join(resolvedMemoryDir, "index.md");
59
+ let indexContent = "(empty)";
60
+ if (await fileExists(indexPath)) {
61
+ const stats = await lstat(indexPath);
62
+ if (stats.isFile()) {
63
+ indexContent = await readFile(indexPath, "utf-8");
64
+ }
65
+ }
66
+ const output = `Root memory file (index.md):
67
+ '''
68
+ ${indexContent}
69
+ '''
70
+
71
+ Files in the memory directory:
72
+ ${fileListString}`;
73
+ return { content: output };
74
+ };
75
+ export const createMemoryReadTool = (options = {}) => {
76
+ const { sendData } = options;
77
+ const memoryReadTool = tool({
78
+ description: 'Read from memory files. If no path is provided, lists all files and shows content of "index.md".',
79
+ inputSchema: z.object({
80
+ filePath: z
81
+ .string()
82
+ .nullable()
83
+ .describe('Optional path to a specific memory file to read, relative to the memory directory. Cannot use ".." or absolute paths.'),
84
+ }),
85
+ execute: async ({ filePath }, { toolCallId }) => {
86
+ sendData?.({
87
+ event: "tool-init",
88
+ id: toolCallId,
89
+ data: "Initializing memory read...",
90
+ });
91
+ const resolvedMemoryDir = resolve(MEMORY_DIR);
92
+ try {
93
+ await mkdir(resolvedMemoryDir, { recursive: true });
94
+ let result;
95
+ if (filePath) {
96
+ sendData?.({
97
+ event: "tool-update",
98
+ id: toolCallId,
99
+ data: { primary: "Reading file:", secondary: [filePath] },
100
+ });
101
+ result = await _readSpecificMemoryFile(resolvedMemoryDir, filePath);
102
+ }
103
+ else {
104
+ sendData?.({
105
+ event: "tool-update",
106
+ id: toolCallId,
107
+ data: { primary: "Listing memory files and index" },
108
+ });
109
+ result = await _listMemoryFilesAndIndex(resolvedMemoryDir);
110
+ }
111
+ sendData?.({
112
+ event: "tool-completion",
113
+ id: toolCallId,
114
+ data: "Done",
115
+ });
116
+ return result;
117
+ }
118
+ catch (error) {
119
+ let errorMsg = "Error reading memory: An unknown error occurred";
120
+ if (error instanceof Error) {
121
+ errorMsg = `Error reading memory: ${error.message}`;
122
+ }
123
+ sendData?.({
124
+ event: "tool-error",
125
+ id: toolCallId,
126
+ data: errorMsg,
127
+ });
128
+ return errorMsg;
129
+ }
130
+ },
131
+ });
132
+ return {
133
+ [MemoryReadTool.name]: memoryReadTool,
134
+ };
135
+ };
@@ -0,0 +1,12 @@
1
+ import type { SendData } from "./types.ts";
2
+ export declare const MemoryWriteTool: {
3
+ name: "memoryWrite";
4
+ };
5
+ export declare const createMemoryWriteTool: (options?: {
6
+ sendData?: SendData | undefined;
7
+ }) => {
8
+ memoryWrite: import("ai").Tool<{
9
+ filePath: string;
10
+ content: string;
11
+ }, string>;
12
+ };
@@ -0,0 +1,83 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
3
+ import { tool } from "ai";
4
+ import { z } from "zod";
5
+ import { config } from "../config.js";
6
+ export const MemoryWriteTool = {
7
+ name: "memoryWrite",
8
+ };
9
+ const MEMORY_DIR = config.app.ensurePathSync("memory");
10
+ export const createMemoryWriteTool = (options = {}) => {
11
+ const { sendData } = options;
12
+ const memoryWriteTool = tool({
13
+ description: "Write content to a memory file.",
14
+ inputSchema: z.object({
15
+ filePath: z
16
+ .string()
17
+ .describe('Path to the memory file, relative to the memory directory. Cannot use ".." or absolute paths.'),
18
+ content: z.string().describe("Content to write to the file."),
19
+ }),
20
+ execute: async ({ filePath, content }, { toolCallId }) => {
21
+ sendData?.({
22
+ event: "tool-init",
23
+ id: toolCallId,
24
+ data: "Initializing memory write...",
25
+ });
26
+ const resolvedMemoryDir = resolve(MEMORY_DIR);
27
+ const normalizedRelativePath = normalize(filePath);
28
+ if (normalizedRelativePath.startsWith("..") ||
29
+ normalizedRelativePath.includes("..") ||
30
+ isAbsolute(normalizedRelativePath)) {
31
+ const errorMsg = `Error: Invalid filePath "${filePath}". Must be a relative path within the memory directory and cannot use '..'.`;
32
+ sendData?.({
33
+ event: "tool-error",
34
+ id: toolCallId,
35
+ data: errorMsg,
36
+ });
37
+ return errorMsg;
38
+ }
39
+ const fullPath = join(resolvedMemoryDir, normalizedRelativePath);
40
+ if (!fullPath.startsWith(resolvedMemoryDir + sep) &&
41
+ fullPath !== resolvedMemoryDir) {
42
+ const errorMsg = `Error: Path "${filePath}" resolves outside the allowed memory directory.`;
43
+ sendData?.({
44
+ event: "tool-error",
45
+ id: toolCallId,
46
+ data: errorMsg,
47
+ });
48
+ return errorMsg;
49
+ }
50
+ sendData?.({
51
+ event: "tool-update",
52
+ id: toolCallId,
53
+ data: { primary: "Writing to file:", secondary: [filePath] },
54
+ });
55
+ try {
56
+ await mkdir(dirname(fullPath), { recursive: true });
57
+ await writeFile(fullPath, content, "utf-8");
58
+ const successMsg = `Memory file '${filePath}' written successfully.`;
59
+ sendData?.({
60
+ event: "tool-completion",
61
+ id: toolCallId,
62
+ data: successMsg,
63
+ });
64
+ return successMsg;
65
+ }
66
+ catch (error) {
67
+ let errorMsg = `Error writing memory file '${filePath}': An unknown error occurred`;
68
+ if (error instanceof Error) {
69
+ errorMsg = `Error writing memory file '${filePath}': ${error.message}`;
70
+ }
71
+ sendData?.({
72
+ event: "tool-error",
73
+ id: toolCallId,
74
+ data: errorMsg,
75
+ });
76
+ return errorMsg;
77
+ }
78
+ },
79
+ });
80
+ return {
81
+ [MemoryWriteTool.name]: memoryWriteTool,
82
+ };
83
+ };
@@ -0,0 +1,13 @@
1
+ import type { SendData } from "./types.ts";
2
+ export declare const MoveFileTool: {
3
+ name: "moveFile";
4
+ };
5
+ export declare const createMoveFileTool: ({ workingDir, sendData, }: {
6
+ workingDir: string;
7
+ sendData?: SendData;
8
+ }) => Promise<{
9
+ moveFile: import("ai").Tool<{
10
+ source: string;
11
+ destination: string;
12
+ }, string>;
13
+ }>;
@@ -0,0 +1,44 @@
1
+ import fs from "node:fs/promises";
2
+ import { tool } from "ai";
3
+ import chalk from "chalk";
4
+ import { z } from "zod";
5
+ import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
6
+ export const MoveFileTool = {
7
+ name: "moveFile",
8
+ };
9
+ export const createMoveFileTool = async ({ workingDir, sendData, }) => {
10
+ const allowedDirectory = workingDir;
11
+ return {
12
+ [MoveFileTool.name]: tool({
13
+ description: "Move or rename files and directories. Can move files between directories " +
14
+ "and rename them in a single operation. If the destination exists, the " +
15
+ "operation will fail. Works across different directories and can be used " +
16
+ "for simple renaming within the same directory. Both source and destination must be within allowed directories.",
17
+ inputSchema: z.object({
18
+ source: z.string(),
19
+ destination: z.string(),
20
+ }),
21
+ execute: async ({ source, destination }, { toolCallId }) => {
22
+ try {
23
+ sendData?.({
24
+ id: toolCallId,
25
+ event: "tool-init",
26
+ data: `Moving file from ${chalk.cyan(source)} to ${chalk.cyan(destination)}`,
27
+ });
28
+ const validSourcePath = await validatePath(joinWorkingDir(source, workingDir), allowedDirectory);
29
+ const validDestPath = await validatePath(joinWorkingDir(destination, workingDir), allowedDirectory);
30
+ await fs.rename(validSourcePath, validDestPath);
31
+ sendData?.({
32
+ id: toolCallId,
33
+ event: "tool-completion",
34
+ data: "Done",
35
+ });
36
+ return `Successfully moved ${source} to ${destination}`;
37
+ }
38
+ catch (error) {
39
+ return `Failed to move file: ${error.message}`;
40
+ }
41
+ },
42
+ }),
43
+ };
44
+ };
@@ -0,0 +1,17 @@
1
+ import type { TokenCounter } from "../token-utils.ts";
2
+ import type { SendData } from "./types.ts";
3
+ export declare const ReadFileTool: {
4
+ name: "readFile";
5
+ };
6
+ export declare const createReadFileTool: ({ workingDir, sendData, tokenCounter, }: {
7
+ workingDir: string;
8
+ sendData?: SendData;
9
+ tokenCounter: TokenCounter;
10
+ }) => Promise<{
11
+ readFile: import("ai").Tool<{
12
+ path: string;
13
+ encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
14
+ startLine: number | null;
15
+ lineCount: number | null;
16
+ }, string>;
17
+ }>;