feat(cli): unified diff display for edit_file / write_file / multi_edit (#1251)#2173
Conversation
Add configurable diff display mode for file-editing tools in CLI, addressing issue esengine#1251 (edit_file/write_file diff without git). ## Changes ### Tool output enhancement - write_file now returns unified diff format matching edit_file: - New file: \created path (N chars)\ - Overwrite: \edited path (old→new chars)\ + unified diff - Large file (>5000 lines / >100KB): summary only, no diff - All three edit tools (edit_file, write_file, multi_edit) now produce consistent output that Desktop's parseEditResult can also parse ### /diff command - \/diff\ — show current mode (default: summary) - \/diff full\ — render unified diff with +/- colors in ToolCard - \/diff summary\ — show path + stats line (edited path +N -M) - \/diff none\ — show only tool name and checkmark ### Config - New DiffDisplay type in config.ts (\summary | full | none\) - Persisted to ~/.reasonix/config.json via /diff command - loadDiffDisplay / saveDiffDisplay functions ### ToolCard renderer - In full mode, parse diff from tool output and render with colored +/- lines, hunk headers, and file stats in the card meta - Summary and none modes preserve existing behavior ### Files modified - src/tools/fs/edit.ts — add generateWriteDiff() - src/tools/filesystem.ts — write_file uses generateWriteDiff - src/config.ts — DiffDisplay type + load/save - src/cli/ui/cards/ToolCard.tsx — diff-aware rendering - src/cli/ui/slash/handlers/diff.ts — new /diff handler - src/cli/ui/slash/commands.ts — register /diff command - src/cli/ui/slash/dispatch.ts — import diffHandlers - src/i18n/EN.ts — diff handler + slash translations - src/i18n/zh-CN.ts — Chinese translations
c174152 to
7ff2069
Compare
esengine
left a comment
There was a problem hiding this comment.
LGTM. Solid feature: write_file now emits the same unified-diff output format as edit_file (consistency), the large-file guard (WRITE_DIFF_MAX_LINES=5000 / MAX_BYTES=100KB → [diff too large] summary) prevents dumping huge diffs into the transcript/context, the /diff summary|full|none command + loadDiffDisplay/saveDiffDisplay config defaults to the concise summary, and parseDiffFromOutput colorizes the card only in full mode. Tests + CI green.
One non-blocking note for later: diffDisplay is consumed UI-side only (ToolCard) — the tool output always includes the diff (model-facing, capped by the large-file guard) regardless of mode. So /diff none hides the card but the model still receives the diff. That's consistent with edit_file's existing behavior and arguably desirable (the model benefits from seeing its change), but the name none could read as 'no diff at all'; if you ever want a true token-saving mode, gating the tool output on diffDisplay would be the follow-up. Merging as-is.
Summary
Add configurable diff display mode for file-editing tools in CLI, addressing issue #1251.
Problem
Users had to run git diff after every file edit to see what changed — especially painful when working without git.
Solution
1. Enhanced write_file output with unified diff
write_file now returns diff-enriched output matching edit_file's format:
Desktop's existing parseEditResult can now parse write_file results too — bonus.
2. /diff command
/diff → show current mode (default: summary) /diff summary → path + stats (edited path +N -M) /diff full → unified diff with colored +/- lines /diff none → checkmark only3. ToolCard diff-aware rendering
In ull mode, the ToolCard renderer parses unified diff from the tool output and renders with colored +/- lines, hunk headers, and file stats in the card meta. In summary and
one modes, existing behavior is preserved.
Files Changed
Design Decisions
Verification
pm run lint — passed
pm run typecheck — passed
pm run test — 3851 tests passed (299 files), 0 failures