Skip to content

An AI skill that provides design intelligence for building professional UI/UX across multiple platforms.

fix(brand): detect token sources under unlisted CSS filenames (#523)

Varrunan Projects67803eac8160
diff --git a/.claude/skills/brand/scripts/sync-brand-to-tokens.cjs b/.claude/skills/brand/scripts/sync-brand-to-tokens.cjs
index f64feb0..c44b466 100644
--- a/.claude/skills/brand/scripts/sync-brand-to-tokens.cjs
+++ b/.claude/skills/brand/scripts/sync-brand-to-tokens.cjs
@@ -20,14 +20,37 @@ const DESIGN_TOKENS_JSON = 'assets/design-tokens.json';
const DESIGN_TOKENS_CSS = 'assets/design-tokens.css';
const CSS_TOKEN_SOURCES = [
'src/index.css',
+ 'src/main.css',
+ 'src/app.css',
+ 'src/global.css',
'src/globals.css',
+ 'src/styles/global.css',
'src/styles/globals.css',
+ 'src/styles/index.css',
+ 'src/styles/main.css',
'src/styles/tokens.css',
+ 'src/app/global.css',
'src/app/globals.css',
+ 'app/global.css',
'app/globals.css',
+ 'styles/global.css',
'styles/globals.css',
'styles/tokens.css'
];
+// Directories shallow-scanned for any *.css that already declares tokens.
+// A hardcoded filename list alone misses real projects by a single letter
+// (e.g. styles/global.css vs styles/globals.css), which silently defeats the
+// overwrite guard.
+const CSS_SCAN_DIRS = [
+ 'src',
+ 'src/styles',
+ 'src/css',
+ 'src/assets/styles',
+ 'app',
+ 'app/styles',
+ 'styles',
+ 'css'
+];
const TAILWIND_CONFIGS = [
'tailwind.config.js',
'tailwind.config.cjs',
@@ -89,7 +112,23 @@ function findExistingTokenSources(projectRoot) {
addIfPresent(DESIGN_TOKENS_JSON);
addIfPresent(DESIGN_TOKENS_CSS);
- for (const relativePath of CSS_TOKEN_SOURCES) {
+ const candidates = new Set(CSS_TOKEN_SOURCES);
+ for (const dir of CSS_SCAN_DIRS) {
+ const absoluteDir = path.resolve(projectRoot, dir);
+ let entries;
+ try {
+ entries = fs.readdirSync(absoluteDir, { withFileTypes: true });
+ } catch {
+ continue;
+ }
+ for (const entry of entries) {
+ if (entry.isFile() && entry.name.toLowerCase().endsWith('.css')) {
+ candidates.add(`${dir}/${entry.name}`);
+ }
+ }
+ }
+
+ for (const relativePath of candidates) {
const absolutePath = path.resolve(projectRoot, relativePath);
scanCssSource(absolutePath);
}
diff --git a/.claude/skills/brand/scripts/tests/test_sync_brand_to_tokens.py b/.claude/skills/brand/scripts/tests/test_sync_brand_to_tokens.py
index 7e621e1..3d97d1a 100644
--- a/.claude/skills/brand/scripts/tests/test_sync_brand_to_tokens.py
+++ b/.claude/skills/brand/scripts/tests/test_sync_brand_to_tokens.py
@@ -315,3 +315,54 @@ def test_force_allows_sync_with_existing_css_token_source(tmp_path):
assert result.returncode == 0, result.stderr + result.stdout
assert (tmp_path / "assets" / "design-tokens.json").exists()
+
+
+ "relative_path",
+ [
+ "src/styles/global.css",
+ "src/global.css",
+ "src/main.css",
+ "src/styles/theme.css",
+ "styles/variables.css",
+ ],
+)
+def test_refuses_token_source_under_unlisted_css_filename(tmp_path, relative_path):
+ """Token detection must not hinge on an exact filename.
+
+ The candidate list only held the plural `globals.css` spellings, so a
+ project whose entry point is `src/styles/global.css` — one letter apart —
+ was never scanned and the guard silently passed, leaving the generated
+ `assets/design-tokens.*` to compete with an existing palette.
+ """
+ (tmp_path / "docs").mkdir()
+ shutil.copy(BRAND_STARTER, tmp_path / "docs" / "brand-guidelines.md")
+ css = tmp_path / relative_path
+ css.parent.mkdir(parents=True, exist_ok=True)
+ css.write_text(":root {\n --dawn: #f5a524;\n --ink: #1c1626;\n}\n")
+
+ result = _run(tmp_path)
+
+ assert result.returncode == 1, result.stdout + result.stderr
+ assert relative_path in result.stderr
+ assert "--force" in result.stderr
+ assert not (tmp_path / "assets" / "design-tokens.json").exists()
+
+
+def test_discovered_css_without_tokens_does_not_block_sync(tmp_path):
+ """Scanning extra CSS files must not introduce false positives.
+
+ Plain stylesheets carry no custom properties, so they are not token
+ sources and must leave the sync path alone.
+ """
+ (tmp_path / "docs").mkdir()
+ shutil.copy(BRAND_STARTER, tmp_path / "docs" / "brand-guidelines.md")
+ styles = tmp_path / "src" / "styles"
+ styles.mkdir(parents=True)
+ (styles / "global.css").write_text(".btn {\n color: red;\n}\n")
+ (styles / "reset.css").write_text("* {\n margin: 0;\n}\n")
+
+ result = _run(tmp_path)
+
+ assert result.returncode == 0, result.stderr + result.stdout
+ assert (tmp_path / "assets" / "design-tokens.json").exists()
diff --git a/cli/assets/skills/brand/scripts/sync-brand-to-tokens.cjs b/cli/assets/skills/brand/scripts/sync-brand-to-tokens.cjs
index f64feb0..c44b466 100644
--- a/cli/assets/skills/brand/scripts/sync-brand-to-tokens.cjs
+++ b/cli/assets/skills/brand/scripts/sync-brand-to-tokens.cjs
@@ -20,14 +20,37 @@ const DESIGN_TOKENS_JSON = 'assets/design-tokens.json';
const DESIGN_TOKENS_CSS = 'assets/design-tokens.css';
const CSS_TOKEN_SOURCES = [
'src/index.css',
+ 'src/main.css',
+ 'src/app.css',
+ 'src/global.css',
'src/globals.css',
+ 'src/styles/global.css',
'src/styles/globals.css',
+ 'src/styles/index.css',
+ 'src/styles/main.css',
'src/styles/tokens.css',
+ 'src/app/global.css',
'src/app/globals.css',
+ 'app/global.css',
'app/globals.css',
+ 'styles/global.css',
'styles/globals.css',
'styles/tokens.css'
];
+// Directories shallow-scanned for any *.css that already declares tokens.
+// A hardcoded filename list alone misses real projects by a single letter
+// (e.g. styles/global.css vs styles/globals.css), which silently defeats the
+// overwrite guard.
+const CSS_SCAN_DIRS = [
+ 'src',
+ 'src/styles',
+ 'src/css',
+ 'src/assets/styles',
+ 'app',
+ 'app/styles',
+ 'styles',
+ 'css'
+];
const TAILWIND_CONFIGS = [
'tailwind.config.js',
'tailwind.config.cjs',
@@ -89,7 +112,23 @@ function findExistingTokenSources(projectRoot) {
addIfPresent(DESIGN_TOKENS_JSON);
addIfPresent(DESIGN_TOKENS_CSS);
- for (const relativePath of CSS_TOKEN_SOURCES) {
+ const candidates = new Set(CSS_TOKEN_SOURCES);
+ for (const dir of CSS_SCAN_DIRS) {
+ const absoluteDir = path.resolve(projectRoot, dir);
+ let entries;
+ try {
+ entries = fs.readdirSync(absoluteDir, { withFileTypes: true });
+ } catch {
+ continue;
+ }
+ for (const entry of entries) {
+ if (entry.isFile() && entry.name.toLowerCase().endsWith('.css')) {
+ candidates.add(`${dir}/${entry.name}`);
+ }
+ }
+ }
+
+ for (const relativePath of candidates) {
const absolutePath = path.resolve(projectRoot, relativePath);
scanCssSource(absolutePath);
}
diff --git a/cli/assets/skills/brand/scripts/tests/test_sync_brand_to_tokens.py b/cli/assets/skills/brand/scripts/tests/test_sync_brand_to_tokens.py
index 7e621e1..3d97d1a 100644
--- a/cli/assets/skills/brand/scripts/tests/test_sync_brand_to_tokens.py
+++ b/cli/assets/skills/brand/scripts/tests/test_sync_brand_to_tokens.py
@@ -315,3 +315,54 @@ def test_force_allows_sync_with_existing_css_token_source(tmp_path):
assert result.returncode == 0, result.stderr + result.stdout
assert (tmp_path / "assets" / "design-tokens.json").exists()
+
+
+ "relative_path",
+ [
+ "src/styles/global.css",
+ "src/global.css",
+ "src/main.css",
+ "src/styles/theme.css",
+ "styles/variables.css",
+ ],
+)
+def test_refuses_token_source_under_unlisted_css_filename(tmp_path, relative_path):
+ """Token detection must not hinge on an exact filename.
+
+ The candidate list only held the plural `globals.css` spellings, so a
+ project whose entry point is `src/styles/global.css` — one letter apart —
+ was never scanned and the guard silently passed, leaving the generated
+ `assets/design-tokens.*` to compete with an existing palette.
+ """
+ (tmp_path / "docs").mkdir()
+ shutil.copy(BRAND_STARTER, tmp_path / "docs" / "brand-guidelines.md")
+ css = tmp_path / relative_path
+ css.parent.mkdir(parents=True, exist_ok=True)
+ css.write_text(":root {\n --dawn: #f5a524;\n --ink: #1c1626;\n}\n")
+
+ result = _run(tmp_path)
+
+ assert result.returncode == 1, result.stdout + result.stderr
+ assert relative_path in result.stderr
+ assert "--force" in result.stderr
+ assert not (tmp_path / "assets" / "design-tokens.json").exists()
+
+
+def test_discovered_css_without_tokens_does_not_block_sync(tmp_path):
+ """Scanning extra CSS files must not introduce false positives.
+
+ Plain stylesheets carry no custom properties, so they are not token
+ sources and must leave the sync path alone.
+ """
+ (tmp_path / "docs").mkdir()
+ shutil.copy(BRAND_STARTER, tmp_path / "docs" / "brand-guidelines.md")
+ styles = tmp_path / "src" / "styles"
+ styles.mkdir(parents=True)
+ (styles / "global.css").write_text(".btn {\n color: red;\n}\n")
+ (styles / "reset.css").write_text("* {\n margin: 0;\n}\n")
+
+ result = _run(tmp_path)
+
+ assert result.returncode == 0, result.stderr + result.stdout
+ assert (tmp_path / "assets" / "design-tokens.json").exists()