Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/announcements-gate.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,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. |
Expand Down
1 change: 1 addition & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,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 补丁的开关。 |
Expand Down
1 change: 1 addition & 0 deletions LIFECYCLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 安全边界) |
Expand Down
4 changes: 4 additions & 0 deletions announcements/remote.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"v": 1,
"entries": []
}
32 changes: 32 additions & 0 deletions scripts/validate-remote-announcements.ts
Original file line number Diff line number Diff line change
@@ -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})`);
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -900,4 +901,10 @@ export async function main(): Promise<void> {
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),
});
}
38 changes: 38 additions & 0 deletions src/install-id.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
75 changes: 75 additions & 0 deletions src/local-announcements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// #5548 P2 lane B: local announcements — one validated record per *.json file
// under <configDir>/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;
}
Loading
Loading