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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag
- **Fix: the Vertex managed block no longer wraps its own value.** `bili install claude` pins `ANTHROPIC_VERTEX_BASE_URL`, and the next derivation read that value back — the settings `env` block reaches the client process, which `readClaudeSettings` falls back to — wrapped it again, and added a `/bili/anthropic/` layer per launch. The extra hop targets the proxy's own port, which the tunnel guard denies (`403 detail:"self"`), so the lane died on the second start. Both derivations (`claudeNativeVertexBaseUrl` in `src/plugin-install.ts`, `claudeVertexUpstream` in `src/launcher.ts`) now collapse any nesting of bili's own wrapper first (`stripBiliWrappers`, `src/vertex.ts`) and are idempotent on their own output; a user's own endpoint behind a wrapper is preserved intact. The same pass closes an install/remove asymmetry: `bili plugin remove claude` now takes `ANTHROPIC_VERTEX_BASE_URL` back when it is ours (a foreign endpoint is left alone, as at install).
- **Claude Code on Vertex AI (`CLAUDE_CODE_USE_VERTEX=1`) is routed through bili.** Under Vertex the plain `ANTHROPIC_BASE_URL` is inert — the client dials `<ANTHROPIC_VERTEX_BASE_URL>/projects/…:rawPredict|streamRawPredict` instead — so the launcher, the managed native install, the upstream-discovery pass and the client config all gained that key: `bili claude` now sets `ANTHROPIC_VERTEX_BASE_URL` to `<proxy>/bili/anthropic/<vertex origin>/v1`, where the protocol marker is required (`:rawPredict` matches no path suffix, so the suffix ladder cannot classify it) and the `/v1` is required because the client appends its own path starting at `/projects/…`; the endpoint host is derived from `ANTHROPIC_VERTEX_BASE_URL`/`CLOUD_ML_REGION` with the region validated against a strict pattern, host and `locations/<loc>` moving together; a dated model id (`claude-opus-5-5@…`) is normalized before the window lookup. The plain key stays set and untouched (inert under Vertex); with Vertex off nothing changes and nothing is emitted. Grounded in a captured Claude Code 2.1.300 wire (`tests/fixtures/vertex-anthropic/`, `tests/vertex-wire-fixture.test.ts`) plus a lane-scoped upstream fake (`tests/wire-contract-fakes.ts` rules `WC-019`/`WC-020`/`WC-021`, `tests/vertex-fake-upstream.test.ts`).
- **Anthropic Threads lane: mirror + reforge (#2926, #2884).** `thread` bodies (`create`/`continue`) hold conversation state server-side: a continue wire body is delta-only no matter how big the thread grew, so bili's history-rewrite lever does not exist on this wire and the compress machinery now stands down for these turns entirely (byte-faithful passthrough, no preflight — the wire body says nothing about the real thread size). Instead every turn is mirrored into the unified store (`session_ext` keys `threads:mirror:*`: create replaces the mirror — it is the client's authoritative snapshot — continue appends its delta; oversized entries are elided, not stored as media). When the mirror estimate crosses the window on a continue and the rollout feature `anthropicThreadsReforge` is on (default 0%; force with `rollout.features.anthropicThreadsReforge: true` or `BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE=1`), bili swaps that continue for a fresh `create` carrying [summary of the folded prefix, verbatim tail ring (last 3 user turns), this turn's delta] — the only channel that can deliver a fold to a server-side thread. The client's system/tools are copied byte-faithfully from the captured create shape (host instructions never enter the summary); one summarizer side-call rides the client's auth and the same upstream; because the message-id chain IS the thread identity, the client's next continue lands in the new thread with zero redirection. Fail-open everywhere: legacy-only storage (no unified sidecar) captures nothing and never reforges; a failed summary side-call forwards the continue untouched. The lane also claims turns before the #2648 global-scope stand-down — the stand-down used to swallow whole Claude Code threads sessions and silently disable folding (#2884).
- **Absorb distillation restored and scoped to image-bearing results by default (#3402, reverts #3309).** The `compress.absorb` block returns. New `compress.absorb.mediaOnly` (default `true`) restricts absorption to tool results that carry media (images): image bytes are not counted in text tokens, so such results are exempt from the `minToolTokens` floor and get marked `[ACP absorb]` even when small, while plain-text large results are no longer marked by default — this removes the old "always over-compresses" failure mode that motivated the original removal. Set `mediaOnly: false` to restore the pre-#3309 full-text behavior. `absorb.enabled` still defaults to `false` (the feature stays opt-in); once enabled, an absorbed result's call+result pair leaves subsequent context and its reclaimed tokens are credited against the compression budget. The plugin-lane prompt/tool gate is pinned consistent (the absorb prompt appears ⟺ the tool is advertised, both driven by the same base config block — #3293). Kernel `acp-kernel` 0.0.128 → 0.0.129 (new optional `mediaOnly` field; wire-contract goldens unchanged).
- **Absorb distillation removed (#3309).** The opt-in `compress.absorb` block (instant distillation of large tool results into short abstracts, originals to the content store) and its `absorb` tool were deleted from host and kernel. *(Backfill: #3309 shipped without a changelog line; this entry was added when the change was reverted. Superseded by the entry above.)*
- **Output-budget restore never exceeds the session's proven budget (#3406 item 4).** When no output ceiling is known for a model (no runtime-info, launcher, config, or registry row) and a starved main request must be restored, the #3071 absolute floor (32768) now applies ONLY when the session has no functional high-water of its own (born-starved / fork-inherited rattle, or a high-water below the 4096 trust line). A high-water at/above the trust line is the budget the provider already accepted at full value — restoring TO it instead of raising it to 32K fixes the hard-rejection on providers that cap `maxOutputTokens` below 32768 (the raised value 400'd outright, trading a degraded-but-working session for a failing one). The #3071 protections are unchanged: fresh sessions and death-rattle decay chains (…, 2061, 252) still get the floor, a known ceiling still floors the target, and non-starved values still pass through verbatim.
- **Stale-guard ownership fast path (#3049, hardened in #3406 item 2):** in shadow/full modes the per-save rollback guard no longer re-reads and re-parses the entire session envelope (the ~320 ms/turn, full-file read on >40 MiB sessions — a large slice of #3049's read amplification). The builder carries an ownership token (the two monotonic counters it just ingested); when the unified row still matches those counters and the envelope file is byte-identical to the stat stamped right after OUR write landed (same size, mtime not newer beyond sub-ms clock skew), no other writer can have committed and the guard skips the read. Cross-instance commits are still caught through the shared `index.db` row; foreign file writes (legacy sibling, manual edit) through the size/mtime stamp mismatch — now regardless of WHEN they land, closing the #3406 item-2 race where a sibling writing inside the old builtAtMs+1.5 s grace window was adopted as "ours" and clobbered on the next save. The debounce is host-owned so EVERY envelope write — the per-turn debounced save or an explicit one — gets stamped when it lands; a save whose write never landed observably (restore-replica seeds, crash before stamping) leaves the token unstamped and always takes the full read. Legacy-only installs keep the exact per-save full read. Residual (documented on `ownershipFastPath`): a foreign write landing in the microsecond gap between our awaited write resolving and the stamp's statSync can be adopted as ours for one cycle — the window shrank from 1.5 s to ~µs.
- **Image pre-compression (`compress.imageCompression`) and the `image_full` tool removed (#3266).** The opt-in downscale pass and its restore channel are gone from host and kernel: no more arrival-time shrinking, no `image_full` injection, no `[Downscaled screenshots]` notes, no image stats — `sharp` is no longer an optional dependency. Rationale: the restore loop was structurally unreachable on hosts that reject bili-injected tools (codex), and where reachable the model had no reliable way to learn the right ref, producing the 38-round guess-reject-resend loop in #3266 (cache hit 75%→28%). Every image now passes through byte-identical at original resolution. Sessions persisted by older versions load unchanged; their legacy `imageShrinks`/`imageFullRestored` state keys and `imageShrunk*` stats are ignored on load (never materialize). A future redesign is tracked on the issue.
Expand Down
2 changes: 1 addition & 1 deletion CLIENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ file (2.x rejects bare file paths in the config `plugin` array); **1.x**
hosts get the bare file path.

What the plugin does (both generations): registers the bili tools natively
in-host — compress / decompress / search_context / acp_status —
in-host — compress / decompress / search_context / acp_status (+ absorb) —
and stamps the proxy headers on every outgoing provider request, including
context-window / max-output read from the host's own model catalog
(`ctx.catalog.model.list()`, refreshed every 60s) and reported to the proxy
Expand Down
2 changes: 1 addition & 1 deletion CLIENTS.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bili 只压缩路径匹配已知 wire 协议(`/chat/completions`、`/llm_raw_cha

HTTPS 走证书 MITM,HTTP 走临时 `opencode.json` 副本(`/bili/` 改写;JSONC 注释照单接受,合并方式与 opencode 自身一致;相对本地插件路径在副本里重新锚定为绝对路径 —— opencode 按声明所在配置文件目录解析,#826)。宿主代次用 `--version` 探测(探测失败默认按 1.x):**2.x** 宿主注入内置 V2 插件(`dist/agent/opencode.js`),以临时包装目录形式给出(目录入口 `index.js` 再 re-export 插件文件 —— 2.x 拒绝配置 `plugin` 数组里的裸文件路径);**1.x** 宿主直接给裸文件路径。

插件在两代宿主上做的事相同:在宿主内原生注册 bili 工具 —— compress / decompress / search_context / acp_status—— 并在每个 provider 请求上盖章代理头,含从宿主自身模型目录(`ctx.catalog.model.list()`,每 60s 刷新)读取的 context-window / max-output,并以 runtime-info 上报给代理(#955)—— 压缩走插件模式,**不做** wire 级工具注入;原生 auto-compaction 自动关闭(`compaction.auto: false`)。所有注册都是防御式的(可选链):任一 2.x build 上接缝缺失或未触发时,插件保持惰性,会话透明回退纯代理模式而不是报错 —— 在相邻的 `dev` build 上观察到过 API 面互不相同(#754 评审探针)。
插件在两代宿主上做的事相同:在宿主内原生注册 bili 工具 —— compress / decompress / search_context / acp_status(另加 absorb)—— 并在每个 provider 请求上盖章代理头,含从宿主自身模型目录(`ctx.catalog.model.list()`,每 60s 刷新)读取的 context-window / max-output,并以 runtime-info 上报给代理(#955)—— 压缩走插件模式,**不做** wire 级工具注入;原生 auto-compaction 自动关闭(`compaction.auto: false`)。所有注册都是防御式的(可选链):任一 2.x build 上接缝缺失或未触发时,插件保持惰性,会话透明回退纯代理模式而不是报错 —— 在相邻的 `dev` build 上观察到过 API 面互不相同(#754 评审探针)。

1.x 细节(1.14.46 + 1.18.31 验证):V1 `.server()` 钩子在进程内把每个 provider 的 `options.baseURL` 改写为 `<proxy>/bili/…` 并设 `compaction.auto: false`;`chat.headers` 每次请求盖章插件头;`tool` 用真实 zod 形状注册 bili 工具(zod 是运行时依赖 —— 解析不到时降级为只改写)。没有显式 `baseURL` 的 provider(SDK 默认值,如裸 `@ai-sdk/openai` → api.openai.com)由全局 `fetch` 补丁兜住(日志:`v1: fetch patch installed`)—— 幂等,`/bili/` 包装过的 URL 原样直通;含 OpenAI Responses 端点端到端验证。

Expand Down
Loading
Loading