From 9e4f569287acc24c6e199043b6ac804427b18d74 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 17:04:10 +0800 Subject: [PATCH 1/6] feat: install any published version, pin for a duration, tag-following auto-upgrade (#6804) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bili update installs any published version (release or prerelease) - bili pin [duration] pins the installed version (1h/12h/1d/7d/forever) - bili unpin lifts the pin early - Auto-upgrade follows the tag channel only: a prerelease/temp build on the release channel (tag "latest") is never auto-swept forward to a release - Any pinned version is check-only: the updater reports new versions but never auto-installs; explicit bili update breaks through the pin - Web panel Updates tab gains a free-text version field and pin controls (duration picker + pin/unpin buttons) - Pin state is machine-level runtime state at ~/.cache/billion-context/.pin.json (no new config key — Configuration Surface Discipline) - The #1481 advisory force-install lane still overrides a local pin Closes #6804 --- src/cli.ts | 89 +++++++++++++++- src/server/admin.ts | 45 +++++++- src/server/update-actions.ts | 28 +++++ src/update-pin.ts | 109 +++++++++++++++++++ src/update.ts | 34 ++++++ src/web/client.ts | 62 +++++++++++ src/web/i18n.ts | 16 +++ src/web/page.ts | 16 +++ tests/update-pin.test.ts | 197 +++++++++++++++++++++++++++++++++++ 9 files changed, 590 insertions(+), 6 deletions(-) create mode 100644 src/update-pin.ts create mode 100644 tests/update-pin.test.ts diff --git a/src/cli.ts b/src/cli.ts index c7f2e55286..bbdc84d7e2 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -35,7 +35,8 @@ import { recordEngineBootstrap } from "./storage/runtime-status.js"; import { configFile as defaultConfigFile } from "./paths.js"; import { log as loggerLog } from "./logger.js"; import { createAutoRestartHandler } from "./restart.js"; -import { checkForUpdate, startAutoUpdate } from "./update.js"; +import { checkForUpdate, startAutoUpdate, forceInstallVersion, findInstallDir } from "./update.js"; +import { setPin, clearPin, activePin, parsePinDuration } from "./update-pin.js"; import { registerUpdateActions } from "./server/update-actions.js"; import { startAdvisoryWatcher, getAdvisoryState, advisoryDeferring, advisoryBlocksVersion, advisoryAwaitingFirstCheck } from "./advisory.js"; import { startReleaseNotesWatcher } from "./update-notes.js"; @@ -121,7 +122,13 @@ Usage: each (pure-append / mid-stream-rewrite / prefix-stable-miss); --json machine output, --log FILE correlates [acp-usage] lines (default /bili.log), --no-log skips, --session SID filters - bili update check for & install a newer version now + bili update [version] check for & install a newer version now; with a + version argument, installs that exact published + version (release or prerelease/temp build) + bili pin [duration] pin the installed version (1h/12h/1d/7d/forever; + default indefinite) — auto-upgrade becomes + check-only until the pin lifts or bili unpin + bili unpin lift the pin early bili doctor audit every install lane: versions, owners, freshness vs registry, running proxy processes (read-only; --json for machine-readable output); @@ -210,7 +217,7 @@ Docs: https://github.com/ranxianglei/billion-context `; type Parsed = { - command: "start" | "update" | "doctor" | "help" | "version" | "launch" | "test" | "export" | "plugin-register" | "mcp" | "plugin" | "acp-cache" | "sessions" | "storage" | "pack"; + command: "start" | "update" | "pin" | "unpin" | "doctor" | "help" | "version" | "launch" | "test" | "export" | "plugin-register" | "mcp" | "plugin" | "acp-cache" | "sessions" | "storage" | "pack"; client?: ClientName; clientArgs: string[]; mitmDomains: string[]; @@ -242,6 +249,8 @@ type Parsed = { jsonOutput?: boolean; doctorJson?: boolean; doctorFix?: boolean; + updateVersion?: string; + pinDuration?: string; }; export function parseArgs(argv: string[]): Parsed { @@ -279,6 +288,8 @@ export function parseArgs(argv: string[]): Parsed { let jsonOutput = false; let doctorJson = false; let doctorFix = false; + let updateVersion: string | undefined; + let pinDuration: string | undefined; for (let i = 0; i < argv.length; i++) { const a = argv[i]!; @@ -485,6 +496,12 @@ export function parseArgs(argv: string[]): Parsed { command = "start"; } else if (cmd === "update") { command = "update"; + updateVersion = positional[1]; + } else if (cmd === "pin") { + command = "pin"; + pinDuration = positional[1]; + } else if (cmd === "unpin") { + command = "unpin"; } else if (cmd === "doctor") { command = "doctor"; } else if (cmd === "export") { @@ -605,11 +622,11 @@ export function parseArgs(argv: string[]): Parsed { } } - return { command, client, clientArgs, mitmDomains, overrides, exportSelector, exportOutput, exportFull, exportJsonl, registerConversationId, pluginAction, pluginAgent, pluginWithMcp, acpCacheDir, acpCacheLog, acpCacheNoLog, acpCacheSession, sessionsSub, sessionsTarget, sessionsNoVacuum, sessionsApply, sessionsRestoreTarget, storageDays, storageVacuum, storageDryRun, jsonOutput, doctorJson, doctorFix, packAction, packSpec, packProject, packForce }; + return { command, client, clientArgs, mitmDomains, overrides, exportSelector, exportOutput, exportFull, exportJsonl, registerConversationId, pluginAction, pluginAgent, pluginWithMcp, acpCacheDir, acpCacheLog, acpCacheNoLog, acpCacheSession, sessionsSub, sessionsTarget, sessionsNoVacuum, sessionsApply, sessionsRestoreTarget, storageDays, storageVacuum, storageDryRun, jsonOutput, doctorJson, doctorFix, packAction, packSpec, packProject, packForce, updateVersion, pinDuration }; } export async function main(): Promise { - const { command, client, clientArgs, mitmDomains, overrides, exportSelector, exportOutput, exportFull, exportJsonl, registerConversationId, pluginAction, pluginAgent, pluginWithMcp, acpCacheDir, acpCacheLog, acpCacheNoLog, acpCacheSession, sessionsSub, sessionsTarget, sessionsNoVacuum, sessionsApply, sessionsRestoreTarget, storageDays, storageVacuum, storageDryRun, jsonOutput, doctorJson, doctorFix, packAction, packSpec, packProject, packForce } = parseArgs(process.argv.slice(2)); + const { command, client, clientArgs, mitmDomains, overrides, exportSelector, exportOutput, exportFull, exportJsonl, registerConversationId, pluginAction, pluginAgent, pluginWithMcp, acpCacheDir, acpCacheLog, acpCacheNoLog, acpCacheSession, sessionsSub, sessionsTarget, sessionsNoVacuum, sessionsApply, sessionsRestoreTarget, storageDays, storageVacuum, storageDryRun, jsonOutput, doctorJson, doctorFix, packAction, packSpec, packProject, packForce, updateVersion, pinDuration } = parseArgs(process.argv.slice(2)); if (command === "help") { process.stdout.write(HELP); return; @@ -819,6 +836,7 @@ export async function main(): Promise { } let updaterResolveProxy: ((url: string) => string | undefined) | undefined; let updateTag: string | undefined; + let installDir: string | undefined; try { const o = loadOptions(); updaterResolveProxy = (url) => resolveProxy(o.routes, o.proxy, url, o.proxyFallback); @@ -826,12 +844,73 @@ export async function main(): Promise { } catch (e) { console.error(`bili update: config load failed (${String(e)}); updater egress goes direct`); } + if (updateVersion) { + // #6804: install a specific published version (release or + // prerelease/temp build). Explicit action = user intent, so this + // bypasses the pin and the tag-channel rule. + try { + installDir = await findInstallDir(PACKAGE_NAME); + } catch { + // installDir stays undefined — forceInstallVersion will refuse + } + const result = await forceInstallVersion( + updateVersion, + installDir, + { packageName: PACKAGE_NAME, currentVersion: VERSION, autoUpdate: true, resolveProxy: updaterResolveProxy, updateTag }, + "manual-cli", + "manual", + ); + if (result.ok) { + console.log(`bili: installed ${updateVersion}`); + } else { + console.error(`bili update ${updateVersion}: ${result.error ?? "install failed"}`); + process.exit(1); + } + return; + } await checkForUpdate( { packageName: PACKAGE_NAME, currentVersion: VERSION, autoUpdate: true, resolveProxy: updaterResolveProxy, updateTag }, true, ); return; } + if (command === "pin") { + // #6804: pin the installed version for a duration. The pin is + // machine-level runtime state — no config file involved. + const version = VERSION; + let until: number | undefined; + if (pinDuration) { + if (pinDuration === "forever") { + // indefinite — no `until` field + } else { + const ms = parsePinDuration(pinDuration); + if (ms === undefined) { + console.error(`bili pin: invalid duration "${pinDuration}" (expected 1h, 12h, 1d, 7d, or forever)`); + process.exit(2); + } + until = Date.now() + ms; + } + } + const pin = await setPin(version, until); + if (pin) { + console.log(`bili: pinned ${version}${until ? ` until ${new Date(until).toISOString()}` : " (indefinite)"}`); + } else { + console.error("bili pin: failed to write pin state"); + process.exit(1); + } + return; + } + if (command === "unpin") { + // #6804: lift the pin early. + const hadPin = (await activePin()) !== undefined; + await clearPin(); + if (hadPin) { + console.log("bili: pin lifted"); + } else { + console.log("bili: no active pin"); + } + return; + } if (command === "test") { if (client === "pi") { await runTestPi({ overrides, mitmDomains }); diff --git a/src/server/admin.ts b/src/server/admin.ts index dd3684131b..0a0591cc54 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -20,7 +20,7 @@ import { handlePluginAttribution, handlePluginCompact, handlePluginFork, handleP import { parseAgentProviderReport, recordAgentProviders, agentProviderRecipes, sanitizeAgentProviderField } from "../agent-providers.js"; import { configDir, defaultLogFile } from "../paths.js"; import { getUpdateVisibility, updateBannerPayload } from "../update-notes.js"; -import { installVersionAction, triggerManualCheck, updateActionsAvailable, updateStateSnapshot } from "./update-actions.js"; +import { installVersionAction, triggerManualCheck, updateActionsAvailable, updateStateSnapshot, pinAction, unpinAction } from "./update-actions.js"; import { getUnrecognizedPathStats } from "./observability.js"; import { getStore } from "../persist.js"; import { BodyTooLargeError, headerValue, readBody } from "../server.js"; @@ -410,6 +410,8 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv } if (req.method === "POST" && req.url === "/__bili/update/check") return handleUpdateCheck(res); if (req.method === "POST" && req.url === "/__bili/update/install") return handleUpdateInstall(req, res, log); + if (req.method === "POST" && req.url === "/__bili/update/pin") return handleUpdatePin(req, res, log); + if (req.method === "POST" && req.url === "/__bili/update/unpin") return handleUpdateUnpin(res, log); if (req.method === "PUT" && req.url === "/__bili/config") { return handleConfigPut(req, res, () => { const fresh = loadOptions(); @@ -1027,6 +1029,47 @@ async function handleUpdateInstall(req: http.IncomingMessage, res: http.ServerRe res.end(JSON.stringify(await installVersionAction(version), null, 2)); } +/** POST /__bili/update/pin {"version":"x.y.z","duration":"1h|12h|1d|7d|forever"} + * — #6804: set a pin on the installed version. Malformed JSON or an invalid + * duration → 400; execution always answers 200 {ok, error?, pin?}. */ +async function handleUpdatePin(req: http.IncomingMessage, res: http.ServerResponse, log: (level: string, msg: string) => void): Promise { + let version: string | undefined; + let duration: string | undefined; + try { + const doc: unknown = JSON.parse((await readBody(req)).toString("utf8")); + if (doc && typeof doc === "object") { + const d = doc as { version?: unknown; duration?: unknown }; + if (typeof d["version"] === "string") version = d["version"].trim(); + if (typeof d["duration"] === "string") duration = d["duration"].trim(); + } + } catch { + res.writeHead(400, { "content-type": "application/json" }); + res.end(JSON.stringify({ error: 'expected JSON body {"version": "", "duration": "<1h|12h|1d|7d|forever>"}' }, null, 2)); + return; + } + if (version === undefined || version.length === 0 || !/^[0-9A-Za-z.+-]+$/.test(version)) { + res.writeHead(400, { "content-type": "application/json" }); + res.end(JSON.stringify({ error: "version must be plain semver characters (digits, dots, +, -) only" }, null, 2)); + return; + } + if (duration !== undefined && duration !== "forever" && !/^\d+[hd]$/.test(duration)) { + res.writeHead(400, { "content-type": "application/json" }); + res.end(JSON.stringify({ error: "duration must be 1h, 12h, 1d, 7d, or forever" }, null, 2)); + return; + } + log("info", `[update] web panel requested pin ${version}${duration ? ` for ${duration}` : " (indefinite)"}`); + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify(await pinAction(version, duration), null, 2)); +} + +/** POST /__bili/update/unpin — #6804: lift the pin early. Always 200 + * {ok, error?}. */ +async function handleUpdateUnpin(res: http.ServerResponse, log: (level: string, msg: string) => void): Promise { + log("info", `[update] web panel requested unpin`); + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify(await unpinAction(), null, 2)); +} + // #2861: server-side dismissal of a host-plugin notice (body {"id": string}). async function handleHostPluginDismiss(req: http.IncomingMessage, res: http.ServerResponse, log: (level: string, msg: string) => void): Promise { let id = ""; diff --git a/src/server/update-actions.ts b/src/server/update-actions.ts index dafcff436a..ffaf7f17ce 100644 --- a/src/server/update-actions.ts +++ b/src/server/update-actions.ts @@ -16,6 +16,7 @@ * nothing here throws into the HTTP handlers. */ import { checkForUpdate, findInstallDir, forceInstallVersion, lastUpdateCheckTime, readDiskVersion, staleInstallStatus, type UpdateCheckOutcome, type UpdateOptions } from "../update.js"; +import { activePin, setPin, clearPin, parsePinDuration, type PinState } from "../update-pin.js"; import { getUpdateVisibility } from "../update-notes.js"; import { log as loggerLog } from "../logger.js"; @@ -44,6 +45,8 @@ interface UpdateStateSnapshotData { checking: boolean; /** True while a pinned install is in flight in this process. */ installing: boolean; + /** #6804: the active pin state (undefined = no pin). */ + pin?: PinState; } let registeredOpts: UpdateOptions | undefined; @@ -139,6 +142,7 @@ export async function updateStateSnapshot(runningVersion: string): Promise { + if (duration === undefined || duration === "forever") { + const pin = await setPin(version); + return { ok: true, pin }; + } + const ms = parsePinDuration(duration); + if (ms === undefined) return { ok: false, error: `invalid duration: ${duration} (expected 1h, 12h, 1d, 7d, or forever)` }; + const pin = await setPin(version, ms); + return { ok: true, pin }; +} + +/** #6804: lift the pin early. Returns ok:true when a pin was active and + * cleared; ok:true with no pin when there was nothing to clear. Never throws. */ +export async function unpinAction(): Promise<{ ok: boolean; error?: string }> { + const hadPin = (await activePin()) !== undefined; + await clearPin(); + if (!hadPin) return { ok: true }; + return { ok: true }; +} + /** Test seam: clear the registered options and both in-flight flags. */ export function _resetUpdateActionsForTest(): void { registeredOpts = undefined; diff --git a/src/update-pin.ts b/src/update-pin.ts new file mode 100644 index 0000000000..a0544f355f --- /dev/null +++ b/src/update-pin.ts @@ -0,0 +1,109 @@ +// #6804: per-machine version pin — a user-intent "hold" on the installed +// version that makes the auto-updater check-only (report but never install). +// Distinct from the #3619 remote policy `pinned` (a fleet-wide upgrade +// ceiling): this is local, per-machine, and survives config edits because it +// is runtime state, not a config key (Configuration Surface Discipline). +// +// The #1481 critical-bug advisory force-install lane still overrides a local +// pin (owner-directed repair wins over user convenience) — the advisory +// watcher calls forceInstallVersion directly, bypassing checkForUpdate. +// +// State file: ~/.cache/billion-context/.pin.json +// { v: 1, version: "0.1.215", setAt: 1700000000000, until?: 1700086400000 } +// `until` absent = indefinite (forever). The pin lifts itself at expiry. + +import { readFile, writeFile, mkdir, rm, rename } from "node:fs/promises"; +import path from "node:path"; +import { cacheDir } from "./paths.js"; + +export interface PinState { + v: 1; + version: string; + setAt: number; + until?: number; +} + +const PIN_FILE = path.join(cacheDir(), ".pin.json"); + +/** Parse a duration string ("1h", "12h", "1d", "7d") into milliseconds. + * Returns undefined for unrecognized input. "forever" is handled by the + * caller (no `until` field). */ +export function parsePinDuration(s: string): number | undefined { + const match = s.trim().match(/^(\d+)\s*([hd])$/i); + if (!match) return undefined; + const amount = Number(match[1]); + if (!Number.isFinite(amount) || amount <= 0) return undefined; + const unit = match[2].toLowerCase(); + if (unit === "h") return amount * 60 * 60 * 1000; + return amount * 24 * 60 * 60 * 1000; // "d" +} + +/** Best-effort read. `undefined` = absent or unreadable/corrupt. */ +export async function readPin(): Promise { + try { + const raw = await readFile(PIN_FILE, "utf-8"); + const doc = JSON.parse(raw) as PinState; + if (!doc || typeof doc !== "object" || doc.v !== 1) return undefined; + if (typeof doc.version !== "string" || doc.version.length === 0) return undefined; + if (typeof doc.setAt !== "number" || !Number.isFinite(doc.setAt)) return undefined; + if (doc.until !== undefined && (typeof doc.until !== "number" || !Number.isFinite(doc.until))) return undefined; + return doc; + } catch { + return undefined; + } +} + +/** Write the pin state atomically (tmp+rename). Never rejects — an + * unwritable cache dir degrades to no-op (the pin simply doesn't persist). */ +export async function writePin(pin: PinState): Promise { + try { + await mkdir(path.dirname(PIN_FILE), { recursive: true }); + const tmp = `${PIN_FILE}.${process.pid}.tmp`; + await writeFile(tmp, JSON.stringify(pin), "utf-8"); + await rename(tmp, PIN_FILE); + } catch { + // best-effort: unwritable cache dir → pin not persisted + } +} + +/** Clear the pin state (remove the file). Never rejects. */ +export async function clearPin(): Promise { + try { + await rm(PIN_FILE, { force: true }); + } catch { + // best-effort + } +} + +/** Return the active pin (or undefined if absent or expired). */ +export async function activePin(): Promise { + const pin = await readPin(); + if (!pin) return undefined; + if (pin.until !== undefined && Date.now() > pin.until) return undefined; + return pin; +} + +/** Check if the given version is currently pinned (version matches and the + * pin has not expired). */ +export async function isVersionPinned(version: string): Promise { + const pin = await activePin(); + if (!pin) return false; + return pin.version === version; +} + +/** Set a pin for the given version. `durationMs` undefined = indefinite. + * Returns the pin state that was written. */ +export async function setPin(version: string, durationMs?: number): Promise { + const now = Date.now(); + const pin: PinState = { v: 1, version, setAt: now }; + if (durationMs !== undefined) { + pin.until = now + durationMs; + } + await writePin(pin); + return pin; +} + +/** Test-only: remove the pin state file. */ +export async function _resetPinForTest(): Promise { + await rm(PIN_FILE, { force: true }); +} diff --git a/src/update.ts b/src/update.ts index 6393774f3c..59cd5e3e3c 100644 --- a/src/update.ts +++ b/src/update.ts @@ -38,6 +38,7 @@ import { resolveDshHome, resolveKimiHome, resolveOmpHome, resolvePiHome } from " import { proxyDispatcher } from "./upstream-proxy.js"; import type { FetchOptions } from "./fetch-util.js"; import { updateRegistryBase as knobUpdateRegistryBase, updateCheckIntervalMs as knobUpdateCheckIntervalMs, updatePolicyUrl as knobUpdatePolicyUrl, updateStaggerMinDelayMs as knobUpdateStaggerMinDelayMs, updateStaggerMaxDelayMs as knobUpdateStaggerMaxDelayMs } from "./knobs.js"; +import { activePin, isVersionPinned } from "./update-pin.js"; import { POLICY_URL_DEFAULT, ensureStaggerDraw, loadUpdatePolicy, resolveStaggerWindow, resolveUpgradeCandidate, setPlannedUpgrade, staggerKey } from "./update-policy.js"; // BILI_UPDATE_REGISTRY overrides the registry base URL (full URL, e.g. a @@ -1696,6 +1697,39 @@ export async function checkForUpdate(opts: UpdateOptions, force = false, checkOn return; } + // #6804: tag-channel rule — an installed prerelease/temp build is never + // auto-swept forward to a release when the updateTag is the release + // channel ("latest"). The check runs, the new version is reported, + // nothing is installed. A prerelease channel target (e.g. + // updateTag=dev) still moves between temp builds (tag !== "latest"). + // Explicit `bili update` (force=true) bypasses this rule. + if (!force && tag === "latest") { + const parsed = parseSemVer(currentVersion); + if (parsed !== undefined && parsed.pre.length > 0) { + if (checkOnly) { + loggerLog("info", `[update] manual web check: installed ${currentVersion} is a prerelease/temp build on the release channel — new version ${latest} reported but not auto-installed (#6804)`); + return { status: "update-available", latest, note: `installed ${currentVersion} is a prerelease/temp build — not auto-swept to a release (#6804)` }; + } + loggerLog("info", `[update] installed ${currentVersion} is a prerelease/temp build on the release channel (tag "latest") — new version ${latest} reported but not auto-installed (#6804)`); + return; + } + } + + // #6804: pin check-only gate — a pinned version is check-only: the + // updater keeps discovering and reporting new versions but never + // auto-installs. An explicit `bili update` (force=true) breaks + // through the pin (explicit action = user intent). The #1481 + // advisory force-install lane overrides the pin (it calls + // forceInstallVersion directly, bypassing checkForUpdate). + if (!force && (await isVersionPinned(currentVersion))) { + if (checkOnly) { + loggerLog("info", `[update] manual web check: version ${currentVersion} is pinned — new version ${latest} reported but not auto-installed (#6804)`); + return { status: "update-available", latest, note: `version ${currentVersion} is pinned — not auto-installing (#6804)` }; + } + loggerLog("info", `[update] version ${currentVersion} is pinned — new version ${latest} reported but not auto-installed (#6804)`); + return; + } + // #3619: remote update policy + staggered rollout. The gate resolves // the final install candidate (pin ceiling / blocked stepping) and the // per-version upgrade moment; any gate failure degrades to the legacy diff --git a/src/web/client.ts b/src/web/client.ts index 3260afdcc5..260997471f 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -1034,6 +1034,20 @@ function changelogCatOf(rawLine) { sel.innerHTML = opt; if (cur) sel.value = cur; } + // #6804: pin status display + const pinStatus = $("up-pin-status"); + const pinBtn = $("up-pin"); + const unpinBtn = $("up-unpin"); + if (pinStatus) { + if (st.pin) { + const until = st.pin.until ? new Date(st.pin.until).toLocaleString() : t("up.pin_none").replace("No pin", "indefinite").replace("未固定", ""); + pinStatus.textContent = t("up.pin_active", { v: st.pin.version, until: until || "indefinite" }); + } else { + pinStatus.textContent = t("up.pin_none"); + } + } + if (pinBtn) pinBtn.disabled = upBusyAction || Boolean(st.pin); + if (unpinBtn) unpinBtn.disabled = upBusyAction || !st.pin; applyUpdateButtons(st); // A check/install started from another tab of this process shows in // the snapshot — keep the buttons held down until it settles. @@ -1167,6 +1181,47 @@ function changelogCatOf(rawLine) { } function upUpgradeNow() { upInstall(upNewestVersion(null).replace(/^v/, "")); } function upInstallSelected() { const sel = $("up-select"); if (sel && sel.value) upInstall(String(sel.value).replace(/^v/, "")); } + function upInstallVersion() { + const input = $("up-version-input"); + if (input && input.value.trim()) upInstall(input.value.trim().replace(/^v/, "")); + } + async function upPin() { + if (upBusyAction) return; + const running = $("up-running") ? $("up-running").textContent.replace(/^v/i, "") : ""; + if (!running || running === "?") return; + const durSel = $("up-pin-duration"); + const duration = durSel ? durSel.value : "forever"; + upBusyAction = true; + upSetButtons(true); + showUpdateResult(t("up.installing", {}), true); + try { + const r = await json(API_ROOT + "/update/pin", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ version: running, duration: duration }) }); + if (r.ok) showUpdateResult(t("up.pin_set", { v: running, until: duration }), true); + else showUpdateResult(String(r.error || t("up.pin_failed", { err: "unknown" })), false); + } catch (e) { + showUpdateResult(e.message, false); + } finally { + upBusyAction = false; + upSetButtons(false); + loadUpdates(); + } + } + async function upUnpin() { + if (upBusyAction) return; + upBusyAction = true; + upSetButtons(true); + try { + const r = await json(API_ROOT + "/update/unpin", { method: "POST", headers: { "content-type": "application/json" }, body: "{}" }); + if (r.ok) showUpdateResult(t("up.pin_cleared"), true); + else showUpdateResult(String(r.error || t("toast.failed", { msg: "unpin failed" })), false); + } catch (e) { + showUpdateResult(e.message, false); + } finally { + upBusyAction = false; + upSetButtons(false); + loadUpdates(); + } + } async function upCheckNow() { if (upBusyAction) return; upBusyAction = true; @@ -5395,6 +5450,13 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " + const unins = $("up-install"); if (usel) usel.addEventListener("change", () => { if (unins) unins.disabled = upBusyAction || !usel.value; focusChangelogRelease(usel.value); }); if (unins) unins.addEventListener("click", () => upInstallSelected()); + // #6804: free-text version install + pin/unpin controls + const upvins = $("up-install-version"); + if (upvins) upvins.addEventListener("click", () => upInstallVersion()); + const uppin = $("up-pin"); + if (uppin) uppin.addEventListener("click", () => upPin()); + const upunpin = $("up-unpin"); + if (upunpin) upunpin.addEventListener("click", () => upUnpin()); let logTimer = null; const lsearch = $("log-search"); if (lsearch) lsearch.addEventListener("input", () => { clearTimeout(logTimer); logTimer = setTimeout(loadLogs, 400); }); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index c512e7d0cc..4ef5a0b914 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -180,6 +180,14 @@ export const MESSAGES: Record> = { "up.upgrade_none": "(暂无已知的更新版本)", "up.upgrade_now": "立即升级到 {v} Upgrade now", "up.install_selected": "安装所选版本 Install selected", + "up.install_version": "安装指定版本 Install version", + "up.pin": "固定版本 Pin", + "up.unpin": "解除固定 Unpin", + "up.pin_active": "已固定 {v} {until}", + "up.pin_none": "未固定 no pin", + "up.pin_set": "已固定 {v} {until}", + "up.pin_cleared": "已解除固定 pin lifted", + "up.pin_failed": "固定失败 {err}", "up.select_placeholder": "选择版本… Select a version…", "up.installing": "正在处理… in flight…", "up.already_in_flight": "已有操作在进行中… an operation is already in flight…", @@ -942,6 +950,14 @@ export const MESSAGES: Record> = { "up.upgrade_none": "(no newer version known)", "up.upgrade_now": "Upgrade now to {v}", "up.install_selected": "Install selected", + "up.install_version": "Install version", + "up.pin": "Pin", + "up.unpin": "Unpin", + "up.pin_active": "Pinned {v} {until}", + "up.pin_none": "No pin", + "up.pin_set": "Pinned {v} {until}", + "up.pin_cleared": "Pin lifted", + "up.pin_failed": "Pin failed: {err}", "up.select_placeholder": "Select a version…", "up.installing": "In flight…", "up.already_in_flight": "An operation is already in flight…", diff --git a/src/web/page.ts b/src/web/page.ts index 45fba31d2d..13a6d5284f 100644 --- a/src/web/page.ts +++ b/src/web/page.ts @@ -169,6 +169,22 @@ export function renderPage(origin: string, version: string, embed = false, theme +
+ + +
+
+ + + + +