@behavioral-agentic-design-system/core 0.39.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -3
- package/scripts/a11y-lint.cjs +93 -39
- package/scripts/a11y-ratchet.mjs +10 -23
- package/scripts/bads-components.mjs +118 -0
- package/scripts/build-tokens.cjs +175 -17
- package/scripts/check-stories.mjs +1 -1
- package/scripts/health-report.mjs +52 -10
- package/scripts/lib/scan-roots.cjs +143 -0
- package/scripts/lint-component-source.mjs +100 -0
- package/scripts/lint-microanimation.mjs +267 -0
- package/scripts/lint-slop.mjs +21 -28
- package/scripts/lint-token-intent.mjs +10 -16
- package/scripts/size-audit.cjs +94 -27
- package/scripts/source-of-truth.cjs +58 -0
- package/scripts/ux-smoke.mjs +438 -0
- package/scripts/wcag-audit.cjs +49 -1
- package/src/api/layers/file.ts +2 -0
- package/src/app/preview/components/page.tsx +972 -0
- package/src/app/preview/health/page.tsx +8 -5
- package/src/app/preview/history/page.tsx +11 -0
- package/src/app/shell.tsx +261 -87
- package/src/components/customize/brand-mark-section.tsx +4 -2
- package/src/components/customize/design-controls.tsx +1 -1
- package/src/components/customize/discipline-section.tsx +91 -0
- package/src/components/customize/font-pickers.tsx +1 -1
- package/src/components/customize/letter-spacing.tsx +1 -1
- package/src/components/customize/save-bar.tsx +2 -2
- package/src/components/customize/theme-io.tsx +7 -7
- package/src/components/customize/type-scale.tsx +1 -1
- package/src/components/customize-tab.tsx +9 -4
- package/src/components/home-tab.tsx +3 -0
- package/src/components/ui/accordion.tsx +7 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/announcement-bar.tsx +256 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/callout.tsx +218 -0
- package/src/components/ui/chart.tsx +2 -14
- package/src/components/ui/color-picker.tsx +1 -1
- package/src/components/ui/format-relative-time.tsx +139 -0
- package/src/components/ui/grid.tsx +255 -0
- package/src/components/ui/icon.tsx +108 -0
- package/src/components/ui/index.ts +8 -0
- package/src/components/ui/page-header.tsx +63 -0
- package/src/components/ui/portal.tsx +111 -0
- package/src/components/ui/presence.tsx +172 -0
- package/src/components/ui/progress-stack.tsx +258 -0
- package/src/components/ui/select.tsx +89 -4
- package/src/components/ui/separator.tsx +1 -0
- package/src/components/ui/slider.tsx +83 -3
- package/src/components/ui/sparkline.tsx +15 -15
- package/src/components/ui/textarea.tsx +28 -1
- package/src/data/docs-index.ts +5 -0
- package/src/data/history.json +269 -0
- package/src/hooks/use-reduced-motion.ts +6 -0
- package/src/stories/Accordion.stories.tsx +59 -0
- package/src/stories/Alert.stories.tsx +3 -1
- package/src/stories/AnnouncementBar.stories.tsx +261 -0
- package/src/stories/Badge.stories.tsx +3 -0
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Callout.stories.tsx +219 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/ColorPicker.stories.tsx +23 -0
- package/src/stories/FormatRelativeTime.stories.tsx +116 -0
- package/src/stories/Grid.stories.tsx +197 -0
- package/src/stories/Icon.stories.tsx +175 -0
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/PageHeader.stories.tsx +102 -0
- package/src/stories/Portal.stories.tsx +189 -0
- package/src/stories/Presence.stories.tsx +228 -0
- package/src/stories/ProgressStack.stories.tsx +287 -0
- package/src/stories/Select.stories.tsx +25 -0
- package/src/stories/Separator.stories.tsx +3 -0
- package/src/stories/Sheet.stories.tsx +9 -3
- package/src/stories/Slider.stories.tsx +54 -5
- package/src/stories/Sparkline.stories.tsx +39 -0
- package/src/stories/Textarea.stories.tsx +18 -0
- package/src/stories/story-groups.json +14 -5
- package/src/styles.css +133 -12
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// pnpm lint:microanimation — flags components that use hardcoded Tailwind
|
|
3
|
+
// motion utilities instead of BADS motion tokens.
|
|
4
|
+
//
|
|
5
|
+
// New components (per CLAUDE.md → Components & Registry → microanimation rule)
|
|
6
|
+
// must drive transitions from BADS motion tokens:
|
|
7
|
+
// duration-[var(--duration-fast|base|slow)]
|
|
8
|
+
// ease-[var(--ease-out|in|in-out|spring)]
|
|
9
|
+
//
|
|
10
|
+
// The Tailwind defaults (`duration-200`, `ease-out`, etc.) are anti-patterns
|
|
11
|
+
// here — they bypass the token surface, so a tone-shift in the motion system
|
|
12
|
+
// can't propagate to the components that use them.
|
|
13
|
+
//
|
|
14
|
+
// Advisory by default. `--strict` exits 1 on any violation (used in the
|
|
15
|
+
// Night Shift step 3b verification gates).
|
|
16
|
+
//
|
|
17
|
+
// Scope by default: the published primitive surface
|
|
18
|
+
// (`packages/core/src/components/ui/*.tsx`). Compositions and showcase code
|
|
19
|
+
// in `components/` and `app/` are not in scope — those are end-product
|
|
20
|
+
// surfaces where one-off `duration-200` is sometimes the right call.
|
|
21
|
+
//
|
|
22
|
+
// File-scoped runs: pass `.tsx` paths as positional args to scan only those.
|
|
23
|
+
// Used by the Night Shift step 3b gate so existing debt elsewhere doesn't
|
|
24
|
+
// block a clean new-component PR. Example:
|
|
25
|
+
//
|
|
26
|
+
// node scripts/lint-microanimation.mjs --strict \
|
|
27
|
+
// packages/core/src/components/ui/accordion.tsx
|
|
28
|
+
|
|
29
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
30
|
+
import { resolve, join, isAbsolute } from 'node:path';
|
|
31
|
+
import { fileURLToPath } from 'node:url';
|
|
32
|
+
|
|
33
|
+
// cwd-rooted so this works in a consumer repo. Rooting at __dirname would make
|
|
34
|
+
// it walk up to the design system and report a pass for files the caller never
|
|
35
|
+
// opened — see scripts/_upstream-only.mjs for the measured version of that bug.
|
|
36
|
+
const ROOT = process.cwd();
|
|
37
|
+
// First primitive directory that exists here. Upstream that is the package
|
|
38
|
+
// source; in a fork consuming @core from npm it is the local components dir.
|
|
39
|
+
const DEFAULT_SCAN_DIR = [
|
|
40
|
+
'packages/core/src/components/ui',
|
|
41
|
+
'components/ui',
|
|
42
|
+
'src/components/ui',
|
|
43
|
+
]
|
|
44
|
+
.map((d) => resolve(ROOT, d))
|
|
45
|
+
.find((d) => existsSync(d)) ?? resolve(ROOT, 'components');
|
|
46
|
+
|
|
47
|
+
const argv = process.argv.slice(2);
|
|
48
|
+
const STRICT = argv.includes('--strict');
|
|
49
|
+
const explicitFiles = argv
|
|
50
|
+
.filter((a) => !a.startsWith('--'))
|
|
51
|
+
.map((a) => (isAbsolute(a) ? a : resolve(process.cwd(), a)));
|
|
52
|
+
|
|
53
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
54
|
+
// rules
|
|
55
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
56
|
+
//
|
|
57
|
+
// Rules updated 2026-06-17 after the Accordion saga (5 PRs) surfaced the
|
|
58
|
+
// actual Tailwind v4 + BADS reality:
|
|
59
|
+
//
|
|
60
|
+
// 1. Tailwind v4 generates utility classes from these recognized theme
|
|
61
|
+
// namespaces ONLY: --color-*, --ease-*, --animate-*, --font-*,
|
|
62
|
+
// --text-*, --radius-*, --shadow-*, --spacing-*, --breakpoint-*, etc.
|
|
63
|
+
// It does NOT have a --duration-* namespace. So `duration-fast`,
|
|
64
|
+
// `duration-base`, `duration-slow` are SILENT FAILURES — they
|
|
65
|
+
// compile to nothing and the transition has no duration.
|
|
66
|
+
//
|
|
67
|
+
// 2. The arbitrary-value form `duration-[var(--duration-fast)]` SHOULD
|
|
68
|
+
// generate a utility but the Tailwind v4 scanner's pickup of these
|
|
69
|
+
// across @theme inline cascade is inconsistent. Treat as unreliable.
|
|
70
|
+
//
|
|
71
|
+
// 3. The correct token-driven pattern in this setup is inline `style`:
|
|
72
|
+
// style={{ transitionDuration: 'var(--duration-fast)',
|
|
73
|
+
// transitionTimingFunction: 'var(--ease-out)' }}
|
|
74
|
+
// CSS vars resolve at runtime against :root, propagate from
|
|
75
|
+
// tokens.json via `pnpm build:tokens`. Bulletproof.
|
|
76
|
+
//
|
|
77
|
+
// 4. For keyframe animations (accordion-down, drawer-slide, etc.),
|
|
78
|
+
// define them in packages/core/scripts/build-tokens.cjs and apply
|
|
79
|
+
// via direct CSS selectors on data-slot + data-state. NOT via
|
|
80
|
+
// @theme inline --animate-* tokens (also unreliable v4 generation).
|
|
81
|
+
//
|
|
82
|
+
// 5. Tailwind stock utilities that DO work:
|
|
83
|
+
// - duration-{75|100|150|200|...} — numeric durations, work but
|
|
84
|
+
// bypass the token surface. Advisory warning only (--strict
|
|
85
|
+
// doesn't fail) since the values happen to match BADS tokens 1:1.
|
|
86
|
+
// - ease-out, ease-spring, ease-in, ease-in-out, ease-linear —
|
|
87
|
+
// Tailwind v4 recognizes --ease-* namespace, these are token-
|
|
88
|
+
// driven via the @theme inline declarations.
|
|
89
|
+
// - transition-colors, transition-transform, transition-opacity,
|
|
90
|
+
// transition-all — property utilities, no duration baked in.
|
|
91
|
+
//
|
|
92
|
+
// What this lint flags now (in --strict, fails CI):
|
|
93
|
+
// - duration-fast | duration-base | duration-slow (silent failure)
|
|
94
|
+
// - duration-[var(--duration-*)] (unreliable v4 scanner pickup)
|
|
95
|
+
// - inline transitionDuration: "<literal-ms>" (hardcoded ms, not token)
|
|
96
|
+
// - inline transitionTimingFunction: "<literal-bezier-or-name>" (hardcoded)
|
|
97
|
+
//
|
|
98
|
+
// What this lint warns on (advisory, doesn't fail --strict):
|
|
99
|
+
// - duration-{numeric} (works, but not token-driven — flag for awareness)
|
|
100
|
+
//
|
|
101
|
+
// What this lint PERMITS (canonical patterns):
|
|
102
|
+
// - inline style={{ transitionDuration: "var(--duration-*)", ... }}
|
|
103
|
+
// - ease-out, ease-spring, etc.
|
|
104
|
+
// - transition-colors, transition-transform, etc.
|
|
105
|
+
// - data-[state=open]:animate-<keyframe-name> for keyframe animations
|
|
106
|
+
// defined in build-tokens.cjs
|
|
107
|
+
|
|
108
|
+
const RULES = [
|
|
109
|
+
{
|
|
110
|
+
name: 'unreliable-tailwind-duration-token',
|
|
111
|
+
pattern: /(?<![\[\w-])(duration-(?:fast|base|slow))(?![\w-])/g,
|
|
112
|
+
severity: 'error',
|
|
113
|
+
why: 'Silent failure: Tailwind v4 does NOT auto-generate utilities from --duration-* theme tokens (only --ease-*, --animate-*, --color-*, etc.). This class compiles to nothing — the transition has no duration and snaps instead of animating.',
|
|
114
|
+
fix: 'Use inline style for the duration: style={{ transitionDuration: "var(--duration-fast)" }} (or --duration-base / --duration-slow). Keep the Tailwind class for the transition property (transition-colors, transition-transform, etc.).',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'unreliable-arbitrary-duration-var',
|
|
118
|
+
pattern: /(?<![\[\w-])(duration-\[var\(--duration-(?:fast|base|slow)\)\])/g,
|
|
119
|
+
severity: 'error',
|
|
120
|
+
why: 'Unreliable: Tailwind v4 scanner pickup of arbitrary-value classes referencing @theme inline CSS vars is inconsistent across this setup. The Accordion saga (5 PRs) confirmed it does not reliably produce a CSS rule.',
|
|
121
|
+
fix: 'Use inline style: style={{ transitionDuration: "var(--duration-fast)" }}. Bulletproof — CSS vars resolve at runtime against :root.',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'hardcoded-inline-transition-duration',
|
|
125
|
+
pattern: /(transitionDuration:\s*["'`](?!var\()[^"'`]+["'`])/g,
|
|
126
|
+
severity: 'error',
|
|
127
|
+
why: 'Inline transitionDuration with a literal value (ms or s). Bypasses the BADS motion token surface — changes to tokens.json will not propagate.',
|
|
128
|
+
fix: 'Use a token reference: transitionDuration: "var(--duration-fast)" (150ms typical), "var(--duration-base)" (200ms), or "var(--duration-slow)" (300ms).',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'hardcoded-inline-transition-timing',
|
|
132
|
+
pattern: /(transitionTimingFunction:\s*["'`](?!var\()[^"'`]+["'`])/g,
|
|
133
|
+
severity: 'error',
|
|
134
|
+
why: 'Inline transitionTimingFunction with a literal value (bezier or stock name). Bypasses the BADS motion token surface.',
|
|
135
|
+
fix: 'Use a token reference: transitionTimingFunction: "var(--ease-out)" (most cases), "var(--ease-spring)" (contained overshoot — chevron flips, switch handles), "var(--ease-in)" (accelerate), or "var(--ease-in-out)" (symmetric). OR drop the inline style and use the Tailwind utility ease-out / ease-spring / etc. — those DO work via the v4 --ease-* namespace.',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'tailwind-numeric-duration',
|
|
139
|
+
pattern: /(?<![\[\w-])(duration-(?:75|100|150|200|300|500|700|1000))(?![\w-])/g,
|
|
140
|
+
severity: 'warn',
|
|
141
|
+
why: 'Stock Tailwind numeric duration. Works (Tailwind generates this utility) but bypasses the BADS motion token surface — changes to tokens.json will not propagate. Acceptable when the value matches a token 1:1 and you want the Tailwind-class form for terseness; preferred is inline style with var(--duration-*).',
|
|
142
|
+
fix: 'Prefer style={{ transitionDuration: "var(--duration-base)" }} (200ms). If you keep duration-200, note that it works because Tailwind generates `transition-duration: 200ms` directly — but it will not pick up future token changes.',
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
147
|
+
// scan
|
|
148
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
function listTsxFiles(dir) {
|
|
151
|
+
let entries;
|
|
152
|
+
try {
|
|
153
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
154
|
+
} catch {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
const out = [];
|
|
158
|
+
for (const e of entries) {
|
|
159
|
+
if (e.isFile() && e.name.endsWith('.tsx')) out.push(join(dir, e.name));
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Strip JS line + block comments so explanatory comments mentioning
|
|
165
|
+
// anti-pattern class names (e.g. "// `duration-fast` doesn't compile") don't
|
|
166
|
+
// trigger false positives. Replaces matched comment contents with spaces of
|
|
167
|
+
// the same length so line/col numbers in findings still align with the
|
|
168
|
+
// original source.
|
|
169
|
+
function stripComments(src) {
|
|
170
|
+
return src
|
|
171
|
+
.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '))
|
|
172
|
+
.replace(/\/\/[^\n]*/g, (m) => ' '.repeat(m.length));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function scanFile(filePath) {
|
|
176
|
+
const body = readFileSync(filePath, 'utf8');
|
|
177
|
+
const stripped = stripComments(body);
|
|
178
|
+
const lines = body.split('\n');
|
|
179
|
+
const findings = [];
|
|
180
|
+
for (const rule of RULES) {
|
|
181
|
+
rule.pattern.lastIndex = 0;
|
|
182
|
+
let m;
|
|
183
|
+
while ((m = rule.pattern.exec(stripped)) !== null) {
|
|
184
|
+
// Compute line/col from match index.
|
|
185
|
+
const upto = body.slice(0, m.index);
|
|
186
|
+
const line = upto.split('\n').length;
|
|
187
|
+
const col = m.index - upto.lastIndexOf('\n');
|
|
188
|
+
findings.push({
|
|
189
|
+
file: filePath,
|
|
190
|
+
line,
|
|
191
|
+
col,
|
|
192
|
+
match: m[1],
|
|
193
|
+
rule: rule.name,
|
|
194
|
+
severity: rule.severity ?? 'error',
|
|
195
|
+
why: rule.why,
|
|
196
|
+
fix: rule.fix,
|
|
197
|
+
context: (lines[line - 1] ?? '').trim(),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return findings;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
205
|
+
// main
|
|
206
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
207
|
+
|
|
208
|
+
function main() {
|
|
209
|
+
let files;
|
|
210
|
+
let scope;
|
|
211
|
+
if (explicitFiles.length > 0) {
|
|
212
|
+
files = explicitFiles.filter((p) => {
|
|
213
|
+
try {
|
|
214
|
+
return statSync(p).isFile() && p.endsWith('.tsx');
|
|
215
|
+
} catch {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
scope = `${files.length} explicitly-scoped file(s)`;
|
|
220
|
+
} else {
|
|
221
|
+
files = listTsxFiles(DEFAULT_SCAN_DIR);
|
|
222
|
+
scope = `${files.length} primitive(s) in packages/core/src/components/ui/`;
|
|
223
|
+
}
|
|
224
|
+
const allFindings = files.flatMap(scanFile);
|
|
225
|
+
|
|
226
|
+
console.log(`lint-microanimation — scanned ${scope}.`);
|
|
227
|
+
|
|
228
|
+
if (allFindings.length === 0) {
|
|
229
|
+
console.log(' every primitive drives motion from BADS tokens. clean.');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Group by file for readable output.
|
|
234
|
+
const byFile = new Map();
|
|
235
|
+
for (const f of allFindings) {
|
|
236
|
+
if (!byFile.has(f.file)) byFile.set(f.file, []);
|
|
237
|
+
byFile.get(f.file).push(f);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const errorCount = allFindings.filter((f) => f.severity === 'error').length;
|
|
241
|
+
const warnCount = allFindings.filter((f) => f.severity === 'warn').length;
|
|
242
|
+
console.log(` flagged: ${errorCount} error(s), ${warnCount} warning(s) across ${byFile.size} file(s).`);
|
|
243
|
+
console.log('');
|
|
244
|
+
|
|
245
|
+
for (const [file, findings] of byFile) {
|
|
246
|
+
const rel = file.replace(ROOT + '/', '');
|
|
247
|
+
console.log(rel);
|
|
248
|
+
for (const f of findings) {
|
|
249
|
+
const badge = f.severity === 'error' ? 'ERROR ' : 'warn ';
|
|
250
|
+
console.log(` ${badge}${rel}:${f.line}:${f.col}`);
|
|
251
|
+
console.log(` rule: ${f.rule}`);
|
|
252
|
+
console.log(` match: ${f.match}`);
|
|
253
|
+
console.log(` why: ${f.why}`);
|
|
254
|
+
console.log(` fix: ${f.fix}`);
|
|
255
|
+
console.log(` line: ${f.context}`);
|
|
256
|
+
console.log('');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log('See CLAUDE.md → Components & Registry → microanimation rule for the full contract.');
|
|
261
|
+
|
|
262
|
+
// --strict fails ONLY on errors. Warnings are advisory (e.g. duration-200
|
|
263
|
+
// works but bypasses tokens — don't block a build on it).
|
|
264
|
+
if (STRICT && errorCount > 0) process.exit(1);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
main();
|
package/scripts/lint-slop.mjs
CHANGED
|
@@ -79,38 +79,26 @@ import path from "node:path";
|
|
|
79
79
|
// repo root.
|
|
80
80
|
const ROOT = process.cwd();
|
|
81
81
|
import { RULES, FILE_RULES } from "./slop-rules.mjs";
|
|
82
|
+
// scan-roots.cjs is CommonJS (shared with the three .cjs bins); the default
|
|
83
|
+
// import is Node's CJS→ESM interop and always carries the full
|
|
84
|
+
// module.exports object, unlike named imports off an arbitrary CJS module.
|
|
85
|
+
import scanRootsLib from "./lib/scan-roots.cjs";
|
|
86
|
+
const { resolveScanFiles, guardEmptyScan } = scanRootsLib;
|
|
82
87
|
|
|
83
88
|
const advisory = process.argv.includes("--warn");
|
|
84
|
-
const explicitPaths = process.argv.slice(2).filter((a) => !a.startsWith("--"));
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// (those live in scripts/, out of scan scope).
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function walk(dir, out = []) {
|
|
100
|
-
if (!fs.existsSync(dir)) return out;
|
|
101
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
102
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
103
|
-
const full = path.join(dir, entry.name);
|
|
104
|
-
if (entry.isDirectory()) walk(full, out);
|
|
105
|
-
else if (/\.tsx?$/.test(entry.name) && !/\.stories\.tsx?$/.test(entry.name))
|
|
106
|
-
out.push(full);
|
|
107
|
-
}
|
|
108
|
-
return out;
|
|
109
|
-
}
|
|
90
|
+
// Centralized in ./lib/scan-roots.cjs — see that file for why: this script,
|
|
91
|
+
// a11y-lint.cjs, size-audit.cjs, a11y-ratchet.mjs and lint-token-intent.mjs
|
|
92
|
+
// used to each keep a drifted copy of the same root list. Set
|
|
93
|
+
// BADS_LINT_ROOTS to point this at a non-standard tree.
|
|
94
|
+
const scan = resolveScanFiles({
|
|
95
|
+
root: ROOT,
|
|
96
|
+
argv: process.argv.slice(2),
|
|
97
|
+
excludeStories: true,
|
|
98
|
+
});
|
|
110
99
|
|
|
111
100
|
function fileList() {
|
|
112
|
-
|
|
113
|
-
return SCAN_ROOTS.flatMap((r) => walk(path.join(ROOT, r)));
|
|
101
|
+
return scan.files;
|
|
114
102
|
}
|
|
115
103
|
|
|
116
104
|
const findings = [];
|
|
@@ -184,7 +172,12 @@ for (const file of fileList()) {
|
|
|
184
172
|
}
|
|
185
173
|
|
|
186
174
|
if (findings.length === 0) {
|
|
187
|
-
|
|
175
|
+
if (guardEmptyScan(scan, "lint-slop")) { /* exited */ }
|
|
176
|
+
console.log(
|
|
177
|
+
scan.files.length
|
|
178
|
+
? "✓ lint-slop: no AI-slop signals found."
|
|
179
|
+
: "✓ lint-slop: no AI-slop signals found (0 files matched under existing scan roots)."
|
|
180
|
+
);
|
|
188
181
|
process.exit(0);
|
|
189
182
|
}
|
|
190
183
|
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
*/
|
|
31
31
|
import fs from "node:fs";
|
|
32
32
|
import path from "node:path";
|
|
33
|
+
import scanRootsLib from "./lib/scan-roots.cjs";
|
|
34
|
+
const { resolveScanFiles, guardEmptyScan } = scanRootsLib;
|
|
33
35
|
|
|
34
36
|
// Repo-root resolution is cwd-based (not file-relative) so this works both in
|
|
35
37
|
// upstream BADS (scripts/ -> repo root) and after shipping as a package bin
|
|
@@ -39,22 +41,9 @@ const ROOT = process.cwd();
|
|
|
39
41
|
const argv = process.argv.slice(2);
|
|
40
42
|
const STRICT = argv.includes("--strict");
|
|
41
43
|
const LOG = argv.includes("--log");
|
|
42
|
-
const fileArgs = argv.filter((a) => !a.startsWith("--"));
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const tsxFiles = [];
|
|
47
|
-
const walk = (dir) => {
|
|
48
|
-
if (!fs.existsSync(dir)) return;
|
|
49
|
-
for (const d of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
50
|
-
if (d.name === "node_modules" || d.name.startsWith(".")) continue;
|
|
51
|
-
const p = path.join(dir, d.name);
|
|
52
|
-
if (d.isDirectory()) walk(p);
|
|
53
|
-
else if (/\.tsx$/.test(d.name)) tsxFiles.push(p);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
if (fileArgs.length) tsxFiles.push(...fileArgs.map((f) => path.resolve(f)));
|
|
57
|
-
else SCAN_DIRS.forEach((d) => walk(path.join(ROOT, d)));
|
|
45
|
+
const scan = resolveScanFiles({ root: ROOT, argv: process.argv.slice(2) });
|
|
46
|
+
const tsxFiles = scan.files;
|
|
58
47
|
|
|
59
48
|
// status vocabulary that indicates the copy's semantic register
|
|
60
49
|
const VOCAB = {
|
|
@@ -107,7 +96,12 @@ for (const file of tsxFiles) {
|
|
|
107
96
|
}
|
|
108
97
|
|
|
109
98
|
if (!findings.length) {
|
|
110
|
-
|
|
99
|
+
if (guardEmptyScan(scan, 'lint-token-intent')) { /* exited */ }
|
|
100
|
+
console.log(
|
|
101
|
+
scan.files.length
|
|
102
|
+
? `✓ token-intent: no intent mismatches across ${scan.files.length} files (2 rule families)`
|
|
103
|
+
: '✓ token-intent: no intent mismatches (0 files matched under existing scan roots)'
|
|
104
|
+
);
|
|
111
105
|
process.exit(0);
|
|
112
106
|
}
|
|
113
107
|
console.log(`token-intent: ${findings.length} candidate mismatch(es) across ${tsxFiles.length} files ${STRICT ? "" : "(advisory)"}\n`);
|
package/scripts/size-audit.cjs
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* Run:
|
|
27
27
|
* pnpm size-audit # report violations, exit 1 on fail
|
|
28
28
|
* pnpm size-audit:warn # report but exit 0 (advisory)
|
|
29
|
-
* node scripts/size-audit.
|
|
29
|
+
* node packages/core/scripts/size-audit.cjs path/to.tsx # scan a specific file
|
|
30
30
|
*
|
|
31
31
|
* Rule code: BADS-2. (BADS-1 = raw <button> not using BADS Button.)
|
|
32
32
|
*/
|
|
@@ -35,38 +35,21 @@
|
|
|
35
35
|
|
|
36
36
|
const fs = require('fs');
|
|
37
37
|
const path = require('path');
|
|
38
|
+
const { resolveScanFiles, guardEmptyScan } = require('./lib/scan-roots.cjs');
|
|
38
39
|
|
|
39
40
|
// Packaged as the `bads-size-audit` bin: runs against the CONSUMER repo
|
|
40
41
|
// (cwd), so prototype repos and client forks get the CTA size contract
|
|
41
42
|
// without copying the script. Pass scan roots as positional args
|
|
42
|
-
// (`bads-size-audit app components`) or rely on the defaults
|
|
43
|
+
// (`bads-size-audit app components`) or rely on the shared defaults in
|
|
44
|
+
// ./lib/scan-roots.cjs (also set BADS_LINT_ROOTS). That file explains why
|
|
45
|
+
// the roots are centralized: this script, a11y-lint, lint-slop,
|
|
46
|
+
// a11y-ratchet and lint-token-intent used to keep drifted copies of the
|
|
47
|
+
// same list.
|
|
43
48
|
const ROOT = process.cwd();
|
|
44
49
|
const advisory = process.argv.includes('--warn');
|
|
45
|
-
const argPaths = process.argv.slice(2).filter((a) => !a.startsWith('--'));
|
|
46
|
-
const argRoots = argPaths.filter((p) => fs.existsSync(p) && fs.statSync(p).isDirectory());
|
|
47
|
-
const explicitPaths = argPaths.filter((p) => !argRoots.includes(p));
|
|
48
|
-
|
|
49
|
-
const SCAN_ROOTS = argRoots.length
|
|
50
|
-
? argRoots
|
|
51
|
-
: ['app', 'components', 'src'].filter((r) => fs.existsSync(path.join(ROOT, r)));
|
|
52
|
-
|
|
53
|
-
function walk(dir, out = []) {
|
|
54
|
-
if (!fs.existsSync(dir)) return out;
|
|
55
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
56
|
-
if (entry.name.startsWith('.') || entry.name === 'node_modules') continue;
|
|
57
|
-
const full = path.join(dir, entry.name);
|
|
58
|
-
if (entry.isDirectory()) {
|
|
59
|
-
walk(full, out);
|
|
60
|
-
} else if (/\.tsx?$/.test(entry.name)) {
|
|
61
|
-
out.push(full);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return out;
|
|
65
|
-
}
|
|
66
50
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
: SCAN_ROOTS.flatMap((r) => walk(path.join(ROOT, r)));
|
|
51
|
+
const scan = resolveScanFiles({ root: ROOT, argv: process.argv.slice(2), allowDirArgs: true });
|
|
52
|
+
const files = scan.files;
|
|
70
53
|
|
|
71
54
|
const issues = [];
|
|
72
55
|
|
|
@@ -78,6 +61,44 @@ const BUTTON_OPEN = /<button\b/;
|
|
|
78
61
|
const TEXT_XS = /\btext-xs\b/;
|
|
79
62
|
const ESCAPE_HATCH = /allow-text-xs-cta/;
|
|
80
63
|
|
|
64
|
+
// ── BADS-2b: a full-width <Button> below the 44px touch-target floor ─────────
|
|
65
|
+
//
|
|
66
|
+
// CLAUDE.md calls 44px non-negotiable (SC 2.5.5) and then documents Button's
|
|
67
|
+
// `default` (h-9, 36px) and `lg` (h-10, 40px) as exceptions reserved for dense
|
|
68
|
+
// NON-CTA chrome: toolbars, table row actions, dialog footers. Sir's call on
|
|
69
|
+
// 2026-09-11 was to keep those sizes and enforce the contract instead, because
|
|
70
|
+
// bumping the default reflows every button in every fork to fix a misuse that
|
|
71
|
+
// may not exist.
|
|
72
|
+
//
|
|
73
|
+
// So the question is how to tell a CTA from chrome, statically, without crying
|
|
74
|
+
// wolf — a false BLOCKER sends someone to fix a correct component and teaches
|
|
75
|
+
// people to bypass the gate (CLAUDE.md, "ask what a passing check measured").
|
|
76
|
+
//
|
|
77
|
+
// `w-full` is the signal with no honest counter-example. Dense chrome is never
|
|
78
|
+
// full-width: a toolbar button sits in a row of them, a table row action is
|
|
79
|
+
// icon-sized, a dialog footer button hugs its label. A button told to fill its
|
|
80
|
+
// container is the primary action of that container, which is exactly the
|
|
81
|
+
// flow-changing case the floor is for. It is also the shape corrections #011
|
|
82
|
+
// already documents as the trap ("a `w-full` button carrying a multi-word
|
|
83
|
+
// label").
|
|
84
|
+
//
|
|
85
|
+
// Deliberately NOT flagged, because each has a real counter-example:
|
|
86
|
+
// type="submit" — dialog footers submit, and they are sanctioned chrome
|
|
87
|
+
// CTA-sounding label — "Save" is a hero CTA on one screen, chrome on another
|
|
88
|
+
// inside a <form> — says nothing about the button's prominence
|
|
89
|
+
//
|
|
90
|
+
// Fix is `size="xl"` (h-11) or `size="2xl"` (h-12), or keep the default text
|
|
91
|
+
// register with `size="default" className="min-h-11 w-full"`. The escape is
|
|
92
|
+
// `// allow-small-cta <reason>` on the line above.
|
|
93
|
+
const BUTTON_COMPONENT_OPEN = /<Button\b/;
|
|
94
|
+
const W_FULL = /\bw-full\b/;
|
|
95
|
+
const HAS_MIN_H_11 = /\bmin-h-(?:11|12|\[(?:44|48)px\])\b/;
|
|
96
|
+
const SIZE_PROP = /\bsize=\{?["']([a-z0-9-]+)["']\}?/;
|
|
97
|
+
const SMALL_CTA_ESCAPE = /allow-small-cta/;
|
|
98
|
+
// Sizes at or above 44px. Anything else (including no size prop at all, which
|
|
99
|
+
// is `default` at 36px) is under the floor.
|
|
100
|
+
const COMPLIANT_SIZES = new Set(['xl', '2xl', 'icon-xl']);
|
|
101
|
+
|
|
81
102
|
for (const file of files) {
|
|
82
103
|
let src;
|
|
83
104
|
try { src = fs.readFileSync(file, 'utf8'); } catch { continue; }
|
|
@@ -121,10 +142,56 @@ for (const file of files) {
|
|
|
121
142
|
flag(file, classLine + 1, 'BADS-2',
|
|
122
143
|
`Raw <button> with text-xs is below the CTA size contract (text-sm / 16px). Bump to text-sm, or add "// allow-text-xs-cta" on the line above the <button> with a reason (see prompts/cta-size-contract.md).`);
|
|
123
144
|
}
|
|
145
|
+
|
|
146
|
+
// BADS-2b — <Button className="... w-full"> at a size under 44px.
|
|
147
|
+
for (let i = 0; i < lines.length; i++) {
|
|
148
|
+
if (!BUTTON_COMPONENT_OPEN.test(lines[i])) continue;
|
|
149
|
+
|
|
150
|
+
// Gather the opening tag: from `<Button` to the first `>` that closes it,
|
|
151
|
+
// capped so a malformed file cannot run away.
|
|
152
|
+
let tag = '';
|
|
153
|
+
let end = i;
|
|
154
|
+
for (let j = i; j < Math.min(i + 12, lines.length); j++) {
|
|
155
|
+
tag += lines[j] + '\n';
|
|
156
|
+
end = j;
|
|
157
|
+
if (/>/.test(lines[j].slice(lines[j].indexOf('<Button'))) && j > i) break;
|
|
158
|
+
if (j === i && /<Button[^>]*>/.test(lines[j])) break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!W_FULL.test(tag)) continue;
|
|
162
|
+
if (HAS_MIN_H_11.test(tag)) continue;
|
|
163
|
+
|
|
164
|
+
// A size passed as an expression (`size={size}`, `size={compact ? "sm" :
|
|
165
|
+
// "xl"}`) is unknowable from source, and a primitive forwarding its own
|
|
166
|
+
// size prop is the common shape. Guessing "default" there reported
|
|
167
|
+
// Combobox's trigger, which renders at whatever size its consumer asks
|
|
168
|
+
// for. Present-but-unquoted means skip, not assume.
|
|
169
|
+
const hasSizeProp = /\bsize=/.test(tag);
|
|
170
|
+
const m = tag.match(SIZE_PROP);
|
|
171
|
+
if (hasSizeProp && !m) continue;
|
|
172
|
+
const size = m ? m[1] : 'default';
|
|
173
|
+
if (COMPLIANT_SIZES.has(size)) continue;
|
|
174
|
+
|
|
175
|
+
let escaped = false;
|
|
176
|
+
for (let k = i - 1; k >= Math.max(0, i - 3); k--) {
|
|
177
|
+
if (SMALL_CTA_ESCAPE.test(lines[k])) { escaped = true; break; }
|
|
178
|
+
}
|
|
179
|
+
if (escaped) continue;
|
|
180
|
+
|
|
181
|
+
const px = size === 'lg' ? 40 : size === 'sm' ? 32 : 36;
|
|
182
|
+
flag(file, i + 1, 'BADS-2b',
|
|
183
|
+
`Full-width <Button size="${size}"> is ${px}px tall, under the 44px touch-target floor (SC 2.5.5). A w-full button is the primary action of its container, not dense chrome. Use size="xl", or size="${size}" className="min-h-11 w-full" to keep this text register. Escape with "// allow-small-cta <reason>" above it.`);
|
|
184
|
+
i = end;
|
|
185
|
+
}
|
|
124
186
|
}
|
|
125
187
|
|
|
126
188
|
if (issues.length === 0) {
|
|
127
|
-
|
|
189
|
+
if (guardEmptyScan(scan, 'size-audit')) { /* exited */ }
|
|
190
|
+
console.log(
|
|
191
|
+
scan.files.length
|
|
192
|
+
? '✓ size-audit: every CTA reads at text-sm. No size divergence.'
|
|
193
|
+
: '✓ size-audit: every CTA reads at text-sm (0 files matched under existing scan roots).'
|
|
194
|
+
);
|
|
128
195
|
process.exit(0);
|
|
129
196
|
}
|
|
130
197
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* readSourceOfTruth — the single reader for `.client-identity.json`'s
|
|
4
|
+
* `sourceOfTruth` block.
|
|
5
|
+
*
|
|
6
|
+
* There is exactly one parser because several things need this value across
|
|
7
|
+
* three runtimes: node lints, `next.config.js` at build time, and React through
|
|
8
|
+
* an inlined env var. Separate copies drift, which is corrections.md #023.
|
|
9
|
+
*
|
|
10
|
+
* It NEVER throws. `next.config.js` calls it, so a malformed identity file that
|
|
11
|
+
* threw here would break every build in the fork rather than degrade to the
|
|
12
|
+
* safe default.
|
|
13
|
+
*
|
|
14
|
+
* It lives flat in `packages/core/scripts/` (not a `lib/` subdirectory) because
|
|
15
|
+
* `scripts/run-script-tests.mjs` reads that directory non-recursively, so a test
|
|
16
|
+
* beside a nested module would silently never run. It ships inside the package
|
|
17
|
+
* because forks receive `@core` over npm, and it needs the `./scripts/*` entry
|
|
18
|
+
* in the package `exports` map to be reachable by specifier.
|
|
19
|
+
*/
|
|
20
|
+
const { readFileSync } = require("node:fs");
|
|
21
|
+
const { join } = require("node:path");
|
|
22
|
+
|
|
23
|
+
const DEFAULTS = Object.freeze({
|
|
24
|
+
components: "bads",
|
|
25
|
+
clientLibrary: null,
|
|
26
|
+
clientDocs: null,
|
|
27
|
+
scanRoots: Object.freeze(["app"]),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function defaults() {
|
|
31
|
+
return { ...DEFAULTS, scanRoots: [...DEFAULTS.scanRoots] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readSourceOfTruth(root = process.cwd()) {
|
|
35
|
+
let data;
|
|
36
|
+
try {
|
|
37
|
+
data = JSON.parse(readFileSync(join(root, ".client-identity.json"), "utf8"));
|
|
38
|
+
} catch {
|
|
39
|
+
return defaults();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const block = data && typeof data === "object" ? data.sourceOfTruth : null;
|
|
43
|
+
if (!block || typeof block !== "object" || Array.isArray(block)) return defaults();
|
|
44
|
+
|
|
45
|
+
const scanRoots = Array.isArray(block.scanRoots)
|
|
46
|
+
? block.scanRoots.filter((r) => typeof r === "string" && r.length > 0)
|
|
47
|
+
: [];
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
components: block.components === "client" ? "client" : "bads",
|
|
51
|
+
clientLibrary: typeof block.clientLibrary === "string" ? block.clientLibrary : null,
|
|
52
|
+
clientDocs: typeof block.clientDocs === "string" ? block.clientDocs : null,
|
|
53
|
+
scanRoots: scanRoots.length > 0 ? scanRoots : [...DEFAULTS.scanRoots],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.readSourceOfTruth = readSourceOfTruth;
|
|
58
|
+
exports.DEFAULTS = DEFAULTS;
|