basalt-ui 1.0.0 → 1.0.2

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 (40) hide show
  1. package/AGENTS.md +12 -12
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +31 -44
  4. package/agent/rules/basalt-charts.md +1 -1
  5. package/agent/rules/basalt-mantine.md +3 -3
  6. package/agent/rules/basalt-router.md +1 -1
  7. package/agent/rules/basalt-state.md +2 -2
  8. package/agent/rules/basalt-tokens.md +3 -3
  9. package/agent/skills/basalt-app/SKILL.md +137 -0
  10. package/agent/skills/basalt-charts/SKILL.md +179 -0
  11. package/agent/skills/basalt-design/SKILL.md +249 -0
  12. package/agent/templates/CLAUDE-block.md.tpl +8 -5
  13. package/agent/templates/__root.tpl +1 -1
  14. package/agent/templates/query-client.ts.tpl +1 -1
  15. package/configs/check.yml +8 -8
  16. package/configs/lefthook.yml +9 -5
  17. package/configs/oxlint-plugin.js +119 -7
  18. package/configs/oxlint-plugin.test.ts +73 -3
  19. package/configs/oxlint.json +2 -71
  20. package/dist/cli/index.d.ts +71 -28
  21. package/dist/cli/index.d.ts.map +1 -1
  22. package/dist/cli/index.js +134 -121
  23. package/dist/surfaces.d.ts +41 -17
  24. package/dist/surfaces.d.ts.map +1 -1
  25. package/dist/surfaces.js +37 -38
  26. package/dist/tokens/index.d.ts +1 -0
  27. package/dist/tokens/index.d.ts.map +1 -1
  28. package/dist/tokens/index.js +3 -0
  29. package/llms.txt +2 -2
  30. package/package.json +2 -2
  31. package/src/cli/check-theme.test.ts +12 -2
  32. package/src/cli/help.test.ts +93 -0
  33. package/src/cli/index.ts +332 -184
  34. package/src/cli/placement-engine.test.ts +194 -0
  35. package/src/cli/tarball-parity.test.ts +44 -0
  36. package/src/cli/template-format.test.ts +64 -0
  37. package/src/cli/template-ledger.test.ts +219 -0
  38. package/src/surfaces.ts +78 -43
  39. package/src/tokens/index.ts +6 -0
  40. /package/bin/{basalt.mjs → basalt-ui.mjs} +0 -0
