Skip to content

fix: pre-load @file references from external editor prompts#20963

Merged
scidomino merged 2 commits intogoogle-gemini:mainfrom
kartikangiras:externaleditor
Mar 3, 2026
Merged

fix: pre-load @file references from external editor prompts#20963
scidomino merged 2 commits intogoogle-gemini:mainfrom
kartikangiras:externaleditor

Conversation

@kartikangiras
Copy link
Copy Markdown
Contributor

Summary

The isAtCommand function in commandUtils.ts used an overly restrictive regex. As a result, handleAtCommand was never invoked, the files were not pre-loaded into the prompt, and the LLM had to read them itself using its read_file tool.

Details

Updated isAtCommand to import and reuse AT_COMMAND_PATH_REGEX_SOURCE from [atCommandProcessor.ts] the exact same regex that parseAllAtCommands uses internally. This guarantees that isAtCommand returns true whenever the at-command processor would find a valid @ pattern, regardless of what character precedes @:

Related Issues

fixes #14919

How to Validate

npx vitest run packages/cli/src/ui/utils/commandUtils.test.ts 

stderr | packages/cli/src/ui/utils/commandUtils.test.ts > commandUtils > getUrlOpenCommand > on unmatched OS > should return xdg-open
Unknown platform: unmatched. Attempting to open URLs with: xdg-open.

 ✓ packages/cli/src/ui/utils/commandUtils.test.ts (33 tests) 135ms

 Test Files  1 passed (1)
      Tests  33 passed (33)
   Start at  18:22:30
   Duration  3.69s (transform 1.61s, setup 0ms, collect 3.28s, tests 135ms, environment 0ms, prepare 66ms)

I have updated the tests related to it and they pass succesfully.

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

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
@kartikangiras kartikangiras requested a review from a team as a code owner March 3, 2026 13:21
@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 refactors the isAtCommand utility to accurately identify @ commands across a broader range of input scenarios. By adopting a more comprehensive regular expression, the change ensures that files referenced via @ commands are consistently recognized and pre-loaded, particularly improving the experience for users who compose prompts in external editors. This enhancement prevents the LLM from having to read files itself due to missed @ command invocations.

Highlights

  • Improved @-command detection: The isAtCommand function was updated to use a more robust regular expression, AT_COMMAND_PATH_REGEX_SOURCE, ensuring consistent detection of @<path> patterns. This resolves an issue where the previous regex was too restrictive, preventing proper pre-loading of files referenced by @ commands.
  • Enhanced external editor support: The updated logic correctly identifies @ commands even when they are preceded by punctuation (e.g., check:@file.py) or appear in multi-line prompts, which is crucial for users composing prompts in external editors.
  • Updated test suite: The test suite for commandUtils.test.ts was significantly revised to reflect the new isAtCommand behavior, including new test cases for various scenarios like non-whitespace preceding @, escaped @, and multi-line prompts, while removing outdated tests.
Changelog
  • packages/cli/src/ui/utils/commandUtils.test.ts
    • Removed a test case where a bare '@' was expected to be a valid command.
    • Added new test cases to verify isAtCommand returns true when '@' is preceded by non-whitespace characters, simulating external editor input.
    • Updated existing test descriptions to align with the new command detection logic.
    • Introduced test cases for escaped '@' commands and multi-line prompts containing '@' references.
  • packages/cli/src/ui/utils/commandUtils.ts
    • Imported AT_COMMAND_PATH_REGEX_SOURCE to reuse a consistent regex for @ command path detection.
    • Defined AT_COMMAND_DETECT_REGEX using the imported source to create a comprehensive regex for identifying @<path> patterns.
    • Refactored the isAtCommand function to utilize AT_COMMAND_DETECT_REGEX, replacing the previous startsWith('@') || /\s@/.test(query) logic.
    • Updated the JSDoc for isAtCommand to accurately describe its new behavior, emphasizing its ability to detect @ commands regardless of preceding characters for external editor compatibility.
Activity
  • The author updated relevant tests, and they passed successfully.
  • The author validated the changes on MacOS using npm run and npx.
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.

Copy link
Copy Markdown
Contributor

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

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 addresses a bug where @ commands were not correctly detected unless they were at the start of a line or preceded by whitespace. The isAtCommand function is updated to use a shared regular expression from the atCommandProcessor, centralizing the definition of an @ command for improved consistency and maintainability. No specific security vulnerabilities were identified in these changes. The implementation is sound, and the comprehensive tests validate the new, more flexible behavior, effectively resolving the described issue.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 3, 2026
@kartikangiras kartikangiras changed the title fix: update isatcommand to use regex fix: pre-load @file references from external editor prompts Mar 3, 2026
@scidomino
Copy link
Copy Markdown
Collaborator

@kartikangiras I'll go ahead and review this but in the future make sure you are assigned to a help-wanted issue before sending us a PR.

@scidomino scidomino enabled auto-merge March 3, 2026 17:29
@scidomino scidomino added this pull request to the merge queue Mar 3, 2026
@kartikangiras
Copy link
Copy Markdown
Contributor Author

kartikangiras commented Mar 3, 2026

@scidomino someone was already assigned on that issue and was not actively working on it.

Merged via the queue into google-gemini:main with commit 50af050 Mar 3, 2026
28 checks passed
@kartikangiras kartikangiras deleted the externaleditor branch March 3, 2026 17:55
jwhelangoog pushed a commit that referenced this pull request Mar 3, 2026
Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
…emini#20963)

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
…emini#20963)

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
…emini#20963)

Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@file does not work when modified in external editor

2 participants