@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,923 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { describe, it, expect, vi } from 'vitest';
7
+ import { CoreToolScheduler, convertToFunctionResponse, } from './coreToolScheduler.js';
8
+ import { BaseDeclarativeTool, BaseToolInvocation, ToolConfirmationOutcome, Kind, ApprovalMode, } from '../index.js';
9
+ import { MockModifiableTool, MockTool } from '../test-utils/tools.js';
10
+ class TestApprovalTool extends BaseDeclarativeTool {
11
+ config;
12
+ static Name = 'testApprovalTool';
13
+ constructor(config) {
14
+ super(TestApprovalTool.Name, 'TestApprovalTool', 'A tool for testing approval logic', Kind.Edit, {
15
+ properties: { id: { type: 'string' } },
16
+ required: ['id'],
17
+ type: 'object',
18
+ });
19
+ this.config = config;
20
+ }
21
+ createInvocation(params) {
22
+ return new TestApprovalInvocation(this.config, params);
23
+ }
24
+ }
25
+ class TestApprovalInvocation extends BaseToolInvocation {
26
+ config;
27
+ constructor(config, params) {
28
+ super(params);
29
+ this.config = config;
30
+ }
31
+ getDescription() {
32
+ return `Test tool ${this.params.id}`;
33
+ }
34
+ async shouldConfirmExecute() {
35
+ // Need confirmation unless approval mode is AUTO_EDIT
36
+ if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
37
+ return false;
38
+ }
39
+ return {
40
+ type: 'edit',
41
+ title: `Confirm Test Tool ${this.params.id}`,
42
+ fileName: `test-${this.params.id}.txt`,
43
+ filePath: `/test-${this.params.id}.txt`,
44
+ fileDiff: 'Test diff content',
45
+ originalContent: '',
46
+ newContent: 'Test content',
47
+ onConfirm: async (outcome) => {
48
+ if (outcome === ToolConfirmationOutcome.ProceedAlways) {
49
+ this.config.setApprovalMode(ApprovalMode.AUTO_EDIT);
50
+ }
51
+ },
52
+ };
53
+ }
54
+ async execute() {
55
+ return {
56
+ llmContent: `Executed test tool ${this.params.id}`,
57
+ returnDisplay: `Executed test tool ${this.params.id}`,
58
+ };
59
+ }
60
+ }
61
+ async function waitForStatus(onToolCallsUpdate, status, timeout = 5000) {
62
+ return new Promise((resolve, reject) => {
63
+ const startTime = Date.now();
64
+ const check = () => {
65
+ if (Date.now() - startTime > timeout) {
66
+ const seenStatuses = onToolCallsUpdate.mock.calls
67
+ .flatMap((call) => call[0])
68
+ .map((toolCall) => toolCall.status);
69
+ reject(new Error(`Timed out waiting for status "${status}". Seen statuses: ${seenStatuses.join(', ')}`));
70
+ return;
71
+ }
72
+ const foundCall = onToolCallsUpdate.mock.calls
73
+ .flatMap((call) => call[0])
74
+ .find((toolCall) => toolCall.status === status);
75
+ if (foundCall) {
76
+ resolve(foundCall);
77
+ }
78
+ else {
79
+ setTimeout(check, 10); // Check again in 10ms
80
+ }
81
+ };
82
+ check();
83
+ });
84
+ }
85
+ describe('CoreToolScheduler', () => {
86
+ it('should cancel a tool call if the signal is aborted before confirmation', async () => {
87
+ const mockTool = new MockTool();
88
+ mockTool.shouldConfirm = true;
89
+ const declarativeTool = mockTool;
90
+ const mockToolRegistry = {
91
+ getTool: () => declarativeTool,
92
+ getFunctionDeclarations: () => [],
93
+ tools: new Map(),
94
+ discovery: {},
95
+ registerTool: () => { },
96
+ getToolByName: () => declarativeTool,
97
+ getToolByDisplayName: () => declarativeTool,
98
+ getTools: () => [],
99
+ discoverTools: async () => { },
100
+ getAllTools: () => [],
101
+ getToolsByServer: () => [],
102
+ };
103
+ const onAllToolCallsComplete = vi.fn();
104
+ const onToolCallsUpdate = vi.fn();
105
+ const mockConfig = {
106
+ getSessionId: () => 'test-session-id',
107
+ getUsageStatisticsEnabled: () => true,
108
+ getDebugMode: () => false,
109
+ getApprovalMode: () => ApprovalMode.DEFAULT,
110
+ getAllowedTools: () => [],
111
+ getContentGeneratorConfig: () => ({
112
+ model: 'test-model',
113
+ authType: 'oauth-personal',
114
+ }),
115
+ getToolRegistry: () => mockToolRegistry,
116
+ };
117
+ const scheduler = new CoreToolScheduler({
118
+ config: mockConfig,
119
+ onAllToolCallsComplete,
120
+ onToolCallsUpdate,
121
+ getPreferredEditor: () => 'vscode',
122
+ onEditorClose: vi.fn(),
123
+ });
124
+ const abortController = new AbortController();
125
+ const request = {
126
+ callId: '1',
127
+ name: 'mockTool',
128
+ args: {},
129
+ isClientInitiated: false,
130
+ prompt_id: 'prompt-id-1',
131
+ };
132
+ abortController.abort();
133
+ await scheduler.schedule([request], abortController.signal);
134
+ expect(onAllToolCallsComplete).toHaveBeenCalled();
135
+ const completedCalls = onAllToolCallsComplete.mock
136
+ .calls[0][0];
137
+ expect(completedCalls[0].status).toBe('cancelled');
138
+ });
139
+ describe('getToolSuggestion', () => {
140
+ it('should suggest the top N closest tool names for a typo', () => {
141
+ // Create mocked tool registry
142
+ const mockConfig = {
143
+ getToolRegistry: () => mockToolRegistry,
144
+ };
145
+ const mockToolRegistry = {
146
+ getAllToolNames: () => ['list_files', 'read_file', 'write_file'],
147
+ };
148
+ // Create scheduler
149
+ const scheduler = new CoreToolScheduler({
150
+ config: mockConfig,
151
+ getPreferredEditor: () => 'vscode',
152
+ onEditorClose: vi.fn(),
153
+ });
154
+ // Test that the right tool is selected, with only 1 result, for typos
155
+ // @ts-expect-error accessing private method
156
+ const misspelledTool = scheduler.getToolSuggestion('list_fils', 1);
157
+ expect(misspelledTool).toBe(' Did you mean "list_files"?');
158
+ // Test that the right tool is selected, with only 1 result, for prefixes
159
+ // @ts-expect-error accessing private method
160
+ const prefixedTool = scheduler.getToolSuggestion('github.list_files', 1);
161
+ expect(prefixedTool).toBe(' Did you mean "list_files"?');
162
+ // Test that the right tool is first
163
+ // @ts-expect-error accessing private method
164
+ const suggestionMultiple = scheduler.getToolSuggestion('list_fils');
165
+ expect(suggestionMultiple).toBe(' Did you mean one of: "list_files", "read_file", "write_file"?');
166
+ });
167
+ });
168
+ });
169
+ describe('CoreToolScheduler with payload', () => {
170
+ it('should update args and diff and execute tool when payload is provided', async () => {
171
+ const mockTool = new MockModifiableTool();
172
+ const declarativeTool = mockTool;
173
+ const mockToolRegistry = {
174
+ getTool: () => declarativeTool,
175
+ getFunctionDeclarations: () => [],
176
+ tools: new Map(),
177
+ discovery: {},
178
+ registerTool: () => { },
179
+ getToolByName: () => declarativeTool,
180
+ getToolByDisplayName: () => declarativeTool,
181
+ getTools: () => [],
182
+ discoverTools: async () => { },
183
+ getAllTools: () => [],
184
+ getToolsByServer: () => [],
185
+ };
186
+ const onAllToolCallsComplete = vi.fn();
187
+ const onToolCallsUpdate = vi.fn();
188
+ const mockConfig = {
189
+ getSessionId: () => 'test-session-id',
190
+ getUsageStatisticsEnabled: () => true,
191
+ getDebugMode: () => false,
192
+ getApprovalMode: () => ApprovalMode.DEFAULT,
193
+ getAllowedTools: () => [],
194
+ getContentGeneratorConfig: () => ({
195
+ model: 'test-model',
196
+ authType: 'oauth-personal',
197
+ }),
198
+ getToolRegistry: () => mockToolRegistry,
199
+ };
200
+ const scheduler = new CoreToolScheduler({
201
+ config: mockConfig,
202
+ onAllToolCallsComplete,
203
+ onToolCallsUpdate,
204
+ getPreferredEditor: () => 'vscode',
205
+ onEditorClose: vi.fn(),
206
+ });
207
+ const abortController = new AbortController();
208
+ const request = {
209
+ callId: '1',
210
+ name: 'mockModifiableTool',
211
+ args: {},
212
+ isClientInitiated: false,
213
+ prompt_id: 'prompt-id-2',
214
+ };
215
+ await scheduler.schedule([request], abortController.signal);
216
+ const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
217
+ const confirmationDetails = awaitingCall.confirmationDetails;
218
+ if (confirmationDetails) {
219
+ const payload = { newContent: 'final version' };
220
+ await confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce, payload);
221
+ }
222
+ expect(onAllToolCallsComplete).toHaveBeenCalled();
223
+ const completedCalls = onAllToolCallsComplete.mock
224
+ .calls[0][0];
225
+ expect(completedCalls[0].status).toBe('success');
226
+ expect(mockTool.executeFn).toHaveBeenCalledWith({
227
+ newContent: 'final version',
228
+ });
229
+ });
230
+ });
231
+ describe('convertToFunctionResponse', () => {
232
+ const toolName = 'testTool';
233
+ const callId = 'call1';
234
+ it('should handle simple string llmContent', () => {
235
+ const llmContent = 'Simple text output';
236
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
237
+ expect(result).toEqual([
238
+ {
239
+ functionResponse: {
240
+ name: toolName,
241
+ id: callId,
242
+ response: { output: 'Simple text output' },
243
+ },
244
+ },
245
+ ]);
246
+ });
247
+ it('should handle llmContent as a single Part with text', () => {
248
+ const llmContent = { text: 'Text from Part object' };
249
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
250
+ expect(result).toEqual([
251
+ {
252
+ functionResponse: {
253
+ name: toolName,
254
+ id: callId,
255
+ response: { output: 'Text from Part object' },
256
+ },
257
+ },
258
+ ]);
259
+ });
260
+ it('should handle llmContent as a PartListUnion array with a single text Part', () => {
261
+ const llmContent = [{ text: 'Text from array' }];
262
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
263
+ expect(result).toEqual([
264
+ {
265
+ functionResponse: {
266
+ name: toolName,
267
+ id: callId,
268
+ response: { output: 'Text from array' },
269
+ },
270
+ },
271
+ ]);
272
+ });
273
+ it('should handle llmContent with inlineData', () => {
274
+ const llmContent = {
275
+ inlineData: { mimeType: 'image/png', data: 'base64...' },
276
+ };
277
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
278
+ expect(result).toEqual([
279
+ {
280
+ functionResponse: {
281
+ name: toolName,
282
+ id: callId,
283
+ response: {
284
+ output: 'Binary content of type image/png was processed.',
285
+ },
286
+ },
287
+ },
288
+ llmContent,
289
+ ]);
290
+ });
291
+ it('should handle llmContent with fileData', () => {
292
+ const llmContent = {
293
+ fileData: { mimeType: 'application/pdf', fileUri: 'gs://...' },
294
+ };
295
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
296
+ expect(result).toEqual([
297
+ {
298
+ functionResponse: {
299
+ name: toolName,
300
+ id: callId,
301
+ response: {
302
+ output: 'Binary content of type application/pdf was processed.',
303
+ },
304
+ },
305
+ },
306
+ llmContent,
307
+ ]);
308
+ });
309
+ it('should handle llmContent as an array of multiple Parts (text and inlineData)', () => {
310
+ const llmContent = [
311
+ { text: 'Some textual description' },
312
+ { inlineData: { mimeType: 'image/jpeg', data: 'base64data...' } },
313
+ { text: 'Another text part' },
314
+ ];
315
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
316
+ expect(result).toEqual([
317
+ {
318
+ functionResponse: {
319
+ name: toolName,
320
+ id: callId,
321
+ response: { output: 'Tool execution succeeded.' },
322
+ },
323
+ },
324
+ ...llmContent,
325
+ ]);
326
+ });
327
+ it('should handle llmContent as an array with a single inlineData Part', () => {
328
+ const llmContent = [
329
+ { inlineData: { mimeType: 'image/gif', data: 'gifdata...' } },
330
+ ];
331
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
332
+ expect(result).toEqual([
333
+ {
334
+ functionResponse: {
335
+ name: toolName,
336
+ id: callId,
337
+ response: {
338
+ output: 'Binary content of type image/gif was processed.',
339
+ },
340
+ },
341
+ },
342
+ ...llmContent,
343
+ ]);
344
+ });
345
+ it('should handle llmContent as a generic Part (not text, inlineData, or fileData)', () => {
346
+ const llmContent = { functionCall: { name: 'test', args: {} } };
347
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
348
+ expect(result).toEqual([
349
+ {
350
+ functionResponse: {
351
+ name: toolName,
352
+ id: callId,
353
+ response: { output: 'Tool execution succeeded.' },
354
+ },
355
+ },
356
+ ]);
357
+ });
358
+ it('should handle empty string llmContent', () => {
359
+ const llmContent = '';
360
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
361
+ expect(result).toEqual([
362
+ {
363
+ functionResponse: {
364
+ name: toolName,
365
+ id: callId,
366
+ response: { output: '' },
367
+ },
368
+ },
369
+ ]);
370
+ });
371
+ it('should handle llmContent as an empty array', () => {
372
+ const llmContent = [];
373
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
374
+ expect(result).toEqual([
375
+ {
376
+ functionResponse: {
377
+ name: toolName,
378
+ id: callId,
379
+ response: { output: 'Tool execution succeeded.' },
380
+ },
381
+ },
382
+ ]);
383
+ });
384
+ it('should handle llmContent as a Part with undefined inlineData/fileData/text', () => {
385
+ const llmContent = {}; // An empty part object
386
+ const result = convertToFunctionResponse(toolName, callId, llmContent);
387
+ expect(result).toEqual([
388
+ {
389
+ functionResponse: {
390
+ name: toolName,
391
+ id: callId,
392
+ response: { output: 'Tool execution succeeded.' },
393
+ },
394
+ },
395
+ ]);
396
+ });
397
+ });
398
+ class MockEditToolInvocation extends BaseToolInvocation {
399
+ constructor(params) {
400
+ super(params);
401
+ }
402
+ getDescription() {
403
+ return 'A mock edit tool invocation';
404
+ }
405
+ async shouldConfirmExecute(_abortSignal) {
406
+ return {
407
+ type: 'edit',
408
+ title: 'Confirm Edit',
409
+ fileName: 'test.txt',
410
+ filePath: 'test.txt',
411
+ fileDiff: '--- test.txt\n+++ test.txt\n@@ -1,1 +1,1 @@\n-old content\n+new content',
412
+ originalContent: 'old content',
413
+ newContent: 'new content',
414
+ onConfirm: async () => { },
415
+ };
416
+ }
417
+ async execute(_abortSignal) {
418
+ return {
419
+ llmContent: 'Edited successfully',
420
+ returnDisplay: 'Edited successfully',
421
+ };
422
+ }
423
+ }
424
+ class MockEditTool extends BaseDeclarativeTool {
425
+ constructor() {
426
+ super('mockEditTool', 'mockEditTool', 'A mock edit tool', Kind.Edit, {});
427
+ }
428
+ createInvocation(params) {
429
+ return new MockEditToolInvocation(params);
430
+ }
431
+ }
432
+ describe('CoreToolScheduler edit cancellation', () => {
433
+ it('should preserve diff when an edit is cancelled', async () => {
434
+ const mockEditTool = new MockEditTool();
435
+ const mockToolRegistry = {
436
+ getTool: () => mockEditTool,
437
+ getFunctionDeclarations: () => [],
438
+ tools: new Map(),
439
+ discovery: {},
440
+ registerTool: () => { },
441
+ getToolByName: () => mockEditTool,
442
+ getToolByDisplayName: () => mockEditTool,
443
+ getTools: () => [],
444
+ discoverTools: async () => { },
445
+ getAllTools: () => [],
446
+ getToolsByServer: () => [],
447
+ };
448
+ const onAllToolCallsComplete = vi.fn();
449
+ const onToolCallsUpdate = vi.fn();
450
+ const mockConfig = {
451
+ getSessionId: () => 'test-session-id',
452
+ getUsageStatisticsEnabled: () => true,
453
+ getDebugMode: () => false,
454
+ getApprovalMode: () => ApprovalMode.DEFAULT,
455
+ getAllowedTools: () => [],
456
+ getContentGeneratorConfig: () => ({
457
+ model: 'test-model',
458
+ authType: 'oauth-personal',
459
+ }),
460
+ getToolRegistry: () => mockToolRegistry,
461
+ };
462
+ const scheduler = new CoreToolScheduler({
463
+ config: mockConfig,
464
+ onAllToolCallsComplete,
465
+ onToolCallsUpdate,
466
+ getPreferredEditor: () => 'vscode',
467
+ onEditorClose: vi.fn(),
468
+ });
469
+ const abortController = new AbortController();
470
+ const request = {
471
+ callId: '1',
472
+ name: 'mockEditTool',
473
+ args: {},
474
+ isClientInitiated: false,
475
+ prompt_id: 'prompt-id-1',
476
+ };
477
+ await scheduler.schedule([request], abortController.signal);
478
+ const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
479
+ // Cancel the edit
480
+ const confirmationDetails = awaitingCall.confirmationDetails;
481
+ if (confirmationDetails) {
482
+ await confirmationDetails.onConfirm(ToolConfirmationOutcome.Cancel);
483
+ }
484
+ expect(onAllToolCallsComplete).toHaveBeenCalled();
485
+ const completedCalls = onAllToolCallsComplete.mock
486
+ .calls[0][0];
487
+ expect(completedCalls[0].status).toBe('cancelled');
488
+ // Check that the diff is preserved
489
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
490
+ const cancelledCall = completedCalls[0];
491
+ expect(cancelledCall.response.resultDisplay).toBeDefined();
492
+ expect(cancelledCall.response.resultDisplay.fileDiff).toBe('--- test.txt\n+++ test.txt\n@@ -1,1 +1,1 @@\n-old content\n+new content');
493
+ expect(cancelledCall.response.resultDisplay.fileName).toBe('test.txt');
494
+ });
495
+ });
496
+ describe('CoreToolScheduler YOLO mode', () => {
497
+ it('should execute tool requiring confirmation directly without waiting', async () => {
498
+ // Arrange
499
+ const mockTool = new MockTool();
500
+ mockTool.executeFn.mockReturnValue({
501
+ llmContent: 'Tool executed',
502
+ returnDisplay: 'Tool executed',
503
+ });
504
+ // This tool would normally require confirmation.
505
+ mockTool.shouldConfirm = true;
506
+ const declarativeTool = mockTool;
507
+ const mockToolRegistry = {
508
+ getTool: () => declarativeTool,
509
+ getToolByName: () => declarativeTool,
510
+ // Other properties are not needed for this test but are included for type consistency.
511
+ getFunctionDeclarations: () => [],
512
+ tools: new Map(),
513
+ discovery: {},
514
+ registerTool: () => { },
515
+ getToolByDisplayName: () => declarativeTool,
516
+ getTools: () => [],
517
+ discoverTools: async () => { },
518
+ getAllTools: () => [],
519
+ getToolsByServer: () => [],
520
+ };
521
+ const onAllToolCallsComplete = vi.fn();
522
+ const onToolCallsUpdate = vi.fn();
523
+ // Configure the scheduler for YOLO mode.
524
+ const mockConfig = {
525
+ getSessionId: () => 'test-session-id',
526
+ getUsageStatisticsEnabled: () => true,
527
+ getDebugMode: () => false,
528
+ getApprovalMode: () => ApprovalMode.YOLO,
529
+ getAllowedTools: () => [],
530
+ getContentGeneratorConfig: () => ({
531
+ model: 'test-model',
532
+ authType: 'oauth-personal',
533
+ }),
534
+ getToolRegistry: () => mockToolRegistry,
535
+ };
536
+ const scheduler = new CoreToolScheduler({
537
+ config: mockConfig,
538
+ onAllToolCallsComplete,
539
+ onToolCallsUpdate,
540
+ getPreferredEditor: () => 'vscode',
541
+ onEditorClose: vi.fn(),
542
+ });
543
+ const abortController = new AbortController();
544
+ const request = {
545
+ callId: '1',
546
+ name: 'mockTool',
547
+ args: { param: 'value' },
548
+ isClientInitiated: false,
549
+ prompt_id: 'prompt-id-yolo',
550
+ };
551
+ // Act
552
+ await scheduler.schedule([request], abortController.signal);
553
+ // Assert
554
+ // 1. The tool's execute method was called directly.
555
+ expect(mockTool.executeFn).toHaveBeenCalledWith({ param: 'value' });
556
+ // 2. The tool call status never entered 'awaiting_approval'.
557
+ const statusUpdates = onToolCallsUpdate.mock.calls
558
+ .map((call) => call[0][0]?.status)
559
+ .filter(Boolean);
560
+ expect(statusUpdates).not.toContain('awaiting_approval');
561
+ expect(statusUpdates).toEqual([
562
+ 'validating',
563
+ 'scheduled',
564
+ 'executing',
565
+ 'success',
566
+ ]);
567
+ // 3. The final callback indicates the tool call was successful.
568
+ expect(onAllToolCallsComplete).toHaveBeenCalled();
569
+ const completedCalls = onAllToolCallsComplete.mock
570
+ .calls[0][0];
571
+ expect(completedCalls).toHaveLength(1);
572
+ const completedCall = completedCalls[0];
573
+ expect(completedCall.status).toBe('success');
574
+ if (completedCall.status === 'success') {
575
+ expect(completedCall.response.resultDisplay).toBe('Tool executed');
576
+ }
577
+ });
578
+ });
579
+ describe('CoreToolScheduler request queueing', () => {
580
+ it('should queue a request if another is running', async () => {
581
+ let resolveFirstCall;
582
+ const firstCallPromise = new Promise((resolve) => {
583
+ resolveFirstCall = resolve;
584
+ });
585
+ const mockTool = new MockTool();
586
+ mockTool.executeFn.mockImplementation(() => firstCallPromise);
587
+ const declarativeTool = mockTool;
588
+ const mockToolRegistry = {
589
+ getTool: () => declarativeTool,
590
+ getToolByName: () => declarativeTool,
591
+ getFunctionDeclarations: () => [],
592
+ tools: new Map(),
593
+ discovery: {},
594
+ registerTool: () => { },
595
+ getToolByDisplayName: () => declarativeTool,
596
+ getTools: () => [],
597
+ discoverTools: async () => { },
598
+ getAllTools: () => [],
599
+ getToolsByServer: () => [],
600
+ };
601
+ const onAllToolCallsComplete = vi.fn();
602
+ const onToolCallsUpdate = vi.fn();
603
+ const mockConfig = {
604
+ getSessionId: () => 'test-session-id',
605
+ getUsageStatisticsEnabled: () => true,
606
+ getDebugMode: () => false,
607
+ getApprovalMode: () => ApprovalMode.YOLO, // Use YOLO to avoid confirmation prompts
608
+ getAllowedTools: () => [],
609
+ getContentGeneratorConfig: () => ({
610
+ model: 'test-model',
611
+ authType: 'oauth-personal',
612
+ }),
613
+ getToolRegistry: () => mockToolRegistry,
614
+ };
615
+ const scheduler = new CoreToolScheduler({
616
+ config: mockConfig,
617
+ onAllToolCallsComplete,
618
+ onToolCallsUpdate,
619
+ getPreferredEditor: () => 'vscode',
620
+ onEditorClose: vi.fn(),
621
+ });
622
+ const abortController = new AbortController();
623
+ const request1 = {
624
+ callId: '1',
625
+ name: 'mockTool',
626
+ args: { a: 1 },
627
+ isClientInitiated: false,
628
+ prompt_id: 'prompt-1',
629
+ };
630
+ const request2 = {
631
+ callId: '2',
632
+ name: 'mockTool',
633
+ args: { b: 2 },
634
+ isClientInitiated: false,
635
+ prompt_id: 'prompt-2',
636
+ };
637
+ // Schedule the first call, which will pause execution.
638
+ scheduler.schedule([request1], abortController.signal);
639
+ // Wait for the first call to be in the 'executing' state.
640
+ await waitForStatus(onToolCallsUpdate, 'executing');
641
+ // Schedule the second call while the first is "running".
642
+ const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
643
+ // Ensure the second tool call hasn't been executed yet.
644
+ expect(mockTool.executeFn).toHaveBeenCalledTimes(1);
645
+ expect(mockTool.executeFn).toHaveBeenCalledWith({ a: 1 });
646
+ // Complete the first tool call.
647
+ resolveFirstCall({
648
+ llmContent: 'First call complete',
649
+ returnDisplay: 'First call complete',
650
+ });
651
+ // Wait for the second schedule promise to resolve.
652
+ await schedulePromise2;
653
+ // Let the second call finish.
654
+ const secondCallResult = {
655
+ llmContent: 'Second call complete',
656
+ returnDisplay: 'Second call complete',
657
+ };
658
+ // Since the mock is shared, we need to resolve the current promise.
659
+ // In a real scenario, a new promise would be created for the second call.
660
+ resolveFirstCall(secondCallResult);
661
+ await vi.waitFor(() => {
662
+ // Now the second tool call should have been executed.
663
+ expect(mockTool.executeFn).toHaveBeenCalledTimes(2);
664
+ });
665
+ expect(mockTool.executeFn).toHaveBeenCalledWith({ b: 2 });
666
+ // Wait for the second completion.
667
+ await vi.waitFor(() => {
668
+ expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
669
+ });
670
+ // Verify the completion callbacks were called correctly.
671
+ expect(onAllToolCallsComplete.mock.calls[0][0][0].status).toBe('success');
672
+ expect(onAllToolCallsComplete.mock.calls[1][0][0].status).toBe('success');
673
+ });
674
+ it('should auto-approve a tool call if it is on the allowedTools list', async () => {
675
+ // Arrange
676
+ const mockTool = new MockTool('mockTool');
677
+ mockTool.executeFn.mockReturnValue({
678
+ llmContent: 'Tool executed',
679
+ returnDisplay: 'Tool executed',
680
+ });
681
+ // This tool would normally require confirmation.
682
+ mockTool.shouldConfirm = true;
683
+ const declarativeTool = mockTool;
684
+ const toolRegistry = {
685
+ getTool: () => declarativeTool,
686
+ getToolByName: () => declarativeTool,
687
+ getFunctionDeclarations: () => [],
688
+ tools: new Map(),
689
+ discovery: {},
690
+ registerTool: () => { },
691
+ getToolByDisplayName: () => declarativeTool,
692
+ getTools: () => [],
693
+ discoverTools: async () => { },
694
+ getAllTools: () => [],
695
+ getToolsByServer: () => [],
696
+ };
697
+ const onAllToolCallsComplete = vi.fn();
698
+ const onToolCallsUpdate = vi.fn();
699
+ // Configure the scheduler to auto-approve the specific tool call.
700
+ const mockConfig = {
701
+ getSessionId: () => 'test-session-id',
702
+ getUsageStatisticsEnabled: () => true,
703
+ getDebugMode: () => false,
704
+ getApprovalMode: () => ApprovalMode.DEFAULT, // Not YOLO mode
705
+ getAllowedTools: () => ['mockTool'], // Auto-approve this tool
706
+ getToolRegistry: () => toolRegistry,
707
+ getContentGeneratorConfig: () => ({
708
+ model: 'test-model',
709
+ authType: 'oauth-personal',
710
+ }),
711
+ };
712
+ const scheduler = new CoreToolScheduler({
713
+ config: mockConfig,
714
+ onAllToolCallsComplete,
715
+ onToolCallsUpdate,
716
+ getPreferredEditor: () => 'vscode',
717
+ onEditorClose: vi.fn(),
718
+ });
719
+ const abortController = new AbortController();
720
+ const request = {
721
+ callId: '1',
722
+ name: 'mockTool',
723
+ args: { param: 'value' },
724
+ isClientInitiated: false,
725
+ prompt_id: 'prompt-auto-approved',
726
+ };
727
+ // Act
728
+ await scheduler.schedule([request], abortController.signal);
729
+ // Assert
730
+ // 1. The tool's execute method was called directly.
731
+ expect(mockTool.executeFn).toHaveBeenCalledWith({ param: 'value' });
732
+ // 2. The tool call status never entered 'awaiting_approval'.
733
+ const statusUpdates = onToolCallsUpdate.mock.calls
734
+ .map((call) => call[0][0]?.status)
735
+ .filter(Boolean);
736
+ expect(statusUpdates).not.toContain('awaiting_approval');
737
+ expect(statusUpdates).toEqual([
738
+ 'validating',
739
+ 'scheduled',
740
+ 'executing',
741
+ 'success',
742
+ ]);
743
+ // 3. The final callback indicates the tool call was successful.
744
+ expect(onAllToolCallsComplete).toHaveBeenCalled();
745
+ const completedCalls = onAllToolCallsComplete.mock
746
+ .calls[0][0];
747
+ expect(completedCalls).toHaveLength(1);
748
+ const completedCall = completedCalls[0];
749
+ expect(completedCall.status).toBe('success');
750
+ if (completedCall.status === 'success') {
751
+ expect(completedCall.response.resultDisplay).toBe('Tool executed');
752
+ }
753
+ });
754
+ it('should handle two synchronous calls to schedule', async () => {
755
+ const mockTool = new MockTool();
756
+ const declarativeTool = mockTool;
757
+ const mockToolRegistry = {
758
+ getTool: () => declarativeTool,
759
+ getToolByName: () => declarativeTool,
760
+ getFunctionDeclarations: () => [],
761
+ tools: new Map(),
762
+ discovery: {},
763
+ registerTool: () => { },
764
+ getToolByDisplayName: () => declarativeTool,
765
+ getTools: () => [],
766
+ discoverTools: async () => { },
767
+ getAllTools: () => [],
768
+ getToolsByServer: () => [],
769
+ };
770
+ const onAllToolCallsComplete = vi.fn();
771
+ const onToolCallsUpdate = vi.fn();
772
+ const mockConfig = {
773
+ getSessionId: () => 'test-session-id',
774
+ getUsageStatisticsEnabled: () => true,
775
+ getDebugMode: () => false,
776
+ getApprovalMode: () => ApprovalMode.YOLO,
777
+ getAllowedTools: () => [],
778
+ getContentGeneratorConfig: () => ({
779
+ model: 'test-model',
780
+ authType: 'oauth-personal',
781
+ }),
782
+ getToolRegistry: () => mockToolRegistry,
783
+ };
784
+ const scheduler = new CoreToolScheduler({
785
+ config: mockConfig,
786
+ onAllToolCallsComplete,
787
+ onToolCallsUpdate,
788
+ getPreferredEditor: () => 'vscode',
789
+ onEditorClose: vi.fn(),
790
+ });
791
+ const abortController = new AbortController();
792
+ const request1 = {
793
+ callId: '1',
794
+ name: 'mockTool',
795
+ args: { a: 1 },
796
+ isClientInitiated: false,
797
+ prompt_id: 'prompt-1',
798
+ };
799
+ const request2 = {
800
+ callId: '2',
801
+ name: 'mockTool',
802
+ args: { b: 2 },
803
+ isClientInitiated: false,
804
+ prompt_id: 'prompt-2',
805
+ };
806
+ // Schedule two calls synchronously.
807
+ const schedulePromise1 = scheduler.schedule([request1], abortController.signal);
808
+ const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
809
+ // Wait for both promises to resolve.
810
+ await Promise.all([schedulePromise1, schedulePromise2]);
811
+ // Ensure the tool was called twice with the correct arguments.
812
+ expect(mockTool.executeFn).toHaveBeenCalledTimes(2);
813
+ expect(mockTool.executeFn).toHaveBeenCalledWith({ a: 1 });
814
+ expect(mockTool.executeFn).toHaveBeenCalledWith({ b: 2 });
815
+ // Ensure completion callbacks were called twice.
816
+ expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
817
+ });
818
+ it('should auto-approve remaining tool calls when first tool call is approved with ProceedAlways', async () => {
819
+ let approvalMode = ApprovalMode.DEFAULT;
820
+ const mockConfig = {
821
+ getSessionId: () => 'test-session-id',
822
+ getUsageStatisticsEnabled: () => true,
823
+ getDebugMode: () => false,
824
+ getApprovalMode: () => approvalMode,
825
+ getAllowedTools: () => [],
826
+ setApprovalMode: (mode) => {
827
+ approvalMode = mode;
828
+ },
829
+ };
830
+ const testTool = new TestApprovalTool(mockConfig);
831
+ const toolRegistry = {
832
+ getTool: () => testTool,
833
+ getFunctionDeclarations: () => [],
834
+ getFunctionDeclarationsFiltered: () => [],
835
+ registerTool: () => { },
836
+ discoverAllTools: async () => { },
837
+ discoverMcpTools: async () => { },
838
+ discoverToolsForServer: async () => { },
839
+ removeMcpToolsByServer: () => { },
840
+ getAllTools: () => [],
841
+ getToolsByServer: () => [],
842
+ tools: new Map(),
843
+ config: mockConfig,
844
+ mcpClientManager: undefined,
845
+ getToolByName: () => testTool,
846
+ getToolByDisplayName: () => testTool,
847
+ getTools: () => [],
848
+ discoverTools: async () => { },
849
+ discovery: {},
850
+ };
851
+ mockConfig.getToolRegistry = () => toolRegistry;
852
+ const onAllToolCallsComplete = vi.fn();
853
+ const onToolCallsUpdate = vi.fn();
854
+ const pendingConfirmations = [];
855
+ const scheduler = new CoreToolScheduler({
856
+ config: mockConfig,
857
+ onAllToolCallsComplete,
858
+ onToolCallsUpdate: (toolCalls) => {
859
+ onToolCallsUpdate(toolCalls);
860
+ // Capture confirmation handlers for awaiting_approval tools
861
+ toolCalls.forEach((call) => {
862
+ if (call.status === 'awaiting_approval') {
863
+ const waitingCall = call;
864
+ if (waitingCall.confirmationDetails?.onConfirm) {
865
+ const originalHandler = pendingConfirmations.find((h) => h === waitingCall.confirmationDetails.onConfirm);
866
+ if (!originalHandler) {
867
+ pendingConfirmations.push(waitingCall.confirmationDetails.onConfirm);
868
+ }
869
+ }
870
+ }
871
+ });
872
+ },
873
+ getPreferredEditor: () => 'vscode',
874
+ onEditorClose: vi.fn(),
875
+ });
876
+ const abortController = new AbortController();
877
+ // Schedule multiple tools that need confirmation
878
+ const requests = [
879
+ {
880
+ callId: '1',
881
+ name: 'testApprovalTool',
882
+ args: { id: 'first' },
883
+ isClientInitiated: false,
884
+ prompt_id: 'prompt-1',
885
+ },
886
+ {
887
+ callId: '2',
888
+ name: 'testApprovalTool',
889
+ args: { id: 'second' },
890
+ isClientInitiated: false,
891
+ prompt_id: 'prompt-2',
892
+ },
893
+ {
894
+ callId: '3',
895
+ name: 'testApprovalTool',
896
+ args: { id: 'third' },
897
+ isClientInitiated: false,
898
+ prompt_id: 'prompt-3',
899
+ },
900
+ ];
901
+ await scheduler.schedule(requests, abortController.signal);
902
+ // Wait for all tools to be awaiting approval
903
+ await vi.waitFor(() => {
904
+ const calls = onToolCallsUpdate.mock.calls.at(-1)?.[0];
905
+ expect(calls?.length).toBe(3);
906
+ expect(calls?.every((call) => call.status === 'awaiting_approval')).toBe(true);
907
+ });
908
+ expect(pendingConfirmations.length).toBe(3);
909
+ // Approve the first tool with ProceedAlways
910
+ const firstConfirmation = pendingConfirmations[0];
911
+ firstConfirmation(ToolConfirmationOutcome.ProceedAlways);
912
+ // Wait for all tools to be completed
913
+ await vi.waitFor(() => {
914
+ expect(onAllToolCallsComplete).toHaveBeenCalled();
915
+ const completedCalls = onAllToolCallsComplete.mock.calls.at(-1)?.[0];
916
+ expect(completedCalls?.length).toBe(3);
917
+ expect(completedCalls?.every((call) => call.status === 'success')).toBe(true);
918
+ });
919
+ // Verify approval mode was changed
920
+ expect(approvalMode).toBe(ApprovalMode.AUTO_EDIT);
921
+ });
922
+ });
923
+ //# sourceMappingURL=coreToolScheduler.test.js.map