mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
feat(tui): show release highlights after updating (#54969)
This commit is contained in:
@@ -112,6 +112,7 @@ jobs:
|
||||
BUN_COMPILE_RELEASE: bun-v1.4.2
|
||||
OPENCODE_VERSION: ${{ needs.version.outputs.version }}
|
||||
OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
|
||||
OPENCODE_RELEASE_NOTES: ${{ (github.ref_name == 'dev' && inputs.release_notes) || '' }}
|
||||
GH_REPO: ${{ needs.version.outputs.repo }}
|
||||
GH_TOKEN: ${{ steps.committer.outputs.token }}
|
||||
|
||||
@@ -258,6 +259,7 @@ jobs:
|
||||
env:
|
||||
OPENCODE_VERSION: ${{ needs.version.outputs.version }}
|
||||
OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
|
||||
OPENCODE_RELEASE_NOTES: ${{ (github.ref_name == 'dev' && inputs.release_notes) || '' }}
|
||||
|
||||
- name: Verify service lifecycle
|
||||
if: matrix.settings.target != 'windows-arm64'
|
||||
|
||||
@@ -7,6 +7,7 @@ import os from "node:os"
|
||||
import path from "node:path"
|
||||
import { build } from "vite"
|
||||
import { Script } from "@opencode/script"
|
||||
import { embed } from "@opencode/script/highlights"
|
||||
import pkg from "../package.json"
|
||||
import { collectNodeAssets, copyNodeAssets, hashNodeAssets, seaAssetMap } from "./node-assets"
|
||||
import { appArchiveAsset, mainConfig } from "../vite.node.config"
|
||||
@@ -28,6 +29,7 @@ const bundleOnly = process.argv.includes("--bundle-only")
|
||||
const single = process.argv.includes("--single")
|
||||
const skipInstall = process.argv.includes("--skip-install")
|
||||
const appArchiveOnly = process.argv.includes("--app-archive-only")
|
||||
const highlights = Script.preview ? undefined : embed(process.env.OPENCODE_RELEASE_NOTES)
|
||||
const requestedArchive = process.argv.find((arg) => arg.startsWith("--app-archive="))?.slice("--app-archive=".length)
|
||||
const archivePath = requestedArchive ? path.resolve(dir, requestedArchive) : undefined
|
||||
const requested = process.argv.find((arg) => arg.startsWith("--target="))?.slice("--target=".length)
|
||||
@@ -93,6 +95,7 @@ for (const target of targets) {
|
||||
const input = {
|
||||
version: Script.version,
|
||||
channel: Script.channel,
|
||||
highlights,
|
||||
assetHash,
|
||||
target,
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { $ } from "bun"
|
||||
import { mkdir, rm } from "fs/promises"
|
||||
import path from "path"
|
||||
import { Script } from "@opencode/script"
|
||||
import { embed } from "@opencode/script/highlights"
|
||||
import { createSolidTransformPlugin } from "@opentui/solid/bun-plugin"
|
||||
import type { BunPlugin } from "bun"
|
||||
import pkg from "../package.json"
|
||||
@@ -29,6 +30,7 @@ const requestedTarget = process.argv.find((arg) => arg.startsWith("--target="))?
|
||||
const skipInstall = process.argv.includes("--skip-install")
|
||||
const skipWebUi = process.argv.includes("--skip-web-ui")
|
||||
const solidPlugin = createSolidTransformPlugin()
|
||||
const highlights = Script.preview ? undefined : embed(process.env.OPENCODE_RELEASE_NOTES)
|
||||
const releaseAssets = new Map<string, Promise<Map<string, string>>>()
|
||||
|
||||
const allTargets: {
|
||||
@@ -189,6 +191,7 @@ export default { path: file, version: ${JSON.stringify(opencodePty.version)}, sh
|
||||
OPENCODE_CLI_NAME: "'opencode'",
|
||||
OPENCODE_CHANNEL: `'${Script.channel}'`,
|
||||
OPENCODE_ARTIFACT: `'cli'`,
|
||||
...(highlights ? { OPENCODE_RELEASE_HIGHLIGHTS: JSON.stringify(highlights) } : {}),
|
||||
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "undefined",
|
||||
// FFF_LIBC selects the fff native lib variant: "musl" or "gnu".
|
||||
FFF_LIBC: item.os === "linux" ? `'${item.abi ?? "gnu"}'` : "undefined",
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ServerConnection } from "../../services/server-connection"
|
||||
import { Updater } from "../../services/updater"
|
||||
import { UpdatePreflight } from "../../services/update-preflight"
|
||||
import { Npm } from "@opencode/util/npm"
|
||||
import { OPENCODE_ARTIFACT, OPENCODE_CHANNEL, OPENCODE_VERSION } from "../../version"
|
||||
import { OPENCODE_ARTIFACT, OPENCODE_CHANNEL, OPENCODE_HIGHLIGHTS, OPENCODE_VERSION } from "../../version"
|
||||
import { Env } from "../../env"
|
||||
import { Service } from "@opencode/client/effect/service"
|
||||
import { OpenCode } from "@opencode/client/promise"
|
||||
@@ -98,6 +98,7 @@ export default Runtime.handler(Commands, (input) =>
|
||||
name: process.env.OPENCODE_CLIENT ?? OPENCODE_ARTIFACT,
|
||||
version: OPENCODE_VERSION,
|
||||
channel: process.env.OPENCODE_TUI_CHANNEL ?? OPENCODE_CHANNEL,
|
||||
highlights: OPENCODE_HIGHLIGHTS,
|
||||
},
|
||||
server: {
|
||||
endpoint: server.endpoint,
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
import { Option, Schema } from "effect"
|
||||
|
||||
declare const OPENCODE_VERSION: string
|
||||
declare const OPENCODE_CHANNEL: string
|
||||
declare const OPENCODE_ARTIFACT: string
|
||||
declare const OPENCODE_RELEASE_HIGHLIGHTS: string
|
||||
|
||||
const version = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
|
||||
const channel = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
|
||||
const artifact = typeof OPENCODE_ARTIFACT === "string" ? OPENCODE_ARTIFACT : "cli"
|
||||
// Stable release builds embed the release notes' Highlights; every other build has none.
|
||||
const highlights =
|
||||
typeof OPENCODE_RELEASE_HIGHLIGHTS === "string"
|
||||
? Option.getOrElse(
|
||||
Schema.decodeUnknownOption(
|
||||
Schema.fromJsonString(Schema.Array(Schema.Struct({ title: Schema.String, body: Schema.String }))),
|
||||
)(OPENCODE_RELEASE_HIGHLIGHTS),
|
||||
() => [],
|
||||
)
|
||||
: []
|
||||
|
||||
export { version as OPENCODE_VERSION, channel as OPENCODE_CHANNEL, artifact as OPENCODE_ARTIFACT }
|
||||
export {
|
||||
version as OPENCODE_VERSION,
|
||||
channel as OPENCODE_CHANNEL,
|
||||
artifact as OPENCODE_ARTIFACT,
|
||||
highlights as OPENCODE_HIGHLIGHTS,
|
||||
}
|
||||
export const OPENCODE_LOCAL = channel === "local"
|
||||
|
||||
@@ -251,6 +251,7 @@ if (process.platform === "linux") process.env.OPENTUI_LIBC = "glibc"`
|
||||
export type NodeBuildInput = {
|
||||
readonly version: string
|
||||
readonly channel: string
|
||||
readonly highlights?: string
|
||||
readonly assetHash: string
|
||||
readonly target: NodeTarget
|
||||
}
|
||||
@@ -278,6 +279,7 @@ export function mainConfig(input: NodeBuildInput): UserConfig {
|
||||
OPENCODE_CLI_NAME: JSON.stringify("opencode2-node"),
|
||||
OPENCODE_CHANNEL: JSON.stringify(input.channel),
|
||||
OPENCODE_ARTIFACT: JSON.stringify("cli-node"),
|
||||
...(input.highlights ? { OPENCODE_RELEASE_HIGHLIGHTS: JSON.stringify(input.highlights) } : {}),
|
||||
OPENCODE_LIBC: input.target.platform === "linux" ? JSON.stringify("glibc") : "undefined",
|
||||
FFF_LIBC: input.target.platform === "linux" ? JSON.stringify("gnu") : "undefined",
|
||||
"process.env.WS_NO_BUFFER_UTIL": JSON.stringify("1"),
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
"name": "@opencode/script",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"semver": "^7.6.3"
|
||||
},
|
||||
@@ -11,6 +14,7 @@
|
||||
"@types/semver": "^7.5.8"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
".": "./src/index.ts",
|
||||
"./highlights": "./src/highlights.ts"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
export type Highlight = { title: string; body: string }
|
||||
|
||||
const LIMIT = { items: 5, title: 60, body: 300 }
|
||||
|
||||
/**
|
||||
* Extracts the `### Highlights` bullets from reviewed release notes. Each bullet is expected to look like
|
||||
* `- **Title**: One or two sentences. ([#123](https://github.com/...))`; trailing pull request links are dropped and
|
||||
* inline Markdown is reduced to plain text, keeping backticks for code spans. Problems are reported instead of thrown
|
||||
* so a formatting mistake never fails a release build.
|
||||
*/
|
||||
export function parse(notes: string) {
|
||||
const problems: string[] = []
|
||||
const lines = notes.replace(/\r\n/g, "\n").split("\n")
|
||||
const start = lines.findIndex((line) => /^###\s+Highlights\s*$/i.test(line.trim()))
|
||||
if (start === -1) return { items: [] as Highlight[], problems }
|
||||
const end = lines.findIndex((line, index) => index > start && /^#{1,3}\s/.test(line))
|
||||
const bullets = lines.slice(start + 1, end === -1 ? undefined : end).reduce(
|
||||
(state, line) => {
|
||||
if (line.trim().startsWith("```")) return { ...state, fenced: !state.fenced }
|
||||
if (state.fenced) return state
|
||||
const bullet = line.match(/^[-*]\s+(.*)$/)
|
||||
if (bullet) return { ...state, items: [...state.items, bullet[1]] }
|
||||
if (state.items.length && /^\s+\S/.test(line))
|
||||
return { ...state, items: [...state.items.slice(0, -1), `${state.items.at(-1)} ${line.trim()}`] }
|
||||
return state
|
||||
},
|
||||
{ fenced: false, items: [] as string[] },
|
||||
).items
|
||||
|
||||
const items = bullets.flatMap((bullet) => {
|
||||
const match = bullet.match(/^\*\*(.+?)\*\*:?\s*(.*)$/)
|
||||
const title = match && plain(match[1].replace(/:$/, ""))
|
||||
const body = match && plain(match[2].replace(/\s*\((?:\[[^\]]*\]\([^)]*\)(?:,\s*)?)+\)\s*$/, ""))
|
||||
if (!title || !body) {
|
||||
problems.push(`Skipped a highlight without a bold title and description: ${bullet.slice(0, 80)}`)
|
||||
return []
|
||||
}
|
||||
return [{ title: truncate(title, LIMIT.title), body: truncate(body, LIMIT.body) }]
|
||||
})
|
||||
|
||||
if (items.length > LIMIT.items) problems.push(`Kept the first ${LIMIT.items} of ${items.length} highlights`)
|
||||
if (!items.length) problems.push("The Highlights section has no highlights in the expected format")
|
||||
return { items: items.slice(0, LIMIT.items), problems }
|
||||
}
|
||||
|
||||
function plain(value: string) {
|
||||
return value
|
||||
.replace(/\*\*(.+?)\*\*/g, "$1")
|
||||
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
}
|
||||
|
||||
function truncate(value: string, limit: number) {
|
||||
if (value.length <= limit) return value
|
||||
const cut = value.slice(0, limit - 1)
|
||||
const space = cut.lastIndexOf(" ")
|
||||
return `${(space > limit / 2 ? cut.slice(0, space) : cut).trimEnd()}…`
|
||||
}
|
||||
|
||||
/** Returns the JSON a stable release build embeds as `OPENCODE_RELEASE_HIGHLIGHTS`, warning about malformed notes. */
|
||||
export function embed(notes: string | undefined) {
|
||||
if (!notes?.trim()) return
|
||||
const result = parse(notes)
|
||||
result.problems.forEach((problem) => console.warn(`release highlights: ${problem}`))
|
||||
if (!result.items.length) return
|
||||
return JSON.stringify(result.items)
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import path from "path"
|
||||
import { parse } from "../src/highlights"
|
||||
|
||||
describe("highlights", () => {
|
||||
test("parses the v2.0.27 release notes", async () => {
|
||||
const changelog = await Bun.file(path.resolve(import.meta.dir, "../../../CHANGELOG.md")).text()
|
||||
const notes = changelog.split(/^## v2\.0\.27 .*$/m)[1].split(/^## /m)[0]
|
||||
const result = parse(notes)
|
||||
|
||||
expect(result.problems).toEqual([])
|
||||
expect(result.items.map((item) => item.title)).toEqual([
|
||||
"Built-In Worktree Tools",
|
||||
"Safer Remote Pairing",
|
||||
"Installable Web App",
|
||||
"Clear Session Failures",
|
||||
"Automatic Project Cleanup",
|
||||
])
|
||||
expect(result.items[0].body).toBe(
|
||||
"Ask OpenCode to use `worktree_create`, `worktree_list`, and `worktree_remove` in Code Mode. You can create " +
|
||||
"isolated worktrees, move sessions into them, and remove them with normal edit approval.",
|
||||
)
|
||||
expect(result.items[2].body).toBe(
|
||||
"Use Chrome or Edge’s Install button to install the OpenCode web app, including when it runs behind an " +
|
||||
"authenticating proxy.",
|
||||
)
|
||||
expect(result.items.some((item) => item.body.includes("github.com") || item.body.includes("(["))).toBe(false)
|
||||
})
|
||||
|
||||
test("joins wrapped lines and drops multiple trailing links", () => {
|
||||
const result = parse(
|
||||
[
|
||||
"### Highlights",
|
||||
"",
|
||||
"- **Reopen Closed Tabs:** Right-click the new-session button to bring back a session you closed by",
|
||||
" mistake. ([#123](https://github.com/anomalyco/opencode/pull/123), [#124](https://github.com/anomalyco/opencode/pull/124))",
|
||||
"* **Faster [Search](https://example.com)**: Results now stream in.",
|
||||
"",
|
||||
"### Core",
|
||||
"",
|
||||
"- **Not a Highlight**: Ignored.",
|
||||
].join("\n"),
|
||||
)
|
||||
|
||||
expect(result).toEqual({
|
||||
items: [
|
||||
{
|
||||
title: "Reopen Closed Tabs",
|
||||
body: "Right-click the new-session button to bring back a session you closed by mistake.",
|
||||
},
|
||||
{ title: "Faster Search", body: "Results now stream in." },
|
||||
],
|
||||
problems: [],
|
||||
})
|
||||
})
|
||||
|
||||
test("returns nothing without a Highlights section", () => {
|
||||
expect(parse("### Core\n\n- Fixed a bug.")).toEqual({ items: [], problems: [] })
|
||||
})
|
||||
|
||||
test("reports malformed highlights instead of failing", () => {
|
||||
const result = parse("### Highlights\n\n- Plain bullet without a title.\n")
|
||||
expect(result.items).toEqual([])
|
||||
expect(result.problems).toHaveLength(2)
|
||||
})
|
||||
|
||||
test("limits the number and length of highlights", () => {
|
||||
const result = parse(
|
||||
[
|
||||
"### Highlights",
|
||||
...Array.from({ length: 7 }, (_, index) => `- **Item ${index}**: ${"word ".repeat(100)}`),
|
||||
].join("\n"),
|
||||
)
|
||||
|
||||
expect(result.items).toHaveLength(5)
|
||||
expect(result.items[0].body.length).toBeLessThanOrEqual(300)
|
||||
expect(result.items[0].body.endsWith("…")).toBe(true)
|
||||
expect(result.problems).toEqual(["Kept the first 5 of 7 highlights"])
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,5 @@
|
||||
import { existsSync } from "fs"
|
||||
import path from "path"
|
||||
import { render, useRenderer, useTerminalDimensions } from "@opentui/solid"
|
||||
import { registerOpencodeSpinner } from "./component/register-spinner"
|
||||
import { Effect, Latch } from "effect"
|
||||
@@ -37,6 +39,7 @@ import {
|
||||
TuiStartupProvider,
|
||||
TuiTerminalEnvironmentProvider,
|
||||
useTuiApp,
|
||||
useTuiPaths,
|
||||
useTuiStartup,
|
||||
useTuiTerminalEnvironment,
|
||||
type TuiApp,
|
||||
@@ -64,6 +67,8 @@ import { DialogStatus } from "./component/dialog-status"
|
||||
import { DialogConfig } from "./component/dialog-config"
|
||||
import { DialogDebug } from "./component/dialog-debug"
|
||||
import { DialogPair } from "./component/dialog-pair"
|
||||
import { DialogHighlights } from "./component/dialog-highlights"
|
||||
import { claim } from "./util/highlights"
|
||||
import { DialogThemeList } from "./component/dialog-theme-list"
|
||||
import { DialogHelp } from "./ui/dialog-help"
|
||||
import { DialogAgent } from "./component/dialog-agent"
|
||||
@@ -685,6 +690,30 @@ function App() {
|
||||
.catch(toast.error)
|
||||
})
|
||||
|
||||
// Opens the release highlights once after an update, but only into an idle home screen during startup.
|
||||
const storage = useStorage()
|
||||
const paths = useTuiPaths()
|
||||
let highlighted = false
|
||||
createEffect(() => {
|
||||
if (highlighted || !plugins.ready() || client.connection.status() !== "connected") return
|
||||
highlighted = true
|
||||
const items = app.highlights ?? []
|
||||
if (config.data.highlights === false) return
|
||||
if (route.data.type !== "home" || dialog.stack.length > 0 || promptRef.current?.current.text) return
|
||||
if (args.prompt || args.continue || args.sessionID || args.newSessionID) return
|
||||
if (process.env.OPENCODE_DRIVE || process.env.OPENCODE_STORY || process.env.OPENCODE_ROUTE) return
|
||||
void claim(storage, {
|
||||
version: app.version,
|
||||
count: items.length,
|
||||
history: existsSync(path.join(paths.state, "prompt-history.jsonl")),
|
||||
})
|
||||
.then((show) => {
|
||||
if (show && dialog.stack.length === 0)
|
||||
dialog.replace(() => <DialogHighlights version={app.version} items={items} />)
|
||||
})
|
||||
.catch(toast.error)
|
||||
})
|
||||
|
||||
const connected = useConnected()
|
||||
const appCommands = createMemo(() =>
|
||||
[
|
||||
@@ -957,6 +986,17 @@ function App() {
|
||||
},
|
||||
category: "Integration",
|
||||
},
|
||||
...(app.highlights?.length
|
||||
? [
|
||||
{
|
||||
name: "opencode.highlights",
|
||||
title: "Show release highlights",
|
||||
slash: { name: "highlights" },
|
||||
run: () => dialog.replace(() => <DialogHighlights version={app.version} items={app.highlights ?? []} />),
|
||||
category: "System",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
name: "opencode.settings",
|
||||
title: "Open settings",
|
||||
|
||||
@@ -289,6 +289,15 @@ export const settings: Setting[] = [
|
||||
format: (value) => `${Math.round(Number(value) * 100)}%`,
|
||||
keywords: ["sound volume", "audio volume"],
|
||||
},
|
||||
{
|
||||
title: "Release highlights",
|
||||
category: "Alerts",
|
||||
path: ["highlights"],
|
||||
default: true,
|
||||
values: [false, true],
|
||||
labels: ["off", "on"],
|
||||
keywords: ["what's new", "changelog", "release notes"],
|
||||
},
|
||||
{
|
||||
title: "Window title",
|
||||
category: "Terminal",
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { TextAttributes, type ScrollBoxRenderable } from "@opentui/core"
|
||||
import { useTerminalDimensions } from "@opentui/solid"
|
||||
import { createMemo, For } from "solid-js"
|
||||
import { useConfig } from "../config"
|
||||
import { Keymap } from "../context/keymap"
|
||||
import type { TuiHighlight } from "../context/runtime"
|
||||
import { useTheme } from "../context/theme"
|
||||
import { useDialog } from "../ui/dialog"
|
||||
import { getScrollAcceleration } from "../util/scroll"
|
||||
|
||||
export function DialogHighlights(props: { version: string; items: ReadonlyArray<TuiHighlight> }) {
|
||||
const dialog = useDialog()
|
||||
const theme = useTheme().surface("dialog")
|
||||
const overlay = useTheme()
|
||||
const config = useConfig().data
|
||||
const dimensions = useTerminalDimensions()
|
||||
const maxHeight = createMemo(() => Math.max(6, Math.floor(dimensions().height * 0.6) - 2))
|
||||
let scroll: ScrollBoxRenderable | undefined
|
||||
|
||||
dialog.setCentered(true)
|
||||
|
||||
Keymap.createLayer(() => ({
|
||||
mode: "modal",
|
||||
commands: [
|
||||
{ bind: "return", title: "Close highlights", group: "Dialog", run: () => dialog.clear() },
|
||||
...["up", "k"].map((bind) => ({ bind, title: "Scroll up", group: "Dialog", run: () => scroll?.scrollBy(-1) })),
|
||||
...["down", "j"].map((bind) => ({ bind, title: "Scroll down", group: "Dialog", run: () => scroll?.scrollBy(1) })),
|
||||
{ bind: "pageup", title: "Previous page", group: "Dialog", run: () => scroll?.scrollBy(-maxHeight()) },
|
||||
{ bind: "pagedown", title: "Next page", group: "Dialog", run: () => scroll?.scrollBy(maxHeight()) },
|
||||
{ bind: "home", title: "Scroll to top", group: "Dialog", run: () => scroll?.scrollTo(0) },
|
||||
{ bind: "end", title: "Scroll to bottom", group: "Dialog", run: () => scroll?.scrollTo(Infinity) },
|
||||
],
|
||||
}))
|
||||
|
||||
return (
|
||||
<box gap={1} paddingBottom={1}>
|
||||
<box flexDirection="row" justifyContent="space-between" paddingLeft={2} paddingRight={2}>
|
||||
<text attributes={TextAttributes.BOLD} fg={theme.text.base}>
|
||||
What's new in {props.version}
|
||||
</text>
|
||||
<text fg={theme.text.muted} onMouseUp={() => dialog.clear()}>
|
||||
esc
|
||||
</text>
|
||||
</box>
|
||||
{/* The band owns the vertical padding so it stays visible while the highlights scroll. */}
|
||||
<box backgroundColor={overlay.background.raised.high} paddingTop={1} paddingBottom={1}>
|
||||
<scrollbox
|
||||
ref={(element: ScrollBoxRenderable) => (scroll = element)}
|
||||
maxHeight={maxHeight()}
|
||||
contentOptions={{ minHeight: 0 }}
|
||||
backgroundColor={overlay.background.raised.high}
|
||||
scrollbarOptions={{ visible: false }}
|
||||
scrollAcceleration={getScrollAcceleration(config)}
|
||||
>
|
||||
<box gap={1} paddingLeft={2} paddingRight={2}>
|
||||
<For each={props.items}>
|
||||
{(item) => (
|
||||
<box>
|
||||
<text attributes={TextAttributes.BOLD} fg={overlay.text.base}>
|
||||
{item.title}
|
||||
</text>
|
||||
{/* Backticks mark code spans, which stand out from the muted description. */}
|
||||
<text fg={overlay.text.muted} wrapMode="word">
|
||||
<For each={item.body.split("`")}>
|
||||
{(part, index) =>
|
||||
index() % 2 === 1 ? <span style={{ fg: overlay.text.base }}>{part}</span> : part
|
||||
}
|
||||
</For>
|
||||
</text>
|
||||
</box>
|
||||
)}
|
||||
</For>
|
||||
</box>
|
||||
</scrollbox>
|
||||
</box>
|
||||
<box flexDirection="row" justifyContent="space-between" alignItems="center" paddingLeft={2} paddingRight={2}>
|
||||
<text fg={theme.text.muted}>↑/↓ scroll</text>
|
||||
<box
|
||||
paddingLeft={3}
|
||||
paddingRight={3}
|
||||
backgroundColor={theme.background.action.primary.focused}
|
||||
onMouseUp={() => dialog.clear()}
|
||||
>
|
||||
<text fg={theme.text.action.primary.focused}>ok</text>
|
||||
</box>
|
||||
</box>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
@@ -244,6 +244,9 @@ export const Info = Schema.Struct({
|
||||
description: "Experimental features that may change or be removed at any time",
|
||||
}),
|
||||
animations: Schema.optional(Schema.Boolean).annotate({ description: "Enable interface animations" }),
|
||||
highlights: Schema.optional(Schema.Boolean).annotate({
|
||||
description: "Show the release highlights once after OpenCode updates",
|
||||
}),
|
||||
mouse: Schema.optional(Schema.Boolean).annotate({ description: "Enable terminal mouse capture" }),
|
||||
cursor: Schema.optional(Cursor),
|
||||
})
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { createComponent, createContext, type JSX, useContext } from "solid-js"
|
||||
|
||||
export type TuiHighlight = Readonly<{
|
||||
title: string
|
||||
body: string
|
||||
}>
|
||||
|
||||
export type TuiApp = Readonly<{
|
||||
name: string
|
||||
version: string
|
||||
channel: string
|
||||
/** The current release's highlights, embedded only in stable release builds. */
|
||||
highlights?: ReadonlyArray<TuiHighlight>
|
||||
}>
|
||||
|
||||
export type TuiPaths = Readonly<{
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { Plugin } from "@opencode/plugin/tui"
|
||||
import { useTerminalDimensions } from "@opentui/solid"
|
||||
import { onMount } from "solid-js"
|
||||
import { DialogHighlights } from "../../../component/dialog-highlights"
|
||||
import type { Story } from "./index"
|
||||
import { StoryFooter } from "./footer"
|
||||
|
||||
// The v2.0.27 release highlights, as a release build embeds them.
|
||||
const items = [
|
||||
{
|
||||
title: "Built-In Worktree Tools",
|
||||
body: "Ask OpenCode to use `worktree_create`, `worktree_list`, and `worktree_remove` in Code Mode. You can create isolated worktrees, move sessions into them, and remove them with normal edit approval.",
|
||||
},
|
||||
{
|
||||
title: "Safer Remote Pairing",
|
||||
body: "The first `opencode pair --remote` now warns that it will expose your server and asks for confirmation. For non-interactive use, pass `opencode pair --remote --yes`.",
|
||||
},
|
||||
{
|
||||
title: "Installable Web App",
|
||||
body: "Use Chrome or Edge’s Install button to install the OpenCode web app, including when it runs behind an authenticating proxy.",
|
||||
},
|
||||
{
|
||||
title: "Clear Session Failures",
|
||||
body: "Desktop and TUI timelines now show execution errors that happen before or between model steps instead of ending without an explanation.",
|
||||
},
|
||||
{
|
||||
title: "Automatic Project Cleanup",
|
||||
body: "Projects whose directories no longer exist are automatically hidden from the project list. Opening the directory again restores the project.",
|
||||
},
|
||||
]
|
||||
|
||||
function HighlightsStory(props: { context: Plugin.Context }) {
|
||||
const dimensions = useTerminalDimensions()
|
||||
const open = (count: number) =>
|
||||
props.context.ui.dialog.show(() => <DialogHighlights version="2.0.27" items={items.slice(0, count)} />)
|
||||
|
||||
props.context.keymap.layer(() => ({
|
||||
commands: [
|
||||
{ bind: "o", title: "Open five highlights", group: "Storybook", run: () => open(5) },
|
||||
{ bind: "t", title: "Open two highlights", group: "Storybook", run: () => open(2) },
|
||||
{
|
||||
bind: "escape",
|
||||
title: "Back to storybook",
|
||||
group: "Storybook",
|
||||
run: () => props.context.ui.router.navigate({ type: "plugin", name: "storybook" }),
|
||||
},
|
||||
],
|
||||
}))
|
||||
onMount(() => open(5))
|
||||
|
||||
return (
|
||||
<box width={dimensions().width} height={dimensions().height} backgroundColor={props.context.theme.background.base}>
|
||||
<box flexGrow={1} />
|
||||
<StoryFooter
|
||||
context={props.context}
|
||||
title="storybook / release highlights"
|
||||
controls={[
|
||||
{ shortcut: "o", label: "five highlights" },
|
||||
{ shortcut: "t", label: "two highlights" },
|
||||
{ shortcut: "esc", label: "back" },
|
||||
]}
|
||||
/>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
export const highlightsStory: Story = {
|
||||
id: "highlights",
|
||||
title: "Release highlights",
|
||||
render: (context) => <HighlightsStory context={context} />,
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { sessionTabsStory } from "./session-tabs"
|
||||
import { sessionLocationMissingStory } from "./session-location-missing"
|
||||
import { oneCellSpinnerStory } from "./one-cell-spinner"
|
||||
import { linkClicksStory } from "./link-clicks"
|
||||
import { highlightsStory } from "./highlights"
|
||||
|
||||
/**
|
||||
* A story is a full-screen, fixture-driven simulation of a real production component. Stories own
|
||||
@@ -24,6 +25,7 @@ const stories: Story[] = [
|
||||
sessionLocationMissingStory,
|
||||
oneCellSpinnerStory,
|
||||
linkClicksStory,
|
||||
highlightsStory,
|
||||
]
|
||||
|
||||
function Commands(props: { context: Plugin.Context }) {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { Storage } from "../context/storage"
|
||||
|
||||
export type HighlightsInput = {
|
||||
readonly version: string
|
||||
/** Number of highlights embedded in this build. */
|
||||
readonly count: number
|
||||
/** Whether this user has used the TUI before, so a first run with no state is still an update. */
|
||||
readonly history: boolean
|
||||
}
|
||||
|
||||
type State = { seen?: string }
|
||||
|
||||
/**
|
||||
* Decides what to do with the current release's highlights: `show` opens the dialog and records the version,
|
||||
* `record` marks a version seen silently, and `none` leaves the state untouched. Only stable versions count.
|
||||
*/
|
||||
export function decide(input: HighlightsInput & { readonly seen?: string }) {
|
||||
const current = stable(input.version)
|
||||
if (!current) return "none"
|
||||
const seen = input.seen === undefined ? undefined : stable(input.seen)
|
||||
if (!seen && !input.history) return "record"
|
||||
if (seen && !newer(current, seen)) return "none"
|
||||
return input.count > 0 ? "show" : "record"
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the decision inside the locked storage update, so only one of several TUIs starting together shows the
|
||||
* dialog. Resolves to whether this TUI should show it.
|
||||
*/
|
||||
export async function claim(storage: Storage, input: HighlightsInput) {
|
||||
const [state, update] = storage.store<State>("highlights", { initial: {} })
|
||||
if (decide({ ...input, seen: state.seen }) === "none") return false
|
||||
const result = { action: "none" as ReturnType<typeof decide> }
|
||||
await update((draft) => {
|
||||
result.action = decide({ ...input, seen: draft.seen })
|
||||
if (result.action !== "none") draft.seen = input.version
|
||||
})
|
||||
return result.action === "show"
|
||||
}
|
||||
|
||||
function stable(version: string) {
|
||||
return version
|
||||
.match(/^(\d+)\.(\d+)\.(\d+)$/)
|
||||
?.slice(1)
|
||||
.map(Number)
|
||||
}
|
||||
|
||||
function newer(current: number[], seen: number[]) {
|
||||
const index = current.findIndex((part, index) => part !== seen[index])
|
||||
return index !== -1 && current[index] > seen[index]
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/** @jsxImportSource @opentui/solid */
|
||||
import { testRender } from "@opentui/solid"
|
||||
import { expect, test } from "bun:test"
|
||||
import { onMount } from "solid-js"
|
||||
import { DialogHighlights } from "../../src/component/dialog-highlights"
|
||||
import { ConfigProvider } from "../../src/config"
|
||||
import { Keymap } from "../../src/context/keymap"
|
||||
import { ThemeProvider } from "../../src/context/theme"
|
||||
import { DialogProvider, useDialog } from "../../src/ui/dialog"
|
||||
import { ToastProvider } from "../../src/ui/toast"
|
||||
import { emptyThemeSource, tmpdir } from "../fixture/fixture"
|
||||
import { TestTuiContexts } from "../fixture/tui-environment"
|
||||
import { createTuiResolvedConfig } from "../fixture/tui-runtime"
|
||||
|
||||
const items = Array.from({ length: 5 }, (_, index) => ({
|
||||
title: `Highlight ${index + 1}`,
|
||||
body: `Use \`command-${index + 1}\` to try the change. It explains what you can do now and why it matters to you.`,
|
||||
}))
|
||||
|
||||
// Dialog key bindings are only active while the dialog is on the stack.
|
||||
function Open() {
|
||||
const dialog = useDialog()
|
||||
onMount(() => dialog.replace(() => <DialogHighlights version="2.0.27" items={items} />))
|
||||
return null
|
||||
}
|
||||
|
||||
test("scrolls long highlights between a fixed title and footer", async () => {
|
||||
await using temporary = await tmpdir()
|
||||
const app = await testRender(
|
||||
() => (
|
||||
<TestTuiContexts directory={temporary.path} paths={{ state: temporary.path }}>
|
||||
<ConfigProvider config={createTuiResolvedConfig()}>
|
||||
<ThemeProvider mode="dark" source={emptyThemeSource}>
|
||||
<Keymap.Provider>
|
||||
<ToastProvider>
|
||||
<DialogProvider>
|
||||
<Open />
|
||||
</DialogProvider>
|
||||
</ToastProvider>
|
||||
</Keymap.Provider>
|
||||
</ThemeProvider>
|
||||
</ConfigProvider>
|
||||
</TestTuiContexts>
|
||||
),
|
||||
{ width: 70, height: 20, kittyKeyboard: true },
|
||||
)
|
||||
|
||||
try {
|
||||
app.renderer.start()
|
||||
await app.waitForFrame((frame) => frame.includes("What's new in 2.0.27") && frame.includes("Highlight 1"))
|
||||
const top = app.captureCharFrame()
|
||||
expect(top).toContain("command-1")
|
||||
expect(top).toContain("↑/↓ scroll")
|
||||
expect(top).not.toContain("Highlight 5")
|
||||
expect(top).not.toContain("`")
|
||||
|
||||
app.mockInput.pressKey("END")
|
||||
await app.waitForFrame((frame) => frame.includes("Highlight 5"))
|
||||
const bottom = app.captureCharFrame()
|
||||
expect(bottom).toContain("What's new in 2.0.27")
|
||||
expect(bottom).toContain("↑/↓ scroll")
|
||||
expect(bottom).not.toContain("Highlight 1")
|
||||
|
||||
app.mockInput.pressKey("k")
|
||||
app.mockInput.pressKey("HOME")
|
||||
await app.waitForFrame((frame) => frame.includes("Highlight 1"))
|
||||
|
||||
app.mockInput.pressEnter()
|
||||
await app.waitForFrame((frame) => !frame.includes("What's new"))
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { readFileSync } from "fs"
|
||||
import path from "path"
|
||||
import { createStorage } from "../src/context/storage"
|
||||
import { claim, decide } from "../src/util/highlights"
|
||||
import { tmpdir } from "./fixture/fixture"
|
||||
|
||||
const input = { version: "2.0.27", count: 5, history: true }
|
||||
|
||||
test("first run shows highlights to existing users and records new installs silently", () => {
|
||||
expect(decide(input)).toBe("show")
|
||||
expect(decide({ ...input, history: false })).toBe("record")
|
||||
expect(decide({ ...input, count: 0 })).toBe("record")
|
||||
})
|
||||
|
||||
test("newer versions show highlights or record silently when there are none", () => {
|
||||
expect(decide({ ...input, seen: "2.0.26" })).toBe("show")
|
||||
expect(decide({ ...input, seen: "1.99.99", history: false })).toBe("show")
|
||||
expect(decide({ ...input, seen: "2.0.26", count: 0 })).toBe("record")
|
||||
})
|
||||
|
||||
test("the same version, downgrades, and unstable versions do nothing", () => {
|
||||
expect(decide({ ...input, seen: "2.0.27" })).toBe("none")
|
||||
expect(decide({ ...input, seen: "2.0.28" })).toBe("none")
|
||||
expect(decide({ ...input, seen: "2.1.0", version: "2.0.30" })).toBe("none")
|
||||
expect(decide({ ...input, version: "0.0.0-dev-123" })).toBe("none")
|
||||
expect(decide({ ...input, version: "local" })).toBe("none")
|
||||
})
|
||||
|
||||
test("only one of several concurrent TUIs claims the highlights", async () => {
|
||||
await using temporary = await tmpdir()
|
||||
const storages = Array.from({ length: 4 }, () => createStorage(temporary.path, "latest"))
|
||||
try {
|
||||
const results = await Promise.all(storages.map((item) => claim(item.storage, input)))
|
||||
expect(results.filter(Boolean)).toHaveLength(1)
|
||||
expect(JSON.parse(readFileSync(path.join(temporary.path, "latest", "tui", "highlights.json"), "utf8"))).toEqual({
|
||||
seen: "2.0.27",
|
||||
})
|
||||
expect(await claim(storages[0].storage, input)).toBe(false)
|
||||
} finally {
|
||||
storages.forEach((item) => item.close())
|
||||
}
|
||||
})
|
||||
@@ -3,6 +3,7 @@
|
||||
import { $ } from "bun"
|
||||
import { OpenCode } from "@opencode/client"
|
||||
import { Service } from "@opencode/client/service"
|
||||
import { parse } from "@opencode/script/highlights"
|
||||
import { rm } from "fs/promises"
|
||||
import path from "path"
|
||||
import { parseArgs } from "util"
|
||||
@@ -87,6 +88,14 @@ const releaseNotes = notes[1].trim()
|
||||
if (!releaseNotes) throw new Error("Release review has no changelog")
|
||||
await Bun.write(changelog, `${releaseNotes}\n`)
|
||||
|
||||
const highlights = parse(releaseNotes)
|
||||
highlights.problems.forEach((problem) => console.warn(`Warning: ${problem}`))
|
||||
console.log(
|
||||
highlights.items.length
|
||||
? `TUI highlights will show:\n${highlights.items.map((item) => ` - ${item.title}`).join("\n")}`
|
||||
: "TUI highlights will not show for this release",
|
||||
)
|
||||
|
||||
const answer = prompt(`Trigger the ${version} release? [y/N]`)
|
||||
if (answer?.trim().toLowerCase() !== "y" && answer?.trim().toLowerCase() !== "yes") {
|
||||
console.log("Release cancelled")
|
||||
|
||||
@@ -243,6 +243,15 @@ Enable system notifications and attention sounds independently:
|
||||
|
||||
An invalid or unreadable override falls back to the built-in sound for that event.
|
||||
|
||||
After an update, the TUI shows the new release's highlights once on the home screen. Run `/highlights` to see them
|
||||
again, or turn the dialog off:
|
||||
|
||||
```json title="cli.json"
|
||||
{
|
||||
"highlights": false
|
||||
}
|
||||
```
|
||||
|
||||
## Terminal
|
||||
|
||||
Configure terminal integration:
|
||||
|
||||
@@ -50,6 +50,8 @@ Type `/` to list slash commands. Continue typing to filter the list, then press
|
||||
|
||||
Common commands include `/new`, `/sessions`, `/models`, `/agents`, `/undo`, `/redo`, and `/editor`. Press **Ctrl+P** to open the command palette for every action available in the current view.
|
||||
|
||||
After an update, OpenCode shows what's new in the release once on the home screen. Run `/highlights` to see it again, or set `"highlights": false` in [`cli.json`](/cli/config#alerts) to stop it from opening automatically.
|
||||
|
||||
## Side questions
|
||||
|
||||
Run `/btw <question>` to ask a quick question about the conversation so far. The answer uses the session's context and current model but is not added to the conversation, so it does not affect later prompts. A `/btw` indicator shows in the prompt footer while it runs, and the answer opens in a dialog; press **C** to copy it.
|
||||
|
||||
Reference in New Issue
Block a user