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
package/src/cli/index.ts CHANGED
@@ -11,8 +11,8 @@
11
11
  * optionalPeers peerDependencies/peerDependenciesMeta presence.
12
12
  *
13
13
  * `init` / `sync` scaffold and reconcile the framework's *agentic* surface into a consumer repo:
14
- * Claude Code rules, a managed CLAUDE.md block, a DESIGN.md seed, and the toolchain templates
15
- * (oxfmt / lefthook / CI). Both are sha256-manifest driven for safe,
14
+ * Claude Code rules + skills, a managed CLAUDE.md block, a DESIGN.md seed, and the toolchain
15
+ * seeds (oxlint / oxfmt / lefthook / CI). Both are sha256-manifest driven for safe,
16
16
  * idempotent three-way reconciliation. Dependency-free — Node/Bun built-ins only.
17
17
  *
18
18
  * Runtime-agnostic (Node or Bun) — built-ins only, no `bun`-module import, so the exported API is
@@ -35,12 +35,18 @@ import { fileURLToPath } from 'node:url'
35
35
  import { checkSource, DEFAULT_GUARD_CONFIG, GUARD_RULES } from '../guard'
36
36
  import type { Finding, GuardConfig, GuardKind } from '../guard'
37
37
  import { evaluateGuardHook } from '../guard/guard-hook'
38
- import { RULE_NAMES, SURFACES } from '../surfaces'
38
+ import {
39
+ hasImportBoundaryRuleRegistered,
40
+ MANTINE_FREE_VIA_IMPORT_BOUNDARY,
41
+ RULE_NAMES,
42
+ SKILL_NAMES,
43
+ SURFACES,
44
+ } from '../surfaces'
39
45
  import type { DoctrineSpec, SurfaceSpec } from '../surfaces'
40
46
 
41
47
  /** Shape of the optional `"basalt"` key in a consumer's package.json. */
