@rien7/seji 0.0.0-stage → 0.6.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 (413) hide show
  1. package/bin/design-surface.mjs +6 -0
  2. package/bin/postinstall.mjs +19 -0
  3. package/bin/seji.mjs +573 -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 +335 -0
  16. package/dist/cli/doctor.mjs +306 -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 +357 -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 +2832 -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/oklab.d.mts +6 -0
  309. package/dist/shared/oklab.mjs +56 -0
  310. package/dist/shared/optimizeEntries.d.mts +5 -0
  311. package/dist/shared/optimizeEntries.mjs +24 -0
  312. package/dist/shared/packages.d.mts +11 -0
  313. package/dist/shared/packages.mjs +96 -0
  314. package/dist/shared/projectFiles.d.mts +23 -0
  315. package/dist/shared/projectFiles.mjs +72 -0
  316. package/dist/shared/prompt.d.mts +20 -0
  317. package/dist/shared/prompt.mjs +201 -0
  318. package/dist/shared/proposals.d.mts +11 -0
  319. package/dist/shared/proposals.mjs +42 -0
  320. package/dist/shared/protocol.d.ts +122 -0
  321. package/dist/shared/protocol.d.ts.map +1 -0
  322. package/dist/shared/protocol.js +7 -0
  323. package/dist/shared/protocol.js.map +1 -0
  324. package/dist/shared/reviewArchive.d.mts +4 -0
  325. package/dist/shared/reviewArchive.mjs +19 -0
  326. package/dist/shared/reviewStore.d.mts +30 -0
  327. package/dist/shared/reviewStore.mjs +218 -0
  328. package/dist/shared/reviewVerify.d.mts +21 -0
  329. package/dist/shared/reviewVerify.mjs +158 -0
  330. package/dist/shared/sizeModes.d.mts +15 -0
  331. package/dist/shared/sizeModes.mjs +53 -0
  332. package/dist/shared/sketches.d.mts +10 -0
  333. package/dist/shared/sketches.mjs +64 -0
  334. package/dist/shared/snapshotCheck.d.mts +13 -0
  335. package/dist/shared/snapshotCheck.mjs +81 -0
  336. package/dist/shared/timeout.d.mts +1 -0
  337. package/dist/shared/timeout.mjs +15 -0
  338. package/dist/shared/tokens.d.ts +2 -0
  339. package/dist/shared/tokens.d.ts.map +1 -0
  340. package/dist/shared/tokens.js +2 -0
  341. package/dist/shared/tokens.js.map +1 -0
  342. package/dist/shared/types.d.ts +689 -0
  343. package/dist/shared/types.d.ts.map +1 -0
  344. package/dist/shared/types.js +13 -0
  345. package/dist/shared/types.js.map +1 -0
  346. package/dist/shared/wheelRouting.d.mts +9 -0
  347. package/dist/shared/wheelRouting.mjs +31 -0
  348. package/dist/shared/writeScope.mjs +96 -0
  349. package/dist/snapshots/diff.d.mts +28 -0
  350. package/dist/snapshots/diff.mjs +263 -0
  351. package/dist/snapshots/index.d.mts +110 -0
  352. package/dist/snapshots/index.mjs +638 -0
  353. package/dist/snapshots/render.d.mts +24 -0
  354. package/dist/snapshots/render.mjs +250 -0
  355. package/dist/snapshots/toolOps.d.mts +25 -0
  356. package/dist/snapshots/toolOps.mjs +69 -0
  357. package/dist/tokens/adapters/css.mjs +51 -0
  358. package/dist/tokens/adapters/cssInCode.mjs +314 -0
  359. package/dist/tokens/adapters/oxcShared.mjs +80 -0
  360. package/dist/tokens/adapters/preprocessor.mjs +63 -0
  361. package/dist/tokens/adapters/registry.mjs +53 -0
  362. package/dist/tokens/adapters/tailwindcss.mjs +424 -0
  363. package/dist/tokens/adapters/types.mjs +117 -0
  364. package/dist/tokens/consolidate/index.d.mts +42 -0
  365. package/dist/tokens/consolidate/index.mjs +111 -0
  366. package/dist/tokens/consolidate/normalize.mjs +479 -0
  367. package/dist/tokens/consolidate/plan.mjs +726 -0
  368. package/dist/tokens/consolidate/scan.mjs +928 -0
  369. package/dist/tokens/extract.mjs +441 -0
  370. package/dist/tokens/moduleData.d.mts +14 -0
  371. package/dist/tokens/moduleData.mjs +32 -0
  372. package/dist/tokens/opLock.d.mts +4 -0
  373. package/dist/tokens/opLock.mjs +108 -0
  374. package/dist/tokens/ops.d.mts +71 -0
  375. package/dist/tokens/ops.mjs +1511 -0
  376. package/dist/tokens/pipeline.mjs +813 -0
  377. package/dist/tokens/report.d.mts +47 -0
  378. package/dist/tokens/report.mjs +257 -0
  379. package/dist/tokens/rewrite/code.mjs +172 -0
  380. package/dist/tokens/rewrite/css.mjs +154 -0
  381. package/dist/tokens/rewrite/index.mjs +244 -0
  382. package/dist/tokens/rewrite/tailwind.mjs +288 -0
  383. package/dist/tokens/rewrite/text.mjs +116 -0
  384. package/dist/tokens/rewrite/value.mjs +115 -0
  385. package/dist/tokens/usage.d.mts +97 -0
  386. package/dist/tokens/usage.mjs +680 -0
  387. package/dist/vite/agent.d.ts +21 -0
  388. package/dist/vite/agent.d.ts.map +1 -0
  389. package/dist/vite/agent.js +165 -0
  390. package/dist/vite/agent.js.map +1 -0
  391. package/dist/vite/events.d.ts +27 -0
  392. package/dist/vite/events.d.ts.map +1 -0
  393. package/dist/vite/events.js +156 -0
  394. package/dist/vite/events.js.map +1 -0
  395. package/dist/vite/layout.d.ts +2 -0
  396. package/dist/vite/layout.d.ts.map +1 -0
  397. package/dist/vite/layout.js +4 -0
  398. package/dist/vite/layout.js.map +1 -0
  399. package/dist/vite/plugin.d.ts +40 -0
  400. package/dist/vite/plugin.d.ts.map +1 -0
  401. package/dist/vite/plugin.js +1255 -0
  402. package/dist/vite/plugin.js.map +1 -0
  403. package/dist/vite/requestGuard.d.mts +3 -0
  404. package/dist/vite/requestGuard.mjs +43 -0
  405. package/dist/vite/review.d.ts +11 -0
  406. package/dist/vite/review.d.ts.map +1 -0
  407. package/dist/vite/review.js +283 -0
  408. package/dist/vite/review.js.map +1 -0
  409. package/package.json +104 -4
  410. package/skills/seji/SKILL.md +395 -0
  411. package/skills/seji-authoring/SKILL.md +397 -0
  412. package/skills/seji-tokens/SKILL.md +432 -0
  413. package/README.md +0 -3
