billion-context 0.1.42 → 0.1.44

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 CHANGED
@@ -61,6 +61,24 @@ Three ways to use it — pick one:
61
61
  or when you want to pin an exact value. Routing is the same `/bili/` prefix
62
62
  either way — the config only changes which context window the proxy uses.
63
63
 
64
+ ### Agent plugin mode (内外呼应)
65
+
66
+ For a native-plugin experience, an agent can run a small cooperative plugin
67
+ alongside the proxy: the plugin registers the four ACP tools
68
+ (`compress` / `decompress` / `search_context` / `acp_status`) natively with
69
+ the agent and drives the agent's own tool loop, while the proxy stays the
70
+ compression authority (state, history folding, philosophy prompt, nudges).
71
+ Tool schemas are served by the proxy itself (`GET /__bili/plugin/manifest`),
72
+ so plugin and proxy can never drift. See [PLUGIN.md](PLUGIN.md) for the
73
+ protocol spec. Plugin-equipped sessions are detected automatically via
74
+ request headers — wire-level tool injection is then suppressed for them
75
+ (no double compression, native tool UX). Works in both proxy modes: the
76
+ `/bili/` prefix baseURL **and MITM transparent mode** — the launcher
77
+ (`bili pi` / `bili codex` / `bili claude`) exports `BILLION_CONTEXT_PROXY`
78
+ for plugins to detect; the plugin can also report the agent's own model
79
+ context window (`x-bili-plugin-context-window`) and read live context
80
+ usage via `GET /__bili/plugin/status`.
81
+
64
82
  Compression is injected automatically — you only configure routing, never
65
83
  compression itself.
66
84
 
@@ -83,6 +101,35 @@ bili test pi # quick end-to-end smoke test of the pi pa
83
101
  bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
