@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.
Files changed (186) hide show
  1. package/package.json +8 -4
  2. package/scripts/a11y-lint.cjs +8 -2
  3. package/scripts/a11y-ratchet.mjs +172 -0
  4. package/scripts/accent-as-text.mjs +274 -0
  5. package/scripts/bads-doctor.mjs +2 -1
  6. package/scripts/check-stories.mjs +265 -52
  7. package/scripts/contrast.mjs +44 -0
  8. package/scripts/health-report.mjs +211 -122
  9. package/scripts/lint-slop.mjs +44 -2
  10. package/scripts/oklch-to-hex.cjs +7 -1
  11. package/scripts/ratchet.mjs +326 -0
  12. package/scripts/slop-rules.mjs +156 -0
  13. package/scripts/token-nearest.mjs +333 -0
  14. package/scripts/wcag-audit.cjs +59 -8
  15. package/src/app/preview/components/page.tsx +363 -0
  16. package/src/components/Foundations/Typography.stories.tsx +82 -21
  17. package/src/components/ui/accordion.tsx +67 -5
  18. package/src/components/ui/alert.tsx +20 -7
  19. package/src/components/ui/avatar.tsx +18 -4
  20. package/src/components/ui/breadcrumb.tsx +47 -0
  21. package/src/components/ui/checkbox-card.tsx +48 -8
  22. package/src/components/ui/checkbox.tsx +17 -8
  23. package/src/components/ui/format-date.tsx +107 -0
  24. package/src/components/ui/progress.tsx +6 -5
  25. package/src/components/ui/sparkline.tsx +198 -0
  26. package/src/components/ui/tag.tsx +17 -1
  27. package/src/components/ui/tags-input.tsx +84 -11
  28. package/src/components/ui/toggle-group.tsx +13 -0
  29. package/src/components/ui/week-picker.tsx +463 -0
  30. package/src/data/docs-index.ts +12 -0
  31. package/src/lib/theme-editor.ts +7 -1
  32. package/src/stories/Accordion.stories.tsx +59 -1
  33. package/src/stories/ActionBar.stories.tsx +1 -1
  34. package/src/stories/Affix.stories.tsx +1 -1
  35. package/src/stories/AiBadge.stories.tsx +1 -1
  36. package/src/stories/Alert.stories.tsx +36 -1
  37. package/src/stories/AlertDialog.stories.tsx +1 -1
  38. package/src/stories/Anchor.stories.tsx +1 -1
  39. package/src/stories/AngleSlider.stories.tsx +1 -1
  40. package/src/stories/AspectRatio.stories.tsx +1 -1
  41. package/src/stories/Autocomplete.stories.tsx +1 -1
  42. package/src/stories/Avatar.stories.tsx +41 -1
  43. package/src/stories/Badge.stories.tsx +1 -1
  44. package/src/stories/Blockquote.stories.tsx +1 -1
  45. package/src/stories/BottomNavigation.stories.tsx +1 -1
  46. package/src/stories/Breadcrumb.stories.tsx +38 -5
  47. package/src/stories/Burger.stories.tsx +1 -1
  48. package/src/stories/Button.stories.tsx +9 -1
  49. package/src/stories/ButtonGroup.stories.tsx +1 -1
  50. package/src/stories/Calendar.stories.tsx +1 -1
  51. package/src/stories/Card.stories.tsx +1 -1
  52. package/src/stories/Carousel.stories.tsx +1 -1
  53. package/src/stories/Cascader.stories.tsx +1 -1
  54. package/src/stories/Chart.stories.tsx +1 -1
  55. package/src/stories/ChatBubble.stories.tsx +1 -1
  56. package/src/stories/ChatMarker.stories.tsx +1 -1
  57. package/src/stories/Checkbox.stories.tsx +36 -5
  58. package/src/stories/CheckboxCard.stories.tsx +37 -2
  59. package/src/stories/CheckboxGroup.stories.tsx +1 -1
  60. package/src/stories/Chip.stories.tsx +1 -1
  61. package/src/stories/CircularProgress.stories.tsx +17 -1
  62. package/src/stories/Clipboard.stories.tsx +1 -1
  63. package/src/stories/CloseButton.stories.tsx +1 -1
  64. package/src/stories/Code.stories.tsx +1 -1
  65. package/src/stories/Collapsible.stories.tsx +1 -1
  66. package/src/stories/ColorPicker.stories.tsx +1 -1
  67. package/src/stories/ColorSwatch.stories.tsx +1 -1
  68. package/src/stories/Combobox.stories.tsx +1 -1
  69. package/src/stories/Command.stories.tsx +1 -1
  70. package/src/stories/Container.stories.tsx +1 -1
  71. package/src/stories/ContextMenu.stories.tsx +1 -1
  72. package/src/stories/CopyButton.stories.tsx +9 -1
  73. package/src/stories/DataList.stories.tsx +1 -1
  74. package/src/stories/DataTable.stories.tsx +1 -1
  75. package/src/stories/DateField.stories.tsx +1 -1
  76. package/src/stories/DatePicker.stories.tsx +1 -1
  77. package/src/stories/DateRangePicker.stories.tsx +1 -1
  78. package/src/stories/Dialog.stories.tsx +1 -1
  79. package/src/stories/Drawer.stories.tsx +1 -1
  80. package/src/stories/DropdownMenu.stories.tsx +1 -1
  81. package/src/stories/Editable.stories.tsx +1 -1
  82. package/src/stories/EmptyState.stories.tsx +1 -1
  83. package/src/stories/Field.stories.tsx +1 -1
  84. package/src/stories/Fieldset.stories.tsx +1 -1
  85. package/src/stories/FileButton.stories.tsx +1 -1
  86. package/src/stories/FileUpload.stories.tsx +1 -1
  87. package/src/stories/FloatLabel.stories.tsx +1 -1
  88. package/src/stories/FloatingActionButton.stories.tsx +1 -1
  89. package/src/stories/FloatingIndicator.stories.tsx +1 -1
  90. package/src/stories/FloatingPanel.stories.tsx +9 -1
  91. package/src/stories/FocusTrap.stories.tsx +1 -1
  92. package/src/stories/FormatByte.stories.tsx +1 -1
  93. package/src/stories/FormatDate.stories.tsx +174 -0
  94. package/src/stories/FormatNumber.stories.tsx +1 -1
  95. package/src/stories/Highlight.stories.tsx +1 -1
  96. package/src/stories/HoverCard.stories.tsx +1 -1
  97. package/src/stories/Image.stories.tsx +1 -1
  98. package/src/stories/Indicator.stories.tsx +17 -1
  99. package/src/stories/Input.stories.tsx +1 -1
  100. package/src/stories/InputClearButton.stories.tsx +1 -1
  101. package/src/stories/InputGroup.stories.tsx +1 -1
  102. package/src/stories/Kbd.stories.tsx +1 -1
  103. package/src/stories/KeyboardShortcut.stories.tsx +1 -1
  104. package/src/stories/Label.stories.tsx +1 -1
  105. package/src/stories/Link.stories.tsx +1 -1
  106. package/src/stories/List.stories.tsx +1 -1
  107. package/src/stories/Listbox.stories.tsx +1 -1
  108. package/src/stories/LoadingDots.stories.tsx +1 -1
  109. package/src/stories/LoadingOverlay.stories.tsx +1 -1
  110. package/src/stories/Mark.stories.tsx +1 -1
  111. package/src/stories/Marquee.stories.tsx +1 -1
  112. package/src/stories/Masonry.stories.tsx +1 -1
  113. package/src/stories/Menubar.stories.tsx +1 -1
  114. package/src/stories/Meter.stories.tsx +1 -1
  115. package/src/stories/MonthPicker.stories.tsx +1 -1
  116. package/src/stories/MotionToggle.stories.tsx +1 -1
  117. package/src/stories/MultiSelect.stories.tsx +1 -1
  118. package/src/stories/NativeSelect.stories.tsx +1 -1
  119. package/src/stories/NavLink.stories.tsx +1 -1
  120. package/src/stories/NavigationMenu.stories.tsx +1 -1
  121. package/src/stories/NavigationRail.stories.tsx +9 -1
  122. package/src/stories/Notification.stories.tsx +1 -1
  123. package/src/stories/NumberInput.stories.tsx +1 -1
  124. package/src/stories/Overlay.stories.tsx +1 -1
  125. package/src/stories/Pagination.stories.tsx +1 -1
  126. package/src/stories/PasswordInput.stories.tsx +1 -1
  127. package/src/stories/PinInput.stories.tsx +1 -1
  128. package/src/stories/Popover.stories.tsx +1 -1
  129. package/src/stories/Progress.stories.tsx +11 -1
  130. package/src/stories/Prose.stories.tsx +1 -1
  131. package/src/stories/QrCode.stories.tsx +1 -1
  132. package/src/stories/Questionnaire.stories.tsx +1 -1
  133. package/src/stories/RadioGroup.stories.tsx +1 -1
  134. package/src/stories/RatingGroup.stories.tsx +1 -1
  135. package/src/stories/Resizable.stories.tsx +1 -1
  136. package/src/stories/Result.stories.tsx +1 -1
  137. package/src/stories/Reveal.stories.tsx +1 -1
  138. package/src/stories/RollingNumber.stories.tsx +1 -1
  139. package/src/stories/ScrollArea.stories.tsx +1 -1
  140. package/src/stories/SearchInput.stories.tsx +1 -1
  141. package/src/stories/SegmentedControl.stories.tsx +1 -1
  142. package/src/stories/Select.stories.tsx +1 -1
  143. package/src/stories/Separator.stories.tsx +1 -1
  144. package/src/stories/Sheet.stories.tsx +1 -1
  145. package/src/stories/Sidebar.stories.tsx +1 -1
  146. package/src/stories/SignaturePad.stories.tsx +1 -1
  147. package/src/stories/SimpleGrid.stories.tsx +1 -1
  148. package/src/stories/Skeleton.stories.tsx +1 -1
  149. package/src/stories/SkeletonTable.stories.tsx +1 -1
  150. package/src/stories/SkipLink.stories.tsx +1 -1
  151. package/src/stories/Slider.stories.tsx +1 -1
  152. package/src/stories/Sonner.stories.tsx +1 -1
  153. package/src/stories/Sparkline.stories.tsx +208 -0
  154. package/src/stories/Spinner.stories.tsx +9 -1
  155. package/src/stories/Spoiler.stories.tsx +1 -1
  156. package/src/stories/Squircle.stories.tsx +1 -1
  157. package/src/stories/Stack.stories.tsx +1 -1
  158. package/src/stories/StatusBadge.stories.tsx +1 -1
  159. package/src/stories/Stepper.stories.tsx +1 -1
  160. package/src/stories/Switch.stories.tsx +1 -1
  161. package/src/stories/Table.stories.tsx +1 -1
  162. package/src/stories/Tabs.stories.tsx +1 -1
  163. package/src/stories/Tag.stories.tsx +23 -1
  164. package/src/stories/TagsInput.stories.tsx +46 -1
  165. package/src/stories/Text.stories.tsx +1 -1
  166. package/src/stories/Textarea.stories.tsx +1 -1
  167. package/src/stories/ThemeIcon.stories.tsx +1 -1
  168. package/src/stories/TimePicker.stories.tsx +1 -1
  169. package/src/stories/Timeline.stories.tsx +9 -1
  170. package/src/stories/Timer.stories.tsx +1 -1
  171. package/src/stories/Toggle.stories.tsx +1 -1
  172. package/src/stories/ToggleGroup.stories.tsx +21 -1
  173. package/src/stories/ToggleTip.stories.tsx +1 -1
  174. package/src/stories/Toolbar.stories.tsx +1 -1
  175. package/src/stories/Tooltip.stories.tsx +1 -1
  176. package/src/stories/Tour.stories.tsx +1 -1
  177. package/src/stories/TransferList.stories.tsx +1 -1
  178. package/src/stories/TreeSelect.stories.tsx +1 -1
  179. package/src/stories/TreeView.stories.tsx +1 -1
  180. package/src/stories/TypingIndicator.stories.tsx +1 -1
  181. package/src/stories/VisuallyHidden.stories.tsx +1 -1
  182. package/src/stories/Watermark.stories.tsx +1 -1
  183. package/src/stories/WeekPicker.stories.tsx +90 -0
  184. package/src/stories/WordRotate.stories.tsx +1 -1
  185. package/src/stories/YearPicker.stories.tsx +1 -1
  186. package/src/stories/story-groups.json +199 -0
