@google/gemini-cli 0.1.1 → 0.1.3-rc.0

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 (391) hide show
  1. package/README.md +7 -6
  2. package/dist/.last_build +0 -0
  3. package/dist/google-gemini-cli-0.1.3.tgz +0 -0
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.js +20 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/package.json +77 -0
  8. package/dist/src/config/auth.d.ts +6 -0
  9. package/dist/src/config/auth.js +38 -0
  10. package/dist/src/config/auth.js.map +1 -0
  11. package/dist/src/config/config.d.ts +14 -0
  12. package/dist/src/config/config.js +225 -0
  13. package/dist/src/config/config.js.map +1 -0
  14. package/dist/src/config/extension.d.ts +19 -0
  15. package/dist/src/config/extension.js +81 -0
  16. package/dist/src/config/extension.js.map +1 -0
  17. package/dist/src/config/sandboxConfig.d.ts +13 -0
  18. package/dist/src/config/sandboxConfig.js +75 -0
  19. package/dist/src/config/sandboxConfig.js.map +1 -0
  20. package/dist/src/config/settings.d.ts +69 -0
  21. package/dist/src/config/settings.js +165 -0
  22. package/dist/src/config/settings.js.map +1 -0
  23. package/dist/src/gemini.d.ts +6 -0
  24. package/dist/src/gemini.js +212 -0
  25. package/dist/src/gemini.js.map +1 -0
  26. package/dist/src/gemini.test.d.ts +6 -0
  27. package/dist/src/gemini.test.js +122 -0
  28. package/dist/src/gemini.test.js.map +1 -0
  29. package/dist/src/generated/git-commit.d.ts +6 -0
  30. package/dist/src/generated/git-commit.js +9 -0
  31. package/dist/src/generated/git-commit.js.map +1 -0
  32. package/dist/src/nonInteractiveCli.d.ts +7 -0
  33. package/dist/src/nonInteractiveCli.js +112 -0
  34. package/dist/src/nonInteractiveCli.js.map +1 -0
  35. package/dist/src/ui/App.d.ts +14 -0
  36. package/dist/src/ui/App.js +398 -0
  37. package/dist/src/ui/App.js.map +1 -0
  38. package/dist/src/ui/App.test.d.ts +6 -0
  39. package/dist/src/ui/App.test.js +280 -0
  40. package/dist/src/ui/App.test.js.map +1 -0
  41. package/dist/src/ui/colors.d.ts +7 -0
  42. package/dist/src/ui/colors.js +48 -0
  43. package/dist/src/ui/colors.js.map +1 -0
  44. package/dist/src/ui/components/AboutBox.d.ts +14 -0
  45. package/dist/src/ui/components/AboutBox.js +6 -0
  46. package/dist/src/ui/components/AboutBox.js.map +1 -0
  47. package/dist/src/ui/components/AsciiArt.d.ts +7 -0
  48. package/dist/src/ui/components/AsciiArt.js +26 -0
  49. package/dist/src/ui/components/AsciiArt.js.map +1 -0
  50. package/dist/src/ui/components/AuthDialog.d.ts +15 -0
  51. package/dist/src/ui/components/AuthDialog.js +67 -0
  52. package/dist/src/ui/components/AuthDialog.js.map +1 -0
  53. package/dist/src/ui/components/AuthDialog.test.d.ts +6 -0
  54. package/dist/src/ui/components/AuthDialog.test.js +69 -0
  55. package/dist/src/ui/components/AuthDialog.test.js.map +1 -0
  56. package/dist/src/ui/components/AuthInProgress.d.ts +11 -0
  57. package/dist/src/ui/components/AuthInProgress.js +27 -0
  58. package/dist/src/ui/components/AuthInProgress.js.map +1 -0
  59. package/dist/src/ui/components/AutoAcceptIndicator.d.ts +12 -0
  60. package/dist/src/ui/components/AutoAcceptIndicator.js +26 -0
  61. package/dist/src/ui/components/AutoAcceptIndicator.js.map +1 -0
  62. package/dist/src/ui/components/ConsolePatcher.d.ts +12 -0
  63. package/dist/src/ui/components/ConsolePatcher.js +40 -0
  64. package/dist/src/ui/components/ConsolePatcher.js.map +1 -0
  65. package/dist/src/ui/components/ConsoleSummaryDisplay.d.ts +11 -0
  66. package/dist/src/ui/components/ConsoleSummaryDisplay.js +11 -0
  67. package/dist/src/ui/components/ConsoleSummaryDisplay.js.map +1 -0
  68. package/dist/src/ui/components/ContextSummaryDisplay.d.ts +15 -0
  69. package/dist/src/ui/components/ContextSummaryDisplay.js +41 -0
  70. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -0
  71. package/dist/src/ui/components/DetailedMessagesDisplay.d.ts +14 -0
  72. package/dist/src/ui/components/DetailedMessagesDisplay.js +34 -0
  73. package/dist/src/ui/components/DetailedMessagesDisplay.js.map +1 -0
  74. package/dist/src/ui/components/EditorSettingsDialog.d.ts +15 -0
  75. package/dist/src/ui/components/EditorSettingsDialog.js +73 -0
  76. package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -0
  77. package/dist/src/ui/components/Footer.d.ts +22 -0
  78. package/dist/src/ui/components/Footer.js +13 -0
  79. package/dist/src/ui/components/Footer.js.map +1 -0
  80. package/dist/src/ui/components/GeminiRespondingSpinner.d.ts +17 -0
  81. package/dist/src/ui/components/GeminiRespondingSpinner.js +16 -0
  82. package/dist/src/ui/components/GeminiRespondingSpinner.js.map +1 -0
  83. package/dist/src/ui/components/Header.d.ts +12 -0
  84. package/dist/src/ui/components/Header.js +20 -0
  85. package/dist/src/ui/components/Header.js.map +1 -0
  86. package/dist/src/ui/components/Help.d.ts +12 -0
  87. package/dist/src/ui/components/Help.js +7 -0
  88. package/dist/src/ui/components/Help.js.map +1 -0
  89. package/dist/src/ui/components/HistoryItemDisplay.d.ts +18 -0
  90. package/dist/src/ui/components/HistoryItemDisplay.js +15 -0
  91. package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -0
  92. package/dist/src/ui/components/HistoryItemDisplay.test.d.ts +6 -0
  93. package/dist/src/ui/components/HistoryItemDisplay.test.js +85 -0
  94. package/dist/src/ui/components/HistoryItemDisplay.test.js.map +1 -0
  95. package/dist/src/ui/components/InputPrompt.d.ts +24 -0
  96. package/dist/src/ui/components/InputPrompt.js +313 -0
  97. package/dist/src/ui/components/InputPrompt.js.map +1 -0
  98. package/dist/src/ui/components/InputPrompt.test.d.ts +6 -0
  99. package/dist/src/ui/components/InputPrompt.test.js +154 -0
  100. package/dist/src/ui/components/InputPrompt.test.js.map +1 -0
  101. package/dist/src/ui/components/LoadingIndicator.d.ts +15 -0
  102. package/dist/src/ui/components/LoadingIndicator.js +19 -0
  103. package/dist/src/ui/components/LoadingIndicator.js.map +1 -0
  104. package/dist/src/ui/components/LoadingIndicator.test.d.ts +6 -0
  105. package/dist/src/ui/components/LoadingIndicator.test.js +141 -0
  106. package/dist/src/ui/components/LoadingIndicator.test.js.map +1 -0
  107. package/dist/src/ui/components/MemoryUsageDisplay.d.ts +7 -0
  108. package/dist/src/ui/components/MemoryUsageDisplay.js +27 -0
  109. package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -0
  110. package/dist/src/ui/components/SessionSummaryDisplay.d.ts +13 -0
  111. package/dist/src/ui/components/SessionSummaryDisplay.js +20 -0
  112. package/dist/src/ui/components/SessionSummaryDisplay.js.map +1 -0
  113. package/dist/src/ui/components/SessionSummaryDisplay.test.d.ts +6 -0
  114. package/dist/src/ui/components/SessionSummaryDisplay.test.js +41 -0
  115. package/dist/src/ui/components/SessionSummaryDisplay.test.js.map +1 -0
  116. package/dist/src/ui/components/ShellModeIndicator.d.ts +7 -0
  117. package/dist/src/ui/components/ShellModeIndicator.js +5 -0
  118. package/dist/src/ui/components/ShellModeIndicator.js.map +1 -0
  119. package/dist/src/ui/components/ShowMoreLines.d.ts +10 -0
  120. package/dist/src/ui/components/ShowMoreLines.js +24 -0
  121. package/dist/src/ui/components/ShowMoreLines.js.map +1 -0
  122. package/dist/src/ui/components/Stats.d.ts +39 -0
  123. package/dist/src/ui/components/Stats.js +23 -0
  124. package/dist/src/ui/components/Stats.js.map +1 -0
  125. package/dist/src/ui/components/Stats.test.d.ts +6 -0
  126. package/dist/src/ui/components/Stats.test.js +57 -0
  127. package/dist/src/ui/components/Stats.test.js.map +1 -0
  128. package/dist/src/ui/components/StatsDisplay.d.ts +14 -0
  129. package/dist/src/ui/components/StatsDisplay.js +28 -0
  130. package/dist/src/ui/components/StatsDisplay.js.map +1 -0
  131. package/dist/src/ui/components/StatsDisplay.test.d.ts +6 -0
  132. package/dist/src/ui/components/StatsDisplay.test.js +51 -0
  133. package/dist/src/ui/components/StatsDisplay.test.js.map +1 -0
  134. package/dist/src/ui/components/SuggestionsDisplay.d.ts +21 -0
  135. package/dist/src/ui/components/SuggestionsDisplay.js +32 -0
  136. package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -0
  137. package/dist/src/ui/components/ThemeDialog.d.ts +19 -0
  138. package/dist/src/ui/components/ThemeDialog.js +126 -0
  139. package/dist/src/ui/components/ThemeDialog.js.map +1 -0
  140. package/dist/src/ui/components/Tips.d.ts +12 -0
  141. package/dist/src/ui/components/Tips.js +8 -0
  142. package/dist/src/ui/components/Tips.js.map +1 -0
  143. package/dist/src/ui/components/UpdateNotification.d.ts +10 -0
  144. package/dist/src/ui/components/UpdateNotification.js +10 -0
  145. package/dist/src/ui/components/UpdateNotification.js.map +1 -0
  146. package/dist/src/ui/components/messages/CompressionMessage.d.ts +11 -0
  147. package/dist/src/ui/components/messages/CompressionMessage.js +16 -0
  148. package/dist/src/ui/components/messages/CompressionMessage.js.map +1 -0
  149. package/dist/src/ui/components/messages/DiffRenderer.d.ts +15 -0
  150. package/dist/src/ui/components/messages/DiffRenderer.js +212 -0
  151. package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -0
  152. package/dist/src/ui/components/messages/DiffRenderer.test.d.ts +6 -0
  153. package/dist/src/ui/components/messages/DiffRenderer.test.js +239 -0
  154. package/dist/src/ui/components/messages/DiffRenderer.test.js.map +1 -0
  155. package/dist/src/ui/components/messages/ErrorMessage.d.ts +11 -0
  156. package/dist/src/ui/components/messages/ErrorMessage.js +9 -0
  157. package/dist/src/ui/components/messages/ErrorMessage.js.map +1 -0
  158. package/dist/src/ui/components/messages/GeminiMessage.d.ts +14 -0
  159. package/dist/src/ui/components/messages/GeminiMessage.js +10 -0
  160. package/dist/src/ui/components/messages/GeminiMessage.js.map +1 -0
  161. package/dist/src/ui/components/messages/GeminiMessageContent.d.ts +14 -0
  162. package/dist/src/ui/components/messages/GeminiMessageContent.js +15 -0
  163. package/dist/src/ui/components/messages/GeminiMessageContent.js.map +1 -0
  164. package/dist/src/ui/components/messages/InfoMessage.d.ts +11 -0
  165. package/dist/src/ui/components/messages/InfoMessage.js +9 -0
  166. package/dist/src/ui/components/messages/InfoMessage.js.map +1 -0
  167. package/dist/src/ui/components/messages/ToolConfirmationMessage.d.ts +15 -0
  168. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +111 -0
  169. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -0
  170. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.d.ts +6 -0
  171. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js +37 -0
  172. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js.map +1 -0
  173. package/dist/src/ui/components/messages/ToolGroupMessage.d.ts +18 -0
  174. package/dist/src/ui/components/messages/ToolGroupMessage.js +53 -0
  175. package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -0
  176. package/dist/src/ui/components/messages/ToolMessage.d.ts +15 -0
  177. package/dist/src/ui/components/messages/ToolMessage.js +61 -0
  178. package/dist/src/ui/components/messages/ToolMessage.js.map +1 -0
  179. package/dist/src/ui/components/messages/ToolMessage.test.d.ts +6 -0
  180. package/dist/src/ui/components/messages/ToolMessage.test.js +116 -0
  181. package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -0
  182. package/dist/src/ui/components/messages/UserMessage.d.ts +11 -0
  183. package/dist/src/ui/components/messages/UserMessage.js +9 -0
  184. package/dist/src/ui/components/messages/UserMessage.js.map +1 -0
  185. package/dist/src/ui/components/messages/UserShellMessage.d.ts +11 -0
  186. package/dist/src/ui/components/messages/UserShellMessage.js +9 -0
  187. package/dist/src/ui/components/messages/UserShellMessage.js.map +1 -0
  188. package/dist/src/ui/components/shared/MaxSizedBox.d.ts +61 -0
  189. package/dist/src/ui/components/shared/MaxSizedBox.js +383 -0
  190. package/dist/src/ui/components/shared/MaxSizedBox.js.map +1 -0
  191. package/dist/src/ui/components/shared/MaxSizedBox.test.d.ts +6 -0
  192. package/dist/src/ui/components/shared/MaxSizedBox.test.js +134 -0
  193. package/dist/src/ui/components/shared/MaxSizedBox.test.js.map +1 -0
  194. package/dist/src/ui/components/shared/RadioButtonSelect.d.ts +41 -0
  195. package/dist/src/ui/components/shared/RadioButtonSelect.js +52 -0
  196. package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -0
  197. package/dist/src/ui/components/shared/text-buffer.d.ts +121 -0
  198. package/dist/src/ui/components/shared/text-buffer.js +1147 -0
  199. package/dist/src/ui/components/shared/text-buffer.js.map +1 -0
  200. package/dist/src/ui/constants.d.ts +8 -0
  201. package/dist/src/ui/constants.js +12 -0
  202. package/dist/src/ui/constants.js.map +1 -0
  203. package/dist/src/ui/contexts/OverflowContext.d.ts +19 -0
  204. package/dist/src/ui/contexts/OverflowContext.js +43 -0
  205. package/dist/src/ui/contexts/OverflowContext.js.map +1 -0
  206. package/dist/src/ui/contexts/SessionContext.d.ts +35 -0
  207. package/dist/src/ui/contexts/SessionContext.js +132 -0
  208. package/dist/src/ui/contexts/SessionContext.js.map +1 -0
  209. package/dist/src/ui/contexts/SessionContext.test.d.ts +6 -0
  210. package/dist/src/ui/contexts/SessionContext.test.js +151 -0
  211. package/dist/src/ui/contexts/SessionContext.test.js.map +1 -0
  212. package/dist/src/ui/contexts/StreamingContext.d.ts +9 -0
  213. package/dist/src/ui/contexts/StreamingContext.js +15 -0
  214. package/dist/src/ui/contexts/StreamingContext.js.map +1 -0
  215. package/dist/src/ui/editors/editorSettingsManager.d.ts +19 -0
  216. package/dist/src/ui/editors/editorSettingsManager.js +50 -0
  217. package/dist/src/ui/editors/editorSettingsManager.js.map +1 -0
  218. package/dist/src/ui/hooks/atCommandProcessor.d.ts +31 -0
  219. package/dist/src/ui/hooks/atCommandProcessor.js +312 -0
  220. package/dist/src/ui/hooks/atCommandProcessor.js.map +1 -0
  221. package/dist/src/ui/hooks/shellCommandProcessor.d.ts +16 -0
  222. package/dist/src/ui/hooks/shellCommandProcessor.js +261 -0
  223. package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -0
  224. package/dist/src/ui/hooks/slashCommandProcessor.d.ts +31 -0
  225. package/dist/src/ui/hooks/slashCommandProcessor.js +922 -0
  226. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -0
  227. package/dist/src/ui/hooks/useAuthCommand.d.ts +15 -0
  228. package/dist/src/ui/hooks/useAuthCommand.js +65 -0
  229. package/dist/src/ui/hooks/useAuthCommand.js.map +1 -0
  230. package/dist/src/ui/hooks/useAutoAcceptIndicator.d.ts +10 -0
  231. package/dist/src/ui/hooks/useAutoAcceptIndicator.js +37 -0
  232. package/dist/src/ui/hooks/useAutoAcceptIndicator.js.map +1 -0
  233. package/dist/src/ui/hooks/useCompletion.d.ts +21 -0
  234. package/dist/src/ui/hooks/useCompletion.js +321 -0
  235. package/dist/src/ui/hooks/useCompletion.js.map +1 -0
  236. package/dist/src/ui/hooks/useConsoleMessages.d.ts +12 -0
  237. package/dist/src/ui/hooks/useConsoleMessages.js +59 -0
  238. package/dist/src/ui/hooks/useConsoleMessages.js.map +1 -0
  239. package/dist/src/ui/hooks/useEditorSettings.d.ts +16 -0
  240. package/dist/src/ui/hooks/useEditorSettings.js +43 -0
  241. package/dist/src/ui/hooks/useEditorSettings.js.map +1 -0
  242. package/dist/src/ui/hooks/useGeminiStream.d.ts +23 -0
  243. package/dist/src/ui/hooks/useGeminiStream.js +552 -0
  244. package/dist/src/ui/hooks/useGeminiStream.js.map +1 -0
  245. package/dist/src/ui/hooks/useGeminiStream.test.d.ts +6 -0
  246. package/dist/src/ui/hooks/useGeminiStream.test.js +823 -0
  247. package/dist/src/ui/hooks/useGeminiStream.test.js.map +1 -0
  248. package/dist/src/ui/hooks/useGitBranchName.d.ts +6 -0
  249. package/dist/src/ui/hooks/useGitBranchName.js +61 -0
  250. package/dist/src/ui/hooks/useGitBranchName.js.map +1 -0
  251. package/dist/src/ui/hooks/useHistoryManager.d.ts +22 -0
  252. package/dist/src/ui/hooks/useHistoryManager.js +72 -0
  253. package/dist/src/ui/hooks/useHistoryManager.js.map +1 -0
  254. package/dist/src/ui/hooks/useInputHistory.d.ts +19 -0
  255. package/dist/src/ui/hooks/useInputHistory.js +84 -0
  256. package/dist/src/ui/hooks/useInputHistory.js.map +1 -0
  257. package/dist/src/ui/hooks/useLoadingIndicator.d.ts +10 -0
  258. package/dist/src/ui/hooks/useLoadingIndicator.js +44 -0
  259. package/dist/src/ui/hooks/useLoadingIndicator.js.map +1 -0
  260. package/dist/src/ui/hooks/useLogger.d.ts +10 -0
  261. package/dist/src/ui/hooks/useLogger.js +29 -0
  262. package/dist/src/ui/hooks/useLogger.js.map +1 -0
  263. package/dist/src/ui/hooks/usePhraseCycler.d.ts +14 -0
  264. package/dist/src/ui/hooks/usePhraseCycler.js +189 -0
  265. package/dist/src/ui/hooks/usePhraseCycler.js.map +1 -0
  266. package/dist/src/ui/hooks/useReactToolScheduler.d.ts +33 -0
  267. package/dist/src/ui/hooks/useReactToolScheduler.js +186 -0
  268. package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -0
  269. package/dist/src/ui/hooks/useRefreshMemoryCommand.d.ts +6 -0
  270. package/dist/src/ui/hooks/useRefreshMemoryCommand.js +7 -0
  271. package/dist/src/ui/hooks/useRefreshMemoryCommand.js.map +1 -0
  272. package/dist/src/ui/hooks/useShellHistory.d.ts +11 -0
  273. package/dist/src/ui/hooks/useShellHistory.js +89 -0
  274. package/dist/src/ui/hooks/useShellHistory.js.map +1 -0
  275. package/dist/src/ui/hooks/useShowMemoryCommand.d.ts +9 -0
  276. package/dist/src/ui/hooks/useShowMemoryCommand.js +58 -0
  277. package/dist/src/ui/hooks/useShowMemoryCommand.js.map +1 -0
  278. package/dist/src/ui/hooks/useStateAndRef.d.ts +7 -0
  279. package/dist/src/ui/hooks/useStateAndRef.js +26 -0
  280. package/dist/src/ui/hooks/useStateAndRef.js.map +1 -0
  281. package/dist/src/ui/hooks/useTerminalSize.d.ts +9 -0
  282. package/dist/src/ui/hooks/useTerminalSize.js +27 -0
  283. package/dist/src/ui/hooks/useTerminalSize.js.map +1 -0
  284. package/dist/src/ui/hooks/useThemeCommand.d.ts +15 -0
  285. package/dist/src/ui/hooks/useThemeCommand.js +78 -0
  286. package/dist/src/ui/hooks/useThemeCommand.js.map +1 -0
  287. package/dist/src/ui/hooks/useTimer.d.ts +12 -0
  288. package/dist/src/ui/hooks/useTimer.js +58 -0
  289. package/dist/src/ui/hooks/useTimer.js.map +1 -0
  290. package/dist/src/ui/themes/ansi-light.d.ts +7 -0
  291. package/dist/src/ui/themes/ansi-light.js +139 -0
  292. package/dist/src/ui/themes/ansi-light.js.map +1 -0
  293. package/dist/src/ui/themes/ansi.d.ts +7 -0
  294. package/dist/src/ui/themes/ansi.js +149 -0
  295. package/dist/src/ui/themes/ansi.js.map +1 -0
  296. package/dist/src/ui/themes/atom-one-dark.d.ts +7 -0
  297. package/dist/src/ui/themes/atom-one-dark.js +136 -0
  298. package/dist/src/ui/themes/atom-one-dark.js.map +1 -0
  299. package/dist/src/ui/themes/ayu-light.d.ts +7 -0
  300. package/dist/src/ui/themes/ayu-light.js +128 -0
  301. package/dist/src/ui/themes/ayu-light.js.map +1 -0
  302. package/dist/src/ui/themes/ayu.d.ts +7 -0
  303. package/dist/src/ui/themes/ayu.js +102 -0
  304. package/dist/src/ui/themes/ayu.js.map +1 -0
  305. package/dist/src/ui/themes/default-light.d.ts +7 -0
  306. package/dist/src/ui/themes/default-light.js +100 -0
  307. package/dist/src/ui/themes/default-light.js.map +1 -0
  308. package/dist/src/ui/themes/default.d.ts +7 -0
  309. package/dist/src/ui/themes/default.js +143 -0
  310. package/dist/src/ui/themes/default.js.map +1 -0
  311. package/dist/src/ui/themes/dracula.d.ts +7 -0
  312. package/dist/src/ui/themes/dracula.js +113 -0
  313. package/dist/src/ui/themes/dracula.js.map +1 -0
  314. package/dist/src/ui/themes/github-dark.d.ts +7 -0
  315. package/dist/src/ui/themes/github-dark.js +136 -0
  316. package/dist/src/ui/themes/github-dark.js.map +1 -0
  317. package/dist/src/ui/themes/github-light.d.ts +7 -0
  318. package/dist/src/ui/themes/github-light.js +138 -0
  319. package/dist/src/ui/themes/github-light.js.map +1 -0
  320. package/dist/src/ui/themes/googlecode.d.ts +7 -0
  321. package/dist/src/ui/themes/googlecode.js +135 -0
  322. package/dist/src/ui/themes/googlecode.js.map +1 -0
  323. package/dist/src/ui/themes/no-color.d.ts +7 -0
  324. package/dist/src/ui/themes/no-color.js +84 -0
  325. package/dist/src/ui/themes/no-color.js.map +1 -0
  326. package/dist/src/ui/themes/theme-manager.d.ts +33 -0
  327. package/dist/src/ui/themes/theme-manager.js +107 -0
  328. package/dist/src/ui/themes/theme-manager.js.map +1 -0
  329. package/dist/src/ui/themes/theme.d.ts +67 -0
  330. package/dist/src/ui/themes/theme.js +304 -0
  331. package/dist/src/ui/themes/theme.js.map +1 -0
  332. package/dist/src/ui/themes/xcode.d.ts +7 -0
  333. package/dist/src/ui/themes/xcode.js +143 -0
  334. package/dist/src/ui/themes/xcode.js.map +1 -0
  335. package/dist/src/ui/types.d.ts +149 -0
  336. package/dist/src/ui/types.js +41 -0
  337. package/dist/src/ui/types.js.map +1 -0
  338. package/dist/src/ui/utils/CodeColorizer.d.ts +14 -0
  339. package/dist/src/ui/utils/CodeColorizer.js +97 -0
  340. package/dist/src/ui/utils/CodeColorizer.js.map +1 -0
  341. package/dist/src/ui/utils/MarkdownDisplay.d.ts +14 -0
  342. package/dist/src/ui/utils/MarkdownDisplay.js +221 -0
  343. package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -0
  344. package/dist/src/ui/utils/commandUtils.d.ts +22 -0
  345. package/dist/src/ui/utils/commandUtils.js +25 -0
  346. package/dist/src/ui/utils/commandUtils.js.map +1 -0
  347. package/dist/src/ui/utils/errorParsing.d.ts +15 -0
  348. package/dist/src/ui/utils/errorParsing.js +80 -0
  349. package/dist/src/ui/utils/errorParsing.js.map +1 -0
  350. package/dist/src/ui/utils/formatters.d.ts +13 -0
  351. package/dist/src/ui/utils/formatters.js +56 -0
  352. package/dist/src/ui/utils/formatters.js.map +1 -0
  353. package/dist/src/ui/utils/markdownUtilities.d.ts +6 -0
  354. package/dist/src/ui/utils/markdownUtilities.js +110 -0
  355. package/dist/src/ui/utils/markdownUtilities.js.map +1 -0
  356. package/dist/src/ui/utils/textUtils.d.ts +22 -0
  357. package/dist/src/ui/utils/textUtils.js +58 -0
  358. package/dist/src/ui/utils/textUtils.js.map +1 -0
  359. package/dist/src/ui/utils/updateCheck.d.ts +6 -0
  360. package/dist/src/ui/utils/updateCheck.js +34 -0
  361. package/dist/src/ui/utils/updateCheck.js.map +1 -0
  362. package/dist/src/utils/cleanup.d.ts +6 -0
  363. package/dist/src/utils/cleanup.js +19 -0
  364. package/dist/src/utils/cleanup.js.map +1 -0
  365. package/dist/src/utils/package.d.ts +12 -0
  366. package/dist/src/utils/package.js +24 -0
  367. package/dist/src/utils/package.js.map +1 -0
  368. package/dist/src/utils/readStdin.d.ts +6 -0
  369. package/dist/src/utils/readStdin.js +34 -0
  370. package/dist/src/utils/readStdin.js.map +1 -0
  371. package/dist/src/utils/sandbox.d.ts +7 -0
  372. package/dist/src/utils/sandbox.js +680 -0
  373. package/dist/src/utils/sandbox.js.map +1 -0
  374. package/dist/src/utils/startupWarnings.d.ts +6 -0
  375. package/dist/src/utils/startupWarnings.js +40 -0
  376. package/dist/src/utils/startupWarnings.js.map +1 -0
  377. package/dist/src/utils/version.d.ts +6 -0
  378. package/dist/src/utils/version.js +11 -0
  379. package/dist/src/utils/version.js.map +1 -0
  380. package/dist/tsconfig.tsbuildinfo +1 -0
  381. package/package.json +63 -71
  382. package/LICENSE +0 -202
  383. package/bundle/gemini.js +0 -257368
  384. package/bundle/shell.json +0 -18
  385. package/bundle/shell.md +0 -16
  386. /package/{bundle → dist/src/utils}/sandbox-macos-permissive-closed.sb +0 -0
  387. /package/{bundle → dist/src/utils}/sandbox-macos-permissive-open.sb +0 -0
  388. /package/{bundle → dist/src/utils}/sandbox-macos-permissive-proxied.sb +0 -0
  389. /package/{bundle → dist/src/utils}/sandbox-macos-restrictive-closed.sb +0 -0
  390. /package/{bundle → dist/src/utils}/sandbox-macos-restrictive-open.sb +0 -0
  391. /package/{bundle → dist/src/utils}/sandbox-macos-restrictive-proxied.sb +0 -0
@@ -0,0 +1,823 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
7
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
8
+ import { renderHook, act, waitFor } from '@testing-library/react';
9
+ import { useGeminiStream, mergePartListUnions } from './useGeminiStream.js';
10
+ import { useInput } from 'ink';
11
+ import { useReactToolScheduler, } from './useReactToolScheduler.js';
12
+ import { AuthType } from '@google/gemini-cli-core';
13
+ import { MessageType, StreamingState } from '../types.js';
14
+ // --- MOCKS ---
15
+ const mockSendMessageStream = vi
16
+ .fn()
17
+ .mockReturnValue((async function* () { })());
18
+ const mockStartChat = vi.fn();
19
+ const MockedGeminiClientClass = vi.hoisted(() => vi.fn().mockImplementation(function (_config) {
20
+ // _config
21
+ this.startChat = mockStartChat;
22
+ this.sendMessageStream = mockSendMessageStream;
23
+ this.addHistory = vi.fn();
24
+ }));
25
+ const MockedUserPromptEvent = vi.hoisted(() => vi.fn().mockImplementation(() => { }));
26
+ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
27
+ const actualCoreModule = (await importOriginal());
28
+ return {
29
+ ...actualCoreModule,
30
+ GitService: vi.fn(),
31
+ GeminiClient: MockedGeminiClientClass,
32
+ UserPromptEvent: MockedUserPromptEvent,
33
+ };
34
+ });
35
+ const mockUseReactToolScheduler = useReactToolScheduler;
36
+ vi.mock('./useReactToolScheduler.js', async (importOriginal) => {
37
+ const actualSchedulerModule = (await importOriginal());
38
+ return {
39
+ ...(actualSchedulerModule || {}),
40
+ useReactToolScheduler: vi.fn(),
41
+ };
42
+ });
43
+ vi.mock('ink', async (importOriginal) => {
44
+ const actualInkModule = (await importOriginal());
45
+ return { ...(actualInkModule || {}), useInput: vi.fn() };
46
+ });
47
+ vi.mock('./shellCommandProcessor.js', () => ({
48
+ useShellCommandProcessor: vi.fn().mockReturnValue({
49
+ handleShellCommand: vi.fn(),
50
+ }),
51
+ }));
52
+ vi.mock('./atCommandProcessor.js', () => ({
53
+ handleAtCommand: vi
54
+ .fn()
55
+ .mockResolvedValue({ shouldProceed: true, processedQuery: 'mocked' }),
56
+ }));
57
+ vi.mock('../utils/markdownUtilities.js', () => ({
58
+ findLastSafeSplitPoint: vi.fn((s) => s.length),
59
+ }));
60
+ vi.mock('./useStateAndRef.js', () => ({
61
+ useStateAndRef: vi.fn((initial) => {
62
+ let val = initial;
63
+ const ref = { current: val };
64
+ const setVal = vi.fn((updater) => {
65
+ if (typeof updater === 'function') {
66
+ val = updater(val);
67
+ }
68
+ else {
69
+ val = updater;
70
+ }
71
+ ref.current = val;
72
+ });
73
+ return [ref, setVal];
74
+ }),
75
+ }));
76
+ vi.mock('./useLogger.js', () => ({
77
+ useLogger: vi.fn().mockReturnValue({
78
+ logMessage: vi.fn().mockResolvedValue(undefined),
79
+ }),
80
+ }));
81
+ const mockStartNewTurn = vi.fn();
82
+ const mockAddUsage = vi.fn();
83
+ vi.mock('../contexts/SessionContext.js', () => ({
84
+ useSessionStats: vi.fn(() => ({
85
+ startNewTurn: mockStartNewTurn,
86
+ addUsage: mockAddUsage,
87
+ })),
88
+ }));
89
+ vi.mock('./slashCommandProcessor.js', () => ({
90
+ handleSlashCommand: vi.fn().mockReturnValue(false),
91
+ }));
92
+ const mockParseAndFormatApiError = vi.hoisted(() => vi.fn());
93
+ vi.mock('../utils/errorParsing.js', () => ({
94
+ parseAndFormatApiError: mockParseAndFormatApiError,
95
+ }));
96
+ // --- END MOCKS ---
97
+ describe('mergePartListUnions', () => {
98
+ it('should merge multiple PartListUnion arrays', () => {
99
+ const list1 = [{ text: 'Hello' }];
100
+ const list2 = [
101
+ { inlineData: { mimeType: 'image/png', data: 'abc' } },
102
+ ];
103
+ const list3 = [{ text: 'World' }, { text: '!' }];
104
+ const result = mergePartListUnions([list1, list2, list3]);
105
+ expect(result).toEqual([
106
+ { text: 'Hello' },
107
+ { inlineData: { mimeType: 'image/png', data: 'abc' } },
108
+ { text: 'World' },
109
+ { text: '!' },
110
+ ]);
111
+ });
112
+ it('should handle empty arrays in the input list', () => {
113
+ const list1 = [{ text: 'First' }];
114
+ const list2 = [];
115
+ const list3 = [{ text: 'Last' }];
116
+ const result = mergePartListUnions([list1, list2, list3]);
117
+ expect(result).toEqual([{ text: 'First' }, { text: 'Last' }]);
118
+ });
119
+ it('should handle a single PartListUnion array', () => {
120
+ const list1 = [
121
+ { text: 'One' },
122
+ { inlineData: { mimeType: 'image/jpeg', data: 'xyz' } },
123
+ ];
124
+ const result = mergePartListUnions([list1]);
125
+ expect(result).toEqual(list1);
126
+ });
127
+ it('should return an empty array if all input arrays are empty', () => {
128
+ const list1 = [];
129
+ const list2 = [];
130
+ const result = mergePartListUnions([list1, list2]);
131
+ expect(result).toEqual([]);
132
+ });
133
+ it('should handle input list being empty', () => {
134
+ const result = mergePartListUnions([]);
135
+ expect(result).toEqual([]);
136
+ });
137
+ it('should correctly merge when PartListUnion items are single Parts not in arrays', () => {
138
+ const part1 = { text: 'Single part 1' };
139
+ const part2 = { inlineData: { mimeType: 'image/gif', data: 'gif' } };
140
+ const listContainingSingleParts = [
141
+ part1,
142
+ [part2],
143
+ { text: 'Another single part' },
144
+ ];
145
+ const result = mergePartListUnions(listContainingSingleParts);
146
+ expect(result).toEqual([
147
+ { text: 'Single part 1' },
148
+ { inlineData: { mimeType: 'image/gif', data: 'gif' } },
149
+ { text: 'Another single part' },
150
+ ]);
151
+ });
152
+ it('should handle a mix of arrays and single parts, including empty arrays and undefined/null parts if they were possible (though PartListUnion typing restricts this)', () => {
153
+ const list1 = [{ text: 'A' }];
154
+ const list2 = [];
155
+ const part3 = { text: 'B' };
156
+ const list4 = [
157
+ { text: 'C' },
158
+ { inlineData: { mimeType: 'text/plain', data: 'D' } },
159
+ ];
160
+ const result = mergePartListUnions([list1, list2, part3, list4]);
161
+ expect(result).toEqual([
162
+ { text: 'A' },
163
+ { text: 'B' },
164
+ { text: 'C' },
165
+ { inlineData: { mimeType: 'text/plain', data: 'D' } },
166
+ ]);
167
+ });
168
+ it('should preserve the order of parts from the input arrays', () => {
169
+ const listA = [{ text: '1' }, { text: '2' }];
170
+ const listB = [{ text: '3' }];
171
+ const listC = [{ text: '4' }, { text: '5' }];
172
+ const result = mergePartListUnions([listA, listB, listC]);
173
+ expect(result).toEqual([
174
+ { text: '1' },
175
+ { text: '2' },
176
+ { text: '3' },
177
+ { text: '4' },
178
+ { text: '5' },
179
+ ]);
180
+ });
181
+ it('should handle cases where some PartListUnion items are single Parts and others are arrays of Parts', () => {
182
+ const singlePart1 = { text: 'First single' };
183
+ const arrayPart1 = [
184
+ { text: 'Array item 1' },
185
+ { text: 'Array item 2' },
186
+ ];
187
+ const singlePart2 = {
188
+ inlineData: { mimeType: 'application/json', data: 'e30=' },
189
+ }; // {}
190
+ const arrayPart2 = [{ text: 'Last array item' }];
191
+ const result = mergePartListUnions([
192
+ singlePart1,
193
+ arrayPart1,
194
+ singlePart2,
195
+ arrayPart2,
196
+ ]);
197
+ expect(result).toEqual([
198
+ { text: 'First single' },
199
+ { text: 'Array item 1' },
200
+ { text: 'Array item 2' },
201
+ { inlineData: { mimeType: 'application/json', data: 'e30=' } },
202
+ { text: 'Last array item' },
203
+ ]);
204
+ });
205
+ });
206
+ // --- Tests for useGeminiStream Hook ---
207
+ describe('useGeminiStream', () => {
208
+ let mockAddItem;
209
+ let mockSetShowHelp;
210
+ let mockConfig;
211
+ let mockOnDebugMessage;
212
+ let mockHandleSlashCommand;
213
+ let mockScheduleToolCalls;
214
+ let mockCancelAllToolCalls;
215
+ let mockMarkToolsAsSubmitted;
216
+ beforeEach(() => {
217
+ vi.clearAllMocks(); // Clear mocks before each test
218
+ mockAddItem = vi.fn();
219
+ mockSetShowHelp = vi.fn();
220
+ // Define the mock for getGeminiClient
221
+ const mockGetGeminiClient = vi.fn().mockImplementation(() => {
222
+ // MockedGeminiClientClass is defined in the module scope by the previous change.
223
+ // It will use the mockStartChat and mockSendMessageStream that are managed within beforeEach.
224
+ const clientInstance = new MockedGeminiClientClass(mockConfig);
225
+ return clientInstance;
226
+ });
227
+ mockConfig = {
228
+ apiKey: 'test-api-key',
229
+ model: 'gemini-pro',
230
+ sandbox: false,
231
+ targetDir: '/test/dir',
232
+ debugMode: false,
233
+ question: undefined,
234
+ fullContext: false,
235
+ coreTools: [],
236
+ toolDiscoveryCommand: undefined,
237
+ toolCallCommand: undefined,
238
+ mcpServerCommand: undefined,
239
+ mcpServers: undefined,
240
+ userAgent: 'test-agent',
241
+ userMemory: '',
242
+ geminiMdFileCount: 0,
243
+ alwaysSkipModificationConfirmation: false,
244
+ vertexai: false,
245
+ showMemoryUsage: false,
246
+ contextFileName: undefined,
247
+ getToolRegistry: vi.fn(() => ({ getToolSchemaList: vi.fn(() => []) })),
248
+ getProjectRoot: vi.fn(() => '/test/dir'),
249
+ getCheckpointingEnabled: vi.fn(() => false),
250
+ getGeminiClient: mockGetGeminiClient,
251
+ getUsageStatisticsEnabled: () => true,
252
+ getDebugMode: () => false,
253
+ addHistory: vi.fn(),
254
+ };
255
+ mockOnDebugMessage = vi.fn();
256
+ mockHandleSlashCommand = vi.fn().mockResolvedValue(false);
257
+ // Mock return value for useReactToolScheduler
258
+ mockScheduleToolCalls = vi.fn();
259
+ mockCancelAllToolCalls = vi.fn();
260
+ mockMarkToolsAsSubmitted = vi.fn();
261
+ // Default mock for useReactToolScheduler to prevent toolCalls being undefined initially
262
+ mockUseReactToolScheduler.mockReturnValue([
263
+ [], // Default to empty array for toolCalls
264
+ mockScheduleToolCalls,
265
+ mockCancelAllToolCalls,
266
+ mockMarkToolsAsSubmitted,
267
+ ]);
268
+ // Reset mocks for GeminiClient instance methods (startChat and sendMessageStream)
269
+ // The GeminiClient constructor itself is mocked at the module level.
270
+ mockStartChat.mockClear().mockResolvedValue({
271
+ sendMessageStream: mockSendMessageStream,
272
+ }); // GeminiChat -> any
273
+ mockSendMessageStream
274
+ .mockClear()
275
+ .mockReturnValue((async function* () { })());
276
+ });
277
+ const mockLoadedSettings = {
278
+ merged: { preferredEditor: 'vscode' },
279
+ user: { path: '/user/settings.json', settings: {} },
280
+ workspace: { path: '/workspace/.gemini/settings.json', settings: {} },
281
+ errors: [],
282
+ forScope: vi.fn(),
283
+ setValue: vi.fn(),
284
+ };
285
+ const renderTestHook = (initialToolCalls = [], geminiClient) => {
286
+ let currentToolCalls = initialToolCalls;
287
+ const setToolCalls = (newToolCalls) => {
288
+ currentToolCalls = newToolCalls;
289
+ };
290
+ mockUseReactToolScheduler.mockImplementation(() => [
291
+ currentToolCalls,
292
+ mockScheduleToolCalls,
293
+ mockCancelAllToolCalls,
294
+ mockMarkToolsAsSubmitted,
295
+ ]);
296
+ const client = geminiClient || mockConfig.getGeminiClient();
297
+ const { result, rerender } = renderHook((props) => {
298
+ // Update the mock's return value if new toolCalls are passed in props
299
+ if (props.toolCalls) {
300
+ setToolCalls(props.toolCalls);
301
+ }
302
+ return useGeminiStream(props.client, props.history, props.addItem, props.setShowHelp, props.config, props.onDebugMessage, props.handleSlashCommand, props.shellModeActive, () => 'vscode', () => { }, () => Promise.resolve());
303
+ }, {
304
+ initialProps: {
305
+ client,
306
+ history: [],
307
+ addItem: mockAddItem,
308
+ setShowHelp: mockSetShowHelp,
309
+ config: mockConfig,
310
+ onDebugMessage: mockOnDebugMessage,
311
+ handleSlashCommand: mockHandleSlashCommand,
312
+ shellModeActive: false,
313
+ loadedSettings: mockLoadedSettings,
314
+ toolCalls: initialToolCalls,
315
+ },
316
+ });
317
+ return {
318
+ result,
319
+ rerender,
320
+ mockMarkToolsAsSubmitted,
321
+ mockSendMessageStream,
322
+ client,
323
+ };
324
+ };
325
+ it('should not submit tool responses if not all tool calls are completed', () => {
326
+ const toolCalls = [
327
+ {
328
+ request: {
329
+ callId: 'call1',
330
+ name: 'tool1',
331
+ args: {},
332
+ isClientInitiated: false,
333
+ },
334
+ status: 'success',
335
+ responseSubmittedToGemini: false,
336
+ response: {
337
+ callId: 'call1',
338
+ responseParts: [{ text: 'tool 1 response' }],
339
+ error: undefined,
340
+ resultDisplay: 'Tool 1 success display',
341
+ },
342
+ tool: {
343
+ name: 'tool1',
344
+ description: 'desc1',
345
+ getDescription: vi.fn(),
346
+ },
347
+ startTime: Date.now(),
348
+ endTime: Date.now(),
349
+ },
350
+ {
351
+ request: { callId: 'call2', name: 'tool2', args: {} },
352
+ status: 'executing',
353
+ responseSubmittedToGemini: false,
354
+ tool: {
355
+ name: 'tool2',
356
+ description: 'desc2',
357
+ getDescription: vi.fn(),
358
+ },
359
+ startTime: Date.now(),
360
+ liveOutput: '...',
361
+ },
362
+ ];
363
+ const { mockMarkToolsAsSubmitted, mockSendMessageStream } = renderTestHook(toolCalls);
364
+ // Effect for submitting tool responses depends on toolCalls and isResponding
365
+ // isResponding is initially false, so the effect should run.
366
+ expect(mockMarkToolsAsSubmitted).not.toHaveBeenCalled();
367
+ expect(mockSendMessageStream).not.toHaveBeenCalled(); // submitQuery uses this
368
+ });
369
+ it('should submit tool responses when all tool calls are completed and ready', async () => {
370
+ const toolCall1ResponseParts = [
371
+ { text: 'tool 1 final response' },
372
+ ];
373
+ const toolCall2ResponseParts = [
374
+ { text: 'tool 2 final response' },
375
+ ];
376
+ const completedToolCalls = [
377
+ {
378
+ request: {
379
+ callId: 'call1',
380
+ name: 'tool1',
381
+ args: {},
382
+ isClientInitiated: false,
383
+ },
384
+ status: 'success',
385
+ responseSubmittedToGemini: false,
386
+ response: { callId: 'call1', responseParts: toolCall1ResponseParts },
387
+ },
388
+ {
389
+ request: {
390
+ callId: 'call2',
391
+ name: 'tool2',
392
+ args: {},
393
+ isClientInitiated: false,
394
+ },
395
+ status: 'error',
396
+ responseSubmittedToGemini: false,
397
+ response: { callId: 'call2', responseParts: toolCall2ResponseParts },
398
+ },
399
+ ];
400
+ // 1. On the first render, there are no tool calls.
401
+ mockUseReactToolScheduler.mockReturnValue([
402
+ [],
403
+ mockScheduleToolCalls,
404
+ mockMarkToolsAsSubmitted,
405
+ ]);
406
+ const { rerender } = renderHook(() => useGeminiStream(new MockedGeminiClientClass(mockConfig), [], mockAddItem, mockSetShowHelp, mockConfig, mockOnDebugMessage, mockHandleSlashCommand, false, () => 'vscode', () => { }, () => Promise.resolve()));
407
+ // 2. Before the second render, change the mock to return the completed tools.
408
+ mockUseReactToolScheduler.mockReturnValue([
409
+ completedToolCalls,
410
+ mockScheduleToolCalls,
411
+ mockMarkToolsAsSubmitted,
412
+ ]);
413
+ // 3. Trigger a re-render. The hook will now receive the completed tools, causing the effect to run.
414
+ act(() => {
415
+ rerender();
416
+ });
417
+ await waitFor(() => {
418
+ expect(mockMarkToolsAsSubmitted).toHaveBeenCalledTimes(1);
419
+ expect(mockSendMessageStream).toHaveBeenCalledTimes(1);
420
+ });
421
+ const expectedMergedResponse = mergePartListUnions([
422
+ toolCall1ResponseParts,
423
+ toolCall2ResponseParts,
424
+ ]);
425
+ expect(mockSendMessageStream).toHaveBeenCalledWith(expectedMergedResponse, expect.any(AbortSignal));
426
+ });
427
+ it('should handle all tool calls being cancelled', async () => {
428
+ const cancelledToolCalls = [
429
+ {
430
+ request: {
431
+ callId: '1',
432
+ name: 'testTool',
433
+ args: {},
434
+ isClientInitiated: false,
435
+ },
436
+ status: 'cancelled',
437
+ response: { callId: '1', responseParts: [{ text: 'cancelled' }] },
438
+ responseSubmittedToGemini: false,
439
+ },
440
+ ];
441
+ const client = new MockedGeminiClientClass(mockConfig);
442
+ // 1. First render: no tool calls.
443
+ mockUseReactToolScheduler.mockReturnValue([
444
+ [],
445
+ mockScheduleToolCalls,
446
+ mockMarkToolsAsSubmitted,
447
+ ]);
448
+ const { rerender } = renderHook(() => useGeminiStream(client, [], mockAddItem, mockSetShowHelp, mockConfig, mockOnDebugMessage, mockHandleSlashCommand, false, () => 'vscode', () => { }, () => Promise.resolve()));
449
+ // 2. Second render: tool calls are now cancelled.
450
+ mockUseReactToolScheduler.mockReturnValue([
451
+ cancelledToolCalls,
452
+ mockScheduleToolCalls,
453
+ mockMarkToolsAsSubmitted,
454
+ ]);
455
+ // 3. Trigger the re-render.
456
+ act(() => {
457
+ rerender();
458
+ });
459
+ await waitFor(() => {
460
+ expect(mockMarkToolsAsSubmitted).toHaveBeenCalledWith(['1']);
461
+ expect(client.addHistory).toHaveBeenCalledWith({
462
+ role: 'user',
463
+ parts: [{ text: 'cancelled' }],
464
+ });
465
+ // Ensure we do NOT call back to the API
466
+ expect(mockSendMessageStream).not.toHaveBeenCalled();
467
+ });
468
+ });
469
+ describe('Session Stats Integration', () => {
470
+ it('should call startNewTurn and addUsage for a simple prompt', async () => {
471
+ const mockMetadata = { totalTokenCount: 123 };
472
+ const mockStream = (async function* () {
473
+ yield { type: 'content', value: 'Response' };
474
+ yield { type: 'usage_metadata', value: mockMetadata };
475
+ })();
476
+ mockSendMessageStream.mockReturnValue(mockStream);
477
+ const { result } = renderTestHook();
478
+ await act(async () => {
479
+ await result.current.submitQuery('Hello, world!');
480
+ });
481
+ expect(mockStartNewTurn).toHaveBeenCalledTimes(1);
482
+ expect(mockAddUsage).toHaveBeenCalledTimes(1);
483
+ expect(mockAddUsage).toHaveBeenCalledWith(mockMetadata);
484
+ });
485
+ it('should only call addUsage for a tool continuation prompt', async () => {
486
+ const mockMetadata = { totalTokenCount: 456 };
487
+ const mockStream = (async function* () {
488
+ yield { type: 'content', value: 'Final Answer' };
489
+ yield { type: 'usage_metadata', value: mockMetadata };
490
+ })();
491
+ mockSendMessageStream.mockReturnValue(mockStream);
492
+ const { result } = renderTestHook();
493
+ await act(async () => {
494
+ await result.current.submitQuery([{ text: 'tool response' }], {
495
+ isContinuation: true,
496
+ });
497
+ });
498
+ expect(mockStartNewTurn).not.toHaveBeenCalled();
499
+ expect(mockAddUsage).toHaveBeenCalledTimes(1);
500
+ expect(mockAddUsage).toHaveBeenCalledWith(mockMetadata);
501
+ });
502
+ it('should not call addUsage if the stream contains no usage metadata', async () => {
503
+ // Arrange: A stream that yields content but never a usage_metadata event
504
+ const mockStream = (async function* () {
505
+ yield { type: 'content', value: 'Some response text' };
506
+ })();
507
+ mockSendMessageStream.mockReturnValue(mockStream);
508
+ const { result } = renderTestHook();
509
+ await act(async () => {
510
+ await result.current.submitQuery('Query with no usage data');
511
+ });
512
+ expect(mockStartNewTurn).toHaveBeenCalledTimes(1);
513
+ expect(mockAddUsage).not.toHaveBeenCalled();
514
+ });
515
+ it('should not call startNewTurn for a slash command', async () => {
516
+ mockHandleSlashCommand.mockReturnValue(true);
517
+ const { result } = renderTestHook();
518
+ await act(async () => {
519
+ await result.current.submitQuery('/stats');
520
+ });
521
+ expect(mockStartNewTurn).not.toHaveBeenCalled();
522
+ expect(mockSendMessageStream).not.toHaveBeenCalled();
523
+ });
524
+ });
525
+ it('should not flicker streaming state to Idle between tool completion and submission', async () => {
526
+ const toolCallResponseParts = [
527
+ { text: 'tool 1 final response' },
528
+ ];
529
+ const initialToolCalls = [
530
+ {
531
+ request: { callId: 'call1', name: 'tool1', args: {} },
532
+ status: 'executing',
533
+ responseSubmittedToGemini: false,
534
+ tool: {
535
+ name: 'tool1',
536
+ description: 'desc',
537
+ getDescription: vi.fn(),
538
+ },
539
+ startTime: Date.now(),
540
+ },
541
+ ];
542
+ const completedToolCalls = [
543
+ {
544
+ ...initialToolCalls[0],
545
+ status: 'success',
546
+ response: {
547
+ callId: 'call1',
548
+ responseParts: toolCallResponseParts,
549
+ error: undefined,
550
+ resultDisplay: 'Tool 1 success display',
551
+ },
552
+ endTime: Date.now(),
553
+ },
554
+ ];
555
+ const { result, rerender, client } = renderTestHook(initialToolCalls);
556
+ // 1. Initial state should be Responding because a tool is executing.
557
+ expect(result.current.streamingState).toBe(StreamingState.Responding);
558
+ // 2. Rerender with the completed tool call.
559
+ // The useEffect should pick this up but hasn't called submitQuery yet.
560
+ act(() => {
561
+ rerender({
562
+ client,
563
+ history: [],
564
+ addItem: mockAddItem,
565
+ setShowHelp: mockSetShowHelp,
566
+ config: mockConfig,
567
+ onDebugMessage: mockOnDebugMessage,
568
+ handleSlashCommand: mockHandleSlashCommand,
569
+ shellModeActive: false,
570
+ loadedSettings: mockLoadedSettings,
571
+ // This is the key part of the test: update the toolCalls array
572
+ // to simulate the tool finishing.
573
+ toolCalls: completedToolCalls,
574
+ });
575
+ });
576
+ // 3. The state should *still* be Responding, not Idle.
577
+ // This is because the completed tool's response has not been submitted yet.
578
+ expect(result.current.streamingState).toBe(StreamingState.Responding);
579
+ // 4. Wait for the useEffect to call submitQuery.
580
+ await waitFor(() => {
581
+ expect(mockSendMessageStream).toHaveBeenCalledWith(toolCallResponseParts, expect.any(AbortSignal));
582
+ });
583
+ // 5. After submission, the state should remain Responding.
584
+ expect(result.current.streamingState).toBe(StreamingState.Responding);
585
+ });
586
+ describe('User Cancellation', () => {
587
+ let useInputCallback;
588
+ const mockUseInput = useInput;
589
+ beforeEach(() => {
590
+ // Capture the callback passed to useInput
591
+ mockUseInput.mockImplementation((callback) => {
592
+ useInputCallback = callback;
593
+ });
594
+ });
595
+ const simulateEscapeKeyPress = () => {
596
+ act(() => {
597
+ useInputCallback('', { escape: true });
598
+ });
599
+ };
600
+ it('should cancel an in-progress stream when escape is pressed', async () => {
601
+ const mockStream = (async function* () {
602
+ yield { type: 'content', value: 'Part 1' };
603
+ // Keep the stream open
604
+ await new Promise(() => { });
605
+ })();
606
+ mockSendMessageStream.mockReturnValue(mockStream);
607
+ const { result } = renderTestHook();
608
+ // Start a query
609
+ await act(async () => {
610
+ result.current.submitQuery('test query');
611
+ });
612
+ // Wait for the first part of the response
613
+ await waitFor(() => {
614
+ expect(result.current.streamingState).toBe(StreamingState.Responding);
615
+ });
616
+ // Simulate escape key press
617
+ simulateEscapeKeyPress();
618
+ // Verify cancellation message is added
619
+ await waitFor(() => {
620
+ expect(mockAddItem).toHaveBeenCalledWith({
621
+ type: MessageType.INFO,
622
+ text: 'Request cancelled.',
623
+ }, expect.any(Number));
624
+ });
625
+ // Verify state is reset
626
+ expect(result.current.streamingState).toBe(StreamingState.Idle);
627
+ });
628
+ it('should not do anything if escape is pressed when not responding', () => {
629
+ const { result } = renderTestHook();
630
+ expect(result.current.streamingState).toBe(StreamingState.Idle);
631
+ // Simulate escape key press
632
+ simulateEscapeKeyPress();
633
+ // No change should happen, no cancellation message
634
+ expect(mockAddItem).not.toHaveBeenCalledWith(expect.objectContaining({
635
+ text: 'Request cancelled.',
636
+ }), expect.any(Number));
637
+ });
638
+ it('should prevent further processing after cancellation', async () => {
639
+ let continueStream;
640
+ const streamPromise = new Promise((resolve) => {
641
+ continueStream = resolve;
642
+ });
643
+ const mockStream = (async function* () {
644
+ yield { type: 'content', value: 'Initial' };
645
+ await streamPromise; // Wait until we manually continue
646
+ yield { type: 'content', value: ' Canceled' };
647
+ })();
648
+ mockSendMessageStream.mockReturnValue(mockStream);
649
+ const { result } = renderTestHook();
650
+ await act(async () => {
651
+ result.current.submitQuery('long running query');
652
+ });
653
+ await waitFor(() => {
654
+ expect(result.current.streamingState).toBe(StreamingState.Responding);
655
+ });
656
+ // Cancel the request
657
+ simulateEscapeKeyPress();
658
+ // Allow the stream to continue
659
+ act(() => {
660
+ continueStream();
661
+ });
662
+ // Wait a bit to see if the second part is processed
663
+ await new Promise((resolve) => setTimeout(resolve, 50));
664
+ // The text should not have been updated with " Canceled"
665
+ const lastCall = mockAddItem.mock.calls.find((call) => call[0].type === 'gemini');
666
+ expect(lastCall?.[0].text).toBe('Initial');
667
+ // The final state should be idle after cancellation
668
+ expect(result.current.streamingState).toBe(StreamingState.Idle);
669
+ });
670
+ it('should not cancel if a tool call is in progress (not just responding)', async () => {
671
+ const toolCalls = [
672
+ {
673
+ request: { callId: 'call1', name: 'tool1', args: {} },
674
+ status: 'executing',
675
+ responseSubmittedToGemini: false,
676
+ tool: {
677
+ name: 'tool1',
678
+ description: 'desc1',
679
+ getDescription: vi.fn(),
680
+ },
681
+ startTime: Date.now(),
682
+ liveOutput: '...',
683
+ },
684
+ ];
685
+ const abortSpy = vi.spyOn(AbortController.prototype, 'abort');
686
+ const { result } = renderTestHook(toolCalls);
687
+ // State is `Responding` because a tool is running
688
+ expect(result.current.streamingState).toBe(StreamingState.Responding);
689
+ // Try to cancel
690
+ simulateEscapeKeyPress();
691
+ // Nothing should happen because the state is not `Responding`
692
+ expect(abortSpy).not.toHaveBeenCalled();
693
+ });
694
+ });
695
+ describe('Client-Initiated Tool Calls', () => {
696
+ it('should execute a client-initiated tool without sending a response to Gemini', async () => {
697
+ const clientToolRequest = {
698
+ shouldScheduleTool: true,
699
+ toolName: 'save_memory',
700
+ toolArgs: { fact: 'test fact' },
701
+ };
702
+ mockHandleSlashCommand.mockResolvedValue(clientToolRequest);
703
+ const completedToolCall = {
704
+ request: {
705
+ callId: 'client-call-1',
706
+ name: clientToolRequest.toolName,
707
+ args: clientToolRequest.toolArgs,
708
+ isClientInitiated: true,
709
+ },
710
+ status: 'success',
711
+ responseSubmittedToGemini: false,
712
+ response: {
713
+ callId: 'client-call-1',
714
+ responseParts: [{ text: 'Memory saved' }],
715
+ resultDisplay: 'Success: Memory saved',
716
+ error: undefined,
717
+ },
718
+ tool: {
719
+ name: clientToolRequest.toolName,
720
+ description: 'Saves memory',
721
+ getDescription: vi.fn(),
722
+ },
723
+ };
724
+ // 1. Initial render state: no tool calls
725
+ mockUseReactToolScheduler.mockReturnValue([
726
+ [],
727
+ mockScheduleToolCalls,
728
+ mockMarkToolsAsSubmitted,
729
+ ]);
730
+ const { result, rerender } = renderHook(() => useGeminiStream(new MockedGeminiClientClass(mockConfig), [], mockAddItem, mockSetShowHelp, mockConfig, mockOnDebugMessage, mockHandleSlashCommand, false, () => 'vscode', () => { }, () => Promise.resolve()));
731
+ // --- User runs the slash command ---
732
+ await act(async () => {
733
+ await result.current.submitQuery('/memory add "test fact"');
734
+ });
735
+ // The command handler schedules the tool. Now we simulate the tool completing.
736
+ // 2. Before the next render, set the mock to return the completed tool.
737
+ mockUseReactToolScheduler.mockReturnValue([
738
+ [completedToolCall],
739
+ mockScheduleToolCalls,
740
+ mockMarkToolsAsSubmitted,
741
+ ]);
742
+ // 3. Trigger a re-render to process the completed tool.
743
+ act(() => {
744
+ rerender();
745
+ });
746
+ // --- Assert the outcome ---
747
+ await waitFor(() => {
748
+ // The tool should be marked as submitted locally
749
+ expect(mockMarkToolsAsSubmitted).toHaveBeenCalledWith([
750
+ 'client-call-1',
751
+ ]);
752
+ // Crucially, no message should be sent to the Gemini API
753
+ expect(mockSendMessageStream).not.toHaveBeenCalled();
754
+ });
755
+ });
756
+ });
757
+ describe('Memory Refresh on save_memory', () => {
758
+ it('should call performMemoryRefresh when a save_memory tool call completes successfully', async () => {
759
+ const mockPerformMemoryRefresh = vi.fn();
760
+ const completedToolCall = {
761
+ request: {
762
+ callId: 'save-mem-call-1',
763
+ name: 'save_memory',
764
+ args: { fact: 'test' },
765
+ isClientInitiated: true,
766
+ },
767
+ status: 'success',
768
+ responseSubmittedToGemini: false,
769
+ response: {
770
+ callId: 'save-mem-call-1',
771
+ responseParts: [{ text: 'Memory saved' }],
772
+ resultDisplay: 'Success: Memory saved',
773
+ error: undefined,
774
+ },
775
+ tool: {
776
+ name: 'save_memory',
777
+ description: 'Saves memory',
778
+ getDescription: vi.fn(),
779
+ },
780
+ };
781
+ mockUseReactToolScheduler.mockReturnValue([
782
+ [completedToolCall],
783
+ mockScheduleToolCalls,
784
+ mockMarkToolsAsSubmitted,
785
+ ]);
786
+ const { rerender } = renderHook(() => useGeminiStream(new MockedGeminiClientClass(mockConfig), [], mockAddItem, mockSetShowHelp, mockConfig, mockOnDebugMessage, mockHandleSlashCommand, false, () => 'vscode', () => { }, mockPerformMemoryRefresh));
787
+ act(() => {
788
+ rerender();
789
+ });
790
+ await waitFor(() => {
791
+ expect(mockPerformMemoryRefresh).toHaveBeenCalledTimes(1);
792
+ });
793
+ });
794
+ });
795
+ describe('Error Handling', () => {
796
+ it('should call parseAndFormatApiError with the correct authType on stream initialization failure', async () => {
797
+ // 1. Setup
798
+ const mockError = new Error('Rate limit exceeded');
799
+ const mockAuthType = AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE;
800
+ mockParseAndFormatApiError.mockClear();
801
+ mockSendMessageStream.mockReturnValue((async function* () {
802
+ yield { type: 'content', value: '' };
803
+ throw mockError;
804
+ })());
805
+ const testConfig = {
806
+ ...mockConfig,
807
+ getContentGeneratorConfig: vi.fn(() => ({
808
+ authType: mockAuthType,
809
+ })),
810
+ };
811
+ const { result } = renderHook(() => useGeminiStream(new MockedGeminiClientClass(testConfig), [], mockAddItem, mockSetShowHelp, testConfig, mockOnDebugMessage, mockHandleSlashCommand, false, () => 'vscode', () => { }, () => Promise.resolve()));
812
+ // 2. Action
813
+ await act(async () => {
814
+ await result.current.submitQuery('test query');
815
+ });
816
+ // 3. Assertion
817
+ await waitFor(() => {
818
+ expect(mockParseAndFormatApiError).toHaveBeenCalledWith('Rate limit exceeded', mockAuthType);
819
+ });
820
+ });
821
+ });
822
+ });
823
+ //# sourceMappingURL=useGeminiStream.test.js.map