Merge tag 'v0.1.21' of github.com:google-gemini/gemini-cli into chore/sync-gemini-cli-v0.1.21

This commit is contained in:
mingholy.lmh
2025-08-20 22:24:50 +08:00
163 changed files with 8812 additions and 4098 deletions

View File

@@ -138,13 +138,11 @@ export const directoryCommand: SlashCommand = {
if (errors.length > 0) {
addItem(
{
type: MessageType.ERROR,
text: errors.join('\n'),
},
{ type: MessageType.ERROR, text: errors.join('\n') },
Date.now(),
);
}
return;
},
},
{

View File

@@ -40,7 +40,6 @@ describe('ideCommand', () => {
} as unknown as CommandContext;
mockConfig = {
getIdeModeFeature: vi.fn(),
getIdeMode: vi.fn(),
getIdeClient: vi.fn(() => ({
reconnect: vi.fn(),
@@ -60,14 +59,12 @@ describe('ideCommand', () => {
vi.restoreAllMocks();
});
it('should return null if ideModeFeature is not enabled', () => {
vi.mocked(mockConfig.getIdeModeFeature).mockReturnValue(false);
const command = ideCommand(mockConfig);
it('should return null if config is not provided', () => {
const command = ideCommand(null);
expect(command).toBeNull();
});
it('should return the ide command if ideModeFeature is enabled', () => {
vi.mocked(mockConfig.getIdeModeFeature).mockReturnValue(true);
it('should return the ide command', () => {
vi.mocked(mockConfig.getIdeMode).mockReturnValue(true);
vi.mocked(mockConfig.getIdeClient).mockReturnValue({
getCurrentIde: () => DetectedIde.VSCode,
@@ -85,7 +82,6 @@ describe('ideCommand', () => {
describe('status subcommand', () => {
const mockGetConnectionStatus = vi.fn();
beforeEach(() => {
vi.mocked(mockConfig.getIdeModeFeature).mockReturnValue(true);
vi.mocked(mockConfig.getIdeClient).mockReturnValue({
getConnectionStatus: mockGetConnectionStatus,
getCurrentIde: () => DetectedIde.VSCode,
@@ -162,7 +158,6 @@ describe('ideCommand', () => {
describe('install subcommand', () => {
const mockInstall = vi.fn();
beforeEach(() => {
vi.mocked(mockConfig.getIdeModeFeature).mockReturnValue(true);
vi.mocked(mockConfig.getIdeMode).mockReturnValue(true);
vi.mocked(mockConfig.getIdeClient).mockReturnValue({
getCurrentIde: () => DetectedIde.VSCode,

View File

@@ -9,7 +9,7 @@ import {
DetectedIde,
QWEN_CODE_COMPANION_EXTENSION_NAME,
IDEConnectionStatus,
getIdeDisplayName,
getIdeInfo,
getIdeInstaller,
IdeClient,
type File,
@@ -116,7 +116,7 @@ async function getIdeStatusMessageWithFiles(ideClient: IdeClient): Promise<{
}
export const ideCommand = (config: Config | null): SlashCommand | null => {
if (!config || !config.getIdeModeFeature()) {
if (!config) {
return null;
}
const ideClient = config.getIdeClient();
@@ -133,7 +133,7 @@ export const ideCommand = (config: Config | null): SlashCommand | null => {
content: `IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: ${Object.values(
DetectedIde,
)
.map((ide) => getIdeDisplayName(ide))
.map((ide) => getIdeInfo(ide).displayName)
.join(', ')}`,
}) as const,
};

View File

@@ -881,9 +881,14 @@ describe('mcpCommand', () => {
}),
getToolRegistry: vi.fn().mockResolvedValue(mockToolRegistry),
getGeminiClient: vi.fn().mockReturnValue(mockGeminiClient),
getPromptRegistry: vi.fn().mockResolvedValue({
removePromptsByServer: vi.fn(),
}),
},
},
});
// Mock the reloadCommands function
context.ui.reloadCommands = vi.fn();
const { MCPOAuthProvider } = await import('@qwen-code/qwen-code-core');
@@ -901,6 +906,7 @@ describe('mcpCommand', () => {
'test-server',
);
expect(mockGeminiClient.setTools).toHaveBeenCalled();
expect(context.ui.reloadCommands).toHaveBeenCalledTimes(1);
expect(isMessageAction(result)).toBe(true);
if (isMessageAction(result)) {
@@ -985,6 +991,8 @@ describe('mcpCommand', () => {
},
},
});
// Mock the reloadCommands function, which is new logic.
context.ui.reloadCommands = vi.fn();
const refreshCommand = mcpCommand.subCommands?.find(
(cmd) => cmd.name === 'refresh',
@@ -1002,6 +1010,7 @@ describe('mcpCommand', () => {
);
expect(mockToolRegistry.discoverMcpTools).toHaveBeenCalled();
expect(mockGeminiClient.setTools).toHaveBeenCalled();
expect(context.ui.reloadCommands).toHaveBeenCalledTimes(1);
expect(isMessageAction(result)).toBe(true);
if (isMessageAction(result)) {

View File

@@ -417,6 +417,9 @@ const authCommand: SlashCommand = {
await geminiClient.setTools();
}
// Reload the slash commands to reflect the changes.
context.ui.reloadCommands();
return {
type: 'message',
messageType: 'info',
@@ -507,6 +510,9 @@ const refreshCommand: SlashCommand = {
await geminiClient.setTools();
}
// Reload the slash commands to reflect the changes.
context.ui.reloadCommands();
return getMcpStatus(context, false, false, false);
},
};

View File

@@ -0,0 +1,85 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { terminalSetupCommand } from './terminalSetupCommand.js';
import * as terminalSetupModule from '../utils/terminalSetup.js';
import { CommandContext } from './types.js';
vi.mock('../utils/terminalSetup.js');
describe('terminalSetupCommand', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should have correct metadata', () => {
expect(terminalSetupCommand.name).toBe('terminal-setup');
expect(terminalSetupCommand.description).toContain('multiline input');
expect(terminalSetupCommand.kind).toBe('built-in');
});
it('should return success message when terminal setup succeeds', async () => {
vi.spyOn(terminalSetupModule, 'terminalSetup').mockResolvedValue({
success: true,
message: 'Terminal configured successfully',
});
const result = await terminalSetupCommand.action({} as CommandContext, '');
expect(result).toEqual({
type: 'message',
content: 'Terminal configured successfully',
messageType: 'info',
});
});
it('should append restart message when terminal setup requires restart', async () => {
vi.spyOn(terminalSetupModule, 'terminalSetup').mockResolvedValue({
success: true,
message: 'Terminal configured successfully',
requiresRestart: true,
});
const result = await terminalSetupCommand.action({} as CommandContext, '');
expect(result).toEqual({
type: 'message',
content:
'Terminal configured successfully\n\nPlease restart your terminal for the changes to take effect.',
messageType: 'info',
});
});
it('should return error message when terminal setup fails', async () => {
vi.spyOn(terminalSetupModule, 'terminalSetup').mockResolvedValue({
success: false,
message: 'Failed to detect terminal',
});
const result = await terminalSetupCommand.action({} as CommandContext, '');
expect(result).toEqual({
type: 'message',
content: 'Failed to detect terminal',
messageType: 'error',
});
});
it('should handle exceptions from terminal setup', async () => {
vi.spyOn(terminalSetupModule, 'terminalSetup').mockRejectedValue(
new Error('Unexpected error'),
);
const result = await terminalSetupCommand.action({} as CommandContext, '');
expect(result).toEqual({
type: 'message',
content: 'Failed to configure terminal: Error: Unexpected error',
messageType: 'error',
});
});
});

View File

@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { MessageActionReturn, SlashCommand, CommandKind } from './types.js';
import { terminalSetup } from '../utils/terminalSetup.js';
/**
* Command to configure terminal keybindings for multiline input support.
*
* This command automatically detects and configures VS Code, Cursor, and Windsurf
* to support Shift+Enter and Ctrl+Enter for multiline input.
*/
export const terminalSetupCommand: SlashCommand = {
name: 'terminal-setup',
description:
'Configure terminal keybindings for multiline input (VS Code, Cursor, Windsurf)',
kind: CommandKind.BUILT_IN,
action: async (): Promise<MessageActionReturn> => {
try {
const result = await terminalSetup();
let content = result.message;
if (result.requiresRestart) {
content +=
'\n\nPlease restart your terminal for the changes to take effect.';
}
return {
type: 'message',
content,
messageType: result.success ? 'info' : 'error',
};
} catch (error) {
return {
type: 'message',
content: `Failed to configure terminal: ${error}`,
messageType: 'error',
};
}
},
};

View File

@@ -61,6 +61,7 @@ export interface CommandContext {
toggleCorgiMode: () => void;
toggleVimEnabled: () => Promise<boolean>;
setGeminiMdFileCount: (count: number) => void;
reloadCommands: () => void;
};
// Session-specific data
session: {