diff --git a/packages/app/src/entry.tsx b/packages/app/src/entry.tsx index b9760dd88be..969f506c1f6 100644 --- a/packages/app/src/entry.tsx +++ b/packages/app/src/entry.tsx @@ -49,7 +49,8 @@ const clearAuthToken = () => { history.replaceState(null, "", location.pathname + (params.size ? `?${params}` : "") + location.hash) } -const web = createWebPlatform(pkg.version) +// package.json carries the last stable version on every channel, so the server's build passes its own release. +const web = createWebPlatform(import.meta.env.VITE_OPENCODE_VERSION ?? pkg.version) if (import.meta.env.PROD && "serviceWorker" in navigator) { window.addEventListener("load", () => void navigator.serviceWorker.register("/sw.js"), { once: true }) diff --git a/packages/app/src/env.d.ts b/packages/app/src/env.d.ts index b18fe121e71..afe80ccabab 100644 --- a/packages/app/src/env.d.ts +++ b/packages/app/src/env.d.ts @@ -3,6 +3,8 @@ interface ImportMetaEnv { readonly VITE_OPENCODE_SERVER_HOST: string readonly VITE_OPENCODE_SERVER_PORT: string readonly VITE_OPENCODE_CHANNEL?: "local" | "dev" | "beta" | "prod" + /** The release of the CLI whose server embeds this build. Absent in the hosted web app. */ + readonly VITE_OPENCODE_VERSION?: string readonly VITE_SENTRY_DSN?: string readonly VITE_SENTRY_ENVIRONMENT?: string diff --git a/packages/cli/script/app-assets.ts b/packages/cli/script/app-assets.ts index 5f2413d3364..7df12c14004 100644 --- a/packages/cli/script/app-assets.ts +++ b/packages/cli/script/app-assets.ts @@ -5,12 +5,15 @@ import { brotliCompress, constants } from "node:zlib" import { AppArchive } from "../src/app-archive" import { collectFiles } from "./files" -export async function buildAppArchive(channel: string, options?: { skipBuild?: boolean }) { +export async function buildAppArchive(channel: string, version: string, options?: { skipBuild?: boolean }) { if (options?.skipBuild) return AppArchive.encode([]) const root = path.resolve(import.meta.dirname, "../../app") - await $`bun run build` - .cwd(root) - .env({ ...process.env, OPENCODE_CHANNEL: channel, VITE_OPENCODE_SERVER_MODE: "origin" }) + await $`bun run build`.cwd(root).env({ + ...process.env, + OPENCODE_CHANNEL: channel, + VITE_OPENCODE_SERVER_MODE: "origin", + VITE_OPENCODE_VERSION: version, + }) return AppArchive.encode( await Promise.all( (await collectFiles(path.join(root, "dist"))) diff --git a/packages/cli/script/build-node.ts b/packages/cli/script/build-node.ts index 92330fdd5ee..0ea92d2ac35 100644 --- a/packages/cli/script/build-node.ts +++ b/packages/cli/script/build-node.ts @@ -53,7 +53,7 @@ if (!skipInstall) run(process.execPath, ["install", "--os=*", "--cpu=*"]) if (appArchiveOnly) { if (!archivePath) throw new Error("--app-archive-only requires OPENCODE_APP_ARCHIVE") await mkdir(path.dirname(archivePath), { recursive: true }) - await writeFile(archivePath, await buildAppArchive(Script.channel)) + await writeFile(archivePath, await buildAppArchive(Script.channel, Script.version)) process.exit(0) } if (targets.length === 0) { @@ -64,7 +64,7 @@ if (!bundleOnly && targets.some((target) => target.platform === "darwin" && targ throw new Error("Node 26.4 SEA does not support macOS x64") } const modelsSnapshot = await bundledModelsSnapshot() -const appArchive = archivePath ? await Bun.file(archivePath).bytes() : await buildAppArchive(Script.channel) +const appArchive = archivePath ? await Bun.file(archivePath).bytes() : await buildAppArchive(Script.channel, Script.version) if (!bundleOnly) await rm(outdir, { recursive: true, force: true }) const builder = !bundleOnly || targets.some((target) => target.platform === process.platform && target.arch === process.arch) diff --git a/packages/cli/script/build.ts b/packages/cli/script/build.ts index e07c27ed87e..a9ae9e60697 100755 --- a/packages/cli/script/build.ts +++ b/packages/cli/script/build.ts @@ -73,7 +73,7 @@ if (!targets.length) throw new Error(`Unknown build target: ${requestedTarget}`) if (!skipInstall) await $`bun install --os="*" --cpu="*" --libc="*" @opentui/core@${pkg.dependencies["@opentui/core"]} @opencode/pty@${pkg.dependencies["@opencode/pty"]}` const appArchive = path.join(dir, ".cache", "bun-app-archive.bin") -await Bun.write(appArchive, await buildAppArchive(Script.channel, { skipBuild: skipWebUi })) +await Bun.write(appArchive, await buildAppArchive(Script.channel, Script.version, { skipBuild: skipWebUi })) const appAssetsPlugin: BunPlugin = { name: "opencode-app-assets", setup(build) {