Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/acp-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,8 @@ export function handleAcpStatus(args: Record<string, unknown>, ctx: AcpStatusCtx
for (const e of upd.span) {
lines.push(` · ${e.version} [${e.tier}] ${e.summary}`);
}
if (!upd.pendingRestart) {
lines.push(` Update with: npm install -g billion-context@${upd.span[upd.span.length - 1]?.version ?? "latest"}`);
}
// No install command on purpose: hosts differ (npm -g / opencode
// plugin / dsh / pi) — naming the version is host-neutral advice.
lines.push("Live state: the update field of GET /__bili/status.");
extra.push(...lines);
}
Expand Down
18 changes: 17 additions & 1 deletion src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getBlindTunnelStats } from "../mitm.js";
import { handlePluginCompact, handlePluginFork, handlePluginManifest, handlePluginRegister, handlePluginRuntimeInfo, handlePluginSessionName, handlePluginSnapshot, handlePluginStatus, handlePluginTool } from "../plugin.js";
import { parseAgentProviderReport, recordAgentProviders, agentProviderRecipes, sanitizeAgentProviderField } from "../agent-providers.js";
import { defaultLogFile } from "../paths.js";
import { getUpdateVisibility, updateBannerPayload } from "../update-notes.js";
import { getUnrecognizedPathStats } from "./observability.js";
import { getStore } from "../persist.js";
import { BodyTooLargeError, headerValue, readBody, selfAdminProbePath } from "../server.js";
Expand Down Expand Up @@ -752,6 +753,20 @@ function currentAdvisoryPayload() {
/** Stale-install state for the web UI badge (#811): whether the on-disk
* version is newer than the running process, plus the opt-in flag state and
* the live in-flight request count. */
// #1870/#1977 web surface: the /acp panel and acp_status carry the critical
// update payload, but the web UI had NO update notice at all — the browser only
// had the disk-vs-running stale banner. Shared single source (the #2152
// advisory-parity lesson): one helper feeds BOTH /__bili/status and
// /__bili/overview, so the web banner's data source can never drift from the
// panel's. STRUCTURED, not a baked English sentence: the client composes the
// sentence per locale (zh/en) from kind/version/summary, and "available"
// carries the MINIMUM fixed version so every locale can say "v{version} 或更新版本 /
// v{version} or newer". null when the span is invisible (routine/recommended-
// only or clean install — silent by default, #1977).
function updateReadyPayload(): { kind: "available" | "ready"; version: string; summary: string } | null {
return updateBannerPayload(getUpdateVisibility(VERSION));
}

async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise<void> {
let diskVersion: string | undefined;
let stale = false;
Expand All @@ -768,7 +783,7 @@ async function sendStatus(res: http.ServerResponse, opts: ProxyOptions): Promise
loggerLog("warn", `split-session canary (#2170): conversation ${w.base} has live traffic under multiple session keys (design persona forks are excluded): ${w.sessions.map((s) => `${s.id} (requests=${s.requests})`).join("; ")}. For a non-persona host this is the #2165 failure shape (stolen anchor / never-compressing split) — investigate if unexpected.`);
}
}
res.end(JSON.stringify({ version: VERSION, commit: BUILD_COMMIT, diskVersion, stale, autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2));
res.end(JSON.stringify({ version: VERSION, commit: BUILD_COMMIT, diskVersion, stale, updateReady: updateReadyPayload(), autoRestartOnUpdate: opts.autoRestartOnUpdate, advisory: currentAdvisoryPayload(), pluginAdvisories: detectCostAdvisories(process.env), inFlight: totalInFlight(), splitSessions: splitWarnings, conflicts: summarizeConflicts(listSessions()) }, null, 2));
}

// #2090 plan A — read-only view backing the web UI's "Signed upstreams" card:
Expand Down Expand Up @@ -816,6 +831,7 @@ async function sendOverview(res: http.ServerResponse, opts: ProxyOptions): Promi
commit: BUILD_COMMIT,
diskVersion,
stale,
updateReady: updateReadyPayload(),
autoRestartOnUpdate: opts.autoRestartOnUpdate,
advisory: currentAdvisoryPayload(),
pluginAdvisories: detectCostAdvisories(process.env),
Expand Down
41 changes: 34 additions & 7 deletions src/update-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,14 @@ export function getUpdateVisibility(runningVersion: string): UpdateVisibility &
};
}

