@travisennis/acai 0.0.1 → 0.0.3

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 (324) hide show
  1. package/README.md +3 -4
  2. package/dist/commands/health-command.d.ts +2 -0
  3. package/dist/commands/health-command.js +59 -0
  4. package/dist/commands/manager.js +2 -0
  5. package/dist/commands/paste-command.d.ts +1 -1
  6. package/dist/commands/paste-command.js +155 -11
  7. package/dist/commands/reset-command.js +1 -0
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.js +2 -1
  10. package/dist/models/openrouter-provider.d.ts +4 -1
  11. package/dist/models/openrouter-provider.js +46 -4
  12. package/dist/models/providers.d.ts +1 -1
  13. package/dist/prompts/manager.d.ts +1 -0
  14. package/dist/prompts/manager.js +10 -0
  15. package/dist/prompts.js +8 -6
  16. package/dist/repl.js +49 -26
  17. package/dist/terminal/formatting.d.ts +16 -5
  18. package/dist/terminal/formatting.js +40 -6
  19. package/dist/terminal/index.d.ts +1 -1
  20. package/dist/terminal/index.js +54 -14
  21. package/dist/terminal/markdown.js +0 -1
  22. package/dist/terminal/supports-color.d.ts +16 -0
  23. package/dist/terminal/supports-color.js +121 -0
  24. package/dist/terminal/supports-hyperlinks.d.ts +7 -0
  25. package/dist/terminal/supports-hyperlinks.js +98 -0
  26. package/dist/tools/bash.js +95 -117
  27. package/dist/tools/code-interpreter.js +11 -1
  28. package/dist/tools/command-validation.d.ts +7 -3
  29. package/dist/tools/command-validation.js +67 -23
  30. package/dist/tools/delete-file.d.ts +4 -1
  31. package/dist/tools/delete-file.js +47 -3
  32. package/dist/tools/git-utils.d.ts +6 -0
  33. package/dist/tools/git-utils.js +89 -12
  34. package/dist/tools/grep.d.ts +20 -0
  35. package/dist/tools/grep.js +128 -40
  36. package/dist/tools/index.d.ts +2 -18
  37. package/dist/tools/index.js +4 -18
  38. package/package.json +30 -20
  39. package/.acai/acai.json +0 -9
  40. package/.acai/prompts/add-openrouter-model.md +0 -13
  41. package/.acai/prompts/project-status.md +0 -4
  42. package/.acai/prompts/update-architecture-document.md +0 -9
  43. package/.acai/rules/learned-rules.md +0 -9
  44. package/.ai/docs/available-tools.txt +0 -3
  45. package/.ai/docs/cognitive_complexity_refactoring_progress.md +0 -65
  46. package/.ai/docs/deleted_tools.md +0 -168
  47. package/.ai/docs/deleted_tools_88ced9ef.md +0 -56
  48. package/.ai/docs/image-pasting.md +0 -46
  49. package/.ai/docs/initialize-app.md +0 -117
  50. package/.ai/docs/issue-4-plan.md +0 -44
  51. package/.ai/docs/marked-renderer-debug.md +0 -15
  52. package/.ai/docs/marked-renderer-refactor-plan.md +0 -64
  53. package/.ai/docs/memory-use-cases.md +0 -55
  54. package/.ai/docs/prompt-consistency.md +0 -31
  55. package/.ai/docs/refactoring-tools.md +0 -98
  56. package/.ai/docs/system-prompt-update.md +0 -174
  57. package/.ai/docs/system_prompt.txt +0 -210
  58. package/.ai/docs/tasks.md +0 -49
  59. package/.ai/plan.md +0 -131
  60. package/.ai/prompt.md +0 -1
  61. package/.ai/scripts/fetch_models.js +0 -27
  62. package/.ai/scripts/generateSystemPrompt.ts +0 -15
  63. package/.ai/scripts/list-tools.mjs +0 -4
  64. package/.ai/scripts/p5_geometric_shapes.js +0 -149
  65. package/.husky/commit-msg +0 -1
  66. package/.husky/pre-commit +0 -3
  67. package/.husky/pre-push +0 -1
  68. package/.ignore +0 -4
  69. package/AGENTS.md +0 -25
  70. package/ARCHITECTURE.md +0 -304
  71. package/TODO.md +0 -2
  72. package/biome.json +0 -61
  73. package/commitlint.config.js +0 -3
  74. package/dist/source/cli.d.ts +0 -19
  75. package/dist/source/cli.js +0 -116
  76. package/dist/source/commands/application-log-command.d.ts +0 -2
  77. package/dist/source/commands/application-log-command.js +0 -43
  78. package/dist/source/commands/clear-command.d.ts +0 -2
  79. package/dist/source/commands/clear-command.js +0 -12
  80. package/dist/source/commands/compact-command.d.ts +0 -2
  81. package/dist/source/commands/compact-command.js +0 -51
  82. package/dist/source/commands/copy-command.d.ts +0 -2
  83. package/dist/source/commands/copy-command.js +0 -51
  84. package/dist/source/commands/edit-command.d.ts +0 -2
  85. package/dist/source/commands/edit-command.js +0 -53
  86. package/dist/source/commands/edit-prompt-command.d.ts +0 -2
  87. package/dist/source/commands/edit-prompt-command.js +0 -25
  88. package/dist/source/commands/exit-command.d.ts +0 -2
  89. package/dist/source/commands/exit-command.js +0 -14
  90. package/dist/source/commands/files-command.d.ts +0 -2
  91. package/dist/source/commands/files-command.js +0 -63
  92. package/dist/source/commands/generate-rules-command.d.ts +0 -2
  93. package/dist/source/commands/generate-rules-command.js +0 -61
  94. package/dist/source/commands/help-command.d.ts +0 -2
  95. package/dist/source/commands/help-command.js +0 -19
  96. package/dist/source/commands/init-command.d.ts +0 -2
  97. package/dist/source/commands/init-command.js +0 -40
  98. package/dist/source/commands/last-log-command.d.ts +0 -2
  99. package/dist/source/commands/last-log-command.js +0 -76
  100. package/dist/source/commands/manager.d.ts +0 -22
  101. package/dist/source/commands/manager.js +0 -123
  102. package/dist/source/commands/model-command.d.ts +0 -2
  103. package/dist/source/commands/model-command.js +0 -84
  104. package/dist/source/commands/paste-command.d.ts +0 -2
  105. package/dist/source/commands/paste-command.js +0 -40
  106. package/dist/source/commands/prompt-command.d.ts +0 -2
  107. package/dist/source/commands/prompt-command.js +0 -111
  108. package/dist/source/commands/reset-command.d.ts +0 -2
  109. package/dist/source/commands/reset-command.js +0 -16
  110. package/dist/source/commands/rules-command.d.ts +0 -2
  111. package/dist/source/commands/rules-command.js +0 -68
  112. package/dist/source/commands/save-command.d.ts +0 -2
  113. package/dist/source/commands/save-command.js +0 -14
  114. package/dist/source/commands/types.d.ts +0 -26
  115. package/dist/source/commands/types.js +0 -1
  116. package/dist/source/commands/usage-command.d.ts +0 -2
  117. package/dist/source/commands/usage-command.js +0 -21
  118. package/dist/source/config.d.ts +0 -60
  119. package/dist/source/config.js +0 -193
  120. package/dist/source/conversation-analyzer.d.ts +0 -10
  121. package/dist/source/conversation-analyzer.js +0 -88
  122. package/dist/source/dedent.d.ts +0 -3
  123. package/dist/source/dedent.js +0 -38
  124. package/dist/source/formatting.d.ts +0 -17
  125. package/dist/source/formatting.js +0 -103
  126. package/dist/source/index.d.ts +0 -18
  127. package/dist/source/index.js +0 -213
  128. package/dist/source/logger.d.ts +0 -2
  129. package/dist/source/logger.js +0 -24
  130. package/dist/source/mentions.d.ts +0 -9
  131. package/dist/source/mentions.js +0 -182
  132. package/dist/source/messages.d.ts +0 -69
  133. package/dist/source/messages.js +0 -261
  134. package/dist/source/middleware/audit-message.d.ts +0 -5
  135. package/dist/source/middleware/audit-message.js +0 -95
  136. package/dist/source/middleware/index.d.ts +0 -2
  137. package/dist/source/middleware/index.js +0 -2
  138. package/dist/source/middleware/rate-limit.d.ts +0 -4
  139. package/dist/source/middleware/rate-limit.js +0 -17
  140. package/dist/source/models/ai-config.d.ts +0 -12
  141. package/dist/source/models/ai-config.js +0 -87
  142. package/dist/source/models/anthropic-provider.d.ts +0 -25
  143. package/dist/source/models/anthropic-provider.js +0 -184
  144. package/dist/source/models/deepseek-provider.d.ts +0 -20
  145. package/dist/source/models/deepseek-provider.js +0 -42
  146. package/dist/source/models/google-provider.d.ts +0 -19
  147. package/dist/source/models/google-provider.js +0 -56
  148. package/dist/source/models/manager.d.ts +0 -15
  149. package/dist/source/models/manager.js +0 -48
  150. package/dist/source/models/openai-provider.d.ts +0 -22
  151. package/dist/source/models/openai-provider.js +0 -70
  152. package/dist/source/models/openrouter-provider.d.ts +0 -36
  153. package/dist/source/models/openrouter-provider.js +0 -276
  154. package/dist/source/models/providers.d.ts +0 -33
  155. package/dist/source/models/providers.js +0 -116
  156. package/dist/source/models/xai-provider.d.ts +0 -20
  157. package/dist/source/models/xai-provider.js +0 -47
  158. package/dist/source/parsing.d.ts +0 -2
  159. package/dist/source/parsing.js +0 -18
  160. package/dist/source/prompts/manager.d.ts +0 -19
  161. package/dist/source/prompts/manager.js +0 -71
  162. package/dist/source/prompts.d.ts +0 -4
  163. package/dist/source/prompts.js +0 -158
  164. package/dist/source/repl-prompt.d.ts +0 -14
  165. package/dist/source/repl-prompt.js +0 -147
  166. package/dist/source/repl.d.ts +0 -27
  167. package/dist/source/repl.js +0 -431
  168. package/dist/source/terminal/formatting.d.ts +0 -37
  169. package/dist/source/terminal/formatting.js +0 -106
  170. package/dist/source/terminal/index.d.ts +0 -94
  171. package/dist/source/terminal/index.js +0 -420
  172. package/dist/source/terminal/markdown-utils.d.ts +0 -2
  173. package/dist/source/terminal/markdown-utils.js +0 -81
  174. package/dist/source/terminal/markdown.d.ts +0 -1
  175. package/dist/source/terminal/markdown.js +0 -111
  176. package/dist/source/terminal/types.d.ts +0 -71
  177. package/dist/source/terminal/types.js +0 -1
  178. package/dist/source/terminal-output.d.ts +0 -8
  179. package/dist/source/terminal-output.js +0 -213
  180. package/dist/source/terminal-output.test.d.ts +0 -8
  181. package/dist/source/terminal-output.test.js +0 -213
  182. package/dist/source/token-tracker.d.ts +0 -14
  183. package/dist/source/token-tracker.js +0 -53
  184. package/dist/source/token-utils.d.ts +0 -7
  185. package/dist/source/token-utils.js +0 -13
  186. package/dist/source/tools/agent.d.ts +0 -17
  187. package/dist/source/tools/agent.js +0 -87
  188. package/dist/source/tools/bash.d.ts +0 -19
  189. package/dist/source/tools/bash.js +0 -294
  190. package/dist/source/tools/code-interpreter.d.ts +0 -12
  191. package/dist/source/tools/code-interpreter.js +0 -131
  192. package/dist/source/tools/command-validation.d.ts +0 -8
  193. package/dist/source/tools/command-validation.js +0 -69
  194. package/dist/source/tools/delete-file.d.ts +0 -12
  195. package/dist/source/tools/delete-file.js +0 -56
  196. package/dist/source/tools/directory-tree.d.ts +0 -12
  197. package/dist/source/tools/directory-tree.js +0 -38
  198. package/dist/source/tools/edit-file.d.ts +0 -19
  199. package/dist/source/tools/edit-file.js +0 -107
  200. package/dist/source/tools/filesystem-utils.d.ts +0 -22
  201. package/dist/source/tools/filesystem-utils.js +0 -191
  202. package/dist/source/tools/git-utils.d.ts +0 -14
  203. package/dist/source/tools/git-utils.js +0 -64
  204. package/dist/source/tools/grep.d.ts +0 -17
  205. package/dist/source/tools/grep.js +0 -138
  206. package/dist/source/tools/index.d.ts +0 -161
  207. package/dist/source/tools/index.js +0 -209
  208. package/dist/source/tools/memory-read.d.ts +0 -13
  209. package/dist/source/tools/memory-read.js +0 -135
  210. package/dist/source/tools/memory-write.d.ts +0 -12
  211. package/dist/source/tools/memory-write.js +0 -83
  212. package/dist/source/tools/move-file.d.ts +0 -13
  213. package/dist/source/tools/move-file.js +0 -44
  214. package/dist/source/tools/read-file.d.ts +0 -17
  215. package/dist/source/tools/read-file.js +0 -86
  216. package/dist/source/tools/read-multiple-files.d.ts +0 -14
  217. package/dist/source/tools/read-multiple-files.js +0 -55
  218. package/dist/source/tools/save-file.d.ts +0 -17
  219. package/dist/source/tools/save-file.js +0 -98
  220. package/dist/source/tools/think.d.ts +0 -11
  221. package/dist/source/tools/think.js +0 -45
  222. package/dist/source/tools/types.d.ts +0 -29
  223. package/dist/source/tools/types.js +0 -14
  224. package/dist/source/tools/web-fetch.d.ts +0 -47
  225. package/dist/source/tools/web-fetch.js +0 -246
  226. package/dist/source/tools/web-search.d.ts +0 -13
  227. package/dist/source/tools/web-search.js +0 -80
  228. package/dist/source/utils/process.d.ts +0 -36
  229. package/dist/source/utils/process.js +0 -75
  230. package/dist/source/version.d.ts +0 -1
  231. package/dist/source/version.js +0 -21
  232. package/dist/terminal-output.d.ts +0 -8
  233. package/dist/terminal-output.js +0 -213
  234. package/dist/tools/memory-read.d.ts +0 -13
  235. package/dist/tools/memory-read.js +0 -135
  236. package/dist/tools/memory-write.d.ts +0 -12
  237. package/dist/tools/memory-write.js +0 -83
  238. package/knip.json +0 -5
  239. package/source/cli.ts +0 -172
  240. package/source/commands/application-log-command.ts +0 -53
  241. package/source/commands/clear-command.ts +0 -14
  242. package/source/commands/compact-command.ts +0 -64
  243. package/source/commands/copy-command.ts +0 -55
  244. package/source/commands/edit-command.ts +0 -63
  245. package/source/commands/edit-prompt-command.ts +0 -31
  246. package/source/commands/exit-command.ts +0 -18
  247. package/source/commands/files-command.ts +0 -85
  248. package/source/commands/generate-rules-command.ts +0 -82
  249. package/source/commands/help-command.ts +0 -27
  250. package/source/commands/init-command.ts +0 -48
  251. package/source/commands/last-log-command.ts +0 -88
  252. package/source/commands/manager.ts +0 -151
  253. package/source/commands/model-command.ts +0 -123
  254. package/source/commands/paste-command.ts +0 -62
  255. package/source/commands/prompt-command.ts +0 -150
  256. package/source/commands/reset-command.ts +0 -22
  257. package/source/commands/rules-command.ts +0 -76
  258. package/source/commands/save-command.ts +0 -20
  259. package/source/commands/types.ts +0 -28
  260. package/source/commands/usage-command.ts +0 -26
  261. package/source/config.ts +0 -223
  262. package/source/conversation-analyzer.ts +0 -115
  263. package/source/dedent.ts +0 -53
  264. package/source/formatting.ts +0 -132
  265. package/source/index.ts +0 -240
  266. package/source/logger.ts +0 -29
  267. package/source/mentions.ts +0 -227
  268. package/source/messages.ts +0 -360
  269. package/source/middleware/audit-message.ts +0 -133
  270. package/source/middleware/index.ts +0 -2
  271. package/source/middleware/rate-limit.ts +0 -24
  272. package/source/models/ai-config.ts +0 -109
  273. package/source/models/anthropic-provider.ts +0 -199
  274. package/source/models/deepseek-provider.ts +0 -53
  275. package/source/models/google-provider.ts +0 -68
  276. package/source/models/manager.ts +0 -84
  277. package/source/models/openai-provider.ts +0 -81
  278. package/source/models/openrouter-provider.ts +0 -288
  279. package/source/models/providers.ts +0 -197
  280. package/source/models/xai-provider.ts +0 -59
  281. package/source/parsing.ts +0 -20
  282. package/source/prompts/manager.ts +0 -90
  283. package/source/prompts.ts +0 -172
  284. package/source/repl-prompt.ts +0 -196
  285. package/source/repl.ts +0 -572
  286. package/source/terminal/formatting.ts +0 -121
  287. package/source/terminal/index.ts +0 -518
  288. package/source/terminal/markdown-utils.ts +0 -89
  289. package/source/terminal/markdown.ts +0 -155
  290. package/source/terminal/types.ts +0 -84
  291. package/source/terminal-output.test.ts +0 -266
  292. package/source/token-tracker.ts +0 -78
  293. package/source/token-utils.ts +0 -17
  294. package/source/tools/agent.ts +0 -107
  295. package/source/tools/bash.ts +0 -367
  296. package/source/tools/code-interpreter.ts +0 -172
  297. package/source/tools/command-validation.ts +0 -81
  298. package/source/tools/delete-file.ts +0 -71
  299. package/source/tools/directory-tree.ts +0 -54
  300. package/source/tools/edit-file.ts +0 -155
  301. package/source/tools/filesystem-utils.ts +0 -265
  302. package/source/tools/git-utils.ts +0 -70
  303. package/source/tools/grep.ts +0 -184
  304. package/source/tools/index.ts +0 -278
  305. package/source/tools/memory-read.ts +0 -174
  306. package/source/tools/memory-write.ts +0 -105
  307. package/source/tools/move-file.ts +0 -59
  308. package/source/tools/read-file.ts +0 -129
  309. package/source/tools/read-multiple-files.ts +0 -80
  310. package/source/tools/save-file.ts +0 -147
  311. package/source/tools/think.ts +0 -51
  312. package/source/tools/types.ts +0 -58
  313. package/source/tools/web-fetch.ts +0 -327
  314. package/source/tools/web-search.ts +0 -101
  315. package/source/utils/process.ts +0 -121
  316. package/source/version.ts +0 -21
  317. package/test/commands/copy-command.test.ts +0 -69
  318. package/test/config.test.ts +0 -200
  319. package/test/terminal/markdown-utils.test.ts +0 -124
  320. package/test/tools/bash-tool.test.ts +0 -58
  321. package/test/tools/code-interpreter.test.ts +0 -91
  322. package/test/tools/command-validation.test.ts +0 -48
  323. package/tsconfig.build.json +0 -9
  324. package/tsconfig.json +0 -30
