Skip to content

Add Stylelint design-token enforcement for Svelte style blocks - #2663

Merged
malibio merged 3 commits into
mainfrom
issue-2589-stylelint-design-tokens
Sep 16, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-2589-stylelint-design-tokens

Conversation

@malibio

@malibio malibio commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds Stylelint as the CSS-side regression gate for the design system, closing the coverage hole described in #2589: eslint-plugin-svelte cannot parse CSS inside Svelte <style> blocks, which is exactly where nearly all the design-system drift lives.

The gate enforces three DESIGN.md constraints and is wired into packages/desktop-app's quality:check / quality:fix, so it runs as part of the existing mandatory gate rather than as a separate, skippable script.

What's enforced

Constraint Rule
Colors come from tokens Raw hex / rgb() / hsl() literals rejected on every color-bearing property. hsl(var(--token)) — this codebase's token idiom — passes.
Shadows only on floating surfaces box-shadow limited to DESIGN.md's floating-surface value, none (modal panels), or a token-built shadow (focus rings).
Motion is off except two cases transition limited to width 0.25s ease-out (sidebar) and opacity 0.2s ease (code-block buttons). animation and @keyframes rejected outright.

Baseline, not a big-bang fix

The audit's violations are real and still present — 248 of them across 44 files. Failing the mandatory gate on all of them would block every unrelated change until the remediation issues (#2590–#2594) land.

So scripts/check-design-tokens.ts compares Stylelint's output against a recorded baseline (design-tokens-baseline.json) and fails only on violations that are not in it. New drift is caught immediately; the existing backlog is worked down separately.

The baseline is a ratchet: it is also an error for it to contain entries that no longer occur, so fixing a file forces the baseline down and the count can never silently grow back.

bun run --cwd packages/desktop-app quality:design-tokens            # check (runs in quality:fix)
bun run --cwd packages/desktop-app quality:design-tokens --list     # print current violations
bun run --cwd packages/desktop-app quality:design-tokens --update   # re-record after fixing some

Notes on rule design

Two cases needed care, and both are covered by tests:

  • The approved shadow is itself a literal. DESIGN.md specifies 0 4px 6px -1px rgb(0 0 0 / 0.1), …, so a naive raw-color rule rejects the very value the spec mandates. It is exempted on box-shadow, and matched whitespace-insensitively since the formatter wraps it across lines.
  • Focus rings use box-shadow but are not elevation. 0 0 0 2px hsl(var(--ring) / 0.2) is correct, tokenized code; the shadow allowlist permits token-built shadows so these are not false positives.

stylelint-declaration-strict-value was evaluated for the color rule and rejected: ignoreFunctions: true lets rgba(0,0,0,0.5) through, and ignoreFunctions: false rejects hsl(var(--token)). Neither expresses "a color function is fine iff its argument is a token," so the rule is a regex on Stylelint's built-in declaration-property-value-disallowed-list instead.

Also note customSyntax: postcss-html is applied per-extension rather than globally — applied globally it makes plain .css files parse as empty and silently skips every rule on them, which would have excluded noderef.css (15 violations) from the gate entirely.

Violations at time of landing

Per the acceptance criteria, this is the checklist the remediation issues can work against. Totals: 152 color, 12 shadow, 84 motion = 248 across 44 files.

