@travisennis/acai 0.0.4 → 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.
- package/README.md +229 -8
- package/dist/agent/index.d.ts +119 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +406 -0
- package/dist/agent/manual-loop.d.ts +41 -0
- package/dist/agent/manual-loop.d.ts.map +1 -0
- package/dist/agent/manual-loop.js +278 -0
- package/dist/api/exa/index.d.ts +177 -0
- package/dist/api/exa/index.d.ts.map +1 -0
- package/dist/api/exa/index.js +439 -0
- package/dist/cli.d.ts +5 -2
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +27 -33
- package/dist/commands/add-directory-command.d.ts +3 -0
- package/dist/commands/add-directory-command.d.ts.map +1 -0
- package/dist/commands/add-directory-command.js +85 -0
- package/dist/commands/application-log-command.d.ts +1 -0
- package/dist/commands/application-log-command.d.ts.map +1 -0
- package/dist/commands/application-log-command.js +39 -3
- package/dist/commands/clear-command.d.ts +1 -0
- package/dist/commands/clear-command.d.ts.map +1 -0
- package/dist/commands/clear-command.js +10 -3
- package/dist/commands/compact-command.d.ts +1 -0
- package/dist/commands/compact-command.d.ts.map +1 -0
- package/dist/commands/compact-command.js +16 -3
- package/dist/commands/context-command.d.ts +3 -0
- package/dist/commands/context-command.d.ts.map +1 -0
- package/dist/commands/context-command.js +183 -0
- package/dist/commands/copy-command.d.ts +1 -0
- package/dist/commands/copy-command.d.ts.map +1 -0
- package/dist/commands/copy-command.js +31 -2
- package/dist/commands/edit-command.d.ts +1 -0
- package/dist/commands/edit-command.d.ts.map +1 -0
- package/dist/commands/edit-command.js +40 -5
- package/dist/commands/edit-prompt-command.d.ts +2 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -0
- package/dist/commands/edit-prompt-command.js +43 -7
- package/dist/commands/exit-command.d.ts +13 -2
- package/dist/commands/exit-command.d.ts.map +1 -0
- package/dist/commands/exit-command.js +34 -2
- package/dist/commands/files-command.d.ts +1 -0
- package/dist/commands/files-command.d.ts.map +1 -0
- package/dist/commands/files-command.js +66 -8
- package/dist/commands/generate-rules-command.d.ts +1 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -0
- package/dist/commands/generate-rules-command.js +315 -4
- package/dist/commands/handoff-command.d.ts +3 -0
- package/dist/commands/handoff-command.d.ts.map +1 -0
- package/dist/commands/handoff-command.js +202 -0
- package/dist/commands/health-command.d.ts +3 -1
- package/dist/commands/health-command.d.ts.map +1 -0
- package/dist/commands/health-command.js +160 -6
- package/dist/commands/help-command.d.ts +1 -0
- package/dist/commands/help-command.d.ts.map +1 -0
- package/dist/commands/help-command.js +30 -3
- package/dist/commands/history-command.d.ts +3 -0
- package/dist/commands/history-command.d.ts.map +1 -0
- package/dist/commands/history-command.js +534 -0
- package/dist/commands/init-command.d.ts +2 -1
- package/dist/commands/init-command.d.ts.map +1 -0
- package/dist/commands/init-command.js +56 -20
- package/dist/commands/last-log-command.d.ts +1 -0
- package/dist/commands/last-log-command.d.ts.map +1 -0
- package/dist/commands/last-log-command.js +39 -17
- package/dist/commands/list-directories-command.d.ts +3 -0
- package/dist/commands/list-directories-command.d.ts.map +1 -0
- package/dist/commands/list-directories-command.js +48 -0
- package/dist/commands/list-tools-command.d.ts +3 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -0
- package/dist/commands/list-tools-command.js +124 -0
- package/dist/commands/manager.d.ts +20 -3
- package/dist/commands/manager.d.ts.map +1 -0
- package/dist/commands/manager.js +123 -26
- package/dist/commands/model-command.d.ts +23 -0
- package/dist/commands/model-command.d.ts.map +1 -0
- package/dist/commands/model-command.js +261 -5
- package/dist/commands/paste-command.d.ts +1 -0
- package/dist/commands/paste-command.d.ts.map +1 -0
- package/dist/commands/paste-command.js +98 -5
- package/dist/commands/pickup-command.d.ts +3 -0
- package/dist/commands/pickup-command.d.ts.map +1 -0
- package/dist/commands/pickup-command.js +161 -0
- package/dist/commands/prompt-command.d.ts +2 -1
- package/dist/commands/prompt-command.d.ts.map +1 -0
- package/dist/commands/prompt-command.js +178 -9
- package/dist/commands/remove-directory-command.d.ts +3 -0
- package/dist/commands/remove-directory-command.d.ts.map +1 -0
- package/dist/commands/remove-directory-command.js +87 -0
- package/dist/commands/reset-command.d.ts +2 -1
- package/dist/commands/reset-command.d.ts.map +1 -0
- package/dist/commands/reset-command.js +14 -3
- package/dist/commands/rules-command.d.ts +1 -0
- package/dist/commands/rules-command.d.ts.map +1 -0
- package/dist/commands/rules-command.js +70 -3
- package/dist/commands/save-command.d.ts +1 -0
- package/dist/commands/save-command.d.ts.map +1 -0
- package/dist/commands/save-command.js +13 -1
- package/dist/commands/shell-command.d.ts +3 -0
- package/dist/commands/shell-command.d.ts.map +1 -0
- package/dist/commands/shell-command.js +128 -0
- package/dist/commands/types.d.ts +16 -8
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/usage-command.d.ts +1 -0
- package/dist/commands/usage-command.d.ts.map +1 -0
- package/dist/commands/usage-command.js +24 -3
- package/dist/config.d.ts +21 -34
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +55 -15
- package/dist/dedent.d.ts +1 -0
- package/dist/dedent.d.ts.map +1 -0
- package/dist/execution/index.d.ts +112 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +432 -0
- package/dist/formatting.d.ts +107 -10
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +150 -62
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +150 -38
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +47 -18
- package/dist/mentions.d.ts +6 -1
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +58 -11
- package/dist/messages.d.ts +16 -20
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +89 -72
- package/dist/middleware/audit-message.d.ts +1 -0
- package/dist/middleware/audit-message.d.ts.map +1 -0
- package/dist/middleware/cache.d.ts +3 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/cache.js +53 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/middleware/rate-limit.d.ts +1 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/models/ai-config.d.ts +5 -2
- package/dist/models/ai-config.d.ts.map +1 -0
- package/dist/models/ai-config.js +12 -2
- package/dist/models/anthropic-provider.d.ts +1 -0
- package/dist/models/anthropic-provider.d.ts.map +1 -0
- package/dist/models/anthropic-provider.js +3 -60
- package/dist/models/deepseek-provider.d.ts +1 -0
- package/dist/models/deepseek-provider.d.ts.map +1 -0
- package/dist/models/google-provider.d.ts +1 -0
- package/dist/models/google-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.d.ts +20 -0
- package/dist/models/groq-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.js +31 -0
- package/dist/models/manager.d.ts +3 -1
- package/dist/models/manager.d.ts.map +1 -0
- package/dist/models/manager.js +26 -2
- package/dist/models/openai-provider.d.ts +2 -1
- package/dist/models/openai-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.d.ts +25 -23
- package/dist/models/openrouter-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.js +181 -122
- package/dist/models/providers.d.ts +4 -5
- package/dist/models/providers.d.ts.map +1 -0
- package/dist/models/providers.js +7 -3
- package/dist/models/xai-provider.d.ts +1 -0
- package/dist/models/xai-provider.d.ts.map +1 -0
- package/dist/parsing.d.ts +2 -1
- package/dist/parsing.d.ts.map +1 -0
- package/dist/prompts/manager.d.ts +14 -2
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +65 -12
- package/dist/repl/display-tool-messages.d.ts +4 -0
- package/dist/repl/display-tool-messages.d.ts.map +1 -0
- package/dist/repl/display-tool-messages.js +58 -0
- package/dist/repl/display-tool-use.d.ts +14 -0
- package/dist/repl/display-tool-use.d.ts.map +1 -0
- package/dist/repl/display-tool-use.js +63 -0
- package/dist/repl/get-prompt-header.d.ts +8 -0
- package/dist/repl/get-prompt-header.d.ts.map +1 -0
- package/dist/repl/get-prompt-header.js +9 -0
- package/dist/repl/project-status-line.d.ts +2 -0
- package/dist/repl/project-status-line.d.ts.map +1 -0
- package/dist/repl/project-status-line.js +31 -0
- package/dist/repl/prompt.d.ts +21 -0
- package/dist/repl/prompt.d.ts.map +1 -0
- package/dist/{repl-prompt.js → repl/prompt.js} +119 -22
- package/dist/repl/tool-call-repair.d.ts +4 -0
- package/dist/repl/tool-call-repair.d.ts.map +1 -0
- package/dist/repl/tool-call-repair.js +54 -0
- package/dist/repl-new.d.ts +53 -0
- package/dist/repl-new.d.ts.map +1 -0
- package/dist/repl-new.js +374 -0
- package/dist/repl.d.ts +9 -7
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +142 -378
- package/dist/terminal/ansi-styles.d.ts +77 -0
- package/dist/terminal/ansi-styles.d.ts.map +1 -0
- package/dist/terminal/ansi-styles.js +215 -0
- package/dist/terminal/checkbox-prompt.d.ts +36 -0
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -0
- package/dist/terminal/checkbox-prompt.js +368 -0
- package/dist/terminal/default-theme.d.ts +6 -0
- package/dist/terminal/default-theme.d.ts.map +1 -0
- package/dist/terminal/default-theme.js +182 -0
- package/dist/terminal/east-asian-width.d.ts +8 -0
- package/dist/terminal/east-asian-width.d.ts.map +1 -0
- package/dist/terminal/east-asian-width.js +409 -0
- package/dist/terminal/editor-prompt.d.ts +10 -0
- package/dist/terminal/editor-prompt.d.ts.map +1 -0
- package/dist/terminal/editor-prompt.js +61 -0
- package/dist/terminal/errors.d.ts +19 -0
- package/dist/terminal/errors.d.ts.map +1 -0
- package/dist/terminal/errors.js +37 -0
- package/dist/terminal/formatting.d.ts +1 -11
- package/dist/terminal/formatting.d.ts.map +1 -0
- package/dist/terminal/formatting.js +4 -20
- package/dist/terminal/highlight/index.d.ts +53 -0
- package/dist/terminal/highlight/index.d.ts.map +1 -0
- package/dist/terminal/highlight/index.js +90 -0
- package/dist/terminal/highlight/theme.d.ts +233 -0
- package/dist/terminal/highlight/theme.d.ts.map +1 -0
- package/dist/terminal/highlight/theme.js +83 -0
- package/dist/terminal/index.d.ts +23 -9
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +136 -126
- package/dist/terminal/input-prompt.d.ts +17 -0
- package/dist/terminal/input-prompt.d.ts.map +1 -0
- package/dist/terminal/input-prompt.js +181 -0
- package/dist/terminal/markdown-utils.d.ts +1 -0
- package/dist/terminal/markdown-utils.d.ts.map +1 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.d.ts.map +1 -0
- package/dist/terminal/markdown.js +20 -12
- package/dist/terminal/search-prompt.d.ts +20 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -0
- package/dist/terminal/search-prompt.js +280 -0
- package/dist/terminal/select-prompt.d.ts +26 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -0
- package/dist/terminal/select-prompt.js +306 -0
- package/dist/terminal/string-width.d.ts +7 -0
- package/dist/terminal/string-width.d.ts.map +1 -0
- package/dist/terminal/string-width.js +61 -0
- package/dist/terminal/strip-ansi.d.ts +2 -0
- package/dist/terminal/strip-ansi.d.ts.map +1 -0
- package/dist/terminal/strip-ansi.js +20 -0
- package/dist/terminal/style.d.ts +191 -0
- package/dist/terminal/style.d.ts.map +1 -0
- package/dist/terminal/style.js +259 -0
- package/dist/terminal/supports-color.d.ts +1 -0
- package/dist/terminal/supports-color.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.d.ts +1 -3
- package/dist/terminal/supports-hyperlinks.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.js +1 -1
- package/dist/terminal/types.d.ts +1 -37
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.d.ts +8 -0
- package/dist/terminal/wrap-ansi.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.js +190 -0
- package/dist/{token-utils.d.ts → tokens/counter.d.ts} +1 -0
- package/dist/tokens/counter.d.ts.map +1 -0
- package/dist/{token-utils.js → tokens/counter.js} +1 -1
- package/dist/tokens/threshold.d.ts +35 -0
- package/dist/tokens/threshold.d.ts.map +1 -0
- package/dist/tokens/threshold.js +85 -0
- package/dist/{token-tracker.d.ts → tokens/tracker.d.ts} +1 -0
- package/dist/tokens/tracker.d.ts.map +1 -0
- package/dist/tools/advanced-edit-file.d.ts +69 -0
- package/dist/tools/advanced-edit-file.d.ts.map +1 -0
- package/dist/tools/advanced-edit-file.js +281 -0
- package/dist/tools/agent.d.ts +19 -7
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +70 -54
- package/dist/tools/bash-utils.d.ts +7 -0
- package/dist/tools/bash-utils.d.ts.map +1 -0
- package/dist/tools/bash-utils.js +220 -0
- package/dist/tools/bash.d.ts +25 -14
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +87 -251
- package/dist/tools/code-interpreter.d.ts +22 -10
- package/dist/tools/code-interpreter.d.ts.map +1 -0
- package/dist/tools/code-interpreter.js +146 -210
- package/dist/tools/delete-file.d.ts +18 -9
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +55 -85
- package/dist/tools/directory-tree.d.ts +26 -6
- package/dist/tools/directory-tree.d.ts.map +1 -0
- package/dist/tools/directory-tree.js +109 -28
- package/dist/tools/dynamic-tool-loader.d.ts +22 -0
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-loader.js +272 -0
- package/dist/tools/dynamic-tool-parser.d.ts +21 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-parser.js +22 -0
- package/dist/tools/edit-file.d.ts +41 -13
- package/dist/tools/edit-file.d.ts.map +1 -0
- package/dist/tools/edit-file.js +173 -96
- package/dist/tools/filesystem-utils.d.ts +7 -21
- package/dist/tools/filesystem-utils.d.ts.map +1 -0
- package/dist/tools/filesystem-utils.js +111 -149
- package/dist/tools/git-utils.d.ts +1 -0
- package/dist/tools/git-utils.d.ts.map +1 -0
- package/dist/tools/glob.d.ts +36 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +143 -0
- package/dist/tools/grep.d.ts +76 -13
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +420 -135
- package/dist/tools/index.d.ts +207 -133
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +245 -127
- package/dist/tools/llm-edit-fixer.d.ts +25 -0
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -0
- package/dist/tools/llm-edit-fixer.js +150 -0
- package/dist/tools/move-file.d.ts +20 -7
- package/dist/tools/move-file.d.ts.map +1 -0
- package/dist/tools/move-file.js +43 -29
- package/dist/tools/read-file.d.ts +49 -10
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +79 -67
- package/dist/tools/read-multiple-files.d.ts +19 -7
- package/dist/tools/read-multiple-files.d.ts.map +1 -0
- package/dist/tools/read-multiple-files.js +117 -33
- package/dist/tools/save-file.d.ts +46 -11
- package/dist/tools/save-file.d.ts.map +1 -0
- package/dist/tools/save-file.js +63 -78
- package/dist/tools/think.d.ts +16 -7
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +34 -22
- package/dist/tools/types.d.ts +18 -11
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +9 -0
- package/dist/tools/utils.d.ts +14 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +16 -0
- package/dist/tools/web-fetch.d.ts +15 -6
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +40 -39
- package/dist/tools/web-search.d.ts +17 -7
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +86 -33
- package/dist/tui/autocomplete.d.ts +44 -0
- package/dist/tui/autocomplete.d.ts.map +1 -0
- package/dist/tui/autocomplete.js +466 -0
- package/dist/tui/components/assistant-message.d.ts +18 -0
- package/dist/tui/components/assistant-message.d.ts.map +1 -0
- package/dist/tui/components/assistant-message.js +29 -0
- package/dist/tui/components/editor.d.ts +51 -0
- package/dist/tui/components/editor.d.ts.map +1 -0
- package/dist/tui/components/editor.js +758 -0
- package/dist/tui/components/footer.d.ts +24 -0
- package/dist/tui/components/footer.d.ts.map +1 -0
- package/dist/tui/components/footer.js +197 -0
- package/dist/tui/components/input.d.ts +14 -0
- package/dist/tui/components/input.d.ts.map +1 -0
- package/dist/tui/components/input.js +122 -0
- package/dist/tui/components/loader.d.ts +19 -0
- package/dist/tui/components/loader.d.ts.map +1 -0
- package/dist/tui/components/loader.js +45 -0
- package/dist/tui/components/markdown.d.ts +103 -0
- package/dist/tui/components/markdown.d.ts.map +1 -0
- package/dist/tui/components/markdown.js +533 -0
- package/dist/tui/components/modal.d.ts +40 -0
- package/dist/tui/components/modal.d.ts.map +1 -0
- package/dist/tui/components/modal.js +292 -0
- package/dist/tui/components/prompt-status.d.ts +16 -0
- package/dist/tui/components/prompt-status.d.ts.map +1 -0
- package/dist/tui/components/prompt-status.js +21 -0
- package/dist/tui/components/select-list.d.ts +22 -0
- package/dist/tui/components/select-list.d.ts.map +1 -0
- package/dist/tui/components/select-list.js +143 -0
- package/dist/tui/components/spacer.d.ts +16 -0
- package/dist/tui/components/spacer.d.ts.map +1 -0
- package/dist/tui/components/spacer.js +27 -0
- package/dist/tui/components/text.d.ts +26 -0
- package/dist/tui/components/text.d.ts.map +1 -0
- package/dist/tui/components/text.js +143 -0
- package/dist/tui/components/thinking-block.d.ts +14 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -0
- package/dist/tui/components/thinking-block.js +30 -0
- package/dist/tui/components/tool-execution.d.ts +17 -0
- package/dist/tui/components/tool-execution.d.ts.map +1 -0
- package/dist/tui/components/tool-execution.js +153 -0
- package/dist/tui/components/user-message.d.ts +9 -0
- package/dist/tui/components/user-message.d.ts.map +1 -0
- package/dist/tui/components/user-message.js +21 -0
- package/dist/tui/components/welcome.d.ts +6 -0
- package/dist/tui/components/welcome.d.ts.map +1 -0
- package/dist/tui/components/welcome.js +30 -0
- package/dist/tui/index.d.ts +14 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +18 -0
- package/dist/tui/terminal.d.ts +37 -0
- package/dist/tui/terminal.d.ts.map +1 -0
- package/dist/tui/terminal.js +104 -0
- package/dist/tui/tui.d.ts +67 -0
- package/dist/tui/tui.d.ts.map +1 -0
- package/dist/tui/tui.js +184 -0
- package/dist/tui/utils.d.ts +19 -0
- package/dist/tui/utils.d.ts.map +1 -0
- package/dist/tui/utils.js +31 -0
- package/dist/utils/filesystem.d.ts +23 -0
- package/dist/utils/filesystem.d.ts.map +1 -0
- package/dist/utils/filesystem.js +140 -0
- package/dist/utils/filetype-detection.d.ts +3 -0
- package/dist/utils/filetype-detection.d.ts.map +1 -0
- package/dist/utils/filetype-detection.js +112 -0
- package/dist/utils/generators.d.ts +3 -0
- package/dist/utils/generators.d.ts.map +1 -0
- package/dist/utils/generators.js +25 -0
- package/dist/utils/glob.d.ts +52 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/glob.js +376 -0
- package/dist/utils/ignore.d.ts +104 -0
- package/dist/utils/ignore.d.ts.map +1 -0
- package/dist/utils/ignore.js +649 -0
- package/dist/utils/iterables.d.ts +2 -0
- package/dist/utils/iterables.d.ts.map +1 -0
- package/dist/utils/iterables.js +6 -0
- package/dist/utils/process.d.ts +3 -2
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +17 -2
- package/dist/utils/zod-utils.d.ts +4 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils/zod-utils.js +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +34 -32
- package/dist/conversation-analyzer.d.ts +0 -10
- package/dist/conversation-analyzer.js +0 -88
- package/dist/repl-prompt.d.ts +0 -14
- package/dist/tools/command-validation.d.ts +0 -11
- package/dist/tools/command-validation.js +0 -45
- /package/dist/{token-tracker.js → tokens/tracker.js} +0 -0
package/dist/prompts.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
1
2
|
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { platform } from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { config } from "./config.js";
|
|
5
6
|
import { dedent } from "./dedent.js";
|
|
7
|
+
import { getShell } from "./terminal/index.js";
|
|
6
8
|
import { AgentTool } from "./tools/agent.js";
|
|
7
9
|
import { BashTool } from "./tools/bash.js";
|
|
8
10
|
import { CodeInterpreterTool } from "./tools/code-interpreter.js";
|
|
@@ -33,7 +35,7 @@ async function instructions() {
|
|
|
33
35
|
}
|
|
34
36
|
return `## Core Principles
|
|
35
37
|
|
|
36
|
-
- **CLI-Optimized**: Be concise and direct - responses appear in a terminal.
|
|
38
|
+
- **CLI-Optimized**: Be concise and direct - responses appear in a terminal. Be extremely concise. Sacrifice grammar for the sake of concision.
|
|
37
39
|
- **Progressive Problem Solving**: Work through problems methodically until resolution.
|
|
38
40
|
- **User Authority**: NEVER commit changes or add dependencies without explicit user approval.
|
|
39
41
|
- **Security-First**: Prioritize secure coding practices in all suggestions.
|
|
@@ -66,12 +68,13 @@ function toolUsage() {
|
|
|
66
68
|
return `## Tool Usage Guidelines
|
|
67
69
|
|
|
68
70
|
### Information Gathering
|
|
69
|
-
-
|
|
71
|
+
- Prefer targeted queries: use \`${GrepTool.name}\` for code pattern searches and \`${ReadMultipleFilesTool.name}\` to fetch files. Avoid full directory dumps for large repositories.
|
|
70
72
|
- Use \`${ReadFileTool.name}\` or \`${ReadMultipleFilesTool.name}\` for file contents if filenames are provided in the prompt
|
|
71
73
|
- Use \`${GrepTool.name}\` for code pattern searches
|
|
72
74
|
- Use \`${WebFetchTool.name}\` for text-based URLs provided in the prompt
|
|
73
75
|
- Use \`${WebSearchTool.name}\` for external research (e.g., libraries, errors)
|
|
74
|
-
- Use \`${AgentTool.name}\` for iterative keyword/file searches. Use this if you need to explore the project
|
|
76
|
+
- Use \`${AgentTool.name}\` for iterative keyword/file searches. Use this if you need to explore the project to find what you are looking for.
|
|
77
|
+
- Use \`${DirectoryTreeTool.name}\` if you need a high-level overview of the project.
|
|
75
78
|
- If file contents or URLs are provided in the prompt, use them directly without re-fetching
|
|
76
79
|
- Always verify file contents before suggesting changes unless provided in the prompt
|
|
77
80
|
|
|
@@ -85,18 +88,38 @@ function toolUsage() {
|
|
|
85
88
|
- Outline multi-step tasks before execution
|
|
86
89
|
|
|
87
90
|
### Bash Commands (\`${BashTool.name}\`)
|
|
88
|
-
-
|
|
89
|
-
- Run
|
|
90
|
-
-
|
|
91
|
-
|
|
91
|
+
- Execute commands with a sandboxed executor that supports pipes (|), conditional chaining (&&, ||, ;), and redirection (> >> < 2> 2>>).
|
|
92
|
+
- Run single commands or compose multi-step flows using shell operators.
|
|
93
|
+
- For extremely large gh/git messages:
|
|
94
|
+
1. Create temp file with ${SaveFileTool.name} in the project's .tmp directory
|
|
95
|
+
2. Use git commit --file path/to/temp/file or gh pr create --title "Title of PR" --body-file path/to/temp/file
|
|
96
|
+
- Note: The .tmp directory in the current working directory is deleted each time the agent shuts down.
|
|
92
97
|
- Commands execute only within the project directory; always use absolute paths.
|
|
93
98
|
- Avoid interactive commands; prefer non-interactive flags (e.g., npm init -y).
|
|
94
99
|
|
|
100
|
+
#### Additional Installed Tools
|
|
101
|
+
|
|
102
|
+
${getInstalledTools()}
|
|
103
|
+
|
|
95
104
|
### Code Interpreter (\`${CodeInterpreterTool.name}\`)
|
|
96
105
|
- Executes JavaScript code in a separate Node.js process using Node's Permission Model
|
|
97
106
|
- By default, the child process has no permissions except read/write within the current working directory
|
|
98
107
|
- Returns stdout, stderr, and exitCode
|
|
99
|
-
- Use console.log/console.error to produce
|
|
108
|
+
- Use console.log/console.error to produce output
|
|
109
|
+
|
|
110
|
+
### Git Workflow
|
|
111
|
+
- Always stage changes before attempting to commit them
|
|
112
|
+
- Never amend git commits without approval from the user
|
|
113
|
+
- Never use \`git add -A\` when preparing for multiple, distinct commits; instead, selectively add files or hunks relevant to each commit
|
|
114
|
+
- Always use \`git checkout -b <branch-name>\` with a branch name that accurately reflects the *type* of changes being made
|
|
115
|
+
- Never stage changes for files that are specified in \`.gitignore\`
|
|
116
|
+
- Always stage changes after running a formatter that modifies files, before attempting to commit
|
|
117
|
+
|
|
118
|
+
### Efficiency Guidelines
|
|
119
|
+
- Always use the most efficient workflow to complete tasks
|
|
120
|
+
- Never re-read file content that has already been provided in the current turn or is directly accessible via a tool; instead, reuse the provided content or reference the file path directly
|
|
121
|
+
- Always use direct file paths or established methods to pass content to tools that accept file input, rather than re-creating content in command strings
|
|
122
|
+
- Always run a build after making code changes to verify correctness`;
|
|
100
123
|
}
|
|
101
124
|
function escalationProcedures() {
|
|
102
125
|
return `## Escalation
|
|
@@ -122,17 +145,19 @@ async function environmentInfo() {
|
|
|
122
145
|
const gitDirectory = await inGitDirectory();
|
|
123
146
|
let gitSection = `- **Is directory a git repo**: ${gitDirectory ? "Yes" : "No"}`;
|
|
124
147
|
if (gitDirectory) {
|
|
125
|
-
gitSection += `\n- **
|
|
148
|
+
gitSection += `\n- **Current git branch**: ${await getCurrentBranch()}`;
|
|
126
149
|
}
|
|
127
150
|
return `## Environment
|
|
128
151
|
|
|
129
152
|
- **Current working directory**: ${process.cwd()}. [Use this value directly instead of calling the \`${BashTool.name}(pwd)\` tool unless you have a specific reason to verify it].
|
|
130
153
|
${gitSection}
|
|
131
154
|
- **Platform**: ${platform()}
|
|
132
|
-
- **
|
|
155
|
+
- **Shell**: ${getShell()}
|
|
156
|
+
- **Today's date**: ${(new Date()).toISOString()}
|
|
157
|
+
- Note: The .tmp directory in the current working directory is deleted each time the agent shuts down.`;
|
|
133
158
|
}
|
|
134
159
|
export async function systemPrompt(options) {
|
|
135
|
-
const { supportsToolCalling = true } = options ?? {};
|
|
160
|
+
const { supportsToolCalling = true, includeRules = true } = options ?? {};
|
|
136
161
|
const prompt = dedent `
|
|
137
162
|
${intro()}
|
|
138
163
|
|
|
@@ -142,7 +167,7 @@ ${supportsToolCalling ? toolUsage() : ""}
|
|
|
142
167
|
|
|
143
168
|
${escalationProcedures()}
|
|
144
169
|
|
|
145
|
-
${await getRules()}
|
|
170
|
+
${includeRules ? await getRules() : ""}
|
|
146
171
|
|
|
147
172
|
${await environmentInfo()}
|
|
148
173
|
`;
|
|
@@ -160,3 +185,31 @@ ${await environmentInfo()}
|
|
|
160
185
|
`;
|
|
161
186
|
return prompt;
|
|
162
187
|
}
|
|
188
|
+
function getInstalledTools() {
|
|
189
|
+
// Check for required bash tools
|
|
190
|
+
const tools = [
|
|
191
|
+
{ name: "git", command: "git --version" },
|
|
192
|
+
{ name: "gh", command: "gh --version" },
|
|
193
|
+
{ name: "rg", command: "rg --version" },
|
|
194
|
+
{ name: "fd", command: "fd --version" },
|
|
195
|
+
{ name: "ast-grep", command: "ast-grep --version" },
|
|
196
|
+
{ name: "jq", command: "jq --version" },
|
|
197
|
+
{ name: "yq", command: "yq --version" },
|
|
198
|
+
];
|
|
199
|
+
const toolStatus = tools
|
|
200
|
+
.map((tool) => {
|
|
201
|
+
let status = false;
|
|
202
|
+
try {
|
|
203
|
+
execSync(tool.command, { stdio: "ignore", timeout: 5000 });
|
|
204
|
+
status = true;
|
|
205
|
+
}
|
|
206
|
+
catch (_error) {
|
|
207
|
+
// Ignore error, tool is not installed
|
|
208
|
+
}
|
|
209
|
+
return [tool.name, status];
|
|
210
|
+
})
|
|
211
|
+
.filter((tool) => tool[1])
|
|
212
|
+
.map((tool) => tool[0])
|
|
213
|
+
.join("\n");
|
|
214
|
+
return toolStatus;
|
|
215
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-tool-messages.d.ts","sourceRoot":"","sources":["../../source/repl/display-tool-messages.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,QAmBvE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { capitalize } from "../formatting.js";
|
|
2
|
+
import { logger } from "../logger.js";
|
|
3
|
+
import style from "../terminal/style.js";
|
|
4
|
+
export function displayToolMessages(message, terminal) {
|
|
5
|
+
switch (message.event) {
|
|
6
|
+
case "tool-completion":
|
|
7
|
+
handleToolCompletionMessage(message, terminal);
|
|
8
|
+
break;
|
|
9
|
+
case "tool-error":
|
|
10
|
+
handleToolErrorMessage(message, terminal);
|
|
11
|
+
break;
|
|
12
|
+
case "tool-init":
|
|
13
|
+
handleToolInitMessage(message, terminal);
|
|
14
|
+
break;
|
|
15
|
+
default:
|
|
16
|
+
logger.debug(`Unhandled tool message event: ${message.event}`);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
terminal.lineBreak();
|
|
20
|
+
}
|
|
21
|
+
function handleToolInitMessage(message, terminal) {
|
|
22
|
+
const indicator = style.blue.bold("●");
|
|
23
|
+
const data = String(message.data);
|
|
24
|
+
const newlineIndex = data.indexOf("\n");
|
|
25
|
+
terminal.write(`${indicator} ${style.bold(capitalize(message.name))} `);
|
|
26
|
+
if (newlineIndex === -1) {
|
|
27
|
+
terminal.writeln(style.bold(data));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const firstLine = data.slice(0, newlineIndex);
|
|
31
|
+
const remainingLines = data.slice(newlineIndex + 1);
|
|
32
|
+
terminal.writeln(style.bold(firstLine));
|
|
33
|
+
if (remainingLines.trim()) {
|
|
34
|
+
terminal.display(remainingLines);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function handleToolCompletionMessage(message, terminal) {
|
|
39
|
+
const indicator = style.green.bold("●");
|
|
40
|
+
const data = String(message.data);
|
|
41
|
+
const newlineIndex = data.indexOf("\n");
|
|
42
|
+
terminal.write(`${indicator} ${style.bold(capitalize(message.name))} `);
|
|
43
|
+
if (newlineIndex === -1) {
|
|
44
|
+
terminal.writeln(style.bold(data));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const firstLine = data.slice(0, newlineIndex);
|
|
48
|
+
const remainingLines = data.slice(newlineIndex + 1);
|
|
49
|
+
terminal.writeln(style.bold(firstLine));
|
|
50
|
+
if (remainingLines.trim()) {
|
|
51
|
+
terminal.display(remainingLines);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function handleToolErrorMessage(message, terminal) {
|
|
56
|
+
const indicator = style.red.bold("●");
|
|
57
|
+
terminal.writeln(`${indicator} ${style.bold(capitalize(message.name))} ${message.data}`);
|
|
58
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Terminal } from "../terminal/index.ts";
|
|
2
|
+
interface MinimalStep {
|
|
3
|
+
toolResults: Array<{
|
|
4
|
+
toolName: string;
|
|
5
|
+
}>;
|
|
6
|
+
toolCalls: Array<{
|
|
7
|
+
toolName: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare function displayToolUse(result: {
|
|
11
|
+
steps: MinimalStep[];
|
|
12
|
+
}, terminal: Terminal): void;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=display-tool-use.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-tool-use.d.ts","sourceRoot":"","sources":["../../source/repl/display-tool-use.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIrD,UAAU,WAAW;IACnB,WAAW,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzC,SAAS,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxC;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE;IAAE,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,EAChC,QAAQ,EAAE,QAAQ,QA0EnB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import style from "../terminal/style.js";
|
|
2
|
+
export function displayToolUse(result, terminal) {
|
|
3
|
+
const toolsCalled = [];
|
|
4
|
+
const toolColors = new Map();
|
|
5
|
+
const styleColors = [
|
|
6
|
+
"red",
|
|
7
|
+
"green",
|
|
8
|
+
"yellow",
|
|
9
|
+
"blue",
|
|
10
|
+
"magenta",
|
|
11
|
+
"cyan",
|
|
12
|
+
"white",
|
|
13
|
+
"gray",
|
|
14
|
+
"redBright",
|
|
15
|
+
"greenBright",
|
|
16
|
+
"yellowBright",
|
|
17
|
+
"blueBright",
|
|
18
|
+
"magentaBright",
|
|
19
|
+
"cyanBright",
|
|
20
|
+
"whiteBright",
|
|
21
|
+
"blackBright",
|
|
22
|
+
];
|
|
23
|
+
terminal.writeln(style.dim(`Steps: ${result.steps.length}`));
|
|
24
|
+
for (const step of result.steps) {
|
|
25
|
+
let currentToolCalls = [];
|
|
26
|
+
if (step.toolResults.length > 0) {
|
|
27
|
+
currentToolCalls = step.toolResults;
|
|
28
|
+
}
|
|
29
|
+
else if (step.toolCalls.length > 0) {
|
|
30
|
+
currentToolCalls = step.toolCalls;
|
|
31
|
+
}
|
|
32
|
+
for (const toolCallOrResult of currentToolCalls) {
|
|
33
|
+
const toolName = toolCallOrResult.toolName;
|
|
34
|
+
if (!toolColors.has(toolName)) {
|
|
35
|
+
const availableColors = styleColors.filter((color) => !Array.from(toolColors.values()).some((c) => c === style[color]));
|
|
36
|
+
const color = availableColors.length > 0
|
|
37
|
+
? (availableColors[Math.floor(Math.random() * availableColors.length)] ?? "white")
|
|
38
|
+
: "white";
|
|
39
|
+
toolColors.set(toolName, style[color]);
|
|
40
|
+
}
|
|
41
|
+
toolsCalled.push(toolName);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (toolsCalled.length > 0) {
|
|
45
|
+
terminal.lineBreak();
|
|
46
|
+
terminal.writeln(style.dim("Tools:"));
|
|
47
|
+
for (const toolCalled of toolsCalled) {
|
|
48
|
+
const colorFn = toolColors.get(toolCalled) ?? style.white;
|
|
49
|
+
terminal.write(`${colorFn("██")} `);
|
|
50
|
+
}
|
|
51
|
+
terminal.lineBreak();
|
|
52
|
+
const uniqueTools = new Set(toolsCalled);
|
|
53
|
+
for (const [index, toolCalled] of Array.from(uniqueTools).entries()) {
|
|
54
|
+
const colorFn = toolColors.get(toolCalled) ?? style.white;
|
|
55
|
+
terminal.write(colorFn(toolCalled));
|
|
56
|
+
if (index < new Set(toolsCalled).size - 1) {
|
|
57
|
+
terminal.write(" - ");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
terminal.lineBreak();
|
|
61
|
+
terminal.lineBreak();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Terminal } from "../terminal/index.ts";
|
|
2
|
+
export declare function getPromptHeader(args: {
|
|
3
|
+
terminal: Terminal;
|
|
4
|
+
modelId: string;
|
|
5
|
+
contextWindow: number;
|
|
6
|
+
currentContextWindow: number;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=get-prompt-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-prompt-header.d.ts","sourceRoot":"","sources":["../../source/repl/get-prompt-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIrD,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import style from "../terminal/style.js";
|
|
2
|
+
import { getProjectStatusLine } from "./project-status-line.js";
|
|
3
|
+
export async function getPromptHeader(args) {
|
|
4
|
+
const { terminal, modelId, contextWindow, currentContextWindow } = args;
|
|
5
|
+
terminal.hr();
|
|
6
|
+
terminal.writeln(await getProjectStatusLine());
|
|
7
|
+
terminal.writeln(style.dim(modelId));
|
|
8
|
+
terminal.displayProgressBar(currentContextWindow, contextWindow);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-status-line.d.ts","sourceRoot":"","sources":["../../source/repl/project-status-line.ts"],"names":[],"mappings":"AASA,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CA2B5D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import style from "../terminal/style.js";
|
|
2
|
+
import { getCurrentBranch, getDiffStat, getGitStatus, hasUncommittedChanges, inGitDirectory, } from "../tools/git-utils.js";
|
|
3
|
+
export async function getProjectStatusLine() {
|
|
4
|
+
const currentDir = process.cwd().split("/").pop() || process.cwd();
|
|
5
|
+
const branch = await getCurrentBranch();
|
|
6
|
+
let gitStatus = "";
|
|
7
|
+
if (branch) {
|
|
8
|
+
const hasChanges = await hasUncommittedChanges();
|
|
9
|
+
const asterisk = hasChanges ? "*" : "";
|
|
10
|
+
gitStatus = ` ${style.gray(branch + asterisk)}`;
|
|
11
|
+
}
|
|
12
|
+
if (await inGitDirectory()) {
|
|
13
|
+
const stats = await getDiffStat();
|
|
14
|
+
const fileChanges = await getGitStatus();
|
|
15
|
+
let fileStatus = "";
|
|
16
|
+
if (fileChanges.added)
|
|
17
|
+
fileStatus += ` +${fileChanges.added}`;
|
|
18
|
+
if (fileChanges.modified)
|
|
19
|
+
fileStatus += ` ~${fileChanges.modified}`;
|
|
20
|
+
if (fileChanges.deleted)
|
|
21
|
+
fileStatus += ` -${fileChanges.deleted}`;
|
|
22
|
+
if (fileChanges.untracked)
|
|
23
|
+
fileStatus += ` ?${fileChanges.untracked}`;
|
|
24
|
+
gitStatus +=
|
|
25
|
+
" " +
|
|
26
|
+
`${style.dim("[")}${style.yellow(fileStatus.trim())} ` +
|
|
27
|
+
`${style.green(`+${stats.insertions}`)} ` +
|
|
28
|
+
`${style.red(`-${stats.deletions}`)}${style.dim("]")}`;
|
|
29
|
+
}
|
|
30
|
+
return `${style.blue(currentDir)}${gitStatus}`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CommandManager } from "../commands/manager.ts";
|
|
2
|
+
import type { WorkspaceContext } from "../index.ts";
|
|
3
|
+
export declare class ReplPrompt {
|
|
4
|
+
private keypressListener?;
|
|
5
|
+
private rl;
|
|
6
|
+
private history;
|
|
7
|
+
private maxHistory;
|
|
8
|
+
private pasteCounter;
|
|
9
|
+
private pasteStore;
|
|
10
|
+
constructor({ commands, history, workspace, }: {
|
|
11
|
+
commands: CommandManager;
|
|
12
|
+
history: string[];
|
|
13
|
+
workspace: WorkspaceContext;
|
|
14
|
+
});
|
|
15
|
+
input(): Promise<string>;
|
|
16
|
+
getPasteStore(): Map<number, string>;
|
|
17
|
+
resetPasteStore(): void;
|
|
18
|
+
close(): void;
|
|
19
|
+
[Symbol.dispose](): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../source/repl/prompt.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAmKpD,qBAAa,UAAU;IAErB,OAAO,CAAC,gBAAgB,CAAC,CAAkC;IAC3D,OAAO,CAAC,EAAE,CAAY;IACtB,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAA6B;gBAEnC,EACV,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE;QACD,QAAQ,EAAE,cAAc,CAAC;QACzB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,SAAS,EAAE,gBAAgB,CAAC;KAC7B;IAwGK,KAAK;IAoBX,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIpC,eAAe,IAAI,IAAI;IAKvB,KAAK;IAQL,CAAC,MAAM,CAAC,OAAO,CAAC;CAGjB"}
|
|
@@ -1,36 +1,82 @@
|
|
|
1
1
|
import { readdir } from "node:fs/promises";
|
|
2
|
-
import { parse, sep } from "node:path";
|
|
2
|
+
import { parse, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { createInterface } from "node:readline/promises";
|
|
4
4
|
import Clipboard from "@crosscopy/clipboard";
|
|
5
5
|
import { asyncTry } from "@travisennis/stdlib/try";
|
|
6
|
-
import { logger } from "
|
|
6
|
+
import { logger } from "../logger.js";
|
|
7
7
|
const whitespaceRegex = /\s+/;
|
|
8
|
-
|
|
8
|
+
// Cache for directory listings to improve performance
|
|
9
|
+
class DirectoryCache {
|
|
10
|
+
cache = new Map();
|
|
11
|
+
ttl = 3000; // 3 seconds
|
|
12
|
+
async get(dir) {
|
|
13
|
+
const cached = this.cache.get(dir);
|
|
14
|
+
if (cached && Date.now() - cached.timestamp < this.ttl) {
|
|
15
|
+
return cached.entries;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
set(dir, entries) {
|
|
20
|
+
this.cache.set(dir, { entries, timestamp: Date.now() });
|
|
21
|
+
}
|
|
22
|
+
clear() {
|
|
23
|
+
this.cache.clear();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const directoryCache = new DirectoryCache();
|
|
27
|
+
// Helper function to get directory entries with caching
|
|
28
|
+
async function getDirectoryEntries(dir) {
|
|
29
|
+
const cached = await directoryCache.get(dir);
|
|
30
|
+
if (cached) {
|
|
31
|
+
return cached;
|
|
32
|
+
}
|
|
33
|
+
const tryAttempt = await asyncTry(readdir(dir, { withFileTypes: true }));
|
|
34
|
+
if (tryAttempt.isFailure) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
const entries = tryAttempt.unwrap();
|
|
38
|
+
directoryCache.set(dir, entries);
|
|
39
|
+
return entries;
|
|
40
|
+
}
|
|
41
|
+
// Helper function to get completions from a specific directory
|
|
42
|
+
async function getCompletionsFromDir(line, dir, workspace) {
|
|
9
43
|
try {
|
|
10
44
|
const words = line.split(" ");
|
|
11
45
|
let last = words.at(-1);
|
|
12
46
|
if (!last) {
|
|
13
|
-
return [
|
|
47
|
+
return [];
|
|
14
48
|
}
|
|
15
49
|
const isAt = last.startsWith("@");
|
|
16
50
|
if (isAt) {
|
|
17
51
|
last = last.slice(1);
|
|
18
52
|
}
|
|
19
|
-
let { dir, base } = parse(last);
|
|
20
|
-
// If
|
|
21
|
-
if (!
|
|
22
|
-
|
|
53
|
+
let { dir: pathDir, base } = parse(last);
|
|
54
|
+
// If pathDir is empty, use current directory
|
|
55
|
+
if (!pathDir) {
|
|
56
|
+
pathDir = ".";
|
|
57
|
+
}
|
|
58
|
+
// Resolve the path relative to the current directory
|
|
59
|
+
const resolvedPath = resolve(dir, pathDir);
|
|
60
|
+
// Check if resolved path is within any allowed directory
|
|
61
|
+
const isWithinAllowed = workspace.allowedDirs.some((allowedDir) => resolvedPath.startsWith(allowedDir));
|
|
62
|
+
if (!isWithinAllowed) {
|
|
63
|
+
return [];
|
|
23
64
|
}
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
65
|
+
let dirEntries = await getDirectoryEntries(resolvedPath);
|
|
66
|
+
// If we couldn't read the directory, try current directory
|
|
67
|
+
if (dirEntries.length === 0 && pathDir !== ".") {
|
|
68
|
+
dirEntries = await getDirectoryEntries(dir);
|
|
69
|
+
pathDir = ".";
|
|
27
70
|
}
|
|
28
|
-
|
|
29
|
-
// for an exact match that is a directory, read the contents of the directory
|
|
71
|
+
// For an exact match that is a directory, read the contents of the directory
|
|
30
72
|
if (dirEntries.find((entry) => entry.name === base && entry.isDirectory())) {
|
|
31
|
-
|
|
32
|
-
|
|
73
|
+
const newPath = pathDir === "/" || pathDir === sep
|
|
74
|
+
? `${pathDir}${base}`
|
|
75
|
+
: `${pathDir}/${base}`;
|
|
76
|
+
const newResolvedPath = resolve(dir, newPath);
|
|
77
|
+
dirEntries = await getDirectoryEntries(newResolvedPath);
|
|
33
78
|
base = "";
|
|
79
|
+
pathDir = newPath;
|
|
34
80
|
}
|
|
35
81
|
else {
|
|
36
82
|
dirEntries = dirEntries.filter((entry) => entry.name.startsWith(base));
|
|
@@ -38,10 +84,41 @@ async function fileSystemCompleter(line) {
|
|
|
38
84
|
const hits = dirEntries
|
|
39
85
|
.filter((entry) => entry.isFile() || entry.isDirectory())
|
|
40
86
|
.map((entry) => {
|
|
41
|
-
const prefix =
|
|
42
|
-
|
|
87
|
+
const prefix = pathDir === "."
|
|
88
|
+
? ""
|
|
89
|
+
: pathDir === sep || pathDir === "/"
|
|
90
|
+
? ""
|
|
91
|
+
: `${pathDir}/`;
|
|
92
|
+
const fullPath = `${prefix}${entry.name}${entry.isDirectory() && !entry.name.endsWith("/") ? "/" : ""}`;
|
|
93
|
+
// Convert to relative path from primary directory for display
|
|
94
|
+
const absolutePath = resolve(dir, fullPath);
|
|
95
|
+
const relativePath = relative(workspace.primaryDir, absolutePath);
|
|
96
|
+
return `${isAt ? "@" : ""}${relativePath.startsWith("..") ? relativePath : `./${relativePath}`}`;
|
|
43
97
|
});
|
|
44
|
-
return
|
|
98
|
+
return hits;
|
|
99
|
+
}
|
|
100
|
+
catch (_error) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function fileSystemCompleter(line, workspace) {
|
|
105
|
+
try {
|
|
106
|
+
const words = line.split(" ");
|
|
107
|
+
let last = words.at(-1);
|
|
108
|
+
if (!last) {
|
|
109
|
+
return [[], line];
|
|
110
|
+
}
|
|
111
|
+
const isAt = last.startsWith("@");
|
|
112
|
+
if (isAt) {
|
|
113
|
+
last = last.slice(1);
|
|
114
|
+
}
|
|
115
|
+
// Search all directories in parallel
|
|
116
|
+
const completionPromises = workspace.allowedDirs.map((dir) => getCompletionsFromDir(line, dir, workspace));
|
|
117
|
+
const allResults = await Promise.all(completionPromises);
|
|
118
|
+
const flattenedResults = allResults.flat();
|
|
119
|
+
// Remove duplicates while preserving order
|
|
120
|
+
const uniqueResults = [...new Set(flattenedResults)];
|
|
121
|
+
return [uniqueResults, `${isAt ? "@" : ""}${last}`];
|
|
45
122
|
}
|
|
46
123
|
catch (_error) {
|
|
47
124
|
logger.error(_error);
|
|
@@ -54,7 +131,9 @@ export class ReplPrompt {
|
|
|
54
131
|
rl;
|
|
55
132
|
history;
|
|
56
133
|
maxHistory = 25;
|
|
57
|
-
|
|
134
|
+
pasteCounter = 0;
|
|
135
|
+
pasteStore = new Map();
|
|
136
|
+
constructor({ commands, history, workspace, }) {
|
|
58
137
|
this.history = history;
|
|
59
138
|
this.rl = createInterface({
|
|
60
139
|
input: process.stdin,
|
|
@@ -79,7 +158,7 @@ export class ReplPrompt {
|
|
|
79
158
|
(words.length === 1 || line.endsWith(" "))) {
|
|
80
159
|
return [matchingCommands, line];
|
|
81
160
|
}
|
|
82
|
-
return fileSystemCompleter(line); // [completions, line];
|
|
161
|
+
return fileSystemCompleter(line, workspace); // [completions, line];
|
|
83
162
|
},
|
|
84
163
|
});
|
|
85
164
|
if (process.stdin.isTTY) {
|
|
@@ -99,11 +178,22 @@ export class ReplPrompt {
|
|
|
99
178
|
const cursorPos = this.rl.cursor;
|
|
100
179
|
const beforeCursor = currentLine.substring(0, cursorPos);
|
|
101
180
|
const afterCursor = currentLine.substring(cursorPos);
|
|
102
|
-
|
|
181
|
+
let textToInsert;
|
|
182
|
+
// Smart paste: use placeholder for text > 50 characters
|
|
183
|
+
if (clipboardText.length > 50) {
|
|
184
|
+
this.pasteCounter++;
|
|
185
|
+
const pasteId = this.pasteCounter;
|
|
186
|
+
this.pasteStore.set(pasteId, clipboardText);
|
|
187
|
+
textToInsert = `[Paste #${pasteId}, ${clipboardText.length} characters]`;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
textToInsert = clipboardText;
|
|
191
|
+
}
|
|
192
|
+
const newLine = beforeCursor + textToInsert + afterCursor;
|
|
103
193
|
// biome-ignore lint/suspicious/noExplicitAny: Accessing internal readline method
|
|
104
194
|
this.rl.line = newLine;
|
|
105
195
|
// biome-ignore lint/suspicious/noExplicitAny: Accessing internal readline method
|
|
106
|
-
this.rl.cursor = cursorPos +
|
|
196
|
+
this.rl.cursor = cursorPos + textToInsert.length;
|
|
107
197
|
// biome-ignore lint/suspicious/noExplicitAny: Accessing internal readline method
|
|
108
198
|
this.rl._refreshLine();
|
|
109
199
|
}
|
|
@@ -134,6 +224,13 @@ export class ReplPrompt {
|
|
|
134
224
|
}
|
|
135
225
|
return input;
|
|
136
226
|
}
|
|
227
|
+
getPasteStore() {
|
|
228
|
+
return new Map(this.pasteStore);
|
|
229
|
+
}
|
|
230
|
+
resetPasteStore() {
|
|
231
|
+
this.pasteCounter = 0;
|
|
232
|
+
this.pasteStore.clear();
|
|
233
|
+
}
|
|
137
234
|
close() {
|
|
138
235
|
if (this.keypressListener) {
|
|
139
236
|
process.stdin.off("keypress", this.keypressListener);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type ToolCallRepairFunction, type ToolSet } from "ai";
|
|
2
|
+
import type { ModelManager } from "../models/manager.js";
|
|
3
|
+
export declare const toolCallRepair: (modelManager: ModelManager) => ToolCallRepairFunction<ToolSet>;
|
|
4
|
+
//# sourceMappingURL=tool-call-repair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-repair.d.ts","sourceRoot":"","sources":["../../source/repl/tool-call-repair.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AAIZ,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAoCzD,eAAO,MAAM,cAAc,GAAI,cAAc,YAAY,oCAmDxD,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { generateObject, NoSuchToolError, } from "ai";
|
|
2
|
+
import { jsonrepair } from "jsonrepair";
|
|
3
|
+
import { logger } from "../logger.js";
|
|
4
|
+
async function remoteToolCallRepair(modelManager, toolCall, tool, inputSchema) {
|
|
5
|
+
const { object: repairedArgs } = await generateObject({
|
|
6
|
+
model: modelManager.getModel("tool-repair"),
|
|
7
|
+
schema: tool.inputSchema,
|
|
8
|
+
prompt: [
|
|
9
|
+
`The model tried to call the tool "${toolCall.toolName}" with the following arguments:`,
|
|
10
|
+
JSON.stringify(toolCall.input),
|
|
11
|
+
"The tool accepts the following schema:",
|
|
12
|
+
JSON.stringify(inputSchema(toolCall)),
|
|
13
|
+
"Please fix the arguments.",
|
|
14
|
+
].join("\n"),
|
|
15
|
+
});
|
|
16
|
+
return { ...toolCall, input: JSON.stringify(repairedArgs) };
|
|
17
|
+
}
|
|
18
|
+
const localToolCallRepair = async (toolCall, tool) => {
|
|
19
|
+
const schema = tool.inputSchema;
|
|
20
|
+
const repairedArgs = jsonrepair(toolCall.input);
|
|
21
|
+
const validatedArgs = schema.parse(JSON.parse(repairedArgs));
|
|
22
|
+
return { ...toolCall, input: JSON.stringify(validatedArgs) };
|
|
23
|
+
};
|
|
24
|
+
export const toolCallRepair = (modelManager) => {
|
|
25
|
+
const fn = async ({ toolCall, tools, inputSchema, error, }) => {
|
|
26
|
+
if (NoSuchToolError.isInstance(error)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
logger.warn(`Attempting to repair tool call: ${toolCall.toolName}.`);
|
|
30
|
+
const tool = tools[toolCall.toolName];
|
|
31
|
+
if (typeof tool === "undefined") {
|
|
32
|
+
logger.error(new Error("Tool not found"), `Failed to repair tool call: ${toolCall.toolName}.`);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const repaired = await localToolCallRepair(toolCall, tool);
|
|
37
|
+
logger.debug(`Tool call repaired with jsonrepair ${repaired.input}`);
|
|
38
|
+
return repaired;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
logger.error(err, `Failed to repair tool call locally: ${toolCall.toolName}.`);
|
|
42
|
+
try {
|
|
43
|
+
const repaired = await remoteToolCallRepair(modelManager, toolCall, tool, inputSchema);
|
|
44
|
+
logger.debug(`Tool call repaired with remote repair ${repaired.input}`);
|
|
45
|
+
return repaired;
|
|
46
|
+
}
|
|
47
|
+
catch (err2) {
|
|
48
|
+
logger.error(err2, `Failed to repair tool call remotely: ${toolCall.toolName}.`);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return fn;
|
|
54
|
+
};
|