Make `/theme` work in the `clai2` web UI

Merged
MP
2mo ago
+359-66

Part 9 of the clai2 web UI stack (… → #10276 → this PR). Based on #10276. No linked issue: requested by the CLAI maintainer.

Why. Make /theme work in the web UI, so the browser follows the palette the terminal uses.

What changes

  • The web plugin sends the /theme choice in its snapshot, plus a ThemeChanged message when a command changes it: the name, the available names, and the termflow palette (bg, fg, 16 ANSI slots). It reads the choice with host.setting('display.theme') from #10276.
  • The browser paints a palette with the same slot for each role as the terminal (ui/rendering/theme.py): accent from slot 12, errors 1, thinking 5, success 14, warnings 3. Diff lines blend green and red into the background at 28%, as diff_theme does. The page's mode follows the palette's brightness, as _is_light decides.
  • default keeps Pydantic's colours and the light/dark toggle. A palette hides the toggle, since it fixes the mode.
  • The sidebar footer has a theme picker that sends /theme NAME. A bare /theme typed in the browser still opens the terminal's picker, so the footer is the browser's way to pick.

New public surface. None (web plugin wire fields only).

Verification.

  • tests/clai2/test_web.py::test_theme checks the default theme and the list of names, then /theme tokyo_night arriving as a ThemeChanged with its palette. It also checks that a command which doesn't change the theme sends nothing.
  • A host without settings reports default.
  • 65 tests pass across the web, built-in plugin and startup-import suites.
  • Headed Playwright against clai2 --web picked tokyo_night, github_light and catppuccin_latte, then typed /theme rose_pine_dawn. The page's computed background, text, sidebar and send button matched each palette, and the saved theme was restored. No page errors.

What changes for existing users. Nothing until they enable web.

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.