Skip to content
TypeScript

fix(web): cmd+k search hides subagents and favors recent, whole-word matches (#24032)

Theo Browne4812dcad02a8
diff --git a/apps/mobile/src/features/keyboard/CommandPalette.tsx b/apps/mobile/src/features/keyboard/CommandPalette.tsx
index c70062ab04c..bbc66e8ff51 100644
--- a/apps/mobile/src/features/keyboard/CommandPalette.tsx
+++ b/apps/mobile/src/features/keyboard/CommandPalette.tsx
@@ -324,7 +324,10 @@ export function CommandPalette(props: {
}),
}));
const threadItems: CommandPaletteItem[] = threads
- .filter((thread) => thread.archivedAt === null)
+ .filter(
+ (thread) =>
+ thread.archivedAt === null && thread.lineage.relationshipToParent !== "subagent",
+ )
.sort((left, right) =>
(right.latestUserMessageAt ?? right.updatedAt).localeCompare(
left.latestUserMessageAt ?? left.updatedAt,
diff --git a/apps/web/src/components/CommandPalette.logic.test.ts b/apps/web/src/components/CommandPalette.logic.test.ts
index 8d9f93a51a6..a81455c56f4 100644
--- a/apps/web/src/components/CommandPalette.logic.test.ts
+++ b/apps/web/src/components/CommandPalette.logic.test.ts
@@ -300,6 +300,116 @@ describe("buildThreadActionItems", () => {
expect.objectContaining({ value: `thread:${idThread.id}` }),
]);
});
+
+ it("hides subagent threads but keeps forks", () => {
+ const parentId = ThreadId.make("parent");
+ const items = buildThreadActionItems({
+ threads: [
+ makeThread({ id: parentId, title: "Parent" }),
+ makeThread({
+ id: ThreadId.make("subagent"),
+ title: "Subagent",
+ lineage: {
+ rootThreadId: parentId,
+ parentThreadId: parentId,
+ relationshipToParent: "subagent",
+ },
+ }),
+ makeThread({
+ id: ThreadId.make("fork"),
+ title: "Fork",
+ lineage: {
+ rootThreadId: parentId,
+ parentThreadId: parentId,
+ relationshipToParent: "fork",
+ },
+ }),
+ ],
+ projectTitleById: new Map(),
+ sortOrder: "updated_at",
+ icon: null,
+ runThread: async () => undefined,
+ });
+
+ expect(items.map((item) => item.value).toSorted()).toEqual(["thread:fork", "thread:parent"]);
+ });
+
+ it("ranks word-start title matches above newer mid-word matches", () => {
+ const items = buildThreadActionItems({
+ threads: [
+ makeThread({
+ id: ThreadId.make("mid-word"),
+ title: "Fix oauth redirect",
+ updatedAt: "2026-03-20T00:00:00.000Z",
+ }),
+ makeThread({
+ id: ThreadId.make("word-start"),
+ title: "Clean up auth tokens",
+ updatedAt: "2026-03-02T00:00:00.000Z",
+ }),
+ makeThread({
+ id: ThreadId.make("branch-word-start"),
+ title: "Refactor login",
+ branch: "feature/auth-cleanup",
+ updatedAt: "2026-03-01T00:00:00.000Z",
+ }),
+ ],
+ projectTitleById: new Map(),
+ sortOrder: "updated_at",
+ icon: null,
+ runThread: async () => undefined,
+ });
+
+ const groups = filterCommandPaletteGroups({
+ activeGroups: [],
+ query: "auth",
+ isInSubmenu: false,
+ projectSearchItems: [],
+ threadSearchItems: items,
+ });
+
+ expect(groups[0]?.items.map((item) => item.value)).toEqual([
+ "thread:word-start",
+ "thread:branch-word-start",
+ "thread:mid-word",
+ ]);
+ });
+
+ it("breaks ties within a match tier by latest user message", () => {
+ const items = buildThreadActionItems({
+ threads: [
+ makeThread({
+ id: ThreadId.make("prefix-stale"),
+ title: "Auth refactor",
+ updatedAt: "2026-03-20T00:00:00.000Z",
+ latestUserMessageAt: "2025-09-01T00:00:00.000Z",
+ }),
+ makeThread({
+ id: ThreadId.make("word-fresh"),
+ title: "Fix auth refresh",
+ updatedAt: "2026-03-10T00:00:00.000Z",
+ latestUserMessageAt: "2026-03-10T00:00:00.000Z",
+ }),
+ ],
+ projectTitleById: new Map(),
+ sortOrder: "updated_at",
+ icon: null,
+ runThread: async () => undefined,
+ });
+
+ const groups = filterCommandPaletteGroups({
+ activeGroups: [],
+ query: "auth",
+ isInSubmenu: false,
+ projectSearchItems: [],
+ threadSearchItems: items,
+ });
+
+ expect(groups[0]?.items.map((item) => item.value)).toEqual([
+ "thread:word-fresh",
+ "thread:prefix-stale",
+ ]);
+ });
});
describe("filterPinnedBrowseEntries", () => {
diff --git a/apps/web/src/components/CommandPalette.logic.ts b/apps/web/src/components/CommandPalette.logic.ts
index 6fe9b7cfb69..ce9d335b4d0 100644
--- a/apps/web/src/components/CommandPalette.logic.ts
+++ b/apps/web/src/components/CommandPalette.logic.ts
@@ -25,6 +25,7 @@ import { getThreadSortTimestamp, sortThreads } from "../lib/threadSort";
import { normalizeSearchText } from "../lib/utils";
import { formatRelativeTimeLabel } from "../timestampFormat";
import { type Project, type SidebarThreadSummary, type Thread } from "../types";
+import { isSidebarSubagentThread } from "./Sidebar.logic";
export const RECENT_THREAD_LIMIT = 12;
export const ITEM_ICON_CLASS = "size-4 text-icon-muted";
@@ -353,6 +354,7 @@ export type BuildThreadActionItemsThread = Pick<
| "createdAt"
| "environmentId"
| "id"
+ | "lineage"
| "modelSelection"
| "projectId"
| "runtime"
@@ -378,7 +380,9 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
limit?: number;
}): CommandPaletteActionItem[] {
const sortedThreads = sortThreads(
- input.threads.filter((thread) => thread.archivedAt === null),
+ input.threads.filter(
+ (thread) => thread.archivedAt === null && !isSidebarSubagentThread(thread),
+ ),
input.sortOrder,
);
const visibleThreads =
@@ -437,6 +441,16 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
});
}
+const ALPHANUMERIC = /[\p{L}\p{N}]/u;
+
+function startsWord(field: string, token: string): boolean {
+ for (let index = field.indexOf(token); index !== -1; index = field.indexOf(token, index + 1)) {
+ if (index === 0 || !ALPHANUMERIC.test(field[index - 1]!)) return true;
+ }
+ return false;
+}
+
+// 3 exact, 2 field prefix, 1 every token starts a word, 0 a token only matches mid-word.
function rankSearchFieldMatch(
field: string,
normalizedQuery: string,
@@ -455,33 +469,30 @@ function rankSearchFieldMatch(
if (normalizedField.startsWith(normalizedQuery)) {
return 2;
}
- if (normalizedField.includes(normalizedQuery)) {
+ if (queryTokens.every((token) => startsWord(normalizedField, token))) {
return 1;
}
return 0;
}
+// A word-start match in any field beats a mid-word match, then earlier fields win.
+// Thread titles collapse prefix and word-start into one tier so recency picks between them.
function rankCommandPaletteItemMatch(
item: CommandPaletteActionItem | CommandPaletteSubmenuItem,
normalizedQuery: string,
queryTokens: ReadonlyArray<string>,
): number {
- const terms = item.searchTerms.filter((term) => term.length > 0);
- if (terms.length === 0) {
- return 0;
- }
-
- for (const [index, field] of terms.entries()) {
+ let best = 0;
+ for (const [index, field] of item.searchTerms.filter((term) => term.length > 0).entries()) {
const fieldRank = rankSearchFieldMatch(field, normalizedQuery, queryTokens);
- if (fieldRank !== Number.NEGATIVE_INFINITY) {
- if (index === 0 && item.searchRecency !== undefined) {
- return 1_000 + Number(fieldRank === 3);
- }
- return 1_000 - index * 100 + fieldRank;
- }
+ if (fieldRank === Number.NEGATIVE_INFINITY) continue;
+ const fieldScore =
+ index === 0 && item.searchRecency !== undefined
+ ? 1_000 + Number(fieldRank === 3)
+ : 1_000 - index * 100 + fieldRank;
+ best = Math.max(best, (fieldRank > 0 ? 10_000 : 0) + fieldScore);
}
-
- return 0;
+ return best;
}
export function filterCommandPaletteGroups(input: {
diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts
index e5bcdffc980..e24439a17f0 100644
--- a/apps/web/src/components/Sidebar.logic.ts
+++ b/apps/web/src/components/Sidebar.logic.ts
@@ -512,7 +512,7 @@ export function buildMultiSelectThreadContextMenuItems(input: {
];
}
-function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
+export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
return thread.lineage.relationshipToParent === "subagent";
}