@@ -0,0 +1,326 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ratchet — the third mode every BADS check was missing.
4
+ *
5
+ * Until now a check was warn (prints, never fails, gets ignored) or strict
6
+ * (fails). On a fresh project strict is right. On an existing codebase with
7
+ * hundreds of violations, strict is unadoptable and warn is theatre, so the
8
+ * rule never lands at all. That is not a hypothetical: a client fork mirroring
9
+ * a dense product runs 10 and 11px text across most of its surfaces against a
10
+ * 14px AAA floor, and the whole adoption question stalled on a yes/no that only
11
+ * had one honest answer.
12
+ *
13
+ * A ratchet gives the third answer. Today's violations are recorded in a
14
+ * baseline. Listed files may stay in violation, and two rules hold:
15
+ *
16
+ * 1. A listed file may not get WORSE.
17
+ * 2. No file may JOIN the list.
18
+ *
19
+ * So the old mess is frozen and new work has to be clean. As people fix things
20
+ * the list shrinks, and it can only shrink. The adoption question changes from
21
+ * "do we fix 300 screens" to "may new screens be legal", which answers itself.
22
+ *
23
+ * The pattern, and every anti-dodge below, is from ClosedLoop's
24
+ * `check-grandfather-line-growth.ts` (audited 2026-09-03, used with
25
+ * permission; see docs/roadmap-closedloop-import.md item 3). A naive ratchet is
26
+ * trivially defeated by adding your file to the baseline, so:
27
+ *
28
+ * - The baseline is diffed against the same file at the BASE GIT REF. An
29
+ * entry that was not there at base is rejected. You cannot exempt your way
30
+ * past the gate.
31
+ * - Renames are resolved. Moving a file that WAS listed keeps it listed
32
+ * (reorganising must stay possible). Renaming an unlisted file INTO the
33
+ * list is the same dodge wearing a hat, and is rejected.
34
+ * - A stale entry (a listed path whose file was deleted) cannot be reused for
35
+ * a different file. Path membership alone does not prove the same file was
36
+ * grandfathered.
37
+ * - When the base baseline cannot be read at all, membership is UNKNOWN.
38
+ * Nothing is rejected and the run SAYS so, because a quiet pass would read
39
+ * as "no entry was added" when the gate never looked.
40
+ * - Every run reports its own coverage, pass or fail. A listed entry the gate
41
+ * could not measure is named, never silently skipped. A gate that measures
42
+ * nothing and exits 0 is worse than no gate, because now you think you are
43
+ * covered.
44
+ *
45
+ * This module is the pure half: no git, no filesystem, no process exit, so the
46
+ * whole decision table is testable. `readBaseAt`, `detectRenames` and
47
+ * `renderReport` are the thin impure helpers around it.
48
+ *
49
+ * A consumer (see scripts/type-floor-ratchet.mjs) measures violations per file
50
+ * and hands in a `{ path: count }` map.
51
+ */
52
+
53
+ import fs from "node:fs";
54
+ import path from "node:path";
55
+ import { execFileSync } from "node:child_process";
56
+
57
+ export const BASELINE_FILE = ".bads-ratchet.json";
58
+ export const SCHEMA_VERSION = 1;
59
+
60
+ // ---------------------------------------------------------------------------
61
+ // Baseline I/O
62
+ // ---------------------------------------------------------------------------
63
+
64
+ export function emptyBaseline() {
65
+ return { version: SCHEMA_VERSION, rules: {} };
66
+ }
67
+
68
+ export function readBaseline(root = process.cwd(), file = BASELINE_FILE) {
69
+ const full = path.join(root, file);
70
+ if (!fs.existsSync(full)) return emptyBaseline();
71
+ return JSON.parse(fs.readFileSync(full, "utf8"));
72
+ }
73
+
74
+ export function writeBaseline(baseline, root = process.cwd(), file = BASELINE_FILE) {
75
+ fs.writeFileSync(path.join(root, file), `${JSON.stringify(baseline, null, 2)}\n`);
76
+ }
77
+
78
+ export function ruleEntry(baseline, ruleId) {
79
+ return baseline?.rules?.[ruleId] ?? null;
80
+ }
81
+
82
+ /**
83
+ * The baseline as it existed at `ref`, or null when it cannot be read.
84
+ *
85
+ * Null is meaningfully different from an empty baseline: empty means "nothing
86
+ * was listed at base", null means "we could not look". Only the second one
87
+ * suppresses the membership rules.
88
+ */
89
+ export function readBaseAt(ref, root = process.cwd(), file = BASELINE_FILE) {
90
+ try {
91
+ const out = execFileSync("git", ["show", `${ref}:${file}`], {
92
+ cwd: root,
93
+ encoding: "utf8",
94
+ stdio: ["ignore", "pipe", "ignore"],
95
+ });
96
+ return JSON.parse(out);
97
+ } catch {
98
+ return null;
99
+ }
100
+ }
101
+
102
+ /** `{ newPath: oldPath }` for files git considers renamed between ref and HEAD. */
103
+ export function detectRenames(ref, root = process.cwd()) {
104
+ try {
105
+ const out = execFileSync("git", ["diff", "--name-status", "-M", `${ref}...HEAD`], {
106
+ cwd: root,
107
+ encoding: "utf8",
108
+ stdio: ["ignore", "pipe", "ignore"],
109
+ });
110
+ const map = {};
111
+ for (const line of out.split("\n")) {
112
+ const parts = line.split("\t");
113
+ if (!parts[0]?.startsWith("R")) continue;
114
+ const [, oldPath, newPath] = parts;
115
+ if (oldPath && newPath) map[newPath] = oldPath;
116
+ }
117
+ return map;
118
+ } catch {
119
+ return {};
120
+ }
121
+ }
122
+
123
+ /** Did `p` exist at `ref`? Used to tell a live entry from a stale one. */
124
+ export function existedAt(ref, p, root = process.cwd()) {
125
+ try {
126
+ execFileSync("git", ["cat-file", "-e", `${ref}:${p}`], {
127
+ cwd: root,
128
+ stdio: "ignore",
129
+ });
130
+ return true;
131
+ } catch {
132
+ return false;
133
+ }
134
+ }
135
+
136
+ // ---------------------------------------------------------------------------
137
+ // The decision table
138
+ // ---------------------------------------------------------------------------
139
+
140
+ /**
141
+ * @param {object} input
142
+ * @param {string} input.ruleId
143
+ * @param {Record<string, number>} input.listed baseline counts in the working tree
144
+ * @param {Record<string, number>|null} input.base baseline counts at the base ref, or null when unreadable
145
+ * @param {Record<string, number>} input.current counts measured right now
146
+ * @param {Record<string, string>} [input.renames] newPath -> oldPath
147
+ * @param {(p: string) => boolean} [input.exists] does this path exist in the working tree
148
+ * @param {(p: string) => boolean} [input.existedAtBase] did this path exist at the base ref
149
+ */
150
+ export function checkRatchet({
151
+ ruleId,
152
+ listed,
153
+ base,
154
+ current,
155
+ renames = {},
156
+ exists = () => true,
157
+ existedAtBase = () => true,
158
+ }) {
159
+ const violations = [];
160
+ const unmeasured = [];
161
+ const resolved = [];
162
+ let checked = 0;
163
+
164
+ const membershipChecked = base !== null && base !== undefined;
165
+ const listedPaths = Object.keys(listed);
166
+
167
+ // Rule 1: a listed file may not get worse.
168
+ for (const p of listedPaths) {
169
+ const allowed = listed[p];
170
+ const now = current[p];
171
+
172
+ if (now === undefined) {
173
+ if (!exists(p)) {
174
+ resolved.push({ path: p, reason: "file no longer exists" });
175
+ } else {
176
+ // The file is there and the measurement produced nothing for it. That
177
+ // is not the same as "clean" — it is "we did not look" — and it must be
178
+ // named, or the coverage number lies.
179
+ unmeasured.push({ path: p, reason: "no count produced for a file that exists" });
180
+ }
181
+ continue;
182
+ }
183
+
184
+ checked += 1;
185
+ if (now > allowed) {
186
+ violations.push({
187
+ kind: "growth",
188
+ path: p,
189
+ allowed,
190
+ found: now,
191
+ detail: `${p} is grandfathered at ${allowed} and now has ${now}. A listed file may not get worse.`,
192
+ });
193
+ } else if (now === 0) {
194
+ resolved.push({ path: p, reason: "no violations left" });
195
+ }
196
+ }
197
+
198
+ // Rule 2: no file may join the list.
199
+ if (membershipChecked) {
200
+ for (const p of listedPaths) {
201
+ if (p in base) {
202
+ // A listed path whose file did not exist at base is a stale entry. It
203
+ // cannot be reused: path membership alone does not prove that THIS file
204
+ // was ever grandfathered.
205
+ if (!existedAtBase(p) && exists(p)) {
206
+ violations.push({
207
+ kind: "stale-entry-reuse",
208
+ path: p,
209
+ detail: `${p} is in the base baseline but no file existed there. A stale entry cannot be reused for a different file.`,
210
+ });
211
+ }
212
+ continue;
213
+ }
214
+ const from = renames[p];
215
+ if (from && from in base) continue; // a listed file that moved stays listed
216
+ violations.push({
217
+ kind: "new-entry",
218
+ path: p,
219
+ detail: from
220
+ ? `${p} was renamed from ${from}, which was not grandfathered. Renaming a file into the baseline is not a way in.`
221
+ : `${p} is new to the baseline. The list is shrink-only; fix the violation instead of listing the file.`,
222
+ });
223
+ }
224
+ }
225
+
226
+ // Rule 3: an unlisted file with violations fails outright. This is the half
227
+ // that makes new work clean; without it the ratchet only guards the old mess.
228
+ for (const [p, count] of Object.entries(current)) {
229
+ if (count === 0 || p in listed) continue;
230
+ violations.push({
231
+ kind: "unlisted-violation",
232
+ path: p,
233
+ found: count,
234
+ detail: `${p} has ${count} violation(s) and is not grandfathered. New work has to be clean.`,
235
+ });
236
+ }
237
+
238
+ return {
239
+ ruleId,
240
+ ok: violations.length === 0,
241
+ membershipChecked,
242
+ coverage: { checked, listed: listedPaths.length, unmeasured },
243
+ resolved,
244
+ violations,
245
+ };
246
+ }
247
+
248
+ // ---------------------------------------------------------------------------
249
+ // Report
250
+ // ---------------------------------------------------------------------------
251
+
252
+ /**
253
+ * Render a result. Coverage is stated on EVERY run, pass or fail, so a run that
254
+ * measured nothing can never be mistaken for a run that found nothing.
255
+ */
256
+ export function renderReport(result, { baseRef } = {}) {
257
+ const out = [];
258
+ const { coverage, ruleId } = result;
259
+
260
+ out.push(
261
+ `ratchet [${ruleId}]: growth-checked ${coverage.checked} of ${coverage.listed} listed file(s)`,
262
+ );
263
+
264
+ if (!result.membershipChecked) {
265
+ out.push(
266
+ ` ! baseline membership NOT checked${baseRef ? ` (could not read ${BASELINE_FILE} at ${baseRef})` : ""}.`,
267
+ " Nothing was rejected for joining the list, because the gate could not look.",
268
+ );
269
+ }
270
+
271
+ for (const u of coverage.unmeasured) {
272
+ out.push(` ! unmeasured ${u.path} (${u.reason})`);
273
+ }
274
+
275
+ for (const v of result.violations) {
276
+ out.push(` x ${v.kind.padEnd(20)} ${v.detail}`);
277
+ }
278
+
279
+ if (result.resolved.length) {
280
+ out.push(
281
+ "",
282
+ ` ${result.resolved.length} entr${result.resolved.length === 1 ? "y is" : "ies are"} now clean and can be removed from the baseline:`,
283
+ );
284
+ for (const r of result.resolved.slice(0, 10)) out.push(` - ${r.path} (${r.reason})`);
285
+ if (result.resolved.length > 10) out.push(` ... and ${result.resolved.length - 10} more`);
286
+ }
287
+
288
+ out.push("", result.ok ? "✓ ratchet: no growth, no new entries." : "✗ ratchet: see above.");
289
+ return out.join("\n");
290
+ }
291
+
292
+ /**
293
+ * The whole flow for a consumer that has already measured `current`.
294
+ * Returns `{ result, report, exitCode }`; the caller decides what to do with it.
295
+ */
296
+ export function runRatchet({
297
+ ruleId,
298
+ current,
299
+ root = process.cwd(),
300
+ baseRef = "origin/main",
301
+ baselineFile = BASELINE_FILE,
302
+ advisory = false,
303
+ }) {
304
+ const baseline = readBaseline(root, baselineFile);
305
+ const entry = ruleEntry(baseline, ruleId);
306
+ const listed = entry?.files ?? {};
307
+
308
+ const baseBaseline = readBaseAt(baseRef, root, baselineFile);
309
+ const base = baseBaseline ? (ruleEntry(baseBaseline, ruleId)?.files ?? {}) : null;
310
+
311
+ const result = checkRatchet({
312
+ ruleId,
313
+ listed,
314
+ base,
315
+ current,
316
+ renames: detectRenames(baseRef, root),
317
+ exists: (p) => fs.existsSync(path.join(root, p)),
318
+ existedAtBase: (p) => existedAt(baseRef, p, root),
319
+ });
320
+
321
+ return {
322
+ result,
323
+ report: renderReport(result, { baseRef }),
324
+ exitCode: advisory || result.ok ? 0 : 1,
325
+ };
326
+ }
@@ -2,6 +2,19 @@
2
2
  * The AI-slop signal set — the single definition shared by the lint that
