@google/gemini-cli 0.5.0-preview.1 → 0.7.0-nightly.20250912.68035591

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 (244) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +12 -2
  3. package/dist/google-gemini-cli-0.6.0-nightly.tgz +0 -0
  4. package/dist/package.json +2 -2
  5. package/dist/src/commands/extensions/install.d.ts +1 -0
  6. package/dist/src/commands/extensions/install.js +7 -0
  7. package/dist/src/commands/extensions/install.js.map +1 -1
  8. package/dist/src/config/config.d.ts +1 -0
  9. package/dist/src/config/config.js +8 -0
  10. package/dist/src/config/config.js.map +1 -1
  11. package/dist/src/config/extension.d.ts +12 -0
  12. package/dist/src/config/extension.js +90 -6
  13. package/dist/src/config/extension.js.map +1 -1
  14. package/dist/src/config/keyBindings.d.ts +2 -1
  15. package/dist/src/config/keyBindings.js +2 -0
  16. package/dist/src/config/keyBindings.js.map +1 -1
  17. package/dist/src/config/settings.js +2 -0
  18. package/dist/src/config/settings.js.map +1 -1
  19. package/dist/src/config/settingsSchema.d.ts +58 -1
  20. package/dist/src/config/settingsSchema.js +55 -1
  21. package/dist/src/config/settingsSchema.js.map +1 -1
  22. package/dist/src/config/trustedFolders.js +2 -2
  23. package/dist/src/config/trustedFolders.js.map +1 -1
  24. package/dist/src/config/trustedFolders.test.js +12 -18
  25. package/dist/src/config/trustedFolders.test.js.map +1 -1
  26. package/dist/src/core/initializer.js +6 -1
  27. package/dist/src/core/initializer.js.map +1 -1
  28. package/dist/src/gemini.js +1 -2
  29. package/dist/src/gemini.js.map +1 -1
  30. package/dist/src/gemini.test.js +1 -0
  31. package/dist/src/gemini.test.js.map +1 -1
  32. package/dist/src/generated/git-commit.d.ts +2 -2
  33. package/dist/src/generated/git-commit.js +2 -2
  34. package/dist/src/generated/git-commit.js.map +1 -1
  35. package/dist/src/nonInteractiveCli.js +23 -9
  36. package/dist/src/nonInteractiveCli.js.map +1 -1
  37. package/dist/src/services/prompt-processors/shellProcessor.js +8 -1
  38. package/dist/src/services/prompt-processors/shellProcessor.js.map +1 -1
  39. package/dist/src/ui/AppContainer.js +50 -21
  40. package/dist/src/ui/AppContainer.js.map +1 -1
  41. package/dist/src/ui/IdeIntegrationNudge.js +2 -1
  42. package/dist/src/ui/IdeIntegrationNudge.js.map +1 -1
  43. package/dist/src/ui/auth/AuthDialog.js +2 -2
  44. package/dist/src/ui/auth/AuthDialog.js.map +1 -1
  45. package/dist/src/ui/auth/AuthInProgress.js +2 -2
  46. package/dist/src/ui/auth/AuthInProgress.js.map +1 -1
  47. package/dist/src/ui/commands/chatCommand.js +2 -2
  48. package/dist/src/ui/commands/chatCommand.js.map +1 -1
  49. package/dist/src/ui/commands/extensionsCommand.js +79 -15
  50. package/dist/src/ui/commands/extensionsCommand.js.map +1 -1
  51. package/dist/src/ui/commands/ideCommand.js +2 -2
  52. package/dist/src/ui/commands/ideCommand.js.map +1 -1
  53. package/dist/src/ui/components/AboutBox.js +2 -2
  54. package/dist/src/ui/components/AboutBox.js.map +1 -1
  55. package/dist/src/ui/components/AnsiOutput.d.ts +13 -0
  56. package/dist/src/ui/components/AnsiOutput.js +12 -0
  57. package/dist/src/ui/components/AnsiOutput.js.map +1 -0
  58. package/dist/src/ui/components/AnsiOutput.test.d.ts +6 -0
  59. package/dist/src/ui/components/AnsiOutput.test.js +97 -0
  60. package/dist/src/ui/components/AnsiOutput.test.js.map +1 -0
  61. package/dist/src/ui/components/AutoAcceptIndicator.js +4 -4
  62. package/dist/src/ui/components/AutoAcceptIndicator.js.map +1 -1
  63. package/dist/src/ui/components/Composer.js +5 -5
  64. package/dist/src/ui/components/Composer.js.map +1 -1
  65. package/dist/src/ui/components/ConfigInitDisplay.js +2 -1
  66. package/dist/src/ui/components/ConfigInitDisplay.js.map +1 -1
  67. package/dist/src/ui/components/ConsoleSummaryDisplay.js +2 -2
  68. package/dist/src/ui/components/ConsoleSummaryDisplay.js.map +1 -1
  69. package/dist/src/ui/components/ContextSummaryDisplay.js +3 -3
  70. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
  71. package/dist/src/ui/components/ContextUsageDisplay.js +2 -2
  72. package/dist/src/ui/components/ContextUsageDisplay.js.map +1 -1
  73. package/dist/src/ui/components/DebugProfiler.js +2 -2
  74. package/dist/src/ui/components/DebugProfiler.js.map +1 -1
  75. package/dist/src/ui/components/DetailedMessagesDisplay.js +7 -7
  76. package/dist/src/ui/components/DetailedMessagesDisplay.js.map +1 -1
  77. package/dist/src/ui/components/DialogManager.js +8 -4
  78. package/dist/src/ui/components/DialogManager.js.map +1 -1
  79. package/dist/src/ui/components/EditorSettingsDialog.js +5 -5
  80. package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -1
  81. package/dist/src/ui/components/FolderTrustDialog.js +4 -3
  82. package/dist/src/ui/components/FolderTrustDialog.js.map +1 -1
  83. package/dist/src/ui/components/FolderTrustDialog.test.js +6 -1
  84. package/dist/src/ui/components/FolderTrustDialog.test.js.map +1 -1
  85. package/dist/src/ui/components/Footer.js +1 -1
  86. package/dist/src/ui/components/Footer.js.map +1 -1
  87. package/dist/src/ui/components/GeminiRespondingSpinner.js +3 -2
  88. package/dist/src/ui/components/GeminiRespondingSpinner.js.map +1 -1
  89. package/dist/src/ui/components/Header.js +2 -2
  90. package/dist/src/ui/components/Header.js.map +1 -1
  91. package/dist/src/ui/components/Help.js +5 -5
  92. package/dist/src/ui/components/Help.js.map +1 -1
  93. package/dist/src/ui/components/HistoryItemDisplay.d.ts +2 -0
  94. package/dist/src/ui/components/HistoryItemDisplay.js +1 -1
  95. package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -1
  96. package/dist/src/ui/components/InputPrompt.d.ts +3 -0
  97. package/dist/src/ui/components/InputPrompt.js +21 -4
  98. package/dist/src/ui/components/InputPrompt.js.map +1 -1
  99. package/dist/src/ui/components/LoadingIndicator.js +2 -2
  100. package/dist/src/ui/components/LoadingIndicator.js.map +1 -1
  101. package/dist/src/ui/components/LoopDetectionConfirmation.d.ts +13 -0
  102. package/dist/src/ui/components/LoopDetectionConfirmation.js +35 -0
  103. package/dist/src/ui/components/LoopDetectionConfirmation.js.map +1 -0
  104. package/dist/src/ui/components/LoopDetectionConfirmation.test.d.ts +6 -0
  105. package/dist/src/ui/components/LoopDetectionConfirmation.test.js +25 -0
  106. package/dist/src/ui/components/LoopDetectionConfirmation.test.js.map +1 -0
  107. package/dist/src/ui/components/MainContent.js +1 -1
  108. package/dist/src/ui/components/MainContent.js.map +1 -1
  109. package/dist/src/ui/components/MemoryUsageDisplay.js +6 -4
  110. package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -1
  111. package/dist/src/ui/components/ModelStatsDisplay.js +7 -7
  112. package/dist/src/ui/components/ModelStatsDisplay.js.map +1 -1
  113. package/dist/src/ui/components/Notifications.js +2 -2
  114. package/dist/src/ui/components/Notifications.js.map +1 -1
  115. package/dist/src/ui/components/PrepareLabel.js +2 -2
  116. package/dist/src/ui/components/PrepareLabel.js.map +1 -1
  117. package/dist/src/ui/components/ProQuotaDialog.js +2 -2
  118. package/dist/src/ui/components/ProQuotaDialog.js.map +1 -1
  119. package/dist/src/ui/components/SettingsDialog.js +7 -7
  120. package/dist/src/ui/components/SettingsDialog.js.map +1 -1
  121. package/dist/src/ui/components/ShellConfirmationDialog.js +2 -2
  122. package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -1
  123. package/dist/src/ui/components/ShellInputPrompt.d.ts +11 -0
  124. package/dist/src/ui/components/ShellInputPrompt.js +36 -0
  125. package/dist/src/ui/components/ShellInputPrompt.js.map +1 -0
  126. package/dist/src/ui/components/ShellModeIndicator.js +2 -2
  127. package/dist/src/ui/components/ShellModeIndicator.js.map +1 -1
  128. package/dist/src/ui/components/ShowMoreLines.js +2 -2
  129. package/dist/src/ui/components/ShowMoreLines.js.map +1 -1
  130. package/dist/src/ui/components/StatsDisplay.js +6 -6
  131. package/dist/src/ui/components/StatsDisplay.js.map +1 -1
  132. package/dist/src/ui/components/SuggestionsDisplay.js +8 -8
  133. package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
  134. package/dist/src/ui/components/ThemeDialog.js +4 -4
  135. package/dist/src/ui/components/ThemeDialog.js.map +1 -1
  136. package/dist/src/ui/components/Tips.js +2 -2
  137. package/dist/src/ui/components/Tips.js.map +1 -1
  138. package/dist/src/ui/components/ToolStatsDisplay.js +4 -4
  139. package/dist/src/ui/components/ToolStatsDisplay.js.map +1 -1
  140. package/dist/src/ui/components/UpdateNotification.js +2 -2
  141. package/dist/src/ui/components/UpdateNotification.js.map +1 -1
  142. package/dist/src/ui/components/WorkspaceMigrationDialog.js +4 -4
  143. package/dist/src/ui/components/WorkspaceMigrationDialog.js.map +1 -1
  144. package/dist/src/ui/components/messages/CompressionMessage.d.ts +1 -2
  145. package/dist/src/ui/components/messages/CompressionMessage.js +37 -8
  146. package/dist/src/ui/components/messages/CompressionMessage.js.map +1 -1
  147. package/dist/src/ui/components/messages/CompressionMessage.test.d.ts +6 -0
  148. package/dist/src/ui/components/messages/CompressionMessage.test.js +160 -0
  149. package/dist/src/ui/components/messages/CompressionMessage.test.js.map +1 -0
  150. package/dist/src/ui/components/messages/DiffRenderer.d.ts +2 -1
  151. package/dist/src/ui/components/messages/DiffRenderer.js +14 -22
  152. package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -1
  153. package/dist/src/ui/components/messages/ErrorMessage.js +2 -2
  154. package/dist/src/ui/components/messages/ErrorMessage.js.map +1 -1
  155. package/dist/src/ui/components/messages/GeminiMessage.js +2 -2
  156. package/dist/src/ui/components/messages/GeminiMessage.js.map +1 -1
  157. package/dist/src/ui/components/messages/InfoMessage.js +2 -2
  158. package/dist/src/ui/components/messages/InfoMessage.js.map +1 -1
  159. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +31 -19
  160. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
  161. package/dist/src/ui/components/messages/ToolGroupMessage.d.ts +3 -0
  162. package/dist/src/ui/components/messages/ToolGroupMessage.js +10 -6
  163. package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -1
  164. package/dist/src/ui/components/messages/ToolMessage.d.ts +4 -0
  165. package/dist/src/ui/components/messages/ToolMessage.js +17 -10
  166. package/dist/src/ui/components/messages/ToolMessage.js.map +1 -1
  167. package/dist/src/ui/components/messages/ToolMessage.test.js +33 -1
  168. package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -1
  169. package/dist/src/ui/components/messages/UserMessage.js +3 -3
  170. package/dist/src/ui/components/messages/UserMessage.js.map +1 -1
  171. package/dist/src/ui/components/messages/UserShellMessage.js +2 -2
  172. package/dist/src/ui/components/messages/UserShellMessage.js.map +1 -1
  173. package/dist/src/ui/components/shared/MaxSizedBox.js +2 -2
  174. package/dist/src/ui/components/shared/MaxSizedBox.js.map +1 -1
  175. package/dist/src/ui/components/shared/RadioButtonSelect.js +12 -12
  176. package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -1
  177. package/dist/src/ui/components/shared/text-buffer.d.ts +19 -2
  178. package/dist/src/ui/components/shared/text-buffer.js +176 -132
  179. package/dist/src/ui/components/shared/text-buffer.js.map +1 -1
  180. package/dist/src/ui/contexts/UIStateContext.d.ts +4 -1
  181. package/dist/src/ui/contexts/UIStateContext.js.map +1 -1
  182. package/dist/src/ui/hooks/keyToAnsi.d.ts +15 -0
  183. package/dist/src/ui/hooks/keyToAnsi.js +67 -0
  184. package/dist/src/ui/hooks/keyToAnsi.js.map +1 -0
  185. package/dist/src/ui/hooks/shellCommandProcessor.d.ts +2 -1
  186. package/dist/src/ui/hooks/shellCommandProcessor.js +58 -15
  187. package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -1
  188. package/dist/src/ui/hooks/shellCommandProcessor.test.js +196 -17
  189. package/dist/src/ui/hooks/shellCommandProcessor.test.js.map +1 -1
  190. package/dist/src/ui/hooks/slashCommandProcessor.d.ts +1 -1
  191. package/dist/src/ui/hooks/slashCommandProcessor.js +2 -2
  192. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
  193. package/dist/src/ui/hooks/useGeminiStream.d.ts +7 -1
  194. package/dist/src/ui/hooks/useGeminiStream.js +43 -9
  195. package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
  196. package/dist/src/ui/hooks/useIdeTrustListener.js +2 -2
  197. package/dist/src/ui/hooks/useIdeTrustListener.js.map +1 -1
  198. package/dist/src/ui/hooks/useQuotaAndFallback.test.js +0 -2
  199. package/dist/src/ui/hooks/useQuotaAndFallback.test.js.map +1 -1
  200. package/dist/src/ui/hooks/useReactToolScheduler.d.ts +3 -2
  201. package/dist/src/ui/hooks/useReactToolScheduler.js +21 -17
  202. package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
  203. package/dist/src/ui/hooks/useToolScheduler.test.js +5 -4
  204. package/dist/src/ui/hooks/useToolScheduler.test.js.map +1 -1
  205. package/dist/src/ui/keyMatchers.test.js +6 -0
  206. package/dist/src/ui/keyMatchers.test.js.map +1 -1
  207. package/dist/src/ui/privacy/CloudFreePrivacyNotice.js +5 -5
  208. package/dist/src/ui/privacy/CloudFreePrivacyNotice.js.map +1 -1
  209. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js +2 -2
  210. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js.map +1 -1
  211. package/dist/src/ui/privacy/GeminiPrivacyNotice.js +2 -2
  212. package/dist/src/ui/privacy/GeminiPrivacyNotice.js.map +1 -1
  213. package/dist/src/ui/themes/theme.js +17 -17
  214. package/dist/src/ui/themes/theme.js.map +1 -1
  215. package/dist/src/ui/types.d.ts +6 -0
  216. package/dist/src/ui/types.js.map +1 -1
  217. package/dist/src/ui/utils/CodeColorizer.js +3 -2
  218. package/dist/src/ui/utils/CodeColorizer.js.map +1 -1
  219. package/dist/src/ui/utils/InlineMarkdownRenderer.js +7 -7
  220. package/dist/src/ui/utils/InlineMarkdownRenderer.js.map +1 -1
  221. package/dist/src/ui/utils/MarkdownDisplay.js +10 -10
  222. package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -1
  223. package/dist/src/ui/utils/TableRenderer.js +4 -4
  224. package/dist/src/ui/utils/TableRenderer.js.map +1 -1
  225. package/dist/src/ui/utils/displayUtils.js +4 -4
  226. package/dist/src/ui/utils/displayUtils.js.map +1 -1
  227. package/dist/src/ui/utils/textUtils.d.ts +9 -0
  228. package/dist/src/ui/utils/textUtils.js +52 -3
  229. package/dist/src/ui/utils/textUtils.js.map +1 -1
  230. package/dist/src/utils/errors.d.ts +21 -0
  231. package/dist/src/utils/errors.js +93 -0
  232. package/dist/src/utils/errors.js.map +1 -1
  233. package/dist/src/utils/errors.test.d.ts +6 -0
  234. package/dist/src/utils/errors.test.js +303 -0
  235. package/dist/src/utils/errors.test.js.map +1 -0
  236. package/dist/src/utils/sandbox.js +2 -0
  237. package/dist/src/utils/sandbox.js.map +1 -1
  238. package/dist/src/utils/settingsUtils.test.js +37 -2
  239. package/dist/src/utils/settingsUtils.test.js.map +1 -1
  240. package/dist/src/zed-integration/zedIntegration.js +10 -7
  241. package/dist/src/zed-integration/zedIntegration.js.map +1 -1
  242. package/dist/tsconfig.tsbuildinfo +1 -1
  243. package/package.json +3 -3
  244. package/dist/google-gemini-cli-0.5.0-preview.tgz +0 -0
