From 63a33ac3fd3e30c16ae7013c104f0ff4d1179616 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:01:21 +0000 Subject: [PATCH] Let plugin screens use the plugin state hooks (#10049) * Let plugin screens use the plugin state hooks A plugin screen opened from the Command Center or the sidebar showed "Plugin failed: Plugin state hooks must run inside a plugin host" as soon as it called useWorkspaces, useAgents or another state hook. Every plugin host paired the installation provider with its own state provider, and the screen host and the plugin settings host did not. The installation provider now supplies the state source for the installation's host, so every surface rendered under it can read state, and the hosts no longer wrap a second provider of their own. Co-Authored-By: Claude Opus 5.5 * Keep a sidebar view's cross-host state in its hooks A sidebar view renders once across every connected host and builds an unscoped state source for that. After the installation provider took over the state source, the environment provider dropped the view's own source, so its hooks read state scoped to one host. The installation provider now takes the surface's source when one is passed and falls back to the installation's host. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../e2e/browser/plugin-sidebar-items.spec.ts | 10 ++++ .../support/helpers/plugin-sidebar-items.ts | 12 ++++ packages/app/src/file-panels/plugin-host.tsx | 11 +--- .../plugins/installation-provider.test.tsx | 56 ++++++++++++++++++- .../app/src/plugins/installation-provider.tsx | 19 ++++++- packages/app/src/plugins/popover.tsx | 5 +- packages/app/src/plugins/timeline/view.tsx | 7 +-- .../src/plugins/workspace-panels/panel.tsx | 7 +-- 8 files changed, 98 insertions(+), 29 deletions(-) diff --git a/packages/app/e2e/browser/plugin-sidebar-items.spec.ts b/packages/app/e2e/browser/plugin-sidebar-items.spec.ts index 3acf19a860..e9858c1ab4 100644 --- a/packages/app/e2e/browser/plugin-sidebar-items.spec.ts +++ b/packages/app/e2e/browser/plugin-sidebar-items.spec.ts @@ -362,6 +362,16 @@ test.describe("Plugin sidebar items", () => { }); }); + test("a plugin screen reads workspaces through the state hooks", async ({ page }) => { + await page.setViewportSize(WIDE); + await gotoWorkspace(page, workspaceId); + await expect(headerRow(page, SHOWCASE_PLUGIN_ID, "deploys")).toBeVisible({ timeout: 30_000 }); + await runCommand(page, "Open plugin workspaces"); + await expect(screenTitle(page)).toHaveText("Workspaces"); + await expect(page.getByText(`Workspace ${workspaceId}`, { exact: true })).toBeVisible(); + await expect(page.getByText("Plugin failed", { exact: false })).toHaveCount(0); + }); + test("a header row's shortcut hint presses the row", async ({ page }) => { await page.setViewportSize(WIDE); await gotoWorkspace(page, workspaceId); diff --git a/packages/app/e2e/support/helpers/plugin-sidebar-items.ts b/packages/app/e2e/support/helpers/plugin-sidebar-items.ts index 0722bd8317..cdc6de753f 100644 --- a/packages/app/e2e/support/helpers/plugin-sidebar-items.ts +++ b/packages/app/e2e/support/helpers/plugin-sidebar-items.ts @@ -15,8 +15,18 @@ export const COMPACT = { width: 390, height: 844 }; /** A plugin written against the current API: a screen, header and footer items, a command. */ const SHOWCASE_SOURCE = `import React from "react"; import { Pressable, Text, View } from "react-native"; +import { useWorkspaces } from "@getpaseo/plugin/client"; import { SidebarRow } from "@getpaseo/plugin/client/ui"; +function WorkspacesScreen({ theme }) { + const workspaces = useWorkspaces(); + return ( + + {workspaces.map((ref) => {"Workspace " + ref.id})} + + ); +} + function DeploysScreen({ theme }) { return Deploys screen body; } @@ -63,11 +73,13 @@ function Broken() { export default function contribute(client) { client.addScreen({ id: "deploys", title: "Deploys", Component: DeploysScreen }); + client.addScreen({ id: "workspaces", title: "Workspaces", Component: WorkspacesScreen }); client.addSidebarHeaderItem({ id: "deploys", title: "Deploys", Component: DeploysItem }); client.addSidebarHeaderItem({ id: "broken", title: "Broken header", Component: Broken }); client.addSidebarFooterItem({ id: "sync", title: "Sync", Component: SyncItem }); client.addSidebarFooterItem({ id: "broken", title: "Broken footer", Component: Broken }); client.addCommandCenterItem({ id: "open-deploys", title: "Open deploys", icon: "Rocket", context: "global", onSelect: (ctx) => ctx.openScreen({ screenId: "deploys" }) }); + client.addCommandCenterItem({ id: "open-workspaces", title: "Open plugin workspaces", icon: "List", context: "global", onSelect: (ctx) => ctx.openScreen({ screenId: "workspaces" }) }); return () => {}; } `; diff --git a/packages/app/src/file-panels/plugin-host.tsx b/packages/app/src/file-panels/plugin-host.tsx index 4cc96cdc3d..d62a17cade 100644 --- a/packages/app/src/file-panels/plugin-host.tsx +++ b/packages/app/src/file-panels/plugin-host.tsx @@ -1,7 +1,4 @@ -import { PluginClientStateProvider } from "@getpaseo/plugin/client/host"; import type { PluginFilePanelProps } from "@getpaseo/plugin/client"; -import { useMemo } from "react"; -import { createPluginClientStateSource } from "@/plugins/client-state/source"; import { PluginInstallationProvider } from "@/plugins/installation-provider"; import { SurfaceErrorBoundary } from "@/plugins/surface-error-boundary"; import type { PluginFilePanel } from "./panels"; @@ -11,17 +8,11 @@ export function PluginFilePanelHost({ ...props }: PluginFilePanelProps & { panel: PluginFilePanel }) { const { plugin, contribution } = panel; - const stateSource = useMemo( - () => createPluginClientStateSource(plugin.serverId), - [plugin.serverId], - ); const Component = contribution.Component; return ( - - - + ); diff --git a/packages/app/src/plugins/installation-provider.test.tsx b/packages/app/src/plugins/installation-provider.test.tsx index 9248221704..0428e3bb2f 100644 --- a/packages/app/src/plugins/installation-provider.test.tsx +++ b/packages/app/src/plugins/installation-provider.test.tsx @@ -1,5 +1,5 @@ import { PluginTranslationRuntime } from "@getpaseo/plugin/client/host"; -import { usePaseo, useRpc } from "@getpaseo/plugin/client"; +import { usePaseo, useRpc, useWorkspace, useWorkspaces } from "@getpaseo/plugin/client"; import { defineRpc } from "@getpaseo/plugin"; import { createPaseoApi, type PaseoApi } from "@getpaseo/client"; import { DaemonClient } from "@getpaseo/client/internal/daemon-client"; @@ -8,7 +8,11 @@ import React from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { expect, it } from "vitest"; import { z } from "zod"; +import type { PluginWorkspaceSnapshot } from "@getpaseo/plugin"; +import type { PluginClientStateSource } from "@getpaseo/plugin/client/host"; +import type { ToastApi } from "@/components/toast-host"; import { PluginInstallationProvider } from "./installation-provider"; +import { PluginEnvironmentProvider } from "./popover"; import type { InstalledPlugin } from "./types"; const status = defineRpc({ @@ -89,3 +93,53 @@ it("gives every surface the installation's client and RPCs on its first frame", plugin.lifetime.abort(); await plugin.paseo.dispose(); }); + +it("lets every surface read state through the plugin state hooks", async () => { + const plugin = installation([]); + function Surface() { + return {useWorkspaces().length} workspaces; + } + + const markup = renderToStaticMarkup( + + + , + ); + + expect(markup).toBe("0 workspaces"); + plugin.lifetime.abort(); + await plugin.paseo.dispose(); +}); + +function pluginEnvironment(plugin: InstalledPlugin, state: PluginClientStateSource) { + return { installation: plugin, state, toast: {} as ToastApi }; +} + +it("lets a surface read the state source its host passes", async () => { + const plugin = installation([]); + // A sidebar view spans every connected host, so its source is not the installation's host. + const workspace = { id: "ws-on-another-host" } as PluginWorkspaceSnapshot; + const state: PluginClientStateSource = { + subscribe: () => () => undefined, + getWorkspace: () => workspace, + getAgent: () => null, + getProject: () => null, + getTerminal: () => null, + getSnapshot: () => ({ workspaces: [], agents: [], projects: [], terminals: [] }), + }; + function Surface() { + return {useWorkspace("ws-on-another-host")?.id}; + } + + const environment = pluginEnvironment(plugin, state); + + const markup = renderToStaticMarkup( + + + , + ); + + expect(markup).toBe("ws-on-another-host"); + plugin.lifetime.abort(); + await plugin.paseo.dispose(); +}); diff --git a/packages/app/src/plugins/installation-provider.tsx b/packages/app/src/plugins/installation-provider.tsx index 19fb3bc8ab..d5faf75b8b 100644 --- a/packages/app/src/plugins/installation-provider.tsx +++ b/packages/app/src/plugins/installation-provider.tsx @@ -2,29 +2,42 @@ import { getPluginClientApi } from "./client-state/api"; import { QueryClientProvider } from "@tanstack/react-query"; import { PaseoApiProvider, + PluginClientStateProvider, PluginComposersProvider, PluginRpcProvider, PluginTranslationProvider, + type PluginClientStateSource, } from "@getpaseo/plugin/client/host"; -import React, { type ReactNode } from "react"; +import React, { useMemo, type ReactNode } from "react"; +import { createPluginClientStateSource } from "./client-state/source"; import { pluginComposersSource } from "./composer-items/source"; import type { InstalledPlugin } from "./types"; -/** Every plugin surface renders under its installation: one query cache, one Paseo client, RPCs. */ +/** + * Every plugin surface renders under its installation: one query cache, one Paseo client, RPCs, + * and the state the plugin state hooks read. That state is scoped to the installation's host + * unless the surface passes its own, as a sidebar view does to span every connected host. + */ export function PluginInstallationProvider({ plugin, + state: surfaceState, children, }: { plugin: InstalledPlugin; + state?: PluginClientStateSource; children: ReactNode; }) { + const state = useMemo( + () => surfaceState ?? createPluginClientStateSource(plugin.serverId), + [plugin.serverId, surfaceState], + ); return ( - {children} + {children} diff --git a/packages/app/src/plugins/popover.tsx b/packages/app/src/plugins/popover.tsx index f9680ebb29..d56b69f0d5 100644 --- a/packages/app/src/plugins/popover.tsx +++ b/packages/app/src/plugins/popover.tsx @@ -1,4 +1,3 @@ -import { PluginClientStateProvider } from "@getpaseo/plugin/client/host"; import type { ReactNode } from "react"; import { View } from "react-native"; import { StyleSheet } from "react-native-unistyles"; @@ -30,8 +29,8 @@ export function PluginEnvironmentProvider({ }: PluginEnvironmentProviderProps) { return ( - - {children} + + {children} ); diff --git a/packages/app/src/plugins/timeline/view.tsx b/packages/app/src/plugins/timeline/view.tsx index 90f6e0e1a2..8a3d522a2b 100644 --- a/packages/app/src/plugins/timeline/view.tsx +++ b/packages/app/src/plugins/timeline/view.tsx @@ -1,4 +1,3 @@ -import { PluginClientStateProvider } from "@getpaseo/plugin/client/host"; import type { PluginTimelineItemProps } from "@getpaseo/plugin/client"; import type { PluginTheme } from "@getpaseo/plugin"; import React, { type ComponentType, useMemo } from "react"; @@ -8,7 +7,6 @@ import { useIsCompactFormFactor } from "@/constants/layout"; import { useHostRuntimeClient, useHosts } from "@/runtime/host-runtime"; import type { Theme } from "@/styles/theme"; import type { PluginTimelineStreamItem } from "@/types/stream"; -import { createPluginClientStateSource } from "../client-state/source"; import { useInstalledPlugin } from "../registry"; import { PluginInstallationProvider } from "../installation-provider"; import { SurfaceErrorBoundary } from "../surface-error-boundary"; @@ -59,7 +57,6 @@ function PluginTimelineItemBody({ const hostLabel = hosts.find((host) => host.serverId === serverId)?.label ?? serverId; const host = useMemo(() => ({ id: serverId, label: hostLabel }), [hostLabel, serverId]); const layout = useMemo(() => ({ compact, platform: resolvePluginPlatform() }), [compact]); - const stateSource = useMemo(() => createPluginClientStateSource(serverId), [serverId]); if (!plugin || !renderer || !parsed || !client) { return ; @@ -82,9 +79,7 @@ function PluginTimelineItemBody({ return ( - - - + ); diff --git a/packages/app/src/plugins/workspace-panels/panel.tsx b/packages/app/src/plugins/workspace-panels/panel.tsx index 096400fb66..1500f1cdf1 100644 --- a/packages/app/src/plugins/workspace-panels/panel.tsx +++ b/packages/app/src/plugins/workspace-panels/panel.tsx @@ -5,7 +5,6 @@ import type { PluginTab, } from "@getpaseo/plugin/client"; import type { PluginTheme } from "@getpaseo/plugin"; -import { PluginClientStateProvider } from "@getpaseo/plugin/client/host"; import { CircleAlert } from "lucide-react-native"; import { useMemo, useState } from "react"; import { Text, View } from "react-native"; @@ -20,7 +19,6 @@ import { useWorkspaceExists } from "@/stores/session-store-hooks"; import type { Theme } from "@/styles/theme"; import { normalizeWorkspaceOpaqueId } from "@/utils/workspace-identity"; import { usePluginHostNavigation } from "../host-navigation"; -import { createPluginClientStateSource } from "../client-state/source"; import { toPluginTheme } from "../theme"; import { pluginIconComponent } from "../icons"; import { useInstalledPlugin } from "../registry"; @@ -67,7 +65,6 @@ function PluginPanelBody({ theme }: { theme: PluginTheme }) { const hostLabel = hosts.find((host) => host.serverId === serverId)?.label ?? serverId; const host = useMemo(() => ({ id: serverId, label: hostLabel }), [hostLabel, serverId]); const layout = useMemo(() => ({ compact, platform: resolvePluginPlatform() }), [compact]); - const stateSource = useMemo(() => createPluginClientStateSource(serverId), [serverId]); const navigation = usePluginHostNavigation(serverId); if (!plugin || !contribution || !workspaceExists) { @@ -123,9 +120,7 @@ function PluginPanelBody({ theme }: { theme: PluginTheme }) { Surface={Surface} key={`${serverId}/${target.pluginId}/${target.panelId}/${target.context}`} > - - {panel} - + {panel} ); }