Skip to content

agent-docs: single-source setup gotchas as data - #6731

Draft
kiranbadam wants to merge 1 commit into
meta:mainfrom
kiranbadam:fix/gotchas-data
Draft

kiranbadam wants to merge 1 commit into
meta:mainfrom
kiranbadam:fix/gotchas-data

Conversation

@kiranbadam

Copy link
Copy Markdown

User need

Setup gotchas are tribal knowledge: hover guards (@media (hover: hover)), @layer ordering, SWC-vs-Babel StyleX transform, SSR theme builds, token import paths — they live in docs and issues, not the toolchain. init --agent generated a cheat sheet that omitted them, so every agent rediscovers each one by failing. The fix per #6725: single-source the gotcha list as data in the CLI package so init, build, doctor, and the generated agent cheat sheet can all consume it.

Problem and solution fit

  • packages/cli/assets/gotchas.json (published with the CLI) holds 12 entries with id, title, trigger, fix, severity, plus a gotchas.schema.json documenting the contract.
  • packages/cli/foundation/agent-docs/gotchas.mjs loads, validates (loud, specific errors on bad edits), and renders the entries as terse severity-ordered cheat-sheet lines.
  • generateCompressedIndex now renders a GOTCHAS section from that JSON, replacing the hand-written error-preventer lines (the "No <div>" and token rules are now owned by the data). The cheat sheet an agent gets from init --agent includes all 12 gotchas.
  • init, build, and doctor can consume the same source next — this PR establishes the data and the first consumer.

Current specification

Fixes #6725. Entry fields are exactly id, title, trigger, fix, severity (severity ∈ high/medium/low). 12 entries mined from the agent docs, setup guidance (getting-started), and the internal/eslint-plugin-astryx rules, including the required four: StyleX compiler setup, SSR theme, hover-on-touch guard, cascade-layer order.

Public delta and caller burden

  • The generated agent-docs block (AGENTS.md/CLAUDE.md managed section) gains a GOTCHAS section — 12 one-line entries, highest severity first. No new flags or commands; init --agent output changes, existing blocks refresh on next init/upgrade.
  • No caller decisions: the section is unconditional (gotchas are system-agnostic or StyleX-noted inline).

Design and alternatives

  • JSON in assets/ (published) rather than code constants: it's the shared source build and doctor will read next, and editors get schema hover-docs.
  • Hand-rolled validation instead of Zod in foundation/: dependency-free, and errors name every problem at generation time.
  • Generation is best-effort (a missing/unreadable file omits the section rather than breaking init), matching the existing topic-list pattern; schema enforcement lives in tests.
  • Rejected: keeping the hand-written lines alongside the JSON — two sources for the same guidance would drift.

Evidence

  • New gotchas.test.mjs (7 tests): schema validation of the shipped JSON, required-gotcha coverage, rejection of bad payloads (bad id format, bad severity, missing fields, duplicates, empty list), severity ordering, and every gotcha's title+fix appearing in generateCompressedIndex output across all three styling systems.
  • packages/cli/foundation/agent-docs/ suites: 120/120 pass — AGENTS marker, update, and idempotency tests all green.
  • packages/cli/api/init/ suites: 19/19 pass.
  • pnpm check:repo — all checks pass; ESLint on changed files — 0 errors.
  • Rendered block inspected: GOTCHAS section present, severity-ordered, no bare-npx astryx footgun reintroduced (caught by existing invocation tests during development).

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest run --project node packages/cli/foundation/agent-docs/ — 120/120 pass.
  • vitest run --project node packages/cli/api/init/ — 19/19 pass.
  • pnpm check:repo — clean.
  • eslint on changed files — 0 errors.

Closes #6725

Add packages/cli/assets/gotchas.json (12 entries: id, title, trigger,
fix, severity) with a loader/validator/renderer in
foundation/agent-docs/gotchas.mjs. generateCompressedIndex now renders
its GOTCHAS section from that JSON instead of hand-written
error-preventers, so init --agent no longer omits the setup gotchas
(StyleX compiler, SSR theme, hover-on-touch guard, cascade-layer order,
...). init, build, and doctor can consume the same source next.

Fixes meta#6725.
@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Error Error Sep 29, 2026 12:36am UTC

Request Review

@meta-cla

meta-cla Bot commented Sep 29, 2026

Copy link
Copy Markdown

Hi @kiranbadam!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@astracat-bot

astracat-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 27, 2026, 12:29 PM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Sep 29, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This pull request needs an engineering owner's decision before it can be approved: no current spec covers what the generated agent-docs block should contain, or a published gotchas.json data contract for init, build and doctor, and the batch review of the agent-tooling gap reports (#6721) has not settled #6725 yet. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request once a record covers the change; the author may do so if they are an engineering owner.