@@ -30,3 +30,12 @@ export declare function cpSlice(str: string, start: number, end?: number): strin
30
30
  * - CR/LF (0x0D/0x0A) - needed for line breaks
31
31
  */
32
32
  export declare function stripUnsafeCharacters(str: string): string;
33
+ /**
34
+ * Cached version of stringWidth function for better performance
35
+ * Follows Ink's approach with unlimited cache (no eviction)
36
+ */
37
+ export declare const getCachedStringWidth: (str: string) => number;
38
+ /**
39
+ * Clear the string width cache
40
+ */
41
+ export declare const clearStringWidthCache: () => void;
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import stripAnsi from 'strip-ansi';
7
7
  import { stripVTControlCharacters } from 'node:util';
8
+ import stringWidth from 'string-width';
8
9
  /**
9
10
  * Calculates the maximum width of a multi-line ASCII art string.
10
11
  * @param asciiArt The ASCII art string.
@@ -22,10 +23,34 @@ export const getAsciiArtWidth = (asciiArt) => {
22
23
  * Unicode‑aware helpers (work at the code‑point level rather than UTF‑16
23
24
  * code units so that surrogate‑pair emoji count as one "column".)
24
25
  * ---------------------------------------------------------------------- */
26
+ // Cache for code points to reduce GC pressure
27
+ const codePointsCache = new Map();
28
+ const MAX_STRING_LENGTH_TO_CACHE = 1000;
25
29
  export function toCodePoints(str) {
26
- // [...str] or Array.from both iterate by UTF‑32 code point, handling
27
- // surrogate pairs correctly.
28
- return Array.from(str);
30
+ // ASCII fast path - check if all chars are ASCII (0-127)
31
+ let isAscii = true;
32
+ for (let i = 0; i < str.length; i++) {
33
+ if (str.charCodeAt(i) > 127) {
34
+ isAscii = false;
35
+ break;
36
+ }
37
+ }
38
+ if (isAscii) {
39
+ return str.split('');
40
+ }
41
+ // Cache short strings
42
+ if (str.length <= MAX_STRING_LENGTH_TO_CACHE) {
43
+ const cached = codePointsCache.get(str);
44
+ if (cached) {
45
+ return cached;
46
+ }
47
+ }
48
+ const result = Array.from(str);
49
+ // Cache result (unlimited like Ink)
50
+ if (str.length <= MAX_STRING_LENGTH_TO_CACHE) {
51
+ codePointsCache.set(str, result);
52
+ }
53
+ return result;
29
54
  }
