herdr-reviewr
AGENTS.md994 starsChanged 5 months agoMITView on GitHub
AGENTS.md is the primary file. CLAUDE.md is a symlink to it. herdr-reviewr is a Rust TUI (ratatui) code-review pane: it runs in a herdr pane beside a coding agent, shows the agent's diff, takes line comments, and sends them back to the agent's input. One binary, one git worktree per pane. It also runs standalone (cargo run in any repo). New behavior is designed with /brainstorming and sequenced with /planning in the conversation; the repo keeps no spec tree. The…
The file
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. AGENTS.md is the primary file. CLAUDE.md is a symlink to it.
herdr-reviewr is a Rust TUI (ratatui) code-review pane: it runs in a herdr pane beside a coding agent, shows the agent's diff, takes line comments, and sends them back to the agent's input. One binary, one git worktree per pane. It also runs standalone (cargo run in any repo).
Commands
just test— full test suite, with the herdr environment stripped so no test can reach a live agent pane. Inside herdr, run a single test the same way:env -u HERDR_WORKSPACE_ID -u HERDR_PANE_ID -u HERDR_SOCKET_PATH HERDR_BIN_PATH=false cargo test <name>(unit tests live beside the code, integration tests intests/:cargo test --test app_flow <name>).just lint— clippy with warnings as errors.just fmt/just fmt-check— rustfmt.just ci— what CI's unix job runs (fmt-check, lint, test, release build, and the idle check:scripts/idle_check.pyproves an idle, hidden, or switched pane wakes for nothing and starts no process). The Windows jobs run on CI only: dispatch them on a branch withgh workflow run ci.yml --ref <branch>.just qa-install— put a local build into the user's real herdr panes. See "QA install" below before using it.just smoke-edit— PTY smoke test of the editor path (e) against a real release binary. Unit tests stop at the argv; everything after it is terminal state, so run this after any change torun_editor, the terminal mode stack, or the editor dialects. Not part ofjust ci: it drives a pty and takes about a minute.cargo run --example snapshot -- <out-dir>— paints every theme's real frames, scene by scene, as HTML fragments for a side-by-side color review. Ad-hoc tooling for theme and color work, not a gate; run it with the herdr environment stripped.python3 scripts/bench_tui.py --binary target/release/herdr-reviewr --fixture— perceived-latency benchmark (keypress → painted frame, via PTY). Ad-hoc tooling, not a gate: run it when a change might feel slower.cargo run --release --example bench_latency -- <repo>attributes a slow number to its component calls. The one committed baseline isscripts/bench-results/baseline.json— replace it when a change moves the numbers, never add per-round runs. For an A/B, rebuild the old binary to a second target dir and interleave runs under the same system load — absolute numbers drift with background load.
Invariants
New behavior is designed with /brainstorming and sequenced with /planning in the conversation; the repo keeps no spec tree. The commit message and the changelog carry the decisions.
Code comments are one line. Two need a serious reason; three mean the code should change instead.
Load-bearing invariants. Cite them by name:
- No writes: reviewr never mutates the worktree, index, or branches. Its only git writes are private refs under
refs/worktree/reviewr/(the turn baseline and the base pick), its private index copies under<git dir>/reviewr/, and the objects a turn snapshot stores, asgit addwould. Worktree changesets (changed_from) and snapshots run on the copies, and every other git call runs withdiff.autoRefreshIndex=false(git_command), so the real index is never refreshed. - Comments survive: comments are never lost to a refresh or the agent's edits, and leave only by explicit export. The comment store is in-memory by design — do not propose persisting it.
- Continuity: place state (cursor, scroll, tab, scope, folds, selection, layout) moves only under the user's own input. World events (watcher batches, refreshes, fetch results) may only reconcile it: match by identity first (path, comment author+anchor — never row index), fall back to the nearest surviving target, clamp last. Derived state on screen may be stale, never wrong: blank a view only when its identity changed, never because the same thing gained newer content.
Architecture
The runtime is a single-threaded frame loop (event_loop in src/lib.rs): draw → sleep until input, a worker's result, or the nearest deadline (src/wake.rs) → mutate App → draw. A worktree switch (W) ends the loop and review starts a fresh one on the pick, as a pane opened there would, carrying only the view (switched_app). Every worker sends its result through a wake::Sender, which wakes the loop, so nothing polls a channel. Clipboard, agent-send, and per-file diff builds run synchronously between frames, and a terminal editor holds the loop for its whole session by design (policies/ux-responsiveness.md). Nothing runs because time passed: an idle pane starts no process and the loop does not wake. The only clocks are one-shot deadlines something armed (a status fade, the PR tab's minute refetch while it is on screen, an age label's rollover, a failure's retry). Seven things run on worker threads: the watcher (src/watch.rs — worktree, git files and the plugin config, as classified batches), the world worker (src/world.rs — full and path-limited builds), the herdr connection (src/herdr_socket.rs — visibility, this pane's ids, and turn tracking from agent status events), the search worker (src/search.rs — the fff-search engine, fed by the watcher, which runs its own scan and content-index threads), the PR input probe, the PR forge fetch (gh/glab/az), and config recovery. src/schedule.rs paces background refreshes: a 150ms debounce (30s while hidden), a budget of 20× the last refresh's time, and retries. World results land through land_world_completion: input-tagged, latest-wins, reconciled only while the view still matches (see Continuity above).
src/app.rs— theAppstate machine. Tabs (Changes/AllFiles/Pr), scopes (Uncommitted/Branch/LastTurn),Focus(files vs diff pane),Mode(Normal, theComposing/Listoverlays, and the body-replacingSearchscreen).reconcile_world()is the one place a world snapshot touches place state;reload()is the synchronous build+reconcile pair used at first tab visits and scope switches; startup and worktree switches paint, then load through the world worker (paint_then_request_load), andworld_loadkeeps a list from claiming "no changes" before that build lands. The process enters the repo it reviews (enter_repo), since herdr reports a pane's folder from it. Each file tab stashes its full place state on switch-away (swap_active_with_stash). While composing, the open diff is frozen (reconcile skips it) so a draft's anchor can't move. A markdown file shows asRow::Renderedrows, each carrying its block's source range.src/world.rs— the world worker: the pure snapshot build (WorldInput→WorldSnapshot) and the request/completion channels (latest-wins by generation).src/git.rs— every git subprocess.changed_from/changed_between(scope changesets, onegit diff --raw --numstateach),all_files(tracked + untracked + ignored vials-files— never usegit status --ignored, it walks inside ignored trees and costs seconds),snapshot_worktree(add -A+write-treeon a privateIndexCopyfor turn baselines), baseline refs.diff_sidesreads both sides of a tracked file from one full-contextgit diff, so the diff compares exactly whatgit diffcompares under anycore.autocrlf, eol attribute, or filter. reviewr never replays git's clean step.src/diff.rs—FileDiffbuild (syntect highlight both sides, similar-line pairing, word emphasis, folds) andDiffCache, keyed by path and gated by content hash. Cleared on scope switch and theme change.src/markdown.rs— the markdown renderer. Every rendered line maps to its block's source range, andsilentlists the source lines nothing renders.src/rendered.rs— a file tab'sRenderedView(choice, content, render, marks) and theRenderedIndexover its rows: unit runs, lead rows, and the one landing rule for a source line.src/marks.rs— rendered change marks. An inserted line belongs to its new block, a deleted line to its block in the old document (the old side renders too), and markers stand for the rest.src/roles.rs— the color roles. A theme's primitives derive every fill (a layer under text, stacked inLAYERS) and every ink (a text or glyph color), each resolved per fill so it reads there. Components paint roles, never a hue;legible/readablekeep content colors (syntax, markdown headings) readable on any fill, hue kept.src/theme.rs— the theme catalog: each built-in theme's primitives, syntax pairing, and the official fills it sets itself.src/ui.rs— all rendering. Row heights and wrapping recompute per frame across the visible diff, so render cost scales with open-file size.src/forge.rs+ thePrRefresh/PrCoordinatorstate machines inlib.rs— the PR snapshot. Fetches are tagged with the input (repository identity, pinned HEAD and base, the branch's published heads and pin) that produced them, and a result paints only if a fresh probe proves the input still matches. This generation/input-tag pattern is the template for moving other derived state off-thread.src/gitlab.rs/src/azure_devops.rs— theglabandazproviders behind the forge boundary inforge.rs, each mapping its CLI's payloads onto the onePrSnapshotshape.src/turn.rs— turn tracking.TurnTrackeris the pure edge machine: a resting→working edge starts a turn, and the first status after a gap starts none.TurnHost(membership, the start snapshot, the race window, the baseline ref write) runs on the herdr connection's thread and holds the pending candidate, which promotes to thelast-turnbaseline on the first watcher batch that changed content against it;src/herdr.rsholds the herdr calls: the CLI, the socket requests, and the subscription transport.src/model.rs—CommentStore(in-memory), comment anchoring (diff_anchoreddistinguishes diff comments from All-files content comments — each renders only in its own view).src/editor.rs— the editor command: the source order (editorkey,$VISUAL,$EDITOR, git'score.editor), a name-keyed dialect table (how each editor takes a line, and whether it draws in the pane), quote-aware splitting, and theeditorkey's{file}/{line}template. Pure argv resolution, spawning nowhere.run_editorinlib.rsowns the spawn, and hands the pane over for a terminal editor, blocking the frame loop for that editor's whole session.src/input.rs— where the frame loop's input comes from. Unix waits on the terminal and the wake together (wake::sys::wait), then reads with crossterm. Windows reads the console in VT input mode (input/windows.rs) and parses the bytes into the same crossterm events (input/vt.rs), so a paste arrives as oneEvent::Paste.src/wake.rs— the frame loop's wake, which every worker's result rings: a socket pair on unix, an event on Windows. Its Windows waits are, with the herdr subscription's cancel inherdr.rs, the crate's onlyunsafecalls.src/watch.rs— the watcher: rawnotifyevents classified into batches (worktree paths, git changes, the config), ignored paths filtered bygit check-ignore, one watch per directory on Linux and one recursive watch elsewhere. It also feeds turn tracking the writes it saw.src/schedule.rs— thePacerfor background refreshes (debounce, hidden debounce, budget, retries) and the sharedBackoff.src/herdr_socket.rs— the herdr connection's thread: one ordered queue of subscription lines and watcher news, the session snapshot (visibility, this pane's ids), member agents' status subscriptions with make-before-break swaps, and gaps for outages and lost events.src/export.rs— comment export: format all, send as onepane.send_textrequest over herdr's socket or copy to the clipboard, consume-on-success only.src/config.rs— plugin config: the whole file validates at startup, on every change the watcher reports, and before every action. An invalid config blocks all review work until recovery, which carries authored state.src/actions.rs— the plugin actions, run asherdr-reviewr --action <toggle|open|close|auto-open>: config validation first, then the workspace's action lock ($HERDR_PLUGIN_STATE_DIR/action-<workspace id in hex>.lock, held until an open reads as reviewr, so concurrent actions on one workspace serialize, and the auto-open event gives way to a held lock instead of waiting), then a live sweep of the workspace for panes running the review UI (pane process-infoper pane, concurrently), then the one it acts on: the focused tab's reviewr, else withtabplacement the reviewr tab whose folder shares the focused pane's worktree. Toggle closes a reviewr on screen, focuses an off-screen one's tab, and opens one if there's none.NonUiRunis the one rule for which argv is not the review UI, shared bymain.rsdispatch and that sweep.herdr-plugin.toml— plugin packaging: the pane, the toggle/open/close actions, and the worktree workspace-birth auto-open event, each runningbin/herdr-reviewrdirectly.
QA install — putting a local build into the user's herdr panes
The user tests builds in real herdr panes. The panes run the GitHub-installed plugin's binary at <plugin_root>/bin/herdr-reviewr, where herdr plugin list --json reports plugin_root (under ~/.config/herdr/plugins/), NOT anything in this worktree. Full procedure: docs/qa-install.md. Short form:
just qa-installThen tell the user to close and reopen their reviewr panes with the toggle keybinding. Done.
Three rules. Each one has already burned a session:
- Never overwrite that binary in place.
cponto the existing file keeps the inode and macOS SIGKILLs the binary at every launch (exit 137, blank panes, no log). Replace through a fresh inode and re-sign — which is exactly whatjust qa-installdoes. Do not improvise the swap by hand. - Swapping the file does not restart running panes. They keep the old binary image until closed and reopened. Refresh inside reviewr does nothing for this.
- Never script pane opens. The plugin's
open/toggleactions act on the currently focused workspace and ignoreHERDR_WORKSPACE_ID. Automating reopens stacks panes into whatever space the user is looking at. Closing viaherdr plugin action invoke close --plugin persiyanov.reviewris safe: it closes the focused tab's reviewr (withtabplacement, the focused worktree's reviewr tab). Runningherdr-reviewr --action closeby hand refuses, since actions run only as herdr plugin actions. Reopening is the user's keystroke, always. The one exception is a seat no user sits at: the Windows QA VM and CI's headless herdr, where a script opens the panes it then drives.
Rollback: just qa-restore puts back the release binary and manifest that just qa-install backed up beside them (or herdr plugin install restores the release).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

