Skip to content

doctor: add stylex-compiler and token-literals checks - #6729

Draft
kiranbadam wants to merge 1 commit into
meta:mainfrom
kiranbadam:fix/doctor-style-checks
Draft

kiranbadam wants to merge 1 commit into
meta:mainfrom
kiranbadam:fix/doctor-style-checks

Conversation

@kiranbadam

Copy link
Copy Markdown

User need

Agent-built Astryx apps fail in two ways astryx doctor never caught. First, StyleX styles silently don't apply when the compiler integration is missing or broken — the app renders unstyled with no error, and the builder blames the theme or their own code. Second, agents hardcode color literals (#6b7280, rgba(0,0,0,0.12)) instead of design tokens, so the app doesn't retint with the theme. Both are first-build-quality killers: the builder's first astryx build looks wrong and they can't tell why. No existing check covers either; doctor reported a clean bill of health while styles were silently broken.

Problem and solution fit

  • stylex-compiler check: fails when no StyleX compiler integration is detectable. It recognizes known compiler packages (@stylexjs/babel-plugin, @stylexjs/unplugin, bundler variants, @astryxdesign/build), fails when a compiler is declared but not installed, and passes when a bundler config references StyleX (the standard wiring). Without the compiler, stylex.create() output is never generated — hence fail, not warn.
  • token-literals check: warns (not fails — literals still render) when project source under src/ contains raw hex colors or color functions with literal digits. Patterns mirror the existing no-raw-color ESLint rule; the theme layer (src/theme/), tests, stories, docs, and generated files are excluded, and color functions built from handed-in values (rgba(${r}, ${g}, ${b}, ${a})) are not flagged.

Current specification

Fixes #6715 (doctor should fail when the StyleX compiler is missing) and #6720 (doctor should warn on raw color literals). Both checks are appended to SYNC_CHECKS in packages/cli/api/doctor/doctor.mjs, following the existing check contract ({id, label, status, message, fix}).

Public delta and caller burden

  • astryx doctor output gains two checks: stylex-compiler (fail/info) and token-literals (warn/pass/info). No new flags, no config changes, no caller decisions — both run as part of the existing doctor command.
  • stylex-compiler is info (skipped) when @astryxdesign/core isn't installed, matching the other core-dependent checks.
  • Check IDs follow the existing noun-style convention (core-installed, docs-progressive-disclosure).

Design and alternatives

  • Compiler detection is heuristic (dependency presence + config reference scan) rather than attempting a real compile: doctor checks must stay read-only and fast, and a failed build would conflate project errors with missing wiring.
  • token-literals scans at most 300 source files and reports at most 5 offenders: a bounded, readable summary rather than an exhaustive lint. The exhaustive path remains the no-raw-color ESLint rule, which the check's fix text points to.
  • Warn rather than fail for literals: a hardcoded color renders; a missing compiler breaks all styling. Severity matches user harm.

Evidence

  • New tests in packages/cli/api/doctor/doctor.test.mjs (59 total in the file, all pass):
    • stylex-compiler: info when core absent; fail when no integration detectable; fail when declared but not installed; pass when installed; pass when a bundler config references StyleX.
    • token-literals: info when core absent; warn on raw hex; warn on rgba(...) with literal digits; pass on runtime-variable-only color functions; pass when only theme/test files contain literals; pass on token-based styles.
  • npx vitest run --project node packages/cli/api/doctor/doctor.test.mjs — 59/59 pass.
  • pnpm check:repo — clean (includes changesets, knowledge, package boundaries).
  • ESLint on changed files — 0 errors.

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

  • npx vitest run --project node packages/cli/api/doctor/doctor.test.mjs — 59/59 pass.
  • pnpm check:repo — all repo checks pass.
  • eslint on packages/cli/api/doctor/doctor.mjs and doctor.test.mjs — 0 errors, 0 warnings.

Closes #6715
Closes #6720

stylex-compiler fails when no StyleX compiler integration is detectable:
declared-but-not-installed, or neither a known compiler dependency nor a
bundler config referencing StyleX. token-literals warns on raw color
literals (hex / color functions with literal digits) in src/, mirroring
the no-raw-color ESLint rule, while ignoring the theme layer, tests, and
generated files.

Fixes meta#6715, fixes meta#6720.
@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:29am 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!

@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 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Nov 19, 2026, 6:00 PM UTC

@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.

Approval waits on an engineering owner's decision, and there are fixes to make either way.

No current spec covers either new doctor check. An engineering owner needs to provide or identify the governing spec for each one (what triggers it, and whether it fails or warns) and record that decision, for example by commenting /approve-spec <full head SHA> once a record covers it.

