Skip to content

Widget: keep its own field colors on dark pages, and an opt-in dark appearance - #472

Merged
neuromechanist merged 10 commits into
developfrom
feature/issue-469-widget-dark-theme
Sep 24, 2026
Merged

neuromechanist merged 10 commits into
developfrom
feature/issue-469-widget-dark-theme

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes #469. On a dark-themed host page the widget's chat input turned dark inside the light panel. This fixes that for every community, and gives the widget an opt-in dark appearance that NEMAR turns on.

The fix every community gets

A host page that declares color-scheme: dark makes the browser draw any form control without colors of its own in its dark field colors, and text without a color of its own inherits the host page's. The container now declares color-scheme: light, and the panel, the chat input and the Settings fields set their own colors. On a light host page the only visible change is typed text, and any panel text that used to inherit the host page's color, becoming the widget's #1f2937.

The dark appearance, opt-in

  • widget.color_scheme: light (default, omitted from the API response) or auto, which follows the reader's device, including a switch while the page is open. Only NEMAR sets auto, and a test holds every other community to the default. dark is never a community's: the config, the response model and the widget each refuse it from that side. A browser without matchMedia leaves auto light with a warning; Safari before 14 follows the device through addListener.
  • OSAChatWidget.setColorScheme('light' | 'dark' | 'auto'): for a host page with its own theme switch (nemar.org's). It outranks the community's value, works before or after init() (before, with no flash of the light panel), and reaches the pop-out, both at opening and afterward. 'dark' works for any community whose host page asks for it. setConfig({colorScheme}) takes the same values.
  • The dark panel: dark tokens, plus overrides for every literal color in the stylesheet (code blocks, tables, banners, tool panels, Settings, tooltips), and a one-pixel edge on raised surfaces so they do not vanish against a dark page.
  • Accent: accent_color was chosen to read on white (NEMAR's #257a92 is 3.6:1 on the dark panel and 3.0:1 on the assistant's bubble), so the inline property moves to --osa-accent-on-light, and the dark panel uses theme_color itself (NEMAR's teal: 8.0:1 and 6.6:1). A theme color under 4.5:1 on either surface is mixed with white in 10% steps until it reads on both; the platform blue becomes #6692f1 (5.9:1 and 4.9:1). The configured disclaimer colors give way the same way.
  • A light widget is untouched: no osa-dark class, no extra inline property, and no media-query listener.

Also in this PR

  • A registry test holds code execution (extensions.client_tools, runtime) and the notebook (notebook) to NEMAR, the way the other NEMAR-only widget settings are held.
  • docs/community-widget.md: a "Light and dark" section and the setConfig row.

Found along the way, not fixed here

Today's pop-out is written into about:blank, inherits its opener's Content-Security-Policy, and runs its scripts inline, so on a host page without script-src 'unsafe-inline' it opens blank. nemar.org allows 'unsafe-inline', so it works there; the browser harness's stricter policy does not. The pop-out is rebuilt in #470, which should load the script by URL instead. The Chrome check below runs its pop-out step under nemar.org's live script-src.

Tests

  • frontend/test-widget-color-scheme.js (new, in both workflows), 128 checks on the real widget source in happy-dom: a light community on a dark device is unchanged; auto follows the device, including a live switch and an addListener-only browser, and stays light with one warning without matchMedia; the host's choice outranks the community's before and after init(); invalid values from the host, setConfig, the server (including dark) or a pop-out preset are ignored with a warning naming the accepted values; every color the dark block replaces is read back, on the widget's own elements where it renders them, from the parsed stylesheet for :hover and ::before, and must differ on a light widget; each JavaScript constant is held to its stylesheet value; the accent kept, lifted to the first step that reads on both surfaces (black stops at #999999), and cleared when stale; what openPopout writes, and the pop-out keeping its host's choice.
  • Mutation check: 46 mutations of the new code, each failing a check.
  • frontend/browser-harness/color-scheme-check.mjs --serve, now in CI (Python 3.12 job of both workflows): starts its own two widget_e2e.py servers (the default config, and a new --color-scheme auto flag, so CI does not depend on --nemar's live recipe fetch). On a dark host page, with a control proving Chrome draws a plain input dark there, a light community's chat input, Settings key field and model menu stay white with the widget's text color; auto follows an emulated device switch, setColorScheme('light') outranks a dark device, and the pop-out keeps the host's choice, then follows it to dark. Seven mutations, each failing it.
  • test-widget-capsule.js (the bubble regression) and test-widget-tools.js pass, the latter with its accent assertions moved to the new property; both also pass against the field-color commit alone.
  • The whole pytest suite and every Bun suite CI runs; ruff clean.
  • Safari by hand on staging, with nemar.org's theme switch, once the website passes its theme on (website PR, next).

Not in this PR

A host page that declares color-scheme: dark made the browser draw the
chat input, the Settings fields and the scrollbars in its dark scheme,
and text with no color of its own took the host's light text color.
The container now declares color-scheme: light, and the panel, the chat
input and the Settings fields set their own colors. Applies to every
community; on a light page only typed text changes, to #1f2937.

Tested: test-widget-capsule.js (bubble regression) and
test-widget-tools.js pass against this version.
WidgetConfig.color_scheme is 'light' (the default, omitted from the API
response) or 'auto', which follows the reader's device. NEMAR sets auto;
a test holds every other community to the light default.

Tested: test_community.py and test_communities_endpoint.py.
An osa-dark class, set when colorScheme is 'dark', or 'auto' on a dark
device (followed live), carries dark tokens and overrides for every
literal color. OSAChatWidget.setColorScheme passes a host page's own
choice, outranks the community's, and reaches the pop-out. accent_color
moves to --osa-accent-on-light so the dark panel can replace it with
theme_color, lifted toward white only if it reads under 4.5:1. A light
widget gets no class, no inline property and no media listener.

Tested: test-widget-color-scheme.js (67 checks, 26 mutations caught),
test-widget-capsule.js, test-widget-tools.js.
Every other real community must declare no client tool, no runtime
and no notebook section.

Tested: fails when NEMAR's own config is left among the others.
color-scheme-check.mjs starts from a dark host page, with a control
proving Chrome draws a plain input dark there, then checks a light
community's fields and NEMAR's auto, host override and pop-out.

Tested: both modes pass in Chrome 153; seven mutations each fail.
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-469-widget-dar-demo.osc.earth
Branch feature/issue-469-widget-dark-theme
Commit 1082ecd

This preview will be updated automatically when you push new commits.

WidgetConfigResponse.color_scheme is Literal['auto'] | None: resolve()
omits light, and dark is never a community's to send, so the response
model guards that whichever code path builds it.

Tested: test_community.py, built from resolve() as the route does.
From the PR #472 review:
- a community config's color_scheme is taken only as light or auto
- the dark accent is measured on the assistant's bubble as well as the
  panel, so the platform blue now lifts to #6692f1; darkAccentFor takes
  the raw theme color and has no unreachable fallback
- no matchMedia warns once and stays light; addListener-only browsers
  (Safari before 14) still follow the device
- reaching the pop-out and the pop-out failing are reported apart
- warnings name the accepted values
- tests: computed color-scheme instead of a source regex, every dark
  rule read back (hover and ::before from the parsed stylesheet), each
  JS constant held to its stylesheet value, black lifted short of white

Tested: test-widget-color-scheme.js (128 checks); 46 mutations caught.
color-scheme-check.mjs --serve starts its own two widget_e2e.py servers
(the default config, and --color-scheme auto, a new harness flag that
avoids --nemar's live recipe fetch) and runs in the Python 3.12 job of
both workflows. From the review: every readiness wait stops the run,
the light run checks the config applied, the page-policy rewrite
records its own failures, and a runner without Chrome fails under CI.

Tested: --serve passes locally in Chrome 153; seven mutations each fail.
NEMAR's config no longer says nemar.org already passes its theme on;
the accent figures cover both dark surfaces; the older-browser behavior
and the CI checks are documented.

Tested: docs and a YAML comment only.
@neuromechanist

Copy link
Copy Markdown
Member Author

Review response

Four Sonnet reviewers (code, tests, error handling, docs). Every finding is addressed below; the code review found no bugs in the three hard constraints (light widgets untouched, the accent rename, the pop-out carry-over).

Tests

  • The Chrome check was not in CI. color-scheme-check.mjs --serve now starts its own two widget_e2e.py servers and runs in the Python 3.12 job of both workflows. The auto server uses a new --color-scheme auto harness flag rather than --nemar, whose live recipe fetch from mcp.nemar.org at startup would make CI depend on production. (e7a9b73)
  • color-scheme: light was asserted with a source regex that a commented-out rule still matched. Replaced with the computed colorScheme, light on a light widget and dark under osa-dark. (ce2fd52)
  • About a dozen dark rules were untested. Every color the dark block replaces is now read back as a computed style, on the widget's own elements where it renders them (the banners, Settings, the input row) and on probes written the way the render functions write them otherwise; each must also differ on a light widget. :hover and ::before rules are read from the parsed stylesheet, where a commented-out or misspelled rule is absent. (ce2fd52)
  • darkAccentFor's #ffffff fallback was never exercised. It could not be: every color reads before the last 10% step. The loop now runs to step 10 (white), with no fallback after it, and a test lifts black (#000000) to #999999, short of white. (ce2fd52)
  • The widget accepted dark from a community config. The community path now takes only light or auto, with a test; and WidgetConfigResponse.color_scheme is Literal["auto"] | None, tested by building it from resolve() the way the route does. (ce2fd52, 287a89b)
  • Noted, not changed here: keyboard-activation-check.mjs has the same not-in-CI gap from before this PR; filed as keyboard-activation-check.mjs is not run in CI #473.

Error handling

  • auto without matchMedia stayed light silently. It now warns once; a query with only addListener (Safari before 14) is followed through it; one with neither warns. Both tested with a simulated older browser. (ce2fd52)
  • The invalid-themeColor fallback had no warning of its own. darkAccentFor now takes the raw theme color, and its comment says why the fallback is the stylesheet default: applyWidgetConfig never applies an invalid themeColor (and warns about it), so the default is what is on screen. Warning again here would repeat that warning on every call. (ce2fd52)
  • darkAccentFor trusted its input. It now validates it itself, since it is given the raw theme color. (ce2fd52)
  • DEFAULT_PRIMARY was not held to the stylesheet. A test now holds it to the computed --osa-primary, and the new DARK_BUBBLE_BG to the dark assistant bubble. (ce2fd52)
  • Warnings did not name the accepted values. They do now, for the host, setConfig and the community config. (ce2fd52)
  • One try covered both reaching the pop-out and the pop-out's own code. Reaching it warns; a failure inside the pop-out's setColorScheme is a console.error with its own message. (ce2fd52)
  • The harness ignored waitForCommunityConfig's result, and double-reported one timeout. Every readiness wait now stops the run when it fails. The light run also checks the config actually applied, via its title and colorScheme, before checking anything that depends on it. (e7a9b73)
  • A failure inside the policy-rewrite listener was an unhandled rejection that left the exit code at 0. The listener records failures, and the run reports them. (e7a9b73)
  • No Chrome passed silently, even in CI. It now fails when CI is set, as chrome.js does. (e7a9b73)

Code

  • The accent was measured only against the panel, while links sit on the lighter assistant bubble. It is now measured on both, so the platform blue lifts to #6692f1 (5.9:1 and 4.9:1). NEMAR's teal needs no lift (8.0:1 and 6.6:1). (ce2fd52)
  • Intentional, now commented: .osa-execution img keeps its white background on the dark panel, so a figure drawn with a transparent background keeps its dark axes and labels readable. (ce2fd52)

Docs

  • NEMAR's config said nemar.org already passes its theme on. It does not yet; reworded. (e52ed86)
  • The osa-dark block comment and applyColorScheme's list of callers were incomplete. Both now name setConfig and the device-change listener. (ce2fd52)
  • A long unbroken sentence in docs/community-widget.md, and CSSOM not spelled out. Fixed. (e52ed86, e7a9b73)

Re-verified after the fixes: the whole pytest suite (2927 passed), every Bun suite, ruff, color-scheme-check.mjs --serve in Chrome 153, 46 happy-dom mutations and 7 Chrome mutations each caught.

@neuromechanist
neuromechanist merged commit bb2d865 into develop Sep 24, 2026
11 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-469-widget-dark-theme branch September 24, 2026 12:20
neuromechanist added a commit that referenced this pull request Sep 24, 2026
Release review: add the widget's Notebook tab (#471, #474), color_scheme auto (#472), the first-paint fix (#476) and the dark-page field colors; the capsule and notebook-site bullets described the notebook opening in a new tab, which #474 replaced.

Tested: docs-only; each claim checked against origin/develop (config.yaml color_scheme, osa-widget-config- key, ADR 0012 path).
neuromechanist added a commit that referenced this pull request Sep 24, 2026
* Title the changelog's release as 0.8.14

Tested: docs only.

* Complete the 0.8.14 changelog

Release review: add the widget's Notebook tab (#471, #474), color_scheme auto (#472), the first-paint fix (#476) and the dark-page field colors; the capsule and notebook-site bullets described the notebook opening in a new tab, which #474 replaced.

Tested: docs-only; each claim checked against origin/develop (config.yaml color_scheme, osa-widget-config- key, ADR 0012 path).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant