basalt-ui 1.2.0 → 1.4.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.
@@ -8,6 +8,8 @@
8
8
  * src/cli/check-theme.test.ts (temp-dir + exit-code contract).
9
9
  */
10
10
  import { describe, expect, it } from 'bun:test'
11
+ import { pxRem } from '../tokens'
12
+ import { SPACE_SCALE } from '../tokens/palette'
11
13
  import { checkSource, DEFAULT_GUARD_CONFIG } from './index'
12
14
  import type { Finding, GuardKind } from './types'
13
15
 
@@ -155,17 +157,15 @@ describe('off-identity-accent', () => {
155
157
  // ── 5. raw-spacing ───────────────────────────────────────────────────────────
156
158
 
157
159
  describe('raw-spacing', () => {
158
- it('flags p={16} (default spacing step)', () => {
159
- const f = find(`<Box p={16} />`)
160
- expect(kinds(f)).toContain('raw-spacing')
160
+ // Interpolated from the real scale, never typed as literals: the previous versions of these tests
161
+ // hardcoded 16 and 12 and so PASSED against a guard whose step list had gone stale — they encoded
162
+ // the drift instead of catching it.
163
+ it('flags a prop value equal to a scale step', () => {
164
+ expect(kinds(find(`<Box p={${SPACE_SCALE.md}} />`))).toContain('raw-spacing')
165
+ expect(kinds(find(`<Stack gap={${SPACE_SCALE.sm}} />`))).toContain('raw-spacing')
161
166
  })
162
167
 
163
- it('flags gap={12}', () => {
164
- const f = find(`<Stack gap={12} />`)
165
- expect(kinds(f)).toContain('raw-spacing')
166
- })
167
-
168
- it('does NOT flag p={8} (not a default step)', () => {
168
+ it('does NOT flag p={8} (sub-scale micro-spacing, no token to prefer)', () => {
169
169
  const f = find(`<Box p={8} />`)
170
170
  expect(kinds(f)).not.toContain('raw-spacing')
171
171
  })
@@ -176,7 +176,7 @@ describe('raw-spacing', () => {
176
176
  })
177
177
 
178
178
  it('does NOT flag a theme-allow line', () => {
179
- const f = find(`<Box p={16} /> // theme-allow`)
179
+ const f = find(`<Box p={${SPACE_SCALE.md}} /> // theme-allow`)
180
180
  expect(kinds(f)).not.toContain('raw-spacing')
181
181
  })
182
182
  })
@@ -1132,13 +1132,112 @@ describe('CSS applicability', () => {
1132
1132
 
1133
1133
  it('still flags inline-spacing on a genuine CSS padding/margin/gap declaration (the pattern is CSS-shaped, not JSX-only, despite the name)', () => {
1134
1134
  const f = checkSource(
1135
- '.foo {\n padding: 8px;\n margin: 4px;\n gap: 8px;\n}\n',
1135
+ '.foo {\n padding: 18px;\n margin: 13px;\n gap: 26px;\n}\n',
1136
1136
  'src/Card.module.css',
1137
1137
  DEFAULT_GUARD_CONFIG,
1138
1138
  )
1139
1139
  expect(kinds(f).filter((k) => k === 'inline-spacing')).toHaveLength(3)
1140
1140
  })
1141
1141
 
1142
+ // ── The CSS-only sub-scale escape ───────────────────────────────────────────
1143
+ //
1144
+ // basalt-tokens.md blesses 2-8px micro-spacing raw, but that permission only ever held for JSX
1145
+ // PROPS: `pl={4}` is not a `prop: value` pair and never matched the pattern. In CSS every
1146
+ // declaration is `prop: value`, so a consumer's 4px cluster gap was flagged with nothing legal to
1147
+ // do about it — no token exists below the scale floor, and `exemptRules` matches whole path
1148
+ // segments so it cannot express `*.module.css`.
1149
+
1150
+ const cssSpacing = (decl: string): GuardKind[] =>
1151
+ kinds(
1152
+ checkSource(`.foo {\n ${decl};\n}\n`, 'src/Card.module.css', DEFAULT_GUARD_CONFIG),
1153
+ ).filter((k) => k === 'inline-spacing')
1154
+
1155
+ it('does NOT flag sub-scale micro-spacing in CSS — there is no token to prefer below the floor', () => {
1156
+ for (const decl of ['gap: 2px', 'padding: 4px', 'margin-bottom: 6px', 'padding: 8px']) {
1157
+ expect(cssSpacing(decl)).toEqual([])
1158
+ }
1159
+ })
1160
+
1161
+ it('judges a multi-value shorthand as a whole', () => {
1162
+ expect(cssSpacing('padding: 4px 8px')).toEqual([])
1163
+ // 16px has a scale stop; one non-micro component makes the whole declaration a finding.
1164
+ expect(cssSpacing('padding: 4px 16px')).toEqual(['inline-spacing'])
1165
+ })
1166
+
1167
+ it('drops var() components before judging — a mixed value is already tokenized where it counts', () => {
1168
+ expect(cssSpacing('padding: 4px var(--vx-space-stack-xs)')).toEqual([])
1169
+ })
1170
+
1171
+ it('does not extend the escape to other units — the doctrine is stated in px', () => {
1172
+ expect(cssSpacing('padding: 1.5rem')).toEqual(['inline-spacing'])
1173
+ expect(cssSpacing('padding: 2em')).toEqual(['inline-spacing'])
1174
+ })
1175
+
1176
+ it('reads a CSS number without its integer part, and one carrying an explicit +', () => {
1177
+ // `.75rem` IS `0.75rem` and `+12px` IS `12px`. Requiring a leading digit skipped both — the
1178
+ // same silent skip the `0.` guard was fixed for, one spelling over.
1179
+ expect(cssSpacing('padding: .75rem')).toEqual(['inline-spacing'])
1180
+ expect(cssSpacing('padding: +12px')).toEqual(['inline-spacing'])
1181
+ // …and the sub-scale escape resolves them the same way: .5rem is 8px, below the floor.
1182
+ expect(cssSpacing('padding: .5rem')).toEqual([])
1183
+ })
1184
+
1185
+ it('does NOT read a custom property whose NAME ends in a spacing word', () => {
1186
+ // A `\b` boundary sits inside a hyphenated identifier, so these matched as declarations. The
1187
+ // first is real generated output from the token layer; the second is the shape a consumer
1188
+ // writes. A custom property is a definition, not a rendered spacing decision.
1189
+ expect(cssSpacing('--vx-space-article-header-padding-bottom: 20px')).toEqual([])
1190
+ expect(cssSpacing('--card-padding-inline: 20px')).toEqual([])
1191
+ expect(cssSpacing('--card-gap: 20px')).toEqual([])
1192
+ // The declaration itself still flags — the fix narrows the boundary, it does not disarm it.
1193
+ expect(cssSpacing('padding-bottom: 20px')).toEqual(['inline-spacing'])
1194
+ expect(cssSpacing('padding-inline: 20px')).toEqual(['inline-spacing'])
1195
+ })
1196
+
1197
+ it('stays case-sensitive — neither dialect spells a property `Padding-Top`', () => {
1198
+ // Pins the decision documented above BOX_SIDE_KEBAB: unifying the two spellings with an `i`
1199
+ // flag would be the short way and would also match casings that are not properties at all.
1200
+ expect(cssSpacing('Padding-Top: 18px')).toEqual([])
1201
+ expect(cssSpacing('PADDING: 18px')).toEqual([])
1202
+ })
1203
+
1204
+ it('keeps the default spacing steps in lockstep with the real scale', () => {
1205
+ // The guard's copy of the xs..xl ladder drifted once already (it still read 10/12/16/20/32
1206
+ // after the level-0 retune, so `p={16}` was flagged in favour of a `p="md"` worth 18, and the
1207
+ // genuine `p={18}` went unflagged). The copy exists to keep the headless core one file; this
1208
+ // asserts it stays honest.
1209
+ expect(DEFAULT_GUARD_CONFIG.spacingSteps).toEqual(Object.values(SPACE_SCALE))
1210
+ })
1211
+
1212
+ it('resolves rem against the same root the token layer converts against', () => {
1213
+ // The guard keeps its own copy of the 16px root to stay dependency-free. The spacing-steps copy
1214
+ // beside it drifted in production once; this pins the relationship rather than the number, so a
1215
+ // token layer that ever moved off a 16px root would fail here instead of silently disagreeing.
1216
+ // 10px is the ceiling; 12px is the first value above it. Expressed through `pxRem` so the
1217
+ // literals here follow the token layer's conversion rather than restating it.
1218
+ expect(cssSpacing(`padding: ${pxRem(10)}`)).toEqual([])
1219
+ expect(cssSpacing(`padding: ${pxRem(12)}`)).toEqual(['inline-spacing'])
1220
+ // The px spellings of the same two values must land identically.
1221
+ expect(cssSpacing('padding: 10px')).toEqual([])
1222
+ expect(cssSpacing('padding: 12px')).toEqual(['inline-spacing'])
1223
+ })
1224
+
1225
+ it('keeps the ceiling below the smallest scale stop, so it can never strand a real token', () => {
1226
+ // The relationship, not the number: if a density retune moves SPACE_SCALE.xs, this still holds.
1227
+ expect(cssSpacing(`gap: ${SPACE_SCALE.xs}px`)).toEqual(['inline-spacing'])
1228
+ expect(cssSpacing(`gap: ${SPACE_SCALE.xs - 1}px`)).toEqual([])
1229
+ })
1230
+
1231
+ it('leaves TSX untouched — an inline style object still has a prop form to prefer', () => {
1232
+ // `pl={4}` is a prop and never matched; `style={{ padding: 4 }}` did, and still should.
1233
+ expect(
1234
+ kinds(checkSource('<Box style={{ padding: 4 }} />', PATH, DEFAULT_GUARD_CONFIG)),
1235
+ ).toContain('inline-spacing')
1236
+ expect(kinds(checkSource('<Box pl={4} />', PATH, DEFAULT_GUARD_CONFIG))).not.toContain(
1237
+ 'inline-spacing',
1238
+ )
1239
+ })
1240
+
1142
1241
  it('does NOT false-positive raw-form-control on a CSS element selector (input, select, textarea)', () => {
1143
1242
  const f = checkSource(
1144
1243
  'input, select, textarea {\n color: red;\n}\n',
@@ -1179,6 +1278,79 @@ describe('CSS applicability', () => {
1179
1278
  )
1180
1279
  expect(kinds(f)).not.toContain('localstorage-theme')
1181
1280
  })
1281
+
1282
+ // ── Kebab longhands and logical properties ──────────────────────────────────
1283
+ //
1284
+ // The alternation was camelCase-only, so a CSS module got the scan for `padding` and not for
1285
+ // `padding-top` beside it. Nothing decided that; it fell out of a pattern written for TSX inline
1286
+ // styles. Logical properties are included because that is what modern CSS in this repo writes.
1287
+
1288
+ it('flags kebab longhands at scale values', () => {
1289
+ expect(cssSpacing(`padding-top: ${SPACE_SCALE.md}px`)).toEqual(['inline-spacing'])
1290
+ expect(cssSpacing(`margin-bottom: ${SPACE_SCALE.lg}px`)).toEqual(['inline-spacing'])
1291
+ expect(cssSpacing(`row-gap: ${SPACE_SCALE.lg}px`)).toEqual(['inline-spacing'])
1292
+ expect(cssSpacing(`column-gap: ${SPACE_SCALE.xl}px`)).toEqual(['inline-spacing'])
1293
+ })
1294
+
1295
+ it('flags logical properties, including the -start/-end forms', () => {
1296
+ for (const prop of [
1297
+ 'padding-block',
1298
+ 'padding-inline',
1299
+ 'margin-block',
1300
+ 'margin-inline',
1301
+ 'padding-inline-start',
1302
+ 'margin-block-end',
1303
+ ]) {
1304
+ expect(cssSpacing(`${prop}: ${SPACE_SCALE.xl}px`)).toEqual(['inline-spacing'])
1305
+ }
1306
+ })
1307
+
1308
+ it('extends the sub-scale escape to the longhands too — same rule, both spellings', () => {
1309
+ expect(cssSpacing('padding-top: 4px')).toEqual([])
1310
+ expect(cssSpacing('margin-inline: 8px')).toEqual([])
1311
+ })
1312
+
1313
+ it('flags the camelCase logical properties in a TSX inline style', () => {
1314
+ expect(
1315
+ kinds(checkSource('<Box style={{ paddingInlineStart: 18 }} />', PATH, DEFAULT_GUARD_CONFIG)),
1316
+ ).toContain('inline-spacing')
1317
+ })
1318
+
1319
+ // ── The `0.` blind spot ─────────────────────────────────────────────────────
1320
+ //
1321
+ // The zero-guard was `(?!0\b)`, and `\b` sits between `0` and `.` — so every value starting `0.`
1322
+ // matched the guard meant for a bare zero and dropped out of the scan entirely.
1323
+
1324
+ it('sees values starting `0.` at all', () => {
1325
+ // 12px — a real spacing value that was previously invisible, not merely tolerated.
1326
+ expect(cssSpacing('padding: 0.75rem')).toEqual(['inline-spacing'])
1327
+ })
1328
+
1329
+ it('still excuses a genuine zero', () => {
1330
+ expect(cssSpacing('padding: 0')).toEqual([])
1331
+ expect(cssSpacing('padding: 0px')).toEqual([])
1332
+ })
1333
+
1334
+ it('resolves rem against the 16px root, so both spellings of one value agree', () => {
1335
+ // 0.25rem IS 4px. Accepting one spelling and flagging the other is the same arbitrariness the
1336
+ // kebab gap produced.
1337
+ expect(cssSpacing('padding: 0.25rem')).toEqual([])
1338
+ expect(cssSpacing('padding: 4px')).toEqual([])
1339
+ // The ceiling lands in the same place either way: 0.625rem = 10px, 0.75rem = 12px.
1340
+ expect(cssSpacing('padding: 0.625rem')).toEqual([])
1341
+ expect(cssSpacing('padding: 0.75rem')).toEqual(['inline-spacing'])
1342
+ })
1343
+
1344
+ it('leaves units it cannot resolve without layout context alone', () => {
1345
+ for (const value of ['2em', '5%', '3ch', '2vw']) {
1346
+ expect(cssSpacing(`padding: ${value}`)).toEqual(['inline-spacing'])
1347
+ }
1348
+ })
1349
+
1350
+ it('keeps the mixed-value and var() rules unchanged under the wider pattern', () => {
1351
+ expect(cssSpacing('padding: 4px 16px')).toEqual(['inline-spacing'])
1352
+ expect(cssSpacing('padding-inline: 4px var(--vx-space-stack-xs)')).toEqual([])
1353
+ })
1182
1354
  })
1183
1355
 
1184
1356
  // ── exemptRules — per-rule, per-path guard exemptions ────────────────────────
@@ -1243,3 +1415,44 @@ describe('exemptRules', () => {
1243
1415
  expect(kinds(f)).toContain('raw-html-layout')
1244
1416
  })
1245
1417
  })
1418
+
1419
+ // ── 20. severity ─────────────────────────────────────────────────────────────
1420
+
1421
+ describe('severity', () => {
1422
+ it('stamps every finding, defaulting to error', () => {
1423
+ const f = find(`<Box style={{ color: '#ff0000' }} />`)
1424
+ expect(f.length).toBeGreaterThan(0)
1425
+ expect(f.every((v) => v.severity === 'error')).toBe(true)
1426
+ })
1427
+
1428
+ it('honours a per-kind consumer override without suppressing the finding', () => {
1429
+ // Turning a kind down must still REPORT it — severity is not an off switch. The per-kind
1430
+ // booleans and `exemptRules` are the off switches, and they stay separate on purpose.
1431
+ const cfg = { ...DEFAULT_GUARD_CONFIG, severity: { 'raw-hex': 'warn' as const } }
1432
+ const f = checkSource(`<Box style={{ color: '#ff0000' }} />`, PATH, cfg)
1433
+ const hex = f.filter((v) => v.kind === 'raw-hex')
1434
+ expect(hex).toHaveLength(1)
1435
+ expect(hex[0]?.severity).toBe('warn')
1436
+ })
1437
+
1438
+ it('scopes the override to the named kind only', () => {
1439
+ const cfg = { ...DEFAULT_GUARD_CONFIG, severity: { 'raw-hex': 'warn' as const } }
1440
+ const f = checkSource(`<Box p={${SPACE_SCALE.md}} style={{ color: '#ff0000' }} />`, PATH, cfg)
1441
+ expect(f.find((v) => v.kind === 'raw-hex')?.severity).toBe('warn')
1442
+ expect(f.find((v) => v.kind === 'raw-spacing')?.severity).toBe('error')
1443
+ })
1444
+
1445
+ it('ships no kind in its grace period today', () => {
1446
+ // Every shipped kind is past its grace minor. This is a LEDGER, not a constraint: when a new
1447
+ // kind lands warn-only, this expectation changes in the same commit, and changing it back is
1448
+ // the promotion. A grace entry that outlives its minor shows up here as an unexplained diff.
1449
+ const cfg = DEFAULT_GUARD_CONFIG
1450
+ const everyKind = checkSource(
1451
+ `<Box p={${SPACE_SCALE.md}} radius={4} style={{ color: '#ff0000', gap: 3 }} />`,
1452
+ PATH,
1453
+ cfg,
1454
+ )
1455
+ expect(everyKind.length).toBeGreaterThan(0)
1456
+ expect(everyKind.every((v) => v.severity === 'error')).toBe(true)
1457
+ })
1458
+ })
@@ -170,4 +170,34 @@ describe('evaluateGuardHook', () => {
170
170
  )
171
171
  expect(result.permissionDecision).toBe('deny')
172
172
  })
173
+
174
+ it('allows a write whose only findings are warnings', () => {
175
+ // A grace-minor kind must not block an edit, or the grace period would be the STRICTEST gate
176
+ // in the toolchain: CI green, hook refusing the write.
177
+ const result = evaluateGuardHook(
178
+ {
179
+ tool_name: 'Write',
180
+ tool_input: { file_path: 'src/Page.tsx', file_text: "const c = '#abc123'" },
181
+ },
182
+ { ...DEFAULT_GUARD_CONFIG, severity: { 'raw-hex': 'warn' } },
183
+ )
184
+ expect(result.permissionDecision).toBe('allow')
185
+ })
186
+
187
+ it('denies on the error when a payload mixes warn and error kinds, listing only the error', () => {
188
+ const result = evaluateGuardHook(
189
+ {
190
+ tool_name: 'Write',
191
+ tool_input: {
192
+ file_path: 'src/Page.tsx',
193
+ file_text: "const C = () => <div style={{ color: '#abc123', gap: 12 }} />",
194
+ },
195
+ },
196
+ { ...DEFAULT_GUARD_CONFIG, severity: { 'raw-hex': 'warn' } },
197
+ )
198
+ expect(result.permissionDecision).toBe('deny')
199
+ expect(result.reason).toContain('inline-spacing')
200
+ // The warn-tier kind is absent from the deny reason — it is not what blocked the write.
201
+ expect(result.reason).not.toContain('raw-hex')
202
+ })
173
203
  })
@@ -106,7 +106,12 @@ export function evaluateGuardHook(
106
106
  return { permissionDecision: 'allow' }
107
107
  }
108
108
 
109
- const findings = checkSource(target.text, target.relPath, cfg)
109
+ // Errors only. A `warn` kind is inside its grace minor — it must not block a write, or the
110
+ // grace period would be the strictest gate in the toolchain rather than the softest: `sync` and
111
+ // CI would pass while the PreToolUse hook refused the edit outright.
112
+ const findings = checkSource(target.text, target.relPath, cfg).filter(
113
+ (f) => f.severity === 'error',
114
+ )
110
115
  if (findings.length === 0) return { permissionDecision: 'allow' }
111
116
 
112
117
  const shown = findings.slice(0, 10)
@@ -4,9 +4,9 @@
4
4
  * GUARD_RULES: the closed registry of all 19 violation kinds.
5
5
  * checkSource: pure (text, relPath, cfg) → Finding[]. No FS, no walk, no console.
6
6
  */
7
- import type { Finding, GuardConfig, GuardKind } from './types'
7
+ import type { Finding, GuardConfig, GuardKind, GuardSeverity } from './types'
8
8
 
9
- export type { Finding, GuardConfig, GuardKind }
9
+ export type { Finding, GuardConfig, GuardKind, GuardSeverity }
10
10
 
11
11
  // ── Static regex consts ──────────────────────────────────────────────────────────────────────────
12
12
 
@@ -64,9 +64,88 @@ const INLINE_STYLE = /style=\{\{/
64
64
  const LAYOUT_SURFACE_PROP =
65
65
  /\b(?:display|padding|margin|gap|flex|grid|border|background|width|height)\b/
66
66
 
67
- // Spacing/sizing literals in inline style={{}} — anchored on property name; var() or 0 pass.
68
- const INLINE_SPACING =
69
- /\b(?:padding(?:Top|Bottom|Left|Right)?|margin(?:Top|Bottom|Left|Right)?|gap|rowGap|columnGap)\s*:\s*(?!var\()['"]?-?(?!0\b)\d/g
67
+ // Spacing/sizing literals — anchored on the property name; `var()` and a plain `0` pass.
68
+ //
69
+ // Composed rather than written out because it must cover BOTH spellings of the same property: the
70
+ // camelCase form a TSX inline style uses (`paddingInlineStart`) and the kebab form CSS uses
71
+ // (`padding-inline-start`). Enumerating one and not the other is how `padding: 18px` came to flag in
72
+ // a CSS module while `padding-top: 18px` beside it did not — a distinction shaped by regex history
73
+ // rather than by any decision, and invisible from the author's seat.
74
+ //
75
+ // Case-insensitivity would be the short way to unify them and is deliberately not used: it would
76
+ // also match `Padding`/`PADDING`, neither of which is a property in either dialect.
77
+ const BOX_SIDE = '(?:Top|Bottom|Left|Right|Block|Inline)(?:Start|End)?'
78
+ const BOX_SIDE_KEBAB = '(?:top|bottom|left|right|block|inline)(?:-(?:start|end))?'
79
+ const SPACING_PROP = `(?:padding|margin)(?:${BOX_SIDE}|-${BOX_SIDE_KEBAB})?|gap|rowGap|columnGap|row-gap|column-gap`
80
+ // A bare `0` needs no unit and no token, so it is never a finding — but the guard for it has to
81
+ // stop at the zero ITSELF. `(?!0\b)` did not: `\b` sits between `0` and `.`, so every value
82
+ // starting `0.` matched the guard and dropped out of the scan entirely. `0.75rem` is 12px, a real
83
+ // spacing value, and it was invisible. `(?!0(?![.\d]))` excuses only a zero that ends there.
84
+ //
85
+ // The number itself is `[-+]?(?:\d|\.\d)`, not `-?\d`: CSS lets a value carry an explicit `+` and
86
+ // omit the integer part, so `.75rem` and `+12px` are the same spacing as `0.75rem` and `12px`.
87
+ // Requiring a leading digit skipped both — the same silent-skip the zero guard above was fixed for,
88
+ // one spelling over.
89
+ //
90
+ // The property is preceded by `(?<![\w-])`, not `\b`: a `\b` boundary sits inside a hyphenated
91
+ // identifier, so every custom property whose NAME ends in a spacing word — the token layer's own
92
+ // `--vx-space-article-header-padding-bottom`, a consumer's `--card-padding-inline` — matched as if
93
+ // it were a declaration. A custom property is a definition, not a rendered spacing decision.
94
+ const INLINE_SPACING = new RegExp(
95
+ `(?<![\\w-])(?:${SPACING_PROP})\\s*:\\s*(?!var\\()['"]?[-+]?(?!0(?![.\\d]))(?:\\d|\\.\\d)`,
96
+ 'g',
97
+ )
98
+
99
+ /**
100
+ * The sub-scale micro-spacing ceiling, in px — the largest literal `inline-spacing` tolerates in a
101
+ * CSS file. Below the smallest spacing scale stop (`SPACE_SCALE.xs`), which is the whole point: a
102
+ * value under that stop has NO token to prefer, so flagging it asks for something that does not
103
+ * exist. Pinned against the real scale by `check-source.test.ts` so a density retune of the ladder
104
+ * cannot leave this stranded above it.
105
+ *
106
+ * Deliberately CSS-ONLY. In TSX the same shape means something different: `pl={4}` is a Mantine
107
+ * PROP and never matches this pattern in the first place, while `style={{ paddingLeft: 4 }}` does —
108
+ * and there the finding is right, because the prop form exists and should have been used. In CSS
109
+ * there is no prop form, and the emitted `--vx-space-*` set is basalt's own component one-offs
110
+ * (`--vx-space-toc-sub-indent`), not a consumer surface. Without this escape a consumer's CSS
111
+ * module had no legal way to write a 4px cluster gap: no token to reach for, `theme-allow` on every
112
+ * line (which `basalt-tokens.md` explicitly warns against), or `exemptRules` — which matches whole
113
+ * path segments and so cannot express `*.module.css`.
114
+ */
115
+ const MICRO_SPACING_CEILING_PX = 10
116
+
117
+ /** The root font size `rem` values resolve against — the same 16 the token layer's `pxRem` uses. */
118
+ const ROOT_FONT_SIZE_PX = 16
119
+
120
+ /**
121
+ * Is this CSS declaration entirely sub-scale? True when every literal in the value is a bare px (or
122
+ * unitless) number at or below {@link MICRO_SPACING_CEILING_PX}. `var(...)` components are dropped
123
+ * before the check — a value that mixes a token with a micro literal (`padding: 4px var(--x)`) is
124
+ * already tokenized where it counts.
125
+ *
126
+ * Multi-value shorthands are judged as a whole: `padding: 4px 8px` passes, `padding: 4px 16px` does
127
+ * not — the 16 has a scale stop and should use it.
128
+ *
129
+ * `rem` is resolved against the 16px root, the same conversion `pxRem` in the token layer applies,
130
+ * so `0.25rem` and `4px` get the same answer. Writing the identical spacing two ways and having the
131
+ * guard accept one is the same arbitrariness the kebab gap produced. Units that cannot be resolved
132
+ * to px without layout context — `em`, `%`, `ch`, `vw` — are not micro-spacing claims and still
133
+ * flag.
134
+ */
135
+ function isSubScaleCssSpacing(line: string, matchIndex: number): boolean {
136
+ const colon = line.indexOf(':', matchIndex)
137
+ if (colon === -1) return false
138
+ const rest = line.slice(colon + 1)
139
+ const end = rest.search(/[;}]/)
140
+ const value = (end === -1 ? rest : rest.slice(0, end)).replace(/var\([^)]*\)/g, ' ').trim()
141
+ if (value === '') return true
142
+ return value.split(/\s+/).every((part) => {
143
+ const literal = /^[-+]?(\d+(?:\.\d+)?|\.\d+)(px|rem)?$/.exec(part)
144
+ if (literal === null) return false
145
+ const px = literal[2] === 'rem' ? Number(literal[1]) * ROOT_FONT_SIZE_PX : Number(literal[1])
146
+ return px <= MICRO_SPACING_CEILING_PX
147
+ })
148
+ }
70
149
 
71
150
  // display:flex/grid/inline-flex/inline-grid in an inline style.
72
151
  const INLINE_DISPLAY = /\bdisplay\s*:\s*['"](?:inline-)?(?:flex|grid)['"]/g
@@ -130,7 +209,21 @@ const SUB_16_FONT_SIZE = /font-?[Ss]ize\s*:\s*['"]?(-?\d+(?:\.\d+)?)(?:px)?['"]?
130
209
  // ── Defaults ─────────────────────────────────────────────────────────────────────────────────────
131
210
 
132
211
  /** Default spacing steps (px) flagged as raw spacing props. */
133
- const DEFAULT_SPACING_STEPS: readonly number[] = [10, 12, 16, 20, 32]
212
+ /**
213
+ * The `xs…xl` spacing scale, as raw numbers — what `raw-spacing` flags, because a prop value that
214
+ * EQUALS a step should be written as the token (`p="md"`, not `p={18}`).
215
+ *
216
+ * Mirrors `SPACE_SCALE` at level 0. Kept as a literal rather than imported from `tokens/palette` so
217
+ * the headless guard core stays a single file: it runs on every Write/Edit through the PreToolUse
218
+ * hook, and pulling the palette in would drag `derive.ts` + `hct.ts`'s color math along with it.
219
+ * `check-source.test.ts` asserts the two agree, so the copy cannot drift — which it did: this list
220
+ * still read `[10, 12, 16, 20, 32]` after the level-0 retune, telling consumers to replace `p={16}`
221
+ * with a `p="md"` that resolves to 18.
222
+ *
223
+ * A consumer whose theme moves the scale (`createBasaltTheme({ density })`, or its own overrides)
224
+ * sets `basalt.spacingSteps` in package.json rather than living with this default.
225
+ */
226
+ const DEFAULT_SPACING_STEPS: readonly number[] = [11, 13, 18, 20, 26]
134
227
  /** Default off-identity Mantine accent families. */
135
228
  const DEFAULT_FORBIDDEN_ACCENTS: readonly string[] = ['teal', 'violet', 'grape', 'indigo', 'pink']
136
229
 
@@ -153,6 +246,29 @@ export const DEFAULT_GUARD_CONFIG: GuardConfig = {
153
246
  sub16InputFont: true,
154
247
  allowComment: 'theme-allow',
155
248
  exemptRules: {},
249
+ severity: {},
250
+ }
251
+
252
+ /**
253
+ * Kinds still inside their grace minor — reported, not fatal, until the next minor promotes them.
254
+ * See {@link GuardSeverity} for the doctrine and why basalt-ui in particular needs it.
255
+ *
256
+ * The value is the promotion note, so the entry carries its own expiry rather than relying on
257
+ * someone remembering. Adding a kind here is part of shipping it; removing the entry IS the
258
+ * promotion, and belongs in its own commit so the changelog says enforcement got stricter.
259
+ *
260
+ * Empty today: every shipped kind is past its grace period. The next new kind goes here first.
261
+ *
262
+ * @example
263
+ * const GRACE: Partial<Record<GuardKind, string>> = {
264
+ * 'raw-font-family': 'introduced 1.4.0 — promote to error in 1.5.0',
265
+ * }
266
+ */
267
+ const GRACE_PERIOD_KINDS: Partial<Record<GuardKind, string>> = {}
268
+
269
+ /** A kind's effective severity: consumer override first, then the grace table, then `error`. */
270
+ function severityOf(kind: GuardKind, cfg: GuardConfig): GuardSeverity {
271
+ return cfg.severity?.[kind] ?? (kind in GRACE_PERIOD_KINDS ? 'warn' : 'error')
156
272
  }
157
273
 
158
274
  // ── Path predicate ────────────────────────────────────────────────────────────────────────────────
@@ -617,7 +733,9 @@ function ruleApplies(kind: GuardKind, relPath: string): boolean {
617
733
  * if (findings.some((f) => f.kind === 'raw-hex')) { ... }
618
734
  */
619
735
  export function checkSource(text: string, relPath: string, cfg: GuardConfig): Finding[] {
620
- const findings: Finding[] = []
736
+ // Severity is stamped once at the end rather than at each of the ~20 push sites — it is a
737
+ // property of the KIND and the config, never of the match.
738
+ const findings: Omit<Finding, 'severity'>[] = []
621
739
 
622
740
  // Derive the 3 dynamic regexes via GUARD_RULES pattern builders.
623
741
  const forbiddenAccentRe = (
@@ -635,7 +753,8 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
635
753
  // the stripped text has already blanked out. Same length / same newline positions as `text`, so
636
754
  // line numbers computed off either one agree.
637
755
  const lines = text.split('\n')
638
- const codeText = stripComments(text, guardSyntaxFor(relPath))
756
+ const syntax = guardSyntaxFor(relPath)
757
+ const codeText = stripComments(text, syntax)
639
758
  const codeLines = codeText.split('\n')
640
759
 
641
760
  for (let i = 0; i < lines.length; i++) {
@@ -708,9 +827,10 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
708
827
  findings.push({ relPath, line: i + 1, token: '<raw-html style>', kind: 'raw-html-layout' })
709
828
  }
710
829
 
711
- // inline-spacing — pattern + gating from GUARD_RULES.
830
+ // inline-spacing — pattern + gating from GUARD_RULES, plus the CSS-only sub-scale escape.
712
831
  if (GUARD_RULES['inline-spacing'].enabled!(cfg)) {
713
832
  for (const m of line.matchAll(GUARD_RULES['inline-spacing'].pattern as RegExp)) {
833
+ if (syntax === 'css' && isSubScaleCssSpacing(line, m.index)) continue
714
834
  findings.push({ relPath, line: i + 1, token: m[0], kind: 'inline-spacing' })
715
835
  }
716
836
  }
@@ -828,5 +948,7 @@ export function checkSource(text: string, relPath: string, cfg: GuardConfig): Fi
828
948
  // Per-rule, per-path exemption post-filter (§exemptRules) — applied once here so it uniformly
829
949
  // covers every kind regardless of whether it was emitted via the GUARD_RULES registry loop above
830
950
  // or one of the inline-handled kinds (raw-surface, raw-html-layout, sub-16-input-font, …).
831
- return findings.filter((f) => !isRuleExempt(f.kind, f.relPath, cfg.exemptRules))
951
+ return findings
952
+ .filter((f) => !isRuleExempt(f.kind, f.relPath, cfg.exemptRules))
953
+ .map((f) => ({ ...f, severity: severityOf(f.kind, cfg) }))
832
954
  }
@@ -28,6 +28,22 @@ export type GuardKind =
28
28
  | 'sub-16-input-font'
29
29
  | 'raw-font-family'
30
30
 
31
+ /**
32
+ * How hard a finding lands. `error` fails the build; `warn` reports and passes.
33
+ *
34
+ * The point of `warn` is the LANDING of a new rule, not a permanent tier. basalt-ui bans majors by
35
+ * design — 1.x absorbs breaks — so a consumer has no semver channel telling them enforcement got
36
+ * stricter, and the guard is the part of the framework that can hard-fail their build. A kind that
37
+ * arrives as an error therefore turns a routine minor upgrade into an unplanned refactor: 1.2.0
38
+ * cost the one real consumer eleven `theme-allow` comments, and 1.3.0 had them delete all eleven
39
+ * again — net zero source change, two commits, two production deploys.
40
+ *
41
+ * So: a change that makes the guard reject code it previously accepted — a new kind, or an existing
42
+ * kind reaching a new file type — ships `warn` for one minor, then promotes. The consumer sees it,
43
+ * schedules it, and upgrades on a green build.
44
+ */
45
+ export type GuardSeverity = 'warn' | 'error'
46
+
31
47
  /**
32
48
  * A structured finding — the chosen testable surface (§C.4). Replaces the old `Violation` type.
33
49
  * `relPath` + `line` + `token` + `kind` uniquely identify the violation.
@@ -41,6 +57,8 @@ export type Finding = {
41
57
  readonly line: number
42
58
  readonly token: string
43
59
  readonly kind: GuardKind
60
+ /** Resolved per kind from {@link GuardConfig.severity} over the shipped default. */
61
+ readonly severity: GuardSeverity
44
62
  }
45
63
 
46
64
  /**
@@ -136,4 +154,21 @@ export type GuardConfig = {
136
154
  * { exemptRules: { 'inline-display': ['agent'] } } // inline-display never fires under src/agent/**
137
155
  */
138
156
  readonly exemptRules: Partial<Record<GuardKind, string[]>>
157
+ /**
158
+ * Per-kind severity override. A kind absent here takes the shipped default, which is `error`
159
+ * for every kind past its grace minor — see {@link GuardSeverity} for why a grace minor exists.
160
+ *
161
+ * Two directions, both legitimate:
162
+ * • `'warn'` on an `error` kind — a consumer who wants to upgrade now and fix later, on their
163
+ * own schedule rather than the release's.
164
+ * • `'error'` on a grace-period kind — a consumer who would rather take the enforcement
165
+ * immediately than carry a warning for a minor.
166
+ *
167
+ * This is severity, NOT an off switch: every kind already has its own boolean in this config,
168
+ * and `exemptRules` scopes a kind to paths. A kind turned down to `warn` still reports.
169
+ *
170
+ * @example
171
+ * { severity: { 'inline-spacing': 'warn' } } // report, don't fail, while we migrate
172
+ */
173
+ readonly severity: Partial<Record<GuardKind, GuardSeverity>>
139
174
  }
package/src/styles.css CHANGED
@@ -24,6 +24,11 @@
24
24
  /* Font stack — overridable via the --basalt-font-* custom properties. */
25
25
  @layer base {
26
26
  :root {
27
+ /* Hubot Sans is a condensed display face; the spec pins it at 88% wherever it lands. A knob
28
+ rather than a literal at the rule below, because that rule reaches BARE h1–h6: a consumer
29
+ that layers its own base type would otherwise have no way to keep its own heading width
30
+ short of out-specifying the framework. `normal` opts out entirely. */
31
+ --basalt-font-head-stretch: 88%;
27
32
  --basalt-font-sans:
28
33
  'Nunito Sans Variable', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
29
34
  Helvetica, Arial, sans-serif;
@@ -75,7 +80,9 @@
75
80
  }
76
81
 
77
82
  /* Hubot Sans is a condensed display face — the spec pins it at 88% font-stretch everywhere it
78
- lands (headings + the Mantine Title component). */
83
+ lands (headings + the Mantine Title component). Read from the knob declared above rather than
84
+ hardcoded here, so a consumer retunes it in one declaration instead of fighting these bare
85
+ element selectors with a more specific rule of their own. */
79
86
  h1,
80
87
  h2,
81
88
  h3,
@@ -83,7 +90,7 @@
83
90
  h5,
84
91
  h6,
85
92
  .mantine-Title-root {
86
- font-stretch: 88%;
93
+ font-stretch: var(--basalt-font-head-stretch, 88%);
87
94
  }
88
95
 
89
96
  /* Scrollbars (docs/DESIGN-SPEC.md §5): 9px, ink-mix thumb (stronger on hover), radius 6,
@@ -153,14 +160,18 @@
153
160
  .mantine-ScrollArea-scrollbar:active .mantine-ScrollArea-thumb {
154
161
  background-color: var(--basalt-scrollbar-thumb-hover);
155
162
  }
156
- }
157
163
 
158
- /* Print: hide the BasaltShell chrome so only page content prints.
159
- * AppShell.Navbar → <nav>, AppShell.Header → <header>, AppShell.Footer → <footer>. */
160
- @media print {
161
- nav,
162
- header,
163
- footer {
164
- display: none !important;
164
+ /* Print: hide the BasaltShell chrome so only page content prints.
165
+ Scoped to AppShell's own class hooks, NOT to bare nav/header/footer. The element form matched
166
+ any landmark on the page — a consumer with a real <nav> and no BasaltShell silently printed a
167
+ blank one, and being unlayered with `!important` there was nothing they could do about it
168
+ either. `@layer basalt` already outranks `@layer mantine`, so no `!important` is needed to win
169
+ against the AppShell's own display rules. */
170
+ @media print {
171
+ .mantine-AppShell-navbar,
172
+ .mantine-AppShell-header,
173
+ .mantine-AppShell-footer {
174
+ display: none;
175
+ }
165
176
  }
166
177
  }
package/src/surfaces.ts CHANGED
@@ -424,6 +424,13 @@ export const SURFACES = {
424
424
  'Mandatory CSS import (after the Mantine styles.layer.css bundles) — @layer basalt base styles, iOS input safety net, font stack',
425
425
  forbiddenImports: [],
426
426
  },
427
+ './tokens.css': {
428
+ kind: 'tooling',
429
+ layer: 'non-js-asset',
430
+ description:
431
+ 'Prebuilt --vx-* token stylesheet — the default buildPaletteCss() output as a plain file, for a consumer with no bundler, no React and no Mantine; retune the selector or trim the spacing set with `basalt-ui tokens:css`',
432
+ forbiddenImports: [],
433
+ },
427
434
  './configs/*': {
428
435
  kind: 'tooling',
429
436
  layer: 'non-js-asset',