Add two-sided compare, CLI output, and a richer web UI - #4
Conversation
Walk both trees, skip junk via ignore rules, handle binaries/images/PDFs, and add stdout/JSON plus a filterable dark-mode UI so real repos are readable instead of dumped as text.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (11)
📒 Files selected for processing (33)
📝 WalkthroughWalkthroughThe change replaces the previous web-only directory comparison with a multi-format comparison engine. It adds CLI and JSON output, ignore rules, image and PDF support, configurable HTTP serving, and an interactive dashboard. ChangesDiffr comparison flow
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant Run
participant Compare
participant Output
participant HTTPServer
CLI->>Run: pass paths and flags
Run->>Compare: build Options and compare paths
Compare-->>Run: return Result
alt CLI output requested
Run->>Output: write JSON or patch
else Web output requested
Run->>HTTPServer: serve Result
HTTPServer-->>CLI: render dashboard and media
end
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR modernizes diffr by replacing the legacy diff implementation with a modular comparison engine that supports two-sided directory/file comparison, multiple file kinds (text/binary/image/PDF), richer CLI outputs (stdout patch + JSON), and a significantly expanded web UI (stats, filtering, dark mode, media viewers).
Changes:
- Replaced the old directory-walk diff implementation with a new
Compare(...)engine that produces structured results, stats, and patch output. - Added CLI output modes (JSON, patch/stdout) plus ignore/exclude controls and context/whitespace/case options.
- Expanded the web UI to include filtering, dark mode, and dedicated renderers for images/PDFs/binaries.
Reviewed changes
Copilot reviewed 33 out of 44 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/demo/right/src/util.go | Demo fixture (right tree) for identical Go helper |
| testdata/demo/right/src/app.go | Demo fixture (right tree) with changed greeting |
| testdata/demo/right/README.md | Demo fixture (right tree) README content change |
| testdata/demo/right/noise.log | Demo fixture (right tree) ignored-by-pattern example |
| testdata/demo/right/node_modules/left-pad/index.js | Demo fixture (right tree) default-exclude example |
| testdata/demo/right/data/config.json | Demo fixture (right tree) JSON config changes |
| testdata/demo/right/changelog.txt | Demo fixture (right tree) right-only file |
| testdata/demo/right/.diffrignore | Demo fixture (right tree) ignore patterns |
| testdata/demo/left/src/util.go | Demo fixture (left tree) for identical Go helper |
| testdata/demo/left/src/app.go | Demo fixture (left tree) baseline greeting |
| testdata/demo/left/README.md | Demo fixture (left tree) README baseline |
| testdata/demo/left/noise.log | Demo fixture (left tree) ignored-by-pattern example |
| testdata/demo/left/node_modules/left-pad/index.js | Demo fixture (left tree) default-exclude example |
| testdata/demo/left/deprecated.txt | Demo fixture (left tree) left-only file |
| testdata/demo/left/data/config.json | Demo fixture (left tree) JSON config baseline |
| testdata/demo/left/.diffrignore | Demo fixture (left tree) ignore patterns |
| testdata/demo/generate.go | Generator for demo fixture trees (including png/pdf/bin) |
| static/static.go | Reworked embedded web UI template (dark mode, filtering, media views) |
| pkg/diffr/text.go | Text diffing + normalization (ignore-case/whitespace) + unified diff generation |
| pkg/diffr/pdf.go | PDF text extraction and PDF-aware comparison behavior |
| pkg/diffr/kind.go | File kind sniffing (text/binary/image/pdf) and kind merging |
| pkg/diffr/image.go | Image decode, pixel diff generation, and summary logic |
| pkg/diffr/ignore.go | Default excludes + .diffrignore/.gitignore integration and --exclude support |
| pkg/diffr/handler.go | New run path (CLI vs web), web server mux, media routes, and page-data shaping |
| pkg/diffr/handler_test.go | Web template parsing + page-data behavior tests |
| pkg/diffr/diff.go | Removed legacy diff implementation |
| pkg/diffr/config.go | Added global config flags backing CLI options |
| pkg/diffr/compare.go | New core compare engine producing Result, Stats, and patch output |
| pkg/diffr/compare_test.go | Extensive test suite covering compare behaviors and output helpers |
| pkg/diffr/color.go | ANSI colorization for stdout patch output |
| pkg/diffr/cli.go | JSON output and CLI writer for stdout/patch reporting |
| pkg/diffr/binary.go | Binary hashing, size summaries, and binary-kind compare fallback |
| pkg/diffr/addr.go | Listen/display address parsing utility for web UI |
| pkg/diffr/addr_test.go | Unit tests for listen/display address parsing |
| pkg/cmd/root/root.go | Updated Cobra root command to use new runner + new flags |
| go.sum | Dependency updates for PDF + gitignore support (and test deps) |
| go.mod | Go version + dependency additions for new features |
| .github/workflows/build-check.yml | CI workflow updates (actions versions + Go version) |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| module github.com/imrajdas/diffr | ||
|
|
||
| go 1.20 | ||
| go 1.26.6 |
| - name: Set up Go | ||
| uses: actions/setup-go@v4 | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.20' | ||
| go-version: '1.26.6' |
| if u.Scheme != "" { | ||
| scheme = u.Scheme | ||
| } | ||
| if h := u.Hostname(); h != "" { | ||
| host = h | ||
| } else if u.Host != "" { | ||
| host = u.Host | ||
| } |
| case "windows": | ||
| cmd = exec.Command("cmd", "/c", "start", url) | ||
| cmd = exec.Command("cmd", "/c", "start", rawURL) | ||
| default: |
| func normalizeText(s string, opts Options) string { | ||
| if !opts.IgnoreCase && !opts.IgnoreWhitespace { | ||
| return s | ||
| } | ||
| lines := splitLines(s) | ||
| var b strings.Builder | ||
| for _, line := range lines { | ||
| line = strings.TrimSuffix(line, "\n") | ||
| if opts.IgnoreWhitespace { | ||
| line = strings.Join(strings.Fields(line), "") | ||
| } | ||
| if opts.IgnoreCase { | ||
| line = strings.ToLower(line) | ||
| } | ||
| b.WriteString(line) | ||
| b.WriteByte('\n') | ||
| } | ||
| return b.String() | ||
| } |
| func Compare(left, right string, opts Options) (*Result, error) { | ||
| start := time.Now() | ||
| if opts.Context <= 0 { | ||
| opts.Context = 3 | ||
| } |
| lb, rb := left.Bounds(), right.Bounds() | ||
| if lb.Dx()*lb.Dy() > maxPixels || rb.Dx()*rb.Dy() > maxPixels { |
This pull request introduces significant enhancements and refactoring to the core comparison logic and CLI of the
diffrtool. The main changes include a complete rewrite of the file and directory comparison logic, the addition of new CLI options for greater flexibility, improved output formatting (including colorized and JSON output), and updates to dependencies and workflow configuration.Core comparison logic and CLI improvements:
diff.gofile has been removed and replaced with a new, modular comparison engine incompare.go, which now supports more robust directory and file comparisons, improved statistics, and extensibility for different file types. [1] [2]--context,--ignore-whitespace,--ignore-case,--stdout,--json,--patch,--exclude,--ignore-file,--no-default-exclude, and--no-gitignore, enabling users to customize comparison behavior and output formats. [1] [2]color.go) and a structured JSON output mode for integration and scripting (cli.go). [1] [2]File type handling and extensibility:
Dependency and workflow updates:
Most important changes:
1. Core comparison and CLI refactor
compare.go, replacing the olddiff.go, enabling robust directory and file comparison, improved statistics, and extensibility for file types. [1] [2]cli.go.2. Output formatting and user experience
color.go.3. File type handling
4. Address parsing and web UI
addr.goandaddr_test.go. [1] [2]5. Dependency and workflow updates
These changes significantly modernize the codebase, improve usability and extensibility, and lay the groundwork for future enhancements.
Summary by CodeRabbit