Skip to content

Commit f34330c

Browse files
CountMyBandsclaude
andcommitted
feat(web): limit thread notifications to chosen projects
Thread notifications are all-or-nothing across every project on every connected environment. A client connected to a server with many projects hears every thread finish, or nothing. Add a `notificationProjects` client setting (environment-scoped project keys, empty means all projects) and a searchable project picker under Settings > General > Notifications. The thread notification coordinator skips the sound, in-app toast and system notification for threads outside the chosen projects, while still tracking every thread so enabling a project later never replays old alerts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 37fbefd commit f34330c

8 files changed

Lines changed: 190 additions & 3 deletions

File tree

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as DesktopClientSettings from "./DesktopClientSettings.ts";
1919
const clientSettings: ClientSettings = {
2020
...DEFAULT_CLIENT_SETTINGS,
2121
notificationMode: "notifications-and-sound",
22+
notificationProjects: ["environment-1:project-a"],
2223
inAppNotificationsEnabled: true,
2324
appearanceContrast: 100,
2425
browserDefaultViewport: { _tag: "preset", width: 1024, height: 600, presetId: "nest-hub" },

‎apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { fakeTimers, stubGlobal } from "../../test/render";
1111
const state = vi.hoisted(() => ({
1212
mode: "notifications",
1313
inApp: false,
14+
projects: [] as ReadonlyArray<string>,
1415
toast: vi.fn(),
1516
shells: null as unknown as { set: (id: string, value: unknown) => void },
1617
navigate: vi.fn(),
@@ -67,6 +68,7 @@ vi.mock(import("../hooks/useSettings"), async (original) => ({
6768
getClientSettings: (() => ({
6869
notificationMode: state.mode,
6970
inAppNotificationsEnabled: state.inApp,
71+
notificationProjects: state.projects,
7072
})) as never,
7173
}));
7274
vi.mock(import("../threadNotifications"), async (original) => ({
@@ -189,6 +191,7 @@ function setup() {
189191
stack.defer(() => testRegistry.dispose());
190192
state.mode = "notifications";
191193
state.inApp = false;
194+
state.projects = [];
192195
state.settingsListeners.clear();
193196
registry.set(environmentIdsAtom, ["one", "two"]);
194197
state.shells.set("one", shell());
@@ -260,3 +263,20 @@ it("holds a completion through a continuation gap and notifies once it settles",
260263
await vi.advanceTimersByTimeAsync(1);
261264
expect(TestNotification.sent.map((sent) => sent.title)).toEqual(["Thread completed"]);
262265
});
266+
267+
it("sounds completions only for the chosen projects", async () => {
268+
await using app = setup();
269+
state.mode = "sound";
270+
state.projects = ["two:project"];
271+
app.start();
272+
using _timers = fakeTimers();
273+
const completed = shell({
274+
latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:00:01.000Z" },
275+
});
276+
state.shells.set("one", completed);
277+
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
278+
expect(state.sound).not.toHaveBeenCalled();
279+
state.shells.set("two", completed);
280+
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
281+
expect(state.sound).toHaveBeenCalledTimes(1);
282+
});

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { scopedProjectKey, scopeProjectRef } from "@t3tools/client-runtime/environment";
12
import {
23
type EnvironmentThreadShell,
34
type PendingSubagentRequest,
@@ -79,7 +80,18 @@ export function startThreadNotifications(
7980
kind: ThreadNotificationKind,
8081
) => {
8182
const { thread, status } = state;
82-
const { notificationMode: mode, inAppNotificationsEnabled } = getClientSettings();
83+
const {
84+
notificationMode: mode,
85+
inAppNotificationsEnabled,
86+
notificationProjects,
87+
} = getClientSettings();
88+
if (
89+
notificationProjects.length > 0 &&
90+
!notificationProjects.includes(
91+
scopedProjectKey(scopeProjectRef(environmentId, thread.projectId)),
92+
)
93+
)
94+
return;
8395
const active = (router.state.matches.at(-1)?.params ?? {}) as {
8496
environmentId?: string;
8597
threadId?: string;

‎apps/web/src/components/settings/NotificationSettings.tsx‎

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
import { scopedProjectKey, scopeProjectRef } from "@t3tools/client-runtime/environment";
12
import { settlePromise } from "@t3tools/client-runtime/state/runtime";
3+
import { ChevronDownIcon } from "lucide-react";
24
import { useState } from "react";
35

6+
import { getClientSettings } from "../../hooks/useSettings";
7+
import { normalizeSearchText } from "../../lib/utils";
8+
import { useProjects } from "../../state/entities";
9+
import { useEnvironments } from "../../state/environments";
410
import {
511
hasDesktopNotifications,
612
hasNotificationSound,
713
NOTIFICATION_MODE_LABELS,
814
unlockNotificationAudio,
915
} from "../../threadNotifications";
16+
import { ProjectFavicon } from "../ProjectFavicon";
17+
import { Button } from "../ui/button";
18+
import {
19+
Menu,
20+
MenuCheckboxItem,
21+
MenuItem,
22+
MenuPopup,
23+
MenuSearchInput,
24+
MenuSeparator,
25+
MenuTrigger,
26+
} from "../ui/menu";
1027
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
11-
import { SettingsRow } from "./settingsLayout";
28+
import { SettingResetButton, SettingsRow } from "./settingsLayout";
1229
import { searchableSetting } from "./settingsSearch";
1330
import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
1431

@@ -80,3 +97,110 @@ export function NotificationSettings() {
8097
/>
8198
);
8299
}
100+
101+
export function NotificationProjectsSettings() {
102+
const selected = useScopedSettings((settings) => settings.notificationProjects);
103+
const updateSettings = useUpdateScopedSettings();
104+
const projects = useProjects();
105+
const { environments } = useEnvironments();
106+
const [query, setQuery] = useState("");
107+
const environmentLabels = new Map(
108+
environments.map((environment) => [environment.environmentId, environment.label]),
109+
);
110+
const showEnvironment = new Set(projects.map((project) => project.environmentId)).size > 1;
111+
const normalizedQuery = normalizeSearchText(query);
112+
const options = projects
113+
.map((project) => ({
114+
project,
115+
key: scopedProjectKey(scopeProjectRef(project.environmentId, project.id)),
116+
environmentLabel: showEnvironment
117+
? (environmentLabels.get(project.environmentId) ?? null)
118+
: null,
119+
}))
120+
.filter(
121+
(option) =>
122+
normalizedQuery === "" ||
123+
normalizeSearchText(`${option.project.title} ${option.environmentLabel ?? ""}`).includes(
124+
normalizedQuery,
125+
),
126+
)
127+
.toSorted((left, right) => left.project.title.localeCompare(right.project.title));
128+
const summary =
129+
selected.length === 0
130+
? "All projects"
131+
: `${selected.length} ${selected.length === 1 ? "project" : "projects"}`;
132+
const setProject = (key: string, checked: boolean) => {
133+
const current = getClientSettings().notificationProjects.filter((entry) => entry !== key);
134+
updateSettings({ notificationProjects: checked ? [...current, key] : current });
135+
};
136+
137+
return (
138+
<SettingsRow
139+
title={searchableSetting("notification-projects").title}
140+
description="Only alert for threads in these projects."
141+
resetAction={
142+
selected.length === 0 ? null : (
143+
<SettingResetButton
144+
label="notification projects"
145+
onClick={() => updateSettings({ notificationProjects: [] })}
146+
/>
147+
)
148+
}
149+
control={
150+
<Menu
151+
onOpenChange={(open) => {
152+
if (!open) setQuery("");
153+
}}
154+
>
155+
<MenuTrigger
156+
render={
157+
<Button
158+
variant="outline"
159+
size="sm"
160+
className="w-full justify-between sm:w-56"
161+
aria-label={`Notification projects: ${summary}`}
162+
/>
163+
}
164+
>
165+
{summary}
166+
<ChevronDownIcon aria-hidden />
167+
</MenuTrigger>
168+
<MenuPopup align="end">
169+
<MenuSearchInput
170+
autoFocus
171+
value={query}
172+
onChange={(event) => setQuery(event.currentTarget.value)}
173+
placeholder="Search projects"
174+
aria-label="Search projects"
175+
/>
176+
<MenuCheckboxItem
177+
checked={selected.length === 0}
178+
onCheckedChange={() => updateSettings({ notificationProjects: [] })}
179+
>
180+
All projects
181+
</MenuCheckboxItem>
182+
<MenuSeparator />
183+
{options.length === 0 ? <MenuItem disabled>No projects found</MenuItem> : null}
184+
{options.map(({ project, key, environmentLabel }) => (
185+
<MenuCheckboxItem
186+
key={key}
187+
checked={selected.includes(key)}
188+
onCheckedChange={(checked) => setProject(key, checked)}
189+
>
190+
<span className="flex min-w-0 items-center gap-2">
191+
<ProjectFavicon project={project} className="size-3.5" />
192+
<span className="min-w-0 flex-1 truncate">{project.title}</span>
193+
{environmentLabel ? (
194+
<span className="shrink-0 text-xs text-muted-foreground">
195+
{environmentLabel}
196+
</span>
197+
) : null}
198+
</span>
199+
</MenuCheckboxItem>
200+
))}
201+
</MenuPopup>
202+
</Menu>
203+
}
204+
/>
205+
);
206+
}

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import { NotificationSettings } from "./NotificationSettings";
2+
import { NotificationProjectsSettings, NotificationSettings } from "./NotificationSettings";
33
import { PRIVACY_POLICY_URL } from "../../legalLinks";
44
import { CheckIcon } from "lucide-react";
55
import { Link, useNavigate } from "@tanstack/react-router";
@@ -453,6 +453,7 @@ export function useSettingsRestore(onRestored?: () => void) {
453453
...(settings.notificationMode !== DEFAULT_UNIFIED_SETTINGS.notificationMode
454454
? ["Thread notifications"]
455455
: []),
456+
...(settings.notificationProjects.length > 0 ? ["Notification projects"] : []),
456457
...(settings.inAppNotificationsEnabled !== DEFAULT_UNIFIED_SETTINGS.inAppNotificationsEnabled
457458
? ["In-app notifications"]
458459
: []),
@@ -613,6 +614,7 @@ export function useSettingsRestore(onRestored?: () => void) {
613614
mathRenderingEnabled: DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled,
614615
timestampFormat: DEFAULT_UNIFIED_SETTINGS.timestampFormat,
615616
notificationMode: DEFAULT_UNIFIED_SETTINGS.notificationMode,
617+
notificationProjects: DEFAULT_UNIFIED_SETTINGS.notificationProjects,
616618
inAppNotificationsEnabled: DEFAULT_UNIFIED_SETTINGS.inAppNotificationsEnabled,
617619
wordWrap: DEFAULT_UNIFIED_SETTINGS.wordWrap,
618620
persistComposerContextStrip: DEFAULT_UNIFIED_SETTINGS.persistComposerContextStrip,
@@ -782,6 +784,9 @@ export function GeneralSettingsPanel() {
782784
/>
783785
}
784786
/>
787+
{settings.notificationMode !== "off" || settings.inAppNotificationsEnabled ? (
788+
<NotificationProjectsSettings />
789+
) : null}
785790
</SettingsSection>
786791

787792
<SettingsSection id="sidebar" title="Sidebar">

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ export const SETTINGS_SEARCH_ITEMS = [
513513
to: "/settings/general",
514514
searchTerms: ["notification sound alert completion input approval desktop"],
515515
},
516+
{
517+
id: "notification-projects",
518+
title: "Notification projects",
519+
to: "/settings/general",
520+
targetId: "thread-notifications",
521+
searchTerms: ["notification sound alert toast filter only some chosen selected projects"],
522+
},
516523
{
517524
id: "in-app-notifications",
518525
title: "In-app notifications",

‎packages/contracts/src/settings.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,21 @@ describe("ClientSettings notifications", () => {
193193
it("requires opt-in when existing settings omit notification preferences", () => {
194194
expect(decodeClientSettings({}).notificationMode).toBe("off");
195195
expect(decodeClientSettings({}).inAppNotificationsEnabled).toBe(false);
196+
expect(decodeClientSettings({}).notificationProjects).toEqual([]);
196197
expect(decodeClientSettingsPatch({})).not.toHaveProperty("inAppNotificationsEnabled");
197198
expect(decodeClientSettingsPatch({})).not.toHaveProperty("notificationMode");
199+
expect(decodeClientSettingsPatch({})).not.toHaveProperty("notificationProjects");
200+
});
201+
202+
it("round-trips the chosen notification projects", () => {
203+
const notificationProjects = ["environment-1:project-a", "environment-2:project-a"];
204+
const settings = decodeClientSettings({ notificationProjects });
205+
206+
expect(settings.notificationProjects).toEqual(notificationProjects);
207+
expect(encodeClientSettings(settings).notificationProjects).toEqual(notificationProjects);
208+
expect(decodeClientSettingsPatch({ notificationProjects: [] })).toEqual({
209+
notificationProjects: [],
210+
});
198211
});
199212
});
200213

‎packages/contracts/src/settings.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ export const ClientSettingsSchema = Schema.Struct({
351351
notificationMode: NotificationMode.pipe(
352352
Schema.withDecodingDefault(Effect.succeed("off" as const)),
353353
),
354+
// `environmentId:projectId` keys; empty means every project.
355+
notificationProjects: Schema.Array(TrimmedNonEmptyString).pipe(
356+
Schema.withDecodingDefault(Effect.succeed([])),
357+
),
354358
inAppNotificationsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
355359
diffColorScheme: DiffColorScheme.pipe(
356360
Schema.withDecodingDefault(Effect.succeed("red-green" as const)),
@@ -1672,6 +1676,7 @@ export function requiredScopesForProjectMutation(
16721676

16731677
export const ClientSettingsPatch = Schema.Struct({
16741678
notificationMode: Schema.optionalKey(NotificationMode),
1679+
notificationProjects: Schema.optionalKey(Schema.Array(TrimmedNonEmptyString)),
16751680
inAppNotificationsEnabled: Schema.optionalKey(Schema.Boolean),
16761681
diffColorScheme: Schema.optionalKey(DiffColorScheme),
16771682
chatWidth: Schema.optionalKey(ChatWidth),

0 commit comments

Comments
 (0)