@travisennis/acai 0.0.5 → 0.0.6

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 (311) hide show
  1. package/README.md +4 -2
  2. package/dist/agent/index.d.ts +119 -0
  3. package/dist/agent/index.d.ts.map +1 -0
  4. package/dist/agent/index.js +406 -0
  5. package/dist/agent/manual-loop.d.ts +41 -0
  6. package/dist/agent/manual-loop.d.ts.map +1 -0
  7. package/dist/agent/manual-loop.js +278 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +27 -33
  11. package/dist/commands/add-directory-command.d.ts +3 -0
  12. package/dist/commands/add-directory-command.d.ts.map +1 -0
  13. package/dist/commands/add-directory-command.js +85 -0
  14. package/dist/commands/application-log-command.d.ts.map +1 -1
  15. package/dist/commands/application-log-command.js +34 -0
  16. package/dist/commands/clear-command.d.ts.map +1 -1
  17. package/dist/commands/clear-command.js +8 -0
  18. package/dist/commands/compact-command.d.ts.map +1 -1
  19. package/dist/commands/compact-command.js +15 -2
  20. package/dist/commands/context-command.d.ts +3 -0
  21. package/dist/commands/context-command.d.ts.map +1 -0
  22. package/dist/commands/context-command.js +183 -0
  23. package/dist/commands/copy-command.d.ts.map +1 -1
  24. package/dist/commands/copy-command.js +28 -0
  25. package/dist/commands/edit-command.d.ts.map +1 -1
  26. package/dist/commands/edit-command.js +33 -0
  27. package/dist/commands/edit-prompt-command.d.ts.map +1 -1
  28. package/dist/commands/edit-prompt-command.js +28 -0
  29. package/dist/commands/exit-command.d.ts.map +1 -1
  30. package/dist/commands/exit-command.js +20 -0
  31. package/dist/commands/files-command.d.ts.map +1 -1
  32. package/dist/commands/files-command.js +57 -0
  33. package/dist/commands/generate-rules-command.d.ts.map +1 -1
  34. package/dist/commands/generate-rules-command.js +311 -1
  35. package/dist/commands/handoff-command.d.ts +3 -0
  36. package/dist/commands/handoff-command.d.ts.map +1 -0
  37. package/dist/commands/handoff-command.js +202 -0
  38. package/dist/commands/health-command.d.ts.map +1 -1
  39. package/dist/commands/health-command.js +119 -2
  40. package/dist/commands/help-command.d.ts.map +1 -1
  41. package/dist/commands/help-command.js +28 -0
  42. package/dist/commands/history-command.d.ts +3 -0
  43. package/dist/commands/history-command.d.ts.map +1 -0
  44. package/dist/commands/history-command.js +534 -0
  45. package/dist/commands/init-command.d.ts +1 -1
  46. package/dist/commands/init-command.d.ts.map +1 -1
  47. package/dist/commands/init-command.js +55 -18
  48. package/dist/commands/last-log-command.d.ts.map +1 -1
  49. package/dist/commands/last-log-command.js +27 -0
  50. package/dist/commands/list-directories-command.d.ts +3 -0
  51. package/dist/commands/list-directories-command.d.ts.map +1 -0
  52. package/dist/commands/list-directories-command.js +48 -0
  53. package/dist/commands/list-tools-command.d.ts.map +1 -1
  54. package/dist/commands/list-tools-command.js +66 -3
  55. package/dist/commands/manager.d.ts +15 -3
  56. package/dist/commands/manager.d.ts.map +1 -1
  57. package/dist/commands/manager.js +86 -26
  58. package/dist/commands/model-command.d.ts +22 -0
  59. package/dist/commands/model-command.d.ts.map +1 -1
  60. package/dist/commands/model-command.js +256 -0
  61. package/dist/commands/paste-command.d.ts.map +1 -1
  62. package/dist/commands/paste-command.js +92 -0
  63. package/dist/commands/pickup-command.d.ts +3 -0
  64. package/dist/commands/pickup-command.d.ts.map +1 -0
  65. package/dist/commands/pickup-command.js +161 -0
  66. package/dist/commands/prompt-command.d.ts +1 -1
  67. package/dist/commands/prompt-command.d.ts.map +1 -1
  68. package/dist/commands/prompt-command.js +117 -2
  69. package/dist/commands/remove-directory-command.d.ts +3 -0
  70. package/dist/commands/remove-directory-command.d.ts.map +1 -0
  71. package/dist/commands/remove-directory-command.js +87 -0
  72. package/dist/commands/reset-command.d.ts +1 -1
  73. package/dist/commands/reset-command.d.ts.map +1 -1
  74. package/dist/commands/reset-command.js +13 -2
  75. package/dist/commands/rules-command.d.ts.map +1 -1
  76. package/dist/commands/rules-command.js +65 -0
  77. package/dist/commands/save-command.d.ts.map +1 -1
  78. package/dist/commands/save-command.js +12 -0
  79. package/dist/commands/shell-command.d.ts.map +1 -1
  80. package/dist/commands/shell-command.js +68 -0
  81. package/dist/commands/types.d.ts +9 -4
  82. package/dist/commands/types.d.ts.map +1 -1
  83. package/dist/commands/usage-command.d.ts.map +1 -1
  84. package/dist/commands/usage-command.js +22 -0
  85. package/dist/config.d.ts +6 -7
  86. package/dist/config.d.ts.map +1 -1
  87. package/dist/config.js +23 -29
  88. package/dist/formatting.d.ts +108 -0
  89. package/dist/formatting.d.ts.map +1 -1
  90. package/dist/formatting.js +147 -0
  91. package/dist/index.d.ts +7 -2
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +140 -38
  94. package/dist/logger.d.ts.map +1 -1
  95. package/dist/logger.js +47 -18
  96. package/dist/mentions.d.ts +2 -1
  97. package/dist/mentions.d.ts.map +1 -1
  98. package/dist/mentions.js +16 -1
  99. package/dist/messages.d.ts +8 -0
  100. package/dist/messages.d.ts.map +1 -1
  101. package/dist/messages.js +56 -19
  102. package/dist/middleware/cache.d.ts +3 -0
  103. package/dist/middleware/cache.d.ts.map +1 -0
  104. package/dist/middleware/cache.js +53 -0
  105. package/dist/middleware/index.d.ts +1 -0
  106. package/dist/middleware/index.d.ts.map +1 -1
  107. package/dist/middleware/index.js +1 -0
  108. package/dist/models/ai-config.d.ts +4 -2
  109. package/dist/models/ai-config.d.ts.map +1 -1
  110. package/dist/models/ai-config.js +12 -2
  111. package/dist/models/anthropic-provider.d.ts.map +1 -1
  112. package/dist/models/anthropic-provider.js +3 -60
  113. package/dist/models/manager.d.ts +2 -1
  114. package/dist/models/manager.d.ts.map +1 -1
  115. package/dist/models/manager.js +26 -2
  116. package/dist/models/openrouter-provider.d.ts +7 -14
  117. package/dist/models/openrouter-provider.d.ts.map +1 -1
  118. package/dist/models/openrouter-provider.js +114 -169
  119. package/dist/models/providers.d.ts +1 -1
  120. package/dist/models/providers.d.ts.map +1 -1
  121. package/dist/prompts.d.ts +1 -0
  122. package/dist/prompts.d.ts.map +1 -1
  123. package/dist/prompts.js +53 -4
  124. package/dist/repl/display-tool-messages.d.ts +1 -1
  125. package/dist/repl/display-tool-messages.d.ts.map +1 -1
  126. package/dist/repl/display-tool-messages.js +47 -44
  127. package/dist/repl/get-prompt-header.d.ts.map +1 -1
  128. package/dist/repl/get-prompt-header.js +1 -30
  129. package/dist/repl/project-status-line.d.ts +2 -0
  130. package/dist/repl/project-status-line.d.ts.map +1 -0
  131. package/dist/repl/project-status-line.js +31 -0
  132. package/dist/repl/prompt.d.ts +21 -0
  133. package/dist/repl/prompt.d.ts.map +1 -0
  134. package/dist/{repl-prompt.js → repl/prompt.js} +119 -22
  135. package/dist/repl/tool-call-repair.d.ts.map +1 -1
  136. package/dist/repl/tool-call-repair.js +8 -4
  137. package/dist/repl-new.d.ts +53 -0
  138. package/dist/repl-new.d.ts.map +1 -0
  139. package/dist/repl-new.js +374 -0
  140. package/dist/repl.d.ts +3 -5
  141. package/dist/repl.d.ts.map +1 -1
  142. package/dist/repl.js +74 -166
  143. package/dist/terminal/checkbox-prompt.d.ts.map +1 -1
  144. package/dist/terminal/checkbox-prompt.js +10 -4
  145. package/dist/terminal/index.d.ts +7 -0
  146. package/dist/terminal/index.d.ts.map +1 -1
  147. package/dist/terminal/index.js +94 -0
  148. package/dist/terminal/input-prompt.d.ts +2 -1
  149. package/dist/terminal/input-prompt.d.ts.map +1 -1
  150. package/dist/terminal/markdown.js +3 -0
  151. package/dist/terminal/search-prompt.d.ts.map +1 -1
  152. package/dist/terminal/search-prompt.js +11 -10
  153. package/dist/terminal/select-prompt.d.ts +2 -2
  154. package/dist/terminal/select-prompt.d.ts.map +1 -1
  155. package/dist/terminal/select-prompt.js +47 -39
  156. package/dist/tokens/threshold.d.ts +35 -0
  157. package/dist/tokens/threshold.d.ts.map +1 -0
  158. package/dist/tokens/threshold.js +85 -0
  159. package/dist/tools/advanced-edit-file.d.ts +69 -0
  160. package/dist/tools/advanced-edit-file.d.ts.map +1 -0
  161. package/dist/tools/advanced-edit-file.js +281 -0
  162. package/dist/tools/agent.d.ts +16 -5
  163. package/dist/tools/agent.d.ts.map +1 -1
  164. package/dist/tools/agent.js +71 -58
  165. package/dist/tools/bash-utils.d.ts +1 -1
  166. package/dist/tools/bash-utils.d.ts.map +1 -1
  167. package/dist/tools/bash-utils.js +14 -6
  168. package/dist/tools/bash.d.ts +21 -12
  169. package/dist/tools/bash.d.ts.map +1 -1
  170. package/dist/tools/bash.js +88 -135
  171. package/dist/tools/code-interpreter.d.ts +21 -9
  172. package/dist/tools/code-interpreter.d.ts.map +1 -1
  173. package/dist/tools/code-interpreter.js +138 -137
  174. package/dist/tools/delete-file.d.ts +17 -10
  175. package/dist/tools/delete-file.d.ts.map +1 -1
  176. package/dist/tools/delete-file.js +51 -95
  177. package/dist/tools/directory-tree.d.ts +17 -6
  178. package/dist/tools/directory-tree.d.ts.map +1 -1
  179. package/dist/tools/directory-tree.js +47 -49
  180. package/dist/tools/dynamic-tool-loader.d.ts +18 -8
  181. package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
  182. package/dist/tools/dynamic-tool-loader.js +121 -129
  183. package/dist/tools/dynamic-tool-parser.d.ts +1 -0
  184. package/dist/tools/dynamic-tool-parser.d.ts.map +1 -1
  185. package/dist/tools/dynamic-tool-parser.js +1 -0
  186. package/dist/tools/edit-file.d.ts +35 -15
  187. package/dist/tools/edit-file.d.ts.map +1 -1
  188. package/dist/tools/edit-file.js +112 -112
  189. package/dist/tools/filesystem-utils.d.ts +2 -1
  190. package/dist/tools/filesystem-utils.d.ts.map +1 -1
  191. package/dist/tools/filesystem-utils.js +31 -17
  192. package/dist/tools/glob.d.ts +36 -0
  193. package/dist/tools/glob.d.ts.map +1 -0
  194. package/dist/tools/glob.js +143 -0
  195. package/dist/tools/grep.d.ts +73 -12
  196. package/dist/tools/grep.d.ts.map +1 -1
  197. package/dist/tools/grep.js +413 -168
  198. package/dist/tools/index.d.ts +204 -124
  199. package/dist/tools/index.d.ts.map +1 -1
  200. package/dist/tools/index.js +242 -135
  201. package/dist/tools/llm-edit-fixer.d.ts +25 -0
  202. package/dist/tools/llm-edit-fixer.d.ts.map +1 -0
  203. package/dist/tools/llm-edit-fixer.js +150 -0
  204. package/dist/tools/move-file.d.ts +19 -7
  205. package/dist/tools/move-file.d.ts.map +1 -1
  206. package/dist/tools/move-file.js +40 -33
  207. package/dist/tools/read-file.d.ts +47 -9
  208. package/dist/tools/read-file.d.ts.map +1 -1
  209. package/dist/tools/read-file.js +74 -69
  210. package/dist/tools/read-multiple-files.d.ts +17 -6
  211. package/dist/tools/read-multiple-files.d.ts.map +1 -1
  212. package/dist/tools/read-multiple-files.js +76 -73
  213. package/dist/tools/save-file.d.ts +45 -12
  214. package/dist/tools/save-file.d.ts.map +1 -1
  215. package/dist/tools/save-file.js +58 -101
  216. package/dist/tools/think.d.ts +15 -7
  217. package/dist/tools/think.d.ts.map +1 -1
  218. package/dist/tools/think.js +30 -22
  219. package/dist/tools/types.d.ts +4 -10
  220. package/dist/tools/types.d.ts.map +1 -1
  221. package/dist/tools/types.js +9 -0
  222. package/dist/tools/utils.d.ts +14 -0
  223. package/dist/tools/utils.d.ts.map +1 -0
  224. package/dist/tools/utils.js +16 -0
  225. package/dist/tools/web-fetch.d.ts +11 -4
  226. package/dist/tools/web-fetch.d.ts.map +1 -1
  227. package/dist/tools/web-fetch.js +39 -38
  228. package/dist/tools/web-search.d.ts +15 -6
  229. package/dist/tools/web-search.d.ts.map +1 -1
  230. package/dist/tools/web-search.js +50 -32
  231. package/dist/tui/autocomplete.d.ts +44 -0
  232. package/dist/tui/autocomplete.d.ts.map +1 -0
  233. package/dist/tui/autocomplete.js +466 -0
  234. package/dist/tui/components/assistant-message.d.ts +18 -0
  235. package/dist/tui/components/assistant-message.d.ts.map +1 -0
  236. package/dist/tui/components/assistant-message.js +29 -0
  237. package/dist/tui/components/editor.d.ts +51 -0
  238. package/dist/tui/components/editor.d.ts.map +1 -0
  239. package/dist/tui/components/editor.js +758 -0
  240. package/dist/tui/components/footer.d.ts +24 -0
  241. package/dist/tui/components/footer.d.ts.map +1 -0
  242. package/dist/tui/components/footer.js +197 -0
  243. package/dist/tui/components/input.d.ts +14 -0
  244. package/dist/tui/components/input.d.ts.map +1 -0
  245. package/dist/tui/components/input.js +122 -0
  246. package/dist/tui/components/loader.d.ts +19 -0
  247. package/dist/tui/components/loader.d.ts.map +1 -0
  248. package/dist/tui/components/loader.js +45 -0
  249. package/dist/tui/components/markdown.d.ts +103 -0
  250. package/dist/tui/components/markdown.d.ts.map +1 -0
  251. package/dist/tui/components/markdown.js +533 -0
  252. package/dist/tui/components/modal.d.ts +40 -0
  253. package/dist/tui/components/modal.d.ts.map +1 -0
  254. package/dist/tui/components/modal.js +292 -0
  255. package/dist/tui/components/prompt-status.d.ts +16 -0
  256. package/dist/tui/components/prompt-status.d.ts.map +1 -0
  257. package/dist/tui/components/prompt-status.js +21 -0
  258. package/dist/tui/components/select-list.d.ts +22 -0
  259. package/dist/tui/components/select-list.d.ts.map +1 -0
  260. package/dist/tui/components/select-list.js +143 -0
  261. package/dist/tui/components/spacer.d.ts +16 -0
  262. package/dist/tui/components/spacer.d.ts.map +1 -0
  263. package/dist/tui/components/spacer.js +27 -0
  264. package/dist/tui/components/text.d.ts +26 -0
  265. package/dist/tui/components/text.d.ts.map +1 -0
  266. package/dist/tui/components/text.js +143 -0
  267. package/dist/tui/components/thinking-block.d.ts +14 -0
  268. package/dist/tui/components/thinking-block.d.ts.map +1 -0
  269. package/dist/tui/components/thinking-block.js +30 -0
  270. package/dist/tui/components/tool-execution.d.ts +17 -0
  271. package/dist/tui/components/tool-execution.d.ts.map +1 -0
  272. package/dist/tui/components/tool-execution.js +153 -0
  273. package/dist/tui/components/user-message.d.ts +9 -0
  274. package/dist/tui/components/user-message.d.ts.map +1 -0
  275. package/dist/tui/components/user-message.js +21 -0
  276. package/dist/tui/components/welcome.d.ts +6 -0
  277. package/dist/tui/components/welcome.d.ts.map +1 -0
  278. package/dist/tui/components/welcome.js +30 -0
  279. package/dist/tui/index.d.ts +14 -0
  280. package/dist/tui/index.d.ts.map +1 -0
  281. package/dist/tui/index.js +18 -0
  282. package/dist/tui/terminal.d.ts +37 -0
  283. package/dist/tui/terminal.d.ts.map +1 -0
  284. package/dist/tui/terminal.js +104 -0
  285. package/dist/tui/tui.d.ts +67 -0
  286. package/dist/tui/tui.d.ts.map +1 -0
  287. package/dist/tui/tui.js +184 -0
  288. package/dist/tui/utils.d.ts +19 -0
  289. package/dist/tui/utils.d.ts.map +1 -0
  290. package/dist/tui/utils.js +31 -0
  291. package/dist/utils/generators.d.ts +3 -0
  292. package/dist/utils/generators.d.ts.map +1 -0
  293. package/dist/utils/generators.js +25 -0
  294. package/dist/utils/iterables.d.ts +2 -0
  295. package/dist/utils/iterables.d.ts.map +1 -0
  296. package/dist/utils/iterables.js +6 -0
  297. package/package.json +16 -16
  298. package/dist/conversation-analyzer.d.ts +0 -11
  299. package/dist/conversation-analyzer.d.ts.map +0 -1
  300. package/dist/conversation-analyzer.js +0 -88
  301. package/dist/repl-prompt.d.ts +0 -15
  302. package/dist/repl-prompt.d.ts.map +0 -1
  303. package/dist/tokens/manage-output.d.ts +0 -34
  304. package/dist/tokens/manage-output.d.ts.map +0 -1
  305. package/dist/tokens/manage-output.js +0 -44
  306. package/dist/tool-executor.d.ts +0 -28
  307. package/dist/tool-executor.d.ts.map +0 -1
  308. package/dist/tool-executor.js +0 -74
  309. package/dist/tools/file-editing-utils.d.ts +0 -2
  310. package/dist/tools/file-editing-utils.d.ts.map +0 -1
  311. package/dist/tools/file-editing-utils.js +0 -135
