Skip to content

Commit a4c01c1

Browse files
authored
feat(ui): save appearance preferences per user profile (#130340)
* feat(ui): save appearance preferences per user profile When a Control UI connection is bound to an authenticated user profile (trusted-proxy, Tailscale, GitHub identity), theme, theme mode, and accent become per-profile: stored in the existing user_preferences KV store via users.prefs.set, overriding gateway-wide ui.prefs, with live cross-device updates over a new additive users.prefs.changed event scoped to the same merged profile. Restore default deletes only the profile key and falls back to the gateway-wide value. talk.config projects the caller's profile accent for native clients. Profile-less connections (token/password/none auth) keep the existing gateway-config behavior byte-identically. Release-note context: on multi-person gateways appearance choices are now personal and follow you across devices; an admin restyling their own UI no longer reskins the whole team. * chore(protocol): allowlist users.prefs.changed for mobile clients iOS and Android resolve the profile accent through talk.config on connect and config refresh; live per-profile appearance push on natives is a named follow-up. * chore(protocol): regenerate Swift/Kotlin models for users.prefs.changed * fix(ui): honor explicit defaults and identity switches for profile appearance Addresses the three ClawSweeper review findings: - resetValue for profile-bound appearance keys is the deletion fallback (gateway value), so an explicit product-default selection persists as a profile write instead of being misclassified as a reset. - An identity switch between two known scopes forces a full appearance reconcile and clears appearance keys the returning identity never set, so a shared browser cannot keep the previous profile's look (boot keeps the last-seen shortcut). - talk.config joins the profile-dependent dispatch gate so a pending GitHub identity sync completes before the profile accent is projected; token clients pass through untouched. * chore(ui): satisfy assertion-safety ratchet and docs formatting * refactor(ui): extract server-prefs storage primitives server-prefs.ts crossed the 700-line cap after the review fixes; the stateless localStorage persistence primitives move to server-prefs-storage.ts (no behavior change). Shrink-prunes the assertion-safety baseline for the moved casts. * fix(ui): keep imported custom themes out of profile storage Custom palettes are browser-local by contract, so a profile must never carry theme=custom to a browser that cannot render it. The wire contract drops custom from the storable theme values (readers self-heal any stored value), a profile-bound custom selection stays retained browser-local (including the offline-queued path), and the exhaustive theme test now encodes the exception.
1 parent e9dc4b9 commit a4c01c1

36 files changed

Lines changed: 1457 additions & 189 deletions

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ enum class GatewayEvent(
821821
DevicePairResolved("device.pair.resolved"),
822822
DevicePairSetupCompleted("device.pair.setup.completed"),
823823
DevicePairSetupDeliveryUncertain("device.pair.setup.deliveryUncertain"),
824+
UsersPrefsChanged("users.prefs.changed"),
824825
SkillsChanged("skills.changed"),
825826
VoicewakeChanged("voicewake.changed"),
826827
VoicewakeRoutingChanged("voicewake.routing.changed"),

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11255,6 +11255,24 @@ public struct AuditListResult: Codable, Sendable {
1125511255
}
1125611256
}
1125711257

11258+
public struct UsersPrefsChangedEvent: Codable, Sendable {
11259+
public let profileid: String
11260+
public let keys: [String]
11261+
11262+
public init(
11263+
profileid: String,
11264+
keys: [String])
11265+
{
11266+
self.profileid = profileid
11267+
self.keys = keys
11268+
}
11269+
11270+
private enum CodingKeys: String, CodingKey {
11271+
case profileid = "profileId"
11272+
case keys
11273+
}
11274+
}
11275+
1125811276
public struct TaskSuggestion: Codable, Sendable {
1125911277
public let id: String
1126011278
public let title: String

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3949,7 +3949,7 @@ ui/src/app/native-window-drag.ts 1
39493949
ui/src/app/overlays.ts 1
39503950
ui/src/app/question-prompt.ts 2
39513951
ui/src/app/server-prefs-state.ts 14
3952-
ui/src/app/server-prefs.ts 17
3952+
ui/src/app/server-prefs.ts 15
39533953
ui/src/app/settings.ts 9
39543954
ui/src/app/stale-chunk-reload.ts 1
39553955
ui/src/app/startup-settings.ts 1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"startupJsGzipBytes": 341333,
3-
"reason": "Tide, Beacon, and Phosphor themes: theme-name wiring, three appearance options, locale strings, and two font stylesheet mappings",
2+
"startupJsGzipBytes": 342930,
3+
"reason": "per-profile appearance preferences: profile-scoped resolution, users.prefs routing, and live cross-device sync on the boot path; measured 342875 B on the tide/beacon/phosphor base, pinned with jitter headroom",
44
"updatedAt": "2026-08-26"
55
}

‎docs/concepts/user-model.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ OpenClaw supplies exact trailers and the ordered contributor list in the model c
3030

3131
Turning **Git co-author credit** off stops attribution for future runs. It does not rewrite commits that already contain the public trailer.
3232

33+
## Profile appearance preferences
34+
35+
When a Control UI connection is bound to an authenticated Gateway profile, its theme, theme mode, and accent color are stored per profile in the existing `user_preferences` table in the shared state database. Those choices follow that person across devices without changing appearance for other people on the same Gateway.
36+
37+
Profile theme and theme mode preferences override their gateway-wide `ui.prefs` settings and otherwise fall back to the active theme's defaults. The imported custom theme is the exception: its palette lives only in the browser that imported it, so selecting it stays browser-local and never follows the profile. Accent precedence is the profile's `ui.accent` preference, gateway-wide `ui.prefs.accent`, `ui.seamColor`, and finally the active theme's default accent. Restoring a default clears only the profile preference. Connections without an authenticated profile, including token, password, or unauthenticated connections, keep the existing gateway-wide appearance behavior unchanged. Language, chat preferences, and sidebar entries continue using gateway configuration.
38+
3339
## Write directives, not observations
3440

3541
Each entry has a metadata line followed by one imperative directive:

‎docs/web/control-ui.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ The Appearance panel has the built-in Claw, Knot, Dash, Absolutely, Tide, Beacon
153153

154154
Imported themes are stored only in the current browser profile; they are not written to gateway config and do not sync across devices. Replacing the imported theme updates the one local slot; clearing it switches back to Claw if the imported theme was active.
155155

156-
Choose an **Accent color** preset or custom color in Appearance to override the active theme's accent. This preference takes precedence over the operator-configured `ui.seamColor`. **Restore default** clears the preference and restores `ui.seamColor` when configured, or the theme's own accent otherwise.
156+
Choose an **Accent color** preset or custom color in Appearance to override the active theme's accent. For an authenticated Gateway profile, the accent precedence is the profile's `ui.accent` preference, the gateway-wide `ui.prefs.accent` setting, the operator-configured `ui.seamColor`, and finally the active theme's default. **Restore default** clears only that profile's preference, leaving the gateway-wide settings unchanged. Connections without an authenticated profile keep the existing gateway-wide preference behavior.
157157

158158
Appearance also has a Text size setting. It applies to chat text, composer text, tool cards, and chat sidebars, and keeps text inputs at least 16px so mobile Safari does not auto-zoom on focus.
159159

160-
Theme, theme mode, accent color, language, and chat display preferences sync through the gateway config (`ui.prefs`), so they follow you across devices and agents can change them through the approval gate — connected clients apply changes live via the gateway's `config.changed` notice. Each browser keeps a local mirror for instant boot. Text size remains browser-local. An explicitly read-only connection applies preference changes only in that browser and does not attempt a config write. Changes made while offline remain queued until a later connection can write config; on a read-only reconnect, they continue to behave as browser-local preferences. See [Configuration reference](/gateway/configuration-reference#ui).
160+
When your connection is bound to an authenticated Gateway profile, theme, theme mode, and accent color are saved to that profile instead of the gateway config. They follow you across devices without changing anyone else's appearance, override gateway-wide `ui.prefs` values, and update your connected clients live. Connections without an authenticated profile continue syncing these preferences through the gateway config exactly as before. Language and chat display preferences remain gateway-config preferences for every connection. Each browser keeps a local mirror for instant boot, and text size remains browser-local. An explicitly read-only connection applies preference changes only in that browser. Changes made while offline remain queued until a later connection can write their applicable preferences; on a read-only reconnect, they continue to behave as browser-local preferences. See [Configuration reference](/gateway/configuration-reference#ui).
161161

162162
## OpenClaw system care
163163

‎packages/gateway-protocol/src/public-schema.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,16 @@ export {
331331
AuditListParamsSchema,
332332
AuditListResultSchema,
333333
GIT_COAUTHOR_PREFERENCE_KEY,
334+
normalizeUiAppearancePreference,
335+
UI_APPEARANCE_PREFERENCE_KEYS,
334336
UserProfileSchema,
335337
UsersLinkEmailParamsSchema,
336338
UsersLinkEmailResultSchema,
337339
UsersListParamsSchema,
338340
UsersListResultSchema,
339341
UsersPrefsGetParamsSchema,
340342
UsersPrefsGetResultSchema,
343+
UsersPrefsChangedEventSchema,
341344
UsersPrefsSetParamsSchema,
342345
UsersPrefsSetResultSchema,
343346
UsersSelfParamsSchema,

‎packages/gateway-protocol/src/schema/protocol-schema-fragment-operations.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as config from "./config.js";
55
import * as openclaw from "./openclaw.js";
66
import * as taskSuggestions from "./task-suggestions.js";
77
import * as tasks from "./tasks.js";
8+
import * as users from "./users.js";
89
import * as wizard from "./wizard.js";
910

1011
export const OperationsProtocolSchemas = {
@@ -28,6 +29,7 @@ export const OperationsProtocolSchemas = {
2829
AuditEvent: audit.AuditEventSchema,
2930
AuditListParams: audit.AuditListParamsSchema,
3031
AuditListResult: audit.AuditListResultSchema,
32+
UsersPrefsChangedEvent: users.UsersPrefsChangedEventSchema,
3133
TaskSuggestion: taskSuggestions.TaskSuggestionSchema,
3234
TaskSuggestionEvent: taskSuggestions.TaskSuggestionEventSchema,
3335
TaskSuggestionResolution: taskSuggestions.TaskSuggestionResolutionSchema,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export const UI_APPEARANCE_PREFERENCE_KEYS = {
2+
theme: "ui.theme",
3+
themeMode: "ui.themeMode",
4+
accent: "ui.accent",
5+
} as const;
6+
7+
export type UiAppearancePreferenceKey =
8+
(typeof UI_APPEARANCE_PREFERENCE_KEYS)[keyof typeof UI_APPEARANCE_PREFERENCE_KEYS];
9+
10+
// Wire-contract list of profile-storable theme names. The Control UI derives
11+
// its synced-theme handling from this tuple; a theme shipped in the UI but
12+
// missing here would silently drop that profile preference on read.
13+
// "custom" is deliberately absent: imported palettes are browser-local, so a
14+
// custom selection must never follow the profile to a browser that cannot
15+
// render it — it stays device-local instead.
16+
export const UI_APPEARANCE_THEME_VALUES = [
17+
"claw",
18+
"knot",
19+
"dash",
20+
"absolutely",
21+
"tide",
22+
"beacon",
23+
"phosphor",
24+
] as const;
25+
const UI_APPEARANCE_THEMES = new Set<string>(UI_APPEARANCE_THEME_VALUES);
26+
const UI_APPEARANCE_THEME_MODES = new Set(["light", "dark", "system"]);
27+
28+
export function normalizeUiAppearancePreference(
29+
key: UiAppearancePreferenceKey,
30+
value: unknown,
31+
): string | undefined {
32+
if (typeof value !== "string") {
33+
return undefined;
34+
}
35+
if (key === UI_APPEARANCE_PREFERENCE_KEYS.accent) {
36+
return /^#[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : undefined;
37+
}
38+
const allowedValues =
39+
key === UI_APPEARANCE_PREFERENCE_KEYS.theme ? UI_APPEARANCE_THEMES : UI_APPEARANCE_THEME_MODES;
40+
return allowedValues.has(value) ? value : undefined;
41+
}

‎packages/gateway-protocol/src/schema/users-prefs.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { describe, expect, it } from "vitest";
33
import {
44
GatewayErrorDetailCodes,
55
GatewayErrorDetailsSchema,
6+
normalizeUiAppearancePreference,
7+
UI_APPEARANCE_PREFERENCE_KEYS,
68
UserPrefsLimitExceededErrorDetailsSchema,
79
UserProfileSchema,
10+
UsersPrefsChangedEventSchema,
811
UsersPrefsGetResultSchema,
912
UsersPrefsSetResultSchema,
1013
validateUsersPrefsGetParams,
@@ -13,6 +16,45 @@ import {
1316
} from "../index.js";
1417

1518
describe("user preference protocol schemas", () => {
19+
it("normalizes only supported profile appearance values and canonicalizes accent colors", () => {
20+
expect(normalizeUiAppearancePreference(UI_APPEARANCE_PREFERENCE_KEYS.theme, "absolutely")).toBe(
21+
"absolutely",
22+
);
23+
expect(normalizeUiAppearancePreference(UI_APPEARANCE_PREFERENCE_KEYS.themeMode, "system")).toBe(
24+
"system",
25+
);
26+
expect(normalizeUiAppearancePreference(UI_APPEARANCE_PREFERENCE_KEYS.accent, "#A1b2C3")).toBe(
27+
"#a1b2c3",
28+
);
29+
30+
for (const [key, value] of [
31+
[UI_APPEARANCE_PREFERENCE_KEYS.theme, "unsupported"],
32+
[UI_APPEARANCE_PREFERENCE_KEYS.themeMode, "automatic"],
33+
[UI_APPEARANCE_PREFERENCE_KEYS.accent, "#abc"],
34+
[UI_APPEARANCE_PREFERENCE_KEYS.accent, "#12345g"],
35+
[UI_APPEARANCE_PREFERENCE_KEYS.accent, { color: "#123456" }],
36+
[UI_APPEARANCE_PREFERENCE_KEYS.theme, 42],
37+
] as const) {
38+
expect(normalizeUiAppearancePreference(key, value)).toBeUndefined();
39+
}
40+
});
41+
42+
it("bounds profile preference change events to their owning profile and written keys", () => {
43+
expect(
44+
Value.Check(UsersPrefsChangedEventSchema, {
45+
profileId: "profile-1",
46+
keys: [UI_APPEARANCE_PREFERENCE_KEYS.accent],
47+
}),
48+
).toBe(true);
49+
expect(Value.Check(UsersPrefsChangedEventSchema, { profileId: "", keys: [] })).toBe(false);
50+
expect(
51+
Value.Check(UsersPrefsChangedEventSchema, {
52+
profileId: "profile-1",
53+
keys: Array.from({ length: 33 }, (_, index) => `key-${index}`),
54+
}),
55+
).toBe(false);
56+
});
57+
1658
it("bounds self-scoped preference requests", () => {
1759
const entries = Object.fromEntries(
1860
Array.from({ length: 32 }, (_, index) => [`key-${index}`, { index }]),

0 commit comments

Comments
 (0)