@office-ai/aioncli-core 0.1.1-8.1
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 +70 -0
- package/dist/src/code_assist/converter.js +126 -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 +279 -0
- package/dist/src/code_assist/converter.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +24 -0
- package/dist/src/code_assist/oauth2.js +373 -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 +334 -0
- package/dist/src/code_assist/oauth2.test.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +37 -0
- package/dist/src/code_assist/server.js +125 -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 +134 -0
- package/dist/src/code_assist/server.test.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +20 -0
- package/dist/src/code_assist/setup.js +70 -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 +65 -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 +272 -0
- package/dist/src/config/config.js +554 -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 +365 -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 +87 -0
- package/dist/src/config/flashFallback.test.js.map +1 -0
- package/dist/src/config/models.d.ts +9 -0
- package/dist/src/config/models.js +10 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/core/client.d.ts +61 -0
- package/dist/src/core/client.js +485 -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 +1008 -0
- package/dist/src/core/client.test.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +45 -0
- package/dist/src/core/contentGenerator.js +85 -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 +100 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +117 -0
- package/dist/src/core/coreToolScheduler.js +530 -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 +625 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +118 -0
- package/dist/src/core/geminiChat.js +509 -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 +10 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/logger.d.ts +37 -0
- package/dist/src/core/logger.js +273 -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 +467 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/core/loggingContentGenerator.d.ts +24 -0
- package/dist/src/core/loggingContentGenerator.js +89 -0
- package/dist/src/core/loggingContentGenerator.js.map +1 -0
- package/dist/src/core/modelCheck.d.ts +14 -0
- package/dist/src/core/modelCheck.js +62 -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 +124 -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 +165 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
- package/dist/src/core/openaiContentGenerator.d.ts +77 -0
- package/dist/src/core/openaiContentGenerator.js +1395 -0
- package/dist/src/core/openaiContentGenerator.js.map +1 -0
- package/dist/src/core/openaiContentGenerator.test.d.ts +6 -0
- package/dist/src/core/openaiContentGenerator.test.js +1904 -0
- package/dist/src/core/openaiContentGenerator.test.js.map +1 -0
- package/dist/src/core/prompts.d.ts +12 -0
- package/dist/src/core/prompts.js +359 -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 +214 -0
- package/dist/src/core/prompts.test.js.map +1 -0
- package/dist/src/core/subagent.d.ts +230 -0
- package/dist/src/core/subagent.js +447 -0
- package/dist/src/core/subagent.js.map +1 -0
- package/dist/src/core/subagent.test.d.ts +6 -0
- package/dist/src/core/subagent.test.js +515 -0
- package/dist/src/core/subagent.test.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +10 -0
- package/dist/src/core/tokenLimits.js +28 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/turn.d.ts +114 -0
- package/dist/src/core/turn.js +143 -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 +369 -0
- package/dist/src/core/turn.test.js.map +1 -0
- package/dist/src/ide/detect-ide.d.ts +10 -0
- package/dist/src/ide/detect-ide.js +27 -0
- package/dist/src/ide/detect-ide.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +56 -0
- package/dist/src/ide/ide-client.js +268 -0
- package/dist/src/ide/ide-client.js.map +1 -0
- package/dist/src/ide/ide-installer.d.ts +14 -0
- package/dist/src/ide/ide-installer.js +109 -0
- package/dist/src/ide/ide-installer.js.map +1 -0
- package/dist/src/ide/ide-installer.test.d.ts +6 -0
- package/dist/src/ide/ide-installer.test.js +55 -0
- package/dist/src/ide/ide-installer.test.js.map +1 -0
- package/dist/src/ide/ideContext.d.ts +374 -0
- package/dist/src/ide/ideContext.js +147 -0
- package/dist/src/ide/ideContext.js.map +1 -0
- package/dist/src/ide/ideContext.test.d.ts +6 -0
- package/dist/src/ide/ideContext.test.js +265 -0
- package/dist/src/ide/ideContext.test.js.map +1 -0
- package/dist/src/index.d.ts +68 -0
- package/dist/src/index.js +78 -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/mcp/google-auth-provider.d.ts +23 -0
- package/dist/src/mcp/google-auth-provider.js +63 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
- package/dist/src/mcp/google-auth-provider.test.js +54 -0
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +147 -0
- package/dist/src/mcp/oauth-provider.js +484 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.test.d.ts +6 -0
- package/dist/src/mcp/oauth-provider.test.js +602 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +83 -0
- package/dist/src/mcp/oauth-token-storage.js +151 -0
- package/dist/src/mcp/oauth-token-storage.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/oauth-token-storage.test.js +205 -0
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +109 -0
- package/dist/src/mcp/oauth-utils.js +183 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -0
- package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
- package/dist/src/mcp/oauth-utils.test.js +144 -0
- package/dist/src/mcp/oauth-utils.test.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +8 -0
- package/dist/src/prompts/mcp-prompts.js +13 -0
- package/dist/src/prompts/mcp-prompts.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +34 -0
- package/dist/src/prompts/prompt-registry.js +63 -0
- package/dist/src/prompts/prompt-registry.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 +143 -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 +101 -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 +209 -0
- package/dist/src/services/gitService.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +97 -0
- package/dist/src/services/loopDetectionService.js +340 -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 +484 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/services/shellExecutionService.d.ts +70 -0
- package/dist/src/services/shellExecutionService.js +175 -0
- package/dist/src/services/shellExecutionService.js.map +1 -0
- package/dist/src/services/shellExecutionService.test.d.ts +6 -0
- package/dist/src/services/shellExecutionService.test.js +272 -0
- package/dist/src/services/shellExecutionService.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +65 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +652 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +6 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +186 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +59 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +159 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +23 -0
- package/dist/src/telemetry/constants.js +24 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/file-exporters.d.ts +28 -0
- package/dist/src/telemetry/file-exporters.js +62 -0
- package/dist/src/telemetry/file-exporters.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 +18 -0
- package/dist/src/telemetry/loggers.js +268 -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 +107 -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 +568 -0
- package/dist/src/telemetry/loggers.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +20 -0
- package/dist/src/telemetry/metrics.js +150 -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 +212 -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 +127 -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 +50 -0
- package/dist/src/telemetry/telemetry.test.js.map +1 -0
- package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
- package/dist/src/telemetry/tool-call-decision.js +29 -0
- package/dist/src/telemetry/tool-call-decision.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +145 -0
- package/dist/src/telemetry/types.js +267 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +71 -0
- package/dist/src/telemetry/uiTelemetry.js +140 -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 +518 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
- package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
- package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
- package/dist/src/test-utils/tools.d.ts +23 -0
- package/dist/src/test-utils/tools.js +41 -0
- package/dist/src/test-utils/tools.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +9 -0
- package/dist/src/tools/diffOptions.js +38 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/diffOptions.test.d.ts +6 -0
- package/dist/src/tools/diffOptions.test.js +119 -0
- package/dist/src/tools/diffOptions.test.js.map +1 -0
- package/dist/src/tools/edit.d.ts +55 -0
- package/dist/src/tools/edit.js +398 -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 +681 -0
- package/dist/src/tools/edit.test.js.map +1 -0
- package/dist/src/tools/glob.d.ts +51 -0
- package/dist/src/tools/glob.js +226 -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 +330 -0
- package/dist/src/tools/glob.test.js.map +1 -0
- package/dist/src/tools/grep.d.ts +46 -0
- package/dist/src/tools/grep.js +503 -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 +272 -0
- package/dist/src/tools/grep.test.js.map +1 -0
- package/dist/src/tools/ls.d.ts +86 -0
- package/dist/src/tools/ls.js +224 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/ls.test.d.ts +6 -0
- package/dist/src/tools/ls.test.js +356 -0
- package/dist/src/tools/ls.test.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +149 -0
- package/dist/src/tools/mcp-client.js +844 -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 +643 -0
- package/dist/src/tools/mcp-client.test.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +29 -0
- package/dist/src/tools/mcp-tool.js +202 -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 +501 -0
- package/dist/src/tools/mcp-tool.test.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +43 -0
- package/dist/src/tools/memoryTool.js +290 -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 +266 -0
- package/dist/src/tools/memoryTool.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +32 -0
- package/dist/src/tools/modifiable-tool.js +88 -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 +193 -0
- package/dist/src/tools/modifiable-tool.test.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +34 -0
- package/dist/src/tools/read-file.js +152 -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 +300 -0
- package/dist/src/tools/read-file.test.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +61 -0
- package/dist/src/tools/read-many-files.js +421 -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 +455 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +23 -0
- package/dist/src/tools/shell.js +313 -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 +321 -0
- package/dist/src/tools/shell.test.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +26 -0
- package/dist/src/tools/tool-error.js +31 -0
- package/dist/src/tools/tool-error.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +85 -0
- package/dist/src/tools/tool-registry.js +390 -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 +417 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -0
- package/dist/src/tools/tools.d.ts +328 -0
- package/dist/src/tools/tools.js +281 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/tools.test.d.ts +6 -0
- package/dist/src/tools/tools.test.js +117 -0
- package/dist/src/tools/tools.test.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +29 -0
- package/dist/src/tools/web-fetch.js +246 -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 +71 -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 +46 -0
- package/dist/src/tools/write-file.js +321 -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 +572 -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 +24 -0
- package/dist/src/utils/bfsFileSearch.js +89 -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 +163 -0
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +49 -0
- package/dist/src/utils/browser.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 +186 -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 +445 -0
- package/dist/src/utils/editor.test.js.map +1 -0
- package/dist/src/utils/environmentContext.d.ts +21 -0
- package/dist/src/utils/environmentContext.js +90 -0
- package/dist/src/utils/environmentContext.js.map +1 -0
- package/dist/src/utils/environmentContext.test.d.ts +6 -0
- package/dist/src/utils/environmentContext.test.js +139 -0
- package/dist/src/utils/environmentContext.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 +130 -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 +56 -0
- package/dist/src/utils/fileUtils.js +314 -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 +363 -0
- package/dist/src/utils/fileUtils.test.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
- package/dist/src/utils/filesearch/crawlCache.js +57 -0
- package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawlCache.test.js +103 -0
- package/dist/src/utils/filesearch/crawlCache.test.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.d.ts +81 -0
- package/dist/src/utils/filesearch/fileSearch.js +241 -0
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.test.d.ts +6 -0
- package/dist/src/utils/filesearch/fileSearch.test.js +654 -0
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.d.ts +35 -0
- package/dist/src/utils/filesearch/ignore.js +81 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.test.d.ts +6 -0
- package/dist/src/utils/filesearch/ignore.test.js +57 -0
- package/dist/src/utils/filesearch/ignore.test.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.d.ts +34 -0
- package/dist/src/utils/filesearch/result-cache.js +61 -0
- package/dist/src/utils/filesearch/result-cache.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/result-cache.test.js +47 -0
- package/dist/src/utils/filesearch/result-cache.test.js.map +1 -0
- package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.integration.test.js +118 -0
- package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
- package/dist/src/utils/formatters.d.ts +6 -0
- package/dist/src/utils/formatters.js +16 -0
- package/dist/src/utils/formatters.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 +31 -0
- package/dist/src/utils/getFolderStructure.js +246 -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 +282 -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 +61 -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 +154 -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 +15 -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 +181 -0
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +42 -0
- package/dist/src/utils/memoryImportProcessor.js +300 -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 +715 -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 +92 -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/partUtils.d.ts +14 -0
- package/dist/src/utils/partUtils.js +65 -0
- package/dist/src/utils/partUtils.js.map +1 -0
- package/dist/src/utils/partUtils.test.d.ts +6 -0
- package/dist/src/utils/partUtils.test.js +130 -0
- package/dist/src/utils/partUtils.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +68 -0
- package/dist/src/utils/paths.js +170 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/paths.test.d.ts +6 -0
- package/dist/src/utils/paths.test.js +153 -0
- package/dist/src/utils/paths.test.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +22 -0
- package/dist/src/utils/quotaErrorDetection.js +65 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/retry.d.ts +30 -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 +22 -0
- package/dist/src/utils/schemaValidator.js +65 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
- package/dist/src/utils/secure-browser-launcher.js +164 -0
- package/dist/src/utils/secure-browser-launcher.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
- package/dist/src/utils/secure-browser-launcher.test.js +149 -0
- package/dist/src/utils/secure-browser-launcher.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/shell-utils.d.ts +78 -0
- package/dist/src/utils/shell-utils.js +306 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils/shell-utils.test.d.ts +6 -0
- package/dist/src/utils/shell-utils.test.js +200 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +25 -0
- package/dist/src/utils/summarizer.js +51 -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/systemEncoding.d.ts +40 -0
- package/dist/src/utils/systemEncoding.js +149 -0
- package/dist/src/utils/systemEncoding.js.map +1 -0
- package/dist/src/utils/systemEncoding.test.d.ts +6 -0
- package/dist/src/utils/systemEncoding.test.js +368 -0
- package/dist/src/utils/systemEncoding.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/textUtils.d.ts +13 -0
- package/dist/src/utils/textUtils.js +28 -0
- package/dist/src/utils/textUtils.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/src/utils/workspaceContext.d.ts +51 -0
- package/dist/src/utils/workspaceContext.js +139 -0
- package/dist/src/utils/workspaceContext.js.map +1 -0
- package/dist/src/utils/workspaceContext.test.d.ts +6 -0
- package/dist/src/utils/workspaceContext.test.js +209 -0
- package/dist/src/utils/workspaceContext.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
|
|
12
|
+
// Mock the child_process module to control grep/git grep behavior
|
|
13
|
+
vi.mock('child_process', () => ({
|
|
14
|
+
spawn: vi.fn(() => ({
|
|
15
|
+
on: (event, cb) => {
|
|
16
|
+
if (event === 'error' || event === 'close') {
|
|
17
|
+
// Simulate command not found or error for git grep and system grep
|
|
18
|
+
// to force it to fall back to JS implementation.
|
|
19
|
+
setTimeout(() => cb(1), 0); // cb(1) for error/close
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
stdout: { on: vi.fn() },
|
|
23
|
+
stderr: { on: vi.fn() },
|
|
24
|
+
})),
|
|
25
|
+
}));
|
|
26
|
+
describe('GrepTool', () => {
|
|
27
|
+
let tempRootDir;
|
|
28
|
+
let grepTool;
|
|
29
|
+
const abortSignal = new AbortController().signal;
|
|
30
|
+
const mockConfig = {
|
|
31
|
+
getTargetDir: () => tempRootDir,
|
|
32
|
+
getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir),
|
|
33
|
+
};
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
tempRootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-root-'));
|
|
36
|
+
grepTool = new GrepTool(mockConfig);
|
|
37
|
+
// Create some test files and directories
|
|
38
|
+
await fs.writeFile(path.join(tempRootDir, 'fileA.txt'), 'hello world\nsecond line with world');
|
|
39
|
+
await fs.writeFile(path.join(tempRootDir, 'fileB.js'), 'const foo = "bar";\nfunction baz() { return "hello"; }');
|
|
40
|
+
await fs.mkdir(path.join(tempRootDir, 'sub'));
|
|
41
|
+
await fs.writeFile(path.join(tempRootDir, 'sub', 'fileC.txt'), 'another world in sub dir');
|
|
42
|
+
await fs.writeFile(path.join(tempRootDir, 'sub', 'fileD.md'), '# Markdown file\nThis is a test.');
|
|
43
|
+
});
|
|
44
|
+
afterEach(async () => {
|
|
45
|
+
await fs.rm(tempRootDir, { recursive: true, force: true });
|
|
46
|
+
});
|
|
47
|
+
describe('validateToolParams', () => {
|
|
48
|
+
it('should return null for valid params (pattern only)', () => {
|
|
49
|
+
const params = { pattern: 'hello' };
|
|
50
|
+
expect(grepTool.validateToolParams(params)).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
it('should return null for valid params (pattern and path)', () => {
|
|
53
|
+
const params = { pattern: 'hello', path: '.' };
|
|
54
|
+
expect(grepTool.validateToolParams(params)).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
it('should return null for valid params (pattern, path, and include)', () => {
|
|
57
|
+
const params = {
|
|
58
|
+
pattern: 'hello',
|
|
59
|
+
path: '.',
|
|
60
|
+
include: '*.txt',
|
|
61
|
+
};
|
|
62
|
+
expect(grepTool.validateToolParams(params)).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
it('should return error if pattern is missing', () => {
|
|
65
|
+
const params = { path: '.' };
|
|
66
|
+
expect(grepTool.validateToolParams(params)).toBe(`params must have required property 'pattern'`);
|
|
67
|
+
});
|
|
68
|
+
it('should return error for invalid regex pattern', () => {
|
|
69
|
+
const params = { pattern: '[[' };
|
|
70
|
+
expect(grepTool.validateToolParams(params)).toContain('Invalid regular expression pattern');
|
|
71
|
+
});
|
|
72
|
+
it('should return error if path does not exist', () => {
|
|
73
|
+
const params = { pattern: 'hello', path: 'nonexistent' };
|
|
74
|
+
// Check for the core error message, as the full path might vary
|
|
75
|
+
expect(grepTool.validateToolParams(params)).toContain('Failed to access path stats for');
|
|
76
|
+
expect(grepTool.validateToolParams(params)).toContain('nonexistent');
|
|
77
|
+
});
|
|
78
|
+
it('should return error if path is a file, not a directory', async () => {
|
|
79
|
+
const filePath = path.join(tempRootDir, 'fileA.txt');
|
|
80
|
+
const params = { pattern: 'hello', path: filePath };
|
|
81
|
+
expect(grepTool.validateToolParams(params)).toContain(`Path is not a directory: ${filePath}`);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('execute', () => {
|
|
85
|
+
it('should find matches for a simple pattern in all files', async () => {
|
|
86
|
+
const params = { pattern: 'world' };
|
|
87
|
+
const invocation = grepTool.build(params);
|
|
88
|
+
const result = await invocation.execute(abortSignal);
|
|
89
|
+
expect(result.llmContent).toContain('Found 3 matches for pattern "world" in the workspace directory');
|
|
90
|
+
expect(result.llmContent).toContain('File: fileA.txt');
|
|
91
|
+
expect(result.llmContent).toContain('L1: hello world');
|
|
92
|
+
expect(result.llmContent).toContain('L2: second line with world');
|
|
93
|
+
expect(result.llmContent).toContain(`File: ${path.join('sub', 'fileC.txt')}`);
|
|
94
|
+
expect(result.llmContent).toContain('L1: another world in sub dir');
|
|
95
|
+
expect(result.returnDisplay).toBe('Found 3 matches');
|
|
96
|
+
});
|
|
97
|
+
it('should find matches in a specific path', async () => {
|
|
98
|
+
const params = { pattern: 'world', path: 'sub' };
|
|
99
|
+
const invocation = grepTool.build(params);
|
|
100
|
+
const result = await invocation.execute(abortSignal);
|
|
101
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "world" in path "sub"');
|
|
102
|
+
expect(result.llmContent).toContain('File: fileC.txt'); // Path relative to 'sub'
|
|
103
|
+
expect(result.llmContent).toContain('L1: another world in sub dir');
|
|
104
|
+
expect(result.returnDisplay).toBe('Found 1 match');
|
|
105
|
+
});
|
|
106
|
+
it('should find matches with an include glob', async () => {
|
|
107
|
+
const params = { pattern: 'hello', include: '*.js' };
|
|
108
|
+
const invocation = grepTool.build(params);
|
|
109
|
+
const result = await invocation.execute(abortSignal);
|
|
110
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "hello" in the workspace directory (filter: "*.js"):');
|
|
111
|
+
expect(result.llmContent).toContain('File: fileB.js');
|
|
112
|
+
expect(result.llmContent).toContain('L2: function baz() { return "hello"; }');
|
|
113
|
+
expect(result.returnDisplay).toBe('Found 1 match');
|
|
114
|
+
});
|
|
115
|
+
it('should find matches with an include glob and path', async () => {
|
|
116
|
+
await fs.writeFile(path.join(tempRootDir, 'sub', 'another.js'), 'const greeting = "hello";');
|
|
117
|
+
const params = {
|
|
118
|
+
pattern: 'hello',
|
|
119
|
+
path: 'sub',
|
|
120
|
+
include: '*.js',
|
|
121
|
+
};
|
|
122
|
+
const invocation = grepTool.build(params);
|
|
123
|
+
const result = await invocation.execute(abortSignal);
|
|
124
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "hello" in path "sub" (filter: "*.js")');
|
|
125
|
+
expect(result.llmContent).toContain('File: another.js');
|
|
126
|
+
expect(result.llmContent).toContain('L1: const greeting = "hello";');
|
|
127
|
+
expect(result.returnDisplay).toBe('Found 1 match');
|
|
128
|
+
});
|
|
129
|
+
it('should return "No matches found" when pattern does not exist', async () => {
|
|
130
|
+
const params = { pattern: 'nonexistentpattern' };
|
|
131
|
+
const invocation = grepTool.build(params);
|
|
132
|
+
const result = await invocation.execute(abortSignal);
|
|
133
|
+
expect(result.llmContent).toContain('No matches found for pattern "nonexistentpattern" in the workspace directory.');
|
|
134
|
+
expect(result.returnDisplay).toBe('No matches found');
|
|
135
|
+
});
|
|
136
|
+
it('should handle regex special characters correctly', async () => {
|
|
137
|
+
const params = { pattern: 'foo.*bar' }; // Matches 'const foo = "bar";'
|
|
138
|
+
const invocation = grepTool.build(params);
|
|
139
|
+
const result = await invocation.execute(abortSignal);
|
|
140
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "foo.*bar" in the workspace directory:');
|
|
141
|
+
expect(result.llmContent).toContain('File: fileB.js');
|
|
142
|
+
expect(result.llmContent).toContain('L1: const foo = "bar";');
|
|
143
|
+
});
|
|
144
|
+
it('should be case-insensitive by default (JS fallback)', async () => {
|
|
145
|
+
const params = { pattern: 'HELLO' };
|
|
146
|
+
const invocation = grepTool.build(params);
|
|
147
|
+
const result = await invocation.execute(abortSignal);
|
|
148
|
+
expect(result.llmContent).toContain('Found 2 matches for pattern "HELLO" in the workspace directory:');
|
|
149
|
+
expect(result.llmContent).toContain('File: fileA.txt');
|
|
150
|
+
expect(result.llmContent).toContain('L1: hello world');
|
|
151
|
+
expect(result.llmContent).toContain('File: fileB.js');
|
|
152
|
+
expect(result.llmContent).toContain('L2: function baz() { return "hello"; }');
|
|
153
|
+
});
|
|
154
|
+
it('should throw an error if params are invalid', async () => {
|
|
155
|
+
const params = { path: '.' }; // Invalid: pattern missing
|
|
156
|
+
expect(() => grepTool.build(params)).toThrow(/params must have required property 'pattern'/);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
describe('multi-directory workspace', () => {
|
|
160
|
+
it('should search across all workspace directories when no path is specified', async () => {
|
|
161
|
+
// Create additional directory with test files
|
|
162
|
+
const secondDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-second-'));
|
|
163
|
+
await fs.writeFile(path.join(secondDir, 'other.txt'), 'hello from second directory\nworld in second');
|
|
164
|
+
await fs.writeFile(path.join(secondDir, 'another.js'), 'function world() { return "test"; }');
|
|
165
|
+
// Create a mock config with multiple directories
|
|
166
|
+
const multiDirConfig = {
|
|
167
|
+
getTargetDir: () => tempRootDir,
|
|
168
|
+
getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir, [secondDir]),
|
|
169
|
+
};
|
|
170
|
+
const multiDirGrepTool = new GrepTool(multiDirConfig);
|
|
171
|
+
const params = { pattern: 'world' };
|
|
172
|
+
const invocation = multiDirGrepTool.build(params);
|
|
173
|
+
const result = await invocation.execute(abortSignal);
|
|
174
|
+
// Should find matches in both directories
|
|
175
|
+
expect(result.llmContent).toContain('Found 5 matches for pattern "world"');
|
|
176
|
+
// Matches from first directory
|
|
177
|
+
expect(result.llmContent).toContain('fileA.txt');
|
|
178
|
+
expect(result.llmContent).toContain('L1: hello world');
|
|
179
|
+
expect(result.llmContent).toContain('L2: second line with world');
|
|
180
|
+
expect(result.llmContent).toContain('fileC.txt');
|
|
181
|
+
expect(result.llmContent).toContain('L1: another world in sub dir');
|
|
182
|
+
// Matches from second directory (with directory name prefix)
|
|
183
|
+
const secondDirName = path.basename(secondDir);
|
|
184
|
+
expect(result.llmContent).toContain(`File: ${path.join(secondDirName, 'other.txt')}`);
|
|
185
|
+
expect(result.llmContent).toContain('L2: world in second');
|
|
186
|
+
expect(result.llmContent).toContain(`File: ${path.join(secondDirName, 'another.js')}`);
|
|
187
|
+
expect(result.llmContent).toContain('L1: function world()');
|
|
188
|
+
// Clean up
|
|
189
|
+
await fs.rm(secondDir, { recursive: true, force: true });
|
|
190
|
+
});
|
|
191
|
+
it('should search only specified path within workspace directories', async () => {
|
|
192
|
+
// Create additional directory
|
|
193
|
+
const secondDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-second-'));
|
|
194
|
+
await fs.mkdir(path.join(secondDir, 'sub'));
|
|
195
|
+
await fs.writeFile(path.join(secondDir, 'sub', 'test.txt'), 'hello from second sub directory');
|
|
196
|
+
// Create a mock config with multiple directories
|
|
197
|
+
const multiDirConfig = {
|
|
198
|
+
getTargetDir: () => tempRootDir,
|
|
199
|
+
getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir, [secondDir]),
|
|
200
|
+
};
|
|
201
|
+
const multiDirGrepTool = new GrepTool(multiDirConfig);
|
|
202
|
+
// Search only in the 'sub' directory of the first workspace
|
|
203
|
+
const params = { pattern: 'world', path: 'sub' };
|
|
204
|
+
const invocation = multiDirGrepTool.build(params);
|
|
205
|
+
const result = await invocation.execute(abortSignal);
|
|
206
|
+
// Should only find matches in the specified sub directory
|
|
207
|
+
expect(result.llmContent).toContain('Found 1 match for pattern "world" in path "sub"');
|
|
208
|
+
expect(result.llmContent).toContain('File: fileC.txt');
|
|
209
|
+
expect(result.llmContent).toContain('L1: another world in sub dir');
|
|
210
|
+
// Should not contain matches from second directory
|
|
211
|
+
expect(result.llmContent).not.toContain('test.txt');
|
|
212
|
+
// Clean up
|
|
213
|
+
await fs.rm(secondDir, { recursive: true, force: true });
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
describe('getDescription', () => {
|
|
217
|
+
it('should generate correct description with pattern only', () => {
|
|
218
|
+
const params = { pattern: 'testPattern' };
|
|
219
|
+
const invocation = grepTool.build(params);
|
|
220
|
+
expect(invocation.getDescription()).toBe("'testPattern'");
|
|
221
|
+
});
|
|
222
|
+
it('should generate correct description with pattern and include', () => {
|
|
223
|
+
const params = {
|
|
224
|
+
pattern: 'testPattern',
|
|
225
|
+
include: '*.ts',
|
|
226
|
+
};
|
|
227
|
+
const invocation = grepTool.build(params);
|
|
228
|
+
expect(invocation.getDescription()).toBe("'testPattern' in *.ts");
|
|
229
|
+
});
|
|
230
|
+
it('should generate correct description with pattern and path', async () => {
|
|
231
|
+
const dirPath = path.join(tempRootDir, 'src', 'app');
|
|
232
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
233
|
+
const params = {
|
|
234
|
+
pattern: 'testPattern',
|
|
235
|
+
path: path.join('src', 'app'),
|
|
236
|
+
};
|
|
237
|
+
const invocation = grepTool.build(params);
|
|
238
|
+
// The path will be relative to the tempRootDir, so we check for containment.
|
|
239
|
+
expect(invocation.getDescription()).toContain("'testPattern' within");
|
|
240
|
+
expect(invocation.getDescription()).toContain(path.join('src', 'app'));
|
|
241
|
+
});
|
|
242
|
+
it('should indicate searching across all workspace directories when no path specified', () => {
|
|
243
|
+
// Create a mock config with multiple directories
|
|
244
|
+
const multiDirConfig = {
|
|
245
|
+
getTargetDir: () => tempRootDir,
|
|
246
|
+
getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir, ['/another/dir']),
|
|
247
|
+
};
|
|
248
|
+
const multiDirGrepTool = new GrepTool(multiDirConfig);
|
|
249
|
+
const params = { pattern: 'testPattern' };
|
|
250
|
+
const invocation = multiDirGrepTool.build(params);
|
|
251
|
+
expect(invocation.getDescription()).toBe("'testPattern' across all workspace directories");
|
|
252
|
+
});
|
|
253
|
+
it('should generate correct description with pattern, include, and path', async () => {
|
|
254
|
+
const dirPath = path.join(tempRootDir, 'src', 'app');
|
|
255
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
256
|
+
const params = {
|
|
257
|
+
pattern: 'testPattern',
|
|
258
|
+
include: '*.ts',
|
|
259
|
+
path: path.join('src', 'app'),
|
|
260
|
+
};
|
|
261
|
+
const invocation = grepTool.build(params);
|
|
262
|
+
expect(invocation.getDescription()).toContain("'testPattern' in *.ts within");
|
|
263
|
+
expect(invocation.getDescription()).toContain(path.join('src', 'app'));
|
|
264
|
+
});
|
|
265
|
+
it('should use ./ for root path in description', () => {
|
|
266
|
+
const params = { pattern: 'testPattern', path: '.' };
|
|
267
|
+
const invocation = grepTool.build(params);
|
|
268
|
+
expect(invocation.getDescription()).toBe("'testPattern' within ./");
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
//# sourceMappingURL=grep.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.test.js","sourceRoot":"","sources":["../../../src/tools/grep.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAkB,MAAM,WAAW,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAEnF,kEAAkE;AAClE,EAAE,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9B,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QAClB,EAAE,EAAE,CAAC,KAAa,EAAE,EAAgC,EAAE,EAAE;YACtD,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;gBAC3C,mEAAmE;gBACnE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AK,CAAC,MAAM,CAAC,CAAC;YAC1C,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseTool, ToolResult } from './tools.js';
|
|
7
|
+
import { Config } from '../config/config.js';
|
|
8
|
+
/**
|
|
9
|
+
* Parameters for the LS tool
|
|
10
|
+
*/
|
|
11
|
+
export interface LSToolParams {
|
|
12
|
+
/**
|
|
13
|
+
* The absolute path to the directory to list
|
|
14
|
+
*/
|
|
15
|
+
path: string;
|
|
16
|
+
/**
|
|
17
|
+
* Array of glob patterns to ignore (optional)
|
|
18
|
+
*/
|
|
19
|
+
ignore?: string[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether to respect .gitignore and .geminiignore patterns (optional, defaults to true)
|
|
22
|
+
*/
|
|
23
|
+
file_filtering_options?: {
|
|
24
|
+
respect_git_ignore?: boolean;
|
|
25
|
+
respect_gemini_ignore?: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* File entry returned by LS tool
|
|
30
|
+
*/
|
|
31
|
+
export interface FileEntry {
|
|
32
|
+
/**
|
|
33
|
+
* Name of the file or directory
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* Absolute path to the file or directory
|
|
38
|
+
*/
|
|
39
|
+
path: string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether this entry is a directory
|
|
42
|
+
*/
|
|
43
|
+
isDirectory: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Size of the file in bytes (0 for directories)
|
|
46
|
+
*/
|
|
47
|
+
size: number;
|
|
48
|
+
/**
|
|
49
|
+
* Last modified timestamp
|
|
50
|
+
*/
|
|
51
|
+
modifiedTime: Date;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Implementation of the LS tool logic
|
|
55
|
+
*/
|
|
56
|
+
export declare class LSTool extends BaseTool<LSToolParams, ToolResult> {
|
|
57
|
+
private config;
|
|
58
|
+
static readonly Name = "list_directory";
|
|
59
|
+
constructor(config: Config);
|
|
60
|
+
/**
|
|
61
|
+
* Validates the parameters for the tool
|
|
62
|
+
* @param params Parameters to validate
|
|
63
|
+
* @returns An error message string if invalid, null otherwise
|
|
64
|
+
*/
|
|
65
|
+
validateToolParams(params: LSToolParams): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a filename matches any of the ignore patterns
|
|
68
|
+
* @param filename Filename to check
|
|
69
|
+
* @param patterns Array of glob patterns to check against
|
|
70
|
+
* @returns True if the filename should be ignored
|
|
71
|
+
*/
|
|
72
|
+
private shouldIgnore;
|
|
73
|
+
/**
|
|
74
|
+
* Gets a description of the file reading operation
|
|
75
|
+
* @param params Parameters for the file reading
|
|
76
|
+
* @returns A string describing the file being read
|
|
77
|
+
*/
|
|
78
|
+
getDescription(params: LSToolParams): string;
|
|
79
|
+
private errorResult;
|
|
80
|
+
/**
|
|
81
|
+
* Executes the LS operation with the given parameters
|
|
82
|
+
* @param params Parameters for the LS operation
|
|
83
|
+
* @returns Result of the LS operation
|
|
84
|
+
*/
|
|
85
|
+
execute(params: LSToolParams, _signal: AbortSignal): Promise<ToolResult>;
|
|
86
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { BaseTool, Icon } from './tools.js';
|
|
9
|
+
import { Type } from '@google/genai';
|
|
10
|
+
import { SchemaValidator } from '../utils/schemaValidator.js';
|
|
11
|
+
import { makeRelative, shortenPath } from '../utils/paths.js';
|
|
12
|
+
import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/config.js';
|
|
13
|
+
/**
|
|
14
|
+
* Implementation of the LS tool logic
|
|
15
|
+
*/
|
|
16
|
+
export class LSTool extends BaseTool {
|
|
17
|
+
config;
|
|
18
|
+
static Name = 'list_directory';
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super(LSTool.Name, 'ReadFolder', 'Lists the names of files and subdirectories directly within a specified directory path. Can optionally ignore entries matching provided glob patterns.', Icon.Folder, {
|
|
21
|
+
properties: {
|
|
22
|
+
path: {
|
|
23
|
+
description: 'The absolute path to the directory to list (must be absolute, not relative)',
|
|
24
|
+
type: Type.STRING,
|
|
25
|
+
},
|
|
26
|
+
ignore: {
|
|
27
|
+
description: 'List of glob patterns to ignore',
|
|
28
|
+
items: {
|
|
29
|
+
type: Type.STRING,
|
|
30
|
+
},
|
|
31
|
+
type: Type.ARRAY,
|
|
32
|
+
},
|
|
33
|
+
file_filtering_options: {
|
|
34
|
+
description: 'Optional: Whether to respect ignore patterns from .gitignore or .geminiignore',
|
|
35
|
+
type: Type.OBJECT,
|
|
36
|
+
properties: {
|
|
37
|
+
respect_git_ignore: {
|
|
38
|
+
description: 'Optional: Whether to respect .gitignore patterns when listing files. Only available in git repositories. Defaults to true.',
|
|
39
|
+
type: Type.BOOLEAN,
|
|
40
|
+
},
|
|
41
|
+
respect_gemini_ignore: {
|
|
42
|
+
description: 'Optional: Whether to respect .geminiignore patterns when listing files. Defaults to true.',
|
|
43
|
+
type: Type.BOOLEAN,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
required: ['path'],
|
|
49
|
+
type: Type.OBJECT,
|
|
50
|
+
});
|
|
51
|
+
this.config = config;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates the parameters for the tool
|
|
55
|
+
* @param params Parameters to validate
|
|
56
|
+
* @returns An error message string if invalid, null otherwise
|
|
57
|
+
*/
|
|
58
|
+
validateToolParams(params) {
|
|
59
|
+
const errors = SchemaValidator.validate(this.schema.parameters, params);
|
|
60
|
+
if (errors) {
|
|
61
|
+
return errors;
|
|
62
|
+
}
|
|
63
|
+
if (!path.isAbsolute(params.path)) {
|
|
64
|
+
return `Path must be absolute: ${params.path}`;
|
|
65
|
+
}
|
|
66
|
+
const workspaceContext = this.config.getWorkspaceContext();
|
|
67
|
+
if (!workspaceContext.isPathWithinWorkspace(params.path)) {
|
|
68
|
+
const directories = workspaceContext.getDirectories();
|
|
69
|
+
return `Path must be within one of the workspace directories: ${directories.join(', ')}`;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a filename matches any of the ignore patterns
|
|
75
|
+
* @param filename Filename to check
|
|
76
|
+
* @param patterns Array of glob patterns to check against
|
|
77
|
+
* @returns True if the filename should be ignored
|
|
78
|
+
*/
|
|
79
|
+
shouldIgnore(filename, patterns) {
|
|
80
|
+
if (!patterns || patterns.length === 0) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
for (const pattern of patterns) {
|
|
84
|
+
// Convert glob pattern to RegExp
|
|
85
|
+
const regexPattern = pattern
|
|
86
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
87
|
+
.replace(/\*/g, '.*')
|
|
88
|
+
.replace(/\?/g, '.');
|
|
89
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
90
|
+
if (regex.test(filename)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets a description of the file reading operation
|
|
98
|
+
* @param params Parameters for the file reading
|
|
99
|
+
* @returns A string describing the file being read
|
|
100
|
+
*/
|
|
101
|
+
getDescription(params) {
|
|
102
|
+
const relativePath = makeRelative(params.path, this.config.getTargetDir());
|
|
103
|
+
return shortenPath(relativePath);
|
|
104
|
+
}
|
|
105
|
+
// Helper for consistent error formatting
|
|
106
|
+
errorResult(llmContent, returnDisplay) {
|
|
107
|
+
return {
|
|
108
|
+
llmContent,
|
|
109
|
+
// Keep returnDisplay simpler in core logic
|
|
110
|
+
returnDisplay: `Error: ${returnDisplay}`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Executes the LS operation with the given parameters
|
|
115
|
+
* @param params Parameters for the LS operation
|
|
116
|
+
* @returns Result of the LS operation
|
|
117
|
+
*/
|
|
118
|
+
async execute(params, _signal) {
|
|
119
|
+
const validationError = this.validateToolParams(params);
|
|
120
|
+
if (validationError) {
|
|
121
|
+
return this.errorResult(`Error: Invalid parameters provided. Reason: ${validationError}`, `Failed to execute tool.`);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const stats = fs.statSync(params.path);
|
|
125
|
+
if (!stats) {
|
|
126
|
+
// fs.statSync throws on non-existence, so this check might be redundant
|
|
127
|
+
// but keeping for clarity. Error message adjusted.
|
|
128
|
+
return this.errorResult(`Error: Directory not found or inaccessible: ${params.path}`, `Directory not found or inaccessible.`);
|
|
129
|
+
}
|
|
130
|
+
if (!stats.isDirectory()) {
|
|
131
|
+
return this.errorResult(`Error: Path is not a directory: ${params.path}`, `Path is not a directory.`);
|
|
132
|
+
}
|
|
133
|
+
const files = fs.readdirSync(params.path);
|
|
134
|
+
const defaultFileIgnores = this.config.getFileFilteringOptions() ?? DEFAULT_FILE_FILTERING_OPTIONS;
|
|
135
|
+
const fileFilteringOptions = {
|
|
136
|
+
respectGitIgnore: params.file_filtering_options?.respect_git_ignore ??
|
|
137
|
+
defaultFileIgnores.respectGitIgnore,
|
|
138
|
+
respectGeminiIgnore: params.file_filtering_options?.respect_gemini_ignore ??
|
|
139
|
+
defaultFileIgnores.respectGeminiIgnore,
|
|
140
|
+
};
|
|
141
|
+
// Get centralized file discovery service
|
|
142
|
+
const fileDiscovery = this.config.getFileService();
|
|
143
|
+
const entries = [];
|
|
144
|
+
let gitIgnoredCount = 0;
|
|
145
|
+
let geminiIgnoredCount = 0;
|
|
146
|
+
if (files.length === 0) {
|
|
147
|
+
// Changed error message to be more neutral for LLM
|
|
148
|
+
return {
|
|
149
|
+
llmContent: `Directory ${params.path} is empty.`,
|
|
150
|
+
returnDisplay: `Directory is empty.`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
for (const file of files) {
|
|
154
|
+
if (this.shouldIgnore(file, params.ignore)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const fullPath = path.join(params.path, file);
|
|
158
|
+
const relativePath = path.relative(this.config.getTargetDir(), fullPath);
|
|
159
|
+
// Check if this file should be ignored based on git or gemini ignore rules
|
|
160
|
+
if (fileFilteringOptions.respectGitIgnore &&
|
|
161
|
+
fileDiscovery.shouldGitIgnoreFile(relativePath)) {
|
|
162
|
+
gitIgnoredCount++;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (fileFilteringOptions.respectGeminiIgnore &&
|
|
166
|
+
fileDiscovery.shouldGeminiIgnoreFile(relativePath)) {
|
|
167
|
+
geminiIgnoredCount++;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const stats = fs.statSync(fullPath);
|
|
172
|
+
const isDir = stats.isDirectory();
|
|
173
|
+
entries.push({
|
|
174
|
+
name: file,
|
|
175
|
+
path: fullPath,
|
|
176
|
+
isDirectory: isDir,
|
|
177
|
+
size: isDir ? 0 : stats.size,
|
|
178
|
+
modifiedTime: stats.mtime,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// Log error internally but don't fail the whole listing
|
|
183
|
+
console.error(`Error accessing ${fullPath}: ${error}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Sort entries (directories first, then alphabetically)
|
|
187
|
+
entries.sort((a, b) => {
|
|
188
|
+
if (a.isDirectory && !b.isDirectory)
|
|
189
|
+
return -1;
|
|
190
|
+
if (!a.isDirectory && b.isDirectory)
|
|
191
|
+
return 1;
|
|
192
|
+
return a.name.localeCompare(b.name);
|
|
193
|
+
});
|
|
194
|
+
// Create formatted content for LLM
|
|
195
|
+
const directoryContent = entries
|
|
196
|
+
.map((entry) => `${entry.isDirectory ? '[DIR] ' : ''}${entry.name}`)
|
|
197
|
+
.join('\n');
|
|
198
|
+
let resultMessage = `Directory listing for ${params.path}:\n${directoryContent}`;
|
|
199
|
+
const ignoredMessages = [];
|
|
200
|
+
if (gitIgnoredCount > 0) {
|
|
201
|
+
ignoredMessages.push(`${gitIgnoredCount} git-ignored`);
|
|
202
|
+
}
|
|
203
|
+
if (geminiIgnoredCount > 0) {
|
|
204
|
+
ignoredMessages.push(`${geminiIgnoredCount} gemini-ignored`);
|
|
205
|
+
}
|
|
206
|
+
if (ignoredMessages.length > 0) {
|
|
207
|
+
resultMessage += `\n\n(${ignoredMessages.join(', ')})`;
|
|
208
|
+
}
|
|
209
|
+
let displayMessage = `Listed ${entries.length} item(s).`;
|
|
210
|
+
if (ignoredMessages.length > 0) {
|
|
211
|
+
displayMessage += ` (${ignoredMessages.join(', ')})`;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
llmContent: resultMessage,
|
|
215
|
+
returnDisplay: displayMessage,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
const errorMsg = `Error listing directory: ${error instanceof Error ? error.message : String(error)}`;
|
|
220
|
+
return this.errorResult(errorMsg, 'Failed to list directory.');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=ls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/tools/ls.ts"],"names":[],"mappings":"AAAA;;;;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