Skip to content

Commit ca9f250

Browse files
Julius Marmingeclaude
andcommitted
fix(web): lock the environment icon picker when it cannot save
The picker was live on every connected environment, including servers that predate the setting (which drop the key on write) and sessions without the operate scope. It now stays visible so the current icon still reads, but goes inert with a tooltip in those cases, gated the same way the provider settings are: a new environmentIcon capability on the descriptor, plus the session's scopes for that environment. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent de920ea commit ca9f250

4 files changed

Lines changed: 129 additions & 3 deletions

File tree

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export const make = Effect.gen(function* () {
225225
threadPinReorder: true,
226226
threadTitleRegeneration: true,
227227
threadPullRequestLinking: true,
228+
environmentIcon: true,
228229
...(serverSelfUpdate === null ? {} : { serverSelfUpdate }),
229230
...(serverSelfUpdate === "boot-service" || desktopAppUpdate
230231
? {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { ServerConfig } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { resolveEnvironmentIconPickerLock } from "./EnvironmentIconPicker";
5+
6+
const config = (environmentIcon: boolean | undefined) =>
7+
({
8+
environment: { capabilities: environmentIcon === undefined ? {} : { environmentIcon } },
9+
}) as unknown as ServerConfig;
10+
11+
describe("resolveEnvironmentIconPickerLock", () => {
12+
it("locks until the environment is connected", () => {
13+
expect(
14+
resolveEnvironmentIconPickerLock({ serverConfig: null, operateAccess: "granted" }),
15+
).toMatch(/Connect/);
16+
});
17+
18+
it("locks on servers that predate the setting, before looking at permissions", () => {
19+
expect(
20+
resolveEnvironmentIconPickerLock({
21+
serverConfig: config(undefined),
22+
operateAccess: "denied",
23+
}),
24+
).toMatch(/too old/);
25+
});
26+
27+
it("locks when the session cannot operate the environment", () => {
28+
expect(
29+
resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "denied" }),
30+
).toMatch(/cannot change/);
31+
});
32+
33+
it("stays open while access is still resolving so a slow session does not flicker", () => {
34+
expect(
35+
resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "pending" }),
36+
).toBeNull();
37+
expect(
38+
resolveEnvironmentIconPickerLock({ serverConfig: config(true), operateAccess: "granted" }),
39+
).toBeNull();
40+
});
41+
});

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

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,73 @@ import {
77
} from "@t3tools/contracts";
88
import { useCallback } from "react";
99

