Skip to content

Commit 486e3d4

Browse files
committed
fix(home): retain message matches in command palettes
1 parent 253205f commit 486e3d4

8 files changed

Lines changed: 64 additions & 22 deletions

File tree

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ export function CommandPalette(props: {
439439
const threadItems: CommandPaletteItem[] = threads
440440
.filter(
441441
(thread) =>
442-
thread.archivedAt === null &&
443-
thread.lineage.relationshipToParent !== "subagent" &&
444-
!isHomeThreadId(thread.id),
442+
thread.archivedAt === null && thread.lineage.relationshipToParent !== "subagent",
445443
)
446444
.map((thread) => {
447445
const project = projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId));
@@ -463,10 +461,18 @@ export function CommandPalette(props: {
463461
? { secondary: true }
464462
: {}),
465463
run: () =>
466-
selectDetail({
467-
name: "Thread",
468-
params: { environmentId: String(thread.environmentId), threadId: String(thread.id) },
469-
}),
464+
isHomeThreadId(thread.id)
465+
? navigation.navigate("HomeAgent", {
466+
environmentId: thread.environmentId,
467+
threadId: thread.id,
468+
})
469+
: selectDetail({
470+
name: "Thread",
471+
params: {
472+
environmentId: String(thread.environmentId),
473+
threadId: String(thread.id),
474+
},
475+
}),
470476
};
471477
});
472478
// Recent means used recently: written in or opened, whichever is later.

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,26 @@ describe("filterCommandPaletteItems", () => {
4646
});
4747

