Commit Graph
13 Commits
Author SHA1 Message Date
Tejas ChopraandClaude Opus 5.5 73f59a32cc refactor(cli): remove test-only and dead helpers from wrap, proxy and mcp (#4118)
## Description

Removes private CLI helpers that no product code calls any more. Each
one lost its last caller in an earlier rewrite, so only its own unit
tests still called it. The tests that pinned the dead code go with it.

Refs #4136
## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [x] Code refactoring (no functional changes)

## Changes Made

- `headroom/cli/wrap.py`: removed six dead helpers and constants.
- `_wrap_marker_proxy_is_dead`: the self-heal path now calls
`_wrap_proxy_alive` inline.
- `_agent_savings_config_mismatches` and `_AGENT_SAVINGS_TARGET_AGENTS`:
the live restart check only compares `savings_profile`.
- The `_normalize_openclaw_gateway_provider_ids` forwarder and its
import alias.
- A dead copy of `_opencode_home_dir`; the real one lives in
`providers/opencode/config.py`.
- The unused `_CONTEXT_1M_SUFFIX` and `_OPENCLAUDE_INSTRUCTIONS_FILE`
constants.
- `headroom/cli/proxy.py`: removed `_get_env_float_optional`, which had
no callers.
- `headroom/cli/mcp.py`: removed `get_headroom_command`,
`load_mcp_config`, `save_mcp_config`, `find_headroom_registration` and
the `CLAUDE_CONFIG_DIR` / `MCP_CONFIG_PATH` / `CLAUDE_JSON_PATH`
constants.
- `mcp install`, `mcp status` and `mcp uninstall` all go through
`headroom.mcp_registry` registrars now.
- `load_mcp_config` returned `{}` on corrupt JSON, and `save_mcp_config`
would then overwrite the file. That data-loss path goes away with them.
- Tests removed, because they only exercised the deleted code:
- `tests/test_cli/test_mcp_status.py`, all of which tested
`find_headroom_registration`;
- `TestMCPConfigFunctions` and its path fixtures in
`tests/test_cli/test_mcp.py`;
  - 3 `_wrap_marker_proxy_is_dead` tests;
  - 5 `_agent_savings_config_mismatches` tests;
  - 1 forwarder test.
- The remaining `mcp uninstall` / `mcp status` tests already patch the
registrars. They no longer take the path fixture.

Evidence: `rg -n -w '<name>' headroom crates plugins sdk examples
benchmarks scripts e2e docs wiki .github pyproject.toml tests <consumer
repos>` for each name finds only the definition and the removed tests.
Live behaviour stays covered:
- `test_wrap_dead_marker_selfheal.py`: `test_dead_port_*`,
`test_live_port_is_never_cleared` and the `_wrap_proxy_alive` tests;
- `tests/test_provider_openclaw_wrap.py`;
- `test_mcp.py::TestMCPStatusCommand` / `TestMCPUninstallCommand`.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`)
- [ ] New tests added for new functionality
- [ ] Manual testing performed

### Test Output

```text
$ pytest -q -p no:cacheprovider tests/test_cli/test_wrap_dead_marker_selfheal.py tests/test_agent_savings.py tests/test_cli/test_wrap_openclaw.py tests/test_cli/test_wrap_opencode.py tests/test_cli/test_mcp.py tests/test_cli/test_wrap_helpers.py tests/test_provider_openclaw_wrap.py tests/test_cli/test_main_help_version.py
253 passed in 33.08s
$ uvx ruff@0.16.8 check headroom/cli tests/test_cli tests/test_agent_savings.py
All checks passed!
$ mypy headroom/cli/wrap.py headroom/cli/mcp.py headroom/cli/proxy.py --ignore-missing-imports
Success: no issues found in 3 source files
```

## Real Behavior Proof

- Environment: macOS, Python 3.12, repo `.venv`, branch cut from
`origin/main` at a9815bbb.
- Exact command / steps: ran the pytest files above, which cover `wrap`,
`unwrap`, `mcp status` and `mcp uninstall` via CliRunner, plus `headroom
--help` / `--version`.
- Observed result: all 253 passed; ruff and mypy are clean.
- Smoke harness (real proxy started from this checkout against a local
fake upstream; temp HOME and workspace, offline):

```text
branch: cleanup/cli-integrations-dead-cli-helpers @ 5f450556
health: 200
POST /v1/messages        -> HTTP200 smoke-ok
POST /v1/chat/completions -> HTTP200 smoke-ok
stats: requests=2 failed=0 tokens_saved=13574 savings_percent=99.82
proxy.log WARNING/ERROR lines (<tmp>/ws/logs/proxy-63492.log):
   2 headroom.proxy - WARNING - event=proxy_offline_mode air-gap active — every connection Headroom initiates is refused (telemetry, update check, license reporter, model/tokenizer/binary/dataset downloads, remote Kompress, OTLP/Langfuse export, Copilot auth, subscription polling, OpenAI embedders, Headroom Cloud compression). Still allowed on purpose: forwarding your requests to the upstream you configured, operator-configured local endpoints, loopback health probes.
   4 headroom.transforms.kompress_compressor - WARNING - Kompress: artifact prefetch found no usable file for chopratejas/kompress-v2-base
   4 headroom.transforms.kompress_compressor - WARNING - Kompress: artifact prefetch refused for chopratejas/kompress-v2-base (HEADROOM_OFFLINE is set): HEADROOM_OFFLINE is set: refusing outbound network access for HuggingFace download of chopratejas/kompress-v2-base/onnx/kompress-int8-wo.onnx to huggingface.co. Unset HEADROOM_OFFLINE, or turn off the feature that needs this connection.
(smoke dir: <tmp>)
```
- Direct runtime command on this PR's own path (temp HOME,
HEADROOM_WORKSPACE_DIR and CODEX_HOME):

```text
$ HOME=<tmp>/home HEADROOM_WORKSPACE_DIR=<tmp>/ws CODEX_HOME=<tmp>/codex headroom mcp install --agent claude
exit=0
--- stdout
Installing Headroom MCP server...
  claude: registered (restart the agent if it was already running)

Next steps:
  1. Start the Headroom proxy (if not running): headroom proxy
  2. Start your agent (e.g.) ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude
  3. Restart any agent that was already running so it picks up the new MCP server.
--- stderr
$ HOME=<tmp>/home HEADROOM_WORKSPACE_DIR=<tmp>/ws CODEX_HOME=<tmp>/codex headroom mcp status
exit=0
--- stdout
Headroom MCP Status
========================================
MCP SDK:        ✓ Installed
Agent Config:
  Antigravity IDE: ✗ Not detected
  Claude Code: ✓ Configured
$ HOME=<tmp>/home HEADROOM_WORKSPACE_DIR=<tmp>/ws CODEX_HOME=<tmp>/codex headroom mcp uninstall
exit=0
--- stdout
✓ Claude Code: removed headroom MCP server(s)
--- stderr
```
- Not tested: a live `headroom wrap` session against a real agent
binary. Only unreferenced private code was deleted, so no runtime path
changes.

## Runtime Rollout Safety

- Rollout-managed feature(s): None.
- Minimum rollout channel: N/A, no rollout-managed behaviour.
- Stable/default behavior changed: No. Only code with no callers is
removed.
- Kill switch / disable path: N/A.
- Unsafe override required: No.
- Qualification impact: None.
- Rollback path: Revert this commit.

## 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
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] 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 did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Screenshots (if applicable)

N/A

## Additional Notes

- Part of maintainer-requested cleanup #4136 (dead code, duplication,
debuggability), split into small PRs for review.
- No new tests or docs are needed, because this is a pure removal and
none of the removed names were documented.
- `_DEFAULT_1M_MODEL` stays, because
`tests/test_cli/test_wrap_helpers.py` pins it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4118"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 09:01:00 -07:00
JD Davis 4263da12b5 fix(deps): remediate vulnerable CLI and plugin dependency trees (#3521)
Updates the wrap E2E CLI and OpenCode plugin dependency trees to remove
vulnerable versions matching 194 of the 198 open Dependabot alerts
reviewed on 2026-09-10.

- Upgrade the pinned OpenClaw CLI from 2026.4.7 to 2026.9.3 and use Node
24 in its Docker harness to satisfy the new engine requirement. Its
current dependency tree removes the vulnerable legacy extraction,
image/PDF, and coding-agent dependencies and updates Hono/tar.
- Upgrade Vitest to 4.1.11 and resolve TOML to 4.3.0 in the OpenCode
plugin lockfile.
- Handle OpenClaw's explicit legacy-flag migration with its
source/capability confirmation flags, preserving terminal install-policy
failures. Run the isolated Docker gateway in the foreground on loopback
with a per-run authentication token.
- Include `/e2e/wrap/tools` in Dependabot's npm update directories.
- Document the four unresolved optional Python dependency alerts in
`SECURITY.md`, with upstream evidence and exposure mitigations. ChromaDB
has no patched release; Accelerate 1.15.0 still has the unsafe
checkpoint loader despite being outside the advisory's stated version
range. No alerts are dismissed and no supported integrations are
removed.

Validation: both npm lockfile audits report zero vulnerabilities; all
194 npm advisory ranges were checked against every installed package
path in the new locks, including an independent review. OpenCode
typecheck, build, all 17 tests, and standalone build pass; both
standalone artifacts exactly match the committed wheel bundles. The
Docker image builds and the full local Docker wrap E2E passes with the
compatibility changes mounted into the built image. All 41 Python
OpenClaw wrapper/provider tests and changed-file Ruff checks pass. CI is
green on e6d760de7b: all four main Python
test shards, optional-extras and Agno tests, package builds, wrapper
checks, CodeQL, dependency/secret scans, and Docker init/wrap/native E2E
passed.

Remaining upstream blockers: Dependabot #204, #205, #206 (ChromaDB) and
#211 (Accelerate). This PR does not claim those four are fixed. Leave
this PR open for review; do not merge automatically.
2026-09-10 09:06:44 -05:00
Tejas Chopra c5545d6ac4 fix(wrap): use canonical headroom-openclaw npm package for wrap openclaw (#1969) (#2120)
## Description
`headroom wrap openclaw` installed a non-existent npm spec — the
`--plugin-spec` default was `headroom-ai/openclaw`, which npm reads as a
GitHub shorthand and fails; the published package is `headroom-openclaw`
(see `plugins/openclaw/package.json`).

Fix introduces a single `OPENCLAW_NPM_PACKAGE = "headroom-openclaw"`
constant (kept in sync with `package.json` and the release env), uses it
as the default, and defers writing the `plugins.entries.headroom` config
until after a successful install so a hard failure leaves no stale
entry.

Closes #1969

## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made
- `headroom/providers/openclaw/wrap.py` + `__init__.py`: canonical
`OPENCLAW_NPM_PACKAGE` constant.
- `headroom/cli/wrap.py`: use it as `--plugin-spec` default; write
config only after successful install.
- `tests/test_cli/test_wrap_openclaw.py`: expect `headroom-openclaw`;
install-before-config ordering; failed-install-writes-no-config test.

## Testing
- [x] Unit tests pass (`pytest tests/test_cli/test_wrap_openclaw.py`) —
29 passed
- [x] Linting passes (`ruff check`)
### Test Output
```text
29 passed
ruff: All checks passed!
```

## Real Behavior Proof
- Before: `wrap openclaw` → npm "unsupported spec" error; a failed
install left a stale config entry.
- After: installs `headroom-openclaw`; no config written on failure.
2026-07-13 16:33:44 -04:00
Tejas Chopra eaf5980b4a fix: stabilize codex compression, stats, and proxy lifecycle 2026-05-09 13:47:53 -07:00
JerrettDavisandCopilot a1dcda6bc4 feat(cli): support OpenClaw in Docker-native installs
Add host-managed OpenClaw wrap and unwrap flows to the Docker-native wrappers so the installed headroom script can configure the OpenClaw plugin on the host while keeping Headroom itself in Docker. Reuse hidden prepare-only hooks for OpenClaw config payloads, preserve existing plugin metadata on unwrap, and update the Docker-native and integration docs to reflect the supported flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-11 00:04:15 -05:00
JerrettDavisandCopilot 37f32a8922 test(openclaw): cover branch routing paths
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-08 23:46:16 -05:00
JerrettDavis 0da1a7b4de Add OpenClaw unwrap flow and non-blocking proxy startup 2026-04-08 21:16:32 -05:00
JerrettDavisandCopilot addcfcffcd Merge upstream/main into feat/docker-e2e-wrap-validation
Resolve the PR merge conflict by carrying forward the secure TLS fail-closed rtk download behavior, bring in the latest upstream proxy-handler updates, and fix the OpenClaw linked-install fallback so it copies the required hook-shim directory with regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-07 23:54:05 -05:00
JerrettDavis cd2741cfff test(cli): add branch coverage for wrap openclaw flows 2026-04-03 23:55:14 -05:00
JerrettDavis 61dacc94a1 fix(cli): default wrap openclaw spec to headroom-ai/openclaw 2026-04-03 23:36:23 -05:00
JerrettDavis 490cf15a57 style: apply ruff formatting for wrap openclaw changes 2026-04-03 23:20:15 -05:00
JerrettDavis 3a25ed4571 fix(cli): make wrap openclaw npm-first and idempotent 2026-04-03 23:15:24 -05:00
JerrettDavis c5e3686c89 feat(cli): add one-command OpenClaw wrap bootstrap 2026-04-03 23:08:13 -05:00