diff --git a/docs/docs/features/plugins.md b/docs/docs/features/plugins.md index dde1d20ce..aa4e2e050 100644 --- a/docs/docs/features/plugins.md +++ b/docs/docs/features/plugins.md @@ -13,11 +13,10 @@ npm package of a local MCP server, which goes through the same package cache and integrity check as the [extension library's local package servers](./agent-extensions.md#local-package-servers). :::note Work in progress -This page describes the plugin **manifest**, the official plugin registry and -how an administrator **installs** a plugin through the API. The Plugins page, -applying contributions to runs, OAuth connections, handlers, webhooks and -commands are added by later releases; until then an installed plugin's state -is stored and served but has no effect on runs. +This page describes the plugin **manifest**, the official plugin registry, the +[Plugins page](#the-plugins-page) and the installation API. A plugin's +generated settings form, handlers, webhooks and commands are added by later +releases. ::: ## Where plugins live @@ -168,6 +167,74 @@ npm run plugins:check -- --online [--registry https://registry.npmjs.org] also asks the npm registry for each package server's version and compares the recorded `integrity` value. It needs network access and is not run in CI. +## The Plugins page + +**Plugins** (`/plugins`) is where an administrator installs a plugin and makes +it work without knowing what it contributes internally. It is in the sidebar +(on mobile, under **More**) and linked from **Settings → Agent Extensions & +Packages → Skills & MCP servers**, and only durable administrators with +`instance.manage_settings` see it. Everything on the page is drawn by ProPR +from the manifest: manifest text is shown as plain text, links appear only for +`https` URLs, and no code, image or markup supplied by the plugin runs in the +browser. + +### Catalog + +The catalog shows one card per plugin: an icon for its category, its name, +one-line description, category and a state badge. Filter by **Category** or +type in **Search by name**. + +| Badge | Meaning | +| --- | --- | +| Not installed | Available in this ProPR, not installed. | +| Off | Installed, every connection set, not enabled. | +| Needs connection | Installed and not enabled, with a connection still to set or sign in. | +| Enabled | Enabled, every connection set. | +| Needs approval | An upgrade asks for permissions or a secret acknowledgement not yet approved. | +| Degraded | Enabled while a connection is missing or needs a new sign-in, or no longer in this ProPR's registry. | + +### Walkthrough + +Open a card to see the plugin's steps, always in this order, each marked +**Done** or **To do**: + +1. **Install.** The step says what the plugin adds in plain words, for example + "Adds 1 MCP server the agent can read from", "Runs 1 local server inside + the task container" or "Adds the /deploy command", and lists the + permissions it asks for, each with a one-line explanation. When a local + package server receives secret variables, the step shows the package, its + exact version and the variable names, with a required checkbox confirming + that those secrets are readable inside the task container. **Install** + stays unavailable until it is ticked. After an upgrade that needs approval, + the step lists what is new and offers **Approve**. +2. **Connect.** One row per connection with its state, the manifest's help text + and a **How to get it** link. An OAuth connection has **Connect**, + **Reconnect** and **Disconnect**, the same controls as an OAuth server in + Skills & MCP servers; sign-in opens in a new tab and the page refreshes when + you come back. A `token` or `signing_secret` connection has a write-only + field: once saved, the page only says who stored it and when, and offers + **Replace** and **Clear**. A required connection cannot be cleared while + the plugin is enabled. +3. **Configure.** **Limit to repositories** picks the repositories the plugin + applies in; leave every box unchecked for all repositories. The form for + the plugin's own settings is added by a later release. +4. **Enable.** A single **Enabled** checkbox. While a required connection, + required setting or secret acknowledgement is missing it cannot be ticked, + and the step lists what is missing, for example "Connection Example API + token (example-token) is not set". Untick it to disable the plugin; its + settings and connections are kept. + +Below the steps, **What it added** lists the plugin's managed MCP servers and +skills, with a link to Skills & MCP servers where they are listed, and its +automation templates, each with whether it applies now. + +**Uninstall** is a separate action. Its confirmation lists what is removed: +the settings and repository limit, each connection and stored credential, the +managed library items and the templates. The audit trail is kept. When an +automation still adds one of the plugin's managed items, the API refuses the +uninstall and the page shows its message, which names the automation; remove +the item from that automation and try again. + ## Installing a plugin A plugin is **available** when it is in this ProPR's registry, **installed** diff --git a/docs/docs/features/web-ui.md b/docs/docs/features/web-ui.md index 816eebeb2..3ff06510f 100644 --- a/docs/docs/features/web-ui.md +++ b/docs/docs/features/web-ui.md @@ -9,7 +9,7 @@ The ProPR Web UI configures repositories and agents, launches work, and shows pr ## Navigation And Chrome -The sidebar's work area contains **Dashboard**, **Inbox**, **Tasks**, **Goals**, **Automations** and **Plans**. The system area contains **Repositories**, **Coding Agents** (administrators), **Analytics**, the collapsible **Logs** group, **Settings** and **Access** (administrators). Count badges show current work and unread Inbox items. Agent Tank usage appears below navigation when enabled. +The sidebar's work area contains **Dashboard**, **Inbox**, **Tasks**, **Goals**, **Automations** and **Plans**. The system area contains **Repositories**, **Coding Agents** (administrators), **Analytics**, the collapsible **Logs** group, **Settings**, **Plugins** and **Access** (administrators). Count badges show current work and unread Inbox items. Agent Tank usage appears below navigation when enabled. The header includes search (`Cmd/Ctrl+K`), activity/review controls, quick add to-do (`Alt+T`) and system health. Search opens a command palette that groups matching repositories, plans and tasks, with a preview of the highlighted item beside the list on wider screens. Tab and Shift+Tab switch between the **All**, **Repos**, **Plans** and **Tasks** tabs, Enter opens the highlighted item, Cmd/Ctrl+Enter opens it on GitHub, and **Search all tasks** runs the term as a full Tasks search. **New Task** is the default creation action. It becomes **New Plan** in Plans/Planner Studio, **New Goal** in Goals and **New Automation** in Automations; the adjacent menu offers the other actions. See [Launching work](./launching-work.md) to choose between them. After quick add confirms **To-Do added**, choose **Add another** to enter the next item without closing the popover. Desktop puts application information in **About ProPR** rather than the sidebar footer. @@ -122,6 +122,17 @@ for the operator walkthrough and the log's filters. ![Settings AI and Models tab showing implementation and planning model controls in a single column](/img/screenshots/0.9.0/settings.png) +## Plugins + +**Plugins** (`/plugins`) installs and manages [plugins](./plugins.md#the-plugins-page). It appears in the sidebar (on mobile, under **More**) and as an **Open Plugins** link above **Skills & MCP servers** in Settings, only for durable administrators with `instance.manage_settings`; anyone else who opens the address sees *Administrator access required*. + +1. The catalog shows a card per plugin with its name, description, category and a state badge (**Not installed**, **Enabled**, **Off**, **Needs connection**, **Needs approval** or **Degraded**). Filter by category or search by name, then open a card. +2. **Install** lists what the plugin adds and the permissions it asks for. If a local package server receives secret variables, tick the acknowledgement that names its package, version and variables, then choose **Install**. +3. **Connect** has one row per connection: **Connect** for an OAuth sign-in (it opens in a new tab), or a write-only field for an API token or signing secret. +4. **Configure** offers **Limit to repositories**; leave it empty to apply everywhere. +5. Tick **Enabled**. While something is missing, the checkbox is unavailable and the step lists what to do first. Untick it to disable the plugin and keep its settings. +6. **What it added** links the plugin's managed items in Skills & MCP servers. **Uninstall…** lists what will be removed before you confirm, and shows the API's message if an automation still uses one of the plugin's items. + ## Access **Access** (`/admin/members`) is available to administrators. It creates durable `admin` and `member` role assignments using stable GitHub user IDs, shows environment administrators configured through `PROPR_ADMIN_USERS`, surfaces recent role-audit events, and prevents removal or demotion of the last durable administrator. On a new installation, sign in as a configured environment administrator and use **Store my administrator role** before removing that username from `PROPR_ADMIN_USERS`. diff --git a/propr-ui/e2e/plugins.pw.ts b/propr-ui/e2e/plugins.pw.ts new file mode 100644 index 000000000..ae627a5ee --- /dev/null +++ b/propr-ui/e2e/plugins.pw.ts @@ -0,0 +1,196 @@ +import { expect, test, type Page } from '@playwright/test'; +import { mkdir } from 'node:fs/promises'; +import path from 'node:path'; + +/** + * The Plugins page end to end against a stateful plugin API fixture: the + * example plugin is installed, connected, limited to a repository, enabled, + * disabled and uninstalled entirely from the page. With PROPR_CAPTURE_PREVIEWS + * set it also captures the catalog and the detail steps at desktop and phone widths. + */ + +const NOW = Date.parse('2026-11-14T09:00:00.000Z'); +const BASE = '/api/instance/plugins/v1'; +const REFUSAL = 'Automations add items of plugin example-pack explicitly; remove them from "Weekly digest" (example-remote) before uninstalling'; + +const MANIFEST = { + id: 'example-pack', name: 'Example pack', version: '0.1.0', category: 'other', + description: 'A small development plugin that exercises every manifest section: one remote MCP server, one pinned package server, one skill and one automation template.', + homepage: 'https://github.com/integry/propr/tree/main/packages/plugins/example-pack', + permissions: [ + { name: 'events.read', description: 'Receive ProPR task, pull request and automation events' }, + { name: 'tasks.read', description: 'Read tasks and their status' }, + ], + connections: [ + { type: 'oauth', name: 'example-account', label: 'Example account', help: 'Sign in with the example service account that the remote MCP server should act as.', helpUrl: 'https://example.com/docs/oauth' }, + { type: 'token', name: 'example-token', label: 'Example API token', help: 'Create a read-only API token in the example service settings and paste it here.', helpUrl: 'https://example.com/docs/tokens' }, + ], + settings: { type: 'object', properties: {}, required: [] }, + outboundHosts: ['api.example.com'], + contributes: { + mcpServers: [ + { kind: 'https', name: 'example-remote', url: 'https://mcp.example.com/mcp', tools: ['search', 'fetch'], capability: 'read', authentication: 'oauth', connection: 'example-account' }, + { kind: 'package', name: 'example-local', ecosystem: 'npm', package: 'propr-fixture-mcp', version: '1.0.0', tools: ['echo'], capability: 'read', secretEnv: [{ name: 'FIXTURE_TOKEN', connection: 'example-token' }] }, + ], + skills: ['example-notes'], automationTemplates: ['example-weekly-digest'], commands: [], subscriptions: [], webhooks: [], + }, +}; +const OTHERS = [ + { id: 'team-chat', name: 'Team chat', category: 'messaging', description: 'Posts task and pull request updates to a chat channel.' }, + { id: 'deploy-hooks', name: 'Deploy hooks', category: 'deployment', description: 'Adds the /deploy command and reports deployment status.' }, +]; + +interface State { installed: boolean; enabled: boolean; token: boolean; oauth: boolean; repositories: string[] | null; refuseUninstall: boolean } + +function view(state: State) { + const active = state.enabled; + const library = '/api/instance/extensions/v1'; + return { + id: 'example-pack', available: true, manifest: MANIFEST, + state: !state.installed ? 'available' : state.enabled ? 'enabled' : 'installed', + installation: state.installed ? { + installedVersion: '0.1.0', enabled: state.enabled, settings: {}, repositories: state.repositories, grantedPermissions: ['events.read', 'tasks.read'], + acknowledgements: { 'example-local': { actor: '1042', at: NOW, package: 'propr-fixture-mcp', version: '1.0.0', secretEnv: ['FIXTURE_TOKEN'] } }, + installedBy: '1042', installedAt: NOW, updatedBy: '1042', updatedAt: NOW, + } : null, + connections: [ + { name: 'example-account', type: 'oauth', label: 'Example account', state: state.oauth ? 'connected' : 'not_connected', required: false }, + { name: 'example-token', type: 'token', label: 'Example API token', state: state.token ? 'connected' : 'not_connected', required: true, ...(state.token ? { setBy: '1042', setAt: NOW } : {}) }, + ], + needsApproval: false, pendingPermissions: [], pendingAcknowledgements: [], + enableBlockers: state.installed && !state.token ? ['Connection Example API token (example-token) is not set'] : [], + contributions: { + mcpServers: [ + { name: 'example-remote', kind: 'https', managed: state.installed ? { kind: 'server', name: 'example-remote', enabled: true, active } : null, href: library }, + { name: 'example-local', kind: 'package', managed: state.installed ? { kind: 'server', name: 'example-local', enabled: true, active } : null, href: library }, + ], + skills: [{ name: 'example-notes', managed: state.installed ? { kind: 'skill', bundleId: 'bundle-1', enabled: true, active } : null, href: library }], + automationTemplates: [{ id: 'example-weekly-digest', catalogId: 'example-weekly-digest', available: state.enabled, href: '/api/automation-definitions/templates' }], + }, + }; +} +const otherView = (other: typeof OTHERS[number], enabled: boolean) => ({ + ...view({ installed: enabled, enabled, token: true, oauth: true, repositories: null, refuseUninstall: false }), + id: other.id, manifest: { ...MANIFEST, ...other, connections: [], contributes: { ...MANIFEST.contributes, mcpServers: [] } }, connections: [], +}); + +async function installFixture(page: Page, state: State): Promise { + await page.routeWebSocket('**/socket.io/**', socket => socket.close()); + await page.route('**/api/**', async route => { + const request = route.request(); + const { pathname } = new URL(request.url()); + const method = request.method(); + if (method !== 'GET' && request.headers()['x-propr-plugins'] !== '1') return route.fulfill({ status: 403, json: { error: 'Plugin changes require the preflight-protected JSON contract' } }); + const body = method === 'GET' ? {} : request.postDataJSON() as Record; + const reply = () => route.fulfill({ json: { plugin: view(state) } }); + if (pathname === BASE) return route.fulfill({ json: { plugins: [view(state), otherView(OTHERS[0], true), otherView(OTHERS[1], false)] } }); + if (pathname === `${BASE}/example-pack`) return route.fulfill({ json: { plugin: { ...view(state), audit: [] } } }); + if (pathname === `${BASE}/example-pack/install`) { + if (!(body.acknowledgements as string[] | undefined)?.includes('example-local')) return route.fulfill({ status: 400, json: { error: 'Confirm that the secret variables of example-local are readable' } }); + state.installed = true; return reply(); + } + if (pathname === `${BASE}/example-pack/connections/example-token`) { state.token = body.value !== null; return reply(); } + if (pathname === `${BASE}/example-pack/repositories`) { state.repositories = body.repositories as string[] | null; return reply(); } + if (pathname === `${BASE}/example-pack/enabled`) { state.enabled = body.enabled === true; return reply(); } + if (pathname === `${BASE}/example-pack/uninstall`) { + if (state.refuseUninstall) { state.refuseUninstall = false; return route.fulfill({ status: 409, json: { error: REFUSAL } }); } + Object.assign(state, { installed: false, enabled: false, token: false, oauth: false, repositories: null }); return reply(); + } + const responses: Record = { + '/api/auth/demo-mode': { demoMode: false }, + '/api/auth/user': { + id: '1042', login: 'preview', username: 'preview', displayName: 'Preview Operator', email: null, avatarUrl: null, role: 'admin', + permissions: ['instance.manage_settings', 'instance.manage_members', 'instance.manage_agents'], authorizationSource: 'local', + }, + '/api/instance/catalog': { agents: [], repositories: [{ name: 'integry/propr' }, { name: 'integry/propr-docs' }] }, + '/api/instance/extensions/v1': { oauth: { redirectUri: 'https://propr.example.com/api/instance/extensions/v1/oauth/callback', clientMetadataUrl: null, connections: {} } }, + '/api/notifications/unread-count': { unreadCount: 0 }, + '/api/notifications/config': { push: { configured: false, vapidPublicKey: null } }, + }; + if (pathname in responses) return route.fulfill({ json: responses[pathname] }); + return route.fulfill({ status: 503, json: { error: 'Unavailable in the plugins fixture' } }); + }); +} + +/** The app scrolls inside its own container, so a capture scrolls the part it shows into view first. */ +async function capture(page: Page, name: string, focus?: ReturnType): Promise { + if (!process.env.PROPR_CAPTURE_PREVIEWS) return; + if (focus) await focus.evaluate(element => element.scrollIntoView({ block: 'start' })); + const directory = path.resolve('../.propr/previews'); + await mkdir(directory, { recursive: true }); + await page.screenshot({ animations: 'disabled', path: path.join(directory, `${name}.png`) }); +} + +const step = (page: Page, title: string) => page.getByRole('region', { name: new RegExp(`^\\d\\. ${title}`) }); +const badge = (page: Page) => page.getByRole('heading', { level: 1 }).getByTestId('plugin-state'); + +test('installs, connects, limits, enables, disables and uninstalls the example plugin from the page', async ({ page }) => { + const state: State = { installed: false, enabled: false, token: false, oauth: false, repositories: null, refuseUninstall: true }; + await page.setViewportSize({ width: 1440, height: 900 }); + await installFixture(page, state); + await page.goto('/plugins'); + + await expect(page.getByRole('navigation').getByRole('link', { name: 'Plugins' })).toHaveAttribute('href', '/plugins'); + await expect(page.getByTestId('plugin-card')).toHaveCount(3); + await capture(page, 'plugins-catalog-desktop'); + await page.getByLabel('Category').selectOption('messaging'); + await expect(page.getByTestId('plugin-card')).toHaveCount(1); + await page.getByLabel('Category').selectOption(''); + await page.getByRole('link', { name: 'Example pack: open' }).click(); + + const install = step(page, 'Install'); + await expect(install.getByRole('button', { name: 'Install' })).toBeDisabled(); + await expect(install.getByTestId('plugin-secret-acknowledgement')).toContainText('FIXTURE_TOKEN'); + await capture(page, 'plugins-install-step-desktop', install.getByText('Permissions it asks for')); + await install.getByRole('checkbox', { name: /propr-fixture-mcp@1\.0\.0/ }).check(); + await install.getByRole('button', { name: 'Install' }).click(); + await expect(badge(page)).toHaveText('Needs connection'); + + const enable = step(page, 'Enable'); + await expect(enable.getByRole('checkbox', { name: /Enabled/ })).toBeDisabled(); + await expect(enable.getByRole('status')).toContainText('Connection Example API token (example-token) is not set'); + await capture(page, 'plugins-connect-and-enable-blocked-desktop', step(page, 'Connect')); + + const token = step(page, 'Connect').getByTestId('plugin-connection').nth(1); + await token.getByLabel('Example API token').fill('tok_preview_value'); + await token.getByRole('button', { name: 'Save' }).click(); + await expect(token).toContainText('Stored by administrator 1042'); + await expect(token.getByLabel('Replace Example API token')).toHaveValue(''); + + const configure = step(page, 'Configure'); + await configure.getByRole('checkbox', { name: 'integry/propr', exact: true }).check(); + await configure.getByRole('button', { name: 'Save repositories' }).click(); + await expect(page.getByTestId('plugin-repository-limit')).toHaveText('Limited to integry/propr.'); + expect(state.repositories).toEqual(['integry/propr']); + + await enable.getByRole('checkbox', { name: /Enabled/ }).check(); + await expect(badge(page)).toHaveText('Degraded'); // the OAuth account is still to sign in + await expect(page.getByTestId('plugin-contributions')).toContainText('MCP server example-remote · Active'); + state.oauth = true; + await page.reload(); + await expect(badge(page)).toHaveText('Enabled'); + await capture(page, 'plugins-enabled-desktop', step(page, 'Configure')); + + await step(page, 'Enable').getByRole('checkbox', { name: /Enabled/ }).uncheck(); + await expect(badge(page)).toHaveText('Off'); + + await page.getByRole('button', { name: 'Uninstall…' }).click(); + await expect(page.getByTestId('plugin-uninstall-confirm')).toContainText('Skill example-notes from Skills & MCP servers'); + await page.getByRole('button', { name: 'Uninstall Example pack' }).click(); + await expect(page.getByTestId('plugin-uninstall-error')).toHaveText(REFUSAL); + await capture(page, 'plugins-uninstall-refused-desktop', page.getByTestId('plugin-contributions')); + await page.getByRole('button', { name: 'Uninstall Example pack' }).click(); + await expect(badge(page)).toHaveText('Not installed'); +}); + +test('keeps the plugin steps usable on a phone', async ({ page }) => { + const state: State = { installed: true, enabled: false, token: false, oauth: false, repositories: null, refuseUninstall: false }; + await page.setViewportSize({ width: 390, height: 844 }); + await installFixture(page, state); + await page.goto('/plugins/example-pack'); + await expect(badge(page)).toHaveText('Needs connection'); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + expect(overflow).toBeLessThanOrEqual(0); + await capture(page, 'plugins-detail-phone'); + await capture(page, 'plugins-enable-blocked-phone', step(page, 'Enable')); +}); diff --git a/propr-ui/src/App.tsx b/propr-ui/src/App.tsx index 7b795925b..c26ced19c 100644 --- a/propr-ui/src/App.tsx +++ b/propr-ui/src/App.tsx @@ -45,6 +45,7 @@ import { LoginPage, McpLogsPage, PlansPage, + PluginsPage, PlanStudioPage, RepositoriesPage, RevertPage, @@ -280,6 +281,7 @@ const AppContent: React.FC = () => { } /> + } /> { } /> - - - - - - } - /> + } /> ; +export type PluginConnectionView = PluginView['connections'][number]; + +/** The refusal text the API returned, kept so the page can show it verbatim. */ +export class PluginApiError extends Error { + constructor(readonly status: number, message: string) { super(message); this.name = 'PluginApiError'; } +} + +async function request(path: string, init?: { method: 'POST' | 'PUT'; body: unknown }): Promise { + const response = await apiFetch(`${API_BASE_URL}${PLUGIN_API_BASE}${path}`, { + credentials: 'include', cache: 'no-store', + ...(init ? { method: init.method, headers: { 'Content-Type': 'application/json', 'X-ProPR-Plugins': '1' }, body: JSON.stringify(init.body) } : {}), + }); + if (response.ok) return response.json() as Promise; + const failure = await response.json().catch(() => null) as { code?: string; message?: string; error?: string } | null; + // The read-only demo explains why plugins are not shown. + if (response.status === 403 && failure?.code === 'DEMO_MODE_LIVE_DATA_UNAVAILABLE' && failure.message) throw new PluginApiError(403, failure.message); + if (typeof failure?.error === 'string' && failure.error) throw new PluginApiError(response.status, failure.error); + if (response.status === 403) throw new PluginApiError(403, 'A current durable instance administrator is required.'); + throw new PluginApiError(response.status, 'Plugin operation unavailable. Check the configuration and try again.'); +} + +const segment = (value: string) => `/${encodeURIComponent(value)}`; +const plugin = (id: string, rest = '') => `${segment(id)}${rest}`; +const connection = (id: string, name: string, rest = '') => plugin(id, `/connections${segment(name)}${rest}`); +type Plugin = Promise; + +export const listPlugins = () => request(''); +export const getPlugin = (id: string) => request(plugin(id)); +/** `acknowledgements` names the package servers whose secret variables the administrator confirmed are readable in the task container. */ +export const installPlugin = (id: string, acknowledgements: string[]): Plugin => + request(plugin(id, '/install'), { method: 'POST', body: acknowledgements.length ? { acknowledgements } : {} }); +/** Approve permissions and acknowledgements a newer manifest asks for. */ +export const approvePlugin = (id: string, acknowledgements: string[]): Plugin => + request(plugin(id, '/approve'), { method: 'POST', body: acknowledgements.length ? { acknowledgements } : {} }); +/** `null` (or an empty list) for all repositories. */ +export const setPluginRepositories = (id: string, repositories: string[] | null): Plugin => + request(plugin(id, '/repositories'), { method: 'PUT', body: { repositories: repositories?.length ? repositories : null } satisfies ProprApi.PluginRepositoriesRequest }); +export const setPluginEnabled = (id: string, enabled: boolean): Plugin => + request(plugin(id, '/enabled'), { method: 'PUT', body: { enabled } satisfies ProprApi.PluginEnabledRequest }); +/** Set (`value`) or clear (`null`) a `token` or `signing_secret` connection. */ +export const setPluginConnection = (id: string, name: string, value: string | null): Plugin => + request(connection(id, name), { method: 'PUT', body: { value } }); +/** The uninstall must repeat the plugin id. */ +export const uninstallPlugin = (id: string): Plugin => + request(plugin(id, '/uninstall'), { method: 'POST', body: { confirm: id } satisfies ProprApi.PluginUninstallRequest }); +export const startPluginOAuth = (id: string, name: string) => + request(connection(id, name, '/oauth/start'), { method: 'POST', body: {} }); +export const disconnectPluginOAuth = (id: string, name: string): Plugin => + request(connection(id, name, '/oauth/disconnect'), { method: 'POST', body: {} }); diff --git a/propr-ui/src/components/Layout.tsx b/propr-ui/src/components/Layout.tsx index ad7d2f787..014bbbdb9 100644 --- a/propr-ui/src/components/Layout.tsx +++ b/propr-ui/src/components/Layout.tsx @@ -23,6 +23,7 @@ import UserAvatar from './UserAvatar'; import VoiceBriefingControl from './VoiceBriefingControl'; import { HeaderScopeSlotContext } from './headerScopeSlot'; import { SidebarNavigation, type NavigationState } from './SidebarNavigation'; +import { canManagePlugins } from '../pages/SettingsPage/settingsPermissions'; interface LayoutProps { children: React.ReactNode; @@ -75,6 +76,7 @@ const Layout: React.FC = ({ children }) => { canManageMembers: userHasPermission(user, 'instance.manage_members'), // The MCP access log needs the permission its admin endpoints require. canReadMcpLog: userHasPermission(user, 'instance.manage_settings'), + canManagePlugins: canManagePlugins(user), }; const navigationState: NavigationState = { currentPath: location.pathname, diff --git a/propr-ui/src/components/MobileBottomNavigation.test.tsx b/propr-ui/src/components/MobileBottomNavigation.test.tsx index 576303508..603b26323 100644 --- a/propr-ui/src/components/MobileBottomNavigation.test.tsx +++ b/propr-ui/src/components/MobileBottomNavigation.test.tsx @@ -301,6 +301,19 @@ describe('MobileBottomNavigation', () => { expect(screen.queryByRole('link', { name: 'MCP Log' })).not.toBeInTheDocument(); }); + it('offers Plugins only to administrators who may change instance settings', () => { + renderNavigation('/plugins/example-pack', vi.fn(), { ...user, permissions: ['instance.manage_settings'] }); + expect(screen.getByRole('button', { name: 'More' })).toHaveAttribute('aria-current', 'page'); + fireEvent.click(screen.getByRole('button', { name: 'More' })); + expect(screen.getByRole('link', { name: 'Plugins' })).toHaveAttribute('href', '/plugins'); + }); + + it('hides Plugins from members and from administrators without the settings permission', () => { + renderNavigation('/tasks', vi.fn(), { ...user, role: 'member', permissions: ['instance.manage_settings'] }); + fireEvent.click(screen.getByRole('button', { name: 'More' })); + expect(screen.queryByRole('link', { name: 'Plugins' })).not.toBeInTheDocument(); + }); + it('hides Access without member management permission', () => { renderNavigation('/tasks', vi.fn(), { ...user, diff --git a/propr-ui/src/components/MobileBottomNavigation.tsx b/propr-ui/src/components/MobileBottomNavigation.tsx index 094200922..f52d51351 100644 --- a/propr-ui/src/components/MobileBottomNavigation.tsx +++ b/propr-ui/src/components/MobileBottomNavigation.tsx @@ -13,6 +13,7 @@ import { ListTodo, MoreHorizontal, Plug, + Puzzle, Plus, ScrollText, Settings, @@ -24,6 +25,7 @@ import { import type { HeaderStats } from '../hooks/useHeaderStats'; import type { CurrentUser } from '../api/proprTypes'; import { userHasPermission } from '../contexts/AuthContext'; +import { canManagePlugins } from '../pages/SettingsPage/settingsPermissions'; import { publicAssetUrl } from '../config/runtimeMode'; import AgentTankSidebar from './AgentTankSidebar'; import QuickAddTodo from './QuickAddTodo'; @@ -67,7 +69,8 @@ const getNavigationState = (pathname: string, search: string) => { pathMatches(pathname, '/repositories') || pathMatches(pathname, '/summaries') || pathMatches(pathname, '/analytics') || pathMatches(pathname, '/llm-logs') || pathMatches(pathname, '/mcp-logs') || pathMatches(pathname, '/ai-agents') || - pathMatches(pathname, '/settings') || pathMatches(pathname, '/admin/members') + pathMatches(pathname, '/settings') || pathMatches(pathname, '/admin/members') || + pathMatches(pathname, '/plugins') ), }; }; @@ -99,6 +102,9 @@ const getMoreGroups = (user: CurrentUser | null) => ({ ? [{ label: 'Coding Agents', to: '/ai-agents', icon: Bot }] : []), { label: 'Settings', to: '/settings', icon: Settings }, + ...(canManagePlugins(user) + ? [{ label: 'Plugins', to: '/plugins', icon: Puzzle }] + : []), ...(userHasPermission(user, 'instance.manage_members') ? [{ label: 'Access', to: '/admin/members', icon: ShieldCheck }] : []), diff --git a/propr-ui/src/components/SidebarNavigation.test.tsx b/propr-ui/src/components/SidebarNavigation.test.tsx new file mode 100644 index 000000000..bf3577280 --- /dev/null +++ b/propr-ui/src/components/SidebarNavigation.test.tsx @@ -0,0 +1,26 @@ +import { render, screen } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; +import { describe, expect, it } from 'vitest'; +import { SidebarNavigation, type NavigationState } from './SidebarNavigation'; + +const state: NavigationState = { + currentPath: '/plugins', desktop: false, hasAgents: true, hasRepos: true, hasTasks: true, + taskCount: 0, goalCount: 0, generatingPlansCount: 0, unreadCount: null, +}; +const renderSidebar = (canManagePlugins?: boolean) => render( + + + , +); + +describe('SidebarNavigation', () => { + it('links Plugins for administrators who may manage plugins', () => { + renderSidebar(true); + expect(screen.getByRole('link', { name: /Plugins/ })).toHaveAttribute('href', '/plugins'); + }); + + it('hides Plugins from everyone else', () => { + renderSidebar(false); + expect(screen.queryByRole('link', { name: /Plugins/ })).not.toBeInTheDocument(); + }); +}); diff --git a/propr-ui/src/components/SidebarNavigation.tsx b/propr-ui/src/components/SidebarNavigation.tsx index 0166d03b6..336a2c23c 100644 --- a/propr-ui/src/components/SidebarNavigation.tsx +++ b/propr-ui/src/components/SidebarNavigation.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'; import { Link } from 'react-router-dom'; import { LayoutDashboard, ScrollText, ListTodo, BookMarked, Bot, ChartColumn, ChevronDown, ChevronRight, - Cpu, Logs, Plug, Settings, ShieldCheck, Inbox, Target, TriangleAlert, Workflow, + Cpu, Logs, Plug, Puzzle, Settings, ShieldCheck, Inbox, Target, TriangleAlert, Workflow, } from 'lucide-react'; import { SIDEBAR_ICON_STROKE_WIDTH, SIDEBAR_ICON_STROKE_CLASS } from './icons/sidebarIconStroke'; @@ -59,6 +59,7 @@ function getResourceNavigation( canManageAgents: boolean, canManageMembers: boolean, canReadMcpLog: boolean, + canManagePlugins = false, ): NavEntry[] { const navigation: NavEntry[] = [{ name: 'Repositories', href: '/repositories', icon: BookMarked }]; if (canManageAgents) navigation.push({ name: 'Coding Agents', href: '/ai-agents', icon: Bot }); @@ -71,6 +72,8 @@ function getResourceNavigation( { name: 'Logs', icon: Logs, items: logs }, { name: 'Settings', href: '/settings', icon: Settings }, ); + // Plugins need a durable administrator who may change instance settings, as their API does. + if (canManagePlugins) navigation.push({ name: 'Plugins', href: '/plugins', icon: Puzzle }); if (canManageMembers) navigation.push({ name: 'Access', href: '/admin/members', icon: ShieldCheck }); return navigation; } @@ -279,12 +282,13 @@ function NavigationEntry({ entry, state }: { entry: NavEntry; state: NavigationS */ export function SidebarNavigation({ state, permissions }: { state: NavigationState; - permissions: { canManageAgents: boolean; canManageMembers: boolean; canReadMcpLog: boolean }; + permissions: { canManageAgents: boolean; canManageMembers: boolean; canReadMcpLog: boolean; canManagePlugins?: boolean }; }) { const resources = getResourceNavigation( permissions.canManageAgents, permissions.canManageMembers, permissions.canReadMcpLog, + permissions.canManagePlugins, ); return (