Repository navigation
fix(cli): anchor dense/zh doc overlays to base sections instead of array index (#2182) - #3891
Conversation
…ray index (meta#2182) The --dense and --zh reference-doc overlays were merged into the base doc by array position: for each base section index, the loader took the overlay entry at the same index and applied that overlay's TITLE to the base section's BODY. An overlay whose sections were ordered differently, or which omitted one, then grafted every title onto the wrong content. The output was actively misleading, not merely untidy: $ astryx docs tokens --dense ## Spacing defined in tokens.stylex.ts. gap props use space0-space12. Token | Light | Dark --color-accent | #0064E0 | #2694FE --color-background-surface | #FFFFFF | #1F1F22 A heading reading Spacing, prose about gap props, and the colour table beneath it. An agent reading that learns spacing tokens are named `--color-*`. The tokens overlay was misaligned from index 0 (its own order is Spacing, Size, Color...; the base is Color, Spacing, Size...), so every one of its sections was wrong. `docs theme --dense` dropped `Extending a Theme` and `Token Utilities` entirely and printed `useTheme` twice; `docs theme --zh` emitted four headings in both Chinese and English. This is what makes it more than a docs nit: CLAUDE.md tells every AI agent to run `docs tokens --dense` and `docs theme --dense` at bootstrap, so the scrambled output is the first thing an agent reads about this design system. `principles` and `layout` happened to be index-aligned, which is why it went unnoticed — the two docs agents are told to read are the two that were broken. Overlay sections now name the base section they override: { section: 'Spacing Tokens', title: 'Spacing', content: [...] } so order is irrelevant and an overlay may cover any subset — sections it does not name keep their base content, which is also why the partially-translated zh overlay now falls back to English cleanly instead of scrambling. docOverlays.test.mjs asserts every overlay anchors to a real base section and that none is overridden twice, so an overlay cannot silently drift back. The type contract in docs-types.ts previously *documented* the footgun ("Array indices must match base doc sections"); it now documents the anchor. The tokens overlay's `Typography` entry is dropped rather than re-anchored: it carried no content overrides (title only), and the base has four separate typography sections (Font Family/Size/Weight, Type Scale) with no single section to anchor it to. Its sole effect had been renaming whichever section sat at index 5 — the shadow table. Claude-Session: https://claude.ai/code/session_01VYm8FsvUjk3xwDmonZRYeE
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
josephfarina
left a comment
There was a problem hiding this comment.
Dug into this and it's a solid, well-scoped fix — recommending merge.
Verified: reproduced on main (docs tokens --dense prints the color table under the ## Spacing heading; docs theme --dense drops "Extending a Theme" and duplicates "useTheme" from index 5 on). The anchor-by-section approach is the right design, the 20 tests + drift guard are exactly right, and it's green + merges clean into main.
Non-blocking nits:
- The
docs-types.tsunion reformatting is unrelated churn — optional to drop. - Block overrides are still index-matched within a section — a smaller residual of the same class; dovetails with the prose-only overlay direction @cixzhang raised on #3892.
For the record, so we frame it accurately: I ran ~46 controlled agent generations (scrambled vs fixed vs full vs no-docs) and couldn't reproduce the compliance-degradation causation in the description — scrambled ≈ fixed ≈ full on veer/purity/real-API usage, and no-docs was actually the worst. That doesn't diminish the fix at all; it's a correctness bug worth fixing on its own merits. Suggest we land it as the correctness fix it is and keep #2182 open for the doc-size angle — "Refs" (not "Closes") is already right.
There was a problem hiding this comment.
Verified: reproduced the scramble on main, the anchor-by-section fix is correct, 20 tests + drift guard, full CI green, clean merge. Landing this as a standalone correctness fix — #2182 stays open for the doc-size work (full details in my review above).
Make reference-doc dense/zh overlays structurally unable to drop, misalign, or override canonical content (the #2182 / #3891 bug class). - ContentBlock gains an optional stable id; ReferenceTranslationDoc is prose-only, id-keyed blocks and cannot express type/code/table/structure - api/docs.mjs merge is id-anchored and fail-safe: unmatched or unexpressible overrides fall back to canonical English; no array positions anywhere - all reference docs migrated: principles, theme, layout (per-block ids), tokens (ids emitted from scripts/generate-token-docs.mjs); overlays rewritten to blocks - docOverlays.test.mjs gate: every overlay block id resolves, prose-only, unique base ids, and the legacy positional content shape is rejected - component/hook overlays already safe on main via #3892 (overlayComponentDoc) Refs #2182 Co-authored-by: Cursor <[email protected]>
Refs #2182.
I've scoped this as a self-standing bug fix rather than claiming to close out the umbrella work — the issue carries a
researchlabel and reads like it may be an umbrella for the broader "how should agents consume our docs" question. This defect is correct to fix on its own merits regardless of where that lands. Happy to retitle/close-link if you'd rather.The bug
The
--denseand--zhreference-doc overlays were merged into the base doc by array position: for each base section index, the loader took the overlay entry at the same index and applied that overlay's title to the base section's body. An overlay ordered differently from the base — or missing a section — grafted every title onto the wrong content.The output is actively misleading, not merely untidy:
A heading reading Spacing, prose about gap props, and the colour table beneath it. An agent reading that learns spacing tokens are named
--color-*.The tokens overlay was misaligned from index 0 — its own order is Spacing, Size, Color…, the base is Color, Spacing, Size… — so every one of its sections was wrong.
docs theme --denselostExtending a ThemeandToken Utilitiesentirely and printeduseThemetwice.docs theme --zhemitted four headings in both Chinese and English.Why this is more than a docs nit:
CLAUDE.mdtells every AI agent to rundocs tokens --denseanddocs theme --denseat bootstrap. The scrambled output is the first thing an agent reads about this design system — a mechanically sufficient cause of the context degradation the issue reports.principlesandlayouthappened to be index-aligned, which is why it went unnoticed: the two docs agents are told to read are the two that were broken.The fix
Overlay sections now name the base section they override:
Order becomes irrelevant, and an overlay may cover any subset — sections it doesn't name keep their base content. That's also why the partially-translated
zhoverlay now falls back to English cleanly instead of scrambling.docs-types.tspreviously documented the footgun ("Array indices must match base doc sections"); it now documents the anchor.One judgment call worth your eye: the tokens overlay's
Typographyentry is dropped, not re-anchored. It carried no content overrides (title only), and the base has four separate typography sections (Font Family / Size / Weight, Type Scale) with no single section to anchor it to. Its only effect had been renaming whichever section sat at index 5 — the shadow table. If you'd rather keep a compressed typography title, tell me which base section should own it.Test plan
docs tokens --densemust not print--color-*under the Spacing heading).## Spacingrenders the spacing table,## Colorthe colour table,theme --denseshows all 14 headings withExtending a Themerestored and no duplicateuseTheme.pnpm exec vitest run— 337 files, 6318 tests, all passing.pnpm -F @astryxdesign/core typecheck— clean.pnpm check:repo— all five gates pass.