Skip to content

Commit d1e9d91

Browse files
committed
feat: show, edit and filter thread tags, and manage them in settings
Threads could already store tags (#29053), but nothing in the apps let you see or change them. This adds the UI asked for in discussion #29334. - Tags show on sidebar rows, in the thread header and in the row hover card (web/desktop), and on mobile rows and headers. - A tag picker (search, checklist, create) opens from the thread menu, the command palette and the header tags; mobile gets the same as a sheet. - The sidebar can filter by one or more tags; mobile filters by one. - Agents can tag and untag threads through t3_thread_organize. - Tags are case-insensitive and keep their first spelling. - Settings > Tags lists tags with thread counts and renames or deletes a tag on every thread of that machine, archived ones included. - Older servers hide all of this through the threadTags capability.
1 parent fcd0687 commit d1e9d91

86 files changed

Lines changed: 2467 additions & 172 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { DEFAULT_HOSTED_APP_URL } from "@t3tools/shared/connectAuth";
2424
import { RegistryContext, useAtomValue } from "@effect/atom-react";
2525
import { ProjectChipIconRasterizer } from "./native/ProjectChipIconImages";
2626
import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet";
27+
import { ThreadTagsHost } from "./features/threads/ThreadTagsSheet";
2728
import * as Dialog from "./components/ui/Dialog";
2829
import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";
2930
import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";
@@ -292,6 +293,7 @@ function AppContent() {
292293
/>
293294
<Dialog.Host />
294295
<ThreadArrangementHost />
296+
<ThreadTagsHost />
295297
<ProjectChipIconRasterizer />
296298
</NativeLayoutMetricsProvider>
297299
</GlobalVoiceInputControl>

‎apps/mobile/src/Stack.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import {
103103
SettingsWorktreesRouteScreen,
104104
SettingsEnvironmentSourceControlRouteScreen,
105105
} from "./features/settings/SettingsServerControlsRouteScreen";
106+
import { SettingsTagsRouteScreen } from "./features/settings/SettingsTagsRouteScreen";
106107
import {
107108
SettingsScheduledTasksRouteScreen,
108109
SettingsScheduledTaskNewRouteScreen,
@@ -282,6 +283,11 @@ const SETTINGS_SCREENS = {
282283
screen: SettingsVoiceModelsRouteScreen,
283284
options: SEARCH_SHEET_ROUTE,
284285
}),
286+
SettingsTags: createNativeStackScreen({
287+
screen: SettingsTagsRouteScreen,
288+
linking: "settings/tags",
289+
options: settingsPage("Tags"),
290+
}),
285291
SettingsFollowUp: createNativeStackScreen({
286292
screen: SettingsFollowUpRouteScreen,
287293
linking: "settings/follow-ups",

‎apps/mobile/src/components/ui/Chip.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function Chip(props: {
3737
) : null}
3838
<AppText
3939
textRole={small ? "caption" : "footnote"}
40-
numberOfLines={small ? undefined : 1}
40+
numberOfLines={1}
4141
className={cn(
4242
"shrink",
4343
!small && "max-w-[180px]",

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { uuidv4 } from "../../lib/uuid";
2+
import { threadTagKey } from "@t3tools/contracts";
23
import { ThreadUndoNotice } from "./ThreadUndoNotice";
34
import { use } from "react";
45
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
@@ -11,8 +12,9 @@ import { Platform } from "react-native";
1112
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
1213
import { pickableProjectGroups } from "@t3tools/client-runtime/state/project-grouping";
1314

14-
import { useProjects } from "../../state/entities";
15-
import { steadyNavigationThreadShellsAtom } from "../../state/threads";
15+
import { useProjects, useQuietThreadShells } from "../../state/entities";
16+
import { steadyNavigationThreadShellsAtom, steadyThreadShellsAtom } from "../../state/threads";
17+
import { threadListEnvironmentsAtom } from "../../state/presentation";
1618
import { useLaunchingThreads, usePendingNewTasks } from "../../state/use-pending-new-tasks";
1719
import { useWorkspaceState } from "../../state/workspace";
1820
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
@@ -31,6 +33,8 @@ import {
3133
import { buildHomeProjectScopes, resolveHomeProjectFilterScope } from "./homeThreadList";
3234
import { usePendingTaskListActions } from "./usePendingTaskListActions";
3335
import { useThreadListActions } from "./useThreadListActions";
36+
import { collectThreadTags } from "@t3tools/client-runtime/state/threadTagFilter";
37+
import { filterListedThreadsByTag } from "../threads/thread-tags";
3438
import { useWorkspaceTabs } from "../layout/workspace/WorkspaceTabsContext";
3539
import { openSettings } from "../settings/settings-navigation";
3640
import { useSelectWorkspaceTab } from "../layout/workspace/useSelectWorkspaceTab";
@@ -47,7 +51,7 @@ export function HomeRouteScreen() {
4751
const projects = useProjects();
4852
// Stop rebuilding the streaming thread list while Thread covers Home.
4953
const visible = useHomeRouteVisible();
50-
const threads = useLaunchingThreads(
54+
const allThreads = useLaunchingThreads(
5155
useAtomValueWhileVisible(steadyNavigationThreadShellsAtom, visible),
5256
);
5357
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
@@ -125,8 +129,30 @@ export function HomeRouteScreen() {
125129
options: listOptions,
126130
setSelectedEnvironmentId,
127131
setSelectedProjectKey,
128-
} = useHomeListOptions(availableEnvironmentIds);
132+
setSelectedTag,
133+
} = useHomeListOptions(
134+
availableEnvironmentIds,
135+
useAtomValueWhileVisible(threadListEnvironmentsAtom, visible).tagEnvironmentIds,
136+
);
129137
const selectedEnvironmentId = listOptions.selectedEnvironmentId;
138+
const selectedTag = listOptions.selectedTag;
139+
const fullShells = useAtomValueWhileVisible(
140+
steadyThreadShellsAtom,
141+
visible && selectedTag !== null,
142+
);
143+
const threads = useMemo(
144+
() => filterListedThreadsByTag(allThreads, fullShells, selectedTag),
145+
[allThreads, fullShells, selectedTag],
146+
);
147+
// Quiet shells include nested subagents, so a tag only a child carries is still offered.
148+
const quietShells = useQuietThreadShells();
149+
const tags = useMemo(() => {
150+
const known = collectThreadTags(quietShells);
151+
return selectedTag === null ||
152+
known.some((tag) => threadTagKey(tag) === threadTagKey(selectedTag))
153+
? known
154+
: [...known, selectedTag];
155+
}, [quietShells, selectedTag]);
130156
const projectScopes = useMemo(
131157
() =>
132158
buildHomeProjectScopes({
@@ -170,14 +196,18 @@ export function HomeRouteScreen() {
170196
accessibilityLabel: "Search threads",
171197
}}
172198
filter={{
173-
customized: selectedEnvironmentId !== null || selectedProjectKey !== null,
199+
customized:
200+
selectedEnvironmentId !== null || selectedProjectKey !== null || selectedTag !== null,
174201
items: buildHomeListFilterMenuItems({
175202
environments,
176203
projects: projectFilterOptions,
177204
selectedEnvironmentId,
178205
selectedProjectKey,
179206
onEnvironmentChange: setSelectedEnvironmentId,
180207
onProjectChange: setSelectedProjectKey,
208+
tags,
209+
selectedTag,
210+
onTagChange: setSelectedTag,
181211
}),
182212
}}
183213
/>
@@ -200,6 +230,9 @@ export function HomeRouteScreen() {
200230
onRegenerateThreadTitle={regenerateThreadTitle}
201231
onEnvironmentChange={setSelectedEnvironmentId}
202232
onProjectChange={setSelectedProjectKey}
233+
selectedTag={selectedTag}
234+
tags={tags}
235+
onTagChange={setSelectedTag}
203236
onOpenSettings={() => selectTab("settings")}
204237
onSearchQueryChange={setSearchQuery}
205238
onSelectThread={handleSelectThread}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ interface HomeScreenProps {
115115
readonly searchQuery: string;
116116
readonly selectedEnvironmentId: EnvironmentId | null;
117117
readonly selectedProjectKey: string | null;
118+
readonly selectedTag: string | null;
119+
readonly tags: ReadonlyArray<string>;
120+
readonly onTagChange: (tag: string | null) => void;
118121
readonly projectSortOrder: HomeProjectSortOrder;
119122
readonly projectGroupingMode: SidebarProjectGroupingMode;
120123
readonly onSearchQueryChange: (query: string) => void;
@@ -397,6 +400,7 @@ export function HomeScreen(props: HomeScreenProps) {
397400
snoozePresetsByEnvironmentId,
398401
pinningEnvironmentIds,
399402
autoSettleOptOutEnvironmentIds,
403+
tagEnvironmentIds,
400404
pinReorderEnvironmentIds,
401405
activeReorderEnvironmentIds,
402406
titleRegenerationEnvironmentIds,
@@ -421,6 +425,7 @@ export function HomeScreen(props: HomeScreenProps) {
421425
activeReorderEnvironmentIds,
422426
queuedThreadKeys,
423427
settledLimit: settledVisibleCount,
428+
tagFilterActive: props.selectedTag !== null,
424429
now,
425430
pendingOrder,
426431
shelfPreferencesLoaded,
@@ -568,6 +573,7 @@ export function HomeScreen(props: HomeScreenProps) {
568573
snoozePresets={snoozePresetsByEnvironmentId.get(thread.environmentId)}
569574
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
570575
autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
576+
tagsSupported={tagEnvironmentIds.has(thread.environmentId)}
571577
reorderSupported={
572578
item.item.pinned
573579
? pinReorderEnvironmentIds.has(thread.environmentId)
@@ -604,7 +610,9 @@ export function HomeScreen(props: HomeScreenProps) {
604610
workingShelfEnabled,
605611
};
606612

613+
// A tag filter that matches nothing keeps its controls and its own empty state.
607614
const hasAnyThreads =
615+
props.selectedTag !== null ||
608616
props.threads.some((thread) => thread.archivedAt === null) ||
609617
props.pendingTasks.length > 0 ||
610618
threadListV2Layout.settledCount > 0;
@@ -686,6 +694,9 @@ export function HomeScreen(props: HomeScreenProps) {
686694
selectedProjectKey={props.selectedProjectKey}
687695
onEnvironmentChange={props.onEnvironmentChange}
688696
onProjectChange={props.onProjectChange}
697+
tags={props.tags}
698+
selectedTag={props.selectedTag}
699+
onTagChange={props.onTagChange}
689700
/>
690701
) : null}
691702
</>
@@ -704,6 +715,12 @@ export function HomeScreen(props: HomeScreenProps) {
704715
detail={`No threads matching "${props.searchQuery}".`}
705716
variant={Platform.OS === "android" ? "plain" : undefined}
706717
/>
718+
) : props.selectedTag !== null ? (
719+
<EmptyState
720+
title={`No threads tagged ${props.selectedTag}`}
721+
detail="Choose another tag or clear the filter."
722+
variant={Platform.OS === "android" ? "plain" : undefined}
723+
/>
707724
) : v2ScopedProjectGroup !== null ? (
708725
<EmptyState
709726
title={`No threads in ${v2ScopedProjectGroup.title}`}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Pressable, ScrollView } from "react-native";
2+
import { threadTagKey } from "@t3tools/contracts";
23
import { SymbolView } from "../../components/ui/AppSymbol";
34
import { ListFilterMenu } from "../layout/workspace/ListFilterMenu";
45
import type { EnvironmentId } from "@t3tools/contracts";
@@ -14,6 +15,9 @@ export function ThreadListFilters(props: {
1415
readonly selectedProjectKey: string | null;
1516
readonly onEnvironmentChange: (environmentId: EnvironmentId | null) => void;
1617
readonly onProjectChange: (projectKey: string | null) => void;
18+
readonly tags: ReadonlyArray<string>;
19+
readonly selectedTag: string | null;
20+
readonly onTagChange: (tag: string | null) => void;
1721
/** List padding the scroller bleeds through so pills start where row content does. */
1822
readonly gutter: number;
1923
}) {
@@ -85,14 +89,36 @@ export function ThreadListFilters(props: {
8589
}
8690
}}
8791
/>
88-
{props.selectedEnvironmentId !== null || props.selectedProjectKey !== null ? (
92+
{props.tags.length > 0 || props.selectedTag !== null ? (
93+
<ListFilterMenu
94+
label={props.selectedTag ?? "All tags"}
95+
accessibilityLabel="Filter threads by tag"
96+
active={props.selectedTag !== null}
97+
actions={[
98+
{ id: "all", title: "All tags", state: props.selectedTag === null ? "on" : "off" },
99+
...props.tags.map((tag) => ({
100+
id: JSON.stringify(tag),
101+
title: tag,
102+
state:
103+
props.selectedTag !== null && threadTagKey(tag) === threadTagKey(props.selectedTag)
104+
? ("on" as const)
105+
: ("off" as const),
106+
})),
107+
]}
108+
onSelect={(id) => props.onTagChange(id === "all" ? null : (JSON.parse(id) as string))}
109+
/>
110+
) : null}
111+
{props.selectedEnvironmentId !== null ||
112+
props.selectedProjectKey !== null ||
113+
props.selectedTag !== null ? (
89114
<Pressable
90115
accessibilityRole="button"
91116
accessibilityLabel="Reset thread filters"
92117
className="h-8 w-8 items-center justify-center"
93118
onPress={() => {
94119
props.onEnvironmentChange(null);
95120
props.onProjectChange(null);
121+
props.onTagChange(null);
96122
}}
97123
>
98124
<SymbolView name="xmark.circle.fill" size={18} tintColorClassName="accent-icon-muted" />

‎apps/mobile/src/features/home/home-list-filter-menu.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { EnvironmentId } from "@t3tools/contracts";
2+
import { threadTagKey } from "@t3tools/contracts";
23

34
import type { AppBarMenuItem } from "../../components/ui/AppBar.types";
45

@@ -19,6 +20,9 @@ export function buildHomeListFilterMenuItems(props: {
1920
readonly selectedProjectKey: string | null;
2021
readonly onEnvironmentChange: (environmentId: EnvironmentId | null) => void;
2122
readonly onProjectChange: (projectKey: string | null) => void;
23+
readonly tags?: ReadonlyArray<string>;
24+
readonly selectedTag?: string | null;
25+
readonly onTagChange?: (tag: string | null) => void;
2226
}): AppBarMenuItem[] {
2327
const items: AppBarMenuItem[] = [
2428
{
@@ -64,5 +68,27 @@ export function buildHomeListFilterMenuItems(props: {
6468
});
6569
}
6670

71+
const { tags = [], selectedTag = null, onTagChange } = props;
72+
if (onTagChange && (tags.length > 0 || selectedTag !== null)) {
73+
items.push({
74+
id: "tag",
75+
title: "Tag",
76+
items: [
77+
{
78+
id: "all-tags",
79+
title: "All tags",
80+
selected: selectedTag === null,
81+
onPress: () => onTagChange(null),
82+
},
83+
...tags.map((tag) => ({
84+
id: `tag:${tag}`,
85+
title: tag,
86+
selected: selectedTag !== null && threadTagKey(selectedTag) === threadTagKey(tag),
87+
onPress: () => onTagChange(tag),
88+
})),
89+
],
90+
});
91+
}
92+
6793
return items;
6894
}

‎apps/mobile/src/features/home/home-list-options.test.tsx‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,41 @@ const AVAILABLE = new Set([ENVIRONMENT]);
1919
it("saves the scope from every update made in one event", async () => {
2020
harness.saved = [];
2121
let controls: ReturnType<typeof useHomeListOptions> | undefined;
22-
function Probe() {
23-
const result = useHomeListOptions(AVAILABLE);
22+
function Probe(props: { readonly tagEnvironmentIds: ReadonlySet<EnvironmentId> }) {
23+
const result = useHomeListOptions(AVAILABLE, props.tagEnvironmentIds);
2424
useLayoutEffect(() => {
2525
controls = result;
2626
});
2727
return null;
2828
}
2929

3030
const root = createRoot(document.createElement("div"));
31-
await act(async () =>
32-
root.render(
33-
<HomeListOptionsProvider projectGroupingMode="repository">
34-
<Probe />
35-
</HomeListOptionsProvider>,
36-
),
37-
);
31+
const renderWith = (tagEnvironmentIds: ReadonlySet<EnvironmentId>) =>
32+
act(async () =>
33+
root.render(
34+
<HomeListOptionsProvider projectGroupingMode="repository">
35+
<Probe tagEnvironmentIds={tagEnvironmentIds} />
36+
</HomeListOptionsProvider>,
37+
),
38+
);
39+
await renderWith(AVAILABLE);
3840
act(() => {
3941
controls!.setSelectedEnvironmentId(ENVIRONMENT);
4042
controls!.setSelectedProjectKey("env-1:project-1");
4143
});
4244

4345
expect(harness.saved.at(-1)).toEqual({
44-
threadListFilters: { environmentId: ENVIRONMENT, projectKey: "env-1:project-1" },
46+
threadListFilters: { environmentId: ENVIRONMENT, projectKey: "env-1:project-1", tag: null },
4547
});
4648
expect(controls!.options.selectedEnvironmentId).toBe(ENVIRONMENT);
4749
expect(controls!.options.selectedProjectKey).toBe("env-1:project-1");
50+
51+
// With no server that supports tags, the saved tag stops filtering but is kept.
52+
act(() => controls!.setSelectedTag("bug"));
53+
await renderWith(new Set());
54+
expect(controls!.options.selectedTag).toBeNull();
55+
expect(harness.saved.at(-1)).toMatchObject({ threadListFilters: { tag: "bug" } });
56+
await renderWith(AVAILABLE);
57+
expect(controls!.options.selectedTag).toBe("bug");
4858
act(() => root.unmount());
4959
});

0 commit comments

Comments
 (0)