@google/gemini-cli-core 0.0.3-preview.4 → 0.0.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 (490) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +12 -2
  3. package/dist/index.d.ts +6 -2
  4. package/dist/index.js +6 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/code_assist/codeAssist.d.ts +2 -0
  7. package/dist/src/code_assist/codeAssist.js +12 -0
  8. package/dist/src/code_assist/codeAssist.js.map +1 -1
  9. package/dist/src/code_assist/converter.d.ts +3 -1
  10. package/dist/src/code_assist/converter.js +2 -1
  11. package/dist/src/code_assist/converter.js.map +1 -1
  12. package/dist/src/code_assist/converter.test.js +10 -0
  13. package/dist/src/code_assist/converter.test.js.map +1 -1
  14. package/dist/src/code_assist/oauth-credential-storage.d.ts +25 -0
  15. package/dist/src/code_assist/oauth-credential-storage.js +109 -0
  16. package/dist/src/code_assist/oauth-credential-storage.js.map +1 -0
  17. package/dist/src/code_assist/oauth-credential-storage.test.js +136 -0
  18. package/dist/src/code_assist/oauth-credential-storage.test.js.map +1 -0
  19. package/dist/src/code_assist/oauth2.js +92 -29
  20. package/dist/src/code_assist/oauth2.js.map +1 -1
  21. package/dist/src/code_assist/oauth2.test.js +729 -339
  22. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  23. package/dist/src/code_assist/server.d.ts +1 -1
  24. package/dist/src/code_assist/server.js +24 -1
  25. package/dist/src/code_assist/server.js.map +1 -1
  26. package/dist/src/code_assist/server.test.js +25 -0
  27. package/dist/src/code_assist/server.test.js.map +1 -1
  28. package/dist/src/code_assist/types.d.ts +17 -2
  29. package/dist/src/config/config.d.ts +72 -12
  30. package/dist/src/config/config.js +196 -64
  31. package/dist/src/config/config.js.map +1 -1
  32. package/dist/src/config/config.test.js +305 -178
  33. package/dist/src/config/config.test.js.map +1 -1
  34. package/dist/src/config/models.d.ts +16 -0
  35. package/dist/src/config/models.js +29 -0
  36. package/dist/src/config/models.js.map +1 -1
  37. package/dist/src/config/models.test.d.ts +6 -0
  38. package/dist/src/config/models.test.js +55 -0
  39. package/dist/src/config/models.test.js.map +1 -0
  40. package/dist/src/config/storage.d.ts +2 -0
  41. package/dist/src/config/storage.js +6 -1
  42. package/dist/src/config/storage.js.map +1 -1
  43. package/dist/src/config/storage.test.js +4 -0
  44. package/dist/src/config/storage.test.js.map +1 -1
  45. package/dist/src/confirmation-bus/index.d.ts +7 -0
  46. package/dist/src/confirmation-bus/index.js +8 -0
  47. package/dist/src/confirmation-bus/index.js.map +1 -0
  48. package/dist/src/confirmation-bus/message-bus.d.ts +17 -0
  49. package/dist/src/confirmation-bus/message-bus.js +81 -0
  50. package/dist/src/confirmation-bus/message-bus.js.map +1 -0
  51. package/dist/src/confirmation-bus/message-bus.test.d.ts +6 -0
  52. package/dist/src/confirmation-bus/message-bus.test.js +164 -0
  53. package/dist/src/confirmation-bus/message-bus.test.js.map +1 -0
  54. package/dist/src/confirmation-bus/types.d.ts +38 -0
  55. package/dist/src/confirmation-bus/types.js +15 -0
  56. package/dist/src/confirmation-bus/types.js.map +1 -0
  57. package/dist/src/core/baseLlmClient.d.ts +46 -0
  58. package/dist/src/core/baseLlmClient.js +112 -0
  59. package/dist/src/core/baseLlmClient.js.map +1 -0
  60. package/dist/src/core/baseLlmClient.test.d.ts +6 -0
  61. package/dist/src/core/baseLlmClient.test.js +253 -0
  62. package/dist/src/core/baseLlmClient.test.js.map +1 -0
  63. package/dist/src/core/client.d.ts +16 -21
  64. package/dist/src/core/client.js +145 -232
  65. package/dist/src/core/client.js.map +1 -1
  66. package/dist/src/core/client.test.js +393 -492
  67. package/dist/src/core/client.test.js.map +1 -1
  68. package/dist/src/core/contentGenerator.d.ts +2 -3
  69. package/dist/src/core/contentGenerator.js +0 -4
  70. package/dist/src/core/contentGenerator.js.map +1 -1
  71. package/dist/src/core/contentGenerator.test.js +1 -3
  72. package/dist/src/core/contentGenerator.test.js.map +1 -1
  73. package/dist/src/core/coreToolScheduler.d.ts +8 -3
  74. package/dist/src/core/coreToolScheduler.js +106 -5
  75. package/dist/src/core/coreToolScheduler.js.map +1 -1
  76. package/dist/src/core/coreToolScheduler.test.js +233 -5
  77. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  78. package/dist/src/core/geminiChat.d.ts +38 -32
  79. package/dist/src/core/geminiChat.js +209 -219
  80. package/dist/src/core/geminiChat.js.map +1 -1
  81. package/dist/src/core/geminiChat.test.js +674 -386
  82. package/dist/src/core/geminiChat.test.js.map +1 -1
  83. package/dist/src/core/loggingContentGenerator.js +13 -16
  84. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  85. package/dist/src/core/nonInteractiveToolExecutor.test.js +59 -1
  86. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  87. package/dist/src/core/prompts.d.ts +5 -0
  88. package/dist/src/core/prompts.js +63 -42
  89. package/dist/src/core/prompts.js.map +1 -1
  90. package/dist/src/core/prompts.test.js +130 -1
  91. package/dist/src/core/prompts.test.js.map +1 -1
  92. package/dist/src/core/subagent.js +7 -10
  93. package/dist/src/core/subagent.js.map +1 -1
  94. package/dist/src/core/subagent.test.js +32 -22
  95. package/dist/src/core/subagent.test.js.map +1 -1
  96. package/dist/src/core/turn.d.ts +21 -5
  97. package/dist/src/core/turn.js +45 -11
  98. package/dist/src/core/turn.js.map +1 -1
  99. package/dist/src/core/turn.test.js +340 -100
  100. package/dist/src/core/turn.test.js.map +1 -1
  101. package/dist/src/fallback/handler.d.ts +7 -0
  102. package/dist/src/fallback/handler.js +51 -0
  103. package/dist/src/fallback/handler.js.map +1 -0
  104. package/dist/src/fallback/handler.test.d.ts +6 -0
  105. package/dist/src/fallback/handler.test.js +130 -0
  106. package/dist/src/fallback/handler.test.js.map +1 -0
  107. package/dist/src/fallback/types.d.ts +14 -0
  108. package/dist/src/fallback/types.js +7 -0
  109. package/dist/src/fallback/types.js.map +1 -0
  110. package/dist/src/generated/git-commit.d.ts +2 -2
  111. package/dist/src/generated/git-commit.js +2 -2
  112. package/dist/src/generated/git-commit.js.map +1 -1
  113. package/dist/src/ide/constants.d.ts +3 -0
  114. package/dist/src/ide/constants.js +3 -0
  115. package/dist/src/ide/constants.js.map +1 -1
  116. package/dist/src/ide/detect-ide.d.ts +42 -14
  117. package/dist/src/ide/detect-ide.js +22 -68
  118. package/dist/src/ide/detect-ide.js.map +1 -1
  119. package/dist/src/ide/detect-ide.test.js +11 -51
  120. package/dist/src/ide/detect-ide.test.js.map +1 -1
  121. package/dist/src/ide/ide-client.d.ts +60 -18
  122. package/dist/src/ide/ide-client.js +275 -53
  123. package/dist/src/ide/ide-client.js.map +1 -1
  124. package/dist/src/ide/ide-client.test.js +239 -6
  125. package/dist/src/ide/ide-client.test.js.map +1 -1
  126. package/dist/src/ide/ide-installer.d.ts +2 -2
  127. package/dist/src/ide/ide-installer.js +15 -11
  128. package/dist/src/ide/ide-installer.js.map +1 -1
  129. package/dist/src/ide/ide-installer.test.js +30 -12
  130. package/dist/src/ide/ide-installer.test.js.map +1 -1
  131. package/dist/src/ide/ideContext.d.ts +35 -365
  132. package/dist/src/ide/ideContext.js +60 -106
  133. package/dist/src/ide/ideContext.js.map +1 -1
  134. package/dist/src/ide/ideContext.test.js +152 -24
  135. package/dist/src/ide/ideContext.test.js.map +1 -1
  136. package/dist/src/ide/process-utils.d.ts +0 -1
  137. package/dist/src/ide/process-utils.js +43 -25
  138. package/dist/src/ide/process-utils.js.map +1 -1
  139. package/dist/src/ide/process-utils.test.js +90 -4
  140. package/dist/src/ide/process-utils.test.js.map +1 -1
  141. package/dist/src/ide/types.d.ts +486 -0
  142. package/dist/src/ide/types.js +138 -0
  143. package/dist/src/ide/types.js.map +1 -0
  144. package/dist/src/index.d.ts +10 -2
  145. package/dist/src/index.js +11 -2
  146. package/dist/src/index.js.map +1 -1
  147. package/dist/src/mcp/oauth-provider.d.ts +15 -12
  148. package/dist/src/mcp/oauth-provider.js +63 -56
  149. package/dist/src/mcp/oauth-provider.js.map +1 -1
  150. package/dist/src/mcp/oauth-provider.test.js +74 -35
  151. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  152. package/dist/src/mcp/oauth-token-storage.d.ts +14 -10
  153. package/dist/src/mcp/oauth-token-storage.js +52 -20
  154. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  155. package/dist/src/mcp/oauth-token-storage.test.js +255 -162
  156. package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
  157. package/dist/src/mcp/token-storage/base-token-storage.d.ts +1 -1
  158. package/dist/src/mcp/token-storage/base-token-storage.js +1 -1
  159. package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -1
  160. package/dist/src/mcp/token-storage/base-token-storage.test.js +1 -1
  161. package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -1
  162. package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
  163. package/dist/src/mcp/token-storage/file-token-storage.js +144 -0
  164. package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
  165. package/dist/src/mcp/token-storage/file-token-storage.test.d.ts +6 -0
  166. package/dist/src/mcp/token-storage/file-token-storage.test.js +235 -0
  167. package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -0
  168. package/dist/src/mcp/token-storage/hybrid-token-storage.d.ts +23 -0
  169. package/dist/src/mcp/token-storage/hybrid-token-storage.js +78 -0
  170. package/dist/src/mcp/token-storage/hybrid-token-storage.js.map +1 -0
  171. package/dist/src/mcp/token-storage/hybrid-token-storage.test.d.ts +6 -0
  172. package/dist/src/mcp/token-storage/hybrid-token-storage.test.js +193 -0
  173. package/dist/src/mcp/token-storage/hybrid-token-storage.test.js.map +1 -0
  174. package/dist/src/mcp/token-storage/index.d.ts +11 -0
  175. package/dist/src/mcp/token-storage/index.js +12 -0
  176. package/dist/src/mcp/token-storage/index.js.map +1 -0
  177. package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +31 -0
  178. package/dist/src/mcp/token-storage/keychain-token-storage.js +190 -0
  179. package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -0
  180. package/dist/src/mcp/token-storage/keychain-token-storage.test.d.ts +6 -0
  181. package/dist/src/mcp/token-storage/keychain-token-storage.test.js +254 -0
  182. package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -0
  183. package/dist/src/mcp/token-storage/types.d.ts +4 -0
  184. package/dist/src/mcp/token-storage/types.js +5 -1
  185. package/dist/src/mcp/token-storage/types.js.map +1 -1
  186. package/dist/src/output/json-formatter.d.ts +11 -0
  187. package/dist/src/output/json-formatter.js +30 -0
  188. package/dist/src/output/json-formatter.js.map +1 -0
  189. package/dist/src/output/json-formatter.test.d.ts +6 -0
  190. package/dist/src/output/json-formatter.test.js +266 -0
  191. package/dist/src/output/json-formatter.test.js.map +1 -0
  192. package/dist/src/output/types.d.ts +20 -0
  193. package/dist/src/output/types.js +11 -0
  194. package/dist/src/output/types.js.map +1 -0
  195. package/dist/src/policy/index.d.ts +7 -0
  196. package/dist/src/policy/index.js +8 -0
  197. package/dist/src/policy/index.js.map +1 -0
  198. package/dist/src/policy/policy-engine.d.ts +30 -0
  199. package/dist/src/policy/policy-engine.js +92 -0
  200. package/dist/src/policy/policy-engine.js.map +1 -0
  201. package/dist/src/policy/policy-engine.test.d.ts +6 -0
  202. package/dist/src/policy/policy-engine.test.js +515 -0
  203. package/dist/src/policy/policy-engine.test.js.map +1 -0
  204. package/dist/src/policy/stable-stringify.d.ts +58 -0
  205. package/dist/src/policy/stable-stringify.js +122 -0
  206. package/dist/src/policy/stable-stringify.js.map +1 -0
  207. package/dist/src/policy/types.d.ts +47 -0
  208. package/dist/src/policy/types.js +12 -0
  209. package/dist/src/policy/types.js.map +1 -0
  210. package/dist/src/routing/modelRouterService.d.ts +23 -0
  211. package/dist/src/routing/modelRouterService.js +70 -0
  212. package/dist/src/routing/modelRouterService.js.map +1 -0
  213. package/dist/src/routing/modelRouterService.test.d.ts +6 -0
  214. package/dist/src/routing/modelRouterService.test.js +98 -0
  215. package/dist/src/routing/modelRouterService.test.js.map +1 -0
  216. package/dist/src/routing/routingStrategy.d.ts +62 -0
  217. package/dist/src/routing/routingStrategy.js +7 -0
  218. package/dist/src/routing/routingStrategy.js.map +1 -0
  219. package/dist/src/routing/strategies/classifierStrategy.d.ts +12 -0
  220. package/dist/src/routing/strategies/classifierStrategy.js +173 -0
  221. package/dist/src/routing/strategies/classifierStrategy.js.map +1 -0
  222. package/dist/src/routing/strategies/classifierStrategy.test.d.ts +6 -0
  223. package/dist/src/routing/strategies/classifierStrategy.test.js +192 -0
  224. package/dist/src/routing/strategies/classifierStrategy.test.js.map +1 -0
  225. package/dist/src/routing/strategies/compositeStrategy.d.ts +26 -0
  226. package/dist/src/routing/strategies/compositeStrategy.js +67 -0
  227. package/dist/src/routing/strategies/compositeStrategy.js.map +1 -0
  228. package/dist/src/routing/strategies/compositeStrategy.test.d.ts +6 -0
  229. package/dist/src/routing/strategies/compositeStrategy.test.js +123 -0
  230. package/dist/src/routing/strategies/compositeStrategy.test.js.map +1 -0
  231. package/dist/src/routing/strategies/defaultStrategy.d.ts +12 -0
  232. package/dist/src/routing/strategies/defaultStrategy.js +20 -0
  233. package/dist/src/routing/strategies/defaultStrategy.js.map +1 -0
  234. package/dist/src/routing/strategies/defaultStrategy.test.d.ts +6 -0
  235. package/dist/src/routing/strategies/defaultStrategy.test.js +26 -0
  236. package/dist/src/routing/strategies/defaultStrategy.test.js.map +1 -0
  237. package/dist/src/routing/strategies/fallbackStrategy.d.ts +12 -0
  238. package/dist/src/routing/strategies/fallbackStrategy.js +25 -0
  239. package/dist/src/routing/strategies/fallbackStrategy.js.map +1 -0
  240. package/dist/src/routing/strategies/fallbackStrategy.test.d.ts +6 -0
  241. package/dist/src/routing/strategies/fallbackStrategy.test.js +55 -0
  242. package/dist/src/routing/strategies/fallbackStrategy.test.js.map +1 -0
  243. package/dist/src/routing/strategies/overrideStrategy.d.ts +15 -0
  244. package/dist/src/routing/strategies/overrideStrategy.js +28 -0
  245. package/dist/src/routing/strategies/overrideStrategy.js.map +1 -0
  246. package/dist/src/routing/strategies/overrideStrategy.test.d.ts +6 -0
  247. package/dist/src/routing/strategies/overrideStrategy.test.js +42 -0
  248. package/dist/src/routing/strategies/overrideStrategy.test.js.map +1 -0
  249. package/dist/src/services/chatRecordingService.d.ts +7 -13
  250. package/dist/src/services/chatRecordingService.js +28 -19
  251. package/dist/src/services/chatRecordingService.js.map +1 -1
  252. package/dist/src/services/chatRecordingService.test.js +62 -20
  253. package/dist/src/services/chatRecordingService.test.js.map +1 -1
  254. package/dist/src/services/fileDiscoveryService.d.ts +10 -0
  255. package/dist/src/services/fileDiscoveryService.js +31 -17
  256. package/dist/src/services/fileDiscoveryService.js.map +1 -1
  257. package/dist/src/services/gitService.js +9 -12
  258. package/dist/src/services/gitService.js.map +1 -1
  259. package/dist/src/services/gitService.test.js +10 -20
  260. package/dist/src/services/gitService.test.js.map +1 -1
  261. package/dist/src/services/loopDetectionService.d.ts +5 -0
  262. package/dist/src/services/loopDetectionService.js +36 -20
  263. package/dist/src/services/loopDetectionService.js.map +1 -1
  264. package/dist/src/services/loopDetectionService.test.js +41 -12
  265. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  266. package/dist/src/services/shellExecutionService.d.ts +34 -2
  267. package/dist/src/services/shellExecutionService.js +192 -43
  268. package/dist/src/services/shellExecutionService.js.map +1 -1
  269. package/dist/src/services/shellExecutionService.test.js +184 -55
  270. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  271. package/dist/src/telemetry/activity-detector.d.ts +41 -0
  272. package/dist/src/telemetry/activity-detector.js +61 -0
  273. package/dist/src/telemetry/activity-detector.js.map +1 -0
  274. package/dist/src/telemetry/activity-detector.test.d.ts +6 -0
  275. package/dist/src/telemetry/activity-detector.test.js +136 -0
  276. package/dist/src/telemetry/activity-detector.test.js.map +1 -0
  277. package/dist/src/telemetry/activity-types.d.ts +19 -0
  278. package/dist/src/telemetry/activity-types.js +21 -0
  279. package/dist/src/telemetry/activity-types.js.map +1 -0
  280. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +16 -2
  281. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +143 -24
  282. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  283. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +101 -1
  284. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
  285. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +19 -2
  286. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +48 -2
  287. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  288. package/dist/src/telemetry/constants.d.ts +8 -0
  289. package/dist/src/telemetry/constants.js +8 -0
  290. package/dist/src/telemetry/constants.js.map +1 -1
  291. package/dist/src/telemetry/gcp-exporters.d.ts +34 -0
  292. package/dist/src/telemetry/gcp-exporters.js +117 -0
  293. package/dist/src/telemetry/gcp-exporters.js.map +1 -0
  294. package/dist/src/telemetry/gcp-exporters.test.d.ts +6 -0
  295. package/dist/src/telemetry/gcp-exporters.test.js +318 -0
  296. package/dist/src/telemetry/gcp-exporters.test.js.map +1 -0
  297. package/dist/src/telemetry/high-water-mark-tracker.d.ts +43 -0
  298. package/dist/src/telemetry/high-water-mark-tracker.js +88 -0
  299. package/dist/src/telemetry/high-water-mark-tracker.js.map +1 -0
  300. package/dist/src/telemetry/high-water-mark-tracker.test.d.ts +6 -0
  301. package/dist/src/telemetry/high-water-mark-tracker.test.js +152 -0
  302. package/dist/src/telemetry/high-water-mark-tracker.test.js.map +1 -0
  303. package/dist/src/telemetry/index.d.ts +7 -2
  304. package/dist/src/telemetry/index.js +7 -2
  305. package/dist/src/telemetry/index.js.map +1 -1
  306. package/dist/src/telemetry/loggers.d.ts +8 -1
  307. package/dist/src/telemetry/loggers.js +140 -8
  308. package/dist/src/telemetry/loggers.js.map +1 -1
  309. package/dist/src/telemetry/loggers.test.js +268 -39
  310. package/dist/src/telemetry/loggers.test.js.map +1 -1
  311. package/dist/src/telemetry/metrics.d.ts +4 -3
  312. package/dist/src/telemetry/metrics.js +33 -10
  313. package/dist/src/telemetry/metrics.js.map +1 -1
  314. package/dist/src/telemetry/metrics.test.js +47 -25
  315. package/dist/src/telemetry/metrics.test.js.map +1 -1
  316. package/dist/src/telemetry/rate-limiter.d.ts +48 -0
  317. package/dist/src/telemetry/rate-limiter.js +100 -0
  318. package/dist/src/telemetry/rate-limiter.js.map +1 -0
  319. package/dist/src/telemetry/rate-limiter.test.d.ts +6 -0
  320. package/dist/src/telemetry/rate-limiter.test.js +207 -0
  321. package/dist/src/telemetry/rate-limiter.test.js.map +1 -0
  322. package/dist/src/telemetry/sdk.js +16 -1
  323. package/dist/src/telemetry/sdk.js.map +1 -1
  324. package/dist/src/telemetry/sdk.test.js +95 -0
  325. package/dist/src/telemetry/sdk.test.js.map +1 -1
  326. package/dist/src/telemetry/types.d.ts +70 -6
  327. package/dist/src/telemetry/types.js +112 -8
  328. package/dist/src/telemetry/types.js.map +1 -1
  329. package/dist/src/telemetry/uiTelemetry.d.ts +1 -1
  330. package/dist/src/telemetry/uiTelemetry.js +6 -7
  331. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  332. package/dist/src/telemetry/uiTelemetry.test.js +15 -15
  333. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  334. package/dist/src/test-utils/index.d.ts +6 -0
  335. package/dist/src/test-utils/index.js +7 -0
  336. package/dist/src/test-utils/index.js.map +1 -0
  337. package/dist/src/test-utils/mock-tool.d.ts +41 -0
  338. package/dist/src/test-utils/mock-tool.js +51 -0
  339. package/dist/src/test-utils/mock-tool.js.map +1 -0
  340. package/dist/src/tools/diffOptions.js +21 -13
  341. package/dist/src/tools/diffOptions.js.map +1 -1
  342. package/dist/src/tools/diffOptions.test.js +58 -22
  343. package/dist/src/tools/diffOptions.test.js.map +1 -1
  344. package/dist/src/tools/edit.d.ts +2 -2
  345. package/dist/src/tools/edit.js +35 -44
  346. package/dist/src/tools/edit.js.map +1 -1
  347. package/dist/src/tools/edit.test.js +124 -13
  348. package/dist/src/tools/edit.test.js.map +1 -1
  349. package/dist/src/tools/glob.d.ts +5 -1
  350. package/dist/src/tools/glob.js +24 -17
  351. package/dist/src/tools/glob.js.map +1 -1
  352. package/dist/src/tools/glob.test.js +51 -0
  353. package/dist/src/tools/glob.test.js.map +1 -1
  354. package/dist/src/tools/ls.js +19 -32
  355. package/dist/src/tools/ls.js.map +1 -1
  356. package/dist/src/tools/ls.test.js +140 -280
  357. package/dist/src/tools/ls.test.js.map +1 -1
  358. package/dist/src/tools/mcp-client-manager.d.ts +5 -3
  359. package/dist/src/tools/mcp-client-manager.js +13 -4
  360. package/dist/src/tools/mcp-client-manager.js.map +1 -1
  361. package/dist/src/tools/mcp-client-manager.test.js +20 -1
  362. package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
  363. package/dist/src/tools/mcp-client.d.ts +5 -5
  364. package/dist/src/tools/mcp-client.js +40 -35
  365. package/dist/src/tools/mcp-client.js.map +1 -1
  366. package/dist/src/tools/mcp-client.test.js +3 -3
  367. package/dist/src/tools/mcp-client.test.js.map +1 -1
  368. package/dist/src/tools/mcp-tool.d.ts +3 -2
  369. package/dist/src/tools/mcp-tool.js +9 -9
  370. package/dist/src/tools/mcp-tool.js.map +1 -1
  371. package/dist/src/tools/mcp-tool.test.js +28 -7
  372. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  373. package/dist/src/tools/memoryTool.js +5 -33
  374. package/dist/src/tools/memoryTool.js.map +1 -1
  375. package/dist/src/tools/read-file.js +8 -3
  376. package/dist/src/tools/read-file.js.map +1 -1
  377. package/dist/src/tools/read-file.test.js +29 -0
  378. package/dist/src/tools/read-file.test.js.map +1 -1
  379. package/dist/src/tools/read-many-files.d.ts +1 -1
  380. package/dist/src/tools/read-many-files.js +18 -50
  381. package/dist/src/tools/read-many-files.js.map +1 -1
  382. package/dist/src/tools/read-many-files.test.js +4 -4
  383. package/dist/src/tools/read-many-files.test.js.map +1 -1
  384. package/dist/src/tools/ripGrep.d.ts +8 -0
  385. package/dist/src/tools/ripGrep.js +26 -1
  386. package/dist/src/tools/ripGrep.js.map +1 -1
  387. package/dist/src/tools/ripGrep.test.js +107 -5
  388. package/dist/src/tools/ripGrep.test.js.map +1 -1
  389. package/dist/src/tools/shell.d.ts +12 -2
  390. package/dist/src/tools/shell.js +20 -24
  391. package/dist/src/tools/shell.js.map +1 -1
  392. package/dist/src/tools/shell.test.js +35 -70
  393. package/dist/src/tools/shell.test.js.map +1 -1
  394. package/dist/src/tools/smart-edit.d.ts +72 -0
  395. package/dist/src/tools/smart-edit.js +594 -0
  396. package/dist/src/tools/smart-edit.js.map +1 -0
  397. package/dist/src/tools/smart-edit.test.d.ts +6 -0
  398. package/dist/src/tools/smart-edit.test.js +419 -0
  399. package/dist/src/tools/smart-edit.test.js.map +1 -0
  400. package/dist/src/tools/tool-registry.d.ts +2 -1
  401. package/dist/src/tools/tool-registry.js +6 -5
  402. package/dist/src/tools/tool-registry.js.map +1 -1
  403. package/dist/src/tools/tools.d.ts +14 -7
  404. package/dist/src/tools/tools.js +9 -2
  405. package/dist/src/tools/tools.js.map +1 -1
  406. package/dist/src/tools/web-fetch.js +4 -3
  407. package/dist/src/tools/web-fetch.js.map +1 -1
  408. package/dist/src/tools/web-search.d.ts +1 -1
  409. package/dist/src/tools/web-search.js +3 -1
  410. package/dist/src/tools/web-search.js.map +1 -1
  411. package/dist/src/tools/write-file.js +14 -19
  412. package/dist/src/tools/write-file.js.map +1 -1
  413. package/dist/src/tools/write-file.test.js +99 -19
  414. package/dist/src/tools/write-file.test.js.map +1 -1
  415. package/dist/src/utils/bfsFileSearch.js +11 -5
  416. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  417. package/dist/src/utils/editCorrector.d.ts +7 -6
  418. package/dist/src/utils/editCorrector.js +61 -18
  419. package/dist/src/utils/editCorrector.js.map +1 -1
  420. package/dist/src/utils/editCorrector.test.js +30 -79
  421. package/dist/src/utils/editCorrector.test.js.map +1 -1
  422. package/dist/src/utils/editor.js +31 -44
  423. package/dist/src/utils/editor.js.map +1 -1
  424. package/dist/src/utils/editor.test.js +61 -75
  425. package/dist/src/utils/editor.test.js.map +1 -1
  426. package/dist/src/utils/errorParsing.js +2 -2
  427. package/dist/src/utils/errorParsing.js.map +1 -1
  428. package/dist/src/utils/errorParsing.test.js +7 -7
  429. package/dist/src/utils/errorParsing.test.js.map +1 -1
  430. package/dist/src/utils/errors.d.ts +6 -0
  431. package/dist/src/utils/errors.js +10 -0
  432. package/dist/src/utils/errors.js.map +1 -1
  433. package/dist/src/utils/fileUtils.d.ts +20 -3
  434. package/dist/src/utils/fileUtils.js +154 -32
  435. package/dist/src/utils/fileUtils.js.map +1 -1
  436. package/dist/src/utils/fileUtils.test.js +347 -29
  437. package/dist/src/utils/fileUtils.test.js.map +1 -1
  438. package/dist/src/utils/flashFallback.test.d.ts +6 -0
  439. package/dist/src/utils/{flashFallback.integration.test.js → flashFallback.test.js} +31 -27
  440. package/dist/src/utils/flashFallback.test.js.map +1 -0
  441. package/dist/src/utils/geminiIgnoreParser.d.ts +18 -0
  442. package/dist/src/utils/geminiIgnoreParser.js +61 -0
  443. package/dist/src/utils/geminiIgnoreParser.js.map +1 -0
  444. package/dist/src/utils/geminiIgnoreParser.test.d.ts +6 -0
  445. package/dist/src/utils/geminiIgnoreParser.test.js +50 -0
  446. package/dist/src/utils/geminiIgnoreParser.test.js.map +1 -0
  447. package/dist/src/utils/gitIgnoreParser.d.ts +3 -7
  448. package/dist/src/utils/gitIgnoreParser.js +125 -34
  449. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  450. package/dist/src/utils/gitIgnoreParser.test.js +66 -35
  451. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  452. package/dist/src/utils/llm-edit-fixer.d.ts +26 -0
  453. package/dist/src/utils/llm-edit-fixer.js +121 -0
  454. package/dist/src/utils/llm-edit-fixer.js.map +1 -0
  455. package/dist/src/utils/llm-edit-fixer.test.d.ts +6 -0
  456. package/dist/src/utils/llm-edit-fixer.test.js +105 -0
  457. package/dist/src/utils/llm-edit-fixer.test.js.map +1 -0
  458. package/dist/src/utils/memoryDiscovery.d.ts +5 -4
  459. package/dist/src/utils/memoryDiscovery.js +10 -9
  460. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  461. package/dist/src/utils/memoryDiscovery.test.js +50 -25
  462. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  463. package/dist/src/utils/nextSpeakerChecker.d.ts +2 -2
  464. package/dist/src/utils/nextSpeakerChecker.js +8 -2
  465. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  466. package/dist/src/utils/nextSpeakerChecker.test.js +75 -64
  467. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  468. package/dist/src/utils/promptIdContext.d.ts +7 -0
  469. package/dist/src/utils/promptIdContext.js +8 -0
  470. package/dist/src/utils/promptIdContext.js.map +1 -0
  471. package/dist/src/utils/shell-utils.d.ts +5 -0
  472. package/dist/src/utils/shell-utils.js +23 -0
  473. package/dist/src/utils/shell-utils.js.map +1 -1
  474. package/dist/src/utils/terminalSerializer.d.ts +28 -0
  475. package/dist/src/utils/terminalSerializer.js +432 -0
  476. package/dist/src/utils/terminalSerializer.js.map +1 -0
  477. package/dist/src/utils/terminalSerializer.test.d.ts +6 -0
  478. package/dist/src/utils/terminalSerializer.test.js +176 -0
  479. package/dist/src/utils/terminalSerializer.test.js.map +1 -0
  480. package/dist/src/utils/textUtils.d.ts +5 -0
  481. package/dist/src/utils/textUtils.js +14 -0
  482. package/dist/src/utils/textUtils.js.map +1 -1
  483. package/dist/src/utils/textUtils.test.d.ts +6 -0
  484. package/dist/src/utils/textUtils.test.js +59 -0
  485. package/dist/src/utils/textUtils.test.js.map +1 -0
  486. package/dist/tsconfig.tsbuildinfo +1 -1
  487. package/package.json +9 -3
  488. package/dist/google-gemini-cli-core-0.3.0-preview.3.tgz +0 -0
  489. package/dist/src/utils/flashFallback.integration.test.js.map +0 -1
  490. /package/dist/src/{utils/flashFallback.integration.test.d.ts → code_assist/oauth-credential-storage.test.d.ts} +0 -0
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { describe, it, expect, vi, beforeEach } from 'vitest';
6
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
7
7
  import { Config, ApprovalMode } from './config.js';
