Skip to content
Merged
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
6 changes: 3 additions & 3 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ Full command surface (`bili --help` prints an abridged version). Precedence ever
| `bili pi-test [opts --] [args]` | Like `bili pi`, but adds `--no-extensions` (clean-room test — the proxy owns compression) |
| `bili codex [opts --] [args]` | Proxy + **codex** |
| `bili claude [opts --] [args]` | Proxy + **claude** (Claude Code CLI) |
| `bili omp [opts --] [args]` | Proxy + **omp** (pi-based) |
| `bili opencode [opts --] [args]` | Proxy + **opencode** |
| `bili omp [opts --] [args]` | Proxy + **omp** (pi-based) — opencode zen models ride the default `opencode.ai` MITM whitelist (#1405) |
| `bili opencode [opts --] [args]` | Proxy + **opencode** — built-in zen gateway (`opencode.ai`) cert-MITM'd by default (#1405); hosts declared in `~/.config/opencode/opencode.json` / `~/.omp/omp.json` `providers[].baseURL` join the MITM whitelist automatically (#1411), and `~/.aider.conf.yml` / `~/.config/opencode/.aider.conf.yml` are watched for the same purpose |
| `bili hermes [opts --] [args]` | Proxy + **hermes-agent** (`/bili/` rewrite) |
| `bili dsh [opts --] [args]` | Proxy + **deepseek-harness** (non-loopback upstreams via proxy envs, loopback via `/bili/` rewrite — #535; args like `--profile web "task"` pass through) |
| `bili codebuddy [opts --] [args]` | Proxy + **codebuddy** (Tencent CodeBuddy Code CLI) — `CODEBUDDY_BASE_URL` `/bili/` rewrite, OpenAI chat-completions wire; budget via `CODEBUDDY_AUTO_COMPACT_WINDOW` (#640) |
Expand Down Expand Up @@ -797,7 +797,7 @@ Supported MITM clients:

> **ZCode native mode (#1145):** ZCode is the only client in this list that also has a **native plugin mode** — `bili plugin install zcode` routes model traffic through the provider store (`~/.zcode/v2/config.json`, or `provider_config.json` on v3.14+) and needs no GUI proxy/CA setup at all. Native mode does not touch the MITM surface: if you run both, keep the GUI proxy settings (and the `"mitm://zcode.z.ai": { "passthrough": true }` route, #661) for login traffic. Full mechanics: README's *ZCode* section.

MITM is scoped to a **whitelist** of model hosts (`open.bigmodel.cn`, `api.anthropic.com`, `api.openai.com`, `chatgpt.com`). All other HTTPS hosts are blind-tunnelled — billion-context never decrypts non-model traffic.
MITM is scoped to a **whitelist** of model hosts (`open.bigmodel.cn`, `api.anthropic.com`, `api.openai.com`, `chatgpt.com`), plus per-lane stock-gateway defaults that discovery auto-seeds where a lane's config exists (e.g. `opencode.ai` — opencode's built-in zen gateway from `opencode auth login`, #1405). All other HTTPS hosts are blind-tunnelled — billion-context never decrypts non-model traffic.

> **CONNECT-only clients (`http.proxy`):** many IDE-class clients (CodeBuddy, Cursor, Windsurf, …) expose no model base-URL setting — they route all traffic through an HTTP proxy via `CONNECT`. Such a client is only decrypted when its model host is whitelisted above (or discovered/auto-whitelisted by a launcher); otherwise its tunnels are **blind**: no error, but also **no compression**, because billion-context never sees the cleartext. This misconfiguration is surfaced explicitly (#897): the first blind tunnel per host logs a one-time `BLIND TUNNEL WARNING` with the fix steps; `GET /__bili/health` and `/__bili/stats` report `blindTunnels` (count + exact target hosts, loopback-only); and `acp_status` gains an `UNDECRYPTED TRAFFIC (instance-level)` section while such tunnels exist. Fix: add the client's model domain to `"mitm".domains` (or `BILI_MITM_DOMAINS`), restart, and trust the root CA per the steps below. Note proxy logs mask non-public target hosts by default (`<private-host>`, #255) — set `BILI_LOG_MASK_HOSTS=0` to see them verbatim in your local log.

Expand Down
6 changes: 3 additions & 3 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@
| `bili pi-test [opts --] [args]` | 类似 `bili pi`,但追加 `--no-extensions`(干净测试 —— 压缩完全由代理负责) |
| `bili codex [opts --] [args]` | 代理 + **codex** |
| `bili claude [opts --] [args]` | 代理 + **claude**(Claude Code CLI) |
| `bili omp [opts --] [args]` | 代理 + **omp**(pi 内核) |
| `bili opencode [opts --] [args]` | 代理 + **opencode** |
| `bili omp [opts --] [args]` | 代理 + **omp**(pi 内核)—— opencode zen 模型走默认 `opencode.ai` MITM 白名单(#1405) |
| `bili opencode [opts --] [args]` | 代理 + **opencode** —— 内置 zen 网关(`opencode.ai`)默认证书 MITM(#1405);`~/.config/opencode/opencode.json` / `~/.omp/omp.json` 中 `providers[].baseURL` 声明的主机自动加入 MITM 白名单(#1411),`~/.aider.conf.yml` / `~/.config/opencode/.aider.conf.yml` 同受监听 |
| `bili hermes [opts --] [args]` | 代理 + **hermes-agent**(`/bili/` 重写) |
| `bili dsh [opts --] [args]` | 代理 + **deepseek-harness**(`/bili/` 重写;`--profile web "task"` 等参数原样透传) |
| `bili codebuddy [opts --] [args]` | 代理 + **codebuddy**(Tencent CodeBuddy Code CLI)—— `CODEBUDDY_BASE_URL` `/bili/` 重写,OpenAI chat-completions wire;预算对齐走 `CODEBUDDY_AUTO_COMPACT_WINDOW`(#640) |
Expand Down Expand Up @@ -771,7 +771,7 @@ export ANTHROPIC_BASE_URL="http://localhost:8787/bili/https://api.anthropic.com"

> **ZCode 原生模式(#1145):** ZCode 是这张表里唯一同时拥有**原生插件模式**的客户端 —— `bili plugin install zcode` 经 provider store(`~/.zcode/v2/config.json`,v3.14+ 为 `provider_config.json`)路由模型流量,完全不需要 GUI 代理/CA 设置。原生模式不碰 MITM 面:若两者并用,请保留 GUI 代理设置(以及 `"mitm://zcode.z.ai": { "passthrough": true }` 路由,#661)供登录流量使用。完整机制:README「ZCode」小节。

MITM 只对一份**白名单**中的模型域名生效(`open.bigmodel.cn`、`api.anthropic.com`、`api.openai.com`、`chatgpt.com`)。其余 HTTPS 主机全部盲转发 —— billion-context 绝不解密非模型流量。
MITM 只对一份**白名单**中的模型域名生效(`open.bigmodel.cn`、`api.anthropic.com`、`api.openai.com`、`chatgpt.com`),外加发现机制按 lane 自动播种的自带网关默认域名(如 `opencode.ai` —— opencode `auth login` 的内置 zen 网关,#1405)。其余 HTTPS 主机全部盲转发 —— billion-context 绝不解密非模型流量。

> **只有 `http.proxy` 设置的客户端(CONNECT-only):** 许多 IDE 系客户端(CodeBuddy、Cursor、Windsurf……)没有模型 base-URL 设置 —— 它们把全部流量经 HTTP 代理以 `CONNECT` 方式发出。这类客户端只有在其模型域名被加进上面的白名单后才会被解密;否则其隧道是**盲**的:不报错,但也**不会压缩**,因为 billion-context 根本看不到明文。该误配置现在会被显式暴露(#897):每个目标域名的首个盲隧道会在日志打一条一次性 `BLIND TUNNEL WARNING` 并附修复步骤;`GET /__bili/health` 与 `/__bili/stats` 输出 `blindTunnels`(计数 + 精确目标域名,仅 loopback);存在此类隧道时 `acp_status` 会多一节 `UNDECRYPTED TRAFFIC (instance-level)`。修复:把该客户端的模型域名加进 `"mitm".domains`(或 `BILI_MITM_DOMAINS`),重启,并按下文信任根 CA。注意代理日志默认对非公开目标域名脱敏(`<private-host>`,#255)—— 设 `BILI_LOG_MASK_HOSTS=0` 可在本地日志看到真实域名。

Expand Down
33 changes: 31 additions & 2 deletions src/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export interface OpencodeConfig {
providers: Record<string, OpencodeProvider>;
}

/** opencode's built-in "zen" gateway (`opencode auth login`): the baseURL
* (`https://opencode.ai/zen/v1/messages`) comes from the models.dev catalog,
* not from any local config file, so discovery cannot see it — seed it like
* the other stock model gateways so `bili omp` / `bili opencode` cert-MITM
* zen traffic instead of blind-tunneling it (#1405). */
export const OPENCODE_DEFAULT_MODEL_HOSTS = ["opencode.ai"];

export interface HermesProvider {
api?: string;
}
Expand Down Expand Up @@ -1212,6 +1219,21 @@ export function resolveOpencodeConfigFile(env: NodeJS.ProcessEnv): string {
return path.join(dir, "opencode.jsonc");
}

// The complete set of files whose contents feed config.opencode (exactly what
// readOpencodeConfigRoot reads): the three global candidates + an explicit
// OPENCODE_CONFIG when set. The discovery mtime cache must watch this same set
// or edits go stale (#1411).
/** Candidate opencode config paths for the discovery mtime cache. Order is
* irrelevant (watch/mtime only); readOpencodeConfigRoot reads config.json
* first by preference — no need to keep the two orders in lockstep. */
export function opencodeConfigFiles(env: NodeJS.ProcessEnv): string[] {
const xdg = nonEmpty(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(os.homedir(), ".config");
const dir = path.join(xdg, "opencode");
const files = OPENCODE_CONFIG_FILES.map((f) => path.join(dir, f));
if (nonEmpty(env.OPENCODE_CONFIG)) files.push(env.OPENCODE_CONFIG);
return files;
}

// opencode accepts JSONC (comments, trailing commas) in every config file; a strict
// JSON.parse silently yields "no config" for .jsonc users.
export function parseConfigText(text: string): Record<string, unknown> | undefined {
Expand Down Expand Up @@ -1538,7 +1560,10 @@ export const AIDER_DEFAULT_MODEL_HOSTS = [
* default_config_files entries over earlier ones; aider lists them
* cwd → git root → home): home > git root > cwd. Only top-level scalar
* values are parsed; anything else is ignored. */
export function readAiderConfUrls(cwd: string, env: NodeJS.ProcessEnv = process.env): string[] {
// The .aider.conf.yml candidates feeding config.aider.baseUrls (home > git
// root > cwd, aider's own resolution order). Exported so the discovery mtime
// cache watches the same set (#1411).
export function aiderConfFiles(cwd: string, env: NodeJS.ProcessEnv = process.env): string[] {
const home = nonEmpty(env.HOME) ? env.HOME! : os.homedir();
const candidates = [path.join(home, ".aider.conf.yml")];
let dir = cwd;
Expand All @@ -1552,7 +1577,11 @@ export function readAiderConfUrls(cwd: string, env: NodeJS.ProcessEnv = process.
dir = parent;
}
candidates.push(path.join(cwd, ".aider.conf.yml"));
for (const file of candidates) {
return [...new Set(candidates)];
}

export function readAiderConfUrls(cwd: string, env: NodeJS.ProcessEnv = process.env): string[] {
for (const file of aiderConfFiles(cwd, env)) {
let text: string;
try {
text = fs.readFileSync(file, "utf8");
Expand Down
23 changes: 22 additions & 1 deletion src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { loadClientConfig, resolvePiHome, resolveCodebuddyHome, resolveQoderHome, resolveTraeHome, resolveZcodeHome, zcodePersonalConfigFiles, nonEmpty, QODER_DEFAULT_MODEL_HOSTS, TRAE_DEFAULT_MODEL_HOSTS, AIDER_DEFAULT_MODEL_HOSTS, type ClientConfig } from "./client-config.js";
import { loadClientConfig, resolvePiHome, resolveOmpHome, resolveCodebuddyHome, resolveQoderHome, resolveTraeHome, resolveZcodeHome, zcodePersonalConfigFiles, opencodeConfigFiles, aiderConfFiles, nonEmpty, QODER_DEFAULT_MODEL_HOSTS, TRAE_DEFAULT_MODEL_HOSTS, AIDER_DEFAULT_MODEL_HOSTS, OPENCODE_DEFAULT_MODEL_HOSTS, type ClientConfig } from "./client-config.js";

const TTL_MS = 2000;

Expand Down Expand Up @@ -43,6 +43,14 @@ export function extractHttpsHosts(config: ClientConfig): string[] {
if (config.zcode) {
for (const prov of Object.values(config.zcode.providers)) push(prov.baseURL);
}
// opencode/omp ride cert-MITM via HTTPS_PROXY; custom providers declared in
// their configs (options.baseURL / baseUrl) blind-tunnel without this (#1411).
for (const prov of Object.values(config.opencode?.providers ?? {})) {
if (typeof prov.baseURL === "string") push(prov.baseURL);
}
for (const prov of Object.values(config.omp?.providers ?? {})) {
if (typeof prov.baseUrl === "string") push(prov.baseUrl);
}
if (config.codebuddy) {
push(config.codebuddy.codebuddyBaseUrl);
for (const u of config.codebuddy.modelUrls ?? []) push(u);
Expand All @@ -69,6 +77,14 @@ export function extractHttpsHosts(config: ClientConfig): string[] {
for (const h of AIDER_DEFAULT_MODEL_HOSTS) push(`https://${h}`);
}
}
if (config.opencode || config.omp) {
// #1405: opencode's built-in zen gateway has no config file to
// discover (auth-login users get their baseURL from the models.dev
// catalog). Seeded for both pi-family lanes — omp runs zen models too
// — and coexists with explicit provider base URLs (a user can mix
// custom providers with zen models in one setup).
for (const h of OPENCODE_DEFAULT_MODEL_HOSTS) push(`https://${h}`);
}
return out;
}

Expand All @@ -88,6 +104,11 @@ function configFilePaths(env: NodeJS.ProcessEnv): string[] {
path.join(process.cwd(), ".codebuddy", "models.json"),
path.join(resolveQoderHome(env), "settings.json"),
path.join(resolveTraeHome(env), "traecli.yaml"),
// Must mirror exactly what loadClientConfig reads for the fields
// extractHttpsHosts consumes, or edits go stale in the mtime cache (#1411).
...opencodeConfigFiles(env),
path.join(resolveOmpHome(env), "models.yml"),
...aiderConfFiles(process.cwd(), env),
];
}

Expand Down
Loading
Loading