@vybestack/llxprt-code-tools 0.10.0-nightly.260613.1adad3b34
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/LICENSE +202 -0
- package/README.md +294 -0
- package/dist/.last_build +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.d.ts +29 -0
- package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.js +30 -0
- package/dist/src/__tests__/fixtures/filesystem-tool-fixtures.js.map +1 -0
- package/dist/src/__tests__/fixtures/key-storage-fixtures.d.ts +39 -0
- package/dist/src/__tests__/fixtures/key-storage-fixtures.js +53 -0
- package/dist/src/__tests__/fixtures/key-storage-fixtures.js.map +1 -0
- package/dist/src/__tests__/fixtures/provider-formatting-fixtures.d.ts +140 -0
- package/dist/src/__tests__/fixtures/provider-formatting-fixtures.js +157 -0
- package/dist/src/__tests__/fixtures/provider-formatting-fixtures.js.map +1 -0
- package/dist/src/__tests__/red-test-helpers.d.ts +14 -0
- package/dist/src/__tests__/red-test-helpers.js +18 -0
- package/dist/src/__tests__/red-test-helpers.js.map +1 -0
- package/dist/src/formatters/IToolFormatter.d.ts +84 -0
- package/dist/src/formatters/IToolFormatter.js +6 -0
- package/dist/src/formatters/IToolFormatter.js.map +1 -0
- package/dist/src/formatters/ToolFormatter.d.ts +94 -0
- package/dist/src/formatters/ToolFormatter.js +379 -0
- package/dist/src/formatters/ToolFormatter.js.map +1 -0
- package/dist/src/formatters/ToolIdStrategy.d.ts +79 -0
- package/dist/src/formatters/ToolIdStrategy.js +173 -0
- package/dist/src/formatters/ToolIdStrategy.js.map +1 -0
- package/dist/src/formatters/doubleEscapeUtils.d.ts +46 -0
- package/dist/src/formatters/doubleEscapeUtils.js +223 -0
- package/dist/src/formatters/doubleEscapeUtils.js.map +1 -0
- package/dist/src/formatters/index.d.ts +21 -0
- package/dist/src/formatters/index.js +12 -0
- package/dist/src/formatters/index.js.map +1 -0
- package/dist/src/formatters/toolIdNormalization.d.ts +28 -0
- package/dist/src/formatters/toolIdNormalization.js +97 -0
- package/dist/src/formatters/toolIdNormalization.js.map +1 -0
- package/dist/src/formatters/toolNameUtils.d.ts +43 -0
- package/dist/src/formatters/toolNameUtils.js +143 -0
- package/dist/src/formatters/toolNameUtils.js.map +1 -0
- package/dist/src/index.d.ts +88 -0
- package/dist/src/index.js +68 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/IAsyncTaskService.d.ts +57 -0
- package/dist/src/interfaces/IAsyncTaskService.js +6 -0
- package/dist/src/interfaces/IAsyncTaskService.js.map +1 -0
- package/dist/src/interfaces/IIdeService.d.ts +62 -0
- package/dist/src/interfaces/IIdeService.js +6 -0
- package/dist/src/interfaces/IIdeService.js.map +1 -0
- package/dist/src/interfaces/ILspService.d.ts +54 -0
- package/dist/src/interfaces/ILspService.js +6 -0
- package/dist/src/interfaces/ILspService.js.map +1 -0
- package/dist/src/interfaces/IMcpToolService.d.ts +47 -0
- package/dist/src/interfaces/IMcpToolService.js +6 -0
- package/dist/src/interfaces/IMcpToolService.js.map +1 -0
- package/dist/src/interfaces/IPromptRegistryService.d.ts +51 -0
- package/dist/src/interfaces/IPromptRegistryService.js +6 -0
- package/dist/src/interfaces/IPromptRegistryService.js.map +1 -0
- package/dist/src/interfaces/ISettingsService.d.ts +50 -0
- package/dist/src/interfaces/ISettingsService.js +6 -0
- package/dist/src/interfaces/ISettingsService.js.map +1 -0
- package/dist/src/interfaces/IShellExecutionService.d.ts +55 -0
- package/dist/src/interfaces/IShellExecutionService.js +6 -0
- package/dist/src/interfaces/IShellExecutionService.js.map +1 -0
- package/dist/src/interfaces/IShellToolHost.d.ts +176 -0
- package/dist/src/interfaces/IShellToolHost.js +6 -0
- package/dist/src/interfaces/IShellToolHost.js.map +1 -0
- package/dist/src/interfaces/ISkillService.d.ts +69 -0
- package/dist/src/interfaces/ISkillService.js +6 -0
- package/dist/src/interfaces/ISkillService.js.map +1 -0
- package/dist/src/interfaces/IStorageService.d.ts +42 -0
- package/dist/src/interfaces/IStorageService.js +6 -0
- package/dist/src/interfaces/IStorageService.js.map +1 -0
- package/dist/src/interfaces/ISubagentService.d.ts +112 -0
- package/dist/src/interfaces/ISubagentService.js +6 -0
- package/dist/src/interfaces/ISubagentService.js.map +1 -0
- package/dist/src/interfaces/ITaskToolHost.d.ts +185 -0
- package/dist/src/interfaces/ITaskToolHost.js +6 -0
- package/dist/src/interfaces/ITaskToolHost.js.map +1 -0
- package/dist/src/interfaces/ITodoService.d.ts +79 -0
- package/dist/src/interfaces/ITodoService.js +6 -0
- package/dist/src/interfaces/ITodoService.js.map +1 -0
- package/dist/src/interfaces/IToolHost.d.ts +91 -0
- package/dist/src/interfaces/IToolHost.js +6 -0
- package/dist/src/interfaces/IToolHost.js.map +1 -0
- package/dist/src/interfaces/IToolKeyStorage.d.ts +62 -0
- package/dist/src/interfaces/IToolKeyStorage.js +6 -0
- package/dist/src/interfaces/IToolKeyStorage.js.map +1 -0
- package/dist/src/interfaces/IToolMessageBus.d.ts +63 -0
- package/dist/src/interfaces/IToolMessageBus.js +6 -0
- package/dist/src/interfaces/IToolMessageBus.js.map +1 -0
- package/dist/src/interfaces/IToolRegistryHost.d.ts +43 -0
- package/dist/src/interfaces/IToolRegistryHost.js +6 -0
- package/dist/src/interfaces/IToolRegistryHost.js.map +1 -0
- package/dist/src/interfaces/IWebSearchService.d.ts +16 -0
- package/dist/src/interfaces/IWebSearchService.js +7 -0
- package/dist/src/interfaces/IWebSearchService.js.map +1 -0
- package/dist/src/interfaces/index.d.ts +33 -0
- package/dist/src/interfaces/index.js +6 -0
- package/dist/src/interfaces/index.js.map +1 -0
- package/dist/src/tools/activate-skill.d.ts +26 -0
- package/dist/src/tools/activate-skill.js +121 -0
- package/dist/src/tools/activate-skill.js.map +1 -0
- package/dist/src/tools/apply-patch.d.ts +65 -0
- package/dist/src/tools/apply-patch.js +528 -0
- package/dist/src/tools/apply-patch.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-config.d.ts +67 -0
- package/dist/src/tools/ast-edit/ast-config.js +72 -0
- package/dist/src/tools/ast-edit/ast-config.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-edit-invocation.d.ts +40 -0
- package/dist/src/tools/ast-edit/ast-edit-invocation.js +410 -0
- package/dist/src/tools/ast-edit/ast-edit-invocation.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-query-extractor.d.ts +21 -0
- package/dist/src/tools/ast-edit/ast-query-extractor.js +178 -0
- package/dist/src/tools/ast-edit/ast-query-extractor.js.map +1 -0
- package/dist/src/tools/ast-edit/ast-read-file-invocation.d.ts +26 -0
- package/dist/src/tools/ast-edit/ast-read-file-invocation.js +149 -0
- package/dist/src/tools/ast-edit/ast-read-file-invocation.js.map +1 -0
- package/dist/src/tools/ast-edit/constants.d.ts +30 -0
- package/dist/src/tools/ast-edit/constants.js +36 -0
- package/dist/src/tools/ast-edit/constants.js.map +1 -0
- package/dist/src/tools/ast-edit/context-collector.d.ts +25 -0
- package/dist/src/tools/ast-edit/context-collector.js +115 -0
- package/dist/src/tools/ast-edit/context-collector.js.map +1 -0
- package/dist/src/tools/ast-edit/context-optimizer.d.ts +29 -0
- package/dist/src/tools/ast-edit/context-optimizer.js +86 -0
- package/dist/src/tools/ast-edit/context-optimizer.js.map +1 -0
- package/dist/src/tools/ast-edit/cross-file-analyzer.d.ts +41 -0
- package/dist/src/tools/ast-edit/cross-file-analyzer.js +294 -0
- package/dist/src/tools/ast-edit/cross-file-analyzer.js.map +1 -0
- package/dist/src/tools/ast-edit/edit-calculator.d.ts +71 -0
- package/dist/src/tools/ast-edit/edit-calculator.js +249 -0
- package/dist/src/tools/ast-edit/edit-calculator.js.map +1 -0
- package/dist/src/tools/ast-edit/edit-helpers.d.ts +22 -0
- package/dist/src/tools/ast-edit/edit-helpers.js +36 -0
- package/dist/src/tools/ast-edit/edit-helpers.js.map +1 -0
- package/dist/src/tools/ast-edit/language-analysis.d.ts +19 -0
- package/dist/src/tools/ast-edit/language-analysis.js +123 -0
- package/dist/src/tools/ast-edit/language-analysis.js.map +1 -0
- package/dist/src/tools/ast-edit/local-context-analyzer.d.ts +84 -0
- package/dist/src/tools/ast-edit/local-context-analyzer.js +267 -0
- package/dist/src/tools/ast-edit/local-context-analyzer.js.map +1 -0
- package/dist/src/tools/ast-edit/repository-context-provider.d.ts +22 -0
- package/dist/src/tools/ast-edit/repository-context-provider.js +139 -0
- package/dist/src/tools/ast-edit/repository-context-provider.js.map +1 -0
- package/dist/src/tools/ast-edit/types.d.ts +155 -0
- package/dist/src/tools/ast-edit/types.js +7 -0
- package/dist/src/tools/ast-edit/types.js.map +1 -0
- package/dist/src/tools/ast-edit/workspace-context-provider.d.ts +22 -0
- package/dist/src/tools/ast-edit/workspace-context-provider.js +39 -0
- package/dist/src/tools/ast-edit/workspace-context-provider.js.map +1 -0
- package/dist/src/tools/ast-edit.d.ts +43 -0
- package/dist/src/tools/ast-edit.js +183 -0
- package/dist/src/tools/ast-edit.js.map +1 -0
- package/dist/src/tools/ast-grep.d.ts +22 -0
- package/dist/src/tools/ast-grep.js +291 -0
- package/dist/src/tools/ast-grep.js.map +1 -0
- package/dist/src/tools/check-async-tasks.d.ts +46 -0
- package/dist/src/tools/check-async-tasks.js +241 -0
- package/dist/src/tools/check-async-tasks.js.map +1 -0
- package/dist/src/tools/codesearch.d.ts +25 -0
- package/dist/src/tools/codesearch.js +153 -0
- package/dist/src/tools/codesearch.js.map +1 -0
- package/dist/src/tools/delete_line_range.d.ts +41 -0
- package/dist/src/tools/delete_line_range.js +238 -0
- package/dist/src/tools/delete_line_range.js.map +1 -0
- package/dist/src/tools/direct-web-fetch.d.ts +22 -0
- package/dist/src/tools/direct-web-fetch.js +215 -0
- package/dist/src/tools/direct-web-fetch.js.map +1 -0
- package/dist/src/tools/edit-utils.d.ts +53 -0
- package/dist/src/tools/edit-utils.js +250 -0
- package/dist/src/tools/edit-utils.js.map +1 -0
- package/dist/src/tools/edit.d.ts +70 -0
- package/dist/src/tools/edit.js +816 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/exa-web-search.d.ts +27 -0
- package/dist/src/tools/exa-web-search.js +153 -0
- package/dist/src/tools/exa-web-search.js.map +1 -0
- package/dist/src/tools/glob.d.ts +55 -0
- package/dist/src/tools/glob.js +284 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/google-web-fetch.d.ts +34 -0
- package/dist/src/tools/google-web-fetch.js +417 -0
- package/dist/src/tools/google-web-fetch.js.map +1 -0
- package/dist/src/tools/google-web-search-invocation.d.ts +53 -0
- package/dist/src/tools/google-web-search-invocation.js +180 -0
- package/dist/src/tools/google-web-search-invocation.js.map +1 -0
- package/dist/src/tools/google-web-search.d.ts +16 -0
- package/dist/src/tools/google-web-search.js +34 -0
- package/dist/src/tools/google-web-search.js.map +1 -0
- package/dist/src/tools/grep.d.ts +56 -0
- package/dist/src/tools/grep.js +883 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/insert_at_line.d.ts +41 -0
- package/dist/src/tools/insert_at_line.js +287 -0
- package/dist/src/tools/insert_at_line.js.map +1 -0
- package/dist/src/tools/list-subagents.d.ts +31 -0
- package/dist/src/tools/list-subagents.js +122 -0
- package/dist/src/tools/list-subagents.js.map +1 -0
- package/dist/src/tools/ls.d.ts +71 -0
- package/dist/src/tools/ls.js +238 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +66 -0
- package/dist/src/tools/memoryTool.js +435 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +37 -0
- package/dist/src/tools/modifiable-tool.js +120 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +49 -0
- package/dist/src/tools/read-file.js +279 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +60 -0
- package/dist/src/tools/read-many-files.js +529 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/read_line_range.d.ts +47 -0
- package/dist/src/tools/read_line_range.js +248 -0
- package/dist/src/tools/read_line_range.js.map +1 -0
- package/dist/src/tools/ripGrep.d.ts +41 -0
- package/dist/src/tools/ripGrep.js +395 -0
- package/dist/src/tools/ripGrep.js.map +1 -0
- package/dist/src/tools/shell.d.ts +60 -0
- package/dist/src/tools/shell.js +735 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/structural-analysis.d.ts +27 -0
- package/dist/src/tools/structural-analysis.js +1089 -0
- package/dist/src/tools/structural-analysis.js.map +1 -0
- package/dist/src/tools/stubs.d.ts +10 -0
- package/dist/src/tools/stubs.js +6 -0
- package/dist/src/tools/stubs.js.map +1 -0
- package/dist/src/tools/task.d.ts +41 -0
- package/dist/src/tools/task.js +195 -0
- package/dist/src/tools/task.js.map +1 -0
- package/dist/src/tools/todo-events.d.ts +22 -0
- package/dist/src/tools/todo-events.js +24 -0
- package/dist/src/tools/todo-events.js.map +1 -0
- package/dist/src/tools/todo-pause.d.ts +29 -0
- package/dist/src/tools/todo-pause.js +172 -0
- package/dist/src/tools/todo-pause.js.map +1 -0
- package/dist/src/tools/todo-read.d.ts +18 -0
- package/dist/src/tools/todo-read.js +98 -0
- package/dist/src/tools/todo-read.js.map +1 -0
- package/dist/src/tools/todo-store.d.ts +35 -0
- package/dist/src/tools/todo-store.js +124 -0
- package/dist/src/tools/todo-store.js.map +1 -0
- package/dist/src/tools/todo-write.d.ts +29 -0
- package/dist/src/tools/todo-write.js +366 -0
- package/dist/src/tools/todo-write.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +156 -0
- package/dist/src/tools/tool-registry.js +623 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tools.d.ts +403 -0
- package/dist/src/tools/tools.js +519 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +45 -0
- package/dist/src/tools/write-file.js +320 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/types/index.d.ts +17 -0
- package/dist/src/types/index.js +9 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/provider-content-types.d.ts +56 -0
- package/dist/src/types/provider-content-types.js +6 -0
- package/dist/src/types/provider-content-types.js.map +1 -0
- package/dist/src/types/todo-schemas.d.ts +263 -0
- package/dist/src/types/todo-schemas.js +32 -0
- package/dist/src/types/todo-schemas.js.map +1 -0
- package/dist/src/types/tool-confirmation-types.d.ts +34 -0
- package/dist/src/types/tool-confirmation-types.js +29 -0
- package/dist/src/types/tool-confirmation-types.js.map +1 -0
- package/dist/src/types/tool-context.d.ts +31 -0
- package/dist/src/types/tool-context.js +6 -0
- package/dist/src/types/tool-context.js.map +1 -0
- package/dist/src/types/tool-error.d.ts +69 -0
- package/dist/src/types/tool-error.js +94 -0
- package/dist/src/types/tool-error.js.map +1 -0
- package/dist/src/types/tool-names.d.ts +57 -0
- package/dist/src/types/tool-names.js +64 -0
- package/dist/src/types/tool-names.js.map +1 -0
- package/dist/src/utils/EmojiFilter.d.ts +134 -0
- package/dist/src/utils/EmojiFilter.js +370 -0
- package/dist/src/utils/EmojiFilter.js.map +1 -0
- package/dist/src/utils/ast-grep-utils.d.ts +42 -0
- package/dist/src/utils/ast-grep-utils.js +140 -0
- package/dist/src/utils/ast-grep-utils.js.map +1 -0
- package/dist/src/utils/debugLogger.d.ts +11 -0
- package/dist/src/utils/debugLogger.js +16 -0
- package/dist/src/utils/debugLogger.js.map +1 -0
- package/dist/src/utils/diffOptions.d.ts +14 -0
- package/dist/src/utils/diffOptions.js +46 -0
- package/dist/src/utils/diffOptions.js.map +1 -0
- package/dist/src/utils/editor.d.ts +39 -0
- package/dist/src/utils/editor.js +212 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/ensure-dirs.d.ts +10 -0
- package/dist/src/utils/ensure-dirs.js +16 -0
- package/dist/src/utils/ensure-dirs.js.map +1 -0
- package/dist/src/utils/errors.d.ts +59 -0
- package/dist/src/utils/errors.js +178 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +11 -0
- package/dist/src/utils/fetch.js +74 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +32 -0
- package/dist/src/utils/fileUtils.js +363 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/fuzzy-replacer.d.ts +61 -0
- package/dist/src/utils/fuzzy-replacer.js +492 -0
- package/dist/src/utils/fuzzy-replacer.js.map +1 -0
- package/dist/src/utils/gitLineChanges.d.ts +12 -0
- package/dist/src/utils/gitLineChanges.js +171 -0
- package/dist/src/utils/gitLineChanges.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +6 -0
- package/dist/src/utils/gitUtils.js +31 -0
- package/dist/src/utils/gitUtils.js.map +1 -0
- package/dist/src/utils/lsp-diagnostics-helper.d.ts +27 -0
- package/dist/src/utils/lsp-diagnostics-helper.js +62 -0
- package/dist/src/utils/lsp-diagnostics-helper.js.map +1 -0
- package/dist/src/utils/mediaUtils.d.ts +38 -0
- package/dist/src/utils/mediaUtils.js +22 -0
- package/dist/src/utils/mediaUtils.js.map +1 -0
- package/dist/src/utils/pathValidation.d.ts +7 -0
- package/dist/src/utils/pathValidation.js +39 -0
- package/dist/src/utils/pathValidation.js.map +1 -0
- package/dist/src/utils/paths.d.ts +7 -0
- package/dist/src/utils/paths.js +158 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/resolveTextSearchTarget.d.ts +17 -0
- package/dist/src/utils/resolveTextSearchTarget.js +45 -0
- package/dist/src/utils/resolveTextSearchTarget.js.map +1 -0
- package/dist/src/utils/retry.d.ts +17 -0
- package/dist/src/utils/retry.js +185 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/ripgrepPathResolver.d.ts +23 -0
- package/dist/src/utils/ripgrepPathResolver.js +179 -0
- package/dist/src/utils/ripgrepPathResolver.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +9 -0
- package/dist/src/utils/safeJsonStringify.js +21 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +13 -0
- package/dist/src/utils/schemaValidator.js +275 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/terminalSerializer.d.ts +33 -0
- package/dist/src/utils/terminalSerializer.js +6 -0
- package/dist/src/utils/terminalSerializer.js.map +1 -0
- package/dist/src/utils/todoContextTracker.d.ts +12 -0
- package/dist/src/utils/todoContextTracker.js +28 -0
- package/dist/src/utils/todoContextTracker.js.map +1 -0
- package/dist/src/utils/todoFormatter.d.ts +24 -0
- package/dist/src/utils/todoFormatter.js +157 -0
- package/dist/src/utils/todoFormatter.js.map +1 -0
- package/dist/src/utils/todoReminderService.d.ts +22 -0
- package/dist/src/utils/todoReminderService.js +43 -0
- package/dist/src/utils/todoReminderService.js.map +1 -0
- package/dist/src/utils/tool-key-storage-facade.d.ts +32 -0
- package/dist/src/utils/tool-key-storage-facade.js +56 -0
- package/dist/src/utils/tool-key-storage-facade.js.map +1 -0
- package/dist/src/utils/tool-key-storage-types.d.ts +56 -0
- package/dist/src/utils/tool-key-storage-types.js +56 -0
- package/dist/src/utils/tool-key-storage-types.js.map +1 -0
- package/dist/src/utils/toolOutputLimiter.d.ts +29 -0
- package/dist/src/utils/toolOutputLimiter.js +107 -0
- package/dist/src/utils/toolOutputLimiter.js.map +1 -0
- package/dist/src/utils/unicodeUtils.d.ts +55 -0
- package/dist/src/utils/unicodeUtils.js +129 -0
- package/dist/src/utils/unicodeUtils.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { EmojiFilter } from '../utils/EmojiFilter.js';
|
|
7
|
+
import { ReadFileTool } from './read-file.js';
|
|
8
|
+
import { ToolErrorType } from '../types/tool-error.js';
|
|
9
|
+
import { fuzzyReplace } from '../utils/fuzzy-replacer.js';
|
|
10
|
+
/**
|
|
11
|
+
* Computes the character offset for the start of a 1-based line number
|
|
12
|
+
* within content split by newlines.
|
|
13
|
+
*/
|
|
14
|
+
function getOffsetForLine(lines, lineNumber) {
|
|
15
|
+
let offset = 0;
|
|
16
|
+
for (let i = 0; i < lineNumber - 1; i++) {
|
|
17
|
+
offset += lines[i].length + 1;
|
|
18
|
+
}
|
|
19
|
+
return offset;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Counts occurrences of oldString that start within the line range
|
|
23
|
+
* [replaceLine, replaceLine+1) — i.e., occurrences whose start position
|
|
24
|
+
* falls on the specified 1-based line number.
|
|
25
|
+
* Returns 0 if replaceLine is out of range.
|
|
26
|
+
*/
|
|
27
|
+
export function countLineGuardedOccurrences(currentContent, oldString, replaceLine) {
|
|
28
|
+
if (oldString === '') {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
const lines = currentContent.split('\n');
|
|
32
|
+
if (replaceLine > lines.length) {
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
const lineStartOffset = getOffsetForLine(lines, replaceLine);
|
|
36
|
+
const nextLineStartOffset = replaceLine < lines.length
|
|
37
|
+
? getOffsetForLine(lines, replaceLine + 1)
|
|
38
|
+
: currentContent.length;
|
|
39
|
+
let count = 0;
|
|
40
|
+
let searchStart = lineStartOffset;
|
|
41
|
+
while (searchStart < nextLineStartOffset) {
|
|
42
|
+
const foundAt = currentContent.indexOf(oldString, searchStart);
|
|
43
|
+
if (foundAt === -1 || foundAt >= nextLineStartOffset) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
count++;
|
|
47
|
+
searchStart = foundAt + oldString.length;
|
|
48
|
+
}
|
|
49
|
+
return count;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Applies replacement of oldString with newString, but only for occurrences
|
|
53
|
+
* whose start position falls within the line range [replaceLine, replaceLine+1).
|
|
54
|
+
* Replaces up to expectedReplacements eligible occurrences.
|
|
55
|
+
* Returns the resulting content string.
|
|
56
|
+
*
|
|
57
|
+
* Deterministic approach: collect all eligible match offsets from the original
|
|
58
|
+
* content first, then build the output string from original content slices.
|
|
59
|
+
* This avoids the stale-bounds bug that arises when searching a mutated result
|
|
60
|
+
* string with offsets computed from the original content.
|
|
61
|
+
*/
|
|
62
|
+
export function applyLineGuardedReplacement(currentContent, oldString, newString, expectedReplacements, replaceLine) {
|
|
63
|
+
if (oldString === '') {
|
|
64
|
+
return currentContent;
|
|
65
|
+
}
|
|
66
|
+
const lines = currentContent.split('\n');
|
|
67
|
+
if (replaceLine > lines.length) {
|
|
68
|
+
return currentContent;
|
|
69
|
+
}
|
|
70
|
+
const lineStartOffset = getOffsetForLine(lines, replaceLine);
|
|
71
|
+
const nextLineStartOffset = replaceLine < lines.length
|
|
72
|
+
? getOffsetForLine(lines, replaceLine + 1)
|
|
73
|
+
: currentContent.length;
|
|
74
|
+
// Collect eligible match start offsets from the original content.
|
|
75
|
+
const matchOffsets = [];
|
|
76
|
+
let searchStart = lineStartOffset;
|
|
77
|
+
while (matchOffsets.length < expectedReplacements &&
|
|
78
|
+
searchStart < nextLineStartOffset) {
|
|
79
|
+
const foundAt = currentContent.indexOf(oldString, searchStart);
|
|
80
|
+
if (foundAt === -1 || foundAt >= nextLineStartOffset) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
matchOffsets.push(foundAt);
|
|
84
|
+
searchStart = foundAt + oldString.length;
|
|
85
|
+
}
|
|
86
|
+
if (matchOffsets.length === 0) {
|
|
87
|
+
return currentContent;
|
|
88
|
+
}
|
|
89
|
+
// Build result from original content slices, replacing at collected offsets.
|
|
90
|
+
let result = '';
|
|
91
|
+
let prevEnd = 0;
|
|
92
|
+
for (const offset of matchOffsets) {
|
|
93
|
+
result += currentContent.substring(prevEnd, offset);
|
|
94
|
+
result += newString;
|
|
95
|
+
prevEnd = offset + oldString.length;
|
|
96
|
+
}
|
|
97
|
+
result += currentContent.substring(prevEnd);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets emoji filter instance based on configuration
|
|
102
|
+
*/
|
|
103
|
+
export function getEmojiFilter(host) {
|
|
104
|
+
// Get emojifilter from ephemeral settings or default to 'auto'
|
|
105
|
+
const mode = host.getEphemeralSettings?.().emojifilter;
|
|
106
|
+
// Map auto to warn for file operations (we want warnings when filtering files)
|
|
107
|
+
let filterMode;
|
|
108
|
+
if (mode === 'allowed') {
|
|
109
|
+
filterMode = 'allowed';
|
|
110
|
+
}
|
|
111
|
+
else if (mode === 'auto' || mode === 'warn') {
|
|
112
|
+
filterMode = 'warn';
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
filterMode = 'error';
|
|
116
|
+
}
|
|
117
|
+
return new EmojiFilter({ mode: filterMode });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Applies a replacement to content.
|
|
121
|
+
*/
|
|
122
|
+
export function applyReplacement(currentContent, oldString, newString, isNewFile, expectedReplacements = 1) {
|
|
123
|
+
if (isNewFile) {
|
|
124
|
+
return newString;
|
|
125
|
+
}
|
|
126
|
+
if (currentContent === null) {
|
|
127
|
+
// Should not happen if not a new file, but defensively return empty or newString if oldString is also empty
|
|
128
|
+
return oldString === '' ? newString : '';
|
|
129
|
+
}
|
|
130
|
+
if (oldString === '' && expectedReplacements > 1) {
|
|
131
|
+
throw new Error('Cannot perform multiple replacements with empty old_string');
|
|
132
|
+
}
|
|
133
|
+
if (oldString === '') {
|
|
134
|
+
return currentContent;
|
|
135
|
+
}
|
|
136
|
+
const preserveTrailingNewline = currentContent.endsWith('\n');
|
|
137
|
+
const fuzzyResult = fuzzyReplace(currentContent, oldString, newString, expectedReplacements > 1);
|
|
138
|
+
if (fuzzyResult && fuzzyResult.occurrences === expectedReplacements) {
|
|
139
|
+
return preserveTrailingNewlineForResult(fuzzyResult.result, preserveTrailingNewline);
|
|
140
|
+
}
|
|
141
|
+
const result = expectedReplacements === 1
|
|
142
|
+
? replaceSingleOccurrence(currentContent, oldString, newString)
|
|
143
|
+
: replaceExpectedOccurrences(currentContent, oldString, newString, expectedReplacements);
|
|
144
|
+
return preserveTrailingNewlineForResult(result, preserveTrailingNewline);
|
|
145
|
+
}
|
|
146
|
+
function preserveTrailingNewlineForResult(result, preserveTrailingNewline) {
|
|
147
|
+
if (preserveTrailingNewline && result.length > 0 && !result.endsWith('\n')) {
|
|
148
|
+
return `${result}\n`;
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function replaceSingleOccurrence(currentContent, oldString, newString) {
|
|
153
|
+
// Use a replacer function so `$` in `newString` is treated literally.
|
|
154
|
+
return currentContent.replace(oldString, () => newString);
|
|
155
|
+
}
|
|
156
|
+
function replaceExpectedOccurrences(currentContent, oldString, newString, expectedReplacements) {
|
|
157
|
+
let result = currentContent;
|
|
158
|
+
let replacementCount = 0;
|
|
159
|
+
let searchIndex = 0;
|
|
160
|
+
while (replacementCount < expectedReplacements) {
|
|
161
|
+
const foundIndex = result.indexOf(oldString, searchIndex);
|
|
162
|
+
if (foundIndex === -1) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
result = replaceAtIndex(result, foundIndex, oldString, newString);
|
|
166
|
+
replacementCount++;
|
|
167
|
+
searchIndex = foundIndex + newString.length;
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
function replaceAtIndex(content, foundIndex, oldString, newString) {
|
|
172
|
+
return (content.substring(0, foundIndex) +
|
|
173
|
+
newString +
|
|
174
|
+
content.substring(foundIndex + oldString.length));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Builds the error object when zero occurrences are found.
|
|
178
|
+
*/
|
|
179
|
+
export function buildNoOccurrenceError(filteredParams, currentContent, filePath) {
|
|
180
|
+
const replaceLine = filteredParams.replaceBeginLineNumber;
|
|
181
|
+
if (replaceLine !== undefined && replaceLine > 0 && currentContent !== null) {
|
|
182
|
+
const lines = currentContent.split('\n');
|
|
183
|
+
if (replaceLine > lines.length) {
|
|
184
|
+
return {
|
|
185
|
+
display: `Failed to edit: replaceBeginLineNumber is out of range.`,
|
|
186
|
+
raw: `Failed to edit: replaceBeginLineNumber=${replaceLine} is out of range for ${filePath} (total lines: ${lines.length}). No edits made.`,
|
|
187
|
+
type: ToolErrorType.INVALID_TOOL_PARAMS,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const lineIndex = replaceLine - 1;
|
|
191
|
+
const startContext = Math.max(0, lineIndex - 2);
|
|
192
|
+
const endContext = Math.min(lines.length - 1, lineIndex + 2);
|
|
193
|
+
let preview = 'Context around requested line:';
|
|
194
|
+
for (let i = startContext; i <= endContext; i++) {
|
|
195
|
+
const lineNumber = i + 1;
|
|
196
|
+
const prefix = lineNumber === replaceLine ? '->' : ' ';
|
|
197
|
+
preview += `\n${prefix} ${lineNumber.toString().padStart(4, ' ')} | ${lines[i]}`;
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
display: `Failed to edit: no occurrences of old_string found starting at the specified line ${replaceLine}.`,
|
|
201
|
+
raw: `Failed to edit, 0 occurrences found for old_string starting at line ${replaceLine} in ${filePath}. No edits made. The exact text in old_string was not found starting at that line.\n\n${preview}`,
|
|
202
|
+
type: ToolErrorType.EDIT_NO_OCCURRENCE_FOUND,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
display: `Failed to edit, could not find the string to replace.`,
|
|
207
|
+
raw: `Failed to edit, 0 occurrences found for old_string in ${filePath}. No edits made. The exact text in old_string was not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context. Use ${ReadFileTool.Name} tool to verify.`,
|
|
208
|
+
type: ToolErrorType.EDIT_NO_OCCURRENCE_FOUND,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Validates the edit parameters after reading file content and builds the
|
|
213
|
+
* appropriate error object if any validation fails.
|
|
214
|
+
*/
|
|
215
|
+
export function validateEditState(filteredParams, currentContent, fileExists, filePath, occurrences, expectedReplacements, finalOldString, finalNewString) {
|
|
216
|
+
if (filteredParams.old_string === '' && expectedReplacements > 1) {
|
|
217
|
+
return {
|
|
218
|
+
display: `Failed to edit. Cannot perform multiple replacements with empty old_string.`,
|
|
219
|
+
raw: `Invalid parameters: empty old_string with expected_replacements=${expectedReplacements} would cause infinite loop`,
|
|
220
|
+
type: ToolErrorType.INVALID_TOOL_PARAMS,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (filteredParams.old_string === '') {
|
|
224
|
+
return {
|
|
225
|
+
display: `Failed to edit. Attempted to create a file that already exists.`,
|
|
226
|
+
raw: `File already exists, cannot create: ${filePath}`,
|
|
227
|
+
type: ToolErrorType.ATTEMPT_TO_CREATE_EXISTING_FILE,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (occurrences === 0) {
|
|
231
|
+
return buildNoOccurrenceError(filteredParams, currentContent, filePath);
|
|
232
|
+
}
|
|
233
|
+
if (occurrences !== expectedReplacements) {
|
|
234
|
+
const occurrenceTerm = expectedReplacements === 1 ? 'occurrence' : 'occurrences';
|
|
235
|
+
return {
|
|
236
|
+
display: `Failed to edit, expected ${expectedReplacements} ${occurrenceTerm} but found ${occurrences}.`,
|
|
237
|
+
raw: `Failed to edit, Expected ${expectedReplacements} ${occurrenceTerm} but found ${occurrences} for old_string in file: ${filePath}`,
|
|
238
|
+
type: ToolErrorType.EDIT_EXPECTED_OCCURRENCE_MISMATCH,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (finalOldString === finalNewString) {
|
|
242
|
+
return {
|
|
243
|
+
display: `No changes to apply. The old_string and new_string are identical.`,
|
|
244
|
+
raw: `No changes to apply. The old_string and new_string are identical in file: ${filePath}`,
|
|
245
|
+
type: ToolErrorType.EDIT_NO_CHANGE,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=edit-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-utils.js","sourceRoot":"","sources":["../../../src/tools/edit-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;;GAGG;AACH,SAAS,gBAAgB,CAAC,KAAe,EAAE,UAAkB;IAC3D,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,cAAsB,EACtB,SAAiB,EACjB,WAAmB;IAEnB,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,WAAW,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC/B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,eAAe,GAAG,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;I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AC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC;QAC5D,OAAO;YACL,OAAO,EAAE,4BAA4B,oBAAoB,IAAI,cAAc,cAAc,WAAW,GAAG;YACvG,GAAG,EAAE,4BAA4B,oBAAoB,IAAI,cAAc,cAAc,WAAW,4BAA4B,QAAQ,EAAE;YACtI,IAAI,EAAE,aAAa,CAAC,iCAAiC;SACtD,CAAC;IACJ,CAAC;IACD,IAAI,cAAc,KAAK,cAAc,EAAE,CAAC;QACtC,OAAO;YACL,OAAO,EAAE,mEAAmE;YAC5E,GAAG,EAAE,6EAA6E,QAAQ,EAAE;YAC5F,IAAI,EAAE,aAAa,CAAC,cAAc;SACnC,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, type ToolInvocation, type ToolResult } from './tools.js';
|
|
7
|
+
import type { IIdeService, ILspService, IToolHost, IToolMessageBus } from '../interfaces/index.js';
|
|
8
|
+
import { type ModifiableDeclarativeTool, type ModifyContext } from './modifiable-tool.js';
|
|
9
|
+
export { applyReplacement, countLineGuardedOccurrences, applyLineGuardedReplacement, } from './edit-utils.js';
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for the Edit tool
|
|
12
|
+
*/
|
|
13
|
+
export interface EditToolParams {
|
|
14
|
+
/**
|
|
15
|
+
* The absolute path to the file to modify
|
|
16
|
+
*/
|
|
17
|
+
absolute_path?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Alternative parameter name for absolute_path (for compatibility)
|
|
20
|
+
* Not shown in schema - internal use only
|
|
21
|
+
*/
|
|
22
|
+
file_path?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The text to replace
|
|
25
|
+
*/
|
|
26
|
+
old_string: string;
|
|
27
|
+
/**
|
|
28
|
+
* The text to replace it with
|
|
29
|
+
*/
|
|
30
|
+
new_string: string;
|
|
31
|
+
/**
|
|
32
|
+
* Number of replacements expected. Defaults to 1 if not specified.
|
|
33
|
+
* Use when you want to replace multiple occurrences.
|
|
34
|
+
*/
|
|
35
|
+
expected_replacements?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Optional 1-based line number where the replacement should begin.
|
|
38
|
+
* Strongly recommended to always set this to guard against misinterpreting
|
|
39
|
+
* the file structure, especially when similar text appears multiple times.
|
|
40
|
+
*/
|
|
41
|
+
replaceBeginLineNumber?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the edit was modified manually by the user.
|
|
44
|
+
*/
|
|
45
|
+
modified_by_user?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Initially proposed content.
|
|
48
|
+
*/
|
|
49
|
+
ai_proposed_content?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Implementation of the Edit tool logic
|
|
53
|
+
*/
|
|
54
|
+
export declare class EditTool extends BaseDeclarativeTool<EditToolParams, ToolResult> implements ModifiableDeclarativeTool<EditToolParams> {
|
|
55
|
+
private readonly host;
|
|
56
|
+
static readonly Name = "replace";
|
|
57
|
+
private readonly ideService?;
|
|
58
|
+
private readonly lspService?;
|
|
59
|
+
constructor(host?: IToolHost, messageBusOrIdeService?: IToolMessageBus | IIdeService, ideServiceOrLspService?: IIdeService | ILspService, lspService?: ILspService);
|
|
60
|
+
/**
|
|
61
|
+
* Validates the parameters for the Edit tool
|
|
62
|
+
* @param params Parameters to validate
|
|
63
|
+
* @returns Error message string or null if valid
|
|
64
|
+
*/
|
|
65
|
+
protected validateToolParamValues(params: EditToolParams): string | null;
|
|
66
|
+
protected createInvocation(params: EditToolParams, messageBus: IToolMessageBus, toolName?: string, displayName?: string): ToolInvocation<EditToolParams, ToolResult>;
|
|
67
|
+
private readTextFile;
|
|
68
|
+
execute(params: EditToolParams, signal?: AbortSignal): Promise<ToolResult>;
|
|
69
|
+
getModifyContext(_: AbortSignal): ModifyContext<EditToolParams>;
|
|
70
|
+
}
|