diff --git a/docs/webui.md b/docs/webui.md index 88a00061d..4ae419ef4 100644 --- a/docs/webui.md +++ b/docs/webui.md @@ -235,12 +235,14 @@ Test a new channel with a private DM. When a supported channel sends a pairing c ## Apps -**Apps → Ready** lists capabilities available for use: +**Apps → Ready** lists capabilities available for use. Use the **CLI Apps**, **Agent Plugins**, and **MCP** filters to manage each kind separately: - **Agent Plugins** are local packages that can bundle skills, MCP servers, or both. A package under `/plugins/` is installed but remains inactive until you enable it in Apps. - **CLI Apps** are command-line tool adapters on the nanobot host. Install and enable an adapter before attaching it to a turn. - **MCP** lists Model Context Protocol servers. Presets provide known configurations, and the **Add MCP server** panel accepts stdio, HTTP, and SSE servers. Custom HTTP/SSE servers can use no authentication, OAuth, or request headers. After saving an OAuth server, choose **Connect** to open its sign-in page. Presets such as Xmind, Notion, and Linear already use OAuth. HTTPS and localhost WebUIs return automatically; a remote plain-HTTP WebUI shows one field for pasting the complete localhost callback URL. +A plugin generated by a CLI App is managed from that app's entry, including re-enabling it if needed. Other Agent Plugins appear in the **Agent Plugins** filter. Plugin details show declared permissions and MCP servers; declared permissions do not sandbox a plugin from nanobot's operating-system permissions. + CLI Apps run with a limited environment that excludes provider API keys. On Unix, they inherit `XDG_RUNTIME_DIR` when it is set in the gateway's environment, so desktop CLIs such as Obsidian can locate the running application. Start the gateway in the same desktop session as the app to inherit that runtime directory. Manage optional runtime support from **System**, **Models**, or **Web**, or use [`nanobot plugins`](./cli-reference.md#optional-features). That command manages runtime extras, not Agent Plugin packages. PDF and common Office attachment readers require no setup. diff --git a/nanobot/apps/cli/service.py b/nanobot/apps/cli/service.py index 13b637f4a..6656a0060 100644 --- a/nanobot/apps/cli/service.py +++ b/nanobot/apps/cli/service.py @@ -457,6 +457,13 @@ class CliAppManager: """Return registry names explicitly installed through CLI Apps.""" return sorted(str(name) for name in self._load_installed()) + def managed_plugin_owners(self) -> dict[Path, str]: + """Map the plugin directories managed by installed CLI Apps to their owners.""" + return { + (self.workspace / _plugin_skill_relative_path(name)).parents[2].resolve(): name + for name in self.installed_names() + } + def installed_skill_aliases(self) -> dict[str, str]: """Map pre-plugin CLI App skill names to their portable identities.""" aliases: dict[str, str] = {} diff --git a/nanobot/webui/mcp_presets_api.py b/nanobot/webui/mcp_presets_api.py index ed122efcf..7729703f8 100644 --- a/nanobot/webui/mcp_presets_api.py +++ b/nanobot/webui/mcp_presets_api.py @@ -23,6 +23,7 @@ from nanobot.agent.tools.mcp_oauth import ( mcp_oauth_has_credentials, ) from nanobot.agent.tools.registry import ToolRegistry +from nanobot.apps.cli import CliAppManager from nanobot.apps.protocol import app_manifest, compact_dict from nanobot.config.loader import load_config, resolve_config_env_vars, save_config from nanobot.config.network import NetworkConfig @@ -600,8 +601,9 @@ def mcp_presets_payload( if name not in known ] existing_names = {str(row["name"]) for row in (*preset_rows, *custom_rows)} - plugin_rows = [ - _agent_plugin_payload(plugin) + managed_plugins = CliAppManager(workspace=config.workspace_path).managed_plugin_owners() + plugin_rows: list[dict[str, Any]] = [ + _agent_plugin_payload(plugin) | {"managed_by_cli": managed_plugins.get(plugin.root)} for plugin in discover_agent_plugins(config.workspace_path) if f"plugin-{plugin.name}" not in existing_names ] diff --git a/tests/webui/test_mcp_presets_api.py b/tests/webui/test_mcp_presets_api.py index dd5d0c634..4f73db776 100644 --- a/tests/webui/test_mcp_presets_api.py +++ b/tests/webui/test_mcp_presets_api.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio import json +import sys from functools import partial from pathlib import Path @@ -10,6 +11,7 @@ from mcp.shared.auth import OAuthToken from nanobot.agent.plugins import AGENT_PLUGIN_MCP_SCHEMA, AGENT_PLUGIN_SCHEMA from nanobot.agent.tools.mcp_oauth import MCPOAuthStorage, mcp_oauth_has_credentials +from nanobot.apps.cli import CliAppManager from nanobot.config.loader import load_config, save_config from nanobot.config.schema import Config from nanobot.webui.mcp_presets_api import ( @@ -162,6 +164,33 @@ def test_agent_plugin_reuses_mcp_catalog_and_runtime_action( assert len(rows) == 1 and rows[0]["source"] == "custom" +def test_cli_installer_exposes_managed_plugin_owner_without_claiming_other_plugins( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, +) -> None: + _use_config(tmp_path, monkeypatch) + workspace = load_config().workspace_path + manager = CliAppManager(workspace=workspace) + app = {"name": "example", "display_name": "Example", "package_manager": "bundled", "entry_point": sys.executable} + monkeypatch.setattr(CliAppManager, "get_app", lambda self, name, **kwargs: app) + monkeypatch.setattr(CliAppManager, "payload", lambda self, **kwargs: {}) + monkeypatch.setattr(CliAppManager, "_fetch_skill_content", lambda self, app: None) + manager.install("example") + + unrelated = workspace / "plugins" / "cli-app-unrelated" + unrelated.mkdir(parents=True) + (unrelated / "plugin.json").write_text(json.dumps({ + "$schema": AGENT_PLUGIN_SCHEMA, "name": "cli-app-unrelated", "description": "A separate plugin", + }), encoding="utf-8") + + rows = {item["name"]: item for item in mcp_presets_payload()["presets"] if item["source"] == "agent-plugin"} + assert rows["plugin-cli-app-example"]["managed_by_cli"] == "example" + assert rows["plugin-cli-app-unrelated"]["managed_by_cli"] is None + + manager.uninstall("example") + names = {item["name"] for item in mcp_presets_payload()["presets"] if item["source"] == "agent-plugin"} + assert names == {"plugin-cli-app-unrelated"} + + @pytest.mark.asyncio async def test_oauth_preset_is_one_click_configured_after_token_storage( tmp_path, diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index 9f7e9803a..10a5e0e21 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -209,7 +209,7 @@ async function loadFixture() { const fixture = await loadFixture(); await initializeI18n(); if (fixtureCase === "activity-wheel") await setAppLanguage("zh-CN"); -if ((["appearance", "session-transition"].includes(fixtureCase ?? "") || historyPreview) && parameters.has("lang")) { +if ((["appearance", "session-transition", "tools-catalog"].includes(fixtureCase ?? "") || historyPreview) && parameters.has("lang")) { await setAppLanguage(normalizeLocale(parameters.get("lang"))); } createRoot(document.getElementById("root")!).render({fixture}); diff --git a/webui/browser/tools-catalog.spec.ts b/webui/browser/tools-catalog.spec.ts index 357f20e40..c620f8df9 100644 --- a/webui/browser/tools-catalog.spec.ts +++ b/webui/browser/tools-catalog.spec.ts @@ -28,24 +28,75 @@ test("settings reentry reuses tools immediately and refreshes expired catalogs w await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible(); await expect(page.getByRole("button", { name: "Ready", exact: true })).toHaveAttribute("aria-pressed", "true"); await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toHaveCount(0); - await page.getByRole("button", { name: "Apps", exact: true }).click(); + await page.getByRole("button", { name: "CLI Apps", exact: true }).click(); + await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible(); + await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toHaveCount(0); + await page.getByRole("button", { name: "Agent Plugins", exact: true }).click(); await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toBeVisible(); + await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toHaveCount(0); await page.getByRole("button", { name: "Leave settings", exact: true }).click(); await page.getByRole("button", { name: "Open settings", exact: true }).click(); - await page.getByRole("button", { name: "Apps", exact: true }).click(); - await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible(); + await page.getByRole("button", { name: "Agent Plugins", exact: true }).click(); await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toBeVisible(); expect(counts).toEqual({ cli: 1, mcp: 1 }); await page.getByRole("button", { name: "Leave settings", exact: true }).click(); refresh = true; await page.clock.setFixedTime(new Date(Date.now() + 31_000)); await page.getByRole("button", { name: "Open settings", exact: true }).click(); - await page.getByRole("button", { name: "Apps", exact: true }).click(); + await page.getByRole("button", { name: "Agent Plugins", exact: true }).click(); await expect.poll(() => counts).toEqual({ cli: 2, mcp: 2 }); - await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible(); await expect(page.getByRole("heading", { name: "Fixture plugin", exact: true })).toBeVisible(); await expect(page.getByRole("status", { name: "Loading apps…", exact: true })).toHaveCount(0); release(); - await expect(page.getByRole("heading", { name: "Updated CLI", exact: true })).toBeVisible(); await expect(page.getByRole("heading", { name: "Updated plugin", exact: true })).toBeVisible(); + await page.getByRole("button", { name: "CLI Apps", exact: true }).click(); + await expect(page.getByRole("heading", { name: "Updated CLI", exact: true })).toBeVisible(); +}); + + +test("shows all category labels on narrow screens in each locale", async ({ page }) => { + await page.setViewportSize({ width: 320, height: 800 }); + await page.route("**/api/settings/cli-apps", route => route.fulfill({ json: { apps: [], installed_count: 0 } })); + await page.route("**/api/settings/mcp-presets", route => route.fulfill({ json: { presets: [], installed_count: 0 } })); + for (const locale of ["en", "es", "fr", "id", "ja", "ko", "pt-BR", "vi", "zh-CN", "zh-TW"]) { + await page.goto(`/browser/fixture.html?case=tools-catalog&lang=${locale}`); + const control = page.locator(".segmented-control").filter({ has: page.getByRole("button", { name: "CLI Apps", exact: true }) }); + await expect(control).toBeVisible(); + const geometry = await control.evaluate(element => { + const bounds = element.getBoundingClientRect(); + return { + left: bounds.left, + right: bounds.right, + buttons: Array.from(element.querySelectorAll("button"), button => ({ + text: button.textContent, + fits: button.scrollWidth <= button.clientWidth, + })), + }; + }); + expect(geometry.left, locale).toBeGreaterThanOrEqual(0); + expect(geometry.right, locale).toBeLessThanOrEqual(320); + expect(geometry.buttons, locale).toHaveLength(4); + expect(geometry.buttons.every(button => button.fits), locale).toBe(true); + } +}); + + +test("opens the generated plugin from its CLI app", async ({ page }) => { + await page.route("**/api/settings/cli-apps", route => route.fulfill({ json: { apps: [{ + name: "fixture-cli", display_name: "Fixture CLI", category: "tools", description: "Fixture app", + requires: "", source: "catalog", entry_point: "fixture-cli", install_supported: true, + installed: true, available: true, status: "installed", skill_installed: true, + }], installed_count: 1 } })); + await page.route("**/api/settings/mcp-presets", route => route.fulfill({ json: { presets: [{ + name: "plugin-cli-app-fixture-cli", display_name: "Generated plugin", category: "Plugin", + description: "Generated skill", requires: "", transport: "stdio", source: "agent-plugin", + managed_by_cli: "fixture-cli", install_supported: false, installed: true, configured: true, + enabled: true, available: true, status: "enabled", required_fields: [], docs_url: "", note: "", connection_summary: "", + }], installed_count: 1 } })); + await page.goto("/browser/fixture.html?case=tools-catalog"); + await expect(page.getByRole("heading", { name: "Fixture CLI", exact: true })).toBeVisible(); + await page.getByRole("button", { name: "App ready", exact: true }).click(); + await page.getByRole("menuitem", { name: "Agent Plugin", exact: true }).click(); + await expect(page.getByRole("dialog", { name: "Generated plugin" })).toBeVisible(); + await expect(page.getByRole("dialog").getByRole("button", { name: "Disable" })).toBeVisible(); }); diff --git a/webui/src/components/settings/system/AgentPluginDialog.tsx b/webui/src/components/settings/system/AgentPluginDialog.tsx new file mode 100644 index 000000000..a99237194 --- /dev/null +++ b/webui/src/components/settings/system/AgentPluginDialog.tsx @@ -0,0 +1,63 @@ +import { ExternalLink, Loader2 } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +import { Button } from "@/components/ui/button"; +import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog"; +import type { McpPresetInfo } from "@/lib/types"; + +export function AgentPluginDialog({ + plugin, + open, + actionKey, + onOpenChange, + onAction, +}: { + plugin: McpPresetInfo; + open: boolean; + actionKey: string | null; + onOpenChange: (open: boolean) => void; + onAction: (action: "enable" | "disable", name: string) => void; +}) { + const { t } = useTranslation(); + const enabled = Boolean(plugin.enabled); + const action = enabled ? "disable" : "enable"; + const busy = actionKey === `${action}:${plugin.name}`; + + return ( + + +
+ {plugin.display_name} + {plugin.description} +
+
+

