@rien7/seji 0.0.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/bin/design-surface.mjs +6 -0
  2. package/bin/postinstall.mjs +19 -0
  3. package/bin/seji.mjs +585 -0
  4. package/dist/agent/host.d.mts +34 -0
  5. package/dist/agent/host.mjs +387 -0
  6. package/dist/agent/messages.d.mts +9 -0
  7. package/dist/agent/messages.mjs +70 -0
  8. package/dist/agent/runtimes.mjs +157 -0
  9. package/dist/cli/app.mjs +321 -0
  10. package/dist/cli/appScan.mjs +284 -0
  11. package/dist/cli/catalog.mjs +78 -0
  12. package/dist/cli/component.mjs +165 -0
  13. package/dist/cli/consolidate.mjs +159 -0
  14. package/dist/cli/cssImport.mjs +68 -0
  15. package/dist/cli/dev.mjs +339 -0
  16. package/dist/cli/doctor.mjs +311 -0
  17. package/dist/cli/init.mjs +338 -0
  18. package/dist/cli/legacyNames.mjs +266 -0
  19. package/dist/cli/migrate.mjs +163 -0
  20. package/dist/cli/prompt.mjs +34 -0
  21. package/dist/cli/propose.mjs +208 -0
  22. package/dist/cli/providers.mjs +344 -0
  23. package/dist/cli/reviewOps.mjs +110 -0
  24. package/dist/cli/semver.mjs +45 -0
  25. package/dist/cli/setup.mjs +360 -0
  26. package/dist/cli/sketches.mjs +47 -0
  27. package/dist/cli/skills.mjs +150 -0
  28. package/dist/cli/snapshot.mjs +107 -0
  29. package/dist/cli/tokenOps.mjs +120 -0
  30. package/dist/cli/types.mjs +191 -0
  31. package/dist/cli/updater.mjs +274 -0
  32. package/dist/components/astIndex.mjs +992 -0
  33. package/dist/components/ops.mjs +1069 -0
  34. package/dist/editor/AgentProposalCard.d.ts +10 -0
  35. package/dist/editor/AgentProposalCard.d.ts.map +1 -0
  36. package/dist/editor/AgentProposalCard.js +31 -0
  37. package/dist/editor/AgentProposalCard.js.map +1 -0
  38. package/dist/editor/App.d.ts +2 -0
  39. package/dist/editor/App.d.ts.map +1 -0
  40. package/dist/editor/App.js +2834 -0
  41. package/dist/editor/App.js.map +1 -0
  42. package/dist/editor/CanvasHud.d.ts +12 -0
  43. package/dist/editor/CanvasHud.d.ts.map +1 -0
  44. package/dist/editor/CanvasHud.js +13 -0
  45. package/dist/editor/CanvasHud.js.map +1 -0
  46. package/dist/editor/CanvasSurface.d.ts +31 -0
  47. package/dist/editor/CanvasSurface.d.ts.map +1 -0
  48. package/dist/editor/CanvasSurface.js +270 -0
  49. package/dist/editor/CanvasSurface.js.map +1 -0
  50. package/dist/editor/CommentPopover.d.ts +17 -0
  51. package/dist/editor/CommentPopover.d.ts.map +1 -0
  52. package/dist/editor/CommentPopover.js +62 -0
  53. package/dist/editor/CommentPopover.js.map +1 -0
  54. package/dist/editor/Comments.d.ts +13 -0
  55. package/dist/editor/Comments.d.ts.map +1 -0
  56. package/dist/editor/Comments.js +41 -0
  57. package/dist/editor/Comments.js.map +1 -0
  58. package/dist/editor/ComponentPage.d.ts +28 -0
  59. package/dist/editor/ComponentPage.d.ts.map +1 -0
  60. package/dist/editor/ComponentPage.js +55 -0
  61. package/dist/editor/ComponentPage.js.map +1 -0
  62. package/dist/editor/ComponentPanel.d.ts +38 -0
  63. package/dist/editor/ComponentPanel.d.ts.map +1 -0
  64. package/dist/editor/ComponentPanel.js +275 -0
  65. package/dist/editor/ComponentPanel.js.map +1 -0
  66. package/dist/editor/Glyph.d.ts +51 -0
  67. package/dist/editor/Glyph.d.ts.map +1 -0
  68. package/dist/editor/Glyph.js +50 -0
  69. package/dist/editor/Glyph.js.map +1 -0
  70. package/dist/editor/History.d.ts +7 -0
  71. package/dist/editor/History.d.ts.map +1 -0
  72. package/dist/editor/History.js +51 -0
  73. package/dist/editor/History.js.map +1 -0
  74. package/dist/editor/Inspector.d.ts +56 -0
  75. package/dist/editor/Inspector.d.ts.map +1 -0
  76. package/dist/editor/Inspector.js +510 -0
  77. package/dist/editor/Inspector.js.map +1 -0
  78. package/dist/editor/LazyMount.d.ts +10 -0
  79. package/dist/editor/LazyMount.d.ts.map +1 -0
  80. package/dist/editor/LazyMount.js +29 -0
  81. package/dist/editor/LazyMount.js.map +1 -0
  82. package/dist/editor/LocaleSwitch.d.ts +3 -0
  83. package/dist/editor/LocaleSwitch.d.ts.map +1 -0
  84. package/dist/editor/LocaleSwitch.js +9 -0
  85. package/dist/editor/LocaleSwitch.js.map +1 -0
  86. package/dist/editor/PreviewFrame.d.ts +10 -0
  87. package/dist/editor/PreviewFrame.d.ts.map +1 -0
  88. package/dist/editor/PreviewFrame.js +22 -0
  89. package/dist/editor/PreviewFrame.js.map +1 -0
  90. package/dist/editor/ProjectIndex.d.ts +12 -0
  91. package/dist/editor/ProjectIndex.d.ts.map +1 -0
  92. package/dist/editor/ProjectIndex.js +43 -0
  93. package/dist/editor/ProjectIndex.js.map +1 -0
  94. package/dist/editor/PromoteComponent.d.ts +28 -0
  95. package/dist/editor/PromoteComponent.d.ts.map +1 -0
  96. package/dist/editor/PromoteComponent.js +33 -0
  97. package/dist/editor/PromoteComponent.js.map +1 -0
  98. package/dist/editor/PromoteForm.d.ts +18 -0
  99. package/dist/editor/PromoteForm.d.ts.map +1 -0
  100. package/dist/editor/PromoteForm.js +35 -0
  101. package/dist/editor/PromoteForm.js.map +1 -0
  102. package/dist/editor/PromoteToken.d.ts +31 -0
  103. package/dist/editor/PromoteToken.d.ts.map +1 -0
  104. package/dist/editor/PromoteToken.js +94 -0
  105. package/dist/editor/PromoteToken.js.map +1 -0
  106. package/dist/editor/StatePreviews.d.ts +28 -0
  107. package/dist/editor/StatePreviews.d.ts.map +1 -0
  108. package/dist/editor/StatePreviews.js +113 -0
  109. package/dist/editor/StatePreviews.js.map +1 -0
  110. package/dist/editor/ValueCombo.d.ts +51 -0
  111. package/dist/editor/ValueCombo.d.ts.map +1 -0
  112. package/dist/editor/ValueCombo.js +260 -0
  113. package/dist/editor/ValueCombo.js.map +1 -0
  114. package/dist/editor/agent/AgentPanel.d.ts +19 -0
  115. package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
  116. package/dist/editor/agent/AgentPanel.js +271 -0
  117. package/dist/editor/agent/AgentPanel.js.map +1 -0
  118. package/dist/editor/agent/Markdown.d.ts +5 -0
  119. package/dist/editor/agent/Markdown.d.ts.map +1 -0
  120. package/dist/editor/agent/Markdown.js +28 -0
  121. package/dist/editor/agent/Markdown.js.map +1 -0
  122. package/dist/editor/agent/agentApi.d.ts +106 -0
  123. package/dist/editor/agent/agentApi.d.ts.map +1 -0
  124. package/dist/editor/agent/agentApi.js +66 -0
  125. package/dist/editor/agent/agentApi.js.map +1 -0
  126. package/dist/editor/agent/toolLines.d.ts +38 -0
  127. package/dist/editor/agent/toolLines.d.ts.map +1 -0
  128. package/dist/editor/agent/toolLines.js +159 -0
  129. package/dist/editor/agent/toolLines.js.map +1 -0
  130. package/dist/editor/agent/useAgent.d.ts +15 -0
  131. package/dist/editor/agent/useAgent.d.ts.map +1 -0
  132. package/dist/editor/agent/useAgent.js +65 -0
  133. package/dist/editor/agent/useAgent.js.map +1 -0
  134. package/dist/editor/api.d.ts +378 -0
  135. package/dist/editor/api.d.ts.map +1 -0
  136. package/dist/editor/api.js +247 -0
  137. package/dist/editor/api.js.map +1 -0
  138. package/dist/editor/camera.d.ts +18 -0
  139. package/dist/editor/camera.d.ts.map +1 -0
  140. package/dist/editor/camera.js +40 -0
  141. package/dist/editor/camera.js.map +1 -0
  142. package/dist/editor/canvas.d.ts +25 -0
  143. package/dist/editor/canvas.d.ts.map +1 -0
  144. package/dist/editor/canvas.js +35 -0
  145. package/dist/editor/canvas.js.map +1 -0
  146. package/dist/editor/changes/ChangesPage.d.ts +25 -0
  147. package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
  148. package/dist/editor/changes/ChangesPage.js +132 -0
  149. package/dist/editor/changes/ChangesPage.js.map +1 -0
  150. package/dist/editor/changes/changeModel.d.ts +25 -0
  151. package/dist/editor/changes/changeModel.d.ts.map +1 -0
  152. package/dist/editor/changes/changeModel.js +81 -0
  153. package/dist/editor/changes/changeModel.js.map +1 -0
  154. package/dist/editor/changes/changeState.d.mts +29 -0
  155. package/dist/editor/changes/changeState.mjs +187 -0
  156. package/dist/editor/chrome/EditorChrome.d.ts +49 -0
  157. package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
  158. package/dist/editor/chrome/EditorChrome.js +21 -0
  159. package/dist/editor/chrome/EditorChrome.js.map +1 -0
  160. package/dist/editor/drafts.d.ts +46 -0
  161. package/dist/editor/drafts.d.ts.map +1 -0
  162. package/dist/editor/drafts.js +38 -0
  163. package/dist/editor/drafts.js.map +1 -0
  164. package/dist/editor/i18n.d.ts +29 -0
  165. package/dist/editor/i18n.d.ts.map +1 -0
  166. package/dist/editor/i18n.js +2320 -0
  167. package/dist/editor/i18n.js.map +1 -0
  168. package/dist/editor/iconStroke.d.ts +6 -0
  169. package/dist/editor/iconStroke.d.ts.map +1 -0
  170. package/dist/editor/iconStroke.js +6 -0
  171. package/dist/editor/iconStroke.js.map +1 -0
  172. package/dist/editor/main.d.ts +2 -0
  173. package/dist/editor/main.d.ts.map +1 -0
  174. package/dist/editor/main.js +14 -0
  175. package/dist/editor/main.js.map +1 -0
  176. package/dist/editor/model.d.ts +16 -0
  177. package/dist/editor/model.d.ts.map +1 -0
  178. package/dist/editor/model.js +11 -0
  179. package/dist/editor/model.js.map +1 -0
  180. package/dist/editor/reasons.d.ts +44 -0
  181. package/dist/editor/reasons.d.ts.map +1 -0
  182. package/dist/editor/reasons.js +131 -0
  183. package/dist/editor/reasons.js.map +1 -0
  184. package/dist/editor/reviewLifecycle.d.ts +8 -0
  185. package/dist/editor/reviewLifecycle.d.ts.map +1 -0
  186. package/dist/editor/reviewLifecycle.js +21 -0
  187. package/dist/editor/reviewLifecycle.js.map +1 -0
  188. package/dist/editor/styles.css +8737 -0
  189. package/dist/editor/tokenMatch.d.ts +59 -0
  190. package/dist/editor/tokenMatch.d.ts.map +1 -0
  191. package/dist/editor/tokenMatch.js +198 -0
  192. package/dist/editor/tokenMatch.js.map +1 -0
  193. package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
  194. package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
  195. package/dist/editor/tokens/ConsolidatePage.js +244 -0
  196. package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
  197. package/dist/editor/tokens/TokenActivity.d.ts +18 -0
  198. package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
  199. package/dist/editor/tokens/TokenActivity.js +18 -0
  200. package/dist/editor/tokens/TokenActivity.js.map +1 -0
  201. package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
  202. package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
  203. package/dist/editor/tokens/TokenDialogs.js +119 -0
  204. package/dist/editor/tokens/TokenDialogs.js.map +1 -0
  205. package/dist/editor/tokens/TokenList.d.ts +21 -0
  206. package/dist/editor/tokens/TokenList.d.ts.map +1 -0
  207. package/dist/editor/tokens/TokenList.js +98 -0
  208. package/dist/editor/tokens/TokenList.js.map +1 -0
  209. package/dist/editor/tokens/TokenPage.d.ts +25 -0
  210. package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
  211. package/dist/editor/tokens/TokenPage.js +108 -0
  212. package/dist/editor/tokens/TokenPage.js.map +1 -0
  213. package/dist/editor/tokens/tokenModel.d.ts +35 -0
  214. package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
  215. package/dist/editor/tokens/tokenModel.js +72 -0
  216. package/dist/editor/tokens/tokenModel.js.map +1 -0
  217. package/dist/editor/ui/Button.d.ts +3 -0
  218. package/dist/editor/ui/Button.d.ts.map +1 -0
  219. package/dist/editor/ui/Button.js +6 -0
  220. package/dist/editor/ui/Button.js.map +1 -0
  221. package/dist/editor/ui/CommentBox.d.ts +23 -0
  222. package/dist/editor/ui/CommentBox.d.ts.map +1 -0
  223. package/dist/editor/ui/CommentBox.js +41 -0
  224. package/dist/editor/ui/CommentBox.js.map +1 -0
  225. package/dist/editor/ui/Icon.d.ts +8 -0
  226. package/dist/editor/ui/Icon.d.ts.map +1 -0
  227. package/dist/editor/ui/Icon.js +6 -0
  228. package/dist/editor/ui/Icon.js.map +1 -0
  229. package/dist/editor/ui/IconButton.d.ts +11 -0
  230. package/dist/editor/ui/IconButton.d.ts.map +1 -0
  231. package/dist/editor/ui/IconButton.js +6 -0
  232. package/dist/editor/ui/IconButton.js.map +1 -0
  233. package/dist/editor/ui/NumberInput.d.ts +14 -0
  234. package/dist/editor/ui/NumberInput.d.ts.map +1 -0
  235. package/dist/editor/ui/NumberInput.js +6 -0
  236. package/dist/editor/ui/NumberInput.js.map +1 -0
  237. package/dist/editor/ui/PageLine.d.ts +14 -0
  238. package/dist/editor/ui/PageLine.d.ts.map +1 -0
  239. package/dist/editor/ui/PageLine.js +7 -0
  240. package/dist/editor/ui/PageLine.js.map +1 -0
  241. package/dist/editor/ui/SearchPicker.d.ts +41 -0
  242. package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
  243. package/dist/editor/ui/SearchPicker.js +82 -0
  244. package/dist/editor/ui/SearchPicker.js.map +1 -0
  245. package/dist/editor/ui/Select.d.ts +19 -0
  246. package/dist/editor/ui/Select.d.ts.map +1 -0
  247. package/dist/editor/ui/Select.js +12 -0
  248. package/dist/editor/ui/Select.js.map +1 -0
  249. package/dist/editor/ui/TokenField.d.ts +14 -0
  250. package/dist/editor/ui/TokenField.d.ts.map +1 -0
  251. package/dist/editor/ui/TokenField.js +41 -0
  252. package/dist/editor/ui/TokenField.js.map +1 -0
  253. package/dist/editor/ui/TokenPicker.d.ts +31 -0
  254. package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
  255. package/dist/editor/ui/TokenPicker.js +26 -0
  256. package/dist/editor/ui/TokenPicker.js.map +1 -0
  257. package/dist/editor/useBuildError.d.ts +7 -0
  258. package/dist/editor/useBuildError.d.ts.map +1 -0
  259. package/dist/editor/useBuildError.js +30 -0
  260. package/dist/editor/useBuildError.js.map +1 -0
  261. package/dist/editor/useLatestRequest.d.ts +22 -0
  262. package/dist/editor/useLatestRequest.d.ts.map +1 -0
  263. package/dist/editor/useLatestRequest.js +49 -0
  264. package/dist/editor/useLatestRequest.js.map +1 -0
  265. package/dist/editor-bundle/editor.css +2 -0
  266. package/dist/editor-bundle/editor.js +83 -0
  267. package/dist/editor-ui.d.ts +15 -0
  268. package/dist/editor-ui.d.ts.map +1 -0
  269. package/dist/editor-ui.js +14 -0
  270. package/dist/editor-ui.js.map +1 -0
  271. package/dist/inspector/runtime.d.ts +18 -0
  272. package/dist/inspector/runtime.d.ts.map +1 -0
  273. package/dist/inspector/runtime.js +1280 -0
  274. package/dist/inspector/runtime.js.map +1 -0
  275. package/dist/preview/main.d.ts +3 -0
  276. package/dist/preview/main.d.ts.map +1 -0
  277. package/dist/preview/main.js +320 -0
  278. package/dist/preview/main.js.map +1 -0
  279. package/dist/preview/preview.css +40 -0
  280. package/dist/runtime/index.d.ts +3 -0
  281. package/dist/runtime/index.d.ts.map +1 -0
  282. package/dist/runtime/index.js +2 -0
  283. package/dist/runtime/index.js.map +1 -0
  284. package/dist/shared/buildError.d.mts +27 -0
  285. package/dist/shared/buildError.mjs +141 -0
  286. package/dist/shared/cameraFit.d.mts +16 -0
  287. package/dist/shared/cameraFit.mjs +47 -0
  288. package/dist/shared/canvasLayout.d.mts +13 -0
  289. package/dist/shared/canvasLayout.mjs +171 -0
  290. package/dist/shared/commentShots.d.mts +12 -0
  291. package/dist/shared/commentShots.mjs +53 -0
  292. package/dist/shared/componentExtract.d.mts +43 -0
  293. package/dist/shared/componentExtract.mjs +136 -0
  294. package/dist/shared/componentMeta.d.mts +26 -0
  295. package/dist/shared/componentMeta.mjs +87 -0
  296. package/dist/shared/componentOps.d.mts +70 -0
  297. package/dist/shared/componentOps.mjs +407 -0
  298. package/dist/shared/componentTarget.d.mts +15 -0
  299. package/dist/shared/componentTarget.mjs +58 -0
  300. package/dist/shared/components.d.mts +30 -0
  301. package/dist/shared/components.mjs +106 -0
  302. package/dist/shared/consolidateCategories.d.mts +2 -0
  303. package/dist/shared/consolidateCategories.mjs +6 -0
  304. package/dist/shared/env.d.mts +4 -0
  305. package/dist/shared/env.mjs +18 -0
  306. package/dist/shared/gitChanges.d.mts +2 -0
  307. package/dist/shared/gitChanges.mjs +30 -0
  308. package/dist/shared/legacyPaths.d.mts +1 -0
  309. package/dist/shared/legacyPaths.mjs +9 -0
  310. package/dist/shared/oklab.d.mts +6 -0
  311. package/dist/shared/oklab.mjs +56 -0
  312. package/dist/shared/optimizeEntries.d.mts +5 -0
  313. package/dist/shared/optimizeEntries.mjs +24 -0
  314. package/dist/shared/packages.d.mts +11 -0
  315. package/dist/shared/packages.mjs +96 -0
  316. package/dist/shared/projectFiles.d.mts +23 -0
  317. package/dist/shared/projectFiles.mjs +72 -0
  318. package/dist/shared/prompt.d.mts +25 -0
  319. package/dist/shared/prompt.mjs +217 -0
  320. package/dist/shared/proposals.d.mts +11 -0
  321. package/dist/shared/proposals.mjs +42 -0
  322. package/dist/shared/protocol.d.ts +122 -0
  323. package/dist/shared/protocol.d.ts.map +1 -0
  324. package/dist/shared/protocol.js +7 -0
  325. package/dist/shared/protocol.js.map +1 -0
  326. package/dist/shared/reviewArchive.d.mts +4 -0
  327. package/dist/shared/reviewArchive.mjs +19 -0
  328. package/dist/shared/reviewStore.d.mts +30 -0
  329. package/dist/shared/reviewStore.mjs +218 -0
  330. package/dist/shared/reviewVerify.d.mts +21 -0
  331. package/dist/shared/reviewVerify.mjs +158 -0
  332. package/dist/shared/sizeModes.d.mts +15 -0
  333. package/dist/shared/sizeModes.mjs +53 -0
  334. package/dist/shared/sketches.d.mts +10 -0
  335. package/dist/shared/sketches.mjs +64 -0
  336. package/dist/shared/snapshotCheck.d.mts +13 -0
  337. package/dist/shared/snapshotCheck.mjs +81 -0
  338. package/dist/shared/timeout.d.mts +1 -0
  339. package/dist/shared/timeout.mjs +15 -0
  340. package/dist/shared/tokens.d.ts +2 -0
  341. package/dist/shared/tokens.d.ts.map +1 -0
  342. package/dist/shared/tokens.js +2 -0
  343. package/dist/shared/tokens.js.map +1 -0
  344. package/dist/shared/types.d.ts +689 -0
  345. package/dist/shared/types.d.ts.map +1 -0
  346. package/dist/shared/types.js +13 -0
  347. package/dist/shared/types.js.map +1 -0
  348. package/dist/shared/wheelRouting.d.mts +9 -0
  349. package/dist/shared/wheelRouting.mjs +31 -0
  350. package/dist/shared/writeScope.mjs +96 -0
  351. package/dist/snapshots/diff.d.mts +28 -0
  352. package/dist/snapshots/diff.mjs +263 -0
  353. package/dist/snapshots/index.d.mts +110 -0
  354. package/dist/snapshots/index.mjs +638 -0
  355. package/dist/snapshots/render.d.mts +24 -0
  356. package/dist/snapshots/render.mjs +250 -0
  357. package/dist/snapshots/toolOps.d.mts +25 -0
  358. package/dist/snapshots/toolOps.mjs +69 -0
  359. package/dist/tokens/adapters/css.mjs +51 -0
  360. package/dist/tokens/adapters/cssInCode.mjs +314 -0
  361. package/dist/tokens/adapters/oxcShared.mjs +80 -0
  362. package/dist/tokens/adapters/preprocessor.mjs +63 -0
  363. package/dist/tokens/adapters/registry.mjs +53 -0
  364. package/dist/tokens/adapters/tailwindcss.mjs +424 -0
  365. package/dist/tokens/adapters/types.mjs +117 -0
  366. package/dist/tokens/consolidate/index.d.mts +42 -0
  367. package/dist/tokens/consolidate/index.mjs +111 -0
  368. package/dist/tokens/consolidate/normalize.mjs +479 -0
  369. package/dist/tokens/consolidate/plan.mjs +726 -0
  370. package/dist/tokens/consolidate/scan.mjs +928 -0
  371. package/dist/tokens/extract.mjs +441 -0
  372. package/dist/tokens/moduleData.d.mts +14 -0
  373. package/dist/tokens/moduleData.mjs +32 -0
  374. package/dist/tokens/opLock.d.mts +4 -0
  375. package/dist/tokens/opLock.mjs +108 -0
  376. package/dist/tokens/ops.d.mts +71 -0
  377. package/dist/tokens/ops.mjs +1511 -0
  378. package/dist/tokens/pipeline.mjs +813 -0
  379. package/dist/tokens/report.d.mts +47 -0
  380. package/dist/tokens/report.mjs +257 -0
  381. package/dist/tokens/rewrite/code.mjs +172 -0
  382. package/dist/tokens/rewrite/css.mjs +154 -0
  383. package/dist/tokens/rewrite/index.mjs +244 -0
  384. package/dist/tokens/rewrite/tailwind.mjs +288 -0
  385. package/dist/tokens/rewrite/text.mjs +116 -0
  386. package/dist/tokens/rewrite/value.mjs +115 -0
  387. package/dist/tokens/usage.d.mts +97 -0
  388. package/dist/tokens/usage.mjs +680 -0
  389. package/dist/vite/agent.d.ts +21 -0
  390. package/dist/vite/agent.d.ts.map +1 -0
  391. package/dist/vite/agent.js +165 -0
  392. package/dist/vite/agent.js.map +1 -0
  393. package/dist/vite/events.d.ts +27 -0
  394. package/dist/vite/events.d.ts.map +1 -0
  395. package/dist/vite/events.js +156 -0
  396. package/dist/vite/events.js.map +1 -0
  397. package/dist/vite/layout.d.ts +2 -0
  398. package/dist/vite/layout.d.ts.map +1 -0
  399. package/dist/vite/layout.js +4 -0
  400. package/dist/vite/layout.js.map +1 -0
  401. package/dist/vite/plugin.d.ts +40 -0
  402. package/dist/vite/plugin.d.ts.map +1 -0
  403. package/dist/vite/plugin.js +1264 -0
  404. package/dist/vite/plugin.js.map +1 -0
  405. package/dist/vite/requestGuard.d.mts +3 -0
  406. package/dist/vite/requestGuard.mjs +43 -0
  407. package/dist/vite/review.d.ts +11 -0
  408. package/dist/vite/review.d.ts.map +1 -0
  409. package/dist/vite/review.js +283 -0
  410. package/dist/vite/review.js.map +1 -0
  411. package/package.json +106 -1
  412. package/skills/seji/SKILL.md +400 -0
  413. package/skills/seji-authoring/SKILL.md +397 -0
  414. package/skills/seji-tokens/SKILL.md +432 -0
