Skip to content

Commit 8bd6d65

Browse files
t3dotggclaude
andcommitted
fix(web): cmd+k search hides subagents and favors recent, whole-word matches
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d7a8d6f commit 8bd6d65

4 files changed

Lines changed: 142 additions & 18 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ export function CommandPalette(props: {
324324
}),
325325
}));
326326
const threadItems: CommandPaletteItem[] = threads
327-
.filter((thread) => thread.archivedAt === null)
327+
.filter(
328+
(thread) =>
329+
thread.archivedAt === null && thread.lineage.relationshipToParent !== "subagent",
330+
)
328331
.sort((left, right) =>
329332
(right.latestUserMessageAt ?? right.updatedAt).localeCompare(
330333
left.latestUserMessageAt ?? left.updatedAt,

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

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,116 @@ describe("buildThreadActionItems", () => {
300300
expect.objectContaining({ value: `thread:${idThread.id}` }),
301301
]);
302302
});
303+
304+
it("hides subagent threads but keeps forks", () => {
305+
const parentId = ThreadId.make("parent");
306+
const items = buildThreadActionItems({
307+
threads: [
308+
makeThread({ id: parentId, title: "Parent" }),
309+
makeThread({
310+
id: ThreadId.make("subagent"),
311+
title: "Subagent",
312+
lineage: {
313+
rootThreadId: parentId,
314+
parentThreadId: parentId,
315+
relationshipToParent: "subagent",
316+
},
317+
}),
318+
makeThread({
319+
id: ThreadId.make("fork"),
320+
title: "Fork",
321+
lineage: {
322+
rootThreadId: parentId,
323+
parentThreadId: parentId,
324+
relationshipToParent: "fork",
325+
},
326+
}),
327+
],
328+
projectTitleById: new Map(),
329+
sortOrder: "updated_at",
330+
icon: null,
331+
runThread: async () => undefined,
332+
});
333+
334+
expect(items.map((item) => item.value).toSorted()).toEqual(["thread:fork", "thread:parent"]);
335+
});
336+
337+
it("ranks word-start title matches above newer mid-word matches", () => {
338+
const items = buildThreadActionItems({
339+
threads: [
340+
makeThread({
341+
id: ThreadId.make("mid-word"),
342+
title: "Fix oauth redirect",
343+
updatedAt: "2026-03-20T00:00:00.000Z",
344+
}),
345+
makeThread({
346+
id: ThreadId.make("word-start"),
347+
title: "Clean up auth tokens",
348+
updatedAt: "2026-03-02T00:00:00.000Z",
349+
}),
350+
makeThread({
351+
id: ThreadId.make("branch-word-start"),
352+
title: "Refactor login",
353+
branch: "feature/auth-cleanup",
354+
updatedAt: "2026-03-01T00:00:00.000Z",
355+
}),
356+
],
357+
projectTitleById: new Map(),
358+
sortOrder: "updated_at",
359+
icon: null,
360+
runThread: async () => undefined,
361+
});
362+
363+
const groups = filterCommandPaletteGroups({
364+
activeGroups: [],
365+
query: "auth",
366+
isInSubmenu: false,
367+
projectSearchItems: [],
368+
threadSearchItems: items,
369+
});
370+
371+
expect(groups[0]?.items.map((item) => item.value)).toEqual([
372+
"thread:word-start",
373+
"thread:branch-word-start",
374+
"thread:mid-word",
375+
]);
376+
});
377+
378+
it("breaks ties within a match tier by latest user message", () => {
379+
const items = buildThreadActionItems({
380+
threads: [
381+
makeThread({
382+
id: ThreadId.make("prefix-stale"),
383+
title: "Auth refactor",
384+
updatedAt: "2026-03-20T00:00:00.000Z",
385+
latestUserMessageAt: "2025-09-01T00:00:00.000Z",
386+
}),
387+
makeThread({
388+
id: ThreadId.make("word-fresh"),
389+
title: "Fix auth refresh",
390+
updatedAt: "2026-03-10T00:00:00.000Z",
391+
latestUserMessageAt: "2026-03-10T00:00:00.000Z",
392+
}),
393+
],
394+
projectTitleById: new Map(),
395+
sortOrder: "updated_at",
396+
icon: null,
397+
runThread: async () => undefined,
398+
});
399+
400+
const groups = filterCommandPaletteGroups({
401+
activeGroups: [],
402+
query: "auth",
403+
isInSubmenu: false,
404+
projectSearchItems: [],
405+
threadSearchItems: items,
406+
});
407+
408+
expect(groups[0]?.items.map((item) => item.value)).toEqual([
409+
"thread:word-fresh",
410+
"thread:prefix-stale",
411+
]);
412+
});
303413
});
304414