3
3
  * enforces it and the eval rubric that scores it.
4
4
  *
5
+ * Two exports, because two rules need to see more than one line:
6
+ * RULES per-line detectors. `test(line, { isComment })`.
7
+ * FILE_RULES whole-file detectors. `test(src, { lines })`. Only lint-slop
8
+ * consumes these; the MCP rubric scores per-line rules only, so
9
+ * adding a file rule can never change a rubric score.
10
+ *
11
+ * Rules 7 to 14 were added 2026-09-03 from the AI design-pattern blacklist in
12
+ * ClosedLoop's design pack (used with permission). They are the subset of that
13
+ * list with an objective, low-false-positive detector. Three items from it were
14
+ * deliberately NOT ported — cookie-cutter section rhythm, badge-where-a-string-
15
+ * would-do, and border-on-everything — because each needs a layout or density
16
+ * model rather than a text scan. See docs/roadmap-closedloop-import.md item 5.
17
+ *
5
18
  * These lived inside lint-slop.mjs as a private const, so the eval had no way
6
19
  * to score them without keeping a second copy. Two copies of "what slop is"
7
20
  * would drift, which is the failure this whole rule set exists to prevent one
@@ -74,4 +87,147 @@ export const RULES = [
74
87
  );
75
88
  },
76
89
  },
