Skip to content

Diff preview tool for dry-run edits - #8

Merged
tjdoomer merged 2 commits into
mainfrom
feature/diff-preview
Apr 2, 2026
Merged

tjdoomer merged 2 commits into
mainfrom
feature/diff-preview

Conversation

@tjdoomer

@tjdoomer tjdoomer commented Apr 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Dry-run edit tool returning unified diff without modifying files
  • Validates file exists, old_string found, and old_string is unique
  • Uses existing diff package dependency (createPatch)
  • Registered as Kind.Read — no confirmation needed

Test plan

  • All 1873 tests pass
  • Type-check clean

Summary by CodeRabbit

New Features

  • Added a file preview tool that performs dry-run edits and generates unified diffs, enabling review of proposed file changes without modifying the original files.
  • Supports configurable context lines for flexible diff visualization.

Dry-run edit returning unified diff for model self-review before
applying changes. Uses existing diff package dependency.
Returns a unified diff of what an edit would look like without
applying it. Validates old_string uniqueness. Uses the diff package.
@tjdoomer
tjdoomer merged commit 5accc25 into main Apr 2, 2026
@coderabbitai

coderabbitai Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a8b6e86-7031-4af6-b57e-f1706e2acd27

📥 Commits

Reviewing files that changed from the base of the PR and between 732221b and ccb196a.

📒 Files selected for processing (3)
  • docs/roadmap/11-diff-preview.md
  • packages/core/src/config/config.ts
  • packages/core/src/tools/diffPreview.ts

📝 Walkthrough

Walkthrough

This PR introduces a new diff_preview tool that performs a dry-run file edit operation. It reads a target file, validates that the old string exists exactly once, computes an in-memory replacement, and generates a unified diff output without modifying the disk. The tool is registered in the core tool registry and documented in the roadmap.

Changes

Cohort / File(s) Summary
Documentation
docs/roadmap/11-diff-preview.md
Roadmap document describing the diff_preview tool concept, validation behavior, unified diff generation with configurable context lines, and example output.
Core Tool Implementation
packages/core/src/tools/diffPreview.ts
New DiffPreviewTool class that accepts file_path, old_string, new_string, and optional context_lines parameters. Implements file reading, exact-match validation (rejecting zero or multiple matches), in-memory string replacement, and unified diff generation via the diff package.
Tool Registration
packages/core/src/config/config.ts
Registers DiffPreviewTool as an enabled core tool in the Config.createToolRegistry() method alongside existing core tools.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A preview tool hops into view,
Dry-runs your changes without a "moo!"
No files are harmed—just diffs to see,
Perfect for checking before you commit, tee-hee! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/diff-preview

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants