Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(lint): theme context usage feedback colors (#18431)

Engel Nystaa593c721038
diff --git a/__tests__/themes/color-themes.test.tsx b/__tests__/themes/color-themes.test.tsx
index 1247439a4a..7a52127edd 100644
--- a/__tests__/themes/color-themes.test.tsx
+++ b/__tests__/themes/color-themes.test.tsx
@@ -84,6 +84,22 @@ describe("color themes", () => {
"--oh-contrast against the Home mode toggle pill",
).toBeGreaterThanOrEqual(4.5);
+ // @spec WN-001 β€” Context meter text and fills preserve contrast in each palette.
+ const contextMeterSurface = luminance(resolve("--oh-surface-raised"));
+ const contextMeterTrack = luminance(resolve("--oh-color-tertiary"));
+ for (const role of ["--oh-feedback-error", "--oh-feedback-warning"]) {
+ expect(
+ contrast(luminance(resolve(role)), contextMeterSurface),
+ `${role} against the context meter raised surface`,
+ ).toBeGreaterThanOrEqual(4.5);
+ }
+ for (const role of ["--oh-feedback-warning", "--oh-status-error"]) {
+ expect(
+ contrast(luminance(resolve(role)), contextMeterTrack),
+ `${role} against the context meter track`,
+ ).toBeGreaterThanOrEqual(3);
+ }
+
const warningInk = luminance(resolve("--oh-feedback-warning"));
const trustBackground = channels(resolve("--oh-background"));
const warningTint = channels(resolve("--oh-warning"));
diff --git a/specs/warning-feedback.md b/specs/warning-feedback.md
index 41d4c3c483..f64660747e 100644
--- a/specs/warning-feedback.md
+++ b/specs/warning-feedback.md
@@ -3,7 +3,7 @@
**Spec ID:** WN-001
**Status:** Implemented
-Small warning text and warning icons use the `feedback-warning` text role, backed by `--oh-feedback-warning`. The built-in role meets 4.5:1 on the theme surfaces used by the Home no-LLM banner, Canvas Apps trust notice, ACP conflict messages, and required-secret onboarding warning. Light+ and Solarized Light use darker text shades while retaining the existing brand warning color for controls and tint.
+Small warning text and warning icons use the `feedback-warning` text role, backed by `--oh-feedback-warning`. The built-in role meets 4.5:1 on the theme surfaces used by the Home no-LLM banner, Canvas Apps trust notice, ACP conflict messages, and required-secret onboarding warning. The Usage panel's context meter warning and danger text meets 4.5:1 against its raised card; its warning and danger fills also retain 3:1 contrast against the track. Light+ and Solarized Light use darker text shades while retaining the existing brand warning color for controls and tint.
Embedding roots may override the role. The UI follows the nearest `[data-agent-server-ui]` scope. Changing the role does not change warning copy, validation, routing, credential state, or trust controls.
diff --git a/src/components/features/conversation/usage-panel/compact-context-button.tsx b/src/components/features/conversation/usage-panel/compact-context-button.tsx
index bc0847f4ab..97899e1e4a 100644
--- a/src/components/features/conversation/usage-panel/compact-context-button.tsx
+++ b/src/components/features/conversation/usage-panel/compact-context-button.tsx
@@ -21,6 +21,7 @@ interface CompactContextButtonProps {
* call-to-action once the context fill passes
* {@link CONTEXT_FILL_WARNING_PERCENT}.
*/
+// @spec WN-001 β€” Compact context warnings use the readable warning role.
export function CompactContextButton({
fillPercent,
perTurnToken = 0,
@@ -36,7 +37,7 @@ export function CompactContextButton({
className="flex flex-col gap-2 border-t border-border-subtle pt-3"
>
{isHighFill && (
- <span className="text-xs text-amber-500">
+ <span className="text-xs text-feedback-warning">
{t(I18nKey.CONVERSATION$CONTEXT_FILLING_UP)}
</span>
)}
diff --git a/src/components/features/conversation/usage-panel/context-meter.test.tsx b/src/components/features/conversation/usage-panel/context-meter.test.tsx
index 9c8d99df37..30ffd99b7b 100644
--- a/src/components/features/conversation/usage-panel/context-meter.test.tsx
+++ b/src/components/features/conversation/usage-panel/context-meter.test.tsx
@@ -1,7 +1,17 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
+import { CompactContextButton } from "./compact-context-button";
import { ContextMeter } from "./context-meter";
+vi.mock("#/hooks/use-compact-context-action", () => ({
+ useCompactContextAction: () => ({
+ handleCompact: vi.fn(),
+ isCompacting: false,
+ isDisabled: false,
+ description: "Compact context",
+ }),
+}));
+
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
@@ -26,16 +36,23 @@ describe("ContextMeter", () => {
expect(bar.style.width).toBe("50%");
});
+ // @spec WN-001 β€” Warning meter text and fill use readable theme roles.
it("warns above 70% fill", () => {
render(<ContextMeter perTurnToken={75} contextWindow={100} />);
- expect(screen.getByTestId("context-meter-bar")).toHaveClass("bg-amber-500");
+ expect(screen.getByTestId("context-meter-bar")).toHaveClass(
+ "bg-feedback-warning",
+ );
+ expect(screen.getByText(/75%/)).toHaveClass("text-feedback-warning");
});
it("signals danger above 90% fill", () => {
render(<ContextMeter perTurnToken={95} contextWindow={100} />);
- expect(screen.getByTestId("context-meter-bar")).toHaveClass("bg-red-500");
+ expect(screen.getByTestId("context-meter-bar")).toHaveClass(
+ "bg-status-error",
+ );
+ expect(screen.getByText(/95%/)).toHaveClass("text-feedback-error");
expect(screen.getByTestId("context-meter")).toHaveTextContent(
"95% CONVERSATION$USED (5% CONVERSATION$LEFT)",
);
@@ -57,3 +74,14 @@ describe("ContextMeter", () => {
expect(meter).not.toHaveTextContent("0.0%");
});
});
+
+// @spec WN-001 β€” The compact action warning uses the same readable text role.
+describe("CompactContextButton", () => {
+ it("uses warning feedback color when context is above the threshold", () => {
+ render(<CompactContextButton fillPercent={75} />);
+
+ expect(screen.getByText("CONVERSATION$CONTEXT_FILLING_UP")).toHaveClass(
+ "text-feedback-warning",
+ );
+ });
+});
diff --git a/src/components/features/conversation/usage-panel/context-meter.tsx b/src/components/features/conversation/usage-panel/context-meter.tsx
index a030a9f121..66ad3bc26d 100644
--- a/src/components/features/conversation/usage-panel/context-meter.tsx
+++ b/src/components/features/conversation/usage-panel/context-meter.tsx
@@ -28,10 +28,10 @@ interface ContextMeterProps {
}
/**
- * Context-fill progress bar: neutral below
- * {@link CONTEXT_FILL_WARNING_PERCENT}, amber above it, red above
- * {@link CONTEXT_FILL_DANGER_PERCENT}. Shows the raw token numbers underneath.
+ * Context-fill progress bar with theme-aware warning and danger states. Shows
+ * the raw token numbers underneath.
*/
+// @spec WN-001 β€” Context usage indicators use readable warning and error roles.
export function ContextMeter({
perTurnToken,
contextWindow,
@@ -67,9 +67,9 @@ export function ContextMeter({
className={cn(
"shrink-0 text-xs",
isDanger
- ? "text-red-500"
+ ? "text-feedback-error"
: isWarning
- ? "text-amber-500"
+ ? "text-feedback-warning"
: "text-muted",
)}
>
@@ -82,9 +82,9 @@ export function ContextMeter({
className={cn(
"absolute inset-y-0 left-0 rounded-full transition-all duration-300",
isDanger
- ? "bg-red-500"
+ ? "bg-status-error"
: isWarning
- ? "bg-amber-500"
+ ? "bg-feedback-warning"
: "bg-foreground",
)}
// runtime usage-percentage width
diff --git a/src/themes/color-theme/definitions/openhands-deepsea.ts b/src/themes/color-theme/definitions/openhands-deepsea.ts
index d00926b77d..c6dcb523b3 100644
--- a/src/themes/color-theme/definitions/openhands-deepsea.ts
+++ b/src/themes/color-theme/definitions/openhands-deepsea.ts
@@ -20,6 +20,10 @@ export const openhandsDeepsea: ColorThemeDefinition = {
"--cool-grey-950": "#0B0E14",
"--cool-grey-975": "#05070A",
},
+ tokens: {
+ // @spec WN-001 β€” Small danger text clears 4.5:1 on raised Usage cards.
+ "--oh-feedback-error": "#EF766A",
+ },
// Values generated by heroui() from hero.ts β€” restore them explicitly when
// switching back from another theme.
heroui: {