@reqvire-org/ads 0.4.0 → 0.4.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 (394) hide show
  1. package/README.md +105 -86
  2. package/dist/a11y.mjs +108 -29
  3. package/dist/analysis/compiler-options.mjs +13 -0
  4. package/dist/analysis/context.mjs +46 -0
  5. package/dist/analysis/file-tree.mjs +52 -0
  6. package/dist/analysis/helpers.mjs +140 -0
  7. package/dist/analysis/impact.mjs +20 -0
  8. package/dist/analysis/inputs.mjs +15 -0
  9. package/dist/analysis/native-adapter.mjs +180 -0
  10. package/dist/analysis/native-project.mjs +323 -0
  11. package/dist/analysis/queries.mjs +133 -0
  12. package/dist/analysis/service.mjs +146 -0
  13. package/dist/analysis/standalone.mjs +57 -0
  14. package/dist/analysis/syntax.mjs +164 -0
  15. package/dist/analysis/worker.mjs +182 -0
  16. package/dist/assets.mjs +5 -5
  17. package/dist/atomic-composition.mjs +191 -70
  18. package/dist/atomic-trace.mjs +120 -50
  19. package/dist/behavior-libraries.mjs +106 -37
  20. package/dist/behaviors.mjs +219 -77
  21. package/dist/boundaries.mjs +135 -38
  22. package/dist/brand-assets.mjs +219 -47
  23. package/dist/brands.mjs +86 -27
  24. package/dist/bun-compiler.mjs +28 -14
  25. package/dist/bun-worker.mjs +7 -5
  26. package/dist/capture/worker.mjs +15 -4
  27. package/dist/capture-store.mjs +4 -2
  28. package/dist/capture.mjs +17 -14
  29. package/dist/check-service.mjs +40 -57
  30. package/dist/check.mjs +749 -188
  31. package/dist/cli.mjs +200 -99
  32. package/dist/color-values.mjs +21 -21
  33. package/dist/component-contrast.mjs +2 -2
  34. package/dist/config.mjs +303 -135
  35. package/dist/construction-styles.cjs +10 -0
  36. package/dist/control-padding.mjs +45 -25
  37. package/dist/css-values.mjs +3 -2
  38. package/dist/declarative-flow.mjs +209 -109
  39. package/dist/design-values.mjs +136 -51
  40. package/dist/development-runtime.mjs +4 -6
  41. package/dist/draft-boundary.mjs +11 -6
  42. package/dist/evidence.mjs +1 -1
  43. package/dist/finding-rules.mjs +7 -5
  44. package/dist/font-rules.mjs +2 -2
  45. package/dist/fonts-generated.mjs +2 -2
  46. package/dist/foundation-views.mjs +238 -0
  47. package/dist/foundation.mjs +63 -39
  48. package/dist/generated-entries.mjs +101 -34
  49. package/dist/icons.mjs +79 -32
  50. package/dist/image-attributes.mjs +109 -36
  51. package/dist/image-size.mjs +1 -1
  52. package/dist/index.mjs +0 -2
  53. package/dist/init.mjs +122 -41
  54. package/dist/investigations.mjs +2 -2
  55. package/dist/layers.mjs +298 -129
  56. package/dist/layout-widths.mjs +180 -85
  57. package/dist/linaria/preserve-values.cjs +7 -0
  58. package/dist/linaria/spatial-inputs.cjs +56 -0
  59. package/dist/lockup-composition.mjs +44 -0
  60. package/dist/lockup-model.cjs +64 -0
  61. package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
  62. package/dist/mcp/apps.mjs +4 -30
  63. package/dist/mcp/behavior-pages.mjs +72 -24
  64. package/dist/mcp/build-status.mjs +257 -64
  65. package/dist/mcp/catalog.mjs +90 -26
  66. package/dist/mcp/context.mjs +17 -18
  67. package/dist/mcp/draft-discovery.mjs +44 -21
  68. package/dist/mcp/drafts.mjs +901 -281
  69. package/dist/mcp/execution-coordinator.mjs +417 -167
  70. package/dist/mcp/execution-results.mjs +7 -7
  71. package/dist/mcp/mutations.mjs +670 -234
  72. package/dist/mcp/preview-watch.mjs +448 -170
  73. package/dist/mcp/preview-widget.bundle.js +44 -50
  74. package/dist/mcp/prompts.mjs +5 -5
  75. package/dist/mcp/result-pages.mjs +1 -1
  76. package/dist/mcp/sandbox-host.mjs +1 -1
  77. package/dist/mcp/server.mjs +2402 -577
  78. package/dist/mcp/showcase-host.mjs +165 -41
  79. package/dist/mcp/skills.mjs +1 -1
  80. package/dist/mcp/text-diff.mjs +29 -10
  81. package/dist/paint-contracts.mjs +174 -81
  82. package/dist/palette-generated.mjs +2 -2
  83. package/dist/preview-bun.mjs +493 -187
  84. package/dist/preview-failure.mjs +1 -1
  85. package/dist/preview-files.mjs +13 -13
  86. package/dist/preview-imports.mjs +104 -55
  87. package/dist/preview-inputs.mjs +2 -2
  88. package/dist/preview-requests.mjs +24 -0
  89. package/dist/preview-resources.mjs +288 -147
  90. package/dist/preview-scope.mjs +5 -4
  91. package/dist/program-cache.mjs +8 -34
  92. package/dist/project-documents.mjs +1 -1
  93. package/dist/public-api.mjs +69 -31
  94. package/dist/public-props.mjs +39 -22
  95. package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
  96. package/dist/{browser-audit → render-audit}/image-shape.mjs +2 -2
  97. package/dist/{browser-audit → render-audit}/layout-overflow.mjs +86 -23
  98. package/dist/{browser-audit → render-audit}/non-text-contrast.mjs +86 -27
  99. package/dist/{browser-audit → render-audit}/render-states.mjs +208 -52
  100. package/dist/{browser-audit → render-audit}/worker.mjs +86 -30
  101. package/dist/render-audit.mjs +828 -0
  102. package/dist/render-color-probe.mjs +96 -42
  103. package/dist/resource-limits.mjs +229 -97
  104. package/dist/runtime-contracts.mjs +467 -185
  105. package/dist/scenario-groups.mjs +22 -10
  106. package/dist/scenario-inspector.mjs +6 -43
  107. package/dist/scenario-program.mjs +8 -25
  108. package/dist/scenario-registry.mjs +72 -30
  109. package/dist/scenario-selectors.mjs +161 -64
  110. package/dist/scenario-slots.mjs +149 -56
  111. package/dist/scenario-trace.mjs +215 -109
  112. package/dist/scenarios-compiler.mjs +719 -378
  113. package/dist/scenarios-vite.d.mts +1 -3
  114. package/dist/scenarios-vite.mjs +2 -81
  115. package/dist/scenarios.mjs +421 -157
  116. package/dist/selector-match.mjs +2 -2
  117. package/dist/showcase/client.bundle.js +57 -56
  118. package/dist/showcase/draft-navigation.js +18 -0
  119. package/dist/showcase/favicon.ico +0 -0
  120. package/dist/showcase/favicon.svg +1 -0
  121. package/dist/showcase/foundation-view.css +55 -0
  122. package/dist/showcase/foundation-view.mjs +252 -0
  123. package/dist/showcase/guide-controls.ads.review.mjs +32 -0
  124. package/dist/showcase/icons.js +1 -145
  125. package/dist/showcase/index.html +3 -31
  126. package/dist/showcase/preview-frame.ads.review.css +46 -0
  127. package/dist/showcase/preview-frame.ads.review.d.mts +11 -0
  128. package/dist/showcase/preview-frame.ads.review.mjs +22 -0
  129. package/dist/showcase/preview-state.js +0 -9
  130. package/dist/showcase/refresh-scheduler.js +23 -0
  131. package/dist/showcase/style.css +5 -47
  132. package/dist/showcase/ui/ui.css +1353 -0
  133. package/dist/showcase/ui/ui.js +1062 -0
  134. package/dist/showcase-coverage.mjs +58 -37
  135. package/dist/skills/README.md +24 -23
  136. package/dist/skills/ads-designer/README.md +8 -2
  137. package/dist/skills/ads-designer/SKILL.md +130 -119
  138. package/dist/skills/ads-designer/references/accessibility.md +12 -13
  139. package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
  140. package/dist/skills/ads-designer/references/behaviors.md +30 -27
  141. package/dist/skills/ads-designer/references/branding.md +98 -10
  142. package/dist/skills/ads-designer/references/captures.md +25 -0
  143. package/dist/skills/ads-designer/references/cli.md +21 -24
  144. package/dist/skills/ads-designer/references/contracts.md +7 -6
  145. package/dist/skills/ads-designer/references/design-data.md +49 -52
  146. package/dist/skills/ads-designer/references/drafts.md +20 -17
  147. package/dist/skills/ads-designer/references/evidence.md +1 -5
  148. package/dist/skills/ads-designer/references/guarded-editing.md +14 -18
  149. package/dist/skills/ads-designer/references/layers.md +1 -1
  150. package/dist/skills/ads-designer/references/layout.md +347 -0
  151. package/dist/skills/ads-designer/references/mobile.md +2 -1
  152. package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
  153. package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
  154. package/dist/skills/ads-designer/references/review.md +37 -34
  155. package/dist/skills/ads-designer/references/runtimes.md +33 -30
  156. package/dist/skills/ads-designer/references/scenarios.md +16 -18
  157. package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
  158. package/dist/skills/ads-designer/references/stress-test.md +68 -0
  159. package/dist/skills/ads-designer/references/validation.md +83 -75
  160. package/dist/skills/ads-designer/references/workflows.md +8 -33
  161. package/dist/skills/ads-import/SKILL.md +43 -325
  162. package/dist/skills/ads-import/references/atomic-styles.md +4 -4
  163. package/dist/skills/ads-import/references/behaviors.md +30 -27
  164. package/dist/skills/ads-import/references/branding.md +5 -5
  165. package/dist/skills/ads-import/references/captures.md +25 -0
  166. package/dist/skills/ads-import/references/cli.md +21 -24
  167. package/dist/skills/ads-import/references/compatibility.md +1 -1
  168. package/dist/skills/ads-import/references/contracts.md +7 -6
  169. package/dist/skills/ads-import/references/design-data.md +49 -52
  170. package/dist/skills/ads-import/references/drafts.md +20 -17
  171. package/dist/skills/ads-import/references/evidence.md +1 -5
  172. package/dist/skills/ads-import/references/guarded-editing.md +14 -18
  173. package/dist/skills/ads-import/references/implementation.md +2 -1
  174. package/dist/skills/ads-import/references/layers.md +1 -1
  175. package/dist/skills/ads-import/references/layout.md +347 -0
  176. package/dist/skills/ads-import/references/review.md +37 -34
  177. package/dist/skills/ads-import/references/runtimes.md +33 -30
  178. package/dist/skills/ads-import/references/scenarios.md +16 -18
  179. package/dist/skills/ads-import/references/tokens.md +3 -3
  180. package/dist/skills/ads-import/references/validation.md +83 -75
  181. package/dist/skills/ads-import/references/workflows.md +8 -33
  182. package/dist/skills/ads-migrate/SKILL.md +56 -0
  183. package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
  184. package/dist/skills/ads-port/SKILL.md +54 -343
  185. package/dist/skills/ads-port/references/atomic-styles.md +4 -4
  186. package/dist/skills/ads-port/references/behaviors.md +30 -27
  187. package/dist/skills/ads-port/references/captures.md +25 -0
  188. package/dist/skills/ads-port/references/cli.md +21 -24
  189. package/dist/skills/ads-port/references/contracts.md +7 -6
  190. package/dist/skills/ads-port/references/design-data.md +49 -52
  191. package/dist/skills/ads-port/references/drafts.md +20 -17
  192. package/dist/skills/ads-port/references/evidence.md +1 -5
  193. package/dist/skills/ads-port/references/guarded-editing.md +14 -18
  194. package/dist/skills/ads-port/references/layers.md +1 -1
  195. package/dist/skills/ads-port/references/layout.md +347 -0
  196. package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
  197. package/dist/skills/ads-port/references/native-implementation.md +2 -1
  198. package/dist/skills/ads-port/references/review.md +37 -34
  199. package/dist/skills/ads-port/references/runtimes.md +33 -30
  200. package/dist/skills/ads-port/references/scenarios.md +16 -18
  201. package/dist/skills/ads-port/references/validation.md +83 -75
  202. package/dist/skills/ads-port/references/workflows.md +8 -33
  203. package/dist/source-symbols.mjs +1 -8
  204. package/dist/source-values.mjs +266 -128
  205. package/dist/spatial-composition.mjs +322 -0
  206. package/dist/spatial-contexts.cjs +56 -0
  207. package/dist/spatial-css.cjs +351 -0
  208. package/dist/spatial-inputs.cjs +80 -0
  209. package/dist/spatial-metadata.mjs +18 -0
  210. package/dist/spatial-model.cjs +322 -0
  211. package/dist/spatial.mjs +21 -0
  212. package/dist/stage-timing.cjs +20 -0
  213. package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +105 -0
  214. package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +275 -0
  215. package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
  216. package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
  217. package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +8 -0
  218. package/dist/starters/preact/ds.config.json +25 -6
  219. package/dist/starters/preact/package.json +4 -8
  220. package/dist/starters/preact/tsconfig.json +4 -5
  221. package/dist/starters/preact/vite.config.ts +3 -3
  222. package/dist/starters/react/ADS.md +42 -47
  223. package/dist/starters/react/README.md +47 -49
  224. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +18 -2
  225. package/dist/starters/react/design-system/components/Actions/IconButton/README.md +3 -0
  226. package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +5 -0
  227. package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
  228. package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
  229. package/dist/starters/react/design-system/index.ts +2 -1
  230. package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
  231. package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
  232. package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
  233. package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
  234. package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
  235. package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
  236. package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
  237. package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
  238. package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
  239. package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
  240. package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
  241. package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
  242. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -1
  243. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
  244. package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
  245. package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
  246. package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
  247. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -1
  248. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
  249. package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
  250. package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
  251. package/dist/starters/react/design-system/tokens/colors.css +1 -1
  252. package/dist/starters/react/design-system/tokens/spacing.css +22 -32
  253. package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
  254. package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
  255. package/dist/starters/react/ds.config.json +25 -6
  256. package/dist/starters/react/package.json +2 -6
  257. package/dist/starters/react/tsconfig.json +2 -3
  258. package/dist/starters/react/vite.config.ts +3 -3
  259. package/dist/style-boundaries.mjs +70 -25
  260. package/dist/task-cache.mjs +173 -72
  261. package/dist/task-worker.mjs +22 -11
  262. package/dist/test-boundaries.mjs +132 -59
  263. package/dist/themes-generated.mjs +1 -1
  264. package/dist/themes-watch.mjs +57 -22
  265. package/dist/themes.mjs +176 -73
  266. package/dist/token-export.mjs +39 -14
  267. package/dist/token-policy.mjs +6 -3
  268. package/dist/token-quality.mjs +6 -6
  269. package/dist/token-samples.mjs +16 -5
  270. package/dist/tokens.mjs +71 -26
  271. package/dist/ui-framework.mjs +16 -14
  272. package/dist/unit-contracts.mjs +251 -104
  273. package/dist/units.mjs +208 -98
  274. package/dist/usage.mjs +138 -38
  275. package/dist/validation-checks.mjs +115 -38
  276. package/dist/validation-inputs.mjs +187 -78
  277. package/dist/validation.mjs +268 -102
  278. package/dist/verification/browser.mjs +27 -5
  279. package/dist/verification.mjs +711 -187
  280. package/docs/ADS.md +90 -79
  281. package/docs/ARCHITECTURE.md +294 -136
  282. package/docs/BEHAVIORS.md +29 -25
  283. package/docs/CACHING.md +52 -17
  284. package/docs/CHANGELOG.md +309 -17
  285. package/docs/CONTRACTS.md +12 -4
  286. package/docs/DESIGN-REFERENCES.md +40 -0
  287. package/docs/GUIDE.md +270 -258
  288. package/docs/MCP.md +181 -324
  289. package/docs/SPATIAL-CHECKS.md +69 -0
  290. package/docs/benchmarks/README.md +39 -0
  291. package/package.json +42 -34
  292. package/dist/browser-audit.mjs +0 -429
  293. package/dist/create.mjs +0 -48
  294. package/dist/lint-config.mjs +0 -50
  295. package/dist/mcp/project-widget.bundle.js +0 -114
  296. package/dist/mcp/reports.mjs +0 -101
  297. package/dist/mcp/widget.bundle.js +0 -147
  298. package/dist/oxlint.mjs +0 -89
  299. package/dist/preview-builder.mjs +0 -133
  300. package/dist/preview-workers.mjs +0 -184
  301. package/dist/showcase.mjs +0 -77
  302. package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
  303. package/dist/skills/ads-break-ui/README.md +0 -16
  304. package/dist/skills/ads-break-ui/SKILL.md +0 -412
  305. package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
  306. package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
  307. package/dist/skills/ads-break-ui/references/behaviors.md +0 -412
  308. package/dist/skills/ads-break-ui/references/captures.md +0 -135
  309. package/dist/skills/ads-break-ui/references/contracts.md +0 -317
  310. package/dist/skills/ads-break-ui/references/design-data.md +0 -354
  311. package/dist/skills/ads-break-ui/references/drafts.md +0 -194
  312. package/dist/skills/ads-break-ui/references/evidence.md +0 -128
  313. package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -165
  314. package/dist/skills/ads-break-ui/references/layers.md +0 -145
  315. package/dist/skills/ads-break-ui/references/reporting.md +0 -101
  316. package/dist/skills/ads-break-ui/references/review.md +0 -97
  317. package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
  318. package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
  319. package/dist/skills/ads-break-ui/references/validation.md +0 -166
  320. package/dist/skills/ads-break-ui/references/verification.md +0 -58
  321. package/dist/skills/ads-break-ui/references/workflows.md +0 -90
  322. package/dist/skills/ads-designer/references/reporting.md +0 -101
  323. package/dist/skills/ads-import/references/reporting.md +0 -101
  324. package/dist/skills/ads-motion/LICENSE.upstream +0 -21
  325. package/dist/skills/ads-motion/README.md +0 -22
  326. package/dist/skills/ads-motion/SKILL.md +0 -385
  327. package/dist/skills/ads-motion/agents/openai.yaml +0 -4
  328. package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
  329. package/dist/skills/ads-motion/references/audit.md +0 -44
  330. package/dist/skills/ads-motion/references/behaviors.md +0 -412
  331. package/dist/skills/ads-motion/references/captures.md +0 -135
  332. package/dist/skills/ads-motion/references/contracts.md +0 -317
  333. package/dist/skills/ads-motion/references/design-data.md +0 -354
  334. package/dist/skills/ads-motion/references/drafts.md +0 -194
  335. package/dist/skills/ads-motion/references/evidence.md +0 -128
  336. package/dist/skills/ads-motion/references/guarded-editing.md +0 -165
  337. package/dist/skills/ads-motion/references/layers.md +0 -145
  338. package/dist/skills/ads-motion/references/motion-review.md +0 -35
  339. package/dist/skills/ads-motion/references/reporting.md +0 -101
  340. package/dist/skills/ads-motion/references/review.md +0 -97
  341. package/dist/skills/ads-motion/references/runtimes.md +0 -203
  342. package/dist/skills/ads-motion/references/scenarios.md +0 -246
  343. package/dist/skills/ads-motion/references/validation.md +0 -166
  344. package/dist/skills/ads-motion/references/verification.md +0 -39
  345. package/dist/skills/ads-motion/references/workflows.md +0 -90
  346. package/dist/skills/ads-port/references/reporting.md +0 -101
  347. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
  348. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
  349. package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
  350. package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
  351. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
  352. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
  353. package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
  354. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
  355. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
  356. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
  357. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
  358. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
  359. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +0 -1
  360. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
  361. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
  362. package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
  363. package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
  364. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +0 -1
  365. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
  366. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
  367. package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +0 -1
  368. package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
  369. package/dist/starters/react/design-system/review/index.ts +0 -6
  370. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
  371. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
  372. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +0 -1
  373. package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
  374. package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
  375. package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
  376. package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
  377. package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
  378. package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
  379. package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
  380. package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
  381. package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
  382. package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
  383. package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
  384. package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
  385. package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
  386. package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
  387. package/dist/starters/react/package-lock.json +0 -4707
  388. package/dist/token-fixtures.mjs +0 -30
  389. package/docs/benchmarks/bun-previews.md +0 -91
  390. package/docs/benchmarks/preview-memory.md +0 -147
  391. package/docs/benchmarks/turbo-poc.md +0 -284
  392. package/docs/plans/execution-coordination.md +0 -57
  393. /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
  394. /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
@@ -1,16 +1,31 @@
1
+ import { mapAsync } from "../analysis/queries.mjs";
1
2
  import { trackExecutionWorkspace } from "./execution-context.mjs";
2
3
  import { createHash, randomUUID } from "node:crypto";
3
- import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
4
+ import {
5
+ cpSync,
6
+ existsSync,
7
+ lstatSync,
8
+ mkdirSync,
9
+ mkdtempSync,
10
+ readFileSync,
11
+ readdirSync,
12
+ realpathSync,
13
+ renameSync,
14
+ rmSync,
15
+ symlinkSync,
16
+ writeFileSync,
17
+ } from "node:fs";
4
18
  import path from "node:path";
5
19
  import { hasProjectConfig } from "../project-boundary.mjs";
6
- import ts from "typescript";
20
+ import ts from "../analysis/syntax.mjs";
7
21
  import { isInside, loadConfig } from "../config.mjs";
8
- import { affectedBehaviorUnits, createVerificationController } from "../verification.mjs";
22
+ import { createVerificationController } from "../verification.mjs";
23
+
9
24
  import { generateBrandAssets } from "../brand-assets.mjs";
10
25
  import { applyFilePatch, parseUnifiedPatch } from "./patch.mjs";
11
- import { createCaptureController, captureSelections } from "../capture.mjs";
26
+ import { createCaptureController } from "../capture.mjs";
12
27
  import { previewSourceRevision } from "../preview-inputs.mjs";
13
- import { inspectScenarios } from "../scenarios.mjs";
28
+
14
29
  import { checkUnitCandidate, checkUnitFiles, inspectUnits, validateUnitId } from "../units.mjs";
15
30
  import { acceptance, failure as evidenceFailure } from "../evidence.mjs";
16
31
  import { checkCandidate, checkCommand, projectChecks as checks } from "../validation-checks.mjs";
@@ -19,41 +34,69 @@ import { validationInputFiles } from "../validation-inputs.mjs";
19
34
  import { mutationLimits } from "./mutation-limits.mjs";
20
35
  import { writeThemesCss } from "../themes-generated.mjs";
21
36
  import { generatedEntries } from "../generated-entries.mjs";
22
- import { inspectTokens } from "../tokens.mjs";
37
+
38
+ import { analyze, registerAnalysisRevision, releaseAnalysisRevision, promoteAnalysisRevision } from "../analysis/service.mjs";
39
+ import { isAnalysisSource } from "../analysis/inputs.mjs";
23
40
 
24
41
  export { mutationLimits } from "./mutation-limits.mjs";
25
- const digest = bytes => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
42
+ const digest = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
26
43
  const ignored = new Set([".git", ".ds", "node_modules", ".vite", "coverage", ".playwright-cli", "test-results", "output"]);
27
- const textFile = file => /\.(?:[cm]?[jt]sx?|css|html|jsonc?|md|txt|svg)$/.test(file);
28
- const setupDotfile = file => /^\.(?:oxlintrc|linariarc|babelrc)(?:\.json)?$/.test(file);
44
+ const textFile = (file) => /\.(?:[cm]?[jt]sx?|css|html|jsonc?|md|txt|svg)$/.test(file);
45
+ const setupDotfile = (file) => /^\.(?:oxlintrc|linariarc|babelrc)(?:\.json)?$/.test(file);
29
46
 
30
- function fail(rule, message, file, boundary = evidenceFailure("architecture","mutation-policy",rule)) {
31
- return Object.assign(new Error(message), { diagnostic: { rule, message, failure:boundary, ...(file ? { file } : {}) } });
47
+ function fail(rule, message, file, boundary) {
48
+ if (boundary === undefined) boundary = evidenceFailure("architecture", "mutation-policy", rule);
49
+ return Object.assign(new Error(message), { diagnostic: { rule, message, failure: boundary, ...(file ? { file } : {}) } });
32
50
  }
33
51
 
34
52
  function address(options, file) {
35
- if (typeof file !== "string" || !file || file.includes("\\") || file.includes("\0") || file.split("/").some(part => !part || part === "." || part === "..") || path.isAbsolute(file)) throw fail("mutation-path", "Use a canonical project-relative ADS file path.", file);
53
+ if (
54
+ typeof file !== "string" ||
55
+ !file ||
56
+ file.includes("\\") ||
57
+ file.includes("\0") ||
58
+ file.split("/").some((part) => !part || part === "." || part === "..") ||
59
+ path.isAbsolute(file)
60
+ )
61
+ throw fail("mutation-path", "Use a canonical project-relative ADS file path.", file);
36
62
  const target = path.resolve(options.root, file);
37
63
  if (!isInside(options.root, target) || target === options.root) throw fail("mutation-path", "Mutation paths must stay inside the project.", file);
38
64
  for (let current = options.root; ; ) {
39
65
  const relative = path.relative(current, target).split(path.sep);
40
- if (relative.some(part => ignored.has(part) || part.startsWith(".") && !setupDotfile(part) && !(part === ".gitkeep" && path.basename(target) === part && isInside(options.dsRoot, target)))) throw fail("mutation-path", "Hidden, dependency and generated paths are not editable.", file);
66
+ if (
67
+ relative.some(
68
+ (part) =>
69
+ ignored.has(part) ||
70
+ (part.startsWith(".") && !setupDotfile(part) && !(part === ".gitkeep" && path.basename(target) === part && isInside(options.dsRoot, target))),
71
+ )
72
+ )
73
+ throw fail("mutation-path", "Hidden, dependency and generated paths are not editable.", file);
41
74
  current = path.join(current, relative[0]);
42
75
  const stat = lstatSync(current, { throwIfNoEntry: false });
43
- if (stat?.isSymbolicLink() || stat && current !== target && !stat.isDirectory() || stat && current === target && (!stat.isFile() || stat.nlink !== 1)) throw fail("mutation-path", "Mutation paths must contain ordinary directories and unlinked regular files.", file);
76
+ if (stat?.isSymbolicLink() || (stat && current !== target && !stat.isDirectory()) || (stat && current === target && (!stat.isFile() || stat.nlink !== 1)))
77
+ throw fail("mutation-path", "Mutation paths must contain ordinary directories and unlinked regular files.", file);
44
78
  if (current === target) break;
45
79
  }
46
- if (options.config.assets.generatedPaths.some(entry => isInside(path.resolve(options.root, entry), target))) throw fail("mutation-path", "Generated output is not editable.", file);
47
- if (options.config.assets.generatedFiles.some(entry => target === path.resolve(options.dsRoot, "assets", entry))) throw fail("mutation-path", "Generated brand files are outputs; edit their source instead.", file);
80
+ if (options.config.assets.generatedPaths.some((entry) => isInside(path.resolve(options.root, entry), target)))
81
+ throw fail("mutation-path", "Generated output is not editable.", file);
82
+ if (options.config.assets.generatedFiles.some((entry) => target === path.resolve(options.dsRoot, "assets", entry)))
83
+ throw fail("mutation-path", "Generated brand files are outputs; edit their source instead.", file);
48
84
  return target;
49
85
  }
50
86
 
51
87
  export function readPatchFile(options, file) {
52
- if (typeof file !== "string" || file.includes("\\") || file.includes("\0") || !/^\.ds\/patches\/[^/]+\.(?:patch|diff)$/.test(file)) throw fail("mutation-patch", "Patch files must be regular .patch/.diff files in .ds/patches/.");
88
+ if (typeof file !== "string" || file.includes("\\") || file.includes("\0") || !/^\.ds\/patches\/[^/]+\.(?:patch|diff)$/.test(file))
89
+ throw fail("mutation-patch", "Patch files must be regular .patch/.diff files in .ds/patches/.");
53
90
  const target = path.join(options.root, file);
54
91
  for (const current of [path.join(options.root, ".ds"), path.dirname(target), target]) {
55
92
  const stat = lstatSync(current, { throwIfNoEntry: false });
56
- if (!stat || stat.isSymbolicLink() || current !== target && !stat.isDirectory() || current === target && (!stat.isFile() || stat.nlink !== 1 || stat.size > mutationLimits.patchFileBytes)) throw fail("mutation-patch", "Patch files must be real files no larger than 16 MiB.");
93
+ if (
94
+ !stat ||
95
+ stat.isSymbolicLink() ||
96
+ (current !== target && !stat.isDirectory()) ||
97
+ (current === target && (!stat.isFile() || stat.nlink !== 1 || stat.size > mutationLimits.patchFileBytes))
98
+ )
99
+ throw fail("mutation-patch", "Patch files must be real files no larger than 16 MiB.");
57
100
  }
58
101
  const bytes = readFileSync(target);
59
102
  if (bytes.includes(0) || !Buffer.from(bytes.toString("utf8")).equals(bytes)) throw fail("mutation-patch", "Patch files must contain UTF-8 Git diff text.");
@@ -69,61 +112,92 @@ function read(options, file) {
69
112
  return { path: file, exists: true, digest: digest(bytes), bytes: bytes.length, binary, content: binary ? bytes : bytes.toString("utf8") };
70
113
  }
71
114
 
72
- function validateContent(change, unit) {
115
+ async function validateContent(change, unit) {
73
116
  if (change.content === null) return;
74
117
  const bytes = Buffer.from(change.content);
75
118
  if (bytes.length > mutationLimits.fileBytes) throw fail("mutation-content", "The patched file exceeds 16 MiB.", change.path);
76
- if ((unit === "documentation" || textFile(change.path)) && (bytes.includes(0) || !Buffer.from(bytes.toString("utf8")).equals(bytes))) throw fail("mutation-content", "Text source and documentation must contain valid UTF-8 without NUL bytes.", change.path);
119
+ if ((unit === "documentation" || textFile(change.path)) && (bytes.includes(0) || !Buffer.from(bytes.toString("utf8")).equals(bytes)))
120
+ throw fail("mutation-content", "Text source and documentation must contain valid UTF-8 without NUL bytes.", change.path);
77
121
  if (/\.jsonc?$/.test(change.path)) {
78
- const content=bytes.toString("utf8");
79
- if (unit === "configuration" && !["package.json","ds.config.json"].includes(path.basename(change.path))) {
80
- if (ts.parseConfigFileTextToJson(change.path,content).error) throw fail("mutation-syntax", "Configuration must contain valid JSON/JSONC.", change.path);
81
- } else { try { JSON.parse(content); } catch { throw fail("mutation-syntax", "JSON source and configuration must be valid JSON.", change.path); } }
122
+ const content = bytes.toString("utf8");
123
+ if (unit === "configuration" && !["package.json", "ds.config.json"].includes(path.basename(change.path))) {
124
+ if ((await ts.parseConfigFileTextToJson(change.path, content)).error)
125
+ throw fail("mutation-syntax", "Configuration must contain valid JSON/JSONC.", change.path);
126
+ } else {
127
+ try {
128
+ JSON.parse(content);
129
+ } catch {
130
+ throw fail("mutation-syntax", "JSON source and configuration must be valid JSON.", change.path);
131
+ }
132
+ }
82
133
  }
83
- if (unit !== "configuration" && /\b(?:oxlint|eslint)-(?:disable|enable)|\bbiome-ignore|@ts-(?:ignore|nocheck|expect-error)/.test(bytes.toString("utf8"))) throw fail("mutation-policy", "Configure reviewed lint/typecheck exceptions through the configuration unit instead of source suppression directives.", change.path);
134
+ if (unit !== "configuration" && /\b(?:oxlint|eslint)-(?:disable|enable)|\bbiome-ignore|@ts-(?:ignore|nocheck|expect-error)/.test(bytes.toString("utf8")))
135
+ throw fail(
136
+ "mutation-policy",
137
+ "Configure reviewed lint/typecheck exceptions through the configuration unit instead of source suppression directives.",
138
+ change.path,
139
+ );
84
140
  }
85
141
 
86
- function candidateInputs(options,extraFiles=[]) {
87
- try { return validationInputFiles(options,extraFiles,{maxFiles:mutationLimits.snapshotFiles,maxBytes:mutationLimits.snapshotBytes}); }
88
- catch(error) { if(error.code==="ADS_INPUT_LIMIT")throw fail("mutation-snapshot",error.message);throw error; }
142
+ async function candidateInputs(options, extraFiles = [], onFile) {
143
+ try {
144
+ return await validationInputFiles(options, extraFiles, { maxFiles: mutationLimits.snapshotFiles, maxBytes: mutationLimits.snapshotBytes, onFile });
145
+ } catch (error) {
146
+ if (error.code === "ADS_INPUT_LIMIT") throw fail("mutation-snapshot", error.message);
147
+ throw error;
148
+ }
89
149
  }
90
- function copyInputs(options, destination, extraFiles, {baseline=new Map(),changed=new Set(),budget={bytes:0,files:0}}={}) {
91
- for (const [relative,value] of Object.entries(candidateInputs(options,extraFiles))) {
150
+ async function copyInputs(options, destination, extraFiles, { baseline = new Map(), changed = new Set(), budget = { bytes: 0, files: 0 }, contents } = {}) {
151
+ const buffers = new Map();
152
+ const inputs = await candidateInputs(options, extraFiles, (file, content) => buffers.set(file, content));
153
+ for (const [relative, value] of Object.entries(inputs)) {
92
154
  if (baseline.has(relative)) continue;
93
- if (relative==="installed-dependencies" || value===null) { baseline.set(relative,value);continue; }
94
- const file=path.resolve(options.root,relative),stat=lstatSync(file);
95
- if (budget.files+1>mutationLimits.snapshotFiles || budget.bytes+stat.size>mutationLimits.snapshotBytes) throw fail("mutation-snapshot","Relevant inputs exceed the bounded validation snapshot limit.");
96
- const content=readFileSync(file);budget.bytes+=content.length;budget.files++;
97
- if (budget.bytes>mutationLimits.snapshotBytes) throw fail("mutation-snapshot","Relevant inputs exceed the bounded validation snapshot limit.");
98
- baseline.set(relative,digest(content));
155
+ if (relative === "installed-dependencies" || value === null) {
156
+ baseline.set(relative, value);
157
+ continue;
158
+ }
159
+ const file = path.resolve(options.root, relative),
160
+ stat = lstatSync(file);
161
+ if (budget.files + 1 > mutationLimits.snapshotFiles || budget.bytes + stat.size > mutationLimits.snapshotBytes)
162
+ throw fail("mutation-snapshot", "Relevant inputs exceed the bounded validation snapshot limit.");
163
+ const content = buffers.get(relative);
164
+ budget.bytes += content.length;
165
+ budget.files++;
166
+ if (budget.bytes > mutationLimits.snapshotBytes) throw fail("mutation-snapshot", "Relevant inputs exceed the bounded validation snapshot limit.");
167
+ baseline.set(relative, digest(content));
168
+ if (contents && isAnalysisSource(relative)) contents.set(relative, content.toString("utf8"));
99
169
  if (!changed.has(relative)) {
100
- const target=path.join(destination,relative);mkdirSync(path.dirname(target),{recursive:true});
101
- writeFileSync(target,content,{mode:stat.mode});
170
+ const target = path.join(destination, relative);
171
+ mkdirSync(path.dirname(target), { recursive: true });
172
+ writeFileSync(target, content, { mode: stat.mode });
102
173
  }
103
174
  }
104
175
  return baseline;
105
176
  }
106
177
 
107
- function snapshot(options) {
178
+ async function snapshot(options) {
108
179
  // Scan the entire *candidate* to detect checking commands that rewrite source,
109
180
  // including files outside the input graph. Live projects are never copied here.
110
- candidateInputs(options);
181
+ await candidateInputs(options);
111
182
  const entries = [];
112
183
  let bytes = 0;
113
- const generated = options.config.assets.generatedPaths.map(file => path.resolve(options.root, file));
184
+ const generated = options.config.assets.generatedPaths.map((file) => path.resolve(options.root, file));
114
185
  function walk(folder) {
115
186
  for (const entry of readdirSync(folder, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
116
187
  if (ignored.has(entry.name)) continue;
117
188
  const file = path.join(folder, entry.name);
118
189
  const relative = path.relative(options.root, file);
119
- if (generated.some(base => isInside(base, file))) continue;
190
+ if (generated.some((base) => isInside(base, file))) continue;
120
191
  if (entry.isSymbolicLink()) continue;
121
- if (entry.isDirectory()) { if (!hasProjectConfig(file)) walk(file); }
122
- else if (entry.isFile()) {
123
- if (bytes + lstatSync(file).size > mutationLimits.snapshotBytes || entries.length >= mutationLimits.snapshotFiles) throw fail("mutation-snapshot", "Project source exceeds the bounded validation snapshot limit.");
192
+ if (entry.isDirectory()) {
193
+ if (!hasProjectConfig(file)) walk(file);
194
+ } else if (entry.isFile()) {
195
+ if (bytes + lstatSync(file).size > mutationLimits.snapshotBytes || entries.length >= mutationLimits.snapshotFiles)
196
+ throw fail("mutation-snapshot", "Project source exceeds the bounded validation snapshot limit.");
124
197
  const content = readFileSync(file);
125
198
  bytes += content.length;
126
- if (bytes > mutationLimits.snapshotBytes || entries.length >= mutationLimits.snapshotFiles) throw fail("mutation-snapshot", "Project source exceeds the bounded validation snapshot limit.");
199
+ if (bytes > mutationLimits.snapshotBytes || entries.length >= mutationLimits.snapshotFiles)
200
+ throw fail("mutation-snapshot", "Project source exceeds the bounded validation snapshot limit.");
127
201
  entries.push([relative, digest(content)]);
128
202
  }
129
203
  }
@@ -135,15 +209,39 @@ function snapshot(options) {
135
209
  return JSON.stringify(entries);
136
210
  }
137
211
 
138
-
139
212
  function mutationEvidence(result, candidateRevision) {
140
- const diagnostics=(result.diagnostics??[]).map(diagnostic=>({...diagnostic,failure:diagnostic.failure??evidenceFailure("architecture","mutation-policy",diagnostic.rule)}));
141
- const failed=diagnostics[0];
142
- const accepted=acceptance("candidate-validation",result.ok,(result.checks??[]).filter(check=>check.passed&&!check.skipped).map(check=>check.name??[check.command,...(check.args??[])].join(" ")),["unregistered-checks","unselected-behavior-checks","post-application-preview-freshness","visual-parity","accessibility-audit"]);
143
- return {...result,...(result.diagnostics?{diagnostics}:{}),acceptance:accepted,investigation:{target:"candidate",candidateRevision:candidateRevision??null,...(failed?{failure:failed.failure,failingStep:failed.failure.phase,source:failed.file?{file:failed.file,line:failed.line,column:failed.column}:null,...(failed.command?{command:failed.command,args:failed.args,exitCode:failed.exitCode,output:failed.output}:{}),message:failed.message}:{}),acceptance:accepted}};
213
+ const diagnostics = (result.diagnostics ?? []).map((diagnostic) => ({
214
+ ...diagnostic,
215
+ failure: diagnostic.failure ?? evidenceFailure("architecture", "mutation-policy", diagnostic.rule),
216
+ }));
217
+ const failed = diagnostics[0];
218
+ const accepted = acceptance(
219
+ "candidate-validation",
220
+ result.ok,
221
+ (result.checks ?? []).filter((check) => check.passed && !check.skipped).map((check) => check.name ?? [check.command, ...(check.args ?? [])].join(" ")),
222
+ ["unregistered-checks", "unselected-behavior-checks", "post-application-preview-freshness", "visual-parity", "accessibility-audit"],
223
+ );
224
+ return {
225
+ ...result,
226
+ ...(result.diagnostics ? { diagnostics } : {}),
227
+ acceptance: accepted,
228
+ investigation: {
229
+ target: "candidate",
230
+ candidateRevision: candidateRevision ?? null,
231
+ ...(failed
232
+ ? {
233
+ failure: failed.failure,
234
+ failingStep: failed.failure.phase,
235
+ source: failed.file ? { file: failed.file, line: failed.line, column: failed.column } : null,
236
+ ...(failed.command ? { command: failed.command, args: failed.args, exitCode: failed.exitCode, output: failed.output } : {}),
237
+ message: failed.message,
238
+ }
239
+ : {}),
240
+ acceptance: accepted,
241
+ },
242
+ };
144
243
  }
145
244
 
146
-
147
245
  export function createMutationController(directory, { captures = createCaptureController(directory), previewWork } = {}) {
148
246
  // A passing dry run's audit holds for accepting the same candidate: remembered by its revision and selection.
149
247
  const audits = new Map();
@@ -155,58 +253,149 @@ export function createMutationController(directory, { captures = createCaptureCo
155
253
  return {
156
254
  status() {
157
255
  const options = loadConfig(root);
158
- let commands = [], diagnostics = [];
159
- try { commands = checks(options).map(check => [check.command, ...check.args].join(" ")); }
160
- catch (error) { diagnostics = [error.diagnostic ?? { rule: "mutation-check", message: error.message }]; }
161
- return { enabled: true, scope: "one-ds-unit", format: "git-unified-diff", route:"draft", drafts:{create:"ads_create_draft",edit:"ads_update_draft",review:"ads_show_draft",accept:"ads_accept",maxUnits:mutationLimits.units,finalCandidateChecks:true}, preparation:{tokenSamples:"ads_prepare_token_samples"}, dsDir: options.config.dsDir, limits: mutationLimits, checks: ["ads check", ...commands, ...options.config.mcp.previewManifest && options.config.mcp.previewWatch ? ["managed production previews"] : []], diagnostics, busy, ...(progress ? { progress } : {}), lastResult };
256
+ let commands = [],
257
+ diagnostics = [];
258
+ try {
259
+ commands = checks(options).map((check) => [check.command, ...check.args].join(" "));
260
+ } catch (error) {
261
+ diagnostics = [error.diagnostic ?? { rule: "mutation-check", message: error.message }];
262
+ }
263
+ return {
264
+ enabled: true,
265
+ scope: "one-ds-unit",
266
+ format: "git-unified-diff",
267
+ route: "draft",
268
+ drafts: {
269
+ create: "ads_create_draft",
270
+ edit: "ads_update_draft",
271
+ review: "ads_show_draft",
272
+ accept: "ads_accept",
273
+ maxUnits: mutationLimits.units,
274
+ finalCandidateChecks: true,
275
+ },
276
+ dsDir: options.config.dsDir,
277
+ limits: mutationLimits,
278
+ checks: ["ads check", ...commands, ...(options.config.framework ? ["managed production previews"] : [])],
279
+ diagnostics,
280
+ busy,
281
+ ...(progress ? { progress } : {}),
282
+ lastResult,
283
+ };
284
+ },
285
+ cancel() {
286
+ active?.abort();
162
287
  },
163
- cancel() { active?.abort(); },
164
- units() { return inspectUnits(loadConfig(root)).units; },
165
- read(file, { offset = 0, limit = mutationLimits.readChars } = {}) {
166
- if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(limit) || limit < 1 || limit > mutationLimits.readChars) throw fail("mutation-range", "Use a non-negative character offset and a limit between 1 and 12000.", file);
167
- const options = loadConfig(root), source = read(options, file);
168
- const inventory = inspectUnits(options), unit = inventory.owner(inventory.relative(file));
169
- if (!unit && inventory.relative(file) !== inventory.publicEntry && inventory.relative(file) !== inventory.reviewEntry) throw fail("mutation-unit", "This file is outside the project's ADS and registered configuration/extension units.", file);
288
+ async units() {
289
+ return (await inspectUnits(loadConfig(root))).units;
290
+ },
291
+ async read(file, { offset = 0, limit = mutationLimits.readChars } = {}) {
292
+ if (!Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(limit) || limit < 1 || limit > mutationLimits.readChars)
293
+ throw fail("mutation-range", "Use a non-negative character offset and a limit between 1 and 12000.", file);
294
+ const options = loadConfig(root),
295
+ source = read(options, file);
296
+ const inventory = await inspectUnits(options),
297
+ unit = inventory.owner(inventory.relative(file));
298
+ if (!unit && inventory.relative(file) !== inventory.publicEntry && inventory.relative(file) !== inventory.reviewEntry)
299
+ throw fail("mutation-unit", "This file is outside the project's ADS and registered configuration/extension units.", file);
170
300
  if (!source.exists) return { ...source, offset: 0, nextOffset: null, totalChars: 0, startLine: 1 };
171
- if (source.binary) return { ...source, unit, content: null, note: "Binary asset: inspect its metadata or preview; edit using a Git binary patch, optionally through patchFile." };
301
+ if (source.binary)
302
+ return {
303
+ ...source,
304
+ unit,
305
+ content: null,
306
+ note: "Binary asset: inspect its metadata or preview; edit using a Git binary patch, optionally through patchFile.",
307
+ };
172
308
  if (offset > source.content.length) throw fail("mutation-range", "Read offset exceeds the current file length.", file);
173
- const content = source.content.slice(offset, offset + limit), end = offset + content.length;
174
- return { ...source, unit, content, offset, nextOffset: end < source.content.length ? end : null, totalChars: source.content.length,
175
- startLine: source.content.slice(0, offset).split("\n").length };
309
+ const content = source.content.slice(offset, offset + limit),
310
+ end = offset + content.length;
311
+ return {
312
+ ...source,
313
+ unit,
314
+ content,
315
+ offset,
316
+ nextOffset: end < source.content.length ? end : null,
317
+ totalChars: source.content.length,
318
+ startLine: source.content.slice(0, offset).split("\n").length,
319
+ };
176
320
  },
177
- async apply({ unit, patch, patchFile, files, patches, checkRoot, previewHost: reviewedHost, dryRun = false, screenshot = false, captures: selections }, signal, notifyProgress, { beforeApply } = {}) {
178
- if (busy) return mutationEvidence({ ok: false, applied: false, diagnostics: [{ rule: "mutation-busy", message: "Another mutation is validating; retry after it finishes.",failure:evidenceFailure("runner","mutation-execution","ADS_MUTATION_BUSY") }] });
321
+ async apply(
322
+ { unit, patch, patchFile, files, patches, checkRoot, previewHost: reviewedHost, dryRun = false },
323
+ signal,
324
+ notifyProgress,
325
+ { beforeApply } = {},
326
+ ) {
327
+ if (busy)
328
+ return mutationEvidence({
329
+ ok: false,
330
+ applied: false,
331
+ diagnostics: [
332
+ {
333
+ rule: "mutation-busy",
334
+ message: "Another mutation is validating; retry after it finishes.",
335
+ failure: evidenceFailure("runner", "mutation-execution", "ADS_MUTATION_BUSY"),
336
+ },
337
+ ],
338
+ });
179
339
  busy = true;
180
340
  active = new AbortController();
181
341
  signal = signal ? AbortSignal.any([signal, active.signal]) : active.signal;
182
342
  let temporary, candidateRevision, releasePreview, releasePublication, previewHost;
183
- let boundary=evidenceFailure("runner","mutation-execution","ADS_MUTATION_EXCEPTION",{certainty:"unclassified"});
343
+ const analysisRoots = new Set(),
344
+ analysisFiles = new Map();
345
+ let boundary = evidenceFailure("runner", "mutation-execution", "ADS_MUTATION_EXCEPTION", { certainty: "unclassified" });
184
346
  const verified = [];
185
347
  try {
186
348
  const options = loadConfig(root);
187
- if (screenshot && !dryRun || selections !== undefined && !screenshot) throw fail("mutation-capture", "Use screenshot:true only with dryRun:true and an explicit captures:[{scenario,target?,theme?,brand?,viewport?}] selection. Ordinary patches create no screenshots.");
188
- if (screenshot) selections = captureSelections(selections);
189
- if (patches !== undefined && (unit !== undefined || patch !== undefined || patchFile !== undefined || !Array.isArray(patches) || patches.length < 2 || patches.length > mutationLimits.units)) throw fail("mutation-batch", `A transaction requires 2–${mutationLimits.units} distinct owner patches, without a top-level unit/patch.`);
190
- const groups = patches ?? [{unit,patch,patchFile,...(files ? {files} : {})}];
191
- if (new Set(groups.map(group => group.unit)).size !== groups.length) throw fail("mutation-batch", "Use one patch per distinct unit in a transaction.");
349
+ if (
350
+ patches !== undefined &&
351
+ (unit !== undefined ||
352
+ patch !== undefined ||
353
+ patchFile !== undefined ||
354
+ !Array.isArray(patches) ||
355
+ patches.length < 2 ||
356
+ patches.length > mutationLimits.units)
357
+ )
358
+ throw fail("mutation-batch", `A transaction requires 2–${mutationLimits.units} distinct owner patches, without a top-level unit/patch.`);
359
+ const groups = patches ?? [{ unit, patch, patchFile, ...(files ? { files } : {}) }];
360
+ if (new Set(groups.map((group) => group.unit)).size !== groups.length)
361
+ throw fail("mutation-batch", "Use one patch per distinct unit in a transaction.");
192
362
  let patchBytes = 0;
193
- const plans = groups.map(group => {
363
+ const plans = groups.map((group) => {
194
364
  validateUnitId(group.unit);
195
365
  // A draft hands over its proposed files as they are; no diff round trip.
196
366
  if (group.files !== undefined) {
197
- if (group.patch !== undefined || group.patchFile !== undefined || !Array.isArray(group.files) || !group.files.length || group.files.length > mutationLimits.files) throw fail("mutation-batch", "Provide an owner's proposed files, or one patch, not both.");
198
- return {unit:group.unit,entries:group.files.map(file => ({path:file.path, direct:true, content:file.content}))};
367
+ if (
368
+ group.patch !== undefined ||
369
+ group.patchFile !== undefined ||
370
+ !Array.isArray(group.files) ||
371
+ !group.files.length ||
372
+ group.files.length > mutationLimits.files
373
+ )
374
+ throw fail("mutation-batch", "Provide an owner's proposed files, or one patch, not both.");
375
+ return { unit: group.unit, entries: group.files.map((file) => ({ path: file.path, direct: true, content: file.content })) };
199
376
  }
200
- if ((typeof group.patch === "string") === (typeof group.patchFile === "string")) throw fail("mutation-patch", "Provide exactly one of patch or patchFile for each owner.");
201
- const value = group.patchFile === undefined ? group.patch : readPatchFile(options,group.patchFile);
377
+ if ((typeof group.patch === "string") === (typeof group.patchFile === "string"))
378
+ throw fail("mutation-patch", "Provide exactly one of patch or patchFile for each owner.");
379
+ const value = group.patchFile === undefined ? group.patch : readPatchFile(options, group.patchFile);
202
380
  const maxPatch = group.patchFile === undefined ? mutationLimits.patchBytes : mutationLimits.patchFileBytes;
203
381
  patchBytes += Buffer.byteLength(value ?? "");
204
- if (typeof value !== "string" || value.includes("\0") || Buffer.from(value).toString("utf8") !== value || Buffer.byteLength(value) > maxPatch || patchBytes > mutationLimits.patchFileBytes) throw fail("mutation-patch", "Patch exceeds its UTF-8 Git diff size limit.");
205
- return {unit:group.unit,entries:parseUnifiedPatch(value,mutationLimits.files)};
382
+ if (
383
+ typeof value !== "string" ||
384
+ value.includes("\0") ||
385
+ Buffer.from(value).toString("utf8") !== value ||
386
+ Buffer.byteLength(value) > maxPatch ||
387
+ patchBytes > mutationLimits.patchFileBytes
388
+ )
389
+ throw fail("mutation-patch", "Patch exceeds its UTF-8 Git diff size limit.");
390
+ return { unit: group.unit, entries: parseUnifiedPatch(value, mutationLimits.files) };
206
391
  });
207
- const units = groups.map(group => group.unit), configuration = units.includes("configuration"), assets = units.some(unit => unit.startsWith("assets"));
208
- for (const plan of plans) for (const entry of plan.entries) address(options,entry.path);
209
- const changes = [], originals = [], byPath = new Map();
392
+ const units = groups.map((group) => group.unit),
393
+ configuration = units.includes("configuration"),
394
+ assets = units.some((unit) => unit.startsWith("assets"));
395
+ for (const plan of plans) for (const entry of plan.entries) address(options, entry.path);
396
+ const changes = [],
397
+ originals = [],
398
+ byPath = new Map();
210
399
  const cache = path.join(root, ".ds");
211
400
  mkdirSync(cache, { recursive: true });
212
401
  if (realpathSync(cache) !== path.join(realpathSync(root), ".ds")) throw fail("mutation-path", "The .ds directory cannot resolve through a symlink.");
@@ -214,248 +403,495 @@ export function createMutationController(directory, { captures = createCaptureCo
214
403
  trackExecutionWorkspace(temporary);
215
404
  const candidate = path.join(temporary, "project");
216
405
  mkdirSync(candidate);
217
- const patchPaths=plans.flatMap(plan=>plan.entries.map(entry=>entry.path));
218
- const copyBudget={bytes:0,files:0};
219
- const copiedInputs=copyInputs(options,candidate,patchPaths,{budget:copyBudget});
406
+ const patchPaths = plans.flatMap((plan) => plan.entries.map((entry) => entry.path));
407
+ const copyBudget = { bytes: 0, files: 0 };
408
+ const copiedInputs = await copyInputs(options, candidate, patchPaths, { budget: copyBudget, contents: analysisFiles });
409
+ const registerAnalysis = async (viewRoot = candidate) => {
410
+ await registerAnalysisRevision(
411
+ root,
412
+ viewRoot,
413
+ analysisFiles,
414
+ changes
415
+ .filter((change) => isAnalysisSource(change.path))
416
+ .map((change) => [change.path, change.content === null ? null : Buffer.from(change.content).toString("utf8")]),
417
+ copiedInputs.get("installed-dependencies") ?? "",
418
+ signal,
419
+ );
420
+ analysisRoots.add(viewRoot);
421
+ };
220
422
  const dependencies = path.join(root, "node_modules");
221
423
  if (!existsSync(dependencies)) throw fail("mutation-check", "Install project dependencies before using guarded mutations.");
222
424
  symlinkSync(realpathSync(dependencies), path.join(candidate, "node_modules"), process.platform === "win32" ? "junction" : "dir");
223
425
  // The tooling repository's own scripts run dist/cli.mjs. Preserve that
224
426
  // already-built runtime without treating generated output as source.
225
427
  if (existsSync(path.join(root, "dist")) && !existsSync(path.join(candidate, "dist"))) {
226
- let count = 0, bytes = 0;
227
- cpSync(path.join(root, "dist"), path.join(candidate, "dist"), { recursive: true, filter(file) {
228
- const stat = lstatSync(file);
229
- if (stat.isSymbolicLink()) throw fail("mutation-snapshot", "Generated runtime copies cannot contain symlinks.");
230
- if (stat.isFile()) { bytes += stat.size; ++count; }
231
- if (count > mutationLimits.snapshotFiles || bytes > mutationLimits.snapshotBytes) throw fail("mutation-snapshot", "Generated runtime exceeds the validation snapshot limit.");
232
- return true;
233
- } });
428
+ let count = 0,
429
+ bytes = 0;
430
+ cpSync(path.join(root, "dist"), path.join(candidate, "dist"), {
431
+ recursive: true,
432
+ filter(file) {
433
+ const stat = lstatSync(file);
434
+ if (stat.isSymbolicLink()) throw fail("mutation-snapshot", "Generated runtime copies cannot contain symlinks.");
435
+ if (stat.isFile()) {
436
+ bytes += stat.size;
437
+ ++count;
438
+ }
439
+ if (count > mutationLimits.snapshotFiles || bytes > mutationLimits.snapshotBytes)
440
+ throw fail("mutation-snapshot", "Generated runtime exceeds the validation snapshot limit.");
441
+ return true;
442
+ },
443
+ });
234
444
  }
235
- const entries = plans.flatMap(plan => plan.entries);
236
- if (entries.some(entry => entry.binary)) {
237
- const formats = new Set(entries.filter(entry=>entry.binary).map(entry=>entry.objectFormat));
445
+ const entries = plans.flatMap((plan) => plan.entries);
446
+ if (entries.some((entry) => entry.binary)) {
447
+ const formats = new Set(entries.filter((entry) => entry.binary).map((entry) => entry.objectFormat));
238
448
  if (formats.size !== 1) throw fail("mutation-patch", "Binary blocks in one Git diff must use the same object format.");
239
449
  await checkCommand("git", ["init", "--quiet", `--object-format=${[...formats][0]}`, candidate], root, signal);
240
450
  }
241
451
  for (const plan of plans) {
242
- const current = loadConfig(candidate), selected = plan.entries.map(entry => {
243
- address(options,entry.path);
244
- const before = read(current,entry.path);
245
- if (!entry.binary && !entry.direct && before.binary) throw fail("mutation-patch", "Binary assets require a git diff --binary patch.", entry.path);
246
- const change = {path:entry.path, originalContent:before.content, content:entry.direct ? entry.content : entry.binary ? entry.operation === "delete" ? null : before.content ?? Buffer.alloc(0) : applyFilePatch(entry,before.content), ...(entry.binary ? {binaryPatch:entry.patch} : {})};
247
- if (!entry.binary) validateContent(change,plan.unit);
248
- if (!byPath.has(entry.path)) {
249
- const original = read(options,entry.path);
250
- // The candidate copy and live inputs must agree before any changes.
251
- if (original.digest !== before.digest) throw fail("mutation-conflict", "Source changed while preparing validation; regenerate the patch.", entry.path);
252
- originals.push({...original,mode:original.exists ? lstatSync(address(options,entry.path)).mode : undefined});
253
- byPath.set(entry.path,changes.length);
254
- changes.push({...change,expectedDigest:original.digest});
255
- if (changes.length > mutationLimits.files) throw fail("mutation-batch", `A transaction may change at most ${mutationLimits.files} distinct files.`);
256
- }
257
- return change;
258
- });
259
- const inventory = checkUnitFiles(current,plan.unit,selected,inspectUnits(current),true);
452
+ const current = loadConfig(candidate),
453
+ selected = await mapAsync(plan.entries, async (entry) => {
454
+ address(options, entry.path);
455
+ const before = read(current, entry.path);
456
+ if (!entry.binary && !entry.direct && before.binary) throw fail("mutation-patch", "Binary assets require a git diff --binary patch.", entry.path);
457
+ const change = {
458
+ path: entry.path,
459
+ originalContent: before.content,
460
+ content: entry.direct
461
+ ? entry.content
462
+ : entry.binary
463
+ ? entry.operation === "delete"
464
+ ? null
465
+ : (before.content ?? Buffer.alloc(0))
466
+ : applyFilePatch(entry, before.content),
467
+ ...(entry.binary ? { binaryPatch: entry.patch } : {}),
468
+ };
469
+ if (!entry.binary) await validateContent(change, plan.unit);
470
+ if (!byPath.has(entry.path)) {
471
+ const original = read(options, entry.path);
472
+ // The candidate copy and live inputs must agree before any changes.
473
+ if (original.digest !== before.digest)
474
+ throw fail("mutation-conflict", "Source changed while preparing validation; regenerate the patch.", entry.path);
475
+ originals.push({ ...original, mode: original.exists ? lstatSync(address(options, entry.path)).mode : undefined });
476
+ byPath.set(entry.path, changes.length);
477
+ changes.push({ ...change, expectedDigest: original.digest });
478
+ if (changes.length > mutationLimits.files)
479
+ throw fail("mutation-batch", `A transaction may change at most ${mutationLimits.files} distinct files.`);
480
+ }
481
+ return change;
482
+ });
483
+ const inventory = await checkUnitFiles(current, plan.unit, selected, await inspectUnits(current), true);
260
484
  for (const change of selected) {
261
- const file = path.join(candidate,change.path);
485
+ const file = path.join(candidate, change.path);
262
486
  if (change.binaryPatch) {
263
- for (const match of change.binaryPatch.matchAll(/^(?:literal|delta) (\d+)$/gm)) if (Number(match[1]) > mutationLimits.fileBytes) throw fail("mutation-content", "Binary patch blocks exceed 16 MiB.", change.path);
264
- await checkCommand("git",["apply","--binary","--whitespace=nowarn","-"],candidate,signal,change.binaryPatch);
487
+ for (const match of change.binaryPatch.matchAll(/^(?:literal|delta) (\d+)$/gm))
488
+ if (Number(match[1]) > mutationLimits.fileBytes) throw fail("mutation-content", "Binary patch blocks exceed 16 MiB.", change.path);
489
+ await checkCommand("git", ["apply", "--binary", "--whitespace=nowarn", "-"], candidate, signal, change.binaryPatch);
265
490
  change.content = existsSync(file) ? readFileSync(file) : null;
266
- validateContent(change,plan.unit);
491
+ await validateContent(change, plan.unit);
267
492
  } else if (change.content === null) rmSync(file);
268
- else {mkdirSync(path.dirname(file),{recursive:true});writeFileSync(file,change.content);}
493
+ else {
494
+ mkdirSync(path.dirname(file), { recursive: true });
495
+ writeFileSync(file, change.content);
496
+ }
269
497
  changes[byPath.get(change.path)].content = change.content;
270
498
  }
271
- checkUnitCandidate(loadConfig(candidate),plan.unit,selected,inventory);
499
+ await checkUnitCandidate(loadConfig(candidate), plan.unit, selected, inventory);
272
500
  }
273
501
  // ADS removes an empty .gitkeep itself once accepted source is added beneath it.
274
- for (const change of changes.filter(item => item.originalContent === null && item.content !== null)) {
275
- for (let directory = path.posix.dirname(change.path); directory !== "." && isInside(options.dsRoot, path.join(root, directory)) && path.join(root, directory) !== options.dsRoot; directory = path.posix.dirname(directory)) {
276
- const marker = `${directory}/.gitkeep`, live = read(options, marker);
502
+ for (const change of changes.filter((item) => item.originalContent === null && item.content !== null)) {
503
+ for (
504
+ let directory = path.posix.dirname(change.path);
505
+ directory !== "." && isInside(options.dsRoot, path.join(root, directory)) && path.join(root, directory) !== options.dsRoot;
506
+ directory = path.posix.dirname(directory)
507
+ ) {
508
+ const marker = `${directory}/.gitkeep`,
509
+ live = read(options, marker);
277
510
  if (!live.exists || live.content !== "" || byPath.has(marker)) continue;
278
- originals.push({...live,mode:lstatSync(address(options,marker)).mode});
279
- byPath.set(marker,changes.length);
280
- changes.push({path:marker,originalContent:"",content:null,expectedDigest:live.digest});
511
+ originals.push({ ...live, mode: lstatSync(address(options, marker)).mode });
512
+ byPath.set(marker, changes.length);
513
+ changes.push({ path: marker, originalContent: "", content: null, expectedDigest: live.digest });
281
514
  // The live placeholder is part of the baseline the publication fences against.
282
- copiedInputs.set(marker,digest(Buffer.from("")));
283
- rmSync(path.join(candidate,marker),{force:true});
515
+ copiedInputs.set(marker, digest(Buffer.from("")));
516
+ rmSync(path.join(candidate, marker), { force: true });
284
517
  }
285
518
  }
519
+ const candidateOptions = loadConfig(candidate);
520
+ // A proposed configuration may add roots or explicit inputs. Preserve
521
+ // already patched files while bringing those additional live inputs in.
522
+ const proposedInputs = Object.keys(await validationInputFiles(candidateOptions));
523
+ await copyInputs(
524
+ {
525
+ root,
526
+ config: candidateOptions.config,
527
+ dsRoot: path.resolve(root, candidateOptions.config.dsDir),
528
+ sourceRoot: path.resolve(root, candidateOptions.config.sourceDir),
529
+ },
530
+ candidate,
531
+ [...patchPaths, ...proposedInputs],
532
+ { baseline: copiedInputs, changed: new Set(changes.map((change) => change.path)), budget: copyBudget, contents: analysisFiles },
533
+ );
286
534
  // Token sheet and theme/brand config changes carry the regenerated theme sheet with them,
287
535
  // and exports file or token sheet changes carry the regenerated entries (barrels, styles entry).
288
536
  {
289
537
  const generatedOptions = loadConfig(candidate);
538
+ await registerAnalysis();
290
539
  // Theme files first: the public barrel publishes the generated font preloads when they exist.
291
- const themes = writeThemesCss(generatedOptions, inspectTokens(candidate, generatedOptions)).files;
292
- const barrels = generatedEntries(generatedOptions);
293
- for (const barrel of barrels) { mkdirSync(path.dirname(barrel.file), { recursive: true }); writeFileSync(barrel.file, barrel.text); }
540
+ const themes = writeThemesCss(generatedOptions, await analyze(candidate, "tokens", [], signal)).files;
541
+ const barrels = await generatedEntries(generatedOptions);
542
+ for (const barrel of barrels) {
543
+ mkdirSync(path.dirname(barrel.file), { recursive: true });
544
+ writeFileSync(barrel.file, barrel.text);
545
+ }
294
546
  for (const generated of [...themes, ...barrels]) {
295
- const relative = path.relative(candidate, generated.file).replaceAll("\\", "/"), current = generated.text !== undefined && read(options, relative);
547
+ const relative = path.relative(candidate, generated.file).replaceAll("\\", "/"),
548
+ current = generated.text !== undefined && read(options, relative);
296
549
  if (current && current.content !== generated.text) {
297
550
  if (!byPath.has(relative)) {
298
- originals.push({...current,mode:current.exists ? lstatSync(address(options,relative)).mode : undefined});
299
- byPath.set(relative,changes.length);
300
- changes.push({path:relative,originalContent:current.content,content:generated.text,expectedDigest:current.digest});
551
+ originals.push({ ...current, mode: current.exists ? lstatSync(address(options, relative)).mode : undefined });
552
+ byPath.set(relative, changes.length);
553
+ changes.push({ path: relative, originalContent: current.content, content: generated.text, expectedDigest: current.digest });
301
554
  } else changes[byPath.get(relative)].content = generated.text;
302
555
  }
303
556
  }
304
557
  }
305
- const candidateOptions = loadConfig(candidate);
306
- // A proposed configuration may add roots or explicit inputs. Preserve
307
- // already patched files while bringing those additional live inputs in.
308
- const proposedInputs = Object.keys(validationInputFiles(candidateOptions));
309
- copyInputs({root,config:candidateOptions.config,dsRoot:path.resolve(root,candidateOptions.config.dsDir),sourceRoot:path.resolve(root,candidateOptions.config.sourceDir)},candidate,[...patchPaths,...proposedInputs],{baseline:copiedInputs,changed:new Set(changes.map(change=>change.path)),budget:copyBudget});
310
- const inputPaths = [...new Set([...changes.map(change=>change.path),...Object.keys(validationInputFiles(candidateOptions))])];
311
- const scopedInputs = () => {
558
+ await registerAnalysis();
559
+ const inputPaths = [...new Set([...changes.map((change) => change.path), ...Object.keys(await validationInputFiles(candidateOptions))])];
560
+ const scopedInputs = async () => {
312
561
  const files = {};
313
- for (const original of [options,candidateOptions]) {
314
- const rebased = { root, config: original.config, dsRoot: path.resolve(root,original.config.dsDir), sourceRoot: path.resolve(root,original.config.sourceDir) };
315
- Object.assign(files,validationInputFiles(rebased,inputPaths));
562
+ for (const original of [options, candidateOptions]) {
563
+ const rebased = {
564
+ root,
565
+ config: original.config,
566
+ dsRoot: path.resolve(root, original.config.dsDir),
567
+ sourceRoot: path.resolve(root, original.config.sourceDir),
568
+ };
569
+ Object.assign(files, await validationInputFiles(rebased, inputPaths));
316
570
  }
317
- return Object.fromEntries(Object.entries(files).sort(([a],[b])=>a.localeCompare(b)));
571
+ return Object.fromEntries(Object.entries(files).sort(([a], [b]) => a.localeCompare(b)));
318
572
  };
319
- const currentInputs = scopedInputs();
320
- const before = JSON.stringify(Object.fromEntries(Object.keys(currentInputs).map(file=>[file,copiedInputs.get(file)??null])));
321
- if (JSON.stringify(currentInputs) !== before) throw fail("mutation-conflict","Relevant inputs changed while preparing validation; regenerate the patch.");
573
+ const currentInputs = await scopedInputs();
574
+ const before = JSON.stringify(Object.fromEntries(Object.keys(currentInputs).map((file) => [file, copiedInputs.get(file) ?? null])));
575
+ if (JSON.stringify(currentInputs) !== before)
576
+ throw fail("mutation-conflict", "Relevant inputs changed while preparing validation; regenerate the patch.");
322
577
  const extraChecks = checks(candidateOptions);
323
- const expected = snapshot(candidateOptions);
324
- candidateRevision=digest(Buffer.from(expected));
578
+ const expected = await snapshot(candidateOptions);
579
+ candidateRevision = digest(Buffer.from(expected));
325
580
  if (previewWork) releasePreview = await previewWork.acquire(signal);
326
581
  // A reviewed draft's workspace holds exactly this candidate's inputs at a stable path, so
327
582
  // its warm check (and a remembered report from a dry run) applies; otherwise check the copy.
328
583
  // Compared over the project's own inputs plus the changed files.
329
- const compared = [...new Set([...Object.keys(validationInputFiles(options)), ...changes.map(change => change.path)])];
330
- const pick = (digests) => JSON.stringify(compared.map(file => [file, digests[file] ?? null]));
331
- const sameInputs = checkRoot && existsSync(checkRoot) && pick(validationInputFiles(loadConfig(checkRoot), compared)) === pick(validationInputFiles(candidateOptions, compared));
584
+ const compared = [...new Set([...Object.keys(await validationInputFiles(options)), ...changes.map((change) => change.path)])];
585
+ const pick = (digests) => JSON.stringify(compared.map((file) => [file, digests[file] ?? null]));
586
+ const sameInputs =
587
+ checkRoot &&
588
+ existsSync(checkRoot) &&
589
+ pick(await validationInputFiles(loadConfig(checkRoot), compared)) === pick(await validationInputFiles(candidateOptions, compared));
332
590
  // Browser checks of a reviewed draft render its workspace through the project's own host and
333
591
  // compiler; only a candidate without one gets a preview host of its own.
334
- const reviewRoot = sameInputs ? checkRoot : candidate, sharedHost = sameInputs ? reviewedHost : undefined;
592
+ const reviewRoot = sameInputs ? checkRoot : candidate,
593
+ sharedHost = sameInputs ? reviewedHost : undefined;
594
+ if (reviewRoot !== candidate) await registerAnalysis(reviewRoot);
335
595
  const result = await checkCandidate(reviewRoot, signal, root);
336
- verified.push({name:"ads check",passed:result.ok,cache:result.cache});
337
- if (!result.ok) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: result.diagnostics, total: result.diagnostics.length, checks: verified },candidateRevision);
596
+ verified.push({ name: "ads check", passed: result.ok, cache: result.cache });
597
+ if (!result.ok)
598
+ return (lastResult = mutationEvidence(
599
+ { ok: false, applied: false, diagnostics: result.diagnostics, total: result.diagnostics.length, checks: verified },
600
+ candidateRevision,
601
+ ));
338
602
  if (assets || configuration) {
339
- boundary=evidenceFailure("build","brand-assets","ADS_ASSET_BUILD");
603
+ boundary = evidenceFailure("build", "brand-assets", "ADS_ASSET_BUILD");
340
604
  const brand = await generateBrandAssets(candidate);
341
605
  verified.push({ name: "brand assets", passed: true, skipped: !!brand.skipped });
342
606
  }
343
- for (const [index,check] of extraChecks.entries()) {
344
- progress={stage:"project-checks",completed:index,total:extraChecks.length,message:`Checking ${check.command} ${check.args.join(" ")}`};notifyProgress?.(progress);
345
- verified.push(await checkCommand(check.command, check.args, candidate, signal, undefined, {category:"build",phase:`project-check:${check.args.at(-1)}`}, candidateOptions.config.mcp.mutationCheckTimeoutMs));
607
+ for (const [index, check] of extraChecks.entries()) {
608
+ progress = { stage: "project-checks", completed: index, total: extraChecks.length, message: `Checking ${check.command} ${check.args.join(" ")}` };
609
+ notifyProgress?.(progress);
610
+ verified.push(
611
+ await checkCommand(
612
+ check.command,
613
+ check.args,
614
+ candidate,
615
+ signal,
616
+ undefined,
617
+ { category: "build", phase: `project-check:${check.args.at(-1)}` },
618
+ candidateOptions.config.mcp.mutationCheckTimeoutMs,
619
+ ),
620
+ );
346
621
  }
347
- const behaviorUnits = candidateOptions.config.acceptance.behaviorChecks ? affectedBehaviorUnits(candidateOptions, changes.map(change => change.path)) : [];
348
- // acceptance.browserAudit: "owners" audits the changed owners' own scenarios, "affected" every scenario they reach, false none.
349
- // It reuses the candidate preview host built for behavior checks/captures; on its own it starts a
350
- // candidate host that compiles only the selected scenarios.
351
- const audit = candidateOptions.config.acceptance.browserAudit ? await import("../browser-audit.mjs") : null;
352
- const auditSelection = audit?.auditScenarioSelection(candidateOptions, changes.map(change => change.path), { mode: candidateOptions.config.acceptance.browserAudit, owners: units });
353
- if ((behaviorUnits.length || screenshot) && candidateOptions.config.mcp.previewManifest && candidateOptions.config.mcp.previewWatch) {
354
- boundary=evidenceFailure("build","preview-build","ADS_PREVIEW_BUILD");
355
- progress={stage:"preview-build",message:"Building all candidate previews"};notifyProgress?.(progress);
356
- if (sharedHost) await sharedHost.buildAll(signal, {timeoutMs:candidateOptions.config.mcp.mutationCheckTimeoutMs});
622
+ // Acceptance checks the draft's owners themselves: their own behavior tests (acceptance.behavior)
623
+ // and their own scenarios' render audit (acceptance.audit). What the change reaches beyond them is
624
+ // ads_validate's to check. The audit reuses the candidate preview host built for browser behavior
625
+ // checks; on its own it starts a candidate host that compiles only the selected scenarios.
626
+ const behaviorUnits = candidateOptions.config.acceptance.behavior
627
+ ? (await analyze(candidate, "behavior", [], signal)).contracts.map((contract) => contract.unit).filter((unit) => units.includes(unit))
628
+ : [];
629
+ const audit = candidateOptions.config.acceptance.audit ? await import("../render-audit.mjs") : null;
630
+ const auditSelection =
631
+ audit && (await analyze(candidate, "audit-selection", [changes.map((change) => change.path), { mode: "owners", owners: units }], signal));
632
+ // Previews are built only when a browser behavior check renders them.
633
+ if ((await analyze(candidate, "needs-browser", [behaviorUnits], signal)) && candidateOptions.config.framework) {
634
+ boundary = evidenceFailure("build", "preview-build", "ADS_PREVIEW_BUILD");
635
+ progress = { stage: "preview-build", message: "Building all candidate previews" };
636
+ notifyProgress?.(progress);
637
+ if (sharedHost) await sharedHost.buildAll(signal, { timeoutMs: candidateOptions.config.mcp.mutationCheckTimeoutMs });
357
638
  else {
358
639
  const { startAdsMcp } = await import("./server.mjs");
359
- previewHost = await startAdsMcp(candidate, { stdio:false });
360
- await previewHost.buildAll(signal, {timeoutMs:candidateOptions.config.mcp.mutationCheckTimeoutMs});
640
+ previewHost = await startAdsMcp(candidate, { stdio: false });
641
+ await previewHost.buildAll(signal, { timeoutMs: candidateOptions.config.mcp.mutationCheckTimeoutMs });
361
642
  // Browser checks consume this immutable production graph. Keep its
362
643
  // resources hosted, release its compiler, and leave Explorer live.
363
644
  await previewHost.parkCompiler();
364
645
  }
365
- verified.push({ name:"managed production previews", passed:true });
646
+ verified.push({ name: "managed production previews", passed: true });
366
647
  }
367
- boundary=evidenceFailure("runner","behavior-verification","ADS_BEHAVIOR_SETUP");
648
+ boundary = evidenceFailure("runner", "behavior-verification", "ADS_BEHAVIOR_SETUP");
368
649
  if (behaviorUnits.length) {
369
- const verification = createVerificationController(reviewRoot, { reportRoot: root, previewHost: previewHost ?? sharedHost, onProgress: value => { progress = { stage: "behavior", ...value }; notifyProgress?.(progress); } });
650
+ const verification = createVerificationController(reviewRoot, {
651
+ reportRoot: root,
652
+ previewHost: previewHost ?? sharedHost,
653
+ onProgress: (value) => {
654
+ progress = { stage: "behavior", ...value };
655
+ notifyProgress?.(progress);
656
+ },
657
+ });
370
658
  let evidence;
371
- try { evidence = await verification.run({ units: behaviorUnits, persist: false }, signal); }
372
- finally { await verification.close(); }
373
- if (!evidence.ok) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: [...evidence.results.filter(item => item.status !== "passed").map(item => ({ rule: "behavior-check", failure:item.failure, message: `${item.unit}#${item.check}: ${item.status}. ${item.message}` })),...evidence.diagnostics], checks: verified, behavior: evidence },candidateRevision);
659
+ try {
660
+ evidence = await verification.run({ units: behaviorUnits, persist: false }, signal);
661
+ } finally {
662
+ await verification.close();
663
+ }
664
+ if (!evidence.ok)
665
+ return (lastResult = mutationEvidence(
666
+ {
667
+ ok: false,
668
+ applied: false,
669
+ diagnostics: [
670
+ ...evidence.results
671
+ .filter((item) => item.status !== "passed")
672
+ .map((item) => ({ rule: "behavior-check", failure: item.failure, message: `${item.unit}#${item.check}: ${item.status}. ${item.message}` })),
673
+ ...evidence.diagnostics,
674
+ ],
675
+ checks: verified,
676
+ behavior: evidence,
677
+ },
678
+ candidateRevision,
679
+ ));
374
680
  verified.push({ name: "registered behavior checks", passed: true, results: evidence.results });
375
- }
376
- else verified.push({name:"registered behavior checks",skipped:true,reason:candidateOptions.config.acceptance.behaviorChecks ? "No affected behavior contracts." : "Not required by acceptance policy."});
681
+ } else
682
+ verified.push({
683
+ name: "registered behavior checks",
684
+ skipped: true,
685
+ reason: candidateOptions.config.acceptance.behavior
686
+ ? "The draft's owners register no behavior checks."
687
+ : "Turned off by acceptance.behavior: false.",
688
+ });
377
689
  if (auditSelection) {
378
- boundary=evidenceFailure("runner","browser-audit","ADS_AUDIT_FAILED");
379
- const selection = {selection:auditSelection.mode,...(auditSelection.reason?{selectionReason:auditSelection.reason}:{}),auditedScenarios:auditSelection.scenarios};
380
- if (!auditSelection.scenarios.length) verified.push({name:"browser-accessibility-audit",skipped:true,reason:"No affected UI scenarios.",scenarios:0,...selection});
690
+ boundary = evidenceFailure("runner", "render-audit", "ADS_AUDIT_FAILED");
691
+ const selection = {
692
+ selection: auditSelection.mode,
693
+ ...(auditSelection.reason ? { selectionReason: auditSelection.reason } : {}),
694
+ auditedScenarios: auditSelection.scenarios,
695
+ };
696
+ if (!auditSelection.scenarios.length)
697
+ verified.push({ name: "render-audit", skipped: true, reason: "No affected UI scenarios.", scenarios: 0, ...selection });
381
698
  else {
382
- progress={stage:"browser-audit",message:`Accessibility audit of ${auditSelection.scenarios.length} candidate scenarios`};notifyProgress?.(progress);
383
- const auditKey = `${candidateRevision}:${JSON.stringify(auditSelection.scenarios)}`, remembered = audits.get(auditKey);
699
+ progress = { stage: "render-audit", message: `Accessibility audit of ${auditSelection.scenarios.length} candidate scenarios` };
700
+ notifyProgress?.(progress);
701
+ const auditKey = `${candidateRevision}:${JSON.stringify(auditSelection.scenarios)}`,
702
+ remembered = audits.get(auditKey);
384
703
  if (remembered) {
385
704
  verified.push({ ...remembered.check, remembered: true });
386
- if (!remembered.check.passed) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: remembered.diagnostics, total: remembered.diagnostics.length, checks: verified },candidateRevision);
705
+ if (!remembered.check.passed)
706
+ return (lastResult = mutationEvidence(
707
+ { ok: false, applied: false, diagnostics: remembered.diagnostics, total: remembered.diagnostics.length, checks: verified },
708
+ candidateRevision,
709
+ ));
387
710
  } else {
388
- let result;
389
- try { result = await audit.runBrowserAudit(reviewRoot, {scenarios:auditSelection.scenarios,previewHost:previewHost ?? sharedHost,signal,onProgress:value=>{progress=value;notifyProgress?.(value);}}); }
390
- catch (error) {
391
- if (signal.aborted) throw error;
392
- verified.push({name:"browser-accessibility-audit",passed:false,...selection});
393
- return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: [{ rule: "browser-audit", message: error.message, failure: evidenceFailure("runner","browser-audit",error.code ?? "ADS_AUDIT_FAILED") }], checks: verified },candidateRevision);
394
- }
395
- const {routed,check} = audit.auditCheck(result,selection);
396
- audits.set(auditKey, { check, diagnostics: routed.diagnostics.map(item => ({...item,failure:evidenceFailure("assertion","browser-audit",item.rule)})) });
397
- while (audits.size > 16) audits.delete(audits.keys().next().value);
398
- verified.push(check);
399
- if (!check.passed) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: routed.diagnostics.map(item => ({...item,failure:evidenceFailure("assertion","browser-audit",item.rule)})), total: routed.diagnostics.length, checks: verified, ...(routed.advisories.length ? {advisories:routed.advisories,advisoryCount:routed.advisories.length} : {}) },candidateRevision);
711
+ let result;
712
+ try {
713
+ result = await audit.runRenderAudit(reviewRoot, {
714
+ scenarios: auditSelection.scenarios,
715
+ previewHost: previewHost ?? sharedHost,
716
+ signal,
717
+ onProgress: (value) => {
718
+ progress = value;
719
+ notifyProgress?.(value);
720
+ },
721
+ });
722
+ } catch (error) {
723
+ if (signal.aborted) throw error;
724
+ verified.push({ name: "render-audit", passed: false, ...selection });
725
+ return (lastResult = mutationEvidence(
726
+ {
727
+ ok: false,
728
+ applied: false,
729
+ diagnostics: [
730
+ { rule: "render-audit", message: error.message, failure: evidenceFailure("runner", "render-audit", error.code ?? "ADS_AUDIT_FAILED") },
731
+ ],
732
+ checks: verified,
733
+ },
734
+ candidateRevision,
735
+ ));
736
+ }
737
+ const { routed, check } = audit.auditCheck(result, selection);
738
+ audits.set(auditKey, {
739
+ check,
740
+ diagnostics: routed.diagnostics.map((item) => ({ ...item, failure: evidenceFailure("assertion", "render-audit", item.rule) })),
741
+ });
742
+ while (audits.size > 16) audits.delete(audits.keys().next().value);
743
+ verified.push(check);
744
+ if (!check.passed)
745
+ return (lastResult = mutationEvidence(
746
+ {
747
+ ok: false,
748
+ applied: false,
749
+ diagnostics: routed.diagnostics.map((item) => ({ ...item, failure: evidenceFailure("assertion", "render-audit", item.rule) })),
750
+ total: routed.diagnostics.length,
751
+ checks: verified,
752
+ ...(routed.advisories.length ? { advisories: routed.advisories, advisoryCount: routed.advisories.length } : {}),
753
+ },
754
+ candidateRevision,
755
+ ));
400
756
  }
401
757
  }
402
758
  }
403
- let screenshots;
404
- if (screenshot) {
405
- boundary=evidenceFailure("runner","capture","ADS_CAPTURE_FAILED");
406
- progress = { stage: "capture", total: selections.length, completed: 0, active: [], profile: "screenshots", elapsedMs: 0 };
407
- notifyProgress?.(progress);
408
- const proposal = digest(Buffer.from(JSON.stringify(changes.map(change => [change.path, change.content === null ? null : digest(Buffer.from(change.content))]))));
409
- screenshots = await captures.run({ captures: selections, candidateRoot: candidate, proposal, publish: false }, signal, value => { progress = value; notifyProgress?.(value); });
410
- }
411
759
  let preparedPreview;
412
- if(!dryRun){try{preparedPreview=preparePreviewCache(candidateOptions,loadConfig(root));}catch{/* A missing cache falls back to background compilation. */}}
413
- if (signal?.aborted) throw fail("mutation-cancelled", "Mutation cancelled before application.",undefined,evidenceFailure("runner","mutation-execution","ADS_CANCELLED"));
414
- if (snapshot(candidateOptions) !== expected) throw fail("mutation-check", "A validation command changed source files. Use checks without source-writing side effects.");
415
- if (JSON.stringify(scopedInputs()) !== before) throw fail("mutation-conflict", "ADS, consuming UI or declared validation inputs changed during validation; no changes were applied. Read current source and retry.");
416
- for (const change of changes) address(options, change.path);
417
- if (screenshots) {
418
- captures.store.commit(screenshots.records);
419
- const selected = new Set(screenshots.records.map(record => record.key));
420
- screenshots = { ok: true, captures: captures.store.list(inspectScenarios(loadConfig(root)).scenarios, screenshots.baseRevision).captures.filter(record => selected.has(record.key)) };
760
+ if (!dryRun) {
761
+ try {
762
+ preparedPreview = await preparePreviewCache(candidateOptions, loadConfig(root));
763
+ } catch {
764
+ /* A missing cache falls back to background compilation. */
765
+ }
421
766
  }
767
+ if (signal?.aborted)
768
+ throw fail(
769
+ "mutation-cancelled",
770
+ "Mutation cancelled before application.",
771
+ undefined,
772
+ evidenceFailure("runner", "mutation-execution", "ADS_CANCELLED"),
773
+ );
774
+ if ((await snapshot(candidateOptions)) !== expected)
775
+ throw fail("mutation-check", "A validation command changed source files. Use checks without source-writing side effects.");
776
+ if (JSON.stringify(await scopedInputs()) !== before)
777
+ throw fail(
778
+ "mutation-conflict",
779
+ "ADS, consuming UI or declared validation inputs changed during validation; no changes were applied. Read current source and retry.",
780
+ );
781
+ for (const change of changes) address(options, change.path);
422
782
  if (!dryRun) {
423
- beforeApply?.();
783
+ await beforeApply?.();
424
784
  if (preparedPreview) releasePublication = holdLivePreview(root);
425
785
  const written = [];
426
786
  const directories = [];
427
- function mkdir(directory) { if (!existsSync(directory)) { mkdir(path.dirname(directory)); mkdirSync(directory); directories.push(directory); } }
787
+ function mkdir(directory) {
788
+ if (!existsSync(directory)) {
789
+ mkdir(path.dirname(directory));
790
+ mkdirSync(directory);
791
+ directories.push(directory);
792
+ }
793
+ }
428
794
  function replace(file, content, mode) {
429
795
  mkdir(path.dirname(file));
430
796
  const staged = path.join(path.dirname(file), `.ads-edit-${randomUUID()}`);
431
- try { writeFileSync(staged, content, { mode }); renameSync(staged, file); }
432
- finally { rmSync(staged, { force: true }); }
797
+ try {
798
+ writeFileSync(staged, content, { mode });
799
+ renameSync(staged, file);
800
+ } finally {
801
+ rmSync(staged, { force: true });
802
+ }
433
803
  }
434
804
  try {
435
805
  changes.forEach((change, index) => {
436
806
  const file = address(options, change.path);
437
- if (change.content === null) rmSync(file); else replace(file, change.content, originals[index].mode);
807
+ if (change.content === null) rmSync(file);
808
+ else replace(file, change.content, originals[index].mode);
438
809
  written.push(index);
439
810
  });
440
811
  } catch (error) {
441
812
  for (const index of written.reverse()) {
442
- const original = originals[index], file = path.join(root, original.path);
443
- if (original.exists) replace(file, original.content, original.mode); else rmSync(file, { force: true });
813
+ const original = originals[index],
814
+ file = path.join(root, original.path);
815
+ if (original.exists) replace(file, original.content, original.mode);
816
+ else rmSync(file, { force: true });
444
817
  }
445
818
  for (const directory of directories.reverse()) if (!readdirSync(directory).length) rmSync(directory, { recursive: true });
446
819
  throw error;
447
820
  }
448
821
  }
449
822
  const warnings = [];
450
- if (!dryRun && (assets || configuration)) { try { await generateBrandAssets(root); } catch (error) { warnings.push({ rule: "mutation-assets", message: `Source was applied; generated brand output needs recovery: ${error.message}` }); } }
451
- if (!dryRun && captures.store.fingerprint()) { try { captures.store.promote(previewSourceRevision(loadConfig(root)), inspectScenarios(loadConfig(root)).scenarios); } catch (error) { warnings.push({ rule: "mutation-capture", message: `Source was applied; capture promotion needs recovery: ${error.message}` }); } }
452
- if (!dryRun && preparedPreview) { try { preparedPreview(); } catch (error) { warnings.push({rule:"mutation-preview-cache",message:`Source was applied; preview warming will rebuild instead: ${error.message}`}); } }
453
- return lastResult = mutationEvidence({ ok: true, ...(patches ? {units,transaction:true} : {unit}), applied: !dryRun, changes: changes.map(change => ({ path: change.path, operation: change.content === null ? "delete" : change.expectedDigest === null ? "create" : "update", digest: change.content === null ? null : digest(Buffer.from(change.content)) })), checks: verified, ...(result.advisories?.length ? { advisories: result.advisories, advisoryCount: result.advisories.length } : {}), ...(warnings.length ? { warnings } : {}),
454
- ...(screenshots ? { screenshots } : {}),
455
- preview: "Source validation passed. Inspect the managed preview build and rendered scenario after applying; validation is not visual verification." },candidateRevision);
823
+ if (!dryRun && (assets || configuration)) {
824
+ try {
825
+ await generateBrandAssets(root);
826
+ } catch (error) {
827
+ warnings.push({ rule: "mutation-assets", message: `Source was applied; generated brand output needs recovery: ${error.message}` });
828
+ }
829
+ }
830
+ if (!dryRun && captures.store.fingerprint()) {
831
+ try {
832
+ captures.store.promote(await previewSourceRevision(loadConfig(root)), (await analyze(root, "registry")).scenarios);
833
+ } catch (error) {
834
+ warnings.push({ rule: "mutation-capture", message: `Source was applied; capture promotion needs recovery: ${error.message}` });
835
+ }
836
+ }
837
+ if (!dryRun && preparedPreview) {
838
+ try {
839
+ await preparedPreview();
840
+ } catch (error) {
841
+ warnings.push({ rule: "mutation-preview-cache", message: `Source was applied; preview warming will rebuild instead: ${error.message}` });
842
+ }
843
+ }
844
+ if (!dryRun && analysisRoots.has(candidate)) {
845
+ try {
846
+ await promoteAnalysisRevision(candidate, root);
847
+ } catch {
848
+ await releaseAnalysisRevision(candidate).catch(() => {});
849
+ }
850
+ analysisRoots.delete(candidate);
851
+ }
852
+ return (lastResult = mutationEvidence(
853
+ {
854
+ ok: true,
855
+ ...(patches ? { units, transaction: true } : { unit }),
856
+ applied: !dryRun,
857
+ changes: changes.map((change) => ({
858
+ path: change.path,
859
+ operation: change.content === null ? "delete" : change.expectedDigest === null ? "create" : "update",
860
+ digest: change.content === null ? null : digest(Buffer.from(change.content)),
861
+ })),
862
+ checks: verified,
863
+ ...(result.advisories?.length ? { advisories: result.advisories, advisoryCount: result.advisories.length } : {}),
864
+ ...(warnings.length ? { warnings } : {}),
865
+ preview: "Source validation passed. Inspect the managed preview build and rendered scenario after applying; validation is not visual verification.",
866
+ },
867
+ candidateRevision,
868
+ ));
456
869
  } catch (error) {
457
- return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: [error.diagnostic ?? { rule: "mutation-error", message: error.message,failure:error.failure??boundary }], checks: verified },candidateRevision);
458
- } finally { releasePublication?.(); try { await previewHost?.close(); } finally { try { if (temporary) rmSync(temporary, { recursive: true, force: true }); } finally { releasePreview?.(); busy = false; active = undefined; progress = undefined; } } }
870
+ return (lastResult = mutationEvidence(
871
+ {
872
+ ok: false,
873
+ applied: false,
874
+ diagnostics: [error.diagnostic ?? { rule: "mutation-error", message: error.message, failure: error.failure ?? boundary }],
875
+ checks: verified,
876
+ },
877
+ candidateRevision,
878
+ ));
879
+ } finally {
880
+ for (const analysisRoot of analysisRoots) await releaseAnalysisRevision(analysisRoot).catch(() => {});
881
+ releasePublication?.();
882
+ try {
883
+ await previewHost?.close();
884
+ } finally {
885
+ try {
886
+ if (temporary) rmSync(temporary, { recursive: true, force: true });
887
+ } finally {
888
+ releasePreview?.();
889
+ busy = false;
890
+ active = undefined;
891
+ progress = undefined;
892
+ }
893
+ }
894
+ }
459
895
  },
460
896
  };
461
897
  }