@behavioral-agentic-design-system/core 0.42.0 → 0.45.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 (104) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +25 -9
  3. package/scripts/a11y-lint.cjs +25 -1
  4. package/scripts/check-spec.mjs +73 -0
  5. package/scripts/deal-directions.mjs +186 -0
  6. package/scripts/health-report.mjs +20 -14
  7. package/scripts/lib/counted-lint.mjs +100 -0
  8. package/scripts/lib/marketing-library.mjs +129 -0
  9. package/scripts/lib/on-system.mjs +249 -0
  10. package/scripts/lib/random.mjs +22 -0
  11. package/scripts/lib/spec-parse.d.mts +25 -0
  12. package/scripts/lib/spec-parse.mjs +188 -0
  13. package/scripts/lib/tells.mjs +128 -0
  14. package/scripts/lint-css-vars.mjs +175 -0
  15. package/scripts/lint-html-nesting.mjs +116 -0
  16. package/scripts/lint-live-ctas.mjs +138 -0
  17. package/scripts/on-system-score.mjs +95 -0
  18. package/scripts/slop-rules.mjs +1 -1
  19. package/scripts/source-images.mjs +180 -0
  20. package/scripts/ux-tells.mjs +78 -0
  21. package/src/api/brand-colors.ts +3 -0
  22. package/src/api/brand-fonts.ts +3 -0
  23. package/src/api/brand-mark.ts +6 -1
  24. package/src/api/dev-write-guard.ts +53 -0
  25. package/src/api/layers/file.ts +7 -4
  26. package/src/api/onboarding-extract.ts +85 -30
  27. package/src/api/onboarding.ts +3 -0
  28. package/src/api/save-tokens.ts +3 -0
  29. package/src/app/layout.tsx +6 -0
  30. package/src/app/preview/canvas/page.tsx +12 -0
  31. package/src/app/preview/components/page.tsx +734 -0
  32. package/src/app/preview/studio/blank-screen.tsx +143 -0
  33. package/src/app/preview/studio/page.tsx +7 -0
  34. package/src/app/shell.tsx +160 -44
  35. package/src/components/canvas/canvas.tsx +458 -0
  36. package/src/components/canvas/layout.ts +72 -0
  37. package/src/components/canvas/parse-canvas.ts +32 -0
  38. package/src/components/canvas/sample.ts +90 -0
  39. package/src/components/canvas/spec-frame.tsx +43 -0
  40. package/src/components/canvas/types.ts +33 -0
  41. package/src/components/docs-tab.tsx +7 -7
  42. package/src/components/home-recent.tsx +73 -0
  43. package/src/components/home-tab.tsx +13 -13
  44. package/src/components/layers-tab.tsx +2 -2
  45. package/src/components/markdown-preview.tsx +60 -12
  46. package/src/components/studio/control-panel.tsx +299 -0
  47. package/src/components/studio/control-row.tsx +77 -0
  48. package/src/components/studio/preview-frame.tsx +165 -0
  49. package/src/components/studio/preview-pane.tsx +247 -0
  50. package/src/components/studio/studio.tsx +133 -128
  51. package/src/components/studio/types.ts +218 -0
  52. package/src/components/studio/use-studio-tweaks.ts +128 -0
  53. package/src/components/studio/use-studio-view-state.ts +72 -0
  54. package/src/components/ui/autocomplete.tsx +1 -1
  55. package/src/components/ui/color-picker.tsx +20 -4
  56. package/src/components/ui/data-table.tsx +64 -3
  57. package/src/components/ui/date-field.tsx +1 -1
  58. package/src/components/ui/editable.tsx +1 -0
  59. package/src/components/ui/faceted-filter.tsx +187 -0
  60. package/src/components/ui/gauge-chart.tsx +18 -4
  61. package/src/components/ui/inline-edit.tsx +175 -0
  62. package/src/components/ui/month-picker.tsx +1 -1
  63. package/src/components/ui/number-input.tsx +28 -5
  64. package/src/components/ui/otp-input.tsx +208 -0
  65. package/src/components/ui/phone-input.tsx +274 -0
  66. package/src/components/ui/search-input.tsx +1 -1
  67. package/src/components/ui/tags-input.tsx +1 -1
  68. package/src/components/ui/timer.tsx +1 -0
  69. package/src/components/ui/transfer-list.tsx +13 -26
  70. package/src/components/ui/week-picker.tsx +1 -1
  71. package/src/components/ui/year-picker.tsx +1 -1
  72. package/src/data/component-added.json +958 -0
  73. package/src/data/docs-index.ts +13 -1
  74. package/src/hooks/use-global-mono-font.ts +1 -0
  75. package/src/hooks/use-global-primary-color.ts +1 -0
  76. package/src/hooks/use-global-sans-font.ts +1 -0
  77. package/src/hooks/use-global-serif-font.ts +1 -0
  78. package/src/hooks/use-global-type-scale.ts +17 -2
  79. package/src/hooks/use-mobile.ts +2 -0
  80. package/src/hooks/use-sync-type-scale.ts +7 -11
  81. package/src/lib/spec-parse.ts +4 -0
  82. package/src/lib/svg-sanitize.ts +19 -9
  83. package/src/stories/Autocomplete.stories.tsx +2 -0
  84. package/src/stories/Canvas.stories.tsx +45 -0
  85. package/src/stories/ColorPicker.stories.tsx +40 -0
  86. package/src/stories/DataTable.stories.tsx +30 -0
  87. package/src/stories/DateField.stories.tsx +21 -0
  88. package/src/stories/Editable.stories.tsx +2 -0
  89. package/src/stories/FacetedFilter.stories.tsx +197 -0
  90. package/src/stories/GaugeChart.stories.tsx +9 -3
  91. package/src/stories/InlineEdit.stories.tsx +106 -0
  92. package/src/stories/MarkdownPreview.stories.tsx +53 -0
  93. package/src/stories/MonthPicker.stories.tsx +21 -0
  94. package/src/stories/NumberInput.stories.tsx +25 -0
  95. package/src/stories/OtpInput.stories.tsx +110 -0
  96. package/src/stories/PhoneInput.stories.tsx +127 -0
  97. package/src/stories/SearchInput.stories.tsx +2 -0
  98. package/src/stories/TagsInput.stories.tsx +2 -0
  99. package/src/stories/Timer.stories.tsx +26 -0
  100. package/src/stories/TransferList.stories.tsx +4 -0
  101. package/src/stories/WeekPicker.stories.tsx +21 -0
  102. package/src/stories/YearPicker.stories.tsx +21 -0
  103. package/src/stories/story-groups.json +22 -16
  104. package/src/tokens.json +82 -54
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthew Stephens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@behavioral-agentic-design-system/core",
3
- "version": "0.42.0",
3
+ "version": "0.45.0",
4
4
  "description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
