Skip to content

fix(cli): resolve @file:line references and prevent ghost text wrap hang - #29581

Merged
DavidAPierce merged 2 commits into
google-gemini:mainfrom
jesussamuel-byte:561555050
Oct 1, 2026
Merged

DavidAPierce merged 2 commits into
google-gemini:mainfrom
jesussamuel-byte:561555050

Conversation

@jesussamuel-byte

Copy link
Copy Markdown
Contributor

Summary

Fixes CLI hangs and resolution failures when referencing files with trailing line numbers or line ranges (e.g., @file:10, @file:10-20, @file#L10-L25), and prevents an infinite loop in InputPrompt ghost text wrapping when terminal width is narrow or contains wide characters.

Details

  • Line & Range Suffix Stripping (@google/gemini-cli-core):
    • Added and exported stripLineNumberSuffix in packages/core/src/utils/atCommandUtils.ts to strip trailing :line, :start-end, :line:col, :line:col-line:col, #L10, #L10-L25, #L10-25, and #L10-#L25 suffixes when the literal path does not exist on disk.
    • Updated resolveAtCommandPath (for both relative and absolute paths) and tryExtractPath to resolve the base file path when fs.stat fails with ENOENT on a suffixed @file token.
  • Ignore & Glob Fallback Handling (@google/gemini-cli):
    • Updated checkPermissions, .gitignore/.geminiignore filtering (shouldIgnoreFile), and the fallback glob pattern in packages/cli/src/ui/hooks/atCommandProcessor.ts to use stripLineNumberSuffix(pathName) ?? pathName. This ensures @file:line respects ignore rules and avoids triggering an expensive recursive **/*file:line* glob scan across workspace directories.
  • Ghost Text Wrapping Safeguard (@google/gemini-cli):
    • Guarded getGhostTextLines in packages/cli/src/ui/components/InputPrompt.tsx against inputWidth <= 0 and ensured the hard-wrap loop (while (stringWidth(wordToProcess) > inputWidth)) always consumes at least one code point when a multi-column character exceeds inputWidth.
  • Unit Test Coverage:
    • Added unit tests in packages/core/src/utils/atCommandUtils.test.ts, packages/cli/src/ui/hooks/atCommandProcessor.test.ts, and packages/cli/src/ui/components/InputPrompt.test.tsx.

Related Issues

Fixes #19985

How to Validate

  1. Run targeted unit tests for @ command path resolution, @ command processing, and InputPrompt:
    npx vitest run packages/core/src/utils/atCommandUtils.test.ts packages/cli/src/ui/hooks/atCommandProcessor.test.ts packages/cli/src/ui/components/InputPrompt.test.tsx
  2. Run full preflight checks (clean, build, lint, typecheck, and test suites):
    npm run preflight

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

@jesussamuel-byte
jesussamuel-byte requested a review from a team as a code owner September 30, 2026 19:49
@github-actions github-actions Bot added the size/l A large sized PR label Sep 30, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 250
  • Additions: +231
  • Deletions: -19
  • Files changed: 6

@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 improves the robustness of the CLI's file resolution logic and UI rendering. It addresses issues where file references with line or range suffixes failed to resolve correctly, and it fixes a potential hang in the input prompt's ghost text wrapping logic under constrained terminal conditions.

Highlights

  • File Reference Resolution: Implemented stripLineNumberSuffix to correctly resolve file paths containing line numbers, ranges, or GitHub-style line references (e.g., @file:10, @file#L10-L25) when the direct path does not exist on disk.
  • Glob Search Optimization: Updated path processing to use the base file path for ignore-rule filtering and glob pattern generation, preventing expensive recursive scans when referencing specific lines in a file.
  • UI Stability: Added a safeguard in InputPrompt to prevent infinite loops during ghost text wrapping when terminal width is narrow or contains multi-column characters.
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 the 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 counterproductive. 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.

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. ↩

@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 introduces robust handling for line, column, and range suffixes (such as :10, :10-20, and #L10-L25) in file paths referenced via @-commands. It adds a utility function stripLineNumberSuffix to strip these suffixes, allowing correct path resolution, permission checks, ignore checks, and glob searches on the base file path. Additionally, it fixes potential hanging issues in the CLI UI's InputPrompt component when wrapping wide characters with very small input widths or when inputWidth is zero. Comprehensive unit tests are added to verify these edge cases. There are no review comments to address, so no further feedback is provided.

@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 Sep 30, 2026
@DavidAPierce
DavidAPierce added this pull request to the merge queue Oct 1, 2026
Merged via the queue into google-gemini:main with commit 7336b08 Oct 1, 2026
33 checks passed
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. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI hangs/freezes when using @filename:line or @filename:range syntax

2 participants