feat(app): check for and install plugin updates in Settings › Extensions (#64511)

Co-authored-by: James Long <james@anoma.ly>
This commit is contained in:
opencode-agent[bot]
2026-11-17 15:58:09 -05:00
committed by GitHub
Unverified
parent b24d599d33
commit b03809b2d7
7 changed files with 445 additions and 17 deletions
@@ -1,4 +1,4 @@
import type { IntegrationInfo } from "@opencode/client/promise"
import type { IntegrationInfo, PluginInfo } from "@opencode/client/promise"
import { QueryClient, QueryClientProvider } from "@tanstack/solid-query"
import type { ParentProps } from "solid-js"
import { LocalProvider } from "@/providers/models/selection"
@@ -503,6 +503,28 @@ type DialogStoryRuntimeOptions = {
const REDIRECT_PASTE = ["openai", "gitlab", "snowflake-cortex"]
/** Package plugins for the Plugins tab: two with a newer version, so its update controls show. */
const storyPlugins: PluginInfo[] = [
{
id: "wakatime",
source: { type: "package", target: "opencode-wakatime@latest", version: "1.2.0", outdated: true },
features: { server: true },
state: { status: "active" },
},
{
id: "notifier",
source: { type: "package", target: "opencode-notifier@latest", version: "0.4.1", outdated: true },
features: { server: true, tui: true },
state: { status: "active" },
},
{
id: "review",
source: { type: "package", target: "@acme/opencode-review@latest", version: "2.0.3" },
features: { server: true },
state: { status: "active" },
},
]
export function createStoryFetch(overrides: IntegrationInfo[] = []): typeof fetch {
const integrations = [
...overrides,
@@ -715,6 +737,14 @@ export function createStoryFetch(overrides: IntegrationInfo[] = []): typeof fetc
if (pathname === "/api/session/active") return jsonResponse({ data: {} })
if (pathname === "/api/plugin") return jsonResponse({ location, data: storyPlugins, ready: true })
if (pathname === "/api/plugin/check") return jsonResponse({ location, data: storyPlugins })
// Long enough to see Updating; the list keeps its flags, as a server whose check has not caught up would.
if (pathname === "/api/plugin/update")
return new Promise<Response>((resolve) => setTimeout(() => resolve(noContentResponse()), 1500))
if (pathname === "/api/config" || pathname === "/api/config/shell") return jsonResponse([])
if (pathname === "/api/mcp/resource") return jsonResponse({ location, data: { resources: [], templates: [] } })
+5
View File
@@ -927,6 +927,11 @@ export const dict = {
"sidebar.view.markAllRead": "Mark all as read",
"sidebar.view.noMatch": "No other sessions match",
"settings.plugins.reload": "Reload",
"settings.plugins.check": "Check for updates",
"settings.plugins.checking": "Checking for updates",
"settings.plugins.update": "Update",
"settings.plugins.updating": "Updating",
"settings.plugins.update.label": "Update {{name}}",
"settings.plugins.status.loading": "Loading",
"settings.plugins.status.failed": "Failed",
"settings.plugins.error.notFound": "Plugin not found",
@@ -10,16 +10,28 @@ import { useLanguage } from "@/runtime/i18n/language"
import { usePlatform } from "@/runtime/platform/platform"
import { SettingsList } from "@/settings/list"
import { showToast } from "@/shell/notifications/toast"
import type { PluginUpdateView } from "@/settings/providers/plugin-update-machine"
import "@/settings/settings.css"
import { builtins } from "./builtins"
import { usePluginHost } from "./host"
import { useReservedPlugins } from "./root"
/** Update controls for the listed plugins' packages; without them the rows offer no update. */
export type ExtensionPluginUpdates = {
readonly view: (source: Extract<PluginInfo["source"], { type: "package" }>) => PluginUpdateView
readonly update: (target: string) => void
}
/**
* The plugins a server lists, for the Plugins tab of Extensions. Only the desktop app's own server (`own`) runs its
* plugins' GUIs in this window, so only its rows add the window's controls; other servers and the web list names.
* Any server's package plugins can be updated.
*/
export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: boolean }) {
export function ExtensionPlugins(props: {
plugins: readonly PluginInfo[]
own: boolean
updates?: ExtensionPluginUpdates
}) {
const listed = () => props.plugins.filter((plugin) => plugin.source.type !== "builtin")
return (
@@ -34,13 +46,14 @@ export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: b
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<span class="settings-extension-name truncate">{pluginLabel(plugin)}</span>
</div>
<PluginUpdateButton plugin={plugin} updates={props.updates} />
</div>
)}
</For>
</SettingsList>
}
>
<OwnServerPlugins plugins={listed()} />
<OwnServerPlugins plugins={listed()} updates={props.updates} />
</Show>
)
}
@@ -50,7 +63,7 @@ export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: b
* switch that turns off only the desktop UI, Reload, status and errors, and rows for plugins main lists that the
* server list does not name. Built-ins always run and stay hidden unless they failed, which only this list reports.
*/
function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
function OwnServerPlugins(props: { plugins: readonly PluginInfo[]; updates?: ExtensionPluginUpdates }) {
const language = useLanguage()
const host = usePluginHost()
const bridge = usePlatform().plugins
@@ -136,7 +149,7 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
run(bridge?.manager.reload(id))
}
const row = (input: { id: string | undefined; name: string; builtin?: boolean }) => {
const row = (input: { id: string | undefined; name: string; builtin?: boolean; plugin?: PluginInfo }) => {
const state = () => (input.builtin ? "loaded" : kind(input.id))
const part = input.builtin ? "builtin" : "config"
const live = () => (state() === "loaded" ? input.id : undefined)
@@ -184,9 +197,15 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
</Show>
</div>
</div>
<Show when={!live() && input.plugin}>
{(plugin) => <PluginUpdateButton plugin={plugin()} updates={props.updates} />}
</Show>
<Show when={live()}>
{(id) => (
<div class="settings-servers-actions">
<Show when={input.plugin}>
{(plugin) => <PluginUpdateButton plugin={plugin()} updates={props.updates} />}
</Show>
<Button size="small" variant="ghost" onClick={() => reload(id())}>
{language.t("settings.plugins.reload")}
</Button>
@@ -206,7 +225,7 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
return (
<>
<SettingsList variant="catalog">
<For each={props.plugins}>{(plugin) => row({ id: plugin.id, name: pluginLabel(plugin) })}</For>
<For each={props.plugins}>{(plugin) => row({ id: plugin.id, name: pluginLabel(plugin), plugin })}</For>
<For each={unnamed()}>{(id) => row({ id, name: id })}</For>
<For each={failedBuiltins()}>{(id) => row({ id, name: id, builtin: true })}</For>
</SettingsList>
@@ -217,6 +236,38 @@ function OwnServerPlugins(props: { plugins: readonly PluginInfo[] }) {
)
}
/** Update for a package plugin with a newer version, or the update in progress; nothing otherwise. */
function PluginUpdateButton(props: { plugin: PluginInfo; updates?: ExtensionPluginUpdates }) {
const language = useLanguage()
const view = createMemo(() => {
const source = props.plugin.source
if (source.type !== "package" || !props.updates) return undefined
const current = props.updates.view(source)
return current.outdated || current.updating ? { ...current, target: source.target } : undefined
})
return (
<Show when={view()}>
{(current) => (
<Button
size="small"
variant="ghost"
disabled={current().updating}
aria-busy={current().updating}
aria-label={language.t("settings.plugins.update.label", { name: pluginLabel(props.plugin) })}
onClick={() => props.updates?.update(current().target)}
>
{language.t(current().updating ? "settings.plugins.updating" : "settings.plugins.update")}
</Button>
)}
</Show>
)
}
/** A plugin's error: its first line, the message, with the rest (such as a stack trace) behind a toggle. */
function PluginError(props: { error: string }) {
const language = useLanguage()
@@ -1,5 +1,16 @@
import type { McpServer } from "@opencode/client/promise"
import { Component, For, Show, createEffect, createMemo, onCleanup, type JSX } from "solid-js"
import {
Component,
For,
Show,
createEffect,
createMemo,
createSignal,
on,
onCleanup,
untrack,
type JSX,
} from "solid-js"
import { useDialog } from "@opencode/ui/context/dialog"
import { Icon } from "@opencode/ui/icon"
import { Button } from "@opencode/ui/button"
@@ -10,6 +21,8 @@ import { useLanguage } from "@/runtime/i18n/language"
import { useData } from "@/runtime/server/current"
import { useServerSDK } from "@/runtime/server/client"
import { ServerConnection } from "@/runtime/server/registry"
import { formatServerError } from "@/runtime/server/errors"
import { showToast } from "@/shell/notifications/toast"
import { useMcpController } from "@/providers/connect/mcp"
import { mcpRowView } from "@/providers/connect/mcp-machine"
import { DialogMcp } from "@/providers/connect/mcp-dialog"
@@ -20,6 +33,14 @@ import { SettingsList } from "@/settings/list"
import { createExtensionLoad, ExtensionLoadFailed } from "@/settings/extension-load"
import type { SettingsView } from "@/settings/surface"
import { ConsoleName, ConsoleReplaced, createConsoleSources } from "./console-link"
import {
createPluginUpdateState,
pluginUpdateChecking,
pluginUpdateView,
transitionPluginUpdate,
type PluginUpdateEffect,
type PluginUpdateEvent,
} from "./plugin-update-machine"
import "@/settings/settings.css"
import "@/shell/search-list.css"
@@ -72,11 +93,9 @@ export const SettingsExtensions: Component<{
task: (_, signal) => serverSdk.api.plugin.list(undefined, { signal }).then((result) => result.data),
})
onCleanup(
serverSdk.event.on("plugin.updated", (event) => {
if (!event.location) plugins.invalidate()
}),
)
// Plugin registries are per Location, so every `plugin.updated` names one; the default Location's names its resolved
// directory rather than none, and a filter on a missing location never matched. Listing again is cheap and coalesced.
onCleanup(serverSdk.event.on("plugin.updated", () => plugins.invalidate()))
const pluginList = createMemo(() => {
const current = plugins.view()
@@ -84,6 +103,66 @@ export const SettingsExtensions: Component<{
return current.status === "ready" ? current.value : undefined
})
const [updateState, setUpdateState] = createSignal(createPluginUpdateState())
const dispatchUpdate = (event: PluginUpdateEvent) => {
const previous = untrack(updateState)
const result = transitionPluginUpdate(previous, event)
if (result.state !== previous) setUpdateState(() => result.state)
result.effects.forEach(runUpdate)
}
const runUpdate = (effect: PluginUpdateEffect) => {
if (effect.type === "refresh") return plugins.invalidate()
if (effect.type === "failed")
return showToast({
title: language.t("common.requestFailed"),
description: effect.message,
})
if (effect.type === "check") {
const attempt = effect.attempt
return void serverSdk.api.plugin.check().then(
(result) =>
dispatchUpdate({
type: "check.succeeded",
attempt,
outdated: Object.fromEntries(
result.data.flatMap((plugin) =>
plugin.source.type === "package" ? [[plugin.source.target, plugin.source.outdated === true]] : [],
),
),
}),
(error) => dispatchUpdate({ type: "check.failed", attempt, message: formatServerError(error, language.t) }),
)
}
const id = effect.id
void serverSdk.api.plugin.update({ targets: [effect.target] }).then(
() => dispatchUpdate({ type: "update.succeeded", id }),
(error) => dispatchUpdate({ type: "update.failed", id, message: formatServerError(error, language.t) }),
)
}
createEffect(
on(
() => serverSdk.scope,
() => dispatchUpdate({ type: "server.changed" }),
{ defer: true },
),
)
createEffect(on(pluginList, (list) => list && dispatchUpdate({ type: "list.loaded" }), { defer: true }))
onCleanup(() => dispatchUpdate({ type: "disposed" }))
const pluginUpdates = {
view: (source: Parameters<typeof pluginUpdateView>[1]) => pluginUpdateView(updateState(), source),
update: (target: string) => dispatchUpdate({ type: "update.requested", target }),
}
// The desktop window runs the GUIs of its own server's plugins, so only that server's rows control them.
const own = () => !!platform.plugins && ServerConnection.builtin(serverSdk.server)
@@ -247,13 +326,26 @@ export const SettingsExtensions: Component<{
<span class="settings-extension-heading text-13-medium">
{language.t("settings.extensions.availableAll")}
</span>
<span class="text-13-regular text-v2-text-text-muted">
{language.t("settings.extensions.manageConfig")}
</span>
<div class="flex items-center gap-3">
<span class="text-13-regular text-v2-text-text-muted">
{language.t("settings.extensions.manageConfig")}
</span>
<Button
size="small"
variant="ghost-muted"
disabled={pluginUpdateChecking(updateState())}
aria-busy={pluginUpdateChecking(updateState())}
onClick={() => dispatchUpdate({ type: "check.requested" })}
>
{language.t(
pluginUpdateChecking(updateState()) ? "settings.plugins.checking" : "settings.plugins.check",
)}
</Button>
</div>
</div>
{/* The desktop's own server also lists the plugins main runs, so its rows stay while the list loads. */}
<Show when={own() || pluginList()}>
<ExtensionPlugins plugins={pluginList() ?? []} own={own()} />
<ExtensionPlugins plugins={pluginList() ?? []} own={own()} updates={pluginUpdates} />
</Show>
<Show when={plugins.view().status === "loading" && !own()}>
<p class="project-settings-extension-empty-description">{language.t("common.loading")}</p>
@@ -0,0 +1,121 @@
import { expect, test } from "bun:test"
import {
createPluginUpdateState,
pluginUpdateChecking,
pluginUpdateView,
transitionPluginUpdate,
type PluginUpdateEffect,
type PluginUpdateEvent,
} from "./plugin-update-machine"
/** Drives the machine as the Extensions page does, recording every effect it asks for. */
function harness() {
const machine = { state: createPluginUpdateState() }
const effects: PluginUpdateEffect[] = []
const dispatch = (event: PluginUpdateEvent) => {
const next = transitionPluginUpdate(machine.state, event)
machine.state = next.state
effects.push(...next.effects)
return next
}
return { machine, effects, dispatch }
}
const source = { target: "opencode-plugin-a@latest" } as const
test("a check claims itself at once, ignores a second request, and its result overrides the listed flags", () => {
const run = harness()
run.dispatch({ type: "check.requested" })
const checking = run.machine.state
run.dispatch({ type: "check.requested" })
expect(run.machine.state).toBe(checking)
expect(pluginUpdateChecking(run.machine.state)).toBe(true)
expect(run.effects).toEqual([{ type: "check", attempt: 0 }])
run.dispatch({ type: "check.succeeded", attempt: 0, outdated: { [source.target]: true } })
expect(pluginUpdateChecking(run.machine.state)).toBe(false)
expect(pluginUpdateView(run.machine.state, source)).toEqual({ outdated: true, updating: false })
run.dispatch({ type: "list.loaded" })
expect(pluginUpdateView(run.machine.state, source)).toEqual({ outdated: false, updating: false })
expect(pluginUpdateView(run.machine.state, { ...source, outdated: true })).toEqual({
outdated: true,
updating: false,
})
})
test("a failed check ends idle and reports the error", () => {
const run = harness()
const message = "offline"
run.dispatch({ type: "check.requested" })
run.dispatch({ type: "check.failed", attempt: 0, message })
expect(pluginUpdateChecking(run.machine.state)).toBe(false)
expect(run.effects.at(-1)).toEqual({ type: "failed", message })
})
test("an update runs once per package, then refreshes the list and hides the button", () => {
const run = harness()
const outdated = { ...source, outdated: true } as const
run.dispatch({ type: "update.requested", target: source.target })
const updating = run.machine.state
run.dispatch({ type: "update.requested", target: source.target })
expect(run.machine.state).toBe(updating)
expect(pluginUpdateView(run.machine.state, outdated)).toEqual({ outdated: true, updating: true })
run.dispatch({ type: "update.succeeded", id: 0 })
expect(run.effects).toEqual([{ type: "update", id: 0, target: source.target }, { type: "refresh" }])
// The list still carries the old flag until it loads again.
expect(pluginUpdateView(run.machine.state, outdated)).toEqual({ outdated: false, updating: false })
})
test("a failed update keeps the package outdated and reports the error", () => {
const run = harness()
const message = "npm failed"
run.dispatch({ type: "update.requested", target: source.target })
run.dispatch({ type: "update.failed", id: 0, message })
expect(pluginUpdateView(run.machine.state, { ...source, outdated: true })).toEqual({
outdated: true,
updating: false,
})
expect(run.effects.at(-1)).toEqual({ type: "failed", message })
})
test("results from before a server change or after dispose are ignored", () => {
const run = harness()
run.dispatch({ type: "check.requested" })
run.dispatch({ type: "update.requested", target: source.target })
run.dispatch({ type: "server.changed" })
const changed = run.machine.state
run.dispatch({ type: "check.succeeded", attempt: 0, outdated: { [source.target]: true } })
run.dispatch({ type: "update.failed", id: 1, message: "late" })
expect(run.machine.state).toBe(changed)
expect(pluginUpdateView(run.machine.state, source)).toEqual({ outdated: false, updating: false })
run.dispatch({ type: "disposed" })
const disposed = run.machine.state
run.dispatch({ type: "check.requested" })
expect(run.machine.state).toBe(disposed)
expect(run.effects).toEqual([
{ type: "check", attempt: 0 },
{ type: "update", id: 1, target: source.target },
])
})
@@ -0,0 +1,123 @@
/** One package update on its way; `id` tells it apart from an update of the same package on an earlier server. */
export type RunningPluginUpdate = { readonly id: number; readonly target: string }
/**
* Checking for and installing plugin package updates from Settings › Extensions. `outdated` holds what the latest
* check or update learned per package, which is fresher than the listed plugins until the list loads again.
*/
export type PluginUpdateState =
| {
readonly status: "idle"
readonly nextId: number
readonly outdated: Readonly<Record<string, boolean>>
readonly updating: readonly RunningPluginUpdate[]
}
| {
readonly status: "checking"
readonly attempt: number
readonly nextId: number
readonly outdated: Readonly<Record<string, boolean>>
readonly updating: readonly RunningPluginUpdate[]
}
| { readonly status: "disposed" }
export type PluginUpdateEvent =
| { readonly type: "check.requested" }
/** `outdated` maps every package the check covered to whether it has a newer version. */
| { readonly type: "check.succeeded"; readonly attempt: number; readonly outdated: Readonly<Record<string, boolean>> }
| { readonly type: "check.failed"; readonly attempt: number; readonly message: string }
| { readonly type: "update.requested"; readonly target: string }
| { readonly type: "update.succeeded"; readonly id: number }
| { readonly type: "update.failed"; readonly id: number; readonly message: string }
/** The plugin list loaded again, so its own flags are current. */
| { readonly type: "list.loaded" }
/** Another server: forget what this one's checks and updates learned. */
| { readonly type: "server.changed" }
| { readonly type: "disposed" }
export type PluginUpdateEffect =
| { readonly type: "check"; readonly attempt: number }
| { readonly type: "update"; readonly id: number; readonly target: string }
| { readonly type: "refresh" }
| { readonly type: "failed"; readonly message: string }
export type PluginUpdateTransition = {
readonly state: PluginUpdateState
readonly effects: readonly PluginUpdateEffect[]
}
const none: readonly PluginUpdateEffect[] = []
const step = (state: PluginUpdateState, effects = none): PluginUpdateTransition => ({ state, effects })
export function createPluginUpdateState(): PluginUpdateState {
return { status: "idle", nextId: 0, outdated: {}, updating: [] }
}
export function transitionPluginUpdate(state: PluginUpdateState, event: PluginUpdateEvent): PluginUpdateTransition {
if (state.status === "disposed") return step(state)
if (event.type === "disposed") return step({ status: "disposed" })
if (event.type === "server.changed") return step({ status: "idle", nextId: state.nextId, outdated: {}, updating: [] })
if (event.type === "list.loaded") {
if (Object.keys(state.outdated).length === 0) return step(state)
return step({ ...state, outdated: {} })
}
if (event.type === "check.requested") {
if (state.status === "checking") return step(state)
const attempt = state.nextId
return step({ ...state, status: "checking", attempt, nextId: attempt + 1 }, [{ type: "check", attempt }])
}
if (event.type === "check.succeeded" || event.type === "check.failed") {
if (state.status !== "checking" || state.attempt !== event.attempt) return step(state)
const idle = { status: "idle", nextId: state.nextId, outdated: state.outdated, updating: state.updating } as const
if (event.type === "check.failed") return step(idle, [{ type: "failed", message: event.message }])
return step({ ...idle, outdated: event.outdated })
}
if (event.type === "update.requested") {
if (state.updating.some((item) => item.target === event.target)) return step(state)
const id = state.nextId
return step({ ...state, nextId: id + 1, updating: [...state.updating, { id, target: event.target }] }, [
{ type: "update", id, target: event.target },
])
}
const running = state.updating.find((item) => item.id === event.id)
if (!running) return step(state)
const updating = state.updating.filter((item) => item !== running)
if (event.type === "update.failed") return step({ ...state, updating }, [{ type: "failed", message: event.message }])
return step({ ...state, updating, outdated: { ...state.outdated, [running.target]: false } }, [{ type: "refresh" }])
}
export type PluginUpdateView = { readonly outdated: boolean; readonly updating: boolean }
/** What the Plugins tab shows for a package, given the flags the listed plugin carries. */
export function pluginUpdateView(
state: PluginUpdateState,
source: { readonly target: string; readonly outdated?: true; readonly updating?: true },
): PluginUpdateView {
if (state.status === "disposed") return { outdated: false, updating: false }
const updating = source.updating === true || state.updating.some((item) => item.target === source.target)
return { outdated: state.outdated[source.target] ?? source.outdated === true, updating }
}
export const pluginUpdateChecking = (state: PluginUpdateState) => state.status === "checking"
@@ -5,11 +5,13 @@ import { SettingsScreen } from "@/settings/shell"
import { SettingsSurfaceProvider, type SettingsRootTab } from "@/settings/surface"
import { LayoutProvider } from "@/shell/state/layout"
function SettingsStory(props: { tab: SettingsRootTab; locked?: boolean }) {
function SettingsStory(props: { tab: SettingsRootTab; subtab?: string; locked?: boolean }) {
const history = createMemoryHistory()
const query = new URLSearchParams({ tab: props.tab })
if (props.subtab) query.set("subtab", props.subtab)
if (props.locked) query.set("server", ServerConnection.key(STORY_LOCKED_SERVER))
history.set({ value: `/settings?${query}`, replace: true, scroll: false })
@@ -51,4 +53,8 @@ export const Models = {
render: () => <SettingsStory tab="models" />,
}
export const Plugins = {
render: () => <SettingsStory tab="extensions" subtab="plugins" />,
}
export const UnavailableServer = { render: () => <SettingsStory tab="providers" locked /> }