From 5efa6ece6151874642e2e2dd8e67871385ad9819 Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 27 Oct 2026 01:15:24 +0800 Subject: [PATCH 1/4] feat(dsh): opt-in overlay scope keeping the /compact command under bili (#4872) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #3354 load-time overlay disabled BOTH dsh compaction packages in web-profile presets. compaction-basic is bili's target (auto-compression whose on-disk checkpoints shadowed the fold substrate, #1729), but command-compact carries the EXPLICIT /compact command — the DSH-official bridge third-party plugins borrow via ctx.commands.find(agent, "compact") (e.g. dsh-switchman's /ctx-handover). Disabling it made those plugins degrade to undefined with nothing pointing at bili. Owner decision (#4872 floor): ship an opt-in switch this release; full unbinding of auto-compaction constraints waits for server-side compaction to fully take over next phase. - new knob dsh.keepCommandCompact (file) / BILI_DSH_KEEP_COMMAND_COMPACT (env), default OFF = today's behavior, zero drift; resolved once at bili-native activation, takes effect at the next host restart - verdict channel now carries {active, keepCommandCompact} (legacy "active" string tolerated for mixed-version mid-update windows); disableBasicCompaction/countCompactionRows take the scope flag so the rewrite and its telemetry count stay in lockstep - web settings UI row + boot-note wording follow the flag --- src/agent/dsh-compaction-disable.ts | 67 ++++-- src/agent/dsh-native.ts | 11 +- src/config.ts | 22 +- src/knobs.ts | 18 ++ src/web/client.ts | 12 ++ src/web/i18n.ts | 4 + tests/dsh-native.test.ts | 14 +- ...issue4872-dsh-keep-command-compact.test.ts | 202 ++++++++++++++++++ 8 files changed, 324 insertions(+), 26 deletions(-) create mode 100644 tests/issue4872-dsh-keep-command-compact.test.ts diff --git a/src/agent/dsh-compaction-disable.ts b/src/agent/dsh-compaction-disable.ts index 4970e3d159..f66584c593 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. /** The two dsh packages whose backends must not instantiate while bili owns the lane. */ const DSH_COMPACTION_BASIC_PACKAGE = "@deepseek-ai/dsh-compaction-basic"; @@ -76,13 +85,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"). */ @@ -137,30 +169,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; }); @@ -195,12 +231,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 5904fba40e..7fa9ffe61c 100644 --- a/src/agent/dsh-native.ts +++ b/src/agent/dsh-native.ts @@ -59,7 +59,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 { bodyProvablyOverWindow as sharedBodyProvablyOverWindow, installNativeFetchIntercept, liveStateSlotEffect, noteRoutedOrigin, observeRoutedOrigin, routedBiliModelUrl, type GateVerdict, type NativeInterceptState } from "./native-intercept.js"; @@ -1737,7 +1737,10 @@ export function apply(ctx: PluginContext): void { // 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() }); // #2082: a fresh activation invalidates the "host tearing down" verdict. // Without this reset, ONE registerTools rejection carrying "inactive @@ -2594,7 +2597,7 @@ export function apply(ctx: PluginContext): void { if (gap !== null) { persistClientEvent(`profile bundles include @deepseek-ai/dsh-web-app 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 CONFIGURATION.md)`); } else { - 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 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 CONFIGURATION.md)." + gateCoverageSuffix()); } } else if (bundles !== undefined && !nonWebTraceLogged) { // #3651: the web-profile note above is the ONLY confirmation that @@ -2604,7 +2607,7 @@ export function apply(ctx: PluginContext): void { // 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 (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 (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()); } } diff --git a/src/config.ts b/src/config.ts index 09f185e384..ae3604602a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -946,10 +946,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 @@ -971,6 +972,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 @@ -2393,9 +2401,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 61edea829f..c859986237 100644 --- a/src/knobs.ts +++ b/src/knobs.ts @@ -588,6 +588,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; +} + /** BILI_DECOMPRESS_TMP_CAP > decompressTmpCap > 50. */ export function decompressTmpCap(): number { const v = tIntLoose("BILI_DECOMPRESS_TMP_CAP", loadConfigFile().decompressTmpCap); diff --git a/src/web/client.ts b/src/web/client.ts index 7556a9efb2..41b4a1b9c4 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -3609,6 +3609,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(); @@ -3689,6 +3690,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 b1b0941061..7ba74dab48 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -511,6 +511,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_pack": "压缩提示词包(compress.promptPack)", @@ -1127,6 +1129,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_pack": "Compression prompt pack (compress.promptPack)", diff --git a/tests/dsh-native.test.ts b/tests/dsh-native.test.ts index e8967f16d6..0c432e1d34 100644 --- a/tests/dsh-native.test.ts +++ b/tests/dsh-native.test.ts @@ -7,7 +7,7 @@ import http from "node:http"; import { pathToFileURL } from "node:url"; import { apply, planNativeDsh, shouldBootstrapNativeDsh, persistClientEvent, mediaBytesOfWireBody, bodyProvablyOverWindow, _attributionHealthForTest, _resetAttributionHealthForTest, _registerStateForTest, _resetRegisterForTest, _setModelInfoForTest, _setSpawnForTest, _setThrewRetryForTest, _settleNativeForTest, _stateHeadersForTest, _stateRespawnForTest, _stateTakeoverGateForTest, _stateToolsReadyForTest, _stateBeforeSendForTest, _stateOnResponseForTest, _noteRoutedForTest, _resetRoutedForTest, _resetWebProfileWarningForTest, _resetNonWebTraceForTest, _resetTitlesForTest, type PluginContext } from "../src/agent/dsh-native.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"; @@ -1292,10 +1292,22 @@ 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); 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 }); + } +}); From 77c60b09f8940e64b2facc5d68dc7a3d3a25497a Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 27 Oct 2026 01:15:30 +0800 Subject: [PATCH 2/4] docs: document dsh.keepCommandCompact / BILI_DSH_KEEP_COMMAND_COMPACT (#4872) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Config-surface seeds (website/config-reference/{server,env-only}.yaml), generated CONFIGURATION.md tables (en/zh via gen-config-docs), manual long-form env rows, and CLIENTS.md/.zh-CN.md web-profile paragraphs: the overlay's /compact re-enable is now scoped to the explicit command — auto-compaction still has no re-enable switch by design (#3651/#3666); /compact-triggered calls remain gated by the #1729 wire guard. --- CLIENTS.md | 23 ++++++++++++++++------- CLIENTS.zh-CN.md | 2 +- CONFIGURATION.md | 6 +++++- CONFIGURATION.zh-CN.md | 6 +++++- website/config-reference/env-only.yaml | 8 ++++++++ website/config-reference/server.yaml | 11 +++++++++-- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/CLIENTS.md b/CLIENTS.md index 0464438dc4..1cb3439b29 100644 --- a/CLIENTS.md +++ b/CLIENTS.md @@ -104,19 +104,28 @@ 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). 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/CLIENTS.zh-CN.md b/CLIENTS.zh-CN.md index f3bf53773e..d0a806d91f 100644 --- a/CLIENTS.zh-CN.md +++ b/CLIENTS.zh-CN.md @@ -14,7 +14,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)。若你运行依赖 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/CONFIGURATION.md b/CONFIGURATION.md index 83461bf386..b18209531f 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -117,10 +117,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" | auto | ACP_PROMPT_CACHE_ROUTING | Prompt-cache routing posture for cache-aware lane selection. | | `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. | @@ -356,6 +357,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_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 via the async twins; export too). Wins over the file tier. | | `BILI_MYSQL_DSN` | string | unset | — | MySQL DSN (mysql://user:pass@host:3306/db) for storage.backend="mysql" (#3388, #3931). Wins over the file key storage.mysql.dsn. Empty = the mysql backend cannot open; the documented error names both knobs. The pool opens lazily; closeQuietlyAsync drains the ingest queue and closes it. | @@ -1795,6 +1797,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) | @@ -1957,6 +1960,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. 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/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 042d98091e..36aed7eb87 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -117,10 +117,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" | auto | ACP_PROMPT_CACHE_ROUTING | 面向缓存感知路由选择的提示词缓存路由姿态。 | | `cacheKeepalive.enabled` | boolean | false | BILI_CACHE_KEEPALIVE | Anthropic 线路空闲期提示缓存保活总开关(#3376):会话空闲时按 TTL 推导的节奏以 max_tokens=1 重放最后一次转发的请求体,维持上游前缀缓存温热;以 usage.cache_read_input_tokens 验证命中,miss/429/连续错误/时长上限即停;支持逐 provider 路由与逐模型覆盖。 | @@ -356,6 +357,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_STORAGE_BACKEND` | sqlite\|mysql | sqlite | — | storage.backend 的环境变量层(#3931):sqlite(默认)或 mysql(已接线,#3388 第二+三步 —— 保存经异步影子队列入 mysql,同步读走 JSON 信封,replicas/ext/GC 走异步孪生;export 同样支持)。优先于文件层。 | | `BILI_MYSQL_DSN` | string | unset | — | storage.backend="mysql" 的 MySQL DSN(mysql://user:pass@host:3306/db)(#3388,#3931)。优先于文件键 storage.mysql.dsn。留空 = mysql 后端无法打开;文档化错误会列出两个旋钮。连接池惰性打开;closeQuietlyAsync 排空入队事务并关闭。 | @@ -1778,6 +1780,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) | @@ -1935,6 +1938,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 激活时一次性解析,改动在下次 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/website/config-reference/env-only.yaml b/website/config-reference/env-only.yaml index f615a194c9..5dbb0f1019 100644 --- a/website/config-reference/env-only.yaml +++ b/website/config-reference/env-only.yaml @@ -18,6 +18,14 @@ entries: group: envonly 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 重启生效。" + - 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 重启生效。" - 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 ae67749e6f..c62bad8f78 100644 --- a/website/config-reference/server.yaml +++ b/website/config-reference/server.yaml @@ -347,8 +347,8 @@ 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_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——见接下来的条目。" - key: dsh.authoredCompaction type: boolean default: "true (on, #3901 flip)" @@ -369,6 +369,13 @@ entries: group: behavior 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 开关)。默认缺省 = 内置名不变。" + - 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 激活时解析)。" - key: resign type: "scheme → { enabled?, passthrough?, credentialRef? }" default: "{} (armed; built-in scheme sdk-hmac-sha256)" From 337a658351960a52254952cfd011f3c5fed411b6 Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 27 Oct 2026 02:08:15 +0800 Subject: [PATCH 3/4] fix(lifecycle): register BILI_DSH_KEEP_COMMAND_COMPACT in the LIFECYCLE.md ledger (#4872) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lifecycle-ledger-guard CI job requires every BILI_* env var read from src/ to be registered in LIFECYCLE.md. The keepCommandCompact switch added by this PR was missing from the ledger, so the guard failed on the PR head. Added it under §1 (transition switches): it is an opt-in scope narrowing of the #3354 load-time overlay, and retires with the next-phase decision to unbind auto-compaction entirely (#4872). --- LIFECYCLE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/LIFECYCLE.md b/LIFECYCLE.md index fdb7f323a4..1f0125d806 100644 --- a/LIFECYCLE.md +++ b/LIFECYCLE.md @@ -48,6 +48,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)走 | 排查逃生口 | From eb8c097f5ebf4c9d80bbf15eb723ea48d4017c49 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 19:28:45 +0800 Subject: [PATCH 4/4] feat(dsh): visible /compact stub when the bili gate stands the command down (#4872/#6814) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Field evidence (#6814, duplicate of #4872): with the #3354 overlay disabling command-compact in a web profile, a typed /compact is demoted by dsh to a PLAIN model message (user/message with rpcId) — no command error, no visible signal, and the user never learns compaction is owned by bili. Register a visible /compact stub in bili-native when bili owns the lane, the overlay latched (gap===null), the profile is web, and dsh.keepCommandCompact is unset — exactly the case where the real command is stood down. The stub answers with kind:success and a message naming billion-context ownership, /acp for live state, and the knob to restore dsh's own /compact. Gating: knob ON re-arms the real command (stub would shadow it); non-web profiles keep the host-plane /compact armed (no stub); overlay gap means the real command may be armed (no stub). The bundles/gap probes are hoisted out of the once-guard (they are pure structural typeof checks — cheap, side-effect-free) so the registration site can reuse the same verdicts; the once-guard now only gates the durable boot note. Tests: tests/dsh-native.test.ts — stub registered + answers visibly (web, knob off); absent (knob on / non-web / overlay gap). Suite 77/77; gate batch issue4872/3354/3662/4147 25/25; typecheck clean. --- docs/clients.md | 17 +++++---- docs/clients.zh-CN.md | 2 +- docs/configuration.md | 2 +- docs/configuration.zh-CN.md | 2 +- src/agent/dsh-native.ts | 69 +++++++++++++++++++++++------------ tests/dsh-native.test.ts | 73 +++++++++++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+), 34 deletions(-) diff --git a/docs/clients.md b/docs/clients.md index 6a6308ed18..852928d309 100644 --- a/docs/clients.md +++ b/docs/clients.md @@ -138,13 +138,16 @@ Two lanes, same plugin (#941): 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). 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); + 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 enters the rewrite (always diff --git a/docs/clients.zh-CN.md b/docs/clients.zh-CN.md index 0a5c6ae094..0e29eaff2e 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` 行(以及未设 `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)。若你运行依赖 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]` 日志,说明两条路径。 +- **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.md b/docs/configuration.md index b942a743cd..c82e0843c4 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2151,7 +2151,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. Resolved once at bili-native activation, so a change takes effect on the next dsh/host restart. | +| `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 f7d586f071..3e806568c9 100644 --- a/docs/configuration.zh-CN.md +++ b/docs/configuration.zh-CN.md @@ -2123,7 +2123,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 激活时一次性解析,改动在下次 dsh/宿主重启生效。 | +| `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/src/agent/dsh-native.ts b/src/agent/dsh-native.ts index ff6b533b24..6ec9959f4d 100644 --- a/src/agent/dsh-native.ts +++ b/src/agent/dsh-native.ts @@ -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 { declareDshCompactionActive, detectCompactionOverlayGap, dshCompactionGateTelemetry } from "./dsh-compaction-disable.js"; +import { 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"; @@ -2823,30 +2823,32 @@ 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. @@ -2877,6 +2879,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/tests/dsh-native.test.ts b/tests/dsh-native.test.ts index cf1a7989ae..b795fcf3a1 100644 --- a/tests/dsh-native.test.ts +++ b/tests/dsh-native.test.ts @@ -1360,6 +1360,79 @@ test("#3354/#3662 apply(): declares lane ownership instead of registering the ov } }); +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); + _resetDshCompactionVerdictForTest(); + } +}); + test("apply() runtime-info (#955): model services stamp model/window/max-output headers", async () => { const proxy = await startMockProxy([]); const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-dsh-ri-"));