@travisennis/acai 0.0.5 → 0.0.7
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 +190 -19
- package/bin/acai-wrapper.js +26 -0
- package/dist/agent/index.d.ts +132 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +434 -0
- package/dist/api/exa/index.js +1 -1
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +67 -40
- 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 +54 -0
- package/dist/commands/application-log-command.d.ts +1 -1
- package/dist/commands/application-log-command.d.ts.map +1 -1
- package/dist/commands/application-log-command.js +18 -20
- package/dist/commands/clear-command.d.ts +1 -1
- package/dist/commands/clear-command.d.ts.map +1 -1
- package/dist/commands/clear-command.js +7 -3
- package/dist/commands/compact-command.d.ts.map +1 -1
- package/dist/commands/compact-command.js +9 -5
- 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 +124 -0
- package/dist/commands/copy-command.d.ts.map +1 -1
- package/dist/commands/copy-command.js +14 -5
- package/dist/commands/edit-command.d.ts +1 -1
- package/dist/commands/edit-command.d.ts.map +1 -1
- package/dist/commands/edit-command.js +21 -34
- package/dist/commands/edit-prompt-command.d.ts +1 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -1
- package/dist/commands/edit-prompt-command.js +18 -15
- package/dist/commands/exit-command.d.ts +1 -4
- package/dist/commands/exit-command.d.ts.map +1 -1
- package/dist/commands/exit-command.js +9 -5
- package/dist/commands/files-command.d.ts +1 -1
- package/dist/commands/files-command.d.ts.map +1 -1
- package/dist/commands/files-command.js +20 -16
- package/dist/commands/generate-rules-command.d.ts +1 -1
- package/dist/commands/generate-rules-command.d.ts.map +1 -1
- package/dist/commands/generate-rules-command.js +307 -39
- 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 +191 -0
- package/dist/commands/health-command.d.ts +1 -1
- package/dist/commands/health-command.d.ts.map +1 -1
- package/dist/commands/health-command.js +49 -27
- package/dist/commands/help-command.d.ts +1 -1
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +25 -5
- 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 +458 -0
- package/dist/commands/init-command.d.ts +1 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/init-command.js +40 -22
- package/dist/commands/last-log-command.d.ts +1 -1
- package/dist/commands/last-log-command.d.ts.map +1 -1
- package/dist/commands/last-log-command.js +15 -15
- 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 +35 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -1
- package/dist/commands/list-tools-command.js +61 -21
- package/dist/commands/manager.d.ts +9 -4
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +64 -39
- package/dist/commands/model-command.d.ts.map +1 -1
- package/dist/commands/model-command.js +201 -66
- package/dist/commands/paste-command.d.ts +1 -1
- package/dist/commands/paste-command.d.ts.map +1 -1
- package/dist/commands/paste-command.js +23 -9
- 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 +109 -0
- package/dist/commands/prompt-command.d.ts +19 -1
- package/dist/commands/prompt-command.d.ts.map +1 -1
- package/dist/commands/prompt-command.js +191 -98
- 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 +55 -0
- package/dist/commands/reset-command.d.ts +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/reset-command.js +8 -5
- package/dist/commands/rules-command.d.ts +1 -1
- package/dist/commands/rules-command.d.ts.map +1 -1
- package/dist/commands/rules-command.js +25 -22
- package/dist/commands/save-command.d.ts +1 -1
- package/dist/commands/save-command.d.ts.map +1 -1
- package/dist/commands/save-command.js +8 -3
- package/dist/commands/shell-command.d.ts.map +1 -1
- package/dist/commands/shell-command.js +45 -24
- package/dist/commands/types.d.ts +9 -7
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/usage-command.d.ts +1 -1
- package/dist/commands/usage-command.d.ts.map +1 -1
- package/dist/commands/usage-command.js +18 -7
- package/dist/config.d.ts +21 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +90 -63
- package/dist/execution/index.d.ts +17 -2
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +62 -20
- package/dist/formatting.d.ts +127 -0
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +201 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +263 -102
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +47 -18
- package/dist/mentions.d.ts +2 -1
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +16 -1
- package/dist/messages.d.ts +11 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +122 -21
- 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 +1 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +1 -0
- package/dist/models/ai-config.d.ts +4 -2
- package/dist/models/ai-config.d.ts.map +1 -1
- package/dist/models/ai-config.js +12 -2
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/anthropic-provider.js +3 -67
- package/dist/models/deepseek-provider.d.ts.map +1 -1
- package/dist/models/deepseek-provider.js +0 -2
- package/dist/models/google-provider.d.ts.map +1 -1
- package/dist/models/google-provider.js +0 -3
- package/dist/models/groq-provider.d.ts.map +1 -1
- package/dist/models/groq-provider.js +0 -1
- package/dist/models/manager.d.ts +2 -1
- package/dist/models/manager.d.ts.map +1 -1
- package/dist/models/manager.js +26 -2
- package/dist/models/openai-provider.d.ts.map +1 -1
- package/dist/models/openai-provider.js +0 -4
- package/dist/models/openrouter-provider.d.ts +16 -22
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +175 -236
- package/dist/models/providers.d.ts +4 -14
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/models/providers.js +1 -57
- package/dist/models/xai-provider.d.ts.map +1 -1
- package/dist/models/xai-provider.js +0 -2
- package/dist/prompts.d.ts +10 -4
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +447 -70
- package/dist/repl/project-status-line.d.ts +3 -0
- package/dist/repl/project-status-line.d.ts.map +1 -0
- package/dist/repl/project-status-line.js +61 -0
- package/dist/repl/tool-call-repair.d.ts.map +1 -1
- package/dist/repl/tool-call-repair.js +8 -4
- package/dist/repl-new.d.ts +51 -0
- package/dist/repl-new.d.ts.map +1 -0
- package/dist/repl-new.js +354 -0
- package/dist/skills.d.ts +20 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +192 -0
- package/dist/terminal/control.d.ts +55 -0
- package/dist/terminal/control.d.ts.map +1 -0
- package/dist/terminal/control.js +109 -0
- package/dist/terminal/default-theme.d.ts +1 -1
- package/dist/terminal/default-theme.d.ts.map +1 -1
- package/dist/terminal/default-theme.js +24 -28
- package/dist/terminal/formatting.d.ts +23 -25
- package/dist/terminal/formatting.d.ts.map +1 -1
- package/dist/terminal/formatting.js +35 -52
- package/dist/terminal/highlight/index.d.ts.map +1 -1
- package/dist/terminal/highlight/index.js +3 -6
- package/dist/terminal/highlight/theme.d.ts.map +1 -1
- package/dist/terminal/highlight/theme.js +2 -6
- package/dist/terminal/index.d.ts +2 -94
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +2 -370
- package/dist/terminal/markdown.js +10 -5
- package/dist/terminal/select-prompt.d.ts +2 -2
- package/dist/terminal/select-prompt.d.ts.map +1 -1
- package/dist/terminal/select-prompt.js +47 -39
- package/dist/terminal/strip-ansi.js +4 -4
- package/dist/terminal/table/cell.d.ts +114 -0
- package/dist/terminal/table/cell.d.ts.map +1 -0
- package/dist/terminal/table/cell.js +407 -0
- package/dist/terminal/table/debug.d.ts +15 -0
- package/dist/terminal/table/debug.d.ts.map +1 -0
- package/dist/terminal/table/debug.js +32 -0
- package/dist/terminal/table/index.d.ts +3 -0
- package/dist/terminal/table/index.d.ts.map +1 -0
- package/dist/terminal/table/index.js +2 -0
- package/dist/terminal/table/layout-manager.d.ts +27 -0
- package/dist/terminal/table/layout-manager.d.ts.map +1 -0
- package/dist/terminal/table/layout-manager.js +257 -0
- package/dist/terminal/table/table.d.ts +9 -0
- package/dist/terminal/table/table.d.ts.map +1 -0
- package/dist/terminal/table/table.js +97 -0
- package/dist/terminal/table/utils.d.ts +63 -0
- package/dist/terminal/table/utils.d.ts.map +1 -0
- package/dist/terminal/table/utils.js +326 -0
- package/dist/tokens/threshold.d.ts +20 -0
- package/dist/tokens/threshold.d.ts.map +1 -0
- package/dist/tokens/threshold.js +67 -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 +285 -0
- package/dist/tools/agent.d.ts +16 -5
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/agent.js +86 -59
- package/dist/tools/bash.d.ts +23 -12
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +243 -128
- package/dist/tools/batch.d.ts +34 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +174 -0
- package/dist/tools/code-interpreter.d.ts +21 -9
- package/dist/tools/code-interpreter.d.ts.map +1 -1
- package/dist/tools/code-interpreter.js +151 -134
- package/dist/tools/delete-file.d.ts +17 -10
- package/dist/tools/delete-file.d.ts.map +1 -1
- package/dist/tools/delete-file.js +60 -97
- package/dist/tools/directory-tree.d.ts +17 -12
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +57 -48
- package/dist/tools/dynamic-tool-loader.d.ts +16 -10
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +122 -130
- package/dist/tools/dynamic-tool-parser.d.ts +1 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-parser.js +1 -0
- package/dist/tools/edit-file.d.ts +35 -15
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +127 -114
- package/dist/tools/glob.d.ts +36 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +154 -0
- package/dist/tools/grep.d.ts +73 -12
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +425 -165
- package/dist/tools/index.d.ts +220 -126
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +284 -135
- package/dist/tools/llm-edit-fixer.d.ts +24 -0
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -0
- package/dist/tools/llm-edit-fixer.js +136 -0
- package/dist/tools/move-file.d.ts +19 -7
- package/dist/tools/move-file.d.ts.map +1 -1
- package/dist/tools/move-file.js +48 -34
- package/dist/tools/read-file.d.ts +47 -9
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +84 -70
- package/dist/tools/read-multiple-files.d.ts +17 -6
- package/dist/tools/read-multiple-files.d.ts.map +1 -1
- package/dist/tools/read-multiple-files.js +132 -72
- package/dist/tools/save-file.d.ts +45 -12
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +76 -101
- package/dist/tools/think.d.ts +15 -7
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +34 -20
- package/dist/tools/types.d.ts +8 -10
- package/dist/tools/types.d.ts.map +1 -1
- 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 +11 -4
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +39 -38
- package/dist/tools/web-search.d.ts +15 -6
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +64 -31
- 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/box.d.ts +20 -0
- package/dist/tui/components/box.d.ts.map +1 -0
- package/dist/tui/components/box.js +81 -0
- package/dist/tui/components/editor.d.ts +106 -0
- package/dist/tui/components/editor.d.ts.map +1 -0
- package/dist/tui/components/editor.js +1220 -0
- package/dist/tui/components/footer.d.ts +12 -0
- package/dist/tui/components/footer.d.ts.map +1 -0
- package/dist/tui/components/footer.js +209 -0
- package/dist/tui/components/header.d.ts +21 -0
- package/dist/tui/components/header.d.ts.map +1 -0
- package/dist/tui/components/header.js +63 -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 +23 -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 +106 -0
- package/dist/tui/components/markdown.d.ts.map +1 -0
- package/dist/tui/components/markdown.js +586 -0
- package/dist/tui/components/modal.d.ts +29 -0
- package/dist/tui/components/modal.d.ts.map +1 -0
- package/dist/tui/components/modal.js +263 -0
- package/dist/tui/components/progress-bar.d.ts +19 -0
- package/dist/tui/components/progress-bar.d.ts.map +1 -0
- package/dist/tui/components/progress-bar.js +78 -0
- package/dist/tui/components/prompt-status.d.ts +17 -0
- package/dist/tui/components/prompt-status.d.ts.map +1 -0
- package/dist/tui/components/prompt-status.js +26 -0
- package/dist/tui/components/select-list.d.ts +48 -0
- package/dist/tui/components/select-list.d.ts.map +1 -0
- package/dist/tui/components/select-list.js +207 -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/table.d.ts +27 -0
- package/dist/tui/components/table.d.ts.map +1 -0
- package/dist/tui/components/table.js +125 -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 +33 -0
- package/dist/tui/components/tool-execution.d.ts +21 -0
- package/dist/tui/components/tool-execution.d.ts.map +1 -0
- package/dist/tui/components/tool-execution.js +161 -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 +23 -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 +18 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +22 -0
- package/dist/tui/terminal.d.ts +38 -0
- package/dist/tui/terminal.d.ts.map +1 -0
- package/dist/tui/terminal.js +94 -0
- package/dist/tui/tui.d.ts +69 -0
- package/dist/tui/tui.d.ts.map +1 -0
- package/dist/tui/tui.js +204 -0
- package/dist/tui/utils.d.ts +24 -0
- package/dist/tui/utils.d.ts.map +1 -0
- package/dist/tui/utils.js +111 -0
- package/dist/utils/bash.d.ts +7 -0
- package/dist/utils/bash.d.ts.map +1 -0
- package/dist/{tools/bash-utils.js → utils/bash.js} +31 -12
- package/dist/utils/{filesystem.d.ts → filesystem/operations.d.ts} +1 -1
- package/dist/utils/filesystem/operations.d.ts.map +1 -0
- package/dist/utils/filesystem/security.d.ts +9 -0
- package/dist/utils/filesystem/security.d.ts.map +1 -0
- package/dist/{tools/filesystem-utils.js → utils/filesystem/security.js} +93 -21
- package/dist/utils/funcs.d.ts +6 -0
- package/dist/utils/funcs.d.ts.map +1 -0
- package/dist/utils/funcs.js +6 -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/{tools/git-utils.d.ts → utils/git.d.ts} +1 -1
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/{tools/git-utils.js → utils/git.js} +0 -6
- package/dist/utils/glob.js +1 -1
- 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/{zod-utils.d.ts → zod.d.ts} +1 -1
- package/dist/utils/zod.d.ts.map +1 -0
- package/package.json +21 -21
- package/dist/conversation-analyzer.d.ts +0 -11
- package/dist/conversation-analyzer.d.ts.map +0 -1
- package/dist/conversation-analyzer.js +0 -88
- package/dist/repl/display-tool-messages.d.ts +0 -4
- package/dist/repl/display-tool-messages.d.ts.map +0 -1
- package/dist/repl/display-tool-messages.js +0 -55
- package/dist/repl/display-tool-use.d.ts +0 -14
- package/dist/repl/display-tool-use.d.ts.map +0 -1
- package/dist/repl/display-tool-use.js +0 -63
- package/dist/repl/get-prompt-header.d.ts +0 -8
- package/dist/repl/get-prompt-header.d.ts.map +0 -1
- package/dist/repl/get-prompt-header.js +0 -38
- package/dist/repl-prompt.d.ts +0 -15
- package/dist/repl-prompt.d.ts.map +0 -1
- package/dist/repl-prompt.js +0 -147
- package/dist/repl.d.ts +0 -31
- package/dist/repl.d.ts.map +0 -1
- package/dist/repl.js +0 -310
- package/dist/terminal/checkbox-prompt.d.ts +0 -36
- package/dist/terminal/checkbox-prompt.d.ts.map +0 -1
- package/dist/terminal/checkbox-prompt.js +0 -362
- package/dist/terminal/editor-prompt.d.ts +0 -10
- package/dist/terminal/editor-prompt.d.ts.map +0 -1
- package/dist/terminal/editor-prompt.js +0 -61
- package/dist/terminal/errors.d.ts +0 -19
- package/dist/terminal/errors.d.ts.map +0 -1
- package/dist/terminal/errors.js +0 -37
- package/dist/terminal/input-prompt.d.ts +0 -16
- package/dist/terminal/input-prompt.d.ts.map +0 -1
- package/dist/terminal/input-prompt.js +0 -181
- package/dist/terminal/search-prompt.d.ts +0 -20
- package/dist/terminal/search-prompt.d.ts.map +0 -1
- package/dist/terminal/search-prompt.js +0 -279
- package/dist/terminal/types.d.ts +0 -35
- package/dist/terminal/types.d.ts.map +0 -1
- package/dist/terminal/types.js +0 -1
- package/dist/tokens/manage-output.d.ts +0 -34
- package/dist/tokens/manage-output.d.ts.map +0 -1
- package/dist/tokens/manage-output.js +0 -44
- package/dist/tool-executor.d.ts +0 -28
- package/dist/tool-executor.d.ts.map +0 -1
- package/dist/tool-executor.js +0 -74
- package/dist/tools/bash-utils.d.ts +0 -7
- package/dist/tools/bash-utils.d.ts.map +0 -1
- package/dist/tools/file-editing-utils.d.ts +0 -2
- package/dist/tools/file-editing-utils.d.ts.map +0 -1
- package/dist/tools/file-editing-utils.js +0 -135
- package/dist/tools/filesystem-utils.d.ts +0 -7
- package/dist/tools/filesystem-utils.d.ts.map +0 -1
- package/dist/tools/git-utils.d.ts.map +0 -1
- package/dist/utils/filesystem.d.ts.map +0 -1
- package/dist/utils/zod-utils.d.ts.map +0 -1
- /package/dist/utils/{filesystem.js → filesystem/operations.js} +0 -0
- /package/dist/utils/{zod-utils.js → zod.js} +0 -0
package/dist/tools/index.js
CHANGED
|
@@ -1,206 +1,355 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { AdvancedEditFileTool, createAdvancedEditFileTool, } from "./advanced-edit-file.js";
|
|
3
|
+
import { AgentTool, createAgentTools } from "./agent.js";
|
|
4
|
+
import { BashTool, createBashTool } from "./bash.js";
|
|
5
|
+
import { BatchTool, createBatchTool } from "./batch.js";
|
|
6
|
+
import { CodeInterpreterTool, createCodeInterpreterTool, } from "./code-interpreter.js";
|
|
7
|
+
import { createDeleteFileTool, DeleteFileTool } from "./delete-file.js";
|
|
8
|
+
import { createDirectoryTreeTool, DirectoryTreeTool, } from "./directory-tree.js";
|
|
6
9
|
import { loadDynamicTools } from "./dynamic-tool-loader.js";
|
|
7
|
-
import { createEditFileTool } from "./edit-file.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (msg) => {
|
|
19
|
-
if (msgStore.has(msg.id)) {
|
|
20
|
-
msgStore.get(msg.id)?.push(msg);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
msgStore.set(msg.id, [msg]);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export async function initTools({ terminal, tokenCounter, events, toolExecutor, }) {
|
|
28
|
-
const sendDataFn = sendDataHandler(events);
|
|
10
|
+
import { createEditFileTool, EditFileTool } from "./edit-file.js";
|
|
11
|
+
import { createGlobTool, GlobTool } from "./glob.js";
|
|
12
|
+
import { createGrepTool, GrepTool } from "./grep.js";
|
|
13
|
+
import { createMoveFileTool, MoveFileTool } from "./move-file.js";
|
|
14
|
+
import { createReadFileTool, ReadFileTool } from "./read-file.js";
|
|
15
|
+
import { createReadMultipleFilesTool, ReadMultipleFilesTool, } from "./read-multiple-files.js";
|
|
16
|
+
import { createSaveFileTool, SaveFileTool } from "./save-file.js";
|
|
17
|
+
import { createThinkTool, ThinkTool } from "./think.js";
|
|
18
|
+
import { createWebFetchTool, WebFetchTool } from "./web-fetch.js";
|
|
19
|
+
import { createWebSearchTool, WebSearchTool } from "./web-search.js";
|
|
20
|
+
export async function initTools({ tokenCounter, workspace, modelManager, tokenTracker, }) {
|
|
29
21
|
const readFileTool = await createReadFileTool({
|
|
30
|
-
workingDir:
|
|
31
|
-
|
|
22
|
+
workingDir: workspace.primaryDir,
|
|
23
|
+
allowedDirs: workspace.allowedDirs,
|
|
32
24
|
tokenCounter,
|
|
33
25
|
});
|
|
34
26
|
const readMultipleFilesTool = await createReadMultipleFilesTool({
|
|
35
|
-
workingDir:
|
|
36
|
-
|
|
27
|
+
workingDir: workspace.primaryDir,
|
|
28
|
+
allowedDirs: workspace.allowedDirs,
|
|
37
29
|
tokenCounter,
|
|
38
30
|
});
|
|
39
31
|
const editFileTool = await createEditFileTool({
|
|
40
|
-
workingDir:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
workingDir: workspace.primaryDir,
|
|
33
|
+
allowedDirs: workspace.allowedDirs,
|
|
34
|
+
modelManager,
|
|
35
|
+
tokenTracker,
|
|
36
|
+
});
|
|
37
|
+
const advancedEditFileTool = await createAdvancedEditFileTool({
|
|
38
|
+
workingDir: workspace.primaryDir,
|
|
39
|
+
allowedDirs: workspace.allowedDirs,
|
|
44
40
|
});
|
|
45
41
|
const saveFileTool = await createSaveFileTool({
|
|
46
|
-
workingDir:
|
|
47
|
-
|
|
48
|
-
terminal,
|
|
49
|
-
toolExecutor,
|
|
42
|
+
workingDir: workspace.primaryDir,
|
|
43
|
+
allowedDirs: workspace.allowedDirs,
|
|
50
44
|
});
|
|
51
45
|
const moveFileTool = await createMoveFileTool({
|
|
52
|
-
workingDir:
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
workingDir: workspace.primaryDir,
|
|
47
|
+
allowedDirs: workspace.allowedDirs,
|
|
48
|
+
});
|
|
49
|
+
const directoryTreeTool = await createDirectoryTreeTool({
|
|
50
|
+
workingDir: workspace.primaryDir,
|
|
51
|
+
allowedDirs: workspace.allowedDirs,
|
|
52
|
+
tokenCounter,
|
|
53
|
+
});
|
|
60
54
|
const deleteFileTool = await createDeleteFileTool({
|
|
61
|
-
workingDir:
|
|
62
|
-
|
|
63
|
-
terminal,
|
|
64
|
-
toolExecutor,
|
|
55
|
+
workingDir: workspace.primaryDir,
|
|
56
|
+
allowedDirs: workspace.allowedDirs,
|
|
65
57
|
});
|
|
66
|
-
const codeInterpreterTool = createCodeInterpreterTool({
|
|
67
|
-
|
|
58
|
+
const codeInterpreterTool = await createCodeInterpreterTool({
|
|
59
|
+
tokenCounter,
|
|
68
60
|
});
|
|
69
|
-
const
|
|
70
|
-
sendData: sendDataFn,
|
|
61
|
+
const globTool = createGlobTool({
|
|
71
62
|
tokenCounter,
|
|
72
63
|
});
|
|
73
|
-
const
|
|
74
|
-
|
|
64
|
+
const grepTool = createGrepTool({
|
|
65
|
+
tokenCounter,
|
|
75
66
|
});
|
|
67
|
+
const thinkTool = createThinkTool();
|
|
76
68
|
const webFetchTool = createWebFetchTool({
|
|
77
|
-
sendData: sendDataFn,
|
|
78
69
|
tokenCounter,
|
|
79
70
|
});
|
|
80
71
|
const webSearchTool = createWebSearchTool({
|
|
81
|
-
sendData: sendDataFn,
|
|
82
72
|
tokenCounter,
|
|
83
73
|
});
|
|
84
74
|
const bashTool = await createBashTool({
|
|
85
|
-
baseDir:
|
|
86
|
-
|
|
75
|
+
baseDir: workspace.primaryDir,
|
|
76
|
+
allowedDirs: workspace.allowedDirs,
|
|
87
77
|
tokenCounter,
|
|
88
|
-
terminal,
|
|
89
|
-
toolExecutor,
|
|
90
78
|
});
|
|
91
79
|
const dynamicTools = await loadDynamicTools({
|
|
92
|
-
baseDir:
|
|
93
|
-
sendData: sendDataFn,
|
|
80
|
+
baseDir: workspace.primaryDir,
|
|
94
81
|
});
|
|
82
|
+
// Build tools object for AI SDK
|
|
95
83
|
const tools = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
84
|
+
[EditFileTool.name]: tool(editFileTool.toolDef),
|
|
85
|
+
[AdvancedEditFileTool.name]: tool(advancedEditFileTool.toolDef),
|
|
86
|
+
[BashTool.name]: tool(bashTool.toolDef),
|
|
87
|
+
[SaveFileTool.name]: tool(saveFileTool.toolDef),
|
|
88
|
+
[DeleteFileTool.name]: tool(deleteFileTool.toolDef),
|
|
89
|
+
[MoveFileTool.name]: tool(moveFileTool.toolDef),
|
|
90
|
+
[ReadFileTool.name]: tool(readFileTool.toolDef),
|
|
91
|
+
[ReadMultipleFilesTool.name]: tool(readMultipleFilesTool.toolDef),
|
|
92
|
+
[GlobTool.name]: tool(globTool.toolDef),
|
|
93
|
+
[GrepTool.name]: tool(grepTool.toolDef),
|
|
94
|
+
[DirectoryTreeTool.name]: tool(directoryTreeTool.toolDef),
|
|
95
|
+
[CodeInterpreterTool.name]: tool(codeInterpreterTool.toolDef),
|
|
96
|
+
[ThinkTool.name]: tool(thinkTool.toolDef),
|
|
97
|
+
[WebFetchTool.name]: tool(webFetchTool.toolDef),
|
|
98
|
+
[WebSearchTool.name]: tool(webSearchTool.toolDef),
|
|
99
|
+
// Add dynamic tools - they already have toolDef structure
|
|
100
|
+
...Object.fromEntries(Object.entries(dynamicTools).map(([name, toolObj]) => [
|
|
101
|
+
name,
|
|
102
|
+
tool(toolObj.toolDef),
|
|
103
|
+
])),
|
|
104
|
+
};
|
|
105
|
+
// Build executors map for manual loop
|
|
106
|
+
const executors = new Map();
|
|
107
|
+
// Add bash tool
|
|
108
|
+
executors.set(BashTool.name, bashTool.execute);
|
|
109
|
+
// Add editFile tool
|
|
110
|
+
executors.set(EditFileTool.name, editFileTool.execute);
|
|
111
|
+
// Add advancedEditFile tool
|
|
112
|
+
executors.set(AdvancedEditFileTool.name, advancedEditFileTool.execute);
|
|
113
|
+
// Add saveFile tool
|
|
114
|
+
executors.set(SaveFileTool.name, saveFileTool.execute);
|
|
115
|
+
// Add deleteFile tool
|
|
116
|
+
executors.set(DeleteFileTool.name, deleteFileTool.execute);
|
|
117
|
+
// Add moveFile tool
|
|
118
|
+
executors.set(MoveFileTool.name, moveFileTool.execute);
|
|
119
|
+
// Add readFile tool
|
|
120
|
+
executors.set(ReadFileTool.name, readFileTool.execute);
|
|
121
|
+
// Add readMultipleFiles tool
|
|
122
|
+
executors.set(ReadMultipleFilesTool.name, readMultipleFilesTool.execute);
|
|
123
|
+
// Add glob tool
|
|
124
|
+
executors.set(GlobTool.name, globTool.execute);
|
|
125
|
+
// Add grep tool
|
|
126
|
+
executors.set(GrepTool.name, grepTool.execute);
|
|
127
|
+
// Add directoryTree tool
|
|
128
|
+
executors.set(DirectoryTreeTool.name, directoryTreeTool.execute);
|
|
129
|
+
// Add webFetch tool
|
|
130
|
+
executors.set(WebFetchTool.name, webFetchTool.execute);
|
|
131
|
+
// Add webSearch tool
|
|
132
|
+
executors.set(WebSearchTool.name, webSearchTool.execute);
|
|
133
|
+
// Add think tool
|
|
134
|
+
executors.set(ThinkTool.name, thinkTool.execute);
|
|
135
|
+
// Add codeInterpreter tool
|
|
136
|
+
executors.set(CodeInterpreterTool.name, codeInterpreterTool.execute);
|
|
137
|
+
// Add dynamic tools to executors
|
|
138
|
+
for (const [name, toolObj] of Object.entries(dynamicTools)) {
|
|
139
|
+
executors.set(name, toolObj.execute);
|
|
140
|
+
}
|
|
141
|
+
// Create batch tool with access to all executors
|
|
142
|
+
const batchTool = await createBatchTool({
|
|
143
|
+
tokenCounter,
|
|
144
|
+
executors,
|
|
145
|
+
});
|
|
146
|
+
// Add batch tool to tools
|
|
147
|
+
const toolsWithBatch = {
|
|
148
|
+
...tools,
|
|
149
|
+
[BatchTool.name]: tool(batchTool.toolDef),
|
|
150
|
+
};
|
|
151
|
+
// Add batch tool to executors
|
|
152
|
+
executors.set(BatchTool.name, batchTool.execute);
|
|
153
|
+
return {
|
|
154
|
+
toolDefs: toolsWithBatch,
|
|
155
|
+
executors,
|
|
110
156
|
};
|
|
111
|
-
return tools;
|
|
112
157
|
}
|
|
113
|
-
export async function initCliTools({ tokenCounter, }) {
|
|
158
|
+
export async function initCliTools({ tokenCounter, workspace, modelManager, tokenTracker, }) {
|
|
114
159
|
const readFileTool = await createReadFileTool({
|
|
115
|
-
workingDir:
|
|
116
|
-
|
|
160
|
+
workingDir: workspace.primaryDir,
|
|
161
|
+
allowedDirs: workspace.allowedDirs,
|
|
117
162
|
tokenCounter,
|
|
118
163
|
});
|
|
119
164
|
const readMultipleFilesTool = await createReadMultipleFilesTool({
|
|
120
|
-
workingDir:
|
|
121
|
-
|
|
165
|
+
workingDir: workspace.primaryDir,
|
|
166
|
+
allowedDirs: workspace.allowedDirs,
|
|
122
167
|
tokenCounter,
|
|
123
168
|
});
|
|
124
169
|
const editFileTool = await createEditFileTool({
|
|
125
|
-
workingDir:
|
|
126
|
-
|
|
127
|
-
|
|
170
|
+
workingDir: workspace.primaryDir,
|
|
171
|
+
allowedDirs: workspace.allowedDirs,
|
|
172
|
+
modelManager,
|
|
173
|
+
tokenTracker,
|
|
174
|
+
});
|
|
175
|
+
const advancedEditFileTool = await createAdvancedEditFileTool({
|
|
176
|
+
workingDir: workspace.primaryDir,
|
|
177
|
+
allowedDirs: workspace.allowedDirs,
|
|
128
178
|
});
|
|
129
179
|
const saveFileTool = await createSaveFileTool({
|
|
130
|
-
workingDir:
|
|
131
|
-
|
|
132
|
-
terminal: undefined,
|
|
180
|
+
workingDir: workspace.primaryDir,
|
|
181
|
+
allowedDirs: workspace.allowedDirs,
|
|
133
182
|
});
|
|
134
183
|
const moveFileTool = await createMoveFileTool({
|
|
135
|
-
workingDir:
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
184
|
+
workingDir: workspace.primaryDir,
|
|
185
|
+
allowedDirs: workspace.allowedDirs,
|
|
186
|
+
});
|
|
187
|
+
const directoryTreeTool = await createDirectoryTreeTool({
|
|
188
|
+
workingDir: workspace.primaryDir,
|
|
189
|
+
allowedDirs: workspace.allowedDirs,
|
|
190
|
+
tokenCounter,
|
|
191
|
+
});
|
|
143
192
|
const deleteFileTool = await createDeleteFileTool({
|
|
144
|
-
workingDir:
|
|
145
|
-
|
|
146
|
-
terminal: undefined,
|
|
193
|
+
workingDir: workspace.primaryDir,
|
|
194
|
+
allowedDirs: workspace.allowedDirs,
|
|
147
195
|
});
|
|
148
|
-
const codeInterpreterTool = createCodeInterpreterTool({
|
|
149
|
-
|
|
196
|
+
const codeInterpreterTool = await createCodeInterpreterTool({
|
|
197
|
+
tokenCounter,
|
|
150
198
|
});
|
|
151
|
-
const
|
|
152
|
-
sendData: undefined,
|
|
199
|
+
const globTool = createGlobTool({
|
|
153
200
|
tokenCounter,
|
|
154
201
|
});
|
|
155
|
-
const
|
|
156
|
-
|
|
202
|
+
const grepTool = createGrepTool({
|
|
203
|
+
tokenCounter,
|
|
157
204
|
});
|
|
205
|
+
const thinkTool = createThinkTool();
|
|
158
206
|
const webFetchTool = createWebFetchTool({
|
|
159
|
-
sendData: undefined,
|
|
160
207
|
tokenCounter,
|
|
161
208
|
});
|
|
162
209
|
const webSearchTool = createWebSearchTool({
|
|
163
|
-
sendData: undefined,
|
|
164
210
|
tokenCounter,
|
|
165
211
|
});
|
|
166
212
|
const bashTool = await createBashTool({
|
|
167
|
-
baseDir:
|
|
168
|
-
|
|
213
|
+
baseDir: workspace.primaryDir,
|
|
214
|
+
allowedDirs: workspace.allowedDirs,
|
|
169
215
|
tokenCounter,
|
|
170
|
-
terminal: undefined,
|
|
171
216
|
});
|
|
172
217
|
const dynamicTools = await loadDynamicTools({
|
|
173
|
-
baseDir:
|
|
174
|
-
|
|
218
|
+
baseDir: workspace.primaryDir,
|
|
219
|
+
});
|
|
220
|
+
// Build executors map for batch tool
|
|
221
|
+
const executors = new Map();
|
|
222
|
+
executors.set(EditFileTool.name, editFileTool.execute);
|
|
223
|
+
executors.set(AdvancedEditFileTool.name, advancedEditFileTool.execute);
|
|
224
|
+
executors.set(BashTool.name, bashTool.execute);
|
|
225
|
+
executors.set(SaveFileTool.name, saveFileTool.execute);
|
|
226
|
+
executors.set(DeleteFileTool.name, deleteFileTool.execute);
|
|
227
|
+
executors.set(MoveFileTool.name, moveFileTool.execute);
|
|
228
|
+
executors.set(ReadFileTool.name, readFileTool.execute);
|
|
229
|
+
executors.set(ReadMultipleFilesTool.name, readMultipleFilesTool.execute);
|
|
230
|
+
executors.set(GlobTool.name, globTool.execute);
|
|
231
|
+
executors.set(GrepTool.name, grepTool.execute);
|
|
232
|
+
executors.set(DirectoryTreeTool.name, directoryTreeTool.execute);
|
|
233
|
+
executors.set(CodeInterpreterTool.name, codeInterpreterTool.execute);
|
|
234
|
+
executors.set(ThinkTool.name, thinkTool.execute);
|
|
235
|
+
executors.set(WebFetchTool.name, webFetchTool.execute);
|
|
236
|
+
executors.set(WebSearchTool.name, webSearchTool.execute);
|
|
237
|
+
for (const [name, toolObj] of Object.entries(dynamicTools)) {
|
|
238
|
+
executors.set(name, toolObj.execute);
|
|
239
|
+
}
|
|
240
|
+
// Create batch tool with access to all executors
|
|
241
|
+
const batchTool = await createBatchTool({
|
|
242
|
+
tokenCounter,
|
|
243
|
+
executors,
|
|
244
|
+
});
|
|
245
|
+
const tools = {
|
|
246
|
+
[EditFileTool.name]: tool({
|
|
247
|
+
...editFileTool.toolDef,
|
|
248
|
+
execute: editFileTool.execute,
|
|
249
|
+
}),
|
|
250
|
+
[AdvancedEditFileTool.name]: tool({
|
|
251
|
+
...advancedEditFileTool.toolDef,
|
|
252
|
+
execute: advancedEditFileTool.execute,
|
|
253
|
+
}),
|
|
254
|
+
[BashTool.name]: tool({
|
|
255
|
+
...bashTool.toolDef,
|
|
256
|
+
execute: bashTool.execute,
|
|
257
|
+
}),
|
|
258
|
+
[SaveFileTool.name]: tool({
|
|
259
|
+
...saveFileTool.toolDef,
|
|
260
|
+
execute: saveFileTool.execute,
|
|
261
|
+
}),
|
|
262
|
+
[DeleteFileTool.name]: tool({
|
|
263
|
+
...deleteFileTool.toolDef,
|
|
264
|
+
execute: deleteFileTool.execute,
|
|
265
|
+
}),
|
|
266
|
+
[MoveFileTool.name]: tool({
|
|
267
|
+
...moveFileTool.toolDef,
|
|
268
|
+
execute: moveFileTool.execute,
|
|
269
|
+
}),
|
|
270
|
+
[ReadFileTool.name]: tool({
|
|
271
|
+
...readFileTool.toolDef,
|
|
272
|
+
execute: readFileTool.execute,
|
|
273
|
+
}),
|
|
274
|
+
[ReadMultipleFilesTool.name]: tool({
|
|
275
|
+
...readMultipleFilesTool.toolDef,
|
|
276
|
+
execute: readMultipleFilesTool.execute,
|
|
277
|
+
}),
|
|
278
|
+
[GlobTool.name]: tool({
|
|
279
|
+
...globTool.toolDef,
|
|
280
|
+
execute: globTool.execute,
|
|
281
|
+
}),
|
|
282
|
+
[GrepTool.name]: tool({
|
|
283
|
+
...grepTool.toolDef,
|
|
284
|
+
execute: grepTool.execute,
|
|
285
|
+
}),
|
|
286
|
+
[DirectoryTreeTool.name]: tool({
|
|
287
|
+
...directoryTreeTool.toolDef,
|
|
288
|
+
execute: directoryTreeTool.execute,
|
|
289
|
+
}),
|
|
290
|
+
[CodeInterpreterTool.name]: tool({
|
|
291
|
+
...codeInterpreterTool.toolDef,
|
|
292
|
+
execute: codeInterpreterTool.execute,
|
|
293
|
+
}),
|
|
294
|
+
[ThinkTool.name]: tool({
|
|
295
|
+
...thinkTool.toolDef,
|
|
296
|
+
execute: thinkTool.execute,
|
|
297
|
+
}),
|
|
298
|
+
[WebFetchTool.name]: tool({
|
|
299
|
+
...webFetchTool.toolDef,
|
|
300
|
+
execute: webFetchTool.execute,
|
|
301
|
+
}),
|
|
302
|
+
[WebSearchTool.name]: tool({
|
|
303
|
+
...webSearchTool.toolDef,
|
|
304
|
+
execute: webSearchTool.execute,
|
|
305
|
+
}),
|
|
306
|
+
[BatchTool.name]: tool({
|
|
307
|
+
...batchTool.toolDef,
|
|
308
|
+
execute: batchTool.execute,
|
|
309
|
+
}),
|
|
310
|
+
// Add dynamic tools with execute functions
|
|
311
|
+
...Object.fromEntries(Object.entries(dynamicTools).map(([name, toolObj]) => [
|
|
312
|
+
name,
|
|
313
|
+
tool({
|
|
314
|
+
...toolObj.toolDef,
|
|
315
|
+
execute: toolObj.execute,
|
|
316
|
+
}),
|
|
317
|
+
])),
|
|
318
|
+
};
|
|
319
|
+
return {
|
|
320
|
+
toolDefs: tools,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
export async function initAgents({ modelManager, tokenTracker, tokenCounter, workspace, }) {
|
|
324
|
+
const agentTools = createAgentTools({
|
|
325
|
+
modelManager,
|
|
326
|
+
tokenTracker,
|
|
327
|
+
tokenCounter,
|
|
328
|
+
workspace,
|
|
175
329
|
});
|
|
176
330
|
const tools = {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
...grepTool,
|
|
186
|
-
...thinkTool,
|
|
187
|
-
...webFetchTool,
|
|
188
|
-
...bashTool,
|
|
189
|
-
...webSearchTool,
|
|
190
|
-
...dynamicTools,
|
|
331
|
+
[AgentTool.name]: tool(agentTools.toolDef),
|
|
332
|
+
};
|
|
333
|
+
// Build executors map for manual loop
|
|
334
|
+
const executors = new Map();
|
|
335
|
+
executors.set(AgentTool.name, agentTools.execute);
|
|
336
|
+
return {
|
|
337
|
+
toolDefs: tools,
|
|
338
|
+
executors,
|
|
191
339
|
};
|
|
192
|
-
return tools;
|
|
193
340
|
}
|
|
194
|
-
export async function
|
|
195
|
-
const sendDataFn = sendDataHandler(events);
|
|
341
|
+
export async function initCliAgents({ modelManager, tokenTracker, tokenCounter, workspace, }) {
|
|
196
342
|
const agentTools = createAgentTools({
|
|
197
343
|
modelManager,
|
|
198
344
|
tokenTracker,
|
|
199
345
|
tokenCounter,
|
|
200
|
-
|
|
346
|
+
workspace,
|
|
201
347
|
});
|
|
202
348
|
const tools = {
|
|
203
|
-
|
|
349
|
+
[AgentTool.name]: tool({
|
|
350
|
+
...agentTools.toolDef,
|
|
351
|
+
execute: agentTools.execute,
|
|
352
|
+
}),
|
|
204
353
|
};
|
|
205
|
-
return tools;
|
|
354
|
+
return { toolDefs: tools };
|
|
206
355
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ModelManager } from "../models/manager.ts";
|
|
3
|
+
declare const SearchReplaceEditSchema: z.ZodObject<{
|
|
4
|
+
search: z.ZodString;
|
|
5
|
+
replace: z.ZodString;
|
|
6
|
+
noChangesRequired: z.ZodBoolean;
|
|
7
|
+
explanation: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type SearchReplaceEdit = z.infer<typeof SearchReplaceEditSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to fix a failed edit by using an LLM to generate a new search and replace pair.
|
|
12
|
+
*
|
|
13
|
+
* @param instruction The instruction for what needs to be done. If not provided, will auto-generate from oldString/newString
|
|
14
|
+
* @param oldString The original string to be replaced
|
|
15
|
+
* @param newString The original replacement string
|
|
16
|
+
* @param error The error that occurred during the initial edit
|
|
17
|
+
* @param currentContent The current content of the file
|
|
18
|
+
* @param modelManager The model manager for accessing LLM models
|
|
19
|
+
* @param abortSignal An abort signal to cancel the operation
|
|
20
|
+
* @returns A corrected search and replace pair, or null if fixing failed
|
|
21
|
+
*/
|
|
22
|
+
export declare function fixLlmEditWithInstruction(instruction: string | undefined, oldString: string, newString: string, error: string, currentContent: string, modelManager: ModelManager | undefined, abortSignal?: AbortSignal): Promise<SearchReplaceEdit | null>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=llm-edit-fixer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-edit-fixer.d.ts","sourceRoot":"","sources":["../../source/tools/llm-edit-fixer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAyDzD,QAAA,MAAM,uBAAuB;;;;;iBAK3B,CAAC;AAEH,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAiEjE;;;;;;;;;;;GAWG;AACH,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CA2BnC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { generateObject } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { logger } from "../logger.js";
|
|
4
|
+
const GENERATE_JSON_TIMEOUT_MS = 40000; // 40 seconds
|
|
5
|
+
const EDIT_SYS_PROMPT = `
|
|
6
|
+
You are an expert code-editing assistant specializing in debugging and correcting failed search-and-replace operations.
|
|
7
|
+
|
|
8
|
+
# Primary Goal
|
|
9
|
+
Your task is to analyze a failed edit attempt and provide a corrected \`search\` string that will match the text in the file precisely. The correction should be as minimal as possible, staying very close to the original, failed \`search\` string. Do NOT invent a completely new edit based on the instruction; your job is to fix the provided parameters.
|
|
10
|
+
|
|
11
|
+
It is important that you do no try to figure out if the instruction is correct. DO NOT GIVE ADVICE. Your only goal here is to do your best to perform the search and replace task!
|
|
12
|
+
|
|
13
|
+
# Input Context
|
|
14
|
+
You will be given:
|
|
15
|
+
1. The high-level instruction for the original edit.
|
|
16
|
+
2. The exact \`search\` and \`replace\` strings that failed.
|
|
17
|
+
3. The error message that was produced.
|
|
18
|
+
4. The full content of the latest version of the source file.
|
|
19
|
+
|
|
20
|
+
# Rules for Correction
|
|
21
|
+
1. **Minimal Correction:** Your new \`search\` string must be a close variation of the original. Focus on fixing issues like whitespace, indentation, line endings, or small contextual differences.
|
|
22
|
+
2. **Explain the Fix:** Your \`explanation\` MUST state exactly why the original \`search\` failed and how your new \`search\` string resolves that specific failure. (e.g., "The original search failed due to incorrect indentation; the new search corrects the indentation to match the source file.").
|
|
23
|
+
3. **Preserve the \`replace\` String:** Do NOT modify the \`replace\` string unless the instruction explicitly requires it and it was the source of the error. Do not escape any characters in \`replace\`. Your primary focus is fixing the \`search\` string.
|
|
24
|
+
4. **No Changes Case:** CRUCIAL: if the change is already present in the file, set \`noChangesRequired\` to True and explain why in the \`explanation\`. It is crucial that you only do this if the changes outline in \`replace\` are already in the file and suits the instruction.
|
|
25
|
+
5. **Exactness:** The final \`search\` field must be the EXACT literal text from the file. Do not escape characters.
|
|
26
|
+
`;
|
|
27
|
+
const EDIT_USER_PROMPT = `
|
|
28
|
+
# Goal of the Original Edit
|
|
29
|
+
<instruction>
|
|
30
|
+
{instruction}
|
|
31
|
+
</instruction>
|
|
32
|
+
|
|
33
|
+
# Failed Attempt Details
|
|
34
|
+
- **Original \`search\` parameter (failed):**
|
|
35
|
+
<search>
|
|
36
|
+
{old_string}
|
|
37
|
+
</search>
|
|
38
|
+
- **Original \`replace\` parameter:**
|
|
39
|
+
<replace>
|
|
40
|
+
{new_string}
|
|
41
|
+
</replace>
|
|
42
|
+
- **Error Encountered:**
|
|
43
|
+
<error>
|
|
44
|
+
{error}
|
|
45
|
+
</error>
|
|
46
|
+
|
|
47
|
+
# Full File Content
|
|
48
|
+
<file_content>
|
|
49
|
+
{current_content}
|
|
50
|
+
</file_content>
|
|
51
|
+
|
|
52
|
+
# Your Task
|
|
53
|
+
Based on the error and the file content, provide a corrected \`search\` string that will succeed. Remember to keep your correction minimal and explain the precise reason for the failure in your \`explanation\`.
|
|
54
|
+
`;
|
|
55
|
+
// Zod schema for the LLM response
|
|
56
|
+
const SearchReplaceEditSchema = z.object({
|
|
57
|
+
search: z.string(),
|
|
58
|
+
replace: z.string(),
|
|
59
|
+
noChangesRequired: z.boolean(),
|
|
60
|
+
explanation: z.string(),
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Auto-generates an instruction based on edit parameters when none is provided
|
|
64
|
+
*/
|
|
65
|
+
function autoGenerateInstruction(oldString, newString) {
|
|
66
|
+
// Create a natural language description of the edit intent
|
|
67
|
+
const oldPreview = oldString.length > 50 ? `${oldString.slice(0, 47)}...` : oldString;
|
|
68
|
+
const newPreview = newString.length > 50 ? `${newString.slice(0, 47)}...` : newString;
|
|
69
|
+
return `Replace "${oldPreview}" with "${newPreview}"`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generates structured JSON with timeout and proper error handling
|
|
73
|
+
*/
|
|
74
|
+
async function generateStructuredEditFix(modelManager, params, timeoutMs) {
|
|
75
|
+
try {
|
|
76
|
+
const controller = new AbortController();
|
|
77
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
78
|
+
// Combine abort signals
|
|
79
|
+
const combinedSignal = AbortSignal.any([
|
|
80
|
+
params.abortSignal ?? new AbortController().signal,
|
|
81
|
+
timeoutSignal,
|
|
82
|
+
controller.signal,
|
|
83
|
+
]);
|
|
84
|
+
if (!modelManager) {
|
|
85
|
+
throw new Error("Edit-fix model not available");
|
|
86
|
+
}
|
|
87
|
+
const { object } = await generateObject({
|
|
88
|
+
model: modelManager.getModel("edit-fix"),
|
|
89
|
+
schema: SearchReplaceEditSchema,
|
|
90
|
+
system: params.system,
|
|
91
|
+
prompt: params.prompt,
|
|
92
|
+
abortSignal: combinedSignal,
|
|
93
|
+
});
|
|
94
|
+
logger.info(object, "LLM edit fix successful.");
|
|
95
|
+
return object;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
99
|
+
logger.warn(`LLM edit fix operation timed out. Timeout: ${timeoutMs}ms`);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
logger.error(`LLM edit fix operation failed. Error: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Attempts to fix a failed edit by using an LLM to generate a new search and replace pair.
|
|
108
|
+
*
|
|
109
|
+
* @param instruction The instruction for what needs to be done. If not provided, will auto-generate from oldString/newString
|
|
110
|
+
* @param oldString The original string to be replaced
|
|
111
|
+
* @param newString The original replacement string
|
|
112
|
+
* @param error The error that occurred during the initial edit
|
|
113
|
+
* @param currentContent The current content of the file
|
|
114
|
+
* @param modelManager The model manager for accessing LLM models
|
|
115
|
+
* @param abortSignal An abort signal to cancel the operation
|
|
116
|
+
* @returns A corrected search and replace pair, or null if fixing failed
|
|
117
|
+
*/
|
|
118
|
+
export async function fixLlmEditWithInstruction(instruction, oldString, newString, error, currentContent, modelManager, abortSignal) {
|
|
119
|
+
// If no modelManager is available, return null (LLM fix not available)
|
|
120
|
+
if (!modelManager) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
const finalInstruction = instruction || autoGenerateInstruction(oldString, newString);
|
|
124
|
+
// Generate the user prompt with substitutions
|
|
125
|
+
const userPrompt = EDIT_USER_PROMPT.replace("{instruction}", finalInstruction)
|
|
126
|
+
.replace("{old_string}", oldString)
|
|
127
|
+
.replace("{new_string}", newString)
|
|
128
|
+
.replace("{error}", error)
|
|
129
|
+
.replace("{current_content}", currentContent);
|
|
130
|
+
const result = await generateStructuredEditFix(modelManager, {
|
|
131
|
+
system: EDIT_SYS_PROMPT,
|
|
132
|
+
prompt: userPrompt,
|
|
133
|
+
abortSignal,
|
|
134
|
+
}, GENERATE_JSON_TIMEOUT_MS);
|
|
135
|
+
return result;
|
|
136
|
+
}
|