@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,21 +0,0 @@
1
- export function usageCommand({ terminal, tokenTracker, }) {
2
- return {
3
- command: "/usage",
4
- description: "Show token usage breakdown",
5
- result: "continue",
6
- getSubCommands: () => Promise.resolve([]),
7
- execute() {
8
- const entries = Object.entries(tokenTracker.getUsageBreakdown());
9
- if (entries.length === 0) {
10
- terminal.info("No usage yet.");
11
- }
12
- else {
13
- terminal.table(entries, {
14
- header: ["App", "Tokens"],
15
- colWidths: [30, 70],
16
- });
17
- }
18
- return Promise.resolve();
19
- },
20
- };
21
- }
@@ -1,60 +0,0 @@
1
- import { z } from "zod";
2
- export declare class DirectoryProvider {
3
- private baseDir;
4
- constructor(baseDir: string);
5
- getPath(subdir?: string): string;
6
- ensurePath(subdir?: string): Promise<string>;
7
- ensurePathSync(subdir?: string): string;
8
- }
9
- export declare class ConfigManager {
10
- readonly project: DirectoryProvider;
11
- readonly app: DirectoryProvider;
12
- constructor();
13
- private _readConfig;
14
- readProjectConfig(): Promise<ProjectConfig>;
15
- readAgentsFile(): Promise<string>;
16
- writeAgentsFile(rules: string): Promise<void>;
17
- readProjectLearnedRulesFile(): Promise<string>;
18
- writeProjectLearnedRulesFile(rules: string): Promise<void>;
19
- readCachedLearnedRulesFile(): Promise<string>;
20
- writeCachedLearnedRulesFile(rules: string): Promise<void>;
21
- readAppConfig(configName: string): Promise<Record<PropertyKey, unknown>>;
22
- ensureAppConfig(configName: string): Promise<Record<PropertyKey, unknown>>;
23
- writeAppConfig(configName: string, data: Record<PropertyKey, unknown>): Promise<void>;
24
- }
25
- declare const ProjectConfigSchema: z.ZodObject<{
26
- logs: z.ZodOptional<z.ZodObject<{
27
- path: z.ZodString;
28
- }, "strip", z.ZodTypeAny, {
29
- path: string;
30
- }, {
31
- path: string;
32
- }>>;
33
- tools: z.ZodDefault<z.ZodOptional<z.ZodObject<{
34
- maxTokens: z.ZodDefault<z.ZodNumber>;
35
- }, "strip", z.ZodTypeAny, {
36
- maxTokens: number;
37
- }, {
38
- maxTokens?: number | undefined;
39
- }>>>;
40
- notify: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
41
- }, "strip", z.ZodTypeAny, {
42
- tools: {
43
- maxTokens: number;
44
- };
45
- notify: boolean;
46
- logs?: {
47
- path: string;
48
- } | undefined;
49
- }, {
50
- logs?: {
51
- path: string;
52
- } | undefined;
53
- tools?: {
54
- maxTokens?: number | undefined;
55
- } | undefined;
56
- notify?: boolean | undefined;
57
- }>;
58
- export type ProjectConfig = z.infer<typeof ProjectConfigSchema>;
59
- export declare const config: ConfigManager;
60
- export {};
@@ -1,193 +0,0 @@
1
- import { mkdirSync } from "node:fs";
2
- import fs from "node:fs/promises";
3
- import { homedir } from "node:os";
4
- import path from "node:path";
5
- import { z } from "zod";
6
- import { jsonParser } from "./parsing.js";
7
- export class DirectoryProvider {
8
- baseDir;
9
- constructor(baseDir) {
10
- this.baseDir = baseDir;
11
- }
12
- getPath(subdir) {
13
- return subdir ? path.join(this.baseDir, subdir) : this.baseDir;
14
- }
15
- // Async-by-default: prefer non-blocking filesystem operations.
16
- async ensurePath(subdir) {
17
- const dirPath = this.getPath(subdir);
18
- await fs.mkdir(dirPath, { recursive: true });
19
- return dirPath;
20
- }
21
- // Synchronous helper for call-sites that require immediate directory availability.
22
- ensurePathSync(subdir) {
23
- const dirPath = this.getPath(subdir);
24
- mkdirSync(dirPath, { recursive: true });
25
- return dirPath;
26
- }
27
- }
28
- export class ConfigManager {
29
- project;
30
- app;
31
- constructor() {
32
- this.project = new DirectoryProvider(path.join(process.cwd(), ".acai"));
33
- this.app = new DirectoryProvider(path.join(homedir(), ".acai"));
34
- }
35
- async _readConfig(configPath) {
36
- try {
37
- const data = await fs.readFile(configPath, "utf8");
38
- return jsonParser(ProjectConfigSchema).parse(data);
39
- }
40
- catch (error) {
41
- if (error.code === "ENOENT") {
42
- return {};
43
- }
44
- throw error;
45
- }
46
- }
47
- // Project config helpers
48
- async readProjectConfig() {
49
- const appConfigPath = path.join(this.app.getPath(), "acai.json");
50
- const projectConfigPath = path.join(this.project.getPath(), "acai.json");
51
- const appConfig = await this._readConfig(appConfigPath);
52
- const projectConfig = await this._readConfig(projectConfigPath);
53
- const mergedConfig = {
54
- ...appConfig,
55
- ...projectConfig,
56
- };
57
- return ProjectConfigSchema.parse(mergedConfig);
58
- }
59
- async readAgentsFile() {
60
- const agentsPath = path.join(process.cwd(), "AGENTS.md");
61
- try {
62
- return await fs.readFile(agentsPath, "utf8");
63
- }
64
- catch (error) {
65
- if (error.code === "ENOENT") {
66
- return "";
67
- }
68
- throw error;
69
- }
70
- }
71
- async writeAgentsFile(rules) {
72
- const agentsPath = path.join(process.cwd(), "AGENTS.md");
73
- try {
74
- return await fs.writeFile(agentsPath, rules, "utf8");
75
- }
76
- catch (error) {
77
- if (error.code === "ENOENT") {
78
- return;
79
- }
80
- throw error;
81
- }
82
- }
83
- // Project-specific learned rules
84
- async readProjectLearnedRulesFile() {
85
- const rulesPath = path.join(this.project.getPath("rules"), "learned-rules.md");
86
- try {
87
- return await fs.readFile(rulesPath, "utf8");
88
- }
89
- catch (error) {
90
- if (error.code === "ENOENT") {
91
- return "";
92
- }
93
- throw error;
94
- }
95
- }
96
- async writeProjectLearnedRulesFile(rules) {
97
- const rulesDir = await this.project.ensurePath("rules");
98
- const rulesPath = path.join(rulesDir, "learned-rules.md");
99
- try {
100
- return await fs.writeFile(rulesPath, rules, "utf8");
101
- }
102
- catch (error) {
103
- if (error.code === "ENOENT") {
104
- return;
105
- }
106
- throw error;
107
- }
108
- }
109
- // App-cached learned rules (used during conversation analysis)
110
- async readCachedLearnedRulesFile() {
111
- const rulesPath = path.join(this.app.getPath("rules"), "learned-rules.md");
112
- try {
113
- return await fs.readFile(rulesPath, "utf8");
114
- }
115
- catch (error) {
116
- if (error.code === "ENOENT") {
117
- return "";
118
- }
119
- throw error;
120
- }
121
- }
122
- async writeCachedLearnedRulesFile(rules) {
123
- const rulesDir = await this.app.ensurePath("rules");
124
- const rulesPath = path.join(rulesDir, "learned-rules.md");
125
- try {
126
- return await fs.writeFile(rulesPath, rules, "utf8");
127
- }
128
- catch (error) {
129
- if (error.code === "ENOENT") {
130
- return;
131
- }
132
- throw error;
133
- }
134
- }
135
- // App config helpers
136
- async readAppConfig(configName) {
137
- const configPath = path.join(this.app.getPath(), `${configName}.json`);
138
- try {
139
- const data = await fs.readFile(configPath, "utf8");
140
- return JSON.parse(data);
141
- }
142
- catch (error) {
143
- if (error.code === "ENOENT") {
144
- return {};
145
- }
146
- throw error;
147
- }
148
- }
149
- async ensureAppConfig(configName) {
150
- const configPath = path.join(this.app.getPath(), `${configName}.json`);
151
- try {
152
- await fs.access(configPath);
153
- return await this.readAppConfig(configName);
154
- }
155
- catch {
156
- // Create directory and default config if missing
157
- await this.app.ensurePath();
158
- const defaultConfig = {
159
- logs: {
160
- path: path.join(this.app.getPath(), "logs", "current.log"),
161
- },
162
- tools: {
163
- maxTokens: 30000,
164
- },
165
- notify: true,
166
- };
167
- await fs.writeFile(configPath, JSON.stringify(defaultConfig, null, 2));
168
- return defaultConfig;
169
- }
170
- }
171
- async writeAppConfig(configName, data) {
172
- await this.app.ensurePath();
173
- const configPath = path.join(this.app.getPath(), `${configName}.json`);
174
- await fs.writeFile(configPath, JSON.stringify(data, null, 2));
175
- }
176
- }
177
- // Type definitions
178
- const ProjectConfigSchema = z.object({
179
- logs: z
180
- .object({
181
- path: z.string(),
182
- })
183
- .optional(),
184
- tools: z
185
- .object({
186
- maxTokens: z.number().default(30000),
187
- })
188
- .optional()
189
- .default({ maxTokens: 30000 }),
190
- notify: z.boolean().optional().default(true),
191
- });
192
- // Create a singleton instance
193
- export const config = new ConfigManager();
@@ -1,10 +0,0 @@
1
- import { type ModelMessage } from "ai";
2
- import type { ModelManager } from "./models/manager.ts";
3
- import type { Terminal } from "./terminal/index.ts";
4
- import type { TokenTracker } from "./token-tracker.ts";
5
- export declare function analyzeConversation({ modelManager, messages, tokenTracker, }: {
6
- modelManager: ModelManager;
7
- messages: ModelMessage[];
8
- terminal?: Terminal | undefined;
9
- tokenTracker: TokenTracker;
10
- }): Promise<string[]>;
@@ -1,88 +0,0 @@
1
- import { generateText } from "ai";
2
- import { config } from "./config.js";
3
- import { createUserMessage } from "./messages.js";
4
- import { systemPrompt } from "./prompts.js";
5
- // Modified System Prompt
6
- const system = async () => `You are an expert analyst reviewing conversations between a coding agent and a software engineer. Your goal is to identify instances where the engineer corrected the agent's approach or understanding in a way that reveals a *generalizable principle* for improving the agent's future behavior across *different* tasks.
7
-
8
- **Your Task:**
9
- 1. Analyze the conversation provided.
10
- 2. Identify significant corrections or redirections from the engineer. Ignore minor clarifications or task-specific adjustments.
11
- 3. For each significant correction, infer a *single, concise, broadly applicable, actionable rule* (starting with 'Always' or 'Never') that captures the underlying principle the agent should follow in the future.
12
- 4. Ensure the rule is general enough to be useful in various scenarios, not just the specific context of this conversation.
13
- 5. Provide a brief, illustrative quote or example from the conversation in parentheses after the rule.
14
- 6. List only the inferred rules in Markdown bullet points. Do not include explanations, summaries, or conversational filler.
15
-
16
- **Crucially, AVOID generating rules that are:**
17
- - Overly specific to the files, functions, or variables discussed (e.g., "Always check for null in the 'processUserData' function"). Instead, generalize (e.g., "Always validate data from external sources before processing").
18
- - Merely restatements of the task requirements.
19
- - Too narrow to be useful outside the immediate context.
20
- - Related to minor typos or formatting preferences unless they represent a consistent pattern requested by the user.
21
-
22
- **Good General Rule Examples:**
23
- <examples>
24
- - Always ask for clarification if the user's request is ambiguous.
25
- - Never make assumptions about file paths without confirmation.
26
- - Always follow the user's explicitly stated formatting preferences.
27
- - Never provide incomplete code snippets without indicating they are partial.
28
- - Always check for potential null or undefined values before accessing properties.
29
- </examples>
30
-
31
- **Bad Specific Rule Examples (Avoid These):**
32
- <bad-examples>
33
- - Always use 'const' instead of 'let' for the 'userId' variable in 'auth.ts'.
34
- - Never forget to pass the 'config' object to the 'initializeDb' function.
35
- - Always add a try-catch block around the 'api.fetchData()' call in 'dataService.ts'.
36
- </bad-examples>
37
-
38
- This is the original system prompt the agent operated under:
39
- <systemPrompt>
40
- ${await systemPrompt()}
41
- </systemPrompt>`;
42
- export async function analyzeConversation({ modelManager, messages, tokenTracker, }) {
43
- const learnedRules = await config.readCachedLearnedRulesFile();
44
- // Modified User Message within analyzeConversation
45
- messages.push(createUserMessage([
46
- `Analyze this conversation based on the system instructions. Identify points where the user made significant corrections revealing general principles for agent improvement. Infer concise, broadly applicable rules (Always/Never) based *only* on these corrections.
47
-
48
- **Key Requirements:**
49
- - Focus on *generalizable* rules applicable to future, different tasks.
50
- - Avoid rules tied to the specifics of *this* conversation.
51
- - Ensure rules don't already exist in <existing-rules>.
52
- - If no *new, general* rules can be inferred, return an empty list or response.
53
- - Return *only* the Markdown list of rules, with no preamble or explanation.
54
-
55
- <existing-rules>
56
- ${learnedRules}
57
- </existing-rules>`,
58
- ]));
59
- const { text, usage } = await generateText({
60
- model: modelManager.getModel("conversation-analyzer"),
61
- maxOutputTokens: 8192,
62
- system: await system(),
63
- messages: messages,
64
- });
65
- tokenTracker.trackUsage("conversation-analyzer", usage);
66
- // Trim whitespace and check if the response is effectively empty or just whitespace
67
- const potentialRulesText = text.trim();
68
- // Basic check to prevent adding empty lines or just formatting
69
- if (!potentialRulesText || potentialRulesText.length === 0) {
70
- return []; // Return empty array if no valid rules generated
71
- }
72
- // Split into individual rules, filter out empty lines
73
- const potentialRulesList = potentialRulesText
74
- .split("\n")
75
- .map((rule) => rule.trim())
76
- .filter((rule) => rule.length > 0);
77
- if (potentialRulesList.length === 0) {
78
- return []; // Return empty array if splitting results in no rules
79
- }
80
- // Further validation could be added here (e.g., check if it starts with '- ', etc.)
81
- // before writing to the file.
82
- // Append only if there are non-empty potential rules
83
- const updatedRules = learnedRules.endsWith("\n") || learnedRules.length === 0
84
- ? `${learnedRules}${potentialRulesList.join("\n")}`
85
- : `${learnedRules}\n${potentialRulesList.join("\n")}`;
86
- await config.writeCachedLearnedRulesFile(updatedRules);
87
- return potentialRulesList; // Return the list of rules that were added
88
- }
@@ -1,3 +0,0 @@
1
- type Dedent = (strings: TemplateStringsArray, ...values: unknown[]) => string;
2
- export declare const dedent: Dedent;
3
- export {};
@@ -1,38 +0,0 @@
1
- const spaces = /^(\s+)\S+/;
2
- export const dedent = (strings, ...values) => {
3
- // Perform interpolation
4
- let result = "";
5
- for (let i = 0; i < strings.raw.length; i++) {
6
- const next = strings.raw[i] ??
7
- ""
8
- // handle escaped newlines, backticks, and interpolation characters
9
- .replace(/\\\n[ \t]*/g, "")
10
- .replace(/\\`/g, "`")
11
- .replace(/\\\$/g, "$")
12
- .replace(/\\\{/g, "{");
13
- result += next;
14
- if (i < values.length) {
15
- result += values[i];
16
- }
17
- }
18
- // Strip indentation
19
- const lines = result.split("\n");
20
- let mindent = null;
21
- for (const line of lines) {
22
- const m = line.match(spaces);
23
- if (m) {
24
- const indent = m[1]?.length ?? 0;
25
- mindent = mindent === null ? indent : Math.min(mindent, indent);
26
- }
27
- }
28
- if (mindent !== null) {
29
- result = lines
30
- .map((l) => (l[0] === " " || l[0] === "\t" ? l.slice(mindent) : l))
31
- .join("\n");
32
- }
33
- // Trim leading and trailing whitespace
34
- result = result.trim();
35
- // Handle escaped newlines at the end
36
- result = result.replace(/\\n/g, "\n");
37
- return result;
38
- };
@@ -1,17 +0,0 @@
1
- /**
2
- * Extracts the first code block content from the given text.
3
- * If a Markdown-style triple backtick code block is found, returns its inner content.
4
- * Otherwise, returns the original text unchanged.
5
- *
6
- * @param text - The input string potentially containing a Markdown code block.
7
- * @returns The extracted code inside the first code block, or the original text if no block is found.
8
- */
9
- export declare const extractCodeBlock: (text: string) => string;
10
- export declare function extractXml(text: string, tag: string): string;
11
- export declare function removeAllLineBreaks(text: string): string;
12
- export declare function removeHtmlTags(text: string): string;
13
- export type FormatType = "xml" | "markdown" | "bracket";
14
- export declare function formatFile(file: string, content: string, format: FormatType): string;
15
- export declare function formatUrl(siteUrl: string, content: string, format: FormatType): string;
16
- export declare function formatCodeSnippet(file: string, content: string, format: FormatType): string;
17
- export declare function formatBlock(content: string, blockName: string, format: FormatType): string;
@@ -1,103 +0,0 @@
1
- import path from "node:path";
2
- const MD_CODE_BLOCK = /```(?:[\w-]+)?\n(.*?)```/s;
3
- /**
4
- * Extracts the first code block content from the given text.
5
- * If a Markdown-style triple backtick code block is found, returns its inner content.
6
- * Otherwise, returns the original text unchanged.
7
- *
8
- * @param text - The input string potentially containing a Markdown code block.
9
- * @returns The extracted code inside the first code block, or the original text if no block is found.
10
- */
11
- export const extractCodeBlock = (text) => {
12
- const pattern = MD_CODE_BLOCK;
13
- const match = text.match(pattern);
14
- if (match) {
15
- return match[1] ?? "";
16
- }
17
- return text;
18
- };
19
- export function extractXml(text, tag) {
20
- const match = text.match(new RegExp(`<${tag}>(.*?)</${tag}>`, "s"));
21
- return match ? (match[1] ?? "") : "";
22
- }
23
- export function removeAllLineBreaks(text) {
24
- return text.replace(/(\r\n|\n|\r)/gm, " ");
25
- }
26
- export function removeHtmlTags(text) {
27
- return text.replace(/<[^>]*>?/gm, "");
28
- }
29
- const MD_TRIPLE_QUOTE = "```";
30
- const codeBlockExtensions = {
31
- js: "javascript",
32
- ts: "typescript",
33
- py: "python",
34
- rb: "ruby",
35
- java: "java",
36
- cpp: "cpp",
37
- cs: "csharp",
38
- go: "go",
39
- rs: "rust",
40
- php: "php",
41
- html: "html",
42
- css: "css",
43
- json: "json",
44
- yml: "yaml",
45
- yaml: "yaml",
46
- md: "markdown",
47
- sql: "sql",
48
- sh: "bash",
49
- bash: "bash",
50
- txt: "text",
51
- };
52
- export function formatFile(file, content, format) {
53
- const fileExtension = path.extname(file).slice(1);
54
- const codeBlockName = codeBlockExtensions[fileExtension] || fileExtension;
55
- switch (format) {
56
- case "xml":
57
- return `<file>\n<name>${file}</name>\n<content>\n${content}\n</content>\n</file>`;
58
- case "markdown":
59
- return `## File: ${file}\n${MD_TRIPLE_QUOTE} ${codeBlockName}\n${content}\n${MD_TRIPLE_QUOTE}`;
60
- case "bracket":
61
- return `[file name]: ${file}\n[file content begin]\n${content}\n[file content end]`;
62
- default:
63
- throw new Error(`Unsupported format: ${format}`);
64
- }
65
- }
66
- export function formatUrl(siteUrl, content, format) {
67
- switch (format) {
68
- case "xml":
69
- return `<webpage>\n<url>${siteUrl}</url>\n<content>\n${content}\n</content>\n</webpage>`;
70
- case "markdown":
71
- return `## URL: ${siteUrl}\n${MD_TRIPLE_QUOTE}\n${content}\n${MD_TRIPLE_QUOTE}`;
72
- case "bracket":
73
- return `[url]: ${siteUrl}\n[url content begin]\n${content}\n[url content end]`;
74
- default:
75
- throw new Error(`Unsupported format: ${format}`);
76
- }
77
- }
78
- export function formatCodeSnippet(file, content, format) {
79
- const fileExtension = path.extname(file).slice(1);
80
- const codeBlockName = codeBlockExtensions[fileExtension] || fileExtension;
81
- switch (format) {
82
- case "xml":
83
- return `<code>\n${content}\n</code>`;
84
- case "markdown":
85
- return `${MD_TRIPLE_QUOTE} ${codeBlockName}\n${content}\n${MD_TRIPLE_QUOTE}`;
86
- case "bracket":
87
- return `[code begin]\n${content}\n[code end]`;
88
- default:
89
- throw new Error(`Unsupported format: ${format}`);
90
- }
91
- }
92
- export function formatBlock(content, blockName, format) {
93
- switch (format) {
94
- case "xml":
95
- return `<${blockName}>\n${content}\n</${blockName}>\n</file>`;
96
- case "markdown":
97
- return `## ${blockName}\n${MD_TRIPLE_QUOTE}\n${content}\n${MD_TRIPLE_QUOTE}`;
98
- case "bracket":
99
- return `[${blockName} begin]\n${content}\n[${blockName} end]`;
100
- default:
101
- throw new Error(`Unsupported format: ${format}`);
102
- }
103
- }
@@ -1,18 +0,0 @@
1
- declare const flags: {
2
- model?: string | undefined;
3
- prompt?: string | undefined;
4
- oneshot: boolean;
5
- continue: boolean;
6
- resume: boolean;
7
- autoAcceptAll: boolean;
8
- help?: boolean | undefined;
9
- version?: boolean | undefined;
10
- };
11
- /**
12
- * Global error handler function.
13
- * @param {Error} error - The error to be handled.
14
- * @throws {Error} Rethrows the error after logging it.
15
- */
16
- export declare function handleError(error: Error): void;
17
- export type Flags = typeof flags;
18
- export {};