basalt-ui 0.4.2 → 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/AGENTS.md +70 -0
- package/CHANGELOG.md +210 -40
- package/LICENSE +201 -0
- package/README.md +421 -160
- package/agent/rules/basalt-agent.md +395 -0
- package/agent/rules/basalt-charts.md +170 -0
- package/agent/rules/basalt-commands.md +320 -0
- package/agent/rules/basalt-content.md +390 -0
- package/agent/rules/basalt-data.md +237 -0
- package/agent/rules/basalt-forms.md +186 -0
- package/agent/rules/basalt-mantine.md +327 -0
- package/agent/rules/basalt-notifications.md +264 -0
- package/agent/rules/basalt-query.md +130 -0
- package/agent/rules/basalt-router.md +173 -0
- package/agent/rules/basalt-state.md +99 -0
- package/agent/rules/basalt-tokens.md +148 -0
- package/agent/skills/basalt-app/SKILL.md +137 -0
- package/agent/skills/basalt-charts/SKILL.md +179 -0
- package/agent/skills/basalt-design/SKILL.md +249 -0
- package/agent/templates/CLAUDE-block.md.tpl +38 -0
- package/agent/templates/DESIGN.md.tpl +71 -0
- package/agent/templates/__root.tpl +31 -0
- package/agent/templates/query-client.ts.tpl +12 -0
- package/bin/basalt-ui.mjs +14 -0
- package/configs/check.yml +29 -0
- package/configs/lefthook.yml +25 -0
- package/configs/oxfmt.json +8 -0
- package/configs/oxlint-plugin.js +269 -0
- package/configs/oxlint-plugin.test.ts +107 -0
- package/configs/oxlint.json +116 -0
- package/configs/tsconfig.base.json +20 -0
- package/configs/tsconfig.node.json +8 -0
- package/configs/tsconfig.react-app.json +8 -0
- package/dist/agent/ai-sdk-transport.d.ts +85 -0
- package/dist/agent/ai-sdk-transport.d.ts.map +1 -0
- package/dist/agent/ai-sdk-transport.js +109 -0
- package/dist/agent/history.d.ts +55 -0
- package/dist/agent/history.d.ts.map +1 -0
- package/dist/agent/history.js +32 -0
- package/dist/agent/index.d.ts +53 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +23 -0
- package/dist/agent/outcome.d.ts +71 -0
- package/dist/agent/outcome.d.ts.map +1 -0
- package/dist/agent/outcome.js +30 -0
- package/dist/agent/part-list.d.ts +75 -0
- package/dist/agent/part-list.d.ts.map +1 -0
- package/dist/agent/part-list.js +127 -0
- package/dist/agent/parts.d.ts +91 -0
- package/dist/agent/parts.d.ts.map +1 -0
- package/dist/agent/parts.js +49 -0
- package/dist/agent/stick-to-bottom.d.ts +23 -0
- package/dist/agent/stick-to-bottom.d.ts.map +1 -0
- package/dist/agent/stick-to-bottom.js +73 -0
- package/dist/agent/thread.d.ts +124 -0
- package/dist/agent/thread.d.ts.map +1 -0
- package/dist/agent/thread.js +131 -0
- package/dist/agent/transport.d.ts +87 -0
- package/dist/agent/transport.d.ts.map +1 -0
- package/dist/agent/transport.js +21 -0
- package/dist/agent/use-agent-stream.d.ts +34 -0
- package/dist/agent/use-agent-stream.d.ts.map +1 -0
- package/dist/agent/use-agent-stream.js +56 -0
- package/dist/agent/use-agent-thread-runs.d.ts +72 -0
- package/dist/agent/use-agent-thread-runs.d.ts.map +1 -0
- package/dist/agent/use-agent-thread-runs.js +217 -0
- package/dist/agent-chat/composer.d.ts +18 -0
- package/dist/agent-chat/composer.d.ts.map +1 -0
- package/dist/agent-chat/composer.js +86 -0
- package/dist/agent-chat/index.d.ts +24 -0
- package/dist/agent-chat/index.d.ts.map +1 -0
- package/dist/agent-chat/index.js +15 -0
- package/dist/agent-chat/thread-detail-panel.d.ts +27 -0
- package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -0
- package/dist/agent-chat/thread-detail-panel.js +108 -0
- package/dist/agent-chat/thread-feed.d.ts +18 -0
- package/dist/agent-chat/thread-feed.d.ts.map +1 -0
- package/dist/agent-chat/thread-feed.js +42 -0
- package/dist/agent-chat/thread-message.d.ts +31 -0
- package/dist/agent-chat/thread-message.d.ts.map +1 -0
- package/dist/agent-chat/thread-message.js +128 -0
- package/dist/agent-chat/thread-outcome-card.d.ts +19 -0
- package/dist/agent-chat/thread-outcome-card.d.ts.map +1 -0
- package/dist/agent-chat/thread-outcome-card.js +120 -0
- package/dist/agent-chat/thread-workspace.d.ts +27 -0
- package/dist/agent-chat/thread-workspace.d.ts.map +1 -0
- package/dist/agent-chat/thread-workspace.js +95 -0
- package/dist/charts/hooks/useChartSize.d.ts +25 -0
- package/dist/charts/hooks/useChartSize.d.ts.map +1 -0
- package/dist/charts/hooks/useChartSize.js +8 -0
- package/dist/charts/hooks/useChartTooltip.d.ts +13 -0
- package/dist/charts/hooks/useChartTooltip.d.ts.map +1 -0
- package/dist/charts/hooks/useChartTooltip.js +26 -0
- package/dist/charts/hooks/useHoverSync.d.ts +30 -0
- package/dist/charts/hooks/useHoverSync.d.ts.map +1 -0
- package/dist/charts/hooks/useHoverSync.js +70 -0
- package/dist/charts/hover-context.d.ts +21 -0
- package/dist/charts/hover-context.d.ts.map +1 -0
- package/dist/charts/hover-context.js +12 -0
- package/dist/charts/hover-sync.d.ts +14 -0
- package/dist/charts/hover-sync.d.ts.map +1 -0
- package/dist/charts/hover-sync.js +17 -0
- package/dist/charts/index.d.ts +47 -0
- package/dist/charts/index.d.ts.map +1 -0
- package/dist/charts/index.js +129 -0
- package/dist/charts/kinds/Bars.d.ts +129 -0
- package/dist/charts/kinds/Bars.d.ts.map +1 -0
- package/dist/charts/kinds/Bars.js +467 -0
- package/dist/charts/kinds/Donut.d.ts +65 -0
- package/dist/charts/kinds/Donut.d.ts.map +1 -0
- package/dist/charts/kinds/Donut.js +158 -0
- package/dist/charts/kinds/DualPanel.d.ts +67 -0
- package/dist/charts/kinds/DualPanel.d.ts.map +1 -0
- package/dist/charts/kinds/DualPanel.js +326 -0
- package/dist/charts/kinds/Heatmap.d.ts +59 -0
- package/dist/charts/kinds/Heatmap.d.ts.map +1 -0
- package/dist/charts/kinds/Heatmap.js +175 -0
- package/dist/charts/kinds/MultiLine.d.ts +73 -0
- package/dist/charts/kinds/MultiLine.d.ts.map +1 -0
- package/dist/charts/kinds/MultiLine.js +275 -0
- package/dist/charts/kinds/StackedArea.d.ts +35 -0
- package/dist/charts/kinds/StackedArea.d.ts.map +1 -0
- package/dist/charts/kinds/StackedArea.js +151 -0
- package/dist/charts/kinds/ZonedLine.d.ts +94 -0
- package/dist/charts/kinds/ZonedLine.d.ts.map +1 -0
- package/dist/charts/kinds/ZonedLine.js +218 -0
- package/dist/charts/primitives/AreaGradient.d.ts +18 -0
- package/dist/charts/primitives/AreaGradient.d.ts.map +1 -0
- package/dist/charts/primitives/AreaGradient.js +13 -0
- package/dist/charts/primitives/Axes.d.ts +22 -0
- package/dist/charts/primitives/Axes.d.ts.map +1 -0
- package/dist/charts/primitives/Axes.js +79 -0
- package/dist/charts/primitives/ChartCard.d.ts +14 -0
- package/dist/charts/primitives/ChartCard.d.ts.map +1 -0
- package/dist/charts/primitives/ChartCard.js +144 -0
- package/dist/charts/primitives/ChartFrame.d.ts +70 -0
- package/dist/charts/primitives/ChartFrame.d.ts.map +1 -0
- package/dist/charts/primitives/ChartFrame.js +77 -0
- package/dist/charts/primitives/ChartLegend.d.ts +36 -0
- package/dist/charts/primitives/ChartLegend.d.ts.map +1 -0
- package/dist/charts/primitives/ChartLegend.js +234 -0
- package/dist/charts/primitives/ChartTooltip.d.ts +34 -0
- package/dist/charts/primitives/ChartTooltip.d.ts.map +1 -0
- package/dist/charts/primitives/ChartTooltip.js +134 -0
- package/dist/charts/primitives/Crosshair.d.ts +23 -0
- package/dist/charts/primitives/Crosshair.d.ts.map +1 -0
- package/dist/charts/primitives/Crosshair.js +21 -0
- package/dist/charts/primitives/HoverOverlay.d.ts +9 -0
- package/dist/charts/primitives/HoverOverlay.d.ts.map +1 -0
- package/dist/charts/primitives/HoverOverlay.js +21 -0
- package/dist/charts/primitives/ResponsiveChart.d.ts +45 -0
- package/dist/charts/primitives/ResponsiveChart.d.ts.map +1 -0
- package/dist/charts/primitives/ResponsiveChart.js +24 -0
- package/dist/charts/primitives/ZoneRects.d.ts +38 -0
- package/dist/charts/primitives/ZoneRects.d.ts.map +1 -0
- package/dist/charts/primitives/ZoneRects.js +30 -0
- package/dist/charts/series.d.ts +99 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +55 -0
- package/dist/charts/sparklines/BarSparkline.d.ts +13 -0
- package/dist/charts/sparklines/BarSparkline.d.ts.map +1 -0
- package/dist/charts/sparklines/BarSparkline.js +33 -0
- package/dist/charts/sparklines/LineSparkline.d.ts +15 -0
- package/dist/charts/sparklines/LineSparkline.d.ts.map +1 -0
- package/dist/charts/sparklines/LineSparkline.js +39 -0
- package/dist/charts/sparklines/index.d.ts +3 -0
- package/dist/charts/sparklines/index.d.ts.map +1 -0
- package/dist/charts/sparklines/index.js +6 -0
- package/dist/charts/theme.d.ts +21 -0
- package/dist/charts/theme.d.ts.map +1 -0
- package/dist/charts/theme.js +30 -0
- package/dist/charts/utils/domain.d.ts +20 -0
- package/dist/charts/utils/domain.d.ts.map +1 -0
- package/dist/charts/utils/domain.js +7 -0
- package/dist/charts/utils/format.d.ts +5 -0
- package/dist/charts/utils/format.d.ts.map +1 -0
- package/dist/charts/utils/format.js +27 -0
- package/dist/charts/utils/ticks.d.ts +5 -0
- package/dist/charts/utils/ticks.d.ts.map +1 -0
- package/dist/charts/utils/ticks.js +18 -0
- package/dist/cli/index.d.ts +292 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +889 -0
- package/dist/commands/ShortcutsHelp.d.ts +17 -0
- package/dist/commands/ShortcutsHelp.d.ts.map +1 -0
- package/dist/commands/ShortcutsHelp.js +64 -0
- package/dist/commands/define-commands.d.ts +140 -0
- package/dist/commands/define-commands.d.ts.map +1 -0
- package/dist/commands/define-commands.js +26 -0
- package/dist/commands/define-overlays.d.ts +134 -0
- package/dist/commands/define-overlays.d.ts.map +1 -0
- package/dist/commands/define-overlays.js +53 -0
- package/dist/commands/index.d.ts +42 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +46 -0
- package/dist/commands/overlays-mount.d.ts +117 -0
- package/dist/commands/overlays-mount.d.ts.map +1 -0
- package/dist/commands/overlays-mount.js +116 -0
- package/dist/commands/projectors.d.ts +152 -0
- package/dist/commands/projectors.d.ts.map +1 -0
- package/dist/commands/projectors.js +87 -0
- package/dist/commands/shortcut-format.d.ts +48 -0
- package/dist/commands/shortcut-format.d.ts.map +1 -0
- package/dist/commands/shortcut-format.js +33 -0
- package/dist/commands/useCommandHotkeys.d.ts +14 -0
- package/dist/commands/useCommandHotkeys.d.ts.map +1 -0
- package/dist/commands/useCommandHotkeys.js +45 -0
- package/dist/connectivity/connectivity-indicator.d.ts +8 -0
- package/dist/connectivity/connectivity-indicator.d.ts.map +1 -0
- package/dist/connectivity/connectivity-indicator.js +203 -0
- package/dist/connectivity/connectivity-provider.d.ts +7 -0
- package/dist/connectivity/connectivity-provider.d.ts.map +1 -0
- package/dist/connectivity/connectivity-provider.js +125 -0
- package/dist/connectivity/index.d.ts +13 -0
- package/dist/connectivity/index.d.ts.map +1 -0
- package/dist/connectivity/index.js +8 -0
- package/dist/connectivity/types.d.ts +36 -0
- package/dist/connectivity/types.d.ts.map +1 -0
- package/dist/connectivity/types.js +0 -0
- package/dist/connectivity/use-connectivity.d.ts +3 -0
- package/dist/connectivity/use-connectivity.d.ts.map +1 -0
- package/dist/connectivity/use-connectivity.js +14 -0
- package/dist/content/article-actions.d.ts +39 -0
- package/dist/content/article-actions.d.ts.map +1 -0
- package/dist/content/article-actions.js +28 -0
- package/dist/content/article-card.d.ts +58 -0
- package/dist/content/article-card.d.ts.map +1 -0
- package/dist/content/article-card.js +76 -0
- package/dist/content/article-card.module.css +109 -0
- package/dist/content/article-card.module.css.d.ts +16 -0
- package/dist/content/article-filter-bar.d.ts +40 -0
- package/dist/content/article-filter-bar.d.ts.map +1 -0
- package/dist/content/article-filter-bar.js +56 -0
- package/dist/content/article-layout.d.ts +61 -0
- package/dist/content/article-layout.d.ts.map +1 -0
- package/dist/content/article-layout.js +71 -0
- package/dist/content/article-layout.module.css +131 -0
- package/dist/content/article-layout.module.css.d.ts +20 -0
- package/dist/content/article-model.d.ts +62 -0
- package/dist/content/article-model.d.ts.map +1 -0
- package/dist/content/article-model.js +41 -0
- package/dist/content/block-split.d.ts +24 -0
- package/dist/content/block-split.d.ts.map +1 -0
- package/dist/content/block-split.js +63 -0
- package/dist/content/callout-alert.d.ts +27 -0
- package/dist/content/callout-alert.d.ts.map +1 -0
- package/dist/content/callout-alert.js +59 -0
- package/dist/content/callout.d.ts +24 -0
- package/dist/content/callout.d.ts.map +1 -0
- package/dist/content/callout.js +59 -0
- package/dist/content/callout.module.css +77 -0
- package/dist/content/callout.module.css.d.ts +16 -0
- package/dist/content/code-block.d.ts +26 -0
- package/dist/content/code-block.d.ts.map +1 -0
- package/dist/content/code-block.js +41 -0
- package/dist/content/code-block.module.css +86 -0
- package/dist/content/code-block.module.css.d.ts +14 -0
- package/dist/content/copy-action.d.ts +29 -0
- package/dist/content/copy-action.d.ts.map +1 -0
- package/dist/content/copy-action.js +46 -0
- package/dist/content/fence-block.d.ts +19 -0
- package/dist/content/fence-block.d.ts.map +1 -0
- package/dist/content/fence-block.js +23 -0
- package/dist/content/glyphs.d.ts +18 -0
- package/dist/content/glyphs.d.ts.map +1 -0
- package/dist/content/glyphs.js +43 -0
- package/dist/content/guide.d.ts +47 -0
- package/dist/content/guide.d.ts.map +1 -0
- package/dist/content/guide.js +110 -0
- package/dist/content/guide.module.css +62 -0
- package/dist/content/guide.module.css.d.ts +13 -0
- package/dist/content/heading-anchor.d.ts +8 -0
- package/dist/content/heading-anchor.d.ts.map +1 -0
- package/dist/content/heading-anchor.js +23 -0
- package/dist/content/heading-components.d.ts +5 -0
- package/dist/content/heading-components.d.ts.map +1 -0
- package/dist/content/heading-components.js +41 -0
- package/dist/content/highlighter.d.ts +8 -0
- package/dist/content/highlighter.d.ts.map +1 -0
- package/dist/content/highlighter.js +85 -0
- package/dist/content/index.d.ts +45 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +43 -0
- package/dist/content/markdown-hast.d.ts +23 -0
- package/dist/content/markdown-hast.d.ts.map +1 -0
- package/dist/content/markdown-hast.js +48 -0
- package/dist/content/markdown.d.ts +68 -0
- package/dist/content/markdown.d.ts.map +1 -0
- package/dist/content/markdown.js +180 -0
- package/dist/content/mdx.d.ts +20 -0
- package/dist/content/mdx.d.ts.map +1 -0
- package/dist/content/mdx.js +64 -0
- package/dist/content/mermaid.d.ts +32 -0
- package/dist/content/mermaid.d.ts.map +1 -0
- package/dist/content/mermaid.js +70 -0
- package/dist/content/mermaid.module.css +20 -0
- package/dist/content/mermaid.module.css.d.ts +8 -0
- package/dist/content/prose.d.ts +29 -0
- package/dist/content/prose.d.ts.map +1 -0
- package/dist/content/prose.js +24 -0
- package/dist/content/prose.module.css +330 -0
- package/dist/content/prose.module.css.d.ts +12 -0
- package/dist/content/reading-progress.d.ts +20 -0
- package/dist/content/reading-progress.d.ts.map +1 -0
- package/dist/content/reading-progress.js +38 -0
- package/dist/content/reading-progress.module.css +22 -0
- package/dist/content/reading-progress.module.css.d.ts +9 -0
- package/dist/content/slug.d.ts +28 -0
- package/dist/content/slug.d.ts.map +1 -0
- package/dist/content/slug.js +28 -0
- package/dist/content/toc.d.ts +37 -0
- package/dist/content/toc.d.ts.map +1 -0
- package/dist/content/toc.js +134 -0
- package/dist/content/toc.module.css +51 -0
- package/dist/content/toc.module.css.d.ts +13 -0
- package/dist/content/url-hardening.d.ts +23 -0
- package/dist/content/url-hardening.d.ts.map +1 -0
- package/dist/content/url-hardening.js +23 -0
- package/dist/dashboard/delta-badge.d.ts +13 -0
- package/dist/dashboard/delta-badge.d.ts.map +1 -0
- package/dist/dashboard/delta-badge.js +45 -0
- package/dist/dashboard/empty-state.d.ts +15 -0
- package/dist/dashboard/empty-state.d.ts.map +1 -0
- package/dist/dashboard/empty-state.js +56 -0
- package/dist/dashboard/index.d.ts +5 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +16 -0
- package/dist/dashboard/settings-section.d.ts +24 -0
- package/dist/dashboard/settings-section.d.ts.map +1 -0
- package/dist/dashboard/settings-section.js +61 -0
- package/dist/dashboard/settings-section.module.css +23 -0
- package/dist/dashboard/settings-section.module.css.d.ts +10 -0
- package/dist/dashboard/stat-card.d.ts +18 -0
- package/dist/dashboard/stat-card.d.ts.map +1 -0
- package/dist/dashboard/stat-card.js +74 -0
- package/dist/data/data-table.d.ts +198 -0
- package/dist/data/data-table.d.ts.map +1 -0
- package/dist/data/data-table.js +342 -0
- package/dist/data/index.d.ts +34 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +2 -0
- package/dist/data/table.d.ts +24 -0
- package/dist/data/table.d.ts.map +1 -0
- package/dist/data/table.js +20 -0
- package/dist/data/virtual-list.d.ts +74 -0
- package/dist/data/virtual-list.d.ts.map +1 -0
- package/dist/data/virtual-list.js +86 -0
- package/dist/data/virtual.d.ts +20 -0
- package/dist/data/virtual.d.ts.map +1 -0
- package/dist/data/virtual.js +4 -0
- package/dist/forms/FormErrorSummary.d.ts +29 -0
- package/dist/forms/FormErrorSummary.d.ts.map +1 -0
- package/dist/forms/FormErrorSummary.js +28 -0
- package/dist/forms/create-form.d.ts +31 -0
- package/dist/forms/create-form.d.ts.map +1 -0
- package/dist/forms/create-form.js +18 -0
- package/dist/forms/field.d.ts +22 -0
- package/dist/forms/field.d.ts.map +1 -0
- package/dist/forms/field.js +9 -0
- package/dist/forms/index.d.ts +17 -0
- package/dist/forms/index.d.ts.map +1 -0
- package/dist/forms/index.js +13 -0
- package/dist/forms/use-form-draft.d.ts +61 -0
- package/dist/forms/use-form-draft.d.ts.map +1 -0
- package/dist/forms/use-form-draft.js +55 -0
- package/dist/guard/guard-hook.d.ts +40 -0
- package/dist/guard/guard-hook.d.ts.map +1 -0
- package/dist/guard/guard-hook.js +55 -0
- package/dist/guard/index.d.ts +144 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +315 -0
- package/dist/guard/types.d.ts +97 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +0 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/motion/index.d.ts +29 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion/index.js +12 -0
- package/dist/notifications/bell.d.ts +12 -0
- package/dist/notifications/bell.d.ts.map +1 -0
- package/dist/notifications/bell.js +84 -0
- package/dist/notifications/center.d.ts +20 -0
- package/dist/notifications/center.d.ts.map +1 -0
- package/dist/notifications/center.js +144 -0
- package/dist/notifications/define-notifications.d.ts +97 -0
- package/dist/notifications/define-notifications.d.ts.map +1 -0
- package/dist/notifications/define-notifications.js +27 -0
- package/dist/notifications/index.d.ts +36 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +52 -0
- package/dist/notifications/notify.d.ts +92 -0
- package/dist/notifications/notify.d.ts.map +1 -0
- package/dist/notifications/notify.js +127 -0
- package/dist/notifications/overlay.d.ts +20 -0
- package/dist/notifications/overlay.d.ts.map +1 -0
- package/dist/notifications/overlay.js +12 -0
- package/dist/notifications/store.d.ts +120 -0
- package/dist/notifications/store.d.ts.map +1 -0
- package/dist/notifications/store.js +113 -0
- package/dist/provider/index.d.ts +93 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +106 -0
- package/dist/query/devtools.d.ts +21 -0
- package/dist/query/devtools.d.ts.map +1 -0
- package/dist/query/devtools.js +12 -0
- package/dist/query/index.d.ts +65 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +68 -0
- package/dist/register.d.ts +139 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +6 -0
- package/dist/router-tanstack/index.d.ts +74 -0
- package/dist/router-tanstack/index.d.ts.map +1 -0
- package/dist/router-tanstack/index.js +29 -0
- package/dist/router-tanstack/multi-search-param-store.d.ts +78 -0
- package/dist/router-tanstack/multi-search-param-store.d.ts.map +1 -0
- package/dist/router-tanstack/multi-search-param-store.js +35 -0
- package/dist/router-tanstack/search-param-store.d.ts +92 -0
- package/dist/router-tanstack/search-param-store.d.ts.map +1 -0
- package/dist/router-tanstack/search-param-store.js +26 -0
- package/dist/shell/account-types.d.ts +118 -0
- package/dist/shell/account-types.d.ts.map +1 -0
- package/dist/shell/account-types.js +0 -0
- package/dist/shell/app-breadcrumbs.d.ts +17 -0
- package/dist/shell/app-breadcrumbs.d.ts.map +1 -0
- package/dist/shell/app-breadcrumbs.js +39 -0
- package/dist/shell/app-header.module.css +73 -0
- package/dist/shell/app-header.module.css.d.ts +11 -0
- package/dist/shell/app-mobile-nav.d.ts +26 -0
- package/dist/shell/app-mobile-nav.d.ts.map +1 -0
- package/dist/shell/app-mobile-nav.js +106 -0
- package/dist/shell/app-mobile-nav.module.css +100 -0
- package/dist/shell/app-mobile-nav.module.css.d.ts +14 -0
- package/dist/shell/app-sidebar-account.d.ts +3 -0
- package/dist/shell/app-sidebar-account.d.ts.map +1 -0
- package/dist/shell/app-sidebar-account.js +84 -0
- package/dist/shell/app-sidebar.d.ts +56 -0
- package/dist/shell/app-sidebar.d.ts.map +1 -0
- package/dist/shell/app-sidebar.js +455 -0
- package/dist/shell/app-sidebar.module.css +414 -0
- package/dist/shell/app-sidebar.module.css.d.ts +34 -0
- package/dist/shell/index.d.ts +123 -0
- package/dist/shell/index.d.ts.map +1 -0
- package/dist/shell/index.js +179 -0
- package/dist/shell/page-header.d.ts +13 -0
- package/dist/shell/page-header.d.ts.map +1 -0
- package/dist/shell/page-header.js +23 -0
- package/dist/shell/sidebar-search.d.ts +12 -0
- package/dist/shell/sidebar-search.d.ts.map +1 -0
- package/dist/shell/sidebar-search.js +62 -0
- package/dist/shell/sidebar-search.module.css +62 -0
- package/dist/shell/sidebar-search.module.css.d.ts +11 -0
- package/dist/state.d.ts +62 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +124 -0
- package/dist/styles.css +166 -0
- package/dist/surfaces.d.ts +386 -0
- package/dist/surfaces.d.ts.map +1 -0
- package/dist/surfaces.js +312 -0
- package/dist/theme/controls.module.css +143 -0
- package/dist/theme/controls.module.css.d.ts +17 -0
- package/dist/theme/floating.module.css +35 -0
- package/dist/theme/floating.module.css.d.ts +9 -0
- package/dist/theme/index.d.ts +22 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +733 -0
- package/dist/theme/nav-link.module.css +67 -0
- package/dist/theme/nav-link.module.css.d.ts +8 -0
- package/dist/theme/segmented-control.module.css +14 -0
- package/dist/theme/segmented-control.module.css.d.ts +8 -0
- package/dist/theme/timeline.module.css +29 -0
- package/dist/theme/timeline.module.css.d.ts +9 -0
- package/dist/theme-lab/index.d.ts +59 -0
- package/dist/theme-lab/index.d.ts.map +1 -0
- package/dist/theme-lab/index.js +263 -0
- package/dist/theme-toggle/index.d.ts +8 -0
- package/dist/theme-toggle/index.d.ts.map +1 -0
- package/dist/theme-toggle/index.js +155 -0
- package/dist/tokens/index.d.ts +152 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +249 -0
- package/dist/tokens/palette.d.ts +304 -0
- package/dist/tokens/palette.d.ts.map +1 -0
- package/dist/tokens/palette.js +186 -0
- package/dist/vite.d.ts +30 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +68 -0
- package/llms.txt +149 -0
- package/package.json +243 -46
- package/src/agent/ai-sdk-transport.ts +280 -0
- package/src/agent/history.ts +128 -0
- package/src/agent/index.ts +92 -0
- package/src/agent/outcome.ts +120 -0
- package/src/agent/part-list.tsx +292 -0
- package/src/agent/parts.ts +136 -0
- package/src/agent/stick-to-bottom.tsx +154 -0
- package/src/agent/thread.ts +312 -0
- package/src/agent/transport.ts +114 -0
- package/src/agent/use-agent-stream.ts +141 -0
- package/src/agent/use-agent-thread-runs.ts +440 -0
- package/src/agent-chat/composer.tsx +131 -0
- package/src/agent-chat/index.ts +35 -0
- package/src/agent-chat/thread-detail-panel.tsx +192 -0
- package/src/agent-chat/thread-feed.tsx +81 -0
- package/src/agent-chat/thread-message.tsx +251 -0
- package/src/agent-chat/thread-outcome-card.tsx +196 -0
- package/src/agent-chat/thread-workspace.tsx +179 -0
- package/src/charts/hooks/useChartSize.ts +31 -0
- package/src/charts/hooks/useChartTooltip.ts +31 -0
- package/src/charts/hooks/useHoverSync.ts +116 -0
- package/src/charts/hover-context.ts +28 -0
- package/src/charts/hover-sync.tsx +37 -0
- package/src/charts/index.ts +118 -0
- package/src/charts/kinds/Bars.tsx +634 -0
- package/src/charts/kinds/Donut.tsx +233 -0
- package/src/charts/kinds/DualPanel.tsx +432 -0
- package/src/charts/kinds/Heatmap.tsx +255 -0
- package/src/charts/kinds/MultiLine.tsx +376 -0
- package/src/charts/kinds/StackedArea.tsx +218 -0
- package/src/charts/kinds/ZonedLine.tsx +346 -0
- package/src/charts/primitives/AreaGradient.tsx +26 -0
- package/src/charts/primitives/Axes.tsx +97 -0
- package/src/charts/primitives/ChartCard.tsx +180 -0
- package/src/charts/primitives/ChartFrame.tsx +157 -0
- package/src/charts/primitives/ChartLegend.tsx +302 -0
- package/src/charts/primitives/ChartTooltip.tsx +158 -0
- package/src/charts/primitives/Crosshair.tsx +40 -0
- package/src/charts/primitives/HoverOverlay.tsx +24 -0
- package/src/charts/primitives/ResponsiveChart.tsx +64 -0
- package/src/charts/primitives/ZoneRects.tsx +67 -0
- package/src/charts/series.ts +163 -0
- package/src/charts/sparklines/BarSparkline.tsx +48 -0
- package/src/charts/sparklines/LineSparkline.tsx +57 -0
- package/src/charts/sparklines/index.ts +2 -0
- package/src/charts/theme.tsx +53 -0
- package/src/charts/utils/domain.test.ts +24 -0
- package/src/charts/utils/domain.ts +22 -0
- package/src/charts/utils/format.ts +27 -0
- package/src/charts/utils/ticks.ts +18 -0
- package/src/cli/check-theme.test.ts +668 -0
- package/src/cli/help.test.ts +93 -0
- package/src/cli/index.ts +1535 -0
- package/src/cli/init-sync.test.ts +160 -0
- package/src/cli/placement-engine.test.ts +194 -0
- package/src/cli/tarball-parity.test.ts +44 -0
- package/src/cli/template-format.test.ts +64 -0
- package/src/commands/ShortcutsHelp.tsx +129 -0
- package/src/commands/define-commands.ts +184 -0
- package/src/commands/define-overlays.ts +197 -0
- package/src/commands/index.ts +86 -0
- package/src/commands/overlays-mount.tsx +301 -0
- package/src/commands/projectors.ts +267 -0
- package/src/commands/shortcut-format.ts +83 -0
- package/src/commands/useCommandHotkeys.ts +114 -0
- package/src/connectivity/connectivity-indicator.tsx +249 -0
- package/src/connectivity/connectivity-provider.tsx +186 -0
- package/src/connectivity/index.ts +18 -0
- package/src/connectivity/types.ts +39 -0
- package/src/connectivity/use-connectivity.ts +25 -0
- package/src/content/article-actions.test.ts +78 -0
- package/src/content/article-actions.ts +72 -0
- package/src/content/article-card.module.css +109 -0
- package/src/content/article-card.module.css.d.ts +16 -0
- package/src/content/article-card.tsx +173 -0
- package/src/content/article-filter-bar.tsx +88 -0
- package/src/content/article-layout.module.css +131 -0
- package/src/content/article-layout.module.css.d.ts +20 -0
- package/src/content/article-layout.tsx +167 -0
- package/src/content/article-model.test.ts +119 -0
- package/src/content/article-model.ts +110 -0
- package/src/content/block-split.test.ts +75 -0
- package/src/content/block-split.ts +102 -0
- package/src/content/callout-alert.ts +88 -0
- package/src/content/callout.module.css +77 -0
- package/src/content/callout.module.css.d.ts +16 -0
- package/src/content/callout.tsx +96 -0
- package/src/content/code-block.module.css +86 -0
- package/src/content/code-block.module.css.d.ts +14 -0
- package/src/content/code-block.tsx +82 -0
- package/src/content/copy-action.tsx +79 -0
- package/src/content/fence-block.tsx +39 -0
- package/src/content/glyphs.tsx +53 -0
- package/src/content/guide.module.css +62 -0
- package/src/content/guide.module.css.d.ts +13 -0
- package/src/content/guide.tsx +174 -0
- package/src/content/heading-anchor.tsx +54 -0
- package/src/content/heading-components.tsx +62 -0
- package/src/content/highlighter.ts +123 -0
- package/src/content/index.ts +60 -0
- package/src/content/markdown-hast.ts +80 -0
- package/src/content/markdown.tsx +346 -0
- package/src/content/mdx.tsx +127 -0
- package/src/content/mermaid.module.css +20 -0
- package/src/content/mermaid.module.css.d.ts +8 -0
- package/src/content/mermaid.tsx +124 -0
- package/src/content/prose.module.css +330 -0
- package/src/content/prose.module.css.d.ts +12 -0
- package/src/content/prose.tsx +53 -0
- package/src/content/reading-progress.module.css +22 -0
- package/src/content/reading-progress.module.css.d.ts +9 -0
- package/src/content/reading-progress.tsx +67 -0
- package/src/content/slug.test.ts +62 -0
- package/src/content/slug.ts +57 -0
- package/src/content/toc.module.css +51 -0
- package/src/content/toc.module.css.d.ts +13 -0
- package/src/content/toc.tsx +226 -0
- package/src/content/url-hardening.ts +46 -0
- package/src/dashboard/delta-badge.tsx +70 -0
- package/src/dashboard/empty-state.tsx +80 -0
- package/src/dashboard/index.ts +11 -0
- package/src/dashboard/settings-section.module.css +23 -0
- package/src/dashboard/settings-section.module.css.d.ts +10 -0
- package/src/dashboard/settings-section.tsx +118 -0
- package/src/dashboard/stat-card.tsx +105 -0
- package/src/data/data-table.tsx +695 -0
- package/src/data/index.ts +37 -0
- package/src/data/table.ts +46 -0
- package/src/data/virtual-list.tsx +180 -0
- package/src/data/virtual.ts +21 -0
- package/src/forms/FormErrorSummary.tsx +64 -0
- package/src/forms/create-form.ts +57 -0
- package/src/forms/field.ts +30 -0
- package/src/forms/index.ts +26 -0
- package/src/forms/use-form-draft.ts +170 -0
- package/src/guard/check-source.test.ts +834 -0
- package/src/guard/guard-hook.test.ts +173 -0
- package/src/guard/guard-hook.ts +122 -0
- package/src/guard/index.ts +510 -0
- package/src/guard/types.ts +117 -0
- package/src/index.ts +139 -0
- package/src/motion/index.ts +26 -0
- package/src/notifications/bell.tsx +108 -0
- package/src/notifications/center.tsx +245 -0
- package/src/notifications/define-notifications.ts +162 -0
- package/src/notifications/index.ts +79 -0
- package/src/notifications/notify.tsx +260 -0
- package/src/notifications/overlay.tsx +64 -0
- package/src/notifications/store.ts +287 -0
- package/src/provider/index.tsx +234 -0
- package/src/query/devtools.tsx +38 -0
- package/src/query/index.ts +129 -0
- package/src/register.ts +158 -0
- package/src/router-tanstack/index.ts +111 -0
- package/src/router-tanstack/multi-search-param-store.test.ts +56 -0
- package/src/router-tanstack/multi-search-param-store.ts +122 -0
- package/src/router-tanstack/search-param-store.ts +125 -0
- package/src/shell/account-types.ts +119 -0
- package/src/shell/app-breadcrumbs.tsx +90 -0
- package/src/shell/app-header.module.css +73 -0
- package/src/shell/app-header.module.css.d.ts +11 -0
- package/src/shell/app-mobile-nav.module.css +100 -0
- package/src/shell/app-mobile-nav.module.css.d.ts +14 -0
- package/src/shell/app-mobile-nav.tsx +146 -0
- package/src/shell/app-sidebar-account.tsx +142 -0
- package/src/shell/app-sidebar.module.css +414 -0
- package/src/shell/app-sidebar.module.css.d.ts +34 -0
- package/src/shell/app-sidebar.tsx +632 -0
- package/src/shell/index.tsx +343 -0
- package/src/shell/page-header.tsx +35 -0
- package/src/shell/sidebar-search.module.css +62 -0
- package/src/shell/sidebar-search.module.css.d.ts +11 -0
- package/src/shell/sidebar-search.tsx +80 -0
- package/src/state.ts +246 -0
- package/src/styles.css +166 -0
- package/src/styles.floor.test.ts +36 -0
- package/src/surfaces.ts +508 -0
- package/src/theme/border-coverage.test.ts +272 -0
- package/src/theme/contrast.test.ts +306 -0
- package/src/theme/controls.module.css +143 -0
- package/src/theme/controls.module.css.d.ts +17 -0
- package/src/theme/floating.module.css +35 -0
- package/src/theme/floating.module.css.d.ts +9 -0
- package/src/theme/index.ts +933 -0
- package/src/theme/nav-link.module.css +67 -0
- package/src/theme/nav-link.module.css.d.ts +8 -0
- package/src/theme/segmented-control.module.css +14 -0
- package/src/theme/segmented-control.module.css.d.ts +8 -0
- package/src/theme/shadow-surfaces.test.ts +421 -0
- package/src/theme/timeline.module.css +29 -0
- package/src/theme/timeline.module.css.d.ts +9 -0
- package/src/theme-lab/index.tsx +359 -0
- package/src/theme-lab/theme-lab.test.ts +60 -0
- package/src/theme-toggle/index.tsx +180 -0
- package/src/tokens/index.ts +369 -0
- package/src/tokens/palette.ts +288 -0
- package/src/vite.ts +122 -0
- package/src/index.css +0 -877
- package/src/starlight.css +0 -308
- package/tailwind.config.js +0 -78
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,1535 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* basalt-ui CLI — `init`, `sync`, `check-theme`, `check-coverage`.
|
|
3
|
+
*
|
|
4
|
+
* `checkTheme` is a thin FS walker over the headless guard core (`../guard`). It reads the
|
|
5
|
+
* BasaltConfig, builds a GuardConfig, walks the source roots, calls `checkSource` per file,
|
|
6
|
+
* collects Finding[], groups/reports findings, and returns an exit code.
|
|
7
|
+
*
|
|
8
|
+
* `checkCoverage` asserts 8 invariants: guardKinds ⊆ GUARD_RULES, rule files on disk,
|
|
9
|
+
* skill union ⊆ plugin.json, subpath-export-coverage, exports→SURFACES reverse, globs
|
|
10
|
+
* required for non-empty forbiddenImports, headless Mantine-ban completeness, and
|
|
11
|
+
* optionalPeers peerDependencies/peerDependenciesMeta presence.
|
|
12
|
+
*
|
|
13
|
+
* `init` / `sync` scaffold and reconcile the framework's *agentic* surface into a consumer repo:
|
|
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
|
+
* idempotent three-way reconciliation. Dependency-free — Node/Bun built-ins only.
|
|
17
|
+
*
|
|
18
|
+
* Runtime-agnostic (Node or Bun) — built-ins only, no `bun`-module import, so the exported API is
|
|
19
|
+
* safe to import under plain Node. Config is read from the consuming package.json `"basalt"` key;
|
|
20
|
+
* argo's hardcoded values are the DEFAULTS.
|
|
21
|
+
*/
|
|
22
|
+
import { createHash } from 'node:crypto'
|
|
23
|
+
import {
|
|
24
|
+
existsSync,
|
|
25
|
+
mkdirSync,
|
|
26
|
+
readdirSync,
|
|
27
|
+
readFileSync,
|
|
28
|
+
statSync,
|
|
29
|
+
unlinkSync,
|
|
30
|
+
writeFileSync,
|
|
31
|
+
} from 'node:fs'
|
|
32
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path'
|
|
33
|
+
import { fileURLToPath } from 'node:url'
|
|
34
|
+
|
|
35
|
+
import { checkSource, DEFAULT_GUARD_CONFIG, GUARD_RULES } from '../guard'
|
|
36
|
+
import type { Finding, GuardConfig, GuardKind } from '../guard'
|
|
37
|
+
import { evaluateGuardHook } from '../guard/guard-hook'
|
|
38
|
+
import { RULE_NAMES, SKILL_NAMES, SURFACES } from '../surfaces'
|
|
39
|
+
import type { DoctrineSpec, SurfaceSpec } from '../surfaces'
|
|
40
|
+
|
|
41
|
+
/** Shape of the optional `"basalt"` key in a consumer's package.json. */
|
|
42
|
+
export type BasaltConfig = {
|
|
43
|
+
/** Source roots to scan. Default: `['src']`. Set explicitly for a monorepo layout. */
|
|
44
|
+
roots?: string[]
|
|
45
|
+
/** Files exempt from the scan (they ARE the palette source). Default: argo's exempt set. */
|
|
46
|
+
exempt?: string[]
|
|
47
|
+
/** Named spacing-scale steps (px) flagged when used as a raw spacing prop. Default: 10/12/16/20/32. */
|
|
48
|
+
spacingSteps?: number[]
|
|
49
|
+
/** Off-identity Mantine accent families forbidden as chrome accents. Default: argo's set. */
|
|
50
|
+
forbiddenAccents?: string[]
|
|
51
|
+
/** Earned accent hue recorded in DESIGN.md `{{ACCENT_HUE}}`. Default: `blue`. */
|
|
52
|
+
accentHue?: string
|
|
53
|
+
/**
|
|
54
|
+
* Flag any numeric radius prop literal (radius={6}) — use the radius token scale instead.
|
|
55
|
+
* Default: `true` (ON). Set `false` to disable the `raw-radius` check (e.g. a repo that DEFINES
|
|
56
|
+
* the radius primitives).
|
|
57
|
+
*/
|
|
58
|
+
rawRadius?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* Flag ad-hoc inline surface styling (`border`/`borderRadius`/`boxShadow` literals in a `style={{}}`)
|
|
61
|
+
* that bypasses the radius-token + `VX.surface.*` + `VX.shadowCard` system. Default: `true` (ON).
|
|
62
|
+
* Set `false` to disable the `raw-surface` check.
|
|
63
|
+
*/
|
|
64
|
+
rawSurface?: boolean
|
|
65
|
+
/**
|
|
66
|
+
* Flag `withBorder` on a `Card` / `Paper`. Card depth is `--vx-shadow-card` — a whisper shadow
|
|
67
|
+
* with the 1px ring baked into the SAME value — so `withBorder` draws a SECOND, real border over
|
|
68
|
+
* that ring and the card reads heavy/boxed (docs/DESIGN-SPEC.md doctrine inversion #1).
|
|
69
|
+
* `withBorder={false}` and `<Card.Section withBorder>` (a section divider) both pass.
|
|
70
|
+
* Default: `true` (ON). Set `false` to disable the `card-with-border` check.
|
|
71
|
+
*/
|
|
72
|
+
cardWithBorder?: boolean
|
|
73
|
+
/**
|
|
74
|
+
* Flag references to a raw Mantine ramp step used for surface color
|
|
75
|
+
* (`var(--mantine-color-gray-N)` / `var(--mantine-color-dark-N)`) — these bypass the basalt
|
|
76
|
+
* surface tokens. Default: `true` (ON). Set `false` to disable the `off-system-surface-var` check.
|
|
77
|
+
*/
|
|
78
|
+
offSystemSurfaceVar?: boolean
|
|
79
|
+
/**
|
|
80
|
+
* Flag raw lowercase JSX layout/surface elements (`div`/`span`/`section`/…) carrying an inline
|
|
81
|
+
* `style={{}}` with a layout/surface property — steer to a Mantine layout primitive
|
|
82
|
+
* (`Box`/`Flex`/`Grid`/`Stack`/`Group`/`SimpleGrid`/`Paper`). Default: `true` (ON). Set `false`
|
|
83
|
+
* to disable the `raw-html-layout` check.
|
|
84
|
+
*/
|
|
85
|
+
rawHtmlLayout?: boolean
|
|
86
|
+
/**
|
|
87
|
+
* Flag spacing/sizing literals inside an inline `style={{}}` (`padding`/`margin`/`gap`/…) — the
|
|
88
|
+
* `raw-spacing` check only catches the Mantine prop syntax. Default: `true` (ON). Set `false` to
|
|
89
|
+
* disable the `inline-spacing` check.
|
|
90
|
+
*/
|
|
91
|
+
inlineSpacing?: boolean
|
|
92
|
+
/**
|
|
93
|
+
* Flag `display: 'flex' | 'grid' | 'inline-flex' | 'inline-grid'` in an inline `style={{}}` —
|
|
94
|
+
* steer to `<Flex>`/`<Grid>`/`<Group>`. Default: `true` (ON). Set `false` to disable the
|
|
95
|
+
* `inline-display` check.
|
|
96
|
+
*/
|
|
97
|
+
inlineDisplay?: boolean
|
|
98
|
+
/**
|
|
99
|
+
* Flag raw `<AxisLeft>` / `<AxisBottom>` / `<AxisRight>` visx JSX inside chart files (a path
|
|
100
|
+
* containing `/charts/`) — these bypass the `AxisLeftNumeric` / `AxisBottomDate` /
|
|
101
|
+
* `AxisRightNumeric` primitives that carry the theme tokens + smart ticks. The legitimate wrapper
|
|
102
|
+
* (`Axes.tsx`, which IS the primitive) is exempt. Default: `true` (ON). Set `false` to disable the
|
|
103
|
+
* `raw-visx-axis` check.
|
|
104
|
+
*/
|
|
105
|
+
rawVisxAxis?: boolean
|
|
106
|
+
/**
|
|
107
|
+
* Flag a hardcoded duration/spring/ease literal inline in a `transition={{...}}` prop — route it
|
|
108
|
+
* through `MOTION_DURATION` / `MOTION_SPRING` / `MOTION_EASE_STANDARD` instead. Default: `true`
|
|
109
|
+
* (ON). Set `false` to disable the `raw-motion-value` check.
|
|
110
|
+
*/
|
|
111
|
+
rawMotionValue?: boolean
|
|
112
|
+
/**
|
|
113
|
+
* Flag a hand-rolled `<ChartLegend items={[...]}>` array literal — legend entries must be
|
|
114
|
+
* derived (e.g. `items={deriveLegend(series)}`), never authored inline. Default: `true` (ON).
|
|
115
|
+
* Set `false` to disable the `unframed-chart` check.
|
|
116
|
+
*/
|
|
117
|
+
unframedChart?: boolean
|
|
118
|
+
/**
|
|
119
|
+
* Flag a chart entry-point JSX tag (`MultiLine`/`Bars`/`Donut`/`DualPanel`/`Heatmap`/`ZonedLine`/
|
|
120
|
+
* `StackedArea`/`LineSparkline`/`BarSparkline`) missing an `ariaLabel` prop. Default: `true`
|
|
121
|
+
* (ON). Set `false` to disable the `chart-missing-aria-label` check.
|
|
122
|
+
*/
|
|
123
|
+
chartMissingAriaLabel?: boolean
|
|
124
|
+
/**
|
|
125
|
+
* Flag a raw lowercase `<input>`/`<select>`/`<textarea>` JSX element — it bypasses the entire
|
|
126
|
+
* theme, not just the iOS font-size floor. Use the Mantine equivalents (`TextInput`,
|
|
127
|
+
* `NumberInput`, `Select`, `Textarea`, …) instead. Default: `true` (ON). Set `false` to disable
|
|
128
|
+
* the `raw-form-control` check.
|
|
129
|
+
*/
|
|
130
|
+
rawFormControl?: boolean
|
|
131
|
+
/**
|
|
132
|
+
* Flag a `fontSize`/`font-size` literal below 16 inside a `style={{…}}` on a raw form control,
|
|
133
|
+
* or a Mantine `styles={{ input: {…} }}` per-part style — the `styles.css` iOS floor is
|
|
134
|
+
* `!important`, so the override is dead code. Default: `true` (ON). Set `false` to disable the
|
|
135
|
+
* `sub-16-input-font` check.
|
|
136
|
+
*/
|
|
137
|
+
sub16InputFont?: boolean
|
|
138
|
+
/** Path of the consumer's guard-exempt series file, for DESIGN.md `{{SERIES_MODULE_PATH}}`. Default: `src/lib/series.ts`. */
|
|
139
|
+
seriesModulePath?: string
|
|
140
|
+
}
|
|
141
|
+
|
|
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'
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Default scan exemption — a bare consumer's only palette source is its configured series module
|
|
153
|
+
* (the doctrine directs every consumer to put raw hex series colors in `seriesModulePath`; default
|
|
154
|
+
* `src/lib/series.ts`). Derived from the same config resolution `buildTemplateVars` uses for
|
|
155
|
+
* `{{SERIES_MODULE_PATH}}`, so overriding `seriesModulePath` keeps the exemption in sync.
|
|
156
|
+
*/
|
|
157
|
+
function defaultExempt(cfg: BasaltConfig): string[] {
|
|
158
|
+
return [cfg.seriesModulePath ?? DEFAULT_SERIES_MODULE_PATH]
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const SKIP = /\.gen\.ts$|\.test\.[tj]sx?$|\.d\.ts$/
|
|
162
|
+
/** Filenames that look like they ARE the palette source, for the check-theme escape-hatch hint. */
|
|
163
|
+
const SERIES_MODULE_HINT_RE = /(series|palette)\.tsx?$/i
|
|
164
|
+
|
|
165
|
+
function readBasaltConfig(cwd: string): BasaltConfig {
|
|
166
|
+
try {
|
|
167
|
+
const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as {
|
|
168
|
+
basalt?: BasaltConfig
|
|
169
|
+
}
|
|
170
|
+
return pkg.basalt ?? {}
|
|
171
|
+
} catch {
|
|
172
|
+
return {}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Recursively collect .ts/.tsx files under a root, skipping dependency/build dirs. Node+Bun-safe. */
|
|
177
|
+
function walkTsFiles(dir: string, out: string[] = []): string[] {
|
|
178
|
+
let entries: string[]
|
|
179
|
+
try {
|
|
180
|
+
entries = readdirSync(dir)
|
|
181
|
+
} catch {
|
|
182
|
+
return out // root absent — nothing to scan
|
|
183
|
+
}
|
|
184
|
+
for (const name of entries) {
|
|
185
|
+
if (name === 'node_modules' || name === '.git' || name === 'dist') continue
|
|
186
|
+
const abs = resolve(dir, name)
|
|
187
|
+
let isDir: boolean
|
|
188
|
+
try {
|
|
189
|
+
isDir = statSync(abs).isDirectory()
|
|
190
|
+
} catch {
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
if (isDir) walkTsFiles(abs, out)
|
|
194
|
+
else if (/\.tsx?$/.test(name)) out.push(abs)
|
|
195
|
+
}
|
|
196
|
+
return out
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* One-line fix guidance per guard kind, printed in the check-theme "Fix:" epilogue — only for the
|
|
201
|
+
* kinds actually present in a given run's findings, so the epilogue never dumps all 16+ rules on a
|
|
202
|
+
* single-kind violation. Kinds without an entry here (e.g. `localstorage-theme`,
|
|
203
|
+
* `chart-missing-aria-label`) fall back to the generic `theme-allow` closer only.
|
|
204
|
+
*/
|
|
205
|
+
const GUARD_KIND_EXPLANATIONS: Partial<Record<GuardKind, string>> = {
|
|
206
|
+
'raw-hex':
|
|
207
|
+
'raw-hex: route color through VX.* / the Mantine theme instead of a hardcoded hex literal.',
|
|
208
|
+
'raw-color-fn':
|
|
209
|
+
'raw-color-fn: route color through VX.* / the Mantine theme instead of a hardcoded rgb()/hsl() literal.',
|
|
210
|
+
'off-identity-accent':
|
|
211
|
+
'off-identity-accent: use blue/gray or a status hue (red/green/orange/yellow) instead.',
|
|
212
|
+
'raw-spacing': 'raw-spacing: use the spacing scale token instead of a raw literal.',
|
|
213
|
+
'raw-radius': 'raw-radius: use the radius scale token instead of a raw literal.',
|
|
214
|
+
'raw-surface':
|
|
215
|
+
'raw-surface: use `VX.surface.*` / a `radius` token / `var(--vx-radius-card)` instead of an ' +
|
|
216
|
+
'inline border/radius/shadow.',
|
|
217
|
+
'card-with-border':
|
|
218
|
+
'card-with-border: `withBorder` on a Card/Paper double-draws the edge — card depth is ' +
|
|
219
|
+
'`--vx-shadow-card`, which already bakes a 1px ring into the shadow. Drop the prop.',
|
|
220
|
+
'off-system-surface-var':
|
|
221
|
+
'off-system-surface-var: raw Mantine ramp step bypasses the basalt surface tokens — use ' +
|
|
222
|
+
'VX.surface.* / --vx-surface-* (border/panel/subtle/bg) instead.',
|
|
223
|
+
'raw-html-layout':
|
|
224
|
+
'raw-html-layout: raw HTML element with inline layout/surface styling — use a Mantine layout ' +
|
|
225
|
+
'primitive (Box/Flex/Grid/Stack/Group).',
|
|
226
|
+
'inline-spacing':
|
|
227
|
+
'inline-spacing: inline spacing literal — use the Mantine spacing prop/token (p/m/gap with xs..xl).',
|
|
228
|
+
'inline-display':
|
|
229
|
+
'inline-display: use <Flex>/<Grid>/<Group> instead of an inline display:flex/grid.',
|
|
230
|
+
'raw-visx-axis':
|
|
231
|
+
'raw-visx-axis: raw <AxisLeft>/<AxisBottom>/<AxisRight> in a chart file — use ' +
|
|
232
|
+
'AxisLeftNumeric / AxisBottomDate / AxisRightNumeric from the charts primitives.',
|
|
233
|
+
'raw-motion-value':
|
|
234
|
+
'raw-motion-value: hardcoded duration/spring/ease in `transition={{...}}` — use ' +
|
|
235
|
+
'MOTION_DURATION / MOTION_SPRING / MOTION_EASE_STANDARD instead.',
|
|
236
|
+
'unframed-chart':
|
|
237
|
+
'unframed-chart: hand-rolled ChartLegend built from an inline array literal — pass a derived ' +
|
|
238
|
+
'legend (deriveLegend(series)), or compose ChartFrame, which derives it for you.',
|
|
239
|
+
'raw-form-control':
|
|
240
|
+
'raw-form-control: raw <input>/<select>/<textarea> bypasses the entire theme — use ' +
|
|
241
|
+
'TextInput / NumberInput / Select / Textarea from @mantine/core.',
|
|
242
|
+
'sub-16-input-font':
|
|
243
|
+
'sub-16-input-font: fontSize below 16 on a form control is dead code against the `!important` ' +
|
|
244
|
+
'iOS floor in styles.css — drop the override or be honest about 16px.',
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Theme guard — thin FS walker over the headless `../guard` core. Reads BasaltConfig, builds a
|
|
249
|
+
* GuardConfig, walks roots, calls checkSource per file, collects Finding[], groups/reports, returns
|
|
250
|
+
* 0 (clean) / 1 (violations). A `theme-allow` comment exempts a line.
|
|
251
|
+
*/
|
|
252
|
+
export function checkTheme(cwd: string = process.cwd()): number {
|
|
253
|
+
const cfg = readBasaltConfig(cwd)
|
|
254
|
+
const roots = cfg.roots ?? DEFAULT_ROOTS
|
|
255
|
+
const exempt = new Set(cfg.exempt ?? defaultExempt(cfg))
|
|
256
|
+
|
|
257
|
+
const guardCfg: GuardConfig = {
|
|
258
|
+
spacingSteps: cfg.spacingSteps ?? DEFAULT_GUARD_CONFIG.spacingSteps,
|
|
259
|
+
rawRadius: cfg.rawRadius ?? DEFAULT_GUARD_CONFIG.rawRadius,
|
|
260
|
+
forbiddenAccents: cfg.forbiddenAccents ?? DEFAULT_GUARD_CONFIG.forbiddenAccents,
|
|
261
|
+
rawSurface: cfg.rawSurface ?? DEFAULT_GUARD_CONFIG.rawSurface,
|
|
262
|
+
cardWithBorder: cfg.cardWithBorder ?? DEFAULT_GUARD_CONFIG.cardWithBorder,
|
|
263
|
+
offSystemSurfaceVar: cfg.offSystemSurfaceVar ?? DEFAULT_GUARD_CONFIG.offSystemSurfaceVar,
|
|
264
|
+
rawHtmlLayout: cfg.rawHtmlLayout ?? DEFAULT_GUARD_CONFIG.rawHtmlLayout,
|
|
265
|
+
inlineSpacing: cfg.inlineSpacing ?? DEFAULT_GUARD_CONFIG.inlineSpacing,
|
|
266
|
+
inlineDisplay: cfg.inlineDisplay ?? DEFAULT_GUARD_CONFIG.inlineDisplay,
|
|
267
|
+
rawVisxAxis: cfg.rawVisxAxis ?? DEFAULT_GUARD_CONFIG.rawVisxAxis,
|
|
268
|
+
rawMotionValue: cfg.rawMotionValue ?? DEFAULT_GUARD_CONFIG.rawMotionValue,
|
|
269
|
+
unframedChart: cfg.unframedChart ?? DEFAULT_GUARD_CONFIG.unframedChart,
|
|
270
|
+
chartMissingAriaLabel: cfg.chartMissingAriaLabel ?? DEFAULT_GUARD_CONFIG.chartMissingAriaLabel,
|
|
271
|
+
rawFormControl: cfg.rawFormControl ?? DEFAULT_GUARD_CONFIG.rawFormControl,
|
|
272
|
+
sub16InputFont: cfg.sub16InputFont ?? DEFAULT_GUARD_CONFIG.sub16InputFont,
|
|
273
|
+
allowComment: 'theme-allow',
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const findings: Finding[] = []
|
|
277
|
+
let scannedCount = 0
|
|
278
|
+
for (const root of roots) {
|
|
279
|
+
for (const f of walkTsFiles(resolve(cwd, root))) {
|
|
280
|
+
// Normalize to forward slashes so path matching (SKIP, exempt, isChartFile) is
|
|
281
|
+
// identical on Windows (where `relative` yields backslashes) and POSIX.
|
|
282
|
+
const rel = relative(cwd, f).replace(/\\/g, '/')
|
|
283
|
+
if (SKIP.test(rel) || exempt.has(rel)) continue
|
|
284
|
+
scannedCount += 1
|
|
285
|
+
const text = readFileSync(f, 'utf8')
|
|
286
|
+
findings.push(...checkSource(text, rel, guardCfg))
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (scannedCount === 0) {
|
|
291
|
+
// A configured-but-wrong root is never intentional, and silently scanning 0 files under the
|
|
292
|
+
// built-in defaults (argo's pre-migration layout) is the same failure mode for every other
|
|
293
|
+
// consumer — both cases fail loud instead of warn-plus-green.
|
|
294
|
+
if (cfg.roots === undefined) {
|
|
295
|
+
console.error(
|
|
296
|
+
`✖ basalt-ui check-theme: 0 files scanned — no "basalt.roots" configured in package.json, and ` +
|
|
297
|
+
`the built-in default roots (${DEFAULT_ROOTS.join(', ')}) matched zero files. ` +
|
|
298
|
+
'Set "basalt": { "roots": [...] } in package.json to point at your source directories.',
|
|
299
|
+
)
|
|
300
|
+
} else {
|
|
301
|
+
console.error(
|
|
302
|
+
`✖ basalt-ui check-theme: 0 files scanned — the configured "basalt.roots" (${roots.join(', ')}) ` +
|
|
303
|
+
'matched zero files. Check the paths in "basalt.roots" in package.json.',
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
return 1
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (findings.length === 0) {
|
|
310
|
+
console.log('✓ Theme guard: no off-palette colors.')
|
|
311
|
+
return 0
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const byFile = new Map<string, Finding[]>()
|
|
315
|
+
for (const f of findings) {
|
|
316
|
+
const list = byFile.get(f.relPath) ?? []
|
|
317
|
+
list.push(f)
|
|
318
|
+
byFile.set(f.relPath, list)
|
|
319
|
+
}
|
|
320
|
+
console.error(`✖ Theme guard: ${findings.length} off-palette / off-identity violation(s)\n`)
|
|
321
|
+
for (const [file, vs] of [...byFile].toSorted()) {
|
|
322
|
+
console.error(file)
|
|
323
|
+
for (const v of vs.toSorted((a, b) => a.line - b.line)) {
|
|
324
|
+
console.error(` ${String(v.line).padStart(4)} ${v.kind.padEnd(22)} ${v.token}`)
|
|
325
|
+
}
|
|
326
|
+
console.error('')
|
|
327
|
+
}
|
|
328
|
+
const presentKinds = new Set(findings.map((f) => f.kind))
|
|
329
|
+
const explanations = (Object.keys(GUARD_KIND_EXPLANATIONS) as GuardKind[])
|
|
330
|
+
.filter((kind) => presentKinds.has(kind))
|
|
331
|
+
.map((kind) => GUARD_KIND_EXPLANATIONS[kind])
|
|
332
|
+
const fixLine = [
|
|
333
|
+
'Fix:',
|
|
334
|
+
...explanations,
|
|
335
|
+
'Add a `theme-allow` comment for a deliberate exception.',
|
|
336
|
+
]
|
|
337
|
+
console.error(fixLine.join(' '))
|
|
338
|
+
|
|
339
|
+
// A violation in a file that looks like the palette source itself is likely intentional — point
|
|
340
|
+
// at the exempt escape hatch instead of leaving the author to search for it.
|
|
341
|
+
if ([...byFile.keys()].some((f) => SERIES_MODULE_HINT_RE.test(f))) {
|
|
342
|
+
console.error(
|
|
343
|
+
'Hint: if a flagged file IS your palette/series source, exempt it via ' +
|
|
344
|
+
'"basalt": { "exempt": ["<path>"] } in package.json.',
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
return 1
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
351
|
+
// init / sync — managed-files engine
|
|
352
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
353
|
+
|
|
354
|
+
/**
|
|
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.
|
|
368
|
+
*
|
|
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.
|
|
372
|
+
*/
|
|
373
|
+
type Mode = 'managed' | 'seed'
|
|
374
|
+
|
|
375
|
+
/** A single file the framework writes into a consumer repo. */
|
|
376
|
+
type ManagedFile = {
|
|
377
|
+
/** Path of the produced file, relative to the consumer repo root. Stable manifest key. */
|
|
378
|
+
dest: string
|
|
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
|
|
386
|
+
/** Path of the shipped source asset, relative to the package root. */
|
|
387
|
+
source: string
|
|
388
|
+
/**
|
|
389
|
+
* The exact bytes this file should contain right now, given the shipped source + consumer
|
|
390
|
+
* context. Returns null when the shipped source is missing (a sibling-authored asset not yet
|
|
391
|
+
* present) so the engine can skip it cleanly instead of crashing.
|
|
392
|
+
*/
|
|
393
|
+
render: (ctx: RenderContext) => string | null
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Everything a template needs to resolve its `{{…}}` placeholders. */
|
|
397
|
+
type RenderContext = {
|
|
398
|
+
pkgRoot: string
|
|
399
|
+
vars: TemplateVars
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The placeholder map consumed by the shipped templates. `{{APP_NAME}}` comes from the consumer
|
|
404
|
+
* package.json; `{{BASALT_VERSION}}` from the framework's own package.json; the rest from the
|
|
405
|
+
* consumer `"basalt"` config with framework defaults.
|
|
406
|
+
*/
|
|
407
|
+
type TemplateVars = {
|
|
408
|
+
APP_NAME: string
|
|
409
|
+
BASALT_VERSION: string
|
|
410
|
+
ACCENT_HUE: string
|
|
411
|
+
SERIES_MODULE_PATH: string
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// The block markers the CLAUDE.md template emits. The begin marker carries the framework version
|
|
415
|
+
// (`<!-- basalt:begin 1.0.0 -->`), so the region is matched by the begin PREFIX, not an exact string.
|
|
416
|
+
const BLOCK_BEGIN_PREFIX = '<!-- basalt:begin'
|
|
417
|
+
const BLOCK_END = '<!-- basalt:end -->'
|
|
418
|
+
const MANIFEST_PATH = '.basalt/manifest.json'
|
|
419
|
+
|
|
420
|
+
function sha256(text: string): string {
|
|
421
|
+
return createHash('sha256').update(text, 'utf8').digest('hex')
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function readIfExists(abs: string): string | null {
|
|
425
|
+
if (!existsSync(abs)) return null
|
|
426
|
+
return readFileSync(abs, 'utf8')
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Read a shipped source asset from the package root; null if the sibling hasn't authored it yet. */
|
|
430
|
+
function readSource(pkgRoot: string, source: string): string | null {
|
|
431
|
+
return readIfExists(resolve(pkgRoot, source))
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function readPackageName(cwd: string): string {
|
|
435
|
+
try {
|
|
436
|
+
const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as { name?: string }
|
|
437
|
+
if (pkg.name && pkg.name.length > 0) return pkg.name
|
|
438
|
+
} catch {
|
|
439
|
+
// fall through to dir name
|
|
440
|
+
}
|
|
441
|
+
return cwd.split('/').filter(Boolean).pop() ?? 'app'
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** The framework's own published version, read from the package root package.json. */
|
|
445
|
+
function readFrameworkVersion(pkgRoot: string): string {
|
|
446
|
+
try {
|
|
447
|
+
const pkg = JSON.parse(readFileSync(resolve(pkgRoot, 'package.json'), 'utf8')) as {
|
|
448
|
+
version?: string
|
|
449
|
+
}
|
|
450
|
+
return pkg.version ?? '0.0.0'
|
|
451
|
+
} catch {
|
|
452
|
+
return '0.0.0'
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Build the template-variable map from the framework root + consumer cwd/config. */
|
|
457
|
+
function buildTemplateVars(pkgRoot: string, cwd: string, cfg: BasaltConfig): TemplateVars {
|
|
458
|
+
return {
|
|
459
|
+
APP_NAME: readPackageName(cwd),
|
|
460
|
+
BASALT_VERSION: readFrameworkVersion(pkgRoot),
|
|
461
|
+
ACCENT_HUE: cfg.accentHue ?? 'blue',
|
|
462
|
+
SERIES_MODULE_PATH: cfg.seriesModulePath ?? DEFAULT_SERIES_MODULE_PATH,
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** Substitute every `{{KEY}}` placeholder from the variable map; unknown keys are left verbatim. */
|
|
467
|
+
function fillTemplate(tpl: string, vars: TemplateVars): string {
|
|
468
|
+
return tpl.replace(/\{\{(\w+)\}\}/g, (m, key: string) => {
|
|
469
|
+
const v = (vars as Record<string, string>)[key]
|
|
470
|
+
return v ?? m
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
|
|
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
|
+
*/
|
|
479
|
+
function findBlockRegion(host: string): { start: number; end: number } | null {
|
|
480
|
+
const start = host.indexOf(BLOCK_BEGIN_PREFIX)
|
|
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
|
+
}
|
|
489
|
+
const endMarker = host.indexOf(BLOCK_END, start)
|
|
490
|
+
if (endMarker === -1) return null
|
|
491
|
+
return { start, end: endMarker + BLOCK_END.length }
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Replace (or append) the managed block inside a host file. `block` is the fully-rendered template
|
|
496
|
+
* INCLUDING its `basalt:begin … basalt:end` markers. Everything outside the region is preserved;
|
|
497
|
+
* with no existing region the block is appended after a separating blank line.
|
|
498
|
+
*/
|
|
499
|
+
function applyBlock(host: string, block: string): string {
|
|
500
|
+
const region = findBlockRegion(host)
|
|
501
|
+
if (region) {
|
|
502
|
+
return `${host.slice(0, region.start)}${block.trim()}${host.slice(region.end)}`
|
|
503
|
+
}
|
|
504
|
+
const base = host.trimEnd()
|
|
505
|
+
return base.length === 0 ? `${block.trim()}\n` : `${base}\n\n${block.trim()}\n`
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Explicit `--with-router` / `--with-query` CLI flags force-include a router/query scaffold even
|
|
510
|
+
* when the peer isn't detected in the consumer's package.json yet (e.g. it's about to be added).
|
|
511
|
+
*/
|
|
512
|
+
type ScaffoldFlags = { withRouter?: boolean; withQuery?: boolean }
|
|
513
|
+
|
|
514
|
+
/** Router/query peer presence, resolved from detection + explicit flags. */
|
|
515
|
+
type PeerFlags = { hasRouter: boolean; hasQuery: boolean }
|
|
516
|
+
|
|
517
|
+
/** True when `pkgName` appears in the consumer's dependencies, devDependencies, or peerDependencies. */
|
|
518
|
+
function hasDependency(cwd: string, pkgName: string): boolean {
|
|
519
|
+
try {
|
|
520
|
+
const pkg = JSON.parse(readFileSync(resolve(cwd, 'package.json'), 'utf8')) as {
|
|
521
|
+
dependencies?: Record<string, string>
|
|
522
|
+
devDependencies?: Record<string, string>
|
|
523
|
+
peerDependencies?: Record<string, string>
|
|
524
|
+
}
|
|
525
|
+
return Boolean(
|
|
526
|
+
pkg.dependencies?.[pkgName] ??
|
|
527
|
+
pkg.devDependencies?.[pkgName] ??
|
|
528
|
+
pkg.peerDependencies?.[pkgName],
|
|
529
|
+
)
|
|
530
|
+
} catch {
|
|
531
|
+
return false
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Resolves whether the consumer has the optional TanStack router/query peers — auto-detected from
|
|
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
|
|
539
|
+
* peer was never installed) call this once, up front.
|
|
540
|
+
*/
|
|
541
|
+
function resolvePeerFlags(cwd: string, flags: ScaffoldFlags): PeerFlags {
|
|
542
|
+
return {
|
|
543
|
+
hasRouter: flags.withRouter === true || hasDependency(cwd, '@tanstack/react-router'),
|
|
544
|
+
hasQuery: flags.withQuery === true || hasDependency(cwd, '@tanstack/react-query'),
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** The full managed-file manifest. Stable, declarative — the single source of truth for init/sync. */
|
|
549
|
+
function managedFiles(peers: PeerFlags): ManagedFile[] {
|
|
550
|
+
// ── managed: exactly what Claude reads ──────────────────────────────────────
|
|
551
|
+
const rules: ManagedFile[] = RULE_NAMES.map((name) => ({
|
|
552
|
+
dest: `.claude/rules/basalt-${name}.md`,
|
|
553
|
+
mode: 'managed' as const,
|
|
554
|
+
source: `agent/rules/basalt-${name}.md`,
|
|
555
|
+
render: (ctx: RenderContext) => readSource(ctx.pkgRoot, `agent/rules/basalt-${name}.md`),
|
|
556
|
+
}))
|
|
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
|
+
|
|
568
|
+
const claudeBlock: ManagedFile = {
|
|
569
|
+
dest: 'CLAUDE.md',
|
|
570
|
+
mode: 'managed',
|
|
571
|
+
markers: true,
|
|
572
|
+
source: 'agent/templates/CLAUDE-block.md.tpl',
|
|
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.
|
|
575
|
+
render: (ctx) => {
|
|
576
|
+
const tpl = readSource(ctx.pkgRoot, 'agent/templates/CLAUDE-block.md.tpl')
|
|
577
|
+
if (tpl === null) return null
|
|
578
|
+
return fillTemplate(tpl, ctx.vars).trim()
|
|
579
|
+
},
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// ── seed: everything a machine reads — written once, then consumer-owned ────
|
|
583
|
+
const design: ManagedFile = {
|
|
584
|
+
dest: 'DESIGN.md',
|
|
585
|
+
mode: 'seed',
|
|
586
|
+
source: 'agent/templates/DESIGN.md.tpl',
|
|
587
|
+
render: (ctx) => {
|
|
588
|
+
const tpl = readSource(ctx.pkgRoot, 'agent/templates/DESIGN.md.tpl')
|
|
589
|
+
if (tpl === null) return null
|
|
590
|
+
return fillTemplate(tpl, ctx.vars)
|
|
591
|
+
},
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// Scaffold destination is `.oxfmtrc.json` — oxfmt auto-discovers that filename, not `oxfmt.json`
|
|
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.
|
|
597
|
+
const oxfmt: ManagedFile = {
|
|
598
|
+
dest: '.oxfmtrc.json',
|
|
599
|
+
mode: 'seed',
|
|
600
|
+
source: 'configs/oxfmt.json',
|
|
601
|
+
render: (ctx) => readSource(ctx.pkgRoot, 'configs/oxfmt.json'),
|
|
602
|
+
}
|
|
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.
|
|
607
|
+
const lefthook: ManagedFile = {
|
|
608
|
+
dest: 'lefthook.yml',
|
|
609
|
+
mode: 'seed',
|
|
610
|
+
source: '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',
|
|
617
|
+
}
|
|
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.
|
|
621
|
+
const ci: ManagedFile = {
|
|
622
|
+
dest: '.github/workflows/check.yml',
|
|
623
|
+
mode: 'seed',
|
|
624
|
+
source: 'configs/check.yml',
|
|
625
|
+
render: (ctx) => readSource(ctx.pkgRoot, 'configs/check.yml'),
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Seed an `.oxlintrc.json` that extends the shipped preset (written once, then consumer-owned).
|
|
629
|
+
// `render` emits the stub inline rather than copying `source`; `source` names the preset the stub
|
|
630
|
+
// extends, and the `seed` mode never reports drift, so it is not read back at sync time.
|
|
631
|
+
const oxlintrc: ManagedFile = {
|
|
632
|
+
dest: '.oxlintrc.json',
|
|
633
|
+
mode: 'seed',
|
|
634
|
+
source: 'configs/oxlint.json',
|
|
635
|
+
render: () => '{\n "extends": ["./node_modules/basalt-ui/configs/oxlint.json"]\n}\n',
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// ── Seed scaffolds: written by init, never overwritten by sync ─────────────
|
|
639
|
+
// These are starting-point files owned entirely by the consumer after first write.
|
|
640
|
+
|
|
641
|
+
/** TanStack Query client bootstrap (seed — consumer-owned after init). */
|
|
642
|
+
const queryClient: ManagedFile = {
|
|
643
|
+
dest: 'src/query-client.ts',
|
|
644
|
+
mode: 'seed',
|
|
645
|
+
source: 'agent/templates/query-client.ts.tpl',
|
|
646
|
+
render: (ctx) => {
|
|
647
|
+
const tpl = readSource(ctx.pkgRoot, 'agent/templates/query-client.ts.tpl')
|
|
648
|
+
if (tpl === null) return null
|
|
649
|
+
return fillTemplate(tpl, ctx.vars)
|
|
650
|
+
},
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** TanStack Router root route with QueryClient context wiring (seed — consumer-owned after init). */
|
|
654
|
+
const rootRoute: ManagedFile = {
|
|
655
|
+
dest: 'src/routes/__root.tsx',
|
|
656
|
+
mode: 'seed',
|
|
657
|
+
source: 'agent/templates/__root.tpl',
|
|
658
|
+
render: (ctx) => {
|
|
659
|
+
const tpl = readSource(ctx.pkgRoot, 'agent/templates/__root.tpl')
|
|
660
|
+
if (tpl === null) return null
|
|
661
|
+
return fillTemplate(tpl, ctx.vars)
|
|
662
|
+
},
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// `query-client.ts` only needs @tanstack/react-query; `__root.tsx` imports BOTH
|
|
666
|
+
// @tanstack/react-router (createRootRouteWithContext) and @tanstack/react-query (the QueryClient
|
|
667
|
+
// type) — both are documented optional peers, so seeding either scaffold without its peer(s)
|
|
668
|
+
// installed would ship a file with an unresolved import.
|
|
669
|
+
const scaffolds: ManagedFile[] = []
|
|
670
|
+
if (peers.hasQuery) scaffolds.push(queryClient)
|
|
671
|
+
if (peers.hasRouter && peers.hasQuery) scaffolds.push(rootRoute)
|
|
672
|
+
|
|
673
|
+
return [...rules, ...skills, claudeBlock, design, oxfmt, lefthook, ci, oxlintrc, ...scaffolds]
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
type Manifest = {
|
|
677
|
+
version: 1
|
|
678
|
+
/** The basalt-ui version that last wrote this manifest — `doctor`'s one reconciliation axis. */
|
|
679
|
+
basaltVersion?: string
|
|
680
|
+
/** dest path → sha256 of the managed unit (file bytes, block body, or stanza) at last write. */
|
|
681
|
+
files: Record<string, string>
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function readManifest(cwd: string): Manifest {
|
|
685
|
+
const raw = readIfExists(resolve(cwd, MANIFEST_PATH))
|
|
686
|
+
if (raw === null) return { version: 1, files: {} }
|
|
687
|
+
try {
|
|
688
|
+
const parsed = JSON.parse(raw) as Partial<Manifest>
|
|
689
|
+
const manifest: Manifest = { version: 1, files: parsed.files ?? {} }
|
|
690
|
+
if (typeof parsed.basaltVersion === 'string') manifest.basaltVersion = parsed.basaltVersion
|
|
691
|
+
return manifest
|
|
692
|
+
} catch {
|
|
693
|
+
return { version: 1, files: {} }
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** The pre-rename oxfmt scaffold dest, superseded by `.oxfmtrc.json` (oxfmt's auto-discovered name). */
|
|
698
|
+
const LEGACY_OXFMT_DEST = 'oxfmt.json'
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* One-time cleanup for consumers who ran `init`/`sync` before the `.oxfmtrc.json` rename: drops the
|
|
702
|
+
* stale `oxfmt.json` manifest entry so it stops being reconciled/recreated forever, and deletes the
|
|
703
|
+
* on-disk file when it still byte-matches the shipped default (untouched since the last sync). A
|
|
704
|
+
* locally-edited copy is left in place — the manifest entry alone determines "was basalt tracking
|
|
705
|
+
* this", so a fresh consumer (no legacy entry) is a no-op.
|
|
706
|
+
*/
|
|
707
|
+
function migrateLegacyOxfmt(cwd: string, pkgRoot: string, manifest: Manifest): void {
|
|
708
|
+
if (!(LEGACY_OXFMT_DEST in manifest.files)) return
|
|
709
|
+
delete manifest.files[LEGACY_OXFMT_DEST]
|
|
710
|
+
const legacyAbs = resolve(cwd, LEGACY_OXFMT_DEST)
|
|
711
|
+
const onDisk = readIfExists(legacyAbs)
|
|
712
|
+
if (onDisk === null) return
|
|
713
|
+
const shipped = readSource(pkgRoot, 'configs/oxfmt.json')
|
|
714
|
+
if (shipped !== null && onDisk === shipped) unlinkSync(legacyAbs)
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function writeFileEnsuringDir(abs: string, content: string): void {
|
|
718
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
719
|
+
writeFileSync(abs, content)
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** Resolve the package root at runtime (two levels up from dist/cli/index.js). */
|
|
723
|
+
function packageRoot(): string {
|
|
724
|
+
return fileURLToPath(new URL('../../', import.meta.url))
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
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.
|
|
731
|
+
*/
|
|
732
|
+
type UnitState = {
|
|
733
|
+
/** The managed unit's current bytes on disk (block region / whole file). */
|
|
734
|
+
current: string | null
|
|
735
|
+
/** The managed unit's desired bytes from the shipped source. null = source not shipped yet. */
|
|
736
|
+
desired: string | null
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** The existing managed region (markers included, trimmed) inside a host file, or null. */
|
|
740
|
+
function extractBlockRegion(host: string | null): string | null {
|
|
741
|
+
if (host === null) return null
|
|
742
|
+
const region = findBlockRegion(host)
|
|
743
|
+
if (region === null) return null
|
|
744
|
+
return host.slice(region.start, region.end).trim()
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/** Read the current vs desired managed-unit bytes for a file. */
|
|
748
|
+
function unitState(file: ManagedFile, cwd: string, ctx: RenderContext): UnitState {
|
|
749
|
+
const desired = file.render(ctx)
|
|
750
|
+
const destAbs = resolve(cwd, file.dest)
|
|
751
|
+
const onDisk = readIfExists(destAbs)
|
|
752
|
+
if (file.markers) {
|
|
753
|
+
return { current: extractBlockRegion(onDisk), desired }
|
|
754
|
+
}
|
|
755
|
+
return { current: onDisk, desired }
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/** Write a managed unit to disk (whole file, or marker-spliced region). Returns the unit's hash. */
|
|
759
|
+
function writeUnit(file: ManagedFile, cwd: string, desired: string): string {
|
|
760
|
+
const destAbs = resolve(cwd, file.dest)
|
|
761
|
+
if (file.markers) {
|
|
762
|
+
const host = readIfExists(destAbs) ?? ''
|
|
763
|
+
writeFileEnsuringDir(destAbs, applyBlock(host, desired))
|
|
764
|
+
return sha256(desired)
|
|
765
|
+
}
|
|
766
|
+
writeFileEnsuringDir(destAbs, desired)
|
|
767
|
+
return sha256(desired)
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
type Classification = 'unchanged' | 'drifted' | 'missing' | 'current'
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Classify a managed file against the manifest for a sync run.
|
|
774
|
+
* - missing : the managed unit is absent on disk → recreate.
|
|
775
|
+
* - current : on disk == desired → nothing to do.
|
|
776
|
+
* - unchanged: on disk == manifest hash (untouched since last sync) but != desired → safe overwrite.
|
|
777
|
+
* - drifted : on disk != manifest hash AND != desired (locally edited) → skip unless --force.
|
|
778
|
+
*/
|
|
779
|
+
function classify(state: UnitState, manifestHash: string | undefined): Classification {
|
|
780
|
+
if (state.current === null) return 'missing'
|
|
781
|
+
if (state.desired !== null && state.current === state.desired) return 'current'
|
|
782
|
+
const currentHash = sha256(state.current)
|
|
783
|
+
if (currentHash === manifestHash) return 'unchanged'
|
|
784
|
+
return 'drifted'
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function diffSummary(file: ManagedFile, state: UnitState): string {
|
|
788
|
+
const cur = state.current ?? ''
|
|
789
|
+
const des = state.desired ?? ''
|
|
790
|
+
const curLines = cur.split('\n').length
|
|
791
|
+
const desLines = des.split('\n').length
|
|
792
|
+
return ` ~ ${file.dest} (local: ${curLines} lines, shipped: ${desLines} lines) — locally edited, skipped (use --force to overwrite)`
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/** Build the render context for a run from the package root + consumer cwd/config. */
|
|
796
|
+
function renderContext(cwd: string): RenderContext {
|
|
797
|
+
const pkgRoot = packageRoot()
|
|
798
|
+
return { pkgRoot, vars: buildTemplateVars(pkgRoot, cwd, readBasaltConfig(cwd)) }
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/** Scaffold all managed files into the consumer repo, then write the manifest. Idempotent. Returns 0. */
|
|
802
|
+
export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags = {}): number {
|
|
803
|
+
const ctx = renderContext(cwd)
|
|
804
|
+
const manifest = readManifest(cwd)
|
|
805
|
+
migrateLegacyOxfmt(cwd, ctx.pkgRoot, manifest)
|
|
806
|
+
const peers = resolvePeerFlags(cwd, scaffoldFlags)
|
|
807
|
+
const files = managedFiles(peers)
|
|
808
|
+
|
|
809
|
+
let written = 0
|
|
810
|
+
let skipped = 0
|
|
811
|
+
const missingSources: string[] = []
|
|
812
|
+
|
|
813
|
+
for (const file of files) {
|
|
814
|
+
const state = unitState(file, cwd, ctx)
|
|
815
|
+
if (state.desired === null) {
|
|
816
|
+
missingSources.push(file.source)
|
|
817
|
+
continue
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// Whole files (managed + seed) are skip-if-exists on init; a marker-spliced region always
|
|
821
|
+
// inserts/updates itself inside its host file.
|
|
822
|
+
const destExists = existsSync(resolve(cwd, file.dest))
|
|
823
|
+
if (!file.markers && destExists) {
|
|
824
|
+
// Already present — keep the consumer's copy untouched. Record the SHIPPED hash so a later
|
|
825
|
+
// sync treats a pre-existing-but-different file as locally drifted (skip unless --force),
|
|
826
|
+
// never silently clobbering a file the consumer authored before init.
|
|
827
|
+
manifest.files[file.dest] = sha256(state.desired)
|
|
828
|
+
skipped++
|
|
829
|
+
continue
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const hash = writeUnit(file, cwd, state.desired)
|
|
833
|
+
manifest.files[file.dest] = hash
|
|
834
|
+
written++
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
manifest.basaltVersion = ctx.vars.BASALT_VERSION
|
|
838
|
+
writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}\n`)
|
|
839
|
+
|
|
840
|
+
console.log(`basalt-ui init: ${written} written, ${skipped} kept, manifest at ${MANIFEST_PATH}`)
|
|
841
|
+
if (missingSources.length > 0) {
|
|
842
|
+
console.log(
|
|
843
|
+
`basalt-ui init: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
|
|
844
|
+
)
|
|
845
|
+
}
|
|
846
|
+
// query-client.ts / __root.tsx reference the optional TanStack peers directly — seeding them
|
|
847
|
+
// without the peer installed would ship an unresolved import. Hint how to opt in instead.
|
|
848
|
+
if (!peers.hasQuery) {
|
|
849
|
+
console.log(
|
|
850
|
+
'basalt-ui init: skipped src/query-client.ts (no @tanstack/react-query dependency detected) — ' +
|
|
851
|
+
'install it, or re-run with --with-query, to scaffold it.',
|
|
852
|
+
)
|
|
853
|
+
}
|
|
854
|
+
if (!peers.hasRouter || !peers.hasQuery) {
|
|
855
|
+
console.log(
|
|
856
|
+
'basalt-ui init: skipped src/routes/__root.tsx (needs both @tanstack/react-router and ' +
|
|
857
|
+
'@tanstack/react-query) — install both, or re-run with --with-router --with-query, to scaffold it.',
|
|
858
|
+
)
|
|
859
|
+
}
|
|
860
|
+
// The guard-hook PreToolUse registration is NOT written automatically — add it manually to
|
|
861
|
+
// .claude/settings.json so every Write/Edit/MultiEdit goes through the theme guard.
|
|
862
|
+
console.log(
|
|
863
|
+
`\nTheme guard hook: add to .claude/settings.json → hooks.PreToolUse to catch violations before they land:\n` +
|
|
864
|
+
` "hooks": {\n` +
|
|
865
|
+
` "PreToolUse": [\n` +
|
|
866
|
+
` {\n` +
|
|
867
|
+
` "matcher": "Write|Edit|MultiEdit",\n` +
|
|
868
|
+
` "hooks": [{ "type": "command", "command": "bunx basalt-ui guard-hook" }]\n` +
|
|
869
|
+
` }\n` +
|
|
870
|
+
` ]\n` +
|
|
871
|
+
` }`,
|
|
872
|
+
)
|
|
873
|
+
// First adoption on a previously guard-clean repo can surface a wall of findings (the 1.0 guard
|
|
874
|
+
// adds several rule kinds beyond a legacy local guard) — steer toward tuning config, not mass-allow.
|
|
875
|
+
console.log(
|
|
876
|
+
'\nFirst run: run `basalt-ui check-theme` next, then tune the per-rule `basalt.*` config keys ' +
|
|
877
|
+
'in package.json for anything that fires — do not mass-`theme-allow` findings.',
|
|
878
|
+
)
|
|
879
|
+
return 0
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
type SyncOptions = { force?: boolean; check?: boolean }
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Reconcile managed files with the shipped versions via a sha256 three-way compare.
|
|
886
|
+
*
|
|
887
|
+
* - `--check` makes NO writes; exits non-zero if any managed file is out-of-date or locally drifted
|
|
888
|
+
* (a CI freshness gate), exit 0 when all current.
|
|
889
|
+
* - `--force` overwrites locally-drifted files instead of skipping them.
|
|
890
|
+
*/
|
|
891
|
+
export function sync(opts: SyncOptions = {}, cwd: string = process.cwd()): number {
|
|
892
|
+
const ctx = renderContext(cwd)
|
|
893
|
+
const manifest = readManifest(cwd)
|
|
894
|
+
if (!opts.check) migrateLegacyOxfmt(cwd, ctx.pkgRoot, manifest)
|
|
895
|
+
const peers = resolvePeerFlags(cwd, {})
|
|
896
|
+
const files = managedFiles(peers)
|
|
897
|
+
|
|
898
|
+
let updated = 0
|
|
899
|
+
let recreated = 0
|
|
900
|
+
let skippedDrift = 0
|
|
901
|
+
let staleForCheck = 0
|
|
902
|
+
const driftLines: string[] = []
|
|
903
|
+
const missingSources: string[] = []
|
|
904
|
+
|
|
905
|
+
for (const file of files) {
|
|
906
|
+
const state = unitState(file, cwd, ctx)
|
|
907
|
+
if (state.desired === null) {
|
|
908
|
+
missingSources.push(file.source)
|
|
909
|
+
continue
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// `seed` is written once, then owned by the consumer — never reconciled, never reported.
|
|
913
|
+
if (file.mode === 'seed') {
|
|
914
|
+
if (state.current === null && !opts.check) {
|
|
915
|
+
manifest.files[file.dest] = writeUnit(file, cwd, state.desired)
|
|
916
|
+
recreated++
|
|
917
|
+
}
|
|
918
|
+
continue
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
const kind = classify(state, manifest.files[file.dest])
|
|
922
|
+
|
|
923
|
+
if (kind === 'current') {
|
|
924
|
+
manifest.files[file.dest] = sha256(state.desired)
|
|
925
|
+
continue
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
if (kind === 'drifted' && !opts.force) {
|
|
929
|
+
driftLines.push(diffSummary(file, state))
|
|
930
|
+
staleForCheck++
|
|
931
|
+
skippedDrift++
|
|
932
|
+
continue
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// missing | unchanged | (drifted && force) → write the shipped version.
|
|
936
|
+
staleForCheck++
|
|
937
|
+
if (opts.check) continue
|
|
938
|
+
manifest.files[file.dest] = writeUnit(file, cwd, state.desired)
|
|
939
|
+
if (kind === 'missing') recreated++
|
|
940
|
+
else updated++
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
if (opts.check) {
|
|
944
|
+
if (driftLines.length > 0) {
|
|
945
|
+
console.error('basalt-ui sync --check: locally-drifted managed files:')
|
|
946
|
+
for (const l of driftLines) console.error(l)
|
|
947
|
+
}
|
|
948
|
+
if (staleForCheck > 0) {
|
|
949
|
+
console.error(`basalt-ui sync --check: ${staleForCheck} managed file(s) out of date.`)
|
|
950
|
+
return 1
|
|
951
|
+
}
|
|
952
|
+
console.log('✓ basalt-ui sync --check: all managed files current.')
|
|
953
|
+
return 0
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
manifest.basaltVersion = ctx.vars.BASALT_VERSION
|
|
957
|
+
writeFileEnsuringDir(resolve(cwd, MANIFEST_PATH), `${JSON.stringify(manifest, null, 2)}\n`)
|
|
958
|
+
|
|
959
|
+
console.log(
|
|
960
|
+
`basalt-ui sync: ${updated} updated, ${recreated} recreated, ${skippedDrift} skipped (drift).`,
|
|
961
|
+
)
|
|
962
|
+
if (driftLines.length > 0) {
|
|
963
|
+
console.log('Locally-edited files were skipped (run with --force to overwrite):')
|
|
964
|
+
for (const l of driftLines) console.log(l)
|
|
965
|
+
}
|
|
966
|
+
if (missingSources.length > 0) {
|
|
967
|
+
console.log(
|
|
968
|
+
`basalt-ui sync: ${missingSources.length} shipped asset(s) not present, skipped: ${missingSources.join(', ')}`,
|
|
969
|
+
)
|
|
970
|
+
}
|
|
971
|
+
return 0
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
975
|
+
// check-coverage — 8-assertion coverage gate
|
|
976
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Assert the 8 SURFACES invariants against the live SURFACES + GUARD_RULES + plugin.json.
|
|
980
|
+
* Returns 0 when all pass; 1 when any fail (console.error each failure).
|
|
981
|
+
*
|
|
982
|
+
* Eight assertions:
|
|
983
|
+
* 1. Every doctrine spec's guardKinds ⊆ keyof GUARD_RULES.
|
|
984
|
+
* 2. Every doctrine rule (deduped) maps to agent/rules/basalt-{rule}.md on disk.
|
|
985
|
+
* 3. Every doctrine skill (deduped) maps to agent/skills/{skill}/SKILL.md on disk.
|
|
986
|
+
* 4. Every non-#, non-'.' JS-subpath SURFACES key has a package.json exports entry.
|
|
987
|
+
* 5. Every real package.json exports key has a SURFACES entry.
|
|
988
|
+
* 6. Every surface with non-empty forbiddenImports has a globs field.
|
|
989
|
+
* 7. Every headless surface carries all 3 Mantine bans (Mantine-free boundary).
|
|
990
|
+
* 8. Every doctrine optionalPeers entry exists in peerDependencies AND peerDependenciesMeta.
|
|
991
|
+
*
|
|
992
|
+
* Tooling surfaces are exempt from assertions 1–3 by the discriminant.
|
|
993
|
+
* Synthetic #-keys participate in assertions 1 and 2 but feed assertion 3 only
|
|
994
|
+
* via the deduped skill union (no independent per-#-surface skill row).
|
|
995
|
+
*/
|
|
996
|
+
export function checkCoverage(): number {
|
|
997
|
+
const pkgRoot = packageRoot()
|
|
998
|
+
const failures: string[] = []
|
|
999
|
+
|
|
1000
|
+
const allSpecs = Object.entries(SURFACES) as [string, SurfaceSpec][]
|
|
1001
|
+
const doctrineSpecs = (Object.values(SURFACES) as SurfaceSpec[]).filter(
|
|
1002
|
+
(s): s is DoctrineSpec => s.kind === 'doctrine',
|
|
1003
|
+
)
|
|
1004
|
+
|
|
1005
|
+
// ── Assertion 1: every doctrine spec's guardKinds ⊆ keyof GUARD_RULES ──────
|
|
1006
|
+
const validGuardKinds = new Set(Object.keys(GUARD_RULES))
|
|
1007
|
+
for (const [key, spec] of allSpecs) {
|
|
1008
|
+
if (spec.kind !== 'doctrine') continue
|
|
1009
|
+
for (const kind of spec.guardKinds) {
|
|
1010
|
+
if (!validGuardKinds.has(kind)) {
|
|
1011
|
+
failures.push(
|
|
1012
|
+
`SURFACES['${key}'].guardKinds includes '${kind}' which is not in GUARD_RULES`,
|
|
1013
|
+
)
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// ── Assertion 2: every doctrine rule (deduped) → agent/rules/basalt-{rule}.md ──
|
|
1019
|
+
for (const rule of RULE_NAMES) {
|
|
1020
|
+
const rulePath = resolve(pkgRoot, `agent/rules/basalt-${rule}.md`)
|
|
1021
|
+
if (!existsSync(rulePath)) {
|
|
1022
|
+
failures.push(
|
|
1023
|
+
`Missing rule file: agent/rules/basalt-${rule}.md (derived from SURFACES doctrine rules)`,
|
|
1024
|
+
)
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
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
|
+
)
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// ── Assertion 4: subpath-export-coverage ────────────────────────────────────
|
|
1041
|
+
// Every non-#, non-'.' JS-subpath SURFACES key must have a package.json exports entry.
|
|
1042
|
+
let pkgExports: Set<string> = new Set()
|
|
1043
|
+
try {
|
|
1044
|
+
const consumerPkgPath = resolve(pkgRoot, 'package.json')
|
|
1045
|
+
const consumerPkg = JSON.parse(readFileSync(consumerPkgPath, 'utf8')) as {
|
|
1046
|
+
exports?: Record<string, unknown>
|
|
1047
|
+
}
|
|
1048
|
+
pkgExports = new Set(Object.keys(consumerPkg.exports ?? {}))
|
|
1049
|
+
} catch {
|
|
1050
|
+
failures.push(`Cannot read package.json at ${pkgRoot}`)
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
for (const key of Object.keys(SURFACES)) {
|
|
1054
|
+
if (key.startsWith('#') || key === '.') continue
|
|
1055
|
+
if (!pkgExports.has(key)) {
|
|
1056
|
+
failures.push(
|
|
1057
|
+
`SURFACES key '${key}' is a JS subpath but has no entry in package.json exports`,
|
|
1058
|
+
)
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// ── Assertion 5: every real package.json exports key has a SURFACES entry ────
|
|
1063
|
+
// Excludes ./styles.css and ./configs/* (non-JS assets / raw file paths).
|
|
1064
|
+
for (const exportKey of pkgExports) {
|
|
1065
|
+
if (exportKey === '.' || exportKey === './styles.css' || exportKey.startsWith('./configs/'))
|
|
1066
|
+
continue
|
|
1067
|
+
if (!(exportKey in SURFACES)) {
|
|
1068
|
+
failures.push(`package.json exports key '${exportKey}' has no matching SURFACES entry`)
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// ── Assertion 6: every surface with non-empty forbiddenImports has a globs field ──
|
|
1073
|
+
for (const [key, spec] of allSpecs) {
|
|
1074
|
+
if (spec.forbiddenImports.length === 0) continue
|
|
1075
|
+
if (!('globs' in spec) || spec.globs === undefined) {
|
|
1076
|
+
failures.push(
|
|
1077
|
+
`SURFACES['${key}'] has non-empty forbiddenImports but no globs field (required for oxlint emission)`,
|
|
1078
|
+
)
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// ── Assertion 7: every headless surface carries all 3 Mantine bans ───────────
|
|
1083
|
+
// Guarantees the Mantine-free boundary — a future headless surface without bans fails here.
|
|
1084
|
+
const REQUIRED_MANTINE_BANS = ['@mantine/core', '@mantine/hooks', '@mantine/*'] as const
|
|
1085
|
+
for (const [key, spec] of allSpecs) {
|
|
1086
|
+
if (spec.layer !== 'headless') continue
|
|
1087
|
+
for (const required of REQUIRED_MANTINE_BANS) {
|
|
1088
|
+
const hasBan = spec.forbiddenImports.some((fi) => fi.spec === required)
|
|
1089
|
+
if (!hasBan) {
|
|
1090
|
+
failures.push(
|
|
1091
|
+
`SURFACES['${key}'] is headless but missing Mantine ban for '${required}' in forbiddenImports`,
|
|
1092
|
+
)
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// ── Assertion 8: every doctrine optionalPeers entry → peerDependencies + peerDependenciesMeta ──
|
|
1098
|
+
// Closes the silent-drop gap: an optionalPeer listed in SURFACES but absent from package.json
|
|
1099
|
+
// means the published package never tells npm about the dependency.
|
|
1100
|
+
let peerDependencies: Record<string, string> = {}
|
|
1101
|
+
let peerDependenciesMeta: Record<string, { optional?: boolean }> = {}
|
|
1102
|
+
try {
|
|
1103
|
+
const frameworkPkg = JSON.parse(readFileSync(resolve(pkgRoot, 'package.json'), 'utf8')) as {
|
|
1104
|
+
peerDependencies?: Record<string, string>
|
|
1105
|
+
peerDependenciesMeta?: Record<string, { optional?: boolean }>
|
|
1106
|
+
}
|
|
1107
|
+
peerDependencies = frameworkPkg.peerDependencies ?? {}
|
|
1108
|
+
peerDependenciesMeta = frameworkPkg.peerDependenciesMeta ?? {}
|
|
1109
|
+
} catch {
|
|
1110
|
+
failures.push(`Cannot read package.json peerDependencies at ${pkgRoot}`)
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
for (const spec of doctrineSpecs) {
|
|
1114
|
+
for (const peer of spec.optionalPeers ?? []) {
|
|
1115
|
+
if (!(peer in peerDependencies)) {
|
|
1116
|
+
failures.push(
|
|
1117
|
+
`SURFACES doctrine optionalPeer '${peer}' is not listed in package.json peerDependencies`,
|
|
1118
|
+
)
|
|
1119
|
+
}
|
|
1120
|
+
if (peerDependenciesMeta[peer]?.optional !== true) {
|
|
1121
|
+
failures.push(
|
|
1122
|
+
`SURFACES doctrine optionalPeer '${peer}' is not marked optional in package.json peerDependenciesMeta`,
|
|
1123
|
+
)
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// ── Report ──────────────────────────────────────────────────────────────────
|
|
1129
|
+
if (failures.length === 0) {
|
|
1130
|
+
console.log('✓ check-coverage: all 8 assertions pass.')
|
|
1131
|
+
return 0
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
console.error(`✖ check-coverage: ${failures.length} failure(s)`)
|
|
1135
|
+
for (const f of failures) {
|
|
1136
|
+
console.error(` ${f}`)
|
|
1137
|
+
}
|
|
1138
|
+
return 1
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
1142
|
+
// doctor — consumer repo integration health check
|
|
1143
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
1144
|
+
|
|
1145
|
+
type DoctorResult = {
|
|
1146
|
+
/** Number of hard failures (exit non-zero). */
|
|
1147
|
+
hardFailures: number
|
|
1148
|
+
/** Number of warnings (informational only). */
|
|
1149
|
+
warnings: number
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Check a consumer repo's basalt integration and print a pass/warn report.
|
|
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
|
+
*
|
|
1160
|
+
* Hard failures (exit non-zero):
|
|
1161
|
+
* 1. .basalt/manifest.json exists (init was run).
|
|
1162
|
+
*
|
|
1163
|
+
* Warnings (non-fatal):
|
|
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).
|
|
1169
|
+
*
|
|
1170
|
+
* Returns the exit code: 0 = all good, 1 = one or more hard failures.
|
|
1171
|
+
*/
|
|
1172
|
+
export function doctor(cwd: string = process.cwd()): number {
|
|
1173
|
+
const result: DoctorResult = { hardFailures: 0, warnings: 0 }
|
|
1174
|
+
const lines: string[] = [`\nbasalt-ui doctor — ${cwd}\n`]
|
|
1175
|
+
|
|
1176
|
+
function pass(msg: string): void {
|
|
1177
|
+
lines.push(` ✓ ${msg}`)
|
|
1178
|
+
}
|
|
1179
|
+
function warn(msg: string): void {
|
|
1180
|
+
lines.push(` ⚠ ${msg}`)
|
|
1181
|
+
result.warnings++
|
|
1182
|
+
}
|
|
1183
|
+
function fail(msg: string): void {
|
|
1184
|
+
lines.push(` ✖ ${msg}`)
|
|
1185
|
+
result.hardFailures++
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// ── Hard check 1: manifest exists ──────────────────────────────────────────
|
|
1189
|
+
const manifestAbs = resolve(cwd, MANIFEST_PATH)
|
|
1190
|
+
const manifestExists = existsSync(manifestAbs)
|
|
1191
|
+
if (manifestExists) {
|
|
1192
|
+
pass(`${MANIFEST_PATH} exists`)
|
|
1193
|
+
} else {
|
|
1194
|
+
fail(`${MANIFEST_PATH} missing — run \`basalt-ui init\` to scaffold the consumer repo`)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
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
|
+
}
|
|
1209
|
+
}
|
|
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) {
|
|
1218
|
+
warn(
|
|
1219
|
+
`installed basalt-ui (${installedVersion}) differs from the version that last synced ` +
|
|
1220
|
+
`(${manifestVersion}) — the placed doctrine is stale; run \`basalt-ui sync\`.`,
|
|
1221
|
+
)
|
|
1222
|
+
} else {
|
|
1223
|
+
pass(`installed basalt-ui (${installedVersion}) matches the manifest's basaltVersion`)
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
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.
|
|
1231
|
+
const cliVersion = readFrameworkVersion(packageRoot())
|
|
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`)
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// ── Report ──────────────────────────────────────────────────────────────────
|
|
1245
|
+
lines.push('')
|
|
1246
|
+
if (result.hardFailures === 0 && result.warnings === 0) {
|
|
1247
|
+
lines.push('All checks passed.')
|
|
1248
|
+
} else {
|
|
1249
|
+
if (result.hardFailures > 0)
|
|
1250
|
+
lines.push(`${result.hardFailures} hard failure(s), ${result.warnings} warning(s).`)
|
|
1251
|
+
else lines.push(`${result.warnings} warning(s).`)
|
|
1252
|
+
}
|
|
1253
|
+
lines.push('')
|
|
1254
|
+
|
|
1255
|
+
if (result.hardFailures > 0) {
|
|
1256
|
+
console.error(lines.join('\n'))
|
|
1257
|
+
return 1
|
|
1258
|
+
}
|
|
1259
|
+
console.log(lines.join('\n'))
|
|
1260
|
+
return 0
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
1264
|
+
// info — SURFACES-derived surface map
|
|
1265
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
1266
|
+
|
|
1267
|
+
/** One row in the `basalt info` output — one per published JS subpath export. */
|
|
1268
|
+
export type InfoSubpath = {
|
|
1269
|
+
path: string
|
|
1270
|
+
description: string
|
|
1271
|
+
layer: string
|
|
1272
|
+
rule: string | null
|
|
1273
|
+
skills: readonly string[]
|
|
1274
|
+
optionalPeers: string[]
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/** The stable JSON shape for `basalt info --json`. */
|
|
1278
|
+
export type InfoOutput = {
|
|
1279
|
+
name: string
|
|
1280
|
+
version: string
|
|
1281
|
+
subpaths: InfoSubpath[]
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Print a human-readable (or JSON) map of the published basalt-ui surface derived from
|
|
1286
|
+
* SURFACES + package.json. Every row is live-derived — the subpath list cannot drift.
|
|
1287
|
+
*
|
|
1288
|
+
* `basalt info` → human-readable table
|
|
1289
|
+
* `basalt info --json` → stable JSON (InfoOutput shape)
|
|
1290
|
+
*/
|
|
1291
|
+
export function info(flags: string[]): number {
|
|
1292
|
+
const pkgRoot = packageRoot()
|
|
1293
|
+
|
|
1294
|
+
// Read package.json for name, version, peerDependencies, peerDependenciesMeta, and exports.
|
|
1295
|
+
let pkgName = 'basalt-ui'
|
|
1296
|
+
let pkgVersion = '0.0.0'
|
|
1297
|
+
let peerDeps: Record<string, string> = {}
|
|
1298
|
+
let peerMeta: Record<string, { optional?: boolean }> = {}
|
|
1299
|
+
let pkgExports: Record<string, unknown> = {}
|
|
1300
|
+
try {
|
|
1301
|
+
const pkg = JSON.parse(readFileSync(resolve(pkgRoot, 'package.json'), 'utf8')) as {
|
|
1302
|
+
name?: string
|
|
1303
|
+
version?: string
|
|
1304
|
+
peerDependencies?: Record<string, string>
|
|
1305
|
+
peerDependenciesMeta?: Record<string, { optional?: boolean }>
|
|
1306
|
+
exports?: Record<string, unknown>
|
|
1307
|
+
}
|
|
1308
|
+
pkgName = pkg.name ?? pkgName
|
|
1309
|
+
pkgVersion = pkg.version ?? pkgVersion
|
|
1310
|
+
peerDeps = pkg.peerDependencies ?? {}
|
|
1311
|
+
peerMeta = pkg.peerDependenciesMeta ?? {}
|
|
1312
|
+
pkgExports = pkg.exports ?? {}
|
|
1313
|
+
} catch {
|
|
1314
|
+
// proceed with defaults
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// Derive optional peer set: all peers marked optional in peerDependenciesMeta.
|
|
1318
|
+
const optionalPeerSet = new Set(
|
|
1319
|
+
Object.entries(peerMeta)
|
|
1320
|
+
.filter(([, m]) => m.optional === true)
|
|
1321
|
+
.map(([name]) => name),
|
|
1322
|
+
)
|
|
1323
|
+
|
|
1324
|
+
// Build subpath rows from SURFACES — only real JS subpath keys (non-#, non-'./configs/*').
|
|
1325
|
+
// Restrict to keys that also appear in package.json exports so we match what is published.
|
|
1326
|
+
const publishedExportKeys = new Set(Object.keys(pkgExports))
|
|
1327
|
+
|
|
1328
|
+
const subpaths: InfoSubpath[] = []
|
|
1329
|
+
for (const [key, spec] of Object.entries(SURFACES) as [string, SurfaceSpec][]) {
|
|
1330
|
+
if (key.startsWith('#')) continue
|
|
1331
|
+
if (!publishedExportKeys.has(key)) continue
|
|
1332
|
+
|
|
1333
|
+
const docSpec = spec.kind === 'doctrine' ? spec : null
|
|
1334
|
+
|
|
1335
|
+
// Resolve optional peers from spec.optionalPeers (SURFACES SSOT), with versions from package.json.
|
|
1336
|
+
const specPeers: readonly string[] =
|
|
1337
|
+
docSpec !== null && 'optionalPeers' in docSpec && Array.isArray(docSpec.optionalPeers)
|
|
1338
|
+
? docSpec.optionalPeers
|
|
1339
|
+
: []
|
|
1340
|
+
const optionalPeers = specPeers
|
|
1341
|
+
.filter((p) => optionalPeerSet.has(p) && p in peerDeps)
|
|
1342
|
+
.map((p) => `${p}@${peerDeps[p]}`)
|
|
1343
|
+
|
|
1344
|
+
subpaths.push({
|
|
1345
|
+
path: `basalt-ui${key === '.' ? '' : key.slice(1)}`,
|
|
1346
|
+
description: spec.description ?? `basalt-ui${key === '.' ? '' : key} subpath`,
|
|
1347
|
+
layer: spec.layer,
|
|
1348
|
+
rule: docSpec?.rule ?? null,
|
|
1349
|
+
skills: docSpec?.skill ?? [],
|
|
1350
|
+
optionalPeers,
|
|
1351
|
+
})
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
const output: InfoOutput = { name: pkgName, version: pkgVersion, subpaths }
|
|
1355
|
+
|
|
1356
|
+
if (flags.includes('--json')) {
|
|
1357
|
+
console.log(JSON.stringify(output, null, 2))
|
|
1358
|
+
return 0
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// Human-readable output
|
|
1362
|
+
console.log(`\nbasalt-ui v${pkgVersion} — published surface\n`)
|
|
1363
|
+
const COL = { path: 32, layer: 18, rule: 18, skills: 36 }
|
|
1364
|
+
const header = [
|
|
1365
|
+
'SUBPATH'.padEnd(COL.path),
|
|
1366
|
+
'LAYER'.padEnd(COL.layer),
|
|
1367
|
+
'RULE'.padEnd(COL.rule),
|
|
1368
|
+
'SKILLS'.padEnd(COL.skills),
|
|
1369
|
+
'OPTIONAL PEERS',
|
|
1370
|
+
].join(' ')
|
|
1371
|
+
console.log(header)
|
|
1372
|
+
console.log('-'.repeat(header.length))
|
|
1373
|
+
for (const row of output.subpaths) {
|
|
1374
|
+
const line = [
|
|
1375
|
+
row.path.padEnd(COL.path),
|
|
1376
|
+
row.layer.padEnd(COL.layer),
|
|
1377
|
+
(row.rule ?? '—').padEnd(COL.rule),
|
|
1378
|
+
(row.skills.join(', ') || '—').padEnd(COL.skills),
|
|
1379
|
+
row.optionalPeers.join(', ') || '—',
|
|
1380
|
+
].join(' ')
|
|
1381
|
+
console.log(line)
|
|
1382
|
+
}
|
|
1383
|
+
console.log('')
|
|
1384
|
+
return 0
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* guard-hook — PreToolUse stdin adapter.
|
|
1389
|
+
*
|
|
1390
|
+
* Reads a JSON PreToolUse payload from stdin, evaluates it against the consumer's GuardConfig
|
|
1391
|
+
* (from the "basalt" key in the nearest package.json), and writes the Claude Code hook response
|
|
1392
|
+
* to stdout. Always exits 0 — the hook must never block Claude on a parse error or non-file tool.
|
|
1393
|
+
*/
|
|
1394
|
+
export async function guardHook(cwd: string = process.cwd()): Promise<number> {
|
|
1395
|
+
let raw: string
|
|
1396
|
+
try {
|
|
1397
|
+
// Bun: Bun.stdin.text() drains stdin to a string; under Node fall back to manual drain.
|
|
1398
|
+
if (typeof (globalThis as Record<string, unknown>)['Bun'] !== 'undefined') {
|
|
1399
|
+
// @ts-expect-error — Bun global, not in @types/bun for this import context
|
|
1400
|
+
raw = await globalThis['Bun'].stdin.text()
|
|
1401
|
+
} else {
|
|
1402
|
+
const chunks: Buffer[] = []
|
|
1403
|
+
for await (const chunk of process.stdin) chunks.push(chunk as Buffer)
|
|
1404
|
+
raw = Buffer.concat(chunks).toString('utf8')
|
|
1405
|
+
}
|
|
1406
|
+
} catch {
|
|
1407
|
+
// Unreadable stdin → allow
|
|
1408
|
+
process.stdout.write(
|
|
1409
|
+
'{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}\n',
|
|
1410
|
+
)
|
|
1411
|
+
return 0
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
let payload: unknown
|
|
1415
|
+
try {
|
|
1416
|
+
payload = JSON.parse(raw)
|
|
1417
|
+
} catch {
|
|
1418
|
+
// Malformed JSON → allow (never block on a bad payload)
|
|
1419
|
+
process.stdout.write(
|
|
1420
|
+
'{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}\n',
|
|
1421
|
+
)
|
|
1422
|
+
return 0
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
const cfg = readBasaltConfig(cwd)
|
|
1426
|
+
const guardCfg: GuardConfig = {
|
|
1427
|
+
spacingSteps: cfg.spacingSteps ?? DEFAULT_GUARD_CONFIG.spacingSteps,
|
|
1428
|
+
rawRadius: cfg.rawRadius ?? DEFAULT_GUARD_CONFIG.rawRadius,
|
|
1429
|
+
forbiddenAccents: cfg.forbiddenAccents ?? DEFAULT_GUARD_CONFIG.forbiddenAccents,
|
|
1430
|
+
rawSurface: cfg.rawSurface ?? DEFAULT_GUARD_CONFIG.rawSurface,
|
|
1431
|
+
cardWithBorder: cfg.cardWithBorder ?? DEFAULT_GUARD_CONFIG.cardWithBorder,
|
|
1432
|
+
offSystemSurfaceVar: cfg.offSystemSurfaceVar ?? DEFAULT_GUARD_CONFIG.offSystemSurfaceVar,
|
|
1433
|
+
rawHtmlLayout: cfg.rawHtmlLayout ?? DEFAULT_GUARD_CONFIG.rawHtmlLayout,
|
|
1434
|
+
inlineSpacing: cfg.inlineSpacing ?? DEFAULT_GUARD_CONFIG.inlineSpacing,
|
|
1435
|
+
inlineDisplay: cfg.inlineDisplay ?? DEFAULT_GUARD_CONFIG.inlineDisplay,
|
|
1436
|
+
rawVisxAxis: cfg.rawVisxAxis ?? DEFAULT_GUARD_CONFIG.rawVisxAxis,
|
|
1437
|
+
rawMotionValue: cfg.rawMotionValue ?? DEFAULT_GUARD_CONFIG.rawMotionValue,
|
|
1438
|
+
unframedChart: cfg.unframedChart ?? DEFAULT_GUARD_CONFIG.unframedChart,
|
|
1439
|
+
chartMissingAriaLabel: cfg.chartMissingAriaLabel ?? DEFAULT_GUARD_CONFIG.chartMissingAriaLabel,
|
|
1440
|
+
rawFormControl: cfg.rawFormControl ?? DEFAULT_GUARD_CONFIG.rawFormControl,
|
|
1441
|
+
sub16InputFont: cfg.sub16InputFont ?? DEFAULT_GUARD_CONFIG.sub16InputFont,
|
|
1442
|
+
allowComment: 'theme-allow',
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// Honor the consumer's roots / exempt / skip config so the hook never blocks edits to exempted
|
|
1446
|
+
// palette source or files outside the guarded roots (mirrors checkTheme's file-walk scoping).
|
|
1447
|
+
const roots = cfg.roots ?? DEFAULT_ROOTS
|
|
1448
|
+
const exempt = new Set(cfg.exempt ?? defaultExempt(cfg))
|
|
1449
|
+
const isInScope = (filePath: string): boolean => {
|
|
1450
|
+
const abs = isAbsolute(filePath) ? filePath : resolve(cwd, filePath)
|
|
1451
|
+
const rel = relative(cwd, abs).replace(/\\/g, '/')
|
|
1452
|
+
if (rel === '' || rel.startsWith('..')) return false
|
|
1453
|
+
if (SKIP.test(rel) || exempt.has(rel)) return false
|
|
1454
|
+
return roots.some((root) => {
|
|
1455
|
+
const r = root.replace(/\\/g, '/').replace(/\/+$/, '')
|
|
1456
|
+
return rel === r || rel.startsWith(`${r}/`)
|
|
1457
|
+
})
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
const result = evaluateGuardHook(payload, guardCfg, { isInScope })
|
|
1461
|
+
|
|
1462
|
+
if (result.permissionDecision === 'deny' && result.reason !== undefined) {
|
|
1463
|
+
process.stdout.write(
|
|
1464
|
+
JSON.stringify({
|
|
1465
|
+
hookSpecificOutput: {
|
|
1466
|
+
hookEventName: 'PreToolUse',
|
|
1467
|
+
permissionDecision: 'deny',
|
|
1468
|
+
permissionDecisionReason: result.reason,
|
|
1469
|
+
},
|
|
1470
|
+
}) + '\n',
|
|
1471
|
+
)
|
|
1472
|
+
} else {
|
|
1473
|
+
process.stdout.write(
|
|
1474
|
+
'{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}\n',
|
|
1475
|
+
)
|
|
1476
|
+
}
|
|
1477
|
+
return 0
|
|
1478
|
+
}
|
|
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
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* CLI dispatcher — parses argv (subcommand + flags) and returns the command's exit code. The bin
|
|
1488
|
+
* entry is the ONLY caller that translates this to process.exit, so init/sync/checkTheme stay free
|
|
1489
|
+
* of process side effects and are safe to import and call from tests.
|
|
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
|
+
*
|
|
1495
|
+
* The `guard-hook` subcommand is async (reads stdin); all others are synchronous.
|
|
1496
|
+
*/
|
|
1497
|
+
export function run(argv: string[], cwd: string = process.cwd()): number | Promise<number> {
|
|
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
|
+
}
|
|
1509
|
+
switch (cmd) {
|
|
1510
|
+
case 'init':
|
|
1511
|
+
return init(cwd, {
|
|
1512
|
+
withRouter: flags.includes('--with-router'),
|
|
1513
|
+
withQuery: flags.includes('--with-query'),
|
|
1514
|
+
})
|
|
1515
|
+
case 'sync':
|
|
1516
|
+
return sync({ force: flags.includes('--force'), check: flags.includes('--check') }, cwd)
|
|
1517
|
+
case 'check-theme':
|
|
1518
|
+
return checkTheme(cwd)
|
|
1519
|
+
case 'check-coverage':
|
|
1520
|
+
return checkCoverage()
|
|
1521
|
+
case 'info':
|
|
1522
|
+
return info(flags)
|
|
1523
|
+
case 'doctor':
|
|
1524
|
+
return doctor(cwd)
|
|
1525
|
+
case 'guard-hook':
|
|
1526
|
+
return guardHook(cwd)
|
|
1527
|
+
default:
|
|
1528
|
+
console.error(USAGE)
|
|
1529
|
+
return 1
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
// Re-export the managed-file manifest for testing / introspection (no default export).
|
|
1534
|
+
export { managedFiles, MANIFEST_PATH, RULE_NAMES, SKILL_NAMES }
|
|
1535
|
+
export type { ManagedFile, Manifest, SyncOptions, DoctorResult }
|