ui-gateway 0.1.1 → 0.1.2

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 (362) hide show
  1. package/AGENTS.md +41 -6
  2. package/BENCHMARK.md +141 -0
  3. package/CHANGELOG.md +200 -2
  4. package/CONTRIBUTING.md +48 -6
  5. package/NON-GOALS.md +9 -6
  6. package/README.md +136 -41
  7. package/SECURITY.md +22 -1
  8. package/SKILL.md +71 -17
  9. package/action.yml +90 -0
  10. package/dist/evals/src/baseline.d.ts +4 -1
  11. package/dist/evals/src/baseline.d.ts.map +1 -1
  12. package/dist/evals/src/baseline.js +28 -6
  13. package/dist/evals/src/baseline.js.map +1 -1
  14. package/dist/evals/src/metrics.d.ts +35 -0
  15. package/dist/evals/src/metrics.d.ts.map +1 -1
  16. package/dist/evals/src/metrics.js +24 -0
  17. package/dist/evals/src/metrics.js.map +1 -1
  18. package/dist/packages/adapters/src/angular/index.js +2 -2
  19. package/dist/packages/adapters/src/angular/manifest.d.ts.map +1 -1
  20. package/dist/packages/adapters/src/angular/manifest.js +2 -8
  21. package/dist/packages/adapters/src/angular/manifest.js.map +1 -1
  22. package/dist/packages/adapters/src/antd/index.js +2 -2
  23. package/dist/packages/adapters/src/antd/manifest.d.ts.map +1 -1
  24. package/dist/packages/adapters/src/antd/manifest.js +2 -8
  25. package/dist/packages/adapters/src/antd/manifest.js.map +1 -1
  26. package/dist/packages/adapters/src/bootstrap/index.js +2 -2
  27. package/dist/packages/adapters/src/bootstrap/manifest.d.ts.map +1 -1
  28. package/dist/packages/adapters/src/bootstrap/manifest.js +2 -8
  29. package/dist/packages/adapters/src/bootstrap/manifest.js.map +1 -1
  30. package/dist/packages/adapters/src/chakra/index.d.ts.map +1 -1
  31. package/dist/packages/adapters/src/chakra/index.js +30 -5
  32. package/dist/packages/adapters/src/chakra/index.js.map +1 -1
  33. package/dist/packages/adapters/src/chakra/manifest.d.ts.map +1 -1
  34. package/dist/packages/adapters/src/chakra/manifest.js +309 -10
  35. package/dist/packages/adapters/src/chakra/manifest.js.map +1 -1
  36. package/dist/packages/adapters/src/index.d.ts +4 -0
  37. package/dist/packages/adapters/src/index.d.ts.map +1 -1
  38. package/dist/packages/adapters/src/index.js +18 -14
  39. package/dist/packages/adapters/src/index.js.map +1 -1
  40. package/dist/packages/adapters/src/local.d.ts.map +1 -1
  41. package/dist/packages/adapters/src/local.js +4 -2
  42. package/dist/packages/adapters/src/local.js.map +1 -1
  43. package/dist/packages/adapters/src/mantine/index.js +3 -3
  44. package/dist/packages/adapters/src/mantine/manifest.d.ts.map +1 -1
  45. package/dist/packages/adapters/src/mantine/manifest.js +8 -21
  46. package/dist/packages/adapters/src/mantine/manifest.js.map +1 -1
  47. package/dist/packages/adapters/src/mui/index.js +3 -3
  48. package/dist/packages/adapters/src/mui/manifest.d.ts.map +1 -1
  49. package/dist/packages/adapters/src/mui/manifest.js +2 -11
  50. package/dist/packages/adapters/src/mui/manifest.js.map +1 -1
  51. package/dist/packages/adapters/src/nuxt-ui/index.d.ts +5 -0
  52. package/dist/packages/adapters/src/nuxt-ui/index.d.ts.map +1 -0
  53. package/dist/packages/adapters/src/nuxt-ui/index.js +79 -0
  54. package/dist/packages/adapters/src/nuxt-ui/index.js.map +1 -0
  55. package/dist/packages/adapters/src/nuxt-ui/manifest.d.ts +3 -0
  56. package/dist/packages/adapters/src/nuxt-ui/manifest.d.ts.map +1 -0
  57. package/dist/packages/adapters/src/nuxt-ui/manifest.js +295 -0
  58. package/dist/packages/adapters/src/nuxt-ui/manifest.js.map +1 -0
  59. package/dist/packages/adapters/src/radix/index.d.ts +5 -0
  60. package/dist/packages/adapters/src/radix/index.d.ts.map +1 -0
  61. package/dist/packages/adapters/src/radix/index.js +71 -0
  62. package/dist/packages/adapters/src/radix/index.js.map +1 -0
  63. package/dist/packages/adapters/src/radix/manifest.d.ts +3 -0
  64. package/dist/packages/adapters/src/radix/manifest.d.ts.map +1 -0
  65. package/dist/packages/adapters/src/radix/manifest.js +331 -0
  66. package/dist/packages/adapters/src/radix/manifest.js.map +1 -0
  67. package/dist/packages/adapters/src/registry.d.ts +1 -1
  68. package/dist/packages/adapters/src/registry.d.ts.map +1 -1
  69. package/dist/packages/adapters/src/registry.js +16 -12
  70. package/dist/packages/adapters/src/registry.js.map +1 -1
  71. package/dist/packages/adapters/src/shadcn/index.js +3 -3
  72. package/dist/packages/adapters/src/shadcn/manifest.d.ts.map +1 -1
  73. package/dist/packages/adapters/src/shadcn/manifest.js +2 -11
  74. package/dist/packages/adapters/src/shadcn/manifest.js.map +1 -1
  75. package/dist/packages/adapters/src/solid/index.js +2 -2
  76. package/dist/packages/adapters/src/solid/manifest.d.ts.map +1 -1
  77. package/dist/packages/adapters/src/solid/manifest.js +2 -8
  78. package/dist/packages/adapters/src/solid/manifest.js.map +1 -1
  79. package/dist/packages/adapters/src/svelte/index.js +2 -2
  80. package/dist/packages/adapters/src/svelte/manifest.d.ts.map +1 -1
  81. package/dist/packages/adapters/src/svelte/manifest.js +2 -8
  82. package/dist/packages/adapters/src/svelte/manifest.js.map +1 -1
  83. package/dist/packages/adapters/src/vue/index.js +2 -2
  84. package/dist/packages/adapters/src/vue/manifest.d.ts.map +1 -1
  85. package/dist/packages/adapters/src/vue/manifest.js +2 -8
  86. package/dist/packages/adapters/src/vue/manifest.js.map +1 -1
  87. package/dist/packages/design-md/src/compile.js +2 -2
  88. package/dist/packages/design-md/src/derive.d.ts +41 -0
  89. package/dist/packages/design-md/src/derive.d.ts.map +1 -0
  90. package/dist/packages/design-md/src/derive.js +341 -0
  91. package/dist/packages/design-md/src/derive.js.map +1 -0
  92. package/dist/packages/design-md/src/index.d.ts +1 -0
  93. package/dist/packages/design-md/src/index.d.ts.map +1 -1
  94. package/dist/packages/design-md/src/index.js +6 -5
  95. package/dist/packages/design-md/src/index.js.map +1 -1
  96. package/dist/packages/gateway/src/confidence.d.ts +51 -1
  97. package/dist/packages/gateway/src/confidence.d.ts.map +1 -1
  98. package/dist/packages/gateway/src/confidence.js +198 -6
  99. package/dist/packages/gateway/src/confidence.js.map +1 -1
  100. package/dist/packages/gateway/src/gateway.d.ts +10 -2
  101. package/dist/packages/gateway/src/gateway.d.ts.map +1 -1
  102. package/dist/packages/gateway/src/gateway.js +190 -14
  103. package/dist/packages/gateway/src/gateway.js.map +1 -1
  104. package/dist/packages/gateway/src/index.d.ts +1 -0
  105. package/dist/packages/gateway/src/index.d.ts.map +1 -1
  106. package/dist/packages/gateway/src/index.js +7 -6
  107. package/dist/packages/gateway/src/index.js.map +1 -1
  108. package/dist/packages/gateway/src/preview.d.ts +12 -0
  109. package/dist/packages/gateway/src/preview.d.ts.map +1 -0
  110. package/dist/packages/gateway/src/preview.js +113 -0
  111. package/dist/packages/gateway/src/preview.js.map +1 -0
  112. package/dist/packages/gateway/src/validate.d.ts +5 -2
  113. package/dist/packages/gateway/src/validate.d.ts.map +1 -1
  114. package/dist/packages/gateway/src/validate.js +46 -18
  115. package/dist/packages/gateway/src/validate.js.map +1 -1
  116. package/dist/packages/kb/src/bundle-size.d.ts +8 -9
  117. package/dist/packages/kb/src/bundle-size.d.ts.map +1 -1
  118. package/dist/packages/kb/src/bundle-size.js +14 -12
  119. package/dist/packages/kb/src/bundle-size.js.map +1 -1
  120. package/dist/packages/kb/src/entry.d.ts +19 -1
  121. package/dist/packages/kb/src/entry.d.ts.map +1 -1
  122. package/dist/packages/kb/src/entry.js +13 -1
  123. package/dist/packages/kb/src/entry.js.map +1 -1
  124. package/dist/packages/kb/src/freshness.d.ts +76 -0
  125. package/dist/packages/kb/src/freshness.d.ts.map +1 -0
  126. package/dist/packages/kb/src/freshness.js +186 -0
  127. package/dist/packages/kb/src/freshness.js.map +1 -0
  128. package/dist/packages/kb/src/index.d.ts +2 -1
  129. package/dist/packages/kb/src/index.d.ts.map +1 -1
  130. package/dist/packages/kb/src/index.js +6 -5
  131. package/dist/packages/kb/src/index.js.map +1 -1
  132. package/dist/packages/kb/src/ingest.d.ts +3 -0
  133. package/dist/packages/kb/src/ingest.d.ts.map +1 -1
  134. package/dist/packages/kb/src/ingest.js +7 -1
  135. package/dist/packages/kb/src/ingest.js.map +1 -1
  136. package/dist/packages/kb/src/kb.d.ts +5 -0
  137. package/dist/packages/kb/src/kb.d.ts.map +1 -1
  138. package/dist/packages/kb/src/kb.js +5 -2
  139. package/dist/packages/kb/src/kb.js.map +1 -1
  140. package/dist/packages/matcher/src/anthropic.js +1 -1
  141. package/dist/packages/matcher/src/index.d.ts +8 -1
  142. package/dist/packages/matcher/src/index.d.ts.map +1 -1
  143. package/dist/packages/matcher/src/index.js +21 -11
  144. package/dist/packages/matcher/src/index.js.map +1 -1
  145. package/dist/packages/matcher/src/scaffold.d.ts.map +1 -1
  146. package/dist/packages/matcher/src/scaffold.js +62 -19
  147. package/dist/packages/matcher/src/scaffold.js.map +1 -1
  148. package/dist/packages/matcher/src/score.d.ts +8 -1
  149. package/dist/packages/matcher/src/score.d.ts.map +1 -1
  150. package/dist/packages/matcher/src/score.js +90 -25
  151. package/dist/packages/matcher/src/score.js.map +1 -1
  152. package/dist/packages/matcher/src/select.d.ts +15 -1
  153. package/dist/packages/matcher/src/select.d.ts.map +1 -1
  154. package/dist/packages/matcher/src/select.js +53 -3
  155. package/dist/packages/matcher/src/select.js.map +1 -1
  156. package/dist/packages/orchestrator/src/figma.d.ts +12 -0
  157. package/dist/packages/orchestrator/src/figma.d.ts.map +1 -0
  158. package/dist/packages/orchestrator/src/figma.js +102 -0
  159. package/dist/packages/orchestrator/src/figma.js.map +1 -0
  160. package/dist/packages/orchestrator/src/index.d.ts +1 -0
  161. package/dist/packages/orchestrator/src/index.d.ts.map +1 -1
  162. package/dist/packages/orchestrator/src/index.js +3 -2
  163. package/dist/packages/orchestrator/src/index.js.map +1 -1
  164. package/dist/packages/orchestrator/src/orchestrator.d.ts.map +1 -1
  165. package/dist/packages/orchestrator/src/orchestrator.js +14 -3
  166. package/dist/packages/orchestrator/src/orchestrator.js.map +1 -1
  167. package/dist/packages/profile/src/detect.d.ts +9 -0
  168. package/dist/packages/profile/src/detect.d.ts.map +1 -1
  169. package/dist/packages/profile/src/detect.js +52 -5
  170. package/dist/packages/profile/src/detect.js.map +1 -1
  171. package/dist/packages/profile/src/index.js +7 -7
  172. package/dist/packages/profile/src/local-components.d.ts.map +1 -1
  173. package/dist/packages/profile/src/local-components.js +70 -1
  174. package/dist/packages/profile/src/local-components.js.map +1 -1
  175. package/dist/packages/profile/src/registry.d.ts.map +1 -1
  176. package/dist/packages/profile/src/registry.js +3 -1
  177. package/dist/packages/profile/src/registry.js.map +1 -1
  178. package/dist/packages/profile/src/skills.js +1 -1
  179. package/dist/packages/protocol/src/errors.js +1 -1
  180. package/dist/packages/protocol/src/errors.js.map +1 -1
  181. package/dist/packages/protocol/src/event-log.d.ts.map +1 -1
  182. package/dist/packages/protocol/src/event-log.js +11 -5
  183. package/dist/packages/protocol/src/event-log.js.map +1 -1
  184. package/dist/packages/protocol/src/events.js +5 -5
  185. package/dist/packages/protocol/src/hashing.d.ts +6 -0
  186. package/dist/packages/protocol/src/hashing.d.ts.map +1 -1
  187. package/dist/packages/protocol/src/hashing.js +8 -2
  188. package/dist/packages/protocol/src/hashing.js.map +1 -1
  189. package/dist/packages/protocol/src/index.js +12 -12
  190. package/dist/packages/protocol/src/lease.js +2 -2
  191. package/dist/packages/protocol/src/schemas.d.ts +2803 -116
  192. package/dist/packages/protocol/src/schemas.d.ts.map +1 -1
  193. package/dist/packages/protocol/src/schemas.js +54 -4
  194. package/dist/packages/protocol/src/schemas.js.map +1 -1
  195. package/dist/packages/protocol/src/semantic.js +1 -1
  196. package/dist/packages/protocol/src/state-machine.js +1 -1
  197. package/dist/packages/transports/src/check.d.ts +30 -0
  198. package/dist/packages/transports/src/check.d.ts.map +1 -0
  199. package/dist/packages/transports/src/check.js +190 -0
  200. package/dist/packages/transports/src/check.js.map +1 -0
  201. package/dist/packages/transports/src/cli.d.ts +1 -1
  202. package/dist/packages/transports/src/cli.js +278 -25
  203. package/dist/packages/transports/src/cli.js.map +1 -1
  204. package/dist/packages/transports/src/exit-codes.d.ts +8 -0
  205. package/dist/packages/transports/src/exit-codes.d.ts.map +1 -0
  206. package/dist/packages/transports/src/exit-codes.js +19 -0
  207. package/dist/packages/transports/src/exit-codes.js.map +1 -0
  208. package/dist/packages/transports/src/http.js +2 -2
  209. package/dist/packages/transports/src/http.js.map +1 -1
  210. package/dist/packages/transports/src/index.d.ts +5 -0
  211. package/dist/packages/transports/src/index.d.ts.map +1 -1
  212. package/dist/packages/transports/src/index.js +11 -6
  213. package/dist/packages/transports/src/index.js.map +1 -1
  214. package/dist/packages/transports/src/init.d.ts +32 -0
  215. package/dist/packages/transports/src/init.d.ts.map +1 -0
  216. package/dist/packages/transports/src/init.js +110 -0
  217. package/dist/packages/transports/src/init.js.map +1 -0
  218. package/dist/packages/transports/src/mcp-config.d.ts +27 -0
  219. package/dist/packages/transports/src/mcp-config.d.ts.map +1 -0
  220. package/dist/packages/transports/src/mcp-config.js +99 -0
  221. package/dist/packages/transports/src/mcp-config.js.map +1 -0
  222. package/dist/packages/transports/src/mcp.js +3 -3
  223. package/dist/packages/transports/src/paths.d.ts +9 -0
  224. package/dist/packages/transports/src/paths.d.ts.map +1 -0
  225. package/dist/packages/transports/src/paths.js +32 -0
  226. package/dist/packages/transports/src/paths.js.map +1 -0
  227. package/dist/packages/transports/src/receipt.d.ts +8 -0
  228. package/dist/packages/transports/src/receipt.d.ts.map +1 -0
  229. package/dist/packages/transports/src/receipt.js +87 -0
  230. package/dist/packages/transports/src/receipt.js.map +1 -0
  231. package/dist/packages/transports/src/resources.js +3 -3
  232. package/dist/packages/transports/src/resources.js.map +1 -1
  233. package/dist/packages/transports/src/tools.d.ts.map +1 -1
  234. package/dist/packages/transports/src/tools.js +284 -10
  235. package/dist/packages/transports/src/tools.js.map +1 -1
  236. package/dist/packages/verifier/src/index.js +7 -7
  237. package/dist/packages/verifier/src/lint.js +1 -1
  238. package/dist/packages/verifier/src/page.js +2 -2
  239. package/dist/packages/verifier/src/render-axe.js +1 -1
  240. package/dist/packages/verifier/src/verify.js +4 -4
  241. package/dist/scripts/build-site.d.ts +2 -0
  242. package/dist/scripts/build-site.d.ts.map +1 -0
  243. package/dist/scripts/build-site.js +254 -0
  244. package/dist/scripts/build-site.js.map +1 -0
  245. package/dist/scripts/calibration.js +33 -2
  246. package/dist/scripts/calibration.js.map +1 -1
  247. package/dist/scripts/fix-imports.js +32 -2
  248. package/dist/scripts/fix-imports.js.map +1 -1
  249. package/dist/scripts/generate-kb.d.ts +3 -0
  250. package/dist/scripts/generate-kb.d.ts.map +1 -0
  251. package/dist/scripts/generate-kb.js +195 -0
  252. package/dist/scripts/generate-kb.js.map +1 -0
  253. package/dist/scripts/generate-refusal-catalog.d.ts +3 -0
  254. package/dist/scripts/generate-refusal-catalog.d.ts.map +1 -0
  255. package/dist/scripts/generate-refusal-catalog.js +50 -0
  256. package/dist/scripts/generate-refusal-catalog.js.map +1 -0
  257. package/dist/scripts/generate-tool-docs.d.ts +3 -0
  258. package/dist/scripts/generate-tool-docs.d.ts.map +1 -0
  259. package/dist/scripts/generate-tool-docs.js +24 -0
  260. package/dist/scripts/generate-tool-docs.js.map +1 -0
  261. package/dist/scripts/mcp-config.js +28 -60
  262. package/dist/scripts/mcp-config.js.map +1 -1
  263. package/docs/archive/UI Gateway Final Project Roadmap.md +285 -0
  264. package/docs/benchmarks/external-repos.json +26 -0
  265. package/docs/benchmarks/local-gemma3-1b-stride32.json +455 -0
  266. package/docs/calibration.svg +44 -0
  267. package/docs/design-import.md +19 -0
  268. package/docs/design-md.md +109 -0
  269. package/docs/distribution.md +41 -0
  270. package/docs/engineering-principles.md +152 -0
  271. package/docs/layers-plan.md +372 -0
  272. package/docs/metrics.md +153 -0
  273. package/docs/modes.md +22 -0
  274. package/docs/parking-lot.md +25 -0
  275. package/docs/quickstart.md +72 -0
  276. package/docs/refusal-catalog.md +32 -0
  277. package/docs/spike-source-discovery.md +36 -0
  278. package/docs/telemetry.md +26 -0
  279. package/evals/fixtures/external-repos.json +55 -0
  280. package/evals/fixtures/kb-generated/angular.json +72 -0
  281. package/evals/fixtures/kb-generated/antd.json +72 -0
  282. package/evals/fixtures/kb-generated/bootstrap.json +72 -0
  283. package/evals/fixtures/kb-generated/chakra.json +14939 -0
  284. package/evals/fixtures/kb-generated/mantine.json +192 -0
  285. package/evals/fixtures/kb-generated/mui.json +8997 -0
  286. package/evals/fixtures/kb-generated/shadcn.json +192 -0
  287. package/evals/fixtures/kb-generated/solid.json +72 -0
  288. package/evals/fixtures/kb-generated/svelte.json +72 -0
  289. package/evals/fixtures/kb-generated/vue.json +72 -0
  290. package/evals/fixtures/projects/existing-chakra-v3/package.json +10 -0
  291. package/evals/fixtures/projects/existing-nuxt-ui/package.json +9 -0
  292. package/evals/fixtures/projects/existing-radix/package.json +9 -0
  293. package/evals/out/agent-report.json +190 -11
  294. package/evals/out/baseline-report.json +1441 -387
  295. package/evals/out/calibration.json +387 -42
  296. package/evals/out/external-repos-report.json +112 -0
  297. package/evals/out/local-benchmark-report.json +455 -0
  298. package/evals/src/agent-eval.test.ts +3 -0
  299. package/evals/src/agent-eval.ts +26 -4
  300. package/evals/src/baseline.ts +48 -7
  301. package/evals/src/blind-labeling-cli.ts +5 -0
  302. package/evals/src/blind-labeling.ts +46 -0
  303. package/evals/src/external-repos.ts +179 -0
  304. package/evals/src/metrics.ts +70 -0
  305. package/evals/src/mutations.ts +6 -6
  306. package/evals/src/page-a11y-eval.ts +37 -36
  307. package/evals/src/page-real-eval.ts +8 -7
  308. package/evals/src/plain-agent.test.ts +14 -0
  309. package/evals/src/plain-agent.ts +240 -0
  310. package/evals/src/run-agent-evals.ts +3 -0
  311. package/evals/src/run-external-repos.ts +43 -0
  312. package/evals/src/run-local-benchmark.ts +105 -0
  313. package/evals/src/run-plain-agent.ts +81 -0
  314. package/examples/README.md +32 -0
  315. package/examples/build-handoff.ts +106 -0
  316. package/examples/design-md.md +24 -0
  317. package/examples/handoff-input.json +59 -0
  318. package/examples/handoff.json +216 -0
  319. package/examples/layer-operations.json +18 -0
  320. package/examples/website-demo-handoff.json +580 -0
  321. package/package.json +29 -6
  322. package/references/design-md.md +3 -1
  323. package/references/errors.md +1 -1
  324. package/references/handoff.md +16 -1
  325. package/references/outcomes.md +60 -11
  326. package/references/patterns.md +3 -3
  327. package/references/tools.md +86 -27
  328. package/scripts/action-review.mjs +59 -0
  329. package/scripts/bench-latency.ts +90 -0
  330. package/scripts/build-site.ts +324 -0
  331. package/scripts/calibration.ts +50 -14
  332. package/scripts/fix-imports.ts +31 -2
  333. package/scripts/generate-kb.ts +214 -0
  334. package/scripts/generate-refusal-catalog.ts +58 -0
  335. package/scripts/generate-tool-docs.ts +31 -0
  336. package/scripts/mcp-config.ts +26 -83
  337. package/scripts/package-plugin.mjs +50 -0
  338. package/scripts/sbom.mjs +46 -0
  339. package/scripts/visual-diff.mjs +52 -0
  340. package/site/data.json +187 -0
  341. package/site/index.html +151 -0
  342. package/skills/ui-gateway-cli/SKILL.md +41 -0
  343. package/templates/next-shadcn/.github/workflows/ui-check.yml +14 -0
  344. package/templates/next-shadcn/.mcp.json +8 -0
  345. package/templates/next-shadcn/DESIGN.md +35 -0
  346. package/templates/next-shadcn/README.md +14 -0
  347. package/templates/next-shadcn/app/page.tsx +8 -0
  348. package/templates/next-shadcn/package.json +19 -0
  349. package/templates/vite-mantine/.github/workflows/ui-check.yml +14 -0
  350. package/templates/vite-mantine/.mcp.json +8 -0
  351. package/templates/vite-mantine/DESIGN.md +30 -0
  352. package/templates/vite-mantine/README.md +7 -0
  353. package/templates/vite-mantine/package.json +21 -0
  354. package/templates/vite-mantine/src/App.tsx +10 -0
  355. package/templates/vite-mui/.github/workflows/ui-check.yml +14 -0
  356. package/templates/vite-mui/.mcp.json +8 -0
  357. package/templates/vite-mui/DESIGN.md +30 -0
  358. package/templates/vite-mui/README.md +8 -0
  359. package/templates/vite-mui/package.json +22 -0
  360. package/templates/vite-mui/src/App.tsx +12 -0
  361. package/scripts/fetch-bundle-sizes.ts +0 -106
  362. package/scripts/test-bundlephobia.ts +0 -11
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Generate KB snapshots from published .d.ts files.
4
+ *
5
+ * Hand-written manifests keep roles, intent types and a11y notes; this script
6
+ * derives the exported component surface and prop names from the installed
7
+ * library types, so a library release produces a reviewable diff instead of
8
+ * silent drift. `--check` exits non-zero when the checked-in snapshots differ.
9
+ */
10
+ import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
11
+ import { createRequire } from "node:module";
12
+ import { dirname, join } from "node:path";
13
+ import ts from "typescript";
14
+ import { createDefaultAdapters } from "../packages/adapters/src/index";
15
+ import type { ComponentEntry } from "../packages/kb/src/index";
16
+
17
+ interface SnapshotEntry {
18
+ component_id: string;
19
+ name: string;
20
+ matched: boolean;
21
+ exports: string[];
22
+ props: string[];
23
+ required_props: string[];
24
+ }
25
+
26
+ interface Snapshot {
27
+ library: string;
28
+ package_name: string;
29
+ types_loaded: boolean;
30
+ entries: SnapshotEntry[];
31
+ unmatched: string[];
32
+ }
33
+
34
+ const outDir = join(process.cwd(), "evals", "fixtures", "kb-generated");
35
+ const check = process.argv.includes("--check");
36
+ const require = createRequire(join(process.cwd(), "package.json"));
37
+
38
+ const snapshots: Snapshot[] = [];
39
+ for (const adapter of createDefaultAdapters()) {
40
+ const library = adapter.capabilities.library;
41
+ if (library === "local") continue;
42
+ const sources = adapter.ingest({});
43
+ const entries = sources.flatMap((source) => source.manifest.entries as ComponentEntry[]);
44
+ const packageName = adapter.capabilities.package_name ?? sources[0]?.manifest.package_name ?? "";
45
+ const types = packageName ? loadTypes(packageName) : undefined;
46
+ const snapshot: Snapshot = {
47
+ library,
48
+ package_name: packageName,
49
+ // Deliberately no timestamp: the snapshot must be byte-stable so the
50
+ // nightly job only opens a PR when the actual surface changed.
51
+ types_loaded: Boolean(types),
52
+ entries: [],
53
+ unmatched: [],
54
+ };
55
+ for (const entry of entries) {
56
+ const name = entry.name;
57
+ const found = types ? findExport(types, name) : undefined;
58
+ snapshot.entries.push({
59
+ component_id: entry.component_id,
60
+ name,
61
+ matched: Boolean(found),
62
+ exports: found?.exports ?? [],
63
+ props: found?.props.map((prop) => prop.name) ?? [],
64
+ required_props: found?.props.filter((prop) => !prop.optional).map((prop) => prop.name) ?? [],
65
+ });
66
+ if (types && !found) snapshot.unmatched.push(entry.component_id);
67
+ }
68
+ snapshots.push(snapshot);
69
+ }
70
+
71
+ mkdirSync(outDir, { recursive: true });
72
+ let drifted = 0;
73
+ for (const snapshot of snapshots) {
74
+ const path = join(outDir, `${snapshot.library}.json`);
75
+ const next = `${JSON.stringify(snapshot, null, 2)}\n`;
76
+ const previous = existsSync(path) ? readFileSync(path, "utf8") : undefined;
77
+ if (previous !== next) {
78
+ drifted += 1;
79
+ if (!check) writeFileSync(path, next, "utf8");
80
+ }
81
+ const missingTypes = snapshot.types_loaded ? 0 : 1;
82
+ process.stderr.write(
83
+ `${snapshot.library}: ${snapshot.entries.length} entries, ${snapshot.unmatched.length} unmatched, types ${snapshot.types_loaded ? "loaded" : "missing"}${missingTypes && snapshot.package_name ? ` (${snapshot.package_name})` : ""}\n`,
84
+ );
85
+ }
86
+
87
+ const report = {
88
+ generated_at: new Date().toISOString(),
89
+ check,
90
+ drifted,
91
+ libraries: snapshots.map((snapshot) => ({
92
+ library: snapshot.library,
93
+ entries: snapshot.entries.length,
94
+ matched: snapshot.entries.filter((entry) => entry.matched).length,
95
+ unmatched: snapshot.unmatched,
96
+ types_loaded: snapshot.types_loaded,
97
+ })),
98
+ };
99
+ mkdirSync(join(process.cwd(), ".tmp"), { recursive: true });
100
+ writeFileSync(join(process.cwd(), ".tmp", "kb-generation-report.json"), `${JSON.stringify(report, null, 2)}\n`);
101
+ process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
102
+ if (check && drifted > 0) process.exit(1);
103
+
104
+ interface TypesIndex {
105
+ exports: Map<string, ts.Node>;
106
+ props: Map<string, Array<{ name: string; optional: boolean }>>;
107
+ files: string[];
108
+ }
109
+
110
+ function loadTypes(packageName: string): TypesIndex | undefined {
111
+ let entry: string | undefined;
112
+ try {
113
+ const manifestPath = require.resolve(`${packageName}/package.json`);
114
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as {
115
+ types?: string;
116
+ typings?: string;
117
+ main?: string;
118
+ exports?: unknown;
119
+ };
120
+ const root = dirname(manifestPath);
121
+ const candidate = manifest.types ?? manifest.typings ?? manifest.main ?? "index.d.ts";
122
+ entry = join(root, candidate.replace(/\.js$/, ".d.ts"));
123
+ if (!existsSync(entry)) entry = findDeclaration(root);
124
+ } catch {
125
+ return undefined;
126
+ }
127
+ if (!entry) return undefined;
128
+ const root = packageName.startsWith("@") ? join(entry, "..", "..", "..") : join(entry, "..", "..");
129
+ const files = collectDts(root, 400);
130
+ const program = ts.createProgram(files, {
131
+ noEmit: true,
132
+ skipLibCheck: true,
133
+ target: ts.ScriptTarget.ES2022,
134
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
135
+ types: [],
136
+ });
137
+ const checker = program.getTypeChecker();
138
+ const exportsMap = new Map<string, ts.Node>();
139
+ const props = new Map<string, Array<{ name: string; optional: boolean }>>();
140
+ for (const file of program.getSourceFiles()) {
141
+ if (file.isDeclarationFile === false) continue;
142
+ const moduleSymbol = checker.getSymbolAtLocation(file);
143
+ if (!moduleSymbol) continue;
144
+ for (const symbol of checker.getExportsOfModule(moduleSymbol)) {
145
+ const name = symbol.getName();
146
+ const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0];
147
+ if (declaration) exportsMap.set(name, declaration);
148
+ const type = checker.getTypeOfSymbolAtLocation(symbol, declaration ?? file);
149
+ // Prefer the component's props parameter over React statics such as
150
+ // displayName/propTypes. Function and class components both expose a
151
+ // construct/call signature whose first parameter is the props object.
152
+ const signature = type.getCallSignatures()[0] ?? type.getConstructSignatures()[0];
153
+ const propsType = signature?.getParameters()[0]
154
+ ? checker.getTypeOfSymbolAtLocation(signature.getParameters()[0]!, declaration ?? file)
155
+ : undefined;
156
+ const memberSource = propsType ? propsType.getProperties() : type.getProperties();
157
+ const names = memberSource.map((property) => ({
158
+ name: property.getName(),
159
+ optional: Boolean(property.flags & ts.SymbolFlags.Optional),
160
+ }));
161
+ if (names.length > 0) props.set(name, names);
162
+ }
163
+ }
164
+ return { exports: exportsMap, props, files };
165
+ }
166
+
167
+ function findExport(index: TypesIndex, name: string): { exports: string[]; props: Array<{ name: string; optional: boolean }> } | undefined {
168
+ if (index.exports.has(name)) {
169
+ return { exports: [name], props: index.props.get(name) ?? index.props.get(`${name}Props`) ?? [] };
170
+ }
171
+ const prefixed = [...index.exports.keys()].filter((key) => key.endsWith(name));
172
+ if (prefixed.length > 0) {
173
+ return {
174
+ exports: prefixed,
175
+ props: prefixed.flatMap((key) => index.props.get(key) ?? []),
176
+ };
177
+ }
178
+ return undefined;
179
+ }
180
+
181
+ function collectDts(root: string, limit: number): string[] {
182
+ const found: string[] = [];
183
+ const walk = (dir: string, depth: number): void => {
184
+ if (found.length >= limit || depth > 5) return;
185
+ let entries: string[];
186
+ try {
187
+ entries = readdirSync(dir);
188
+ } catch {
189
+ return;
190
+ }
191
+ for (const entry of entries) {
192
+ if (found.length >= limit) return;
193
+ if (entry === "node_modules") continue;
194
+ const path = join(dir, entry);
195
+ try {
196
+ const stat = ts.sys.directoryExists(path);
197
+ if (stat) walk(path, depth + 1);
198
+ else if (entry.endsWith(".d.ts")) found.push(path);
199
+ } catch {
200
+ // ignore
201
+ }
202
+ }
203
+ };
204
+ walk(root, 0);
205
+ return found;
206
+ }
207
+
208
+ function findDeclaration(root: string): string | undefined {
209
+ for (const candidate of ["index.d.ts", join("dist", "index.d.ts"), join("types", "index.d.ts")]) {
210
+ const path = join(root, candidate);
211
+ if (existsSync(path)) return path;
212
+ }
213
+ return undefined;
214
+ }
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Generate docs/refusal-catalog.md from the protocol ErrorCode enum. The
4
+ * catalog is the agent-facing list of every refusal, whether it is retryable,
5
+ * and what to do next. Run with `npm run docs:refusals`.
6
+ */
7
+ import { writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { ErrorCodeSchema, RETRYABLE, type ErrorCode } from "../packages/protocol/src/index";
10
+
11
+ const FIXES: Record<ErrorCode, string> = {
12
+ INVALID_HANDOFF: "Fix the schema, hash, semantic issue or Design MD error named in the message, then rebuild. Do not submit again unchanged.",
13
+ INTEGRITY_MISMATCH: "Re-read the Design MD and rebuild the handoff so design_md_hash matches the normalized text.",
14
+ CONFLICT: "The handoff_id was already used with different content. Use a new handoff_id; do not overwrite history.",
15
+ UNSATISFIABLE_CONSTRAINTS: "The Design MD contradicts itself or the project. Remove the conflicting constraint or add the missing provider.",
16
+ NO_MATCH: "No vetted component survived verification. Read the failures, add a local component, or relax the constraint that filtered the candidates.",
17
+ KB_STALE: "Call describe_kb and rebuild with the returned kb_version.",
18
+ LEASE_EXPIRED: "Ownership was not returned in time. Retry with a new handoff or recover the expired result.",
19
+ LEASE_CONFLICT: "Another process owns this handoff. Wait for its lease or use a different handoff_id.",
20
+ UNSUPPORTED: "The framework, schema version or library is not supported. Ask the user; do not guess a fallback.",
21
+ INTERNAL: "Report the message with the handoff id. Do not retry automatically.",
22
+ RESULT_REJECTED: "The returned result failed its integrity check. Report it; do not apply it.",
23
+ };
24
+
25
+ const rows = ErrorCodeSchema.options.map(
26
+ (code) => `| \`${code}\` | ${RETRYABLE[code] ? "yes" : "no"} | ${FIXES[code]} |`,
27
+ );
28
+
29
+ writeFileSync(
30
+ join(process.cwd(), "docs", "refusal-catalog.md"),
31
+ [
32
+ "# Refusal catalog",
33
+ "",
34
+ "Generated from `ErrorCodeSchema` and `RETRYABLE` in `packages/protocol/src/errors.ts`.",
35
+ "Do not edit by hand; run `npm run docs:refusals`.",
36
+ "",
37
+ "The gateway fails closed. A refusal is data: report it, answer the missing",
38
+ "information, or fix the input. Never replace a refused mapping with a guess.",
39
+ "",
40
+ "| Code | Retryable | What to do |",
41
+ "| --- | --- | --- |",
42
+ ...rows,
43
+ "",
44
+ "## Outcomes",
45
+ "",
46
+ "| Outcome | Meaning | Action |",
47
+ "| --- | --- | --- |",
48
+ "| `COMPLETED` | Every intent mapped and acceptance passed. | Apply the scaffolds. |",
49
+ "| `PARTIAL` | Some intents mapped; others refused or acceptance failed. | Apply mapped intents only and report the rest. |",
50
+ "| `NEEDS_INPUT` | The gateway needs a decision or a fact. | Write nothing; ask the questions in `missing_information`. |",
51
+ "| `AMBIGUOUS` | Two or more candidates are too close to choose. | Ask the user to pick from the returned alternatives. |",
52
+ "| `FAILED` | Nothing could be mapped, or a hard failure occurred. | Read `errors`; do not retry unchanged. |",
53
+ "| `EXPIRED` | The lease expired before the result was written. | Recover or resubmit with a new handoff. |",
54
+ "",
55
+ ].join("\n"),
56
+ "utf8",
57
+ );
58
+ process.stdout.write(`wrote ${rows.length} error codes to docs/refusal-catalog.md\n`);
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Regenerate the tool table in README.md from TOOLS, so the README cannot
4
+ * drift from the actual MCP/HTTP surface. Run with `npm run docs:tools`.
5
+ */
6
+ import { readFileSync, writeFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { TOOLS } from "../packages/transports/src/tools";
9
+
10
+ const START = "<!-- TOOLS:START -->";
11
+ const END = "<!-- TOOLS:END -->";
12
+
13
+ export function renderToolTable(): string {
14
+ const rows = TOOLS.map(
15
+ (tool) => `| \`${tool.name}\` | ${tool.description.split(/(?<=\.)\s/)[0]!.replace(/\|/g, "\\|")} |`,
16
+ );
17
+ return [`| Tool | Purpose |`, `| --- | --- |`, ...rows].join("\n");
18
+ }
19
+
20
+ const readmePath = join(process.cwd(), "README.md");
21
+ const readme = readFileSync(readmePath, "utf8");
22
+ if (!readme.includes(START) || !readme.includes(END)) {
23
+ process.stderr.write(`README.md is missing ${START} / ${END} markers\n`);
24
+ process.exit(1);
25
+ }
26
+ const next = readme.replace(
27
+ new RegExp(`${START}[\\s\\S]*?${END}`),
28
+ `${START}\n${renderToolTable()}\n${END}`,
29
+ );
30
+ writeFileSync(readmePath, next, "utf8");
31
+ process.stdout.write(`wrote ${TOOLS.length} tools to README.md\n`);
@@ -1,90 +1,33 @@
1
1
  #!/usr/bin/env tsx
2
- import { existsSync } from "node:fs";
3
- import { dirname, join, resolve } from "node:path";
4
- import { fileURLToPath } from "node:url";
2
+ /**
3
+ * Thin wrapper kept for `npm run mcp:config`. The real implementation lives in
4
+ * packages/transports/src/mcp-config.ts and is exported by the CLI as
5
+ * `ui-gateway mcp:config`, so installed consumers do not need tsx or source.
6
+ */
7
+ import { existsSync, writeFileSync } from "node:fs";
8
+ import { join, resolve } from "node:path";
9
+ import { detectClient, mergeMcpConfig, readJsonIfPresent, renderMcpConfig, type McpClient } from "../packages/transports/src/mcp-config";
5
10
 
6
- interface Args {
7
- project: string;
8
- client: "generic" | "opencode";
9
- }
10
-
11
- function parseArgs(): Args {
12
- const args = process.argv.slice(2);
13
- let project = process.cwd();
14
- let client: Args["client"] = "generic";
15
- for (let i = 0; i < args.length; i += 1) {
16
- if (args[i] === "--project" && i + 1 < args.length) {
17
- project = args[++i];
18
- } else if (args[i] === "--client" && i + 1 < args.length) {
19
- const value = args[++i];
20
- if (value !== "generic" && value !== "opencode") {
21
- throw new Error(`unknown client "${value}"; use "generic" or "opencode"`);
22
- }
23
- client = value;
24
- }
25
- }
26
- return { project: resolve(project), client };
27
- }
11
+ const args = process.argv.slice(2);
12
+ const valueOf = (name: string): string | undefined => {
13
+ const inline = args.find((arg) => arg.startsWith(`--${name}=`));
14
+ if (inline) return inline.slice(name.length + 3);
15
+ const index = args.indexOf(`--${name}`);
16
+ return index >= 0 ? args[index + 1] : undefined;
17
+ };
28
18
 
29
- const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
30
- const tsxCli = join(repoRoot, "node_modules", "tsx", "dist", "cli.mjs");
31
- const gatewayCli = join(repoRoot, "packages", "transports", "src", "cli.ts");
32
-
33
- const { project, client } = parseArgs();
34
- if (!existsSync(tsxCli)) {
35
- process.stderr.write(
36
- `tsx was not found at ${tsxCli}. Run "npm install" in ${repoRoot} first.\n`,
37
- );
38
- process.exit(1);
39
- }
40
- if (!existsSync(gatewayCli)) {
41
- process.stderr.write(`gateway CLI was not found at ${gatewayCli}.\n`);
42
- process.exit(1);
43
- }
19
+ const project = resolve(valueOf("project") ?? process.cwd());
20
+ const requested = valueOf("client");
21
+ const client = (requested ?? detectClient(project)) as McpClient;
44
22
  if (!existsSync(project)) {
45
23
  process.stderr.write(`project directory does not exist: ${project}\n`);
46
24
  process.exit(1);
47
25
  }
48
-
49
- const command = ["node", tsxCli, gatewayCli, "mcp", "--project", project];
50
-
51
- if (client === "opencode") {
52
- process.stdout.write(
53
- `${JSON.stringify(
54
- {
55
- $schema: "https://opencode.ai/config.json",
56
- mcp: {
57
- "ui-gateway": {
58
- type: "local",
59
- command,
60
- enabled: true,
61
- },
62
- },
63
- },
64
- null,
65
- 2,
66
- )}\n`,
67
- );
68
- } else {
69
- process.stdout.write(
70
- `${JSON.stringify(
71
- {
72
- mcpServers: {
73
- "ui-gateway": {
74
- command: command[0],
75
- args: command.slice(1),
76
- },
77
- },
78
- },
79
- null,
80
- 2,
81
- )}\n`,
82
- );
83
- }
84
-
85
- process.stderr.write(
86
- client === "opencode"
87
- ? `\nPaste the "mcp" entry above into your OpenCode config. --project is ${project}.\n`
88
- : `\nPaste the JSON above into your MCP client config. --project is ${project}.\n` +
89
- `Use "npm run mcp:config -- --project <dir> --client opencode" for OpenCode.\n`,
90
- );
26
+ const write = args.includes("--write");
27
+ const rendered = renderMcpConfig({ project, client });
28
+ const config = write
29
+ ? mergeMcpConfig(readJsonIfPresent(join(project, rendered.target)), rendered.config)
30
+ : rendered.config;
31
+ if (write) writeFileSync(join(project, rendered.target), `${JSON.stringify(config, null, 2)}\n`, "utf8");
32
+ process.stdout.write(`${JSON.stringify(config, null, 2)}\n`);
33
+ process.stderr.write(`${rendered.instructions}${write ? ` Written to ${rendered.target}.` : ""}\n`);
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Bundle the skill, references, examples and a ready MCP config into one
4
+ * directory that can be dropped into a plugin marketplace or copied to a
5
+ * client's skill location. Run with `npm run plugin:bundle`.
6
+ */
7
+ import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+
10
+ const out = join(process.cwd(), ".tmp", "ui-gateway-plugin");
11
+ rmSync(out, { recursive: true, force: true });
12
+ mkdirSync(out, { recursive: true });
13
+
14
+ for (const entry of ["SKILL.md", "references", "examples"]) {
15
+ const source = join(process.cwd(), entry);
16
+ if (!existsSync(source)) {
17
+ console.error(`missing ${entry}`);
18
+ process.exit(1);
19
+ }
20
+ cpSync(source, join(out, entry), { recursive: true });
21
+ }
22
+
23
+ writeFileSync(
24
+ join(out, ".mcp.json"),
25
+ `${JSON.stringify(
26
+ {
27
+ mcpServers: {
28
+ "ui-gateway": { command: "npx", args: ["-y", "ui-gateway", "mcp", "--project", "."] },
29
+ },
30
+ },
31
+ null,
32
+ 2,
33
+ )}\n`,
34
+ );
35
+
36
+ writeFileSync(
37
+ join(out, "README.md"),
38
+ [
39
+ "# UI Gateway plugin",
40
+ "",
41
+ "This directory is a self-contained skill bundle.",
42
+ "",
43
+ "1. Copy `SKILL.md`, `references/` and `examples/` to your client's skill location.",
44
+ "2. Merge `.mcp.json` into the client's MCP config.",
45
+ "3. Or run `npx ui-gateway init --project <app>` to do both.",
46
+ "",
47
+ ].join("\n"),
48
+ );
49
+
50
+ console.log(`plugin bundle written to ${out}`);
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generate a CycloneDX-style SBOM from package-lock.json. No network access.
4
+ * Usage: node scripts/sbom.mjs [--out path]
5
+ */
6
+ import { readFileSync, writeFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+
9
+ const args = process.argv.slice(2);
10
+ const outIndex = args.indexOf("--out");
11
+ const out = outIndex >= 0 ? args[outIndex + 1] : join(".tmp", "sbom.cdx.json");
12
+ const lock = JSON.parse(readFileSync(join(process.cwd(), "package-lock.json"), "utf8"));
13
+ const root = JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf8"));
14
+
15
+ const components = Object.entries(lock.packages ?? {})
16
+ .filter(([path]) => path.startsWith("node_modules/"))
17
+ .map(([path, pkg]) => {
18
+ const name = path.replace(/^node_modules\//, "").replace(/\/node_modules\//g, "/");
19
+ return {
20
+ type: "library",
21
+ name,
22
+ version: pkg.version ?? "unknown",
23
+ purl: `pkg:npm/${name.replace("@", "%40")}@${pkg.version ?? "unknown"}`,
24
+ ...(pkg.license ? { licenses: [{ license: { id: String(pkg.license) } }] } : {}),
25
+ ...(pkg.dev ? { scope: "optional" } : {}),
26
+ };
27
+ });
28
+
29
+ writeFileSync(
30
+ out,
31
+ JSON.stringify(
32
+ {
33
+ bomFormat: "CycloneDX",
34
+ specVersion: "1.5",
35
+ version: 1,
36
+ metadata: {
37
+ timestamp: new Date().toISOString(),
38
+ component: { type: "application", name: root.name, version: root.version },
39
+ },
40
+ components,
41
+ },
42
+ null,
43
+ 2,
44
+ ),
45
+ );
46
+ console.error(`wrote ${components.length} components to ${out}`);
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Optional visual regression check. Compares two directories of screenshots
4
+ * (from Playwright, Chromatic, or any tool) by file bytes and reports
5
+ * added/removed/changed images. Exit 1 on drift.
6
+ *
7
+ * Usage: node scripts/visual-diff.mjs <baseline-dir> <current-dir> [--out report.json]
8
+ */
9
+ import { createHash } from "node:crypto";
10
+ import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
11
+ import { join, relative } from "node:path";
12
+
13
+ const [baselineDir, currentDir] = process.argv.slice(2).filter((arg) => !arg.startsWith("--"));
14
+ const outIndex = process.argv.indexOf("--out");
15
+ const out = outIndex >= 0 ? process.argv[outIndex + 1] : undefined;
16
+ if (!baselineDir || !currentDir || !existsSync(baselineDir) || !existsSync(currentDir)) {
17
+ console.error("usage: visual-diff <baseline-dir> <current-dir> [--out report.json]");
18
+ process.exit(2);
19
+ }
20
+
21
+ function images(root, dir = root) {
22
+ const found = [];
23
+ for (const entry of readdirSync(dir)) {
24
+ const path = join(dir, entry);
25
+ if (statSync(path).isDirectory()) found.push(...images(root, path));
26
+ else if (/\.(png|jpe?g|webp)$/i.test(entry)) found.push(relative(root, path).replace(/\\/g, "/"));
27
+ }
28
+ return found;
29
+ }
30
+
31
+ const hash = (path) => createHash("sha256").update(readFileSync(path)).digest("hex");
32
+ const baseline = new Map(images(baselineDir).map((file) => [file, hash(join(baselineDir, file))]));
33
+ const current = new Map(images(currentDir).map((file) => [file, hash(join(currentDir, file))]));
34
+
35
+ const added = [...current.keys()].filter((file) => !baseline.has(file));
36
+ const removed = [...baseline.keys()].filter((file) => !current.has(file));
37
+ const changed = [...current.keys()].filter(
38
+ (file) => baseline.has(file) && baseline.get(file) !== current.get(file),
39
+ );
40
+
41
+ const report = {
42
+ generated_at: new Date().toISOString(),
43
+ baseline: baselineDir,
44
+ current: currentDir,
45
+ added,
46
+ removed,
47
+ changed,
48
+ ok: added.length === 0 && removed.length === 0 && changed.length === 0,
49
+ };
50
+ if (out) writeFileSync(out, `${JSON.stringify(report, null, 2)}\n`);
51
+ process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
52
+ process.exit(report.ok ? 0 : 1);