Skip to content

fix(core): improve editor detection on Windows - #21576

Closed
dogukanozen wants to merge 6 commits into
google-gemini:mainfrom
dogukanozen:fix/editor-detection-windows
Closed

dogukanozen wants to merge 6 commits into
google-gemini:mainfrom
dogukanozen:fix/editor-detection-windows

Conversation

@dogukanozen

@dogukanozen dogukanozen commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Improves editor detection on Windows by resolving common installation paths and refactoring command resolution to be dynamic. This ensures that VS Code and Antigravity (detected as gemini or agy) are correctly identified even when they are not in the system PATH.

Details

  • Dynamic Config: Refactored editorCommands to a function-based resolution to ensure environment variables like LOCALAPPDATA and ProgramFiles are resolved at runtime.
  • Enhanced Search: Added explicit file existence checks for common Windows installation paths for VS Code, VSCodium, and Cursor in both System and User directories.
  • Antigravity Detection: Added gemini and gemini.cmd to the detection list for the Antigravity editor, ensuring it's found across different install methods.
  • Improved Performance: Implemented direct fs.existsSync checks for absolute paths, avoiding unnecessary and potentially slow where.exe calls.
  • Updated Tests: Refactored unit tests to verify the new dynamic logic and ensure consistent cross-platform behavior.

Related Issues

Fixes #21571

How to Validate

  1. Run the updated unit tests to ensure no regressions:
    npm test -w @google/gemini-cli-core -- src/utils/editor.test.ts
    (All 147 tests should pass).

  2. Manual verification:

  • Open Gemini CLI on a Windows machine where VS Code is installed but not in PATH.
  • Run the /editor command.
  • Expected: editors should be listed as "Installed".

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@dogukanozen
dogukanozen requested a review from a team as a code owner March 7, 2026 13:53
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the editor detection mechanism on Windows by introducing dynamic command resolution and explicit checks for common installation directories. It also refines how backspace input is interpreted in Windows Terminal, leading to more accurate and reliable editor identification and input handling, particularly for users whose editors are not in their system's PATH.

Highlights

  • Dynamic Editor Configuration: Refactored editor command resolution to a function-based approach, dynamically resolving environment variables like LOCALAPPDATA and ProgramFiles at runtime for Windows.
  • Enhanced Windows Editor Detection: Added explicit file existence checks for common Windows installation paths for VS Code, VSCodium, and Cursor, improving detection even when editors are not in the system PATH.
  • Improved Antigravity Detection: Expanded the detection list for the Antigravity editor to include gemini, gemini.cmd, and agy.cmd in APPDATA, ensuring better identification across various install methods.
  • Optimized Command Existence Checks: Switched to direct fs.existsSync checks for absolute paths, reducing reliance on where.exe calls for potentially faster performance.
  • Refined Windows Terminal Backspace Handling: Implemented specific logic to correctly interpret the \b character as ctrl+backspace within Windows Terminal environments, while maintaining standard backspace behavior elsewhere.
  • Comprehensive Test Updates: Updated unit tests to cover the new dynamic logic, Windows-specific paths, and backspace handling, ensuring robust cross-platform behavior.
Changelog
  • packages/cli/src/ui/contexts/KeypressContext.test.tsx
    • Added describe, it, expect, beforeEach, afterEach to Vitest imports.
    • Introduced a new test suite for Windows Terminal backspace handling, including tests for \b and \x7f characters with and without WT_SESSION environment variable.
  • packages/cli/src/ui/contexts/KeypressContext.tsx
    • Modified the emitKeys generator to differentiate \b (Ctrl+H) from \x7f (backspace).
    • Added logic to treat \b as ctrl: true for backspace when WT_SESSION environment variable is present, specifically for Windows Terminal.
  • packages/core/src/utils/editor.test.ts
    • Mocked node:fs and imported existsSync.
    • Stubbed LOCALAPPDATA, ProgramFiles, APPDATA, and ANTIGRAVITY_CLI_ALIAS environment variables in beforeEach.
    • Expanded win32Commands lists for vscode, vscodium, cursor, emacs, and antigravity to include common installation paths and aliases.
    • Modified hasValidEditorCommand and getDiffCommand tests to use existsSync for path-based commands and execSync for non-path commands, reflecting the new logic.
    • Updated mock implementations for execSync and existsSync to handle sequential calls in tests.
  • packages/core/src/utils/editor.ts
    • Imported existsSync from node:fs.
    • Modified commandExists and commandExistsAsync functions to use existsSync for commands containing path separators (\ or /), bypassing execSync for absolute paths.
    • Refactored editorCommands from a constant object to a getEditorConfig function, allowing dynamic resolution of environment variables (LOCALAPPDATA, ProgramFiles, APPDATA, ANTIGRAVITY_CLI_ALIAS) at runtime.
    • Expanded the win32 command lists within getEditorConfig for vscode, vscodium, cursor, emacs, and antigravity to include common installation paths and aliases.
    • Ensured unique command entries using Set for antigravity's win32 and default lists.