File Color Shadow Motion Total
src/lib/design/components/diagnostic-panel.svelte 30 30
src/lib/components/collaboration/invitations-inbox.svelte 24 1 25
src/lib/styles/noderef.css 7 8 15
src/lib/components/viewers/ai-chat-pty-session.svelte 10 4 14
src/lib/components/delete-confirmation-modal.svelte 12 1 13
src/lib/components/settings/model-manager.svelte 8 5 13
src/lib/components/conflict-toast.svelte 7 1 3 11
src/lib/components/update-banner.svelte 10 1 11
src/lib/components/onboarding/onboarding-wizard.svelte 7 1 2 10
src/lib/components/subtree-access-denied-modal.svelte 9 1 10
src/lib/components/viewers/ai-chat-node-viewer.svelte 4 1 4 9
src/lib/components/layout/navigation-sidebar.svelte 8 8
src/lib/components/layout/collection-sub-panel.svelte 1 1 4 6
src/lib/components/pro-relogin-modal.svelte 5 1 6
src/routes/+layout.svelte 6 6
src/lib/components/viewers/query-node-viewer.svelte 5 5
src/lib/components/autocomplete-modal.svelte 4 4
src/lib/components/first-pro-consent-modal.svelte 3 1 4
src/lib/components/layout/tab-system.svelte 4 4
src/lib/components/query/query-editor.svelte 4 4
src/lib/components/viewers/collection-node-viewer.svelte 4 4
src/app.css 3 3
src/lib/components/chat/chat-message.svelte 3 3
src/lib/components/collaboration/collaboration-locked.svelte 3 3
src/lib/components/node-tree.svelte 3 3
src/lib/components/dev/version-badge.svelte 2 2
src/lib/components/first-pro-consent-slot.svelte 1 1 2
src/lib/components/ui/slash-command-dropdown/slash-command-dropdown.svelte 2 2
src/lib/design/components/code-block-node.svelte 1 1 2
src/lib/design/components/node-row.svelte 2 2
src/lib/components/agent/pty-terminal.svelte 1 1
src/lib/components/chat/chat-input.svelte 1 1
src/lib/components/collaboration/collaboration-view.svelte 1 1
src/lib/components/layout/database-switcher.svelte 1 1
src/lib/components/layout/pane-manager.svelte 1 1
src/lib/components/query/kanban-view.svelte 1 1
src/lib/components/query/list-view.svelte 1 1
src/lib/components/references/base-node-reference.svelte 1 1
src/lib/components/references/node-ref-preview.svelte 1 1
src/lib/components/status-bar.svelte 1 1
src/lib/components/ui/node-autocomplete/node-autocomplete.svelte 1 1
src/lib/components/viewers/date-node-viewer.svelte 1 1
src/lib/design/components/backlinks-panel.svelte 1 1
src/lib/design/components/theme-provider.svelte 1 1
Total (44 files) 152 12 84 248

The three violations in src/app.css are real: a leftover @keyframes blink demo animation and two background-color 0.15s ease transitions (inert anyway, since app.css disables transitions globally). The file is exempt from the color rule only — raw values are what a token is — and that exemption deliberately does not extend to motion or shadows.

Testing

  • src/tests/design/stylelint-design-tokens.test.ts (30 tests) — rule behavior: what each rule accepts and rejects, that Svelte <style> blocks are parsed, that plain .css files still lint, and that the app.css exemption does not widen into a blanket disable.
  • src/tests/design/design-tokens-baseline.test.ts (8 tests) — baseline comparison: added vs fixed, duplicate counting (N identical violations are not masked by one baseline entry), and file-scoped keys.

Verified end-to-end that the gate fails on a newly introduced violation and fails on a fixed violation until the baseline is re-recorded.

Acceptance criteria

  • CSS-aware linter added and configured to parse <style> blocks in .svelte
  • Hex/rgb/hsl literals flagged, var(--token) required
  • box-shadow restricted to the DESIGN.md floating-surface value; modal panels use none
  • transition/animation/@keyframes restricted to the two approved cases
  • Wired into quality:check / quality:fix — no separate skippable script
  • Produces violations consistent with the audit (diagnostic-panel, noderef.css, modals, pills, navigation-sidebar, theme-provider all present)
  • Passes against src/app.css for color; its 3 motion violations are genuine findings, not config noise
  • Violating files documented above for the remediation issues
  • bun run quality:fix
  • bun run test:all

Closes #2589


🤖 Generated with Claude Code

…#2589)

ESLint cannot parse CSS inside Svelte `<style>` blocks, so the design-system
drift that lives there — hardcoded colors, ad-hoc shadows, unauthorized
motion — was invisible to the existing quality gate. Add Stylelint with
postcss-html as the CSS-side gate, wired into quality:check/quality:fix.

Three rules, from the design spec:
- Color literals rejected on color-bearing properties; hsl(var(--token)) passes
- box-shadow limited to the floating-surface value, none, or a token shadow
- transition limited to the two approved cases; animation/@Keyframes rejected

The codebase has 248 pre-existing violations across 44 files. Failing the
mandatory gate on all of them would block every unrelated change until the
remediation issues land, so scripts/check-design-tokens.ts compares against a
recorded baseline and fails only on new drift. The baseline is a ratchet: it
is also an error for it to contain entries that no longer occur, so fixing a
file forces the baseline down and the count cannot silently grow back.