10+
import { isElectron } from "../../env";
11+
import { usePrimarySessionState } from "../../environments/primary";
1012
import { useUpdateEnvironmentSettings } from "../../hooks/useSettings";
13+
import { usePrimaryEnvironmentId } from "../../state/environments";
14+
import { useEnvironmentSessionState } from "../../state/session";
1115
import { ENVIRONMENT_MACHINE_KIND_LABELS, EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
1216
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
17+
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
18+
import {
19+
resolvePrimaryOperateAccess,
20+
resolveRemoteOperateAccess,
21+
} from "./ProviderSettingsPanel.logic";
1322

1423
const AUTOMATIC_VALUE = "automatic";
1524

25+
/**
26+
* Why the picker is inert, in the order the user can do something about it.
27+
* Null means it can be changed.
28+
*/
29+
export function resolveEnvironmentIconPickerLock(input: {
30+
readonly serverConfig: ServerConfig | null;
31+
readonly operateAccess: "granted" | "denied" | "pending";
32+
}): string | null {
33+
if (input.serverConfig === null) {
34+
return "Connect to this environment to change its icon.";
35+
}
36+
if (input.serverConfig.environment.capabilities.environmentIcon !== true) {
37+
return "This environment's server is too old to keep an icon. Update it to choose one.";
38+
}
39+
if (input.operateAccess === "denied") {
40+
return "Your session on this environment cannot change its settings.";
41+
}
42+
return null;
43+
}
44+
45+
// Same split the provider settings use: the desktop app owns its primary
46+
// server outright, a browser session on the primary checks its cookie
47+
// session's scopes, and a remote checks the scopes its own server reports.
48+
function useEnvironmentOperateAccess(environmentId: EnvironmentId) {
49+
const isPrimary = usePrimaryEnvironmentId() === environmentId;
50+
const primarySession = usePrimarySessionState();
51+
const remoteSession = useEnvironmentSessionState(environmentId);
52+
if (isPrimary) {
53+
return isElectron
54+
? "granted"
55+
: resolvePrimaryOperateAccess({
56+
isPrimary: true,
57+
hasDesktopBridge: false,
58+
session: primarySession.data,
59+
isPending: primarySession.isPending,
60+
hasError: primarySession.error !== null,
61+
});
62+
}
63+
return resolveRemoteOperateAccess({
64+
session: remoteSession.data,
65+
isPending: remoteSession.isPending,
66+
hasError: remoteSession.hasError,
67+
});
68+
}
69+
1670
/**
1771
* Picks the machine glyph an environment wears everywhere it is listed.
1872
* "Automatic" clears the override so the server's own detection shows
1973
* through; the label says what that currently resolves to so the user can
20-
* tell whether detection got it right before overriding.
74+
* tell whether detection got it right before overriding. The control stays
75+
* visible while locked so the current icon still reads, the same way
76+
* server-scoped rows go inert instead of disappearing.
2177
*/
2278
export function EnvironmentIconPicker({
2379
environmentId,
@@ -29,6 +85,8 @@ export function EnvironmentIconPicker({
2985
readonly size?: "xs" | "sm";
3086
}) {
3187
const updateSettings = useUpdateEnvironmentSettings(environmentId);
88+
const operateAccess = useEnvironmentOperateAccess(environmentId);
89+
const lock = resolveEnvironmentIconPickerLock({ serverConfig, operateAccess });
3290
const override = serverConfig?.settings.environmentIcon ?? null;
3391
const detected = serverConfig?.environment.platform.machine ?? null;
3492
const resolved = resolveEnvironmentMachineKind(serverConfig);
@@ -48,8 +106,8 @@ export function EnvironmentIconPicker({
48106
[updateSettings],
49107
);
50108

51-
return (
52-
<Select value={value} onValueChange={handleValueChange} disabled={serverConfig === null}>
109+
const select = (
110+
<Select value={value} onValueChange={handleValueChange} disabled={lock !== null}>
53111
<SelectTrigger size={size} className="w-full sm:w-52" aria-label="Environment icon">
54112
<SelectValue>
55113
<span className="flex min-w-0 items-center gap-2">
@@ -78,4 +136,26 @@ export function EnvironmentIconPicker({
78136
</SelectPopup>
79137
</Select>
80138
);
139+
140+
if (lock === null) {
141+
return select;
142+
}
143+
return (
144+
<Tooltip>
145+
<TooltipTrigger
146+
render={
147+
// Focusable so keyboard users can still reach the explanation.
148+
<span
149+
tabIndex={0}
150+
className="flex w-full items-center rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring sm:w-auto"
151+
/>
152+
}
153+
>
154+
<span className="flex w-full items-center sm:w-auto">{select}</span>
155+
</TooltipTrigger>
156+
<TooltipPopup side="top" className="max-w-72">
157+
{lock}
158+
</TooltipPopup>
159+
</Tooltip>
160+
);
81161
}

‎packages/contracts/src/environment.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
129129
this is false — no update would ever repaint it. Absent on older
130130
servers, which may still publish, so only an explicit false skips. */
131131
agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
132+
/** Server detects `platform.machine` and persists the `environmentIcon`
133+
setting. Older servers drop the key on write, so clients show the
134+
picker inert rather than offering a choice that would never stick. */
135+
environmentIcon: Schema.optionalKey(Schema.Boolean),
132136
/** The desktop app supervising this server can be driven over RPC:
133137
server.updateServer runs its check -> download -> relaunch. Absent on
134138
desktop servers whose app predates the remote trigger, where clients

0 commit comments

Comments
 (0)