headroom/wiki
Manmit Singh 942e916368
feat(cli): add headroom inspect to view original vs compressed content (#1595)
## Description

Headroom exposes plenty of *quantitative* compression telemetry (token
counts, ratios, `headroom perf`, `/metrics`) but no way to actually
**see what the compressor changed** in the content. That makes it hard
to trust compression or debug a quality regression ("did it drop
something I cared about?").

This adds a `headroom inspect` command (the issue's Option 1). It reads
the proxy's existing loopback `/transformations/feed` endpoint — which
already carries the pre/post-compression message snapshots when the
proxy runs with `--log-messages` — and renders, per request, the
original vs compressed content for each message with the changed
segments highlighted. No new dependencies (stdlib `difflib`).

```
headroom inspect                 # inspect the most recent request
headroom inspect --last 5        # the 5 most recent
headroom inspect --full          # include unchanged messages
headroom inspect --format json   # raw feed for offline tooling
```

Per request it shows the model, per-request token counts + savings, the
transforms applied, and a colorized unified diff of each changed message
(red = removed, green = added). Clear errors when no proxy is reachable
or when the proxy wasn't started with `--log-messages`.

Side-by-side / interactive rendering (the fuller form of Option 1) can
follow as a polish pass; this lands the core "see what changed"
capability on data Headroom already captures.

Closes #1267

## Type of Change

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

## Changes Made

- `headroom/cli/inspect.py`: new `inspect` command +
content-flattening/diff-render helpers.
- `headroom/cli/__init__.py`, `headroom/cli/main.py`: register the
command.
- `tests/test_cli_inspect.py`: unit tests (content extraction, the
no-proxy / no-`--log-messages` / empty-feed paths, text render, json
output).
- `wiki/cli.md`: document the command + options.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check`)
- [x] New tests added

### Test Output

```text
$ pytest tests/test_cli_inspect.py -q
7 passed

$ ruff check headroom/cli/ tests/test_cli_inspect.py
All checks passed!
```

## Real Behavior Proof

- Environment: repo main @ HEAD, local venv
- Exact command / steps: invoked the `inspect` command against a mocked
`/transformations/feed` payload (one request, a user message with a line
removed by SmartCrusher).
- Observed result: header shows `req-1 gpt-4o`, `tokens 100 → 40 (saved
60, 60.0%)`, `transforms: SmartCrusher`, and a unified diff with the
removed line on the original side; no-proxy and missing-`--log-messages`
cases raise actionable errors; `--format json` emits the raw feed.
- Not tested: live end-to-end against a real proxy with `--log-messages`
(the data source — the feed endpoint — is exercised via the mocked
payload that mirrors its shape).

## 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 made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove the feature works
2026-07-15 19:58:38 +00:00
..
overrides new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
plans fix: add anthropic pre-upstream timeouts 2026-04-21 09:48:32 +07:00
screenshots new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
stylesheets new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
agno.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
api.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
ARCHITECTURE.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
benchmarks.md fix(telemetry): switch anonymous telemetry to opt-in (off by default) (#1223) 2026-06-20 21:26:04 -07:00
ccr.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
cli.md feat(cli): add headroom inspect to view original vs compressed content (#1595) 2026-07-15 19:58:38 +00:00
compression.md fix(cli): proxy/perf/wrap UX cleanup + perf --hours correctness 2026-05-07 16:43:35 -07:00
configuration.md fix(proxy): dedupe Codex WS request logging for accurate mixed-provider dashboards (#2189) 2026-07-15 18:18:34 +00:00
docker-install.md fix: align docker image versions with releases 2026-04-17 12:17:49 -05:00
errors.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
filesystem-contract.md docs: document HEADROOM_CONFIG_DIR / HEADROOM_WORKSPACE_DIR filesystem contract 2026-04-16 19:24:17 -05:00
getting-started.md docs: use headroom-ai package name in install commands (#1014) (#1257) 2026-06-22 19:25:00 -05:00
image-compression.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
index.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
integration-guide.md fix(copilot): restore generic endpoint for non-subscription OAuth (#610) (#612) 2026-06-04 16:27:54 -07:00
langchain.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
LATENCY_BENCHMARKS.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
learn.md fix(cli): harden all CLI surfaces + fix docs accuracy (#1491) 2026-06-27 14:48:43 -07:00
LIMITATIONS.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
macos-deployment.md docs: correct macOS troubleshooting Python floor to 3.10+ (#981) 2026-06-15 11:09:59 -05:00
mcp.md docs: document HEADROOM_CONFIG_DIR / HEADROOM_WORKSPACE_DIR filesystem contract 2026-04-16 19:24:17 -05:00
memory.md feat(memory): add opt-in Apple-GPU (MPS) embedding runtime (#766) 2026-06-11 12:59:20 -05:00
metrics.md fix(cli): harden all CLI surfaces + fix docs accuracy (#1491) 2026-06-27 14:48:43 -07:00
network-diff-capture.md feat: add differential network capture harness (#761) 2026-06-08 22:18:31 -07:00
persistent-installs.md docs: document HEADROOM_CONFIG_DIR / HEADROOM_WORKSPACE_DIR filesystem contract 2026-04-16 19:24:17 -05:00
proxy.md fix(proxy): dedupe Codex WS request logging for accurate mixed-provider dashboards (#2189) 2026-07-15 18:18:34 +00:00
quickstart.md fix(cli): harden all CLI surfaces + fix docs accuracy (#1491) 2026-06-27 14:48:43 -07:00
sdk.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
shared-context.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
strands.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
text-compression.md new docs UI + ts doc coverage 2026-04-12 13:15:58 +06:00
transforms.md docs: sync README + benchmarks with code (drop retired IntelligentContext/RollingWindow) (#1545) 2026-06-28 22:36:41 -07:00
troubleshooting.md fix: skip Magika backend on x86 CPUs without AVX2 (#1162) 2026-06-30 13:34:17 -05:00
typescript-sdk.md chore: remove committed node_modules + stray/internal markdown (repo hygiene) (#1528) 2026-06-27 23:32:54 -07:00
vertex.md chore: remove committed node_modules + stray/internal markdown (repo hygiene) (#1528) 2026-06-27 23:32:54 -07:00