π OpenHands: AI-Driven Development
refactor(theme): use readable MCP feedback text tokens (#18270)
Engel Nyst8af7ee59a158
diff --git a/.agents/skills/frontend-development/references/guide.md b/.agents/skills/frontend-development/references/guide.mdindex 99eb9facf5..76ff3fb8f5 100644--- a/.agents/skills/frontend-development/references/guide.md+++ b/.agents/skills/frontend-development/references/guide.md@@ -99,6 +99,7 @@ When adding code that needs a new string, decide up front which rule it falls un- Public embedding entry points should use `AgentServerUIProviders` (scoped root on by default) or `AgentServerUIRoot` for manual control. The standalone app already renders its own scoped root in `src/root.tsx`, so `src/entry.client.tsx` must pass `withStyleRoot={false}` to avoid nesting duplicate shells. Keep `AgentServerUIRoot` and the scoping constants re-exported from `src/lib/index.ts` so library consumers can customize the host wrapper without reaching into private paths.- `AgentServerUIRoot`'s themed inner wrapper must set a default `color: var(--foreground)` in addition to the `dark` / `data-theme` markers; otherwise inherited text and `currentColor` SVG icons fall back to dark browser defaults after CSS scoping, causing dark-on-dark regressions on pages like the home screen.- Theme/customization tokens for the embedded shell are exposed as `--oh-*` CSS variables. Override them through `styleOverrides`, `style`, or host CSS targeting `[data-agent-server-ui]`; Tailwind theme tokens in `src/tailwind.css` should continue to reference those variables with `@theme inline` so host apps can restyle the UI without reworking component class names.+- Small form feedback uses the `feedback-error` / `feedback-success` text roles (`--oh-feedback-error` / `--oh-feedback-success`), separately from the general danger/success control palette. Their built-in values must meet 4.5:1 on modal surfaces; host overrides remain owned by the embedding root. See `src/themes/README.md` and the theme contrast tests when migrating raw feedback colors.- Regression coverage for the CSS isolation work lives in `__tests__/agent-server-ui-providers.test.tsx`, `__tests__/agent-server-ui-style-scope.test.ts`, and the browser-level CSS-isolation test in `tests/e2e/mock-llm/regressions/mock-llm-ui-regressions.spec.ts`.- Conversation history is loaded lazily, REST-first then WebSocket:diff --git a/__tests__/themes/color-themes.test.tsx b/__tests__/themes/color-themes.test.tsxindex d0ea38d9c2..6bd9354e20 100644--- a/__tests__/themes/color-themes.test.tsx+++ b/__tests__/themes/color-themes.test.tsx@@ -1,6 +1,7 @@import { act, render, screen } from "@testing-library/react";import { afterEach, describe, expect, it } from "vitest";import { AgentServerUIRoot } from "#/components/providers/agent-server-ui-root";+import { AGENT_SERVER_UI_DEFAULT_CSS_VARIABLES } from "#/styles/agent-server-ui-style-scope";import {AVAILABLE_COLOR_THEMES,COLOR_THEMES,@@ -8,6 +9,48 @@ import {} from "#/themes/color-themes";describe("color themes", () => {+ // @spec MCP-004 β Form feedback follows readable theme text roles+ it.each(Object.entries(COLOR_THEMES))(+ "keeps small form feedback readable on the %s modal surface",+ (_key, theme) => {+ // Resolve the shipped palette, including stylesheet-owned defaults.+ const variables: Record<string, string> = {+ ...AGENT_SERVER_UI_DEFAULT_CSS_VARIABLES,+ ...theme.scale,+ ...theme.tokens,+ };+ const resolve = (name: string): string => {+ const value = variables[name];+ expect(value, `Missing theme token ${name}`).toBeDefined();+ const reference = /^var\((--[\w-]+)\)$/.exec(value);+ return reference ? resolve(reference[1]) : value;+ };+ const luminance = (hex: string): number => {+ const channels = [1, 3, 5].map((offset) => {+ const channel =+ Number.parseInt(hex.slice(offset, offset + 2), 16) / 255;+ return channel <= 0.04045+ ? channel / 12.92+ : ((channel + 0.055) / 1.055) ** 2.4;+ });+ return (+ channels[0] * 0.2126 + channels[1] * 0.7152 + channels[2] * 0.0722+ );+ };+ const surface = luminance(resolve("--oh-color-base-secondary"));++ for (const role of ["--oh-feedback-error", "--oh-feedback-success"]) {+ const ink = luminance(resolve(role));+ const ratio =+ (Math.max(ink, surface) + 0.05) / (Math.min(ink, surface) + 0.05);+ expect(+ ratio,+ `${role} against the modal surface`,+ ).toBeGreaterThanOrEqual(4.5);+ }+ },+ );+afterEach(() => {document.querySelectorAll("style[data-theme-test]")@@ -30,6 +73,29 @@ describe("color themes", () => {expect(style.getPropertyValue("--oh-color-primary")).toBe("#123456");expect(style.getPropertyValue("--oh-radius")).toBe("12px");});+ // @spec MCP-004 β Form feedback follows readable theme text roles+ it("preserves host feedback colors when the selected palette changes", () => {+ const overrides = {+ "--oh-feedback-error": "#672727",+ "--oh-feedback-success": "#24542d",+ } as const;+ render(+ <AgentServerUIRoot+ data-testid="feedback-scope"+ styleOverrides={overrides}+ >+ Canvas+ </AgentServerUIRoot>,+ );++ act(() => applyColorTheme("light-plus"));++ const style = getComputedStyle(screen.getByTestId("feedback-scope"));+ for (const [token, value] of Object.entries(overrides)) {+ expect(style.getPropertyValue(token)).toBe(value);+ }+ document.getElementById("oh-color-theme-override")?.remove();+ });it("includes OpenHands-Neo as a neutral-based theme with white button tokens", () => {const neo = COLOR_THEMES["openhands-neo"];diff --git a/specs/mcp-settings.md b/specs/mcp-settings.mdindex e6f8d1187b..41b432569e 100644--- a/specs/mcp-settings.md+++ b/specs/mcp-settings.md@@ -32,3 +32,11 @@or arguments.- [x] Rename shall use one atomic map patch, reject collisions, and rejecthidden-secret renames that could lose credentials.++### MCP-004: Form feedback follows readable theme text roles++- [x] Custom-server validation and connection feedback, and catalog-install+ errors, use the selected theme's error/success text roles.+- [x] Both text roles meet 4.5:1 against the modal surface in every built-in+ palette, independently of the danger/success control colors.+- [x] Embedded host overrides for those roles survive palette changes.diff --git a/src/components/features/mcp-page/install-server-modal.tsx b/src/components/features/mcp-page/install-server-modal.tsxindex 652938339d..cf78063b4c 100644--- a/src/components/features/mcp-page/install-server-modal.tsx+++ b/src/components/features/mcp-page/install-server-modal.tsx@@ -522,6 +522,7 @@ export function InstallServerModal({return handleStdioSubmit();};+ // @spec MCP-004 β Form feedback follows readable theme text rolesconst renderFields = () => {if (template?.kind === "shttp" || template?.kind === "sse") {const oauthMode = isOAuthOption(option);@@ -542,7 +543,7 @@ export function InstallServerModal({className="w-full"/>{state.errors.url && (- <p className="text-xs text-red-500">{state.errors.url}</p>+ <p className="text-xs text-feedback-error">{state.errors.url}</p>)}{headerFields.map((field) => (<div key={field.key} className="flex flex-col gap-1">@@ -564,7 +565,7 @@ export function InstallServerModal({</p>)}{state.errors[field.key] && (- <p className="text-xs text-red-500">+ <p className="text-xs text-feedback-error">{state.errors[field.key]}</p>)}@@ -615,7 +616,9 @@ export function InstallServerModal({</p>)}{state.errors.api_key && (- <p className="text-xs text-red-500">{state.errors.api_key}</p>+ <p className="text-xs text-feedback-error">+ {state.errors.api_key}+ </p>)}{credentialSecretName && (<SaveAsSecretToggle@@ -664,7 +667,9 @@ export function InstallServerModal({</p>)}{state.errors[field.key] && (- <p className="text-xs text-red-500">{state.errors[field.key]}</p>+ <p className="text-xs text-feedback-error">+ {state.errors[field.key]}+ </p>)}{field.key in state.savedAsSecret && (<SaveAsSecretToggle@@ -697,7 +702,9 @@ export function InstallServerModal({</p>)}{state.errors[field.key] && (- <p className="text-xs text-red-500">{state.errors[field.key]}</p>+ <p className="text-xs text-feedback-error">+ {state.errors[field.key]}+ </p>)}</div>))}@@ -805,10 +812,11 @@ export function InstallServerModal({<div className="flex flex-col gap-3">{renderFields()}</div>+ {/* @spec MCP-004 β Form feedback follows readable theme text roles */}{globalError && (<pdata-testid="mcp-install-modal-error"- className="text-sm text-red-500 whitespace-pre-wrap"+ className="text-sm text-feedback-error whitespace-pre-wrap">{globalError}</p>diff --git a/src/components/features/settings/mcp-settings/mcp-server-form.tsx b/src/components/features/settings/mcp-settings/mcp-server-form.tsxindex ba1f534d03..e3c4bc1a10 100644--- a/src/components/features/settings/mcp-settings/mcp-server-form.tsx+++ b/src/components/features/settings/mcp-settings/mcp-server-form.tsx@@ -480,7 +480,8 @@ export function MCPServerForm({/>)}- {error && <p className="text-red-500 text-sm">{error}</p>}+ {/* @spec MCP-004 β Form feedback follows readable theme text roles */}+ {error && <p className="text-feedback-error text-sm">{error}</p>}{(serverType === "sse" || serverType === "shttp") && (<>@@ -703,13 +704,14 @@ export function MCPServerForm({</>)}+ {/* @spec MCP-004 β Form feedback follows readable theme text roles */}{testMessage && (<pdata-testid="mcp-test-message"className={testMessage.ok- ? "text-sm text-green-500 whitespace-pre-wrap"- : "text-sm text-red-500 whitespace-pre-wrap"+ ? "text-sm text-feedback-success whitespace-pre-wrap"+ : "text-sm text-feedback-error whitespace-pre-wrap"}>{testMessage.text}diff --git a/src/styles/agent-server-ui-style-scope.ts b/src/styles/agent-server-ui-style-scope.tsindex a0bb0ffeb8..343b02a512 100644--- a/src/styles/agent-server-ui-style-scope.ts+++ b/src/styles/agent-server-ui-style-scope.ts@@ -24,6 +24,9 @@ export const AGENT_SERVER_UI_DEFAULT_CSS_VARIABLES = {"--oh-color-base-secondary": "var(--cool-grey-925)","--oh-color-danger": "#e76a5e","--oh-color-success": "#a5e75e",+ // @spec MCP-004 β Form feedback follows readable theme text roles+ "--oh-feedback-error": "var(--oh-color-danger)",+ "--oh-feedback-success": "var(--oh-color-success)","--oh-color-basic": "var(--cool-grey-400)","--oh-color-tertiary": "var(--cool-grey-800)","--oh-color-tertiary-light": "var(--cool-grey-300)",diff --git a/src/tailwind.css b/src/tailwind.cssindex c092ccde02..e162e4d3fb 100644--- a/src/tailwind.css+++ b/src/tailwind.css@@ -18,6 +18,9 @@--color-base-secondary: var(--oh-color-base-secondary);--color-danger: var(--oh-color-danger);--color-success: var(--oh-color-success);+ /* @spec MCP-004 β Form feedback follows readable theme text roles */+ --color-feedback-error: var(--oh-feedback-error);+ --color-feedback-success: var(--oh-feedback-success);--color-basic: var(--oh-color-basic);--color-tertiary: var(--oh-color-tertiary);--color-tertiary-light: var(--oh-color-tertiary-light);@@ -85,6 +88,9 @@--oh-color-base-secondary: var(--cool-grey-925);--oh-color-danger: #e76a5e;--oh-color-success: #a5e75e;+ /* Small feedback text has its own contrast contract, separate from controls. */+ --oh-feedback-error: var(--oh-color-danger);+ --oh-feedback-success: var(--oh-color-success);--oh-color-basic: var(--cool-grey-400);--oh-color-tertiary: var(--cool-grey-800);--oh-color-tertiary-light: var(--cool-grey-300);diff --git a/src/themes/README.md b/src/themes/README.mdindex 9a5635d28d..e78fe7c5ad 100644--- a/src/themes/README.md+++ b/src/themes/README.md@@ -37,6 +37,10 @@ them; changing the page background alone is not a complete theme.high-emphasis ink (white in dark palettes, dark in light palettes); itspaired `contrast-foreground` is for inverse pills and tooltips. Opacity andstate variants such as `hover:bg-contrast/10` retain their stated values.+- Use `feedback-error` and `feedback-success` for small validation and connection+ messages. These text roles meet 4.5:1 on the built-in modal surface and leave+ the general danger/success control colors unchanged. Embedded hosts can+ override `--oh-feedback-error` and `--oh-feedback-success` for their surfaces.- Literal white is reserved for fixed-color surfaces (for example the bluePlan control, an image-lightbox scrim, or a document preview). Do not globallyredefine white or add theme-specific selectors that reinterpret utilities.diff --git a/src/themes/color-theme/definitions/light-plus.ts b/src/themes/color-theme/definitions/light-plus.tsindex 3cc0519609..75f75c3b58 100644--- a/src/themes/color-theme/definitions/light-plus.ts+++ b/src/themes/color-theme/definitions/light-plus.ts@@ -62,6 +62,9 @@ export const LIGHT_PLUS_TOKENS: Partial<"--oh-color-base-secondary": "#F3F3F3","--oh-color-danger": "#D13438","--oh-color-success": "#16825D",+ // Feedback text must remain readable on the light modal surface.+ "--oh-feedback-error": "#C0282D",+ "--oh-feedback-success": "#0F734D","--oh-color-basic": "#616161","--oh-color-tertiary": "#E5E5E5","--oh-color-tertiary-light": "#4D4D4D",diff --git a/src/themes/color-theme/definitions/solarized-light.ts b/src/themes/color-theme/definitions/solarized-light.tsindex e2830c3435..cbbc3ea52b 100644--- a/src/themes/color-theme/definitions/solarized-light.ts+++ b/src/themes/color-theme/definitions/solarized-light.ts@@ -65,6 +65,8 @@ const SOLARIZED_LIGHT_TOKENS: Partial<"--oh-color-base-secondary": "#EEE8D5","--oh-color-danger": "#DC322F","--oh-color-success": "#859900",+ "--oh-feedback-error": "#BB2A26",+ "--oh-feedback-success": "#5D6A00","--oh-color-basic": "#839496","--oh-color-tertiary": "#E6DFCC","--oh-color-tertiary-light": "#657B83",