@@ -0,0 +1,928 @@
1
+ // `consolidate scan`: find hard-coded style values and the tokens in use inside a scope, cluster
2
+ // near-identical values per category, and propose one action per cluster:
3
+ // reuse — an existing token has this value (exactly, or within the tolerance: marked as a
4
+ // visible change with its delta);
5
+ // create — no token is close; a new token is needed. The NAME is not invented here: the row
6
+ // carries naming hints (the project's prefixes per tier) for the agent / user;
7
+ // merge — several independently defined tokens hold the same value;
8
+ // keep — tokens only, nothing to do.
9
+ // Colors cluster only within one hue family (shared/oklab.mjs: a tint never joins a gray, a red
10
+ // tint never a violet one). A row whose proposal changes the rendering is `undecided`: nothing
11
+ // is pre-selected, a human picks, and `apply` refuses undecided rows.
12
+ // Everything is located through ASTs (postcss for stylesheets, @babel/parser for code via the
13
+ // token adapters' walkers, the Tailwind class splitter); file text is never searched.
14
+ import { readFileSync } from 'node:fs'
15
+ import { relative, sep } from 'node:path'
16
+
17
+ import valueParser from 'postcss-value-parser'
18
+
19
+ import { walkCssInCode } from '../adapters/cssInCode.mjs'
20
+ import { walkTailwindClasses } from '../adapters/tailwindcss.mjs'
21
+ import { createLineIndex } from '../adapters/types.mjs'
22
+ import { loadTokenConfig, readTokenRecords, resolveRecords, scanFiles } from '../pipeline.mjs'
23
+ import { writeScope } from '../../shared/writeScope.mjs'
24
+ import { stringInner } from '../rewrite/code.mjs'
25
+ import { cssSyntaxOf, parseStylesheet } from '../rewrite/css.mjs'
26
+ import { buildThemeUtilityIndex, groupSegments, parseClassToken } from '../rewrite/tailwind.mjs'
27
+ import { splitClassesWithOffsets } from '../rewrite/text.mjs'
28
+ import {
29
+ CATEGORIES,
30
+ DEFAULT_CATEGORIES,
31
+ DEFAULT_TOLERANCE,
32
+ categoryOfProperty,
33
+ colorOfNode,
34
+ deltaOf,
35
+ LENGTH_CATEGORIES,
36
+ unitKind,
37
+ normalizeValue,
38
+ shorthandCategories,
39
+ utilitiesOf,
40
+ valueDistance,
41
+ } from './normalize.mjs'
42
+
43
+ // Keywords valid in color properties that are not consolidated.
44
+ const COLOR_WORDS = new Set(['transparent', 'currentcolor', 'inherit', 'initial', 'unset', 'revert', 'revert-layer', 'none'])
45
+ const CODE_EXT = /\.(?:tsx|jsx|ts|js|mts|cts|mjs|cjs)$/i
46
+ const TIER_RANK = { semantic: 0, component: 1, primitive: 2 }
47
+ const toPosix = (file) => file.split(sep).join('/')
48
+ const lower = (value) => String(value ?? '').trim().toLowerCase()
49
+
50
+ export class ConsolidateError extends Error {
51
+ constructor(message, details) {
52
+ super(message)
53
+ this.name = 'ConsolidateError'
54
+ if (details) this.details = details
55
+ }
56
+ }
57
+
58
+ // ---------------------------------------------------------------------------------------
59
+ // Scope
60
+
61
+ /** `**` / `*` / `?` / `{a,b}` glob → RegExp over root-relative posix paths. */
62
+ export function globToRegExp(glob) {
63
+ let out = ''
64
+ let i = 0
65
+ let braces = 0
66
+ while (i < glob.length) {
67
+ const ch = glob[i]
68
+ if (ch === '*') {
69
+ if (glob[i + 1] === '*') {
70
+ const slash = glob[i + 2] === '/'
71
+ out += slash ? '(?:.*/)?' : '.*'
72
+ i += slash ? 3 : 2
73
+ continue
74
+ }
75
+ out += '[^/]*'
76
+ } else if (ch === '?') out += '[^/]'
77
+ else if (ch === '{') {
78
+ braces += 1
79
+ out += '(?:'
80
+ } else if (ch === '}' && braces) {
81
+ braces -= 1
82
+ out += ')'
83
+ } else if (ch === ',' && braces) out += '|'
84
+ else out += ch.replace(/[.+^$()|[\]\\]/g, '\\$&')
85
+ i += 1
86
+ }
87
+ return new RegExp(`^${out}$`)
88
+ }
89
+
90
+ /** A scope matcher for root-relative posix paths; no scopes = everything. */
91
+ export function scopeMatcher(scopes) {
92
+ const list = (scopes ?? []).map((scope) => toPosix(String(scope)).trim()).filter(Boolean)
93
+ if (!list.length) return () => true
94
+ const tests = list.map((scope) => {
95
+ const clean = scope.replace(/^\.\//, '').replace(/\/$/, '')
96
+ if (/[*?{]/.test(clean)) {
97
+ const re = globToRegExp(clean)
98
+ return (file) => re.test(file)
99
+ }
100
+ return (file) => file === clean || file.startsWith(`${clean}/`)
101
+ })
102
+ return (file) => tests.some((test) => test(file))
103
+ }
104
+
105
+ // ---------------------------------------------------------------------------------------
106
+ // Token categories
107
+
108
+ const PATH_CATEGORY = [
109
+ [/(^|[.-])(radius|rounded|corner)s?($|[.-])/, 'radius'],
110
+ [/(^|[.-])(font-size|text-size|fontsize)($|[.-])/, 'font-size'],
111
+ [/^(text|font-size|type)\./, 'font-size'],
112
+ [/(^|[.-])(font-weight|weight)($|[.-])/, 'font-weight'],
113
+ [/(^|[.-])(line-height|leading)($|[.-])/, 'line-height'],
114
+ [/(^|[.-])(border-width|stroke-width|outline-width)($|[.-])/, 'border-width'],
115
+ [/(^|[.-])(space|spacing|gap|gutter|padding|margin|inset)s?($|[.-])/, 'spacing'],
116
+ [/(^|[.-])(shadow|elevation)s?($|[.-])/, 'shadow'],
117
+ [/(^|[.-])(width|height|size)($|[.-])/, 'size'],
118
+ ]
119
+
120
+ /** Category of a token record: its type, then its path, then how code uses it. */
121
+ function tokenCategory(record, refCategories) {
122
+ if (record.dtcgType === 'color') return 'color'
123
+ if (record.dtcgType === 'shadow') return 'shadow'
124
+ if (record.dtcgType === 'fontWeight') return 'font-weight'
125
+ const key = record.path.join('.').toLowerCase()
126
+ if (record.dtcgType === 'dimension' || record.dtcgType === 'number' || record.dtcgType === 'string') {
127
+ for (const [re, category] of PATH_CATEGORY) if (re.test(key)) return category
128
+ }
129
+ const counts = refCategories?.get(record.cssName)
130
+ if (counts?.size) return [...counts.entries()].sort((a, b) => b[1] - a[1])[0][0]
131
+ if (record.dtcgType === 'string' && normalizeValue('color', record.value)) return 'color'
132
+ return null
133
+ }
134
+
135
+ /** Follow DTCG aliases to the token that holds the value. */
136
+ function rootOf(record, byPath) {
137
+ let current = record
138
+ const seen = new Set()
139
+ while (current.alias && byPath.has(current.alias) && !seen.has(current.alias)) {
140
+ seen.add(current.alias)
141
+ current = byPath.get(current.alias)
142
+ }
143
+ return current
144
+ }
145
+
146
+ // ---------------------------------------------------------------------------------------
147
+ // Occurrences
148
+
149
+ function significant(nodes) {
150
+ return nodes.filter((node) => node.type !== 'space' && node.type !== 'comment')
151
+ }
152
+
153
+ /** Literal nodes of `category` anywhere in `nodes` (not inside var()/url()). */
154
+ function nestedLiterals(nodes, category, options, out = []) {
155
+ for (const node of nodes) {
156
+ if (node.type === 'function') {
157
+ const name = node.value.toLowerCase()
158
+ if (name === 'var' || name === 'url' || name === 'env') continue
159
+ if (category === 'color' && colorOfNode(node)) {
160
+ out.push({ node, normalized: colorOfNode(node) })
161
+ continue
162
+ }
163
+ nestedLiterals(node.nodes ?? [], category, options, out)
164
+ continue
165
+ }
166
+ if (node.type !== 'word') continue
167
+ const normalized = category === 'color' ? colorOfNode(node) : normalizeValue(category, node.value, options)
168
+ if (normalized) out.push({ node, normalized })
169
+ }
170
+ return out
171
+ }
172
+
173
+ function varNames(nodes, out = []) {
174
+ for (const node of nodes) {
175
+ if (node.type !== 'function') continue
176
+ if (node.value.toLowerCase() === 'var') {
177
+ const first = (node.nodes ?? []).find((child) => child.type === 'word')
178
+ if (first?.value.startsWith('--')) out.push(first.value)
179
+ }
180
+ varNames(node.nodes ?? [], out)
181
+ }
182
+ return out
183
+ }
184
+
185
+ /**
186
+ * Collect literal occurrences and token references from one value. `sink.occurrence(entry)`
187
+ * and `sink.tokenRef(name, property)`; `base` holds file / line / column / scheme / property.
188
+ */
189
+ function analyzeValue(value, base, categories, options, sink) {
190
+ let parsed
191
+ try {
192
+ parsed = valueParser(String(value))
193
+ } catch {
194
+ return
195
+ }
196
+ for (const name of varNames(parsed.nodes)) sink.tokenRef(name, base.property)
197
+ const property = lower(base.property)
198
+ const category = categoryOfProperty(property)
199
+ const nodes = significant(parsed.nodes)
200
+ if (category && categories.has(category)) {
201
+ if (category === 'shadow') {
202
+ const normalized = normalizeValue('shadow', value, options)
203
+ const text = valueParser.stringify(parsed.nodes).trim()
204
+ if (normalized) sink.occurrence({ ...base, category, text, canonical: normalized.canonical, normalized, replaceable: true })
205
+ else if (!varNames(parsed.nodes).length && text && !/^(none|inherit|initial|unset)$/i.test(text)) {
206
+ sink.unclustered({ ...base, category, text, reason: 'computed-value' })
207
+ }
208
+ return
209
+ }
210
+ if (nodes.length === 1) {
211
+ const node = nodes[0]
212
+ const text = valueParser.stringify(node)
213
+ const normalized = category === 'color' ? colorOfNode(node) : node.type === 'word' ? normalizeValue(category, node.value, options) : null
214
+ if (normalized) {
215
+ sink.occurrence({ ...base, category, text, canonical: normalized.canonical, normalized, replaceable: true })
216
+ return
217
+ }
218
+ // A word in a color property that is no color we know (a typo, a system color): reported.
219
+ if (category === 'color' && node.type === 'word' && /^[a-z]+$/i.test(node.value) && !COLOR_WORDS.has(node.value.toLowerCase())) {
220
+ sink.unclustered({ ...base, category, text, reason: 'unrecognized-color' })
221
+ return
222
+ }
223
+ if (node.type === 'function' && !['var', 'env', 'url', 'image-set'].includes(node.value.toLowerCase())) {
224
+ const inner = nestedLiterals(node.nodes ?? [], category, options)
225
+ if (!inner.length && !varNames([node]).length) sink.unclustered({ ...base, category, text, reason: 'computed-value' })
226
+ for (const entry of inner) {
227
+ const literal = valueParser.stringify(entry.node)
228
+ sink.occurrence({ ...base, category, text: literal, canonical: entry.normalized.canonical, normalized: entry.normalized, replaceable: false, reason: 'mixed-value' })
229
+ }
230
+ }
231
+ return
232
+ }
233
+ for (const entry of nestedLiterals(nodes, category, options)) {
234
+ const literal = valueParser.stringify(entry.node)
235
+ sink.occurrence({ ...base, category, text: literal, canonical: entry.normalized.canonical, normalized: entry.normalized, replaceable: false, reason: 'mixed-value' })
236
+ }
237
+ return
238
+ }
239
+ for (const other of shorthandCategories(property)) {
240
+ if (!categories.has(other)) continue
241
+ for (const entry of nestedLiterals(nodes, other, options)) {
242
+ // A bare number inside `font` is not a weight we can tell from a line-height.
243
+ if (other !== 'color' && entry.normalized.unit === '' && other !== 'font-weight') continue
244
+ const literal = valueParser.stringify(entry.node)
245
+ sink.occurrence({ ...base, category: other, text: literal, canonical: entry.normalized.canonical, normalized: entry.normalized, replaceable: false, reason: 'shorthand' })
246
+ }
247
+ }
248
+ }
249
+
250
+ /** Category of a Tailwind arbitrary value for `utility`, or null. */
251
+ function utilityCategory(utility, value, categories, options) {
252
+ const tries = []
253
+ for (const category of CATEGORIES) {
254
+ if (!categories.has(category) || !utilitiesOf(category).includes(utility)) continue
255
+ const normalized = normalizeValue(category, value, options)
256
+ if (normalized) tries.push({ category, normalized })
257
+ }
258
+ // `text-[#fff]` is a color, `text-[13px]` a font size; a color always wins over a length.
259
+ return tries.find((entry) => entry.category === 'color') ?? tries[0] ?? null
260
+ }
261
+
262
+ function analyzeClassList(raw, at, locationAt, base, categories, options, themeIndex, sink) {
263
+ for (const entry of splitClassesWithOffsets(raw)) {
264
+ const token = entry.value
265
+ const parsed = parseClassToken(token)
266
+ const { base: classBase, baseStart } = parsed
267
+ const segments = groupSegments(classBase)
268
+ const loc = locationAt(at + entry.start + baseStart)
269
+ if (!segments.length) {
270
+ for (const hit of themeIndex?.get(classBase) ?? []) sink.tokenRef(hit.token, hit.utility)
271
+ continue
272
+ }
273
+ if (segments.length !== 1) continue
274
+ const segment = segments[0]
275
+ const inner = classBase.slice(segment.innerStart, segment.innerEnd)
276
+ const prefix = classBase.slice(0, segment.innerStart - 1)
277
+ const utility = prefix.endsWith('-') ? prefix.slice(0, -1) : ''
278
+ if (segment.kind === '(') {
279
+ const name = inner.slice(inner.indexOf('--'))
280
+ if (name.startsWith('--')) sink.tokenRef(name, utility)
281
+ continue
282
+ }
283
+ const typed = /^[a-z-]+:/i.exec(inner)
284
+ const valueText = (typed ? inner.slice(typed[0].length) : inner).split('_').join(' ')
285
+ if (/^var\(/i.test(valueText.trim()) || valueText.trim().startsWith('--')) {
286
+ let parsedValue
287
+ try {
288
+ parsedValue = valueParser(valueText)
289
+ } catch {
290
+ continue
291
+ }
292
+ for (const name of varNames(parsedValue.nodes)) sink.tokenRef(name, utility)
293
+ if (valueText.trim().startsWith('--')) sink.tokenRef(valueText.trim(), utility)
294
+ continue
295
+ }
296
+ if (!utility) continue
297
+ const hit = utilityCategory(utility, valueText, categories, options)
298
+ if (!hit) continue
299
+ const whole = segment.innerEnd === classBase.length - 1
300
+ const reason = typed ? 'typed-arbitrary-value' : parsed.negative ? 'needs-judgment' : !whole ? 'mixed-value' : null
301
+ sink.occurrence({
302
+ ...base,
303
+ ...loc,
304
+ category: hit.category,
305
+ property: utility,
306
+ scheme: 'tailwind',
307
+ text: inner,
308
+ canonical: hit.normalized.canonical,
309
+ normalized: hit.normalized,
310
+ replaceable: !reason,
311
+ ...(reason ? { reason } : {}),
312
+ })
313
+ }
314
+ }
315
+
316
+ /** Every literal occurrence and token reference in `files` (absolute) of the given categories. */
317
+ export async function collectOccurrences({ root, files, categories, options = {}, tokenNames = [], theme = false, outside = new Set() }) {
318
+ const occurrences = []
319
+ const unclustered = []
320
+ const tokenRefs = []
321
+ const unsupported = []
322
+ const themeIndex = theme ? buildThemeUtilityIndex(tokenNames) : null
323
+ for (const abs of files) {
324
+ const file = toPosix(relative(root, abs))
325
+ let content
326
+ try {
327
+ content = readFileSync(abs, 'utf8')
328
+ } catch {
329
+ continue
330
+ }
331
+ const isOutside = outside.has(abs)
332
+ const sink = {
333
+ occurrence(entry) {
334
+ const { normalized, ...rest } = entry
335
+ const out = { ...rest }
336
+ if (normalized?.converted) out.converted = normalized.converted
337
+ if (isOutside) {
338
+ out.replaceable = false
339
+ out.reason = 'outside-project-root'
340
+ }
341
+ occurrences.push(out)
342
+ },
343
+ tokenRef(token, property) {
344
+ tokenRefs.push({ token, property, file })
345
+ },
346
+ unclustered(entry) {
347
+ unclustered.push(entry)
348
+ },
349
+ }
350
+ if (cssSyntaxOf(file)) {
351
+ const parsed = await parseStylesheet(file, content).catch((error) => ({ unsupported: `parse-error: ${error?.message?.split('\n')[0]}` }))
352
+ if (!parsed.root) {
353
+ unsupported.push({ file, reason: parsed.unsupported })
354
+ continue
355
+ }
356
+ parsed.root.walkDecls((decl) => {
357
+ if (decl.prop.startsWith('--')) {
358
+ // Local custom properties (definitions) are not consolidated; their var() uses count.
359
+ let refs
360
+ try {
361
+ refs = varNames(valueParser(decl.value).nodes)
362
+ } catch {
363
+ refs = []
364
+ }
365
+ for (const name of refs) sink.tokenRef(name, decl.prop)
366
+ return
367
+ }
368
+ const base = {
369
+ file,
370
+ line: decl.source?.start?.line ?? 1,
371
+ column: decl.source?.start?.column ?? 1,
372
+ property: decl.prop.toLowerCase(),
373
+ scheme: 'css',
374
+ }
375
+ analyzeValue(decl.value, base, categories, options, sink)
376
+ })
377
+ continue
378
+ }
379
+ if (!CODE_EXT.test(file)) continue
380
+ const locationAt = createLineIndex(content)
381
+ const ctx = { parseCache: new Map() }
382
+ walkCssInCode(file, content, ctx, {
383
+ onString(node, value, property) {
384
+ if (!property) return
385
+ const loc = locationAt(node.start)
386
+ const base = { file, ...loc, property, scheme: 'css-in-code' }
387
+ if (!stringInner(content, node)) {
388
+ const probe = []
389
+ analyzeValue(value, base, categories, options, { ...sink, occurrence: (entry) => probe.push(entry) })
390
+ for (const entry of probe) sink.occurrence({ ...entry, replaceable: false, reason: 'escaped-string' })
391
+ return
392
+ }
393
+ analyzeValue(value, base, categories, options, sink)
394
+ },
395
+ onUnsupported() {},
396
+ })
397
+ walkTailwindClasses(file, content, ctx, {
398
+ onClassString(node, value) {
399
+ const inner = stringInner(content, node)
400
+ const base = { file, scheme: 'tailwind' }
401
+ if (!inner) {
402
+ const probe = []
403
+ analyzeClassList(value, node.start, () => locationAt(node.start), base, categories, options, themeIndex, {
404
+ ...sink,
405
+ occurrence: (entry) => probe.push(entry),
406
+ })
407
+ for (const entry of probe) sink.occurrence({ ...entry, replaceable: false, reason: 'escaped-string' })
408
+ return
409
+ }
410
+ analyzeClassList(inner.text, inner.at, locationAt, base, categories, options, themeIndex, sink)
411
+ },
412
+ onUnsupported() {},
413
+ })
414
+ }
415
+ return { occurrences, unclustered, tokenRefs, unsupported }
416
+ }
417
+
418
+ // ---------------------------------------------------------------------------------------
419
+ // Context, clustering, suggestions
420
+
421
+ /** Records, scope files and options for a scan (read-only). */
422
+ export function loadScanContext(
423
+ root,
424
+ { scope, categories, tolerance, rootPx, config: givenConfig, records: givenRecords, writable: givenWritable } = {},
425
+ ) {
426
+ const options = normalizeOptions({ scope, categories, tolerance, rootPx })
427
+ const config = givenConfig ?? loadTokenConfig(root)
428
+ // The one write scope of the tools (shared/writeScope.mjs): what apply may rewrite.
429
+ const writable = givenWritable ?? writeScope(root, { writableDirs: config.writableDirs })
430
+ let records = givenRecords
431
+ if (!records) {
432
+ records = readTokenRecords(root, config.tokenDir).records
433
+ resolveRecords(records)
434
+ }
435
+ scope = options.scope
436
+ const inScope = scopeMatcher(scope)
437
+ const all = scanFiles(root, config)
438
+ const files = []
439
+ const outside = new Set()
440
+ for (const abs of all) {
441
+ const rel = toPosix(relative(root, abs))
442
+ const inside = writable.isWritable(abs)
443
+ // Without a scope only the files the tools may write are scanned; other scanDirs (shared
444
+ // sources outside the root, not listed in writableDirs) are included only when a scope
445
+ // names them, and only reported.
446
+ if (!scope?.length && !inside) continue
447
+ if (!inScope(rel)) continue
448
+ files.push(abs)
449
+ if (!inside) outside.add(abs)
450
+ }
451
+ return {
452
+ root,
453
+ config,
454
+ records,
455
+ files,
456
+ outside,
457
+ theme: config.cssFormat === 'theme',
458
+ options,
459
+ }
460
+ }
461
+
462
+ export function normalizeOptions({ scope, categories, tolerance, rootPx } = {}) {
463
+ const list = (value) => (Array.isArray(value) ? value : value === undefined || value === null || value === '' ? [] : [value])
464
+ .flatMap((entry) => String(entry).split(','))
465
+ .map((entry) => entry.trim())
466
+ .filter(Boolean)
467
+ const cats = list(categories)
468
+ for (const category of cats) {
469
+ if (!CATEGORIES.includes(category)) throw new ConsolidateError(`unknown category: ${category} (expected ${CATEGORIES.join(', ')})`, { code: 'invalid-args' })
470
+ }
471
+ const tol = { ...DEFAULT_TOLERANCE }
472
+ if (tolerance !== undefined && tolerance !== null && tolerance !== '') {
473
+ if (typeof tolerance === 'object') {
474
+ for (const [key, value] of Object.entries(tolerance)) {
475
+ if (!CATEGORIES.includes(key) || !(Number(value) >= 0)) throw new ConsolidateError(`invalid tolerance for ${key}: ${value}`, { code: 'invalid-args' })
476
+ tol[key] = Number(value)
477
+ }
478
+ } else {
479
+ const number = Number(tolerance)
480
+ if (!(number >= 0)) throw new ConsolidateError(`--tolerance must be a number ≥ 0, not ${tolerance}`, { code: 'invalid-args' })
481
+ for (const category of cats.length ? cats : DEFAULT_CATEGORIES) tol[category] = number
482
+ }
483
+ }
484
+ const px = rootPx === undefined || rootPx === null || rootPx === '' ? 16 : Number(rootPx)
485
+ if (!(px > 0)) throw new ConsolidateError(`--root-px must be a positive number, not ${rootPx}`, { code: 'invalid-args' })
486
+ return { scope: list(scope), categories: cats.length ? cats : [...DEFAULT_CATEGORIES], tolerance: tol, rootPx: px }
487
+ }
488
+
489
+ function namingHints(category, records, catOf) {
490
+ const tiers = {}
491
+ for (const record of records) {
492
+ if (record.deprecated !== undefined || catOf.get(record.cssName) !== category) continue
493
+ const tier = (tiers[record.tier] ??= new Map())
494
+ const prefix = record.path.length > 1 ? record.path[0] : ''
495
+ const entry = tier.get(prefix) ?? { prefix, count: 0, examples: [] }
496
+ entry.count += 1
497
+ if (entry.examples.length < 4) entry.examples.push(record.path.join('.'))
498
+ tier.set(prefix, entry)
499
+ }
500
+ const out = {}
501
+ for (const [tier, map] of Object.entries(tiers)) {
502
+ out[tier] = [...map.values()].sort((a, b) => b.count - a.count || a.prefix.localeCompare(b.prefix))
503
+ }
504
+ return {
505
+ required: true,
506
+ tiers: out,
507
+ rule:
508
+ 'Name it with an existing prefix of the tier you choose (primitive = raw values, e.g. color.*; semantic = roles, e.g. chrome.*, usually aliasing a primitive). Tier and $description are required; the tool never invents the name.',
509
+ }
510
+ }
511
+
512
+ const tokenSort = (a, b) =>
513
+ a.distance - b.distance ||
514
+ (TIER_RANK[a.tier] ?? 9) - (TIER_RANK[b.tier] ?? 9) ||
515
+ b.scopeRefs - a.scopeRefs ||
516
+ b.totalRefs - a.totalRefs ||
517
+ a.path.localeCompare(b.path)
518
+
519
+ const recordFor = (byPath, ref) => {
520
+ const name = String(ref ?? '').trim()
521
+ if (!name) return null
522
+ return byPath.get(name) ?? [...byPath.values()].find((entry) => entry.cssName === name || entry.cssName === `--${name}`) ?? null
523
+ }
524
+
525
+ /** Comparison key of a written value: canonical + written unit (for lengths). */
526
+ const keyOf = (category, normalized, text) => `${normalized.canonical}|${unitKind(category, text)}`
527
+
528
+ /** A target `{ normalized, kind, text, key }` for the written value `text` (null when not a value of the category). */
529
+ export function targetFromValue(category, text, options, byPath) {
530
+ let value = String(text ?? '').trim()
531
+ const alias = /^\{([^}]+)\}$/.exec(value)?.[1]
532
+ if (alias) {
533
+ const record = byPath ? recordFor(byPath, alias) : null
534
+ if (!record) return null
535
+ value = record.value
536
+ }
537
+ const normalized = normalizeValue(category, value, options)
538
+ if (!normalized) return null
539
+ return { normalized, text: value, kind: unitKind(category, value), key: keyOf(category, normalized, value) }
540
+ }
541
+
542
+ /**
543
+ * What changes on screen if the replaceable `occurrences` and the `mergeTokens` take `target`:
544
+ * a different canonical value (with its delta), a different written unit (rem follows the root
545
+ * font size, px does not), or a color outside sRGB compared after clipping. Merge tokens are
546
+ * resolved through the current records (`byPath`), not the row.
547
+ */
548
+ export function visibleChangesFor({ category, occurrences, target, mergeTokens = [], byPath, options }) {
549
+ if (!target) return []
550
+ const groups = new Map()
551
+ for (const occurrence of occurrences) {
552
+ if (!occurrence.replaceable) continue
553
+ const text = String(occurrence.text).split('_').join(' ')
554
+ const from = normalizeValue(category, text, options)
555
+ const key = from ? keyOf(category, from, text) : `${occurrence.value}|?`
556
+ if (key === target.key) continue
557
+ const group = groups.get(key)
558
+ if (group) {
559
+ group.occurrences += 1
560
+ continue
561
+ }
562
+ const kind = unitKind(category, text)
563
+ const delta = from ? deltaOf(category, from, target.normalized) : { different: true }
564
+ if (kind !== target.kind) delta.unit = `${kind || 'unitless'} → ${target.kind || 'unitless'}`
565
+ groups.set(key, { key, from: LENGTH_CATEGORIES.has(category) ? text.toLowerCase() : from?.canonical ?? text, to: target.text, occurrences: 1, delta })
566
+ }
567
+ const changes = [...groups.values()]
568
+ for (const name of mergeTokens) {
569
+ const record = byPath ? recordFor(byPath, name) : null
570
+ const path = record ? record.path.join('.') : String(name)
571
+ const from = record ? normalizeValue(category, record.value, options) : null
572
+ const key = from ? keyOf(category, from, record.value) : '?'
573
+ if (key === target.key) continue
574
+ const delta = from ? deltaOf(category, from, target.normalized) : { different: true, reason: record ? `${record.value} is not a ${category} value` : 'unknown token' }
575
+ if (from && unitKind(category, record.value) !== target.kind) delta.unit = `${unitKind(category, record.value) || 'unitless'} → ${target.kind || 'unitless'}`
576
+ changes.push({ token: path, key, from: record?.value ?? '?', to: target.text, delta })
577
+ }
578
+ return changes
579
+ }
580
+
581
+ /** Stable identity of a visible change, for binding an acceptance to what was accepted. */
582
+ export const changeSignature = (change, target) => `${change.token ?? ''}:${change.key}->${target?.key ?? change.to}`
583
+
584
+ /**
585
+ * Scan `root`. Returns `{ options, counts, rows, unclustered, unsupported }`; each row is one
586
+ * cluster with its suggestion. Pure read: nothing is written.
587
+ */
588
+ export async function scanConsolidation({ root = process.cwd(), scope, categories, tolerance, rootPx, context } = {}) {
589
+ const ctx = context ?? loadScanContext(root, { scope, categories, tolerance, rootPx })
590
+ const { options, records } = ctx
591
+ const categorySet = new Set(options.categories)
592
+ const byPath = new Map(records.map((record) => [record.path.join('.'), record]))
593
+ const byCss = new Map(records.map((record) => [record.cssName, record]))
594
+ const normalizeOptions = { rootPx: options.rootPx }
595
+ const collected = await collectOccurrences({
596
+ root: ctx.root,
597
+ files: ctx.files,
598
+ categories: categorySet,
599
+ options: normalizeOptions,
600
+ tokenNames: records.map((record) => record.cssName),
601
+ theme: ctx.theme,
602
+ outside: ctx.outside,
603
+ })
604
+
605
+ // How code uses each token in scope (and the property categories, to classify dimensions).
606
+ const scopeRefs = new Map()
607
+ const refCategories = new Map()
608
+ for (const ref of collected.tokenRefs) {
609
+ if (!byCss.has(ref.token)) continue
610
+ scopeRefs.set(ref.token, (scopeRefs.get(ref.token) ?? 0) + 1)
611
+ const category = categoryOfProperty(lower(ref.property)) ?? CATEGORIES.find((entry) => utilitiesOf(entry).includes(ref.property) && entry !== 'color')
612
+ if (category) {
613
+ const counts = refCategories.get(ref.token) ?? new Map()
614
+ counts.set(category, (counts.get(category) ?? 0) + 1)
615
+ refCategories.set(ref.token, counts)
616
+ }
617
+ }
618
+ // Total references (whole project) for ranking: tokens used by tokens or code anywhere.
619
+ const totalRefs = new Map()
620
+ for (const record of records) {
621
+ if (record.alias) totalRefs.set(byPath.get(record.alias)?.cssName, (totalRefs.get(byPath.get(record.alias)?.cssName) ?? 0) + 1)
622
+ }
623
+ for (const [name, count] of scopeRefs) totalRefs.set(name, (totalRefs.get(name) ?? 0) + count)
624
+
625
+ const catOf = new Map(records.map((record) => [record.cssName, tokenCategory(record, refCategories)]))
626
+ const rows = []
627
+ for (const category of options.categories) {
628
+ const tol = options.tolerance[category] ?? 0
629
+ const clusters = []
630
+ const nearest = (normalized) => {
631
+ let best = null
632
+ for (const cluster of clusters) {
633
+ const distance = valueDistance(category, cluster.anchor, normalized)
634
+ if (distance <= tol && (!best || distance < best.distance)) best = { cluster, distance }
635
+ }
636
+ return best
637
+ }
638
+ // Tokens anchor clusters first (a cluster ideally maps to one token), then literals join.
639
+ const tokens = records
640
+ .filter((record) => catOf.get(record.cssName) === category)
641
+ .map((record) => ({ record, normalized: normalizeValue(category, record.value, normalizeOptions) }))
642
+ .filter((entry) => entry.normalized)
643
+ .sort((a, b) => (TIER_RANK[b.record.tier] ?? 9) - (TIER_RANK[a.record.tier] ?? 9) || a.record.path.join('.').localeCompare(b.record.path.join('.')))
644
+ for (const entry of tokens) {
645
+ const hit = nearest(entry.normalized)
646
+ if (hit) hit.cluster.tokens.push(entry)
647
+ else clusters.push({ anchor: entry.normalized, tokens: [entry], literals: new Map() })
648
+ }
649
+ const literalGroups = new Map()
650
+ for (const occurrence of collected.occurrences) {
651
+ if (occurrence.category !== category) continue
652
+ const group = literalGroups.get(occurrence.canonical) ?? { canonical: occurrence.canonical, occurrences: [] }
653
+ group.occurrences.push(occurrence)
654
+ literalGroups.set(occurrence.canonical, group)
655
+ }
656
+ const sortedGroups = [...literalGroups.values()].sort((a, b) => b.occurrences.length - a.occurrences.length || a.canonical.localeCompare(b.canonical))
657
+ for (const group of sortedGroups) {
658
+ const normalized = normalizeValue(category, group.occurrences[0].text.split('_').join(' '), normalizeOptions)
659
+ const hit = normalized ? nearest(normalized) : null
660
+ if (hit) hit.cluster.literals.set(group.canonical, group)
661
+ else clusters.push({ anchor: normalized ?? { canonical: group.canonical }, tokens: [], literals: new Map([[group.canonical, group]]), literalAnchor: true })
662
+ }
663
+
664
+ for (const cluster of clusters) {
665
+ const occurrences = [...cluster.literals.values()].flatMap((group) => group.occurrences)
666
+ const inScopeTokens = cluster.tokens.filter((entry) => scopeRefs.has(entry.record.cssName))
667
+ if (!occurrences.length && !inScopeTokens.length) continue
668
+ const tokenEntries = cluster.tokens
669
+ .map(({ record, normalized }) => ({
670
+ token: record.cssName,
671
+ path: record.path.join('.'),
672
+ tier: record.tier,
673
+ value: record.value,
674
+ canonical: normalized.canonical,
675
+ distance: Math.round(valueDistance(category, cluster.anchor, normalized) * 100) / 100,
676
+ ...(record.alias ? { alias: record.alias } : {}),
677
+ root: rootOf(record, byPath).path.join('.'),
678
+ ...(record.deprecated !== undefined ? { deprecated: record.deprecated } : {}),
679
+ ...(record.description ? { description: record.description } : {}),
680
+ scopeRefs: scopeRefs.get(record.cssName) ?? 0,
681
+ totalRefs: totalRefs.get(record.cssName) ?? 0,
682
+ }))
683
+ .sort(tokenSort)
684
+ const values = [...cluster.literals.values()]
685
+ .map((group) => ({
686
+ canonical: group.canonical,
687
+ spellings: [...new Set(group.occurrences.map((entry) => entry.text))].sort(),
688
+ example: group.occurrences[0].text.split('_').join(' '),
689
+ count: group.occurrences.length,
690
+ replaceable: group.occurrences.filter((entry) => entry.replaceable).length,
691
+ files: [...new Set(group.occurrences.map((entry) => entry.file))].sort(),
692
+ }))
693
+ .sort((a, b) => b.count - a.count || a.canonical.localeCompare(b.canonical))
694
+ rows.push({
695
+ category,
696
+ anchor: cluster.anchor.canonical,
697
+ values,
698
+ tokens: tokenEntries,
699
+ occurrences: occurrences
700
+ .map(({ category: _category, canonical, ...rest }) => ({ ...rest, value: canonical }))
701
+ .sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column),
702
+ normalizeOptions,
703
+ anchorValue: cluster.anchor,
704
+ })
705
+ }
706
+ }
707
+
708
+ // Suggestions.
709
+ rows.sort((a, b) => options.categories.indexOf(a.category) - options.categories.indexOf(b.category) || b.occurrences.length - a.occurrences.length || b.tokens.length - a.tokens.length || a.anchor.localeCompare(b.anchor))
710
+ const finalRows = rows.map((row, index) => suggest({ ...row, id: `r${index + 1}` }, records, catOf, byPath))
711
+ const counts = {
712
+ files: ctx.files.length,
713
+ rows: finalRows.length,
714
+ occurrences: finalRows.reduce((sum, row) => sum + row.occurrences.length, 0),
715
+ replaceable: finalRows.reduce((sum, row) => sum + row.occurrences.filter((entry) => entry.replaceable).length, 0),
716
+ tokensInUse: new Set(finalRows.flatMap((row) => row.tokens.filter((entry) => entry.scopeRefs).map((entry) => entry.token))).size,
717
+ suggestions: finalRows.reduce((acc, row) => ({ ...acc, [row.suggestion.action]: (acc[row.suggestion.action] ?? 0) + 1 }), {}),
718
+ visibleChanges: finalRows.filter((row) => row.visibleChange.length).length,
719
+ }
720
+ counts.leftovers = counts.occurrences - counts.replaceable
721
+ const unclustered = summarizeUnclustered(collected.unclustered)
722
+ return {
723
+ options,
724
+ counts,
725
+ rows: finalRows.map(({ normalizeOptions: _n, anchorValue: _a, ...row }) => row),
726
+ unclustered,
727
+ ...(collected.unsupported.length ? { unsupported: collected.unsupported } : {}),
728
+ }
729
+ }
730
+
731
+ function summarizeUnclustered(entries) {
732
+ const map = new Map()
733
+ for (const entry of entries) {
734
+ const key = `${entry.category}\0${entry.text}`
735
+ const existing = map.get(key) ?? { category: entry.category, text: entry.text, reason: entry.reason, count: 0, places: [] }
736
+ existing.count += 1
737
+ if (existing.places.length < 10) existing.places.push(`${entry.file}:${entry.line}`)
738
+ map.set(key, existing)
739
+ }
740
+ return [...map.values()].sort((a, b) => b.count - a.count || a.text.localeCompare(b.text))
741
+ }
742
+
743
+ function suggest(row, records, catOf, byPath) {
744
+ const live = row.tokens.filter((entry) => entry.deprecated === undefined)
745
+ const literals = row.occurrences.length
746
+ // Independently defined tokens with the same value (different alias roots) are duplicates.
747
+ const roots = new Map()
748
+ for (const entry of live) {
749
+ const root = byPath.get(entry.root)
750
+ if (!root || root.deprecated !== undefined) continue
751
+ const rootEntry = live.find((candidate) => candidate.path === entry.root)
752
+ if (!rootEntry) continue
753
+ const group = roots.get(entry.root) ?? { root: rootEntry, refs: 0 }
754
+ group.refs += entry.scopeRefs + entry.totalRefs
755
+ roots.set(entry.root, group)
756
+ }
757
+ const rootGroups = [...roots.values()].sort(
758
+ (a, b) => a.root.distance - b.root.distance || b.refs - a.refs || (TIER_RANK[b.root.tier] ?? 9) - (TIER_RANK[a.root.tier] ?? 9) || a.root.path.localeCompare(b.root.path),
759
+ )
760
+ const sameType = (a, b) => byPath.get(a.path)?.dtcgType === byPath.get(b.path)?.dtcgType
761
+ const keeper = rootGroups[0]?.root
762
+ const duplicates = keeper ? rootGroups.slice(1).map((group) => group.root).filter((entry) => sameType(entry, keeper)) : []
763
+
764
+ let target = live[0]
765
+ if (target && duplicates.some((entry) => entry.path === rootOfPath(target.path, byPath))) target = keeper
766
+ const warnings = []
767
+ let suggestion
768
+ let action
769
+ const base = { normalizeOptions: row.normalizeOptions }
770
+ if (!live.length) {
771
+ const value = row.values[0]
772
+ const near = nearestTokens(row, records, catOf)
773
+ const replaceable = row.occurrences.filter((entry) => entry.replaceable).length
774
+ suggestion = {
775
+ action: 'create',
776
+ value: createValue(row, value),
777
+ reason: `no ${row.category} token within the tolerance of ${row.anchor}`,
778
+ // `code` + `params` say the same as `reason` for the editor to translate.
779
+ code: 'no-token-near',
780
+ params: { category: row.category, anchor: row.anchor },
781
+ naming: namingHints(row.category, records, catOf),
782
+ ...(near.length ? { alternatives: near } : {}),
783
+ // Nothing here is replaceable by the tool (shorthands, mixed values…): not pre-selected.
784
+ ...(replaceable ? {} : { note: 'every occurrence is a leftover for the agent; skipped unless you choose create', noteCode: 'all-leftovers' }),
785
+ }
786
+ action = replaceable ? { action: 'create', name: '', tier: '', description: '', value: createValue(row, value) } : { action: 'skip' }
787
+ } else if (duplicates.length && (literals || live.some((entry) => entry.scopeRefs))) {
788
+ suggestion = {
789
+ action: 'merge',
790
+ token: keeper.path,
791
+ merge: duplicates.map((entry) => entry.path),
792
+ reason: `${[keeper, ...duplicates].map((entry) => entry.path).join(', ')} are defined separately with ${keeper.canonical === duplicates[0].canonical ? 'the same value' : 'near-identical values'}; they may still be separate roles, so merging is opt-in`,
793
+ code: keeper.canonical === duplicates[0].canonical ? 'duplicates-same' : 'duplicates-near',
794
+ params: { tokens: [keeper, ...duplicates].map((entry) => entry.path).join(', ') },
795
+ }
796
+ // Merging changes what future edits affect; it is never pre-selected.
797
+ action = literals ? { action: 'reuse', token: target.path } : { action: 'skip' }
798
+ } else if (literals) {
799
+ const exact = target.distance === 0 && target.canonical === row.anchor
800
+ suggestion = {
801
+ action: 'reuse',
802
+ token: target.path,
803
+ exact: row.values.every((value) => value.canonical === target.canonical),
804
+ reason: exact ? `${target.path} is ${target.value}` : `nearest ${row.category} token: ${target.path} (${target.value})`,
805
+ code: exact ? 'exact' : 'nearest',
806
+ params: { token: target.path, value: target.value, category: row.category },
807
+ ...(live.length > 1 ? { alternatives: live.slice(1, 6).map((entry) => ({ token: entry.path, tier: entry.tier, value: entry.value })) } : {}),
808
+ }
809
+ action = { action: 'reuse', token: target.path }
810
+ } else {
811
+ suggestion = { action: 'keep', reason: 'tokens only; no hard-coded value in scope', code: 'tokens-only', params: {} }
812
+ action = { action: 'skip' }
813
+ }
814
+ if (target && (action.action === 'reuse' || suggestion.action === 'merge') && byPath.get(action.token ?? suggestion.token)?.tier === 'primitive' && row.occurrences.length) {
815
+ warnings.push('primitive-token: components should use a semantic or component token; pick a semantic alternative, or `--action create --tier semantic --value "{<primitive>}"` to add one aliasing the primitive')
816
+ }
817
+ const leftovers = row.occurrences.filter((entry) => !entry.replaceable).length
818
+ const out = {
819
+ id: row.id,
820
+ category: row.category,
821
+ anchor: row.anchor,
822
+ values: row.values,
823
+ tokens: row.tokens,
824
+ suggestion,
825
+ ...action,
826
+ acceptVisibleChange: false,
827
+ counts: { occurrences: row.occurrences.length, replaceable: row.occurrences.length - leftovers, leftovers, files: new Set(row.occurrences.map((entry) => entry.file)).size },
828
+ occurrences: row.occurrences,
829
+ ...(warnings.length ? { warnings } : {}),
830
+ ...base,
831
+ }
832
+ out.visibleChange = rowVisibleChange(out, byPath)
833
+ if (suggestion.action === 'reuse') suggestion.exact = out.visibleChange.length === 0
834
+ return out.visibleChange.length ? undecided(out) : out
835
+ }
836
+
837
+ /** Fields of a row that belong to its chosen action. */
838
+ const ACTION_FIELDS = ['action', 'token', 'name', 'tier', 'description', 'value', 'merge']
839
+
840
+ /**
841
+ * A row whose suggested action would change the rendering is never pre-selected: its action is
842
+ * `undecided` until a human picks one (`consolidate set --action …`), and `apply` refuses it.
843
+ * The tool's pick stays as `proposed` (what `visibleChange` describes), the reason as
844
+ * `suggestion`.
845
+ */
846
+ function undecided(row) {
847
+ const proposed = Object.fromEntries(ACTION_FIELDS.filter((key) => row[key] !== undefined).map((key) => [key, row[key]]))
848
+ const out = Object.fromEntries(Object.entries(row).filter(([key]) => !ACTION_FIELDS.includes(key)))
849
+ return { ...out, action: 'undecided', proposed }
850
+ }
851
+
852
+ const rootOfPath = (path, byPath) => {
853
+ const record = byPath.get(path)
854
+ return record ? rootOf(record, byPath).path.join('.') : path
855
+ }
856
+
857
+ /**
858
+ * The value a new token gets: the most common written form among the replaceable occurrences,
859
+ * so a rem codebase gets rem tokens and a wide-gamut color keeps its notation. Colors inside
860
+ * sRGB use the canonical hex (identical rendering); lengths keep their unit when the token
861
+ * pipeline accepts it (px, rem, em, %), otherwise the canonical px.
862
+ */
863
+ function createValue(row, value) {
864
+ if (!value) return ''
865
+ if (row.category === 'shadow') return value.example
866
+ const counts = new Map()
867
+ for (const occurrence of row.occurrences) {
868
+ if (!occurrence.replaceable || occurrence.value !== value.canonical) continue
869
+ const text = String(occurrence.text).split('_').join(' ').trim()
870
+ counts.set(text, (counts.get(text) ?? 0) + 1)
871
+ }
872
+ const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([text]) => text)
873
+ if (row.category === 'color') {
874
+ const wide = ranked.find((text) => normalizeValue('color', text)?.approximate)
875
+ return wide ? wide.toLowerCase().replace(/\s+/g, ' ') : value.canonical
876
+ }
877
+ if (LENGTH_CATEGORIES.has(row.category)) {
878
+ for (const text of ranked) {
879
+ const unit = valueParser.unit(text)
880
+ if (!unit) continue
881
+ const suffix = unit.unit.toLowerCase()
882
+ if (['px', 'rem', 'em', '%'].includes(suffix) || (suffix === '' && row.category === 'line-height')) return `${Number(unit.number)}${suffix}`
883
+ }
884
+ }
885
+ return value.canonical
886
+ }
887
+
888
+ function nearestTokens(row, records, catOf) {
889
+ const anchor = normalizeValue(row.category, row.values[0]?.example ?? row.anchor, row.normalizeOptions)
890
+ if (!anchor) return []
891
+ return records
892
+ .filter((record) => record.deprecated === undefined && catOf.get(record.cssName) === row.category)
893
+ .map((record) => {
894
+ const normalized = normalizeValue(row.category, record.value, row.normalizeOptions)
895
+ return { record, normalized, distance: valueDistance(row.category, anchor, normalized) }
896
+ })
897
+ .filter((entry) => Number.isFinite(entry.distance))
898
+ .sort((a, b) => a.distance - b.distance)
899
+ .slice(0, 3)
900
+ .map((entry) => ({ token: entry.record.path.join('.'), tier: entry.record.tier, value: entry.record.value, delta: deltaOf(row.category, anchor, entry.normalized) }))
901
+ }
902
+
903
+ /** Target of a row's chosen action (`targetFromValue` shape), or null. */
904
+ export function rowTarget(row, byPath) {
905
+ const options = row.normalizeOptions
906
+ if (row.action === 'create') return row.value ? targetFromValue(row.category, row.value, options, byPath) : null
907
+ if (row.action === 'reuse' || row.action === 'merge') {
908
+ const record = recordFor(byPath, row.token)
909
+ return record ? targetFromValue(row.category, record.value, options, byPath) : null
910
+ }
911
+ return null
912
+ }
913
+
914
+ /** The row's visible changes for its current action (`occurrences` default to the row's own). */
915
+ export function rowVisibleChange(input, byPath, occurrences = input.occurrences ?? []) {
916
+ // An undecided row shows what the tool's proposal would change.
917
+ const row = input.action === 'undecided' && input.proposed ? { ...input, ...input.proposed } : input
918
+ if (!['reuse', 'create', 'merge'].includes(row.action)) return []
919
+ const target = rowTarget(row, byPath)
920
+ return visibleChangesFor({
921
+ category: row.category,
922
+ occurrences,
923
+ target,
924
+ mergeTokens: row.action === 'merge' ? row.merge ?? [] : [],
925
+ byPath,
926
+ options: row.normalizeOptions,
927
+ }).map((change) => ({ ...change, signature: changeSignature(change, target) }))
928
+ }