feat(app): manage desktop plugins in Extensions › Plugins (#59489)

This commit is contained in:
Luke Parker
2026-10-27 13:39:18 +10:00
committed by GitHub
Unverified
parent bc175f675c
commit 5792c3e63b
21 changed files with 408 additions and 300 deletions
@@ -1,4 +1,4 @@
import type { SessionMessageInfo } from "@opencode/client/promise"
import type { PluginInfo, SessionMessageInfo } from "@opencode/client/promise"
import { DialogProvider } from "@opencode/ui/context/dialog"
import { Toast } from "@opencode/ui/toast"
import {
@@ -44,7 +44,7 @@ import { createClosedTabs } from "../src/runtime/plugin/closed-tabs"
import { PluginSlot } from "../src/runtime/plugin/render"
import { persistedHandle } from "../src/runtime/plugin/stores"
import { LanguageProvider } from "../src/runtime/i18n/language"
import { PluginsSettings } from "../src/runtime/plugin/settings-plugins"
import { ExtensionPlugins } from "../src/runtime/plugin/extension-plugins"
import { SessionPluginPills } from "../src/session/composer/plugin-pills"
import { ui } from "../src/runtime/plugin/ui"
@@ -226,8 +226,8 @@ export function mountPlugins(input: {
disabled?: readonly string[]
bridge?: Parameters<typeof createInstalled>[0]
stored?: Readonly<Record<string, Json>>
/** Shows the production Settings > Plugins page for status-label contracts. */
settings?: boolean
/** Shows the production Extensions › Plugins rows of the desktop app's own server, which lists these plugins. */
plugins?: readonly PluginInfo[]
/** The client of an Ipc while main provides it, as a desktop window's bridge reports it. Omitted: the web. */
ipc?: (token: Ipc) => IpcClient<IpcSpec> | undefined
}) {
@@ -310,8 +310,12 @@ export function mountPlugins(input: {
return (
<Show when={host.ready()}>
<Show when={input.settings}>
<PluginsSettings />
<Show when={input.plugins}>
{(plugins) => (
<div data-testid="extension-plugins">
<ExtensionPlugins plugins={plugins()} own />
</div>
)}
</Show>
<PluginSlot at="window.bottom" input={{}} />
</Show>
@@ -1,4 +1,5 @@
import type { Component, Owner } from "solid-js"
import type { PluginInfo } from "@opencode/client/promise"
import type { Context, Contract, DialogHandle, Dialogs, Live, SessionRef, SessionScreen } from "@opencode/plugin/gui"
import type { BuiltinPanelTab } from "@opencode/plugin/gui/builtin"
import type { Bridge, BridgeMessage, EnableState, Installed } from "@opencode/plugin/gui/host"
@@ -1084,19 +1085,32 @@ story("a contract component reads its provider context and preserves reactive pr
expect(result).toEqual({ context: "provider", mounts: 1, before: "before", after: "after" })
})
story("Settings > Plugins shows where each part of a plugin from the config is turned off", async ({ page }, info) => {
await page.evaluate(async (fixture) => {
story("Extensions › Plugins merges the own server's plugins with the desktop GUIs they run", async ({ page }, info) => {
const calls = await page.evaluateHandle(async (fixture) => {
const { mountPlugins, until } = await import(fixture)
const calls: string[] = []
const installed: Installed[] = [
// A built-in that runs stays hidden; one that failed keeps a row, as nothing else reports it.
{ id: "review", builtin: true, enabled: true },
{ id: "terminal", builtin: true, enabled: true },
{ id: "acme", builtin: false, enabled: true, server: true, tui: true },
// A package with only a GUI part has no other part to tag.
// A package with only a GUI part has no other part to tag, and here the server list does not name it.
{ id: "notes", builtin: false, enabled: false, server: false, tui: false },
// A plugin whose `os` leaves out this system keeps a row that says so, and never loads.
{ id: "windows-only", builtin: false, enabled: true, server: true, unsupported: true },
// A bundle main could not read never reaches the window.
{ id: "garbled", builtin: false, enabled: true, error: "SyntaxError: garbled bundle" },
{ id: "flaky", builtin: false, enabled: true },
]
const listed = (id: string, features: PluginInfo["features"]): PluginInfo => ({
id,
source: { type: "package", target: id },
features,
state: { status: "active" },
})
const bridge: Bridge = {
packaged: false,
call: async () => undefined,
@@ -1110,33 +1124,81 @@ story("Settings > Plugins shows where each part of a plugin from the config is t
manager: {
initial: Promise.resolve(installed),
list: async () => installed,
enable: async () => {},
disable: async () => {},
reload: async () => {},
enable: async (id) => void calls.push(`enable ${id}`),
disable: async (id) => void calls.push(`disable ${id}`),
reload: async (id) => void calls.push(`reload ${id}`),
},
}
const host = mountPlugins({
settings: true,
bridge,
definitions: installed.flatMap((item) =>
item.unsupported ? [] : [{ id: item.id, windowEntry: async () => ({ default: () => {} }) }],
),
const fails = (message: string) => async () => ({
default: () => {
throw new Error(message)
},
})
await until(() => !!host.container.textContent?.includes("cli.json"))
const host = mountPlugins({
bridge,
plugins: [
listed("acme", { gui: true, server: true, tui: true }),
listed("windows-only", { gui: true, server: true }),
listed("flaky", { gui: true }),
// A plugin without a GUI lists its name only.
listed("lint-rules", { server: true }),
// The server's own built-ins are not listed, as on every server.
{ ...listed("opencode-builtin", { server: true }), source: { type: "builtin" } },
],
definitions: [
{ id: "review", windowEntry: async () => ({ default: () => {} }) },
{ id: "terminal", windowEntry: fails("terminal broke") },
{ id: "acme", windowEntry: async () => ({ default: () => {} }) },
{ id: "notes", windowEntry: async () => ({ default: () => {} }) },
{ id: "flaky", windowEntry: fails("flaky broke") },
],
})
await until(() => !!host.container.textContent?.includes("cli.json") && host.status("flaky") === "failed")
return calls
}, fixture)
const settings = page.getByRole("region", { name: "Plugins", exact: true })
await settings.screenshot({ path: info.outputPath("plugin-parts.png") })
const plugins = page.getByTestId("extension-plugins")
await plugins.screenshot({ path: info.outputPath("extension-plugins.png") })
// One row per plugin id, in the server's order, then what only main reports, then failed built-ins.
await expect(plugins.locator(".settings-extension-name")).toHaveText([
"acme",
"windows-only",
"flaky",
"lint-rules",
"notes",
"garbled",
"terminal",
])
// Only plugins from the config tag their other parts, and one note says how to turn those off.
await expect(settings.getByText("Server", { exact: true })).toHaveCount(1)
await expect(settings.getByText("TUI", { exact: true })).toHaveCount(1)
await expect(settings.getByText(/Switches turn off only a plugin's desktop UI/)).toHaveCount(1)
await expect(settings.getByText("Not available on this system.", { exact: true })).toBeVisible()
await expect(plugins.getByText("Server", { exact: true })).toHaveCount(1)
await expect(plugins.getByText("TUI", { exact: true })).toHaveCount(1)
await expect(plugins.getByText(/Switches turn off only a plugin's desktop UI/)).toHaveCount(1)
await expect(plugins.getByText("Not available on this system.", { exact: true })).toBeVisible()
// An error shows its first line; the rest, such as a stack trace, is behind a toggle that a one-line error lacks.
await expect(plugins.getByText("SyntaxError: garbled bundle", { exact: true })).toBeVisible()
await expect(plugins.getByText("Error: flaky broke", { exact: true })).toBeVisible()
await expect(plugins.getByText("Error: terminal broke", { exact: true })).toBeVisible()
await expect(plugins.getByRole("button", { name: "Show details" })).toHaveCount(2)
const flaky = plugins.locator(".settings-extension-row").filter({ hasText: "flaky" })
await flaky.getByRole("button", { name: "Show details" }).press("Enter")
await expect(flaky.locator("pre")).toHaveText(/^Error: flaky broke\s+at /)
await expect(flaky.getByRole("button", { name: "Hide details" })).toHaveAttribute("aria-expanded", "true")
await expect(plugins.getByText("Failed", { exact: true })).toHaveCount(2)
await expect(plugins.getByText("Built-in", { exact: true })).toHaveCount(1)
// A built-in always runs, so it has no switch; the switches carry on and off without a status label.
await expect(settings.getByRole("switch")).toHaveCount(2)
await expect(settings.getByRole("switch", { name: "terminal" })).toHaveCount(0)
await expect(settings.getByText("Active", { exact: true })).toHaveCount(0)
await expect(plugins.getByRole("switch")).toHaveCount(3)
await expect(plugins.getByRole("switch", { name: "terminal" })).toHaveCount(0)
await expect(plugins.getByRole("button", { name: "Reload" })).toHaveCount(4)
await expect(plugins.getByText("Active", { exact: true })).toHaveCount(0)
// The fixture mounts below the story, out of the viewport, so the controls are driven from the keyboard.
await plugins.getByRole("switch", { name: "acme" }).press("Space")
await plugins.getByRole("button", { name: "Reload" }).nth(1).press("Enter")
expect(await calls.jsonValue()).toEqual(["disable acme", "reload flaky"])
})
const invalidSetups = ["promise", "thenable"]
+2 -2
View File
@@ -1,6 +1,6 @@
import type { PluginInfo } from "@opencode/client"
function pluginLabel(plugin: PluginInfo) {
export function pluginLabel(plugin: PluginInfo) {
if (plugin.id) return plugin.id
if (plugin.source.type === "package") return plugin.source.target
@@ -11,5 +11,5 @@ function pluginLabel(plugin: PluginInfo) {
}
export function pluginLabels(plugins: readonly PluginInfo[]) {
return plugins.filter((plugin) => plugin.source.type !== "builtin").map(pluginLabel)
return plugins.flatMap((plugin) => (plugin.source.type === "builtin" ? [] : [pluginLabel(plugin)]))
}
+2 -2
View File
@@ -766,12 +766,12 @@ export const dict = {
"settings.experimental.row.newIcons.description": "Preview the updated icon set",
"settings.experimental.row.newModelPicker.title": "New model picker",
"settings.experimental.row.newModelPicker.description": "Preview the redesigned model picker",
"settings.plugins.title": "Plugins",
"settings.plugins.description": "Built-in plugins and plugins from your OpenCode config",
"settings.plugins.reload": "Reload",
"settings.plugins.status.loading": "Loading",
"settings.plugins.status.failed": "Failed",
"settings.plugins.error.notFound": "Plugin not found",
"settings.plugins.error.show": "Show details",
"settings.plugins.error.hide": "Hide details",
"settings.plugins.builtin": "Built-in",
"settings.plugins.reserved": "Not loaded. A built-in plugin already uses this ID.",
"settings.plugins.unsupported": "Not available on this system.",
@@ -0,0 +1,249 @@
import type { PluginInfo } from "@opencode/client"
import { Predicate } from "effect"
import { createMemo, createSignal, createUniqueId, For, Show } from "solid-js"
import { Badge } from "@opencode/ui/badge"
import { Button } from "@opencode/ui/button"
import { Icon } from "@opencode/ui/icon"
import { Switch } from "@opencode/ui/switch"
import { pluginLabel } from "@/providers/catalog/plugin"
import { useLanguage } from "@/runtime/i18n/language"
import { usePlatform } from "@/runtime/platform/platform"
import { SettingsList } from "@/settings/list"
import { showToast } from "@/shell/notifications/toast"
import "@/settings/settings.css"
import { builtins } from "./builtins"
import { usePluginHost } from "./host"
import { createInstalled } from "./installed"
import { useReservedPlugins } from "./root"
/**
* 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.
*/
export function ExtensionPlugins(props: { plugins: readonly PluginInfo[]; own: boolean }) {
const listed = () => props.plugins.filter((plugin) => plugin.source.type !== "builtin")
return (
<Show
when={props.own}
fallback={
<SettingsList variant="catalog">
<For each={listed()}>
{(plugin) => (
<div class="settings-extension-row">
<div class="settings-extension-lead">
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<span class="settings-extension-name truncate">{pluginLabel(plugin)}</span>
</div>
</div>
)}
</For>
</SettingsList>
}
>
<OwnServerPlugins plugins={listed()} />
</Show>
)
}
/**
* The plugins of the desktop app's own server, merged by id with what main and this window know of their GUIs: a
* 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[] }) {
const language = useLanguage()
const host = usePluginHost()
const bridge = usePlatform().plugins
const installed = createInstalled(bridge)
const reserved = useReservedPlugins()
const builtin = (id: string) => builtins.some((definition) => definition.id === id)
// A server plugin's id can be a built-in's (a reserved id), so each row looks up its own kind of item.
const itemOf = (id: string, kind: "builtin" | "config") =>
installed.list().find((item) => item.id === id && item.builtin === (kind === "builtin"))
const defined = (id: string) => !builtin(id) && host.definitions().some((definition) => definition.id === id)
// What the window knows of a plugin on this server. A plugin without a GUI has nothing besides its name.
const kind = (id: string | undefined) => {
if (!id) return undefined
if (reserved().includes(id)) return "reserved"
const item = itemOf(id, "config")
if (item?.unsupported) return "unsupported"
// A bundle main could not read never reaches the window.
if (item?.error !== undefined && !defined(id)) return "unreadable"
if (item || defined(id)) return "loaded"
return undefined
}
// Plugins main reports that the server list does not name, for example while that list loads or after it failed.
const unnamed = createMemo(() => {
const named = new Set(props.plugins.flatMap((plugin) => (plugin.id ? [plugin.id] : [])))
return [
...new Set([
...host.definitions().flatMap((definition) => (builtin(definition.id) ? [] : [definition.id])),
...installed.list().flatMap((item) => (item.builtin ? [] : [item.id])),
...reserved(),
]),
].filter((id) => !named.has(id))
})
// Why the window entry or main's entry failed; either fails the plugin.
const errorOf = (id: string, kind: "builtin" | "config") => host.state.failures[id]?.error ?? itemOf(id, kind)?.error
const failedBuiltins = createMemo(() =>
host
.definitions()
.flatMap((definition) =>
builtin(definition.id) && errorOf(definition.id, "builtin") !== undefined ? [definition.id] : [],
),
)
// The switch already shows whether a plugin runs; only the states it cannot show get a label.
const status = (id: string, kind: "builtin" | "config") => {
const value = host.state.status[id] ?? "loading"
if (value === "failed" || (value === "active" && itemOf(id, kind)?.error))
return language.t("settings.plugins.status.failed")
if (value === "active" || value === "disabled") return undefined
return language.t("settings.plugins.status.loading")
}
const run = (work: Promise<void> | undefined) =>
void work?.catch((cause: unknown) =>
showToast({
variant: "error",
title:
Predicate.hasProperty(cause, "code") && cause.code === "notFound"
? language.t("settings.plugins.error.notFound")
: language.t("common.requestFailed"),
}),
)
const toggle = (id: string, next: boolean) => run(next ? bridge?.manager.enable(id) : bridge?.manager.disable(id))
// Main entries reload through the manager; the renderer entry reloads here.
const reload = (id: string) => {
host.reload(id)
run(bridge?.manager.reload(id))
}
const row = (input: { id: string | undefined; name: string; builtin?: boolean }) => {
const state = () => (input.builtin ? "loaded" : kind(input.id))
const part = input.builtin ? "builtin" : "config"
const live = () => (state() === "loaded" ? input.id : undefined)
return (
<div class="settings-extension-row">
<div class="settings-extension-lead">
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<div class="flex min-w-0 flex-col gap-0.5">
<div class="settings-provider-main">
<bdi dir="ltr" class="settings-extension-name truncate">
{input.name}
</bdi>
<Show when={live()}>
{(id) => (
<>
<Show when={input.builtin}>
<Badge>{language.t("settings.plugins.builtin")}</Badge>
</Show>
{/* The parts besides the desktop UI that this row's switch leaves running. */}
<Show when={itemOf(id(), part)?.server}>
<Badge>{language.t("settings.plugins.part.server")}</Badge>
</Show>
<Show when={itemOf(id(), part)?.tui}>
<Badge>{language.t("settings.plugins.part.tui")}</Badge>
</Show>
<Show when={status(id(), part)}>
{(label) => <span class="text-11-regular text-v2-text-text-muted">{label()}</span>}
</Show>
</>
)}
</Show>
</div>
<Show when={live()}>
{(id) => <Show when={errorOf(id(), part)}>{(error) => <PluginError error={error()} />}</Show>}
</Show>
<Show when={state() === "unsupported"}>
<span class="text-11-regular text-v2-text-text-muted">{language.t("settings.plugins.unsupported")}</span>
</Show>
<Show when={state() === "unreadable" && input.id && itemOf(input.id, part)?.error}>
{(error) => <PluginError error={error()} />}
</Show>
<Show when={state() === "reserved"}>
<span class="settings-server-dialog-error">{language.t("settings.plugins.reserved")}</span>
</Show>
</div>
</div>
<Show when={live()}>
{(id) => (
<div class="settings-servers-actions">
<Button size="small" variant="ghost" onClick={() => reload(id())}>
{language.t("settings.plugins.reload")}
</Button>
{/* A built-in always runs; it keeps the switch's width, so every Reload lines up. */}
<Show when={!input.builtin} fallback={<span class="w-6 shrink-0" aria-hidden="true" />}>
<Switch hideLabel checked={itemOf(id(), part)?.enabled ?? true} onChange={(next) => toggle(id(), next)}>
{id()}
</Switch>
</Show>
</div>
)}
</Show>
</div>
)
}
return (
<>
<SettingsList variant="catalog">
<For each={props.plugins}>{(plugin) => row({ id: plugin.id, name: pluginLabel(plugin) })}</For>
<For each={unnamed()}>{(id) => row({ id, name: id })}</For>
<For each={failedBuiltins()}>{(id) => row({ id, name: id, builtin: true })}</For>
</SettingsList>
<Show when={installed.list().some((item) => !item.builtin)}>
<p class="text-11-regular text-v2-text-text-muted">{language.t("settings.plugins.parts.note")}</p>
</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()
const id = createUniqueId()
const [open, setOpen] = createSignal(false)
const message = () => props.error.split("\n", 1)[0]
const more = () => props.error.trimEnd().includes("\n")
return (
<div class="flex min-w-0 flex-col items-start gap-1">
<pre id={id} class="settings-server-dialog-error whitespace-pre-wrap">
{open() || !more() ? props.error : message()}
</pre>
<Show when={more()}>
<Button
size="small"
variant="ghost-muted"
class="settings-plugin-error-toggle"
aria-expanded={open()}
aria-controls={id}
onClick={() => setOpen((value) => !value)}
>
{language.t(open() ? "settings.plugins.error.hide" : "settings.plugins.error.show")}
</Button>
</Show>
</div>
)
}
+1 -1
View File
@@ -29,7 +29,7 @@ const modules = {
* Builds a host `Entry` for a plugin's `./gui-experimental` bundle, read from the desktop app's own server. The
* bundle is evaluated here so the host reads its `Plugin.define` declarations (`os`, `stores`, `i18n`) before it
* activates the plugin. A plugin with only a `main` setup gets an empty window setup, so it still lists as active. It
* takes the server plugin's id. A bundle that fails to evaluate becomes an entry that fails, so Settings > Plugins
* takes the server plugin's id. A bundle that fails to evaluate becomes an entry that fails, so Extensions › Plugins
* reports it.
*/
export async function pluginDefinition(id: string, code: string): Promise<Entry> {
+2 -1
View File
@@ -56,7 +56,8 @@ export function PluginRoot(props: ParentProps) {
// The GUIs of the plugins on the app's own server, as main sends them.
const [plugins, setPlugins] = createSignal<readonly PluginGui[]>([])
// Plugins whose GUI cannot load because a built-in claims the id, as main reports them; Settings > Plugins shows them.
// Plugins whose GUI cannot load because a built-in claims the id, as main reports them; Extensions › Plugins shows
// them.
const [reserved, setReserved] = createSignal<readonly string[]>([])
// The same definitions in the same order are no change, so a refetch that found nothing new restarts nothing.
@@ -1,184 +0,0 @@
import { Predicate } from "effect"
import { For, Show } from "solid-js"
import { Badge } from "@opencode/ui/badge"
import { Button } from "@opencode/ui/button"
import { Icon } from "@opencode/ui/icon"
import { Switch } from "@opencode/ui/switch"
import { useLanguage } from "@/runtime/i18n/language"
import { usePlatform } from "@/runtime/platform/platform"
import { SettingsList } from "@/settings/list"
import { showToast } from "@/shell/notifications/toast"
import "@/settings/settings.css"
import { builtins } from "./builtins"
import { usePluginHost } from "./host"
import { createInstalled } from "./installed"
import { useReservedPlugins } from "./root"
/** Every plugin of this desktop window, built-in or from the app's own server, with reload and enable controls. */
export function PluginsSettings() {
const language = useLanguage()
const host = usePluginHost()
const bridge = usePlatform().plugins
const installed = createInstalled(bridge)
const reserved = useReservedPlugins()
const itemOf = (id: string) => installed.list().find((item) => item.id === id)
// Built-ins always run, so they have no switch.
const builtin = (id: string) => builtins.some((definition) => definition.id === id)
const enabled = (id: string) => itemOf(id)?.enabled ?? true
// Plugins main lists that this window does not load: limited to other systems, or a bundle main could not read.
const unloaded = () =>
installed
.list()
.filter(
(item) =>
item.unsupported ||
(!item.builtin &&
item.error !== undefined &&
!host.definitions().some((definition) => definition.id === item.id)),
)
// Why the window entry or main's entry failed; either fails the plugin.
const errorOf = (id: string) => host.state.failures[id]?.error ?? itemOf(id)?.error
// The switch already shows whether a plugin runs; only the states it cannot show get a label.
const status = (id: string) => {
const value = host.state.status[id] ?? "loading"
if (value === "failed" || (value === "active" && itemOf(id)?.error))
return language.t("settings.plugins.status.failed")
if (value === "active" || value === "disabled") return undefined
return language.t("settings.plugins.status.loading")
}
const run = (work: Promise<void> | undefined) =>
void work?.catch((cause: unknown) =>
showToast({
variant: "error",
title:
Predicate.hasProperty(cause, "code") && cause.code === "notFound"
? language.t("settings.plugins.error.notFound")
: language.t("common.requestFailed"),
}),
)
const toggle = (id: string, next: boolean) => run(next ? bridge?.manager.enable(id) : bridge?.manager.disable(id))
// Main entries reload through the manager; the renderer entry reloads here.
const reload = (id: string) => {
host.reload(id)
run(bridge?.manager.reload(id))
}
return (
<>
<div class="settings-tab-header">
<div class="settings-tab-header-row">
<div class="flex flex-col gap-1">
<h2 class="settings-tab-title">{language.t("settings.plugins.title")}</h2>
<span class="text-11-regular text-v2-text-text-muted">{language.t("settings.plugins.description")}</span>
</div>
</div>
</div>
<div class="settings-tab-body settings-tab-body--sectioned">
<section class="settings-section" aria-label={language.t("settings.plugins.title")}>
{/* The rows of the server Extensions tab, with the Providers tab's badges. */}
<SettingsList variant="catalog">
<For each={host.definitions()}>
{(definition) => (
<div class="settings-extension-row">
<div class="settings-extension-lead">
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<div class="flex min-w-0 flex-col gap-0.5">
<div class="settings-provider-main">
<bdi dir="ltr" class="settings-extension-name truncate">
{definition.id}
</bdi>
<Show when={builtin(definition.id)}>
<Badge>{language.t("settings.plugins.builtin")}</Badge>
</Show>
{/* The parts besides the desktop UI that this row's switch leaves running. */}
<Show when={itemOf(definition.id)?.server}>
<Badge>{language.t("settings.plugins.part.server")}</Badge>
</Show>
<Show when={itemOf(definition.id)?.tui}>
<Badge>{language.t("settings.plugins.part.tui")}</Badge>
</Show>
<Show when={status(definition.id)}>
{(label) => <span class="text-11-regular text-v2-text-text-muted">{label()}</span>}
</Show>
</div>
<Show when={errorOf(definition.id)}>
{(error) => <pre class="settings-server-dialog-error whitespace-pre-wrap">{error()}</pre>}
</Show>
</div>
</div>
<div class="settings-servers-actions">
<Button size="small" variant="ghost" onClick={() => reload(definition.id)}>
{language.t("settings.plugins.reload")}
</Button>
{/* A built-in keeps the switch's width, so every Reload lines up. */}
<Show when={!builtin(definition.id)} fallback={<span class="w-6 shrink-0" aria-hidden="true" />}>
<Switch
hideLabel
checked={enabled(definition.id)}
onChange={(next) => toggle(definition.id, next)}
>
{definition.id}
</Switch>
</Show>
</div>
</div>
)}
</For>
<For each={unloaded()}>
{(item) => (
<div class="settings-extension-row">
<div class="settings-extension-lead">
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<div class="flex min-w-0 flex-col gap-0.5">
<bdi dir="ltr" class="settings-extension-name truncate">
{item.id}
</bdi>
<Show
when={item.unsupported}
fallback={<pre class="settings-server-dialog-error whitespace-pre-wrap">{item.error}</pre>}
>
<span class="text-11-regular text-v2-text-text-muted">
{language.t("settings.plugins.unsupported")}
</span>
</Show>
</div>
</div>
</div>
)}
</For>
<For each={reserved()}>
{(id) => (
<div class="settings-extension-row">
<div class="settings-extension-lead">
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<div class="flex min-w-0 flex-col gap-0.5">
<bdi dir="ltr" class="settings-extension-name truncate">
{id}
</bdi>
<span class="settings-server-dialog-error">{language.t("settings.plugins.reserved")}</span>
</div>
</div>
</div>
)}
</For>
</SettingsList>
<Show when={installed.list().some((item) => !item.builtin)}>
<p class="text-11-regular text-v2-text-text-muted">{language.t("settings.plugins.parts.note")}</p>
</Show>
</section>
</div>
</>
)
}
-2
View File
@@ -14,7 +14,6 @@ export const pageIcons = {
extensions: "extensions",
servers: "server",
experimental: "flask",
plugins: "cube",
about: "info",
} as const satisfies Record<SettingsRootTab, IconProps["name"]>
@@ -30,6 +29,5 @@ export const pageLabels = {
extensions: "settings.tab.extensions",
servers: "settings.section.server",
experimental: "settings.tab.experimental",
plugins: "settings.plugins.title",
about: "settings.tab.about",
} as const satisfies Record<SettingsRootTab, Parameters<ReturnType<typeof useLanguage>["t"]>[0]>
@@ -1,3 +1,4 @@
import { Predicate } from "effect"
import { Component, For, Show, createEffect, createMemo, createResource, type JSX } from "solid-js"
import { useDialog } from "@opencode/ui/context/dialog"
import { Icon } from "@opencode/ui/icon"
@@ -8,10 +9,12 @@ import { TruncatedText } from "@opencode/ui/truncated-text"
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 { useMcpToggle } from "@/providers/connect/mcp"
import { DialogMcp } from "@/providers/connect/mcp-dialog"
import { pluginLabels } from "@/providers/catalog/plugin"
import { ExtensionPlugins } from "@/runtime/plugin/extension-plugins"
import { ExternalLink } from "@/runtime/platform/external-link"
import { usePlatform } from "@/runtime/platform/platform"
import { SettingsList } from "@/settings/list"
import type { SettingsView } from "@/settings/surface"
import "@/settings/settings.css"
@@ -24,10 +27,6 @@ const statusLabels = {
disabled: "mcp.status.disabled",
} as const
interface PluginRowItem {
name: string
}
export const SettingsExtensions: Component<{
directory?: string
subtab?: SettingsView["subtab"]
@@ -38,6 +37,7 @@ export const SettingsExtensions: Component<{
const serverSdk = useServerSDK()
const data = useData()
const dialog = useDialog()
const platform = usePlatform()
// MCP connections are per Location, so read and toggle them where the active session runs, as the TUI does. The
// names come from the default Location so this page lists only the servers available to all projects.
const location = () => (props.directory ? { directory: props.directory } : data.location.default())
@@ -74,7 +74,8 @@ export const SettingsExtensions: Component<{
{ initialValue: [] },
)
const plugins = createMemo<PluginRowItem[]>(() => pluginLabels(pluginList.latest ?? []).map((name) => ({ name })))
// 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)
createEffect(() => {
if (serverSdk.connection.status() !== "connected") return
@@ -125,7 +126,7 @@ export const SettingsExtensions: Component<{
const busy = () => {
const target = toggleMcp.isPending ? toggleMcp.variables : undefined
return (typeof target === "string" ? target : target?.name) === item.name
return (Predicate.isString(target) ? target : target?.name) === item.name
}
// The dot shows the status, as in the MCPs dialog; the words stay for assistive technology.
@@ -202,18 +203,7 @@ export const SettingsExtensions: Component<{
{language.t("settings.extensions.manageConfig")}
</span>
</div>
<SettingsList variant="catalog">
<For each={plugins()}>
{(plugin) => (
<div class="settings-extension-row">
<div class="settings-extension-lead">
<Icon name="cube" class="text-v2-icon-icon-muted shrink-0" />
<span class="settings-extension-name truncate">{plugin.name}</span>
</div>
</div>
)}
</For>
</SettingsList>
<ExtensionPlugins plugins={pluginList.latest ?? []} own={own()} />
</div>
</Tabs.Content>
+9
View File
@@ -40,6 +40,15 @@ describe("settings route", () => {
})
})
test("opens links to the desktop's old Plugins page on the Plugins tab of Extensions", () => {
expect(parseSettingsView("?tab=plugins")).toEqual({
type: "root",
tab: "extensions",
server: undefined,
subtab: "plugins",
})
})
test("keeps search reveal state transient", () => {
expect(
parseSettingsView("?server=local&project=%2Fwork&tab=extensions&subtab=plugins", {
+4 -2
View File
@@ -10,7 +10,6 @@ export type SettingsRootTab =
| "extensions"
| "servers"
| "experimental"
| "plugins"
| "about"
declare const pluginTab: unique symbol
@@ -56,7 +55,6 @@ const rootTabs: Record<SettingsRootTab, true> = {
extensions: true,
servers: true,
experimental: true,
plugins: true,
about: true,
}
@@ -91,6 +89,10 @@ export function parseSettingsView(
// Links to a server's own page, which the Servers page replaced, name a server without a tab.
if (!project && server && !params.has("tab")) return { type: "root", tab: "servers", server, ...transient }
// The desktop's Plugins page is now the Plugins tab of Extensions, so links to it and `layout.settings("plugins")`
// land there.
if (!project && tab === "plugins") return { type: "root", tab: "extensions", server, subtab: "plugins", ...transient }
if (!project && isRootTab(tab))
return { type: "root", tab, server, subtab: nested === "lsps" ? undefined : nested, ...transient }
+6 -8
View File
@@ -20,13 +20,6 @@ export const clientSettings: Entry<SettingsRootTab>[] = [
{ tab: "appearance", label: "settings.general.section.appearance" },
{ tab: "notifications", label: "settings.tab.notifications" },
{ tab: "shortcuts", label: "settings.shortcuts.title", keywords: "keybind keyboard hotkey" },
{
tab: "plugins",
label: "settings.plugins.title",
description: "settings.plugins.description",
keywords: "extension gui built-in",
available: "desktop",
},
{ tab: "about", label: "settings.tab.about", keywords: "version license credits" },
{ tab: "experimental", label: "settings.tab.experimental", keywords: "experiments preview beta" },
{ tab: "general", label: "settings.general.row.language.title", target: "settings-language" },
@@ -227,7 +220,12 @@ export const serverSettings: Entry<SettingsServerTab | "servers">[] = [
label: "settings.extensions.tab.mcps",
keywords: "model context protocol tools",
},
{ tab: "extensions", subtab: "plugins", label: "settings.extensions.tab.plugins" },
{
tab: "extensions",
subtab: "plugins",
label: "settings.extensions.tab.plugins",
keywords: "extension gui built-in",
},
{ tab: "extensions", subtab: "skills", label: "settings.extensions.tab.skills" },
{
tab: "servers",
+11
View File
@@ -2157,6 +2157,17 @@
color: var(--v2-text-text-muted);
}
/* A quiet toggle under a plugin's error, its label lined up with the error text above it. */
.settings-plugin-error-toggle[data-component="button-v2"][data-size="small"] {
height: 20px;
margin-inline-start: -5px;
padding-inline: 5px;
font-size: 11px;
font-weight: 440;
line-height: 16px;
letter-spacing: 0.05px;
}
.settings-extension-lead {
display: flex;
flex: 1;
+2 -37
View File
@@ -1,22 +1,8 @@
import { Tabs } from "@opencode/ui/tabs"
import { useDialog } from "@opencode/ui/context/dialog"
import {
createEffect,
createMemo,
For,
lazy,
on,
onCleanup,
onMount,
Show,
Suspense,
Switch,
Match,
type Accessor,
} from "solid-js"
import { createEffect, createMemo, For, on, onCleanup, onMount, Show, Switch, Match, type Accessor } from "solid-js"
import { createStore } from "solid-js/store"
import { useLanguage } from "@/runtime/i18n/language"
import { usePlatform } from "@/runtime/platform/platform"
import { useTabs } from "@/shell/tabs/tabs"
import { useGlobal, useServerCtx } from "@/runtime/server/runtime"
import { ServerConnection } from "@/runtime/server/registry"
@@ -50,10 +36,6 @@ import { revealSettingsSearch } from "./search-reveal"
import { PluginSettingsPages } from "@/runtime/plugin/settings-page-view"
import "@/settings/settings.css"
const PluginsSettings = lazy(() =>
import("@/runtime/plugin/settings-plugins").then((module) => ({ default: module.PluginsSettings })),
)
const rootClientTabs = [
{ value: "general", icon: pageIcons.general, label: "settings.tab.preferences" },
{ value: "appearance", icon: pageIcons.appearance, label: "settings.general.section.appearance" },
@@ -82,8 +64,6 @@ const experimentalTab = [
{ value: "experimental", icon: pageIcons.experimental, label: "settings.tab.experimental" },
] as const
const pluginsTab = [{ value: "plugins", icon: pageIcons.plugins, label: "settings.plugins.title" }] as const
const aboutTab = [{ value: "about", icon: pageIcons.about, label: "settings.tab.about" }] as const
const nestedProjectTabs = [
@@ -246,7 +226,6 @@ function RootSettings() {
const surface = useSettingsSurface()
const global = useGlobal()
const inventory = useSettingsServers()
const platform = usePlatform()
const [state, setState] = createStore<{ worktreeFilterReset: number; modelProvider: string | undefined }>({
worktreeFilterReset: 0,
@@ -264,15 +243,12 @@ function RootSettings() {
const prefetchWorkspaces = useWorkspacesPrefetch(reachable)
const activeDirectory = useSettingsDirectory(reachable)
const showPlugins = platform.platform === "desktop"
createEffect(() => {
const view = surface.view()
if (view.type !== "root") return
if (view.tab === "experimental" && !experimentalSettingsAvailable) surface.open("general")
if (view.tab === "plugins" && !showPlugins) surface.open("general")
})
const selectServer = (server: ServerConnection.Any) => surface.selectServer(ServerConnection.key(server))
@@ -294,10 +270,7 @@ function RootSettings() {
})),
},
{
items: [
...rootClientTabs.map((item) => ({ ...item, label: language.t(item.label) })),
...pluginTabs(),
],
items: [...rootClientTabs.map((item) => ({ ...item, label: language.t(item.label) })), ...pluginTabs()],
},
{
items: [
@@ -311,7 +284,6 @@ function RootSettings() {
...(experimentalSettingsAvailable
? [{ items: experimentalTab.map((item) => ({ ...item, label: language.t(item.label) })) }]
: []),
...(showPlugins ? [{ items: pluginsTab.map((item) => ({ ...item, label: language.t(item.label) })) }] : []),
{
items: [...aboutTab.map((item) => ({ ...item, label: language.t(item.label) })), ...pluginTabs("about")],
},
@@ -346,13 +318,6 @@ function RootSettings() {
<Tabs.Content value="experimental" class="settings-panel">
<SettingsExperimental />
</Tabs.Content>
{showPlugins && (
<Tabs.Content value="plugins" class="settings-panel">
<Suspense>
<PluginsSettings />
</Suspense>
</Tabs.Content>
)}
<Tabs.Content value="about" class="settings-panel settings-about">
<SettingsAbout active={surface.view().tab === "about"} />
</Tabs.Content>
+5 -3
View File
@@ -91,15 +91,17 @@ type ListedPlugin = {
/**
* What main keeps of the plugin listing besides the plugins: the ids a built-in claims, the plugins with a server
* part and those that export `./tui` (Settings › Plugins shows that part's switch), and the follow of the server.
* part and those that export `./tui` (Extensions › Plugins tags those parts), and the follow of the server.
*/
type Inventory = {
reserved: readonly string[]
server: ReadonlySet<string>
tui: ReadonlySet<string>
/** Plugins whose `os` leaves out this system: listed in Settings, never run. */
/** Plugins whose `os` leaves out this system: listed in Extensions › Plugins, never run. */
unsupported: ReadonlySet<string>
/** New plugins whose bundle main could not read, with why: listed in Settings until a listing reads them. */
/**
* New plugins whose bundle main could not read, with why: listed in Extensions › Plugins until a listing reads them.
*/
unreadable: ReadonlyMap<string, string>
/** Aborts the current follow of the app's own server. */
watch?: AbortController
+1 -1
View File
@@ -7,7 +7,7 @@ Built-in features of the desktop and web app, each behind the GUI plugin SDK, `@
- The SDK and the contracts `file`, `review`, `browser` and `updater` live in `packages/plugin/src/gui/`; all but `updater` publish with `@opencode/plugin` as `@opencode/plugin/gui*`. Built-ins, hosts and third-party plugin bundles all import them by that name; this package holds only the built-ins. Three subpaths are workspace-only and never published: `gui/host` (the hosts' protocol), `gui/builtin` (what only built-ins use) and `gui/updater` (the app's own updater contract).
- Keep the public SDK for third-party plugins. API only built-ins use goes in `@opencode/plugin/gui/builtin` (`packages/plugin/src/gui/builtin.ts`), which no public SDK module imports: import `onIdle`, `BuiltinStore`, `BuiltinPanel`, `BuiltinPanelTab`, `BuiltinCommand`, `BuiltinSlot`, `builtinContext`, `builtinMainContext` and `builtinCatalog` from there. Each built-in registry token has the public token's id; the hosts read every item through it.
- Built-ins declare with `Plugin.define` like any plugin, as TUI built-ins do; "built-in" is only the host's flag for what `src/renderer.ts` and `src/main.ts` load. A third-party `./gui-experimental` bundle default-exports one `Plugin.define({ setup?, main?, ...declarations })`. No definition declares an id: the host gives a built-in its key in `compose` and a bundle the server plugin's id, as `ctx.id`. Main alone lists the plugins on the app's own server and sends windows their bundles; both hosts evaluate bundles only through `evaluatePluginBundle` in `@opencode/plugin/gui/host`, which owns the shape checks.
- Every declaration field is declared once, in `Plugin.Declarations` (`packages/plugin/src/gui/declarations.ts`). `Plugin.Definition` adds the setups; the host's `Entry` (`@opencode/plugin/gui/host`) adds the lazy `windowEntry` and `mainEntry`. Every OS check goes through `runsOn`. A plugin from the config whose `os` leaves out this system never runs, and Settings › Plugins keeps its row with "Not available on this system."
- Every declaration field is declared once, in `Plugin.Declarations` (`packages/plugin/src/gui/declarations.ts`). `Plugin.Definition` adds the setups; the host's `Entry` (`@opencode/plugin/gui/host`) adds the lazy `windowEntry` and `mainEntry`. Every OS check goes through `runsOn`. A plugin from the config whose `os` leaves out this system never runs, and Extensions › Plugins keeps its row with "Not available on this system."
- One folder per built-in: `index.ts` (`Plugin.define({ os?, stores?, i18n })`), `contract.ts`, `renderer.tsx`, an optional `main.ts`, and `i18n/<locale>.ts`.
- `src/renderer.ts` and `src/main.ts` are the only files that list the built-ins, each through `compose` from `@opencode/plugin/gui/host`, which attaches the lazy `windowEntry` and `mainEntry`. Main never imports window code.
- Every plugin here ships. Do not add a plugin, fixture or wrapper only to document or demonstrate the SDK; the guide shows shipping code.
+1 -1
View File
@@ -413,7 +413,7 @@ const saved = builtinMainContext(ctx).storage.store("servers", {
- `Storage.remove(key, { from })` reads as `initial` again and never imports `from` again.
- Renaming a built-in that has shipped moves three things: stored keys (`from`), command ids (the keybind rename map in `packages/app/src/settings/keybinds/migration.ts`), and panel keys (`BuiltinPanel.legacy`). Never drop user data. The enable setting starts again under the new id.
A built-in always runs, whatever setting is saved under its id, and Settings › Plugins has no switch for it. For any other plugin, the setting saved under its id wins; with none, the plugin is enabled. A plugin from the config whose `os` leaves out this system never runs; Settings › Plugins keeps its row, without a switch, with "Not available on this system." Both desktop hosts use this rule (`pluginEnabled`). A failed startup snapshot is unknown, so the window waits for the manager list rather than running disabled plugins.
A built-in always runs, whatever setting is saved under its id, so Extensions › Plugins does not list it, unless it failed: then its row shows the error and Reload, without a switch. For any other plugin, the setting saved under its id wins; with none, the plugin is enabled. A plugin from the config whose `os` leaves out this system never runs; Extensions › Plugins keeps its row, without a switch, with "Not available on this system." Both desktop hosts use this rule (`pluginEnabled`). A failed startup snapshot is unknown, so the window waits for the manager list rather than running disabled plugins.
## Runtime rules
+2 -2
View File
@@ -369,7 +369,7 @@ export interface Installed {
readonly server?: boolean
/** A plugin from the config that also exports `./tui`, which `cli.json` turns off; a built-in has no TUI part. */
readonly tui?: boolean
/** A plugin from the config whose `os` leaves out this system: it never runs here, and Settings says so. */
/** A plugin from the config whose `os` leaves out this system: it never runs here; Extensions › Plugins says so. */
readonly unsupported?: boolean
}
@@ -403,7 +403,7 @@ export interface BridgePluginGui {
export interface BridgePluginGuis {
/** The plugins whose GUI loads on this system, after main's id and OS checks. */
readonly plugins: readonly BridgePluginGui[]
/** Plugins whose GUI cannot load because a built-in claims the id; Settings › Plugins reports them. */
/** Plugins whose GUI cannot load because a built-in claims the id; Extensions › Plugins reports them. */
readonly reserved: readonly string[]
}
@@ -226,13 +226,13 @@ vite build --watch
- An installed package's GUI changes only with its version.
- Changing the plugin's `options` in `opencode.json(c)` reloads the plugin.
- `opencode plugin update` replaces a package's GUI once the update finishes.
- [**Settings > Plugins**](/plugins#desktop) lists the plugin with a switch that turns its GUI off. To remove it, remove
it from `opencode.json(c)` or run `opencode plugin remove <package>`.
- [**Settings > Extensions > Plugins**](/plugins#desktop) lists the plugin with a switch that turns its GUI off. To
remove it, remove it from `opencode.json(c)` or run `opencode plugin remove <package>`.
<Callout type="note">
The app's own plugins reserve their ids. If your plugin's id is one of them, nests under one with a `.`, has one
nested under it, or is in the `opencode` namespace, its GUI does not load, and **Settings > Plugins** lists it as not
loaded.
nested under it, or is in the `opencode` namespace, its GUI does not load, and **Settings > Extensions > Plugins**
lists it as not loaded.
</Callout>
## Define the GUI plugin
@@ -260,7 +260,7 @@ export const definition = Plugin.define({
server part (the directory name for a local directory without a `name`). It prefixes every id the plugin creates: commands (`<id>.<command>`), panel keys (`<id>:<tab>`), stored
keys (`plugin.<id>.<key>`), and the ids of the [contracts and Ipcs](#contracts-and-tokens) it provides.
- `os` limits the plugin to some operating systems. Omit it to run on every OS. A plugin whose `os` leaves out this
system does not run, and **Settings > Plugins** keeps its row with "Not available on this system."
system does not run, and **Settings > Extensions > Plugins** keeps its row with "Not available on this system."
- `stores` declares [stored state](#stored-state) for windows. Read it as `ctx.stores.<key>`.
- `i18n` holds copy by locale. Write every locale inline; English fills every key a locale lacks. Read it with
`ctx.t(key, params)` and `ctx.plural(key, count)`. In a window, `ctx.t` also reads the app's shared keys, such as `common.*`. In `main`, a missing key returns the key.
+3 -2
View File
@@ -141,8 +141,9 @@ plugins from the server it runs, so configure the plugin in your global `opencod
}
```
**Settings > Plugins** lists them. A plugin's switch turns off only its desktop UI, and **Reload** loads it again
after a failure. To turn off the whole plugin, add `-` and its ID to `plugins`, for example `"-acme"`.
**Settings > Extensions > Plugins** lists them when the app's own server is selected. A plugin's switch turns off only
its desktop UI, and **Reload** loads it again after a failure. To turn off the whole plugin, add `-` and its ID to
`plugins`, for example `"-acme"`.
## Terminal