headroom/headroom
Aashish Tamsya 420dc9077b
feat(grok-build): add Grok Build wrap command and MCP integration (#1629)
## Description

Adds first-class Grok Build support to Headroom so Grok CLI sessions can
route through the local proxy for context compression and savings
tracking.

This PR introduces `headroom wrap grok-build` / `headroom unwrap
grok-build`, a `grok_build` provider slice, Grok MCP registrar support,
and install/telemetry wiring so Grok traffic is attributed correctly in
the proxy and dashboard.

Review follow-up (`9368c413`): when users already own
`[model.grok-build]` in `~/.grok/config.toml`, wrap rewrites `base_url`
in that table in place instead of appending a duplicate header (invalid
TOML).

## Type of Change

- [x] New feature (non-breaking change that adds functionality)

## Changes Made

- Added `headroom/providers/grok_build/` with runtime helpers,
reversible `~/.grok/config.toml` injection, and install env builders.
- Added `headroom wrap grok-build` and `headroom unwrap grok-build` CLI
commands.
- Added `GrokRegistrar` for Headroom MCP registration in Grok config.
- Wired `grok_build` into install planner/registry, agent savings,
telemetry, and proxy client detection (`grok/` user agent).
- **Review fix:** rewrite `base_url` inside an existing user-owned
`[model.grok-build]` table in place (`# was: …` metadata).
- Added regression tests + docs (`grok-build.mdx`, `proxy.mdx`) and
CHANGELOG entry.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ pytest -q tests/test_provider_grok_build.py tests/test_mcp_registry/test_grok_registrar.py
============================== 12 passed in 1.13s ==============================
```

See **Screenshots** below for terminal captures (pytest, review-fix
in-place rewrite, proxy `/readyz`, unwrap).

## Real Behavior Proof

- Environment: macOS, Python 3.11.12 venv, feat/grok-build @ `9368c413`,
isolated `GROK_HOME` temp dirs, proxy port 8799
- Exact command / steps: see screenshot evidence (wrap/unwrap, in-place
table rewrite, `/readyz`)
- Observed result: see screenshots — 12 tests pass; single
`[model.grok-build]` table after wrap on pre-existing config; proxy
healthy; unwrap restores backup
- Not tested: Live interactive Grok chat with xAI auth through the proxy

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I have updated the CHANGELOG.md if applicable

## Screenshots (if applicable)

Terminal captures from local verification (`9368c413`). Assets hosted on
fork prerelease only — **not** in the source tree.

**1. Pytest — 12 passed (incl. review-fix regression)**

![pytest 12
passed](https://github.com/aashishtamsya/headroom/releases/download/pr-1629-evidence/01-pytest.png)

**2. Review fix — in-place `[model.grok-build]` rewrite (single table,
`# was:` metadata)**

![review fix in-place
rewrite](https://github.com/aashishtamsya/headroom/releases/download/pr-1629-evidence/02-review-fix-in-place.png)

**3. Proxy health — `/readyz` healthy on port 8799**

![proxy readyz
healthy](https://github.com/aashishtamsya/headroom/releases/download/pr-1629-evidence/03-proxy-health.png)

**4. Unwrap — restores pre-wrap backup**

![unwrap restores
backup](https://github.com/aashishtamsya/headroom/releases/download/pr-1629-evidence/04-unwrap.png)

## Additional Notes

Screenshot assets:
https://github.com/aashishtamsya/headroom/releases/tag/pr-1629-evidence
(temporary prerelease; safe to delete after merge).

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-07-15 20:51:52 +00:00
..
audit [codex] Simulate Codex read maturation risk (#1395) 2026-07-15 20:36:34 +00:00
backends fix(backend/bedrock): preserve system-prompt cache_control breakpoint (list form) (#2225) 2026-07-15 19:58:06 +00:00
cache fix(ccr): skip compact summaries for proactive expansion (#2242) 2026-07-15 19:57:46 +00:00
capture fix(cli): harden all CLI surfaces + fix docs accuracy (#1491) 2026-06-27 14:48:43 -07:00
ccr fix(ccr): lowercase a retrieved hash so an uppercase echo still hits the store (#2236) 2026-07-15 19:57:58 +00:00
cli feat(grok-build): add Grok Build wrap command and MCP integration (#1629) 2026-07-15 20:51:52 +00:00
compression fix(code): parse-probe tree-sitter availability in code_handler (#1231) (#1300) 2026-07-09 14:06:29 -05:00
dashboard fix(proxy): dedupe Codex WS request logging for accurate mixed-provider dashboards (#2189) 2026-07-15 18:18:34 +00:00
evals feat: 3-layer context compression pipeline (L1+L2+L3) (#1405) 2026-07-15 19:58:51 +00:00
graph feat(wrap): make tokensave the primary coding-task compressor, Serena the backup (#1230) 2026-06-25 16:55:37 -05:00
image fix(startup): suppress proxy startup log noise (#619) 2026-06-05 14:44:40 -08:00
install feat(grok-build): add Grok Build wrap command and MCP integration (#1629) 2026-07-15 20:51:52 +00:00
integrations feat: add CrewAI and AutoGen tool compression integrations (#1384) 2026-07-15 19:58:54 +00:00
lean_ctx fix(windows): pin UTF-8 encoding on text-mode subprocess calls (#1311) 2026-06-23 12:52:49 -05:00
learn feat(wrap): add first-class Grok CLI support (#1823) 2026-07-15 18:51:38 +00:00
mcp_registry feat(wrap): add first-class Grok CLI support (#1823) 2026-07-15 18:51:38 +00:00
memory fix(memory): filter inactive graph-expanded results (#2210) 2026-07-15 19:58:13 +00:00
models fix(models): version-boundary longest-prefix match in ModelRegistry.get (#1658) 2026-07-10 23:07:31 -05:00
observability fix(docker): report source build version (#1862) 2026-07-08 13:32:04 -05:00
perf fix(cli): harden all CLI surfaces + fix docs accuracy (#1491) 2026-06-27 14:48:43 -07:00
prediction chore: add nosec B324 annotations to non-cryptographic MD5 usages and update temporary database path to use system temp directory 2026-04-07 13:07:26 +06:00
pricing fix(pricing): alias retired claude-3-sonnet to Sonnet-tier price, not Haiku (#2095) 2026-07-13 10:50:33 -04:00
providers feat(grok-build): add Grok Build wrap command and MCP integration (#1629) 2026-07-15 20:51:52 +00:00
proxy feat(grok-build): add Grok Build wrap command and MCP integration (#1629) 2026-07-15 20:51:52 +00:00
relevance feat(security): pilot hardening — stateless guarantee, model pinning, CI security gate (#1515) 2026-06-27 17:44:10 -07:00
reporting feat: attribute reread waste to over-compression via marker check (#901) 2026-06-13 10:43:35 -05:00
rtk fix: use rtk native Cursor hook instead of injecting .cursorrules (#756) (#1846) 2026-07-07 23:31:54 -05:00
storage Fix 19 test failures: missing security attr, nosec inside f-strings, stale test mock 2026-04-07 18:30:29 -07:00
subscription fix(subscription): keep efficiency_pct from exceeding 100% (#2121) 2026-07-14 11:53:13 -04:00
telemetry feat(grok-build): add Grok Build wrap command and MCP integration (#1629) 2026-07-15 20:51:52 +00:00
tokenizers fix: add DeepSeek V4/V3.2/R1 tokenizer mappings and context limits (#912) 2026-07-15 09:24:44 -05:00
transforms fix(transforms): guard Log fallback against invalid JSON + fix MIXED false-positive on source code (#1347) 2026-07-15 20:36:20 +00:00
__init__.py Pin ORT dylib on Windows; init Python logging (#1010) 2026-06-23 07:46:24 -05:00
_ort.py fix(core): load ONNX Runtime dynamically so headroom._core imports on non-AVX2 x86-64 (#1715) 2026-07-14 13:25:41 -04:00
_subprocess.py fix(install): use Windows-safe PID liveness probe in runtime_status (#1544) (#1560) 2026-07-01 17:13:11 -05:00
_version.py fix(version): mark source-checkout builds as -dev (#2072) 2026-07-13 09:38:17 -04:00
agent_savings.py fix(savings): coding profile compresses the recent delta (protect_recent 2->0, min_tokens 25->10) (#2145) 2026-07-14 04:07:25 -04:00
binaries.py fix(windows): pin UTF-8 encoding on text-mode subprocess calls (#1311) 2026-06-23 12:52:49 -05:00
cli.py Add Click-based CLI with memory management commands 2026-01-29 21:30:21 -08:00
client.py refactor: DRY cache logic, add thread safety, fix Bash exclusion (#704) 2026-06-16 14:50:04 -05:00
compress.py feat(compress): expose frozen_message_count in library-mode compress() (#2178) 2026-07-14 16:07:21 -04:00
config.py fix(proxy): protect WebSearch/WebFetch tool results from lossy compression (#2115) 2026-07-14 11:52:26 -04:00
copilot_auth.py fix(auth): support GitHub Enterprise Copilot OAuth domain (#2192) 2026-07-14 16:07:17 -04:00
copilot_linux_secret.py fix(windows): pin UTF-8 encoding on text-mode subprocess calls (#1311) 2026-06-23 12:52:49 -05:00
copilot_macos_keychain.py fix(windows): pin UTF-8 encoding on text-mode subprocess calls (#1311) 2026-06-23 12:52:49 -05:00
exceptions.py fix: B1 — retire ICM, RollingWindow, scoring, relevance + dependents 2026-05-02 12:23:17 -07:00
fsutil.py fix(io): use UTF-8 with locale fallback and preserve line endings on config/text I/O (#1498) 2026-06-28 13:18:47 -07:00
hooks.py feat: introduce canonical pipeline lifecycle contract 2026-04-21 23:54:28 -05:00
offline.py feat(proxy): pilot hardening — inbound auth, security headers, audit log, air-gap switch (#1537) 2026-06-28 12:09:00 -07:00
onnx_runtime.py fix(windows): unwedge compression on degraded ONNX runtimes (every request timing out at 30s, 0% savings) (#822) 2026-07-15 09:23:44 -05:00
parser.py fix(agno): tolerate streaming tool-call SDK objects in parser (#1312) (#1336) 2026-06-24 09:52:15 -05:00
paths.py fix(proxy): dedupe Codex WS request logging for accurate mixed-provider dashboards (#2189) 2026-07-15 18:18:34 +00:00
pipeline.py feat: introduce canonical pipeline lifecycle contract 2026-04-21 23:54:28 -05:00
py.typed Prepare for OSS release v0.2.0 2026-01-07 11:36:44 -08:00
release_version.py ci(release): publish win_amd64 wheel so Windows installs need no Rust (#1328) (#1335) 2026-06-24 09:48:37 -05:00
savings_ledger.py fix(savings): don't bill free models at the $3/M fallback in the ledger (#2147) 2026-07-14 12:19:30 -04:00
settings_store.py fix(proxy): dedupe Codex WS request logging for accurate mixed-provider dashboards (#2189) 2026-07-15 18:18:34 +00:00
shared_context.py fix(shared_context): don't evict an unrelated entry on an update at capacity (#2136) 2026-07-13 19:57:32 -04:00
tokenizer.py Initial commit: Headroom SDK - LLM context optimization toolkit 2026-01-06 23:16:58 -08:00
tools.json fix(review): address PR #210 feedback — race, query-params, SHA logging, frozen prefix, etc 2026-04-20 17:36:44 -07:00
update_check.py feat(proxy): pilot hardening — inbound auth, security headers, audit log, air-gap switch (#1537) 2026-06-28 12:09:00 -07:00
utils.py chore: add nosec B324 annotations to non-cryptographic MD5 usages and update temporary database path to use system temp directory 2026-04-07 13:07:26 +06:00