305415
describe("filterPinnedBrowseEntries", () => {

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { getThreadSortTimestamp, sortThreads } from "../lib/threadSort";
2525
import { normalizeSearchText } from "../lib/utils";
2626
import { formatRelativeTimeLabel } from "../timestampFormat";
2727
import { type Project, type SidebarThreadSummary, type Thread } from "../types";
28+
import { isSidebarSubagentThread } from "./Sidebar.logic";
2829

2930
export const RECENT_THREAD_LIMIT = 12;
3031
export const ITEM_ICON_CLASS = "size-4 text-icon-muted";
@@ -353,6 +354,7 @@ export type BuildThreadActionItemsThread = Pick<
353354
| "createdAt"
354355
| "environmentId"
355356
| "id"
357+
| "lineage"
356358
| "modelSelection"
357359
| "projectId"
358360
| "runtime"
@@ -378,7 +380,9 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
378380
limit?: number;
379381
}): CommandPaletteActionItem[] {
380382
const sortedThreads = sortThreads(
381-
input.threads.filter((thread) => thread.archivedAt === null),
383+
input.threads.filter(
384+
(thread) => thread.archivedAt === null && !isSidebarSubagentThread(thread),
385+
),
382386
input.sortOrder,
383387
);
384388
const visibleThreads =
@@ -437,6 +441,16 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
437441
});
438442
}
439443

444+
const ALPHANUMERIC = /[\p{L}\p{N}]/u;
445+
446+
function startsWord(field: string, token: string): boolean {
447+
for (let index = field.indexOf(token); index !== -1; index = field.indexOf(token, index + 1)) {
448+
if (index === 0 || !ALPHANUMERIC.test(field[index - 1]!)) return true;
449+
}
450+
return false;
451+
}
452+
453+
// 3 exact, 2 field prefix, 1 every token starts a word, 0 a token only matches mid-word.
440454
function rankSearchFieldMatch(
441455
field: string,
442456
normalizedQuery: string,
@@ -455,33 +469,30 @@ function rankSearchFieldMatch(
455469
if (normalizedField.startsWith(normalizedQuery)) {
456470
return 2;
457471
}
458-
if (normalizedField.includes(normalizedQuery)) {
472+
if (queryTokens.every((token) => startsWord(normalizedField, token))) {
459473
return 1;
460474
}
461475
return 0;
462476
}
463477

478+
// A word-start match in any field beats a mid-word match, then earlier fields win.
479+
// Thread titles collapse prefix and word-start into one tier so recency picks between them.
464480
function rankCommandPaletteItemMatch(
465481
item: CommandPaletteActionItem | CommandPaletteSubmenuItem,
466482
normalizedQuery: string,
467483
queryTokens: ReadonlyArray<string>,
468484
): number {
469-
const terms = item.searchTerms.filter((term) => term.length > 0);
470-
if (terms.length === 0) {
471-
return 0;
472-
}
473-
474-
for (const [index, field] of terms.entries()) {
485+
let best = 0;
486+
for (const [index, field] of item.searchTerms.filter((term) => term.length > 0).entries()) {
475487
const fieldRank = rankSearchFieldMatch(field, normalizedQuery, queryTokens);
476-
if (fieldRank !== Number.NEGATIVE_INFINITY) {
477-
if (index === 0 && item.searchRecency !== undefined) {
478-
return 1_000 + Number(fieldRank === 3);
479-
}
480-
return 1_000 - index * 100 + fieldRank;
481-
}
488+
if (fieldRank === Number.NEGATIVE_INFINITY) continue;
489+
const fieldScore =
490+
index === 0 && item.searchRecency !== undefined
491+
? 1_000 + Number(fieldRank === 3)
492+
: 1_000 - index * 100 + fieldRank;
493+
best = Math.max(best, (fieldRank > 0 ? 10_000 : 0) + fieldScore);
482494
}
483-
484-
return 0;
495+
return best;
485496
}
486497

487498
export function filterCommandPaletteGroups(input: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export function buildMultiSelectThreadContextMenuItems(input: {
512512
];
513513
}
514514

515-
function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
515+
export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "lineage">): boolean {
516516
return thread.lineage.relationshipToParent === "subagent";
517517
}
518518

0 commit comments

Comments
 (0)