@@ -1,6 +1,12 @@
1
- import { analyzeConversation } from "../conversation-analyzer.js";
1
+ import { generateText } from "ai";
2
+ import { config } from "../config.js";
2
3
  import { logger } from "../logger.js"; // Import logger
4
+ import { createUserMessage } from "../messages.js";
5
+ import { systemPrompt } from "../prompts.js";
3
6
  import { checkbox } from "../terminal/checkbox-prompt.js";
7
+ import { getTerminalSize } from "../terminal/formatting.js";
8
+ import style from "../terminal/style.js";
9
+ import { Container, Input, Spacer, Text, } from "../tui/index.js";
4
10
  async function _processAndSaveRules(newRules, terminal, config) {
5
11
  if (!newRules || newRules.length === 0) {
6
12
  terminal.warn("No new generalizable rules were identified.");
@@ -58,5 +64,309 @@ export const generateRulesCommand = ({ terminal, messageHistory, modelManager, t
58
64
  }
59
65
  return "continue";
60
66
  },
67
+ async handle(_args, { tui, container, inputContainer, editor, }) {
68
+ if (messageHistory.isEmpty()) {
69
+ container.addChild(new Text(style.yellow("Cannot generate rules from an empty conversation."), 1, 0));
70
+ tui.requestRender();
71
+ editor.setText("");
72
+ return "continue";
73
+ }
74
+ container.addChild(new Text("Analyzing conversation to generate rules...", 0, 1));
75
+ tui.requestRender();
76
+ try {
77
+ const newRules = await analyzeConversation({
78
+ modelManager,
79
+ messages: messageHistory.get(),
80
+ tokenTracker,
81
+ terminal,
82
+ });
83
+ if (!newRules || newRules.length === 0) {
84
+ container.addChild(new Text(style.yellow("No new generalizable rules were identified."), 2, 0));
85
+ tui.requestRender();
86
+ editor.setText("");
87
+ return "continue";
88
+ }
89
+ // Create rule selector for TUI mode
90
+ const ruleSelector = new RuleSelectorComponent(newRules, async (selectedRules) => {
91
+ // Handle rule selection
92
+ if (selectedRules.length === 0) {
93
+ container.addChild(new Text(style.yellow("No rules selected to save."), 2, 0));
94
+ }
95
+ else {
96
+ try {
97
+ const existingRules = await config.readProjectLearnedRulesFile();
98
+ const rulesToAdd = selectedRules.join("\n");
99
+ const updatedProjectRules = existingRules.endsWith("\n") || existingRules.length === 0
100
+ ? `${existingRules}${rulesToAdd}`
101
+ : `${existingRules}\n${rulesToAdd}`;
102
+ await config.writeProjectLearnedRulesFile(updatedProjectRules);
103
+ container.addChild(new Text(style.green("Selected rules saved to project learned rules."), 2, 0));
104
+ container.addChild(new Text(style.dim("Saved rules:"), 3, 0));
105
+ selectedRules.forEach((rule, index) => {
106
+ container.addChild(new Text(`- ${rule}`, 4 + index, 0));
107
+ });
108
+ }
109
+ catch (error) {
110
+ container.addChild(new Text(style.red(`Failed to save rules: ${error}`), 2, 0));
111
+ }
112
+ }
113
+ // Hide selector and show editor again
114
+ hideRuleSelector(inputContainer, editor, tui);
115
+ tui.requestRender();
116
+ }, () => {
117
+ // Cancel selection - just hide selector
118
+ hideRuleSelector(inputContainer, editor, tui);
119
+ tui.requestRender();
120
+ });
121
+ // Replace editor with rule selector
122
+ inputContainer.clear();
123
+ inputContainer.addChild(ruleSelector);
124
+ tui.setFocus(ruleSelector);
125
+ tui.requestRender();
126
+ return "continue";
127
+ }
128
+ catch (error) {
129
+ const errorMessage = error instanceof Error ? error.message : String(error);
130
+ container.addChild(new Text(style.red(`Error generating rules: ${errorMessage}`), 0, 1));
131
+ logger.error(error, "Error during rule generation:");
132
+ tui.requestRender();
133
+ editor.setText("");
134
+ return "continue";
135
+ }
136
+ },
61
137
  };
62
138
  };
