Skip to content
Closed
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
9 changes: 6 additions & 3 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `promptCache.routing` | "auto" \| "enabled" \| "disabled" | auto | ACP_PROMPT_CACHE_ROUTING | Prompt-cache routing posture for cache-aware lane selection. |
| `native.attachExternal` | boolean | false | BILI_NATIVE_ATTACH_EXTERNAL | Let launcher-less native plugins attach to an external (lane'd, unarmed) daemon instead of spawning their own. |
| `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). |
| `claude.allowNativeCompaction` | boolean | false | BILI_ALLOW_CLAUDE_COMPACTION | Lift bili's local 403 refusal of Claude Code native compaction calls (manual /compact, precomputed compression, auto-compact behind a non-managed install — final user message carrying the CC summarize template) on every wire lane bili serves — anthropic natively, openai/responses behind CC-router installs (#2612/#2728): when true the call forwards; on success CC rewrites its transcript to the summary while bili's fold ledger still anchors the raw history (unannounced-rewrite desync family), so this is an explicit opt-out of bili-owned compression. Default OFF keeps the guard active; the managed install block separately sets DISABLE_AUTO_COMPACT=1 so auto-compact does not fire under a bili-managed CC. |
| `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. |

**MITM lane**
Expand Down Expand Up @@ -682,10 +683,10 @@ Top-level keys that control how the proxy listens and behaves globally.

### `claude`

- **Type:** `{ nativePort?: number }`
- **Default:** `{}` (lane rides the self-managed port zone)
- **Type:** `{ nativePort?: number, allowNativeCompaction?: boolean }`
- **Default:** `{}` (lane rides the self-managed port zone; compaction guard active)
- **Status:** ACTIVE
- **Description:** claude native-lane settings. `nativePort` pins an EXACT port for the hook-spawned proxy (#964/#1660): strict-port semantics — a squatter on the port is refused loudly instead of hopping — and the baked managed `ANTHROPIC_BASE_URL` points at it. Without it the lane rides the self-managed zone (`BILI_ZONE_PORT` base + per-lane sticky) and re-pins the managed URL to the live origin each session, so port drift self-heals. Overridden by `BILI_CLAUDE_NATIVE_PORT`.
- **Description:** claude native-lane settings. `nativePort` pins an EXACT port for the hook-spawned proxy (#964/#1660): strict-port semantics — a squatter on the port is refused loudly instead of hopping — and the baked managed `ANTHROPIC_BASE_URL` points at it. Without it the lane rides the self-managed zone (`BILI_ZONE_PORT` base + per-lane sticky) and re-pins the managed URL to the live origin each session, so port drift self-heals. Overridden by `BILI_CLAUDE_NATIVE_PORT`. `allowNativeCompaction` (env `BILI_ALLOW_CLAUDE_COMPACTION`) lifts the wire guard that refuses Claude Code native compaction with 403 (#2612/#2728) — an explicit opt-out of bili-owned compression; see the key table above.

### `native`

Expand Down Expand Up @@ -1599,6 +1600,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `BILI_ADVISORY_CHECK` | `advisoryCheck` | true |
| `BILI_ADVISORY_URL` | `advisoryUrl` | unset (built-in feed) |
| `BILI_AFFINITY_SIMHASH` | `affinitySimhash` | true |
| `BILI_ALLOW_CLAUDE_COMPACTION` | `claude.allowNativeCompaction` | false |
| `BILI_ALLOW_DSH_COMPACTION` | `dsh.allowDshCompaction` | false |
| `BILI_CCR_RETRIEVAL_TTL_MS` | `ccrRetrievalTtlMs` | 600000 (0 disables retrieval) |
| `BILI_CHAIN_CONTENT` | `chainContentDetection` | false |
Expand Down Expand Up @@ -1767,6 +1769,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `BILI_ZCODE_SIGNING_FIXED` | `1`/`true` = assume your ZCode build fixed ClientRequestSigningV4 (#1621): the per-entry skips for coding-plan accounts on v3.14+ personal stores flip off and they route again. Temporary escape hatch — there is **no** file equivalent. |
| `BILI_CLAUDE_UPSTREAM` | claude direct mode: your relay endpoint, when `ANTHROPIC_BASE_URL` already points at a relay the launcher would otherwise bypass. |
| `BILI_CLAUDE_NATIVE_PORT` | Pin an **exact** port for the claude native lane's hook-spawned proxy (#964/#1660): strict-port semantics — a squatter on the port is refused loudly instead of hopping — and the baked managed `ANTHROPIC_BASE_URL` points at it. Without it the hook rides the self-managed zone (`BILI_ZONE_PORT` base + per-lane sticky) and re-pins the managed URL to the live origin each session, so port drift self-heals (#1660). |
| `BILI_ALLOW_CLAUDE_COMPACTION` | Claude Code native-compaction handling (#2612/#2728). Default `0`/unset: bili's wire guard refuses CC compaction calls (manual `/compact`, precomputed compression, auto-compact when the managed `DISABLE_AUTO_COMPACT=1` is not in force) locally with 403 — never forwarded, kernel state untouched, CC's transcript stays verbatim and the refusal surfaces through CC's "Error during compaction" — because on success CC rewrites its transcript to the summary while bili's fold ledger still anchors the raw history (the unannounced-rewrite desync family, #2728), and the envelope re-sends the full raw history upstream exactly when things are already broken. Set `1` to forward anyway (same trade as `claude.allowNativeCompaction` in the file; `0` also forces the guard on when the file opted out). |
| `BILI_CODEX_COMPACT` | Codex native-compaction handling. Default `intercept`: bili intercepts codex's compaction requests and forges a local handoff to the ACP state when the safety gate passes (transform ok + steady-state usage < 90% of the window + at least one active compressed block) — trigger form forges a 2-frame SSE, endpoint form forges `{output}` — and never contacts upstream. Forged ACP summaries are re-injected as a history-borne handoff message (developer-message fallback) so compressed content stays visible after codex truncates its history. Set `pass` to opt out and forward codex's compaction requests upstream (native compaction backstops). On any gate failure the request passes through untouched. Codex client detection (which traffic this applies to, also used for window clamping and session-identity fingerprinting): the User-Agent must either start with a registered prefix (`codex_cli_rs/`, `codex_exec/`, `codex desktop/` — matched case-insensitively, since variants like Codex Desktop send an initial capital, #1169) or contain a whitespace-delimited component starting with lowercase `codex` (unknown variants such as `codex_sdk_ts/…`, #645 — narrowed from a bare substring to a token-level prefix in #1641 so non-codex clients whose UAs merely mention "codex" mid-token or in parens are no longer misclassified; the fallback stays case-sensitive on purpose so "Codex"-shaped relays are excluded, #1106). |

---
Expand Down
2 changes: 2 additions & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
| `promptCache.routing` | "auto" \| "enabled" \| "disabled" | auto | ACP_PROMPT_CACHE_ROUTING | 面向缓存感知路由选择的提示词缓存路由姿态。 |
| `native.attachExternal` | boolean | false | BILI_NATIVE_ATTACH_EXTERNAL | 允许无启动器的原生插件挂到外部(车道化、未武装看门狗)守护进程,而不是自行派生。 |
| `claude.nativePort` | number | unset (lane sticky zone port) | BILI_CLAUDE_NATIVE_PORT | claude 原生车道钩子派生代理的精确端口钉死(严格端口:被占用时响亮拒绝而非跳端口)。 |
| `claude.allowNativeCompaction` | boolean | false | BILI_ALLOW_CLAUDE_COMPACTION | 解除 bili 对 Claude Code 原生压缩调用的本地 403 拒绝(手动 /compact、预计算压缩、非托管安装下的 auto-compact —— 尾部 user 消息携带 CC 摘要模板),覆盖 bili 服务的全部线路 —— CC 原生走 anthropic,经 CC-router 的安装走 openai/responses(#2612/#2728):为 true 时调用照常转发;一旦成功 CC 会把本地转录改写为摘要,而 bili 的折叠账本仍锚定原始历史(无告知改写 / 静默失同步家族),因此这是对 bili 自管压缩的显式 opt-out。默认关闭(守卫生效);托管安装块另行设置 DISABLE_AUTO_COMPACT=1,bili 托管下的 CC 不会触发 auto-compact。 |
| `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 段。 |

**MITM 通道**
Expand Down Expand Up @@ -1598,6 +1599,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报
| `BILI_ADVISORY_CHECK` | `advisoryCheck` | true |
| `BILI_ADVISORY_URL` | `advisoryUrl` | unset (built-in feed) |
| `BILI_AFFINITY_SIMHASH` | `affinitySimhash` | true |
| `BILI_ALLOW_CLAUDE_COMPACTION` | `claude.allowNativeCompaction` | false |
| `BILI_ALLOW_DSH_COMPACTION` | `dsh.allowDshCompaction` | false |
| `BILI_CCR_RETRIEVAL_TTL_MS` | `ccrRetrievalTtlMs` | 600000 (0 disables retrieval) |
| `BILI_CHAIN_CONTENT` | `chainContentDetection` | false |
Expand Down
41 changes: 40 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,25 @@ export type ProxyOptions = {
* `{ "dsh": { "allowDshCompaction": true } }` in the config file, or env
* BILI_ALLOW_DSH_COMPACTION=1. */
allowDshCompaction?: boolean;
/** #2612/#2728: opt-in to letting Claude Code's native compaction
* (manual /compact, auto-compact, precomputed compression) run through
* bili instead of being refused by the wire guard
* (src/server/claude-compaction-guard.ts, the claude twin of #1729's
* dsh guard). Default OFF (= guard active): a CC compaction envelope
* (final user message = the CC summarize template) is refused locally
* with 403 — not forwarded, kernel state untouched, CC's transcript
* preserved verbatim. When ON the call is forwarded: on success CC
* rewrites its transcript to the summary while bili's fold ledger still
* anchors the raw history — the unannounced-rewrite desync family
* (#2728) — which is why this stays off by default. The managed install
* block separately sets DISABLE_AUTO_COMPACT=1 (applyClaudeManagedBlock,
* "bili owns compression"), so under a bili-managed CC auto-compact does
* not fire at all; the guard is the wire backstop covering manual
* /compact, users who re-enabled the env, and CC installs routed through
* bili without the managed block. Enable with `{ "claude": {
* "allowNativeCompaction": true } }` in the config file, or env
* BILI_ALLOW_CLAUDE_COMPACTION=1. */
allowClaudeCompaction?: boolean;
};

/** #2028: dsh client-lane settings namespace — home for dsh-specific file
Expand Down Expand Up @@ -1169,6 +1188,15 @@ export function allowDshCompactionState(env: NodeJS.ProcessEnv): { enabled: bool
return { enabled: fileAllow, source: fileAllow ? "file" : null };
}

// #2612: resolved claude-native-compaction opt-in state, the claude twin of
// allowDshCompactionState (same "0-off" env semantics; single source of truth
// for loadOptions and future web-config consumers).
export function allowClaudeCompactionState(env: NodeJS.ProcessEnv): { enabled: boolean; source: "env" | "file" | null } {
const fileAllow = loadConfigFile().claude?.allowNativeCompaction === true;
if (env.BILI_ALLOW_CLAUDE_COMPACTION !== undefined) return { enabled: env.BILI_ALLOW_CLAUDE_COMPACTION !== "0", source: "env" };
return { enabled: fileAllow, source: fileAllow ? "file" : null };
}

// #1359: provider/model absorb.* overrides apply only to the proxy lane (plugin
// lane follows the base block). Warn once per load so the divergence isn't silent.
const ABSORB_DIVERGENCE_FIELDS = ["enabled", "toolName", "minToolTokens", "contextThresholdPct", "excludeTools"] as const;
Expand Down Expand Up @@ -1439,6 +1467,10 @@ export function loadOptions(env: NodeJS.ProcessEnv = process.env): ProxyOptions
// #2028: default OFF keeps the #1729 wire refusal unconditional unless
// explicitly opted out — see the Options.allowDshCompaction docstring.
allowDshCompaction: (env.BILI_ALLOW_DSH_COMPACTION ?? (fileConfig.dsh?.allowDshCompaction === true ? "1" : "0")) !== "0",
// #2612: default OFF keeps the claude compaction wire guard
// unconditional unless explicitly opted out — see the
// Options.allowClaudeCompaction docstring.
allowClaudeCompaction: (env.BILI_ALLOW_CLAUDE_COMPACTION ?? (fileConfig.claude?.allowNativeCompaction === true ? "1" : "0")) !== "0",
};
}

Expand Down Expand Up @@ -1656,7 +1688,14 @@ type FileConfig = {
* claude lane — strict-port semantics (EADDRINUSE fails loud). Undefined
* (the default) means the lane's sticky zone port (ZONE_PORT_BASE base).
* Env BILI_CLAUDE_NATIVE_PORT wins over the file. */
claude?: { nativePort?: number };
claude?: { nativePort?: number; allowNativeCompaction?: boolean };
/** Claude-native native-compaction opt-in (#2612/#2728), the claude twin
* of dsh.allowDshCompaction (#2028): `"claude": {
* "allowNativeCompaction": true }` in the config file lifts bili's local
* 403 refusal of Claude Code native compaction requests (/compact,
* auto-compact, precomputed compression — final user message carrying
* the CC summarize template). Default OFF (= guard active). Env
* BILI_ALLOW_CLAUDE_COMPACTION wins over the file. */
/** Built-in pi-lane sub-agents (#2230 config-home): the `pi.subagents`
* section owns the acp_delegate surface for the pi lane (embedded wiring
* src/agent/pi-subagents.ts; the standalone package
Expand Down
2 changes: 1 addition & 1 deletion src/plugin-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export function applyClaudeManagedBlock(settings: Record<string, unknown>, opts:
if (dac === undefined || dac === null || dac === "1") {
if (dac !== "1") {
env.DISABLE_AUTO_COMPACT = "1";
notes.push("env.DISABLE_AUTO_COMPACT=1 (bili owns compression; manual /compact survives)");
notes.push("env.DISABLE_AUTO_COMPACT=1 (bili owns compression; manual /compact is refused by the wire guard, #2612)");
}
} else {
notes.push(`env.DISABLE_AUTO_COMPACT left untouched (foreign value ${JSON.stringify(dac)})`);
Expand Down
Loading
Loading