basalt-ui 1.0.0 → 1.0.1

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.
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,12 @@ 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 { RULE_NAMES, SKILL_NAMES, SURFACES } from '../surfaces'
39
39
  import type { DoctrineSpec, SurfaceSpec } from '../surfaces'
40
40
 
41
41
  /** Shape of the optional `"basalt"` key in a consumer's package.json. */
42
42
  export type BasaltConfig = {
43
- /** Source roots to scan. Default: argo's `['apps/dashboard/src', 'packages/charts/src']`. */
43
+ /** Source roots to scan. Default: `['src']`. Set explicitly for a monorepo layout. */
44
44
  roots?: string[]
45
45
  /** Files exempt from the scan (they ARE the palette source). Default: argo's exempt set. */
46
46
  exempt?: string[]
@@ -135,22 +135,27 @@ export type BasaltConfig = {
135
135
  * `sub-16-input-font` check.
136
136
  */
137
137
  sub16InputFont?: boolean
138
- /** Path of the consumer's guard-exempt series file, for DESIGN.md `{{SERIES_MODULE_PATH}}`. Default: `src/theme/series.ts`. */
138
+ /** Path of the consumer's guard-exempt series file, for DESIGN.md `{{SERIES_MODULE_PATH}}`. Default: `src/lib/series.ts`. */
139
139
  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
140
  }
143
141
 
144
- const DEFAULT_ROOTS = ['apps/dashboard/src', 'packages/charts/src']
142
+ const DEFAULT_ROOTS = ['src']
143
+
144
+ /**
145
+ * The one default consumer series path — the DESIGN.md template's `{{SERIES_MODULE_PATH}}`, the
146
+ * default scan exemption, and the skills' prose all point at this same file, so it lives in a
147
+ * single constant (argo's convention: `<root>/lib/series.ts`).
148
+ */
149
+ const DEFAULT_SERIES_MODULE_PATH = 'src/lib/series.ts'
145
150
 
146
151
  /**
147
152
  * Default scan exemption — a bare consumer's only palette source is its configured series module
148
153
  * (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
154
+ * `src/lib/series.ts`). Derived from the same config resolution `buildTemplateVars` uses for
150
155
  * `{{SERIES_MODULE_PATH}}`, so overriding `seriesModulePath` keeps the exemption in sync.
151
156
  */
152
157
  function defaultExempt(cfg: BasaltConfig): string[] {
153
- return [cfg.seriesModulePath ?? 'src/theme/series.ts']
158
+ return [cfg.seriesModulePath ?? DEFAULT_SERIES_MODULE_PATH]
154
159
  }
155
160
 
156
161
  const SKIP = /\.gen\.ts$|\.test\.[tj]sx?$|\.d\.ts$/
@@ -288,13 +293,13 @@ export function checkTheme(cwd: string = process.cwd()): number {
288
293
  // consumer — both cases fail loud instead of warn-plus-green.
289
294
  if (cfg.roots === undefined) {
290
295
  console.error(
291
- `✖ basalt check-theme: 0 files scanned — no "basalt.roots" configured in package.json, and ` +
296
+ `✖ basalt-ui check-theme: 0 files scanned — no "basalt.roots" configured in package.json, and ` +
292
297
  `the built-in default roots (${DEFAULT_ROOTS.join(', ')}) matched zero files. ` +
293
298
  'Set "basalt": { "roots": [...] } in package.json to point at your source directories.',
294
299
  )
295
300
  } else {
296
301
  console.error(
297
- `✖ basalt check-theme: 0 files scanned — the configured "basalt.roots" (${roots.join(', ')}) ` +
302
+ `✖ basalt-ui check-theme: 0 files scanned — the configured "basalt.roots" (${roots.join(', ')}) ` +
298
303
  'matched zero files. Check the paths in "basalt.roots" in package.json.',
299
304
  )
300
305
  }
@@ -347,22 +352,37 @@ export function checkTheme(cwd: string = process.cwd()): number {
347
352
  // ──────────────────────────────────────────────────────────────────────────────
348
353
 
349
354
  /**
350
- * How a managed file is reconciled with its shipped source.
355
+ * How a file the framework writes into a consumer repo is owned. Two modes, one question:
356
+ * **does Claude read this file?**
357
+ *
358
+ * - `managed` : basalt owns it. sync refreshes it to the shipped version; a local edit is skipped
359
+ * and reported (`--force` overwrites); `--check` exits 1 on drift. Applies to exactly
360
+ * what Claude reads (.claude/rules/*, .claude/skills/*, the CLAUDE.md block) —
361
+ * Claude Code cannot load rules or skills from node_modules, and that platform limit
362
+ * is the only reason anything is copied at all. The sync diff is the review gate.
363
+ * - `seed` : written once if absent, then owned entirely by the consumer. sync never overwrites
364
+ * it and never reports drift (a starting point, not a managed mirror). Everything a
365
+ * machine reads is a seed, and a good seed's content is a REFERENCE (`extends` into
366
+ * node_modules/basalt-ui/configs/*), not a copy, so the toolchain auto-updates with
367
+ * the package while the consumer still owns the file.
351
368
  *
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).
369
+ * A managed file with `markers: true` is spliced as a `<!-- basalt:begin -->…<!-- basalt:end -->`
370
+ * region inside a host file the consumer otherwise owns (CLAUDE.md) — not a third mode, just
371
+ * managed ownership scoped to a region.
357
372
  */
358
- type Strategy = 'copy' | 'block' | 'seed'
373
+ type Mode = 'managed' | 'seed'
359
374
 
360
375
  /** A single file the framework writes into a consumer repo. */
361
376
  type ManagedFile = {
362
377
  /** Path of the produced file, relative to the consumer repo root. Stable manifest key. */
363
378
  dest: string
364
- /** Reconciliation strategy. */
365
- strategy: Strategy
379
+ /** Ownership mode. */
380
+ mode: Mode
381
+ /**
382
+ * `managed` only: the file is a marker-delimited region spliced into a consumer-owned host file
383
+ * rather than a whole file. `render()` returns the region INCLUDING its begin/end markers.
384
+ */
385
+ markers?: true
366
386
  /** Path of the shipped source asset, relative to the package root. */
367
387
  source: string
368
388
  /**
@@ -389,8 +409,6 @@ type TemplateVars = {
389
409
  BASALT_VERSION: string
390
410
  ACCENT_HUE: string
391
411
  SERIES_MODULE_PATH: string
392
- MARKETPLACE_OWNER: string
393
- MARKETPLACE_REPO: string
394
412
  }
395
413
 
396
414
  // The block markers the CLAUDE.md template emits. The begin marker carries the framework version
@@ -441,9 +459,7 @@ function buildTemplateVars(pkgRoot: string, cwd: string, cfg: BasaltConfig): Tem
441
459
  APP_NAME: readPackageName(cwd),
442
460
  BASALT_VERSION: readFrameworkVersion(pkgRoot),
443
461
  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',
462
+ SERIES_MODULE_PATH: cfg.seriesModulePath ?? DEFAULT_SERIES_MODULE_PATH,
447
463
  }
448
464
  }
449
465
 
@@ -455,10 +471,21 @@ function fillTemplate(tpl: string, vars: TemplateVars): string {
455
471
  })
456
472
  }
457
473
 
458
- /** The character span of the managed `basalt:begin … basalt:end` region, or null if absent. */
474
+ /**
475
+ * The character span of the managed `basalt:begin … basalt:end` region, or null if absent.
476
+ * Duplicate begin markers are an error, loudly — silently picking one region would splice into the
477
+ * wrong place and leave the other stale forever.
478
+ */
459
479
  function findBlockRegion(host: string): { start: number; end: number } | null {
460
480
  const start = host.indexOf(BLOCK_BEGIN_PREFIX)
461
481
  if (start === -1) return null
482
+ const duplicate = host.indexOf(BLOCK_BEGIN_PREFIX, start + BLOCK_BEGIN_PREFIX.length)
483
+ if (duplicate !== -1) {
484
+ throw new Error(
485
+ `duplicate \`${BLOCK_BEGIN_PREFIX}\` markers found in the host file — remove the stale ` +
486
+ 'basalt block by hand, then re-run.',
487
+ )
488
+ }
462
489
  const endMarker = host.indexOf(BLOCK_END, start)
463
490
  if (endMarker === -1) return null
464
491
  return { start, end: endMarker + BLOCK_END.length }
@@ -507,8 +534,8 @@ function hasDependency(cwd: string, pkgName: string): boolean {
507
534
 
508
535
  /**
509
536
  * 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
537
+ * package.json, or forced via `--with-router` / `--with-query`. Both `basalt-ui init` (for gating
538
+ * which seed scaffolds to write) and `basalt-ui sync` (so it doesn't silently re-seed a scaffold whose
512
539
  * peer was never installed) call this once, up front.
513
540
  */
514
541
  function resolvePeerFlags(cwd: string, flags: ScaffoldFlags): PeerFlags {
@@ -520,19 +547,31 @@ function resolvePeerFlags(cwd: string, flags: ScaffoldFlags): PeerFlags {
520
547
 
521
548
  /** The full managed-file manifest. Stable, declarative — the single source of truth for init/sync. */
522
549
  function managedFiles(peers: PeerFlags): ManagedFile[] {
550
+ // ── managed: exactly what Claude reads ──────────────────────────────────────
523
551
  const rules: ManagedFile[] = RULE_NAMES.map((name) => ({
524
552
  dest: `.claude/rules/basalt-${name}.md`,
525
- strategy: 'copy' as const,
553
+ mode: 'managed' as const,
526
554
  source: `agent/rules/basalt-${name}.md`,
527
555
  render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/rules/basalt-${name}.md`),
528
556
  }))
529
557
 
558
+ // Skills take the same managed path the rules do — Claude Code cannot load skills from
559
+ // node_modules, and a plugin cannot ship rules, so init/sync is the one delivery channel for the
560
+ // whole agentic layer. The `basalt-` filename prefix keeps the /basalt-design ergonomics.
561
+ const skills: ManagedFile[] = SKILL_NAMES.map((name) => ({
562
+ dest: `.claude/skills/${name}/SKILL.md`,
563
+ mode: 'managed' as const,
564
+ source: `agent/skills/${name}/SKILL.md`,
565
+ render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/skills/${name}/SKILL.md`),
566
+ }))
567
+
530
568
  const claudeBlock: ManagedFile = {
531
569
  dest: 'CLAUDE.md',
532
- strategy: 'block',
570
+ mode: 'managed',
571
+ markers: true,
533
572
  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.
573
+ // With markers, render() returns the fully-rendered region INCLUDING its begin/end markers.
574
+ // The writer splices it into the consumer's host CLAUDE.md at apply time.
536
575
  render: (ctx) => {
537
576
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/CLAUDE-block.md.tpl')
538
577
  if (tpl === null) return null
@@ -540,9 +579,10 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
540
579
  },
541
580
  }
542
581
 
582
+ // ── seed: everything a machine reads — written once, then consumer-owned ────
543
583
  const design: ManagedFile = {
544
584
  dest: 'DESIGN.md',
545
- strategy: 'seed',
585
+ mode: 'seed',
546
586
  source: 'agent/templates/DESIGN.md.tpl',
547
587
  render: (ctx) => {
548
588
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/DESIGN.md.tpl')
@@ -553,33 +593,44 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
553
593
 
554
594
  // Scaffold destination is `.oxfmtrc.json` — oxfmt auto-discovers that filename, not `oxfmt.json`
555
595
  // (the pre-rename scaffold; see migrateLegacyOxfmt for the one-time cleanup of the old dest).
596
+ // Content is a starting copy, not a reference — oxfmt has no `extends` mechanism.
556
597
  const oxfmt: ManagedFile = {
557
598
  dest: '.oxfmtrc.json',
558
- strategy: 'copy',
599
+ mode: 'seed',
559
600
  source: 'configs/oxfmt.json',
560
601
  render: (ctx) => readSource(ctx.pkgRoot, 'configs/oxfmt.json'),
561
602
  }
562
603
 
604
+ // Seed a lefthook.yml that `extends` the shipped preset — the consumer owns the file (their own
605
+ // commands merge alongside), while the preset's oxlint/oxfmt/check-theme jobs auto-update with
606
+ // the package. `source` names the preset the stub references; the stub itself is emitted inline.
563
607
  const lefthook: ManagedFile = {
564
608
  dest: 'lefthook.yml',
565
- strategy: 'copy',
609
+ mode: 'seed',
566
610
  source: 'configs/lefthook.yml',
567
- render: (ctx) => readSource(ctx.pkgRoot, 'configs/lefthook.yml'),
611
+ render: () =>
612
+ '# Seeded by basalt-ui init — you own this file; sync never touches it again.\n' +
613
+ '# The extends target supplies oxlint + oxfmt + check-theme pre-commit jobs and\n' +
614
+ '# auto-updates with the basalt-ui package. Add your own commands alongside.\n' +
615
+ 'extends:\n' +
616
+ ' - node_modules/basalt-ui/configs/lefthook.yml\n',
568
617
  }
569
618
 
619
+ // CI is inherently repo-shaped (a monorepo's check.yml needs its own globs and scripts), and
620
+ // GitHub Actions has no in-repo `extends` — so the workflow seeds as an explicit starting copy.
570
621
  const ci: ManagedFile = {
571
622
  dest: '.github/workflows/check.yml',
572
- strategy: 'copy',
623
+ mode: 'seed',
573
624
  source: 'configs/check.yml',
574
625
  render: (ctx) => readSource(ctx.pkgRoot, 'configs/check.yml'),
575
626
  }
576
627
 
577
628
  // Seed an `.oxlintrc.json` that extends the shipped preset (written once, then consumer-owned).
578
629
  // `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.
630
+ // extends, and the `seed` mode never reports drift, so it is not read back at sync time.
580
631
  const oxlintrc: ManagedFile = {
581
632
  dest: '.oxlintrc.json',
582
- strategy: 'seed',
633
+ mode: 'seed',
583
634
  source: 'configs/oxlint.json',
584
635
  render: () => '{\n "extends": ["./node_modules/basalt-ui/configs/oxlint.json"]\n}\n',
585
636
  }
@@ -590,7 +641,7 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
590
641
  /** TanStack Query client bootstrap (seed — consumer-owned after init). */
591
642
  const queryClient: ManagedFile = {
592
643
  dest: 'src/query-client.ts',
593
- strategy: 'seed',
644
+ mode: 'seed',
594
645
  source: 'agent/templates/query-client.ts.tpl',
595
646
  render: (ctx) => {
596
647
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/query-client.ts.tpl')
@@ -602,7 +653,7 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
602
653
  /** TanStack Router root route with QueryClient context wiring (seed — consumer-owned after init). */
603
654
  const rootRoute: ManagedFile = {
604
655
  dest: 'src/routes/__root.tsx',
605
- strategy: 'seed',
656
+ mode: 'seed',
606
657
  source: 'agent/templates/__root.tpl',
607
658
  render: (ctx) => {
608
659
  const tpl = readSource(ctx.pkgRoot, 'agent/templates/__root.tpl')
@@ -619,11 +670,13 @@ function managedFiles(peers: PeerFlags): ManagedFile[] {
619
670
  if (peers.hasQuery) scaffolds.push(queryClient)
620
671
  if (peers.hasRouter && peers.hasQuery) scaffolds.push(rootRoute)
621
672
 
622
- return [...rules, claudeBlock, design, oxfmt, lefthook, ci, oxlintrc, ...scaffolds]
673
+ return [...rules, ...skills, claudeBlock, design, oxfmt, lefthook, ci, oxlintrc, ...scaffolds]
623
674
  }
624
675
 
625
676
  type Manifest = {
626
677
  version: 1
678
+ /** The basalt-ui version that last wrote this manifest — `doctor`'s one reconciliation axis. */
679
+ basaltVersion?: string
627
680
  /** dest path → sha256 of the managed unit (file bytes, block body, or stanza) at last write. */
628
681
  files: Record<string, string>
629
682
  }
@@ -633,7 +686,9 @@ function readManifest(cwd: string): Manifest {
633
686
  if (raw === null) return { version: 1, files: {} }
634
687
  try {
635
688
  const parsed = JSON.parse(raw) as Partial<Manifest>
636
- return { version: 1, files: parsed.files ?? {} }
689
+ const manifest: Manifest = { version: 1, files: parsed.files ?? {} }
690
+ if (typeof parsed.basaltVersion === 'string') manifest.basaltVersion = parsed.basaltVersion
691
+ return manifest
637
692
  } catch {
638
693
  return { version: 1, files: {} }
639
694
  }
@@ -670,9 +725,9 @@ function packageRoot(): string {
670
725
  }
671
726
 
672
727
  /**
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.
728
+ * The current on-disk state of a managed unit, plus the version the framework wants. For a
729
+ * marker-spliced file the "current" unit is the existing region (markers included); otherwise it
730
+ * is the whole file.
676
731
  */
677
732
  type UnitState = {
678
733
  /** The managed unit's current bytes on disk (block region / whole file). */
@@ -694,16 +749,16 @@ function unitState(file: ManagedFile, cwd: string, ctx: RenderContext): UnitStat
694
749
  const desired = file.render(ctx)
695
750
  const destAbs = resolve(cwd, file.dest)
696
751
  const onDisk = readIfExists(destAbs)
697
- if (file.strategy === 'block') {
752
+ if (file.markers) {
698
753
  return { current: extractBlockRegion(onDisk), desired }
699
754
  }
700
755
  return { current: onDisk, desired }
701
756
  }
702
757
 
703
- /** Write a managed unit to disk according to its strategy. Returns the hash of the written unit. */
758
+ /** Write a managed unit to disk (whole file, or marker-spliced region). Returns the unit's hash. */
704
759
  function writeUnit(file: ManagedFile, cwd: string, desired: string): string {
705
760
  const destAbs = resolve(cwd, file.dest)
706
- if (file.strategy === 'block') {
761
+ if (file.markers) {
707
762
  const host = readIfExists(destAbs) ?? ''
708
763
  writeFileEnsuringDir(destAbs, applyBlock(host, desired))
709
764
  return sha256(desired)
@@ -762,9 +817,10 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
762
817
  continue
763
818
  }
764
819
 
765
- // `seed` + `copy` are skip-if-exists on init. `block` always inserts/updates its region;
820
+ // Whole files (managed + seed) are skip-if-exists on init; a marker-spliced region always
821
+ // inserts/updates itself inside its host file.
766
822
  const destExists = existsSync(resolve(cwd, file.dest))
767
- if ((file.strategy === 'copy' || file.strategy === 'seed') && destExists) {
823
+ if (!file.markers && destExists) {
768
824
  // Already present — keep the consumer's copy untouched. Record the SHIPPED hash so a later
769
825
  // sync treats a pre-existing-but-different file as locally drifted (skip unless --force),
770
826
  // never silently clobbering a file the consumer authored before init.
@@ -778,37 +834,29 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
778
834
  written++
779
835
  }
780
836
 
837
+ manifest.basaltVersion = ctx.vars.BASALT_VERSION
781
838
  writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}\n`)
782
839
 
783
- console.log(`basalt init: ${written} written, ${skipped} kept, manifest at ${MANIFEST_PATH}`)
840
+ console.log(`basalt-ui init: ${written} written, ${skipped} kept, manifest at ${MANIFEST_PATH}`)
784
841
  if (missingSources.length > 0) {
785
842
  console.log(
786
- `basalt init: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
843
+ `basalt-ui init: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
787
844
  )
788
845
  }
789
846
  // query-client.ts / __root.tsx reference the optional TanStack peers directly — seeding them
790
847
  // without the peer installed would ship an unresolved import. Hint how to opt in instead.
791
848
  if (!peers.hasQuery) {
792
849
  console.log(
793
- 'basalt init: skipped src/query-client.ts (no @tanstack/react-query dependency detected) — ' +
850
+ 'basalt-ui init: skipped src/query-client.ts (no @tanstack/react-query dependency detected) — ' +
794
851
  'install it, or re-run with --with-query, to scaffold it.',
795
852
  )
796
853
  }
797
854
  if (!peers.hasRouter || !peers.hasQuery) {
798
855
  console.log(
799
- 'basalt init: skipped src/routes/__root.tsx (needs both @tanstack/react-router and ' +
856
+ 'basalt-ui init: skipped src/routes/__root.tsx (needs both @tanstack/react-router and ' +
800
857
  '@tanstack/react-query) — install both, or re-run with --with-router --with-query, to scaffold it.',
801
858
  )
802
859
  }
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
860
  // The guard-hook PreToolUse registration is NOT written automatically — add it manually to
813
861
  // .claude/settings.json so every Write/Edit/MultiEdit goes through the theme guard.
814
862
  console.log(
@@ -817,7 +865,7 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
817
865
  ` "PreToolUse": [\n` +
818
866
  ` {\n` +
819
867
  ` "matcher": "Write|Edit|MultiEdit",\n` +
820
- ` "hooks": [{ "type": "command", "command": "bunx basalt guard-hook" }]\n` +
868
+ ` "hooks": [{ "type": "command", "command": "bunx basalt-ui guard-hook" }]\n` +
821
869
  ` }\n` +
822
870
  ` ]\n` +
823
871
  ` }`,
@@ -825,7 +873,7 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
825
873
  // First adoption on a previously guard-clean repo can surface a wall of findings (the 1.0 guard
826
874
  // adds several rule kinds beyond a legacy local guard) — steer toward tuning config, not mass-allow.
827
875
  console.log(
828
- '\nFirst run: run `basalt check-theme` next, then tune the per-rule `basalt.*` config keys ' +
876
+ '\nFirst run: run `basalt-ui check-theme` next, then tune the per-rule `basalt.*` config keys ' +
829
877
  'in package.json for anything that fires — do not mass-`theme-allow` findings.',
830
878
  )
831
879
  return 0
@@ -862,7 +910,7 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
862
910
  }
863
911
 
864
912
  // `seed` is written once, then owned by the consumer — never reconciled, never reported.
865
- if (file.strategy === 'seed') {
913
+ if (file.mode === 'seed') {
866
914
  if (state.current === null && !opts.check) {
867
915
  manifest.files[file.dest] = writeUnit(file, cwd, state.desired)
868
916
  recreated++
@@ -894,21 +942,22 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
894
942
 
895
943
  if (opts.check) {
896
944
  if (driftLines.length > 0) {
897
- console.error('basalt sync --check: locally-drifted managed files:')
945
+ console.error('basalt-ui sync --check: locally-drifted managed files:')
898
946
  for (const l of driftLines) console.error(l)
899
947
  }
900
948
  if (staleForCheck > 0) {
901
- console.error(`basalt sync --check: ${staleForCheck} managed file(s) out of date.`)
949
+ console.error(`basalt-ui sync --check: ${staleForCheck} managed file(s) out of date.`)
902
950
  return 1
903
951
  }
904
- console.log('✓ basalt sync --check: all managed files current.')
952
+ console.log('✓ basalt-ui sync --check: all managed files current.')
905
953
  return 0
906
954
  }
907
955
 
956
+ manifest.basaltVersion = ctx.vars.BASALT_VERSION
908
957
  writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}\n`)
909
958
 
910
959
  console.log(
911
- `basalt sync: ${updated} updated, ${recreated} recreated, ${skippedDrift} skipped (drift).`,
960
+ `basalt-ui sync: ${updated} updated, ${recreated} recreated, ${skippedDrift} skipped (drift).`,
912
961
  )
913
962
  if (driftLines.length > 0) {
914
963
  console.log('Locally-edited files were skipped (run with --force to overwrite):')
@@ -916,7 +965,7 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
916
965
  }
917
966
  if (missingSources.length > 0) {
918
967
  console.log(
919
- `basalt sync: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
968
+ `basalt-ui sync: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
920
969
  )
921
970
  }
922
971
  return 0
@@ -933,7 +982,7 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
933
982
  * Eight assertions:
934
983
  * 1. Every doctrine spec's guardKinds ⊆ keyof GUARD_RULES.
935
984
  * 2. Every doctrine rule (deduped) maps to agent/rules/basalt-{rule}.md on disk.
936
- * 3. Deduped union of doctrine skill[] ⊆ plugin.json skills.
985
+ * 3. Every doctrine skill (deduped) maps to agent/skills/{skill}/SKILL.md on disk.
937
986
  * 4. Every non-#, non-'.' JS-subpath SURFACES key has a package.json exports entry.
938
987
  * 5. Every real package.json exports key has a SURFACES entry.
939
988
  * 6. Every surface with non-empty forbiddenImports has a globs field.
@@ -944,7 +993,7 @@ export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): numbe
944
993
  * Synthetic #-keys participate in assertions 1 and 2 but feed assertion 3 only
945
994
  * via the deduped skill union (no independent per-#-surface skill row).
946
995
  */
947
- export function checkCoverage(cwd: string = process.cwd()): number {
996
+ export function checkCoverage(): number {
948
997
  const pkgRoot = packageRoot()
949
998
  const failures: string[] = []
950
999
 
@@ -976,30 +1025,15 @@ export function checkCoverage(cwd: string = process.cwd()): number {
976
1025
  }
977
1026
  }
978
1027
 
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
- }
1028
+ // ── Assertion 3: every doctrine skill (deduped) → agent/skills/{skill}/SKILL.md ──
1029
+ // Mirrors assertion 2's shape — skills ship in the npm package and are placed by init/sync,
1030
+ // so a skill referenced by SURFACES must exist as a shipped asset at the package root.
1031
+ for (const skill of SKILL_NAMES) {
1032
+ const skillPath = resolve(pkgRoot, `agent/skills/${skill}/SKILL.md`)
1033
+ if (!existsSync(skillPath)) {
1034
+ failures.push(
1035
+ `Missing skill file: agent/skills/${skill}/SKILL.md (derived from SURFACES doctrine skills)`,
1036
+ )
1003
1037
  }
1004
1038
  }
1005
1039
 
@@ -1118,21 +1152,26 @@ type DoctorResult = {
1118
1152
  /**
1119
1153
  * Check a consumer repo's basalt integration and print a pass/warn report.
1120
1154
  *
1155
+ * With the plugin retired there is exactly ONE version axis — the npm package — so doctor verifies
1156
+ * one thing: the basalt-ui resolved in the consumer's node_modules against the version recorded in
1157
+ * .basalt/manifest.json at the last init/sync. File-level drift is `sync --check`'s job, not
1158
+ * doctor's.
1159
+ *
1121
1160
  * Hard failures (exit non-zero):
1122
1161
  * 1. .basalt/manifest.json exists (init was run).
1123
1162
  *
1124
1163
  * 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).
1164
+ * 2. The installed node_modules/basalt-ui version matches the manifest's basaltVersion
1165
+ * (a mismatch means the package was upgraded but `sync` never ran — the placed doctrine is
1166
+ * stale).
1167
+ * 3. The running CLI's own version matches the installed basalt-ui (catches a stale
1168
+ * `bunx basalt-ui` npm fetch; best-effort, skipped if node_modules is absent).
1130
1169
  *
1131
1170
  * Returns the exit code: 0 = all good, 1 = one or more hard failures.
1132
1171
  */
1133
1172
  export function doctor(cwd: string = process.cwd()): number {
1134
1173
  const result: DoctorResult = { hardFailures: 0, warnings: 0 }
1135
- const lines: string[] = [`\nbasalt doctor — ${cwd}\n`]
1174
+ const lines: string[] = [`\nbasalt-ui doctor — ${cwd}\n`]
1136
1175
 
1137
1176
  function pass(msg: string): void {
1138
1177
  lines.push(` ✓ ${msg}`)
@@ -1148,76 +1187,57 @@ export function doctor(cwd: string = process.cwd()): number {
1148
1187
 
1149
1188
  // ── Hard check 1: manifest exists ──────────────────────────────────────────
1150
1189
  const manifestAbs = resolve(cwd, MANIFEST_PATH)
1151
- if (existsSync(manifestAbs)) {
1190
+ const manifestExists = existsSync(manifestAbs)
1191
+ if (manifestExists) {
1152
1192
  pass(`${MANIFEST_PATH} exists`)
1153
1193
  } 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
- )
1194
+ fail(`${MANIFEST_PATH} missing — run \`basalt-ui init\` to scaffold the consumer repo`)
1168
1195
  }
1169
1196
 
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
- )
1197
+ // ── Warn check 2: installed basalt-ui version matches the manifest ─────────
1198
+ // THE one version axis. The manifest records the version whose init/sync placed the doctrine;
1199
+ // node_modules is what the app actually resolves. A mismatch means "upgrade landed, sync didn't".
1200
+ const consumerPkgRaw = readIfExists(resolve(cwd, 'node_modules', 'basalt-ui', 'package.json'))
1201
+ let installedVersion: string | null = null
1202
+ if (consumerPkgRaw !== null) {
1203
+ try {
1204
+ const consumerPkg = JSON.parse(consumerPkgRaw) as { version?: string }
1205
+ installedVersion = consumerPkg.version ?? null
1206
+ } catch {
1207
+ warn('could not parse node_modules/basalt-ui/package.json — version checks skipped')
1208
+ }
1182
1209
  }
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 {
1210
+ if (manifestExists && installedVersion !== null) {
1211
+ const manifestVersion = readManifest(cwd).basaltVersion
1212
+ if (manifestVersion === undefined) {
1213
+ warn(
1214
+ `${MANIFEST_PATH} records no basaltVersion (written by an older basalt-ui) — run ` +
1215
+ '`basalt-ui sync` to refresh the doctrine and stamp the manifest.',
1216
+ )
1217
+ } else if (manifestVersion !== installedVersion) {
1191
1218
  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',
1219
+ `installed basalt-ui (${installedVersion}) differs from the version that last synced ` +
1220
+ `(${manifestVersion}) — the placed doctrine is stale; run \`basalt-ui sync\`.`,
1195
1221
  )
1222
+ } else {
1223
+ pass(`installed basalt-ui (${installedVersion}) matches the manifest's basaltVersion`)
1196
1224
  }
1197
- } catch {
1198
- warn('could not read ~/.claude/settings.json — plugin install status unknown')
1199
1225
  }
1200
1226
 
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.
1227
+ // ── Warn check 3: running CLI version matches the consumer's installed basalt-ui ────
1228
+ // Catches the failure mode where bunx fetches a stale published package instead of the local
1229
+ // install — the CLI that ran doctor and the package resolved from the consumer's node_modules
1230
+ // silently disagree.
1205
1231
  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')
1232
+ if (installedVersion !== null) {
1233
+ if (installedVersion !== cliVersion) {
1234
+ warn(
1235
+ `running CLI version (${cliVersion}) differs from the installed basalt-ui version in ` +
1236
+ `node_modules (${installedVersion}) — likely a stale \`bunx basalt-ui\` fetch from npm; ` +
1237
+ 'add basalt-ui as a root devDependency so the bin hoists from your workspace.',
1238
+ )
1239
+ } else {
1240
+ pass(`CLI version (${cliVersion}) matches the installed basalt-ui in node_modules`)
1221
1241
  }
1222
1242
  }
1223
1243
 
@@ -1457,15 +1477,35 @@ export async function guardHook(cwd: string = process.cwd()): Promise<number> {
1457
1477
  return 0
1458
1478
  }
1459
1479
 
1480
+ /** The one usage string — printed by `basalt help` / `--help` / `-h` AND the unknown-command fallback. */
1481
+ const USAGE =
1482
+ 'Usage: basalt-ui <init [--with-router] [--with-query] | sync [--force] [--check] | ' +
1483
+ 'check-theme | check-coverage | info [--json] | doctor | guard-hook | help>\n\n' +
1484
+ 'Every subcommand accepts --help / -h to print this message and exit without running.'
1485
+
1460
1486
  /**
1461
1487
  * CLI dispatcher — parses argv (subcommand + flags) and returns the command's exit code. The bin
1462
1488
  * entry is the ONLY caller that translates this to process.exit, so init/sync/checkTheme stay free
1463
1489
  * of process side effects and are safe to import and call from tests.
1464
1490
  *
1491
+ * `--help` / `-h` (on ANY subcommand) and the bare `help` command short-circuit BEFORE dispatch —
1492
+ * checked first, so a mutating command (`sync`, `init`) never runs just because the caller only
1493
+ * asked to read about it.
1494
+ *
1465
1495
  * The `guard-hook` subcommand is async (reads stdin); all others are synchronous.
1466
1496
  */
1467
1497
  export function run(argv: string[], cwd: string = process.cwd()): number | Promise<number> {
1468
1498
  const [cmd, ...flags] = argv
1499
+ if (
1500
+ cmd === 'help' ||
1501
+ cmd === '--help' ||
1502
+ cmd === '-h' ||
1503
+ flags.includes('--help') ||
1504
+ flags.includes('-h')
1505
+ ) {
1506
+ console.log(USAGE)
1507
+ return 0
1508
+ }
1469
1509
  switch (cmd) {
1470
1510
  case 'init':
1471
1511
  return init(cwd, {
@@ -1477,7 +1517,7 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
1477
1517
  case 'check-theme':
1478
1518
  return checkTheme(cwd)
1479
1519
  case 'check-coverage':
1480
- return checkCoverage(cwd)
1520
+ return checkCoverage()
1481
1521
  case 'info':
1482
1522
  return info(flags)
1483
1523
  case 'doctor':
@@ -1485,13 +1525,11 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
1485
1525
  case 'guard-hook':
1486
1526
  return guardHook(cwd)
1487
1527
  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
- )
1528
+ console.error(USAGE)
1491
1529
  return 1
1492
1530
  }
1493
1531
  }
1494
1532
 
1495
1533
  // Re-export the managed-file manifest for testing / introspection (no default export).
1496
- export { managedFiles, MANIFEST_PATH, RULE_NAMES }
1534
+ export { managedFiles, MANIFEST_PATH, RULE_NAMES, SKILL_NAMES }
1497
1535
  export type { ManagedFile, Manifest, SyncOptions, DoctorResult }