33AI-assisted git commit messages, PR summaries, and changelogs — with caching,
44cost control, and a human always in the loop before anything is committed.
55
6- ## Install (development)
6+ [ ![ CI] ( https://github.com/getdownandcode/gitmate/actions/workflows/ci.yml/badge.svg )] ( https://github.com/getdownandcode/gitmate/actions/workflows/ci.yml )
7+ [ ![ PyPI] ( https://img.shields.io/pypi/v/gitmate-cli.svg )] ( https://pypi.org/project/gitmate-cli/ )
8+ [ ![ Python] ( https://img.shields.io/pypi/pyversions/gitmate-cli.svg )] ( https://pypi.org/project/gitmate-cli/ )
9+ [ ![ License] ( https://img.shields.io/pypi/l/gitmate-cli.svg )] ( LICENSE )
710
8- Requires [ uv] ( https://docs.astral.sh/uv/ ) . No manual install step is needed;
9- ` uv run ` syncs the environment automatically:
11+ ![ gitmate demo] ( docs/demo.gif )
12+
13+ ## Why gitmate
14+
15+ - ** A human reviews everything.** ` gitmate commit ` shows the message and asks
16+ before anything is committed — accept, edit, regenerate, or cancel.
17+ Non-interactive mode exists but is strictly opt-in.
18+ - ** It still works when the API doesn't.** Offline, rate-limited, or keyless?
19+ gitmate degrades to deterministic, template-based messages with a visible
20+ warning — never a stack trace in your face, never a silent quality drop.
21+ - ** Costs are tracked, not guessed.** Responses are cached by content hash,
22+ diffs over the model's context window are truncated or chunked, and every
23+ invocation logs tokens, latency, and estimated spend to a local SQLite
24+ database you can inspect with ` gitmate stats ` .
25+
26+ ## Install
1027
1128``` bash
12- git clone https://github.com/getdownandcode/gitmate.git
13- cd gitmate
14- uv run gitmate --help
29+ # uv (recommended)
30+ uv tool install gitmate-cli
31+
32+ # pipx
33+ pipx install gitmate-cli
34+
35+ # plain pip
36+ pip install gitmate-cli
1537```
1638
17- For the full dev toolchain (pytest, ruff, mypy):
39+ The command is ` gitmate ` (the distribution name is ` gitmate-cli ` ).
40+ Requires Python 3.11+.
41+
42+ Then store your Gemini API key — it goes into your OS keychain, never a file:
1843
1944``` bash
20- uv sync --extra dev
21- uv run pytest
45+ gitmate config set-key
2246```
2347
24- ## Usage
48+ ## Quickstart
2549
2650``` bash
27- uv run gitmate --help
28- uv run gitmate config set-key # stored in the OS credential store, never in a file
29- uv run gitmate config show
30- uv run gitmate config set model gemini-3.5-flash-lite
31- uv run gitmate config set commit_style conventional # or 'plain'
32- uv run gitmate config set ignore_globs ' *.gen.py,*.tmp' # comma-separated, empty clears
33- uv run gitmate config set max_context_tokens 8000 # override model context limit
34- uv run gitmate config set reserved_output_tokens 1500 # reserve headroom for model reply
35- uv run gitmate config set template_overhead 600 # reserve headroom for prompt template
36- uv run gitmate config set cache_dir /path/to/cache # custom prompt cache directory
37- uv run gitmate debug-diff # staged diff: per-file table + cleaned patch
38- uv run gitmate debug-diff --summary # per-file stats table only, no patch text
39- uv run gitmate debug-diff --base main # branch-vs-main diff (PR path)
40- uv run gitmate commit # review, edit, accept, or cancel a message
41- uv run gitmate pr-summary --base main
42- uv run gitmate changelog --from v1.0.0 --to v1.1.0
43- uv run gitmate stats
44- uv run gitmate install-hook # optional local prepare-commit-msg hook
45- uv run gitmate uninstall-hook # remove the local hook
51+ git add -p # stage something
52+ gitmate commit # generate → review → accept
4653```
4754
48- Phase 4 introduces versioned prompt templates (` src/gitmate/templates/ ` : ` commit_conventional.txt ` ,
49- ` commit_plain.txt ` , ` pr_summary.txt ` ) and deterministic template-based fallback degradation
50- (` fallback.py ` ). When the LLM backend is offline, rate-limited, unauthenticated, or fails retries,
51- ` generate_commit_message ` warns the user (` ⚠ API unavailable, using template fallback ` ) and
52- derives a clean commit message directly from diff metadata without making an LLM call.
53- ` doc ` is an unscheduled stub; commit, PR summary, changelog, stats, and hook
54- commands are implemented.
55-
56- ### Automatic commit message generation
57-
58- For a personal checkout, run ` gitmate install-hook ` . It installs a local
59- ` prepare-commit-msg ` hook; Git opens the usual editor with the generated message
60- so you can review or change it before saving. The hook never runs ` git commit `
61- and has a four-second generation timeout. If generation fails or times out, it
62- leaves Git's existing message in place and exits successfully so the commit is
63- not blocked. It only generates when the source is ` template ` or absent; explicit
64- ` git commit -m ` /` -F ` messages (` message ` ), merge messages (` merge ` ), squash
65- messages (` squash ` ), and other source values are left alone. Existing hooks are
66- refused rather than overwritten; ` gitmate uninstall-hook ` removes only the
67- gitmate-managed hook. Both commands work with Git's configured ` core.hooksPath ` .
68-
69- For teams using the ` pre-commit ` framework, add this to ` .pre-commit-config.yaml `
70- and run ` pre-commit install --hook-type prepare-commit-msg ` :
55+ That's the whole loop. The generated message appears in your terminal with
56+ ` [a]ccept / [e]dit / [r]egenerate / [c]ancel ` — you choose what lands.
57+
58+ ## Commands
59+
60+ ``` bash
61+ gitmate commit # message for the staged diff (interactive)
62+ gitmate pr-summary --base main # PR description vs base branch, to clipboard
63+ gitmate changelog --from v1.0.0 --to v1.1.0 # grouped release notes
64+ gitmate stats # usage, cache hits, spend, latency
65+ gitmate debug-diff # cleaned/filtered staged diff (debugging aid)
66+ ```
67+
68+ Configuration lives in ` ~/.config/gitmate/config.toml ` (auto-created):
69+
70+ ``` bash
71+ gitmate config show # current settings (never the key)
72+ gitmate config set model gemini-3.5-flash-lite
73+ gitmate config set commit_style conventional # or 'plain'
74+ gitmate config set ignore_globs ' *.gen.py,*.tmp'
75+ gitmate config set max_context_tokens 8000 # override the model's window
76+ gitmate config set cache_dir /path/to/cache # prompt-cache location
77+ gitmate config set free_tier true # zero-cost accounting
78+ ```
79+
80+ ### Automatic commit messages via git hooks
81+
82+ For a personal checkout:
83+
84+ ``` bash
85+ gitmate install-hook
86+ ```
87+
88+ This installs a ` prepare-commit-msg ` hook: Git opens your editor with the
89+ generated message already in it, so you review inside your normal
90+ ` git commit ` flow. The hook is crash-safe — four-second generation budget,
91+ atomic message writes, and it never blocks a commit: on failure or timeout
92+ it leaves Git's own message untouched and exits 0. Re-running ` install-hook `
93+ upgrades a gitmate-managed hook in place; foreign hooks are never overwritten.
94+ ` gitmate uninstall-hook ` removes it.
95+
96+ For teams on the [ pre-commit] ( https://pre-commit.com ) framework:
7197
7298``` yaml
7399repos :
@@ -77,22 +103,85 @@ repos:
77103 - id : gitmate-prepare-commit-msg
78104` ` `
79105
80- The repository's ` .pre-commit-hooks.yaml` declares the `prepare-commit-msg`
81- stage and `language : python`, so pre-commit installs gitmate into its isolated
82- environment for each adopting checkout. `keyring` still uses the user's OS
83- credential store from that environment; the API key is not copied into the
84- repository or the pre-commit environment. The `gitmate install-hook` route is
85- local-only because `.git/hooks` is not version controlled; the pre-commit route
86- lets a team version the hook declaration for everyone who opts in.
87-
88- # # Diagrams
89-
90- Editable draw.io sources plus publishable PNG exports (open the `.drawio`
91- files in the draw.io desktop app to edit) :
92-
93- | Diagram | Source | Export |
94- |---|---|---|
95- | System architecture (Phases 0–8, gemini-3.5-flash-lite) | [`docs/architecture.drawio`](docs/architecture.drawio) | [`docs/architecture.png`](docs/architecture.png) |
96- | Class diagram (Phases 0–4 : config, diffs, budget, providers, templates & fallback) | [`docs/class-diagram.drawio`](docs/class-diagram.drawio) | [`docs/class-diagram.png`](docs/class-diagram.png) |
97- | Use cases (implemented + planned) | [`docs/use-case.drawio`](docs/use-case.drawio) | [`docs/use-case.png`](docs/use-case.png) |
98- | `config` command sequences | [`docs/sequence.drawio`](docs/sequence.drawio) | [`docs/sequence.png`](docs/sequence.png) |
106+ ## Architecture
107+
108+ 
109+
110+ Full-resolution diagram and editable sources (draw.io): see
111+ [` docs/`](docs/) — architecture, class, use-case, and sequence diagrams.
112+
113+ # # Real metrics (from `gitmate stats`)
114+
115+ These are gitmate's own numbers from this project's development period
116+ (~1 week of real usage while building Phases 0–8; ~61% of runs hit the
117+ template fallback because the keychain often had no API key during automated
118+ runs — shown exactly as recorded, not cleaned up) :
119+
120+ | Command | Runs | Cache hit rate | Tokens | Est. spend | Avg latency |
121+ |---|---:|---:|---:|---:|---:|
122+ | `changelog` | 94 | 0.0% | 7,750 | $0.0057 | 1 ms |
123+ | `commit` | 64 | 0.0% | 0 | $0.0000 | 2 ms |
124+ | `commit-hook` | 5 | 0.0% | 0 | $0.0000 | 0 ms |
125+ | `pr_summary` | 114 | 0.0% | 3,520 | $0.0030 | 0 ms |
126+
127+ **Total: 277 invocations, 11,270 tokens, $0.0087 estimated spend.**
128+ Two weeks of daily-use data will replace this table at the next release.
129+
130+ # # The caching tradeoff
131+
132+ gitmate uses **hash-based caching** (`sha256(template_version + model +
133+ prompt)` → response) rather than semantic caching. Semantic caching needs a
134+ vector store, an embedding-model call on every lookup, and a similarity
135+ threshold you'll forever be tuning. Hash caching is O(1), free, and correct;
136+ its only cost is a ~0% hit rate on a diff that changed by one line — an
137+ acceptable, explainable tradeoff for v1. Because the key includes a
138+ ` template_version` , changing a prompt template deliberately invalidates old
139+ entries instead of mixing generations. Semantic caching gets revisited only
140+ if the metrics above ever show the hit rate matters.
141+
142+ # # Design decisions
143+
144+ **Graceful degradation comes first.** The most interesting engineering in a
145+ CLI that calls an LLM is not the happy path — it's every other path. gitmate
146+ treats API failure as a normal input : typed `ProviderUnavailable` after
147+ bounded retries, a deterministic template fallback that derives a usable
148+ message from diff metadata (no LLM call at all), and a visible warning so
149+ nobody mistakes a degraded message for a generated one.
150+
151+ **A human is in the loop by default, not as a feature.** Nothing auto-commits
152+ without explicit confirmation. The `--yes` escape hatch is opt-in precisely
153+ because the easiest way to break trust with a tool that writes to your
154+ repository is to make one decision the user didn't approve.
155+
156+ **`subprocess` over GitPython.** Exact control over diff flags (`--staged`,
157+ three-dot ranges, `-M`, `-z`) with zero abstraction leakage — and the parser
158+ is hardened against the real-world mess git emits (spaces, quotes, backslashes,
159+ non-ASCII filenames, and ambient config like `diff.mnemonicPrefix` that
160+ silently breaks naive parsers).
161+
162+ **One provider protocol, proven once.** `LLMProvider` is a three-line
163+ protocol; Gemini (`google-genai`) is the default, Anthropic slots in behind
164+ the same boundary. The abstraction earned its keep by staying small.
165+
166+ **Plans lose to data.** Phase 2 originally truncated "low-signal" files
167+ (test snapshots first) per the roadmap. In practice that actively harmed
168+ test-focused commits — where the tests *are* the story. It was reverted to
169+ size-only ordering, deliberately, with the reasoning recorded in the code.
170+
171+ **Tests run against real git.** The suite never mocks the git binary —
172+ scratch repositories in `tmp_path` with real commits. Only the `LLMProvider`
173+ boundary is faked, because that's where our code ends and a vendor's begins.
174+ 291 tests, `mypy --strict` clean, `ruff` clean.
175+
176+ # # Development
177+
178+ ` ` ` bash
179+ git clone https://github.com/getdownandcode/gitmate.git
180+ cd gitmate
181+ uv sync --extra dev
182+ uv run pytest
183+ ` ` `
184+
185+ # # License
186+
187+ Apache-2.0 — see [LICENSE](LICENSE).
0 commit comments