Whatever the decision, these need fixing:

  • The first, high-severity gotcha (packages/cli/assets/gotchas.json:5) tells every project that without a StyleX compiler "no Astryx styles are compiled", but the prebuilt stylesheets need no compiler and plain-CSS blocks say "No StyleX/Tailwind compiler here" a few lines above, so scope it to swizzled or self-authored StyleX (or render it only for StyleX projects) and drop the astryx doctor pointer, since doctor has no compiler check.
  • gotchas.json:61 writes npx @astryxdesign/cli into the block, but commands there are written bare (astryx …) so the CLI can substitute the project's own command, so drop the entry or write the command bare.
  • gotchas.json fails its own schema because gotchas.schema.json sets additionalProperties: false without allowing the top-level $schema key, so allow that key and check the shipped file against the schema in a test.
  • The changeset says gotchas are now "single-sourced", but the same guidance stays hand-written in the styling and getting-started docs and in the block's RULES lines, so describe it as a new GOTCHAS section read from gotchas.json.
  • agent-docs.mjs:473 prints the GOTCHAS header even when loading the data fails, though the comment says the section is omitted, so push the header only after the lines render.

The branch also conflicts with main in agent-docs.mjs and needs a rebase.

[Automated review]

"$schema": "./gotchas.schema.json",
"gotchas": [
{
"fix": "Install and wire a StyleX compiler (@stylexjs/unplugin or your bundler's integration) \u2014 without it no Astryx styles are compiled. Run `astryx doctor` to verify.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This renders first, at high severity, in every project's agent-docs block, including plain-CSS and Tailwind ones whose RULES line says "No StyleX/Tailwind compiler here". The prebuilt stylesheets need no compiler (the styling doc says "consuming the published package needs no StyleX setup"), so this sends agents to install tooling the project does not need. Scope it to swizzled or self-authored StyleX source, or render it only for StyleX projects. astryx doctor has no StyleX-compiler check, so drop that pointer too.

"trigger": ":hover styles never apply, or stick on touch devices"
},
{
"fix": "Invoke via `npx @astryxdesign/cli`, or add the astryx script to package.json.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commands in the generated block are written bare (astryx …) so the CLI can substitute the project's own command, which the header already names (for example pnpm exec astryx). Hard-coding an unversioned npx @astryxdesign/cli here bypasses that. Drop the entry, or write the command bare.

@@ -0,0 +1,90 @@
{
"$schema": "./gotchas.schema.json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gotchas.schema.json sets additionalProperties: false at the top level and allows only gotchas and version, so this file fails its own schema (Ajv draft 2020-12: "must NOT have additional properties" for $schema). Add "$schema": {"type": "string"} to the schema's properties, and validate the shipped file against the schema in gotchas.test.mjs so the schema and validateGotchas cannot drift apart.

// Gotchas — setup failure modes, single-sourced from assets/gotchas.json.
// Best-effort like the topic list above: a missing/unreadable file omits
// the section rather than breaking init; the schema is enforced by tests.
lines.push('GOTCHAS — setup failure modes, do not rediscover by failing:');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The header is pushed before the try, so when gotchas.json is missing or invalid the block prints "GOTCHAS — …" with nothing under it, not the omitted section the comment above describes. Push the header only after renderGotchaLines returns lines.

'@astryxdesign/cli': patch
---

[feat] Setup gotchas are now single-sourced as data: `packages/cli/assets/gotchas.json` holds 12 entries (id, title, trigger, fix, severity), and the generated agent cheat sheet (`init --agent`) renders its GOTCHAS section from that JSON instead of hand-written error-preventers — covering StyleX compiler setup, stylesheet import order, cascade-layer order, SWC-vs-Babel on Next.js, SSR theme builds, token usage, the hover-on-touch guard, and more. `init`, `build`, and `doctor` can consume the same source next. (#6725)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Single-sourced" claims more than the change delivers: the same guidance stays hand-written in the styling and getting-started docs and in the block's RULES and SELF-CHECK lines. Suggested wording: "The generated agent-docs block gains a GOTCHAS section read from packages/cli/assets/gotchas.json: StyleX setup, stylesheet and layer order, SWC on Next.js, SSR theme builds, tokens, the hover guard and more."

@cixzhang

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thanks, @kiranbadam. main has since rewritten the agent docs as one managed block, so this needs rebuilding against that structure. Some of the gotchas also assume a StyleX compiler is required, but an app can use Core's prebuilt stylesheet without one. If you rebase onto the managed block and drop or reword those entries, we'll take another look.

@cixzhang cixzhang added the lane:2 Astryx fix-loop lane 2 owns this label Nov 21, 2026

This branch had an error being deployed

1 failed deployment
Preview — 5dc41da9 Deployed Sep 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Authored by a community contributor (not on the eng/design team) lane:2 Astryx fix-loop lane 2 owns this needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[gap] init: Setup gotchas are tribal knowledge; init --agent omits them

2 participants