Open Code Review (OCR) — Diff engine

docs / modules / diff

← all docs

Open Code Review (OCR) — Diff engine

flowchart LR IN["Input\ngit repository + From/To refs, a commit SHA, or nothing (workspace mode)"] --> ACT["Diff engine\nEverything about turning 'what changed' into a precise, per-file diff the agent can send to the model."] ACT --> OUT["Output\n[]model.Diff — one parsed unified diff per changed file, plus resolved commit endpoints"]

Everything about turning 'what changed' into a precise, per-file diff the agent can send to the model. Package: internal/diff/.

What flows through it

flowchart LR IN["git repository + From/To refs, a commit SHA, or nothing (workspace mode)"] --> MOD["Diff engine"] MOD --> OUT["[]model.Diff — one parsed unified diff per changed file, plus resolved commit endpoints"]

Technical details

Package: internal/diff/ Depends on: gitcmd Depended on by: CLI, Review agent

What actually happens here

diff.Provider (git.go) shells out to git diff for one of three modes — workspace (all staged+unstaged+untracked), range (merge-base against a target branch), or a single commit — and gitcmd.Runner bounds concurrent git subprocesses. parser.go splits the unified diff into hunks; gitignore.go filters paths git itself would ignore; resolver.go and relocation.go are what let a later code_comment tool call be checked against real line numbers, including finding a comment's new position when a hunk shifted lines around it.

How the LLM / model version is chosen

No model calls — pure git subprocess + text parsing.

Deterministic (non-LLM) work in this module

The entire package: diff retrieval, hunk parsing, gitignore filtering, and line-number resolution/relocation are all deterministic. This is the 'precise file selection' and 'external positioning module' the README's design philosophy calls out as engineering, not AI, work.


Part of the module docs index. Full interactive version, with every module side by side: architecture.html §7. Cross-cutting mechanisms this module participates in (retry, compression, manifest, resume, hashing): LLD.