5
5
  "license": "MIT",
6
6
  "author": "Matthew Stephens <work@matthewstephens.com> (https://github.com/matthewlarn)",
@@ -41,24 +41,32 @@
41
41
  "bads-a11y-ratchet": "scripts/a11y-ratchet.mjs",
42
42
  "bads-build-fonts": "scripts/build-fonts.cjs",
43
43
  "bads-build-tokens": "scripts/build-tokens.cjs",
44
+ "bads-check-spec": "scripts/check-spec.mjs",
44
45
  "bads-check-stories": "scripts/check-stories.mjs",
45
46
  "bads-check-sync": "scripts/check-sync.mjs",
46
47
  "bads-components": "scripts/bads-components.mjs",
48
+ "bads-deal-directions": "scripts/deal-directions.mjs",
47
49
  "bads-doctor": "scripts/bads-doctor.mjs",
48
50
  "bads-fix-stories": "scripts/fix-stories.mjs",
49
51
  "bads-generate-stories": "scripts/generate-stories.cjs",
50
52
  "bads-health-report": "scripts/health-report.mjs",
51
53
  "bads-lint-accent-text": "scripts/accent-as-text.mjs",
52
54
  "bads-lint-component-source": "scripts/lint-component-source.mjs",
55
+ "bads-lint-css-vars": "scripts/lint-css-vars.mjs",
53
56
  "bads-lint-ethics": "scripts/lint-ethics-contract.mjs",
57
+ "bads-lint-html-nesting": "scripts/lint-html-nesting.mjs",
58
+ "bads-lint-live-ctas": "scripts/lint-live-ctas.mjs",
54
59
  "bads-lint-microanimation": "./scripts/lint-microanimation.mjs",
55
60
  "bads-lint-slop": "scripts/lint-slop.mjs",
56
61
  "bads-lint-token-intent": "scripts/lint-token-intent.mjs",
57
62
  "bads-oklch-to-hex": "scripts/oklch-to-hex.cjs",
63
+ "bads-on-system": "scripts/on-system-score.mjs",
58
64
  "bads-size-audit": "scripts/size-audit.cjs",
65
+ "bads-source-images": "scripts/source-images.mjs",
59
66
  "bads-sync": "scripts/bads-sync.mjs",
60
67
  "bads-token-nearest": "scripts/token-nearest.mjs",
61
68
  "bads-ux-smoke": "./scripts/ux-smoke.mjs",
69
+ "bads-ux-tells": "scripts/ux-tells.mjs",
62
70
  "bads-wcag-audit": "scripts/wcag-audit.cjs"
63
71
  },
64
72
  "exports": {
@@ -88,6 +96,10 @@
88
96
  "./components/dev-identity-badge": "./src/components/dev-identity-badge.tsx",
89
97
  "./components/onboarding-wizard": "./src/components/onboarding-wizard.tsx",
90
98
  "./components/customize/*": "./src/components/customize/*.tsx",
99
+ "./components/canvas/*": "./src/components/canvas/*.tsx",
100
+ "./components/canvas/parse-canvas": "./src/components/canvas/parse-canvas.ts",
101
+ "./components/canvas/types": "./src/components/canvas/types.ts",
102
+ "./components/canvas/sample": "./src/components/canvas/sample.ts",
91
103
  "./components/motion/*": "./src/components/motion/*.tsx",
92
104
  "./components/Foundations/*": "./src/components/Foundations/*.tsx",
93
105
  "./app/page": "./src/app/page.tsx",
@@ -103,6 +115,7 @@
103
115
  "./app/preview/dashboard/page": "./src/app/preview/dashboard/page.tsx",
104
116
  "./app/preview/mail/page": "./src/app/preview/mail/page.tsx",
105
117
  "./app/preview/pricing/page": "./src/app/preview/pricing/page.tsx",
118
+ "./app/preview/studio/page": "./src/app/preview/studio/page.tsx",
106
119
  "./app/preview/typography/page": "./src/app/preview/typography/page.tsx",
107
120
  "./api/bads-update-check": "./src/api/bads-update-check.ts",
108
121
  "./api/layers": "./src/api/layers.ts",
@@ -121,11 +134,13 @@
121
134
  "access": "public"
122
135
  },
