GeezerVison is showing github.com — feat(tui): show release highlights after updating (#54969) · jonBoone/opencode@2bf145b
File treeExpand file treeCollapse file tree Open diff view settings feature-plugins/system/storybook
services/www/src/docs/content/cli
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/publish.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,7 @@ jobs: | 112 | 112 | BUN_COMPILE_RELEASE: bun-v1.4.2 | 113 | 113 | OPENCODE_VERSION: ${{ needs.version.outputs.version }} | 114 | 114 | OPENCODE_RELEASE: ${{ needs.version.outputs.release }} | | 115 | + OPENCODE_RELEASE_NOTES: ${{ (github.ref_name == 'dev' && inputs.release_notes) || '' }} | 115 | 116 | GH_REPO: ${{ needs.version.outputs.repo }} | 116 | 117 | GH_TOKEN: ${{ steps.committer.outputs.token }} | 117 | 118 |
| @@ -258,6 +259,7 @@ jobs: | 258 | 259 | env: | 259 | 260 | OPENCODE_VERSION: ${{ needs.version.outputs.version }} | 260 | 261 | OPENCODE_RELEASE: ${{ needs.version.outputs.release }} | | 262 | + OPENCODE_RELEASE_NOTES: ${{ (github.ref_name == 'dev' && inputs.release_notes) || '' }} | 261 | 263 |
| 262 | 264 | - name: Verify service lifecycle | 263 | 265 | if: matrix.settings.target != 'windows-arm64' | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/script/build-node.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import os from "node:os" | 7 | 7 | import path from "node:path" | 8 | 8 | import { build } from "vite" | 9 | 9 | import { Script } from "@opencode/script" | | 10 | +import { embed } from "@opencode/script/highlights" | 10 | 11 | import pkg from "../package.json" | 11 | 12 | import { collectNodeAssets, copyNodeAssets, hashNodeAssets, seaAssetMap } from "./node-assets" | 12 | 13 | import { appArchiveAsset, mainConfig } from "../vite.node.config" | @@ -28,6 +29,7 @@ const bundleOnly = process.argv.includes("--bundle-only") | 28 | 29 | const single = process.argv.includes("--single") | 29 | 30 | const skipInstall = process.argv.includes("--skip-install") | 30 | 31 | const appArchiveOnly = process.argv.includes("--app-archive-only") | | 32 | +const highlights = Script.preview ? undefined : embed(process.env.OPENCODE_RELEASE_NOTES) | 31 | 33 | const requestedArchive = process.argv.find((arg) => arg.startsWith("--app-archive="))?.slice("--app-archive=".length) | 32 | 34 | const archivePath = requestedArchive ? path.resolve(dir, requestedArchive) : undefined | 33 | 35 | const requested = process.argv.find((arg) => arg.startsWith("--target="))?.slice("--target=".length) | @@ -93,6 +95,7 @@ for (const target of targets) { | 93 | 95 | const input = { | 94 | 96 | version: Script.version, | 95 | 97 | channel: Script.channel, | | 98 | + highlights, | 96 | 99 | assetHash, | 97 | 100 | target, | 98 | 101 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/script/build.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ import { $ } from "bun" | 4 | 4 | import { mkdir, rm } from "fs/promises" | 5 | 5 | import path from "path" | 6 | 6 | import { Script } from "@opencode/script" | | 7 | +import { embed } from "@opencode/script/highlights" | 7 | 8 | import { createSolidTransformPlugin } from "@opentui/solid/bun-plugin" | 8 | 9 | import type { BunPlugin } from "bun" | 9 | 10 | import pkg from "../package.json" | @@ -29,6 +30,7 @@ const requestedTarget = process.argv.find((arg) => arg.startsWith("--target="))? | 29 | 30 | const skipInstall = process.argv.includes("--skip-install") | 30 | 31 | const skipWebUi = process.argv.includes("--skip-web-ui") | 31 | 32 | const solidPlugin = createSolidTransformPlugin() | | 33 | +const highlights = Script.preview ? undefined : embed(process.env.OPENCODE_RELEASE_NOTES) | 32 | 34 | const releaseAssets = new Map<string, Promise<Map<string, string>>>() | 33 | 35 |
| 34 | 36 | const allTargets: { | @@ -189,6 +191,7 @@ export default { path: file, version: ${JSON.stringify(opencodePty.version)}, sh | 189 | 191 | OPENCODE_CLI_NAME: "'opencode'", | 190 | 192 | OPENCODE_CHANNEL: `'${Script.channel}'`, | 191 | 193 | OPENCODE_ARTIFACT: `'cli'`, | | 194 | + ...(highlights ? { OPENCODE_RELEASE_HIGHLIGHTS: JSON.stringify(highlights) } : {}), | 192 | 195 | OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "undefined", | 193 | 196 | // FFF_LIBC selects the fff native lib variant: "musl" or "gnu". | 194 | 197 | FFF_LIBC: item.os === "linux" ? `'${item.abi ?? "gnu"}'` : "undefined", | |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/src/commands/handlers/default.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ import { ServerConnection } from "../../services/server-connection" | 9 | 9 | import { Updater } from "../../services/updater" | 10 | 10 | import { UpdatePreflight } from "../../services/update-preflight" | 11 | 11 | import { Npm } from "@opencode/util/npm" | 12 | | -import { OPENCODE_ARTIFACT, OPENCODE_CHANNEL, OPENCODE_VERSION } from "../../version" | | 12 | +import { OPENCODE_ARTIFACT, OPENCODE_CHANNEL, OPENCODE_HIGHLIGHTS, OPENCODE_VERSION } from "../../version" | 13 | 13 | import { Env } from "../../env" | 14 | 14 | import { Service } from "@opencode/client/effect/service" | 15 | 15 | import { OpenCode } from "@opencode/client/promise" | @@ -98,6 +98,7 @@ export default Runtime.handler(Commands, (input) => | 98 | 98 | name: process.env.OPENCODE_CLIENT ?? OPENCODE_ARTIFACT, | 99 | 99 | version: OPENCODE_VERSION, | 100 | 100 | channel: process.env.OPENCODE_TUI_CHANNEL ?? OPENCODE_CHANNEL, | | 101 | + highlights: OPENCODE_HIGHLIGHTS, | 101 | 102 | }, | 102 | 103 | server: { | 103 | 104 | endpoint: server.endpoint, | |
Collapse file Copy file name to clipboard +19-1Lines changed: 19 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { Option, Schema } from "effect" | | 2 | + | 1 | 3 | declare const OPENCODE_VERSION: string | 2 | 4 | declare const OPENCODE_CHANNEL: string | 3 | 5 | declare const OPENCODE_ARTIFACT: string | | 6 | +declare const OPENCODE_RELEASE_HIGHLIGHTS: string | 4 | 7 |
| 5 | 8 | const version = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local" | 6 | 9 | const channel = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local" | 7 | 10 | const artifact = typeof OPENCODE_ARTIFACT === "string" ? OPENCODE_ARTIFACT : "cli" | | 11 | +// Stable release builds embed the release notes' Highlights; every other build has none. | | 12 | +const highlights = | | 13 | + typeof OPENCODE_RELEASE_HIGHLIGHTS === "string" | | 14 | + ? Option.getOrElse( | | 15 | + Schema.decodeUnknownOption( | | 16 | + Schema.fromJsonString(Schema.Array(Schema.Struct({ title: Schema.String, body: Schema.String }))), | | 17 | + )(OPENCODE_RELEASE_HIGHLIGHTS), | | 18 | + () => [], | | 19 | + ) | | 20 | + : [] | 8 | 21 |
| 9 | | -export { version as OPENCODE_VERSION, channel as OPENCODE_CHANNEL, artifact as OPENCODE_ARTIFACT } | | 22 | +export { | | 23 | + version as OPENCODE_VERSION, | | 24 | + channel as OPENCODE_CHANNEL, | | 25 | + artifact as OPENCODE_ARTIFACT, | | 26 | + highlights as OPENCODE_HIGHLIGHTS, | | 27 | +} | 10 | 28 | export const OPENCODE_LOCAL = channel === "local" |
Collapse file Copy file name to clipboardExpand all lines: packages/cli/vite.node.config.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -251,6 +251,7 @@ if (process.platform === "linux") process.env.OPENTUI_LIBC = "glibc"` | 251 | 251 | export type NodeBuildInput = { | 252 | 252 | readonly version: string | 253 | 253 | readonly channel: string | | 254 | + readonly highlights?: string | 254 | 255 | readonly assetHash: string | 255 | 256 | readonly target: NodeTarget | 256 | 257 | } | @@ -278,6 +279,7 @@ export function mainConfig(input: NodeBuildInput): UserConfig { | 278 | 279 | OPENCODE_CLI_NAME: JSON.stringify("opencode2-node"), | 279 | 280 | OPENCODE_CHANNEL: JSON.stringify(input.channel), | 280 | 281 | OPENCODE_ARTIFACT: JSON.stringify("cli-node"), | | 282 | + ...(input.highlights ? { OPENCODE_RELEASE_HIGHLIGHTS: JSON.stringify(input.highlights) } : {}), | 281 | 283 | OPENCODE_LIBC: input.target.platform === "linux" ? JSON.stringify("glibc") : "undefined", | 282 | 284 | FFF_LIBC: input.target.platform === "linux" ? JSON.stringify("gnu") : "undefined", | 283 | 285 | "process.env.WS_NO_BUFFER_UTIL": JSON.stringify("1"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/script/package.json +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | "name": "@opencode/script", | 4 | 4 | "type": "module", | 5 | 5 | "license": "MIT", | | 6 | + "scripts": { | | 7 | + "test": "bun test" | | 8 | + }, | 6 | 9 | "dependencies": { | 7 | 10 | "semver": "^7.6.3" | 8 | 11 | }, | | 11 | 14 | "@types/semver": "^7.5.8" | 12 | 15 | }, | 13 | 16 | "exports": { | 14 | | - ".": "./src/index.ts" | | 17 | + ".": "./src/index.ts", | | 18 | + "./highlights": "./src/highlights.ts" | 15 | 19 | } | 16 | 20 | } |
Collapse file Copy file name to clipboard +68Lines changed: 68 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +export type Highlight = { title: string; body: string } | | 2 | + | | 3 | +const LIMIT = { items: 5, title: 60, body: 300 } | | 4 | + | | 5 | +/** | | 6 | + * Extracts the `### Highlights` bullets from reviewed release notes. Each bullet is expected to look like | | 7 | + * `- **Title**: One or two sentences. ([#123](https://github.com/...))`; trailing pull request links are dropped and | | 8 | + * inline Markdown is reduced to plain text, keeping backticks for code spans. Problems are reported instead of thrown | | 9 | + * so a formatting mistake never fails a release build. | | 10 | + */ | | 11 | +export function parse(notes: string) { | | 12 | + const problems: string[] = [] | | 13 | + const lines = notes.replace(/\r\n/g, "\n").split("\n") | | 14 | + const start = lines.findIndex((line) => /^###\s+Highlights\s*$/i.test(line.trim())) | | 15 | + if (start === -1) return { items: [] as Highlight[], problems } | | 16 | + const end = lines.findIndex((line, index) => index > start && /^#{1,3}\s/.test(line)) | | 17 | + const bullets = lines.slice(start + 1, end === -1 ? undefined : end).reduce( | | 18 | + (state, line) => { | | 19 | + if (line.trim().startsWith("```")) return { ...state, fenced: !state.fenced } | | 20 | + if (state.fenced) return state | | 21 | + const bullet = line.match(/^[-*]\s+(.*)$/) | | 22 | + if (bullet) return { ...state, items: [...state.items, bullet[1]] } | | 23 | + if (state.items.length && /^\s+\S/.test(line)) | | 24 | + return { ...state, items: [...state.items.slice(0, -1), `${state.items.at(-1)} ${line.trim()}`] } | | 25 | + return state | | 26 | + }, | | 27 | + { fenced: false, items: [] as string[] }, | | 28 | + ).items | | 29 | + | | 30 | + const items = bullets.flatMap((bullet) => { | | 31 | + const match = bullet.match(/^\*\*(.+?)\*\*:?\s*(.*)$/) | | 32 | + const title = match && plain(match[1].replace(/:$/, "")) | | 33 | + const body = match && plain(match[2].replace(/\s*\((?:\[[^\]]*\]\([^)]*\)(?:,\s*)?)+\)\s*$/, "")) | | 34 | + if (!title || !body) { | | 35 | + problems.push(`Skipped a highlight without a bold title and description: ${bullet.slice(0, 80)}`) | | 36 | + return [] | | 37 | + } | | 38 | + return [{ title: truncate(title, LIMIT.title), body: truncate(body, LIMIT.body) }] | | 39 | + }) | | 40 | + | | 41 | + if (items.length > LIMIT.items) problems.push(`Kept the first ${LIMIT.items} of ${items.length} highlights`) | | 42 | + if (!items.length) problems.push("The Highlights section has no highlights in the expected format") | | 43 | + return { items: items.slice(0, LIMIT.items), problems } | | 44 | +} | | 45 | + | | 46 | +function plain(value: string) { | | 47 | + return value | | 48 | + .replace(/\*\*(.+?)\*\*/g, "$1") | | 49 | + .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") | | 50 | + .replace(/\s+/g, " ") | | 51 | + .trim() | | 52 | +} | | 53 | + | | 54 | +function truncate(value: string, limit: number) { | | 55 | + if (value.length <= limit) return value | | 56 | + const cut = value.slice(0, limit - 1) | | 57 | + const space = cut.lastIndexOf(" ") | | 58 | + return `${(space > limit / 2 ? cut.slice(0, space) : cut).trimEnd()}…` | | 59 | +} | | 60 | + | | 61 | +/** Returns the JSON a stable release build embeds as `OPENCODE_RELEASE_HIGHLIGHTS`, warning about malformed notes. */ | | 62 | +export function embed(notes: string | undefined) { | | 63 | + if (!notes?.trim()) return | | 64 | + const result = parse(notes) | | 65 | + result.problems.forEach((problem) => console.warn(`release highlights: ${problem}`)) | | 66 | + if (!result.items.length) return | | 67 | + return JSON.stringify(result.items) | | 68 | +} |
Collapse file Copy file name to clipboard +80Lines changed: 80 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { describe, expect, test } from "bun:test" | | 2 | +import path from "path" | | 3 | +import { parse } from "../src/highlights" | | 4 | + | | 5 | +describe("highlights", () => { | | 6 | + test("parses the v2.0.27 release notes", async () => { | | 7 | + const changelog = await Bun.file(path.resolve(import.meta.dir, "../../../CHANGELOG.md")).text() | | 8 | + const notes = changelog.split(/^## v2\.0\.27 .*$/m)[1].split(/^## /m)[0] | | 9 | + const result = parse(notes) | | 10 | + | | 11 | + expect(result.problems).toEqual([]) | | 12 | + expect(result.items.map((item) => item.title)).toEqual([ | | 13 | + "Built-In Worktree Tools", | | 14 | + "Safer Remote Pairing", | | 15 | + "Installable Web App", | | 16 | + "Clear Session Failures", | | 17 | + "Automatic Project Cleanup", | | 18 | + ]) | | 19 | + expect(result.items[0].body).toBe( | | 20 | + "Ask OpenCode to use `worktree_create`, `worktree_list`, and `worktree_remove` in Code Mode. You can create " + | | 21 | + "isolated worktrees, move sessions into them, and remove them with normal edit approval.", | | 22 | + ) | | 23 | + expect(result.items[2].body).toBe( | | 24 | + "Use Chrome or Edge’s Install button to install the OpenCode web app, including when it runs behind an " + | | 25 | + "authenticating proxy.", | | 26 | + ) | | 27 | + expect(result.items.some((item) => item.body.includes("github.com") || item.body.includes("(["))).toBe(false) | | 28 | + }) | | 29 | + | | 30 | + test("joins wrapped lines and drops multiple trailing links", () => { | | 31 | + const result = parse( | | 32 | + [ | | 33 | + "### Highlights", | | 34 | + "", | | 35 | + "- **Reopen Closed Tabs:** Right-click the new-session button to bring back a session you closed by", | | 36 | + " mistake. ([#123](https://github.com/anomalyco/opencode/pull/123), [#124](https://github.com/anomalyco/opencode/pull/124))", | | 37 | + "* **Faster [Search](https://example.com)**: Results now stream in.", | | 38 | + "", | | 39 | + "### Core", | | 40 | + "", | | 41 | + "- **Not a Highlight**: Ignored.", | | 42 | + ].join("\n"), | | 43 | + ) | | 44 | + | | 45 | + expect(result).toEqual({ | | 46 | + items: [ | | 47 | + { | | 48 | + title: "Reopen Closed Tabs", | | 49 | + body: "Right-click the new-session button to bring back a session you closed by mistake.", | | 50 | + }, | | 51 | + { title: "Faster Search", body: "Results now stream in." }, | | 52 | + ], | | 53 | + problems: [], | | 54 | + }) | | 55 | + }) | | 56 | + | | 57 | + test("returns nothing without a Highlights section", () => { | | 58 | + expect(parse("### Core\n\n- Fixed a bug.")).toEqual({ items: [], problems: [] }) | | 59 | + }) | | 60 | + | | 61 | + test("reports malformed highlights instead of failing", () => { | | 62 | + const result = parse("### Highlights\n\n- Plain bullet without a title.\n") | | 63 | + expect(result.items).toEqual([]) | | 64 | + expect(result.problems).toHaveLength(2) | | 65 | + }) | | 66 | + | | 67 | + test("limits the number and length of highlights", () => { | | 68 | + const result = parse( | | 69 | + [ | | 70 | + "### Highlights", | | 71 | + ...Array.from({ length: 7 }, (_, index) => `- **Item ${index}**: ${"word ".repeat(100)}`), | | 72 | + ].join("\n"), | | 73 | + ) | | 74 | + | | 75 | + expect(result.items).toHaveLength(5) | | 76 | + expect(result.items[0].body.length).toBeLessThanOrEqual(300) | | 77 | + expect(result.items[0].body.endsWith("…")).toBe(true) | | 78 | + expect(result.problems).toEqual(["Kept the first 5 of 7 highlights"]) | | 79 | + }) | | 80 | +}) |
Collapse file Copy file name to clipboardExpand all lines: packages/tui/src/app.tsx +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { existsSync } from "fs" | | 2 | +import path from "path" | 1 | 3 | import { render, useRenderer, useTerminalDimensions } from "@opentui/solid" | 2 | 4 | import { registerOpencodeSpinner } from "./component/register-spinner" | 3 | 5 | import { Effect, Latch } from "effect" | @@ -37,6 +39,7 @@ import { | 37 | 39 | TuiStartupProvider, | 38 | 40 | TuiTerminalEnvironmentProvider, | 39 | 41 | useTuiApp, | | 42 | + useTuiPaths, | 40 | 43 | useTuiStartup, | 41 | 44 | useTuiTerminalEnvironment, | 42 | 45 | type TuiApp, | @@ -64,6 +67,8 @@ import { DialogStatus } from "./component/dialog-status" | 64 | 67 | import { DialogConfig } from "./component/dialog-config" | 65 | 68 | import { DialogDebug } from "./component/dialog-debug" | 66 | 69 | import { DialogPair } from "./component/dialog-pair" | | 70 | +import { DialogHighlights } from "./component/dialog-highlights" | | 71 | +import { claim } from "./util/highlights" | 67 | 72 | import { DialogThemeList } from "./component/dialog-theme-list" | 68 | 73 | import { DialogHelp } from "./ui/dialog-help" | 69 | 74 | import { DialogAgent } from "./component/dialog-agent" | @@ -685,6 +690,30 @@ function App() { | 685 | 690 | .catch(toast.error) | 686 | 691 | }) | 687 | 692 |
| | 693 | + // Opens the release highlights once after an update, but only into an idle home screen during startup. | | 694 | + const storage = useStorage() | | 695 | + const paths = useTuiPaths() | | 696 | + let highlighted = false | | 697 | + createEffect(() => { | | 698 | + if (highlighted || !plugins.ready() || client.connection.status() !== "connected") return | | 699 | + highlighted = true | | 700 | + const items = app.highlights ?? [] | | 701 | + if (config.data.highlights === false) return | | 702 | + if (route.data.type !== "home" || dialog.stack.length > 0 || promptRef.current?.current.text) return | | 703 | + if (args.prompt || args.continue || args.sessionID || args.newSessionID) return | | 704 | + if (process.env.OPENCODE_DRIVE || process.env.OPENCODE_STORY || process.env.OPENCODE_ROUTE) return | | 705 | + void claim(storage, { | | 706 | + version: app.version, | | 707 | + count: items.length, | | 708 | + history: existsSync(path.join(paths.state, "prompt-history.jsonl")), | | 709 | + }) | | 710 | + .then((show) => { | | 711 | + if (show && dialog.stack.length === 0) | | 712 | + dialog.replace(() => <DialogHighlights version={app.version} items={items} />) | | 713 | + }) | | 714 | + .catch(toast.error) | | 715 | + }) | | 716 | + | 688 | 717 | const connected = useConnected() | 689 | 718 | const appCommands = createMemo(() => | 690 | 719 | [ | @@ -957,6 +986,17 @@ function App() { | 957 | 986 | }, | 958 | 987 | category: "Integration", | 959 | 988 | }, | | 989 | + ...(app.highlights?.length | | 990 | + ? [ | | 991 | + { | | 992 | + name: "opencode.highlights", | | 993 | + title: "Show release highlights", | | 994 | + slash: { name: "highlights" }, | | 995 | + run: () => dialog.replace(() => <DialogHighlights version={app.version} items={app.highlights ?? []} />), | | 996 | + category: "System", | | 997 | + }, | | 998 | + ] | | 999 | + : []), | 960 | 1000 | { | 961 | 1001 | name: "opencode.settings", | 962 | 1002 | title: "Open settings", | |
|