Activity
  • The author provided a detailed summary of changes and validation steps in the PR description.
  • The author included a "Pre-Merge Checklist" indicating self-review and validation on various platforms (MacOS, Windows, Linux) and methods (npm run, npx, Docker, Podman, Seatbelt).
  • The author linked to a related issue (fix: Editor detection fails on Windows for standard installation paths #21571) that this PR fixes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dogukanozen dogukanozen closed this Mar 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively improves editor detection on Windows by adding checks for common installation paths and refactoring the configuration to be dynamic. However, it introduces potential command injection vulnerabilities due to insufficient sanitization of environment variables and command strings. It is recommended to sanitize the alias or use safer process execution methods. Additionally, there is significant duplication in test configurations that should be refactored for better maintainability.

case 'emacs':
return { win32: ['emacs.exe', 'emacs'], default: ['emacs'] };
case 'antigravity': {
const alias = process.env['ANTIGRAVITY_CLI_ALIAS'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The ANTIGRAVITY_CLI_ALIAS environment variable is used to construct a command string that is passed to execSync without proper sanitization. An attacker who can control this environment variable can execute arbitrary commands. For example, setting ANTIGRAVITY_CLI_ALIAS to agy & calc.exe would cause calc.exe to be executed when the application checks if the editor exists.

To remediate this, sanitize the alias variable to ensure it only contains alphanumeric characters, or use spawnSync with an array of arguments to avoid shell interpretation.

References
  1. Environment variables used in security-sensitive contexts, such as constructing commands, should be sanitized to prevent malicious input from leading to command injection. This aligns with the principle of sanitizing environment variables to prevent extensions from bypassing security measures, as seen in rules for stdio-based MCP server configurations and HTTP headers.

Comment on lines +91 to +93
if (cmd.includes('\\') || cmd.includes('/')) {
return existsSync(cmd);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The check if (cmd.includes('\\') || cmd.includes('/')) is insufficient to prevent command injection when cmd is passed to execSync. Shell metacharacters like &, ;, |, or backticks can still be used to inject commands.

Consider using spawnSync with an array of arguments instead of execSync with a command string to safely check for command existence.

References
  1. While the rule states not to sanitize command names for ANSI escape sequences or other C0 control characters, this comment addresses the need to sanitize for shell metacharacters (e.g., &, ;, |) to prevent command injection. These are distinct concerns, and the current behavior of not sanitizing for shell metacharacters is not desired in this context due to security implications.

Comment on lines 242 to 291
}> = [
{ editor: 'vscode', commands: ['code'], win32Commands: ['code.cmd'] },
{
editor: 'vscode',
commands: ['code'],
win32Commands: [
'code.cmd',
'code',
'C:\\LOCALAPPDATA\\Programs\\Microsoft VS Code\\bin\\code.cmd',
'C:\\Program Files\\Microsoft VS Code\\bin\\code.cmd',
],
},
{
editor: 'vscodium',
commands: ['codium'],
win32Commands: ['codium.cmd'],
win32Commands: [
'codium.cmd',
'codium',
'C:\\LOCALAPPDATA\\Programs\\VSCodium\\bin\\codium.cmd',
'C:\\Program Files\\VSCodium\\bin\\codium.cmd',
],
},
{
editor: 'windsurf',
commands: ['windsurf'],
win32Commands: ['windsurf'],
},
{ editor: 'cursor', commands: ['cursor'], win32Commands: ['cursor'] },
{
editor: 'cursor',
commands: ['cursor'],
win32Commands: [
'cursor',
'C:\\LOCALAPPDATA\\Programs\\cursor\\resources\\app\\bin\\cursor.cmd',
'C:\\Program Files\\cursor\\resources\\app\\bin\\cursor.cmd',
],
},
{ editor: 'zed', commands: ['zed', 'zeditor'], win32Commands: ['zed'] },
{
editor: 'antigravity',
commands: ['agy', 'antigravity'],
win32Commands: ['agy.cmd', 'antigravity.cmd', 'antigravity'],
commands: ['gemini', 'agy', 'antigravity'],
win32Commands: [
'gemini.cmd',
'gemini',
'agy.cmd',
'agy',
'antigravity.cmd',
'antigravity',
'C:\\APPDATA\\npm\\agy.cmd',
],
},
];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The editor configurations in this array are largely duplicated from the testCases array defined earlier in this file (lines 70-131). This duplication makes the tests harder to maintain, as changes to editor configurations must be updated in multiple places, increasing the risk of inconsistencies. To improve maintainability, I suggest refactoring to define the editor test configurations in a single, shared data structure that can be reused across both the hasValidEditorCommand and getDiffCommand test suites. You could then filter this structure as needed for each suite.

References
  1. While the rule suggests preferring hardcoded literal values in tests to ensure they are self-contained and less brittle, this comment addresses the duplication of complex test configurations within the same test file. Refactoring such configurations into a shared data structure within the test file improves maintainability without necessarily violating the principle of self-contained tests or introducing brittleness from external dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Editor detection fails on Windows for standard installation paths

2 participants