84
102
  ```
85
103
 
104
+ **Plugin-in-launcher mode (#162)** — for `claude` and `codex` the launcher
105
+ additionally injects a single `bili` MCP server (`--mcp-config` for claude,
106
+ `-c mcp_servers.bili.*` for codex — both ephemeral, nothing written to host
107
+ config). The traffic route is **unchanged by default** — the transparent-
108
+ MITM proxy as before — so existing setups keep working exactly as they did
109
+ (OAuth-subscription traffic, custom relay endpoints). Opt in to **direct URL
110
+ routing** (`BILI_LAUNCHER_DIRECT=1`) to drop MITM/CA trust entirely (claude's
111
+ `ANTHROPIC_BASE_URL` / codex's provider `base_url` pointing at the `/bili/`
112
+ prefix); the launcher prints a warning when direct mode changes your traffic
113
+ route. The result is the native-plugin experience of [PLUGIN.md](PLUGIN.md)
114
+ with zero setup: the four ACP tools appear as native MCP tools, executed on
115
+ the proxy under the session lock, while the proxy keeps state, folding,
116
+ philosophy prompt and nudges. Session binding is automatic — claude passes
117
+ its session id to MCP children and on every request; codex spawns bind on
118
+ first sight. Plugin mode is opt-in while host-flag compatibility soaks: set
119
+ `BILI_LAUNCHER_PLUGIN=1` to enable the native MCP tools (verified with
120
+ claude 2.1.227 / codex 0.147.0; `BILI_LAUNCHER_PLUGIN=0` forces the plain
121
+ wire-injected launcher once the default flips on).
122
+ `BILI_LAUNCHER_DIRECT=1` is an opt-in, not an opt-out.
123
+
124
+ Mode matrix:
125
+
126
+ | Mode | Tools surface | Setup | When |
127
+ |------|--------------|-------|------|
128
+ | Launcher + MCP (`BILI_LAUNCHER_PLUGIN=1`) | native MCP tools | one env var | best UX; opt-in while soaking |
129
+ | Launcher wire mode (default for claude/codex) | proxy-injected wire tools | none — just `bili claude` / `bili codex` | default until plugin mode soaks |
130
+ | Manual plugin (pi etc.) | agent-side plugin | install plugin | hosts with plugin APIs |
131
+ | Manual baseURL | proxy-injected wire tools | edit client config | exotic hosts |
132
+
86
133
  How the client is pointed at the proxy (set automatically in the child env):
87
134
 
88
135
  | Client | Proxy redirect | CA trust env var |
@@ -91,6 +138,13 @@ How the client is pointed at the proxy (set automatically in the child env):
91
138
  | claude | `HTTPS_PROXY` | `NODE_EXTRA_CA_CERTS` |
92
139
  | codex | `HTTPS_PROXY` | `SSL_CERT_FILE` |
93
140
 
141
+ `NODE_EXTRA_CA_CERTS` *appends* to the built-in trust store, so it points at
142
+ the MITM root alone (`root-ca.pem`). `SSL_CERT_FILE` *replaces* the default
143
+ CA bundle, so for codex it points at `combined-ca.pem` — a bundle containing
144
+ the MITM root **plus** the system/Node public roots — keeping pip/git/curl
145
+ style TLS (blind-tunnelled, real certificates) working inside the child env
146
+ (#152).
147
+
94
148
  The real upstream HTTPS hosts are **discovered by reading** (never editing)
95
149
  the client's own config, so whatever you already have set up keeps working:
96
150
 
@@ -107,7 +161,8 @@ now auto-proxied too. Both schemes are covered with no config edits:
107
161
  - **HTTPS upstreams → cert MITM.** The MITM CA cert is the proxy's own root
108
162
  (`~/.local/share/billion-context/ca/root-ca.pem`, generated lazily); the
109
163
  client must trust it — pi/claude honor `NODE_EXTRA_CA_CERTS`, codex honors
110
- `SSL_CERT_FILE`. Compression is injected on the intercepted TLS stream.
164
+ `SSL_CERT_FILE` (which points at `combined-ca.pem`, see above). Compression
165
+ is injected on the intercepted TLS stream.
111
166
  - **HTTP upstreams → `/bili/` baseURL rewrite** (since plaintext can't be
112
167
  MITM'd). The launcher rewrites the client's base URL through the client's own
113
168
  mechanism, leaving its config files untouched: codex via `-c key=value` flags,
@@ -644,6 +699,49 @@ recommended** for many concurrent conversations because of the collision
644
699
  risk — until pi grows its own session-id signal. For pi multi-agent use,
645
700
  pass an explicit `x-acp-session` header per conversation to avoid collisions.
646
701
 
702
+ ### Codex subagents get their own compression namespace (#150)
703
+
704
+ Codex subagents (e.g. the `guardian_subagent` approval reviewer) reuse the
705
+ main conversation's `session_id`, so on the wire they look like the same
706
+ session. Without care their requests inherit the main conversation's
707
+ compression state — a subagent turn can get its context folded (losing the
708
+ verbatim user authorization it must read back) and the two roles' usage
709
+ estimates pollute each other.
710
+
711
+ billion-context detects this via the `instructions` field: subagent requests
712
+ carry their own role prompt. The **first** instructions seen for a
713
+ conversation anchor the main namespace (stable even if the main prompt
714
+ drifts); any other instructions value maps to a separate `|sub:` namespace
715
+ with its own empty compression state. Subagent requests are self-contained
716
+ replays, so the fresh namespace is lossless — and the web UI's session list
717
+ shows the two namespaces as separate sessions sharing the same client label.
718
+
719
+ ### Sessions depend on the proxy (#151)
720
+
721
+ Compression state (blocks, summaries, original message cache) lives **in the
722
+ proxy**, not in the client. The client's own local history is the full
723
+ uncompressed view. Two consequences:
724
+
725
+ - If you point the client back at the real upstream (or stop the proxy), the
726
+ client replays its **full local history** every turn. After a long
727
+ compressed session this can exceed the model's context window
728
+ (`context_window_exceeded`).
729
+ - There is no way to "unpack" a compression block into the client's local
730
+ history — the client never saw the compressed form.
731
+
732
+ **Migrating off the proxy:** export the session and paste it into a fresh
733
+ conversation as a handoff:
734
+
735
+ ```bash
736
+ bili export # list persisted sessions (id, label, blocks)
737
+ bili export <id|label> # print a Markdown handoff (block summaries)
738
+ bili export <id> --full # include the original messages per block
739
+ bili export <id> --full --output handoff.md
740
+ ```
741
+
742
+ Then start a new conversation in the client (direct to upstream) and paste
743
+ the handoff doc as the opening context.
744
+
647
745
  ## Status
648
746
 
649
747
  Early. Protocol handling and compression work against mock tests (146 passing). Real-model integration testing is the next milestone. Expect rough edges.
package/README.zh-CN.md CHANGED
@@ -47,6 +47,21 @@ npm install -g billion-context
47
47
  - **零配置(最简单):** 在客户端 baseURL 前面加上代理地址 + `/bili/`。无需配置文件 —— context 窗口自动从 [models.dev](https://models.dev) registry 查询。`/bili/` 前缀还是个自检测信号:billion-context 的客户端扩展(billion-context-pi / opencode-acp)能在自己的 baseUrl 里认出它并自禁用,避免双层压缩。
48
48
  - **显式 context 窗口覆盖:** 在配置文件(或网页)里按 URL 声明 context 窗口,用于 registry 不认识的端点,或想钉死一个精确值的场景。两种方式路由都是同一个 `/bili/` 前缀 —— 配置只改变代理用哪个 context 窗口。
49
49
 
50
+ ### Agent 插件模式(内外呼应)
51
+
52
+ 想要原生插件体验,可以在 agent 内部装一个配合代理的插件:插件把四个
53
+ ACP 工具(`compress` / `decompress` / `search_context` / `acp_status`)
54
+ 原生注册进 agent、由 agent 自己的工具循环驱动,而代理仍然是压缩引擎
55
+ (状态、历史折叠、压缩哲学 prompt、nudge 全归代理)。工具 schema 由
56
+ 代理统一下发(`GET /__bili/plugin/manifest`),插件与代理永远不会版本
57
+ 漂移。协议规范见 [PLUGIN.md](PLUGIN.md)。带插件的会话通过请求头自动
58
+ 识别 —— 该会话的 wire 层工具注入自动关闭(不会双重压缩,工具体验原生)。
59
+ 两种代理模式都支持:`/bili/` 前缀 baseURL **和 MITM 透明模式** ——
60
+ launcher(`bili pi` / `bili codex` / `bili claude`)会导出
61
+ `BILLION_CONTEXT_PROXY` 供插件检测;插件还可以上报 agent 自己的模型
62
+ 上下文窗口(`x-bili-plugin-context-window`),并通过
63
+ `GET /__bili/plugin/status` 读取实时上下文水位。
64
+
50
65
  压缩是自动注入的 —— 你只需配置路由,无需配置压缩本身。
51
66
 
52
67
  ### 方式 A —— 零配置(`/bili/` 前缀)