feat(search): filter threads with GitHub-style qualifiers #16858
Closedonmax(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/16858/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -338,3 +379,4 @@338379 thread.branch ?? "",339380 ...threadPullRequestSearchTerms(thread),340381 ],382+ matchesSearch: () =>@@ -0,0 +228,21 @@228+ readonly values: ReadonlyArray<string>;229+ readonly negated: boolean;230+}231+232+function recognizedQueryToken(token: QueryToken): RecognizedQueryToken | null {233+ const negated = token.value.startsWith("-");234+ const candidate = negated ? token.value.slice(1) : token.value;235+ if (candidate.toLowerCase() === "is:archived") {236+ return { key: "archived", values: ["archived"], negated };237+ }238+ const separator = candidate.indexOf(":");239+ if (separator <= 0) return null;240+ const key = KEY_ALIASES[candidate.slice(0, separator).toLowerCase()];241+ if (key === undefined) return null;242+ // Editing validates date syntax, without resolving boundaries against the current time.243+ const values = validValues(key, candidate.slice(separator + 1), new Date(0));244+ return values === null ? null : { key, values, negated };245+}246+247+function formatQualifierValue(value: string): string {248+ return /\s/.test(value) ? `"${value}"` : value;@@ -2866,10 +2884,15 @@28662884 const [threadSearchQuery, setThreadSearchQuery] = useState("");2885+ const parsedThreadSearch = useMemo(2886+ () => parseThreadSearchQuery(threadSearchQuery, { now: new Date() }),2887+ [threadSearchQuery],2888+ );28672889 const [activeSearchResultIndex, setActiveSearchResultIndex] = useState(0);28682890 const isSearchingThreads = threadSearchQuery.trim().length > 0;2891+ const searchEnvironmentIds = useConnectedEnvironmentIds();2892+ const archivedSnapshots = useArchivedThreadSnapshots(2893+ parsedThreadSearch.filters.archived ? searchEnvironmentIds : [],2894+ );28692895 const searchableThreads = useMemo(2870- () => [2871- ...pinnedThreads,2872- ...activeThreads,2873- ...workingThreads,2874- ...snoozedThreads,2875- ...settledThreads,2896+ () =>2897+ parsedThreadSearch.filters.archived2898+ ? archivedSnapshots.snapshots@@ -0,0 +192,21 @@192+ status: [],193+ since: [],194+ before: [],195+ };196+ const text: string[] = [];197+ let archived = false;198+ let hasFilters = false;199+ for (const token of tokenize(raw)) {200+ const negated = token.startsWith("-");201+ const candidate = negated ? token.slice(1) : token;202+ const separator = candidate.indexOf(":");203+ const key =204+ separator > 0 ? KEY_ALIASES[candidate.slice(0, separator).toLowerCase()] : undefined;205+ const value = separator > 0 ? candidate.slice(separator + 1) : "";206+ if (candidate.toLowerCase() === "is:archived") {207+ if (!negated) {208+ archived = true;209+ hasFilters = true;210+ }211+ continue;212+ }@@ -601,4 +650,4 @@601650 // they are spliced in below the active block and stay visible and deletable602651 // while their environment is offline. Same environment scope and search603652 // filter as the list itself.604- const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();653+ const v2SearchQuery = parsedSearch.text.trim().toLocaleLowerCase();@@ -245,4 +254,4 @@245254 : [],246255 [props.environments, props.selectedEnvironmentId],247256 );248- const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);257+ const archivedSnapshots = useArchivedThreadSnapshots(
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/mobile/src/features/keyboard/commandPaletteItems.ts lines 19 to 31Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -14,11 +17,13 @@1417 matchedThreadKeys: ReadonlySet<string>,1518 ) {1619 const actionsOnly = query.startsWith(">");17- const normalized = (actionsOnly ? query.slice(1) : query).trim().toLocaleLowerCase();20+ const parsed = parseThreadSearchQuery(actionsOnly ? query.slice(1) : query, { now: new Date() });21+ const normalized = parsed.text.trim().toLocaleLowerCase();1822 const tokens = normalized.split(/\s+/);1923 return items2024 .flatMap((item, index) => {2125 if (actionsOnly && item.kind !== "action") return [];26+ if (item.kind === "thread" && item.matchesSearch && !item.matchesSearch(query)) return [];2227 if (!normalized) return item.kind === "project" ? [] : [{ item, rank: 0, index }];2328 const title = item.title.toLocaleLowerCase();2429 const haystack = [title, ...item.searchTerms].join(" ").toLocaleLowerCase();apps/web/src/components/CommandPalette.logic.ts line 471OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -448,6 +464,8 @@448464 }): CommandPaletteGroup[] {449465 const isActionsFilter = input.query.startsWith(">");450466 const searchQuery = isActionsFilter ? input.query.slice(1) : input.query;451- const normalizedQuery = normalizeSearchText(searchQuery);467+ const parsedQuery = parseThreadSearchQuery(searchQuery, { now: new Date() });468+ const normalizedQuery = normalizeSearchText(parsedQuery.text);452469453470 if (normalizedQuery.length === 0) {471+ if (parsedQuery.hasFilters && !isActionsFilter) {@@ -2867,9 +2886,15 @@2886+ () => parseThreadSearchQuery(threadSearchQuery, { now: new Date() }),2887+ [threadSearchQuery],2888+ );28672889 const [activeSearchResultIndex, setActiveSearchResultIndex] = useState(0);28682890 const isSearchingThreads = threadSearchQuery.trim().length > 0;2891+ const searchEnvironmentIds = useConnectedEnvironmentIds();2892+ const archivedSnapshots = useArchivedThreadSnapshots(2893+ parsedThreadSearch.filters.archived ? searchEnvironmentIds : [],2894+ );28692895 const searchableThreads = useMemo(2870- () => [2871- ...pinnedThreads,2872- ...activeThreads,2873- ...workingThreads,2874- ...snoozedThreads,2875- ...settledThreads,2896+ () =>2897+ parsedThreadSearch.filters.archived2898+ ? archivedSnapshots.snapshots2899+ .flatMap(({ environmentId, snapshot }) =>2900+ snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),docs/user/thread-sidebar.md lines 183 to 184OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -180,6 +180,5 @@180180181181 ## Find and reference work182182183-On web and desktop, open the command palette with `Cmd/Ctrl+K` to search threads184-across connected environments. Message search starts after two characters and185-includes your messages and final agent responses.183+Search the sidebar, command palette, or mobile thread list for titles, linked pull184+requests, and message content. Add `project:` (or `in:`), `env:`, `branch:`,coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
@@ -851,5 +907,8 @@851907 // that matches nothing needs the in-list "No results" state, not the852908 // full-page "No threads yet". Settled threads are unarchived live shells,853909 // so the archived-at check already covers the settled shelf.854- const hasAnyThreads =855- props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;910+ const hasAnyThreads = parsedSearch.filters.archived911+ ? searchableThreads.length > 0 ||912+ archivedSnapshots.isLoading ||913+ archivedSnapshots.error !== null914+ : props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;@@ -0,0 +118,21 @@118+ index += 1;119+ continue;120+ }121+ }122+ if (!quoted && /\s/.test(character)) break;123+ index += 1;124+ }125+ tokens.push({ raw: input.slice(start, index), start, end: index });126+ while (index < input.length && /\s/.test(input[index]!)) index += 1;127+ }128+ return tokens;129+}130+131+function splitCommaValues(raw: string): string[] | null {132+ const values: string[] = [];133+ let start = 0;134+ let quoted = false;135+ for (let index = 0; index < raw.length; index += 1) {136+ const character = raw[index]!;137+ if (character === '"' && raw[index - 1] !== "\\") {138+ quoted = !quoted;tanstack-source added labelsfeature
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed