From 7476fcd18c7131b78e5a7a6c014fbc16924773a4 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 00:32:15 +0800 Subject: [PATCH 1/4] feat: bili antigravity-desktop launcher for the Antigravity Desktop IDE (#4675) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The desktop app spawns the same closed Go language_server as the agy CLI and honors the identical CLOUD_CODE_URL env override, so this adds an antigravity-desktop alias launch client that reuses the exact same env lane as bili antigravity — only the launched binary differs. It probes the standard desktop install paths (Windows %LOCALAPPDATA%\Programs\antigravity and %PROGRAMFILES%\antigravity; macOS /Applications/Antigravity.app; Linux /usr/bin and ~/.local/share/antigravity) with a --bin/BILI_CLIENT_BIN override for custom locations. Docs: docs/clients.{md,zh-CN.md,ja.md} and README.{md,zh-CN.md} gain a desktop bullet, the manual-attach-to-bili-start recipe, and the single-instance caveat. (cherry picked from commit d210f2a9e960c6d4e0dbeafdc101daaeec45df74) --- README.md | 5 +- README.zh-CN.md | 5 +- docs/clients.ja.md | 3 +- docs/clients.md | 22 +++++++-- docs/clients.zh-CN.md | 17 ++++++- src/cli.ts | 4 +- src/launcher.ts | 55 ++++++++++++++++++++-- tests/launcher-gemini-family.test.ts | 6 +++ tests/launcher.test.ts | 70 ++++++++++++++++++++++++++++ 9 files changed, 173 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b52b072107..e64547aff0 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Pick by your client: | **gemini** (Gemini CLI) | `bili gemini` (launcher, `GOOGLE_GEMINI_BASE_URL` `/bili/` rewrite) or `/bili/` prefix — launcher-only (no in-loop tool seam, #1043) | | **iflow** (iFlow CLI) | `bili iflow` (launcher, `IFLOW_BASE_URL` `/bili/` rewrite) or `/bili/` prefix | | **qwen** (Qwen Code) | `bili qwen` (launcher, cert-MITM) or `/bili/` prefix | -| **antigravity** (Antigravity CLI / agy, Google) | `bili antigravity` (launcher, `CLOUD_CODE_URL` `/bili/` rewrite of daily-cloudcode-pa.googleapis.com — Antigravity's real default upstream, #3129) or `/bili/` prefix — no plugin seam (closed Go language_server; its user-plugin surface is additive-only, #2115) — details: [docs/clients.md](docs/clients.md) | + | **antigravity** (Antigravity CLI / agy + Desktop IDE, Google) | `bili antigravity` (CLI; launcher, `CLOUD_CODE_URL` `/bili/` rewrite of daily-cloudcode-pa.googleapis.com — Antigravity's real default upstream, #3129) or `bili antigravity-desktop` (Desktop IDE; same `CLOUD_CODE_URL` lane, probes desktop install paths, #4675) or `/bili/` prefix — no plugin seam (closed Go language_server; its user-plugin surface is additive-only, #2115) — details: [docs/clients.md](docs/clients.md) | | **mcode** (MiniMax Code) | [`billion-context`](https://github.com/ranxianglei/billion-context) via `bili mcode` (cert-MITM) or `/bili/` prefix — no native mode (event hooks only, no model-request seam, [#1050](https://github.com/ranxianglei/billion-context/issues/1050)) | | **aider** | [`billion-context`](https://github.com/ranxianglei/billion-context) via `bili aider` (cert-MITM) or `/bili/` prefix — no native mode (shell-command-only hooks, no tool-injection seam, [#1048](https://github.com/ranxianglei/billion-context/issues/1048)) | | **copilot** (GitHub Copilot CLI) | `bili copilot` (launcher, cert-MITM) — closed Go binary, no plugin seam (#1049) | @@ -254,7 +254,7 @@ Notes: - `jcode` and `aider` have no native mode (no plugin/MCP/tool-injection seam: #962, #1048) — use `bili jcode` / `bili aider`. - `copilot`, `amp` and `goose` are launcher-only (#1049); goose cannot be cert-MITMed (rustls trusts no CA file) and rides plain-HTTP base-URL redirects instead. -### Option 2 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh` / `bili codebuddy` / `bili qoder` / `bili trae` / `bili jcode` / `bili kimi` / `bili gemini` / `bili iflow` / `bili qwen` / `bili antigravity` / `bili mcode` / `bili aider` / `bili copilot` / `bili amp` / `bili goose` / `bili kiro`) +### Option 2 — Launcher (`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh` / `bili codebuddy` / `bili qoder` / `bili trae` / `bili jcode` / `bili kimi` / `bili gemini` / `bili iflow` / `bili qwen` / `bili antigravity` / `bili antigravity-desktop` / `bili mcode` / `bili aider` / `bili copilot` / `bili amp` / `bili goose` / `bili kiro`) The launcher wraps a client in one command: it starts a proxy on an independent port (a fresh instance is always spawned — a port is never @@ -282,6 +282,7 @@ bili gemini # Gemini CLI (Google): GOOGLE_GEMINI_BASE_ bili iflow # iFlow CLI: IFLOW_BASE_URL /bili/ rewrite to apis.iflow.cn/v1 (OpenAI chat-completions wire), real ~/.iflow untouched bili qwen # Qwen Code (multi-protocol gemini-cli fork, no base-URL hook): cert-MITM via HTTPS_PROXY + NODE_EXTRA_CA_CERTS, default DashScope/Qwen model hosts whitelisted, custom relays via --mitm-domain bili antigravity # Antigravity CLI (agy, Google): CLOUD_CODE_URL /bili/ rewrite of daily-cloudcode-pa.googleapis.com — the real default upstream (bare cloudcode-pa 400s on /v1internal:*, #3129); undocumented language-server env override, v2.19.1 binary-verified; wire recognized as Google native by path (#2115) +bili antigravity-desktop # Antigravity Desktop (IDE, Google): same CLOUD_CODE_URL lane as the CLI, probes standard desktop install paths, --bin override for custom locations (#4675) bili mcode # MiniMax Code CLI: same shape as kimi (proxy envs, unconditional loopback bypass, cert-MITM/absolute-form); session bound via X-Mavis-Session-Id (#1050) bili aider # Aider (Python pair programmer): cert-MITM via HTTPS_PROXY + SSL_CERT_FILE/REQUESTS_CA_BUNDLE; endpoint from OPENAI_API_BASE / ANTHROPIC_BASE_URL / --openai-api-base / .aider.conf.yml (#1048) bili copilot # Copilot CLI (GitHub, closed Go binary) — cert-MITM via HTTPS_PROXY + SSL_CERT_FILE, api.githubcopilot.com + per-plan subdomains whitelisted (#1049) diff --git a/README.zh-CN.md b/README.zh-CN.md index ee02e832f4..6d27cdd3bf 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -112,7 +112,7 @@ QQ群: | **gemini**(Gemini CLI) | `bili gemini`(启动器,`GOOGLE_GEMINI_BASE_URL` `/bili/` 改写)或 `/bili/` 前缀 —— 仅启动器(无环内工具注入接缝,#1043) | | **iflow**(iFlow CLI) | `bili iflow`(启动器,`IFLOW_BASE_URL` `/bili/` 改写)或 `/bili/` 前缀 | | **qwen**(Qwen Code) | `bili qwen`(启动器,cert-MITM)或 `/bili/` 前缀 | -| **antigravity**(Antigravity CLI / agy,Google) | `bili antigravity`(启动器,`CLOUD_CODE_URL` 对 `daily-cloudcode-pa.googleapis.com` 的 `/bili/` 改写 —— Antigravity 真实默认上游,#3129)或 `/bili/` 前缀 —— 无插件接缝(闭源 Go language_server;其用户插件面仅可追加、不能拦截模型流,[#2115](https://github.com/ranxianglei/billion-context/issues/2115))—— 细节见 [docs/clients.zh-CN.md](docs/clients.zh-CN.md) | +| **antigravity**(Antigravity CLI / agy + 桌面 IDE,Google) | `bili antigravity`(CLI;启动器,`CLOUD_CODE_URL` 对 `daily-cloudcode-pa.googleapis.com` 的 `/bili/` 改写 —— Antigravity 真实默认上游,#3129)或 `bili antigravity-desktop`(桌面 IDE;同一 `CLOUD_CODE_URL` lane,探测桌面安装路径,#4675)或 `/bili/` 前缀 —— 无插件接缝(闭源 Go language_server;其用户插件面仅可追加、不能拦截模型流,[#2115](https://github.com/ranxianglei/billion-context/issues/2115))—— 细节见 [docs/clients.zh-CN.md](docs/clients.zh-CN.md) | | **mcode**(MiniMax Code) | [`billion-context`](https://github.com/ranxianglei/billion-context),`bili mcode`(cert-MITM)或 `/bili/` 前缀 —— 无原生模式(纯声明式事件钩子,无模型请求接缝,[#1050](https://github.com/ranxianglei/billion-context/issues/1050)) | | **aider** | [`billion-context`](https://github.com/ranxianglei/billion-context),`bili aider`(cert-MITM)或 `/bili/` 前缀 —— 无原生模式(仅 shell 命令钩子,无工具注入接缝,[#1048](https://github.com/ranxianglei/billion-context/issues/1048)) | | **copilot**(GitHub Copilot CLI) | `bili copilot`(启动器,cert-MITM)—— 闭源 Go 二进制、无插件接缝(#1049) | @@ -201,7 +201,7 @@ pi / omp / kimi / claude 没有客户端侧通道 —— 它们的配置条目 - `jcode`、`aider` 无原生模式(无插件/MCP/工具注入接缝:#962、#1048)—— 用 `bili jcode` / `bili aider`。 - `copilot`、`amp`、`crush`、`zed`、`goose` 仅启动器模式(#1049/#2340);goose 无法 cert-MITM(rustls 不信任任何 CA 文件),改走纯 HTTP base-URL 重定向。 -### 方式 2 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh` / `bili codebuddy` / `bili qoder` / `bili trae` / `bili jcode` / `bili kimi` / `bili gemini` / `bili iflow` / `bili qwen` / `bili antigravity` / `bili mcode` / `bili aider` / `bili copilot` / `bili amp` / `bili crush` / `bili zed` / `bili goose` / `bili kiro`) +### 方式 2 —— 启动器(`bili pi` / `bili codex` / `bili claude` / `bili omp` / `bili opencode` / `bili hermes` / `bili dsh` / `bili codebuddy` / `bili qoder` / `bili trae` / `bili jcode` / `bili kimi` / `bili gemini` / `bili iflow` / `bili qwen` / `bili antigravity` / `bili antigravity-desktop` / `bili mcode` / `bili aider` / `bili copilot` / `bili amp` / `bili crush` / `bili zed` / `bili goose` / `bili kiro`) 启动器把客户端包进一条命令:在独立端口拉起一个代理(总是全新实例,绝不复用端口),再按客户端支持的机制把它指向代理 —— 能吃代理/CA 环境变量的走**证书 MITM**,不吃的走隔离的**`/bili/` 配置重写**。真实配置文件从不被修改;客户端自己的配置只被**读取**,用来发现它实际连接的 HTTPS 上游主机,把这些主机加入 MITM 白名单 —— 代理只 TLS 终结它们,其余流量盲透传。 @@ -222,6 +222,7 @@ bili gemini # Gemini CLI(Google):GOOGLE_GEMINI_BASE_UR bili iflow # iFlow CLI:IFLOW_BASE_URL /bili/ 改写到 apis.iflow.cn/v1(OpenAI chat-completions wire),真实 ~/.iflow 零改动 bili qwen # Qwen Code(多协议 gemini-cli fork,无 base-URL 钩子):HTTPS_PROXY + NODE_EXTRA_CA_CERTS 证书 MITM,默认 DashScope/Qwen 模型主机加白,自建中转用 --mitm-domain 追加 bili antigravity # Google Antigravity CLI(agy,Gemini CLI 继任者):CLOUD_CODE_URL 对 daily-cloudcode-pa.googleapis.com 的 /bili/ 改写 —— 真实默认上游(裸 cloudcode-pa 在 /v1internal:* 上 400,#3129),无需证书 MITM(#2115) +bili antigravity-desktop # Google Antigravity 桌面端(IDE):与 CLI 同一 CLOUD_CODE_URL lane,探测标准桌面安装路径,自定义位置用 --bin 覆盖(#4675) bili mcode # MiniMax Code CLI:与 kimi 同构(代理环境变量、无条件回环绕过、证书 MITM/绝对形式);会话经 X-Mavis-Session-Id 绑定(#1050) bili aider # Aider(Python pair programmer):HTTPS_PROXY + SSL_CERT_FILE/REQUESTS_CA_BUNDLE 证书 MITM;端点取自 OPENAI_API_BASE / ANTHROPIC_BASE_URL / --openai-api-base / .aider.conf.yml(#1048) bili copilot # Copilot CLI(GitHub,闭源 Go 二进制)—— 证书 MITM(HTTPS_PROXY + SSL_CERT_FILE),api.githubcopilot.com + 各套餐子域加白(#1049) diff --git a/docs/clients.ja.md b/docs/clients.ja.md index 1723430597..7e77d8f350 100644 --- a/docs/clients.ja.md +++ b/docs/clients.ja.md @@ -114,7 +114,8 @@ gemini-cli アーキテクチャファミリーのための 4 つのランチャ - **`bili gemini`** — Gemini CLI (`@google/gemini-cli`)。`GOOGLE_GEMINI_BASE_URL=/bili/` を設定する(デフォルトアップストリーム `https://generativelanguage.googleapis.com`;自分で `GOOGLE_GEMINI_BASE_URL` をエクスポートするなら、その値が代わりにプロキシ経由で中継される)。クライアントは `gateway` 認証モードに切り替わり、Google ネイティブワイヤ要求をループバックプロキシに直接送る — MITM なし、CA インストールなし、`~/.gemini` は決して触れない。プロキシはこのワイヤをネイティブで話す(モデル名は URL パスに乗る)。制約:ヘッドレス `-p` 実行は保存済みの認証選択が必要(例:settings の `security.auth.selectedType = "gemini-api-key"` + `GEMINI_API_KEY`)— gemini-cli は非対話モードで純粋に環境由来の gateway 認証を拒否するため;OAuth 個人ログイン(CodeAssist)ユーザーはこのルートでまったくカバーされない — そのパスは base-URL フックを無視する。 - **`bili iflow`** — iFlow CLI (`@iflow-ai/iflow-cli`)。`IFLOW_BASE_URL` 経由で同じパターン(デフォルト `https://apis.iflow.cn/v1`、設定したら中継);OpenAI chat-completions ワイヤ。 - **`bili qwen`** — Qwen Code (`QwenLM/qwen-code`)。このフォークは base-URL フックを落とした(`DASHSCOPE_PROXY_BASE_URL` はヘッダ調整ノブであってルーティングではない)が、標準プロキシ環境変数は尊重するので、ランチャーは cert-MITM を使う:`HTTPS_PROXY=` + `NODE_EXTRA_CA_CERTS=`、デフォルトモデルホスト(DashScope / Qwen ゲートウェイ / よくあるサードパーティエンドポイント)の静的ホワイトリスト付き。カスタム中継ホスト:`--mitm-domain ` で追加。ベストエフォートルート — ログの `BLIND TUNNEL WARNING` はホストがホワイトリストから漏れていることを意味する。 -- **`bili antigravity`** — Google Antigravity (#2115)。ランチャーは公式 CLI バイナリ **`agy`** を駆動する(Gemini CLI の後継で、2026-06 に廃止;`PATH` または `~/.local/bin/agy`、Windows `%LOCALAPPDATA%\agy\bin` にある)。そのモデルチャネルはクローズドソースの Go `language_server` の中にあり、**文書化されていない** `CLOUD_CODE_URL` 環境上書きを尊重する(v2.19.1 バイナリで確認:*"Overriding CloudCodeServerURL via CLOUD_CODE_URL environment variable"*)— gemini-cli の base-URL フックと同じ形状。ランチャーは `CLOUD_CODE_URL=/bili/` を設定する(デフォルトアップストリーム `https://daily-cloudcode-pa.googleapis.com` — Antigravity の実際のデフォルト;裸の `cloudcode-pa` ホストは `/v1internal:*` で 400 になる、#3129;自分で `CLOUD_CODE_URL` をエクスポートするなら、その値が代わりにプロキシ経由で中継される)。MITM なし、CA インストールなし。プロキシは**パスで**ワイヤを認識する:`:streamGenerateContent` / `:generateContent` / `:countTokens` 要求は Google ネイティブアダプタにルーティングされ `bili gemini` と同様に圧縮される。サーバーが代わりに gRPC メソッドパス(`/google.internal.cloud.code.v1internal.CloudCode/*`)を使う場合、そうした要求は認識されずそのまま圧縮なしで中継される — グレースフルな退化で、確認次第レーンごとの `protocol` 宣言 (#1909) で修正可能。Google がいつか環境フックを削除した場合のフォールバック:cert-MITM — language_server は `HTTPS_PROXY` を尊重し証明書ピン留めをしないので、`daily-cloudcode-pa.googleapis.com`(Antigravity の実際のデフォルトエンドポイント;裸の `cloudcode-pa` 名は `/v1internal:*` で 400 になる、#3129)を `"mitm".domains` に追加し、bili のルート CA を信頼する。デスクトップアプリと IDE エクステンションはこの同じ language_server チャネルを共有する;ランチャーは具体的には CLI を駆動する — デスクトップユーザーは `CLOUD_CODE_URL` を手動でエクスポートするか、MITM レシピを使える。 +- **`bili antigravity`** — Google Antigravity (#2115)。ランチャーは公式 CLI バイナリ **`agy`** を駆動する(Gemini CLI の後継で、2026-06 に廃止;`PATH` または `~/.local/bin/agy`、Windows `%LOCALAPPDATA%\agy\bin` にある)。そのモデルチャネルはクローズドソースの Go `language_server` の中にあり、**文書化されていない** `CLOUD_CODE_URL` 環境上書きを尊重する(v2.19.1 バイナリで確認:*"Overriding CloudCodeServerURL via CLOUD_CODE_URL environment variable"*)— gemini-cli の base-URL フックと同じ形状。ランチャーは `CLOUD_CODE_URL=/bili/` を設定する(デフォルトアップストリーム `https://daily-cloudcode-pa.googleapis.com` — Antigravity の実際のデフォルト;裸の `cloudcode-pa` ホストは `/v1internal:*` で 400 になる、#3129;自分で `CLOUD_CODE_URL` をエクスポートするなら、その値が代わりにプロキシ経由で中継される)。MITM なし、CA インストールなし。プロキシは**パスで**ワイヤを認識する:`:streamGenerateContent` / `:generateContent` / `:countTokens` 要求は Google ネイティブアダプタにルーティングされ `bili gemini` と同様に圧縮される。サーバーが代わりに gRPC メソッドパス(`/google.internal.cloud.code.v1internal.CloudCode/*`)を使う場合、そうした要求は認識されずそのまま圧縮なしで中継される — グレースフルな退化で、確認次第レーンごとの `protocol` 宣言 (#1909) で修正可能。Google がいつか環境フックを削除した場合のフォールバック:cert-MITM — language_server は `HTTPS_PROXY` を尊重し証明書ピン留めをしないので、`daily-cloudcode-pa.googleapis.com`(Antigravity の実際のデフォルトエンドポイント;裸の `cloudcode-pa` 名は `/v1internal:*` で 400 になる、#3129)を `"mitm".domains` に追加し、bili のルート CA を信頼する。デスクトップアプリと IDE エクステンションはこの同じ language_server チャネルを共有する;`bili antigravity-desktop` (#4675) は同一レーンでデスクトップバイナリを駆動する(下記)。 +- **`bili antigravity-desktop`** — Google Antigravity **デスクトップ**(IDE アプリ)(#4675)。デスクトップアプリは `agy` と同じ Go `language_server` を起動し、同じ `CLOUD_CODE_URL` フックを尊重するため、このランチャーは `bili antigravity` と全く同じ環境レーンを再利用する — 変わるのは起動するバイナリだけ。標準デスクトップインストールパスを探索する(Windows: `%LOCALAPPDATA%\Programs\antigravity\Antigravity.exe`、次に `%PROGRAMFILES%\antigravity\Antigravity.exe`;macOS: `/Applications/Antigravity.app/Contents/MacOS/Antigravity`;Linux: `/usr/bin/antigravity`、次に `~/.local/share/antigravity/antigravity`);カスタム位置は `--bin`/`BILI_CLIENT_BIN` 上書きが優先。デスクトップは単一インスタンスアプリ:既に起動中の場合、新しいプロセスは既存のウィンドウをフォーカスして終了する(ランチャーのプロキシが解体される)— 先に開いている Antigravity ウィンドウを閉じて。手動起動したインスタンスを動作中の `bili start` デーモンに接続したい場合:`export CLOUD_CODE_URL="http://localhost:8787/bili/https://daily-cloudcode-pa.googleapis.com"` を実行し、そのシェルからアプリを起動(または上記の MITM レシピを使用)。 4 つのいずれにもネイティブモードはない:どれもループ内ツール注入シームを公開しない(gemini-cli のエクステンションはカスタムコマンドにしか到達できない;フォークはその表面を継承;Antigravity はユーザープラグインシステムを同梱する — `plugins//` に `plugin.json`、`hooks.json`、`mcp_config.json`、`skills/`、JS サイドカー — がすべての表面は追加型のみ:ツール、プロンプト、UI、イベントコールバック。その中の何ものもモデル要求/応答ストリームをインターセプトしたり書き換えたりできず、それはクローズドな language_server の内部に完全に留まるため、ワイヤのみ統合が v1 の天井)。設計上ランチャーのみ。 diff --git a/docs/clients.md b/docs/clients.md index e0819f6151..7849307689 100644 --- a/docs/clients.md +++ b/docs/clients.md @@ -669,9 +669,25 @@ the four have a base-URL env hook; one doesn't: `daily-cloudcode-pa.googleapis.com` (Antigravity's real default endpoint; the bare `cloudcode-pa` name 400s on `/v1internal:*`, #3129) to `"mitm".domains` and trust bili's root CA. - The desktop app and the IDE extension share this same language_server - channel; the launcher drives the CLI specifically — desktop users can export - `CLOUD_CODE_URL` manually or use the MITM recipe. + The desktop app and the IDE extension share this same language_server + channel; `bili antigravity-desktop` (#4675) drives the desktop binary + through the identical lane (below). +- **`bili antigravity-desktop`** — Google Antigravity **Desktop** (the IDE + app) (#4675). The desktop app spawns the *same* Go `language_server` as + `agy` and honors the identical `CLOUD_CODE_URL` hook, so this launcher + reuses the exact same env lane as `bili antigravity` — it only changes which + binary is spawned. It probes the standard desktop install paths (Windows + `%LOCALAPPDATA%\Programs\antigravity\Antigravity.exe`, then + `%PROGRAMFILES%\antigravity\Antigravity.exe`; macOS + `/Applications/Antigravity.app/Contents/MacOS/Antigravity`; Linux + `/usr/bin/antigravity`, then `~/.local/share/antigravity/antigravity`), and + a `--bin`/`BILI_CLIENT_BIN` override wins for custom locations. The desktop + is a single-instance app: if one is already running, the new process just + focuses the existing window and exits (which tears down the launcher's + proxy) — close any open Antigravity window first. To attach a + manually-started instance to a running `bili start` daemon instead: + `export CLOUD_CODE_URL="http://localhost:8787/bili/https://daily-cloudcode-pa.googleapis.com"` + and launch the app from that shell (or use the MITM recipe above). None of the four has a native mode: none exposes an in-loop tool injection seam (gemini-cli extensions reach custom commands only; the forks inherit diff --git a/docs/clients.zh-CN.md b/docs/clients.zh-CN.md index 24d9a97b65..eb5fe06099 100644 --- a/docs/clients.zh-CN.md +++ b/docs/clients.zh-CN.md @@ -77,8 +77,21 @@ language_server 遵循 `HTTPS_PROXY` 且不锁定证书,把 `daily-cloudcode-pa.googleapis.com`(Antigravity 真实默认端点;裸 `cloudcode-pa` 名称在 `/v1internal:*` 上 400,#3129)加进 `"mitm".domains` - 并信任 bili 根 CA 即可。桌面端与 IDE 扩展共用同一条 language_server 通道;启动器只驱动 - CLI —— 桌面用户可手动导出 `CLOUD_CODE_URL`,或直接用上面的 MITM 配方。 + 并信任 bili 根 CA 即可。桌面端与 IDE 扩展共用同一条 language_server 通道; + `bili antigravity-desktop`(#4675)通过完全相同的 lane 驱动桌面二进制(见下)。 + - **`bili antigravity-desktop`** —— Google Antigravity **桌面端**(IDE 应用) + (#4675)。桌面端启动的 Go `language_server` 与 `agy` 完全相同,遵循同一个 + `CLOUD_CODE_URL` 钩子,因此该启动器复用 `bili antigravity` 完全相同的环境 + lane —— 只是换掉被启动的二进制。它探测标准桌面安装路径(Windows 为 + `%LOCALAPPDATA%\Programs\antigravity\Antigravity.exe`,其次 + `%PROGRAMFILES%\antigravity\Antigravity.exe`;macOS 为 + `/Applications/Antigravity.app/Contents/MacOS/Antigravity`;Linux 为 + `/usr/bin/antigravity`,其次 `~/.local/share/antigravity/antigravity`);自定义 + 位置用 `--bin`/`BILI_CLIENT_BIN` 覆盖优先。桌面端是单实例应用:若已有实例在 + 运行,新进程只会聚焦已有窗口后退出(从而拆掉启动器的代理)—— 先关闭已打开的 + Antigravity 窗口。若要把手动启动的实例挂到运行中的 `bili start` 守护进程上: + `export CLOUD_CODE_URL="http://localhost:8787/bili/https://daily-cloudcode-pa.googleapis.com"`, + 再从该 shell 启动应用(或用上面的 MITM 配方)。 四者都没有 native 模式:均无环内工具注入接缝(gemini-cli 扩展只到自定义命令, fork 继承同一面;Antigravity 自带用户插件系统 —— `plugins//` 下的 diff --git a/src/cli.ts b/src/cli.ts index ae2e533fb3..995c395977 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -84,6 +84,7 @@ Usage: bili iflow [opts --] [args] start a proxy + launch iFlow CLI against it (IFLOW_BASE_URL /bili/ rewrite) bili qwen [opts --] [args] start a proxy + launch Qwen Code against it (cert-MITM) bili antigravity [opts --] [args] start a proxy + launch Antigravity CLI (agy) against it (CLOUD_CODE_URL /bili/ rewrite) + bili antigravity-desktop [opts --] [args] start a proxy + launch Antigravity Desktop (IDE) against it (same CLOUD_CODE_URL lane; probes desktop install paths) bili mcode [opts --] [args] start a proxy + launch MiniMax Code against it (cert-MITM) bili aider [opts --] [args] start a proxy + launch aider against it (cert-MITM) bili copilot [opts --] [args] start a proxy + launch Copilot CLI against it (cert-MITM) @@ -148,7 +149,7 @@ Usage: bili --version print version bili --help show this help -Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh / bili codebuddy / bili qoder / bili trae / bili jcode / bili kimi / bili gemini / bili iflow / bili qwen / bili antigravity / bili mcode / bili aider / bili copilot / bili amp / bili crush / bili zed / bili goose / bili kiro): +Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili hermes / bili dsh / bili codebuddy / bili qoder / bili trae / bili jcode / bili kimi / bili gemini / bili iflow / bili qwen / bili antigravity / bili antigravity-desktop / bili mcode / bili aider / bili copilot / bili amp / bili crush / bili zed / bili goose / bili kiro): Brings up a proxy on an independent port (a fresh instance every launch), then runs the client pointed at it via HTTPS_PROXY + the proxy's MITM CA — no config-file edits. Discovered HTTPS upstream domains are auto-whitelisted for MITM so the proxy TLS-terminates exactly the hosts the @@ -176,6 +177,7 @@ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili h bili iflow # launch iFlow CLI through the proxy (IFLOW_BASE_URL /bili/ rewrite of apis.iflow.cn/v1) bili qwen # launch Qwen Code through the proxy (cert-MITM; DashScope/Qwen gateways whitelisted by default, custom relays via --mitm-domain) bili antigravity # launch Antigravity CLI (agy) through the proxy (CLOUD_CODE_URL /bili/ rewrite of daily-cloudcode-pa.googleapis.com — real default upstream, #3129) + bili antigravity-desktop # launch Antigravity Desktop (IDE) through the proxy (same CLOUD_CODE_URL lane as the CLI; probes standard desktop install paths, #4675) bili mcode # launch MiniMax Code through the proxy (cert-MITM; provider hosts from ~/.minimax*/config.yaml or the official agent.minimax.* endpoints) bili aider # launch aider through the proxy (cert-MITM; endpoint from OPENAI_API_BASE/--openai-api-base/.aider.conf.yml or api.openai.com+api.anthropic.com by default) bili copilot # launch Copilot CLI through the proxy (cert-MITM; api.githubcopilot.com + plan subdomains whitelisted by default) diff --git a/src/launcher.ts b/src/launcher.ts index b09d4a80ad..5d9a7dbff8 100644 --- a/src/launcher.ts +++ b/src/launcher.ts @@ -169,7 +169,7 @@ import { conflictRemediation } from "./conflict-watch.js"; import { conflictScanEnabled, isDesignBenign, scanClientPlugins } from "./thirdparty-scan.js"; export const LAUNCHER_DEFAULT_HOST = "127.0.0.1"; -export const LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "codebuddy", "qoder", "trae", "jcode", "kimi", "gemini", "iflow", "qwen", "mcode", "aider", "copilot", "amp", "crush", "zed", "goose", "antigravity", "kiro", "pi-test", "pi-inline", "opencode-inline"] as const; +export const LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "codebuddy", "qoder", "trae", "jcode", "kimi", "gemini", "iflow", "qwen", "mcode", "aider", "copilot", "amp", "crush", "zed", "goose", "antigravity", "antigravity-desktop", "kiro", "pi-test", "pi-inline", "opencode-inline"] as const; export type ClientName = (typeof LAUNCH_CLIENTS)[number]; type BaseClientName = "claude" | "codex" | "pi" | "omp" | "opencode" | "hermes" | "dsh" | "codebuddy" | "qoder" | "trae" | "jcode" | "kimi" | "gemini" | "iflow" | "qwen" | "mcode" | "aider" | "copilot" | "amp" | "crush" | "zed" | "goose" | "antigravity" | "kiro"; @@ -377,7 +377,10 @@ export function isLaunchClient(value: string): value is ClientName { } export function baseClientName(client: ClientName): BaseClientName { - return client === "pi-test" || client === "pi-inline" ? "pi" : client === "opencode-inline" ? "opencode" : client; + return client === "pi-test" || client === "pi-inline" ? "pi" + : client === "opencode-inline" ? "opencode" + : client === "antigravity-desktop" ? "antigravity" + : client; } /** `pi-test` injects `--no-extensions` so the billion-context-pi client extension doesn't double-compress alongside the proxy. */ @@ -6700,10 +6703,34 @@ function probeInstalledBin(base: string, exts: readonly string[]): string { return base; } +// #4675: ordered candidate install locations for the Antigravity Desktop app +// (per the issue report). The desktop IDE spawns the same Go language_server as +// the agy CLI, so the CLOUD_CODE_URL lane is identical — only the binary path +// differs. First existing candidate wins. +function antigravityDesktopCandidates(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): string[] { + const home = os.homedir(); + if (platform === "win32") { + const localAppData = env.LOCALAPPDATA ?? path.join(home, "AppData", "Local"); + const programFiles = env.PROGRAMFILES ?? "C:\\Program Files"; + return [ + path.join(localAppData, "Programs", "antigravity", "Antigravity.exe"), + path.join(programFiles, "antigravity", "Antigravity.exe"), + ]; + } + if (platform === "darwin") { + return [path.join("/Applications", "Antigravity.app", "Contents", "MacOS", "Antigravity")]; + } + return [ + "/usr/bin/antigravity", + path.join(home, ".local", "share", "antigravity", "antigravity"), + ]; +} + export function resolveClientCommand( client: ClientName, env: NodeJS.ProcessEnv, platform: NodeJS.Platform = process.platform, + opts?: { desktop?: boolean }, ): { command: string; prefixArgs: string[] } { const binOverride = env.BILI_CLIENT_BIN?.trim(); if (binOverride) { @@ -6756,6 +6783,23 @@ export function resolveClientCommand( return { command: probeInstalledBin(binBase, platform === "win32" ? [".cmd", ".bat", ".exe", ""] : [""]), prefixArgs: [] }; } if (client === "antigravity") { + if (opts?.desktop) { + // #4675: the desktop IDE (+ its IDE extension) spawns the same closed + // Go language_server as the agy CLI and honors the same CLOUD_CODE_URL + // env override — the env lane is identical (buildAntigravityEnv); only + // the launched binary differs. Probe the standard desktop install + // locations (first existing wins; the bare first candidate is the + // ENOENT fallback so a clean error names the expected path). + const candidates = antigravityDesktopCandidates(env, platform); + for (const c of candidates) { + if (fs.existsSync(c)) return { command: c, prefixArgs: [] }; + } + console.error( + "bili: no Antigravity Desktop install found (looked at: " + candidates.join(", ") + + "). Pass --bin /path/to/Antigravity to launch a custom location.", + ); + return { command: candidates[0], prefixArgs: [] }; + } // #2115: the CLI binary is named `agy` (Gemini CLI successor), not // `antigravity`; install.sh places it at ~/.local/bin/agy (Windows: // %LOCALAPPDATA%\agy\bin\agy.exe). @@ -7697,7 +7741,12 @@ export async function runLaunch(params: RunLaunchParams, deps: LauncherDeps = {} } } - const { command, prefixArgs } = resolveClientCommand(base, process.env, deps.platform ?? process.platform); + const { command, prefixArgs } = resolveClientCommand( + base, + process.env, + deps.platform ?? process.platform, + { desktop: params.client === "antigravity-desktop" }, + ); const effectiveClientArgs = piTestArgs(params.client, clientArgs); let code = 0; try { diff --git a/tests/launcher-gemini-family.test.ts b/tests/launcher-gemini-family.test.ts index 15ec032179..be6363ee57 100644 --- a/tests/launcher-gemini-family.test.ts +++ b/tests/launcher-gemini-family.test.ts @@ -37,6 +37,12 @@ test("launch client registry includes antigravity (#2115)", () => { assert.ok(LAUNCH_CLIENTS.includes("antigravity")); }); +test("launch client registry includes antigravity-desktop alias → antigravity base (#4675)", () => { + assert.equal(isLaunchClient("antigravity-desktop"), true); + assert.equal(baseClientName("antigravity-desktop"), "antigravity"); + assert.ok(LAUNCH_CLIENTS.includes("antigravity-desktop")); +}); + test("discoverRoutes: gemini default → GOOGLE_GEMINI_BASE_URL /bili/ rewrite of generativelanguage", () => { assert.deepEqual(discoverRoutes("gemini", {}), { ...EMPTY_ROUTES, diff --git a/tests/launcher.test.ts b/tests/launcher.test.ts index f3705816a0..c31f8385e0 100644 --- a/tests/launcher.test.ts +++ b/tests/launcher.test.ts @@ -7724,6 +7724,76 @@ test("resolveClientCommand: antigravity/mcode honor the injectable platform para } }); +test("resolveClientCommand: antigravity-desktop probes standard desktop install paths (#4675)", () => { + const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-agydesk-home-")); + const localAppData = fs.mkdtempSync(path.join(os.tmpdir(), "bili-agydesk-lad-")); + const programFiles = fs.mkdtempSync(path.join(os.tmpdir(), "bili-agydesk-pf-")); + const prevHome = process.env.HOME; + const prevUserProfile = process.env.USERPROFILE; + try { + process.env.HOME = home; + // os.homedir() reads USERPROFILE on win32, not HOME — seal it so the + // non-win32 expectations hold on every host (CI runs on Windows). + if (prevUserProfile === undefined) delete process.env.USERPROFILE; + else process.env.USERPROFILE = home; + // win32: %LOCALAPPDATA%\Programs\antigravity\Antigravity.exe is preferred. + const winLocal = path.join(localAppData, "Programs", "antigravity", "Antigravity.exe"); + fs.mkdirSync(path.dirname(winLocal), { recursive: true }); + fs.writeFileSync(winLocal, ""); + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz", LOCALAPPDATA: localAppData, PROGRAMFILES: programFiles }, "win32", { desktop: true }), + { command: winLocal, prefixArgs: [] }, + ); + // win32: falls back to %PROGRAMFILES%\antigravity\Antigravity.exe when the + // LOCALAPPDATA candidate is absent (no LOCALAPPDATA in env → home fallback). + const winPf = path.join(programFiles, "antigravity", "Antigravity.exe"); + fs.mkdirSync(path.dirname(winPf), { recursive: true }); + fs.writeFileSync(winPf, ""); + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz", PROGRAMFILES: programFiles }, "win32", { desktop: true }), + { command: winPf, prefixArgs: [] }, + ); + // darwin: /Applications/Antigravity.app/Contents/MacOS/Antigravity (the + // bare first candidate is returned when the app is not installed). + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz" }, "darwin", { desktop: true }), + { command: "/Applications/Antigravity.app/Contents/MacOS/Antigravity", prefixArgs: [] }, + ); + // linux: /usr/bin/antigravity is the first candidate (returned when absent). + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz" }, "linux", { desktop: true }), + { command: "/usr/bin/antigravity", prefixArgs: [] }, + ); + // linux: falls back to ~/.local/share/antigravity/antigravity when + // /usr/bin/antigravity is absent. + const linuxLocal = path.join(home, ".local", "share", "antigravity", "antigravity"); + fs.mkdirSync(path.dirname(linuxLocal), { recursive: true }); + fs.writeFileSync(linuxLocal, ""); + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz" }, "linux", { desktop: true }), + { command: linuxLocal, prefixArgs: [] }, + ); + // BILI_CLIENT_BIN (--bin) override still wins for the desktop lane. + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz", BILI_CLIENT_BIN: "/custom/Antigravity" }, "win32", { desktop: true }), + { command: "/custom/Antigravity", prefixArgs: [] }, + ); + // the CLI lane is unchanged: without { desktop: true } it still resolves agy. + assert.deepEqual( + resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz", LOCALAPPDATA: localAppData }, "win32"), + { command: path.join(localAppData, "agy", "bin", "agy"), prefixArgs: [] }, + ); + } finally { + if (prevHome === undefined) delete process.env.HOME; + else process.env.HOME = prevHome; + if (prevUserProfile === undefined) delete process.env.USERPROFILE; + else process.env.USERPROFILE = prevUserProfile; + rmrf(home); + rmrf(localAppData); + rmrf(programFiles); + } +}); + test("runLaunch mcode: cert-MITM envs (combined CA on SSL_CERT_FILE + NODE_EXTRA_CA_CERTS), discovered host whitelist, model windows (#1050)", async () => { const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-mcode-launch-")); const prevHome = process.env.HOME; From 91d5cf076c67753ad202d263b1c18fb0c7b7289e Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 00:55:50 +0800 Subject: [PATCH 2/4] docs: align the antigravity README table row to column 0 (review nit, #6761) The antigravity row in the 'Pick by your client' table was indented one space relative to every other row; GFM still parses it, but the inconsistent indentation is diff noise. Review fix on PR #6761. (cherry picked from commit 16fe0c5e338b633323c6584a901c01fc1f6f8406) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e64547aff0..1da5bef0d7 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Pick by your client: | **gemini** (Gemini CLI) | `bili gemini` (launcher, `GOOGLE_GEMINI_BASE_URL` `/bili/` rewrite) or `/bili/` prefix — launcher-only (no in-loop tool seam, #1043) | | **iflow** (iFlow CLI) | `bili iflow` (launcher, `IFLOW_BASE_URL` `/bili/` rewrite) or `/bili/` prefix | | **qwen** (Qwen Code) | `bili qwen` (launcher, cert-MITM) or `/bili/` prefix | - | **antigravity** (Antigravity CLI / agy + Desktop IDE, Google) | `bili antigravity` (CLI; launcher, `CLOUD_CODE_URL` `/bili/` rewrite of daily-cloudcode-pa.googleapis.com — Antigravity's real default upstream, #3129) or `bili antigravity-desktop` (Desktop IDE; same `CLOUD_CODE_URL` lane, probes desktop install paths, #4675) or `/bili/` prefix — no plugin seam (closed Go language_server; its user-plugin surface is additive-only, #2115) — details: [docs/clients.md](docs/clients.md) | +| **antigravity** (Antigravity CLI / agy + Desktop IDE, Google) | `bili antigravity` (CLI; launcher, `CLOUD_CODE_URL` `/bili/` rewrite of daily-cloudcode-pa.googleapis.com — Antigravity's real default upstream, #3129) or `bili antigravity-desktop` (Desktop IDE; same `CLOUD_CODE_URL` lane, probes desktop install paths, #4675) or `/bili/` prefix — no plugin seam (closed Go language_server; its user-plugin surface is additive-only, #2115) — details: [docs/clients.md](docs/clients.md) | | **mcode** (MiniMax Code) | [`billion-context`](https://github.com/ranxianglei/billion-context) via `bili mcode` (cert-MITM) or `/bili/` prefix — no native mode (event hooks only, no model-request seam, [#1050](https://github.com/ranxianglei/billion-context/issues/1050)) | | **aider** | [`billion-context`](https://github.com/ranxianglei/billion-context) via `bili aider` (cert-MITM) or `/bili/` prefix — no native mode (shell-command-only hooks, no tool-injection seam, [#1048](https://github.com/ranxianglei/billion-context/issues/1048)) | | **copilot** (GitHub Copilot CLI) | `bili copilot` (launcher, cert-MITM) — closed Go binary, no plugin seam (#1049) | From 2eb0932d8f2365d592c6f958cbf088e8c9590c0a Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 01:10:10 +0800 Subject: [PATCH 3/4] test: build the darwin desktop-path expectation with path.join (#6761) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI (windows-latest, node 22) failed the new antigravity-desktop test: the production darwin branch builds its candidate with path.join, which yields backslashes on a win32 runner, while the test compared against a hardcoded forward-slash literal. Build the expectation with path.join (the same host-independent pattern as the #2260 test in this file) so the injected-platform assertion holds on every host. Production behavior is unchanged — the darwin branch only ever runs on darwin. (cherry picked from commit 516bcba4c45e54874ef0a7567db2514d74577fe2) --- tests/launcher.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/launcher.test.ts b/tests/launcher.test.ts index c31f8385e0..b44b9642d1 100644 --- a/tests/launcher.test.ts +++ b/tests/launcher.test.ts @@ -7755,9 +7755,13 @@ test("resolveClientCommand: antigravity-desktop probes standard desktop install ); // darwin: /Applications/Antigravity.app/Contents/MacOS/Antigravity (the // bare first candidate is returned when the app is not installed). + // Expected value built with path.join (same as the #2260 test) so the + // host-independent platform injection holds on Windows runners too — + // the production darwin branch path.joins, which yields backslashes + // on a win32 host. assert.deepEqual( resolveClientCommand("antigravity", { PATH: "/nonexistent-dir-zzz" }, "darwin", { desktop: true }), - { command: "/Applications/Antigravity.app/Contents/MacOS/Antigravity", prefixArgs: [] }, + { command: path.join("/Applications", "Antigravity.app", "Contents", "MacOS", "Antigravity"), prefixArgs: [] }, ); // linux: /usr/bin/antigravity is the first candidate (returned when absent). assert.deepEqual( From d8f99c524a8f40d8d4a1c74ab2bce781db82f233 Mon Sep 17 00:00:00 2001 From: ci-check Date: Mon, 16 Nov 2026 15:41:22 +0800 Subject: [PATCH 4/4] fix: pin the absolute node path in zcode hook/MCP entries (#6891) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `bili plugin install zcode` wrote a bare `node` as the spawn command for both the SessionStart hook and the stdio MCP server in ~/.zcode/cli/config.json. The ZCode binary executes that JSON command directly (no shell), so the token only resolves through the client process's own PATH — when node is not there the spawn dies silently, the MCP handshake collapses, and compression never activates while `bili doctor` still reports ok. The bare-`node` shape came from the #1902 rule, which exists for the SHELL-STRING hooks (claude/kimi) where a spaced command token breaks PowerShell/cmd parsing; it does not apply to a JSON args array. - applyZcodeManagedConfig takes nodeCommand; zcodeInstall passes process.execPath (the node bili itself runs under). - doctor probe: an absolute spawn command becomes an existence-checked target (node binary gone → broken); a bare token becomes an advisory warning (the lane still works when node IS on the client PATH) — verdict unchanged, surfaced via LanePresence.spawnWarnings → DoctorLane.warnings. - Reinstall self-heals pre-fix bare-`node` entries (ownership detection matches args, not command). - Docs (en/zh/ja) updated to describe the pinned absolute node path. (cherry picked from commit fe102ad92d92c660283c2aca1ffd15e34256a743) --- docs/clients.ja.md | 2 +- docs/clients.md | 8 +- docs/clients.zh-CN.md | 2 +- src/doctor.ts | 5 + src/plugin-install.ts | 50 ++++++- tests/plugin-install-zcode.test.ts | 202 +++++++++++++++++++++++++++++ 6 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 tests/plugin-install-zcode.test.ts diff --git a/docs/clients.ja.md b/docs/clients.ja.md index 7e77d8f350..8d9764fb8b 100644 --- a/docs/clients.ja.md +++ b/docs/clients.ja.md @@ -50,7 +50,7 @@ 整列した 3 つのモード:`/bili/` URL プレフィックス、GUI の Settings → Network(HTTP プロキシ + ルート CA パス)を通じた cert-MITM、ネイティブプラグインモード(`bili plugin install zcode`、#1145)。ZCode のエクステンション表面は Claude-Code 形状ですが宣言型です:`~/.zcode/cli/config.json` のユーザーレベルフックと stdio MCP サーバー、プロセス内 JS シームなし。そのためネイティブレーンはクライアントの周りで仕事をこなす小さな node スクリプトを 2 つ同梱します: -- **インストール:** `bili plugin install zcode` は `~/.zcode/cli/config.json` を書き、`hooks.enabled = true` を設定し、`SessionStart` プロセスフック(`node /dist/zcode/bootstrap-hook.js`)を追加し、stdio MCP サーバー `mcp.servers.bili`(`node /dist/zcode/mcp-entry.js`)を登録します。既存のユーザー所有 `mcp.servers.bili` エントリは決して上書きされません — インストーラは代わりに明白に拒否します。インストール時に URL は凍結されません;ルーティングはセッションごとに行われます。削除は `bili plugin remove zcode`(bili のエントリのみを取り除き、自分が有効にしたものなら `hooks.enabled` を戻し、スナップショットからプロバイダーストアを復元)。 +- **インストール:** `bili plugin install zcode` は `~/.zcode/cli/config.json` を書き、`hooks.enabled = true` を設定し、`SessionStart` プロセスフック(` /dist/zcode/bootstrap-hook.js`)を追加し、stdio MCP サーバー `mcp.servers.bili`(` /dist/zcode/mcp-entry.js`)を登録します。ここで `` は bili が動作している node バイナリの**絶対パス**です — ZCode は JSON の `command` を直接 spawn するため(shell を介さない)、素の `node` はクライアント自身の PATH でのみ解決され、PATH に node が無い場合は spawn が無言で失敗します(#6891)。既存のユーザー所有 `mcp.servers.bili` エントリは決して上書きされません — インストーラは代わりに明白に拒否します。インストール時に URL は凍結されません;ルーティングはセッションごとに行われます。削除は `bili plugin remove zcode`(bili のエントリのみを取り除き、自分が有効にしたものなら `hooks.enabled` を戻し、スナップショットからプロバイダーストアを復元)。 - **削除後のオープンセッション (#2155):** `bili plugin remove zcode` はすでに開かれたクライアントウィンドウの中までは到達できません — その MCP 子プロセスは消えたが、プロキシ側のバインド(セッションメタデータ)は生き残っています。そのようなゾンビセッションは、プラグインヘッダなし・ワイヤ上に bili ツールなし・圧縮なしの nudge 付きラウンドが 5 回連続したあとに検出されます:セッションは**proxy モードへの退化**によって自己修復します — ACP ツールは wire 側に再注入され、プロキシが再び圧縮を所有する(nudge は残る)。wire 注入が利用不可(`compress.injectTool=false`)の場合、nudge は圧縮削減が再開するまで代わりに抑制されます。戻ってきたプラグインヘッダ(クライアント再起動 / 再インストール)は最初の要求でプラグインモードを回復します。削除コマンドは直近 10 分間にライブセッションが見られたら注記を表示します;web UI はそうしたセッションにバッジ(「heal」)を付けます。 - **セッションごとのブートストラップ:** 各 ZCode セッションは MCP 子プロセスを直接のプロセスとして spawn します;起動時に健康なプロキシ(`BILLION_CONTEXT_PROXY`)に取り付いたり、エフェメラルポートで独自のものを spawn したりしてから、mkdir ロックファイル下で冪等な JSON サージェリーによりアクティブなプロバイダーストアを書き換えます:ルーティング可能な各プロバイダーストアエントリの `baseURL` が `http://127.0.0.1:/bili/` になる(自分で設定した任意の baseURL はラッパーの後ろにそのまま保持)。両方のストア世代に対応します:レガシー `~/.zcode/v2/config.json`(`provider..options.baseURL`)と v3.14+ のパーソナルストア `~/.zcode/v2/provider_config.json`(`config.providerConfigRules.providerRules[].config.api.baseUrl`)— 両方が存在するなら新しいストアが優先(どのエントリがルーティングされ、どれがスキップされるかは Routing scope を参照)。元のファイルはユーザー編集ごとに一度だけ `.bili-bak` にスナップショットされます(スナップショットは常にあなたの最後の実際の状態を反映し、決して bili 自身の書き込みを反映しない);他のすべてのキーはバイト単位で同一。レガシー世代のクライアントは起動時にプロバイダ設定を読み込むため、インストール後に ZCode を一度再起動してください;新しいビルドはセッション中にルーティング変更を取得します(約 1 秒ポーリング)。`SessionStart` フックは同じブートストラップを機会的に実行します(attach のみ — spawn は絶対にしない);その非ブロッキングな競合は設計上許容されます:ラウンド 1 が wire モードに乗ってもよく、不変条件は `baseURL` を死んだポートに向けないことです。 - **プラグインモード押印:** MCP 子プロセスが ACP ツールリストを生きたプロキシのマニフェストと照合して検証したら、ルーティングされたエントリに `headers["x-bili-plugin"] = "zcode"` が加わります — それまではトラフィックは wire モードに乗ります。ツール呼び出しは呼び出しごとの `conversation_id` 引数でバインドされます (#760)。 diff --git a/docs/clients.md b/docs/clients.md index 7849307689..9c086e9f53 100644 --- a/docs/clients.md +++ b/docs/clients.md @@ -373,8 +373,12 @@ two small node scripts that do the work around the client: - **Install:** `bili plugin install zcode` writes `~/.zcode/cli/config.json`: sets `hooks.enabled = true`, appends a `SessionStart` process hook - (`node /dist/zcode/bootstrap-hook.js`) and registers a stdio MCP - server `mcp.servers.bili` (`node /dist/zcode/mcp-entry.js`). A + (` /dist/zcode/bootstrap-hook.js`) and registers a stdio MCP + server `mcp.servers.bili` (` /dist/zcode/mcp-entry.js`), where + `` is the ABSOLUTE path of the node binary bili runs under — ZCode + spawns the JSON `command` directly (no shell), so a bare `node` only + resolves through the client's own PATH and the spawn dies silently when + node is not there (#6891). A pre-existing user-owned `mcp.servers.bili` entry is never overwritten — the installer refuses loudly instead. No URL is frozen at install time; routing happens per session. Remove with `bili plugin remove zcode` (strips only diff --git a/docs/clients.zh-CN.md b/docs/clients.zh-CN.md index eb5fe06099..6ab1e9797a 100644 --- a/docs/clients.zh-CN.md +++ b/docs/clients.zh-CN.md @@ -113,7 +113,7 @@ fork 继承同一面;Antigravity 自带用户插件系统 —— `plugins/ 三种对齐模式:`/bili/` URL 前缀、GUI「设置 → 网络」证书 MITM(HTTP 代理 + 根 CA 路径)、原生插件模式(`bili plugin install zcode`,#1145)。ZCode 的扩展面是 Claude-Code 形状但纯声明式:`~/.zcode/cli/config.json` 里的用户级 hooks 与 stdio MCP server,没有进程内 JS 接缝。所以原生通道随包带两个小 node 脚本,在客户端外围干活: -- **安装:** `bili plugin install zcode` 写 `~/.zcode/cli/config.json`:置 `hooks.enabled = true`、追加一条 `SessionStart` process hook(`node /dist/zcode/bootstrap-hook.js`)、注册 stdio MCP server `mcp.servers.bili`(`node /dist/zcode/mcp-entry.js`)。已存在的用户自有 `mcp.servers.bili` 条目**绝不覆盖** —— 安装器会响亮地拒绝。安装时不冻结任何 URL;路由按会话发生。卸载:`bili plugin remove zcode`(只剥离 bili 自己的条目、由 bili 启用的 `hooks.enabled` 予以还原、provider store 从快照恢复)。 +- **安装:** `bili plugin install zcode` 写 `~/.zcode/cli/config.json`:置 `hooks.enabled = true`、追加一条 `SessionStart` process hook(` /dist/zcode/bootstrap-hook.js`)、注册 stdio MCP server `mcp.servers.bili`(` /dist/zcode/mcp-entry.js`),其中 `` 是 bili 所运行的 node 二进制的**绝对路径**——ZCode 直接 spawn JSON 里的 `command`(无 shell),裸 `node` 只能靠客户端自己的 PATH 解析,PATH 里没有 node 时 spawn 会静默失败(#6891)。已存在的用户自有 `mcp.servers.bili` 条目**绝不覆盖** —— 安装器会响亮地拒绝。安装时不冻结任何 URL;路由按会话发生。卸载:`bili plugin remove zcode`(只剥离 bili 自己的条目、由 bili 启用的 `hooks.enabled` 予以还原、provider store 从快照恢复)。 - **卸载后的已开会话(#2155):**`bili plugin remove zcode` 无法触及已开着的客户端窗口 —— 它们的 MCP 子进程已死,但代理侧的会话绑定(session metadata)仍在。这类僵尸会话在连续 5 轮“有 nudge、无插件头、线上无 bili 工具、零压缩”后被检测到,随即**自愈降级为代理模式** —— ACP 工具改由代理线上回注、压缩重新由代理接管(nudge 保留)。若线上注入不可用(`compress.injectTool=false`)则改为静默 nudge,直到出现一次压缩缩减自动解除。插件头重现(客户端重启/重装)即在同一请求内恢复 plugin 模式。remove 命令在近 10 分钟内见过活跃会话时会打印提示;web UI 会为这类会话挂“自愈”徽标。 - **每会话自举:** 每个 ZCode 会话把 MCP 子进程作为直接子进程拉起;启动时附着到健康代理(`BILLION_CONTEXT_PROXY`)或在临时端口自拉起,然后在 mkdir 锁文件下对生效的 provider store 做幂等 JSON 手术:每个可路由 provider 条目的 `baseURL` 变为 `http://127.0.0.1:/bili/<上游>`(你设的自定义 baseURL 原样保留在包装之内)。两代 store 都处理:legacy `~/.zcode/v2/config.json`(`provider..options.baseURL`)与 v3.14+ personal store `~/.zcode/v2/provider_config.json`(`config.providerConfigRules.providerRules[].config.api.baseUrl`)—— 两者并存时以新 store 为准(其中哪些条目路由、哪些被跳过见下方路由范围)。原始文件按每次用户编辑快照到 `.bili-bak`(快照永远反映你最后一次真实状态,绝不记录 bili 自己的写入);其余所有键逐字节保留。旧世代客户端在启动时加载 provider 配置 —— 安装后重启一次 ZCode;新版构建可在会话中途感知路由变化(约 1 s 轮询)。`SessionStart` hook 机会性地跑同一套自举(仅附着 —— 绝不 spawn);它的非阻塞竞态被设计为可容忍:第一轮可以走 wire 模式,不变量是 `baseURL` 永不指向死端口。 - **Plugin 模式盖章:** MCP 子进程对着存活代理清单核验 ACP 工具列表之后,才给路由条目加 `headers["x-bili-plugin"] = "zcode"` —— 此前流量走 wire 模式。工具调用经每次调用的 `conversation_id` 参数绑定(#760)。 diff --git a/src/doctor.ts b/src/doctor.ts index c23cae3c9e..0068d960d2 100644 --- a/src/doctor.ts +++ b/src/doctor.ts @@ -285,6 +285,11 @@ function laneRowsFor(agent: PluginAgent, presence: ReturnType 0, frozen: false, copyVersion: presence.copyVersion, registryVersion }), }; if (row.verdict === "broken") row.reason = missingTargets.map((t) => `target missing: ${t}`).join("; "); + if (presence.spawnWarnings !== undefined && presence.spawnWarnings.length > 0) { + // #6891: advisory spawn-command notes (e.g. zcode's bare-`node` entries) + // — the lane may still work, so they never touch the verdict. + row.warnings = [...(row.warnings ?? []), ...presence.spawnWarnings]; + } if (agent === "opencode" && presence.installed && presence.form === "npm") { // #1234/#2199: the cache copy is bili-owned in place (self-updates via its // own proxy) — show the actual load path + disk version when resolvable so diff --git a/src/plugin-install.ts b/src/plugin-install.ts index 3e46c60eed..9ee6eed584 100644 --- a/src/plugin-install.ts +++ b/src/plugin-install.ts @@ -1987,8 +1987,13 @@ function isOursZcodeMcpServer(server: unknown): boolean { /** Managed-block apply for ~/.zcode/cli/config.json (#1145). Pure over the * parsed doc: enables hooks, upserts our SessionStart entry, and owns ONLY * mcp.servers.bili when it already points at our dist — a user's own "bili" - * server throws instead of being clobbered (§7.3). */ -function applyZcodeManagedConfig(doc: Record, opts: { hookEntry: string; mcpEntry: string }): { data: Record; notes: string[] } { + * server throws instead of being clobbered (§7.3). + * + * nodeCommand is the ABSOLUTE node path (#6891): the ZCode binary spawns this + * JSON command directly — no shell — so a bare `node` only resolves through + * the client process's own PATH, which need not include node. The #1902 + * bare-node rule is for the shell-string hooks (claude/kimi) only. */ +function applyZcodeManagedConfig(doc: Record, opts: { hookEntry: string; mcpEntry: string; nodeCommand: string }): { data: Record; notes: string[] } { const data = structuredClone(doc); const notes: string[] = []; const hooks = zcodeAsPlain(data.hooks) ?? {}; @@ -2000,7 +2005,7 @@ function applyZcodeManagedConfig(doc: Record, opts: { hookEntry const sessionStart = Array.isArray(events.SessionStart) ? [...(events.SessionStart as unknown[])] : []; const kept = sessionStart.filter((e) => !isOursZcodeHookEntry(e)); if (kept.length !== sessionStart.length) notes.push("replaced a previous bili SessionStart entry"); - kept.push({ hooks: [{ type: "process", command: "node", args: [opts.hookEntry] }] }); + kept.push({ hooks: [{ type: "process", command: opts.nodeCommand, args: [opts.hookEntry] }] }); events.SessionStart = kept; hooks.events = events; data.hooks = hooks; @@ -2009,7 +2014,7 @@ function applyZcodeManagedConfig(doc: Record, opts: { hookEntry if (servers.bili !== undefined && !isOursZcodeMcpServer(servers.bili)) { throw new Error(`${zcodeUserConfigFile()} already defines mcp.servers.bili owned by something else — rename or remove it first; refusing to overwrite`); } - servers.bili = { type: "stdio", command: "node", args: [opts.mcpEntry] }; + servers.bili = { type: "stdio", command: opts.nodeCommand, args: [opts.mcpEntry] }; mcp.servers = servers; data.mcp = mcp; return { data, notes }; @@ -2052,7 +2057,7 @@ function zcodeInstall(): string { requireDistFile(hookEntry); requireDistFile(mcpEntry); const file = zcodeUserConfigFile(); - const { data, notes } = applyZcodeManagedConfig(readJson(file), { hookEntry, mcpEntry }); + const { data, notes } = applyZcodeManagedConfig(readJson(file), { hookEntry, mcpEntry, nodeCommand: process.execPath }); writeJson(file, data); return `wrote the billion-context hook+MCP into ${file}${notes.length > 0 ? ` (${notes.join("; ")})` : ""} — start a new ZCode session to activate`; } @@ -2116,6 +2121,10 @@ interface LanePresence { form: "npm" | "local-path" | "managed-block" | "none"; copyVersion?: string; profiles?: Array<{ name: string; spec?: string; pinned: boolean; bundleInstalled: boolean; copyVersion?: string }>; + /** Advisory spawn-command notes (e.g. a bare PATH-resolved token the + * client may not resolve, #6891) — surfaced as doctor warnings; they + * never change the verdict. */ + spawnWarnings?: string[]; } function laneAbsent(): LanePresence { @@ -2431,14 +2440,41 @@ export function inspectLanePresence(agent: PluginAgent): LanePresence { if (path.isAbsolute(a) && /\.(js|ts)$/.test(a)) out.targets.push(a); } }; + // #6891: the entry's spawn command is what the ZCode binary executes. + // Absolute → existence-checked target (node binary gone → broken verdict); + // bare token → resolved through the CLIENT process's PATH, which we cannot + // inspect — advisory warning only, the lane still works when node IS on + // that PATH, so the verdict must not flip. + const checkCommand = (face: string, command: unknown): void => { + if (typeof command !== "string" || command.length === 0) return; + if (path.isAbsolute(command)) { + if (!out.targets.includes(command)) out.targets.push(command); + } else { + out.spawnWarnings = [...(out.spawnWarnings ?? []), `${face} command "${command}" is a bare PATH-resolved token — if node is not on the ZCode process's PATH the spawn dies silently and compression never activates; rerun 'bili plugin install zcode' to pin the absolute node path (#6891)`]; + } + }; + // dist args first (targets[0] must stay a dist entry — rootFromDistFile + // derives the install root from it), node commands after. + const commands: Array<[string, unknown]> = []; if (Array.isArray(sessionStart)) { for (const e of sessionStart as unknown[]) { if (!isOursZcodeHookEntry(e)) continue; const hooks = zcodeAsPlain(e)?.hooks; - if (Array.isArray(hooks)) for (const h of hooks as unknown[]) collectArgs(zcodeAsPlain(h)?.args); + if (Array.isArray(hooks)) { + for (const h of hooks as unknown[]) { + const hh = zcodeAsPlain(h); + collectArgs(hh?.args); + commands.push(["SessionStart hook", hh?.command]); + } + } } } - if (hasMcp) collectArgs(zcodeAsPlain(mcpBili)?.args); + if (hasMcp) { + const s = zcodeAsPlain(mcpBili); + collectArgs(s?.args); + commands.push(["MCP server", s?.command]); + } + for (const [face, command] of commands) checkCommand(face, command); const first = out.targets[0]; if (first !== undefined) out.copyVersion = pkgVersionAt(rootFromDistFile(first)); return out; diff --git a/tests/plugin-install-zcode.test.ts b/tests/plugin-install-zcode.test.ts new file mode 100644 index 0000000000..5c1f8fa2db --- /dev/null +++ b/tests/plugin-install-zcode.test.ts @@ -0,0 +1,202 @@ +// #6891: `bili plugin install zcode` must pin the ABSOLUTE node path into the +// managed hook/MCP entries — the ZCode binary spawns the JSON config's +// `command` directly (no shell), so a bare `node` only resolves through the +// client process's own PATH, which need not include node. The doctor probe +// must surface pre-fix bare-`node` entries as an advisory (the lane still +// works when node IS on the client PATH) and existence-check absolute ones. + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { inspectLanePresence, pluginInstall, selfPackageRoot } from "../src/plugin-install.ts"; +import { renderDoctorReport, runDoctor } from "../src/doctor.ts"; +import { rmrf } from "./tmp-rm.ts"; + +function tempDir(prefix: string): string { + return fs.mkdtempSync(path.join(os.tmpdir(), prefix)); +} + +function withHome(t: import("node:test").TestContext, home: string): void { + const prevHome = process.env.HOME; + const prevUp = process.env.USERPROFILE; + process.env.HOME = home; + // Windows os.homedir() resolves through USERPROFILE, not HOME — mirror the + // sandboxed HOME there or real-machine config (~/.zcode) leaks in. + if (process.platform === "win32") process.env.USERPROFILE = home; + t.after(() => { + if (prevHome === undefined) delete process.env.HOME; + else process.env.HOME = prevHome; + if (prevUp === undefined) delete process.env.USERPROFILE; + else process.env.USERPROFILE = prevUp; + rmrf(home); + }); +} + +type ZcodeCfg = { + hooks?: { enabled?: boolean; events?: { SessionStart?: unknown[] } }; + mcp?: { servers?: Record }; +}; + +const hookEntry = (): string => path.join(selfPackageRoot(), "dist", "zcode", "bootstrap-hook.js"); +const mcpEntry = (): string => path.join(selfPackageRoot(), "dist", "zcode", "mcp-entry.js"); + +function ourHookCommand(doc: ZcodeCfg): string | undefined { + const entries = doc.hooks?.events?.SessionStart ?? []; + for (const e of entries) { + const hooks = (e as { hooks?: Array<{ command?: string; args?: string[] }> })?.hooks; + if (Array.isArray(hooks) && hooks.some((h) => (h.args ?? []).some((a) => /zcode[\\/]bootstrap-hook\.(js|ts)$/.test(a)))) { + return hooks[0]?.command as string | undefined; + } + } + return undefined; +} + +test("#6891: plugin install zcode pins the absolute node path in hook + MCP entries", (t) => { + const home = tempDir("bili-zcode-inst-"); + withHome(t, home); + const out = pluginInstall("zcode"); + assert.match(out, /wrote the billion-context hook\+MCP into/); + const doc = JSON.parse(fs.readFileSync(path.join(home, ".zcode", "cli", "config.json"), "utf8")) as ZcodeCfg; + assert.equal(doc.hooks?.enabled, true); + assert.equal(ourHookCommand(doc), process.execPath); + assert.ok(path.isAbsolute(ourHookCommand(doc)!), "hook command must be absolute"); + assert.deepEqual(doc.mcp?.servers?.bili, { type: "stdio", command: process.execPath, args: [mcpEntry()] }); +}); + +test("#6891: reinstall upgrades a pre-fix bare-`node` entry to the absolute node path", (t) => { + const home = tempDir("bili-zcode-heal-"); + withHome(t, home); + const file = path.join(home, ".zcode", "cli", "config.json"); + fs.mkdirSync(path.dirname(file), { recursive: true }); + fs.writeFileSync(file, JSON.stringify({ + hooks: { enabled: true, events: { SessionStart: [{ hooks: [{ type: "process", command: "node", args: [hookEntry()] }] }] } }, + mcp: { servers: { bili: { type: "stdio", command: "node", args: [mcpEntry()] } } }, + }, null, 2)); + const out = pluginInstall("zcode"); + assert.match(out, /replaced a previous bili SessionStart entry/); + const doc = JSON.parse(fs.readFileSync(file, "utf8")) as ZcodeCfg; + assert.equal(ourHookCommand(doc), process.execPath); + assert.equal(doc.mcp?.servers?.bili?.command, process.execPath); +}); + +test("#6891: a foreign mcp.servers.bili is still refused (§7.3)", (t) => { + const home = tempDir("bili-zcode-foreign-"); + withHome(t, home); + const file = path.join(home, ".zcode", "cli", "config.json"); + fs.mkdirSync(path.dirname(file), { recursive: true }); + fs.writeFileSync(file, JSON.stringify({ mcp: { servers: { bili: { type: "stdio", command: "node", args: ["/opt/user-mcp/bili.js"] } } } }, null, 2)); + assert.throws(() => pluginInstall("zcode"), /already defines mcp\.servers\.bili owned by something else/); +}); + +// Hermetic dist stand-ins: the probe's targets point at sandbox files, so the +// tests never depend on whether the repo's dist/ is built. +function sandboxZcodeConfig(home: string, command: string): { hookEntry: string; mcpEntry: string } { + const root = path.join(home, "bili-root"); + const hook = path.join(root, "dist", "zcode", "bootstrap-hook.js"); + const mcp = path.join(root, "dist", "zcode", "mcp-entry.js"); + fs.mkdirSync(path.dirname(hook), { recursive: true }); + fs.writeFileSync(hook, ""); + fs.writeFileSync(mcp, ""); + fs.mkdirSync(path.join(home, ".zcode", "cli"), { recursive: true }); + fs.writeFileSync(path.join(home, ".zcode", "cli", "config.json"), JSON.stringify({ + hooks: { enabled: true, events: { SessionStart: [{ hooks: [{ type: "process", command, args: [hook] }] }] } }, + mcp: { servers: { bili: { type: "stdio", command, args: [mcp] } } }, + }, null, 2)); + return { hookEntry: hook, mcpEntry: mcp }; +} + +test("#6891: doctor probe — bare-`node` entries warn (advisory), absolute node path is an existence-checked target", (t) => { + const home = tempDir("bili-zcode-probe-"); + withHome(t, home); + + const { hookEntry: hook, mcpEntry: mcp } = sandboxZcodeConfig(home, "node"); + let p = inspectLanePresence("zcode"); + assert.equal(p.installed, true); + assert.equal(p.spawnWarnings?.length, 2, `expected 2 spawn warnings, got ${JSON.stringify(p.spawnWarnings)}`); + assert.match(p.spawnWarnings![0], /SessionStart hook command "node" is a bare PATH-resolved token/); + assert.match(p.spawnWarnings![0], /#6891/); + assert.match(p.spawnWarnings![1], /MCP server command "node" is a bare PATH-resolved token/); + // dist entries stay the targets; the bare node command is NOT one + assert.deepEqual(p.targets, [hook, mcp]); + + sandboxZcodeConfig(home, process.execPath); + p = inspectLanePresence("zcode"); + assert.equal(p.installed, true); + assert.equal(p.spawnWarnings, undefined, "absolute node path must not warn"); + assert.deepEqual(p.targets, [hook, mcp, process.execPath]); +}); + + + +function mockFetch(handler: (url: string) => Response | Promise): (fn: () => Promise) => Promise { + const original = globalThis.fetch; + return (fn) => { + globalThis.fetch = ((url: unknown) => Promise.resolve(handler(String(url)))) as unknown as typeof fetch; + return fn().finally(() => { + globalThis.fetch = original; + }); + }; +} + +function doctorSandboxEnv(base: string): Record { + return { + HOME: path.join(base, "home"), + XDG_CONFIG_HOME: path.join(base, "xdg-config"), + XDG_DATA_HOME: path.join(base, "xdg-data"), + XDG_CACHE_HOME: path.join(base, "xdg-cache"), + XDG_STATE_HOME: path.join(base, "xdg-state"), + PI_CODING_AGENT_DIR: undefined, PI_HOME: undefined, DSH_HOME: undefined, HERMES_HOME: undefined, + KIMI_CODE_HOME: undefined, CODEX_HOME: undefined, CLAUDE_CONFIG_DIR: undefined, OPENCODE_CONFIG: undefined, + }; +} + +test("#6891: runDoctor — bare-`node` zcode lane keeps its verdict and gains an advisory warning", async (t) => { + const base = tempDir("bili-zcode-doctor-"); + const runWithFetch = mockFetch(() => new Response(JSON.stringify({ name: "billion-context", version: "999.0.0" }), { status: 200, headers: { "Content-Type": "application/json" } })); + try { + await runWithFetch(async () => { + const prev = process.env; + const saved: Record = {}; + for (const [k, v] of Object.entries(doctorSandboxEnv(base))) { + saved[k] = prev[k]; + if (v === undefined) delete prev[k]; + else prev[k] = v; + } + if (process.platform === "win32") prev.USERPROFILE = prev.HOME; + t.after(() => { + for (const [k, v] of Object.entries(saved)) { + if (v === undefined) delete prev[k]; + else prev[k] = v; + } + }); + const home = path.join(base, "home"); + + sandboxZcodeConfig(home, "node"); + const bare = await runDoctor({ packageName: "billion-context", runningVersion: "0.1.143" }); + const zc = bare.lanes.find((l) => l.agent === "zcode"); + assert.ok(zc, "zcode lane present"); + // the warning must NOT change the verdict: targets exist, so ok + assert.equal(zc?.verdict, "ok", `bare-node is advisory, got ${JSON.stringify(zc)}`); + assert.ok(zc?.warnings?.some((w) => w.includes('command "node"') && w.includes("#6891")), `expected bare-node warning, got ${JSON.stringify(zc?.warnings)}`); + assert.match(renderDoctorReport(bare), /⚠️ .*command "node" is a bare PATH-resolved token/); + + sandboxZcodeConfig(home, process.execPath); + const fixed = await runDoctor({ packageName: "billion-context", runningVersion: "0.1.143" }); + const zf = fixed.lanes.find((l) => l.agent === "zcode"); + assert.equal(zf?.verdict, "ok"); + assert.equal(zf?.warnings, undefined, "fixed install must not warn"); + + // an absolute node command that is gone on disk IS a real defect + const ghost = path.join(home, "gone-node"); + sandboxZcodeConfig(home, ghost); + const gone = await runDoctor({ packageName: "billion-context", runningVersion: "0.1.143" }); + const zg = gone.lanes.find((l) => l.agent === "zcode"); + assert.equal(zg?.verdict, "broken", `missing node binary must break the lane, got ${JSON.stringify(zg)}`); + assert.match(zg?.reason ?? "", new RegExp(`target missing: .*gone-node`)); + }); + } finally { + rmrf(base); + } +});