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
24 changes: 12 additions & 12 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ Full command surface (`bili --help` prints an abridged version). Precedence ever
| `bili omp [opts --] [args]` | Proxy + **omp** (pi-based) |
| `bili opencode [opts --] [args]` | Proxy + **opencode** |
| `bili hermes [opts --] [args]` | Proxy + **hermes-agent** (`/bili/` rewrite) |
| `bili dsh [opts --] [args]` | Proxy + **deepseek-harness** (`/bili/` rewrite; args like `--profile web "task"` pass through) |
| `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 test pi` | Non-polluting end-to-end smoke test of the pi path |
| `bili export [session] [--full] [--output FILE]` | List persisted sessions / export one as a Markdown handoff — see [Sessions & Migration](#sessions--migration) |
| `bili update` | Check for & install a newer version now (bypasses the 3-minute throttle) |
Expand Down Expand Up @@ -533,13 +533,13 @@ How each client is pointed at the proxy (set automatically in the child env):

| Client | Redirect | CA trust |
|---|---|---|
| pi | `HTTPS_PROXY` + isolated `PI_CODING_AGENT_DIR` | `NODE_EXTRA_CA_CERTS` |
| omp | `HTTPS_PROXY` + isolated `PI_CODING_AGENT_DIR` | `NODE_EXTRA_CA_CERTS` |
| pi | `HTTPS_PROXY` + `BILI_PROVIDER_REWRITES` env manifest (extension `registerProvider`) | `NODE_EXTRA_CA_CERTS` |
| omp | `HTTPS_PROXY` + `BILI_PROVIDER_REWRITES` env manifest (extension `registerProvider`) | `NODE_EXTRA_CA_CERTS` |
| codex | `HTTPS_PROXY` + `-c key=value` overrides | `SSL_CERT_FILE` → `combined-ca.pem` |
| claude | `ANTHROPIC_BASE_URL` = `/bili/` URL | none needed |
| opencode | `HTTPS_PROXY` + isolated `OPENCODE_CONFIG` | `NODE_EXTRA_CA_CERTS` |
| hermes | isolated `HERMES_HOME`; **all** upstreams `/bili/` | none (certifi ignores `SSL_CERT_FILE`) |
| dsh | isolated `DSH_HOME` + `DEEPSEEK_BASE_URL`; **all** upstreams `/bili/` | none (plain fetch, no proxy/CA knobs) |
| hermes | `HTTPS_PROXY` (plain-http rides absolute-form forward-proxy requests) | `HERMES_CA_BUNDLE` → `root-ca.pem` |
| dsh | `HTTPS_PROXY` (+ `HTTP_PROXY` for plain-http) + `DEEPSEEK_BASE_URL`; **loopback-only** isolated `DSH_HOME` | `SSL_CERT_FILE` → `combined-ca.pem` |

`NODE_EXTRA_CA_CERTS` *appends* to the built-in trust store, so it points at the MITM root alone (`root-ca.pem`). `SSL_CERT_FILE` *replaces* the default CA bundle, so for codex it points at `combined-ca.pem` — a bundle containing the MITM root **plus** the system/Node public roots — keeping pip/git/curl style TLS (blind-tunnelled, real certificates) working inside the child env (#152).

Expand All @@ -555,16 +555,16 @@ Where upstreams are discovered from (read-only):
| Claude Code | `ANTHROPIC_BASE_URL` env var, else hardcoded `api.anthropic.com` |
| OpenCode | `~/.config/opencode/opencode.json` — each provider's `baseURL` |
| hermes | `~/.hermes/config.yaml` — each provider's endpoint lines |
| dsh | `~/.dsh/settings.yaml` — every `baseURL`/`baseUrl`/`base_url` value; plus the built-in `deepseek-official` route via `$DEEPSEEK_BASE_URL` |
| dsh | `~/.dsh/settings.yaml` — every `baseURL`/`baseUrl`/`base_url` value, split by destination (loopback → `/bili/` rewrite; non-loopback https → MITM whitelist; non-loopback http → `HTTP_PROXY`); plus the built-in `deepseek-official` route via `$DEEPSEEK_BASE_URL` |

### Isolated temp config (what gets written)
### Generated files (what gets written — last resort only, #535)

The `/bili/` rewrite modes write a **temp copy** — the real config is never edited — and the temp dir is removed when the client exits:
The launcher prefers file-free injection (env vars > CLI flags/extension APIs > generated files; see README, “Injection priority” section). Where a file is unavoidable it is a **copy** — the real config is never edited:

- **pi / omp** — an isolated `PI_CODING_AGENT_DIR` (under `/tmp`) containing only a rewritten `models.json` / `models.yml` with the `/bili/`-wrapped plaintext baseUrls. Everything else (`settings.json`, `sessions/`, `auth.json`, extensions…) is **symlinked** to the real pi/omp home, so sessions and logins are shared: a conversation started under the launcher continues seamlessly in a bare client, and vice versa.
- **opencode** — a temp `opencode.json` pointed at by `OPENCODE_CONFIG`, with `/bili/`-rewritten baseURLs **plus the thin `/acp` plugin appended** (native tools out of the box; the standalone `opencode-acp` plugin self-disables via `BILLION_CONTEXT_PROXY`).
- **hermes** — an isolated `HERMES_HOME` with a rewritten `config.yaml` routing **every** upstream (HTTP and HTTPS) through `/bili/` (httpx builds its own CA bundle and ignores `SSL_CERT_FILE`, so cert MITM is impossible). `skills/`, `memories/`, `sessions/` are symlinked through. If no providers are configured — or `config.yaml` can't be rewritten — the launcher prints a warning and hermes runs **unproxied** (compression off).
- **dsh** — an isolated `DSH_HOME` (persistent overlay `~/.dsh-bili`) with a rewritten `settings.yaml` routing every configured upstream through `/bili/` (plain `fetch`, no proxy/CA knobs, so cert MITM is impossible). `profiles/`, credentials and sessions are symlinked through. The built-in `deepseek-official` route is captured separately via `$DEEPSEEK_BASE_URL` (dsh resolves `settings llm-deepseek.baseURL` ?? env ?? default, so a rewritten user setting wins and the env is the zero-config fallback) — with no custom providers the deepseek route is still proxied out of the box.
- **pi / omp** — nothing is written (#535): provider baseUrls ride the `BILI_PROVIDER_REWRITES` env manifest consumed by the bili extension at load (`registerProvider`), and native compaction is cancelled in-extension (`session_before_compact`). The real `~/.pi` / `~/.omp` homes are untouched.
- **opencode** — a temp `opencode.json` pointed at by `OPENCODE_CONFIG` (removed when the client exits), with `/bili/`-rewritten plaintext baseURLs **plus the thin `/acp` plugin appended** (native tools out of the box; the standalone `opencode-acp` plugin self-disables via `BILLION_CONTEXT_PROXY`).
- **hermes** — nothing is written (#535): its httpx stack rides `HTTPS_PROXY` (+ `HERMES_CA_BUNDLE`) — https via CONNECT cert-MITM, plain-http via absolute-form forward-proxy requests. If no providers are configured, the launcher prints a warning and hermes runs **unproxied** (compression off).
- **dsh** — split by destination (#535): dsh's fetch stack honors proxy envs except for an unconditional loopback bypass, so **non-loopback** upstreams ride `HTTPS_PROXY` (cert MITM) / `HTTP_PROXY` (absolute-form forward-proxy requests) with `SSL_CERT_FILE` → `combined-ca.pem`; only **loopback** upstreams keep the persistent overlay `DSH_HOME` (`~/.dsh-bili`) with a rewritten `settings.yaml` routing them through `/bili/`. `profiles/`, credentials and sessions are symlinked through; the real `~/.dsh` is never touched. The built-in `deepseek-official` route is captured separately via `$DEEPSEEK_BASE_URL` (dsh resolves `settings llm-deepseek.baseURL` ?? env ?? default, so a user setting wins and the env is the zero-config fallback) — with no custom providers the deepseek route is still proxied out of the box.

### Native tools in the launcher

Expand Down
22 changes: 11 additions & 11 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ MITM 只对一份**白名单**中的模型域名生效(`open.bigmodel.cn`、`a

| 客户端 | 重定向方式 | CA 信任 |
|---|---|---|
| pi | `HTTPS_PROXY` + 隔离 `PI_CODING_AGENT_DIR` | `NODE_EXTRA_CA_CERTS` |
| omp | `HTTPS_PROXY` + 隔离 `PI_CODING_AGENT_DIR` | `NODE_EXTRA_CA_CERTS` |
| pi | `HTTPS_PROXY` + `BILI_PROVIDER_REWRITES` env 清单(扩展 `registerProvider`) | `NODE_EXTRA_CA_CERTS` |
| omp | `HTTPS_PROXY` + `BILI_PROVIDER_REWRITES` env 清单(扩展 `registerProvider`) | `NODE_EXTRA_CA_CERTS` |
| codex | `HTTPS_PROXY` + `-c key=value` 覆盖 | `SSL_CERT_FILE` → `combined-ca.pem` |
| claude | `ANTHROPIC_BASE_URL` = `/bili/` URL | 无需 |
| opencode | `HTTPS_PROXY` + 隔离 `OPENCODE_CONFIG` | `NODE_EXTRA_CA_CERTS` |
| hermes | 隔离 `HERMES_HOME`;**全部**上游走 `/bili/` | 无(certifi 忽略 `SSL_CERT_FILE`) |
| dsh | 隔离 `DSH_HOME` + `DEEPSEEK_BASE_URL`;**全部**上游走 `/bili/` | 无(纯 fetch,无代理/CA 接口) |
| hermes | `HTTPS_PROXY`(明文 http 走 absolute-form 正向代理请求) | `HERMES_CA_BUNDLE` → `root-ca.pem` |
| dsh | `HTTPS_PROXY`(明文 http 另加 `HTTP_PROXY`)+ `DEEPSEEK_BASE_URL`;**仅回环**隔离 `DSH_HOME` | `SSL_CERT_FILE` → `combined-ca.pem` |

`NODE_EXTRA_CA_CERTS` 是**追加**到内置信任库,所以只指向 MITM 根证书(`root-ca.pem`)即可。`SSL_CERT_FILE` 会**替换**默认 CA bundle,所以 codex 指向 `combined-ca.pem` —— 包含 MITM 根证书**加上**系统/Node 公共根 —— 保证子进程环境里 pip/git/curl 类 TLS(盲转发、真证书)不受影响(#152)。

Expand All @@ -552,16 +552,16 @@ Claude Code 的 undici fetch 忽略 `HTTPS_PROXY`,所以证书 MITM 拦不到
| Claude Code | `ANTHROPIC_BASE_URL` 环境变量,否则硬编码 `api.anthropic.com` |
| OpenCode | `~/.config/opencode/opencode.json` —— 各 provider 的 `baseURL` |
| hermes | `~/.hermes/config.yaml` —— 各 provider 的端点行 |
| dsh | `~/.dsh/settings.yaml` —— 每个 `baseURL`/`baseUrl`/`base_url` 值;内置 `deepseek-official` 路由另经 `$DEEPSEEK_BASE_URL` 接管 |
| dsh | `~/.dsh/settings.yaml` —— 每个 `baseURL`/`baseUrl`/`base_url` 值,按目的地分流(回环 → `/bili/` 重写;非回环 https → MITM 白名单;非回环 http → `HTTP_PROXY`);内置 `deepseek-official` 路由另经 `$DEEPSEEK_BASE_URL` 接管 |

### 隔离临时配置(写了什么)
### 生成文件(写了什么 —— 最后手段,#535)

`/bili/` 重写模式写的是**临时副本** —— 真实配置绝不编辑 —— 客户端退出时临时目录一并删除:
启动器优先零文件注入(env > CLI 参数/扩展 API > 生成文件;见 [README —— 注入优先级](README.zh-CN.md))。确实绕不开文件时写的都是**副本** —— 真实配置绝不编辑:

- **pi / omp** —— 隔离的 `PI_CODING_AGENT_DIR`(在 `/tmp` 下),里面只有一份重写后的 `models.json` / `models.yml`(明文 baseUrl 包上 `/bili/`)。其余一切(`settings.json`、`sessions/`、`auth.json`、扩展……)都**符号链接**到真实 pi/omp 主目录,所以会话与登录互通:launcher 里开的会话在裸客户端里无缝继续,反之亦然。
- **opencode** —— 临时 `opencode.json`(由 `OPENCODE_CONFIG` 指向),`baseURL` 重写为 `/bili/` 形式,**并追加了薄 `/acp` 插件**(开箱即原生工具;独立的 `opencode-acp` 插件检测到 `BILLION_CONTEXT_PROXY` 后自禁用)。
- **hermes** —— 隔离的 `HERMES_HOME`,重写后的 `config.yaml` 让**所有**上游(HTTP 和 HTTPS)都走 `/bili/`(httpx 自建 CA bundle 且忽略 `SSL_CERT_FILE`,证书 MITM 不可行)。`skills/`、`memories/`、`sessions/` 符号链接共享。若没配置任何 provider —— 或 `config.yaml` 无法重写 —— 启动器打印警告,hermes 将**不经代理**运行(无压缩)。
- **dsh** —— 隔离的 `DSH_HOME`(持久 overlay `~/.dsh-bili`),重写后的 `settings.yaml` 让所有已配置上游都走 `/bili/`(纯 `fetch`,无代理/CA 接口,证书 MITM 不可行)。`profiles/`、凭据、会话符号链接共享。内置 `deepseek-official` 路由另行经 `$DEEPSEEK_BASE_URL` 接管(dsh 解析顺序为 settings `llm-deepseek.baseURL` ?? 环境变量 ?? 默认值,重写过的用户配置优先,环境变量作零配置兜底)—— 即便没有任何自定义 provider,内置 deepseek 路由也照样走代理。
- **pi / omp** —— 不写任何文件(#535):provider baseUrl 走 `BILI_PROVIDER_REWRITES` env 清单,由 bili 扩展加载时消费(`registerProvider`);原生压缩改由扩展内取消(`session_before_compact`)。真实 `~/.pi` / `~/.omp` 主目录原样不动。
- **opencode** —— 临时 `opencode.json`(由 `OPENCODE_CONFIG` 指向,客户端退出时删除),明文 `baseURL` 重写为 `/bili/` 形式,**并追加了薄 `/acp` 插件**(开箱即原生工具;独立的 `opencode-acp` 插件检测到 `BILLION_CONTEXT_PROXY` 后自禁用)。
- **hermes** —— 不写任何文件(#535):其 httpx 栈走 `HTTPS_PROXY`(+ `HERMES_CA_BUNDLE`)—— https 经 CONNECT 证书 MITM,明文 http 经 absolute-form 正向代理请求。若没配置任何 provider,启动器打印警告,hermes 将**不经代理**运行(无压缩)。
- **dsh** —— 按目的地分流(#535):dsh 的 fetch 栈尊重代理 env,但对回环目标无条件绕过,所以**非回环**上游走 `HTTPS_PROXY`(证书 MITM)/ `HTTP_PROXY`(absolute-form 正向代理请求),`SSL_CERT_FILE` → `combined-ca.pem`;仅**回环**上游保留持久 overlay `DSH_HOME`(`~/.dsh-bili`),重写后的 `settings.yaml` 让它们走 `/bili/`。`profiles/`、凭据、会话符号链接共享;真实 `~/.dsh` 绝不触碰。内置 `deepseek-official` 路由另行经 `$DEEPSEEK_BASE_URL` 接管(dsh 解析顺序为 settings `llm-deepseek.baseURL` ?? 环境变量 ?? 默认值,用户配置优先,环境变量作零配置兜底)—— 即便没有任何自定义 provider,内置 deepseek 路由也照样走代理。

### 启动器里的原生工具

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ Two ways to use it — pick one:
- **URL change (persistent):** prefix your client's baseURL with the proxy
origin + `/bili/`.

### Injection priority — no files unless unavoidable (#535)

bili never owns user data: every launched client runs on its **real home**, so
runtime writes land where the user expects them. When pointing a client at the
proxy, the launcher picks by priority — **env vars first** (proxy/CA envs for
hermes/dsh/codex; the `BILI_PROVIDER_REWRITES` URL manifest for pi/omp,
consumed by their extension's `registerProvider` at load), then **CLI flags or
extension APIs** (codex `-c key=value`, opencode plugin), and **generated files
last** — today only opencode's temp `opencode.json` (deleted on exit) and dsh's
loopback exception: dsh's fetch stack bypasses proxy envs for loopback targets
unconditionally, so local upstreams keep the persistent `~/.dsh-bili` overlay
rewrite until dsh gains a settings-path env or an upstream loopback opt-out.
Overlay dirs created by older versions are left in place and never merged back
into the real home.

### Option 1 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`)

The launcher wraps a client in one command: it starts a proxy on an
Expand All @@ -158,7 +173,7 @@ bili claude # launch claude through the proxy
bili omp # pi-style, file-free (#535): env + extension registerProvider + compaction cancel, real ~/.omp untouched
bili opencode # MITM for HTTPS + temp opencode.json (/bili/ for HTTP) + thin /acp plugin
bili hermes # file-free (#535): hermes proxy env (HTTPS_PROXY + HERMES_CA_BUNDLE) — https via CONNECT MITM, http via absolute-form forward proxy; real ~/.hermes untouched
bili dsh # deepseek-harness: built-in deepseek route via DEEPSEEK_BASE_URL + overlay DSH_HOME (~/.dsh-bili), all traffic /bili/, native /acp command injected via --patch
bili dsh # deepseek-harness: non-loopback upstreams ride proxy envs (https MITM, http absolute-form), loopback keeps the overlay DSH_HOME (~/.dsh-bili) rewrite (#535), built-in deepseek route via DEEPSEEK_BASE_URL, native /acp command injected via --patch
bili pi --mitm-domain api.foo.com # add a domain to the MITM whitelist
```

Expand Down
6 changes: 5 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ npm install -g billion-context



### 注入优先级 —— 能不写文件就不写(#535)

bili 永不拥有用户数据:每个被启动的客户端都跑在**真实 home** 上,运行期写入落在用户预期的位置。把客户端指向代理时,启动器按优先级选择——**优先 env 变量**(hermes/dsh/codex 的代理/CA env;pi/omp 的 `BILI_PROVIDER_REWRITES` URL 清单,由扩展加载时经 `registerProvider` 消费),其次 **CLI 参数或扩展 API**(codex `-c key=value`、opencode 插件),最后才是**生成文件**——目前仅剩 opencode 的临时 `opencode.json`(退出即删)和 dsh 的回环例外:dsh 的 fetch 栈对回环目标无条件绕过代理 env,所以本地上游保留持久 `~/.dsh-bili` overlay 改写,直到 dsh 提供 settings-path env 或上游支持回环 opt-out。旧版本创建的 overlay 目录原地保留,绝不合并回真实 home。

### 方式 1 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh`)

启动器把客户端包进一条命令:在独立端口拉起一个代理(总是全新实例,绝不复用端口),再按客户端支持的机制把它指向代理 —— 能吃代理/CA 环境变量的走**证书 MITM**,不吃的走隔离的**`/bili/` 配置重写**。真实配置文件从不被修改;客户端自己的配置只被**读取**,用来发现它实际连接的 HTTPS 上游主机,把这些主机加入 MITM 白名单 —— 代理只 TLS 终结它们,其余流量盲透传。
Expand All @@ -89,7 +93,7 @@ bili claude # 拉起 claude
bili omp # pi 同款,file-free(#535):环境变量 + 扩展 registerProvider + 压缩取消,真实 ~/.omp 不动
bili opencode # HTTPS 走 MITM + 临时 opencode.json(HTTP 走 /bili/)+ 轻量 /acp 插件
bili hermes # file-free(#535):hermes 代理环境变量(HTTPS_PROXY + HERMES_CA_BUNDLE)—— https 走 CONNECT MITM,http 走绝对形式转发;真实 ~/.hermes 不动
bili dsh # deepseek-harness:内置 deepseek 路由走 DEEPSEEK_BASE_URL + 隔离 DSH_HOME(~/.dsh-bili),全部流量 /bili/,经 --patch 注入原生 /acp 命令
bili dsh # deepseek-harness:非回环上游走代理 env(https MITM、http absolute-form),回环上游保留 overlay DSH_HOME(~/.dsh-bili)改写(#535),内置 deepseek 路由走 DEEPSEEK_BASE_URL,经 --patch 注入原生 /acp 命令
bili pi --mitm-domain api.foo.com # 向 MITM 白名单追加域名
```

Expand Down
Loading
Loading