Skip to content

fix(core-tools): show ellipsis on multi-line edit snippets#28126

Open
mc856 wants to merge 2 commits into
google-gemini:mainfrom
mc856:fix/edit-snippet-ellipsis-multiline
Open

fix(core-tools): show ellipsis on multi-line edit snippets#28126
mc856 wants to merge 2 commits into
google-gemini:mainfrom
mc856:fix/edit-snippet-ellipsis-multiline

Conversation

@mc856

@mc856 mc856 commented Jun 24, 2026

Copy link
Copy Markdown

Summary

EditToolInvocation.getDescription() decided whether to append ... to the
snippet by checking the full string length. For multi-line edits whose first
line was short (≤ 30 chars), the ellipsis was skipped and the confirmation UI
looked like only a single short line changed.

New condition: firstLine.length > 30 || s.includes('\n') — ellipsis appears
whenever the snippet actually hides content from the user. CRLF handling is
unchanged from the original implementation.

Related Issues

Fixes #28110
Fixes #28109

How to Validate

npx vitest run packages/core/src/tools/edit.test.ts -t "getDescription"
# 8 passed — includes a regression case for the issue, boundary cases
# (exact 30 chars, empty new_string), and the no-change / Create paths.

Drive-by: also canonicalizes the test's tempDir via fs.realpathSync so
edit.test.ts runs cleanly on macOS (previously ~30 unrelated cases in the
same file failed locally due to /var/private/var).

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

@mc856 mc856 requested review from a team as code owners June 24, 2026 12:20
@github-actions github-actions Bot added the size/l A large sized PR label Jun 24, 2026
@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 resolves a display issue in the edit tool's confirmation UI where multi-line snippets were incorrectly presented without an ellipsis if the first line was short. The changes ensure that users are properly notified of hidden content in multi-line edits. Additionally, the PR improves test suite stability across different operating systems and removes legacy bot configuration files that are no longer in use.

Highlights

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.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 131
  • Additions: +124
  • Deletions: -7
  • Files changed: 2

@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 refactors the description snippet generation in EditTool to correctly append an ellipsis when content is hidden, adds comprehensive unit tests for these scenarios, and canonicalizes the temporary directory path in tests to resolve macOS path mismatches. It also removes several obsolete agent/skill definition files. The reviewer recommended handling CRLF line endings to prevent terminal rendering corruption and using Array.from() to avoid splitting multi-byte Unicode characters during truncation.

Comment on lines +866 to +870
const snippet = (s: string) => {
const firstLine = s.split('\n')[0];
const hasHiddenContent = firstLine.length > 30 || s.includes('\n');
return firstLine.substring(0, 30) + (hasHiddenContent ? '...' : '');
};

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

When splitting the string by \n on files with CRLF (\r\n) line endings, the resulting firstLine will retain the trailing carriage return (\r). Since this is a terminal-first CLI tool, printing a string containing a carriage return followed by an ellipsis (e.g., foo\r...) can cause the terminal cursor to reset to the beginning of the line, leading to rendering corruption where the ellipsis overwrites the start of the line.

Additionally, when truncating strings that may contain multi-byte Unicode characters (such as emojis), we should use methods that operate on grapheme clusters (like Array.from()) instead of UTF-16 code units (string.length, string.substring()) to prevent character splitting.

Suggested change
const snippet = (s: string) => {
const firstLine = s.split('\n')[0];
const hasHiddenContent = firstLine.length > 30 || s.includes('\n');
return firstLine.substring(0, 30) + (hasHiddenContent ? '...' : '');
};
const snippet = (s: string) => {
const firstLine = s.split(/\r?\n/)[0];
const chars = Array.from(firstLine);
const hasHiddenContent = chars.length > 30 || s.includes('\n');
return chars.slice(0, 30).join('') + (hasHiddenContent ? '...' : '');
};
References
  1. When truncating strings that may contain multi-byte Unicode characters (e.g., emojis), use methods that operate on grapheme clusters (like Intl.Segmenter or Array.from()) instead of UTF-16 code units (string.length, string.slice()) to prevent character splitting.

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

EditToolInvocation.getDescription() decided whether to append "..." to
the displayed snippet based on the full string length. For multi-line
edits whose first line was short, the snippet rendered without ellipsis
and the confirmation UI looked like only a single short line changed.

The ellipsis now reflects what is actually hidden from the snippet:
either the first line was truncated past 30 chars, or there are
additional lines below it.

Fixes google-gemini#28110
Fixes google-gemini#28109
@mc856 mc856 force-pushed the fix/edit-snippet-ellipsis-multiline branch from 3542b59 to 5a19cf7 Compare June 24, 2026 12:27
@github-actions github-actions Bot added the size/m A medium sized PR label Jun 24, 2026
@mc856

mc856 commented Jun 24, 2026

Copy link
Copy Markdown
Author

Force-pushed to remove an unintended 5-file deletion under tools/gemini-cli-bot/.gemini/ — those files were missing from my local snapshot of upstream (the directory is matched by the repo's **/.gemini/ gitignore, but the files were tracked before that rule was added). Restored them verbatim from upstream and re-pushed. The PR now only contains the intended edit.ts + edit.test.ts changes (+124/-7).

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release. size/l A large sized PR size/m A medium sized PR

Projects

None yet

1 participant