@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/tools/move-file.js
CHANGED
|
@@ -1,44 +1,58 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
-
import { tool } from "ai";
|
|
3
|
-
import chalk from "chalk";
|
|
4
2
|
import { z } from "zod";
|
|
3
|
+
import style from "../terminal/style.js";
|
|
5
4
|
import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
|
|
6
5
|
export const MoveFileTool = {
|
|
7
6
|
name: "moveFile",
|
|
8
7
|
};
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const inputSchema = z.object({
|
|
9
|
+
source: z.string(),
|
|
10
|
+
destination: z.string(),
|
|
11
|
+
});
|
|
12
|
+
export const createMoveFileTool = async ({ workingDir, allowedDirs, }) => {
|
|
13
|
+
const allowedDirectory = allowedDirs ?? [workingDir];
|
|
11
14
|
return {
|
|
12
|
-
|
|
15
|
+
toolDef: {
|
|
13
16
|
description: "Move or rename files and directories. Can move files between directories " +
|
|
14
17
|
"and rename them in a single operation. If the destination exists, the " +
|
|
15
18
|
"operation will fail. Works across different directories and can be used " +
|
|
16
19
|
"for simple renaming within the same directory. Both source and destination must be within allowed directories.",
|
|
17
|
-
inputSchema
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
sendData?.({
|
|
24
|
-
id: toolCallId,
|
|
25
|
-
event: "tool-init",
|
|
26
|
-
data: `Moving file from ${chalk.cyan(source)} to ${chalk.cyan(destination)}`,
|
|
27
|
-
});
|
|
28
|
-
const validSourcePath = await validatePath(joinWorkingDir(source, workingDir), allowedDirectory);
|
|
29
|
-
const validDestPath = await validatePath(joinWorkingDir(destination, workingDir), allowedDirectory);
|
|
30
|
-
await fs.rename(validSourcePath, validDestPath);
|
|
31
|
-
sendData?.({
|
|
32
|
-
id: toolCallId,
|
|
33
|
-
event: "tool-completion",
|
|
34
|
-
data: "Done",
|
|
35
|
-
});
|
|
36
|
-
return `Successfully moved ${source} to ${destination}`;
|
|
20
|
+
inputSchema,
|
|
21
|
+
},
|
|
22
|
+
async *execute({ source, destination }, { toolCallId, abortSignal }) {
|
|
23
|
+
try {
|
|
24
|
+
if (abortSignal?.aborted) {
|
|
25
|
+
throw new Error("File move aborted");
|
|
37
26
|
}
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
yield {
|
|
28
|
+
name: MoveFileTool.name,
|
|
29
|
+
id: toolCallId,
|
|
30
|
+
event: "tool-init",
|
|
31
|
+
data: `${style.cyan(source)} => ${style.cyan(destination)}`,
|
|
32
|
+
};
|
|
33
|
+
const validSourcePath = await validatePath(joinWorkingDir(source, workingDir), allowedDirectory, { abortSignal });
|
|
34
|
+
const validDestPath = await validatePath(joinWorkingDir(destination, workingDir), allowedDirectory, { requireExistence: false, abortSignal });
|
|
35
|
+
if (abortSignal?.aborted) {
|
|
36
|
+
throw new Error("File move aborted before file operation");
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
await fs.rename(validSourcePath, validDestPath);
|
|
39
|
+
yield {
|
|
40
|
+
name: MoveFileTool.name,
|
|
41
|
+
id: toolCallId,
|
|
42
|
+
event: "tool-completion",
|
|
43
|
+
data: "File moved",
|
|
44
|
+
};
|
|
45
|
+
yield `Successfully moved ${source} to ${destination}`;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
yield {
|
|
49
|
+
name: MoveFileTool.name,
|
|
50
|
+
event: "tool-error",
|
|
51
|
+
id: toolCallId,
|
|
52
|
+
data: error.message,
|
|
53
|
+
};
|
|
54
|
+
yield `Failed to move file: ${error.message}`;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
43
57
|
};
|
|
44
58
|
};
|
|
@@ -1,17 +1,56 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
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";
|
|
3
5
|
export declare const ReadFileTool: {
|
|
4
6
|
name: "readFile";
|
|
5
7
|
};
|
|
6
|
-
|
|
8
|
+
declare const inputSchema: z.ZodObject<{
|
|
9
|
+
path: z.ZodString;
|
|
10
|
+
encoding: z.ZodEnum<{
|
|
11
|
+
utf8: "utf8";
|
|
12
|
+
ascii: "ascii";
|
|
13
|
+
"utf-8": "utf-8";
|
|
14
|
+
utf16le: "utf16le";
|
|
15
|
+
ucs2: "ucs2";
|
|
16
|
+
"ucs-2": "ucs-2";
|
|
17
|
+
base64: "base64";
|
|
18
|
+
base64url: "base64url";
|
|
19
|
+
latin1: "latin1";
|
|
20
|
+
binary: "binary";
|
|
21
|
+
hex: "hex";
|
|
22
|
+
}>;
|
|
23
|
+
startLine: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
24
|
+
lineCount: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
type ReadFileInputSchema = z.infer<typeof inputSchema>;
|
|
27
|
+
export declare const createReadFileTool: ({ workingDir, allowedDirs, tokenCounter, }: {
|
|
7
28
|
workingDir: string;
|
|
8
|
-
|
|
29
|
+
allowedDirs?: string[];
|
|
9
30
|
tokenCounter: TokenCounter;
|
|
10
31
|
}) => Promise<{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
toolDef: {
|
|
33
|
+
description: string;
|
|
34
|
+
inputSchema: z.ZodObject<{
|
|
35
|
+
path: z.ZodString;
|
|
36
|
+
encoding: z.ZodEnum<{
|
|
37
|
+
utf8: "utf8";
|
|
38
|
+
ascii: "ascii";
|
|
39
|
+
"utf-8": "utf-8";
|
|
40
|
+
utf16le: "utf16le";
|
|
41
|
+
ucs2: "ucs2";
|
|
42
|
+
"ucs-2": "ucs-2";
|
|
43
|
+
base64: "base64";
|
|
44
|
+
base64url: "base64url";
|
|
45
|
+
latin1: "latin1";
|
|
46
|
+
binary: "binary";
|
|
47
|
+
hex: "hex";
|
|
48
|
+
}>;
|
|
49
|
+
startLine: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
50
|
+
lineCount: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
};
|
|
53
|
+
execute({ path: providedPath, encoding, startLine, lineCount, }: ReadFileInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
17
54
|
}>;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=read-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../../source/tools/read-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;iBAef,CAAC;AAEH,KAAK,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEvD,eAAO,MAAM,kBAAkB,GAAU,4CAItC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;;;;;;;;;;;;;;;;qEAiBQ,mBAAmB,+BACO,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAoFhC,CAAC"}
|
package/dist/tools/read-file.js
CHANGED
|
@@ -1,86 +1,98 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import { isNumber } from "@travisennis/stdlib/typeguards";
|
|
3
|
-
import { tool } from "ai";
|
|
4
|
-
import chalk from "chalk";
|
|
5
3
|
import { z } from "zod";
|
|
6
|
-
import
|
|
4
|
+
import style from "../terminal/style.js";
|
|
5
|
+
import { manageTokenLimit } from "../tokens/threshold.js";
|
|
7
6
|
import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
|
|
8
7
|
import { fileEncodingSchema } from "./types.js";
|
|
9
8
|
export const ReadFileTool = {
|
|
10
9
|
name: "readFile",
|
|
11
10
|
};
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const inputSchema = z.object({
|
|
12
|
+
path: z.string().describe("Absolute path to file to read"),
|
|
13
|
+
encoding: fileEncodingSchema.describe('Encoding format for reading the file. Use "utf-8" as default for text files'),
|
|
14
|
+
startLine: z.coerce
|
|
15
|
+
.number()
|
|
16
|
+
.nullable()
|
|
17
|
+
.describe("1-based line number to start reading from. Pass null to start at beginning of file"),
|
|
18
|
+
lineCount: z.coerce
|
|
19
|
+
.number()
|
|
20
|
+
.nullable()
|
|
21
|
+
.describe("Maximum number of lines to read. Pass null to get all lines."),
|
|
22
|
+
});
|
|
23
|
+
export const createReadFileTool = async ({ workingDir, allowedDirs, tokenCounter, }) => {
|
|
24
|
+
const allowedDirectory = allowedDirs ?? [workingDir];
|
|
14
25
|
return {
|
|
15
|
-
|
|
26
|
+
toolDef: {
|
|
16
27
|
description: "Read the complete contents of a file from the file system unless startLine and lineCount are given to read a file selection. " +
|
|
17
28
|
"Handles various text encodings and provides detailed error messages " +
|
|
18
29
|
"if the file cannot be read. Use this tool when you need to examine " +
|
|
19
30
|
"the contents of a single file. Only works within allowed directories.",
|
|
20
|
-
inputSchema
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
.describe("Maximum number of lines to read. Pass null to get all lines."),
|
|
31
|
-
}),
|
|
32
|
-
execute: async ({ path: providedPath, encoding, startLine, lineCount, }, { toolCallId }) => {
|
|
33
|
-
sendData?.({
|
|
31
|
+
inputSchema,
|
|
32
|
+
},
|
|
33
|
+
async *execute({ path: providedPath, encoding, startLine, lineCount, }, { toolCallId, abortSignal }) {
|
|
34
|
+
try {
|
|
35
|
+
// Check if execution has been aborted
|
|
36
|
+
if (abortSignal?.aborted) {
|
|
37
|
+
throw new Error("File reading aborted");
|
|
38
|
+
}
|
|
39
|
+
yield {
|
|
40
|
+
name: ReadFileTool.name,
|
|
34
41
|
id: toolCallId,
|
|
35
42
|
event: "tool-init",
|
|
36
|
-
data:
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Apply line-based selection if requested
|
|
42
|
-
if (isNumber(startLine) || isNumber(lineCount)) {
|
|
43
|
-
const lines = file.split("\n");
|
|
44
|
-
const totalLines = lines.length;
|
|
45
|
-
const startIndex = (startLine ?? 1) - 1; // Default to start of file if only lineCount is given
|
|
46
|
-
const count = lineCount ?? totalLines - startIndex; // Default to read all lines from start if only startLine is given
|
|
47
|
-
if (startIndex < 0 || startIndex >= totalLines) {
|
|
48
|
-
return `startLine ${startLine} is out of bounds for file with ${totalLines} lines.`;
|
|
49
|
-
}
|
|
50
|
-
const endIndex = Math.min(startIndex + count, totalLines);
|
|
51
|
-
file = lines.slice(startIndex, endIndex).join("\n");
|
|
52
|
-
}
|
|
53
|
-
let tokenCount = 0;
|
|
54
|
-
try {
|
|
55
|
-
// Only calculate tokens for non-image files and if encoding is text-based
|
|
56
|
-
if (encoding.startsWith("utf")) {
|
|
57
|
-
tokenCount = tokenCounter.count(file);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (tokenError) {
|
|
61
|
-
console.error("Error calculating token count:", tokenError);
|
|
62
|
-
// Log or handle error, but don't block file return
|
|
63
|
-
}
|
|
64
|
-
const maxTokens = (await config.readProjectConfig()).tools.maxTokens;
|
|
65
|
-
// Adjust max token check message if line selection was used
|
|
66
|
-
const maxTokenMessage = isNumber(startLine) || isNumber(lineCount)
|
|
67
|
-
? `Selected file content (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}). Consider adjusting startLine/lineCount or using grepFiles.`
|
|
68
|
-
: `File content (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}). Please use startLine and lineCount parameters to read specific portions of the file, or using grepFiles to search for specific content.`;
|
|
69
|
-
const result = tokenCount <= maxTokens ? file : maxTokenMessage;
|
|
70
|
-
sendData?.({
|
|
71
|
-
id: toolCallId,
|
|
72
|
-
event: "tool-completion",
|
|
73
|
-
// Include token count only if calculated (i.e., for text files)
|
|
74
|
-
data: tokenCount <= maxTokens
|
|
75
|
-
? `File read successfully ${tokenCount > 0 ? ` (${tokenCount} tokens)` : ""}`
|
|
76
|
-
: result,
|
|
77
|
-
});
|
|
78
|
-
return result;
|
|
43
|
+
data: `${style.cyan(providedPath)}${startLine ? style.cyan(`:${startLine}`) : ""}${lineCount ? style.cyan(`:${lineCount}`) : ""}`,
|
|
44
|
+
};
|
|
45
|
+
const filePath = await validatePath(joinWorkingDir(providedPath, workingDir), allowedDirectory, { abortSignal });
|
|
46
|
+
if (abortSignal?.aborted) {
|
|
47
|
+
throw new Error("File reading aborted before file read");
|
|
79
48
|
}
|
|
80
|
-
|
|
81
|
-
|
|
49
|
+
let file = await fs.readFile(filePath, { encoding });
|
|
50
|
+
// Apply line-based selection if requested
|
|
51
|
+
if (isNumber(startLine) || isNumber(lineCount)) {
|
|
52
|
+
const lines = file.split("\n");
|
|
53
|
+
const totalLines = lines.length;
|
|
54
|
+
const startIndex = (startLine ?? 1) - 1; // Default to start of file if only lineCount is given
|
|
55
|
+
const count = lineCount ?? totalLines - startIndex; // Default to read all lines from start if only startLine is given
|
|
56
|
+
if (startIndex < 0 || startIndex >= totalLines) {
|
|
57
|
+
const errorMsg = `startLine ${startLine} is out of bounds for file with ${totalLines} lines.`;
|
|
58
|
+
yield {
|
|
59
|
+
name: ReadFileTool.name,
|
|
60
|
+
event: "tool-error",
|
|
61
|
+
id: toolCallId,
|
|
62
|
+
data: errorMsg,
|
|
63
|
+
};
|
|
64
|
+
yield errorMsg;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const endIndex = Math.min(startIndex + count, totalLines);
|
|
68
|
+
file = lines.slice(startIndex, endIndex).join("\n");
|
|
82
69
|
}
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
const result = await manageTokenLimit(file, tokenCounter, "ReadFile", isNumber(startLine) || isNumber(lineCount)
|
|
71
|
+
? "Consider adjusting startLine/lineCount or using grepFiles"
|
|
72
|
+
: "Use startLine and lineCount parameters to read specific portions, or use grepFiles for targeted access", encoding);
|
|
73
|
+
// Calculate line count for the returned content
|
|
74
|
+
const linesRead = result.content.split("\n").length;
|
|
75
|
+
yield {
|
|
76
|
+
name: ReadFileTool.name,
|
|
77
|
+
id: toolCallId,
|
|
78
|
+
event: "tool-completion",
|
|
79
|
+
// Include success, line count, and token count
|
|
80
|
+
data: !result.truncated
|
|
81
|
+
? `Read ${linesRead} lines (${result.tokenCount} tokens)`
|
|
82
|
+
: result.content,
|
|
83
|
+
};
|
|
84
|
+
yield result.content;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const errorMsg = `${error.message}`;
|
|
88
|
+
yield {
|
|
89
|
+
name: ReadFileTool.name,
|
|
90
|
+
event: "tool-error",
|
|
91
|
+
id: toolCallId,
|
|
92
|
+
data: errorMsg,
|
|
93
|
+
};
|
|
94
|
+
yield errorMsg;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
85
97
|
};
|
|
86
98
|
};
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
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";
|
|
3
5
|
export declare const ReadMultipleFilesTool: {
|
|
4
6
|
name: "readMultipleFiles";
|
|
5
7
|
};
|
|
6
|
-
|
|
8
|
+
declare const inputSchema: z.ZodObject<{
|
|
9
|
+
paths: z.ZodArray<z.ZodString>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
type ReadMultipleFilesInputSchema = z.infer<typeof inputSchema>;
|
|
12
|
+
export declare const createReadMultipleFilesTool: ({ workingDir, allowedDirs, tokenCounter, }: {
|
|
7
13
|
workingDir: string;
|
|
8
|
-
|
|
14
|
+
allowedDirs?: string[];
|
|
9
15
|
tokenCounter: TokenCounter;
|
|
10
16
|
}) => Promise<{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
toolDef: {
|
|
18
|
+
description: string;
|
|
19
|
+
inputSchema: z.ZodObject<{
|
|
20
|
+
paths: z.ZodArray<z.ZodString>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
};
|
|
23
|
+
execute({ paths }: ReadMultipleFilesInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
14
24
|
}>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=read-multiple-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-multiple-files.d.ts","sourceRoot":"","sources":["../../source/tools/read-multiple-files.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,qBAAqB;;CAEjC,CAAC;AAEF,QAAA,MAAM,WAAW;;iBAEf,CAAC;AAEH,KAAK,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEhE,eAAO,MAAM,2BAA2B,GAAU,4CAI/C;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;uBAcgB,4BAA4B,+BACV,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAwIhC,CAAC"}
|
|
@@ -1,55 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import chalk from "chalk";
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
3
2
|
import { z } from "zod";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
3
|
+
import { formatFile } from "../formatting.js";
|
|
4
|
+
import style from "../terminal/style.js";
|
|
5
|
+
import { manageTokenLimit } from "../tokens/threshold.js";
|
|
6
|
+
import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
|
|
6
7
|
export const ReadMultipleFilesTool = {
|
|
7
8
|
name: "readMultipleFiles",
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const inputSchema = z.object({
|
|
11
|
+
paths: z.array(z.string()),
|
|
12
|
+
});
|
|
13
|
+
export const createReadMultipleFilesTool = async ({ workingDir, allowedDirs, tokenCounter, }) => {
|
|
14
|
+
const allowedDirectory = allowedDirs ?? [workingDir];
|
|
11
15
|
return {
|
|
12
|
-
|
|
16
|
+
toolDef: {
|
|
13
17
|
description: "Read the contents of multiple files simultaneously. This is more " +
|
|
14
18
|
"efficient than reading files one by one when you need to analyze " +
|
|
15
19
|
"or compare multiple files. Each file's content is returned with its " +
|
|
16
20
|
"path as a reference. Failed reads for individual files won't stop " +
|
|
17
21
|
"the entire operation. Only works within allowed directories.",
|
|
18
|
-
inputSchema
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
inputSchema,
|
|
23
|
+
},
|
|
24
|
+
async *execute({ paths }, { toolCallId, abortSignal }) {
|
|
25
|
+
try {
|
|
26
|
+
// Check if execution has been aborted
|
|
27
|
+
if (abortSignal?.aborted) {
|
|
28
|
+
throw new Error("Multiple file reading aborted");
|
|
29
|
+
}
|
|
30
|
+
yield {
|
|
31
|
+
name: ReadMultipleFilesTool.name,
|
|
23
32
|
id: toolCallId,
|
|
24
33
|
event: "tool-init",
|
|
25
|
-
data:
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
data: `${paths.map((p) => style.cyan(p)).join(", ")}`,
|
|
35
|
+
};
|
|
36
|
+
if (abortSignal?.aborted) {
|
|
37
|
+
throw new Error("Multiple file reading aborted before reading files");
|
|
38
|
+
}
|
|
39
|
+
const results = await Promise.all(paths.map(async (filePath) => {
|
|
40
|
+
if (abortSignal?.aborted) {
|
|
41
|
+
throw new Error("Multiple file reading aborted during file processing");
|
|
42
|
+
}
|
|
43
|
+
const fileResult = await validateAndReadFile(filePath, workingDir, allowedDirectory);
|
|
44
|
+
return fileResult;
|
|
45
|
+
}));
|
|
46
|
+
const processedResults = await Promise.all(results.map(async (result) => {
|
|
47
|
+
if (result.error) {
|
|
48
|
+
return {
|
|
49
|
+
path: result.path,
|
|
50
|
+
content: `${result.path}: Error - ${result.error}`,
|
|
51
|
+
tokenCount: 0,
|
|
52
|
+
error: result.error,
|
|
53
|
+
truncated: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Apply token limit check to each file
|
|
57
|
+
const managedResult = await manageTokenLimit(result.content ?? "", tokenCounter, "ReadMultipleFiles", "Use readFile with startLine/lineCount or grepFiles for targeted access");
|
|
58
|
+
return {
|
|
59
|
+
path: result.path,
|
|
60
|
+
content: formatFile(result.path, managedResult.content, "markdown"),
|
|
61
|
+
tokenCount: managedResult.tokenCount,
|
|
62
|
+
error: null,
|
|
63
|
+
truncated: managedResult.truncated,
|
|
64
|
+
};
|
|
65
|
+
}));
|
|
66
|
+
const formattedResults = processedResults.map((r) => r.content);
|
|
67
|
+
const finalResult = await manageTokenLimit(formattedResults.join("\n---\n"), tokenCounter, "ReadMultipleFiles", "Reduce number of files or use more specific paths");
|
|
68
|
+
// Aggregate results with detailed breakdown
|
|
29
69
|
let totalTokens = 0;
|
|
30
70
|
let filesReadCount = 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
71
|
+
let filesExceededLimitCount = 0;
|
|
72
|
+
let filesErrorCount = 0;
|
|
73
|
+
for (const processedResult of processedResults) {
|
|
74
|
+
if (processedResult.error) {
|
|
75
|
+
filesErrorCount++;
|
|
76
|
+
}
|
|
77
|
+
else if (processedResult.truncated) {
|
|
78
|
+
filesExceededLimitCount++;
|
|
79
|
+
totalTokens += processedResult.tokenCount;
|
|
34
80
|
}
|
|
35
|
-
|
|
36
|
-
if (result.tokenCount > 0) {
|
|
81
|
+
else {
|
|
37
82
|
filesReadCount++;
|
|
83
|
+
totalTokens += processedResult.tokenCount;
|
|
38
84
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
85
|
+
}
|
|
86
|
+
const parts = [];
|
|
87
|
+
if (filesReadCount > 0) {
|
|
88
|
+
parts.push(`Read ${filesReadCount} files successfully (${totalTokens} total tokens)`);
|
|
89
|
+
}
|
|
90
|
+
if (filesExceededLimitCount > 0) {
|
|
91
|
+
parts.push(`${filesExceededLimitCount} files exceeded token limit`);
|
|
92
|
+
}
|
|
93
|
+
if (filesErrorCount > 0) {
|
|
94
|
+
parts.push(`${filesErrorCount} files could not be read`);
|
|
95
|
+
}
|
|
96
|
+
if (finalResult.truncated) {
|
|
97
|
+
parts.push(`Combined output exceeded token limit. ${finalResult.content}`);
|
|
98
|
+
}
|
|
99
|
+
const completionMessage = `${parts.join(", ")}.`;
|
|
100
|
+
yield {
|
|
101
|
+
name: ReadMultipleFilesTool.name,
|
|
47
102
|
id: toolCallId,
|
|
48
103
|
event: "tool-completion",
|
|
49
104
|
data: completionMessage,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
105
|
+
};
|
|
106
|
+
yield finalResult.content;
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
const errorMsg = error.message;
|
|
110
|
+
yield {
|
|
111
|
+
name: ReadMultipleFilesTool.name,
|
|
112
|
+
id: toolCallId,
|
|
113
|
+
event: "tool-error",
|
|
114
|
+
data: errorMsg,
|
|
115
|
+
};
|
|
116
|
+
yield errorMsg;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
54
119
|
};
|
|
55
120
|
};
|
|
121
|
+
async function validateAndReadFile(filePath, workingDir, allowedDirectory) {
|
|
122
|
+
try {
|
|
123
|
+
const validPath = await validatePath(joinWorkingDir(filePath, workingDir), allowedDirectory);
|
|
124
|
+
const content = await readFile(validPath, "utf-8");
|
|
125
|
+
return {
|
|
126
|
+
path: filePath,
|
|
127
|
+
content,
|
|
128
|
+
error: null,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
133
|
+
return {
|
|
134
|
+
path: filePath,
|
|
135
|
+
content: null,
|
|
136
|
+
error: errorMessage,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -1,17 +1,52 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { ToolCallOptions } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type ToolResult } from "./types.ts";
|
|
3
4
|
export declare const SaveFileTool: {
|
|
4
5
|
name: "saveFile";
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
+
declare const inputSchema: z.ZodObject<{
|
|
8
|
+
path: z.ZodString;
|
|
9
|
+
content: z.ZodString;
|
|
10
|
+
encoding: z.ZodEnum<{
|
|
11
|
+
utf8: "utf8";
|
|
12
|
+
ascii: "ascii";
|
|
13
|
+
"utf-8": "utf-8";
|
|
14
|
+
utf16le: "utf16le";
|
|
15
|
+
ucs2: "ucs2";
|
|
16
|
+
"ucs-2": "ucs-2";
|
|
17
|
+
base64: "base64";
|
|
18
|
+
base64url: "base64url";
|
|
19
|
+
latin1: "latin1";
|
|
20
|
+
binary: "binary";
|
|
21
|
+
hex: "hex";
|
|
22
|
+
}>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
type SaveFileInputSchema = z.infer<typeof inputSchema>;
|
|
25
|
+
export declare const createSaveFileTool: ({ workingDir, allowedDirs, }: {
|
|
7
26
|
workingDir: string;
|
|
8
|
-
|
|
9
|
-
terminal?: Terminal;
|
|
10
|
-
autoAcceptAll?: boolean;
|
|
27
|
+
allowedDirs?: string[];
|
|
11
28
|
}) => Promise<{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
toolDef: {
|
|
30
|
+
description: string;
|
|
31
|
+
inputSchema: z.ZodObject<{
|
|
32
|
+
path: z.ZodString;
|
|
33
|
+
content: z.ZodString;
|
|
34
|
+
encoding: z.ZodEnum<{
|
|
35
|
+
utf8: "utf8";
|
|
36
|
+
ascii: "ascii";
|
|
37
|
+
"utf-8": "utf-8";
|
|
38
|
+
utf16le: "utf16le";
|
|
39
|
+
ucs2: "ucs2";
|
|
40
|
+
"ucs-2": "ucs-2";
|
|
41
|
+
base64: "base64";
|
|
42
|
+
base64url: "base64url";
|
|
43
|
+
latin1: "latin1";
|
|
44
|
+
binary: "binary";
|
|
45
|
+
hex: "hex";
|
|
46
|
+
}>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
};
|
|
49
|
+
execute({ path: userPath, content, encoding }: SaveFileInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
17
50
|
}>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=save-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-file.d.ts","sourceRoot":"","sources":["../../source/tools/save-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;iBAMf,CAAC;AAEH,KAAK,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEvD,eAAO,MAAM,kBAAkB,GAAU,8BAGtC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;;;;;;;;;;;;;;;;;;;;;mDAa4C,mBAAmB,+BAC7B,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAuEhC,CAAC"}
|