Skip to content

docs theme --dense causes AI agent context degradation (regression to 20% compliance) #2182

Closed

Description

@cixzhang

Problem

npm run xds -- docs theme --dense outputs 12.5 KB / 308 lines covering HCT color models, derived variable registries, cascade layers, color scale expansion, motion curves, and type scale math. AI coding agents that read this doc to learn defineTheme() routinely abandon XDS components and fall back to raw CSS.

Evidence from Monotelier benchmarks

The Monotelier benchmark builds an ASCII art canvas editor across 6 frontend stacks. XDS (source) compliance scores are highly variable, and the variance tracks whether the agent reads the theme docs:

Run Agent read theme docs? Compliance Anti-patterns Outcome
run-009 No (guessed) 94% 0 Used defineTheme({ name }) minimally, stayed on track
run-011 Yes (--dense) 45% 74 Overwhelmed by HCT details, abandoned XDS components
run-012 Yes (--dense) 20% 70 Same — total design system abandonment

The theme doc is the single strongest predictor of framework compliance in XDS benchmarks. Every run where the agent reads it scores below 50%. Every run where the agent skips it scores above 70%.

Root cause

The dense theme doc includes information the agent doesn't need to use defineTheme():

  • HCT color model theory (agents just need [light, dark] tuples)
  • Derived variable registries (internal implementation)
  • Cascade layer architecture (internal implementation)
  • Color scale expansion math (agents don't build color scales)
  • Motion curve definitions (not needed for basic theming)

This burns the agent's context budget. By the time it reaches actual component code, the relevant guidance has either decayed from context or the agent has been spooked into hand-rolling everything.

Comparison with other frameworks

MUI and Ant Design score 90-95% consistently because their theming APIs (createTheme({ palette: {...} }), ConfigProvider theme={{ algorithm: darkAlgorithm }}) are in the LLM's training data. The agent doesn't need to read docs — it already knows the API shape.

XDS's defineTheme() is proprietary — the agent MUST read docs. When those docs dump architecture internals alongside the API, it backfires.

Proposed fix

Add a docs theme --api or docs theme --brief flag that returns only the API surface:

  • defineTheme({ name, tokens, base? }) signature
  • Token naming convention (--color-*, --spacing-*, --radius-*, etc.)
  • [light, dark] tuple format
  • 1-2 complete examples
  • ~2-3 KB / ~60 lines

Leave --dense as-is for humans building production themes. Add the new flag for AI agent consumption, and document it in working-with-ai.doc.mjs as the recommended path over --dense for theming.

Prior art

The Monotelier project ships a 2.8 KB / 79 line THEMING.md reference that consistently produces 96% compliance when agents read it instead of docs theme --dense. This could serve as a template for what the --api output should look like.

Activity

  1. added
    bug
    documentation
    theming
    research
    on May 18, 2026
  2. josephfarina commented on Jul 20, 2026

    @josephfarina
    Contributor

    Picking this up — status + plan.

    #3891 (reference-doc --dense/--zh scramble) and #3892 (component-doc prop-drop, merged) fix real overlay-correctness bugs, but neither touches the size concern this issue is about, so keeping this open for that.

    On size: I compared the ~16KB docs theme --dense against a ~3KB lean version on both a basic and a hard theming task (custom theme extending a base + component overrides + a custom variant + light/dark). The lean doc was capability-equivalent — real API, extends, overrides, custom variants, and light/dark tuples all at 100%, with nothing dropped. A lean --dense is safe.

    Two honesty notes:

    • I could not reproduce "reading --dense → ~20%, guessing → ~94%." In my runs, no-docs was the worst (agents invent createTheme/ThemeProvider and hardcode values); any docs (even scrambled) produced correct real-API usage. So the win from a lean doc is ~80% token savings, not a compliance rescue.
    • I did not test multi-turn context-budget degradation (this issue's hypothesized mechanism) — that's a separate study.

    Plan:

    1. Land fix(cli): anchor dense/zh doc overlays to base sections instead of array index (#2182) #3891 (correctness).
    2. Make --dense emit lean, curated output for reference docs + add a --detail minimal level; keep leanness a renderer concern, not encoded per-doc.
    3. Adopt @cixzhang's prose-only overlay lockdown from fix(cli): translated component docs must not drop props #3892 (translations carry description/anchor only, enforced via type + lint) so leanness can never drop structure.
  3. josephfarina commented on Jul 20, 2026

    @josephfarina
    Contributor

    Design refinement for the overlay/size work (from digging into #3891):

    #3891 fixes overlay drift at the section level (anchor by section: name), but content blocks within a section are still matched by array position (content: [null, null, {prose}]) — the same bug class one level down. Reorder or insert a base block and the prose override lands on the wrong one.

    Durable design we'll build on top:

    • Block-level stable ids in the canonical docs; overlays key overrides by id, not array position (the block-level analog of 3891's section anchoring). Removes the null arrays.
    • Co-locate the --dense variant on each block — { id, type, text, dense } — so the compressed form lives next to its source and can't drift. This deletes the parallel *.doc.dense.mjs files entirely and makes leanness a render-time concern.
    • --zh stays a separate locale overlay, but keyed by id and prose-only (per @cixzhang's lockdown: entries are { id, text }, structurally unable to carry type/default/structure).
    • Enforce via type + test: overlay entries prose-only, block ids unique per section, every overlay id resolves to a real base block.

    Net: no positional arrays, no parallel plain-text to drift, structurally impossible to drop or misalign a block. This unifies 3891 (sections) + @cixzhang's prose-only lockdown + render-time leanness into one model.

  4. josephfarina commented on Nov 16, 2026

    @josephfarina
    Contributor

    Thanks for the benchmarks behind this. #7141 split the theme doc into use-a-theme and author-a-theme, so astryx docs theme now prints about 2 to 4 KB, with or without --dense, down from 12 to 16 KB. Closing as fixed.

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

    bugdocumentationresearchtheming

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions