basalt-ui 0.4.2 → 1.0.0

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