Skip to content

Commit 725cf20

Browse files
committed
feat(web): enable full-text message content search in sidebar
The sidebar thread search was previously limited to filtering thread titles locally, ignoring the full-text search backend already available to the command palette and mobile app. Connect the sidebar search input to `useThreadSearch` via WebSocket RPC, merge title and content search results with priority and deduplication, and display highlighted message snippets with sender badges in the results list. Model: Gemini 3.7 Flash Harness: Antigravity CLI
1 parent 3f326ff commit 725cf20

10 files changed

Lines changed: 335 additions & 95 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6749,7 +6749,6 @@ function ChatViewContent(props: ChatViewProps) {
67496749
onOpenChange={setIsHandoffDialogOpen}
67506750
sourceThread={activeServerThread}
67516751
targetModelSelection={handoffTargetModelSelection}
6752-
providerInstanceEntries={providerInstanceEntries}
67536752
onConfirmHandoff={handleConfirmHandoff}
67546753
/>
67556754
) : null}

‎apps/web/src/components/CommandPaletteResults.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function foldAsciiCase(value: string): string {
2020
return value.replace(/[A-Z]/g, (character) => character.toLowerCase());
2121
}
2222

23-
function HighlightedSearchText(props: { text: string; query: string }) {
23+
export function HighlightedSearchText(props: { text: string; query: string }) {
2424
const query = props.query.trim();
2525
if (query.length === 0) return props.text;
2626

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
resolveThreadStatusPill,
2323
resolveWorkingStartedAt,
2424
searchSidebarThreadsByTitle,
25+
mergeSidebarThreadSearchResults,
2526
formatWorkingDurationLabel,
2627
shouldNavigateAfterProjectRemoval,
2728
shouldClearThreadSelectionOnMouseDown,
@@ -755,6 +756,107 @@ describe("searchSidebarThreadsByTitle", () => {
755756
});
756757
});
757758

