Skip to content

feat(docs): ship the docs as plain Markdown for coding agents - #121

Merged
tenphi merged 4 commits into
mainfrom
claude/upbeat-ramanujan-h4qu4l
Nov 23, 2026
Merged

tenphi merged 4 commits into
mainfrom
claude/upbeat-ramanujan-h4qu4l

Conversation

@tenphi

@tenphi tenphi commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #116.

  • 📄 The package ships every docs page as plain Markdown in harness/docs/, indexed by harness/docs/llms.txt. harnesspm gives it to agents as glaze:docs, so plugin.json now points docs at ./docs (relative to harness/).
  • 🧪 Each live example becomes the code the site prints for it, followed by a table of what its theme resolves to in light, dark, light HC and dark HC. A cell gives the color's tone (or an overlay's opacity and the step it paints) and its contrast on its base.
  • 🖼️ Every figure keeps its caption as > **Figure:** …. A figure of measurements gets a table of them. A whole UI in the reader's scheme (UiPreview, PalettePreview) and an interactive Preview keep only the caption, and a Preview links to its page on the site.
  • 🧩 Cookbook components become Markdown: <Callout> → GitHub alert (> [!NOTE]), <CodeGroup> → titled fences, <Card> → linked list item, <Steps> → ordered list.
  • 🔗 No import or link leads outside the package. Page links become relative .md links, site routes become page links, and anything else must be a full URL. The build fails otherwise.
  • 📦 docs/ (the .mdx sources) stays for the site and no longer ships.

Why

The shipped docs/ held site MDX. 9 of 19 pages imported components from ../docs-site/, which doesn't ship, and their examples existed only as JSX props. An agent reading glaze:docs saw imports it couldn't follow and examples it couldn't copy.

How it works

scripts/build-docs.mjs runs at prepack (and in CI through pnpm check:harness):

  1. It reads each page in docs/ and parses MDX with @mdx-js/mdx (a new dev dependency).
  2. It evaluates each component's props the way the page does: a module with the page's exports and the imports they use, with component imports dropped. Node runs the site's .ts helpers and src/ through its type stripping and a small resolve hook.
  3. It replaces each component with its form in docs-site/components/markdown.ts, and removes imports, exports and comments.
  4. It rewrites links, adds the title, the description and a short reading note under it, and writes the pages plus an llms.txt in the order of docs.config.ts.

The build fails on:

  • a component with no Markdown form
  • MDX left in the prose
  • an expression outside a component
  • a relative link or route that is not a page
  • a page missing from the navigation

Errors give the line in the source file. The parser sees blank lines where the frontmatter was, so every position, including the spans inside an MDX syntax error, is a line of the file.

Figures and the site share one source of values. Each figure's theme now comes from a .ts builder (figures.ts in each folder, token-pair.ts, palette-output.ts, plus exampleSource/cssOutput in glaze-docs.ts). The site's components and the Markdown forms both read these, so they print the same numbers. The site renders the same pages as before.

A sample (contrast.md, "Floors at a glance")

```ts title="theme.ts"
import { glaze } from '@tenphi/glaze';

const theme = glaze(280, 80);

theme.colors({
  surface: { tone: 97, saturation: 0.1 },
  'aa-text': { base: 'surface', tone: '-20', saturation: 0.4, contrast: 'AA' },
  …
});
```

| Color | Light | Dark | Light HC | Dark HC |
| --- | --- | --- | --- | --- |
| `aa-text` on `surface` | 4.55:1 · Lc 68.3 · tone 47.9 | 4.55:1 · Lc 38.7 · tone 61.9 | 7.07:1 · Lc 80.6 · tone 33.2 | 7.07:1 · Lc 48.9 · tone 67.5 |
| `preferred-text` on `surface` | Lc 90.5 · 10.56:1 · tone 20.0 | … | Lc 99.7 (misses Lc 105) · 19.16:1 · tone 0.0 | … |

> **Figure:** Each row is measured against surface in the active scheme. …