90
+ {
91
+ code: "BADS-SLOP-7",
92
+ name: "system-font-primary",
93
+ why: "system-ui / -apple-system as the FIRST face in the stack — the 'gave up on typography' signal. A stack that names a real face first and falls back to system-ui is fine; this only fires when the system font IS the choice. Pick a typeface from layer 1.",
94
+ test: (line, { isComment }) => {
95
+ if (isComment) return false;
96
+ // Tailwind arbitrary family: font-[system-ui] / font-[-apple-system]
97
+ if (/\bfont-\[\s*(system-ui|-apple-system|BlinkMacSystemFont)/i.test(line)) return true;
98
+ // CSS or inline style: the first face in the declared stack
99
+ const decl = line.match(/font-?[Ff]amily\s*[:=]\s*["'`]?\s*([^;"'`,}]+)/);
100
+ if (!decl) return false;
101
+ return /^\s*(system-ui|-apple-system|BlinkMacSystemFont)\b/i.test(decl[1]);
102
+ },
103
+ },
104
+ {
105
+ code: "BADS-SLOP-8",
106
+ name: "accent-left-border",
107
+ why: "A colored left border on a CARD (border-left: 3px solid <accent>). It reads as a status stripe nobody defined. If it IS a status, use Alert; if it is emphasis, use Blockquote; otherwise use the semantic surface tokens.",
108
+ // Deliberately scoped to cards. Two BADS registers own a colored left bar
109
+ // and must never fire: Alert's status stripe and Blockquote's editorial
110
+ // accent. Both are named, both are the sanctioned answer this rule points
111
+ // at, so the Tailwind branch requires a card signal on the same element.
112
+ test: (line, { isComment }) => {
113
+ if (isComment) return false;
114
+ const cardish = /\bbg-card\b|<Card\b|\brounded-(lg|xl|2xl|3xl)\b/.test(line);
115
+ if (/\bborder-l-(2|4|8)\b/.test(line) && SATURATED_BG_OR_BORDER.test(line) && cardish)
116
+ return true;
117
+ // CSS / inline: border-left: 3px solid <anything but transparent>
118
+ const css = line.match(/border-?[Ll]eft\s*[:=]\s*["'`]?\s*(\d+)px\s+solid\s+([^;"'`}]+)/);
119
+ if (css && Number(css[1]) >= 2 && !/transparent/i.test(css[2])) return true;
120
+ return false;
121
+ },
122
+ },
123
+ {
124
+ code: "BADS-SLOP-9",
125
+ name: "icon-in-colored-circle",
126
+ why: "An icon centered in a saturated colored disc — the SaaS-starter-template look. BADS carries status in the icon's own token color, not in a decorative puck behind it. Status dots (size-2/3) and neutral avatars deliberately do not fire.",
127
+ test: (line, { isComment }) => {
128
+ if (isComment) return false;
129
+ if (!/\brounded-full\b/.test(line)) return false;
130
+ if (!SATURATED_BG.test(line)) return false;
131
+ // icon scale only: size-8 and up, or a matched h-N w-N at that scale.
132
+ const sized = /\bsize-(8|9|10|11|12|14|16|20)\b/.test(line);
133
+ const hw = line.match(/\bh-(\d{1,2})\b/) && line.match(/\bw-(\d{1,2})\b/);
134
+ const hwBig =
135
+ hw &&
136
+ Number(line.match(/\bh-(\d{1,2})\b/)[1]) >= 8 &&
137
+ Number(line.match(/\bw-(\d{1,2})\b/)[1]) >= 8;
138
+ return sized || Boolean(hwBig);
139
+ },
140
+ },
141
+ {
142
+ code: "BADS-SLOP-10",
143
+ name: "decorative-blob",
144
+ why: "A blurred colored disc floated behind the content (absolute + rounded-full + blur-2xl/3xl). A section that feels empty needs better content, not a background blob.",
145
+ test: (line, { isComment }) => {
146
+ if (isComment) return false;
147
+ return (
148
+ /\babsolute\b/.test(line) &&
149
+ /\brounded-full\b/.test(line) &&
150
+ /\bblur-(2xl|3xl)\b/.test(line)
151
+ );
152
+ },
153
+ },
154
+ {
155
+ code: "BADS-SLOP-11",
156
+ name: "three-up-feature-grid",
157
+ why: "The symmetric three-column feature grid with centered cards — the single most recognizable AI layout. Three real things in a row is fine; three centered cards because three looks balanced is the tell. Vary the weights, or use a Section with plain rows.",
158
+ test: (line, { isComment }) => {
159
+ if (isComment) return false;
160
+ return /\bgrid-cols-3\b/.test(line) && /\btext-center\b/.test(line);
161
+ },
162
+ },
163
+ {
164
+ code: "BADS-SLOP-12",
165
+ name: "wave-divider",
166
+ why: "A full-bleed wavy SVG divider between sections. Decoration standing in for hierarchy. Let spacing and type do the separating.",
167
+ test: (line, { isComment }) => {
168
+ if (isComment) return false;
169
+ if (!/<svg/i.test(line)) return false;
170
+ return (
171
+ /viewBox=["'`]0 0 (1440|1920|2880)\b/.test(line) ||
172
+ /preserveAspectRatio=["'`]none/.test(line)
173
+ );
174
+ },
175
+ },
176
+ ];
177
+
178
+ // Saturated fills only. BADS's neutral surfaces (muted, secondary, accent,
179
+ // card, background) are deliberately excluded: an avatar fallback or a
180
+ // neutral chip is not the pattern these rules are looking for.
181
+ const SATURATED_NAMES =
182
+ "primary|destructive|success|warning|info|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose";
183
+ // The trailing (?![\w-]) matters: a bare \b would let `bg-primary` match
184
+ // inside `bg-primary-foreground`, which is a TEXT color token and the exact
185
+ // opposite of a decorative fill. That false-positived the Switch thumb.
186
+ const SATURATED_BG = new RegExp(`\\bbg-(${SATURATED_NAMES})(-\\d{2,3})?(?![\\w-])`);
187
+ const SATURATED_BG_OR_BORDER = new RegExp(
188
+ `\\b(bg|border)-(${SATURATED_NAMES})(-\\d{2,3})?(?![\\w-])`,
189
+ );
190
+
191
+ /**
192
+ * Whole-file detectors. A file rule sees the full source because the signal IS
193
+ * the repetition — one centered heading is a choice, eight is a template.
194
+ *
195
+ * Contract: `test(src, { lines })` returns null for a pass, or
196
+ * `{ line, detail }` for a finding, where `line` is 1-indexed and points at
197
+ * the first occurrence so the report can cite something real.
198
+ */
199
+ export const FILE_RULES = [
200
+ {
201
+ code: "BADS-SLOP-13",
202
+ name: "center-everything",
203
+ why: "text-center on nearly every block in the file. Centering is for the rare focal moment; centering everything removes the left edge the eye reads down and flattens hierarchy to nothing.",
204
+ threshold: 6,
205
+ test: (src, { lines }) => {
206
+ const hits = [];
207
+ lines.forEach((l, i) => {
208
+ if (/\btext-center\b/.test(l)) hits.push(i + 1);
209
+ });
210
+ if (hits.length < 6) return null;
211
+ return { line: hits[0], detail: `${hits.length} elements use text-center in this file` };
212
+ },
213
+ },
214
+ {
215
+ code: "BADS-SLOP-14",
216
+ name: "uniform-bubbly-radius",
217
+ why: "One large radius on every element and nothing else. A radius scale communicates surface tier — a card, a popover, and a button should not all read as the same pill. Use the --radius scale.",
218
+ threshold: 5,
219
+ test: (src, { lines }) => {
220
+ const big = [];
221
+ let other = 0;
222
+ lines.forEach((l, i) => {
223
+ if (/\brounded-(2xl|3xl)\b/.test(l)) big.push(i + 1);
224
+ if (/\brounded-(sm|md|lg|none)\b/.test(l)) other += 1;
225
+ });
226
+ if (big.length < 5 || other > 0) return null;
227
+ return {
228
+ line: big[0],
229
+ detail: `${big.length} elements use rounded-2xl/3xl and nothing uses the smaller steps`,
230
+ };
231
+ },
232
+ },
77
233
  ];