The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(shared): fuzzyRank folds [-_.] to space on both sides like the desktop picker did
teknium13f0225951832
diff --git a/apps/desktop/src/components/model-picker.test.tsx b/apps/desktop/src/components/model-picker.test.tsxindex 432a2a77f82..1f309bee7fb 100644--- a/apps/desktop/src/components/model-picker.test.tsx+++ b/apps/desktop/src/components/model-picker.test.tsx@@ -178,4 +178,29 @@ describe('ModelPickerDialog search ranking', () => {expect(rows).toEqual(expected)})})++ // Regression guard: main folded `[-_.]` on both sides (foldIncludes); the+ // shared ranker must too, or a query typed with the "wrong" separator+ // drops every row while the highlighter (which still folds) disagrees.+ it.each([+ ['gpt.4o', 'gpt-4o'],+ ['claude_3', 'claude-3-opus'],+ ['qwen3-8', 'qwen3.8-flash']+ ])('separator variant %s still lists %s', async (query, expected) => {+ const catalog = ['gpt-4o', 'claude-3-opus', 'qwen3.8-flash']++ vi.mocked(requestModelOptions).mockResolvedValue({+ providers: [{ slug: 'nous', name: 'Nous', models: catalog, authenticated: true }]+ })+ renderPicker({ currentModel: 'gpt-4o', currentProvider: 'nous' })+ await screen.findByText('gpt-4o')++ fireEvent.change(screen.getByRole('combobox'), { target: { value: query } })++ await waitFor(() => {+ const rows = screen.getAllByRole('option').map(el => el.textContent?.trim())++ expect(rows).toContain(expected)+ })+ })})diff --git a/apps/shared/src/fuzzy.test.ts b/apps/shared/src/fuzzy.test.tsindex 4554b882595..58df2f1499e 100644--- a/apps/shared/src/fuzzy.test.ts+++ b/apps/shared/src/fuzzy.test.ts@@ -103,6 +103,21 @@ describe('fuzzyRank', () => {expect(ranked.map(r => r.item.i)).toEqual([0, 1, 2])})+ // Ids use hyphens, display names spaces, quants underscores, versions dots;+ // a user typing from memory picks any of them and must still get the row.+ it.each([+ ['gpt.4o', 'gpt-4o'],+ ['claude_3', 'claude-3-opus'],+ ['qwen3-8', 'qwen3.8-flash']+ ])('folds separators on both sides so %s finds %s', (query, expected) => {+ const catalog = ['gpt-4o', 'claude-3-opus', 'qwen3.8-flash', 'o1-preview']+ const ranked = fuzzyRank(catalog, query, m => m)++ expect(ranked[0]?.item).toBe(expected)+ // Positions still index the ORIGINAL target (fold is length-preserving).+ expect(ranked[0]!.positions.every(i => i >= 0 && i < expected.length)).toBe(true)+ })+it('matches across a derived key, not just the raw string', () => {const providers = [{ slug: 'openai', name: 'OpenAI' },diff --git a/apps/shared/src/fuzzy.ts b/apps/shared/src/fuzzy.tsindex 21b567d6297..d047099d4c4 100644--- a/apps/shared/src/fuzzy.ts+++ b/apps/shared/src/fuzzy.ts@@ -11,6 +11,12 @@// intentionally simple — no external dependency — but good enough to make// `son4` rank `claude-sonnet-4` above an incidental scattered hit.//+// Separators (`-`, `_`, `.`) fold to a space on BOTH sides before matching, so+// `gpt.4o`, `claude_3` and `qwen3-8` hit `gpt-4o`, `claude-3-opus` and+// `qwen3.8-flash` the way a user typing from memory expects. The fold is one+// char in, one char out, so returned positions still index the original+// target and a highlighter can apply the same fold without drift.+//// Shared by the desktop, web and TUI pickers via `@hermes/shared/fuzzy` so a// query ranks identically on every surface.@@ -23,6 +29,11 @@ export interface FuzzyMatch {const WORD_BOUNDARY = /[-_/.\s]/+/** Length-preserving search fold: lower-case and `[-_.]` → space. */+export function searchFold(value: string): string {+ return value.toLowerCase().replace(/[-_.]/g, ' ')+}+function isBoundary(target: string, index: number): boolean {if (index === 0) {return true@@ -49,8 +60,8 @@ export function fuzzyScore(target: string, query: string): FuzzyMatch | null {return { score: 0, positions: [] }}- const lowerTarget = target.toLowerCase()- const lowerQuery = query.toLowerCase()+ const lowerTarget = searchFold(target)+ const lowerQuery = searchFold(query)const positions: number[] = []let score = 0