Files
worktrunk/docs/demos/shared/themes.py
ee52834701 docs(demos): record demos with the site's current palette (#4069)
The demo recorder kept its own copies of the docs site's colors, and
they had drifted from `docs/src/styles/custom.css`:

- The VHS terminal's ANSI colors were still the Zola site's palette,
which #3866 deleted and #3936 replaced with `--wt-terminal-*`. Light
yellow had 2.65:1 contrast against the page background; the site's
browser test requires 4.5:1 for its own dim terminal text.
- `brightWhite`, the background of Worktrunk's gutter, used the ink
color, so dark GIFs drew the gutter as a near-white bar.
- Zellij, the starship prompt, and Claude Code were configured for light
in both themes, so dark GIFs showed a light Zellij tab bar and Claude
Code's light theme.

`docs/demos/shared/themes.py` now reads the hex `--wt-*` properties from
`custom.css` when the build runs. The VHS theme maps ANSI colors the way
the site renders snapshot output (`terminal_color_class` and
`terminal_background_class` in
`tests/integration_tests/readme_sync.rs`). `DemoEnv` carries the
recording's theme, so Zellij, the starship palette, and Claude Code
follow it. This replaces the `(pre-Starlight; site is #…)` comments the
PR first added.

Recording from inside a Claude Code session also leaked into the Claude
demos. The demo's Claude Code inherited that session's `CLAUDE*`
variables and warned that transcript saving was off, and it started
Remote Control, which printed a live claude.ai session URL into the GIF.
The recorder now drops inherited `CLAUDE*` variables except
`CLAUDE_CODE_OAUTH_TOKEN`, and the demo's `settings.json` sets
`remoteControlAtStartup` to false.

The GIFs are re-recorded locally (`./docs/demos/build docs` and
`./docs/demos/build social`) and published in
max-sixty/worktrunk-assets@bb3bfba.

## Verification

- `pytest docs/demos/tests`: 4 passed.
- OCR of every 20th frame of the Claude demos (354 frames) finds no
`remote-control`, `claude.ai/code`, `rc active`, or `Transcript saving`.
The same check matches on frames from the leaking recording.
- Frames checked by eye in both themes for the ANSI colors, the gutter,
and the Zellij chrome.
- TUI validation passes for all nine Claude demo GIFs. The `wt-switch`
and `wt-statusline` checkpoints named absolute frames past the end of
these faster recordings (274–318 frames, against 344–465 in the
previously published GIFs), so a negative checkpoint frame now counts
back from the last frame; the omnibus checkpoint on its closing `wt
list` uses the same anchoring. The previously published GIFs pass the
new checkpoints too. Those checkpoints also forbid `claude.ai/code` and
`Transcript saving`, and a GIF made from a leaking frame fails on them.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01TQPDxs2csvGFGBr2j4MtrA

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com>
Co-authored-by: Maximilian Roos <m@maxroos.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-12 15:42:32 -07:00

75 lines
2.6 KiB
Python

"""Demo recording palettes, read from the documentation site's stylesheet.
The VHS terminal, Zellij, and starship colors come from hex ``--wt-*`` custom
properties in ``docs/src/styles/custom.css``: the light theme from its
``:root`` block, the dark theme from ``:root[data-theme='dark']``. A recording
uses whatever palette the site has when the build runs. Each property a
recording uses must be declared as a lowercase six-digit hex color in both
blocks; any other form is a ``KeyError`` rather than a silently wrong color.
The VHS terminal theme maps ANSI colors to properties the way the site renders
snapshot output (``terminal_color_class`` and ``terminal_background_class`` in
``tests/integration_tests/readme_sync.rs``). A bright hue uses its normal hue's
property. Bright black and white text use ``--wt-ink-muted``, the site's gray;
black, which the site never renders, matches them. Bright white uses
``--wt-terminal-gutter``, because Worktrunk draws its gutter with a bright-white
background.
"""
import json
import re
from pathlib import Path
CUSTOM_CSS = Path(__file__).parents[2] / "src" / "styles" / "custom.css"
def _hex_properties(css: str, selector: str) -> dict[str, str]:
"""Hex ``--wt-*`` properties declared in the top-level ``selector`` block."""
start = css.index(f"\n{selector} {{\n")
end = css.index("\n}\n", start)
declarations = re.findall(
r"^\s+(--wt-[\w-]+): (#[0-9a-f]{6});$", css[start:end], re.MULTILINE
)
return dict(declarations)
def _site_palettes() -> dict[str, dict[str, str]]:
css = CUSTOM_CSS.read_text()
return {
"light": _hex_properties(css, ":root"),
"dark": _hex_properties(css, ":root[data-theme='dark']"),
}
PALETTES = _site_palettes()
def _vhs_theme(theme: str) -> dict[str, str]:
palette = PALETTES[theme]
hues = {
hue: palette[f"--wt-terminal-{hue}"]
for hue in ("red", "green", "yellow", "blue", "magenta", "cyan")
}
gray = palette["--wt-ink-muted"]
return {
"name": f"worktrunk-{theme}",
"black": gray,
**hues,
"white": gray,
"brightBlack": gray,
**{f"bright{hue.title()}": color for hue, color in hues.items()},
"brightWhite": palette["--wt-terminal-gutter"],
"background": palette["--wt-paper"],
"foreground": palette["--wt-terminal-ink"],
"cursor": palette["--wt-copper"],
"selection": palette["--wt-gold-wash"],
}
THEMES = {theme: _vhs_theme(theme) for theme in PALETTES}
def format_theme_for_vhs(theme: dict) -> str:
"""Format a theme dict as a VHS Set Theme command value."""
return json.dumps(theme)