@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
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isPathWithinAllowedDirs } from "./filesystem-utils.js";
|
|
5
|
+
// Validate path arguments to ensure they're within the project
|
|
6
|
+
export function validatePaths(command, allowedDirs, cwd, allowedPaths) {
|
|
7
|
+
// Simple tokenization - split on spaces but respect quotes
|
|
8
|
+
const tokens = [];
|
|
9
|
+
let current = "";
|
|
10
|
+
let inQuotes = false;
|
|
11
|
+
let quoteChar = "";
|
|
12
|
+
for (let i = 0; i < command.length; i++) {
|
|
13
|
+
const char = command[i] ?? "";
|
|
14
|
+
if ((char === '"' || char === "'") && !inQuotes) {
|
|
15
|
+
inQuotes = true;
|
|
16
|
+
quoteChar = char;
|
|
17
|
+
current += char;
|
|
18
|
+
}
|
|
19
|
+
else if (char === quoteChar && inQuotes) {
|
|
20
|
+
inQuotes = false;
|
|
21
|
+
quoteChar = "";
|
|
22
|
+
current += char;
|
|
23
|
+
}
|
|
24
|
+
else if (char === " " && !inQuotes) {
|
|
25
|
+
if (current) {
|
|
26
|
+
tokens.push(current);
|
|
27
|
+
current = "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
current += char;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (current)
|
|
35
|
+
tokens.push(current);
|
|
36
|
+
// Check each token that looks like a path
|
|
37
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
38
|
+
// Skip the command itself
|
|
39
|
+
const token = tokens[i];
|
|
40
|
+
if (!token)
|
|
41
|
+
continue;
|
|
42
|
+
// Remove quotes for path checking
|
|
43
|
+
const cleanToken = token.replace(/^['"]|['"]$/g, "");
|
|
44
|
+
// Skip if it's clearly not a path
|
|
45
|
+
if (cleanToken.startsWith("-") ||
|
|
46
|
+
cleanToken.includes("://") ||
|
|
47
|
+
(!cleanToken.includes("/") && cleanToken !== "~")) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// Skip git commit messages and other special cases
|
|
51
|
+
const prevToken = tokens[i - 1]?.replace(/^['"]|['"]$/g, "");
|
|
52
|
+
if (prevToken === "-m" || prevToken === "--message") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
// Expand ~ to home directory for proper validation
|
|
57
|
+
const expandedToken = cleanToken.startsWith("~/") || cleanToken === "~"
|
|
58
|
+
? path.join(os.homedir(), cleanToken.slice(1))
|
|
59
|
+
: cleanToken;
|
|
60
|
+
const resolvedPath = path.resolve(cwd, expandedToken);
|
|
61
|
+
// Allow access to explicitly allowed paths
|
|
62
|
+
const isAllowedPath = allowedPaths?.some((allowedPath) => resolvedPath === path.resolve(allowedPath));
|
|
63
|
+
if (!isAllowedPath &&
|
|
64
|
+
!isPathWithinAllowedDirs(resolvedPath, allowedDirs)) {
|
|
65
|
+
return {
|
|
66
|
+
isValid: false,
|
|
67
|
+
error: `Path '${cleanToken}' resolves outside the allowed directories (${resolvedPath}). All paths must be within ${allowedDirs.join(", ")}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (_e) { }
|
|
72
|
+
}
|
|
73
|
+
return { isValid: true };
|
|
74
|
+
}
|
|
75
|
+
export const resolveCwd = (cwdInput, workingDir) => {
|
|
76
|
+
const projectRootAbs = path.resolve(workingDir);
|
|
77
|
+
let projectRoot = projectRootAbs;
|
|
78
|
+
try {
|
|
79
|
+
projectRoot = fs.realpathSync(projectRootAbs);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Fallback to resolved path
|
|
83
|
+
}
|
|
84
|
+
const raw = typeof cwdInput === "string" && cwdInput.trim() !== ""
|
|
85
|
+
? cwdInput.trim()
|
|
86
|
+
: projectRoot;
|
|
87
|
+
const abs = path.isAbsolute(raw) ? raw : path.resolve(projectRoot, raw);
|
|
88
|
+
let target = abs;
|
|
89
|
+
try {
|
|
90
|
+
target = fs.realpathSync(abs);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// If the path doesn't exist entirely, validate intended path
|
|
94
|
+
}
|
|
95
|
+
const rel = path.relative(projectRoot, target);
|
|
96
|
+
const inside = rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
97
|
+
if (!inside) {
|
|
98
|
+
throw new Error(`Working directory must be within the project directory: ${projectRoot}. Received: ${cwdInput ?? "<default>"} -> ${target}`);
|
|
99
|
+
}
|
|
100
|
+
// Check existence and that it's a directory
|
|
101
|
+
let stats;
|
|
102
|
+
try {
|
|
103
|
+
stats = fs.statSync(target);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
const error = err;
|
|
107
|
+
if (error.code === "ENOENT") {
|
|
108
|
+
throw new Error(`Working directory does not exist: ${target} (from ${cwdInput ?? "<default>"})`);
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
if (!stats.isDirectory()) {
|
|
113
|
+
throw new Error(`Working directory is not a directory: ${target}`);
|
|
114
|
+
}
|
|
115
|
+
return target;
|
|
116
|
+
};
|
|
117
|
+
export const isMutatingCommand = (rawCommand) => {
|
|
118
|
+
const command = rawCommand.trim();
|
|
119
|
+
// Redirections that write to disk
|
|
120
|
+
if (/>|>>/.test(command)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
// Normalize whitespace and split into simple segments (does not fully parse shell)
|
|
124
|
+
const segments = command
|
|
125
|
+
.split(/\s*(?:&&|\|\||;|\|)\s*/)
|
|
126
|
+
.map((s) => s.trim())
|
|
127
|
+
.filter((s) => s.length > 0);
|
|
128
|
+
const mutatingBinaries = new Set([
|
|
129
|
+
"rm",
|
|
130
|
+
"mv",
|
|
131
|
+
"cp",
|
|
132
|
+
"mkdir",
|
|
133
|
+
"rmdir",
|
|
134
|
+
"touch",
|
|
135
|
+
"chmod",
|
|
136
|
+
"chown",
|
|
137
|
+
"ln",
|
|
138
|
+
"truncate",
|
|
139
|
+
"dd",
|
|
140
|
+
"tee",
|
|
141
|
+
]);
|
|
142
|
+
const npmMutating = new Set([
|
|
143
|
+
"install",
|
|
144
|
+
"uninstall",
|
|
145
|
+
"update",
|
|
146
|
+
"ci",
|
|
147
|
+
"publish",
|
|
148
|
+
"link",
|
|
149
|
+
"dedupe",
|
|
150
|
+
"prune",
|
|
151
|
+
"rebuild",
|
|
152
|
+
"add",
|
|
153
|
+
]);
|
|
154
|
+
const gitMutating = new Set([
|
|
155
|
+
"add",
|
|
156
|
+
"am",
|
|
157
|
+
"apply",
|
|
158
|
+
"branch",
|
|
159
|
+
"checkout",
|
|
160
|
+
"switch",
|
|
161
|
+
"cherry-pick",
|
|
162
|
+
"clean",
|
|
163
|
+
"commit",
|
|
164
|
+
"merge",
|
|
165
|
+
"mv",
|
|
166
|
+
"pull",
|
|
167
|
+
"push",
|
|
168
|
+
"rebase",
|
|
169
|
+
"reset",
|
|
170
|
+
"revert",
|
|
171
|
+
"stash",
|
|
172
|
+
"tag",
|
|
173
|
+
"worktree",
|
|
174
|
+
"submodule",
|
|
175
|
+
"config",
|
|
176
|
+
]);
|
|
177
|
+
// Generic action words that should be considered mutating when present in the command
|
|
178
|
+
const actionMutating = new Set(["create", "update", "upgrade", "install"]);
|
|
179
|
+
for (const seg of segments) {
|
|
180
|
+
const tokens = seg.split(/\s+/);
|
|
181
|
+
if (tokens.length === 0)
|
|
182
|
+
continue;
|
|
183
|
+
const bin = tokens[0];
|
|
184
|
+
if (!bin)
|
|
185
|
+
continue;
|
|
186
|
+
// If any token is an action-like mutating word, consider mutating
|
|
187
|
+
if (tokens.some((t) => actionMutating.has(t))) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
// sed -i is mutating
|
|
191
|
+
if (bin === "sed") {
|
|
192
|
+
if (tokens.some((t) => /^-i/.test(t))) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
// sed without -i is not mutating
|
|
196
|
+
}
|
|
197
|
+
if (mutatingBinaries.has(bin)) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
if (bin === "git" && tokens.length > 1) {
|
|
201
|
+
const sub = tokens[1];
|
|
202
|
+
if (typeof sub === "string" && gitMutating.has(sub)) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (bin === "npm" && tokens.length > 1) {
|
|
207
|
+
const sub = tokens[1];
|
|
208
|
+
if (typeof sub === "string" && npmMutating.has(sub)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if ((bin === "pnpm" || bin === "yarn") && tokens.length > 1) {
|
|
213
|
+
const sub = tokens[1];
|
|
214
|
+
if (typeof sub === "string" && npmMutating.has(sub)) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
};
|
package/dist/tools/bash.d.ts
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
1
|
+
import type { ToolCallOptions } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { TokenCounter } from "../tokens/counter.ts";
|
|
4
|
+
import type { ToolResult } from "./types.ts";
|
|
4
5
|
export declare const BashTool: {
|
|
5
6
|
name: "bash";
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
declare const inputSchema: z.ZodObject<{
|
|
9
|
+
command: z.ZodString;
|
|
10
|
+
cwd: z.ZodNullable<z.ZodString>;
|
|
11
|
+
timeout: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
type BashInputSchema = z.infer<typeof inputSchema>;
|
|
14
|
+
export declare const createBashTool: ({ baseDir, allowedDirs, tokenCounter, }: {
|
|
8
15
|
baseDir: string;
|
|
9
|
-
|
|
16
|
+
allowedDirs?: string[];
|
|
10
17
|
tokenCounter: TokenCounter;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
18
|
+
}) => Promise<{
|
|
19
|
+
toolDef: {
|
|
20
|
+
description: string;
|
|
21
|
+
inputSchema: z.ZodObject<{
|
|
22
|
+
command: z.ZodString;
|
|
23
|
+
cwd: z.ZodNullable<z.ZodString>;
|
|
24
|
+
timeout: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
};
|
|
27
|
+
execute({ command, cwd, timeout }: BashInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
28
|
+
}>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=bash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../source/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,QAAQ;;CAEpB,CAAC;AAKF,QAAA,MAAM,WAAW;;;;iBAcf,CAAC;AAEH,KAAK,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD,eAAO,MAAM,cAAc,GAAU,yCAIlC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;;;uCAcgC,eAAe,+BACb,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAyFhC,CAAC"}
|
package/dist/tools/bash.js
CHANGED
|
@@ -1,272 +1,108 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { input, select } from "@inquirer/prompts";
|
|
3
|
-
import { tool } from "ai";
|
|
4
|
-
import chalk from "chalk";
|
|
5
1
|
import { z } from "zod";
|
|
6
2
|
import { config } from "../config.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { initExecutionEnvironment } from "../execution/index.js";
|
|
4
|
+
import { logger } from "../logger.js";
|
|
5
|
+
import style from "../terminal/style.js";
|
|
6
|
+
import { manageTokenLimit } from "../tokens/threshold.js";
|
|
7
|
+
import { isMutatingCommand, resolveCwd, validatePaths } from "./bash-utils.js";
|
|
8
|
+
import { isPathWithinAllowedDirs } from "./filesystem-utils.js";
|
|
9
9
|
export const BashTool = {
|
|
10
10
|
name: "bash",
|
|
11
11
|
};
|
|
12
|
-
// Whitelist of allowed commands
|
|
13
|
-
const ALLOWED_COMMANDS = [
|
|
14
|
-
"chmod",
|
|
15
|
-
"ls",
|
|
16
|
-
"pwd",
|
|
17
|
-
"cat",
|
|
18
|
-
"grep",
|
|
19
|
-
"find",
|
|
20
|
-
"echo",
|
|
21
|
-
"mkdir",
|
|
22
|
-
"touch",
|
|
23
|
-
"cp",
|
|
24
|
-
"mv",
|
|
25
|
-
"pwd",
|
|
26
|
-
"wc",
|
|
27
|
-
"diff",
|
|
28
|
-
"sort",
|
|
29
|
-
"head",
|
|
30
|
-
"tail",
|
|
31
|
-
"sleep",
|
|
32
|
-
"npm",
|
|
33
|
-
"npx",
|
|
34
|
-
"node",
|
|
35
|
-
"git",
|
|
36
|
-
"gh",
|
|
37
|
-
"rg",
|
|
38
|
-
"jq",
|
|
39
|
-
"sed",
|
|
40
|
-
"awk",
|
|
41
|
-
];
|
|
42
12
|
// Command execution timeout in milliseconds
|
|
43
13
|
const DEFAULT_TIMEOUT = 1.5 * 60 * 1000; // 1.5 minutes
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
current += char;
|
|
63
|
-
}
|
|
64
|
-
else if (char === quoteChar && inQuotes) {
|
|
65
|
-
inQuotes = false;
|
|
66
|
-
quoteChar = "";
|
|
67
|
-
current += char;
|
|
68
|
-
}
|
|
69
|
-
else if (char === " " && !inQuotes) {
|
|
70
|
-
if (current) {
|
|
71
|
-
tokens.push(current);
|
|
72
|
-
current = "";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
current += char;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (current)
|
|
80
|
-
tokens.push(current);
|
|
81
|
-
// Check each token that looks like a path
|
|
82
|
-
for (let i = 1; i < tokens.length; i++) {
|
|
83
|
-
// Skip the command itself
|
|
84
|
-
const token = tokens[i];
|
|
85
|
-
if (!token)
|
|
86
|
-
continue;
|
|
87
|
-
// Remove quotes for path checking
|
|
88
|
-
const cleanToken = token.replace(/^['"]|['"]$/g, "");
|
|
89
|
-
// Skip if it's clearly not a path
|
|
90
|
-
if (cleanToken.startsWith("-") ||
|
|
91
|
-
cleanToken.includes("://") ||
|
|
92
|
-
!cleanToken.includes("/")) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
// Skip git commit messages and other special cases
|
|
96
|
-
const prevToken = tokens[i - 1]?.replace(/^['"]|['"]$/g, "");
|
|
97
|
-
if (prevToken === "-m" || prevToken === "--message") {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
const resolvedPath = path.resolve(cwd, cleanToken);
|
|
102
|
-
if (!isPathWithinBaseDir(resolvedPath, baseDir)) {
|
|
103
|
-
return {
|
|
104
|
-
isValid: false,
|
|
105
|
-
error: `Path '${cleanToken}' resolves outside the project directory (${resolvedPath}). All paths must be within ${baseDir}`,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (_e) { }
|
|
110
|
-
}
|
|
111
|
-
return { isValid: true };
|
|
112
|
-
}
|
|
113
|
-
// Initialize command validator with allowed commands
|
|
114
|
-
const commandValidator = new CommandValidation(ALLOWED_COMMANDS);
|
|
115
|
-
export const createBashTool = ({ baseDir, sendData, tokenCounter, terminal, autoAcceptAll, }) => {
|
|
116
|
-
let autoAcceptCommands = autoAcceptAll;
|
|
14
|
+
const inputSchema = z.object({
|
|
15
|
+
command: z.string().describe("Full CLI command to execute."),
|
|
16
|
+
cwd: z
|
|
17
|
+
.string()
|
|
18
|
+
.nullable()
|
|
19
|
+
.describe("Working directory file path (default: project root). Must be within the project directory."),
|
|
20
|
+
timeout: z.coerce
|
|
21
|
+
.number()
|
|
22
|
+
.nullable()
|
|
23
|
+
.describe(`Command execution timeout in milliseconds. Default: ${DEFAULT_TIMEOUT}ms`),
|
|
24
|
+
});
|
|
25
|
+
export const createBashTool = async ({ baseDir, allowedDirs, tokenCounter, }) => {
|
|
26
|
+
const execEnv = await initExecutionEnvironment();
|
|
27
|
+
const projectConfig = await config.readProjectConfig();
|
|
28
|
+
const allowedPaths = projectConfig.logs?.path
|
|
29
|
+
? [projectConfig.logs.path]
|
|
30
|
+
: [];
|
|
31
|
+
const allowedDirectories = allowedDirs ?? [baseDir];
|
|
117
32
|
return {
|
|
118
|
-
|
|
119
|
-
description:
|
|
120
|
-
inputSchema
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
sendData?.({
|
|
33
|
+
toolDef: {
|
|
34
|
+
description: "Execute commands in a shell. Commands execute only within the project directory. Always use absolute paths.",
|
|
35
|
+
inputSchema,
|
|
36
|
+
},
|
|
37
|
+
async *execute({ command, cwd, timeout }, { toolCallId, abortSignal }) {
|
|
38
|
+
try {
|
|
39
|
+
if (abortSignal?.aborted) {
|
|
40
|
+
throw new Error("Command execution aborted");
|
|
41
|
+
}
|
|
42
|
+
// grok doesn't follow my instructions
|
|
43
|
+
const safeCwd = cwd === "null" ? null : cwd;
|
|
44
|
+
const resolvedCwd = resolveCwd(safeCwd, baseDir);
|
|
45
|
+
const safeTimeout = timeout ?? DEFAULT_TIMEOUT;
|
|
46
|
+
// Safety warning for potentially mutating commands
|
|
47
|
+
const isMutating = isMutatingCommand(command);
|
|
48
|
+
yield {
|
|
49
|
+
name: BashTool.name,
|
|
136
50
|
event: "tool-init",
|
|
137
51
|
id: toolCallId,
|
|
138
|
-
data:
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return errorMsg;
|
|
145
|
-
}
|
|
146
|
-
// Validate command using improved validation
|
|
147
|
-
const commandValidation = commandValidator.isValid(command);
|
|
148
|
-
if (!commandValidation.isValid) {
|
|
149
|
-
sendData?.({
|
|
52
|
+
data: `${style.cyan(command)}${isMutating ? " *" : ""}`,
|
|
53
|
+
};
|
|
54
|
+
if (!isPathWithinAllowedDirs(resolvedCwd, allowedDirectories)) {
|
|
55
|
+
const errorMsg = `Working directory must be within the allowed directories: ${allowedDirectories.join(", ")}`;
|
|
56
|
+
yield {
|
|
57
|
+
name: BashTool.name,
|
|
150
58
|
event: "tool-error",
|
|
151
59
|
id: toolCallId,
|
|
152
|
-
data:
|
|
153
|
-
}
|
|
154
|
-
|
|
60
|
+
data: errorMsg,
|
|
61
|
+
};
|
|
62
|
+
yield errorMsg;
|
|
63
|
+
return;
|
|
155
64
|
}
|
|
156
|
-
|
|
157
|
-
const pathValidation = validatePaths(command, baseDir, safeCwd);
|
|
65
|
+
const pathValidation = validatePaths(command, allowedDirectories, resolvedCwd, allowedPaths);
|
|
158
66
|
if (!pathValidation.isValid) {
|
|
159
|
-
|
|
67
|
+
yield {
|
|
68
|
+
name: BashTool.name,
|
|
160
69
|
event: "tool-error",
|
|
161
70
|
id: toolCallId,
|
|
162
71
|
data: pathValidation.error ?? "Unknown error.",
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// Prompt user for command execution approval (only in interactive mode)
|
|
167
|
-
if (terminal) {
|
|
168
|
-
if (!autoAcceptCommands) {
|
|
169
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
170
|
-
terminal.lineBreak();
|
|
171
|
-
terminal.writeln(`${chalk.blue.bold("●")} About to execute command: ${chalk.cyan(command)}`);
|
|
172
|
-
terminal.writeln(`${chalk.gray("Working directory:")} ${safeCwd}`);
|
|
173
|
-
terminal.lineBreak();
|
|
174
|
-
}
|
|
175
|
-
let userChoice;
|
|
176
|
-
if (autoAcceptCommands) {
|
|
177
|
-
terminal.writeln(chalk.green("✓ Auto-accepting command (all future commands will be accepted)"));
|
|
178
|
-
userChoice = "accept";
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
userChoice = await select({
|
|
182
|
-
message: "What would you like to do with this command?",
|
|
183
|
-
choices: [
|
|
184
|
-
{ name: "Execute this command", value: "accept" },
|
|
185
|
-
{
|
|
186
|
-
name: "Execute all future commands (including this)",
|
|
187
|
-
value: "accept-all",
|
|
188
|
-
},
|
|
189
|
-
{ name: "Reject this command", value: "reject" },
|
|
190
|
-
],
|
|
191
|
-
default: "accept",
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
terminal.lineBreak();
|
|
195
|
-
if (userChoice === "accept-all") {
|
|
196
|
-
autoAcceptCommands = true;
|
|
197
|
-
terminal.writeln(chalk.yellow("✓ Auto-accept mode enabled for all future commands"));
|
|
198
|
-
terminal.lineBreak();
|
|
199
|
-
}
|
|
200
|
-
if (userChoice === "reject") {
|
|
201
|
-
const reason = await input({ message: "Feedback: " });
|
|
202
|
-
terminal.lineBreak();
|
|
203
|
-
const rejectionMsg = `Command rejected by user. Reason: ${reason}`;
|
|
204
|
-
sendData?.({
|
|
205
|
-
event: "tool-completion",
|
|
206
|
-
id: toolCallId,
|
|
207
|
-
data: rejectionMsg,
|
|
208
|
-
});
|
|
209
|
-
return rejectionMsg;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// Execute command
|
|
213
|
-
try {
|
|
214
|
-
const result = await executeCommand(command, {
|
|
215
|
-
cwd: safeCwd,
|
|
216
|
-
timeout: safeTimeout,
|
|
217
|
-
shell: false,
|
|
218
|
-
throwOnError: false,
|
|
219
|
-
});
|
|
220
|
-
if (result.signal === "SIGTERM") {
|
|
221
|
-
const timeoutMessage = `Command timed out after ${safeTimeout}ms. This might be because the command is waiting for input.`;
|
|
222
|
-
sendData?.({
|
|
223
|
-
event: "tool-error",
|
|
224
|
-
id: toolCallId,
|
|
225
|
-
data: timeoutMessage,
|
|
226
|
-
});
|
|
227
|
-
return timeoutMessage;
|
|
228
|
-
}
|
|
229
|
-
const formattedResult = format(result);
|
|
230
|
-
sendData?.({
|
|
231
|
-
event: "tool-update",
|
|
232
|
-
id: toolCallId,
|
|
233
|
-
data: {
|
|
234
|
-
primary: "Result",
|
|
235
|
-
secondary: formattedResult.split("\n").slice(-5),
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
let tokenCount = 0;
|
|
239
|
-
try {
|
|
240
|
-
tokenCount = tokenCounter.count(formattedResult);
|
|
241
|
-
}
|
|
242
|
-
catch (tokenError) {
|
|
243
|
-
console.error("Error calculating token count:", tokenError);
|
|
244
|
-
}
|
|
245
|
-
const maxTokens = (await config.readProjectConfig()).tools.maxTokens;
|
|
246
|
-
const maxTokenMessage = `Output of command (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}). Please adjust how you call the command to get back more specific results`;
|
|
247
|
-
const finalResult = tokenCount <= maxTokens ? formattedResult : maxTokenMessage;
|
|
248
|
-
sendData?.({
|
|
249
|
-
event: "tool-completion",
|
|
250
|
-
id: toolCallId,
|
|
251
|
-
data: tokenCount <= maxTokens
|
|
252
|
-
? "Command executed successfully."
|
|
253
|
-
: `Output of command (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}).`,
|
|
254
|
-
});
|
|
255
|
-
return finalResult;
|
|
72
|
+
};
|
|
73
|
+
yield pathValidation.error ?? "Unknown error.";
|
|
74
|
+
return;
|
|
256
75
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
sendData?.({
|
|
260
|
-
event: "tool-error",
|
|
261
|
-
id: toolCallId,
|
|
262
|
-
data: errorMsg,
|
|
263
|
-
});
|
|
264
|
-
return errorMsg;
|
|
76
|
+
if (abortSignal?.aborted) {
|
|
77
|
+
throw new Error("Command execution aborted before running the command");
|
|
265
78
|
}
|
|
266
|
-
|
|
267
|
-
|
|
79
|
+
const { output, exitCode } = await execEnv.executeCommand(command, {
|
|
80
|
+
cwd: resolvedCwd,
|
|
81
|
+
timeout: safeTimeout,
|
|
82
|
+
abortSignal,
|
|
83
|
+
preserveOutputOnError: true,
|
|
84
|
+
captureStderr: true,
|
|
85
|
+
throwOnError: false,
|
|
86
|
+
});
|
|
87
|
+
const result = await manageTokenLimit(output, tokenCounter, "Bash", "Adjust command to return more specific results");
|
|
88
|
+
yield {
|
|
89
|
+
name: BashTool.name,
|
|
90
|
+
event: "tool-completion",
|
|
91
|
+
id: toolCallId,
|
|
92
|
+
data: `${exitCode} (${result.tokenCount} tokens)`,
|
|
93
|
+
};
|
|
94
|
+
yield result.content;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
logger.error(error, "Bash Tool Error:");
|
|
98
|
+
yield {
|
|
99
|
+
name: BashTool.name,
|
|
100
|
+
event: "tool-error",
|
|
101
|
+
id: toolCallId,
|
|
102
|
+
data: error.message,
|
|
103
|
+
};
|
|
104
|
+
yield error.message;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
268
107
|
};
|
|
269
108
|
};
|
|
270
|
-
function format({ stdout, stderr, }) {
|
|
271
|
-
return `${stdout}\n${stderr}`;
|
|
272
|
-
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ToolCallOptions } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { TokenCounter } from "../tokens/counter.ts";
|
|
4
|
+
import type { ToolResult } from "./types.ts";
|
|
2
5
|
export declare const CodeInterpreterTool: {
|
|
3
6
|
name: "codeInterpreter";
|
|
4
7
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
declare const inputSchema: z.ZodObject<{
|
|
9
|
+
code: z.ZodString;
|
|
10
|
+
timeoutSeconds: z.ZodNullable<z.ZodNumber>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
export declare const createCodeInterpreterTool: ({ tokenCounter, }: {
|
|
13
|
+
tokenCounter: TokenCounter;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
toolDef: {
|
|
16
|
+
description: string;
|
|
17
|
+
inputSchema: z.ZodObject<{
|
|
18
|
+
code: z.ZodString;
|
|
19
|
+
timeoutSeconds: z.ZodNullable<z.ZodNumber>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
};
|
|
22
|
+
execute: ({ code, timeoutSeconds }: z.infer<typeof inputSchema>, { toolCallId, abortSignal }: ToolCallOptions) => AsyncGenerator<ToolResult>;
|
|
23
|
+
}>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=code-interpreter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-interpreter.d.ts","sourceRoot":"","sources":["../../source/tools/code-interpreter.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,mBAAmB;;CAE/B,CAAC;AAmBF,QAAA,MAAM,WAAW;;;iBASf,CAAC;AAEH,eAAO,MAAM,yBAAyB,GAAU,mBAE7C;IACD,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;;wCAO6B,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,+BACxB,eAAe,KAC3C,cAAc,CAAC,UAAU,CAAC;EAqK9B,CAAC"}
|