From 5792c3e63b82add26b5eb562ec0ffa6d6f340959 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:39:18 +1000 Subject: [PATCH] =?UTF-8?q?feat(app):=20manage=20desktop=20plugins=20in=20?= =?UTF-8?q?Extensions=20=E2=80=BA=20Plugins=20(#59489)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component-tests/plugin-host.fixture.tsx | 16 +- .../app/component-tests/plugin-host.spec.ts | 106 ++++++-- packages/app/src/providers/catalog/plugin.ts | 4 +- packages/app/src/runtime/i18n/en.ts | 4 +- .../src/runtime/plugin/extension-plugins.tsx | 249 ++++++++++++++++++ packages/app/src/runtime/plugin/module.ts | 2 +- packages/app/src/runtime/plugin/root.tsx | 3 +- .../src/runtime/plugin/settings-plugins.tsx | 184 ------------- packages/app/src/settings/pages.ts | 2 - .../app/src/settings/providers/extensions.tsx | 28 +- packages/app/src/settings/route.test.ts | 9 + packages/app/src/settings/route.ts | 6 +- packages/app/src/settings/search-catalog.ts | 14 +- packages/app/src/settings/settings.css | 11 + packages/app/src/settings/shell.tsx | 39 +-- packages/desktop/src/main/plugin/host.ts | 8 +- packages/gui-plugins/AGENTS.md | 2 +- packages/gui-plugins/README.md | 2 +- packages/plugin/src/gui/host.ts | 4 +- .../docs/content/build/plugins/gui/index.mdx | 10 +- services/www/src/docs/content/plugins.mdx | 5 +- 21 files changed, 408 insertions(+), 300 deletions(-) create mode 100644 packages/app/src/runtime/plugin/extension-plugins.tsx delete mode 100644 packages/app/src/runtime/plugin/settings-plugins.tsx diff --git a/packages/app/component-tests/plugin-host.fixture.tsx b/packages/app/component-tests/plugin-host.fixture.tsx index 8481c577006..89b01f80c26 100644 --- a/packages/app/component-tests/plugin-host.fixture.tsx +++ b/packages/app/component-tests/plugin-host.fixture.tsx @@ -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[0] stored?: Readonly> - /** 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 | undefined }) { @@ -310,8 +310,12 @@ export function mountPlugins(input: { return ( - - + + {(plugins) => ( +
+ +
+ )}
diff --git a/packages/app/component-tests/plugin-host.spec.ts b/packages/app/component-tests/plugin-host.spec.ts index 9d78fac942f..b838eb9bb02 100644 --- a/packages/app/component-tests/plugin-host.spec.ts +++ b/packages/app/component-tests/plugin-host.spec.ts @@ -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"] diff --git a/packages/app/src/providers/catalog/plugin.ts b/packages/app/src/providers/catalog/plugin.ts index 6613aeb7323..d4c20fc8197 100644 --- a/packages/app/src/providers/catalog/plugin.ts +++ b/packages/app/src/providers/catalog/plugin.ts @@ -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)])) } diff --git a/packages/app/src/runtime/i18n/en.ts b/packages/app/src/runtime/i18n/en.ts index 4bd17777af0..5d6946bf807 100644 --- a/packages/app/src/runtime/i18n/en.ts +++ b/packages/app/src/runtime/i18n/en.ts @@ -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.", diff --git a/packages/app/src/runtime/plugin/extension-plugins.tsx b/packages/app/src/runtime/plugin/extension-plugins.tsx new file mode 100644 index 00000000000..93250fcc3c2 --- /dev/null +++ b/packages/app/src/runtime/plugin/extension-plugins.tsx @@ -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 ( + + + {(plugin) => ( +
+
+ + {pluginLabel(plugin)} +
+
+ )} +
+ + } + > + +
+ ) +} + +/** + * 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 | 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 ( +
+
+ +
+
+ + {input.name} + + + {(id) => ( + <> + + {language.t("settings.plugins.builtin")} + + {/* The parts besides the desktop UI that this row's switch leaves running. */} + + {language.t("settings.plugins.part.server")} + + + {language.t("settings.plugins.part.tui")} + + + {(label) => {label()}} + + + )} + +
+ + {(id) => {(error) => }} + + + {language.t("settings.plugins.unsupported")} + + + {(error) => } + + + {language.t("settings.plugins.reserved")} + +
+
+ + {(id) => ( +
+ + {/* A built-in always runs; it keeps the switch's width, so every Reload lines up. */} + +
+ )} +
+
+ ) + } + + return ( + <> + + {(plugin) => row({ id: plugin.id, name: pluginLabel(plugin) })} + {(id) => row({ id, name: id })} + {(id) => row({ id, name: id, builtin: true })} + + !item.builtin)}> +

