@google/gemini-cli-core 0.0.3-preview.4

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.
Files changed (669) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +310 -0
  3. package/dist/.last_build +0 -0
  4. package/dist/google-gemini-cli-core-0.3.0-preview.3.tgz +0 -0
  5. package/dist/index.d.ts +12 -0
  6. package/dist/index.js +13 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/src/__mocks__/fs/promises.d.ts +11 -0
  9. package/dist/src/__mocks__/fs/promises.js +17 -0
  10. package/dist/src/__mocks__/fs/promises.js.map +1 -0
  11. package/dist/src/code_assist/codeAssist.d.ts +10 -0
  12. package/dist/src/code_assist/codeAssist.js +19 -0
  13. package/dist/src/code_assist/codeAssist.js.map +1 -0
  14. package/dist/src/code_assist/converter.d.ts +72 -0
  15. package/dist/src/code_assist/converter.js +159 -0
  16. package/dist/src/code_assist/converter.js.map +1 -0
  17. package/dist/src/code_assist/converter.test.d.ts +6 -0
  18. package/dist/src/code_assist/converter.test.js +362 -0
  19. package/dist/src/code_assist/converter.test.js.map +1 -0
  20. package/dist/src/code_assist/oauth2.d.ts +22 -0
  21. package/dist/src/code_assist/oauth2.js +353 -0
  22. package/dist/src/code_assist/oauth2.js.map +1 -0
  23. package/dist/src/code_assist/oauth2.test.d.ts +6 -0
  24. package/dist/src/code_assist/oauth2.test.js +427 -0
  25. package/dist/src/code_assist/oauth2.test.js.map +1 -0
  26. package/dist/src/code_assist/server.d.ts +37 -0
  27. package/dist/src/code_assist/server.js +125 -0
  28. package/dist/src/code_assist/server.js.map +1 -0
  29. package/dist/src/code_assist/server.test.d.ts +6 -0
  30. package/dist/src/code_assist/server.test.js +134 -0
  31. package/dist/src/code_assist/server.test.js.map +1 -0
  32. package/dist/src/code_assist/setup.d.ts +20 -0
  33. package/dist/src/code_assist/setup.js +101 -0
  34. package/dist/src/code_assist/setup.js.map +1 -0
  35. package/dist/src/code_assist/setup.test.d.ts +6 -0
  36. package/dist/src/code_assist/setup.test.js +171 -0
  37. package/dist/src/code_assist/setup.test.js.map +1 -0
  38. package/dist/src/code_assist/types.d.ts +148 -0
  39. package/dist/src/code_assist/types.js +46 -0
  40. package/dist/src/code_assist/types.js.map +1 -0
  41. package/dist/src/config/config.d.ts +318 -0
  42. package/dist/src/config/config.js +633 -0
  43. package/dist/src/config/config.js.map +1 -0
  44. package/dist/src/config/config.test.d.ts +6 -0
  45. package/dist/src/config/config.test.js +585 -0
  46. package/dist/src/config/config.test.js.map +1 -0
  47. package/dist/src/config/flashFallback.test.d.ts +6 -0
  48. package/dist/src/config/flashFallback.test.js +87 -0
  49. package/dist/src/config/flashFallback.test.js.map +1 -0
  50. package/dist/src/config/models.d.ts +9 -0
  51. package/dist/src/config/models.js +10 -0
  52. package/dist/src/config/models.js.map +1 -0
  53. package/dist/src/config/storage.d.ts +32 -0
  54. package/dist/src/config/storage.js +90 -0
  55. package/dist/src/config/storage.js.map +1 -0
  56. package/dist/src/config/storage.test.d.ts +6 -0
  57. package/dist/src/config/storage.test.js +43 -0
  58. package/dist/src/config/storage.test.js.map +1 -0
  59. package/dist/src/core/client.d.ts +65 -0
  60. package/dist/src/core/client.js +689 -0
  61. package/dist/src/core/client.js.map +1 -0
  62. package/dist/src/core/client.test.d.ts +6 -0
  63. package/dist/src/core/client.test.js +1857 -0
  64. package/dist/src/core/client.test.js.map +1 -0
  65. package/dist/src/core/contentGenerator.d.ts +33 -0
  66. package/dist/src/core/contentGenerator.js +80 -0
  67. package/dist/src/core/contentGenerator.js.map +1 -0
  68. package/dist/src/core/contentGenerator.test.d.ts +6 -0
  69. package/dist/src/core/contentGenerator.test.js +124 -0
  70. package/dist/src/core/contentGenerator.test.js.map +1 -0
  71. package/dist/src/core/coreToolScheduler.d.ts +126 -0
  72. package/dist/src/core/coreToolScheduler.js +605 -0
  73. package/dist/src/core/coreToolScheduler.js.map +1 -0
  74. package/dist/src/core/coreToolScheduler.test.d.ts +6 -0
  75. package/dist/src/core/coreToolScheduler.test.js +923 -0
  76. package/dist/src/core/coreToolScheduler.test.js.map +1 -0
  77. package/dist/src/core/geminiChat.d.ts +122 -0
  78. package/dist/src/core/geminiChat.js +547 -0
  79. package/dist/src/core/geminiChat.js.map +1 -0
  80. package/dist/src/core/geminiChat.test.d.ts +6 -0
  81. package/dist/src/core/geminiChat.test.js +875 -0
  82. package/dist/src/core/geminiChat.test.js.map +1 -0
  83. package/dist/src/core/geminiRequest.d.ts +13 -0
  84. package/dist/src/core/geminiRequest.js +11 -0
  85. package/dist/src/core/geminiRequest.js.map +1 -0
  86. package/dist/src/core/logger.d.ts +60 -0
  87. package/dist/src/core/logger.js +360 -0
  88. package/dist/src/core/logger.js.map +1 -0
  89. package/dist/src/core/logger.test.d.ts +6 -0
  90. package/dist/src/core/logger.test.js +534 -0
  91. package/dist/src/core/logger.test.js.map +1 -0
  92. package/dist/src/core/loggingContentGenerator.d.ts +25 -0
  93. package/dist/src/core/loggingContentGenerator.js +97 -0
  94. package/dist/src/core/loggingContentGenerator.js.map +1 -0
  95. package/dist/src/core/nonInteractiveToolExecutor.d.ts +10 -0
  96. package/dist/src/core/nonInteractiveToolExecutor.js +24 -0
  97. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -0
  98. package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +6 -0
  99. package/dist/src/core/nonInteractiveToolExecutor.test.js +236 -0
  100. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
  101. package/dist/src/core/prompts.d.ts +12 -0
  102. package/dist/src/core/prompts.js +359 -0
  103. package/dist/src/core/prompts.js.map +1 -0
  104. package/dist/src/core/prompts.test.d.ts +6 -0
  105. package/dist/src/core/prompts.test.js +214 -0
  106. package/dist/src/core/prompts.test.js.map +1 -0
  107. package/dist/src/core/subagent.d.ts +236 -0
  108. package/dist/src/core/subagent.js +485 -0
  109. package/dist/src/core/subagent.js.map +1 -0
  110. package/dist/src/core/subagent.test.d.ts +6 -0
  111. package/dist/src/core/subagent.test.js +520 -0
  112. package/dist/src/core/subagent.test.js.map +1 -0
  113. package/dist/src/core/tokenLimits.d.ts +10 -0
  114. package/dist/src/core/tokenLimits.js +28 -0
  115. package/dist/src/core/tokenLimits.js.map +1 -0
  116. package/dist/src/core/turn.d.ts +125 -0
  117. package/dist/src/core/turn.js +154 -0
  118. package/dist/src/core/turn.js.map +1 -0
  119. package/dist/src/core/turn.test.d.ts +6 -0
  120. package/dist/src/core/turn.test.js +388 -0
  121. package/dist/src/core/turn.test.js.map +1 -0
  122. package/dist/src/generated/git-commit.d.ts +7 -0
  123. package/dist/src/generated/git-commit.js +10 -0
  124. package/dist/src/generated/git-commit.js.map +1 -0
  125. package/dist/src/ide/constants.d.ts +6 -0
  126. package/dist/src/ide/constants.js +7 -0
  127. package/dist/src/ide/constants.js.map +1 -0
  128. package/dist/src/ide/detect-ide.d.ts +25 -0
  129. package/dist/src/ide/detect-ide.js +104 -0
  130. package/dist/src/ide/detect-ide.js.map +1 -0
  131. package/dist/src/ide/detect-ide.test.d.ts +6 -0
  132. package/dist/src/ide/detect-ide.test.js +109 -0
  133. package/dist/src/ide/detect-ide.test.js.map +1 -0
  134. package/dist/src/ide/ide-client.d.ts +67 -0
  135. package/dist/src/ide/ide-client.js +418 -0
  136. package/dist/src/ide/ide-client.js.map +1 -0
  137. package/dist/src/ide/ide-client.test.d.ts +6 -0
  138. package/dist/src/ide/ide-client.test.js +155 -0
  139. package/dist/src/ide/ide-client.test.js.map +1 -0
  140. package/dist/src/ide/ide-installer.d.ts +14 -0
  141. package/dist/src/ide/ide-installer.js +107 -0
  142. package/dist/src/ide/ide-installer.js.map +1 -0
  143. package/dist/src/ide/ide-installer.test.d.ts +6 -0
  144. package/dist/src/ide/ide-installer.test.js +113 -0
  145. package/dist/src/ide/ide-installer.test.js.map +1 -0
  146. package/dist/src/ide/ideContext.d.ts +374 -0
  147. package/dist/src/ide/ideContext.js +147 -0
  148. package/dist/src/ide/ideContext.js.map +1 -0
  149. package/dist/src/ide/ideContext.test.d.ts +6 -0
  150. package/dist/src/ide/ideContext.test.js +265 -0
  151. package/dist/src/ide/ideContext.test.js.map +1 -0
  152. package/dist/src/ide/process-utils.d.ts +22 -0
  153. package/dist/src/ide/process-utils.js +153 -0
  154. package/dist/src/ide/process-utils.js.map +1 -0
  155. package/dist/src/ide/process-utils.test.d.ts +6 -0
  156. package/dist/src/ide/process-utils.test.js +72 -0
  157. package/dist/src/ide/process-utils.test.js.map +1 -0
  158. package/dist/src/index.d.ts +81 -0
  159. package/dist/src/index.js +90 -0
  160. package/dist/src/index.js.map +1 -0
  161. package/dist/src/index.test.d.ts +6 -0
  162. package/dist/src/index.test.js +12 -0
  163. package/dist/src/index.test.js.map +1 -0
  164. package/dist/src/mcp/google-auth-provider.d.ts +23 -0
  165. package/dist/src/mcp/google-auth-provider.js +72 -0
  166. package/dist/src/mcp/google-auth-provider.js.map +1 -0
  167. package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
  168. package/dist/src/mcp/google-auth-provider.test.js +89 -0
  169. package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
  170. package/dist/src/mcp/oauth-provider.d.ts +146 -0
  171. package/dist/src/mcp/oauth-provider.js +601 -0
  172. package/dist/src/mcp/oauth-provider.js.map +1 -0
  173. package/dist/src/mcp/oauth-provider.test.d.ts +6 -0
  174. package/dist/src/mcp/oauth-provider.test.js +672 -0
  175. package/dist/src/mcp/oauth-provider.test.js.map +1 -0
  176. package/dist/src/mcp/oauth-token-storage.d.ts +61 -0
  177. package/dist/src/mcp/oauth-token-storage.js +148 -0
  178. package/dist/src/mcp/oauth-token-storage.js.map +1 -0
  179. package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
  180. package/dist/src/mcp/oauth-token-storage.test.js +206 -0
  181. package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
  182. package/dist/src/mcp/oauth-utils.d.ts +119 -0
  183. package/dist/src/mcp/oauth-utils.js +235 -0
  184. package/dist/src/mcp/oauth-utils.js.map +1 -0
  185. package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
  186. package/dist/src/mcp/oauth-utils.test.js +199 -0
  187. package/dist/src/mcp/oauth-utils.test.js.map +1 -0
  188. package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
  189. package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
  190. package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
  191. package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
  192. package/dist/src/mcp/token-storage/base-token-storage.test.js +160 -0
  193. package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
  194. package/dist/src/mcp/token-storage/types.d.ts +34 -0
  195. package/dist/src/mcp/token-storage/types.js +7 -0
  196. package/dist/src/mcp/token-storage/types.js.map +1 -0
  197. package/dist/src/mocks/msw.d.ts +6 -0
  198. package/dist/src/mocks/msw.js +8 -0
  199. package/dist/src/mocks/msw.js.map +1 -0
  200. package/dist/src/prompts/mcp-prompts.d.ts +8 -0
  201. package/dist/src/prompts/mcp-prompts.js +13 -0
  202. package/dist/src/prompts/mcp-prompts.js.map +1 -0
  203. package/dist/src/prompts/prompt-registry.d.ts +34 -0
  204. package/dist/src/prompts/prompt-registry.js +63 -0
  205. package/dist/src/prompts/prompt-registry.js.map +1 -0
  206. package/dist/src/services/chatRecordingService.d.ts +150 -0
  207. package/dist/src/services/chatRecordingService.js +321 -0
  208. package/dist/src/services/chatRecordingService.js.map +1 -0
  209. package/dist/src/services/chatRecordingService.test.d.ts +6 -0
  210. package/dist/src/services/chatRecordingService.test.js +290 -0
  211. package/dist/src/services/chatRecordingService.test.js.map +1 -0
  212. package/dist/src/services/fileDiscoveryService.d.ts +35 -0
  213. package/dist/src/services/fileDiscoveryService.js +91 -0
  214. package/dist/src/services/fileDiscoveryService.js.map +1 -0
  215. package/dist/src/services/fileDiscoveryService.test.d.ts +6 -0
  216. package/dist/src/services/fileDiscoveryService.test.js +143 -0
  217. package/dist/src/services/fileDiscoveryService.test.js.map +1 -0
  218. package/dist/src/services/fileSystemService.d.ts +31 -0
  219. package/dist/src/services/fileSystemService.js +18 -0
  220. package/dist/src/services/fileSystemService.js.map +1 -0
  221. package/dist/src/services/fileSystemService.test.d.ts +6 -0
  222. package/dist/src/services/fileSystemService.test.js +41 -0
  223. package/dist/src/services/fileSystemService.test.js.map +1 -0
  224. package/dist/src/services/gitService.d.ts +23 -0
  225. package/dist/src/services/gitService.js +110 -0
  226. package/dist/src/services/gitService.js.map +1 -0
  227. package/dist/src/services/gitService.test.d.ts +6 -0
  228. package/dist/src/services/gitService.test.js +212 -0
  229. package/dist/src/services/gitService.test.js.map +1 -0
  230. package/dist/src/services/loopDetectionService.d.ts +98 -0
  231. package/dist/src/services/loopDetectionService.js +363 -0
  232. package/dist/src/services/loopDetectionService.js.map +1 -0
  233. package/dist/src/services/loopDetectionService.test.d.ts +6 -0
  234. package/dist/src/services/loopDetectionService.test.js +558 -0
  235. package/dist/src/services/loopDetectionService.test.js.map +1 -0
  236. package/dist/src/services/shellExecutionService.d.ts +68 -0
  237. package/dist/src/services/shellExecutionService.js +332 -0
  238. package/dist/src/services/shellExecutionService.js.map +1 -0
  239. package/dist/src/services/shellExecutionService.test.d.ts +6 -0
  240. package/dist/src/services/shellExecutionService.test.js +517 -0
  241. package/dist/src/services/shellExecutionService.test.js.map +1 -0
  242. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +121 -0
  243. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +773 -0
  244. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
  245. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +17 -0
  246. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +407 -0
  247. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
  248. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +90 -0
  249. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +229 -0
  250. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
  251. package/dist/src/telemetry/constants.d.ts +32 -0
  252. package/dist/src/telemetry/constants.js +33 -0
  253. package/dist/src/telemetry/constants.js.map +1 -0
  254. package/dist/src/telemetry/file-exporters.d.ts +29 -0
  255. package/dist/src/telemetry/file-exporters.js +62 -0
  256. package/dist/src/telemetry/file-exporters.js.map +1 -0
  257. package/dist/src/telemetry/index.d.ts +21 -0
  258. package/dist/src/telemetry/index.js +21 -0
  259. package/dist/src/telemetry/index.js.map +1 -0
  260. package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
  261. package/dist/src/telemetry/integration.test.circular.js +54 -0
  262. package/dist/src/telemetry/integration.test.circular.js.map +1 -0
  263. package/dist/src/telemetry/loggers.d.ts +26 -0
  264. package/dist/src/telemetry/loggers.js +404 -0
  265. package/dist/src/telemetry/loggers.js.map +1 -0
  266. package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
  267. package/dist/src/telemetry/loggers.test.circular.js +107 -0
  268. package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
  269. package/dist/src/telemetry/loggers.test.d.ts +6 -0
  270. package/dist/src/telemetry/loggers.test.js +658 -0
  271. package/dist/src/telemetry/loggers.test.js.map +1 -0
  272. package/dist/src/telemetry/metrics.d.ts +36 -0
  273. package/dist/src/telemetry/metrics.js +208 -0
  274. package/dist/src/telemetry/metrics.js.map +1 -0
  275. package/dist/src/telemetry/metrics.test.d.ts +6 -0
  276. package/dist/src/telemetry/metrics.test.js +242 -0
  277. package/dist/src/telemetry/metrics.test.js.map +1 -0
  278. package/dist/src/telemetry/sdk.d.ts +9 -0
  279. package/dist/src/telemetry/sdk.js +163 -0
  280. package/dist/src/telemetry/sdk.js.map +1 -0
  281. package/dist/src/telemetry/sdk.test.d.ts +6 -0
  282. package/dist/src/telemetry/sdk.test.js +82 -0
  283. package/dist/src/telemetry/sdk.test.js.map +1 -0
  284. package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
  285. package/dist/src/telemetry/telemetry-utils.js +14 -0
  286. package/dist/src/telemetry/telemetry-utils.js.map +1 -0
  287. package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
  288. package/dist/src/telemetry/telemetry-utils.test.js +40 -0
  289. package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
  290. package/dist/src/telemetry/telemetry.test.d.ts +6 -0
  291. package/dist/src/telemetry/telemetry.test.js +50 -0
  292. package/dist/src/telemetry/telemetry.test.js.map +1 -0
  293. package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
  294. package/dist/src/telemetry/tool-call-decision.js +29 -0
  295. package/dist/src/telemetry/tool-call-decision.js.map +1 -0
  296. package/dist/src/telemetry/types.d.ts +220 -0
  297. package/dist/src/telemetry/types.js +383 -0
  298. package/dist/src/telemetry/types.js.map +1 -0
  299. package/dist/src/telemetry/uiTelemetry.d.ts +75 -0
  300. package/dist/src/telemetry/uiTelemetry.js +153 -0
  301. package/dist/src/telemetry/uiTelemetry.js.map +1 -0
  302. package/dist/src/telemetry/uiTelemetry.test.d.ts +6 -0
  303. package/dist/src/telemetry/uiTelemetry.test.js +558 -0
  304. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
  305. package/dist/src/test-utils/config.d.ts +17 -0
  306. package/dist/src/test-utils/config.js +32 -0
  307. package/dist/src/test-utils/config.js.map +1 -0
  308. package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
  309. package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
  310. package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
  311. package/dist/src/test-utils/tools.d.ts +45 -0
  312. package/dist/src/test-utils/tools.js +105 -0
  313. package/dist/src/test-utils/tools.js.map +1 -0
  314. package/dist/src/tools/diffOptions.d.ts +9 -0
  315. package/dist/src/tools/diffOptions.js +38 -0
  316. package/dist/src/tools/diffOptions.js.map +1 -0
  317. package/dist/src/tools/diffOptions.test.d.ts +6 -0
  318. package/dist/src/tools/diffOptions.test.js +119 -0
  319. package/dist/src/tools/diffOptions.test.js.map +1 -0
  320. package/dist/src/tools/edit.d.ts +56 -0
  321. package/dist/src/tools/edit.js +423 -0
  322. package/dist/src/tools/edit.js.map +1 -0
  323. package/dist/src/tools/edit.test.d.ts +6 -0
  324. package/dist/src/tools/edit.test.js +713 -0
  325. package/dist/src/tools/edit.test.js.map +1 -0
  326. package/dist/src/tools/glob.d.ts +52 -0
  327. package/dist/src/tools/glob.js +236 -0
  328. package/dist/src/tools/glob.js.map +1 -0
  329. package/dist/src/tools/glob.test.d.ts +6 -0
  330. package/dist/src/tools/glob.test.js +375 -0
  331. package/dist/src/tools/glob.test.js.map +1 -0
  332. package/dist/src/tools/grep.d.ts +47 -0
  333. package/dist/src/tools/grep.js +517 -0
  334. package/dist/src/tools/grep.js.map +1 -0
  335. package/dist/src/tools/grep.test.d.ts +6 -0
  336. package/dist/src/tools/grep.test.js +295 -0
  337. package/dist/src/tools/grep.test.js.map +1 -0
  338. package/dist/src/tools/ls.d.ts +68 -0
  339. package/dist/src/tools/ls.js +227 -0
  340. package/dist/src/tools/ls.js.map +1 -0
  341. package/dist/src/tools/ls.test.d.ts +6 -0
  342. package/dist/src/tools/ls.test.js +389 -0
  343. package/dist/src/tools/ls.test.js.map +1 -0
  344. package/dist/src/tools/mcp-client-manager.d.ts +38 -0
  345. package/dist/src/tools/mcp-client-manager.js +74 -0
  346. package/dist/src/tools/mcp-client-manager.js.map +1 -0
  347. package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
  348. package/dist/src/tools/mcp-client-manager.test.js +39 -0
  349. package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
  350. package/dist/src/tools/mcp-client.d.ts +199 -0
  351. package/dist/src/tools/mcp-client.js +995 -0
  352. package/dist/src/tools/mcp-client.js.map +1 -0
  353. package/dist/src/tools/mcp-client.test.d.ts +6 -0
  354. package/dist/src/tools/mcp-client.test.js +454 -0
  355. package/dist/src/tools/mcp-client.test.js.map +1 -0
  356. package/dist/src/tools/mcp-tool.d.ts +23 -0
  357. package/dist/src/tools/mcp-tool.js +240 -0
  358. package/dist/src/tools/mcp-tool.js.map +1 -0
  359. package/dist/src/tools/mcp-tool.test.d.ts +6 -0
  360. package/dist/src/tools/mcp-tool.test.js +576 -0
  361. package/dist/src/tools/mcp-tool.test.js.map +1 -0
  362. package/dist/src/tools/memoryTool.d.ts +40 -0
  363. package/dist/src/tools/memoryTool.js +296 -0
  364. package/dist/src/tools/memoryTool.js.map +1 -0
  365. package/dist/src/tools/memoryTool.test.d.ts +6 -0
  366. package/dist/src/tools/memoryTool.test.js +298 -0
  367. package/dist/src/tools/memoryTool.test.js.map +1 -0
  368. package/dist/src/tools/modifiable-tool.d.ts +32 -0
  369. package/dist/src/tools/modifiable-tool.js +88 -0
  370. package/dist/src/tools/modifiable-tool.js.map +1 -0
  371. package/dist/src/tools/modifiable-tool.test.d.ts +6 -0
  372. package/dist/src/tools/modifiable-tool.test.js +193 -0
  373. package/dist/src/tools/modifiable-tool.test.js.map +1 -0
  374. package/dist/src/tools/read-file.d.ts +35 -0
  375. package/dist/src/tools/read-file.js +127 -0
  376. package/dist/src/tools/read-file.js.map +1 -0
  377. package/dist/src/tools/read-file.test.d.ts +6 -0
  378. package/dist/src/tools/read-file.test.js +311 -0
  379. package/dist/src/tools/read-file.test.js.map +1 -0
  380. package/dist/src/tools/read-many-files.d.ts +60 -0
  381. package/dist/src/tools/read-many-files.js +414 -0
  382. package/dist/src/tools/read-many-files.js.map +1 -0
  383. package/dist/src/tools/read-many-files.test.d.ts +6 -0
  384. package/dist/src/tools/read-many-files.test.js +565 -0
  385. package/dist/src/tools/read-many-files.test.js.map +1 -0
  386. package/dist/src/tools/ripGrep.d.ts +47 -0
  387. package/dist/src/tools/ripGrep.js +368 -0
  388. package/dist/src/tools/ripGrep.js.map +1 -0
  389. package/dist/src/tools/ripGrep.test.d.ts +6 -0
  390. package/dist/src/tools/ripGrep.test.js +874 -0
  391. package/dist/src/tools/ripGrep.test.js.map +1 -0
  392. package/dist/src/tools/shell.d.ts +22 -0
  393. package/dist/src/tools/shell.js +320 -0
  394. package/dist/src/tools/shell.js.map +1 -0
  395. package/dist/src/tools/shell.test.d.ts +6 -0
  396. package/dist/src/tools/shell.test.js +336 -0
  397. package/dist/src/tools/shell.test.js.map +1 -0
  398. package/dist/src/tools/tool-error.d.ts +43 -0
  399. package/dist/src/tools/tool-error.js +58 -0
  400. package/dist/src/tools/tool-error.js.map +1 -0
  401. package/dist/src/tools/tool-registry.d.ts +86 -0
  402. package/dist/src/tools/tool-registry.js +369 -0
  403. package/dist/src/tools/tool-registry.js.map +1 -0
  404. package/dist/src/tools/tool-registry.test.d.ts +6 -0
  405. package/dist/src/tools/tool-registry.test.js +332 -0
  406. package/dist/src/tools/tool-registry.test.js.map +1 -0
  407. package/dist/src/tools/tools.d.ts +274 -0
  408. package/dist/src/tools/tools.js +250 -0
  409. package/dist/src/tools/tools.js.map +1 -0
  410. package/dist/src/tools/tools.test.d.ts +6 -0
  411. package/dist/src/tools/tools.test.js +205 -0
  412. package/dist/src/tools/tools.test.js.map +1 -0
  413. package/dist/src/tools/web-fetch.d.ts +27 -0
  414. package/dist/src/tools/web-fetch.js +243 -0
  415. package/dist/src/tools/web-fetch.js.map +1 -0
  416. package/dist/src/tools/web-fetch.test.d.ts +6 -0
  417. package/dist/src/tools/web-fetch.test.js +114 -0
  418. package/dist/src/tools/web-fetch.test.js.map +1 -0
  419. package/dist/src/tools/web-search.d.ts +49 -0
  420. package/dist/src/tools/web-search.js +137 -0
  421. package/dist/src/tools/web-search.js.map +1 -0
  422. package/dist/src/tools/web-search.test.d.ts +6 -0
  423. package/dist/src/tools/web-search.test.js +207 -0
  424. package/dist/src/tools/web-search.test.js.map +1 -0
  425. package/dist/src/tools/write-file.d.ts +52 -0
  426. package/dist/src/tools/write-file.js +314 -0
  427. package/dist/src/tools/write-file.js.map +1 -0
  428. package/dist/src/tools/write-file.test.d.ts +6 -0
  429. package/dist/src/tools/write-file.test.js +531 -0
  430. package/dist/src/tools/write-file.test.js.map +1 -0
  431. package/dist/src/utils/LruCache.d.ts +13 -0
  432. package/dist/src/utils/LruCache.js +38 -0
  433. package/dist/src/utils/LruCache.js.map +1 -0
  434. package/dist/src/utils/bfsFileSearch.d.ts +24 -0
  435. package/dist/src/utils/bfsFileSearch.js +89 -0
  436. package/dist/src/utils/bfsFileSearch.js.map +1 -0
  437. package/dist/src/utils/bfsFileSearch.test.d.ts +6 -0
  438. package/dist/src/utils/bfsFileSearch.test.js +163 -0
  439. package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
  440. package/dist/src/utils/browser.d.ts +13 -0
  441. package/dist/src/utils/browser.js +50 -0
  442. package/dist/src/utils/browser.js.map +1 -0
  443. package/dist/src/utils/editCorrector.d.ts +53 -0
  444. package/dist/src/utils/editCorrector.js +545 -0
  445. package/dist/src/utils/editCorrector.js.map +1 -0
  446. package/dist/src/utils/editCorrector.test.d.ts +6 -0
  447. package/dist/src/utils/editCorrector.test.js +564 -0
  448. package/dist/src/utils/editCorrector.test.js.map +1 -0
  449. package/dist/src/utils/editor.d.ts +28 -0
  450. package/dist/src/utils/editor.js +186 -0
  451. package/dist/src/utils/editor.js.map +1 -0
  452. package/dist/src/utils/editor.test.d.ts +6 -0
  453. package/dist/src/utils/editor.test.js +445 -0
  454. package/dist/src/utils/editor.test.js.map +1 -0
  455. package/dist/src/utils/environmentContext.d.ts +21 -0
  456. package/dist/src/utils/environmentContext.js +90 -0
  457. package/dist/src/utils/environmentContext.js.map +1 -0
  458. package/dist/src/utils/environmentContext.test.d.ts +6 -0
  459. package/dist/src/utils/environmentContext.test.js +140 -0
  460. package/dist/src/utils/environmentContext.test.js.map +1 -0
  461. package/dist/src/utils/errorParsing.d.ts +8 -0
  462. package/dist/src/utils/errorParsing.js +93 -0
  463. package/dist/src/utils/errorParsing.js.map +1 -0
  464. package/dist/src/utils/errorParsing.test.d.ts +6 -0
  465. package/dist/src/utils/errorParsing.test.js +172 -0
  466. package/dist/src/utils/errorParsing.test.js.map +1 -0
  467. package/dist/src/utils/errorReporting.d.ts +14 -0
  468. package/dist/src/utils/errorReporting.js +88 -0
  469. package/dist/src/utils/errorReporting.js.map +1 -0
  470. package/dist/src/utils/errorReporting.test.d.ts +6 -0
  471. package/dist/src/utils/errorReporting.test.js +130 -0
  472. package/dist/src/utils/errorReporting.test.js.map +1 -0
  473. package/dist/src/utils/errors.d.ts +33 -0
  474. package/dist/src/utils/errors.js +86 -0
  475. package/dist/src/utils/errors.js.map +1 -0
  476. package/dist/src/utils/fetch.d.ts +11 -0
  477. package/dist/src/utils/fetch.js +51 -0
  478. package/dist/src/utils/fetch.js.map +1 -0
  479. package/dist/src/utils/fileUtils.d.ts +52 -0
  480. package/dist/src/utils/fileUtils.js +283 -0
  481. package/dist/src/utils/fileUtils.js.map +1 -0
  482. package/dist/src/utils/fileUtils.test.d.ts +6 -0
  483. package/dist/src/utils/fileUtils.test.js +364 -0
  484. package/dist/src/utils/fileUtils.test.js.map +1 -0
  485. package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
  486. package/dist/src/utils/filesearch/crawlCache.js +57 -0
  487. package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
  488. package/dist/src/utils/filesearch/crawlCache.test.d.ts +6 -0
  489. package/dist/src/utils/filesearch/crawlCache.test.js +103 -0
  490. package/dist/src/utils/filesearch/crawlCache.test.js.map +1 -0
  491. package/dist/src/utils/filesearch/crawler.d.ts +15 -0
  492. package/dist/src/utils/filesearch/crawler.js +50 -0
  493. package/dist/src/utils/filesearch/crawler.js.map +1 -0
  494. package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
  495. package/dist/src/utils/filesearch/crawler.test.js +468 -0
  496. package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
  497. package/dist/src/utils/filesearch/fileSearch.d.ts +38 -0
  498. package/dist/src/utils/filesearch/fileSearch.js +191 -0
  499. package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
  500. package/dist/src/utils/filesearch/fileSearch.test.d.ts +6 -0
  501. package/dist/src/utils/filesearch/fileSearch.test.js +642 -0
  502. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -0
  503. package/dist/src/utils/filesearch/ignore.d.ts +42 -0
  504. package/dist/src/utils/filesearch/ignore.js +106 -0
  505. package/dist/src/utils/filesearch/ignore.js.map +1 -0
  506. package/dist/src/utils/filesearch/ignore.test.d.ts +6 -0
  507. package/dist/src/utils/filesearch/ignore.test.js +144 -0
  508. package/dist/src/utils/filesearch/ignore.test.js.map +1 -0
  509. package/dist/src/utils/filesearch/result-cache.d.ts +33 -0
  510. package/dist/src/utils/filesearch/result-cache.js +59 -0
  511. package/dist/src/utils/filesearch/result-cache.js.map +1 -0
  512. package/dist/src/utils/filesearch/result-cache.test.d.ts +6 -0
  513. package/dist/src/utils/filesearch/result-cache.test.js +46 -0
  514. package/dist/src/utils/filesearch/result-cache.test.js.map +1 -0
  515. package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
  516. package/dist/src/utils/flashFallback.integration.test.js +118 -0
  517. package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
  518. package/dist/src/utils/formatters.d.ts +6 -0
  519. package/dist/src/utils/formatters.js +16 -0
  520. package/dist/src/utils/formatters.js.map +1 -0
  521. package/dist/src/utils/generateContentResponseUtilities.d.ts +13 -0
  522. package/dist/src/utils/generateContentResponseUtilities.js +80 -0
  523. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
  524. package/dist/src/utils/generateContentResponseUtilities.test.d.ts +6 -0
  525. package/dist/src/utils/generateContentResponseUtilities.test.js +235 -0
  526. package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
  527. package/dist/src/utils/getFolderStructure.d.ts +31 -0
  528. package/dist/src/utils/getFolderStructure.js +246 -0
  529. package/dist/src/utils/getFolderStructure.js.map +1 -0
  530. package/dist/src/utils/getFolderStructure.test.d.ts +6 -0
  531. package/dist/src/utils/getFolderStructure.test.js +282 -0
  532. package/dist/src/utils/getFolderStructure.test.js.map +1 -0
  533. package/dist/src/utils/getPty.d.ts +19 -0
  534. package/dist/src/utils/getPty.js +23 -0
  535. package/dist/src/utils/getPty.js.map +1 -0
  536. package/dist/src/utils/gitIgnoreParser.d.ts +20 -0
  537. package/dist/src/utils/gitIgnoreParser.js +61 -0
  538. package/dist/src/utils/gitIgnoreParser.js.map +1 -0
  539. package/dist/src/utils/gitIgnoreParser.test.d.ts +6 -0
  540. package/dist/src/utils/gitIgnoreParser.test.js +154 -0
  541. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -0
  542. package/dist/src/utils/gitUtils.d.ts +17 -0
  543. package/dist/src/utils/gitUtils.js +61 -0
  544. package/dist/src/utils/gitUtils.js.map +1 -0
  545. package/dist/src/utils/ignorePatterns.d.ts +103 -0
  546. package/dist/src/utils/ignorePatterns.js +220 -0
  547. package/dist/src/utils/ignorePatterns.js.map +1 -0
  548. package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
  549. package/dist/src/utils/ignorePatterns.test.js +250 -0
  550. package/dist/src/utils/ignorePatterns.test.js.map +1 -0
  551. package/dist/src/utils/installationManager.d.ts +16 -0
  552. package/dist/src/utils/installationManager.js +50 -0
  553. package/dist/src/utils/installationManager.js.map +1 -0
  554. package/dist/src/utils/installationManager.test.d.ts +6 -0
  555. package/dist/src/utils/installationManager.test.js +83 -0
  556. package/dist/src/utils/installationManager.test.js.map +1 -0
  557. package/dist/src/utils/language-detection.d.ts +6 -0
  558. package/dist/src/utils/language-detection.js +101 -0
  559. package/dist/src/utils/language-detection.js.map +1 -0
  560. package/dist/src/utils/memoryDiscovery.d.ts +15 -0
  561. package/dist/src/utils/memoryDiscovery.js +253 -0
  562. package/dist/src/utils/memoryDiscovery.js.map +1 -0
  563. package/dist/src/utils/memoryDiscovery.test.d.ts +6 -0
  564. package/dist/src/utils/memoryDiscovery.test.js +219 -0
  565. package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
  566. package/dist/src/utils/memoryImportProcessor.d.ts +42 -0
  567. package/dist/src/utils/memoryImportProcessor.js +296 -0
  568. package/dist/src/utils/memoryImportProcessor.js.map +1 -0
  569. package/dist/src/utils/memoryImportProcessor.test.d.ts +6 -0
  570. package/dist/src/utils/memoryImportProcessor.test.js +573 -0
  571. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -0
  572. package/dist/src/utils/messageInspectors.d.ts +8 -0
  573. package/dist/src/utils/messageInspectors.js +16 -0
  574. package/dist/src/utils/messageInspectors.js.map +1 -0
  575. package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
  576. package/dist/src/utils/nextSpeakerChecker.js +91 -0
  577. package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
  578. package/dist/src/utils/nextSpeakerChecker.test.d.ts +6 -0
  579. package/dist/src/utils/nextSpeakerChecker.test.js +168 -0
  580. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -0
  581. package/dist/src/utils/partUtils.d.ts +35 -0
  582. package/dist/src/utils/partUtils.js +133 -0
  583. package/dist/src/utils/partUtils.js.map +1 -0
  584. package/dist/src/utils/partUtils.test.d.ts +6 -0
  585. package/dist/src/utils/partUtils.test.js +241 -0
  586. package/dist/src/utils/partUtils.test.js.map +1 -0
  587. package/dist/src/utils/pathReader.d.ts +17 -0
  588. package/dist/src/utils/pathReader.js +92 -0
  589. package/dist/src/utils/pathReader.js.map +1 -0
  590. package/dist/src/utils/pathReader.test.d.ts +6 -0
  591. package/dist/src/utils/pathReader.test.js +363 -0
  592. package/dist/src/utils/pathReader.test.js.map +1 -0
  593. package/dist/src/utils/paths.d.ts +58 -0
  594. package/dist/src/utils/paths.js +159 -0
  595. package/dist/src/utils/paths.js.map +1 -0
  596. package/dist/src/utils/paths.test.d.ts +6 -0
  597. package/dist/src/utils/paths.test.js +225 -0
  598. package/dist/src/utils/paths.test.js.map +1 -0
  599. package/dist/src/utils/quotaErrorDetection.d.ts +18 -0
  600. package/dist/src/utils/quotaErrorDetection.js +65 -0
  601. package/dist/src/utils/quotaErrorDetection.js.map +1 -0
  602. package/dist/src/utils/retry.d.ts +30 -0
  603. package/dist/src/utils/retry.js +276 -0
  604. package/dist/src/utils/retry.js.map +1 -0
  605. package/dist/src/utils/retry.test.d.ts +6 -0
  606. package/dist/src/utils/retry.test.js +325 -0
  607. package/dist/src/utils/retry.test.js.map +1 -0
  608. package/dist/src/utils/safeJsonStringify.d.ts +13 -0
  609. package/dist/src/utils/safeJsonStringify.js +25 -0
  610. package/dist/src/utils/safeJsonStringify.js.map +1 -0
  611. package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
  612. package/dist/src/utils/safeJsonStringify.test.js +61 -0
  613. package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
  614. package/dist/src/utils/schemaValidator.d.ts +15 -0
  615. package/dist/src/utils/schemaValidator.js +38 -0
  616. package/dist/src/utils/schemaValidator.js.map +1 -0
  617. package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
  618. package/dist/src/utils/secure-browser-launcher.js +165 -0
  619. package/dist/src/utils/secure-browser-launcher.js.map +1 -0
  620. package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
  621. package/dist/src/utils/secure-browser-launcher.test.js +149 -0
  622. package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
  623. package/dist/src/utils/session.d.ts +6 -0
  624. package/dist/src/utils/session.js +8 -0
  625. package/dist/src/utils/session.js.map +1 -0
  626. package/dist/src/utils/shell-utils.d.ts +117 -0
  627. package/dist/src/utils/shell-utils.js +370 -0
  628. package/dist/src/utils/shell-utils.js.map +1 -0
  629. package/dist/src/utils/shell-utils.test.d.ts +6 -0
  630. package/dist/src/utils/shell-utils.test.js +332 -0
  631. package/dist/src/utils/shell-utils.test.js.map +1 -0
  632. package/dist/src/utils/summarizer.d.ts +25 -0
  633. package/dist/src/utils/summarizer.js +51 -0
  634. package/dist/src/utils/summarizer.js.map +1 -0
  635. package/dist/src/utils/summarizer.test.d.ts +6 -0
  636. package/dist/src/utils/summarizer.test.js +131 -0
  637. package/dist/src/utils/summarizer.test.js.map +1 -0
  638. package/dist/src/utils/systemEncoding.d.ts +40 -0
  639. package/dist/src/utils/systemEncoding.js +149 -0
  640. package/dist/src/utils/systemEncoding.js.map +1 -0
  641. package/dist/src/utils/systemEncoding.test.d.ts +6 -0
  642. package/dist/src/utils/systemEncoding.test.js +368 -0
  643. package/dist/src/utils/systemEncoding.test.js.map +1 -0
  644. package/dist/src/utils/testUtils.d.ts +29 -0
  645. package/dist/src/utils/testUtils.js +70 -0
  646. package/dist/src/utils/testUtils.js.map +1 -0
  647. package/dist/src/utils/textUtils.d.ts +13 -0
  648. package/dist/src/utils/textUtils.js +28 -0
  649. package/dist/src/utils/textUtils.js.map +1 -0
  650. package/dist/src/utils/tool-utils.d.ts +19 -0
  651. package/dist/src/utils/tool-utils.js +58 -0
  652. package/dist/src/utils/tool-utils.js.map +1 -0
  653. package/dist/src/utils/tool-utils.test.d.ts +6 -0
  654. package/dist/src/utils/tool-utils.test.js +61 -0
  655. package/dist/src/utils/tool-utils.test.js.map +1 -0
  656. package/dist/src/utils/userAccountManager.d.ts +20 -0
  657. package/dist/src/utils/userAccountManager.js +114 -0
  658. package/dist/src/utils/userAccountManager.js.map +1 -0
  659. package/dist/src/utils/userAccountManager.test.d.ts +6 -0
  660. package/dist/src/utils/userAccountManager.test.js +223 -0
  661. package/dist/src/utils/userAccountManager.test.js.map +1 -0
  662. package/dist/src/utils/workspaceContext.d.ts +66 -0
  663. package/dist/src/utils/workspaceContext.js +171 -0
  664. package/dist/src/utils/workspaceContext.js.map +1 -0
  665. package/dist/src/utils/workspaceContext.test.d.ts +6 -0
  666. package/dist/src/utils/workspaceContext.test.js +318 -0
  667. package/dist/src/utils/workspaceContext.test.js.map +1 -0
  668. package/dist/tsconfig.tsbuildinfo +1 -0
  669. package/package.json +85 -0
