From 23a255f6d87e777bc8af1b555e2d45f7bf64fc3c Mon Sep 17 00:00:00 2001 From: ci-check Date: Fri, 6 Nov 2026 03:04:51 +0800 Subject: [PATCH] fix(hermes launcher): route plain-http providers through the proxy (#5116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Companion to PR #5117 (reporter's fork PR), which fixes the same mechanism in the native plugin lane and stays there untouched — this branch is a fork, so this PR covers only the complementary part: the 'bili hermes' LAUNCHER lane + docs + launcher test. hermes' httpx stack resolves proxy envs per scheme (field-verified on Hermes v0.22.5): https upstreams read HTTPS_PROXY, plain-http upstreams read HTTP_PROXY. The launcher exported only the HTTPS pair, so plain-http providers went straight out and bili never saw them (#5116). Same defect class as the plugin lane; same fix shape as the dsh/kimi/mcode/jcode/zed/ qwen house pattern (HTTP_PROXY = origin + loopback NO_PROXY). The child env is stripped of inherited proxy vars first, so the static loopback constant is the whole NO_PROXY value here. Behavior changes (disclosed per policy): - plain-http provider traffic: direct to server -> routed through bili (absolute-form forward-proxy requests) — the intended fix. - child env gains HTTP_PROXY/http_proxy= and NO_PROXY/no_proxy=localhost,127.0.0.1,::1. - loopback https providers now go DIRECT instead of CONNECT-MITM'd through bili — consistent with the loopback-direct contract every other env-routing lane already keeps for its own proxy origin. - non-model http egress of the spawned hermes process rides bili instead of going direct. Together with #5117 this completes #5116; the two PRs touch disjoint files and merge cleanly in either order. --- CLIENTS.md | 10 +++++++--- CONFIGURATION.md | 4 ++-- README.md | 2 +- src/launcher.ts | 15 +++++++++++---- tests/launcher.test.ts | 5 +++++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CLIENTS.md b/CLIENTS.md index 47e00e6209..d062aa955c 100644 --- a/CLIENTS.md +++ b/CLIENTS.md @@ -302,9 +302,13 @@ pure-stdlib Python module shipped inside the npm package: it; parent-pid watchdog tears it down when hermes exits; concurrent starts arbitrate through the same starting-marker protocol the launcher uses). Only once the proxy is verified healthy does it - point hermes' httpx stack at it via `HTTPS_PROXY` / `https_proxy` + - `SSL_CERT_FILE` (bili's combined CA bundle — current hermes resolves ambient - trust there; `HERMES_CA_BUNDLE` stays set for older builds) — + point hermes' httpx stack at it via `HTTPS_PROXY` / `https_proxy` (https) + and `HTTP_PROXY` / `http_proxy` (plain-http — per-scheme resolution, #5116: + HTTPS_PROXY alone left plain-http providers invisible to bili) + loopback + kept direct in `NO_PROXY` / `no_proxy` (defaulted when the user hasn't set + one) + + `SSL_CERT_FILE` (bili's combined CA bundle — current hermes resolves ambient + trust there; `HERMES_CA_BUNDLE` stays set for older builds) — `~/.hermes/config.yaml` is never touched. Provider https hosts are read from hermes' config and whitelisted for MITM; everything else blind-tunnels exactly like launcher mode. If no proxy can be made healthy, the plugin stands down silently and traffic goes diff --git a/CONFIGURATION.md b/CONFIGURATION.md index ac584f640c..f502f00236 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2344,7 +2344,7 @@ How each client is pointed at the proxy (set automatically in the child env): | codex | `HTTPS_PROXY` + `-c key=value` overrides | `SSL_CERT_FILE` → `combined-ca.pem` | | claude | `ANTHROPIC_BASE_URL` = `/bili/` URL (Vertex: `ANTHROPIC_VERTEX_BASE_URL`, when `CLAUDE_CODE_USE_VERTEX=1`; + `NO_PROXY`/`no_proxy` loopback merge, #3446) | none needed | | opencode | `HTTPS_PROXY` + isolated `OPENCODE_CONFIG` | `NODE_EXTRA_CA_CERTS` | -| hermes | `HTTPS_PROXY` (plain-http rides absolute-form forward-proxy requests) | `SSL_CERT_FILE` → `combined-ca.pem` (+ legacy `HERMES_CA_BUNDLE` → `root-ca.pem`) | +| hermes | `HTTPS_PROXY` (https) + `HTTP_PROXY` (plain-http rides absolute-form forward-proxy requests, #5116) + `NO_PROXY` loopback | `SSL_CERT_FILE` → `combined-ca.pem` (+ legacy `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/dsh/hermes it points at `combined-ca.pem` — a bundle containing the MITM root **plus** the OS trust store and the Node public roots. The OS-store merge matters because some launched clients treat this file as their *entire* trust pool (codex's rustls HTTP stack replaces rather than appends, #1807): any direct, non-proxied connection of theirs must validate against this file alone, so the file must be a superset of what the OS itself trusts (Windows cert stores via PowerShell, macOS keychains via `security(1)`; Linux already reads the filesystem bundle; rebuilt at most once per 24 h). Keeping pip/git/curl style TLS (blind-tunnelled, real certificates) working inside the child env is the original reason for the bundle (#152; hermes since #1375, because current hermes resolves ambient trust only through `SSL_CERT_FILE`; OS-store merge since #1807). @@ -2369,7 +2369,7 @@ The launcher prefers file-free injection (env vars > CLI flags/extension APIs > - **pi / omp** — nothing is written (#535): provider baseUrls ride the `BILI_PROVIDER_REWRITES` env manifest consumed by the bili extension at load (`registerProvider`), and auto native compaction is cancelled in-extension (`session_before_compact`; omp distinguishes auto vs manual via the `auto_compaction_start` announcement, #851) — but only on positive evidence the proxy actually carries the conversation (the plugin stamped `x-bili-plugin-conversation` for this session id, or omp's identity register succeeded, or `/__bili/plugin/status?conversationId=` confirms it); non-http(s) provider baseUrls (e.g. pi-claude-bridge's literal `"claude-bridge"`) are never cancelled by default, so their own compaction takeover keeps working (#1382); a provider can be opted in via its entry in the `providers` table — key = the provider id (a non-URL key is inert for routing), field `"compactionOptIn": true` — or `BILI_NON_HTTP_PROVIDERS` (env, comma-separated) — but opt-in only widens the candidate set, so even an opted-in provider is cancelled only on the same positive carriage evidence above (#1392) — manual `/compact` stays user-owned either way. 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 plugin appended** (`/acp` + `/acp-cache` commands). On OpenCode 1.x the `opencode-acp` entries are stripped from the clone (the host must not load it armed) and the thin plugin imports that same package as a library instead, gated on legacy sessions; the first stripped spec rides along via `BILI_OPENCODE_ACP_SPEC` so the bridge imports the exact copy the host would have loaded (#920). Relative local plugin specs (`./x`, `../x`) are re-anchored to absolute paths in the clone — opencode resolves them against the declaring config file's dir, which the clone no longer is (#826). -- **hermes** — nothing is written (#535): its httpx stack rides `HTTPS_PROXY` (+ `SSL_CERT_FILE` → `combined-ca.pem`; legacy `HERMES_CA_BUNDLE` stays set for older builds, #1375) — 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). +- **hermes** — nothing is written (#535): its httpx stack resolves proxy envs per scheme (#5116) — https via `HTTPS_PROXY` (CONNECT cert-MITM), plain-http via `HTTP_PROXY` (absolute-form forward-proxy requests); `NO_PROXY`/`no_proxy` keep the loopback legs (local model endpoints, MCP) direct (+ `SSL_CERT_FILE` → `combined-ca.pem`; legacy `HERMES_CA_BUNDLE` stays set for older builds, #1375). 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. Home-root SQLite databases are the one exception to sharing: each launch gets a private copy in the overlay, merged back as a unit on exit (a file-linked main db would let the two paths grow independent WALs over one inode — #1917). 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. - **codex** — a persistent overlay `CODEX_HOME` (`~/.codex-bili`, or `-bili`) whose other entries (auth, sessions, model settings) stay shared links into the real home. The exception is home-root SQLite databases (`*.db` / `*.sqlite` / `*.sqlite3` — codex keeps its logs/state there): each launch gets a private copy in the overlay, merged back into the real home as ONE unit on exit (newer main-db generation wins; the loser is preserved as `.bili-conflict`). File-linking those dbs across the two homes lets two paths grow independent WALs over one inode — committed writes lost or the database corrupted (#1917). Two generated files: (a) when MCP injection is on, a merged `config.toml` — real contents plus the per-spawn `[mcp_servers.bili]` block (inline `-c` values cannot survive cmd.exe quoting on Windows, #681); (b) since #1802, a generated `.env` (mode 0600) that re-pins THIS launch's `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` / `NO_PROXY` / `SSL_CERT_FILE` / `BILLION_CONTEXT_PROXY`: codex's own `load_dotenv()` overwrites the launcher's spawn env from `$CODEX_HOME/.env` **after** start, so a user `.env` pointing at e.g. a socks5h proxy would otherwise silently re-route codex off bili (and codex's custom-CA rustls HTTP stack cannot speak SOCKS at all). Your other `.env` variables are carried over verbatim; pre-existing shared `.env` links are migrated to an owned file; the real home's `.env` and every other real-home file are never touched. Direct-URL mode (`BILI_LAUNCHER_DIRECT=1`) generates no `.env` (there is no injected proxy to protect) and, without MCP, no overlay at all. diff --git a/README.md b/README.md index 7063c258e5..53ee360656 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ bili codex # launch codex through the proxy bili claude # launch claude through the proxy bili omp # pi-style, file-free (#535): env + extension registerProvider + compaction cancel, real ~/.omp untouched bili opencode # OpenCode (1.x & 2.x): full guide in the [OpenCode](CLIENTS.md#opencode) section below -bili hermes # file-free (#535): hermes proxy env (HTTPS_PROXY + combined CA bundle via SSL_CERT_FILE) — https via CONNECT MITM, http via absolute-form forward proxy; real ~/.hermes untouched +bili hermes # file-free (#535): hermes proxy env (HTTPS_PROXY + HTTP_PROXY per scheme (#5116) + combined CA bundle via SSL_CERT_FILE; loopback direct via NO_PROXY) — https via CONNECT MITM, http via absolute-form forward proxy; real ~/.hermes untouched bili dsh # deepseek-harness: full native plugin injected via --patch (#941) — real dsh tools, session-bound /acp + /acp-cache (plugin mode); non-loopback upstreams ride proxy envs, loopback keeps the overlay DSH_HOME rewrite (#535); dsh auto-compaction off everywhere — host plane via the bundle patch, web-profile presets at load time (#1772/#2474/#3354) bili codebuddy # Tencent CodeBuddy Code CLI: CODEBUDDY_BASE_URL /bili/ rewrite (OpenAI chat completions wire), budget aligned via CODEBUDDY_AUTO_COMPACT_WINDOW; real ~/.codebuddy untouched bili qoder # qoder CLI (`qoder`/`qodercli`): model endpoint is hardcoded https (no /bili/ rewrite possible) — cert-MITM via HTTPS_PROXY + NODE_EXTRA_CA_CERTS, default model hosts whitelisted (#653). Qoder Desktop is a separate BYOK/custom channel that speaks plaintext OpenAI over a `/bili/` prefix — point it at bili as a normal custom provider (not this MITM lane); its official-subscription traffic is encrypted and out of scope (#764) diff --git a/src/launcher.ts b/src/launcher.ts index e6d5458053..98ea2246cb 100644 --- a/src/launcher.ts +++ b/src/launcher.ts @@ -6739,10 +6739,14 @@ export async function runLaunch(params: RunLaunchParams, deps: LauncherDeps = {} // #535 phase 2: file-free — no overlay HERMES_HOME, no config.yaml // runs on its REAL home — including a user-set HERMES_HOME (discovery // resolved the same path, so the MITM whitelist matches). Its httpx - // stack resolves ONE proxy env var (HTTPS_PROXY first) for both - // schemes: https upstreams ride CONNECT + cert MITM, plain-http - // upstreams ride absolute-form forward-proxy requests the server - // understands. CA trust (#1375): current hermes resolves the main + // stack resolves proxy envs PER SCHEME (#5116, field-verified on Hermes + // v0.22.5): https upstreams read HTTPS_PROXY (CONNECT + cert MITM), + // plain-http upstreams read HTTP_PROXY (absolute-form forward-proxy + // requests the server understands) — HTTPS_PROXY alone left plain-http + // providers going straight out, invisible to bili. NO_PROXY keeps the + // loopback legs (local model endpoints, MCP) direct; the env was + // stripped above, so the static constant is the whole value. CA trust + // (#1375): current hermes resolves the main // client via agent/ssl_verify.py — platform store + per-provider // ssl_ca_cert, ambient trust only through SSL_CERT_FILE (OpenSSL // replace semantics → the COMBINED bundle keeps blind-tunnelled hosts @@ -6752,6 +6756,9 @@ export async function runLaunch(params: RunLaunchParams, deps: LauncherDeps = {} // carrier is present (anonymous requests are accepted, #286). env = stripInheritedProxy(process.env); env.HTTPS_PROXY = origin; + env.HTTP_PROXY = origin; + env.NO_PROXY = LAUNCHER_LOOPBACK_NO_PROXY; + env.no_proxy = LAUNCHER_LOOPBACK_NO_PROXY; env.HERMES_CA_BUNDLE = ca; env.SSL_CERT_FILE = resolveCombinedCaPath(process.env); if (routes.httpRewrites.length === 0 && routes.httpsDomains.length === 0) { diff --git a/tests/launcher.test.ts b/tests/launcher.test.ts index 8012b43ae8..d92effcb06 100644 --- a/tests/launcher.test.ts +++ b/tests/launcher.test.ts @@ -860,6 +860,11 @@ test("runLaunch hermes #535: proxy env routing, no HERMES_HOME overlay, real con assert.deepEqual(exitCalls, [0]); assert.ok(childEnv, "client spawned"); assert.match(childEnv!.HTTPS_PROXY ?? "", /^http:\/\/127\.0\.0\.1:\d+$/); + // #5116: per-scheme proxy resolution — plain-http upstreams read HTTP_PROXY (HTTPS_PROXY + // alone left them going straight out), loopback stays direct via NO_PROXY. + assert.equal(childEnv!.HTTP_PROXY, childEnv!.HTTPS_PROXY, "plain-http upstreams ride the same origin"); + assert.equal(childEnv!.NO_PROXY, "localhost,127.0.0.1,::1"); + assert.equal(childEnv!.no_proxy, "localhost,127.0.0.1,::1"); assert.ok(childEnv!.HERMES_CA_BUNDLE, "CA bundle exported"); assert.ok( String(childEnv!.SSL_CERT_FILE).endsWith(path.join("billion-context", "ca", "combined-ca.pem")),