8
8
  import * as path from 'node:path';
9
9
  import { setGeminiMdFilename as mockSetGeminiMdFilename } from '../tools/memoryTool.js';
@@ -14,6 +14,11 @@ import { GitService } from '../services/gitService.js';
14
14
  import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js';
15
15
  import { ShellTool } from '../tools/shell.js';
16
16
  import { ReadFileTool } from '../tools/read-file.js';
17
+ import { GrepTool } from '../tools/grep.js';
18
+ import { RipGrepTool, canUseRipgrep } from '../tools/ripGrep.js';
19
+ import { logRipgrepFallback } from '../telemetry/loggers.js';
20
+ import { RipgrepFallbackEvent } from '../telemetry/types.js';
21
+ import { ToolRegistry } from '../tools/tool-registry.js';
17
22
  vi.mock('fs', async (importOriginal) => {
18
23
  const actual = await importOriginal();
19
24
  return {
@@ -41,7 +46,12 @@ vi.mock('../utils/memoryDiscovery.js', () => ({
41
46
  // Mock individual tools if their constructors are complex or have side effects
42
47
  vi.mock('../tools/ls');
43
48
  vi.mock('../tools/read-file');
44
- vi.mock('../tools/grep');
49
+ vi.mock('../tools/grep.js');
50
+ vi.mock('../tools/ripGrep.js', () => ({
51
+ canUseRipgrep: vi.fn(),
52
+ RipGrepTool: class MockRipGrepTool {
53
+ },
54
+ }));
45
55
  vi.mock('../tools/glob');
46
56
  vi.mock('../tools/edit');
47
57
  vi.mock('../tools/shell');
@@ -55,16 +65,11 @@ vi.mock('../tools/memoryTool', () => ({
55
65
  DEFAULT_CONTEXT_FILENAME: 'GEMINI.md',
56
66
  GEMINI_CONFIG_DIR: '.gemini',
57
67
  }));
58
- vi.mock('../core/contentGenerator.js', async (importOriginal) => {
59
- const actual = await importOriginal();
60
- return {
61
- ...actual,
62
- createContentGeneratorConfig: vi.fn(),
63
- };
64
- });
68
+ vi.mock('../core/contentGenerator.js');
65
69
  vi.mock('../core/client.js', () => ({
66
70
  GeminiClient: vi.fn().mockImplementation(() => ({
67
71
  initialize: vi.fn().mockResolvedValue(undefined),
72
+ stripThoughtsFromHistory: vi.fn(),
68
73
  })),
69
74
  }));
70
75
  vi.mock('../telemetry/index.js', async (importOriginal) => {
@@ -72,6 +77,16 @@ vi.mock('../telemetry/index.js', async (importOriginal) => {
72
77
  return {
73
78
  ...actual,
74
79
  initializeTelemetry: vi.fn(),
80
+ uiTelemetryService: {
81
+ getLastPromptTokenCount: vi.fn(),
82
+ },
83
+ };
84
+ });
85
+ vi.mock('../telemetry/loggers.js', async (importOriginal) => {
86
+ const actual = await importOriginal();
87
+ return {
88
+ ...actual,
89
+ logRipgrepFallback: vi.fn(),
75
90
  };
76
91
  });
77
92
  vi.mock('../services/gitService.js', () => {
@@ -79,6 +94,22 @@ vi.mock('../services/gitService.js', () => {
79
94
  GitServiceMock.prototype.initialize = vi.fn();
80
95
  return { GitService: GitServiceMock };
81
96
  });
97
+ vi.mock('../ide/ide-client.js', () => ({
98
+ IdeClient: {
99
+ getInstance: vi.fn().mockResolvedValue({
100
+ getConnectionStatus: vi.fn(),
101
+ initialize: vi.fn(),
102
+ shutdown: vi.fn(),
103
+ }),
104
+ },
105
+ }));
106
+ import { BaseLlmClient } from '../core/baseLlmClient.js';
107
+ import { tokenLimit } from '../core/tokenLimits.js';
108
+ import { uiTelemetryService } from '../telemetry/index.js';
109
+ vi.mock('../core/baseLlmClient.js');
110
+ vi.mock('../core/tokenLimits.js', () => ({
111
+ tokenLimit: vi.fn(),
112
+ }));
82
113
  describe('Server Config (config.ts)', () => {
83
114
  const MODEL = 'gemini-pro';
84
115
  const SANDBOX = {
@@ -144,144 +175,34 @@ describe('Server Config (config.ts)', () => {
144
175
  it('should refresh auth and update config', async () => {
145
176
  const config = new Config(baseParams);
146
177
  const authType = AuthType.USE_GEMINI;
147
- const newModel = 'gemini-flash';
148
178
  const mockContentConfig = {
149
- model: newModel,
150
179
  apiKey: 'test-key',
151
180
  };
152
- createContentGeneratorConfig.mockReturnValue(mockContentConfig);
181
+ vi.mocked(createContentGeneratorConfig).mockReturnValue(mockContentConfig);
153
182
  // Set fallback mode to true to ensure it gets reset
154
183
  config.setFallbackMode(true);
155
184
  expect(config.isInFallbackMode()).toBe(true);
156
185
  await config.refreshAuth(authType);
157
186
  expect(createContentGeneratorConfig).toHaveBeenCalledWith(config, authType);
158
- // Verify that contentGeneratorConfig is updated with the new model
187
+ // Verify that contentGeneratorConfig is updated
159
188
  expect(config.getContentGeneratorConfig()).toEqual(mockContentConfig);
160
- expect(config.getContentGeneratorConfig().model).toBe(newModel);
161
- expect(config.getModel()).toBe(newModel); // getModel() should return the updated model
162
189
  expect(GeminiClient).toHaveBeenCalledWith(config);
163
190
  // Verify that fallback mode is reset
164
191
  expect(config.isInFallbackMode()).toBe(false);
165
192
  });
166
- it('should preserve conversation history when refreshing auth', async () => {
167
- const config = new Config(baseParams);
168
- const authType = AuthType.USE_GEMINI;
169
- const mockContentConfig = {
170
- model: 'gemini-pro',
171
- apiKey: 'test-key',
172
- };
173
- createContentGeneratorConfig.mockReturnValue(mockContentConfig);
174
- // Mock the existing client with some history
175
- const mockExistingHistory = [
176
- { role: 'user', parts: [{ text: 'Hello' }] },
177
- { role: 'model', parts: [{ text: 'Hi there!' }] },
178
- { role: 'user', parts: [{ text: 'How are you?' }] },
179
- ];
180
- const mockExistingClient = {
181
- isInitialized: vi.fn().mockReturnValue(true),
182
- getHistory: vi.fn().mockReturnValue(mockExistingHistory),
183
- };
184
- const mockNewClient = {
185
- isInitialized: vi.fn().mockReturnValue(true),
186
- getHistory: vi.fn().mockReturnValue([]),
187
- setHistory: vi.fn(),
188
- initialize: vi.fn().mockResolvedValue(undefined),
189
- };
190
- // Set the existing client
191
- config.geminiClient = mockExistingClient;
192
- GeminiClient.mockImplementation(() => mockNewClient);
193
- await config.refreshAuth(authType);
194
- // Verify that existing history was retrieved
195
- expect(mockExistingClient.getHistory).toHaveBeenCalled();
196
- // Verify that new client was created and initialized
197
- expect(GeminiClient).toHaveBeenCalledWith(config);
198
- expect(mockNewClient.initialize).toHaveBeenCalledWith(mockContentConfig);
199
- // Verify that history was restored to the new client
200
- expect(mockNewClient.setHistory).toHaveBeenCalledWith(mockExistingHistory, { stripThoughts: false });
201
- });
202
- it('should handle case when no existing client is initialized', async () => {
203
- const config = new Config(baseParams);
204
- const authType = AuthType.USE_GEMINI;
205
- const mockContentConfig = {
206
- model: 'gemini-pro',
207
- apiKey: 'test-key',
208
- };
209
- createContentGeneratorConfig.mockReturnValue(mockContentConfig);
210
- const mockNewClient = {
211
- isInitialized: vi.fn().mockReturnValue(true),
212
- getHistory: vi.fn().mockReturnValue([]),
213
- setHistory: vi.fn(),
214
- initialize: vi.fn().mockResolvedValue(undefined),
215
- };
216
- // No existing client
217
- config.geminiClient = null;
218
- GeminiClient.mockImplementation(() => mockNewClient);
219
- await config.refreshAuth(authType);
220
- // Verify that new client was created and initialized
221
- expect(GeminiClient).toHaveBeenCalledWith(config);
222
- expect(mockNewClient.initialize).toHaveBeenCalledWith(mockContentConfig);
223
- // Verify that setHistory was not called since there was no existing history
224
- expect(mockNewClient.setHistory).not.toHaveBeenCalled();
225
- });
226
193
  it('should strip thoughts when switching from GenAI to Vertex', async () => {
227
194
  const config = new Config(baseParams);
228
- const mockContentConfig = {
229
- model: 'gemini-pro',
230
- apiKey: 'test-key',
231
- authType: AuthType.USE_GEMINI,
232
- };
233
- config.contentGeneratorConfig = mockContentConfig;
234
- createContentGeneratorConfig.mockReturnValue({
235
- ...mockContentConfig,
236
- authType: AuthType.LOGIN_WITH_GOOGLE,
237
- });
238
- const mockExistingHistory = [
239
- { role: 'user', parts: [{ text: 'Hello' }] },
240
- ];
241
- const mockExistingClient = {
242
- isInitialized: vi.fn().mockReturnValue(true),
243
- getHistory: vi.fn().mockReturnValue(mockExistingHistory),
244
- };
245
- const mockNewClient = {
246
- isInitialized: vi.fn().mockReturnValue(true),
247
- getHistory: vi.fn().mockReturnValue([]),
248
- setHistory: vi.fn(),
249
- initialize: vi.fn().mockResolvedValue(undefined),
250
- };
251
- config.geminiClient = mockExistingClient;
252
- GeminiClient.mockImplementation(() => mockNewClient);
195
+ vi.mocked(createContentGeneratorConfig).mockImplementation((_, authType) => ({ authType }));
196
+ await config.refreshAuth(AuthType.USE_GEMINI);
253
197
  await config.refreshAuth(AuthType.LOGIN_WITH_GOOGLE);
254
- expect(mockNewClient.setHistory).toHaveBeenCalledWith(mockExistingHistory, { stripThoughts: true });
198
+ expect(config.getGeminiClient().stripThoughtsFromHistory).toHaveBeenCalledWith();
255
199
  });
256
200
  it('should not strip thoughts when switching from Vertex to GenAI', async () => {
257
201
  const config = new Config(baseParams);
258
- const mockContentConfig = {
259
- model: 'gemini-pro',
260
- apiKey: 'test-key',
261
- authType: AuthType.LOGIN_WITH_GOOGLE,
262
- };
263
- config.contentGeneratorConfig = mockContentConfig;
264
- createContentGeneratorConfig.mockReturnValue({
265
- ...mockContentConfig,
266
- authType: AuthType.USE_GEMINI,
267
- });
268
- const mockExistingHistory = [
269
- { role: 'user', parts: [{ text: 'Hello' }] },
270
- ];
271
- const mockExistingClient = {
272
- isInitialized: vi.fn().mockReturnValue(true),
273
- getHistory: vi.fn().mockReturnValue(mockExistingHistory),
274
- };
275
- const mockNewClient = {
276
- isInitialized: vi.fn().mockReturnValue(true),
277
- getHistory: vi.fn().mockReturnValue([]),
278
- setHistory: vi.fn(),
279
- initialize: vi.fn().mockResolvedValue(undefined),
280
- };
281
- config.geminiClient = mockExistingClient;
282
- GeminiClient.mockImplementation(() => mockNewClient);
202
+ vi.mocked(createContentGeneratorConfig).mockImplementation((_, authType) => ({ authType }));
203
+ await config.refreshAuth(AuthType.USE_VERTEX_AI);
283
204
  await config.refreshAuth(AuthType.USE_GEMINI);
284
- expect(mockNewClient.setHistory).toHaveBeenCalledWith(mockExistingHistory, { stripThoughts: false });
205
+ expect(config.getGeminiClient().stripThoughtsFromHistory).not.toHaveBeenCalledWith();
285
206
  });
286
207
  });
287
208
  it('Config constructor should store userMemory correctly', () => {
@@ -360,6 +281,30 @@ describe('Server Config (config.ts)', () => {
360
281
  const config = new Config(paramsWithoutTelemetry);
361
282
  expect(config.getTelemetryEnabled()).toBe(TELEMETRY_SETTINGS.enabled);
362
283
  });
284
+ it('Config constructor should set telemetry useCollector to true when provided', () => {
285
+ const paramsWithTelemetry = {
286
+ ...baseParams,
287
+ telemetry: { enabled: true, useCollector: true },
288
+ };
289
+ const config = new Config(paramsWithTelemetry);
290
+ expect(config.getTelemetryUseCollector()).toBe(true);
291
+ });
292
+ it('Config constructor should set telemetry useCollector to false when provided', () => {
293
+ const paramsWithTelemetry = {
294
+ ...baseParams,
295
+ telemetry: { enabled: true, useCollector: false },
296
+ };
297
+ const config = new Config(paramsWithTelemetry);
298
+ expect(config.getTelemetryUseCollector()).toBe(false);
299
+ });
300
+ it('Config constructor should default telemetry useCollector to false if not provided', () => {
301
+ const paramsWithTelemetry = {
302
+ ...baseParams,
303
+ telemetry: { enabled: true },
304
+ };
305
+ const config = new Config(paramsWithTelemetry);
306
+ expect(config.getTelemetryUseCollector()).toBe(false);
307
+ });
363
308
  it('should have a getFileService method that returns FileDiscoveryService', () => {
364
309
  const config = new Config(baseParams);
365
310
  const fileService = config.getFileService();
@@ -385,7 +330,7 @@ describe('Server Config (config.ts)', () => {
385
330
  ...baseParams,
386
331
  usageStatisticsEnabled: true,
387
332
  });
388
- await config.initialize();
333
+ await config.refreshAuth(AuthType.USE_GEMINI);
389
334
  expect(ClearcutLogger.prototype.logStartSessionEvent).toHaveBeenCalledOnce();
390
335
  });
391
336
  });
@@ -473,33 +418,55 @@ describe('Server Config (config.ts)', () => {
473
418
  });
474
419
  });
475
420
  describe('UseRipgrep Configuration', () => {
476
- it('should default useRipgrep to false when not provided', () => {
421
+ it('should default useRipgrep to true when not provided', () => {
477
422
  const config = new Config(baseParams);
478
- expect(config.getUseRipgrep()).toBe(false);
423
+ expect(config.getUseRipgrep()).toBe(true);
479
424
  });
480
- it('should set useRipgrep to true when provided as true', () => {
425
+ it('should set useRipgrep to false when provided as false', () => {
481
426
  const paramsWithRipgrep = {
482
427
  ...baseParams,
483
- useRipgrep: true,
428
+ useRipgrep: false,
484
429
  };
485
430
  const config = new Config(paramsWithRipgrep);
486
- expect(config.getUseRipgrep()).toBe(true);
431
+ expect(config.getUseRipgrep()).toBe(false);
487
432
  });
488
- it('should set useRipgrep to false when explicitly provided as false', () => {
433
+ it('should set useRipgrep to true when explicitly provided as true', () => {
489
434
  const paramsWithRipgrep = {
490
435
  ...baseParams,
491
- useRipgrep: false,
436
+ useRipgrep: true,
492
437
  };
493
438
  const config = new Config(paramsWithRipgrep);
494
- expect(config.getUseRipgrep()).toBe(false);
439
+ expect(config.getUseRipgrep()).toBe(true);
495
440
  });
496
- it('should default useRipgrep to false when undefined', () => {
441
+ it('should default useRipgrep to true when undefined', () => {
497
442
  const paramsWithUndefinedRipgrep = {
498
443
  ...baseParams,
499
444
  useRipgrep: undefined,
500
445
  };
501
446
  const config = new Config(paramsWithUndefinedRipgrep);
502
- expect(config.getUseRipgrep()).toBe(false);
447
+ expect(config.getUseRipgrep()).toBe(true);
448
+ });
449
+ });
450
+ describe('UseModelRouter Configuration', () => {
451
+ it('should default useModelRouter to false when not provided', () => {
452
+ const config = new Config(baseParams);
453
+ expect(config.getUseModelRouter()).toBe(false);
454
+ });
455
+ it('should set useModelRouter to true when provided as true', () => {
456
+ const paramsWithModelRouter = {
457
+ ...baseParams,
458
+ useModelRouter: true,
459
+ };
460
+ const config = new Config(paramsWithModelRouter);
461
+ expect(config.getUseModelRouter()).toBe(true);
462
+ });
463
+ it('should set useModelRouter to false when explicitly provided as false', () => {
464
+ const paramsWithModelRouter = {
465
+ ...baseParams,
466
+ useModelRouter: false,
467
+ };
468
+ const config = new Config(paramsWithModelRouter);
469
+ expect(config.getUseModelRouter()).toBe(false);
503
470
  });
504
471
  });
505
472
  describe('createToolRegistry', () => {
@@ -519,67 +486,227 @@ describe('Server Config (config.ts)', () => {
519
486
  const wasReadFileToolRegistered = registerToolMock.mock.calls.some((call) => call[0] instanceof vi.mocked(ReadFileTool));
520
487
  expect(wasReadFileToolRegistered).toBe(false);
521
488
  });
489
+ describe('with minified tool class names', () => {
490
+ beforeEach(() => {
491
+ Object.defineProperty(vi.mocked(ShellTool).prototype.constructor, 'name', {
492
+ value: '_ShellTool',
493
+ configurable: true,
494
+ });
495
+ });
496
+ afterEach(() => {
497
+ Object.defineProperty(vi.mocked(ShellTool).prototype.constructor, 'name', {
498
+ value: 'ShellTool',
499
+ });
500
+ });
501
+ it('should register a tool if coreTools contains the non-minified class name', async () => {
502
+ const params = {
503
+ ...baseParams,
504
+ coreTools: ['ShellTool'],
505
+ };
506
+ const config = new Config(params);
507
+ await config.initialize();
508
+ const registerToolMock = (await vi.importMock('../tools/tool-registry')).ToolRegistry.prototype.registerTool;
509
+ const wasShellToolRegistered = registerToolMock.mock.calls.some((call) => call[0] instanceof vi.mocked(ShellTool));
510
+ expect(wasShellToolRegistered).toBe(true);
511
+ });
512
+ it('should not register a tool if excludeTools contains the non-minified class name', async () => {
513
+ const params = {
514
+ ...baseParams,
515
+ coreTools: undefined, // all tools enabled by default
516
+ excludeTools: ['ShellTool'],
517
+ };
518
+ const config = new Config(params);
519
+ await config.initialize();
520
+ const registerToolMock = (await vi.importMock('../tools/tool-registry')).ToolRegistry.prototype.registerTool;
521
+ const wasShellToolRegistered = registerToolMock.mock.calls.some((call) => call[0] instanceof vi.mocked(ShellTool));
522
+ expect(wasShellToolRegistered).toBe(false);
523
+ });
524
+ it('should register a tool if coreTools contains an argument-specific pattern with the non-minified class name', async () => {
525
+ const params = {
526
+ ...baseParams,
527
+ coreTools: ['ShellTool(git status)'],
528
+ };
529
+ const config = new Config(params);
530
+ await config.initialize();
531
+ const registerToolMock = (await vi.importMock('../tools/tool-registry')).ToolRegistry.prototype.registerTool;
532
+ const wasShellToolRegistered = registerToolMock.mock.calls.some((call) => call[0] instanceof vi.mocked(ShellTool));
533
+ expect(wasShellToolRegistered).toBe(true);
534
+ });
535
+ });
536
+ });
537
+ describe('getTruncateToolOutputThreshold', () => {
538
+ beforeEach(() => {
539
+ vi.clearAllMocks();
540
+ });
541
+ it('should return the calculated threshold when it is smaller than the default', () => {
542
+ const config = new Config(baseParams);
543
+ vi.mocked(tokenLimit).mockReturnValue(32000);
544
+ vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(1000);
545
+ // 4 * (32000 - 1000) = 4 * 31000 = 124000
546
+ // default is 4_000_000
547
+ expect(config.getTruncateToolOutputThreshold()).toBe(124000);
548
+ });
549
+ it('should return the default threshold when the calculated value is larger', () => {
550
+ const config = new Config(baseParams);
551
+ vi.mocked(tokenLimit).mockReturnValue(2_000_000);
552
+ vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(500_000);
553
+ // 4 * (2_000_000 - 500_000) = 4 * 1_500_000 = 6_000_000
554
+ // default is 4_000_000
555
+ expect(config.getTruncateToolOutputThreshold()).toBe(4_000_000);
556
+ });
557
+ it('should use a custom truncateToolOutputThreshold if provided', () => {
558
+ const customParams = {
559
+ ...baseParams,
560
+ truncateToolOutputThreshold: 50000,
561
+ };
562
+ const config = new Config(customParams);
563
+ vi.mocked(tokenLimit).mockReturnValue(8000);
564
+ vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(2000);
565
+ // 4 * (8000 - 2000) = 4 * 6000 = 24000
566
+ // custom threshold is 50000
567
+ expect(config.getTruncateToolOutputThreshold()).toBe(24000);
568
+ vi.mocked(tokenLimit).mockReturnValue(32000);
569
+ vi.mocked(uiTelemetryService.getLastPromptTokenCount).mockReturnValue(1000);
570
+ // 4 * (32000 - 1000) = 124000
571
+ // custom threshold is 50000
572
+ expect(config.getTruncateToolOutputThreshold()).toBe(50000);
573
+ });
522
574
  });
523
575
  });
524
576
  describe('setApprovalMode with folder trust', () => {
577
+ const baseParams = {
578
+ sessionId: 'test',
579
+ targetDir: '.',
580
+ debugMode: false,
581
+ model: 'test-model',
582
+ cwd: '.',
583
+ };
525
584
  it('should throw an error when setting YOLO mode in an untrusted folder', () => {
526
- const config = new Config({
527
- sessionId: 'test',
528
- targetDir: '.',
529
- debugMode: false,
530
- model: 'test-model',
531
- cwd: '.',
532
- trustedFolder: false, // Untrusted
533
- });
585
+ const config = new Config(baseParams);
586
+ vi.spyOn(config, 'isTrustedFolder').mockReturnValue(false);
534
587
  expect(() => config.setApprovalMode(ApprovalMode.YOLO)).toThrow('Cannot enable privileged approval modes in an untrusted folder.');
535
588
  });
536
589
  it('should throw an error when setting AUTO_EDIT mode in an untrusted folder', () => {
537
- const config = new Config({
538
- sessionId: 'test',
539
- targetDir: '.',
540
- debugMode: false,
541
- model: 'test-model',
542
- cwd: '.',
543
- trustedFolder: false, // Untrusted
544
- });
590
+ const config = new Config(baseParams);
591
+ vi.spyOn(config, 'isTrustedFolder').mockReturnValue(false);
545
592
  expect(() => config.setApprovalMode(ApprovalMode.AUTO_EDIT)).toThrow('Cannot enable privileged approval modes in an untrusted folder.');
546
593
  });
547
594
  it('should NOT throw an error when setting DEFAULT mode in an untrusted folder', () => {
548
- const config = new Config({
549
- sessionId: 'test',
550
- targetDir: '.',
551
- debugMode: false,
552
- model: 'test-model',
553
- cwd: '.',
554
- trustedFolder: false, // Untrusted
555
- });
595
+ const config = new Config(baseParams);
596
+ vi.spyOn(config, 'isTrustedFolder').mockReturnValue(false);
556
597
  expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
557
598
  });
558
599
  it('should NOT throw an error when setting any mode in a trusted folder', () => {
559
- const config = new Config({
560
- sessionId: 'test',
561
- targetDir: '.',
562
- debugMode: false,
563
- model: 'test-model',
564
- cwd: '.',
565
- trustedFolder: true, // Trusted
566
- });
600
+ const config = new Config(baseParams);
601
+ vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
567
602
  expect(() => config.setApprovalMode(ApprovalMode.YOLO)).not.toThrow();
568
603
  expect(() => config.setApprovalMode(ApprovalMode.AUTO_EDIT)).not.toThrow();
569
604
  expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
570
605
  });
571
606
  it('should NOT throw an error when setting any mode if trustedFolder is undefined', () => {
572
- const config = new Config({
573
- sessionId: 'test',
574
- targetDir: '.',
575
- debugMode: false,
576
- model: 'test-model',
577
- cwd: '.',
578
- trustedFolder: undefined, // Undefined
579
- });
607
+ const config = new Config(baseParams);
608
+ vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true); // isTrustedFolder defaults to true
580
609
  expect(() => config.setApprovalMode(ApprovalMode.YOLO)).not.toThrow();
581
610
  expect(() => config.setApprovalMode(ApprovalMode.AUTO_EDIT)).not.toThrow();
582
611
  expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
583
612
  });
613
+ describe('registerCoreTools', () => {
614
+ beforeEach(() => {
615
+ vi.clearAllMocks();
616
+ });
617
+ it('should register RipGrepTool when useRipgrep is true and it is available', async () => {
618
+ canUseRipgrep.mockResolvedValue(true);
619
+ const config = new Config({ ...baseParams, useRipgrep: true });
620
+ await config.initialize();
621
+ const calls = ToolRegistry.prototype.registerTool.mock.calls;
622
+ const wasRipGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(RipGrepTool));
623
+ const wasGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(GrepTool));
624
+ expect(wasRipGrepRegistered).toBe(true);
625
+ expect(wasGrepRegistered).toBe(false);
626
+ expect(logRipgrepFallback).not.toHaveBeenCalled();
627
+ });
628
+ it('should register GrepTool as a fallback when useRipgrep is true but it is not available', async () => {
629
+ canUseRipgrep.mockResolvedValue(false);
630
+ const config = new Config({ ...baseParams, useRipgrep: true });
631
+ await config.initialize();
632
+ const calls = ToolRegistry.prototype.registerTool.mock.calls;
633
+ const wasRipGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(RipGrepTool));
634
+ const wasGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(GrepTool));
635
+ expect(wasRipGrepRegistered).toBe(false);
636
+ expect(wasGrepRegistered).toBe(true);
637
+ expect(logRipgrepFallback).toHaveBeenCalledWith(config, expect.any(RipgrepFallbackEvent));
638
+ const event = logRipgrepFallback.mock.calls[0][1];
639
+ expect(event.error).toBeUndefined();
640
+ });
641
+ it('should register GrepTool as a fallback when canUseRipgrep throws an error', async () => {
642
+ const error = new Error('ripGrep check failed');
643
+ canUseRipgrep.mockRejectedValue(error);
644
+ const config = new Config({ ...baseParams, useRipgrep: true });
645
+ await config.initialize();
646
+ const calls = ToolRegistry.prototype.registerTool.mock.calls;
647
+ const wasRipGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(RipGrepTool));
648
+ const wasGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(GrepTool));
649
+ expect(wasRipGrepRegistered).toBe(false);
650
+ expect(wasGrepRegistered).toBe(true);
651
+ expect(logRipgrepFallback).toHaveBeenCalledWith(config, expect.any(RipgrepFallbackEvent));
652
+ const event = logRipgrepFallback.mock.calls[0][1];
653
+ expect(event.error).toBe(String(error));
654
+ });
655
+ it('should register GrepTool when useRipgrep is false', async () => {
656
+ const config = new Config({ ...baseParams, useRipgrep: false });
657
+ await config.initialize();
658
+ const calls = ToolRegistry.prototype.registerTool.mock.calls;
659
+ const wasRipGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(RipGrepTool));
660
+ const wasGrepRegistered = calls.some((call) => call[0] instanceof vi.mocked(GrepTool));
661
+ expect(wasRipGrepRegistered).toBe(false);
662
+ expect(wasGrepRegistered).toBe(true);
663
+ expect(canUseRipgrep).not.toHaveBeenCalled();
664
+ expect(logRipgrepFallback).not.toHaveBeenCalled();
665
+ });
666
+ });
667
+ });
668
+ describe('BaseLlmClient Lifecycle', () => {
669
+ const MODEL = 'gemini-pro';
670
+ const SANDBOX = {
671
+ command: 'docker',
672
+ image: 'gemini-cli-sandbox',
673
+ };
674
+ const TARGET_DIR = '/path/to/target';
675
+ const DEBUG_MODE = false;
676
+ const QUESTION = 'test question';
677
+ const FULL_CONTEXT = false;
678
+ const USER_MEMORY = 'Test User Memory';
679
+ const TELEMETRY_SETTINGS = { enabled: false };
680
+ const EMBEDDING_MODEL = 'gemini-embedding';
681
+ const SESSION_ID = 'test-session-id';
682
+ const baseParams = {
683
+ cwd: '/tmp',
684
+ embeddingModel: EMBEDDING_MODEL,
685
+ sandbox: SANDBOX,
686
+ targetDir: TARGET_DIR,
687
+ debugMode: DEBUG_MODE,
688
+ question: QUESTION,
689
+ fullContext: FULL_CONTEXT,
690
+ userMemory: USER_MEMORY,
691
+ telemetry: TELEMETRY_SETTINGS,
692
+ sessionId: SESSION_ID,
693
+ model: MODEL,
694
+ usageStatisticsEnabled: false,
695
+ };
696
+ it('should throw an error if getBaseLlmClient is called before refreshAuth', () => {
697
+ const config = new Config(baseParams);
698
+ expect(() => config.getBaseLlmClient()).toThrow('BaseLlmClient not initialized. Ensure authentication has occurred and ContentGenerator is ready.');
699
+ });
700
+ it('should successfully initialize BaseLlmClient after refreshAuth is called', async () => {
701
+ const config = new Config(baseParams);
702
+ const authType = AuthType.USE_GEMINI;
703
+ const mockContentConfig = { model: 'gemini-flash', apiKey: 'test-key' };
704
+ vi.mocked(createContentGeneratorConfig).mockReturnValue(mockContentConfig);
705
+ await config.refreshAuth(authType);
706
+ // Should not throw
707
+ const llmService = config.getBaseLlmClient();
708
+ expect(llmService).toBeDefined();
709
+ expect(BaseLlmClient).toHaveBeenCalledWith(config.getContentGenerator(), config);
710
+ });
584
711
  });
585
712
  //# sourceMappingURL=config.test.js.map