{t(enabled ? "settings.values.enabled" : "settings.values.disabled")}

+ {plugin.requires ? ( +
+

{t("settings.apps.pluginPermissions")}

+

{plugin.requires}

+
+ ) : null} + {plugin.connection_summary ? ( +
+

{t("settings.apps.pluginServers")}

+

{plugin.connection_summary}

+
+ ) : null} +

{t("settings.apps.pluginTrustNotice")}

+ {plugin.docs_url ? ( + + {t("settings.mcp.openDocs")} + + ) : null} +
+
+ +
+
+
+ ); +} diff --git a/webui/src/components/settings/system/AppsSettings.tsx b/webui/src/components/settings/system/AppsSettings.tsx index 6eed8154d..ba5f30ba0 100644 --- a/webui/src/components/settings/system/AppsSettings.tsx +++ b/webui/src/components/settings/system/AppsSettings.tsx @@ -41,6 +41,7 @@ import { SETTINGS_SEARCH_INPUT_CLASS, SettingsSectionTitle, } from "@/components/settings/shared/SettingsControls"; +import { AgentPluginDialog } from "@/components/settings/system/AgentPluginDialog"; import { McpManagementDialog, type McpManagementTab, @@ -67,7 +68,7 @@ import type { } from "@/lib/types"; import { cn } from "@/lib/utils"; -export type AppsKindFilter = "ready" | "cli" | "mcp"; +export type AppsKindFilter = "ready" | "cli" | "plugins" | "mcp"; type AppsCatalogItem = | { id: string; kind: "cli"; app: CliAppInfo } | { id: string; kind: "mcp"; preset: McpPresetInfo }; @@ -216,24 +217,31 @@ export function AppsCatalogSettings({ const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); const filterOptions = [ { value: "ready", label: tx("settings.apps.filterAll", "Ready") }, - { value: "cli", label: tx("settings.apps.filterCli", "Apps") }, + { value: "cli", label: tx("settings.apps.filterCli", "CLI Apps") }, + { value: "plugins", label: tx("settings.apps.filterPlugins", "Plugins") }, { value: "mcp", label: tx("settings.apps.filterMcp", "MCP") }, ]; const normalizedQuery = query.trim().toLowerCase(); + const installedCliNames = new Set((cliApps?.apps ?? []).filter((app) => app.installed).map((app) => app.name)); + const managedPlugins = new Map( + (mcpPresets?.presets ?? []) + .filter((preset) => preset.source === "agent-plugin" && preset.managed_by_cli) + .map((preset) => [preset.managed_by_cli!, preset]), + ); const items: AppsCatalogItem[] = [ ...(cliApps?.apps ?? []).map((app) => ({ id: `cli:${app.name}`, kind: "cli" as const, app })), - ...(mcpPresets?.presets ?? []).map((preset) => ({ - id: `mcp:${preset.name}`, - kind: "mcp" as const, - preset, - })), + ...(mcpPresets?.presets ?? []) + .filter((preset) => !preset.managed_by_cli || !installedCliNames.has(preset.managed_by_cli)) + .map((preset) => ({ id: `mcp:${preset.name}`, kind: "mcp" as const, preset })), ] .filter((item) => { const matchesFilter = filter === "ready" ? appsReady(item) : filter === "cli" - ? item.kind === "cli" || item.preset.source === "agent-plugin" - : item.kind === "mcp" && item.preset.source !== "agent-plugin"; + ? item.kind === "cli" + : filter === "plugins" + ? item.kind === "mcp" && item.preset.source === "agent-plugin" + : item.kind === "mcp" && item.preset.source !== "agent-plugin"; return matchesFilter && (!normalizedQuery || appsSearchText(item).includes(normalizedQuery)); }) .sort((left, right) => { @@ -250,10 +258,12 @@ export function AppsCatalogSettings({ ? tx("settings.apps.empty", "No tools match your search.") : filter === "cli" ? tx("settings.apps.emptyApps", "No apps available.") - : filter === "mcp" - ? tx("settings.apps.emptyIntegrations", "No MCP tools available.") - : tx("settings.apps.emptyReady", "No tools are ready yet."); - const emptyBrowseTarget: AppsKindFilter | null = normalizedQuery + : filter === "plugins" + ? tx("settings.apps.emptyPlugins", "No Agent Plugins installed.") + : filter === "mcp" + ? tx("settings.apps.emptyIntegrations", "No MCP tools available.") + : tx("settings.apps.emptyReady", "No tools are ready yet."); + const emptyBrowseTarget: AppsKindFilter | null = normalizedQuery || filter === "plugins" ? null : filter === "cli" ? "mcp" @@ -296,6 +306,7 @@ export function AppsCatalogSettings({ value={filter} options={filterOptions} onChange={(value) => onFilterChange(value as AppsKindFilter)} + className="max-[480px]:grid max-[480px]:w-full max-[480px]:grid-cols-2 max-[480px]:rounded-2xl" /> @@ -325,7 +336,9 @@ export function AppsCatalogSettings({ {filter === "mcp" ? tx("settings.apps.mcpTools", "MCP tools") - : tx("settings.apps.featured", "Tools")} + : filter === "plugins" + ? tx("settings.apps.filterPlugins", "Plugins") + : tx("settings.apps.featured", "Tools")} {loading ? "—" : items.length} @@ -338,9 +351,12 @@ export function AppsCatalogSettings({ ) : ( ) : (

- {tx( - "settings.apps.emptyIntegrationsHint", - "Add a custom MCP server below.", - )} + {filter === "plugins" + ? tx("settings.apps.emptyPluginsHint", "Add a plugin to the workspace plugins directory to enable it here.") + : tx("settings.apps.emptyIntegrationsHint", "Add a custom MCP server below.")}

)} @@ -427,16 +442,23 @@ export function AppsCatalogSettings({ function CliAppsCatalogRow({ app, + plugin, actionKey, + pluginActionKey, showBrandLogos, onAction, + onPluginAction, }: { app: CliAppInfo; + plugin?: McpPresetInfo; actionKey: string | null; + pluginActionKey: string | null; showBrandLogos: boolean; onAction: (action: "install" | "update" | "uninstall" | "test", name: string) => void; + onPluginAction: (action: "enable" | "disable", name: string) => void; }) { const { t } = useTranslation(); + const [pluginOpen, setPluginOpen] = useState(false); const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback }); const installBusy = actionKey === `install:${app.name}`; const updateBusy = actionKey === `update:${app.name}`; @@ -454,6 +476,11 @@ function CliAppsCatalogRow({ {tx("settings.apps.cliLabel", "App")}

{description}

+ {plugin?.enabled === false ? ( + + ) : null}
{app.installed ? ( @@ -470,6 +497,12 @@ function CliAppsCatalogRow({ + {plugin ? ( + setPluginOpen(true)}> + + {tx("settings.apps.pluginDetails", "Agent Plugin")} + + ) : null} onAction("test", app.name)}> {tx("settings.cliApps.test", "Test CLI")} @@ -512,6 +545,15 @@ function CliAppsCatalogRow({ )}
+ {plugin && pluginOpen ? ( + + ) : null} ); } @@ -595,7 +637,7 @@ function McpAppsCatalogRow({ const runtimeFailed = !toggleable && preset.installed && preset.runtime_status === "failed"; const connecting = Boolean(oauthFlow) || (runtimeConnecting && configuredInstalled); const statusLabel = toggleable - ? tx("settings.nanobotFeatures.enabled", "Enabled") + ? preset.enabled ? tx("settings.values.enabled", "Enabled") : tx("settings.values.disabled", "Disabled") : runtimeConnected ? tx("connection.open", "Connected") : mcpPresetStatusLabel(preset.status, tx); @@ -895,7 +937,15 @@ function McpAppsCatalogRow({ ) : null} - {managementOpen ? ( + {managementOpen && agentPlugin ? ( + + ) : managementOpen ? ( snapshot.cliApps !== null && Date.now() - cliUpdated < TOOLS_CATALOG_TTL_MS, mcpFresh: () => snapshot.mcpPresets !== null && Date.now() - mcpUpdated < TOOLS_CATALOG_TTL_MS, loadCliApps(): Promise { diff --git a/webui/src/lib/types.ts b/webui/src/lib/types.ts index 97f5aa2c2..93a4c5bf2 100644 --- a/webui/src/lib/types.ts +++ b/webui/src/lib/types.ts @@ -1320,6 +1320,7 @@ export interface McpPresetInfo { error?: string | null; enabled_tools?: string[]; source?: "preset" | "custom" | string; + managed_by_cli?: string | null; manifest?: AppManifest; } diff --git a/webui/src/tests/catalog-loading.test.tsx b/webui/src/tests/catalog-loading.test.tsx index 0b00780e6..8875066a8 100644 --- a/webui/src/tests/catalog-loading.test.tsx +++ b/webui/src/tests/catalog-loading.test.tsx @@ -57,8 +57,9 @@ describe("catalog loading", () => { cleanup(); fetch.mockClear(); renderSettingsView({ client, initialSettings: settingsPayload() }); - fireEvent.click(screen.getByRole("button", { name: "Apps" })); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" })); expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument(); expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); expect(fetch.mock.calls.filter(([url]) => String(url).match(/cli-apps|mcp-presets/))).toHaveLength(0); @@ -67,8 +68,9 @@ describe("catalog loading", () => { const now = vi.spyOn(Date, "now").mockReturnValue(Date.now() + TOOLS_CATALOG_TTL_MS + 1); try { renderSettingsView({ client, initialSettings: settingsPayload() }); - fireEvent.click(screen.getByRole("button", { name: "Apps" })); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" })); expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument(); expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); expect(fetch.mock.calls.filter(([url]) => String(url).match(/cli-apps|mcp-presets/))).toHaveLength(2); @@ -76,8 +78,9 @@ describe("catalog loading", () => { cli.resolve(jsonResponse({ apps: [{ ...app, display_name: "Updated app" }], installed_count: 1 })); mcp.resolve(jsonResponse({ presets: [{ ...plugin, display_name: "Updated plugin" }], installed_count: 1 })); }); - expect(screen.getByRole("heading", { name: "Updated app" })).toBeInTheDocument(); expect(screen.getByRole("heading", { name: "Updated plugin" })).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); + expect(screen.getByRole("heading", { name: "Updated app" })).toBeInTheDocument(); } finally { now.mockRestore(); } @@ -136,13 +139,15 @@ describe("catalog loading", () => { return Promise.resolve(jsonResponse(settingsPayload())); })); renderSettingsView({ initialSettings: settingsPayload() }); - fireEvent.click(screen.getByRole("button", { name: "Apps" })); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); expect(screen.getByRole("status", { name: "Loading apps…" })).toHaveAttribute("aria-busy", "true"); await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); }); expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument(); expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument(); await act(async () => { mcp.resolve(jsonResponse({ presets: [plugin], installed_count: 1 })); }); + expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" })); expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument(); expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); }); @@ -160,7 +165,7 @@ describe("catalog loading", () => { renderSettingsView({ initialSettings: settingsPayload() }); await act(async () => {}); expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument(); - expect(screen.queryByText("No apps available.")).not.toBeInTheDocument(); + expect(screen.queryByText("No CLI Apps available.")).not.toBeInTheDocument(); fireEvent.click(screen.getByRole("button", { name: "MCP" })); expect(screen.getByText("No MCP tools available.")).toBeInTheDocument(); @@ -168,7 +173,7 @@ describe("catalog loading", () => { fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "AnyGen" } }); expect(screen.getByText("No tools match your search.")).toBeInTheDocument(); expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument(); - fireEvent.click(screen.getByRole("button", { name: "Apps" })); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); expect(screen.getByRole("status", { name: "Loading apps…" })).toBeInTheDocument(); expect(screen.queryByText("No tools match your search.")).not.toBeInTheDocument(); await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); }); @@ -186,7 +191,7 @@ describe("catalog loading", () => { renderSettingsView({ initialSection: section, initialSettings: settingsPayload() }); expect(await screen.findByText("Catalog offline")).toBeInTheDocument(); expect(screen.queryByRole("status", { name: /Loading (apps|channels)/ })).not.toBeInTheDocument(); - expect(screen.queryByText("No apps available.")).not.toBeInTheDocument(); + expect(screen.queryByText("No CLI Apps available.")).not.toBeInTheDocument(); expect(screen.queryByText("No channels match this filter.")).not.toBeInTheDocument(); }); diff --git a/webui/src/tests/settings-apps-default.test.tsx b/webui/src/tests/settings-apps-default.test.tsx index 99c6cdc1f..c390df7a3 100644 --- a/webui/src/tests/settings-apps-default.test.tsx +++ b/webui/src/tests/settings-apps-default.test.tsx @@ -42,7 +42,7 @@ describe("Apps default filter", () => { renderSettingsView({ initialSettings: settingsPayload() }); expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument(); - expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true"); + expect(screen.getByRole("button", { name: "CLI Apps" })).toHaveAttribute("aria-pressed", "true"); }); it("preserves a manual choice while MCP loads, then defaults to the cached Ready items on re-entry", async () => { @@ -56,9 +56,9 @@ describe("Apps default filter", () => { renderSettingsView({ client, initialSettings: settingsPayload() }); await act(async () => {}); expect(screen.queryByRole("heading", { name: "Example App" })).not.toBeInTheDocument(); - fireEvent.click(screen.getByRole("button", { name: "Apps" })); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); await act(async () => { pending.resolve(jsonResponse({ presets: [mcp], installed_count: 1 })); }); - expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true"); + expect(screen.getByRole("button", { name: "CLI Apps" })).toHaveAttribute("aria-pressed", "true"); expect(screen.getByRole("heading", { name: "Example App" })).toBeInTheDocument(); cleanup(); diff --git a/webui/src/tests/settings-apps-oauth.test.tsx b/webui/src/tests/settings-apps-oauth.test.tsx index 4e701a115..be38a1cfa 100644 --- a/webui/src/tests/settings-apps-oauth.test.tsx +++ b/webui/src/tests/settings-apps-oauth.test.tsx @@ -83,7 +83,7 @@ describe("SettingsView Apps catalog", () => { expect(screen.getByRole("heading", { name: "Figma local" })).toBeInTheDocument(); expect(screen.getByRole("heading", { name: "Figma connected" })).toBeInTheDocument(); expect(screen.queryByRole("heading", { name: "Figma CLI" })).not.toBeInTheDocument(); - fireEvent.click(screen.getByRole("button", { name: "Apps" })); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); expect(screen.getByRole("heading", { name: "Figma pending" })).toBeInTheDocument(); expect(screen.queryByRole("heading", { name: "Figma local" })).not.toBeInTheDocument(); expect(screen.queryByRole("heading", { name: "Photoshop CLI" })).not.toBeInTheDocument(); diff --git a/webui/src/tests/settings-overview.test.tsx b/webui/src/tests/settings-overview.test.tsx index ecead5121..3d1100152 100644 --- a/webui/src/tests/settings-overview.test.tsx +++ b/webui/src/tests/settings-overview.test.tsx @@ -348,7 +348,7 @@ describe("Settings overview and appearance", () => { renderSettingsView(); - expect(await screen.findByText("No apps available.")).toBeInTheDocument(); + expect(await screen.findByText("No CLI Apps available.")).toBeInTheDocument(); fireEvent.click(screen.getByRole("button", { name: "Browse MCP tools" })); expect(await screen.findByText("Add MCP")).toBeInTheDocument(); }); diff --git a/webui/src/tests/settings-system.test.tsx b/webui/src/tests/settings-system.test.tsx index 1f525a5b0..746b00dd8 100644 --- a/webui/src/tests/settings-system.test.tsx +++ b/webui/src/tests/settings-system.test.tsx @@ -138,11 +138,16 @@ describe("Settings system domains", () => { renderSettingsView(); + fireEvent.click(await screen.findByRole("button", { name: "Agent Plugins" })); expect(await screen.findByText("Computer Use")).toBeInTheDocument(); - expect(screen.getByText("Plugins")).toBeInTheDocument(); expect(screen.getByText(/Control the desktop/)).toBeInTheDocument(); - expect(screen.getByText("screen-recording, accessibility")).toBeInTheDocument(); - fireEvent.click(screen.getByRole("button", { name: "Enable" })); + fireEvent.click(screen.getByRole("button", { name: "Computer Use" })); + const dialog = screen.getByRole("dialog", { name: "Computer Use" }); + expect(within(dialog).getByText("Declared permissions")).toBeVisible(); + expect(within(dialog).getByText("screen-recording, accessibility")).toBeVisible(); + expect(within(dialog).queryByRole("tab", { name: "Tools" })).not.toBeInTheDocument(); + expect(requestMutationMock).not.toHaveBeenCalled(); + fireEvent.click(within(dialog).getByRole("button", { name: "Enable" })); await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith( "settings.mcp.enable", { name: "plugin-computer-use" }, 20_000, @@ -159,6 +164,52 @@ describe("Settings system domains", () => { }); + it("groups a CLI-managed plugin under its app while keeping other plugins independent", async () => { + const managed = { ...agentPlugin, name: "plugin-cli-app-anygen", display_name: "Managed plugin", managed_by_cli: "anygen" }; + const separate = { ...agentPlugin, name: "plugin-cli-app-other", display_name: "Separate plugin", managed_by_cli: null }; + vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [installedAnyGen], installed_count: 1 }); + if (url === "/api/settings/mcp-presets") return jsonResponse({ presets: [managed, separate], installed_count: 1 }); + return jsonResponse(settingsPayload()); + })); + requestMutationMock.mockResolvedValue({ + presets: [{ ...managed, enabled: true, status: "enabled" }, separate], installed_count: 2, + }); + renderSettingsView({ initialSection: "apps" }); + + expect(await screen.findByRole("heading", { name: "AnyGen" })).toBeVisible(); + expect(screen.queryByRole("heading", { name: "Managed plugin" })).not.toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Agent Plugins" })); + expect(screen.getByRole("heading", { name: "Separate plugin" })).toBeVisible(); + expect(screen.queryByRole("heading", { name: "Managed plugin" })).not.toBeInTheDocument(); + fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "separate" } }); + expect(screen.getByRole("heading", { name: "Separate plugin" })).toBeVisible(); + fireEvent.click(screen.getByRole("button", { name: "CLI Apps" })); + expect(screen.queryByRole("heading", { name: "AnyGen" })).not.toBeInTheDocument(); + fireEvent.change(screen.getByPlaceholderText("Search tools"), { target: { value: "" } }); + fireEvent.click(screen.getByRole("button", { name: "Agent Plugin disabled" })); + fireEvent.click(within(screen.getByRole("dialog", { name: "Managed plugin" })).getByRole("button", { name: "Enable" })); + await waitFor(() => expect(requestMutationMock).toHaveBeenCalledWith( + "settings.mcp.enable", { name: "plugin-cli-app-anygen" }, 20_000, + )); + await waitFor(() => expect(screen.queryByRole("button", { name: "Agent Plugin disabled" })).not.toBeInTheDocument()); + }); + + it("keeps a managed plugin accessible when its owning app is missing from the loaded catalog", async () => { + vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/settings/cli-apps") return jsonResponse({ apps: [], installed_count: 1 }); + if (url === "/api/settings/mcp-presets") return jsonResponse({ + presets: [{ ...agentPlugin, managed_by_cli: "missing-app" }], installed_count: 0, + }); + return jsonResponse(settingsPayload()); + })); + renderSettingsView({ initialSection: "apps" }); + fireEvent.click(await screen.findByRole("button", { name: "Agent Plugins" })); + expect(await screen.findByRole("heading", { name: "Computer Use" })).toBeVisible(); + }); + it.each(["apps", "skills", "automations", "channels"] as const)( "uses the conversation-width content frame for the standalone %s page", (initialSection) => { @@ -487,6 +538,35 @@ describe("Settings system domains", () => { }); }); + it("refreshes plugin ownership after installing a CLI app without replacing its mutation result", async () => { + let installed = false; + const managed = { ...agentPlugin, name: "plugin-cli-app-anygen", display_name: "Managed plugin", enabled: true, managed_by_cli: "anygen" }; + const fetchMock = vi.fn(async (input: RequestInfo | URL) => { + const url = String(input); + if (url === "/api/settings/cli-apps") return jsonResponse({ + apps: [{ ...installedAnyGen, installed: false }], installed_count: 0, + }); + if (url === "/api/settings/mcp-presets") return jsonResponse({ + presets: installed ? [managed] : [], installed_count: Number(installed), + }); + return jsonResponse(settingsPayload()); + }); + vi.stubGlobal("fetch", fetchMock); + requestMutationMock.mockImplementation(async () => { + installed = true; + return { apps: [installedAnyGen], installed_count: 1 }; + }); + renderSettingsView({ initialSection: "apps" }); + + fireEvent.click(await screen.findByRole("button", { name: "Install app" })); + await waitFor(() => expect(fetchMock.mock.calls.filter(([url]) => String(url) === "/api/settings/mcp-presets")).toHaveLength(2)); + const appAction = await screen.findByRole("button", { name: "App ready" }); + fireEvent.pointerDown(appAction, { button: 0, ctrlKey: false }); + fireEvent.click(await screen.findByRole("menuitem", { name: "Agent Plugin" })); + expect(screen.getByRole("dialog", { name: "Managed plugin" })).toBeVisible(); + expect(fetchMock.mock.calls.filter(([url]) => String(url) === "/api/settings/cli-apps")).toHaveLength(1); + }); + it("shows a visible uninstall button for installed CLI apps and calls uninstall", async () => { const fetchMock = vi.fn(async (input: RequestInfo | URL) => { const url = String(input); @@ -581,7 +661,8 @@ describe("Settings system domains", () => { expect(await screen.findByText("AnyGen")).toBeInTheDocument(); expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "false"); - expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true"); + expect(screen.getByRole("button", { name: "CLI Apps" })).toHaveAttribute("aria-pressed", "true"); + expect(screen.getByRole("button", { name: "Agent Plugins" })).toBeInTheDocument(); expect(screen.getByRole("button", { name: "MCP" })).toBeInTheDocument(); });