feat: launch Gemini 3 in Gemini CLI 🚀🚀🚀 (in main) (#13287)

Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com>
Co-authored-by: Sehoon Shon <sshon@google.com>
Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com>
Co-authored-by: Sandy Tao <sandytao520@icloud.com>
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
Co-authored-by: Aishanee Shah <aishaneeshah@gmail.com>
Co-authored-by: gemini-cli-robot <gemini-cli-robot@google.com>
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
Co-authored-by: Jacob Richman <jacob314@gmail.com>
Co-authored-by: joshualitt <joshualitt@google.com>
Co-authored-by: Jenna Inouye <jinouye@google.com>
This commit is contained in:
Shreya Keshive
2025-11-18 12:01:16 -05:00
committed by GitHub
parent 78075c8a37
commit 86828bb561
79 changed files with 3148 additions and 605 deletions
+6
View File
@@ -88,6 +88,12 @@ describe('detectIde', () => {
vi.stubEnv('CURSOR_TRACE_ID', '');
expect(detectIde(ideProcessInfoNoCode)).toBe(IDE_DEFINITIONS.vscodefork);
});
it('should detect AntiGravity', () => {
vi.stubEnv('TERM_PROGRAM', 'vscode');
vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', 'agy');
expect(detectIde(ideProcessInfo)).toBe(IDE_DEFINITIONS.antigravity);
});
});
describe('detectIde with ideInfoFromFile', () => {
+4
View File
@@ -14,6 +14,7 @@ export const IDE_DEFINITIONS = {
trae: { name: 'trae', displayName: 'Trae' },
vscode: { name: 'vscode', displayName: 'VS Code' },
vscodefork: { name: 'vscodefork', displayName: 'IDE' },
antigravity: { name: 'antigravity', displayName: 'Antigravity' },
} as const;
export interface IdeInfo {
@@ -26,6 +27,9 @@ export function isCloudShell(): boolean {
}
export function detectIdeFromEnv(): IdeInfo {
if (process.env['ANTIGRAVITY_CLI_ALIAS']) {
return IDE_DEFINITIONS.antigravity;
}
if (process.env['__COG_BASHRC_SOURCED']) {
return IDE_DEFINITIONS.devin;
}
+5 -4
View File
@@ -137,11 +137,12 @@ export class IdeClient {
this.trustChangeListeners.delete(listener);
}
async connect(): Promise<void> {
async connect(options: { logToConsole?: boolean } = {}): Promise<void> {
const logError = options.logToConsole ?? true;
if (!this.currentIde) {
this.setState(
IDEConnectionStatus.Disconnected,
`IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: VS Code or VS Code forks`,
`IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: Antigravity, VS Code, or VS Code forks.`,
false,
);
return;
@@ -163,7 +164,7 @@ export class IdeClient {
);
if (!isValid) {
this.setState(IDEConnectionStatus.Disconnected, error, true);
this.setState(IDEConnectionStatus.Disconnected, error, logError);
return;
}
@@ -205,7 +206,7 @@ export class IdeClient {
this.setState(
IDEConnectionStatus.Disconnected,
`Failed to connect to IDE companion extension in ${this.currentIde.displayName}. Please ensure the extension is running. To install the extension, run /ide install.`,
true,
logError,
);
}
@@ -47,6 +47,13 @@ describe('ide-installer', () => {
expect(installer).not.toBeNull();
expect(installer?.install).toEqual(expect.any(Function));
});
it('returns an AntigravityInstaller for "antigravity"', () => {
const installer = getIdeInstaller(IDE_DEFINITIONS.antigravity);
expect(installer).not.toBeNull();
expect(installer?.install).toEqual(expect.any(Function));
});
});
describe('VsCodeInstaller', () => {
@@ -188,3 +195,59 @@ describe('ide-installer', () => {
});
});
});
describe('AntigravityInstaller', () => {
function setup({
execSync = () => '',
platform = 'linux' as NodeJS.Platform,
}: {
execSync?: () => string;
platform?: NodeJS.Platform;
} = {}) {
vi.spyOn(child_process, 'execSync').mockImplementation(execSync);
const installer = getIdeInstaller(IDE_DEFINITIONS.antigravity, platform)!;
return { installer };
}
it('installs the extension using the alias', async () => {
vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', 'agy');
const { installer } = setup({});
const result = await installer.install();
expect(result.success).toBe(true);
expect(child_process.spawnSync).toHaveBeenCalledWith(
'agy',
[
'--install-extension',
'google.gemini-cli-vscode-ide-companion',
'--force',
],
{ stdio: 'pipe', shell: false },
);
});
it('returns a failure message if the alias is not set', async () => {
vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', '');
const { installer } = setup({});
const result = await installer.install();
expect(result.success).toBe(false);
expect(result.message).toContain(
'ANTIGRAVITY_CLI_ALIAS environment variable not set',
);
});
it('returns a failure message if the command is not found', async () => {
vi.stubEnv('ANTIGRAVITY_CLI_ALIAS', 'not-a-command');
const { installer } = setup({
execSync: () => {
throw new Error('Command not found');
},
});
const result = await installer.install();
expect(result.success).toBe(false);
expect(result.message).toContain('not-a-command not found');
});
});
+96 -42
View File
@@ -12,10 +12,6 @@ import * as os from 'node:os';
import { IDE_DEFINITIONS, type IdeInfo } from './detect-ide.js';
import { GEMINI_CLI_COMPANION_EXTENSION_NAME } from './constants.js';
function getVsCodeCommand(platform: NodeJS.Platform = process.platform) {
return platform === 'win32' ? 'code.cmd' : 'code';
}
export interface IdeInstaller {
install(): Promise<InstallResult>;
}
@@ -25,15 +21,15 @@ export interface InstallResult {
message: string;
}
async function findVsCodeCommand(
async function findCommand(
command: string,
platform: NodeJS.Platform = process.platform,
): Promise<string | null> {
// 1. Check PATH first.
const vscodeCommand = getVsCodeCommand(platform);
try {
if (platform === 'win32') {
const result = child_process
.execSync(`where.exe ${vscodeCommand}`)
.execSync(`where.exe ${command}`)
.toString()
.trim();
// `where.exe` can return multiple paths. Return the first one.
@@ -42,10 +38,10 @@ async function findVsCodeCommand(
return firstPath;
}
} else {
child_process.execSync(`command -v ${vscodeCommand}`, {
child_process.execSync(`command -v ${command}`, {
stdio: 'ignore',
});
return vscodeCommand;
return command;
}
} catch {
// Not in PATH, continue to check common locations.
@@ -55,38 +51,40 @@ async function findVsCodeCommand(
const locations: string[] = [];
const homeDir = os.homedir();
if (platform === 'darwin') {
// macOS
locations.push(
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
path.join(homeDir, 'Library/Application Support/Code/bin/code'),
);
} else if (platform === 'linux') {
// Linux
locations.push(
'/usr/share/code/bin/code',
'/snap/bin/code',
path.join(homeDir, '.local/share/code/bin/code'),
);
} else if (platform === 'win32') {
// Windows
locations.push(
path.join(
process.env['ProgramFiles'] || 'C:\\Program Files',
'Microsoft VS Code',
'bin',
'code.cmd',
),
path.join(
homeDir,
'AppData',
'Local',
'Programs',
'Microsoft VS Code',
'bin',
'code.cmd',
),
);
if (command === 'code' || command === 'code.cmd') {
if (platform === 'darwin') {
// macOS
locations.push(
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code',
path.join(homeDir, 'Library/Application Support/Code/bin/code'),
);
} else if (platform === 'linux') {
// Linux
locations.push(
'/usr/share/code/bin/code',
'/snap/bin/code',
path.join(homeDir, '.local/share/code/bin/code'),
);
} else if (platform === 'win32') {
// Windows
locations.push(
path.join(
process.env['ProgramFiles'] || 'C:\\Program Files',
'Microsoft VS Code',
'bin',
'code.cmd',
),
path.join(
homeDir,
'AppData',
'Local',
'Programs',
'Microsoft VS Code',
'bin',
'code.cmd',
),
);
}
}
for (const location of locations) {
@@ -105,7 +103,8 @@ class VsCodeInstaller implements IdeInstaller {
readonly ideInfo: IdeInfo,
readonly platform = process.platform,
) {
this.vsCodeCommand = findVsCodeCommand(platform);
const command = platform === 'win32' ? 'code.cmd' : 'code';
this.vsCodeCommand = findCommand(command, platform);
}
async install(): Promise<InstallResult> {
@@ -147,6 +146,59 @@ class VsCodeInstaller implements IdeInstaller {
}
}
class AntigravityInstaller implements IdeInstaller {
constructor(
readonly ideInfo: IdeInfo,
readonly platform = process.platform,
) {}
async install(): Promise<InstallResult> {
const command = process.env['ANTIGRAVITY_CLI_ALIAS'];
if (!command) {
return {
success: false,
message: 'ANTIGRAVITY_CLI_ALIAS environment variable not set.',
};
}
const commandPath = await findCommand(command, this.platform);
if (!commandPath) {
return {
success: false,
message: `${command} not found. Please ensure it is in your system's PATH.`,
};
}
try {
const result = child_process.spawnSync(
commandPath,
[
'--install-extension',
'google.gemini-cli-vscode-ide-companion',
'--force',
],
{ stdio: 'pipe', shell: this.platform === 'win32' },
);
if (result.status !== 0) {
throw new Error(
`Failed to install extension: ${result.stderr?.toString()}`,
);
}
return {
success: true,
message: `${this.ideInfo.displayName} companion extension was installed successfully.`,
};
} catch (_error) {
return {
success: false,
message: `Failed to install ${this.ideInfo.displayName} companion extension. Please try installing '${GEMINI_CLI_COMPANION_EXTENSION_NAME}' manually from the ${this.ideInfo.displayName} extension marketplace.`,
};
}
}
}
export function getIdeInstaller(
ide: IdeInfo,
platform = process.platform,
@@ -155,6 +207,8 @@ export function getIdeInstaller(
case IDE_DEFINITIONS.vscode.name:
case IDE_DEFINITIONS.firebasestudio.name:
return new VsCodeInstaller(ide, platform);
case IDE_DEFINITIONS.antigravity.name:
return new AntigravityInstaller(ide, platform);
default:
return null;
}