ui-gateway 0.1.0 → 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 +148 -38
  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 +30 -7
  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
@@ -9,7 +9,7 @@ blindly retry.
9
9
  | Code | Meaning | Retryable | Agent action |
10
10
  | --- | --- | --- | --- |
11
11
  | `INVALID_HANDOFF` | Schema, Design MD or structural validation failed. | No | Fix the report (`design_errors`, `semantic_issues`) and rebuild. Do not resubmit unchanged. |
12
- | `INTEGRITY_MISMATCH` | The `design_md_hash`, project profile hash, result hash or event chain hash does not match. | Yes | Re-run `detect_project`, rebuild the handoff, submit with a new id. If it persists, stop and report. |
12
+ | `INTEGRITY_MISMATCH` | The `design_md_hash`, project profile hash, result hash or event chain hash does not match. | No | Re-run `detect_project`, rebuild the handoff, submit with a new id. Retrying the same bytes cannot succeed. |
13
13
  | `CONFLICT` | `handoff_id` was reused with different content, or operations conflict. | No | Use a new `handoff_id`. Do not overwrite another handoff's id. |
14
14
  | `UNSATISFIABLE_CONSTRAINTS` | The Design MD contradicts itself or the project. | No | Ask the user which constraint wins, or edit the Design MD; then rebuild. |
15
15
  | `NO_MATCH` | No verified component could be found. | No | Read `missing_information` / `alternatives`; ask the user. Consider a different intent split. |
@@ -29,6 +29,12 @@ with `id`, `label`, `intent_ids`, `order` and `required`), `nav_targets`,
29
29
  one region. `scaffold_mode: "page"` requires a plan; `build_handoff` derives
30
30
  one when omitted. See `references/patterns.md`.
31
31
 
32
+ `state_components` maps a required state name (`loading`, `empty`, `error`,
33
+ `disabled`) to a KB component id. When a state has an entry, the composed page
34
+ renders that declared component (wrapped in a `role="status"` element with an
35
+ accessible name) instead of the generic fallback text; states without an entry
36
+ keep the fallback. An unknown id is a typed refusal, never a guess.
37
+
32
38
  The direct `buildHandoff` TypeScript helper defaults to `all_intents_mapped` plus
33
39
  `scaffolds_compile`; pass an explicit array if you want the MCP tool's lighter
34
40
  default.
@@ -121,6 +127,15 @@ manually:
121
127
  A hash mismatch is a hard rejection. A correct hash with an invalid Design MD
122
128
  is still a rejection; `validate_handoff` now reports both.
123
129
 
130
+ ## Result hash
131
+
132
+ `result_hash` is sha256 over the result body with four fields removed:
133
+ `result_hash`, `started_at`, `completed_at` and `owner`. Timing and process
134
+ identity are not decisions, so the same handoff hashes the same across gateway
135
+ instances and clocks and the caller can re-hash a returned result to compare.
136
+ Anything that changes the decision — outcome, mappings, scaffolds, acceptance,
137
+ page verification — changes the hash.
138
+
124
139
  ## Idempotency and ownership
125
140
 
126
141
  - Re-submitting the same `handoff_id` with the same content returns the stored
@@ -142,7 +157,7 @@ See `examples/handoff.json` for a full, validated handoff and
142
157
  "correlation_id": "corr_demo",
143
158
  "design_md": "# Design MD: Demo\n\n## Tokens\n- color.primary: #0f172a\n...",
144
159
  "design_md_hash": "<from build_handoff>",
145
- "kb_version": "kb-2026.11.1",
160
+ "kb_version": "kb-2026.11.3",
146
161
  "wireframe": {
147
162
  "root": {
148
163
  "id": "page-root",
@@ -1,13 +1,59 @@
1
1
  # Outcomes and reporting
2
2
 
3
- `submit_handoff` returns either:
3
+ `submit_handoff` returns one shape:
4
4
 
5
- - `{ ok: true, result, state, ownership_returned }` — the gateway evaluated the
6
- handoff. `result.outcome` is the final outcome.
7
- - `{ ok: false, outcome, error, state, ownership_returned }` — the handoff was
8
- rejected, failed, or expired before a result was produced.
5
+ - `{ ok: true, outcome: "COMPLETED", result, error: null }` — success.
6
+ - `{ ok: false, outcome, result, error, blocking }` — every other outcome.
7
+ `result` is still present (read `mappings`, `alternatives`,
8
+ `missing_information` and `page`) except for `REJECTED`, where no result
9
+ exists.
9
10
 
10
- `get_handoff` returns the same result after the fact, plus `state`.
11
+ `ok` and `outcome` always agree: `ok` is true only for `COMPLETED`. Do not treat
12
+ `ok: false` as "no information returned"; read `outcome` to decide what to do.
13
+
14
+ `get_handoff` returns the same result after the fact, plus `state` and
15
+ `ownership_returned`.
16
+
17
+ ## Blocking
18
+
19
+ Every non-success response carries one `blocking` object, and the same object is
20
+ on the attached result, so a report does not have to walk nested checks:
21
+
22
+ ```json
23
+ {
24
+ "kind": "error",
25
+ "code": "KB_STALE",
26
+ "message": "handoff pins kb_version \"...\" but the gateway holds \"...\"",
27
+ "retryable": true,
28
+ "fix": ["Call describe_kb and rebuild with the returned kb_version."]
29
+ }
30
+ ```
31
+
32
+ | `kind` | Set when | `code` |
33
+ | --- | --- | --- |
34
+ | `error` | a typed gateway error ended the run | the error code (`KB_STALE`, `NO_MATCH`, ...) |
35
+ | `input` | the outcome is `NEEDS_INPUT` or `AMBIGUOUS` | the outcome |
36
+ | `acceptance` | an acceptance criterion failed under `PARTIAL` | `ACCEPTANCE_FAILED` |
37
+ | `page_check` | the composed page failed its own checks | the page issue code |
38
+
39
+ `fix` lists concrete next steps; report the first one instead of inventing a
40
+ workaround. `retryable: false` means resubmitting unchanged cannot succeed.
41
+
42
+ ## CLI exit codes
43
+
44
+ `ui-gateway submit` (and the other commands that submit a handoff) exit with one
45
+ code per outcome, so a script can tell the cases apart without parsing stdout:
46
+
47
+ | Exit code | Outcome |
48
+ | --- | --- |
49
+ | 0 | `COMPLETED` |
50
+ | 1 | `REJECTED` |
51
+ | 2 | internal error |
52
+ | 3 | `NEEDS_INPUT` |
53
+ | 4 | `PARTIAL` |
54
+ | 5 | `FAILED` |
55
+ | 6 | `AMBIGUOUS` |
56
+ | 7 | `EXPIRED` |
11
57
 
12
58
  ## Outcome table
13
59
 
@@ -20,9 +66,9 @@
20
66
  | `FAILED` | No acceptable result: no intent mapped, or `strict` turned any unmapped intent into a whole-handoff failure. | Report the errors and the intent interpretations. Do not write code. |
21
67
  | `EXPIRED` | The handoff deadline passed before evaluation. | Rebuild with a fresh deadline only if the user still wants it. |
22
68
 
23
- `SubmitResponse.ok === false` can have `outcome: "REJECTED"`, `"FAILED"`, or
24
- `"EXPIRED"`. `REJECTED` means pre-flight validation failed; there is no result
25
- to apply. Check `error.code` and `error.details`.
69
+ `REJECTED` means pre-flight validation failed; `result` is null and there is
70
+ nothing to apply. Check `error.code` and `error.details`. `FAILED` and `EXPIRED`
71
+ may still carry a result with per-intent errors, so read it before reporting.
26
72
 
27
73
  ## Intent statuses
28
74
 
@@ -53,8 +99,11 @@ to apply. Check `error.code` and `error.details`.
53
99
  a retrieved candidate or fix the KB/policy problem. A warning does not
54
100
  invalidate the mapping, but do not silently ignore it.
55
101
  9. `result.page_plan` and, in page mode, `result.page` — check `region_order`,
56
- `missing_intents` and `imports` before writing `Page.tsx`. Run
57
- `verify_page` on the composed page.
102
+ `missing_intents` and `imports` before writing `Page.tsx`. `result.page.verification`
103
+ is the gateway's own page-check report: when `passed` is false the outcome is
104
+ `PARTIAL` and `issues` names each problem (for example `BROKEN_ANCHOR`). Fix
105
+ the plan or ask; do not ship a page whose checks failed. Also run
106
+ `verify_page` yourself on the final files.
58
107
  10. `result.token_projection` — projected tokens for the target adapters.
59
108
  Merge them into the project theme; do not replace an existing theme file.
60
109
  11. `ownership_returned` (or `get_handoff`) — the gateway has released the
@@ -10,9 +10,9 @@ compose the mapped components into a page shell.
10
10
  {
11
11
  "primary_task": "Let the operator find an order and open its detail.",
12
12
  "regions": [
13
- { "id": "region-toolbar", "label": "Search and filters", "intent_ids": ["search"] },
14
- { "id": "region-results", "label": "Orders", "intent_ids": ["orders-table"] },
15
- { "id": "region-detail", "label": "Order detail", "intent_ids": ["order-detail"] }
13
+ { "id": "region-toolbar", "label": "Search and filters", "intent_ids": ["search"], "order": 0 },
14
+ { "id": "region-results", "label": "Orders", "intent_ids": ["orders-table"], "order": 1 },
15
+ { "id": "region-detail", "label": "Order detail", "intent_ids": ["order-detail"], "order": 2 }
16
16
  ],
17
17
  "nav_targets": [
18
18
  { "label": "Orders", "target": "#region-results", "intent_id": "orders-table" }
@@ -5,9 +5,22 @@ MCP. If MCP is unavailable, use the CLI equivalents in `README.md`.
5
5
 
6
6
  ## Tool order
7
7
 
8
+ Fast path (recommended):
9
+
10
+ ```text
11
+ map_ui({ intents, path: "." })
12
+ -> (write the returned scaffolds)
13
+ -> verify_page (for composed pages)
14
+ ```
15
+
16
+ `map_ui` composes detect -> derive Design MD -> build -> validate -> submit. Use
17
+ `mode: "lookup"` for a read-only ranking with no lease or event-log write.
18
+ Only use the granular flow when you need to inspect or edit an intermediate:
19
+
8
20
  ```text
9
21
  detect_project
10
22
  -> describe_kb
23
+ -> derive_design_md (or import_design_md for an existing file)
11
24
  -> import_design_md (reads DESIGN.md from disk, validates, returns content + hash)
12
25
  -> validate_design_md (repeat until ok)
13
26
  -> build_handoff
@@ -43,7 +56,10 @@ The MCP/HTTP server normally returns the KB it was started with (`--project`);
43
56
  `project_dir` is used only when no server KB is configured.
44
57
 
45
58
  Returns the KB `version`, `content_hash`, `libraries`, `entries` and
46
- `self_test`. Call it before choosing intents. Use the returned `version` as the
59
+ `self_test`. Each library carries `library_version` (the version line its entries
60
+ were verified against, for example `6.x`) and `source_url`; each entry carries
61
+ the same `library_version` and mappings repeat it. Keep generated code on that
62
+ version line. Call it before choosing intents. Use the returned `version` as the
47
63
  handoff's `kb_version` if you assemble a handoff manually.
48
64
 
49
65
  If `library` is unknown, returns `UNSUPPORTED` with the available ids.
@@ -133,7 +149,7 @@ Input:
133
149
  "design_md": "...",
134
150
  "intents": [{ "id": "save", "intent_type": "action", "elements": ["save-button"] }],
135
151
  "project": { "dir": "." },
136
- "acceptance_criteria": [{ "type": "all_intents_mapped" }],
152
+ "acceptance_criteria": [{ "type": "all_intents_mapped" }, { "type": "scaffolds_compile" }],
137
153
  "scaffold_mode": "page",
138
154
  "page_import_prefix": "@/components/intents"
139
155
  }
@@ -157,7 +173,9 @@ to that prefix, e.g. `@/components/intents/intent`. Write the scaffolds there.
157
173
 
158
174
  Defaults:
159
175
  - `project.dir` is the gateway's `--project` when omitted.
160
- - `acceptance_criteria` is `[{ "type": "all_intents_mapped" }]` when omitted.
176
+ - `acceptance_criteria` is the same `DEFAULT_ACCEPTANCE` as the library:
177
+ `[{ "type": "all_intents_mapped" }, { "type": "scaffolds_compile" }]`. The tool and
178
+ the orchestrator no longer disagree; pass a narrower list to skip compilation.
161
179
  - The wireframe is generated from the intents.
162
180
  - `kb_version` is the gateway's current KB version.
163
181
 
@@ -200,17 +218,21 @@ read `errors` and fix the cause.
200
218
 
201
219
  Input: `{ handoff: object }`.
202
220
 
203
- Returns the gateway response plus `state` and `ownership_returned`. Read
204
- `references/outcomes.md` before applying anything.
221
+ `ok` is true only when `outcome` is `COMPLETED`; every other outcome returns
222
+ `ok: false` with the result still attached (except `REJECTED`) and a single
223
+ `blocking` cause (`kind`, `code`, `message`, `retryable`, `fix`) — the same
224
+ object is on the result. Read `references/outcomes.md` before applying anything.
205
225
 
206
226
  Extra result fields when present:
207
227
  - `warnings`: typed non-fatal warnings, including `PREFERRED_COMPONENT_NOT_RETRIEVED`
208
228
  with `reason`, `suggested_fix` and the per-id `checks`.
209
229
  - `page_plan`: the contract the result was built against.
210
230
  - `page`: composed page shell (page mode only), with `region_order`,
211
- `missing_intents`, import wiring, `files` (`page.css`) and `providers` for
212
- mixed-library wrappers. Responsive code uses the mapped library's surface
213
- (Tailwind, MUI `sx`, Chakra props or external CSS).
231
+ `missing_intents`, import wiring, `files` (`page.css`), `providers` for
232
+ mixed-library wrappers, and `verification` — the page checks the gateway ran
233
+ on its own output (`passed`, `checks`, `issues`). A failing page check
234
+ downgrades `COMPLETED` to `PARTIAL`. Responsive code uses the mapped
235
+ library's surface (Tailwind, MUI `sx`, Chakra props or external CSS).
214
236
  - `token_projection`: Design MD tokens projected to each target adapter
215
237
  (`css-variables`, `theme-object` or `project-tokens`).
216
238
 
@@ -248,11 +270,15 @@ If the app already has a theme, the merge helper is the recommended entry point:
248
270
  Input: `{ code: string, filename?: string, files?: [{ filename, code }], page_plan?: object, compile?: boolean }`.
249
271
 
250
272
  Read-only check of a page source. Reports `issues` with `code`, `message` and
251
- `file`, plus checks named `syntax`, `anchors`, `ids`, `imports`, `responsive`, `a11y` and
252
- `landmarks`. It catches dead (`href="#"`) and broken anchors, missing page-plan
273
+ `file`, plus checks named `syntax`, `anchors`, `ids`, `imports`, `responsive`, `a11y`,
274
+ `landmarks` and `states`. It catches dead (`href="#"`) and broken anchors, missing page-plan
253
275
  region ids, duplicate ids, unused imports, missing `img` alt, links/buttons
254
276
  without an accessible name, a missing `<main>`, duplicate display utilities
255
- and conflicting responsive utilities at the same breakpoint. Responsive checks
277
+ and conflicting responsive utilities at the same breakpoint. When `page_plan`
278
+ declares `required_states`, the `states` check fails closed unless the page wires
279
+ each one as plain semantic HTML (a `state === "<state>"` branch, `aria-busy` for
280
+ `loading`, a `role="status"` message for `empty`/`error`) — no invented
281
+ components. Responsive checks
256
282
  cover Tailwind `className`, MUI `sx`, Chakra responsive props and scoped CSS
257
283
  declarations, including a supplied `page.css`. If related JS/TS files are
258
284
  passed, relative imports must resolve to one of them. When `compile` is `true`,
@@ -310,6 +336,39 @@ not from installed library types. It returns the tsc output and a boolean
310
336
  reported as `tsc timed out in the compile sandbox` with whatever output the
311
337
  process produced.
312
338
 
339
+ ### `map_ui`
340
+
341
+ Input: `{ intents: Intent[], path?: string, design_md?: string, mode?: "submit" | "lookup", scaffold_mode?: "component" | "page", k?: number }`.
342
+
343
+ Two-call happy path. Returns `design_md`, `design_hash`, `design_source`
344
+ (`derived` or `provided`), `handoff_id`, `outcome`, `acceptance`, per-intent
345
+ `mapping`/`scaffold`/`verification`/`missing_information`, `page`,
346
+ `token_projection` and `state`. In `lookup` mode it returns ranked candidates
347
+ per intent and writes nothing. A refused submit returns the typed response so
348
+ the caller can ask the user instead of retrying blindly.
349
+
350
+ ### `derive_design_md`
351
+
352
+ Input: `{ path?: string, design_md?: string, mode?: "greenfield" | "existing" }`.
353
+
354
+ Derives a strict Design MD from CSS custom properties, Tailwind theme values,
355
+ DTCG token files or an existing `DESIGN.md`. Returns `design_md`, `hash`,
356
+ `inferred`, `defaults`, `unknown`, `questions`, `sources`, `satisfiable`,
357
+ contradictions and validation. The neutral palette fills only tokens the project
358
+ does not define; `questions` lists the precise next steps (which defaulted brand
359
+ tokens to confirm, which constraints to resolve) so the caller is never forced to
360
+ author a full Design MD from scratch.
361
+
362
+ ### `refusal_ledger`
363
+
364
+ Input: `{ handoff_id?: string }`.
365
+
366
+ Reads the event log and groups repeated refusal reasons (`NEEDS_INPUT`,
367
+ `AMBIGUOUS`, `FAILED`, `PARTIAL`) with counts, affected handoffs and a suggested
368
+ fix. When the result carries a `blocking` object, its concrete `fix` steps are
369
+ used verbatim; otherwise a keyword heuristic fills in. Use it to turn recurring
370
+ refusals into a local component or a Design MD change.
371
+
313
372
  ### `get_handoff`
314
373
 
315
374
  Input: `{ handoff_id: string }`.
@@ -339,29 +398,28 @@ Read `ui-gateway://reference/handoff` before building your first handoff.
339
398
 
340
399
  ## MCP setup
341
400
 
342
- From the gateway repository, print a ready-to-paste config:
401
+ One command detects the client, writes/merges the config and copies the skill:
402
+
403
+ ```bash
404
+ npx ui-gateway init --project /absolute/path/to/your/app
405
+ ```
406
+
407
+ To print a config without writing anything:
343
408
 
344
409
  ```bash
345
- npm install
346
- npm run mcp:config -- --project /absolute/path/to/your/app
410
+ npx ui-gateway mcp:config --project /absolute/path/to/your/app
411
+ npx ui-gateway mcp:config --project /absolute/path/to/your/app --client cursor
347
412
  ```
348
413
 
349
- The output uses the repository's local `tsx` and the target project path. Add it
350
- to your MCP client's config (for example `.mcp.json` or the client's settings).
351
- The important parts are:
414
+ `--client` accepts `generic`, `claude`, `cursor`, `vscode` and `opencode`. The
415
+ published command is:
352
416
 
353
417
  ```json
354
418
  {
355
419
  "mcpServers": {
356
420
  "ui-gateway": {
357
- "command": "node",
358
- "args": [
359
- "<gateway-repo>/node_modules/tsx/dist/cli.mjs",
360
- "<gateway-repo>/packages/transports/src/cli.ts",
361
- "mcp",
362
- "--project",
363
- "/absolute/path/to/your/app"
364
- ]
421
+ "command": "npx",
422
+ "args": ["-y", "ui-gateway", "mcp", "--project", "/absolute/path/to/your/app"]
365
423
  }
366
424
  }
367
425
  }
@@ -369,7 +427,8 @@ The important parts are:
369
427
 
370
428
  `--project` is the application the agent is editing, not the gateway repository.
371
429
  Relative tool paths resolve against it. Restart the client after changing the
372
- config.
430
+ config. Without MCP, `npx ui-gateway init --project <app> --print-skill` prints
431
+ the CLI-mode skill.
373
432
 
374
433
  If your client supports environment variables, set the project path there
375
434
  instead of hard-coding it. Do not point `--project` at a parent directory that
@@ -378,7 +437,7 @@ contains unrelated projects; `detect_project` will read its files.
378
437
  ## HTTP alternative
379
438
 
380
439
  ```bash
381
- npm run cli -- http --project /absolute/path/to/your/app --port 3456
440
+ npx ui-gateway http --project /absolute/path/to/your/app --port 3456
382
441
  ```
383
442
 
384
443
  Then call `/tools`, `/tools/call`, `/handoff`, `/validate`, `/validate-design`,
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post inline PR review comments for ui-gateway check findings.
4
+ * Uses the REST review-comment API, so it works with the default GITHUB_TOKEN
5
+ * and does not need Octokit. Failures are reported but never fail the build;
6
+ * the check step owns the exit status.
7
+ */
8
+ import { readFileSync } from "node:fs";
9
+
10
+ const reportPath = process.argv[2];
11
+ const token = process.env.GITHUB_TOKEN;
12
+ const repository = process.env.GITHUB_REPOSITORY;
13
+ const eventPath = process.env.GITHUB_EVENT_PATH;
14
+
15
+ if (!reportPath || !token || !repository || !eventPath) {
16
+ console.error("action-review: missing report path, token, repository or event payload");
17
+ process.exit(0);
18
+ }
19
+
20
+ const report = JSON.parse(readFileSync(reportPath, "utf8"));
21
+ const event = JSON.parse(readFileSync(eventPath, "utf8"));
22
+ const pull = event.pull_request;
23
+ if (!pull) process.exit(0);
24
+
25
+ const findings = (report.findings ?? []).filter(
26
+ (finding) => finding.line && finding.severity === "error",
27
+ );
28
+ if (findings.length === 0) process.exit(0);
29
+
30
+ const [owner, repo] = repository.split("/");
31
+ const body = (finding) =>
32
+ `**ui-gateway:** ${finding.code}\n\n${finding.message}\n\n` +
33
+ `Fix or, if this is intentional, change the Design MD so the constraint matches.`;
34
+
35
+ let posted = 0;
36
+ for (const finding of findings.slice(0, 50)) {
37
+ const response = await fetch(
38
+ `https://api.github.com/repos/${owner}/${repo}/pulls/${pull.number}/comments`,
39
+ {
40
+ method: "POST",
41
+ headers: {
42
+ authorization: `Bearer ${token}`,
43
+ accept: "application/vnd.github+json",
44
+ "content-type": "application/json",
45
+ "user-agent": "ui-gateway-check",
46
+ },
47
+ body: JSON.stringify({
48
+ body: body(finding),
49
+ commit_id: pull.head.sha,
50
+ path: finding.file,
51
+ line: finding.line,
52
+ side: "RIGHT",
53
+ }),
54
+ },
55
+ );
56
+ if (response.ok) posted += 1;
57
+ else console.error(`action-review: ${response.status} ${await response.text()}`);
58
+ }
59
+ console.error(`action-review: posted ${posted} inline comment(s)`);
@@ -0,0 +1,90 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { performance } from "node:perf_hooks";
4
+ import { buildKnowledgeBase, createDefaultAdapters } from "@uigw/adapters";
5
+ import { createGateway } from "@uigw/gateway";
6
+ import { buildHandoff } from "@uigw/orchestrator";
7
+ import { detectProject } from "@uigw/profile";
8
+ import type { Handoff } from "@uigw/protocol";
9
+
10
+ const fixtures = join(process.cwd(), "evals", "fixtures");
11
+ const design = readFileSync(join(fixtures, "design-md", "default.md"), "utf8");
12
+ const projectDir = join(fixtures, "projects", "greenfield-react");
13
+
14
+ const iterations = Number(process.env.BENCH_N ?? 20);
15
+ const warmup = Number(process.env.BENCH_WARMUP ?? 3);
16
+
17
+ function percentile(sorted: number[], p: number): number {
18
+ if (sorted.length === 0) return 0;
19
+ const index = Math.min(sorted.length - 1, Math.max(0, Math.ceil((p / 100) * sorted.length) - 1));
20
+ return sorted[index];
21
+ }
22
+
23
+ function summarize(label: string, samples: number[]): void {
24
+ const sorted = [...samples].sort((a, b) => a - b);
25
+ const mean = samples.reduce((sum, value) => sum + value, 0) / samples.length;
26
+ console.log(`\n=== ${label} (n=${samples.length}) ===`);
27
+ console.log(` mean ${mean.toFixed(1)} ms`);
28
+ console.log(` p50 ${percentile(sorted, 50).toFixed(1)} ms`);
29
+ console.log(` p90 ${percentile(sorted, 90).toFixed(1)} ms`);
30
+ console.log(` p99 ${percentile(sorted, 99).toFixed(1)} ms`);
31
+ console.log(` min ${sorted[0].toFixed(1)} ms`);
32
+ console.log(` max ${sorted[sorted.length - 1].toFixed(1)} ms`);
33
+ }
34
+
35
+ async function main(): Promise<number> {
36
+ const gateway = createGateway({
37
+ kb: buildKnowledgeBase({ adapters: createDefaultAdapters(), profile: detectProject(projectDir) }),
38
+ compile: "off",
39
+ });
40
+
41
+ const base = buildHandoff({
42
+ design_md: design,
43
+ project: { dir: projectDir },
44
+ intents: [
45
+ {
46
+ id: "submit-order",
47
+ intent_type: "action",
48
+ description: "Primary submit button for the checkout form",
49
+ elements: ["submit-button"],
50
+ attributes: { interaction: "click" },
51
+ },
52
+ {
53
+ id: "orders-table",
54
+ intent_type: "data_display",
55
+ description: "Table of recent orders with status and total columns",
56
+ elements: ["orders-table"],
57
+ attributes: { content_size: "large" },
58
+ },
59
+ ],
60
+ });
61
+
62
+ const runOnce = async (id: string): Promise<number> => {
63
+ const handoff: Handoff = { ...base, handoff_id: id };
64
+ const start = performance.now();
65
+ await gateway.submit(handoff);
66
+ return performance.now() - start;
67
+ };
68
+
69
+ for (let i = 0; i < warmup; i += 1) {
70
+ await runOnce(`bench-warmup-${i}`);
71
+ }
72
+
73
+ const samples: number[] = [];
74
+ for (let i = 0; i < iterations; i += 1) {
75
+ samples.push(await runOnce(`bench-${i}`));
76
+ }
77
+
78
+ summarize("gateway.submit (handoff -> result)", samples);
79
+ console.log(`\nReproduce: BENCH_N=${iterations} BENCH_WARMUP=${warmup} npm run bench`);
80
+ return 0;
81
+ }
82
+
83
+ main()
84
+ .then((code) => {
85
+ process.exitCode = code;
86
+ })
87
+ .catch((error) => {
88
+ process.stderr.write(`${(error as Error).stack ?? String(error)}\n`);
89
+ process.exitCode = 2;
90
+ });