@machina.ai/cell-cli-core 1.0.21-rc4 → 1.2.2-rc1

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 (479) hide show
  1. package/dist/index.d.ts +3 -1
  2. package/dist/index.js +3 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/package.json +24 -11
  5. package/dist/src/code_assist/codeAssist.d.ts +4 -3
  6. package/dist/src/code_assist/codeAssist.js.map +1 -1
  7. package/dist/src/code_assist/converter.d.ts +2 -1
  8. package/dist/src/code_assist/converter.js +36 -4
  9. package/dist/src/code_assist/converter.js.map +1 -1
  10. package/dist/src/code_assist/converter.test.js +83 -0
  11. package/dist/src/code_assist/converter.test.js.map +1 -1
  12. package/dist/src/code_assist/oauth2.d.ts +2 -1
  13. package/dist/src/code_assist/oauth2.js +29 -24
  14. package/dist/src/code_assist/oauth2.js.map +1 -1
  15. package/dist/src/code_assist/oauth2.test.js +65 -15
  16. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  17. package/dist/src/code_assist/server.d.ts +5 -5
  18. package/dist/src/code_assist/server.js +1 -1
  19. package/dist/src/code_assist/server.js.map +1 -1
  20. package/dist/src/code_assist/setup.d.ts +1 -1
  21. package/dist/src/code_assist/setup.js +1 -1
  22. package/dist/src/code_assist/setup.js.map +1 -1
  23. package/dist/src/code_assist/setup.test.js.map +1 -1
  24. package/dist/src/config/config.d.ts +53 -11
  25. package/dist/src/config/config.js +113 -29
  26. package/dist/src/config/config.js.map +1 -1
  27. package/dist/src/config/config.test.js +103 -5
  28. package/dist/src/config/config.test.js.map +1 -1
  29. package/dist/src/config/models.d.ts +1 -0
  30. package/dist/src/config/models.js +2 -0
  31. package/dist/src/config/models.js.map +1 -1
  32. package/dist/src/config/storage.d.ts +32 -0
  33. package/dist/src/config/storage.js +90 -0
  34. package/dist/src/config/storage.js.map +1 -0
  35. package/dist/src/config/storage.test.js +43 -0
  36. package/dist/src/config/storage.test.js.map +1 -0
  37. package/dist/src/core/client.d.ts +17 -9
  38. package/dist/src/core/client.js +76 -19
  39. package/dist/src/core/client.js.map +1 -1
  40. package/dist/src/core/client.test.js +366 -84
  41. package/dist/src/core/client.test.js.map +1 -1
  42. package/dist/src/core/contentGenerator.d.ts +6 -6
  43. package/dist/src/core/contentGenerator.js +4 -3
  44. package/dist/src/core/contentGenerator.js.map +1 -1
  45. package/dist/src/core/contentGenerator.test.js.map +1 -1
  46. package/dist/src/core/coreToolScheduler.d.ts +14 -5
  47. package/dist/src/core/coreToolScheduler.js +120 -49
  48. package/dist/src/core/coreToolScheduler.js.map +1 -1
  49. package/dist/src/core/coreToolScheduler.test.js +365 -72
  50. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  51. package/dist/src/core/geminiChat.d.ts +18 -14
  52. package/dist/src/core/geminiChat.js +223 -156
  53. package/dist/src/core/geminiChat.js.map +1 -1
  54. package/dist/src/core/geminiChat.test.js +862 -257
  55. package/dist/src/core/geminiChat.test.js.map +1 -1
  56. package/dist/src/core/geminiRequest.js +1 -0
  57. package/dist/src/core/geminiRequest.js.map +1 -1
  58. package/dist/src/core/logger.d.ts +4 -2
  59. package/dist/src/core/logger.js +4 -3
  60. package/dist/src/core/logger.js.map +1 -1
  61. package/dist/src/core/logger.test.js +19 -18
  62. package/dist/src/core/logger.test.js.map +1 -1
  63. package/dist/src/core/loggingContentGenerator.d.ts +3 -3
  64. package/dist/src/core/loggingContentGenerator.js +3 -1
  65. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  66. package/dist/src/core/nonInteractiveToolExecutor.d.ts +3 -5
  67. package/dist/src/core/nonInteractiveToolExecutor.js +15 -123
  68. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  69. package/dist/src/core/nonInteractiveToolExecutor.test.js +114 -90
  70. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  71. package/dist/src/core/prompts.js +8 -7
  72. package/dist/src/core/prompts.js.map +1 -1
  73. package/dist/src/core/prompts.test.js +21 -21
  74. package/dist/src/core/prompts.test.js.map +1 -1
  75. package/dist/src/core/subagent.d.ts +24 -18
  76. package/dist/src/core/subagent.js +125 -87
  77. package/dist/src/core/subagent.js.map +1 -1
  78. package/dist/src/core/subagent.test.js +31 -26
  79. package/dist/src/core/subagent.test.js.map +1 -1
  80. package/dist/src/core/turn.d.ts +24 -7
  81. package/dist/src/core/turn.js +41 -11
  82. package/dist/src/core/turn.js.map +1 -1
  83. package/dist/src/core/turn.test.js +157 -1
  84. package/dist/src/core/turn.test.js.map +1 -1
  85. package/dist/src/generated/git-commit.d.ts +2 -2
  86. package/dist/src/generated/git-commit.js +2 -2
  87. package/dist/src/generated/git-commit.js.map +1 -1
  88. package/dist/src/ide/constants.d.ts +1 -1
  89. package/dist/src/ide/constants.js +1 -1
  90. package/dist/src/ide/constants.js.map +1 -1
  91. package/dist/src/ide/detect-ide.d.ts +8 -3
  92. package/dist/src/ide/detect-ide.js +29 -11
  93. package/dist/src/ide/detect-ide.js.map +1 -1
  94. package/dist/src/ide/detect-ide.test.js +96 -52
  95. package/dist/src/ide/detect-ide.test.js.map +1 -1
  96. package/dist/src/ide/ide-client.d.ts +11 -7
  97. package/dist/src/ide/ide-client.js +127 -29
  98. package/dist/src/ide/ide-client.js.map +1 -1
  99. package/dist/src/ide/ide-client.test.js +147 -25
  100. package/dist/src/ide/ide-client.test.js.map +1 -1
  101. package/dist/src/ide/ide-installer.d.ts +1 -1
  102. package/dist/src/ide/ide-installer.js +31 -22
  103. package/dist/src/ide/ide-installer.js.map +1 -1
  104. package/dist/src/ide/ide-installer.test.js +82 -22
  105. package/dist/src/ide/ide-installer.test.js.map +1 -1
  106. package/dist/src/ide/process-utils.d.ts +14 -6
  107. package/dist/src/ide/process-utils.js +136 -34
  108. package/dist/src/ide/process-utils.js.map +1 -1
  109. package/dist/src/ide/process-utils.test.js +158 -0
  110. package/dist/src/ide/process-utils.test.js.map +1 -0
  111. package/dist/src/index.d.ts +11 -2
  112. package/dist/src/index.js +10 -1
  113. package/dist/src/index.js.map +1 -1
  114. package/dist/src/mcp/google-auth-provider.d.ts +3 -3
  115. package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
  116. package/dist/src/mcp/oauth-provider.d.ts +2 -2
  117. package/dist/src/mcp/oauth-provider.js.map +1 -1
  118. package/dist/src/mcp/oauth-provider.test.js +1 -1
  119. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  120. package/dist/src/mcp/oauth-token-storage.d.ts +5 -27
  121. package/dist/src/mcp/oauth-token-storage.js +2 -5
  122. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  123. package/dist/src/mcp/oauth-token-storage.test.js +7 -6
  124. package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
  125. package/dist/src/mcp/oauth-utils.d.ts +9 -1
  126. package/dist/src/mcp/oauth-utils.js +41 -27
  127. package/dist/src/mcp/oauth-utils.js.map +1 -1
  128. package/dist/src/mcp/oauth-utils.test.js +41 -1
  129. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  130. package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
  131. package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
  132. package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
  133. package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
  134. package/dist/src/mcp/token-storage/base-token-storage.test.js +160 -0
  135. package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
  136. package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
  137. package/dist/src/mcp/token-storage/file-token-storage.js +144 -0
  138. package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
  139. package/dist/src/mcp/token-storage/file-token-storage.test.d.ts +6 -0
  140. package/dist/src/mcp/token-storage/file-token-storage.test.js +235 -0
  141. package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -0
  142. package/dist/src/mcp/token-storage/types.d.ts +34 -0
  143. package/dist/src/mcp/token-storage/types.js +7 -0
  144. package/dist/src/mcp/token-storage/types.js.map +1 -0
  145. package/dist/src/prompts/mcp-prompts.d.ts +2 -2
  146. package/dist/src/prompts/prompt-registry.d.ts +1 -1
  147. package/dist/src/services/chatRecordingService.d.ts +2 -2
  148. package/dist/src/services/chatRecordingService.js +6 -3
  149. package/dist/src/services/chatRecordingService.js.map +1 -1
  150. package/dist/src/services/chatRecordingService.test.js +10 -8
  151. package/dist/src/services/chatRecordingService.test.js.map +1 -1
  152. package/dist/src/services/fileDiscoveryService.js +1 -1
  153. package/dist/src/services/fileDiscoveryService.js.map +1 -1
  154. package/dist/src/services/fileDiscoveryService.test.js +3 -3
  155. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  156. package/dist/src/services/fileSystemService.js +1 -1
  157. package/dist/src/services/fileSystemService.js.map +1 -1
  158. package/dist/src/services/fileSystemService.test.js +1 -1
  159. package/dist/src/services/fileSystemService.test.js.map +1 -1
  160. package/dist/src/services/gitService.d.ts +3 -1
  161. package/dist/src/services/gitService.js +21 -12
  162. package/dist/src/services/gitService.js.map +1 -1
  163. package/dist/src/services/gitService.test.js +22 -19
  164. package/dist/src/services/gitService.test.js.map +1 -1
  165. package/dist/src/services/loopDetectionService.d.ts +2 -2
  166. package/dist/src/services/loopDetectionService.js +9 -3
  167. package/dist/src/services/loopDetectionService.js.map +1 -1
  168. package/dist/src/services/loopDetectionService.test.js +23 -1
  169. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  170. package/dist/src/services/shellExecutionService.d.ts +8 -10
  171. package/dist/src/services/shellExecutionService.js +292 -135
  172. package/dist/src/services/shellExecutionService.js.map +1 -1
  173. package/dist/src/services/shellExecutionService.test.js +277 -42
  174. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  175. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +16 -4
  176. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +140 -9
  177. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  178. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +84 -11
  179. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
  180. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +26 -1
  181. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +62 -0
  182. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  183. package/dist/src/telemetry/constants.d.ts +8 -0
  184. package/dist/src/telemetry/constants.js +8 -0
  185. package/dist/src/telemetry/constants.js.map +1 -1
  186. package/dist/src/telemetry/file-exporters.d.ts +5 -4
  187. package/dist/src/telemetry/file-exporters.js +1 -1
  188. package/dist/src/telemetry/file-exporters.js.map +1 -1
  189. package/dist/src/telemetry/index.d.ts +5 -2
  190. package/dist/src/telemetry/index.js +3 -2
  191. package/dist/src/telemetry/index.js.map +1 -1
  192. package/dist/src/telemetry/loggers.d.ts +8 -2
  193. package/dist/src/telemetry/loggers.js +105 -2
  194. package/dist/src/telemetry/loggers.js.map +1 -1
  195. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  196. package/dist/src/telemetry/loggers.test.js +69 -9
  197. package/dist/src/telemetry/loggers.test.js.map +1 -1
  198. package/dist/src/telemetry/metrics.d.ts +15 -4
  199. package/dist/src/telemetry/metrics.js +46 -8
  200. package/dist/src/telemetry/metrics.js.map +1 -1
  201. package/dist/src/telemetry/metrics.test.js +5 -25
  202. package/dist/src/telemetry/metrics.test.js.map +1 -1
  203. package/dist/src/telemetry/sdk.d.ts +1 -1
  204. package/dist/src/telemetry/sdk.js +3 -3
  205. package/dist/src/telemetry/sdk.js.map +1 -1
  206. package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
  207. package/dist/src/telemetry/telemetry-utils.js +14 -0
  208. package/dist/src/telemetry/telemetry-utils.js.map +1 -0
  209. package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
  210. package/dist/src/telemetry/telemetry-utils.test.js +40 -0
  211. package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
  212. package/dist/src/telemetry/types.d.ts +52 -6
  213. package/dist/src/telemetry/types.js +87 -2
  214. package/dist/src/telemetry/types.js.map +1 -1
  215. package/dist/src/telemetry/uiTelemetry.d.ts +2 -2
  216. package/dist/src/telemetry/uiTelemetry.js +1 -1
  217. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  218. package/dist/src/telemetry/uiTelemetry.test.js +16 -12
  219. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  220. package/dist/src/test-utils/config.d.ts +2 -1
  221. package/dist/src/test-utils/config.js.map +1 -1
  222. package/dist/src/test-utils/index.d.ts +6 -0
  223. package/dist/src/test-utils/index.js +7 -0
  224. package/dist/src/test-utils/index.js.map +1 -0
  225. package/dist/src/test-utils/mock-tool.d.ts +41 -0
  226. package/dist/src/test-utils/mock-tool.js +51 -0
  227. package/dist/src/test-utils/mock-tool.js.map +1 -0
  228. package/dist/src/test-utils/mockWorkspaceContext.d.ts +1 -1
  229. package/dist/src/test-utils/tools.d.ts +3 -2
  230. package/dist/src/test-utils/tools.js.map +1 -1
  231. package/dist/src/tools/diffOptions.d.ts +1 -1
  232. package/dist/src/tools/edit.d.ts +6 -5
  233. package/dist/src/tools/edit.js +36 -17
  234. package/dist/src/tools/edit.js.map +1 -1
  235. package/dist/src/tools/edit.test.js +45 -8
  236. package/dist/src/tools/edit.test.js.map +1 -1
  237. package/dist/src/tools/glob.d.ts +3 -2
  238. package/dist/src/tools/glob.js +17 -6
  239. package/dist/src/tools/glob.js.map +1 -1
  240. package/dist/src/tools/glob.test.js +29 -4
  241. package/dist/src/tools/glob.test.js.map +1 -1
  242. package/dist/src/tools/grep.d.ts +3 -2
  243. package/dist/src/tools/grep.js +35 -15
  244. package/dist/src/tools/grep.js.map +1 -1
  245. package/dist/src/tools/grep.test.js +26 -3
  246. package/dist/src/tools/grep.test.js.map +1 -1
  247. package/dist/src/tools/ls.d.ts +3 -2
  248. package/dist/src/tools/ls.js +12 -7
  249. package/dist/src/tools/ls.js.map +1 -1
  250. package/dist/src/tools/ls.test.js +7 -2
  251. package/dist/src/tools/ls.test.js.map +1 -1
  252. package/dist/src/tools/mcp-client-manager.d.ts +8 -6
  253. package/dist/src/tools/mcp-client-manager.js +30 -5
  254. package/dist/src/tools/mcp-client-manager.js.map +1 -1
  255. package/dist/src/tools/mcp-client-manager.test.js +20 -1
  256. package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
  257. package/dist/src/tools/mcp-client.d.ts +18 -11
  258. package/dist/src/tools/mcp-client.js +38 -33
  259. package/dist/src/tools/mcp-client.js.map +1 -1
  260. package/dist/src/tools/mcp-client.test.js +29 -4
  261. package/dist/src/tools/mcp-client.test.js.map +1 -1
  262. package/dist/src/tools/mcp-tool.d.ts +6 -3
  263. package/dist/src/tools/mcp-tool.js +21 -7
  264. package/dist/src/tools/mcp-tool.js.map +1 -1
  265. package/dist/src/tools/mcp-tool.test.js +49 -6
  266. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  267. package/dist/src/tools/memoryTool.d.ts +4 -3
  268. package/dist/src/tools/memoryTool.js +15 -38
  269. package/dist/src/tools/memoryTool.js.map +1 -1
  270. package/dist/src/tools/memoryTool.test.js +24 -12
  271. package/dist/src/tools/memoryTool.test.js.map +1 -1
  272. package/dist/src/tools/modifiable-tool.d.ts +2 -2
  273. package/dist/src/tools/modifiable-tool.js +3 -3
  274. package/dist/src/tools/modifiable-tool.js.map +1 -1
  275. package/dist/src/tools/modifiable-tool.test.js +4 -4
  276. package/dist/src/tools/modifiable-tool.test.js.map +1 -1
  277. package/dist/src/tools/read-file.d.ts +3 -2
  278. package/dist/src/tools/read-file.js +12 -34
  279. package/dist/src/tools/read-file.js.map +1 -1
  280. package/dist/src/tools/read-file.test.js +9 -6
  281. package/dist/src/tools/read-file.test.js.map +1 -1
  282. package/dist/src/tools/read-many-files.d.ts +3 -2
  283. package/dist/src/tools/read-many-files.js +35 -58
  284. package/dist/src/tools/read-many-files.js.map +1 -1
  285. package/dist/src/tools/read-many-files.test.js +60 -7
  286. package/dist/src/tools/read-many-files.test.js.map +1 -1
  287. package/dist/src/tools/ripGrep.d.ts +47 -0
  288. package/dist/src/tools/ripGrep.js +368 -0
  289. package/dist/src/tools/ripGrep.js.map +1 -0
  290. package/dist/src/tools/ripGrep.test.d.ts +6 -0
  291. package/dist/src/tools/ripGrep.test.js +874 -0
  292. package/dist/src/tools/ripGrep.test.js.map +1 -0
  293. package/dist/src/tools/shell.d.ts +3 -2
  294. package/dist/src/tools/shell.js +26 -24
  295. package/dist/src/tools/shell.js.map +1 -1
  296. package/dist/src/tools/shell.test.js +33 -24
  297. package/dist/src/tools/shell.test.js.map +1 -1
  298. package/dist/src/tools/smart-edit.d.ts +73 -0
  299. package/dist/src/tools/smart-edit.js +607 -0
  300. package/dist/src/tools/smart-edit.js.map +1 -0
  301. package/dist/src/tools/smart-edit.test.d.ts +6 -0
  302. package/dist/src/tools/smart-edit.test.js +397 -0
  303. package/dist/src/tools/smart-edit.test.js.map +1 -0
  304. package/dist/src/tools/tool-error.d.ts +17 -1
  305. package/dist/src/tools/tool-error.js +26 -0
  306. package/dist/src/tools/tool-error.js.map +1 -1
  307. package/dist/src/tools/tool-registry.d.ts +10 -4
  308. package/dist/src/tools/tool-registry.js +19 -7
  309. package/dist/src/tools/tool-registry.js.map +1 -1
  310. package/dist/src/tools/tool-registry.test.js +86 -3
  311. package/dist/src/tools/tool-registry.test.js.map +1 -1
  312. package/dist/src/tools/tools.d.ts +9 -7
  313. package/dist/src/tools/tools.js +12 -0
  314. package/dist/src/tools/tools.js.map +1 -1
  315. package/dist/src/tools/tools.test.js +1 -2
  316. package/dist/src/tools/tools.test.js.map +1 -1
  317. package/dist/src/tools/web-fetch.d.ts +3 -2
  318. package/dist/src/tools/web-fetch.js +10 -7
  319. package/dist/src/tools/web-fetch.js.map +1 -1
  320. package/dist/src/tools/web-fetch.test.js +55 -16
  321. package/dist/src/tools/web-fetch.test.js.map +1 -1
  322. package/dist/src/tools/web-search.d.ts +4 -3
  323. package/dist/src/tools/web-search.js +28 -7
  324. package/dist/src/tools/web-search.js.map +1 -1
  325. package/dist/src/tools/web-search.test.js +69 -1
  326. package/dist/src/tools/web-search.test.js.map +1 -1
  327. package/dist/src/tools/write-file.d.ts +4 -3
  328. package/dist/src/tools/write-file.js +13 -13
  329. package/dist/src/tools/write-file.js.map +1 -1
  330. package/dist/src/tools/write-file.test.js +9 -5
  331. package/dist/src/tools/write-file.test.js.map +1 -1
  332. package/dist/src/utils/bfsFileSearch.d.ts +2 -2
  333. package/dist/src/utils/bfsFileSearch.js +2 -2
  334. package/dist/src/utils/bfsFileSearch.js.map +1 -1
  335. package/dist/src/utils/bfsFileSearch.test.js +3 -3
  336. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  337. package/dist/src/utils/editCorrector.d.ts +2 -2
  338. package/dist/src/utils/editCorrector.js +1 -1
  339. package/dist/src/utils/editCorrector.js.map +1 -1
  340. package/dist/src/utils/editCorrector.test.js +3 -3
  341. package/dist/src/utils/editCorrector.test.js.map +1 -1
  342. package/dist/src/utils/editor.js +2 -2
  343. package/dist/src/utils/editor.js.map +1 -1
  344. package/dist/src/utils/editor.test.js +2 -2
  345. package/dist/src/utils/editor.test.js.map +1 -1
  346. package/dist/src/utils/environmentContext.d.ts +2 -2
  347. package/dist/src/utils/environmentContext.js +1 -1
  348. package/dist/src/utils/environmentContext.js.map +1 -1
  349. package/dist/src/utils/environmentContext.test.js +1 -1
  350. package/dist/src/utils/environmentContext.test.js.map +1 -1
  351. package/dist/src/utils/errorReporting.d.ts +1 -1
  352. package/dist/src/utils/errors.d.ts +19 -0
  353. package/dist/src/utils/errors.js +32 -0
  354. package/dist/src/utils/errors.js.map +1 -1
  355. package/dist/src/utils/fetch.js +1 -1
  356. package/dist/src/utils/fetch.js.map +1 -1
  357. package/dist/src/utils/fileUtils.d.ts +23 -12
  358. package/dist/src/utils/fileUtils.js +155 -75
  359. package/dist/src/utils/fileUtils.js.map +1 -1
  360. package/dist/src/utils/fileUtils.test.js +293 -1
  361. package/dist/src/utils/fileUtils.test.js.map +1 -1
  362. package/dist/src/utils/filesearch/crawler.d.ts +1 -1
  363. package/dist/src/utils/filesearch/crawler.test.js +2 -2
  364. package/dist/src/utils/filesearch/crawler.test.js.map +1 -1
  365. package/dist/src/utils/filesearch/fileSearch.d.ts +1 -0
  366. package/dist/src/utils/filesearch/fileSearch.js +14 -9
  367. package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
  368. package/dist/src/utils/filesearch/fileSearch.test.js +90 -0
  369. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
  370. package/dist/src/utils/generateContentResponseUtilities.d.ts +1 -2
  371. package/dist/src/utils/generateContentResponseUtilities.js +1 -13
  372. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
  373. package/dist/src/utils/generateContentResponseUtilities.test.js +2 -40
  374. package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -1
  375. package/dist/src/utils/getFolderStructure.d.ts +2 -2
  376. package/dist/src/utils/getFolderStructure.js +2 -2
  377. package/dist/src/utils/getFolderStructure.js.map +1 -1
  378. package/dist/src/utils/getFolderStructure.test.js +13 -13
  379. package/dist/src/utils/getFolderStructure.test.js.map +1 -1
  380. package/dist/src/utils/getPty.d.ts +19 -0
  381. package/dist/src/utils/getPty.js +23 -0
  382. package/dist/src/utils/getPty.js.map +1 -0
  383. package/dist/src/utils/gitIgnoreParser.js +3 -3
  384. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  385. package/dist/src/utils/gitIgnoreParser.test.js +3 -3
  386. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  387. package/dist/src/utils/gitUtils.js +2 -2
  388. package/dist/src/utils/gitUtils.js.map +1 -1
  389. package/dist/src/utils/ignorePatterns.d.ts +103 -0
  390. package/dist/src/utils/ignorePatterns.js +220 -0
  391. package/dist/src/utils/ignorePatterns.js.map +1 -0
  392. package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
  393. package/dist/src/utils/ignorePatterns.test.js +250 -0
  394. package/dist/src/utils/ignorePatterns.test.js.map +1 -0
  395. package/dist/src/utils/installationManager.d.ts +16 -0
  396. package/dist/src/utils/installationManager.js +50 -0
  397. package/dist/src/utils/installationManager.js.map +1 -0
  398. package/dist/src/utils/installationManager.test.d.ts +6 -0
  399. package/dist/src/utils/installationManager.test.js +83 -0
  400. package/dist/src/utils/installationManager.test.js.map +1 -0
  401. package/dist/src/utils/language-detection.d.ts +6 -0
  402. package/dist/src/utils/language-detection.js +101 -0
  403. package/dist/src/utils/language-detection.js.map +1 -0
  404. package/dist/src/utils/llm-edit-fixer.d.ts +25 -0
  405. package/dist/src/utils/llm-edit-fixer.js +112 -0
  406. package/dist/src/utils/llm-edit-fixer.js.map +1 -0
  407. package/dist/src/utils/memoryDiscovery.d.ts +7 -6
  408. package/dist/src/utils/memoryDiscovery.js +68 -33
  409. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  410. package/dist/src/utils/memoryDiscovery.test.js +76 -20
  411. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  412. package/dist/src/utils/memoryImportProcessor.js +2 -2
  413. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  414. package/dist/src/utils/memoryImportProcessor.test.js +2 -141
  415. package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
  416. package/dist/src/utils/messageInspectors.d.ts +1 -1
  417. package/dist/src/utils/nextSpeakerChecker.d.ts +2 -2
  418. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  419. package/dist/src/utils/partUtils.d.ts +22 -1
  420. package/dist/src/utils/partUtils.js +68 -0
  421. package/dist/src/utils/partUtils.js.map +1 -1
  422. package/dist/src/utils/partUtils.test.js +112 -1
  423. package/dist/src/utils/partUtils.test.js.map +1 -1
  424. package/dist/src/utils/pathReader.d.ts +17 -0
  425. package/dist/src/utils/pathReader.js +92 -0
  426. package/dist/src/utils/pathReader.js.map +1 -0
  427. package/dist/src/utils/pathReader.test.d.ts +6 -0
  428. package/dist/src/utils/pathReader.test.js +363 -0
  429. package/dist/src/utils/pathReader.test.js.map +1 -0
  430. package/dist/src/utils/paths.d.ts +1 -18
  431. package/dist/src/utils/paths.js +3 -29
  432. package/dist/src/utils/paths.js.map +1 -1
  433. package/dist/src/utils/quotaErrorDetection.d.ts +1 -1
  434. package/dist/src/utils/retry.test.js +4 -1
  435. package/dist/src/utils/retry.test.js.map +1 -1
  436. package/dist/src/utils/schemaValidator.js +4 -0
  437. package/dist/src/utils/schemaValidator.js.map +1 -1
  438. package/dist/src/utils/session.js +1 -1
  439. package/dist/src/utils/session.js.map +1 -1
  440. package/dist/src/utils/shell-utils.d.ts +1 -1
  441. package/dist/src/utils/shell-utils.js +23 -29
  442. package/dist/src/utils/shell-utils.js.map +1 -1
  443. package/dist/src/utils/shell-utils.test.js +8 -1
  444. package/dist/src/utils/shell-utils.test.js.map +1 -1
  445. package/dist/src/utils/summarizer.d.ts +2 -2
  446. package/dist/src/utils/summarizer.test.js.map +1 -1
  447. package/dist/src/utils/systemEncoding.js +2 -2
  448. package/dist/src/utils/systemEncoding.js.map +1 -1
  449. package/dist/src/utils/systemEncoding.test.js +2 -2
  450. package/dist/src/utils/systemEncoding.test.js.map +1 -1
  451. package/dist/src/utils/tool-utils.d.ts +19 -0
  452. package/dist/src/utils/tool-utils.js +58 -0
  453. package/dist/src/utils/tool-utils.js.map +1 -0
  454. package/dist/src/utils/tool-utils.test.d.ts +6 -0
  455. package/dist/src/utils/tool-utils.test.js +61 -0
  456. package/dist/src/utils/tool-utils.test.js.map +1 -0
  457. package/dist/src/utils/userAccountManager.d.ts +20 -0
  458. package/dist/src/utils/userAccountManager.js +114 -0
  459. package/dist/src/utils/userAccountManager.js.map +1 -0
  460. package/dist/src/utils/userAccountManager.test.d.ts +6 -0
  461. package/dist/src/utils/{user_account.test.js → userAccountManager.test.js} +33 -30
  462. package/dist/src/utils/userAccountManager.test.js.map +1 -0
  463. package/dist/src/utils/workspaceContext.js +13 -7
  464. package/dist/src/utils/workspaceContext.js.map +1 -1
  465. package/dist/src/utils/workspaceContext.test.js +41 -16
  466. package/dist/src/utils/workspaceContext.test.js.map +1 -1
  467. package/dist/tsconfig.tsbuildinfo +1 -1
  468. package/package.json +25 -12
  469. package/dist/src/utils/user_account.d.ts +0 -9
  470. package/dist/src/utils/user_account.js +0 -109
  471. package/dist/src/utils/user_account.js.map +0 -1
  472. package/dist/src/utils/user_account.test.js.map +0 -1
  473. package/dist/src/utils/user_id.d.ts +0 -11
  474. package/dist/src/utils/user_id.js +0 -49
  475. package/dist/src/utils/user_id.js.map +0 -1
  476. package/dist/src/utils/user_id.test.js +0 -21
  477. package/dist/src/utils/user_id.test.js.map +0 -1
  478. /package/dist/src/{utils/user_account.test.d.ts → config/storage.test.d.ts} +0 -0
  479. /package/dist/src/{utils/user_id.test.d.ts → ide/process-utils.test.d.ts} +0 -0
