From 0cba9f8f9e3d4f29635d4c53923e92a629850a3d Mon Sep 17 00:00:00 2001 From: amanthanvi Date: Sat, 19 Sep 2026 23:47:23 -0400 Subject: [PATCH 1/3] feat(web,mobile): seven more environment icons Two generic servers in the Connections list show the same glyph, because the only vocabulary is the seven shapes a server can detect. A dev box and a database box are both "server". Add seven role icons that a machine is given rather than detected as: Dev box, Database, Container, Edge, Home server, GPU box, and Network. Every SF Symbol name reuses a key the Android fallback map already has, so the Android map and the Metro bundle get no new entries, and both renderers hold an exhaustive record over the id list in contracts so a missing entry fails typecheck. The picker lists all fourteen with a rule between the machine kinds and the roles. A role travels as the object form, which a server without the `environmentIconOverride` capability rejects, so those items stay disabled with the reason until that server is updated. The write and the per-item lock are pure functions with tests. Claude Fable 5.1 via Claude Code --- .../components/EnvironmentMachineSymbol.tsx | 43 +++++-- .../src/components/EnvironmentMachineIcon.tsx | 52 ++++++-- .../settings/EnvironmentIconPicker.test.ts | 54 +++++++- .../settings/EnvironmentIconPicker.tsx | 120 +++++++++++++----- packages/contracts/src/environment.ts | 22 ++++ 5 files changed, 234 insertions(+), 57 deletions(-) diff --git a/apps/mobile/src/components/EnvironmentMachineSymbol.tsx b/apps/mobile/src/components/EnvironmentMachineSymbol.tsx index 9f4ce3b22a18b..aaaffd22ce267 100644 --- a/apps/mobile/src/components/EnvironmentMachineSymbol.tsx +++ b/apps/mobile/src/components/EnvironmentMachineSymbol.tsx @@ -1,11 +1,14 @@ import { - isEnvironmentMachineKind, + isEnvironmentCuratedIconId, + type EnvironmentCuratedIconId, type EnvironmentIcon, - type EnvironmentMachineKind, } from "@t3tools/contracts"; import { SymbolView, type AppSymbolName } from "./AppSymbol"; -export const ENVIRONMENT_MACHINE_SYMBOLS = { +// Every SF name here is already a key of the Android fallback map, so a new +// id adds nothing to the Metro bundle; only iOS needs a check that the glyph +// exists. +const SYMBOL_BY_ID = { server: "server.rack", cloud: "cloud", linux: "terminal", @@ -13,9 +16,16 @@ export const ENVIRONMENT_MACHINE_SYMBOLS = { laptop: "laptopcomputer", "mac-mini": "macmini", "mac-studio": "macstudio", -} as const satisfies Record; + terminal: "terminal", + database: "internaldrive", + container: "cube", + globe: "globe", + home: "house", + gpu: "brain", + network: "point.3.connected.trianglepath.dotted", +} as const satisfies Record; -export const ENVIRONMENT_MACHINE_KIND_LABELS: Record = { +export const ENVIRONMENT_ICON_LABELS: Record = { server: "Server", cloud: "Cloud VM", linux: "Linux/WSL", @@ -23,20 +33,27 @@ export const ENVIRONMENT_MACHINE_KIND_LABELS: Record) { ); } -const ICON_BY_KIND: Record> = { +const ICON_BY_ID: Record> = { server: ServerIcon, cloud: CloudIcon, linux: LinuxIcon, @@ -55,9 +68,16 @@ const ICON_BY_KIND: Record = { +export const ENVIRONMENT_ICON_LABELS: Record = { server: "Server", cloud: "Cloud VM", linux: "Linux/WSL", @@ -65,22 +85,32 @@ export const ENVIRONMENT_MACHINE_KIND_LABELS: Record { - return icon.kind === "icon" && isEnvironmentMachineKind(icon.name) - ? ICON_BY_KIND[icon.name] - : ICON_BY_KIND.server; + return ICON_BY_ID[curatedIconId(icon)]; } export function EnvironmentMachineIcon({ icon, ...props }: LucideProps & { readonly icon: EnvironmentIcon }) { - const Icon = environmentMachineIcon(icon); + const Icon = ICON_BY_ID[curatedIconId(icon)]; return ; } diff --git a/apps/web/src/components/settings/EnvironmentIconPicker.test.ts b/apps/web/src/components/settings/EnvironmentIconPicker.test.ts index 25fd930e3b6bc..ae9f242e2ae53 100644 --- a/apps/web/src/components/settings/EnvironmentIconPicker.test.ts +++ b/apps/web/src/components/settings/EnvironmentIconPicker.test.ts @@ -1,11 +1,20 @@ -import type { ServerConfig } from "@t3tools/contracts"; +import { environmentIconForMachineKind, type ServerConfig } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { resolveEnvironmentIconPickerLock } from "./EnvironmentIconPicker"; +import { + resolveEnvironmentIconChoiceLock, + resolveEnvironmentIconPickerLock, + resolveEnvironmentIconWrite, +} from "./EnvironmentIconPicker"; -const config = (environmentIcon: boolean | undefined) => +const config = (environmentIcon: boolean | undefined, environmentIconOverride?: boolean) => ({ - environment: { capabilities: environmentIcon === undefined ? {} : { environmentIcon } }, + environment: { + capabilities: { + ...(environmentIcon === undefined ? {} : { environmentIcon }), + ...(environmentIconOverride === undefined ? {} : { environmentIconOverride }), + }, + }, }) as unknown as ServerConfig; describe("resolveEnvironmentIconPickerLock", () => { @@ -39,3 +48,40 @@ describe("resolveEnvironmentIconPickerLock", () => { ).toBeNull(); }); }); + +describe("resolveEnvironmentIconWrite", () => { + it("clears the override when the pick matches detection", () => { + expect(resolveEnvironmentIconWrite({ next: "laptop", detected: "laptop" })).toBeNull(); + }); + + it("writes a machine kind as its shared reference", () => { + expect(resolveEnvironmentIconWrite({ next: "laptop", detected: "server" })).toBe( + environmentIconForMachineKind("laptop"), + ); + }); + + it("writes a role as a named icon", () => { + expect(resolveEnvironmentIconWrite({ next: "database", detected: "server" })).toEqual({ + kind: "icon", + name: "database", + }); + }); +}); + +describe("resolveEnvironmentIconChoiceLock", () => { + it("never locks a machine kind, which every server stores as a string", () => { + expect( + resolveEnvironmentIconChoiceLock({ serverConfig: config(true), id: "laptop" }), + ).toBeNull(); + expect(resolveEnvironmentIconChoiceLock({ serverConfig: null, id: "laptop" })).toBeNull(); + }); + + it("locks a role until the server stores the object form", () => { + expect( + resolveEnvironmentIconChoiceLock({ serverConfig: config(true), id: "database" }), + ).toMatch(/Update/); + expect( + resolveEnvironmentIconChoiceLock({ serverConfig: config(true, true), id: "database" }), + ).toBeNull(); + }); +}); diff --git a/apps/web/src/components/settings/EnvironmentIconPicker.tsx b/apps/web/src/components/settings/EnvironmentIconPicker.tsx index 372fdf4a70f40..5426996aa617c 100644 --- a/apps/web/src/components/settings/EnvironmentIconPicker.tsx +++ b/apps/web/src/components/settings/EnvironmentIconPicker.tsx @@ -1,16 +1,22 @@ import { AuthSettingsWriteScope, - ENVIRONMENT_MACHINE_KINDS, + ENVIRONMENT_CURATED_ICON_IDS, environmentIconForMachineKind, + isEnvironmentCuratedIconId, isEnvironmentMachineKind, resolveEnvironmentIcon, + type EnvironmentCuratedIconId, + type EnvironmentIcon, type EnvironmentId, + type EnvironmentMachineKind, type ServerConfig, } from "@t3tools/contracts"; +import { Fragment } from "react"; + import { useUpdateEnvironmentSettings } from "../../hooks/useSettings"; import { useEnvironmentScope } from "../../state/session"; -import { ENVIRONMENT_MACHINE_KIND_LABELS, EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; +import { ENVIRONMENT_ICON_LABELS, EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; import { MenuItem, MenuRadioGroup, @@ -21,6 +27,11 @@ import { MenuSubTrigger, } from "../ui/menu"; +// The curated list starts with the machine kinds; roles follow after a rule. +const ENVIRONMENT_MACHINE_KINDS_COUNT = ENVIRONMENT_CURATED_ICON_IDS.findIndex( + (id) => !isEnvironmentMachineKind(id), +); + /** * Why the picker is inert, in the order the user can do something about it. * Null means it can be changed. @@ -42,7 +53,40 @@ export function resolveEnvironmentIconPickerLock(input: { } /** - * "Icon" submenu for an environment's row menu. Lists the machine kinds with + * What to store for a pick. Picking what the server would draw anyway clears + * the override instead of pinning it, so detection keeps working if the + * machine changes; a machine kind gets the shared reference, so renderers + * memoized on the icon do not repaint for the same pick. + */ +export function resolveEnvironmentIconWrite(input: { + readonly next: EnvironmentCuratedIconId; + readonly detected: EnvironmentMachineKind; +}): EnvironmentIcon | null { + if (input.next === input.detected) return null; + // A plain machine kind encodes to the bare string on the wire, so a server + // that predates the object form accepts it unchanged; a role stays an object. + return isEnvironmentMachineKind(input.next) + ? environmentIconForMachineKind(input.next) + : { kind: "icon", name: input.next }; +} + +/** + * Only the seven machine kinds have a string form an older server accepts; + * a role travels as the object, which such a server rejects. Null means the + * id can be picked. + */ +export function resolveEnvironmentIconChoiceLock(input: { + readonly serverConfig: ServerConfig | null; + readonly id: EnvironmentCuratedIconId; +}): string | null { + if (isEnvironmentMachineKind(input.id)) return null; + return input.serverConfig?.environment.capabilities.environmentIconOverride === true + ? null + : "Update this environment's server to pick an icon beyond its machine kind."; +} + +/** + * "Icon" submenu for an environment's row menu. Lists the curated icons with * the server's own detection marked, so the user can tell whether detection * got it right before overriding. Picking the detected kind clears the * override. Locked environments show the reason as a disabled item instead of @@ -64,9 +108,10 @@ export function EnvironmentIconMenu({ // kind clears the override the same way picking the detected kind does. const detected = serverConfig?.environment.platform.machine ?? "server"; const resolved = resolveEnvironmentIcon(serverConfig); - // The radio list only knows the seven kinds; a richer pick checks nothing. - const resolvedKind = - resolved.kind === "icon" && isEnvironmentMachineKind(resolved.name) ? resolved.name : null; + // The radio list only knows the curated ids; a richer pick checks nothing. + const resolvedId = + resolved.kind === "icon" && isEnvironmentCuratedIconId(resolved.name) ? resolved.name : null; + const roleLock = lock ?? resolveEnvironmentIconChoiceLock({ serverConfig, id: "terminal" }); return ( @@ -84,33 +129,50 @@ export function EnvironmentIconMenu({ ) : null} { - if (lock !== null || !isEnvironmentMachineKind(next)) return; - // A plain machine kind encodes to the bare string on the wire, so a - // server that predates the object form accepts this unchanged. - updateSettings({ - environmentIcon: next === detected ? null : { kind: "icon", name: next }, - }); + if (!isEnvironmentCuratedIconId(next)) return; + if (resolveEnvironmentIconChoiceLock({ serverConfig, id: next }) !== null) return; + if (lock !== null) return; + updateSettings({ environmentIcon: resolveEnvironmentIconWrite({ next, detected }) }); }} > - {ENVIRONMENT_MACHINE_KINDS.map((kind) => ( - - - - - {ENVIRONMENT_MACHINE_KIND_LABELS[kind]} + {ENVIRONMENT_CURATED_ICON_IDS.map((id, index) => ( + + {index === ENVIRONMENT_MACHINE_KINDS_COUNT ? ( + <> + + {lock === null && roleLock !== null ? ( + + {roleLock} + + ) : null} + + ) : null} + + + + {ENVIRONMENT_ICON_LABELS[id]} + {id === detected ? ( + + {serverConfig?.environment.platform.machine ? "detected" : "default"} + + ) : null} - {kind === detected ? ( - - {serverConfig?.environment.platform.machine ? "detected" : "default"} - - ) : null} - - + + ))} diff --git a/packages/contracts/src/environment.ts b/packages/contracts/src/environment.ts index 9ffc7131ad12d..8ace7a6e4671d 100644 --- a/packages/contracts/src/environment.ts +++ b/packages/contracts/src/environment.ts @@ -70,6 +70,28 @@ export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS) export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type; export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind); +/** + * Named glyphs every client draws: the machine kinds a server can detect, + * plus roles a machine is given but never detected as. Both renderers hold an + * exhaustive map over this list, so a new id fails typecheck until each + * surface can draw it. Only the machine kinds have a bare-string form on the + * wire; a role always travels as the object, which is why picking one needs + * the `environmentIconOverride` capability. + */ +export const ENVIRONMENT_CURATED_ICON_IDS = [ + ...ENVIRONMENT_MACHINE_KINDS, + "terminal", + "database", + "container", + "globe", + "home", + "gpu", + "network", +] as const; +export const EnvironmentCuratedIconId = Schema.Literals(ENVIRONMENT_CURATED_ICON_IDS); +export type EnvironmentCuratedIconId = typeof EnvironmentCuratedIconId.Type; +export const isEnvironmentCuratedIconId = Schema.is(EnvironmentCuratedIconId); + const EnvironmentNamedIcon = Schema.Struct({ kind: Schema.Literal("icon"), // A curated id or a Lucide id. Renderers try the curated map first, so the From 60b930e338ec70afe27fb5ed24270e2dfc66279a Mon Sep 17 00:00:00 2001 From: amanthanvi Date: Tue, 22 Sep 2026 01:31:30 -0400 Subject: [PATCH 2/3] refactor(contracts): one label per curated icon id Web and mobile each held a byte-identical `ENVIRONMENT_ICON_LABELS` map, and this layer grew both from seven entries to fourteen. Typecheck catches a missing key on either side but not two keys that say different things, so the labels move next to the id list they are exhaustive over. `settings.ts` already keeps display strings in a record keyed by a schema literal. Model: Claude Opus 5 via T3 Code. --- .../components/EnvironmentMachineSymbol.tsx | 18 +-------------- .../src/components/EnvironmentMachineIcon.tsx | 17 -------------- .../settings/EnvironmentIconPicker.tsx | 3 ++- packages/contracts/src/environment.ts | 23 +++++++++++++++++++ 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/apps/mobile/src/components/EnvironmentMachineSymbol.tsx b/apps/mobile/src/components/EnvironmentMachineSymbol.tsx index aaaffd22ce267..1ce2b02d92975 100644 --- a/apps/mobile/src/components/EnvironmentMachineSymbol.tsx +++ b/apps/mobile/src/components/EnvironmentMachineSymbol.tsx @@ -1,4 +1,5 @@ import { + ENVIRONMENT_ICON_LABELS, isEnvironmentCuratedIconId, type EnvironmentCuratedIconId, type EnvironmentIcon, @@ -25,23 +26,6 @@ const SYMBOL_BY_ID = { network: "point.3.connected.trianglepath.dotted", } as const satisfies Record; -export const ENVIRONMENT_ICON_LABELS: Record = { - server: "Server", - cloud: "Cloud VM", - linux: "Linux/WSL", - desktop: "Desktop", - laptop: "Laptop", - "mac-mini": "Mini PC", - "mac-studio": "Workstation", - terminal: "Dev box", - database: "Database", - container: "Container", - globe: "Edge", - home: "Home server", - gpu: "GPU box", - network: "Network", -}; - /** * The curated id an icon draws as. A name this build cannot draw (picked on * a newer client) gets the generic server so the row still reads as a diff --git a/apps/web/src/components/EnvironmentMachineIcon.tsx b/apps/web/src/components/EnvironmentMachineIcon.tsx index e060bccd2edfa..5e8d737fa7703 100644 --- a/apps/web/src/components/EnvironmentMachineIcon.tsx +++ b/apps/web/src/components/EnvironmentMachineIcon.tsx @@ -77,23 +77,6 @@ const ICON_BY_ID: Record = { - server: "Server", - cloud: "Cloud VM", - linux: "Linux/WSL", - desktop: "Desktop", - laptop: "Laptop", - "mac-mini": "Mini PC", - "mac-studio": "Workstation", - terminal: "Dev box", - database: "Database", - container: "Container", - globe: "Edge", - home: "Home server", - gpu: "GPU box", - network: "Network", -}; - /** * Which curated glyph draws a named icon. A name this build cannot draw * (picked on a newer client) gets the generic server so the row still reads diff --git a/apps/web/src/components/settings/EnvironmentIconPicker.tsx b/apps/web/src/components/settings/EnvironmentIconPicker.tsx index 5426996aa617c..2b631f3840360 100644 --- a/apps/web/src/components/settings/EnvironmentIconPicker.tsx +++ b/apps/web/src/components/settings/EnvironmentIconPicker.tsx @@ -1,6 +1,7 @@ import { AuthSettingsWriteScope, ENVIRONMENT_CURATED_ICON_IDS, + ENVIRONMENT_ICON_LABELS, environmentIconForMachineKind, isEnvironmentCuratedIconId, isEnvironmentMachineKind, @@ -16,7 +17,7 @@ import { Fragment } from "react"; import { useUpdateEnvironmentSettings } from "../../hooks/useSettings"; import { useEnvironmentScope } from "../../state/session"; -import { ENVIRONMENT_ICON_LABELS, EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; +import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; import { MenuItem, MenuRadioGroup, diff --git a/packages/contracts/src/environment.ts b/packages/contracts/src/environment.ts index 8ace7a6e4671d..902c7747952db 100644 --- a/packages/contracts/src/environment.ts +++ b/packages/contracts/src/environment.ts @@ -92,6 +92,29 @@ export const EnvironmentCuratedIconId = Schema.Literals(ENVIRONMENT_CURATED_ICON export type EnvironmentCuratedIconId = typeof EnvironmentCuratedIconId.Type; export const isEnvironmentCuratedIconId = Schema.is(EnvironmentCuratedIconId); +/** + * What each curated glyph is called in a picker and in an accessibility + * label. Web and mobile draw different glyph sets for the same id, so the + * name is the one thing both surfaces must agree on, and typecheck only + * catches a missing entry rather than two that drifted apart. + */ +export const ENVIRONMENT_ICON_LABELS: Record = { + server: "Server", + cloud: "Cloud VM", + linux: "Linux/WSL", + desktop: "Desktop", + laptop: "Laptop", + "mac-mini": "Mini PC", + "mac-studio": "Workstation", + terminal: "Dev box", + database: "Database", + container: "Container", + globe: "Edge", + home: "Home server", + gpu: "GPU box", + network: "Network", +}; + const EnvironmentNamedIcon = Schema.Struct({ kind: Schema.Literal("icon"), // A curated id or a Lucide id. Renderers try the curated map first, so the From 887d7520aa3fde84c2bf24914ade3c0901d70c06 Mon Sep 17 00:00:00 2001 From: amanthanvi Date: Wed, 23 Sep 2026 10:38:54 -0400 Subject: [PATCH 3/3] fix(web): the icon submenu draws its lock row once The submenu shows why a pick is unavailable as a disabled `MenuItem` that wraps its text. The role section earlier in this branch added a second copy of that row, so one `IconLockNotice` component now covers both, and a change to how the reason reads lands in one place. --- .../settings/EnvironmentIconPicker.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/settings/EnvironmentIconPicker.tsx b/apps/web/src/components/settings/EnvironmentIconPicker.tsx index 2b631f3840360..5c9e112a3706a 100644 --- a/apps/web/src/components/settings/EnvironmentIconPicker.tsx +++ b/apps/web/src/components/settings/EnvironmentIconPicker.tsx @@ -86,6 +86,18 @@ export function resolveEnvironmentIconChoiceLock(input: { : "Update this environment's server to pick an icon beyond its machine kind."; } +/** + * Why a pick is unavailable, shown as a disabled row so the list still reads. + * Both the whole-submenu lock and the role-section lock render one of these. + */ +function IconLockNotice({ reason }: { readonly reason: string }) { + return ( + + {reason} + + ); +} + /** * "Icon" submenu for an environment's row menu. Lists the curated icons with * the server's own detection marked, so the user can tell whether detection @@ -123,9 +135,7 @@ export function EnvironmentIconMenu({ {lock !== null ? ( <> - - {lock} - + ) : null} @@ -143,11 +153,7 @@ export function EnvironmentIconMenu({ {index === ENVIRONMENT_MACHINE_KINDS_COUNT ? ( <> - {lock === null && roleLock !== null ? ( - - {roleLock} - - ) : null} + {lock === null && roleLock !== null ? : null} ) : null}