@@ -1,184 +0,0 @@
1
- import { execSync } from "node:child_process";
2
- import { inspect } from "node:util";
3
- import { tool } from "ai";
4
- import chalk from "chalk";
5
- import { z } from "zod";
6
- import type { SendData } from "./types.ts";
7
-
8
- export const GrepTool = {
9
- name: "grepFiles" as const,
10
- };
11
-
12
- export const createGrepTool = (
13
- options: { sendData?: SendData | undefined } = {},
14
- ) => {
15
- const { sendData } = options;
16
- return {
17
- [GrepTool.name]: tool({
18
- description: "Search files for patterns using ripgrep",
19
- inputSchema: z.object({
20
- pattern: z.string().describe("The regex pattern to search for"),
21
- path: z.string().describe("The path to search in"),
22
- recursive: z
23
- .boolean()
24
- .nullable()
25
- .describe("Pass null to use the default (true, search recursively)."),
26
- ignoreCase: z
27
- .boolean()
28
- .nullable()
29
- .describe(
30
- "Pass null to use the default (false, case-sensitive search).",
31
- ),
32
- filePattern: z
33
- .string()
34
- .nullable()
35
- .describe("Pass null if no file pattern filter is needed."),
36
- contextLines: z
37
- .number()
38
- .nullable()
39
- .describe("Pass null if no context lines are needed."),
40
- searchIgnored: z
41
- .boolean()
42
- .nullable()
43
- .describe(
44
- "Pass null to use the default (false, don't search ignored files).",
45
- ),
46
- }),
47
- execute: (
48
- {
49
- pattern,
50
- path,
51
- recursive,
52
- ignoreCase,
53
- filePattern,
54
- contextLines,
55
- searchIgnored,
56
- },
57
- { toolCallId },
58
- ) => {
59
- try {
60
- sendData?.({
61
- event: "tool-init",
62
- id: toolCallId,
63
- data: `Searching codebase for "${chalk.cyan(inspect(pattern))}" in ${chalk.cyan(path)}`,
64
- });
65
- const result = grepFiles(pattern, path, {
66
- recursive,
67
- ignoreCase,
68
- filePattern,
69
- contextLines,
70
- searchIgnored,
71
- });
72
-
73
- const matchCount =
74
- result === "No matches found."
75
- ? 0
76
- : result
77
- .trim()
78
- .split("\n")
79
- .filter((line) => {
80
- if (line === "--") {
81
- return false;
82
- }
83
- // A match line from ripgrep with --line-number has the format:
84
- // path:linenumber:match
85
- // A context line has the format:
86
- // path-linenumber-match
87
- // This regex distinguishes between them by looking for the colon after the line number.
88
- return /^(.+?):(\d+):(.*)$/.test(line);
89
- }).length;
90
-
91
- sendData?.({
92
- event: "tool-completion",
93
- id: toolCallId,
94
- data: `Found ${chalk.cyan(matchCount)} matches.`,
95
- });
96
- return Promise.resolve(result);
97
- } catch (error) {
98
- sendData?.({
99
- event: "tool-error",
100
- id: toolCallId,
101
- data: `Error searching for "${pattern}" in ${path}`,
102
- });
103
- return Promise.resolve((error as Error).message);
104
- }
105
- },
106
- }),
107
- };
108
- };
109
-
110
- interface GrepOptions {
111
- recursive?: boolean | null;
112
- ignoreCase?: boolean | null;
113
- filePattern?: string | null;
114
- contextLines?: number | null;
115
- searchIgnored?: boolean | null;
116
- }
117
-
118
- /**
119
- * Search files for patterns using ripgrep
120
- *
121
- * @param pattern - The regex pattern to search for
122
- * @param path - The path to search in
123
- * @param options - Additional options for the grep command
124
- * @returns The result of the grep command
125
- */
126
- function grepFiles(
127
- pattern: string,
128
- path: string,
129
- options: GrepOptions = {},
130
- ): string {
131
- try {
132
- // Handle null values by providing defaults
133
- const effectiveRecursive =
134
- options.recursive === null ? true : options.recursive;
135
- const effectiveIgnoreCase =
136
- options.ignoreCase === null ? false : options.ignoreCase;
137
- const effectiveSearchIgnored =
138
- options.searchIgnored === null ? false : options.searchIgnored;
139
- const effectiveFilePattern = options.filePattern;
140
- const effectiveContextLines = options.contextLines;
141
-
142
- // Build the ripgrep command
143
- let command = "rg --line-number";
144
-
145
- // Ripgrep is recursive by default, so we only need to add
146
- // --no-recursive if effectiveRecursive is explicitly false
147
- if (effectiveRecursive === false) {
148
- command += " --max-depth=0";
149
- }
150
-
151
- if (effectiveIgnoreCase) {
152
- command += " --ignore-case";
153
- }
154
-
155
- if (effectiveContextLines !== null && effectiveContextLines !== undefined) {
156
- command += ` --context=${effectiveContextLines}`;
157
- }
158
-
159
- // Add pattern (escaped for shell)
160
- command += ` ${JSON.stringify(pattern)}`;
161
-
162
- // Add path
163
- command += ` ${path}`;
164
-
165
- // Add file pattern if specified
166
- if (effectiveFilePattern !== null && effectiveFilePattern !== undefined) {
167
- command += ` --glob=${JSON.stringify(effectiveFilePattern)}`;
168
- }
169
-
170
- if (effectiveSearchIgnored) {
171
- command += " --no-ignore";
172
- }
173
-
174
- // Execute the command
175
- const result = execSync(command, { encoding: "utf-8" });
176
- return result;
177
- } catch (error) {
178
- if (error instanceof Error && "status" in error && error.status === 1) {
179
- // Status 1 in ripgrep just means "no matches found"
180
- return "No matches found.";
181
- }
182
- throw new Error(`Error executing ripgrep: ${(error as Error).message}`);
183
- }
184
- }
@@ -1,278 +0,0 @@
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 { createAgentTools } from "./agent.ts";
6
- import { createBashTool } from "./bash.ts";
7
- import { createCodeInterpreterTool } from "./code-interpreter.ts";
8
- import { createDeleteFileTool } from "./delete-file.ts";
9
- import { createDirectoryTreeTool } from "./directory-tree.ts";
10
- import { createEditFileTool } from "./edit-file.ts";
11
- import { createGrepTool } from "./grep.ts";
12
- import { createMemoryReadTool } from "./memory-read.ts";
13
- import { createMemoryWriteTool } from "./memory-write.ts";
14
- import { createMoveFileTool } from "./move-file.ts";
15
- import { createReadFileTool } from "./read-file.ts";
16
- import { createReadMultipleFilesTool } from "./read-multiple-files.ts";
17
- import { createSaveFileTool } from "./save-file.ts";
18
- import { createThinkTool } from "./think.ts";
19
- import type { Message } from "./types.ts";
20
- import { createWebFetchTool } from "./web-fetch.ts";
21
- import { createWebSearchTool } from "./web-search.ts";
22
-
23
- const sendDataHandler = (events: Map<string, Message[]>) => {
24
- const msgStore: Map<string, Message[]> = events;
25
- return (msg: Message) => {
26
- if (msgStore.has(msg.id)) {
27
- msgStore.get(msg.id)?.push(msg);
28
- } else {
29
- msgStore.set(msg.id, [msg]);
30
- }
31
- };
32
- };
33
-
34
- export async function initTools({
35
- terminal,
36
- tokenCounter,
37
- events,
38
- autoAcceptAll,
39
- }: {
40
- terminal: Terminal;
41
- tokenCounter: TokenCounter;
42
- events: Map<string, Message[]>;
43
- autoAcceptAll: boolean;
44
- }) {
45
- const sendDataFn = sendDataHandler(events);
46
-
47
- const readFileTool = await createReadFileTool({
48
- workingDir: process.cwd(),
49
- sendData: sendDataFn,
50
- tokenCounter,
51
- });
52
-
53
- const readMultipleFilesTool = await createReadMultipleFilesTool({
54
- workingDir: process.cwd(),
55
- sendData: sendDataFn,
56
- tokenCounter,
57
- });
58
-
59
- const editFileTool = await createEditFileTool({
60
- workingDir: process.cwd(),
61
- terminal,
62
- sendData: sendDataFn,
63
- autoAcceptAll,
64
- });
65
-
66
- const saveFileTool = await createSaveFileTool({
67
- workingDir: process.cwd(),
68
- sendData: sendDataFn,
69
- terminal,
70
- autoAcceptAll,
71
- });
72
-
73
- const moveFileTool = await createMoveFileTool({
74
- workingDir: process.cwd(),
75
- sendData: sendDataFn,
76
- });
77
-
78
- const directoryTreeTool = await createDirectoryTreeTool({
79
- workingDir: process.cwd(),
80
- sendData: sendDataFn,
81
- });
82
-
83
- const deleteFileTool = await createDeleteFileTool({
84
- workingDir: process.cwd(),
85
- sendData: sendDataFn,
86
- });
87
-
88
- const codeInterpreterTool = createCodeInterpreterTool({
89
- sendData: sendDataFn,
90
- });
91
-
92
- const grepTool = createGrepTool({
93
- sendData: sendDataFn,
94
- });
95
-
96
- const thinkTool = createThinkTool({
97
- sendData: sendDataFn,
98
- });
99
-
100
- const webFetchTool = createWebFetchTool({
101
- sendData: sendDataFn,
102
- tokenCounter,
103
- });
104
-
105
- const webSearchTool = createWebSearchTool({
106
- sendData: sendDataFn,
107
- tokenCounter,
108
- });
109
-
110
- const bashTool = createBashTool({
111
- baseDir: process.cwd(),
112
- sendData: sendDataFn,
113
- tokenCounter,
114
- terminal,
115
- autoAcceptAll,
116
- });
117
-
118
- const memoryReadTool = createMemoryReadTool({
119
- sendData: sendDataFn,
120
- });
121
-
122
- const memoryWriteTool = createMemoryWriteTool({
123
- sendData: sendDataFn,
124
- });
125
-
126
- const tools = {
127
- ...readFileTool,
128
- ...readMultipleFilesTool,
129
- ...editFileTool,
130
- ...saveFileTool,
131
- ...moveFileTool,
132
- ...directoryTreeTool,
133
- ...deleteFileTool,
134
- ...codeInterpreterTool,
135
- ...grepTool,
136
- ...thinkTool,
137
- ...webFetchTool,
138
- ...bashTool,
139
- ...webSearchTool,
140
- ...memoryReadTool,
141
- ...memoryWriteTool,
142
- } as const;
143
-
144
- return tools;
145
- }
146
-
147
- export async function initCliTools({
148
- tokenCounter,
149
- }: {
150
- tokenCounter: TokenCounter;
151
- }) {
152
- const readFileTool = await createReadFileTool({
153
- workingDir: process.cwd(),
154
- sendData: undefined,
155
- tokenCounter,
156
- });
157
-
158
- const readMultipleFilesTool = await createReadMultipleFilesTool({
159
- workingDir: process.cwd(),
160
- sendData: undefined,
161
- tokenCounter,
162
- });
163
-
164
- const editFileTool = await createEditFileTool({
165
- workingDir: process.cwd(),
166
- terminal: undefined,
167
- sendData: undefined,
168
- autoAcceptAll: true,
169
- });
170
-
171
- const saveFileTool = await createSaveFileTool({
172
- workingDir: process.cwd(),
173
- sendData: undefined,
174
- terminal: undefined,
175
- autoAcceptAll: true,
176
- });
177
-
178
- const moveFileTool = await createMoveFileTool({
179
- workingDir: process.cwd(),
180
- sendData: undefined,
181
- });
182
-
183
- const directoryTreeTool = await createDirectoryTreeTool({
184
- workingDir: process.cwd(),
185
- sendData: undefined,
186
- });
187
-
188
- const deleteFileTool = await createDeleteFileTool({
189
- workingDir: process.cwd(),
190
- sendData: undefined,
191
- });
192
-
193
- const codeInterpreterTool = createCodeInterpreterTool({
194
- sendData: undefined,
195
- });
196
-
197
- const grepTool = createGrepTool({
198
- sendData: undefined,
199
- });
200
-
201
- const thinkTool = createThinkTool({
202
- sendData: undefined,
203
- });
204
-
205
- const webFetchTool = createWebFetchTool({
206
- sendData: undefined,
207
- tokenCounter,
208
- });
209
-
210
- const webSearchTool = createWebSearchTool({
211
- sendData: undefined,
212
- tokenCounter,
213
- });
214
-
215
- const bashTool = createBashTool({
216
- baseDir: process.cwd(),
217
- sendData: undefined,
218
- tokenCounter,
219
- terminal: undefined,
220
- autoAcceptAll: true,
221
- });
222
-
223
- const memoryReadTool = createMemoryReadTool({
224
- sendData: undefined,
225
- });
226
-
227
- const memoryWriteTool = createMemoryWriteTool({
228
- sendData: undefined,
229
- });
230
-
231
- const tools = {
232
- ...readFileTool,
233
- ...readMultipleFilesTool,
234
- ...editFileTool,
235
- ...saveFileTool,
236
- ...moveFileTool,
237
- ...directoryTreeTool,
238
- ...deleteFileTool,
239
- ...codeInterpreterTool,
240
- ...grepTool,
241
- ...thinkTool,
242
- ...webFetchTool,
243
- ...bashTool,
244
- ...webSearchTool,
245
- ...memoryReadTool,
246
- ...memoryWriteTool,
247
- } as const;
248
-
249
- return tools;
250
- }
251
-
252
- export async function initAgents({
253
- modelManager,
254
- tokenTracker,
255
- tokenCounter,
256
- events,
257
- }: {
258
- terminal: Terminal;
259
- modelManager: ModelManager;
260
- tokenTracker: TokenTracker;
261
- tokenCounter: TokenCounter;
262
- events: Map<string, Message[]>;
263
- }) {
264
- const sendDataFn = sendDataHandler(events);
265
-
266
- const agentTools = createAgentTools({
267
- modelManager,
268
- tokenTracker,
269
- tokenCounter,
270
- sendData: sendDataFn,
271
- });
272
-
273
- const tools = {
274
- ...agentTools,
275
- };
276
-
277
- return tools;
278
- }
@@ -1,174 +0,0 @@
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.ts";
6
- import type { SendData } from "./types.ts";
7
-
8
- export const MemoryReadTool = {
9
- name: "memoryRead" as const,
10
- };
11
-
12
- const MEMORY_DIR = config.app.ensurePathSync("memory");
13
-
14
- // Helper to check if a file exists
15
- // Moved to module level as it does not use sendData
16
- async function fileExists(filePath: string): Promise<boolean> {
17
- try {
18
- await access(filePath);
19
- return true;
20
- } catch {
21
- return false;
22
- }
23
- }
24
-
25
- // Helper function, does not use sendData directly
26
- const _readSpecificMemoryFile = async (
27
- resolvedMemoryDir: string,
28
- filePath: string,
29
- ) => {
30
- const normalizedRelativePath = normalize(filePath);
31
-
32
- if (
33
- normalizedRelativePath.startsWith("..") ||
34
- normalizedRelativePath.includes("..") ||
35
- isAbsolute(normalizedRelativePath)
36
- ) {
37
- throw new Error(
38
- `Error: Invalid filePath "${filePath}". Must be a relative path and cannot use '..'.`,
39
- );
40
- }
41
-
42
- const fullPath = join(resolvedMemoryDir, normalizedRelativePath);
43
-
44
- if (
45
- !fullPath.startsWith(resolvedMemoryDir + sep) &&
46
- fullPath !== resolvedMemoryDir
47
- ) {
48
- throw new Error(
49
- `Error: Path "${filePath}" resolves outside the allowed memory directory.`,
50
- );
51
- }
52
- if (!(await fileExists(fullPath))) {
53
- throw new Error(`Error: Memory file '${filePath}' does not exist.`);
54
- }
55
- const stats = await lstat(fullPath);
56
- if (stats.isDirectory()) {
57
- throw new Error(
58
- `Error: '${filePath}' is a directory. Please provide a path to a file to read.`,
59
- );
60
- }
61
- const content = await readFile(fullPath, "utf-8");
62
- return { filePath, content };
63
- };
64
-
65
- // Helper function, does not use sendData directly
66
- const _listMemoryFilesAndIndex = async (resolvedMemoryDir: string) => {
67
- const entries = await readdir(resolvedMemoryDir, {
68
- recursive: true,
69
- withFileTypes: true,
70
- });
71
- const filesOnly = entries
72
- .filter((entry) => entry.isFile())
73
- .map((entry) => join(entry.parentPath ?? resolvedMemoryDir, entry.name)); // entry.path is available with recursive
74
-
75
- const fileListString =
76
- filesOnly.length > 0
77
- ? filesOnly
78
- .map((p) => `- ${normalize(p.replace(resolvedMemoryDir + sep, ""))}`)
79
- .join("\n") // Show relative paths
80
- : "No files in memory.";
81
-
82
- const indexPath = join(resolvedMemoryDir, "index.md");
83
- let indexContent = "(empty)";
84
- if (await fileExists(indexPath)) {
85
- const stats = await lstat(indexPath);
86
- if (stats.isFile()) {
87
- indexContent = await readFile(indexPath, "utf-8");
88
- }
89
- }
90
-
91
- const output = `Root memory file (index.md):
92
- '''
93
- ${indexContent}
94
- '''
95
-
96
- Files in the memory directory:
97
- ${fileListString}`;
98
- return { content: output };
99
- };
100
-
101
- export const createMemoryReadTool = (
102
- options: { sendData?: SendData | undefined } = {},
103
- ) => {
104
- const { sendData } = options;
105
-
106
- const memoryReadTool = tool({
107
- description:
108
- 'Read from memory files. If no path is provided, lists all files and shows content of "index.md".',
109
- inputSchema: z.object({
110
- filePath: z
111
- .string()
112
- .nullable()
113
- .describe(
114
- 'Optional path to a specific memory file to read, relative to the memory directory. Cannot use ".." or absolute paths.',
115
- ),
116
- }),
117
- execute: async (
118
- { filePath }: { filePath: string | null },
119
- { toolCallId },
120
- ) => {
121
- sendData?.({
122
- event: "tool-init",
123
- id: toolCallId,
124
- data: "Initializing memory read...",
125
- });
126
-
127
- const resolvedMemoryDir = resolve(MEMORY_DIR);
128
-
129
- try {
130
- await mkdir(resolvedMemoryDir, { recursive: true });
131
-
132
- let result: { content: string };
133
- if (filePath) {
134
- sendData?.({
135
- event: "tool-update",
136
- id: toolCallId,
137
- data: { primary: "Reading file:", secondary: [filePath] },
138
- });
139
- result = await _readSpecificMemoryFile(resolvedMemoryDir, filePath);
140
- } else {
141
- sendData?.({
142
- event: "tool-update",
143
- id: toolCallId,
144
- data: { primary: "Listing memory files and index" },
145
- });
146
- result = await _listMemoryFilesAndIndex(resolvedMemoryDir);
147
- }
148
-
149
- sendData?.({
150
- event: "tool-completion",
151
- id: toolCallId,
152
- data: "Done",
153
- });
154
-
155
- return result;
156
- } catch (error: unknown) {
157
- let errorMsg = "Error reading memory: An unknown error occurred";
158
- if (error instanceof Error) {
159
- errorMsg = `Error reading memory: ${error.message}`;
160
- }
161
- sendData?.({
162
- event: "tool-error",
163
- id: toolCallId,
164
- data: errorMsg,
165
- });
166
- return errorMsg;
167
- }
168
- },
169
- });
170
-
171
- return {
172
- [MemoryReadTool.name]: memoryReadTool,
173
- };
174
- };