30
55
  export function cpLen(str) {
31
56
  return toCodePoints(str).length;
@@ -77,4 +102,28 @@ export function stripUnsafeCharacters(str) {
77
102
  })
78
103
  .join('');
79
104
  }
105
+ // String width caching for performance optimization
106
+ const stringWidthCache = new Map();
107
+ /**
108
+ * Cached version of stringWidth function for better performance
109
+ * Follows Ink's approach with unlimited cache (no eviction)
110
+ */
111
+ export const getCachedStringWidth = (str) => {
112
+ // ASCII printable chars have width 1
113
+ if (/^[\x20-\x7E]*$/.test(str)) {
114
+ return str.length;
115
+ }
116
+ if (stringWidthCache.has(str)) {
117
+ return stringWidthCache.get(str);
118
+ }
119
+ const width = stringWidth(str);
120
+ stringWidthCache.set(str, width);
121
+ return width;
122
+ };
123
+ /**
124
+ * Clear the string width cache
125
+ */
126
+ export const clearStringWidthCache = () => {
127
+ stringWidthCache.clear();
128
+ };
80
129
  //# sourceMappingURL=textUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"textUtils.js","sourceRoot":"","sources":["../../../../src/ui/utils/textUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF;;;;4EAI4E;AAE5E,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,qEAAqE;IACrE,6BAA6B;IAC7B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,KAAa,EAAE,GAAY;IAC9D,2CAA2C;IAC3C,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qBAAqB,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C,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,IAAI,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IACpC,CAAC;IAED,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC/B,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEjC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAS,EAAE;IAC9C,gBAAgB,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC,CAAC"}
