@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,40 +0,0 @@
1
- import { platform } from "node:os";
2
- import { stepCountIs, streamText } from "ai";
3
- import { inGitDirectory } from "../tools/git-utils.js";
4
- import { initTools } from "../tools/index.js";
5
- export const initCommand = ({ terminal, modelManager, tokenCounter, toolEvents, }) => {
6
- return {
7
- command: "/init",
8
- description: "Creates the AGENTS.md file.",
9
- result: "continue",
10
- getSubCommands: () => Promise.resolve([]),
11
- execute: async () => {
12
- const result = streamText({
13
- model: modelManager.getModel("init-project"),
14
- temperature: 0.5,
15
- prompt: `Please analyze this codebase and create a AGENTS.md file containing:
16
- 1. Build/lint/test commands - especially for running a single test
17
- 2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
18
-
19
- 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.
20
-
21
- If there's already a AGENTS.md, improve it.
22
- 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.
23
-
24
- Your current working directory is ${process.cwd()}
25
- Is directory a git repo: ${(await inGitDirectory()) ? "Yes" : "No"}
26
- Platform: ${platform()}`,
27
- stopWhen: stepCountIs(40),
28
- tools: await initTools({
29
- terminal,
30
- tokenCounter,
31
- events: toolEvents,
32
- autoAcceptAll: true,
33
- }),
34
- });
35
- for await (const text of result.textStream) {
36
- terminal.write(text);
37
- }
38
- },
39
- };
40
- };
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare const lastLogCommand: ({ terminal }: CommandOptions) => ReplCommand;
@@ -1,76 +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.js";
7
- const isoDateRegex = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/;
8
- // Function to find the most recent log file
9
- async function findMostRecentLog(logDir) {
10
- const logPattern = join(logDir, "*-repl-message.json");
11
- const files = await globby(logPattern);
12
- if (files.length === 0) {
13
- return null;
14
- }
15
- const datedFiles = files
16
- .map((file) => {
17
- const filename = file.split("/").pop();
18
- if (!filename) {
19
- return null; // Skip if filename is somehow undefined
20
- }
21
- // Match the ISO date string at the beginning of the filename
22
- const match = filename.match(isoDateRegex);
23
- if (match?.[1]) {
24
- try {
25
- const date = new Date(match[1]);
26
- // Check if the date is valid
27
- if (!Number.isNaN(date.getTime())) {
28
- return { file, date };
29
- }
30
- }
31
- catch (e) {
32
- // Ignore files with invalid date strings
33
- console.warn(`Could not parse date from filename: ${filename}`, e);
34
- }
35
- }
36
- return null; // Exclude files that don't match the pattern or have invalid dates
37
- })
38
- .filter((item) => item !== null);
39
- if (datedFiles.length === 0) {
40
- return null; // No valid log files found
41
- }
42
- // Sort files by date (descending)
43
- datedFiles.sort((a, b) => b.date.getTime() - a.date.getTime());
44
- return datedFiles[0]?.file ?? null; // The first file is the most recent
45
- }
46
- export const lastLogCommand = ({ terminal }) => {
47
- return {
48
- command: "/last-log",
49
- description: "Opens the most recent REPL audit log in the editor.",
50
- result: "continue",
51
- getSubCommands: () => Promise.resolve([]),
52
- execute: async () => {
53
- const logDir = config.app.ensurePathSync("audit");
54
- const mostRecentLog = await findMostRecentLog(logDir);
55
- if (!mostRecentLog) {
56
- terminal.error(`No REPL audit logs found in '${logDir}'.`);
57
- return;
58
- }
59
- try {
60
- const content = await readFile(mostRecentLog, { encoding: "utf8" });
61
- // Use the editor prompt to display the content (read-only)
62
- await editor({
63
- message: `Viewing ${chalk.green(mostRecentLog)}`,
64
- postfix: ".json", // Set postfix for syntax highlighting if editor supports it
65
- default: content,
66
- // By not providing an onSubmit or similar handler to write the file,
67
- // and not calling writeFileSync after, this effectively becomes read-only.
68
- });
69
- terminal.info("Closed log view");
70
- }
71
- catch (error) {
72
- terminal.error(`Error reading or displaying log file ${mostRecentLog}: ${error}`);
73
- }
74
- },
75
- };
76
- };
@@ -1,22 +0,0 @@
1
- import type { CommandOptions } from "./types.ts";
2
- export declare class CommandManager {
3
- private commands;
4
- private promptManager;
5
- private modelManager;
6
- private messageHistory;
7
- private tokenTracker;
8
- private terminal;
9
- private config;
10
- private tokenCounter;
11
- private toolEvents;
12
- constructor({ promptManager, modelManager, terminal, messageHistory, tokenTracker, config, tokenCounter, toolEvents, }: CommandOptions);
13
- initializeCommmands(): void;
14
- getCommands(): string[];
15
- getSubCommands(command: string): Promise<string[]>;
16
- handle({ userInput }: {
17
- userInput: string;
18
- }): Promise<{
19
- continue: boolean;
20
- break: boolean;
21
- }>;
22
- }
@@ -1,123 +0,0 @@
1
- import { applicationLogCommand } from "./application-log-command.js";
2
- import { clearCommand } from "./clear-command.js";
3
- import { compactCommand } from "./compact-command.js";
4
- import { copyCommand } from "./copy-command.js";
5
- import { editCommand } from "./edit-command.js";
6
- import { editPromptCommand } from "./edit-prompt-command.js";
7
- import { exitCommand } from "./exit-command.js";
8
- import { filesCommand } from "./files-command.js";
9
- import { generateRulesCommand } from "./generate-rules-command.js";
10
- import { helpCommand } from "./help-command.js";
11
- import { initCommand } from "./init-command.js";
12
- import { lastLogCommand } from "./last-log-command.js";
13
- import { modelCommand } from "./model-command.js";
14
- import { pasteCommand } from "./paste-command.js";
15
- import { promptCommand } from "./prompt-command.js";
16
- import { resetCommand } from "./reset-command.js";
17
- import { rulesCommand } from "./rules-command.js";
18
- import { saveCommand } from "./save-command.js";
19
- import { usageCommand } from "./usage-command.js";
20
- export class CommandManager {
21
- commands;
22
- promptManager;
23
- modelManager;
24
- messageHistory;
25
- tokenTracker;
26
- terminal;
27
- config;
28
- tokenCounter;
29
- toolEvents;
30
- constructor({ promptManager, modelManager, terminal, messageHistory, tokenTracker, config, tokenCounter, toolEvents, }) {
31
- this.commands = new Map();
32
- this.promptManager = promptManager;
33
- this.modelManager = modelManager;
34
- this.terminal = terminal;
35
- this.messageHistory = messageHistory;
36
- this.tokenTracker = tokenTracker;
37
- this.config = config;
38
- this.tokenCounter = tokenCounter;
39
- this.toolEvents = toolEvents;
40
- this.initializeCommmands();
41
- }
42
- initializeCommmands() {
43
- // Import and register each command
44
- const options = {
45
- promptManager: this.promptManager,
46
- modelManager: this.modelManager,
47
- terminal: this.terminal,
48
- messageHistory: this.messageHistory,
49
- tokenTracker: this.tokenTracker,
50
- config: this.config,
51
- tokenCounter: this.tokenCounter,
52
- toolEvents: this.toolEvents,
53
- };
54
- // Register all commands
55
- const cmds = [
56
- clearCommand(options),
57
- compactCommand(options),
58
- editCommand(options),
59
- editPromptCommand(options),
60
- exitCommand(options),
61
- filesCommand(options),
62
- initCommand(options),
63
- pasteCommand(options),
64
- promptCommand(options),
65
- resetCommand(options),
66
- saveCommand(options),
67
- rulesCommand(options),
68
- modelCommand(options),
69
- usageCommand(options),
70
- lastLogCommand(options),
71
- generateRulesCommand(options),
72
- applicationLogCommand(options),
73
- copyCommand(options),
74
- ];
75
- // Add help command with access to all commands
76
- const helpCmd = helpCommand(options, this.commands);
77
- cmds.push({
78
- ...helpCmd,
79
- execute: () => helpCmd.execute([]),
80
- });
81
- // Register all commands
82
- for (const cmd of cmds) {
83
- this.commands.set(cmd.command, cmd);
84
- const aliases = cmd.aliases ?? [];
85
- for (const alias of aliases) {
86
- this.commands.set(alias, cmd);
87
- }
88
- }
89
- }
90
- getCommands() {
91
- return Array.from(this.commands.keys()).sort();
92
- }
93
- async getSubCommands(command) {
94
- return (await this.commands.get(command)?.getSubCommands()) ?? [];
95
- }
96
- async handle({ userInput }) {
97
- const commandArgs = userInput.split(" ");
98
- const command = commandArgs.at(0);
99
- const args = commandArgs.slice(1);
100
- if (command) {
101
- const replCommand = this.commands.get(command);
102
- if (replCommand) {
103
- await replCommand.execute(args);
104
- if (replCommand.result === "continue") {
105
- return {
106
- continue: true,
107
- break: false,
108
- };
109
- }
110
- if (replCommand.result === "break") {
111
- return {
112
- continue: false,
113
- break: true,
114
- };
115
- }
116
- }
117
- }
118
- return {
119
- continue: false,
120
- break: false,
121
- };
122
- }
123
- }
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare function modelCommand(options: CommandOptions): ReplCommand;
@@ -1,84 +0,0 @@
1
- import { formatModelInfo, getModelsByCategory, isValidModel, modelRegistry, models, providers, } from "../models/providers.js";
2
- export function modelCommand(options) {
3
- const { terminal, modelManager } = options;
4
- function switchModel(newModelName) {
5
- try {
6
- // Get current and new model configs
7
- const currentModelConfig = modelManager.getModelMetadata("repl");
8
- const newModelConfig = modelRegistry[newModelName]; // Ensure modelRegistry is available
9
- if (!newModelConfig) {
10
- terminal.error(`Model configuration not found for: ${newModelName}`);
11
- return;
12
- }
13
- // Check for capability differences
14
- if (currentModelConfig.supportsToolCalling &&
15
- !newModelConfig.supportsToolCalling) {
16
- terminal.warn("The new model doesn't support tool calling, which may limit functionality.");
17
- }
18
- if (currentModelConfig.supportsReasoning &&
19
- !newModelConfig.supportsReasoning) {
20
- terminal.warn("The new model doesn't support reasoning, which may change response quality.");
21
- }
22
- // Update model in ModelManager
23
- modelManager.setModel("repl", newModelName);
24
- // Assuming ModelManager handles the actual model instance switching internally.
25
- terminal.info(`Model set to ${newModelName}.`); // Simplified message
26
- }
27
- catch (error) {
28
- terminal.error(`Failed to switch model: ${error.message}`);
29
- }
30
- }
31
- return {
32
- command: "/model",
33
- description: "List available models or switch to a different model. Usage: /model [provider:model-name|category|provider]",
34
- result: "continue",
35
- getSubCommands: () => Promise.resolve(models),
36
- async execute(args) {
37
- const arg = args.join(" ").trim();
38
- const modelConfig = modelManager.getModelMetadata("repl");
39
- // No args - display current model and list available models by category
40
- if (!arg) {
41
- const currentModel = modelConfig.id;
42
- terminal.header(`Current model: ${currentModel}`);
43
- terminal.header("Available models by category:");
44
- // Display models by category
45
- for (const category of ["fast", "balanced", "powerful"]) {
46
- // Use 'as const' for stricter typing
47
- terminal.writeln(`\n${category.charAt(0).toUpperCase() + category.slice(1)} models:`);
48
- for (const model of getModelsByCategory(category)) {
49
- terminal.writeln(formatModelInfo(model));
50
- }
51
- }
52
- return;
53
- }
54
- // Switch to a specific model
55
- if (isValidModel(arg)) {
56
- // Call the standalone switchModel function
57
- switchModel(arg);
58
- return;
59
- }
60
- // Display models by category
61
- const categories = ["fast", "balanced", "powerful"];
62
- if (categories.includes(arg)) {
63
- terminal.header(`${arg.charAt(0).toUpperCase() + arg.slice(1)} models:`);
64
- // Need to assert arg is a valid category if the check passes
65
- for (const model of getModelsByCategory(arg)) {
66
- terminal.writeln(formatModelInfo(model));
67
- }
68
- return;
69
- }
70
- // Display models by provider
71
- if (providers.includes(arg)) {
72
- terminal.header(`Models from ${arg}:`);
73
- // Need to ensure modelRegistry is accessible and correctly typed
74
- for (const model of Object.values(modelRegistry).filter((m) => m.provider === arg)) {
75
- terminal.writeln(formatModelInfo(model));
76
- }
77
- return;
78
- }
79
- // Invalid model name
80
- terminal.error(`Invalid model name or category: ${arg}`);
81
- terminal.info("Usage: /model [provider:model-name|category|provider]");
82
- },
83
- };
84
- }
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare const pasteCommand: ({ terminal, modelManager, promptManager, }: CommandOptions) => ReplCommand;
@@ -1,40 +0,0 @@
1
- import Clipboard from "@crosscopy/clipboard";
2
- import { formatBlock } from "../formatting.js";
3
- import { logger } from "../logger.js";
4
- const base64UrlRegex = /^data:(.*?);base64,/;
5
- export const pasteCommand = ({ terminal, modelManager, promptManager, }) => {
6
- return {
7
- command: "/paste",
8
- description: "Pastes image or text content from the clipboard into the next prompt.",
9
- result: "continue",
10
- getSubCommands: () => Promise.resolve([]),
11
- execute: async () => {
12
- try {
13
- if (Clipboard.hasImage()) {
14
- const base64DataUrl = await Clipboard.getImageBase64();
15
- const mimeTypeMatch = base64DataUrl.match(base64UrlRegex);
16
- const mimeType = mimeTypeMatch ? mimeTypeMatch[1] : "image/png";
17
- promptManager.addContext({
18
- type: "image",
19
- image: base64DataUrl,
20
- mediaType: mimeType,
21
- });
22
- terminal.success("Image from clipboard will be added to your next prompt.");
23
- return;
24
- }
25
- const clipboardContent = await Clipboard.getText();
26
- if (!clipboardContent || clipboardContent.trim() === "") {
27
- terminal.warn("Clipboard is empty.");
28
- return;
29
- }
30
- promptManager.addContext(formatBlock(clipboardContent, "clipboard", modelManager.getModelMetadata("repl").promptFormat));
31
- terminal.success("Clipboard content will be added to your next prompt.");
32
- }
33
- catch (error) {
34
- const message = error instanceof Error ? error.message : String(error);
35
- terminal.error(`Error processing clipboard content: ${message}`);
36
- logger.error(error, "Paste command error:");
37
- }
38
- },
39
- };
40
- };
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare const promptCommand: ({ terminal, modelManager, promptManager, config, }: CommandOptions) => ReplCommand;
@@ -1,111 +0,0 @@
1
- import { readdir, readFile } from "node:fs/promises";
2
- import path, { basename } from "node:path";
3
- import { processPrompt } from "../mentions.js";
4
- export const promptCommand = ({ terminal, modelManager, promptManager, config, }) => {
5
- return {
6
- command: "/prompt",
7
- description: "Loads and executes prompts. Project prompts override user prompts with the same name.",
8
- result: "use",
9
- getSubCommands: async () => {
10
- const getPromptNamesFromDir = async (dirPath) => {
11
- try {
12
- const dirents = await readdir(dirPath, { withFileTypes: true });
13
- return dirents
14
- .filter((dirent) => dirent.isFile() && dirent.name.endsWith(".md"))
15
- .map((dirent) => basename(dirent.name, ".md"));
16
- }
17
- catch (error) {
18
- if (error.code === "ENOENT") {
19
- return []; // Directory doesn't exist, return empty array
20
- }
21
- terminal.error(`Error reading prompts from ${dirPath}: ${error}`);
22
- return []; // Return empty on other errors too, but log them
23
- }
24
- };
25
- const userPromptDir = config.app.ensurePathSync("prompts"); // User prompts are global (~/.acai/prompts)
26
- const projectPromptDir = config.project.ensurePathSync("prompts"); // Project prompts are local (./.acai/prompts)
27
- const userPrompts = await getPromptNamesFromDir(userPromptDir);
28
- const projectPrompts = await getPromptNamesFromDir(projectPromptDir);
29
- // Combine and deduplicate, with project prompts taking precedence
30
- const allPrompts = new Set([...userPrompts, ...projectPrompts]);
31
- return Array.from(allPrompts).sort();
32
- },
33
- execute: async (args) => {
34
- const promptName = args?.[0];
35
- if (!promptName) {
36
- terminal.warn("Please provide a prompt name. Usage: /prompt <prompt-name> [input...]");
37
- return;
38
- }
39
- // Check for old format and provide helpful error
40
- if (promptName.includes(":")) {
41
- terminal.warn("The old format (user:name or project:name) is no longer supported. Use: /prompt <prompt-name> [input...]");
42
- return;
43
- }
44
- try {
45
- const promptResult = await findPrompt(promptName, config);
46
- if (!promptResult) {
47
- terminal.error(`Prompt not found: ${promptName}. Available prompts can be seen with tab completion.`);
48
- return;
49
- }
50
- let promptContent;
51
- try {
52
- promptContent = await readFile(promptResult.path, "utf8");
53
- }
54
- catch (error) {
55
- if (error.code === "ENOENT") {
56
- terminal.error(`Prompt file not found: ${promptName} at ${promptResult.path}`);
57
- return;
58
- }
59
- throw error;
60
- }
61
- // Combine remaining arguments into a single string for input
62
- const inputArgs = args.slice(1);
63
- const inputString = inputArgs.join(" ");
64
- // Replace {{INPUT}} placeholder with the input string
65
- if (promptContent.includes("{{INPUT}}")) {
66
- promptContent = promptContent.replace(/{{INPUT}}/g, inputString);
67
- }
68
- terminal.info(`Loaded ${promptResult.type} prompt: ${promptName}`);
69
- if (inputArgs.length > 0) {
70
- terminal.info(`Input: "${inputString}"`);
71
- }
72
- const processedPrompt = await processPrompt(promptContent, {
73
- baseDir: process.cwd(),
74
- model: modelManager.getModelMetadata("repl"),
75
- });
76
- for (const context of processedPrompt.context) {
77
- promptManager.addContext(context);
78
- }
79
- promptManager.set(processedPrompt.message);
80
- }
81
- catch (error) {
82
- terminal.error(`Error loading prompt: ${error.message}`);
83
- }
84
- },
85
- };
86
- };
87
- async function findPrompt(promptName, config) {
88
- // Check project prompts first (they take precedence)
89
- const projectPath = path.join(config.project.ensurePathSync("prompts"), `${promptName}.md`);
90
- try {
91
- await readFile(projectPath, "utf8");
92
- return { path: projectPath, type: "project" };
93
- }
94
- catch (error) {
95
- if (error.code !== "ENOENT") {
96
- throw error; // Re-throw non-file-not-found errors
97
- }
98
- }
99
- // Check user prompts if not found in project
100
- const userPath = path.join(config.app.ensurePathSync("prompts"), `${promptName}.md`);
101
- try {
102
- await readFile(userPath, "utf8");
103
- return { path: userPath, type: "user" };
104
- }
105
- catch (error) {
106
- if (error.code !== "ENOENT") {
107
- throw error; // Re-throw non-file-not-found errors
108
- }
109
- }
110
- return null; // Prompt not found in either location
111
- }
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare const resetCommand: ({ terminal, messageHistory, }: CommandOptions) => ReplCommand;
@@ -1,16 +0,0 @@
1
- export const resetCommand = ({ terminal, messageHistory, }) => {
2
- return {
3
- command: "/reset",
4
- description: "Saves the chat history and then resets it.",
5
- result: "continue",
6
- getSubCommands: () => Promise.resolve([]),
7
- execute: async () => {
8
- if (!messageHistory.isEmpty()) {
9
- await messageHistory.save();
10
- messageHistory.clear();
11
- }
12
- terminal.setTitle(`acai: ${process.cwd()}`);
13
- terminal.clear();
14
- },
15
- };
16
- };
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare const rulesCommand: ({ terminal }: CommandOptions) => ReplCommand;
@@ -1,68 +0,0 @@
1
- import { editor } from "@inquirer/prompts";
2
- import { config } from "../config.js";
3
- export const rulesCommand = ({ terminal }) => {
4
- return {
5
- command: "/rules",
6
- description: "View, add, or edit rules. Usage: /rules [view|add <text>|edit]",
7
- result: "continue",
8
- getSubCommands: () => Promise.resolve(["view", "add", "edit"]),
9
- execute: async (args) => {
10
- const subCommand = args[0] ?? "view"; // Default to 'view'
11
- const commandArgs = args.slice(1).join(" ");
12
- try {
13
- switch (subCommand) {
14
- case "view": {
15
- const currentContent = await config.readAgentsFile();
16
- if (currentContent) {
17
- terminal.writeln("--- Current Rules ---");
18
- terminal.writeln(currentContent);
19
- terminal.writeln("---------------------");
20
- }
21
- else {
22
- terminal.writeln("No rules defined yet. Use '/rules add' or '/rules edit'.");
23
- }
24
- break;
25
- }
26
- case "add": {
27
- const newMemory = commandArgs.trim();
28
- if (!newMemory) {
29
- terminal.error("Error: Memory text cannot be empty for 'add'.");
30
- terminal.writeln("Usage: /memory add <new memory text>");
31
- return;
32
- }
33
- const currentContent = await config.readAgentsFile();
34
- const updatedContent = currentContent
35
- ? `${currentContent.trim()}\n- ${newMemory}` // Ensure space after dash
36
- : `- ${newMemory}`; // Start with dash if new file
37
- await config.writeAgentsFile(updatedContent);
38
- break;
39
- }
40
- case "edit": {
41
- const currentContent = await config.readAgentsFile();
42
- const updatedContent = await editor({
43
- message: "Edit rules:",
44
- postfix: "md",
45
- default: currentContent,
46
- });
47
- // Check if the user cancelled the edit (editor returns the original content)
48
- // Or if the content is actually different
49
- if (updatedContent !== currentContent) {
50
- await config.writeAgentsFile(updatedContent);
51
- }
52
- else {
53
- terminal.writeln("Edit cancelled or no changes made.");
54
- }
55
- break;
56
- }
57
- default:
58
- terminal.writeln("Invalid subcommand. Usage: /rules [view|add <text>|edit]");
59
- break;
60
- }
61
- }
62
- catch (_error) {
63
- // Errors from read/write helpers are already logged
64
- terminal.error("Failed to execute memory command.");
65
- }
66
- },
67
- };
68
- };
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare const saveCommand: ({ messageHistory, terminal, }: CommandOptions) => ReplCommand;
@@ -1,14 +0,0 @@
1
- export const saveCommand = ({ messageHistory, terminal, }) => {
2
- return {
3
- command: "/save",
4
- description: "Saves the chat history.",
5
- result: "continue",
6
- getSubCommands: () => Promise.resolve([]),
7
- execute: async () => {
8
- if (!messageHistory.isEmpty()) {
9
- await messageHistory.save();
10
- }
11
- terminal.info("Message history saved.");
12
- },
13
- };
14
- };
@@ -1,26 +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
- export interface ReplCommand {
10
- command: string;
11
- aliases?: string[];
12
- description: string;
13
- result: "break" | "continue" | "use";
14
- getSubCommands: () => Promise<string[]>;
15
- execute: (args: string[]) => Promise<void>;
16
- }
17
- export interface CommandOptions {
18
- promptManager: PromptManager;
19
- modelManager: ModelManager;
20
- terminal: Terminal;
21
- messageHistory: MessageHistory;
22
- tokenTracker: TokenTracker;
23
- config: ConfigManager;
24
- tokenCounter: TokenCounter;
25
- toolEvents: Map<string, Message[]>;
26
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import type { CommandOptions, ReplCommand } from "./types.ts";
2
- export declare function usageCommand({ terminal, tokenTracker, }: CommandOptions): ReplCommand;