Blocking findings

  • stylex-compiler fails, and makes astryx doctor exit 1, on the prebuilt astryx.css setup that Getting Started documents and that spec:AST-080 FR2/FR5 make the default (apps/example-nextjs exits 0 today and 1 with this change).
  • The new compiler package list duplicates detectStylingSystem() in packages/cli/foundation/agent-docs/agent-docs.mjs with a different list, so astryx init and astryx doctor can disagree about the same project; please extend and call that one detector instead.
  • token-literals warns on the theme files astryx theme add writes to src/themes/<slug>, because the theme/ exemption misses themes/, and on comments such as // see #1234, because it scans whole file text rather than string literals.
  • pnpm -F @astryxdesign/cli typecheck:strict, which CI runs, reports 7 errors on the added code, because the JSDoc blocks sit on the constants instead of on checkStylexCompiler, checkTokenLiterals and scannableSourceFiles.
  • The fail message and the description say styles "silently do not apply" without a compiler, but Astryx component styles come from astryx.css and an uncompiled stylex.create() throws at runtime, so the wording should describe what actually happens.
  • The token-literals fix tells builders to run the no-raw-color ESLint rule, which ships only inside this repository and is not published.
  • The token-literals result overstates its coverage: it reports "in 5 file(s)" when it stopped at five, and it passes with "No raw color literals found" when it stopped after 300 files.

The branch also conflicts with main in both doctor files and needs a rebase.

[Automated review]

}