@@ -3,4 +3,25 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import type { Config } from '@google/gemini-cli-core';
6
7
  export declare function getErrorMessage(error: unknown): string;
8
+ /**
9
+ * Handles errors consistently for both JSON and text output formats.
10
+ * In JSON mode, outputs formatted JSON error and exits.
11
+ * In text mode, outputs error message and re-throws.
12
+ */
13
+ export declare function handleError(error: unknown, config: Config, customErrorCode?: string | number): never;
14
+ /**
15
+ * Handles tool execution errors specifically.
16
+ * In JSON mode, outputs formatted JSON error and exits.
17
+ * In text mode, outputs error message to stderr only.
18
+ */
19
+ export declare function handleToolError(toolName: string, toolError: Error, config: Config, errorCode?: string | number, resultDisplay?: string): void;
20
+ /**
21
+ * Handles cancellation/abort signals consistently.
22
+ */
23
+ export declare function handleCancellationError(config: Config): never;
24
+ /**
25
+ * Handles max session turns exceeded consistently.
26
+ */
27
+ export declare function handleMaxTurnsExceededError(config: Config): never;
@@ -3,10 +3,103 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { OutputFormat, JsonFormatter, parseAndFormatApiError, FatalTurnLimitedError, FatalToolExecutionError, FatalCancellationError, } from '@google/gemini-cli-core';
6
7
  export function getErrorMessage(error) {
7
8
  if (error instanceof Error) {
8
9
  return error.message;
9
10
  }
10
11
  return String(error);
11
12
  }
