@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,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Context optimizer for snippet deduplication and context size management.
|
|
7
|
+
*/
|
|
8
|
+
import { ASTConfig } from './ast-config.js';
|
|
9
|
+
/**
|
|
10
|
+
* Handles optimization of code context including snippet management and prompt clipping.
|
|
11
|
+
*/
|
|
12
|
+
export class ContextOptimizer {
|
|
13
|
+
/**
|
|
14
|
+
* Clip prompt to fit max length limit (corresponds to AST clip_prompt)
|
|
15
|
+
*/
|
|
16
|
+
static clipPrompt(prompt, maxLength) {
|
|
17
|
+
if (prompt.length <= maxLength) {
|
|
18
|
+
return prompt;
|
|
19
|
+
}
|
|
20
|
+
// Clip from start, preserve newest content (AST strategy)
|
|
21
|
+
let start = prompt.length - maxLength;
|
|
22
|
+
while (!this.isCharBoundary(prompt, start)) {
|
|
23
|
+
start += 1;
|
|
24
|
+
}
|
|
25
|
+
return prompt.substring(start);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check UTF-16 character boundary
|
|
29
|
+
*/
|
|
30
|
+
static isCharBoundary(str, index) {
|
|
31
|
+
if (index <= 0)
|
|
32
|
+
return true;
|
|
33
|
+
if (index >= str.length)
|
|
34
|
+
return true;
|
|
35
|
+
// Check for low surrogate (0xDC00–0xDFFF)
|
|
36
|
+
const code = str.charCodeAt(index);
|
|
37
|
+
if (code >= 0xdc00 && code <= 0xdfff) {
|
|
38
|
+
// If previous character is high surrogate (0xD800–0xDBFF), this is not a boundary
|
|
39
|
+
const prevCode = str.charCodeAt(index - 1);
|
|
40
|
+
if (prevCode >= 0xd800 && prevCode <= 0xdbff) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Manage snippets by priority and budget (corresponds to AST snippet collection)
|
|
48
|
+
*/
|
|
49
|
+
static optimizeSnippets(snippets, maxChars = ASTConfig.MAX_SNIPPET_CHARS) {
|
|
50
|
+
// 1. Sort by priority and relevance
|
|
51
|
+
const sortedSnippets = [...snippets].sort((a, b) => {
|
|
52
|
+
// Higher priority first
|
|
53
|
+
if (a.priority !== b.priority) {
|
|
54
|
+
return a.priority - b.priority;
|
|
55
|
+
}
|
|
56
|
+
// Same priority, sort by relevance
|
|
57
|
+
return b.relevance - a.relevance;
|
|
58
|
+
});
|
|
59
|
+
// 2. Select snippets within budget
|
|
60
|
+
const optimizedSnippets = [];
|
|
61
|
+
let usedChars = 0;
|
|
62
|
+
for (const snippet of sortedSnippets) {
|
|
63
|
+
const truncatedSnippet = this.truncateSnippet(snippet);
|
|
64
|
+
if (usedChars + truncatedSnippet.charLength > maxChars) {
|
|
65
|
+
break; // Budget exhausted
|
|
66
|
+
}
|
|
67
|
+
optimizedSnippets.push(truncatedSnippet);
|
|
68
|
+
usedChars += truncatedSnippet.charLength;
|
|
69
|
+
}
|
|
70
|
+
return optimizedSnippets;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Truncate overly long snippets
|
|
74
|
+
*/
|
|
75
|
+
static truncateSnippet(snippet) {
|
|
76
|
+
if (snippet.text.length <= ASTConfig.SNIPPET_TRUNCATE_LENGTH) {
|
|
77
|
+
return snippet;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
...snippet,
|
|
81
|
+
text: snippet.text.substring(0, ASTConfig.SNIPPET_TRUNCATE_LENGTH) + '...',
|
|
82
|
+
charLength: ASTConfig.SNIPPET_TRUNCATE_LENGTH + 3,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=context-optimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-optimizer.js","sourceRoot":"","sources":["../../../../src/tools/ast-edit/context-optimizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;OAEG;IACH,MAAM,CAAC,U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AE,CAAC;gBAC9B,OAAO,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;YACjC,CAAC;YACD,mCAAmC;YACnC,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,mCAAmC;QACnC,MAAM,iBAAiB,GAAkB,EAAE,CAAC;QAC5C,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,KAAK,MAAM,OAAO,IAAI,cAAc,EAAE,CAAC;YACrC,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAEvD,IAAI,SAAS,GAAG,gBAAgB,CAAC,UAAU,GAAG,QAAQ,EAAE,CAAC;gBACvD,MAAM,CAAC,mBAAmB;YAC5B,CAAC;YAED,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACzC,SAAS,IAAI,gBAAgB,CAAC,UAAU,CAAC;QAC3C,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,OAAoB;QACzC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,uBAAuB,EAAE,CAAC;YAC7D,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,OAAO;YACL,GAAG,OAAO;YACV,IAAI,EACF,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,uBAAuB,CAAC,GAAG,KAAK;YACtE,UAAU,EAAE,SAAS,CAAC,uBAAuB,GAAG,CAAC;SAClD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Cross-file relationship analyzer for symbol indexing and reference tracking.
|
|
7
|
+
*/
|
|
8
|
+
import type { Lang } from '@ast-grep/napi';
|
|
9
|
+
import type { SymbolReference } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Discovers workspace files for symbol indexing using fast-glob.
|
|
12
|
+
* @param workspaceRoot - The root directory to search
|
|
13
|
+
* @returns Array of absolute file paths
|
|
14
|
+
*/
|
|
15
|
+
export declare function getWorkspaceFiles(workspaceRoot: string): Promise<string[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Analyzes cross-file relationships for symbol tracking and import graph building.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CrossFileRelationshipAnalyzer {
|
|
20
|
+
private symbolIndex;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Symbol indexing is disabled by default due to performance issues.
|
|
23
|
+
* [CCR] Reason: Prefer on-demand queryViaFindInFiles to avoid OOM in large workspaces.
|
|
24
|
+
*/
|
|
25
|
+
buildSymbolIndex(files: string[]): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Find related symbols using ast-grep's findInFiles with strict concurrency and quantity limits.
|
|
28
|
+
* [CCR] Relation: Core logic for 'Lazy' context gathering.
|
|
29
|
+
* Reason: Replaces eager indexing with atomic, timed-out queries to maintain CLI speed.
|
|
30
|
+
*/
|
|
31
|
+
findRelatedSymbols(symbolName: string, workspacePath: string, lang?: Lang | string): Promise<SymbolReference[]>;
|
|
32
|
+
private executeSymbolSearch;
|
|
33
|
+
private searchWithLang;
|
|
34
|
+
private searchAllLanguages;
|
|
35
|
+
private groupFilesByLanguage;
|
|
36
|
+
private searchLanguageGroups;
|
|
37
|
+
findRelatedFiles(filePath: string): Promise<string[]>;
|
|
38
|
+
private resolveImportPath;
|
|
39
|
+
private fileExists;
|
|
40
|
+
private fileExistsSync;
|
|
41
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Cross-file relationship analyzer for symbol indexing and reference tracking.
|
|
7
|
+
*/
|
|
8
|
+
import { promises as fsPromises, accessSync } from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { findInFiles } from '@ast-grep/napi';
|
|
11
|
+
import FastGlob from 'fast-glob';
|
|
12
|
+
import { debugLogger } from '../../utils/debugLogger.js';
|
|
13
|
+
import { LANGUAGE_MAP } from '../../utils/ast-grep-utils.js';
|
|
14
|
+
import { ASTConfig } from './ast-config.js';
|
|
15
|
+
import { ASTQueryExtractor } from './ast-query-extractor.js';
|
|
16
|
+
import { detectLanguage, extractImports } from './language-analysis.js';
|
|
17
|
+
const logger = debugLogger;
|
|
18
|
+
function withTimeout(promise, ms) {
|
|
19
|
+
let timeoutId;
|
|
20
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
21
|
+
timeoutId = setTimeout(() => {
|
|
22
|
+
reject(new Error(`Timeout after ${ms}ms`));
|
|
23
|
+
}, ms);
|
|
24
|
+
});
|
|
25
|
+
return Promise.race([promise, timeoutPromise]).finally(() => {
|
|
26
|
+
clearTimeout(timeoutId);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Discovers workspace files for symbol indexing using fast-glob.
|
|
31
|
+
* @param workspaceRoot - The root directory to search
|
|
32
|
+
* @returns Array of absolute file paths
|
|
33
|
+
*/
|
|
34
|
+
export async function getWorkspaceFiles(workspaceRoot) {
|
|
35
|
+
// Cross-platform workspace file collection using fast-glob
|
|
36
|
+
try {
|
|
37
|
+
const patterns = ['**/*.ts', '**/*.js', '**/*.py'];
|
|
38
|
+
const files = await FastGlob(patterns, {
|
|
39
|
+
cwd: workspaceRoot,
|
|
40
|
+
absolute: true,
|
|
41
|
+
onlyFiles: true,
|
|
42
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/build/**'],
|
|
43
|
+
});
|
|
44
|
+
return files.filter((file) => file.length > 0);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
logger.error(`Error discovering workspace files`, error);
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Analyzes cross-file relationships for symbol tracking and import graph building.
|
|
53
|
+
*/
|
|
54
|
+
export class CrossFileRelationshipAnalyzer {
|
|
55
|
+
symbolIndex = new Map();
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Symbol indexing is disabled by default due to performance issues.
|
|
58
|
+
* [CCR] Reason: Prefer on-demand queryViaFindInFiles to avoid OOM in large workspaces.
|
|
59
|
+
*/
|
|
60
|
+
async buildSymbolIndex(files) {
|
|
61
|
+
if (!ASTConfig.ENABLE_SYMBOL_INDEXING) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.symbolIndex.clear();
|
|
65
|
+
for (const filePath of files) {
|
|
66
|
+
try {
|
|
67
|
+
const content = await fsPromises.readFile(filePath, 'utf-8');
|
|
68
|
+
const extractor = new ASTQueryExtractor();
|
|
69
|
+
const declarations = await extractor.extractDeclarations(filePath, content);
|
|
70
|
+
const imports = extractImports(content, detectLanguage(filePath));
|
|
71
|
+
// Build symbol index
|
|
72
|
+
for (const decl of declarations) {
|
|
73
|
+
// eslint-disable-next-line sonarjs/nested-control-flow -- Existing structure is intentionally preserved; refactoring this boundary is outside the lint slice.
|
|
74
|
+
if (!this.symbolIndex.has(decl.name)) {
|
|
75
|
+
this.symbolIndex.set(decl.name, []);
|
|
76
|
+
}
|
|
77
|
+
this.symbolIndex.get(decl.name).push({
|
|
78
|
+
type: 'definition',
|
|
79
|
+
filePath,
|
|
80
|
+
line: decl.line,
|
|
81
|
+
column: decl.column,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// Build import relationships
|
|
85
|
+
for (const imp of imports) {
|
|
86
|
+
// eslint-disable-next-line sonarjs/nested-control-flow -- Existing structure is intentionally preserved; refactoring this boundary is outside the lint slice.
|
|
87
|
+
for (const item of imp.items) {
|
|
88
|
+
if (!this.symbolIndex.has(item)) {
|
|
89
|
+
this.symbolIndex.set(item, []);
|
|
90
|
+
}
|
|
91
|
+
this.symbolIndex.get(item).push({
|
|
92
|
+
type: 'import',
|
|
93
|
+
filePath,
|
|
94
|
+
line: imp.line,
|
|
95
|
+
column: 0, // Default column for imports
|
|
96
|
+
sourceModule: imp.module,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// File read failed - skip this import
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Find related symbols using ast-grep's findInFiles with strict concurrency and quantity limits.
|
|
108
|
+
* [CCR] Relation: Core logic for 'Lazy' context gathering.
|
|
109
|
+
* Reason: Replaces eager indexing with atomic, timed-out queries to maintain CLI speed.
|
|
110
|
+
*/
|
|
111
|
+
async findRelatedSymbols(symbolName, workspacePath, lang) {
|
|
112
|
+
const references = [];
|
|
113
|
+
try {
|
|
114
|
+
let workspaceTooLarge = false;
|
|
115
|
+
const queryPromise = this.executeSymbolSearch(symbolName, workspacePath, lang, references, () => {
|
|
116
|
+
workspaceTooLarge = true;
|
|
117
|
+
});
|
|
118
|
+
await withTimeout(queryPromise, ASTConfig.FIND_RELATED_TIMEOUT_MS);
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Workspace-size guard is set inside async search callbacks before this await resumes.
|
|
120
|
+
if (workspaceTooLarge)
|
|
121
|
+
return [];
|
|
122
|
+
if (references.length > 0)
|
|
123
|
+
return references;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
logger.warn(`findRelatedSymbols failed or timed out for symbol '${symbolName}' in workspace '${workspacePath}' (lang: ${lang ?? 'mixed'})`, error);
|
|
127
|
+
}
|
|
128
|
+
// Fallback to in-memory symbol index only if explicitly enabled
|
|
129
|
+
if (ASTConfig.ENABLE_SYMBOL_INDEXING) {
|
|
130
|
+
return this.symbolIndex.get(symbolName) ?? [];
|
|
131
|
+
}
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
async executeSymbolSearch(symbolName, workspacePath, lang, references, markWorkspaceTooLarge) {
|
|
135
|
+
if (lang) {
|
|
136
|
+
await this.searchWithLang(lang, workspacePath, symbolName, references);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
await this.searchAllLanguages(workspacePath, symbolName, references, markWorkspaceTooLarge);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async searchWithLang(lang, workspacePath, symbolName, references) {
|
|
143
|
+
await new Promise((resolve) => {
|
|
144
|
+
findInFiles(lang, {
|
|
145
|
+
paths: [workspacePath],
|
|
146
|
+
matcher: { rule: { pattern: symbolName } },
|
|
147
|
+
}, (err, matches) => {
|
|
148
|
+
if (err !== null || matches.length === 0) {
|
|
149
|
+
resolve();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
matches.slice(0, ASTConfig.MAX_RESULTS_PER_SYMBOL).forEach((m) => {
|
|
153
|
+
const range = m.range();
|
|
154
|
+
references.push({
|
|
155
|
+
type: 'reference',
|
|
156
|
+
filePath: m.getRoot().filename(),
|
|
157
|
+
line: range.start.line + 1,
|
|
158
|
+
column: range.start.column,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
resolve();
|
|
162
|
+
}).catch(() => resolve());
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async searchAllLanguages(workspacePath, symbolName, references, markWorkspaceTooLarge) {
|
|
166
|
+
const filesByLanguage = new Map();
|
|
167
|
+
const files = await FastGlob(Object.keys(LANGUAGE_MAP).map((ext) => `**/*.${ext}`), {
|
|
168
|
+
cwd: workspacePath,
|
|
169
|
+
absolute: true,
|
|
170
|
+
onlyFiles: true,
|
|
171
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/build/**'],
|
|
172
|
+
});
|
|
173
|
+
// [CCR] Relation: Workspace size guard.
|
|
174
|
+
// Reason: Prevent OOM in very large monorepos by aborting if file count exceeds limit.
|
|
175
|
+
if (files.length > ASTConfig.MAX_WORKSPACE_FILES) {
|
|
176
|
+
logger.warn(`Workspace has ${files.length} files, exceeding limit of ${ASTConfig.MAX_WORKSPACE_FILES}. Skipping cross-file symbol search for ${symbolName}.`);
|
|
177
|
+
markWorkspaceTooLarge();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.groupFilesByLanguage(files, filesByLanguage);
|
|
181
|
+
await this.searchLanguageGroups(filesByLanguage, symbolName, references);
|
|
182
|
+
if (references.length > ASTConfig.MAX_RESULTS_PER_SYMBOL) {
|
|
183
|
+
references.length = ASTConfig.MAX_RESULTS_PER_SYMBOL;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
groupFilesByLanguage(files, filesByLanguage) {
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
const extension = path.extname(file).substring(1);
|
|
189
|
+
const fileLang = LANGUAGE_MAP[extension];
|
|
190
|
+
// eslint-disable-next-line sonarjs/nested-control-flow -- Existing structure is intentionally preserved; refactoring this boundary is outside the lint slice.
|
|
191
|
+
if (fileLang) {
|
|
192
|
+
if (!filesByLanguage.has(fileLang)) {
|
|
193
|
+
filesByLanguage.set(fileLang, new Set());
|
|
194
|
+
}
|
|
195
|
+
filesByLanguage.get(fileLang).add(file);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async searchLanguageGroups(filesByLanguage, symbolName, references) {
|
|
200
|
+
const promises = [];
|
|
201
|
+
for (const [searchLang, searchFiles] of filesByLanguage) {
|
|
202
|
+
const promise = new Promise((resolve) => {
|
|
203
|
+
findInFiles(searchLang, {
|
|
204
|
+
paths: Array.from(searchFiles),
|
|
205
|
+
matcher: { rule: { pattern: symbolName } },
|
|
206
|
+
}, (err, matches) => {
|
|
207
|
+
// eslint-disable-next-line sonarjs/nested-control-flow -- Existing structure is intentionally preserved; refactoring this boundary is outside the lint slice.
|
|
208
|
+
if (err !== null || matches.length === 0) {
|
|
209
|
+
resolve();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
matches.slice(0, ASTConfig.MAX_RESULTS_PER_SYMBOL).forEach((m) => {
|
|
213
|
+
const range = m.range();
|
|
214
|
+
references.push({
|
|
215
|
+
type: 'reference',
|
|
216
|
+
filePath: m.getRoot().filename(),
|
|
217
|
+
line: range.start.line + 1,
|
|
218
|
+
column: range.start.column,
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
resolve();
|
|
222
|
+
}).catch(() => resolve());
|
|
223
|
+
});
|
|
224
|
+
promises.push(promise);
|
|
225
|
+
}
|
|
226
|
+
await Promise.all(promises);
|
|
227
|
+
}
|
|
228
|
+
async findRelatedFiles(filePath) {
|
|
229
|
+
try {
|
|
230
|
+
const content = await fsPromises.readFile(filePath, 'utf-8');
|
|
231
|
+
const imports = extractImports(content, detectLanguage(filePath));
|
|
232
|
+
const relatedFiles = new Set();
|
|
233
|
+
for (const imp of imports) {
|
|
234
|
+
// Resolve relative path
|
|
235
|
+
const resolvedPath = this.resolveImportPath(imp.module, filePath);
|
|
236
|
+
if (resolvedPath && (await this.fileExists(resolvedPath))) {
|
|
237
|
+
relatedFiles.add(resolvedPath);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return Array.from(relatedFiles);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
resolveImportPath(importModule, currentFilePath) {
|
|
247
|
+
try {
|
|
248
|
+
const dir = path.dirname(currentFilePath);
|
|
249
|
+
const resolved = path.resolve(dir, importModule);
|
|
250
|
+
// If the import already has an extension that exists, use it directly
|
|
251
|
+
if (path.extname(resolved) && this.fileExistsSync(resolved)) {
|
|
252
|
+
return resolved;
|
|
253
|
+
}
|
|
254
|
+
// Try common extensions
|
|
255
|
+
const extensions = ['.ts', '.js', '.tsx', '.jsx'];
|
|
256
|
+
for (const ext of extensions) {
|
|
257
|
+
const withExt = resolved + ext;
|
|
258
|
+
if (this.fileExistsSync(withExt)) {
|
|
259
|
+
return withExt;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Try index files
|
|
263
|
+
for (const ext of extensions) {
|
|
264
|
+
const indexPath = path.join(resolved, `index${ext}`);
|
|
265
|
+
if (this.fileExistsSync(indexPath)) {
|
|
266
|
+
return indexPath;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async fileExists(filePath) {
|
|
276
|
+
try {
|
|
277
|
+
await fsPromises.access(filePath);
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
fileExistsSync(filePath) {
|
|
285
|
+
try {
|
|
286
|
+
accessSync(filePath);
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=cross-file-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-file-analyzer.js","sourceRoot":"","sources":["../../../../src/tools/ast-edit/cross-file-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AACxD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAA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C,EAAE,CAAC;oBACnC,OAAO,SAAS,CAAC;gBACnB,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,QAAgB;QACvC,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,cAAc,CAAC,QAAgB;QACrC,IAAI,CAAC;YACH,UAAU,CAAC,QAAQ,CAAC,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Vybestack LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Edit calculation logic for ast-edit tool.
|
|
7
|
+
* Contains calculateEdit, validation, and helper functions.
|
|
8
|
+
*/
|
|
9
|
+
import type { IToolHost } from '../../interfaces/index.js';
|
|
10
|
+
import type { ASTEditToolParams } from './types.js';
|
|
11
|
+
import { ToolErrorType } from '../../types/tool-error.js';
|
|
12
|
+
/**
|
|
13
|
+
* Result of edit calculation, including validation and freshness checks.
|
|
14
|
+
*/
|
|
15
|
+
export interface CalculatedEdit {
|
|
16
|
+
currentContent: string | null;
|
|
17
|
+
newContent: string;
|
|
18
|
+
occurrences: number;
|
|
19
|
+
error?: {
|
|
20
|
+
display: string;
|
|
21
|
+
raw: string;
|
|
22
|
+
type: ToolErrorType;
|
|
23
|
+
};
|
|
24
|
+
isNewFile: boolean;
|
|
25
|
+
astValidation?: {
|
|
26
|
+
valid: boolean;
|
|
27
|
+
errors: string[];
|
|
28
|
+
};
|
|
29
|
+
fileFreshness?: number | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Calculates the edit to be applied, including validation and freshness checks.
|
|
33
|
+
*
|
|
34
|
+
* @param params - Edit parameters
|
|
35
|
+
* @param host - Tool host interface
|
|
36
|
+
* @param _abortSignal - Abort signal (currently unused)
|
|
37
|
+
* @returns Calculated edit result with validation info
|
|
38
|
+
*/
|
|
39
|
+
export declare function calculateEdit(params: ASTEditToolParams, host: IToolHost, _abortSignal: AbortSignal): Promise<CalculatedEdit>;
|
|
40
|
+
/**
|
|
41
|
+
* Counts occurrences that will be replaced (0 or 1).
|
|
42
|
+
* Returns 0/1 not true count, aligned with String.replace() single-replacement semantics.
|
|
43
|
+
*
|
|
44
|
+
* @param content - File content
|
|
45
|
+
* @param searchString - String to search for
|
|
46
|
+
* @returns 0 if not found, 1 if found
|
|
47
|
+
*/
|
|
48
|
+
export declare function countOccurrences(content: string, searchString: string): number;
|
|
49
|
+
/**
|
|
50
|
+
* Validates AST syntax for the given file path and content.
|
|
51
|
+
* Inspects the tree-sitter parse tree for ERROR nodes and zero-width
|
|
52
|
+
* phantom nodes (MISSING tokens inserted by error recovery) rather than
|
|
53
|
+
* relying on thrown exceptions (tree-sitter is error-recovering and
|
|
54
|
+
* never throws on syntax errors).
|
|
55
|
+
*
|
|
56
|
+
* @param filePath - File path (used to detect language)
|
|
57
|
+
* @param content - File content to validate
|
|
58
|
+
* @returns Validation result
|
|
59
|
+
*/
|
|
60
|
+
export declare function validateASTSyntax(filePath: string, content: string): {
|
|
61
|
+
valid: boolean;
|
|
62
|
+
errors: string[];
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Gets the last modified timestamp of a file.
|
|
66
|
+
* Returns null if file doesn't exist.
|
|
67
|
+
*
|
|
68
|
+
* @param filePath - Path to the file
|
|
69
|
+
* @returns Timestamp in milliseconds or null
|
|
70
|
+
*/
|
|
71
|
+
export declare function getFileLastModified(filePath: string): Promise<number | null>;
|