@behavioral-agentic-design-system/core 0.37.0 → 0.38.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.
@@ -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
- // Repo-root resolution is cwd-based (not file-relative) so this works both in
25
- // upstream BADS (scripts/ -> repo root) and after shipping as a package bin
26
- // into a client fork, invoked as `npx bads-health-report` from the fork's own
27
- // repo root.
28
- const ROOT = process.cwd();
29
- const argv = process.argv.slice(2);
30
- const DATE = argv.find((a) => a.startsWith("--date="))?.split("=")[1] || new Date().toISOString().slice(0, 10);
31
- const DRIFT = argv.includes("--drift");
32
-
33
- const read = (p) => fs.readFileSync(path.join(ROOT, p), "utf8");
34
- const readJsonl = (p) => {
35
- const full = path.join(ROOT, p);
36
- if (!fs.existsSync(full)) return [];
37
- return read(p).split("\n").filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
38
- };
39
-
40
- const registry = JSON.parse(read("layer-5-component-registry/component-registry.json"));
41
- const uxRows = readJsonl("ledgers/ux-tests.jsonl");
42
- const buildRows = readJsonl("ledgers/component-builds.jsonl");
43
- const corrections = fs.existsSync(path.join(ROOT, "corrections.md")) ? read("corrections.md") : "";
44
- const showcase = read("packages/core/src/app/preview/components/page.tsx");
45
- // case-insensitive: the QrCode/QRCode story case-collision fix means registry
46
- // name casing and story filename casing can legitimately differ
47
- const storyFiles = new Set(fs.readdirSync(path.join(ROOT, "packages/core/src/stories")).map((f) => f.toLowerCase()));
48
-
49
- const kebab = (s) => s.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
50
- const daysBetween = (a, b) => Math.round((new Date(a) - new Date(b)) / 86400000);
51
-
52
- const UX_PENALTY = { BLOCKER: 25, HIGH: 15, MEDIUM: 8, LOW: 3, none: 0 };
53
-
54
- const components = Object.keys(registry).sort().map((name) => {
55
- const e = registry[name];
56
- const penalties = [];
57
- let dataPoints = 0;
58
-
59
- // signal: ux-test findings (rows match on the component field)
60
- for (const r of uxRows.filter((r) => r.component === name)) {
61
- dataPoints++;
62
- const p = UX_PENALTY[r.severity] ?? 0;
63
- if (p) penalties.push({ source: "ux-test", points: p, why: `${r.severity}: ${String(r.finding || "").slice(0, 100)}` });
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
- // signal: corrections recurrences (word-boundary name mentions, capped)
67
- const mentions = (corrections.match(new RegExp(`\\b${name}\\b`, "g")) || []).length;
68
- if (mentions) {
69
- dataPoints += mentions;
70
- penalties.push({ source: "corrections", points: Math.min(mentions * 5, 15), why: `${mentions} mention(s) in corrections.md` });
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
- // signal: build-ledger outcome (latest row for this component)
74
- const builds = buildRows.filter((r) => (r.candidate || "").split(" ")[0] === name);
75
- if (builds.length) {
76
- dataPoints += builds.length;
77
- const last = builds[builds.length - 1];
78
- if (last.status === "rejected") penalties.push({ source: "build-ledger", points: 10, why: "last build attempt rejected by gates" });
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
- // structure: registry completeness (these are hygiene, not incidents)
82
- if (!e.a11yContract) penalties.push({ source: "registry", points: 10, why: "no a11yContract" });
83
- if (!e.antiPatterns?.length) penalties.push({ source: "registry", points: 5, why: "no antiPatterns" });
84
- if (!e.examples?.length) penalties.push({ source: "registry", points: 5, why: "no examples" });
85
- if (!e.costModel) penalties.push({ source: "registry", points: 5, why: "no costModel" });
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 score = Math.max(0, 100 - penalties.reduce((s, p) => s + p.points, 0));
100
- return {
101
- name,
102
- score,
103
- band: score >= 90 ? "healthy" : score >= 70 ? "watch" : "attention",
104
- insufficientData: dataPoints === 0,
105
- dataPoints,
106
- penalties: penalties.sort((a, b) => b.points - a.points),
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 known = components.filter((c) => !c.insufficientData);
111
- const summary = {
112
- components: components.length,
113
- scored: known.length,
114
- insufficientData: components.length - known.length,
115
- avgScore: known.length ? Math.round(known.reduce((s, c) => s + c.score, 0) / known.length) : null,
116
- bands: {
117
- healthy: components.filter((c) => c.band === "healthy").length,
118
- watch: components.filter((c) => c.band === "watch").length,
119
- attention: components.filter((c) => c.band === "attention").length,
120
- },
121
- };
122
-
123
- const month = DATE.slice(0, 7);
124
- const outPath = path.join(ROOT, "ledgers", "reports", `health-${month}.json`);
125
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
126
-
127
- // --drift: compare against the most recent PRIOR report before overwriting
128
- if (DRIFT) {
129
- const prior = fs.readdirSync(path.dirname(outPath))
130
- .filter((f) => /^health-\d{4}-\d{2}\.json$/.test(f) && f < `health-${month}.json`)
131
- .sort()
132
- .pop();
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
- console.log("\nLowest bands:");
156
- for (const c of worst.sort((a, b) => a.score - b.score).slice(0, 8))
157
- console.log(` ${String(c.score).padStart(3)} ${c.band.padEnd(9)} ${c.name} — ${c.penalties[0]?.why || ""}`);
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 };
@@ -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) {
@@ -153,4 +153,10 @@ function main() {
153
153
  console.log(hex);
154
154
  }
155
155
 
156
- main();
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();