@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,82 +0,0 @@
1
- import { checkbox } from "@inquirer/prompts";
2
- import { analyzeConversation } from "../conversation-analyzer.ts";
3
- import { logger } from "../logger.ts"; // Import logger
4
- import type { CommandOptions, ReplCommand } from "./types.ts";
5
-
6
- async function _processAndSaveRules(
7
- newRules: string[] | null,
8
- terminal: CommandOptions["terminal"],
9
- config: CommandOptions["config"], // Simplified type
10
- ) {
11
- if (!newRules || newRules.length === 0) {
12
- terminal.warn("No new generalizable rules were identified.");
13
- return;
14
- }
15
-
16
- terminal.info("Generated potential rules:");
17
- terminal.lineBreak();
18
-
19
- const rulesToKeep = await checkbox({
20
- message: "Select the rules you want to keep:",
21
- choices: newRules.map((rule) => ({ name: rule, value: rule })),
22
- });
23
-
24
- if (rulesToKeep.length === 0) {
25
- terminal.warn("No rules selected to save.");
26
- return;
27
- }
28
-
29
- terminal.info("Saving selected rules...");
30
- const existingRules = await config.readProjectLearnedRulesFile();
31
- const rulesToAdd = rulesToKeep.join("\n");
32
- const updatedProjectRules =
33
- existingRules.endsWith("\n") || existingRules.length === 0
34
- ? `${existingRules}${rulesToAdd}`
35
- : `${existingRules}\n${rulesToAdd}`;
36
-
37
- await config.writeProjectLearnedRulesFile(updatedProjectRules);
38
- terminal.success("Selected rules saved to project learned rules.");
39
- terminal.lineBreak();
40
- terminal.display(rulesToAdd); // Display only the saved rules
41
- }
42
-
43
- export const generateRulesCommand = ({
44
- terminal,
45
- messageHistory,
46
- modelManager,
47
- tokenTracker,
48
- config, // This is the config module from CommandOptions
49
- }: CommandOptions): ReplCommand => {
50
- return {
51
- command: "/generate-rules",
52
- description:
53
- "Analyzes the current conversation to generate and save new interaction rules, then displays them.",
54
- result: "continue" as const,
55
- getSubCommands: () => Promise.resolve([]),
56
- execute: async () => {
57
- if (messageHistory.isEmpty()) {
58
- terminal.writeln("Cannot generate rules from an empty conversation.");
59
- return;
60
- }
61
-
62
- terminal.lineBreak();
63
- terminal.info("Analyzing conversation to generate rules...");
64
- try {
65
- const newRules = await analyzeConversation({
66
- modelManager,
67
- messages: messageHistory.get(),
68
- tokenTracker,
69
- terminal,
70
- });
71
-
72
- // Pass the config object available in CommandOptions scope
73
- await _processAndSaveRules(newRules, terminal, config);
74
- } catch (error) {
75
- const errorMessage =
76
- error instanceof Error ? error.message : String(error);
77
- terminal.error(`Error generating rules: ${errorMessage}`);
78
- logger.error(error, "Error during rule generation:");
79
- }
80
- },
81
- };
82
- };
@@ -1,27 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
-
3
- export const helpCommand = (
4
- { terminal }: CommandOptions,
5
- cmds: Map<string, ReplCommand>,
6
- ): ReplCommand => {
7
- return {
8
- command: "/help",
9
- description: "Shows available commands.",
10
- result: "continue" as const,
11
- getSubCommands: () => Promise.resolve([]),
12
- execute: () => {
13
- const commands = cmds;
14
-
15
- const entries: [string, string][] = Array.from(commands.entries())
16
- .sort(([a], [b]) => a.localeCompare(b))
17
- .map(([key, cmd]) => [key, cmd.description]);
18
-
19
- terminal.table(entries, {
20
- header: ["Command", "Description"],
21
- colWidths: [30, 70],
22
- });
23
-
24
- return Promise.resolve();
25
- },
26
- };
27
- };
@@ -1,48 +0,0 @@
1
- import { platform } from "node:os";
2
- import { stepCountIs, streamText } from "ai";
3
- import { inGitDirectory } from "../tools/git-utils.ts";
4
- import { initTools } from "../tools/index.ts";
5
- import type { CommandOptions, ReplCommand } from "./types.ts";
6
-
7
- export const initCommand = ({
8
- terminal,
9
- modelManager,
10
- tokenCounter,
11
- toolEvents,
12
- }: CommandOptions): ReplCommand => {
13
- return {
14
- command: "/init",
15
- description: "Creates the AGENTS.md file.",
16
- result: "continue" as const,
17
- getSubCommands: () => Promise.resolve([]),
18
- execute: async () => {
19
- const result = streamText({
20
- model: modelManager.getModel("init-project"),
21
- temperature: 0.5,
22
- prompt: `Please analyze this codebase and create a AGENTS.md file containing:
23
- 1. Build/lint/test commands - especially for running a single test
24
- 2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
25
-
26
- The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 20 lines long.
27
-
28
- If there's already a AGENTS.md, improve it.
29
- If there are Cursor rules (in .cursor/rules/ or .cursorrules), Copilot rules (in .github/copilot-instructions.md), or Windsurf rules (in .windsurf/rules), make sure to include them.
30
-
31
- Your current working directory is ${process.cwd()}
32
- Is directory a git repo: ${(await inGitDirectory()) ? "Yes" : "No"}
33
- Platform: ${platform()}`,
34
- stopWhen: stepCountIs(40),
35
- tools: await initTools({
36
- terminal,
37
- tokenCounter,
38
- events: toolEvents,
39
- autoAcceptAll: true,
40
- }),
41
- });
42
-
43
- for await (const text of result.textStream) {
44
- terminal.write(text);
45
- }
46
- },
47
- };
48
- };
@@ -1,88 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { editor } from "@inquirer/prompts";
4
- import chalk from "chalk";
5
- import { globby } from "globby";
6
- import { config } from "../config.ts";
7
- import type { CommandOptions, ReplCommand } from "./types.ts";
8
-
9
- const isoDateRegex = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/;
10
-
11
- // Function to find the most recent log file
12
- async function findMostRecentLog(logDir: string): Promise<string | null> {
13
- const logPattern = join(logDir, "*-repl-message.json");
14
- const files = await globby(logPattern);
15
-
16
- if (files.length === 0) {
17
- return null;
18
- }
19
-
20
- const datedFiles = files
21
- .map((file) => {
22
- const filename = file.split("/").pop();
23
- if (!filename) {
24
- return null; // Skip if filename is somehow undefined
25
- }
26
- // Match the ISO date string at the beginning of the filename
27
- const match = filename.match(isoDateRegex);
28
- if (match?.[1]) {
29
- try {
30
- const date = new Date(match[1]);
31
- // Check if the date is valid
32
- if (!Number.isNaN(date.getTime())) {
33
- return { file, date };
34
- }
35
- } catch (e) {
36
- // Ignore files with invalid date strings
37
- console.warn(`Could not parse date from filename: ${filename}`, e);
38
- }
39
- }
40
- return null; // Exclude files that don't match the pattern or have invalid dates
41
- })
42
- .filter((item): item is { file: string; date: Date } => item !== null);
43
-
44
- if (datedFiles.length === 0) {
45
- return null; // No valid log files found
46
- }
47
-
48
- // Sort files by date (descending)
49
- datedFiles.sort((a, b) => b.date.getTime() - a.date.getTime());
50
-
51
- return datedFiles[0]?.file ?? null; // The first file is the most recent
52
- }
53
-
54
- export const lastLogCommand = ({ terminal }: CommandOptions): ReplCommand => {
55
- return {
56
- command: "/last-log",
57
- description: "Opens the most recent REPL audit log in the editor.",
58
- result: "continue" as const,
59
- getSubCommands: () => Promise.resolve([]),
60
- execute: async () => {
61
- const logDir = config.app.ensurePathSync("audit");
62
- const mostRecentLog = await findMostRecentLog(logDir);
63
-
64
- if (!mostRecentLog) {
65
- terminal.error(`No REPL audit logs found in '${logDir}'.`);
66
- return;
67
- }
68
-
69
- try {
70
- const content = await readFile(mostRecentLog, { encoding: "utf8" });
71
-
72
- // Use the editor prompt to display the content (read-only)
73
- await editor({
74
- message: `Viewing ${chalk.green(mostRecentLog)}`,
75
- postfix: ".json", // Set postfix for syntax highlighting if editor supports it
76
- default: content,
77
- // By not providing an onSubmit or similar handler to write the file,
78
- // and not calling writeFileSync after, this effectively becomes read-only.
79
- });
80
- terminal.info("Closed log view");
81
- } catch (error) {
82
- terminal.error(
83
- `Error reading or displaying log file ${mostRecentLog}: ${error}`,
84
- );
85
- }
86
- },
87
- };
88
- };
@@ -1,151 +0,0 @@
1
- import type { ConfigManager } from "../config.ts";
2
- import type { MessageHistory } from "../messages.ts";
3
- import type { ModelManager } from "../models/manager.ts";
4
- import type { PromptManager } from "../prompts/manager.ts";
5
- import type { Terminal } from "../terminal/index.ts";
6
- import type { TokenTracker } from "../token-tracker.ts";
7
- import type { TokenCounter } from "../token-utils.ts";
8
- import type { Message } from "../tools/types.ts";
9
- import { applicationLogCommand } from "./application-log-command.ts";
10
- import { clearCommand } from "./clear-command.ts";
11
- import { compactCommand } from "./compact-command.ts";
12
- import { copyCommand } from "./copy-command.ts";
13
- import { editCommand } from "./edit-command.ts";
14
- import { editPromptCommand } from "./edit-prompt-command.ts";
15
- import { exitCommand } from "./exit-command.ts";
16
- import { filesCommand } from "./files-command.ts";
17
- import { generateRulesCommand } from "./generate-rules-command.ts";
18
- import { helpCommand } from "./help-command.ts";
19
- import { initCommand } from "./init-command.ts";
20
- import { lastLogCommand } from "./last-log-command.ts";
21
- import { modelCommand } from "./model-command.ts";
22
- import { pasteCommand } from "./paste-command.ts";
23
- import { promptCommand } from "./prompt-command.ts";
24
- import { resetCommand } from "./reset-command.ts";
25
- import { rulesCommand } from "./rules-command.ts";
26
- import { saveCommand } from "./save-command.ts";
27
- import type { CommandOptions, ReplCommand } from "./types.ts";
28
- import { usageCommand } from "./usage-command.ts";
29
-
30
- export class CommandManager {
31
- private commands: Map<string, ReplCommand>;
32
- private promptManager: PromptManager;
33
- private modelManager: ModelManager;
34
- private messageHistory: MessageHistory;
35
- private tokenTracker: TokenTracker;
36
- private terminal: Terminal;
37
- private config: ConfigManager;
38
- private tokenCounter: TokenCounter;
39
- private toolEvents: Map<string, Message[]>;
40
-
41
- constructor({
42
- promptManager,
43
- modelManager,
44
- terminal,
45
- messageHistory,
46
- tokenTracker,
47
- config,
48
- tokenCounter,
49
- toolEvents,
50
- }: CommandOptions) {
51
- this.commands = new Map();
52
- this.promptManager = promptManager;
53
- this.modelManager = modelManager;
54
- this.terminal = terminal;
55
- this.messageHistory = messageHistory;
56
- this.tokenTracker = tokenTracker;
57
- this.config = config;
58
- this.tokenCounter = tokenCounter;
59
- this.toolEvents = toolEvents;
60
- this.initializeCommmands();
61
- }
62
-
63
- initializeCommmands() {
64
- // Import and register each command
65
- const options: CommandOptions = {
66
- promptManager: this.promptManager,
67
- modelManager: this.modelManager,
68
- terminal: this.terminal,
69
- messageHistory: this.messageHistory,
70
- tokenTracker: this.tokenTracker,
71
- config: this.config,
72
- tokenCounter: this.tokenCounter,
73
- toolEvents: this.toolEvents,
74
- };
75
-
76
- // Register all commands
77
- const cmds = [
78
- clearCommand(options),
79
- compactCommand(options),
80
- editCommand(options),
81
- editPromptCommand(options),
82
- exitCommand(options),
83
- filesCommand(options),
84
- initCommand(options),
85
- pasteCommand(options),
86
- promptCommand(options),
87
- resetCommand(options),
88
- saveCommand(options),
89
- rulesCommand(options),
90
- modelCommand(options),
91
- usageCommand(options),
92
- lastLogCommand(options),
93
- generateRulesCommand(options),
94
- applicationLogCommand(options),
95
- copyCommand(options),
96
- ];
97
-
98
- // Add help command with access to all commands
99
- const helpCmd = helpCommand(options, this.commands);
100
- cmds.push({
101
- ...helpCmd,
102
- execute: () => helpCmd.execute([]),
103
- });
104
-
105
- // Register all commands
106
- for (const cmd of cmds) {
107
- this.commands.set(cmd.command, cmd);
108
- const aliases: string[] = cmd.aliases ?? [];
109
- for (const alias of aliases) {
110
- this.commands.set(alias, cmd);
111
- }
112
- }
113
- }
114
-
115
- getCommands() {
116
- return Array.from(this.commands.keys()).sort();
117
- }
118
-
119
- async getSubCommands(command: string): Promise<string[]> {
120
- return (await this.commands.get(command)?.getSubCommands()) ?? [];
121
- }
122
-
123
- async handle({ userInput }: { userInput: string }) {
124
- const commandArgs = userInput.split(" ");
125
- const command = commandArgs.at(0);
126
- const args = commandArgs.slice(1);
127
-
128
- if (command) {
129
- const replCommand = this.commands.get(command);
130
- if (replCommand) {
131
- await replCommand.execute(args);
132
- if (replCommand.result === "continue") {
133
- return {
134
- continue: true,
135
- break: false,
136
- };
137
- }
138
- if (replCommand.result === "break") {
139
- return {
140
- continue: false,
141
- break: true,
142
- };
143
- }
144
- }
145
- }
146
- return {
147
- continue: false,
148
- break: false,
149
- };
150
- }
151
- }
@@ -1,123 +0,0 @@
1
- import {
2
- formatModelInfo,
3
- getModelsByCategory,
4
- isValidModel,
5
- type ModelName,
6
- type ModelProvider,
7
- modelRegistry,
8
- models,
9
- providers,
10
- } from "../models/providers.ts";
11
- import type { CommandOptions, ReplCommand } from "./types.ts";
12
-
13
- export function modelCommand(options: CommandOptions): ReplCommand {
14
- const { terminal, modelManager } = options;
15
-
16
- function switchModel(newModelName: ModelName) {
17
- try {
18
- // Get current and new model configs
19
- const currentModelConfig = modelManager.getModelMetadata("repl");
20
- const newModelConfig = modelRegistry[newModelName]; // Ensure modelRegistry is available
21
-
22
- if (!newModelConfig) {
23
- terminal.error(`Model configuration not found for: ${newModelName}`);
24
- return;
25
- }
26
-
27
- // Check for capability differences
28
- if (
29
- currentModelConfig.supportsToolCalling &&
30
- !newModelConfig.supportsToolCalling
31
- ) {
32
- terminal.warn(
33
- "The new model doesn't support tool calling, which may limit functionality.",
34
- );
35
- }
36
- if (
37
- currentModelConfig.supportsReasoning &&
38
- !newModelConfig.supportsReasoning
39
- ) {
40
- terminal.warn(
41
- "The new model doesn't support reasoning, which may change response quality.",
42
- );
43
- }
44
-
45
- // Update model in ModelManager
46
- modelManager.setModel("repl", newModelName);
47
-
48
- // Assuming ModelManager handles the actual model instance switching internally.
49
- terminal.info(`Model set to ${newModelName}.`); // Simplified message
50
- } catch (error) {
51
- terminal.error(`Failed to switch model: ${(error as Error).message}`);
52
- }
53
- }
54
-
55
- return {
56
- command: "/model",
57
- description:
58
- "List available models or switch to a different model. Usage: /model [provider:model-name|category|provider]",
59
- result: "continue",
60
- getSubCommands: () => Promise.resolve(models as unknown as string[]),
61
- async execute(args: string[]): Promise<void> {
62
- const arg = args.join(" ").trim();
63
- const modelConfig = modelManager.getModelMetadata("repl");
64
-
65
- // No args - display current model and list available models by category
66
- if (!arg) {
67
- const currentModel = modelConfig.id;
68
- terminal.header(`Current model: ${currentModel}`);
69
- terminal.header("Available models by category:");
70
-
71
- // Display models by category
72
- for (const category of ["fast", "balanced", "powerful"] as const) {
73
- // Use 'as const' for stricter typing
74
- terminal.writeln(
75
- `\n${category.charAt(0).toUpperCase() + category.slice(1)} models:`,
76
- );
77
- for (const model of getModelsByCategory(category)) {
78
- terminal.writeln(formatModelInfo(model));
79
- }
80
- }
81
- return;
82
- }
83
-
84
- // Switch to a specific model
85
- if (isValidModel(arg)) {
86
- // Call the standalone switchModel function
87
- switchModel(arg as ModelName);
88
- return;
89
- }
90
-
91
- // Display models by category
92
- const categories = ["fast", "balanced", "powerful"];
93
- if (categories.includes(arg)) {
94
- terminal.header(
95
- `${arg.charAt(0).toUpperCase() + arg.slice(1)} models:`,
96
- );
97
- // Need to assert arg is a valid category if the check passes
98
- for (const model of getModelsByCategory(
99
- arg as "fast" | "balanced" | "powerful",
100
- )) {
101
- terminal.writeln(formatModelInfo(model));
102
- }
103
- return;
104
- }
105
-
106
- // Display models by provider
107
- if (providers.includes(arg as ModelProvider)) {
108
- terminal.header(`Models from ${arg}:`);
109
- // Need to ensure modelRegistry is accessible and correctly typed
110
- for (const model of Object.values(modelRegistry).filter(
111
- (m) => m.provider === arg,
112
- )) {
113
- terminal.writeln(formatModelInfo(model));
114
- }
115
- return;
116
- }
117
-
118
- // Invalid model name
119
- terminal.error(`Invalid model name or category: ${arg}`);
120
- terminal.info("Usage: /model [provider:model-name|category|provider]");
121
- },
122
- };
123
- }
@@ -1,62 +0,0 @@
1
- import Clipboard from "@crosscopy/clipboard";
2
- import { formatBlock } from "../formatting.ts";
3
- import { logger } from "../logger.ts";
4
- import type { CommandOptions, ReplCommand } from "./types.ts";
5
-
6
- const base64UrlRegex = /^data:(.*?);base64,/;
7
-
8
- export const pasteCommand = ({
9
- terminal,
10
- modelManager,
11
- promptManager,
12
- }: CommandOptions): ReplCommand => {
13
- return {
14
- command: "/paste",
15
- description:
16
- "Pastes image or text content from the clipboard into the next prompt.",
17
- result: "continue" as const,
18
- getSubCommands: () => Promise.resolve([]),
19
- execute: async () => {
20
- try {
21
- if (Clipboard.hasImage()) {
22
- const base64DataUrl = await Clipboard.getImageBase64();
23
- const mimeTypeMatch = base64DataUrl.match(base64UrlRegex);
24
- const mimeType = mimeTypeMatch ? mimeTypeMatch[1] : "image/png";
25
-
26
- promptManager.addContext({
27
- type: "image",
28
- image: base64DataUrl,
29
- mediaType: mimeType,
30
- });
31
-
32
- terminal.success(
33
- "Image from clipboard will be added to your next prompt.",
34
- );
35
- return;
36
- }
37
-
38
- const clipboardContent = await Clipboard.getText();
39
- if (!clipboardContent || clipboardContent.trim() === "") {
40
- terminal.warn("Clipboard is empty.");
41
- return;
42
- }
43
-
44
- promptManager.addContext(
45
- formatBlock(
46
- clipboardContent,
47
- "clipboard",
48
- modelManager.getModelMetadata("repl").promptFormat,
49
- ),
50
- );
51
-
52
- terminal.success(
53
- "Clipboard content will be added to your next prompt.",
54
- );
55
- } catch (error) {
56
- const message = error instanceof Error ? error.message : String(error);
57
- terminal.error(`Error processing clipboard content: ${message}`);
58
- logger.error(error, "Paste command error:");
59
- }
60
- },
61
- };
62
- };