Skip to content

Commit f84a524

Browse files
committed
feat(search): filter threads with GitHub-style qualifiers
Thread search understands project:/in:, env:, branch:, provider:, status:, since:/before:, and is:archived, with - negation and comma OR lists. Free text keeps searching titles, PR terms, and message content. The command palette gets a filter menu that writes the same qualifiers into the query.
1 parent cd41c4a commit f84a524

28 files changed

Lines changed: 1635 additions & 141 deletions

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ export function HomeRouteScreen() {
3636
const { savedConnectionsById } = useSavedRemoteConnections();
3737
const navigation = useNavigation();
3838
const [searchQuery, setSearchQuery] = useState("");
39-
const handleSelectThread = useHomeThreadSelection();
39+
const selectThread = useHomeThreadSelection();
40+
const handleSelectThread = useCallback(
41+
(thread: EnvironmentThreadShell) => {
42+
if (thread.archivedAt !== null) {
43+
navigation.navigate("SettingsSheet", {
44+
screen: "SettingsContent",
45+
params: { screen: "SettingsArchive" },
46+
});
47+
return;
48+
}
49+
selectThread(thread);
50+
},
51+
[navigation, selectThread],
52+
);
4053
const handleNewThreadOnBranch = useCallback(
4154
(thread: EnvironmentThreadShell) => {
4255
navigation.navigate("NewTaskSheet", {

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
55
import {
66
type EnvironmentProject,
77
type EnvironmentThreadShell,
8+
presentThreadShell,
89
} from "@t3tools/client-runtime/state/shell";
910
import {
1011
threadSearchMatchKey,
@@ -33,6 +34,8 @@ import type { SavedRemoteConnection } from "../../lib/connection";
3334
import { scopedProjectKey } from "../../lib/scopedEntities";
3435
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
3536
import { useThreadSearch } from "../../state/queries";
37+
import { useArchivedThreadSnapshots } from "../archive/useArchivedThreadSnapshots";
38+
import { parseThreadSearchQuery } from "@t3tools/client-runtime/state/threadSearchQuery";
3639
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
3740
import { usePendingThreadOrder } from "../../state/thread-order";
3841
import { threadListEnvironmentsAtom } from "../../state/server";
@@ -49,13 +52,15 @@ import {
4952
import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
5053
import {
5154
buildThreadListV2Items,
55+
createMobileThreadSearchContext,
5256
getThreadListV2OrderedSection,
5357
buildThreadListV2ListItems,
5458
threadListV2ListItemsAreEqual,
5559
threadListInboxReturns,
5660
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
5761
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
5862
type ThreadListV2ListItem,
63+
sortThreadsByActivity,
5964
} from "../threads/threadListV2";
6065
import { useThreadListV2ShelfPreferences } from "../threads/use-thread-list-v2-shelf-preferences";
6166
import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu";
@@ -222,6 +227,10 @@ function HomeTopContentSpacer() {
222227
/* ─── Main screen ────────────────────────────────────────────────────── */
223228

224229
export function HomeScreen(props: HomeScreenProps) {
230+
const parsedSearch = useMemo(
231+
() => parseThreadSearchQuery(props.searchQuery, { now: new Date() }),
232+
[props.searchQuery],
233+
);
225234
const queuedThreadKeys = useQueuedThreadKeys();
226235
const openSwipeableRef = useRef<SwipeableMethods | null>(null);
227236
const insets = useSafeAreaInsets();
@@ -245,7 +254,25 @@ export function HomeScreen(props: HomeScreenProps) {
245254
: [],
246255
[props.environments, props.selectedEnvironmentId],
247256
);
248-
const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
257+
const archivedSnapshots = useArchivedThreadSnapshots(
258+
parsedSearch.filters.archived ? searchEnvironmentIds : [],
259+
);
260+
const searchableThreads = useMemo(
261+
() =>
262+
parsedSearch.filters.archived
263+
? sortThreadsByActivity(
264+
archivedSnapshots.snapshots.flatMap(({ environmentId, snapshot }) =>
265+
snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),
266+
),
267+
)
268+
: props.threads,
269+
[archivedSnapshots.snapshots, parsedSearch.filters.archived, props.threads],
270+
);
271+
const threadSearch = useThreadSearch(
272+
searchEnvironmentIds,
273+
parsedSearch.text,
274+
parsedSearch.filters.archived,
275+
);
249276
const threadSearchMatchByKey = useMemo(() => {
250277
const matches = new Map<string, EnvironmentThreadSearchMatch>();
251278
for (const match of threadSearch.matches) {
@@ -504,6 +531,22 @@ export function HomeScreen(props: HomeScreenProps) {
504531
} = listEnvironments;
505532
const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
506533
const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
534+
const threadSearchContext = useMemo(
535+
() =>
536+
createMobileThreadSearchContext({
537+
projects: projectByKey,
538+
providers: providersByEnvironmentId,
539+
environmentNames: (thread) =>
540+
[
541+
props.environments.find(
542+
(environment) => environment.environmentId === thread.environmentId,
543+
)?.label,
544+
props.savedConnectionsById[thread.environmentId]?.environmentLabel,
545+
thread.environmentId,
546+
].filter((name): name is string => name !== undefined),
547+
}),
548+
[projectByKey, props.environments, props.savedConnectionsById, providersByEnvironmentId],
549+
);
507550
// Up/down menu availability for every card, computed once per section per
508551
// rebuild (see computeThreadMoveAvailability): per-thread planner calls made
509552
// list construction quadratic, and this list rebuilds on every minute tick.
@@ -544,14 +587,18 @@ export function HomeScreen(props: HomeScreenProps) {
544587
]);
545588
const threadListV2Layout = useMemo(() => {
546589
threadListInboxReturns.observe(workingShelfEnabled ? props.threads : null);
547-
// Settled threads are live shells; archived threads keep their original
548-
// "hidden from lists" meaning.
590+
// Archive searches use the snapshot instead of the live shells.
549591
return buildThreadListV2Items({
550592
pendingOrder,
551-
threads: props.threads.filter((thread) => thread.archivedAt === null),
593+
threads: searchableThreads.filter(
594+
(thread) => parsedSearch.filters.archived || thread.archivedAt === null,
595+
),
552596
environmentId: props.selectedEnvironmentId,
553597
projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs,
554-
searchQuery: props.searchQuery,
598+
searchQuery: parsedSearch.text,
599+
searchFilters: parsedSearch.filters,
600+
searchFilterContext: threadSearchContext,
601+
searchNow: new Date(),
555602
matchedThreadKeys,
556603
settlementEnvironmentIds,
557604
snoozeEnvironmentIds,
@@ -577,11 +624,13 @@ export function HomeScreen(props: HomeScreenProps) {
577624
settledVisibleCount,
578625
settlementEnvironmentIds,
579626
snoozeEnvironmentIds,
580-
props.searchQuery,
627+
parsedSearch,
581628
props.selectedEnvironmentId,
582629
props.threads,
630+
searchableThreads,
583631
matchedThreadKeys,
584632
v2ScopedProjectGroup,
633+
threadSearchContext,
585634
]);
586635
// Re-partition the moment the earliest snooze expires (clamped to the
587636
// signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
@@ -601,7 +650,7 @@ export function HomeScreen(props: HomeScreenProps) {
601650
// they are spliced in below the active block and stay visible and deletable
602651
// while their environment is offline. Same environment scope and search
603652
// filter as the list itself.
604-
const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
653+
const v2SearchQuery = parsedSearch.text.trim().toLocaleLowerCase();
605654
const v2PendingTasks = useMemo(
606655
() =>
607656
props.pendingTasks.filter(
@@ -745,7 +794,7 @@ export function HomeScreen(props: HomeScreenProps) {
745794
threadId: thread.id,
746795
}),
747796
)}
748-
searchQuery={props.searchQuery}
797+
searchQuery={parsedSearch.text}
749798
onSelectThread={props.onSelectThread}
750799
onDeleteThread={handleDeleteThread}
751800
onArchiveThread={props.onArchiveThread}
@@ -830,7 +879,7 @@ export function HomeScreen(props: HomeScreenProps) {
830879
projectTitleByProjectKey: v2ProjectTitleByProjectKey,
831880
listEnvironments,
832881
savedConnectionsById: props.savedConnectionsById,
833-
searchQuery: props.searchQuery,
882+
searchQuery: parsedSearch.text,
834883
threadSearchMatchByKey,
835884
// Rows read it for their reorder menu items.
836885
workingShelfEnabled,

‎apps/mobile/src/features/keyboard/CommandPalette.tsx‎

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
2626
import { T3KeyboardCommands } from "../../native/T3KeyboardCommands";
2727
import { useProjects, useThreadShell, useThreadShells } from "../../state/entities";
2828
import { useThreadSearch } from "../../state/queries";
29+
import {
30+
matchesThreadSearchFilters,
31+
parseThreadSearchQuery,
32+
} from "@t3tools/client-runtime/state/threadSearchQuery";
33+
import { createMobileThreadSearchContext, sortThreadsByActivity } from "../threads/threadListV2";
34+
import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
35+
import { useArchivedThreadSnapshots } from "../archive/useArchivedThreadSnapshots";
2936
import { useWorkspaceEnvironments } from "../../state/workspace";
3037
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
38+
import { threadListEnvironmentsAtom } from "../../state/server";
39+
import { useAtomValue } from "@effect/atom-react";
3140
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
3241
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
3342
import { ThreadSearchMatchExcerpt } from "../threads/thread-search-match";
@@ -143,11 +152,20 @@ export function CommandPalette(props: {
143152
const runCommand = props.onCommand;
144153
const projects = useProjects();
145154
const threads = useThreadShells();
155+
const projectByKey = useMemo(
156+
() =>
157+
new Map(
158+
projects.map((project) => [scopedProjectKey(project.environmentId, project.id), project]),
159+
),
160+
[projects],
161+
);
146162
const activeThreadRef = useMemo(() => parseActiveThreadPath(props.pathname), [props.pathname]);
147163
const activeThread = useThreadShell(activeThreadRef);
148164
const environments = useWorkspaceEnvironments();
149165
const { savedConnectionsById } = useSavedRemoteConnections();
166+
const { providersByEnvironmentId } = useAtomValue(threadListEnvironmentsAtom);
150167
const [query, setQuery] = useState("");
168+
const parsedSearch = useMemo(() => parseThreadSearchQuery(query, { now: new Date() }), [query]);
151169
const [selection, setSelection] = useState<string | null>(null);
152170
const [visible, setVisible] = useState(true);
153171
const pendingAction = useRef<(() => void) | null>(null);
@@ -162,7 +180,38 @@ export function CommandPalette(props: {
162180
.map((environment) => environment.environmentId),
163181
[environments],
164182
);
165-
const search = useThreadSearch(searchEnvironmentIds, query.startsWith(">") ? "" : query);
183+
const archivedSnapshots = useArchivedThreadSnapshots(
184+
parsedSearch.filters.archived ? searchEnvironmentIds : [],
185+
);
186+
const searchableThreads = useMemo(
187+
() =>
188+
parsedSearch.filters.archived
189+
? archivedSnapshots.snapshots.flatMap(({ environmentId, snapshot }) =>
190+
snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),
191+
)
192+
: threads,
193+
[archivedSnapshots.snapshots, parsedSearch.filters.archived, threads],
194+
);
195+
const threadSearchContext = useMemo(
196+
() =>
197+
createMobileThreadSearchContext({
198+
projects: projectByKey,
199+
providers: providersByEnvironmentId,
200+
environmentNames: (thread) =>
201+
[
202+
environments.find((environment) => environment.environmentId === thread.environmentId)
203+
?.environmentLabel,
204+
savedConnectionsById[thread.environmentId]?.environmentLabel,
205+
thread.environmentId,
206+
].filter((name): name is string => name !== undefined),
207+
}),
208+
[environments, projectByKey, providersByEnvironmentId, savedConnectionsById],
209+
);
210+
const search = useThreadSearch(
211+
searchEnvironmentIds,
212+
query.startsWith(">") ? "" : parsedSearch.text,
213+
parsedSearch.filters.archived,
214+
);
166215
const matchedThreadKeys = useMemo(
167216
() =>
168217
new Set(search.matches.map((match) => scopedThreadKey(match.environmentId, match.threadId))),
@@ -260,9 +309,6 @@ export function CommandPalette(props: {
260309
}),
261310
},
262311
];
263-
const projectByKey = new Map(
264-
projects.map((project) => [scopedProjectKey(project.environmentId, project.id), project]),
265-
);
266312
const activeProject = activeThread
267313
? projectByKey.get(scopedProjectKey(activeThread.environmentId, activeThread.projectId))
268314
: null;
@@ -316,13 +362,8 @@ export function CommandPalette(props: {
316362
},
317363
}),
318364
}));
319-
const threadItems: CommandPaletteItem[] = threads
320-
.filter((thread) => thread.archivedAt === null)
321-
.sort((left, right) =>
322-
(right.latestUserMessageAt ?? right.updatedAt).localeCompare(
323-
left.latestUserMessageAt ?? left.updatedAt,
324-
),
325-
)
365+
const threadItems: CommandPaletteItem[] = sortThreadsByActivity(searchableThreads)
366+
.filter((thread) => parsedSearch.filters.archived || thread.archivedAt === null)
326367
.map((thread) => {
327368
const project = projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId));
328369
const environment =
@@ -338,6 +379,10 @@ export function CommandPalette(props: {
338379
thread.branch ?? "",
339380
...threadPullRequestSearchTerms(thread),
340381
],
382+
matchesSearch: () =>
383+
matchesThreadSearchFilters(thread, parsedSearch.filters, threadSearchContext, {
384+
now: new Date(),
385+
}),
341386
run: () => selectThread(thread),
342387
};
343388
});
@@ -346,11 +391,14 @@ export function CommandPalette(props: {
346391
activeThread,
347392
activeThreadRef,
348393
navigation,
394+
projectByKey,
349395
projects,
396+
parsedSearch,
350397
runCommand,
351398
savedConnectionsById,
352399
selectThread,
353-
threads,
400+
searchableThreads,
401+
threadSearchContext,
354402
]);
355403
const results = useMemo(
356404
() => filterCommandPaletteItems(items, query, matchedThreadKeys),
@@ -497,7 +545,7 @@ export function CommandPalette(props: {
497545
searchMatch={
498546
item.kind === "thread" ? contentMatchByKey.get(item.key) : undefined
499547
}
500-
searchQuery={query}
548+
searchQuery={parsedSearch.text}
501549
onSelect={() => close(item.run)}
502550
/>
503551
)}

‎apps/mobile/src/features/keyboard/commandPaletteItems.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { describe, expect, it } from "vite-plus/test";
2+
import {
3+
matchesThreadSearchFilters,
4+
parseThreadSearchQuery,
5+
} from "@t3tools/client-runtime/state/threadSearchQuery";
26

37
import {
48
filterCommandPaletteItems,
@@ -63,6 +67,38 @@ describe("filterCommandPaletteItems", () => {
6367
).toEqual(["siva:one"]);
6468
expect(filterCommandPaletteItems(items, "> message content", matches)).toEqual([]);
6569
});
70+
71+
it("applies qualifiers before including a server content match", () => {
72+
const now = new Date("2026-10-07T12:00:00.000Z");
73+
const context = {
74+
projectName: () => "Mobile",
75+
environmentNames: () => ["Local"],
76+
providerNames: () => ["Codex"],
77+
status: () => "ready",
78+
activityAt: (thread: { updatedAt: string }) => thread.updatedAt,
79+
};
80+
const candidates = ["2026-10-06T12:00:00.000Z", "2026-09-01T12:00:00.000Z"].map(
81+
(updatedAt, index) => ({
82+
...item(`thread:${index}`, "Unrelated title", "thread"),
83+
matchesSearch: (query: string) =>
84+
matchesThreadSearchFilters(
85+
{ updatedAt, branch: null },
86+
parseThreadSearchQuery(query, { now }).filters,
87+
context,
88+
{ now },
89+
),
90+
}),
91+
);
92+
const matches = new Set(candidates.map((candidate) => candidate.key));
93+
expect(
94+
filterCommandPaletteItems(candidates, "since:7d", matches).map((candidate) => candidate.key),
95+
).toEqual(["thread:0"]);
96+
expect(
97+
filterCommandPaletteItems(candidates, "since:7d message", matches).map(
98+
(candidate) => candidate.key,
99+
),
100+
).toEqual(["thread:0"]);
101+
});
66102
});
67103

68104
describe("nextPaletteIndex", () => {

‎apps/mobile/src/features/keyboard/commandPaletteItems.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { parseThreadSearchQuery } from "@t3tools/client-runtime/state/threadSearchQuery";
2+
13
export interface CommandPaletteItem {
24
readonly key: string;
35
readonly kind: "action" | "project" | "thread";
46
readonly title: string;
57
readonly detail?: string;
68
readonly searchTerms: ReadonlyArray<string>;
79
readonly run: () => void;
10+
readonly matchesSearch?: (query: string) => boolean;
811
}
912

1013
/** `>` narrows to actions, matching the desktop palette. Stable ties retain recent-thread order. */
@@ -14,11 +17,13 @@ export function filterCommandPaletteItems(
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 items
2024
.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();

0 commit comments

Comments
 (0)