feat(desktop): search sessions by id

This commit is contained in:
Harry Riddle
2026-06-04 07:49:34 -07:00
committed by Teknium
parent 62f0cfd902
commit 9ecc331be8
7 changed files with 289 additions and 13 deletions
+2 -2
View File
@@ -35,6 +35,7 @@ import {
} from '@/components/ui/sidebar'
import { Skeleton } from '@/components/ui/skeleton'
import { searchSessions, type SessionInfo, type SessionSearchResult } from '@/hermes'
import { sessionMatchesSearch } from '@/lib/session-search'
import { cn } from '@/lib/utils'
import {
$panesFlipped,
@@ -330,11 +331,10 @@ export function ChatSidebar({
return []
}
const needle = trimmedQuery.toLowerCase()
const out = new Map<string, SessionInfo>()
for (const s of sortedSessions) {
if (`${s.title ?? ''} ${s.preview ?? ''} ${s.cwd ?? ''}`.toLowerCase().includes(needle)) {
if (sessionMatchesSearch(s, trimmedQuery)) {
out.set(s.id, s)
}
}
@@ -0,0 +1,58 @@
import { describe, expect, it } from 'vitest'
import type { SessionInfo } from '@/types/hermes'
import { sessionMatchesSearch } from './session-search'
function makeSession(overrides: Partial<SessionInfo> = {}): SessionInfo {
return {
archived: false,
cwd: '/home/user/projects/hermes-agent',
ended_at: null,
id: '20260603_090200_abcd12',
input_tokens: 0,
is_active: false,
last_active: 1_000,
message_count: 2,
model: 'claude',
output_tokens: 0,
preview: 'Fix Desktop session search',
source: 'cli',
started_at: 1_000,
title: 'Desktop Search Feature',
tool_call_count: 0,
...overrides
}
}
describe('sessionMatchesSearch', () => {
it('matches loaded sessions by full and partial session id', () => {
const session = makeSession()
expect(sessionMatchesSearch(session, '20260603_090200_abcd12')).toBe(true)
expect(sessionMatchesSearch(session, '090200')).toBe(true)
expect(sessionMatchesSearch(session, 'ABCD12')).toBe(true)
})
it('matches projected compression sessions by lineage root id', () => {
const session = makeSession({
_lineage_root_id: '20260602_235959_root99',
id: '20260603_010000_tip01'
})
expect(sessionMatchesSearch(session, 'root99')).toBe(true)
expect(sessionMatchesSearch(session, '20260602')).toBe(true)
})
it('preserves title, preview, and workspace matching', () => {
const session = makeSession()
expect(sessionMatchesSearch(session, 'desktop search')).toBe(true)
expect(sessionMatchesSearch(session, 'session search')).toBe(true)
expect(sessionMatchesSearch(session, 'hermes-agent')).toBe(true)
})
it('does not match unrelated queries', () => {
expect(sessionMatchesSearch(makeSession(), 'totally-unrelated')).toBe(false)
})
})
+19
View File
@@ -0,0 +1,19 @@
import type { SessionInfo } from '@/types/hermes'
import { sessionTitle } from './chat-runtime'
export function sessionMatchesSearch(session: SessionInfo, query: string): boolean {
const needle = query.trim().toLowerCase()
if (!needle) {
return true
}
return [
session.id,
session._lineage_root_id ?? '',
sessionTitle(session),
session.preview ?? '',
session.cwd ?? ''
].some(value => value.toLowerCase().includes(needle))
}