{language.t("settings.plugins.parts.note")}

+
+ + ) +} + +/** 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 ( +
+
+        {open() || !more() ? props.error : message()}
+      
+ + + +
+ ) +} diff --git a/packages/app/src/runtime/plugin/module.ts b/packages/app/src/runtime/plugin/module.ts index 9ecd633b614..2fdadcdccb1 100644 --- a/packages/app/src/runtime/plugin/module.ts +++ b/packages/app/src/runtime/plugin/module.ts @@ -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 { diff --git a/packages/app/src/runtime/plugin/root.tsx b/packages/app/src/runtime/plugin/root.tsx index 219e0afe166..f42076976c5 100644 --- a/packages/app/src/runtime/plugin/root.tsx +++ b/packages/app/src/runtime/plugin/root.tsx @@ -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([]) - // 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([]) // The same definitions in the same order are no change, so a refetch that found nothing new restarts nothing. diff --git a/packages/app/src/runtime/plugin/settings-plugins.tsx b/packages/app/src/runtime/plugin/settings-plugins.tsx deleted file mode 100644 index 026c897452f..00000000000 --- a/packages/app/src/runtime/plugin/settings-plugins.tsx +++ /dev/null @@ -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 | 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 ( - <> -
-
-
-

{language.t("settings.plugins.title")}

- {language.t("settings.plugins.description")} -
-
-
-
-
- {/* The rows of the server Extensions tab, with the Providers tab's badges. */} - - - {(definition) => ( -
-
- -
-
- - {definition.id} - - - {language.t("settings.plugins.builtin")} - - {/* The parts besides the desktop UI that this row's switch leaves running. */} - - {language.t("settings.plugins.part.server")} - - - {language.t("settings.plugins.part.tui")} - - - {(label) => {label()}} - -
- - {(error) =>
{error()}
} -
-
-
-
- - {/* A built-in keeps the switch's width, so every Reload lines up. */} - -
-
- )} -
- - {(item) => ( -
-
- -
- - {item.id} - - {item.error}} - > - - {language.t("settings.plugins.unsupported")} - - -
-
-
- )} -
- - {(id) => ( -
-
- -
- - {id} - - {language.t("settings.plugins.reserved")} -
-
-
- )} -
-
- !item.builtin)}> -

{language.t("settings.plugins.parts.note")}

