@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8665.1.2455b2503c

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 (285) hide show
  1. package/.turbo/turbo-build.log +4 -2
  2. package/AGENTS.md +3 -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 +2564 -265
  9. package/dist/agentic/guides/module-facts.v2.json +2580 -265
  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/index.md +1 -1
  63. package/dist/agentic/guides/modules/configs/index.md +1 -1
  64. package/dist/agentic/guides/modules/content/index.md +1 -1
  65. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  66. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  67. package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
  68. package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
  69. package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
  70. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  71. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
  72. package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
  73. package/dist/agentic/guides/modules/customers/index.md +3 -3
  74. package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
  75. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
  76. package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
  77. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
  78. package/dist/agentic/guides/modules/dashboards/index.md +2 -3
  79. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  80. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  81. package/dist/agentic/guides/modules/devices/index.md +1 -1
  82. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  83. package/dist/agentic/guides/modules/directory/index.md +1 -1
  84. package/dist/agentic/guides/modules/documents/index.md +1 -1
  85. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  86. package/dist/agentic/guides/modules/entities/index.md +1 -1
  87. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  88. package/dist/agentic/guides/modules/events/index.md +1 -1
  89. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  90. package/dist/agentic/guides/modules/forms/index.md +1 -1
  91. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  92. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  93. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  94. package/dist/agentic/guides/modules/generators/index.md +1 -1
  95. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  96. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
  97. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
  98. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
  99. package/dist/agentic/guides/modules/integrations/index.md +2 -2
  100. package/dist/agentic/guides/modules/integrations/setup.md +1 -1
  101. package/dist/agentic/guides/modules/integrations/workers.md +3 -1
  102. package/dist/agentic/guides/modules/messages/index.md +1 -1
  103. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  104. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  105. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  106. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  107. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  108. package/dist/agentic/guides/modules/planner/index.md +1 -1
  109. package/dist/agentic/guides/modules/portal/index.md +1 -1
  110. package/dist/agentic/guides/modules/progress/index.md +1 -1
  111. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  112. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  113. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  114. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  115. package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
  116. package/dist/agentic/guides/modules/resources/index.md +1 -1
  117. package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
  118. package/dist/agentic/guides/modules/resources/setup.md +1 -1
  119. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
  120. package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
  121. package/dist/agentic/guides/modules/sales/index.md +3 -3
  122. package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
  123. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  124. package/dist/agentic/guides/modules/search/index.md +1 -1
  125. package/dist/agentic/guides/modules/security/index.md +1 -1
  126. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  127. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  128. package/dist/agentic/guides/modules/sso/index.md +1 -1
  129. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
  130. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
  131. package/dist/agentic/guides/modules/staff/index.md +1 -1
  132. package/dist/agentic/guides/modules/staff/workers.md +1 -1
  133. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  134. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  135. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  136. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  137. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  138. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  139. package/dist/agentic/guides/modules/translations/index.md +1 -1
  140. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  141. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  142. package/dist/agentic/guides/modules/wms/index.md +1 -1
  143. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  144. package/dist/agentic/guides/reference-module-facts.json +811 -21
  145. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
  146. package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
  147. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
  148. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
  149. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  150. package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
  151. package/dist/agentic/guides/reference-modules/example/events.md +2 -1
  152. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
  153. package/dist/agentic/guides/reference-modules/example/index.md +7 -7
  154. package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
  155. package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
  156. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
  157. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
  158. package/dist/agentic/guides/upstream/AGENTS.md +5 -4
  159. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
  160. package/dist/agentic/guides/upstream/manifest.json +3 -3
  161. package/dist/agentic/shared/AGENTS.md.template +11 -15
  162. package/dist/agentic/shared/ai/harness/README.md +4 -2
  163. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  164. package/dist/agentic/shared/ai/harness/cases.json +1420 -41
  165. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  166. package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
  167. package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
  168. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  169. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
  170. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
  171. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
  172. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
  173. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
  174. package/dist/lib/cache-provider-manifest.js +9 -0
  175. package/dist/lib/cache-provider-manifest.js.map +7 -0
  176. package/dist/lib/generate-child-process.js +21 -3
  177. package/dist/lib/generate-child-process.js.map +2 -2
  178. package/dist/lib/generate-watch-events.js +135 -19
  179. package/dist/lib/generate-watch-events.js.map +2 -2
  180. package/dist/lib/generate-watch-plan.js +170 -0
  181. package/dist/lib/generate-watch-plan.js.map +7 -0
  182. package/dist/lib/generate-watch-runner.js +54 -0
  183. package/dist/lib/generate-watch-runner.js.map +7 -0
  184. package/dist/lib/generate-watch-structure.js +578 -203
  185. package/dist/lib/generate-watch-structure.js.map +3 -3
  186. package/dist/lib/generators/ast/writers.js +5 -1
  187. package/dist/lib/generators/ast/writers.js.map +2 -2
  188. package/dist/lib/generators/cache-providers.js +80 -0
  189. package/dist/lib/generators/cache-providers.js.map +7 -0
  190. package/dist/lib/generators/extensions/agent-files.js +1 -0
  191. package/dist/lib/generators/extensions/agent-files.js.map +2 -2
  192. package/dist/lib/generators/form-section-ast.js +156 -0
  193. package/dist/lib/generators/form-section-ast.js.map +7 -0
  194. package/dist/lib/generators/form-section-extension-compiler.js +568 -0
  195. package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
  196. package/dist/lib/generators/form-section-extension-source.js +245 -0
  197. package/dist/lib/generators/form-section-extension-source.js.map +7 -0
  198. package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
  199. package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
  200. package/dist/lib/generators/form-sections.js +773 -0
  201. package/dist/lib/generators/form-sections.js.map +7 -0
  202. package/dist/lib/generators/index.js +2 -0
  203. package/dist/lib/generators/index.js.map +2 -2
  204. package/dist/lib/generators/module-entities.js +21 -2
  205. package/dist/lib/generators/module-entities.js.map +2 -2
  206. package/dist/lib/generators/module-extension-facts.js +2 -1
  207. package/dist/lib/generators/module-extension-facts.js.map +2 -2
  208. package/dist/lib/generators/module-facts.js +30 -1
  209. package/dist/lib/generators/module-facts.js.map +2 -2
  210. package/dist/lib/generators/module-override-targets.js +24 -2
  211. package/dist/lib/generators/module-override-targets.js.map +2 -2
  212. package/dist/lib/generators/module-registry.js +223 -194
  213. package/dist/lib/generators/module-registry.js.map +3 -3
  214. package/dist/lib/generators/openapi.js +51 -18
  215. package/dist/lib/generators/openapi.js.map +2 -2
  216. package/dist/lib/generators/web-research-adapters.js +54 -22
  217. package/dist/lib/generators/web-research-adapters.js.map +2 -2
  218. package/dist/lib/in-process-generate-watcher.js +98 -75
  219. package/dist/lib/in-process-generate-watcher.js.map +2 -2
  220. package/dist/lib/post-generate-invalidation.js +20 -1
  221. package/dist/lib/post-generate-invalidation.js.map +2 -2
  222. package/dist/lib/resolver.js +195 -1
  223. package/dist/lib/resolver.js.map +3 -3
  224. package/dist/lib/single-instance-strategy-guard.js +26 -3
  225. package/dist/lib/single-instance-strategy-guard.js.map +2 -2
  226. package/dist/mercato.js +106 -50
  227. package/dist/mercato.js.map +2 -2
  228. package/jest.config.cjs +2 -0
  229. package/package.json +7 -7
  230. package/src/__tests__/mercato.test.ts +18 -0
  231. package/src/__tests__/rotation-json-output.test.ts +52 -0
  232. package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
  233. package/src/lib/__tests__/generate-child-process.test.ts +30 -0
  234. package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
  235. package/src/lib/__tests__/generate-watch-plan.test.ts +99 -0
  236. package/src/lib/__tests__/generate-watch-runner.test.ts +138 -0
  237. package/src/lib/__tests__/generate-watch-structure.test.ts +556 -1
  238. package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
  239. package/src/lib/__tests__/module-inspection.test.ts +17 -11
  240. package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
  241. package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
  242. package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
  243. package/src/lib/cache-provider-manifest.ts +8 -0
  244. package/src/lib/generate-child-process.ts +26 -3
  245. package/src/lib/generate-watch-events.ts +189 -17
  246. package/src/lib/generate-watch-plan.ts +180 -0
  247. package/src/lib/generate-watch-runner.ts +63 -0
  248. package/src/lib/generate-watch-structure.ts +670 -227
  249. package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
  250. package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
  251. package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
  252. package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
  253. package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
  254. package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
  255. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
  256. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
  257. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
  258. package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
  259. package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
  260. package/src/lib/generators/__tests__/openapi.test.ts +147 -10
  261. package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
  262. package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
  263. package/src/lib/generators/ast/writers.ts +6 -1
  264. package/src/lib/generators/cache-providers.ts +111 -0
  265. package/src/lib/generators/extension.ts +2 -0
  266. package/src/lib/generators/extensions/agent-files.ts +1 -0
  267. package/src/lib/generators/form-section-ast.ts +166 -0
  268. package/src/lib/generators/form-section-extension-compiler.ts +632 -0
  269. package/src/lib/generators/form-section-extension-source.ts +308 -0
  270. package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
  271. package/src/lib/generators/form-sections.ts +896 -0
  272. package/src/lib/generators/index.ts +1 -0
  273. package/src/lib/generators/module-entities.ts +22 -4
  274. package/src/lib/generators/module-extension-facts.ts +1 -0
  275. package/src/lib/generators/module-facts.ts +40 -0
  276. package/src/lib/generators/module-override-targets.ts +19 -0
  277. package/src/lib/generators/module-registry.ts +246 -202
  278. package/src/lib/generators/openapi.ts +65 -20
  279. package/src/lib/generators/web-research-adapters.ts +76 -21
  280. package/src/lib/in-process-generate-watcher.ts +151 -96
  281. package/src/lib/post-generate-invalidation.ts +28 -1
  282. package/src/lib/resolver.ts +218 -0
  283. package/src/lib/single-instance-strategy-guard.ts +51 -1
  284. package/src/mercato.ts +117 -57
  285. package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
