@vybestack/llxprt-code-core 0.1.12
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/dist/.last_build +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__mocks__/fs/promises.d.ts +11 -0
- package/dist/src/__mocks__/fs/promises.js +17 -0
- package/dist/src/__mocks__/fs/promises.js.map +1 -0
- package/dist/src/code_assist/codeAssist.d.ts +9 -0
- package/dist/src/code_assist/codeAssist.js +19 -0
- package/dist/src/code_assist/codeAssist.js.map +1 -0
- package/dist/src/code_assist/converter.d.ts +68 -0
- package/dist/src/code_assist/converter.js +125 -0
- package/dist/src/code_assist/converter.js.map +1 -0
- package/dist/src/code_assist/converter.test.d.ts +6 -0
- package/dist/src/code_assist/converter.test.js +229 -0
- package/dist/src/code_assist/converter.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +20 -0
- package/dist/src/code_assist/oauth2.js +339 -0
- package/dist/src/code_assist/oauth2.js.map +1 -0
- package/dist/src/code_assist/oauth2.test.d.ts +6 -0
- package/dist/src/code_assist/oauth2.test.js +249 -0
- package/dist/src/code_assist/oauth2.test.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +39 -0
- package/dist/src/code_assist/server.js +191 -0
- package/dist/src/code_assist/server.js.map +1 -0
- package/dist/src/code_assist/server.test.d.ts +6 -0
- package/dist/src/code_assist/server.test.js +123 -0
- package/dist/src/code_assist/server.test.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +15 -0
- package/dist/src/code_assist/setup.js +67 -0
- package/dist/src/code_assist/setup.js.map +1 -0
- package/dist/src/code_assist/setup.test.d.ts +6 -0
- package/dist/src/code_assist/setup.test.js +62 -0
- package/dist/src/code_assist/setup.test.js.map +1 -0
- package/dist/src/code_assist/types.d.ts +148 -0
- package/dist/src/code_assist/types.js +46 -0
- package/dist/src/code_assist/types.js.map +1 -0
- package/dist/src/config/config.d.ts +212 -0
- package/dist/src/config/config.js +454 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/config.test.d.ts +6 -0
- package/dist/src/config/config.test.js +291 -0
- package/dist/src/config/config.test.js.map +1 -0
- package/dist/src/config/flashFallback.test.d.ts +6 -0
- package/dist/src/config/flashFallback.test.js +115 -0
- package/dist/src/config/flashFallback.test.js.map +1 -0
- package/dist/src/config/models.d.ts +8 -0
- package/dist/src/config/models.js +9 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/core/client.d.ts +59 -0
- package/dist/src/core/client.js +503 -0
- package/dist/src/core/client.js.map +1 -0
- package/dist/src/core/client.test.d.ts +6 -0
- package/dist/src/core/client.test.js +1006 -0
- package/dist/src/core/client.test.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +36 -0
- package/dist/src/core/contentGenerator.js +79 -0
- package/dist/src/core/contentGenerator.js.map +1 -0
- package/dist/src/core/contentGenerator.test.d.ts +6 -0
- package/dist/src/core/contentGenerator.test.js +92 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +104 -0
- package/dist/src/core/coreToolScheduler.js +413 -0
- package/dist/src/core/coreToolScheduler.js.map +1 -0
- package/dist/src/core/coreToolScheduler.test.d.ts +6 -0
- package/dist/src/core/coreToolScheduler.test.js +347 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +116 -0
- package/dist/src/core/geminiChat.js +513 -0
- package/dist/src/core/geminiChat.js.map +1 -0
- package/dist/src/core/geminiChat.test.d.ts +6 -0
- package/dist/src/core/geminiChat.test.js +424 -0
- package/dist/src/core/geminiChat.test.js.map +1 -0
- package/dist/src/core/geminiRequest.d.ts +13 -0
- package/dist/src/core/geminiRequest.js +45 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/geminiRequest.test.d.ts +6 -0
- package/dist/src/core/geminiRequest.test.js +72 -0
- package/dist/src/core/geminiRequest.test.js.map +1 -0
- package/dist/src/core/logger.d.ts +38 -0
- package/dist/src/core/logger.js +237 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/logger.test.d.ts +6 -0
- package/dist/src/core/logger.test.js +387 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/core/modelCheck.d.ts +14 -0
- package/dist/src/core/modelCheck.js +55 -0
- package/dist/src/core/modelCheck.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +12 -0
- package/dist/src/core/nonInteractiveToolExecutor.js +93 -0
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +6 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js +180 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
- package/dist/src/core/prompts.d.ts +12 -0
- package/dist/src/core/prompts.js +418 -0
- package/dist/src/core/prompts.js.map +1 -0
- package/dist/src/core/prompts.test.d.ts +6 -0
- package/dist/src/core/prompts.test.js +97 -0
- package/dist/src/core/prompts.test.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +10 -0
- package/dist/src/core/tokenLimits.js +75 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/tokenLimits.test.d.ts +6 -0
- package/dist/src/core/tokenLimits.test.js +66 -0
- package/dist/src/core/tokenLimits.test.js.map +1 -0
- package/dist/src/core/turn.d.ts +116 -0
- package/dist/src/core/turn.js +131 -0
- package/dist/src/core/turn.js.map +1 -0
- package/dist/src/core/turn.test.d.ts +6 -0
- package/dist/src/core/turn.test.js +237 -0
- package/dist/src/core/turn.test.js.map +1 -0
- package/dist/src/index.d.ts +57 -0
- package/dist/src/index.js +64 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.test.d.ts +6 -0
- package/dist/src/index.test.js +12 -0
- package/dist/src/index.test.js.map +1 -0
- package/dist/src/providers/ProviderContentGenerator.d.ts +21 -0
- package/dist/src/providers/ProviderContentGenerator.js +52 -0
- package/dist/src/providers/ProviderContentGenerator.js.map +1 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.d.ts +68 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.js +549 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.js.map +1 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.d.ts +6 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +253 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +1 -0
- package/dist/src/providers/types.d.ts +82 -0
- package/dist/src/providers/types.js +7 -0
- package/dist/src/providers/types.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.d.ts +35 -0
- package/dist/src/services/fileDiscoveryService.js +91 -0
- package/dist/src/services/fileDiscoveryService.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.test.d.ts +6 -0
- package/dist/src/services/fileDiscoveryService.test.js +102 -0
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -0
- package/dist/src/services/gitService.d.ts +21 -0
- package/dist/src/services/gitService.js +102 -0
- package/dist/src/services/gitService.js.map +1 -0
- package/dist/src/services/gitService.test.d.ts +6 -0
- package/dist/src/services/gitService.test.js +246 -0
- package/dist/src/services/gitService.test.js.map +1 -0
- package/dist/src/services/ideContext.d.ts +124 -0
- package/dist/src/services/ideContext.js +90 -0
- package/dist/src/services/ideContext.js.map +1 -0
- package/dist/src/services/ideContext.test.d.ts +6 -0
- package/dist/src/services/ideContext.test.js +101 -0
- package/dist/src/services/ideContext.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +35 -0
- package/dist/src/services/loopDetectionService.js +117 -0
- package/dist/src/services/loopDetectionService.js.map +1 -0
- package/dist/src/services/loopDetectionService.test.d.ts +6 -0
- package/dist/src/services/loopDetectionService.test.js +232 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +35 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +424 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +47 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +123 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +20 -0
- package/dist/src/telemetry/constants.js +21 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +18 -0
- package/dist/src/telemetry/index.js +20 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
- package/dist/src/telemetry/integration.test.circular.js +53 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +15 -0
- package/dist/src/telemetry/loggers.js +229 -0
- package/dist/src/telemetry/loggers.js.map +1 -0
- package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.circular.js +100 -0
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.test.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.js +558 -0
- package/dist/src/telemetry/loggers.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +19 -0
- package/dist/src/telemetry/metrics.js +144 -0
- package/dist/src/telemetry/metrics.js.map +1 -0
- package/dist/src/telemetry/metrics.test.d.ts +6 -0
- package/dist/src/telemetry/metrics.test.js +162 -0
- package/dist/src/telemetry/metrics.test.js.map +1 -0
- package/dist/src/telemetry/sdk.d.ts +9 -0
- package/dist/src/telemetry/sdk.js +120 -0
- package/dist/src/telemetry/sdk.js.map +1 -0
- package/dist/src/telemetry/telemetry.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry.test.js +52 -0
- package/dist/src/telemetry/telemetry.test.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +115 -0
- package/dist/src/telemetry/types.js +217 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +67 -0
- package/dist/src/telemetry/uiTelemetry.js +131 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.test.d.ts +6 -0
- package/dist/src/telemetry/uiTelemetry.test.js +412 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +7 -0
- package/dist/src/tools/diffOptions.js +10 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/edit.d.ts +73 -0
- package/dist/src/tools/edit.js +343 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/edit.test.d.ts +6 -0
- package/dist/src/tools/edit.test.js +500 -0
- package/dist/src/tools/edit.test.js.map +1 -0
- package/dist/src/tools/glob.d.ts +58 -0
- package/dist/src/tools/glob.js +193 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/glob.test.d.ts +6 -0
- package/dist/src/tools/glob.test.js +294 -0
- package/dist/src/tools/glob.test.js.map +1 -0
- package/dist/src/tools/grep.d.ts +78 -0
- package/dist/src/tools/grep.js +422 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/grep.test.d.ts +6 -0
- package/dist/src/tools/grep.test.js +188 -0
- package/dist/src/tools/grep.test.js.map +1 -0
- package/dist/src/tools/ls.d.ts +83 -0
- package/dist/src/tools/ls.js +194 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +112 -0
- package/dist/src/tools/mcp-client.js +332 -0
- package/dist/src/tools/mcp-client.js.map +1 -0
- package/dist/src/tools/mcp-client.test.d.ts +6 -0
- package/dist/src/tools/mcp-client.test.js +227 -0
- package/dist/src/tools/mcp-client.test.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +23 -0
- package/dist/src/tools/mcp-tool.js +119 -0
- package/dist/src/tools/mcp-tool.js.map +1 -0
- package/dist/src/tools/mcp-tool.test.d.ts +6 -0
- package/dist/src/tools/mcp-tool.test.js +173 -0
- package/dist/src/tools/mcp-tool.test.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +28 -0
- package/dist/src/tools/memoryTool.js +172 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/memoryTool.test.d.ts +6 -0
- package/dist/src/tools/memoryTool.test.js +181 -0
- package/dist/src/tools/memoryTool.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +29 -0
- package/dist/src/tools/modifiable-tool.js +85 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.test.d.ts +6 -0
- package/dist/src/tools/modifiable-tool.test.js +204 -0
- package/dist/src/tools/modifiable-tool.test.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +35 -0
- package/dist/src/tools/read-file.js +106 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-file.test.d.ts +6 -0
- package/dist/src/tools/read-file.test.js +181 -0
- package/dist/src/tools/read-file.test.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +59 -0
- package/dist/src/tools/read-many-files.js +321 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/read-many-files.test.d.ts +6 -0
- package/dist/src/tools/read-many-files.test.js +312 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +43 -0
- package/dist/src/tools/shell.js +435 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/shell.test.d.ts +6 -0
- package/dist/src/tools/shell.test.js +407 -0
- package/dist/src/tools/shell.test.js.map +1 -0
- package/dist/src/tools/todo-read.d.ts +15 -0
- package/dist/src/tools/todo-read.js +66 -0
- package/dist/src/tools/todo-read.js.map +1 -0
- package/dist/src/tools/todo-read.test.d.ts +6 -0
- package/dist/src/tools/todo-read.test.js +158 -0
- package/dist/src/tools/todo-read.test.js.map +1 -0
- package/dist/src/tools/todo-schemas.d.ts +43 -0
- package/dist/src/tools/todo-schemas.js +16 -0
- package/dist/src/tools/todo-schemas.js.map +1 -0
- package/dist/src/tools/todo-schemas.test.d.ts +6 -0
- package/dist/src/tools/todo-schemas.test.js +152 -0
- package/dist/src/tools/todo-schemas.test.js.map +1 -0
- package/dist/src/tools/todo-store.d.ts +15 -0
- package/dist/src/tools/todo-store.js +59 -0
- package/dist/src/tools/todo-store.js.map +1 -0
- package/dist/src/tools/todo-store.test.d.ts +6 -0
- package/dist/src/tools/todo-store.test.js +175 -0
- package/dist/src/tools/todo-store.test.js.map +1 -0
- package/dist/src/tools/todo-write.d.ts +17 -0
- package/dist/src/tools/todo-write.js +98 -0
- package/dist/src/tools/todo-write.js.map +1 -0
- package/dist/src/tools/todo-write.test.d.ts +6 -0
- package/dist/src/tools/todo-write.test.js +208 -0
- package/dist/src/tools/todo-write.test.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +67 -0
- package/dist/src/tools/tool-registry.js +326 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tool-registry.test.d.ts +6 -0
- package/dist/src/tools/tool-registry.test.js +398 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -0
- package/dist/src/tools/tools.d.ts +184 -0
- package/dist/src/tools/tools.js +88 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +29 -0
- package/dist/src/tools/web-fetch.js +243 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/tools/web-fetch.test.d.ts +6 -0
- package/dist/src/tools/web-fetch.test.js +70 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -0
- package/dist/src/tools/web-search.d.ts +49 -0
- package/dist/src/tools/web-search.js +120 -0
- package/dist/src/tools/web-search.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +42 -0
- package/dist/src/tools/write-file.js +248 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/tools/write-file.test.d.ts +6 -0
- package/dist/src/tools/write-file.test.js +413 -0
- package/dist/src/tools/write-file.test.js.map +1 -0
- package/dist/src/utils/LruCache.d.ts +13 -0
- package/dist/src/utils/LruCache.js +38 -0
- package/dist/src/utils/LruCache.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +22 -0
- package/dist/src/utils/bfsFileSearch.js +62 -0
- package/dist/src/utils/bfsFileSearch.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.test.d.ts +6 -0
- package/dist/src/utils/bfsFileSearch.test.js +129 -0
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
- package/dist/src/utils/editCorrector.d.ts +53 -0
- package/dist/src/utils/editCorrector.js +546 -0
- package/dist/src/utils/editCorrector.js.map +1 -0
- package/dist/src/utils/editCorrector.test.d.ts +6 -0
- package/dist/src/utils/editCorrector.test.js +564 -0
- package/dist/src/utils/editCorrector.test.js.map +1 -0
- package/dist/src/utils/editor.d.ts +28 -0
- package/dist/src/utils/editor.js +163 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/editor.test.d.ts +6 -0
- package/dist/src/utils/editor.test.js +293 -0
- package/dist/src/utils/editor.test.js.map +1 -0
- package/dist/src/utils/errorReporting.d.ts +14 -0
- package/dist/src/utils/errorReporting.js +88 -0
- package/dist/src/utils/errorReporting.js.map +1 -0
- package/dist/src/utils/errorReporting.test.d.ts +6 -0
- package/dist/src/utils/errorReporting.test.js +124 -0
- package/dist/src/utils/errorReporting.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +14 -0
- package/dist/src/utils/errors.js +54 -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 +51 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +49 -0
- package/dist/src/utils/fileUtils.js +286 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/fileUtils.test.d.ts +6 -0
- package/dist/src/utils/fileUtils.test.js +321 -0
- package/dist/src/utils/fileUtils.test.js.map +1 -0
- package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.integration.test.js +112 -0
- package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +14 -0
- package/dist/src/utils/generateContentResponseUtilities.js +92 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.test.d.ts +6 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js +273 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +30 -0
- package/dist/src/utils/getFolderStructure.js +247 -0
- package/dist/src/utils/getFolderStructure.js.map +1 -0
- package/dist/src/utils/getFolderStructure.test.d.ts +6 -0
- package/dist/src/utils/getFolderStructure.test.js +298 -0
- package/dist/src/utils/getFolderStructure.test.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.d.ts +20 -0
- package/dist/src/utils/gitIgnoreParser.js +64 -0
- package/dist/src/utils/gitIgnoreParser.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.test.d.ts +6 -0
- package/dist/src/utils/gitIgnoreParser.test.js +145 -0
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +17 -0
- package/dist/src/utils/gitUtils.js +61 -0
- package/dist/src/utils/gitUtils.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.d.ts +14 -0
- package/dist/src/utils/memoryDiscovery.js +219 -0
- package/dist/src/utils/memoryDiscovery.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.test.d.ts +6 -0
- package/dist/src/utils/memoryDiscovery.test.js +432 -0
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +35 -0
- package/dist/src/utils/memoryImportProcessor.js +141 -0
- package/dist/src/utils/memoryImportProcessor.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.test.d.ts +6 -0
- package/dist/src/utils/memoryImportProcessor.test.js +170 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -0
- package/dist/src/utils/messageInspectors.d.ts +8 -0
- package/dist/src/utils/messageInspectors.js +16 -0
- package/dist/src/utils/messageInspectors.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
- package/dist/src/utils/nextSpeakerChecker.js +113 -0
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.test.d.ts +6 -0
- package/dist/src/utils/nextSpeakerChecker.test.js +168 -0
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +49 -0
- package/dist/src/utils/paths.js +145 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +22 -0
- package/dist/src/utils/quotaErrorDetection.js +67 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/retry.d.ts +21 -0
- package/dist/src/utils/retry.js +276 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/retry.test.d.ts +6 -0
- package/dist/src/utils/retry.test.js +322 -0
- package/dist/src/utils/retry.test.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +13 -0
- package/dist/src/utils/safeJsonStringify.js +25 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
- package/dist/src/utils/safeJsonStringify.test.js +61 -0
- package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +23 -0
- package/dist/src/utils/schemaValidator.js +142 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/schemaValidator.test.d.ts +6 -0
- package/dist/src/utils/schemaValidator.test.js +146 -0
- package/dist/src/utils/schemaValidator.test.js.map +1 -0
- package/dist/src/utils/session.d.ts +6 -0
- package/dist/src/utils/session.js +8 -0
- package/dist/src/utils/session.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +25 -0
- package/dist/src/utils/summarizer.js +80 -0
- package/dist/src/utils/summarizer.js.map +1 -0
- package/dist/src/utils/summarizer.test.d.ts +6 -0
- package/dist/src/utils/summarizer.test.js +131 -0
- package/dist/src/utils/summarizer.test.js.map +1 -0
- package/dist/src/utils/testUtils.d.ts +29 -0
- package/dist/src/utils/testUtils.js +70 -0
- package/dist/src/utils/testUtils.js.map +1 -0
- package/dist/src/utils/user_account.d.ts +9 -0
- package/dist/src/utils/user_account.js +99 -0
- package/dist/src/utils/user_account.js.map +1 -0
- package/dist/src/utils/user_account.test.d.ts +6 -0
- package/dist/src/utils/user_account.test.js +153 -0
- package/dist/src/utils/user_account.test.js.map +1 -0
- package/dist/src/utils/user_id.d.ts +11 -0
- package/dist/src/utils/user_id.js +49 -0
- package/dist/src/utils/user_id.js.map +1 -0
- package/dist/src/utils/user_id.test.d.ts +6 -0
- package/dist/src/utils/user_id.test.js +21 -0
- package/dist/src/utils/user_id.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vybestack-llxprt-code-core-0.1.12.tgz +0 -0
- package/package.json +62 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import fsPromises from 'fs/promises';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { EOL } from 'os';
|
|
10
|
+
import { spawn } from 'child_process';
|
|
11
|
+
import { globStream } from 'glob';
|
|
12
|
+
import { BaseTool } from './tools.js';
|
|
13
|
+
import { Type } from '@google/genai';
|
|
14
|
+
import { SchemaValidator } from '../utils/schemaValidator.js';
|
|
15
|
+
import { makeRelative, shortenPath } from '../utils/paths.js';
|
|
16
|
+
import { getErrorMessage, isNodeError } from '../utils/errors.js';
|
|
17
|
+
import { isGitRepository } from '../utils/gitUtils.js';
|
|
18
|
+
// --- GrepLogic Class ---
|
|
19
|
+
/**
|
|
20
|
+
* Implementation of the Grep tool logic (moved from CLI)
|
|
21
|
+
*/
|
|
22
|
+
export class GrepTool extends BaseTool {
|
|
23
|
+
config;
|
|
24
|
+
static Name = 'search_file_content'; // Keep static name
|
|
25
|
+
constructor(config) {
|
|
26
|
+
super(GrepTool.Name, 'SearchFileContent', 'Searches for a regular expression pattern within the content of files in a specified directory (or current working directory). Can filter files by a glob pattern. Returns the lines containing matches, along with their file paths and line numbers. IMPORTANT: This tool expects regular expression patterns, not literal strings.', {
|
|
27
|
+
properties: {
|
|
28
|
+
pattern: {
|
|
29
|
+
description: "The regular expression (regex) pattern to search for within file contents. Special characters like ( ) [ ] { } . * + ? ^ $ \\ | must be escaped with a backslash. Examples: 'openModelDialog\\(' to find 'openModelDialog(', 'function\\s+myFunction' to find function declarations, '\\.test\\.' to find '.test.' in filenames.",
|
|
30
|
+
type: Type.STRING,
|
|
31
|
+
},
|
|
32
|
+
path: {
|
|
33
|
+
description: 'Optional: The absolute path to the directory to search within. If omitted, searches the current working directory.',
|
|
34
|
+
type: Type.STRING,
|
|
35
|
+
},
|
|
36
|
+
include: {
|
|
37
|
+
description: "Optional: A glob pattern to filter which files are searched (e.g., '*.js', '*.{ts,tsx}', 'src/**'). If omitted, searches all files (respecting potential global ignores).",
|
|
38
|
+
type: Type.STRING,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
required: ['pattern'],
|
|
42
|
+
type: Type.OBJECT,
|
|
43
|
+
});
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
// --- Validation Methods ---
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a path is within the root directory and resolves it.
|
|
49
|
+
* @param relativePath Path relative to the root directory (or undefined for root).
|
|
50
|
+
* @returns The absolute path if valid and exists.
|
|
51
|
+
* @throws {Error} If path is outside root, doesn't exist, or isn't a directory.
|
|
52
|
+
*/
|
|
53
|
+
resolveAndValidatePath(relativePath) {
|
|
54
|
+
const targetPath = path.resolve(this.config.getTargetDir(), relativePath || '.');
|
|
55
|
+
// Security Check: Ensure the resolved path is still within the root directory.
|
|
56
|
+
if (!targetPath.startsWith(this.config.getTargetDir()) &&
|
|
57
|
+
targetPath !== this.config.getTargetDir()) {
|
|
58
|
+
throw new Error(`Path validation failed: Attempted path "${relativePath || '.'}" resolves outside the allowed root directory "${this.config.getTargetDir()}".`);
|
|
59
|
+
}
|
|
60
|
+
// Check existence and type after resolving
|
|
61
|
+
try {
|
|
62
|
+
const stats = fs.statSync(targetPath);
|
|
63
|
+
if (!stats.isDirectory()) {
|
|
64
|
+
throw new Error(`Path is not a directory: ${targetPath}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (isNodeError(error) && error.code !== 'ENOENT') {
|
|
69
|
+
throw new Error(`Path does not exist: ${targetPath}`);
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`Failed to access path stats for ${targetPath}: ${error}`);
|
|
72
|
+
}
|
|
73
|
+
return targetPath;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validates the parameters for the tool
|
|
77
|
+
* @param params Parameters to validate
|
|
78
|
+
* @returns An error message string if invalid, null otherwise
|
|
79
|
+
*/
|
|
80
|
+
validateToolParams(params) {
|
|
81
|
+
const errors = SchemaValidator.validate(this.schema.parameters, params);
|
|
82
|
+
if (errors) {
|
|
83
|
+
return errors;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
new RegExp(params.pattern);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return `Invalid regular expression pattern provided: ${params.pattern}. Error: ${getErrorMessage(error)}`;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
this.resolveAndValidatePath(params.path);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return getErrorMessage(error);
|
|
96
|
+
}
|
|
97
|
+
return null; // Parameters are valid
|
|
98
|
+
}
|
|
99
|
+
// --- Core Execution ---
|
|
100
|
+
/**
|
|
101
|
+
* Executes the grep search with the given parameters
|
|
102
|
+
* @param params Parameters for the grep search
|
|
103
|
+
* @returns Result of the grep search
|
|
104
|
+
*/
|
|
105
|
+
async execute(params, signal) {
|
|
106
|
+
const validationError = this.validateToolParams(params);
|
|
107
|
+
if (validationError) {
|
|
108
|
+
return {
|
|
109
|
+
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
|
110
|
+
returnDisplay: `Model provided invalid parameters. Error: ${validationError}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
let searchDirAbs;
|
|
114
|
+
try {
|
|
115
|
+
searchDirAbs = this.resolveAndValidatePath(params.path);
|
|
116
|
+
const searchDirDisplay = params.path || '.';
|
|
117
|
+
const matches = await this.performGrepSearch({
|
|
118
|
+
pattern: params.pattern,
|
|
119
|
+
path: searchDirAbs,
|
|
120
|
+
include: params.include,
|
|
121
|
+
signal,
|
|
122
|
+
});
|
|
123
|
+
if (matches.length === 0) {
|
|
124
|
+
const noMatchMsg = `No matches found for pattern "${params.pattern}" in path "${searchDirDisplay}"${params.include ? ` (filter: "${params.include}")` : ''}.`;
|
|
125
|
+
return { llmContent: noMatchMsg, returnDisplay: `No matches found` };
|
|
126
|
+
}
|
|
127
|
+
const matchesByFile = matches.reduce((acc, match) => {
|
|
128
|
+
const relativeFilePath = path.relative(searchDirAbs, path.resolve(searchDirAbs, match.filePath)) || path.basename(match.filePath);
|
|
129
|
+
if (!acc[relativeFilePath]) {
|
|
130
|
+
acc[relativeFilePath] = [];
|
|
131
|
+
}
|
|
132
|
+
acc[relativeFilePath].push(match);
|
|
133
|
+
acc[relativeFilePath].sort((a, b) => a.lineNumber - b.lineNumber);
|
|
134
|
+
return acc;
|
|
135
|
+
}, {});
|
|
136
|
+
const matchCount = matches.length;
|
|
137
|
+
const matchTerm = matchCount === 1 ? 'match' : 'matches';
|
|
138
|
+
let llmContent = `Found ${matchCount} ${matchTerm} for pattern "${params.pattern}" in path "${searchDirDisplay}"${params.include ? ` (filter: "${params.include}")` : ''}:\n---\n`;
|
|
139
|
+
for (const filePath in matchesByFile) {
|
|
140
|
+
llmContent += `File: ${filePath}\n`;
|
|
141
|
+
matchesByFile[filePath].forEach((match) => {
|
|
142
|
+
const trimmedLine = match.line.trim();
|
|
143
|
+
llmContent += `L${match.lineNumber}: ${trimmedLine}\n`;
|
|
144
|
+
});
|
|
145
|
+
llmContent += '---\n';
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
llmContent: llmContent.trim(),
|
|
149
|
+
returnDisplay: `Found ${matchCount} ${matchTerm}`,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.error(`Error during GrepLogic execution: ${error}`);
|
|
154
|
+
const errorMessage = getErrorMessage(error);
|
|
155
|
+
return {
|
|
156
|
+
llmContent: `Error during grep search operation: ${errorMessage}`,
|
|
157
|
+
returnDisplay: `Error: ${errorMessage}`,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// --- Grep Implementation Logic ---
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a command is available in the system's PATH.
|
|
164
|
+
* @param {string} command The command name (e.g., 'git', 'grep').
|
|
165
|
+
* @returns {Promise<boolean>} True if the command is available, false otherwise.
|
|
166
|
+
*/
|
|
167
|
+
isCommandAvailable(command) {
|
|
168
|
+
return new Promise((resolve) => {
|
|
169
|
+
const checkCommand = process.platform === 'win32' ? 'where' : 'command';
|
|
170
|
+
const checkArgs = process.platform === 'win32' ? [command] : ['-v', command];
|
|
171
|
+
try {
|
|
172
|
+
const child = spawn(checkCommand, checkArgs, {
|
|
173
|
+
stdio: 'ignore',
|
|
174
|
+
shell: process.platform === 'win32',
|
|
175
|
+
});
|
|
176
|
+
child.on('close', (code) => resolve(code === 0));
|
|
177
|
+
child.on('error', () => resolve(false));
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
resolve(false);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Parses the standard output of grep-like commands (git grep, system grep).
|
|
186
|
+
* Expects format: filePath:lineNumber:lineContent
|
|
187
|
+
* Handles colons within file paths and line content correctly.
|
|
188
|
+
* @param {string} output The raw stdout string.
|
|
189
|
+
* @param {string} basePath The absolute directory the search was run from, for relative paths.
|
|
190
|
+
* @returns {GrepMatch[]} Array of match objects.
|
|
191
|
+
*/
|
|
192
|
+
parseGrepOutput(output, basePath) {
|
|
193
|
+
const results = [];
|
|
194
|
+
if (!output)
|
|
195
|
+
return results;
|
|
196
|
+
const lines = output.split(EOL); // Use OS-specific end-of-line
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
if (!line.trim())
|
|
199
|
+
continue;
|
|
200
|
+
// Find the index of the first colon.
|
|
201
|
+
const firstColonIndex = line.indexOf(':');
|
|
202
|
+
if (firstColonIndex === -1)
|
|
203
|
+
continue; // Malformed
|
|
204
|
+
// Find the index of the second colon, searching *after* the first one.
|
|
205
|
+
const secondColonIndex = line.indexOf(':', firstColonIndex + 1);
|
|
206
|
+
if (secondColonIndex === -1)
|
|
207
|
+
continue; // Malformed
|
|
208
|
+
// Extract parts based on the found colon indices
|
|
209
|
+
const filePathRaw = line.substring(0, firstColonIndex);
|
|
210
|
+
const lineNumberStr = line.substring(firstColonIndex + 1, secondColonIndex);
|
|
211
|
+
const lineContent = line.substring(secondColonIndex + 1);
|
|
212
|
+
const lineNumber = parseInt(lineNumberStr, 10);
|
|
213
|
+
if (!isNaN(lineNumber)) {
|
|
214
|
+
const absoluteFilePath = path.resolve(basePath, filePathRaw);
|
|
215
|
+
const relativeFilePath = path.relative(basePath, absoluteFilePath);
|
|
216
|
+
results.push({
|
|
217
|
+
filePath: relativeFilePath || path.basename(absoluteFilePath),
|
|
218
|
+
lineNumber,
|
|
219
|
+
line: lineContent,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return results;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Gets a description of the grep operation
|
|
227
|
+
* @param params Parameters for the grep operation
|
|
228
|
+
* @returns A string describing the grep
|
|
229
|
+
*/
|
|
230
|
+
getDescription(params) {
|
|
231
|
+
let description = `'${params.pattern}'`;
|
|
232
|
+
if (params.include) {
|
|
233
|
+
description += ` in ${params.include}`;
|
|
234
|
+
}
|
|
235
|
+
if (params.path) {
|
|
236
|
+
const resolvedPath = path.resolve(this.config.getTargetDir(), params.path);
|
|
237
|
+
if (resolvedPath === this.config.getTargetDir() || params.path === '.') {
|
|
238
|
+
description += ` within ./`;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const relativePath = makeRelative(resolvedPath, this.config.getTargetDir());
|
|
242
|
+
description += ` within ${shortenPath(relativePath)}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return description;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Performs the actual search using the prioritized strategies.
|
|
249
|
+
* @param options Search options including pattern, absolute path, and include glob.
|
|
250
|
+
* @returns A promise resolving to an array of match objects.
|
|
251
|
+
*/
|
|
252
|
+
async performGrepSearch(options) {
|
|
253
|
+
const { pattern, path: absolutePath, include } = options;
|
|
254
|
+
let strategyUsed = 'none';
|
|
255
|
+
try {
|
|
256
|
+
// --- Strategy 1: git grep ---
|
|
257
|
+
const isGit = isGitRepository(absolutePath);
|
|
258
|
+
const gitAvailable = isGit && (await this.isCommandAvailable('git'));
|
|
259
|
+
if (gitAvailable) {
|
|
260
|
+
strategyUsed = 'git grep';
|
|
261
|
+
const gitArgs = [
|
|
262
|
+
'grep',
|
|
263
|
+
'--untracked',
|
|
264
|
+
'-n',
|
|
265
|
+
'-E',
|
|
266
|
+
'--ignore-case',
|
|
267
|
+
pattern,
|
|
268
|
+
];
|
|
269
|
+
if (include) {
|
|
270
|
+
gitArgs.push('--', include);
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const output = await new Promise((resolve, reject) => {
|
|
274
|
+
const child = spawn('git', gitArgs, {
|
|
275
|
+
cwd: absolutePath,
|
|
276
|
+
windowsHide: true,
|
|
277
|
+
});
|
|
278
|
+
const stdoutChunks = [];
|
|
279
|
+
const stderrChunks = [];
|
|
280
|
+
child.stdout.on('data', (chunk) => stdoutChunks.push(chunk));
|
|
281
|
+
child.stderr.on('data', (chunk) => stderrChunks.push(chunk));
|
|
282
|
+
child.on('error', (err) => reject(new Error(`Failed to start git grep: ${err.message}`)));
|
|
283
|
+
child.on('close', (code) => {
|
|
284
|
+
const stdoutData = Buffer.concat(stdoutChunks).toString('utf8');
|
|
285
|
+
const stderrData = Buffer.concat(stderrChunks).toString('utf8');
|
|
286
|
+
if (code === 0)
|
|
287
|
+
resolve(stdoutData);
|
|
288
|
+
else if (code === 1)
|
|
289
|
+
resolve(''); // No matches
|
|
290
|
+
else
|
|
291
|
+
reject(new Error(`git grep exited with code ${code}: ${stderrData}`));
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
return this.parseGrepOutput(output, absolutePath);
|
|
295
|
+
}
|
|
296
|
+
catch (gitError) {
|
|
297
|
+
console.debug(`GrepLogic: git grep failed: ${getErrorMessage(gitError)}. Falling back...`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// --- Strategy 2: System grep ---
|
|
301
|
+
const grepAvailable = await this.isCommandAvailable('grep');
|
|
302
|
+
if (grepAvailable) {
|
|
303
|
+
strategyUsed = 'system grep';
|
|
304
|
+
const grepArgs = ['-r', '-n', '-H', '-E'];
|
|
305
|
+
const commonExcludes = ['.git', 'node_modules', 'bower_components'];
|
|
306
|
+
commonExcludes.forEach((dir) => grepArgs.push(`--exclude-dir=${dir}`));
|
|
307
|
+
if (include) {
|
|
308
|
+
grepArgs.push(`--include=${include}`);
|
|
309
|
+
}
|
|
310
|
+
grepArgs.push(pattern);
|
|
311
|
+
grepArgs.push('.');
|
|
312
|
+
try {
|
|
313
|
+
const output = await new Promise((resolve, reject) => {
|
|
314
|
+
const child = spawn('grep', grepArgs, {
|
|
315
|
+
cwd: absolutePath,
|
|
316
|
+
windowsHide: true,
|
|
317
|
+
});
|
|
318
|
+
const stdoutChunks = [];
|
|
319
|
+
const stderrChunks = [];
|
|
320
|
+
const onData = (chunk) => stdoutChunks.push(chunk);
|
|
321
|
+
const onStderr = (chunk) => {
|
|
322
|
+
const stderrStr = chunk.toString();
|
|
323
|
+
// Suppress common harmless stderr messages
|
|
324
|
+
if (!stderrStr.includes('Permission denied') &&
|
|
325
|
+
!/grep:.*: Is a directory/i.test(stderrStr)) {
|
|
326
|
+
stderrChunks.push(chunk);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const onError = (err) => {
|
|
330
|
+
cleanup();
|
|
331
|
+
reject(new Error(`Failed to start system grep: ${err.message}`));
|
|
332
|
+
};
|
|
333
|
+
const onClose = (code) => {
|
|
334
|
+
const stdoutData = Buffer.concat(stdoutChunks).toString('utf8');
|
|
335
|
+
const stderrData = Buffer.concat(stderrChunks)
|
|
336
|
+
.toString('utf8')
|
|
337
|
+
.trim();
|
|
338
|
+
cleanup();
|
|
339
|
+
if (code === 0)
|
|
340
|
+
resolve(stdoutData);
|
|
341
|
+
else if (code === 1)
|
|
342
|
+
resolve(''); // No matches
|
|
343
|
+
else {
|
|
344
|
+
if (stderrData)
|
|
345
|
+
reject(new Error(`System grep exited with code ${code}: ${stderrData}`));
|
|
346
|
+
else
|
|
347
|
+
resolve(''); // Exit code > 1 but no stderr, likely just suppressed errors
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
const cleanup = () => {
|
|
351
|
+
child.stdout.removeListener('data', onData);
|
|
352
|
+
child.stderr.removeListener('data', onStderr);
|
|
353
|
+
child.removeListener('error', onError);
|
|
354
|
+
child.removeListener('close', onClose);
|
|
355
|
+
if (child.connected) {
|
|
356
|
+
child.disconnect();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
child.stdout.on('data', onData);
|
|
360
|
+
child.stderr.on('data', onStderr);
|
|
361
|
+
child.on('error', onError);
|
|
362
|
+
child.on('close', onClose);
|
|
363
|
+
});
|
|
364
|
+
return this.parseGrepOutput(output, absolutePath);
|
|
365
|
+
}
|
|
366
|
+
catch (grepError) {
|
|
367
|
+
console.debug(`GrepLogic: System grep failed: ${getErrorMessage(grepError)}. Falling back...`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// --- Strategy 3: Pure JavaScript Fallback ---
|
|
371
|
+
console.debug('GrepLogic: Falling back to JavaScript grep implementation.');
|
|
372
|
+
strategyUsed = 'javascript fallback';
|
|
373
|
+
const globPattern = include ? include : '**/*';
|
|
374
|
+
const ignorePatterns = [
|
|
375
|
+
'.git/**',
|
|
376
|
+
'node_modules/**',
|
|
377
|
+
'bower_components/**',
|
|
378
|
+
'.svn/**',
|
|
379
|
+
'.hg/**',
|
|
380
|
+
]; // Use glob patterns for ignores here
|
|
381
|
+
const filesStream = globStream(globPattern, {
|
|
382
|
+
cwd: absolutePath,
|
|
383
|
+
dot: true,
|
|
384
|
+
ignore: ignorePatterns,
|
|
385
|
+
absolute: true,
|
|
386
|
+
nodir: true,
|
|
387
|
+
signal: options.signal,
|
|
388
|
+
});
|
|
389
|
+
const regex = new RegExp(pattern, 'i');
|
|
390
|
+
const allMatches = [];
|
|
391
|
+
for await (const filePath of filesStream) {
|
|
392
|
+
const fileAbsolutePath = filePath;
|
|
393
|
+
try {
|
|
394
|
+
const content = await fsPromises.readFile(fileAbsolutePath, 'utf8');
|
|
395
|
+
const lines = content.split(/\r?\n/);
|
|
396
|
+
lines.forEach((line, index) => {
|
|
397
|
+
if (regex.test(line)) {
|
|
398
|
+
allMatches.push({
|
|
399
|
+
filePath: path.relative(absolutePath, fileAbsolutePath) ||
|
|
400
|
+
path.basename(fileAbsolutePath),
|
|
401
|
+
lineNumber: index + 1,
|
|
402
|
+
line,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
catch (readError) {
|
|
408
|
+
// Ignore errors like permission denied or file gone during read
|
|
409
|
+
if (!isNodeError(readError) || readError.code !== 'ENOENT') {
|
|
410
|
+
console.debug(`GrepLogic: Could not read/process ${fileAbsolutePath}: ${getErrorMessage(readError)}`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return allMatches;
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
console.error(`GrepLogic: Error in performGrepSearch (Strategy: ${strategyUsed}): ${getErrorMessage(error)}`);
|
|
418
|
+
throw error; // Re-throw
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=grep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/tools/grep.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACl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;gBACL,CAAC;gBAAC,OAAO,SAAkB,EAAE,CAAC;oBAC5B,gEAAgE;oBAChE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;wBAC3D,OAAO,CAAC,KAAK,CACX,qCAAqC,gBAAgB,KAAK,eAAe,CAAC,SAAS,CAAC,EAAE,CACvF,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;YAED,OAAO,UAAU,CAAC;QACpB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CACX,oDAAoD,YAAY,MAAM,eAAe,CAAC,KAAK,CAAC,EAAE,CAC/F,CAAC;YACF,MAAM,KAAK,CAAC,CAAC,WAAW;QAC1B,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
7
|
+
import { GrepTool } from './grep.js';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import fs from 'fs/promises';
|
|
10
|
+
import os from 'os';
|
|
11
|
+
// Mock the child_process module to control grep/git grep behavior
|
|
12
|
+
vi.mock('child_process', () => ({
|
|
13
|
+
spawn: vi.fn(() => ({
|
|
14
|
+
on: (event, cb) => {
|
|
15
|
+
if (event === 'error' || event === 'close') {
|
|
16
|
+
// Simulate command not found or error for git grep and system grep
|
|
17
|
+
// to force fallback to JS implementation.
|
|
18
|
+
setTimeout(() => cb(1), 0); // cb(1) for error/close
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
stdout: { on: vi.fn() },
|
|
22
|
+
stderr: { on: vi.fn() },
|
|
23
|
+
})),
|
|
24
|
+
}));
|
|
25
|
+
describe('GrepTool', () => {
|
|
26
|
+
let tempRootDir;
|
|
27
|
+
let grepTool;
|
|
28
|
+
const abortSignal = new AbortController().signal;
|
|
29
|
+
const mockConfig = {
|
|
30
|
+
getTargetDir: () => tempRootDir,
|
|
31
|
+
};
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
tempRootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-root-'));
|
|
34
|
+
grepTool = new GrepTool(mockConfig);
|
|
35
|
+
// Create some test files and directories
|
|
36
|
+
await fs.writeFile(path.join(tempRootDir, 'fileA.txt'), 'hello world\nsecond line with world');
|
|
37
|
+
await fs.writeFile(path.join(tempRootDir, 'fileB.js'), 'const foo = "bar";\nfunction baz() { return "hello"; }');
|
|
38
|
+
await fs.mkdir(path.join(tempRootDir, 'sub'));
|
|
39
|
+
await fs.writeFile(path.join(tempRootDir, 'sub', 'fileC.txt'), 'another world in sub dir');
|
|
40
|
+
await fs.writeFile(path.join(tempRootDir, 'sub', 'fileD.md'), '# Markdown file\nThis is a test.');
|
|
41
|
+
});
|
|
42
|
+
afterEach(async () => {
|
|
43
|
+
await fs.rm(tempRootDir, { recursive: true, force: true });
|
|
44
|
+
});
|
|
45
|
+
describe('validateToolParams', () => {
|
|
46
|
+
it('should return null for valid params (pattern only)', () => {
|
|
47
|
+
const params = { pattern: 'hello' };
|
|
48
|
+
expect(grepTool.validateToolParams(params)).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
it('should return null for valid params (pattern and path)', () => {
|
|
51
|
+
const params = { pattern: 'hello', path: '.' };
|
|
52
|
+
expect(grepTool.validateToolParams(params)).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
it('should return null for valid params (pattern, path, and include)', () => {
|
|
55
|
+
const params = {
|
|
56
|
+
pattern: 'hello',
|
|
57
|
+
path: '.',
|
|
58
|
+
include: '*.txt',
|
|
59
|
+
};
|
|
60
|
+
expect(grepTool.validateToolParams(params)).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
it('should return error if pattern is missing', () => {
|
|
63
|
+
const params = { path: '.' };
|
|
64
|
+
expect(grepTool.validateToolParams(params)).toBe(`params must have required property 'pattern'`);
|
|
65
|
+
});
|
|
66
|
+
it('should return error for invalid regex pattern', () => {
|
|
67
|
+
const params = { pattern: '[[' };
|
|
68
|
+
expect(grepTool.validateToolParams(params)).toContain('Invalid regular expression pattern');
|
|
69
|
+
});
|
|
70
|
+
it('should return error if path does not exist', () => {
|
|
71
|
+
const params = { pattern: 'hello', path: 'nonexistent' };
|
|
72
|
+
// Check for the core error message, as the full path might vary
|
|
73
|
+
expect(grepTool.validateToolParams(params)).toContain('Failed to access path stats for');
|
|
74
|
+
expect(grepTool.validateToolParams(params)).toContain('nonexistent');
|
|
75
|
+
});
|
|
76
|
+
it('should return error if path is a file, not a directory', async () => {
|
|
77
|
+
const filePath = path.join(tempRootDir, 'fileA.txt');
|
|
78
|
+
const params = { pattern: 'hello', path: filePath };
|
|
79
|
+
expect(grepTool.validateToolParams(params)).toContain(`Path is not a directory: ${filePath}`);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('execute', () => {
|
|
83
|
+
it('should find matches for a simple pattern in all files', async () => {
|
|
84
|
+
const params = { pattern: 'world' };
|
|
85
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
86
|
+
expect(result.llmContent).toContain('Found 3 matches for pattern "world" in path "."');
|
|
87
|
+
expect(result.llmContent).toContain('File: fileA.txt');
|
|
88
|
+
expect(result.llmContent).toContain('L1: hello world');
|
|
89
|
+
expect(result.llmContent).toContain('L2: second line with world');
|
|
90
|
+
expect(result.llmContent).toContain('File: sub/fileC.txt');
|
|
91
|
+
expect(result.llmContent).toContain('L1: another world in sub dir');
|
|
92
|
+
expect(result.returnDisplay).toBe('Found 3 matches');
|
|
93
|
+
});
|
|
94
|
+
it('should find matches in a specific path', async () => {
|
|
95
|
+
const params = { pattern: 'world', path: 'sub' };
|
|
96
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
97
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "world" in path "sub"');
|
|
98
|
+
expect(result.llmContent).toContain('File: fileC.txt'); // Path relative to 'sub'
|
|
99
|
+
expect(result.llmContent).toContain('L1: another world in sub dir');
|
|
100
|
+
expect(result.returnDisplay).toBe('Found 1 match');
|
|
101
|
+
});
|
|
102
|
+
it('should find matches with an include glob', async () => {
|
|
103
|
+
const params = { pattern: 'hello', include: '*.js' };
|
|
104
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
105
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "hello" in path "." (filter: "*.js")');
|
|
106
|
+
expect(result.llmContent).toContain('File: fileB.js');
|
|
107
|
+
expect(result.llmContent).toContain('L2: function baz() { return "hello"; }');
|
|
108
|
+
expect(result.returnDisplay).toBe('Found 1 match');
|
|
109
|
+
});
|
|
110
|
+
it('should find matches with an include glob and path', async () => {
|
|
111
|
+
await fs.writeFile(path.join(tempRootDir, 'sub', 'another.js'), 'const greeting = "hello";');
|
|
112
|
+
const params = {
|
|
113
|
+
pattern: 'hello',
|
|
114
|
+
path: 'sub',
|
|
115
|
+
include: '*.js',
|
|
116
|
+
};
|
|
117
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
118
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "hello" in path "sub" (filter: "*.js")');
|
|
119
|
+
expect(result.llmContent).toContain('File: another.js');
|
|
120
|
+
expect(result.llmContent).toContain('L1: const greeting = "hello";');
|
|
121
|
+
expect(result.returnDisplay).toBe('Found 1 match');
|
|
122
|
+
});
|
|
123
|
+
it('should return "No matches found" when pattern does not exist', async () => {
|
|
124
|
+
const params = { pattern: 'nonexistentpattern' };
|
|
125
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
126
|
+
expect(result.llmContent).toContain('No matches found for pattern "nonexistentpattern" in path "."');
|
|
127
|
+
expect(result.returnDisplay).toBe('No matches found');
|
|
128
|
+
});
|
|
129
|
+
it('should handle regex special characters correctly', async () => {
|
|
130
|
+
const params = { pattern: 'foo.*bar' }; // Matches 'const foo = "bar";'
|
|
131
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
132
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "foo.*bar" in path "."');
|
|
133
|
+
expect(result.llmContent).toContain('File: fileB.js');
|
|
134
|
+
expect(result.llmContent).toContain('L1: const foo = "bar";');
|
|
135
|
+
});
|
|
136
|
+
it('should be case-insensitive by default (JS fallback)', async () => {
|
|
137
|
+
const params = { pattern: 'HELLO' };
|
|
138
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
139
|
+
expect(result.llmContent).toContain('Found 2 matches for pattern "HELLO" in path "."');
|
|
140
|
+
expect(result.llmContent).toContain('File: fileA.txt');
|
|
141
|
+
expect(result.llmContent).toContain('L1: hello world');
|
|
142
|
+
expect(result.llmContent).toContain('File: fileB.js');
|
|
143
|
+
expect(result.llmContent).toContain('L2: function baz() { return "hello"; }');
|
|
144
|
+
});
|
|
145
|
+
it('should return an error if params are invalid', async () => {
|
|
146
|
+
const params = { path: '.' }; // Invalid: pattern missing
|
|
147
|
+
const result = await grepTool.execute(params, abortSignal);
|
|
148
|
+
expect(result.llmContent).toBe("Error: Invalid parameters provided. Reason: params must have required property 'pattern'");
|
|
149
|
+
expect(result.returnDisplay).toBe("Model provided invalid parameters. Error: params must have required property 'pattern'");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('getDescription', () => {
|
|
153
|
+
it('should generate correct description with pattern only', () => {
|
|
154
|
+
const params = { pattern: 'testPattern' };
|
|
155
|
+
expect(grepTool.getDescription(params)).toBe("'testPattern'");
|
|
156
|
+
});
|
|
157
|
+
it('should generate correct description with pattern and include', () => {
|
|
158
|
+
const params = {
|
|
159
|
+
pattern: 'testPattern',
|
|
160
|
+
include: '*.ts',
|
|
161
|
+
};
|
|
162
|
+
expect(grepTool.getDescription(params)).toBe("'testPattern' in *.ts");
|
|
163
|
+
});
|
|
164
|
+
it('should generate correct description with pattern and path', () => {
|
|
165
|
+
const params = {
|
|
166
|
+
pattern: 'testPattern',
|
|
167
|
+
path: 'src/app',
|
|
168
|
+
};
|
|
169
|
+
// The path will be relative to the tempRootDir, so we check for containment.
|
|
170
|
+
expect(grepTool.getDescription(params)).toContain("'testPattern' within");
|
|
171
|
+
expect(grepTool.getDescription(params)).toContain(path.join('src', 'app'));
|
|
172
|
+
});
|
|
173
|
+
it('should generate correct description with pattern, include, and path', () => {
|
|
174
|
+
const params = {
|
|
175
|
+
pattern: 'testPattern',
|
|
176
|
+
include: '*.ts',
|
|
177
|
+
path: 'src/app',
|
|
178
|
+
};
|
|
179
|
+
expect(grepTool.getDescription(params)).toContain("'testPattern' in *.ts within");
|
|
180
|
+
expect(grepTool.getDescription(params)).toContain('src/app');
|
|
181
|
+
});
|
|
182
|
+
it('should use ./ for root path in description', () => {
|
|
183
|
+
const params = { pattern: 'testPattern', path: '.' };
|
|
184
|
+
expect(grepTool.getDescription(params)).toBe("'testPattern' within ./");
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
//# sourceMappingURL=grep.test.js.map
|