Skip to content

The agent that grows with you

feat(desktop): move the capabilities bridge to sdk/bridge.ts; pluginDecisions read-only

teknium1488cd566ba75
diff --git a/apps/desktop/src/sdk/bridge.test.ts b/apps/desktop/src/sdk/bridge.test.ts
new file mode 100644
index 00000000000..e84ba599d04
--- /dev/null
+++ b/apps/desktop/src/sdk/bridge.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it, vi } from 'vitest'
+
+import { $pluginDecisions } from '@/contrib/plugins-store'
+import { host } from '@/sdk'
+
+// The bridge must hit the SAME api-module functions the Capabilities page
+// calls (not a parallel fetch path), forwarding the ProfileScope untouched —
+// that is the whole contract: typing + profile scoping over existing doors.
+const apiMocks = vi.hoisted(() => ({
+ getProfiles: vi.fn(async () => ({ profiles: [] })),
+ getSkills: vi.fn(async () => []),
+ getToolsets: vi.fn(async () => []),
+ setSkillEnabled: vi.fn(async () => ({ enabled: false, name: 'docx', ok: true })),
+ setToolsetEnabled: vi.fn(async () => ({ enabled: true, name: 'browser', ok: true }))
+}))
+
+vi.mock('@/api/skills', () => ({ getSkills: apiMocks.getSkills, setSkillEnabled: apiMocks.setSkillEnabled }))
+vi.mock('@/api/toolsets', () => ({ getToolsets: apiMocks.getToolsets, setToolsetEnabled: apiMocks.setToolsetEnabled }))
+vi.mock('@/api/profiles', () => ({ getProfiles: apiMocks.getProfiles }))
+
+describe('host capabilities bridge', () => {
+ it('routes list/setEnabled through the Capabilities api modules with the profile scope', async () => {
+ const scope = { connectionId: 'conn-1', profile: 'writer' }
+
+ await host.skills.list(scope)
+ await host.skills.setEnabled('docx', false, scope)
+ await host.toolsets.list('writer')
+ await host.toolsets.setEnabled('browser', true, 'writer')
+ await host.profiles.list()
+
+ expect(apiMocks.getSkills).toHaveBeenCalledWith(scope)
+ expect(apiMocks.setSkillEnabled).toHaveBeenCalledWith('docx', false, scope)
+ expect(apiMocks.getToolsets).toHaveBeenCalledWith('writer')
+ expect(apiMocks.setToolsetEnabled).toHaveBeenCalledWith('browser', true, 'writer')
+ expect(apiMocks.getProfiles).toHaveBeenCalledWith(undefined)
+ })
+
+ // Declined by design: a plugin must not flip another plugin's enable state,
+ // and the singleton host cannot attribute the caller to restrict `set` to its
+ // own id. The view is a live, subscribable mirror of the app's store with NO
+ // writer at runtime (a type-only `ReadableAtom` cast would still carry `.set`).
+ it('pluginDecisions is a live read-only view of the decisions store', () => {
+ const seen: Record<string, boolean>[] = []
+ const unsubscribe = host.pluginDecisions.subscribe(value => seen.push(value))
+
+ $pluginDecisions.set({ 'demo-plugin': false })
+
+ expect(host.pluginDecisions.get()).toEqual({ 'demo-plugin': false })
+ expect(seen.at(-1)).toEqual({ 'demo-plugin': false })
+ expect(typeof (host.pluginDecisions as unknown as { set?: unknown }).set).toBe('undefined')
+
+ unsubscribe()
+ })
+})
diff --git a/apps/desktop/src/sdk/bridge.ts b/apps/desktop/src/sdk/bridge.ts
new file mode 100644
index 00000000000..33e20aa5dad
--- /dev/null
+++ b/apps/desktop/src/sdk/bridge.ts
@@ -0,0 +1,68 @@
+/**
+ * Typed capabilities bridge for desktop plugins (`host.skills`, `host.toolsets`,
+ * `host.profiles`, `host.pluginDecisions`).
+ *
+ * Plugins that configure capabilities used to call `window.hermesDesktop.api`
+ * raw and read the persisted plugin-decisions map straight out of
+ * localStorage. These wrappers give them the SAME doors the Capabilities page
+ * uses — same endpoints, same `ProfileScope` handling — so a plugin acting on
+ * skills or toolsets behaves exactly like the page. Nothing new is arbitrated
+ * here: every RPC below is already reachable via `host.request`; the value is
+ * typing plus profile scoping.
+ *
+ * `pluginDecisions` is READ-ONLY on purpose. A `set()` would let one plugin
+ * flip another plugin's enable state, which is exactly "plugins messing with
+ * each other" and the singleton `host` cannot tell which plugin is calling to
+ * restrict it to its own id. Enabling/disabling plugins stays in the app's
+ * Capabilities → Plugins tab (`host.navigate('/capabilities?tab=plugins')`).
+ */
+import type { ReadableAtom } from 'nanostores'
+
+import type { ProfileScope } from '@/api/client'
+import { getProfiles } from '@/api/profiles'
+import { getSkills, setSkillEnabled } from '@/api/skills'
+import { getToolsets, setToolsetEnabled } from '@/api/toolsets'
+import { $pluginDecisions } from '@/contrib/plugins-store'
+
+/** Skills for a profile scope — omit `profile` for the app-wide active one. */
+export const skills = {
+ /** Every skill the backend reports for the scope. */
+ list: (profile?: ProfileScope) => getSkills(profile),
+ /** Enable/disable a skill (the Capabilities toggle). */
+ setEnabled: (name: string, enabled: boolean, profile?: ProfileScope) => setSkillEnabled(name, enabled, profile)
+}
+
+export const toolsets = {
+ /** Every toolset with its enabled state for the scope. */
+ list: (profile?: ProfileScope) => getToolsets(profile),
+ /** Enable/disable a toolset (the Capabilities toggle). */
+ setEnabled: (name: string, enabled: boolean, profile?: ProfileScope) => setToolsetEnabled(name, enabled, profile)
+}
+
+export const profiles = {
+ /** The profile list as the app's own surfaces read it (same endpoint and
+ * startup timeout as the profile rail). */
+ list: (scope?: ProfileScope) => getProfiles(scope)
+}
+
+/** This window's plugin enable/disable decisions (id → enabled; absence means
+ * the user never chose, so the plugin's own `defaultEnabled` applies).
+ * A hand-built view rather than a `computed`/type cast: both of those still
+ * carry `.set` at runtime, and the point is that a plugin cannot cast its way
+ * into another plugin's toggle. */
+export const pluginDecisions: ReadableAtom<Record<string, boolean>> = {
+ get: () => $pluginDecisions.get(),
+ get init() {
+ return $pluginDecisions.init
+ },
+ get lc() {
+ return $pluginDecisions.lc
+ },
+ listen: listener => $pluginDecisions.listen(listener),
+ notify: oldValue => $pluginDecisions.notify(oldValue),
+ off: () => $pluginDecisions.off(),
+ subscribe: listener => $pluginDecisions.subscribe(listener),
+ get value() {
+ return $pluginDecisions.value
+ }
+}
diff --git a/apps/desktop/src/sdk/index.test.ts b/apps/desktop/src/sdk/index.test.ts
index bf5fc54fffc..796bb948e09 100644
--- a/apps/desktop/src/sdk/index.test.ts
+++ b/apps/desktop/src/sdk/index.test.ts
@@ -449,57 +449,3 @@ describe('host.sessions session-list mutations', () => {
expect($sessionColorOverrides.get()).toEqual({})
})
})
-
-// The typed capabilities bridge: plugins configure skills/toolsets/profiles
-// through the SAME endpoints the Capabilities page uses, and read the plugin
-// decision map through one accessor instead of raw storage writes.
-describe('host capability namespaces', () => {
- const desktopWindow = window as unknown as { hermesDesktop?: Window['hermesDesktop'] }
- const originalDesktop = desktopWindow.hermesDesktop
- const api = vi.fn(async (request: { path: string }) => ({ ok: true, path: request.path }))
-
- beforeEach(() => {
- api.mockClear()
- desktopWindow.hermesDesktop = { ...originalDesktop, api } as unknown as Window['hermesDesktop']
- })
-
- afterEach(() => {
- desktopWindow.hermesDesktop = originalDesktop
- })
-
- it('skills.setEnabled routes through the Capabilities toggle endpoint with the profile scope', async () => {
- await host.skills.setEnabled('docx', false, { profile: 'writer' })
-
- expect(api).toHaveBeenCalledWith(
- expect.objectContaining({
- body: { enabled: false, name: 'docx' },
- method: 'PUT',
- path: '/api/skills/toggle',
- profile: 'writer'
- })
- )
- })
-
- it('toolsets.setEnabled routes through the toolset endpoint', async () => {
- await host.toolsets.setEnabled('browser', true)
-
- expect(api).toHaveBeenCalledWith(
- expect.objectContaining({ body: { enabled: true }, method: 'PUT', path: '/api/tools/toolsets/browser' })
- )
- })
-
- it('profiles.list reads the same endpoint the profile rail does', async () => {
- await host.profiles.list()
-
- expect(api).toHaveBeenCalledWith(expect.objectContaining({ path: '/api/profiles' }))
- })
-
- it('pluginDecisions reads the live decisions store', async () => {
- const { $pluginDecisions } = await import('@/contrib/plugins-store')
-
- $pluginDecisions.set({ demo: false })
-
- expect(host.pluginDecisions.get('demo')).toBe(false)
- expect(host.pluginDecisions.all()).toEqual({ demo: false })
- })
-})
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index f48c6e022bc..ca2b981dfca 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -21,10 +21,7 @@
import { atom, computed, type ReadableAtom } from 'nanostores'
import type { ReactNode } from 'react'
-import { capabilityScoped, type ProfileScope } from '@/api/client'
-import { getProfiles } from '@/api/profiles'
-import { getSkills, setSkillEnabled } from '@/api/skills'
-import { getToolsets, setToolsetEnabled } from '@/api/toolsets'
+import { capabilityScoped } from '@/api/client'
import { PRIMARY_SESSION_VIEW } from '@/app/chat/session-view'
import { openSession, type OpenSessionIntent } from '@/app/open-session'
import { syncWorkspaceRoute } from '@/app/routes'
@@ -47,7 +44,6 @@ import {
type WorkspaceNewSessionTarget
} from '@/components/pane-shell/workspace-scope'
import { onGatewayEvent } from '@/contrib/events'
-import { $pluginDecisions, setPluginEnabled } from '@/contrib/plugins-store'
import { registry } from '@/contrib/registry'
import type { WorkspaceMode } from '@/contrib/types'
import { deleteProfile, getLogs, getStatus, hermesApi, type HermesGateway } from '@/hermes'
@@ -110,6 +106,7 @@ import {
import { runGatewayRestart } from '@/store/system-actions'
import type { PaginatedSessions, UsageStats } from '@/types/hermes'
+import { pluginDecisions, profiles, skills, toolsets } from './bridge'
import { composerHost } from './composer'
import { planPluginOpenSession } from './plugin-open-session-plan'
import { sessionsHost } from './sessions'
@@ -926,44 +923,12 @@ export const host = {
/** Session-list mutations (pin, reorder, colour) — see `./sessions`. */
sessions: sessionsHost,
- /** Capability management — the SAME endpoints the Capabilities page uses,
- * wrapped with the app's profile scoping, so a plugin configuring skills or
- * toolsets behaves exactly like the page (and stops calling
- * `window.hermesDesktop.api` raw). Every call takes an optional
- * `ProfileScope` to configure ANY profile without swapping the app-wide
- * active profile; omit it for the active one. */
- skills: {
- /** Every skill the backend reports for the scope. */
- list: (profile?: ProfileScope) => getSkills(profile),
- /** Enable/disable a skill (the Capabilities toggle). */
- setEnabled: (name: string, enabled: boolean, profile?: ProfileScope) => setSkillEnabled(name, enabled, profile)
- },
-
- toolsets: {
- /** Every toolset with its enabled state for the scope. */
- list: (profile?: ProfileScope) => getToolsets(profile),
- /** Enable/disable a toolset (the Capabilities toggle). */
- setEnabled: (name: string, enabled: boolean, profile?: ProfileScope) => setToolsetEnabled(name, enabled, profile)
- },
-
- profiles: {
- /** The profile list as the app's own surfaces read it (same endpoint and
- * startup timeout as the profile rail). */
- list: (scope?: ProfileScope) => getProfiles(scope)
- },
-
- /** This window's plugin enable/disable decisions — the persisted map the
- * Capabilities → Plugins page writes. Read it to respect a user's choice;
- * `set` goes through the SAME live toggle the page uses (deactivate and
- * activate included), never a raw storage write. */
- pluginDecisions: {
- /** Every recorded decision, id → enabled. */
- all: (): Readonly<Record<string, boolean>> => $pluginDecisions.get(),
- /** One decision, or undefined when the user never made one. */
- get: (id: string): boolean | undefined => $pluginDecisions.get()[id],
- /** Flip one decision (persists + applies immediately). */
- set: (id: string, enabled: boolean): Promise<void> => setPluginEnabled(id, enabled)
- },
+ /** Typed capabilities bridge — see `./bridge.ts`. `pluginDecisions` is
+ * read-only: plugin toggling stays in the app's Plugins tab. */
+ skills,
+ toolsets,
+ profiles,
+ pluginDecisions,
/** Open a stored session the way core surfaces do. A plugin/Bot Mode open
* is navigation, not a workspace or chrome API-home switch —