@@ -0,0 +1,295 @@
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 'node:path';
9
+ import fs from 'node:fs/promises';
10
+ import os from 'node:os';
11
+ import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
12
+ import { ToolErrorType } from './tool-error.js';
13
+ import * as glob from 'glob';
14
+ vi.mock('glob', { spy: true });
15
+ // Mock the child_process module to control grep/git grep behavior
16
+ vi.mock('child_process', () => ({
17
+ spawn: vi.fn(() => ({
18
+ on: (event, cb) => {
19
+ if (event === 'error' || event === 'close') {
20
+ // Simulate command not found or error for git grep and system grep
21
+ // to force it to fall back to JS implementation.
22
+ setTimeout(() => cb(1), 0); // cb(1) for error/close
23
+ }
24
+ },
25
+ stdout: { on: vi.fn() },
26
+ stderr: { on: vi.fn() },
27
+ })),
28
+ }));
29
+ describe('GrepTool', () => {
30
+ let tempRootDir;
31
+ let grepTool;
32
+ const abortSignal = new AbortController().signal;
33
+ const mockConfig = {
34
+ getTargetDir: () => tempRootDir,
35
+ getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir),
36
+ getFileExclusions: () => ({
37
+ getGlobExcludes: () => [],
38
+ }),
39
+ };
40
+ beforeEach(async () => {
41
+ tempRootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-root-'));
42
+ grepTool = new GrepTool(mockConfig);
43
+ // Create some test files and directories
44
+ await fs.writeFile(path.join(tempRootDir, 'fileA.txt'), 'hello world\nsecond line with world');
45
+ await fs.writeFile(path.join(tempRootDir, 'fileB.js'), 'const foo = "bar";\nfunction baz() { return "hello"; }');
46
+ await fs.mkdir(path.join(tempRootDir, 'sub'));
47
+ await fs.writeFile(path.join(tempRootDir, 'sub', 'fileC.txt'), 'another world in sub dir');
48
+ await fs.writeFile(path.join(tempRootDir, 'sub', 'fileD.md'), '# Markdown file\nThis is a test.');
49
+ });
50
+ afterEach(async () => {
51
+ await fs.rm(tempRootDir, { recursive: true, force: true });
52
+ });
53
+ describe('validateToolParams', () => {
54
+ it('should return null for valid params (pattern only)', () => {
55
+ const params = { pattern: 'hello' };
56
+ expect(grepTool.validateToolParams(params)).toBeNull();
57
+ });
58
+ it('should return null for valid params (pattern and path)', () => {
59
+ const params = { pattern: 'hello', path: '.' };
60
+ expect(grepTool.validateToolParams(params)).toBeNull();
61
+ });
62
+ it('should return null for valid params (pattern, path, and include)', () => {
63
+ const params = {
64
+ pattern: 'hello',
65
+ path: '.',
66
+ include: '*.txt',
67
+ };
68
+ expect(grepTool.validateToolParams(params)).toBeNull();
69
+ });
70
+ it('should return error if pattern is missing', () => {
71
+ const params = { path: '.' };
72
+ expect(grepTool.validateToolParams(params)).toBe(`params must have required property 'pattern'`);
73
+ });
74
+ it('should return error for invalid regex pattern', () => {
75
+ const params = { pattern: '[[' };
76
+ expect(grepTool.validateToolParams(params)).toContain('Invalid regular expression pattern');
77
+ });
78
+ it('should return error if path does not exist', () => {
79
+ const params = { pattern: 'hello', path: 'nonexistent' };
80
+ // Check for the core error message, as the full path might vary
81
+ expect(grepTool.validateToolParams(params)).toContain('Failed to access path stats for');
82
+ expect(grepTool.validateToolParams(params)).toContain('nonexistent');
83
+ });
84
+ it('should return error if path is a file, not a directory', async () => {
85
+ const filePath = path.join(tempRootDir, 'fileA.txt');
86
+ const params = { pattern: 'hello', path: filePath };
87
+ expect(grepTool.validateToolParams(params)).toContain(`Path is not a directory: ${filePath}`);
88
+ });
89
+ });
90
+ describe('execute', () => {
91
+ it('should find matches for a simple pattern in all files', async () => {
92
+ const params = { pattern: 'world' };
93
+ const invocation = grepTool.build(params);
94
+ const result = await invocation.execute(abortSignal);
95
+ expect(result.llmContent).toContain('Found 3 matches for pattern "world" in the workspace directory');
96
+ expect(result.llmContent).toContain('File: fileA.txt');
97
+ expect(result.llmContent).toContain('L1: hello world');
98
+ expect(result.llmContent).toContain('L2: second line with world');
99
+ expect(result.llmContent).toContain(`File: ${path.join('sub', 'fileC.txt')}`);
100
+ expect(result.llmContent).toContain('L1: another world in sub dir');
101
+ expect(result.returnDisplay).toBe('Found 3 matches');
102
+ });
103
+ it('should find matches in a specific path', async () => {
104
+ const params = { pattern: 'world', path: 'sub' };
105
+ const invocation = grepTool.build(params);
106
+ const result = await invocation.execute(abortSignal);
107
+ expect(result.llmContent).toContain('Found 1 match for pattern "world" in path "sub"');
108
+ expect(result.llmContent).toContain('File: fileC.txt'); // Path relative to 'sub'
109
+ expect(result.llmContent).toContain('L1: another world in sub dir');
110
+ expect(result.returnDisplay).toBe('Found 1 match');
111
+ });
112
+ it('should find matches with an include glob', async () => {
113
+ const params = { pattern: 'hello', include: '*.js' };
114
+ const invocation = grepTool.build(params);
115
+ const result = await invocation.execute(abortSignal);
116
+ expect(result.llmContent).toContain('Found 1 match for pattern "hello" in the workspace directory (filter: "*.js"):');
117
+ expect(result.llmContent).toContain('File: fileB.js');
118
+ expect(result.llmContent).toContain('L2: function baz() { return "hello"; }');
119
+ expect(result.returnDisplay).toBe('Found 1 match');
120
+ });
121
+ it('should find matches with an include glob and path', async () => {
122
+ await fs.writeFile(path.join(tempRootDir, 'sub', 'another.js'), 'const greeting = "hello";');
123
+ const params = {
124
+ pattern: 'hello',
125
+ path: 'sub',
126
+ include: '*.js',
127
+ };
128
+ const invocation = grepTool.build(params);
129
+ const result = await invocation.execute(abortSignal);
130
+ expect(result.llmContent).toContain('Found 1 match for pattern "hello" in path "sub" (filter: "*.js")');
131
+ expect(result.llmContent).toContain('File: another.js');
132
+ expect(result.llmContent).toContain('L1: const greeting = "hello";');
133
+ expect(result.returnDisplay).toBe('Found 1 match');
134
+ });
135
+ it('should return "No matches found" when pattern does not exist', async () => {
136
+ const params = { pattern: 'nonexistentpattern' };
137
+ const invocation = grepTool.build(params);
138
+ const result = await invocation.execute(abortSignal);
139
+ expect(result.llmContent).toContain('No matches found for pattern "nonexistentpattern" in the workspace directory.');
140
+ expect(result.returnDisplay).toBe('No matches found');
141
+ });
142
+ it('should handle regex special characters correctly', async () => {
143
+ const params = { pattern: 'foo.*bar' }; // Matches 'const foo = "bar";'
144
+ const invocation = grepTool.build(params);
145
+ const result = await invocation.execute(abortSignal);
146
+ expect(result.llmContent).toContain('Found 1 match for pattern "foo.*bar" in the workspace directory:');
147
+ expect(result.llmContent).toContain('File: fileB.js');
148
+ expect(result.llmContent).toContain('L1: const foo = "bar";');
149
+ });
150
+ it('should be case-insensitive by default (JS fallback)', async () => {
151
+ const params = { pattern: 'HELLO' };
152
+ const invocation = grepTool.build(params);
153
+ const result = await invocation.execute(abortSignal);
154
+ expect(result.llmContent).toContain('Found 2 matches for pattern "HELLO" in the workspace directory:');
155
+ expect(result.llmContent).toContain('File: fileA.txt');
156
+ expect(result.llmContent).toContain('L1: hello world');
157
+ expect(result.llmContent).toContain('File: fileB.js');
158
+ expect(result.llmContent).toContain('L2: function baz() { return "hello"; }');
159
+ });
160
+ it('should throw an error if params are invalid', async () => {
161
+ const params = { path: '.' }; // Invalid: pattern missing
162
+ expect(() => grepTool.build(params)).toThrow(/params must have required property 'pattern'/);
163
+ });
164
+ it('should return a GREP_EXECUTION_ERROR on failure', async () => {
165
+ vi.mocked(glob.globStream).mockRejectedValue(new Error('Glob failed'));
166
+ const params = { pattern: 'hello' };
167
+ const invocation = grepTool.build(params);
168
+ const result = await invocation.execute(abortSignal);
169
+ expect(result.error?.type).toBe(ToolErrorType.GREP_EXECUTION_ERROR);
170
+ vi.mocked(glob.globStream).mockReset();
171
+ });
172
+ });
173
+ describe('multi-directory workspace', () => {
174
+ it('should search across all workspace directories when no path is specified', async () => {
175
+ // Create additional directory with test files
176
+ const secondDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-second-'));
177
+ await fs.writeFile(path.join(secondDir, 'other.txt'), 'hello from second directory\nworld in second');
178
+ await fs.writeFile(path.join(secondDir, 'another.js'), 'function world() { return "test"; }');
179
+ // Create a mock config with multiple directories
180
+ const multiDirConfig = {
181
+ getTargetDir: () => tempRootDir,
182
+ getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir, [secondDir]),
183
+ getFileExclusions: () => ({
184
+ getGlobExcludes: () => [],
185
+ }),
186
+ };
187
+ const multiDirGrepTool = new GrepTool(multiDirConfig);
188
+ const params = { pattern: 'world' };
189
+ const invocation = multiDirGrepTool.build(params);
190
+ const result = await invocation.execute(abortSignal);
191
+ // Should find matches in both directories
192
+ expect(result.llmContent).toContain('Found 5 matches for pattern "world"');
193
+ // Matches from first directory
194
+ expect(result.llmContent).toContain('fileA.txt');
195
+ expect(result.llmContent).toContain('L1: hello world');
196
+ expect(result.llmContent).toContain('L2: second line with world');
197
+ expect(result.llmContent).toContain('fileC.txt');
198
+ expect(result.llmContent).toContain('L1: another world in sub dir');
199
+ // Matches from second directory (with directory name prefix)
200
+ const secondDirName = path.basename(secondDir);
201
+ expect(result.llmContent).toContain(`File: ${path.join(secondDirName, 'other.txt')}`);
202
+ expect(result.llmContent).toContain('L2: world in second');
203
+ expect(result.llmContent).toContain(`File: ${path.join(secondDirName, 'another.js')}`);
204
+ expect(result.llmContent).toContain('L1: function world()');
205
+ // Clean up
206
+ await fs.rm(secondDir, { recursive: true, force: true });
207
+ });
208
+ it('should search only specified path within workspace directories', async () => {
209
+ // Create additional directory
210
+ const secondDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grep-tool-second-'));
211
+ await fs.mkdir(path.join(secondDir, 'sub'));
212
+ await fs.writeFile(path.join(secondDir, 'sub', 'test.txt'), 'hello from second sub directory');
213
+ // Create a mock config with multiple directories
214
+ const multiDirConfig = {
215
+ getTargetDir: () => tempRootDir,
216
+ getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir, [secondDir]),
217
+ getFileExclusions: () => ({
218
+ getGlobExcludes: () => [],
219
+ }),
220
+ };
221
+ const multiDirGrepTool = new GrepTool(multiDirConfig);
222
+ // Search only in the 'sub' directory of the first workspace
223
+ const params = { pattern: 'world', path: 'sub' };
224
+ const invocation = multiDirGrepTool.build(params);
225
+ const result = await invocation.execute(abortSignal);
226
+ // Should only find matches in the specified sub directory
227
+ expect(result.llmContent).toContain('Found 1 match for pattern "world" in path "sub"');
228
+ expect(result.llmContent).toContain('File: fileC.txt');
229
+ expect(result.llmContent).toContain('L1: another world in sub dir');
230
+ // Should not contain matches from second directory
231
+ expect(result.llmContent).not.toContain('test.txt');
232
+ // Clean up
233
+ await fs.rm(secondDir, { recursive: true, force: true });
234
+ });
235
+ });
236
+ describe('getDescription', () => {
237
+ it('should generate correct description with pattern only', () => {
238
+ const params = { pattern: 'testPattern' };
239
+ const invocation = grepTool.build(params);
240
+ expect(invocation.getDescription()).toBe("'testPattern'");
241
+ });
242
+ it('should generate correct description with pattern and include', () => {
243
+ const params = {
244
+ pattern: 'testPattern',
245
+ include: '*.ts',
246
+ };
247
+ const invocation = grepTool.build(params);
248
+ expect(invocation.getDescription()).toBe("'testPattern' in *.ts");
249
+ });
250
+ it('should generate correct description with pattern and path', async () => {
251
+ const dirPath = path.join(tempRootDir, 'src', 'app');
252
+ await fs.mkdir(dirPath, { recursive: true });
253
+ const params = {
254
+ pattern: 'testPattern',
255
+ path: path.join('src', 'app'),
256
+ };
257
+ const invocation = grepTool.build(params);
258
+ // The path will be relative to the tempRootDir, so we check for containment.
259
+ expect(invocation.getDescription()).toContain("'testPattern' within");
260
+ expect(invocation.getDescription()).toContain(path.join('src', 'app'));
261
+ });
262
+ it('should indicate searching across all workspace directories when no path specified', () => {
263
+ // Create a mock config with multiple directories
264
+ const multiDirConfig = {
265
+ getTargetDir: () => tempRootDir,
266
+ getWorkspaceContext: () => createMockWorkspaceContext(tempRootDir, ['/another/dir']),
267
+ getFileExclusions: () => ({
268
+ getGlobExcludes: () => [],
269
+ }),
270
+ };
271
+ const multiDirGrepTool = new GrepTool(multiDirConfig);
272
+ const params = { pattern: 'testPattern' };
273
+ const invocation = multiDirGrepTool.build(params);
274
+ expect(invocation.getDescription()).toBe("'testPattern' across all workspace directories");
275
+ });
276
+ it('should generate correct description with pattern, include, and path', async () => {
277
+ const dirPath = path.join(tempRootDir, 'src', 'app');
278
+ await fs.mkdir(dirPath, { recursive: true });
279
+ const params = {
280
+ pattern: 'testPattern',
281
+ include: '*.ts',
282
+ path: path.join('src', 'app'),
283
+ };
284
+ const invocation = grepTool.build(params);
285
+ expect(invocation.getDescription()).toContain("'testPattern' in *.ts within");
286
+ expect(invocation.getDescription()).toContain(path.join('src', 'app'));
287
+ });
288
+ it('should use ./ for root path in description', () => {
289
+ const params = { pattern: 'testPattern', path: '.' };
290
+ const invocation = grepTool.build(params);
291
+ expect(invocation.getDescription()).toBe("'testPattern' within ./");
292
+ });
293
+ });
294
+ });
295
+ //# 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;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAE/B,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,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}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { ToolInvocation, ToolResult } from './tools.js';
7
+ import { BaseDeclarativeTool } from './tools.js';
8
+ import type { Config } from '../config/config.js';
9
+ /**
10
+ * Parameters for the LS tool
11
+ */
12
+ export interface LSToolParams {
13
+ /**
14
+ * The absolute path to the directory to list
15
+ */
16
+ path: string;
17
+ /**
18
+ * Array of glob patterns to ignore (optional)
19
+ */
20
+ ignore?: string[];
21
+ /**
22
+ * Whether to respect .gitignore and .geminiignore patterns (optional, defaults to true)
23
+ */
24
+ file_filtering_options?: {
25
+ respect_git_ignore?: boolean;
26
+ respect_gemini_ignore?: boolean;
27
+ };
28
+ }
29
+ /**
30
+ * File entry returned by LS tool
31
+ */
32
+ export interface FileEntry {
33
+ /**
34
+ * Name of the file or directory
35
+ */
36
+ name: string;
37
+ /**
38
+ * Absolute path to the file or directory
39
+ */
40
+ path: string;
41
+ /**
42
+ * Whether this entry is a directory
43
+ */
44
+ isDirectory: boolean;
45
+ /**
46
+ * Size of the file in bytes (0 for directories)
47
+ */
48
+ size: number;
49
+ /**
50
+ * Last modified timestamp
51
+ */
52
+ modifiedTime: Date;
53
+ }
54
+ /**
55
+ * Implementation of the LS tool logic
56
+ */
57
+ export declare class LSTool extends BaseDeclarativeTool<LSToolParams, ToolResult> {
58
+ private config;
59
+ static readonly Name = "list_directory";
60
+ constructor(config: Config);
61
+ /**
62
+ * Validates the parameters for the tool
63
+ * @param params Parameters to validate
64
+ * @returns An error message string if invalid, null otherwise
65
+ */
66
+ protected validateToolParamValues(params: LSToolParams): string | null;
67
+ protected createInvocation(params: LSToolParams): ToolInvocation<LSToolParams, ToolResult>;
68
+ }
@@ -0,0 +1,227 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
9
+ import { makeRelative, shortenPath } from '../utils/paths.js';
10
+ import { DEFAULT_FILE_FILTERING_OPTIONS } from '../config/config.js';
11
+ import { ToolErrorType } from './tool-error.js';
12
+ class LSToolInvocation extends BaseToolInvocation {
13
+ config;
14
+ constructor(config, params) {
15
+ super(params);
16
+ this.config = config;
17
+ }
18
+ /**
19
+ * Checks if a filename matches any of the ignore patterns
20
+ * @param filename Filename to check
21
+ * @param patterns Array of glob patterns to check against
22
+ * @returns True if the filename should be ignored
23
+ */
24
+ shouldIgnore(filename, patterns) {
25
+ if (!patterns || patterns.length === 0) {
26
+ return false;
27
+ }
28
+ for (const pattern of patterns) {
29
+ // Convert glob pattern to RegExp
30
+ const regexPattern = pattern
31
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
32
+ .replace(/\*/g, '.*')
33
+ .replace(/\?/g, '.');
34
+ const regex = new RegExp(`^${regexPattern}$`);
35
+ if (regex.test(filename)) {
36
+ return true;
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+ /**
42
+ * Gets a description of the file reading operation
43
+ * @returns A string describing the file being read
44
+ */
45
+ getDescription() {
46
+ const relativePath = makeRelative(this.params.path, this.config.getTargetDir());
47
+ return shortenPath(relativePath);
48
+ }
49
+ // Helper for consistent error formatting
50
+ errorResult(llmContent, returnDisplay, type) {
51
+ return {
52
+ llmContent,
53
+ // Keep returnDisplay simpler in core logic
54
+ returnDisplay: `Error: ${returnDisplay}`,
55
+ error: {
56
+ message: llmContent,
57
+ type,
58
+ },
59
+ };
60
+ }
61
+ /**
62
+ * Executes the LS operation with the given parameters
63
+ * @returns Result of the LS operation
64
+ */
65
+ async execute(_signal) {
66
+ try {
67
+ const stats = fs.statSync(this.params.path);
68
+ if (!stats) {
69
+ // fs.statSync throws on non-existence, so this check might be redundant
70
+ // but keeping for clarity. Error message adjusted.
71
+ return this.errorResult(`Error: Directory not found or inaccessible: ${this.params.path}`, `Directory not found or inaccessible.`, ToolErrorType.FILE_NOT_FOUND);
72
+ }
73
+ if (!stats.isDirectory()) {
74
+ return this.errorResult(`Error: Path is not a directory: ${this.params.path}`, `Path is not a directory.`, ToolErrorType.PATH_IS_NOT_A_DIRECTORY);
75
+ }
76
+ const files = fs.readdirSync(this.params.path);
77
+ const defaultFileIgnores = this.config.getFileFilteringOptions() ?? DEFAULT_FILE_FILTERING_OPTIONS;
78
+ const fileFilteringOptions = {
79
+ respectGitIgnore: this.params.file_filtering_options?.respect_git_ignore ??
80
+ defaultFileIgnores.respectGitIgnore,
81
+ respectGeminiIgnore: this.params.file_filtering_options?.respect_gemini_ignore ??
82
+ defaultFileIgnores.respectGeminiIgnore,
83
+ };
84
+ // Get centralized file discovery service
85
+ const fileDiscovery = this.config.getFileService();
86
+ const entries = [];
87
+ let gitIgnoredCount = 0;
88
+ let geminiIgnoredCount = 0;
89
+ if (files.length === 0) {
90
+ // Changed error message to be more neutral for LLM
91
+ return {
92
+ llmContent: `Directory ${this.params.path} is empty.`,
93
+ returnDisplay: `Directory is empty.`,
94
+ };
95
+ }
96
+ for (const file of files) {
97
+ if (this.shouldIgnore(file, this.params.ignore)) {
98
+ continue;
99
+ }
100
+ const fullPath = path.join(this.params.path, file);
101
+ const relativePath = path.relative(this.config.getTargetDir(), fullPath);
102
+ // Check if this file should be ignored based on git or gemini ignore rules
103
+ if (fileFilteringOptions.respectGitIgnore &&
104
+ fileDiscovery.shouldGitIgnoreFile(relativePath)) {
105
+ gitIgnoredCount++;
106
+ continue;
107
+ }
108
+ if (fileFilteringOptions.respectGeminiIgnore &&
109
+ fileDiscovery.shouldGeminiIgnoreFile(relativePath)) {
110
+ geminiIgnoredCount++;
111
+ continue;
112
+ }
113
+ try {
114
+ const stats = fs.statSync(fullPath);
115
+ const isDir = stats.isDirectory();
116
+ entries.push({
117
+ name: file,
118
+ path: fullPath,
119
+ isDirectory: isDir,
120
+ size: isDir ? 0 : stats.size,
121
+ modifiedTime: stats.mtime,
122
+ });
123
+ }
124
+ catch (error) {
125
+ // Log error internally but don't fail the whole listing
126
+ console.error(`Error accessing ${fullPath}: ${error}`);
127
+ }
128
+ }
129
+ // Sort entries (directories first, then alphabetically)
130
+ entries.sort((a, b) => {
131
+ if (a.isDirectory && !b.isDirectory)
132
+ return -1;
133
+ if (!a.isDirectory && b.isDirectory)
134
+ return 1;
135
+ return a.name.localeCompare(b.name);
136
+ });
137
+ // Create formatted content for LLM
138
+ const directoryContent = entries
139
+ .map((entry) => `${entry.isDirectory ? '[DIR] ' : ''}${entry.name}`)
140
+ .join('\n');
141
+ let resultMessage = `Directory listing for ${this.params.path}:\n${directoryContent}`;
142
+ const ignoredMessages = [];
143
+ if (gitIgnoredCount > 0) {
144
+ ignoredMessages.push(`${gitIgnoredCount} git-ignored`);
145
+ }
146
+ if (geminiIgnoredCount > 0) {
147
+ ignoredMessages.push(`${geminiIgnoredCount} gemini-ignored`);
148
+ }
149
+ if (ignoredMessages.length > 0) {
150
+ resultMessage += `\n\n(${ignoredMessages.join(', ')})`;
151
+ }
152
+ let displayMessage = `Listed ${entries.length} item(s).`;
153
+ if (ignoredMessages.length > 0) {
154
+ displayMessage += ` (${ignoredMessages.join(', ')})`;
155
+ }
156
+ return {
157
+ llmContent: resultMessage,
158
+ returnDisplay: displayMessage,
159
+ };
160
+ }
161
+ catch (error) {
162
+ const errorMsg = `Error listing directory: ${error instanceof Error ? error.message : String(error)}`;
163
+ return this.errorResult(errorMsg, 'Failed to list directory.', ToolErrorType.LS_EXECUTION_ERROR);
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Implementation of the LS tool logic
169
+ */
170
+ export class LSTool extends BaseDeclarativeTool {
171
+ config;
172
+ static Name = 'list_directory';
173
+ constructor(config) {
174
+ 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.', Kind.Search, {
175
+ properties: {
176
+ path: {
177
+ description: 'The absolute path to the directory to list (must be absolute, not relative)',
178
+ type: 'string',
179
+ },
180
+ ignore: {
181
+ description: 'List of glob patterns to ignore',
182
+ items: {
183
+ type: 'string',
184
+ },
185
+ type: 'array',
186
+ },
187
+ file_filtering_options: {
188
+ description: 'Optional: Whether to respect ignore patterns from .gitignore or .geminiignore',
189
+ type: 'object',
190
+ properties: {
191
+ respect_git_ignore: {
192
+ description: 'Optional: Whether to respect .gitignore patterns when listing files. Only available in git repositories. Defaults to true.',
193
+ type: 'boolean',
194
+ },
195
+ respect_gemini_ignore: {
196
+ description: 'Optional: Whether to respect .geminiignore patterns when listing files. Defaults to true.',
197
+ type: 'boolean',
198
+ },
199
+ },
200
+ },
201
+ },
202
+ required: ['path'],
203
+ type: 'object',
204
+ });
205
+ this.config = config;
206
+ }
207
+ /**
208
+ * Validates the parameters for the tool
209
+ * @param params Parameters to validate
210
+ * @returns An error message string if invalid, null otherwise
211
+ */
212
+ validateToolParamValues(params) {
213
+ if (!path.isAbsolute(params.path)) {
214
+ return `Path must be absolute: ${params.path}`;
215
+ }
216
+ const workspaceContext = this.config.getWorkspaceContext();
217
+ if (!workspaceContext.isPathWithinWorkspace(params.path)) {
218
+ const directories = workspaceContext.getDirectories();
219
+ return `Path must be within one of the workspace directories: ${directories.join(', ')}`;
220
+ }
221
+ return null;
222
+ }
223
+ createInvocation(params) {
224
+ return new LSToolInvocation(this.config, params);
225
+ }
226
+ }
227
+ //# sourceMappingURL=ls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/tools/ls.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,8BAA8B,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