@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,13 +0,0 @@
1
- import type { TokenCounter } from "../token-utils.ts";
2
- import type { SendData } from "./types.ts";
3
- export declare const WebSearchTool: {
4
- name: "webSearch";
5
- };
6
- export declare const createWebSearchTool: ({ sendData, tokenCounter, }: {
7
- sendData?: SendData;
8
- tokenCounter: TokenCounter;
9
- }) => {
10
- webSearch: import("ai").Tool<{
11
- query: string;
12
- }, string>;
13
- };
@@ -1,80 +0,0 @@
1
- import { tool } from "ai";
2
- import chalk from "chalk";
3
- import { SafeSearchType, search } from "duck-duck-scrape";
4
- import Exa from "exa-js";
5
- import { z } from "zod";
6
- export const WebSearchTool = {
7
- name: "webSearch",
8
- };
9
- export const createWebSearchTool = ({ sendData, tokenCounter, }) => {
10
- return {
11
- [WebSearchTool.name]: tool({
12
- description: "Searches the web and returns match documents with their title, url, and text content. The query should be formulated as a natural language question.",
13
- inputSchema: z.object({
14
- query: z.string().describe("The search query."),
15
- }),
16
- execute: async ({ query }, { toolCallId }) => {
17
- sendData?.({
18
- id: toolCallId,
19
- event: "tool-init",
20
- data: `Web search: ${chalk.cyan(query)}`,
21
- });
22
- const result = await performSearch(query);
23
- const sources = result.results.map((source) => `## ${source.title}\nURL: ${source.url}\n\n${source.text}`);
24
- const resultText = `# Search Results:\n\n${sources.join("\n\n")}`;
25
- const tokenCount = tokenCounter.count(resultText);
26
- sendData?.({
27
- id: toolCallId,
28
- event: "tool-completion",
29
- data: `Found ${result.results.length} results. (${tokenCount} tokens)`,
30
- });
31
- return resultText;
32
- },
33
- }),
34
- };
35
- };
36
- async function performSearch(query) {
37
- // Check if EXA API key is available
38
- const hasExaApiKey = process.env["EXA_API_KEY"] && process.env["EXA_API_KEY"].trim() !== "";
39
- if (hasExaApiKey) {
40
- // Use Exa search
41
- try {
42
- const exa = new Exa(process.env["EXA_API_KEY"]);
43
- const result = await exa.searchAndContents(query, {
44
- numResults: 5,
45
- text: true,
46
- });
47
- return result;
48
- }
49
- catch (error) {
50
- // If Exa fails, fall back to duck duck scrape
51
- console.info("Exa search failed, falling back to DuckDuckGo:", error);
52
- return await searchWithDuckDuckGo(query);
53
- }
54
- }
55
- else {
56
- // Use DuckDuckGo search as fallback
57
- console.info("EXA_API_KEY not set, using DuckDuckGo search");
58
- return await searchWithDuckDuckGo(query);
59
- }
60
- }
61
- async function searchWithDuckDuckGo(query) {
62
- try {
63
- const searchResults = await search(query, {
64
- safeSearch: SafeSearchType.MODERATE,
65
- });
66
- // Transform duck-duck-scrape results to match Exa format
67
- // Take only first 5 results to match Exa behavior
68
- const results = searchResults.results
69
- .slice(0, 5)
70
- .map((result) => ({
71
- title: result.title,
72
- url: result.url,
73
- text: result.description || "",
74
- }));
75
- return { results };
76
- }
77
- catch (error) {
78
- throw new Error(`Failed to perform web search: ${error}`);
79
- }
80
- }
@@ -1,36 +0,0 @@
1
- interface ExecuteOptions {
2
- /** Working directory where the command will be executed */
3
- cwd?: string;
4
- /** Timeout in milliseconds before killing the process */
5
- timeout?: number;
6
- /** AbortSignal to cancel the execution */
7
- abortSignal?: AbortSignal;
8
- /** Whether to use shell syntax (defaults to false) */
9
- shell?: boolean;
10
- /** Whether to throw an error on non-zero exit codes (defaults to false) */
11
- throwOnError?: boolean;
12
- /** Whether to include stdout/stderr in the result even when there's an error (defaults to true) */
13
- preserveOutputOnError?: boolean;
14
- /** Maximum buffer size in bytes (defaults to 1MB) */
15
- maxBuffer?: number;
16
- }
17
- export interface ExecuteResult {
18
- /** Standard output from the command */
19
- stdout: string;
20
- /** Standard error from the command */
21
- stderr: string;
22
- /** Exit code (0 for success, non-zero for errors) */
23
- code: number;
24
- /** The signal that terminated the process, if any */
25
- signal?: NodeJS.Signals;
26
- }
27
- /**
28
- * Executes a command and returns the result, providing unified error handling
29
- *
30
- * @param command Either a string command with arguments or an array where the first item is the command
31
- * and the rest are arguments
32
- * @param options Execution options
33
- * @returns Promise resolving to an object containing stdout, stderr, and exit code
34
- */
35
- export declare function executeCommand(command: string | [string, ...string[]], options?: ExecuteOptions): Promise<ExecuteResult>;
36
- export {};
@@ -1,75 +0,0 @@
1
- import { execFile } from "node:child_process";
2
- import { isUndefined } from "@travisennis/stdlib/typeguards";
3
- const MS_IN_SECOND = 1000;
4
- const SECONDS_IN_MINUTE = 60;
5
- const DEFAULT_TIMEOUT = 2 * SECONDS_IN_MINUTE * MS_IN_SECOND;
6
- /**
7
- * Executes a command and returns the result, providing unified error handling
8
- *
9
- * @param command Either a string command with arguments or an array where the first item is the command
10
- * and the rest are arguments
11
- * @param options Execution options
12
- * @returns Promise resolving to an object containing stdout, stderr, and exit code
13
- */
14
- export function executeCommand(command, options) {
15
- const { cwd = process.cwd(), timeout = DEFAULT_TIMEOUT, abortSignal, shell = false, throwOnError = false, preserveOutputOnError = true, maxBuffer = 1_000_000, } = options || {};
16
- let cmd;
17
- let args;
18
- if (Array.isArray(command)) {
19
- [cmd, ...args] = command;
20
- }
21
- else {
22
- const parts = command.split(" ");
23
- cmd = parts[0] ?? "";
24
- args = parts.slice(1);
25
- }
26
- if (isUndefined(cmd) || cmd.trim() === "") {
27
- const result = {
28
- stdout: "",
29
- stderr: "Missing command",
30
- code: 1,
31
- };
32
- return throwOnError
33
- ? Promise.reject(new Error("Missing command"))
34
- : Promise.resolve(result);
35
- }
36
- return new Promise((resolve, reject) => {
37
- try {
38
- execFile(cmd, args, {
39
- cwd,
40
- timeout,
41
- signal: abortSignal,
42
- shell,
43
- maxBuffer,
44
- }, (error, stdout, stderr) => {
45
- if (error) {
46
- const errorCode = typeof error.code === "number" ? error.code : 1;
47
- const result = {
48
- stdout: preserveOutputOnError ? stdout : "",
49
- stderr: preserveOutputOnError ? stderr : "",
50
- code: errorCode,
51
- signal: error.signal ?? undefined,
52
- };
53
- if (throwOnError) {
54
- reject(Object.assign(error, { result }));
55
- }
56
- else {
57
- resolve(result);
58
- }
59
- }
60
- else {
61
- resolve({ stdout, stderr, code: 0 });
62
- }
63
- });
64
- }
65
- catch (error) {
66
- const result = { stdout: "", stderr: "", code: 1 };
67
- if (throwOnError) {
68
- reject(error);
69
- }
70
- else {
71
- resolve(result);
72
- }
73
- }
74
- });
75
- }
@@ -1 +0,0 @@
1
- export declare function getPackageVersion(fallback?: string): string;
@@ -1,21 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "@travisennis/stdlib/desm";
3
- export function getPackageVersion(fallback = "unavailable") {
4
- try {
5
- const pkgPath = join(import.meta.url, "..", "package.json");
6
- const pkgRaw = readFileSync(pkgPath, "utf8");
7
- const parsed = JSON.parse(pkgRaw);
8
- const v = typeof parsed.version === "string" ? parsed.version : undefined;
9
- if (v && v.length > 0) {
10
- return v;
11
- }
12
- }
13
- catch {
14
- // ignore
15
- }
16
- const envV = process.env["npm_package_version"];
17
- if (typeof envV === "string" && envV.length > 0) {
18
- return envV;
19
- }
20
- return fallback;
21
- }
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings
2
- /**
3
- * Terminal Output Test Module
4
- *
5
- * Exercises all methods and features of the Terminal class for testing purposes.
6
- * Demonstrates various markdown rendering capabilities.
7
- */
8
- export {};
@@ -1,213 +0,0 @@
1
- #!/usr/bin/env -S node --no-warnings
2
- /**
3
- * Terminal Output Test Module
4
- *
5
- * Exercises all methods and features of the Terminal class for testing purposes.
6
- * Demonstrates various markdown rendering capabilities.
7
- */
8
- import { initTerminal } from "./terminal/index.js";
9
- // Initialize terminal
10
- const terminal = initTerminal({
11
- useColors: true,
12
- showProgressIndicators: true,
13
- });
14
- // Test all terminal methods and features
15
- function testTerminalOutput() {
16
- // Clear screen and show welcome
17
- terminal.clear();
18
- terminal.displayWelcome();
19
- // Test basic output methods
20
- terminal.header("Basic Output Methods");
21
- terminal.writeln("This is a basic write line");
22
- terminal.write("This is a basic write without newline");
23
- terminal.lineBreak();
24
- terminal.emphasize("This is emphasized text");
25
- terminal.info("This is an info message");
26
- terminal.success("This is a success message");
27
- terminal.warn("This is a warning message");
28
- terminal.error("This is an error message");
29
- terminal.lineBreak();
30
- // Test markdown display
31
- terminal.header("Markdown Display Features");
32
- // Headers
33
- terminal.display("# This is an H1 Header");
34
- terminal.display("## This is an H2 Header");
35
- terminal.display("### This is an H3 Header");
36
- terminal.display("#### This is an H4 Header");
37
- terminal.display("##### This is an H5 Header");
38
- terminal.display("###### This is an H6 Header");
39
- // Text formatting
40
- terminal.display("**This is bold text**");
41
- terminal.display("*This is italic text*");
42
- terminal.display("***This is bold and italic text***");
43
- terminal.display("This is `inline code` text");
44
- terminal.display("~~This is strikethrough text~~");
45
- // Links
46
- terminal.display("This is a [link](https://example.com)");
47
- // Images
48
- terminal.display("This is an ![image](https://example.com/image.jpg)");
49
- // Blockquotes
50
- terminal.display("> This is a blockquote");
51
- terminal.display("> This is a\n> multi-line blockquote");
52
- // Horizontal rule
53
- terminal.display("---");
54
- // Lists
55
- terminal.display("- This is an unordered list item");
56
- terminal.display("- This is another unordered list item");
57
- terminal.display(" - This is a nested list item");
58
- terminal.display(" - This is a double nested list item");
59
- terminal.display("1. This is an ordered list item");
60
- terminal.display("2. This is another ordered list item");
61
- terminal.display(" 1. This is a nested ordered list item");
62
- terminal.display(" 2. This is another nested ordered list item");
63
- // Code blocks
64
- terminal.display("```javascript\nconst greeting = 'Hello World';\nconsole.log(greeting);\n```");
65
- terminal.display("```python\ndef hello():\n print('Hello World')\n```");
66
- terminal.display("```\nThis is a plain code block\n```");
67
- // Tables
68
- terminal.display("| Header 1 | Header 2 | Header 3 |\n|----------|----------|----------|\n| Cell 1 | Cell 2 | Cell 3 |\n| Cell 4 | Cell 5 | Cell 6 |");
69
- // Paragraphs
70
- terminal.display("This is a paragraph with some **bold** and *italic* text. " +
71
- "It also contains `inline code` and a [link](https://example.com). " +
72
- "Here's an ![image](image.jpg) for good measure.");
73
- terminal.display("This is another paragraph that demonstrates how line breaks work " +
74
- "in markdown with the terminal display. It should wrap appropriately based " +
75
- "on the terminal width.");
76
- // Complex markdown example
77
- const complexMarkdown = `
78
- # Complex Markdown Example
79
-
80
- This is a complex example showing various **markdown** features in *one* document.
81
-
82
- ## Features Demonstrated
83
-
84
- 1. **Headers** of different levels
85
- 2. *Text formatting* options
86
- 3. \`Code elements\` of various types
87
- 4. [External links](https://example.com)
88
- 5. ![Images](image.jpg)
89
- 6. Blockquotes
90
-
91
- > Blockquotes
92
-
93
- 7. Horizontal rules
94
- 8. Lists (ordered and unordered)
95
- 9. Tables
96
- 10. Code blocks
97
-
98
- ## Code Example
99
-
100
- Here's some JavaScript code:
101
-
102
- \`\`\`javascript
103
- function fibonacci(n) {
104
- if (n <= 1) return n;
105
- return fibonacci(n - 1) + fibonacci(n - 2);
106
- }
107
-
108
- console.log(fibonacci(10)); // 55
109
- \`\`\`
110
-
111
- ## Table Example
112
-
113
- | Name | Age | City |
114
- |------|-----|------|
115
- | John | 30 | New York |
116
- | Jane | 25 | Boston |
117
- | Bob | 35 | Chicago |
118
-
119
- ## Blockquote Example
120
-
121
- > This is a blockquote.
122
- >
123
- > It can span multiple lines.
124
- >
125
- > > It can also contain nested blockquotes.
126
-
127
- ---
128
-
129
- ## List Examples
130
-
131
- ### Unordered List
132
-
133
- - Item 1
134
- - Item 2
135
- - Nested item 2.1
136
- - Nested item 2.2
137
- - Double nested item 2.2.1
138
- - Item 3
139
-
140
- ### Ordered List
141
-
142
- 1. First item
143
- 2. Second item
144
- 1. Nested item 2.1
145
- 2. Nested item 2.2
146
- 1. Double nested item 2.2.1
147
- 3. Third item
148
-
149
- ## Inline Elements
150
-
151
- This paragraph contains **bold text**, *italic text*, \`inline code\`,
152
- ~~strikethrough text~~, [a link](https://example.com), and ![an image](image.jpg).
153
-
154
- The end of this complex example.
155
- `;
156
- terminal.header("Complex Markdown Example");
157
- terminal.display(complexMarkdown);
158
- // Test other terminal features
159
- terminal.header("Other Terminal Features");
160
- // Box display
161
- terminal.box("Info Box", "This is content inside a box with a header");
162
- terminal.box("Code", `
163
- \`\`\`javascript
164
- function fibonacci(n) {
165
- if (n <= 1) return n;
166
- return fibonacci(n - 1) + fibonacci(n - 2);
167
- }
168
-
169
- console.log(fibonacci(10)); // 55
170
- \`\`\`
171
- `);
172
- terminal.box("Markdown Block", `
173
- This paragraph contains **bold text**, *italic text*, \`inline code\`,
174
- ~~strikethrough text~~, [a link](https://example.com), and ![an image](image.jpg).
175
- `);
176
- // Horizontal rule
177
- terminal.hr();
178
- // Table
179
- terminal.table([
180
- ["Headers", "Working"],
181
- ["Text Formatting", "Working"],
182
- ["Lists", "Working"],
183
- ["Code Blocks", "Working"],
184
- ["Tables", "Working"],
185
- ["Links", "Working"],
186
- ["Images", "Working"],
187
- ["Blockquotes", "Working"],
188
- ], { header: ["Feature", "Status"] });
189
- // Progress bar
190
- terminal.header("Progress Bar Example");
191
- for (let i = 0; i <= 100; i += 10) {
192
- terminal.displayProgressBar(i, 100);
193
- }
194
- // Spinner (demonstration)
195
- // terminal.header("Spinner Example");
196
- // const spinner = terminal.spinner("Loading...");
197
- // setTimeout(() => {
198
- // spinner.succeed("Loading complete!");
199
- // }, 2000);
200
- // Terminal info
201
- terminal.header("Terminal Information");
202
- terminal.writeln(`Terminal size: ${terminal["terminalWidth"]}x${terminal["terminalHeight"]}`);
203
- terminal.writeln(`Is interactive: ${terminal["isInteractive"]}`);
204
- // Link example
205
- terminal.header("Link Example");
206
- terminal.writeln(`Visit ${terminal.link("Google", "https://google.com")} for search`);
207
- // Alert
208
- terminal.alert();
209
- // Final message
210
- terminal.success("All terminal features tested successfully!");
211
- }
212
- // Run the test
213
- testTerminalOutput();
@@ -1,13 +0,0 @@
1
- import type { SendData } from "./types.ts";
2
- export declare const MemoryReadTool: {
3
- name: "memoryRead";
4
- };
5
- export declare const createMemoryReadTool: (options?: {
6
- sendData?: SendData | undefined;
7
- }) => {
8
- memoryRead: import("ai").Tool<{
9
- filePath: string | null;
10
- }, string | {
11
- content: string;
12
- }>;
13
- };
@@ -1,135 +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.js";
6
- export const MemoryReadTool = {
7
- name: "memoryRead",
8
- };
9
- const MEMORY_DIR = config.app.ensurePathSync("memory");
10
- // Helper to check if a file exists
11
- // Moved to module level as it does not use sendData
12
- async function fileExists(filePath) {
13
- try {
14
- await access(filePath);
15
- return true;
16
- }
17
- catch {
18
- return false;
19
- }
20
- }
21
- // Helper function, does not use sendData directly
22
- const _readSpecificMemoryFile = async (resolvedMemoryDir, filePath) => {
23
- const normalizedRelativePath = normalize(filePath);
24
- if (normalizedRelativePath.startsWith("..") ||
25
- normalizedRelativePath.includes("..") ||
26
- isAbsolute(normalizedRelativePath)) {
27
- throw new Error(`Error: Invalid filePath "${filePath}". Must be a relative path and cannot use '..'.`);
28
- }
29
- const fullPath = join(resolvedMemoryDir, normalizedRelativePath);
30
- if (!fullPath.startsWith(resolvedMemoryDir + sep) &&
31
- fullPath !== resolvedMemoryDir) {
32
- throw new Error(`Error: Path "${filePath}" resolves outside the allowed memory directory.`);
33
- }
34
- if (!(await fileExists(fullPath))) {
35
- throw new Error(`Error: Memory file '${filePath}' does not exist.`);
36
- }
37
- const stats = await lstat(fullPath);
38
- if (stats.isDirectory()) {
39
- throw new Error(`Error: '${filePath}' is a directory. Please provide a path to a file to read.`);
40
- }
41
- const content = await readFile(fullPath, "utf-8");
42
- return { filePath, content };
43
- };
44
- // Helper function, does not use sendData directly
45
- const _listMemoryFilesAndIndex = async (resolvedMemoryDir) => {
46
- const entries = await readdir(resolvedMemoryDir, {
47
- recursive: true,
48
- withFileTypes: true,
49
- });
50
- const filesOnly = entries
51
- .filter((entry) => entry.isFile())
52
- .map((entry) => join(entry.parentPath ?? resolvedMemoryDir, entry.name)); // entry.path is available with recursive
53
- const fileListString = filesOnly.length > 0
54
- ? filesOnly
55
- .map((p) => `- ${normalize(p.replace(resolvedMemoryDir + sep, ""))}`)
56
- .join("\n") // Show relative paths
57
- : "No files in memory.";
58
- const indexPath = join(resolvedMemoryDir, "index.md");
59
- let indexContent = "(empty)";
60
- if (await fileExists(indexPath)) {
61
- const stats = await lstat(indexPath);
62
- if (stats.isFile()) {
63
- indexContent = await readFile(indexPath, "utf-8");
64
- }
65
- }
66
- const output = `Root memory file (index.md):
67
- '''
68
- ${indexContent}
69
- '''
70
-
71
- Files in the memory directory:
72
- ${fileListString}`;
73
- return { content: output };
74
- };
75
- export const createMemoryReadTool = (options = {}) => {
76
- const { sendData } = options;
77
- const memoryReadTool = tool({
78
- description: 'Read from memory files. If no path is provided, lists all files and shows content of "index.md".',
79
- inputSchema: z.object({
80
- filePath: z
81
- .string()
82
- .nullable()
83
- .describe('Optional path to a specific memory file to read, relative to the memory directory. Cannot use ".." or absolute paths.'),
84
- }),
85
- execute: async ({ filePath }, { toolCallId }) => {
86
- sendData?.({
87
- event: "tool-init",
88
- id: toolCallId,
89
- data: "Initializing memory read...",
90
- });
91
- const resolvedMemoryDir = resolve(MEMORY_DIR);
92
- try {
93
- await mkdir(resolvedMemoryDir, { recursive: true });
94
- let result;
95
- if (filePath) {
96
- sendData?.({
97
- event: "tool-update",
98
- id: toolCallId,
99
- data: { primary: "Reading file:", secondary: [filePath] },
100
- });
101
- result = await _readSpecificMemoryFile(resolvedMemoryDir, filePath);
102
- }
103
- else {
104
- sendData?.({
105
- event: "tool-update",
106
- id: toolCallId,
107
- data: { primary: "Listing memory files and index" },
108
- });
109
- result = await _listMemoryFilesAndIndex(resolvedMemoryDir);
110
- }
111
- sendData?.({
112
- event: "tool-completion",
113
- id: toolCallId,
114
- data: "Done",
115
- });
116
- return result;
117
- }
118
- catch (error) {
119
- let errorMsg = "Error reading memory: An unknown error occurred";
120
- if (error instanceof Error) {
121
- errorMsg = `Error reading memory: ${error.message}`;
122
- }
123
- sendData?.({
124
- event: "tool-error",
125
- id: toolCallId,
126
- data: errorMsg,
127
- });
128
- return errorMsg;
129
- }
130
- },
131
- });
132
- return {
133
- [MemoryReadTool.name]: memoryReadTool,
134
- };
135
- };
@@ -1,12 +0,0 @@
1
- import type { SendData } from "./types.ts";
2
- export declare const MemoryWriteTool: {
3
- name: "memoryWrite";
4
- };
5
- export declare const createMemoryWriteTool: (options?: {
6
- sendData?: SendData | undefined;
7
- }) => {
8
- memoryWrite: import("ai").Tool<{
9
- filePath: string;
10
- content: string;
11
- }, string>;
12
- };