Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag
## [Unreleased]

### Changed
- **pi 内联压缩通道默认开启(#5428,取代 #4687 的手动开启规则)**:装了 bili 扩展的裸 `pi`(没设任何环境变量、没写配置)现在直接跑**进程内引擎**,不再自己派生代理进程。新优先级:kill-switch > /bili/ 改写启动 > 显式内联(`BILI_PI_INLINE=1/on/yes/TRUE` 或 `"pi": {"inline": true}`)> 宣告的附着目标(launcher 预置的 `BILLION_CONTEXT_PROXY/ATTACH`,`bili pi` 照旧用自己的 launcher 代理)> **默认内联** > spawn。**人类入口(短旗标,必须放在子命令前)**:`bili -i pi`(≡ `bili pi-inline`,强制内联+预检扩展+清理继承代理变量)与 `bili -s pi`(钉死代理姿态:子进程预置 `BILI_PI_INLINE=0`,压过继承的内联变量;opencode 同理)。不想用内联:`bili -s pi`、`BILI_PI_INLINE=0/false/no/off` 或 `"pi": {"inline": false}`——都恢复旧的 attach/spawn 姿态(有宣告代理就附着,否则自己派生代理)。`bili pi-inline` 一键车道保留(同 `-i pi`);空白 `BILI_PI_INLINE=""` 按未设置折叠。opencode 通道的默认不变(仍手动开启,`-i/-s` 两个旗标对它可用)。
- **The full-resend watermark fastpath (#5403/#5418) is now ON by default (GA)** after its §7.4 human review: plugin-lane chat-completions turns whose prefix is byte-stable skip the full history re-parse/re-pin on hit (the #5403 OOM producer), any doubt still falls back to the untouched full-parse path per turn. Opt out per install with `rollout.features.pluginFullResendWatermark: false` (or a percent) or `BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=0`.

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `native.attachUrl` | string | unset (discover per lane) | BILI_MCP_PROXY | Explicit target origin for native-hook attach (any URL). When set, a hook attaches ONLY to that exact origin instead of auto-discovering, and spawns its own if it is not live; it must still be code-compatible and pass the lifecycle gate. The BILI_MCP_PROXY env var (also set by CLI --origin) takes precedence over this file value; empty/whitespace means unset. |
| `claude.nativePort` | number | unset (lane sticky zone port) | BILI_CLAUDE_NATIVE_PORT | Exact port pin for the claude native lane's hook-spawned proxy (strict-port: squatters are refused loudly). |
| `pi.subagents` | object \| boolean | {} (acp_delegate enabled with package defaults) | PI_ACP_DELEGATE_FORCE_ENABLE, PI_ACP_DELEGATE_MAX_DEPTH, PI_ACP_DELEGATE_SYNC_TIMEOUT_MINUTES, PI_ACP_DELEGATE_IDLE_TIMEOUT_MINUTES, PI_ACP_DELEGATE_ASYNC_TIMEOUT_MINUTES, PI_ACP_DELEGATE_MAX_CONCURRENT | Built-in pi-lane sub-agents (acp_delegate) surface, #2230 config-home. The pi.subagents section of billion-context.json owns the delegate config; the four acp.json keys (delegate/delegatePrompt/displayUsage/debug) are a deprecated fallback read only while the section is absent. prompt replaces delegatePrompt; debug is scoped to the sub-agent subsystem. Boolean shorthand subagents: false disables the whole surface. Full field table: the pi section in CONFIGURATION.md. |
| `pi.inline` | boolean | false | BILI_PI_INLINE | Pi inline lane (#3278; OPT-IN — #4687 reverts the #4571 default flip, default stays the spawned proxy): the pi extension's compression runs IN-PROCESS — no spawned proxy, no ephemeral port; model traffic and the /__bili//__acp tool surface are served by an in-process engine through a pseudo-origin, the codex Responses WebSocket lane by a loopback-only WS bridge, and the Web UI by a loopback-only web listener booted with the engine. Set true (or BILI_PI_INLINE=1/on/yes/TRUE) to enable. Resolved env > file; an explicit inline choice always beats an announced attach target (launcher-set BILLION_CONTEXT_PROXY/ATTACH); when unset the lane behaves exactly as before (attach/spawn). `bili pi-inline` presets the env for the one-command lane. |
| `pi.inline` | boolean | true (unset env+file runs inline) | BILI_PI_INLINE | Pi inline lane (#3278; DEFAULT-ON since #5428, superseding the #4687 opt-in rule): the pi extension's compression runs IN-PROCESS — no spawned proxy, no ephemeral port; model traffic and the /__bili//__acp tool surface are served by an in-process engine through a pseudo-origin, the codex Responses WebSocket lane by a loopback-only WS bridge, and the Web UI by a loopback-only web listener booted with the engine. Unset env+file now runs INLINE; an ANNOUNCED attach target (launcher-set BILLION_CONTEXT_PROXY/ATTACH) still beats the default, so `bili pi` keeps its launcher proxy. Opt OUT with BILI_PI_INLINE=0/false/no/off or this key set false — restores the old attach/spawn posture. Resolved env > file > default; an explicit inline choice always beats an announced attach target. Human surface: `bili -i/--inline pi` (≡ the one-command lane) and `bili -s/--server pi` (pin the proxy posture, beats an inherited inline env). |
| `opencode.inline` | boolean | false | BILI_OPENCODE_INLINE | OpenCode inline lane (#3278 port; OPT-IN — the default stays the spawned proxy, per owner decision on #4687): the opencode plugin's compression runs IN-PROCESS — no spawned proxy, no ephemeral port, no MITM certs; model traffic and the /__bili/ tool surface are served by an in-process engine through a pseudo-origin (verified on the Bun host). Set true (or BILI_OPENCODE_INLINE=1) to enable. Resolved env > file; an explicit inline choice always beats an announced attach target, an absent choice falls back to attach/spawn as before. `bili opencode-inline` is the one-command lane. |

**MITM lane**
Expand Down Expand Up @@ -413,7 +413,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `BILI_NATIVE_OMP` | boolean-ish | off | — | Host posture: marks an omp-native plugin process. |
| `BILI_NATIVE_OPENCODE` | boolean-ish | off | — | Host posture: marks an opencode-native plugin process. |
| `BILI_NATIVE_PI` | boolean-ish | off | — | Host posture: marks a pi-native plugin process. |
| `BILI_PI_INLINE` | boolean-ish | off (opt-in) | — | Host posture: pi inline lane (#3278) — the pi extension compresses IN-PROCESS through the pseudo-origin instead of spawning its own proxy; outranks a preset BILLION_CONTEXT_PROXY attach target. OPT-IN: #4687 reverts the #4571 default flip — unset env/file behaves exactly as before (attach/spawn). Truthy = any non-empty value except 0/false/no/off (on/yes/TRUE all enable). Codex Responses WS traffic is routed through a loopback-only bridge booted with the engine; if that bridge fails, the WS lane degrades DIRECT (warned) while HTTP compression stays in-process. |
| `BILI_PI_INLINE` | boolean-ish | inline when unset (DEFAULT-ON since #5428; explicit 0/false/no/off opts out) | — | Host posture: pi inline lane (#3278) — the pi extension compresses IN-PROCESS through the pseudo-origin instead of spawning its own proxy; outranks a preset BILLION_CONTEXT_PROXY attach target. DEFAULT-ON since #5428 (supersedes the #4687 opt-in rule): unset env+file runs inline; an announced attach target still beats the DEFAULT, so `bili pi` keeps its launcher proxy. Explicit OPT-OUT = 0/false/no/off (or `"pi": {"inline": false}`) — restores the old attach/spawn posture. Human surface: `bili -i/--inline pi` forces inline, `bili -s/--server pi` pins the proxy posture (beats an inherited inline env). Truthy = any non-empty value except 0/false/no/off (on/yes/TRUE all enable). Codex Responses WS traffic is routed through a loopback-only bridge booted with the engine; if that bridge fails, the WS lane degrades DIRECT (warned) while HTTP compression stays in-process. |
| `BILI_OPENCODE_INLINE` | boolean-ish | off (opt-in) | — | Host posture: opencode inline lane (#3278 port) — the opencode plugin compresses IN-PROCESS through the pseudo-origin instead of spawning its own proxy; outranks a preset BILLION_CONTEXT_PROXY attach target. OPT-IN: the opencode lane keeps its legacy default (spawned proxy) unless this env or "opencode": {"inline": true} explicitly enables it (owner decision on #4687). Truthy = any non-empty value except 0/false/no/off (on/yes/TRUE all enable). Verified on the Bun host (engine boots and dispatches without node:sqlite). |
| `BILI_INLINE_DEBUG` | boolean-ish | off | — | Inline lane (#3278) only: keep the engine's log lines on stderr after muting them (the inline engine runs inside the pi process, where stderr is the interactive TUI — every [persist]/[storage]/[inline] line would scroll the input box away; default keeps them in bili.log only). |
| `BILI_NATIVE_ZCODE` | boolean-ish | off | — | Host posture: marks a zcode-native plugin process. |
Expand Down Expand Up @@ -1914,7 +1914,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `BILI_PERSIST_TAIL_TOKENS` | `persist.tailTokens` | 16384 (0 disables message persistence) |
| `BILI_PERSIST_ZSTD` | `persist.zstd` | false |
| `BILI_PERSONA_SPLIT` | `personaSplit` | true |
| `BILI_PI_INLINE` | `pi.inline` | false |
| `BILI_PI_INLINE` | `pi.inline` | true (unset env+file runs inline) |
| `BILI_POST_RESPONSE_LINGER_MS` | `network.postResponseLingerMs` | 5000 |
| `BILI_PREFLIGHT_DEAD_END_COOLDOWN_MS` | `network.preflightDeadEndCooldownMs` | 300000 |
| `BILI_PREFLIGHT_HOLD_MS` | `network.preflightHoldMs` | 30000 |
Expand Down
6 changes: 3 additions & 3 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
| `native.attachUrl` | string | unset (discover per lane) | BILI_MCP_PROXY | native hook 附着的显式目标源(任意 URL)。设置后,hook 只附着到该精确 origin 而不是自动发现,若其不在线则自行派生;仍需代码兼容并通过生命周期门禁。BILI_MCP_PROXY 环境变量(CLI --origin 亦会设置它)优先于此文件值;空/空白视为未设置。 |
| `claude.nativePort` | number | unset (lane sticky zone port) | BILI_CLAUDE_NATIVE_PORT | claude 原生车道钩子派生代理的精确端口钉死(严格端口:被占用时响亮拒绝而非跳端口)。 |
| `pi.subagents` | object \| boolean | {} (acp_delegate enabled with package defaults) | PI_ACP_DELEGATE_FORCE_ENABLE, PI_ACP_DELEGATE_MAX_DEPTH, PI_ACP_DELEGATE_SYNC_TIMEOUT_MINUTES, PI_ACP_DELEGATE_IDLE_TIMEOUT_MINUTES, PI_ACP_DELEGATE_ASYNC_TIMEOUT_MINUTES, PI_ACP_DELEGATE_MAX_CONCURRENT | 内置 pi lane 子代理(acp_delegate)面(#2230 配置搬家)。billion-context.json 的 pi.subagents 段拥有 delegate 配置;acp.json 四键(delegate/delegatePrompt/displayUsage/debug)为已废弃回退源,仅段缺失时读取。prompt 取代 delegatePrompt;debug 限定子代理子系统。布尔简写 subagents: false 整体关闭。完整字段表见 CONFIGURATION.md 的 pi 段。 |
| `pi.inline` | boolean | false | BILI_PI_INLINE | pi 内联压缩通道(#3278;需手动开启——#4687 收回 #4571 的默认翻转,默认仍是派生代理):pi 扩展的压缩在进程内完成——不派生代理进程、无临时端口;模型流量与 /__bili//__acp 工具面由进程内引擎经伪源站服务,codex 的 Responses WebSocket 通道走随引擎启动的仅回环 WS 桥,Web UI 走随引擎启动的仅回环监听。设 true(或 BILI_PI_INLINE=1/on/yes/TRUE)开启。解析顺序 env > 文件;显式开启永远压过附着目标,未设置时行为与旧版一致(attach/spawn)。`bili pi-inline` 一键车道会预置该变量。 |
| `pi.inline` | boolean | true (unset env+file runs inline) | BILI_PI_INLINE | pi 内联压缩通道(#3278;自 #5428 起默认开启,取代 #4687 的手动开启规则):pi 扩展的压缩在进程内完成——不派生代理进程、无临时端口;模型流量与 /__bili//__acp 工具面由进程内引擎经伪源站服务,codex 的 Responses WebSocket 通道走随引擎启动的仅回环 WS 桥,Web UI 走随引擎启动的仅回环监听。未设置 env+文件时默认内联;显式宣告的附着目标(launcher 预置的 BILLION_CONTEXT_PROXY/ATTACH)仍压过默认,`bili pi` 照旧用 launcher 代理。不想用就 BILI_PI_INLINE=0/false/no/off 或本键设 false——恢复旧的 attach/spawn 姿态。解析顺序 env > 文件 > 默认;显式开启永远压过附着目标。人类入口:`bili -i/--inline pi`(≡ 一键车道)与 `bili -s/--server pi`(钉死代理姿态,压过继承的内联变量)。 |
| `opencode.inline` | boolean | false | BILI_OPENCODE_INLINE | opencode 内联压缩通道(#3278 移植;需手动开启——按 #4687 决定,默认仍是派生代理):opencode 插件的压缩在进程内完成——不派生代理进程、无临时端口、无 MITM 证书;模型流量与 /__bili/ 工具面由进程内引擎经伪源站服务(已在 Bun 宿主验证)。设 true(或 BILI_OPENCODE_INLINE=1)开启。解析顺序 env > 文件;显式开启永远压过附着目标,未设置时行为与旧版一致(attach/spawn)。`bili opencode-inline` 一键车道。 |

**MITM 通道**
Expand Down Expand Up @@ -413,7 +413,7 @@
| `BILI_NATIVE_OMP` | boolean-ish | off | — | 宿主姿态:标记 omp 原生插件进程。 |
| `BILI_NATIVE_OPENCODE` | boolean-ish | off | — | 宿主姿态:标记 opencode 原生插件进程。 |
| `BILI_NATIVE_PI` | boolean-ish | off | — | 宿主姿态:标记 pi 原生插件进程。 |
| `BILI_PI_INLINE` | boolean-ish | off (opt-in) | — | 宿主姿态:pi 内联压缩通道(#3278)——pi 扩展在进程内通过伪源站直接压缩,不再另起代理进程;优先于预置的 BILLION_CONTEXT_PROXY 附着目标。需手动开启:#4687 收回 #4571 的默认翻转,不设置时行为与旧版完全一致(attach/spawn);除 0/false/no/off 外任何非空值均算开启(on/yes/TRUE 均可)。codex 的 Responses WS 流量改走随引擎启动的仅回环桥;桥起不来时该通道退回直连(打 warn),HTTP 压缩仍留在进程内。 |
| `BILI_PI_INLINE` | boolean-ish | inline when unset (DEFAULT-ON since #5428; explicit 0/false/no/off opts out) | — | 宿主姿态:pi 内联压缩通道(#3278)——pi 扩展在进程内通过伪源站直接压缩,不再另起代理进程;优先于预置的 BILLION_CONTEXT_PROXY 附着目标。自 #5428 起默认开启(取代 #4687 的手动开启规则):未设置 env+文件时走内联;显式宣告的附着目标仍压过默认,`bili pi` 照旧用 launcher 代理。显式关闭 = 0/false/no/off(或 `"pi": {"inline": false}`)——恢复旧的 attach/spawn 姿态。人类入口:`bili -i/--inline pi` 强制内联,`bili -s/--server pi` 钉死代理姿态(压过继承的内联变量)。除 0/false/no/off 外任何非空值均算开启(on/yes/TRUE 均可)。codex 的 Responses WS 流量改走随引擎启动的仅回环桥;桥起不来时该通道退回直连(打 warn),HTTP 压缩仍留在进程内。 |
| `BILI_OPENCODE_INLINE` | boolean-ish | off (opt-in) | — | 宿主姿态:opencode 内联压缩通道(#3278 移植)——opencode 插件在进程内通过伪源站直接压缩,不再另起代理进程;优先于预置的 BILLION_CONTEXT_PROXY 附着目标。需手动开启:按 #4687 决定,opencode 通道默认保持旧行为(另起代理),只有本环境变量或 "opencode": {"inline": true} 显式开启才切换;除 0/false/no/off 外任何非空值均算开启(on/yes/TRUE 均可)。已在 Bun 宿主上验证(无 node:sqlite 时引擎 boot/dispatch 正常)。 |
| `BILI_INLINE_DEBUG` | boolean-ish | off | — | 仅内联通道(#3278):把引擎日志保留在 stderr 上(默认关闭——内联引擎跑在 pi 进程里,stderr 就是交互终端,每行 [persist]/[storage]/[inline] 都会把输入框挤掉;默认只写 bili.log)。 |
| `BILI_NATIVE_ZCODE` | boolean-ish | off | — | 宿主姿态:标记 zcode 原生插件进程。 |
Expand Down Expand Up @@ -1891,7 +1891,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报
| `BILI_PERSIST_TAIL_TOKENS` | `persist.tailTokens` | 16384 (0 disables message persistence) |
| `BILI_PERSIST_ZSTD` | `persist.zstd` | false |
| `BILI_PERSONA_SPLIT` | `personaSplit` | true |
| `BILI_PI_INLINE` | `pi.inline` | false |
| `BILI_PI_INLINE` | `pi.inline` | true (unset env+file runs inline) |
| `BILI_POST_RESPONSE_LINGER_MS` | `network.postResponseLingerMs` | 5000 |
| `BILI_PREFLIGHT_DEAD_END_COOLDOWN_MS` | `network.preflightDeadEndCooldownMs` | 300000 |
| `BILI_PREFLIGHT_HOLD_MS` | `network.preflightHoldMs` | 30000 |
Expand Down
27 changes: 18 additions & 9 deletions src/agent/pi-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function shouldBootstrapNative(env: NodeJS.ProcessEnv): boolean {

/** Decide this process's native posture (#886/#983 mechanism, ported to the pi
* lane in #1795). Precedence kill-switch > /bili/ rewrite launch > explicit
* inline > attach > spawn (DEFAULT). A preset BILLION_CONTEXT_PROXY is an ATTACH target, not a
* inline > attach > inline (DEFAULT since #5428) > spawn. A preset BILLION_CONTEXT_PROXY is an ATTACH target, not a
* stand-down: the pseudo-attach hole (preset env + bare pi) used to disarm
* routing entirely while tools still found the proxy through the env — model
* traffic went direct and uncompressed, the proxy never saw the session, and
Expand All @@ -59,12 +59,15 @@ export function shouldBootstrapNative(env: NodeJS.ProcessEnv): boolean {
* /bili/ launch (BILI_PROVIDER_REWRITES) still stands us down — its URLs are
* already proxy-shaped. BILI_PI_INLINE (#3278) outranks ambient attach envs:
* it is a deliberate choice about WHERE compression runs (in this process),
* not just which proxy to use. Resolved env > file > default(off): the
* not just which proxy to use. Resolved env > file > default: the
* config-file home is `"pi": {"inline": true}`; an explicit BILI_PI_INLINE=0/
* false disables over the file. OPT-IN ONLY (owner decision on #4687:
* never flip defaults) — unset env/file behaves exactly as before the
* #4571 default flip (attach > spawned proxy); `bili pi-inline` presets
* BILI_PI_INLINE=1 for the one-command lane. */
* false disables over the file. DEFAULT INLINE since #5428 (supersedes the
* #4687 opt-in rule): unset env+file runs the in-process lane — opt out
* with BILI_PI_INLINE=0/false/no/off or `"pi": {"inline": false}` to
* restore the old attach/spawn posture. An ANNOUNCED attach target
* (launcher-set BILLION_CONTEXT_PROXY/ATTACH) still beats the default —
* `bili pi` keeps its launcher proxy; only explicit inline outranks attach.
* `bili pi-inline` presets BILI_PI_INLINE=1 for the one-command lane. */
export function planNativePi(env: NodeJS.ProcessEnv, fileInline: boolean | undefined = undefined): { mode: "off" | "attach" | "spawn" | "inline"; attachOrigin?: string } {
if (env.BILLION_CONTEXT_PLUGIN === "0" || env.BILI_NATIVE_PI === "0") return { mode: "off" };
if (env.BILI_PROVIDER_REWRITES !== undefined) return { mode: "off" };
Expand All @@ -78,10 +81,16 @@ export function planNativePi(env: NodeJS.ProcessEnv, fileInline: boolean | undef
// still suppresses a file-true value (env > file, #3278 contract):
if (!inlineEnvOff && (inlineEnvOn || fileInline === true)) return { mode: "inline" };
const attachOrigin = nativeAttachOrigin(env) ?? proxyEnvOrigin(env);
// An ANNOUNCED attach target beats the #5428 inline default: `bili pi`
// sets BILLION_CONTEXT_PROXY before the child starts, and its launcher
// proxy must keep serving that child.
if (attachOrigin !== undefined) return { mode: "attach", attachOrigin };
// …then spawn: the historical default (owner decision on #4687 — inline
// is opt-in only, the #4571 default flip is reverted; a proxy server is
// spawned unless BILI_PI_INLINE / pi.inline=true opted into in-process).
// #5428 default flip (supersedes #4687): with NO explicit choice anywhere
// (env unset/blank AND file unset) the lane runs INLINE in-process. Reach
// spawn only via explicit opt-out — BILI_PI_INLINE=0/false/no/off or
// "pi": {"inline": false} — which restores the pre-#5428 posture above
// (attach when announced, else a spawned proxy).
if ((inlineEnv === undefined || inlineEnv === "") && fileInline === undefined) return { mode: "inline" };
return { mode: "spawn" };
}

Expand Down
Loading
Loading