@@ -7,12 +7,87 @@ import { describe, it, expect, vi } from 'vitest';
7
7
  import { CoreToolScheduler, convertToFunctionResponse, } from './coreToolScheduler.js';
8
8
  import { BaseDeclarativeTool, BaseToolInvocation, ToolConfirmationOutcome, Kind, ApprovalMode, } from '../index.js';
9
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
+ }
10
85
  describe('CoreToolScheduler', () => {
11
86
  it('should cancel a tool call if the signal is aborted before confirmation', async () => {
12
87
  const mockTool = new MockTool();
13
88
  mockTool.shouldConfirm = true;
14
89
  const declarativeTool = mockTool;
15
- const toolRegistry = {
90
+ const mockToolRegistry = {
16
91
  getTool: () => declarativeTool,
17
92
  getFunctionDeclarations: () => [],
18
93
  tools: new Map(),
@@ -32,14 +107,15 @@ describe('CoreToolScheduler', () => {
32
107
  getUsageStatisticsEnabled: () => true,
33
108
  getDebugMode: () => false,
34
109
  getApprovalMode: () => ApprovalMode.DEFAULT,
110
+ getAllowedTools: () => [],
35
111
  getContentGeneratorConfig: () => ({
36
112
  model: 'test-model',
37
113
  authType: 'oauth-personal',
38
114
  }),
115
+ getToolRegistry: () => mockToolRegistry,
39
116
  };
40
117
  const scheduler = new CoreToolScheduler({
41
118
  config: mockConfig,
42
- toolRegistry: Promise.resolve(toolRegistry),
43
119
  onAllToolCallsComplete,
44
120
  onToolCallsUpdate,
45
121
  getPreferredEditor: () => 'vscode',
@@ -60,12 +136,41 @@ describe('CoreToolScheduler', () => {
60
136
  .calls[0][0];
61
137
  expect(completedCalls[0].status).toBe('cancelled');
62
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
+ });
63
168
  });
64
169
  describe('CoreToolScheduler with payload', () => {
65
170
  it('should update args and diff and execute tool when payload is provided', async () => {
66
171
  const mockTool = new MockModifiableTool();
67
172
  const declarativeTool = mockTool;
68
- const toolRegistry = {
173
+ const mockToolRegistry = {
69
174
  getTool: () => declarativeTool,
70
175
  getFunctionDeclarations: () => [],
71
176
  tools: new Map(),
@@ -85,14 +190,15 @@ describe('CoreToolScheduler with payload', () => {
85
190
  getUsageStatisticsEnabled: () => true,
86
191
  getDebugMode: () => false,
87
192
  getApprovalMode: () => ApprovalMode.DEFAULT,
193
+ getAllowedTools: () => [],
88
194
  getContentGeneratorConfig: () => ({
89
195
  model: 'test-model',
90
196
  authType: 'oauth-personal',
91
197
  }),
198
+ getToolRegistry: () => mockToolRegistry,
92
199
  };
93
200
  const scheduler = new CoreToolScheduler({
94
201
  config: mockConfig,
95
- toolRegistry: Promise.resolve(toolRegistry),
96
202
  onAllToolCallsComplete,
97
203
  onToolCallsUpdate,
98
204
  getPreferredEditor: () => 'vscode',
@@ -107,11 +213,7 @@ describe('CoreToolScheduler with payload', () => {
107
213
  prompt_id: 'prompt-id-2',
108
214
  };
109
215
  await scheduler.schedule([request], abortController.signal);
110
- await vi.waitFor(() => {
111
- const awaitingCall = onToolCallsUpdate.mock.calls.find((call) => call[0][0].status === 'awaiting_approval')?.[0][0];
112
- expect(awaitingCall).toBeDefined();
113
- });
114
- const awaitingCall = onToolCallsUpdate.mock.calls.find((call) => call[0][0].status === 'awaiting_approval')?.[0][0];
216
+ const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
115
217
  const confirmationDetails = awaitingCall.confirmationDetails;
116
218
  if (confirmationDetails) {
117
219
  const payload = { newContent: 'final version' };
@@ -132,35 +234,41 @@ describe('convertToFunctionResponse', () => {
132
234
  it('should handle simple string llmContent', () => {
133
235
  const llmContent = 'Simple text output';
134
236
  const result = convertToFunctionResponse(toolName, callId, llmContent);
135
- expect(result).toEqual({
136
- functionResponse: {
137
- name: toolName,
138
- id: callId,
139
- response: { output: 'Simple text output' },
237
+ expect(result).toEqual([
238
+ {
239
+ functionResponse: {
240
+ name: toolName,
241
+ id: callId,
242
+ response: { output: 'Simple text output' },
243
+ },
140
244
  },
141
- });
245
+ ]);
142
246
  });
143
247
  it('should handle llmContent as a single Part with text', () => {
144
248
  const llmContent = { text: 'Text from Part object' };
145
249
  const result = convertToFunctionResponse(toolName, callId, llmContent);
146
- expect(result).toEqual({
147
- functionResponse: {
148
- name: toolName,
149
- id: callId,
150
- response: { output: 'Text from Part object' },
250
+ expect(result).toEqual([
251
+ {
252
+ functionResponse: {
253
+ name: toolName,
254
+ id: callId,
255
+ response: { output: 'Text from Part object' },
256
+ },
151
257
  },
152
- });
258
+ ]);
153
259
  });
154
260
  it('should handle llmContent as a PartListUnion array with a single text Part', () => {
155
261
  const llmContent = [{ text: 'Text from array' }];
156
262
  const result = convertToFunctionResponse(toolName, callId, llmContent);
157
- expect(result).toEqual({
158
- functionResponse: {
159
- name: toolName,
160
- id: callId,
161
- response: { output: 'Text from array' },
263
+ expect(result).toEqual([
264
+ {
265
+ functionResponse: {
266
+ name: toolName,
267
+ id: callId,
268
+ response: { output: 'Text from array' },
269
+ },
162
270
  },
163
- });
271
+ ]);
164
272
  });
165
273
  it('should handle llmContent with inlineData', () => {
166
274
  const llmContent = {
@@ -237,24 +345,28 @@ describe('convertToFunctionResponse', () => {
237
345
  it('should handle llmContent as a generic Part (not text, inlineData, or fileData)', () => {
238
346
  const llmContent = { functionCall: { name: 'test', args: {} } };
239
347
  const result = convertToFunctionResponse(toolName, callId, llmContent);
240
- expect(result).toEqual({
241
- functionResponse: {
242
- name: toolName,
243
- id: callId,
244
- response: { output: 'Tool execution succeeded.' },
348
+ expect(result).toEqual([
349
+ {
350
+ functionResponse: {
351
+ name: toolName,
352
+ id: callId,
353
+ response: { output: 'Tool execution succeeded.' },
354
+ },
245
355
  },
246
- });
356
+ ]);
247
357
  });
248
358
  it('should handle empty string llmContent', () => {
249
359
  const llmContent = '';
250
360
  const result = convertToFunctionResponse(toolName, callId, llmContent);
251
- expect(result).toEqual({
252
- functionResponse: {
253
- name: toolName,
254
- id: callId,
255
- response: { output: '' },
361
+ expect(result).toEqual([
362
+ {
363
+ functionResponse: {
364
+ name: toolName,
365
+ id: callId,
366
+ response: { output: '' },
367
+ },
256
368
  },
257
- });
369
+ ]);
258
370
  });
259
371
  it('should handle llmContent as an empty array', () => {
260
372
  const llmContent = [];
@@ -272,13 +384,15 @@ describe('convertToFunctionResponse', () => {
272
384
  it('should handle llmContent as a Part with undefined inlineData/fileData/text', () => {
273
385
  const llmContent = {}; // An empty part object
274
386
  const result = convertToFunctionResponse(toolName, callId, llmContent);
275
- expect(result).toEqual({
276
- functionResponse: {
277
- name: toolName,
278
- id: callId,
279
- response: { output: 'Tool execution succeeded.' },
387
+ expect(result).toEqual([
388
+ {
389
+ functionResponse: {
390
+ name: toolName,
391
+ id: callId,
392
+ response: { output: 'Tool execution succeeded.' },
393
+ },
280
394
  },
281
- });
395
+ ]);
282
396
  });
283
397
  });
284
398
  class MockEditToolInvocation extends BaseToolInvocation {
@@ -318,15 +432,14 @@ class MockEditTool extends BaseDeclarativeTool {
318
432
  describe('CoreToolScheduler edit cancellation', () => {
319
433
  it('should preserve diff when an edit is cancelled', async () => {
320
434
  const mockEditTool = new MockEditTool();
321
- const declarativeTool = mockEditTool;
322
- const toolRegistry = {
323
- getTool: () => declarativeTool,
435
+ const mockToolRegistry = {
436
+ getTool: () => mockEditTool,
324
437
  getFunctionDeclarations: () => [],
325
438
  tools: new Map(),
326
439
  discovery: {},
327
440
  registerTool: () => { },
328
- getToolByName: () => declarativeTool,
329
- getToolByDisplayName: () => declarativeTool,
441
+ getToolByName: () => mockEditTool,
442
+ getToolByDisplayName: () => mockEditTool,
330
443
  getTools: () => [],
331
444
  discoverTools: async () => { },
332
445
  getAllTools: () => [],
@@ -339,14 +452,15 @@ describe('CoreToolScheduler edit cancellation', () => {
339
452
  getUsageStatisticsEnabled: () => true,
340
453
  getDebugMode: () => false,
341
454
  getApprovalMode: () => ApprovalMode.DEFAULT,
455
+ getAllowedTools: () => [],
342
456
  getContentGeneratorConfig: () => ({
343
457
  model: 'test-model',
344
458
  authType: 'oauth-personal',
345
459
  }),
460
+ getToolRegistry: () => mockToolRegistry,
346
461
  };
347
462
  const scheduler = new CoreToolScheduler({
348
463
  config: mockConfig,
349
- toolRegistry: Promise.resolve(toolRegistry),
350
464
  onAllToolCallsComplete,
351
465
  onToolCallsUpdate,
352
466
  getPreferredEditor: () => 'vscode',
@@ -361,9 +475,7 @@ describe('CoreToolScheduler edit cancellation', () => {
361
475
  prompt_id: 'prompt-id-1',
362
476
  };
363
477
  await scheduler.schedule([request], abortController.signal);
364
- // Wait for the tool to reach awaiting_approval state
365
- const awaitingCall = onToolCallsUpdate.mock.calls.find((call) => call[0][0].status === 'awaiting_approval')?.[0][0];
366
- expect(awaitingCall).toBeDefined();
478
+ const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
367
479
  // Cancel the edit
368
480
  const confirmationDetails = awaitingCall.confirmationDetails;
369
481
  if (confirmationDetails) {
@@ -392,7 +504,7 @@ describe('CoreToolScheduler YOLO mode', () => {
392
504
  // This tool would normally require confirmation.
393
505
  mockTool.shouldConfirm = true;
394
506
  const declarativeTool = mockTool;
395
- const toolRegistry = {
507
+ const mockToolRegistry = {
396
508
  getTool: () => declarativeTool,
397
509
  getToolByName: () => declarativeTool,
398
510
  // Other properties are not needed for this test but are included for type consistency.
@@ -414,14 +526,15 @@ describe('CoreToolScheduler YOLO mode', () => {
414
526
  getUsageStatisticsEnabled: () => true,
415
527
  getDebugMode: () => false,
416
528
  getApprovalMode: () => ApprovalMode.YOLO,
529
+ getAllowedTools: () => [],
417
530
  getContentGeneratorConfig: () => ({
418
531
  model: 'test-model',
419
532
  authType: 'oauth-personal',
420
533
  }),
534
+ getToolRegistry: () => mockToolRegistry,
421
535
  };
422
536
  const scheduler = new CoreToolScheduler({
423
537
  config: mockConfig,
424
- toolRegistry: Promise.resolve(toolRegistry),
425
538
  onAllToolCallsComplete,
426
539
  onToolCallsUpdate,
427
540
  getPreferredEditor: () => 'vscode',
@@ -472,7 +585,7 @@ describe('CoreToolScheduler request queueing', () => {
472
585
  const mockTool = new MockTool();
473
586
  mockTool.executeFn.mockImplementation(() => firstCallPromise);
474
587
  const declarativeTool = mockTool;
475
- const toolRegistry = {
588
+ const mockToolRegistry = {
476
589
  getTool: () => declarativeTool,
477
590
  getToolByName: () => declarativeTool,
478
591
  getFunctionDeclarations: () => [],
@@ -492,14 +605,15 @@ describe('CoreToolScheduler request queueing', () => {
492
605
  getUsageStatisticsEnabled: () => true,
493
606
  getDebugMode: () => false,
494
607
  getApprovalMode: () => ApprovalMode.YOLO, // Use YOLO to avoid confirmation prompts
608
+ getAllowedTools: () => [],
495
609
  getContentGeneratorConfig: () => ({
496
610
  model: 'test-model',
497
611
  authType: 'oauth-personal',
498
612
  }),
613
+ getToolRegistry: () => mockToolRegistry,
499
614
  };
500
615
  const scheduler = new CoreToolScheduler({
501
616
  config: mockConfig,
502
- toolRegistry: Promise.resolve(toolRegistry),
503
617
  onAllToolCallsComplete,
504
618
  onToolCallsUpdate,
505
619
  getPreferredEditor: () => 'vscode',
@@ -523,10 +637,7 @@ describe('CoreToolScheduler request queueing', () => {
523
637
  // Schedule the first call, which will pause execution.
524
638
  scheduler.schedule([request1], abortController.signal);
525
639
  // Wait for the first call to be in the 'executing' state.
526
- await vi.waitFor(() => {
527
- const calls = onToolCallsUpdate.mock.calls.at(-1)?.[0];
528
- expect(calls?.[0]?.status).toBe('executing');
529
- });
640
+ await waitForStatus(onToolCallsUpdate, 'executing');
530
641
  // Schedule the second call while the first is "running".
531
642
  const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
532
643
  // Ensure the second tool call hasn't been executed yet.
@@ -539,14 +650,6 @@ describe('CoreToolScheduler request queueing', () => {
539
650
  });
540
651
  // Wait for the second schedule promise to resolve.
541
652
  await schedulePromise2;
542
- // Wait for the second call to be in the 'executing' state.
543
- await vi.waitFor(() => {
544
- const calls = onToolCallsUpdate.mock.calls.at(-1)?.[0];
545
- expect(calls?.[0]?.status).toBe('executing');
546
- });
547
- // Now the second tool call should have been executed.
548
- expect(mockTool.executeFn).toHaveBeenCalledTimes(2);
549
- expect(mockTool.executeFn).toHaveBeenCalledWith({ b: 2 });
550
653
  // Let the second call finish.
551
654
  const secondCallResult = {
552
655
  llmContent: 'Second call complete',
@@ -555,6 +658,11 @@ describe('CoreToolScheduler request queueing', () => {
555
658
  // Since the mock is shared, we need to resolve the current promise.
556
659
  // In a real scenario, a new promise would be created for the second call.
557
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 });
558
666
  // Wait for the second completion.
559
667
  await vi.waitFor(() => {
560
668
  expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
@@ -563,10 +671,90 @@ describe('CoreToolScheduler request queueing', () => {
563
671
  expect(onAllToolCallsComplete.mock.calls[0][0][0].status).toBe('success');
564
672
  expect(onAllToolCallsComplete.mock.calls[1][0][0].status).toBe('success');
565
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
+ });
566
754
  it('should handle two synchronous calls to schedule', async () => {
567
755
  const mockTool = new MockTool();
568
756
  const declarativeTool = mockTool;
569
- const toolRegistry = {
757
+ const mockToolRegistry = {
570
758
  getTool: () => declarativeTool,
571
759
  getToolByName: () => declarativeTool,
572
760
  getFunctionDeclarations: () => [],
@@ -586,14 +774,15 @@ describe('CoreToolScheduler request queueing', () => {
586
774
  getUsageStatisticsEnabled: () => true,
587
775
  getDebugMode: () => false,
588
776
  getApprovalMode: () => ApprovalMode.YOLO,
777
+ getAllowedTools: () => [],
589
778
  getContentGeneratorConfig: () => ({
590
779
  model: 'test-model',
591
780
  authType: 'oauth-personal',
592
781
  }),
782
+ getToolRegistry: () => mockToolRegistry,
593
783
  };
594
784
  const scheduler = new CoreToolScheduler({
595
785
  config: mockConfig,
596
- toolRegistry: Promise.resolve(toolRegistry),
597
786
  onAllToolCallsComplete,
598
787
  onToolCallsUpdate,
599
788
  getPreferredEditor: () => 'vscode',
@@ -626,5 +815,109 @@ describe('CoreToolScheduler request queueing', () => {
626
815
  // Ensure completion callbacks were called twice.
627
816
  expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
628
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
+ });
629
922
  });
630
923
  //# sourceMappingURL=coreToolScheduler.test.js.map