# Agent Review A GitLab-style code review of the uncommitted changes in a git repo, of one commit of the branch, or of everything committed on the branch, made for reviewing what a Claude Code agent just wrote. A side panel lists the changed files as a folder tree, with a picker for what to review; a tab of its own opens with a side-by-side diff with syntax colors where changed words are highlighted, each file has a "Viewed" checkbox and viewed files fold away like on GitLab, comments sit inline under the lines (one line or a range picked with "+" markers) as threads, and "Send review" sends every unsent comment to the space's Claude Code agent as one message. The agent answers each thread by appending a line to a file in `.git`, and its replies show up under the same lines. ![Agent Review](preview.png) ## What you see **Side panel** (a layout block, ~368px wide in the author's layout, rounded 10px, `t.background`, 1px `t.border`): - Header, 42px: "Review" semibold, the repo folder name in `t.muted` 11px, a `Viewed x/y` tag, then on the right a solid button "Open diff" (or "Show diff" when the repo's diff tab is open) and a `↻` refresh glyph. - Picker row (with a repo), under the header with a bottom border: a 24px rounded box filling the width, showing "Local changes" in `t.muted` on `t.raised`, or the chosen view (` · `, or "All branch changes since ") in `t.accent` with an accent border on `t.accent` at 0x14; a `▾`/`▴` glyph at the right; tooltip "Review local changes or one commit of the branch". Clicked, the list below turns into the choices: "Local changes" (sub-line "uncommitted and untracked files"), "All branch changes" ("everything committed since ", or "since the default branch" while no base is known), then a one-line accent link 11px "Base: (auto) ▸" (no "(auto)" when picked by hand; "default branch" when none), then the branch's commits (subject, sub-line ` · `), each 2 lines of 12/11px with `t.selected` on the current one; "Loading commits…" or "No commits" while there are none. The "Base" link turns the list into the base picker: a dim 11px line "Compare the branch against", "Automatic · " (sub-line "the branch this one most recently left"), then every candidate branch (sub-line "N commits since the fork"), nearest first, `t.selected` on the current choice. - File list (scrolls): a folder tree of the changed files and the files that still have threads, folders first, then by name, indented 14px per level. A folder row is 24px in `t.muted`: a `▾`/`▸` glyph and the folder name. A file row is 26px: a 12px column with an accent `✓` when viewed, the file name (dimmed once viewed), then tags 10px with a 1px border: `only this` (accent) when the diff is narrowed to this file, `N unsent` (`t.blocked`) for unsent comments, else `N threads` (dim). The last clicked file gets `t.selected`. - Status line when there's nothing to list: "Not a git repository", "No repository", "Loading…", "No changes". - Footer: when the space has more than one Claude Code agent, a chip per agent (` ·
`, accent border on the chosen one); a line `→ (
)` or "No Claude agent in this space"; buttons "Clear sent" and "Send review (N)" (disabled with no agent or nothing to send, "Sending…" while sending); under them a one-line note (dim on success, `t.blocked` on error). **Diff tab** (a tab named `Review ` in the current space, holding the mod as its only pane): - Header, 36px: "Diff", the repo name, the chosen commit (` · ` or "All branch changes since ") as an accent-bordered tag when it isn't "Local changes", a `only ` accent tag when narrowed, `N files` on the right. - One virtual list in the terminal font (`settings().font_family`, 12px): - File header 32px on `t.raised`, top/bottom border: a dim `▾` (open) or `▸` (folded), a status letter (A `t.ansi2`, D `t.ansi1`, R `t.accent`, M `t.blocked`), the path (`old → new` for renames), `binary` tag, and at the right end a 14px checkbox (filled `t.accent` with ✓ when viewed) with a dim 11px "Viewed". A folded file shows only its header. - Hunk header 22px on `t.canvas`, dim `@@ … @@` text. - Line rows 20px, two equal columns split by a 1px `t.border` line. Each column: a 16px "+" marker (a 13px rounded square, bold 11px accent "+" on `t.accent` at 0x33; solid `t.accent` with `t.accent_foreground` "+" when the line is selected; absent on an empty side), a 40px right-aligned dim line number, then the text. Lines in the selection (the comment being written, or the selected comment's lines) get a `t.accent` 0x30 background. Removed lines `t.ansi1` at 0x18 alpha on the left, added `t.ansi2` at 0x18 on the right, context on `t.background` both sides, the empty side of an unpaired line on `t.chrome`. When a removed line is paired with an added one, the changed words get a stronger 0x40 alpha of the same color. The code is syntax-colored by file extension with theme colors: keywords `t.ansi5`, strings `t.ansi2`, numbers `t.ansi3`, functions and properties/keys `t.ansi4`, types (capitalized names) and `$variables` `t.ansi6`, comments `t.dim`, the rest `t.foreground`; the word-diff background sits on top of the colors, and tabs show as 4 spaces. Languages: C-family (JS/TS, Java, Kotlin, Scala, Go, Rust, C/C++, C#, Swift, Dart, Groovy, JSONC), PHP, Python, Ruby, shell (also Dockerfile, Makefile, `.env*`), SQL (keywords any case), GraphQL, CSS/SCSS/Less, JSON, YAML, TOML/INI, HTML/XML/SVG/Vue (also `.blade.php`), Markdown (headings and inline code); other files stay plain. Long lines don't wrap or truncate: a horizontal swipe or shift + wheel scrolls the code of both columns together (line numbers stay put), up to the longest line at ~7.2px per character. - Threads under the line they're anchored to (a range: under its last line), in that line's column (old left, new right), indented 48px, replies 16px more. Each comment is a rounded box: a header line with the author ("you" for the user, else the agent's name), `lines a–b` for a range, `unsent` in `t.blocked` if unsent, and when selected the key hints on the right; then the text wrapped to the column. User comments on `t.raised` with `t.border`; agent comments with a `t.accent` border and accent-tinted background; the selected one with a `t.foreground` border on `t.selected`. - The comment box being written: accent border, a hint line ("New comment, line N · shift-click a line for a range", "New comment, lines a–b", "Reply" or "Edit" · "ctrl-s save · esc cancel") and a 4-row textarea. - A file cut at the row limits ends with a dim separator: "… N more lines not shown" (over 1500 diff lines), or "… N more lines not shown: the diff is too large, double-click the file in the sidebar to view it alone" (over the whole-list limit). - Threads whose line is gone go under "Comments no longer anchored to the diff" at the end of their file, or under "Comments on files no longer in the diff" at the end. ## How it behaves - The panel follows the focused pane's folder; in a repo's diff tab it keeps showing that repo. Outside a git repo it says so. A space on another machine works the same: git and the agent channel run there (`exec`/`readTextFile` with `on: space.machine`). - "Open diff" opens a new tab `Review ` in the current space with the diff; "Show diff" selects that tab again (switching space if it's in another one). One diff tab per repo; once it's closed, "Open diff" makes a new one. - The picker chooses what both views show, per repo: "Local changes" (the default), "All branch changes" (`git diff` from where HEAD left its base branch to HEAD, like a merge request against that branch), or one commit of the branch (that commit against its first parent). The commits listed are those since HEAD left its base, newest first, at most 50; with no fork point (e.g. on the default branch with no other branch behind it), the latest 50. - The base is, by default, found automatically: among all local and remote branches, except the current one, its upstream, `origin/` and the branches that already contain HEAD, the one with the fewest commits from its fork point to HEAD; on a tie the default branch (`origin/HEAD`, else `main`, else `master`) wins. With no candidate, the default branch. The candidates are recomputed only when HEAD moves. "Base: … ▸" in the picker lets the user pick one by hand (kept per repo) or go back to "Automatic"; picking reloads the commit list and, in the branch view, the diff. The list is re-read each time the picker opens. Picking closes the list, clears the selected file, and in the diff drops the open comment box, the selection and the manual folds. - Each view (local changes, the branch, each commit) has its own comments, Viewed marks and narrowing. A commit's diff never changes, so it's read once; local changes and the branch refresh as below. - Clicking a file scrolls the diff to it (opening/showing the diff tab). If the diff is narrowed to another file, the narrowing moves to this one. Double-click narrows the diff to that file, again shows all files. Clicking a folder folds or unfolds it (not kept across restarts). - In a diff file header, a click on the right 90px (the Viewed checkbox) toggles Viewed; Viewed stays until that file's diff changes. Viewed files start folded; a click elsewhere on the header folds or unfolds the file, and that choice holds until its Viewed state changes. - Both views refresh when files in the repo change (folder watch, local repos only) and every 10s; the diff is re-parsed only when git's output changed. - In the diff: click a line to comment on its new side (old if it only has an old side); right-click picks the side under the pointer; a click on a "+" picks that column's side. `ctrl-s` saves, `esc` cancels (both are handled by the pane, which gets the key even while the textarea has focus); `cmd-enter` in the textarea is a new line. One comment box at a time. - Ranges: the first line clicked is the anchor. With a new comment open, a click on another line's "+" (or a shift-click) on the same file and side stretches the comment from the anchor to that line, keeping the typed text; `shift-down`/`shift-up` move the far end one line at a time, skipping rows without that side. A "+" on the far end drops it (the range shrinks one line toward the anchor), a "+" on the anchor moves the anchor one line inward, and a "+" on the only selected line closes the comment. Selecting a saved comment highlights its lines. - Click a comment to select it; with it selected `r` replies, `e` edits and `d`/`backspace` deletes (whole thread if it's the first comment). Edit and delete only for the user's own comments; agent notes can only be replied to. A second click on the selected comment replies. `esc` clears the selection. - "Send review (N)" sends one message, grouped by file, with each thread as `- file:line [thread ] — text` (`file:a-b`, plus ` (old side)` and the selected code in a fenced block for a range) and its replies, followed by the exact `jq` commands the agent runs to reply. Its first line names the view: "Review of repo ." for local changes; for a commit, `Review of commit ("")`, adding that line numbers refer to that commit and the agent should find the same code in the current files; for the branch, "Review of all changes committed on the current branch … (since it left )" ("the default branch" when no base is known). It goes to the chosen agent (or the focused one, else the one in the active tab, else the most recent) with `hc send`; the comments then count as sent. Messages over 50 KB aren't sent. - Agent replies: lines appended to `/herdr-review.jsonl` are merged into the threads within seconds and the file is emptied. A reply carries `parentId`; a new note carries `file`, `side`, `line`. A reply goes to the view of its thread even when another view is shown (a commit's or the branch's comment ids carry it); a new note goes to the view shown now. - "Clear sent" removes the threads where every user comment was sent and the agent has answered. - A new HEAD (commit, checkout) drops the threads on files no longer in the diff, and the narrowing if its file is gone. - Comments, Viewed and the narrowing are kept per repo and view, and survive restarts, as does the picked view. - No agent statuses are shown: the panel only looks for Claude Code agents (`app === "claude-code"`) with a pane in the shown space. ## Built from - Files: `mods/agent-review/main.js` (one `View` class with two views), `mods/agent-review/diff.js` (pure functions), `mods/agent-review/highlight.js` (syntax highlighter, pure functions), `mod.json` `{ "place": "none", "title": "Agent Review" }`. - Layout: a block `{ "mod": "agent-review" }` with no props is the panel. The author keeps it as the third child of a `stack` (`panel-body`) inside a `column` node `panel`, next to the shipped `files` and `changes`, and toggles it with `layout.select {stack: "panel-body", child: "review"}` + `layout.show {id: "panel"}`. - The diff tab: `tab.new {name: "Review ", space, mod: "agent-review", props: {view: "diff", root, on}}` (`on`: the space's machine, null here), through `exec("herdr-app", ["do", …])` to get the tab id back, kept in `shared("review.tabs")[root] = { tab, on }`; "Show diff" finds the space that still has that tab and runs `space.select` (if not active) and `tab.select`. `init` reads `props()` from `herdr` and shows the diff when `view === "diff"`. - Git, in one `sh -c` per refresh. Local changes: `B=$(git rev-parse -q --verify HEAD || git hash-object -t tree /dev/null)`, echo `$B` (the HEAD for pruning), `git diff $B`, then `git ls-files -z -o --exclude-standard | xargs -0 -n1 git diff --no-index -- /dev/null` for untracked files. A commit: echo the sha, `git show --format= --diff-merges=first-parent --`. The branch: the base `B` comes in as `$1` (`sh -c SCRIPT sh `); empty, it is the default branch, `git symbolic-ref -q --short refs/remotes/origin/HEAD`, else `main` if it exists, else `master`; `M=$(git merge-base HEAD "$B")`; echo `git rev-parse HEAD`, then `git diff "$M" HEAD` (no `M`: error "No common ancestor with "). The commit list: `git log -n 50 --format='%h%x09%H%x09%s%x09%cr'` over `$M..HEAD`, or `HEAD` when there's no `M` or it is HEAD itself, with the same `$1`. The base candidates (`BASES`, timeout 120s): echo `git rev-parse HEAD`, then for a first line `refs/default ` followed by `git for-each-ref --format='%(refname) %(refname:short)' refs/heads refs/remotes`, skip `*/HEAD` refs, the current branch (`git symbolic-ref -q --short HEAD`), its upstream (`git rev-parse -q --abbrev-ref '@{u}'`) and `origin/`; `m=$(git merge-base HEAD )`, skip it if missing or equal to HEAD; print `\t`. The JS sorts the lines by count with a stable sort (so the default branch, first, wins ties) and drops repeated names. All with `--no-optional-locks -c core.fsmonitor=false -c diff.autoRefreshIndex=false`, `--no-color --no-ext-diff --no-textconv`. - `diff.js`: `parseUnified` (files with status, rename, binary, the `index a..b` line, blocks of rows with line numbers), `pairSplit` (runs of `-` then `+` paired 1:1, each side carrying its syntax tokens as `tok`), `wordDiff` (LCS over `\w+|\s+|[^\w\s]` tokens, merged segments), `anchor` (re-anchoring), `mergeAgent` (JSONL into the store), `reviewMessage(root, file, threads, ids, commit)` (`commit`: the picked view, null for local changes, which sets the first line). `node diff.js` runs its asserts. - `highlight.js`: `languageOf(path)` (a language table picked by extension or file name: line/block comment markers, quote characters, keyword set, plus flags for `$` variables, CSS properties, JSON/YAML/TOML keys, HTML tags and attributes, Markdown), `tokenize(line, lang, state)` (regexes left to right → `[[text, kind]]`, `state` = the end marker of an open block comment), `annotate(blocks, path)` (run right after `parseUnified`: tokens per row as `r.ot`/`r.nt` for the old/new side, each side carrying its own block-comment state through a hunk), `SYNTAX` (token kind → theme key), `mergeChanged(tokens, segs)` (syntax tokens cut at the word-diff boundaries → `[[text, kind, changed]]`, what a cell renders). `node highlight.js` runs its asserts. - State: `shared("review.commit:")` is the picked view, `{ sha, short, subject }` (`sha` = the first 12 hex digits, or `"branch"`), or null for local changes. Each view has its store: `shared("review:")` for local changes, `shared("review:@")` for a commit or the branch, each `{ comments, viewed, scope, head }`. A user comment's id is `user:.` in a commit or branch view, `user:` for local changes. A comment is `{ id, source: "user"|"agent", author, file, side: "old"|"new", line, end?, code?, text, at, parentId, sent, ctx? }` (`end` and `code`, the selected lines' text up to 80, only for a range; `ctx` is the text of its last line); `viewed[path]` is the file's `index a..b` line. `shared("review.goto") = { root, file, n }` tells the pane where to scroll. `shared("review.base:")` is the base picked by hand, null for automatic; `shared("review.bases:") = { head, list: [{ name, n }] }` caches the candidates, nearest first, for that HEAD. - `herdr` functions: `spaces`, `panes`, `agents`, `focused`, `exec`, `theme`, `shared`/`setShared`, `settings`, `props`, `watchFolder`, `readTextFile`, `writeTextFile` (with the expected old text). gpui-base: `v_virtual_list` with per-item sizes, `VirtualListScrollHandle`, `Scrollbar`, `Textarea`/`TextareaState`. - Programs: `git`, `sh`, `xargs`, `herdr-app do`, `hc send`; the agent needs `jq`. - No art. ## Watch out - Pane props come from `props()`, not from `init`'s argument: reading `init(props)` makes the pane a second copy of the panel. - Event handlers inside virtual list items don't work: use the list's `on_item_click` / `on_item_secondary_click` and work out the item from its key; keys go to the list container via `track_focus` + `on_key_down`. To tell a click on the header's Viewed checkbox from one on the rest of the header, an `on_mouse_down` on the list's container records whether the pointer was in the right 90px, and `on_item_click` reads it. - Herdr interrupts a render that runs too long ("This view could not be re-rendered … interrupted"): keep the paired rows of each file in a cache per diff generation, so the rebuild on every comment, click or key only reassembles the list. Rebuilding every row on each selection change trips it on diffs of a few thousand lines. Cut each file to its first 1500 diff lines right after parsing (`capRows`), before highlighting; push a folded file's header and skip it before building its rows, so folded files cost nothing. - `v_virtual_list` takes at most 10000 items, past that the view is interrupted too: stop adding rows at 9000 items in all (the files after that show only their headers, plus the "too large" separator), and never push an item past the 9999th. - Pointer drags can't select lines: `on_item_click` fires only when press and release land on the same row, rows can't take their own handlers, and the list's scroll offset isn't readable, so a pointer position can't be turned into a row. Ranges are made of clicks on "+" markers, told from clicks on the rest of the row by the press's x (the first 16px of each half), and keys. - Every item needs its height in the sizes array up front, so comment text is wrapped in JS at an estimated 7.2px per character of the column width (`on_size_change`). - Clicking a comment must not open the textarea right away, or the textarea takes the keys and `e`/`d` never reach the list. - Focus the textarea after a short sleep (~50ms), once the item exists. - The panel and the pane both write the store and both read the JSONL: re-read the store right before every write, dedup agent lines by id (lines without an id get a hash of the line), and empty the file with `writeTextFile(path, "", raw)` so lines appended meanwhile aren't lost. `writeTextFile` and `watchFolder` are local only: on another machine the file is emptied with `sh -c '[ "$(wc -l < "$1")" -eq "$2" ] && : > "$1"'` (only if its line count is still the one read), and the diff refreshes on the timer. - Git must not write under `.git` (the flags above), or the folder watch wakes itself forever. - The pane must stay on its own repo (`props.root`); the panel's repo changes with focus, so drop stale results when the repo or the picked view changed during a refresh, and refresh again. - The diff tab has no terminal, so the panel can't take the repo from the focused pane there: look the focused tab up in `review.tabs` first. A tab id there may belong to a closed tab: check that a space still has it before selecting it. - Both views watch `review.commit:` (and, in the branch view, `review.base:`) in render and reload when it changed; the panel and the pane switch together. - The automatic base is a guess: the nearest fork point wins, so an old branch left pointing at a commit in the middle of the current branch becomes the base and hides the commits before it. That's what picking the base by hand is for. `BASES` runs one `merge-base` and one `rev-list` per branch (~0.6s with 34 refs, seconds with hundreds), so its result is cached per HEAD, not recomputed on each refresh. - Herdr's JS engine copies the string on every `slice`, so tokenizing a very long line takes time quadratic in its length: a 40,000-character line (a generated JSON snapshot) kept a diff from loading for minutes. Lines over 2000 characters are left uncolored. - Agent lines are routed before merging: a `parentId` found in the shown store goes there; else a `user:.` prefix picks that view's store; else local changes. A new note (no `parentId`) goes to the shown view. - A mod only starts once shown: a pane opened in a hidden space does nothing until you go there. - Syntax tokens are computed once per diff generation (`annotate` on the parsed files), not in render, for the same reason. - Limits: diff lines capped at 1500 per file and the list at ~9000 rows in all (threads on hidden lines are listed as no longer anchored), lines at 4000 characters; word diff off above 400 tokens per side; no syntax colors on lines over 2000 characters; highlighting is regex-based, not a grammar: no multi-line strings (template literals, heredocs, triple quotes color only their first line), no nested languages (JS/CSS inside HTML or Vue stay uncolored), block comments carry only within a hunk and start fresh at each hunk; quoted git paths (unusual characters) aren't parsed; re-anchoring is an exact text match only; remote repos refresh every 10s only, and their JSONL is emptied by line count, not compare-and-swap; no limit on untracked files. - The author opens the panel from a "Review" tab-bar button and `cmd-shift-r` in a cloned tabs mod; that toggle also closes the space's `agent-review` panes (`panes().filter(p => p.mod === "agent-review")` → `pane.close`) and brings back the panel it covered. Without it, show the block with `layout.select` / `layout.show`. ## Done when - `herdr-app check mods/agent-review` passes and `node mods/agent-review/diff.js` and `node mods/agent-review/highlight.js` print `ok`. - In a `.ts` file's diff, keywords, strings, numbers, function names and comments show in their theme colors on both sides; a `/* … */` comment spanning several lines stays dimmed on every line; a changed word inside a string keeps the string color with the word-diff background; a file with an unknown extension shows plain text. - In a repo with a commit, changing one word of a line shows the line paired across both columns with only that word highlighted on each side; a new untracked file shows as A with an empty left column. - "Open diff" opens a tab `Review ` with the diff, and the panel keeps showing that repo while the tab is focused; from another tab "Show diff" goes back to it; clicking a file in the panel scrolls the diff to it; double-click shows only that file. - On a feature branch, the picker lists the branch's commits; picking one shows only that commit's files in both views, with the commit tag in the diff header; a comment there is sent as `Review of commit `, and switching back to "Local changes" doesn't show it. "All branch changes" shows every file changed since the base branch. - On a branch started from another feature branch (not the default branch), "Base: (auto)" is found by itself and "All branch changes" shows the same files as a merge request into it; picking `origin/main` from "Base ▸" shows everything since main, and "Automatic" goes back. - A diff with a line of 40,000 characters loads in seconds, with that line uncolored. - Clicking a line, typing and `ctrl-s` adds a comment under it, marked `unsent`, and the panel shows `1 unsent`; `r`, `e`, `d` reply, edit and delete it. - Clicking the "+" of line 10 then the "+" of line 14 highlights lines 10–14 and moves the comment box under line 14; `shift-up` shrinks it to 10–13; the "+" of line 13 shrinks it to 10–12. Saved, it shows `lines 10–12`, and the sent message has `file:10-12` with those three lines of code. - Ticking Viewed in a file's diff header folds the file and puts a ✓ by it in the panel; Viewed survives a restart and clears (unfolding the file) after that file is edited again. - Running the `jq` reply command from the sent message adds an accent-styled agent reply under the thread and empties `.git/herdr-review.jsonl`. - After committing a file, its threads disappear within 10s. - A diff of more than 10000 lines (e.g. a large generated file) opens without "interrupted": the file ends with a "… more lines not shown" separator, and double-clicking it in the panel shows it alone. A thread on a folded (Viewed) file stays with that file, not under "Comments on files no longer in the diff".