-
Notifications
You must be signed in to change notification settings - Fork 14.5k
feat(extensions): add support for custom themes in extensions #17327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dd57de4
feat(extensions): add support for custom themes in extensions
spencer426 e1ea92e
Merge branch 'main' into feature/custom-themes
spencer426 92bad52
feat: address code review comments for custom themes
spencer426 6a09428
Merge branch 'main' into feature/custom-themes
spencer426 c9ec1c4
fix(cli): correct mock config for extension theme tests
spencer426 5f204d9
Merge branch 'main' into feature/custom-themes
spencer426 7f3ad14
Merge branch 'main' into feature/custom-themes
spencer426 33dd1e1
Merge branch 'main' into feature/custom-themes
spencer426 686599f
feat(themes): Improve theme persistence and display
spencer426 a44d084
feat(themes): Improve theme persistence and display
spencer426 d1ab25e
Merge branch 'main' into feature/custom-themes
spencer426 e660329
Merge branch 'main' into feature/custom-themes
spencer426 b331faf
fix(cli): Correct assertion in extension-manager-themes.spec.ts
spencer426 127e02f
Merge branch 'main' into feature/custom-themes
spencer426 3d4eafe
Merge branch 'main' into feature/custom-themes
spencer426 0e7a796
Merge branch 'main' into feature/custom-themes
spencer426 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/cli/src/commands/extensions/examples/themes-example/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Themes Example | ||
|
|
||
| This is an example of a Gemini CLI extension that adds a custom theme. | ||
|
|
||
| ## How to use | ||
|
|
||
| 1. Link this extension: | ||
|
|
||
| ```bash | ||
| gemini extensions link packages/cli/src/commands/extensions/examples/themes-example | ||
| ``` | ||
|
|
||
| 2. Set the theme in your settings file (`~/.gemini/config.yaml`): | ||
|
|
||
| ```yaml | ||
| ui: | ||
| theme: 'shades-of-green-theme (themes-example)' | ||
| ``` | ||
|
|
||
| Alternatively, you can set it through the UI by running `gemini` and then | ||
| typing `/theme` and pressing Enter. | ||
|
|
||
| 3. **Observe the Changes:** | ||
|
|
||
| After setting the theme, you should see the changes reflected in the Gemini | ||
| CLI's UI. The background will be a dark green, the primary text a lighter | ||
| green, and various other UI elements will display different shades of green, | ||
| as defined in this extension's `gemini-extension.json` file. |
29 changes: 29 additions & 0 deletions
29
packages/cli/src/commands/extensions/examples/themes-example/gemini-extension.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "themes-example", | ||
| "version": "1.0.0", | ||
| "themes": [ | ||
| { | ||
| "name": "shades-of-green-theme", | ||
| "type": "custom", | ||
| "background": { | ||
| "primary": "#1a362a" | ||
| }, | ||
| "text": { | ||
| "primary": "#a6e3a1", | ||
| "secondary": "#6e8e7a", | ||
| "link": "#89e689" | ||
| }, | ||
| "status": { | ||
| "success": "#76c076", | ||
| "warning": "#d9e689", | ||
| "error": "#b34e4e" | ||
| }, | ||
| "border": { | ||
| "default": "#4a6c5a" | ||
| }, | ||
| "ui": { | ||
| "comment": "#6e8e7a" | ||
| } | ||
| } | ||
| ] | ||
| } |
226 changes: 226 additions & 0 deletions
226
packages/cli/src/config/extension-manager-themes.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,226 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import { | ||
| beforeAll, | ||
| afterAll, | ||
| beforeEach, | ||
| describe, | ||
| expect, | ||
| it, | ||
| vi, | ||
| afterEach, | ||
| } from 'vitest'; | ||
| import { createExtension } from '../test-utils/createExtension.js'; | ||
| import { ExtensionManager } from './extension-manager.js'; | ||
| import { themeManager, DEFAULT_THEME } from '../ui/themes/theme-manager.js'; | ||
| import { GEMINI_DIR, type Config } from '@google/gemini-cli-core'; | ||
| import { createTestMergedSettings, SettingScope } from './settings.js'; | ||
|
|
||
| describe('ExtensionManager theme loading', () => { | ||
| let extensionManager: ExtensionManager; | ||
| let userExtensionsDir: string; | ||
| let tempHomeDir: string; | ||
|
|
||
| beforeAll(async () => { | ||
| tempHomeDir = await fs.promises.mkdtemp( | ||
| path.join(fs.realpathSync('/tmp'), 'gemini-cli-test-'), | ||
| ); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| if (tempHomeDir) { | ||
| await fs.promises.rm(tempHomeDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| process.env['GEMINI_CLI_HOME'] = tempHomeDir; | ||
| userExtensionsDir = path.join(tempHomeDir, GEMINI_DIR, 'extensions'); | ||
| // Ensure userExtensionsDir is clean for each test | ||
| fs.rmSync(userExtensionsDir, { recursive: true, force: true }); | ||
| fs.mkdirSync(userExtensionsDir, { recursive: true }); | ||
|
|
||
| extensionManager = new ExtensionManager({ | ||
| settings: createTestMergedSettings({ | ||
| experimental: { extensionConfig: true }, | ||
| security: { blockGitExtensions: false }, | ||
| admin: { extensions: { enabled: true }, mcp: { enabled: true } }, | ||
| tools: { enableHooks: true }, | ||
| }), | ||
| requestConsent: async () => true, | ||
| requestSetting: async () => '', | ||
| workspaceDir: tempHomeDir, | ||
| enabledExtensionOverrides: [], | ||
| }); | ||
| vi.clearAllMocks(); | ||
| themeManager.clearExtensionThemes(); | ||
| themeManager.loadCustomThemes({}); | ||
| themeManager.setActiveTheme(DEFAULT_THEME.name); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete process.env['GEMINI_CLI_HOME']; | ||
| }); | ||
|
|
||
| it('should register themes from an extension when started', async () => { | ||
| const registerSpy = vi.spyOn(themeManager, 'registerExtensionThemes'); | ||
| createExtension({ | ||
| extensionsDir: userExtensionsDir, | ||
| name: 'my-theme-extension', | ||
| themes: [ | ||
| { | ||
| name: 'My-Awesome-Theme', | ||
| type: 'custom', | ||
| text: { | ||
| primary: '#FF00FF', | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| await extensionManager.loadExtensions(); | ||
|
|
||
| const mockConfig = { | ||
| getEnableExtensionReloading: () => false, | ||
| getMcpClientManager: () => ({ | ||
| startExtension: vi.fn().mockResolvedValue(undefined), | ||
| }), | ||
| getGeminiClient: () => ({ | ||
| isInitialized: () => false, | ||
| updateSystemInstruction: vi.fn(), | ||
| setTools: vi.fn(), | ||
| }), | ||
| getHookSystem: () => undefined, | ||
| getWorkingDir: () => tempHomeDir, | ||
| shouldLoadMemoryFromIncludeDirectories: () => false, | ||
| getDebugMode: () => false, | ||
| getFileExclusions: () => ({ | ||
| isIgnored: () => false, | ||
| }), | ||
| getGeminiMdFilePaths: () => [], | ||
| getMcpServers: () => ({}), | ||
| getAllowedMcpServers: () => [], | ||
| getSanitizationConfig: () => ({ | ||
| allowedEnvironmentVariables: [], | ||
| blockedEnvironmentVariables: [], | ||
| enableEnvironmentVariableRedaction: false, | ||
| }), | ||
| getShellExecutionConfig: () => ({ | ||
| terminalWidth: 80, | ||
| terminalHeight: 24, | ||
| showColor: false, | ||
| pager: 'cat', | ||
| sanitizationConfig: { | ||
| allowedEnvironmentVariables: [], | ||
| blockedEnvironmentVariables: [], | ||
| enableEnvironmentVariableRedaction: false, | ||
| }, | ||
| }), | ||
| getToolRegistry: () => ({ | ||
| getTools: () => [], | ||
| }), | ||
| getProxy: () => undefined, | ||
| getFileService: () => ({ | ||
| findFiles: async () => [], | ||
| }), | ||
| getExtensionLoader: () => ({ | ||
| getExtensions: () => [], | ||
| }), | ||
| isTrustedFolder: () => true, | ||
| getImportFormat: () => 'tree', | ||
| } as unknown as Config; | ||
|
|
||
| await extensionManager.start(mockConfig); | ||
|
|
||
| expect(registerSpy).toHaveBeenCalledWith('my-theme-extension', [ | ||
| { | ||
| name: 'My-Awesome-Theme', | ||
| type: 'custom', | ||
| text: { | ||
| primary: '#FF00FF', | ||
| }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should revert to default theme when extension is stopped', async () => { | ||
| const extensionName = 'my-theme-extension'; | ||
| const themeName = 'My-Awesome-Theme'; | ||
| const namespacedThemeName = `${themeName} (${extensionName})`; | ||
|
|
||
| createExtension({ | ||
| extensionsDir: userExtensionsDir, | ||
| name: extensionName, | ||
| themes: [ | ||
| { | ||
| name: themeName, | ||
| type: 'custom', | ||
| text: { | ||
| primary: '#FF00FF', | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| await extensionManager.loadExtensions(); | ||
|
|
||
| const mockConfig = { | ||
| getWorkingDir: () => tempHomeDir, | ||
| shouldLoadMemoryFromIncludeDirectories: () => false, | ||
| getWorkspaceContext: () => ({ | ||
| getDirectories: () => [], | ||
| }), | ||
| getDebugMode: () => false, | ||
| getFileService: () => ({ | ||
| findFiles: async () => [], | ||
| }), | ||
| getExtensionLoader: () => ({ | ||
| getExtensions: () => [], | ||
| }), | ||
| isTrustedFolder: () => true, | ||
| getImportFormat: () => 'tree', | ||
| getFileFilteringOptions: () => ({ | ||
| respectGitIgnore: true, | ||
| respectGeminiIgnore: true, | ||
| }), | ||
| getDiscoveryMaxDirs: () => 200, | ||
| getMcpClientManager: () => ({ | ||
| getMcpInstructions: () => '', | ||
| startExtension: vi.fn().mockResolvedValue(undefined), | ||
| stopExtension: vi.fn().mockResolvedValue(undefined), | ||
| }), | ||
| setUserMemory: vi.fn(), | ||
| setGeminiMdFileCount: vi.fn(), | ||
| setGeminiMdFilePaths: vi.fn(), | ||
| getEnableExtensionReloading: () => true, | ||
| getGeminiClient: () => ({ | ||
| isInitialized: () => false, | ||
| updateSystemInstruction: vi.fn(), | ||
| setTools: vi.fn(), | ||
| }), | ||
| getHookSystem: () => undefined, | ||
| getProxy: () => undefined, | ||
| getAgentRegistry: () => ({ | ||
| reload: vi.fn().mockResolvedValue(undefined), | ||
| }), | ||
| } as unknown as Config; | ||
|
|
||
| await extensionManager.start(mockConfig); | ||
|
|
||
| // Set the active theme to the one from the extension | ||
| themeManager.setActiveTheme(namespacedThemeName); | ||
| expect(themeManager.getActiveTheme().name).toBe(namespacedThemeName); | ||
|
|
||
| // Stop the extension | ||
| await extensionManager.disableExtension(extensionName, SettingScope.User); | ||
|
|
||
| // Check that the active theme has reverted to the default | ||
| expect(themeManager.getActiveTheme().name).toBe(DEFAULT_THEME.name); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test verifying that stopping an extension with a theme causes the theme to change back to the default theme if that custom theme was in use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a "Should revert to default theme when extension is stopped" spec in
packages/cli/src/config/extension-manager-themes.spec.ts