Skip to main content

Crate diffler_core

Crate diffler_core 

Source
Expand description

Core review engine for diffler: diff computation, sessions, comments, viewed marks.

This crate holds all logic with no terminal dependency, so it can be tested headless and reused by the TUI, the MCP server, and future frontends.

Modules§

classify
Which bucket a changed file belongs to, from its path alone. The rule order is the design: Generated outranks Tests so a generated fixture reads as noise, and Build outranks Config so Cargo.toml reads as a manifest.
diff
Intra-line diff: byte ranges of changed regions between a paired old/new line, used for word-level emphasis on top of line diffs.
diffalgo
Selectable line-diff algorithms, shared by every diff source. Myers, Minimal and Patience are git2’s own (see crate::git); Histogram and Structural (which layers reformat detection on top, in crate::syntax::intraline) run through imara-diff, since libgit2 has no histogram implementation.
feedback
Markdown export of review feedback: comments with diff context, ready to paste into any agent prompt.
git
git2 backend for the Vcs trait: the only module that may touch git2 (test fixtures aside).
highlight
Whole-file syntax highlighting via tree-sitter, sliced into per-line styled ranges. Highlighting whole files (not hunks) keeps multi-line constructs like strings correct across hunk boundaries. Unknown languages and parse failures degrade to plain (empty) ranges so rendering never breaks.
jj
jj backend for the Vcs trait: a colocated jj/git repo (.jj beside .git, as jj git init --colocate makes). Reads delegate to GitVcs, since a colocated repo keeps git’s HEAD on jj’s @- and the working copy on disk matches @, so diff, log, blame, and tree reads already answer correctly through git2. Writes shell out to the jj CLI: jj owns the operation log and working-copy snapshot, and duplicating that through git2 would fight the real source of truth.
language
What language a path is written in, the colour GitHub paints it, and the comment syntax the line counter needs.
lens
The symbol lens’s model: the names on one diff line, how far each one reaches, and every use of them on a line the diff shows. A local name reaches as far as its enclosing function; a function, method or type (a definition, a call or a type position) reaches across every file of the diff. The names come from the parse tree, so only the identifiers of the code count.
model
Diff model: what changed, organized as files -> hunks -> lines.
pairing
Pair deleted/added line runs inside a hunk and attach intra-line emphasis. Within a run, lines pair by best total similarity (delta’s homologous-line model): an unbalanced run pairs each line with its true counterpart, and lines with no counterpart stay unpaired and render plain: emphasis only ever contrasts a line against its homolog.
repo
Repository discovery and backend selection.
review
Facade tying the VCS backend, session, and store together: the one entry point the TUI and MCP layers consume.
session
Review session: comments and per-file viewed marks, reconciled against fresh diff models. Persistence lives in store.
source
What a review is of: the working tree, a single commit, a contiguous commit range, or everything since a named revision. A source has a deterministic, filesystem-safe persistence key and a human-facing label, so review state can be tracked per source and the agent can be told exactly what the human reviewed.
stats
Counting a repo, and counting a review.
store
Session persistence: one file per review source under .diffler/reviews/, atomically written, self-gitignored. The legacy single-session file .diffler/session.json is read once and migrated to reviews/working.json. A file written before a walkthrough was a source of its own carries it embedded (walkthroughs, or the older singular walkthrough); reading any such file splits each one out into its own walkthrough-<id>.json.
syntax
Tree-sitter foundation shared by highlighting, scope context, and the structural diff. Grammars are statically linked (no runtime loading, since musl-static binaries cannot dlopen); a parse failure or unknown language degrades silently to plain behavior so the UI is never blocked.
vcs
Backend-agnostic VCS interface. Everything above this trait consumes dyn Vcs; only the git and repo modules (and test fixtures) may import git2.
walkthrough
The walkthrough: the agent’s own reading order for a review, one stop per real decision, each a span of code and a short reason. A stop is an agent comment carrying a title and an anchor, so the reader replies to it, the comments pane lists it and the card renderer draws it with no second system beside the first. A walkthrough is a review source of its own (ReviewSource::Walkthrough): every comment in that source’s session is this walkthrough’s, so nothing tracks ownership beyond stops itself.