Skip to content

The agent that grows with you

fix(desktop): scope terminal backend picker to profile

1052326311885a37658ad3
diff --git a/apps/desktop/src/api/toolsets.ts b/apps/desktop/src/api/toolsets.ts
index 862c0fc521d..4b5424574f7 100644
--- a/apps/desktop/src/api/toolsets.ts
+++ b/apps/desktop/src/api/toolsets.ts
@@ -109,16 +109,19 @@ export function runToolsetPostSetup(
})
}
-export function getTerminalBackends(): Promise<TerminalBackendsResponse> {
- return hermesApi<TerminalBackendsResponse>({
- ...profileScoped(),
+export function getTerminalBackends(profile?: ProfileScope): Promise<TerminalBackendsResponse> {
+ return window.hermesDesktop.api<TerminalBackendsResponse>({
+ ...capabilityScoped(profile),
path: '/api/tools/terminal/backends'
})
}
-export function selectTerminalBackend(backend: string): Promise<{ ok: boolean; backend: string }> {
- return hermesApi<{ ok: boolean; backend: string }>({
- ...profileScoped(),
+export function selectTerminalBackend(
+ backend: string,
+ profile?: ProfileScope
+): Promise<{ ok: boolean; backend: string }> {
+ return window.hermesDesktop.api<{ ok: boolean; backend: string }>({
+ ...capabilityScoped(profile),
path: '/api/tools/terminal/backend',
method: 'PUT',
body: { backend }
diff --git a/apps/desktop/src/app/capabilities/toolsets/toolset-detail.tsx b/apps/desktop/src/app/capabilities/toolsets/toolset-detail.tsx
index de16e13ea46..dca646aa4fc 100644
--- a/apps/desktop/src/app/capabilities/toolsets/toolset-detail.tsx
+++ b/apps/desktop/src/app/capabilities/toolsets/toolset-detail.tsx
@@ -77,7 +77,9 @@ export function ToolsetDetail({
config option users kept missing because its only GUI home was the
generic Settings → Config editor. */}
{toolset.name === 'browser' && <BrowserRealProfilePanel profile={profile} />}
- {toolset.name === 'terminal' && <TerminalBackendPanel onConfiguredChange={onConfiguredChange} />}
+ {toolset.name === 'terminal' && (
+ <TerminalBackendPanel onConfiguredChange={onConfiguredChange} profile={profile} />
+ )}
<ToolsetConfigPanel
key={`${toolset.name}:${profileScopeKey(profile)}`}
onConfiguredChange={onConfiguredChange}
diff --git a/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx b/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx
index 07829010f2b..54f279fd991 100644
--- a/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx
+++ b/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx
@@ -1,6 +1,7 @@
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { ProfileScope } from '@/api/client'
import { deferred } from '@/test/deferred'
import type { TerminalBackendsResponse } from '@/types/hermes'
@@ -9,8 +10,8 @@ const selectTerminalBackend = vi.fn()
const confirmMock = vi.fn()
vi.mock('@/hermes', () => ({
- getTerminalBackends: () => getTerminalBackends(),
- selectTerminalBackend: (backend: string) => selectTerminalBackend(backend)
+ getTerminalBackends: (profile?: ProfileScope) => getTerminalBackends(profile),
+ selectTerminalBackend: (backend: string, profile?: ProfileScope) => selectTerminalBackend(backend, profile)
}))
vi.mock('@/store/confirm', () => ({
@@ -71,6 +72,22 @@ afterEach(() => {
})
describe('TerminalBackendPanel', () => {
+ it('reads and writes the profile currently selected by Capabilities', async () => {
+ const { TerminalBackendPanel } = await import('./terminal-backend-panel')
+ const { rerender } = render(<TerminalBackendPanel profile="research" />)
+
+ for (const profile of ['research', 'coder', 'research']) {
+ rerender(<TerminalBackendPanel profile={profile} />)
+ await waitFor(() => expect(getTerminalBackends).toHaveBeenLastCalledWith(profile))
+ await waitFor(() =>
+ expect(screen.getByRole('button', { name: /Local/ }).getAttribute('aria-pressed')).toBe('true')
+ )
+ fireEvent.click(screen.getByRole('button', { name: /SSH/ }))
+ await waitFor(() => expect(selectTerminalBackend).toHaveBeenLastCalledWith('ssh', profile))
+ await waitFor(() => expect(screen.getByRole('button', { name: /SSH/ }).getAttribute('aria-pressed')).toBe('true'))
+ }
+ })
+
it('marks the active backend as pressed', async () => {
render(<TerminalBackendPanel onConfiguredChange={vi.fn()} />)
@@ -84,7 +101,7 @@ describe('TerminalBackendPanel', () => {
fireEvent.click(await screen.findByRole('button', { name: /SSH/ }))
- await waitFor(() => expect(selectTerminalBackend).toHaveBeenCalledWith('ssh'))
+ await waitFor(() => expect(selectTerminalBackend).toHaveBeenCalledWith('ssh', undefined))
await waitFor(() => expect(onConfiguredChange).toHaveBeenCalled())
// Active highlight moves without a refetch.
const ssh = screen.getByRole('button', { name: /SSH/ })
@@ -111,7 +128,7 @@ describe('TerminalBackendPanel', () => {
confirmGate.resolve(true)
- await waitFor(() => expect(selectTerminalBackend).toHaveBeenCalledWith('docker'))
+ await waitFor(() => expect(selectTerminalBackend).toHaveBeenCalledWith('docker', undefined))
// The guidance detail stays visible on the now-active row.
expect(screen.getByText(/Docker daemon not reachable/)).toBeTruthy()
})
diff --git a/apps/desktop/src/app/settings/terminal-backend-panel.tsx b/apps/desktop/src/app/settings/terminal-backend-panel.tsx
index db3a19ae268..508b4ee1698 100644
--- a/apps/desktop/src/app/settings/terminal-backend-panel.tsx
+++ b/apps/desktop/src/app/settings/terminal-backend-panel.tsx
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useState } from 'react'
+import type { ProfileScope } from '@/api/client'
import { Button } from '@/components/ui/button'
import { getTerminalBackends, selectTerminalBackend } from '@/hermes'
import { useI18n } from '@/i18n'
@@ -15,6 +16,8 @@ interface TerminalBackendPanelProps {
/** Re-read the parent toolset list after a backend change so any derived
* pills stay in sync. */
onConfiguredChange?: () => void
+ /** Capabilities can edit a profile other than the app-wide active one. */
+ profile?: ProfileScope
}
function StatusPill({ backend }: { backend: TerminalBackendInfo }) {
@@ -48,7 +51,7 @@ function StatusPill({ backend }: { backend: TerminalBackendInfo }) {
* immediately and every later session inherits a backend with no terminal or
* file tools, so one ambient click must not do that silently.
*/
-export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPanelProps) {
+export function TerminalBackendPanel({ onConfiguredChange, profile }: TerminalBackendPanelProps) {
const { t } = useI18n()
const copy = t.settings.toolsets.terminalBackend
const [data, setData] = useState<TerminalBackendsResponse | null>(null)
@@ -59,13 +62,13 @@ export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPane
setLoading(true)
try {
- setData(await getTerminalBackends())
+ setData(await getTerminalBackends(profile))
} catch (err) {
notifyError(err, copy.failedLoad)
} finally {
setLoading(false)
}
- }, [copy.failedLoad])
+ }, [copy.failedLoad, profile])
useEffect(() => {
void refresh()
@@ -93,7 +96,7 @@ export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPane
}
}
- await selectTerminalBackend(backend.name)
+ await selectTerminalBackend(backend.name, profile)
// Mirror the backend write locally so the active highlight tracks the
// new selection without a refetch (probes are unchanged by a select).
setData(current =>
diff --git a/apps/desktop/src/hermes-capability-scope.test.ts b/apps/desktop/src/hermes-capability-scope.test.ts
index e7c7b097983..5298251977c 100644
--- a/apps/desktop/src/hermes-capability-scope.test.ts
+++ b/apps/desktop/src/hermes-capability-scope.test.ts
@@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { approvePairing, getMessagingPlatforms } from './api/messaging'
import { getAuxiliaryModels, getGlobalModelInfo } from './api/models'
import { getOfficialSkills, getSkillHubSources } from './api/skills'
-import { getToolsetConfig } from './api/toolsets'
+import { getTerminalBackends, getToolsetConfig, selectTerminalBackend } from './api/toolsets'
import {
getHermesConfigRecord,
getMcpCatalog,
@@ -78,6 +78,30 @@ describe('capability helpers are connection-scoped', () => {
expect(last().connectionId).toBe('gw-tailscale')
})
+ it('routes terminal backend reads and writes through the rendered capability scope', () => {
+ setApiRequestProfile('stale-sidebar-profile')
+ setApiRequestConnection('gw-tailscale')
+
+ for (const profile of ['research', 'coder', 'research']) {
+ void getTerminalBackends(profile)
+ expect(last()).toMatchObject({
+ connectionId: 'gw-tailscale',
+ path: '/api/tools/terminal/backends',
+ priority: 'foreground',
+ profile
+ })
+
+ void selectTerminalBackend('docker', { connectionId: 'homelab', profile })
+ expect(last()).toMatchObject({
+ body: { backend: 'docker' },
+ connectionId: 'homelab',
+ method: 'PUT',
+ path: '/api/tools/terminal/backend',
+ profile
+ })
+ }
+ })
+
it('marks an explicitly scoped Settings / Capabilities read as foreground (#111651)', () => {
// A scope-selector pick is a visible user action: its cold dial must take
// the pool's reserved foreground slot instead of queueing behind hydration.