# Git Panel A VS Code–style source control column on the right of Herdr's main layout. It follows the repository of the focused terminal and shows a commit box, staged and unstaged changes with inline diffs, stage / unstage / discard, pull and push, the repo's GitHub pull requests and a colored commit graph. A **Git** pill in the top bar, next to Files and Changes, shows and hides it. ![Git Panel](preview.png) ## What you see Left to right, the window is Herdr's `main` layout (spaces and agents sidebar, tab bar, panes, Files / Changes panel, status bar) with two additions: - **Top bar:** the tab bar now shares a 42px row with a 60px block on its right. That block draws one pill in the tab bar's style: 26px high, 8px side padding, radius 6, a 14px git-branch icon and "Git" at 12px. It uses `selected` background and `foreground` text while the column is open, and `chrome` / `muted` when it is closed, with `hover` on hover. - **Git column**, 380px wide (280–800, resizable), right of the Files/Changes panel inside the 8px-padded work area. It's a card: radius 10, 1px `border`, `background` fill, 13px text. Top to bottom: - **Header:** the repo folder's name (semibold), the branch in a pill (`raised` fill, `accent` text, 11px), a spinner while loading, then ↻ (refresh) and × (hide). Under that: a 32px commit-message input ("Message (Enter to commit)"), a 28px full-width **✓ Commit** button (`solid` when there is a message and changes, `raised`/`dim` otherwise; the label is **✓ Commit All** when nothing is staged), and a **Sync ↓n ↑m** or **Publish branch** button beside it when relevant. Then "tracking " at 10px `dim`, and any error from the last action in `ansi1` with a × to dismiss. - **Sections**, each with a 28px `chrome` header: a chevron, an uppercase 11px semibold `muted` title, and a count pill on the right. - **Staged Changes** (only when something is staged) and **Changes**: 24px rows with the file name, its folder in `dim` 11px, and a monospace status letter on the right (M in `blocked`, A and untracked U in `ansi2`, D and conflicts in `ansi1`; deleted names are struck through). - **Pull Requests**: two or three lines per PR. First line: a dot (open `ansi2`, draft `dim`, merged `ansi5`, closed `ansi1`), `#number` in `dim`, and the title. Second line: the state, "this branch" in `accent` for the current branch's PR, `owner:head → base`, and `author · age`. Third line: the base repo, when the repo has more than one GitHub remote. The current branch's PRs come first, with a `selected` background. - **Graph**: the last 120 commits of all branches, remotes and tags, in date order. The lane characters from `git log --graph` are 7px monospace cells colored by lane (`ansi4, ansi5, ansi2, ansi3, ansi6, ansi1`, repeating), with each commit's `*` drawn as a `foreground` ●. Up to three ref pills come next (HEAD's branch `accent`, tags `ansi3`, remote branches `ansi5`, local `ansi2`; at most 150px each), then the subject and the relative time ("5 weeks"). ## How it behaves - **Which repo:** the focused terminal's. It refreshes every 5 seconds and whenever anything in the repo folder changes, and switches as soon as focus moves to another pane. With no repo it shows "Not a git repository: ". - **Files:** click a file to open its diff under the row. That's up to 600 lines, line numbers on the left, additions tinted `ansi2`, deletions `ansi1`, hunk headers on `raised`. Untracked files show their whole content as additions. Click it again to close it. - **Hovering a file** shows its actions. In Changes: ↺ (discard) and + (stage). ↺ turns into a red **Discard?** (**Delete?** for an untracked file) that needs a second click; moving away disarms it. In Staged Changes: − (unstage). Hovering a section header shows + (stage all) or − (unstage all). - **Commit:** Enter in the message box, or click the button. It commits what's staged; when nothing is staged it stages everything first, like VS Code. Escape leaves the input. - **Sync:** pulls (fast-forward only) when behind, then pushes when ahead. **Publish branch** pushes with `-u` when the repo has exactly one remote. With several remotes it names them and asks you to choose with `git push -u`. - **Pull requests:** for every github.com remote (a fork and its upstream), the 30 most recently updated open PRs, plus any PR for the current branch in any state. They load when the repo or branch changes and every 5 minutes; ↻ forces a reload. Clicking a PR opens it in the browser. - **Graph:** click a commit for its author, date, message and changed files. - **Folding:** click a section header. Folded sections are remembered. - **The Git pill** and the column's × both show / hide the `git` node, and the pill stays highlighted exactly while the column is shown. - Agent statuses: the panel doesn't show any (no working / blocked / done / idle styling). ## Built from - **Layout** `layouts/git-panel.json`: a clone of Herdr's `main` (v0.1.13). The `tabs` block moved into a new row `topbar` (`px: 42`, not resizable) beside a block `git-panel-button` (`px: 60`, `window_drag: true`, mod `git-panel-button`). A block `git` (`px: 380`, min 280, max 800, mod `git-panel`) was added as the last child of `work-body`. The root has `"preview": "layouts/git-panel.png"`. - **Mod `git-panel`** (`mod.json`: `{ "place": "none" }`), one `View`: - `herdr`: `spaces`, `panes`, `focused`, `exec`, `hc`, `readTextFile`, `watchFolder`, `theme`, `settings`, `run` (`layout.hide`), `window` (platform). - Programs: `git` (reads use `--no-optional-locks -c core.fsmonitor=false -c diff.autoRefreshIndex=false`), `hc get --json`, `sh` with `ps`, `pgrep` and `lsof` (finding the real folder, below), `gh api` when installed, and `open` / `xdg-open` / `cmd /c start` for PR links. - Network: `https://api.github.com/repos///pulls` when `gh` is not installed. - Shipped art it borrows: `mods/files/chevron-down.svg`, `mods/files/chevron-right.svg`, `mods/workspace-chrome/spinner.svg`. - **Mod `git-panel-button`** (`{ "place": "none" }`): reads `layout()`, finds the node `git`, and runs `layout.show` / `layout.hide`. Its art is `mods/git-panel-button/git.svg`. ## Watch out - **The real folder.** `panes()[].cwd` is the folder of the terminal's foreground program. A wrapper that owns the terminal (ghost-complete, some multiplexers) never changes folder, so after `cd` Herdr still reports the old one. The panel runs `hc get --json`, takes `foreground.pid`, walks down the first-child chain with `pgrep -P`, and uses the deepest shell's folder from `lsof -d cwd`. That works on macOS and Linux; on Windows, and for terminals on other machines, it falls back to Herdr's folder. - **Write `mod.json` before `main.js`.** If Herdr sees a mod folder without `"place": "none"`, it docks an extra copy into the shown layout as a 320px column. - **The pill's gap.** The `tabs` mod keeps 10px of padding on its right, so the gap before Git is about 7px wider than between Files and Changes. Blocks clip their content, so a negative margin squares off the pill's highlight, and a negative row `gap` is ignored. Only a clone of `tabs` removes it. - **No refresh loop:** reads must not write under `.git` (the read flags above), or `watchFolder` wakes the panel on every refresh. - **Limits:** at most 1,000 changed files are read and 200 shown per section, diffs stop at 600 lines (lines cut at 2,000 characters), and the graph has 120 commits. - **GitHub:** without `gh`, PRs use the unauthenticated API (public repos only, 60 requests an hour). Each load is one request per remote, plus one per remote pair for the current branch. - The layout is a snapshot of `main` 0.1.13 and won't pick up later changes to Herdr's `main`. ## Done when - `herdr-app check` passes for `mods/git-panel` and `mods/git-panel-button`, and `herdr-app status` shows no errors after `layout.switch {name: "git-panel"}`. - The Git pill sits right of Changes, and clicking it shows and hides the column. - Focusing a terminal that ran `cd` into a repo (also under a wrapper like ghost-complete) shows that repo's name and branch within 5 seconds. - Editing a file lists it under Changes; clicking it shows its diff; + moves it to Staged Changes; − moves it back; ↺ then **Discard?** restores it. - A message plus Enter commits, and the list empties. - In a repo with a GitHub remote, the Pull Requests section lists that repo's open PRs, and the current branch's PR is first and marked "this branch". - The Graph shows branch lines, ref pills and times, and clicking a commit shows its files.