# Herdr Code Review A Source Control and code-review mod: tabbed diffs, whole-change multibuffer, file views, Neovim, and compact inline feedback on lines or ranges that can be sent to Herdr agents. ![Tabbed Changes](preview.png) ## What you see - **Panel** (dock where Herdr's `changes` block sits): 42px header (branch icon, branch, ↑/↓ counts, layers "all changes", refresh), commit box (textarea + `Commit N staged` button), then sections MERGE CHANGES / STAGED CHANGES / CHANGES with 26px rows: a 16px status badge (a rounded square with `+` added, a filled dot modified, `−` deleted, `→` renamed, `!` conflict; drawn with 1.25px strokes in the name's colour), the name coloured by change type (`ansi2` added/untracked, `ansi4` modified, `ansi1` deleted/conflict, `ansi5` renamed), folder in `dim`, and `+N −N`. There is no trailing status letter and there are no per-file-type icons. The navigator tree and the diff file headers use the same badge and colour; the single-file viewer header keeps one plain `file` icon. - **Diff tab**: 44px header with file/commit identity, counts, inline/side-by-side controls and single/all-file mode; a slim loading row only while loading; virtualized code rows and a wrapping shortcut footer. Historical reviews identify the commit and omit working-file/editor/comment actions. ## How it behaves - Row click: preview diff tab (named Changes, made once per space and reused; `shared("tabbed-changes.view")[space] = {view, tab, at}`). Double-click: pinned tab (`props.pinned`). - Hover row: Neovim, Open file, Discard (asks), Stage/Unstage. - Diff: double-click a code line to select its row. Use the Neovim button to open the file in the editor. File header rows fold on click and open the single-file diff on double-click. - Staging moves the file between sections; the preview follows it. - History drills from the current HEAD's commits into changed files, then opens an immutable single-file or all-files review. Bottom shortcut hints reflect the current mode and selection. - The default local editor action reuses the selected tab's persistent Neovim. Custom/remote editors and an absent companion retain the plain terminal path; installed-companion failures notify rather than silently falling back. ## Built from `main.js` dispatches `props.role`: panel, `diff`, `file`, `history`, `branches`, `comments` or `pane-header`. `git.js` handles status, numstat, diff rows, pairing, C-quoted patch paths, deletion metadata and editor argv. `tabs.js` opens previews, pinned/file tabs and history overlays; `editor.js` owns editor selection and captured-context companion handoff. `history.js` provides Git-object history reads; `history-view.js` owns the dialog. `shortcut-model.js` maps scoped keys to actions and `shortcuts.js` renders contextual keycaps. The existing `panel.js`, `diff.js`, `viewer.js`, `ui.js` and icon modules retain their review responsibilities. ## Watch out - `run` returns nothing: find the new tab by diffing the space's tab ids. - Virtual-list rows cannot hold handlers. - Reads use `--no-optional-locks -c core.fsmonitor=false` so the folder watch doesn't loop. - Review panes have no cwd. Resolve a recognized preview through `VIEW_KEY`; otherwise read the focused pane's saved props from the Core `herdr-app` document. Pinned diffs and file tabs use their own source, never an unrelated preview or space folder. Cache the resolved source only for that location; switching panes/spaces resets it. Standalone Source Control tabs (including an omitted role) use the space folder. The metadata query is read-only and requires `herdr-core` on PATH. ## Done when `npm test` and `herdr-app check` pass; file previews reuse the Changes tab and pinned reviews remain separate; history opens root/ordinary/merge commits without working-tree contamination; historical views cannot edit/comment on the working tree; review hints follow mode/selection without hijacking inputs; default local Enter opens the requested line in the same tab's Neovim without creating another terminal; native tree icons preserve existing navigation and editor behavior. ## Review comments Hover over a code line to reveal its gutter +. Double-click selects the row and keeps the + visible. Shift-click extends a range. Click the + or press ⌘⇧I to expand a compact inline comment thread with a stable height before and after saving directly below that row. No separate comments panel or dialog. The retained `InlineComments` View in `comments.js` is created with `cx.new` outside render and mounted inside the selected virtual-list row. It switches from the composer to saved notes after Save comment. Saved notes have a same-space idle agent picker and per-note Send to agent and Delete actions. Closed threads use a gutter dot and count on each covered line; amber flags outdated snapshots. `comment-model.js` builds per-line contexts, scopes notes, remaps unchanged diff rows after refresh and formats delivery. File rows and inline diff rows use the current version, with removed lines attached to the original version. Split views attach comments to the clicked half. Hunk headers and missing cells cannot be commented on. Shared key `tabbed-changes.comments.v1` persists repository/machine-scoped notes with path, side, line and snapshot. Drafts survive switching lines in a tab. Send calls `hc(["send", "--if", "idle", address, text])`, never force; successful sends delete the note and failures retain it. No automatic sending. Verify inline save/reopen/delete in both views, and no-agent rejection. A real idle-agent send still needs end-to-end verification. Ranges use `rangeContext` to enforce one repository, machine, path and side, consecutive visible line numbers, and at most 500 lines. `isOutdated` compares saved code with current line contexts. `sendAndRemove` deletes only after successful guarded delivery. File views reload every three seconds and refresh the inline thread references. Keyboard handling uses a tracked focus handle and `on_key_down` in the file/diff root, without replacing global key bindings. ## Remote branch comparison The panel resolves one origin default base and places a single labeled comparison control beside branch checkout. It opens All changes with the detected explicit ref. Diff tabs show only the active comparison, Local changes and Fetch origin; no separate main/master choices. `comparison.js` resolves explicit `refs/remotes/origin/main` or `master` to immutable commit SHAs, using origin/HEAD when it points to either, then main/master fallback. Compare directly with `git diff --`, including committed changes and local edits; merge-base comparison was explicitly declined. Add untracked previews as in local All changes. Remote mode also works when drilling into one file. Fetch is explicit `git fetch --no-tags origin`; no checkout, merge or push. Missing refs show an explanation. New preview requests reset toolbar overrides. Old-side comment contexts include the base ref name and captured SHA; pending comments stay visible as outdated after fetching the same branch, but main/master comments do not mix. Draft identity includes the SHA. ## Branch switching and Git controls The Source Control header stays compact, with compare (columns), review-comments (speech bubble with a count badge), history, all-changes and refresh icons. The file list fills the panel; below it, Zed-style, a branch row shows a clickable branch name/chevron and one split button: the next likely action (Fetch when in sync, Pull ↓N when behind, Push ↑N when ahead, Publish when the branch is not on origin, disabled Diverged) plus a chevron that opens a Fetch / Pull / Push menu. A one-line status appears only for warnings (diverged, confirm push to main, no repository). The commit message sits in one card with a compact Commit N button inside it, bottom-right. The shortcut footer lists only the keys that currently work. Push targets only the current local ref and configured upstream; publishing sets origin/upstream for the same branch name. Branch and upstream are rechecked for Push/Pull; Pull is fast-forward-only and disables automatic stash/rebase. No force actions. Clicking the branch name opens the same mod with role `branches`, a 520×420 dialog. `branch-picker.js` provides native Input filtering and a virtual list with local/remote/current/worktree labels. `branches.js` lists full refs, skips symbolic remote HEAD, guards stale current branch+commit, switches local branches normally, or creates a local tracking branch for a remote ref. Existing local branches with different upstreams are not silently repointed. Switch success emits a shared branch-change event so the panel refreshes immediately. Git retains compatible local edits and rejects overwrites. Branch names are argv entries, never interpolated shell commands. Test with disposable local and bare repositories; do not switch or push the user's repository merely to validate the feature. ## Responsive review navigation and diff options `read-cache.js` provides bounded read deduplication, TTL reuse, coalescing and pure memo caches; `repository.js` wraps read-only Git with root/machine/argument keys and emits invalidation events after writes. Watch callbacks coalesce for 150ms; file fallback polling is 10 seconds. Diff reloads fingerprint loaded data and skip unchanged rebuilds. Clearing a view invalidates its fingerprint so rapid switching between Show more lines and Show fewer lines cannot leave it empty. Scope identity excludes presentation options so surviving comment selections remap safely. File contexts/width/sizes are cached, and unchanged metadata does not call the retained comment child. `review-model.js` owns bounded token LCS word spans, syntax-span splitting, Git context/whitespace flags, hunk/search targets, tree flattening and horizontal comment placement. `review-controls.js` renders a 30px options toolbar, optional 34px search row, and optional 180px changed-file tree. Inputs and `VirtualListScrollHandle` are created in `init`. Navigation uses the scroll handle and does no Git I/O. Folder/file handlers are attached to the virtual list, never inside row callbacks. Search expands folded files; Alt+Up/Down moves hunks, Cmd+F opens search, Enter/Shift+Enter moves matches. Words defaults on. Context cycles 3/10/30. Ignore spaces passes `--ignore-all-space` to local and origin diff paths. Because Git -w emits new-side whitespace in context rows, mark those rows `oldContextUnavailable` and disallow original-side context comments rather than inventing a snapshot; actual removals and current-side comments remain valid. Side-by-side horizontal scrolling uses content-local pointer positions for side detection; comment placement derives visible offset from content/viewport event bounds. Cmd+Shift+I reveals the input by resetting horizontal position. Long token comparisons have a bounded whole-line fallback, preserving the underlying source text. Run `npm test`, `npm run check:herdr` (the actual native mod load/render check), and optionally `npm run benchmark`. Tests use real disposable Git repositories plus native host-only adapters. They cover option races, scope changes, unchanged refreshes, selection preservation, ignored-whitespace comment fidelity, cache invalidation/bounds, history and keyboard policy. The native command is a smoke check, not a source/label snapshot suite. Automated live verification exercised history opening and the existing-tab Neovim handoff; no physical-pointer or fresh-frame visual verification is claimed for this pass. The default comparison control uses origin/HEAD when it names main or master, then main/master fallback. Hide it if neither ref is available; Fetch origin remains accessible. Do not use the current feature branch upstream as the review base. ## History and embedded-editor contracts `listCommits(git, {limit, skip})` returns commits plus `hasMore`; log fields and records use NUL delimiters. Full SHA-1/SHA-256 object IDs identify reviews. An unborn repository is empty history; other Git failures propagate. `commitFiles` preserves NUL-delimited paths and binary counts. `commitPatch` reads commit objects only, using the empty tree for roots and first-parent comparisons for merges. `DiffTab` includes the commit in scope identity, stops working-tree watches for historical views, and disables working-tree editor/comment paths. History owns two virtual-list scroll handles and releases them on close. Key navigation keeps its selection visible; file-list index zero is the all-files review. The dialog closes only its own overlay. Review keyboard handling stays in each view and ignores inputs/modifiers; the README lists the bindings. `editor.js` captures the space, selected tab, terminal and source root before its asynchronous call to `/mods/herdr-nvim/bin/herdr-nvim open --ctx :`. It uses Herdr's native `appHome()` API, not Node-only imports. Helper spawn/transport/permission failures are not mistaken for an absent installation. The Node test adapter supplies this host API separately.