Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ Environment variables take precedence over the config file. They are useful for
| `BILI_CCR_RETRIEVAL_TTL_MS` | Expiry (ms) for a queued-but-undelivered `acp_retrieve` injection (#1343): if the full text stays queued this long without ever riding an upstream request, it is dropped **loudly** — warn log with refs + reason, `stats.retrieveDropped` bump, and a corrective note on the next request telling the model to re-issue `acp_retrieve`. Default `600000` (10 min); `0` disables expiry. Plugin-lane queue items only; range-restore riders (#1207) are exempt. |
| `BILI_IMAGE_TOKEN_CAP` | Cap the per-image token estimate used by the preflight size gate, output clamp, and image-compression stats (#488/#496/#1843). Applied on top of whatever billing mode resolved — a blanket ceiling for routes whose real encoder bills below even the pixel prior. Wins over both config levels ([`imageTokenCap`](#imagetokencap)); live-read per request (no restart). Unset = fall back to config (`providers.<url>.imageTokenCap`, then global), default no cap. |
| `BILI_IMAGE_BILLING` | Override the image billing mode used by the preflight size gate and output clamp (#767/#1843): `pixels` or `bytes`. Live-read per request (no restart); beats the global `imageBilling` and every per-provider `providers.<url>.imageBilling`. Since #1843 the default resolves to `pixels` for every host, so use `bytes` to force conservative byte billing process-wide (e.g. a byte-counting relay) — the per-route setting remains the narrower tool. See [`imageBilling`](#imagebilling). |
| `BILI_PI_INPROC` | pi in-process entry kill-switch (#1988). Default: **on** — the `npm:billion-context` pi extension runs the bundled in-process compression engine (`dist/agent/pi-inprocess.js`, no local server; model traffic goes direct to your upstream). Set to `0` (also accepts `false`/`off`/`no`) to delegate to the server-based native instead (self-spawned proxy + fetch-layer rewrite, `dist/agent/pi-native.js`) — read once at extension load, restart pi after changing it. The two postures are never both active, and both stand down automatically when a bili proxy already owns the traffic (`BILLION_CONTEXT_PROXY`, `/bili/` baseUrl, or a foreign `BILLION_CONTEXT_NATIVE` marker). |
| `BILI_PREFLIGHT_HOLD_MS` | Grace period (ms) before a long preflight compression starts holding the client with keep-alive bytes (default `30000`; see #568). |
| `BILI_STREAM_KEEPALIVE_MS` | Streaming-phase client hold (#1647): when an SSE response has written zero bytes to the client for this many milliseconds, bili emits one SSE comment line (`: bili-keepalive`, a spec-level no-op) so the client's undici `bodyTimeout` (default 300s; Node built-in fetch cannot override it per request) cannot kill long prefills whose upstream pings the rewriter/strip pipes swallow. Default `15000`; `0` disables. Sibling of `BILI_PREFLIGHT_HOLD_MS`, which covers compression-preflight silence — this covers upstream-caused silence during streaming. |
| `BILI_RECLAIM_FETCH_PATCH` | Set to `0` to disable the native-mode fetch self-heal re-arm (#1158). By default the native fetch intercept installs `globalThis.fetch` as a guarded accessor, so a third-party patch that re-installs `globalThis.fetch` (e.g. dsh-http-proxy's settings refresh writing its frozen pre-bili `originalFetch`) is re-chained as the downstream and model traffic keeps routing through bili. With `0` the classic direct install stays: a third-party re-arm then wins and bili stops seeing model traffic for the session. **Egress note:** while the guard holds, claimed model traffic is dispatched by the bili proxy itself — it no longer rides the third-party chain's egress (e.g. a SOCKS5 proxy configured in dsh-http-proxy; bili's own upstream proxying supports HTTP proxies only). If you need the third-party egress back, set `0` and configure the egress at bili's level (`"proxy": "http://…"`). |
Expand Down
1 change: 1 addition & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@
| `BILLION_CONTEXT_NODE` | 非 Node 宿主进程拉起代理时显式指定的 Node 可执行文件路径(#819/#1429)。宿主自身不是 Node 时的解析顺序:本覆盖项 → PATH 搜索 + GUI PATH 会遗漏的众所周知安装位置(`/opt/homebrew/bin`、`/usr/local/bin`、Volta 等)→ Electron 宿主自身二进制以纯 Node 运行(`ELECTRON_RUN_AS_NODE=1`,最后手段 —— 因此 deepseek-harness desktop 这类桌面应用零配置即可用)。用于强制指定某个 Node(如比宿主捆绑运行时更新的版本);始终优先于上述回退。 |
| `BILI_IMAGE_TOKEN_CAP` | 预检尺寸门、输出钳制与图片压缩统计所用单图 token 估算的统一天花板(#488/#496/#1843)。叠加在任何计费模式之上 —— 适用于路由真实编码器计费低于像素先验的场景。优先于两级配置([`imageTokenCap`](#imagetokencap));每次请求实时读取(无需重启)。不设置 = 回退到配置(`providers.<url>.imageTokenCap`,再全局),默认无上限。 |
| `BILI_IMAGE_BILLING` | 覆盖预检尺寸门与输出钳制的图片计费模式(#767/#1843):`pixels` 或 `bytes`。每次请求实时读取(无需重启);优先于全局 `imageBilling` 与所有按 provider 的 `providers.<url>.imageBilling`。自 #1843 起默认对所有 host 解析为 `pixels`,故用 `bytes` 全进程强制保守字节计费(例如字节计数 relay)—— 更窄的场景仍用按路由设置。详见 [`imageBilling`](#imagebilling)。 |
| `BILI_PI_INPROC` | pi 进程内入口开关(#1988)。默认**开** —— `npm:billion-context` 的 pi 扩展运行内置进程内压缩引擎(`dist/agent/pi-inprocess.js`,无本地 server;模型流量直连上游)。设为 `0`(也接受 `false`/`off`/`no`)则改为委托给 server 版原生(自拉起代理 + fetch 层改写,`dist/agent/pi-native.js`)——扩展加载时读一次,改完需重启 pi。两种姿态永远不会同时生效,且当 bili 代理已接管流量时(`BILLION_CONTEXT_PROXY`、`/bili/` baseUrl 或外来的 `BILLION_CONTEXT_NATIVE` 标记)两者都会自动退出。 |
| `BILI_PREFLIGHT_HOLD_MS` | 预压缩超过该宽限期(毫秒)后,代理提前提交响应并用保活字节挂住客户端(默认 `30000`;见 #568)。 |
| `BILI_STREAM_KEEPALIVE_MS` | 流式阶段客户端保活(#1647):SSE 响应连续该毫秒数没有向客户端写出任何字节时,bili 发一条 SSE 注释行(`: bili-keepalive`,协议层 no-op),防止客户端 undici `bodyTimeout`(默认 300s;Node 内置 fetch 无法按请求覆盖)在长 prefill 时断连——上游的 ping 注释会被重写器/剥离管道吞掉。默认 `15000`;`0` 关闭。与 `BILI_PREFLIGHT_HOLD_MS` 互补:后者覆盖压缩预检期的静默,本变量覆盖流式期上游导致的静默。 |
| `BILI_RECLAIM_FETCH_PATCH` | 设为 `0` 关闭 native 模式 fetch 自愈重武装(#1158)。默认情况下 native fetch 拦截会把 `globalThis.fetch` 装成受保护的访问器:第三方补丁重新赋值 `globalThis.fetch` 时(如 dsh-http-proxy 的 settings 刷新用冻结的 pre-bili `originalFetch` 盲覆盖),会被接链为下游,模型流量继续经过 bili。设 `0` 则回到经典直装:第三方重装生效,bili 将看不到本会话的模型流量。**出口提示:** 自愈生效期间,被认领的模型流量由 bili 代理自身派发——不再走第三方链的出口(例如 dsh-http-proxy 里配置的 SOCKS5;bili 自身的上游代理仅支持 HTTP 形式)。若需要回退第三方出口,设 `0` 并在 bili 层配置出口(`"proxy": "http://…"`)。 |
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Pick by your client:

| Client | Use |
|---|---|
| **pi** | [`billion-context`](https://github.com/ranxianglei/billion-context) — `bili pi` (launcher) or `bili plugin install pi` (native); standalone [`billion-context-pi`](https://github.com/ranxianglei/billion-context-pi) remains usable |
| **pi** | [`billion-context`](https://github.com/ranxianglei/billion-context) — `bili pi` (launcher) or `npm:billion-context` (in-process extension, no local server; model traffic goes direct to your upstream). `BILI_PI_INPROC=0` falls back to the server-based native (self-spawned proxy); standalone [`billion-context-pi`](https://github.com/ranxianglei/billion-context-pi) is deprecated (#1988) |
| **opencode** (1.x / 2.x) | [`billion-context`](https://github.com/ranxianglei/billion-context) — `bili opencode` (launcher) or `bili plugin install opencode` (native); standalone [`opencode-acp`](https://github.com/ranxianglei/opencode-acp) remains usable on 1.x — full guide: [OpenCode](CLIENTS.md#opencode) |
| **omp** | [`billion-context`](https://github.com/ranxianglei/billion-context) via `bili omp` (built-in plugin) or `bili plugin install omp` (self-spawning native plugin, no launcher) |
| **dsh** | `bili dsh` (launcher — full native plugin via `--patch`) or `bili plugin install dsh` ≡ `dsh plugin --profile <name> add billion-context` (one unified lane) — details: [CLIENTS.md](CLIENTS.md) |
Expand All @@ -123,7 +123,7 @@ Pick by your client:
| **goose** (Goose CLI) | `bili goose` (launcher) — rustls trusts no CA file, so no cert-MITM: openai/anthropic legs via `OPENAI_HOST`/`ANTHROPIC_HOST`, custom providers via a regenerated `GOOSE_PATH_ROOT` overlay (#1049) |
| **everything else** (no context hook) | [`billion-context`](https://github.com/ranxianglei/billion-context) — `bili <client>` (launcher, preferred) or `/bili/` prefix |

**Native mode vs standalone extensions.** The host-native plugins (`bili plugin install …`) and the standalone in-process extensions (`billion-context-pi`, `opencode-acp`) are **mutually exclusive** — both active means double compression. The installer makes the switch: it replaces the legacy entries (bare name, `npm:` alias, versioned, path form; array or object shape) and snapshots the original config to `.bili-bak` once; a **project-local** install is not touched — remove that one by hand. As a runtime safety net for manual installs, the native entries set `BILLION_CONTEXT_NATIVE=<host>` synchronously at load so a standalone extension can stand down at action time. On the pi side the marker needs `billion-context-pi` **0.1.72+**, and the pi-native entry scans both pi settings files once its proxy is up and warns loudly when it spots a co-resident legacy entry the installer never saw — that warning is the only visible signal while an old `billion-context-pi` silently double-compresses.
**Native mode vs standalone extensions.** The host-native plugins (`bili plugin install …`) and the standalone in-process extensions (`opencode-acp`, legacy `billion-context-pi`) are **mutually exclusive** — both active means double compression. The installer makes the switch: it replaces the legacy entries (bare name, `npm:` alias, versioned, path form; array or object shape) and snapshots the original config to `.bili-bak` once; a **project-local** install is not touched — remove that one by hand. As a runtime safety net for manual installs, the native entries set `BILLION_CONTEXT_NATIVE=<host>` synchronously at load so a standalone extension can stand down at action time. For pi this is now mostly history: since #1988 the default pi lane IS billion-context's own in-process entry (`dist/agent/pi-inprocess.js`, no server), and the standalone `billion-context-pi` package is deprecated pending retirement — its state files (`.acp.json` sidecars) are read as-is by the new entry, and builds ≥ 0.1.72 stand down automatically on our marker. Older builds predate the marker, so BOTH pi entries scan the global + project pi settings files and warn loudly when they spot a co-resident legacy `billion-context-pi` — that warning, not silence, is what you get if one lingers.


## Install
Expand Down Expand Up @@ -199,7 +199,7 @@ install <client>` writes their config entries for you (kimi's declarative

Notes:

- Native mode is **mutually exclusive** with the standalone in-process extensions (`billion-context-pi`, `opencode-acp`) — the installer swaps the entries and snapshots the original config (`.bili-bak`).
- For pi the two postures live in ONE package and are never both active: the in-process entry is the default (`npm:billion-context`), `BILI_PI_INPROC=0` delegates to the server-based native instead. Standalone in-process extensions (`opencode-acp`, legacy `billion-context-pi`) remain mutually exclusive with whichever posture is active — the installer swaps the entries and snapshots the original config (`.bili-bak`).
- OpenCode legacy sessions, V1/V2 shapes and caveats: [OpenCode](CLIENTS.md#opencode).
- `kimi` reports runtime-info at bootstrap only (static headers can't carry per-request window/model values); subagent tool calls are routed by the proxy's outbound tool-use witness ring (#1685) — no model-visible conversation id.
- `hermes`'s native plugin is Python: it points hermes' httpx stack at the proxy via env vars after a health check and stamps per-request headers through an `llm_request` middleware.
Expand Down Expand Up @@ -450,7 +450,7 @@ Short-lived sessions leave small state files behind that are never resumed. Clea

Early. Protocol handling and compression work against mock tests (500+ passing). Real-model integration testing is the next milestone. Expect rough edges.

Client-side plugins for pi / omp / opencode ship inside `billion-context` (`dist/agent/*.js`) for the cooperative-proxy path. See the **"Which do I need?"** section above for how `billion-context`, the standalone `billion-context-pi`, and `opencode-acp` relate.
Client-side entries for pi / omp / opencode ship inside `billion-context` (`dist/agent/*.js`): pi gets both the in-process engine (default, #1988) and the server-based native (`BILI_PI_INPROC=0`), while omp / opencode ride the cooperative-proxy path. See the **"Which do I need?"** section above for how `billion-context`, the standalone `opencode-acp`, and the deprecated `billion-context-pi` relate.

## Attribution requirement (one term on top of MIT)

Expand Down
8 changes: 4 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ QQ群:

| 客户端 | 用这个 |
|---|---|
| **pi** | [`billion-context`](https://github.com/ranxianglei/billion-context) —— `bili pi`(启动器)或 `bili plugin install pi`(原生);独立 [`billion-context-pi`](https://github.com/ranxianglei/billion-context-pi) 仍可用 |
| **pi** | [`billion-context`](https://github.com/ranxianglei/billion-context) —— `bili pi`(启动器)或 `npm:billion-context`(进程内扩展,无本地 server;模型流量直连上游)。`BILI_PI_INPROC=0` 回退到 server 版原生(自拉起代理);独立 [`billion-context-pi`](https://github.com/ranxianglei/billion-context-pi) 已弃用(#1988) |
| **opencode**(1.x / 2.x) | [`billion-context`](https://github.com/ranxianglei/billion-context) —— `bili opencode`(启动器)或 `bili plugin install opencode`(原生);独立 [`opencode-acp`](https://github.com/ranxianglei/opencode-acp) 在 1.x 上仍可用 —— 完整指南:[OpenCode](CLIENTS.zh-CN.md#opencode) |
| **omp** | [`billion-context`](https://github.com/ranxianglei/billion-context),`bili omp`(内置插件)或 `bili plugin install omp`(自拉起原生插件,免启动器) |
| **dsh** | [`billion-context`](https://github.com/ranxianglei/billion-context) —— `bili dsh`(启动器,经 `--patch` 注入完整原生插件)或 `bili plugin install dsh` ≡ `dsh plugin --profile <name> add billion-context`(统一泳道)—— 细节见 [CLIENTS.zh-CN.md](CLIENTS.zh-CN.md) |
Expand All @@ -125,7 +125,7 @@ QQ群:
| **goose**(Goose CLI) | `bili goose`(启动器)—— rustls 不信任任何 CA 文件,无法 cert-MITM:openai/anthropic 腿经 `OPENAI_HOST`/`ANTHROPIC_HOST`,自定义 provider 经重新生成的 `GOOSE_PATH_ROOT` overlay(#1049) |
| **其余所有**(没有上下文 hook) | [`billion-context`](https://github.com/ranxianglei/billion-context) —— `bili <client>`(启动器,优先)或 `/bili/` 前缀 |

**原生模式 vs 独立扩展。** 宿主原生插件(`bili plugin install …`)与独立进程内扩展(`billion-context-pi`、`opencode-acp`)**互斥** —— 两者同时生效意味着双重压缩。安装器负责切换:替换旧条目(裸名、`npm:` 别名、带版本号、路径形式都认,数组/对象两种形态都处理),原配置快照到 `.bili-bak`;**项目级**安装不会被碰 —— 需手动移除。作为手动安装的运行期安全网,原生入口在加载时同步设置 `BILLION_CONTEXT_NATIVE=<host>`,让独立扩展在动作时自动退出。pi 一侧该标记需要 `billion-context-pi` **0.1.72+**。
**原生模式 vs 独立扩展。** 宿主原生插件(`bili plugin install …`)与独立进程内扩展(`billion-context-pi`、`opencode-acp`)**互斥** —— 两者同时生效意味着双重压缩。安装器负责切换:替换旧条目(裸名、`npm:` 别名、带版本号、路径形式都认,数组/对象两种形态都处理),原配置快照到 `.bili-bak`;**项目级**安装不会被碰 —— 需手动移除。作为手动安装的运行期安全网,原生入口在加载时同步设置 `BILLION_CONTEXT_NATIVE=<host>`,让独立扩展在动作时自动退出。对 pi 而言这基本已是历史:#1988 之后默认 pi 泳道就是 billion-context 自己的进程内入口(`dist/agent/pi-inprocess.js`,无 server),独立的 `billion-context-pi` 包已弃用、待下线 —— 它的状态文件(`.acp.json` sidecar)由新入口原样读取,≥ 0.1.72 的构建见到我们的标记会自动退出。更早的构建没有该标记,所以两个 pi 入口都会扫描全局 + 项目级 pi 配置,发现残留的旧 `billion-context-pi` 时大声告警 —— 若有一个残留,你看到的是告警而不是静默。


## 安装
Expand Down Expand Up @@ -172,7 +172,7 @@ pi / omp / kimi / claude 没有客户端侧通道 —— 它们的配置条目

注意:

- 原生模式与独立进程内扩展(`billion-context-pi`、`opencode-acp`)**互斥** —— 安装器负责换条目并把原配置快照(`.bili-bak`)。
- 对 pi,两种姿态在同一个包里、永远不会同时生效:进程内入口是默认(`npm:billion-context`),`BILI_PI_INPROC=0` 则委托给 server 版原生。独立进程内扩展(`opencode-acp`、旧 `billion-context-pi`)与当前生效的姿态互斥 —— 安装器负责换条目并把原配置快照(`.bili-bak`)。
- OpenCode 旧会话、V1/V2 插件形态与全部注意事项:[OpenCode](CLIENTS.zh-CN.md#opencode)。
- `kimi` 仅在自举时上报 runtime-info(静态头无法承载逐请求窗口/模型值);子代理工具调用由代理的出站 tool_use 见证环路由(#1685)——模型看不到任何会话 id。
- `hermes` 的原生插件是 Python:健康检查通过后用环境变量把 hermes 的 httpx 栈指向代理,并经 `llm_request` 中间件打逐请求头。
Expand Down Expand Up @@ -361,7 +361,7 @@ bili --no-auto-update # 本次启动禁用自动更新

早期。协议处理和压缩已通过 mock 测试(500+ 项通过)。真实模型集成测试是下一里程碑。预期会有粗糙的地方。

针对 pi / omp / opencode 的客户端插件随 `billion-context` 一起发布(`dist/agent/*.js`),用于协作代理路径。三者(`billion-context`、独立的 `billion-context-pi`、`opencode-acp`)如何取舍,见上文「该选哪个?」一节。
针对 pi / omp / opencode 的客户端入口随 `billion-context` 一起发布(`dist/agent/*.js`):pi 同时拥有进程内引擎(默认,#1988)与 server 版原生(`BILI_PI_INPROC=0`),omp / opencode 走协作代理路径。`billion-context`、独立的 `opencode-acp` 与已弃用的 `billion-context-pi` 如何取舍,见上文「该选哪个?」一节。

## 额外署名要求(在 MIT 之上的一条附加条款)

Expand Down
Loading
Loading