@rien7/seji 0.0.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/bin/design-surface.mjs +6 -0
  2. package/bin/postinstall.mjs +19 -0
  3. package/bin/seji.mjs +585 -0
  4. package/dist/agent/host.d.mts +34 -0
  5. package/dist/agent/host.mjs +387 -0
  6. package/dist/agent/messages.d.mts +9 -0
  7. package/dist/agent/messages.mjs +70 -0
  8. package/dist/agent/runtimes.mjs +157 -0
  9. package/dist/cli/app.mjs +321 -0
  10. package/dist/cli/appScan.mjs +284 -0
  11. package/dist/cli/catalog.mjs +78 -0
  12. package/dist/cli/component.mjs +165 -0
  13. package/dist/cli/consolidate.mjs +159 -0
  14. package/dist/cli/cssImport.mjs +68 -0
  15. package/dist/cli/dev.mjs +339 -0
  16. package/dist/cli/doctor.mjs +311 -0
  17. package/dist/cli/init.mjs +338 -0
  18. package/dist/cli/legacyNames.mjs +266 -0
  19. package/dist/cli/migrate.mjs +163 -0
  20. package/dist/cli/prompt.mjs +34 -0
  21. package/dist/cli/propose.mjs +208 -0
  22. package/dist/cli/providers.mjs +344 -0
  23. package/dist/cli/reviewOps.mjs +110 -0
  24. package/dist/cli/semver.mjs +45 -0
  25. package/dist/cli/setup.mjs +360 -0
  26. package/dist/cli/sketches.mjs +47 -0
  27. package/dist/cli/skills.mjs +150 -0
  28. package/dist/cli/snapshot.mjs +107 -0
  29. package/dist/cli/tokenOps.mjs +120 -0
  30. package/dist/cli/types.mjs +191 -0
  31. package/dist/cli/updater.mjs +274 -0
  32. package/dist/components/astIndex.mjs +992 -0
  33. package/dist/components/ops.mjs +1069 -0
  34. package/dist/editor/AgentProposalCard.d.ts +10 -0
  35. package/dist/editor/AgentProposalCard.d.ts.map +1 -0
  36. package/dist/editor/AgentProposalCard.js +31 -0
  37. package/dist/editor/AgentProposalCard.js.map +1 -0
  38. package/dist/editor/App.d.ts +2 -0
  39. package/dist/editor/App.d.ts.map +1 -0
  40. package/dist/editor/App.js +2834 -0
  41. package/dist/editor/App.js.map +1 -0
  42. package/dist/editor/CanvasHud.d.ts +12 -0
  43. package/dist/editor/CanvasHud.d.ts.map +1 -0
  44. package/dist/editor/CanvasHud.js +13 -0
  45. package/dist/editor/CanvasHud.js.map +1 -0
  46. package/dist/editor/CanvasSurface.d.ts +31 -0
  47. package/dist/editor/CanvasSurface.d.ts.map +1 -0
  48. package/dist/editor/CanvasSurface.js +270 -0
  49. package/dist/editor/CanvasSurface.js.map +1 -0
  50. package/dist/editor/CommentPopover.d.ts +17 -0
  51. package/dist/editor/CommentPopover.d.ts.map +1 -0
  52. package/dist/editor/CommentPopover.js +62 -0
  53. package/dist/editor/CommentPopover.js.map +1 -0
  54. package/dist/editor/Comments.d.ts +13 -0
  55. package/dist/editor/Comments.d.ts.map +1 -0
  56. package/dist/editor/Comments.js +41 -0
  57. package/dist/editor/Comments.js.map +1 -0
  58. package/dist/editor/ComponentPage.d.ts +28 -0
  59. package/dist/editor/ComponentPage.d.ts.map +1 -0
  60. package/dist/editor/ComponentPage.js +55 -0
  61. package/dist/editor/ComponentPage.js.map +1 -0
  62. package/dist/editor/ComponentPanel.d.ts +38 -0
  63. package/dist/editor/ComponentPanel.d.ts.map +1 -0
  64. package/dist/editor/ComponentPanel.js +275 -0
  65. package/dist/editor/ComponentPanel.js.map +1 -0
  66. package/dist/editor/Glyph.d.ts +51 -0
  67. package/dist/editor/Glyph.d.ts.map +1 -0
  68. package/dist/editor/Glyph.js +50 -0
  69. package/dist/editor/Glyph.js.map +1 -0
  70. package/dist/editor/History.d.ts +7 -0
  71. package/dist/editor/History.d.ts.map +1 -0
  72. package/dist/editor/History.js +51 -0
  73. package/dist/editor/History.js.map +1 -0
  74. package/dist/editor/Inspector.d.ts +56 -0
  75. package/dist/editor/Inspector.d.ts.map +1 -0
  76. package/dist/editor/Inspector.js +510 -0
  77. package/dist/editor/Inspector.js.map +1 -0
  78. package/dist/editor/LazyMount.d.ts +10 -0
  79. package/dist/editor/LazyMount.d.ts.map +1 -0
  80. package/dist/editor/LazyMount.js +29 -0
  81. package/dist/editor/LazyMount.js.map +1 -0
  82. package/dist/editor/LocaleSwitch.d.ts +3 -0
  83. package/dist/editor/LocaleSwitch.d.ts.map +1 -0
  84. package/dist/editor/LocaleSwitch.js +9 -0
  85. package/dist/editor/LocaleSwitch.js.map +1 -0
  86. package/dist/editor/PreviewFrame.d.ts +10 -0
  87. package/dist/editor/PreviewFrame.d.ts.map +1 -0
  88. package/dist/editor/PreviewFrame.js +22 -0
  89. package/dist/editor/PreviewFrame.js.map +1 -0
  90. package/dist/editor/ProjectIndex.d.ts +12 -0
  91. package/dist/editor/ProjectIndex.d.ts.map +1 -0
  92. package/dist/editor/ProjectIndex.js +43 -0
  93. package/dist/editor/ProjectIndex.js.map +1 -0
  94. package/dist/editor/PromoteComponent.d.ts +28 -0
  95. package/dist/editor/PromoteComponent.d.ts.map +1 -0
  96. package/dist/editor/PromoteComponent.js +33 -0
  97. package/dist/editor/PromoteComponent.js.map +1 -0
  98. package/dist/editor/PromoteForm.d.ts +18 -0
  99. package/dist/editor/PromoteForm.d.ts.map +1 -0
  100. package/dist/editor/PromoteForm.js +35 -0
  101. package/dist/editor/PromoteForm.js.map +1 -0
  102. package/dist/editor/PromoteToken.d.ts +31 -0
  103. package/dist/editor/PromoteToken.d.ts.map +1 -0
  104. package/dist/editor/PromoteToken.js +94 -0
  105. package/dist/editor/PromoteToken.js.map +1 -0
  106. package/dist/editor/StatePreviews.d.ts +28 -0
  107. package/dist/editor/StatePreviews.d.ts.map +1 -0
  108. package/dist/editor/StatePreviews.js +113 -0
  109. package/dist/editor/StatePreviews.js.map +1 -0
  110. package/dist/editor/ValueCombo.d.ts +51 -0
  111. package/dist/editor/ValueCombo.d.ts.map +1 -0
  112. package/dist/editor/ValueCombo.js +260 -0
  113. package/dist/editor/ValueCombo.js.map +1 -0
  114. package/dist/editor/agent/AgentPanel.d.ts +19 -0
  115. package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
  116. package/dist/editor/agent/AgentPanel.js +271 -0
  117. package/dist/editor/agent/AgentPanel.js.map +1 -0
  118. package/dist/editor/agent/Markdown.d.ts +5 -0
  119. package/dist/editor/agent/Markdown.d.ts.map +1 -0
  120. package/dist/editor/agent/Markdown.js +28 -0
  121. package/dist/editor/agent/Markdown.js.map +1 -0
  122. package/dist/editor/agent/agentApi.d.ts +106 -0
  123. package/dist/editor/agent/agentApi.d.ts.map +1 -0
  124. package/dist/editor/agent/agentApi.js +66 -0
  125. package/dist/editor/agent/agentApi.js.map +1 -0
  126. package/dist/editor/agent/toolLines.d.ts +38 -0
  127. package/dist/editor/agent/toolLines.d.ts.map +1 -0
  128. package/dist/editor/agent/toolLines.js +159 -0
  129. package/dist/editor/agent/toolLines.js.map +1 -0
  130. package/dist/editor/agent/useAgent.d.ts +15 -0
  131. package/dist/editor/agent/useAgent.d.ts.map +1 -0
  132. package/dist/editor/agent/useAgent.js +65 -0
  133. package/dist/editor/agent/useAgent.js.map +1 -0
  134. package/dist/editor/api.d.ts +378 -0
  135. package/dist/editor/api.d.ts.map +1 -0
  136. package/dist/editor/api.js +247 -0
  137. package/dist/editor/api.js.map +1 -0
  138. package/dist/editor/camera.d.ts +18 -0
  139. package/dist/editor/camera.d.ts.map +1 -0
  140. package/dist/editor/camera.js +40 -0
  141. package/dist/editor/camera.js.map +1 -0
  142. package/dist/editor/canvas.d.ts +25 -0
  143. package/dist/editor/canvas.d.ts.map +1 -0
  144. package/dist/editor/canvas.js +35 -0
  145. package/dist/editor/canvas.js.map +1 -0
  146. package/dist/editor/changes/ChangesPage.d.ts +25 -0
  147. package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
  148. package/dist/editor/changes/ChangesPage.js +132 -0
  149. package/dist/editor/changes/ChangesPage.js.map +1 -0
  150. package/dist/editor/changes/changeModel.d.ts +25 -0
  151. package/dist/editor/changes/changeModel.d.ts.map +1 -0
  152. package/dist/editor/changes/changeModel.js +81 -0
  153. package/dist/editor/changes/changeModel.js.map +1 -0
  154. package/dist/editor/changes/changeState.d.mts +29 -0
  155. package/dist/editor/changes/changeState.mjs +187 -0
  156. package/dist/editor/chrome/EditorChrome.d.ts +49 -0
  157. package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
  158. package/dist/editor/chrome/EditorChrome.js +21 -0
  159. package/dist/editor/chrome/EditorChrome.js.map +1 -0
  160. package/dist/editor/drafts.d.ts +46 -0
  161. package/dist/editor/drafts.d.ts.map +1 -0
  162. package/dist/editor/drafts.js +38 -0
  163. package/dist/editor/drafts.js.map +1 -0
  164. package/dist/editor/i18n.d.ts +29 -0
  165. package/dist/editor/i18n.d.ts.map +1 -0
  166. package/dist/editor/i18n.js +2320 -0
  167. package/dist/editor/i18n.js.map +1 -0
  168. package/dist/editor/iconStroke.d.ts +6 -0
  169. package/dist/editor/iconStroke.d.ts.map +1 -0
  170. package/dist/editor/iconStroke.js +6 -0
  171. package/dist/editor/iconStroke.js.map +1 -0
  172. package/dist/editor/main.d.ts +2 -0
  173. package/dist/editor/main.d.ts.map +1 -0
  174. package/dist/editor/main.js +14 -0
  175. package/dist/editor/main.js.map +1 -0
  176. package/dist/editor/model.d.ts +16 -0
  177. package/dist/editor/model.d.ts.map +1 -0
  178. package/dist/editor/model.js +11 -0
  179. package/dist/editor/model.js.map +1 -0
  180. package/dist/editor/reasons.d.ts +44 -0
  181. package/dist/editor/reasons.d.ts.map +1 -0
  182. package/dist/editor/reasons.js +131 -0
  183. package/dist/editor/reasons.js.map +1 -0
  184. package/dist/editor/reviewLifecycle.d.ts +8 -0
  185. package/dist/editor/reviewLifecycle.d.ts.map +1 -0
  186. package/dist/editor/reviewLifecycle.js +21 -0
  187. package/dist/editor/reviewLifecycle.js.map +1 -0
  188. package/dist/editor/styles.css +8737 -0
  189. package/dist/editor/tokenMatch.d.ts +59 -0
  190. package/dist/editor/tokenMatch.d.ts.map +1 -0
  191. package/dist/editor/tokenMatch.js +198 -0
  192. package/dist/editor/tokenMatch.js.map +1 -0
  193. package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
  194. package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
  195. package/dist/editor/tokens/ConsolidatePage.js +244 -0
  196. package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
  197. package/dist/editor/tokens/TokenActivity.d.ts +18 -0
  198. package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
  199. package/dist/editor/tokens/TokenActivity.js +18 -0
  200. package/dist/editor/tokens/TokenActivity.js.map +1 -0
  201. package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
  202. package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
  203. package/dist/editor/tokens/TokenDialogs.js +119 -0
  204. package/dist/editor/tokens/TokenDialogs.js.map +1 -0
  205. package/dist/editor/tokens/TokenList.d.ts +21 -0
  206. package/dist/editor/tokens/TokenList.d.ts.map +1 -0
  207. package/dist/editor/tokens/TokenList.js +98 -0
  208. package/dist/editor/tokens/TokenList.js.map +1 -0
  209. package/dist/editor/tokens/TokenPage.d.ts +25 -0
  210. package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
  211. package/dist/editor/tokens/TokenPage.js +108 -0
  212. package/dist/editor/tokens/TokenPage.js.map +1 -0
  213. package/dist/editor/tokens/tokenModel.d.ts +35 -0
  214. package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
  215. package/dist/editor/tokens/tokenModel.js +72 -0
  216. package/dist/editor/tokens/tokenModel.js.map +1 -0
  217. package/dist/editor/ui/Button.d.ts +3 -0
  218. package/dist/editor/ui/Button.d.ts.map +1 -0
  219. package/dist/editor/ui/Button.js +6 -0
  220. package/dist/editor/ui/Button.js.map +1 -0
  221. package/dist/editor/ui/CommentBox.d.ts +23 -0
  222. package/dist/editor/ui/CommentBox.d.ts.map +1 -0
  223. package/dist/editor/ui/CommentBox.js +41 -0
  224. package/dist/editor/ui/CommentBox.js.map +1 -0
  225. package/dist/editor/ui/Icon.d.ts +8 -0
  226. package/dist/editor/ui/Icon.d.ts.map +1 -0
  227. package/dist/editor/ui/Icon.js +6 -0
  228. package/dist/editor/ui/Icon.js.map +1 -0
  229. package/dist/editor/ui/IconButton.d.ts +11 -0
  230. package/dist/editor/ui/IconButton.d.ts.map +1 -0
  231. package/dist/editor/ui/IconButton.js +6 -0
  232. package/dist/editor/ui/IconButton.js.map +1 -0
  233. package/dist/editor/ui/NumberInput.d.ts +14 -0
  234. package/dist/editor/ui/NumberInput.d.ts.map +1 -0
  235. package/dist/editor/ui/NumberInput.js +6 -0
  236. package/dist/editor/ui/NumberInput.js.map +1 -0
  237. package/dist/editor/ui/PageLine.d.ts +14 -0
  238. package/dist/editor/ui/PageLine.d.ts.map +1 -0
  239. package/dist/editor/ui/PageLine.js +7 -0
  240. package/dist/editor/ui/PageLine.js.map +1 -0
  241. package/dist/editor/ui/SearchPicker.d.ts +41 -0
  242. package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
  243. package/dist/editor/ui/SearchPicker.js +82 -0
  244. package/dist/editor/ui/SearchPicker.js.map +1 -0
  245. package/dist/editor/ui/Select.d.ts +19 -0
  246. package/dist/editor/ui/Select.d.ts.map +1 -0
  247. package/dist/editor/ui/Select.js +12 -0
  248. package/dist/editor/ui/Select.js.map +1 -0
  249. package/dist/editor/ui/TokenField.d.ts +14 -0
  250. package/dist/editor/ui/TokenField.d.ts.map +1 -0
  251. package/dist/editor/ui/TokenField.js +41 -0
  252. package/dist/editor/ui/TokenField.js.map +1 -0
  253. package/dist/editor/ui/TokenPicker.d.ts +31 -0
  254. package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
  255. package/dist/editor/ui/TokenPicker.js +26 -0
  256. package/dist/editor/ui/TokenPicker.js.map +1 -0
  257. package/dist/editor/useBuildError.d.ts +7 -0
  258. package/dist/editor/useBuildError.d.ts.map +1 -0
  259. package/dist/editor/useBuildError.js +30 -0
  260. package/dist/editor/useBuildError.js.map +1 -0
  261. package/dist/editor/useLatestRequest.d.ts +22 -0
  262. package/dist/editor/useLatestRequest.d.ts.map +1 -0
  263. package/dist/editor/useLatestRequest.js +49 -0
  264. package/dist/editor/useLatestRequest.js.map +1 -0
  265. package/dist/editor-bundle/editor.css +2 -0
  266. package/dist/editor-bundle/editor.js +83 -0
  267. package/dist/editor-ui.d.ts +15 -0
  268. package/dist/editor-ui.d.ts.map +1 -0
  269. package/dist/editor-ui.js +14 -0
  270. package/dist/editor-ui.js.map +1 -0
  271. package/dist/inspector/runtime.d.ts +18 -0
  272. package/dist/inspector/runtime.d.ts.map +1 -0
  273. package/dist/inspector/runtime.js +1280 -0
  274. package/dist/inspector/runtime.js.map +1 -0
  275. package/dist/preview/main.d.ts +3 -0
  276. package/dist/preview/main.d.ts.map +1 -0
  277. package/dist/preview/main.js +320 -0
  278. package/dist/preview/main.js.map +1 -0
  279. package/dist/preview/preview.css +40 -0
  280. package/dist/runtime/index.d.ts +3 -0
  281. package/dist/runtime/index.d.ts.map +1 -0
  282. package/dist/runtime/index.js +2 -0
  283. package/dist/runtime/index.js.map +1 -0
  284. package/dist/shared/buildError.d.mts +27 -0
  285. package/dist/shared/buildError.mjs +141 -0
  286. package/dist/shared/cameraFit.d.mts +16 -0
  287. package/dist/shared/cameraFit.mjs +47 -0
  288. package/dist/shared/canvasLayout.d.mts +13 -0
  289. package/dist/shared/canvasLayout.mjs +171 -0
  290. package/dist/shared/commentShots.d.mts +12 -0
  291. package/dist/shared/commentShots.mjs +53 -0
  292. package/dist/shared/componentExtract.d.mts +43 -0
  293. package/dist/shared/componentExtract.mjs +136 -0
  294. package/dist/shared/componentMeta.d.mts +26 -0
  295. package/dist/shared/componentMeta.mjs +87 -0
  296. package/dist/shared/componentOps.d.mts +70 -0
  297. package/dist/shared/componentOps.mjs +407 -0
  298. package/dist/shared/componentTarget.d.mts +15 -0
  299. package/dist/shared/componentTarget.mjs +58 -0
  300. package/dist/shared/components.d.mts +30 -0
  301. package/dist/shared/components.mjs +106 -0
  302. package/dist/shared/consolidateCategories.d.mts +2 -0
  303. package/dist/shared/consolidateCategories.mjs +6 -0
  304. package/dist/shared/env.d.mts +4 -0
  305. package/dist/shared/env.mjs +18 -0
  306. package/dist/shared/gitChanges.d.mts +2 -0
  307. package/dist/shared/gitChanges.mjs +30 -0
  308. package/dist/shared/legacyPaths.d.mts +1 -0
  309. package/dist/shared/legacyPaths.mjs +9 -0
  310. package/dist/shared/oklab.d.mts +6 -0
  311. package/dist/shared/oklab.mjs +56 -0
  312. package/dist/shared/optimizeEntries.d.mts +5 -0
  313. package/dist/shared/optimizeEntries.mjs +24 -0
  314. package/dist/shared/packages.d.mts +11 -0
  315. package/dist/shared/packages.mjs +96 -0
  316. package/dist/shared/projectFiles.d.mts +23 -0
  317. package/dist/shared/projectFiles.mjs +72 -0
  318. package/dist/shared/prompt.d.mts +25 -0
  319. package/dist/shared/prompt.mjs +217 -0
  320. package/dist/shared/proposals.d.mts +11 -0
  321. package/dist/shared/proposals.mjs +42 -0
  322. package/dist/shared/protocol.d.ts +122 -0
  323. package/dist/shared/protocol.d.ts.map +1 -0
  324. package/dist/shared/protocol.js +7 -0
  325. package/dist/shared/protocol.js.map +1 -0
  326. package/dist/shared/reviewArchive.d.mts +4 -0
  327. package/dist/shared/reviewArchive.mjs +19 -0
  328. package/dist/shared/reviewStore.d.mts +30 -0
  329. package/dist/shared/reviewStore.mjs +218 -0
  330. package/dist/shared/reviewVerify.d.mts +21 -0
  331. package/dist/shared/reviewVerify.mjs +158 -0
  332. package/dist/shared/sizeModes.d.mts +15 -0
  333. package/dist/shared/sizeModes.mjs +53 -0
  334. package/dist/shared/sketches.d.mts +10 -0
  335. package/dist/shared/sketches.mjs +64 -0
  336. package/dist/shared/snapshotCheck.d.mts +13 -0
  337. package/dist/shared/snapshotCheck.mjs +81 -0
  338. package/dist/shared/timeout.d.mts +1 -0
  339. package/dist/shared/timeout.mjs +15 -0
  340. package/dist/shared/tokens.d.ts +2 -0
  341. package/dist/shared/tokens.d.ts.map +1 -0
  342. package/dist/shared/tokens.js +2 -0
  343. package/dist/shared/tokens.js.map +1 -0
  344. package/dist/shared/types.d.ts +689 -0
  345. package/dist/shared/types.d.ts.map +1 -0
  346. package/dist/shared/types.js +13 -0
  347. package/dist/shared/types.js.map +1 -0
  348. package/dist/shared/wheelRouting.d.mts +9 -0
  349. package/dist/shared/wheelRouting.mjs +31 -0
  350. package/dist/shared/writeScope.mjs +96 -0
  351. package/dist/snapshots/diff.d.mts +28 -0
  352. package/dist/snapshots/diff.mjs +263 -0
  353. package/dist/snapshots/index.d.mts +110 -0
  354. package/dist/snapshots/index.mjs +638 -0
  355. package/dist/snapshots/render.d.mts +24 -0
  356. package/dist/snapshots/render.mjs +250 -0
  357. package/dist/snapshots/toolOps.d.mts +25 -0
  358. package/dist/snapshots/toolOps.mjs +69 -0
  359. package/dist/tokens/adapters/css.mjs +51 -0
  360. package/dist/tokens/adapters/cssInCode.mjs +314 -0
  361. package/dist/tokens/adapters/oxcShared.mjs +80 -0
  362. package/dist/tokens/adapters/preprocessor.mjs +63 -0
  363. package/dist/tokens/adapters/registry.mjs +53 -0
  364. package/dist/tokens/adapters/tailwindcss.mjs +424 -0
  365. package/dist/tokens/adapters/types.mjs +117 -0
  366. package/dist/tokens/consolidate/index.d.mts +42 -0
  367. package/dist/tokens/consolidate/index.mjs +111 -0
  368. package/dist/tokens/consolidate/normalize.mjs +479 -0
  369. package/dist/tokens/consolidate/plan.mjs +726 -0
  370. package/dist/tokens/consolidate/scan.mjs +928 -0
  371. package/dist/tokens/extract.mjs +441 -0
  372. package/dist/tokens/moduleData.d.mts +14 -0
  373. package/dist/tokens/moduleData.mjs +32 -0
  374. package/dist/tokens/opLock.d.mts +4 -0
  375. package/dist/tokens/opLock.mjs +108 -0
  376. package/dist/tokens/ops.d.mts +71 -0
  377. package/dist/tokens/ops.mjs +1511 -0
  378. package/dist/tokens/pipeline.mjs +813 -0
  379. package/dist/tokens/report.d.mts +47 -0
  380. package/dist/tokens/report.mjs +257 -0
  381. package/dist/tokens/rewrite/code.mjs +172 -0
  382. package/dist/tokens/rewrite/css.mjs +154 -0
  383. package/dist/tokens/rewrite/index.mjs +244 -0
  384. package/dist/tokens/rewrite/tailwind.mjs +288 -0
  385. package/dist/tokens/rewrite/text.mjs +116 -0
  386. package/dist/tokens/rewrite/value.mjs +115 -0
  387. package/dist/tokens/usage.d.mts +97 -0
  388. package/dist/tokens/usage.mjs +680 -0
  389. package/dist/vite/agent.d.ts +21 -0
  390. package/dist/vite/agent.d.ts.map +1 -0
  391. package/dist/vite/agent.js +165 -0
  392. package/dist/vite/agent.js.map +1 -0
  393. package/dist/vite/events.d.ts +27 -0
  394. package/dist/vite/events.d.ts.map +1 -0
  395. package/dist/vite/events.js +156 -0
  396. package/dist/vite/events.js.map +1 -0
  397. package/dist/vite/layout.d.ts +2 -0
  398. package/dist/vite/layout.d.ts.map +1 -0
  399. package/dist/vite/layout.js +4 -0
  400. package/dist/vite/layout.js.map +1 -0
  401. package/dist/vite/plugin.d.ts +40 -0
  402. package/dist/vite/plugin.d.ts.map +1 -0
  403. package/dist/vite/plugin.js +1264 -0
  404. package/dist/vite/plugin.js.map +1 -0
  405. package/dist/vite/requestGuard.d.mts +3 -0
  406. package/dist/vite/requestGuard.mjs +43 -0
  407. package/dist/vite/review.d.ts +11 -0
  408. package/dist/vite/review.d.ts.map +1 -0
  409. package/dist/vite/review.js +283 -0
  410. package/dist/vite/review.js.map +1 -0
  411. package/package.json +106 -1
  412. package/skills/seji/SKILL.md +400 -0
  413. package/skills/seji-authoring/SKILL.md +397 -0
  414. package/skills/seji-tokens/SKILL.md +432 -0
