diff --git a/docs/clients.md b/docs/clients.md index b71a23fe7b..24e684716b 100644 --- a/docs/clients.md +++ b/docs/clients.md @@ -129,19 +129,31 @@ Two lanes, same plugin (#941): alive when `bili-native` is disabled or kill-switched (#3662) — registers a cordis `internal/config` overlay (vendored from deshark42/dsh-compaction-basic-disable, MIT) that marks the preset's - `compaction-basic` and `command-compact` rows `disabled: true` while + `compaction-basic` rows — and `command-compact` rows unless + `dsh.keepCommandCompact` is set (#4872) — `disabled: true` while bili owns the lane, and the preset gate rows in the bundle patch make each Web preset wait for that overlay's service before it can register. Native auto-compaction is OFF in these profiles too (and `/compact` is - unavailable there — that is EXPECTED, not a bug (#4002): bili owns - compression on the lane, so the preset's compact command and its - auto-compaction are both stood down deliberately; there is no - re-enable switch by design (#3651/#3666), see configuration.md); + unavailable there by default — that is EXPECTED, not a bug (#4002): + bili owns compression on the lane, so the preset's compact command + and its auto-compaction are both stood down deliberately; there is + no re-enable switch for AUTO-compaction by design (#3651/#3666). + While the knob is unset, bili registers a visible `/compact` stub in + these profiles so a typed `/compact` is answered — never silently + demoted to a plain model message (#6814) — pointing at /acp and at + the knob. If you run third-party plugins bridging through the + DSH-official `ctx.commands.find(agent, "compact")` path and need the + explicit `/compact` command back, set `dsh.keepCommandCompact` (env + `BILI_DSH_KEEP_COMMAND_COMPACT`) — the overlay then disables only + compaction-basic, and a `/compact`-triggered call still passes the + #1729 wire guard; see configuration.md, #4872); ACP compression is unaffected. Since #4147 the overlay matches STRUCTURALLY — any entry whose resolved `config.plugins` nests - `compaction-basic`/`command-compact` rows gets them disabled, custom - and profile-local presets exactly like the factory ones (the four + `compaction-basic`/`command-compact` rows enters the rewrite (always + for compaction-basic, additionally for command-compact while + `dsh.keepCommandCompact` is unset, #4872), custom and profile-local + presets exactly like the factory ones (the four gate-row ids in `dsh.bundle.patch.yml` are ordering insurance for the factory roster, not the coverage boundary — a profile shipping other preset ids is covered by the structural walk). The one-time `[dsh-client]` diff --git a/docs/clients.zh-CN.md b/docs/clients.zh-CN.md index 109c1049d8..0b2d23a1a9 100644 --- a/docs/clients.zh-CN.md +++ b/docs/clients.zh-CN.md @@ -16,7 +16,7 @@ - **桌面应用(Electron 宿主):** 同一插件也运行在 deepseek-harness **desktop** 应用内(经其应用内插件管理器安装)。此时 bootstrap 在应用进程内拉起代理:该进程的 `process.execPath` 是 Electron 二进制而非 Node,GUI 的 PATH 又不含常规安装目录 —— `resolveNodeRuntime`(#819/#1429)先探测众所周知的安装位置(`/opt/homebrew/bin`、`/usr/local/bin`、Volta 等),再回退到以纯 Node 方式运行应用自身二进制(`ELECTRON_RUN_AS_NODE=1`,强制注入子进程 env),于是无需 PATH 里有独立 Node 也能零配置压缩;设 `BILLION_CONTEXT_NODE` 可强制指定某个 Node(优先于两者)。#1429 之前该路径在 spawn 前抛错,所有会话静默降级为直连(不压缩),只能从 bili.log 里发现。 - **自动更新保持各 profile 同步:** 刷新有两个触发器 —— 全局自更新完成后,以及**profile 自己的代理**在周期检查里发现注册表有新版本时(全局 bili 从不运行也一样刷新,#1196 —— 插件市场安装的用户往往根本没有全局安装)。两种触发器都扫描 `~/.dsh/profiles/*/package.json`,把注册表钉住的 `billion-context` 依赖刷新到目标版本(全局触发器刷到新全局版本,自触发刷到注册表最新),统一经 dsh 自己的 `plugin add` 通道,绝不在位覆盖 —— 加载的插件与代理从此不再漂移(#953);钉在本地源的 profile 不动。刷新是尽力而为,失败下个周期重试,绝不会让代理或更新本身失败。 - **已报告:Profile 安装下部分传输零代理流量(#1158,调查中):** dsh `llm-pi-ai` 层的部分传输服务会话**从未有任何模型请求到达代理**(日志无 `processTurn`,调用 bili 工具返回 404 "no model request has arrived"),而同宿主的其他 provider 正常。根因仍在用运行时证据定性 —— 候选:传输层 fetch 形态(SDK 注入 fetch / 非全局 dispatcher)或宿主侧归属缺口导致流量未被 takeover gate 认领。检测:此类情况会打一次性 `[plugin] NO MODEL REQUESTS seen for conversation …` 告警,dsh 插件还会把归属 gate 放行的每个端点各记一条日志(每进程一次)。期间可靠规避:改用 `bili dsh` 启动 —— 启动器的 settings overlay 会把那些 provider 的 `baseURL` 重写为 `/bili/` URL,无论传输层使用哪种 fetch、归属状态如何,流量都必然过代理。 -- **Web profile 压缩(#1772,#3354 解决):** 当 profile 的 bundles 含 `@deepseek-ai/dsh-web-app` 时,真正运行的 `compaction-basic` 实例位于 agent preset(`preset-standard.config.plugins`)内部 —— dsh 的 patch 引擎只按 id 索引顶层条目与真 group(`group: true` 且 config 为数组)的子项,preset 内的嵌套行任何 patch 层都无法**按 id 直寻**。于是 bundle 里的 `auto: false` 落在 web-app 已禁用的宿主平面行上、什么都没改。#3354 起 bili 在**加载期**补上这一环:一个**常驻**的 bundle 条目 `bili-compaction-gate`(与 `bili-native` 并列的独立 cordis 条目,由同一组 patch 层挂载,因此 `bili-native` 被禁用或 kill-switch 时它仍然存活,#3662)注册一个 cordis `internal/config` overlay(移植自 deshark42/dsh-compaction-basic-disable,MIT),在 bili 持有该泳道期间把 preset 里的 `compaction-basic` 与 `command-compact` 行标记为 `disabled: true`;#4147 起该匹配是**结构化**的 —— 任何 entry 的 `config.plugins` 里嵌套了这两个包的行都会被禁用,自定义/本地 preset 与官方 preset 一视同仁(`dsh.bundle.patch.yml` 里的四个门控 id 只是对官方 roster 的顺序保险,不是覆盖边界);bundle patch 里的 preset 门控行让每个 Web preset 在注册前等待该 overlay 的服务。这些 profile 里原生自动压缩同样关闭(且 `/compact` 在那里不可用 —— 这是**预期行为而非 bug**(#4002):该泳道的压缩由 bili 接管,preset 的 compact 命令与自动压缩被有意一并撤下;按设计**没有**重新打开的开关(#3651/#3666),见 configuration.md);ACP 压缩不受影响。启动的一次性 `[dsh-client]` 日志会列出 overlay 实际改写过的 entry(#3962),patch 行落空(如 roster 改名)无需翻宿主 loader 日志即可见。overlay 依赖 dsh 的内部钩子、对版本敏感 —— 若在新/旧 dsh 构建上仍见到 dsh 压缩 checkpoint 落地,回退到 #2474 配方:profile 层 patch(你 profile 自己的 `cordis.patch.yml`,在所有 bundle 之后生效)用同 id + **完整快照** `config` 整体覆盖 preset-standard —— 从 `dsh --profile --dump-config` 抄下完整的 preset config,在其 `compaction-basic` 行下加 `config.auto: false`,把结果追加进 `cordis.patch.yml`。Config 替换是**整体语义**(片段会静默丢掉一切未重述的键 —— 不只是其他插件,连 preset 自己的 `id`/`order` 身份也会丢,可能使 roster 无法识别该 preset);`- insert:` 同 id 则是在末尾追加一条死行而非合并。dsh 升级 preset 后快照冻结 roster、需重抄一次。此类 profile 启动时插件打一条一次性 `[dsh-client]` 日志,说明两条路径。 +- **Web profile 压缩(#1772,#3354 解决):** 当 profile 的 bundles 含 `@deepseek-ai/dsh-web-app` 时,真正运行的 `compaction-basic` 实例位于 agent preset(`preset-standard.config.plugins`)内部 —— dsh 的 patch 引擎只按 id 索引顶层条目与真 group(`group: true` 且 config 为数组)的子项,preset 内的嵌套行任何 patch 层都无法**按 id 直寻**。于是 bundle 里的 `auto: false` 落在 web-app 已禁用的宿主平面行上、什么都没改。#3354 起 bili 在**加载期**补上这一环:一个**常驻**的 bundle 条目 `bili-compaction-gate`(与 `bili-native` 并列的独立 cordis 条目,由同一组 patch 层挂载,因此 `bili-native` 被禁用或 kill-switch 时它仍然存活,#3662)注册一个 cordis `internal/config` overlay(移植自 deshark42/dsh-compaction-basic-disable,MIT),在 bili 持有该泳道期间把 preset 里的 `compaction-basic` 行(以及未设 `dsh.keepCommandCompact` 时的 `command-compact` 行,#4872)标记为 `disabled: true`;#4147 起该匹配是**结构化**的 —— 任何 entry 的 `config.plugins` 里嵌套了这两个包的行都会进入改写(compaction-basic 恒禁,command-compact 仅在未设 `dsh.keepCommandCompact` 时禁,#4872),自定义/本地 preset 与官方 preset 一视同仁(`dsh.bundle.patch.yml` 里的四个门控 id 只是对官方 roster 的顺序保险,不是覆盖边界);bundle patch 里的 preset 门控行让每个 Web preset 在注册前等待该 overlay 的服务。这些 profile 里原生自动压缩同样关闭(且 `/compact` 在那里默认不可用 —— 这是**预期行为而非 bug**(#4002):该泳道的压缩由 bili 接管,preset 的 compact 命令与自动压缩默认被有意一并撤下;**自动压缩**按设计**没有**重新打开的开关(#3651/#3666)。开关未设时,bili 在这些 profile 里注册一个可见的 `/compact` 占位命令:输入的 `/compact` 会得到明确答复(指向 /acp 与该开关),而**不会**被静默降级为普通模型消息(#6814)。若你运行依赖 DSH 官方 `ctx.commands.find(agent, "compact")` 通路的第三方插件、需要显式 `/compact` 命令,设 `dsh.keepCommandCompact`(env `BILI_DSH_KEEP_COMMAND_COMPACT`)——overlay 便只禁 compaction-basic;/compact 触发的调用仍经 #1729 wire guard(#4872),见 configuration.md);ACP 压缩不受影响。启动的一次性 `[dsh-client]` 日志会列出 overlay 实际改写过的 entry(#3962),patch 行落空(如 roster 改名)无需翻宿主 loader 日志即可见。overlay 依赖 dsh 的内部钩子、对版本敏感 —— 若在新/旧 dsh 构建上仍见到 dsh 压缩 checkpoint 落地,回退到 #2474 配方:profile 层 patch(你 profile 自己的 `cordis.patch.yml`,在所有 bundle 之后生效)用同 id + **完整快照** `config` 整体覆盖 preset-standard —— 从 `dsh --profile --dump-config` 抄下完整的 preset config,在其 `compaction-basic` 行下加 `config.auto: false`,把结果追加进 `cordis.patch.yml`。Config 替换是**整体语义**(片段会静默丢掉一切未重述的键 —— 不只是其他插件,连 preset 自己的 `id`/`order` 身份也会丢,可能使 roster 无法识别该 preset);`- insert:` 同 id 则是在末尾追加一条死行而非合并。dsh 升级 preset 后快照冻结 roster、需重抄一次。此类 profile 启动时插件打一条一次性 `[dsh-client]` 日志,说明两条路径。 - **禁用与移除插件的区别(#3662):** #3662 之前,禁用 `bili-native`(dsh 插件管理器,或任何 patch 层里写 `disabled: true`)会把门控服务的**唯一**提供方一并移除,而 preset 行仍在等它 —— 四个 Web preset 永久 pending,新建/恢复会话全部报 `Unknown agent preset: standard`。现在该服务住在独立的常驻条目 `bili-compaction-gate` 里:禁用或 kill-switch(`BILLION_CONTEXT_PLUGIN=0`)`bili-native` 只是把泳道交还 dsh **原生行为** —— preset 正常注册、原生自动压缩恢复,bili 压缩则完全关闭。请勿禁用 `bili-compaction-gate` 本身 —— 那会重新造成「砖」。要彻底卸载:从 profile 的 `dsh.profile.bundles`(及其依赖)里移除 `billion-context` 后重启 —— 整个 patch 层消失,`compaction-basic` 回到原生默认 `auto: true`。若卡在 #3662 之前的版本且插件已被禁用:升级即自愈(patch 层按 bundles 里列出的包装载,与 `bili-native` 的启用状态无关);手动解砖是在 HOME 层 patch `$DSH_HOME/cordis.patch.yml`(`DSH_HOME` 未设时为 `~/.dsh/cordis.patch.yml`)追加四行 `- id: preset-standard` / `preset-ptc` / `preset-minimal` / `preset-cordis`,各配 `inject: null` —— 顶层键为整体替换,清掉 pending 锁。 - **全局副本在加载期抢占 profile 副本(#2891):** dsh 解析 `dsh.profile.bundles` 里的裸包名 `billion-context` 时是 installation-anchor-first —— 先在自己的安装树(全局 npm root)里找,再找 profile 的 `node_modules`。因此只要机器上存在一份全局 `billion-context`,dsh 就加载**全局那份**,profile 里装的被静默忽略 —— 不崩溃、无日志。两者版本不一致时,实际运行的可能与 profile 声明的不同(例如 #1590 之前的全局没有 `dsh.client` web 面,设置页菜单凭空消失)。这一事实默认情况下处处不可见:`bili doctor` 现在会按 profile 逐一标记任何版本不一致的全局/本地对(#2891);用 `dsh --profile --dump-config`(读该 bundle 的 `name:` 行)可核对 dsh 实际加载了哪份。 diff --git a/docs/configuration.ja.md b/docs/configuration.ja.md index fccfc24ae2..e2c8710173 100644 --- a/docs/configuration.ja.md +++ b/docs/configuration.ja.md @@ -122,10 +122,11 @@ | `compat.streamErrorShape` | "protocol" \| "completion" | protocol | BILI_STREAM_ERROR_SHAPE | 200 がコミットされた後、上流ストリーム失敗がどのように提示されるか:プロトコルネイティブのエラーフレーム(デフォルト)またはレガシーの合成完了形状。 | | `compat.noCacheControl` | boolean | false | BILI_NO_CACHE_CONTROL | Anthropic レーンの cache_control ブレークポイントを完全にスタンプしないようにします(独自のブレークポイントポリシーを持つ上流/リレー用のエスケープハッチ)。 | | `compat.keepResponseId` | boolean | false | ACP_KEEP_RESPONSE_ID | カーネル再構築された Responses リクエストで previous_response_id を保持します(デフォルトでは削除するため、再構築されたボディは上流が発行したことのない ID を参照しません)。 | -| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | セクションは認識されるが、従来のエスケープハッチは削除された(#3666、#2028 を代替):`allowDshCompaction` キーおよび `BILI_ALLOW_DSH_COMPACTION` 環境変数はもはや存在しない — dsh ネイティブコンパクションは、すべてのレーンにおいてワイヤガードによって無条件に拒否される。残存する `dsh.allowDshCompaction` の値は、一度限りの非推奨警告とともに無視される;代わりにホスト側の抑制を適用すること(#3354/#2474)。ライブキー — `dsh.authoredCompaction`、`dsh.contextTab`、`dsh.contextTabLabel` — は以下のエントリに文書化されている。 | +| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | セクションは認識されるが、従来のエスケープハッチは削除された(#3666、#2028 を代替):`allowDshCompaction` キーおよび `BILI_ALLOW_DSH_COMPACTION` 環境変数はもはや存在しない — dsh ネイティブコンパクションは、すべてのレーンにおいてワイヤガードによって無条件に拒否される。残存する `dsh.allowDshCompaction` の値は、一度限りの非推奨警告とともに無視される;代わりにホスト側の抑制を適用すること(#3354/#2474)。ライブキー — `dsh.authoredCompaction`、`dsh.contextTab`、`dsh.contextTabLabel`、`dsh.keepCommandCompact` — は以下のエントリに文書化されている。 | | `dsh.authoredCompaction` | boolean | true (on, #3901 flip) | BILI_DSH_AUTHORED_COMPACTION | bili は dsh コンパクションの summarize 呼び出しを、拒否する代わりに折り畳みスナップショットでローカルに回答する(#3723/#3733)。0.1.203 のドッグフッド期間が維持されたため、デフォルトで ON。`false`(または環境変数 `BILI_DSH_AUTHORED_COMPACTION=0`)を設定すると、#1729 の拒否パスが復元される。 | | `dsh.contextTab` | boolean | true | BILI_DSH_CONTEXT_TAB | DSH トップバーの「上下文」/「Context」会話タブを登録する(#3862/#4237):`false` にすると、そのタブのみが削除される — コンプレッション、設定セクション、その他のすべてのサーフェスは引き続き動作する。非表示にしてもコンプレッションは無効にならない;台帳は設定セクション(会话 サブページ)、プラグインバンドル設定フェイス、Web UI、および `/acp` コマンド経由で引き続きアクセス可能。次のページ読み込み / dsh リスタート時に有効になる(スロット登録はページ読み込み時に発生);デフォルト `true` = 現在の動作は変更なし。 | | `dsh.contextTabLabel` | string | unset (built-in 「上下文」/「Context」) | — | DSH トップバーの Context タブのカスタム表示名(#4237)、例:別のプラグイン(dsh-context)が「上下文」の名前を所有している場合の "压缩账本"。トリムされた空でない文字列が組み込みラベルに優先される;空白または未設定の場合は組み込みにフォールバック。ファイル専用ティア(表示設定、#2030 に従い環境変数なし)。デフォルト未設定 = 組み込みラベルは変更なし。 | +| `dsh.keepCommandCompact` | boolean | false | BILI_DSH_KEEP_COMMAND_COMPACT | #3354 のロード時オーバーレイの下で @deepseek-ai/dsh-command-compact を**有効**のままにします: compaction-basic のみが無効化されるため、明示的な /compact コマンドが生存し、DSH 公式の ctx.commands.find(agent, "compact") 経路でブリッジするサードパーティプラグインが bili が圧縮を所有している間も引き続き動作します (#4872)。/compact によるコンパクション呼び出しは #1729 のワイヤガードを依然通過します — セッションがアクティブなフォールドブロックを持つ場合は bili の authored compaction がローカルで応答し、そうでない場合は拒否 — したがって bili の認識外にチェックポイントが置かれることはありません。デフォルト OFF = 現在の両パッケージ無効ルール; 次の dsh リスタート時に有効化 (bili-native 活性化時に解決)。 | | `resign` | scheme → { enabled?, passthrough?, credentialRef? } | {} (armed; built-in scheme sdk-hmac-sha256) | BILI_RESIGN, BILI_RESIGN_PASSTHROUGH, BILI_CODEARTS_REF, BILI_RESIGN_BENEFIT | Authorization スキームでキーイングされた再署名アーム:署名済みモデルリクエストは、すべてのエグレスボディが再署名されてトンネリングされる;署名解除できないリクエストは、パススルーがそのスキームを逐語転送にオプトインしていない限り、ローカルで 403 として拒否される。 | | `promptCache.routing` | "auto" \| "enabled" \| "disabled" | disabled | ACP_PROMPT_CACHE_ROUTING | bili 自身の `prompt_cache_key` 出力の姿勢(両方のワイヤ);クライアントが供給したキーは常に逐語的に転送される。 | | `cacheKeepalive.enabled` | boolean | false | BILI_CACHE_KEEPALIVE | Anthropic ワイヤにおけるアイドル時のプロンプトキャッシュキープアライブのマスタースイッチ(#3376):セッションがアイドルになると、bili は TTL 由来の周期で `max_tokens=1` を伴う最後の転送ボディを再生し、アップストリームのプレフィックスキャッシュをウォームに保つ;ヒットは `usage.cache_read_input_tokens` 経由で検証される;ミス/429/エラー連続/期間上限で停止。プロバイダルートごとおよびモデルごとにも設定可能。 | @@ -384,6 +385,7 @@ |-----|------|---------|-----|-------------| | `BILI_DSH_AUTHORED_COMPACTION` | boolean | true (on, #3901 flip) | — | bili が dsh のコンパクト化要約呼び出しを拒否する (#3733) 代わりに、折り畳みスナップショットでローカルに ANSWER する: アイデンティティヘッダー + カーネルレンダリングされたブロック要約、ゼロエグレス; リプレイは #2432 リベースによって認識される。 | | `BILI_DSH_CONTEXT_TAB` | boolean | true | — | dsh.contextTab (#4237) の環境変数ティア: 0/false で DSH トップバーの「上下文」/「Context」タブを削除 (その他はすべて動作維持); その他の値はファイルティアを上書きして強制オン; 未設定 = ファイルティアが適用 (デフォルト true)。次のページ読み込み / dsh 再起動時に有効化。 | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | boolean | false | — | dsh.keepCommandCompact の環境変数ティア (#4872): 1/true は #3354 のロード時オーバーレイの下で @deepseek-ai/dsh-command-compact を有効のままにします (自動コンパクションの compaction-basic のみ無効化)、ctx.commands.find(agent, "compact") でブリッジするサードパーティプラグイン向けに明示的な /compact コマンドを復元します; 0/false または未設定 = 現在の両パッケージ無効ルール。次の dsh リスタート時に有効化。 | | `BILI_DSH_MAX_TESTED_VERSION` | string | 0.2.0-rc.2 (CI e2e anchor) | — | dsh ネイティブレーンのブートノート (#4545) 背後にある最新テスト済み @deepseek-ai/dsh ビルド: 実行中のクライアントビルドは、注入バンドルより上位の最も近い node_modules/@deepseek-ai/dsh/package.json から解決される; この上限より厳密に新しい場合、サポートが実装されるまでロールバックを推奨するブート時のノート (永続ログ記録 + バナー) が 1 回発行される。片方向のみ — 上限以下または等しいビルドは沈黙する (既知の旧ビルド破損モードには独自のオーバーレイラッチ検出器がある)。警告のみ — トラフィックをゲートまたはブロックしない。ビルドが検証されるにつれて上限を引き上げる; 空文字列はこのレーンでのチェックをオフにする。解決不能/解析不能なバージョンは沈黙に向けてオープンに失敗する。 | | `BILI_IDENTITY_HARVEST` | string | off | — | 安定したメッセージ ID レーン (#5825) 向けクライアントローカルトランスクリプト/sqlite のロールアウトゲート付きループバックハーベスト。未設定/空 = OFF (完全に不活性)。`all` またはソース ID のカンマ区切りリスト (`claude,codebuddy,mcode`) は、アイデンティティがループバックであるリクエストの一致するソースを有効化する; すべての一致には `pluginLaneServerHistory` ロールアウトが ON であることも必要。判定不能なものは、ターン全体で配線前のパスにデグレード — 部分的なマッピングは決して行われない。設計上の開発/検証スイッチ (レーンはすでにクライアントごとに安全であるため)、調整ノブではない。 | | `BILI_STORAGE_BACKEND` | sqlite\|mysql | sqlite | — | storage.backend (#3931) の環境変数ティア: sqlite (デフォルト) または mysql (完全配線済み, #3388 ステップ 2+3 - 非同期シャドウキュー経由でインジェストを保存、同期読み取りは JSON エンベロープに乗る、レプリカ/拡張/GC/フォークは非同期ツイン経由 (#4911); エクスポートも)。ファイルティアに優先する。 | @@ -1959,6 +1961,7 @@ ACP ネイティブエージェント(現在は `pi` 拡張機能)は、プ | `BILI_DECOMPRESS_TMP_CAP` | `decompressTmpCap` | 50 | | `BILI_DSH_AUTHORED_COMPACTION` | `dsh.authoredCompaction` | true (on, #3901 flip) | | `BILI_DSH_CONTEXT_TAB` | `dsh.contextTab` | true | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | `dsh.keepCommandCompact` | false | | `BILI_DUMP_4XX` | `diagnostics.dump4xx` | false | | `BILI_DUMP_4XX_MAX_BYTES` | `diagnostics.dump4xxMaxBytes` | 2097152 (floor 1024) | | `BILI_DUMP_MAX_AGE_DAYS` | `diagnostics.maxAgeDays` | unset (off) | diff --git a/docs/configuration.md b/docs/configuration.md index 76d706788e..d9e9200e36 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -125,10 +125,11 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `compat.streamErrorShape` | "protocol" \| "completion" | protocol | BILI_STREAM_ERROR_SHAPE | How upstream stream failures are presented after the 200 is committed: protocol-native error frames (default) or the legacy synthesized-completion shape. | | `compat.noCacheControl` | boolean | false | BILI_NO_CACHE_CONTROL | Stop stamping Anthropic-lane cache_control breakpoints entirely (escape hatch for upstreams/relays with their own breakpoint policy). | | `compat.keepResponseId` | boolean | false | ACP_KEEP_RESPONSE_ID | Preserve previous_response_id on kernel-rebuilt Responses requests (default strips it so rebuilt bodies never reference ids the upstream never issued). | -| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | Section recognized but its former escape hatch is gone (#3666, superseding #2028): the allowDshCompaction key and the BILI_ALLOW_DSH_COMPACTION env var no longer exist — dsh native compaction is refused unconditionally by the wire guard on every lane. Leftover dsh.allowDshCompaction values are ignored with a one-time deprecation warning; apply host-side suppression instead (#3354/#2474). The live keys — dsh.authoredCompaction, dsh.contextTab, dsh.contextTabLabel — are documented in the following entries. | +| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | Section recognized but its former escape hatch is gone (#3666, superseding #2028): the allowDshCompaction key and the BILI_ALLOW_DSH_COMPACTION env var no longer exist — dsh native compaction is refused unconditionally by the wire guard on every lane. Leftover dsh.allowDshCompaction values are ignored with a one-time deprecation warning; apply host-side suppression instead (#3354/#2474). The live keys — dsh.authoredCompaction, dsh.contextTab, dsh.contextTabLabel, dsh.keepCommandCompact — are documented in the following entries. | | `dsh.authoredCompaction` | boolean | true (on, #3901 flip) | BILI_DSH_AUTHORED_COMPACTION | bili answers dsh compaction summarize calls locally with the folded snapshot instead of refusing (#3723/#3733). ON by default since the 0.1.203 dogfood window held; false (or env BILI_DSH_AUTHORED_COMPACTION=0) restores the #1729 refusal path. | | `dsh.contextTab` | boolean | true | BILI_DSH_CONTEXT_TAB | Registers the DSH top-bar 「上下文」/「Context」 conversation tab at all (#3862/#4237): false removes ONLY that tab — compression, the settings section and every other surface keep working. Hiding never disables compression; the ledger stays reachable via the settings section (会话 subpage), the plugin bundle config face, the Web UI and the /acp command. Takes effect on the next page load / dsh restart (slot registration happens at page load); default true = today's behavior unchanged. | | `dsh.contextTabLabel` | string | unset (built-in 「上下文」/「Context」) | — | Custom display name for the DSH top-bar Context tab (#4237), e.g. "压缩账本" when another plugin (dsh-context) owns the name 「上下文」. Trimmed non-empty string wins over the built-in label; blank or absent falls back to the built-in. File-only tier (display preference, no env knob per #2030). Default unset = built-in label unchanged. | +| `dsh.keepCommandCompact` | boolean | false | BILI_DSH_KEEP_COMMAND_COMPACT | Keep @deepseek-ai/dsh-command-compact ENABLED under the #3354 load-time overlay: only compaction-basic gets disabled, so the explicit /compact command survives and third-party plugins bridging through the DSH-official ctx.commands.find(agent, "compact") path keep working while bili owns compression (#4872). A /compact-triggered compaction call still passes the #1729 wire guard — answered locally by bili's authored compaction when the session holds active fold blocks, refused otherwise — so no checkpoint lands outside bili's knowledge. Default OFF = today's both-packages rule; takes effect on the next dsh restart (resolved at bili-native activation). | | `resign` | scheme → { enabled?, passthrough?, credentialRef? } | {} (armed; built-in scheme sdk-hmac-sha256) | BILI_RESIGN, BILI_RESIGN_PASSTHROUGH, BILI_CODEARTS_REF, BILI_RESIGN_BENEFIT | Re-sign arm keyed by Authorization scheme: signed model requests tunnel with every egress body re-signed; unresignable requests are refused locally 403 unless passthrough opts that scheme into verbatim forwarding. | | `promptCache.routing` | "auto" \| "enabled" \| "disabled" | disabled | ACP_PROMPT_CACHE_ROUTING | Posture of bili's own `prompt_cache_key` emission (both wires); client-supplied keys always forward verbatim. | | `cacheKeepalive.enabled` | boolean | false | BILI_CACHE_KEEPALIVE | Master switch for idle prompt-cache keepalive on the Anthropic wire (#3376): while a session goes idle, bili replays the last forwarded body with max_tokens=1 on a TTL-derived cadence so the upstream prefix cache stays warm; hits are verified via usage.cache_read_input_tokens; stops on miss/429/error-streak/duration cap. Also settable per provider route and per model. | @@ -387,6 +388,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed |-----|------|---------|-----|-------------| | `BILI_DSH_AUTHORED_COMPACTION` | boolean | true (on, #3901 flip) | — | Let bili ANSWER dsh compaction summarize calls locally with the folded snapshot instead of refusing (#3733): identity header + kernel-rendered block summaries, zero egress; replay recognized via the #2432 rebase. | | `BILI_DSH_CONTEXT_TAB` | boolean | true | — | Env tier for dsh.contextTab (#4237): 0/false removes the DSH top-bar 「上下文」/「Context」 tab (everything else keeps working); any other value forces it on over the file tier; unset = file tier applies (default true). Takes effect on next page load / dsh restart. | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | boolean | false | — | Env tier for dsh.keepCommandCompact (#4872): 1/true keeps @deepseek-ai/dsh-command-compact enabled under the #3354 load-time overlay (only auto-compaction compaction-basic stays disabled), restoring the explicit /compact command for third-party plugins bridging through ctx.commands.find(agent, "compact"); 0/false or unset = today's both-packages rule. Takes effect on the next dsh restart. | | `BILI_DSH_MAX_TESTED_VERSION` | string | 0.2.0-rc.2 (CI e2e anchor) | — | Newest-tested @deepseek-ai/dsh build behind the dsh native lane's boot note (#4545): the running client build is resolved from the nearest node_modules/@deepseek-ai/dsh/package.json above the injected bundle; being STRICTLY NEWER than this cap earns ONE boot-time note (durable log record + banner) advising roll-back until support lands. One direction only — at-or-below-cap builds stay silent (known older-build break modes have their own overlay-latch detectors). Warns only — never gates or blocks traffic. Move the cap up as builds get verified; an EMPTY string turns the check off for this lane. Unresolvable/unparseable versions fail open to silence. | | `BILI_IDENTITY_HARVEST` | string | off | — | Rollout-gated loopback harvest of client-local transcripts/sqlite for stable message-id lanes (#5825). Unset/empty = OFF (fully inert). `all` or a comma list of source ids (`claude,codebuddy,mcode`) enables matching sources for requests whose identity is loopback; every match also requires the `pluginLaneServerHistory` rollout to be ON. Anything undecidable degrades to the pre-wiring path for the whole turn — never a partial mapping. Dev/verification switch by design (the lanes are already safe per client), not a tuning knob. | | `BILI_STORAGE_BACKEND` | sqlite\|mysql | sqlite | — | Env tier for storage.backend (#3931): sqlite (default) or mysql (fully wired, #3388 steps 2+3 - saves ingest through the async shadow queue, sync reads ride the JSON envelope, replicas/ext/GC/fork via the async twins (#4911); export too). Wins over the file tier. | @@ -1973,6 +1975,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes | `BILI_DECOMPRESS_TMP_CAP` | `decompressTmpCap` | 50 | | `BILI_DSH_AUTHORED_COMPACTION` | `dsh.authoredCompaction` | true (on, #3901 flip) | | `BILI_DSH_CONTEXT_TAB` | `dsh.contextTab` | true | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | `dsh.keepCommandCompact` | false | | `BILI_DUMP_4XX` | `diagnostics.dump4xx` | false | | `BILI_DUMP_4XX_MAX_BYTES` | `diagnostics.dump4xxMaxBytes` | 2097152 (floor 1024) | | `BILI_DUMP_MAX_AGE_DAYS` | `diagnostics.maxAgeDays` | unset (off) | @@ -2152,6 +2155,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes | `BILI_ALLOW_DSH_COMPACTION` | **REMOVED in #3666** (superseding #2028). The former switch let dsh's built-in auto-compaction run through bili by lifting the wire-level refusal (#1729); because a landed dsh checkpoint durably shadows the raw conversation history — irreversible, destroying the proxy's compression substrate — the escape hatch has been deleted outright: dsh native compaction calls are now intercepted unconditionally on every lane bili serves, on every build — refused (422) by default, or answered locally by bili itself when `BILI_DSH_AUTHORED_COMPACTION` is set (row below). Any leftover value — `"dsh": { "allowDshCompaction": true }`, a bare top-level `"allowDshCompaction"` in an older file, or the old env var — is ignored, with a one-time deprecation warning naming it. If you need dsh-side checkpoints out entirely, apply host-side suppression instead: the shipped bundle patch (`auto: false`) on non-web profiles, or the #3354 load-time overlay / #2474 full-snapshot override of preset-standard on web profiles. | | `BILI_DSH_CONTEXT_TAB` | Set `0` to REMOVE the DSH top-bar 「上下文」/「Context」 conversation tab (#4237) — the name collides with dsh-context's identically-named tab on co-installed machines, and no user-side switch existed before this knob. Hiding removes ONLY the tab: compression, the settings section (会话 subpage), the plugin bundle config face, the Web UI and the /acp command are all unaffected — the ledger stays reachable there. Any other value (`1`, `true`, …) forces the tab on over the file tier; unset lets the config-file `dsh.contextTab` boolean apply (default true = today's behavior). The setting is shipped to the DSH page through the existing snapshot + `/bili/origin` carriers and read at page load, so it takes effect on the next page load / dsh restart without a proxy restart. The display NAME of the tab is a separate file-only tier: `dsh.contextTabLabel`. | | `BILI_DSH_AUTHORED_COMPACTION` | Set `1` to have bili itself ANSWER dsh's compaction summarize calls locally instead of refusing them (#3733). Prerequisites per call: the #1729 guard fires (marker-decisive; unconditional since #3651) and the session holds at least one ACTIVE fold block. The reply is forged with zero egress (the autoModeForge #2740 discipline): an identity header `` plus every active block's summary in the kernel render format — exactly the bytes the model already reads upstream, so client display, upstream context and server state agree for the first time, and dsh's checkpoint file shrinks (#3723's unbounded growth loop). Originals stay recoverable via CCR/export; the landed checkpoint is recognized on replay through the same #2432 rebase as a foreign one, but recorded as `dshAuthoredCheckpointLanded` (info, not warn). Env-only for the rollout window; read per-request, no restart needed. | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | Set `1` to keep `@deepseek-ai/dsh-command-compact` ENABLED under the #3354 load-time overlay: only the auto-compaction package (`compaction-basic`) gets disabled, so the explicit `/compact` command survives and third-party plugins bridging through the DSH-official `ctx.commands.find(agent, "compact")` path keep working while bili owns compression on the lane (#4872). A `/compact`-triggered compaction call STILL passes the #1729 wire guard — answered locally by bili's authored compaction when the session holds active fold blocks, refused otherwise — so no checkpoint lands outside bili's knowledge; the knob restores the command surface, it does not open the auto path. File key: `dsh.keepCommandCompact` (same value). Default OFF = today's both-packages rule, zero drift. While the knob is unset, bili-native additionally registers a visible `/compact` stub in web profiles (overlay latched) so a typed `/compact` gets an explicit answer pointing at /acp and this knob — dsh would otherwise demote the unknown command to a plain model message with no signal (#6814). Resolved once at bili-native activation, so a change takes effect on the next dsh/host restart. | | `BILI_NO_CACHE_CONTROL` | Set `1` to disable bili's Anthropic-lane `cache_control` breakpoint stamping (#1637, shipped in #1639). On by default: Anthropic-style upstreams cache only what is explicitly breakpointed (max 4 per request, counted across system + tools + message blocks combined), so bili marks the system block plus up to 3 cumulative message marks — a marked message stays marked (byte-stable prefix), marks die only by folding, and the last 3 stable messages carry the advancing frontier. Any client-set `cache_control` (message blocks, tools entries) suppresses bili's stamps entirely — client-managed caching wins. Marks persist with the session. This switch is the escape hatch for upstreams that reject the field or relays with their own breakpoint policy. Plain-proxy Anthropic lane only; OpenAI/Responses lanes cache implicitly and are never stamped. Config-file twin: [`compat.noCacheControl`](#compat) — the env var wins. | | `BILI_CACHE_KEEPALIVE` | Set `1` to turn ON idle prompt-cache keepalive for the Anthropic wire (#3376) — see [`cacheKeepalive`](#cachekeepalive) for the full mechanism, stop rules, and cost notes. File twin: `"cacheKeepalive": { "enabled": true }`; the env var wins. Default OFF. | | `BILI_CACHE_KEEPALIVE_TTL_FACTOR` | Cadence factor applied to the detected/assumed cache-TTL tier (default `0.9` → pings at ~4.5 min on the 5-min tier, ~54 min on the 1-hour tier). Must be in `(0, 1]`. File twin: `cacheKeepalive.ttlFactor`. | diff --git a/docs/configuration.zh-CN.md b/docs/configuration.zh-CN.md index 99f67ab91c..4b578e8180 100644 --- a/docs/configuration.zh-CN.md +++ b/docs/configuration.zh-CN.md @@ -125,10 +125,11 @@ | `compat.streamErrorShape` | "protocol" \| "completion" | protocol | BILI_STREAM_ERROR_SHAPE | 200 已提交后上游流失败的呈现方式:协议原生错误帧(默认)或旧版合成完成形态。 | | `compat.noCacheControl` | boolean | false | BILI_NO_CACHE_CONTROL | 完全停止 Anthropic 通道的 cache_control 断点打标(面向拒收该字段或有自有断点策略的上游/中继的逃生门)。 | | `compat.keepResponseId` | boolean | false | ACP_KEEP_RESPONSE_ID | 在内核重建的 Responses 请求上保留 previous_response_id(默认剔除,使重建请求体永不引用上游从未签发过的响应 id)。 | -| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | 段仍被识别,但其原逃生门已移除(#3666,取代 #2028):allowDshCompaction 键与 BILI_ALLOW_DSH_COMPACTION 环境变量已不存在——dsh 原生压缩现在在所有线路上被无条件拒绝。遗留的 dsh.allowDshCompaction 取值会被忽略(一次性弃用警告);请改用宿主侧抑制(#3354/#2474)。存活的键——dsh.authoredCompaction、dsh.contextTab、dsh.contextTabLabel——见接下来的条目。 | +| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | 段仍被识别,但其原逃生门已移除(#3666,取代 #2028):allowDshCompaction 键与 BILI_ALLOW_DSH_COMPACTION 环境变量已不存在——dsh 原生压缩现在在所有线路上被无条件拒绝。遗留的 dsh.allowDshCompaction 取值会被忽略(一次性弃用警告);请改用宿主侧抑制(#3354/#2474)。存活的键——dsh.authoredCompaction、dsh.contextTab、dsh.contextTabLabel、dsh.keepCommandCompact——见接下来的条目。 | | `dsh.authoredCompaction` | boolean | true (on, #3901 flip) | BILI_DSH_AUTHORED_COMPACTION | bili 用折叠快照本地应答 dsh 压缩摘要请求而非拒绝(#3723/#3733)。0.1.203 狗粮窗口守住后默认开启;false(或环境变量 BILI_DSH_AUTHORED_COMPACTION=0)恢复 #1729 拒绝路径。 | | `dsh.contextTab` | boolean | true | BILI_DSH_CONTEXT_TAB | 是否注册 DSH 顶栏「上下文」会话标签页(#3862/#4237):false 只移除该标签页——压缩、设置页一节及其余所有入口不受影响。隐藏绝不关闭压缩;账本仍可从设置页(会话子页)、插件 bundle 配置面、Web UI 与 /acp 命令查看。下次页面加载 / dsh 重启生效(槽位注册发生在页面加载时);默认 true = 现状不变。 | | `dsh.contextTabLabel` | string | unset (built-in 「上下文」/「Context」) | — | DSH 顶栏上下文标签页的自定义显示名(#4237),例如另一插件(dsh-context)已占用「上下文」时改为"压缩账本"。去空白后的非空字符串优先于内置名;留空或缺省回退内置名。仅文件层(显示偏好,按 #2030 不设 env 开关)。默认缺省 = 内置名不变。 | +| `dsh.keepCommandCompact` | boolean | false | BILI_DSH_KEEP_COMMAND_COMPACT | 在 #3354 加载期 overlay 下保留 @deepseek-ai/dsh-command-compact **启用**:只禁用 compaction-basic,显式 /compact 命令得以保留,通过 DSH 官方 ctx.commands.find(agent, "compact") 通路桥接的第三方插件在 bili 持有压缩期间继续可用(#4872)。/compact 触发的压缩调用仍经 #1729 wire guard——会话有活跃折叠块时由 bili authored compaction 本地应答,否则拒绝——因此不会有检查点落在 bili 不知情处。默认关 = 现状两包同禁;下次 dsh 重启生效(bili-native 激活时解析)。 | | `resign` | scheme → { enabled?, passthrough?, credentialRef? } | {} (armed; built-in scheme sdk-hmac-sha256) | BILI_RESIGN, BILI_RESIGN_PASSTHROUGH, BILI_CODEARTS_REF, BILI_RESIGN_BENEFIT | 按 Authorization 方案键控的重签名臂:可重签名的模型请求全程重签转发;无法重签的请求本地 403 拒绝,除非该方案经 passthrough 选择原文透传。 | | `promptCache.routing` | "auto" \| "enabled" \| "disabled" | disabled | ACP_PROMPT_CACHE_ROUTING | bili 自注入 `prompt_cache_key` 的姿态(两条 wire 同时生效);客户端自带的 key 永远原样转发。 | | `cacheKeepalive.enabled` | boolean | false | BILI_CACHE_KEEPALIVE | Anthropic 线路空闲期提示缓存保活总开关(#3376):会话空闲时按 TTL 推导的节奏以 max_tokens=1 重放最后一次转发的请求体,维持上游前缀缓存温热;以 usage.cache_read_input_tokens 验证命中,miss/429/连续错误/时长上限即停;支持逐 provider 路由与逐模型覆盖。 | @@ -387,6 +388,7 @@ |-----|------|---------|-----|-------------| | `BILI_DSH_AUTHORED_COMPACTION` | boolean | true (on, #3901 flip) | — | 让 bili 本地应答 dsh 压缩摘要请求(返回折叠快照而非拒绝,#3733):身份头 + 内核渲染格式的块摘要,零出口流量;重放经 #2432 再基线识别。 | | `BILI_DSH_CONTEXT_TAB` | boolean | true | — | dsh.contextTab 的 env 层(#4237):0/false 移除 DSH 顶栏「上下文」标签页(其余一切照常工作);其他取值强制开启并覆盖文件层;缺省 = 按文件层取值(默认 true)。下次页面加载 / dsh 重启生效。 | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | boolean | false | — | dsh.keepCommandCompact 的 env 层(#4872):1/true 在 #3354 加载期 overlay 下保留 @deepseek-ai/dsh-command-compact 启用(只禁自动压缩 compaction-basic),恢复显式 /compact 命令给通过 ctx.commands.find(agent, "compact") 桥接的第三方插件;0/false 或缺省 = 现状两包同禁。下次 dsh 重启生效。 | | `BILI_DSH_MAX_TESTED_VERSION` | string | 0.2.0-rc.2 (CI e2e anchor) | — | “dsh native lane 启动提示的“我们测过的最高版本”上限(#4545):从注入包上方最近的 node_modules/@deepseek-ai/dsh/package.json 读出运行中的构建,**严格高于**上限才弹一条启动提示(持久日志 + 横幅),建议先回滚到上限版本。只覆盖"更新"一个方向:≤ 上限保持静默(旧版已知坏法有专门的失锁探测)。只提示、绝不拦截或阻断流量;新版本验证通过后抬高上限,空字符串 = 关闭本 lane 检查;读不到/解析不了的版本按静默处理。” | | `BILI_IDENTITY_HARVEST` | string | off | — | #5825 身份信道接线的采集开关(灰度门控下的回环本地转录/SQLite 采集):缺省关闭、完全惰性;`all` 或逗号列表(`claude,codebuddy,mcode`)开启对应来源,且仅对回环身份请求生效,同时要求 pluginLaneServerHistory 灰度为开。任何无法判定的情形整轮退化为接线前路径,绝不做部分映射。设计上是开发/验证开关而非调参旋钮。 | | `BILI_STORAGE_BACKEND` | sqlite\|mysql | sqlite | — | storage.backend 的环境变量层(#3931):sqlite(默认)或 mysql(已接线,#3388 第二+三步 —— 保存经异步影子队列入 mysql,同步读走 JSON 信封,replicas/ext/GC/fork 走异步孪生(#4911);export 同样支持)。优先于文件层。 | @@ -1950,6 +1952,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 | `BILI_DECOMPRESS_TMP_CAP` | `decompressTmpCap` | 50 | | `BILI_DSH_AUTHORED_COMPACTION` | `dsh.authoredCompaction` | true (on, #3901 flip) | | `BILI_DSH_CONTEXT_TAB` | `dsh.contextTab` | true | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | `dsh.keepCommandCompact` | false | | `BILI_DUMP_4XX` | `diagnostics.dump4xx` | false | | `BILI_DUMP_4XX_MAX_BYTES` | `diagnostics.dump4xxMaxBytes` | 2097152 (floor 1024) | | `BILI_DUMP_MAX_AGE_DAYS` | `diagnostics.maxAgeDays` | unset (off) | @@ -2124,6 +2127,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 | `BILI_ALLOW_DSH_COMPACTION` | **#3666 起移除**(取代 #2028)。原开关通过解除 wire 级拒绝(#1729)放行 dsh 内置自动压缩;由于落地的 dsh checkpoint 会永久覆盖原始会话历史——不可逆、摧毁代理的压缩基底——该逃生门已被整体删除:所有 bili 服务的线路上,dsh 原生压缩调用现在一律被无条件拦截,所有构建一致——默认拒绝(422),或在设置 `BILI_DSH_AUTHORED_COMPACTION`(下一行)时由 bili 本地应答。任何遗留取值——`"dsh": { "allowDshCompaction": true }`、旧文件里裸写在顶层的 `"allowDshCompaction"`、或旧环境变量——都会被忽略,并给出一条点名该键的一次性弃用警告。若要彻底避免 dsh 侧 checkpoint 落地,请改用宿主侧抑制:非 web profile 下随附 bundle patch(`auto: false`),web profile 下用 #3354 加载期 overlay 或 #2474 对 preset-standard 的完整快照覆盖。 | | `BILI_DSH_CONTEXT_TAB` | 设为 `0` **移除** DSH 顶栏「上下文」会话标签页(#4237)——同名标签页与同机安装的 dsh-context 冲突,且此前没有用户侧开关。隐藏只移除该标签页:压缩、设置页一节(会话子页)、插件 bundle 配置面、Web UI 与 /acp 命令全部不受影响——账本仍可从这些入口查看。其他取值(`1`、`true`、…)强制开启并覆盖文件层;缺省则按配置文件 `dsh.contextTab` 布尔值取值(默认 true = 现状不变)。设置经既有的快照 + `/bili/origin` 载体送达 DSH 页面并在页面加载时读取,因此下次页面加载 / dsh 重启即生效,无需重启代理。标签页的显示**名称**是另一个仅文件层的键:`dsh.contextTabLabel`。 | | `BILI_DSH_AUTHORED_COMPACTION` | 设为 `1` 让 bili **本地应答** dsh 的压缩摘要调用,而不是拒绝它们(#3733)。每次调用的前置条件:#1729 守卫触发(由标记决定;#3651 起无条件)、会话至少持有一个 ACTIVE 折叠块。应答零出口流量构造(autoModeForge #2740 纪律):一行身份头 `` 加上每个活跃块的内核渲染格式摘要——与模型在上游已读到的字节完全一致,客户端显示、上游上下文与服务端状态首次吻合,dsh 的 checkpoint 文件随之缩小(终结 #3723 的无界增长环)。原始历史随时可经 CCR/导出恢复;落地的检查点在重放时经同一 #2432 rebase 识别(与外部 checkpoint 同路径),但记为 `dshAuthoredCheckpointLanded`(info 而非 warn)。灰度窗口期 env-only(无配置文件键);每请求读取,无需重启。 | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | 设为 `1` 在 #3354 加载期 overlay 下保留 `@deepseek-ai/dsh-command-compact` **启用**:只禁用自动压缩包(`compaction-basic`),显式 `/compact` 命令得以保留,经 DSH 官方 `ctx.commands.find(agent, "compact")` 通路桥接的第三方插件在 bili 持有该泳道期间继续可用(#4872)。`/compact` 触发的压缩调用**仍经** #1729 wire guard——会话有活跃折叠块时由 bili authored compaction 本地应答,否则拒绝——因此没有检查点落在 bili 不知情处;该开关恢复的是命令面,不放开自动路径。文件键:`dsh.keepCommandCompact`(取值相同)。默认关 = 现状两包同禁,零漂移。开关未设时,bili-native 另在 web profile(overlay 已挂上)注册一个可见的 `/compact` 占位命令:输入的 `/compact` 会得到指向 /acp 与该开关的明确答复——否则 dsh 会把未知命令静默降级为普通模型消息、无任何提示(#6814)。bili-native 激活时一次性解析,改动在下次 dsh/宿主重启生效。 | | `BILI_NO_CACHE_CONTROL` | 设为 `1` 关闭 bili 在 Anthropic 通道上的 `cache_control` 断点标注(#1637,随 #1639 落地)。默认开启:Anthropic 系上游只缓存被显式打断点的内容(每请求最多 4 个,按 system + tools + 消息块合并计数),因此 bili 会标注 system 块加上至多 3 个累积消息断点——被标注的消息保持标注(前缀字节稳定),断点只随折叠消亡,最近 3 条稳定消息承载推进前沿。客户端自设的任何 `cache_control`(消息块、tools 条目)都会完全抑制 bili 的标注——客户端自管缓存优先。断点随会话持久化。本开关是逃生阀:用于拒绝该字段的上游或有自己断点策略的中继。仅限 plain-proxy Anthropic 通道;OpenAI/Responses 通道隐式缓存,从不标注。配置文件对应项:[`compat.noCacheControl`](#compat) —— 环境变量优先。 | | `BILI_CACHE_KEEPALIVE` | 设为 `1` 开启 Anthropic 线路的空闲期提示缓存保活(#3376)——完整机制、停止规则与成本说明见 [`cacheKeepalive`](#cachekeepalive)。配置文件对应项:`"cacheKeepalive": { "enabled": true }`;环境变量优先。默认关闭。 | | `BILI_CACHE_KEEPALIVE_TTL_FACTOR` | 作用于检测/假定缓存 TTL 档位的节奏因子(默认 `0.9` → 5 分钟档约每 4.5 分钟一次,1 小时档约每 54 分钟一次)。取值须在 `(0, 1]`。配置文件对应项:`cacheKeepalive.ttlFactor`。 | diff --git a/docs/lifecycle.md b/docs/lifecycle.md index 97c4400148..4c700e8538 100644 --- a/docs/lifecycle.md +++ b/docs/lifecycle.md @@ -50,6 +50,7 @@ | `BILI_ALLOW_DSH_COMPACTION` | dsh compaction | dsh compaction opt-in(env 语义同 BILI_PERSIST 家族) | 转正后移 §2 | opt-in(`=1`) | | `BILI_SNAPSHOT_SHADOW` | #3756 | snapshot-render 影子观测:每个 armed turn 计算快照视图但**不使用**(出站仍走 legacy 路径),与实际发送对比记 per-session 计数(面板 + `snapshot-shadow` 诊断话题)——render 引擎在 rollout 翻转前用真实流量证明健康(dry-run-then-flip,同存储 #2815 shadow→#3818 full 纪律) | render 车道转正(rollout 100% 且影子计数归稳)后退役 | 默认 on(render lane 本身 rollout 0%,纯观测) | | `BILI_DSH_AUTHORED_COMPACTION` | #3733 | dsh 原生 compaction summarize 调用由 #1729 guard 拒绝改为**本地应答折叠快照**(零出账;dsh 记 checkpoint、会话文件收缩) | adoption 后按 #2028 模式转 file/web 开关,env 退役(file 键 `dsh.authoredCompaction` 已镜像) | 0.1.203 dogfood 站稳后默认 on;`=0` 回 #1729 拒绝路径 | +| `BILI_DSH_KEEP_COMMAND_COMPACT` | #4872(PR #4883) | #3354 加载期 overlay 的作用域收窄开关:ON 时 overlay 只禁 compaction-basic、保留显式 /compact 命令包(command-compact),恢复经 DSH 官方 `ctx.commands.find(agent, "compact")` 桥接的第三方插件;env > file 键 `dsh.keepCommandCompact` > 默认 false(零漂移);bili-native 激活时一次性解析,下次 dsh/宿主重启生效 | 下一期服务端压缩转正、自动压缩约束彻底放开后(owner 方向,#4872),command-compact 默认保留、本开关失去意义,随 overlay 作用域重做一并退役 | opt-in(默认 OFF = 现状两包同禁规则) | | `BILI_PI_INLINE` | #3278(#4669 默认翻转,#4687 收回) | pi inline 模式(需手动开启,默认保持旧行为,owner 禁改默认值):不起 proxy 进程,fetch 链在 intercept 之下的一个环节把伪 origin 流量路由进进程内引擎(inline-engine.ts,跑同 startServer 的每请求管线);`=1/on/yes/TRUE` 或 file 家 `"pi": {"inline": true}` 显式开启(显式开启压过 attach 目标);`bili pi-inline` 一键车道预置该变量 | inline 车道稳定一个版本周期后转 §2 常设 | opt-in(不设置时 attach/spawn 行为与旧版完全一致) | | `BILI_OPENCODE_INLINE` | #3278 opencode 移植(#4687) | opencode inline 模式(需手动开启,默认保持旧行为 spawn,owner 决定不改默认):与 pi 同构——不起 proxy 进程,模型 URL 被 V2 route/intercept 改写成伪 origin 后由进程内引擎接住(bun 宿主已验:引擎 boot/dispatch 全绿);`=1/on/yes/TRUE` 或 file 家 `"opencode": {"inline": true}` 显式开启(显式开启压过 attach 目标);`bili opencode-inline` 一键车道 | 同 pi inline 车道节奏 | opt-in(不设置时 attach/spawn 行为与旧版完全一致) | | `BILI_INLINE_DEBUG` | #4669 | 仅 inline 车道:引擎 stderr 日志腿默认静默(stderr 是 pi 的交互终端,日志会挤掉输入框;默认只写 bili.log),设 1 恢复 stderr 输出用于排查 | 随 inline 车道(#3278)走 | 排查逃生口 | diff --git a/src/agent/dsh-compaction-disable.ts b/src/agent/dsh-compaction-disable.ts index 7f997f8b47..a901d4a759 100644 --- a/src/agent/dsh-compaction-disable.ts +++ b/src/agent/dsh-compaction-disable.ts @@ -32,6 +32,15 @@ // bili-native can surface which entries the overlay actually covered (the // bundle-patch gate rows may target ids a profile does not ship — their miss // is otherwise visible only in the host loader log). +// #4872: the overlay SCOPE is knob-gated. With dsh.keepCommandCompact ON +// (env BILI_DSH_KEEP_COMMAND_COMPACT), bili-native declares the verdict with +// keepCommandCompact and the transform disables ONLY compaction-basic, +// leaving the explicit /compact command (command-compact) armed so third-party +// plugins bridging through the DSH-official ctx.commands.find(agent, "compact") +// path keep working. A /compact-triggered compaction call still passes the +// #1729 wire guard — answered locally by #3733 authored compaction when the +// session holds active blocks, refused otherwise — so no checkpoint lands +// outside bili's knowledge. Default OFF = the original both-packages rule. // #7190: runtime-registered presets (a plugin calling // ctx.agentPresets.register(definition) from JS after boot) bypass EVERY // config layer: dsh's registry mounts the definition's nested rows straight @@ -88,13 +97,36 @@ export function compactionDisablePatchRows(): string { // refusal guard (#1729) as backstop. const DSH_COMPACTION_VERDICT_KEY = "__BILI_DSH_COMPACTION_VERDICT__"; -/** bili-native calls this from apply() when its plan keeps the lane owned. */ -export function declareDshCompactionActive(): void { - (globalThis as Record)[DSH_COMPACTION_VERDICT_KEY] = "active"; +type DshCompactionVerdict = { active: true; keepCommandCompact?: boolean }; + +/** bili-native calls this from apply() when its plan keeps the lane owned. + * #4872: options.keepCommandCompact narrows the overlay to compaction-basic + * only (the explicit /compact command stays armed); absent/false keeps the + * original both-packages rule. */ +export function declareDshCompactionActive(options?: { keepCommandCompact?: boolean }): void { + const verdict: DshCompactionVerdict = { active: true }; + if (options?.keepCommandCompact === true) verdict.keepCommandCompact = true; + (globalThis as Record)[DSH_COMPACTION_VERDICT_KEY] = verdict; +} + +function readDshCompactionVerdict(): DshCompactionVerdict | null { + const v = (globalThis as Record)[DSH_COMPACTION_VERDICT_KEY]; + // Tolerate the pre-#4872 string form so a mixed-version process mid-update + // degrades to the original both-packages rule instead of losing the gate. + if (v === "active") return { active: true }; + if (v !== null && typeof v === "object" && (v as { active?: unknown }).active === true) { + return v as DshCompactionVerdict; + } + return null; } export function isDshCompactionActive(): boolean { - return (globalThis as Record)[DSH_COMPACTION_VERDICT_KEY] === "active"; + return readDshCompactionVerdict() !== null; +} + +/** #4872: the active verdict carries the keep-command-compact scope option. */ +export function dshCompactionKeepCommandCompact(): boolean { + return readDshCompactionVerdict()?.keepCommandCompact === true; } /** Test hook: forget any declaration (back to "bili-native never ran"). */ @@ -202,30 +234,34 @@ type PresetRow = { name?: unknown; group?: unknown; config?: unknown }; /** Count compaction-basic/command-compact rows the disable walk would mark * (recursing through group rows with the SAME shape gate as * disableBasicCompaction, so telemetry counts never drift from what the - * rewrite actually did). Zero = nothing to rewrite here. */ -function countCompactionRows(rows: readonly unknown[]): number { + * rewrite actually did). Zero = nothing to rewrite here. #4872: honors the + * verdict scope — keepCommandCompact counts compaction-basic rows only. */ +function countCompactionRows(rows: readonly unknown[], keepCommandCompact: boolean): number { let n = 0; for (const row of rows) { if (row === null || typeof row !== "object") continue; const r = row as PresetRow; - if (r.name === DSH_COMPACTION_BASIC_PACKAGE || r.name === DSH_COMMAND_COMPACT_PACKAGE) n += 1; - else if (r.group && Array.isArray(r.config)) n += countCompactionRows(r.config); + if (r.name === DSH_COMPACTION_BASIC_PACKAGE || (!keepCommandCompact && r.name === DSH_COMMAND_COMPACT_PACKAGE)) n += 1; + else if (r.group && Array.isArray(r.config)) n += countCompactionRows(r.config, keepCommandCompact); } return n; } /** Mark every compaction row of a preset plugins tree disabled. Pure: returns * detached copies and never mutates the input rows (the resolved config may - * be shared with other consumers). */ -export function disableBasicCompaction(rows: readonly unknown[]): unknown[] { + * be shared with other consumers). #4872: opts.keepCommandCompact leaves the + * explicit /compact command (command-compact) armed — only compaction-basic + * rows get marked, untouched rows pass through by identity. */ +export function disableBasicCompaction(rows: readonly unknown[], opts?: { keepCommandCompact?: boolean }): unknown[] { + const keep = opts?.keepCommandCompact === true; return rows.map((row) => { if (row === null || typeof row !== "object") return row; const r = row as PresetRow & Record; - if (r.name === DSH_COMPACTION_BASIC_PACKAGE || r.name === DSH_COMMAND_COMPACT_PACKAGE) { + if (r.name === DSH_COMPACTION_BASIC_PACKAGE || (!keep && r.name === DSH_COMMAND_COMPACT_PACKAGE)) { return { ...r, disabled: true }; } if (r.group && Array.isArray(r.config)) { - return { ...r, config: disableBasicCompaction(r.config) }; + return { ...r, config: disableBasicCompaction(r.config, opts) }; } return row; }); @@ -256,10 +292,11 @@ export function disableRuntimePresetCompaction(definition: unknown): unknown { const def = definition as { id?: unknown; plugins?: unknown }; if (typeof def.id !== "string" || !Array.isArray(def.plugins)) return definition; if (!isDshCompactionActive()) return definition; - const rows = countCompactionRows(def.plugins as readonly unknown[]); + const keepCommandCompact = dshCompactionKeepCommandCompact(); + const rows = countCompactionRows(def.plugins as readonly unknown[], keepCommandCompact); if (rows === 0) return definition; noteRuntimePresetCoverage(def.id.slice(0, 120), rows); - return { ...def, plugins: disableBasicCompaction(def.plugins as readonly unknown[]) }; + return { ...def, plugins: disableBasicCompaction(def.plugins as readonly unknown[], { keepCommandCompact }) }; } /** @@ -314,12 +351,15 @@ export function registerCompactionDisable(ctx: CompactionDisableHost): void { // their resolved config object identity. const config = (resolved ?? {}) as { plugins?: unknown }; if (!Array.isArray(config.plugins)) return resolved; - const compactionRows = countCompactionRows(config.plugins); + // #4872: honor the verdict's scope option — keepCommandCompact + // narrows the rewrite to compaction-basic rows only. + const keepCommandCompact = dshCompactionKeepCommandCompact(); + const compactionRows = countCompactionRows(config.plugins, keepCommandCompact); if (compactionRows === 0) return resolved; const rawName = this?.entry?.options?.name; const entryName = typeof rawName === "string" ? rawName : "unnamed-entry"; noteGateCoverage(entryName.slice(0, 120), compactionRows, entryName === DSH_AGENT_PRESET_PACKAGE); - return { ...config, plugins: disableBasicCompaction(config.plugins) }; + return { ...config, plugins: disableBasicCompaction(config.plugins, { keepCommandCompact }) }; }, { global: true }); } // Publish only after the middleware is registered; the host owns both lifetimes. diff --git a/src/agent/dsh-native.ts b/src/agent/dsh-native.ts index 8654a7b2b7..a2f8228a89 100644 --- a/src/agent/dsh-native.ts +++ b/src/agent/dsh-native.ts @@ -60,7 +60,7 @@ import { VERSION } from "../version.js"; import { APIG_RESIGN_SCHEME, unresolvedRefusals } from "../apig-resign.js"; import { adminRelayEnabled, resolveResignSettings } from "../config.js"; import { decodeRequestBody } from "../content-encoding.js"; -import { dshContextTabEnabled, dshContextTabLabel, limitsDecodedBytes } from "../knobs.js"; +import { dshContextTabEnabled, dshContextTabLabel, dshKeepCommandCompactEnabled, limitsDecodedBytes } from "../knobs.js"; import { MIN_ASSUMED_WINDOW_TOKENS } from "../util.js"; import { markNativeHost, nativeAttachOrigin, nativeBootstrapGate, nativeProxyScriptPath, proxyEnvOrigin, singleFlight } from "./native-bootstrap.js"; import { bodyOverWindowDetail as sharedBodyOverWindowDetail, getDeclaredModelEndpoints, installNativeFetchIntercept, liveStateSlotEffect, noteRoutedOrigin, observeRoutedOrigin, routedBiliModelUrl, setDeclaredModelEndpoints, type GateVerdict, type NativeInterceptState } from "./native-intercept.js"; @@ -70,7 +70,7 @@ import { installNativeWebSocketIntercept } from "./native-ws-intercept.js"; import { asciiHeaderValue, fetchManifest, fetchProxyVersion, fetchStatus, fetchStatusLatest, forwardTool, reportAttributionHealth, reportRuntimeInfo, waitForProxyVersion, type ManifestTool } from "./shared.js"; import { createForkAdopter, sideShapedBody } from "./fork-adopt.js"; import { clearIncrementalProbe, createPrepareDirectSend, INCREMENTAL_TURN_MARKER_HEADER, INCREMENTAL_TURN_ID_HEADER, newIncrementalTurnId, noteIncrementalRejection, noteIncrementalAck, planIncrementalTurn, probeIncrementalTurns, rememberOriginalBody, sweepStale, wireMessagesLookAnthropic, type IncrementalWireMessage } from "./incremental-client.js"; -import { compactionCoverageText, declareDshCompactionActive, detectCompactionOverlayGap } from "./dsh-compaction-disable.js"; +import { compactionCoverageText, declareDshCompactionActive, detectCompactionOverlayGap, dshCompactionGateTelemetry, dshCompactionKeepCommandCompact } from "./dsh-compaction-disable.js"; import { maskUrlForDiagnostics } from "../log-mask.js"; import { mediaBytesOfWireBody } from "./media-bytes.js"; import { conversationRecallStats, learnConversation, recallBoundaryOfMessages, recallConversation, recallHistoryFingerprints, recallLaneHasEntries, recallLaneKey } from "./conversation-recall.js"; @@ -1981,7 +1981,10 @@ export async function apply(ctx: PluginContext): Promise { // kill-switched or disabled bili-native never declares, and the gate then // leaves every row stock while its service still lets the presets boot // (disabling the plugin must not brick session creation, #3662). - declareDshCompactionActive(); + // #4872: the declaration also carries the verdict scope — dsh.keepCommand- + // Compact ON narrows the overlay to compaction-basic only (the explicit + // /compact command stays armed); OFF keeps the both-packages rule. + declareDshCompactionActive({ keepCommandCompact: dshKeepCommandCompactEnabled() }); const owner = beginToolsOwner(ctx); register.dead = false; @@ -2889,36 +2892,38 @@ export async function apply(ctx: PluginContext): Promise { // whose internal 'internal/config' hook moved. Surface it once through the // durable channel (GUI hosts swallow stderr); ACP compression is // unaffected. - if (!webProfileWarned) { - let bundles: readonly string[] | undefined; - try { - if (typeof ctx.inject === "function") { - ctx.inject(["profileContext"], (sub) => { - bundles = sub.profileContext?.startedBundles; - }); - } else { - bundles = ctx.profileContext?.startedBundles; - } - } catch { - // older dsh builds without the service: diagnostic only + // #5686: the bundles/gap probes are pure structural typeof checks on the + // cordis host surface — cheap, side-effect-free — so they run on EVERY + // apply() now; the once-guard below only gates the durable NOTE. The + // pre-#5686 code ran the latch check only inside the + // @deepseek-ai/dsh-web-app branch, so every other form — in particular + // the desktop app-in-bundle layout where NO @deepseek-ai/* package sits + // under the profile and the core ships inside the app — booted SILENTLY + // when the #3354 disable middleware could not latch: native + // auto-compaction armed with zero boot-time signal while bili's wire + // refusals were its only backstop. (#4872/#6814: the /compact stub + // registration further down reuses the same verdicts.) + let bundles: readonly string[] | undefined; + try { + if (typeof ctx.inject === "function") { + ctx.inject(["profileContext"], (sub) => { + bundles = sub.profileContext?.startedBundles; + }); + } else { + bundles = ctx.profileContext?.startedBundles; } - // #5686: the latch check (pure structural typeof probes on the cordis - // host surface — cheap, side-effect-free) runs for EVERY profile - // shape now. The pre-#5686 code only called it inside the - // @deepseek-ai/dsh-web-app branch, so every other form — in - // particular the desktop app-in-bundle layout where NO @deepseek-ai/* - // package sits under the profile and the core ships inside the app — - // booted SILENTLY when the #3354 disable middleware could not latch: - // native auto-compaction armed with zero boot-time signal while bili's - // wire refusals were its only backstop. - const isWeb = bundles !== undefined && bundles.includes("@deepseek-ai/dsh-web-app"); - const gap = detectCompactionOverlayGap(ctx); + } catch { + // older dsh builds without the service: diagnostic only + } + const isWeb = bundles !== undefined && bundles.includes("@deepseek-ai/dsh-web-app"); + const gap = detectCompactionOverlayGap(ctx); + if (!webProfileWarned) { webProfileWarned = true; if (gap !== null) { // #3806/#5686: overlay failed to latch -> boot-time alarm on ANY profile shape. persistClientEvent(`profile${isWeb ? " bundles include @deepseek-ai/dsh-web-app and" : bundles === undefined ? " shape could not be introspected (older dsh build) and" : " (non-web-app bundle list) and"} the load-time compaction-disable overlay (#3354) could not latch on this dsh build (${gap}) — dsh native auto-compaction is likely ARMED here. bili's wire-level refusal (#1729) refuses routed compaction calls but CANNOT stop dsh writing its checkpoint locally, so a landed checkpoint will destroy the compression substrate and surface later as a 'compression conflict' banner. Apply the #2474 full-snapshot override of preset-standard in your profile's cordis.patch.yml now (a partial snippet silently drops everything not restated; see docs/configuration.md)`); } else if (isWeb) { - persistClientEvent("profile bundles include @deepseek-ai/dsh-web-app — its agent presets run their own compaction-basic in nested rows no patch layer can address by id (#1772/#2360); bili disables those preset rows at load time via a vendored overlay (deshark42/dsh-compaction-basic-disable, MIT, #3354; since #4147 the match is structural, covering custom presets too), so dsh native auto-compaction stays OFF in this profile (ACP compression unaffected). If you still see a dsh compaction checkpoint land on a newer/older dsh build — the overlay rides cordis' INTERNAL 'internal/config' hook and is version-sensitive — fall back to the #2474 full-snapshot override of preset-standard in your profile's cordis.patch.yml (a partial snippet silently drops everything not restated; see docs/configuration.md)." + gateCoverageSuffix()); + persistClientEvent("profile bundles include @deepseek-ai/dsh-web-app — its agent presets run their own compaction-basic in nested rows no patch layer can address by id (#1772/#2360); bili disables those preset rows at load time via a vendored overlay (deshark42/dsh-compaction-basic-disable, MIT, #3354; since #4147 the match is structural, covering custom presets too), so dsh native auto-compaction stays OFF in this profile (ACP compression unaffected)." + (dshKeepCommandCompactEnabled() ? " With dsh.keepCommandCompact on (#4872), the overlay keeps @deepseek-ai/dsh-command-compact ENABLED — the explicit /compact command stays available, and its calls still pass the #1729 wire guard (answered locally by bili when the session holds active fold blocks, refused otherwise)." : "") + " If you still see a dsh compaction checkpoint land on a newer/older dsh build — the overlay rides cordis' INTERNAL 'internal/config' hook and is version-sensitive — fall back to the #2474 full-snapshot override of preset-standard in your profile's cordis.patch.yml (a partial snippet silently drops everything not restated; see docs/configuration.md)." + gateCoverageSuffix()); } else if (bundles !== undefined && !nonWebTraceLogged) { // #3651: the web-profile note above is the ONLY confirmation that // the #3354 overlay took effect, and it is scoped to dsh-web-app @@ -2927,7 +2932,7 @@ export async function apply(ctx: PluginContext): Promise { // trace so a field log can tell "overlay registered" from "profile // shape unconfirmed". nonWebTraceLogged = true; - persistClientEvent("profile bundles do not include @deepseek-ai/dsh-web-app — the #3354 load-time compaction-disable middleware is registered anyway (it rewrites any entry's nested compaction-basic/command-compact rows through cordis' version-sensitive internal 'internal/config' hook, covering custom presets as of #4147), but no web-profile disable note applies here; if dsh native auto-compaction still lands in this profile, apply the #2474 full-snapshot override of preset-standard (docs/configuration.md) — and note the #1729 wire guard now refuses such native compaction calls unconditionally (the #2028 allowDshCompaction opt-in was removed in #3651)." + gateCoverageSuffix()); + persistClientEvent("profile bundles do not include @deepseek-ai/dsh-web-app — the #3354 load-time compaction-disable middleware is registered anyway (it rewrites any entry's nested " + (dshKeepCommandCompactEnabled() ? "compaction-basic" : "compaction-basic/command-compact") + " rows through cordis' version-sensitive internal 'internal/config' hook, covering custom presets as of #4147), but no web-profile disable note applies here; if dsh native auto-compaction still lands in this profile, apply the #2474 full-snapshot override of preset-standard (docs/configuration.md) — and note the #1729 wire guard now refuses such native compaction calls unconditionally (the #2028 allowDshCompaction opt-in was removed in #3651)." + gateCoverageSuffix()); } } @@ -2943,6 +2948,25 @@ export async function apply(ctx: PluginContext): Promise { description: "Prompt-cache reconciliation (same report as the acp_cache tool)", handler: (invocation) => cacheOutcome(ctx, invocation), }); + // #4872/#6814: in a web profile where the overlay latched, the preset's + // own /compact is stood down (unless dsh.keepCommandCompact re-arms it) — + // and dsh demotes an unregistered /compact to a PLAIN model message with + // no visible signal (#6814 field evidence: typed twice, both forwarded + // as user/message, the user never told). Register a visible stub so the + // input is answered, never silently forwarded. Gated on gap===null: if + // the overlay failed to latch the real command-compact may still be + // armed and a stub would shadow it; non-web profiles keep the host-plane + // /compact armed, so no stub there either. + if (gap === null && isWeb && !dshCompactionKeepCommandCompact()) { + ctx.commands.register({ + name: "compact", + description: "Compaction is handled by billion-context (dsh /compact is stood down by the bili gate)", + handler: async () => ({ + kind: "success", + text: "This session's compaction is owned by billion-context: the dsh /compact command is disabled by bili's compaction gate (#3354/#4872), so there is no dsh checkpoint to run here. Use /acp for live compression state. To restore dsh's own /compact, set dsh.keepCommandCompact (env BILI_DSH_KEEP_COMMAND_COMPACT) and restart the host.", + }), + }); + } // node:test drives apply() directly with a mock ctx — never patch // globalThis.fetch/WebSocket from inside a test run. diff --git a/src/config.ts b/src/config.ts index d5cba295e0..c5ed44bd2e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1147,10 +1147,11 @@ export type ProxyOptions = { * `allowDshCompaction` escape hatch was REMOVED (#3651) — dsh native * compaction is now refused unconditionally by the #1729 wire guard on every * lane, and a landed checkpoint durably shadows the raw history - * (irreversible), so no opt-in remains. The one live key is - * `authoredCompaction` (#3723/#3901). Leftover removed keys still sit in old - * files: the section stays RECOGNIZED so they don't trip the unknown-key - * warning, and each is ignored with a once-per-process deprecation note + * (irreversible), so no opt-in remains. Live keys: `authoredCompaction` + * (#3723/#3901), `contextTab` + `contextTabLabel` (#4237), + * `keepCommandCompact` (#4872). Leftover removed keys still sit in old files: + * the section stays RECOGNIZED so they don't trip the unknown-key warning, + * and each is ignored with a once-per-process deprecation note * (warnRemovedDshAllowKey). */ interface DshFileSettings { /** #3723/#3901: bili-authored compaction answers (ON by default since @@ -1172,6 +1173,13 @@ interface DshFileSettings { * rename exists for machines where another plugin occupies the same name * (dsh-context ships its own "上下文"). */ contextTabLabel?: string; + /** #4872: keep @deepseek-ai/dsh-command-compact ENABLED under the #3354 + * load-time overlay (only compaction-basic gets disabled), restoring the + * explicit /compact command for third-party plugins bridging through + * ctx.commands.find(agent, "compact"). Default OFF = today's both- + * packages rule. Env BILI_DSH_KEEP_COMMAND_COMPACT wins; resolved at + * bili-native activation (next host restart). */ + keepCommandCompact?: boolean; } /** The routing fields a provider entry can carry — exactly what @@ -2720,9 +2728,9 @@ function warnRemovedDshAllowKey(obj: Record): void { const d = obj.dsh; if (d !== null && typeof d === "object" && !Array.isArray(d)) { // authoredCompaction (#3723/#3901), contextTab + contextTabLabel - // (#4237) are the LIVE keys in the section — everything else found - // here is removed/unknown and gets named. - const live = new Set(["authoredCompaction", "contextTab", "contextTabLabel"]); + // (#4237), keepCommandCompact (#4872) are the LIVE keys in the section + // — everything else found here is removed/unknown and gets named. + const live = new Set(["authoredCompaction", "contextTab", "contextTabLabel", "keepCommandCompact"]); for (const key of Object.keys(d as Record)) if (!live.has(key)) hits.push(`dsh.${key}`); } hits.sort(); diff --git a/src/knobs.ts b/src/knobs.ts index 9fe5ee2e2c..37f439e62e 100644 --- a/src/knobs.ts +++ b/src/knobs.ts @@ -707,6 +707,24 @@ export function dshContextTabLabel(): string | undefined { return s.length > 0 ? s : undefined; } +/** BILI_DSH_KEEP_COMMAND_COMPACT > dsh.keepCommandCompact > false (#4872). + * When ON, the #3354 load-time overlay disables ONLY + * @deepseek-ai/dsh-compaction-basic and leaves + * @deepseek-ai/dsh-command-compact armed: the explicit /compact command + * survives, so third-party plugins bridging through the DSH-official + * ctx.commands.find(agent, "compact") path keep working while bili owns + * compression. A /compact-triggered compaction call still passes the #1729 + * wire guard — answered locally by #3733 authored compaction when the + * session holds active blocks, refused otherwise — so no checkpoint lands + * outside bili's knowledge. Default OFF = today's both-packages rule. + * Resolved once at bili-native activation; changing it takes effect on the + * next host restart (plugin-mode convention). */ +export function dshKeepCommandCompactEnabled(): boolean { + const envRaw = process.env.BILI_DSH_KEEP_COMMAND_COMPACT; + if (envRaw !== undefined) return !(envRaw.trim() === "0" || envRaw.trim().toLowerCase() === "false"); + return loadConfigFile().dsh?.keepCommandCompact === true; +} + type PluginBypassOverride = "auto" | "on" | "off"; /** BILI_PLUGIN_BYPASS — operator override of the x-bili-plugin-bypass diff --git a/src/web/client.ts b/src/web/client.ts index 5ca025d133..9bff078b30 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -4658,6 +4658,7 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const ds = (draft.dsh && typeof draft.dsh === "object" && !Array.isArray(draft.dsh)) ? draft.dsh : null; dshCtxRow.inp.checked = ds ? ds.contextTab !== false : true; dshLblInp.value = (ds && typeof ds.contextTabLabel === "string") ? ds.contextTabLabel : ""; + dshKccRow.inp.checked = ds ? ds.keepCommandCompact === true : false; } function commit(mutate) { const fresh = freshDraft(); @@ -4738,6 +4739,17 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + if (v.length > 0) ds.contextTabLabel = v; else delete ds.contextTabLabel; if (Object.keys(ds).length === 0) delete d.dsh; else d.dsh = ds; })); + const dshKccRow = row("quick-dsh-keepcompact", t("cfg.q_dsh_keepcompact")); + qCtrls.push(dshKccRow.inp); + dshKccRow.inp.addEventListener("change", () => commit((d) => { + const ds = (d.dsh && typeof d.dsh === "object" && !Array.isArray(d.dsh)) ? d.dsh : {}; + if (dshKccRow.inp.checked) ds.keepCommandCompact = true; else delete ds.keepCommandCompact; + if (Object.keys(ds).length === 0) delete d.dsh; else d.dsh = ds; + })); + const dshKccHint = document.createElement("span"); + dshKccHint.className = "dim small"; + dshKccHint.textContent = t("cfg.q_dsh_keepcompact_hint"); + dshKccRow.ctl.appendChild(dshKccHint); const abRow = row("quick-absorb", t("cfg.q_absorb")); qCtrls.push(abRow.inp); abRow.inp.addEventListener("change", () => commit((d) => { diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 45d66a429b..c162b5861f 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -630,6 +630,8 @@ export const MESSAGES: Record> = { "cfg.q_dsh_ctxtab": "DSH 顶栏「上下文」标签页(dsh.contextTab)——关闭只摘掉 DSH 会话区顶部那个标签页,压缩不受影响;账本仍可在 bili 设置页、插件详情页和本 Web UI 查看(默认开)", "cfg.q_dsh_ctxtab_hint": "下次页面加载 / 重启 dsh 后生效;也可用环境变量 BILI_DSH_CONTEXT_TAB=0 强制隐藏", "cfg.q_dsh_ctxtab_label": "DSH「上下文」标签页名称(dsh.contextTabLabel)——留空用内置名「上下文」,可改名避免与其他插件重名", + "cfg.q_dsh_keepcompact": "DSH /compact 命令(dsh.keepCommandCompact)——开启后 bili 只禁用自动压缩(compaction-basic),保留显式 /compact 命令,依赖它的第三方插件恢复可用(默认关)", + "cfg.q_dsh_keepcompact_hint": "重启 dsh 后生效;可用环境变量 BILI_DSH_KEEP_COMMAND_COMPACT=1 强制开启。/compact 触发的压缩调用仍经 bili wire guard:会话有活跃折叠块时由 bili 本地应答,否则拒绝", "cfg.q_absorb": "工具结果即时蒸馏(absorb)——大工具结果到达时由模型即时蒸馏,原文隐藏到下一轮折叠前(默认关)", "cfg.q_absorb_hint": "默认只吸含图结果(#3422);mediaOnly: false 可恢复吸全文。子项(minToolTokens、contextThresholdPct、excludeTools)请在下方 JSON 编辑框写", "cfg.q_require_nudge": "禁止未提示压缩(compress.requireNudge)——只在 nudge 信用存活时(最近一次真正注入的提醒起 20 个模型轮内,新提醒刷新、未提示轮衰减、成功折叠不消耗)允许模型调用 compress,其余拒绝并回错误回执(默认关)", @@ -1430,6 +1432,8 @@ export const MESSAGES: Record> = { "cfg.q_dsh_ctxtab": "DSH top-bar Context tab (dsh.contextTab) — off removes only that tab from the DSH conversation area; compression is untouched and the ledger stays visible in the bili settings section, the plugin detail page and this Web UI (default on)", "cfg.q_dsh_ctxtab_hint": "takes effect on the next page load / dsh restart; env BILI_DSH_CONTEXT_TAB=0 also forces it hidden", "cfg.q_dsh_ctxtab_label": "Label of the DSH Context tab (dsh.contextTabLabel) — empty keeps the built-in name \"Context\"; rename to avoid clashing with another plugin's tab", + "cfg.q_dsh_keepcompact": "DSH /compact command (dsh.keepCommandCompact) — on keeps the explicit /compact command enabled under bili (only auto-compaction stays disabled), restoring third-party plugins that bridge through it (default off)", + "cfg.q_dsh_keepcompact_hint": "takes effect on the next dsh restart; env BILI_DSH_KEEP_COMMAND_COMPACT=1 also forces it on. /compact-triggered compaction still passes bili's wire guard: answered locally when the session holds active fold blocks, refused otherwise", "cfg.q_absorb": "Instant tool-result absorption (absorb) — large tool results are distilled by the model on arrival; originals hidden until the next fold round (default off)", "cfg.q_absorb_hint": "by default only image-bearing results are absorbed (#3422); set mediaOnly: false to absorb full text. Sub-fields (minToolTokens, contextThresholdPct, excludeTools) go in the JSON editor below", "cfg.q_require_nudge": "Forbid unprompted compression (compress.requireNudge) — compress may only be called while a nudge credit is live (within 20 model rounds of the last actually-injected nudge: refreshed by new nudges, decayed per un-nudged round, NOT consumed by successful folds); anything else is refused with an error receipt (default off)", diff --git a/tests/dsh-native.test.ts b/tests/dsh-native.test.ts index 1c9a6148dc..b795fcf3a1 100644 --- a/tests/dsh-native.test.ts +++ b/tests/dsh-native.test.ts @@ -9,7 +9,7 @@ import { apply, installDshIntercepts, planNativeDsh, shouldBootstrapNativeDsh, p import { nativeInterceptInstalled, _resetForTest as _resetFetchInterceptForTest, type NativeInterceptState } from "../src/agent/native-intercept.ts"; import { nativeWebSocketInterceptInstalled, _resetForTest as _resetWsInterceptForTest } from "../src/agent/native-ws-intercept.ts"; import { __resetIncrementalClientForTests } from "../src/agent/incremental-client.ts"; -import { isDshCompactionActive, _resetDshCompactionVerdictForTest } from "../src/agent/dsh-compaction-disable.ts"; +import { dshCompactionKeepCommandCompact, isDshCompactionActive, _resetDshCompactionVerdictForTest } from "../src/agent/dsh-compaction-disable.ts"; import { once } from "node:events"; import { startServer } from "../src/server.ts"; import { defaultConfig } from "acp-kernel"; @@ -1336,11 +1336,96 @@ test("#3354/#3662 apply(): declares lane ownership instead of registering the ov // that transform honors (tests/issue3662-dsh-gate-fallback.test.ts // pins the transform + service side). assert.ok(isDshCompactionActive(), "active plan must declare the lane owned"); + // #4872: the scope flag rides the verdict — absent by default, so + // the transform keeps the original both-packages rule. + assert.equal(dshCompactionKeepCommandCompact(), false); assert.ok(!ctx.registrationOrder().some((e) => e.startsWith("on:internal/config"))); assert.equal(ctx.providedServices.length, 0); await _stateToolsReadyForTest(); }); + // #4872: knob ON → the declaration narrows the overlay to compaction-basic + _resetDshCompactionVerdictForTest(); + await withEnv({ DSH_HOME: home, BILLION_CONTEXT_PROXY: proxy.origin, BILI_DSH_KEEP_COMMAND_COMPACT: "1" }, async () => { + _resetRegisterForTest(proxy.origin); + apply(mockCtx()); + assert.ok(isDshCompactionActive()); + assert.equal(dshCompactionKeepCommandCompact(), true, "knob must reach the verdict at activation time"); + await _stateToolsReadyForTest(); + }); + } finally { + proxy.close(); + rmrf(home); + _resetRegisterForTest(undefined); + _resetDshCompactionVerdictForTest(); + } +}); + +test("#4872/#6814 apply(): a web profile with the overlay latched registers a visible /compact stub", async () => { + const proxy = await startMockProxy([]); + const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-dsh-compact-stub-")); + const webBundles = ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-web-app", "billion-context"]; + _setSpawnForTest(async () => undefined); + try { + await withEnv({ DSH_HOME: home, BILLION_CONTEXT_PROXY: proxy.origin }, async () => { + // 1. web profile, knob OFF (default) → the preset's /compact is + // stood down by the #3354 overlay, so the stub must be + // registered and answer visibly — never demoted to a plain + // model message (#6814 field evidence). + _resetDshCompactionVerdictForTest(); + _resetRegisterForTest(proxy.origin); + const ctx = mockCtx(); + ctx.setProfileContext({ startedBundles: webBundles }); + apply(ctx); + const names = ctx.registeredCommands.map((c) => c.name); + assert.ok(names.includes("acp"), "baseline: /acp still registered"); + const stub = ctx.registeredCommands.find((c) => c.name === "compact"); + assert.ok(stub, "web profile + knob off: the /compact stub must be registered"); + const outcome = await stub!.handler(); + assert.equal(outcome.kind, "success"); + assert.match(outcome.text, /billion-context/); + assert.match(outcome.text, /\/acp/); + assert.match(outcome.text, /dsh\.keepCommandCompact/); + await _stateToolsReadyForTest(); + + // 2. web profile, knob ON → the overlay re-arms the real + // command-compact → the stub must stay out (a double + // registration would shadow the real command). + _resetDshCompactionVerdictForTest(); + await withEnv({ BILI_DSH_KEEP_COMMAND_COMPACT: "1" }, async () => { + _resetRegisterForTest(proxy.origin); + const ctxOn = mockCtx(); + ctxOn.setProfileContext({ startedBundles: webBundles }); + apply(ctxOn); + assert.ok(!ctxOn.registeredCommands.some((c) => c.name === "compact"), "knob on: the real /compact is armed, the stub must stay out"); + await _stateToolsReadyForTest(); + }); + + // 3. non-web profile → the host-plane /compact stays armed → no stub. + _resetDshCompactionVerdictForTest(); + _resetRegisterForTest(proxy.origin); + const plain = mockCtx(); + plain.setProfileContext({ startedBundles: ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-headless", "billion-context"] }); + apply(plain); + assert.ok(!plain.registeredCommands.some((c) => c.name === "compact"), "non-web profile: host-plane /compact armed, no stub"); + await _stateToolsReadyForTest(); + + // 4. overlay failed to latch (host without the internal/config + // hook) → the real command-compact may still be armed → no stub. + _resetDshCompactionVerdictForTest(); + _resetRegisterForTest(proxy.origin); + const captured: Array<{ name: string }> = []; + const bare: Parameters[0] = { + tools: { register: () => undefined }, + commands: { register: (c: { name: string }) => { captured.push(c); } }, + agents: {}, + profileContext: { startedBundles: webBundles }, + }; + apply(bare); + assert.ok(!captured.some((c) => c.name === "compact"), "overlay gap: the real /compact may be armed, no stub"); + await _stateToolsReadyForTest(); + }); } finally { + _setSpawnForTest(undefined); proxy.close(); rmrf(home); _resetRegisterForTest(undefined); diff --git a/tests/issue4872-dsh-keep-command-compact.test.ts b/tests/issue4872-dsh-keep-command-compact.test.ts new file mode 100644 index 0000000000..1abd01d589 --- /dev/null +++ b/tests/issue4872-dsh-keep-command-compact.test.ts @@ -0,0 +1,202 @@ +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 { declareDshCompactionActive, disableBasicCompaction, dshCompactionGateTelemetry, dshCompactionKeepCommandCompact, isDshCompactionActive, registerCompactionDisable, _resetDshCompactionGateTelemetryForTest, _resetDshCompactionVerdictForTest } from "../src/agent/dsh-compaction-disable.ts"; +import { dshKeepCommandCompactEnabled } from "../src/knobs.ts"; + +// #4872: the #3354 load-time overlay scope is knob-gated — with +// dsh.keepCommandCompact ON the transform disables ONLY compaction-basic and +// leaves the explicit /compact command (command-compact) armed so third-party +// plugins bridging through the DSH-official ctx.commands.find(agent, "compact") +// path keep working. Default OFF = the original both-packages rule (zero drift). +// The apply-level wiring (knob → verdict flag) is pinned in +// tests/dsh-native.test.ts ("declares lane ownership"). + +const VERDICT_KEY = "__BILI_DSH_COMPACTION_VERDICT__"; + +function resetAll(): void { + _resetDshCompactionVerdictForTest(); + _resetDshCompactionGateTelemetryForTest(); +} + +async function withEnv(env: Record, fn: () => T): Promise { + const saved: Record = {}; + for (const [k, v] of Object.entries(env)) { + saved[k] = process.env[k]; + if (v === undefined) delete process.env[k]; + else process.env[k] = v; + } + try { + return await fn(); + } finally { + for (const [k, v] of Object.entries(saved)) { + if (v === undefined) delete process.env[k]; + else process.env[k] = v; + } + } +} + +test("#4872 disableBasicCompaction: default scope still disables BOTH packages", () => { + const rows = [ + { name: "@deepseek-ai/dsh-compaction-basic", config: { auto: true } }, + { name: "@deepseek-ai/dsh-command-compact" }, + { name: "@deepseek-ai/dsh-other" }, + ]; + const out = disableBasicCompaction(rows) as Array>; + assert.equal(out[0].disabled, true); + assert.equal(out[1].disabled, true); + assert.equal(out[2].disabled, undefined); +}); + +test("#4872 disableBasicCompaction: keepCommandCompact leaves /compact armed at any depth", () => { + const nestedCompact = { name: "@deepseek-ai/dsh-command-compact" }; + const deepCompact = { name: "@deepseek-ai/dsh-command-compact" }; + const rows = [ + { name: "@deepseek-ai/dsh-compaction-basic" }, + { name: "@deepseek-ai/dsh-command-compact" }, + { name: "@deepseek-ai/dsh-other" }, + { + id: "compaction", + name: "cordis:group", + group: true, + config: [ + { name: "@deepseek-ai/dsh-compaction-basic" }, + nestedCompact, + { group: true, config: [deepCompact] }, + ], + }, + ]; + const snapshot = JSON.stringify(rows); + const out = disableBasicCompaction(rows, { keepCommandCompact: true }) as Array>; + // input untouched, output detached + assert.equal(JSON.stringify(rows), snapshot); + assert.notEqual(out[0], rows[0]); + // basic disabled at top level and in every nesting depth… + assert.equal(out[0].disabled, true); + const inner = (out[3] as Record).config as Array>; + assert.equal(inner[0].disabled, true); + // …while command-compact rows pass through BY IDENTITY (untouched) + assert.equal(out[1], rows[1]); + assert.equal(inner[1], nestedCompact); + const deep = (inner[2].config as Array>)[0]; + // Reference equality with the pristine input leaf proves the row passed through + // untouched (a rewrite would produce a detached copy) — so no `disabled` key exists. + assert.equal(deep, deepCompact); + assert.deepEqual(deep, { name: "@deepseek-ai/dsh-command-compact" }); + // non-compaction rows pass through by identity too + assert.equal(out[2], rows[2]); +}); + +test("#4872 verdict channel: scope flag rides the declaration, legacy string tolerated", () => { + resetAll(); + try { + assert.equal(isDshCompactionActive(), false); + assert.equal(dshCompactionKeepCommandCompact(), false); + declareDshCompactionActive(); + assert.equal(isDshCompactionActive(), true); + assert.equal(dshCompactionKeepCommandCompact(), false, "absent option keeps the both-packages rule"); + declareDshCompactionActive({ keepCommandCompact: false }); + assert.equal(dshCompactionKeepCommandCompact(), false); + declareDshCompactionActive({ keepCommandCompact: true }); + assert.equal(isDshCompactionActive(), true); + assert.equal(dshCompactionKeepCommandCompact(), true); + // pre-#4872 builds declared the bare string "active" — a mixed-version + // process mid-update must degrade to the original rule, not lose the gate + (globalThis as Record)[VERDICT_KEY] = "active"; + assert.equal(isDshCompactionActive(), true); + assert.equal(dshCompactionKeepCommandCompact(), false); + } finally { + resetAll(); + } +}); + +test("#4872 transform: keepCommandCompact verdict rewrites only compaction-basic", () => { + type Mw = (raw: unknown, next: () => unknown) => unknown; + let mw: Mw | undefined; + resetAll(); + declareDshCompactionActive({ keepCommandCompact: true }); + try { + registerCompactionDisable({ + on: (_event, listener) => { mw = listener as Mw; }, + reflect: {}, + }); + assert.equal(typeof mw, "function"); + const compact = { name: "@deepseek-ai/dsh-command-compact" }; + const other = { name: "@deepseek-ai/dsh-tool-result-pruner" }; + const cfg: Record = { + plugins: [ + { name: "@deepseek-ai/dsh-compaction-basic", config: { auto: true } }, + compact, + other, + ], + isolate: { compaction: true }, + }; + const self = { entry: { options: { name: "@deepseek-ai/dsh-agent-preset" } } }; + const out = mw?.call(self, null, () => cfg) as { plugins?: Array; isolate?: Record }; + assert.deepEqual(out.isolate, { compaction: true }); + assert.notEqual(out, cfg); + assert.equal((out.plugins?.[0] as Record).disabled, true); + assert.equal(out.plugins?.[1], compact, "/compact row must survive by identity"); + assert.equal(out.plugins?.[2], other); + // telemetry counts only what the rewrite actually marked + const tel = dshCompactionGateTelemetry(); + assert.ok(tel); + assert.deepEqual(tel.covered, [{ entry: "@deepseek-ai/dsh-agent-preset", rows: 1 }]); + assert.equal(tel.sawFactoryPreset, true); + // a tree carrying ONLY command-compact rows has nothing to rewrite — + // the resolved config keeps its object identity and records no coverage + const compactOnly: Record = { plugins: [{ name: "@deepseek-ai/dsh-command-compact" }] }; + assert.equal(mw?.call(self, null, () => compactOnly), compactOnly); + assert.deepEqual(dshCompactionGateTelemetry()?.covered, [{ entry: "@deepseek-ai/dsh-agent-preset", rows: 1 }]); + } finally { + resetAll(); + } +}); + +test("#4872 transform: default verdict still rewrites both packages (regression pin)", () => { + type Mw = (raw: unknown, next: () => unknown) => unknown; + let mw: Mw | undefined; + resetAll(); + declareDshCompactionActive(); + try { + registerCompactionDisable({ + on: (_event, listener) => { mw = listener as Mw; }, + reflect: {}, + }); + const cfg: Record = { + plugins: [ + { name: "@deepseek-ai/dsh-compaction-basic" }, + { name: "@deepseek-ai/dsh-command-compact" }, + ], + }; + const self = { entry: { options: { name: "@deepseek-ai/dsh-agent-preset" } } }; + const out = mw?.call(self, null, () => cfg) as { plugins?: Array> }; + assert.equal(out.plugins?.[0]?.disabled, true); + assert.equal(out.plugins?.[1]?.disabled, true); + assert.deepEqual(dshCompactionGateTelemetry()?.covered, [{ entry: "@deepseek-ai/dsh-agent-preset", rows: 2 }]); + // an ABSENT declaration (bili-native never ran) passes everything through stock + _resetDshCompactionVerdictForTest(); + assert.equal(mw?.call(self, null, () => cfg), cfg); + } finally { + resetAll(); + } +}); + +test("#4872 dshKeepCommandCompactEnabled: env > file > default(false)", async () => { + const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-issue4872-knob-")); + try { + const onFile = path.join(home, "on.json"); + fs.writeFileSync(onFile, JSON.stringify({ dsh: { keepCommandCompact: true } })); + const offFile = path.join(home, "off.json"); + fs.writeFileSync(offFile, "{}"); + assert.equal(await withEnv({ BILI_CONFIG_FILE: offFile, BILI_DSH_KEEP_COMMAND_COMPACT: undefined }, () => dshKeepCommandCompactEnabled()), false, "default OFF = today's behavior"); + assert.equal(await withEnv({ BILI_CONFIG_FILE: onFile, BILI_DSH_KEEP_COMMAND_COMPACT: undefined }, () => dshKeepCommandCompactEnabled()), true, "file tier"); + assert.equal(await withEnv({ BILI_CONFIG_FILE: onFile, BILI_DSH_KEEP_COMMAND_COMPACT: "0" }, () => dshKeepCommandCompactEnabled()), false, "env wins over file (off)"); + assert.equal(await withEnv({ BILI_CONFIG_FILE: offFile, BILI_DSH_KEEP_COMMAND_COMPACT: "false" }, () => dshKeepCommandCompactEnabled()), false); + assert.equal(await withEnv({ BILI_CONFIG_FILE: offFile, BILI_DSH_KEEP_COMMAND_COMPACT: "1" }, () => dshKeepCommandCompactEnabled()), true, "env wins over file (on)"); + } finally { + fs.rmSync(home, { recursive: true, force: true }); + } +}); diff --git a/website/config-reference/env-only.yaml b/website/config-reference/env-only.yaml index b34c86ce13..e4d863b0d2 100644 --- a/website/config-reference/env-only.yaml +++ b/website/config-reference/env-only.yaml @@ -20,6 +20,15 @@ entries: desc_en: "Env tier for dsh.contextTab (#4237): 0/false removes the DSH top-bar 「上下文」/「Context」 tab (everything else keeps working); any other value forces it on over the file tier; unset = file tier applies (default true). Takes effect on next page load / dsh restart." desc_zh: "dsh.contextTab 的 env 层(#4237):0/false 移除 DSH 顶栏「上下文」标签页(其余一切照常工作);其他取值强制开启并覆盖文件层;缺省 = 按文件层取值(默认 true)。下次页面加载 / dsh 重启生效。" desc_ja: "dsh.contextTab (#4237) の環境変数ティア: 0/false で DSH トップバーの「上下文」/「Context」タブを削除 (その他はすべて動作維持); その他の値はファイルティアを上書きして強制オン; 未設定 = ファイルティアが適用 (デフォルト true)。次のページ読み込み / dsh 再起動時に有効化。" + - key: BILI_DSH_KEEP_COMMAND_COMPACT + type: boolean + default: "false" + kind: env-only + audience: user + group: envonly + desc_en: "Env tier for dsh.keepCommandCompact (#4872): 1/true keeps @deepseek-ai/dsh-command-compact enabled under the #3354 load-time overlay (only auto-compaction compaction-basic stays disabled), restoring the explicit /compact command for third-party plugins bridging through ctx.commands.find(agent, \"compact\"); 0/false or unset = today's both-packages rule. Takes effect on the next dsh restart." + desc_zh: "dsh.keepCommandCompact 的 env 层(#4872):1/true 在 #3354 加载期 overlay 下保留 @deepseek-ai/dsh-command-compact 启用(只禁自动压缩 compaction-basic),恢复显式 /compact 命令给通过 ctx.commands.find(agent, \"compact\") 桥接的第三方插件;0/false 或缺省 = 现状两包同禁。下次 dsh 重启生效。" + desc_ja: "dsh.keepCommandCompact の環境変数ティア (#4872): 1/true は #3354 のロード時オーバーレイの下で @deepseek-ai/dsh-command-compact を有効のままにします (自動コンパクションの compaction-basic のみ無効化)、ctx.commands.find(agent, \"compact\") でブリッジするサードパーティプラグイン向けに明示的な /compact コマンドを復元します; 0/false または未設定 = 現在の両パッケージ無効ルール。次の dsh リスタート時に有効化。" - key: BILI_DSH_MAX_TESTED_VERSION type: string default: "0.2.0-rc.2 (CI e2e anchor)" diff --git a/website/config-reference/server.yaml b/website/config-reference/server.yaml index d05c9e7e50..c6fd73351d 100644 --- a/website/config-reference/server.yaml +++ b/website/config-reference/server.yaml @@ -428,9 +428,9 @@ entries: default: "{}" env: BILI_ALLOW_DSH_COMPACTION group: behavior - desc_en: "Section recognized but its former escape hatch is gone (#3666, superseding #2028): the allowDshCompaction key and the BILI_ALLOW_DSH_COMPACTION env var no longer exist — dsh native compaction is refused unconditionally by the wire guard on every lane. Leftover dsh.allowDshCompaction values are ignored with a one-time deprecation warning; apply host-side suppression instead (#3354/#2474). The live keys — dsh.authoredCompaction, dsh.contextTab, dsh.contextTabLabel — are documented in the following entries." - desc_zh: "段仍被识别,但其原逃生门已移除(#3666,取代 #2028):allowDshCompaction 键与 BILI_ALLOW_DSH_COMPACTION 环境变量已不存在——dsh 原生压缩现在在所有线路上被无条件拒绝。遗留的 dsh.allowDshCompaction 取值会被忽略(一次性弃用警告);请改用宿主侧抑制(#3354/#2474)。存活的键——dsh.authoredCompaction、dsh.contextTab、dsh.contextTabLabel——见接下来的条目。" - desc_ja: "セクションは認識されるが、従来のエスケープハッチは削除された(#3666、#2028 を代替):`allowDshCompaction` キーおよび `BILI_ALLOW_DSH_COMPACTION` 環境変数はもはや存在しない — dsh ネイティブコンパクションは、すべてのレーンにおいてワイヤガードによって無条件に拒否される。残存する `dsh.allowDshCompaction` の値は、一度限りの非推奨警告とともに無視される;代わりにホスト側の抑制を適用すること(#3354/#2474)。ライブキー — `dsh.authoredCompaction`、`dsh.contextTab`、`dsh.contextTabLabel` — は以下のエントリに文書化されている。" + desc_en: "Section recognized but its former escape hatch is gone (#3666, superseding #2028): the allowDshCompaction key and the BILI_ALLOW_DSH_COMPACTION env var no longer exist — dsh native compaction is refused unconditionally by the wire guard on every lane. Leftover dsh.allowDshCompaction values are ignored with a one-time deprecation warning; apply host-side suppression instead (#3354/#2474). The live keys — dsh.authoredCompaction, dsh.contextTab, dsh.contextTabLabel, dsh.keepCommandCompact — are documented in the following entries." + desc_zh: "段仍被识别,但其原逃生门已移除(#3666,取代 #2028):allowDshCompaction 键与 BILI_ALLOW_DSH_COMPACTION 环境变量已不存在——dsh 原生压缩现在在所有线路上被无条件拒绝。遗留的 dsh.allowDshCompaction 取值会被忽略(一次性弃用警告);请改用宿主侧抑制(#3354/#2474)。存活的键——dsh.authoredCompaction、dsh.contextTab、dsh.contextTabLabel、dsh.keepCommandCompact——见接下来的条目。" + desc_ja: "セクションは認識されるが、従来のエスケープハッチは削除された(#3666、#2028 を代替):`allowDshCompaction` キーおよび `BILI_ALLOW_DSH_COMPACTION` 環境変数はもはや存在しない — dsh ネイティブコンパクションは、すべてのレーンにおいてワイヤガードによって無条件に拒否される。残存する `dsh.allowDshCompaction` の値は、一度限りの非推奨警告とともに無視される;代わりにホスト側の抑制を適用すること(#3354/#2474)。ライブキー — `dsh.authoredCompaction`、`dsh.contextTab`、`dsh.contextTabLabel`、`dsh.keepCommandCompact` — は以下のエントリに文書化されている。" - key: dsh.authoredCompaction type: boolean default: "true (on, #3901 flip)" @@ -454,6 +454,14 @@ entries: desc_en: "Custom display name for the DSH top-bar Context tab (#4237), e.g. \"压缩账本\" when another plugin (dsh-context) owns the name 「上下文」. Trimmed non-empty string wins over the built-in label; blank or absent falls back to the built-in. File-only tier (display preference, no env knob per #2030). Default unset = built-in label unchanged." desc_zh: "DSH 顶栏上下文标签页的自定义显示名(#4237),例如另一插件(dsh-context)已占用「上下文」时改为\"压缩账本\"。去空白后的非空字符串优先于内置名;留空或缺省回退内置名。仅文件层(显示偏好,按 #2030 不设 env 开关)。默认缺省 = 内置名不变。" desc_ja: "DSH トップバーの Context タブのカスタム表示名(#4237)、例:別のプラグイン(dsh-context)が「上下文」の名前を所有している場合の \"压缩账本\"。トリムされた空でない文字列が組み込みラベルに優先される;空白または未設定の場合は組み込みにフォールバック。ファイル専用ティア(表示設定、#2030 に従い環境変数なし)。デフォルト未設定 = 組み込みラベルは変更なし。" + - key: dsh.keepCommandCompact + type: boolean + default: "false" + env: BILI_DSH_KEEP_COMMAND_COMPACT + group: behavior + desc_en: "Keep @deepseek-ai/dsh-command-compact ENABLED under the #3354 load-time overlay: only compaction-basic gets disabled, so the explicit /compact command survives and third-party plugins bridging through the DSH-official ctx.commands.find(agent, \"compact\") path keep working while bili owns compression (#4872). A /compact-triggered compaction call still passes the #1729 wire guard — answered locally by bili's authored compaction when the session holds active fold blocks, refused otherwise — so no checkpoint lands outside bili's knowledge. Default OFF = today's both-packages rule; takes effect on the next dsh restart (resolved at bili-native activation)." + desc_zh: "在 #3354 加载期 overlay 下保留 @deepseek-ai/dsh-command-compact **启用**:只禁用 compaction-basic,显式 /compact 命令得以保留,通过 DSH 官方 ctx.commands.find(agent, \"compact\") 通路桥接的第三方插件在 bili 持有压缩期间继续可用(#4872)。/compact 触发的压缩调用仍经 #1729 wire guard——会话有活跃折叠块时由 bili authored compaction 本地应答,否则拒绝——因此不会有检查点落在 bili 不知情处。默认关 = 现状两包同禁;下次 dsh 重启生效(bili-native 激活时解析)。" + desc_ja: "#3354 のロード時オーバーレイの下で @deepseek-ai/dsh-command-compact を**有効**のままにします: compaction-basic のみが無効化されるため、明示的な /compact コマンドが生存し、DSH 公式の ctx.commands.find(agent, \"compact\") 経路でブリッジするサードパーティプラグインが bili が圧縮を所有している間も引き続き動作します (#4872)。/compact によるコンパクション呼び出しは #1729 のワイヤガードを依然通過します — セッションがアクティブなフォールドブロックを持つ場合は bili の authored compaction がローカルで応答し、そうでない場合は拒否 — したがって bili の認識外にチェックポイントが置かれることはありません。デフォルト OFF = 現在の両パッケージ無効ルール; 次の dsh リスタート時に有効化 (bili-native 活性化時に解決)。" - key: resign type: "scheme → { enabled?, passthrough?, credentialRef? }" default: "{} (armed; built-in scheme sdk-hmac-sha256)"