headroom-openclaw 0.1.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -6
- package/dist/README.md +225 -0
- package/dist/hook-shim/HOOK.md +21 -0
- package/dist/hook-shim/handler.js +3 -0
- package/dist/index.d.ts +65 -37
- package/dist/index.js +782 -232
- package/dist/index.js.map +1 -1
- package/dist/openclaw.plugin.json +125 -0
- package/dist/package.json +36 -0
- package/hook-shim/HOOK.md +21 -0
- package/hook-shim/handler.js +3 -0
- package/openclaw.plugin.json +94 -10
- package/package.json +21 -5
package/README.md
CHANGED
|
@@ -4,16 +4,68 @@ Context compression plugin for [OpenClaw](https://github.com/openclaw/openclaw).
|
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
+
Recommended one-command setup:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
headroom wrap openclaw
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Manual install:
|
|
14
|
+
|
|
7
15
|
```bash
|
|
8
16
|
pip install "headroom-ai[proxy]"
|
|
9
|
-
openclaw plugins install
|
|
17
|
+
openclaw plugins install --dangerously-force-unsafe-install headroom-ai/openclaw
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This plugin can auto-start a local `headroom proxy` when needed. OpenClaw treats process-launching plugins as unsafe by default, so `--dangerously-force-unsafe-install` is required even if you plan to use a remote proxy (the capability is declared at install time).
|
|
21
|
+
|
|
22
|
+
## Local Development Install (Detection-Friendly)
|
|
23
|
+
|
|
24
|
+
If you are testing from this repo, run npm install/build from the plugin directory so local launcher detection aligns with runtime paths. These linked installs are supported:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd plugins/openclaw
|
|
28
|
+
npm install
|
|
29
|
+
npm run build
|
|
30
|
+
openclaw plugins install --dangerously-force-unsafe-install --link .
|
|
31
|
+
openclaw plugins install --dangerously-force-unsafe-install --link dist
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
From the repo root, install the plugin directory explicitly:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
openclaw plugins install --dangerously-force-unsafe-install --link ./plugins/openclaw
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or, from inside `dist/`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cd plugins/openclaw/dist
|
|
44
|
+
openclaw plugins install --dangerously-force-unsafe-install --link .
|
|
10
45
|
```
|
|
11
46
|
|
|
47
|
+
Why this matters:
|
|
48
|
+
- The plugin checks launchers in this order: PATH -> local npm bin -> global npm -> python.
|
|
49
|
+
- "local npm bin" means `plugins/openclaw/node_modules/.bin/headroom` relative to the source checkout.
|
|
50
|
+
- Using `--link dist` (or `--link .` from `dist/`) still keeps runtime code adjacent to the checkout, and launcher detection falls back to PATH/global/python if a local npm bin is not present under the installed root.
|
|
51
|
+
- `plugins/openclaw` also carries a no-op hook shim so OpenClaw's hook-pack fallback treats the path as valid instead of emitting a misleading `package.json missing openclaw.hooks` warning.
|
|
52
|
+
- If you install from a `.tgz`, local npm bin may not exist in the installed extension and detection will fall back to PATH/global/python.
|
|
53
|
+
|
|
12
54
|
## Configure
|
|
13
55
|
|
|
56
|
+
Install automatically selects the `contextEngine` slot for `headroom` on current OpenClaw releases. If you need to switch back manually, set `plugins.slots.contextEngine` to `"legacy"` or another engine id.
|
|
57
|
+
|
|
14
58
|
```json
|
|
15
59
|
{
|
|
16
60
|
"plugins": {
|
|
61
|
+
"entries": {
|
|
62
|
+
"headroom": {
|
|
63
|
+
"enabled": true,
|
|
64
|
+
"config": {
|
|
65
|
+
"proxyUrl": "http://127.0.0.1:8787"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
17
69
|
"slots": {
|
|
18
70
|
"contextEngine": "headroom"
|
|
19
71
|
}
|
|
@@ -21,7 +73,117 @@ openclaw plugins install @headroom-ai/openclaw
|
|
|
21
73
|
}
|
|
22
74
|
```
|
|
23
75
|
|
|
24
|
-
|
|
76
|
+
`proxyUrl` is optional. If omitted, the plugin auto-detects on localhost:
|
|
77
|
+
- `http://127.0.0.1:<proxyPort>`
|
|
78
|
+
- `http://localhost:<proxyPort>`
|
|
79
|
+
|
|
80
|
+
Default `proxyPort` is `8787`. Auto-start is opt-in; in production, prefer an externally
|
|
81
|
+
managed proxy such as systemd with `proxyUrl` set and `autoStart: false`.
|
|
82
|
+
|
|
83
|
+
### Upstream gateway routing
|
|
84
|
+
|
|
85
|
+
By default, the plugin also rewrites the built-in `openai-codex` provider base URL to a verified active Headroom proxy at runtime. That means Codex provider traffic flows through Headroom, so `/stats` can observe real upstream request and cache activity instead of only local context compression.
|
|
86
|
+
|
|
87
|
+
This does not replace Headroom's existing Codex routing rules. The proxy already decides between `api.openai.com` and `chatgpt.com/backend-api/codex/responses` based on ChatGPT auth. The plugin change only points OpenClaw's provider config at the active proxy in memory and preserves the rest of the provider config.
|
|
88
|
+
|
|
89
|
+
You can also route additional provider ids such as `anthropic`, `github-copilot`, `google`, or `openrouter` through the same proxy:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"plugins": {
|
|
94
|
+
"entries": {
|
|
95
|
+
"headroom": {
|
|
96
|
+
"enabled": true,
|
|
97
|
+
"config": {
|
|
98
|
+
"gatewayProviderIds": ["openai-codex", "anthropic", "github-copilot", "google", "openrouter"]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
When `gatewayProviderIds` is set, it becomes the exact list the plugin rewrites in memory for the current gateway process.
|
|
107
|
+
|
|
108
|
+
For convenience, the plugin also accepts family aliases:
|
|
109
|
+
- `codex` -> `openai-codex`
|
|
110
|
+
- `claude` -> `anthropic`
|
|
111
|
+
- `copilot` -> `github-copilot`
|
|
112
|
+
- `gemini` -> `google`
|
|
113
|
+
|
|
114
|
+
When OpenClaw has already resolved a provider's upstream `baseUrl`, the plugin preserves protocol-specific path segments while swapping only the origin. That keeps provider families on the right proxy route:
|
|
115
|
+
- Codex / ChatGPT backend: `/backend-api`
|
|
116
|
+
- OpenAI-compatible providers: `/v1` or `/api/v1`
|
|
117
|
+
- GitHub Copilot Claude-family models: `/anthropic`
|
|
118
|
+
- Gemini: `/v1beta`
|
|
119
|
+
|
|
120
|
+
GitHub Copilot is a special case because OpenClaw can route it through either OpenAI Responses or Anthropic Messages depending on the selected model. The plugin only rewrites Copilot when OpenClaw has already resolved the upstream `baseUrl`, so it can preserve the correct `/v1` or `/anthropic` path instead of guessing.
|
|
121
|
+
|
|
122
|
+
The routing is intentionally lightweight and reversible:
|
|
123
|
+
- the plugin does not persist provider `baseUrl` changes back to `openclaw.json`
|
|
124
|
+
- disabling the plugin, clearing `gatewayProviderIds`, or restarting without Headroom restores OpenClaw's normal provider resolution
|
|
125
|
+
- if you want durable provider rewrites, use `headroom wrap openclaw` instead of relying on plugin install side effects
|
|
126
|
+
|
|
127
|
+
If you need to disable that behavior:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"plugins": {
|
|
132
|
+
"entries": {
|
|
133
|
+
"headroom": {
|
|
134
|
+
"enabled": true,
|
|
135
|
+
"config": {
|
|
136
|
+
"routeCodexViaProxy": false
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Local proxy (auto-start)
|
|
145
|
+
|
|
146
|
+
When `proxyUrl` points to localhost (or is omitted), the plugin will auto-start `headroom proxy` if no running proxy is detected. Launch order:
|
|
147
|
+
1. `headroom` from `PATH`
|
|
148
|
+
2. local npm bin (`node_modules/.bin/headroom`)
|
|
149
|
+
3. global npm bin
|
|
150
|
+
4. Python module (`python -m headroom.cli proxy ...`)
|
|
151
|
+
|
|
152
|
+
If `pythonPath` is set, it is tried first in the Python fallback step.
|
|
153
|
+
|
|
154
|
+
Docker-native Headroom installs intentionally leave `pythonPath` unset so this launcher order prefers the installed host `headroom` wrapper on `PATH`, which then runs Headroom in Docker.
|
|
155
|
+
|
|
156
|
+
### Remote proxy (connect-only)
|
|
157
|
+
|
|
158
|
+
Point `proxyUrl` to any reachable Headroom instance:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"config": {
|
|
163
|
+
"proxyUrl": "https://headroom.example.com:8787"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Remote URLs are **connect-only** — the plugin probes the URL at startup and fails fast if the proxy is not reachable. No subprocess is spawned for remote addresses.
|
|
169
|
+
|
|
170
|
+
## Manual Proxy Setup
|
|
171
|
+
|
|
172
|
+
If you prefer to manage the proxy yourself (or are running a remote instance), start it before launching OpenClaw:
|
|
173
|
+
|
|
174
|
+
Python install:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pip install "headroom-ai[proxy]"
|
|
178
|
+
headroom proxy --host 127.0.0.1 --port 8787
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
NPM install:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm install -g headroom-ai
|
|
185
|
+
headroom proxy --host 127.0.0.1 --port 8787
|
|
186
|
+
```
|
|
25
187
|
|
|
26
188
|
## How It Works
|
|
27
189
|
|
|
@@ -38,10 +200,16 @@ Compression is lossless via CCR (Compress-Cache-Retrieve): originals are stored
|
|
|
38
200
|
|
|
39
201
|
| Option | Default | Description |
|
|
40
202
|
|--------|---------|-------------|
|
|
41
|
-
| `proxyUrl` | auto-detected | URL of
|
|
42
|
-
| `
|
|
43
|
-
| `pythonPath` | auto-detected |
|
|
44
|
-
| `
|
|
203
|
+
| `proxyUrl` | auto-detected | Optional URL of a Headroom proxy. Configured URLs are probe-gated before provider routing. Remote URLs (`https://headroom.example.com`) are connect-only. |
|
|
204
|
+
| `proxyPort` | `8787` | Port used for default auto-detect and optional local auto-start when `proxyUrl` is not set. |
|
|
205
|
+
| `pythonPath` | auto-detected | Optional Python executable override for Python fallback launcher. |
|
|
206
|
+
| `autoStart` | `false` | Opt-in auto-start for a local `headroom proxy` if not already running (local URLs only; ignored for remote proxies). Keep `false` when systemd owns the proxy. |
|
|
207
|
+
| `startupTimeoutMs` | `20000` | Time to wait for auto-started proxy to become healthy |
|
|
208
|
+
| `requestTimeoutMs` | `30000` | Maximum milliseconds to wait for a single `compress()` call. If the proxy hangs or is slow, the call is cancelled after this deadline and the original uncompressed messages are used as a fallback. |
|
|
209
|
+
| `circuitBreakerThreshold` | `3` | Number of consecutive `assemble()` errors before the circuit breaker opens and all requests bypass the proxy. Prevents cascading failures when the proxy is unhealthy. |
|
|
210
|
+
| `circuitBreakerCooldownMs` | `60000` | How long (ms) the circuit breaker stays open after the threshold is reached. After the cool-down the breaker resets automatically and the next request re-probes the proxy via `/health`. |
|
|
211
|
+
| `routeCodexViaProxy` | `true` | Rewrite OpenClaw's built-in `openai-codex` provider to use the active Headroom proxy in memory so upstream Codex requests pass through Headroom. |
|
|
212
|
+
| `gatewayProviderIds` | `[]` | Optional explicit list of OpenClaw provider ids to route through the active Headroom proxy in memory. Friendly aliases `codex`, `claude`, `copilot`, and `gemini` are also accepted. When set, this overrides the default `openai-codex` routing list. |
|
|
45
213
|
|
|
46
214
|
## Comparison with lossless-claw
|
|
47
215
|
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @headroom-ai/openclaw
|
|
2
|
+
|
|
3
|
+
Context compression plugin for [OpenClaw](https://github.com/openclaw/openclaw). Compresses tool outputs, code, logs, and structured data — 70-90% token savings with zero LLM calls.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Recommended one-command setup:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
headroom wrap openclaw
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Manual install:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install "headroom-ai[proxy]"
|
|
17
|
+
openclaw plugins install --dangerously-force-unsafe-install headroom-ai/openclaw
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
This plugin can auto-start a local `headroom proxy` when needed. OpenClaw treats process-launching plugins as unsafe by default, so `--dangerously-force-unsafe-install` is required even if you plan to use a remote proxy (the capability is declared at install time).
|
|
21
|
+
|
|
22
|
+
## Local Development Install (Detection-Friendly)
|
|
23
|
+
|
|
24
|
+
If you are testing from this repo, run npm install/build from the plugin directory so local launcher detection aligns with runtime paths. These linked installs are supported:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
cd plugins/openclaw
|
|
28
|
+
npm install
|
|
29
|
+
npm run build
|
|
30
|
+
openclaw plugins install --dangerously-force-unsafe-install --link .
|
|
31
|
+
openclaw plugins install --dangerously-force-unsafe-install --link dist
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
From the repo root, install the plugin directory explicitly:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
openclaw plugins install --dangerously-force-unsafe-install --link ./plugins/openclaw
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or, from inside `dist/`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cd plugins/openclaw/dist
|
|
44
|
+
openclaw plugins install --dangerously-force-unsafe-install --link .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Why this matters:
|
|
48
|
+
- The plugin checks launchers in this order: PATH -> local npm bin -> global npm -> python.
|
|
49
|
+
- "local npm bin" means `plugins/openclaw/node_modules/.bin/headroom` relative to the source checkout.
|
|
50
|
+
- Using `--link dist` (or `--link .` from `dist/`) still keeps runtime code adjacent to the checkout, and launcher detection falls back to PATH/global/python if a local npm bin is not present under the installed root.
|
|
51
|
+
- `plugins/openclaw` also carries a no-op hook shim so OpenClaw's hook-pack fallback treats the path as valid instead of emitting a misleading `package.json missing openclaw.hooks` warning.
|
|
52
|
+
- If you install from a `.tgz`, local npm bin may not exist in the installed extension and detection will fall back to PATH/global/python.
|
|
53
|
+
|
|
54
|
+
## Configure
|
|
55
|
+
|
|
56
|
+
Install automatically selects the `contextEngine` slot for `headroom` on current OpenClaw releases. If you need to switch back manually, set `plugins.slots.contextEngine` to `"legacy"` or another engine id.
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"plugins": {
|
|
61
|
+
"entries": {
|
|
62
|
+
"headroom": {
|
|
63
|
+
"enabled": true,
|
|
64
|
+
"config": {
|
|
65
|
+
"proxyUrl": "http://127.0.0.1:8787"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"slots": {
|
|
70
|
+
"contextEngine": "headroom"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`proxyUrl` is optional. If omitted, the plugin auto-detects on localhost:
|
|
77
|
+
- `http://127.0.0.1:<proxyPort>`
|
|
78
|
+
- `http://localhost:<proxyPort>`
|
|
79
|
+
|
|
80
|
+
Default `proxyPort` is `8787`. Auto-start is opt-in; in production, prefer an externally
|
|
81
|
+
managed proxy such as systemd with `proxyUrl` set and `autoStart: false`.
|
|
82
|
+
|
|
83
|
+
### Upstream gateway routing
|
|
84
|
+
|
|
85
|
+
By default, the plugin also rewrites the built-in `openai-codex` provider base URL to a verified active Headroom proxy at runtime. That means Codex provider traffic flows through Headroom, so `/stats` can observe real upstream request and cache activity instead of only local context compression.
|
|
86
|
+
|
|
87
|
+
This does not replace Headroom's existing Codex routing rules. The proxy already decides between `api.openai.com` and `chatgpt.com/backend-api/codex/responses` based on ChatGPT auth. The plugin change only points OpenClaw's provider config at the active proxy in memory and preserves the rest of the provider config.
|
|
88
|
+
|
|
89
|
+
You can also route additional provider ids such as `anthropic`, `github-copilot`, `google`, or `openrouter` through the same proxy:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"plugins": {
|
|
94
|
+
"entries": {
|
|
95
|
+
"headroom": {
|
|
96
|
+
"enabled": true,
|
|
97
|
+
"config": {
|
|
98
|
+
"gatewayProviderIds": ["openai-codex", "anthropic", "github-copilot", "google", "openrouter"]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
When `gatewayProviderIds` is set, it becomes the exact list the plugin rewrites in memory for the current gateway process.
|
|
107
|
+
|
|
108
|
+
For convenience, the plugin also accepts family aliases:
|
|
109
|
+
- `codex` -> `openai-codex`
|
|
110
|
+
- `claude` -> `anthropic`
|
|
111
|
+
- `copilot` -> `github-copilot`
|
|
112
|
+
- `gemini` -> `google`
|
|
113
|
+
|
|
114
|
+
When OpenClaw has already resolved a provider's upstream `baseUrl`, the plugin preserves protocol-specific path segments while swapping only the origin. That keeps provider families on the right proxy route:
|
|
115
|
+
- Codex / ChatGPT backend: `/backend-api`
|
|
116
|
+
- OpenAI-compatible providers: `/v1` or `/api/v1`
|
|
117
|
+
- GitHub Copilot Claude-family models: `/anthropic`
|
|
118
|
+
- Gemini: `/v1beta`
|
|
119
|
+
|
|
120
|
+
GitHub Copilot is a special case because OpenClaw can route it through either OpenAI Responses or Anthropic Messages depending on the selected model. The plugin only rewrites Copilot when OpenClaw has already resolved the upstream `baseUrl`, so it can preserve the correct `/v1` or `/anthropic` path instead of guessing.
|
|
121
|
+
|
|
122
|
+
The routing is intentionally lightweight and reversible:
|
|
123
|
+
- the plugin does not persist provider `baseUrl` changes back to `openclaw.json`
|
|
124
|
+
- disabling the plugin, clearing `gatewayProviderIds`, or restarting without Headroom restores OpenClaw's normal provider resolution
|
|
125
|
+
- if you want durable provider rewrites, use `headroom wrap openclaw` instead of relying on plugin install side effects
|
|
126
|
+
|
|
127
|
+
If you need to disable that behavior:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"plugins": {
|
|
132
|
+
"entries": {
|
|
133
|
+
"headroom": {
|
|
134
|
+
"enabled": true,
|
|
135
|
+
"config": {
|
|
136
|
+
"routeCodexViaProxy": false
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Local proxy (auto-start)
|
|
145
|
+
|
|
146
|
+
When `proxyUrl` points to localhost (or is omitted), the plugin will auto-start `headroom proxy` if no running proxy is detected. Launch order:
|
|
147
|
+
1. `headroom` from `PATH`
|
|
148
|
+
2. local npm bin (`node_modules/.bin/headroom`)
|
|
149
|
+
3. global npm bin
|
|
150
|
+
4. Python module (`python -m headroom.cli proxy ...`)
|
|
151
|
+
|
|
152
|
+
If `pythonPath` is set, it is tried first in the Python fallback step.
|
|
153
|
+
|
|
154
|
+
Docker-native Headroom installs intentionally leave `pythonPath` unset so this launcher order prefers the installed host `headroom` wrapper on `PATH`, which then runs Headroom in Docker.
|
|
155
|
+
|
|
156
|
+
### Remote proxy (connect-only)
|
|
157
|
+
|
|
158
|
+
Point `proxyUrl` to any reachable Headroom instance:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"config": {
|
|
163
|
+
"proxyUrl": "https://headroom.example.com:8787"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Remote URLs are **connect-only** — the plugin probes the URL at startup and fails fast if the proxy is not reachable. No subprocess is spawned for remote addresses.
|
|
169
|
+
|
|
170
|
+
## Manual Proxy Setup
|
|
171
|
+
|
|
172
|
+
If you prefer to manage the proxy yourself (or are running a remote instance), start it before launching OpenClaw:
|
|
173
|
+
|
|
174
|
+
Python install:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pip install "headroom-ai[proxy]"
|
|
178
|
+
headroom proxy --host 127.0.0.1 --port 8787
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
NPM install:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm install -g headroom-ai
|
|
185
|
+
headroom proxy --host 127.0.0.1 --port 8787
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## How It Works
|
|
189
|
+
|
|
190
|
+
Every time OpenClaw assembles context for the model, the plugin compresses tool outputs and large messages:
|
|
191
|
+
|
|
192
|
+
- **JSON arrays** (tool outputs, search results) — statistical selection keeps anomalies, errors, boundaries
|
|
193
|
+
- **Code** — AST-aware compression via tree-sitter
|
|
194
|
+
- **Logs** — pattern deduplication, keeps errors and boundaries
|
|
195
|
+
- **Text** — ML-based token compression
|
|
196
|
+
|
|
197
|
+
Compression is lossless via CCR (Compress-Cache-Retrieve): originals are stored and the agent gets a `headroom_retrieve` tool to access full details when needed.
|
|
198
|
+
|
|
199
|
+
## Configuration Options
|
|
200
|
+
|
|
201
|
+
| Option | Default | Description |
|
|
202
|
+
|--------|---------|-------------|
|
|
203
|
+
| `proxyUrl` | auto-detected | Optional URL of a Headroom proxy. Configured URLs are probe-gated before provider routing. Remote URLs (`https://headroom.example.com`) are connect-only. |
|
|
204
|
+
| `proxyPort` | `8787` | Port used for default auto-detect and optional local auto-start when `proxyUrl` is not set. |
|
|
205
|
+
| `pythonPath` | auto-detected | Optional Python executable override for Python fallback launcher. |
|
|
206
|
+
| `autoStart` | `false` | Opt-in auto-start for a local `headroom proxy` if not already running (local URLs only; ignored for remote proxies). Keep `false` when systemd owns the proxy. |
|
|
207
|
+
| `startupTimeoutMs` | `20000` | Time to wait for auto-started proxy to become healthy |
|
|
208
|
+
| `requestTimeoutMs` | `30000` | Maximum milliseconds to wait for a single `compress()` call. If the proxy hangs or is slow, the call is cancelled after this deadline and the original uncompressed messages are used as a fallback. |
|
|
209
|
+
| `circuitBreakerThreshold` | `3` | Number of consecutive `assemble()` errors before the circuit breaker opens and all requests bypass the proxy. Prevents cascading failures when the proxy is unhealthy. |
|
|
210
|
+
| `circuitBreakerCooldownMs` | `60000` | How long (ms) the circuit breaker stays open after the threshold is reached. After the cool-down the breaker resets automatically and the next request re-probes the proxy via `/health`. |
|
|
211
|
+
| `routeCodexViaProxy` | `true` | Rewrite OpenClaw's built-in `openai-codex` provider to use the active Headroom proxy in memory so upstream Codex requests pass through Headroom. |
|
|
212
|
+
| `gatewayProviderIds` | `[]` | Optional explicit list of OpenClaw provider ids to route through the active Headroom proxy in memory. Friendly aliases `codex`, `claude`, `copilot`, and `gemini` are also accepted. When set, this overrides the default `openai-codex` routing list. |
|
|
213
|
+
|
|
214
|
+
## Comparison with lossless-claw
|
|
215
|
+
|
|
216
|
+
| | lossless-claw | headroom |
|
|
217
|
+
|---|---|---|
|
|
218
|
+
| Compaction method | LLM summarization (DAG) | Content-aware compression (zero LLM) |
|
|
219
|
+
| Cost of compaction | Tokens (LLM calls) | Zero |
|
|
220
|
+
| Best for | Long conversations | Tool-heavy agents with large outputs |
|
|
221
|
+
| Retrieval | `lcm_grep`, `lcm_expand` | `headroom_retrieve` (instant) |
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
Apache-2.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: headroom-link-shim
|
|
3
|
+
description: "No-op hook shim so local plugin source paths are also valid OpenClaw hook-pack paths."
|
|
4
|
+
metadata:
|
|
5
|
+
{
|
|
6
|
+
"openclaw":
|
|
7
|
+
{
|
|
8
|
+
"emoji": "🪝",
|
|
9
|
+
"events": ["command"],
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Headroom Link Shim
|
|
15
|
+
|
|
16
|
+
This hook intentionally does nothing.
|
|
17
|
+
|
|
18
|
+
OpenClaw currently falls back to validating local plugin paths as hook packs when a
|
|
19
|
+
plugin install cannot proceed, such as when the plugin is already installed.
|
|
20
|
+
Including this no-op hook keeps `--link` installs from reporting a misleading
|
|
21
|
+
`package.json missing openclaw.hooks` error for valid Headroom plugin paths.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Headroom OpenClaw Plugin — register ContextEngine + CCR retrieval tool.
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
|
-
* openclaw plugins install
|
|
5
|
+
* openclaw plugins install headroom-ai/openclaw
|
|
6
6
|
*
|
|
7
7
|
* Configuration (in ~/.openclaw/config.json or ~/.clawdbot/clawdbot.json):
|
|
8
8
|
* {
|
|
@@ -12,20 +12,25 @@
|
|
|
12
12
|
* }
|
|
13
13
|
* }
|
|
14
14
|
*/
|
|
15
|
-
declare function headroomPlugin(api: any): void;
|
|
16
|
-
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* - If not, spawns one as a child process with auto-assigned port
|
|
22
|
-
* - Health checks, restart on crash, graceful shutdown
|
|
16
|
+
* OpenClaw 2026.x plugin API requires a `{ register(api) }` object export.
|
|
17
|
+
* The previous bare-function default export was silently skipped by the loader.
|
|
18
|
+
* See: https://github.com/chopratejas/headroom/issues/XXX
|
|
23
19
|
*/
|
|
20
|
+
declare const _default: {
|
|
21
|
+
register: typeof registerHeadroomPlugin;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare function registerHeadroomPlugin(api: any): void;
|
|
25
|
+
|
|
24
26
|
interface ProxyManagerConfig {
|
|
25
27
|
proxyUrl?: string;
|
|
28
|
+
proxyPort?: number;
|
|
26
29
|
pythonPath?: string;
|
|
27
30
|
autoStart?: boolean;
|
|
28
|
-
|
|
31
|
+
startupTimeoutMs?: number;
|
|
32
|
+
retryMaxAttempts?: number;
|
|
33
|
+
connectTimeoutSeconds?: number;
|
|
29
34
|
}
|
|
30
35
|
interface ProxyManagerLogger {
|
|
31
36
|
info(message: string): void;
|
|
@@ -33,41 +38,44 @@ interface ProxyManagerLogger {
|
|
|
33
38
|
error(message: string): void;
|
|
34
39
|
debug(message: string): void;
|
|
35
40
|
}
|
|
41
|
+
/** Default logger that prefixes all messages with `[headroom]`. */
|
|
42
|
+
declare const defaultLogger: ProxyManagerLogger;
|
|
43
|
+
interface ProxyProbeResult {
|
|
44
|
+
reachable: boolean;
|
|
45
|
+
isHeadroom: boolean;
|
|
46
|
+
reason?: string;
|
|
47
|
+
}
|
|
36
48
|
declare class ProxyManager {
|
|
37
49
|
private config;
|
|
38
50
|
private logger;
|
|
39
|
-
private process;
|
|
40
51
|
private proxyUrl;
|
|
41
|
-
private weStartedIt;
|
|
42
|
-
private restartCount;
|
|
43
|
-
private healthInterval;
|
|
44
|
-
private disposed;
|
|
45
52
|
constructor(config?: ProxyManagerConfig, logger?: ProxyManagerLogger);
|
|
46
53
|
/**
|
|
47
|
-
* Ensure a proxy is available. Returns the URL.
|
|
48
|
-
*
|
|
49
|
-
* 1. If proxyUrl is configured, use it
|
|
50
|
-
* 2. Check if proxy is already running on default port
|
|
51
|
-
* 3. If autoStart, spawn one
|
|
54
|
+
* Ensure a proxy is available. Returns the normalized URL origin.
|
|
52
55
|
*/
|
|
53
56
|
start(): Promise<string>;
|
|
57
|
+
private getProxyPort;
|
|
58
|
+
private getDefaultProxyCandidates;
|
|
54
59
|
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
private spawnProxy;
|
|
58
|
-
/**
|
|
59
|
-
* Stop the proxy if we started it.
|
|
60
|
+
* Stop manager state. Spawned proxy processes are detached and externally managed.
|
|
60
61
|
*/
|
|
61
62
|
stop(): Promise<void>;
|
|
62
63
|
getUrl(): string | null;
|
|
63
|
-
private
|
|
64
|
-
private
|
|
65
|
-
private
|
|
66
|
-
private
|
|
67
|
-
private
|
|
68
|
-
private
|
|
69
|
-
private
|
|
64
|
+
private startHeadroomProxy;
|
|
65
|
+
private buildLaunchSpecs;
|
|
66
|
+
private getConfiguredPythonCommand;
|
|
67
|
+
private getPyenvResolvedHeadroom;
|
|
68
|
+
private getPythonCommands;
|
|
69
|
+
private canExecute;
|
|
70
|
+
private getNpmGlobalPrefix;
|
|
70
71
|
}
|
|
72
|
+
declare function normalizeAndValidateProxyUrl(proxyUrl: string): string;
|
|
73
|
+
/** Returns true if the URL points to a local address (localhost or 127.0.0.1). */
|
|
74
|
+
declare function isLocalProxyUrl(proxyUrl: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Probe a configured URL and verify whether it is a running Headroom proxy.
|
|
77
|
+
*/
|
|
78
|
+
declare function probeHeadroomProxy(proxyUrl: string): Promise<ProxyProbeResult>;
|
|
71
79
|
|
|
72
80
|
/**
|
|
73
81
|
* HeadroomContextEngine — ContextEngine implementation for OpenClaw.
|
|
@@ -78,6 +86,9 @@ declare class ProxyManager {
|
|
|
78
86
|
|
|
79
87
|
interface HeadroomEngineConfig extends ProxyManagerConfig {
|
|
80
88
|
enabled?: boolean;
|
|
89
|
+
requestTimeoutMs?: number;
|
|
90
|
+
circuitBreakerThreshold?: number;
|
|
91
|
+
circuitBreakerCooldownMs?: number;
|
|
81
92
|
}
|
|
82
93
|
declare class HeadroomContextEngine {
|
|
83
94
|
readonly info: {
|
|
@@ -90,7 +101,11 @@ declare class HeadroomContextEngine {
|
|
|
90
101
|
private proxyUrl;
|
|
91
102
|
private config;
|
|
92
103
|
private logger;
|
|
104
|
+
private proxyReadyListeners;
|
|
105
|
+
private proxyStartupPromise;
|
|
106
|
+
private proxyStartupError;
|
|
93
107
|
private stats;
|
|
108
|
+
private circuit;
|
|
94
109
|
constructor(config?: HeadroomEngineConfig, logger?: ProxyManagerLogger);
|
|
95
110
|
bootstrap(params: {
|
|
96
111
|
sessionId: string;
|
|
@@ -181,6 +196,14 @@ declare class HeadroomContextEngine {
|
|
|
181
196
|
compactions: number;
|
|
182
197
|
};
|
|
183
198
|
getProxyUrl(): string | null;
|
|
199
|
+
getProxyStartupError(): unknown;
|
|
200
|
+
private isCircuitOpen;
|
|
201
|
+
private tripCircuit;
|
|
202
|
+
private resetCircuit;
|
|
203
|
+
ensureProxyStarted(): void;
|
|
204
|
+
onProxyReady(listener: (proxyUrl: string) => void | Promise<void>): () => void;
|
|
205
|
+
ensureProxyUrl(): Promise<string>;
|
|
206
|
+
private notifyProxyReady;
|
|
184
207
|
}
|
|
185
208
|
|
|
186
209
|
/**
|
|
@@ -202,6 +225,7 @@ interface OpenAIMessage {
|
|
|
202
225
|
tool_calls?: any[];
|
|
203
226
|
tool_call_id?: string;
|
|
204
227
|
name?: string;
|
|
228
|
+
_headroomMeta?: Record<string, unknown>;
|
|
205
229
|
}
|
|
206
230
|
/**
|
|
207
231
|
* Convert AgentMessage[] to OpenAI message format for compression.
|
|
@@ -211,6 +235,7 @@ declare function agentToOpenAI(messages: any[]): OpenAIMessage[];
|
|
|
211
235
|
* Convert compressed OpenAI messages back to AgentMessage format.
|
|
212
236
|
*/
|
|
213
237
|
declare function openAIToAgent(messages: OpenAIMessage[]): any[];
|
|
238
|
+
declare function normalizeAgentMessages(messages: any[]): any[];
|
|
214
239
|
|
|
215
240
|
/**
|
|
216
241
|
* CCR (Compress-Cache-Retrieve) tool for OpenClaw.
|
|
@@ -231,17 +256,20 @@ declare function createHeadroomRetrieveTool(config: RetrieveToolConfig): {
|
|
|
231
256
|
type: string;
|
|
232
257
|
description: string;
|
|
233
258
|
};
|
|
234
|
-
query: {
|
|
235
|
-
type: string;
|
|
236
|
-
description: string;
|
|
237
|
-
};
|
|
238
259
|
};
|
|
239
260
|
required: string[];
|
|
240
261
|
};
|
|
241
262
|
execute: (args: {
|
|
242
263
|
hash: string;
|
|
243
|
-
query?: string;
|
|
244
264
|
}) => Promise<string>;
|
|
245
265
|
};
|
|
246
266
|
|
|
247
|
-
|
|
267
|
+
declare const DEFAULT_GATEWAY_PROVIDER_IDS: readonly ["openai-codex"];
|
|
268
|
+
declare function resolveGatewayProviderIds(config: Record<string, unknown> | undefined): string[];
|
|
269
|
+
declare function applyGatewayProviderBaseUrls<T>(cfg: T, proxyUrl: string, providerIds: readonly string[]): {
|
|
270
|
+
changed: boolean;
|
|
271
|
+
config: T;
|
|
272
|
+
};
|
|
273
|
+
declare function applyGatewayProviderBaseUrlsInPlace(cfg: any, proxyUrl: string, providerIds: readonly string[]): boolean;
|
|
274
|
+
|
|
275
|
+
export { DEFAULT_GATEWAY_PROVIDER_IDS, HeadroomContextEngine, ProxyManager, agentToOpenAI, applyGatewayProviderBaseUrls, applyGatewayProviderBaseUrlsInPlace, createHeadroomRetrieveTool, _default as default, defaultLogger, isLocalProxyUrl, normalizeAgentMessages, normalizeAndValidateProxyUrl, openAIToAgent, probeHeadroomProxy, registerHeadroomPlugin, resolveGatewayProviderIds };
|