TypeScript
fix(web): settings stay compact with many connected machines (#19744)
maria6d73370ef1c5
diff --git a/apps/web/src/components/settings/DeviceHostEditor.tsx b/apps/web/src/components/settings/DeviceHostEditor.tsxindex 263ee1779ea..a93699752cb 100644--- a/apps/web/src/components/settings/DeviceHostEditor.tsx+++ b/apps/web/src/components/settings/DeviceHostEditor.tsx@@ -1,8 +1,9 @@import { useState } from "react";import * as Option from "effect/Option";import type { SshDeviceHostConfig } from "@t3tools/contracts";-import { CheckIcon, MonitorIcon, XIcon } from "lucide-react";-import { Button } from "../ui/button";+import { CheckIcon, ChevronDownIcon, MonitorIcon, XIcon } from "lucide-react";+import { Button, InlineButton } from "../ui/button";+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";import { Input } from "../ui/input";import { Spinner } from "../ui/spinner";import {@@ -38,12 +39,24 @@ export function DeviceHostEditor({onClose: () => void;}) {const [draft, setDraft] = useState(host);+ const [expandedChecks, setExpandedChecks] = useState<{ key: string; open: boolean } | null>(null);const { checks, testConnection } = useHostConnectionChecks(targets);- const results = checks[deviceHostConnectionKey(draft)];+ const connectionKey = deviceHostConnectionKey(draft);+ const results = checks[connectionKey];const checking = Object.values(results ?? {}).some((check) => check.status === "pending");const input = parseDeviceHostDraft({ ...draft, label: draft.label.trim() || draft.target });const valid = Option.isSome(input);const failed = Object.values(results ?? {}).filter((check) => check.status === "failed").length;+ const checksOpen =+ targets.length === 1 ||+ (expandedChecks?.key === connectionKey ? expandedChecks.open : failed > 0);+ const checkSummary = checking+ ? "Checking environments…"+ : results+ ? failed+ ? `${failed} of ${targets.length} failed`+ : "Connection checks passed"+ : "Check access before saving";return (<Dialogopen@@ -136,17 +149,34 @@ export function DeviceHostEditor({Optional. Resolved separately on each environment.</p></details>- <div className="rounded-lg border border-border/60">+ <Collapsible+ open={checksOpen}+ onOpenChange={(open) => setExpandedChecks({ key: connectionKey, open })}+ render={<div className="rounded-lg border border-border/60" />}+ ><div className="flex items-center justify-between gap-3 px-3 py-2.5">- <p role="status" className="text-xs text-muted-foreground">- {checking- ? "Checking environments…"- : results- ? failed- ? `${failed} of ${targets.length} failed`- : "Connection checks passed"- : "Check access before saving"}- </p>+ {targets.length === 1 ? (+ <p role="status" className="text-xs text-muted-foreground">+ {checkSummary}+ </p>+ ) : (+ <div className="min-w-0 text-xs [--inline-button-white-space:normal]">+ <CollapsibleTrigger+ disabled={!results}+ aria-label={`${checkSummary}. Per-machine results`}+ render={<InlineButton tone="muted" />}+ >+ <span role="status" className="text-left">+ {checkSummary}+ </span>+ {results ? (+ <ChevronDownIcon+ className={`size-3 shrink-0 ${checksOpen ? "rotate-180" : ""}`}+ />+ ) : null}+ </CollapsibleTrigger>+ </div>+ )}<Buttontype="button"size="sm"@@ -160,7 +190,9 @@ export function DeviceHostEditor({</Button></div>{results ? (- <ul className="border-t border-border/60 divide-y divide-border/40">+ <CollapsiblePanel+ render={<ul className="border-t border-border/60 divide-y divide-border/40" />}+ >{targets.map((target) => {const result = results[target.environmentId];if (!result) return null;@@ -206,9 +238,9 @@ export function DeviceHostEditor({</li>);})}- </ul>+ </CollapsiblePanel>) : null}- </div>+ </Collapsible></DialogPanel><DialogFooter><Button type="button" variant="ghost" disabled={busy} onClick={onClose}>diff --git a/apps/web/src/components/settings/DeviceHostsSettings.tsx b/apps/web/src/components/settings/DeviceHostsSettings.tsxindex 781f549f5d3..e6fd979a601 100644--- a/apps/web/src/components/settings/DeviceHostsSettings.tsx+++ b/apps/web/src/components/settings/DeviceHostsSettings.tsx@@ -1,4 +1,8 @@import { DeviceToolVersions } from "../device/DeviceToolVersions";+import { DeviceHostAvailability } from "../device/DeviceHostAvailability";+import { useAtomValue } from "@effect/atom-react";+import * as Option from "effect/Option";+import { AsyncResult, Atom } from "effect/reactivity";import { AuthSettingsWriteScope } from "@t3tools/contracts";import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";@@ -6,21 +10,36 @@ import { AppleIcon, AndroidIcon } from "../Icons";import { Spinner } from "../ui/spinner";import type { EnvironmentId, SshDeviceHostConfig } from "@t3tools/contracts";import { randomUUID } from "../../lib/utils";-import { useState } from "react";-import { deviceEnvironment, useDeviceState } from "../../state/device";+import { useMemo, useState } from "react";+import { deviceEnvironment } from "../../state/device";import { serverEnvironment } from "../../state/server";import { useAtomCommand } from "../../state/use-atom-command";-import { Button } from "../ui/button";-import { MoreVertical, PlusIcon } from "lucide-react";+import { Button, InlineButton } from "../ui/button";+import {+ CheckIcon,+ ChevronDownIcon,+ CircleIcon,+ MoreVertical,+ PlusIcon,+ TriangleAlertIcon,+} from "lucide-react";+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";import { Menu, MenuTrigger, MenuPopup, MenuItem } from "../ui/menu";import { SettingsRow } from "./settingsLayout";import { useSettingsScope } from "./SettingsScopeContext";import { toastManager } from "../ui/toast";-import { updateDeviceHosts } from "./deviceHostsSettings.logic";+import {+ groupDeviceHosts,+ updateDeviceHosts,+ type DeviceHostEnvironment,+ type DeviceHostGroup,+} from "./deviceHostsSettings.logic";+import { FoldedSettingsSection } from "./FoldedSettingsSection";import { DeviceHostEditor } from "./DeviceHostEditor";import { useHostConnectionChecks } from "./useHostConnectionChecks";import { deviceHostConnectionKey } from "./deviceHostConnectionChecks";+import { settingsScopeEnvironmentLabel, settingsScopeEnvironmentLabels } from "./settingsScopeAxis";export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null }) {const { scope, environments, connectedEnvironments } = useSettingsScope();@@ -32,10 +51,21 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | nullconst [busy, setBusy] = useState(false);const targets = environments.map((environment) => ({environmentId: environment.environmentId,- label: environment.label,+ label: settingsScopeEnvironmentLabel(environment, environments),connected: environment.connection.phase === "connected",}));const { checks, testConnection } = useHostConnectionChecks(targets);+ const hostEnvironments = useMemo(+ () =>+ connectedEnvironments.map((environment) => ({+ environmentId: environment.environmentId,+ label: environment.label,+ labels: settingsScopeEnvironmentLabels(environment, connectedEnvironments),+ hosts: environment.serverConfig?.settings.deviceHosts ?? [],+ })),+ [connectedEnvironments],+ );+ const groupedHosts = useMemo(() => groupDeviceHosts(hostEnvironments), [hostEnvironments]);const save = async (host: SshDeviceHostConfig, remove = false, original = host) => {if (!props.environmentId || projectScope) return;setBusy(true);@@ -80,6 +110,30 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | nullsetBusy(false);}};+ const listActions = {+ busy: !canConfigure || projectScope || busy,+ checks,+ testConnection: async (host: SshDeviceHostConfig) => {+ const results = await testConnection(host);+ if (!results) return;+ const failed = targets.filter((target) => results[target.environmentId]?.status === "failed");+ toastManager.add({+ type: failed.length ? "error" : "success",+ title: failed.length+ ? `${host.label}: ${failed.length} of ${targets.length} environments failed`+ : `${host.label}: connection checks passed`,+ description: failed.length+ ? `Could not connect from ${failed.map((target) => target.label).join(", ")}.`+ : "Connected or already available locally on each selected environment.",+ });+ return results;+ },+ onEdit: (host: SshDeviceHostConfig) => {+ setOriginalHost(host);+ setEditing(host);+ },+ onRemove: (host: SshDeviceHostConfig) => void save(host, true),+ };return (<SettingsRowid="device-hosts"@@ -110,44 +164,43 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null</p>) : (<>- {connectedEnvironments.map((environment) => (- <div key={environment.environmentId}>- {connectedEnvironments.length > 1 ? (- <p className="pt-3 pb-1 text-xs font-medium text-muted-foreground">- {environment.label}- </p>- ) : null}- <DeviceHostList- environmentLabel={environment.label}- environmentId={environment.environmentId}- hosts={environment.serverConfig?.settings.deviceHosts ?? []}- busy={!canConfigure || projectScope || busy}- checks={checks}- testConnection={async (host) => {- const results = await testConnection(host);- if (!results) return;- const failed = targets.filter(- (target) => results[target.environmentId]?.status === "failed",- );- toastManager.add({- type: failed.length ? "error" : "success",- title: failed.length- ? `${host.label}: ${failed.length} of ${targets.length} environments failed`- : `${host.label}: connection checks passed`,- description: failed.length- ? `Could not connect from ${failed.map((target) => target.label).join(", ")}.`- : "Connected or already available locally on each selected environment.",- });- return results;- }}- onEdit={(host) => {- setOriginalHost(host);- setEditing(host);- }}- onRemove={(host) => void save(host, true)}- />+ {hostEnvironments.length > 1 && groupedHosts === null ? (+ <div className="space-y-2">+ {hostEnvironments.map((environment) => (+ <FoldedSettingsSection+ key={environment.environmentId}+ id={`device-hosts-${environment.environmentId}`}+ title={+ <>+ <span className="block max-w-64 truncate">+ {environment.labels.primary}+ </span>+ {environment.labels.secondary ? (+ <span className="block max-w-64 truncate text-xs font-normal text-muted-foreground">+ {environment.labels.secondary}+ </span>+ ) : null}+ </>+ }+ summary={+ summarizeLabels(environment.hosts.map((host) => host.label)) ||+ "No device hosts"+ }+ >+ <div className="px-3 sm:px-4 [&>div:first-child]:border-t-0">+ <DeviceHostList environments={[environment]} {...listActions} />+ </div>+ </FoldedSettingsSection>+ ))}</div>- ))}+ ) : (+ <DeviceHostList+ environments={hostEnvironments}+ groups={groupedHosts ?? undefined}+ compact={hostEnvironments.length > 1}+ {...listActions}+ />+ )}{editing ? (<DeviceHostEditorkey={editing.id}@@ -167,39 +220,112 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null}function DeviceHostList({- environmentLabel,- environmentId,- hosts,+ environments,+ groups,+ compact = false,busy,onEdit,onRemove,checks,testConnection,}: {- environmentLabel: string;- environmentId: EnvironmentId;- hosts: ReadonlyArray<SshDeviceHostConfig>;+ environments: ReadonlyArray<DeviceHostEnvironment>;+ groups?: ReadonlyArray<DeviceHostGroup> | undefined;+ compact?: boolean;busy: boolean;onEdit: (host: SshDeviceHostConfig) => void;onRemove: (host: SshDeviceHostConfig) => void;checks: ReturnType<typeof useHostConnectionChecks>["checks"];testConnection: ReturnType<typeof useHostConnectionChecks>["testConnection"];}) {- const { state } = useDeviceState(environmentId);+ const { environments: scopeEnvironments } = useSettingsScope();+ const environmentLabels = new Map(+ scopeEnvironments.map((environment) => [+ environment.environmentId,+ settingsScopeEnvironmentLabels(environment, scopeEnvironments),+ ]),+ );+ const states = useAtomValue(+ useMemo(+ () =>+ Atom.make(+ (get) =>+ new Map(+ environments.map(({ environmentId }) => {+ const result = get(deviceEnvironment.state({ environmentId, input: {} }));+ return [environmentId, Option.getOrUndefined(AsyncResult.value(result))] as const;+ }),+ ),+ ),+ [environments],+ ),+ );const retry = useAtomCommand(deviceEnvironment.list);const [retrying, setRetrying] = useState<string | null>(null);+ const retryHost = (environmentId: EnvironmentId, hostId: string, key = hostId) => {+ setRetrying(key);+ void retry({ environmentId, input: { retryHostId: hostId } }).finally(() => setRetrying(null));+ };+ const rows =+ groups ??+ environments.flatMap((environment) =>+ environment.hosts.map((host) => ({+ host,+ members: [{ environmentId: environment.environmentId, label: environment.label, host }],+ })),+ );return (<>- {hosts.length === 0 ? (+ {rows.length === 0 ? (<p className="py-2 text-sm text-muted-foreground">No device hosts.</p>) : null}- {hosts.map((host) => {- const status = state.hostStatuses[host.id];- const check = checks[deviceHostConnectionKey(host)]?.[environmentId];+ {rows.map(({ host, members }) => {+ const hostChecks = checks[deviceHostConnectionKey(host)];+ const checkedMembers = scopeEnvironments.flatMap((environment) =>+ hostChecks?.[environment.environmentId] &&+ !members.some((member) => member.environmentId === environment.environmentId)+ ? [{ environmentId: environment.environmentId, label: environment.label, host }]+ : [],+ );+ const results = [...members, ...checkedMembers].map((member) => {+ const state = states.get(member.environmentId);+ const status = state?.hostStatuses[member.host.id];+ const check = hostChecks?.[member.environmentId];+ const summary = state?.hosts.find((value) => value.id === member.host.id);+ const label = environmentLabels.get(member.environmentId)?.primary ?? member.label;+ const address = environmentLabels.get(member.environmentId)?.secondary;+ const error =+ check?.status === "failed"+ ? check.error+ : check?.status === "local"+ ? undefined+ : status?.status === "failed"+ ? status.detail+ : undefined;+ return {+ ...member,+ label,+ address,+ name: [label, address].filter(Boolean).join(" · "),+ state,+ status,+ check,+ summary,+ error,+ versions: (+ <DeviceToolVersions+ owner={label}+ error={summary?.toolInspectionError}+ tools={summary?.tools ?? (check?.status === "connected" ? check.tools : undefined)}+ />+ ),+ };+ });+ const first = results[0];+ if (!first) return null;+ const { environmentId, status, check, summary, error } = first;const platforms =- (check?.status === "connected" ? check.platforms : undefined) ??- state.hosts.find((value) => value.id === host.id)?.platforms ??- [];+ (check?.status === "connected" ? check.platforms : undefined) ?? summary?.platforms ?? [];const progress =check?.status === "pending"? "Checking connection…"@@ -208,61 +334,166 @@ function DeviceHostList({: status?.status === "starting"? "Connecting…": null;- const error =- check?.status === "failed"- ? check.error- : check?.status === "local"- ? undefined- : status?.status === "failed"- ? status.detail- : undefined;+ const failed = results.filter(+ (result) =>+ result.check?.status === "failed" ||+ (result.check?.status !== "local" && result.status?.status === "failed"),+ );+ const pending = results.some(+ (result) =>+ result.check?.status === "pending" ||+ result.status?.status === "installing" ||+ result.status?.status === "starting",+ );+ const ready = results.every(+ (result) =>+ result.check?.status === "connected" ||+ result.check?.status === "local" ||+ result.status?.status === "ready",+ );+ const retryable = results.filter(+ (result) =>+ result.status?.status === "failed" &&+ result.state?.supportsHostRetry &&+ result.state.hostStatus !== "disabled",+ );+ const canRetry = !compact && retryable.includes(first);+ const indicators = compact+ ? [+ {+ key: "connection",+ label: failed.length+ ? "Connection failed"+ : pending+ ? "Checking connections"+ : ready+ ? "Connected"+ : "Connection not checked",+ warning: failed.length > 0,+ icon: failed.length ? (+ <TriangleAlertIcon className="size-3.5" />+ ) : pending ? (+ <Spinner size="xs" />+ ) : ready ? (+ <CheckIcon className="size-3.5" />+ ) : (+ <CircleIcon className="size-3.5" />+ ),+ detail: failed.length ? (+ <div className="space-y-1">+ {failed.map((result) => (+ <p key={result.environmentId}>+ {result.name}: {result.error || "Connection failed"}+ </p>+ ))}+ </div>+ ) : pending ? (+ "Checking connections…"+ ) : ready ? (+ "Connected or available locally on each listed machine"+ ) : (+ "Test the connection to check access from each machine"+ ),+ },+ ]+ : platforms+ .filter((platform) => platform.available)+ .map((platform) => ({+ key: platform.platform,+ label: platform.platform === "ios" ? "iOS available" : "Android available",+ warning: false,+ icon:+ platform.platform === "ios" ? (+ // The Apple mark is bottom-heavy; lift it so it does not dip under the label.+ <AppleIcon className="size-3.5 -translate-y-px" />+ ) : (+ <AndroidIcon className="size-3.5" />+ ),+ }));return (<div key={host.id} className="flex items-center gap-2 border-t border-border/50 py-2.5"><div className="min-w-0 flex-1"><div className="flex min-w-0 items-center gap-2"><p className="truncate text-sm font-medium">{host.label}</p>- {platforms- .filter((platform) => platform.available)- .map((platform) => (- <Tooltip key={platform.platform}>- <TooltipTrigger- render={- <span- tabIndex={0}- role="img"- aria-label={- platform.platform === "ios" ? "iOS available" : "Android available"- }- className="shrink-0 text-muted-foreground"- />- }- >- {platform.platform === "ios" ? (- // The Apple mark is bottom-heavy; lift it so it does not dip under the label.- <AppleIcon className="size-3.5 -translate-y-px" />- ) : (- <AndroidIcon className="size-3.5" />- )}- </TooltipTrigger>- <TooltipPopup>- {platform.platform === "ios" ? "iOS available" : "Android available"}- </TooltipPopup>- </Tooltip>- ))}+ {indicators.map((indicator) => (+ <Tooltip key={indicator.key}>+ <TooltipTrigger+ render={+ <span+ tabIndex={0}+ role="img"+ aria-label={indicator.label}+ className={+ indicator.warning+ ? "shrink-0 text-warning"+ : "shrink-0 text-muted-foreground"+ }+ />+ }+ >+ {indicator.icon}+ </TooltipTrigger>+ <TooltipPopup>+ {"detail" in indicator ? indicator.detail : indicator.label}+ </TooltipPopup>+ </Tooltip>+ ))}</div><p className="truncate text-xs text-muted-foreground">{host.target}</p>- <DeviceToolVersions- owner={environmentLabel}- error={state.hosts.find((value) => value.id === host.id)?.toolInspectionError}- tools={- state.hosts.find((value) => value.id === host.id)?.tools ??- (check?.status === "connected" ? check.tools : undefined)- }- />- {check?.status === "local" ? (+ {compact ? (+ <Collapsible>+ <div className="min-w-0 text-xs [--inline-button-white-space:normal]">+ <CollapsibleTrigger+ aria-label={`${host.label} machine details`}+ render={<InlineButton tone="muted" />}+ >+ <span className="line-clamp-1 break-all text-left">+ {summarizeLabels(results.map((result) => result.name))}+ </span>+ <ChevronDownIcon className="size-3 shrink-0" />+ </CollapsibleTrigger>+ </div>+ <CollapsiblePanel>+ <div className="mt-2 space-y-2">+ {results.map((result) => (+ <div key={result.environmentId}>+ <p className="text-xs text-muted-foreground">{result.label}</p>+ {result.address ? (+ <p className="truncate text-xs text-muted-foreground">+ {result.address}+ </p>+ ) : null}+ {result.error ? (+ <p role="status" className="text-xs text-destructive">+ {result.error}+ </p>+ ) : null}+ {result.versions}+ {result.check?.status === "local" ? (+ <p className="text-xs text-muted-foreground">+ Already available locally+ </p>+ ) : (+ <DeviceHostAvailability+ platforms={+ (result.check?.status === "connected"+ ? result.check.platforms+ : result.summary?.platforms) ?? []+ }+ />+ )}+ </div>+ ))}+ </div>+ </CollapsiblePanel>+ </Collapsible>+ ) : (+ first.versions+ )}+ {!compact && check?.status === "local" ? (<p className="mt-1 text-xs text-muted-foreground">Already available locally</p>) : null}- {error ? (+ {!compact && error ? (<div className="mt-1" role="status"><details className="text-xs text-destructive"><summary>Connection failed</summary>@@ -271,7 +502,7 @@ function DeviceHostList({</div>) : null}</div>- {progress ? (+ {!compact && progress ? (<spanrole="status"className="inline-flex items-center gap-1.5 text-xs text-muted-foreground"@@ -294,47 +525,47 @@ function DeviceHostList({<MoreVertical /></MenuTrigger><MenuPopup align="end">- <MenuItem- onClick={() => {- onEdit(host);- }}- >- Edit- </MenuItem>+ <MenuItem onClick={() => onEdit(host)}>Edit</MenuItem><MenuItem variant="destructive" onClick={() => onRemove(host)}>Remove</MenuItem>+ {compact+ ? retryable.map((result) => (+ <MenuItem+ key={result.environmentId}+ disabled={retrying !== null}+ onClick={() =>+ retryHost(result.environmentId, result.host.id, result.environmentId)+ }+ >+ {retrying === result.environmentId ? "Retrying" : "Retry"} from{" "}+ {result.label}+ {result.address ? ` (${result.address})` : null}+ </MenuItem>+ ))+ : null}</MenuPopup></Menu>- {status?.status === "failed" &&- state.supportsHostRetry &&- state.hostStatus !== "disabled" ? (- <Button- size="sm"- variant="outline"- disabled={busy || retrying !== null}- onClick={() => {- setRetrying(host.id);- void retry({ environmentId, input: { retryHostId: host.id } }).finally(() =>- setRetrying(null),- );- }}- >- {retrying === host.id ? "Retrying…" : "Retry"}- </Button>- ) : (- <Button- size="sm"- variant="outline"- disabled={busy || progress !== null}- onClick={() => void testConnection(host)}- >- Test connection- </Button>- )}+ <Button+ size="sm"+ variant="outline"+ disabled={+ busy || (canRetry ? retrying !== null : compact ? pending : progress !== null)+ }+ onClick={() => {+ if (canRetry) retryHost(environmentId, host.id);+ else void testConnection(host);+ }}+ >+ {canRetry ? (retrying === host.id ? "Retrying…" : "Retry") : "Test connection"}+ </Button></div>);})}</>);}++function summarizeLabels(labels: ReadonlyArray<string>) {+ return `${labels.slice(0, 2).join(", ")}${labels.length > 2 ? ` +${labels.length - 2}` : ""}`;+}diff --git a/apps/web/src/components/settings/FoldedSettingsSection.tsx b/apps/web/src/components/settings/FoldedSettingsSection.tsxindex cf4e91fcf53..588a6e83119 100644--- a/apps/web/src/components/settings/FoldedSettingsSection.tsx+++ b/apps/web/src/components/settings/FoldedSettingsSection.tsx@@ -20,7 +20,7 @@ export function FoldedSettingsSection({children,}: {readonly id: string;- readonly title: string;+ readonly title: ReactNode;readonly summary?: string | null;readonly control?: ReactNode;readonly headerPlacement?: "inside" | "outside";diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.tsxindex 2ad856e1671..fefe064a914 100644--- a/apps/web/src/components/settings/ProjectSettingsPanel.tsx+++ b/apps/web/src/components/settings/ProjectSettingsPanel.tsx@@ -32,6 +32,7 @@ import { Alert, AlertDescription } from "../ui/alert";import { Button } from "../ui/button";import { Input } from "../ui/input";import { stackedThreadToast, toastManager } from "../ui/toast";+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";import {SettingResetButton,SettingsPageContainer,@@ -46,6 +47,7 @@ import { ProjectActionsSettings } from "./ProjectActionsSettings";import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";import { projectGroupTitleNeedsUpdate } from "./ProjectSettingsPanel.logic";import { useSettingsProjectGroups } from "./useSettingsProjectGroups";+import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";const ProjectIconPickerDialog = lazy(() =>import("./ProjectIconPickerDialog").then((module) => ({@@ -423,26 +425,88 @@ function ProjectDetail({],);+ const checkoutsByEnvironment = new Map<EnvironmentId, SidebarProjectGroupMember[]>();+ for (const member of group.memberProjects) {+ const members = checkoutsByEnvironment.get(member.environmentId);+ if (members) members.push(member);+ else checkoutsByEnvironment.set(member.environmentId, [member]);+ }+ const checkoutRemoveButton = (member: SidebarProjectGroupMember) => (+ <Button+ size="sm"+ variant="outline"+ disabled={!editableIds.has(member.environmentId)}+ onClick={() => void removeMembers([member])}+ aria-label={`Remove checkout ${member.workspaceRoot}`}+ >+ Remove+ </Button>+ );const checkoutChoices = (<SettingsSection title="Checkouts">- {group.memberProjects.map((member) => (- <SettingsRow- key={member.physicalProjectKey}- title={member.environmentLabel ?? "Environment"}- description={member.workspaceRoot}- control={- <Button- size="sm"- variant="outline"- disabled={!editableIds.has(member.environmentId)}- onClick={() => void removeMembers([member])}- aria-label={`Remove checkout ${member.workspaceRoot}`}- >- Remove- </Button>- }- />- ))}+ {Array.from(checkoutsByEnvironment, ([environmentId, members]) => {+ if (checkoutsByEnvironment.size === 1) {+ return members.map((member) => (+ <SettingsRow+ key={member.physicalProjectKey}+ title={member.environmentLabel ?? "Environment"}+ description={member.workspaceRoot}+ control={checkoutRemoveButton(member)}+ />+ ));+ }+ const firstMember = members[0]!;+ const hasMultiple = members.length > 1;+ const environment = environmentById.get(environmentId);+ const labels = environment+ ? settingsScopeEnvironmentLabels(environment, environments)+ : { primary: firstMember.environmentLabel ?? "Environment", secondary: environmentId };+ return (+ <SettingsRow+ key={environmentId}+ title={labels.primary}+ description={+ <>+ {labels.secondary ? (+ <span className="block truncate">{labels.secondary}</span>+ ) : null}+ {!hasMultiple ? (+ <Tooltip>+ <TooltipTrigger render={<span className="block truncate" />}>+ {firstMember.workspaceRoot}+ </TooltipTrigger>+ <TooltipPopup>{firstMember.workspaceRoot}</TooltipPopup>+ </Tooltip>+ ) : null}+ </>+ }+ control={hasMultiple ? undefined : checkoutRemoveButton(firstMember)}+ >+ {hasMultiple ? (+ <div className="space-y-3 pb-2 pt-1">+ {members.map((member) => (+ <div+ key={member.physicalProjectKey}+ className="flex min-w-0 items-center justify-between gap-3"+ >+ <Tooltip>+ <TooltipTrigger+ render={+ <span className="min-w-0 truncate text-xs text-muted-foreground/80" />+ }+ >+ {member.workspaceRoot}+ </TooltipTrigger>+ <TooltipPopup>{member.workspaceRoot}</TooltipPopup>+ </Tooltip>+ <div className="shrink-0">{checkoutRemoveButton(member)}</div>+ </div>+ ))}+ </div>+ ) : null}+ </SettingsRow>+ );+ })}</SettingsSection>);diff --git a/apps/web/src/components/settings/ScheduledTasksSettings.tsx b/apps/web/src/components/settings/ScheduledTasksSettings.tsxindex 4864759934e..268d8ecb155 100644--- a/apps/web/src/components/settings/ScheduledTasksSettings.tsx+++ b/apps/web/src/components/settings/ScheduledTasksSettings.tsx@@ -1,4 +1,7 @@import { useAtomValue } from "@effect/atom-react";+import { connectionStatusTitle } from "@t3tools/client-runtime/connection";+import * as Option from "effect/Option";+import { AsyncResult, Atom } from "effect/reactivity";import {Clock3Icon,CopyIcon,@@ -54,14 +57,18 @@ import {type EnvironmentPresentation,} from "../../state/environments";import { useProjects } from "../../state/entities";-import { useEnvironmentQuery } from "../../state/query";+import { formatEnvironmentQueryError, useEnvironmentQuery } from "../../state/query";import { EMPTY_SERVER_PROVIDERS, serverEnvironment } from "../../state/server";import { useAtomCommand } from "../../state/use-atom-command";import { WorktreeBaseBranchPicker } from "../WorktreeBaseBranchPicker";import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";+import { ConnectionStatusDot, connectionPhaseDotClassName } from "../ConnectionStatusDot";import { AuthOrchestrationOperateScope } from "@t3tools/contracts";import { readEnvironmentScope } from "~/state/session";import { useSettingsScope } from "./SettingsScopeContext";+import { EnvironmentRow, environmentTransportLabel } from "./EnvironmentRow";+import { SettingsGroup } from "./SettingsGroup";+import { settingsScopeEnvironmentLabel, settingsScopeEnvironmentLabels } from "./settingsScopeAxis";import {WEBHOOK_SIGNATURE_DEFAULTS,matchesScheduledTaskScope,@@ -94,6 +101,7 @@ import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../import { Switch } from "../ui/switch";import { Textarea } from "../ui/textarea";import { stackedThreadToast, toastManager } from "../ui/toast";+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";import {SettingsPageContainer,SettingsRow,@@ -285,6 +293,13 @@ export function ScheduledTasksSettings(target: {<EmptyDescription>Connect an environment to manage scheduled tasks.</EmptyDescription></EmptyHeader></Empty>+ ) : environments.length > 1 ? (+ <ScheduledTaskEnvironmentList+ key={`${target.environmentId ?? defaultEnvironment?.environmentId}:${target.taskId ?? ""}`}+ environmentId={target.environmentId ?? defaultEnvironment?.environmentId}+ taskId={target.taskId}+ onEdit={openForEdit}+ />) : (<div className="space-y-8">{environments.map((entry) => (@@ -316,6 +331,153 @@ export function ScheduledTasksSettings(target: {);}+function ScheduledTaskEnvironmentList({+ environmentId,+ taskId,+ onEdit,+}: {+ readonly environmentId: EnvironmentId | undefined;+ readonly taskId: ScheduledTaskId | undefined;+ readonly onEdit: (environmentId: EnvironmentId, task: ScheduledTask) => void;+}) {+ const { scope, environments } = useSettingsScope();+ const states = useAtomValue(+ useMemo(+ () =>+ Atom.make((get) =>+ environments.map((environment) => {+ const connected =+ environment.connection.phase === "connected" && environment.serverConfig !== null;+ const query = connected+ ? get(+ serverEnvironment.scheduledTasksLive({+ environmentId: environment.environmentId,+ input: {},+ }),+ )+ : null;+ const data = query === null ? null : Option.getOrNull(AsyncResult.value(query));+ return {+ environment,+ connected,+ tasks: data?.tasks.filter((task) =>+ matchesScheduledTaskScope(scope, environment.environmentId, task.projectId),+ ),+ error: query?._tag === "Failure" ? formatEnvironmentQueryError(query.cause) : null,+ };+ }),+ ),+ [environments, scope],+ ),+ );+ const linkedState = states.find((state) => state.environment.environmentId === environmentId);+ const linkedTask = linkedState?.tasks?.find((task) => task.id === taskId);+ const openedLink = useRef(false);+ useEffect(() => {+ if (!openedLink.current && environmentId && linkedTask) {+ openedLink.current = true;+ onEdit(environmentId, linkedTask);+ }+ }, [environmentId, linkedTask, onEdit]);+ useRelativeTimeTick(60_000);++ const loaded = states.filter((state) => state.connected && state.error === null && state.tasks);+ const populated = loaded.filter((state) => state.tasks && state.tasks.length > 0);+ const summaries: Record<string, string[]> = {+ "Not connected:": [],+ "Loading scheduled tasks on": [],+ "Could not load scheduled tasks:": [],+ "No tasks on": [],+ };+ for (const { environment, connected, tasks, error } of states) {+ const label = settingsScopeEnvironmentLabel(environment, environments);+ if (!connected) {+ summaries["Not connected:"]!.push(+ `${label} (${connectionStatusTitle(environment.connection)})`,+ );+ } else if (error !== null) {+ summaries["Could not load scheduled tasks:"]!.push(`${label}: ${error}`);+ } else if (!tasks) {+ summaries["Loading scheduled tasks on"]!.push(label);+ } else if (tasks.length === 0 && populated.length > 0) {+ summaries["No tasks on"]!.push(label);+ }+ }++ return (+ <SettingsGroup>+ {populated.map(({ environment, tasks }) => {+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);+ const transport = environmentTransportLabel(environment);+ return (+ <div key={environment.environmentId} className="divide-y divide-border/50">+ <EnvironmentRow+ kind={resolveEnvironmentMachineKind(environment.serverConfig)}+ label={primary}+ subtitle={+ <>+ {secondary && secondary !== transport ? (+ <span className="block truncate">{secondary}</span>+ ) : null}+ <span className="block truncate">{transport}</span>+ </>+ }+ >+ <ConnectionStatusDot+ dotClassName={connectionPhaseDotClassName(environment.connection.phase)}+ tooltipText={connectionStatusTitle(environment.connection)}+ />+ <span className="text-xs text-muted-foreground">+ {connectionStatusTitle(environment.connection)}+ </span>+ </EnvironmentRow>+ {tasks?.map((task) => (+ <ScheduledTaskRow+ key={task.id}+ environmentId={environment.environmentId}+ task={task}+ onEdit={() => onEdit(environment.environmentId, task)}+ />+ ))}+ </div>+ );+ })}+ {taskId && linkedState?.tasks && linkedState.error === null && !linkedTask ? (+ <SettingsRow+ title="Task unavailable"+ description="This task no longer exists or is outside the selected project scope."+ role="status"+ />+ ) : null}+ {populated.length === 0 && loaded.length > 0 ? (+ <SettingsRow+ title="No scheduled tasks"+ description="No tasks match this environment and project selection."+ />+ ) : null}+ {Object.entries(summaries).map(([label, entries]) => {+ if (entries.length === 0) return null;+ const summary = `${label} ${entries.join(", ")}`;+ return (+ <Tooltip key={label}>+ <TooltipTrigger+ render={+ <p+ className="truncate px-3 py-2.5 text-xs text-muted-foreground sm:px-4"+ role="status"+ />+ }+ >+ {summary}+ </TooltipTrigger>+ <TooltipPopup>{summary}</TooltipPopup>+ </Tooltip>+ );+ })}+ </SettingsGroup>+ );+}+function ScheduledTaskEnvironmentSection({environment,showEnvironmentHeading,@@ -1009,15 +1171,34 @@ function ScheduledTaskEditorDialog({</SelectValue></SelectTrigger><SelectPopup>- {connectedEnvironments.map((entry) => (- <SelectItem key={entry.environmentId} value={entry.environmentId}>- <EnvironmentMachineIcon- kind={resolveEnvironmentMachineKind(entry.serverConfig)}- className="size-4"- />- {entry.label}- </SelectItem>- ))}+ {connectedEnvironments.map((entry) => {+ const { secondary } = settingsScopeEnvironmentLabels(+ entry,+ connectedEnvironments,+ );+ return (+ <SelectItem+ key={entry.environmentId}+ value={entry.environmentId}+ label={entry.label}+ >+ <span className="flex min-w-0 items-center gap-2">+ <EnvironmentMachineIcon+ kind={resolveEnvironmentMachineKind(entry.serverConfig)}+ className="size-4"+ />+ <span className="min-w-0">+ <span className="block truncate">{entry.label}</span>+ {secondary ? (+ <span className="block max-w-72 truncate text-xs text-muted-foreground">+ {secondary}+ </span>+ ) : null}+ </span>+ </span>+ </SelectItem>+ );+ })}</SelectPopup></Select></Field>@@ -1057,8 +1238,18 @@ function ScheduledTaskEditorDialog({</SelectTrigger><SelectPopup>{projects.map((project) => (- <SelectItem key={project.id} value={project.id}>- {project.title}+ <SelectItem key={project.id} value={project.id} label={project.title}>+ <span className="block truncate">{project.title}</span>+ {allProjects.some(+ (other) =>+ other.title === project.title &&+ (other.environmentId !== project.environmentId ||+ other.id !== project.id),+ ) ? (+ <span className="block max-w-72 truncate text-xs text-muted-foreground">+ {project.workspaceRoot}+ </span>+ ) : null}</SelectItem>))}</SelectPopup>diff --git a/apps/web/src/components/settings/SettingInheritance.tsx b/apps/web/src/components/settings/SettingInheritance.tsxindex 4eb641ea0aa..cd76fcfad07 100644--- a/apps/web/src/components/settings/SettingInheritance.tsx+++ b/apps/web/src/components/settings/SettingInheritance.tsx@@ -6,7 +6,7 @@ import {type ServerSettings,type WorktreeSubmodules,} from "@t3tools/contracts";-import { CheckIcon, LayersIcon } from "lucide-react";+import { CheckIcon, ChevronRightIcon, LayersIcon } from "lucide-react";import * as Equal from "effect/Equal";import { cn } from "../../lib/utils";@@ -15,10 +15,13 @@ import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";import { resolveEnvModeLabel, WORKTREE_SUBMODULES_LABELS } from "../BranchToolbar.logic";import { PULL_REQUEST_MERGE_METHOD_LABELS } from "../pullRequest/pullRequestDetail.logic";import { Button, InlineButton } from "../ui/button";+import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";+import { useOptionalSettingsScope } from "./SettingsScopeContext";import type { ProjectOverrideEntry, ScopedSettingsTarget } from "./scopedSettings";import { isProjectScopedSettingKey } from "./scopedSettings";+import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";interface InheritanceLayer {readonly key: "project" | "environment" | "t3.json" | "built-in";@@ -173,14 +176,19 @@ export function SettingInheritance({state: SettingInheritanceState;summary: string;targets: readonly ScopedSettingsTarget[];- environments: readonly Pick<EnvironmentPresentation, "environmentId" | "serverConfig">[];+ environments: readonly Pick<+ EnvironmentPresentation,+ "environmentId" | "label" | "displayUrl" | "serverConfig"+ >[];keys: readonly (keyof ServerSettings)[];/** At environment scope: projects whose own value hides the environment's. */overridingProjects?: readonly SettingOverridingProject[];onClearOverrides?: (entries: readonly ProjectOverrideEntry[]) => void;}) {+ const scopeContext = useOptionalSettingsScope();const key = keys[0];if (!key || targets.length === 0) return null;+ const hasMultipleEnvironments = new Set(targets.map((target) => target.environmentId)).size > 1;const overrideSummary =overridingProjects.length > 0? `${summary} · ${overridingProjects.length} project ${overridingProjects.length === 1 ? "override" : "overrides"}`@@ -190,15 +198,51 @@ export function SettingInheritance({(candidate) => candidate.environmentId === target.environmentId,);if (!environment?.serverConfig) return [];+ const labels = settingsScopeEnvironmentLabels(environment, environments);+ const path = scopeContext?.scope.members.find(+ (member) => member.environmentId === target.environmentId && member.id === target.projectId,+ )?.workspaceRoot;+ const secondary = [labels.secondary, path?.split(/[\\/]/).filter(Boolean).slice(-2).join("/")]+ .filter(Boolean)+ .join(" · ");+ const layers = settingInheritanceLayers(target, environment.serverConfig.settings, key);+ const winningLayer = layers.find((layer) => layer.effective);return [{+ id: `${target.environmentId}:${target.projectId ?? ""}`,target,- environment: { ...environment, serverConfig: environment.serverConfig },+ label: [labels.primary, secondary].filter(Boolean).join(" · "),+ machineLabel: [labels.primary, labels.secondary].filter(Boolean).join(" · "),+ overrides: environment.serverConfig.settings.projectSettingsOverrides,machine: resolveEnvironmentMachineKind(environment.serverConfig),- layers: settingInheritanceLayers(target, environment.serverConfig.settings, key),+ layers,+ winningLayer,+ resolution: {+ winner: winningLayer?.key,+ layers: layers.map(({ key, value }) => [key, value]),+ settings: keys.map((settingKey) => target.settings[settingKey]),+ },},];});+ const primary =+ chains.find(+ ({ target }) =>+ target.environmentId === scopeContext?.target?.environmentId &&+ target.projectId === scopeContext?.target?.projectId,+ ) ?? chains[0];+ const machineLabelFor = (environmentId: string) =>+ chains.find((entry) => entry.target.environmentId === environmentId)?.machineLabel ?? "";+ const groups: (typeof chains)[] = [];+ for (const chain of hasMultipleEnvironments && primary+ ? [primary, ...chains.filter((entry) => entry !== primary)]+ : chains) {+ const group =+ hasMultipleEnvironments &&+ groups.find(([first]) => first && Equal.equals(first.resolution, chain.resolution));+ if (group) group.push(chain);+ else groups.push([chain]);+ }return (<Popover><Tooltip>@@ -227,15 +271,11 @@ export function SettingInheritance({</Tooltip><PopoverPopup align="start" width="md" padding="none"><div className="divide-y divide-border/60">- {chains.map(({ target, environment, machine, layers }) => (- <section- key={`${target.environmentId}:${target.projectId ?? ""}`}- className="px-3 py-2.5"- >- <h4 className="flex items-center gap-1.5 pb-1.5 text-xs font-medium text-muted-foreground">- <EnvironmentMachineIcon aria-hidden kind={machine} className="size-3.5 shrink-0" />- <span className="min-w-0 truncate">{target.label}</span>- </h4>+ {groups.map((members) => {+ const first = members[0];+ if (!first) return null;+ const { id, target, machine, layers, winningLayer } = first;+ const chain = (<ol role="list" className="text-sm">{layers.map((layer) => (<li@@ -273,44 +313,159 @@ export function SettingInheritance({</li>))}</ol>- {(() => {- const overriding = overridingProjects.filter(- (project) => project.environmentId === target.environmentId,- );- if (overriding.length === 0) return null;- const overrides = environment.serverConfig.settings.projectSettingsOverrides;- return (- <div className="mt-2 border-t border-border/60 pt-2">+ );+ return (+ <section key={id} className="px-3 py-2.5">+ {!hasMultipleEnvironments ? (+ <h4 className="flex items-center gap-1.5 pb-1.5 text-xs font-medium text-muted-foreground">+ <EnvironmentMachineIcon+ aria-hidden+ kind={machine}+ className="size-3.5 shrink-0"+ />+ <span className="min-w-0 truncate">{target.label}</span>+ </h4>+ ) : null}+ {hasMultipleEnvironments && groups.length > 1 ? (+ <Collapsible>+ <CollapsibleTrigger+ render={+ <Button+ variant="ghost"+ size="sm-multiline"+ className="w-full justify-start text-left"+ />+ }+ >+ <span className="flex w-full min-w-0 flex-col">+ <span className="flex min-w-0 items-center gap-2">+ <span className="min-w-0 flex-1 truncate text-sm text-foreground tabular-nums">+ {winningLayer?.value}+ </span>+ <span className="text-xs text-muted-foreground">+ {winningLayer?.key === "environment"+ ? "Environment"+ : winningLayer?.label}+ </span>+ <ChevronRightIcon+ aria-hidden+ className="size-3 shrink-0 text-muted-foreground [[data-panel-open]_&]:rotate-90"+ />+ </span>+ <span className="flex min-w-0 flex-col gap-0.5 text-xs text-muted-foreground">+ {members.map((member) => (+ <span+ key={member.id}+ className="flex min-w-0 max-w-full items-center gap-1"+ >+ <EnvironmentMachineIcon+ aria-hidden+ kind={member.machine}+ className="size-3 shrink-0"+ />+ <span className="truncate">{member.label}</span>+ </span>+ ))}+ </span>+ </span>+ </CollapsibleTrigger>+ <CollapsiblePanel>+ <div className="pt-1.5">{chain}</div>+ </CollapsiblePanel>+ </Collapsible>+ ) : (+ <>+ {chain}+ {hasMultipleEnvironments ? (+ <p className="px-2 pt-1.5 text-xs text-muted-foreground">+ Same on all machines+ </p>+ ) : null}+ </>+ )}+ {(() => {+ const overriding = overridingProjects.filter((project) =>+ members.some((member) => member.target.environmentId === project.environmentId),+ );+ if (overriding.length === 0) return null;+ const foldOverrides = hasMultipleEnvironments && overriding.length > 3;+ const header = (<div className="flex items-center justify-between gap-3 px-2 text-xs text-muted-foreground">- <span>Overridden by</span>+ {foldOverrides ? (+ <CollapsibleTrigger render={<InlineButton tone="muted" />}>+ <ChevronRightIcon+ aria-hidden+ className="size-3 [[data-panel-open]_&]:rotate-90"+ />+ Overridden by+ </CollapsibleTrigger>+ ) : (+ <span>Overridden by</span>+ )}{onClearOverrides ? (<InlineButton onClick={() => onClearOverrides(overriding)}>Reset {overriding.length === 1 ? "it" : "all"}</InlineButton>) : null}</div>- <ul role="list" className="mt-0.5 text-sm">+ );+ const projects = (+ <ul+ role="list"+ className={cn("mt-0.5 text-sm", foldOverrides && "max-h-48 overflow-y-auto")}+ >{overriding.map((project) => (<li- key={project.projectId}+ key={`${project.environmentId}:${project.projectId}`}className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 px-2 py-1">- <InlineButton className="min-w-0 justify-start" onClick={project.open}>- <span className="truncate">{project.label}</span>- </InlineButton>+ <span className="flex min-w-0 flex-col items-start">+ <InlineButton+ className="min-w-0 max-w-full justify-start"+ onClick={project.open}+ >+ <span className="truncate">{project.label}</span>+ </InlineButton>+ {hasMultipleEnvironments ? (+ <span className="max-w-full truncate text-xs text-muted-foreground">+ {machineLabelFor(project.environmentId)}+ </span>+ ) : null}+ </span><span className="max-w-32 truncate text-muted-foreground tabular-nums">{isProjectScopedSettingKey(key)- ? formatValue(key, overrides[project.projectId]?.[key])+ ? formatValue(+ key,+ members.find(+ (member) =>+ member.target.environmentId === project.environmentId,+ )?.overrides[project.projectId]?.[key],+ ): null}</span></li>))}</ul>- </div>- );- })()}- </section>- ))}+ );+ return (+ <div className="mt-2 border-t border-border/60 pt-2">+ {foldOverrides ? (+ <Collapsible>+ {header}+ <CollapsiblePanel>{projects}</CollapsiblePanel>+ </Collapsible>+ ) : (+ <>+ {header}+ {projects}+ </>+ )}+ </div>+ );+ })()}+ </section>+ );+ })}</div></PopoverPopup></Popover>diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsxindex ef60c9e3c3c..f1825032c50 100644--- a/apps/web/src/components/settings/SettingsPanels.tsx+++ b/apps/web/src/components/settings/SettingsPanels.tsx@@ -1,4 +1,5 @@import { SettingsGroup } from "./SettingsGroup";+import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis";import { useScopedSettingsWriteAllowed } from "./useScopedSettings";import { Spinner } from "~/components/ui/spinner";import { NotificationSettings } from "./NotificationSettings";@@ -3443,7 +3444,7 @@ export function GeneralSettingsPanel() {}export function ArchivedThreadsPanel() {- const { scope } = useSettingsScope();+ const { scope, groups: projectGroups, environments } = useSettingsScope();const { unarchiveThread, confirmAndDeleteThread } = useThreadActions();const {snapshots: archivedSnapshots,@@ -3452,7 +3453,7 @@ export function ArchivedThreadsPanel() {refresh: refreshArchivedThreads,} = useArchivedThreadSnapshots(scope.environmentIds);- const archivedGroups = useMemo(() => {+ const { groups: archivedGroups, hasMultipleEnvironments } = useMemo(() => {const selectedProjectKeys =scope.kind === "project" || scope.kind === "checkout"? new Set(scope.members.map((member) => `${member.environmentId}:${member.id}`))@@ -3470,15 +3471,43 @@ export function ArchivedThreadsPanel() {),),);+ const environmentLabels = new Map(+ environments.map((environment) => {+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);+ return [environment.environmentId, secondary ? `${primary} (${secondary})` : primary];+ }),+ );const threads = archivedSnapshots.flatMap(({ environmentId, snapshot }) =>- snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),+ snapshot.threads.map((thread) => ({+ ...presentThreadShell(environmentId, thread),+ environmentLabel: environmentLabels.get(environmentId) ?? environmentId,+ })),+ );+ const hasMultipleEnvironments =+ new Set(+ threads+ .filter((thread) =>+ projectsByEnvironmentAndId.has(`${thread.environmentId}:${thread.projectId}`),+ )+ .map((thread) => thread.environmentId),+ ).size > 1;+ const logicalGroupsByProjectKey = new Map(+ projectGroups.flatMap((group) =>+ group.memberProjectRefs.map(+ (member) => [`${member.environmentId}:${member.projectId}`, group] as const,+ ),+ ),);const archivedProjects = Array.from(projectsByEnvironmentAndId.values());- const groups: Array<{- readonly project: (typeof archivedProjects)[number];- readonly threads: Array<(typeof threads)[number]>;- }> = [];+ const groups = new Map<+ string,+ {+ readonly project: (typeof archivedProjects)[number];+ readonly title: string;+ readonly threads: Array<(typeof threads)[number]>;+ }+ >();for (const project of archivedProjects) {const projectThreads: Array<(typeof threads)[number]> = [];for (const thread of threads) {@@ -3487,18 +3516,34 @@ export function ArchivedThreadsPanel() {}}if (projectThreads.length > 0) {- groups.push({- project,- threads: projectThreads.toSorted((left, right) => {- const leftKey = left.archivedAt ?? left.createdAt;- const rightKey = right.archivedAt ?? right.createdAt;- return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id);- }),- });+ const physicalProjectKey = `${project.environmentId}:${project.id}` as const;+ const logicalGroup = hasMultipleEnvironments+ ? logicalGroupsByProjectKey.get(physicalProjectKey)+ : undefined;+ const groupKey = logicalGroup?.projectKey ?? physicalProjectKey;+ const group = groups.get(groupKey);+ if (group) {+ group.threads.push(...projectThreads);+ } else {+ groups.set(groupKey, {+ project,+ title: logicalGroup?.displayName ?? project.title,+ threads: projectThreads,+ });+ }}}- return groups;- }, [archivedSnapshots, scope]);+ const sortedGroups = Array.from(groups, ([key, group]) => ({+ ...group,+ key,+ threads: group.threads.toSorted((left, right) => {+ const leftKey = left.archivedAt ?? left.createdAt;+ const rightKey = right.archivedAt ?? right.createdAt;+ return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id);+ }),+ }));+ return { groups: sortedGroups, hasMultipleEnvironments };+ }, [archivedSnapshots, environments, projectGroups, scope]);const handleArchivedThreadContextMenu = useCallback(async (threadRef: ScopedThreadRef, position: { x: number; y: number }) => {@@ -3578,16 +3623,16 @@ export function ArchivedThreadsPanel() {/></SettingsSection>) : (- archivedGroups.map(({ project, threads: projectThreads }, index) => (+ archivedGroups.map(({ key, project, title, threads: projectThreads }, index) => (<SettingsSection- key={`${project.environmentId}:${project.id}`}+ key={key}id={index === 0 ? searchableSetting("archive").id : undefined}- title={project.title}+ title={title}icon={<ProjectFavicon project={project} />}>{projectThreads.map((thread) => (<SettingsRow- key={thread.id}+ key={`${thread.environmentId}:${thread.id}`}onContextMenu={(event) => {event.preventDefault();void (async () => {@@ -3615,11 +3660,12 @@ export function ArchivedThreadsPanel() {}}title={thread.title}description={- <>+ <span className={hasMultipleEnvironments ? "block truncate" : undefined}>+ {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null}Archived {formatRelativeTimeLabel(thread.archivedAt ?? thread.createdAt)}{" \u00b7 Created "}{formatRelativeTimeLabel(thread.createdAt)}- </>+ </span>}control={<Buttondiff --git a/apps/web/src/components/settings/SettingsScopeNotice.tsx b/apps/web/src/components/settings/SettingsScopeNotice.tsxindex bd248370db5..e9eda9426c0 100644--- a/apps/web/src/components/settings/SettingsScopeNotice.tsx+++ b/apps/web/src/components/settings/SettingsScopeNotice.tsx@@ -1,12 +1,31 @@-import { Button } from "../ui/button";-import { Alert, AlertAction, AlertDescription } from "../ui/alert";-import { SettingsPageContainer } from "./settingsLayout";+import { resolveEnvironmentMachineKind, type EnvironmentId } from "@t3tools/contracts";+import { useLocation, useNavigate } from "@tanstack/react-router";+import { ChevronRightIcon, LayersIcon } from "lucide-react";+import type { ReactNode } from "react";++import { cn } from "../../lib/utils";+import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";+import { useEnvironments, type EnvironmentPresentation } from "../../state/environments";+import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";+import { ProjectFavicon } from "../ProjectFavicon";+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";+import { ITEM_ROW_CLASSNAME } from "./itemRows";+import { SettingsGroup } from "./SettingsGroup";+import { SettingsPageContainer, SettingsSection } from "./settingsLayout";import { useSettingsScope } from "./SettingsScopeContext";-import { useEnvironments } from "../../state/environments";import type { SettingsScopeSearch } from "./settingsScope";-import { useSettingsProjectGroups } from "./useSettingsProjectGroups";-import { useLocation, useNavigate } from "@tanstack/react-router";-import type { EnvironmentId } from "@t3tools/contracts";+import {+ settingsScopeEnvironmentAddress,+ settingsScopeEnvironmentLabels,+ settingsScopeProjectMachines,+} from "./settingsScopeAxis";++interface ScopeChoice {+ label: string;+ secondary?: string;+ icon: ReactNode;+ search: SettingsScopeSearch;+}/** Offer an explicit target change when a category has no settings at this scope. */export function SettingsScopeNotice({@@ -20,28 +39,58 @@ export function SettingsScopeNotice({targetId?: string;eligibleEnvironmentIds?: readonly EnvironmentId[];}) {- const { selectScope, search } = useSettingsScope();+ const { selectScope, search, groups } = useSettingsScope();const navigate = useNavigate({ from: "/settings" });const pathname = useLocation({ select: (location) => location.pathname });const { environments } = useEnvironments();- const groups = useSettingsProjectGroups();- const choices: { label: string; search: SettingsScopeSearch }[] =+ const environmentIcon = (environment: EnvironmentPresentation | undefined) =>+ environment ? (+ <EnvironmentMachineIcon+ aria-hidden+ kind={resolveEnvironmentMachineKind(environment.serverConfig)}+ className="size-4 shrink-0 text-muted-foreground"+ />+ ) : null;+ const choiceGroups =target === "checkout"- ? groups- .filter((group) => !search.project || group.projectKey === search.project)- .flatMap((group) =>- group.memberProjects.map((member) => ({- label: `${group.displayName} · ${member.environmentLabel ?? "Environment"} · ${member.workspaceRoot}`,- search: {- project: group.projectKey,- machine: member.environmentId,- checkout: member.physicalProjectKey,- },- })),- )+ ? groups.filter((group) => !search.project || group.projectKey === search.project)+ : [null];+ const renderChoices = (group: SidebarProjectSnapshot | null) => {+ const choices: ScopeChoice[] = group+ ? group.memberProjects.map((member) => {+ const environment = environments.find(+ (entry) => entry.environmentId === member.environmentId,+ );+ const { primary, secondary } = environment+ ? settingsScopeEnvironmentLabels(environment, environments)+ : {+ primary: member.environmentLabel ?? "Environment",+ secondary: member.environmentId,+ };+ return {+ label: primary,+ secondary: [secondary, member.workspaceRoot].filter(Boolean).join(" · "),+ icon: environmentIcon(environment),+ search: {+ project: group.projectKey,+ machine: member.environmentId,+ checkout: member.physicalProjectKey,+ },+ };+ }): target === "project"? groups.map((group) => ({label: group.displayName,+ secondary: [+ ...(groups.some(+ (other) =>+ other.projectKey !== group.projectKey && other.displayName === group.displayName,+ )+ ? settingsScopeProjectMachines(group, environments)+ : []),+ group.workspaceRoot,+ ].join(" · "),+ icon: <ProjectFavicon project={group} className="size-4 shrink-0" />,search: { project: group.projectKey },})): target === "environment"@@ -51,40 +100,74 @@ export function SettingsScopeNotice({eligibleEnvironmentIds === undefined ||eligibleEnvironmentIds.includes(entry.environmentId),)- .map((entry) => ({- label: environments.some(- (other) =>- other.environmentId !== entry.environmentId && other.label === entry.label,- )- ? `${entry.label} · ${entry.displayUrl || entry.environmentId}`- : entry.label,- search: { machine: entry.environmentId },- }))- : [{ label: "Open all environments", search: {} }];+ .map((entry) => {+ const { primary, secondary } = settingsScopeEnvironmentLabels(entry, environments);+ return {+ label: primary,+ secondary: secondary || settingsScopeEnvironmentAddress(entry),+ icon: environmentIcon(entry),+ search: { machine: entry.environmentId },+ };+ })+ : [+ {+ label: "Open all environments",+ icon: <LayersIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />,+ search: {},+ },+ ];+ return choices.map((choice) => (+ <button+ key={JSON.stringify(choice.search)}+ type="button"+ className={cn(+ ITEM_ROW_CLASSNAME,+ "flex w-full min-w-0 cursor-pointer items-center gap-3 text-left outline-none hover:bg-accent/50 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",+ )}+ onClick={() => {+ if (targetId)+ void navigate({ to: pathname, search: () => choice.search, hash: targetId });+ else selectScope(choice.search);+ }}+ >+ {choice.icon}+ <span className="min-w-0 flex-1">+ <span className="block truncate text-sm font-medium">{choice.label}</span>+ {choice.secondary ? (+ <Tooltip>+ <TooltipTrigger+ render={<span className="block truncate text-xs text-muted-foreground" />}+ >+ {choice.secondary}+ </TooltipTrigger>+ <TooltipPopup>{choice.secondary}</TooltipPopup>+ </Tooltip>+ ) : null}+ </span>+ <ChevronRightIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />+ </button>+ ));+ };return (<SettingsPageContainer>- <Alert role="status">- <AlertDescription>- <p>{children}</p>- <AlertAction className="flex-wrap">- {choices.map((choice) => (- <Button- key={JSON.stringify(choice.search)}- size="sm-multiline"- variant="outline"- className="max-w-full break-all text-left"- onClick={() => {- if (targetId)- void navigate({ to: pathname, search: () => choice.search, hash: targetId });- else selectScope(choice.search);- }}- >- {choice.label}- </Button>- ))}- </AlertAction>- </AlertDescription>- </Alert>+ <div className="space-y-3">+ <p role="status" className="px-3 text-sm text-muted-foreground sm:px-4">+ {children}+ </p>+ <div className="space-y-4">+ {choiceGroups.map((group) =>+ group?.displayName ? (+ <SettingsSection key={group.projectKey} title={group.displayName}>+ {renderChoices(group)}+ </SettingsSection>+ ) : (+ <SettingsGroup key={group?.projectKey ?? target}>+ {renderChoices(group)}+ </SettingsGroup>+ ),+ )}+ </div>+ </div></SettingsPageContainer>);}diff --git a/apps/web/src/components/settings/SettingsScopeSentence.tsx b/apps/web/src/components/settings/SettingsScopeSentence.tsxindex 04312fd0314..a08658b3f8e 100644--- a/apps/web/src/components/settings/SettingsScopeSentence.tsx+++ b/apps/web/src/components/settings/SettingsScopeSentence.tsx@@ -1,13 +1,22 @@import { resolveEnvironmentMachineKind } from "@t3tools/contracts";import { useLocation } from "@tanstack/react-router";-import { ChevronDownIcon, LayersIcon } from "lucide-react";-import type { ReactNode } from "react";+import { CheckIcon, ChevronDownIcon, LayersIcon } from "lucide-react";+import { Fragment, useState, type ReactNode } from "react";import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";import { useEnvironments, type EnvironmentPresentation } from "../../state/environments";import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";import { ProjectFavicon } from "../ProjectFavicon";import { InlineButton } from "../ui/button";+import {+ Combobox,+ ComboboxEmpty,+ ComboboxItem,+ ComboboxList,+ ComboboxPopup,+ ComboboxSearchInput,+ ComboboxTrigger,+} from "../ui/combobox";import {Menu,MenuPopup,@@ -26,7 +35,10 @@ import {projectAxisValue,selectEnvironmentAxis,selectProjectAxis,+ settingsScopeEnvironmentAddress,settingsScopeEnvironmentLabel,+ settingsScopeEnvironmentLabels,+ settingsScopeProjectMachines,} from "./settingsScopeAxis";/** Pages whose every row is saved on this client; they have no scope to pick. */@@ -80,29 +92,133 @@ export function SettingsScopeSentence() {);}+interface ScopeOption {+ value: string;+ label: string;+ secondary?: string;+ icon?: ReactNode;+ offline?: boolean;+}++function ScopeOptionLabel({ option }: { option: ScopeOption }) {+ return (+ <>+ {option.icon}+ <span className="min-w-0 flex-1">+ <span className="block truncate">{option.label}</span>+ {option.secondary ? (+ <span className="block truncate text-xs text-muted-foreground">{option.secondary}</span>+ ) : null}+ </span>+ {option.offline ? (+ <span className="shrink-0 text-xs text-muted-foreground">Offline</span>+ ) : null}+ </>+ );+}+function ScopeMenu({ariaLabel,icon,label,- children,+ value,+ options,+ allOption,+ searchLabel,+ onChange,}: {ariaLabel: string;icon: ReactNode;label: string;- children: ReactNode;+ value: string;+ options: ScopeOption[];+ allOption: ScopeOption | null;+ searchLabel: string;+ onChange: (next: string) => void;}) {+ const [query, setQuery] = useState("");+ const Trigger = options.length > 6 ? ComboboxTrigger : MenuTrigger;+ const trigger = (+ <Trigger+ aria-label={`${ariaLabel}: ${label}`}+ render={<InlineButton tone="picker" />}+ className="min-w-0 max-w-72"+ >+ {icon}+ <span className="min-w-0 truncate">{label}</span>+ <ChevronDownIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />+ </Trigger>+ );+ const choices = allOption ? [allOption, ...options] : options;+ if (options.length > 6) {+ const needle = query.trim().toLowerCase();+ const filteredItems = choices.filter((option) =>+ `${option.label} ${option.secondary ?? ""} ${option.value}`.toLowerCase().includes(needle),+ );+ return (+ <Combobox+ items={choices}+ filteredItems={filteredItems}+ filter={null}+ autoHighlight+ itemToStringLabel={(option) => option.label}+ isItemEqualToValue={(a, b) => a.value === b.value}+ value={choices.find((option) => option.value === value) ?? null}+ onOpenChange={(open) => {+ if (!open) setQuery("");+ }}+ onValueChange={(option) => {+ if (option) onChange(option.value);+ }}+ >+ {trigger}+ <ComboboxPopup align="start" className="w-80">+ <ComboboxSearchInput+ aria-label={searchLabel}+ placeholder={searchLabel}+ value={query}+ onChange={(event) => setQuery(event.target.value)}+ />+ <ComboboxEmpty>No matches found.</ComboboxEmpty>+ <ComboboxList>+ {(option: ScopeOption) => (+ <ComboboxItem key={option.value} value={option}>+ <ScopeOptionLabel option={option} />+ {option.value === value ? (+ <CheckIcon aria-hidden className="size-3.5 shrink-0" />+ ) : null}+ </ComboboxItem>+ )}+ </ComboboxList>+ </ComboboxPopup>+ </Combobox>+ );+ }return (<Menu>- <MenuTrigger- aria-label={`${ariaLabel}: ${label}`}- render={<InlineButton tone="picker" />}- className="min-w-0 max-w-72"- >- {icon}- <span className="min-w-0 truncate">{label}</span>- <ChevronDownIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />- </MenuTrigger>- <MenuPopup align="start">{children}</MenuPopup>+ {trigger}+ <MenuPopup align="start">+ <div className="w-72 max-w-full">+ <MenuRadioGroup+ value={value}+ onValueChange={(next) => {+ if (typeof next === "string") onChange(next);+ }}+ >+ {choices.map((option, index) => (+ <Fragment key={option.value}>+ <MenuRadioItem value={option.value} closeOnClick>+ <span className="flex min-w-0 items-center gap-2">+ <ScopeOptionLabel option={option} />+ <MenuRadioItemIndicator />+ </span>+ </MenuRadioItem>+ {index === 0 && allOption ? <MenuSeparator /> : null}+ </Fragment>+ ))}+ </MenuRadioGroup>+ </div>+ </MenuPopup></Menu>);}@@ -143,83 +259,76 @@ function EnvironmentScopeMenu({? "No environments": "All environments"}- >- <MenuRadioGroup- value={environmentValue}- onValueChange={(next) => {- if (typeof next === "string") onChange(selectEnvironmentAxis(value, next));- }}- >- {!singleEnvironment ? (- <>- <MenuRadioItem value={ALL_ENVIRONMENTS_VALUE} closeOnClick>- <span className="flex min-w-0 items-center gap-2">- <LayersIcon aria-hidden className="size-3.5" />- <span className="min-w-0 flex-1 truncate">All environments</span>- <MenuRadioItemIndicator />- </span>- </MenuRadioItem>- <MenuSeparator />- </>- ) : null}- {environments.map((environment) => (- <MenuRadioItem- key={environment.environmentId}- value={environment.environmentId}- closeOnClick- >- <span className="flex min-w-0 items-center gap-2">- <EnvironmentMachineIcon- aria-hidden- kind={resolveEnvironmentMachineKind(environment.serverConfig)}- className="size-3.5"- />- <span className="min-w-0 flex-1 truncate">- {settingsScopeEnvironmentLabel(environment, environments)}- </span>- {environment.connection.phase === "connected" ? null : (- <span className="shrink-0 text-xs text-muted-foreground">Offline</span>- )}- <MenuRadioItemIndicator />- </span>- </MenuRadioItem>- ))}- </MenuRadioGroup>- </ScopeMenu>+ value={environmentValue}+ onChange={(next) => onChange(selectEnvironmentAxis(value, next))}+ searchLabel="Search environments"+ allOption={+ singleEnvironment+ ? null+ : {+ value: ALL_ENVIRONMENTS_VALUE,+ label: "All environments",+ icon: <LayersIcon aria-hidden className="size-3.5 shrink-0" />,+ }+ }+ options={environments.map((environment) => {+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);+ return {+ value: environment.environmentId,+ label: primary,+ secondary:+ environments.length <= 1+ ? ""+ : secondary || settingsScopeEnvironmentAddress(environment),+ icon: (+ <EnvironmentMachineIcon+ aria-hidden+ kind={resolveEnvironmentMachineKind(environment.serverConfig)}+ className="size-3.5 shrink-0"+ />+ ),+ offline: environment.connection.phase !== "connected",+ };+ })}+ />);}-function ProjectScopeMenu({ value, groups, onChange }: SettingsScopeMenuProps) {+function ProjectScopeMenu({ value, groups, environments, onChange }: SettingsScopeMenuProps) {const selected = groups.find((group) => group.projectKey === value.project);+ const projects = groups.map((group) => ({+ group,+ machines: settingsScopeProjectMachines(group, environments, true).join(", "),+ }));return (<ScopeMenuariaLabel="Project scope"icon={selected ? <ProjectFavicon project={selected} className="size-3.5 shrink-0" /> : null}label={selected?.displayName ?? (value.project ? "Unavailable project" : "All projects")}- >- <MenuRadioGroup- value={projectAxisValue(value)}- onValueChange={(next) => {- if (typeof next === "string") onChange(selectProjectAxis(value, next));- }}- >- <MenuRadioItem value={ALL_PROJECTS_VALUE} closeOnClick>- <span className="flex min-w-0 items-center gap-2">- <span className="min-w-0 flex-1 truncate">All projects</span>- <MenuRadioItemIndicator />- </span>- </MenuRadioItem>- <MenuSeparator />- {groups.map((group) => (- <MenuRadioItem key={group.projectKey} value={group.projectKey} closeOnClick>- <span className="flex min-w-0 items-center gap-2">- <ProjectFavicon project={group} className="size-3.5" />- <span className="min-w-0 flex-1 truncate">{group.displayName}</span>- <MenuRadioItemIndicator />- </span>- </MenuRadioItem>- ))}- </MenuRadioGroup>- </ScopeMenu>+ value={projectAxisValue(value)}+ onChange={(next) => onChange(selectProjectAxis(value, next))}+ searchLabel="Search projects"+ allOption={{ value: ALL_PROJECTS_VALUE, label: "All projects" }}+ options={projects.map(({ group, machines }) => {+ const sameName = projects.filter(+ (other) =>+ other.group.projectKey !== group.projectKey &&+ other.group.displayName === group.displayName,+ );+ return {+ value: group.projectKey,+ label: group.displayName,+ secondary:+ sameName.length === 0+ ? environments.length > 1+ ? group.workspaceRoot+ : ""+ : sameName.some((other) => other.machines === machines)+ ? `${machines} · ${group.workspaceRoot}`+ : machines,+ icon: <ProjectFavicon project={group} className="size-3.5 shrink-0" />,+ };+ })}+ />);}diff --git a/apps/web/src/components/settings/StorageSettings.tsx b/apps/web/src/components/settings/StorageSettings.tsxindex 92ca6ed1806..ff6937681bc 100644--- a/apps/web/src/components/settings/StorageSettings.tsx+++ b/apps/web/src/components/settings/StorageSettings.tsx@@ -47,6 +47,7 @@ import {useScopedSettingsMixed,useUpdateScopedSettings,} from "./useScopedSettings";+import { settingsScopeEnvironmentLabel } from "./settingsScopeAxis";function WorktreesDirectoryRow() {const { connectedEnvironments, targets } = useSettingsScope();@@ -171,6 +172,20 @@ const KEEP_WHEN_LABELS = {"tracked-changes": "Edited tracked files",} as const;+/** One line for the last-run fold; identical results across machines collapse into one. */+function lastRunSummary(+ entries: readonly { readonly label: string; readonly counts: string }[],+ machineCount: number,+) {+ const first = entries[0];+ if (!first) return "";+ if (machineCount <= 1) return first.counts;+ if (entries.length === machineCount && entries.every((entry) => entry.counts === first.counts)) {+ return `${first.counts} on every machine`;+ }+ return entries.map((entry) => `${entry.label}: ${entry.counts}`).join(" · ");+}+function CleanupResults({report,environmentLabel,@@ -294,6 +309,10 @@ function CleanupSection() {return {environment,report,+ label: settingsScopeEnvironmentLabel(environment, connectedEnvironments),+ counts: report+ ? `${report.counts.removed} removed, ${report.counts.kept} kept${report.counts.failed > 0 ? `, ${report.counts.failed} failed` : ""}`+ : "",description: report? `Last run ${formatRelativeTimeLabel(report.finishedAt)}. ${formatBytes(report.bytesFreed)} recovered.${report.counts.failed > 0 ? ` ${report.counts.failed} ${report.counts.failed === 1 ? "item" : "items"} couldn't be removed.` : ""}`: query?.failed@@ -346,9 +365,9 @@ function CleanupSection() {<span>{!hasRules? "Turn on a cleanup rule to use this."- : summaries.map(({ environment, description }) => (+ : summaries.map(({ environment, label, description }) => (<span key={environment.environmentId} className="block">- {supported.length > 1 ? `${environment.label}: ` : ""}+ {supported.length > 1 ? `${label}: ` : ""}{description}</span>))}@@ -371,25 +390,18 @@ function CleanupSection() {id="storage-cleanup-last-run"title="Last run"headerPlacement="inside"- summary={summaries- .flatMap(({ environment, report }) =>- report- ? [- `${connectedEnvironments.length > 1 ? `${environment.label}: ` : ""}${report.counts.removed} removed, ${report.counts.kept} kept${report.counts.failed > 0 ? `, ${report.counts.failed} failed` : ""}`,- ]- : [],- )- .join(" · ")}+ summary={lastRunSummary(+ summaries.filter(({ report }) => report !== null),+ connectedEnvironments.length,+ )}>{summaries.map(- ({ environment, report }) =>+ ({ environment, label, report }) =>report && (<CleanupResultskey={environment.environmentId}report={report}- environmentLabel={- connectedEnvironments.length > 1 ? environment.label : undefined- }+ environmentLabel={connectedEnvironments.length > 1 ? label : undefined}/>),)}diff --git a/apps/web/src/components/settings/deviceHostsSettings.logic.ts b/apps/web/src/components/settings/deviceHostsSettings.logic.tsindex ae633b0c3eb..3a48ae6d9bc 100644--- a/apps/web/src/components/settings/deviceHostsSettings.logic.ts+++ b/apps/web/src/components/settings/deviceHostsSettings.logic.ts@@ -1,4 +1,56 @@-import type { SshDeviceHostConfig } from "@t3tools/contracts";+import type { EnvironmentId, SshDeviceHostConfig } from "@t3tools/contracts";++export interface DeviceHostEnvironment {+ readonly environmentId: EnvironmentId;+ readonly label: string;+ readonly hosts: ReadonlyArray<SshDeviceHostConfig>;+}++export interface DeviceHostGroup {+ readonly host: SshDeviceHostConfig;+ readonly members: Array<{+ readonly environmentId: EnvironmentId;+ readonly label: string;+ readonly host: SshDeviceHostConfig;+ }>;+}++/** Only combine matching configurations; ambiguous identities keep their machine's list. */+export function groupDeviceHosts(+ environments: ReadonlyArray<DeviceHostEnvironment>,+): ReadonlyArray<DeviceHostGroup> | null {+ const groups = new Map<string, DeviceHostGroup>();+ const identities = new Map<string, string>();+ const configurations = new Map<string, string>();+ for (const environment of environments) {+ const destinations = new Set<string>();+ for (const host of environment.hosts) {+ const destination = JSON.stringify([host.target, host.port, host.identityFile]);+ const configuration = JSON.stringify([host.label, host.target, host.port, host.identityFile]);+ const previousConfiguration = identities.get(host.id);+ const targetConfiguration = configurations.get(host.target);+ const group = groups.get(destination);+ if (+ destinations.has(destination) ||+ (previousConfiguration !== undefined && previousConfiguration !== configuration) ||+ (targetConfiguration !== undefined && targetConfiguration !== configuration)+ ) {+ return null;+ }+ destinations.add(destination);+ identities.set(host.id, configuration);+ configurations.set(host.target, configuration);+ const member = {+ environmentId: environment.environmentId,+ label: environment.label,+ host,+ };+ if (group) group.members.push(member);+ else groups.set(destination, { host, members: [member] });+ }+ }+ return [...groups.values()];+}/** Apply one host change without replacing another environment's host list. */export function updateDeviceHosts(diff --git a/apps/web/src/components/settings/settingsScopeAxis.test.ts b/apps/web/src/components/settings/settingsScopeAxis.test.tsindex 54a87dc956a..5eecdddcea4 100644--- a/apps/web/src/components/settings/settingsScopeAxis.test.ts+++ b/apps/web/src/components/settings/settingsScopeAxis.test.ts@@ -25,10 +25,7 @@ describe("settings scope environment labels", () => {const environments = [first, second];expect(environments.map((environment) => settingsScopeEnvironmentLabel(environment, environments)),- ).toEqual([- "Development · https://first.example.com",- "Development · https://second.example.com",- ]);+ ).toEqual(["Development · first.example.com", "Development · second.example.com"]);});it("falls back to environment IDs when duplicate names have no display URL", () => {diff --git a/apps/web/src/components/settings/settingsScopeAxis.ts b/apps/web/src/components/settings/settingsScopeAxis.tsindex 0c0915c54c8..9d0d1fdd461 100644--- a/apps/web/src/components/settings/settingsScopeAxis.ts+++ b/apps/web/src/components/settings/settingsScopeAxis.ts@@ -1,19 +1,58 @@+import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping";import type { EnvironmentPresentation } from "../../state/environments";import type { ResolvedSettingsScope, SettingsScopeSearch } from "./settingsScope";type ScopeEnvironment = Pick<EnvironmentPresentation, "environmentId" | "label" | "displayUrl">;-export function settingsScopeEnvironmentLabel(+export function settingsScopeEnvironmentAddress(environment: ScopeEnvironment) {+ if (!environment.displayUrl) return environment.environmentId;+ try {+ return new URL(environment.displayUrl).host || environment.displayUrl;+ } catch {+ return environment.displayUrl;+ }+}++export function settingsScopeEnvironmentLabels(environment: ScopeEnvironment,- environments: readonly ScopeEnvironment[],+ environments?: readonly ScopeEnvironment[],) {- const duplicate = environments.some(+ const duplicates = environments?.filter((other) =>other.environmentId !== environment.environmentId && other.label === environment.label,);- return duplicate- ? `${environment.label} · ${environment.displayUrl ?? environment.environmentId}`- : environment.label;+ const address = settingsScopeEnvironmentAddress(environment);+ const secondary = duplicates?.some((other) => settingsScopeEnvironmentAddress(other) === address)+ ? environment.displayUrl || environment.environmentId+ : address;+ return {+ primary: environment.label,+ secondary: environments === undefined || duplicates?.length ? secondary : "",+ };+}++export function settingsScopeEnvironmentLabel(+ environment: ScopeEnvironment,+ environments: readonly ScopeEnvironment[],+) {+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);+ return secondary ? `${primary} · ${secondary}` : primary;+}++export function settingsScopeProjectMachines(+ group: SidebarProjectSnapshot,+ environments: readonly ScopeEnvironment[],+ includeAddresses = false,+) {+ const machines = group.memberProjects.map((member) => {+ const environment = environments.find((entry) => entry.environmentId === member.environmentId);+ if (!environment) return member.environmentLabel ?? member.environmentId;+ const { primary, secondary } = settingsScopeEnvironmentLabels(environment, environments);+ const address =+ secondary || (includeAddresses ? settingsScopeEnvironmentAddress(environment) : "");+ return includeAddresses || address ? `${primary} · ${address}` : primary;+ });+ return Array.from(new Set(machines));}export const ALL_ENVIRONMENTS_VALUE = "all";