4848
it("lists message matches after the other results, once, except in actions-only mode", () => {
49-
const results = filterCommandPaletteItems(items, "layout", ["siva:one", "mac:one"], NOW);
49+
const home = {
50+
...item("studio:home:managed", "Home", "thread"),
51+
threadSearch: { id: "home:managed", title: "Home", activityAt: NOW },
52+
};
53+
const candidates = [...items, home];
54+
expect(keys(filterCommandPaletteItems(candidates, "", [], NOW))).not.toContain(home.key);
55+
expect(keys(filterCommandPaletteItems(candidates, "home", [], NOW))).not.toContain(home.key);
56+
const results = filterCommandPaletteItems(
57+
candidates,
58+
"layout",
59+
["siva:one", "mac:one", home.key],
60+
NOW,
61+
);
5062
expect(results.map((entry) => [entry.key, entry.fromMessages ?? false])).toEqual([
5163
["mac:one", false],
5264
["siva:one", true],
65+
[home.key, true],
5366
]);
54-
expect(filterCommandPaletteItems(items, "> layout", ["siva:one"], NOW)).toEqual([]);
67+
expect(filterCommandPaletteItems(candidates, "> layout", ["siva:one", home.key], NOW)).toEqual(
68+
[],
69+
);
5570
});
5671
});

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isHomeThreadId } from "@t3tools/contracts";
12
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
23
import {
34
foldSearchQuery,
@@ -49,7 +50,10 @@ export function filterCommandPaletteItems(
4950
): CommandPaletteResult[] {
5051
const actionsOnly = query.startsWith(">");
5152
const normalizedQuery = foldSearchQuery(actionsOnly ? query.slice(1) : query);
52-
const candidates = actionsOnly ? items.filter((item) => item.kind === "action") : items;
53+
const candidates = items.filter(
54+
(item) =>
55+
!isHomeThreadId(item.threadSearch?.id ?? "") && (!actionsOnly || item.kind === "action"),
56+
);
5357
if (!normalizedQuery) return candidates.filter((item) => item.kind !== "project");
5458

5559
// On equal match classes, groups keep this order, as on web.

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe("buildThreadActionItems", () => {
175175
icon: null,
176176
runThread,
177177
});
178-
expect(new Set(items.map((item) => item.value)).size).toBe(2);
178+
expect(new Set(items.map((item) => item.value)).size).toBe(3);
179179
const remoteItem = items.find((item) => item.description === "Remote project · Current thread");
180180
await remoteItem?.run();
181181
expect(runThread).toHaveBeenCalledWith(remote);
@@ -271,13 +271,15 @@ describe("buildThreadActionItems", () => {
271271
const threads = [
272272
makeThread({ id: ThreadId.make("title"), title: "Disable Convex schema validation" }),
273273
makeThread({ id: ThreadId.make("message"), title: "Fix schema validation" }),
274+
makeThread({ id: ThreadId.make("home:managed"), title: "Home" }),
274275
];
275276
const items = buildThreadActionItems({
276277
threads,
277278
projectByKey: new Map(),
278279
icon: null,
279280
runThread: async () => undefined,
280281
});
282+
expect(items.map((item) => item.value)).toContain("thread:environment-local:home:managed");
281283
const filter = (threadMessageItems: typeof items) =>
282284
filterCommandPaletteGroups({
283285
activeGroups: [],
@@ -290,11 +292,14 @@ describe("buildThreadActionItems", () => {
290292

291293
const before = filter([]);
292294
// The server matched both; the title match stays where it was.
293-
const after = filter([items[0]!, items[1]!].toReversed());
295+
const after = filter(items.toReversed());
294296
expect(before).toEqual([["Threads", ["thread:environment-local:title"]]]);
295297
expect(after).toEqual([
296298
["Threads", ["thread:environment-local:title"]],
297-
["In messages", ["thread:environment-local:message"]],
299+
[
300+
"In messages",
301+
["thread:environment-local:home:managed", "thread:environment-local:message"],
302+
],
298303
]);
299304
});
300305

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
type SourceControlDiscoveryResult,
2727
type SourceControlRepositoryInfo,
2828
THREAD_JUMP_KEYBINDING_COMMANDS,
29-
isHomeThreadId,
3029
} from "@t3tools/contracts";
3130
import { filterFilesystemBrowseEntries } from "@t3tools/client-runtime/state/filesystem";
3231
import { type ReactNode } from "react";
@@ -421,8 +420,7 @@ export function buildThreadActionItems<TThread extends BuildThreadActionItemsThr
421420
}): CommandPaletteActionItem[] {
422421
// Callers order these: recents by last use, search results by rank.
423422
const visibleThreads = input.threads.filter(
424-
(thread) =>
425-
thread.archivedAt === null && !isSidebarSubagentThread(thread) && !isHomeThreadId(thread.id),
423+
(thread) => thread.archivedAt === null && !isSidebarSubagentThread(thread),
426424
);
427425

428426
return visibleThreads.map((thread) => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
pickedQuery,
1313
rankMessageMatches,
1414
} from "@t3tools/shared/paletteSearch";
15-
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
15+
import { isHomeThreadId, type EnvironmentId, type ThreadId } from "@t3tools/contracts";
1616
import { useAtomValue } from "@effect/atom-react";
1717
import { useNavigate } from "@tanstack/react-router";
1818
import { MessageSquareIcon } from "lucide-react";
@@ -109,7 +109,7 @@ export function useCommandPaletteThreadItems(input: {
109109
const [now] = useState(() => Date.now());
110110

111111
const { environments } = useEnvironments();
112-
const threadItems = buildThreadActionItems({
112+
const candidateItems = buildThreadActionItems({
113113
threads,
114114
...(environments.length > 1
115115
? {
@@ -190,7 +190,7 @@ export function useCommandPaletteThreadItems(input: {
190190
},
191191
});
192192

193-
const itemByValue = new Map(threadItems.map((item) => [item.value, item]));
193+
const itemByValue = new Map(candidateItems.map((item) => [item.value, item]));
194194
const itemForMatch = (match: EnvironmentThreadSearchMatch) =>
195195
itemByValue.get(`thread:${match.environmentId}:${match.threadId}`);
196196
const rankedMessageItems = rankMessageMatches(
@@ -243,7 +243,7 @@ export function useCommandPaletteThreadItems(input: {
243243
.flatMap((value) => messageItemByValue.get(value) ?? []);
244244

245245
return {
246-
threadItems,
246+
threadItems: candidateItems.filter((item) => !isHomeThreadId(item.threadSearch?.id ?? "")),
247247
threadMessageItems,
248248
now,
249249
isSearchPending: messageSearch.isPending,

‎packages/shared/src/paletteSearch.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,11 @@ describe("rankMessageMatches", () => {
461461
),
462462
).toEqual(["b-picked", "b-recent", "a-word", "a-word-2", "b-prefix"]);
463463
// A palette lists title matches above, so they use up no message rows.
464-
const titled = new Map([...subjects, ["c-titled", thread("Needle cleanup")]]);
464+
const titled = new Map([
465+
...subjects,
466+
["c-titled", thread("Needle cleanup")],
467+
["home", { ...thread("Home needle"), id: "home:managed" }],
468+
]);
465469
expect(
466470
rankMessageMatches(
467471
[{ key: "c-titled", quality: 1 }, ...matches],
@@ -471,6 +475,15 @@ describe("rankMessageMatches", () => {
471475
{ withoutTitleMatches: true },
472476
).map((match) => match.key),
473477
).not.toContain("c-titled");
478+
expect(
479+
rankMessageMatches(
480+
[{ key: "home", quality: 1 }],
481+
(match) => titled.get(match.key),
482+
"home",
483+
NOW,
484+
{ withoutTitleMatches: true },
485+
).map((match) => match.key),
486+
).toEqual(["home"]);
474487
});
475488

476489
it("ranks a thread that keeps using the word above a passing mention of equal quality", () => {

‎packages/shared/src/paletteSearch.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Shared ranking keeps command palettes and MCP thread search consistent across surfaces. */
22

3-
import type { OrchestrationV2ThreadOpens } from "@t3tools/contracts";
3+
import { isHomeThreadId, type OrchestrationV2ThreadOpens } from "@t3tools/contracts";
44

55
import { WORKTREE_BRANCH_PREFIX } from "./git.ts";
66

@@ -1038,6 +1038,7 @@ export function rankMessageMatches<
10381038
if (!subject) return [];
10391039
if (
10401040
options?.withoutTitleMatches &&
1041+
!isHomeThreadId(subject.id ?? "") &&
10411042
scoreThreadSearch(normalizedQuery, subject, now, { picks: false }) !== null
10421043
) {
10431044
return [];

0 commit comments

Comments
 (0)