-
-
-
- - ) -} diff --git a/packages/app/src/settings/pages.ts b/packages/app/src/settings/pages.ts index 7cb9f2767f6..2aad8a9812f 100644 --- a/packages/app/src/settings/pages.ts +++ b/packages/app/src/settings/pages.ts @@ -14,7 +14,6 @@ export const pageIcons = { extensions: "extensions", servers: "server", experimental: "flask", - plugins: "cube", about: "info", } as const satisfies Record @@ -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["t"]>[0]> diff --git a/packages/app/src/settings/providers/extensions.tsx b/packages/app/src/settings/providers/extensions.tsx index 33e827fec62..cc85893b8e2 100644 --- a/packages/app/src/settings/providers/extensions.tsx +++ b/packages/app/src/settings/providers/extensions.tsx @@ -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(() => 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")} - - - {(plugin) => ( -
-
- - {plugin.name} -
-
- )} -
-
+ diff --git a/packages/app/src/settings/route.test.ts b/packages/app/src/settings/route.test.ts index 399598e01f8..ac3d4fb9f01 100644 --- a/packages/app/src/settings/route.test.ts +++ b/packages/app/src/settings/route.test.ts @@ -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", { diff --git a/packages/app/src/settings/route.ts b/packages/app/src/settings/route.ts index 444c1c94896..bb5c4b45e8c 100644 --- a/packages/app/src/settings/route.ts +++ b/packages/app/src/settings/route.ts @@ -10,7 +10,6 @@ export type SettingsRootTab = | "extensions" | "servers" | "experimental" - | "plugins" | "about" declare const pluginTab: unique symbol @@ -56,7 +55,6 @@ const rootTabs: Record = { 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 } diff --git a/packages/app/src/settings/search-catalog.ts b/packages/app/src/settings/search-catalog.ts index 2e5922589cd..c58dd1d67f0 100644 --- a/packages/app/src/settings/search-catalog.ts +++ b/packages/app/src/settings/search-catalog.ts @@ -20,13 +20,6 @@ export const clientSettings: Entry[] = [ { 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[] = [ 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", diff --git a/packages/app/src/settings/settings.css b/packages/app/src/settings/settings.css index 0e1ce4dbfd6..8fffd4c8f5e 100644 --- a/packages/app/src/settings/settings.css +++ b/packages/app/src/settings/settings.css @@ -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; diff --git a/packages/app/src/settings/shell.tsx b/packages/app/src/settings/shell.tsx index 1fc1f68ad0d..c7f68832bc9 100644 --- a/packages/app/src/settings/shell.tsx +++ b/packages/app/src/settings/shell.tsx @@ -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() { - {showPlugins && ( - - - - - - )} diff --git a/packages/desktop/src/main/plugin/host.ts b/packages/desktop/src/main/plugin/host.ts index 189dbabe7a3..bd358d66161 100644 --- a/packages/desktop/src/main/plugin/host.ts +++ b/packages/desktop/src/main/plugin/host.ts @@ -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 tui: ReadonlySet - /** 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 - /** 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 /** Aborts the current follow of the app's own server. */ watch?: AbortController diff --git a/packages/gui-plugins/AGENTS.md b/packages/gui-plugins/AGENTS.md index 5cc58aef89c..43301cb7461 100644 --- a/packages/gui-plugins/AGENTS.md +++ b/packages/gui-plugins/AGENTS.md @@ -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/.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. diff --git a/packages/gui-plugins/README.md b/packages/gui-plugins/README.md index 8578e5ae214..0566758d792 100644 --- a/packages/gui-plugins/README.md +++ b/packages/gui-plugins/README.md @@ -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 diff --git a/packages/plugin/src/gui/host.ts b/packages/plugin/src/gui/host.ts index b937c9cfd69..b77fb4a7936 100644 --- a/packages/plugin/src/gui/host.ts +++ b/packages/plugin/src/gui/host.ts @@ -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[] } diff --git a/services/www/src/docs/content/build/plugins/gui/index.mdx b/services/www/src/docs/content/build/plugins/gui/index.mdx index 87b9344e8a3..2c2a391bdb5 100644 --- a/services/www/src/docs/content/build/plugins/gui/index.mdx +++ b/services/www/src/docs/content/build/plugins/gui/index.mdx @@ -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 `. +- [**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 `. 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. ## 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 (`.`), panel keys (`:`), stored keys (`plugin..`), 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.`. - `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. diff --git a/services/www/src/docs/content/plugins.mdx b/services/www/src/docs/content/plugins.mdx index 240fa84ca07..d3c96ff30a3 100644 --- a/services/www/src/docs/content/plugins.mdx +++ b/services/www/src/docs/content/plugins.mdx @@ -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