@@ -0,0 +1,335 @@
1
+ // `seji dev`: the app's own Vite (and Vite config) with the design plugin, inside the
2
+ // app package (found like setup: from a monorepo root it switches to the one app, `--app <dir>`
3
+ // picks one). Never installs anything. Before the server starts: the token build, the runtime
4
+ // types in design/.seji/, design/.gitignore. The server's output is also written to
5
+ // design/.seji/dev.log.
6
+ import dns from 'node:dns'
7
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
8
+ import { dirname, join, relative, resolve, sep } from 'node:path'
9
+ import process from 'node:process'
10
+ import { format } from 'node:util'
11
+
12
+ import { CACHE_PATHS, ensureCacheGitignore } from '../shared/projectFiles.mjs'
13
+ import { runTokenPipeline } from '../tokens/pipeline.mjs'
14
+ import { appProblemText, designLocation, looksLikeDesignDir, resolveApp } from './app.mjs'
15
+ import { DESIGN_PACKAGE, RUNTIME_PACKAGE, declaredRange } from './init.mjs'
16
+ import { importFromApp } from './appScan.mjs'
17
+ import { OLD_PACKAGE, findOldImports, formatCacheMigration, migrateCacheDir, oldDependency } from './legacyNames.mjs'
18
+ import { ensureDesignTypes } from './types.mjs'
19
+
20
+ const DEFAULT_CSS_CANDIDATES = ['src/index.css', 'src/main.css', 'src/App.css']
21
+ const DEFAULT_COMPONENT_GROUPS = [
22
+ {
23
+ id: 'components',
24
+ label: 'Components',
25
+ globs: ['src/components/**/*.tsx'],
26
+ },
27
+ ]
28
+
29
+ export function parseDevArgs(argv = []) {
30
+ let port
31
+ let host
32
+ let open = false
33
+ let configFile
34
+ let app
35
+
36
+ for (let i = 0; i < argv.length; i += 1) {
37
+ const token = argv[i]
38
+ if (token === '--open') {
39
+ open = true
40
+ continue
41
+ }
42
+ if (token === '--port') {
43
+ const next = argv[i + 1]
44
+ if (!next) throw new Error('--port requires a port number')
45
+ port = parsePort(next)
46
+ i += 1
47
+ continue
48
+ }
49
+ if (token.startsWith('--port=')) {
50
+ port = parsePort(token.slice('--port='.length))
51
+ continue
52
+ }
53
+ if (token === '--host') {
54
+ const next = argv[i + 1]
55
+ if (next && !next.startsWith('-')) {
56
+ host = next
57
+ i += 1
58
+ } else {
59
+ host = true
60
+ }
61
+ continue
62
+ }
63
+ if (token.startsWith('--host=')) {
64
+ const value = token.slice('--host='.length)
65
+ host = value ? value : true
66
+ continue
67
+ }
68
+ if (token === '--app') {
69
+ const next = argv[i + 1]
70
+ if (!next) throw new Error('--app requires the app directory')
71
+ app = next
72
+ i += 1
73
+ continue
74
+ }
75
+ if (token.startsWith('--app=')) {
76
+ app = token.slice('--app='.length)
77
+ continue
78
+ }
79
+ if (token === '--config') {
80
+ const next = argv[i + 1]
81
+ if (!next) throw new Error('--config requires a Vite config file path')
82
+ configFile = next
83
+ i += 1
84
+ continue
85
+ }
86
+ if (token.startsWith('--config=')) {
87
+ const value = token.slice('--config='.length)
88
+ if (!value) throw new Error('--config requires a Vite config file path')
89
+ configFile = value
90
+ continue
91
+ }
92
+ throw new Error(`unknown dev option: ${token}`)
93
+ }
94
+
95
+ return { port, host, open, configFile, app }
96
+ }
97
+
98
+ function parsePort(raw) {
99
+ const num = Number(raw)
100
+ if (!Number.isInteger(num) || num < 1 || num > 65535) {
101
+ throw new Error(`invalid --port "${raw}". Expected an integer between 1 and 65535.`)
102
+ }
103
+ return num
104
+ }
105
+
106
+ /** design/surface.config.json; `designDir` when the design directory is not `<root>/design`. */
107
+ export function loadSurfaceConfig(root, designDir = join(root, 'design')) {
108
+ const configPath = join(designDir, 'surface.config.json')
109
+ const dirOption = relative(root, designDir).split(sep).join('/') || 'design'
110
+ if (existsSync(configPath)) {
111
+ let parsed
112
+ try {
113
+ parsed = JSON.parse(readFileSync(configPath, 'utf8'))
114
+ } catch (error) {
115
+ const message = error instanceof Error ? error.message : String(error)
116
+ throw new Error(`failed to parse design/surface.config.json: ${message}`)
117
+ }
118
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
119
+ throw new Error('design/surface.config.json must contain a JSON object')
120
+ }
121
+ return dirOption === 'design' ? parsed : { ...parsed, dir: dirOption }
122
+ }
123
+
124
+ const detectedCss = DEFAULT_CSS_CANDIDATES.filter((rel) => existsSync(join(root, rel))).map(
125
+ (rel) => `/${rel}`,
126
+ )
127
+ if (!detectedCss.length && existsSync(join(root, 'src/tokens.generated.css'))) {
128
+ detectedCss.push('/src/tokens.generated.css')
129
+ }
130
+
131
+ return {
132
+ dir: dirOption,
133
+ css: detectedCss,
134
+ componentGroups: DEFAULT_COMPONENT_GROUPS,
135
+ }
136
+ }
137
+
138
+ /** The app's own Vite `createServer` (its node_modules), else the one next to this CLI. */
139
+ export async function resolveViteCreateServer(root) {
140
+ try {
141
+ const mod = await importFromApp(root, 'vite')
142
+ if (typeof mod?.createServer === 'function') return mod.createServer
143
+ } catch {
144
+ // fall back to the package's own vite below
145
+ }
146
+ try {
147
+ const mod = await import('vite')
148
+ if (typeof mod.createServer === 'function') return mod.createServer
149
+ } catch {
150
+ // handled by the error below
151
+ }
152
+ throw new Error(`vite is not installed in ${root}: run the app's package install, then retry.`)
153
+ }
154
+
155
+ export async function loadDesignPlugin() {
156
+ const distPluginUrl = new URL('../vite/plugin.js', import.meta.url)
157
+ if (existsSync(distPluginUrl)) {
158
+ const mod = await import(distPluginUrl.href)
159
+ return mod.designPlugin
160
+ }
161
+ const srcPluginUrl = new URL('../vite/plugin.ts', import.meta.url)
162
+ const mod = await import(srcPluginUrl.href)
163
+ return mod.designPlugin
164
+ }
165
+
166
+ /** One line per leftover runtime dependency (project or app package.json); resolution is unchanged. */
167
+ function warnOldDependency(cwd, root) {
168
+ const seen = new Set()
169
+ for (const dir of [...new Set([resolve(cwd), root])]) {
170
+ for (const name of [RUNTIME_PACKAGE, DESIGN_PACKAGE]) {
171
+ if (seen.has(name) || !declaredRange(dir, name)) continue
172
+ seen.add(name)
173
+ console.warn(`seji: the project's ${name} dependency is no longer needed; you can remove it (npm/pnpm remove ${name}).`)
174
+ }
175
+ if (!seen.has(OLD_PACKAGE) && oldDependency(dir).length) {
176
+ seen.add(OLD_PACKAGE)
177
+ console.warn(`seji: package.json still depends on ${OLD_PACKAGE} (renamed to ${DESIGN_PACKAGE}): run seji setup to switch it and its imports.`)
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Only for the server `seji dev` creates: no Vite full-screen error overlay (it would cover the
184
+ * editor and the agent panel; build errors show per frame and in the status bar instead). An app
185
+ * config that turns HMR off keeps it off; the plugin alone, inside the app's own Vite, never
186
+ * touches this.
187
+ */
188
+ export function devOverlayPlugin() {
189
+ return {
190
+ name: 'seji:dev-overlay',
191
+ config(config) {
192
+ if (config.server?.hmr === false) return undefined
193
+ return { server: { hmr: { overlay: false } } }
194
+ },
195
+ }
196
+ }
197
+
198
+ /** Tool-owned files the editor needs, regenerated before a server starts. */
199
+ export async function prepareDesignDir(root, { log = console.warn } = {}) {
200
+ if (!existsSync(join(root, 'design'))) return
201
+ try {
202
+ ensureCacheGitignore(root)
203
+ for (const item of await ensureDesignTypes(root)) if (item.status === 'failed') log(`seji: ${item.file}: ${item.detail}`)
204
+ } catch (error) {
205
+ log(`seji: runtime types not written: ${error instanceof Error ? error.message : String(error)}`)
206
+ }
207
+ if (existsSync(join(root, 'design', 'tokens'))) {
208
+ try {
209
+ await runTokenPipeline({ root, check: false })
210
+ } catch (error) {
211
+ const message = error instanceof Error ? error.message : String(error)
212
+ log(`seji: token build: ${message}`)
213
+ }
214
+ }
215
+ }
216
+
217
+ /** Copy console output to design/.seji/dev.log (fresh per start). */
218
+ function teeToLog(root) {
219
+ const file = join(root, CACHE_PATHS.devLog)
220
+ try {
221
+ mkdirSync(dirname(file), { recursive: true })
222
+ writeFileSync(file, `seji dev ${new Date().toISOString()}\n`)
223
+ } catch {
224
+ return
225
+ }
226
+ for (const method of ['log', 'info', 'warn', 'error']) {
227
+ const original = console[method].bind(console)
228
+ console[method] = (...args) => {
229
+ original(...args)
230
+ try {
231
+ appendFileSync(file, `${format(...args)}\n`)
232
+ } catch {
233
+ // the log is best effort
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ /** A design dir named plainly: `apps/web/design/`, `./design/ at the repo root`, never a bare "design". */
240
+ function designDirLabel(dir, { cwd, base }) {
241
+ const rel = relative(resolve(cwd), dir).split(sep).join('/')
242
+ const shown = !rel ? '.' : rel.startsWith('..') ? dir.split(sep).join('/') : rel.includes('/') ? rel : `./${rel}`
243
+ const parent = dirname(resolve(dir))
244
+ const where = base && parent === resolve(base) ? ' at the repo root' : parent === resolve(cwd) ? ' in the current directory' : ''
245
+ return `${shown}/${where}`
246
+ }
247
+
248
+ /** One line when the app's own design/ is used and another design dir is ignored. */
249
+ export function twoDesignDirsWarning({ cwd = process.cwd(), base, inUse, ignored }) {
250
+ return `seji: found two design directories: ${designDirLabel(inUse, { cwd, base })} (in use) and ${designDirLabel(ignored, { cwd, base })} (ignored). Remove one of them.`
251
+ }
252
+
253
+ export async function startDevServer({ root: cwd = process.cwd(), argv = [] } = {}) {
254
+ const { port, host, open, configFile, app } = parseDevArgs(argv)
255
+ const found = await resolveApp({ cwd, app })
256
+ if (found.status !== 'ok') throw new Error(appProblemText(found, 'dev'))
257
+ const root = found.root
258
+ if (found.root !== resolve(cwd)) console.log(`APP ${found.rel}`)
259
+ const design = designLocation(found, cwd)
260
+ if (design.external) console.log(`DESIGN ${design.rel}`)
261
+ else {
262
+ // The app's own design/ wins; say so when another one sits at the cwd or the workspace root.
263
+ for (const dir of new Set([resolve(cwd), found.base && resolve(found.base)].filter(Boolean))) {
264
+ if (dir !== root && looksLikeDesignDir(join(dir, 'design'))) {
265
+ console.warn(twoDesignDirsWarning({ cwd, base: found.base, inUse: join(root, 'design'), ignored: join(dir, 'design') }))
266
+ }
267
+ }
268
+ }
269
+ // 0.5.x: design/.design-surface/ → design/.seji/, before the log creates the new dir.
270
+ for (const line of formatCacheMigration(migrateCacheDir(design.home))) console.warn(line)
271
+ // Design data (cache, log, tokens) lives next to the design dir; nothing is created in the app.
272
+ teeToLog(design.home)
273
+ warnOldDependency(cwd, root)
274
+ const surfaceConfig = loadSurfaceConfig(root, design.designDir)
275
+ await prepareDesignDir(design.home)
276
+
277
+ const createServer = await resolveViteCreateServer(root)
278
+ const designPlugin = await loadDesignPlugin()
279
+
280
+ if (host === undefined && typeof dns.setDefaultResultOrder === 'function') {
281
+ dns.setDefaultResultOrder('ipv4first')
282
+ }
283
+
284
+ const serverConfig = {}
285
+ if (port !== undefined) serverConfig.port = port
286
+ if (host !== undefined) serverConfig.host = host
287
+ if (open) serverConfig.open = '/__seji'
288
+
289
+ let server
290
+ try {
291
+ server = await createServer({
292
+ root,
293
+ ...(configFile ? { configFile: resolve(cwd, configFile) } : {}),
294
+ plugins: [designPlugin(surfaceConfig), devOverlayPlugin()],
295
+ ...(Object.keys(serverConfig).length ? { server: serverConfig } : {}),
296
+ })
297
+ } catch (error) {
298
+ // A vite.config still importing the old package name (often already uninstalled).
299
+ if (findOldImports([root]).length) {
300
+ const message = error instanceof Error ? error.message : String(error)
301
+ throw new Error(`${message}\nThis project still imports ${OLD_PACKAGE}: run seji setup`)
302
+ }
303
+ throw error
304
+ }
305
+
306
+ await server.listen()
307
+
308
+ const localUrl = server.resolvedUrls?.local?.[0]
309
+ const networkUrl = server.resolvedUrls?.network?.[0]
310
+ const activePort = server.config.server.port ?? port ?? 5173
311
+ const baseUrl = localUrl ?? networkUrl ?? `http://localhost:${activePort}/`
312
+ const designUrl = `${baseUrl.replace(/\/$/, '')}/__seji`
313
+
314
+ console.log(`\n seji ready: ${designUrl}`)
315
+ if (localUrl) console.log(` App preview: ${localUrl}`)
316
+ if (networkUrl && networkUrl !== localUrl) {
317
+ console.log(` Network: ${networkUrl.replace(/\/$/, '')}/__seji`)
318
+ }
319
+ console.log('')
320
+
321
+ let closing = false
322
+ const shutdown = async () => {
323
+ if (closing) return
324
+ closing = true
325
+ try {
326
+ await server.close()
327
+ } finally {
328
+ process.exit(0)
329
+ }
330
+ }
331
+ process.once('SIGINT', shutdown)
332
+ process.once('SIGTERM', shutdown)
333
+
334
+ return { server, designUrl }
335
+ }
@@ -0,0 +1,306 @@
1
+ // `seji doctor [--deep]`: is this machine and app ready for an agent? The global CLI
2
+ // (latest release; the updater's cached answer, at most one registry request, none with
3
+ // SEJI_NO_UPDATE=1), the global skills, then the app: found (monorepos: the one Vite +
4
+ // React package), its vite / react / React plugin resolvable from it, design/ set up, every
5
+ // configured path present, tokens building (every unknown variable listed), the generated CSS
6
+ // imported by the CSS entry, runtime types, providers, the tool cache ignored by git and not
7
+ // tracked, no 0.4.2 leftovers. `--deep` (setup runs it) starts the app's Vite in middleware mode
8
+ // and transforms every design module, which resolves their real component imports.
9
+ // Each problem comes with its fix; `ok` is false (exit 1) when any check fails.
10
+ // Doctor writes only tool-owned files (the runtime type copy in design/.seji/).
11
+ import { spawnSync } from 'node:child_process'
12
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
13
+ import { homedir } from 'node:os'
14
+ import { dirname, join, relative, resolve } from 'node:path'
15
+
16
+ import { toolEnv } from '../shared/env.mjs'
17
+ import { findPackageDir } from '../shared/packages.mjs'
18
+ import { CACHE_DIR, CACHE_PATHS, LEGACY_PATHS, isCacheIgnored } from '../shared/projectFiles.mjs'
19
+ import { withTimeout } from '../shared/timeout.mjs'
20
+ import { analyzeTokens, staleOutputs } from '../tokens/pipeline.mjs'
21
+ import { appPackages, appProblemText, appTraits, designLocation, generatedCssPath, resolveApp } from './app.mjs'
22
+ import { appStyles, loadAppViteConfig } from './appScan.mjs'
23
+ import { hasTokenImport, importSpecifier } from './cssImport.mjs'
24
+ import { CLI, DESIGN_PACKAGE, PACKAGE_VERSION, RUNTIME_PACKAGE, compareVersions, declaredRange } from './init.mjs'
25
+ import { LEGACY_CACHE_DIR, OLD_PACKAGE, oldNameState } from './legacyNames.mjs'
26
+ import { legacyLayout } from './migrate.mjs'
27
+ import { SKILLS_FIX, globalSkillStatus, projectSkillDirs } from './skills.mjs'
28
+ import { designTypesState, ensureDesignTypes } from './types.mjs'
29
+ import { GLOBAL_INSTALL_TEXT, NO_UPDATE_ENV, cacheDir, detectInstall, latestVersion, reinstallWithNpmText } from './updater.mjs'
30
+
31
+ const SETUP = `${CLI} setup`
32
+ const check = (id, status, detail, fix) => ({ id, status, detail, ...(fix ? { fix } : {}) })
33
+
34
+ /** `cli`: the global install is the latest release. `latest` / `install` are injectable. */
35
+ async function cliCheck({ latest, install, env, home }) {
36
+ const where = install ?? detectInstall()
37
+ const disabled = toolEnv('NO_UPDATE', env) === '1'
38
+ let known = latest
39
+ if (known === undefined) {
40
+ const cacheFile = join(cacheDir({ env, home }), 'update-check.json')
41
+ // With updates off: the cached answer only, no request.
42
+ known = (await latestVersion({ cacheFile, ...(disabled ? { fetchLatest: async () => { throw new Error('updates off') }, failedTtlMs: 0 } : {}) })).latest
43
+ }
44
+ const off = disabled ? ` (auto-update off: ${NO_UPDATE_ENV}=1)` : ''
45
+ if (!known) return check('cli', 'warn', `seji ${PACKAGE_VERSION}; latest release unknown${disabled ? off : ' (the npm registry could not be reached)'}`)
46
+ if (compareVersions(known, PACKAGE_VERSION) > 0) {
47
+ return check('cli', 'fail', `seji ${PACKAGE_VERSION}, latest is ${known}${off}`, where.pm === 'npm' ? `npm install -g ${DESIGN_PACKAGE}@latest` : reinstallWithNpmText(where.pm).replace(/^seji: [^:]+: /, ''))
48
+ }
49
+ if (!where.global) {
50
+ return check('cli', 'warn', `seji ${PACKAGE_VERSION} (latest) runs from a ${where.kind} copy, not a global install: it does not update itself`, GLOBAL_INSTALL_TEXT)
51
+ }
52
+ if (where.pm !== 'npm') return check('cli', 'warn', `seji ${PACKAGE_VERSION} (latest), installed globally with ${where.pm}: updates need npm's global install`, reinstallWithNpmText(where.pm).replace(/^seji: [^:]+: /, ''))
53
+ return check('cli', 'ok', `seji ${PACKAGE_VERSION} (latest), npm global install${off}`)
54
+ }
55
+
56
+ function skillsCheck({ home, env, skillDirs }) {
57
+ const targets = globalSkillStatus({ home, env, dirs: skillDirs })
58
+ const problems = []
59
+ for (const target of targets) {
60
+ for (const [skill, state] of Object.entries(target.skills)) if (state !== 'current') problems.push(`${target.dir}/${skill} ${state}`)
61
+ for (const skill of target.legacy ?? []) problems.push(`${target.dir}/${skill} (0.5.x name, replaced by seji skills)`)
62
+ }
63
+ const dirs = targets.map((target) => target.dir).join(', ')
64
+ return problems.length
65
+ ? check('skills', 'fail', `${problems.join(', ')} (CLI ${PACKAGE_VERSION})`, SKILLS_FIX)
66
+ : check('skills', 'ok', `global skills match ${PACKAGE_VERSION} in ${dirs}`)
67
+ }
68
+
69
+ /** 0.5.x naming left in the project (design-surface → seji): one check, `seji setup` fixes all of it. */
70
+ function oldNameCheck({ home, appRoot, fix }) {
71
+ const state = oldNameState({ home, appRoot })
72
+ const found = []
73
+ if (state.imports.length) found.push(`${OLD_PACKAGE} imported in ${state.imports.slice(0, 5).map((entry) => entry.file).join(', ')}${state.imports.length > 5 ? ', …' : ''}`)
74
+ if (state.dependency.length) found.push(`${OLD_PACKAGE} ${state.dependency[0].range} in package.json ${state.dependency[0].section}`)
75
+ if (state.cache) found.push(`tool cache still at ${LEGACY_CACHE_DIR}/`)
76
+ if (!found.length) return null
77
+ return check('old-name', state.imports.length ? 'fail' : 'warn', `design-surface was renamed to ${DESIGN_PACKAGE}: ${found.join('; ')}`, fix)
78
+ }
79
+
80
+ const readJson = (file) => {
81
+ try {
82
+ return JSON.parse(readFileSync(file, 'utf8'))
83
+ } catch {
84
+ return null
85
+ }
86
+ }
87
+
88
+ /** Static directory prefix of a glob. */
89
+ const globBase = (pattern) => {
90
+ const parts = []
91
+ for (const part of pattern.split('/')) {
92
+ if (/[*?{}[\]()!]/.test(part)) break
93
+ parts.push(part)
94
+ }
95
+ return parts.join('/') || '.'
96
+ }
97
+
98
+ function pathsCheck(root) {
99
+ const missing = []
100
+ const surface = readJson(join(root, 'design/surface.config.json'))
101
+ for (const css of surface?.css ?? []) if (!existsSync(join(root, String(css).replace(/^\//, '')))) missing.push(`surface.config.json css ${css}`)
102
+ for (const group of surface?.componentGroups ?? []) {
103
+ for (const pattern of group.globs ?? []) {
104
+ if (String(pattern).startsWith('!')) continue
105
+ if (!existsSync(join(root, globBase(String(pattern))))) missing.push(`surface.config.json glob ${pattern}`)
106
+ }
107
+ }
108
+ const tokens = readJson(join(root, 'design/tokens.config.json'))
109
+ if (tokens?.cssOut && !existsSync(dirname(generatedCssPath(root, tokens.cssOut)))) missing.push(`tokens.config.json cssOut ${tokens.cssOut} (its directory)`)
110
+ for (const dir of tokens?.scanDirs ?? []) if (!existsSync(join(root, dir))) missing.push(`tokens.config.json scanDirs ${dir}`)
111
+ if (tokens?.tokenDir && !existsSync(join(root, tokens.tokenDir))) missing.push(`tokens.config.json tokenDir ${tokens.tokenDir}`)
112
+ return missing.length
113
+ ? check('paths', 'fail', `configured paths that do not exist: ${missing.join('; ')}`, `fix them in design/*.config.json, or delete the file and run ${SETUP}`)
114
+ : check('paths', 'ok', 'every path in surface.config.json and tokens.config.json exists')
115
+ }
116
+
117
+ async function tokensChecks(root, cssFiles) {
118
+ const out = []
119
+ try {
120
+ const analysis = await analyzeTokens({ root })
121
+ if (analysis.errors.length) {
122
+ out.push(check('tokens', 'fail', `token validation (${analysis.errors.length}): ${analysis.errors.join('; ')}`, `fix design/tokens/*.tokens.json, then ${CLI} tokens build`))
123
+ } else {
124
+ const stale = staleOutputs(root, analysis.config, analysis.outputs)
125
+ const appOwned = stale.filter((file) => !file.startsWith(`${CACHE_DIR}/`))
126
+ out.push(
127
+ appOwned.length
128
+ ? check('tokens', 'fail', `generated token files are stale: ${appOwned.join(', ')}`, `${CLI} tokens build`)
129
+ : check('tokens', 'ok', `${analysis.records.length} tokens, ${analysis.config.cssOut} fresh${stale.length ? ' (tool cache regenerated by dev)' : ''}`),
130
+ )
131
+ }
132
+ const unknown = analysis.usage.unknown ?? []
133
+ if (unknown.length) {
134
+ out.push(check('unknown-vars', 'warn', `${unknown.length} CSS variable(s) used but not tokens: ${unknown.join(', ')}`, `${CLI} tokens extract ${cssFiles.length ? cssFiles.join(' ') : '<css files>'} (or list them in localAliases)`))
135
+ }
136
+ return { checks: out, config: analysis.config }
137
+ } catch (error) {
138
+ out.push(check('tokens', 'fail', error instanceof Error ? error.message.split('\n')[0] : String(error), `${CLI} tokens build`))
139
+ return { checks: out, config: readJson(join(root, 'design/tokens.config.json')) }
140
+ }
141
+ }
142
+
143
+ function gitChecks(root) {
144
+ const out = []
145
+ if (!isCacheIgnored(root)) out.push(check('git-ignore', 'warn', `design/.gitignore does not list ${CACHE_PATHS.types.split('/')[1]}/ (the tool cache)`, SETUP))
146
+ const result = spawnSync('git', ['ls-files', '--', CACHE_DIR, LEGACY_PATHS.tokensTs, LEGACY_PATHS.manifest, LEGACY_PATHS.consolidate], { cwd: root, encoding: 'utf8' })
147
+ if (result.status === 0) {
148
+ const tracked = String(result.stdout).split('\n').filter(Boolean)
149
+ if (tracked.length) {
150
+ out.push(check('git-tracked', 'warn', `tool-owned files are committed (${tracked.length}): ${tracked.slice(0, 5).join(', ')}${tracked.length > 5 ? ', …' : ''}`, `git rm -r --cached --quiet ${[...new Set(tracked.map((file) => (file.startsWith(`${CACHE_DIR}/`) ? CACHE_DIR : file)))].join(' ')}`))
151
+ }
152
+ }
153
+ return out
154
+ }
155
+
156
+ const CLOSE_TIMEOUT_MS = 5000
157
+
158
+ /** Start the app's Vite in middleware mode and transform every design module. */
159
+ export async function deepCheck(root, { timeoutMs = 90_000, designDir = join(root, 'design') } = {}) {
160
+ const { resolveViteCreateServer, loadDesignPlugin, loadSurfaceConfig } = await import('./dev.mjs')
161
+ // A design dir outside the app is served through /@fs/.
162
+ const urlOf = (file) => (file.startsWith(`${root}/`) ? file.slice(root.length) : `/@fs/${file.replace(/^\/+/, '')}`)
163
+ const modules = []
164
+ for (const entry of existsSync(designDir) ? readdirSync(designDir, { withFileTypes: true }) : []) {
165
+ if (entry.isDirectory() && !entry.name.startsWith('.') && existsSync(join(designDir, entry.name, 'design.tsx'))) modules.push(urlOf(join(designDir, entry.name, 'design.tsx')))
166
+ }
167
+ for (const name of ['providers.tsx', 'tokens.ts', 'components.ts']) if (existsSync(join(designDir, name))) modules.push(urlOf(join(designDir, name)))
168
+ let server = null
169
+ let timer
170
+ const run = async () => {
171
+ const createServer = await resolveViteCreateServer(root)
172
+ const designPlugin = await loadDesignPlugin()
173
+ server = await createServer({
174
+ root,
175
+ logLevel: 'silent',
176
+ clearScreen: false,
177
+ appType: 'custom',
178
+ server: { middlewareMode: true, hmr: false, ws: false, watch: null },
179
+ plugins: [designPlugin({ ...loadSurfaceConfig(root, designDir), snapshots: { autoBaseline: false } })],
180
+ })
181
+ const failed = []
182
+ for (const id of modules) {
183
+ try {
184
+ const result = await server.transformRequest(id)
185
+ if (!result) failed.push(`${id}: not served`)
186
+ } catch (error) {
187
+ failed.push(`${id}: ${error instanceof Error ? error.message.split('\n')[0] : String(error)}`)
188
+ }
189
+ }
190
+ return failed
191
+ }
192
+ try {
193
+ const failed = await Promise.race([
194
+ run(),
195
+ new Promise((_, reject) => {
196
+ timer = setTimeout(() => reject(new Error(`no answer within ${timeoutMs / 1000}s`)), timeoutMs)
197
+ }),
198
+ ])
199
+ return failed.length
200
+ ? check('deep', 'fail', `Vite could not serve: ${failed.join('; ')}`, 'fix the import / file named above, then doctor --deep again')
201
+ : check('deep', 'ok', `the app's Vite serves ${modules.length} design module(s) and resolves their imports`)
202
+ } catch (error) {
203
+ return check('deep', 'fail', `Vite did not start: ${error instanceof Error ? error.message.split('\n')[0] : String(error)}`, 'fix the app\'s vite config / install, then doctor --deep again')
204
+ } finally {
205
+ clearTimeout(timer)
206
+ // Bounded: Vite's close can stay pending with no handle left, and an emptied event loop
207
+ // would end the process mid-await (exit 13). The ref'd timer keeps it alive until the bound.
208
+ if (server?.close) await withTimeout(server.close().catch(() => {}), CLOSE_TIMEOUT_MS, { unref: false })
209
+ }
210
+ }
211
+
212
+ export async function runDoctor({ root: cwd = process.cwd(), app, designDir: forcedDesignDir, home = homedir(), env = process.env, latest, install, skillDirs, deep = false } = {}) {
213
+ const checks = []
214
+ checks.push(await cliCheck({ latest, install, env, home }))
215
+ checks.push(skillsCheck({ home, env, skillDirs }))
216
+ const found = await resolveApp({ cwd, app })
217
+ if (found.status !== 'ok') {
218
+ checks.push(check('app', 'fail', appProblemText(found, 'doctor').replace(/\n/g, '\n '), found.status === 'multiple' ? `${SETUP} --app <path>` : undefined))
219
+ return { ok: false, version: PACKAGE_VERSION, checks }
220
+ }
221
+ const appRoot = found.root
222
+ const design = designLocation(forcedDesignDir ? { ...found, designDir: forcedDesignDir } : found, cwd)
223
+ // Design checks run against the design dir's parent: the app, or the repository root that
224
+ // keeps an existing design/ (the app's own Vite still serves it).
225
+ const root = design.home
226
+ const traits = appTraits(appRoot)
227
+ checks.push(check('app', 'ok', `${found.rel} (${traits.name ?? 'app'}: ${traits.config}, react, ${traits.reactPlugin})`))
228
+ if (design.external) checks.push(check('design-dir', 'ok', `using existing design/ at ${design.rel}`))
229
+ const packages = appPackages(appRoot, traits)
230
+ const missing = Object.entries(packages).filter(([, dir]) => !dir).map(([name]) => name)
231
+ checks.push(
232
+ missing.length
233
+ ? check('app-packages', 'fail', `not installed in the app: ${missing.join(', ')}`, "run the app's package install (seji installs nothing)")
234
+ : check('app-packages', 'ok', `vite, react, react-dom and ${traits.reactPlugin} resolve from the app`),
235
+ )
236
+
237
+ const leftovers = projectSkillDirs(root, { home })
238
+ if (leftovers.length) checks.push(check('project-skills', 'fail', `old project-level skill copies duplicate the global skills: ${leftovers.join(', ')}`, SETUP))
239
+ const oldName = oldNameCheck({ home: root, appRoot, fix: found.how === 'flag' ? `${SETUP} --app ${found.rel}` : SETUP })
240
+ if (oldName) checks.push(oldName)
241
+
242
+ if (!existsSync(join(root, 'design', 'tokens.config.json'))) {
243
+ checks.push(check('setup', 'fail', 'seji is not set up in this app', SETUP))
244
+ return { ok: false, version: PACKAGE_VERSION, app: found.rel, checks }
245
+ }
246
+ checks.push(check('setup', 'ok', 'design/ is set up'))
247
+
248
+ const vite = await loadAppViteConfig(appRoot)
249
+ if (!vite.ok) checks.push(check('vite-config', 'fail', vite.error, "fix the app's vite config / install"))
250
+ else if (vite.designPlugin && !findPackageDir(appRoot, DESIGN_PACKAGE)) {
251
+ checks.push(check('vite-config', 'fail', `${vite.file} mounts designPlugin but ${DESIGN_PACKAGE} is not installed in the app`, `remove designPlugin from ${vite.file} (\`${CLI} dev\` mounts it) or install ${DESIGN_PACKAGE}`))
252
+ } else checks.push(check('vite-config', 'ok', `${vite.file} loads${vite.designPlugin ? ' (mounts designPlugin itself)' : ''}`))
253
+
254
+ checks.push(pathsCheck(root))
255
+ const styles = appStyles(appRoot, { aliases: vite.ok ? vite.aliases : [], tailwindPlugin: vite.ok && vite.tailwind })
256
+ const cssRel = styles.stylesheets.map((file) => relative(root, file).split('\\').join('/'))
257
+ const tokens = await tokensChecks(root, cssRel)
258
+ checks.push(...tokens.checks)
259
+
260
+ const cssOut = tokens.config?.cssOut ? generatedCssPath(root, tokens.config.cssOut) : null
261
+ if (cssOut) {
262
+ const surface = readJson(join(root, 'design/surface.config.json'))
263
+ const listed = (surface?.css ?? []).some((css) => resolve(root, String(css).replace(/^\//, '')) === cssOut)
264
+ if (styles.cssEntry && hasTokenImport(styles.cssEntry, cssOut)) checks.push(check('css-import', 'ok', `${styles.cssEntry.slice(root.length + 1)} imports ${tokens.config.cssOut}`))
265
+ else if (styles.cssEntry) {
266
+ const entryRel = relative(root, styles.cssEntry).split('\\').join('/')
267
+ const line = `@import "${importSpecifier(styles.cssEntry, cssOut)}";`
268
+ // A root design/ (legacy layout): setup leaves that app's CSS alone, so name the line to add.
269
+ const fix = design.external ? `add \`${line}\` at the top of ${entryRel}` : `${SETUP} (adds ${line})`
270
+ checks.push(check('css-import', 'fail', `${entryRel} does not import ${tokens.config.cssOut}: the app does not see the tokens`, fix))
271
+ }
272
+ else checks.push(check('css-import', listed ? 'warn' : 'fail', `the entry imports no stylesheet; ${tokens.config.cssOut} ${listed ? 'reaches the frames through surface.config.json only' : 'is not loaded anywhere'}`, `import "${tokens.config.cssOut}" from the app's entry`))
273
+ }
274
+
275
+ try {
276
+ // Not while the 0.5.x cache is still there: creating design/.seji/ now would leave the old
277
+ // one (comments, screenshots) behind instead of renamed by setup.
278
+ if (!existsSync(join(root, LEGACY_CACHE_DIR))) await ensureDesignTypes(root)
279
+ } catch {
280
+ // reported below
281
+ }
282
+ const types = designTypesState(root)
283
+ checks.push(check('types', types.ok ? 'ok' : types.warn ? 'warn' : 'fail', types.detail, types.ok ? undefined : types.warn ? 'add "extends": "./.seji/tsconfig.json" to design/tsconfig.json' : SETUP))
284
+
285
+ checks.push(existsSync(join(root, 'design/providers.tsx')) ? check('providers', 'ok', 'design/providers.tsx') : check('providers', 'warn', 'design/providers.tsx is missing: frames render without the app\'s providers', SETUP))
286
+
287
+ for (const name of [RUNTIME_PACKAGE, DESIGN_PACKAGE]) {
288
+ const declared = declaredRange(root, name)
289
+ if (declared) checks.push(check('dependency', 'warn', `${name} ${declared} is a project dependency; seji no longer needs it (dev uses the CLI's own runtime) — removable`, `remove ${name} from package.json (optional)`))
290
+ }
291
+
292
+ checks.push(...gitChecks(root))
293
+ const legacy = legacyLayout(root)
294
+ if (legacy.length) checks.push(check('layout', 'warn', `0.4.2 layout still present: ${legacy.join(', ')}`, SETUP))
295
+ if (deep) checks.push(await deepCheck(appRoot, { designDir: design.designDir }))
296
+
297
+ const list = checks.filter(Boolean)
298
+ return { ok: !list.some((entry) => entry.status === 'fail'), version: PACKAGE_VERSION, app: found.rel, root: appRoot, checks: list }
299
+ }
300
+
301
+ export function formatDoctor(report) {
302
+ const label = { ok: 'OK ', warn: 'WARN', fail: 'FAIL' }
303
+ const lines = report.checks.map((entry) => `${label[entry.status]} ${entry.id.padEnd(14)} ${entry.detail}${entry.fix ? `\n fix: ${entry.fix}` : ''}`)
304
+ lines.push('', report.ok ? `seji ${report.version}: ready.` : `seji ${report.version}: run the fixes above, then doctor again.`)
305
+ return lines.join('\n')
306
+ }