Two rule-design details, both covered by tests:
- The approved shadow is itself specified as a literal rgb() value, so it is
  exempted on box-shadow and matched whitespace-insensitively (the formatter
  wraps it across lines).
- Focus rings use box-shadow but are not elevation, so token-built shadows are
  allowed rather than reported as false positives.

customSyntax is applied per-extension rather than globally: applied globally
it parses plain .css files as empty and silently skips every rule on them,
which would have excluded noderef.css from the gate entirely.

stylelint-declaration-strict-value was evaluated and rejected — ignoreFunctions
true allows rgba(0,0,0,0.5), false rejects hsl(var(--token)) — so the color
rule is a regex on the built-in declaration-property-value-disallowed-list.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2663 (issue #2589)

Review Type: Initial Review

Requirements Check

# Criterion Status Note
1 CSS-aware linter parses <style> blocks in .svelte ✅ stylelint@^17.15.0 + postcss-html@^2.0.0; verified.
2 Flags hex/rgb/hsl literals, requires var(--token) ⚠️ Works for hex and numeric color functions. Misses named CSS colors and component-local custom properties — F1/F2.
3 box-shadow allowlist; rejects modal-panel shadows ✅ Approved value passes (incl. line-wrapped and !important), token focus rings pass, literal elevation rejected. The negative-lookahead bypass probe (approved value + appended literal) is correctly caught.
4 transition/animation/@keyframes allowlist ⚠️ Core cases work, but the two approved transitions cannot be combined, and vendor-prefixed keyframes escape — F4/F5.
5 Wired into quality:check/quality:fix ⚠️ Correctly wired, but no automated hook invokes them — F6.
6 Produces violations consistent with the audit ✅ 248 across 44 files (164 color, 72 shadow/motion, 12 @keyframes).
7 Zero violations against src/app.css ✅ Override drops only color entries, keeping motion bans.
8 Violating files documented ✅ Baseline JSON is machine-readable and enforced.
9 bun run quality:fix ✅
10 Tests pass ✅ 38 new tests; design suite 73/73.

Findings

🔴 F1 — Named CSS colors bypass the color rule entirely

📁 packages/desktop-app/stylelint.config.js:38

RAW_COLOR_SOURCE matches only #hex and color functions with numeric first args. Bare named colors are invisible. Verified: a component with color: white; background-color: black; → gate exits 0.

This drift exists today in a file the issue names:

src/lib/design/components/diagnostic-panel.svelte:226,340,345:    color: white;

The baseline has 30 entries for that file and zero mentioning white. So #2593 will "fix" it while three literals survive with the gate's blessing.

Fix: add a named-color alternative to RAW_COLOR_SOURCE, then re-record the baseline.
Principle: a validator's rejection set must cover the domain it claims to govern; a partial blacklist is worse than none because it stops people looking.

🔴 F2 — A component-local custom property launders any raw color

📁 packages/desktop-app/stylelint.config.js:46-68

Custom-property declarations (--foo: <value>) aren't in COLOR_PROPERTIES and aren't matched. Verified: .x { --brand: #ff00aa; color: var(--brand); } → exit 0.

A one-line, natural-looking bypass that reads as more idiomatic than the thing being blocked.

Fix: flag raw literals in custom-property declarations outside src/app.css (regex property key /^--/), reusing the existing override shape.
Principle: enforce the invariant, not one spelling of it.

🔴 F3 — stylelint-disable comments silently suppress the gate

📁 packages/desktop-app/stylelint.config.js (config root)

Verified: /* stylelint-disable */ above a #ff00aa → exit 0. CLAUDE.md: "NO lint suppression — fix issues properly."

Fix: reportDescriptionlessDisables, reportNeedlessDisables, reportInvalidScopeDisables.
Principle: a standard a tool can silently opt out of is a convention, not a gate.

🟡 F4 — The two approved transitions cannot be combined

📁 stylelint.config.js:121-128 — ^…$ anchoring rejects transition: width 0.25s ease-out, opacity 0.2s ease;, a value the spec permits. Latent false positive. Fix: match per comma-segment.

🟡 F5 — Vendor-prefixed keyframes escape

📁 stylelint.config.js:187 — @-webkit-keyframes passes. This is a Tauri/WebKit app. Fix: enumerate the prefixed forms.

🟡 F6 — The "mandatory gate" isn't enforced by any hook

📁 package.json:38-40, scripts/test-gate.ts — the pre-push hook never runs quality:check, and there's no CI. Separately (pre-existing, not this PR): root quality:check calls a quality script that doesn't exist in desktop-app. Fix: add the design-token check to test-gate.ts; file the root typo separately.

🟢 F7–F10

readBaseline() trusts JSON shape (fails closed, but with a stack trace not a diagnosis); --update has no guard against silencing new drift; baseline keying is the right tradeoff but a file rename forces a re-record (worth a readme line); color-mix()/gradients collapse into F1.

Verified correct

  • Fail-closed is solid — missing baseline, corrupt JSON, wrong shape, and empty glob all exit non-zero. No path yields a green gate on a broken setup.
  • Shadow negative-lookahead is correctly grouped; appending a literal to the approved shadow is caught by both rules.
  • !important handled — matters, since app.css:191 uses that form.
  • Per-extension customSyntax is right and non-obvious, and pinned by a test.
  • Test quality is genuinely good — behavior through the real Stylelint API, not implementation restatement.
  • CLAUDE.md compliance clean apart from F3; console.* in a tooling script is correct here.

On the baseline approach

The ratchet is the right call. Failing on all 248 would block every unrelated PR until five remediation issues land, which means someone disables the gate within a day. The fixed > 0 check makes the count monotonically non-increasing — a stronger property than the issue asked for.

The caveat: the ratchet's value is bounded by rule coverage. F1/F2 mean 248 undercounts real drift and the floor it defends has holes. Fixing them before merge preserves the guarantee.

Recommendation

REQUEST CHANGES — blocking: F1, F2, F3. Strongly recommended same pass: F4, F5, F6.

The architecture is right; the gaps are in coverage. For a regression gate specifically, "mostly catches it" is the failure mode that matters most.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks requesting changes on your own PR). Blocking: F1 (named CSS colors bypass the color rule), F2 (custom-property declarations launder raw colors), F3 (stylelint-disable silently suppresses the gate). Full findings in the review comment above.

The gate let through the exact drift it targets. Each bypass below was
reproduced against the real linter before and after the fix.

F1 — named CSS colors were invisible to the color rule, which matched only
hex and numeric color functions. `color: white` passed. This was not
hypothetical: diagnostic-panel.svelte has three such declarations, in a file
the remediation set targets, and the baseline recorded none of them. Adds the
full CSS named-color list.

F2 — a component-local custom property laundered any literal:
`--brand: #ff00aa` then `color: var(--brand)` passed every rule and reads as
more idiomatic than the thing being blocked. Adds a `/^--/` property key.

F3 — `stylelint-disable` silently switched the gate off, against CLAUDE.md's
no-suppression rule. reportDescriptionlessDisables alone was insufficient (it
only flags a disable *without* a description, leaving a one-word bypass), so
configurationComment is renamed: `stylelint-disable` is no longer a recognized
directive and suppresses nothing.

Also:
- transition is matched per comma-segment, so the two approved transitions can
  be combined on one element rather than rejected for being combined (F4)
- vendor-prefixed @Keyframes enumerated; this app ships on WebKit (F5)
- the design-token check runs in scripts/test-gate.ts, so the gate is enforced
  by the push hook rather than by remembering to run it (F6)
- readBaseline validates shape and reports the problem instead of throwing a
  stack trace from inside the diff (F7)
- the baseline readme notes that a file rename needs a re-record (F9)

Adding named colors initially introduced a false positive — `\b` matched
inside identifiers, so `var(--white-overlay)` was rejected. Now bounded by
`(?<![\w-])`/`(?![\w-])`, with tests for leading, trailing and embedded color
words in token names. A gate that rejects correct code gets disabled.

Not done: an --update guard (F8). The ratchet already surfaces silencing as a
baseline-count increase in review, which is the signal that matters.

Baseline re-recorded 248 -> 251. Design-token tests 30 -> 43, diff tests 8 -> 9.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

Review response

All three blocking findings fixed, plus F4–F7 and F9. Baseline re-recorded: 248 → 251.

Addressed

Finding Fix
🔴 F1 named colors bypass Full CSS named-color list added to RAW_COLOR_SOURCE
🔴 F2 custom-property laundering /^--/ regex property key flags raw colors in custom-property declarations
🔴 F3 stylelint-disable suppression configurationComment renamed + the three report*Disables options
🟡 F4 transitions can't combine transition matched per comma-segment
🟡 F5 prefixed keyframes escape -webkit-/-moz-/-o-/-ms- enumerated
🟡 F6 gate not actually enforced Design-token check added to scripts/test-gate.ts (pre-push)
🟢 F7 opaque malformed-baseline error readBaseline() validates shape, reports cleanly without a stack trace
🟢 F9 rename cost undocumented Noted in the baseline readme string

Two notes where I diverged from the suggestion

F3 needed more than report*Disables. Those options only flag a descriptionless disable — I verified /* stylelint-disable -- reason */ still suppressed silently, so the fix as proposed left a one-word bypass. Also renamed configurationComment, which makes stylelint-disable an ordinary comment that suppresses nothing. Both forms now report, covered by three tests.

F1 introduced a false positive, caught by its own new test. \b around named colors meant var(--white-overlay) was flagged, because white matched inside the token name — rejecting correct code. Switched to (?<![\w-])/(?![\w-]), with four cases covering leading, trailing and embedded color words in token names. A gate that rejects valid work gets disabled fast, so this mattered more than the original gap.

Skipped

  • F8 (--update guard) — the ratchet already makes silencing visible in review as a baseline-count increase; a --force flag adds ceremony over an existing signal. Worth revisiting if a baseline increase ever lands unnoticed.
  • F10 — folds entirely into F1; no separate action needed.

The three newly-caught violations

Exactly the drift the review identified as invisible:

src/lib/design/components/diagnostic-panel.svelte:226,340,345    color: white;

A file remediation issue #2593 targets, previously unrecorded in the baseline.

Verification

  • quality:fix — exit 0 (svelte-check 0 errors, clippy clean)
  • test:all — exit 0
  • Design-token tests: 30 → 43; baseline diff tests: 8 → 9
  • Manually re-verified all three bypasses now report, and both malformed-baseline paths (missing array, bad entry index) fail closed with actionable messages

One self-inflicted issue worth recording: the F7 change initially failed svelte-check because an arrow function's never return doesn't propagate for type narrowing. Fixed with function declarations plus an isViolation type guard.

…terals

Adding named colors made the color rule scan raw declaration values, so a
color word anywhere inside a URL path or a quoted string was reported as a
literal — `url(/img/gold.png)` came back as `Raw color literal
"url(/img/gold.png)"`, which also misdescribes the value.

Two things made this worth fixing before the remediation issues start:

- the `/^--/` key put every custom property under the color rule, so one
  holding a URL, a grid-area list or a content string was scanned for color
  words
- a `data:` URI payload containing `stroke='white'` was flagged, and icon
  components are full of those — it would have fired on a correct icon change

Boundary widened from `(?<![\w-])`/`(?![\w-])` to `(?<![\w\-./'"(])` and
`(?![\w\-./'"])`. Detection is unweakened: `linear-gradient(white, black)` is
still caught, verified explicitly because `(` is now in the lookbehind.

`--anim-name: plum` still flags, deliberately. A bare word in a custom
property is genuinely ambiguous between an animation name and a color, with
nothing in the declaration to separate them, so flagging is the safer default.

Also documents the override spelling in the config — it was previously
discoverable only by reading stylelint's internals.

Design tests 95 -> 103. Baseline holds at 251, so no genuine finding was lost.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review follow-up: N1 fixed

Re-review returned APPROVE with one non-blocking finding. Fixed it here rather than deferring, since it was a regression my own F1 fix introduced and it lands squarely where the remediation work is headed.

N1 — color words inside URLs and quoted strings read as literals

url(/img/gold.png) was reported as Raw color literal "url(/img/gold.png)" — a false positive on correct code, with a message about design tokens that explains nothing about the actual value.

Two things made this worth fixing now rather than following up:

Boundary widened from (?<![\w-])/(?![\w-]) to (?<![\w\-./'"(])/(?![\w\-./'"]).

Now clean: url(/img/gold.png), url(red.svg), --icon: url(white.svg), content: "red", grid-area: navy, font-family: 'Gill Sans', Tahoma, and the data: URI with stroke='white'.

Still caught — the wider boundary does not weaken detection: color: white, border: 1px solid silver, caret-color: tan, --surface: white, and linear-gradient(white, black) (verified explicitly, since ( is now in the lookbehind).

One deliberate non-fix

--anim-name: plum still flags. A bare word in a custom property is genuinely ambiguous between an animation name and a color, and there's no signal in the declaration to tell them apart — flagging is the safer default. The documented override exists for the rare real case.

Nit also addressed

The override spelling is now documented in the config. It was previously discoverable only by reading stylelint's internals:

/* stylelint-design-token-override-disable-next-line <rule> -- <reason> */

Verification

  • Design tests 95 → 103 (7 URL/string cases + 1 gradient-still-caught guard)
  • Baseline holds at 251 — the fix removed no genuine findings
  • quality:fix exit 0, test:all exit 0

@malibio
malibio merged commit 5c44bf9 into main Sep 16, 2026
@malibio
malibio deleted the issue-2589-stylelint-design-tokens branch September 16, 2026 19:53
malibio added a commit that referenced this pull request Sep 16, 2026
Blocker (🔴): #2663 landed the design-token ratchet while this PR was in
flight, wiring `quality:design-tokens` into quality:check/quality:fix. The
gate failed with 21 net-new violations in diagnostic-panel.svelte.

The mechanism is subtle: design-tokens-baseline.json keys entries on
file/rule/text, and `text` embeds the literal verbatim. The baseline held
`var(--color-text-muted, #888)`. Unwrapping that dead var() to a bare #888 —
correct in itself, since --color-text-muted is defined nowhere — produced a
different key, so the gate read the result as net-new drift.

Fix the cause rather than the symptom: define six theme-invariant --console-*
tokens in app.css and swap all 21 literals. HSL values round-trip to the exact
original hex, so the console is pixel-identical. The panel keeps its deliberate
dark-in-both-themes appearance while satisfying the token rule, and the
rationale moves to app.css where the tokens are defined.

This drives the baseline DOWN from 251 to 194 (-57): diagnostic-panel goes from
33 entries to 0. The baseline is re-recorded because violations were *fixed*,
which the ratchet requires — not to absorb new ones, which it forbids.

Important (🟡): remove `box-shadow` from .modal in invitations-inbox.svelte.
DESIGN.md reserves elevation shadows for floating surfaces; modal panels get
none, since the backdrop provides separation. This PR rewrote the .modal block
two lines above and should have caught it.

Comment corrections (🟡/🟢): the --*-light rationale said those tokens "flip"
lightness, which is imprecise — the real disqualifier is that they have no
paired --*-light-foreground token. The badge comment's "~2.5-2.8:1" also
omitted that white-on---destructive clears AA in light at 4.57:1; the binding
constraint is the 2.86:1 dark case. Both now state the measured figures,
including .status.error sitting at 2.88:1 in light.

Not addressed: the rgba(0,0,0,0.5) overlay scrim (1 remaining baseline entry).
It is the identical value used by all four other modals, and no overlay token
exists. Inventing a one-off here would break that consistency; it belongs to
the modals remediation issue.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
malibio added a commit that referenced this pull request Sep 16, 2026
… tokens (closes #2592) (#2669)

* Replace hardcoded status colors and phantom CSS variables with design tokens (closes #2592)

diagnostic-panel.svelte and invitations-inbox.svelte bypassed the app.css
semantic token system in two ways: hardcoded status hex literals, and
references to a parallel CSS-variable vocabulary (--surface-1, --color-border,
--text-primary, …) that is defined nowhere in the repo and so always resolved
to its hardcoded fallback.

The second problem was the more serious one. invitations-inbox.svelte is a
user-facing modal whose fallbacks were all light-mode values, so it rendered as
a white panel with dark text in dark mode regardless of theme — a real theming
bug masked by token-shaped syntax that did nothing.

Map status colors to --success/--destructive/--warning/--primary and chrome to
--card/--foreground/--muted-foreground/--border, using hsl(var(--token)): the
tokens are HSL triplets, so the rgb(var(--token) / alpha) form is wrong here.
Ring/tint alpha follows the existing noderef.css:386 precedent.

Contrast-check every mapping in both themes rather than matching by hue. Three
pairings that looked correct fail WCAG AA:

- State tags on --*-light: those tokens flip lightness between themes (pale in
  light, dark in dark), so no single foreground works — 2.22:1 and 3.41:1 in
  dark. Use a 0.15 tint of the solid token instead (12.7-17.7:1 both themes).
- .status.success/.status.error badges: --success-foreground and
  --destructive-foreground are white in BOTH themes, landing at 2.55-2.83:1 on
  the solid mid-tone fills. Tint the background and use the state color as text.
- .init-error-banner: white passes in light (4.57:1) but fails in dark (2.86:1)
  and the inverse foreground fails in light. Tinted for the same reason.

diagnostic-panel.svelte stays a fixed dark console in both themes — it is a
monospace developer tool, and mapping its surfaces to --background/--foreground
would turn it white in light mode. Its surface greys remain explicit literals
with the dead var() wrappers removed so the intent is honest, and a comment
records why. Its status colors are tokenized and verified legible (4.17-7.68:1)
against that surface.

Known residual: .ok text is 2.83:1 in light mode. Neither --success nor
--success-light is dark enough for body text on a white card; this is a gap in
the token set rather than a mapping error, and warrants a separate issue.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Correct the repo-structure tree in CLAUDE.md

The tree listed packages/design-system/, which does not exist, and omitted five
packages that do: nodespace-types, proto, daemon, cli, and skill. dev-tools was
described as "Development utilities" when it is specifically a Bun dev-proxy.

Descriptions are taken from each package's own manifest (Cargo.toml
`description` for the Rust crates, package.json for skill and dev-tools), and
package order now follows the Cargo workspace members list. Also point at where
the design system actually lives — packages/desktop-app/src/lib/design/ plus
app.css for the color tokens — since that is what the missing design-system
entry was gesturing at, and add the assets/ directory.

Verified: every packages/ path referenced anywhere in CLAUDE.md now resolves.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Address review: add --console-* tokens, drop the modal shadow

Blocker (🔴): #2663 landed the design-token ratchet while this PR was in
flight, wiring `quality:design-tokens` into quality:check/quality:fix. The
gate failed with 21 net-new violations in diagnostic-panel.svelte.

The mechanism is subtle: design-tokens-baseline.json keys entries on
file/rule/text, and `text` embeds the literal verbatim. The baseline held
`var(--color-text-muted, #888)`. Unwrapping that dead var() to a bare #888 —
correct in itself, since --color-text-muted is defined nowhere — produced a
different key, so the gate read the result as net-new drift.

Fix the cause rather than the symptom: define six theme-invariant --console-*
tokens in app.css and swap all 21 literals. HSL values round-trip to the exact
original hex, so the console is pixel-identical. The panel keeps its deliberate
dark-in-both-themes appearance while satisfying the token rule, and the
rationale moves to app.css where the tokens are defined.

This drives the baseline DOWN from 251 to 194 (-57): diagnostic-panel goes from
33 entries to 0. The baseline is re-recorded because violations were *fixed*,
which the ratchet requires — not to absorb new ones, which it forbids.

Important (🟡): remove `box-shadow` from .modal in invitations-inbox.svelte.
DESIGN.md reserves elevation shadows for floating surfaces; modal panels get
none, since the backdrop provides separation. This PR rewrote the .modal block
two lines above and should have caught it.

Comment corrections (🟡/🟢): the --*-light rationale said those tokens "flip"
lightness, which is imprecise — the real disqualifier is that they have no
paired --*-light-foreground token. The badge comment's "~2.5-2.8:1" also
omitted that white-on---destructive clears AA in light at 4.57:1; the binding
constraint is the 2.86:1 dark case. Both now state the measured figures,
including .status.error sitting at 2.88:1 in light.

Not addressed: the rgba(0,0,0,0.5) overlay scrim (1 remaining baseline entry).
It is the identical value used by all four other modals, and no overlay token
exists. Inventing a one-off here would break that consistency; it belongs to
the modals remediation issue.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Address review: tighten the badge-contrast comment

Re-review nit (🟢, explicitly non-blocking): the comment enumerated five
contrast ratios to justify one decision, and "white-on---destructive" read
badly as a triple hyphen.

Keep what stays useful at the call site — why a solid fill is not an option,
and the one accepted sub-AA-large case — and drop the rejected-alternative
figures, which are working notes rather than a standing constraint. They remain
in the commit history and PR discussion if anyone needs to re-derive the
decision.

Comment-only; no behavioral change. Retained figures re-verified: solid fill is
2.55:1/2.86:1 in dark, and the tint clears 3:1 everywhere except .status.error
at 2.88:1 in light (3.92/4.29/3.97 for the rest).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

Add Stylelint enforcement for design tokens, shadows, and transitions in Svelte components

1 participant