@google/gemini-cli 0.6.0-nightly.20250910.a31830a3 → 0.6.0-preview.10
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.
- package/LICENSE +2 -2
- package/README.md +12 -2
- package/dist/package.json +4 -2
- package/dist/src/commands/extensions/disable.d.ts +2 -3
- package/dist/src/commands/extensions/disable.js +20 -6
- package/dist/src/commands/extensions/disable.js.map +1 -1
- package/dist/src/commands/extensions/enable.d.ts +2 -3
- package/dist/src/commands/extensions/enable.js +20 -9
- package/dist/src/commands/extensions/enable.js.map +1 -1
- package/dist/src/commands/extensions/install.d.ts +2 -0
- package/dist/src/commands/extensions/install.js +20 -4
- package/dist/src/commands/extensions/install.js.map +1 -1
- package/dist/src/commands/extensions/install.test.js +80 -3
- package/dist/src/commands/extensions/install.test.js.map +1 -1
- package/dist/src/commands/extensions/link.js +1 -1
- package/dist/src/commands/extensions/link.js.map +1 -1
- package/dist/src/commands/extensions/uninstall.js +1 -1
- package/dist/src/commands/extensions/uninstall.js.map +1 -1
- package/dist/src/commands/extensions/update.js +42 -11
- package/dist/src/commands/extensions/update.js.map +1 -1
- package/dist/src/config/config.d.ts +1 -1
- package/dist/src/config/config.js +20 -6
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/extension.d.ts +10 -14
- package/dist/src/config/extension.js +156 -145
- package/dist/src/config/extension.js.map +1 -1
- package/dist/src/config/extensions/extensionEnablement.d.ts +44 -0
- package/dist/src/config/extensions/extensionEnablement.js +161 -0
- package/dist/src/config/extensions/extensionEnablement.js.map +1 -0
- package/dist/src/config/extensions/extensionEnablement.test.d.ts +6 -0
- package/dist/src/config/extensions/extensionEnablement.test.js +261 -0
- package/dist/src/config/extensions/extensionEnablement.test.js.map +1 -0
- package/dist/src/config/extensions/github.d.ts +29 -0
- package/dist/src/config/extensions/github.js +301 -0
- package/dist/src/config/extensions/github.js.map +1 -0
- package/dist/src/config/extensions/github.test.d.ts +6 -0
- package/dist/src/config/extensions/github.test.js +267 -0
- package/dist/src/config/extensions/github.test.js.map +1 -0
- package/dist/src/config/extensions/update.d.ts +20 -0
- package/dist/src/config/extensions/update.js +94 -0
- package/dist/src/config/extensions/update.js.map +1 -0
- package/dist/src/config/extensions/update.test.d.ts +6 -0
- package/dist/src/config/extensions/update.test.js +324 -0
- package/dist/src/config/extensions/update.test.js.map +1 -0
- package/dist/src/config/extensions/variableSchema.d.ts +8 -0
- package/dist/src/config/extensions/variableSchema.js +4 -0
- package/dist/src/config/extensions/variableSchema.js.map +1 -1
- package/dist/src/config/keyBindings.d.ts +4 -1
- package/dist/src/config/keyBindings.js +8 -0
- package/dist/src/config/keyBindings.js.map +1 -1
- package/dist/src/config/settings.d.ts +3 -0
- package/dist/src/config/settings.js +55 -16
- package/dist/src/config/settings.js.map +1 -1
- package/dist/src/config/settingsSchema.d.ts +74 -8
- package/dist/src/config/settingsSchema.js +71 -8
- package/dist/src/config/settingsSchema.js.map +1 -1
- package/dist/src/config/settingsSchema.test.js +6 -0
- package/dist/src/config/settingsSchema.test.js.map +1 -1
- package/dist/src/config/trustedFolders.d.ts +1 -1
- package/dist/src/config/trustedFolders.js +9 -4
- package/dist/src/config/trustedFolders.js.map +1 -1
- package/dist/src/config/trustedFolders.test.js +41 -25
- package/dist/src/config/trustedFolders.test.js.map +1 -1
- package/dist/src/core/initializer.js +6 -1
- package/dist/src/core/initializer.js.map +1 -1
- package/dist/src/gemini.js +53 -32
- package/dist/src/gemini.js.map +1 -1
- package/dist/src/gemini.test.js +24 -2
- package/dist/src/gemini.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/generated/git-commit.js.map +1 -1
- package/dist/src/nonInteractiveCli.js +23 -9
- package/dist/src/nonInteractiveCli.js.map +1 -1
- package/dist/src/services/McpPromptLoader.js +43 -8
- package/dist/src/services/McpPromptLoader.js.map +1 -1
- package/dist/src/services/McpPromptLoader.test.js +228 -1
- package/dist/src/services/McpPromptLoader.test.js.map +1 -1
- package/dist/src/services/prompt-processors/shellProcessor.js +8 -1
- package/dist/src/services/prompt-processors/shellProcessor.js.map +1 -1
- package/dist/src/test-utils/createExtension.d.ts +15 -0
- package/dist/src/test-utils/createExtension.js +25 -0
- package/dist/src/test-utils/createExtension.js.map +1 -0
- package/dist/src/test-utils/mockCommandContext.js +2 -0
- package/dist/src/test-utils/mockCommandContext.js.map +1 -1
- package/dist/src/ui/AppContainer.js +66 -32
- package/dist/src/ui/AppContainer.js.map +1 -1
- package/dist/src/ui/AppContainer.test.js +36 -0
- package/dist/src/ui/AppContainer.test.js.map +1 -1
- package/dist/src/ui/IdeIntegrationNudge.js +2 -1
- package/dist/src/ui/IdeIntegrationNudge.js.map +1 -1
- package/dist/src/ui/auth/AuthDialog.js +2 -2
- package/dist/src/ui/auth/AuthDialog.js.map +1 -1
- package/dist/src/ui/auth/AuthInProgress.js +2 -2
- package/dist/src/ui/auth/AuthInProgress.js.map +1 -1
- package/dist/src/ui/commands/chatCommand.d.ts +2 -0
- package/dist/src/ui/commands/chatCommand.js +82 -3
- package/dist/src/ui/commands/chatCommand.js.map +1 -1
- package/dist/src/ui/commands/extensionsCommand.js +86 -16
- package/dist/src/ui/commands/extensionsCommand.js.map +1 -1
- package/dist/src/ui/commands/ideCommand.js +2 -2
- package/dist/src/ui/commands/ideCommand.js.map +1 -1
- package/dist/src/ui/commands/types.d.ts +4 -1
- package/dist/src/ui/commands/types.js +0 -1
- package/dist/src/ui/commands/types.js.map +1 -1
- package/dist/src/ui/components/AboutBox.js +2 -2
- package/dist/src/ui/components/AboutBox.js.map +1 -1
- package/dist/src/ui/components/AnsiOutput.d.ts +13 -0
- package/dist/src/ui/components/AnsiOutput.js +12 -0
- package/dist/src/ui/components/AnsiOutput.js.map +1 -0
- package/dist/src/ui/components/AnsiOutput.test.d.ts +6 -0
- package/dist/src/ui/components/AnsiOutput.test.js +97 -0
- package/dist/src/ui/components/AnsiOutput.test.js.map +1 -0
- package/dist/src/ui/components/AutoAcceptIndicator.js +4 -4
- package/dist/src/ui/components/AutoAcceptIndicator.js.map +1 -1
- package/dist/src/ui/components/Composer.js +10 -5
- package/dist/src/ui/components/Composer.js.map +1 -1
- package/dist/src/ui/components/ConfigInitDisplay.js +2 -1
- package/dist/src/ui/components/ConfigInitDisplay.js.map +1 -1
- package/dist/src/ui/components/ConsoleSummaryDisplay.js +2 -2
- package/dist/src/ui/components/ConsoleSummaryDisplay.js.map +1 -1
- package/dist/src/ui/components/ContextSummaryDisplay.js +3 -3
- package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
- package/dist/src/ui/components/ContextUsageDisplay.js +2 -2
- package/dist/src/ui/components/ContextUsageDisplay.js.map +1 -1
- package/dist/src/ui/components/DebugProfiler.js +2 -2
- package/dist/src/ui/components/DebugProfiler.js.map +1 -1
- package/dist/src/ui/components/DetailedMessagesDisplay.js +7 -7
- package/dist/src/ui/components/DetailedMessagesDisplay.js.map +1 -1
- package/dist/src/ui/components/DialogManager.js +9 -5
- package/dist/src/ui/components/DialogManager.js.map +1 -1
- package/dist/src/ui/components/EditorSettingsDialog.js +5 -5
- package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -1
- package/dist/src/ui/components/FolderTrustDialog.js +16 -8
- package/dist/src/ui/components/FolderTrustDialog.js.map +1 -1
- package/dist/src/ui/components/FolderTrustDialog.test.js +18 -8
- package/dist/src/ui/components/FolderTrustDialog.test.js.map +1 -1
- package/dist/src/ui/components/Footer.d.ts +3 -0
- package/dist/src/ui/components/Footer.js +8 -3
- package/dist/src/ui/components/Footer.js.map +1 -1
- package/dist/src/ui/components/GeminiRespondingSpinner.js +3 -2
- package/dist/src/ui/components/GeminiRespondingSpinner.js.map +1 -1
- package/dist/src/ui/components/Header.js +2 -2
- package/dist/src/ui/components/Header.js.map +1 -1
- package/dist/src/ui/components/Help.js +5 -5
- package/dist/src/ui/components/Help.js.map +1 -1
- package/dist/src/ui/components/HistoryItemDisplay.d.ts +2 -0
- package/dist/src/ui/components/HistoryItemDisplay.js +2 -1
- package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -1
- package/dist/src/ui/components/InputPrompt.d.ts +3 -0
- package/dist/src/ui/components/InputPrompt.js +97 -19
- package/dist/src/ui/components/InputPrompt.js.map +1 -1
- package/dist/src/ui/components/LoadingIndicator.js +2 -2
- package/dist/src/ui/components/LoadingIndicator.js.map +1 -1
- package/dist/src/ui/components/LoopDetectionConfirmation.d.ts +13 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.js +35 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.js.map +1 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.test.d.ts +6 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.test.js +25 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.test.js.map +1 -0
- package/dist/src/ui/components/MainContent.js +1 -1
- package/dist/src/ui/components/MainContent.js.map +1 -1
- package/dist/src/ui/components/MemoryUsageDisplay.js +6 -4
- package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -1
- package/dist/src/ui/components/ModelStatsDisplay.js +7 -7
- package/dist/src/ui/components/ModelStatsDisplay.js.map +1 -1
- package/dist/src/ui/components/Notifications.js +2 -2
- package/dist/src/ui/components/Notifications.js.map +1 -1
- package/dist/src/ui/components/PrepareLabel.d.ts +5 -5
- package/dist/src/ui/components/PrepareLabel.js +67 -11
- package/dist/src/ui/components/PrepareLabel.js.map +1 -1
- package/dist/src/ui/components/PrepareLabel.test.d.ts +6 -0
- package/dist/src/ui/components/PrepareLabel.test.js +71 -0
- package/dist/src/ui/components/PrepareLabel.test.js.map +1 -0
- package/dist/src/ui/components/ProQuotaDialog.js +2 -2
- package/dist/src/ui/components/ProQuotaDialog.js.map +1 -1
- package/dist/src/ui/components/SettingsDialog.d.ts +2 -1
- package/dist/src/ui/components/SettingsDialog.js +73 -17
- package/dist/src/ui/components/SettingsDialog.js.map +1 -1
- package/dist/src/ui/components/SettingsDialog.test.js +291 -0
- package/dist/src/ui/components/SettingsDialog.test.js.map +1 -1
- package/dist/src/ui/components/ShellConfirmationDialog.js +2 -2
- package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -1
- package/dist/src/ui/components/ShellInputPrompt.d.ts +11 -0
- package/dist/src/ui/components/ShellInputPrompt.js +36 -0
- package/dist/src/ui/components/ShellInputPrompt.js.map +1 -0
- package/dist/src/ui/components/ShellModeIndicator.js +2 -2
- package/dist/src/ui/components/ShellModeIndicator.js.map +1 -1
- package/dist/src/ui/components/ShowMoreLines.js +2 -2
- package/dist/src/ui/components/ShowMoreLines.js.map +1 -1
- package/dist/src/ui/components/StatsDisplay.js +6 -6
- package/dist/src/ui/components/StatsDisplay.js.map +1 -1
- package/dist/src/ui/components/SuggestionsDisplay.d.ts +5 -2
- package/dist/src/ui/components/SuggestionsDisplay.js +17 -11
- package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
- package/dist/src/ui/components/ThemeDialog.js +4 -4
- package/dist/src/ui/components/ThemeDialog.js.map +1 -1
- package/dist/src/ui/components/ThemeDialog.test.js +10 -0
- package/dist/src/ui/components/ThemeDialog.test.js.map +1 -1
- package/dist/src/ui/components/Tips.js +2 -2
- package/dist/src/ui/components/Tips.js.map +1 -1
- package/dist/src/ui/components/ToolStatsDisplay.js +4 -4
- package/dist/src/ui/components/ToolStatsDisplay.js.map +1 -1
- package/dist/src/ui/components/UpdateNotification.js +2 -2
- package/dist/src/ui/components/UpdateNotification.js.map +1 -1
- package/dist/src/ui/components/WorkspaceMigrationDialog.js +4 -4
- package/dist/src/ui/components/WorkspaceMigrationDialog.js.map +1 -1
- package/dist/src/ui/components/messages/CompressionMessage.d.ts +1 -2
- package/dist/src/ui/components/messages/CompressionMessage.js +37 -8
- package/dist/src/ui/components/messages/CompressionMessage.js.map +1 -1
- package/dist/src/ui/components/messages/CompressionMessage.test.d.ts +6 -0
- package/dist/src/ui/components/messages/CompressionMessage.test.js +160 -0
- package/dist/src/ui/components/messages/CompressionMessage.test.js.map +1 -0
- package/dist/src/ui/components/messages/DiffRenderer.d.ts +2 -1
- package/dist/src/ui/components/messages/DiffRenderer.js +14 -22
- package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -1
- package/dist/src/ui/components/messages/ErrorMessage.js +2 -2
- package/dist/src/ui/components/messages/ErrorMessage.js.map +1 -1
- package/dist/src/ui/components/messages/GeminiMessage.js +2 -2
- package/dist/src/ui/components/messages/GeminiMessage.js.map +1 -1
- package/dist/src/ui/components/messages/InfoMessage.js +2 -2
- package/dist/src/ui/components/messages/InfoMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolConfirmationMessage.js +31 -19
- package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolGroupMessage.d.ts +3 -0
- package/dist/src/ui/components/messages/ToolGroupMessage.js +14 -8
- package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolMessage.d.ts +4 -0
- package/dist/src/ui/components/messages/ToolMessage.js +24 -10
- package/dist/src/ui/components/messages/ToolMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolMessage.test.js +33 -1
- package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -1
- package/dist/src/ui/components/messages/UserMessage.js +3 -3
- package/dist/src/ui/components/messages/UserMessage.js.map +1 -1
- package/dist/src/ui/components/messages/UserShellMessage.js +2 -2
- package/dist/src/ui/components/messages/UserShellMessage.js.map +1 -1
- package/dist/src/ui/components/shared/MaxSizedBox.js +2 -2
- package/dist/src/ui/components/shared/MaxSizedBox.js.map +1 -1
- package/dist/src/ui/components/shared/RadioButtonSelect.js +12 -12
- package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -1
- package/dist/src/ui/components/shared/text-buffer.d.ts +19 -2
- package/dist/src/ui/components/shared/text-buffer.js +191 -133
- package/dist/src/ui/components/shared/text-buffer.js.map +1 -1
- package/dist/src/ui/components/views/ExtensionsList.d.ts +6 -0
- package/dist/src/ui/components/views/ExtensionsList.js +47 -0
- package/dist/src/ui/components/views/ExtensionsList.js.map +1 -0
- package/dist/src/ui/components/views/ExtensionsList.test.d.ts +6 -0
- package/dist/src/ui/components/views/ExtensionsList.test.js +97 -0
- package/dist/src/ui/components/views/ExtensionsList.test.js.map +1 -0
- package/dist/src/ui/constants.d.ts +1 -0
- package/dist/src/ui/constants.js +1 -0
- package/dist/src/ui/constants.js.map +1 -1
- package/dist/src/ui/contexts/UIStateContext.d.ts +6 -1
- package/dist/src/ui/contexts/UIStateContext.js.map +1 -1
- package/dist/src/ui/hooks/keyToAnsi.d.ts +15 -0
- package/dist/src/ui/hooks/keyToAnsi.js +67 -0
- package/dist/src/ui/hooks/keyToAnsi.js.map +1 -0
- package/dist/src/ui/hooks/shellCommandProcessor.d.ts +2 -1
- package/dist/src/ui/hooks/shellCommandProcessor.js +60 -15
- package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/shellCommandProcessor.test.js +196 -17
- package/dist/src/ui/hooks/shellCommandProcessor.test.js.map +1 -1
- package/dist/src/ui/hooks/slashCommandProcessor.d.ts +4 -1
- package/dist/src/ui/hooks/slashCommandProcessor.js +16 -46
- package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/useAutoAcceptIndicator.d.ts +3 -2
- package/dist/src/ui/hooks/useAutoAcceptIndicator.js +9 -5
- package/dist/src/ui/hooks/useAutoAcceptIndicator.js.map +1 -1
- package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js +69 -0
- package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js.map +1 -1
- package/dist/src/ui/hooks/useExtensionUpdates.d.ts +12 -0
- package/dist/src/ui/hooks/useExtensionUpdates.js +64 -0
- package/dist/src/ui/hooks/useExtensionUpdates.js.map +1 -0
- package/dist/src/ui/hooks/useExtensionUpdates.test.d.ts +6 -0
- package/dist/src/ui/hooks/useExtensionUpdates.test.js +162 -0
- package/dist/src/ui/hooks/useExtensionUpdates.test.js.map +1 -0
- package/dist/src/ui/hooks/useGeminiStream.d.ts +11 -1
- package/dist/src/ui/hooks/useGeminiStream.js +89 -26
- package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
- package/dist/src/ui/hooks/useGitBranchName.js +15 -18
- package/dist/src/ui/hooks/useGitBranchName.js.map +1 -1
- package/dist/src/ui/hooks/useGitBranchName.test.js +49 -53
- package/dist/src/ui/hooks/useGitBranchName.test.js.map +1 -1
- package/dist/src/ui/hooks/useIdeTrustListener.js +2 -2
- package/dist/src/ui/hooks/useIdeTrustListener.js.map +1 -1
- package/dist/src/ui/hooks/useQuotaAndFallback.test.js +0 -2
- package/dist/src/ui/hooks/useQuotaAndFallback.test.js.map +1 -1
- package/dist/src/ui/hooks/useReactToolScheduler.d.ts +3 -2
- package/dist/src/ui/hooks/useReactToolScheduler.js +21 -17
- package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
- package/dist/src/ui/hooks/useReverseSearchCompletion.d.ts +1 -1
- package/dist/src/ui/hooks/useReverseSearchCompletion.js +67 -20
- package/dist/src/ui/hooks/useReverseSearchCompletion.js.map +1 -1
- package/dist/src/ui/hooks/useSlashCompletion.d.ts +1 -1
- package/dist/src/ui/hooks/useSlashCompletion.js +12 -1
- package/dist/src/ui/hooks/useSlashCompletion.js.map +1 -1
- package/dist/src/ui/hooks/useSlashCompletion.test.js +14 -2
- package/dist/src/ui/hooks/useSlashCompletion.test.js.map +1 -1
- package/dist/src/ui/hooks/useToolScheduler.test.js +6 -4
- package/dist/src/ui/hooks/useToolScheduler.test.js.map +1 -1
- package/dist/src/ui/keyMatchers.test.js +8 -0
- package/dist/src/ui/keyMatchers.test.js.map +1 -1
- package/dist/src/ui/privacy/CloudFreePrivacyNotice.js +8 -8
- package/dist/src/ui/privacy/CloudFreePrivacyNotice.js.map +1 -1
- package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js +2 -2
- package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js.map +1 -1
- package/dist/src/ui/privacy/GeminiPrivacyNotice.js +2 -2
- package/dist/src/ui/privacy/GeminiPrivacyNotice.js.map +1 -1
- package/dist/src/ui/state/extensions.d.ts +15 -0
- package/dist/src/ui/state/extensions.js +17 -0
- package/dist/src/ui/state/extensions.js.map +1 -0
- package/dist/src/ui/themes/ayu.js +1 -1
- package/dist/src/ui/themes/dracula.js +2 -2
- package/dist/src/ui/themes/github-dark.js +1 -1
- package/dist/src/ui/themes/theme.js +17 -17
- package/dist/src/ui/themes/theme.js.map +1 -1
- package/dist/src/ui/types.d.ts +12 -2
- package/dist/src/ui/types.js +1 -0
- package/dist/src/ui/types.js.map +1 -1
- package/dist/src/ui/utils/CodeColorizer.js +3 -2
- package/dist/src/ui/utils/CodeColorizer.js.map +1 -1
- package/dist/src/ui/utils/InlineMarkdownRenderer.js +7 -7
- package/dist/src/ui/utils/InlineMarkdownRenderer.js.map +1 -1
- package/dist/src/ui/utils/MarkdownDisplay.js +10 -10
- package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -1
- package/dist/src/ui/utils/MarkdownDisplay.test.js +6 -2
- package/dist/src/ui/utils/MarkdownDisplay.test.js.map +1 -1
- package/dist/src/ui/utils/TableRenderer.js +4 -4
- package/dist/src/ui/utils/TableRenderer.js.map +1 -1
- package/dist/src/ui/utils/clipboardUtils.js +5 -6
- package/dist/src/ui/utils/clipboardUtils.js.map +1 -1
- package/dist/src/ui/utils/displayUtils.js +4 -4
- package/dist/src/ui/utils/displayUtils.js.map +1 -1
- package/dist/src/ui/utils/textUtils.d.ts +9 -0
- package/dist/src/ui/utils/textUtils.js +52 -3
- package/dist/src/ui/utils/textUtils.js.map +1 -1
- package/dist/src/utils/commands.d.ts +20 -0
- package/dist/src/utils/commands.js +53 -0
- package/dist/src/utils/commands.js.map +1 -0
- package/dist/src/utils/commands.test.d.ts +6 -0
- package/dist/src/utils/commands.test.js +115 -0
- package/dist/src/utils/commands.test.js.map +1 -0
- package/dist/src/utils/commentJson.d.ts +9 -0
- package/dist/src/utils/commentJson.js +48 -0
- package/dist/src/utils/commentJson.js.map +1 -0
- package/dist/src/utils/commentJson.test.d.ts +6 -0
- package/dist/src/utils/commentJson.test.js +146 -0
- package/dist/src/utils/commentJson.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +21 -0
- package/dist/src/utils/errors.js +93 -0
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/errors.test.d.ts +6 -0
- package/dist/src/utils/errors.test.js +303 -0
- package/dist/src/utils/errors.test.js.map +1 -0
- package/dist/src/utils/processUtils.d.ts +13 -0
- package/dist/src/utils/processUtils.js +18 -0
- package/dist/src/utils/processUtils.js.map +1 -0
- package/dist/src/utils/processUtils.test.d.ts +6 -0
- package/dist/src/utils/processUtils.test.js +20 -0
- package/dist/src/utils/processUtils.test.js.map +1 -0
- package/dist/src/utils/sandbox.d.ts +1 -1
- package/dist/src/utils/sandbox.js +19 -8
- package/dist/src/utils/sandbox.js.map +1 -1
- package/dist/src/utils/settingsUtils.test.js +37 -2
- package/dist/src/utils/settingsUtils.test.js.map +1 -1
- package/dist/src/validateNonInterActiveAuth.js +30 -18
- package/dist/src/validateNonInterActiveAuth.js.map +1 -1
- package/dist/src/zed-integration/schema.d.ts +22 -22
- package/dist/src/zed-integration/zedIntegration.js +10 -7
- package/dist/src/zed-integration/zedIntegration.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
|
@@ -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;
|
package/dist/src/utils/errors.js
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"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I,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -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.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I should be relaunched.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RELAUNCH_EXIT_CODE = 42;
|
|
10
|
+
/**
|
|
11
|
+
* Exits the process with a special code to signal that the parent process should relaunch it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function relaunchApp(): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { runExitCleanup } from './cleanup.js';
|
|
7
|
+
/**
|
|
8
|
+
* Exit code used to signal that the CLI should be relaunched.
|
|
9
|
+
*/
|
|
10
|
+
export const RELAUNCH_EXIT_CODE = 42;
|
|
11
|
+
/**
|
|
12
|
+
* Exits the process with a special code to signal that the parent process should relaunch it.
|
|
13
|
+
*/
|
|
14
|
+
export async function relaunchApp() {
|
|
15
|
+
await runExitCleanup();
|
|
16
|
+
process.exit(RELAUNCH_EXIT_CODE);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=processUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processUtils.js","sourceRoot":"","sources":["../../../src/utils/processUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,cAAc,EAAE,CAAC;IACvB,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { vi } from 'vitest';
|
|
7
|
+
import { RELAUNCH_EXIT_CODE, relaunchApp } from './processUtils.js';
|
|
8
|
+
import * as cleanup from './cleanup.js';
|
|
9
|
+
describe('processUtils', () => {
|
|
10
|
+
const processExit = vi
|
|
11
|
+
.spyOn(process, 'exit')
|
|
12
|
+
.mockReturnValue(undefined);
|
|
13
|
+
const runExitCleanup = vi.spyOn(cleanup, 'runExitCleanup');
|
|
14
|
+
it('should run cleanup and exit with the relaunch code', async () => {
|
|
15
|
+
await relaunchApp();
|
|
16
|
+
expect(runExitCleanup).toHaveBeenCalledTimes(1);
|
|
17
|
+
expect(processExit).toHaveBeenCalledWith(RELAUNCH_EXIT_CODE);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=processUtils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processUtils.test.js","sourceRoot":"","sources":["../../../src/utils/processUtils.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,WAAW,GAAG,EAAE;SACnB,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC;SACtB,eAAe,CAAC,SAAkB,CAAC,CAAC;IACvC,MAAM,cAAc,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAE3D,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,WAAW,EAAE,CAAC;QACpB,MAAM,CAAC,cAAc,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import type { Config, SandboxConfig } from '@google/gemini-cli-core';
|
|
7
|
-
export declare function start_sandbox(config: SandboxConfig, nodeArgs?: string[], cliConfig?: Config, cliArgs?: string[]): Promise<
|
|
7
|
+
export declare function start_sandbox(config: SandboxConfig, nodeArgs?: string[], cliConfig?: Config, cliArgs?: string[]): Promise<number>;
|
|
@@ -264,11 +264,17 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs =
|
|
|
264
264
|
await execAsync(`until timeout 0.25 curl -s http://localhost:8877; do sleep 0.25; done`);
|
|
265
265
|
}
|
|
266
266
|
// spawn child and let it inherit stdio
|
|
267
|
+
process.stdin.pause();
|
|
267
268
|
sandboxProcess = spawn(config.command, args, {
|
|
268
269
|
stdio: 'inherit',
|
|
269
270
|
});
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
return new Promise((resolve, reject) => {
|
|
272
|
+
sandboxProcess?.on('error', reject);
|
|
273
|
+
sandboxProcess?.on('close', (code) => {
|
|
274
|
+
process.stdin.resume();
|
|
275
|
+
resolve(code ?? 1);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
272
278
|
}
|
|
273
279
|
console.error(`hopping into sandbox (command: ${config.command}) ...`);
|
|
274
280
|
// determine full path for gemini-cli to distinguish linked vs installed setting
|
|
@@ -324,6 +330,8 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs =
|
|
|
324
330
|
if (process.stdin.isTTY) {
|
|
325
331
|
args.push('-t');
|
|
326
332
|
}
|
|
333
|
+
// allow access to host.docker.internal
|
|
334
|
+
args.push('--add-host', 'host.docker.internal:host-gateway');
|
|
327
335
|
// mount current directory as working directory in sandbox (set via --workdir)
|
|
328
336
|
args.push('--volume', `${workdir}:${containerWorkdir}`);
|
|
329
337
|
// mount user settings directory inside container, after creating if missing
|
|
@@ -596,18 +604,21 @@ export async function start_sandbox(config, nodeArgs = [], cliConfig, cliArgs =
|
|
|
596
604
|
await execAsync(`${config.command} network connect ${SANDBOX_NETWORK_NAME} ${SANDBOX_PROXY_NAME}`);
|
|
597
605
|
}
|
|
598
606
|
// spawn child and let it inherit stdio
|
|
607
|
+
process.stdin.pause();
|
|
599
608
|
sandboxProcess = spawn(config.command, args, {
|
|
600
609
|
stdio: 'inherit',
|
|
601
610
|
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
611
|
+
return new Promise((resolve, reject) => {
|
|
612
|
+
sandboxProcess.on('error', (err) => {
|
|
613
|
+
console.error('Sandbox process error:', err);
|
|
614
|
+
reject(err);
|
|
615
|
+
});
|
|
606
616
|
sandboxProcess?.on('close', (code, signal) => {
|
|
607
|
-
|
|
617
|
+
process.stdin.resume();
|
|
618
|
+
if (code !== 0 && code !== null) {
|
|
608
619
|
console.log(`Sandbox process exited with code: ${code}, signal: ${signal}`);
|
|
609
620
|
}
|
|
610
|
-
resolve();
|
|
621
|
+
resolve(code ?? 1);
|
|
611
622
|
});
|
|
612
623
|
});
|
|
613
624
|
}
|