@open-mercato/cli 0.11.1-develop.8593.1.50784dae35 → 0.11.1-develop.8687.1.adb16f62b3

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 (327) hide show
  1. package/.turbo/turbo-build.log +6 -2
  2. package/AGENTS.md +2 -0
  3. package/dist/agentic/guides/architecture.md +2 -2
  4. package/dist/agentic/guides/extensions.md +7 -2
  5. package/dist/agentic/guides/framework-extension-points.md +1 -0
  6. package/dist/agentic/guides/infrastructure-providers.md +20 -0
  7. package/dist/agentic/guides/integrations.md +2 -2
  8. package/dist/agentic/guides/module-facts.json +11067 -7122
  9. package/dist/agentic/guides/module-facts.v2.json +11055 -7094
  10. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  11. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  12. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  13. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  14. package/dist/agentic/guides/modules/assisted_selling/acl-features.md +16 -0
  15. package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
  16. package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
  17. package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
  18. package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
  19. package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
  20. package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
  21. package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
  22. package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
  23. package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
  24. package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
  25. package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
  26. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  27. package/dist/agentic/guides/modules/attachments/workers.md +1 -1
  28. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  29. package/dist/agentic/guides/modules/auth/index.md +1 -1
  30. package/dist/agentic/guides/modules/availability/index.md +1 -1
  31. package/dist/agentic/guides/modules/backups/di-registrations-rich.md +11 -0
  32. package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
  33. package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
  34. package/dist/agentic/guides/modules/backups/index.md +5 -2
  35. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  36. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  37. package/dist/agentic/guides/modules/cart/index.md +1 -1
  38. package/dist/agentic/guides/modules/catalog/acl-features.md +2 -1
  39. package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
  40. package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
  41. package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
  42. package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
  43. package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
  44. package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
  45. package/dist/agentic/guides/modules/catalog/entities.md +1 -0
  46. package/dist/agentic/guides/modules/catalog/events.md +4 -1
  47. package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
  48. package/dist/agentic/guides/modules/catalog/index.md +9 -9
  49. package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
  50. package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
  51. package/dist/agentic/guides/modules/catalog/workers.md +1 -0
  52. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  53. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  54. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  55. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  56. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  57. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  58. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  59. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  60. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  61. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  62. package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +1 -1
  63. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  64. package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
  65. package/dist/agentic/guides/modules/configs/index.md +1 -1
  66. package/dist/agentic/guides/modules/content/index.md +1 -1
  67. package/dist/agentic/guides/modules/currencies/active-extension-bindings.md +11 -0
  68. package/dist/agentic/guides/modules/currencies/di-registrations-rich.md +1 -1
  69. package/dist/agentic/guides/modules/currencies/di-service-tokens.md +1 -1
  70. package/dist/agentic/guides/modules/currencies/exact-override-targets.md +1 -1
  71. package/dist/agentic/guides/modules/currencies/index.md +3 -2
  72. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  73. package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
  74. package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
  75. package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
  76. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  77. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
  78. package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
  79. package/dist/agentic/guides/modules/customers/index.md +3 -3
  80. package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
  81. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
  82. package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
  83. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
  84. package/dist/agentic/guides/modules/dashboards/index.md +2 -3
  85. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  86. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  87. package/dist/agentic/guides/modules/devices/index.md +1 -1
  88. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  89. package/dist/agentic/guides/modules/directory/index.md +1 -1
  90. package/dist/agentic/guides/modules/documents/index.md +1 -1
  91. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  92. package/dist/agentic/guides/modules/entities/index.md +1 -1
  93. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  94. package/dist/agentic/guides/modules/events/index.md +1 -1
  95. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  96. package/dist/agentic/guides/modules/forms/index.md +1 -1
  97. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  98. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  99. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  100. package/dist/agentic/guides/modules/generators/index.md +1 -1
  101. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  102. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
  103. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
  104. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
  105. package/dist/agentic/guides/modules/integrations/index.md +2 -2
  106. package/dist/agentic/guides/modules/integrations/setup.md +1 -1
  107. package/dist/agentic/guides/modules/integrations/workers.md +3 -1
  108. package/dist/agentic/guides/modules/ledger/acl-features.md +16 -0
  109. package/dist/agentic/guides/modules/ledger/active-extension-bindings.md +11 -0
  110. package/dist/agentic/guides/modules/ledger/backend-pages.md +21 -0
  111. package/dist/agentic/guides/modules/ledger/domain-commands.md +22 -0
  112. package/dist/agentic/guides/modules/ledger/encryption.md +11 -0
  113. package/dist/agentic/guides/modules/ledger/entities.md +17 -0
  114. package/dist/agentic/guides/modules/ledger/events.md +19 -0
  115. package/dist/agentic/guides/modules/ledger/exact-override-targets.md +30 -0
  116. package/dist/agentic/guides/modules/ledger/index.md +22 -0
  117. package/dist/agentic/guides/modules/ledger/owned-contract-module-metadata.md +11 -0
  118. package/dist/agentic/guides/modules/ledger/setup.md +11 -0
  119. package/dist/agentic/guides/modules/ledger/umes-hosts.md +26 -0
  120. package/dist/agentic/guides/modules/messages/index.md +1 -1
  121. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  122. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  123. package/dist/agentic/guides/modules/payment_gateways/active-extension-bindings.md +1 -1
  124. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  125. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  126. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  127. package/dist/agentic/guides/modules/planner/index.md +1 -1
  128. package/dist/agentic/guides/modules/portal/index.md +1 -1
  129. package/dist/agentic/guides/modules/progress/index.md +1 -1
  130. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  131. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  132. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  133. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  134. package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
  135. package/dist/agentic/guides/modules/resources/index.md +1 -1
  136. package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
  137. package/dist/agentic/guides/modules/resources/setup.md +1 -1
  138. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
  139. package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
  140. package/dist/agentic/guides/modules/sales/index.md +3 -3
  141. package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
  142. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  143. package/dist/agentic/guides/modules/search/index.md +1 -1
  144. package/dist/agentic/guides/modules/security/index.md +1 -1
  145. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  146. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  147. package/dist/agentic/guides/modules/sso/index.md +1 -1
  148. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
  149. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
  150. package/dist/agentic/guides/modules/staff/index.md +1 -1
  151. package/dist/agentic/guides/modules/staff/workers.md +1 -1
  152. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  153. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  154. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  155. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  156. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  157. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  158. package/dist/agentic/guides/modules/translations/index.md +1 -1
  159. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  160. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  161. package/dist/agentic/guides/modules/wms/index.md +1 -1
  162. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  163. package/dist/agentic/guides/reference-module-facts.json +811 -21
  164. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
  165. package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
  166. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
  167. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
  168. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  169. package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
  170. package/dist/agentic/guides/reference-modules/example/events.md +2 -1
  171. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
  172. package/dist/agentic/guides/reference-modules/example/index.md +7 -7
  173. package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
  174. package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
  175. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
  176. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
  177. package/dist/agentic/guides/upstream/AGENTS.md +5 -4
  178. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
  179. package/dist/agentic/guides/upstream/manifest.json +3 -3
  180. package/dist/agentic/shared/AGENTS.md.template +12 -16
  181. package/dist/agentic/shared/ai/harness/README.md +4 -2
  182. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  183. package/dist/agentic/shared/ai/harness/cases.json +1420 -41
  184. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  185. package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
  186. package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
  187. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  188. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
  189. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
  190. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
  191. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
  192. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
  193. package/dist/lib/cache-provider-manifest.js +9 -0
  194. package/dist/lib/cache-provider-manifest.js.map +7 -0
  195. package/dist/lib/generate-watch-plan.js +4 -0
  196. package/dist/lib/generate-watch-plan.js.map +2 -2
  197. package/dist/lib/generate-watch-runner.js +1 -0
  198. package/dist/lib/generate-watch-runner.js.map +2 -2
  199. package/dist/lib/generate-watch-structure.js +2 -0
  200. package/dist/lib/generate-watch-structure.js.map +2 -2
  201. package/dist/lib/generators/ast/writers.js +5 -1
  202. package/dist/lib/generators/ast/writers.js.map +2 -2
  203. package/dist/lib/generators/cache-providers.js +80 -0
  204. package/dist/lib/generators/cache-providers.js.map +7 -0
  205. package/dist/lib/generators/form-section-ast.js +156 -0
  206. package/dist/lib/generators/form-section-ast.js.map +7 -0
  207. package/dist/lib/generators/form-section-extension-compiler.js +568 -0
  208. package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
  209. package/dist/lib/generators/form-section-extension-source.js +245 -0
  210. package/dist/lib/generators/form-section-extension-source.js.map +7 -0
  211. package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
  212. package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
  213. package/dist/lib/generators/form-sections.js +773 -0
  214. package/dist/lib/generators/form-sections.js.map +7 -0
  215. package/dist/lib/generators/index.js +2 -0
  216. package/dist/lib/generators/index.js.map +2 -2
  217. package/dist/lib/generators/module-entities.js +21 -2
  218. package/dist/lib/generators/module-entities.js.map +2 -2
  219. package/dist/lib/generators/module-extension-facts.js +2 -1
  220. package/dist/lib/generators/module-extension-facts.js.map +2 -2
  221. package/dist/lib/generators/module-facts.js +30 -1
  222. package/dist/lib/generators/module-facts.js.map +2 -2
  223. package/dist/lib/generators/module-override-targets.js +24 -2
  224. package/dist/lib/generators/module-override-targets.js.map +2 -2
  225. package/dist/lib/generators/module-registry.js +75 -3
  226. package/dist/lib/generators/module-registry.js.map +2 -2
  227. package/dist/lib/generators/openapi.js +27 -17
  228. package/dist/lib/generators/openapi.js.map +2 -2
  229. package/dist/lib/post-generate-invalidation.js +20 -1
  230. package/dist/lib/post-generate-invalidation.js.map +2 -2
  231. package/dist/lib/resolver.js +195 -1
  232. package/dist/lib/resolver.js.map +3 -3
  233. package/dist/lib/scaffold/field-dsl.js +393 -0
  234. package/dist/lib/scaffold/field-dsl.js.map +7 -0
  235. package/dist/lib/scaffold/index.js +412 -0
  236. package/dist/lib/scaffold/index.js.map +7 -0
  237. package/dist/lib/scaffold/targets.js +42 -0
  238. package/dist/lib/scaffold/targets.js.map +7 -0
  239. package/dist/lib/scaffold/templates/create-page.js +52 -0
  240. package/dist/lib/scaffold/templates/create-page.js.map +7 -0
  241. package/dist/lib/scaffold/templates/detail-page.js +186 -0
  242. package/dist/lib/scaffold/templates/detail-page.js.map +7 -0
  243. package/dist/lib/scaffold/templates/form-config.js +42 -0
  244. package/dist/lib/scaffold/templates/form-config.js.map +7 -0
  245. package/dist/lib/scaffold/templates/index.js +27 -0
  246. package/dist/lib/scaffold/templates/index.js.map +7 -0
  247. package/dist/lib/scaffold/templates/list-page.js +190 -0
  248. package/dist/lib/scaffold/templates/list-page.js.map +7 -0
  249. package/dist/lib/scaffold/templates/metas.js +47 -0
  250. package/dist/lib/scaffold/templates/metas.js.map +7 -0
  251. package/dist/lib/scaffold/templates/module-files.js +85 -0
  252. package/dist/lib/scaffold/templates/module-files.js.map +7 -0
  253. package/dist/lib/single-instance-strategy-guard.js +26 -3
  254. package/dist/lib/single-instance-strategy-guard.js.map +2 -2
  255. package/dist/lib/testing/integration-discovery.js +32 -3
  256. package/dist/lib/testing/integration-discovery.js.map +2 -2
  257. package/dist/lib/testing/integration.js +232 -8
  258. package/dist/lib/testing/integration.js.map +2 -2
  259. package/dist/mercato.js +40 -7
  260. package/dist/mercato.js.map +2 -2
  261. package/jest.config.cjs +2 -0
  262. package/package.json +7 -7
  263. package/src/__tests__/mercato.test.ts +18 -0
  264. package/src/__tests__/rotation-json-output.test.ts +52 -0
  265. package/src/lib/__tests__/agentic-workflows-ownership.test.ts +79 -0
  266. package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
  267. package/src/lib/__tests__/generate-watch-plan.test.ts +3 -2
  268. package/src/lib/__tests__/generate-watch-runner.test.ts +13 -1
  269. package/src/lib/__tests__/generate-watch-structure.test.ts +34 -0
  270. package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
  271. package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
  272. package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
  273. package/src/lib/cache-provider-manifest.ts +8 -0
  274. package/src/lib/generate-watch-plan.ts +6 -3
  275. package/src/lib/generate-watch-runner.ts +1 -0
  276. package/src/lib/generate-watch-structure.ts +5 -1
  277. package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
  278. package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
  279. package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
  280. package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
  281. package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
  282. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
  283. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
  284. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
  285. package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
  286. package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
  287. package/src/lib/generators/__tests__/openapi.test.ts +60 -13
  288. package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
  289. package/src/lib/generators/ast/writers.ts +6 -1
  290. package/src/lib/generators/cache-providers.ts +111 -0
  291. package/src/lib/generators/form-section-ast.ts +166 -0
  292. package/src/lib/generators/form-section-extension-compiler.ts +632 -0
  293. package/src/lib/generators/form-section-extension-source.ts +308 -0
  294. package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
  295. package/src/lib/generators/form-sections.ts +896 -0
  296. package/src/lib/generators/index.ts +1 -0
  297. package/src/lib/generators/module-entities.ts +22 -4
  298. package/src/lib/generators/module-extension-facts.ts +1 -0
  299. package/src/lib/generators/module-facts.ts +40 -0
  300. package/src/lib/generators/module-override-targets.ts +19 -0
  301. package/src/lib/generators/module-registry.ts +80 -4
  302. package/src/lib/generators/openapi.ts +31 -20
  303. package/src/lib/post-generate-invalidation.ts +28 -1
  304. package/src/lib/resolver.ts +218 -0
  305. package/src/lib/scaffold/__tests__/__snapshots__/scaffold-golden.test.ts.snap +1742 -0
  306. package/src/lib/scaffold/__tests__/helpers.ts +75 -0
  307. package/src/lib/scaffold/__tests__/scaffold-ds-contract.test.ts +248 -0
  308. package/src/lib/scaffold/__tests__/scaffold-golden.test.ts +267 -0
  309. package/src/lib/scaffold/__tests__/scaffold-runtime.test.tsx +193 -0
  310. package/src/lib/scaffold/field-dsl.ts +491 -0
  311. package/src/lib/scaffold/index.ts +531 -0
  312. package/src/lib/scaffold/targets.ts +68 -0
  313. package/src/lib/scaffold/templates/create-page.ts +52 -0
  314. package/src/lib/scaffold/templates/detail-page.ts +190 -0
  315. package/src/lib/scaffold/templates/form-config.ts +42 -0
  316. package/src/lib/scaffold/templates/index.ts +27 -0
  317. package/src/lib/scaffold/templates/list-page.ts +190 -0
  318. package/src/lib/scaffold/templates/metas.ts +48 -0
  319. package/src/lib/scaffold/templates/module-files.ts +87 -0
  320. package/src/lib/single-instance-strategy-guard.ts +51 -1
  321. package/src/lib/testing/__tests__/integration-app-only-playwright.test.ts +225 -0
  322. package/src/lib/testing/__tests__/integration-app-only.test.ts +320 -0
  323. package/src/lib/testing/__tests__/integration-discovery.test.ts +45 -1
  324. package/src/lib/testing/integration-discovery.ts +32 -2
  325. package/src/lib/testing/integration.ts +293 -11
  326. package/src/mercato.ts +39 -5
  327. package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
