Files
headroom/plugins/opencode
Kenneth WongandKenneth Wong 2e49e5304b fix(deps): clear the glob and minimatch npm audit findings (#4599)
## Description

Since 2026-10-30, `npm audit (e2e/wrap/tools)` and `npm audit
(plugins/opencode)` fail on every PR. Main has not run since, so it will
fail the same way on its next push. Two advisories were published that
day:

- glob
[GHSA-3g3m-2fjr-6pw4](https://github.com/advisories/GHSA-3g3m-2fjr-6pw4)
(moderate): an aborted async walk keeps reading directories after it
rejects. Affects 9.0.0 to 14.0.1; fixed only in 14.0.2.
- minimatch
[GHSA-g3hv-75wg-m249](https://github.com/advisories/GHSA-g3hv-75wg-m249)
(moderate): `**/../` patterns expand the pattern parts exponentially,
then compare every pair, at `optimizationLevel >= 2`. Affects < 11.0.1;
fixed only in 11.0.1.

Neither fix is backported to an older major, and upstream has not moved:
openclaw 2026.10.9 still pins minimatch 10.2.6, and `@opencode/util`
2.2.5 still pins glob 13.0.5 and minimatch 10.2.5.

The undici and ip-address findings in the same logs come from npm
12.2.1's bundled copies. They were already listed in
`e2e/wrap/tools/npm-audit-exceptions.json` and did not fail the job (CI
printed `NOT EXCEPTED` only for glob and minimatch). npm 12.2.1 is still
the latest release, so they stay excepted until the existing 2026-11-15
expiry.

## Type of Change

- [x] 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
- [ ] Code refactoring (no functional changes)

## Changes Made

- `e2e/wrap/tools/package.json`: override OpenClaw's `minimatch` to
11.0.3, next to its existing `undici` override.
- `e2e/wrap/tools/npm-audit-exceptions.json`: add npm 12.2.1's bundled
`glob` 13.0.6 and `minimatch` 10.2.5 at their exact paths, under the
existing 2026-11-15 expiry. Bundled copies ignore overrides, the same
reason the bundled undici and ip-address are listed.
- `e2e/wrap/tools/dependency-regression.test.cjs`: new test. It counts
minimatch's pairwise `partsMatch` comparisons for a 4096-part `**/../`
pattern in the copy OpenClaw resolves. That's 8,386,560 on 10.2.6 and 0
on 11.0.3. It counts calls instead of timing, so it can't flake on a
slow runner. It fails loudly if minimatch renames `partsMatch`.
- `e2e/wrap/tools/README.md`: list the new check.
- `plugins/opencode/package.json`: override `glob` to 14.0.3 and
`minimatch` to 11.0.3. Every copy is a dev dependency
(`@opencode/plugin`, npm's `@npmcli/*` tooling, `rimraf` under
`gaxios`). glob 14 is required: minimatch 11 changes `Minimatch.set`
entries from `RegExp`s to `Matcher` objects, which globs before 14 rely
on.
- Both `package-lock.json` files are regenerated with npm 11.16.0 (`npm
install --package-lock-only`):
- e2e: only `minimatch` 10.2.6 → 11.0.3, plus its new dependency
`@isaacs/nonrecursive-glob-match`.
- opencode: `glob` 13.0.5 → 14.0.3, `minimatch` 10.2.5 → 11.0.3 and
`path-scurry` 2.0.2 → 3.0.0. rimraf's nested glob 10 and its old CLI
helper packages drop out.

## Testing

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

### Test Output

```text
# CI's audit step, run locally (the Python exception check copied from .github/workflows/security.yml)
$ cd plugins/opencode && npm audit --package-lock-only --audit-level=low
found 0 vulnerabilities
$ cd e2e/wrap/tools && npm audit --package-lock-only --json > audit.json && python3 ci_audit_check.py audit.json
Only excepted bundled advisories remain (8), until 2026-11-15.

# e2e/wrap/tools: npm ci of main's lock (minimatch 10.2.6), then the new test file
not ok 2 - minimatch bounds the **/.. expansion instead of comparing every pair (GHSA-g3hv-75wg-m249)
  error: '8386560 pairwise part comparisons'
# pass 2
# fail 1
# npm ci of this branch's lock (minimatch 11.0.3)
ok 1 - Ajv rejects a percent-encoded scheme instead of aliasing an HTTPS schema
ok 2 - minimatch bounds the **/.. expansion instead of comparing every pair (GHSA-g3hv-75wg-m249)
ok 3 - unsupported charset with invalid gzip leaves the Express process healthy
# pass 3
# fail 0

# plugins/opencode after npm ci of this branch's lock
$ npm test
 Test Files  4 passed (4)
      Tests  61 passed (61)
$ npm run typecheck        # exit 0
$ npm run build            # ESM + DTS build success
$ npm run build:standalone # ESM build success, dist-standalone/index.js 759.23 KB
```

## Real Behavior Proof

- Environment: macOS 27 (arm64), Node 24.22.2; npm 11.16.0 for the
lockfiles; a fresh `npm ci --ignore-scripts` of each lock in a scratch
directory.
- Exact command / steps: (1) the audit commands above. (2) `openclaw
--version`, `openclaw config file` and `openclaw health` from the new
e2e install, in a temporary HOME. (3) Dynamically import each OpenClaw
dist module that imports minimatch (`policy-*`,
`systemd-service-files-*`, `workspace-bootstrap-policy-*`). (4) grep
both OpenCode builds for glob/minimatch code.
- Observed result: both audits pass. `openclaw --version` prints
`OpenClaw 2026.10.6 (fe06181)`, `config file` prints the config path,
and `health` reports the expected missing-credentials message. All three
modules load on minimatch 11.0.3. Neither `dist/index.js` nor
`dist-standalone/` (the copy shipped in the wheel) contains glob or
minimatch code, so the OpenCode change does not change shipped code.
- Not tested: the Docker wrap E2E locally; this PR's `docker-native-e2e`
and Wrap E2E jobs run it, since their path filters include `e2e/**`.

## Runtime Rollout Safety

- Rollout-managed feature(s): none
- Minimum rollout channel: n/a, dependency pins for the E2E harness and
the OpenCode plugin's dev tooling
- Stable/default behavior changed: no shipped code changes. The E2E
image's OpenClaw now loads minimatch 11.0.3. One OpenClaw path relies on
minimatch 10 internals: `expandSystemdEnvironmentFilePattern` (systemd
`EnvironmentFile=` patterns with wildcards) checks `part instanceof
RegExp`. On 11 those parts are `Matcher` objects, so wildcard entries
would match no files. It runs only for an installed systemd unit; the
harness runs `openclaw gateway --bind loopback` in the foreground, so it
never reaches that path.
- Kill switch / disable path: none needed
- Unsafe override required: no
- Qualification impact: none expected for the wheel or SDK; the E2E
harness picks up the new lock on its next image build
- 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
- [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
- [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

**Dependency justification** (CONTRIBUTING, "Dependencies & supply
chain"):

| Package | Why this version | Maintainer, activity | Install surface |
|---|---|---|---|
| `glob` 13.0.5 → 14.0.3 (opencode, dev only) | Security patch:
GHSA-3g3m-2fjr-6pw4 is fixed only in 14.0.2. 14.0.3 is the latest and
needs the minimatch 11 below. | isaacs (sole npm maintainer) since 2011,
[isaacs/node-glob](https://github.com/isaacs/node-glob). 14 releases in
the last 12 months; 14.0.3 published 2026-10-28. Earlier advisory:
GHSA-5j98-mcp5-4vw2 (high, 2025-11, CLI `--shell`, fixed in 12). | Deps:
minipass, minimatch, path-scurry. No native code. No install-time script
(`prepare` runs only for git or local installs). No network use. |
| `minimatch` → 11.0.3 (opencode dev; e2e via openclaw) | Security
patch: GHSA-g3hv-75wg-m249 is fixed only in 11.0.1. 11.0.3 is the
latest. | isaacs since 2011,
[isaacs/minimatch](https://github.com/isaacs/minimatch). 35 releases in
the last 12 months, many of them ReDoS hardening. Earlier advisories:
three highs in 2026-02 and older ReDoS fixes (2022, 2018), all fixed.
11.0 replaces per-portion `RegExp`s with a non-recursive matcher, the
structural fix for that class. | Deps: brace-expansion and the new
package below. No native code, install-time script or network use. |
| `path-scurry` 2.0.2 → 3.0.0 (opencode, dev only) | Required by glob
14. | isaacs,
[isaacs/path-scurry](https://github.com/isaacs/path-scurry). 3 releases
in the last 12 months; no advisories. | Deps: minipass, lru-cache. No
native code, install-time script or network use. |
| `@isaacs/nonrecursive-glob-match` 1.0.3 (new, both lockfiles) |
Required by minimatch 11; it is the new matcher that replaces the
`RegExp` path. | isaacs, source at
[isaacs/nonrecursive-glob-match](https://github.com/isaacs/nonrecursive-glob-match)
(repo created 2026-03-06; the npm manifest omits its `repository`
field). **New:** first npm release 2026-10-26, 5 versions so far, no
advisories yet. | No dependencies. No native code, install-time script
or network use. 380 KB unpacked. |

None of the four tarballs has npm provenance attestations; each carries
registry signatures, and the lockfiles pin their integrity hashes. The
new matcher package is the one with no track record. It is accepted here
only because it is now a hard dependency of the only fixed minimatch
release, from the same maintainer as minimatch and glob.

- "Unit tests pass" covers the e2e `npm test` and OpenCode's vitest
suite; no Python changed, so ruff and mypy are left unchecked.
- Deadline: `npm-audit-exceptions.json` still expires on **2026-11-15**.
I kept the existing date rather than extend it. After that day, `npm
audit (e2e/wrap/tools)` fails on every PR by design until someone acts.
Before then:
- If npm has shipped a release bundling glob ≥ 14.0.2, minimatch ≥
11.0.1, undici ≥ 6.29.1 and ip-address ≥ 10.7.4, bump the `npm` override
and delete the exceptions.
  - If not, move `expires` with a one-line reason.
- Revisit the openclaw and OpenCode overrides once openclaw and
`@opencode/util` move to the fixed majors themselves.

https://claude.ai/code/session_01S4VPhWACY6qi2jBcN3M2sr

Co-authored-by: Kenneth Wong <17061293+KennethWKZ@users.noreply.github.com>
2026-11-03 08:12:57 +05:30
..

headroom-opencode

OpenCode integration helpers for Headroom. The package supports two integration paths:

  1. Provider config helpers used by headroom wrap opencode and persistent installs.
  2. A native OpenCode plugin that installs Headroom transport interception and exposes the retrieve tool.

Install

npm install headroom-opencode

Provider Config Helpers

Use these helpers when you need to generate OpenCode config that routes a headroom provider through a running Headroom proxy.

import {
  buildOpencodeConfigContent,
  createHeadroomProvider,
} from "headroom-opencode";

const provider = createHeadroomProvider({ proxyPort: 8787 });
const config = buildOpencodeConfigContent({
  proxyPort: 8787,
  defaultModel: "claude-sonnet-4-6",
});

console.log(provider.provider.headroom.npm);
console.log(config.model);

The generated provider uses @ai-sdk/openai-compatible and points model requests at http://127.0.0.1:<port>/v1.

Native OpenCode Plugin

The package's default export is an OpenCode plugin that loads on both OpenCode 1.x and 2.x. Register it in opencode.json:

{
  "plugin": [
    ["headroom-opencode", { "proxyUrl": "http://127.0.0.1:8787" }]
  ]
}

OpenCode 2.x migrates the 1.x plugin key automatically. To configure it the 2.x way, use "plugins": [{ "package": "headroom-opencode", "options": { ... } }].

The default export is { id: "headroom", server, setup }. OpenCode 1.x calls server (HeadroomPlugin) and 2.x calls setup (headroomSetup); each ignores the other's field. Both entry points:

  • install Headroom transport interception for OpenCode provider traffic.
  • expose the headroom_retrieve tool (a direct tool on 2.x, not only through code mode).
  • add HEADROOM_ACTIVE, HEADROOM_PROXY_URL, HEADROOM_PROJECT (and HEADROOM_BACKEND when set) to shell command environments.
  • default to HEADROOM_PROXY_URL, then http://127.0.0.1:8787, when no proxyUrl option is supplied.
  • skip routing for hosts listed in excludeHosts (or HEADROOM_OPENCODE_EXCLUDE_HOSTS); those requests go straight upstream with no compression or telemetry.

On 2.x, setup returns a cleanup that releases the transport, so hot reloads do not stack interceptors.

OpenCode 2.x keeps its own reference to fetch from before plugins load, so patching fetch alone does not catch its model traffic. On 2.x the plugin also rewrites each remote model that uses the OpenAI chat-completions or responses format so that it points at the proxy. Headers name the real upstream, as the transport does. Models on other formats (Anthropic messages, Google) are left alone. headroom wrap opencode routes native Anthropic and OpenAI through the proxy separately, via their baseURL.

To keep a provider off the proxy, list its host. An entry matches the host and all of its subdomains, and .example.com / *.example.com are accepted as spellings of example.com:

// opencode.json
{
  "plugin": [["/path/to/headroom/providers/opencode/_dist", { "excludeHosts": ["opencode.ai"] }]]
}

or, for headroom wrap opencode and spawned Node child processes, set the environment variable before launching:

HEADROOM_OPENCODE_EXCLUDE_HOSTS="opencode.ai,.corp.internal" headroom wrap opencode

Retrieve Tool

import { createHeadroomRetrieveTool } from "headroom-opencode";

const retrieve = createHeadroomRetrieveTool({
  proxyBaseUrl: "http://127.0.0.1:8787",
});

const result = await retrieve.execute({
  hash: "0123456789abcdef01234567",
});

The tool calls /v1/retrieve/<hash> on the Headroom proxy.

Compression Helper

import { compressWithHeadroom } from "headroom-opencode";

const result = await compressWithHeadroom(
  [{ role: "user", content: "Summarize this file" }],
  { model: "gpt-4o", proxyUrl: "http://127.0.0.1:8787" },
);

console.log(`Saved ${result.tokensSaved} tokens`);

Models

Model Context Output
claude-sonnet-4-6 200K 16K
claude-opus-4-6 200K 16K
claude-haiku-4-5-20251001 200K 8K
gpt-4o 128K 16K
gpt-4.1 1M 32K

The provider config exposes these as headroom/<model> and defaults to headroom/claude-sonnet-4-6.

Environment

Variable Used by Description
HEADROOM_PROXY_URL Native plugin Proxy URL used by HeadroomPlugin
HEADROOM_OPENCODE_EXCLUDE_HOSTS Native plugin Comma-separated hosts (and their subdomains) that bypass the proxy; the excludeHosts plugin option takes precedence
OPENCODE_CONFIG_CONTENT OpenCode wrapper Generated OpenCode provider, model, and MCP config

License

Apache-2.0