Changes

  • scripts/build-docs.mjs + scripts/build-docs.test.mjs (Vitest now also runs scripts/**/*.test.mjs).
  • docs-site/components/markdown.ts: the Markdown form of every component the pages use.
  • docs-site/components/**/figures.ts and the other shared .ts builders; the site components that now use them.
  • package.json:
    • files ships harness and drops docs.
    • prepack builds the docs and runs harnesspm check, with its logs kept off stdout so pack --json stays JSON.
    • New check:harness script.
  • harness/plugin.json (docs: ./docs), .gitignore (harness/docs/), and the CI step "Build the agent docs and check the harness".
  • tsconfig.json: erasableSyntaxOnly, because the docs build runs src/ with Node's type stripping.
  • Links to docs/ now point at the site:
    • code comments in src/okhst.ts, src/warnings.ts, src/resolver.ts and src/types.ts
    • the Glaze 2 snapshot error in src/serialize.ts, and the reference quote of it
    • README.md
  • AGENTS.md, README.md, docs-site/components/README.md: how the Markdown is built and what a new component needs.
  • Changeset: minor. Consumers who read node_modules/@tenphi/glaze/docs/* directly need the new paths in harness/docs/*.md.

Checks

  • ✅ pnpm typecheck, pnpm lint, pnpm format:check, pnpm build, pnpm check:harness
  • ✅ pnpm test: 901 pass, 21 of them for the docs build
  • ✅ Site unchanged: astro build HTML is byte-identical to main, with asset hashes and per-build UUIDs normalized. The one exception is the intended new wording of the Glaze 2 snapshot error, on the reference page and in the Glaze bundle inlined on two pages.
  • ✅ Packing: npm pack and pnpm pack include all 20 harness/docs files and no docs/. npm pack --dry-run --json prints clean JSON.
  • ✅ Consumer project: the packed tarball, installed with harnesspm 0.9.2, lists Docs: node_modules/.harnesspm/pkgs/@tenphi/glaze/harness/docs/llms.txt (glaze:docs) in AGENTS.md, and harnesspm doctor reports Ready.
  • ✅ Links: every relative link and #anchor in the built pages resolves. harnesspm check catches a planted dead link.
  • ✅ Runnable code: every generated code block that imports @tenphi/glaze runs against dist. The only blocks that don't are hand-written fragments that continue an earlier block.

Review rounds

Each round used fresh reviewers who read the code itself, not a summary of it. Every finding was fixed, or kept as a deliberate decision listed below.

Round Reviews Fixed
1 Correctness · output and docs Captions whose values didn't ship, ContrastExample metrics, measurement figures without tables, link and fence edge cases, error messages
2 Correctness · output and docs A theme printed twice on Getting started, error lines off by the frontmatter, quoted components with children, APCA/WCAG target mix-up, Lc noise on fills, the reading note, pack --json
3 The round 2 diff Prose that looked like a reference definition, positions inside MDX syntax errors, frontmatter continuation past a blank line, the reading note's table check, inline components and children on a tag's line, CodeGroup items with no language

Deliberate decisions

  • The output lives in harness/docs/ (git-ignored), next to the rest of the harness. There is no postpack cleanup, because pnpm 11 reads the packed files after postpack.
  • Site prose and captions are not reworded. Where a caption says "the scheme you're viewing", the table header names every scheme.
  • A "without its floor" row removes one color's floor at a time, as the site's ContrastMix does. The site's ContrastRows removes them all at once. The two differ only for a chain of floored colors, which no page has.

Follow-ups (not in this PR)

  • 🧭 UI Kit: cube-js/cube-ui-kit's AGENTS.md links Glaze's docs index by hand as node_modules/.harnesspm/docs/glaze/llms.txt. After this ships, the path harnesspm writes becomes node_modules/.harnesspm/pkgs/@tenphi/glaze/harness/docs/llms.txt.
  • ✍️ Site prose: two sentences in Shadows and glows ("Card shadows") and Migration (3.0) say the card shadows in dark high contrast "stay fully transparent and warn". The site's own rule ("Unreachable steps") says a dark-HC shortfall warns only when light HC is out of reach too, and here light HC has room. The new tables make this visible (α 0.000).


Generated by Claude Code

The package shipped the site's sources as its docs: 9 of 19 pages were
MDX that imported components from docs-site/, which doesn't ship, and
their examples lived only in JSX props (#116).

- scripts/build-docs.mjs runs at prepack and writes harness/docs/: one
  .md per page and llms.txt, indexed in the order of the site's
  navigation. harness/plugin.json points docs at it; docs/ no longer
  ships.
- Each component becomes its form in docs-site/components/markdown.ts:
  an example prints the code the site prints, then a table of what its
  theme resolves to in all four schemes (tone, or opacity and step, and
  each floor's contrast, measured as glaze:inspect does); a figure keeps
  its caption; Callout becomes a GitHub alert.
- The build fails on a component with no form, MDX in prose, a link
  that leads nowhere or a page missing from the navigation.
  pnpm check:harness builds and checks it in CI.
- Code both forms print moves out of .astro/.tsx into .ts modules
  (exampleSource, cssOutput, token-pair.ts, palette-output.ts); the site
  renders byte-identical pages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7EW65e4ssEmkDivbZ5
Two independent reviews of the docs build; every finding fixed.

- Values the captions describe now ship: ContrastExample prints both
  metrics, the floor's first, and the roles-swapped Lc; the contrast
  level example gets a table per level; the measurement figures
  (StepCompare, Unreachable, TintedPigment, MixRamp, FloorCompare,
  SchemeRamp, WindowMap, ToneRamp, ToneDrift, StatusThemes) get tables.
  Their themes come from shared figures.ts builders, so the site and the
  Markdown can't drift; the site renders the same pages.
- A page prints a theme once: an example always prints its code, a
  figure only a theme the page hasn't printed. A note under each title
  says how to read the tables and where the live examples are.
- Metrics: ratio is WCAG as on the site, a row without its floor is
  measured in the floor's metric, the asked step uses the theme's
  tuning, Callout severities map to the right alerts.
- The build: components and comments are replaced at any depth; an
  expression inside a component, or a link to a file that isn't a page,
  is an error; fences inside blockquotes, footnotes, the / route,
  double-backtick spans and CRLF frontmatter are handled; errors name
  their page; the Node guard can run on older Node.
- The reference quotes the new snapshot error; shipped type comments
  and README links point at the site instead of docs/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7EW65e4ssEmkDivbZ5
- Getting started printed its whole theme twice: UiPreview, a whole UI in
  the reader's scheme, keeps only its caption, as PalettePreview does.
- Preview links "the site" to its page; forms get the page's site URL.
- The reading note explains table cells only on pages that have them, and
  now covers `h`/`s` and which side APCA takes as text.
- PaletteStep prints Lc only where the site does: the site's KIND table
  moves to methodology/palette.ts so both read it.
- An overlay's WCAG ratio is no longer checked against an APCA target.
- Level tables honor the `schemes` and `hc` props, as LevelStrip does.
- Build errors give the line in the file, past its frontmatter, and an MDX
  syntax error gives its line and column.
- A component with children inside a blockquote drops the quote markers
  of its children; inline comments go; an inline component says so.
- Reference definitions in blockquotes are rewritten; a frontmatter value
  continued on the next line fails; CodeGroup takes an item with no
  language; a Card or Steps item of more than one paragraph fails.
- Comments in okhst.ts, warnings.ts and resolver.ts link to the site.
- prepack keeps its logs off stdout, so `pack --json` stays JSON, and
  tsconfig sets erasableSyntaxOnly: the docs build runs src with Node's
  type stripping.
- AGENTS.md: test file locations, a run-on sentence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7EW65e4ssEmkDivbZ5
- A line that starts with `[label]:` is a reference definition only when
  a URL and an optional title follow; any other such line is prose, and
  its inline links are rewritten (it used to swallow them, in blockquotes
  too).
- The build parses an MDX page with blank lines where its frontmatter
  was, so every position is a line of the file, including the spans
  inside an MDX syntax error. The firstLine offset goes.
- A frontmatter value continued past a blank line fails too; an indented
  comment line is not a continuation.
- The reading note detects the tables by the headers the forms print,
  and mentions tables only on pages that have them; hue is 0–360.
- An inline component is an error inside a component too, and a
  component with children on its tag's line is an error instead of
  leaking the tag.
- A CodeGroup item with no language gets a `text` fence, so its title
  stays a title.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7EW65e4ssEmkDivbZ5
@github-actions

Copy link
Copy Markdown
Contributor

📦 Snapshot release

Published 0.0.0-snapshot.300a410.

pnpm add @tenphi/[email protected]

@tenphi
tenphi merged commit 99e6c28 into main Nov 23, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
tenphi pushed a commit to cube-js/cube-ui-kit that referenced this pull request Nov 23, 2026
Glaze 3.2.0 ships its docs as plain Markdown in harness/docs/, indexed
by its own llms.txt (tenphi/glaze#121, which fixes tenphi/glaze#116, the
follow-up this PR filed). Its code is unchanged apart from one error
message, so no color moves.

- `pnpm update-glaze` with 3.2.0: package.json, pnpm-lock.yaml, and
  `harnesspm sync` for the lock and AGENTS.md's harnesspm block.
- The three hand-written links to Glaze's old `docs/*.mdx` pages
  (AGENTS.md, docs/rules/probe.md, docs/rules/review.md) lead to
  `harness/docs/*.md`.
- The changeset says UI Kit now pins Glaze 3.2.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gr8S7FAHF2ZZjma1gHg43N

This branch was previously deployed

1 inactive deployment
release — 74fa41b2 Deployed Nov 23, 2026 by tenphi via Build & snapshot release #315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs for agents: 9 of 19 published pages are site MDX, with imports of docs-site/, which doesn't ship

2 participants