billion-context 0.1.50 → 0.1.51-pr.234.76
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 +9 -226
- package/README.zh-CN.md +1 -5
- package/dist/index.js +506 -87
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,78 +44,12 @@ This installs the `bili` command (`bili-proxy` is kept as an alias).
|
|
|
44
44
|
|
|
45
45
|
Two ways to use it — pick one:
|
|
46
46
|
|
|
47
|
-
- **Launcher (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(whitelisted for TLS interception), HTTP upstreams via a `/bili/` baseURL
|
|
52
|
-
rewrite (cert MITM can't intercept plaintext). See **Option 0** below.
|
|
53
|
-
- **Zero-config (simplest):** prefix your client's baseURL with the proxy
|
|
54
|
-
origin + `/bili/`. No config file needed — context windows are auto-detected
|
|
55
|
-
from the [models.dev](https://models.dev) registry. The `/bili/` prefix also
|
|
56
|
-
doubles as a self-detection signal: billion-context client extensions
|
|
57
|
-
(billion-context-pi / opencode-acp) can recognize it in their own baseUrl
|
|
58
|
-
and self-disable, so you never get double compression.
|
|
59
|
-
|
|
60
|
-
### Agent plugin mode (inside-out)
|
|
61
|
-
|
|
62
|
-
For a native-plugin experience, an agent can run a small cooperative plugin
|
|
63
|
-
alongside the proxy: the plugin registers the four ACP tools
|
|
64
|
-
(`compress` / `decompress` / `search_context` / `acp_status`) natively with
|
|
65
|
-
the agent and drives the agent's own tool loop, while the proxy stays the
|
|
66
|
-
compression authority (state, history folding, philosophy prompt, nudges).
|
|
67
|
-
Tool schemas are served by the proxy itself (`GET /__bili/plugin/manifest`),
|
|
68
|
-
so plugin and proxy can never drift. See [PLUGIN.md](PLUGIN.md) for the
|
|
69
|
-
protocol spec. Plugin-equipped sessions are detected automatically via
|
|
70
|
-
request headers — wire-level tool injection is then suppressed for them
|
|
71
|
-
(no double compression, native tool UX). Works in both proxy modes: the
|
|
72
|
-
`/bili/` prefix baseURL **and MITM transparent mode** — the launcher
|
|
73
|
-
(`bili pi` / `bili codex` / `bili claude`) exports `BILLION_CONTEXT_PROXY`
|
|
74
|
-
for plugins to detect; the plugin can also report the agent's own model
|
|
75
|
-
context window (`x-bili-plugin-context-window`) and read live context
|
|
76
|
-
usage via `GET /__bili/plugin/status`.
|
|
77
|
-
|
|
78
|
-
Compression is injected automatically — you only configure routing, never
|
|
79
|
-
compression itself.
|
|
80
|
-
|
|
81
|
-
Installing a plugin is **optional** — without one, every client (hermes
|
|
82
|
-
included) still gets the four tools wire-injected by the proxy; installing
|
|
83
|
-
only upgrades them to native agent tools. The plugins ship **inside
|
|
84
|
-
billion-context itself** — no separate package: pi and omp get native agent
|
|
85
|
-
plugins (`dist/agent/*.js`), claude, codex and opencode get the MCP bridge
|
|
86
|
-
(`dist/mcp.js`, same protocol underneath). hermes has no plugin API — it
|
|
87
|
-
always rides the wire-injected tools.
|
|
88
|
-
|
|
89
|
-
What each host gets from a plugin: **pi / omp / opencode** register the four
|
|
90
|
-
tools natively **and** add an `/acp` status command; **claude / codex** (MCP
|
|
91
|
-
bridge) get the four tools as native MCP tools but no `/acp` slash command
|
|
92
|
-
(the MCP protocol has none). Without a plugin the compression is identical —
|
|
93
|
-
the client UI just never lists the tools; ask the model to run `acp_status`
|
|
94
|
-
if you want the status panel rendered in chat.
|
|
47
|
+
- **Launcher (easiest):** one `bili <client>` command brings up the proxy and
|
|
48
|
+
the client together — no real config file is ever touched.
|
|
49
|
+
- **URL change (persistent):** prefix your client's baseURL with the proxy
|
|
50
|
+
origin + `/bili/`.
|
|
95
51
|
|
|
96
|
-
|
|
97
|
-
bili plugin install pi # needed: pi's native tools + /acp come ONLY from install (the launcher never injects MCP for pi)
|
|
98
|
-
bili plugin list # install status for every supported host
|
|
99
|
-
bili plugin remove pi # undo (original files backed up to *.bili-bak once)
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Every other host skips install: omp ships with the plugin built in, opencode
|
|
103
|
-
is injected automatically by `bili opencode`, claude/codex can set
|
|
104
|
-
`BILI_LAUNCHER_PLUGIN=1` with the launcher (or `plugin install` for a
|
|
105
|
-
persistent MCP registration), and hermes has no plugin API at all.
|
|
106
|
-
|
|
107
|
-
The installed plugin is a **thin** one (~5 KB, zero runtime deps): it just
|
|
108
|
-
detects the proxy (from the `/bili/` baseURL or `BILLION_CONTEXT_PROXY`),
|
|
109
|
-
fetches tool schemas from the proxy, registers native tools, and forwards
|
|
110
|
-
executions — the proxy remains the single compression authority, so plugin
|
|
111
|
-
and proxy always match versions. Killing it entirely: `BILLION_CONTEXT_PLUGIN=0`.
|
|
112
|
-
|
|
113
|
-
Via the launcher you never need `plugin install`: `bili opencode` injects
|
|
114
|
-
its plugin automatically (temp `OPENCODE_CONFIG`), claude/codex get the
|
|
115
|
-
MCP shell with `BILI_LAUNCHER_PLUGIN=1`, and pi/omp/hermes ride the
|
|
116
|
-
wire-injected tools.
|
|
117
|
-
|
|
118
|
-
### Option 0 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes`)
|
|
52
|
+
### Option 1 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes`)
|
|
119
53
|
|
|
120
54
|
The launcher wraps a client in one command: it starts a proxy on an
|
|
121
55
|
independent port (a fresh instance is always spawned — a port is never
|
|
@@ -128,123 +62,15 @@ and blind-tunnel everything else.
|
|
|
128
62
|
|
|
129
63
|
```bash
|
|
130
64
|
bili pi # launch pi through the proxy
|
|
131
|
-
bili pi -- print "hi" # args after the client are passed through
|
|
132
|
-
bili pi-test # clean pi (extensions off) — proxy owns compression, no double-compress
|
|
133
65
|
bili codex # launch codex through the proxy
|
|
134
66
|
bili claude # launch claude through the proxy
|
|
135
|
-
bili omp # pi-style: MITM env +
|
|
67
|
+
bili omp # pi-style: MITM env + persistent overlay home (~/.omp/agent-bili, real config untouched)
|
|
136
68
|
bili opencode # MITM for HTTPS + temp opencode.json (/bili/ for HTTP) + thin /acp plugin
|
|
137
|
-
bili hermes # no MITM possible (certifi CA) —
|
|
138
|
-
bili test pi # quick end-to-end smoke test of the pi path
|
|
69
|
+
bili hermes # no MITM possible (certifi CA) — persistent overlay home (~/.hermes-bili), all traffic /bili/
|
|
139
70
|
bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
|
|
140
71
|
```
|
|
141
72
|
|
|
142
|
-
|
|
143
|
-
additionally injects a single `bili` MCP server (`--mcp-config` for claude,
|
|
144
|
-
`-c mcp_servers.bili.*` for codex — both ephemeral, nothing written to host
|
|
145
|
-
config). The traffic route is **unchanged by default** — the transparent-
|
|
146
|
-
MITM proxy as before — so existing setups keep working exactly as they did
|
|
147
|
-
(OAuth-subscription traffic, custom relay endpoints). Opt in to **direct URL
|
|
148
|
-
routing** (`BILI_LAUNCHER_DIRECT=1`) to drop MITM/CA trust entirely (claude's
|
|
149
|
-
`ANTHROPIC_BASE_URL` / codex's provider `base_url` pointing at the `/bili/`
|
|
150
|
-
prefix); the launcher prints a warning when direct mode changes your traffic
|
|
151
|
-
route. The result is the native-plugin experience of [PLUGIN.md](PLUGIN.md)
|
|
152
|
-
with zero setup: the four ACP tools appear as native MCP tools, executed on
|
|
153
|
-
the proxy under the session lock, while the proxy keeps state, folding,
|
|
154
|
-
philosophy prompt and nudges. Session binding is automatic — claude passes
|
|
155
|
-
its session id to MCP children and on every request; codex spawns bind on
|
|
156
|
-
first sight. Plugin mode is opt-in while host-flag compatibility soaks: set
|
|
157
|
-
`BILI_LAUNCHER_PLUGIN=1` to enable the native MCP tools (verified with
|
|
158
|
-
claude 2.1.227 / codex 0.147.0; `BILI_LAUNCHER_PLUGIN=0` forces the plain
|
|
159
|
-
wire-injected launcher once the default flips on).
|
|
160
|
-
`BILI_LAUNCHER_DIRECT=1` is an opt-in, not an opt-out.
|
|
161
|
-
|
|
162
|
-
Mode matrix:
|
|
163
|
-
|
|
164
|
-
| Mode | Tools surface | Setup | When |
|
|
165
|
-
|------|--------------|-------|------|
|
|
166
|
-
| Launcher + MCP (`BILI_LAUNCHER_PLUGIN=1`) | native MCP tools | one env var | best UX; opt-in while soaking |
|
|
167
|
-
| Launcher wire mode (default for claude/codex) | proxy-injected wire tools | none — just `bili claude` / `bili codex` | default until plugin mode soaks |
|
|
168
|
-
| Manual plugin (pi etc.) | agent-side plugin | install plugin | hosts with plugin APIs |
|
|
169
|
-
| Manual baseURL | proxy-injected wire tools | edit client config | exotic hosts |
|
|
170
|
-
|
|
171
|
-
How the client is pointed at the proxy (set automatically in the child env):
|
|
172
|
-
|
|
173
|
-
| Client | Proxy redirect | CA trust env var |
|
|
174
|
-
|-------------|---------------------|-------------------------|
|
|
175
|
-
| pi | `HTTPS_PROXY` | `NODE_EXTRA_CA_CERTS` |
|
|
176
|
-
| claude | `HTTPS_PROXY` (undici ignores it → `ANTHROPIC_BASE_URL` `/bili/` ride-along) | `NODE_EXTRA_CA_CERTS` |
|
|
177
|
-
| codex | `HTTPS_PROXY` | `SSL_CERT_FILE` |
|
|
178
|
-
| omp | `HTTPS_PROXY` | `NODE_EXTRA_CA_CERTS` |
|
|
179
|
-
| opencode | `HTTPS_PROXY` | `NODE_EXTRA_CA_CERTS` |
|
|
180
|
-
| hermes | `HERMES_HOME` (temp `config.yaml`, every upstream `/bili/`) | — (no MITM: httpx builds its own CA bundle) |
|
|
181
|
-
|
|
182
|
-
`NODE_EXTRA_CA_CERTS` *appends* to the built-in trust store, so it points at
|
|
183
|
-
the MITM root alone (`root-ca.pem`). `SSL_CERT_FILE` *replaces* the default
|
|
184
|
-
CA bundle, so for codex it points at `combined-ca.pem` — a bundle containing
|
|
185
|
-
the MITM root **plus** the system/Node public roots — keeping pip/git/curl
|
|
186
|
-
style TLS (blind-tunnelled, real certificates) working inside the child env
|
|
187
|
-
(#152).
|
|
188
|
-
|
|
189
|
-
The real upstream HTTPS hosts are **discovered by reading** (never editing)
|
|
190
|
-
the client's own config, so whatever you already have set up keeps working:
|
|
191
|
-
|
|
192
|
-
| Client | Read from |
|
|
193
|
-
|-------------|----------------------------------------------|
|
|
194
|
-
| Pi | `~/.pi/agent/models.json` — each provider's `baseUrl` |
|
|
195
|
-
| Codex | `~/.codex/config.toml` — each `[model_providers.<name>]` `base_url` (+ top-level `openai_base_url`) |
|
|
196
|
-
| Claude Code | hardcoded `api.anthropic.com` (no per-config upstream) |
|
|
197
|
-
| omp | `~/.omp/agent/models.yml` — each provider's `baseUrl` |
|
|
198
|
-
| opencode | `~/.config/opencode/opencode.json` — each provider's `options.baseURL` |
|
|
199
|
-
| hermes | `~/.hermes/config.yaml` — each provider's `api:`/`base_url:` endpoint |
|
|
200
|
-
|
|
201
|
-
Only **HTTPS** hosts are MITM'd (a self-signed CA can't intercept plaintext
|
|
202
|
-
anyway); HTTP / `localhost` / `127.0.0.1` providers used to go direct, but are
|
|
203
|
-
now auto-proxied too. Both schemes are covered with no config edits:
|
|
204
|
-
|
|
205
|
-
- **HTTPS upstreams → cert MITM.** The MITM CA cert is the proxy's own root
|
|
206
|
-
(`~/.local/share/billion-context/ca/root-ca.pem`, generated lazily); the
|
|
207
|
-
client must trust it — pi/claude honor `NODE_EXTRA_CA_CERTS`, codex honors
|
|
208
|
-
`SSL_CERT_FILE` (which points at `combined-ca.pem`, see above). Compression
|
|
209
|
-
is injected on the intercepted TLS stream.
|
|
210
|
-
- **HTTP upstreams → `/bili/` baseURL rewrite** (since plaintext can't be
|
|
211
|
-
MITM'd). The launcher rewrites the client's base URL through the client's own
|
|
212
|
-
mechanism, leaving its config files untouched: codex via `-c key=value` flags,
|
|
213
|
-
claude via the `ANTHROPIC_BASE_URL` env var, pi via an isolated
|
|
214
|
-
`PI_CODING_AGENT_DIR` pointing at a temp copy of the pi home with a rewritten
|
|
215
|
-
`models.json` (`auth.json` and the rest are symlinked through unchanged; the
|
|
216
|
-
temp dir is removed when the client exits).
|
|
217
|
-
|
|
218
|
-
`--mitm-domain <domain>` (repeatable) adds extra domains to the whitelist
|
|
219
|
-
beyond what auto-discovery finds — useful for hosts the client fetches at
|
|
220
|
-
runtime rather than from its config file. The proxy port defaults to `8787`;
|
|
221
|
-
if it's taken, a free port is chosen automatically. Use `--passthrough` /
|
|
222
|
-
`--debug` / `--no-auto-update` just like plain `bili`.
|
|
223
|
-
|
|
224
|
-
For clients whose config can't be pointed at the proxy through env vars, the
|
|
225
|
-
launcher writes an **isolated temp copy** of the client config with the
|
|
226
|
-
discovered upstreams rewritten and points the client at it — the real config
|
|
227
|
-
is never touched, and the temp dir is removed when the client exits:
|
|
228
|
-
|
|
229
|
-
- **pi / omp** — an isolated `PI_CODING_AGENT_DIR` whose `models.json` /
|
|
230
|
-
`models.yml` rewrites HTTP upstreams to the `/bili/` form (HTTPS upstreams
|
|
231
|
-
ride cert-MITM; everything else in the real home is symlinked through).
|
|
232
|
-
- **opencode** — `OPENCODE_CONFIG` pointing at a full copy of `opencode.json`
|
|
233
|
-
with HTTP upstreams `/bili/`-rewritten **and** the thin `bili` `/acp`
|
|
234
|
-
status plugin appended to `plugin` (`BILLION_CONTEXT_PROXY` makes a host
|
|
235
|
-
opencode-acp plugin self-disable so the proxy owns the ACP tools).
|
|
236
|
-
- **hermes** — cert MITM is impossible (httpx builds its own CA bundle from
|
|
237
|
-
certifi and ignores `SSL_CERT_FILE`), so **every** upstream is rewritten to
|
|
238
|
-
the `/bili/` form in an isolated `HERMES_HOME` (`config.yaml` copy;
|
|
239
|
-
skills/memories/sessions stay shared via symlinks). No plugin — hermes has
|
|
240
|
-
no plugin API; wire-injected tools ride the proxied stream.
|
|
241
|
-
|
|
242
|
-
> **Note:** the launcher ties the proxy's lifetime to the client — when the
|
|
243
|
-
> client exits, the proxy it started is stopped. Each `bili <client>` spawns
|
|
244
|
-
> its own fresh proxy instance; an independently started `bili` on the same
|
|
245
|
-
> port is never reused.
|
|
246
|
-
|
|
247
|
-
### Option A — Zero-config (`/bili/` prefix)
|
|
73
|
+
### Option 2 — URL change (`/bili/` prefix)
|
|
248
74
|
|
|
249
75
|
Start the proxy:
|
|
250
76
|
|
|
@@ -445,52 +271,9 @@ recommended** for many concurrent conversations because of the collision
|
|
|
445
271
|
risk — until pi grows its own session-id signal. For pi multi-agent use,
|
|
446
272
|
pass an explicit `x-acp-session` header per conversation to avoid collisions.
|
|
447
273
|
|
|
448
|
-
### Codex subagents get their own compression namespace (#150)
|
|
449
|
-
|
|
450
|
-
Codex subagents (e.g. the `guardian_subagent` approval reviewer) reuse the
|
|
451
|
-
main conversation's `session_id`, so on the wire they look like the same
|
|
452
|
-
session. Without care their requests inherit the main conversation's
|
|
453
|
-
compression state — a subagent turn can get its context folded (losing the
|
|
454
|
-
verbatim user authorization it must read back) and the two roles' usage
|
|
455
|
-
estimates pollute each other.
|
|
456
|
-
|
|
457
|
-
billion-context detects this via the `instructions` field: subagent requests
|
|
458
|
-
carry their own role prompt. The **first** instructions seen for a
|
|
459
|
-
conversation anchor the main namespace (stable even if the main prompt
|
|
460
|
-
drifts); any other instructions value maps to a separate `|sub:` namespace
|
|
461
|
-
with its own empty compression state. Subagent requests are self-contained
|
|
462
|
-
replays, so the fresh namespace is lossless — and the web UI's session list
|
|
463
|
-
shows the two namespaces as separate sessions sharing the same client label.
|
|
464
|
-
|
|
465
|
-
### Sessions depend on the proxy (#151)
|
|
466
|
-
|
|
467
|
-
Compression state (blocks, summaries, original message cache) lives **in the
|
|
468
|
-
proxy**, not in the client. The client's own local history is the full
|
|
469
|
-
uncompressed view. Two consequences:
|
|
470
|
-
|
|
471
|
-
- If you point the client back at the real upstream (or stop the proxy), the
|
|
472
|
-
client replays its **full local history** every turn. After a long
|
|
473
|
-
compressed session this can exceed the model's context window
|
|
474
|
-
(`context_window_exceeded`).
|
|
475
|
-
- There is no way to "unpack" a compression block into the client's local
|
|
476
|
-
history — the client never saw the compressed form.
|
|
477
|
-
|
|
478
|
-
**Migrating off the proxy:** export the session and paste it into a fresh
|
|
479
|
-
conversation as a handoff:
|
|
480
|
-
|
|
481
|
-
```bash
|
|
482
|
-
bili export # list persisted sessions (id, label, blocks)
|
|
483
|
-
bili export <id|label> # print a Markdown handoff (block summaries)
|
|
484
|
-
bili export <id> --full # include the original messages per block
|
|
485
|
-
bili export <id> --full --output handoff.md
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
Then start a new conversation in the client (direct to upstream) and paste
|
|
489
|
-
the handoff doc as the opening context.
|
|
490
|
-
|
|
491
274
|
## Status
|
|
492
275
|
|
|
493
|
-
Early. Protocol handling and compression work against mock tests (
|
|
276
|
+
Early. Protocol handling and compression work against mock tests (500+ passing). Real-model integration testing is the next milestone. Expect rough edges.
|
|
494
277
|
|
|
495
278
|
See [billion-context-pi](https://github.com/ranxianglei/billion-context-pi) for the pi-extension mode (in-process, tighter integration, the reference implementation).
|
|
496
279
|
|
package/README.zh-CN.md
CHANGED
|
@@ -62,10 +62,6 @@ bili opencode # HTTPS 走 MITM + 临时 opencode.json(HT
|
|
|
62
62
|
bili hermes # 无法 MITM(certifi CA)—— 隔离 HERMES_HOME,全部流量 /bili/
|
|
63
63
|
bili pi --mitm-domain api.foo.com # 向 MITM 白名单追加域名
|
|
64
64
|
```
|
|
65
|
-
注意,以下客户端需要执行`bili plugin install`以获得原生体验
|
|
66
|
-
```bash
|
|
67
|
-
bili plugin install pi # 必需: launcher 对 pi/omp 不注入 MCP,install 是原生工具 + /acp 的唯一途径
|
|
68
|
-
```
|
|
69
65
|
|
|
70
66
|
|
|
71
67
|
### 方式 2 —— 改url(`/bili/` 前缀)
|
|
@@ -226,7 +222,7 @@ Windows 下会自动发现常见 Clash/Mihomo 静态系统代理;Web UI 会显
|
|
|
226
222
|
|
|
227
223
|
## 状态
|
|
228
224
|
|
|
229
|
-
早期。协议处理和压缩已通过 mock 测试(
|
|
225
|
+
早期。协议处理和压缩已通过 mock 测试(500+ 项通过)。真实模型集成测试是下一里程碑。预期会有粗糙的地方。
|
|
230
226
|
|
|
231
227
|
pi 扩展模式(进程内、更紧密集成、参考实现)见 [billion-context-pi](https://github.com/ranxianglei/billion-context-pi)。
|
|
232
228
|
|