13
+ /**
14
+ * Extracts the appropriate error code from an error object.
15
+ */
16
+ function extractErrorCode(error) {
17
+ const errorWithCode = error;
18
+ // Prioritize exitCode for FatalError types, fall back to other codes
19
+ if (typeof errorWithCode.exitCode === 'number') {
20
+ return errorWithCode.exitCode;
21
+ }
22
+ if (errorWithCode.code !== undefined) {
23
+ return errorWithCode.code;
24
+ }
25
+ if (errorWithCode.status !== undefined) {
26
+ return errorWithCode.status;
27
+ }
28
+ return 1; // Default exit code
29
+ }
30
+ /**
31
+ * Converts an error code to a numeric exit code.
32
+ */
33
+ function getNumericExitCode(errorCode) {
34
+ return typeof errorCode === 'number' ? errorCode : 1;
35
+ }
36
+ /**
37
+ * Handles errors consistently for both JSON and text output formats.
38
+ * In JSON mode, outputs formatted JSON error and exits.
39
+ * In text mode, outputs error message and re-throws.
40
+ */
41
+ export function handleError(error, config, customErrorCode) {
42
+ const errorMessage = parseAndFormatApiError(error, config.getContentGeneratorConfig()?.authType);
43
+ if (config.getOutputFormat() === OutputFormat.JSON) {
44
+ const formatter = new JsonFormatter();
45
+ const errorCode = customErrorCode ?? extractErrorCode(error);
46
+ const formattedError = formatter.formatError(error instanceof Error ? error : new Error(getErrorMessage(error)), errorCode);
47
+ console.error(formattedError);
48
+ process.exit(getNumericExitCode(errorCode));
49
+ }
50
+ else {
51
+ console.error(errorMessage);
52
+ throw error;
53
+ }
54
+ }
55
+ /**
56
+ * Handles tool execution errors specifically.
57
+ * In JSON mode, outputs formatted JSON error and exits.
58
+ * In text mode, outputs error message to stderr only.
59
+ */
60
+ export function handleToolError(toolName, toolError, config, errorCode, resultDisplay) {
61
+ const errorMessage = `Error executing tool ${toolName}: ${resultDisplay || toolError.message}`;
62
+ const toolExecutionError = new FatalToolExecutionError(errorMessage);
63
+ if (config.getOutputFormat() === OutputFormat.JSON) {
64
+ const formatter = new JsonFormatter();
65
+ const formattedError = formatter.formatError(toolExecutionError, errorCode ?? toolExecutionError.exitCode);
66
+ console.error(formattedError);
67
+ process.exit(typeof errorCode === 'number' ? errorCode : toolExecutionError.exitCode);
68
+ }
69
+ else {
70
+ console.error(errorMessage);
71
+ }
72
+ }
73
+ /**
74
+ * Handles cancellation/abort signals consistently.
75
+ */
76
+ export function handleCancellationError(config) {
77
+ const cancellationError = new FatalCancellationError('Operation cancelled.');
78
+ if (config.getOutputFormat() === OutputFormat.JSON) {
79
+ const formatter = new JsonFormatter();
80
+ const formattedError = formatter.formatError(cancellationError, cancellationError.exitCode);
81
+ console.error(formattedError);
82
+ process.exit(cancellationError.exitCode);
83
+ }
84
+ else {
85
+ console.error(cancellationError.message);
86
+ process.exit(cancellationError.exitCode);
87
+ }
88
+ }
89
+ /**
90
+ * Handles max session turns exceeded consistently.
91
+ */
92
+ export function handleMaxTurnsExceededError(config) {
93
+ const maxTurnsError = new FatalTurnLimitedError('Reached max session turns for this session. Increase the number of turns by specifying maxSessionTurns in settings.json.');
94
+ if (config.getOutputFormat() === OutputFormat.JSON) {
95
+ const formatter = new JsonFormatter();
96
+ const formattedError = formatter.formatError(maxTurnsError, maxTurnsError.exitCode);
97
+ console.error(formattedError);
98
+ process.exit(maxTurnsError.exitCode);
99
+ }
100
+ else {
101
+ console.error(maxTurnsError.message);
102
+ process.exit(maxTurnsError.exitCode);
103
+ }
104
+ }
12
105
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
1
+ {"version":3,"file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AAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export {};
@@ -0,0 +1,303 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { vi } from 'vitest';
7
+ import { OutputFormat, FatalInputError } from '@google/gemini-cli-core';
8
+ import { getErrorMessage, handleError, handleToolError, handleCancellationError, handleMaxTurnsExceededError, } from './errors.js';
9
+ // Mock the core modules
10
+ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
11
+ const original = await importOriginal();
12
+ return {
13
+ ...original,
14
+ parseAndFormatApiError: vi.fn((error) => {
15
+ if (error instanceof Error) {
16
+ return `API Error: ${error.message}`;
17
+ }
18
+ return `API Error: ${String(error)}`;
19
+ }),
20
+ JsonFormatter: vi.fn().mockImplementation(() => ({
21
+ formatError: vi.fn((error, code) => JSON.stringify({
22
+ error: {
23
+ type: error.constructor.name,
24
+ message: error.message,
25
+ ...(code && { code }),
26
+ },
27
+ }, null, 2)),
28
+ })),
29
+ FatalToolExecutionError: class extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = 'FatalToolExecutionError';
33
+ this.exitCode = 54;
34
+ }
35
+ exitCode;
36
+ },
37
+ FatalCancellationError: class extends Error {
38
+ constructor(message) {
39
+ super(message);
40
+ this.name = 'FatalCancellationError';
41
+ this.exitCode = 130;
42
+ }
43
+ exitCode;
44
+ },
45
+ };
46
+ });
47
+ describe('errors', () => {
48
+ let mockConfig;
49
+ let processExitSpy;
50
+ let consoleErrorSpy;
51
+ beforeEach(() => {
52
+ // Reset mocks
53
+ vi.clearAllMocks();
54
+ // Mock console.error
55
+ consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => { });
56
+ // Mock process.exit to throw instead of actually exiting
57
+ processExitSpy = vi.spyOn(process, 'exit').mockImplementation((code) => {
58
+ throw new Error(`process.exit called with code: ${code}`);
59
+ });
60
+ // Create mock config
61
+ mockConfig = {
62
+ getOutputFormat: vi.fn().mockReturnValue(OutputFormat.TEXT),
63
+ getContentGeneratorConfig: vi.fn().mockReturnValue({ authType: 'test' }),
64
+ };
65
+ });
66
+ afterEach(() => {
67
+ consoleErrorSpy.mockRestore();
68
+ processExitSpy.mockRestore();
69
+ });
70
+ describe('getErrorMessage', () => {
71
+ it('should return error message for Error instances', () => {
72
+ const error = new Error('Test error message');
73
+ expect(getErrorMessage(error)).toBe('Test error message');
74
+ });
75
+ it('should convert non-Error values to strings', () => {
76
+ expect(getErrorMessage('string error')).toBe('string error');
77
+ expect(getErrorMessage(123)).toBe('123');
78
+ expect(getErrorMessage(null)).toBe('null');
79
+ expect(getErrorMessage(undefined)).toBe('undefined');
80
+ });
81
+ it('should handle objects', () => {
82
+ const obj = { message: 'test' };
83
+ expect(getErrorMessage(obj)).toBe('[object Object]');
84
+ });
85
+ });
86
+ describe('handleError', () => {
87
+ describe('in text mode', () => {
88
+ beforeEach(() => {
89
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.TEXT);
90
+ });
91
+ it('should log error message and re-throw', () => {
92
+ const testError = new Error('Test error');
93
+ expect(() => {
94
+ handleError(testError, mockConfig);
95
+ }).toThrow(testError);
96
+ expect(consoleErrorSpy).toHaveBeenCalledWith('API Error: Test error');
97
+ });
98
+ it('should handle non-Error objects', () => {
99
+ const testError = 'String error';
100
+ expect(() => {
101
+ handleError(testError, mockConfig);
102
+ }).toThrow(testError);
103
+ expect(consoleErrorSpy).toHaveBeenCalledWith('API Error: String error');
104
+ });
105
+ });
106
+ describe('in JSON mode', () => {
107
+ beforeEach(() => {
108
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.JSON);
109
+ });
110
+ it('should format error as JSON and exit with default code', () => {
111
+ const testError = new Error('Test error');
112
+ expect(() => {
113
+ handleError(testError, mockConfig);
114
+ }).toThrow('process.exit called with code: 1');
115
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
116
+ error: {
117
+ type: 'Error',
118
+ message: 'Test error',
119
+ code: 1,
120
+ },
121
+ }, null, 2));
122
+ });
123
+ it('should use custom error code when provided', () => {
124
+ const testError = new Error('Test error');
125
+ expect(() => {
126
+ handleError(testError, mockConfig, 42);
127
+ }).toThrow('process.exit called with code: 42');
128
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
129
+ error: {
130
+ type: 'Error',
131
+ message: 'Test error',
132
+ code: 42,
133
+ },
134
+ }, null, 2));
135
+ });
136
+ it('should extract exitCode from FatalError instances', () => {
137
+ const fatalError = new FatalInputError('Fatal error');
138
+ expect(() => {
139
+ handleError(fatalError, mockConfig);
140
+ }).toThrow('process.exit called with code: 42');
141
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
142
+ error: {
143
+ type: 'FatalInputError',
144
+ message: 'Fatal error',
145
+ code: 42,
146
+ },
147
+ }, null, 2));
148
+ });
149
+ it('should handle error with code property', () => {
150
+ const errorWithCode = new Error('Error with code');
151
+ errorWithCode.code = 404;
152
+ expect(() => {
153
+ handleError(errorWithCode, mockConfig);
154
+ }).toThrow('process.exit called with code: 404');
155
+ });
156
+ it('should handle error with status property', () => {
157
+ const errorWithStatus = new Error('Error with status');
158
+ errorWithStatus.status = 'TIMEOUT';
159
+ expect(() => {
160
+ handleError(errorWithStatus, mockConfig);
161
+ }).toThrow('process.exit called with code: 1'); // string codes become 1
162
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
163
+ error: {
164
+ type: 'Error',
165
+ message: 'Error with status',
166
+ code: 'TIMEOUT',
167
+ },
168
+ }, null, 2));
169
+ });
170
+ });
171
+ });
172
+ describe('handleToolError', () => {
173
+ const toolName = 'test-tool';
174
+ const toolError = new Error('Tool failed');
175
+ describe('in text mode', () => {
176
+ beforeEach(() => {
177
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.TEXT);
178
+ });
179
+ it('should log error message to stderr', () => {
180
+ handleToolError(toolName, toolError, mockConfig);
181
+ expect(consoleErrorSpy).toHaveBeenCalledWith('Error executing tool test-tool: Tool failed');
182
+ });
183
+ it('should use resultDisplay when provided', () => {
184
+ handleToolError(toolName, toolError, mockConfig, 'CUSTOM_ERROR', 'Custom display message');
185
+ expect(consoleErrorSpy).toHaveBeenCalledWith('Error executing tool test-tool: Custom display message');
186
+ });
187
+ });
188
+ describe('in JSON mode', () => {
189
+ beforeEach(() => {
190
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.JSON);
191
+ });
192
+ it('should format error as JSON and exit with default code', () => {
193
+ expect(() => {
194
+ handleToolError(toolName, toolError, mockConfig);
195
+ }).toThrow('process.exit called with code: 54');
196
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
197
+ error: {
198
+ type: 'FatalToolExecutionError',
199
+ message: 'Error executing tool test-tool: Tool failed',
200
+ code: 54,
201
+ },
202
+ }, null, 2));
203
+ });
204
+ it('should use custom error code', () => {
205
+ expect(() => {
206
+ handleToolError(toolName, toolError, mockConfig, 'CUSTOM_TOOL_ERROR');
207
+ }).toThrow('process.exit called with code: 54');
208
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
209
+ error: {
210
+ type: 'FatalToolExecutionError',
211
+ message: 'Error executing tool test-tool: Tool failed',
212
+ code: 'CUSTOM_TOOL_ERROR',
213
+ },
214
+ }, null, 2));
215
+ });
216
+ it('should use numeric error code and exit with that code', () => {
217
+ expect(() => {
218
+ handleToolError(toolName, toolError, mockConfig, 500);
219
+ }).toThrow('process.exit called with code: 500');
220
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
221
+ error: {
222
+ type: 'FatalToolExecutionError',
223
+ message: 'Error executing tool test-tool: Tool failed',
224
+ code: 500,
225
+ },
226
+ }, null, 2));
227
+ });
228
+ it('should prefer resultDisplay over error message', () => {
229
+ expect(() => {
230
+ handleToolError(toolName, toolError, mockConfig, 'DISPLAY_ERROR', 'Display message');
231
+ }).toThrow('process.exit called with code: 54');
232
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
233
+ error: {
234
+ type: 'FatalToolExecutionError',
235
+ message: 'Error executing tool test-tool: Display message',
236
+ code: 'DISPLAY_ERROR',
237
+ },
238
+ }, null, 2));
239
+ });
240
+ });
241
+ });
242
+ describe('handleCancellationError', () => {
243
+ describe('in text mode', () => {
244
+ beforeEach(() => {
245
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.TEXT);
246
+ });
247
+ it('should log cancellation message and exit with 130', () => {
248
+ expect(() => {
249
+ handleCancellationError(mockConfig);
250
+ }).toThrow('process.exit called with code: 130');
251
+ expect(consoleErrorSpy).toHaveBeenCalledWith('Operation cancelled.');
252
+ });
253
+ });
254
+ describe('in JSON mode', () => {
255
+ beforeEach(() => {
256
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.JSON);
257
+ });
258
+ it('should format cancellation as JSON and exit with 130', () => {
259
+ expect(() => {
260
+ handleCancellationError(mockConfig);
261
+ }).toThrow('process.exit called with code: 130');
262
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
263
+ error: {
264
+ type: 'FatalCancellationError',
265
+ message: 'Operation cancelled.',
266
+ code: 130,
267
+ },
268
+ }, null, 2));
269
+ });
270
+ });
271
+ });
272
+ describe('handleMaxTurnsExceededError', () => {
273
+ describe('in text mode', () => {
274
+ beforeEach(() => {
275
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.TEXT);
276
+ });
277
+ it('should log max turns message and exit with 53', () => {
278
+ expect(() => {
279
+ handleMaxTurnsExceededError(mockConfig);
280
+ }).toThrow('process.exit called with code: 53');
281
+ expect(consoleErrorSpy).toHaveBeenCalledWith('Reached max session turns for this session. Increase the number of turns by specifying maxSessionTurns in settings.json.');
282
+ });
283
+ });
284
+ describe('in JSON mode', () => {
285
+ beforeEach(() => {
286
+ mockConfig.getOutputFormat.mockReturnValue(OutputFormat.JSON);
287
+ });
288
+ it('should format max turns error as JSON and exit with 53', () => {
289
+ expect(() => {
290
+ handleMaxTurnsExceededError(mockConfig);
291
+ }).toThrow('process.exit called with code: 53');
292
+ expect(consoleErrorSpy).toHaveBeenCalledWith(JSON.stringify({
293
+ error: {
294
+ type: 'FatalTurnLimitedError',
295
+ message: 'Reached max session turns for this session. Increase the number of turns by specifying maxSessionTurns in settings.json.',
296
+ code: 53,
297
+ },
298
+ }, null, 2));
299
+ });
300
+ });
301
+ });
302
+ });
303
+ //# sourceMappingURL=errors.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../../../src/utils/errors.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,EAAE,EAAqB,MAAM,QAAQ,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EACL,eAAe,EACf,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AAErB,wBAAwB;AACxB,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;IAC1D,MAAM,QAAQ,GACZ,MAAM,cAAc,EAA4C,CAAC;IAEnE,OAAO;QACL,GAAG,QAAQ;QACX,sBAAsB,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,KAAc,EAAE,EAAE;YAC/C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,OAAO,cAAc,KAAK,CAAC,OAAO,EAAE,CAAC;YACvC,CAAC;YACD,OAAO,cAAc,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,CAAC,CAAC;QACF,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;YAC/C,WAAW,EAAE,EAAE,C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0HAA0H;wBAC5H,IAAI,EAAE,EAAE;qBACT;iBACF,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -324,6 +324,8 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs =
324
324
  if (process.stdin.isTTY) {
325
325
  args.push('-t');
326
326
  }
327
+ // allow access to host.docker.internal
328
+ args.push('--add-host', 'host.docker.internal:host-gateway');
327
329
  // mount current directory as working directory in sandbox (set via --workdir)
328
330
  args.push('--volume', `${workdir}:${containerWorkdir}`);
329
331
  // mount user settings directory inside container, after creating if missing