[Bug] write_file shows no diff when overwriting an existing file, only a dump of the new content
Description
When write_file overwrites an existing file, the tool activity display shows the entire new file content (syntax-highlighted) with no comparison to what was there before. string_replace and diff_edit both show real colored diffs for their edits; write_file used for the largest, highest-risk rewrites is the one path that doesn't.
Parent: #907
Steps to Reproduce
- Ask Nanocoder to rewrite an existing file using
write_file(notstring_replace). - Look at the tool activity shown for that call.
Expected Behavior
A diff against the file's previous content added/removed lines, similar to string_replace's existing colored-diff treatment.
Actual Behavior
The full new file is rendered line-by-line with syntax highlighting. There is no reference to the old content at all, even though the tool's own return message says "File overwritten successfully."
Recording
Root Cause
source/tools/file-ops/write-file.tsx WriteFileFormatter renders args.content (the new content) line by line; it never reads or compares the file's previous contents. Note: this is unrelated to #776 (merged)
that PR stopped echoing the file content back to the model to save tokens, and intentionally didn't touch this display component, so it's still working from the raw new content only.
Suggested Fix
When the file already existed, read its previous content (already fetched elsewhere in this file for the VS Code diff view) and render a diff the same way string_replace's formatter already does, falling back to the current full-dump rendering only for brand-new files.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs on the latest
main
Hey @akramcodez, could you assign this to me ?