Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

Description

@kateebonner

Important

Problem

The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

Approach

Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

Scope

In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


Acceptance Criteria

  • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
  • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
  • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
  • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
  • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
  • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
  • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
  • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
  • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

Testing Decisions

CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

Key Decisions

  • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
  • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
  • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
  • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
  • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

Constraints & Invariants

  • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
  • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
  • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
  • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
  • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
  • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
Prior Art / Patterns
  • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
  • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
  • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

Source

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    afkImplement + merge unattended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
       blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
      }
      } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
      })();
      (function(){
      try {
      var __m = "github.com";
      var __re = new RegExp('^' + "github\\.com" + '
      
      Skip to content

      Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

      Description

      @kateebonner

      Important

      Problem

      The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

      Approach

      Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

      Scope

      In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
      Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


      Acceptance Criteria

      • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
      • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
      • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
      • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
      • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
      • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
      • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
      • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
      • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

      Testing Decisions

      CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

      Key Decisions

      • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
      • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
      • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
      • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
      • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

      Constraints & Invariants

      • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
      • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
      • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
      • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
      • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
      • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
      Prior Art / Patterns
      • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
      • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
      • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

      Source

      Activity

      Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

      Metadata

      Metadata

      Assignees

      No one assigned

        Labels

        afkImplement + merge unattended

        Type

        No type

        Projects

        No projects

          Milestone

          No milestone

          Relationships

          None yet

          Development

          No branches or pull requests

          Issue actions

          , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
          Skip to content

          Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

          Description

          @kateebonner

          Important

          Problem

          The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

          Approach

          Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

          Scope

          In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
          Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


          Acceptance Criteria

          • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
          • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
          • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
          • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
          • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
          • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
          • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
          • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
          • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

          Testing Decisions

          CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

          Key Decisions

          • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
          • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
          • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
          • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
          • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

          Constraints & Invariants

          • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
          • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
          • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
          • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
          • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
          • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
          Prior Art / Patterns
          • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
          • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
          • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

          Source

          Activity

          Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

          Metadata

          Metadata

          Assignees

          No one assigned

            Labels

            afkImplement + merge unattended

            Type

            No type

            Projects

            No projects

              Milestone

              No milestone

              Relationships

              None yet

              Development

              No branches or pull requests

              Issue actions

              , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
              Skip to content

              Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

              Description

              @kateebonner

              Important

              Problem

              The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

              Approach

              Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

              Scope

              In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
              Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


              Acceptance Criteria

              • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
              • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
              • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
              • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
              • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
              • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
              • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
              • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
              • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

              Testing Decisions

              CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

              Key Decisions

              • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
              • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
              • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
              • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
              • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

              Constraints & Invariants

              • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
              • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
              • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
              • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
              • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
              • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
              Prior Art / Patterns
              • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
              • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
              • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

              Source

              Activity

              Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

              Metadata

              Metadata

              Assignees

              No one assigned

                Labels

                afkImplement + merge unattended

                Type

                No type

                Projects

                No projects

                  Milestone

                  No milestone

                  Relationships

                  None yet

                  Development

                  No branches or pull requests

                  Issue actions

                  , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
                  Skip to content

                  Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

                  Description

                  @kateebonner

                  Important

                  Problem

                  The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

                  Approach

                  Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

                  Scope

                  In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
                  Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


                  Acceptance Criteria

                  • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
                  • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
                  • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
                  • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
                  • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
                  • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
                  • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
                  • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
                  • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

                  Testing Decisions

                  CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

                  Key Decisions

                  • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
                  • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
                  • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
                  • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
                  • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

                  Constraints & Invariants

                  • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
                  • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
                  • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
                  • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
                  • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
                  • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
                  Prior Art / Patterns
                  • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
                  • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
                  • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

                  Source

                  Activity

                  Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                  Metadata

                  Metadata

                  Assignees

                  No one assigned

                    Labels

                    afkImplement + merge unattended

                    Type

                    No type

                    Projects

                    No projects

                      Milestone

                      No milestone

                      Relationships

                      None yet

                      Development

                      No branches or pull requests

                      Issue actions

                      , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
                      Skip to content

                      Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

                      Description

                      @kateebonner

                      Important

                      Problem

                      The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

                      Approach

                      Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

                      Scope

                      In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
                      Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


                      Acceptance Criteria

                      • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
                      • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
                      • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
                      • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
                      • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
                      • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
                      • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
                      • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
                      • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

                      Testing Decisions

                      CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

                      Key Decisions

                      • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
                      • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
                      • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
                      • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
                      • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

                      Constraints & Invariants

                      • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
                      • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
                      • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
                      • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
                      • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
                      • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
                      Prior Art / Patterns
                      • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
                      • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
                      • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

                      Source

                      Activity

                      Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                      Metadata

                      Metadata

                      Assignees

                      No one assigned

                        Labels

                        afkImplement + merge unattended

                        Type

                        No type

                        Projects

                        No projects

                          Milestone

                          No milestone

                          Relationships

                          None yet

                          Development

                          No branches or pull requests

                          Issue actions

                          , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
                          Skip to content

                          Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

                          Description

                          @kateebonner

                          Important

                          Problem

                          The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

                          Approach

                          Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

                          Scope

                          In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
                          Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


                          Acceptance Criteria

                          • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
                          • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
                          • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
                          • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
                          • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
                          • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
                          • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
                          • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
                          • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

                          Testing Decisions

                          CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

                          Key Decisions

                          • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
                          • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
                          • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
                          • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
                          • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

                          Constraints & Invariants

                          • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
                          • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
                          • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
                          • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
                          • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
                          • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
                          Prior Art / Patterns
                          • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
                          • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
                          • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

                          Source

                          Activity

                          Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                          Metadata

                          Metadata

                          Assignees

                          No one assigned

                            Labels

                            afkImplement + merge unattended

                            Type

                            No type

                            Projects

                            No projects

                              Milestone

                              No milestone

                              Relationships

                              None yet

                              Development

                              No branches or pull requests

                              Issue actions

                              , 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
                              Skip to content

                              Derive two AA-floored, chat-theme-keyed Glass tint tiers with a contrast test #60

                              Description

                              @kateebonner

                              Important

                              Problem

                              The Brain becomes the Chat's full-bleed background (see #56), so every component will sit on a translucent surface over a moving, sometimes bright-yellow graph. Legibility must be guaranteed by construction, and that guarantee has to exist and be tested before any component is restyled — the earlier build shipped a tint that silently failed AA over its worst frame.

                              Approach

                              Build the Glass token layer as a standalone, contrast-proven artifact decoupled from any component work. A theme-agnostic generator derives two tint tiers — standard (prose, bubbles, composer) and dense (code, diffs, run-plots, tool-cards, more opaque) — whose opacities are computed, not eyeballed, to clear the WCAG-AA floor with a small safety margin over a per-mode reference frame: the worst-case opaque feature the Brain engine's own palette actually paints in that mode (dark: the peak-bloom thought #fff676, the brightest value, worst for near-white text; light: the darkest solid feature the light palette paints, #8f8000, worst for near-black text). The frame is fixed — a synthetic worst case, never per-frame readback — but it is not mode-independent. Blur is one high constant shared by both tiers (calm, cheap, never credited toward contrast); the tint carries all contrast. The generator keys off the chat theme's own resolved tokens and emits CSS exposing the tiers via a stable data-glass hook, restyling nothing. A headless contrast test that composites tint-over-reference-frame is the legibility guarantee.

                              Scope

                              In: a theme-agnostic two-tier derivation (pure function of a resolved theme's tokens + that mode's worst-case reference frame); the generator + generate:glass script + committed generated CSS; the data-glass="standard"|"dense" hook and per-tier CSS vars keyed by the chat theme's existing data-theme/data-color-scheme attributes; a @supports not (backdrop-filter) opaque fallback; a headless contrast test proving the default chat theme oc-2 (light + dark) clears every floor.
                              Out: floating/restyling any real component on Glass (no component touched — later slices consume the hook; keeps this slice a pure, provable token layer). The Brain-as-background mount and live re-validation on theme switch (this slice ships the derivation + keying; wiring is downstream). Hand-validating the other 35 bundled third-party themes (their palettes are author-owned and some ship native sub-3:1 marks a backing tint cannot raise; body-text AA still generalizes by construction). Blur radius tuning and any perf work (blur is a single constant here, not contrast-load-bearing).


                              Acceptance Criteria

                              • Standard tint, body text: for the default chat theme oc-2 in both light and dark modes, the shipped standard tint composited over that mode's reference frame (dark = opaque #fff676; light = opaque #8f8000) yields body-text (text-strong) contrast ≥ 4.5:1, and the value the derivation targeted is ≥ 4.8:1 (the small safety margin is actually present, not sitting on the 4.5 cliff). Measured numerically against the fixture, no rendering.
                              • Dense tint, code/diff text: for oc-2 light + dark, the shipped dense tint over that mode's reference frame yields code/diff text (text-strong) contrast ≥ 4.5:1 (target ≥ 4.8:1).
                              • Dense tint, graphical marks (WCAG 1.4.11): for oc-2 light + dark, for every graphical-mark color in the set {theme syntax tokens, diff add/delete fills, run-plot series strokes}, its contrast over the dense composite is ≥ 3:1 whenever that mark clears 3:1 on the theme's own base surface, and in all cases is no more than 0.2 below its contrast over the theme's own base surface (the dense tint never degrades a mark relative to native rendering).
                              • Dense is strictly more opaque than standard: derived dense alpha > standard alpha for each oc-2 mode.
                              • Blur is one shared constant: the emitted blur radius is identical for both tiers, greater than zero, and blur is never used as a term in the derivation or the contrast test (tint alone clears every floor).
                              • Chat-theme-keyed, not hardcoded: the derivation is a pure function of the resolved theme tokens (plus that mode's reference frame) — feeding two token sets that differ in text/surface (e.g. oc-2 dark vs. oc-2 light) produces different standard alphas. The emitted CSS scopes each tier's tokens under html[data-theme="<id>"][data-color-scheme="<mode>"], matching the attributes the chat theme system already stamps.
                              • Stable hook, nothing restyled: the generated CSS exposes exactly data-glass="standard" and data-glass="dense" surfaces (background tint + shared blur + hairline edge + elevation); applying no data-glass attribute anywhere, the app's rendered output is unchanged (this slice adds the layer, wires it to no component).
                              • No-backdrop-filter fallback: under @supports not (backdrop-filter), both tiers fall back to a near-opaque tint so text can never land on the bare animated canvas.
                              • Generated CSS is in sync: re-running the generator reproduces the committed generated CSS byte-for-byte (drift guard).

                              Testing Decisions

                              CREATE one new headless test file for the glass token module (there is no glass test on the current branch to extend; slice 1 adds no glass surface). Follow the existing headless discipline of the brain-engine test — bun:test, pure numbers, no DOM, no rAF. Reuse the WCAG helpers ported from the old branch (toLinear/luminance/composite/contrast) rather than reimplementing sRGB math; the test imports the module's exported derive + contrast functions and pulls oc-2's concrete token values through the theme resolve API. The reference frame per mode is the brain engine's own worst-case painted feature — dark #fff676, light #8f8000 — read from the engine's PALETTES (not a mode-independent literal). Concrete tests to write, all as numeric assertions over the fixture: (1) standard body contrast ≥ 4.5 and derived target ≥ 4.8, for oc-2 light and dark, each over its mode's reference frame; (2) dense text contrast ≥ 4.5 / target ≥ 4.8, both modes; (3) dense graphical-mark rule — iterate the mark set {syntax tokens ∪ diff add/delete fills ∪ run-plot series strokes}, assert each mark over the dense composite is ≥ 3:1 when it is ≥ 3:1 over the theme's base surface, and is never more than 0.2 below its base-surface contrast, both modes; (4) dense alpha > standard alpha per mode; (5) blur constant equal across tiers, > 0, and (guard) the derive path takes no blur argument; (6) purity/keying — derive over dark tokens+frame vs light tokens+frame gives distinct standard alphas; (7) fallback — the @supports block resolves both tiers to alpha ≥ 0.92; (8) drift — generateGlassCss() output equals the committed generated CSS string. No visual/screenshot test in this slice; contrast is proven arithmetically. This test file is the surface later slices EXTEND when they add a theme or a mark class.

                              Key Decisions

                              • Reference frame = a fixed, per-mode worst-case Brain feature, read from the engine's own PALETTES[mode] — a synthetic worst case, NOT per-frame readback (the rejected dynamic-contrast path). Two backdrops, because the worst frame differs by mode: dark = the peak-bloom thought #fff676 (brightest palette value; near-white text-strong sits at ~1:1 on bare yellow, so the tint must pull the composite dark); light = the darkest solid feature the light palette paints, #8f8000 (the light live-thought / darkest node fill, per the old branch's derived-dark thought; worst for near-black text-strong). A single mode-independent #fff676 is WRONG on light: the light brain never paints #fff676 (its live-thought is #8f8000 and its category nodes are all darker than the surface), so near-black text over #fff676 clears ~16:1 and the derivation would return a near-transparent tint that silently fails AA over the real light frame — the exact failure this slice exists to prevent.
                              • Tint base per tier = the theme's resolved surface-base; body reference = resolved text-strong. Both tiers tint from surface-base (glass reads as the theme's own surface pulled over the brain); dense differs only by a higher derived alpha. Derivation: sweep alpha upward, standard alpha = least alpha where text-strong over composite hits the target ratio (4.8), rounded up to 0.01; dense alpha = max(standard alpha, least alpha where the mark set converges to within 0.2 of native and code/diff text hits 4.8), rounded up. Safety margin is a fixed +0.3 on the ratio (target 4.8, floor 4.5).
                              • Guarantee is the default theme; mechanism generalizes. The generator is theme-agnostic and emits tiers for every bundled theme so switching re-keys correctly, but the shipped-and-tested guarantee is oc-2 (light + dark). Body-text AA holds for any theme by construction (at full alpha the composite collapses to the theme's own surface, which the theme already renders body text legibly on); the dense mark rule is only asserted for oc-2 because third-party palettes may ship native sub-3:1 marks a backing tint cannot lift.
                              • Data contract: per-tier CSS custom properties (--glass-standard-bg, --glass-dense-bg as rgba with the derived alpha; one --glass-blur; plus hairline border + elevation tokens) scoped under html[data-theme="<id>"][data-color-scheme="<mode>"]; two utility selectors [data-glass="standard"] and [data-glass="dense"] apply background + shared backdrop-filter blur (with -webkit- prefix for the webview) + border + shadow. Graphical-mark set for the dense check = resolved syntax-* tokens + diffAdd/diffDelete fills + run-plot series stroke colors.
                              • Wire the generator like the existing token generators — a script/-level generator run via a generate:glass package script (mirroring the existing generate:tailwind / generate:v2-oc2), emitting a committed generated CSS file that is not hand-edited.

                              Constraints & Invariants

                              • Blur is never a contrast term. The derivation and the test assume zero blur benefit; blur is a conservative bonus only. A dev must not "buy back" transparency by leaning on blur.
                              • The standard tint is bounded below by the contrast floor — it cannot be made ultra-transparent (the exact failure the earlier build hit). Consequently muted/secondary text (text-base) is NOT guaranteed on the standard tier; it must ride the dense tier or a locally-dimmed zone. Do not attempt to float muted grey on standard.
                              • Restyle nothing. This slice ships tokens + generated CSS + test only. The data-glass hook exists but is applied to no component; the app's rendered output is byte-identical until a later slice opts a component in.
                              • Key off the theme system's existing signals (data-theme and data-color-scheme on documentElement) — do not invent a new attribute or a separate mode flag.
                              • Yellow stays the brain's, never the glass's.#fff676 is the dark-mode reference backdrop and the dark brain's live-thought color (the light brain's live-thought is #8f8000); neither is ever the glass fill and never ink (amicode brand law). The glass tint is the theme's neutral surface + a hairline edge (light hairline on dark, dark hairline on light).
                              • Generated CSS is derived output — regenerate via the script; never hand-edit, and keep it in sync (the drift test enforces this).
                              Prior Art / Patterns
                              • Old-branch raw material to port (design-neutral, de-risked):packages/ui/src/amicode/glass-tokens.ts on the kate/chat-brain-atmosphere worktree carries the reusable WCAG machinery (toLinear, luminance, composite, contrast, tierContrast) and the generateGlassCss() emit skeleton, and packages/ui/src/amicode/glass.css shows the emit shape — [data-glass] utility selectors, -webkit- prefixing, and the @supports not (backdrop-filter) opaque fallback. Reuse the math and the emit skeleton; change three things: collapse the three tiers (airy/dense/chrome) to two (standard/dense); re-key from data-color-scheme-only to data-theme + data-color-scheme; and derive each alpha from the resolved theme tokens instead of the hardcoded GLASS constants (the old file's tint alphas were per-theme literals — this slice computes them). Carry forward the old file's two documented facts (no-blur figures are a conservative floor; muted greys can't clear AA on the most translucent tier) and its per-mode worst backdrops — dark #fff676 / light #8f8000 (the old file's worstBackdrop values, matching the current brain engine's dark/light thought palette).
                              • Current branch seams: the theme resolve API (resolveTheme / resolveThemeVariant in packages/ui/src/theme/resolve.ts) yields the concrete token values the generator and test read; the theme context (packages/ui/src/theme/context.tsx) is what stamps data-theme + data-color-scheme on documentElement and injects --text-strong / --surface-base / --syntax-*; packages/ui/src/theme/themes/oc-2.json is the default-theme source (its dark.overrides and light.overrides are the fixtures). packages/ui/src/amicode/brain-engine.ts confirms the per-mode worst backdrops — PALETTES.dark.thought = #fff676 and PALETTES.light.thought = #8f8000 (its accent#fff676 is defined but never painted). The mark set's plot-line colors come from the run-plot series (run-plot.ts / run-series.ts).
                              • Harness patterns:packages/ui/src/amicode/brain-engine.test.ts is the headless-discipline model (bun:test, no DOM, recording stubs) — the contrast test is even simpler (pure arithmetic). Generator wiring mirrors the existing generate:tailwind / generate:v2-oc2 scripts in packages/ui/package.json.

                              Source

                              Activity

                              Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

                              Metadata

                              Metadata

                              Assignees

                              No one assigned

                                Labels

                                afkImplement + merge unattended

                                Type

                                No type

                                Projects

                                No projects

                                  Milestone

                                  No milestone

                                  Relationships

                                  None yet

                                  Development

                                  No branches or pull requests

                                  Issue actions