@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,726 @@
1
+ // Consolidation plans: a saved scan the user / agent edits row by row (`consolidate set`), then
2
+ // `consolidate apply` executes through the token-operation machinery of src/tokens/ops.mjs —
3
+ // one composite operation under the project's token-operation lock: new tokens are written
4
+ // (explicit tier + $description), duplicates are merged (the old name stays as a deprecated
5
+ // alias), hard-coded literals are replaced with AST rewriters, tokens are rebuilt, and ONE
6
+ // review item (kind 'token', tokenAction 'consolidate') + ONE revertible batch are recorded.
7
+ import { randomUUID } from 'node:crypto'
8
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync } from 'node:fs'
9
+ import { join, relative, resolve, sep } from 'node:path'
10
+
11
+ import { readReviewFile, reviewFilePath } from '../../shared/reviewStore.mjs'
12
+ import { TOKEN_TIERS, TokenOpError, revertBatch, runTokenPlan, tokenOpInternals, withTokenLock } from '../ops.mjs'
13
+ import { cssNameOf, loadTokenConfig, readTokenRecords, resolveRecords } from '../pipeline.mjs'
14
+ import { writeFileAtomic } from '../rewrite/index.mjs'
15
+ import { NAMESPACE_HINT, normalizeValue } from './normalize.mjs'
16
+ import { ConsolidateError, loadScanContext, rowVisibleChange, scanConsolidation, targetFromValue } from './scan.mjs'
17
+
18
+ export const PLAN_DIR = 'design/.seji/consolidate'
19
+ export const ROW_ACTIONS = ['reuse', 'create', 'merge', 'skip']
20
+ /** Actions that write something. A row may also be `undecided` (a visible change nobody picked). */
21
+ const ACTIVE_ACTIONS = ['reuse', 'create', 'merge']
22
+ const SAFE_PLAN_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,80}$/
23
+ const toPosix = (file) => file.split(sep).join('/')
24
+ const lower = (value) => String(value ?? '').trim().toLowerCase()
25
+
26
+ const fail = (message, details) => {
27
+ throw new ConsolidateError(message, details)
28
+ }
29
+
30
+ export function planPath(root, id) {
31
+ if (typeof id !== 'string' || !SAFE_PLAN_ID.test(id)) fail(`invalid plan id: ${id}`, { code: 'invalid-args' })
32
+ return resolve(root, PLAN_DIR, `${id}.json`)
33
+ }
34
+
35
+ export function readPlan(root, id) {
36
+ const file = planPath(root, id)
37
+ if (!existsSync(file)) fail(`plan not found: ${id}`, { code: 'not-found' })
38
+ let plan
39
+ try {
40
+ plan = JSON.parse(readFileSync(file, 'utf8'))
41
+ } catch {
42
+ fail(`plan ${id} is not valid JSON (${toPosix(relative(root, file))})`)
43
+ }
44
+ if (plan?.version !== 1 || !Array.isArray(plan.rows)) fail(`plan ${id} has an invalid shape`)
45
+ return plan
46
+ }
47
+
48
+ function writePlan(root, plan) {
49
+ const file = planPath(root, plan.id)
50
+ mkdirSync(resolve(root, PLAN_DIR), { recursive: true })
51
+ writeFileAtomic(file, `${JSON.stringify(plan, null, 2)}\n`)
52
+ return toPosix(relative(root, file))
53
+ }
54
+
55
+ export function listPlans(root) {
56
+ const dir = resolve(root, PLAN_DIR)
57
+ if (!existsSync(dir)) return []
58
+ return readdirSync(dir)
59
+ .filter((name) => name.endsWith('.json') && SAFE_PLAN_ID.test(name.slice(0, -5)))
60
+ .map((name) => {
61
+ try {
62
+ const plan = readPlan(root, name.slice(0, -5))
63
+ return {
64
+ id: plan.id,
65
+ status: plan.status,
66
+ createdAt: plan.createdAt,
67
+ updatedAt: plan.updatedAt,
68
+ scope: plan.options?.scope ?? [],
69
+ categories: plan.options?.categories ?? [],
70
+ rows: plan.rows.length,
71
+ active: plan.rows.filter((row) => ACTIVE_ACTIONS.includes(row.action)).length,
72
+ undecided: plan.rows.filter((row) => row.action === 'undecided').length,
73
+ ...(plan.applied ? { batchId: plan.applied.batchId } : {}),
74
+ }
75
+ } catch (error) {
76
+ return { id: name.slice(0, -5), error: error instanceof Error ? error.message : String(error) }
77
+ }
78
+ })
79
+ .sort((a, b) => String(b.createdAt ?? '').localeCompare(String(a.createdAt ?? '')))
80
+ }
81
+
82
+ const tokenMaps = (root) => {
83
+ const config = loadTokenConfig(root)
84
+ const { records } = readTokenRecords(root, config.tokenDir)
85
+ resolveRecords(records)
86
+ return { records, byPath: new Map(records.map((record) => [record.path.join('.'), record])), byCss: new Map(records.map((record) => [record.cssName, record])) }
87
+ }
88
+
89
+ const lookup = (maps, ref) => {
90
+ const name = String(ref ?? '').trim()
91
+ if (!name) return null
92
+ return maps.byPath.get(name) ?? maps.byCss.get(name) ?? (name.startsWith('--') ? null : maps.byCss.get(`--${name}`)) ?? null
93
+ }
94
+
95
+ const withOptions = (plan, row) => ({ ...row, normalizeOptions: { rootPx: plan.options?.rootPx ?? 16 } })
96
+ const stripOptions = ({ normalizeOptions: _options, ...row }) => row
97
+
98
+ /** Scan and save the result as a plan file. */
99
+ export async function createPlan({ root = process.cwd(), scope, category, categories, tolerance, rootPx, design } = {}) {
100
+ const result = await scanConsolidation({ root, scope, categories: categories ?? category, tolerance, rootPx })
101
+ const now = new Date().toISOString()
102
+ const id = `plan-${now.replace(/[-:.TZ]/g, '').slice(0, 14)}-${randomUUID().slice(0, 6)}`
103
+ const plan = {
104
+ version: 1,
105
+ id,
106
+ status: 'draft',
107
+ createdAt: now,
108
+ updatedAt: now,
109
+ ...(design ? { design: String(design) } : {}),
110
+ options: result.options,
111
+ counts: result.counts,
112
+ rows: result.rows,
113
+ unclustered: result.unclustered,
114
+ ...(result.unsupported ? { unsupported: result.unsupported } : {}),
115
+ }
116
+ const file = await withTokenLock(root, () => writePlan(root, plan))
117
+ return { ...plan, file }
118
+ }
119
+
120
+ function findRow(plan, ref) {
121
+ const key = String(ref ?? '').trim()
122
+ if (!key) fail('<row> is required (row id like r3, or its 1-based number)', { code: 'invalid-args' })
123
+ const row = plan.rows.find((entry) => entry.id === key) ?? (/^\d+$/.test(key) ? plan.rows[Number(key) - 1] : undefined)
124
+ if (!row) fail(`row not found in ${plan.id}: ${key}`, { code: 'not-found' })
125
+ return row
126
+ }
127
+
128
+ const listOf = (value) =>
129
+ (Array.isArray(value) ? value : value === undefined || value === null ? [] : [value])
130
+ .flatMap((entry) => String(entry).split(','))
131
+ .map((entry) => entry.trim())
132
+ .filter(Boolean)
133
+
134
+ /**
135
+ * Edit one plan row: `{ action?, token?, name?, tier?, description?, value?, merge?,
136
+ * acceptVisibleChange? }`. Returns the updated row with its recomputed visible changes.
137
+ */
138
+ export async function setPlanRow({ root = process.cwd(), plan: planId, row: rowRef, ...changes } = {}) {
139
+ return withTokenLock(root, () => {
140
+ const plan = readPlan(root, planId)
141
+ if (plan.status === 'applied' && !syncReverted(root, plan)) {
142
+ fail(`${plan.id} was applied (batch ${plan.applied?.batchId}); revert it first (\`consolidate revert ${plan.id}\`) or make a new plan`, {
143
+ why: { code: 'plan-applied', params: { plan: plan.id } },
144
+ })
145
+ }
146
+ const row = findRow(plan, rowRef)
147
+ const maps = tokenMaps(root)
148
+ const before = JSON.stringify([row.action, row.token, row.value, row.merge])
149
+ if (changes.action !== undefined) {
150
+ if (!ROW_ACTIONS.includes(changes.action)) fail(`--action must be one of ${ROW_ACTIONS.join(', ')}`, { code: 'invalid-args' })
151
+ row.action = changes.action
152
+ } else if (changes.token !== undefined && !['reuse', 'merge'].includes(row.action)) {
153
+ // `--token X` alone means "reuse X" (it would otherwise be silently ignored).
154
+ row.action = 'reuse'
155
+ } else if (changes.name !== undefined && row.action !== 'create') {
156
+ row.action = 'create'
157
+ } else if (row.action === 'skip' && (changes.tier !== undefined || changes.description !== undefined || changes.value !== undefined || changes.merge !== undefined)) {
158
+ fail(`row ${row.id} is skip; pass --action create|merge with these options`, { code: 'invalid-args' })
159
+ } else if (row.action === 'undecided') {
160
+ // Nobody picked an action yet: accepting a visible change (or a tier, a note…) alone
161
+ // would decide it implicitly.
162
+ fail(`row ${row.id} is undecided: pass --action ${ROW_ACTIONS.join('|')} (it changes the rendering, so the tool does not pick)`, {
163
+ code: 'invalid-args',
164
+ why: { code: 'needs-decision', params: { row: row.id } },
165
+ })
166
+ }
167
+ for (const key of ['name', 'tier', 'description', 'value', 'token']) {
168
+ if (changes[key] !== undefined) row[key] = String(changes[key]).trim()
169
+ }
170
+ if (changes.merge !== undefined) row.merge = listOf(changes.merge)
171
+ const live = row.tokens.filter((entry) => entry.deprecated === undefined)
172
+ if (row.action === 'reuse' || row.action === 'merge') {
173
+ const proposedToken = row.proposed && ['reuse', 'merge'].includes(row.proposed.action) ? row.proposed.token : ''
174
+ row.token = row.token || proposedToken || row.suggestion?.token || live[0]?.path || ''
175
+ if (!row.token) fail(`row ${row.id} has no token to ${row.action}: pass --token <token>`, { code: 'invalid-args' })
176
+ const record = lookup(maps, row.token)
177
+ if (!record) fail(`unknown token: ${row.token}`, { code: 'invalid-args', why: { code: 'unknown-token', params: { token: row.token } } })
178
+ const path = record.path.join('.')
179
+ if (record.deprecated !== undefined) {
180
+ fail(`${path} is deprecated; choose its replacement`, { code: 'invalid-args', why: { code: 'deprecated-token', params: { token: path } } })
181
+ }
182
+ if (!normalizeValue(row.category, record.value, { rootPx: plan.options?.rootPx })) {
183
+ fail(`${path} (${record.value}) is not a ${row.category} value`, {
184
+ code: 'invalid-args',
185
+ why: { code: 'wrong-category', params: { token: path, value: record.value, category: row.category } },
186
+ })
187
+ }
188
+ row.token = record.path.join('.')
189
+ }
190
+ if (row.action === 'merge') {
191
+ // Without an explicit --merge list, merge the other duplicates of the chosen keeper (the
192
+ // suggested group, or every independently defined token of the row).
193
+ const group =
194
+ row.suggestion?.action === 'merge'
195
+ ? [row.suggestion.token, ...row.suggestion.merge]
196
+ : live.filter((entry) => entry.root === entry.path).map((entry) => entry.path)
197
+ const pathOf = (name) => lookup(maps, name)?.path.join('.') ?? name
198
+ if (changes.merge === undefined) {
199
+ const kept = (row.merge ?? []).filter((name) => pathOf(name) !== row.token)
200
+ row.merge = kept.length ? kept : group.filter((name) => pathOf(name) !== row.token)
201
+ }
202
+ if (!row.merge.length) fail(`row ${row.id}: nothing to merge into ${row.token}; pass --merge <token,…>`, { code: 'invalid-args' })
203
+ row.merge = row.merge.map((name) => {
204
+ const record = lookup(maps, name)
205
+ if (!record) fail(`unknown token to merge: ${name}`, { code: 'invalid-args', why: { code: 'unknown-merge', params: { token: name } } })
206
+ if (record.path.join('.') === row.token) fail(`cannot merge ${row.token} into itself`, { code: 'invalid-args', why: { code: 'merge-self', params: {} } })
207
+ return record.path.join('.')
208
+ })
209
+ }
210
+ if (row.action === 'create') {
211
+ row.name = row.name ?? ''
212
+ row.tier = row.tier ?? ''
213
+ row.description = row.description ?? ''
214
+ row.value = row.value || row.suggestion?.value || row.values[0]?.canonical || ''
215
+ if (row.value && !targetFromValue(row.category, row.value, { rootPx: plan.options?.rootPx }, maps.byPath)) {
216
+ fail(`--value ${row.value} is not a ${row.category} value${/^\{/.test(row.value) ? ' (or the alias target does not exist)' : ''}`, {
217
+ code: 'invalid-args',
218
+ why: { code: 'bad-value', params: { value: row.value, category: row.category } },
219
+ })
220
+ }
221
+ if (row.tier && !TOKEN_TIERS.includes(row.tier)) fail(`--tier must be one of ${TOKEN_TIERS.join(', ')}`, { code: 'invalid-args' })
222
+ if (row.name) {
223
+ try {
224
+ tokenOpInternals.parsePath(row.name)
225
+ } catch (error) {
226
+ fail(error.message, { code: 'invalid-args', ...(error.details?.why ? { why: error.details.why } : {}) })
227
+ }
228
+ if (lookup(maps, row.name)) {
229
+ fail(`${row.name} already exists; use --action reuse --token ${row.name}`, { code: 'invalid-args', why: { code: 'exists', params: { name: row.name } } })
230
+ }
231
+ }
232
+ }
233
+ // Decided now: the tool's proposal has done its job.
234
+ delete row.proposed
235
+ const changedTarget = JSON.stringify([row.action, row.token, row.value, row.merge]) !== before
236
+ row.visibleChange = rowVisibleChange(withOptions(plan, row), maps.byPath)
237
+ // An acceptance is bound to the exact changes accepted (their signatures): a later change of
238
+ // the target (`tokens set`, another token, new occurrences with another value) needs a new one.
239
+ if (changes.acceptVisibleChange === true) {
240
+ row.acceptVisibleChange = true
241
+ row.acceptedVisibleChange = row.visibleChange.map((change) => change.signature)
242
+ } else if (changes.acceptVisibleChange === false || changedTarget) {
243
+ row.acceptVisibleChange = false
244
+ delete row.acceptedVisibleChange
245
+ }
246
+ plan.updatedAt = new Date().toISOString()
247
+ if (plan.status === 'reverted') plan.status = 'draft'
248
+ writePlan(root, plan)
249
+ return { plan: plan.id, row, ...issueFields(rowIssues(plan, row, maps)) }
250
+ })
251
+ }
252
+
253
+ /**
254
+ * Why a row cannot be applied yet (empty when it can): `{ code, params, message }` each. The
255
+ * message is what the CLI prints; the editor translates `code` with `params`.
256
+ */
257
+ function rowIssues(plan, row, maps, created = new Map(), { visible = true, merged = new Map() } = {}) {
258
+ const issues = []
259
+ const problems = { push: (code, params, message) => issues.push({ code, params, message }) }
260
+ if (row.action === 'undecided') {
261
+ problems.push(
262
+ 'needs-decision',
263
+ { row: row.id },
264
+ `undecided: it changes the rendering, so the tool does not pick; \`consolidate set ${plan.id} ${row.id} --action ${ROW_ACTIONS.join('|')}\``,
265
+ )
266
+ return issues
267
+ }
268
+ if (!ACTIVE_ACTIONS.includes(row.action)) return issues
269
+ const options = { rootPx: plan.options?.rootPx ?? 16 }
270
+ if (row.action === 'create') {
271
+ if (!row.name) {
272
+ problems.push(
273
+ 'needs-name',
274
+ {},
275
+ `needs a token name: \`consolidate set ${plan.id} ${row.id} --name <dot.path>\` (prefixes in use: ${namingSummary(row) || 'none'}); the tool does not invent names`,
276
+ )
277
+ } else {
278
+ try {
279
+ tokenOpInternals.parsePath(row.name)
280
+ if (lookup(maps, row.name) || maps.byCss.has(cssNameOf(row.name.split('.')))) {
281
+ problems.push('exists', { name: row.name }, `${row.name} already exists`)
282
+ } else if (created.has(row.name)) {
283
+ problems.push('created-twice', { name: row.name, row: created.get(row.name) }, `${row.name} is also created by row ${created.get(row.name)}`)
284
+ }
285
+ } catch (error) {
286
+ problems.push(error.details?.why?.code ?? 'invalid-path', error.details?.why?.params ?? { value: row.name }, error.message)
287
+ }
288
+ }
289
+ if (!TOKEN_TIERS.includes(row.tier)) {
290
+ problems.push('needs-tier', {}, `needs an explicit tier: --tier ${TOKEN_TIERS.join('|')} (there is no default)`)
291
+ }
292
+ if (!String(row.description ?? '').trim()) {
293
+ problems.push('needs-description', {}, 'needs a $description usage note: --description "<when to use it>"')
294
+ }
295
+ if (!row.value || !targetFromValue(row.category, row.value, options, maps.byPath)) {
296
+ problems.push('needs-value', { category: row.category }, `needs a ${row.category} --value (a value or an existing {alias.path})`)
297
+ }
298
+ } else {
299
+ const record = lookup(maps, row.token)
300
+ if (!record) problems.push('unknown-token', { token: row.token || '' }, `unknown token: ${row.token || '(none)'}`)
301
+ else if (record.deprecated !== undefined) problems.push('deprecated-token', { token: row.token }, `${row.token} is deprecated`)
302
+ else if (!fitsCategory(record, row.category, options)) {
303
+ problems.push(
304
+ 'wrong-category',
305
+ { token: row.token, value: record.value, category: row.category },
306
+ `${row.token} (${record.value}) is not a ${row.category} value`,
307
+ )
308
+ }
309
+ if (row.action === 'merge') {
310
+ if (!row.merge?.length) problems.push('merge-empty', {}, 'merge lists no tokens (--merge <token,…>)')
311
+ for (const name of row.merge ?? []) {
312
+ const source = lookup(maps, name)
313
+ if (!source) problems.push('unknown-merge', { token: name }, `unknown token to merge: ${name}`)
314
+ else if (record && source.dtcgType !== record.dtcgType) {
315
+ problems.push(
316
+ 'type-mismatch',
317
+ { token: name, type: source.dtcgType, other: row.token, otherType: record.dtcgType },
318
+ `cannot merge ${source.dtcgType} ${name} into ${record.dtcgType} ${row.token}`,
319
+ )
320
+ }
321
+ const key = source ? source.path.join('.') : name
322
+ if (merged.has(key) && merged.get(key) !== row.id) {
323
+ problems.push('merged-twice', { token: key, row: merged.get(key) }, `${key} is also merged by row ${merged.get(key)}`)
324
+ } else merged.set(key, row.id)
325
+ }
326
+ }
327
+ }
328
+ if (visible) {
329
+ const problem = visibleProblem(row, rowVisibleChange(withOptions(plan, row), maps.byPath))
330
+ if (problem) issues.push(problem)
331
+ }
332
+ return issues
333
+ }
334
+
335
+ /** Messages of `rowIssues` (what the CLI prints) and their codes (what the editor translates). */
336
+ const issueFields = (issues) => ({
337
+ problems: issues.map((issue) => issue.message),
338
+ issues: issues.map(({ code, params }) => ({ code, params })),
339
+ })
340
+
341
+ /** Unaccepted visible changes of a row (null when there are none, or all were accepted as they are). */
342
+ function visibleProblem(row, visible) {
343
+ if (!visible.length) return null
344
+ const accepted = new Set(row.acceptVisibleChange === true && Array.isArray(row.acceptedVisibleChange) ? row.acceptedVisibleChange : [])
345
+ const open = visible.filter((change) => !accepted.has(change.signature))
346
+ if (!open.length) return null
347
+ const shown = open
348
+ .slice(0, 3)
349
+ .map((change) => `${change.token ? `${change.token} ` : ''}${change.from} → ${change.to} (${Object.entries(change.delta).map(([key, value]) => `${key} ${value}`).join(', ')})`)
350
+ .join('; ')
351
+ const again = accepted.size ? ' (differs from what was accepted)' : ''
352
+ return {
353
+ code: accepted.size ? 'visible-changed' : 'visible',
354
+ params: { changes: open.slice(0, 3).map((change) => `${change.from} → ${change.to}`).join(', '), more: Math.max(0, open.length - 3) },
355
+ message: `changes rendering${again}: ${shown}${open.length > 3 ? ` (+${open.length - 3})` : ''}; confirm with --accept-visible-change or choose another action`,
356
+ }
357
+ }
358
+
359
+ /** A plan marked applied whose batch was reverted (`tokens revert`) is marked reverted. Returns true then. */
360
+ function syncReverted(root, plan) {
361
+ if (plan.status !== 'applied' || !plan.applied?.batchId) return false
362
+ const batch = ledgerBatch(root, plan.applied.design, plan.applied.batchId)
363
+ if (!batch?.revertedAt) return false
364
+ plan.status = 'reverted'
365
+ plan.reverted = { at: batch.revertedAt, batchId: plan.applied.batchId }
366
+ return true
367
+ }
368
+
369
+ function namingSummary(row) {
370
+ const tiers = row.suggestion?.naming?.tiers ?? {}
371
+ return Object.entries(tiers)
372
+ .map(([tier, prefixes]) => `${tier}: ${prefixes.map((entry) => `${entry.prefix}.*`).join(', ')}`)
373
+ .join('; ')
374
+ }
375
+
376
+ const ledgerBatch = (root, design, batchId) => {
377
+ try {
378
+ return readReviewFile(reviewFilePath(root, design))?.batches?.find((entry) => entry.id === batchId) ?? null
379
+ } catch {
380
+ return null
381
+ }
382
+ }
383
+
384
+ const dtcgTypeFor = (category, value) => {
385
+ if (category === 'color') return 'color'
386
+ if (category === 'shadow') return 'string'
387
+ if (category === 'font-weight') return 'fontWeight'
388
+ if (/^-?\d*\.?\d+(px|rem|em|%)$/i.test(String(value).trim())) return 'dimension'
389
+ if (/^-?\d*\.?\d+$/.test(String(value).trim())) return 'number'
390
+ return 'string'
391
+ }
392
+
393
+ /** Build the composite token operation for a plan (runs inside `execute`, under the lock). */
394
+ function buildApply(plan) {
395
+ const { createDraft, findRecord, keyOf, addTokenToDraft, planMerge, renameSpec, noteList } = tokenOpInternals
396
+ return async (ctx) => {
397
+ // Rows nobody decided (their proposal changes the rendering) block the whole apply.
398
+ const undecidedRows = plan.rows.filter((row) => row.action === 'undecided')
399
+ if (undecidedRows.length) {
400
+ const rows = undecidedRows.map((row) => ({ row: row.id, category: row.category, anchor: row.anchor, action: row.action, ...issueFields(rowIssues(plan, row, {})) }))
401
+ fail(
402
+ `${plan.id} is not ready: ${rows.map((entry) => `${entry.row} (${entry.anchor}): ${entry.problems.join('; ')}`).join(' | ')}`,
403
+ { code: 'plan-incomplete', rows, why: { code: 'plan-incomplete', params: { count: rows.length } } },
404
+ )
405
+ }
406
+ const active = plan.rows.filter((row) => ACTIVE_ACTIONS.includes(row.action))
407
+ if (!active.length) {
408
+ fail(`nothing to apply: every row of ${plan.id} is skip (set an action with \`consolidate set\`)`, { why: { code: 'nothing-to-apply', params: {} } })
409
+ }
410
+ const maps = { byPath: ctx.byPath, byCss: ctx.byCss }
411
+ const problems = []
412
+ const createdNames = new Map()
413
+ const merged = new Map()
414
+ for (const row of active) {
415
+ // Visible changes are checked below against the CURRENT scan, not the plan's.
416
+ const list = rowIssues(plan, row, maps, createdNames, { visible: false, merged })
417
+ if (row.action === 'create' && row.name) createdNames.set(row.name, row.id)
418
+ if (list.length) problems.push({ row: row.id, category: row.category, anchor: row.anchor, action: row.action, ...issueFields(list) })
419
+ }
420
+ if (problems.length) {
421
+ fail(
422
+ `${plan.id} is not ready: ${problems.map((entry) => `${entry.row} (${entry.action} ${entry.anchor}): ${entry.problems.join('; ')}`).join(' | ')}`,
423
+ { code: 'plan-incomplete', rows: problems, why: { code: 'plan-incomplete', params: { count: problems.length } } },
424
+ )
425
+ }
426
+
427
+ // Re-scan now: occurrences are re-located in the current files (never replayed offsets).
428
+ const scan = await scanConsolidation({
429
+ root: ctx.root,
430
+ context: loadScanContext(ctx.root, { ...plan.options, config: ctx.config, records: ctx.records, writable: ctx.scope }),
431
+ })
432
+ const current = new Map()
433
+ for (const row of scan.rows) {
434
+ for (const occurrence of row.occurrences) {
435
+ const key = `${row.category}\0${occurrence.value}`
436
+ if (!current.has(key)) current.set(key, [])
437
+ current.get(key).push(occurrence)
438
+ }
439
+ }
440
+ const scanSet = new Set(ctx.scan)
441
+ const draft = createDraft(ctx)
442
+ const expect = { present: [], aliases: {}, values: {} }
443
+ const renames = new Map()
444
+ const notes = noteList()
445
+ const steps = []
446
+ const extraLeftovers = []
447
+ const rowsReport = []
448
+ const visibleProblems = []
449
+ const literalFiles = new Set()
450
+ let subject = null
451
+ for (const row of active) {
452
+ let target
453
+ if (row.action === 'create') {
454
+ const created = addTokenToDraft(ctx, draft, {
455
+ token: row.name,
456
+ value: row.value,
457
+ tier: row.tier,
458
+ description: row.description,
459
+ // An alias (`{color.x}`) takes its target's type.
460
+ ...(/^\{[^}]+\}$/.test(String(row.value).trim()) ? {} : { type: dtcgTypeFor(row.category, row.value) }),
461
+ })
462
+ target = created.record
463
+ expect.present.push(...created.expect.present)
464
+ Object.assign(expect.values, created.expect.values ?? {})
465
+ Object.assign(expect.aliases, created.expect.aliases ?? {})
466
+ } else {
467
+ target = findRecord(ctx, row.token)
468
+ expect.present.push(target.cssName)
469
+ }
470
+ subject ??= target
471
+ const targetPath = keyOf(target)
472
+ if (row.action === 'merge') {
473
+ for (const name of row.merge) {
474
+ const source = findRecord(ctx, name)
475
+ if (source.alias === targetPath) {
476
+ notes.add('already-alias', { token: name, other: targetPath }, `${name} already aliases ${targetPath}; not merged again`)
477
+ continue
478
+ }
479
+ const merged = await planMerge({
480
+ token: name,
481
+ into: targetPath,
482
+ keep: 'target',
483
+ reason: `Consolidated into ${targetPath} (${plan.id} ${row.id}).`,
484
+ })(ctx, { draft })
485
+ renames.set(source.cssName, target.cssName)
486
+ Object.assign(expect.aliases, merged.expect.aliases ?? {})
487
+ for (const [index, text] of (merged.notes ?? []).entries()) {
488
+ const coded = merged.notes?.codes?.[index]
489
+ notes.add(coded?.code ?? 'text', coded?.params ?? { text }, text)
490
+ }
491
+ }
492
+ }
493
+ const groups = new Map()
494
+ const toReplace = []
495
+ let replaceable = 0
496
+ let left = 0
497
+ for (const value of row.values) {
498
+ for (const occurrence of current.get(`${row.category}\0${value.canonical}`) ?? []) {
499
+ const abs = resolve(ctx.root, occurrence.file)
500
+ if (occurrence.replaceable && scanSet.has(abs)) toReplace.push(occurrence)
501
+ if (!occurrence.replaceable || !scanSet.has(abs)) {
502
+ left += 1
503
+ extraLeftovers.push({
504
+ file: occurrence.file,
505
+ line: occurrence.line,
506
+ column: occurrence.column,
507
+ property: occurrence.property,
508
+ scheme: occurrence.scheme,
509
+ reason: occurrence.replaceable ? 'outside-project-root' : occurrence.reason,
510
+ text: occurrence.text,
511
+ })
512
+ continue
513
+ }
514
+ replaceable += 1
515
+ const key = lower(occurrence.text)
516
+ const group = groups.get(key) ?? { literal: occurrence.text, properties: new Set(), utilities: new Set(), files: new Set() }
517
+ if (occurrence.scheme === 'tailwind') group.utilities.add(occurrence.property)
518
+ else group.properties.add(lower(occurrence.property))
519
+ group.files.add(abs)
520
+ literalFiles.add(abs)
521
+ groups.set(key, group)
522
+ }
523
+ }
524
+ for (const group of groups.values()) {
525
+ steps.push({
526
+ spec: {
527
+ mode: 'literal',
528
+ literal: group.literal,
529
+ token: target.cssName,
530
+ replacement: `var(${target.cssName})`,
531
+ properties: [...group.properties],
532
+ utilities: [...group.utilities],
533
+ classes: group.utilities.size > 0,
534
+ ...(NAMESPACE_HINT[row.category] ? { namespaceHint: NAMESPACE_HINT[row.category] } : {}),
535
+ theme: ctx.theme && !ctx.uno,
536
+ },
537
+ files: group.files,
538
+ })
539
+ }
540
+ // What this row changes on screen NOW (current files, current token values), and whether
541
+ // exactly that was accepted.
542
+ const visibleNow = rowVisibleChange(withOptions(plan, row), ctx.byPath, toReplace)
543
+ const problem = visibleProblem(row, visibleNow)
544
+ if (problem) visibleProblems.push({ row: row.id, category: row.category, anchor: row.anchor, action: row.action, ...issueFields([problem]) })
545
+ rowsReport.push({
546
+ row: row.id,
547
+ category: row.category,
548
+ action: row.action,
549
+ token: targetPath,
550
+ cssName: target.cssName,
551
+ values: row.values.map((value) => value.canonical),
552
+ ...(row.action === 'merge' ? { merged: row.merge } : {}),
553
+ found: replaceable + left,
554
+ replaceable,
555
+ ...(visibleNow.length ? { visibleChange: visibleNow.map(({ signature: _s, ...change }) => change) } : {}),
556
+ })
557
+ }
558
+ if (visibleProblems.length) {
559
+ fail(
560
+ `${plan.id} is not ready: ${visibleProblems.map((entry) => `${entry.row} (${entry.action} ${entry.anchor}): ${entry.problems.join('; ')}`).join(' | ')}`,
561
+ { code: 'plan-incomplete', rows: visibleProblems, why: { code: 'plan-incomplete', params: { count: visibleProblems.length } } },
562
+ )
563
+ }
564
+ // Merged tokens: every var(--old) / Tailwind reference moves to the target, like `tokens merge`.
565
+ if (renames.size) steps.push({ spec: renameSpec(ctx, renames) })
566
+ const counts = active.reduce((acc, row) => ({ ...acc, [row.action]: (acc[row.action] ?? 0) + 1 }), {})
567
+ const summary = `Consolidated ${active.length} row(s) of ${plan.id} (${Object.entries(counts).map(([action, n]) => `${n} ${action}`).join(', ')})`
568
+ if (!Object.keys(expect.values).length) delete expect.values
569
+ if (!Object.keys(expect.aliases).length) delete expect.aliases
570
+ expect.present = [...new Set(expect.present)]
571
+ return {
572
+ op: 'consolidate',
573
+ record: subject,
574
+ draft,
575
+ notes,
576
+ files: renames.size ? ctx.scan : [...literalFiles],
577
+ outsideFiles: renames.size ? ctx.outside : [],
578
+ codeSteps: steps,
579
+ extraLeftovers,
580
+ expect,
581
+ item: { tokenAction: 'consolidate', from: '', to: summary, rationale: `Plan ${plan.id}` },
582
+ tokenOpExtra: { plan: plan.id, rows: rowsReport },
583
+ args: { plan: plan.id, rows: active.length, counts },
584
+ summary,
585
+ rowsReport,
586
+ }
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Apply a plan. `dryRun` lists every place and writes nothing (an incomplete plan returns
592
+ * `refused` + per-row `problems` instead of throwing).
593
+ */
594
+ export async function applyPlan({ root = process.cwd(), plan: planId, dryRun = false, design, hooks } = {}) {
595
+ const preview = readPlan(root, planId)
596
+ try {
597
+ return await runTokenPlan({
598
+ root,
599
+ dryRun,
600
+ design: design ?? preview.design,
601
+ hooks,
602
+ build: async (ctx) => {
603
+ // Read the plan again under the lock: a concurrent `set` or `apply` is seen.
604
+ const plan = readPlan(root, planId)
605
+ if (plan.status === 'applied') {
606
+ const batch = plan.applied ? ledgerBatch(root, plan.applied.design, plan.applied.batchId) : null
607
+ if (!batch || !batch.revertedAt) {
608
+ fail(`${plan.id} was already applied (batch ${plan.applied?.batchId}); revert it first or make a new plan`, {
609
+ why: { code: 'plan-applied', params: { plan: plan.id } },
610
+ })
611
+ }
612
+ }
613
+ return buildApply(plan)(ctx)
614
+ },
615
+ after: (result) => {
616
+ if (dryRun) return { plan: planId, ...result }
617
+ const plan = readPlan(root, planId)
618
+ const now = new Date().toISOString()
619
+ plan.status = 'applied'
620
+ plan.updatedAt = now
621
+ plan.applied = {
622
+ at: now,
623
+ design: result.design,
624
+ batchId: result.batchId,
625
+ itemId: result.itemId,
626
+ counts: result.counts,
627
+ }
628
+ writePlan(root, plan)
629
+ return { plan: planId, ...result }
630
+ },
631
+ })
632
+ } catch (error) {
633
+ if (dryRun && error instanceof ConsolidateError && error.details?.code === 'plan-incomplete') {
634
+ return { plan: planId, dryRun: true, refused: error.message, why: error.details.why, problems: error.details.rows }
635
+ }
636
+ throw error
637
+ }
638
+ }
639
+
640
+ /** Revert the batch a plan was applied with (`tokens revert <batch>`), and mark the plan. */
641
+ export async function revertPlan({ root = process.cwd(), plan: planId, force = false, dryRun = false } = {}) {
642
+ const plan = readPlan(root, planId)
643
+ if (plan.status !== 'applied' || !plan.applied?.batchId) {
644
+ fail(`${plan.id} is not applied; nothing to revert`, { why: { code: 'plan-not-applied', params: { plan: plan.id } } })
645
+ }
646
+ // Reverted elsewhere (`tokens revert <batch>`): just record it on the plan.
647
+ const batch = ledgerBatch(root, plan.applied.design, plan.applied.batchId)
648
+ if (batch?.revertedAt) {
649
+ if (!dryRun) {
650
+ await withTokenLock(root, () => {
651
+ const latest = readPlan(root, planId)
652
+ if (syncReverted(root, latest)) {
653
+ latest.updatedAt = new Date().toISOString()
654
+ writePlan(root, latest)
655
+ }
656
+ })
657
+ }
658
+ return { plan: plan.id, batch: plan.applied.batchId, alreadyReverted: batch.revertedAt }
659
+ }
660
+ const result = await revertBatch({ root, batch: plan.applied.batchId, design: plan.applied.design, force, dryRun })
661
+ if (dryRun || result.refused) return { plan: plan.id, ...result }
662
+ await withTokenLock(root, () => {
663
+ const latest = readPlan(root, planId)
664
+ const now = new Date().toISOString()
665
+ latest.status = 'reverted'
666
+ latest.updatedAt = now
667
+ latest.reverted = { at: now, batchId: plan.applied.batchId }
668
+ writePlan(root, latest)
669
+ })
670
+ return { plan: plan.id, ...result }
671
+ }
672
+
673
+ /**
674
+ * Delete a plan file (`consolidate discard`): a draft nobody wants, or a reverted plan. An
675
+ * applied plan is the record of its batch, so it has to be reverted first.
676
+ */
677
+ export async function discardPlan({ root = process.cwd(), plan: planId } = {}) {
678
+ return withTokenLock(root, () => {
679
+ const plan = readPlan(root, planId)
680
+ if (plan.status === 'applied' && !syncReverted(root, plan)) {
681
+ fail(`${plan.id} was applied (batch ${plan.applied?.batchId}); revert it first (\`consolidate revert ${plan.id}\`)`, {
682
+ why: { code: 'plan-applied', params: { plan: plan.id } },
683
+ })
684
+ }
685
+ const file = planPath(root, plan.id)
686
+ rmSync(file, { force: true })
687
+ return { plan: plan.id, discarded: true, status: plan.status, file: toPosix(relative(root, file)) }
688
+ })
689
+ }
690
+
691
+ /** A token a row of `category` may reuse or merge into (the same check `rowIssues` makes). */
692
+ const fitsCategory = (record, category, options) => Boolean(normalizeValue(category, record.value, options))
693
+
694
+ /**
695
+ * Every token a row of each plan category may reuse or merge into: not deprecated and its
696
+ * value is a value of that category (what `rowIssues` accepts). The editor's token picker
697
+ * offers these, not only the tokens the scan found near the row.
698
+ */
699
+ export function planCandidates(root, plan) {
700
+ const { records } = tokenMaps(root)
701
+ const options = { rootPx: plan.options?.rootPx ?? 16 }
702
+ const out = {}
703
+ for (const category of plan.options?.categories ?? []) {
704
+ out[category] = records
705
+ .filter((record) => record.deprecated === undefined && fitsCategory(record, category, options))
706
+ .map((record) => record.path.join('.'))
707
+ .sort()
708
+ }
709
+ return out
710
+ }
711
+
712
+ /** Rows that still block `apply`, for `show` / GET plan. */
713
+ export function planReadiness(root, plan) {
714
+ const maps = tokenMaps(root)
715
+ const created = new Map()
716
+ const merged = new Map()
717
+ const rows = []
718
+ for (const row of plan.rows) {
719
+ const issues = rowIssues(plan, row, maps, created, { merged })
720
+ if (row.action === 'create' && row.name) created.set(row.name, row.id)
721
+ if (issues.length) rows.push({ row: row.id, ...issueFields(issues) })
722
+ }
723
+ return { ready: rows.length === 0 && plan.rows.some((row) => ACTIVE_ACTIONS.includes(row.action)), blocked: rows }
724
+ }
725
+
726
+ export { TokenOpError, stripOptions }