139
+ // Modified System Prompt
140
+ 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.
141
+
142
+ **Your Task:**
143
+ 1. Analyze the conversation provided.
144
+ 2. Identify significant corrections or redirections from the engineer. Ignore minor clarifications or task-specific adjustments.
145
+ 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.
146
+ 4. Ensure the rule is general enough to be useful in various scenarios, not just the specific context of this conversation.
147
+ 5. Provide a brief, illustrative quote or example from the conversation in parentheses after the rule.
148
+ 6. List only the inferred rules in Markdown bullet points. Do not include explanations, summaries, or conversational filler.
149
+
150
+ **Crucially, AVOID generating rules that are:**
151
+ - 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").
152
+ - Merely restatements of the task requirements.
153
+ - Too narrow to be useful outside the immediate context.
154
+ - Related to minor typos or formatting preferences unless they represent a consistent pattern requested by the user.
155
+
156
+ **Good General Rule Examples:**
157
+ <examples>
158
+ - Always ask for clarification if the user's request is ambiguous.
159
+ - Never make assumptions about file paths without confirmation.
160
+ - Always follow the user's explicitly stated formatting preferences.
161
+ - Never provide incomplete code snippets without indicating they are partial.
162
+ - Always check for potential null or undefined values before accessing properties.
163
+ </examples>
164
+
165
+ **Bad Specific Rule Examples (Avoid These):**
166
+ <bad-examples>
167
+ - Always use 'const' instead of 'let' for the 'userId' variable in 'auth.ts'.
168
+ - Never forget to pass the 'config' object to the 'initializeDb' function.
169
+ - Always add a try-catch block around the 'api.fetchData()' call in 'dataService.ts'.
170
+ </bad-examples>
171
+
172
+ This is the original system prompt the agent operated under:
173
+ <systemPrompt>
174
+ ${await systemPrompt()}
175
+ </systemPrompt>`;
176
+ async function analyzeConversation({ modelManager, messages, tokenTracker, }) {
177
+ const learnedRules = await config.readCachedLearnedRulesFile();
178
+ // Modified User Message within analyzeConversation
179
+ messages.push(createUserMessage([
180
+ `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.
181
+
182
+ **Key Requirements:**
183
+ - Focus on *generalizable* rules applicable to future, different tasks.
184
+ - Avoid rules tied to the specifics of *this* conversation.
185
+ - Ensure rules don't already exist in <existing-rules>.
186
+ - If no *new, general* rules can be inferred, return an empty list or response.
187
+ - Return *only* the Markdown list of rules, with no preamble or explanation.
188
+
189
+ <existing-rules>
190
+ ${learnedRules}
191
+ </existing-rules>`,
192
+ ]));
193
+ const { text, usage } = await generateText({
194
+ model: modelManager.getModel("conversation-analyzer"),
195
+ maxOutputTokens: 8192,
196
+ system: await system(),
197
+ messages: messages,
198
+ });
199
+ tokenTracker.trackUsage("conversation-analyzer", usage);
200
+ // Trim whitespace and check if the response is effectively empty or just whitespace
201
+ const potentialRulesText = text.trim();
202
+ // Basic check to prevent adding empty lines or just formatting
203
+ if (!potentialRulesText || potentialRulesText.length === 0) {
204
+ return []; // Return empty array if no valid rules generated
205
+ }
206
+ // Split into individual rules, filter out empty lines
207
+ const potentialRulesList = potentialRulesText
208
+ .split("\n")
209
+ .map((rule) => rule.trim())
210
+ .filter((rule) => rule.length > 0);
211
+ if (potentialRulesList.length === 0) {
212
+ return []; // Return empty array if splitting results in no rules
213
+ }
214
+ // Further validation could be added here (e.g., check if it starts with '- ', etc.)
215
+ // before writing to the file.
216
+ // Append only if there are non-empty potential rules
217
+ const updatedRules = learnedRules.endsWith("\n") || learnedRules.length === 0
218
+ ? `${learnedRules}${potentialRulesList.join("\n")}`
219
+ : `${learnedRules}\n${potentialRulesList.join("\n")}`;
220
+ await config.writeCachedLearnedRulesFile(updatedRules);
221
+ return potentialRulesList; // Return the list of rules that were added
222
+ }
223
+ function hideRuleSelector(editorContainer, editor, tui) {
224
+ // Replace selector with editor in the container
225
+ editorContainer.clear();
226
+ editorContainer.addChild(editor);
227
+ tui.setFocus(editor);
228
+ }
229
+ /**
230
+ * Component that renders a rule selector with search and multi-selection
231
+ */
232
+ class RuleSelectorComponent extends Container {
233
+ searchInput;
234
+ listContainer;
235
+ allRules = [];
236
+ filteredRules = [];
237
+ selectedIndex = 0;
238
+ selectedRules = new Set();
239
+ onSelectCallback;
240
+ onCancelCallback;
241
+ constructor(rules, onSelect, onCancel) {
242
+ super();
243
+ this.onSelectCallback = onSelect;
244
+ this.onCancelCallback = onCancel;
245
+ // Load all rules
246
+ this.allRules = rules;
247
+ this.filteredRules = rules;
248
+ const { columns } = getTerminalSize();
249
+ // Add top border
250
+ this.addChild(new Text(style.blue("─".repeat(columns)), 0, 0));
251
+ this.addChild(new Spacer(1));
252
+ // Create search input
253
+ this.searchInput = new Input();
254
+ this.searchInput.onSubmit = () => {
255
+ // Enter on search input toggles selection of current item
256
+ this.toggleSelection(this.selectedIndex);
257
+ };
258
+ this.addChild(this.searchInput);
259
+ this.addChild(new Spacer(1));
260
+ // Create list container
261
+ this.listContainer = new Container();
262
+ this.addChild(this.listContainer);
263
+ this.addChild(new Spacer(1));
264
+ // Add instructions
265
+ this.addChild(new Text(style.dim("Space: toggle selection, Enter: confirm, Escape: cancel"), 0, 0));
266
+ this.addChild(new Spacer(1));
267
+ // Add bottom border
268
+ this.addChild(new Text(style.blue("─".repeat(columns)), 0, 0));
269
+ // Initial render
270
+ this.updateList();
271
+ }
272
+ filterRules(query) {
273
+ if (!query.trim()) {
274
+ this.filteredRules = this.allRules;
275
+ }
276
+ else {
277
+ const searchTokens = query
278
+ .toLowerCase()
279
+ .split(/\s+/)
280
+ .filter((t) => t);
281
+ this.filteredRules = this.allRules.filter((rule) => {
282
+ const searchText = rule.toLowerCase();
283
+ return searchTokens.every((token) => searchText.includes(token));
284
+ });
285
+ }
286
+ this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredRules.length - 1));
287
+ this.updateList();
288
+ }
289
+ updateList() {
290
+ this.listContainer.clear();
291
+ const maxVisible = 10;
292
+ const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(maxVisible / 2), this.filteredRules.length - maxVisible));
293
+ const endIndex = Math.min(startIndex + maxVisible, this.filteredRules.length);
294
+ // Show visible slice of filtered rules
295
+ for (let i = startIndex; i < endIndex; i++) {
296
+ const rule = this.filteredRules[i];
297
+ if (!rule)
298
+ continue;
299
+ const isSelected = i === this.selectedIndex;
300
+ const isChecked = this.selectedRules.has(i);
301
+ let line = "";
302
+ if (isSelected) {
303
+ const prefix = style.blue("→ ");
304
+ const checkbox = isChecked ? style.green("[✓] ") : "[ ] ";
305
+ const ruleText = rule;
306
+ line = `${prefix + checkbox + style.blue(ruleText)}`;
307
+ }
308
+ else {
309
+ const checkbox = isChecked ? style.green("[✓] ") : "[ ] ";
310
+ const ruleText = ` ${rule}`;
311
+ line = `${checkbox + ruleText}`;
312
+ }
313
+ this.listContainer.addChild(new Text(line, 0, 0));
314
+ }
315
+ // Add scroll indicator if needed
316
+ if (startIndex > 0 || endIndex < this.filteredRules.length) {
317
+ const scrollInfo = style.gray(` (${this.selectedIndex + 1}/${this.filteredRules.length})`);
318
+ this.listContainer.addChild(new Text(scrollInfo, 0, 0));
319
+ }
320
+ // Show "no results" if empty
321
+ if (this.filteredRules.length === 0) {
322
+ this.listContainer.addChild(new Text(style.gray(" No matching rules"), 0, 0));
323
+ }
324
+ }
325
+ handleInput(keyData) {
326
+ // Up arrow
327
+ if (keyData === "\x1b[A") {
328
+ this.selectedIndex = Math.max(0, this.selectedIndex - 1);
329
+ this.updateList();
330
+ }
331
+ // Down arrow
332
+ else if (keyData === "\x1b[B") {
333
+ this.selectedIndex = Math.min(this.filteredRules.length - 1, this.selectedIndex + 1);
334
+ this.updateList();
335
+ }
336
+ // Space - toggle selection
337
+ else if (keyData === " ") {
338
+ this.toggleSelection(this.selectedIndex);
339
+ }
340
+ // Enter - confirm selection
341
+ else if (keyData === "\r") {
342
+ this.handleConfirm();
343
+ }
344
+ // Escape
345
+ else if (keyData === "\x1b") {
346
+ this.onCancelCallback();
347
+ }
348
+ // Pass everything else to search input
349
+ else {
350
+ this.searchInput.handleInput(keyData);
351
+ this.filterRules(this.searchInput.getValue());
352
+ }
353
+ }
354
+ toggleSelection(index) {
355
+ if (this.selectedRules.has(index)) {
356
+ this.selectedRules.delete(index);
357
+ }
358
+ else {
359
+ this.selectedRules.add(index);
360
+ }
361
+ this.updateList();
362
+ }
363
+ handleConfirm() {
364
+ const selectedRuleTexts = Array.from(this.selectedRules)
365
+ .map((index) => this.filteredRules[index])
366
+ .filter((rule) => rule !== undefined);
367
+ this.onSelectCallback(selectedRuleTexts);
368
+ }
369
+ getSearchInput() {
370
+ return this.searchInput;
371
+ }
372
+ }
@@ -0,0 +1,3 @@
1
+ import type { CommandOptions, ReplCommand } from "./types.ts";
2
+ export declare const handoffCommand: (options: CommandOptions) => ReplCommand;
3
+ //# sourceMappingURL=handoff-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff-command.d.ts","sourceRoot":"","sources":["../../source/commands/handoff-command.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,cAAc,GAAI,SAAS,cAAc,KAAG,WAkExD,CAAC"}
@@ -0,0 +1,202 @@
1
+ import { generateText } from "ai";
2
+ import style from "../terminal/style.js";
3
+ import { initCliTools } from "../tools/index.js";
4
+ import { Text } from "../tui/index.js";
5
+ export const handoffCommand = (options) => {
6
+ return {
7
+ command: "/handoff",
8
+ description: "Creates a detailed handoff plan of the conversation for continuing the work in a new session. Usage: /handoff <the purpose of the handoff>",
9
+ getSubCommands: () => Promise.resolve([]),
10
+ execute: async (args) => {
11
+ const { terminal } = options;
12
+ // Validate that purpose is provided
13
+ const purpose = args.join(" ").trim();
14
+ if (!purpose) {
15
+ terminal.error("Please provide a purpose for the handoff. Usage: /handoff <the purpose of the handoff>");
16
+ return "continue";
17
+ }
18
+ await createHandoffDocument(options, purpose);
19
+ return "continue";
20
+ },
21
+ async handle(args, { tui, container, editor, }) {
22
+ // Validate that purpose is provided
23
+ const purpose = args.join(" ").trim();
24
+ if (!purpose) {
25
+ container.addChild(new Text(style.red("Please provide a purpose for the handoff. Usage: /handoff <the purpose of the handoff>"), 1, 0));
26
+ tui.requestRender();
27
+ editor.setText("");
28
+ return "continue";
29
+ }
30
+ container.addChild(new Text(`Creating handoff document for purpose: ${style.blue(purpose)}`, 1, 0));
31
+ tui.requestRender();
32
+ await createHandoffDocument(options, purpose);
33
+ container.addChild(new Text(style.green("Handoff document created"), 2, 0));
34
+ tui.requestRender();
35
+ editor.setText("");
36
+ return "continue";
37
+ },
38
+ };
39
+ };
40
+ const handoffPrompt = (purpose) => {
41
+ return `Creates a detailed handoff plan of the conversation for continuing the work in a new session.
42
+
43
+ The user specified purpose:
44
+
45
+ <purpose>${purpose}</purpose>
46
+
47
+ You are creating a summary specifically so that it can be continued by another agent. For this to work you MUST have a purpose. If no specified purpose was provided in the \`<purpose>...</purpose>\` tag you must STOP IMMEDIATELY and ask the user what the purpose is.
48
+
49
+ Do not continue before asking for the purpose as you will otherwise not understand the instructions and do not assume a purpose!
50
+
51
+ ## Goal
52
+
53
+ Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit purpose for the next steps.
54
+ This handoff plan should be thorough in capturing technical details, code patterns, and architectural decisions that will be essential for continuing development work without losing context.
55
+
56
+ ## Process
57
+
58
+ Before providing your final plan, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:
59
+
60
+ 1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:
61
+ - The user's explicit requests and intents
62
+ - Your approach to addressing the user's requests
63
+ - Key decisions, technical concepts and code patterns
64
+ - Specific details like file names, full code snippets, function signatures, file edits, etc
65
+ 2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.
66
+
67
+ Your plan should include the following sections:
68
+
69
+ 1. **Primary Request and Intent**: Capture all of the user's explicit requests and intents in detail
70
+ 2. **Key Technical Concepts**: List all important technical concepts, technologies, and frameworks discussed.
71
+ 3. **Files and Code Sections**: Enumerate specific files and code sections examined, modified, or created. Pay special attention to the most recent messages and include full code snippets where applicable and include a summary of why this file read or edit is important.
72
+ 4. **Problem Solving**: Document problems solved and any ongoing troubleshooting efforts.
73
+ 5. **Pending Tasks**: Outline any pending tasks that you have explicitly been asked to work on.
74
+ 6. **Current Work**: Describe in detail precisely what was being worked on immediately before this handoff request, paying special attention to the most recent messages from both user and assistant. Include file names and code snippets where applicable.
75
+ 7. **Optional Next Step**: List the next step that you will take that is related to the most recent work you were doing. IMPORTANT: ensure that this step is DIRECTLY in line with the user's explicit requests, and the task you were working on immediately before this handoff request. If your last task was concluded, then only list next steps if they are explicitly in line with the users request. Do not start on tangential requests without confirming with the user first.
76
+
77
+ Additionally create a "slug" for this handoff. The "slug" is how we will refer to it later in a few places. Examples:
78
+
79
+ * current-user-api-handler
80
+ * implement-auth
81
+ * fix-issue-42
82
+
83
+ Together with the slug create a "Readable Summary". Examples:
84
+
85
+ * Implement Currnet User API Handler
86
+ * Implement Authentication
87
+ * Fix Issue #42
88
+
89
+ ## Output Structure
90
+
91
+ Here's an example of how your output should be structured:
92
+
93
+ \`\`\` markdown
94
+ # Readable Summary
95
+
96
+ <analysis>
97
+ [Your thought process, ensuring all points are covered thoroughly and accurately]
98
+ </analysis>
99
+
100
+ <plan>
101
+ # Session Handoff Plan
102
+
103
+ ## 1. Primary Request and Intent
104
+ [Detailed description of all user requests and intents]
105
+
106
+ ## 2. Key Technical Concepts
107
+ - [Concept 1]
108
+ - [Concept 2]
109
+ - [...]
110
+
111
+ ## 3. Files and Code Sections
112
+ ### [File Name 1]
113
+ - **Why important**: [Summary of why this file is important]
114
+ - **Changes made**: [Summary of the changes made to this file, if any]
115
+ - **Code snippet**:
116
+ \`\`\` language
117
+ [Important Code Snippet]
118
+ \`\`\`
119
+
120
+ ### [File Name 2]
121
+ - **Code snippet**:
122
+ \`\`\` language
123
+ [Important Code Snippet]
124
+ \`\`\`
125
+
126
+ [...]
127
+
128
+ ## 4. Problem Solving
129
+ [Description of solved problems and ongoing troubleshooting]
130
+
131
+ ## 5. Next Step
132
+ [Required next step to take, directly aligned with user's explicit handoff purpose]
133
+ </plan>
134
+ \`\`\`
135
+
136
+ ## Final Step
137
+
138
+ After providing your analysis and summary, write the handoff summary to a markdown file at \`handoff-[timestamp]-[slug].md\` where [timestamp] is the current date in format YYYY-MM-DD and the slug is what we defined before.
139
+
140
+ Then tell the user about this file and that they can use \`/pickup FILENAME\` to continue.`;
141
+ };
142
+ async function createHandoffDocument({ modelManager, tokenTracker, tokenCounter, workspace }, purpose) {
143
+ const app = "handoff-agent";
144
+ const { text, usage } = await generateText({
145
+ model: modelManager.getModel(app),
146
+ system: "You are a helpful AI assistant tasked with creating detailed handoff summaries for coding agents. Focus on technical accuracy and completeness so that another agent can seamlessly continue the work.",
147
+ prompt: handoffPrompt(purpose),
148
+ tools: (await initCliTools({ tokenCounter, workspace })).toolDefs,
149
+ });
150
+ tokenTracker.trackUsage(app, usage);
151
+ console.info(text);
152
+ // // Parse the response to extract the readable summary and slug
153
+ // const lines = text.split("\n");
154
+ // let readableSummary = "";
155
+ // let slug = "";
156
+ // const planContent = text;
157
+ // // Extract readable summary (first heading after markdown)
158
+ // for (let i = 0; i < lines.length; i++) {
159
+ // const line = lines[i].trim();
160
+ // if (line.startsWith("# ") && !readableSummary) {
161
+ // readableSummary = line.substring(2).trim();
162
+ // break;
163
+ // }
164
+ // }
165
+ // // Create slug from readable summary
166
+ // if (readableSummary) {
167
+ // slug = readableSummary
168
+ // .toLowerCase()
169
+ // .replace(/[^a-z0-9\s-]/g, "")
170
+ // .replace(/\s+/g, "-")
171
+ // .replace(/-+/g, "-")
172
+ // .trim();
173
+ // }
174
+ // // Generate filename with timestamp
175
+ // const now = new Date();
176
+ // const timestamp = now.toISOString().split("T")[0]; // YYYY-MM-DD format
177
+ // const filename = `handoff-${timestamp}-${slug || "session"}.md`;
178
+ // // Create the final handoff document
179
+ // const handoffDocument = `# ${readableSummary || "Session Handoff"}
180
+ // ${planContent}
181
+ // ---
182
+ // *Generated on ${now.toISOString()} for purpose: ${purpose}*
183
+ // *This handoff file can be used to continue the work using the /pickup command*`;
184
+ // // Save the handoff document using the saveFile tool
185
+ // const saveFileTool = await createSaveFileTool({
186
+ // workingDir: workspace.primaryDir,
187
+ // allowedDirs: workspace.allowedDirs,
188
+ // });
189
+ // saveFileTool.execute(
190
+ // {
191
+ // path: `./${filename}`,
192
+ // content: handoffDocument,
193
+ // encoding: "utf-8",
194
+ // },
195
+ // {
196
+ // toolCallId: `handoff-${Date.now()}`,
197
+ // abortSignal: undefined,
198
+ // messages: messageHistory.get(),
199
+ // },
200
+ // );
201
+ // console.info(`Handoff document created: ${filename}`);
202
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"health-command.d.ts","sourceRoot":"","sources":["../../source/commands/health-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,aAAa,CAC3B,EAAE,QAAQ,EAAE,EAAE,cAAc,EAC5B,MAAM,kBAAW,GAChB,WAAW,CAqHb"}
1
+ {"version":3,"file":"health-command.d.ts","sourceRoot":"","sources":["../../source/commands/health-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAI9C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,aAAa,CAC3B,EAAE,QAAQ,EAAE,EAAE,cAAc,EAC5B,MAAM,kBAAW,GAChB,WAAW,CAoRb"}