/** Shared wording for the /acp panel line — one line, stripper-safe slot is
* the caller's job. Kept compact: the panel is small, and acp_status carries
* the full span. Only ever rendered for critical spans (#1977); the final
* fallback branch exists for totality (invisible states never reach the
* surfaces, but the function must stay total for future callers). */
/** Shared wording for the /acp panel line, acp_status and the web update
* banner — one line, stripper-safe slot is the caller's job. Kept compact:
* the panel is small, and acp_status carries the full span. Only ever
* rendered for critical spans (#1977); the final fallback branch exists for
* totality (invisible states never reach the surfaces, but the function
* must stay total for future callers). NEVER prescribes an install command:
* hosts differ (npm -g / opencode plugin / dsh / pi) and the wrong hint is
* worse than none — name the version, let the client's own docs say how. */
export function describeUpdateReady(v: UpdateVisibility): string {
const latest = v.span.length > 0 ? v.span[v.span.length - 1].version : v.diskVersion;
const topCritical = v.span.find((e) => e.tier === "critical");
Expand All @@ -194,9 +197,33 @@ export function describeUpdateReady(v: UpdateVisibility): string {
return `Critical update ready: ${latest} — restart to finish.${notable}`;
}
if (topCritical && latest !== undefined) {
return `Critical update available: ${latest} — ${topCritical.summary} (npm install -g billion-context@${latest})`;
// ≥ the MINIMUM version carrying the fix (topCritical = first critical
// in the ascending span): any version at-or-above it is safe, so the
// line must read "≥ X", not "X" — pinning exactly X would be wrong
// advice for hosts whose installer grabbed a newer release.
return `Critical update available: ≥ ${topCritical.version} — ${topCritical.summary}`;
}
return `Update available: ${latest ?? "newer version"} — npm install -g billion-context@${latest ?? "latest"}`;
return `Update available: ${latest ?? "newer version"}.`;
}

/** Localizable wire payload for the web update banner (#1870 web surface):
* the SERVER must not bake an English sentence — the UI ships zh + en, so
* it sends kind/version/summary and lets i18n compose the sentence
* ("upgrade to v{version} or newer", separately translated per locale).
* available → version = the MINIMUM version carrying the critical fix
* (first critical in the ascending span; anything ≥ it is safe).
* ready → version = the on-disk version a restart delivers.
* null when the span is invisible (#1977: routine/recommended stay silent). */
export function updateBannerPayload(v: UpdateVisibility & { visible: boolean }): { kind: "available" | "ready"; version: string; summary: string } | null {
if (!v.visible) return null;
const criticals = v.span.filter((e) => e.tier === "critical");
const first = criticals[0];
const newest = criticals[criticals.length - 1] ?? first;
if (first === undefined || newest === undefined) return null; // defensive: visible implies a critical, but stay total
if (v.pendingRestart && v.diskVersion !== undefined) {
return { kind: "ready", version: v.diskVersion, summary: newest.summary };
}
return { kind: "available", version: first.version, summary: first.summary };
}

function throttleFile(): string {
Expand Down
22 changes: 22 additions & 0 deletions src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,28 @@ export const WEB_CLIENT = `(function () {
}
}
function renderBanners(d) {
// #1870 web surface: critical update notice (#1977 — only critical
// spans ever reach here; the server sends null otherwise). Kept ABOVE
// the stale banner: it carries the release context (version + summary),
// while stale-banner stays the generic disk-vs-running restart cue.
const ub = $("update-banner");
if (ub) {
const u = d.updateReady;
if (u && typeof u === "object" && typeof u.version === "string") {
// compose per locale from kind/version/summary — "available"
// carries the MINIMUM fixed version, so each locale can say
// "v{version} 或更新版本" / "v{version} or newer" separately.
const vars = { version: u.version, summary: u.summary || "" };
const line = u.kind === "ready" ? t("sys.update_ready", vars) : t("sys.update_available", vars);
ub.hidden = false;
ub.classList.add("show");
ub.innerHTML = "<strong>" + t("sys.update") + "</strong> " + escapeHtml(line);
} else {
ub.hidden = true;
ub.classList.remove("show");
ub.innerHTML = "";
}
}
const stale = $("stale-banner");
if (d.stale) {
stale.hidden = false;
Expand Down
6 changes: 6 additions & 0 deletions src/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"sys.disk_version": "磁盘版本",
"sys.inflight": "进行中请求",
"sys.blind_tunnels": "MITM 盲隧道(CONNECT 后无 TLS)",
"sys.update": "升级提醒:",
"sys.update_available": "发现 critical 修复,请升级到 v{version} 或更新版本 — {summary}",
"sys.update_ready": "critical 修复已就绪 v{version} — 重启 bili 即可生效",
"sys.stale": "磁盘已有新版本 v{disk} —— 重启 bili 生效(当前运行 v{running})",
"sys.stale_auto": "自动重启已启用,空闲时自动切换",
"sys.stale_manual": "自动重启未启用(需要 --auto-restart-on-update)",
Expand Down Expand Up @@ -549,6 +552,9 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"sys.disk_version": "On-disk version",
"sys.inflight": "In-flight requests",
"sys.blind_tunnels": "MITM blind tunnels (CONNECT without TLS)",
"sys.update": "Update notice:",
"sys.update_available": "critical fix available — upgrade to v{version} or newer: {summary}",
"sys.update_ready": "critical fix ready (v{version}) — restart bili to apply",
"sys.stale": "Newer version v{disk} on disk — restart bili to apply (running v{running})",
"sys.stale_auto": "Auto-restart enabled — switches automatically when idle",
"sys.stale_manual": "Auto-restart not enabled (needs --auto-restart-on-update)",
Expand Down
1 change: 1 addition & 0 deletions src/web/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function renderPage(origin: string, version: string, embed = false, theme
return `<!doctype html><html lang="zh-CN"${theme ? ` data-theme="${theme}"` : ""}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>billion-context</title><style>${WEB_STYLES}</style></head><body${embed ? ' class="embed"' : ""}>
<header class="topbar"><div class="brand"><span class="logo">∞</span>billion-context<span class="ver">v${version}</span></div><nav class="nav"><a href="#/overview" data-nav="overview" class="active" data-i18n="nav.overview">${zh("nav.overview")}</a><a href="#/sessions" data-nav="sessions" data-i18n="nav.sessions">${zh("nav.sessions")}</a><a href="#/config" data-nav="config" data-i18n="nav.config">${zh("nav.config")}</a><a href="#/connect" data-nav="connect" data-i18n="nav.connect">${zh("nav.connect")}</a><a href="#/logs" data-nav="logs" data-i18n="nav.logs">${zh("nav.logs")}</a></nav><div class="actions"><a class="fork-link" href="https://github.com/ranxianglei/billion-context" target="_blank" rel="noopener" data-i18n="fork.label">${zh("fork.label")}</a><button id="language-toggle" class="lang-btn">English</button></div></header>
<div id="passthrough-banner" class="banner warn" hidden></div>
<div id="update-banner" class="banner warn" hidden></div>
<div id="stale-banner" class="banner warn" hidden></div>
<div id="conflicts-banner" class="banner warn" hidden></div>
<div id="advisory-banner" class="banner warn" hidden></div>
Expand Down
18 changes: 13 additions & 5 deletions tests/update-notes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
spanNotes,
getUpdateVisibility,
describeUpdateReady,
updateBannerPayload,
type ReleaseNoteEntry,
} from "../src/update-notes.ts";
import { VERSION } from "../src/version.ts";
Expand Down Expand Up @@ -152,11 +153,17 @@ test("#1977 describeUpdateReady: critical wording + byte-stability", () => {
assert.ok(line.startsWith("Critical update ready: 0.1.181 — restart to finish."), `pending-restart wording (got: ${line})`);
assert.ok(line.includes("#1844"), "top critical summary carried");
assert.equal(line, describeUpdateReady(getUpdateVisibility("0.1.179")), "byte-stable for identical state");
assert.deepEqual(updateBannerPayload(pending), { kind: "ready", version: "0.1.181", summary: "OpenCode WebSocket traffic intercepted again (#1844)" }, "wire payload (ready): names the disk version, newest critical summary");

_setReleaseNotesStateForTest({ entries: ENTRIES }); // no disk info
const rec = describeUpdateReady(getUpdateVisibility("0.1.179"));
assert.ok(rec.startsWith("Critical update available: 0.1.181 —"), `critical wording (got: ${rec})`);
assert.ok(rec.includes("npm install -g billion-context@0.1.181"), "manual command when restart cannot finish it");
const recVis = getUpdateVisibility("0.1.179");
const rec = describeUpdateReady(recVis);
assert.ok(rec.startsWith("Critical update available: ≥ 0.1.180 —"), `critical wording names the MINIMUM fixed version (got: ${rec})`);
assert.ok(!rec.includes("npm install"), "no install command — hosts differ (npm -g / opencode / dsh / pi)");
// span = [0.1.180 critical, 0.1.181 routine] ascending: the payload must
// carry 0.1.180 (the minimum version WITH the fix), not 0.1.181 — the
// locales render "v{version} 或更新版本 / v{version} or newer" from it.
assert.deepEqual(updateBannerPayload(recVis), { kind: "available", version: "0.1.180", summary: "OpenCode WebSocket traffic intercepted again (#1844)" }, "wire payload (available): minimum fixed version, never the routine tail");

// Span with NO critical entry + no pending restart = invisible; the
// routine-only branch exists for panel completeness only.
Expand Down Expand Up @@ -242,11 +249,12 @@ test("#1977 acp_status: CRITICAL UPDATE READY section lists the span; clean + no
assert.ok(out.text.includes(`· ${NEXT2} [routine] docs and log polish`), "span renders up to the disk version the restart will finish");
assert.ok(out.text.includes("the update field of GET /__bili/status"), "points at the live-state field");

// No disk info (auto-update off): AVAILABLE wording + manual command.
// No disk info (auto-update off): AVAILABLE wording — and NO install
// command anywhere (hosts differ: npm -g / opencode / dsh / pi).
_setReleaseNotesStateForTest({ entries: SURFACE_ENTRIES });
const avail = handleAcpStatus({}, ctx);
assert.ok(avail.text.includes("CRITICAL UPDATE AVAILABLE (instance-level):"), "available headline when nothing is pending");
assert.ok(avail.text.includes(`npm install -g billion-context@${NEXT2}`), "manual update command present");
assert.ok(!avail.text.includes("npm install"), "no npm install prescription (host-neutral wording)");
assert.ok(!avail.text.includes("UPDATE READY"), "ready wording reserved for the pending-restart case");
} finally {
_resetReleaseNotesWatcherForTest();
Expand Down
Loading
Loading