@@ -0,0 +1,249 @@
1
+ ---
2
+ name: basalt-design
3
+ description: Design and restyle data visualizations and analytics UIs in a basalt-ui app (Mantine v9 + visx). The dataviz successor — restraint doctrine plus the live theme-lab tuning loop and the centralized, lint-enforced --vx-* token system. Use when building or restyling charts/dashboards, choosing a palette, tuning dark/light, or when charts look childish / inconsistent / over-colored.
4
+ when_to_use: User is building or restyling charts, dashboards, or metric UIs in a basalt-ui consumer; picking or tuning a palette; deciding on dark/light shades; or complaining that charts look "AI default", inconsistent across tabs, or over-saturated. Also the entry point for any "make this look professional" dataviz request in a Mantine + visx app.
5
+ ---
6
+
7
+ `/basalt-design` is the design authority for a basalt-ui app. It is the **method**; the project's
8
+ doctrine is the **law**. Professional dataviz is restraint, not decoration — this skill encodes
9
+ that restraint and the concrete, lint-enforced way basalt-ui makes it impossible to bypass.
10
+
11
+ ## Read the law first (strict precedence)
12
+
13
+ Before applying any generic guidance, load the doctrine in this exact order and obey the highest
14
+ one that exists. Lower layers fill gaps; they never override a higher layer.
15
+
16
+ 1. **Consumer `DESIGN.md`** (repo root) — the thin, app-specific instantiation. Identity
17
+ confirmation, the series dictionary, app deviations. **This wins on every conflict.** It is the
18
+ Google-spec convention (YAML token front matter + Markdown prose, sibling to `CLAUDE.md`).
19
+ 2. **Shipped `basalt-*` rules** (`.claude/rules/basalt-{tokens,charts,mantine,state}.md`) — the
20
+ universal law AND its enforcement: the Basalt modern-zinc palette + saturated sky accent,
21
+ one-hue-per-metric, neutral structure, gradient defaults, the three-tier token contract, the
22
+ shadow-card elevation/density doctrine.
23
+ 3. **This skill** — only the loop and the judgment, where the above are silent.
24
+
25
+ If a consumer `DESIGN.md` does not exist yet, the app has not been scaffolded — run `/basalt-app`
26
+ (it wraps `basalt-ui init`, which writes the thin `DESIGN.md` and the `basalt-*` rules). Do not invent
27
+ a palette ad hoc.
28
+
29
+ ## Restraint doctrine (decide before touching code)
30
+
31
+ This is the same restraint `frontend-design` calls for, applied to data: intentionality over
32
+ intensity. The `basalt-ui init` CLAUDE block sets a restraint override for exactly this reason — in a
33
+ dashboard the bold move is calm.
34
+
35
+ - **One muted hue family, reused everywhere.** The Basalt modern-zinc identity (below), never raw
36
+ Material / AntD / Tailwind primaries (they read childish and clash). A small harmonious subset
37
+ across every page so tabs feel like one app.
38
+ - **Single hue per metric.** Each metric owns ONE color, stable across all views (HRV always
39
+ violet, bench always amber). Series colors are app-side and distinct from the UI accent — don't
40
+ reuse the sky accent as a metric hue. Multiple colors only for genuinely categorical data
41
+ (sleep stages, source breakdown). A line chart almost never needs more than one hue plus neutrals.
42
+ - **Neutral structure, colored signal.** Lines/axes/grids in muted neutrals; color is the data and
43
+ status (good/warn/bad). A single neutral line with a soft tinted area reads more premium than a
44
+ rainbow.
45
+ - **Gradients on areas, not everything.** A soft single-hue vertical gradient under a line is the
46
+ canonical "modern" move (`AreaGradient`). Keep stacked-area bands opaque — transparency leaks
47
+ lower bands.
48
+ - **Quiet chrome.** Hairline grids (~6–8% neutral), thin crosshairs, restrained tooltips with a
49
+ card surface and one accent swatch per row. Generous whitespace.
50
+ - **Motion restraint (same doctrine, applied to animation).** Subtle and purposeful, never
51
+ decorative — a state change earns a transition, idle chrome does not. Reach for the shared
52
+ `MOTION_DURATION` / `MOTION_SPRING` tokens (`basalt-ui`'s `src/motion`) instead of inventing
53
+ per-component durations/easings, so animated chrome feels like one identity the same way the
54
+ `--vx-*` palette does for color. Never a looping/pulsing idle animation. Always respect
55
+ `useReducedMotion` (`@mantine/hooks`) — an animated component needs a real unanimated code path,
56
+ not just `duration: 0`.
57
+
58
+ ## Color identity & accent restraint (the #1 lever)
59
+
60
+ The Basalt identity is **modern zinc + a saturated sky accent** — cool-neutral zinc surfaces
61
+ (Tailwind zinc family) on both schemes, a slightly darker page with panels lifting off it via depth
62
+ (a whisper shadow + 1px ring, `shadow-card` — never a bare border), and one saturated sky-blue
63
+ accent. Restraint is now about _placement_, not _saturation_ — the accent is louder than the old
64
+ muted-slate identity, so the discipline below (where it appears / where it never appears) carries
65
+ more of the weight.
66
+
67
+ **Neutrals carry the surface — cool zinc on both schemes**, never warm-neutral/off-white, never
68
+ steel-blue, never pure black/white:
69
+
70
+ - **Dark:** bg `color-mix(in srgb, #27272a 70%, #18181b)` (#232326), panel `#27272a`, panel-hover
71
+ `color-mix(in srgb, #3f3f46 50%, #27272a)` (#333338), hairline (card ring)
72
+ `color-mix(in srgb, #52525c 50%, #3f3f46)` (#494951), line (strong border) `#3f3f46`. Ink
73
+ `#e5e5e5`, muted `#d4d4d4`, faint `#a1a1a1`.
74
+ - **Light:** bg `color-mix(in srgb, #f4f4f5 50%, #e4e4e7)` (#ececee), panel `#f4f4f5`, panel-hover
75
+ `#fafafa`, hairline `#e5e5e5`, line (strong border) `color-mix(in srgb, #e4e4e7 50%, #d4d4d8)`
76
+ (#dcdce0). Ink `#262626`, muted `#525252`, faint `#737373`.
77
+
78
+ The surface token set is `bg` (page) · `panel` (cards, controls) · `panel-hover` · `line` (strong
79
+ border) · `hairline` (card ring, lives inside `shadow-card`, never rendered as a bare `border`) ·
80
+ `divider` (layout separators).
81
+
82
+ **One accent, saturated sky-blue — split by ROLE.** As **ink** (links, active-nav icon, chart lines,
83
+ focus ring) it is read against the page, so it inverts: `#0077bd` light / `#8ec5ff` dark. As a
84
+ **filled surface** it carries a label, so it is squeezed between that label (≥4.5:1) and the page
85
+ behind it (≥3:1) — which leaves one luminance band, the same on both pages: `#0077bd` with a WHITE
86
+ label, in BOTH schemes. Fill with `--vx-accentFill` / `--vx-fill-{family}`, never with `--vx-accent`
87
+ (a light fill cannot carry white text). Every Mantine family's fill sits in that same band, so a
88
+ filled surface always reads white. With `accent-hover` (derived from the fill) and `on-accent`
89
+ companions (NOT the old ~50%-saturation muted slate).
90
+
91
+ The accent appears on: the primary data series, active-nav **icons** and active **child** labels,
92
+ links, primary buttons, focus rings, and the leader bar in meters. It stays off: general chrome,
93
+ borders, large fills, every icon, secondary buttons. "Ink earns its color" — neutral does the
94
+ structure, the accent only points.
95
+
96
+ - **Active nav = panel bg + `shadow-card` + accent-colored icon + weight-600 ink text**, never a
97
+ full accent fill. The theme bakes this into `NavLink` for every render path — don't re-color it.
98
+ - **Buttons:** exactly one filled-accent primary CTA per view; every other action is
99
+ `variant="default"` (neutral). Avoid colored `variant="light"` for routine actions.
100
+ - **Status:** positive deltas `color="green"` (forest), never `teal`/turquoise/saturated emerald.
101
+ - **Dark done right:** cool zinc, neutral/faint-cool, never steel-blue, never pure black; the
102
+ dark-scheme accent (`#8ec5ff`) is lighter/less saturated than its light counterpart so it doesn't
103
+ glow/bleed.
104
+ - **Light done right:** cool zinc page + panel lift (never warm/off-white); depth comes from
105
+ `shadow-card`, not a bare hairline border.
106
+
107
+ ### Density & surface consistency
108
+
109
+ - **Dense by default** (Linear/Notion): compact nav rows, `sm` (12px) gaps and card padding, a
110
+ 48px shell header. Separate by surface + `shadow-card`, not by large air — default to the
111
+ tighter step.
112
+ - **All cards render identically:** Mantine `Card`/`Paper` **and** the Mantine-free `ChartCard`
113
+ resolve to **one radius token** (`--vx-radius-card` = 7px) and **`shadow-card`** — a whisper
114
+ shadow with the 1px ring baked into the shadow itself, **no `border` property**. Never
115
+ inline-override a surface's `border`/`borderRadius`/`boxShadow`/`backgroundColor` — use the
116
+ radius token + `VX.surface.*` / the shadow-card token. Mechanically enforced by
117
+ `basalt-ui check-theme`'s `raw-surface` guard.
118
+ - **Strict surfaces & primitives.** The theme runs a strict surface system: Mantine components read
119
+ raw ramp steps directly, so `cssVariablesResolver` **collapses the ramp steps onto the
120
+ `--vx-surface-*` tokens** — one `shadow-card` treatment, one card bg, one radius across every
121
+ component (AppShell, Table, Input, Divider, Tabs, Popover, Accordion, cards). Consumer code must
122
+ **use Mantine layout primitives** (`Box`/`Flex`/`Grid`/`SimpleGrid`/`Stack`/`Group`/`Paper`/`Card`),
123
+ not raw `<div>`/`<span>` with inline `style`. `check-theme` adds four guard kinds to enforce this
124
+ (default ON, `theme-allow` escape): `off-system-surface-var` (raw ramp-step vars),
125
+ `raw-html-layout`, `inline-spacing`, `inline-display`. Only the Mantine-free `src/charts/**` may
126
+ use raw `<div>` (still with `VX.*` tokens).
127
+
128
+ **Anti-slop checklist:** no pure `#000`/`#fff`; one accent locked page-wide; neutral does the
129
+ structure, accent only points; don't flood blue; hierarchy via scale/weight/contrast/space, not
130
+ color; depth = `shadow-card` (whisper shadow + ring), never a bare hairline border on cards.
131
+
132
+ ## The three-tier token system (centralize + enforce)
133
+
134
+ Aesthetics only survive if they cannot be bypassed. basalt-ui ships this as the `./tokens` and
135
+ `./charts` surfaces:
136
+
137
+ 1. **Palette data** — the Basalt modern-zinc ramps + the saturated sky accent family, plus
138
+ every semantic/status/neutral/surface entry as a per-theme `{ light, dark }` pair. Pure data: no
139
+ React, no `@mantine/*`, no browser API.
140
+ 2. **CSS variables** — `buildPaletteCss(opts)` emits the pairs as `--vx-*` custom properties under
141
+ the light/dark color-scheme selector. Theme resolution is **pure CSS** — no JS branching, works
142
+ in non-component files.
143
+ 3. **Token refs** — `VX.*` are just `var(--vx-*)` strings (colors) plus non-color sizing constants.
144
+ Opacity via `alpha(token, a)` (= `color-mix`), **never** `rgba()` — the hue must keep resolving
145
+ per scheme.
146
+
147
+ Hard rules (the guard enforces these, not just prose):
148
+
149
+ - **Never a raw hex / `rgb()` / `hsl()` in chart or app source.** Route every color through
150
+ `VX.*` / the palette. `basalt-ui check-theme` fails the build on a literal; a `theme-allow` comment
151
+ is the only deliberate exception.
152
+ - **Never `localStorage.getItem('theme')`.** The scheme resolves via Mantine's color scheme + the
153
+ `--vx-*` vars. The guard bans this read.
154
+ - New colors go into the palette as `{ light, dark }` pairs — never inline, never two
155
+ `fooLight`/`fooDark` keys.
156
+
157
+ ```ts
158
+ import { VX, alpha } from 'basalt-ui/tokens'
159
+ import { SERIES } from '../lib/series' // consumer-owned — see /basalt-charts
160
+
161
+ const stroke = SERIES.hrv // app-side series ref (consumer-defined — see /basalt-charts)
162
+ const fill = alpha(SERIES.hrv, 0.12) // theme-aware soft area, NOT rgba()
163
+ const grid = VX.grid // framework neutral
164
+ ```
165
+
166
+ ## Drive the theme-lab loop (tune by eye, then bake)
167
+
168
+ Static HTML POCs do not translate 1:1 to visx/Mantine. Tune in the **real app** with the shipped
169
+ theme lab (`basalt-ui/theme-lab`), then bake the values into the palette. The lab writes overrides
170
+ as inline `--vx-*` styles on `<html>`, which beat the stylesheet's per-scheme rules — so everything
171
+ restyles **instantly with no React re-render**.
172
+
173
+ Wire it (DEV-only) inside a dev dock popover:
174
+
175
+ ```tsx
176
+ import { ThemeLabControls, applyOverrides, loadOverrides } from 'basalt-ui/theme-lab'
177
+
178
+ // At boot — re-apply a persisted tuning session (the control body does NOT do the initial apply):
179
+ applyOverrides(loadOverrides())
180
+
181
+ // In the dev dock — pass the consumer's own series groups so they're tunable too:
182
+ <ThemeLabControls
183
+ groups={[
184
+ ...COLOR_GROUPS, // framework: Semantic / Status / Neutral / Surface
185
+ { title: 'Health', items: [{ var: '--vx-hrv', label: 'HRV' }, /* ... */] },
186
+ ]}
187
+ onCopy={(json) => notifications.show({ message: 'Overrides copied' })}
188
+ copyIcon={<IconCopy size={16} />} // framework ships no icon/notification dep
189
+ resetIcon={<IconRefresh size={16} />}
190
+ />
191
+ ```
192
+
193
+ The loop:
194
+
195
+ 1. Open the lab, adjust `--vx-*` colors and the area-gradient strength (`--vx-area-top` /
196
+ `--vx-area-bottom`) by eye, in both schemes.
197
+ 2. Toggle the Mantine color scheme and re-check: saturated mid-tones **glow/bleed on dark** — step
198
+ one shade lighter and slightly desaturated; on light go one shade deeper for contrast. Same hue,
199
+ different shade — **never the same hex in both**.
200
+ 3. **Copy JSON** → hand the values back into the palette data as `{ light, dark }` pairs.
201
+ 4. Remove the override (or "Reset to palette defaults") and confirm the baked palette matches.
202
+
203
+ The lab is a tuning sandbox, not a prod theme editor: inline overrides apply to whatever scheme is
204
+ on screen and win over both light and dark rules. It is the closing step of design, not a shipped
205
+ feature.
206
+
207
+ ## Primitives + kind discipline (don't loosen, extend)
208
+
209
+ Every chart composes the shipped primitives — never hand-rolled equivalents:
210
+
211
+ - **`ChartCard`** wrapper (title + info-tooltip + extra slot, consistent margin).
212
+ - **`ChartLegend`** (`line | bar | split | splitLine` shapes) — never hand-rolled legend markup.
213
+ - **`ChartTooltip`** + `TooltipHeader` / `TooltipRow` / `TooltipBody` — never import `@visx/tooltip`
214
+ directly (oxlint bans it in chart files).
215
+ - **`AxisBottomDate`** / **`AxisLeftNumeric`** / **`AxisRightNumeric`** — never raw
216
+ `<AxisLeft>`/`<AxisBottom>` (they miss theme tokens + smart ticks). Now lint-enforced:
217
+ `basalt-ui check-theme`'s `raw-visx-axis` guard fails the build on a raw axis inside a `/charts/`
218
+ file (escape via `theme-allow`).
219
+ - **`HoverOverlay`** + `HoverContext` + `useChartTooltip` for hover/crosshair. Wrap a group of
220
+ date-aligned charts in **`ChartHoverSync`** to cast a ghost crosshair across all siblings on hover
221
+ (without it, `useHoverSync` runs per-chart only and warns in dev).
222
+ - **`AreaGradient`** / `areaFillUrl` for the soft single-hue fill.
223
+
224
+ Shipped kinds beyond `ZonedLine` / `Bars` / `StackedArea` / `Donut`: **`MultiLine`** (N series on a
225
+ shared y-axis, legend-hover dimming, dashed MA companions, per-point markers, zones/refLines, fixed
226
+ or auto domain — also z-score/σ via a symmetric domain + zero refLine), **`DualPanel`** (line pane
227
+
228
+ - signed-histogram pane on one x-scale and cursor, optional fill-between), **`Heatmap`**
229
+ (category×category intensity grid with per-cell tooltip + optional gradient legend strip).
230
+
231
+ > If the new chart does not fit the primitives, **add a kind — don't loosen the primitives.**
232
+ > Recurring shape → extract a kind via the Rule of Three. Genuinely unique → stay bespoke,
233
+ > composing primitives directly. New color → a `{ light, dark }` pair in the palette, wired through
234
+ > `--vx-*`, exposed as a `VX.*` ref — never an inline hex. The mechanics of all three live in
235
+ > **`/basalt-charts`** — defer to it for the "how".
236
+
237
+ The Mantine-free boundary holds here too: `./charts` and `./tokens` import zero `@mantine/*`, and
238
+ `@visx/*` is only allowed under chart files. Both are oxlint-enforced in the shipped consumer
239
+ preset.
240
+
241
+ ## Checklist before declaring a chart "done"
242
+
243
+ - Every color comes from a token (`VX.*` / palette) — `basalt-ui check-theme` green, zero raw hex.
244
+ - One hue per metric; categorical multi-color only where the data is genuinely categorical.
245
+ - Neutral line/axis/grid; soft `AreaGradient` on plain metric lines, opaque stacked-area bands.
246
+ - Tooltip = `ChartCard` / `ChartTooltip` primitives, one swatch per row — no hand-rolled markup.
247
+ - Looks right in BOTH schemes (toggled and checked: glow on dark, contrast on light).
248
+ - New colors landed as `{ light, dark }` pairs in the palette, not inline.
249
+ - Nothing reads `localStorage.getItem('theme')`.
@@ -1,8 +1,9 @@
1
1
  <!-- basalt:begin {{BASALT_VERSION}} -->
2
+
2
3
  ## basalt-ui (managed — do not hand-edit)
3
4
 
4
- Scaffolded by `bunx basalt init` and refreshed by `bunx basalt sync` (run it after a basalt-ui
5
- upgrade; `basalt sync --check` gates drift in CI). This block is framework-owned — edit `DESIGN.md`
5
+ Scaffolded by `bunx basalt-ui init` and refreshed by `bunx basalt-ui sync` (run it after a basalt-ui
6
+ upgrade; `basalt-ui sync --check` gates drift in CI). This block is framework-owned — edit `DESIGN.md`
6
7
  or the `basalt-*` rules instead; manual changes here are overwritten on the next sync.
7
8
 
8
9
  **Stack:** React 19 + Mantine v9, themed by `basalt-ui` (`BasaltProvider` + `createBasaltTheme`).
@@ -11,17 +12,18 @@ never a raw hex/`rgb()`/`hsl()`. Charts are visx via `basalt-ui/charts` (compose
11
12
  `ChartCard`, `ChartLegend`, the `ChartTooltip` family, `AxisLeftNumeric`/`AxisBottomDate`); add a
12
13
  kind on the third repeat, don't loosen the primitives. `basalt-ui/charts` and `basalt-ui/tokens`
13
14
  are Mantine-free — never import `@mantine/*` under `**/charts/**`, never import `@visx/*` outside
14
- charts. Toolchain is oxlint + oxfmt (no ESLint/Biome/Prettier) and `basalt check-theme` guards the
15
+ charts. Toolchain is oxlint + oxfmt (no ESLint/Biome/Prettier) and `basalt-ui check-theme` guards the
15
16
  palette. Runtime is Bun.
16
17
 
17
18
  **Before guessing an import, check the installed package's machine docs**:
18
19
  `node_modules/basalt-ui/llms.txt` (per-subpath import map), `node_modules/basalt-ui/AGENTS.md`, or
19
- run `bunx basalt info --json`.
20
+ run `bunx basalt-ui info --json`.
20
21
 
21
22
  **DESIGN.md is law.** `./DESIGN.md` (imported below) records this app's palette identity and series
22
23
  dictionary. Precedence: **DESIGN.md > `basalt-*` rules > skills.** When building or restyling any
23
24
  UI, that law wins over habit, over library defaults, and over a skill's instinct. The design/charts
24
- workflows are in the `basalt` plugin (`/basalt:design`, `/basalt:charts`) — they defer to DESIGN.md.
25
+ workflows are the managed skills in `.claude/skills/` (`/basalt-design`, `/basalt-charts`) — they
26
+ defer to DESIGN.md.
25
27
 
26
28
  @./DESIGN.md
27
29
 
@@ -32,4 +34,5 @@ three-font system (Nunito Sans body, Hubot Sans condensed headings, JetBrains Mo
32
34
  numeral/micro-label), depth via `shadow-card` (a whisper shadow + 1px ring, never a decorative drop
33
35
  shadow), neutral zinc-by-default with the single saturated accent spent only when earned (trend /
34
36
  signal / categorical separation). Restraint **is** the identity.
37
+
35
38
  <!-- basalt:end -->
@@ -2,7 +2,7 @@
2
2
  * TanStack Router root route — wires QueryClient into the router context so
3
3
  * loader functions and components can call `Route.useRouteContext()`.
4
4
  *
5
- * Scaffold written by `basalt init`. This file is yours — `basalt sync` will not overwrite it.
5
+ * Scaffold written by `basalt-ui init`. This file is yours — `basalt-ui sync` will not overwrite it.
6
6
  */
7
7
  import { Outlet, createRootRouteWithContext } from '@tanstack/react-router'
8
8
  import type { QueryClient } from '@tanstack/react-query'
@@ -2,7 +2,7 @@
2
2
  * Basalt query client — configure once, share via router context.
3
3
  * Extend staleTime / gcTime defaults and add per-query error handling here.
4
4
  *
5
- * Scaffold written by `basalt init`. This file is yours — `basalt sync` will not overwrite it.
5
+ * Scaffold written by `basalt-ui init`. This file is yours — `basalt-ui sync` will not overwrite it.
6
6
  */
7
7
  import { createBasaltQueryClient } from 'basalt-ui/query'
8
8
 
package/configs/check.yml CHANGED
@@ -1,10 +1,10 @@
1
- # basalt-ui consumer CI template — placed at .github/workflows/check.yml by `basalt init`
2
- # (kept fresh by `basalt sync`). Mirrors the basalt-ui gate order: frozen install ->
3
- # lint + theme guard -> format check -> doctrine drift gate.
4
- # `basalt check-theme` is the palette guard shipped by basalt-ui (fails on raw
1
+ # basalt-ui consumer CI seed — placed at .github/workflows/check.yml by `basalt-ui init`,
2
+ # then owned by the consumer (sync never touches it again). Mirrors the basalt-ui gate
3
+ # order: frozen install -> lint + theme guard -> doctrine drift gate -> format check.
4
+ # `basalt-ui check-theme` is the palette guard shipped by basalt-ui (fails on raw
5
5
  # color literals / off-identity accents that bypass the --vx-* token system).
6
- # `basalt sync --check` fails when the basalt-managed files (rules, CLAUDE block,
7
- # toolchain templates) have drifted from the installed basalt-ui version.
6
+ # `basalt-ui sync --check` fails when the basalt-managed files (rules, skills, the
7
+ # CLAUDE block) have drifted from the installed basalt-ui version.
8
8
  name: check
9
9
  on:
10
10
  pull_request:
@@ -21,8 +21,8 @@ jobs:
21
21
  bun-version: latest
22
22
  - run: bun install --frozen-lockfile
23
23
  - run: bunx oxlint .
24
- - run: bunx basalt check-theme
25
- - run: bunx basalt sync --check
24
+ - run: bunx basalt-ui check-theme
25
+ - run: bunx basalt-ui sync --check
26
26
  - run: bunx oxfmt 'src/**' '!**/dist/**' --check
27
27
  # Enable once your app defines these package.json scripts:
28
28
  # - run: bun run typecheck
@@ -1,7 +1,11 @@
1
- # basalt-ui consumer lefthook template.
2
- # Copy to your repo root as lefthook.yml. Runs oxlint + oxfmt on staged files and the
3
- # theme guard on the whole tree, pre-commit. Assumes oxlint/oxfmt are installed and your
4
- # .oxlintrc.json extends ./node_modules/basalt-ui/configs/oxlint.json.
1
+ # basalt-ui consumer lefthook preset — an `extends` target, not a copy.
2
+ # `basalt-ui init` seeds a lefthook.yml that references this file:
3
+ # extends:
4
+ # - node_modules/basalt-ui/configs/lefthook.yml
5
+ # lefthook merges these commands with the consumer's own, so this preset auto-updates
6
+ # with the package. Runs oxlint + oxfmt on staged files and the theme guard on the whole
7
+ # tree, pre-commit. Assumes oxlint/oxfmt are installed and your .oxlintrc.json extends
8
+ # ./node_modules/basalt-ui/configs/oxlint.json.
5
9
  pre-commit:
6
10
  parallel: true
7
11
  commands:
@@ -18,4 +22,4 @@ pre-commit:
18
22
  # ran are indistinguishable from the kinds that found nothing.
19
23
  check-theme:
20
24
  glob: '*.{ts,tsx}'
21
- run: bunx basalt check-theme
25
+ run: bunx basalt-ui check-theme
@@ -1,15 +1,17 @@
1
1
  // oxlint-disable import/no-default-export -- oxlint's JS plugin loader requires a default export
2
2
  /**
3
3
  * basalt — the shipped oxlint JS plugin (alpha `jsPlugins`, ESLint-v9-compatible `create(context)`
4
- * API). Three design-guard AST rules steering consumers onto the token/idiom system that
5
- * `src/guard` (the regex-based `check-theme` CLI) cannot see from a raw-text scan alone.
4
+ * API). Design-guard AST rules steering consumers onto the token/idiom system that `src/guard`
5
+ * (the regex-based `check-theme` CLI) cannot see from a raw-text scan alone, plus the
6
+ * `import-boundary` rule enforcing basalt's architecture boundaries (see below).
6
7
  *
7
8
  * Ships inside `configs/` so the shipped preset (`configs/oxlint.json`) can reference it as
8
9
  * `./oxlint-plugin.js` — a consumer `extends`-ing that preset inherits `jsPlugins` too, and the
9
10
  * path resolves relative to the preset file, not the consumer's own config.
10
11
  *
11
- * Every rule supports the same `theme-allow` escape as `src/guard`: skip a reported node if a line
12
- * comment containing `theme-allow` sits on the node's own line or the line immediately above it.
12
+ * The four design-guard rules below support the same `theme-allow` escape as `src/guard`: skip a
13
+ * reported node if a line comment containing `theme-allow` sits on the node's own line or the line
14
+ * immediately above it. `import-boundary` deliberately does NOT — see its own comment for why.
13
15
  *
14
16
  * ── About the shipped `configs/oxlint.json` preset ────────────────────────────────────────────
15
17
  * Consumers extend it from their own `.oxlintrc.json` via the node_modules-relative path:
@@ -17,9 +19,14 @@
17
19
  * specifiers, so the relative `./node_modules` path is required. NOTE: oxlint `extends` is
18
20
  * per-glob last-writer-wins for `no-restricted-imports` — a base ban does NOT merge into an
19
21
  * override glob, so any ban that must also hold inside an override is duplicated into that
20
- * override. `configs/oxlint.json` is generated from `SURFACES` by `scripts/gen-oxlint.ts`
21
- * (`--check` is the CI drift gate) — its top-level keys are limited to what oxlint's own parser
22
- * accepts (see `ALLOWED_TOP_LEVEL_KEYS` in that script); do not add ad hoc keys to that file.
22
+ * override, AND a consumer's own `no-restricted-imports` override on an overlapping glob silently
23
+ * REPLACES basalt's ban rather than merging with it. That is exactly why the `@visx/*`-only-in-
24
+ * charts and Mantine-free charts/tokens boundaries live in the `import-boundary` rule below instead
25
+ * of `no-restricted-imports`: a jsPlugin rule has its own rule id, so a consumer can only turn it
26
+ * off explicitly, by name — never silently. `configs/oxlint.json` is generated from `SURFACES` by
27
+ * `scripts/gen-oxlint.ts` (`--check` is the CI drift gate) — its top-level keys are limited to what
28
+ * oxlint's own parser accepts (see `ALLOWED_TOP_LEVEL_KEYS` in that script); do not add ad hoc keys
29
+ * to that file.
23
30
  */
24
31
 
25
32
  // ── Shared helpers ──────────────────────────────────────────────────────────────────────────────
@@ -256,6 +263,110 @@ const rawScrollContainer = {
256
263
  },
257
264
  }
258
265
 
266
+ // ── Rule 5 — import-boundary ────────────────────────────────────────────────────────────────────
267
+
268
+ // Message bodies mirror the wording that used to live in the shipped `no-restricted-imports`
269
+ // overrides (configs/oxlint.json) verbatim, so the DX doesn't regress.
270
+ const IMPORT_BOUNDARY_MESSAGES = {
271
+ visxOutsideCharts:
272
+ 'Direct @visx/* imports are only allowed inside the charts boundary (**/charts/**). ' +
273
+ '(basalt/import-boundary)',
274
+ visxTooltip:
275
+ 'Use ChartTooltip + TooltipHeader/Row/Body from basalt-ui charts primitives. ' +
276
+ '(basalt/import-boundary)',
277
+ mantineInCharts:
278
+ 'charts must be Mantine-free — no Mantine imports allowed. (basalt/import-boundary)',
279
+ mantineInTokens:
280
+ 'tokens must be Mantine-free — no Mantine imports allowed. (basalt/import-boundary)',
281
+ }
282
+
283
+ /** True when any path segment of `filename` equals `segment` (POSIX or Windows separators). */
284
+ function hasPathSegment(filename, segment) {
285
+ return filename.split(/[\\/]/).includes(segment)
286
+ }
287
+
288
+ /** Import specifier for an ImportDeclaration or a dynamic `import()` call; undefined otherwise. */
289
+ function importSource(node) {
290
+ if (node.type === 'ImportDeclaration') return node.source?.value
291
+ if (node.type === 'ImportExpression' && node.source?.type === 'Literal') {
292
+ return node.source.value
293
+ }
294
+ return undefined
295
+ }
296
+
297
+ /**
298
+ * Import specifier for a source-bearing export (`export { x } from '…'` / `export * from '…'`);
299
+ * undefined for a plain local `export { x }` (no `source`) or any other node shape.
300
+ */
301
+ function exportSource(node) {
302
+ if (node.type === 'ExportNamedDeclaration' || node.type === 'ExportAllDeclaration') {
303
+ return node.source?.value
304
+ }
305
+ return undefined
306
+ }
307
+
308
+ const importBoundary = {
309
+ meta: {
310
+ type: 'suggestion',
311
+ docs: {
312
+ description:
313
+ 'Enforce the @visx/*-only-in-charts and Mantine-free charts/tokens import boundaries.',
314
+ },
315
+ schema: [],
316
+ },
317
+ create(context) {
318
+ const filename = getFilename(context)
319
+ const inCharts = hasPathSegment(filename, 'charts')
320
+ const inTokens = hasPathSegment(filename, 'tokens')
321
+
322
+ // Deliberately NO `hasThemeAllow` escape here (unlike the four design-guard rules above).
323
+ // `theme-allow` exists so the theme/palette source can opt out of DESIGN guidance (raw font
324
+ // sizes, raw colors) — it is not a license to punch through an ARCHITECTURE boundary. The whole
325
+ // point of moving this check into a plugin rule instead of `no-restricted-imports` was that it
326
+ // can only be turned off explicitly, by rule id (see the file-header comment); a stray
327
+ // `theme-allow` comment (which also matches the line above the flagged node) must not silently
328
+ // bypass it. Do not "restore consistency" by adding it back.
329
+ function reportFor(node, source) {
330
+ if (typeof source !== 'string') return
331
+
332
+ if (source === '@visx/tooltip') {
333
+ context.report({ node, message: IMPORT_BOUNDARY_MESSAGES.visxTooltip })
334
+ return
335
+ }
336
+ if (source.startsWith('@visx/')) {
337
+ if (!inCharts) context.report({ node, message: IMPORT_BOUNDARY_MESSAGES.visxOutsideCharts })
338
+ return
339
+ }
340
+ if (
341
+ source === '@mantine/core' ||
342
+ source === '@mantine/hooks' ||
343
+ source.startsWith('@mantine/')
344
+ ) {
345
+ if (inCharts) {
346
+ context.report({ node, message: IMPORT_BOUNDARY_MESSAGES.mantineInCharts })
347
+ } else if (inTokens) {
348
+ context.report({ node, message: IMPORT_BOUNDARY_MESSAGES.mantineInTokens })
349
+ }
350
+ }
351
+ }
352
+
353
+ return {
354
+ ImportDeclaration(node) {
355
+ reportFor(node, importSource(node))
356
+ },
357
+ ImportExpression(node) {
358
+ reportFor(node, importSource(node))
359
+ },
360
+ ExportNamedDeclaration(node) {
361
+ reportFor(node, exportSource(node))
362
+ },
363
+ ExportAllDeclaration(node) {
364
+ reportFor(node, exportSource(node))
365
+ },
366
+ }
367
+ },
368
+ }
369
+
259
370
  // ── Plugin export ───────────────────────────────────────────────────────────────────────────────
260
371
 
261
372
  export default {
@@ -265,5 +376,6 @@ export default {
265
376
  'card-inset': cardInset,
266
377
  'chart-in-raw-surface': chartInRawSurface,
267
378
  'raw-scroll-container': rawScrollContainer,
379
+ 'import-boundary': importBoundary,
268
380
  },
269
381
  }
@@ -8,9 +8,9 @@
8
8
  * and returns the parsed set of `basalt/<rule>` diagnostics it printed.
9
9
  */
10
10
  import { afterEach, beforeEach, describe, expect, it } from 'bun:test'
11
- import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
11
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
12
12
  import { tmpdir } from 'node:os'
13
- import { resolve } from 'node:path'
13
+ import { dirname, resolve } from 'node:path'
14
14
 
15
15
  const PLUGIN_PATH = resolve(import.meta.dirname, 'oxlint-plugin.js')
16
16
  const OXLINT_BIN = resolve(import.meta.dirname, '..', '..', '..', 'node_modules', '.bin', 'oxlint')
@@ -28,6 +28,7 @@ beforeEach(() => {
28
28
  'basalt/no-raw-font-size': 'error',
29
29
  'basalt/card-inset': 'error',
30
30
  'basalt/chart-in-raw-surface': 'error',
31
+ 'basalt/import-boundary': 'error',
31
32
  },
32
33
  }),
33
34
  )
@@ -39,7 +40,9 @@ afterEach(() => {
39
40
 
40
41
  /** Writes `source` as the sole fixture file and runs oxlint against the temp fixture repo. */
41
42
  function run(source: string, filename = 'fixture.tsx'): { code: number; rules: Set<string> } {
42
- writeFileSync(resolve(dir, filename), source)
43
+ const filePath = resolve(dir, filename)
44
+ mkdirSync(dirname(filePath), { recursive: true })
45
+ writeFileSync(filePath, source)
43
46
  const result = Bun.spawnSync([OXLINT_BIN, '-c', '.oxlintrc.json', filename], { cwd: dir })
44
47
  const output = `${result.stdout}${result.stderr}`
45
48
  const rules = new Set(
@@ -105,3 +108,70 @@ describe('basalt/chart-in-raw-surface', () => {
105
108
  expect(rules).not.toContain('chart-in-raw-surface')
106
109
  })
107
110
  })
111
+
112
+ // ── import-boundary ────────────────────────────────────────────────────────────
113
+
114
+ describe('basalt/import-boundary', () => {
115
+ it('flags a @visx/* import outside charts', () => {
116
+ const { code, rules } = run(`import { scaleLinear } from '@visx/scale'\n`, 'lib.ts')
117
+ expect(code).toBe(1)
118
+ expect(rules).toContain('import-boundary')
119
+ })
120
+
121
+ it('does NOT flag a @visx/* import inside charts', () => {
122
+ const { code, rules } = run(`import { scaleLinear } from '@visx/scale'\n`, 'charts/lib.ts')
123
+ expect(code).toBe(0)
124
+ expect(rules).not.toContain('import-boundary')
125
+ })
126
+
127
+ it('flags a @mantine/* import inside charts (Mantine-free)', () => {
128
+ const { code, rules } = run(`import { Button } from '@mantine/core'\n`, 'charts/lib.tsx')
129
+ expect(code).toBe(1)
130
+ expect(rules).toContain('import-boundary')
131
+ })
132
+
133
+ it('does NOT flag a @mantine/* import outside charts/tokens', () => {
134
+ const { code, rules } = run(`import { Button } from '@mantine/core'\n`, 'lib.tsx')
135
+ expect(code).toBe(0)
136
+ expect(rules).not.toContain('import-boundary')
137
+ })
138
+
139
+ it('flags @visx/tooltip even inside charts', () => {
140
+ const { code, rules } = run(`import { Tooltip } from '@visx/tooltip'\n`, 'charts/lib.tsx')
141
+ expect(code).toBe(1)
142
+ expect(rules).toContain('import-boundary')
143
+ })
144
+
145
+ it('flags a @mantine/* import inside tokens (Mantine-free)', () => {
146
+ const { code, rules } = run(`import { Button } from '@mantine/core'\n`, 'tokens/lib.ts')
147
+ expect(code).toBe(1)
148
+ expect(rules).toContain('import-boundary')
149
+ })
150
+
151
+ it('still flags a @visx/* import outside charts carrying a theme-allow comment (no escape hatch)', () => {
152
+ const { code, rules } = run(
153
+ `// theme-allow: legacy\nimport { scaleLinear } from '@visx/scale'\n`,
154
+ 'lib.ts',
155
+ )
156
+ expect(code).toBe(1)
157
+ expect(rules).toContain('import-boundary')
158
+ })
159
+
160
+ it('flags a source-bearing named re-export of @visx/* outside charts', () => {
161
+ const { code, rules } = run(`export { scaleLinear } from '@visx/scale'\n`, 'lib.ts')
162
+ expect(code).toBe(1)
163
+ expect(rules).toContain('import-boundary')
164
+ })
165
+
166
+ it('flags a wildcard re-export of @visx/* outside charts', () => {
167
+ const { code, rules } = run(`export * from '@visx/scale'\n`, 'lib.ts')
168
+ expect(code).toBe(1)
169
+ expect(rules).toContain('import-boundary')
170
+ })
171
+
172
+ it('does NOT flag a plain local named export (no source)', () => {
173
+ const { code, rules } = run(`const x = 1\nexport { x }\n`, 'lib.ts')
174
+ expect(code).toBe(0)
175
+ expect(rules).not.toContain('import-boundary')
176
+ })
177
+ })