From f07bf8544c73ee937f377be2039ca08b22a34b08 Mon Sep 17 00:00:00 2001 From: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com> Date: Mon, 21 Sep 2026 14:11:40 -0400 Subject: [PATCH] feat(session-search): sort search results by newest, and break relevance ties by recency (#21863) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(session-search): sort search results by newest, and break relevance ties by recency Results were ordered by match score alone with the session id as the tiebreak, so equally good matches came out in an arbitrary order and nothing ever favoured recent work. The Sort menu now offers Most relevant and Newest while the box has text; the engine already knew both orders and the all-computers merge already honoured the newest one, so only the panel had to ask. Under Most relevant, equal scores now go to the newer session. The choice persists with the other view options, separately from the list's own Last updated / Created sort. * fix(session-search): label results by the order they are in The header subtitle and the results group said "best matches" whichever sort was chosen; under Newest they now say so. The panel's scope state and its two context effects move to use-ai-vault-panel-scope.ts, which keeps the panel under the line cap and gives that behaviour a name. * feat(session-search): move search sort onto a results bar above the hits Search mode gets a bar in the group header's place: the hit count on the left, a ghost menu button on the right that names the current order and opens the two-item radio group. The filter menu's Sort section keeps one meaning again (Last updated / Created), the header subtitle stops reporting sort, and search rows run flat with no group header. * style(session-search): drop the icons from the results-bar sort menu and match its text size * feat(session-search): one sort bar above the list in both modes Filters stay behind the header filter icon; sort moves onto the bar directly above the session list, in browse mode as well as search. The bar is mode-agnostic: it takes a label, the selected value, a typed option list, and a callback, and the panel configures it twice. - rename AiVaultSearchResultsBar to AiVaultSessionListBar and generalize it - add ai-vault-sort-options for the two option lists and their aria labels - drop the Sort section from the filter menu and stop counting sort in the badge - header subtitle now reads "Indexed history" in both modes * feat(session-search): count sessions plainly and offer Show more when the scan fills its depth * fix(session-search): step history depth 250 at a time and keep Show more visible while the rescan runs * style(session-search): let the sort menu hug its two options * fix(session-search): show more reads the depth its rows came from The row inferred "a deeper rescan is running" from the selected depth minus one page, which at the default depth is zero, so every foreground scan with at least one session painted a disabled "Loading more sessions…" footer the scan had room for. The scan now publishes the depth it ran at beside its sessions, and the row compares the two: it survives the rescan because that depth trails the selected one until the deeper scan lands. Drops the stepping arithmetic and nextAiVaultSessionLimit, and moves the row out of the menu file it was sharing. * refactor(session-search): an untitled group is what hides a header Search mode said "no group headers" twice, in two files, both keyed off the same flag: an empty label in the filters hook and a hideGroupHeaders prop on the list. The label is now the only fact. A null label means the group has no header of its own, the list renders its rows flat, and the prop is gone. The shared group type keeps its string label so the mobile sections that map it are untouched; the nullable label is the renderer list's own type. * refactor(session-search): plain labels, and a browse bar that can report zero Three small simplifications around the list bar: - The browse bar is guarded on the loaded history rather than the filtered rows, so "0 of 250 sessions" can actually appear when filters hide everything and the sort control stays reachable. Search keeps its own guard. - The two count labels were components whose whole body was a ternary over translate; they are functions returning a string, and the bar's label prop is a string. - The persistence guards stop being exported with no caller outside the file, and the search-sort guard reads the AI_VAULT_SEARCH_SORTS list instead of respelling the union. --- .../session-search-hit-ranking.test.ts | 9 ++ .../session-search-hit-ranking.ts | 7 +- .../AiVaultPanel.legacy-filter.test.tsx | 90 ++++++++++++++++- .../components/right-sidebar/AiVaultPanel.tsx | 93 +++++++++--------- .../right-sidebar/AiVaultPanelControls.tsx | 29 +----- .../AiVaultPanelHeader.focus.test.tsx | 4 - .../right-sidebar/AiVaultPanelHeader.tsx | 48 ++------- .../right-sidebar/AiVaultSessionLimitMenu.tsx | 4 +- .../AiVaultSessionListBar.test.tsx | 97 +++++++++++++++++++ .../right-sidebar/AiVaultSessionListBar.tsx | 88 +++++++++++++++++ .../AiVaultSessionVirtualList.tsx | 11 ++- .../AiVaultShowMoreSessionsRow.test.tsx | 86 ++++++++++++++++ .../AiVaultShowMoreSessionsRow.tsx | 45 +++++++++ .../right-sidebar/ai-vault-applied-scan.ts | 27 ++++++ .../ai-vault-search-scope-identity.test.tsx | 4 +- .../right-sidebar/ai-vault-session-filters.ts | 21 ++-- .../right-sidebar/ai-vault-session-limit.ts | 11 ++- .../right-sidebar/ai-vault-session-refresh.ts | 17 ++-- .../right-sidebar/ai-vault-sort-options.ts | 48 +++++++++ .../ai-vault-view-defaults.test.ts | 10 +- .../right-sidebar/ai-vault-view-defaults.ts | 5 +- .../ai-vault-view-options-persistence.test.ts | 7 ++ .../ai-vault-view-options-persistence.ts | 12 +++ .../right-sidebar/use-ai-vault-panel-scope.ts | 56 +++++++++++ .../use-ai-vault-search.test.tsx | 33 ++++++- .../right-sidebar/use-ai-vault-search.ts | 14 ++- .../use-persisted-ai-vault-view-options.ts | 12 +++ src/renderer/src/i18n/locales/en.json | 19 ++-- src/renderer/src/i18n/locales/es.json | 3 - src/renderer/src/i18n/locales/fr.json | 3 - src/renderer/src/i18n/locales/ja.json | 3 - src/renderer/src/i18n/locales/ko.json | 3 - src/renderer/src/i18n/locales/zh.json | 3 - src/shared/ai-vault-search-contract.ts | 8 +- src/shared/ai-vault-types.ts | 3 + 35 files changed, 735 insertions(+), 198 deletions(-) create mode 100644 src/renderer/src/components/right-sidebar/AiVaultSessionListBar.test.tsx create mode 100644 src/renderer/src/components/right-sidebar/AiVaultSessionListBar.tsx create mode 100644 src/renderer/src/components/right-sidebar/AiVaultShowMoreSessionsRow.test.tsx create mode 100644 src/renderer/src/components/right-sidebar/AiVaultShowMoreSessionsRow.tsx create mode 100644 src/renderer/src/components/right-sidebar/ai-vault-applied-scan.ts create mode 100644 src/renderer/src/components/right-sidebar/ai-vault-sort-options.ts create mode 100644 src/renderer/src/components/right-sidebar/use-ai-vault-panel-scope.ts diff --git a/src/main/ai-vault-search/session-search-hit-ranking.test.ts b/src/main/ai-vault-search/session-search-hit-ranking.test.ts index 54919bace0f..63df3c0e77b 100644 --- a/src/main/ai-vault-search/session-search-hit-ranking.test.ts +++ b/src/main/ai-vault-search/session-search-hit-ranking.test.ts @@ -39,6 +39,15 @@ describe('order', () => { expect(rankSessionHits(sessions, scores, 'newest').map((e) => e.session.id)).toEqual([2, 1]) }) + it('hands a relevance tie to the newer session before falling back to id', () => { + const sessions = [ + session(1, { updated_at: '2026-09-01T00:00:00.000Z' }), + session(2, { updated_at: '2026-09-09T00:00:00.000Z' }) + ] + const scores = matches(match(1, 5), match(2, 5)) + expect(rankSessionHits(sessions, scores, 'relevance').map((e) => e.session.id)).toEqual([2, 1]) + }) + it.each(['relevance', 'newest'] as const)( 'breaks a %s tie by session, whatever order retrieval handed them over in', (sort) => { diff --git a/src/main/ai-vault-search/session-search-hit-ranking.ts b/src/main/ai-vault-search/session-search-hit-ranking.ts index 364858ea650..2172113074a 100644 --- a/src/main/ai-vault-search/session-search-hit-ranking.ts +++ b/src/main/ai-vault-search/session-search-hit-ranking.ts @@ -65,11 +65,12 @@ export function rankSessionHits( ) // Why a total order and not just the key: a cursor is an offset into this // list, so two entries that tie must not be free to swap between pages. + // Newer first among equal scores, so relevance never hands ties to whichever id is lower. scored.sort( (left, right) => - (sort === 'newest' - ? (right.session.updated_at ?? '').localeCompare(left.session.updated_at ?? '') - : right.score - left.score) || left.session.id - right.session.id + (sort === 'newest' ? 0 : right.score - left.score) || + (right.session.updated_at ?? '').localeCompare(left.session.updated_at ?? '') || + left.session.id - right.session.id ) return scored } diff --git a/src/renderer/src/components/right-sidebar/AiVaultPanel.legacy-filter.test.tsx b/src/renderer/src/components/right-sidebar/AiVaultPanel.legacy-filter.test.tsx index 7eed10ad14b..92424db0506 100644 --- a/src/renderer/src/components/right-sidebar/AiVaultPanel.legacy-filter.test.tsx +++ b/src/renderer/src/components/right-sidebar/AiVaultPanel.legacy-filter.test.tsx @@ -3,7 +3,7 @@ import { cleanup, render, screen, waitFor } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { afterEach, beforeEach, expect, it, vi } from 'vitest' import type { AiVaultSession } from '../../../../shared/ai-vault-types' -import type { AiVaultSessionGroup } from './ai-vault-session-filters' +import type { AiVaultSessionListGroup } from './ai-vault-session-filters' const mockState: { settings: { aiVaultSearch?: { enabled: boolean } } @@ -76,8 +76,9 @@ vi.mock('./ai-vault-session-delete-action', () => ({ // The virtualizer measures a zero-height viewport under happy-dom; the rows it would // choose are exactly the grouped sessions, so render those instead. vi.mock('./AiVaultSessionVirtualList', () => ({ - AiVaultSessionVirtualList: ({ groups }: { groups: readonly AiVaultSessionGroup[] }) => ( -