diff --git a/.github/workflows/announcements-gate.yml b/.github/workflows/announcements-gate.yml new file mode 100644 index 0000000000..c6e8774e0f --- /dev/null +++ b/.github/workflows/announcements-gate.yml @@ -0,0 +1,36 @@ +name: announcements-gate + +on: + # #5548 §五.4: the ONLY new CI touchpoint for the announcement surface — + # validate announcements/remote.json with the client's own validator module + # so a bad push is blocked before merge (PR) or right after land (push). + pull_request: + types: [opened, synchronize, reopened] + branches: [master, agent-relay] # #3468: agent PRs target the relay branch + paths: + - "announcements/remote.json" + - ".github/workflows/announcements-gate.yml" + push: + branches: [master] + paths: + - "announcements/remote.json" + workflow_dispatch: + +concurrency: + group: announcements-gate-${{ github.ref }} + cancel-in-progress: ${{ github.event_name != 'schedule' }} + +jobs: + validate: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [22] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: npm + - run: npm ci --no-audit --no-fund + - run: node --import tsx scripts/validate-remote-announcements.ts diff --git a/AGENTS.md b/AGENTS.md index b9b1e4e5e5..8c1d62f35c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,6 +58,8 @@ The full file-by-file map lives in [reference/architecture.md](reference/archite 15. **全量重发水位快路径(full-resend watermark fastpath — #5403/#5418,rollout `pluginFullResendWatermark` 实验性灰度(默认约 5% 安装开启,owner 裁定 2026-11-02:先小流量灰度,web 面板一次性公告+快速开关同步出厂)) — 插件车道(dsh threads 模型等宿主)**每轮把完整历史重发**一次;legacy 路径每轮对整包 body 做一次 `JSON.parse` + `openaiToCore` 全量转换,`snapshotMessages` 再把 AST 钉进 `session.lastMessages` 跨轮驻留——这是 #5403 OOM(81 MiB 入站 → 数百 MB 常驻)的生产者对。机制:每个成功响应上服务端盖 `x-bili-pf-seq` = 该请求 messages 元素数 T(由 `src/server/fastpath-scan.ts` 的**结构扫描**测出——单遍字符遍历,零分配、零解析);客户端下一轮把它作为 `x-bili-pf-count` 回带;v2 身份通道:再回带 `x-bili-pf-tail-ids` = 上一锚点元素 + 全部新增元素的**宿主 msgid** 逐段百分号编码(宿主 body 不带 id,但注入的 shim 能从宿主上下文读到并代发,#4491 同一套逐元素筛查;owner 层级 msgid>顺序>hash #11——缺字段=纯计数模式零回归;**无对齐证明**(owner 裁定 2026-11-02:宿主本就压缩/改写历史,证明永远对不上且自伤)——坏槽位随 `?` 占位符旅行不毒邻居(压缩后 `acp_summary` 槽不再杀整份列表),整份解析失败才清空存储列表;长度/重复/坏段=**静默降级本轮、不计熔断**(重盖戳自愈),锚点 id 仅在两侧都是已知 id 时校验。v4 计数降级(owner 裁定 2026-11-02):某轮带形状合格且宽度与服务端账本吻合(`len = T − K + 1`,服务端重验)的 tail-ids 列表时,K 取自**服务端账本**(seed.stampT)而非客户端回显——`x-bili-pf-count` 该轮降级为纯诊断(缺失/错乱回显不产生 miss,决策串留痕 `hit(no-count)`/`hit(count-off=N)`,永不喂熔断);无合格列表时旧阶梯逐字节不变;前缀收缩(compaction/truncation)的宽度算式出非正值、id 列表不可能满足,credited ahead/seed-stale 照旧触发;零增量轮(T==K)即便带合格单元素列表也保 no-progress(空窗会钉空 lastMessages 基线)。客户端收敛为**一台状态机**(`src/agent/pf-channel.ts`)+ **一个发戳点**:全局 fetch 拦截(`src/agent/native-intercept.ts`)对全部插件车道模型请求盖头(`/bili/` 路由分支、provider URL 重写分支、以及直连代理的自分支——provider URL 直指 bili 根,dsh profile bundle 即此类;三条出网点盖戳+学习对称),车道之间只剩「在哪拿到 msgid」的薄采集适配器——dsh `hostMsgIdsOf` 的逐槽变体 `pfSlotIdsOf`(`?` 占位,见上);pi 共享 entry walker 两族(anthropic `laneMsgIdsForWire` / chat-completions `laneMsgIdsForOpenAiWire`,后者的 config-assembled 前导 system 槽无 branch entry,用合成 `bili-ps-N` 位置令牌覆盖——链不会死在第一个 system 元素上,槽位挪动仍诚实断锚);opencode 复用 transform 钩子已对齐的同一份验证列表;omp 在 fetch 层把宿主 `before_provider_request` 暂存的 branch 条目与实际出体对齐(`ompTurnMsgIds`,与增量信封共用这同一份;**仅 anthropic wire 回合**——其严格 count+role 证明桥不过 config-assembled 前导 system 段,若对 openai 形失败清空会抹掉共享钩子对同一会话刚落下的列表;openai 形回合由共享 `laneMsgIdsForOpenAiWire` 解析器单独覆盖,#2583 逐模型 egress)。pi/opencode/omp 解析器仍是全有全无:整份验证失败立即清空存储列表(陈旧锚点比没字段更糟;dsh 逐槽采集不受此限,见上)。命中条件 = K 由回带 count(v4 下由账本算式)定出、进程内种子恰在 K 盖戳且模型未换、头部 8 元素的 system 与种子逐字一致、窗口首无 system/developer(hoist 险)——全部通过时,管道输入从「全量解析」换成「上一轮的 canonical cores(模块级 WeakMap,不进 Session 面板)+ 仅尾窗 [K..T) 新解析」,尾窗 cores 的 cluster id/wireIndex 按前缀重编号(`openaiToCore` 的 ClusterCounter 按调用内次序编号、prune first-user-pin 依赖 wireIndex 连续,K=1 合并情形有回归钉)。任何疑点(无/坏/旧 stamp——除 v4 账本级 tail-ids 撑场、模型切换、头部漂移、扫描失败、熔断器)整轮走**原封未动的 legacy 全量路径**并重新盖戳,客户端一轮收敛;5 次连续「可证实」miss 触发熔断持有一小时(持有期间继续扫描并盖戳把真值教回客户端,否则旧 stamp 永不收敛)。退出开关:`rollout.features.pluginFullResendWatermark: true/false`(或百分比)/ env BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0,web「配置」页快速配置也有同效三态开关。诚实边界:① **保元素数的前缀字节改写不可检测**(代价即跳过逐条复核的信任模型变化——§7.4 需人工评审,不得自动合并);② kernel 按位置区分 user content-array 图片在尾部 vs 历史中部的渲染,**多模态尾部一旦进入缓存,该段历史此后永久降级回 legacy 全量轮**(宁降级不偏离);③ marker-strip 计数随种子账本继承(中部区从不重扫);④ pf-* 握手头是**协议头不是 hop 头**:转发上游前剥掉(`UPSTREAM_HOP_HEADERS`)。本地实测(dog 机,2026-11-02):真实 pi REPL + sglang openai 线,turn1 no-stamp → turn2-4 连续 `fastpath HIT T=4/6/8`(单进程会话内回环生效;每次 `pi -p` 是新进程,戳表不跨进程)。证据:`tests/issue5403-watermark-fastpath.test.ts`(A/B hermetic 双代理:出站字节逐字一致仅 time attr 归一、stamp 逐轮收敛、pf-* 头不出代理、驻留带 lastMessages 8684B→1210B @ 8 回合语料)、`tests/fastpath.test.ts`(verdict 阶梯全表)、`tests/fastpath-scanner.test.ts`(对抗集+50k 规模)、`tests/lane-decisions-matrix.test.ts` 行。实测收益:命中轮跳过全量解析/转换/钉存(服务端 CPU 与 RSS 峰值消失);未命中轮只多付一次结构扫描。**与增量车道(#3248/#4491)的关系——可同开、互不双处理**:两机制服务同一痛点(插件宿主全量重发)但按请求形状分轨:dsh 的 divert 只接 **anthropic wire**(`wireMessagesLookAnthropic` 门,OpenAI tool 形态走全量重发,#3433),而 #5403 这类 chat-completions(openai profile)会话增量车道根本不发散 → 水位快路径正是那些会话的专属机制;anthropic-wire 会话则反之由增量车道接管。同一请求恒走其中一条路(dsh shim 逐回合二选一),服务端对带 `x-bili-plugin-turn` 标记的请求跳过水位判定(不打混合标,KDD 行首阶梯 `incrementalTurn` 行),增量响应不盖 pf-seq、改盖 `x-bili-applied-seq`;divert 合成重入请求的头上游是显式白名单(不含 pf-*)→ pf-* 头绝不到模型端点。残留无害情形:某会话混用时旧 pf-count 可能多陪跑一轮验证(服务端当轮重盖真值即收敛)。附带发现另案登记:legacy 自身存在 mid-history 图片压平 quirk(与本特性无关)。 +16. **公告面三来源(unified announcement surface — #5548,设计 v2 owner 已批准)** —— Web UI 公告只有**一套渲染器**(`src/web/client.ts` 的 `renderAnnouncementBanners`:textContent-only、零 innerHTML 外部数据、顶部最多 5 条横幅其余进面板列表),三个来源汇入同一个 `notices[]` 载荷(`GET /__bili/notices` + overview):**A 内置声明**(`src/notices.ts` 的 `BUILTIN_NOTICES` 表,与代码行为绑定、评审门在代码里)、**B 本地 JSON**(`~/.config/billion-context/announcements/*.json`,每文件一条记录 ≤64KB,loader `src/local-announcements.ts` 按 name:size:mtime 签名 memo、坏文件单独跳过+warnOnce)、**C 远程 GitHub raw**(本仓库 master 的 `announcements/remote.json` `{v:1,entries:[…]}`,发布/撤回 = git push;fetcher `src/remote-announcements.ts` 按自更新同节奏(复用其 egress 出口、独立计时)、timeout 8s、非关键路径 A/B 先行渲染 C 到齐补渲染、成功落 last-known-good 快照 `/announcements-remote-snapshot.json`、失败展示上次快照、首次失败则无 C)。同 id 冲突 **B > C > A**。三来源共用同一白名单校验器(`validateNoticeRecord`:未知字段丢弃+debug 日志、坏值只杀本条记录;文本上限 title≤120/desc≤600/hint≤300;ctaUrl http(s)≤200)与同一套 targeting(`versions` 匹配器精确钉/比较符/^caret/区间列表 AND 组合、脏版本号按数值体比、本地版本不可解析→带 gate 的记录隐藏宁缺毋滥;`percent` 分桶 sha256(installId|id)%100——installId 是 state 目录持久化的稳定 uuid `src/install-id.ts`,不可持久化时隐藏而非闪动;`since` 闭/`until` 开时间窗)。关闭语义三态:persistent(默认;存储键升级为 `id@sha16(normalized record)`——内容改动复现一次,旧裸 id 键仍生效所以升级不会让已关横幅复活;store FIFO 上限 200 键)、instance(仅进程内存,重启复现)、always(不渲染关闭按钮,永不隐藏,重大事故用)。排序 priority desc → publishedAt desc(kind 默认 incident 90 > upgrade-advisory 80 > warning 70 > deprecation 60 > suggestion 50 > new-feature 40 > other 30,显式 priority 覆盖)。逃生门 env `BILI_ANNOUNCEMENTS_URL`(path-relocation 类,缺省官方 raw 地址,防火墙中继用)。CI 门 `.github/workflows/announcements-gate.yml` 对触碰 `announcements/remote.json` 的 PR/push 跑与客户端同一个校验模块(`scripts/validate-remote-announcements.ts`:schema+体量帽+matcher 可解析性+时间格式)——坏推送合并前拦住。信任边界 A(评审门) > B(owner 本机权限) > C(repo push 权);单向广播、**零遥测**(隐私红线);任何来源不可用/坏格式只是该来源缺席,天花板 = 无横幅,永不红屏。模块边界:纯函数层全在 `src/notices.ts`(无 fs/io),fs 只在 install-id/local-announcements/remote-announcements 三个薄模块。测试:`tests/notices-registry.test.ts`、`tests/notices-local-lane.test.ts`、`tests/remote-announcements.test.ts`(四注入:断网/慢响应/坏JSON/超大文件)+ P1 客户端渲染测试 `tests/web-notices-banner.test.ts`。新增内置横幅 = 往 `BUILTIN_NOTICES` 加一条记录(约 10 行 diff,不改其他文件)。 + ### Install-Lane & Update-Ownership Contract (#1196) Every bili presence on a machine follows ONE contract — decide changes against it, not ad hoc: diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 17bcb8ea11..fc25f55cd9 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -15,6 +15,7 @@ | **Config file (explicit)** | value of `BILI_CONFIG_FILE` | points directly at any JSON file | | **CLI flag** | `--config ` | same as `BILI_CONFIG_FILE`; highest precedence for the file path | | **Session data** | `~/.local/share/billion-context/sessions/` | persisted compression state, grows over time | +| **Local announcements (#5548)** | `~/.config/billion-context/announcements/*.json` | user-owned announcement records, one per file (≤64 KB each); drop a file → it appears on the next overview poll, delete it → it disappears. Same whitelist schema as the remote lane; unknown fields dropped, a bad file is skipped individually and never takes down the others | On first run, `billion-context` seeds an empty template (`{ "providers": {} }`) at the config path so you have something to edit. It never overwrites an existing file. @@ -371,6 +372,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `BILI_SNAPSHOT_SHADOW` | boolean | true (on) | — | Snapshot-render shadow observability (#3756 follow-up): compute the outbound snapshot view on every armed turn WITHOUT using it, classify the diff against the legacy outbound, and surface per-session counters in the web panel + the snapshot-shadow diagnostics topic. 0/false/off disables; 1/true/on enables; otherwise the config-file snapshot.shadow boolean applies (default on). The render lane itself stays rollout-gated (BILI_ROLLOUT_SNAPSHOT_RENDER), so the shadow lane never changes outbound bytes - it is the dry-run evidence that flips the rollout later. | | `BILI_CONFIG_FILE` | string | unset (XDG config path) | — | Override the config file path (path relocation). | | `BILI_SESSIONS_DIR` | string | unset (XDG state path) | — | Where session records are stored (path relocation). | +| `BILI_ANNOUNCEMENTS_URL` | string | official raw URL of announcements/remote.json | — | Override the remote announcements document URL (#5548 lane C): installs behind firewalls can point bili at their own relay of announcements/remote.json; unset = the official raw address. Path relocation; fail-open either way (unreachable or malformed document = no remote lane, never blocks startup or traffic). | | `BILI_ENCRYPTION_KEY` | string | unset | — | Key material for encrypted persisted payloads (secret). | | `BILI_TUNNEL_ALLOWED_HOSTS` | string[] (csv) | unset | — | Host allowlist for the MITM tunnel lane. | | `BILI_RECLAIM_FETCH_PATCH` | boolean-ish | on | — | Toggle for reclaiming the global fetch patch on shutdown. | @@ -1794,7 +1796,7 @@ For a request to `https://api.anthropic.com/v1/messages` with model `claude-sonn Environment variables take precedence over the config file. They are useful for environment-specific overrides (CI, containers) without editing the file. -**Precedence model (#2030).** Every behavior knob resolves as **env var > config file > built-in default**. Since #2030 each pure-behavior knob ALSO has a config-file key, so a deployment can live entirely in `billion-context.json`; the env var remains the override tier. A *set* env var owns its knob even when its value is garbage — it parses exactly as it did before #2030 (falling back to the default) and neither leaks into nor gets shadowed by the file tier. Env-only variables are reserved for what cannot live in the file: secrets (`BILI_LAUNCH_TOKEN`, `BILI_ENCRYPTION_KEY`), per-process channels written by another bili component at spawn (`BILI_MCP_PROXY`, `BILI_PARENT_PID`, `BILI_STRICT_PORT`, `BILI_OPENCODE_ACP_SPEC`, `BILI_LAUNCHER_MODEL_*`), host-side posture read inside third-party host processes (`BILLION_CONTEXT_PLUGIN*`, `BILI_NATIVE_*`, `BILI_RECLAIM_FETCH_PATCH`), path relocation (`BILI_CONFIG_FILE`, `BILI_SESSIONS_DIR`, `ACP_DUMP_DIR`, `XDG_*`), and third-party conventions (`CLAUDE_CODE_SESSION_ID`, `CODEX_HOME`, `https_proxy`). New knobs follow the rules in AGENTS.md "Environment Variable Discipline". +**Precedence model (#2030).** Every behavior knob resolves as **env var > config file > built-in default**. Since #2030 each pure-behavior knob ALSO has a config-file key, so a deployment can live entirely in `billion-context.json`; the env var remains the override tier. A *set* env var owns its knob even when its value is garbage — it parses exactly as it did before #2030 (falling back to the default) and neither leaks into nor gets shadowed by the file tier. Env-only variables are reserved for what cannot live in the file: secrets (`BILI_LAUNCH_TOKEN`, `BILI_ENCRYPTION_KEY`), per-process channels written by another bili component at spawn (`BILI_MCP_PROXY`, `BILI_PARENT_PID`, `BILI_STRICT_PORT`, `BILI_OPENCODE_ACP_SPEC`, `BILI_LAUNCHER_MODEL_*`), host-side posture read inside third-party host processes (`BILLION_CONTEXT_PLUGIN*`, `BILI_NATIVE_*`, `BILI_RECLAIM_FETCH_PATCH`), path relocation (`BILI_CONFIG_FILE`, `BILI_SESSIONS_DIR`, `ACP_DUMP_DIR`, `BILI_ANNOUNCEMENTS_URL`, `XDG_*`), and third-party conventions (`CLAUDE_CODE_SESSION_ID`, `CODEX_HOME`, `https_proxy`). New knobs follow the rules in AGENTS.md "Environment Variable Discipline". ### Config-file keys for environment knobs (#2030) @@ -1974,6 +1976,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes | `BILI_RECLAIM_FETCH_PATCH` | Set to `0` to disable the native-mode fetch self-heal re-arm (#1158). By default the native fetch intercept installs `globalThis.fetch` as a guarded accessor, so a third-party patch that re-installs `globalThis.fetch` (e.g. dsh-http-proxy's settings refresh writing its frozen pre-bili `originalFetch`) is re-chained as the downstream and model traffic keeps routing through bili. With `0` the classic direct install stays: a third-party re-arm then wins and bili stops seeing model traffic for the session. **Egress note:** while the guard holds, claimed model traffic is dispatched by the bili proxy itself — it no longer rides the third-party chain's egress (e.g. a SOCKS5 proxy configured in dsh-http-proxy; bili's own upstream proxying supports HTTP proxies only). If you need the third-party egress back, set `0` and configure the egress at bili's level (`"proxy": "http://…"`). **Coexistence note (#3528):** the default accessor form is incompatible with third-party components that require `globalThis.fetch` to be a plain writable data property — they read its property descriptor, find no `value`, and abort their fetch observer at load (reported: DSH Desktop's Developer Tools / NodeJS diagnostic plugin, `@deepseek-ai/dsh-experimental-inspector`). Set `0` (then fully restart the host) so such observers load via the classic direct install; you accept the trade-offs above. See #3528. | | `BILI_RESIGN` | Set to `0` to un-deploy the #1884 re-sign arm end to end (pre-fix behavior: signed bodies ride the normal rewrite path and fail upstream with 401). Default: armed — a signed model request that can be re-signed (SDK-HMAC-SHA256 with a resolvable credential) tunnels with every egress body re-signed; the arm needs no configuration on dsh (account-pool discovery via the credentials service). A BUILT-IN-scheme request that CANNOT be re-signed (no resolvable credential) is refused locally with 403 and an actionable message — its fix (provide the credential) is actionable. Every OTHER detected scheme (SigV4, gateway-invented headers like `x-ofm-signature` — detection is shape-based, #2090) has no credential source anywhere in bili, so it is ALWAYS refused (binary contract: re-signed+compressed or refused, never passed through unsigned): a 403 naming the scheme, remembered in `resign-pending.json`, and re-warned at every startup (and shown in the web UI) until bili ships the scheme's re-signer. `BILI_RESIGN_PASSTHROUGH=1` turns on verbatim no-compression forwarding for the BUILT-IN scheme only — it is inert for every other scheme. `enabled` / `passthrough` / `credentialRef` have config-file twins under the [`resign`](#resign) block, keyed by signature scheme (`resign["sdk-hmac-sha256"]`; `providers..resign[""]` is the level-2 override) — env vars win over the file. Scheme keys pin the passthrough opt-in: only the scheme whose key sets it tunnels. Related: `BILI_RESIGN_BENEFIT` (comma-separated list of CodeArts benefit models whose requests get the signed `maas_type: benefit` header — wins over the whole three-level tree; file-side twin is the level-3 `models..benefit` boolean, unset falls back to the built-in `glm-5.3-flash,deepseek-v4.1-flash`, mirroring the dsh codearts plugin's `CODEARTS_BENEFIT_FALLBACK`) and `BILI_CODEARTS_REF` (force the dsh credentials-service ref used for re-signing instead of discovering enabled `codearts` accounts from `$DSH_HOME/jet-hub/state.json`). | | `BILI_CONFIG_FILE` | Override the config file path (point at any JSON file). | +| `BILI_ANNOUNCEMENTS_URL` | Override the remote announcements document URL (#5548 lane C). Default: the official raw URL of `announcements/remote.json` on this repo's master. Path-relocation escape hatch for installs behind a firewall that cannot reach raw.githubusercontent.com — point it at your own relay serving the same `{v:1, entries:[…]}` document. Env-only by design (no config-file twin): it relocates a fetch target, and the remote lane is fail-open either way. | | `ACP_PORT` / `PORT` | Override the listen port. | | `ACP_HOST` | Override the listen host. | | `ACP_UPSTREAM` | Override the default upstream base URL. | diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 600daf8c27..ee9e230ada 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -15,6 +15,7 @@ | **配置文件(显式指定)** | `BILI_CONFIG_FILE` 的值 | 直接指向任意 JSON 文件 | | **CLI 参数** | `--config ` | 与 `BILI_CONFIG_FILE` 等价,文件路径优先级最高 | | **会话数据** | `~/.local/share/billion-context/sessions/` | 持久化的压缩状态,会随时间增长 | +| **本地公告(#5548)** | `~/.config/billion-context/announcements/*.json` | 用户自有的公告记录,每文件一条(单文件 ≤64 KB);丢一个文件进去 → 下一次概览轮询即出现,删掉 → 消失。与远程车道共用同一套白名单 schema;未知字段丢弃,坏文件单独跳过、绝不拖垮其余文件 | 首次运行时,`billion-context` 会在配置路径下生成一个空模板(`{ "providers": {} }`),方便你直接编辑。它**不会**覆盖已存在的文件。 @@ -371,6 +372,7 @@ | `BILI_SNAPSHOT_SHADOW` | boolean | true (on) | — | 快照渲染影子对账(#3756 后续):每轮已折叠会话都用引擎现算一次出站快照视图但不使用,与 legacy 实际出站比对分类,逐会话计数进 web 面板与 snapshot-shadow 诊断主题。0/false/off 关闭;1/true/on 开启;否则读配置文件 snapshot.shadow 布尔(默认开)。渲染车道本身仍受灰度开关控制(BILI_ROLLOUT_SNAPSHOT_RENDER),影子车道绝不改变出站字节 —— 它是后续翻转灰度的干跑证据。 | | `BILI_CONFIG_FILE` | string | unset (XDG config path) | — | 覆盖配置文件路径(路径重定位)。 | | `BILI_SESSIONS_DIR` | string | unset (XDG state path) | — | 会话记录的存放目录(路径重定位)。 | +| `BILI_ANNOUNCEMENTS_URL` | string | official raw URL of announcements/remote.json | — | 覆盖远程公告文档地址(#5548 C 车道):防火墙后的装机可指向自己中继的 announcements/remote.json;缺省 = 官方 raw 地址。路径重定位类;任何情况下 fail-open(拉不到/文档坏 = 无远程车道,永不阻断启动或流量)。 | | `BILI_ENCRYPTION_KEY` | string | unset | — | 加密持久化载荷的密钥材料(机密)。 | | `BILI_TUNNEL_ALLOWED_HOSTS` | string[] (csv) | unset | — | MITM 隧道车道的主机白名单。 | | `BILI_RECLAIM_FETCH_PATCH` | boolean-ish | on | — | 进程退出时回收全局 fetch 补丁的开关。 | @@ -1777,7 +1779,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 环境变量优先于配置文件。在不修改文件的情况下,它们适用于环境特定的覆盖(CI、容器)。 -**优先级模型(#2030)。** 每个行为开关的解析顺序为 **环境变量 > 配置文件 > 内置默认值**。自 #2030 起,每个纯行为开关同时拥有配置文件键,部署可以完全放在 `billion-context.json` 里;环境变量保留为覆盖层。**已设置**的环境变量独占其开关——即使值是垃圾值,也按 #2030 之前的原样解析(回落到默认值),既不会泄漏到文件层、也不会被文件层遮蔽。纯环境变量仅保留给无法放进文件的东西:密钥(`BILI_LAUNCH_TOKEN`、`BILI_ENCRYPTION_KEY`)、由另一个 bili 组件在 spawn 时写入的进程间通道(`BILI_MCP_PROXY`、`BILI_PARENT_PID`、`BILI_STRICT_PORT`、`BILI_OPENCODE_ACP_SPEC`、`BILI_LAUNCHER_MODEL_*`)、在第三方宿主进程内读取的宿主侧姿态(`BILLION_CONTEXT_PLUGIN*`、`BILI_NATIVE_*`、`BILI_RECLAIM_FETCH_PATCH`)、路径重定位(`BILI_CONFIG_FILE`、`BILI_SESSIONS_DIR`、`ACP_DUMP_DIR`、`XDG_*`)以及第三方约定(`CLAUDE_CODE_SESSION_ID`、`CODEX_HOME`、`https_proxy`)。新开关的准入规则见 AGENTS.md「Environment Variable Discipline」。 +**优先级模型(#2030)。** 每个行为开关的解析顺序为 **环境变量 > 配置文件 > 内置默认值**。自 #2030 起,每个纯行为开关同时拥有配置文件键,部署可以完全放在 `billion-context.json` 里;环境变量保留为覆盖层。**已设置**的环境变量独占其开关——即使值是垃圾值,也按 #2030 之前的原样解析(回落到默认值),既不会泄漏到文件层、也不会被文件层遮蔽。纯环境变量仅保留给无法放进文件的东西:密钥(`BILI_LAUNCH_TOKEN`、`BILI_ENCRYPTION_KEY`)、由另一个 bili 组件在 spawn 时写入的进程间通道(`BILI_MCP_PROXY`、`BILI_PARENT_PID`、`BILI_STRICT_PORT`、`BILI_OPENCODE_ACP_SPEC`、`BILI_LAUNCHER_MODEL_*`)、在第三方宿主进程内读取的宿主侧姿态(`BILLION_CONTEXT_PLUGIN*`、`BILI_NATIVE_*`、`BILI_RECLAIM_FETCH_PATCH`)、路径重定位(`BILI_CONFIG_FILE`、`BILI_SESSIONS_DIR`、`ACP_DUMP_DIR`、`BILI_ANNOUNCEMENTS_URL`、`XDG_*`)以及第三方约定(`CLAUDE_CODE_SESSION_ID`、`CODEX_HOME`、`https_proxy`)。新开关的准入规则见 AGENTS.md「Environment Variable Discipline」。 ### 环境变量的配置键对照(#2030) @@ -1956,6 +1958,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 | `BILI_RECLAIM_FETCH_PATCH` | 设为 `0` 关闭 native 模式 fetch 自愈重武装(#1158)。默认情况下 native fetch 拦截会把 `globalThis.fetch` 装成受保护的访问器:第三方补丁重新赋值 `globalThis.fetch` 时(如 dsh-http-proxy 的 settings 刷新用冻结的 pre-bili `originalFetch` 盲覆盖),会被接链为下游,模型流量继续经过 bili。设 `0` 则回到经典直装:第三方重装生效,bili 将看不到本会话的模型流量。**出口提示:** 自愈生效期间,被认领的模型流量由 bili 代理自身派发——不再走第三方链的出口(例如 dsh-http-proxy 里配置的 SOCKS5;bili 自身的上游代理仅支持 HTTP 形式)。若需要回退第三方出口,设 `0` 并在 bili 层配置出口(`"proxy": "http://…"`)。**共存提示(#3528):** 默认的访问器形态与要求 `globalThis.fetch` 为普通可写数据属性的第三方组件不兼容——它们读取其属性描述符、发现没有 `value`,便在加载时中止 fetch 观察者(已报告:DSH 桌面「开发者工具 / NodeJS 诊断」插件,`@deepseek-ai/dsh-experimental-inspector`)。设 `0`(然后完全重启宿主)让此类观察者经经典直装正常加载;代价见上文。详见 #3528。 | | `BILI_RESIGN` | 设为 `0` 整体卸载 #1884 重签臂(回到修复前行为:带签名的请求照常改写、上游 401)。默认开启——可重签的签名请求(SDK-HMAC-SHA256 且能解析出凭据)走隧道,每个出站 body 都重签;重签臂在 dsh 上无需任何配置(经 credentials 服务做账号池发现)。**内置方案**无法重签的请求(解析不出凭据)本地拒收 403 并给出可操作提示——其修复(提供凭据)是可操作的。其他任何被检测到的方案(SigV4、`x-ofm-signature` 等网关自造头——检测是形状判定,#2090)在 bili 内部没有凭据来源也没有重签器,因此**一律本地拒收**(二元契约:重签+压缩或拒绝,绝不无签名放行):403 指明方案名,记入 `resign-pending.json`,每次启动(以及 web UI)反复提醒直到 bili 补上该方案的重签器。`BILI_RESIGN_PASSTHROUGH=1` 仅对内置方案开启原样转发(不压缩)——对其余方案无效。`enabled` / `passthrough` / `credentialRef` 有配置文件孪生项,见 [`resign`](#resign) 块——按签名方案分键(`resign["sdk-hmac-sha256"]`;`providers..resign["<方案>"]` 是二级覆盖)——环境变量优先于文件。方案键把 passthrough 钉死到具体签名:只有自己的键设了的方案才走隧道。相关:`BILI_RESIGN_BENEFIT`(逗号分隔的 CodeArts benefit 模型列表,这些请求附带参与签名的 `maas_type: benefit` 头——优先于整棵三级树;文件侧孪生项是三级的 `models..benefit` 布尔,未设置落到内置 `glm-5.3-flash,deepseek-v4.1-flash`,对齐 dsh codearts 插件的 `CODEARTS_BENEFIT_FALLBACK`)与 `BILI_CODEARTS_REF`(强制指定重签用的 dsh credentials 服务 ref,而不是从 `$DSH_HOME/jet-hub/state.json` 里发现启用的 `codearts` 账号)。 | | `BILI_CONFIG_FILE` | 覆盖配置文件路径(指向任意 JSON 文件)。 | +| `BILI_ANNOUNCEMENTS_URL` | 覆盖远程公告文档地址(#5548 车道 C)。缺省:本仓库 master 上 `announcements/remote.json` 的官方 raw 地址。供防火墙后无法访问 raw.githubusercontent.com 的装机做路径重定位逃生门——指向自己中继上同一份 `{v:1, entries:[…]}` 文档。设计为纯环境变量(无配置文件孪生项):它重定位的是一个抓取目标,且远程车道无论如何都是 fail-open。 | | `ACP_PORT` / `PORT` | 覆盖监听端口。 | | `ACP_HOST` | 覆盖监听主机。 | | `ACP_UPSTREAM` | 覆盖默认上游 base URL。 | diff --git a/LIFECYCLE.md b/LIFECYCLE.md index 073fd4ce9e..6f74de4733 100644 --- a/LIFECYCLE.md +++ b/LIFECYCLE.md @@ -183,6 +183,7 @@ | `BILI_UPDATE_CHECK_INTERVAL_MS` | update.checkIntervalMs 覆盖(#2030) | | `BILI_ADVISORY_CHECK` | 公告检查开关(默认 ON;文件 advisoryCheck:false 退出) | | `BILI_ADVISORY_URL` | 公告文档 URL 覆盖 | +| `BILI_ANNOUNCEMENTS_URL` | 统一公告面远程文档 URL 覆盖(#5548 C 车道,防火墙中继逃生门;缺省官方 raw 地址,fail-open) | | `BILI_RELEASE_NOTES_CHECK` | 发布说明检查(#1870,默认 ON) | | `BILI_RELEASE_NOTES_URL` | 发布说明 URL 覆盖 | | `BILI_UPDATE_POLICY_URL` | update.policyUrl——更新策略 URL 覆盖(**测试专用**:生产固定官方 repo,#3619 安全边界) | diff --git a/README.md b/README.md index fc00b14733..d135d7e96f 100644 --- a/README.md +++ b/README.md @@ -529,6 +529,10 @@ A **long-lived** standalone proxy can keep holding stale OS-resolver state after Independent of auto-update (#1481): even with `autoUpdate` off, the proxy polls a small companion npm package (`billion-context-advisories`, published by CI from this repo's [`advisories/`](advisories/) directory) on the same 3-minute cadence. Each advisory names a semver range of broken versions (`affected`), the exact version to install (`target` — which may be *older* than the current one, i.e. a rollback), and a user-facing `reason`. When the local version falls inside `affected`, bili force-installs `target` through the self-updater's full safety chain (cross-process lock, backup + verify + rollback; source checkouts and host-managed installs are refused with manual instructions instead) and warns prominently: a one-time `[advisory] ⚠️ …` log line per process per advisory id, a banner on the web UI showing the reason and the exact manual upgrade command, and the active entry under `advisory` in `/__bili/status`. The check is fail-open by design: an unreachable or malformed advisory source only produces a warning — model traffic is never blocked by it. Disable via config (`"advisoryCheck": false`) or env (`BILI_ADVISORY_CHECK=0`); point at a custom document with `"advisoryUrl"` / `BILI_ADVISORY_URL`. +### Announcements (#5548) + +The web UI surfaces announcements from **three sources through one renderer**: built-in declarations tied to code behavior (e.g. the `prompt_cache_key` default-flip notice, the incremental-parsing experimental intro), user-owned JSON files under `~/.config/billion-context/announcements/` (one record per `*.json` file, validated by the same whitelist schema as the remote lane), and a remote document (`announcements/remote.json` in this repo's master) fetched on the self-update cadence — publishing or retracting a remote announcement is just a push to master. Same-id collisions resolve local-over-remote-over-builtin. Every record supports targeting (`versions`, per-install `percent` bucketing, `since`/`until`) and dismissal modes: persistent (default; re-shows once if the content changes), instance (re-shows after restart), and always (no close button, major incidents). Up to five banners render at the top of the overview page, the rest list below. The whole surface is one-way broadcast with no telemetry, and every source fails open independently — an unreachable or malformed source simply contributes nothing. Behind a firewall, point the remote lane at your own relay via `BILI_ANNOUNCEMENTS_URL`. Record schema and the env var: [CONFIGURATION.md → Environment variables](CONFIGURATION.md#environment-variables). + ## Configuration The full configuration reference — config file location, top-level keys, diff --git a/README.zh-CN.md b/README.zh-CN.md index c5344beaae..a03250a5ed 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -392,6 +392,10 @@ bili --no-auto-update # 本次启动禁用自动更新 该检查默认 fail-open:公告源不可达或格式错误只产生警告,绝不阻断模型流量。禁用方式:配置(`"advisoryCheck": false`)或环境变量(`BILI_ADVISORY_CHECK=0`);可用 `"advisoryUrl"` / `BILI_ADVISORY_URL` 指向自定义文档。 +### 公告面(#5548) + +Web UI 的公告来自**三个来源、一套渲染器**:与代码行为绑定的内置声明(如 `prompt_cache_key` 默认翻转提示、增量解析实验性功能介绍)、用户自有的 JSON 文件(`~/.config/billion-context/announcements/` 下每文件一条记录,与远程车道共用同一套白名单校验)、以及本仓库 master 上的远程文档(`announcements/remote.json`,按自更新节奏拉取——发布/撤回远程公告就是向 master 推一次)。同 id 冲突时本地优先于远程、远程优先于内置。每条记录支持定向投放(`versions` 版本匹配、按安装实例的 `percent` 分桶、`since`/`until` 时间窗)与关闭模式:persistent(默认;内容变更后复现一次)、instance(重启后复现)、always(不渲染关闭按钮,重大事故用)。页面顶部最多渲染 5 条横幅,其余列在下方公告列表。整个面是单向广播、零遥测,且每个来源独立 fail-open——不可达或格式错误的来源只是缺席。防火墙后可用 `BILI_ANNOUNCEMENTS_URL` 把远程车道指向自己的中继。记录 schema 与环境变量见 [CONFIGURATION.zh-CN.md → 环境变量](CONFIGURATION.zh-CN.md#环境变量)。 + ## 配置 完整的配置参考 —— 配置文件位置、顶层键、providers、压缩调参、环境变量 —— diff --git a/announcements/remote.json b/announcements/remote.json new file mode 100644 index 0000000000..a533cf87f5 --- /dev/null +++ b/announcements/remote.json @@ -0,0 +1,4 @@ +{ + "v": 1, + "entries": [] +} diff --git a/reference/architecture.md b/reference/architecture.md index baa641963f..80e9afb507 100644 --- a/reference/architecture.md +++ b/reference/architecture.md @@ -126,6 +126,11 @@ billion-context/ │ ├── advisory.ts # Critical-defect advisory watcher (#1481) │ ├── plugin-advisory.ts # dsh cost-advisory detection + TTL cache (#2462) │ ├── host-plugin-notice.ts # Known host-side metering plugin notice + dismiss state (#2861) +│ ├── notices.ts # Unified announcement surface (#5548): built-in registry + whitelist validator + targeting gates + hash-dismiss (pure, no fs/io) +│ ├── local-announcements.ts # Lane B loader: ~/.config/billion-context/announcements/*.json, one record per file (#5548) +│ ├── remote-announcements.ts # Lane C fetcher: GitHub raw remote.json on update-check cadence + last-known-good snapshot (#5548) +│ ├── install-id.ts # Stable per-install uuid for percent bucketing (#5548) +│ ├── pck-notice.ts # Announcement dismissal store (upgrade-notices.json) + id@hash16 keys / legacy bare-id compat (#5079/#5548) │ ├── update-notes.ts # Tiered release-notes visibility (#1870/#1977) │ ├── restart.ts # Opt-in self-restart once newer code is on disk (#811) │ ├── upstream-alerts.ts # Upstream connection alert table (#1682) diff --git a/scripts/validate-remote-announcements.ts b/scripts/validate-remote-announcements.ts new file mode 100644 index 0000000000..6f1370a161 --- /dev/null +++ b/scripts/validate-remote-announcements.ts @@ -0,0 +1,32 @@ +// #5548 §五.4: CI gate for announcements/remote.json — runs the SAME validator +// module the client uses, so a bad push is blocked before merge instead of +// silently degrading on every install after push. +import fs from "node:fs"; +import { applyRemoteDoc, REMOTE_DOC_CAP_BYTES } from "../src/notices.js"; + +const file = new URL("../announcements/remote.json", import.meta.url); +let raw: string; +try { + raw = fs.readFileSync(file, "utf8"); +} catch { + console.log("announcements/remote.json absent — nothing to validate"); + process.exit(0); +} +if (Buffer.byteLength(raw) > REMOTE_DOC_CAP_BYTES) { + console.error(`FAIL: announcements/remote.json exceeds ${REMOTE_DOC_CAP_BYTES} bytes`); + process.exit(1); +} +let doc: unknown; +try { + doc = JSON.parse(raw); +} catch (e) { + console.error(`FAIL: announcements/remote.json is not valid JSON: ${String(e)}`); + process.exit(1); +} +const res = applyRemoteDoc(doc); +for (const w of res.warnings ?? []) console.warn(`WARN: ${w}`); +if (!res.ok) { + console.error(`FAIL: ${res.reason}`); + process.exit(1); +} +console.log(`OK: ${res.entries.length} entr${res.entries.length === 1 ? "y" : "ies"} validated (v${(doc as { v: number }).v})`); diff --git a/src/cli.ts b/src/cli.ts index daaea99423..73e138b122 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -37,6 +37,7 @@ import { checkForUpdate, startAutoUpdate } from "./update.js"; import { registerUpdateActions } from "./server/update-actions.js"; import { startAdvisoryWatcher, getAdvisoryState, advisoryDeferring, advisoryBlocksVersion, advisoryAwaitingFirstCheck } from "./advisory.js"; import { startReleaseNotesWatcher } from "./update-notes.js"; +import { startRemoteAnnouncementWatcher } from "./remote-announcements.js"; import { resolveProxy } from "./upstream-proxy.js"; import { runMcpStdio } from "./mcp.js"; import { PLUGIN_AGENTS, isPluginAgent, pluginInstall, pluginRemove, pluginStatusAll, pluginUpdate, renderPluginList, warnActivePluginSessions, type PluginAgent } from "./plugin-install.js"; @@ -900,4 +901,10 @@ export async function main(): Promise { resolveProxy: (url) => resolveProxy(opts.routes, opts.proxy, url, opts.proxyFallback), }); } + // #5548 lane C: the remote announcement fetch rides the update-check + // cadence (§五.2). Unconditional by design: a one-way broadcast with zero + // side effects — offline it simply never renders lane C. + startRemoteAnnouncementWatcher({ + resolveProxy: (url) => resolveProxy(opts.routes, opts.proxy, url, opts.proxyFallback), + }); } diff --git a/src/install-id.ts b/src/install-id.ts new file mode 100644 index 0000000000..2aaa3f2f6c --- /dev/null +++ b/src/install-id.ts @@ -0,0 +1,38 @@ +// #5548 P2: stable per-install identity for percent bucketing (§4.1) — same +// persistence discipline as the dismissal store (state dir, best-effort fs). +import fs from "node:fs"; +import path from "node:path"; +import { randomUUID } from "node:crypto"; +import { stateDir } from "./paths.js"; + +const INSTALL_ID_FILE = "install-id"; + +function stateDirFor(env: NodeJS.ProcessEnv): string { + const v = env.XDG_STATE_HOME; + return v && v.length > 0 ? path.join(path.resolve(v), "billion-context") : stateDir(); +} + +let cached: { dir: string; id: string } | undefined; + +/** Stable uuid persisted under the state dir. Returns "" when it cannot be + * persisted (read-only state) — percent-gated notices then hide rather than + * flicker buckets across restarts. */ +export function installIdOf(env: NodeJS.ProcessEnv = process.env): string { + const dir = stateDirFor(env); + if (cached && cached.dir === dir) return cached.id; + try { + const file = path.join(dir, INSTALL_ID_FILE); + try { + const raw = fs.readFileSync(file, "utf8").trim(); + if (/^[0-9a-f-]{36}$/i.test(raw)) return (cached = { dir, id: raw }).id; + } catch { + // first run — no file yet + } + const id = randomUUID(); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync(file, id + "\n"); + return (cached = { dir, id }).id; + } catch { + return (cached = { dir, id: "" }).id; + } +} diff --git a/src/local-announcements.ts b/src/local-announcements.ts new file mode 100644 index 0000000000..a3555db1ee --- /dev/null +++ b/src/local-announcements.ts @@ -0,0 +1,75 @@ +// #5548 P2 lane B: local announcements — one validated record per *.json file +// under /announcements/. The directory is re-scanned on every load; +// a result is memoized by a name:size:mtime signature so bad files log once +// per change instead of once per overview poll. A broken file never takes +// down the other files or the page (§六: any source unavailable → that source absent). +import fs from "node:fs"; +import path from "node:path"; +import { configDir } from "./paths.js"; +import { log } from "./logger.js"; +import { validateNoticeRecord, type NoticeRecord } from "./notices.js"; + +const ANNOUNCEMENTS_DIRNAME = "announcements"; +export const LOCAL_FILE_CAP_BYTES = 64 * 1024; // §六.3 size cap + +interface LocalAnnouncementLoad { + records: NoticeRecord[]; + errors: Array<{ file: string; reason: string }>; +} + +function announcementsDirFor(env: NodeJS.ProcessEnv): string { + const v = env.XDG_CONFIG_HOME; + const base = v && v.length > 0 ? path.join(path.resolve(v), "billion-context") : configDir(); + return path.join(base, ANNOUNCEMENTS_DIRNAME); +} + +let cache: { dir: string; sig: string; result: LocalAnnouncementLoad } | undefined; + +export function loadLocalAnnouncements(env: NodeJS.ProcessEnv = process.env): LocalAnnouncementLoad { + const dir = announcementsDirFor(env); + let entries: fs.Dirent[]; + try { + entries = fs.readdirSync(dir, { withFileTypes: true }); + } catch { + // no directory = zero local notices, not an error + return { records: [], errors: [] }; + } + const names = entries.filter((e) => e.isFile() && e.name.endsWith(".json")).map((e) => e.name).sort(); + const parts: string[] = []; + const records: NoticeRecord[] = []; + const errors: LocalAnnouncementLoad["errors"] = []; + for (const name of names) { + const file = path.join(dir, name); + let st: fs.Stats; + try { + st = fs.statSync(file); + } catch { + continue; // vanished between readdir and stat + } + parts.push(`${name}:${st.size}:${st.mtimeMs}`); + if (st.size > LOCAL_FILE_CAP_BYTES) { + errors.push({ file: name, reason: `exceeds ${LOCAL_FILE_CAP_BYTES} bytes` }); + continue; + } + let doc: unknown; + try { + doc = JSON.parse(fs.readFileSync(file, "utf8")); + } catch (e) { + errors.push({ file: name, reason: `bad JSON: ${String(e)}` }); + continue; + } + const res = validateNoticeRecord(doc); + if (!res.ok) { + errors.push({ file: name, reason: res.reason }); + continue; + } + if (res.droppedFields.length > 0) log("debug", `[notices] ${name}: dropped unknown field(s) ${res.droppedFields.join(", ")}`); + records.push(res.rec); + } + const sig = parts.join("|"); + if (cache && cache.dir === dir && cache.sig === sig) return cache.result; + if (errors.length > 0) log("warn", `[notices] local lane: ${errors.map((e) => `${e.file} (${e.reason})`).join("; ")}`); + const result: LocalAnnouncementLoad = { records, errors }; + cache = { dir, sig, result }; + return result; +} diff --git a/src/notices.ts b/src/notices.ts new file mode 100644 index 0000000000..0ceed294bb --- /dev/null +++ b/src/notices.ts @@ -0,0 +1,484 @@ +// #5548 unified announcement surface (design v2, owner-approved): three sources +// (A built-in declarations / B local JSON / C remote GitHub raw) feed ONE +// renderer through shared pure filter/sort functions and one dismissal store. +// P1 landed lane A; P2 adds lane B's machinery here: the whitelist validator, +// the targeting gates (versions matcher / percent bucketing / since-until +// window), the id@hash16 dismissal keys, and layer merging (B > C > A). +// Pure module: no fs, no io — the dismissal store stays in pck-notice.ts, the +// local-file loader in local-announcements.ts. + +import { createHash } from "node:crypto"; + +export type NoticeKind = "new-feature" | "upgrade-advisory" | "warning" | "suggestion" | "incident" | "deprecation" | "other"; +type NoticeTone = "ok" | "warn" | "info"; +type NoticeDismiss = "persistent" | "instance" | "always"; +/** Multilang copy: locale object (keys like "zh-CN"/"en") or a plain string. */ +type NoticeText = string | Record; + +export interface NoticeRecord { + id: string; + kind: NoticeKind; + title: NoticeText; + desc?: NoticeText; + hint?: NoticeText; + ctaLabel?: NoticeText; + ctaUrl?: string; + /** Explicit tone overrides the kind-derived one (toneOf). */ + tone?: NoticeTone; + /** persistent (default) | instance (process-only) | always (never hidden, no close button). */ + dismiss?: NoticeDismiss; + /** 0–100; absent/null falls back to the kind default in KIND_PRIORITY. */ + priority?: number | null; + /** ISO8601 UTC; sort tiebreak after priority (newer first). */ + publishedAt?: string; + // Targeting dimensions (§4.1) — AND-combined, applied to EVERY source: + versions?: string[]; + percent?: number | null; + since?: string; + until?: string; +} + +/** Server-side state a built-in declaration's active predicate may read. */ +interface BuiltInContext { + /** effectivePromptCacheRouting() result ("disabled"/"auto"/"enabled"). */ + promptCacheRouting: string; + /** True when the user wrote an explicit pluginFullResendWatermark rollout override. */ + wmOverridePresent: boolean; +} + +interface BuiltinNotice extends NoticeRecord { + active: (ctx: BuiltInContext) => boolean; +} + +const KIND_PRIORITY: Record = { + incident: 90, + "upgrade-advisory": 80, + warning: 70, + deprecation: 60, + suggestion: 50, + "new-feature": 40, + other: 30, +}; + +export function priorityOf(rec: Pick): number { + return typeof rec.priority === "number" ? rec.priority : KIND_PRIORITY[rec.kind]; +} + +/** Kind-derived tone: new-feature→ok, warning/incident/deprecation→warn, rest→info. */ +export function toneOf(rec: Pick): NoticeTone { + if (rec.tone) return rec.tone; + if (rec.kind === "new-feature") return "ok"; + if (rec.kind === "warning" || rec.kind === "incident" || rec.kind === "deprecation") return "warn"; + return "info"; +} + +export function dismissModeOf(rec: Pick): NoticeDismiss { + return rec.dismiss ?? "persistent"; +} + +/** Visible under the record's dismiss mode. Persistent keys are + * `id@hash16(record)`; a legacy bare-id entry (pre-P2 stores) still counts, + * so an upgrade never re-shows a banner the user already closed. */ +export function noticeVisible( + rec: NoticeRecord, + dismissedPersistent: ReadonlySet, + dismissedInstance: ReadonlySet = new Set(), +): boolean { + const mode = dismissModeOf(rec); + if (mode === "always") return true; + if (mode === "instance") return !dismissedInstance.has(rec.id); + return !(dismissedPersistent.has(dismissKeyOf(rec)) || dismissedPersistent.has(rec.id)); +} + +/** Stable sort: priority desc, then publishedAt desc (missing timestamps last). */ +export function sortNotices(list: readonly T[]): T[] { + const ts = (r: NoticeRecord): number => { + const t = r.publishedAt ? Date.parse(r.publishedAt) : NaN; + return Number.isNaN(t) ? -Infinity : t; + }; + return [...list].sort((a, b) => { + const pa = priorityOf(a), pb = priorityOf(b); + if (pa !== pb) return pb - pa; + const ta = ts(a), tb = ts(b); + if (ta !== tb) return tb - ta; + return 0; + }); +} + +/** Merge notice layers by id — earlier layers win (B local > C remote > A + * built-in, §三). Input order within a layer is preserved. */ +export function mergeNoticeLayers(layers: readonly (readonly NoticeRecord[])[]): NoticeRecord[] { + const seen = new Set(); + const out: NoticeRecord[] = []; + for (const layer of layers) { + for (const rec of layer) { + if (seen.has(rec.id)) continue; + seen.add(rec.id); + out.push(rec); + } + } + return out; +} + +// --------------------------------------------------------------------------- +// P2 lane B: validation, targeting gates, dismissal hashing (§4) +// --------------------------------------------------------------------------- + +export const NOTICE_KINDS: readonly NoticeKind[] = ["new-feature", "upgrade-advisory", "warning", "suggestion", "incident", "deprecation", "other"]; +const NOTICE_TONES: readonly NoticeTone[] = ["ok", "warn", "info"]; +const DISMISS_MODES: readonly NoticeDismiss[] = ["persistent", "instance", "always"]; +const NOTICE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/; +const TEXT_LIMITS = { title: 120, desc: 600, hint: 300, ctaLabel: 120 } as const; +const CTA_URL_MAX = 200; +const NOTICE_FIELDS: readonly string[] = [ + "id", "kind", "title", "desc", "hint", "ctaLabel", "ctaUrl", + "tone", "dismiss", "priority", "publishedAt", "versions", "percent", "since", "until", +]; + +type TextCheck = { ok: true; value: NoticeText } | { ok: false; reason: string }; + +function checkText(v: unknown, field: string, limit: number): TextCheck { + if (typeof v === "string") { + return v.length <= limit ? { ok: true, value: v } : { ok: false, reason: `${field} exceeds ${limit} chars` }; + } + if (v && typeof v === "object" && !Array.isArray(v)) { + const entries = Object.entries(v as Record); + if (entries.length === 0) return { ok: false, reason: `${field}: empty locale object` }; + for (const [k, val] of entries) { + if (typeof val !== "string" || val.length > limit) { + return { ok: false, reason: `${field}[${k}] must be a string ≤${limit} chars` }; + } + } + return { ok: true, value: v as Record }; + } + return { ok: false, reason: `${field} must be a string or locale object` }; +} + +function isKind(v: unknown): v is NoticeKind { + return typeof v === "string" && (NOTICE_KINDS as readonly string[]).includes(v); +} + +function isIso8601(v: unknown): v is string { + return typeof v === "string" && Number.isFinite(Date.parse(v)); +} + +function isIntInRange(v: unknown, lo: number, hi: number): v is number { + return typeof v === "number" && Number.isInteger(v) && v >= lo && v <= hi; +} + +/** Whitelist validator (§4): unknown fields are dropped (reported, not fatal); + * a bad value invalidates ONLY this record. Returns the cleaned record. */ +export function validateNoticeRecord(raw: unknown): { ok: true; rec: NoticeRecord; droppedFields: string[] } | { ok: false; reason: string } { + if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { ok: false, reason: "record is not an object" }; + const src = raw as Record; + const droppedFields = Object.keys(src).filter((k) => !NOTICE_FIELDS.includes(k)); + const id = src["id"]; + if (typeof id !== "string" || !NOTICE_ID_RE.test(id)) return { ok: false, reason: "id must match ^[a-z0-9][a-z0-9-]{0,63}$" }; + const kind = src["kind"]; + if (!isKind(kind)) return { ok: false, reason: `kind must be one of: ${NOTICE_KINDS.join(" / ")}` }; + const title = checkText(src["title"], "title", TEXT_LIMITS.title); + if (!title.ok) return { ok: false, reason: title.reason }; + const rec: NoticeRecord = { id, kind, title: title.value }; + if ("desc" in src) { + const d = checkText(src["desc"], "desc", TEXT_LIMITS.desc); + if (!d.ok) return { ok: false, reason: d.reason }; + rec.desc = d.value; + } + if ("hint" in src) { + const h = checkText(src["hint"], "hint", TEXT_LIMITS.hint); + if (!h.ok) return { ok: false, reason: h.reason }; + rec.hint = h.value; + } + if ("ctaLabel" in src) { + const c = checkText(src["ctaLabel"], "ctaLabel", TEXT_LIMITS.ctaLabel); + if (!c.ok) return { ok: false, reason: c.reason }; + rec.ctaLabel = c.value; + } + if ("ctaUrl" in src) { + const u = src["ctaUrl"]; + if (typeof u !== "string" || u.length > CTA_URL_MAX || !/^https?:\/\//.test(u)) { + return { ok: false, reason: `ctaUrl must be http(s) ≤${CTA_URL_MAX} chars` }; + } + rec.ctaUrl = u; + } + if ("tone" in src && !NOTICE_TONES.includes(src["tone"] as NoticeTone)) return { ok: false, reason: "tone must be ok/warn/info" }; + else if ("tone" in src) rec.tone = src["tone"] as NoticeTone; + if ("dismiss" in src && !DISMISS_MODES.includes(src["dismiss"] as NoticeDismiss)) return { ok: false, reason: "dismiss must be persistent/instance/always" }; + else if ("dismiss" in src) rec.dismiss = src["dismiss"] as NoticeDismiss; + if ("priority" in src) { + if (src["priority"] !== null && !isIntInRange(src["priority"], 0, 100)) return { ok: false, reason: "priority must be an integer 0–100 or null" }; + rec.priority = src["priority"] as number | null; + } + for (const f of ["publishedAt", "since", "until"] as const) { + if (!(f in src)) continue; + if (!isIso8601(src[f])) return { ok: false, reason: `${f} must be ISO8601` }; + rec[f] = src[f]; + } + if ("versions" in src) { + const vs = src["versions"]; + if (!Array.isArray(vs) || vs.some((el) => typeof el !== "string")) return { ok: false, reason: "versions must be an array of matcher strings" }; + for (const el of vs as string[]) { + if (parseVersionMatcher(el) === null) return { ok: false, reason: `versions element not parseable: ${el}` }; + } + rec.versions = vs as string[]; + } + if ("percent" in src) { + if (src["percent"] !== null && !isIntInRange(src["percent"], 0, 100)) return { ok: false, reason: "percent must be an integer 0–100 or null" }; + rec.percent = src["percent"] as number | null; + } + return { ok: true, rec, droppedFields }; +} + +// ---- versions matcher (§4.1) --------------------------------------------- + +type VerT = [number, number, number]; +interface Constraint { op: ">" | ">=" | "<" | "<=" | "="; v: VerT } + +/** Numeric body of a version string — dirty/pre-release builds compare by + * their major.minor.patch body only (§4.1). */ +export function parseVersion(s: string): VerT | null { + const m = /^(\d+)\.(\d+)\.(\d+)/.exec(s.trim()); + return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null; +} + +function cmpVer(a: VerT, b: VerT): number { + for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1; + return 0; +} + +function holds(c: Constraint, v: VerT): boolean { + const d = cmpVer(v, c.v); + switch (c.op) { + case ">": return d > 0; + case ">=": return d >= 0; + case "<": return d < 0; + case "<=": return d <= 0; + default: return d === 0; + } +} + +function caretRange(tok: string): Constraint[] | null { + const v = parseVersion(tok.slice(1)); + if (!v) return null; + const upper: VerT = v[0] > 0 ? [v[0] + 1, 0, 0] : v[1] > 0 ? [0, v[1] + 1, 0] : [0, 0, v[2] + 1]; + return [{ op: ">=", v }, { op: "<", v: upper }]; +} + +function parseTokenList(tokens: string[]): Constraint[] | null { + const bare: VerT[] = []; + const cons: Constraint[] = []; + for (const tok of tokens) { + if (tok.startsWith("^")) { + const cr = caretRange(tok); + if (!cr) return null; + cons.push(...cr); + continue; + } + const m = /^(>=|<=|>|<|=)?(.*)$/.exec(tok)!; + const v = parseVersion(m[2]); + if (!v) return null; + if (m[1]) cons.push({ op: m[1] as Constraint["op"], v }); + else bare.push(v); + } + // One bare version is an exact pin; two bare versions inside brackets mean + // the inclusive range "[c d]" (§4.1 example); mixed lists are ambiguous → invalid. + if (bare.length === 1 && cons.length === 0) cons.push({ op: "=", v: bare[0] }); + else if (bare.length === 2 && cons.length === 0) cons.push({ op: ">=", v: bare[0] }, { op: "<=", v: bare[1] }); + else if (bare.length > 0) return null; + return cons; +} + +/** One matcher element → alternatives joined by OR (`||`); each alternative is + * an AND of constraints. Element forms: exact `0.1.212`, comparator list + * `>=a =a 0 ? alts : null; + } + const cons = parseTokenList(s.split(/\s+/).filter(Boolean)); + return cons ? [cons] : null; +} + +/** Elements AND together; empty/absent list matches every version. An + * unparseable LOCAL version hides any gated record (宁缺毋滥, §4.1). */ +export function versionMatches(elements: readonly string[], version: string | null): boolean { + if (elements.length === 0) return true; + const ver = version === null ? null : parseVersion(version); + if (!ver) return false; + return elements.every((el) => { + const alts = parseVersionMatcher(el); + return alts !== null && alts.some((alt) => alt.every((c) => holds(c, ver))); + }); +} + +// ---- percent bucketing (§4.1) --------------------------------------------- + +/** Deterministic per-install, per-notice bucket in [0,100): same install + id + * always lands in the same bucket; different ids use different salt so + * buckets don't correlate with business rollouts. */ +export function percentBucket(installId: string, id: string): number { + const h = createHash("sha256").update(`${installId}|${id}`).digest("hex"); + return parseInt(h.slice(0, 8), 16) % 100; +} + +export interface TargetingContext { + /** Running bili version string (null-safe: unparseable → gated records hide). */ + version: string | null; + /** Stable install identity; "" when it cannot be persisted (read-only state). */ + installId: string; + now: number; +} + +/** The three common targeting gates, AND-combined (§4.1). since is inclusive, + * until exclusive. A missing installId hides percent-gated records rather + * than flicker buckets across restarts. */ +export function passesTargeting(rec: Pick, ctx: TargetingContext): boolean { + if (rec.versions && rec.versions.length > 0 && !versionMatches(rec.versions, ctx.version)) return false; + if (typeof rec.percent === "number") { + if (!ctx.installId) return false; + if (percentBucket(ctx.installId, rec.id) >= rec.percent) return false; + } + if (rec.since && Number.isFinite(Date.parse(rec.since)) && Date.parse(rec.since) > ctx.now) return false; + if (rec.until && Number.isFinite(Date.parse(rec.until)) && ctx.now >= Date.parse(rec.until)) return false; + return true; +} + +// ---- dismissal hashing (§4.4) ---------------------------------------------- + +function canonValue(v: unknown): unknown { + if (Array.isArray(v)) return v.map(canonValue); + if (v && typeof v === "object") { + const out: Record = {}; + for (const k of Object.keys(v as Record).sort()) out[k] = canonValue((v as Record)[k]); + return out; + } + return v; +} + +/** Canonical form of a validated record — key-sorted JSON, stable across + * processes and independent of source-file key order. */ +export function normalizeRecord(rec: NoticeRecord): string { + return JSON.stringify(canonValue(rec)); +} + +export function noticeHash16(rec: NoticeRecord): string { + return createHash("sha1").update(normalizeRecord(rec)).digest("hex").slice(0, 16); +} + +/** Store key: `id@hash16`. Content edits change the hash → the banner re-shows + * once (persistent mode); always-mode records never reach the store. */ +export function dismissKeyOf(rec: NoticeRecord): string { + return `${rec.id}@${noticeHash16(rec)}`; +} + +// ---- P3 lane C: remote document (§五) -------------------------------------- + +/** Remote document format version; this build reads v1 only. Higher v → the + * WHOLE document is skipped (older builds must never partially parse a newer + * shape, §五.5). */ +export const REMOTE_DOC_VERSION = 1; +/** Size cap for the remote document body (§六.3): over cap = invalid doc. */ +export const REMOTE_DOC_CAP_BYTES = 512 * 1024; + +/** Pure gate for a fetched/published remote document: v header check + each + * entry through the shared whitelist validator. Invalid entries are skipped + * with a warning (reported by the CI gate), never fatal to the rest. */ +export function applyRemoteDoc(raw: unknown): { ok: true; entries: NoticeRecord[]; warnings: string[] } | { ok: false; reason: string } { + if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { ok: false, reason: "document is not an object" }; + const doc = raw as Record; + if (doc["v"] !== REMOTE_DOC_VERSION) return { ok: false, reason: `unsupported document version ${JSON.stringify(doc["v"])} (this build reads v${REMOTE_DOC_VERSION})` }; + const list = doc["entries"]; + if (!Array.isArray(list)) return { ok: false, reason: "entries missing or not an array" }; + const entries: NoticeRecord[] = []; + const warnings: string[] = []; + list.forEach((item, i) => { + const r = validateNoticeRecord(item); + if (!r.ok) { + warnings.push(`entry[${i}]: ${r.reason}`); + return; + } + if (r.droppedFields.length > 0) warnings.push(`entry[${i}]: dropped unknown field(s) ${r.droppedFields.join(", ")}`); + entries.push(r.rec); + }); + return { ok: true, entries, warnings }; +} + +export const PCK_NOTICE_ID = "pck-default-off"; +export const WM_FASTPATH_INTRO_ID = "wm-fastpath-intro"; + +/** Lane A: built-in declarations (bound to code behavior, review-gated here). */ +export const BUILTIN_NOTICES: readonly BuiltinNotice[] = [ + { + // #5079: prompt_cache.routing default flip (auto → disabled) upgrade notice. + // Explicit tone "warn": the derived tone for upgrade-advisory is info, but + // this banner has rendered as .banner.warn since #5079 (byte-stable). + id: PCK_NOTICE_ID, + kind: "upgrade-advisory", + tone: "warn", + title: { "zh-CN": "prompt_cache_key 自注入已默认关闭(升级提示)", en: "prompt_cache_key self-stamping is now off by default (upgrade notice)" }, + desc: { + "zh-CN": "本版本起 bili 不再自行向请求添加 OpenAI 的 prompt_cache_key 字段(此前默认开启)。如果你的上游是按该字段路由前缀缓存的中转站或号池(如 workbuddy panel/hub 等),请打开开关恢复注入,否则流量可能被随机路由、频繁未命中缓存。", + en: "Since this version bili no longer adds OpenAI's prompt_cache_key field to requests on its own (previously on by default). If your upstream routes prefix cache by this key (relays such as workbuddy panel/hub, account pools), turn the switch back on — otherwise traffic may route randomly and miss the prefix cache.", + }, + hint: { + "zh-CN": "开关在「配置」页快速配置里(promptCache.routing:disabled/auto/enabled),也可直接改 billion-context.json;直连官方 API 的用户可忽略此提示。", + en: "Switch: Configuration page → quick config (promptCache.routing: disabled/auto/enabled), or edit billion-context.json directly; direct official-API users can ignore this notice.", + }, + active: (ctx) => ctx.promptCacheRouting === "disabled", + }, + { + // #5403/#5469: watermark fastpath experimental-grey intro — every install + // sees it on first upgrade until closed or an explicit rollout override. + id: WM_FASTPATH_INTRO_ID, + kind: "new-feature", + tone: "ok", + title: { "zh-CN": "新功能提示:大上下文增量解析(增量压缩过渡功能 · 实验性)", en: "New: incremental parsing for large contexts (incremental-compression bridge feature, experimental)" }, + desc: { + "zh-CN": "长会话每轮都要把整个历史重新发给代理解析一遍,现在改为增量解析:只解析本轮新增的那部分,优化长会话的解析性能(发给模型的内容不变;有任何疑点,当轮自动回退老路径并重新对齐)。当前版本对约 5% 的安装灰度开启,属实验性功能。", + en: "Long conversations used to re-send their entire history for parsing on every turn. Now only the new part of each turn is parsed — faster parsing on long sessions (the request sent to the model is unchanged; any doubt falls back to the old path for that turn and re-aligns). This release rolls it out to roughly 5% of installs; it is marked experimental.", + }, + hint: { + "zh-CN": "开关在「配置」页快速配置(大上下文增量解析),也可在 billion-context.json 写 rollout.features.pluginFullResendWatermark: true/false,或设环境变量 BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0。", + en: "Switch: Configuration page → quick config (incremental parsing for large contexts), or write rollout.features.pluginFullResendWatermark: true/false in billion-context.json, or set environment variable BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0.", + }, + active: (ctx) => !ctx.wmOverridePresent, + }, +]; + +const dynamicIds = new Set(); + +/** Lanes B/C register their loaded ids so dismissal stays validated (#5548 §4.5). */ +export function registerDynamicNoticeIds(ids: Iterable): void { + for (const id of ids) dynamicIds.add(id); +} + +/** Every notice id a dismissal POST may name: built-ins + registered lanes B/C. */ +export function knownNoticeIds(): ReadonlySet { + const all = new Set(BUILTIN_NOTICES.map((b) => b.id)); + for (const id of dynamicIds) all.add(id); + return all; +} + +interface VisibleNoticesOptions { + dismissed: ReadonlySet; + instanceDismissed?: ReadonlySet; +} + +/** Lane-A visible set: active predicates AND dismiss mode, priority-sorted. + * Wire shape strips the active function — plain records only. */ +export function visibleBuiltInNotices(ctx: BuiltInContext, opts: VisibleNoticesOptions): NoticeRecord[] { + const live = BUILTIN_NOTICES.filter((b) => b.active(ctx) && noticeVisible(b, opts.dismissed, opts.instanceDismissed)); + return sortNotices(live).map(({ active: _active, ...wire }) => wire); +} diff --git a/src/pck-notice.ts b/src/pck-notice.ts index 55b5041e59..e1e0424871 100644 --- a/src/pck-notice.ts +++ b/src/pck-notice.ts @@ -1,63 +1,106 @@ -// #5079: one-time upgrade notice for the prompt_cache.routing default flip -// (auto → disabled). bili no longer writes its own prompt_cache_key by -// default; upstreams that ROUTE prefix cache by that field (body-keyed relays -// like the workbuddy panel, header-keyed ones like the workbuddy hub, and -// account-pool aggregators) lose their affinity signal unless the user turns -// the switch back on. The notice is shown until dismissed — once per proxy -// instance, persisted beside instances.json (same discipline as -// host-plugin-notice.ts: server-side, not per-browser, best-effort fs that -// never fails a request or a page load). It is only active while the EFFECTIVE -// routing is "disabled": users who already chose auto/enabled made the call -// themselves and are not nagged. - +// #5079/#5469 → #5548: shared dismissal store for upgrade notices. P1 moved the +// notice declarations into src/notices.ts (the registry); this module keeps only +// the persistence layer — the store file, the allowlist-checked writes, and the +// pck predicate (still consumed by acp-status.ts / server.ts startup log). +// #5548 P2: store keys upgrade from bare ids to `id@hash16(record)` (content +// edits re-show once), the array keeps insertion order under a 200-key FIFO cap, +// and instance-mode dismissals live in memory only. import fs from "node:fs"; import path from "node:path"; import { stateDir } from "./paths.js"; +import { BUILTIN_NOTICES, PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID, dismissKeyOf, knownNoticeIds, type NoticeRecord } from "./notices.js"; -export const PCK_NOTICE_ID = "pck-default-off"; -// #5403 watermark fastpath experimental-grey intro (owner ruling 2026-11-02): -// same one-time-per-instance store, its own id so dismissal stays independent. -export const WM_FASTPATH_INTRO_ID = "wm-fastpath-intro"; - -const UPGRADE_NOTICE_IDS: ReadonlySet = new Set([PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID]); +export { PCK_NOTICE_ID, WM_FASTPATH_INTRO_ID }; const DISMISS_FILE = "upgrade-notices.json"; +const MAX_STORED_KEYS = 200; // #5548 §4.4 FIFO cap function stateDirFor(env: NodeJS.ProcessEnv): string { const v = env.XDG_STATE_HOME; return v && v.length > 0 ? path.join(path.resolve(v), "billion-context") : stateDir(); } -export function dismissedUpgradeNotices(env: NodeJS.ProcessEnv = process.env): ReadonlySet { +export function dismissedUpgradeNotices(env: NodeJS.ProcessEnv = process.env): Set { try { const raw = fs.readFileSync(path.join(stateDirFor(env), DISMISS_FILE), "utf8"); const doc: unknown = JSON.parse(raw); - const arr = doc && typeof doc === "object" && Array.isArray((doc as { dismissed?: unknown })["dismissed"]) - ? ((doc as { dismissed: unknown[] })["dismissed"]) - : []; - return new Set(arr.filter((x): x is string => typeof x === "string")); + if (doc && typeof doc === "object" && Array.isArray((doc as { dismissed?: unknown }).dismissed)) { + return new Set((doc as { dismissed: unknown[] }).dismissed.filter((x): x is string => typeof x === "string")); + } } catch { - return new Set(); + // absent/unreadable/corrupt → empty set (first run or fresh profile) } + return new Set(); +} + +/** Ordered key list as persisted — insertion order IS the FIFO order. */ +function readStoreKeys(env: NodeJS.ProcessEnv): string[] { + return [...dismissedUpgradeNotices(env)]; +} + +function appendKey(key: string, env: NodeJS.ProcessEnv): void { + const keys = readStoreKeys(env); + if (!keys.includes(key)) keys.push(key); + if (keys.length > MAX_STORED_KEYS) keys.splice(0, keys.length - MAX_STORED_KEYS); + const dir = stateDirFor(env); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync(path.join(dir, DISMISS_FILE), JSON.stringify({ dismissed: keys }, null, 2) + "\n"); } -/** Idempotent. Returns false only for unknown notice ids. */ +/** Legacy entry point (#5079/#5469 suites + pre-P2 stores): writes the bare id + * key, which noticeVisible() still honors so an upgrade never re-shows an + * already-closed banner. New callers write id@hash16 keys via + * dismissPersistentNotice(). */ export function dismissUpgradeNotice(id: string, env: NodeJS.ProcessEnv = process.env): boolean { - if (!UPGRADE_NOTICE_IDS.has(id)) return false; - const set = new Set(dismissedUpgradeNotices(env)); - set.add(id); + if (!knownNoticeIds().has(id)) return false; + try { + appendKey(id, env); + } catch { + // best-effort persistence: nothing to report if the state dir is unwritable + } + return true; +} + +/** Persistent dismissal under the #5548 hash key (`id@hash16`); a content edit + * changes the hash and re-shows the banner once. */ +export function dismissPersistentNotice(key: string, env: NodeJS.ProcessEnv = process.env): boolean { + const at = key.indexOf("@"); + if (at <= 0) return false; + if (!knownNoticeIds().has(key.slice(0, at))) return false; try { - const dir = stateDirFor(env); - fs.mkdirSync(dir, { recursive: true }); - fs.writeFileSync(path.join(dir, DISMISS_FILE), JSON.stringify({ dismissed: [...set].sort() }, null, 2) + "\n"); + appendKey(key, env); } catch { - // best effort: dismissal intent still holds for this process's answers + // best-effort persistence: nothing to report if the state dir is unwritable } return true; } -/** The notice is visible while self-stamping is off and the user has not closed it. */ +// Instance-mode dismissals (§4.4): process memory only — they re-show on restart. +const instanceDismissed = new Set(); + +export function instanceDismissedNotices(): ReadonlySet { + return instanceDismissed; +} + +export function recordInstanceNoticeDismissal(id: string): void { + instanceDismissed.add(id); +} + +function builtinWireRecord(id: string): NoticeRecord | undefined { + const b = BUILTIN_NOTICES.find((x) => x.id === id); + if (!b) return undefined; + const { active: _active, ...wire } = b; + return wire; +} + +/** True when the prompt-cache routing default-flip notice should surface: + * routing is disabled and the user has not dismissed it (legacy bare-id key + * or the #5548 hash key). */ export function pckNoticeActive(routing: string, env: NodeJS.ProcessEnv = process.env): boolean { if (routing !== "disabled") return false; - return !dismissedUpgradeNotices(env).has(PCK_NOTICE_ID); + const store = dismissedUpgradeNotices(env); + if (store.has(PCK_NOTICE_ID)) return false; + const wire = builtinWireRecord(PCK_NOTICE_ID); + if (wire && store.has(dismissKeyOf(wire))) return false; + return true; } diff --git a/src/remote-announcements.ts b/src/remote-announcements.ts new file mode 100644 index 0000000000..17134eb5eb --- /dev/null +++ b/src/remote-announcements.ts @@ -0,0 +1,168 @@ +// #5548 P3 lane C: remote announcements from a single GitHub raw file on +// master (publish = git push, retract = delete entry + push). Mirrors the +// advisory watcher's shape — same cadence, fail-open, warnOnce logging — but +// is a pure read-only display feed: never blocks, installs, or restarts. +// A/B render first; lane C merges in whenever its entries arrive. +import fs from "node:fs"; +import path from "node:path"; +import { log as loggerLog, type Logger } from "./logger.js"; +import { cacheDir } from "./paths.js"; +import { CHECK_INTERVAL_MS, egressDispatcher } from "./update.js"; +import type { FetchOptions } from "./fetch-util.js"; +import { applyRemoteDoc, REMOTE_DOC_CAP_BYTES, REMOTE_DOC_VERSION, registerDynamicNoticeIds, type NoticeRecord } from "./notices.js"; + +export const DEFAULT_REMOTE_ANNOUNCEMENTS_URL = "https://raw.githubusercontent.com/ranxianglei/billion-context/master/announcements/remote.json"; +const FETCH_TIMEOUT_MS = 8000; +const SNAPSHOT_FILE = "announcements-remote-snapshot.json"; + +interface RemoteAnnouncementOptions { + /** Override the feed URL (env BILI_ANNOUNCEMENTS_URL wins over this). */ + url?: string; + resolveProxy?: (url: string) => string | undefined; + log?: Logger; + /** Test seam: shorten the fetch timeout for slow-response injection. */ + timeoutMs?: number; +} + +interface RemoteState { + entries: NoticeRecord[]; + lastError?: string; + lastCheckAt?: number; +} + +let state: RemoteState = { entries: [] }; +let timer: ReturnType | undefined; +let inFlight = false; + +export function remoteAnnouncementEntries(): readonly NoticeRecord[] { + return state.entries; +} + +/** Test seam: drop in-memory state (and warn-once keys) so each test starts + * from a clean slate — otherwise an earlier test's identical failure key + * swallows a later test's expected warning. */ +export function _resetRemoteAnnouncementsForTest(): void { + state = { entries: [] }; + warned.clear(); +} + +export function _stopRemoteAnnouncementWatcherForTest(): void { + if (timer) { + clearInterval(timer); + timer = undefined; + } +} + +/** BILI_ANNOUNCEMENTS_URL is the firewall-relay escape hatch (§五.3): + * path-relocation class env, owner-approved design point. */ +export function resolveRemoteUrl(envUrl: string | undefined, optsUrl: string | undefined): string { + const pick = (v: string | undefined): string | undefined => { + const t = v?.trim(); + return t && t.length > 0 ? t : undefined; + }; + return pick(envUrl) ?? pick(optsUrl) ?? DEFAULT_REMOTE_ANNOUNCEMENTS_URL; +} + +function snapshotFile(): string { + return path.join(cacheDir(), SNAPSHOT_FILE); +} + +/** Last-known-good snapshot from a previous session (§五.2): a failed fetch + * keeps showing this instead of nothing. Absent/corrupt → no lane C. */ +export function loadRemoteSnapshot(): NoticeRecord[] { + try { + const doc: unknown = JSON.parse(fs.readFileSync(snapshotFile(), "utf8")); + const res = applyRemoteDoc(doc); + if (!res.ok) return []; + registerDynamicNoticeIds(res.entries.map((r) => r.id)); + return res.entries; + } catch { + return []; + } +} + +function saveRemoteSnapshot(entries: readonly NoticeRecord[]): void { + try { + fs.mkdirSync(path.dirname(snapshotFile()), { recursive: true }); + fs.writeFileSync(snapshotFile(), JSON.stringify({ v: REMOTE_DOC_VERSION, entries }, null, 2) + "\n"); + } catch { + // cache dir unwritable: in-memory copy still serves this session + } +} + +const warned = new Set(); +function warnOnce(log: Logger, key: string, message: string): void { + if (warned.has(key)) return; + warned.add(key); + log("warn", message); +} + +/** One fetch cycle. Fail-open by design: any error keeps the previous + * entries (snapshot-seeded at startup), logs warnOnce, never throws. */ +export async function runRemoteCheck(opts: RemoteAnnouncementOptions = {}): Promise { + if (inFlight) return; + inFlight = true; + const log = opts.log ?? loggerLog; + try { + const url = resolveRemoteUrl(process.env.BILI_ANNOUNCEMENTS_URL, opts.url); + let body: string; + try { + const dispatcher = egressDispatcher({ resolveProxy: opts.resolveProxy }, url); + const init: FetchOptions = { + method: "GET", + headers: { Accept: "application/json" }, + signal: AbortSignal.timeout(opts.timeoutMs ?? FETCH_TIMEOUT_MS), + ...(dispatcher ? { dispatcher } : {}), + }; + const res = await fetch(url, init as RequestInit); + if (!res.ok) throw new Error(`remote announcements returned HTTP ${res.status}`); + body = await res.text(); + } catch (e) { + state.lastError = String(e); + warnOnce(log, `fetch:${String(e)}`, `[notices] remote check failed (${String(e)}) — continuing with last-known-good`); + return; + } + if (Buffer.byteLength(body, "utf8") > REMOTE_DOC_CAP_BYTES) { + state.lastError = `document exceeds ${REMOTE_DOC_CAP_BYTES} bytes`; + warnOnce(log, "size", `[notices] ignoring oversized remote document (>${REMOTE_DOC_CAP_BYTES} bytes)`); + return; + } + let doc: unknown; + try { + doc = JSON.parse(body); + } catch (e) { + state.lastError = String(e); + warnOnce(log, "parse", `[notices] ignoring malformed remote document (${String(e)})`); + return; + } + const res = applyRemoteDoc(doc); + if (!res.ok) { + state.lastError = res.reason; + warnOnce(log, `doc:${res.reason}`, `[notices] ignoring remote document: ${res.reason}`); + return; + } + for (const w of res.warnings) warnOnce(log, `entry:${w}`, `[notices] remote document: ${w}`); + state = { entries: res.entries, lastCheckAt: Date.now() }; + registerDynamicNoticeIds(res.entries.map((r) => r.id)); + saveRemoteSnapshot(res.entries); + } finally { + inFlight = false; + } +} + +/** Start the periodic feed: same cadence as the update check (§五.2), first + * fetch after a short startup delay like the advisory watcher, unref'd so it + * never holds the process open. */ +export function startRemoteAnnouncementWatcher(opts: RemoteAnnouncementOptions = {}): void { + if (timer) return; + const log = opts.log ?? loggerLog; + state.entries = loadRemoteSnapshot(); + log("info", `[notices] remote feed enabled (checking every ${CHECK_INTERVAL_MS / 1000 | 0}s, independent of auto-update)`); + setTimeout(() => { + void runRemoteCheck(opts); + }, 10_000); + timer = setInterval(() => { + void runRemoteCheck(opts); + }, CHECK_INTERVAL_MS); + timer.unref?.(); +} diff --git a/src/server/admin.ts b/src/server/admin.ts index da947bc792..07c530ccdb 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -23,7 +23,11 @@ import { getUnrecognizedPathStats } from "./observability.js"; import { getStore } from "../persist.js"; import { BodyTooLargeError, headerValue, readBody } from "../server.js"; import { dismissHostPlugin, visibleHostPluginNotices } from "../host-plugin-notice.js"; -import { dismissedUpgradeNotices, dismissUpgradeNotice, PCK_NOTICE_ID, pckNoticeActive, WM_FASTPATH_INTRO_ID } from "../pck-notice.js"; +import { dismissedUpgradeNotices, dismissPersistentNotice, instanceDismissedNotices, recordInstanceNoticeDismissal } from "../pck-notice.js"; +import { BUILTIN_NOTICES, dismissKeyOf, dismissModeOf, mergeNoticeLayers, noticeVisible, passesTargeting, registerDynamicNoticeIds, sortNotices, visibleBuiltInNotices, type NoticeRecord, type TargetingContext } from "../notices.js"; +import { installIdOf } from "../install-id.js"; +import { loadLocalAnnouncements } from "../local-announcements.js"; +import { remoteAnnouncementEntries } from "../remote-announcements.js"; import { featureOverrideAbsent } from "../rollout.js"; import { listSessions, memoryReport, peekSession, splitSessionWarnings, totalInFlight } from "../session.js"; import { BILI_TUNNEL_HEADER } from "../tunnel-guard.js"; @@ -438,8 +442,14 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv if (req.method === "POST" && req.url?.startsWith("/__bili/conflicts/clear")) return handleConflictsClear(req.url, res, log); // #2861: silence a known host-side plugin notice for this environment. if (req.method === "POST" && req.url === "/__bili/host-plugins/dismiss") return handleHostPluginDismiss(req, res, log); - // #5079: silence the prompt_cache.routing default-off upgrade notice. + // #5079: silence a known notice of the unified announcement surface. if (req.method === "POST" && req.url === "/__bili/notices/dismiss") return handleNoticeDismiss(req, res, log); + // #5548: unified announcement payload for non-overview consumers. + if (req.method === "GET" && req.url === "/__bili/notices") { + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify({ notices: collectVisibleNotices(opts) }, null, 2)); + return; + } // #3923/#3959: dismiss the surfaced split-brain notice (body {"sessionId": string}). if (req.method === "POST" && req.url === "/__bili/storage/split-brain/ack") return handleSplitBrainAck(req, res, log); if (req.method === "GET" && req.url === "/__bili/upstream") { @@ -1040,12 +1050,25 @@ async function handleNoticeDismiss(req: http.IncomingMessage, res: http.ServerRe res.end(JSON.stringify({ error: 'expected JSON body {"id": ""}' }, null, 2)); return; } - if (!dismissUpgradeNotice(id)) { + const rec = findNoticeRecord(id); + if (!rec) { res.writeHead(400, { "content-type": "application/json" }); res.end(JSON.stringify({ error: `unknown notice: ${id}` }, null, 2)); return; } - log("info", `[notices] notice ${id} dismissed via web UI`); + // #5548 §4.4 dismiss modes: always → success without writing; instance → + // process memory only; persistent → the id@hash16 store key. + const mode = dismissModeOf(rec); + if (mode === "always") { + log("info", `[notices] dismiss ignored for ${id} (always-shown)`); + } else if (mode === "instance") { + recordInstanceNoticeDismissal(id); + } else if (!dismissPersistentNotice(dismissKeyOf(rec))) { + res.writeHead(400, { "content-type": "application/json" }); + res.end(JSON.stringify({ error: `unknown notice: ${id}` }, null, 2)); + return; + } + log("info", `[notices] notice ${id} dismissed via web UI (${mode})`); res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify({ ok: true }, null, 2)); } @@ -1302,6 +1325,45 @@ function sendResignStatus(res: http.ServerResponse): void { }, null, 2)); } +// #5548 P2: unified announcement payload — lane A built-ins + lane B local JSON +// (B overrides A on id collision, §三), targeting gates (versions/percent/ +// since/until) applied to every source, priority-sorted server-side. The wm +// intro stays visible to EVERY install on its first upgrade until closed unless +// an explicit rollout override exists. +function collectVisibleNotices(opts: ProxyOptions): NoticeRecord[] { + const dismissed = dismissedUpgradeNotices(process.env); + const inst = instanceDismissedNotices(); + const tctx: TargetingContext = { version: VERSION, installId: installIdOf(process.env), now: Date.now() }; + const local = loadLocalAnnouncements(process.env).records; + const remote = [...remoteAnnouncementEntries()]; + registerDynamicNoticeIds(local.map((r) => r.id)); + registerDynamicNoticeIds(remote.map((r) => r.id)); + const merged = mergeNoticeLayers([ + local.filter((r) => passesTargeting(r, tctx) && noticeVisible(r, dismissed, inst)), + remote.filter((r) => passesTargeting(r, tctx) && noticeVisible(r, dismissed, inst)), + visibleBuiltInNotices( + { + promptCacheRouting: effectivePromptCacheRouting(opts.promptCache), + wmOverridePresent: !featureOverrideAbsent("pluginFullResendWatermark", loadConfigFile().rollout), + }, + { dismissed, instanceDismissed: inst }, + ), + ]); + return sortNotices(merged).filter((r) => passesTargeting(r, tctx)); +} + +/** Dismissal lookup by id — local lane first (B > C > A), then built-ins. */ +function findNoticeRecord(id: string): NoticeRecord | undefined { + const local = loadLocalAnnouncements(process.env).records.find((r) => r.id === id); + if (local) return local; + const remote = remoteAnnouncementEntries().find((r) => r.id === id); + if (remote) return remote; + const b = BUILTIN_NOTICES.find((x) => x.id === id); + if (!b) return undefined; + const { active: _active, ...wire } = b; + return wire; +} + async function sendOverview(res: http.ServerResponse, opts: ProxyOptions, laneHost?: string): Promise { let diskVersion: string | undefined; let stale = false; @@ -1338,16 +1400,7 @@ async function sendOverview(res: http.ServerResponse, opts: ProxyOptions, laneHo updatePolicy: updatePolicyPayload(), pluginAdvisories: detectCostAdvisories(process.env), hostPluginNotices: visibleHostPluginNotices(process.env), - pckNotice: { id: PCK_NOTICE_ID, active: pckNoticeActive(effectivePromptCacheRouting(opts.promptCache)) }, - wmNotice: { - id: WM_FASTPATH_INTRO_ID, - // #5403 experimental-grey intro: visible to EVERY install on its - // first upgrade to this build until closed — unless the user - // already wrote an explicit rollout override (they made the call). - active: - !dismissedUpgradeNotices(process.env).has(WM_FASTPATH_INTRO_ID) && - featureOverrideAbsent("pluginFullResendWatermark", loadConfigFile().rollout), - }, + notices: collectVisibleNotices(opts), inFlight: totalInFlight(), blindTunnels: getBlindTunnelStats(), conflicts: summarizeConflicts(listSessions()), diff --git a/src/web/client.ts b/src/web/client.ts index e3bc1d4f70..1868c497b2 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -419,28 +419,87 @@ export const WEB_CLIENT = `(function () { return html; } window.bili_hostPluginBanner = bili_hostPluginBanner; - // #5079: one-time-per-instance upgrade notice — prompt_cache_key - // self-stamping is off by default now. Server decides active (effective - // routing "disabled" && not dismissed); pure builder, same test-seam - // convention as the banners above. - function bili_pckNoticeBanner(s) { - let html = '"; - html += '
' + escapeHtml(s.desc) + '
"; - html += '
' + escapeHtml(s.hint) + "
"; - return html; + // #5548: unified announcement surface (design v2 lane A). The server ships + // priority-sorted visible records whose copy rides the record (string or + // locale object, fallback locale → zh-CN → en → any); elements are built + // with textContent only — zero innerHTML with external data (design §4.2). + function bili_noticeText(v, lang) { + if (typeof v === "string") return v; + if (v && typeof v === "object") { + for (const k of [lang, "zh-CN", "en"]) if (typeof v[k] === "string" && v[k]) return v[k]; + for (const k of Object.keys(v)) if (typeof v[k] === "string" && v[k]) return v[k]; + } + return ""; } - window.bili_pckNoticeBanner = bili_pckNoticeBanner; - // #5403: one-time-per-instance intro for the watermark fastpath - // experimental grey rollout — same server-side dismissal convention as - // above (own notice id, visible on every install until closed or an - // explicit rollout override exists); pure builder + same test seam. - function bili_wmNoticeBanner(s) { - let html = '"; - html += '
' + escapeHtml(s.desc) + '
"; - html += '
' + escapeHtml(s.hint) + "
"; - return html; + window.bili_noticeText = bili_noticeText; + const NOTICE_MAX_HEADER_BANNERS = 5; + function bili_buildNoticeEl(n) { + const el = document.createElement("div"); + el.className = "banner show " + String(n.tone || "info"); + const title = document.createElement("div"); + title.className = "banner-title"; + title.textContent = bili_noticeText(n.title, locale); + el.appendChild(title); + const row = document.createElement("div"); + row.className = "alert-row"; + const span = document.createElement("span"); + span.textContent = bili_noticeText(n.desc, locale); + row.appendChild(span); + if (n.ctaUrl && n.ctaLabel) { + const link = document.createElement("a"); + link.className = "mono"; + link.href = String(n.ctaUrl); + link.target = "_blank"; + link.rel = "noopener"; + link.textContent = bili_noticeText(n.ctaLabel, locale); + row.appendChild(link); + } + if (n.dismiss !== "always") { + const btn = document.createElement("button"); + btn.className = "btn sm notice-dismiss"; + btn.textContent = t("notices.dismiss_btn"); + btn.addEventListener("click", async () => { + busy(btn, true); + try { + await json(API_ROOT + "/notices/dismiss", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: typeof n.id === "string" ? n.id : "" }) }); + toast(t("notices.dismissed"), "ok"); + await loadOverview(true); + } catch (e) { + toast(e.message, "err"); + } finally { + busy(btn, false); + } + }); + row.appendChild(btn); + } + el.appendChild(row); + if (n.hint !== undefined) { + const hint = document.createElement("div"); + hint.className = "dim small"; + hint.style.marginTop = "6px"; + hint.textContent = bili_noticeText(n.hint, locale); + el.appendChild(hint); + } + return el; + } + window.bili_buildNoticeEl = bili_buildNoticeEl; + function renderAnnouncementBanners(list) { + const host = $("notices-banners"); + if (!host) return; + while (host.firstChild) host.removeChild(host.firstChild); + const card = $("notice-list-card"); + const ovf = $("notice-list"); + if (ovf) while (ovf.firstChild) ovf.removeChild(ovf.firstChild); + if (card) card.hidden = true; + if (!Array.isArray(list) || !list.length) return; + const head = list.slice(0, NOTICE_MAX_HEADER_BANNERS); + for (const n of head) host.appendChild(bili_buildNoticeEl(n)); + const rest = list.slice(NOTICE_MAX_HEADER_BANNERS); + if (rest.length && card && ovf) { + card.hidden = false; + for (const n of rest) ovf.appendChild(bili_buildNoticeEl(n)); + } } - window.bili_wmNoticeBanner = bili_wmNoticeBanner; function $(id) { return document.getElementById(id); } function toast(message, kind) { const host = $("toast-host"); @@ -1583,65 +1642,13 @@ function changelogCatOf(rawLine) { hb.innerHTML = ""; } } - // #5079: prompt_cache_key default-off upgrade notice — dismissal is - // server-side (POST /__bili/notices/dismiss) so one close silences - // every browser; the banner re-renders from the refetched overview. - const nb = $("pck-notice-banner"); - if (nb) { - const pn = d.pckNotice && typeof d.pckNotice === "object" ? d.pckNotice : null; - if (pn && pn.active === true) { - nb.hidden = false; - nb.classList.add("show"); - nb.innerHTML = bili_pckNoticeBanner({ on: t("pckoff.on"), desc: t("pckoff.desc"), hint: t("pckoff.hint"), dismiss: t("pckoff.dismiss_btn") }); - for (const btn of Array.from(nb.querySelectorAll(".pck-notice-dismiss"))) { - btn.addEventListener("click", async () => { - busy(btn, true); - try { - await json(API_ROOT + "/notices/dismiss", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: typeof pn.id === "string" ? pn.id : "" }) }); - toast(t("pckoff.dismissed"), "ok"); - await loadOverview(true); - } catch (e) { - toast(e.message, "err"); - } finally { - busy(btn, false); - } - }); - } - } else { - nb.hidden = true; - nb.classList.remove("show"); - nb.innerHTML = ""; - } - } - // #5403: watermark fastpath experimental-grey intro — all installs see - // it on first upgrade until closed (server-side, like #5079 above). - const wnb = $("wm-notice-banner"); - if (wnb) { - const wn = d.wmNotice && typeof d.wmNotice === "object" ? d.wmNotice : null; - if (wn && wn.active === true) { - wnb.hidden = false; - wnb.classList.add("show"); - wnb.innerHTML = bili_wmNoticeBanner({ on: t("wmfast.on"), desc: t("wmfast.desc"), hint: t("wmfast.hint"), dismiss: t("wmfast.dismiss_btn") }); - for (const btn of Array.from(wnb.querySelectorAll(".wm-notice-dismiss"))) { - btn.addEventListener("click", async () => { - busy(btn, true); - try { - await json(API_ROOT + "/notices/dismiss", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: typeof wn.id === "string" ? wn.id : "" }) }); - toast(t("wmfast.dismissed"), "ok"); - await loadOverview(true); - } catch (e) { - toast(e.message, "err"); - } finally { - busy(btn, false); - } - }); - } - } else { - wnb.hidden = true; - wnb.classList.remove("show"); - wnb.innerHTML = ""; - } - } + // #5548: unified announcement surface — one loop over the server's + // visible records (lane A built-ins today; B/C merge in later phases). + // Dismissal stays server-side (POST /__bili/notices/dismiss) so one + // close silences every browser; banners re-render from the refetched + // overview. More than NOTICE_MAX_HEADER_BANNERS overflow into the + // overview's 公告列表 card. + renderAnnouncementBanners(Array.isArray(d.notices) ? d.notices : []); // #1682: global upstream-connection alert banner — visible on every view, // one row per active alert (no stacking), dismiss per alert instance. latestAlerts = Array.isArray(d.alerts) ? d.alerts : []; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 36cc98dfc2..7e1807eda1 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -284,16 +284,10 @@ export const MESSAGES: Record> = { "pck.on": "缓存路由键(prompt_cache_key)已停用", "pck.sessions": "受影响会话:{ids}", "pck.hint": "该上游拒绝携带 prompt_cache_key 的请求(带键 400、去键成功,A/B 实证),bili 重启前不再向其发送该键。若这是你的中转/号池,相关会话的前缀缓存亲和可能下降。", - "pckoff.on": "prompt_cache_key 自注入已默认关闭(升级提示)", - "pckoff.desc": "本版本起 bili 不再自行向请求添加 OpenAI 的 prompt_cache_key 字段(此前默认开启)。如果你的上游是按该字段路由前缀缓存的中转站或号池(如 workbuddy panel/hub 等),请打开开关恢复注入,否则流量可能被随机路由、频繁未命中缓存。", - "pckoff.hint": "开关在「配置」页快速配置里(promptCache.routing:disabled/auto/enabled),也可直接改 billion-context.json;直连官方 API 的用户可忽略此提示。", - "pckoff.dismiss_btn": "我知道了", - "pckoff.dismissed": "已关闭该提示", - "wmfast.on": "新功能提示:大上下文增量解析(增量压缩过渡功能 · 实验性)", - "wmfast.desc": "长会话每轮都要把整个历史重新发给代理解析一遍,现在改为增量解析:只解析本轮新增的那部分,优化长会话的解析性能(发给模型的内容不变;有任何疑点,当轮自动回退老路径并重新对齐)。当前版本对约 5% 的安装灰度开启,属实验性功能。", - "wmfast.hint": "开关在「配置」页快速配置(大上下文增量解析),也可在 billion-context.json 写 rollout.features.pluginFullResendWatermark: true/false,或设环境变量 BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0。", - "wmfast.dismiss_btn": "我知道了", - "wmfast.dismissed": "已关闭该提示", + // #5548: banner copy now rides the notice records (src/notices.ts); only action words stay here. + "notices.dismiss_btn": "我知道了", + "notices.dismissed": "已关闭该提示", + "notices.list_title": "公告列表", "ses.title": "会话", "ses.sub": "覆盖内存与磁盘的全部会话 · 点击行查看详情、轨迹与交接文档", "ses.search_ph": "搜索标题、标签或 id…", @@ -1018,16 +1012,10 @@ export const MESSAGES: Record> = { "pck.on": "Cache routing key (prompt_cache_key) withheld", "pck.sessions": "Affected session(s): {ids}", "pck.hint": "This upstream rejected requests carrying prompt_cache_key (400 with the key, accepted without it), so bili withholds the key there until restart. If this is your relay/account pool, prefix-cache affinity may degrade for those sessions.", - "pckoff.on": "prompt_cache_key self-stamping is now off by default (upgrade notice)", - "pckoff.desc": "Since this version bili no longer adds OpenAI's prompt_cache_key field to requests on its own (previously on by default). If your upstream routes prefix cache by this key (relays such as workbuddy panel/hub, account pools), turn the switch back on — otherwise traffic may route randomly and miss the prefix cache.", - "pckoff.hint": "Switch: Configuration page → quick config (promptCache.routing: disabled/auto/enabled), or edit billion-context.json directly; direct official-API users can ignore this notice.", - "pckoff.dismiss_btn": "Got it", - "pckoff.dismissed": "Notice dismissed", - "wmfast.on": "New: incremental parsing for large contexts (incremental-compression bridge feature, experimental)", - "wmfast.desc": "Long conversations used to re-send their entire history for parsing on every turn. Now only the new part of each turn is parsed — faster parsing on long sessions (the request sent to the model is unchanged; any doubt falls back to the old path for that turn and re-aligns). This release rolls it out to roughly 5% of installs; it is marked experimental.", - "wmfast.hint": "Switch: Configuration page → quick config (incremental parsing for large contexts), or write rollout.features.pluginFullResendWatermark: true/false in billion-context.json, or set BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1/0.", - "wmfast.dismiss_btn": "Got it", - "wmfast.dismissed": "Notice dismissed", + // #5548: banner copy now rides the notice records (src/notices.ts); only action words stay here. + "notices.dismiss_btn": "Got it", + "notices.dismissed": "Notice dismissed", + "notices.list_title": "Announcements", "ses.title": "Sessions", "ses.sub": "Every session across memory and disk — click a row for details, trajectory & handoff document", "ses.search_ph": "Search title, label or id…", diff --git a/src/web/page.ts b/src/web/page.ts index 52439b4fb6..9f53d671ea 100644 --- a/src/web/page.ts +++ b/src/web/page.ts @@ -40,8 +40,7 @@ export function renderPage(origin: string, version: string, embed = false, theme - - +
@@ -72,6 +71,7 @@ export function renderPage(origin: string, version: string, embed = false, theme
${zh("ov.recent")}${zh("ov.view_all")}
${zh("ses.th_title")}${zh("ses.th_client")}${zh("ses.th_proto")}${zh("ses.th_upstream")}${zh("ses.th_reqs")}${zh("ses.th_ctx")}${zh("ses.th_input")}${zh("ses.th_saved")}${zh("ses.th_hit")}${zh("ses.th_switches")}${zh("ses.th_folds")}${zh("ses.th_blocks")}${zh("ses.th_seen")}
+