Files
gemini-cli/packages/core/src/ide/detect-ide.ts
T
Shreya Keshive 8d7e4e70ff 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>
2025-11-18 09:01:16 -08:00

98 lines
2.5 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
export const IDE_DEFINITIONS = {
devin: { name: 'devin', displayName: 'Devin' },
replit: { name: 'replit', displayName: 'Replit' },
cursor: { name: 'cursor', displayName: 'Cursor' },
cloudshell: { name: 'cloudshell', displayName: 'Cloud Shell' },
codespaces: { name: 'codespaces', displayName: 'GitHub Codespaces' },
firebasestudio: { name: 'firebasestudio', displayName: 'Firebase Studio' },
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 {
name: string;
displayName: string;
}
export function isCloudShell(): boolean {
return !!(process.env['EDITOR_IN_CLOUD_SHELL'] || process.env['CLOUD_SHELL']);
}
export function detectIdeFromEnv(): IdeInfo {
if (process.env['ANTIGRAVITY_CLI_ALIAS']) {
return IDE_DEFINITIONS.antigravity;
}
if (process.env['__COG_BASHRC_SOURCED']) {
return IDE_DEFINITIONS.devin;
}
if (process.env['REPLIT_USER']) {
return IDE_DEFINITIONS.replit;
}
if (process.env['CURSOR_TRACE_ID']) {
return IDE_DEFINITIONS.cursor;
}
if (process.env['CODESPACES']) {
return IDE_DEFINITIONS.codespaces;
}
if (isCloudShell()) {
return IDE_DEFINITIONS.cloudshell;
}
if (process.env['TERM_PRODUCT'] === 'Trae') {
return IDE_DEFINITIONS.trae;
}
if (process.env['MONOSPACE_ENV']) {
return IDE_DEFINITIONS.firebasestudio;
}
return IDE_DEFINITIONS.vscode;
}
function verifyVSCode(
ide: IdeInfo,
ideProcessInfo: {
pid: number;
command: string;
},
): IdeInfo {
if (ide.name !== IDE_DEFINITIONS.vscode.name) {
return ide;
}
if (
!ideProcessInfo.command ||
ideProcessInfo.command.toLowerCase().includes('code')
) {
return IDE_DEFINITIONS.vscode;
}
return IDE_DEFINITIONS.vscodefork;
}
export function detectIde(
ideProcessInfo: {
pid: number;
command: string;
},
ideInfoFromFile?: { name?: string; displayName?: string },
): IdeInfo | undefined {
if (ideInfoFromFile?.name && ideInfoFromFile.displayName) {
return {
name: ideInfoFromFile.name,
displayName: ideInfoFromFile.displayName,
};
}
// Only VSCode-based integrations are currently supported.
if (process.env['TERM_PROGRAM'] !== 'vscode') {
return undefined;
}
const ide = detectIdeFromEnv();
return verifyVSCode(ide, ideProcessInfo);
}