@@ -0,0 +1,531 @@
1
+ /**
2
+ * `mercato module scaffold` orchestrator: parse flags → plan → write → report.
3
+ * Spec: .ai/specs/2026-07-05-ds-module-ui-scaffold.md
4
+ *
5
+ * Rules enforced here (CLI AGENTS.md + spec):
6
+ * - deterministic output: identical inputs produce byte-identical files
7
+ * (stable ordering, no timestamps);
8
+ * - hard no-overwrite: if any target file exists, abort listing conflicts
9
+ * (exit 1) — `acl.ts` / `setup.ts` / `index.ts` are the exception: they are
10
+ * generated only when absent and otherwise reported, never touched;
11
+ * - `--dry-run` prints the plan without writing.
12
+ */
13
+ import fs from 'node:fs'
14
+ import path from 'node:path'
15
+ import type { PackageResolver } from '../resolver'
16
+ import { createResolver } from '../resolver'
17
+ import {
18
+ FIELD_DSL_GRAMMAR,
19
+ FieldDslError,
20
+ buildFieldI18nEntries,
21
+ camelCase,
22
+ emitColumnLines,
23
+ emitCrudFieldLines,
24
+ emitFieldIdList,
25
+ emitFilterDefLines,
26
+ emitFilterParamLines,
27
+ emitInitialValueLines,
28
+ emitRowTypeLines,
29
+ emitStatusMapEntries,
30
+ emitStatusUnion,
31
+ emitZodFieldLines,
32
+ findStatusField,
33
+ hasCheckboxField,
34
+ humanizeIdentifier,
35
+ parseFieldsSpec,
36
+ pascalCase,
37
+ selectFields,
38
+ upperSnakeCase,
39
+ type ScaffoldField,
40
+ } from './field-dsl'
41
+ import { ScaffoldTargetError, resolveScaffoldTarget, type ScaffoldTarget } from './targets'
42
+ import {
43
+ aclTemplate,
44
+ createMetaTemplate,
45
+ createPageTemplate,
46
+ detailMetaTemplate,
47
+ detailPageTemplate,
48
+ formConfigTemplate,
49
+ listMetaTemplate,
50
+ listPageTemplate,
51
+ moduleIndexTemplate,
52
+ setupTemplate,
53
+ statusMapTemplate,
54
+ validatorsTemplate,
55
+ } from './templates'
56
+
57
+ const MODULE_ID_PATTERN = /^[a-z][a-z0-9_]*$/
58
+ const FEATURES_PREFIX_PATTERN = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*$/
59
+ const PLACEHOLDER_PATTERN = /\{\{([a-zA-Z0-9]+)\}\}/g
60
+
61
+ export const SCAFFOLD_USAGE = [
62
+ 'Usage: yarn mercato module scaffold <module_id> --entity <entity_singular> --fields "<fields>" [options]',
63
+ '',
64
+ 'Options:',
65
+ ' --entity <name> Singular entity name (snake_case) — drives file names,',
66
+ ' i18n key prefixes, StatusMap type and the API path.',
67
+ ' --fields "<spec>" Field DSL declaration (required, see grammar below).',
68
+ ' --with-ui Generate the DS-compliant page slice (default: on).',
69
+ ' --target <target> app (default) → apps/mercato/src/modules/<module_id>/',
70
+ ' packages/core → packages/core/src/modules/<module_id>/',
71
+ ' --features-prefix <p> Feature-id prefix (default: <module_id>).',
72
+ ' --dry-run Print the file plan without writing.',
73
+ '',
74
+ FIELD_DSL_GRAMMAR,
75
+ ].join('\n')
76
+
77
+ export type ScaffoldOptions = {
78
+ moduleId: string
79
+ entity: string
80
+ fields: ScaffoldField[]
81
+ featuresPrefix: string
82
+ target: string
83
+ dryRun: boolean
84
+ }
85
+
86
+ export type ScaffoldPlanFile = {
87
+ /** Path relative to the module directory (POSIX separators). */
88
+ relPath: string
89
+ contents: string
90
+ }
91
+
92
+ export type ScaffoldPlan = {
93
+ moduleDir: string
94
+ files: ScaffoldPlanFile[]
95
+ /** Backbone files that already exist and are intentionally left untouched. */
96
+ skipped: string[]
97
+ /** Feature ids the generated pages reference. */
98
+ expectedFeatures: string[]
99
+ }
100
+
101
+ export function renderTemplate(templateName: string, template: string, vars: Record<string, string>): string {
102
+ const rendered = template.replace(PLACEHOLDER_PATTERN, (_match, name: string) => {
103
+ const value = vars[name]
104
+ if (value === undefined) {
105
+ throw new Error(`[scaffold] template "${templateName}" references unknown placeholder {{${name}}}`)
106
+ }
107
+ return value
108
+ })
109
+ const leftover = rendered.match(PLACEHOLDER_PATTERN)
110
+ if (leftover) {
111
+ throw new Error(`[scaffold] template "${templateName}" left unresolved placeholders: ${leftover.join(', ')}`)
112
+ }
113
+ return rendered
114
+ }
115
+
116
+ // ---------------------------------------------------------------------------
117
+ // Argument parsing
118
+ // ---------------------------------------------------------------------------
119
+
120
+ type ParsedArgs =
121
+ | { ok: true; options: ScaffoldOptions }
122
+ | { ok: false; error: string }
123
+
124
+ export function parseScaffoldArgs(args: string[]): ParsedArgs {
125
+ let moduleId: string | null = null
126
+ let entity: string | null = null
127
+ let fieldsSpec: string | null = null
128
+ let target = 'app'
129
+ let featuresPrefix: string | null = null
130
+ let dryRun = false
131
+
132
+ const takesValue = new Set(['--entity', '--fields', '--target', '--features-prefix'])
133
+
134
+ for (let i = 0; i < args.length; i++) {
135
+ const arg = args[i]
136
+ if (takesValue.has(arg)) {
137
+ const value = args[i + 1]
138
+ if (value === undefined || value.startsWith('--')) {
139
+ return { ok: false, error: `Flag ${arg} needs a value.` }
140
+ }
141
+ i++
142
+ if (arg === '--entity') entity = value
143
+ else if (arg === '--fields') fieldsSpec = value
144
+ else if (arg === '--target') target = value
145
+ else featuresPrefix = value
146
+ continue
147
+ }
148
+ if (arg === '--with-ui') continue // default on
149
+ if (arg === '--no-ui') {
150
+ return {
151
+ ok: false,
152
+ error: '--no-ui is reserved for a future backbone-only mode and is not implemented yet.',
153
+ }
154
+ }
155
+ if (arg === '--dry-run') {
156
+ dryRun = true
157
+ continue
158
+ }
159
+ if (arg.startsWith('-')) {
160
+ return { ok: false, error: `Unknown flag "${arg}".` }
161
+ }
162
+ if (moduleId !== null) {
163
+ return { ok: false, error: `Unexpected argument "${arg}" — module id already set to "${moduleId}".` }
164
+ }
165
+ moduleId = arg
166
+ }
167
+
168
+ if (!moduleId) return { ok: false, error: 'Missing <module_id>.' }
169
+ if (!MODULE_ID_PATTERN.test(moduleId)) {
170
+ return { ok: false, error: `Invalid module id "${moduleId}" — expected plural snake_case matching ^[a-z][a-z0-9_]*$.` }
171
+ }
172
+ if (!entity) return { ok: false, error: 'Missing --entity <entity_singular>.' }
173
+ if (!MODULE_ID_PATTERN.test(entity)) {
174
+ return { ok: false, error: `Invalid entity name "${entity}" — expected singular snake_case matching ^[a-z][a-z0-9_]*$.` }
175
+ }
176
+ if (!fieldsSpec) return { ok: false, error: 'Missing --fields "<spec>".' }
177
+
178
+ const prefix = featuresPrefix ?? moduleId
179
+ if (!FEATURES_PREFIX_PATTERN.test(prefix)) {
180
+ return { ok: false, error: `Invalid --features-prefix "${prefix}".` }
181
+ }
182
+
183
+ let fields: ScaffoldField[]
184
+ try {
185
+ fields = parseFieldsSpec(fieldsSpec)
186
+ } catch (error) {
187
+ if (error instanceof FieldDslError) return { ok: false, error: error.message }
188
+ throw error
189
+ }
190
+
191
+ return {
192
+ ok: true,
193
+ options: { moduleId, entity, fields, featuresPrefix: prefix, target, dryRun },
194
+ }
195
+ }
196
+
197
+ // ---------------------------------------------------------------------------
198
+ // Plan building
199
+ // ---------------------------------------------------------------------------
200
+
201
+ type TemplateVars = Record<string, string>
202
+
203
+ function buildTemplateVars(options: ScaffoldOptions): TemplateVars {
204
+ const { moduleId, entity, fields, featuresPrefix } = options
205
+ const entityPascal = pascalCase(entity)
206
+ const entityCamel = camelCase(entity)
207
+ const entityUpperSnake = upperSnakeCase(entity)
208
+ const entityTitle = humanizeIdentifier(entity)
209
+ const entityLower = entityTitle.toLowerCase()
210
+ const moduleTitle = humanizeIdentifier(moduleId)
211
+ const moduleTitleLower = moduleTitle.toLowerCase()
212
+
213
+ const statusField = findStatusField(fields)
214
+ const selects = selectFields(fields)
215
+ const statusTypeIdent = statusField ? `${entityPascal}Status` : null
216
+ const statusMapIdent = statusField ? `${entityCamel}StatusMap` : null
217
+
218
+ const firstTextField = fields.find((field) => field.type === 'text') ?? null
219
+ const detailTitleExpr = firstTextField
220
+ ? firstTextField.required
221
+ ? `record.${firstTextField.name}`
222
+ : `record.${firstTextField.name} ?? record.id`
223
+ : 'record.id'
224
+
225
+ const statusBadgeProp = statusField
226
+ ? [
227
+ ' statusBadge={record.status ? (',
228
+ ` <StatusBadge variant={${statusMapIdent}[record.status] ?? 'neutral'} dot>`,
229
+ ` {t('${moduleId}.fields.status.options.' + record.status, record.status)}`,
230
+ ' </StatusBadge>',
231
+ ' ) : undefined}',
232
+ '',
233
+ ].join('\n')
234
+ : ''
235
+
236
+ const filtersMemo = selects.length
237
+ ? [
238
+ ' const filters = React.useMemo<FilterDef[]>(() => [',
239
+ emitFilterDefLines(fields, moduleId),
240
+ ' ], [t])',
241
+ '',
242
+ '',
243
+ ].join('\n')
244
+ : ''
245
+
246
+ const filterProps = selects.length
247
+ ? [
248
+ ' filters={filters}',
249
+ ' filterValues={filterValues}',
250
+ ' onFiltersApply={(values) => { setFilterValues(values); setPage(1) }}',
251
+ " onFiltersClear={() => { setFilterValues({}); setPage(1) }}",
252
+ '',
253
+ ].join('\n')
254
+ : ''
255
+
256
+ return {
257
+ moduleId,
258
+ moduleTitle,
259
+ moduleTitleLower,
260
+ entityPascal,
261
+ entityCamel,
262
+ entityUpperSnake,
263
+ entityTitle,
264
+ entityLower,
265
+ entitySnake: entity,
266
+ featuresPrefix,
267
+ rowTypeFields: emitRowTypeLines(fields, statusTypeIdent),
268
+ columnsBlock: emitColumnLines(fields, moduleId, statusMapIdent),
269
+ zodFields: emitZodFieldLines(fields),
270
+ crudFields: emitCrudFieldLines(fields, moduleId),
271
+ fieldIdList: emitFieldIdList(fields),
272
+ initialValueLines: emitInitialValueLines(fields),
273
+ detailTitleExpr,
274
+ statusBadgeProp,
275
+ statusUnion: statusField ? emitStatusUnion(statusField) : '',
276
+ statusMapEntries: statusField ? emitStatusMapEntries(statusField) : '',
277
+ statusImports: '', // overridden per page below
278
+ dateImport: fields.some((field) => field.type === 'date')
279
+ ? "import { parseISO } from 'date-fns/parseISO'\n"
280
+ : '',
281
+ filterTypeImport: selects.length
282
+ ? "import type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterOverlay'\n"
283
+ : '',
284
+ filterStateLine: selects.length
285
+ ? ' const [filterValues, setFilterValues] = React.useState<FilterValues>({})\n'
286
+ : '',
287
+ filterParamLines: selects.length ? `${emitFilterParamLines(fields)}\n` : '',
288
+ listParamsDeps: selects.length ? '[filterValues, page, search]' : '[page, search]',
289
+ filtersMemo,
290
+ filterProps,
291
+ }
292
+ }
293
+
294
+ function buildI18nEntries(options: ScaffoldOptions, vars: TemplateVars): Record<string, string> {
295
+ const p = options.moduleId
296
+ const entries: Record<string, string> = {
297
+ [`${p}.nav.group`]: vars.moduleTitle,
298
+ [`${p}.nav.title`]: vars.moduleTitle,
299
+ [`${p}.list.title`]: vars.moduleTitle,
300
+ [`${p}.list.searchPlaceholder`]: `Search ${vars.moduleTitleLower}`,
301
+ [`${p}.list.actions.create`]: `Create ${vars.entityLower}`,
302
+ [`${p}.list.actions.edit`]: 'Edit',
303
+ [`${p}.list.actions.delete`]: 'Delete',
304
+ [`${p}.list.empty.title`]: `No ${vars.moduleTitleLower} yet`,
305
+ [`${p}.list.empty.description`]: `Create your first ${vars.entityLower} to get started.`,
306
+ [`${p}.list.loadError`]: `Failed to load ${vars.moduleTitleLower}`,
307
+ [`${p}.create.title`]: `Create ${vars.entityLower}`,
308
+ [`${p}.create.success`]: `${vars.entityTitle} created`,
309
+ [`${p}.form.submit`]: 'Save',
310
+ [`${p}.form.groups.details`]: 'Details',
311
+ [`${p}.form.groups.attributes`]: 'Attributes',
312
+ [`${p}.delete.confirmTitle`]: `Delete ${vars.entityLower}?`,
313
+ [`${p}.delete.confirmDescription`]: 'This action cannot be undone.',
314
+ [`${p}.delete.success`]: `${vars.entityTitle} deleted`,
315
+ [`${p}.delete.error`]: `Failed to delete ${vars.entityLower}`,
316
+ [`${p}.detail.title`]: `${vars.entityTitle} details`,
317
+ [`${p}.detail.loading`]: `Loading ${vars.entityLower}`,
318
+ [`${p}.detail.notFound`]: `${vars.entityTitle} not found`,
319
+ [`${p}.detail.loadError`]: `Failed to load ${vars.entityLower}`,
320
+ [`${p}.detail.tabs.label`]: `${vars.entityTitle} sections`,
321
+ [`${p}.detail.tabs.overview`]: 'Overview',
322
+ [`${p}.detail.updateSuccess`]: `${vars.entityTitle} updated`,
323
+ [`${p}.detail.actions.delete`]: 'Delete',
324
+ ...buildFieldI18nEntries(options.fields, p),
325
+ }
326
+ if (hasCheckboxField(options.fields)) {
327
+ entries[`${p}.list.boolean.yes`] = 'Yes'
328
+ entries[`${p}.list.boolean.no`] = 'No'
329
+ }
330
+ return entries
331
+ }
332
+
333
+ function renderI18nJson(entries: Record<string, string>): string {
334
+ const sorted: Record<string, string> = {}
335
+ for (const key of Object.keys(entries).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))) sorted[key] = entries[key]
336
+ return `${JSON.stringify(sorted, null, 2)}\n`
337
+ }
338
+
339
+ export const NON_ENGLISH_LOCALES = ['pl', 'es', 'de', 'ko'] as const
340
+
341
+ export function buildScaffoldPlan(options: ScaffoldOptions, target: ScaffoldTarget): ScaffoldPlan {
342
+ const vars = buildTemplateVars(options)
343
+ const statusField = findStatusField(options.fields)
344
+ const { moduleId } = options
345
+
346
+ const files: ScaffoldPlanFile[] = []
347
+ const push = (relPath: string, templateName: string, template: string, overrides: TemplateVars = {}) => {
348
+ files.push({
349
+ relPath,
350
+ contents: renderTemplate(templateName, template, { ...vars, ...overrides }),
351
+ })
352
+ }
353
+
354
+ push(`backend/${moduleId}/page.tsx`, 'list-page', listPageTemplate, {
355
+ statusImports: statusField
356
+ ? `import { StatusBadge } from '@open-mercato/ui/primitives/status-badge'\n` +
357
+ `import { ${vars.entityCamel}StatusMap, type ${vars.entityPascal}Status } from '../../components/statusMap'\n`
358
+ : '',
359
+ })
360
+ push(`backend/${moduleId}/page.meta.ts`, 'list-meta', listMetaTemplate)
361
+ push(`backend/${moduleId}/create/page.tsx`, 'create-page', createPageTemplate)
362
+ push(`backend/${moduleId}/create/page.meta.ts`, 'create-meta', createMetaTemplate)
363
+ push(`backend/${moduleId}/[id]/page.tsx`, 'detail-page', detailPageTemplate, {
364
+ statusImports: statusField
365
+ ? `import { StatusBadge } from '@open-mercato/ui/primitives/status-badge'\n` +
366
+ `import { ${vars.entityCamel}StatusMap, type ${vars.entityPascal}Status } from '../../../components/statusMap'\n`
367
+ : '',
368
+ })
369
+ push(`backend/${moduleId}/[id]/page.meta.ts`, 'detail-meta', detailMetaTemplate)
370
+ push('components/formConfig.ts', 'form-config', formConfigTemplate)
371
+ if (statusField) {
372
+ push('components/statusMap.ts', 'status-map', statusMapTemplate)
373
+ }
374
+ push('data/validators.ts', 'validators', validatorsTemplate)
375
+
376
+ // acl.ts / setup.ts / index.ts are generated only when absent — the UI slice
377
+ // must reference real feature ids; an existing module is never appended to.
378
+ const skipped: string[] = []
379
+ const backbone: Array<[string, string, string]> = [
380
+ ['acl.ts', 'acl', aclTemplate],
381
+ ['setup.ts', 'setup', setupTemplate],
382
+ ['index.ts', 'module-index', moduleIndexTemplate],
383
+ ]
384
+ for (const [relPath, templateName, template] of backbone) {
385
+ if (fs.existsSync(path.join(target.moduleDir, relPath))) {
386
+ skipped.push(relPath)
387
+ } else {
388
+ push(relPath, templateName, template)
389
+ }
390
+ }
391
+
392
+ const i18nEntries = buildI18nEntries(options, vars)
393
+ const i18nJson = renderI18nJson(i18nEntries)
394
+ files.push({ relPath: 'i18n/en.json', contents: i18nJson })
395
+ for (const locale of NON_ENGLISH_LOCALES) {
396
+ // Identical key set with English values — key parity on day zero beats
397
+ // missing files; `yarn i18n:check-values` nudges the actual translation.
398
+ files.push({ relPath: `i18n/${locale}.json`, contents: i18nJson })
399
+ }
400
+
401
+ const expectedFeatures = ['view', 'create', 'edit', 'delete'].map(
402
+ (verb) => `${options.featuresPrefix}.${verb}`,
403
+ )
404
+
405
+ return { moduleDir: target.moduleDir, files, skipped, expectedFeatures }
406
+ }
407
+
408
+ // ---------------------------------------------------------------------------
409
+ // Reporting
410
+ // ---------------------------------------------------------------------------
411
+
412
+ type Logger = {
413
+ log: (message: string) => void
414
+ error: (message: string) => void
415
+ }
416
+
417
+ function printNextSteps(logger: Logger, target: ScaffoldTarget, options: ScaffoldOptions) {
418
+ const modulesConfigHint =
419
+ target.kind === 'app' ? 'apps/mercato/src/modules.ts' : 'apps/mercato/src/modules.ts (or the consuming app)'
420
+ logger.log('Next steps:')
421
+ logger.log(
422
+ ` 1. Enable the module: add { id: '${options.moduleId}', from: '${target.registrationFrom}' } to ${modulesConfigHint}`,
423
+ )
424
+ logger.log(' 2. Regenerate registries: yarn generate')
425
+ logger.log(' 3. Wire the backend: add data/entities.ts + api/ CRUD route, then yarn db:generate')
426
+ logger.log(' 4. Verify DS compliance: yarn lint:ds')
427
+ }
428
+
429
+ // ---------------------------------------------------------------------------
430
+ // Entry point
431
+ // ---------------------------------------------------------------------------
432
+
433
+ export type ScaffoldDeps = {
434
+ resolver?: PackageResolver
435
+ logger?: Logger
436
+ }
437
+
438
+ export async function runModuleScaffold(args: string[], deps: ScaffoldDeps = {}): Promise<number> {
439
+ const logger: Logger = deps.logger ?? { log: console.log, error: console.error }
440
+
441
+ const parsed = parseScaffoldArgs(args)
442
+ if (!parsed.ok) {
443
+ logger.error(`❌ ${parsed.error}`)
444
+ logger.error('')
445
+ logger.error(SCAFFOLD_USAGE)
446
+ return 1
447
+ }
448
+ const options = parsed.options
449
+
450
+ const resolver = deps.resolver ?? createResolver()
451
+
452
+ let target: ScaffoldTarget
453
+ try {
454
+ target = resolveScaffoldTarget(resolver, options.target, options.moduleId)
455
+ } catch (error) {
456
+ if (error instanceof ScaffoldTargetError) {
457
+ logger.error(`❌ ${error.message}`)
458
+ return 1
459
+ }
460
+ throw error
461
+ }
462
+
463
+ const plan = buildScaffoldPlan(options, target)
464
+ const rootDir = resolver.getRootDir()
465
+ const relModuleDir = path.relative(rootDir, target.moduleDir) || target.moduleDir
466
+
467
+ if (options.dryRun) {
468
+ logger.log(`Plan for module "${options.moduleId}" → ${relModuleDir} (dry run, nothing written):`)
469
+ for (const file of plan.files) {
470
+ const conflict = fs.existsSync(path.join(target.moduleDir, file.relPath))
471
+ logger.log(conflict ? ` ! ${file.relPath} (conflict — a real run would abort)` : ` + ${file.relPath}`)
472
+ }
473
+ for (const relPath of plan.skipped) {
474
+ logger.log(` = ${relPath} (exists, left untouched)`)
475
+ }
476
+ if (plan.skipped.length > 0) {
477
+ logger.log(`Pages expect features: ${plan.expectedFeatures.join(', ')}`)
478
+ }
479
+ logger.log('')
480
+ printNextSteps(logger, target, options)
481
+ return 0
482
+ }
483
+
484
+ // Hard no-overwrite rule: collect every conflict, then abort with exit 1.
485
+ const conflicts = plan.files
486
+ .map((file) => file.relPath)
487
+ .filter((relPath) => fs.existsSync(path.join(target.moduleDir, relPath)))
488
+ if (conflicts.length > 0) {
489
+ logger.error(`❌ Scaffold aborted — target files already exist under ${relModuleDir}:`)
490
+ for (const relPath of conflicts) {
491
+ logger.error(` ${relPath}`)
492
+ }
493
+ logger.error('No files were written. Remove the conflicting files or pick a different module id.')
494
+ return 1
495
+ }
496
+
497
+ const written: string[] = []
498
+ try {
499
+ for (const file of plan.files) {
500
+ const absPath = path.join(target.moduleDir, file.relPath)
501
+ fs.mkdirSync(path.dirname(absPath), { recursive: true })
502
+ fs.writeFileSync(absPath, file.contents, { flag: 'wx' })
503
+ written.push(file.relPath)
504
+ }
505
+ } catch (error) {
506
+ logger.error(`❌ Scaffold failed mid-write: ${error instanceof Error ? error.message : String(error)}`)
507
+ if (written.length > 0) {
508
+ logger.error(`Files already written (remove them before retrying):`)
509
+ for (const relPath of written) logger.error(` ${relPath}`)
510
+ }
511
+ return 1
512
+ }
513
+
514
+ logger.log(`\n✅ Module "${options.moduleId}" UI slice scaffolded → ${relModuleDir}\n`)
515
+ logger.log('Created:')
516
+ for (const file of plan.files) {
517
+ logger.log(` ${file.relPath}`)
518
+ }
519
+ if (plan.skipped.length > 0) {
520
+ logger.log('Skipped (already present, left untouched):')
521
+ for (const relPath of plan.skipped) {
522
+ logger.log(` ${relPath}`)
523
+ }
524
+ logger.log(` → pages expect features: ${plan.expectedFeatures.join(', ')}`)
525
+ }
526
+ logger.log('')
527
+ logger.log(`Locales ${NON_ENGLISH_LOCALES.join(', ')} were generated with English values — needs translation.`)
528
+ logger.log('')
529
+ printNextSteps(logger, target, options)
530
+ return 0
531
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Monorepo target resolution for `mercato module scaffold` (spec:
3
+ * .ai/specs/2026-07-05-ds-module-ui-scaffold.md §CLI contract, `--target`).
4
+ */
5
+ import path from 'node:path'
6
+ import type { PackageResolver } from '../resolver'
7
+
8
+ export type ScaffoldTargetKind = 'app' | 'packages/core'
9
+
10
+ export const SCAFFOLD_TARGETS: ScaffoldTargetKind[] = ['app', 'packages/core']
11
+
12
+ export type ScaffoldTarget = {
13
+ kind: ScaffoldTargetKind
14
+ /** Absolute path of the modules root the module directory lives under. */
15
+ modulesRoot: string
16
+ /** Absolute path of the module directory to scaffold into. */
17
+ moduleDir: string
18
+ /** `from` value for the modules.ts registration entry in the next-steps block. */
19
+ registrationFrom: '@app' | '@open-mercato/core'
20
+ }
21
+
22
+ export class ScaffoldTargetError extends Error {
23
+ constructor(message: string) {
24
+ super(message)
25
+ this.name = 'ScaffoldTargetError'
26
+ }
27
+ }
28
+
29
+ export function resolveScaffoldTarget(
30
+ resolver: PackageResolver,
31
+ target: string,
32
+ moduleId: string,
33
+ ): ScaffoldTarget {
34
+ if (!resolver.isMonorepo()) {
35
+ // PHASE-3 SEAM (standalone target resolution): in a standalone create-app
36
+ // consumer the default and only target is `src/modules/<module_id>/` under
37
+ // the app dir (`resolver.getAppDir()`), detected the same way
38
+ // `createResolver()` detects `node_modules/@open-mercato/*/dist/modules/`.
39
+ // Wire it here when Phase 3 lands; until then the command is monorepo-only.
40
+ throw new ScaffoldTargetError(
41
+ 'module scaffold currently supports monorepo checkouts only — standalone app support lands in a later phase.',
42
+ )
43
+ }
44
+
45
+ if (target === 'app') {
46
+ const modulesRoot = path.join(resolver.getAppDir(), 'src', 'modules')
47
+ return {
48
+ kind: 'app',
49
+ modulesRoot,
50
+ moduleDir: path.join(modulesRoot, moduleId),
51
+ registrationFrom: '@app',
52
+ }
53
+ }
54
+
55
+ if (target === 'packages/core') {
56
+ const modulesRoot = path.join(resolver.getRootDir(), 'packages', 'core', 'src', 'modules')
57
+ return {
58
+ kind: 'packages/core',
59
+ modulesRoot,
60
+ moduleDir: path.join(modulesRoot, moduleId),
61
+ registrationFrom: '@open-mercato/core',
62
+ }
63
+ }
64
+
65
+ throw new ScaffoldTargetError(
66
+ `Unknown --target "${target}" — supported targets: ${SCAFFOLD_TARGETS.join(', ')}.`,
67
+ )
68
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Create page template (lineage: om-ds-guardian page-templates.md §Create Page +
3
+ * packages/core/src/modules/customers/backend/customers/people/create/page.tsx).
4
+ */
5
+ export const createPageTemplate = `"use client"
6
+
7
+ import * as React from 'react'
8
+ import { useRouter } from 'next/navigation'
9
+ import { Page, PageBody } from '@open-mercato/ui/backend/Page'
10
+ import { CrudForm } from '@open-mercato/ui/backend/CrudForm'
11
+ import { createCrud } from '@open-mercato/ui/backend/utils/crud'
12
+ import { flash } from '@open-mercato/ui/backend/FlashMessages'
13
+ import { useT } from '@open-mercato/shared/lib/i18n/context'
14
+ import {
15
+ {{entityUpperSnake}}_ENTITY_ID,
16
+ create{{entityPascal}}FormFields,
17
+ create{{entityPascal}}FormGroups,
18
+ create{{entityPascal}}FormSchema,
19
+ type {{entityPascal}}FormValues,
20
+ } from '../../../components/formConfig'
21
+
22
+ export default function {{entityPascal}}CreatePage() {
23
+ const t = useT()
24
+ const router = useRouter()
25
+ const schema = React.useMemo(() => create{{entityPascal}}FormSchema(), [])
26
+ const fields = React.useMemo(() => create{{entityPascal}}FormFields(t), [t])
27
+ const groups = React.useMemo(() => create{{entityPascal}}FormGroups(t), [t])
28
+
29
+ return (
30
+ <Page>
31
+ <PageBody>
32
+ <CrudForm<{{entityPascal}}FormValues>
33
+ title={t('{{moduleId}}.create.title', 'Create {{entityLower}}')}
34
+ backHref="/backend/{{moduleId}}"
35
+ cancelHref="/backend/{{moduleId}}"
36
+ schema={schema}
37
+ fields={fields}
38
+ groups={groups}
39
+ entityIds={[{{entityUpperSnake}}_ENTITY_ID]}
40
+ submitLabel={t('{{moduleId}}.form.submit', 'Save')}
41
+ onSubmit={async (values) => {
42
+ const call = await createCrud<{ id?: string }>('{{moduleId}}', values)
43
+ const createdId = typeof call.result?.id === 'string' ? call.result.id : null
44
+ flash(t('{{moduleId}}.create.success', '{{entityTitle}} created'), 'success')
45
+ router.push(createdId ? '/backend/{{moduleId}}/' + createdId : '/backend/{{moduleId}}')
46
+ }}
47
+ />
48
+ </PageBody>
49
+ </Page>
50
+ )
51
+ }
52
+ `