The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(theme): allow an empty colour map, and require string token values\n\nTwo review findings, both correct. The first reverses a decision I argued for\nin the original commit and got wrong.\n\n**Empty `{}` is now ACCEPTED (chatgpt-codex).** I had rejected it, reasoning\nthat a zero-token theme applies nothing and is therefore as broken as `null`.\nThat reasoning was wrong, and the counter-example is in this repo:\n`CLASSIC_LIGHT` and `CLASSIC_DARK` both carry `colors: {}` deliberately\n(`lib/theme/presets.ts:63-78`). They inherit the base stylesheet tokens and\ncarry their meaning in `isDark`, which `applyTheme` applies independently of any\ncolour (`providers/ThemeProvider.tsx:48-50`). And `exportJson` serialises the\neffective theme, so with Classic active the panel's own Export box emits\n`colors: {}` — which my check then refused on Import, breaking the panel's\nexport -> import round trip for the two most common themes, and refusing\nlegitimate font-, gradient- or backdrop-only themes with it.\n\nThe actual #5901 defect is unchanged and still fixed: `null` and arrays are\nmalformed and are rejected, because `typeof null === 'object'` and\n`typeof [] === 'object'` let both past the old check and `{ ...null }` yields\n`{}` silently.\n\n**Token values must now be strings (CodeRabbit).** The predicate claimed\n`Record<string, string>` while only checking the container, so\n`{"surface": 42}` was accepted and stored. `swatchChannels` falls back only on\nnull/undefined (`??`), so a non-string reaches `channelsToCss`, which calls\n`.trim()` on it and throws — crashing the panel on a theme already in the store.\n\nRenamed `hasColorTokens` -> `isValidColorMap`, since after the first change the\npredicate is about validity, not emptiness.\n\nVerified locally, all through the fleet CI semaphore:\n- `ThemeStudioPanel.test.tsx` 14/14 pass; `tsc --noEmit` exit 0, 0 errors.\n- Revert-proof, string values: replacing the value check with `return true`\n fails exactly the 4 non-string cases.\n- Revert-proof, container: dropping the null/array guard fails the array case.\n Null still rejects, but only incidentally — `Object.values(null)` throws into\n the outer catch. The explicit guard makes that rejection intentional rather\n than an exception caught by a broad handler, which is why it stays.\n\n## Related\nRefs #5901\n
M3gA-Mind7973dace0723
diff --git a/app/src/components/settings/panels/ThemeStudioPanel.test.tsx b/app/src/components/settings/panels/ThemeStudioPanel.test.tsxindex 46a84719a3..95a612b726 100644--- a/app/src/components/settings/panels/ThemeStudioPanel.test.tsx+++ b/app/src/components/settings/panels/ThemeStudioPanel.test.tsx@@ -82,15 +82,21 @@ describe('<ThemeStudioPanel />', () => {// #5901: `typeof null === 'object'` and `typeof [] === 'object'`, so the old// shape check let both through; `{ ...null }` and `{ ...[] }` each yield `{}`,- // and a zero-token theme was stored and could be activated from the gallery.- // `{}` is refused for the same reason — `applyTheme` writes one custom- // property per token, so a colourless theme applies nothing at all.+ // and a malformed paste was stored as a theme.+ //+ // A non-string token value is rejected for a different reason: `swatchChannels`+ // falls back only on null/undefined, so `{"surface": 42}` reaches+ // `channelsToCss`, which calls `.trim()` and throws — crashing the panel on a+ // theme already in the store.it.each([['null colors', null],['an array of colors', []],- ['an empty colors object', {}],['a string colors value', 'surface'],['a numeric colors value', 42],+ ['a numeric token value', { surface: 42 }],+ ['a null token value', { surface: null }],+ ['an object token value', { surface: {} }],+ ['one bad value among good ones', { surface: '1 2 3', content: 7 }],])('refuses to import a theme with %s', (_label, colors) => {const { store } = renderWithProviders(<ThemeStudioPanel />, {preloadedState: { theme: themeState },@@ -98,7 +104,7 @@ describe('<ThemeStudioPanel />', () => {});fireEvent.change(screen.getByLabelText('Import theme'), {- target: { value: JSON.stringify({ name: 'Colourless', isDark: false, colors }) },+ target: { value: JSON.stringify({ name: 'Malformed', isDark: false, colors }) },});fireEvent.click(screen.getByRole('button', { name: 'Import' }));@@ -125,4 +131,31 @@ describe('<ThemeStudioPanel />', () => {colors: { surface: '1 2 3' },});});++ // An empty colour map is VALID, not malformed. CLASSIC_LIGHT and CLASSIC_DARK+ // both carry `colors: {}` (presets.ts:63-78) and mean it — they inherit the+ // base tokens and express themselves through `isDark`. The panel's export+ // serialises the effective theme, so rejecting `{}` would break its own+ // export -> import round trip for the two most common themes.+ it('imports a theme with an empty colour map, preserving isDark', () => {+ const { store } = renderWithProviders(<ThemeStudioPanel />, {+ preloadedState: { theme: themeState },+ initialEntries: ['/settings/theme'],+ });++ fireEvent.change(screen.getByLabelText('Import theme'), {+ target: {+ value: JSON.stringify({ name: 'Inherits base', isDark: true, colors: {}, fonts: {} }),+ },+ });+ fireEvent.click(screen.getByRole('button', { name: 'Import' }));++ expect(screen.queryByText('Could not parse that theme JSON.')).not.toBeInTheDocument();+ expect(store.getState().theme.customThemes).toHaveLength(1);+ expect(store.getState().theme.customThemes[0]).toMatchObject({+ name: 'Inherits base',+ isDark: true,+ colors: {},+ });+ });});diff --git a/app/src/components/settings/panels/ThemeStudioPanel.tsx b/app/src/components/settings/panels/ThemeStudioPanel.tsxindex bd1b64c757..b1083de0cc 100644--- a/app/src/components/settings/panels/ThemeStudioPanel.tsx+++ b/app/src/components/settings/panels/ThemeStudioPanel.tsx@@ -89,34 +89,33 @@ function tileCanvas(theme: Theme): string {}/**- * Does this value carry at least one colour token?+ * Is this a usable colour map — an object of `token -> "r g b"` strings?*- * The old check was `typeof parsed.colors !== 'object'`, which passes for- * `null` and for an array — `typeof null` and `typeof []` are both `'object'`.- * Execution then reached `colors: { ...(parsed.colors) }`, and spreading either- * yields `{}`, so a theme with ZERO colour tokens was written to the store and- * could be activated from the gallery (#5901).+ * The bug this exists for (#5901): the old check was+ * `typeof parsed.colors !== 'object'`, which passes for `null` AND for an+ * array, since `typeof null` and `typeof []` are both `'object'`. Execution+ * then reached `colors: { ...(parsed.colors) }`; spreading either yields `{}`+ * silently, so a malformed paste was accepted as a theme.*- * An empty object is refused for the same reason, not merely for tidiness: its- * user-visible outcome is identical to `null`. `applyTheme` writes one custom- * property per token and `withDerivedChrome` derives only FROM existing tokens- * (`lib/theme/chrome.ts:67-79`), so a zero-token theme applies nothing at all —- * a named entry in the gallery that silently does nothing when clicked.- * Accepting `{}` while rejecting `null` would fix the shape and leave the- * defect.+ * An EMPTY object is deliberately allowed. `CLASSIC_LIGHT` and `CLASSIC_DARK`+ * both carry `colors: {}` on purpose (`lib/theme/presets.ts:63-78`) — they+ * inherit the base stylesheet tokens and carry their meaning in `isDark`, which+ * `applyTheme` applies independently of any colour+ * (`providers/ThemeProvider.tsx:48-50`). The panel's own export serialises the+ * effective theme, so rejecting `{}` would break its export -> import round trip+ * for the two most common themes, and would also refuse legitimate+ * font-, gradient- or backdrop-only themes.*- * The cost, stated plainly: a fonts-or-backdrop-only theme can no longer be- * imported without at least one colour. That was never really supported —- * `colors` has always been a required field here — and it is the narrower- * trade against shipping a theme that does nothing.+ * Every value must be a string. `swatchChannels` falls back only on+ * `null`/`undefined` (`??`), so a non-string like `{"surface": 42}` reaches+ * `channelsToCss`, which calls `.trim()` on it and throws — crashing the panel+ * on a theme that was already stored.*/-function hasColorTokens(colors: unknown): colors is Record<string, string> {- return (- typeof colors === 'object' &&- colors !== null &&- !Array.isArray(colors) &&- Object.keys(colors).length > 0- );+function isValidColorMap(colors: unknown): colors is Record<string, string> {+ if (typeof colors !== 'object' || colors === null || Array.isArray(colors)) {+ return false;+ }+ return Object.values(colors).every(value => typeof value === 'string');}function importedGradient(parsed: Partial<Theme>): Theme['gradient'] {@@ -179,7 +178,7 @@ const ThemeStudioPanel = ({ embedded = false }: ThemeStudioPanelProps = {}) => {setImportError('');try {const parsed = JSON.parse(importText) as Partial<Theme>;- if (!parsed || typeof parsed !== 'object' || !hasColorTokens(parsed.colors)) {+ if (!parsed || typeof parsed !== 'object' || !isValidColorMap(parsed.colors)) {throw new Error('shape');}const theme: Theme = {