const installed = declared.filter(name => !notInstalled.includes(name));
if (installed.length === 0 && wiredConfigs.length === 0) {

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 fails, and makes doctor exit 1, on the prebuilt astryx.css setup that Getting Started documents and that spec:AST-080 FR2/FR5 make the complete default with no compiler (apps/example-nextjs goes from exit 0 to exit 1). Gate it on a non-type-only @stylexjs/stylex import in project source, the condition spec:AST-048 FR20 uses.

* @param {DoctorContext} ctx
* @returns {DoctorCheck}
*/
const STYLEX_COMPILER_PACKAGES = [

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.

detectStylingSystem() in packages/cli/foundation/agent-docs/agent-docs.mjs already owns which packages count as StyleX compilers, and its list shares only @stylexjs/babel-plugin with this one. Please extend or export that one detector and call it here, so astryx init and astryx doctor agree.

'webpack.config.cjs',
];

export function checkStylexCompiler(ctx) {

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.

typecheck:strict (run in CI) reports implicit-any ctx here and at line 1217, plus errors at lines 1187, 1190, 1301 and 1302. The JSDoc block above STYLEX_COMPILER_PACKAGES belongs on this function, and the same goes for the block above TOKEN_LITERAL_HEX.

label,
status: 'fail',
message:
'No StyleX compiler integration detected. Astryx styles are compiled at build time — without the compiler, stylex.create() output is never generated and styles silently do not apply.',

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.

Astryx component styles come from the prebuilt astryx.css, and an uncompiled stylex.create() throws at runtime in @stylexjs/stylex 0.19 (Unexpected 'stylex.create' call at runtime), so styles do not "silently" fail. Suggested wording: "This project's source imports @stylexjs/stylex, but no StyleX compiler is configured; stylex.create() calls throw at runtime until one is."

const TOKEN_LITERAL_SKIP_FILE = /\.(test|spec|stories|doc|sandbox)\./;
/** The theme layer owns color values by design; never flag it. Paths here are
* relative to src/, so `theme/` alone identifies the layer. */
const TOKEN_LITERAL_THEME_LAYER = /(^|\/)theme\//;

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.

astryx theme add writes to src/themes/<slug> by default, and this pattern does not match themes/. Right after astryx theme add neutral, this check warns about neutralTheme.ts and two generated palette files. Consider /(^|\/)themes?\//.

} catch {
continue;
}
let hit = TOKEN_LITERAL_HEX.test(text);

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 tests the whole file text, so a comment such as // see #1234 or #6715 counts as a raw colour. no-raw-color.js reads only string and template literals for exactly this reason.

label,
status: 'warn',
message: `Raw color literals bypassing design tokens in ${offenders.length} file(s): ${shown}${more}. Hardcoded colors do not retint with the theme.`,
fix: 'Replace literals with theme tokens (e.g. colorVars / shadowVars from your theme), or run the no-raw-color ESLint rule to find every occurrence.',

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 no-raw-color rule lives in the private internal/eslint-plugin-astryx package, so a consumer cannot run it. Point to something they have (for example astryx docs tokens) or drop this clause.

id,
label,
status: 'pass',
message: 'No raw color literals found in src/ — colors flow through design tokens.',

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 also passes after the scan stopped at 300 files, so an offender in file 301 is reported as "No raw color literals found". Report info (not fully inspected) when the limit cut the scan short. The warn message likewise says "in 5 file(s)" when it stopped counting at five.

@cixzhang

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thanks for this, @kiranbadam, and for keeping it current. Two things to resolve before it can move forward. First, the stylex-compiler check would flag apps that are set up correctly: the setup records support loading Core's prebuilt stylesheet with no StyleX compiler at all, and doctor's existing stylesheet check already passes those apps. Second, the token-literals check overlaps the existing no-raw-color lint rule, so it would report the same problem twice. If you'd like to narrow it to what neither of those covers, we're glad to review that version.

@astracat-bot

astracat-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

In reply to @cixzhang

I'll run a full review to re-check this with your note.

@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.

Changes are needed before this can move forward, and an engineering owner has already set the direction: narrow both checks to what existing tooling does not cover.

Blocking findings

  • stylex-compiler fails, and makes astryx doctor exit 1, on the prebuilt astryx.css setup that needs no StyleX compiler (spec:AST-080 FR2/FR5), so it should fire only on what that setup and doctor's stylesheet check do not cover, such as source that imports @stylexjs/stylex with no compiler configured.
  • As an engineering owner noted here, token-literals reports what the no-raw-color lint rule already reports, so narrow it to what that rule does not cover or drop it.
  • The new compiler package list duplicates detectStylingSystem() in packages/cli/foundation/agent-docs/agent-docs.mjs with a different list, so astryx init and astryx doctor can disagree; please extend and call that one detector instead.
  • token-literals warns on the theme files astryx theme add writes to src/themes/<slug> and on comments such as // see #1234, because its exemption matches only theme/ and it scans whole file text rather than string literals.
  • pnpm -F @astryxdesign/cli typecheck:strict, which CI runs, reports 7 errors on the added code, because the JSDoc blocks sit on the constants instead of on checkStylexCompiler, checkTokenLiterals and scannableSourceFiles.
  • The fail message and the description say styles "silently do not apply" without a compiler, but Astryx component styles come from astryx.css and an uncompiled stylex.create() throws at runtime, so the wording should describe what actually happens.
  • The token-literals fix tells builders to run the no-raw-color ESLint rule, which ships only inside this repository and is not published.
  • The token-literals result overstates its coverage: it says "in 5 file(s)" when it stopped counting at five, and passes with "No raw color literals found" when it stopped after 300 files.

The branch also conflicts with main in both doctor files and needs a rebase. A narrowed version gets a fresh review.

Claims and files checked

Review mode: full; reason: recipe-changed (many rules)

  • Release note: stylex-compiler fails when a compiler is declared but not installed, or when there is neither a compiler dependency nor a config mentioning StyleX: verified (doctor.mjs:1088-1108, tests).
  • Release note: token-literals warns on raw colour literals under src/: verified, but it also flags comments and the theme files astryx theme add writes.
  • Description: without a compiler, StyleX styles silently do not apply and the app renders unstyled with no error: false (stylex.create() throws at runtime; Core styles come from astryx.css).
  • Description: doctor reported a clean bill of health while styles were silently broken: false for the same reason.
  • Description: known compiler packages are recognised, including @astryxdesign/build: verified (doctor.mjs:1027-1037); the list differs from detectStylingSystem().
  • Description: the check passes when a bundler config references StyleX: verified (test; doctor.mjs:1078-1086).
  • Description: a missing compiler means no generated output, hence fail rather than warn: false; the prebuilt default needs no compiler (spec:AST-080 FR2).
  • Description: token-literals warns rather than fails: verified (status: 'warn').
  • Description: its patterns mirror the no-raw-color rule: partly false; it scans whole file text, comments included, with a narrower theme exemption.
  • Description: the theme layer, tests, stories, docs and generated files are excluded: partly; src/theme/, those file names and build-output folders are skipped, but src/themes/ is not.
  • Description: colour functions built from passed-in values are not flagged: verified (test).
  • Description: stylex-compiler reports info when Core is missing: verified (doctor.mjs:1063-1070).
  • Description: at most 300 files and 5 offenders: verified, but the result text overstates what was read.
  • Description: no new flags, config changes or caller decisions: partly false; doctor gains an exit-1 path on the default setup.
  • Description: 59 tests pass and ESLint is clean on the changed files: verified.
  • Description: the repository checks pass: the changeset check passes; the other repository checks were not rerun.
  • .changeset/doctor-style-checks.md: clear.
  • packages/cli/api/doctor/doctor.mjs: the findings above.
  • packages/cli/api/doctor/doctor.test.mjs: no finding; the tests pass but do not cover the prebuilt-stylesheet setup, astryx theme add output or comments.

Automated review (maintainer link)

@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 — 5461b738 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

2 participants