123
136
  "dependencies": {
124
- "@radix-ui/react-alert-dialog": "^1.1.23",
137
+ "@radix-ui/react-alert-dialog": "^1.1.24",
125
138
  "@xmldom/xmldom": "^0.9.12",
139
+ "@xyflow/react": "12.12.0",
126
140
  "cheerio": "^1.0.0",
127
141
  "class-variance-authority": "^0.7.0",
128
142
  "clsx": "^2.1.0",
143
+ "react-colorful": "^5.8.1",
129
144
  "react-markdown": "^10.1.0",
130
145
  "remark-gfm": "^4.0.1",
131
146
  "tailwind-merge": "^3.7.0",
@@ -163,6 +178,7 @@
163
178
  "@tanstack/react-table": "^8",
164
179
  "cmdk": "*",
165
180
  "lucide-react": "*",
181
+ "next": ">=15",
166
182
  "next-themes": "*",
167
183
  "react": ">=18",
168
184
  "react-day-picker": "^10.0.1",
@@ -202,9 +218,6 @@
202
218
  "@radix-ui/react-dialog": {
203
219
  "optional": true
204
220
  },
205
- "@radix-ui/react-navigation-menu": {
206
- "optional": true
207
- },
208
221
  "@radix-ui/react-dropdown-menu": {
209
222
  "optional": true
210
223
  },
@@ -217,6 +230,9 @@
217
230
  "@radix-ui/react-menubar": {
218
231
  "optional": true
219
232
  },
233
+ "@radix-ui/react-navigation-menu": {
234
+ "optional": true
235
+ },
220
236
  "@radix-ui/react-popover": {
221
237
  "optional": true
222
238
  },
@@ -265,13 +281,13 @@
265
281
  "lucide-react": {
266
282
  "optional": true
267
283
  },
268
- "next-themes": {
284
+ "next": {
269
285
  "optional": true
270
286
  },
271
- "react-day-picker": {
287
+ "next-themes": {
272
288
  "optional": true
273
289
  },
274
- "react-resizable-panels": {
290
+ "react-day-picker": {
275
291
  "optional": true
276
292
  },
277
293
  "recharts": {
@@ -284,4 +300,4 @@
284
300
  "devDependencies": {
285
301
  "@types/react-dom": "^19.3.0"
286
302
  }
287
- }
303
+ }
@@ -18,6 +18,7 @@
18
18
  * 3.3.2 Labels or Instructions — <input> without associated <Label> or aria-label
19
19
  * 4.1.2 Name, Role, Value — <button> with no text and no aria-label
20
20
  * BADS-WEIGHT Font weight floor — text-xs/text-sm must be font-medium (500) or heavier
21
+ * BADS-LIVE Conditional aria-live — aria-live/role="status|alert|log" inside a JSX conditional
21
22
  *
22
23
  * Run:
23
24
  * bads-a11y-lint # report violations, exit 1 on fail
@@ -73,7 +74,7 @@ const CLIENT_OWNED = readSourceOfTruth(ROOT).components === 'client';
73
74
  // weight floor) and BADS-CHART (hand-rolled chart) all belong here. The four
74
75
  // Level A codes (1.1.1, 2.1.1, 2.4.4, 4.1.2) are deliberately absent — those
75
76
  // are real defects in anyone's markup and keep blocking in every mode.
76
- const WARN_IN_CLIENT_MODE = new Set(['1.4.4', '1.4.6', '2.4.13', 'BADS-WEIGHT', 'BADS-CHART']);
77
+ const WARN_IN_CLIENT_MODE = new Set(['1.4.4', '1.4.6', '2.4.13', 'BADS-WEIGHT', 'BADS-CHART', 'BADS-LIVE']);
77
78
  const CLIENT_OWNED_NOTE = ' (warned, not failed: components are client-owned)';
78
79
 
79
80
  function isDowngraded(it) {
@@ -268,6 +269,29 @@ for (const file of files) {
268
269
  `font-normal (or lighter) on a step below ${WEIGHT_FLOOR_PX}px (${TS.smallStepsDesc}). Weight floor: font-medium (500) minimum. Add "// allow-font-normal-small" above to intentionally bypass.`);
269
270
  }
270
271
 
272
+ // BADS-LIVE — aria-live region inside a JSX conditional.
273
+ // A <div aria-live> (or role="status/alert/log") that is conditionally
274
+ // rendered gets unmounted and remounted when the condition toggles. Screen
275
+ // readers don't re-announce a newly mounted live region — the live region
276
+ // silently breaks. Fix: persistently-mounted/empty-content pattern (keep
277
+ // the element in the DOM, set children based on state).
278
+ // Escape hatch: `// allow-conditional-aria-live <one-sentence reason>`
279
+ // on the flagged line or the line above.
280
+ if (!isStory) {
281
+ const ARIA_LIVE_ATTR = /\baria-live\s*=|\brole\s*=\s*["'](?:status|alert|log)["']/;
282
+ const JSX_CONDITIONAL = /\{[^}]*&&|\?[^:]*<[A-Z]/;
283
+ if (ARIA_LIVE_ATTR.test(line)) {
284
+ const prevLine = i > 0 ? lines[i - 1] : '';
285
+ const inConditional = JSX_CONDITIONAL.test(line) || JSX_CONDITIONAL.test(prevLine);
286
+ const allowed = /\/\/\s*allow-conditional-aria-live/.test(line)
287
+ || (i > 0 && /allow-conditional-aria-live/.test(lines[i - 1]));
288
+ if (inConditional && !allowed) {
289
+ flag(file, lineNum, 'BADS-LIVE', 'conditional-aria-live',
290
+ 'aria-live region (or role="status/alert/log") inside a JSX conditional. Conditionally unmounting a live region breaks screen reader announcements on remount. Use the persistently-mounted/empty-content pattern: keep the element in the DOM and set its children based on state. Add "// allow-conditional-aria-live" with a reason to bypass.');
291
+ }
292
+ }
293
+ }
294
+
271
295
  if (FOCUS_OUTLINE_NONE.test(line) && !/ring-|outline-|focus-visible:/.test(line)) {
272
296
  flag(file, lineNum, '2.4.13', 'focus-removed',
273
297
  'outline-none without a replacement focus indicator. AAA 2.4.13 requires a visible focus marker.');
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * bads-check-spec: gate a prototype's spec.md.
4
+ *
5
+ * Layout it reads (default root: ./prototypes):
6
+ * prototypes/<slug>/prototype.meta.ts status: "draft" | "review" | "approved" | "shipped"
7
+ * prototypes/<slug>/spec.md
8
+ *
9
+ * For a prototype at review, approved, or shipped, any spec problem is an error
10
+ * and the exit code is 1. A draft reports problems as warnings. The status comes
11
+ * from prototype.meta.ts, the single source, so the spec carries no status of
12
+ * its own.
13
+ *
14
+ * npx bads-check-spec [root] [--warn]
15
+ */
16
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs"
17
+ import { join, resolve } from "node:path"
18
+ import { fileURLToPath } from "node:url"
19
+ import { analyzeSpec } from "./lib/spec-parse.mjs"
20
+
21
+ const GATED = new Set(["review", "approved", "shipped"])
22
+
23
+ export function readStatus(metaSource) {
24
+ const m = /status\s*:\s*["'](draft|review|approved|shipped)["']/.exec(metaSource)
25
+ return m ? m[1] : null
26
+ }
27
+
28
+ /** Check every prototype folder under `root`. Returns { errors, warnings }. */
29
+ export function checkPrototypes(root) {
30
+ const errors = []
31
+ const warnings = []
32
+ if (!existsSync(root)) return { errors, warnings, checked: 0 }
33
+ let checked = 0
34
+ for (const slug of readdirSync(root).sort()) {
35
+ const dir = join(root, slug)
36
+ if (!statSync(dir).isDirectory()) continue
37
+ const metaPath = join(dir, "prototype.meta.ts")
38
+ if (!existsSync(metaPath)) continue
39
+ checked += 1
40
+ const status = readStatus(readFileSync(metaPath, "utf8"))
41
+ const out = status && GATED.has(status) ? errors : warnings
42
+ if (!status) {
43
+ errors.push(`${slug}: prototype.meta.ts has no readable status`)
44
+ continue
45
+ }
46
+ const specPath = join(dir, "spec.md")
47
+ if (!existsSync(specPath)) {
48
+ out.push(`${slug} (${status}): no spec.md`)
49
+ continue
50
+ }
51
+ const { frontMatter, problems } = analyzeSpec(readFileSync(specPath, "utf8"))
52
+ if (frontMatter.prototype && frontMatter.prototype !== slug && !frontMatter.prototype.includes("<")) {
53
+ problems.push(`front matter \`prototype\` is "${frontMatter.prototype}" but the folder is "${slug}"`)
54
+ }
55
+ for (const p of problems) out.push(`${slug} (${status}): ${p}`)
56
+ }
57
+ return { errors, warnings, checked }
58
+ }
59
+
60
+ // A bin runs through a symlink, so compare real paths, not argv[1] as given.
61
+ const isMain = process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)
62
+
63
+ if (isMain) {
64
+ const args = process.argv.slice(2)
65
+ const warnOnly = args.includes("--warn")
66
+ const root = resolve(args.find((a) => !a.startsWith("--")) ?? "prototypes")
67
+ const { errors, warnings, checked } = checkPrototypes(root)
68
+ for (const w of warnings) console.log(`warn ${w}`)
69
+ for (const e of errors) console.log(`error ${e}`)
70
+ if (checked === 0) console.log(`bads-check-spec: no prototypes found under ${root}`)
71
+ else console.log(`bads-check-spec: ${checked} prototype(s), ${errors.length} error(s), ${warnings.length} warning(s)`)
72
+ process.exit(errors.length > 0 && !warnOnly ? 1 : 0)
73
+ }
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * deal-directions — deal three starting directions for a Path B build, so the
4
+ * agent chooses among them instead of inventing the category default.
5
+ *
6
+ * Why a script: asked to invent a look, a model returns the safest shape for the
7
+ * category every time. design-exploration step 3.7 already says to pick a named
8
+ * macrostructure and diversify against the fork's last three; this makes the
9
+ * draw mechanical. The idea of dealing a few researched directions, rather than
10
+ * asking for one, is from Leonxlnx/taste-skill (MIT); the pool, the exclusion
11
+ * rule and the ledger memory are BADS's own (prompts/macrostructures.md,
12
+ * ledgers/prototypes.jsonl).
13
+ *
14
+ * What it deals: three macrostructures with a visual register and an interaction
15
+ * paradigm each. The three differ on every axis, so they meet the "differ on at
16
+ * least two axes" rule by construction. It skips the fork's last three
17
+ * macrostructures (ledger `macrostructure` field) and flags the two safest
18
+ * shapes, which need a written reason if chosen.
19
+ *
20
+ * Marketing, with the composition library present (disciplines/marketing/library/), deals
21
+ * full directions from it, and then a direction sheet: a hero and a section per role.
22
+ * Product surfaces, and marketing without the library, deal macrostructures.
23
+ *
24
+ * Usage (from the repo root):
25
+ * bads-deal-directions --surface product [--seed 42] [--count 3] [--json]
26
+ * bads-deal-directions --surface marketing --sector restaurant --tone warm
27
+ * bads-deal-directions --surface marketing --direction <id> --sections intro,features,proof,cta
28
+ * bads-deal-directions --surface marketing --direction <id> --alternatives features
29
+ * bads-deal-directions --list sectors|tones|roles|directions
30
+ *
31
+ * Same seed, same ledger, same deal. Without --seed the deal is random.
32
+ * It never writes anything. Record the direction you choose on the prototype's
33
+ * ledgers/prototypes.jsonl row, as `macrostructure`.
34
+ */
35
+ import fs from "node:fs";
36
+ import path from "node:path";
37
+ import { fileURLToPath } from "node:url";
38
+ import { rng, shuffle } from "./lib/random.mjs";
39
+
40
+ export const REGISTERS = ["editorial-magazine", "pro-tool-terminal", "brutalist", "consumer-playful", "motion-led", "retro", "art-direction-led"];
41
+ export const PARADIGMS = { product: ["click-driven", "keyboard-first", "voice", "gesture", "scroll-driven", "command-palette"], marketing: ["click-driven", "scroll-driven", "keyboard-first", "gesture"] };
42
+ // The two shapes a model reaches for unprompted. Allowed, but only with a written reason.
43
+ export const SAFE_DEFAULTS = ["Dashboard-of-tiles", "Split master–detail"];
44
+
45
+ export { rng, shuffle };
46
+
47
+ /** Macrostructures named in prompts/macrostructures.md, by surface. */
48
+ export function parseMacrostructures(md) {
49
+ const out = { product: [], marketing: [] };
50
+ let into = null;
51
+ let current = null;
52
+ const flush = () => { if (current) out[into].push({ name: current.name, note: current.text.replace(/\s+/g, " ").trim() }); current = null; };
53
+ for (const line of md.replace(/\r\n/g, "\n").split("\n")) {
54
+ if (/^##\s+Product/i.test(line)) { flush(); into = "product"; continue; }
55
+ if (/^##\s+Marketing/i.test(line)) { flush(); into = "marketing"; continue; }
56
+ if (/^##\s+/.test(line) || /^---\s*$/.test(line)) { flush(); into = /^##\s+/.test(line) ? null : into; continue; }
57
+ if (!into) continue;
58
+ const m = line.match(/^-\s+\*\*(.+?)\*\*\s*(?:—|-)?\s*(.*)$/);
59
+ if (m) { flush(); current = { name: m[1].trim(), text: m[2] }; } else if (current && /^\s+\S/.test(line)) current.text += " " + line.trim();
60
+ }
61
+ flush();
62
+ return out;
63
+ }
64
+
65
+ /** The newest `n` non-empty values of one ledger field, oldest first. Malformed rows are skipped. */
66
+ export function recentField(jsonl, field, n = 3) {
67
+ const rows = [];
68
+ for (const line of jsonl.split("\n")) {
69
+ if (!line.trim()) continue;
70
+ try { rows.push(JSON.parse(line)); } catch { /* skip a malformed row */ }
71
+ }
72
+ return rows.map((r) => r[field]).filter(Boolean).slice(-n);
73
+ }
74
+
75
+ /** The macrostructures used by this fork's recent builds, newest last. */
76
+ export const recentMacrostructures = (jsonl, n = 3) => recentField(jsonl, "macrostructure", n);
77
+
78
+ const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
79
+
80
+ /** Deal `count` directions. Pure: pass the pool, the exclusions and a random source. */
81
+ export function deal({ pool, exclude = [], surface, count = 3, random = Math.random }) {
82
+ const skip = new Set(exclude.map(norm));
83
+ let candidates = pool.filter((m) => !skip.has(norm(m.name)));
84
+ const excluded = pool.length - candidates.length;
85
+ // If the exclusions leave too few, say so and relax rather than returning short.
86
+ let relaxed = false;
87
+ if (candidates.length < count) { candidates = pool; relaxed = true; }
88
+ const picks = shuffle(candidates, random).slice(0, count);
89
+ const registers = shuffle(REGISTERS, random);
90
+ const paradigms = shuffle(PARADIGMS[surface] || PARADIGMS.product, random);
91
+ const directions = picks.map((m, i) => ({
92
+ macrostructure: m.name,
93
+ register: registers[i % registers.length],
94
+ paradigm: paradigms[i % paradigms.length],
95
+ note: m.note,
96
+ safeDefault: SAFE_DEFAULTS.some((s) => norm(s) === norm(m.name)),
97
+ }));
98
+ return { surface, excluded, relaxed, directions };
99
+ }
100
+
101
+ export function format(result, recent) {
102
+ const lines = [];
103
+ lines.push(`Dealt ${result.directions.length} directions for a ${result.surface} surface.`);
104
+ lines.push(recent.length ? `Skipped this fork's last ${recent.length}: ${recent.join(", ")}.` : "No macrostructure recorded in ledgers/prototypes.jsonl yet, so nothing is skipped.");
105
+ if (result.relaxed) lines.push("The pool is too small to skip them all, so a recent one may appear. Say why in the sketch.");
106
+ lines.push("");
107
+ result.directions.forEach((d, i) => {
108
+ lines.push(`${i + 1}. ${d.macrostructure} · ${d.register} · ${d.paradigm}`);
109
+ if (d.note) lines.push(` ${d.note.length > 240 ? d.note.slice(0, 237) + "…" : d.note}`);
110
+ if (d.safeDefault) lines.push(" ⚠ A safe default. Choose it only with a written reason.");
111
+ });
112
+ lines.push("");
113
+ lines.push("Hold each against the subject inventory (prompts/subject-inventory.md): which can carry something only this client has? Choose one, write why in one line, then sketch within it. Redraw only for a reason you can state, such as a brand constraint, and record the redraw.");
114
+ return lines.join("\n");
115
+ }
116
+
117
+ /** Parse a comma list flag. */
118
+ const list = (v) => (v ? String(v).split(",").map((x) => x.trim()).filter(Boolean) : []);
119
+
120
+ async function main(argv) {
121
+ const arg = (name, fallback) => { const i = argv.indexOf(name); return i >= 0 ? argv[i + 1] : fallback; };
122
+ const root = process.cwd();
123
+ const json = argv.includes("--json");
124
+ const seed = arg("--seed");
125
+ const random = seed !== undefined ? rng(Number(seed)) : Math.random;
126
+ const { loadLibrary, vocab, dealDirections, dealSheet, alternatives, formatDirections, formatSheet } = await import("./lib/marketing-library.mjs");
127
+ const lib = loadLibrary(root);
128
+
129
+ const listing = arg("--list");
130
+ if (listing) {
131
+ if (!lib) { console.error("deal-directions: no marketing library here. Run it from the repo root."); return 2; }
132
+ const v = vocab(lib);
133
+ const out = listing === "directions" ? lib.directions.map((d) => `${d.id} ${d.name}`) : v[listing];
134
+ if (!out) { console.error("usage: --list sectors|tones|roles|directions"); return 2; }
135
+ console.log(out.join("\n"));
136
+ return 0;
137
+ }
138
+
139
+ const surface = arg("--surface");
140
+ if (!["marketing", "product"].includes(surface)) {
141
+ console.error("usage: deal-directions --surface marketing|product [--seed N] [--json]\n marketing: [--sector S] [--tone T] [--have product-photo,product-ui] [--software]\n [--direction ID --sections intro,features,proof,cta | --alternatives ROLE]\n list: --list sectors|tones|roles|directions");
142
+ return 2;
143
+ }
144
+
145
+ // Marketing with the library present: deal full directions and sheets. Otherwise the macrostructure deal.
146
+ if (surface === "marketing" && lib && !argv.includes("--macrostructures")) {
147
+ const have = list(arg("--have")), software = argv.includes("--software");
148
+ const direction = arg("--direction");
149
+ try {
150
+ if (direction && arg("--alternatives")) {
151
+ const alts = alternatives(lib, { direction, role: arg("--alternatives"), have, software });
152
+ console.log(json ? JSON.stringify(alts, null, 2) : alts.map((x) => `${x.id} ${x.name} (${x.shape})`).join("\n") || "none");
153
+ return 0;
154
+ }
155
+ if (direction) {
156
+ const roles = list(arg("--sections"));
157
+ if (!roles.length) { console.error("--direction needs --sections, e.g. --sections intro,features,proof,cta. Roles: " + vocab(lib).roles.join(", ")); return 2; }
158
+ const bad = roles.filter((r) => !vocab(lib).roles.includes(r));
159
+ if (bad.length) { console.error(`unknown role: ${bad.join(", ")}. Roles: ${vocab(lib).roles.join(", ")}`); return 2; }
160
+ const sheet = dealSheet(lib, { direction, roles, have, software, random });
161
+ console.log(json ? JSON.stringify(sheet, null, 2) : formatSheet(sheet));
162
+ return 0;
163
+ }
164
+ const sector = arg("--sector"), tone = arg("--tone");
165
+ const v = vocab(lib);
166
+ if (sector && !v.sectors.includes(sector)) { console.error(`unknown sector "${sector}". Sectors: ${v.sectors.join(", ")}`); return 2; }
167
+ if (tone && !v.tones.includes(tone)) { console.error(`unknown tone "${tone}". Tones: ${v.tones.join(", ")}`); return 2; }
168
+ const ledger = path.join(root, "ledgers/prototypes.jsonl");
169
+ const recent = fs.existsSync(ledger) ? recentField(fs.readFileSync(ledger, "utf8"), "libraryDirection", 3) : [];
170
+ const result = dealDirections(lib, { sector, tone, have, software, exclude: recent, count: Number(arg("--options", 3)), random });
171
+ console.log(json ? JSON.stringify(result, null, 2) : formatDirections(result, { sector, tone }));
172
+ return 0;
173
+ } catch (e) { console.error(`deal-directions: ${e.message}`); return 2; }
174
+ }
175
+
176
+ const mdPath = path.join(root, "prompts/macrostructures.md");
177
+ if (!fs.existsSync(mdPath)) { console.error(`deal-directions: ${path.relative(root, mdPath)} not found. Run it from the repo root.`); return 2; }
178
+ const pool = parseMacrostructures(fs.readFileSync(mdPath, "utf8"))[surface];
179
+ const ledger = path.join(root, "ledgers/prototypes.jsonl");
180
+ const recent = fs.existsSync(ledger) ? recentMacrostructures(fs.readFileSync(ledger, "utf8")) : [];
181
+ const result = deal({ pool, exclude: recent, surface, count: Number(arg("--count", 3)), random });
182
+ console.log(json ? JSON.stringify({ ...result, skipped: recent }, null, 2) : format(result, recent));
183
+ return 0;
184
+ }
185
+
186
+ if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) process.exit(await main(process.argv.slice(2)));
@@ -91,6 +91,24 @@ function uxRowText(row) {
91
91
  return String(row.finding ?? row.summary ?? "");
92
92
  }
93
93
 
94
+ /**
95
+ * Whether `name` is demonstrated in the showcase page source. The registry
96
+ * key is not always the JSX tag actually rendered: TreeView's primitive
97
+ * exports as <Tree>, not <TreeView> (same alias gap as corrections.md
98
+ * #009/#010). Caught 2026-10-05 when TreeView scored a false "not
99
+ * demonstrated" despite a full showcase section titled "Tree View". Checks
100
+ * every costModel.jsxNames alias too, and loosens the title match to ignore
101
+ * case/spacing so "Tree View" matches title="TreeView".
102
+ */
103
+ function isDemonstratedInShowcase(name, jsxNames, showcaseSource) {
104
+ const aliases = [name, ...(jsxNames ?? [])];
105
+ const looseTitle = new RegExp(`title=["']${name.replace(/\s+/g, "")}["']`, "i");
106
+ return (
107
+ aliases.some((a) => showcaseSource.includes(`<${a}`) || showcaseSource.includes(`${a}Showcase`)) ||
108
+ looseTitle.test(showcaseSource.replace(/\s+/g, ""))
109
+ );
110
+ }
111
+
94
112
  function main() {
95
113
  // Repo-root resolution is cwd-based (not file-relative) so this works both in
96
114
  // upstream BADS (scripts/ -> repo root) and after shipping as a package bin
@@ -202,19 +220,7 @@ function main() {
202
220
  if (showcase === null) {
203
221
  penalties.push({ source: "showcase", points: 0, why: "showcase-presence signal unavailable (showcase page not found locally or in the package)" });
204
222
  } else {
205
- // The registry key is not always the JSX tag rendered in the showcase
206
- // (TreeView's primitive exports as <Tree>, not <TreeView> — same alias
207
- // gap as corrections.md #009/#010, caught 2026-10-05 when TreeView
208
- // scored a false "not demonstrated" despite a full showcase section
209
- // titled "Tree View"). Check every costModel.jsxNames alias too, and
210
- // loosen the title match to ignore case/spacing so "Tree View" matches
211
- // "TreeView".
212
- const aliases = [name, ...(e.costModel?.jsxNames ?? [])];
213
- const looseTitle = new RegExp(`title=["']${name.replace(/\s+/g, "")}["']`, "i");
214
- const demonstrated =
215
- aliases.some((a) => showcase.includes(`<${a}`) || showcase.includes(`${a}Showcase`)) ||
216
- looseTitle.test(showcase.replace(/\s+/g, ""));
217
- if (!demonstrated) {
223
+ if (!isDemonstratedInShowcase(name, e.costModel?.jsxNames, showcase)) {
218
224
  penalties.push({ source: "showcase", points: 5, why: "not demonstrated in the components showcase" });
219
225
  }
220
226
  }
@@ -300,4 +306,4 @@ function isMainModule() {
300
306
 
301
307
  if (isMainModule()) main();
302
308
 
303
- export { resolvePackageOwned, isMainModule, main, activeCorrectionsNaming, buildRowComponent, uxRowPenalizes, uxRowText };
309
+ export { resolvePackageOwned, isMainModule, main, activeCorrectionsNaming, buildRowComponent, uxRowPenalizes, uxRowText, isDemonstratedInShowcase };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * counted-lint — the shared tail of the lints that count findings per file.
3
+ *
4
+ * A lint collects `findings` (what is wrong) and `scanned` (every file it
5
+ * actually looked at, including the clean ones) and hands both here. This module
6
+ * owns the four modes every such lint offers, so each lint stays about its rule:
7
+ *
8
+ * (default) strict: print the findings, exit 1 when there are any
9
+ * --warn the same report, always exit 0
10
+ * --init record today's counts into .bads-ratchet.json under this rule's id
11
+ * --ratchet compare against that baseline using ratchet.mjs: a listed file may
12
+ * not get worse, and no file may join the list
13
+ *
14
+ * `scanned` matters for a reason worth stating: a lint that looked at nothing
15
+ * and found nothing reports the same "clean" as one that looked at everything.
16
+ * Zero files scanned is refused here, loudly, in every mode.
17
+ */
18
+
19
+ import { readBaseline, writeBaseline, runRatchet, BASELINE_FILE, SCHEMA_VERSION } from "../ratchet.mjs";
20
+
21
+ export function flagValue(argv, name, fallback) {
22
+ const i = argv.indexOf(`--${name}`);
23
+ return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : fallback;
24
+ }
25
+
26
+ /**
27
+ * @param {object} o
28
+ * @param {string} o.ruleId key in .bads-ratchet.json, e.g. "live-ctas"
29
+ * @param {string} o.bin for messages, e.g. "bads-lint-live-ctas"
30
+ * @param {{file: string, line?: number, text: string}[]} o.findings
31
+ * @param {string[]} o.scanned every file read, relative to root
32
+ * @param {string} o.fix one short paragraph telling the reader how to fix a finding
33
+ * @param {string[]} [o.argv]
34
+ * @param {string} [o.root]
35
+ * @returns {number} the exit code (the caller decides whether to exit)
36
+ */
37
+ export function finishCountedLint({ ruleId, bin, findings, scanned, fix, argv = process.argv.slice(2), root = process.cwd() }) {
38
+ if (scanned.length === 0) {
39
+ console.error(`${bin}: 0 files were scanned, so nothing was checked. This is NOT "no violations."`);
40
+ return 1;
41
+ }
42
+
43
+ const current = Object.fromEntries(scanned.map((f) => [f, 0]));
44
+ for (const f of findings) current[f.file] = (current[f.file] ?? 0) + 1;
45
+
46
+ if (argv.includes("--init")) {
47
+ const withViolations = Object.fromEntries(Object.entries(current).filter(([, n]) => n > 0));
48
+ const baseline = readBaseline(root);
49
+ baseline.version = SCHEMA_VERSION;
50
+ baseline.rules = baseline.rules ?? {};
51
+ baseline.rules[ruleId] = {
52
+ recordedAt: new Date().toISOString().slice(0, 10),
53
+ note: `${bin}. Shrink-only: an entry may be removed once its file is clean, and nothing may be added.`,
54
+ files: withViolations,
55
+ };
56
+ writeBaseline(baseline, root);
57
+ const n = Object.keys(withViolations).length;
58
+ console.log(`ratchet [${ruleId}]: recorded ${n} file(s) with findings into ${BASELINE_FILE}.`);
59
+ console.log(n === 0 ? " Nothing is in violation, so the rule can go straight to strict instead." : " Commit this file. From here the list may only shrink.");
60
+ return 0;
61
+ }
62
+
63
+ if (argv.includes("--ratchet")) {
64
+ const { report, exitCode } = runRatchet({
65
+ ruleId,
66
+ current,
67
+ root,
68
+ baseRef: flagValue(argv, "base", "origin/main"),
69
+ advisory: argv.includes("--warn"),
70
+ });
71
+ console.log(report);
72
+ return exitCode;
73
+ }
74
+
75
+ if (findings.length === 0) {
76
+ console.log(`${bin}: ${scanned.length} file(s) scanned, no findings.`);
77
+ return 0;
78
+ }
79
+
80
+ const byFile = new Map();
81
+ for (const f of findings) byFile.set(f.file, [...(byFile.get(f.file) ?? []), f]);
82
+ console.error(`${bin}: ${findings.length} finding(s) in ${byFile.size} file(s).\n`);
83
+ for (const [file, list] of byFile) {
84
+ console.error(file);
85
+ for (const f of list.slice(0, 20)) console.error(` ${f.line ? `L${f.line} ` : ""}${f.text}`);
86
+ if (list.length > 20) console.error(` …and ${list.length - 20} more`);
87
+ }
88
+ console.error(`\n${fix}`);
89
+ console.error(`\nAdopting on an existing codebase? Run \`${bin} --init\` to record today's counts, then \`${bin} --ratchet\` in CI: listed files may not get worse and no file may join the list.`);
90
+ return argv.includes("--warn") ? 0 : 1;
91
+ }
92
+
93
+ /** True when the module is being run as a script, not imported by a test. */
94
+ export function isMain(importMetaUrl) {
95
+ try {
96
+ return importMetaUrl === new URL(`file://${process.argv[1]}`).href || importMetaUrl.endsWith(process.argv[1]);
97
+ } catch {
98
+ return false;
99
+ }
100
+ }