42
48
  export type BasaltConfig = {
43
- /** Source roots to scan. Default: argo's `['apps/dashboard/src', 'packages/charts/src']`. */
49
+ /** Source roots to scan. Default: `['src']`. Set explicitly for a monorepo layout. */
44
50
  roots?: string[]
45
51
  /** Files exempt from the scan (they ARE the palette source). Default: argo's exempt set. */
46
52
  exempt?: string[]
@@ -135,22 +141,27 @@ export type BasaltConfig = {
135
141
  * `sub-16-input-font` check.
136
142
  */
137
143
  sub16InputFont?: boolean
138
- /** Path of the consumer's guard-exempt series file, for DESIGN.md `{{SERIES_MODULE_PATH}}`. Default: `src/theme/series.ts`. */
144
+ /** Path of the consumer's guard-exempt series file, for DESIGN.md `{{SERIES_MODULE_PATH}}`. Default: `src/lib/series.ts`. */
139
145
  seriesModulePath?: string
140
- /** Claude Code marketplace coordinates for the settings stanza `{{MARKETPLACE_OWNER}}/{{MARKETPLACE_REPO}}`. Default: `jkrumm/basalt-ui`. */
141
- marketplace?: { owner?: string; repo?: string }
142
146
  }
143
147
 
144
- const DEFAULT_ROOTS = ['apps/dashboard/src', 'packages/charts/src']
148
+ const DEFAULT_ROOTS = ['src']
149
+
150
+ /**
151
+ * The one default consumer series path — the DESIGN.md template's `{{SERIES_MODULE_PATH}}`, the
152
+ * default scan exemption, and the skills' prose all point at this same file, so it lives in a
153
+ * single constant (argo's convention: `<root>/lib/series.ts`).
154
+ */
155
+ const DEFAULT_SERIES_MODULE_PATH = 'src/lib/series.ts'
145
156
 
146
157
  /**
147
158
  * Default scan exemption — a bare consumer's only palette source is its configured series module
148
159
  * (the doctrine directs every consumer to put raw hex series colors in `seriesModulePath`; default
149
- * `src/theme/series.ts`). Derived from the same config resolution `buildTemplateVars` uses for
160
+ * `src/lib/series.ts`). Derived from the same config resolution `buildTemplateVars` uses for
150
161
  * `{{SERIES_MODULE_PATH}}`, so overriding `seriesModulePath` keeps the exemption in sync.
151
162
  */
152
163
  function defaultExempt(cfg: BasaltConfig): string[] {
153
- return [cfg.seriesModulePath ?? 'src/theme/series.ts']
164
+ return [cfg.seriesModulePath ?? DEFAULT_SERIES_MODULE_PATH]
154
165
  }
155
166
 
156
167
  const SKIP = /\.gen\.ts$|\.test\.[tj]sx?$|\.d\.ts$/
@@ -288,13 +299,13 @@ export function checkTheme(cwd: string = process.cwd()): number {
288
299
  // consumer — both cases fail loud instead of warn-plus-green.
289
300
  if (cfg.roots === undefined) {
290
301
  console.error(
291
- `✖ basalt check-theme: 0 files scanned — no "basalt.roots" configured in package.json, and ` +
302
+ `✖ basalt-ui check-theme: 0 files scanned — no "basalt.roots" configured in package.json, and ` +
292
303
  `the built-in default roots (${DEFAULT_ROOTS.join(', ')}) matched zero files. ` +
293
304
  'Set "basalt": { "roots": [...] } in package.json to point at your source directories.',
294
305
  )
295
306
  } else {
296
307
  console.error(
297
- `✖ basalt check-theme: 0 files scanned — the configured "basalt.roots" (${roots.join(', ')}) ` +
308
+ `✖ basalt-ui check-theme: 0 files scanned — the configured "basalt.roots" (${roots.join(', ')}) ` +
298
309
  'matched zero files. Check the paths in "basalt.roots" in package.json.',
299
310
  )
300
311
  }
@@ -347,22 +358,37 @@ export function checkTheme(cwd: string = process.cwd()): number {
347
358
  // ──────────────────────────────────────────────────────────────────────────────
348
359
 
349
360
  /**
350
- * How a managed file is reconciled with its shipped source.
361
+ * How a file the framework writes into a consumer repo is owned. Two modes, one question:
362
+ * **does Claude read this file?**
363
+ *
364
+ * - `managed` : basalt owns it. sync refreshes it to the shipped version; a local edit is skipped
365
+ * and reported (`--force` overwrites); `--check` exits 1 on drift. Applies to exactly
366
+ * what Claude reads (.claude/rules/*, .claude/skills/*, the CLAUDE.md block) —
367
+ * Claude Code cannot load rules or skills from node_modules, and that platform limit
368
+ * is the only reason anything is copied at all. The sync diff is the review gate.
369
+ * - `seed` : written once if absent, then owned entirely by the consumer. sync never overwrites
370
+ * it and never reports drift (a starting point, not a managed mirror). Everything a
371
+ * machine reads is a seed, and a good seed's content is a REFERENCE (`extends` into
372
+ * node_modules/basalt-ui/configs/*), not a copy, so the toolchain auto-updates with
373
+ * the package while the consumer still owns the file.
351
374
  *
352
- * - `copy` : verbatim asset. init skips if the dest already exists; sync three-way reconciles it.
353
- * - `block` : a `<!-- basalt:begin -->…<!-- basalt:end -->` region inside a host file (CLAUDE.md).
354
- * The rest of the host file is owned by the consumer; only the block is managed.
355
- * - `seed` : written once if absent, then owned entirely by the consumer. sync never overwrites it
356
- * and never reports drift (it is a starting point, not a managed mirror).
375
+ * A managed file with `markers: true` is spliced as a `<!-- basalt:begin -->…<!-- basalt:end -->`
376
+ * region inside a host file the consumer otherwise owns (CLAUDE.md) — not a third mode, just
377
+ * managed ownership scoped to a region.
357
378
  */
358
- type Strategy = 'copy' | 'block' | 'seed'
379
+ type Mode = 'managed' | 'seed'
359
380
 
360
381
  /** A single file the framework writes into a consumer repo. */
361
382
  type ManagedFile = {
362
383
  /** Path of the produced file, relative to the consumer repo root. Stable manifest key. */
363
384
  dest: string
364
- /** Reconciliation strategy. */
365
- strategy: Strategy
385
+ /** Ownership mode. */
386
+ mode: Mode
387
+ /**
388
+ * `managed` only: the file is a marker-delimited region spliced into a consumer-owned host file
389
+ * rather than a whole file. `render()` returns the region INCLUDING its begin/end markers.
390
+ */
391
+ markers?: true
366
392
  /** Path of the shipped source asset, relative to the package root. */
367
393
  source: string
368
394
  /**
@@ -389,8 +415,6 @@ type TemplateVars = {
389
415
  BASALT_VERSION: string
390
416
  ACCENT_HUE: string
391
417
  SERIES_MODULE_PATH: string
392
- MARKETPLACE_OWNER: string
393
- MARKETPLACE_REPO: string
394
418
  }
395
419
 
396
420
  // The block markers the CLAUDE.md template emits. The begin marker carries the framework version
@@ -441,9 +465,7 @@ function buildTemplateVars(pkgRoot: string, cwd: string, cfg: BasaltConfig): Tem
441
465
  APP_NAME: readPackageName(cwd),
442
466
  BASALT_VERSION: readFrameworkVersion(pkgRoot),
443
467
  ACCENT_HUE: cfg.accentHue ?? 'blue',
444
- SERIES_MODULE_PATH: cfg.seriesModulePath ?? 'src/theme/series.ts',
445
- MARKETPLACE_OWNER: cfg.marketplace?.owner ?? 'jkrumm',
446
- MARKETPLACE_REPO: cfg.marketplace?.repo ?? 'basalt-ui',
468
+ SERIES_MODULE_PATH: cfg.seriesModulePath ?? DEFAULT_SERIES_MODULE_PATH,
447
469
  }
448
470
  }
449
471
 
@@ -455,10 +477,21 @@ function fillTemplate(tpl: string, vars: TemplateVars): string {
455
477
  })
456
478
  }
457
479
 
458
- /** The character span of the managed `basalt:begin … basalt:end` region, or null if absent. */
480
+ /**
481
+ * The character span of the managed `basalt:begin … basalt:end` region, or null if absent.
482
+ * Duplicate begin markers are an error, loudly — silently picking one region would splice into the
483
+ * wrong place and leave the other stale forever.
484
+ */
459
485
  function findBlockRegion(host: string): { start: number; end: number } | null {
460
486
  const start = host.indexOf(BLOCK_BEGIN_PREFIX)
461
487
  if (start === -1) return null
488
+ const duplicate = host.indexOf(BLOCK_BEGIN_PREFIX, start + BLOCK_BEGIN_PREFIX.length)
489
+ if (duplicate !== -1) {
490
+ throw new Error(
491
+ `duplicate \`${BLOCK_BEGIN_PREFIX}\` markers found in the host file — remove the stale ` +
492
+ 'basalt block by hand, then re-run.',
493
+ )
494
+ }
462
495
  const endMarker = host.indexOf(BLOCK_END, start)
463
496
  if (endMarker === -1) return null
464
497
  return { start, end: endMarker + BLOCK_END.length }
@@ -507,8 +540,8 @@ function hasDependency(cwd: string, pkgName: string): boolean {
507
540
 
508
541
  /**
509
542
  * Resolves whether the consumer has the optional TanStack router/query peers — auto-detected from
510
- * package.json, or forced via `--with-router` / `--with-query`. Both `basalt init` (for gating
511
- * which seed scaffolds to write) and `basalt sync` (so it doesn't silently re-seed a scaffold whose
543
+ * package.json, or forced via `--with-router` / `--with-query`. Both `basalt-ui init` (for gating
544
+ * which seed scaffolds to write) and `basalt-ui sync` (so it doesn't silently re-seed a scaffold whose
512
545
  * peer was never installed) call this once, up front.
513
546
  */
514
547
  function resolvePeerFlags(cwd: string, flags: ScaffoldFlags): PeerFlags {
@@ -520,19 +553,31 @@ function resolvePeerFlags(cwd: string, flags: ScaffoldFlags): PeerFlags {
520
553
 
521
554
  /** The full managed-file manifest. Stable, declarative — the single source of truth for init/sync. */
522
555
  function managedFiles(peers: PeerFlags): ManagedFile[] {
556
+ // ── managed: exactly what Claude reads ──────────────────────────────────────
523
557
  const rules: ManagedFile[] = RULE_NAMES.map((name) => ({
524
558
  dest: `.claude/rules/basalt-${name}.md`,
525
- strategy: 'copy' as const,
559
+ mode: 'managed' as const,
526
560
  source: `agent/rules/basalt-${name}.md`,
527
561
  render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/rules/basalt-${name}.md`),
528
562
  }))
529
563
 
564
+ // Skills take the same managed path the rules do — Claude Code cannot load skills from
565
+ // node_modules, and a plugin cannot ship rules, so init/sync is the one delivery channel for the
566
+ // whole agentic layer. The `basalt-` filename prefix keeps the /basalt-design ergonomics.
567
+ const skills: ManagedFile[] = SKILL_NAMES.map((name) => ({
568
+ dest: `.claude/skills/${name}/SKILL.md`,
569
+ mode: 'managed' as const,
570
+ source: `agent/skills/${name}/SKILL.md`,
571
+ render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/skills/${name}/SKILL.md`),
572
+ }))
573
+
530
574
  const claudeBlock: ManagedFile = {
531
575
  dest: 'CLAUDE.md',
532
- strategy: 'block',
576
+ mode: 'managed',
577
+ markers: true,
533
578
  source: 'agent/templates/CLAUDE-block.md.tpl',
534
- // For block, render() returns the fully-rendered block INCLUDING its begin/end markers — the
535
- // managed region. The writer splices it into the consumer's host CLAUDE.md at apply time.
579
+ // With markers, render() returns the fully-rendered region INCLUDING its begin/end markers.
580
+ // The writer splices it into the consumer's host CLAUDE.md at apply time.
536
581
  render: (ctx) => {
537
582
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/CLAUDE-block.md.tpl')
538
583
  if (tpl === null) return null
@@ -540,9 +585,10 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
540
585
  },
541
586
  }
542
587
 
588
+ // ── seed: everything a machine reads — written once, then consumer-owned ────
543
589
  const design: ManagedFile = {
544
590
  dest: 'DESIGN.md',
545
- strategy: 'seed',
591
+ mode: 'seed',
546
592
  source: 'agent/templates/DESIGN.md.tpl',
547
593
  render: (ctx) => {
548
594
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/DESIGN.md.tpl')
@@ -553,33 +599,44 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
553
599
 
554
600
  // Scaffold destination is `.oxfmtrc.json` — oxfmt auto-discovers that filename, not `oxfmt.json`
555
601
  // (the pre-rename scaffold; see migrateLegacyOxfmt for the one-time cleanup of the old dest).
602
+ // Content is a starting copy, not a reference — oxfmt has no `extends` mechanism.
556
603
  const oxfmt: ManagedFile = {
557
604
  dest: '.oxfmtrc.json',
558
- strategy: 'copy',
605
+ mode: 'seed',
559
606
  source: 'configs/oxfmt.json',
560
607
  render: (ctx) => readSource(ctx.pkgRoot, 'configs/oxfmt.json'),
561
608
  }
562
609
 
610
+ // Seed a lefthook.yml that `extends` the shipped preset — the consumer owns the file (their own
611
+ // commands merge alongside), while the preset's oxlint/oxfmt/check-theme jobs auto-update with
612
+ // the package. `source` names the preset the stub references; the stub itself is emitted inline.
563
613
  const lefthook: ManagedFile = {
564
614
  dest: 'lefthook.yml',
565
- strategy: 'copy',
615
+ mode: 'seed',
566
616
  source: 'configs/lefthook.yml',
567
- render: (ctx) => readSource(ctx.pkgRoot, 'configs/lefthook.yml'),
617
+ render: () =>
618
+ '# Seeded by basalt-ui init — you own this file; sync never touches it again.\n' +
619
+ '# The extends target supplies oxlint + oxfmt + check-theme pre-commit jobs and\n' +
620
+ '# auto-updates with the basalt-ui package. Add your own commands alongside.\n' +
621
+ 'extends:\n' +
622
+ ' - node_modules/basalt-ui/configs/lefthook.yml\n',
568
623
  }
569
624
 
625
+ // CI is inherently repo-shaped (a monorepo's check.yml needs its own globs and scripts), and
626
+ // GitHub Actions has no in-repo `extends` — so the workflow seeds as an explicit starting copy.
570
627
  const ci: ManagedFile = {
571
628
  dest: '.github/workflows/check.yml',
572
- strategy: 'copy',
629
+ mode: 'seed',
573
630
  source: 'configs/check.yml',
574
631
  render: (ctx) => readSource(ctx.pkgRoot, 'configs/check.yml'),
575
632
  }
576
633
 
577
634
  // Seed an `.oxlintrc.json` that extends the shipped preset (written once, then consumer-owned).
578
635
  // `render` emits the stub inline rather than copying `source`; `source` names the preset the stub
579
- // extends, and the `seed` strategy never reports drift, so it is not read back at sync time.
636
+ // extends, and the `seed` mode never reports drift, so it is not read back at sync time.
580
637
  const oxlintrc: ManagedFile = {
581
638
  dest: '.oxlintrc.json',
582
- strategy: 'seed',
639
+ mode: 'seed',
583
640
  source: 'configs/oxlint.json',
584
641
  render: () => '{\n "extends": ["./node_modules/basalt-ui/configs/oxlint.json"]\n}\n',
585
642
  }
@@ -590,7 +647,7 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
590
647
  /** TanStack Query client bootstrap (seed — consumer-owned after init). */
591
648
  const queryClient: ManagedFile = {
592
649
  dest: 'src/query-client.ts',
593
- strategy: 'seed',
650
+ mode: 'seed',
594
651
  source: 'agent/templates/query-client.ts.tpl',
595
652
  render: (ctx) => {
596
653
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/query-client.ts.tpl')
@@ -602,7 +659,7 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
602
659
  /** TanStack Router root route with QueryClient context wiring (seed — consumer-owned after init). */
603
660
  const rootRoute: ManagedFile = {
604
661
  dest: 'src/routes/__root.tsx',
605
- strategy: 'seed',
662
+ mode: 'seed',
606
663
  source: 'agent/templates/__root.tpl',
607
664
  render: (ctx) => {
608
665
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/__root.tpl')
@@ -619,11 +676,13 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
619
676
  if (peers.hasQuery) scaffolds.push(queryClient)
620
677
  if (peers.hasRouter && peers.hasQuery) scaffolds.push(rootRoute)
621
678
 
622
- return [...rules, claudeBlock, design, oxfmt, lefthook, ci, oxlintrc, ...scaffolds]
679
+ return [...rules, ...skills, claudeBlock, design, oxfmt, lefthook, ci, oxlintrc, ...scaffolds]
623
680
  }
624
681
 
625
682
  type Manifest = {
626
683
  version: 1
684
+ /** The basalt-ui version that last wrote this manifest — `doctor`'s one reconciliation axis. */
685
+ basaltVersion?: string
627
686
  /** dest path → sha256 of the managed unit (file bytes, block body, or stanza) at last write. */
628
687
  files: Record<string, string>
629
688
  }
@@ -633,7 +692,9 @@ function readManifest(cwd: string): Manifest {
633
692
  if (raw === null) return { version: 1, files: {} }
634
693
  try {
635
694
  const parsed = JSON.parse(raw) as Partial<Manifest>
636
- return { version: 1, files: parsed.files ?? {} }
695
+ const manifest: Manifest = { version: 1, files: parsed.files ?? {} }
696
+ if (typeof parsed.basaltVersion === 'string') manifest.basaltVersion = parsed.basaltVersion
697
+ return manifest
637
698
  } catch {
638
699
  return { version: 1, files: {} }
639
700
  }
@@ -670,9 +731,9 @@ function packageRoot(): string {
670
731
  }
671
732
 
672
733
  /**
673
- * The current on-disk state of a managed unit, plus the version the framework wants. For `block`
674
- * the "current" unit is the existing region (markers included); for `copy`/`seed` it is the whole
675
- * file.
734
+ * The current on-disk state of a managed unit, plus the version the framework wants. For a
735
+ * marker-spliced file the "current" unit is the existing region (markers included); otherwise it
736
+ * is the whole file.
676
737
  */
677
738
  type UnitState = {
678
739
  /** The managed unit's current bytes on disk (block region / whole file). */
@@ -694,38 +755,111 @@ function unitState(file: ManagedFile, cwd: string, ctx: RenderContext): UnitStat
694
755
  const desired = file.render(ctx)
695
756
  const destAbs = resolve(cwd, file.dest)
696
757
  const onDisk = readIfExists(destAbs)
697
- if (file.strategy === 'block') {
758
+ if (file.markers) {
698
759
  return { current: extractBlockRegion(onDisk), desired }
699
760
  }
700
761
  return { current: onDisk, desired }
701
762
  }
702
763
 
703
- /** Write a managed unit to disk according to its strategy. Returns the hash of the written unit. */
764
+ type Classification = 'unchanged' | 'drifted' | 'missing' | 'current'
765
+
766
+ /**
767
+ * Normalize a managed unit's rendered bytes for the ledger comparison below — makes a delta that is
768
+ * PURELY formatting or a version bump invisible to drift detection, while a real prose/content edit
769
+ * stays fully visible:
770
+ *
771
+ * - Blank out the per-release `BASALT_VERSION` token in a marker's begin line
772
+ * (`<!-- basalt:begin 1.0.1 -->` → `<!-- basalt:begin -->`). It changes on every release and is
773
+ * the only per-release variable that lands INSIDE the hashed region (the rest of
774
+ * `CLAUDE-block.md.tpl` has no other `{{…}}` placeholders today), so stripping it is what lets
775
+ * one normalized rendering stand in for every version of a given template body instead of
776
+ * needing one ledger entry per release. If a future marker template interpolates another
777
+ * per-release var inside its region, extend this normalization the same way.
778
+ * - Trim trailing whitespace per line and collapse every run of blank lines to none. This is the
779
+ * fix for the actual argo repro: lefthook's oxfmt reformats a spliced block (or a whole managed
780
+ * file) AFTER `writeUnit` has already exited and the manifest hash was recorded, so the manifest
781
+ * can never account for the reformat up front — normalizing it away here is the only place that
782
+ * can.
783
+ *
784
+ * Deliberately whitespace-only — word content is untouched, so a genuine hand-edit inside the block
785
+ * still changes the normalized text and still classifies `drifted`.
786
+ */
787
+ function normalizeForLedger(text: string): string {
788
+ return text
789
+ .replace(/(<!-- basalt:begin)\s+\S+(\s*-->)/, '$1$2')
790
+ .split('\n')
791
+ .map((line) => line.replace(/[ \t]+$/, ''))
792
+ .join('\n')
793
+ .replace(/\n{2,}/g, '\n')
794
+ .trim()
795
+ }
796
+
797
+ /**
798
+ * Write a managed unit to disk (whole file, or marker-spliced region). Returns the unit's hash —
799
+ * `sha256(normalizeForLedger(desired))`, NOT the raw bytes.
800
+ *
801
+ * This is the ledger: the manifest already records "what basalt shipped last sync", one entry per
802
+ * dest — a stored NORMALIZED hash makes that same single entry survive both a downstream formatter
803
+ * (the consumer's own lefthook oxfmt reformatting the written file/block after this function has
804
+ * already returned) and a version bump that changed the template's own words since the recorded
805
+ * entry — the argo cross-version case: current is v1.0.0's block, post-oxfmt; desired is v1.0.1's
806
+ * (different words, e.g. the CLI bin rename). Recording the raw hash can never reconcile that;
807
+ * recording the normalized hash lets `classify()` normalize `state.current` the same way and
808
+ * compare directly against it, no separate historical-hash storage required.
809
+ */
704
810
  function writeUnit(file: ManagedFile, cwd: string, desired: string): string {
705
811
  const destAbs = resolve(cwd, file.dest)
706
- if (file.strategy === 'block') {
812
+ if (file.markers) {
707
813
  const host = readIfExists(destAbs) ?? ''
708
814
  writeFileEnsuringDir(destAbs, applyBlock(host, desired))
709
- return sha256(desired)
815
+ } else {
816
+ writeFileEnsuringDir(destAbs, desired)
710
817
  }
711
- writeFileEnsuringDir(destAbs, desired)
712
- return sha256(desired)
818
+ return sha256(normalizeForLedger(desired))
713
819
  }
714
820
 
715
- type Classification = 'unchanged' | 'drifted' | 'missing' | 'current'
716
-
717
821
  /**
718
822
  * Classify a managed file against the manifest for a sync run.
719
823
  * - missing : the managed unit is absent on disk → recreate.
720
824
  * - current : on disk == desired → nothing to do.
721
- * - unchanged: on disk == manifest hash (untouched since last sync) but != desired → safe overwrite.
722
- * - drifted : on disk != manifest hash AND != desired (locally edited) → skip unless --force.
825
+ * - unchanged: on disk matches a KNOWN-SHIPPED rendering of this template, checked three ways (any
826
+ * one is sufficient) — but != desired as-is → safe overwrite:
827
+ * 1. `sha256(current) === manifestHash` — legacy raw-hash path. An existing consumer
828
+ * manifest (written before this fix, or by a still-running older CLI) holds the RAW
829
+ * hash of what was written, not the normalized one; keep matching it directly so an
830
+ * upgrade never mass-classifies a pristine tree as drifted.
831
+ * Residual transitional gap: a manifest written by a pre-1.0.2 CLI holds a raw hash
832
+ * of the exact old bytes, so if the on-disk block was ALSO reformatted by a
833
+ * downstream formatter AND the template body changed cross-version in the same
834
+ * upgrade, none of the three paths above match and it classifies `drifted`, needing
835
+ * one `--force`. Once any sync since writes a normalized entry (path 2/3 or a
836
+ * healed write), the gap is closed for good for that file. Deliberately not solved
837
+ * by keeping a historical per-version ledger — that's a real but bounded tradeoff.
838
+ * 2. `sha256(normalizeForLedger(current)) === manifestHash` — the ledger proper.
839
+ * `manifestHash` normally holds `sha256(normalizeForLedger(<bytes written at the
840
+ * last sync>))` (see `writeUnit`); normalizing `current` the same way and comparing
841
+ * survives a downstream formatter reformatting the file AND a version bump that
842
+ * changed the template's own words between the sync that wrote this manifest entry
843
+ * and the version being synced now — the argo cross-version false positive.
844
+ * 3. `normalizeForLedger(current) === normalizeForLedger(desired)` — same-version
845
+ * fallback for when there is no manifest entry to compare against at all (e.g. it
846
+ * was dropped), but the on-disk bytes still match today's rendering modulo
847
+ * formatting noise.
848
+ * - drifted : on disk matches NONE of the above (a real, word-level local edit) → skip unless
849
+ * --force.
723
850
  */
724
851
  function classify(state: UnitState, manifestHash: string | undefined): Classification {
725
852
  if (state.current === null) return 'missing'
726
853
  if (state.desired !== null && state.current === state.desired) return 'current'
727
854
  const currentHash = sha256(state.current)
728
855
  if (currentHash === manifestHash) return 'unchanged'
856
+ if (sha256(normalizeForLedger(state.current)) === manifestHash) return 'unchanged'
857
+ if (
858
+ state.desired !== null &&
859
+ normalizeForLedger(state.current) === normalizeForLedger(state.desired)
860
+ ) {
861
+ return 'unchanged'
862
+ }
729
863
  return 'drifted'
730
864
  }
731
865
 
@@ -762,13 +896,15 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
762
896
  continue
763
897
  }
764
898
 
765
- // `seed` + `copy` are skip-if-exists on init. `block` always inserts/updates its region;
899
+ // Whole files (managed + seed) are skip-if-exists on init; a marker-spliced region always
900
+ // inserts/updates itself inside its host file.
766
901
  const destExists = existsSync(resolve(cwd, file.dest))
767
- if ((file.strategy === 'copy' || file.strategy === 'seed') && destExists) {
768
- // Already present — keep the consumer's copy untouched. Record the SHIPPED hash so a later
769
- // sync treats a pre-existing-but-different file as locally drifted (skip unless --force),
770
- // never silently clobbering a file the consumer authored before init.
771
- manifest.files[file.dest] = sha256(state.desired)
902
+ if (!file.markers && destExists) {
903
+ // Already present — keep the consumer's copy untouched. Record the SHIPPED hash (normalized,
904
+ // same ledger form `writeUnit` uses) so a later sync treats a pre-existing-but-different file
905
+ // as locally drifted (skip unless --force), never silently clobbering a file the consumer
906
+ // authored before init.
907
+ manifest.files[file.dest] = sha256(normalizeForLedger(state.desired))
772
908
  skipped++
773
909
  continue
774
910
  }
@@ -778,37 +914,29 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
778
914
  written++
779
915
  }
780
916
 
917
+ manifest.basaltVersion = ctx.vars.BASALT_VERSION
781
918
  writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}\n`)
782
919
 
783
- console.log(`basalt init: ${written} written, ${skipped} kept, manifest at ${MANIFEST_PATH}`)
920
+ console.log(`basalt-ui init: ${written} written, ${skipped} kept, manifest at ${MANIFEST_PATH}`)
784
921
  if (missingSources.length > 0) {
785
922
  console.log(
786
- `basalt init: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
923
+ `basalt-ui init: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
787
924
  )
788
925
  }
789
926
  // query-client.ts / __root.tsx reference the optional TanStack peers directly — seeding them
790
927
  // without the peer installed would ship an unresolved import. Hint how to opt in instead.
791
928
  if (!peers.hasQuery) {
792
929
  console.log(
793
- 'basalt init: skipped src/query-client.ts (no @tanstack/react-query dependency detected) — ' +
930
+ 'basalt-ui init: skipped src/query-client.ts (no @tanstack/react-query dependency detected) — ' +
794
931
  'install it, or re-run with --with-query, to scaffold it.',
795
932
  )
796
933
  }
797
934
  if (!peers.hasRouter || !peers.hasQuery) {
798
935
  console.log(
799
- 'basalt init: skipped src/routes/__root.tsx (needs both @tanstack/react-router and ' +
936
+ 'basalt-ui init: skipped src/routes/__root.tsx (needs both @tanstack/react-router and ' +
800
937
  '@tanstack/react-query) — install both, or re-run with --with-router --with-query, to scaffold it.',
801
938
  )
802
939
  }
803
- // Skills ship via the basalt plugin, not init (a plugin can't write repo doctrine, and project
804
- // settings can't auto-install a plugin). Install it once at user scope — applies to every project
805
- // and auto-updates — so per-project setup stays just `basalt init`.
806
- const mp = `${ctx.vars.MARKETPLACE_OWNER}/${ctx.vars.MARKETPLACE_REPO}`
807
- console.log(
808
- `\nSkills: install the basalt plugin once (user scope → all projects, then auto-updates):\n` +
809
- ` claude plugin marketplace add ${mp}\n` +
810
- ` claude plugin install basalt@${ctx.vars.MARKETPLACE_REPO} (enable auto-update when prompted)`,
811
- )
812
940
  // The guard-hook PreToolUse registration is NOT written automatically — add it manually to
813
941
  // .claude/settings.json so every Write/Edit/MultiEdit goes through the theme guard.
814
942
  console.log(
@@ -817,7 +945,7 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
817
945
  ` "PreToolUse": [\n` +
818
946
  ` {\n` +
819
947
  ` "matcher": "Write|Edit|MultiEdit",\n` +
820
- ` "hooks": [{ "type": "command", "command": "bunx basalt guard-hook" }]\n` +
948
+ ` "hooks": [{ "type": "command", "command": "bunx basalt-ui guard-hook" }]\n` +
821
949
  ` }\n` +
822
950
  ` ]\n` +
823
951
  ` }`,
@@ -825,7 +953,7 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
825
953
  // First adoption on a previously guard-clean repo can surface a wall of findings (the 1.0 guard
826
954
  // adds several rule kinds beyond a legacy local guard) — steer toward tuning config, not mass-allow.
827
955
  console.log(
828
- '\nFirst run: run `basalt check-theme` next, then tune the per-rule `basalt.*` config keys ' +
956
+ '\nFirst run: run `basalt-ui check-theme` next, then tune the per-rule `basalt.*` config keys ' +
829
957
  'in package.json for anything that fires — do not mass-`theme-allow` findings.',
830
958
  )
831
959
  return 0
@@ -862,7 +990,7 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
862
990
  }
863
991
 
864
992
  // `seed` is written once, then owned by the consumer — never reconciled, never reported.
865
- if (file.strategy === 'seed') {
993
+ if (file.mode === 'seed') {
866
994
  if (state.current === null && !opts.check) {
867
995
  manifest.files[file.dest] = writeUnit(file, cwd, state.desired)
868
996
  recreated++
@@ -873,7 +1001,10 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
873
1001
  const kind = classify(state, manifest.files[file.dest])
874
1002
 
875
1003
  if (kind === 'current') {
876
- manifest.files[file.dest] = sha256(state.desired)
1004
+ // On-disk bytes already equal `desired` exactly — record the ledger's normalized form
1005
+ // (not the raw bytes) so this entry keeps behaving like every other `writeUnit`-recorded
1006
+ // hash for a future classify() call.
1007
+ manifest.files[file.dest] = sha256(normalizeForLedger(state.desired))
877
1008
  continue
878
1009
  }
879
1010
 
@@ -894,21 +1025,22 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
894
1025
 
895
1026
  if (opts.check) {
896
1027
  if (driftLines.length > 0) {
897
- console.error('basalt sync --check: locally-drifted managed files:')
1028
+ console.error('basalt-ui sync --check: locally-drifted managed files:')
898
1029
  for (const l of driftLines) console.error(l)
899
1030
  }
900
1031
  if (staleForCheck > 0) {
901
- console.error(`basalt sync --check: ${staleForCheck} managed file(s) out of date.`)
1032
+ console.error(`basalt-ui sync --check: ${staleForCheck} managed file(s) out of date.`)
902
1033
  return 1
903
1034
  }
904
- console.log('✓ basalt sync --check: all managed files current.')
1035
+ console.log('✓ basalt-ui sync --check: all managed files current.')
905
1036
  return 0
906
1037
  }
907
1038
 
1039
+ manifest.basaltVersion = ctx.vars.BASALT_VERSION
908
1040
  writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}\n`)
909
1041
 
910
1042
  console.log(
911
- `basalt sync: ${updated} updated, ${recreated} recreated, ${skippedDrift} skipped (drift).`,
1043
+ `basalt-ui sync: ${updated} updated, ${recreated} recreated, ${skippedDrift} skipped (drift).`,
912
1044
  )
913
1045
  if (driftLines.length > 0) {
914
1046
  console.log('Locally-edited files were skipped (run with --force to overwrite):')
@@ -916,7 +1048,7 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
916
1048
  }
917
1049
  if (missingSources.length > 0) {
918
1050
  console.log(
919
- `basalt sync: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
1051
+ `basalt-ui sync: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
920
1052
  )
921
1053
  }
922
1054
  return 0
@@ -933,18 +1065,20 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
933
1065
  * Eight assertions:
934
1066
  * 1. Every doctrine spec's guardKinds ⊆ keyof GUARD_RULES.
935
1067
  * 2. Every doctrine rule (deduped) maps to agent/rules/basalt-{rule}.md on disk.
936
- * 3. Deduped union of doctrine skill[] ⊆ plugin.json skills.
1068
+ * 3. Every doctrine skill (deduped) maps to agent/skills/{skill}/SKILL.md on disk.
937
1069
  * 4. Every non-#, non-'.' JS-subpath SURFACES key has a package.json exports entry.
938
1070
  * 5. Every real package.json exports key has a SURFACES entry.
939
1071
  * 6. Every surface with non-empty forbiddenImports has a globs field.
940
- * 7. Every headless surface carries all 3 Mantine bans (Mantine-free boundary).
1072
+ * 7. Every headless surface is Mantine-free — via all 3 `forbiddenImports` bans, OR (for
1073
+ * `MANTINE_FREE_VIA_IMPORT_BOUNDARY` members) the `basalt/import-boundary` plugin rule actually
1074
+ * registered as `'error'` in the shipped config.
941
1075
  * 8. Every doctrine optionalPeers entry exists in peerDependencies AND peerDependenciesMeta.
942
1076
  *
943
1077
  * Tooling surfaces are exempt from assertions 1–3 by the discriminant.
944
1078
  * Synthetic #-keys participate in assertions 1 and 2 but feed assertion 3 only
945
1079
  * via the deduped skill union (no independent per-#-surface skill row).
946
1080
  */
947
- export function checkCoverage(cwd: string = process.cwd()): number {
1081
+ export function checkCoverage(): number {
948
1082
  const pkgRoot = packageRoot()
949
1083
  const failures: string[] = []
950
1084
 
@@ -976,30 +1110,15 @@ export function checkCoverage(cwd: string = process.cwd()): number {
976
1110
  }
977
1111
  }
978
1112
 
979
- // ── Assertion 3: deduped union of doctrine skill[] ⊆ plugin.json skills ────
980
- // Skipped gracefully when plugin.json is absent (non-framework-repo context).
981
- const pluginJsonPath = resolve(cwd, 'plugins/basalt/.claude-plugin/plugin.json')
982
- if (!existsSync(pluginJsonPath)) {
983
- console.log(
984
- ` (assertion 3 skipped: plugin.json not found — not in the basalt-ui framework repo, skipping the plugin-skills check)`,
985
- )
986
- } else {
987
- let pluginSkillNames: Set<string> = new Set()
988
- try {
989
- const pluginJson = JSON.parse(readFileSync(pluginJsonPath, 'utf8')) as { skills?: string[] }
990
- // skills are path references like './skills/basalt-app'; extract the last path segment
991
- pluginSkillNames = new Set((pluginJson.skills ?? []).map((s) => s.split('/').pop() ?? s))
992
- } catch {
993
- failures.push(`Cannot read plugin.json at ${pluginJsonPath}`)
994
- }
995
-
996
- const doctrineSkillUnion = new Set(doctrineSpecs.flatMap((s) => [...s.skill]))
997
- for (const skill of doctrineSkillUnion) {
998
- if (!pluginSkillNames.has(skill)) {
999
- failures.push(
1000
- `SURFACES doctrine skill '${skill}' is not listed in plugins/basalt/.claude-plugin/plugin.json skills`,
1001
- )
1002
- }
1113
+ // ── Assertion 3: every doctrine skill (deduped) → agent/skills/{skill}/SKILL.md ──
1114
+ // Mirrors assertion 2's shape — skills ship in the npm package and are placed by init/sync,
1115
+ // so a skill referenced by SURFACES must exist as a shipped asset at the package root.
1116
+ for (const skill of SKILL_NAMES) {
1117
+ const skillPath = resolve(pkgRoot, `agent/skills/${skill}/SKILL.md`)
1118
+ if (!existsSync(skillPath)) {
1119
+ failures.push(
1120
+ `Missing skill file: agent/skills/${skill}/SKILL.md (derived from SURFACES doctrine skills)`,
1121
+ )
1003
1122
  }
1004
1123
  }
1005
1124
 
@@ -1045,11 +1164,34 @@ export function checkCoverage(cwd: string = process.cwd()): number {
1045
1164
  }
1046
1165
  }
1047
1166
 
1048
- // ── Assertion 7: every headless surface carries all 3 Mantine bans ───────────
1049
- // Guarantees the Mantine-free boundary — a future headless surface without bans fails here.
1167
+ // ── Assertion 7: every headless surface is Mantine-free ──────────────────────
1168
+ // Guarantees the Mantine-free boundary — a future headless surface without coverage fails here.
1169
+ // Coverage is either all 3 forbiddenImports bans, OR (for `./charts`/`./tokens`, the surfaces the
1170
+ // `basalt/import-boundary` plugin rule fires on) that rule actually registered as 'error' in the
1171
+ // shipped config — membership in MANTINE_FREE_VIA_IMPORT_BOUNDARY alone does NOT pass this; the
1172
+ // registration must be live, so a future removal of the rule fails loudly instead of silently.
1050
1173
  const REQUIRED_MANTINE_BANS = ['@mantine/core', '@mantine/hooks', '@mantine/*'] as const
1174
+ let shippedRules: Record<string, unknown> | undefined
1175
+ try {
1176
+ const shippedConfig = JSON.parse(
1177
+ readFileSync(resolve(pkgRoot, 'configs/oxlint.json'), 'utf8'),
1178
+ ) as { rules?: Record<string, unknown> }
1179
+ shippedRules = shippedConfig.rules
1180
+ } catch {
1181
+ failures.push(`Cannot read configs/oxlint.json at ${pkgRoot} to verify basalt/import-boundary`)
1182
+ }
1183
+ const importBoundaryRegistered = hasImportBoundaryRuleRegistered(shippedRules)
1184
+
1051
1185
  for (const [key, spec] of allSpecs) {
1052
1186
  if (spec.layer !== 'headless') continue
1187
+ if (MANTINE_FREE_VIA_IMPORT_BOUNDARY.has(key)) {
1188
+ if (importBoundaryRegistered) continue
1189
+ failures.push(
1190
+ `SURFACES['${key}'] relies on the basalt/import-boundary plugin rule for Mantine-free ` +
1191
+ `coverage, but that rule is not registered as 'error' in configs/oxlint.json`,
1192
+ )
1193
+ continue
1194
+ }
1053
1195
  for (const required of REQUIRED_MANTINE_BANS) {
1054
1196
  const hasBan = spec.forbiddenImports.some((fi) => fi.spec === required)
1055
1197
  if (!hasBan) {
@@ -1118,21 +1260,26 @@ type DoctorResult = {
1118
1260
  /**
1119
1261
  * Check a consumer repo's basalt integration and print a pass/warn report.
1120
1262
  *
1263
+ * With the plugin retired there is exactly ONE version axis — the npm package — so doctor verifies
1264
+ * one thing: the basalt-ui resolved in the consumer's node_modules against the version recorded in
1265
+ * .basalt/manifest.json at the last init/sync. File-level drift is `sync --check`'s job, not
1266
+ * doctor's.
1267
+ *
1121
1268
  * Hard failures (exit non-zero):
1122
1269
  * 1. .basalt/manifest.json exists (init was run).
1123
1270
  *
1124
1271
  * Warnings (non-fatal):
1125
- * 2. CLAUDE.md contains the basalt managed block (<!-- basalt:begin marker).
1126
- * 3. All 12 basalt-*.md rule files exist under .claude/rules/.
1127
- * 4. The basalt plugin appears to be installed (best-effort ~/.claude/settings.json check).
1128
- * 5. The running CLI's own version matches the basalt-ui version resolved in the consumer's
1129
- * node_modules (catches a stale `bunx basalt` npm fetch; best-effort, skipped if absent).
1272
+ * 2. The installed node_modules/basalt-ui version matches the manifest's basaltVersion
1273
+ * (a mismatch means the package was upgraded but `sync` never ran — the placed doctrine is
1274
+ * stale).
1275
+ * 3. The running CLI's own version matches the installed basalt-ui (catches a stale
1276
+ * `bunx basalt-ui` npm fetch; best-effort, skipped if node_modules is absent).
1130
1277
  *
1131
1278
  * Returns the exit code: 0 = all good, 1 = one or more hard failures.
1132
1279
  */
1133
1280
  export function doctor(cwd: string = process.cwd()): number {
1134
1281
  const result: DoctorResult = { hardFailures: 0, warnings: 0 }
1135
- const lines: string[] = [`\nbasalt doctor — ${cwd}\n`]
1282
+ const lines: string[] = [`\nbasalt-ui doctor — ${cwd}\n`]
1136
1283
 
1137
1284
  function pass(msg: string): void {
1138
1285
  lines.push(` ✓ ${msg}`)
@@ -1148,76 +1295,57 @@ export function doctor(cwd: string = process.cwd()): number {
1148
1295
 
1149
1296
  // ── Hard check 1: manifest exists ──────────────────────────────────────────
1150
1297
  const manifestAbs = resolve(cwd, MANIFEST_PATH)
1151
- if (existsSync(manifestAbs)) {
1298
+ const manifestExists = existsSync(manifestAbs)
1299
+ if (manifestExists) {
1152
1300
  pass(`${MANIFEST_PATH} exists`)
1153
1301
  } else {
1154
- fail(`${MANIFEST_PATH} missing — run \`basalt init\` to scaffold the consumer repo`)
1155
- }
1156
-
1157
- // ── Warn check 2: CLAUDE.md contains the basalt managed block ──────────────
1158
- const claudeMdAbs = resolve(cwd, 'CLAUDE.md')
1159
- const claudeMdContent = readIfExists(claudeMdAbs)
1160
- if (claudeMdContent !== null && claudeMdContent.includes(BLOCK_BEGIN_PREFIX)) {
1161
- pass('CLAUDE.md contains the basalt managed block')
1162
- } else if (claudeMdContent === null) {
1163
- warn('CLAUDE.md not found — run `basalt init` to scaffold the basalt block')
1164
- } else {
1165
- warn(
1166
- `CLAUDE.md does not contain the basalt managed block (expected marker: ${BLOCK_BEGIN_PREFIX}) — run \`basalt sync\``,
1167
- )
1302
+ fail(`${MANIFEST_PATH} missing — run \`basalt-ui init\` to scaffold the consumer repo`)
1168
1303
  }
1169
1304
 
1170
- // ── Warn check 3: all 12 rule files exist ──────────────────────────────────
1171
- const missingRules: string[] = []
1172
- for (const name of RULE_NAMES) {
1173
- const ruleAbs = resolve(cwd, `.claude/rules/basalt-${name}.md`)
1174
- if (!existsSync(ruleAbs)) missingRules.push(`basalt-${name}.md`)
1175
- }
1176
- if (missingRules.length === 0) {
1177
- pass(`all ${RULE_NAMES.length} basalt-*.md rule files present under .claude/rules/`)
1178
- } else {
1179
- warn(
1180
- `missing rule files under .claude/rules/: ${missingRules.join(', ')} — run \`basalt sync\` to restore`,
1181
- )
1305
+ // ── Warn check 2: installed basalt-ui version matches the manifest ─────────
1306
+ // THE one version axis. The manifest records the version whose init/sync placed the doctrine;
1307
+ // node_modules is what the app actually resolves. A mismatch means "upgrade landed, sync didn't".
1308
+ const consumerPkgRaw = readIfExists(resolve(cwd, 'node_modules', 'basalt-ui', 'package.json'))
1309
+ let installedVersion: string | null = null
1310
+ if (consumerPkgRaw !== null) {
1311
+ try {
1312
+ const consumerPkg = JSON.parse(consumerPkgRaw) as { version?: string }
1313
+ installedVersion = consumerPkg.version ?? null
1314
+ } catch {
1315
+ warn('could not parse node_modules/basalt-ui/package.json — version checks skipped')
1316
+ }
1182
1317
  }
1183
-
1184
- // ── Warn check 4: basalt plugin appears installed (best-effort) ─────────────
1185
- const settingsPath = resolve(process.env['HOME'] ?? '~', '.claude', 'settings.json')
1186
- try {
1187
- const settingsContent = readIfExists(settingsPath)
1188
- if (settingsContent !== null && settingsContent.includes('basalt')) {
1189
- pass('basalt plugin appears installed in ~/.claude/settings.json')
1190
- } else {
1318
+ if (manifestExists && installedVersion !== null) {
1319
+ const manifestVersion = readManifest(cwd).basaltVersion
1320
+ if (manifestVersion === undefined) {
1321
+ warn(
1322
+ `${MANIFEST_PATH} records no basaltVersion (written by an older basalt-ui) — run ` +
1323
+ '`basalt-ui sync` to refresh the doctrine and stamp the manifest.',
1324
+ )
1325
+ } else if (manifestVersion !== installedVersion) {
1191
1326
  warn(
1192
- 'basalt plugin not detected in ~/.claude/settings.json — install once at user scope:\n' +
1193
- ' claude plugin marketplace add jkrumm/basalt-ui\n' +
1194
- ' claude plugin install basalt@basalt-ui',
1327
+ `installed basalt-ui (${installedVersion}) differs from the version that last synced ` +
1328
+ `(${manifestVersion}) — the placed doctrine is stale; run \`basalt-ui sync\`.`,
1195
1329
  )
1330
+ } else {
1331
+ pass(`installed basalt-ui (${installedVersion}) matches the manifest's basaltVersion`)
1196
1332
  }
1197
- } catch {
1198
- warn('could not read ~/.claude/settings.json — plugin install status unknown')
1199
1333
  }
1200
1334
 
1201
- // ── Warn check 5: running CLI version matches the consumer's installed basalt-ui ────
1202
- // Catches the `bunx basalt` failure mode where bunx fetches a stale published package instead of
1203
- // the workspace `file:` dep — the CLI that ran doctor and the package resolved from the
1204
- // consumer's node_modules silently disagree.
1335
+ // ── Warn check 3: running CLI version matches the consumer's installed basalt-ui ────
1336
+ // Catches the failure mode where bunx fetches a stale published package instead of the local
1337
+ // install — the CLI that ran doctor and the package resolved from the consumer's node_modules
1338
+ // silently disagree.
1205
1339
  const cliVersion = readFrameworkVersion(packageRoot())
1206
- const consumerPkgRaw = readIfExists(resolve(cwd, 'node_modules', 'basalt-ui', 'package.json'))
1207
- if (consumerPkgRaw !== null) {
1208
- try {
1209
- const consumerPkg = JSON.parse(consumerPkgRaw) as { version?: string }
1210
- if (consumerPkg.version !== undefined && consumerPkg.version !== cliVersion) {
1211
- warn(
1212
- `running CLI version (${cliVersion}) differs from the installed basalt-ui version in ` +
1213
- `node_modules (${consumerPkg.version}) — likely a stale \`bunx basalt\` fetch from npm; ` +
1214
- 'add basalt-ui as a root devDependency so the bin hoists from your workspace.',
1215
- )
1216
- } else {
1217
- pass(`CLI version (${cliVersion}) matches the installed basalt-ui in node_modules`)
1218
- }
1219
- } catch {
1220
- warn('could not parse node_modules/basalt-ui/package.json — CLI version check skipped')
1340
+ if (installedVersion !== null) {
1341
+ if (installedVersion !== cliVersion) {
1342
+ warn(
1343
+ `running CLI version (${cliVersion}) differs from the installed basalt-ui version in ` +
1344
+ `node_modules (${installedVersion}) — likely a stale \`bunx basalt-ui\` fetch from npm; ` +
1345
+ 'add basalt-ui as a root devDependency so the bin hoists from your workspace.',
1346
+ )
1347
+ } else {
1348
+ pass(`CLI version (${cliVersion}) matches the installed basalt-ui in node_modules`)
1221
1349
  }
1222
1350
  }
1223
1351
 
@@ -1457,15 +1585,35 @@ export async function guardHook(cwd: string = process.cwd()): Promise<number> {
1457
1585
  return 0
1458
1586
  }
1459
1587
 
1588
+ /** The one usage string — printed by `basalt help` / `--help` / `-h` AND the unknown-command fallback. */
1589
+ const USAGE =
1590
+ 'Usage: basalt-ui <init [--with-router] [--with-query] | sync [--force] [--check] | ' +
1591
+ 'check-theme | check-coverage | info [--json] | doctor | guard-hook | help>\n\n' +
1592
+ 'Every subcommand accepts --help / -h to print this message and exit without running.'
1593
+
1460
1594
  /**
1461
1595
  * CLI dispatcher — parses argv (subcommand + flags) and returns the command's exit code. The bin
1462
1596
  * entry is the ONLY caller that translates this to process.exit, so init/sync/checkTheme stay free
1463
1597
  * of process side effects and are safe to import and call from tests.
1464
1598
  *
1599
+ * `--help` / `-h` (on ANY subcommand) and the bare `help` command short-circuit BEFORE dispatch —
1600
+ * checked first, so a mutating command (`sync`, `init`) never runs just because the caller only
1601
+ * asked to read about it.
1602
+ *
1465
1603
  * The `guard-hook` subcommand is async (reads stdin); all others are synchronous.
1466
1604
  */
1467
1605
  export function run(argv: string[], cwd: string = process.cwd()): number | Promise<number> {
1468
1606
  const [cmd, ...flags] = argv
1607
+ if (
1608
+ cmd === 'help' ||
1609
+ cmd === '--help' ||
1610
+ cmd === '-h' ||
1611
+ flags.includes('--help') ||
1612
+ flags.includes('-h')
1613
+ ) {
1614
+ console.log(USAGE)
1615
+ return 0
1616
+ }
1469
1617
  switch (cmd) {
1470
1618
  case 'init':
1471
1619
  return init(cwd, {
@@ -1477,7 +1625,7 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
1477
1625
  case 'check-theme':
1478
1626
  return checkTheme(cwd)
1479
1627
  case 'check-coverage':
1480
- return checkCoverage(cwd)
1628
+ return checkCoverage()
1481
1629
  case 'info':
1482
1630
  return info(flags)
1483
1631
  case 'doctor':
@@ -1485,13 +1633,13 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
1485
1633
  case 'guard-hook':
1486
1634
  return guardHook(cwd)
1487
1635
  default:
1488
- console.error(
1489
- 'Usage: basalt <init [--with-router] [--with-query] | sync [--force] [--check] | check-theme | check-coverage | info [--json] | doctor | guard-hook>',
1490
- )
1636
+ console.error(USAGE)
1491
1637
  return 1
1492
1638
  }
1493
1639
  }
1494
1640
 
1495
1641
  // Re-export the managed-file manifest for testing / introspection (no default export).
1496
- export { managedFiles, MANIFEST_PATH, RULE_NAMES }
1642
+ // `normalizeForLedger` is exported so tests can compute a fixture's expected ledger hash without
1643
+ // duplicating the normalization algorithm — it stays call-site-internal to writeUnit/classify.
1644
+ export { managedFiles, MANIFEST_PATH, normalizeForLedger, RULE_NAMES, SKILL_NAMES }
1497
1645
  export type { ManagedFile, Manifest, SyncOptions, DoctorResult }