Skip to content

Return updated line numbers with post-replace diff#20325

Closed
gundermanc wants to merge 7 commits intomainfrom
gundermanc/line-nums
Closed

Return updated line numbers with post-replace diff#20325
gundermanc wants to merge 7 commits intomainfrom
gundermanc/line-nums

Conversation

@gundermanc
Copy link
Member

@gundermanc gundermanc commented Feb 25, 2026

Summary

In the past week or so I merged #19240 which reduced the failure rate of the replace tool by ~1-2%. Shortly after, I merged #19574 which made the agent significantly faster by eliminating a bunch of read turns.

19574 unfortunately regressed replace tool success rate back to about where it was because the smaller view of the updated file meant that the agent's understanding of line numbers got out of sync without it realizing.

This change adds in a start_line, end_line, and total doc length into the response from replace, filling in these context gaps for the agent without requiring a verification read. Initial evals seem to show that the regression to replace success rate is fixed.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gundermanc, 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 introduces significant improvements to the edit tool's functionality by implementing detailed line number tracking for code modifications and standardizing newline character handling. Additionally, it integrates a new devtools package, enhancing the overall development experience with better log management and type safety within the DevTools client.

Highlights

  • Enhanced Edit Tool with Line Number Tracking: The edit tool now precisely tracks the start and end line numbers of exact string replacements, providing more granular feedback in success messages.
  • Standardized Newline Handling: Replaced direct ' ' string splits with String.fromCharCode(10) for consistent newline character processing across various replacement functions in the core edit tool.
  • DevTools Integration and Refinements: Integrated a new @google/gemini-cli-devtools package, updated tsconfig.json for proper compilation, and refined the DevTools client to improve network log handling and type safety.
Changelog
  • package-lock.json
    • Updated package dependencies, including the addition of @google/gemini-cli-devtools and setting peer: true for @modelcontextprotocol/sdk.
  • packages/cli/package.json
    • Added @google/gemini-cli-devtools as a new dependency.
  • packages/cli/tsconfig.json
    • Included a project reference to the ../devtools package.
  • packages/core/src/tools/edit.ts
    • Implemented logic to calculate and store line number ranges for exact string replacements.
    • Updated string splitting to use String.fromCharCode(10) for newlines.
    • Modified success messages to report detailed line range information.
  • packages/devtools/client/src/App.tsx
    • Modified import statements to include .js extensions.
    • Adjusted network log processing to prevent overwriting existing type fields.
    • Added explicit type annotations to forEach iterators.
  • packages/devtools/client/src/main.tsx
    • Updated the import path for the App component to include the .js extension.
  • packages/devtools/tsconfig.json
    • Configured the outDir to dist.
    • Removed allowImportingTsExtensions and noEmit compiler options.
Activity
  • The pull request description is a template and does not contain any specific activity or comments from the author or reviewers.
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
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 primarily enhances the edit tool by adding line number tracking for exact matches, which will provide more precise feedback to the language model. It also includes dependency updates to integrate a new devtools package. While the changes for line number tracking are a good improvement, there is a critical bug in the calculateRegexReplacement function where the tokenization logic has been incorrectly modified, which will likely break the regex-based replacement strategy.

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Size Change: +552 B (0%)

Total Size: 25.7 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +552 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added the priority/p1 Important and should be addressed in the near term. label Feb 25, 2026
@gundermanc gundermanc changed the title Gundermanc/line nums Return updated line numbers with post-replace diff Feb 25, 2026
@gundermanc gundermanc marked this pull request as ready for review February 25, 2026 22:08
@gundermanc gundermanc requested a review from a team as a code owner February 25, 2026 22:08
@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 25, 2026
@gundermanc gundermanc closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term. status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants