Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(console): search shows managed agents, not legacy ones, under agent management (#975)
Louis Amaudruz0a05b8981814
diff --git a/console/apps/switch-console-desktop/src/main/core/search/search-service.db.test.ts b/console/apps/switch-console-desktop/src/main/core/search/search-service.db.test.tsindex 4f21ed666..3dff01c85 100644--- a/console/apps/switch-console-desktop/src/main/core/search/search-service.db.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/search/search-service.db.test.ts@@ -90,7 +90,7 @@ describe('searchService', () => {const result = searchService.search({query: 'reviewer',- includeSessions: true,+ includeLegacy: true,context: { locationId: 'loc-1', sessionId: 'session-1' },});@@ -104,10 +104,10 @@ describe('searchService', () => {it('returns the same results with a session context as without one', () => {searchService.initialize();- const withoutContext = searchService.search({ query: 'reviewer', includeSessions: true });+ const withoutContext = searchService.search({ query: 'reviewer', includeLegacy: true });const withContext = searchService.search({query: 'reviewer',- includeSessions: true,+ includeLegacy: true,context: { locationId: 'loc-1', sessionId: 'session-1' },});@@ -115,29 +115,30 @@ describe('searchService', () => {});});- // Under agent management Console's own sessions are the legacy way agents- // run, and the palette leaves them out.- describe('without sessions', () => {- it('matches agents but not sessions', () => {+ // Under agent management Console's own agents and sessions are the legacy+ // way agents run, and the palette leaves them out.+ describe('without legacy agents and sessions', () => {+ it('matches neither agents nor sessions', () => {searchService.initialize();- const result = searchService.search({ query: 'reviewer', includeSessions: false });+ const result = searchService.search({ query: 'reviewer', includeLegacy: false });- expect(result.status).toBe('ok');- expect(result.items.map((i) => [i.kind, i.title])).toEqual([['agent', 'reviewer-bot']]);+ expect(result).toEqual({ items: [], status: 'ok' });});it('still matches commands', () => {searchService.initialize();- const withSessions = searchService.search({ query: 'settings', includeSessions: true });+ const withLegacy = searchService.search({ query: 'settings', includeLegacy: true });- const result = searchService.search({ query: 'settings', includeSessions: false });+ const result = searchService.search({ query: 'settings', includeLegacy: false });expect(result.items.some((i) => i.kind === 'command')).toBe(true);- expect(result.items).toEqual(withSessions.items.filter((i) => i.kind !== 'session'));+ expect(result.items).toEqual(+ withLegacy.items.filter((i) => i.kind !== 'session' && i.kind !== 'agent')+ );});- it('fills the result cap with other kinds rather than dropped sessions', () => {+ it('fills the result cap with other kinds rather than dropped agents and sessions', () => {searchService.initialize();for (let i = 0; i < 40; i++) {fixture.sqlite@@ -146,22 +147,28 @@ describe('searchService', () => {VALUES ('session', ?, 'loc-1', NULL, ?, '')`).run(`s-${i}`, `crowded ${i}`);+ agentEvents._emit(+ 'agent:created',+ agentRecord({ id: `agent-crowded-${i}`, name: `crowded-bot-${i}`, locationId: 'loc-1' }),+ 'unknown'+ );}- agentEvents._emit(- 'agent:created',- agentRecord({ id: 'agent-crowded', name: 'crowded-bot', locationId: 'loc-1' }),- 'unknown'- );+ fixture.sqlite+ .prepare(+ `INSERT INTO search_index(item_type, item_id, location_id, session_id, title, keywords)+ VALUES ('command', 'crowded.command', NULL, NULL, 'Crowded command', '')`+ )+ .run();- const result = searchService.search({ query: 'crowded', includeSessions: false });+ const result = searchService.search({ query: 'crowded', includeLegacy: false });- expect(result.items.map((i) => i.title)).toEqual(['crowded-bot']);+ expect(result.items.map((i) => i.title)).toEqual(['Crowded command']);});it('offers no recent sessions for an empty query', () => {searchService.initialize();- expect(searchService.search({ query: '', includeSessions: false })).toEqual({+ expect(searchService.search({ query: '', includeLegacy: false })).toEqual({items: [],status: 'recents',});@@ -170,7 +177,7 @@ describe('searchService', () => {it('offers no recent sessions for a query too short to search', () => {searchService.initialize();- expect(searchService.search({ query: 'ab', includeSessions: false })).toEqual({+ expect(searchService.search({ query: 'ab', includeLegacy: false })).toEqual({items: [],status: 'query-too-short',});@@ -181,7 +188,7 @@ describe('searchService', () => {it('backfills existing agents so they are findable by name', () => {searchService.initialize();- const result = searchService.search({ query: 'reviewer-bot', includeSessions: true });+ const result = searchService.search({ query: 'reviewer-bot', includeLegacy: true });expect(result.status).toBe('ok');const agentHits = result.items.filter((i) => i.kind === 'agent');@@ -192,14 +199,14 @@ describe('searchService', () => {it('finds an agent by its provider, which is indexed as a keyword', () => {searchService.initialize();- const result = searchService.search({ query: 'codex', includeSessions: true });+ const result = searchService.search({ query: 'codex', includeLegacy: true });expect(titles(result.items.filter((i) => i.kind === 'agent'))).toEqual(['migration-bot']);});it('indexes an agent created after startup', () => {searchService.initialize();- expect(searchService.search({ query: 'newcomer', includeSessions: true }).items).toHaveLength(+ expect(searchService.search({ query: 'newcomer', includeLegacy: true }).items).toHaveLength(0);@@ -210,7 +217,7 @@ describe('searchService', () => {);expect(- titles(searchService.search({ query: 'newcomer', includeSessions: true }).items)+ titles(searchService.search({ query: 'newcomer', includeLegacy: true }).items)).toEqual(['newcomer-bot']);});@@ -225,10 +232,10 @@ describe('searchService', () => {);expect(- searchService.search({ query: 'reviewer-bot', includeSessions: true }).items+ searchService.search({ query: 'reviewer-bot', includeLegacy: true }).items).toHaveLength(0);expect(- titles(searchService.search({ query: 'auditor-bot', includeSessions: true }).items)+ titles(searchService.search({ query: 'auditor-bot', includeLegacy: true }).items)).toEqual(['auditor-bot']);});@@ -247,7 +254,7 @@ describe('searchService', () => {}expect(- searchService.search({ query: 'reviewer-bot', includeSessions: true }).items+ searchService.search({ query: 'reviewer-bot', includeLegacy: true }).items).toHaveLength(1);});@@ -257,14 +264,14 @@ describe('searchService', () => {agentEvents._emit('agent:deleted', 'agent-1');expect(- searchService.search({ query: 'reviewer-bot', includeSessions: true }).items+ searchService.search({ query: 'reviewer-bot', includeLegacy: true }).items).toHaveLength(0);});it('carries the location so the palette can navigate to it', () => {searchService.initialize();- const [hit] = searchService.search({ query: 'migration-bot', includeSessions: true }).items;+ const [hit] = searchService.search({ query: 'migration-bot', includeLegacy: true }).items;expect(hit).toMatchObject({ kind: 'agent', locationId: 'loc-2' });});@@ -274,7 +281,7 @@ describe('searchService', () => {it('reports an empty query as recents rather than as matches', () => {searchService.initialize();- const result = searchService.search({ query: '', includeSessions: true });+ const result = searchService.search({ query: '', includeLegacy: true });expect(result.status).toBe('recents');expect(titles(result.items)).toEqual(['Fix the reviewer crash']);@@ -285,7 +292,7 @@ describe('searchService', () => {it('reports a query with no usable term as query-too-short', () => {searchService.initialize();- const result = searchService.search({ query: 'ab', includeSessions: true });+ const result = searchService.search({ query: 'ab', includeLegacy: true });expect(result.status).toBe('query-too-short');expect(result.items.every((i) => i.kind === 'session')).toBe(true);@@ -294,7 +301,7 @@ describe('searchService', () => {it('treats a multi-word query of short terms as too short, not as a match', () => {searchService.initialize();- expect(searchService.search({ query: 'ab cd', includeSessions: true }).status).toBe(+ expect(searchService.search({ query: 'ab cd', includeLegacy: true }).status).toBe('query-too-short');});@@ -302,7 +309,7 @@ describe('searchService', () => {it('reports a usable query as ok', () => {searchService.initialize();- expect(searchService.search({ query: 'reviewer', includeSessions: true }).status).toBe('ok');+ expect(searchService.search({ query: 'reviewer', includeLegacy: true }).status).toBe('ok');});it('distinguishes a failed search from an empty one', () => {@@ -312,7 +319,7 @@ describe('searchService', () => {throw broken;});- const result = searchService.search({ query: 'reviewer', includeSessions: true });+ const result = searchService.search({ query: 'reviewer', includeLegacy: true });expect(result.status).toBe('failed');expect(result.items).toEqual([]);@@ -324,7 +331,7 @@ describe('searchService', () => {it('does not match every row of a kind by typing that kind name', () => {searchService.initialize();- const result = searchService.search({ query: 'session', includeSessions: true });+ const result = searchService.search({ query: 'session', includeLegacy: true });expect(result.items.filter((i) => i.kind === 'session')).toHaveLength(0);});@@ -332,10 +339,11 @@ describe('searchService', () => {it('matches mid-word, so a term inside a compound name is still found', () => {searchService.initialize();- expect(titles(searchService.search({ query: 'iewer', includeSessions: true }).items)).toEqual(- ['Fix the reviewer crash', 'reviewer-bot']- );- expect(titles(searchService.search({ query: 'rat', includeSessions: true }).items)).toEqual([+ expect(titles(searchService.search({ query: 'iewer', includeLegacy: true }).items)).toEqual([+ 'Fix the reviewer crash',+ 'reviewer-bot',+ ]);+ expect(titles(searchService.search({ query: 'rat', includeLegacy: true }).items)).toEqual(['migration-bot',]);});@@ -360,9 +368,9 @@ describe('searchService', () => {);}- expect(- titles(searchService.search({ query: 'test-tt', includeSessions: true }).items)- ).toEqual(['test-tt']);+ expect(titles(searchService.search({ query: 'test-tt', includeLegacy: true }).items)).toEqual(+ ['test-tt']+ );});// The short term still has to be present, it just cannot be asked of the@@ -376,14 +384,14 @@ describe('searchService', () => {);expect(- titles(searchService.search({ query: 'reviewer cc', includeSessions: true }).items)+ titles(searchService.search({ query: 'reviewer cc', includeLegacy: true }).items)).toEqual(['reviewer cc']);});it('matches a word after a separator, so a suffixed name is still findable', () => {searchService.initialize();- expect(titles(searchService.search({ query: 'bot', includeSessions: true }).items)).toEqual([+ expect(titles(searchService.search({ query: 'bot', includeLegacy: true }).items)).toEqual(['migration-bot','reviewer-bot',]);@@ -398,7 +406,7 @@ describe('searchService', () => {);// 'codex' is agent-2's provider (a keyword) and agent-4's name.- const items = searchService.search({ query: 'codex', includeSessions: true }).items;+ const items = searchService.search({ query: 'codex', includeLegacy: true }).items;expect(items.map((i) => i.title)).toEqual(['codex-runner', 'migration-bot']);});@@ -407,7 +415,7 @@ describe('searchService', () => {searchService.initialize();expect(- titles(searchService.search({ query: 'reviewer', includeSessions: true }).items)+ titles(searchService.search({ query: 'reviewer', includeLegacy: true }).items)).toEqual(['Fix the reviewer crash', 'reviewer-bot']);});@@ -418,11 +426,9 @@ describe('searchService', () => {searchService.initialize();expect(- searchService.search({ query: 'switch-console repo', includeSessions: true }).items+ searchService.search({ query: 'switch-console repo', includeLegacy: true }).items).toEqual([]);- expect(searchService.search({ query: 'other repo', includeSessions: true }).items).toEqual(- []- );+ expect(searchService.search({ query: 'other repo', includeLegacy: true }).items).toEqual([]);});});});diff --git a/console/apps/switch-console-desktop/src/main/core/search/search-service.ts b/console/apps/switch-console-desktop/src/main/core/search/search-service.tsindex b46901294..d399244fd 100644--- a/console/apps/switch-console-desktop/src/main/core/search/search-service.ts+++ b/console/apps/switch-console-desktop/src/main/core/search/search-service.ts@@ -118,9 +118,9 @@ class SearchService {this.seedCommands();}- search({ query, includeSessions, context }: CommandPaletteQuery): SearchResult {+ search({ query, includeLegacy, context }: CommandPaletteQuery): SearchResult {if (!query.trim()) {- return { items: includeSessions ? this.recents(context) : [], status: 'recents' };+ return { items: includeLegacy ? this.recents(context) : [], status: 'recents' };}const terms = queryTerms(query);@@ -132,7 +132,7 @@ class SearchService {const indexable = terms.filter((t) => t.length >= MIN_INDEXABLE_TERM);if (indexable.length === 0) {return {- items: includeSessions ? this.recents(context) : [],+ items: includeLegacy ? this.recents(context) : [],status: 'query-too-short',};}@@ -150,11 +150,11 @@ class SearchService {bm25(search_index) AS rankFROM search_indexWHERE search_index MATCH ?- AND (? OR item_type != 'session')+ AND (? OR item_type NOT IN ('session', 'agent'))ORDER BY rankLIMIT ?`)- .all(ftsQuery, includeSessions ? 1 : 0, FTS_CANDIDATE_LIMIT) as FtsRow[];+ .all(ftsQuery, includeLegacy ? 1 : 0, FTS_CANDIDATE_LIMIT) as FtsRow[];} catch (e) {log.error('SearchService: FTS query failed', { query, error: String(e) });return { items: [], status: 'failed' };diff --git a/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx b/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsxindex 8785ec05c..4b314b71b 100644--- a/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/command-palette/command-palette-modal.tsx@@ -4,6 +4,8 @@ import { Activity, DoorOpen, Globe, type LucideIcon, MessageSquare, Server } froimport { observer, useObserver } from 'mobx-react-lite';import React, { useCallback, useEffect, useMemo, useState } from 'react';import { agentChatsFlag } from '@renderer/features/chats/stores/agent-chats-flag';+import { managedAgentLabel } from '@renderer/features/managed-agents/managed-agent-state';+import { useManagedAgents } from '@renderer/features/managed-agents/use-managed-agents';import { REMOTE_HOSTS_QUERY_KEY } from '@renderer/features/remote-hosts/views/remote-hosts-view';import { getSessionStore } from '@renderer/features/sessions/stores/session-selectors';import { useAgentManagementMode } from '@renderer/features/sidebar/sidebar-grouped-list';@@ -15,6 +17,7 @@ import { switchRoomsStore } from '@renderer/features/switch-servers/switch-roomsimport { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { commandRegistry } from '@renderer/lib/commands/registry';import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';+import { failureText } from '@renderer/lib/errors/describe-failure';import { useDebounce } from '@renderer/lib/hooks/useDebounce';import { getEffectiveHotkey } from '@renderer/lib/hooks/useKeyboardShortcuts';import { rpc } from '@renderer/lib/ipc';@@ -27,16 +30,19 @@ import { Shortcut } from '@renderer/lib/ui/shortcut';import { cn } from '@renderer/utils/utils';import { ALL_COMMAND_DEFS, type CommandDef } from '@shared/commands';import type { CommandId } from '@shared/commands';+import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';import type { SearchItem, SearchResult } from '@shared/core/search';import { getCommandIcon } from './command-icons';-import { PaletteAgentItem } from './palette-agent-item';+import { PaletteAgentItem, PaletteManagedAgentItem } from './palette-agent-item';import { PALETTE_ITEM_CLASS } from './palette-item-styles';import { PaletteSessionItem } from './palette-session-item';import { ResourceMonitorView } from './resource-monitor-view';import {applyContextAffinity,indexedSearchLabel,+ instantMatchLabel,matchHosts,+ matchManagedAgents,matchRooms,matchServers,paletteSearchPlaceholder,@@ -187,9 +193,12 @@ export function CommandPaletteModal({const debouncedQuery = useDebounce(query, 100);const { navigate } = useNavigate();const queryClient = useQueryClient();- // Under agent management the sidebar files Console's own sessions under- // Legacy; the palette leaves them out entirely.- const includeSessions = !useAgentManagementMode();+ // Under agent management the sidebar files Console's own agents and+ // sessions under Legacy; the palette leaves them out entirely and offers the+ // server's managed agents instead.+ const managementMode = useAgentManagementMode();+ const includeLegacy = !managementMode;+ const managedAgents = useManagedAgents(managementMode ? switchServersStore.activeServerId : null);const handleClose = onClose;@@ -208,11 +217,11 @@ export function CommandPaletteModal({// Prefetch recents immediately on mount so the empty-query view is instant.useEffect(() => {void queryClient.prefetchQuery({- queryKey: ['cmdk-search', '', includeSessions, locationId, sessionId],+ queryKey: ['cmdk-search', '', includeLegacy, locationId, sessionId],queryFn: () =>rpc.search.commandPalette({query: '',- includeSessions,+ includeLegacy,context: { locationId, sessionId },}),staleTime: 5_000,@@ -221,11 +230,11 @@ export function CommandPaletteModal({}, []);const { data: searchResult = EMPTY_RESULT } = useQuery({- queryKey: ['cmdk-search', debouncedQuery, includeSessions, locationId, sessionId],+ queryKey: ['cmdk-search', debouncedQuery, includeLegacy, locationId, sessionId],queryFn: () =>rpc.search.commandPalette({query: debouncedQuery,- includeSessions,+ includeLegacy,context: { locationId, sessionId },}),// Keep results fresh for 5 s — re-opening the palette with the same query@@ -302,7 +311,11 @@ export function CommandPaletteModal({staleTime: 30_000,});const hostResults = matchHosts(hosts, debouncedQuery);- const rendererMatchCount = roomResults.length + serverResults.length + hostResults.length;+ const managedAgentResults = managementMode+ ? matchManagedAgents(managedAgents.data ?? [], debouncedQuery)+ : [];+ const rendererMatchCount =+ managedAgentResults.length + roomResults.length + serverResults.length + hostResults.length;const q = debouncedQuery.toLowerCase();const matchedResourceMonitor =@@ -368,6 +381,15 @@ export function CommandPaletteModal({});};+ const handleNavigateToManagedAgent = (agent: ManagedAgentView) => {+ handleClose();+ navigate('managedAgent', {+ serverId: agent.serverId,+ agentId: agent.agentId,+ name: managedAgentLabel(agent),+ });+ };+const handleNavigateToRoom = (item: SearchItem) => {handleClose();void openRoom(item.id);@@ -455,7 +477,7 @@ export function CommandPaletteModal({<Command.Inputvalue={query}onValueChange={setQuery}- placeholder={paletteSearchPlaceholder(includeSessions)}+ placeholder={paletteSearchPlaceholder(includeLegacy)}className="w-full bg-transparent px-3 py-3 text-sm outline-none placeholder:text-foreground/40"autoFocus/>@@ -474,11 +496,17 @@ export function CommandPaletteModal({the log for details.</div>)}+ {managementMode && managedAgents.error && (+ <div className="px-3 py-2 text-xs text-destructive">+ {failureText(managedAgents.error, 'Managed agents could not be listed.')} Agents are+ missing from these results.+ </div>+ )}{searchResult.status === 'query-too-short' && (<div className="px-3 py-6 text-center text-sm text-foreground/40">- Type at least 3 characters to search {indexedSearchLabel(includeSessions)}.+ Type at least 3 characters to search {indexedSearchLabel(includeLegacy)}.{rendererMatchCount > 0 &&- ' Rooms, servers and hosts are matched from the first character.'}+ ` ${instantMatchLabel(includeLegacy)} are matched from the first character.`}</div>)}<PaletteResultGroup@@ -486,6 +514,18 @@ export function CommandPaletteModal({items={indexed.agent}onSelect={handleNavigateToAgent}/>+ {managedAgentResults.length > 0 && (+ <Command.Group heading="Agents" className={GROUP_CLASS}>+ {managedAgentResults.map((agent) => (+ <PaletteManagedAgentItem+ key={`managed-agent:${agent.agentId}`}+ value={`managed-agent:${agent.agentId}`}+ agent={agent}+ onSelect={() => handleNavigateToManagedAgent(agent)}+ />+ ))}+ </Command.Group>+ )}{indexed.session.length > 0 && (<Command.Group heading="Sessions" className={GROUP_CLASS}>{indexed.session.map(renderSessionResult)}diff --git a/console/apps/switch-console-desktop/src/renderer/features/command-palette/palette-agent-item.tsx b/console/apps/switch-console-desktop/src/renderer/features/command-palette/palette-agent-item.tsxindex 38578284f..1970c0a42 100644--- a/console/apps/switch-console-desktop/src/renderer/features/command-palette/palette-agent-item.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/command-palette/palette-agent-item.tsx@@ -2,10 +2,13 @@ import { Command } from 'cmdk';import { Bot } from 'lucide-react';import { observer } from 'mobx-react-lite';import { agentsStore } from '@renderer/features/locations/stores/agents-store';+import { managedAgentLabel } from '@renderer/features/managed-agents/managed-agent-state';import { AgentAvatar } from '@renderer/lib/components/agent-avatar';import { AgentIcon } from '@renderer/lib/components/agent-icon';import { sidebarStore } from '@renderer/lib/stores/app-state';import { useAgentIconUrl } from '@renderer/lib/stores/use-workspace-agents';+import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';+import { isValidProviderId } from '@shared/core/providers/agent-provider-registry';import type { SearchItem } from '@shared/core/search';import { PALETTE_ITEM_CLASS } from './palette-item-styles';@@ -56,3 +59,39 @@ export const PaletteAgentItem = observer(function PaletteAgentItem({</Command.Item>);});++/** A managed agent's row: the same layout, drawn from the server's view of it. */+export const PaletteManagedAgentItem = observer(function PaletteManagedAgentItem({+ agent,+ value,+ onSelect,+}: {+ agent: ManagedAgentView;+ value: string;+ onSelect: () => void;+}) {+ const label = managedAgentLabel(agent);+ const provider = agent.definition.provider;+ return (+ <Command.Item value={value} onSelect={onSelect} className={PALETTE_ITEM_CLASS}>+ <span className="flex size-3.5 shrink-0 items-center justify-center">+ <AgentAvatar+ name={label}+ iconUrl={agent.iconUrl}+ serverId={agent.serverId}+ size={16}+ className="-mx-px bg-transparent"+ />+ </span>+ <span className="flex min-w-0 flex-1 items-center gap-1.5">+ <span className="truncate">{label}</span>+ {!sidebarStore.hideProviderMark &&+ (isValidProviderId(provider) ? (+ <AgentIcon id={provider} size={12} className="h-3 w-3 shrink-0" />+ ) : (+ <Bot className="h-3 w-3 shrink-0 text-foreground-muted" />+ ))}+ </span>+ </Command.Item>+ );+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts b/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.tsindex 0980ab663..7b7035218 100644--- a/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/command-palette/search-utils.ts@@ -1,3 +1,5 @@+import { managedAgentLabel } from '@renderer/features/managed-agents/managed-agent-state';+import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';import { matchQuality, type SearchItem, type SearchItemKind } from '@shared/core/search';import type { RemoteRoomSummary, SwitchServer } from '@shared/core/switch-servers/switch-servers';@@ -19,13 +21,18 @@ export function applyContextAffinity(}/** The indexed kinds a search covers, for the hint under a too-short query. */-export function indexedSearchLabel(includeSessions: boolean): string {- return includeSessions ? 'agents, sessions and commands' : 'agents and commands';+export function indexedSearchLabel(includeLegacy: boolean): string {+ return includeLegacy ? 'agents, sessions and commands' : 'commands';+}++/** The kinds matched from the first character, for the same hint. */+export function instantMatchLabel(includeLegacy: boolean): string {+ return includeLegacy ? 'Rooms, servers and hosts' : 'Agents, rooms, servers and hosts';}/** The search box's placeholder, naming only what the palette will find. */-export function paletteSearchPlaceholder(includeSessions: boolean): string {- return includeSessions+export function paletteSearchPlaceholder(includeLegacy: boolean): string {+ return includeLegacy? 'Search agents, sessions, rooms, servers, actions…': 'Search agents, rooms, servers, actions…';}@@ -99,6 +106,26 @@ export function matchRooms(rooms: RemoteRoomSummary[], query: string): SearchIte);}+/**+ * Matches the active server's managed agents, by the name they are shown under+ * and by their Switch name. These are the agents under agent management; the+ * Console agents the index holds are the legacy ones.+ */+export function matchManagedAgents(agents: ManagedAgentView[], query: string): ManagedAgentView[] {+ const q = query.trim().toLowerCase();+ if (!q) return [];++ return agents+ .flatMap((agent) => {+ const label = managedAgentLabel(agent);+ const score = rank(label, q) ?? rank(agent.name, q);+ return score === null ? [] : [{ agent, label, score }];+ })+ .sort((a, b) => a.score - b.score || a.label.localeCompare(b.label))+ .slice(0, RENDERER_RESULT_LIMIT)+ .map(({ agent }) => agent);+}+/** Matches Switch servers. Also matches on the server's address, since a server* is as often recognised by where it lives as by what it was named. */export function matchServers(servers: SwitchServer[], query: string): SearchItem[] {diff --git a/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.tsindex 7ce551acf..4a2c8fe8f 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/palette-search-utils.test.ts@@ -2,12 +2,15 @@ import { describe, expect, it } from 'vitest';import {applyContextAffinity,indexedSearchLabel,+ instantMatchLabel,matchHosts,+ matchManagedAgents,matchRooms,matchServers,paletteSearchPlaceholder,sectionResults,} from '@renderer/features/command-palette/search-utils';+import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';import type { SearchItem } from '@shared/core/search';import type { RemoteRoomSummary, SwitchServer } from '@shared/core/switch-servers/switch-servers';@@ -266,6 +269,62 @@ describe('palette copy', () => {it('still names the kinds that stay searchable', () => {expect(paletteSearchPlaceholder(false)).toBe('Search agents, rooms, servers, actions…');- expect(indexedSearchLabel(false)).toBe('agents and commands');+ expect(indexedSearchLabel(false)).toBe('commands');+ });++ it('names managed agents among the kinds matched from the first character', () => {+ expect(instantMatchLabel(false)).toBe('Agents, rooms, servers and hosts');+ expect(instantMatchLabel(true)).toBe('Rooms, servers and hosts');+ });+});++function managedAgent(+ over: Pick<ManagedAgentView, 'agentId' | 'name'> & Partial<ManagedAgentView>+): ManagedAgentView {+ return {+ serverId: 'server-1',+ workspaceId: 'workspace-1',+ displayName: null,+ iconUrl: null,+ description: '',+ machine: null,+ desiredState: 'running',+ revision: 1,+ definition: {+ provider: 'claude',+ model: null,+ advancedConfig: {},+ instructions: '',+ autoMode: true,+ autoApprove: false,+ directory: null,+ isolation: 'shared',+ },+ status: null,+ ...over,+ };+}++describe('matchManagedAgents', () => {+ const agents = [+ managedAgent({ agentId: 'a-1', name: 'notes-helper', displayName: 'Notes Helper' }),+ managedAgent({ agentId: 'a-2', name: 'switch-buddy-ada' }),+ managedAgent({ agentId: 'a-3', name: 'release-notes' }),+ ];++ it('matches nothing for an empty query', () => {+ expect(matchManagedAgents(agents, ' ')).toEqual([]);+ });++ it('matches the shown name and the Switch name, prefix matches first', () => {+ expect(matchManagedAgents(agents, 'notes').map((agent) => agent.agentId)).toEqual([+ 'a-1',+ 'a-3',+ ]);+ expect(matchManagedAgents(agents, 'notes-help').map((agent) => agent.agentId)).toEqual(['a-1']);+ });++ it('matches queries shorter than the index needs', () => {+ expect(matchManagedAgents(agents, 'sw').map((agent) => agent.agentId)).toEqual(['a-2']);});});diff --git a/console/apps/switch-console-desktop/src/shared/core/search.ts b/console/apps/switch-console-desktop/src/shared/core/search.tsindex 4329609cc..f9e3d31ee 100644--- a/console/apps/switch-console-desktop/src/shared/core/search.ts+++ b/console/apps/switch-console-desktop/src/shared/core/search.ts@@ -81,12 +81,12 @@ export function matchQuality(text: string, term: string): MatchQuality {export interface CommandPaletteQuery {query: string;/**- * Whether Console's own sessions are results, as matches and as recents.- * Off on a server that runs agent management, where those sessions are the- * legacy way agents run and the palette offers agents, rooms and chats- * instead.+ * Whether Console's own agents and sessions are results, sessions as matches+ * and as recents. Off on a server that runs agent management, where those+ * are the legacy way agents run and the palette offers managed agents, rooms+ * and chats instead.*/- includeSessions: boolean;+ includeLegacy: boolean;context?: {sessionId?: string;locationId?: string;