Repository navigation
feat(tools): read large files in part and tolerate common edit mismatches - #299
Merged
Merged
Conversation
This was referenced Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #261 (tool execution: editing, reading, and recovery from errors).
What changed
Read
lines 1-N of M), instead of an error that forces a second, ranged read.--resumerebuilds it from the transcript). After compaction, a file over the limit is referred to instead of being restored in part.Edit
matchEditfunction (src/tools/FileEditTool/matchEdit.ts) replaces the scattered matching code. After an exact match it tries, in order: desanitized tags, curly quotes, line-number prefixes copied from Read, trailing whitespace, indentation (withnew_stringre-indented by the same mapping), and written-out escapes. Each strategy must find exactly one candidate; the line-block strategies also count substring occurrences so they never replace a different spot.old_string/new_string, i.e. the text that will actually be written; the transcript and tool cards keep the model's text. If the approved input is unchanged,call()gets the model's original input and matches again; if a hook or the user changed anything,call()uses the approved input as is.new_string.Success text
new_stringor the user modified the edit.Sidecar
tool_use_completeis built only from the CLI's assistant message, so a tool card shows the same input live and after a refresh.Other
@types/lodash-esas a dev dependency: lodash-es ships no types, so its 108 importers insrcwere typed asany.Why
Third-party models often quote
old_stringwith tabs instead of spaces, missing trailing spaces, Read's line-number prefixes or escaped quotes. Each of these failed the edit and cost one or two extra round trips with the wholeold_stringresent. A Read over the limit cost a guaranteed extra round trip. Without a read-back note, models tend to Read the file again after editing it.Numbers
Measured on one large file (direct measurement, no benchmark set):
How tested
bun test: 3414 pass, 0 fail (before the rebase onto current main).bun test --randomize --seed=1on the touched test files: pass.matchEdit.test.ts(every strategy, ambiguity, prefixes, desanitize),FileEditTool.test.ts(end-to-end edits, the approved input, an Edit run throughrunToolUsewith approval as shown, a fresh copy, and a user-changedold_string/new_string),FileReadTool.test.ts(partial read, Write refusal, restore from transcript, @ attachments),postCompactFileRestore.test.ts, sidecarws-memory-events.test.ts. Each fix was checked by reverting it and seeing its test fail.QueryEngine.ts,queryHelpers.ts:66-68,pluginService.ts,client.ts,mcp.test.ts) thatanyused to hide. The root project is not type-checked in CI.Known gaps
sed -iwrites do not clear the partial-read state.new_string, so a\nthe code needs there becomes a real newline.