@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
package/scripts/build-tokens.cjs
CHANGED
|
@@ -31,9 +31,42 @@ const path = require('path');
|
|
|
31
31
|
// process.cwd() means the same script works for upstream BADS (CWD = repo
|
|
32
32
|
// root) and for client forks alike.
|
|
33
33
|
const ROOT = process.cwd();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
|
|
35
|
+
// Same candidate resolution wcag-audit.cjs uses. The old single hardcoded
|
|
36
|
+
// `packages/core/src/tokens.json` assumed the consumer was a *fork* (which has
|
|
37
|
+
// that directory). A repo that merely installed the package and keeps
|
|
38
|
+
// tokens.json at its root got ENOENT before printing anything — the identical
|
|
39
|
+
// bug fixed in wcag-audit on 2026-08-24, missed here. Found again 2026-09-09
|
|
40
|
+
// from a standalone consumer, so the resolution now lives in one shared helper
|
|
41
|
+
// (see resolveTokens below) rather than being copied a third time.
|
|
42
|
+
const TOKEN_CANDIDATES = [
|
|
43
|
+
process.env.BADS_TOKENS,
|
|
44
|
+
path.join(ROOT, 'packages/core/src/tokens.json'),
|
|
45
|
+
path.join(ROOT, 'tokens.json'),
|
|
46
|
+
].filter(Boolean);
|
|
47
|
+
|
|
48
|
+
const TOKENS = TOKEN_CANDIDATES.find((p) => fs.existsSync(p));
|
|
49
|
+
if (!TOKENS) {
|
|
50
|
+
console.error(
|
|
51
|
+
'build-tokens: no tokens.json found. Looked in:\n' +
|
|
52
|
+
TOKEN_CANDIDATES.map((p) => ` ${p}`).join('\n') +
|
|
53
|
+
'\n\nSet BADS_TOKENS=/path/to/tokens.json to point at it explicitly.'
|
|
54
|
+
);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Generated CSS lands beside whichever tokens.json we actually read, so a
|
|
59
|
+
// consumer with tokens.json at its root gets ./styles.css rather than a write
|
|
60
|
+
// into a packages/core path it doesn't have. BADS_CSS_OUT overrides the dir.
|
|
61
|
+
const CSS_OUT_DIR = process.env.BADS_CSS_OUT
|
|
62
|
+
? path.resolve(process.env.BADS_CSS_OUT)
|
|
63
|
+
: path.dirname(TOKENS);
|
|
64
|
+
const PKG_CSS = path.join(CSS_OUT_DIR, 'styles.css');
|
|
65
|
+
const PKG_FONTS_CDN_CSS = path.join(CSS_OUT_DIR, 'fonts-cdn.css');
|
|
66
|
+
|
|
67
|
+
// The preview app's globals.css only exists in upstream BADS and in forks that
|
|
68
|
+
// ship the showcase. A package consumer has no styles/ dir, so writing there
|
|
69
|
+
// would either fail or scatter files — skip it unless the dir is already there.
|
|
37
70
|
const APP_CSS = path.join(ROOT, 'styles/globals.css');
|
|
38
71
|
const CLIENT_EXTRAS = path.join(ROOT, 'styles/client-extras.css');
|
|
39
72
|
|
|
@@ -329,10 +362,18 @@ const themeInline = `@theme inline {
|
|
|
329
362
|
:root above already defines --font-sans, and Tailwind picks it up
|
|
330
363
|
for the font-sans utility automatically. */
|
|
331
364
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
365
|
+
/* Per-step override hook, same shape as the type scale above: a fork whose
|
|
366
|
+
brand radius ramp isn't linear-from-one-base (e.g. Furnished Finder's
|
|
367
|
+
4/8/12/16, which no single --radius value produces from these calc()s)
|
|
368
|
+
sets --radius-sm-size etc. directly. Also closes the duplicate-value
|
|
369
|
+
trap this used to have — a brand file that declared --radius-lg in
|
|
370
|
+
:root created a second, silently-losing value under the same name as
|
|
371
|
+
this computed one; the override name is now distinct from the utility
|
|
372
|
+
name it feeds. */
|
|
373
|
+
--radius-sm: var(--radius-sm-size, calc(var(--radius) - 4px));
|
|
374
|
+
--radius-md: var(--radius-md-size, calc(var(--radius) - 2px));
|
|
375
|
+
--radius-lg: var(--radius-lg-size, var(--radius));
|
|
376
|
+
--radius-xl: var(--radius-xl-size, calc(var(--radius) + 4px));
|
|
336
377
|
|
|
337
378
|
/* Map Tailwind's shadow-* utilities through to the :root --shadow-* tokens
|
|
338
379
|
so the Customize tab's Shadow Opacity slider takes effect. Without this
|
|
@@ -385,12 +426,15 @@ const themeInline = `@theme inline {
|
|
|
385
426
|
/* Marketing tier — display sizes for landing pages, hero blocks, editorial.
|
|
386
427
|
Tailwind only emits utilities that get used, so a non-marketing fork pays
|
|
387
428
|
nothing for these. line-height drops to 1.1 at scale to keep big type
|
|
388
|
-
readable; tracking tightens slightly to compensate for optical loosening.
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
--text-
|
|
393
|
-
--text-
|
|
429
|
+
readable; tracking tightens slightly to compensate for optical loosening.
|
|
430
|
+
Same --text-*-size override hook as the body tier above, so a fork with
|
|
431
|
+
its own display scale (corrections.md-class drift otherwise) can retarget
|
|
432
|
+
these steps too instead of hitting a cliff at text-4xl. */
|
|
433
|
+
--text-4xl: calc(var(--text-4xl-size, ${text4xl}) * var(--font-size-scale, 1));
|
|
434
|
+
--text-5xl: calc(var(--text-5xl-size, ${text5xl}) * var(--font-size-scale, 1));
|
|
435
|
+
--text-6xl: calc(var(--text-6xl-size, ${text6xl}) * var(--font-size-scale, 1));
|
|
436
|
+
--text-7xl: calc(var(--text-7xl-size, ${text7xl}) * var(--font-size-scale, 1));
|
|
437
|
+
--text-8xl: calc(var(--text-8xl-size, ${text8xl}) * var(--font-size-scale, 1));
|
|
394
438
|
--text-4xl--line-height: 1.15;
|
|
395
439
|
--text-5xl--line-height: 1.10;
|
|
396
440
|
--text-6xl--line-height: 1.05;
|
|
@@ -484,8 +528,19 @@ const baseLayer = `@layer base {
|
|
|
484
528
|
body { transition: none; }
|
|
485
529
|
}
|
|
486
530
|
/* WCAG AAA 1.4.8: paragraph spacing ≥ 1.5× line-height inside running
|
|
487
|
-
text.
|
|
488
|
-
|
|
531
|
+
text. Last-child has no trailing margin so containers don't get extra
|
|
532
|
+
padding.
|
|
533
|
+
|
|
534
|
+
"UI primitives stay tight" is NOT this rule's doing — it is the flex/grid
|
|
535
|
+
carve-out immediately below, and you cannot tell that by reading this
|
|
536
|
+
selector. Measured 2026-09-11 across all eight rail destinations: exactly
|
|
537
|
+
18 paragraphs in the whole app compute to 1.5em, all of them section
|
|
538
|
+
descriptions on the Components showcase, which is running text and is
|
|
539
|
+
what the rule is for. EmptyState, Stepper, Questionnaire, FileUpload and
|
|
540
|
+
HoverCard all compute to margin-bottom 0 because their content sits in a
|
|
541
|
+
flex column. Every one of those five had been reported as "loosened by
|
|
542
|
+
this rule" from counting <p> tags in source rather than reading the DOM.
|
|
543
|
+
If you are about to rescope or delete this rule, measure first. */
|
|
489
544
|
p:not(:last-child) {
|
|
490
545
|
margin-bottom: 1.5em;
|
|
491
546
|
}
|
|
@@ -849,6 +904,105 @@ html, body {
|
|
|
849
904
|
animation: progress-stripe var(--progress-stripe-duration, 1s) linear infinite;
|
|
850
905
|
}
|
|
851
906
|
|
|
907
|
+
/* Presence enter/exit keyframes — applied via the data-slot + data-transition
|
|
908
|
+
+ data-state selectors the Presence primitive sets (spec §4 pattern (b):
|
|
909
|
+
plain CSS in the design-system layer, no Tailwind utility generation in
|
|
910
|
+
the path). The component flips data-state to "closed" and waits on
|
|
911
|
+
element.getAnimations() before unmounting, so the -out keyframe is what
|
|
912
|
+
the user actually sees.
|
|
913
|
+
|
|
914
|
+
- fill-mode "both" is load-bearing: the -out keyframe must HOLD its final
|
|
915
|
+
frame (opacity 0) until React commits the unmount, otherwise the element
|
|
916
|
+
pops back to fully visible for one frame after animationend.
|
|
917
|
+
- Translate distances are small (0.5rem) so the motion reads as a settle,
|
|
918
|
+
not a slide; scale starts at .96 for the same reason.
|
|
919
|
+
- Reduced motion: the base layer forces animation-duration to 0.01ms; the
|
|
920
|
+
finished promise still resolves, so the unmount is effectively instant. */
|
|
921
|
+
@keyframes presence-fade-in {
|
|
922
|
+
from { opacity: 0; }
|
|
923
|
+
to { opacity: 1; }
|
|
924
|
+
}
|
|
925
|
+
@keyframes presence-fade-out {
|
|
926
|
+
from { opacity: 1; }
|
|
927
|
+
to { opacity: 0; }
|
|
928
|
+
}
|
|
929
|
+
@keyframes presence-scale-in {
|
|
930
|
+
from { opacity: 0; transform: scale(0.96); }
|
|
931
|
+
to { opacity: 1; transform: scale(1); }
|
|
932
|
+
}
|
|
933
|
+
@keyframes presence-scale-out {
|
|
934
|
+
from { opacity: 1; transform: scale(1); }
|
|
935
|
+
to { opacity: 0; transform: scale(0.96); }
|
|
936
|
+
}
|
|
937
|
+
@keyframes presence-slide-up-in {
|
|
938
|
+
from { opacity: 0; transform: translateY(0.5rem); }
|
|
939
|
+
to { opacity: 1; transform: translateY(0); }
|
|
940
|
+
}
|
|
941
|
+
@keyframes presence-slide-up-out {
|
|
942
|
+
from { opacity: 1; transform: translateY(0); }
|
|
943
|
+
to { opacity: 0; transform: translateY(0.5rem); }
|
|
944
|
+
}
|
|
945
|
+
@keyframes presence-slide-down-in {
|
|
946
|
+
from { opacity: 0; transform: translateY(-0.5rem); }
|
|
947
|
+
to { opacity: 1; transform: translateY(0); }
|
|
948
|
+
}
|
|
949
|
+
@keyframes presence-slide-down-out {
|
|
950
|
+
from { opacity: 1; transform: translateY(0); }
|
|
951
|
+
to { opacity: 0; transform: translateY(-0.5rem); }
|
|
952
|
+
}
|
|
953
|
+
@keyframes presence-slide-left-in {
|
|
954
|
+
from { opacity: 0; transform: translateX(0.5rem); }
|
|
955
|
+
to { opacity: 1; transform: translateX(0); }
|
|
956
|
+
}
|
|
957
|
+
@keyframes presence-slide-left-out {
|
|
958
|
+
from { opacity: 1; transform: translateX(0); }
|
|
959
|
+
to { opacity: 0; transform: translateX(0.5rem); }
|
|
960
|
+
}
|
|
961
|
+
@keyframes presence-slide-right-in {
|
|
962
|
+
from { opacity: 0; transform: translateX(-0.5rem); }
|
|
963
|
+
to { opacity: 1; transform: translateX(0); }
|
|
964
|
+
}
|
|
965
|
+
@keyframes presence-slide-right-out {
|
|
966
|
+
from { opacity: 1; transform: translateX(0); }
|
|
967
|
+
to { opacity: 0; transform: translateX(-0.5rem); }
|
|
968
|
+
}
|
|
969
|
+
[data-slot="presence"][data-transition="fade"][data-state="open"] {
|
|
970
|
+
animation: presence-fade-in var(--duration-base) var(--ease-out) both;
|
|
971
|
+
}
|
|
972
|
+
[data-slot="presence"][data-transition="fade"][data-state="closed"] {
|
|
973
|
+
animation: presence-fade-out var(--duration-base) var(--ease-out) both;
|
|
974
|
+
}
|
|
975
|
+
[data-slot="presence"][data-transition="scale"][data-state="open"] {
|
|
976
|
+
animation: presence-scale-in var(--duration-base) var(--ease-out) both;
|
|
977
|
+
}
|
|
978
|
+
[data-slot="presence"][data-transition="scale"][data-state="closed"] {
|
|
979
|
+
animation: presence-scale-out var(--duration-base) var(--ease-out) both;
|
|
980
|
+
}
|
|
981
|
+
[data-slot="presence"][data-transition="slide-up"][data-state="open"] {
|
|
982
|
+
animation: presence-slide-up-in var(--duration-base) var(--ease-out) both;
|
|
983
|
+
}
|
|
984
|
+
[data-slot="presence"][data-transition="slide-up"][data-state="closed"] {
|
|
985
|
+
animation: presence-slide-up-out var(--duration-base) var(--ease-out) both;
|
|
986
|
+
}
|
|
987
|
+
[data-slot="presence"][data-transition="slide-down"][data-state="open"] {
|
|
988
|
+
animation: presence-slide-down-in var(--duration-base) var(--ease-out) both;
|
|
989
|
+
}
|
|
990
|
+
[data-slot="presence"][data-transition="slide-down"][data-state="closed"] {
|
|
991
|
+
animation: presence-slide-down-out var(--duration-base) var(--ease-out) both;
|
|
992
|
+
}
|
|
993
|
+
[data-slot="presence"][data-transition="slide-left"][data-state="open"] {
|
|
994
|
+
animation: presence-slide-left-in var(--duration-base) var(--ease-out) both;
|
|
995
|
+
}
|
|
996
|
+
[data-slot="presence"][data-transition="slide-left"][data-state="closed"] {
|
|
997
|
+
animation: presence-slide-left-out var(--duration-base) var(--ease-out) both;
|
|
998
|
+
}
|
|
999
|
+
[data-slot="presence"][data-transition="slide-right"][data-state="open"] {
|
|
1000
|
+
animation: presence-slide-right-in var(--duration-base) var(--ease-out) both;
|
|
1001
|
+
}
|
|
1002
|
+
[data-slot="presence"][data-transition="slide-right"][data-state="closed"] {
|
|
1003
|
+
animation: presence-slide-right-out var(--duration-base) var(--ease-out) both;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
852
1006
|
/* Prose — long-form typographic rhythm for arbitrary HTML descendants
|
|
853
1007
|
(MDX output, CMS articles, rendered markdown). Keyed off the .prose
|
|
854
1008
|
class the Prose primitive (data-slot="prose") applies — same
|
|
@@ -1307,5 +1461,9 @@ ${borderColorUtilities}
|
|
|
1307
1461
|
}
|
|
1308
1462
|
${clientExtras}`;
|
|
1309
1463
|
|
|
1310
|
-
fs.
|
|
1311
|
-
|
|
1464
|
+
if (fs.existsSync(path.dirname(APP_CSS))) {
|
|
1465
|
+
fs.writeFileSync(APP_CSS, appCss);
|
|
1466
|
+
console.log(`✓ wrote ${path.relative(ROOT, APP_CSS)}${clientExtras ? ' (with client-extras)' : ''}`);
|
|
1467
|
+
} else {
|
|
1468
|
+
console.log('· skipped styles/globals.css (no styles/ dir — package consumer, not a fork)');
|
|
1469
|
+
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* co-located story at components/<PascalCase>.stories.tsx (matching upstream
|
|
19
19
|
* pairs like components/activity-feed.tsx + components/ActivityFeed.stories.tsx),
|
|
20
20
|
* and this also covers exactly one level of subdirectory, the depth at
|
|
21
|
-
* which a fork vendors its own components (components/
|
|
21
|
+
* which a fork vendors its own components (components/acme/*.tsx),
|
|
22
22
|
* accepting a story at either the co-located subdirectory path or the
|
|
23
23
|
* top-level components/<PascalCase>.stories.tsx path, since only the
|
|
24
24
|
* top-level location is guaranteed to actually render in Storybook today.
|
|
@@ -50,6 +50,47 @@ function resolvePackageOwned(relPath) {
|
|
|
50
50
|
return fs.existsSync(resolved) ? resolved : null;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// ---- signal counting ------------------------------------------------------
|
|
54
|
+
//
|
|
55
|
+
// Three ways the v1 counters measured something other than what their penalty
|
|
56
|
+
// says, found 2026-09-11 by reading the rows behind every component flagged
|
|
57
|
+
// on the September report:
|
|
58
|
+
//
|
|
59
|
+
// - corrections: every word occurrence counted as a "recurrence", so one
|
|
60
|
+
// long entry naming Command seven times scored as seven, and entries
|
|
61
|
+
// moved to the Archive (which corrections.md defines as no longer
|
|
62
|
+
// actively recurring) kept penalizing forever. A recurrence is an active
|
|
63
|
+
// entry, so that is what is counted.
|
|
64
|
+
// - ux rows: a finding penalized forever, even after the fix landed,
|
|
65
|
+
// because ux-tests.jsonl had no way to say "resolved". It now carries the
|
|
66
|
+
// same status field as drift.jsonl and research.jsonl.
|
|
67
|
+
// - build rows: newer rows name the component in `component` or `name`,
|
|
68
|
+
// not `candidate`, and were silently skipped.
|
|
69
|
+
|
|
70
|
+
/** Number of active (non-archived) corrections entries that name `name`. */
|
|
71
|
+
function activeCorrectionsNaming(md, name) {
|
|
72
|
+
const archiveAt = md.search(/^## Archive\b/m);
|
|
73
|
+
const active = archiveAt === -1 ? md : md.slice(0, archiveAt);
|
|
74
|
+
const bodies = active.split(/^### \d{3}\./m).slice(1);
|
|
75
|
+
const re = new RegExp(`\\b${name}\\b`);
|
|
76
|
+
return bodies.filter((b) => re.test(b)).length;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The component a component-builds.jsonl row is about, across row shapes. */
|
|
80
|
+
function buildRowComponent(row) {
|
|
81
|
+
return ((row.candidate || "").split(" ")[0] || row.component || row.name || "").trim();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Whether a ux-tests.jsonl row still counts against the component. */
|
|
85
|
+
function uxRowPenalizes(row) {
|
|
86
|
+
return row.status !== "resolved" && row.status !== "accepted";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The human-readable text of a ux-tests.jsonl row (older rows use summary). */
|
|
90
|
+
function uxRowText(row) {
|
|
91
|
+
return String(row.finding ?? row.summary ?? "");
|
|
92
|
+
}
|
|
93
|
+
|
|
53
94
|
function main() {
|
|
54
95
|
// Repo-root resolution is cwd-based (not file-relative) so this works both in
|
|
55
96
|
// upstream BADS (scripts/ -> repo root) and after shipping as a package bin
|
|
@@ -117,22 +158,23 @@ function main() {
|
|
|
117
158
|
const penalties = [];
|
|
118
159
|
let dataPoints = 0;
|
|
119
160
|
|
|
120
|
-
// signal: ux-test findings (rows match on the component field)
|
|
161
|
+
// signal: ux-test findings (rows match on the component field). A resolved
|
|
162
|
+
// or accepted row is still a data point, it just no longer penalizes.
|
|
121
163
|
for (const r of uxRows.filter((r) => r.component === name)) {
|
|
122
164
|
dataPoints++;
|
|
123
|
-
const p = UX_PENALTY[r.severity] ?? 0;
|
|
124
|
-
if (p) penalties.push({ source: "ux-test", points: p, why: `${r.severity}: ${
|
|
165
|
+
const p = uxRowPenalizes(r) ? UX_PENALTY[r.severity] ?? 0 : 0;
|
|
166
|
+
if (p) penalties.push({ source: "ux-test", points: p, why: `${r.severity}: ${uxRowText(r).slice(0, 100)}` });
|
|
125
167
|
}
|
|
126
168
|
|
|
127
|
-
// signal: corrections recurrences (
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
dataPoints +=
|
|
131
|
-
penalties.push({ source: "corrections", points: Math.min(
|
|
169
|
+
// signal: corrections recurrences (active entries naming it, capped)
|
|
170
|
+
const entries = activeCorrectionsNaming(corrections, name);
|
|
171
|
+
if (entries) {
|
|
172
|
+
dataPoints += entries;
|
|
173
|
+
penalties.push({ source: "corrections", points: Math.min(entries * 5, 15), why: `named in ${entries} active correction(s)` });
|
|
132
174
|
}
|
|
133
175
|
|
|
134
176
|
// signal: build-ledger outcome (latest row for this component)
|
|
135
|
-
const builds = buildRows.filter((r) => (r
|
|
177
|
+
const builds = buildRows.filter((r) => buildRowComponent(r) === name);
|
|
136
178
|
if (builds.length) {
|
|
137
179
|
dataPoints += builds.length;
|
|
138
180
|
const last = builds[builds.length - 1];
|
|
@@ -244,4 +286,4 @@ function isMainModule() {
|
|
|
244
286
|
|
|
245
287
|
if (isMainModule()) main();
|
|
246
288
|
|
|
247
|
-
export { resolvePackageOwned, isMainModule, main };
|
|
289
|
+
export { resolvePackageOwned, isMainModule, main, activeCorrectionsNaming, buildRowComponent, uxRowPenalizes, uxRowText };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* scan-roots — the file-discovery logic shared by every static scanner
|
|
4
|
+
* shipped as a bin (a11y-lint, size-audit, lint-slop, a11y-ratchet,
|
|
5
|
+
* lint-token-intent).
|
|
6
|
+
*
|
|
7
|
+
* Why this exists: each of those five scripts carried its own near-duplicate
|
|
8
|
+
* SCAN_ROOTS list and its own walk(), and they'd drifted — a11y-lint and
|
|
9
|
+
* size-audit disagreed on whether `src` was a root, lint-slop scanned
|
|
10
|
+
* `packages/core/src/app` and the other two didn't. One list now, imported by
|
|
11
|
+
* all five, so a root added for one scanner is a root for all of them.
|
|
12
|
+
*
|
|
13
|
+
* The bug this was written to fix (found 2026-09-09, from a standalone
|
|
14
|
+
* consumer that installed @core but kept its own tree shape): when NONE of
|
|
15
|
+
* the default scan roots exist — which is the normal case for a consumer
|
|
16
|
+
* repo, not a BADS fork — `files` resolves to `[]`, `issues` stays `[]`, and
|
|
17
|
+
* every one of the five scripts printed a "✓ clean" message and exited 0.
|
|
18
|
+
* That is not "no violations." It is "the scanner never ran," and it looked
|
|
19
|
+
* identical to success. `resolveScanFiles` below returns enough information
|
|
20
|
+
* for the caller to tell the two apart and refuse to report a false pass.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
|
|
26
|
+
const DEFAULT_SCAN_ROOTS = [
|
|
27
|
+
'app',
|
|
28
|
+
'components',
|
|
29
|
+
'src',
|
|
30
|
+
'packages/core/src/components',
|
|
31
|
+
'packages/core/src/app',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
function walk(dir, out, opts) {
|
|
35
|
+
out = out || [];
|
|
36
|
+
opts = opts || {};
|
|
37
|
+
if (!fs.existsSync(dir)) return out;
|
|
38
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
39
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules') continue;
|
|
40
|
+
const full = path.join(dir, entry.name);
|
|
41
|
+
if (entry.isDirectory()) {
|
|
42
|
+
walk(full, out, opts);
|
|
43
|
+
} else if (/\.tsx?$/.test(entry.name)) {
|
|
44
|
+
if (opts.excludeStories && /\.stories\.tsx?$/.test(entry.name)) continue;
|
|
45
|
+
out.push(full);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the file list a scanner should run against.
|
|
53
|
+
*
|
|
54
|
+
* Precedence: explicit file paths on the CLI > explicit directory args (only
|
|
55
|
+
* when `allowDirArgs` is set — size-audit and a11y-ratchet support
|
|
56
|
+
* `bads-size-audit app components`; a11y-lint and lint-slop only ever took
|
|
57
|
+
* file paths, so leave them off) > BADS_LINT_ROOTS env override > the
|
|
58
|
+
* built-in default list, each filtered by existsSync.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} opts
|
|
61
|
+
* @param {string} opts.root - process.cwd() of the invoking script
|
|
62
|
+
* @param {string[]} opts.argv - process.argv.slice(2)
|
|
63
|
+
* @param {string[]} [opts.scanRoots] - override the default root list
|
|
64
|
+
* (still subject to BADS_LINT_ROOTS taking precedence)
|
|
65
|
+
* @param {boolean} [opts.excludeStories]
|
|
66
|
+
* @param {boolean} [opts.allowDirArgs]
|
|
67
|
+
* @returns {{files: string[], mode: 'explicit'|'dir-args'|'default',
|
|
68
|
+
* rootsChecked: string[], rootsFound: string[]}}
|
|
69
|
+
*/
|
|
70
|
+
function resolveScanFiles(opts) {
|
|
71
|
+
const root = opts.root;
|
|
72
|
+
const argv = opts.argv || [];
|
|
73
|
+
const scanRoots = opts.scanRoots || DEFAULT_SCAN_ROOTS;
|
|
74
|
+
const excludeStories = !!opts.excludeStories;
|
|
75
|
+
const allowDirArgs = !!opts.allowDirArgs;
|
|
76
|
+
|
|
77
|
+
const positional = argv.filter((a) => !a.startsWith('--'));
|
|
78
|
+
|
|
79
|
+
let explicitPaths = positional;
|
|
80
|
+
let dirArgs = [];
|
|
81
|
+
if (allowDirArgs) {
|
|
82
|
+
dirArgs = positional.filter((p) => fs.existsSync(p) && fs.statSync(p).isDirectory());
|
|
83
|
+
explicitPaths = positional.filter((p) => !dirArgs.includes(p));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (explicitPaths.length) {
|
|
87
|
+
return {
|
|
88
|
+
files: explicitPaths.map((p) => path.resolve(p)),
|
|
89
|
+
mode: 'explicit',
|
|
90
|
+
rootsChecked: [],
|
|
91
|
+
rootsFound: [],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let roots = dirArgs.length ? dirArgs : scanRoots;
|
|
96
|
+
let mode = dirArgs.length ? 'dir-args' : 'default';
|
|
97
|
+
|
|
98
|
+
if (!dirArgs.length && process.env.BADS_LINT_ROOTS) {
|
|
99
|
+
roots = process.env.BADS_LINT_ROOTS.split(',').map((s) => s.trim()).filter(Boolean);
|
|
100
|
+
mode = 'env';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const rootsChecked = roots.map((r) => (path.isAbsolute(r) ? r : path.join(root, r)));
|
|
104
|
+
const rootsFound = rootsChecked.filter((r) => fs.existsSync(r));
|
|
105
|
+
const files = rootsFound.flatMap((r) => walk(r, [], { excludeStories }));
|
|
106
|
+
|
|
107
|
+
return { files, mode, rootsChecked, rootsFound };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Print the shared "did this scan actually run" diagnostic and, when the
|
|
112
|
+
* scan silently found nothing to look at, exit loudly instead of letting the
|
|
113
|
+
* caller print a "✓ clean" message over zero evidence.
|
|
114
|
+
*
|
|
115
|
+
* A scanner calls this once it has `files` and `issues.length === 0`. It is a
|
|
116
|
+
* no-op (returns false) when there's real signal that the scan ran — either
|
|
117
|
+
* files were found, or the caller passed explicit paths, or at least one
|
|
118
|
+
* default root existed on disk and simply held no matching files. It exits
|
|
119
|
+
* the process when NONE of the scan roots exist: that's the case that used to
|
|
120
|
+
* print "no violations found" while having read nothing.
|
|
121
|
+
*
|
|
122
|
+
* @param {ReturnType<typeof resolveScanFiles>} scan
|
|
123
|
+
* @param {string} binName - e.g. 'a11y-lint', for the error message
|
|
124
|
+
* @returns {boolean} true if it exited (caller code after this is dead)
|
|
125
|
+
*/
|
|
126
|
+
function guardEmptyScan(scan, binName) {
|
|
127
|
+
if (scan.files.length > 0) return false;
|
|
128
|
+
if (scan.mode === 'explicit') return false; // caller pointed at specific files; empty is on them
|
|
129
|
+
if (scan.rootsFound.length > 0) return false; // roots exist, they're just clean — real signal
|
|
130
|
+
|
|
131
|
+
console.error(
|
|
132
|
+
`${binName}: 0 files found — none of the scan roots exist in this repo, so nothing was ` +
|
|
133
|
+
`checked. This is NOT "no violations."\n\n` +
|
|
134
|
+
`Looked for:\n` +
|
|
135
|
+
scan.rootsChecked.map((r) => ` ${r}`).join('\n') +
|
|
136
|
+
`\n\nPass file or directory paths explicitly, or set BADS_LINT_ROOTS=` +
|
|
137
|
+
`"path/one,path/two" to point at your actual source tree.`
|
|
138
|
+
);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = { DEFAULT_SCAN_ROOTS, walk, resolveScanFiles, guardEmptyScan };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lint-component-source — when the client owns the components, stop new code
|
|
4
|
+
* importing BADS primitives.
|
|
5
|
+
*
|
|
6
|
+
* This is the enforcement half of the sourceOfTruth switch. The agent rules in
|
|
7
|
+
* CLAUDE.md are framing and drift; this is the ratchet.
|
|
8
|
+
*
|
|
9
|
+
* It scans `sourceOfTruth.scanRoots` (default ["app"], from
|
|
10
|
+
* source-of-truth.cjs's DEFAULTS). It deliberately does NOT default to
|
|
11
|
+
* scanning `components/`: upstream ships ~127 files there that import core
|
|
12
|
+
* UI, and a fork is a clone of upstream, so scanning it wholesale would flag
|
|
13
|
+
* the whole template library on day one and the lint would get bypassed
|
|
14
|
+
* rather than obeyed. A fork names its own authored directories.
|
|
15
|
+
*
|
|
16
|
+
* File discovery is delegated to ./lib/scan-roots.cjs — the same
|
|
17
|
+
* resolveScanFiles()/guardEmptyScan() pair a11y-lint.cjs, size-audit.cjs, and
|
|
18
|
+
* lint-slop.mjs use. That module exists precisely because a hand-rolled walk
|
|
19
|
+
* over a fixed root list silently reports "clean" when none of its roots
|
|
20
|
+
* exist on disk (0 files read, 0 findings, exit 0) — indistinguishable from a
|
|
21
|
+
* real pass. guardEmptyScan() is what turns that into a loud failure instead.
|
|
22
|
+
* scanRoots here comes from the fork's own sourceOfTruth block, not the
|
|
23
|
+
* module's built-in default list, so it's passed in explicitly.
|
|
24
|
+
*
|
|
25
|
+
* Escape hatch: `// allow-bads-component <reason>` on the line above the
|
|
26
|
+
* import.
|
|
27
|
+
*
|
|
28
|
+
* Run:
|
|
29
|
+
* node lint-component-source.mjs # exit 1 on findings
|
|
30
|
+
* node lint-component-source.mjs --warn # advisory, exit 0
|
|
31
|
+
*/
|
|
32
|
+
import { readFileSync } from "node:fs";
|
|
33
|
+
import { relative } from "node:path";
|
|
34
|
+
import { createRequire } from "node:module";
|
|
35
|
+
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
const { readSourceOfTruth } = require("./source-of-truth.cjs");
|
|
38
|
+
// scan-roots.cjs is CommonJS (shared with the .cjs bins); the default import
|
|
39
|
+
// is Node's CJS→ESM interop and always carries the full module.exports
|
|
40
|
+
// object, unlike named imports off an arbitrary CJS module. Mirrors how
|
|
41
|
+
// lint-slop.mjs consumes the same module.
|
|
42
|
+
import scanRootsLib from "./lib/scan-roots.cjs";
|
|
43
|
+
const { resolveScanFiles, guardEmptyScan } = scanRootsLib;
|
|
44
|
+
|
|
45
|
+
const ROOT = process.cwd();
|
|
46
|
+
const warn = process.argv.includes("--warn");
|
|
47
|
+
|
|
48
|
+
// The package name never changes on rename, so this specifier is literal —
|
|
49
|
+
// never a @<slug>/ placeholder.
|
|
50
|
+
const BADS_UI = /from\s+["']@behavioral-agentic-design-system\/core\/components\/ui\/[^"']*["']/;
|
|
51
|
+
const ESCAPE = /\/\/\s*allow-bads-component\s+\S/;
|
|
52
|
+
|
|
53
|
+
const sot = readSourceOfTruth(ROOT);
|
|
54
|
+
|
|
55
|
+
if (sot.components !== "client") {
|
|
56
|
+
console.log("OK lint-component-source: BADS owns components here, nothing to check.");
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// scanRoots is the fork's own sourceOfTruth.scanRoots (default ["app"]), not
|
|
61
|
+
// scan-roots.cjs's built-in DEFAULT_SCAN_ROOTS list — the switch owns this
|
|
62
|
+
// scope, the shared module only owns the walk + false-green guard.
|
|
63
|
+
const scan = resolveScanFiles({
|
|
64
|
+
root: ROOT,
|
|
65
|
+
argv: process.argv.slice(2),
|
|
66
|
+
scanRoots: sot.scanRoots,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const findings = [];
|
|
70
|
+
for (const file of scan.files) {
|
|
71
|
+
const lines = readFileSync(file, "utf8").split("\n");
|
|
72
|
+
lines.forEach((line, i) => {
|
|
73
|
+
if (!BADS_UI.test(line)) return;
|
|
74
|
+
if (i > 0 && ESCAPE.test(lines[i - 1])) return;
|
|
75
|
+
findings.push({ file: relative(ROOT, file), line: i + 1, text: line.trim() });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (findings.length === 0) {
|
|
80
|
+
// Must run before any success message prints: this is the guard against
|
|
81
|
+
// the false-green the 2026-09-14 plan revision exists to prevent. It exits
|
|
82
|
+
// the process (non-zero, listing what it looked for) when none of
|
|
83
|
+
// sot.scanRoots exist on disk, rather than letting the line below claim a
|
|
84
|
+
// clean scan over zero files read.
|
|
85
|
+
if (guardEmptyScan(scan, "lint-component-source")) {
|
|
86
|
+
/* exited */
|
|
87
|
+
}
|
|
88
|
+
console.log(`OK lint-component-source: no BADS component imports under ${sot.scanRoots.join(", ")}.`);
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const label = warn ? "WARN" : "FAIL";
|
|
93
|
+
console.error(`${label} lint-component-source: ${findings.length} BADS component import(s) in a client-owned fork.`);
|
|
94
|
+
console.error(` This fork's components come from ${sot.clientLibrary}.`);
|
|
95
|
+
for (const f of findings) {
|
|
96
|
+
console.error(` ${f.file}:${f.line}`);
|
|
97
|
+
console.error(` ${f.text}`);
|
|
98
|
+
}
|
|
99
|
+
console.error(` escape: add "// allow-bads-component <reason>" on the line above.`);
|
|
100
|
+
process.exit(warn ? 0 : 1);
|