@@ -1,6 +1,7 @@
1
1
  import crypto from "node:crypto";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
+ import ts from "typescript-js";
4
5
  import {
5
6
  MODULE_CODE_EXTENSIONS,
6
7
  SCAN_CONFIGS,
@@ -8,241 +9,615 @@ import {
8
9
  scanModuleDir,
9
10
  stripModuleCodeExtension
10
11
  } from "./generators/scanner.js";
11
- const STRUCTURAL_CONVENTION_FILES = [
12
- "index.ts",
13
- "cli.ts",
14
- "di.ts",
15
- "acl.ts",
16
- "setup.ts",
17
- "runtime.ts",
18
- "encryption.ts",
19
- "ce.ts",
20
- "search.ts",
21
- "events.ts",
22
- "notifications.ts",
23
- "notifications.client.ts",
24
- "notifications.handlers.ts",
25
- "translations.ts",
26
- "generators.ts",
27
- "ai-tools.ts",
28
- "ai-agents.ts",
29
- "analytics.ts",
30
- "workflows.ts",
31
- "inbox-actions.ts",
32
- "message-types.ts",
33
- "message-objects.ts",
34
- "integration.ts",
35
- "security.mfa-providers.ts",
36
- "security.sudo.ts",
37
- "data/entities.ts",
38
- "data/extensions.ts",
39
- "data/fields.ts",
40
- "data/enrichers.ts",
41
- "data/guards.ts",
42
- "api/interceptors.ts",
43
- "commands/interceptors.ts",
44
- "widgets/components.ts",
45
- "widgets/injection-table.ts",
46
- "frontend/middleware.ts",
47
- "backend/middleware.ts"
48
- ];
49
- const CONTENT_SENSITIVE_SCAN_CONFIGS = [
50
- SCAN_CONFIGS.apiRoutes,
51
- SCAN_CONFIGS.apiPlainFiles,
52
- SCAN_CONFIGS.subscribers,
53
- SCAN_CONFIGS.workers,
54
- SCAN_CONFIGS.dashboardWidgets,
55
- SCAN_CONFIGS.injectionWidgets
56
- ];
57
- const ROUTE_SHAPE_SCAN_CONFIGS = [
58
- SCAN_CONFIGS.frontendPages,
59
- SCAN_CONFIGS.backendPages
12
+ const cacheStates = /* @__PURE__ */ new WeakMap();
13
+ function createGenerateWatchStructureCache() {
14
+ const cache = {};
15
+ cacheStates.set(cache, { files: /* @__PURE__ */ new Map() });
16
+ return cache;
17
+ }
18
+ const REGISTRY_CONVENTIONS = [
19
+ "index",
20
+ "acl",
21
+ "setup",
22
+ "runtime",
23
+ "encryption",
24
+ "ce",
25
+ "integration",
26
+ "vector",
27
+ "data/extensions",
28
+ "data/fields"
60
29
  ];
30
+ const EXTENSION_CONVENTIONS = {
31
+ notifications: "registry.notifications",
32
+ "notifications.client": "registry.notifications",
33
+ "notifications.handlers": "registry.notifications",
34
+ "message-types": "registry.messages",
35
+ "message-objects": "registry.messages",
36
+ "ai-tools": "registry.ai-tools",
37
+ "ai-agents": "registry.ai-agents",
38
+ analytics: "registry.analytics",
39
+ translations: "registry.translatable-fields",
40
+ workflows: "registry.workflows",
41
+ "inbox-actions": "registry.inbox-actions",
42
+ "data/enrichers": "registry.enrichers",
43
+ "data/guards": "registry.guards",
44
+ "api/interceptors": "registry.interceptors",
45
+ "commands/interceptors": "registry.command-interceptors",
46
+ "widgets/components": "registry.component-overrides",
47
+ "frontend/middleware": "registry.page-middleware",
48
+ "backend/middleware": "registry.page-middleware"
49
+ };
50
+ const COMMAND_SCAN_CONFIG = {
51
+ folder: "commands",
52
+ include: (name) => MODULE_CODE_EXTENSIONS.some((extension) => name.endsWith(extension)) && !name.endsWith(".d.ts") && !/\.(test|spec)\.[jt]sx?$/.test(name) && !["index", "shared", "factory"].includes(stripModuleCodeExtension(name))
53
+ };
54
+ const LEGACY_API_SCAN_CONFIGS = ["get", "post", "put", "patch", "delete"].map((method) => ({
55
+ folder: `api/${method}`,
56
+ include: (name) => /\.[jt]s$/.test(name) && !/\.(test|spec)\.[jt]s$/.test(name)
57
+ }));
61
58
  function checksum(value) {
62
59
  return crypto.createHash("md5").update(value).digest("hex");
63
60
  }
64
- function moduleRootIdentity(roots) {
65
- return JSON.stringify([
66
- roots.pkgBase.replace(/\\/g, "/"),
67
- roots.appBase.replace(/\\/g, "/")
68
- ]);
61
+ function isMissing(error) {
62
+ return typeof error === "object" && error !== null && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
69
63
  }
70
- function fileRecord(filePath, base, mode) {
71
- if (!fs.existsSync(filePath)) return null;
72
- let stat;
73
- try {
74
- stat = fs.statSync(filePath);
75
- } catch {
76
- return null;
77
- }
78
- if (!stat.isFile()) return null;
79
- const rel = path.relative(base, filePath).replace(/\\/g, "/");
80
- if (mode === "shape") {
81
- return `file:${rel}`;
64
+ function unwrap(node) {
65
+ while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node)) node = node.expression;
66
+ return node;
67
+ }
68
+ function pluginConventions(file) {
69
+ const declarations = /* @__PURE__ */ new Map();
70
+ let exported;
71
+ for (const statement of file.statements) {
72
+ if (ts.isVariableStatement(statement)) {
73
+ for (const declaration of statement.declarationList.declarations) {
74
+ if (ts.isIdentifier(declaration.name) && declaration.initializer) {
75
+ declarations.set(declaration.name.text, declaration.initializer);
76
+ if (declaration.name.text === "generatorPlugins" && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
77
+ exported = declaration.initializer;
78
+ }
79
+ }
80
+ }
81
+ } else if (ts.isExportAssignment(statement)) {
82
+ exported ??= statement.expression;
83
+ } else if (ts.isImportDeclaration(statement)) {
84
+ if (!statement.importClause?.isTypeOnly) return null;
85
+ } else if (!ts.isFunctionDeclaration(statement) && !ts.isInterfaceDeclaration(statement) && !ts.isTypeAliasDeclaration(statement) && !ts.isEmptyStatement(statement)) return null;
82
86
  }
83
- try {
84
- return `file:${rel}:${stat.size}:${checksum(fs.readFileSync(filePath, "utf8"))}`;
85
- } catch {
86
- return `file:${rel}:unreadable`;
87
+ if (!exported) return null;
88
+ const resolve = (expression, seen = /* @__PURE__ */ new Set()) => {
89
+ const node = unwrap(expression);
90
+ if (!ts.isIdentifier(node)) return node;
91
+ if (seen.has(node.text)) return null;
92
+ seen.add(node.text);
93
+ const value = declarations.get(node.text);
94
+ return value ? resolve(value, seen) : null;
95
+ };
96
+ const plugins = resolve(exported);
97
+ if (!plugins || !ts.isArrayLiteralExpression(plugins)) return null;
98
+ const conventions = [];
99
+ for (const element of plugins.elements) {
100
+ const plugin = resolve(element);
101
+ if (!plugin || !ts.isObjectLiteralExpression(plugin)) return null;
102
+ let convention;
103
+ for (const property of plugin.properties) {
104
+ if (ts.isSpreadAssignment(property) || ts.isComputedPropertyName(property.name)) return null;
105
+ if (property.name.getText(file).replace(/^['"]|['"]$/g, "") !== "conventionFile") continue;
106
+ const value = ts.isPropertyAssignment(property) ? resolve(property.initializer) : null;
107
+ if (!value || !ts.isStringLiteralLike(value)) return null;
108
+ convention = value.text;
109
+ }
110
+ if (!convention) return null;
111
+ conventions.push(convention);
87
112
  }
113
+ return conventions;
88
114
  }
89
- function addFileRecord(records, prefix, filePath, base, mode) {
90
- const record = fileRecord(filePath, base, mode);
91
- if (record) records.push(`${prefix}:${record}`);
115
+ function pageFingerprint(parsed) {
116
+ const metadata = parsed.statements.some((statement) => {
117
+ if (ts.isExportDeclaration(statement)) {
118
+ return !statement.exportClause || ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => element.name.text === "metadata");
119
+ }
120
+ if (!ts.canHaveModifiers(statement) || !ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) return false;
121
+ if (ts.isVariableStatement(statement)) {
122
+ return statement.declarationList.declarations.some((declaration) => /\bmetadata\b/.test(declaration.name.getText(parsed)));
123
+ }
124
+ return (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name?.text === "metadata";
125
+ });
126
+ if (metadata) return null;
127
+ const hasDefault = parsed.statements.some(
128
+ (statement) => ts.isExportAssignment(statement) && !statement.isExportEquals || ts.canHaveModifiers(statement) && ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) || ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => element.name.text === "default")
129
+ );
130
+ return `page:default:${hasDefault}`;
92
131
  }
93
- function resolveCodeFile(base, relativePath) {
94
- const stripped = stripModuleCodeExtension(relativePath);
95
- const candidates = MODULE_CODE_EXTENSIONS.map((extension) => `${stripped}${extension}`);
96
- for (const candidate of candidates) {
97
- const filePath = path.join(base, ...candidate.split("/"));
98
- if (fs.existsSync(filePath)) return filePath;
99
- }
100
- return null;
132
+ const SUPERVISOR_OVERRIDE_CALLS = ["applyWorkerOverrides", "applyCliOverrides"];
133
+ function declaresSupervisorOverride(parsed) {
134
+ const direct = /* @__PURE__ */ new Set();
135
+ const namespaces = /* @__PURE__ */ new Set();
136
+ for (const statement of parsed.statements) {
137
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.moduleSpecifier.text !== "@open-mercato/shared/modules/overrides") continue;
138
+ const bindings = statement.importClause?.namedBindings;
139
+ if (bindings && ts.isNamespaceImport(bindings)) namespaces.add(bindings.name.text);
140
+ if (bindings && ts.isNamedImports(bindings)) {
141
+ for (const element of bindings.elements) {
142
+ if (SUPERVISOR_OVERRIDE_CALLS.includes(element.propertyName?.text ?? element.name.text)) direct.add(element.name.text);
143
+ }
144
+ }
145
+ }
146
+ let found = false;
147
+ const visit = (node) => {
148
+ if (ts.isCallExpression(node)) {
149
+ const expression = node.expression;
150
+ if (ts.isIdentifier(expression) && direct.has(expression.text)) found = true;
151
+ if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression) && namespaces.has(expression.expression.text) && SUPERVISOR_OVERRIDE_CALLS.includes(expression.name.text)) found = true;
152
+ }
153
+ if (!found) ts.forEachChild(node, visit);
154
+ };
155
+ visit(parsed);
156
+ return found;
101
157
  }
102
- function resolveRuntimeCounterpart(pkgBase, sourceBase, sourceFile) {
103
- if (sourceBase === pkgBase) return null;
104
- const relativePath = path.relative(sourceBase, sourceFile).replace(/\\/g, "/");
105
- return resolveCodeFile(pkgBase, relativePath);
158
+ function staticImports(parsed) {
159
+ const specifiers = [];
160
+ let uncertain = false;
161
+ const visit = (node) => {
162
+ if (ts.isFunctionLike(node)) return;
163
+ if (ts.isImportDeclaration(node)) {
164
+ if (node.importClause?.isTypeOnly) return;
165
+ const bindings = node.importClause?.namedBindings;
166
+ if (!node.importClause?.name && bindings && ts.isNamedImports(bindings) && bindings.elements.length > 0 && bindings.elements.every((element) => element.isTypeOnly)) return;
167
+ if (ts.isStringLiteralLike(node.moduleSpecifier)) specifiers.push(node.moduleSpecifier.text);
168
+ return;
169
+ }
170
+ if (ts.isExportDeclaration(node) && !node.isTypeOnly && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) specifiers.push(node.moduleSpecifier.text);
171
+ if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword || ts.isIdentifier(node.expression) && node.expression.text === "require")) {
172
+ const argument = node.arguments[0];
173
+ if (argument && ts.isStringLiteralLike(argument)) specifiers.push(argument.text);
174
+ else uncertain = true;
175
+ }
176
+ ts.forEachChild(node, visit);
177
+ };
178
+ visit(parsed);
179
+ return { specifiers, uncertain };
106
180
  }
107
- function hasInlinePageMetadata(filePath) {
108
- try {
109
- const source = fs.readFileSync(filePath, "utf8");
110
- return /\bexport\s+(?:const|let|var|function|class)\s+metadata\b/.test(source) || /\bexport\s+\{[^}]*\bmetadata\b[^}]*\}/.test(source);
111
- } catch {
112
- return false;
181
+ class SnapshotCollector {
182
+ constructor(cache) {
183
+ this.cache = cache;
184
+ this.records = /* @__PURE__ */ new Map();
185
+ this.fullReasons = /* @__PURE__ */ new Set();
186
+ this.stats = /* @__PURE__ */ new Map();
187
+ this.identities = /* @__PURE__ */ new Map();
188
+ this.uncertainDependencies = /* @__PURE__ */ new Set();
189
+ this.uncertainPluginDescriptors = /* @__PURE__ */ new Set();
190
+ this.dependencySeeds = /* @__PURE__ */ new Map();
191
+ this.inspectedCachePaths = /* @__PURE__ */ new Set();
192
+ this.sources = /* @__PURE__ */ new Map();
193
+ this.parsedFiles = /* @__PURE__ */ new Map();
113
194
  }
114
- }
115
- function addConventionRecords(records, roots) {
116
- const packageSourceBase = resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase;
117
- for (const base of [roots.pkgBase, roots.appBase]) {
118
- records.push(`module-root:${base}:${fs.existsSync(base) ? "present" : "missing"}`);
119
- }
120
- if (packageSourceBase !== roots.pkgBase) {
121
- records.push(
122
- `module-root:${packageSourceBase}:${fs.existsSync(packageSourceBase) ? "present" : "missing"}`
123
- );
195
+ identity(file) {
196
+ if (!this.identities.has(file)) this.stat(file);
197
+ return this.identities.get(file) ?? null;
124
198
  }
125
- for (const relativePath of STRUCTURAL_CONVENTION_FILES) {
126
- const appFile = resolveCodeFile(roots.appBase, relativePath);
127
- if (appFile) {
128
- addFileRecord(records, "convention:app", appFile, roots.appBase, "content");
129
- continue;
130
- }
131
- const sourceFile = resolveCodeFile(packageSourceBase, relativePath);
132
- if (!sourceFile) {
133
- const runtimeFile2 = packageSourceBase === roots.pkgBase ? null : resolveCodeFile(roots.pkgBase, relativePath);
134
- if (runtimeFile2) {
135
- addFileRecord(records, "convention:package-runtime", runtimeFile2, roots.pkgBase, "content");
136
- } else {
137
- records.push(`convention:missing:${relativePath}`);
138
- }
139
- continue;
199
+ seedDependency(file, kind) {
200
+ const identity = `${kind.category}:${kind.extensionId ?? ""}`;
201
+ const kinds = this.dependencySeeds.get(file) ?? /* @__PURE__ */ new Map();
202
+ kinds.set(identity, kind);
203
+ this.dependencySeeds.set(file, kinds);
204
+ }
205
+ stat(file) {
206
+ if (this.stats.has(file)) return this.stats.get(file) ?? null;
207
+ try {
208
+ const stat = fs.statSync(file);
209
+ const identity = [stat.dev, stat.ino, stat.size, stat.mtimeMs, stat.ctimeMs].join(":");
210
+ this.stats.set(file, stat);
211
+ this.identities.set(file, identity);
212
+ return stat;
213
+ } catch (error) {
214
+ if (!isMissing(error)) this.fullReasons.add(`Cannot inspect generator input: ${file}`);
215
+ this.stats.set(file, null);
216
+ this.identities.set(file, null);
217
+ return null;
140
218
  }
141
- const packagePrefix = packageSourceBase === roots.pkgBase ? "package" : "package-source";
142
- addFileRecord(records, `convention:${packagePrefix}`, sourceFile, packageSourceBase, "content");
143
- const runtimeFile = resolveRuntimeCounterpart(roots.pkgBase, packageSourceBase, sourceFile);
144
- if (runtimeFile) {
145
- addFileRecord(records, "convention:package-runtime", runtimeFile, roots.pkgBase, "content");
146
- } else if (packageSourceBase !== roots.pkgBase) {
147
- records.push(`convention:package-runtime:missing:${relativePath}`);
219
+ }
220
+ /** Stat-keyed cache entry for a readable file; unchanged identities are never re-read. */
221
+ entry(file) {
222
+ const stat = this.stat(file);
223
+ const identity = this.identity(file);
224
+ if (!stat?.isFile() || !identity) {
225
+ this.fullReasons.add(`Cannot read generator input: ${file}`);
226
+ return null;
148
227
  }
228
+ this.inspectedCachePaths.add(file);
229
+ const cached = this.cache.files.get(file);
230
+ if (cached?.identity === identity) return cached;
231
+ const source = this.readSource(file);
232
+ if (source === null) return null;
233
+ const entry = { identity, fingerprint: checksum(source) };
234
+ this.cache.files.set(file, entry);
235
+ return entry;
149
236
  }
150
- }
151
- function addScannedRecords(records, roots) {
152
- const packageSourceBase = resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase;
153
- for (const config of CONTENT_SENSITIVE_SCAN_CONFIGS) {
154
- for (const scanned of scanModuleDir(roots, config)) {
155
- const base = scanned.fromApp ? roots.appBase : packageSourceBase;
156
- const filePath = path.join(base, ...config.folder.split("/"), ...scanned.relPath.split("/"));
157
- let sourceOrigin = "app";
158
- if (!scanned.fromApp) {
159
- sourceOrigin = packageSourceBase === roots.pkgBase ? "package" : "package-source";
237
+ readSource(file) {
238
+ const known = this.sources.get(file);
239
+ if (known !== void 0) return known;
240
+ try {
241
+ const source = fs.readFileSync(file, "utf8");
242
+ this.sources.set(file, source);
243
+ return source;
244
+ } catch {
245
+ this.fullReasons.add(`Cannot read generator input: ${file}`);
246
+ return null;
247
+ }
248
+ }
249
+ /** Capture-local AST for a file whose cached facts are missing; parse failures are cached per identity. */
250
+ parsed(file, entry) {
251
+ if (entry.parseFailed) {
252
+ this.fullReasons.add(`Cannot parse generator input: ${file}`);
253
+ return null;
254
+ }
255
+ const known = this.parsedFiles.get(file);
256
+ if (known) return known;
257
+ const source = this.readSource(file);
258
+ if (source === null) return null;
259
+ let parsed;
260
+ try {
261
+ parsed = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true);
262
+ } catch {
263
+ this.fullReasons.add(`Cannot parse generator input: ${file}`);
264
+ return null;
265
+ }
266
+ const diagnostics = parsed.parseDiagnostics;
267
+ if (diagnostics?.length) {
268
+ entry.parseFailed = true;
269
+ this.fullReasons.add(`Cannot parse generator input: ${file}`);
270
+ return null;
271
+ }
272
+ this.parsedFiles.set(file, parsed);
273
+ return parsed;
274
+ }
275
+ record(key, file, kind, fingerprint) {
276
+ this.records.set(key, { key, path: file, ...kind, fingerprint });
277
+ }
278
+ file(key, file, kind, mode = "content") {
279
+ if (!this.stat(file)?.isFile()) return;
280
+ if (mode === "membership") {
281
+ this.record(key, file, kind, "present");
282
+ return;
283
+ }
284
+ if (mode === "stat") {
285
+ this.record(key, file, kind, this.identity(file) ?? "present");
286
+ return;
287
+ }
288
+ const entry = this.entry(file);
289
+ if (!entry) {
290
+ this.record(key, file, kind, "unreadable");
291
+ return;
292
+ }
293
+ if (mode === "page") {
294
+ if (entry.pageFingerprint === void 0) {
295
+ const parsed = this.parsed(file, entry);
296
+ if (!parsed) {
297
+ this.record(key, file, kind, "unparseable");
298
+ return;
299
+ }
300
+ entry.pageFingerprint = pageFingerprint(parsed);
160
301
  }
161
- addFileRecord(records, `${config.folder}:${sourceOrigin}`, filePath, base, "content");
162
- if (!scanned.fromApp && packageSourceBase !== roots.pkgBase) {
163
- const runtimeFile = resolveRuntimeCounterpart(roots.pkgBase, packageSourceBase, filePath);
164
- if (runtimeFile) {
165
- addFileRecord(
166
- records,
167
- `${config.folder}:package-runtime`,
168
- runtimeFile,
169
- roots.pkgBase,
170
- "content"
171
- );
172
- } else {
173
- records.push(`${config.folder}:package-runtime:missing:${scanned.relPath}`);
302
+ if (entry.pageFingerprint !== null) {
303
+ this.record(key, file, kind, entry.pageFingerprint);
304
+ return;
305
+ }
306
+ }
307
+ this.record(key, file, kind, entry.fingerprint);
308
+ if (/\.[cm]?[jt]sx?$/.test(file)) this.seedDependency(file, kind);
309
+ }
310
+ codeFile(base, relativePath) {
311
+ const stripped = stripModuleCodeExtension(relativePath);
312
+ const candidates = [relativePath, ...MODULE_CODE_EXTENSIONS.map((extension) => `${stripped}${extension}`)];
313
+ for (const candidate of candidates) {
314
+ const file = path.join(base, candidate);
315
+ if (this.stat(file)?.isFile()) return file;
316
+ }
317
+ return null;
318
+ }
319
+ scan(roots, config) {
320
+ try {
321
+ return scanModuleDir(roots, config);
322
+ } catch {
323
+ this.fullReasons.add(`Cannot scan generator inputs: ${roots.appBase}, ${roots.pkgBase}/${config.folder}`);
324
+ return [];
325
+ }
326
+ }
327
+ entries(directory) {
328
+ if (!this.stat(directory)?.isDirectory()) return [];
329
+ try {
330
+ return fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
331
+ } catch {
332
+ this.fullReasons.add(`Cannot scan generator inputs: ${directory}`);
333
+ return [];
334
+ }
335
+ }
336
+ pair(identity, roots, relativePath, kind, mode = "content") {
337
+ const sourceBase = resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase;
338
+ const app = this.codeFile(roots.appBase, relativePath);
339
+ const source = app ?? this.codeFile(sourceBase, relativePath);
340
+ const runtime = !app && sourceBase !== roots.pkgBase ? this.codeFile(roots.pkgBase, stripModuleCodeExtension(relativePath)) : source;
341
+ const primary = source ?? runtime;
342
+ if (!primary) return [];
343
+ const logical = stripModuleCodeExtension(relativePath).replace(/\\/g, "/");
344
+ const key = `${identity}:${kind.category}:${kind.extensionId ?? ""}:${logical}`;
345
+ if (source) this.file(`${key}:source`, source, kind, mode);
346
+ if (runtime && runtime !== source) this.file(`${key}:runtime`, runtime, kind, mode);
347
+ this.record(`${key}:authority`, primary, kind, JSON.stringify([source, runtime]));
348
+ return source && runtime && runtime !== source ? [source, runtime] : [primary];
349
+ }
350
+ tree(identity, directory, kind, skipTests = true) {
351
+ for (const entry of this.entries(directory)) {
352
+ if (skipTests && (entry.name === "__tests__" || entry.name === "__mocks__")) continue;
353
+ const file = path.join(directory, entry.name);
354
+ if (entry.isDirectory()) this.tree(identity, file, kind, skipTests);
355
+ else if (entry.isFile()) this.file(`${identity}:${file}`, file, kind);
356
+ }
357
+ }
358
+ supervisor(appSource) {
359
+ const pending = [appSource];
360
+ let found = false;
361
+ while (pending.length > 0 && !found) {
362
+ const directory = pending.pop();
363
+ for (const entry of this.entries(directory)) {
364
+ const file = path.join(directory, entry.name);
365
+ if (entry.isDirectory()) {
366
+ if (entry.name !== "__tests__" && entry.name !== "node_modules") pending.push(file);
367
+ continue;
368
+ }
369
+ if (!/\.[cm]?tsx?$/.test(entry.name) || /(?:^|\.)test\.[cm]?tsx?$/.test(entry.name)) continue;
370
+ const cached = this.entry(file);
371
+ if (!cached) continue;
372
+ if (cached.supervisorOverride === void 0) {
373
+ if (!this.readSource(file)?.includes("@open-mercato/shared/modules/overrides")) {
374
+ cached.supervisorOverride = false;
375
+ continue;
376
+ }
377
+ const parsed = this.parsed(file, cached);
378
+ if (!parsed) continue;
379
+ cached.supervisorOverride = declaresSupervisorOverride(parsed);
380
+ }
381
+ if (cached.supervisorOverride) {
382
+ found = true;
383
+ break;
174
384
  }
175
385
  }
176
386
  }
387
+ this.record("supervisor-overrides", appSource, { category: "registry-convention", extensionId: "supervisor" }, String(found));
177
388
  }
178
- for (const config of ROUTE_SHAPE_SCAN_CONFIGS) {
179
- for (const scanned of scanModuleDir(roots, config)) {
180
- const base = scanned.fromApp ? roots.appBase : packageSourceBase;
181
- const folderPath = path.join(base, ...config.folder.split("/"));
182
- const filePath = path.join(folderPath, ...scanned.relPath.split("/"));
183
- let sourceOrigin = "app";
184
- if (!scanned.fromApp) {
185
- sourceOrigin = packageSourceBase === roots.pkgBase ? "package" : "package-source";
389
+ dependencies(appSource) {
390
+ const visited = /* @__PURE__ */ new Set();
391
+ const pending = [...this.dependencySeeds].flatMap(([file, kinds]) => [...kinds.entries()].map(([identity, kind]) => ({ file, identity, kind }))).sort((left, right) => right.file.localeCompare(left.file) || right.identity.localeCompare(left.identity));
392
+ while (pending.length > 0) {
393
+ const { file, identity, kind } = pending.pop();
394
+ const visitKey = `${identity}:${file}`;
395
+ if (visited.has(visitKey)) continue;
396
+ visited.add(visitKey);
397
+ const cached = this.entry(file);
398
+ if (!cached) continue;
399
+ if (!cached.imports) {
400
+ const parsed = this.parsed(file, cached);
401
+ if (!parsed) continue;
402
+ cached.imports = staticImports(parsed);
186
403
  }
187
- addFileRecord(
188
- records,
189
- `${config.folder}:${sourceOrigin}`,
190
- filePath,
191
- base,
192
- hasInlinePageMetadata(filePath) ? "content" : "shape"
193
- );
194
- let runtimeFile = null;
195
- if (!scanned.fromApp && packageSourceBase !== roots.pkgBase) {
196
- runtimeFile = resolveRuntimeCounterpart(roots.pkgBase, packageSourceBase, filePath);
197
- if (runtimeFile) {
198
- addFileRecord(
199
- records,
200
- `${config.folder}:package-runtime`,
201
- runtimeFile,
202
- roots.pkgBase,
203
- hasInlinePageMetadata(runtimeFile) ? "content" : "shape"
204
- );
205
- } else {
206
- records.push(`${config.folder}:package-runtime:missing:${scanned.relPath}`);
404
+ if (cached.imports.uncertain) this.uncertainDependencies.add(file);
405
+ const imports = cached.imports.specifiers;
406
+ for (const specifier of imports) {
407
+ if (!specifier.startsWith(".") && !specifier.startsWith("@/")) continue;
408
+ const target = specifier.startsWith("@/") ? path.join(appSource, specifier.slice(2)) : path.resolve(path.dirname(file), specifier);
409
+ const resolved = this.codeFile(path.dirname(target), path.basename(target)) ?? this.codeFile(target, "index");
410
+ const dependencyKey = `dependency:${identity}:${file}:${target}`;
411
+ if (!resolved) {
412
+ this.record(dependencyKey, target, kind, "missing");
413
+ continue;
207
414
  }
415
+ if (resolved.includes(`${path.sep}.mercato${path.sep}`) || resolved.includes(`${path.sep}generated${path.sep}`)) continue;
416
+ const fingerprint = this.entry(resolved)?.fingerprint ?? "unreadable";
417
+ this.record(dependencyKey, resolved, kind, `${resolved}:${fingerprint}`);
418
+ if (/\.[cm]?[jt]sx?$/.test(resolved)) pending.push({ file: resolved, identity, kind });
208
419
  }
209
- const stem = stripModuleCodeExtension(path.basename(filePath));
210
- const metaCandidates = stem === "page" ? ["page.meta", "meta"] : [`${stem}.meta`, "meta"];
211
- for (const candidate of metaCandidates) {
212
- const metaPath = resolveCodeFile(path.dirname(filePath), candidate);
213
- if (!metaPath) continue;
214
- addFileRecord(records, `${config.folder}:meta:${sourceOrigin}`, metaPath, base, "content");
420
+ }
421
+ }
422
+ }
423
+ function addModule(collector, roots, index, plugins) {
424
+ const distMarker = `${path.sep}dist${path.sep}modules${path.sep}`;
425
+ const distIndex = roots.pkgBase.lastIndexOf(distMarker);
426
+ if (distIndex >= 0) {
427
+ const packageRoot = roots.pkgBase.slice(0, distIndex);
428
+ collector.stat(path.join(packageRoot, "src", "modules", roots.pkgBase.slice(distIndex + distMarker.length)));
429
+ }
430
+ const sourceBase = resolveStandaloneSourceMirrorBase(roots.pkgBase) ?? roots.pkgBase;
431
+ const identity = `module:${index}:${roots.moduleId ?? path.basename(roots.appBase)}:${roots.appBase}:${roots.pkgBase}`;
432
+ collector.record(`${identity}:roots`, roots.appBase, { category: "configuration" }, JSON.stringify([
433
+ Object.entries(roots).sort(([left], [right]) => left.localeCompare(right)),
434
+ sourceBase,
435
+ collector.stat(roots.appBase)?.isDirectory() ?? false,
436
+ collector.stat(roots.pkgBase)?.isDirectory() ?? false
437
+ ]));
438
+ const convention = (relativePath, kind) => collector.pair(identity, roots, `${relativePath}.ts`, kind);
439
+ for (const relativePath of REGISTRY_CONVENTIONS) convention(relativePath, { category: "registry-convention" });
440
+ convention("form-sections", { category: "configuration" });
441
+ for (const [relativePath, extensionId] of Object.entries(EXTENSION_CONVENTIONS)) {
442
+ convention(relativePath, { category: "extension", extensionId });
443
+ }
444
+ collector.pair(identity, roots, "widgets/payments/client.tsx", { category: "extension", extensionId: "registry.notifications" });
445
+ for (const category of ["cli", "di", "search", "events"]) convention(category, { category });
446
+ convention("widgets/injection-table", { category: "injection-widgets" });
447
+ for (const descriptor of convention("generators", { category: "generator-plugin" })) {
448
+ const cached = collector.entry(descriptor);
449
+ if (cached && cached.pluginConventions === void 0) {
450
+ const parsed = collector.parsed(descriptor, cached);
451
+ if (parsed) cached.pluginConventions = pluginConventions(parsed);
452
+ }
453
+ const discovered = cached?.pluginConventions ?? null;
454
+ if (discovered === null) collector.uncertainPluginDescriptors.add(descriptor);
455
+ else for (const file of discovered) plugins.add(file);
456
+ }
457
+ for (const base of /* @__PURE__ */ new Set([roots.appBase, roots.pkgBase, sourceBase])) {
458
+ for (const directory of ["data", "db"]) {
459
+ for (const stem of ["entities.override", "entities", "schema"]) {
460
+ for (const extension of MODULE_CODE_EXTENSIONS) {
461
+ const file = path.join(base, directory, `${stem}${extension}`);
462
+ collector.file(`${identity}:entities:${file}`, file, { category: "entities" });
463
+ }
464
+ }
465
+ }
466
+ }
467
+ if (distIndex >= 0) {
468
+ const packageRoot = roots.pkgBase.slice(0, distIndex);
469
+ const direct = path.join(packageRoot, "generated");
470
+ collector.record(
471
+ `${identity}:package-entities-direct-root`,
472
+ direct,
473
+ { category: "entities" },
474
+ collector.stat(direct)?.isDirectory() ? "directory" : "missing"
475
+ );
476
+ const generated = collector.stat(direct)?.isDirectory() ? direct : path.join(packageRoot, "dist", "generated");
477
+ collector.record(`${identity}:package-entities-root`, generated, { category: "entities" }, generated);
478
+ for (const extension of [".ts", ".js"]) {
479
+ const ids = path.join(generated, `entities.ids.generated${extension}`);
480
+ collector.file(`${identity}:package-entities:${ids}`, ids, { category: "entities" });
481
+ for (const entry of collector.entries(path.join(generated, "entities"))) {
482
+ if (!entry.isDirectory()) continue;
483
+ const fields = path.join(generated, "entities", entry.name, `index${extension}`);
484
+ collector.file(`${identity}:package-entities:${fields}`, fields, { category: "entities" });
215
485
  }
216
- if (runtimeFile) {
217
- for (const candidate of metaCandidates) {
218
- const runtimeMetaPath = resolveCodeFile(path.dirname(runtimeFile), candidate);
219
- if (!runtimeMetaPath) continue;
220
- addFileRecord(
221
- records,
222
- `${config.folder}:meta:package-runtime`,
223
- runtimeMetaPath,
224
- roots.pkgBase,
225
- "content"
226
- );
486
+ }
487
+ }
488
+ const scans = [
489
+ [SCAN_CONFIGS.apiRoutes, "api-route"],
490
+ [SCAN_CONFIGS.apiPlainFiles, "api-route"],
491
+ ...LEGACY_API_SCAN_CONFIGS.map((config) => [config, "api-route"]),
492
+ [COMMAND_SCAN_CONFIG, "commands"],
493
+ [SCAN_CONFIGS.subscribers, "subscribers"],
494
+ [SCAN_CONFIGS.workers, "workers"],
495
+ [SCAN_CONFIGS.dashboardWidgets, "dashboard-widgets"],
496
+ [SCAN_CONFIGS.injectionWidgets, "injection-widgets"],
497
+ [SCAN_CONFIGS.frontendPages, "frontend-page"],
498
+ [SCAN_CONFIGS.backendPages, "backend-page"]
499
+ ];
500
+ for (const [config, category] of scans) {
501
+ for (const scanned of collector.scan(roots, config)) {
502
+ const relativePath = `${config.folder}/${scanned.relPath}`;
503
+ if (EXTENSION_CONVENTIONS[stripModuleCodeExtension(relativePath)]) continue;
504
+ const page = category === "frontend-page" || category === "backend-page";
505
+ const files = collector.pair(identity, roots, relativePath, { category }, page ? "page" : "content");
506
+ if (!page) continue;
507
+ for (const file of files) {
508
+ const stem = stripModuleCodeExtension(path.basename(file));
509
+ for (const candidate of [stem === "page" ? "page.meta" : `${stem}.meta`, "meta"]) {
510
+ const metadata = collector.codeFile(path.dirname(file), candidate);
511
+ if (metadata) collector.file(`${identity}:${category}:metadata:${metadata}`, metadata, { category });
227
512
  }
228
513
  }
229
514
  }
230
515
  }
516
+ for (const base of /* @__PURE__ */ new Set([sourceBase, roots.appBase])) {
517
+ const directory = path.join(base, "i18n");
518
+ for (const entry of collector.entries(directory)) {
519
+ if (!entry.isFile() || !/^[a-zA-Z0-9][a-zA-Z0-9_-]*\.json$/.test(entry.name)) continue;
520
+ const file = path.join(directory, entry.name);
521
+ collector.file(`${identity}:i18n:${file}`, file, { category: "i18n" }, "membership");
522
+ if (base === sourceBase && sourceBase !== roots.pkgBase) {
523
+ const runtime = path.join(roots.pkgBase, "i18n", entry.name);
524
+ collector.file(`${identity}:i18n:runtime:${runtime}`, runtime, { category: "i18n" }, "membership");
525
+ }
526
+ }
527
+ collector.tree(`${identity}:agents`, path.join(base, "agents"), { category: "extension", extensionId: "registry.agent-files" });
528
+ }
529
+ }
530
+ function collectGenerateWatchStructureSnapshot(options, cache) {
531
+ const cacheState = cache ? cacheStates.get(cache) : { files: /* @__PURE__ */ new Map() };
532
+ if (!cacheState) throw new TypeError("Invalid generate watch structure cache");
533
+ const collector = new SnapshotCollector(cacheState);
534
+ for (const reason of options.webResearchAdapterFullReasons ?? []) collector.fullReasons.add(reason);
535
+ collector.file(`configuration:${options.modulesFile}`, options.modulesFile, { category: "configuration" });
536
+ const plugins = /* @__PURE__ */ new Set();
537
+ options.moduleRoots.forEach((roots, index) => addModule(collector, roots, index, plugins));
538
+ options.moduleRoots.forEach((roots, index) => {
539
+ const identity = `module:${index}:${roots.moduleId ?? path.basename(roots.appBase)}:${roots.appBase}:${roots.pkgBase}`;
540
+ for (const relativePath of plugins) collector.pair(identity, roots, relativePath, { category: "generator-plugin" });
541
+ });
542
+ const knownInputs = /* @__PURE__ */ new Map();
543
+ for (const record of collector.records.values()) {
544
+ if (record.category !== "configuration") knownInputs.set(record.path, record);
545
+ }
546
+ const ordered = (inputs) => [...new Set(inputs ?? [])].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
547
+ for (const input of ordered(options.additionalInputs)) {
548
+ if (knownInputs.has(input)) continue;
549
+ const stat = collector.stat(input);
550
+ if (stat?.isFile()) collector.file(`configuration:${input}`, input, { category: "configuration" });
551
+ else collector.record(`configuration:${input}`, input, { category: "configuration" }, stat?.isDirectory() ? "directory" : "missing");
552
+ }
553
+ const addSpecializedInputs = (inputs, kind, keyPrefix, mode = "content") => {
554
+ for (const input of ordered(inputs)) {
555
+ const stat = collector.stat(input);
556
+ if (stat?.isFile()) collector.file(`${keyPrefix}:${input}`, input, kind, mode);
557
+ else collector.record(`${keyPrefix}:${input}`, input, kind, stat?.isDirectory() ? "directory" : "missing");
558
+ }
559
+ };
560
+ addSpecializedInputs(options.openapiInputs, { category: "openapi" }, "openapi-input");
561
+ addSpecializedInputs(
562
+ options.webResearchAdapterInputs,
563
+ { category: "web-research-adapters" },
564
+ "web-research-adapter-input",
565
+ "stat"
566
+ );
567
+ addSpecializedInputs(options.cacheProviderInputs, { category: "cache-providers" }, "cache-provider-input", "membership");
568
+ collector.supervisor(path.dirname(options.modulesFile));
569
+ collector.dependencies(path.dirname(options.modulesFile));
570
+ if (collector.uncertainPluginDescriptors.size > 0 || collector.uncertainDependencies.size > 0) {
571
+ const category = collector.uncertainPluginDescriptors.size > 0 ? "generator-plugin" : "unknown";
572
+ for (const roots of options.moduleRoots) {
573
+ for (const base of /* @__PURE__ */ new Set([roots.appBase, roots.pkgBase, resolveStandaloneSourceMirrorBase(roots.pkgBase)])) {
574
+ if (base) collector.tree(`uncertain-dependencies:${base}`, base, { category }, false);
575
+ }
576
+ }
577
+ for (const descriptor of collector.uncertainPluginDescriptors) {
578
+ collector.record(`uncertain-plugin:${descriptor}`, descriptor, { category: "generator-plugin" }, "unresolved-conventions");
579
+ }
580
+ for (const dependency of collector.uncertainDependencies) {
581
+ collector.record(`uncertain-dependency:${dependency}`, dependency, { category: "unknown" }, "unresolved-import");
582
+ }
583
+ }
584
+ const records = new Map([...collector.records].sort(([left], [right]) => left.localeCompare(right)));
585
+ const fullReasons = [...collector.fullReasons].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
586
+ if (fullReasons.length === 0) {
587
+ for (const cachedPath of cacheState.files.keys()) {
588
+ if (!collector.inspectedCachePaths.has(cachedPath)) cacheState.files.delete(cachedPath);
589
+ }
590
+ }
591
+ return {
592
+ checksum: checksum(JSON.stringify([[...records.values()], fullReasons])),
593
+ records,
594
+ fullReasons
595
+ };
596
+ }
597
+ function diffGenerateWatchStructureSnapshots(previous, next) {
598
+ const changes = [];
599
+ for (const key of [.../* @__PURE__ */ new Set([...previous.records.keys(), ...next.records.keys()])].sort((left, right) => left < right ? -1 : left > right ? 1 : 0)) {
600
+ const before = previous.records.get(key);
601
+ const after = next.records.get(key);
602
+ if (before && after && before.fingerprint === after.fingerprint && before.path === after.path && before.category === after.category && before.extensionId === after.extensionId) continue;
603
+ const record = after ?? before;
604
+ changes.push({
605
+ key,
606
+ kind: !before ? "add" : !after ? "delete" : "change",
607
+ category: record.category,
608
+ path: record.path,
609
+ ...record.extensionId ? { extensionId: record.extensionId } : {}
610
+ });
611
+ }
612
+ return changes;
231
613
  }
232
614
  function calculateGenerateWatchStructureChecksum(options) {
233
- const records = [];
234
- const modulesRecord = fileRecord(options.modulesFile, path.dirname(options.modulesFile), "content");
235
- records.push(modulesRecord ?? `missing:${options.modulesFile}`);
236
- for (const roots of options.moduleRoots) {
237
- const moduleRecords = [];
238
- addConventionRecords(moduleRecords, roots);
239
- addScannedRecords(moduleRecords, roots);
240
- const rootIdentity = moduleRootIdentity(roots);
241
- records.push(...moduleRecords.map((record) => `${rootIdentity}:${record}`));
242
- }
243
- return checksum(records.sort((a, b) => a.localeCompare(b)).join("\n"));
615
+ return collectGenerateWatchStructureSnapshot(options).checksum;
244
616
  }
245
617
  export {
246
- calculateGenerateWatchStructureChecksum
618
+ calculateGenerateWatchStructureChecksum,
619
+ collectGenerateWatchStructureSnapshot,
620
+ createGenerateWatchStructureCache,
621
+ diffGenerateWatchStructureSnapshots
247
622
  };
248
623
  //# sourceMappingURL=generate-watch-structure.js.map