759+
describe("mergeSidebarThreadSearchResults", () => {
760+
const threads = [
761+
{ id: "thread-1", environmentId: "env-1", title: "Fix workspace search" },
762+
{ id: "thread-2", environmentId: "env-1", title: "Review providers" },
763+
{ id: "thread-3", environmentId: "env-1", title: "Refactor engine" },
764+
];
765+
766+
it("returns title matches when there are no content matches", () => {
767+
const results = mergeSidebarThreadSearchResults(threads, "workspace", []);
768+
expect(results).toEqual([
769+
{
770+
thread: threads[0],
771+
contentMatch: undefined,
772+
},
773+
]);
774+
});
775+
776+
it("returns content matches for threads whose title does not match", () => {
777+
const contentMatches = [
778+
{
779+
environmentId: EnvironmentId.make("env-1"),
780+
threadId: ThreadId.make("thread-3"),
781+
projectId: ProjectId.make("proj-1"),
782+
source: "user" as const,
783+
snippet: "Need to refactor the search engine",
784+
messageCreatedAt: "2026-03-09T10:00:00.000Z",
785+
},
786+
];
787+
const results = mergeSidebarThreadSearchResults(threads, "engine", contentMatches);
788+
expect(results).toEqual([
789+
{
790+
thread: threads[2],
791+
contentMatch: {
792+
source: "user",
793+
snippet: "Need to refactor the search engine",
794+
query: "engine",
795+
},
796+
},
797+
]);
798+
});
799+
800+
it("prioritizes title matches and attaches content match info when thread matches both", () => {
801+
const contentMatches = [
802+
{
803+
environmentId: EnvironmentId.make("env-1"),
804+
threadId: ThreadId.make("thread-2"),
805+
projectId: ProjectId.make("proj-1"),
806+
source: "assistant" as const,
807+
snippet: "Here is the search result for providers",
808+
messageCreatedAt: "2026-03-09T11:00:00.000Z",
809+
},
810+
{
811+
environmentId: EnvironmentId.make("env-1"),
812+
threadId: ThreadId.make("thread-1"),
813+
projectId: ProjectId.make("proj-1"),
814+
source: "user" as const,
815+
snippet: "Let's test search functionality",
816+
messageCreatedAt: "2026-03-09T12:00:00.000Z",
817+
},
818+
];
819+
const results = mergeSidebarThreadSearchResults(threads, "search", contentMatches);
820+
expect(results).toEqual([
821+
{
822+
thread: threads[0],
823+
contentMatch: {
824+
source: "user",
825+
snippet: "Let's test search functionality",
826+
query: "search",
827+
},
828+
},
829+
{
830+
thread: threads[1],
831+
contentMatch: {
832+
source: "assistant",
833+
snippet: "Here is the search result for providers",
834+
query: "search",
835+
},
836+
},
837+
]);
838+
});
839+
840+
it("ignores content matches for threads not in the given thread collection", () => {
841+
const contentMatches = [
842+
{
843+
environmentId: EnvironmentId.make("env-1"),
844+
threadId: ThreadId.make("deleted-thread"),
845+
projectId: ProjectId.make("proj-1"),
846+
source: "user" as const,
847+
snippet: "some search match",
848+
messageCreatedAt: "2026-03-09T10:00:00.000Z",
849+
},
850+
];
851+
const results = mergeSidebarThreadSearchResults(threads, "match", contentMatches);
852+
expect(results).toEqual([]);
853+
});
854+
855+
it("returns empty array for empty query", () => {
856+
expect(mergeSidebarThreadSearchResults(threads, " ", [])).toEqual([]);
857+
});
858+
});
859+
758860
describe("sortThreadsForSidebar", () => {
759861
const sortable = (input: { id: string; createdAt: string }) => ({
760862
id: input.id,

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react";
22
import type { ContextMenuItem } from "@t3tools/contracts";
3+
import type { EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
34
import type { SidebarProjectSortOrder, SidebarThreadSortOrder } from "@t3tools/contracts/settings";
45
import {
56
getThreadSortTimestamp,
@@ -568,6 +569,86 @@ export function searchSidebarThreadsByTitle<T extends { readonly title: string }
568569
return threads.filter((thread) => thread.title.toLowerCase().includes(normalizedQuery));
569570
}
570571

572+
export interface SidebarThreadContentMatch {
573+
readonly source: "user" | "assistant";
574+
readonly snippet: string;
575+
readonly query: string;
576+
}
577+
578+
export interface SidebarSearchResult<T> {
579+
readonly thread: T;
580+
readonly contentMatch?: SidebarThreadContentMatch | undefined;
581+
}
582+
583+
export function mergeSidebarThreadSearchResults<
584+
T extends {
585+
readonly id: string;
586+
readonly environmentId?: string | undefined;
587+
readonly title: string;
588+
},
589+
>(
590+
threads: readonly T[],
591+
query: string,
592+
contentMatches: ReadonlyArray<EnvironmentThreadSearchMatch> = [],
593+
): SidebarSearchResult<T>[] {
594+
const normalizedQuery = query.trim().toLowerCase();
595+
if (normalizedQuery.length === 0) return [];
596+
597+
const titleMatches = searchSidebarThreadsByTitle(threads, query);
598+
const contentMatchByThreadKey = new Map<string, EnvironmentThreadSearchMatch>();
599+
for (const match of contentMatches) {
600+
const key = `${match.environmentId}:${match.threadId}`;
601+
if (!contentMatchByThreadKey.has(key)) {
602+
contentMatchByThreadKey.set(key, match);
603+
}
604+
}
605+
606+
const threadByKey = new Map<string, T>();
607+
for (const thread of threads) {
608+
const key = `${thread.environmentId ?? ""}:${thread.id}`;
609+
if (!threadByKey.has(key)) {
610+
threadByKey.set(key, thread);
611+
}
612+
}
613+
614+
const seenKeys = new Set<string>();
615+
const results: SidebarSearchResult<T>[] = [];
616+
617+
for (const thread of titleMatches) {
618+
const key = `${thread.environmentId ?? ""}:${thread.id}`;
619+
seenKeys.add(key);
620+
const contentMatch = contentMatchByThreadKey.get(key);
621+
results.push({
622+
thread,
623+
contentMatch: contentMatch
624+
? {
625+
source: contentMatch.source,
626+
snippet: contentMatch.snippet,
627+
query,
628+
}
629+
: undefined,
630+
});
631+
}
632+
633+
for (const match of contentMatches) {
634+
const key = `${match.environmentId}:${match.threadId}`;
635+
if (seenKeys.has(key)) continue;
636+
const thread = threadByKey.get(key);
637+
if (!thread) continue;
638+
seenKeys.add(key);
639+
results.push({
640+
thread,
641+
contentMatch: {
642+
source: match.source,
643+
snippet: match.snippet,
644+
query,
645+
},
646+
});
647+
}
648+
649+
return results;
650+
}
651+
571652
type SettledTimestampInput = Pick<
572653
SidebarThreadSummary,
573654
"settledAt" | "latestUserMessageAt" | "latestTurn" | "updatedAt"

0 commit comments

Comments
 (0)