From 4adcef2932ec9440ac46d21069fdf26500223405 Mon Sep 17 00:00:00 2001 From: cspiritsong <215228390+cspiritsong@users.noreply.github.com> Date: Thu, 17 Sep 2026 19:26:58 +0800 Subject: [PATCH] fix(desktop): scope sidebar session search to active profile --- apps/desktop/src/api/sessions.ts | 12 ++++++++++-- apps/desktop/src/app/chat/sidebar/index.tsx | 20 +++++++++++++++----- apps/desktop/src/hermes.test.ts | 12 ++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/api/sessions.ts b/apps/desktop/src/api/sessions.ts index 8ad982da8c129..64f28c31bceb3 100644 --- a/apps/desktop/src/api/sessions.ts +++ b/apps/desktop/src/api/sessions.ts @@ -379,9 +379,17 @@ export function setSessionUnreadRemote(id: string, unread: boolean, profile?: st }) } -export function searchSessions(query: string): Promise { +export function searchSessions(query: string, profile?: ProfileScope): Promise { + const scoped = sessionScoped(profile) + const params = new URLSearchParams({ q: query }) + + if (scoped.profile) { + params.set('profile', scoped.profile) + } + return hermesApi({ - path: `/api/sessions/search?q=${encodeURIComponent(query)}` + ...scoped, + path: `/api/sessions/search?${params.toString()}` }) } diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx index 99d31d6cd2532..74f43c7de221f 100644 --- a/apps/desktop/src/app/chat/sidebar/index.tsx +++ b/apps/desktop/src/app/chat/sidebar/index.tsx @@ -460,6 +460,7 @@ export function ChatSidebar({ const newSessionKbd = newSessionCombo ? comboTokens(newSessionCombo) : [] const [searchQuery, setSearchQuery] = useState('') const [serverMatches, setServerMatches] = useState([]) + const [serverMatchesScope, setServerMatchesScope] = useState('') const [searchPending, setSearchPending] = useState(false) const [newSessionKbdFlash, setNewSessionKbdFlash] = useState(false) const [messagingLoadMorePending, setMessagingLoadMorePending] = useState>({}) @@ -647,10 +648,15 @@ export function ChatSidebar({ // Full-text search across *all* sessions (not just the loaded page) so 699 // sessions stay findable. Debounced; loaded sessions are matched instantly - // client-side and merged ahead of the server hits. + // client-side and merged ahead of the server hits. Server hits are scoped to + // the current profile scope: a concrete profile searches only its own state.db, + // and All Profiles searches everything. + const searchScope = showAllProfiles ? ALL_PROFILES : profileScope + useEffect(() => { if (!trimmedQuery) { setServerMatches([]) + setServerMatchesScope('') setSearchPending(false) return @@ -658,13 +664,16 @@ export function ChatSidebar({ let cancelled = false + setServerMatches([]) + setServerMatchesScope(searchScope) setSearchPending(true) const id = window.setTimeout(() => { - void searchSessions(trimmedQuery) + void searchSessions(trimmedQuery, showAllProfiles ? undefined : profileScope) .then(res => { if (!cancelled) { setServerMatches(res.results) + setServerMatchesScope(searchScope) } }) .catch(() => undefined) @@ -679,13 +688,14 @@ export function ChatSidebar({ cancelled = true window.clearTimeout(id) } - }, [trimmedQuery]) + }, [trimmedQuery, searchScope, showAllProfiles, profileScope]) const searchResults = useMemo(() => { if (!trimmedQuery) { return [] } + const matchesForCurrentScope = serverMatchesScope === searchScope ? serverMatches : [] const out = new Map() for (const s of sortedSessions) { @@ -694,7 +704,7 @@ export function ChatSidebar({ } } - for (const match of serverMatches) { + for (const match of matchesForCurrentScope) { if (out.has(match.session_id)) { continue } @@ -704,7 +714,7 @@ export function ChatSidebar({ } return [...out.values()] - }, [trimmedQuery, sortedSessions, serverMatches, sessionByAnyId]) + }, [trimmedQuery, sortedSessions, serverMatches, serverMatchesScope, searchScope, sessionByAnyId]) const unpinnedAgentSessions = useMemo( () => sortedSessions.filter(s => !isPinnedSession(s)), diff --git a/apps/desktop/src/hermes.test.ts b/apps/desktop/src/hermes.test.ts index bb06f19468f0c..54725bd7679b0 100644 --- a/apps/desktop/src/hermes.test.ts +++ b/apps/desktop/src/hermes.test.ts @@ -27,6 +27,7 @@ import { listSidebarSessions, pluginSocket, resetSidebarBatchCapability, + searchSessions, setApiRequestConnection, setApiRequestProfile, speakText, @@ -84,6 +85,17 @@ describe('Hermes REST helpers', () => { ) }) + it('routes a session search to the selected profile backend', async () => { + api.mockResolvedValue({ results: [] }) + + await searchSessions('attendance audit', 'sabby') + + expect(api).toHaveBeenCalledWith({ + path: '/api/sessions/search?q=attendance+audit&profile=sabby', + profile: 'sabby' + }) + }) + it('batches the sidebar slices into a single request with per-slice limits + excludes', async () => { api.mockResolvedValue({ recents: { sessions: [] }, cron: { sessions: [] }, messaging: { sessions: [] } })