@devries-cameron20 / t3code-1 / commits / 381514e7af
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): the background activity setting and its dialog live in their own file (#22669)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:39 UTC 381514e7af09293b35d11e21c21e5d7fe65ccb84
2 files changed +490 -464
apps/web/src/components/settings/BackgroundActivitySettings.tsx new
+487
@@ -0,0 +1,487 @@
1 +import { useScopedSettingsWriteAllowed } from "./useScopedSettings";
2 +import { SettingsIcon } from "lucide-react";
3 +import { useState } from "react";
4 +import { type BackgroundActivityProfile } from "@t3tools/contracts";
5 +import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
6 +import { resolveServerBackgroundActivitySettings } from "@t3tools/shared/backgroundActivitySettings";
7 +import * as Duration from "effect/Duration";
8 +import * as Equal from "effect/Equal";
9 +import {
10 + useScopedSettings,
11 + useScopedSettingsMixed,
12 + useUpdateScopedSettings,
13 +} from "./useScopedSettings";
14 +import { useSettingsScope } from "./SettingsScopeContext";
15 +import { Button } from "../ui/button";
16 +import {
17 + Dialog,
18 + DialogDescription,
19 + DialogFooter,
20 + DialogHeader,
21 + DialogPanel,
22 + DialogPopup,
23 + DialogTitle,
24 +} from "../ui/dialog";
25 +import {
26 + NumberField,
27 + NumberFieldDecrement,
28 + NumberFieldGroup,
29 + NumberFieldIncrement,
30 + NumberFieldInput,
31 +} from "../ui/number-field";
32 +import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
33 +import { Switch } from "../ui/switch";
34 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
35 +import {
36 + backgroundActivityOverrideSettings,
37 + backgroundActivitySharedPolicySettings,
38 + durationToSeconds,
39 + normalizeIntervalSeconds,
40 + PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
41 + resolveBackgroundActivityProfileOption,
42 +} from "./SettingsPanels.logic";
43 +import { PolicyTooltip, SettingResetButton, SettingsRow } from "./settingsLayout";
44 +import { searchableSetting } from "./settingsSearch";
45 +
46 +const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, string> = {
47 + balanced: "Balanced",
48 + performance: "Performance",
49 + "battery-saver": "Battery saver",
50 +};
51 +
52 +type BackgroundActivityProfileOption = BackgroundActivityProfile | "advanced";
53 +
54 +const BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption, string> = {
55 + ...BACKGROUND_ACTIVITY_PROFILE_LABELS,
56 + advanced: "Advanced",
57 +};
58 +
59 +const BACKGROUND_ACTIVITY_PROFILE_DESCRIPTIONS: Record<BackgroundActivityProfile, string> = {
60 + balanced: "Pauses probes for idle clients, locked hosts, or low power mode.",
61 + performance: "Allows scoped background probes while any subscribed client remains connected.",
62 + "battery-saver": "Also pauses background probes when the host or client is on battery.",
63 +};
64 +
65 +const ADVANCED_BACKGROUND_ACTIVITY_DESCRIPTION = "Uses custom intervals.";
66 +
67 +const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
68 + readonly key:
69 + | "pauseWhenHostLocked"
70 + | "pauseWhenHostLowPower"
71 + | "pauseWhenClientLowPower"
72 + | "pauseWhenOnBattery";
73 + readonly label: string;
74 +}> = [
75 + { key: "pauseWhenHostLocked", label: "Pause when host is locked" },
76 + { key: "pauseWhenHostLowPower", label: "Pause on host low power" },
77 + { key: "pauseWhenClientLowPower", label: "Pause on client low power" },
78 + { key: "pauseWhenOnBattery", label: "Pause on battery" },
79 +];
80 +
81 +function resetBackgroundActivitySettings() {
82 + return {
83 + backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
84 + };
85 +}
86 +
87 +function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
88 + return {
89 + backgroundActivity: {
90 + schemaVersion: 1 as const,
91 + profile,
92 + overrides: {},
93 + },
94 + };
95 +}
96 +
97 +function BackgroundActivityAdvancedDialog({
98 + open,
99 + onOpenChange,
100 +}: {
101 + readonly open: boolean;
102 + readonly onOpenChange: (open: boolean) => void;
103 +}) {
104 + const canWriteSettings = useScopedSettingsWriteAllowed();
105 + const settings = useScopedSettings();
106 + const updateSettings = useUpdateScopedSettings();
107 + const resolvedBackgroundActivity = resolveServerBackgroundActivitySettings(settings);
108 + const activeProfile = resolvedBackgroundActivity.profile;
109 + const automaticGitFetchIntervalSeconds = durationToSeconds(
110 + resolvedBackgroundActivity.automaticGitFetchInterval,
111 + );
112 + const providerHealthRefreshIntervalSeconds = durationToSeconds(
113 + resolvedBackgroundActivity.providerHealthRefreshInterval,
114 + );
115 + const hostPowerMonitorActiveIntervalSeconds = durationToSeconds(
116 + resolvedBackgroundActivity.hostPowerMonitorActiveInterval,
117 + );
118 + const hostPowerMonitorIdleIntervalSeconds = durationToSeconds(
119 + resolvedBackgroundActivity.hostPowerMonitorIdleInterval,
120 + );
121 +
122 + return (
123 + <Dialog open={open && canWriteSettings} onOpenChange={onOpenChange}>
124 + <DialogPopup className="max-w-xl">
125 + <DialogHeader>
126 + <DialogTitle>Background Activity</DialogTitle>
127 + <DialogDescription>
128 + Tune the shared power policy and the background intervals that feed it.
129 + </DialogDescription>
130 + </DialogHeader>
131 + <DialogPanel>
132 + <fieldset
133 + disabled={!canWriteSettings}
134 + className="min-w-0 overflow-hidden rounded-xl border bg-card text-card-foreground"
135 + >
136 + <div className="flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
137 + <div className="min-w-0 space-y-1">
138 + <div className="text-sm font-medium">Shared policy</div>
139 + <p className="text-xs leading-relaxed text-muted-foreground">
140 + Controls whether background work may run after a subscribed interval fires.
141 + </p>
142 + </div>
143 + <Select
144 + value={activeProfile}
145 + onValueChange={(value) => {
146 + if (
147 + value === "balanced" ||
148 + value === "performance" ||
149 + value === "battery-saver"
150 + ) {
151 + updateSettings({
152 + backgroundActivity: backgroundActivitySharedPolicySettings(settings, value),
153 + });
154 + }
155 + }}
156 + >
157 + <SelectTrigger
158 + size="sm"
159 + className="w-full sm:w-40"
160 + aria-label="Shared background policy"
161 + >
162 + <SelectValue>{BACKGROUND_ACTIVITY_PROFILE_LABELS[activeProfile]}</SelectValue>
163 + </SelectTrigger>
164 + <SelectPopup align="end" alignItemWithTrigger={false}>
165 + <SelectItem hideIndicator value="balanced">
166 + {BACKGROUND_ACTIVITY_PROFILE_LABELS.balanced}
167 + </SelectItem>
168 + <SelectItem hideIndicator value="performance">
169 + {BACKGROUND_ACTIVITY_PROFILE_LABELS.performance}
170 + </SelectItem>
171 + <SelectItem hideIndicator value="battery-saver">
172 + {BACKGROUND_ACTIVITY_PROFILE_LABELS["battery-saver"]}
173 + </SelectItem>
174 + </SelectPopup>
175 + </Select>
176 + </div>
177 +
178 + <div className="flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
179 + <div className="min-w-0 space-y-1">
180 + <div className="text-sm font-medium">
181 + {searchableSetting("git-fetch-interval").title}
182 + </div>
183 + <p className="text-xs leading-relaxed text-muted-foreground">
184 + Refresh remote branch status in the background.
185 + </p>
186 + </div>
187 + <div className="flex shrink-0 items-center gap-2">
188 + <NumberField
189 + value={automaticGitFetchIntervalSeconds}
190 + min={0}
191 + step={5}
192 + size="sm"
193 + className="w-32"
194 + onValueChange={(value) =>
195 + updateSettings(
196 + backgroundActivityOverrideSettings(
197 + settings.backgroundActivity,
198 + resolvedBackgroundActivity,
199 + {
200 + automaticGitFetchInterval: Duration.seconds(
201 + normalizeIntervalSeconds(value),
202 + ),
203 + },
204 + ),
205 + )
206 + }
207 + >
208 + <NumberFieldGroup>
209 + <NumberFieldDecrement aria-label="Decrease Git fetch interval" />
210 + <NumberFieldInput aria-label="Git fetch interval in seconds" />
211 + <NumberFieldIncrement aria-label="Increase Git fetch interval" />
212 + </NumberFieldGroup>
213 + </NumberField>
214 + <span className="text-xs text-muted-foreground">seconds</span>
215 + </div>
216 + </div>
217 +
218 + <div className="flex flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
219 + <div className="min-w-0 space-y-1">
220 + <div className="text-sm font-medium">Provider health interval</div>
221 + <p className="text-xs leading-relaxed text-muted-foreground">
222 + Refresh provider availability, versions, and auth state. Model catalog updates
223 + follow Provider update checks.
224 + </p>
225 + </div>
226 + <div className="flex shrink-0 items-center gap-2">
227 + <NumberField
228 + value={providerHealthRefreshIntervalSeconds}
229 + min={0}
230 + step={PROVIDER_HEALTH_INTERVAL_STEP_SECONDS}
231 + size="sm"
232 + className="w-32"
233 + onValueChange={(value) =>
234 + updateSettings(
235 + backgroundActivityOverrideSettings(
236 + settings.backgroundActivity,
237 + resolvedBackgroundActivity,
238 + {
239 + providerHealthRefreshInterval: Duration.seconds(
240 + normalizeIntervalSeconds(value),
241 + ),
242 + },
243 + ),
244 + )
245 + }
246 + >
247 + <NumberFieldGroup>
248 + <NumberFieldDecrement aria-label="Decrease provider health interval" />
249 + <NumberFieldInput aria-label="Provider health interval in seconds" />
250 + <NumberFieldIncrement aria-label="Increase provider health interval" />
251 + </NumberFieldGroup>
252 + </NumberField>
253 + <span className="text-xs text-muted-foreground">seconds</span>
254 + </div>
255 + </div>
256 +
257 + <div className="flex flex-col gap-3 border-t px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
258 + <div className="min-w-0 space-y-1">
259 + <div className="text-sm font-medium">Host power monitor</div>
260 + <p className="text-xs leading-relaxed text-muted-foreground">
261 + Poll host power state while clients are active.
262 + </p>
263 + </div>
264 + <div className="flex shrink-0 items-center gap-2">
265 + <NumberField
266 + value={hostPowerMonitorActiveIntervalSeconds}
267 + min={5}
268 + step={5}
269 + size="sm"
270 + className="w-32"
271 + onValueChange={(value) =>
272 + updateSettings(
273 + backgroundActivityOverrideSettings(
274 + settings.backgroundActivity,
275 + resolvedBackgroundActivity,
276 + {
277 + hostPowerMonitorActiveInterval: Duration.seconds(
278 + normalizeIntervalSeconds(value, 5),
279 + ),
280 + },
281 + ),
282 + )
283 + }
284 + >
285 + <NumberFieldGroup>
286 + <NumberFieldDecrement aria-label="Decrease active host power interval" />
287 + <NumberFieldInput aria-label="Active host power interval in seconds" />
288 + <NumberFieldIncrement aria-label="Increase active host power interval" />
289 + </NumberFieldGroup>
290 + </NumberField>
291 + <span className="text-xs text-muted-foreground">seconds</span>
292 + </div>
293 + </div>
294 +
295 + <div className="flex flex-col gap-3 border-t px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
296 + <div className="min-w-0 space-y-1">
297 + <div className="text-sm font-medium">Idle host monitor</div>
298 + <p className="text-xs leading-relaxed text-muted-foreground">
299 + Poll host power state when no foreground client is active.
300 + </p>
301 + </div>
302 + <div className="flex shrink-0 items-center gap-2">
303 + <NumberField
304 + value={hostPowerMonitorIdleIntervalSeconds}
305 + min={5}
306 + step={30}
307 + size="sm"
308 + className="w-32"
309 + onValueChange={(value) =>
310 + updateSettings(
311 + backgroundActivityOverrideSettings(
312 + settings.backgroundActivity,
313 + resolvedBackgroundActivity,
314 + {
315 + hostPowerMonitorIdleInterval: Duration.seconds(
316 + normalizeIntervalSeconds(value, 5),
317 + ),
318 + },
319 + ),
320 + )
321 + }
322 + >
323 + <NumberFieldGroup>
324 + <NumberFieldDecrement aria-label="Decrease idle host power interval" />
325 + <NumberFieldInput aria-label="Idle host power interval in seconds" />
326 + <NumberFieldIncrement aria-label="Increase idle host power interval" />
327 + </NumberFieldGroup>
328 + </NumberField>
329 + <span className="text-xs text-muted-foreground">seconds</span>
330 + </div>
331 + </div>
332 +
333 + <div className="grid gap-0 border-t sm:grid-cols-2">
334 + {BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES.map(({ key, label }) => (
335 + <label
336 + key={key}
337 + className="flex items-center justify-between gap-3 border-b px-4 py-3 last:border-b-0 sm:border-r sm:even:border-r-0"
338 + >
339 + <span className="text-sm font-medium">{label}</span>
340 + <Switch
341 + checked={resolvedBackgroundActivity[key]}
342 + onCheckedChange={(checked) =>
343 + updateSettings(
344 + backgroundActivityOverrideSettings(
345 + settings.backgroundActivity,
346 + resolvedBackgroundActivity,
347 + {
348 + [key]: Boolean(checked),
349 + },
350 + ),
351 + )
352 + }
353 + aria-label={label}
354 + />
355 + </label>
356 + ))}
357 + </div>
358 + </fieldset>
359 + </DialogPanel>
360 + <DialogFooter>
361 + <Button
362 + variant="outline"
363 + disabled={!canWriteSettings}
364 + onClick={() => updateSettings(resetBackgroundActivitySettings())}
365 + >
366 + Reset all
367 + </Button>
368 + <Button onClick={() => onOpenChange(false)}>Done</Button>
369 + </DialogFooter>
370 + </DialogPopup>
371 + </Dialog>
372 + );
373 +}
374 +
375 +export function BackgroundActivitySettingsRow() {
376 + const settings = useScopedSettings();
377 + const updateSettings = useUpdateScopedSettings();
378 + const { scope, environment } = useSettingsScope();
379 + const environmentId = environment?.environmentId ?? null;
380 + const isEnvironmentScope = scope.environmentIds.length === 1 && environmentId !== null;
381 + const [backgroundActivityDialogOpen, setBackgroundActivityDialogOpen] = useState(false);
382 + const mixedBackgroundActivity = useScopedSettingsMixed(["backgroundActivity"]);
383 + const resolvedBackgroundActivity = resolveServerBackgroundActivitySettings(settings);
384 + const activeBackgroundActivityProfile = resolvedBackgroundActivity.profile;
385 + const backgroundActivityProfileOption = resolveBackgroundActivityProfileOption(settings);
386 + const backgroundActivityDescription =
387 + backgroundActivityProfileOption === "advanced"
388 + ? `${ADVANCED_BACKGROUND_ACTIVITY_DESCRIPTION} Shared policy: ${
389 + BACKGROUND_ACTIVITY_PROFILE_LABELS[activeBackgroundActivityProfile]
390 + }.`
391 + : BACKGROUND_ACTIVITY_PROFILE_DESCRIPTIONS[resolvedBackgroundActivity.profile];
392 + const canResetBackgroundActivity = !Equal.equals(
393 + settings.backgroundActivity,
394 + DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
395 + );
396 +
397 + return (
398 + <SettingsRow
399 + serverScoped
400 + settingKeys={["backgroundActivity"]}
401 + id={searchableSetting("background-activity").id}
402 + title={
403 + <span className="inline-flex items-center gap-1.5">
404 + {searchableSetting("background-activity").title}
405 + <PolicyTooltip>
406 + This shared policy gates background work such as Git refreshes and provider health
407 + probes after their individual intervals elapse.
408 + </PolicyTooltip>
409 + </span>
410 + }
411 + description={backgroundActivityDescription}
412 + resetAction={
413 + canResetBackgroundActivity ? (
414 + <SettingResetButton
415 + label="background activity"
416 + onClick={() => updateSettings(resetBackgroundActivitySettings())}
417 + />
418 + ) : null
419 + }
420 + control={
421 + <>
422 + <Select
423 + value={mixedBackgroundActivity ? null : backgroundActivityProfileOption}
424 + onValueChange={(value) => {
425 + if (value === "advanced") {
426 + if (isEnvironmentScope) setBackgroundActivityDialogOpen(true);
427 + return;
428 + }
429 + if (value === "balanced" || value === "performance" || value === "battery-saver") {
430 + updateSettings(backgroundActivityProfileSettings(value));
431 + }
432 + }}
433 + >
434 + <SelectTrigger
435 + size="sm"
436 + className="w-full sm:w-40"
437 + aria-label="Background activity profile"
438 + >
439 + <SelectValue>
440 + {(value: BackgroundActivityProfileOption | null) =>
441 + value === null ? "Mixed" : BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS[value]
442 + }
443 + </SelectValue>
444 + </SelectTrigger>
445 + <SelectPopup align="end" alignItemWithTrigger={false}>
446 + <SelectItem hideIndicator value="balanced">
447 + {BACKGROUND_ACTIVITY_PROFILE_LABELS.balanced}
448 + </SelectItem>
449 + <SelectItem hideIndicator value="performance">
450 + {BACKGROUND_ACTIVITY_PROFILE_LABELS.performance}
451 + </SelectItem>
452 + <SelectItem hideIndicator value="battery-saver">
453 + {BACKGROUND_ACTIVITY_PROFILE_LABELS["battery-saver"]}
454 + </SelectItem>
455 + <SelectItem hideIndicator value="advanced" disabled={!isEnvironmentScope}>
456 + {isEnvironmentScope
457 + ? BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS.advanced
458 + : `${BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS.advanced} (one environment)`}
459 + </SelectItem>
460 + </SelectPopup>
461 + </Select>
462 + {backgroundActivityProfileOption === "advanced" && isEnvironmentScope ? (
463 + <Tooltip>
464 + <TooltipTrigger
465 + render={
466 + <Button
467 + size="icon-sm"
468 + variant="outline"
469 + aria-label="Configure advanced background activity"
470 + onClick={() => setBackgroundActivityDialogOpen(true)}
471 + >
472 + <SettingsIcon className="size-4" />
473 + </Button>
474 + }
475 + />
476 + <TooltipPopup side="top">Configure background activity</TooltipPopup>
477 + </Tooltip>
478 + ) : null}
479 + <BackgroundActivityAdvancedDialog
480 + open={backgroundActivityDialogOpen && isEnvironmentScope}
481 + onOpenChange={setBackgroundActivityDialogOpen}
482 + />
483 + </>
484 + }
485 + />
486 + );
487 +}
apps/web/src/components/settings/SettingsPanels.tsx
+3 -464
@@ -1,12 +1,10 @@
1 import { SettingsGroup } from "./SettingsGroup";
2 -import { useScopedSettingsWriteAllowed } from "./useScopedSettings";
2 import { NotificationSettings } from "./NotificationSettings";
3 import { PRIVACY_POLICY_URL } from "../../legalLinks";
5 -import { CheckIcon, ChevronRightIcon, SettingsIcon } from "lucide-react";
4 +import { CheckIcon, ChevronRightIcon } from "lucide-react";
5 import { Link, useNavigate } from "@tanstack/react-router";
6 import { useEffect, useRef, useState } from "react";
7 import {
9 - type BackgroundActivityProfile,
8 type DesktopUpdateChannel,
9 ProviderDriverKind,
10 type ProviderInstanceId,
@@ -21,9 +19,7 @@ import {
19 type QuitConfirmationMode,
20 SidebarProjectSortOrder,
21 } from "@t3tools/contracts/settings";
24 -import { resolveServerBackgroundActivitySettings } from "@t3tools/shared/backgroundActivitySettings";
22 import { createModelSelection } from "@t3tools/shared/model";
26 -import * as Duration from "effect/Duration";
23 import * as Equal from "effect/Equal";
24 import * as Schema from "effect/Schema";
25 import { APP_VERSION, HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
@@ -72,46 +68,23 @@ import { useEnvironmentProviders } from "../../state/environments";
68 import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
69 import { Button } from "../ui/button";
70 import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
75 -import {
76 - Dialog,
77 - DialogDescription,
78 - DialogFooter,
79 - DialogHeader,
80 - DialogPanel,
81 - DialogPopup,
82 - DialogTitle,
83 -} from "../ui/dialog";
71 import { DraftInput } from "../ui/draft-input";
72 import { Input } from "../ui/input";
86 -import {
87 - NumberField,
88 - NumberFieldDecrement,
89 - NumberFieldGroup,
90 - NumberFieldIncrement,
91 - NumberFieldInput,
92 -} from "../ui/number-field";
73 import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
74 import { Switch } from "../ui/switch";
75 import { ScopedSwitch } from "./ScopedSwitch";
76 import { stackedThreadToast, toastManager } from "../ui/toast";
77 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
78 import {
99 - backgroundActivityOverrideSettings,
100 - backgroundActivitySharedPolicySettings,
101 - durationToSeconds,
79 getChangedBrowserSettingLabels,
80 getChangedTypographySettingLabels,
104 - normalizeIntervalSeconds,
105 - PROVIDER_HEALTH_INTERVAL_STEP_SECONDS,
81 hasChangedBackgroundActivitySettings,
82 isProjectGroupingEnabled,
83 projectGroupingModeFromToggle,
84 readLastEnabledProjectGroupingMode,
85 rememberEnabledProjectGroupingMode,
111 - resolveBackgroundActivityProfileOption,
86 } from "./SettingsPanels.logic";
87 import {
114 - PolicyTooltip,
88 SETTINGS_PICKER_TRIGGER_CLASSNAME,
89 SettingResetButton,
90 SettingsPageContainer,
@@ -121,6 +94,7 @@ import {
94 useSettingsSearchTargetId,
95 } from "./settingsLayout";
96 import { searchableSetting } from "./settingsSearch";
97 +import { BackgroundActivitySettingsRow } from "./BackgroundActivitySettings";
98
99 const RESPONSE_STREAMING_MODE_LABELS: Record<ResponseStreamingMode, string> = {
100 turn: "Wait for the full response",
@@ -156,58 +130,7 @@ const QUIT_CONFIRMATION_MODE_LABELS: Record<QuitConfirmationMode, string> = {
130 "double-click": "Double press",
131 };
132
159 -const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record<BackgroundActivityProfile, string> = {
160 - balanced: "Balanced",
161 - performance: "Performance",
162 - "battery-saver": "Battery saver",
163 -};
164 -
165 -type BackgroundActivityProfileOption = BackgroundActivityProfile | "advanced";
166 -
167 -const BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record<BackgroundActivityProfileOption, string> = {
168 - ...BACKGROUND_ACTIVITY_PROFILE_LABELS,
169 - advanced: "Advanced",
170 -};
171 -
172 -const BACKGROUND_ACTIVITY_PROFILE_DESCRIPTIONS: Record<BackgroundActivityProfile, string> = {
173 - balanced: "Pauses probes for idle clients, locked hosts, or low power mode.",
174 - performance: "Allows scoped background probes while any subscribed client remains connected.",
175 - "battery-saver": "Also pauses background probes when the host or client is on battery.",
176 -};
177 -
178 -const ADVANCED_BACKGROUND_ACTIVITY_DESCRIPTION = "Uses custom intervals.";
179 -
133 const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
181 -const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{
182 - readonly key:
183 - | "pauseWhenHostLocked"
184 - | "pauseWhenHostLowPower"
185 - | "pauseWhenClientLowPower"
186 - | "pauseWhenOnBattery";
187 - readonly label: string;
188 -}> = [
189 - { key: "pauseWhenHostLocked", label: "Pause when host is locked" },
190 - { key: "pauseWhenHostLowPower", label: "Pause on host low power" },
191 - { key: "pauseWhenClientLowPower", label: "Pause on client low power" },
192 - { key: "pauseWhenOnBattery", label: "Pause on battery" },
193 -];
194 -
195 -function resetBackgroundActivitySettings() {
196 - return {
197 - backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
198 - };
199 -}
200 -
201 -function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) {
202 - return {
203 - backgroundActivity: {
204 - schemaVersion: 1 as const,
205 - profile,
206 - overrides: {},
207 - },
208 - };
209 -}
210 -
134 function AboutVersionTitle() {
135 return (
136 <span className="inline-flex items-baseline gap-2">
@@ -729,284 +652,6 @@ export function useSettingsRestore(onRestored?: () => void) {
652 };
653 }
654
732 -function BackgroundActivityAdvancedDialog({
733 - open,
734 - onOpenChange,
735 -}: {
736 - readonly open: boolean;
737 - readonly onOpenChange: (open: boolean) => void;
738 -}) {
739 - const canWriteSettings = useScopedSettingsWriteAllowed();
740 - const settings = useScopedSettings();
741 - const updateSettings = useUpdateScopedSettings();
742 - const resolvedBackgroundActivity = resolveServerBackgroundActivitySettings(settings);
743 - const activeProfile = resolvedBackgroundActivity.profile;
744 - const automaticGitFetchIntervalSeconds = durationToSeconds(
745 - resolvedBackgroundActivity.automaticGitFetchInterval,
746 - );
747 - const providerHealthRefreshIntervalSeconds = durationToSeconds(
748 - resolvedBackgroundActivity.providerHealthRefreshInterval,
749 - );
750 - const hostPowerMonitorActiveIntervalSeconds = durationToSeconds(
751 - resolvedBackgroundActivity.hostPowerMonitorActiveInterval,
752 - );
753 - const hostPowerMonitorIdleIntervalSeconds = durationToSeconds(
754 - resolvedBackgroundActivity.hostPowerMonitorIdleInterval,
755 - );
756 -
757 - return (
758 - <Dialog open={open && canWriteSettings} onOpenChange={onOpenChange}>
759 - <DialogPopup className="max-w-xl">
760 - <DialogHeader>
761 - <DialogTitle>Background Activity</DialogTitle>
762 - <DialogDescription>
763 - Tune the shared power policy and the background intervals that feed it.
764 - </DialogDescription>
765 - </DialogHeader>
766 - <DialogPanel>
767 - <fieldset
768 - disabled={!canWriteSettings}
769 - className="min-w-0 overflow-hidden rounded-xl border bg-card text-card-foreground"
770 - >
771 - <div className="flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
772 - <div className="min-w-0 space-y-1">
773 - <div className="text-sm font-medium">Shared policy</div>
774 - <p className="text-xs leading-relaxed text-muted-foreground">
775 - Controls whether background work may run after a subscribed interval fires.
776 - </p>
777 - </div>
778 - <Select
779 - value={activeProfile}
780 - onValueChange={(value) => {
781 - if (
782 - value === "balanced" ||
783 - value === "performance" ||
784 - value === "battery-saver"
785 - ) {
786 - updateSettings({
787 - backgroundActivity: backgroundActivitySharedPolicySettings(settings, value),
788 - });
789 - }
790 - }}
791 - >
792 - <SelectTrigger
793 - size="sm"
794 - className="w-full sm:w-40"
795 - aria-label="Shared background policy"
796 - >
797 - <SelectValue>{BACKGROUND_ACTIVITY_PROFILE_LABELS[activeProfile]}</SelectValue>
798 - </SelectTrigger>
799 - <SelectPopup align="end" alignItemWithTrigger={false}>
800 - <SelectItem hideIndicator value="balanced">
801 - {BACKGROUND_ACTIVITY_PROFILE_LABELS.balanced}
802 - </SelectItem>
803 - <SelectItem hideIndicator value="performance">
804 - {BACKGROUND_ACTIVITY_PROFILE_LABELS.performance}
805 - </SelectItem>
806 - <SelectItem hideIndicator value="battery-saver">
807 - {BACKGROUND_ACTIVITY_PROFILE_LABELS["battery-saver"]}
808 - </SelectItem>
809 - </SelectPopup>
810 - </Select>
811 - </div>
812 -
813 - <div className="flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
814 - <div className="min-w-0 space-y-1">
815 - <div className="text-sm font-medium">
816 - {searchableSetting("git-fetch-interval").title}
817 - </div>
818 - <p className="text-xs leading-relaxed text-muted-foreground">
819 - Refresh remote branch status in the background.
820 - </p>
821 - </div>
822 - <div className="flex shrink-0 items-center gap-2">
823 - <NumberField
824 - value={automaticGitFetchIntervalSeconds}
825 - min={0}
826 - step={5}
827 - size="sm"
828 - className="w-32"
829 - onValueChange={(value) =>
830 - updateSettings(
831 - backgroundActivityOverrideSettings(
832 - settings.backgroundActivity,
833 - resolvedBackgroundActivity,
834 - {
835 - automaticGitFetchInterval: Duration.seconds(
836 - normalizeIntervalSeconds(value),
837 - ),
838 - },
839 - ),
840 - )
841 - }
842 - >
843 - <NumberFieldGroup>
844 - <NumberFieldDecrement aria-label="Decrease Git fetch interval" />
845 - <NumberFieldInput aria-label="Git fetch interval in seconds" />
846 - <NumberFieldIncrement aria-label="Increase Git fetch interval" />
847 - </NumberFieldGroup>
848 - </NumberField>
849 - <span className="text-xs text-muted-foreground">seconds</span>
850 - </div>
851 - </div>
852 -
853 - <div className="flex flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
854 - <div className="min-w-0 space-y-1">
855 - <div className="text-sm font-medium">Provider health interval</div>
856 - <p className="text-xs leading-relaxed text-muted-foreground">
857 - Refresh provider availability, versions, and auth state. Model catalog updates
858 - follow Provider update checks.
859 - </p>
860 - </div>
861 - <div className="flex shrink-0 items-center gap-2">
862 - <NumberField
863 - value={providerHealthRefreshIntervalSeconds}
864 - min={0}
865 - step={PROVIDER_HEALTH_INTERVAL_STEP_SECONDS}
866 - size="sm"
867 - className="w-32"
868 - onValueChange={(value) =>
869 - updateSettings(
870 - backgroundActivityOverrideSettings(
871 - settings.backgroundActivity,
872 - resolvedBackgroundActivity,
873 - {
874 - providerHealthRefreshInterval: Duration.seconds(
875 - normalizeIntervalSeconds(value),
876 - ),
877 - },
878 - ),
879 - )
880 - }
881 - >
882 - <NumberFieldGroup>
883 - <NumberFieldDecrement aria-label="Decrease provider health interval" />
884 - <NumberFieldInput aria-label="Provider health interval in seconds" />
885 - <NumberFieldIncrement aria-label="Increase provider health interval" />
886 - </NumberFieldGroup>
887 - </NumberField>
888 - <span className="text-xs text-muted-foreground">seconds</span>
889 - </div>
890 - </div>
891 -
892 - <div className="flex flex-col gap-3 border-t px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
893 - <div className="min-w-0 space-y-1">
894 - <div className="text-sm font-medium">Host power monitor</div>
895 - <p className="text-xs leading-relaxed text-muted-foreground">
896 - Poll host power state while clients are active.
897 - </p>
898 - </div>
899 - <div className="flex shrink-0 items-center gap-2">
900 - <NumberField
901 - value={hostPowerMonitorActiveIntervalSeconds}
902 - min={5}
903 - step={5}
904 - size="sm"
905 - className="w-32"
906 - onValueChange={(value) =>
907 - updateSettings(
908 - backgroundActivityOverrideSettings(
909 - settings.backgroundActivity,
910 - resolvedBackgroundActivity,
911 - {
912 - hostPowerMonitorActiveInterval: Duration.seconds(
913 - normalizeIntervalSeconds(value, 5),
914 - ),
915 - },
916 - ),
917 - )
918 - }
919 - >
920 - <NumberFieldGroup>
921 - <NumberFieldDecrement aria-label="Decrease active host power interval" />
922 - <NumberFieldInput aria-label="Active host power interval in seconds" />
923 - <NumberFieldIncrement aria-label="Increase active host power interval" />
924 - </NumberFieldGroup>
925 - </NumberField>
926 - <span className="text-xs text-muted-foreground">seconds</span>
927 - </div>
928 - </div>
929 -
930 - <div className="flex flex-col gap-3 border-t px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
931 - <div className="min-w-0 space-y-1">
932 - <div className="text-sm font-medium">Idle host monitor</div>
933 - <p className="text-xs leading-relaxed text-muted-foreground">
934 - Poll host power state when no foreground client is active.
935 - </p>
936 - </div>
937 - <div className="flex shrink-0 items-center gap-2">
938 - <NumberField
939 - value={hostPowerMonitorIdleIntervalSeconds}
940 - min={5}
941 - step={30}
942 - size="sm"
943 - className="w-32"
944 - onValueChange={(value) =>
945 - updateSettings(
946 - backgroundActivityOverrideSettings(
947 - settings.backgroundActivity,
948 - resolvedBackgroundActivity,
949 - {
950 - hostPowerMonitorIdleInterval: Duration.seconds(
951 - normalizeIntervalSeconds(value, 5),
952 - ),
953 - },
954 - ),
955 - )
956 - }
957 - >
958 - <NumberFieldGroup>
959 - <NumberFieldDecrement aria-label="Decrease idle host power interval" />
960 - <NumberFieldInput aria-label="Idle host power interval in seconds" />
961 - <NumberFieldIncrement aria-label="Increase idle host power interval" />
962 - </NumberFieldGroup>
963 - </NumberField>
964 - <span className="text-xs text-muted-foreground">seconds</span>
965 - </div>
966 - </div>
967 -
968 - <div className="grid gap-0 border-t sm:grid-cols-2">
969 - {BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES.map(({ key, label }) => (
970 - <label
971 - key={key}
972 - className="flex items-center justify-between gap-3 border-b px-4 py-3 last:border-b-0 sm:border-r sm:even:border-r-0"
973 - >
974 - <span className="text-sm font-medium">{label}</span>
975 - <Switch
976 - checked={resolvedBackgroundActivity[key]}
977 - onCheckedChange={(checked) =>
978 - updateSettings(
979 - backgroundActivityOverrideSettings(
980 - settings.backgroundActivity,
981 - resolvedBackgroundActivity,
982 - {
983 - [key]: Boolean(checked),
984 - },
985 - ),
986 - )
987 - }
988 - aria-label={label}
989 - />
990 - </label>
991 - ))}
992 - </div>
993 - </fieldset>
994 - </DialogPanel>
995 - <DialogFooter>
996 - <Button
997 - variant="outline"
998 - disabled={!canWriteSettings}
999 - onClick={() => updateSettings(resetBackgroundActivitySettings())}
1000 - >
1001 - Reset all
1002 - </Button>
1003 - <Button onClick={() => onOpenChange(false)}>Done</Button>
1004 - </DialogFooter>
1005 - </DialogPopup>
1006 - </Dialog>
1007 - );
1008 -}
1009 -
655 const AUTO_SETTLE_DEFAULT_DAYS = DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ?? 3;
656
657 function AutoSettleDaysInput({
@@ -1143,7 +788,6 @@ export function GeneralSettingsPanel() {
788 const environmentId = environment?.environmentId ?? null;
789 const isEnvironmentScope = scope.environmentIds.length === 1 && environmentId !== null;
790 const hasServerTargets = connectedEnvironments.length > 0;
1146 - const [backgroundActivityDialogOpen, setBackgroundActivityDialogOpen] = useState(false);
791 const mixedResponseStreamingMode = useScopedSettingsMixed(["responseStreamingMode"]);
792 const lastEnabledProjectGroupingMode = useRef<SidebarProjectGroupingMode>(
793 readLastEnabledProjectGroupingMode(),
@@ -1206,22 +850,8 @@ export function GeneralSettingsPanel() {
850 settings,
851 textGenerationModelInstanceEntries,
852 );
1209 - const resolvedBackgroundActivity = resolveServerBackgroundActivitySettings(settings);
1210 - const activeBackgroundActivityProfile = resolvedBackgroundActivity.profile;
1211 - const backgroundActivityProfileOption = resolveBackgroundActivityProfileOption(settings);
1212 - const mixedBackgroundActivity = useScopedSettingsMixed(["backgroundActivity"]);
853 const mixedAddProjectBaseDirectory = useScopedSettingsMixed(["addProjectBaseDirectory"]);
854 const mixedTextGenerationModel = useScopedSettingsMixed(["textGenerationModelSelection"]);
1215 - const backgroundActivityDescription =
1216 - backgroundActivityProfileOption === "advanced"
1217 - ? `${ADVANCED_BACKGROUND_ACTIVITY_DESCRIPTION} Shared policy: ${
1218 - BACKGROUND_ACTIVITY_PROFILE_LABELS[activeBackgroundActivityProfile]
1219 - }.`
1220 - : BACKGROUND_ACTIVITY_PROFILE_DESCRIPTIONS[resolvedBackgroundActivity.profile];
1221 - const canResetBackgroundActivity = !Equal.equals(
1222 - settings.backgroundActivity,
1223 - DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
1224 - );
855
856 return (
857 <SettingsPageContainer>
@@ -1959,98 +1589,7 @@ export function GeneralSettingsPanel() {
1589 }
1590 />
1591
1962 - <SettingsRow
1963 - serverScoped
1964 - settingKeys={["backgroundActivity"]}
1965 - id={searchableSetting("background-activity").id}
1966 - title={
1967 - <span className="inline-flex items-center gap-1.5">
1968 - {searchableSetting("background-activity").title}
1969 - <PolicyTooltip>
1970 - This shared policy gates background work such as Git refreshes and provider health
1971 - probes after their individual intervals elapse.
1972 - </PolicyTooltip>
1973 - </span>
1974 - }
1975 - description={backgroundActivityDescription}
1976 - resetAction={
1977 - canResetBackgroundActivity ? (
1978 - <SettingResetButton
1979 - label="background activity"
1980 - onClick={() => updateSettings(resetBackgroundActivitySettings())}
1981 - />
1982 - ) : null
1983 - }
1984 - control={
1985 - <>
1986 - <Select
1987 - value={mixedBackgroundActivity ? null : backgroundActivityProfileOption}
1988 - onValueChange={(value) => {
1989 - if (value === "advanced") {
1990 - if (isEnvironmentScope) setBackgroundActivityDialogOpen(true);
1991 - return;
1992 - }
1993 - if (
1994 - value === "balanced" ||
1995 - value === "performance" ||
1996 - value === "battery-saver"
1997 - ) {
1998 - updateSettings(backgroundActivityProfileSettings(value));
1999 - }
2000 - }}
2001 - >
2002 - <SelectTrigger
2003 - size="sm"
2004 - className="w-full sm:w-40"
2005 - aria-label="Background activity profile"
2006 - >
2007 - <SelectValue>
2008 - {(value: BackgroundActivityProfileOption | null) =>
2009 - value === null ? "Mixed" : BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS[value]
2010 - }
2011 - </SelectValue>
2012 - </SelectTrigger>
2013 - <SelectPopup align="end" alignItemWithTrigger={false}>
2014 - <SelectItem hideIndicator value="balanced">
2015 - {BACKGROUND_ACTIVITY_PROFILE_LABELS.balanced}
2016 - </SelectItem>
2017 - <SelectItem hideIndicator value="performance">
2018 - {BACKGROUND_ACTIVITY_PROFILE_LABELS.performance}
2019 - </SelectItem>
2020 - <SelectItem hideIndicator value="battery-saver">
2021 - {BACKGROUND_ACTIVITY_PROFILE_LABELS["battery-saver"]}
2022 - </SelectItem>
2023 - <SelectItem hideIndicator value="advanced" disabled={!isEnvironmentScope}>
2024 - {isEnvironmentScope
2025 - ? BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS.advanced
2026 - : `${BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS.advanced} (one environment)`}
2027 - </SelectItem>
2028 - </SelectPopup>
2029 - </Select>
2030 - {backgroundActivityProfileOption === "advanced" && isEnvironmentScope ? (
2031 - <Tooltip>
2032 - <TooltipTrigger
2033 - render={
2034 - <Button
2035 - size="icon-sm"
2036 - variant="outline"
2037 - aria-label="Configure advanced background activity"
2038 - onClick={() => setBackgroundActivityDialogOpen(true)}
2039 - >
2040 - <SettingsIcon className="size-4" />
2041 - </Button>
2042 - }
2043 - />
2044 - <TooltipPopup side="top">Configure background activity</TooltipPopup>
2045 - </Tooltip>
2046 - ) : null}
2047 - <BackgroundActivityAdvancedDialog
2048 - open={backgroundActivityDialogOpen && isEnvironmentScope}
2049 - onOpenChange={setBackgroundActivityDialogOpen}
2050 - />
2051 - </>
2052 - }
2053 - />
1592 + <BackgroundActivitySettingsRow />
1593 </SettingsSection>
1594
1595 <SettingsSection id="projects-and-threads" title="Projects & threads">