# @syrigan/pi-git-bar

A git status bar for [pi](https://pi.dev) that sits directly above the input editor.

<img src="./screenshot.png" alt="The git bar in a live pi session" width="880">

*The bar above the input editor in a real pi session.*

The bar shows the repository (plus the path inside it), the current branch, what the
diff is measured against, and either line counts (`+12 -3`) or a changed-file count
(`3 files`). It refreshes right after a command/edit/write in pi and polls for
changes made elsewhere.

Compact reference:

```
╭──────────────────────────────────────────────────────╮
│  pixd  main  vs main                          +12 -3 │
╰──────────────────────────────────────────────────────╯
```

## Install

From npm:

```bash
pi install npm:@syrigan/pi-git-bar
```

From a local checkout of the [pixd monorepo](../..):

```bash
pi install ./packages/git-bar
```

Or run it for a single invocation without installing:

```bash
pi -e ./packages/git-bar
```

## Commands

Everything is under `/git-bar`:

| Command | Effect |
|---|---|
| `/git-bar hide` · `show` · `toggle` | Show or hide the bar (stops/starts polling to match) |
| `/git-bar metric lines` | Show `+12 -3` |
| `/git-bar metric files` | Show `3 files` |
| `/git-bar base head` | Diff the working tree against `HEAD` (default) |
| `/git-bar base staged` | Diff the index against `HEAD` |
| `/git-bar base session` | Diff against `HEAD` as it was when this pi session started |
| `/git-bar base main` | Diff against `main` |
| `/git-bar base upstream` | Diff against this branch's `@{upstream}` |
| `/git-bar poll 5` · `10` · `15` | Poll interval for external changes, in seconds (`0` disables) |
| `/git-bar refresh` | Re-read git now |

Subcommands, values, and the poll choices all have autocomplete in the `/` menu.

If a base ref does not exist (for example `main` in a fresh repo), the bar shows
`n/a` rather than a misleading `clean`.

## Settings

Defaults live in `settings.json` (global or project) and are overridden per session
by `/git-bar` commands:

```json
{
  "gitBar": {
    "pollSeconds": 15,
    "base": "head",
    "metric": "lines",
    "hidden": false
  }
}
```

## How it refreshes

| Trigger | When |
|---|---|
| `session_start` | Immediately, then starts the poll |
| `tool_execution_end` | Right after `bash`, `edit`, or `write` |
| `turn_end` | Backstop for any other tool-mediated change |
| poll timer | Every `pollSeconds` (default 15), for changes made outside pi |
| `/git-bar refresh` | Manually |

Refreshes are coalesced: a burst of parallel tool calls results in a single git
read, and a poll landing mid-read is deferred rather than raced. Every `git` call
has a 3s timeout, and failures leave the last known values in place.

The poll timer is session-scoped — started on `session_start`, cleared
idempotently on `session_shutdown`.

## Notes

- The widget uses pi's `ctx.ui.setWidget()` with the default `aboveEditor`
  placement, so it stacks above the editor without replacing it.
- Diff counts come from `git diff --numstat`. Untracked files are not part of a
  diff, so a repo with only untracked files reports `clean`.
- Before the first commit (`HEAD` does not exist yet), the `head` base falls back
  to combining the worktree and index diffs.

## License

MIT