@@ -0,0 +1,813 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
3
+ import { basename, dirname, join, relative, resolve, sep } from 'node:path'
4
+
5
+ import { generatedCssPath } from '../cli/app.mjs'
6
+ import { analyzeFilesWithAdapters } from './adapters/registry.mjs'
7
+
8
+ const TIERS = ['primitive', 'semantic', 'component']
9
+ const TIER_ORDER = Object.fromEntries(TIERS.map((tier, index) => [tier, index]))
10
+
11
+ export const DEFAULT_TOKEN_CONFIG = {
12
+ tokenDir: 'design/tokens',
13
+ cssOut: 'src/tokens.generated.css',
14
+ tsOut: 'design/.seji/tokens.generated.ts',
15
+ manifestOut: 'design/.seji/tokens.manifest.json',
16
+ scanDirs: ['src', 'design'],
17
+ // Directories outside the project root the tools may rewrite (shared/writeScope.mjs).
18
+ // Empty: token and component operations never write outside the root.
19
+ writableDirs: [],
20
+ cssFormat: 'theme',
21
+ contrastPairs: [],
22
+ localAliases: [],
23
+ }
24
+
25
+ const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'))
26
+ const sha256 = (value) => createHash('sha256').update(value).digest('hex')
27
+ const toPosix = (file) => file.split(sep).join('/')
28
+
29
+ export const cssNameOf = (tokenPath) => `--${tokenPath.join('-')}`
30
+
31
+ export const aliasPath = (value) => {
32
+ if (typeof value !== 'string') return null
33
+ const match = /^\{([^}]+)\}$/.exec(value)
34
+ return match ? match[1] : null
35
+ }
36
+
37
+ // A token's tier must be explicit: either `$extensions["design-surface"].tier` on the token or
38
+ // one of its groups, or a `<tier>.tokens.json` source file name. There is no silent default.
39
+ const tierOf = (meta, file, tokenPath) => {
40
+ const fromFile = /^(primitive|semantic|component)\.tokens\.json$/.exec(basename(file))?.[1]
41
+ const tier = meta.tier ?? fromFile
42
+ if (!tier) {
43
+ throw new Error(
44
+ `${file}: ${tokenPath.join('.')} has no tier. Set $extensions["design-surface"].tier (primitive | semantic | component) on the token or its group, or name the file <tier>.tokens.json.`,
45
+ )
46
+ }
47
+ if (!TIERS.includes(tier)) {
48
+ throw new Error(`${file}: ${tokenPath.join('.')} has invalid tier "${tier}". Expected one of: ${TIERS.join(', ')}`)
49
+ }
50
+ return tier
51
+ }
52
+
53
+ function mergeMeta(base, next) {
54
+ return { ...base, ...(next ?? {}) }
55
+ }
56
+
57
+ export function loadTokenConfig(root, overrides = {}) {
58
+ const configPath = join(root, 'design/tokens.config.json')
59
+ const fileConfig = existsSync(configPath) ? readJson(configPath) : {}
60
+ const merged = {
61
+ ...DEFAULT_TOKEN_CONFIG,
62
+ ...fileConfig,
63
+ ...overrides,
64
+ }
65
+ if (merged.cssFormat !== 'theme' && merged.cssFormat !== 'root') {
66
+ throw new Error(`Invalid cssFormat "${merged.cssFormat}". Expected "theme" or "root".`)
67
+ }
68
+ return {
69
+ tokenDir: String(merged.tokenDir),
70
+ cssOut: String(merged.cssOut),
71
+ // Absolute: cssOut against the app (not the design home of a root design/).
72
+ cssOutPath: generatedCssPath(root, String(merged.cssOut)),
73
+ tsOut: String(merged.tsOut),
74
+ manifestOut: String(merged.manifestOut),
75
+ scanDirs: Array.isArray(merged.scanDirs) ? merged.scanDirs.map(String) : DEFAULT_TOKEN_CONFIG.scanDirs,
76
+ writableDirs: Array.isArray(merged.writableDirs) ? merged.writableDirs.map(String) : [],
77
+ cssFormat: merged.cssFormat,
78
+ contrastPairs: Array.isArray(merged.contrastPairs) ? merged.contrastPairs : [],
79
+ localAliases: Array.isArray(merged.localAliases) ? merged.localAliases.map(String) : [],
80
+ adapters: Array.isArray(merged.adapters) ? merged.adapters.map(String) : undefined,
81
+ }
82
+ }
83
+
84
+ export function walkTokens(node, tokenPath, inheritedMeta, inheritedType, file, root, records) {
85
+ if (!node || typeof node !== 'object' || Array.isArray(node)) return
86
+ if ('$value' in node) {
87
+ const own = node.$extensions?.['design-surface'] ?? {}
88
+ const meta = mergeMeta(inheritedMeta, own)
89
+ const type = node.$type ?? inheritedType
90
+ if (!type) throw new Error(`${file}: ${tokenPath.join('.')} has no $type`)
91
+ const cssName = meta.cssName ?? cssNameOf(tokenPath)
92
+ records.push({
93
+ path: tokenPath,
94
+ cssName,
95
+ raw: node.$value,
96
+ alias: aliasPath(node.$value),
97
+ dtcgType: type,
98
+ type: meta.uiType ?? (type === 'color' ? 'color' : type === 'dimension' ? 'length' : 'text'),
99
+ tier: tierOf(meta, file, tokenPath),
100
+ group: meta.group ?? tokenPath[0],
101
+ label: meta.label ?? tokenPath[tokenPath.length - 1],
102
+ labelZh: meta.labelZh,
103
+ description: node.$description,
104
+ // DTCG `$deprecated`: true or a reason string (the tool writes the reason).
105
+ deprecated: node.$deprecated === undefined || node.$deprecated === false ? undefined : node.$deprecated,
106
+ groupLabel: inheritedMeta.label,
107
+ groupLabelZh: inheritedMeta.labelZh,
108
+ min: typeof meta.min === 'number' ? meta.min : undefined,
109
+ max: typeof meta.max === 'number' ? meta.max : undefined,
110
+ step: typeof meta.step === 'number' ? meta.step : undefined,
111
+ source: toPosix(relative(root, file)),
112
+ })
113
+ return
114
+ }
115
+ const own = node.$extensions?.['design-surface'] ?? {}
116
+ const meta = mergeMeta(inheritedMeta, own)
117
+ const type = node.$type ?? inheritedType
118
+ for (const [key, value] of Object.entries(node)) {
119
+ if (key.startsWith('$')) continue
120
+ walkTokens(value, [...tokenPath, key], meta, type, file, root, records)
121
+ }
122
+ }
123
+
124
+ export function readTokenRecords(root, tokenDir) {
125
+ const tokenRoot = resolve(root, tokenDir)
126
+ if (!existsSync(tokenRoot)) {
127
+ throw new Error(`Missing token source directory: ${tokenRoot}`)
128
+ }
129
+ const files = readdirSync(tokenRoot)
130
+ .filter((file) => file.endsWith('.tokens.json'))
131
+ .sort()
132
+ .map((file) => join(tokenRoot, file))
133
+ if (!files.length) throw new Error(`No *.tokens.json files found in ${tokenRoot}`)
134
+ const records = []
135
+ for (const file of files) {
136
+ const json = readJson(file)
137
+ walkTokens(json, [], {}, undefined, file, root, records)
138
+ }
139
+ return { files, records }
140
+ }
141
+
142
+ export function resolveRecords(records) {
143
+ const byPath = new Map(records.map((record) => [record.path.join('.'), record]))
144
+ const byCss = new Map(records.map((record) => [record.cssName, record]))
145
+ const seen = new Map()
146
+
147
+ const resolveToken = (record, stack = []) => {
148
+ const key = record.path.join('.')
149
+ if (seen.has(key)) return seen.get(key)
150
+ if (stack.includes(key)) {
151
+ throw new Error(`Circular token alias: ${[...stack, key].join(' -> ')}`)
152
+ }
153
+ let value
154
+ if (record.alias) {
155
+ const target = byPath.get(record.alias)
156
+ if (!target) throw new Error(`${key} references missing token ${record.alias}`)
157
+ value = resolveToken(target, [...stack, key])
158
+ } else if (record.raw && typeof record.raw === 'object' && !Array.isArray(record.raw)) {
159
+ if ('value' in record.raw && 'unit' in record.raw) {
160
+ value = `${record.raw.value}${record.raw.unit}`
161
+ } else {
162
+ throw new Error(`${key} has an unsupported composite value`)
163
+ }
164
+ } else {
165
+ value = String(record.raw).replace(/var\((--[a-zA-Z0-9_-]+)\)/g, (match, name) => {
166
+ const target = byCss.get(name)
167
+ return target ? resolveToken(target, stack) : match
168
+ })
169
+ }
170
+ seen.set(key, value)
171
+ return value
172
+ }
173
+
174
+ for (const record of records) {
175
+ record.value = resolveToken(record)
176
+ if (record.alias) {
177
+ const target = byPath.get(record.alias)
178
+ if (target && record.dtcgType !== target.dtcgType) {
179
+ // DTCG aliases inherit the target type; a mismatched explicit type is a bug.
180
+ throw new Error(
181
+ `${record.path.join('.')} type ${record.dtcgType} does not match alias ${record.alias} type ${target.dtcgType}`,
182
+ )
183
+ }
184
+ }
185
+ }
186
+
187
+ const seenCss = new Map()
188
+ for (const record of records) {
189
+ if (seenCss.has(record.cssName)) {
190
+ throw new Error(
191
+ `Duplicate CSS variable ${record.cssName}: ${seenCss.get(record.cssName)} and ${record.path.join('.')}`,
192
+ )
193
+ }
194
+ seenCss.set(record.cssName, record.path.join('.'))
195
+ if (!/^--[a-zA-Z0-9_-]+$/.test(record.cssName)) {
196
+ throw new Error(`Invalid CSS variable ${record.cssName}`)
197
+ }
198
+ }
199
+ return { byPath, byCss: new Map(records.map((record) => [record.cssName, record])) }
200
+ }
201
+
202
+ function cssValue(record, byPath) {
203
+ if (record.alias) {
204
+ const target = byPath.get(record.alias)
205
+ if (!target) throw new Error(`Missing alias target ${record.alias}`)
206
+ return `var(${target.cssName})`
207
+ }
208
+ if (record.raw && typeof record.raw === 'object' && 'value' in record.raw && 'unit' in record.raw) {
209
+ return `${record.raw.value}${record.raw.unit}`
210
+ }
211
+ return String(record.raw)
212
+ }
213
+
214
+ /** The generated CSS file of `config` (see generatedCssPath). */
215
+ export const cssOutFile = (root, config) => config.cssOutPath ?? generatedCssPath(root, config.cssOut)
216
+
217
+ export function scanFiles(root, config) {
218
+ const roots = config.scanDirs.map((dir) => resolve(root, dir))
219
+ const ignoredFiles = new Set([
220
+ cssOutFile(root, config),
221
+ resolve(root, config.tsOut),
222
+ resolve(root, config.manifestOut),
223
+ ])
224
+ const files = []
225
+ const visit = (dir) => {
226
+ if (!existsSync(dir)) return
227
+ for (const entry of readdirSync(dir)) {
228
+ if (
229
+ entry === 'node_modules' ||
230
+ entry === 'dist' ||
231
+ entry === '.git' ||
232
+ entry === '.seji' ||
233
+ entry === 'tokens.generated.css' ||
234
+ entry === 'tokens.generated.ts'
235
+ ) {
236
+ continue
237
+ }
238
+ const file = join(dir, entry)
239
+ if (ignoredFiles.has(file)) continue
240
+ const stat = statSync(file)
241
+ if (stat.isDirectory()) {
242
+ visit(file)
243
+ } else if (
244
+ /\.(css|scss|sass|less|tsx|ts|jsx|js|mts|cts|mjs|cjs)$/i.test(entry) &&
245
+ !file.endsWith('tokens.manifest.json')
246
+ ) {
247
+ files.push(file)
248
+ }
249
+ }
250
+ }
251
+ roots.forEach(visit)
252
+ return files
253
+ }
254
+
255
+ function collectProposedTokenRefs(root) {
256
+ const designRoot = join(root, 'design')
257
+ const proposed = new Set()
258
+ if (!existsSync(designRoot)) return proposed
259
+ for (const entry of readdirSync(designRoot, { withFileTypes: true })) {
260
+ if (!entry.isDirectory()) continue
261
+ const reviewFile = join(designRoot, entry.name, 'review.json')
262
+ if (!existsSync(reviewFile)) continue
263
+ try {
264
+ const review = readJson(reviewFile)
265
+ for (const item of review?.items ?? []) {
266
+ if (
267
+ item?.kind === 'token' &&
268
+ item?.author === 'agent' &&
269
+ item?.status !== 'archived' &&
270
+ item?.proposalDecision !== 'rejected' &&
271
+ item?.target?.type === 'token' &&
272
+ typeof item.target.token === 'string' &&
273
+ item.target.token.startsWith('--')
274
+ ) {
275
+ proposed.add(item.target.token)
276
+ }
277
+ }
278
+ } catch {
279
+ // ignore malformed review ledgers during token scan
280
+ }
281
+ }
282
+ return proposed
283
+ }
284
+
285
+ async function scanUsage(root, records, config) {
286
+ const files = scanFiles(root, config)
287
+ const diagnostics = await analyzeFilesWithAdapters({
288
+ root,
289
+ files,
290
+ adapters: config.adapters,
291
+ })
292
+
293
+ const tokenNames = new Set(records.map((record) => record.cssName))
294
+ const usedIn = new Map(records.map((record) => [record.cssName, []]))
295
+ const defined = new Set(records.map((record) => record.cssName))
296
+ const localAliases = new Set(config.localAliases)
297
+ const proposedTokens = collectProposedTokenRefs(root)
298
+ const usedProposedTokens = new Map()
299
+ const unknown = new Set()
300
+
301
+ const hardcodedByFile = new Map()
302
+ const clusterMap = new Map()
303
+ const unsupportedMap = new Map()
304
+
305
+ for (const diag of diagnostics) {
306
+ if (diag.kind === 'token-ref' && diag.token) {
307
+ const name = diag.token
308
+ if (
309
+ name.startsWith('--tw-') ||
310
+ name.startsWith('--anchor-') ||
311
+ name.startsWith('--available-') ||
312
+ name.startsWith('--transform-')
313
+ ) {
314
+ continue
315
+ }
316
+ if (tokenNames.has(name)) {
317
+ usedIn.get(name).push(diag.file)
318
+ } else if (proposedTokens.has(name)) {
319
+ let filesForProposed = usedProposedTokens.get(name)
320
+ if (!filesForProposed) {
321
+ filesForProposed = new Set()
322
+ usedProposedTokens.set(name, filesForProposed)
323
+ }
324
+ filesForProposed.add(diag.file)
325
+ } else if (!localAliases.has(name) && !defined.has(name)) {
326
+ unknown.add(`${name} (${diag.file})`)
327
+ }
328
+ continue
329
+ }
330
+
331
+ if (diag.kind === 'literal') {
332
+ let fileMap = hardcodedByFile.get(diag.file)
333
+ if (!fileMap) {
334
+ fileMap = new Map()
335
+ hardcodedByFile.set(diag.file, fileMap)
336
+ }
337
+ fileMap.set(diag.value, (fileMap.get(diag.value) ?? 0) + 1)
338
+
339
+ let cluster = clusterMap.get(diag.value)
340
+ if (!cluster) {
341
+ cluster = { value: diag.value, count: 0, files: new Set(), adapters: new Set() }
342
+ clusterMap.set(diag.value, cluster)
343
+ }
344
+ cluster.count += 1
345
+ cluster.files.add(diag.file)
346
+ cluster.adapters.add(diag.adapter)
347
+ continue
348
+ }
349
+
350
+ if (diag.kind === 'unsupported') {
351
+ const reason = diag.reason ?? 'unsupported'
352
+ const key = `${diag.file}\0${diag.adapter}\0${reason}`
353
+ const existing = unsupportedMap.get(key)
354
+ if (existing) {
355
+ existing.count += 1
356
+ } else {
357
+ unsupportedMap.set(key, {
358
+ file: diag.file,
359
+ adapter: diag.adapter,
360
+ reason,
361
+ count: 1,
362
+ ...(typeof diag.line === 'number' ? { line: diag.line } : {}),
363
+ })
364
+ }
365
+ }
366
+ }
367
+
368
+ for (const [name, filesUsed] of usedIn) {
369
+ usedIn.set(name, [...new Set(filesUsed)].sort())
370
+ }
371
+
372
+ const hardcoded = [...hardcodedByFile.entries()]
373
+ .map(([file, valueCounts]) => {
374
+ const values = [...valueCounts.entries()]
375
+ .map(([value, count]) => ({ value, count }))
376
+ .sort((a, b) => b.count - a.count || a.value.localeCompare(b.value))
377
+ const count = values.reduce((sum, entry) => sum + entry.count, 0)
378
+ return { file, count, values }
379
+ })
380
+ .sort((a, b) => b.count - a.count || a.file.localeCompare(b.file))
381
+
382
+ const clusters = [...clusterMap.values()]
383
+ .map((cluster) => ({
384
+ value: cluster.value,
385
+ count: cluster.count,
386
+ files: [...cluster.files].sort(),
387
+ adapters: [...cluster.adapters].sort(),
388
+ }))
389
+ .sort((a, b) => b.count - a.count || a.value.localeCompare(b.value))
390
+
391
+ const unsupported = [...unsupportedMap.values()].sort(
392
+ (a, b) => b.count - a.count || a.file.localeCompare(b.file),
393
+ )
394
+
395
+ const proposedRefs = [...usedProposedTokens.entries()]
396
+ .map(([token, filesSet]) => ({ token, files: [...filesSet].sort() }))
397
+ .sort((a, b) => a.token.localeCompare(b.token))
398
+
399
+ return {
400
+ usedIn,
401
+ unknown: [...unknown].sort(),
402
+ hardcoded,
403
+ clusters,
404
+ unsupported,
405
+ proposedRefs,
406
+ diagnostics,
407
+ }
408
+ }
409
+
410
+ export function colorToRgb(value) {
411
+ if (typeof value !== 'string') return null
412
+ const hex = value.trim().match(/^#([0-9a-f]{3,8})$/i)
413
+ if (hex) {
414
+ const raw = hex[1]
415
+ if (raw.length === 3) {
416
+ return [0, 1, 2].map((i) => parseInt(raw[i] + raw[i], 16))
417
+ }
418
+ if (raw.length === 6 || raw.length === 8) {
419
+ return [0, 2, 4].map((i) => parseInt(raw.slice(i, i + 2), 16))
420
+ }
421
+ }
422
+ const rgb = value.trim().match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i)
423
+ if (rgb) return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])]
424
+ return null
425
+ }
426
+
427
+ function luminance(rgb) {
428
+ const channels = rgb.map((channel) => {
429
+ const value = channel / 255
430
+ return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4
431
+ })
432
+ return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2]
433
+ }
434
+
435
+ function contrast(fg, bg) {
436
+ const a = luminance(fg)
437
+ const b = luminance(bg)
438
+ return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
439
+ }
440
+
441
+ function checkContrast(byPath, contrastPairs) {
442
+ const results = []
443
+ for (const pair of contrastPairs) {
444
+ if (!Array.isArray(pair) || pair.length < 2) continue
445
+ const [fgPath, bgPath] = pair
446
+ const fgToken = byPath.get(fgPath)
447
+ const bgToken = byPath.get(bgPath)
448
+ if (!fgToken || !bgToken) continue
449
+ const fg = colorToRgb(fgToken.value)
450
+ const bg = colorToRgb(bgToken.value)
451
+ if (!fg || !bg) continue
452
+ const ratio = contrast(fg, bg)
453
+ results.push({ fg: fgPath, bg: bgPath, ratio: Math.round(ratio * 100) / 100, pass: ratio >= 4.5 })
454
+ }
455
+ return results
456
+ }
457
+
458
+ function resolveRuntimeImport(root) {
459
+ const pkgPath = resolve(root, 'package.json')
460
+ if (!existsSync(pkgPath)) return '@rien7/design-surface-runtime'
461
+ try {
462
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
463
+ const deps = {
464
+ ...(pkg.dependencies ?? {}),
465
+ ...(pkg.devDependencies ?? {}),
466
+ ...(pkg.peerDependencies ?? {}),
467
+ }
468
+ if (!('@rien7/design-surface-runtime' in deps) && '@rien7/seji' in deps) {
469
+ return '@rien7/seji/runtime'
470
+ }
471
+ } catch {
472
+ // ignore malformed package.json
473
+ }
474
+ return '@rien7/design-surface-runtime'
475
+ }
476
+
477
+ function buildOutputs(root, records, files, usage, config) {
478
+ const byPath = new Map(records.map((record) => [record.path.join('.'), record]))
479
+ const sourceHash = sha256(files.map((file) => readFileSync(file, 'utf8')).join('\n'))
480
+ const sorted = [...records].sort((a, b) => {
481
+ const tier = (TIER_ORDER[a.tier] ?? 99) - (TIER_ORDER[b.tier] ?? 99)
482
+ if (tier) return tier
483
+ if (a.group !== b.group) return a.group.localeCompare(b.group)
484
+ return a.path.join('.').localeCompare(b.path.join('.'))
485
+ })
486
+
487
+ const groups = new Map()
488
+ for (const record of sorted) {
489
+ const key = `${record.tier}:${record.group}`
490
+ if (!groups.has(key)) {
491
+ groups.set(key, {
492
+ id: key,
493
+ tier: record.tier,
494
+ tokens: [],
495
+ })
496
+ }
497
+ groups.get(key).tokens.push(record)
498
+ }
499
+ // Group labels come from the group metadata, captured on each token's walk.
500
+ // The group label is stable even when a token has its own label.
501
+ for (const record of records) {
502
+ const key = `${record.tier}:${record.group}`
503
+ const group = groups.get(key)
504
+ if (!group) continue
505
+ if (!group.label) {
506
+ group.label = record.groupLabel ?? record.group
507
+ group.labelZh = record.groupLabelZh
508
+ }
509
+ }
510
+
511
+ const cssBlock = config.cssFormat === 'root' ? ':root {' : '@theme {'
512
+ const tailwindExcludes =
513
+ config.cssFormat === 'theme'
514
+ ? [
515
+ `@source not "${toPosix(relative(dirname(cssOutFile(root, config)), resolve(root, 'design')))}/**/canvas.json";`,
516
+ `@source not "${toPosix(relative(dirname(cssOutFile(root, config)), resolve(root, 'design')))}/**/review.json";`,
517
+ `@source not "${toPosix(relative(dirname(cssOutFile(root, config)), resolve(root, 'design')))}/.seji/**";`,
518
+ '',
519
+ ]
520
+ : []
521
+ const css = [
522
+ `/* Generated from ${config.tokenDir}/*.tokens.json. Do not edit by hand. */`,
523
+ `/* sourceHash: ${sourceHash} */`,
524
+ ...tailwindExcludes,
525
+ cssBlock,
526
+ ...sorted.map((record) => ` ${record.cssName}: ${cssValue(record, byPath)};`),
527
+ '}',
528
+ '',
529
+ ].join('\n')
530
+
531
+ const aliasedBy = new Map(records.map((record) => [record.path.join('.'), []]))
532
+ for (const record of records) {
533
+ if (record.alias) aliasedBy.get(record.alias)?.push(record.path.join('.'))
534
+ }
535
+
536
+ const tokenDefs = sorted.map((record) => ({
537
+ name: record.cssName,
538
+ path: record.path.join('.'),
539
+ label: record.label,
540
+ ...(record.labelZh ? { labelZh: record.labelZh } : {}),
541
+ type: record.type,
542
+ ...(record.description ? { description: record.description } : {}),
543
+ ...(record.deprecated !== undefined ? { deprecated: record.deprecated } : {}),
544
+ ...(record.min !== undefined ? { min: record.min } : {}),
545
+ ...(record.max !== undefined ? { max: record.max } : {}),
546
+ ...(record.step !== undefined ? { step: record.step } : {}),
547
+ tier: record.tier,
548
+ ...(record.alias ? { alias: record.alias } : {}),
549
+ source: record.source,
550
+ value: record.value,
551
+ ...(usage.usedIn.get(record.cssName)?.length ? { usedIn: usage.usedIn.get(record.cssName) } : {}),
552
+ ...(aliasedBy.get(record.path.join('.'))?.length
553
+ ? { aliasedBy: [...new Set(aliasedBy.get(record.path.join('.')))].sort() }
554
+ : {}),
555
+ }))
556
+
557
+ const groupList = [...groups.values()].map((group) => ({
558
+ id: group.id,
559
+ label: group.label ?? group.id,
560
+ ...(group.labelZh ? { labelZh: group.labelZh } : {}),
561
+ tier: group.tier,
562
+ tokens: group.tokens.map((record) => tokenDefs.find((token) => token.name === record.cssName)),
563
+ }))
564
+
565
+ const values = Object.fromEntries(sorted.map((record) => [record.cssName, record.value]))
566
+ const sources = Object.fromEntries(sorted.map((record) => [record.cssName, record.source]))
567
+ const aliases = Object.fromEntries(
568
+ sorted.filter((record) => record.alias).map((record) => [record.cssName, record.alias]),
569
+ )
570
+
571
+ const byPathAll = new Map(records.map((record) => [record.path.join('.'), record]))
572
+ const duplicateGroups = new Map()
573
+ for (const record of records) {
574
+ if (record.alias) continue
575
+ const key = `${record.group}:${record.value}`
576
+ const list = duplicateGroups.get(key) ?? []
577
+ list.push(record)
578
+ duplicateGroups.set(key, list)
579
+ }
580
+ const duplicates = [...duplicateGroups.values()]
581
+ .filter((list) => list.length > 1)
582
+ .map((list) => ({
583
+ group: list[0].group,
584
+ value: list[0].value,
585
+ tokens: list.map((record) => record.path.join('.')),
586
+ }))
587
+ const orphans = sorted
588
+ .filter(
589
+ (record) =>
590
+ !(usage.usedIn.get(record.cssName)?.length) &&
591
+ !(aliasedBy.get(record.path.join('.'))?.length),
592
+ )
593
+ .map((record) => record.path.join('.'))
594
+ const semanticLiterals = sorted
595
+ .filter((record) => record.tier === 'semantic' && !record.alias)
596
+ .map((record) => record.path.join('.'))
597
+ const componentPrimitive = sorted
598
+ .filter(
599
+ (record) =>
600
+ record.tier === 'component' &&
601
+ record.alias &&
602
+ byPathAll.get(record.alias)?.tier === 'primitive',
603
+ )
604
+ .map((record) => ({ token: record.path.join('.'), alias: record.alias }))
605
+ const health = {
606
+ duplicates,
607
+ orphans,
608
+ semanticLiterals,
609
+ componentPrimitive,
610
+ hardcoded: usage.hardcoded,
611
+ clusters: usage.clusters,
612
+ unsupported: usage.unsupported,
613
+ }
614
+
615
+ const runtimeImport = resolveRuntimeImport(root)
616
+
617
+ const ts = [
618
+ `// Generated from ${config.tokenDir}/*.tokens.json. Do not edit by hand.`,
619
+ `// sourceHash: ${sourceHash}`,
620
+ `import type { TokenGroup } from '${runtimeImport}'`,
621
+ '',
622
+ `export const tokenSourceHash = ${JSON.stringify(sourceHash)}`,
623
+ `export const tokenGroups: TokenGroup[] = ${JSON.stringify(groupList, null, 2)}`,
624
+ '',
625
+ `export const tokenValues: Record<string, string> = ${JSON.stringify(values, null, 2)}`,
626
+ '',
627
+ `export const tokenSources: Record<string, string> = ${JSON.stringify(sources, null, 2)}`,
628
+ '',
629
+ `export const tokenAliases: Record<string, string> = ${JSON.stringify(aliases, null, 2)}`,
630
+ '',
631
+ `export const tokenHealth = ${JSON.stringify(health, null, 2)}`,
632
+ '',
633
+ ].join('\n')
634
+
635
+ const manifest = {
636
+ version: 1,
637
+ sourceHash,
638
+ generatedAt: 'generated',
639
+ counts: {
640
+ total: sorted.length,
641
+ byTier: Object.fromEntries(
642
+ TIERS.map((tier) => [tier, sorted.filter((record) => record.tier === tier).length]),
643
+ ),
644
+ },
645
+ tokens: sorted.map((record) => ({
646
+ path: record.path.join('.'),
647
+ cssName: record.cssName,
648
+ type: record.dtcgType,
649
+ tier: record.tier,
650
+ group: record.group,
651
+ value: record.value,
652
+ alias: record.alias,
653
+ source: record.source,
654
+ description: record.description,
655
+ ...(record.deprecated !== undefined ? { deprecated: record.deprecated } : {}),
656
+ usedIn: usage.usedIn.get(record.cssName) ?? [],
657
+ aliasedBy: [...new Set(aliasedBy.get(record.path.join('.')) ?? [])].sort(),
658
+ })),
659
+ contrast: checkContrast(byPath, config.contrastPairs),
660
+ unknownVars: usage.unknown,
661
+ hardcoded: usage.hardcoded,
662
+ clusters: usage.clusters,
663
+ unsupported: usage.unsupported,
664
+ health,
665
+ }
666
+ // The same values the generated TS module exports (virtual:design/tokens), as plain data
667
+ // for GET /__seji/api/tokens.
668
+ const data = {
669
+ tokenSourceHash: sourceHash,
670
+ tokenGroups: groupList,
671
+ tokenValues: values,
672
+ tokenSources: sources,
673
+ tokenAliases: aliases,
674
+ tokenHealth: health,
675
+ }
676
+ return { css, ts, manifest, sorted, groupList, health, data }
677
+ }
678
+
679
+ function validate(records, usage, outputs) {
680
+ const errors = []
681
+ const warnings = []
682
+ for (const record of records) {
683
+ if (
684
+ record.dtcgType === 'dimension' &&
685
+ !record.alias &&
686
+ !/^-?\d+(\.\d+)?(px|rem|em|%)$/.test(record.value)
687
+ ) {
688
+ errors.push(`${record.path.join('.')} is not a valid dimension: ${record.value}`)
689
+ }
690
+ if (
691
+ record.dtcgType === 'color' &&
692
+ !record.alias &&
693
+ !colorToRgb(record.value) &&
694
+ !/^(color-mix|rgb|hsl|oklch|var\()/i.test(record.value)
695
+ ) {
696
+ errors.push(`${record.path.join('.')} is not a valid color: ${record.value}`)
697
+ }
698
+ }
699
+ for (const item of outputs.manifest.contrast) {
700
+ if (!item.pass) errors.push(`Contrast ${item.fg} on ${item.bg} is ${item.ratio}:1, needs 4.5:1`)
701
+ }
702
+ // Variables the code reads that are not tokens: reported (all of them, in the manifest's
703
+ // unknownVars and the build result), never fatal. `tokens extract` turns them into tokens.
704
+ if (usage.unknown.length) {
705
+ warnings.push(
706
+ `${usage.unknown.length} CSS variable(s) used but not defined as tokens (run seji tokens extract, or list them in localAliases): ${usage.unknown.join(', ')}`,
707
+ )
708
+ }
709
+ if (usage.proposedRefs?.length) {
710
+ warnings.push(
711
+ `${usage.proposedRefs.length} unrejected agent proposal token(s) referenced (${usage.proposedRefs.map((entry) => entry.token).join(', ')}); report-only until approved and built`,
712
+ )
713
+ }
714
+ if (usage.hardcoded.length) {
715
+ const total = usage.hardcoded.reduce((sum, item) => sum + item.count, 0)
716
+ warnings.push(
717
+ `${total} hardcoded color literal(s) in ${usage.hardcoded.length} file(s); report-only for now`,
718
+ )
719
+ }
720
+ if (usage.unsupported.length) {
721
+ const total = usage.unsupported.reduce((sum, item) => sum + item.count, 0)
722
+ warnings.push(
723
+ `${total} unsupported style expression(s) across ${usage.unsupported.length} entry/entries; report-only`,
724
+ )
725
+ }
726
+ return { errors, warnings }
727
+ }
728
+
729
+ // Files in the tool cache (design/.seji/) are never committed, so `check` regenerates
730
+ // them instead of calling them stale; only the app-owned CSS output is held to `check`.
731
+ const inToolCache = (root, file) => {
732
+ const rel = toPosix(relative(resolve(root, 'design', '.seji'), file))
733
+ return rel !== '' && !rel.startsWith('..') && !rel.startsWith('/')
734
+ }
735
+
736
+ function compareOrWrite(root, file, content, check) {
737
+ const existing = existsSync(file) ? readFileSync(file, 'utf8') : ''
738
+ if (existing === content) return
739
+ if (check && !inToolCache(root, file)) {
740
+ if (existing !== content) {
741
+ throw new Error(`${toPosix(relative(root, file))} is stale. Run tokens build.`)
742
+ }
743
+ return
744
+ }
745
+ mkdirSync(dirname(file), { recursive: true })
746
+ writeFileSync(file, content)
747
+ }
748
+
749
+ /** Generated files (css / ts / manifest) that differ from what a build would write now. */
750
+ export function staleOutputs(root, config, outputs) {
751
+ const expected = [
752
+ [config.cssOut, outputs.css, cssOutFile(root, config)],
753
+ [config.tsOut, outputs.ts],
754
+ [config.manifestOut, `${JSON.stringify(outputs.manifest, null, 2)}\n`],
755
+ ]
756
+ return expected
757
+ .filter(([file, content, path]) => {
758
+ const abs = path ?? resolve(root, file)
759
+ return !existsSync(abs) || readFileSync(abs, 'utf8') !== content
760
+ })
761
+ .map(([file]) => file)
762
+ }
763
+
764
+ /**
765
+ * Read, resolve, scan, and validate tokens without writing anything. Shared by
766
+ * `tokens build|check`, `health`, and the usage index so headless commands see
767
+ * exactly what the build sees.
768
+ */
769
+ export async function analyzeTokens({ root = process.cwd(), config: overrides = {} } = {}) {
770
+ const config = loadTokenConfig(root, overrides)
771
+ const { files, records } = readTokenRecords(root, config.tokenDir)
772
+ resolveRecords(records)
773
+ const usage = await scanUsage(root, records, config)
774
+ const outputs = buildOutputs(root, records, files, usage, config)
775
+ const { errors, warnings } = validate(records, usage, outputs)
776
+ return { config, files, records, usage, outputs, errors, warnings }
777
+ }
778
+
779
+ export async function runTokenPipeline({ root = process.cwd(), check = false, config: overrides = {} } = {}) {
780
+ const { config, usage, outputs, errors, warnings } = await analyzeTokens({ root, config: overrides })
781
+
782
+ const validationError = () => {
783
+ const error = new Error(`Token validation failed (${errors.length}):\n${errors.map((e) => ` - ${e}`).join('\n')}`)
784
+ error.validationErrors = errors
785
+ error.warnings = warnings
786
+ error.counts = outputs.manifest.counts
787
+ return error
788
+ }
789
+ if (check && errors.length) throw validationError()
790
+
791
+ // A build always writes its outputs, so the editor and the app see the current tokens even
792
+ // while a validation problem (an invalid value, a failing contrast pair) is being fixed; the
793
+ // problem is still the command's error.
794
+ compareOrWrite(root, cssOutFile(root, config), outputs.css, check)
795
+ compareOrWrite(root, resolve(root, config.tsOut), outputs.ts, check)
796
+ compareOrWrite(
797
+ root,
798
+ resolve(root, config.manifestOut),
799
+ `${JSON.stringify(outputs.manifest, null, 2)}\n`,
800
+ check,
801
+ )
802
+ if (errors.length) throw validationError()
803
+
804
+ return {
805
+ check,
806
+ config,
807
+ counts: outputs.manifest.counts,
808
+ contrast: outputs.manifest.contrast,
809
+ unsupported: usage.unsupported,
810
+ unknown: usage.unknown,
811
+ warnings,
812
+ }
813
+ }