mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
## Description
Adds first-class Grok CLI integration so Headroom can wrap, compress,
and learn from Grok sessions the same way it does for Claude Code and
Codex.
Grok routes inference through `GROK_CLI_CHAT_PROXY_BASE_URL`; Headroom
sets that to the local proxy so chat traffic is compressed before
forwarding to xAI. MCP retrieval and session learning follow the same
patterns as Codex.
Closes #
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)
## Changes Made
- Add `headroom/providers/grok/` provider slice (`runtime.py`,
`install.py`) with `GROK_CLI_CHAT_PROXY_BASE_URL` routing and project
attribution prefix
- Add `headroom wrap grok` and `headroom unwrap grok` CLI commands (MCP
registration, RTK/context-tool setup, proxy launch)
- Add `GrokRegistrar` for marker-delimited `[mcp_servers.headroom]`
injection in `~/.grok/config.toml`
- Add `headroom learn --agent grok` plugin parsing
`~/.grok/sessions/*/updates.jsonl` and `GrokWriter` targeting `GROK.md`
- Register Grok in install planner, install registry, MCP install list,
and agent savings tracking
- Update README agent compatibility matrix and unwrap support list
- Add unit tests for provider, wrap CLI, MCP registrar, and learn plugin
## Testing
- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [ ] Manual testing performed
### Test Output
```text
$ uv run pytest tests/test_provider_grok.py tests/test_cli/test_wrap_grok.py tests/test_mcp_registry_grok.py tests/test_learn_grok_plugin.py -q
============================== 10 passed in 0.15s ==============================
$ uv run ruff check headroom/providers/grok headroom/mcp_registry/grok.py headroom/learn/plugins/grok.py headroom/cli/wrap.py headroom/learn/writer.py
All checks passed!
$ uv run mypy headroom/providers/grok headroom/mcp_registry/grok.py headroom/learn/plugins/grok.py
Success: no issues found in 5 source files
```
## Real Behavior Proof
- Environment: macOS (darwin), Python 3.13.14 via `uv`, repo at
`/Users/s/dev/headroom`, Grok CLI at `/Users/s/.grok/bin/grok`
- Exact command / steps: `cd /Users/s/dev/headroom && uv run pytest
tests/test_provider_grok.py tests/test_cli/test_wrap_grok.py
tests/test_mcp_registry_grok.py tests/test_learn_grok_plugin.py -q`; `uv
run ruff check headroom/providers/grok headroom/mcp_registry/grok.py
headroom/learn/plugins/grok.py`; `uv run python -c "from
headroom.providers.grok import build_launch_env; env, display =
build_launch_env(8787, environ={}); print(display[0])"`; `uv run python
-c "from pathlib import Path; import tempfile; from
headroom.mcp_registry.grok import GrokRegistrar; from
headroom.mcp_registry.install import build_headroom_spec;
td=tempfile.mkdtemp(); reg=GrokRegistrar(home_dir=Path(td));
print(reg.register_server(build_headroom_spec('http://127.0.0.1:8787'),
force=True).status.value)"`
- Observed result: pytest reported `10 passed`; ruff reported `All
checks passed!`; `build_launch_env` printed
`GROK_CLI_CHAT_PROXY_BASE_URL=http://127.0.0.1:8787/v1`; MCP registrar
returned `registered` and wrote the Headroom marker block to
`config.toml`
- Not tested: live `headroom wrap grok` session with authenticated Grok
API traffic through a running Headroom proxy (requires maintainer
environment with active `grok login`)
## 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
- [x] 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
- [ ] I have updated the CHANGELOG.md if applicable
## Screenshots (if applicable)
N/A — CLI/integration change only.
## Additional Notes
- Follows the provider-slice pattern from `b17c6d81` / `93a1f211`
(Codex/Cursor/Aider extraction).
- Routing uses the session env var only (not `config.toml` endpoint
override) so `grok login` session auth continues to work.
- Manual E2E wrap/unwrap with real Grok sessions is left for maintainer
verification.
---------
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
Co-authored-by: Tejas Chopra <chopratejas@gmail.com>
118 lines
2.9 KiB
Python
118 lines
2.9 KiB
Python
"""Models used by the install / deployment subsystem."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime, timezone
|
|
from enum import Enum
|
|
from typing import Any
|
|
|
|
|
|
class InstallPreset(str, Enum):
|
|
"""User-facing persistent runtime presets."""
|
|
|
|
PERSISTENT_SERVICE = "persistent-service"
|
|
PERSISTENT_TASK = "persistent-task"
|
|
PERSISTENT_DOCKER = "persistent-docker"
|
|
|
|
|
|
class RuntimeKind(str, Enum):
|
|
"""Runtime used to execute Headroom."""
|
|
|
|
PYTHON = "python"
|
|
DOCKER = "docker"
|
|
|
|
|
|
class SupervisorKind(str, Enum):
|
|
"""How a persistent deployment is kept alive."""
|
|
|
|
SERVICE = "service"
|
|
TASK = "task"
|
|
NONE = "none"
|
|
|
|
|
|
class ProviderSelectionMode(str, Enum):
|
|
"""How tool targets are selected for configuration."""
|
|
|
|
AUTO = "auto"
|
|
ALL = "all"
|
|
MANUAL = "manual"
|
|
|
|
|
|
class ConfigScope(str, Enum):
|
|
"""Where persistent configuration should be applied."""
|
|
|
|
PROVIDER = "provider"
|
|
USER = "user"
|
|
SYSTEM = "system"
|
|
|
|
|
|
class ToolTarget(str, Enum):
|
|
"""Supported tool targets for persistent proxy wiring."""
|
|
|
|
CLAUDE = "claude"
|
|
COPILOT = "copilot"
|
|
CODEX = "codex"
|
|
AIDER = "aider"
|
|
CURSOR = "cursor"
|
|
GROK = "grok"
|
|
OPENCLAW = "openclaw"
|
|
OPENCODE = "opencode"
|
|
|
|
|
|
def iso_utc_now() -> str:
|
|
"""Return the current UTC timestamp in ISO-8601 format."""
|
|
|
|
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
|
|
|
|
@dataclass
|
|
class ManagedMutation:
|
|
"""A reversible change applied by `headroom install`."""
|
|
|
|
target: str
|
|
kind: str
|
|
path: str | None = None
|
|
data: dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class ArtifactRecord:
|
|
"""A rendered file or platform object owned by the deployment."""
|
|
|
|
kind: str
|
|
path: str
|
|
metadata: dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class DeploymentManifest:
|
|
"""Persisted deployment state for a named profile."""
|
|
|
|
profile: str
|
|
preset: str
|
|
runtime_kind: str
|
|
supervisor_kind: str
|
|
scope: str
|
|
provider_mode: str
|
|
targets: list[str]
|
|
port: int
|
|
host: str
|
|
backend: str
|
|
anyllm_provider: str | None = None
|
|
region: str | None = None
|
|
proxy_mode: str = "token"
|
|
memory_enabled: bool = False
|
|
memory_db_path: str = ""
|
|
telemetry_enabled: bool = True
|
|
image: str = "ghcr.io/headroomlabs-ai/headroom:latest"
|
|
service_name: str = "headroom"
|
|
container_name: str = "headroom-persistent"
|
|
health_url: str = "http://127.0.0.1:8787/readyz"
|
|
base_env: dict[str, str] = field(default_factory=dict)
|
|
tool_envs: dict[str, dict[str, str]] = field(default_factory=dict)
|
|
proxy_args: list[str] = field(default_factory=list)
|
|
mutations: list[ManagedMutation] = field(default_factory=list)
|
|
artifacts: list[ArtifactRecord] = field(default_factory=list)
|
|
created_at: str = field(default_factory=iso_utc_now)
|
|
updated_at: str = field(default_factory=iso_utc_now)
|