Warn when an html surface hardcodes scheme colors#190
Open
benvinegar wants to merge 1 commit into
Open
Conversation
An html surface that sets a background/text color to a literal (hex, rgb,
hsl, white/black) instead of a --color-* theme token renders washed-out on
a board in the opposite scheme — e.g. a `background:#fff` note on a dark
board. The guide already forbids this ("dark mode is mandatory"), but the
renderer can't fix it (it can't tell an accidental light card from a
deliberate one), so it goes unnoticed until a human sees the clash.
Flag it back to the author at publish/revise time as a non-blocking
`warnings` array in the API response (same channel as `userFeedback`),
pointing at the theme tokens. Token-driven surfaces and non-html kinds are
unaffected; intentional designs are warned but never blocked.
- server/surfaceLint.ts: findHardcodedColors / lintSurfaces (bg+color only,
skips var(), SVG fill/stroke, decorative borders)
- thread warnings through publishSurface/reviseSurface + every surface-write
response
- unit tests (surfaceLint) + API integration tests (publish/revise)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Agents sometimes publish an html surface whose markdown/HTML hardcodes a light (or dark) color palette — e.g.
background:#ffffff; color:#57606a. On a board in the opposite scheme it renders washed-out and nearly unreadable:#ffffffon a dark board--color-*tokensThis was reported as "the agent sometimes generates markdown that doesn't match the theme (dark + light)." Root-caused by reproduction: it's not markdown (markdown surfaces are transparent and escape raw HTML), not a theming/cache/timing bug, and not the renderer — token-driven surfaces already adapt correctly. It's an
htmlsurface hardcoding colors.The guide already states the firm rule ("Theming — dark mode is mandatory … Never hardcode colors"), and the renderer can't fix it after the fact: it can't distinguish an accidental light card from a deliberate one (some light/dark designs are intentional). So the clash goes unnoticed until a human sees it.
Change
Flag it back to the author at publish/revise time as a non-blocking
warningsarray in the API response — the same channel that already carriesuserFeedback:{ "id": "…", "sessionId": "…", "version": 1, "warnings": ["surface hardcodes colors (background: #ffffff, color: #57606a) — drive color from the --color-* theme tokens so it adapts to light/dark; hardcoded colors render washed-out on a board in the opposite scheme."] }server/surfaceLint.ts—findHardcodedColors/lintSurfaces. Scans inlinestyle="…"and<style>blocks for background/color declarations with a literal value (hex / rgb / hsl / white|black). Skipsvar(--…)(includingvar(--x, #fff)fallbacks), SVGfill/stroke, and decorative borders to keep false positives down.publishSurface+reviseSurface(and the per-surface append/replace/remove/reorder paths) into every surface-write response.Tests
test/surfaceLint.test.ts— detector unit tests (hex/rgb/hsl/named,<style>blocks,var()incl. fallback, SVG/border exclusion, cap, 1-based labels).test/api.test.ts— integration: publishing a hardcoded surface returnswarnings; a token-driven surface returns none; revising into hardcoded colors warns too.npm test(413),npm run typecheck,npm run lint,npm run format:checkall green.🤖 Generated with Claude Code