@travisennis/acai 0.0.1
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.
- package/.acai/acai.json +9 -0
- package/.acai/prompts/add-openrouter-model.md +13 -0
- package/.acai/prompts/project-status.md +4 -0
- package/.acai/prompts/update-architecture-document.md +9 -0
- package/.acai/rules/learned-rules.md +9 -0
- package/.ai/docs/available-tools.txt +3 -0
- package/.ai/docs/cognitive_complexity_refactoring_progress.md +65 -0
- package/.ai/docs/deleted_tools.md +168 -0
- package/.ai/docs/deleted_tools_88ced9ef.md +56 -0
- package/.ai/docs/image-pasting.md +46 -0
- package/.ai/docs/initialize-app.md +117 -0
- package/.ai/docs/issue-4-plan.md +44 -0
- package/.ai/docs/marked-renderer-debug.md +15 -0
- package/.ai/docs/marked-renderer-refactor-plan.md +64 -0
- package/.ai/docs/memory-use-cases.md +55 -0
- package/.ai/docs/prompt-consistency.md +31 -0
- package/.ai/docs/refactoring-tools.md +98 -0
- package/.ai/docs/system-prompt-update.md +174 -0
- package/.ai/docs/system_prompt.txt +210 -0
- package/.ai/docs/tasks.md +49 -0
- package/.ai/plan.md +131 -0
- package/.ai/prompt.md +1 -0
- package/.ai/scripts/fetch_models.js +27 -0
- package/.ai/scripts/generateSystemPrompt.ts +15 -0
- package/.ai/scripts/list-tools.mjs +4 -0
- package/.ai/scripts/p5_geometric_shapes.js +149 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +3 -0
- package/.husky/pre-push +1 -0
- package/.ignore +4 -0
- package/AGENTS.md +25 -0
- package/ARCHITECTURE.md +304 -0
- package/LICENSE +21 -0
- package/README.md +392 -0
- package/TODO.md +2 -0
- package/biome.json +61 -0
- package/commitlint.config.js +3 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +116 -0
- package/dist/commands/application-log-command.d.ts +2 -0
- package/dist/commands/application-log-command.js +43 -0
- package/dist/commands/clear-command.d.ts +2 -0
- package/dist/commands/clear-command.js +12 -0
- package/dist/commands/compact-command.d.ts +2 -0
- package/dist/commands/compact-command.js +51 -0
- package/dist/commands/copy-command.d.ts +2 -0
- package/dist/commands/copy-command.js +51 -0
- package/dist/commands/edit-command.d.ts +2 -0
- package/dist/commands/edit-command.js +53 -0
- package/dist/commands/edit-prompt-command.d.ts +2 -0
- package/dist/commands/edit-prompt-command.js +25 -0
- package/dist/commands/exit-command.d.ts +2 -0
- package/dist/commands/exit-command.js +14 -0
- package/dist/commands/files-command.d.ts +2 -0
- package/dist/commands/files-command.js +63 -0
- package/dist/commands/generate-rules-command.d.ts +2 -0
- package/dist/commands/generate-rules-command.js +61 -0
- package/dist/commands/help-command.d.ts +2 -0
- package/dist/commands/help-command.js +19 -0
- package/dist/commands/init-command.d.ts +2 -0
- package/dist/commands/init-command.js +40 -0
- package/dist/commands/last-log-command.d.ts +2 -0
- package/dist/commands/last-log-command.js +76 -0
- package/dist/commands/manager.d.ts +22 -0
- package/dist/commands/manager.js +123 -0
- package/dist/commands/model-command.d.ts +2 -0
- package/dist/commands/model-command.js +84 -0
- package/dist/commands/paste-command.d.ts +2 -0
- package/dist/commands/paste-command.js +40 -0
- package/dist/commands/prompt-command.d.ts +2 -0
- package/dist/commands/prompt-command.js +111 -0
- package/dist/commands/reset-command.d.ts +2 -0
- package/dist/commands/reset-command.js +16 -0
- package/dist/commands/rules-command.d.ts +2 -0
- package/dist/commands/rules-command.js +68 -0
- package/dist/commands/save-command.d.ts +2 -0
- package/dist/commands/save-command.js +14 -0
- package/dist/commands/types.d.ts +26 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/usage-command.d.ts +2 -0
- package/dist/commands/usage-command.js +21 -0
- package/dist/config.d.ts +60 -0
- package/dist/config.js +193 -0
- package/dist/conversation-analyzer.d.ts +10 -0
- package/dist/conversation-analyzer.js +88 -0
- package/dist/dedent.d.ts +3 -0
- package/dist/dedent.js +38 -0
- package/dist/formatting.d.ts +17 -0
- package/dist/formatting.js +103 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +213 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +24 -0
- package/dist/mentions.d.ts +9 -0
- package/dist/mentions.js +182 -0
- package/dist/messages.d.ts +69 -0
- package/dist/messages.js +261 -0
- package/dist/middleware/audit-message.d.ts +5 -0
- package/dist/middleware/audit-message.js +95 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/rate-limit.d.ts +4 -0
- package/dist/middleware/rate-limit.js +17 -0
- package/dist/models/ai-config.d.ts +12 -0
- package/dist/models/ai-config.js +87 -0
- package/dist/models/anthropic-provider.d.ts +25 -0
- package/dist/models/anthropic-provider.js +184 -0
- package/dist/models/deepseek-provider.d.ts +20 -0
- package/dist/models/deepseek-provider.js +42 -0
- package/dist/models/google-provider.d.ts +19 -0
- package/dist/models/google-provider.js +56 -0
- package/dist/models/manager.d.ts +15 -0
- package/dist/models/manager.js +48 -0
- package/dist/models/openai-provider.d.ts +22 -0
- package/dist/models/openai-provider.js +70 -0
- package/dist/models/openrouter-provider.d.ts +36 -0
- package/dist/models/openrouter-provider.js +276 -0
- package/dist/models/providers.d.ts +33 -0
- package/dist/models/providers.js +116 -0
- package/dist/models/xai-provider.d.ts +20 -0
- package/dist/models/xai-provider.js +47 -0
- package/dist/parsing.d.ts +2 -0
- package/dist/parsing.js +18 -0
- package/dist/prompts/manager.d.ts +19 -0
- package/dist/prompts/manager.js +71 -0
- package/dist/prompts.d.ts +4 -0
- package/dist/prompts.js +158 -0
- package/dist/repl-prompt.d.ts +14 -0
- package/dist/repl-prompt.js +147 -0
- package/dist/repl.d.ts +27 -0
- package/dist/repl.js +431 -0
- package/dist/source/cli.d.ts +19 -0
- package/dist/source/cli.js +116 -0
- package/dist/source/commands/application-log-command.d.ts +2 -0
- package/dist/source/commands/application-log-command.js +43 -0
- package/dist/source/commands/clear-command.d.ts +2 -0
- package/dist/source/commands/clear-command.js +12 -0
- package/dist/source/commands/compact-command.d.ts +2 -0
- package/dist/source/commands/compact-command.js +51 -0
- package/dist/source/commands/copy-command.d.ts +2 -0
- package/dist/source/commands/copy-command.js +51 -0
- package/dist/source/commands/edit-command.d.ts +2 -0
- package/dist/source/commands/edit-command.js +53 -0
- package/dist/source/commands/edit-prompt-command.d.ts +2 -0
- package/dist/source/commands/edit-prompt-command.js +25 -0
- package/dist/source/commands/exit-command.d.ts +2 -0
- package/dist/source/commands/exit-command.js +14 -0
- package/dist/source/commands/files-command.d.ts +2 -0
- package/dist/source/commands/files-command.js +63 -0
- package/dist/source/commands/generate-rules-command.d.ts +2 -0
- package/dist/source/commands/generate-rules-command.js +61 -0
- package/dist/source/commands/help-command.d.ts +2 -0
- package/dist/source/commands/help-command.js +19 -0
- package/dist/source/commands/init-command.d.ts +2 -0
- package/dist/source/commands/init-command.js +40 -0
- package/dist/source/commands/last-log-command.d.ts +2 -0
- package/dist/source/commands/last-log-command.js +76 -0
- package/dist/source/commands/manager.d.ts +22 -0
- package/dist/source/commands/manager.js +123 -0
- package/dist/source/commands/model-command.d.ts +2 -0
- package/dist/source/commands/model-command.js +84 -0
- package/dist/source/commands/paste-command.d.ts +2 -0
- package/dist/source/commands/paste-command.js +40 -0
- package/dist/source/commands/prompt-command.d.ts +2 -0
- package/dist/source/commands/prompt-command.js +111 -0
- package/dist/source/commands/reset-command.d.ts +2 -0
- package/dist/source/commands/reset-command.js +16 -0
- package/dist/source/commands/rules-command.d.ts +2 -0
- package/dist/source/commands/rules-command.js +68 -0
- package/dist/source/commands/save-command.d.ts +2 -0
- package/dist/source/commands/save-command.js +14 -0
- package/dist/source/commands/types.d.ts +26 -0
- package/dist/source/commands/types.js +1 -0
- package/dist/source/commands/usage-command.d.ts +2 -0
- package/dist/source/commands/usage-command.js +21 -0
- package/dist/source/config.d.ts +60 -0
- package/dist/source/config.js +193 -0
- package/dist/source/conversation-analyzer.d.ts +10 -0
- package/dist/source/conversation-analyzer.js +88 -0
- package/dist/source/dedent.d.ts +3 -0
- package/dist/source/dedent.js +38 -0
- package/dist/source/formatting.d.ts +17 -0
- package/dist/source/formatting.js +103 -0
- package/dist/source/index.d.ts +18 -0
- package/dist/source/index.js +213 -0
- package/dist/source/logger.d.ts +2 -0
- package/dist/source/logger.js +24 -0
- package/dist/source/mentions.d.ts +9 -0
- package/dist/source/mentions.js +182 -0
- package/dist/source/messages.d.ts +69 -0
- package/dist/source/messages.js +261 -0
- package/dist/source/middleware/audit-message.d.ts +5 -0
- package/dist/source/middleware/audit-message.js +95 -0
- package/dist/source/middleware/index.d.ts +2 -0
- package/dist/source/middleware/index.js +2 -0
- package/dist/source/middleware/rate-limit.d.ts +4 -0
- package/dist/source/middleware/rate-limit.js +17 -0
- package/dist/source/models/ai-config.d.ts +12 -0
- package/dist/source/models/ai-config.js +87 -0
- package/dist/source/models/anthropic-provider.d.ts +25 -0
- package/dist/source/models/anthropic-provider.js +184 -0
- package/dist/source/models/deepseek-provider.d.ts +20 -0
- package/dist/source/models/deepseek-provider.js +42 -0
- package/dist/source/models/google-provider.d.ts +19 -0
- package/dist/source/models/google-provider.js +56 -0
- package/dist/source/models/manager.d.ts +15 -0
- package/dist/source/models/manager.js +48 -0
- package/dist/source/models/openai-provider.d.ts +22 -0
- package/dist/source/models/openai-provider.js +70 -0
- package/dist/source/models/openrouter-provider.d.ts +36 -0
- package/dist/source/models/openrouter-provider.js +276 -0
- package/dist/source/models/providers.d.ts +33 -0
- package/dist/source/models/providers.js +116 -0
- package/dist/source/models/xai-provider.d.ts +20 -0
- package/dist/source/models/xai-provider.js +47 -0
- package/dist/source/parsing.d.ts +2 -0
- package/dist/source/parsing.js +18 -0
- package/dist/source/prompts/manager.d.ts +19 -0
- package/dist/source/prompts/manager.js +71 -0
- package/dist/source/prompts.d.ts +4 -0
- package/dist/source/prompts.js +158 -0
- package/dist/source/repl-prompt.d.ts +14 -0
- package/dist/source/repl-prompt.js +147 -0
- package/dist/source/repl.d.ts +27 -0
- package/dist/source/repl.js +431 -0
- package/dist/source/terminal/formatting.d.ts +37 -0
- package/dist/source/terminal/formatting.js +106 -0
- package/dist/source/terminal/index.d.ts +94 -0
- package/dist/source/terminal/index.js +420 -0
- package/dist/source/terminal/markdown-utils.d.ts +2 -0
- package/dist/source/terminal/markdown-utils.js +81 -0
- package/dist/source/terminal/markdown.d.ts +1 -0
- package/dist/source/terminal/markdown.js +111 -0
- package/dist/source/terminal/types.d.ts +71 -0
- package/dist/source/terminal/types.js +1 -0
- package/dist/source/terminal-output.d.ts +8 -0
- package/dist/source/terminal-output.js +213 -0
- package/dist/source/terminal-output.test.d.ts +8 -0
- package/dist/source/terminal-output.test.js +213 -0
- package/dist/source/token-tracker.d.ts +14 -0
- package/dist/source/token-tracker.js +53 -0
- package/dist/source/token-utils.d.ts +7 -0
- package/dist/source/token-utils.js +13 -0
- package/dist/source/tools/agent.d.ts +17 -0
- package/dist/source/tools/agent.js +87 -0
- package/dist/source/tools/bash.d.ts +19 -0
- package/dist/source/tools/bash.js +294 -0
- package/dist/source/tools/code-interpreter.d.ts +12 -0
- package/dist/source/tools/code-interpreter.js +131 -0
- package/dist/source/tools/command-validation.d.ts +8 -0
- package/dist/source/tools/command-validation.js +69 -0
- package/dist/source/tools/delete-file.d.ts +12 -0
- package/dist/source/tools/delete-file.js +56 -0
- package/dist/source/tools/directory-tree.d.ts +12 -0
- package/dist/source/tools/directory-tree.js +38 -0
- package/dist/source/tools/edit-file.d.ts +19 -0
- package/dist/source/tools/edit-file.js +107 -0
- package/dist/source/tools/filesystem-utils.d.ts +22 -0
- package/dist/source/tools/filesystem-utils.js +191 -0
- package/dist/source/tools/git-utils.d.ts +14 -0
- package/dist/source/tools/git-utils.js +64 -0
- package/dist/source/tools/grep.d.ts +17 -0
- package/dist/source/tools/grep.js +138 -0
- package/dist/source/tools/index.d.ts +161 -0
- package/dist/source/tools/index.js +209 -0
- package/dist/source/tools/memory-read.d.ts +13 -0
- package/dist/source/tools/memory-read.js +135 -0
- package/dist/source/tools/memory-write.d.ts +12 -0
- package/dist/source/tools/memory-write.js +83 -0
- package/dist/source/tools/move-file.d.ts +13 -0
- package/dist/source/tools/move-file.js +44 -0
- package/dist/source/tools/read-file.d.ts +17 -0
- package/dist/source/tools/read-file.js +86 -0
- package/dist/source/tools/read-multiple-files.d.ts +14 -0
- package/dist/source/tools/read-multiple-files.js +55 -0
- package/dist/source/tools/save-file.d.ts +17 -0
- package/dist/source/tools/save-file.js +98 -0
- package/dist/source/tools/think.d.ts +11 -0
- package/dist/source/tools/think.js +45 -0
- package/dist/source/tools/types.d.ts +29 -0
- package/dist/source/tools/types.js +14 -0
- package/dist/source/tools/web-fetch.d.ts +47 -0
- package/dist/source/tools/web-fetch.js +246 -0
- package/dist/source/tools/web-search.d.ts +13 -0
- package/dist/source/tools/web-search.js +80 -0
- package/dist/source/utils/process.d.ts +36 -0
- package/dist/source/utils/process.js +75 -0
- package/dist/source/version.d.ts +1 -0
- package/dist/source/version.js +21 -0
- package/dist/terminal/formatting.d.ts +37 -0
- package/dist/terminal/formatting.js +106 -0
- package/dist/terminal/index.d.ts +94 -0
- package/dist/terminal/index.js +420 -0
- package/dist/terminal/markdown-utils.d.ts +2 -0
- package/dist/terminal/markdown-utils.js +81 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.js +111 -0
- package/dist/terminal/types.d.ts +71 -0
- package/dist/terminal/types.js +1 -0
- package/dist/terminal-output.d.ts +8 -0
- package/dist/terminal-output.js +213 -0
- package/dist/token-tracker.d.ts +14 -0
- package/dist/token-tracker.js +53 -0
- package/dist/token-utils.d.ts +7 -0
- package/dist/token-utils.js +13 -0
- package/dist/tools/agent.d.ts +17 -0
- package/dist/tools/agent.js +87 -0
- package/dist/tools/bash.d.ts +19 -0
- package/dist/tools/bash.js +294 -0
- package/dist/tools/code-interpreter.d.ts +12 -0
- package/dist/tools/code-interpreter.js +131 -0
- package/dist/tools/command-validation.d.ts +8 -0
- package/dist/tools/command-validation.js +69 -0
- package/dist/tools/delete-file.d.ts +12 -0
- package/dist/tools/delete-file.js +56 -0
- package/dist/tools/directory-tree.d.ts +12 -0
- package/dist/tools/directory-tree.js +38 -0
- package/dist/tools/edit-file.d.ts +19 -0
- package/dist/tools/edit-file.js +107 -0
- package/dist/tools/filesystem-utils.d.ts +22 -0
- package/dist/tools/filesystem-utils.js +191 -0
- package/dist/tools/git-utils.d.ts +14 -0
- package/dist/tools/git-utils.js +64 -0
- package/dist/tools/grep.d.ts +17 -0
- package/dist/tools/grep.js +138 -0
- package/dist/tools/index.d.ts +161 -0
- package/dist/tools/index.js +209 -0
- package/dist/tools/memory-read.d.ts +13 -0
- package/dist/tools/memory-read.js +135 -0
- package/dist/tools/memory-write.d.ts +12 -0
- package/dist/tools/memory-write.js +83 -0
- package/dist/tools/move-file.d.ts +13 -0
- package/dist/tools/move-file.js +44 -0
- package/dist/tools/read-file.d.ts +17 -0
- package/dist/tools/read-file.js +86 -0
- package/dist/tools/read-multiple-files.d.ts +14 -0
- package/dist/tools/read-multiple-files.js +55 -0
- package/dist/tools/save-file.d.ts +17 -0
- package/dist/tools/save-file.js +98 -0
- package/dist/tools/think.d.ts +11 -0
- package/dist/tools/think.js +45 -0
- package/dist/tools/types.d.ts +29 -0
- package/dist/tools/types.js +14 -0
- package/dist/tools/web-fetch.d.ts +47 -0
- package/dist/tools/web-fetch.js +246 -0
- package/dist/tools/web-search.d.ts +13 -0
- package/dist/tools/web-search.js +80 -0
- package/dist/utils/process.d.ts +36 -0
- package/dist/utils/process.js +75 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +21 -0
- package/knip.json +5 -0
- package/package.json +83 -0
- package/source/cli.ts +172 -0
- package/source/commands/application-log-command.ts +53 -0
- package/source/commands/clear-command.ts +14 -0
- package/source/commands/compact-command.ts +64 -0
- package/source/commands/copy-command.ts +55 -0
- package/source/commands/edit-command.ts +63 -0
- package/source/commands/edit-prompt-command.ts +31 -0
- package/source/commands/exit-command.ts +18 -0
- package/source/commands/files-command.ts +85 -0
- package/source/commands/generate-rules-command.ts +82 -0
- package/source/commands/help-command.ts +27 -0
- package/source/commands/init-command.ts +48 -0
- package/source/commands/last-log-command.ts +88 -0
- package/source/commands/manager.ts +151 -0
- package/source/commands/model-command.ts +123 -0
- package/source/commands/paste-command.ts +62 -0
- package/source/commands/prompt-command.ts +150 -0
- package/source/commands/reset-command.ts +22 -0
- package/source/commands/rules-command.ts +76 -0
- package/source/commands/save-command.ts +20 -0
- package/source/commands/types.ts +28 -0
- package/source/commands/usage-command.ts +26 -0
- package/source/config.ts +223 -0
- package/source/conversation-analyzer.ts +115 -0
- package/source/dedent.ts +53 -0
- package/source/formatting.ts +132 -0
- package/source/index.ts +240 -0
- package/source/logger.ts +29 -0
- package/source/mentions.ts +227 -0
- package/source/messages.ts +360 -0
- package/source/middleware/audit-message.ts +133 -0
- package/source/middleware/index.ts +2 -0
- package/source/middleware/rate-limit.ts +24 -0
- package/source/models/ai-config.ts +109 -0
- package/source/models/anthropic-provider.ts +199 -0
- package/source/models/deepseek-provider.ts +53 -0
- package/source/models/google-provider.ts +68 -0
- package/source/models/manager.ts +84 -0
- package/source/models/openai-provider.ts +81 -0
- package/source/models/openrouter-provider.ts +288 -0
- package/source/models/providers.ts +197 -0
- package/source/models/xai-provider.ts +59 -0
- package/source/parsing.ts +20 -0
- package/source/prompts/manager.ts +90 -0
- package/source/prompts.ts +172 -0
- package/source/repl-prompt.ts +196 -0
- package/source/repl.ts +572 -0
- package/source/terminal/formatting.ts +121 -0
- package/source/terminal/index.ts +518 -0
- package/source/terminal/markdown-utils.ts +89 -0
- package/source/terminal/markdown.ts +155 -0
- package/source/terminal/types.ts +84 -0
- package/source/terminal-output.test.ts +266 -0
- package/source/token-tracker.ts +78 -0
- package/source/token-utils.ts +17 -0
- package/source/tools/agent.ts +107 -0
- package/source/tools/bash.ts +367 -0
- package/source/tools/code-interpreter.ts +172 -0
- package/source/tools/command-validation.ts +81 -0
- package/source/tools/delete-file.ts +71 -0
- package/source/tools/directory-tree.ts +54 -0
- package/source/tools/edit-file.ts +155 -0
- package/source/tools/filesystem-utils.ts +265 -0
- package/source/tools/git-utils.ts +70 -0
- package/source/tools/grep.ts +184 -0
- package/source/tools/index.ts +278 -0
- package/source/tools/memory-read.ts +174 -0
- package/source/tools/memory-write.ts +105 -0
- package/source/tools/move-file.ts +59 -0
- package/source/tools/read-file.ts +129 -0
- package/source/tools/read-multiple-files.ts +80 -0
- package/source/tools/save-file.ts +147 -0
- package/source/tools/think.ts +51 -0
- package/source/tools/types.ts +58 -0
- package/source/tools/web-fetch.ts +327 -0
- package/source/tools/web-search.ts +101 -0
- package/source/utils/process.ts +121 -0
- package/source/version.ts +21 -0
- package/test/commands/copy-command.test.ts +69 -0
- package/test/config.test.ts +200 -0
- package/test/terminal/markdown-utils.test.ts +124 -0
- package/test/tools/bash-tool.test.ts +58 -0
- package/test/tools/code-interpreter.test.ts +91 -0
- package/test/tools/command-validation.test.ts +48 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,10 @@
|
|
|
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[]>;
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
}
|
package/dist/dedent.d.ts
ADDED
package/dist/dedent.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { text } from "node:stream/consumers";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { select } from "@inquirer/prompts";
|
|
4
|
+
import { asyncTry } from "@travisennis/stdlib/try";
|
|
5
|
+
import { isDefined } from "@travisennis/stdlib/typeguards";
|
|
6
|
+
import { Cli } from "./cli.js";
|
|
7
|
+
import { CommandManager } from "./commands/manager.js";
|
|
8
|
+
import { config } from "./config.js";
|
|
9
|
+
import { logger } from "./logger.js";
|
|
10
|
+
import { MessageHistory } from "./messages.js";
|
|
11
|
+
import { ModelManager } from "./models/manager.js";
|
|
12
|
+
import { isSupportedModel } from "./models/providers.js";
|
|
13
|
+
import { PromptManager } from "./prompts/manager.js";
|
|
14
|
+
import { Repl } from "./repl.js";
|
|
15
|
+
import { initTerminal } from "./terminal/index.js";
|
|
16
|
+
import { TokenTracker } from "./token-tracker.js";
|
|
17
|
+
import { TokenCounter } from "./token-utils.js";
|
|
18
|
+
import { getPackageVersion } from "./version.js";
|
|
19
|
+
const helpText = `
|
|
20
|
+
Usage
|
|
21
|
+
$ acai <input>
|
|
22
|
+
|
|
23
|
+
Options
|
|
24
|
+
--model, -m Sets the model to use
|
|
25
|
+
--prompt, -p Sets the prompt
|
|
26
|
+
--oneshot, -o Run once and exit
|
|
27
|
+
--continue Load the most recent conversation
|
|
28
|
+
--resume Select a recent conversation to resume
|
|
29
|
+
--autoAcceptAll Accept all commands and edits without prompting
|
|
30
|
+
--help, -h Show help
|
|
31
|
+
--version, -v Show version
|
|
32
|
+
|
|
33
|
+
Examples
|
|
34
|
+
$ acai --model anthopric:sonnet
|
|
35
|
+
$ acai -p "initial prompt"
|
|
36
|
+
$ acai -p "one-shot prompt" -o
|
|
37
|
+
`;
|
|
38
|
+
const parsed = parseArgs({
|
|
39
|
+
options: {
|
|
40
|
+
model: { type: "string", short: "m" },
|
|
41
|
+
prompt: { type: "string", short: "p" },
|
|
42
|
+
oneshot: { type: "boolean", short: "o", default: false },
|
|
43
|
+
continue: { type: "boolean", default: false },
|
|
44
|
+
resume: { type: "boolean", default: false },
|
|
45
|
+
autoAcceptAll: { type: "boolean", default: false },
|
|
46
|
+
help: { type: "boolean", short: "h" },
|
|
47
|
+
version: { type: "boolean", short: "v" },
|
|
48
|
+
},
|
|
49
|
+
allowPositionals: true,
|
|
50
|
+
});
|
|
51
|
+
const flags = parsed.values;
|
|
52
|
+
const input = parsed.positionals;
|
|
53
|
+
/**
|
|
54
|
+
* Global error handler function.
|
|
55
|
+
* @param {Error} error - The error to be handled.
|
|
56
|
+
* @throws {Error} Rethrows the error after logging it.
|
|
57
|
+
*/
|
|
58
|
+
export function handleError(error) {
|
|
59
|
+
logger.error({ error: error }, error.message);
|
|
60
|
+
}
|
|
61
|
+
async function main() {
|
|
62
|
+
const appConfig = await config.ensureAppConfig("acai");
|
|
63
|
+
if (flags.version === true) {
|
|
64
|
+
console.info(getPackageVersion());
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}
|
|
67
|
+
if (flags.help === true) {
|
|
68
|
+
console.info(helpText);
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
const appDir = config.app;
|
|
72
|
+
const messageHistoryDir = await appDir.ensurePath("message-history");
|
|
73
|
+
// --- Argument Validation ---
|
|
74
|
+
if (flags.continue === true && flags.resume === true) {
|
|
75
|
+
console.error("Cannot use --continue and --resume flags together.");
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const hasContinueOrResume = flags.continue === true || flags.resume === true;
|
|
79
|
+
if (hasContinueOrResume && flags.oneshot === true) {
|
|
80
|
+
console.error("Cannot use --continue or --resume with --oneshot.");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
// --- Determine Initial Prompt (potential conflict) ---
|
|
84
|
+
const positionalPrompt = input.at(0);
|
|
85
|
+
let stdInPrompt;
|
|
86
|
+
// Check if there's data available on stdin
|
|
87
|
+
if (!process.stdin.isTTY) {
|
|
88
|
+
try {
|
|
89
|
+
// Non-TTY stdin means data is being piped in
|
|
90
|
+
stdInPrompt = await text(process.stdin);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(`Error reading stdin: ${error.message}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const initialPromptInput = typeof flags.prompt === "string" && flags.prompt.length > 0
|
|
97
|
+
? flags.prompt
|
|
98
|
+
: positionalPrompt && positionalPrompt.length > 0
|
|
99
|
+
? positionalPrompt
|
|
100
|
+
: undefined;
|
|
101
|
+
if (hasContinueOrResume && isDefined(initialPromptInput)) {
|
|
102
|
+
console.error("Cannot use --continue or --resume with an initial prompt.");
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
const terminal = initTerminal();
|
|
106
|
+
terminal.setTitle(`acai: ${process.cwd()}`);
|
|
107
|
+
const chosenModel = isSupportedModel(flags.model)
|
|
108
|
+
? flags.model
|
|
109
|
+
: "openrouter:sonnet4";
|
|
110
|
+
const modelManager = new ModelManager({
|
|
111
|
+
stateDir: await appDir.ensurePath("audit"),
|
|
112
|
+
});
|
|
113
|
+
modelManager.setModel("repl", chosenModel);
|
|
114
|
+
modelManager.setModel("cli", chosenModel);
|
|
115
|
+
modelManager.setModel("title-conversation", "openrouter:gemini-flash25");
|
|
116
|
+
modelManager.setModel("conversation-summarizer", "openrouter:gemini-flash25");
|
|
117
|
+
modelManager.setModel("tool-repair", "openai:gpt-4.1");
|
|
118
|
+
modelManager.setModel("conversation-analyzer", "openrouter:gemini-flash25");
|
|
119
|
+
modelManager.setModel("init-project", chosenModel);
|
|
120
|
+
modelManager.setModel("task-agent", "openrouter:gemini-flash25");
|
|
121
|
+
const tokenTracker = new TokenTracker();
|
|
122
|
+
const tokenCounter = new TokenCounter();
|
|
123
|
+
const messageHistory = new MessageHistory({
|
|
124
|
+
stateDir: messageHistoryDir,
|
|
125
|
+
modelManager,
|
|
126
|
+
tokenTracker,
|
|
127
|
+
});
|
|
128
|
+
messageHistory.on("update-title", (title) => terminal.setTitle(title));
|
|
129
|
+
if (flags.continue === true) {
|
|
130
|
+
const histories = await MessageHistory.load(messageHistoryDir, 1);
|
|
131
|
+
const latestHistory = histories.at(0);
|
|
132
|
+
if (latestHistory) {
|
|
133
|
+
messageHistory.restore(latestHistory);
|
|
134
|
+
console.info(`Resuming conversation: ${latestHistory.title}`);
|
|
135
|
+
// Set terminal title after restoring
|
|
136
|
+
terminal.setTitle(latestHistory.title || `acai: ${process.cwd()}`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
logger.info("No previous conversation found to continue.");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (flags.resume === true) {
|
|
143
|
+
const histories = await MessageHistory.load(messageHistoryDir, 10);
|
|
144
|
+
if (histories.length > 0) {
|
|
145
|
+
const choice = await select({
|
|
146
|
+
message: "Select a conversation to resume:",
|
|
147
|
+
choices: histories.map((h, index) => ({
|
|
148
|
+
name: `${index + 1}: ${h.title} (${h.updatedAt.toLocaleString()})`,
|
|
149
|
+
value: index,
|
|
150
|
+
description: `${h.messages.length} messages`,
|
|
151
|
+
})),
|
|
152
|
+
});
|
|
153
|
+
const selectedHistory = histories.at(choice);
|
|
154
|
+
if (selectedHistory) {
|
|
155
|
+
messageHistory.restore(selectedHistory);
|
|
156
|
+
logger.info(`Resuming conversation: ${selectedHistory.title}`);
|
|
157
|
+
// Set terminal title after restoring
|
|
158
|
+
terminal.setTitle(selectedHistory.title || `acai: ${process.cwd()}`);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
// This case should theoretically not happen if choice is valid
|
|
162
|
+
logger.error("Selected history index out of bounds.");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
logger.info("No previous conversations found to resume.");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// --- Setup Prompt Manager (only if not continuing/resuming) ---
|
|
170
|
+
const promptManager = new PromptManager(tokenCounter);
|
|
171
|
+
if (!hasContinueOrResume && isDefined(initialPromptInput)) {
|
|
172
|
+
promptManager.set(initialPromptInput);
|
|
173
|
+
}
|
|
174
|
+
if (stdInPrompt) {
|
|
175
|
+
promptManager.addContext(stdInPrompt);
|
|
176
|
+
}
|
|
177
|
+
const toolEvents = new Map();
|
|
178
|
+
const commands = new CommandManager({
|
|
179
|
+
promptManager,
|
|
180
|
+
modelManager,
|
|
181
|
+
terminal,
|
|
182
|
+
messageHistory,
|
|
183
|
+
tokenTracker,
|
|
184
|
+
config,
|
|
185
|
+
tokenCounter,
|
|
186
|
+
toolEvents,
|
|
187
|
+
});
|
|
188
|
+
if (flags.oneshot === true) {
|
|
189
|
+
const cliProcess = new Cli({
|
|
190
|
+
promptManager,
|
|
191
|
+
config: appConfig,
|
|
192
|
+
messageHistory,
|
|
193
|
+
modelManager,
|
|
194
|
+
tokenTracker,
|
|
195
|
+
tokenCounter,
|
|
196
|
+
});
|
|
197
|
+
return (await asyncTry(cliProcess.run())).recover(handleError);
|
|
198
|
+
}
|
|
199
|
+
const repl = new Repl({
|
|
200
|
+
promptManager,
|
|
201
|
+
terminal,
|
|
202
|
+
config: appConfig,
|
|
203
|
+
messageHistory,
|
|
204
|
+
modelManager,
|
|
205
|
+
tokenTracker,
|
|
206
|
+
commands,
|
|
207
|
+
tokenCounter,
|
|
208
|
+
toolEvents,
|
|
209
|
+
autoAcceptAll: flags.autoAcceptAll === true,
|
|
210
|
+
});
|
|
211
|
+
return (await asyncTry(repl.run())).recover(handleError);
|
|
212
|
+
}
|
|
213
|
+
main();
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import pino from "pino";
|
|
3
|
+
import { config } from "./config.js";
|
|
4
|
+
const transport = pino.transport({
|
|
5
|
+
target: "pino-roll",
|
|
6
|
+
options: {
|
|
7
|
+
file: join(config.app.ensurePathSync("logs"), "acai.log"),
|
|
8
|
+
size: "10m",
|
|
9
|
+
symlink: true,
|
|
10
|
+
limit: {
|
|
11
|
+
count: 3,
|
|
12
|
+
},
|
|
13
|
+
mkdir: true,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
export const logger = pino({
|
|
17
|
+
level: process.env["LOG_LEVEL"] ?? "debug",
|
|
18
|
+
formatters: {
|
|
19
|
+
level: (label) => {
|
|
20
|
+
return { level: label.toUpperCase() };
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
24
|
+
}, transport);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModelMetadata } from "./models/providers.ts";
|
|
2
|
+
import type { ContextItem } from "./prompts/manager.ts";
|
|
3
|
+
export declare function processPrompt(message: string, { baseDir, model }: {
|
|
4
|
+
baseDir: string;
|
|
5
|
+
model: ModelMetadata;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
message: string;
|
|
8
|
+
context: ContextItem[];
|
|
9
|
+
}>;
|