Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
docs: port Docker-native, filesystem-contract, and persistent-installs pages to Fumadocs
chopratejas6d250554f74d
diff --git a/docs/content/docs/docker-install.mdx b/docs/content/docs/docker-install.mdxnew file mode 100644index 000000000..f61ca7761--- /dev/null+++ b/docs/content/docs/docker-install.mdx@@ -0,0 +1,201 @@+---+title: Docker-Native Install+description: Run Headroom without installing Python or Node.js on the host. A native `headroom` wrapper keeps the proxy and CLI in Docker while your other tools run on the host OS.+---++Run Headroom without installing Python or Node.js on the host. The install scripts add a native `headroom` wrapper that keeps **Headroom itself** in Docker while orchestrating the rest of your workflow on the host OS.++## One-line install++### Linux++```bash+curl -fsSL https://raw.githubusercontent.com/chopratejas/headroom/main/scripts/install.sh | bash+```++### macOS (bash 4.3+)++```bash+curl -fsSL https://raw.githubusercontent.com/chopratejas/headroom/main/scripts/install.sh | "$(brew --prefix bash)/bin/bash"+```++Stock `/bin/bash` on macOS is 3.2, so install a newer bash first (for example via Homebrew) and run the installer with that shell. The installed wrapper pins that same bash interpreter so later invocations stay on the supported runtime.++### Windows PowerShell++```powershell+irm https://raw.githubusercontent.com/chopratejas/headroom/main/scripts/install.ps1 | iex+```++## What the installer does++1. Verifies Docker is installed and available.+2. Pulls `ghcr.io/chopratejas/headroom:latest` by default, or reuses / pulls `HEADROOM_DOCKER_IMAGE` when you set a custom image override.+3. Installs a `headroom` wrapper into `~/.local/bin` or `~/bin`.+4. Updates shell startup files so the wrapper directory is on `PATH`.++The wrapper keeps Headroom inside Docker and mounts host state back into the container so native behavior stays consistent:++- project workspace → `/workspace`+- `~/.headroom`+- `~/.claude`+- `~/.codex`+- `~/.gemini`++Port `8787` stays the default, so `http://localhost:8787` works the same way as a native install.++Published releases also push versioned GHCR tags such as `ghcr.io/chopratejas/headroom:0.5.26`, and those images are built with the same synced package version used for the matching PyPI and npm release.++## How the wrapper behaves++### Native Headroom commands++These run directly inside the container:++```bash+headroom proxy+headroom learn+headroom mcp install+headroom memory list+```++For `proxy`, the wrapper publishes the selected port back to the host:++```bash+docker run --rm -it \+ -p 8787:8787 \+ -v "$PWD:/workspace" \+ -w /workspace \+ ghcr.io/chopratejas/headroom:latest \+ headroom proxy --host 0.0.0.0 --port 8787+```++### `wrap` commands++`wrap` is host-oriented in Docker-native mode:++- the wrapper starts the Headroom proxy in Docker+- container-side prep writes Headroom config, memory, and `rtk` guidance into mounted host files+- the target CLI itself is launched on the host by the wrapper++Supported host wrap flows:++- `headroom wrap claude`+- `headroom wrap codex`+- `headroom wrap aider`+- `headroom wrap cursor`+- `headroom wrap openclaw`+- `headroom unwrap openclaw`++OpenClaw remains host-native in Docker-native mode:++- the host must already have the `openclaw` CLI installed+- `headroom wrap openclaw` installs/configures the Headroom plugin through the host `openclaw` CLI+- plugin auto-start still launches the installed host `headroom` wrapper from `PATH`, which then runs Headroom in Docker+- local plugin source mode (`--plugin-path`) is also supported, but it may require host `npm` when build steps are needed++## Persistent Docker lifecycle from the native wrapper++The Docker-native `headroom` wrapper exposes the persistent Docker lifecycle directly:++```bash+headroom install apply --profile default --preset persistent-docker+headroom install status+headroom install restart+headroom install remove+```++In Docker-native mode this surface is intentionally scoped to **persistent-docker**:++- supported: `apply`, `status`, `start`, `stop`, `restart`, `remove`+- supported flags: `--profile`, `--port`, `--backend`, `--anyllm-provider`, `--region`, `--mode`, `--memory`, `--no-telemetry`, `--image`+- not supported: `persistent-service`, `persistent-task`, or provider/user/system mutation flags such as `--scope`, `--providers`, and `--target`++Those broader lifecycle and config-mutation flows still belong to the Python-native `headroom install ...` command.++Persistent Docker deployments launched by the wrapper also tag the proxy process with deployment metadata, so `/health` reports the active `profile`, `preset`, `runtime`, `supervisor`, and `scope` the same way the Python install subsystem does.++## Docker Compose support++Use `docker/docker-compose.native.yml` when you want an explicit compose-managed proxy or CLI shell, or when you prefer compose over the native wrapper's `headroom install ...` surface.++### Persistent Docker runtime++The `proxy` service uses `restart: unless-stopped`, so compose can act as the always-on Docker runtime for Headroom:++```bash+export HEADROOM_HOST_HOME="$HOME"+export HEADROOM_WORKSPACE="$PWD"+docker compose -f docker/docker-compose.native.yml up -d proxy+```++```powershell+$env:HEADROOM_HOST_HOME = $HOME+$env:HEADROOM_WORKSPACE = (Get-Location).Path+docker compose -f docker/docker-compose.native.yml up -d proxy+```++This is a supported persistent-Docker path when you want the proxy managed explicitly through Compose instead of the installed wrapper.++<Callout type="info" title="HEADROOM_WORKSPACE vs HEADROOM_WORKSPACE_DIR">+These are two different variables — both are set by the compose file, and both are retained for backward compatibility:++- **`HEADROOM_WORKSPACE`** (host-side) is the directory the compose file bind-mounts into the container as `/workspace`. It behaves like CWD in a native (non-Docker) run.+- **`HEADROOM_WORKSPACE_DIR`** (inside the container) is the canonical Headroom state root from the [filesystem contract](/docs/filesystem-contract). The compose file sets it to `/tmp/headroom-home/.headroom` so the proxy resolves savings, logs, TOIN, and memory under the bind-mounted `${HOME}/.headroom`.++You do not need to set `HEADROOM_WORKSPACE_DIR` manually when using the shipped compose file — it is already in the `environment:` block.+</Callout>++### macOS / Linux++```bash+export HEADROOM_HOST_HOME="$HOME"+export HEADROOM_WORKSPACE="$PWD"+docker compose -f docker/docker-compose.native.yml up proxy+```++### Windows PowerShell++```powershell+$env:HEADROOM_HOST_HOME = $HOME+$env:HEADROOM_WORKSPACE = (Get-Location).Path+docker compose -f docker/docker-compose.native.yml up proxy+```++You can also run one-off CLI commands through compose:++```bash+docker compose -f docker/docker-compose.native.yml run --rm cli learn+docker compose -f docker/docker-compose.native.yml run --rm cli mcp install+```++## Environment passthrough++The wrapper forwards Headroom and provider environment variables into the container, including common prefixes such as:++- `HEADROOM_`+- `ANTHROPIC_`+- `OPENAI_`+- `GEMINI_`+- `AWS_`+- `GOOGLE_` / `GOOGLE_CLOUD_`+- `AZURE_`+- `OTEL_`++That keeps provider auth and runtime config working without maintaining a separate env file for the container.++## Notes++- Docker is the only required Headroom runtime dependency on the host.+- Wrapped tools like Claude Code, Codex CLI, Aider, and Cursor still run on the host when you use `headroom wrap ...`.+- The install scripts are idempotent: rerunning them refreshes the wrapper and image without duplicating shell profile blocks.+- For persistent service and task installs, use the Python-native `headroom install ...` workflow — see [Persistent Installs](/docs/persistent-installs).+- For Docker-native `headroom install ...`, the wrapper persists its profile manifest under `~/.headroom/deploy/<profile>/`.++## Next steps++<Cards>+ <Card title="Quickstart" href="/docs/quickstart" />+ <Card title="Proxy Server" href="/docs/proxy" />+ <Card title="Installation (pip / npm / plain Docker)" href="/docs/installation" />+</Cards>diff --git a/docs/content/docs/filesystem-contract.mdx b/docs/content/docs/filesystem-contract.mdxnew file mode 100644index 000000000..64e90e11e--- /dev/null+++ b/docs/content/docs/filesystem-contract.mdx@@ -0,0 +1,146 @@+---+title: Filesystem Contract+description: Where Headroom writes config, runtime state, logs, and caches — the canonical two-root model, precedence rules, and Docker behavior.+---++Headroom writes configuration, runtime state, logs, and caches to a small set of well-known paths under the user's home directory. This page is the source of truth for where those paths live, how to override them, and how they behave inside Docker containers.++## Two-root model++| Variable | Default | Purpose | Typical access |+|---|---|---|---|+| `HEADROOM_CONFIG_DIR` | `~/.headroom/config` | User/admin-authored configuration (model catalogs, plugin settings, etc.) | Read-mostly |+| `HEADROOM_WORKSPACE_DIR` | `~/.headroom` | Runtime state written by the proxy and CLI (savings, logs, memory DB, telemetry, caches) | Read-write |++Both variables are recognized by the Python proxy / CLI and the npm SDK. They are **additive** — every pre-existing per-resource env var (`HEADROOM_SAVINGS_PATH`, `HEADROOM_TOIN_PATH`, `HEADROOM_SUBSCRIPTION_STATE_PATH`, `HEADROOM_MODEL_LIMITS`, ...) continues to work with identical semantics.++## Precedence++For every per-resource helper, resolution follows this order:++```+explicit argument+ │ falls through when None/""+ ▼+per-resource env var (e.g. HEADROOM_SAVINGS_PATH)+ │ falls through when unset/blank+ ▼+derived from canonical root+ │ e.g. ${HEADROOM_WORKSPACE_DIR}/proxy_savings.json+ ▼+default (e.g. ~/.headroom/proxy_savings.json)+```++Examples:++- `HEADROOM_WORKSPACE_DIR=/mnt/state` → savings land at `/mnt/state/proxy_savings.json` unless `HEADROOM_SAVINGS_PATH` overrides.+- `HEADROOM_SAVINGS_PATH=/custom/savings.json` always wins, even when `HEADROOM_WORKSPACE_DIR` is set.+- Unset both and the default is `~/.headroom/proxy_savings.json`.++## Bucket assignments++### Workspace bucket (`HEADROOM_WORKSPACE_DIR`)++| Resource | Default path | Legacy env var |+|---|---|---|+| Proxy savings ledger | `${WORKSPACE_DIR}/proxy_savings.json` | `HEADROOM_SAVINGS_PATH` |+| TOIN telemetry JSON | `${WORKSPACE_DIR}/toin.json` | `HEADROOM_TOIN_PATH` |+| Subscription tracker state | `${WORKSPACE_DIR}/subscription_state.json` | `HEADROOM_SUBSCRIPTION_STATE_PATH` |+| Memory SQLite | `${WORKSPACE_DIR}/memory.db` | CLI `--memory-db-path` |+| Native memory directory | `${WORKSPACE_DIR}/memories/` | `MemoryConfig.native_memory_dir` |+| License cache | `${WORKSPACE_DIR}/license_cache.json` | — |+| Session stats JSONL | `${WORKSPACE_DIR}/session_stats.jsonl` | — |+| Memory sync state | `${WORKSPACE_DIR}/sync_state.json` | — |+| Memory bridge state | `${WORKSPACE_DIR}/bridge_state.json` | — |+| Proxy log directory | `${WORKSPACE_DIR}/logs/` | — |+| HTTP 400 debug dumps | `${WORKSPACE_DIR}/logs/debug_400/` | — |+| Vendored `rtk` binary | `${WORKSPACE_DIR}/bin/rtk[.exe]` | — |+| Deployment profiles | `${WORKSPACE_DIR}/deploy/` | — |+| Beacon lock file | `${WORKSPACE_DIR}/.beacon_lock_<port>` | — |++### Config bucket (`HEADROOM_CONFIG_DIR`)++| Resource | Default path | Legacy env var |+|---|---|---|+| Models catalog | `${CONFIG_DIR}/models.json` | `HEADROOM_MODEL_LIMITS` (content override) |+| Plugin settings | `${CONFIG_DIR}/plugins/<name>/...` | — |++### Backward compatibility — models.json++`models.json` historically lived at `~/.headroom/models.json` (i.e. in the workspace root, not in `config/`). For a seamless migration the Python providers check **both** locations in this order:++1. `${HEADROOM_CONFIG_DIR}/models.json` (new canonical location)+2. `${HEADROOM_WORKSPACE_DIR}/models.json` (legacy fallback)++Existing installs continue to work unchanged. New installs are encouraged to put `models.json` in the config bucket.++## Plugin authors++Two helpers give plugins isolated, per-plugin directories under both roots:++### Python++```python+from headroom import paths++cfg_dir = paths.plugin_config_dir("my-plugin")+# → ~/.headroom/config/plugins/my-plugin++state_dir = paths.plugin_workspace_dir("my-plugin")+# → ~/.headroom/plugins/my-plugin++cfg_dir.mkdir(parents=True, exist_ok=True)+(cfg_dir / "settings.json").write_text("{}")+```++### npm SDK++```typescript+import { pluginConfigDir, pluginWorkspaceDir } from "@headroom/sdk";++const cfgDir = pluginConfigDir("my-plugin");+const stateDir = pluginWorkspaceDir("my-plugin");+```++Plugin-author helpers reject names containing `/` or `\` to keep the namespace flat.++## Docker naming overlap: `HEADROOM_WORKSPACE` vs `HEADROOM_WORKSPACE_DIR`++These are **two different variables** with different semantics, both retained for backward compatibility:++| Variable | Scope | Meaning |+|---|---|---|+| `HEADROOM_WORKSPACE` | Host-side (Docker) | Directory to bind-mount into the container as `/workspace` (equivalent to CWD in native runs). Used by `docker-compose.native.yml`. |+| `HEADROOM_WORKSPACE_DIR` | Inside the container | Canonical Headroom state root. Resolves to `/tmp/headroom-home/.headroom` inside the official container image, which in turn bind-mounts to `${HOME}/.headroom` on the host. |++The official Docker bootstrap (compose file, `scripts/install.sh`, and the Python `install` command) sets `HEADROOM_WORKSPACE_DIR` and `HEADROOM_CONFIG_DIR` inside the container so the proxy resolves state to the bind-mounted path without any user action.++## Project-scoped `.headroom/` directories++A few code paths deliberately use **project-local** `.headroom/` paths resolved relative to the current working directory rather than the canonical workspace root:++- `headroom/proxy/server.py` — project-scoped memory DB default+- `headroom/memory/mcp_server.py` — project-scoped memory DB default+- `headroom/cli/wrap.py` — project-scoped memory and hook artifacts++These **do not obey** `HEADROOM_WORKSPACE_DIR`. This is intentional: it preserves the "project memory lives in the project directory" invariant. Users who want a single centrally located memory store can pass `--memory-db-path <path>` explicitly or set the path via the plugin API.++## Legacy per-resource env vars++Every legacy env var continues to work with its original semantics (raw string in, raw string out — no tilde expansion, no path-separator normalization), ensuring byte-for-byte backward compatibility.++Full list:++- `HEADROOM_SAVINGS_PATH`+- `HEADROOM_TOIN_PATH`+- `HEADROOM_SUBSCRIPTION_STATE_PATH`+- `HEADROOM_MODEL_LIMITS` (content override — JSON string or file path)++## See also++<Cards>+ <Card title="Configuration" href="/docs/configuration" />+ <Card title="Docker-Native Install" href="/docs/docker-install" />+ <Card title="Persistent Installs" href="/docs/persistent-installs" />+ <Card title="Memory" href="/docs/memory" />+</Cards>diff --git a/docs/content/docs/installation.mdx b/docs/content/docs/installation.mdxindex 211bd781e..b157126bd 100644--- a/docs/content/docs/installation.mdx+++ b/docs/content/docs/installation.mdx@@ -95,6 +95,10 @@ docker pull ghcr.io/chopratejas/headroom:latestdocker run -p 8787:8787 ghcr.io/chopratejas/headroom:latest```+<Callout type="info" title="Running Headroom without installing Python or Node?">+If you want a host `headroom` CLI that keeps Headroom itself inside a container — with mounted state, a one-line installer, and a persistent Docker lifecycle — see [Docker-Native Install](/docs/docker-install).+</Callout>+### Image tags| Tag | Extras | Base image | Description |diff --git a/docs/content/docs/meta.json b/docs/content/docs/meta.jsonindex d538b3fef..b3acc81f8 100644--- a/docs/content/docs/meta.json+++ b/docs/content/docs/meta.json@@ -4,6 +4,8 @@"index","quickstart","installation",+ "docker-install",+ "persistent-installs","community-savings","---Compression---","how-compression-works",@@ -33,6 +35,7 @@"mcp","---Configuration---","configuration",+ "filesystem-contract","---Observability---","metrics","simulation",diff --git a/docs/content/docs/persistent-installs.mdx b/docs/content/docs/persistent-installs.mdxnew file mode 100644index 000000000..955a21e16--- /dev/null+++ b/docs/content/docs/persistent-installs.mdx@@ -0,0 +1,163 @@+---+title: Persistent Installs+description: Install Headroom as a durable local runtime — background service, scheduled watchdog, or restartable Docker container — instead of starting it ad hoc.+---++Headroom can be installed as a durable local runtime instead of only being started ad hoc with `headroom proxy` or `headroom wrap ...`.++Use the Python-native `headroom install` CLI when you want supported tools to keep talking to an always-on proxy at `http://127.0.0.1:8787` and have `wrap` reuse or recover that deployment instead of starting a second ephemeral proxy.++## Runtime matrix++| Mode | What stays running | Primary entrypoint |+|---|---|---|+| Persistent Service | Native background service | `headroom install apply --preset persistent-service` |+| Persistent Task | Scheduled watchdog + on-demand runner | `headroom install apply --preset persistent-task` |+| Persistent Docker | Restartable Docker container | `headroom install apply --preset persistent-docker` |+| On-Demand CLI (Python) | Nothing after command exits | `headroom proxy` |+| On-Demand CLI (Docker) | Nothing after container exits | Docker-native wrapper / compose CLI |+| Wrapped (Python) | Proxy lasts for wrapped session | `headroom wrap ...` |+| Wrapped (Docker) | Containerized proxy + host tool session | Docker-native wrapper |++## Quick examples++### Persistent service on the local machine++```bash+headroom install apply --preset persistent-service --providers auto+headroom install status+```++This installs a background service on the current machine, applies persistent tool wiring, and keeps the proxy healthy on port `8787`.++### Persistent watchdog task++```bash+headroom install apply --preset persistent-task --providers manual --target claude --target codex+```++This installs a scheduled recovery path instead of a traditional always-running service.++### Persistent Docker++```bash+headroom install apply --preset persistent-docker --scope user --providers auto+```++This uses Docker's restart policy instead of an OS supervisor.++If you are using the Docker-native host wrapper instead of a Python install, you can use `headroom install apply|status|start|stop|restart|remove` for the `persistent-docker` preset directly from the installed wrapper. Service/task installs and provider/user/system mutation flows still belong to the Python-native CLI.++## Command surface++```text+headroom install apply+headroom install status+headroom install start+headroom install stop+headroom install restart+headroom install remove+```++`apply` creates or updates a named deployment profile, stores its manifest under `~/.headroom/deploy/<profile>/manifest.json`, applies reversible configuration changes, and starts the selected runtime.++## Presets and runtime kinds++### Presets++- `persistent-service` → native service supervisor+- `persistent-task` → scheduled watchdog / recovery supervisor+- `persistent-docker` → Docker restart policy with no extra OS supervisor++### Runtime kinds++- `--runtime python` runs `headroom proxy` directly+- `--runtime docker` runs Headroom inside Docker while keeping the deployment managed locally++For `persistent-docker`, the runtime is always Docker.++## Configuration scopes++| Scope | What changes |+|---|---|+| `provider` | Tool-specific config surfaces where Headroom can make a precise reversible edit |+| `user` | User-level shell or environment surfaces |+| `system` | Machine-wide shell or environment surfaces |++### Provider scope today++Provider scope is intentionally conservative. The current direct adapters are:++- Claude Code → `~/.claude/settings.json` `env`+- Codex → managed block in `~/.codex/config.toml`+- OpenClaw → existing `wrap openclaw` / `unwrap openclaw` flow++For Copilot, Aider, Cursor, and broader env-driven setups, prefer `--scope user` or `--scope system`.++## Provider selection++| Option | Meaning |+|---|---|+| `--providers auto` | Detect supported tools on the host and configure the best available defaults |+| `--providers all` | Configure all known targets |+| `--providers manual --target ...` | Configure only the named tools |++Examples:++```bash+headroom install apply --providers auto+headroom install apply --providers all --scope user+headroom install apply --providers manual --target claude --target copilot+```++## Health and wrap behavior++Persistent deployments publish the same `readyz` and `health` endpoints as ad hoc proxy runs.++`/health` also exposes deployment metadata when the proxy was launched through the install subsystem:++```json+{+ "deployment": {+ "profile": "default",+ "preset": "persistent-service",+ "runtime": "python",+ "supervisor": "service",+ "scope": "user"+ }+}+```++The Python-native `headroom wrap ...` flow checks for a matching persistent deployment on the requested port before it starts a new ephemeral proxy. If an installed deployment exists but is stopped or unhealthy, it attempts to recover it first.++The Docker-native host wrapper does **not** yet reuse or recover persistent profiles automatically; it still starts a fresh proxy container unless you opt into `--no-proxy`.++## Docker-native relationship++The Docker-native host wrapper and the Python install CLI solve different layers of the runtime story:++- [Docker-Native Install](/docs/docker-install) → containerized on-demand CLI, wrapped host-tool flows, and Docker-native `persistent-docker` lifecycle commands+- `headroom install ...` → full persistent service, task, and Docker lifecycle management, including provider/user/system mutation++For a no-Python persistent Docker workflow, use the compose-managed proxy path from `docker/docker-compose.native.yml`:++```bash+export HEADROOM_HOST_HOME="$HOME"+export HEADROOM_WORKSPACE="$PWD"+docker compose -f docker/docker-compose.native.yml up -d proxy+```++That keeps `localhost:8787` stable and restarts the proxy automatically.++<Callout type="info" title="HEADROOM_WORKSPACE vs HEADROOM_WORKSPACE_DIR">+`HEADROOM_WORKSPACE` (the host-side bind-mount source used by the compose file) is **not** the same variable as `HEADROOM_WORKSPACE_DIR` (the canonical Headroom state root inside the container). Both are retained; the compose file sets the latter automatically. See [Filesystem Contract](/docs/filesystem-contract) for the full bucket model.+</Callout>++## Related guides++<Cards>+ <Card title="Docker-Native Install" href="/docs/docker-install" />+ <Card title="Proxy Server" href="/docs/proxy" />+ <Card title="Filesystem Contract" href="/docs/filesystem-contract" />+ <Card title="Configuration" href="/docs/configuration" />+</Cards>