@behavioral-agentic-design-system/core 0.37.0 → 0.39.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 -4
- package/scripts/a11y-lint.cjs +8 -2
- package/scripts/a11y-ratchet.mjs +172 -0
- package/scripts/accent-as-text.mjs +274 -0
- package/scripts/bads-doctor.mjs +2 -1
- package/scripts/check-stories.mjs +265 -52
- package/scripts/contrast.mjs +44 -0
- package/scripts/health-report.mjs +211 -122
- package/scripts/lint-slop.mjs +44 -2
- package/scripts/oklch-to-hex.cjs +7 -1
- package/scripts/ratchet.mjs +326 -0
- package/scripts/slop-rules.mjs +156 -0
- package/scripts/token-nearest.mjs +333 -0
- package/scripts/wcag-audit.cjs +59 -8
- package/src/app/preview/components/page.tsx +363 -0
- package/src/components/Foundations/Typography.stories.tsx +82 -21
- package/src/components/ui/accordion.tsx +67 -5
- package/src/components/ui/alert.tsx +20 -7
- package/src/components/ui/avatar.tsx +18 -4
- package/src/components/ui/breadcrumb.tsx +47 -0
- package/src/components/ui/checkbox-card.tsx +48 -8
- package/src/components/ui/checkbox.tsx +17 -8
- package/src/components/ui/format-date.tsx +107 -0
- package/src/components/ui/progress.tsx +6 -5
- package/src/components/ui/sparkline.tsx +198 -0
- package/src/components/ui/tag.tsx +17 -1
- package/src/components/ui/tags-input.tsx +84 -11
- package/src/components/ui/toggle-group.tsx +13 -0
- package/src/components/ui/week-picker.tsx +463 -0
- package/src/data/docs-index.ts +12 -0
- package/src/lib/theme-editor.ts +7 -1
- package/src/stories/Accordion.stories.tsx +59 -1
- package/src/stories/ActionBar.stories.tsx +1 -1
- package/src/stories/Affix.stories.tsx +1 -1
- package/src/stories/AiBadge.stories.tsx +1 -1
- package/src/stories/Alert.stories.tsx +36 -1
- package/src/stories/AlertDialog.stories.tsx +1 -1
- package/src/stories/Anchor.stories.tsx +1 -1
- package/src/stories/AngleSlider.stories.tsx +1 -1
- package/src/stories/AspectRatio.stories.tsx +1 -1
- package/src/stories/Autocomplete.stories.tsx +1 -1
- package/src/stories/Avatar.stories.tsx +41 -1
- package/src/stories/Badge.stories.tsx +1 -1
- package/src/stories/Blockquote.stories.tsx +1 -1
- package/src/stories/BottomNavigation.stories.tsx +1 -1
- package/src/stories/Breadcrumb.stories.tsx +38 -5
- package/src/stories/Burger.stories.tsx +1 -1
- package/src/stories/Button.stories.tsx +9 -1
- package/src/stories/ButtonGroup.stories.tsx +1 -1
- package/src/stories/Calendar.stories.tsx +1 -1
- package/src/stories/Card.stories.tsx +1 -1
- package/src/stories/Carousel.stories.tsx +1 -1
- package/src/stories/Cascader.stories.tsx +1 -1
- package/src/stories/Chart.stories.tsx +1 -1
- package/src/stories/ChatBubble.stories.tsx +1 -1
- package/src/stories/ChatMarker.stories.tsx +1 -1
- package/src/stories/Checkbox.stories.tsx +36 -5
- package/src/stories/CheckboxCard.stories.tsx +37 -2
- package/src/stories/CheckboxGroup.stories.tsx +1 -1
- package/src/stories/Chip.stories.tsx +1 -1
- package/src/stories/CircularProgress.stories.tsx +17 -1
- package/src/stories/Clipboard.stories.tsx +1 -1
- package/src/stories/CloseButton.stories.tsx +1 -1
- package/src/stories/Code.stories.tsx +1 -1
- package/src/stories/Collapsible.stories.tsx +1 -1
- package/src/stories/ColorPicker.stories.tsx +1 -1
- package/src/stories/ColorSwatch.stories.tsx +1 -1
- package/src/stories/Combobox.stories.tsx +1 -1
- package/src/stories/Command.stories.tsx +1 -1
- package/src/stories/Container.stories.tsx +1 -1
- package/src/stories/ContextMenu.stories.tsx +1 -1
- package/src/stories/CopyButton.stories.tsx +9 -1
- package/src/stories/DataList.stories.tsx +1 -1
- package/src/stories/DataTable.stories.tsx +1 -1
- package/src/stories/DateField.stories.tsx +1 -1
- package/src/stories/DatePicker.stories.tsx +1 -1
- package/src/stories/DateRangePicker.stories.tsx +1 -1
- package/src/stories/Dialog.stories.tsx +1 -1
- package/src/stories/Drawer.stories.tsx +1 -1
- package/src/stories/DropdownMenu.stories.tsx +1 -1
- package/src/stories/Editable.stories.tsx +1 -1
- package/src/stories/EmptyState.stories.tsx +1 -1
- package/src/stories/Field.stories.tsx +1 -1
- package/src/stories/Fieldset.stories.tsx +1 -1
- package/src/stories/FileButton.stories.tsx +1 -1
- package/src/stories/FileUpload.stories.tsx +1 -1
- package/src/stories/FloatLabel.stories.tsx +1 -1
- package/src/stories/FloatingActionButton.stories.tsx +1 -1
- package/src/stories/FloatingIndicator.stories.tsx +1 -1
- package/src/stories/FloatingPanel.stories.tsx +9 -1
- package/src/stories/FocusTrap.stories.tsx +1 -1
- package/src/stories/FormatByte.stories.tsx +1 -1
- package/src/stories/FormatDate.stories.tsx +174 -0
- package/src/stories/FormatNumber.stories.tsx +1 -1
- package/src/stories/Highlight.stories.tsx +1 -1
- package/src/stories/HoverCard.stories.tsx +1 -1
- package/src/stories/Image.stories.tsx +1 -1
- package/src/stories/Indicator.stories.tsx +17 -1
- package/src/stories/Input.stories.tsx +1 -1
- package/src/stories/InputClearButton.stories.tsx +1 -1
- package/src/stories/InputGroup.stories.tsx +1 -1
- package/src/stories/Kbd.stories.tsx +1 -1
- package/src/stories/KeyboardShortcut.stories.tsx +1 -1
- package/src/stories/Label.stories.tsx +1 -1
- package/src/stories/Link.stories.tsx +1 -1
- package/src/stories/List.stories.tsx +1 -1
- package/src/stories/Listbox.stories.tsx +1 -1
- package/src/stories/LoadingDots.stories.tsx +1 -1
- package/src/stories/LoadingOverlay.stories.tsx +1 -1
- package/src/stories/Mark.stories.tsx +1 -1
- package/src/stories/Marquee.stories.tsx +1 -1
- package/src/stories/Masonry.stories.tsx +1 -1
- package/src/stories/Menubar.stories.tsx +1 -1
- package/src/stories/Meter.stories.tsx +1 -1
- package/src/stories/MonthPicker.stories.tsx +1 -1
- package/src/stories/MotionToggle.stories.tsx +1 -1
- package/src/stories/MultiSelect.stories.tsx +1 -1
- package/src/stories/NativeSelect.stories.tsx +1 -1
- package/src/stories/NavLink.stories.tsx +1 -1
- package/src/stories/NavigationMenu.stories.tsx +1 -1
- package/src/stories/NavigationRail.stories.tsx +9 -1
- package/src/stories/Notification.stories.tsx +1 -1
- package/src/stories/NumberInput.stories.tsx +1 -1
- package/src/stories/Overlay.stories.tsx +1 -1
- package/src/stories/Pagination.stories.tsx +1 -1
- package/src/stories/PasswordInput.stories.tsx +1 -1
- package/src/stories/PinInput.stories.tsx +1 -1
- package/src/stories/Popover.stories.tsx +1 -1
- package/src/stories/Progress.stories.tsx +11 -1
- package/src/stories/Prose.stories.tsx +1 -1
- package/src/stories/QrCode.stories.tsx +1 -1
- package/src/stories/Questionnaire.stories.tsx +1 -1
- package/src/stories/RadioGroup.stories.tsx +1 -1
- package/src/stories/RatingGroup.stories.tsx +1 -1
- package/src/stories/Resizable.stories.tsx +1 -1
- package/src/stories/Result.stories.tsx +1 -1
- package/src/stories/Reveal.stories.tsx +1 -1
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/ScrollArea.stories.tsx +1 -1
- package/src/stories/SearchInput.stories.tsx +1 -1
- package/src/stories/SegmentedControl.stories.tsx +1 -1
- package/src/stories/Select.stories.tsx +1 -1
- package/src/stories/Separator.stories.tsx +1 -1
- package/src/stories/Sheet.stories.tsx +1 -1
- package/src/stories/Sidebar.stories.tsx +1 -1
- package/src/stories/SignaturePad.stories.tsx +1 -1
- package/src/stories/SimpleGrid.stories.tsx +1 -1
- package/src/stories/Skeleton.stories.tsx +1 -1
- package/src/stories/SkeletonTable.stories.tsx +1 -1
- package/src/stories/SkipLink.stories.tsx +1 -1
- package/src/stories/Slider.stories.tsx +1 -1
- package/src/stories/Sonner.stories.tsx +1 -1
- package/src/stories/Sparkline.stories.tsx +208 -0
- package/src/stories/Spinner.stories.tsx +9 -1
- package/src/stories/Spoiler.stories.tsx +1 -1
- package/src/stories/Squircle.stories.tsx +1 -1
- package/src/stories/Stack.stories.tsx +1 -1
- package/src/stories/StatusBadge.stories.tsx +1 -1
- package/src/stories/Stepper.stories.tsx +1 -1
- package/src/stories/Switch.stories.tsx +1 -1
- package/src/stories/Table.stories.tsx +1 -1
- package/src/stories/Tabs.stories.tsx +1 -1
- package/src/stories/Tag.stories.tsx +23 -1
- package/src/stories/TagsInput.stories.tsx +46 -1
- package/src/stories/Text.stories.tsx +1 -1
- package/src/stories/Textarea.stories.tsx +1 -1
- package/src/stories/ThemeIcon.stories.tsx +1 -1
- package/src/stories/TimePicker.stories.tsx +1 -1
- package/src/stories/Timeline.stories.tsx +9 -1
- package/src/stories/Timer.stories.tsx +1 -1
- package/src/stories/Toggle.stories.tsx +1 -1
- package/src/stories/ToggleGroup.stories.tsx +21 -1
- package/src/stories/ToggleTip.stories.tsx +1 -1
- package/src/stories/Toolbar.stories.tsx +1 -1
- package/src/stories/Tooltip.stories.tsx +1 -1
- package/src/stories/Tour.stories.tsx +1 -1
- package/src/stories/TransferList.stories.tsx +1 -1
- package/src/stories/TreeSelect.stories.tsx +1 -1
- package/src/stories/TreeView.stories.tsx +1 -1
- package/src/stories/TypingIndicator.stories.tsx +1 -1
- package/src/stories/VisuallyHidden.stories.tsx +1 -1
- package/src/stories/Watermark.stories.tsx +1 -1
- package/src/stories/WeekPicker.stories.tsx +90 -0
- package/src/stories/WordRotate.stories.tsx +1 -1
- package/src/stories/YearPicker.stories.tsx +1 -1
- package/src/stories/story-groups.json +199 -0
|
@@ -20,139 +20,228 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import fs from "node:fs";
|
|
22
22
|
import path from "node:path";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a package-owned path. This script ships inside the @core package
|
|
27
|
+
* itself -- packages/core/scripts/ in upstream's own checkout, and again
|
|
28
|
+
* inside node_modules/@behavioral-agentic-design-system/core/scripts/ once a
|
|
29
|
+
* fork installs it -- so package-owned content always sits at a fixed
|
|
30
|
+
* position relative to wherever THIS module's own file actually resolved
|
|
31
|
+
* to. import.meta.url follows any symlink Node used to reach this file, so
|
|
32
|
+
* this is exact regardless of pnpm's store layout, hoisting, or a package
|
|
33
|
+
* rename.
|
|
34
|
+
*
|
|
35
|
+
* This used to check the consumer's own root first and only fall back to
|
|
36
|
+
* the installed package. But a fork's packages/core/src/** is a stub by the
|
|
37
|
+
* premise of this whole branch (see BADS_SYNC.md): an empty stub directory
|
|
38
|
+
* or a placeholder page.tsx satisfies existsSync and silently masked the
|
|
39
|
+
* real, installed copy, producing full-weight penalties instead of an
|
|
40
|
+
* unavailable marker. Resolving off import.meta.url removes that fork-local
|
|
41
|
+
* guess entirely. In upstream's own checkout this lands on the exact same
|
|
42
|
+
* file the old root-relative path always did, so it is a simplification,
|
|
43
|
+
* not a special case.
|
|
44
|
+
*
|
|
45
|
+
* Returns null when the resolved path does not exist, so callers degrade
|
|
46
|
+
* rather than throw.
|
|
47
|
+
*/
|
|
48
|
+
function resolvePackageOwned(relPath) {
|
|
49
|
+
const resolved = fileURLToPath(new URL(`../${relPath}`, import.meta.url));
|
|
50
|
+
return fs.existsSync(resolved) ? resolved : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function main() {
|
|
54
|
+
// Repo-root resolution is cwd-based (not file-relative) so this works both in
|
|
55
|
+
// upstream BADS (scripts/ -> repo root) and after shipping as a package bin
|
|
56
|
+
// into a client fork, invoked as `npx bads-health-report` from the fork's own
|
|
57
|
+
// repo root.
|
|
58
|
+
const ROOT = process.cwd();
|
|
59
|
+
const argv = process.argv.slice(2);
|
|
60
|
+
const DATE = argv.find((a) => a.startsWith("--date="))?.split("=")[1] || new Date().toISOString().slice(0, 10);
|
|
61
|
+
const DRIFT = argv.includes("--drift");
|
|
62
|
+
|
|
63
|
+
const read = (p) => fs.readFileSync(path.join(ROOT, p), "utf8");
|
|
64
|
+
const readJsonl = (p) => {
|
|
65
|
+
const full = path.join(ROOT, p);
|
|
66
|
+
if (!fs.existsSync(full)) return [];
|
|
67
|
+
return read(p).split("\n").filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
|
68
|
+
};
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const registry = JSON.parse(read("layer-5-component-registry/component-registry.json"));
|
|
71
|
+
const uxRows = readJsonl("ledgers/ux-tests.jsonl");
|
|
72
|
+
const buildRows = readJsonl("ledgers/component-builds.jsonl");
|
|
73
|
+
const corrections = fs.existsSync(path.join(ROOT, "corrections.md")) ? read("corrections.md") : "";
|
|
74
|
+
|
|
75
|
+
// Package-owned inputs: resolved off this script's own location (see
|
|
76
|
+
// resolvePackageOwned), never off the consumer's ROOT, because a fork's
|
|
77
|
+
// own packages/core/src/** is a stub. Degrade with a clear log line rather
|
|
78
|
+
// than throw when the package copy is missing. Callers treat the
|
|
79
|
+
// resulting null/empty state as "signal unavailable", never as a passing
|
|
80
|
+
// (or artificially failing) score.
|
|
81
|
+
const showcasePath = resolvePackageOwned("src/app/preview/components/page.tsx");
|
|
82
|
+
let showcase = null;
|
|
83
|
+
if (showcasePath) {
|
|
84
|
+
showcase = fs.readFileSync(showcasePath, "utf8");
|
|
85
|
+
} else {
|
|
86
|
+
console.error(
|
|
87
|
+
"health-report: showcase page not found locally or in the installed package (packages/core/src/app/preview/components/page.tsx); showcase-presence signal unavailable."
|
|
88
|
+
);
|
|
71
89
|
}
|
|
72
90
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
const storiesDirPath = resolvePackageOwned("src/stories");
|
|
92
|
+
let storyFiles = null;
|
|
93
|
+
if (storiesDirPath) {
|
|
94
|
+
// case-insensitive: the QrCode/QRCode story case-collision fix means registry
|
|
95
|
+
// name casing and story filename casing can legitimately differ
|
|
96
|
+
storyFiles = new Set(fs.readdirSync(storiesDirPath).map((f) => f.toLowerCase()));
|
|
97
|
+
} else {
|
|
98
|
+
console.error(
|
|
99
|
+
"health-report: stories directory not found locally or in the installed package (packages/core/src/stories); story-presence signal unavailable."
|
|
100
|
+
);
|
|
79
101
|
}
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
else if (e.costModel.lastReviewedAt && daysBetween(DATE, e.costModel.lastReviewedAt) > 180)
|
|
87
|
-
penalties.push({ source: "registry", points: 5, why: `costModel last reviewed ${e.costModel.lastReviewedAt}` });
|
|
88
|
-
|
|
89
|
-
// structure: story + showcase presence — REQUIRED only for components whose
|
|
90
|
-
// source ships inside @core (the Storybook rule's scope). Repo-root
|
|
91
|
-
// compositions (bucket C) live in feature tabs, not the components page.
|
|
92
|
-
const inCore = fs.existsSync(path.join(ROOT, "packages/core/src/components/ui", `${kebab(name)}.tsx`));
|
|
93
|
-
if (inCore) {
|
|
94
|
-
if (!storyFiles.has(`${name.toLowerCase()}.stories.tsx`)) penalties.push({ source: "stories", points: 10, why: "no story file (STORYBOOK_RULE violation)" });
|
|
95
|
-
if (!showcase.includes(`<${name}`) && !showcase.includes(`${name}Showcase`) && !showcase.includes(`title="${name}"`))
|
|
96
|
-
penalties.push({ source: "showcase", points: 5, why: "not demonstrated in the components showcase" });
|
|
103
|
+
const uiDirPath = resolvePackageOwned("src/components/ui");
|
|
104
|
+
if (!uiDirPath) {
|
|
105
|
+
console.error(
|
|
106
|
+
"health-report: components/ui directory not found locally or in the installed package (packages/core/src/components/ui); story/showcase presence signals unavailable for every component."
|
|
107
|
+
);
|
|
97
108
|
}
|
|
98
109
|
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
const kebab = (s) => s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
111
|
+
const daysBetween = (a, b) => Math.round((new Date(a) - new Date(b)) / 86400000);
|
|
112
|
+
|
|
113
|
+
const UX_PENALTY = { BLOCKER: 25, HIGH: 15, MEDIUM: 8, LOW: 3, none: 0 };
|
|
114
|
+
|
|
115
|
+
const components = Object.keys(registry).sort().map((name) => {
|
|
116
|
+
const e = registry[name];
|
|
117
|
+
const penalties = [];
|
|
118
|
+
let dataPoints = 0;
|
|
119
|
+
|
|
120
|
+
// signal: ux-test findings (rows match on the component field)
|
|
121
|
+
for (const r of uxRows.filter((r) => r.component === name)) {
|
|
122
|
+
dataPoints++;
|
|
123
|
+
const p = UX_PENALTY[r.severity] ?? 0;
|
|
124
|
+
if (p) penalties.push({ source: "ux-test", points: p, why: `${r.severity}: ${String(r.finding || "").slice(0, 100)}` });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// signal: corrections recurrences (word-boundary name mentions, capped)
|
|
128
|
+
const mentions = (corrections.match(new RegExp(`\\b${name}\\b`, "g")) || []).length;
|
|
129
|
+
if (mentions) {
|
|
130
|
+
dataPoints += mentions;
|
|
131
|
+
penalties.push({ source: "corrections", points: Math.min(mentions * 5, 15), why: `${mentions} mention(s) in corrections.md` });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// signal: build-ledger outcome (latest row for this component)
|
|
135
|
+
const builds = buildRows.filter((r) => (r.candidate || "").split(" ")[0] === name);
|
|
136
|
+
if (builds.length) {
|
|
137
|
+
dataPoints += builds.length;
|
|
138
|
+
const last = builds[builds.length - 1];
|
|
139
|
+
if (last.status === "rejected") penalties.push({ source: "build-ledger", points: 10, why: "last build attempt rejected by gates" });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// structure: registry completeness (these are hygiene, not incidents)
|
|
143
|
+
if (!e.a11yContract) penalties.push({ source: "registry", points: 10, why: "no a11yContract" });
|
|
144
|
+
if (!e.antiPatterns?.length) penalties.push({ source: "registry", points: 5, why: "no antiPatterns" });
|
|
145
|
+
if (!e.examples?.length) penalties.push({ source: "registry", points: 5, why: "no examples" });
|
|
146
|
+
if (!e.costModel) penalties.push({ source: "registry", points: 5, why: "no costModel" });
|
|
147
|
+
else if (e.costModel.lastReviewedAt && daysBetween(DATE, e.costModel.lastReviewedAt) > 180)
|
|
148
|
+
penalties.push({ source: "registry", points: 5, why: `costModel last reviewed ${e.costModel.lastReviewedAt}` });
|
|
149
|
+
|
|
150
|
+
// structure: story + showcase presence: REQUIRED only for components whose
|
|
151
|
+
// source ships inside @core (the Storybook rule's scope). Repo-root
|
|
152
|
+
// compositions (bucket C) live in feature tabs, not the components page.
|
|
153
|
+
const inCore = uiDirPath !== null && fs.existsSync(path.join(uiDirPath, `${kebab(name)}.tsx`));
|
|
154
|
+
if (inCore) {
|
|
155
|
+
if (storyFiles === null) {
|
|
156
|
+
penalties.push({ source: "stories", points: 0, why: "story-presence signal unavailable (stories directory not found locally or in the package)" });
|
|
157
|
+
} else if (!storyFiles.has(`${name.toLowerCase()}.stories.tsx`)) {
|
|
158
|
+
penalties.push({ source: "stories", points: 10, why: "no story file (STORYBOOK_RULE violation)" });
|
|
159
|
+
}
|
|
160
|
+
if (showcase === null) {
|
|
161
|
+
penalties.push({ source: "showcase", points: 0, why: "showcase-presence signal unavailable (showcase page not found locally or in the package)" });
|
|
162
|
+
} else if (!showcase.includes(`<${name}`) && !showcase.includes(`${name}Showcase`) && !showcase.includes(`title="${name}"`)) {
|
|
163
|
+
penalties.push({ source: "showcase", points: 5, why: "not demonstrated in the components showcase" });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const score = Math.max(0, 100 - penalties.reduce((s, p) => s + p.points, 0));
|
|
168
|
+
return {
|
|
169
|
+
name,
|
|
170
|
+
score,
|
|
171
|
+
band: score >= 90 ? "healthy" : score >= 70 ? "watch" : "attention",
|
|
172
|
+
insufficientData: dataPoints === 0,
|
|
173
|
+
dataPoints,
|
|
174
|
+
penalties: penalties.sort((a, b) => b.points - a.points),
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const known = components.filter((c) => !c.insufficientData);
|
|
179
|
+
const summary = {
|
|
180
|
+
components: components.length,
|
|
181
|
+
scored: known.length,
|
|
182
|
+
insufficientData: components.length - known.length,
|
|
183
|
+
avgScore: known.length ? Math.round(known.reduce((s, c) => s + c.score, 0) / known.length) : null,
|
|
184
|
+
bands: {
|
|
185
|
+
healthy: components.filter((c) => c.band === "healthy").length,
|
|
186
|
+
watch: components.filter((c) => c.band === "watch").length,
|
|
187
|
+
attention: components.filter((c) => c.band === "attention").length,
|
|
188
|
+
},
|
|
107
189
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (prior) {
|
|
134
|
-
const prev = JSON.parse(read(path.join("ledgers", "reports", prior)));
|
|
135
|
-
const prevScores = Object.fromEntries(prev.components.map((c) => [c.name, c.score]));
|
|
136
|
-
const drops = components.filter((c) => prevScores[c.name] != null && prevScores[c.name] - c.score > 10);
|
|
137
|
-
if (drops.length) {
|
|
138
|
-
const rows = drops.map((c) => JSON.stringify({
|
|
139
|
-
schemaVersion: "1", date: DATE, source: "health", rule: "score-drop",
|
|
140
|
-
target: c.name, severity: c.band === "attention" ? "high" : "medium",
|
|
141
|
-
signal: `health ${prevScores[c.name]} → ${c.score} since ${prior.slice(7, 14)}`,
|
|
142
|
-
evidence: c.penalties[0]?.why || "", status: "open",
|
|
143
|
-
}));
|
|
144
|
-
fs.appendFileSync(path.join(ROOT, "ledgers", "drift.jsonl"), rows.join("\n") + "\n");
|
|
145
|
-
console.log(`drift: logged ${rows.length} score drop(s) to ledgers/drift.jsonl`);
|
|
190
|
+
|
|
191
|
+
const month = DATE.slice(0, 7);
|
|
192
|
+
const outPath = path.join(ROOT, "ledgers", "reports", `health-${month}.json`);
|
|
193
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
194
|
+
|
|
195
|
+
// --drift: compare against the most recent PRIOR report before overwriting
|
|
196
|
+
if (DRIFT) {
|
|
197
|
+
const prior = fs.readdirSync(path.dirname(outPath))
|
|
198
|
+
.filter((f) => /^health-\d{4}-\d{2}\.json$/.test(f) && f < `health-${month}.json`)
|
|
199
|
+
.sort()
|
|
200
|
+
.pop();
|
|
201
|
+
if (prior) {
|
|
202
|
+
const prev = JSON.parse(read(path.join("ledgers", "reports", prior)));
|
|
203
|
+
const prevScores = Object.fromEntries(prev.components.map((c) => [c.name, c.score]));
|
|
204
|
+
const drops = components.filter((c) => prevScores[c.name] != null && prevScores[c.name] - c.score > 10);
|
|
205
|
+
if (drops.length) {
|
|
206
|
+
const rows = drops.map((c) => JSON.stringify({
|
|
207
|
+
schemaVersion: "1", date: DATE, source: "health", rule: "score-drop",
|
|
208
|
+
target: c.name, severity: c.band === "attention" ? "high" : "medium",
|
|
209
|
+
signal: `health ${prevScores[c.name]} → ${c.score} since ${prior.slice(7, 14)}`,
|
|
210
|
+
evidence: c.penalties[0]?.why || "", status: "open",
|
|
211
|
+
}));
|
|
212
|
+
fs.appendFileSync(path.join(ROOT, "ledgers", "drift.jsonl"), rows.join("\n") + "\n");
|
|
213
|
+
console.log(`drift: logged ${rows.length} score drop(s) to ledgers/drift.jsonl`);
|
|
214
|
+
}
|
|
146
215
|
}
|
|
147
216
|
}
|
|
148
|
-
}
|
|
149
217
|
|
|
150
|
-
fs.writeFileSync(outPath, JSON.stringify({ schemaVersion: "1", generatedFor: DATE, summary, components }, null, 2) + "\n");
|
|
218
|
+
fs.writeFileSync(outPath, JSON.stringify({ schemaVersion: "1", generatedFor: DATE, summary, components }, null, 2) + "\n");
|
|
151
219
|
|
|
152
|
-
console.log(`✓ health-report: ${summary.scored} scored, ${summary.insufficientData} insufficient-data, avg ${summary.avgScore} → ledgers/reports/health-${month}.json`);
|
|
153
|
-
const worst = known.filter((c) => c.band !== "healthy").slice(0, 8);
|
|
154
|
-
if (worst.length) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
220
|
+
console.log(`✓ health-report: ${summary.scored} scored, ${summary.insufficientData} insufficient-data, avg ${summary.avgScore} → ledgers/reports/health-${month}.json`);
|
|
221
|
+
const worst = known.filter((c) => c.band !== "healthy").slice(0, 8);
|
|
222
|
+
if (worst.length) {
|
|
223
|
+
console.log("\nLowest bands:");
|
|
224
|
+
for (const c of worst.sort((a, b) => a.score - b.score).slice(0, 8))
|
|
225
|
+
console.log(` ${String(c.score).padStart(3)} ${c.band.padEnd(9)} ${c.name}: ${c.penalties[0]?.why || ""}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Node resolves import.meta.url through any symlink in the module's own
|
|
230
|
+
// path, but process.argv[1] is left exactly as invoked. The shipped bin
|
|
231
|
+
// (bads-health-report, run as `npx bads-health-report` in a fork) is a
|
|
232
|
+
// symlink into node_modules/.bin, so a naive
|
|
233
|
+
// `import.meta.url === file://${process.argv[1]}` check never matches
|
|
234
|
+
// there and main() silently never runs. Resolve both sides to the same
|
|
235
|
+
// real, absolute path before comparing.
|
|
236
|
+
function isMainModule() {
|
|
237
|
+
if (!process.argv[1]) return false;
|
|
238
|
+
try {
|
|
239
|
+
return import.meta.url === `file://${fs.realpathSync(process.argv[1])}`;
|
|
240
|
+
} catch {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
158
243
|
}
|
|
244
|
+
|
|
245
|
+
if (isMainModule()) main();
|
|
246
|
+
|
|
247
|
+
export { resolvePackageOwned, isMainModule, main };
|
package/scripts/lint-slop.mjs
CHANGED
|
@@ -33,6 +33,20 @@
|
|
|
33
33
|
* BADS-SLOP-5 emoji-in-ui decorative emoji (🚀✨⚡🎉🔥💡🎯🌟🚨💪) in rendered UI copy
|
|
34
34
|
* BADS-SLOP-6 fake-stat-cliche invented-metric marketing tokens hardcoded as copy
|
|
35
35
|
* (99.9%/99.99% uptime, 10k+/1M+ vanity counts, ★★★★★)
|
|
36
|
+
* BADS-SLOP-7 system-font-primary system-ui / -apple-system as the FIRST face
|
|
37
|
+
* BADS-SLOP-8 accent-left-border border-left: Npx solid <accent> as card semantics
|
|
38
|
+
* BADS-SLOP-9 icon-in-colored-circle icon centered in a saturated disc, size-8 and up
|
|
39
|
+
* BADS-SLOP-10 decorative-blob absolute + rounded-full + blur-2xl/3xl
|
|
40
|
+
* BADS-SLOP-11 three-up-feature-grid grid-cols-3 + text-center on one element
|
|
41
|
+
* BADS-SLOP-12 wave-divider full-bleed wavy SVG section divider
|
|
42
|
+
*
|
|
43
|
+
* File-scope detectors (the signal IS the repetition, so one line cannot show it):
|
|
44
|
+
* BADS-SLOP-13 center-everything text-center on 6+ blocks in one file
|
|
45
|
+
* BADS-SLOP-14 uniform-bubbly-radius rounded-2xl/3xl on 5+ blocks, no smaller step used
|
|
46
|
+
*
|
|
47
|
+
* Rules 7 to 14 came from ClosedLoop's design pack (2026-09-03, used with
|
|
48
|
+
* permission); see docs/roadmap-closedloop-import.md item 5 for the three
|
|
49
|
+
* blacklist entries deliberately left unported.
|
|
36
50
|
*
|
|
37
51
|
* Rule 6 is adapted from Nutlope's Hallmark slop-test gate 46 (invented
|
|
38
52
|
* metrics), matched to BADS's own "fake stat trio" anti-default. Real metrics
|
|
@@ -64,7 +78,7 @@ import path from "node:path";
|
|
|
64
78
|
// into a client fork, invoked as `npx bads-lint-slop` from the fork's own
|
|
65
79
|
// repo root.
|
|
66
80
|
const ROOT = process.cwd();
|
|
67
|
-
import { RULES } from "./slop-rules.mjs";
|
|
81
|
+
import { RULES, FILE_RULES } from "./slop-rules.mjs";
|
|
68
82
|
|
|
69
83
|
const advisory = process.argv.includes("--warn");
|
|
70
84
|
const explicitPaths = process.argv.slice(2).filter((a) => !a.startsWith("--"));
|
|
@@ -117,7 +131,7 @@ for (const file of fileList()) {
|
|
|
117
131
|
for (const rule of RULES) {
|
|
118
132
|
if (!rule.test(line, { isComment })) continue;
|
|
119
133
|
// escape hatch on the line above: // allow-slop:CODE <reason>
|
|
120
|
-
const esc = prev.match(/\/\/\s*allow-slop:(BADS-SLOP-\d)\b(.*)$/);
|
|
134
|
+
const esc = prev.match(/\/\/\s*allow-slop:(BADS-SLOP-\d+)\b(.*)$/);
|
|
121
135
|
if (esc && esc[1] === rule.code) {
|
|
122
136
|
if (!esc[2].trim()) {
|
|
123
137
|
findings.push({
|
|
@@ -139,6 +153,34 @@ for (const file of fileList()) {
|
|
|
139
153
|
});
|
|
140
154
|
}
|
|
141
155
|
}
|
|
156
|
+
|
|
157
|
+
// File-scope pass. The escape hatch for these is file-wide (the finding has
|
|
158
|
+
// no single owning line to sit above), so it may appear on any line.
|
|
159
|
+
for (const rule of FILE_RULES) {
|
|
160
|
+
const hit = rule.test(src, { lines });
|
|
161
|
+
if (!hit) continue;
|
|
162
|
+
const esc = src.match(
|
|
163
|
+
new RegExp(`//\\s*allow-slop:${rule.code}\\b(.*)`),
|
|
164
|
+
);
|
|
165
|
+
if (esc) {
|
|
166
|
+
if (esc[1].trim()) continue; // escaped with a reason — allowed
|
|
167
|
+
findings.push({
|
|
168
|
+
file: path.relative(ROOT, file),
|
|
169
|
+
line: hit.line,
|
|
170
|
+
code: rule.code,
|
|
171
|
+
name: rule.name,
|
|
172
|
+
why: "allow-slop escape hatch requires a one-sentence reason.",
|
|
173
|
+
});
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
findings.push({
|
|
177
|
+
file: path.relative(ROOT, file),
|
|
178
|
+
line: hit.line,
|
|
179
|
+
code: rule.code,
|
|
180
|
+
name: rule.name,
|
|
181
|
+
why: `${rule.why} (${hit.detail})`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
142
184
|
}
|
|
143
185
|
|
|
144
186
|
if (findings.length === 0) {
|
package/scripts/oklch-to-hex.cjs
CHANGED
|
@@ -153,4 +153,10 @@ function main() {
|
|
|
153
153
|
console.log(hex);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
// Exported so token-nearest.mjs resolves oklch the same way this CLI does.
|
|
157
|
+
// One copy of the colour math, or the two would drift and the drift would be
|
|
158
|
+
// invisible: a token would resolve to one hex in the audit and another in the
|
|
159
|
+
// nearest-token report, and nothing would say which was right.
|
|
160
|
+
module.exports = { colorToHex, oklchToHex, hslToHex, rgbToHex, srgbToHex };
|
|
161
|
+
|
|
162
|
+
if (require.main === module) main();
|