@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8593.1.50784dae35

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 (133) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/AGENTS.md +1 -0
  3. package/dist/agentic/guides/module-facts.json +164 -164
  4. package/dist/agentic/guides/module-facts.v2.json +164 -164
  5. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  6. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  8. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  9. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  10. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  11. package/dist/agentic/guides/modules/auth/index.md +1 -1
  12. package/dist/agentic/guides/modules/availability/index.md +1 -1
  13. package/dist/agentic/guides/modules/backups/index.md +1 -1
  14. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  15. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  16. package/dist/agentic/guides/modules/cart/index.md +1 -1
  17. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  25. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  26. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  27. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  28. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  29. package/dist/agentic/guides/modules/configs/index.md +1 -1
  30. package/dist/agentic/guides/modules/content/index.md +1 -1
  31. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  32. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  33. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  34. package/dist/agentic/guides/modules/customers/index.md +1 -1
  35. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  36. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  37. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  38. package/dist/agentic/guides/modules/devices/index.md +1 -1
  39. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  40. package/dist/agentic/guides/modules/directory/index.md +1 -1
  41. package/dist/agentic/guides/modules/documents/index.md +1 -1
  42. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  43. package/dist/agentic/guides/modules/entities/index.md +1 -1
  44. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  45. package/dist/agentic/guides/modules/events/index.md +1 -1
  46. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  47. package/dist/agentic/guides/modules/forms/index.md +1 -1
  48. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  49. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  50. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  51. package/dist/agentic/guides/modules/generators/index.md +1 -1
  52. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  53. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  54. package/dist/agentic/guides/modules/messages/index.md +1 -1
  55. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  56. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  57. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  58. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  59. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  60. package/dist/agentic/guides/modules/planner/index.md +1 -1
  61. package/dist/agentic/guides/modules/portal/index.md +1 -1
  62. package/dist/agentic/guides/modules/progress/index.md +1 -1
  63. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  64. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  65. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  66. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  67. package/dist/agentic/guides/modules/resources/index.md +1 -1
  68. package/dist/agentic/guides/modules/sales/index.md +1 -1
  69. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  70. package/dist/agentic/guides/modules/search/index.md +1 -1
  71. package/dist/agentic/guides/modules/security/index.md +1 -1
  72. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  73. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  74. package/dist/agentic/guides/modules/sso/index.md +1 -1
  75. package/dist/agentic/guides/modules/staff/index.md +1 -1
  76. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  77. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  78. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  79. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  80. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  81. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  82. package/dist/agentic/guides/modules/translations/index.md +1 -1
  83. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  84. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  85. package/dist/agentic/guides/modules/wms/index.md +1 -1
  86. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  87. package/dist/agentic/guides/reference-module-facts.json +1 -1
  88. package/dist/agentic/guides/upstream/manifest.json +1 -1
  89. package/dist/lib/generate-child-process.js +21 -3
  90. package/dist/lib/generate-child-process.js.map +2 -2
  91. package/dist/lib/generate-watch-events.js +135 -19
  92. package/dist/lib/generate-watch-events.js.map +2 -2
  93. package/dist/lib/generate-watch-plan.js +166 -0
  94. package/dist/lib/generate-watch-plan.js.map +7 -0
  95. package/dist/lib/generate-watch-runner.js +53 -0
  96. package/dist/lib/generate-watch-runner.js.map +7 -0
  97. package/dist/lib/generate-watch-structure.js +576 -203
  98. package/dist/lib/generate-watch-structure.js.map +3 -3
  99. package/dist/lib/generators/extensions/agent-files.js +1 -0
  100. package/dist/lib/generators/extensions/agent-files.js.map +2 -2
  101. package/dist/lib/generators/module-registry.js +148 -191
  102. package/dist/lib/generators/module-registry.js.map +3 -3
  103. package/dist/lib/generators/openapi.js +24 -1
  104. package/dist/lib/generators/openapi.js.map +2 -2
  105. package/dist/lib/generators/web-research-adapters.js +54 -22
  106. package/dist/lib/generators/web-research-adapters.js.map +2 -2
  107. package/dist/lib/in-process-generate-watcher.js +98 -75
  108. package/dist/lib/in-process-generate-watcher.js.map +2 -2
  109. package/dist/mercato.js +74 -46
  110. package/dist/mercato.js.map +2 -2
  111. package/package.json +7 -7
  112. package/src/lib/__tests__/generate-child-process.test.ts +30 -0
  113. package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
  114. package/src/lib/__tests__/generate-watch-plan.test.ts +98 -0
  115. package/src/lib/__tests__/generate-watch-runner.test.ts +126 -0
  116. package/src/lib/__tests__/generate-watch-structure.test.ts +522 -1
  117. package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
  118. package/src/lib/__tests__/module-inspection.test.ts +17 -11
  119. package/src/lib/generate-child-process.ts +26 -3
  120. package/src/lib/generate-watch-events.ts +189 -17
  121. package/src/lib/generate-watch-plan.ts +177 -0
  122. package/src/lib/generate-watch-runner.ts +62 -0
  123. package/src/lib/generate-watch-structure.ts +666 -227
  124. package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
  125. package/src/lib/generators/__tests__/openapi.test.ts +91 -1
  126. package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
  127. package/src/lib/generators/extension.ts +2 -0
  128. package/src/lib/generators/extensions/agent-files.ts +1 -0
  129. package/src/lib/generators/module-registry.ts +168 -200
  130. package/src/lib/generators/openapi.ts +34 -0
  131. package/src/lib/generators/web-research-adapters.ts +76 -21
  132. package/src/lib/in-process-generate-watcher.ts +151 -96
  133. package/src/mercato.ts +85 -53
package/src/mercato.ts CHANGED
@@ -36,7 +36,9 @@ import {
36
36
  startInProcessGenerateWatcher,
37
37
  type GenerateWatcherHandle,
38
38
  } from './lib/in-process-generate-watcher'
39
- import { runGenerateChildProcess } from './lib/generate-child-process'
39
+ import type { GenerateWatchPlan, GenerateWatchSnapshot } from './lib/generate-watch-plan'
40
+ import type { GenerateWatchModuleTarget } from './lib/generate-watch-events'
41
+ import { readGenerateWatchRequest, runGenerateChildProcess } from './lib/generate-child-process'
40
42
  import {
41
43
  resolveGenerateWatcherMode,
42
44
  type GenerateWatcherMode,
@@ -846,33 +848,15 @@ async function runPostGenerateStructuralInvalidation(quiet: boolean): Promise<vo
846
848
  }
847
849
  }
848
850
 
849
- /** Full one-shot suite; long-lived watchers invoke this in a disposable CLI process. */
850
- async function runGeneratorSuite(quiet: boolean): Promise<boolean> {
851
- const { createResolver } = await import('./lib/resolver')
852
- const {
853
- generateEntityIds,
854
- generateModuleRegistries,
855
- generateModuleEntities,
856
- generateModuleDi,
857
- generateModulePackageSources,
858
- generateOpenApi,
859
- generateWebResearchAdapters,
860
- } = await import('./lib/generators')
861
- const resolver = createResolver()
862
- const results = [
863
- await generateEntityIds({ resolver, quiet }),
864
- ...(await generateModuleRegistries({ resolver, quiet })),
865
- await generateModuleEntities({ resolver, quiet }),
866
- await generateModuleDi({ resolver, quiet }),
867
- await generateModulePackageSources({ resolver, quiet }),
868
- await generateWebResearchAdapters({ resolver, quiet }),
869
- await generateOpenApi({ resolver, quiet }),
870
- ]
871
- return results.some((result) => (result?.filesWritten.length ?? 0) > 0)
872
- }
873
851
 
874
- async function runGeneratorSuiteWithStructuralInvalidation(quiet: boolean): Promise<void> {
875
- const generatedFilesChanged = await runGeneratorSuite(quiet)
852
+ async function runGeneratorSuiteWithStructuralInvalidation(
853
+ quiet: boolean,
854
+ plan?: GenerateWatchPlan,
855
+ onOpenApiCascade?: (reason: string) => void,
856
+ ): Promise<void> {
857
+ // Keep the generator/compiler graph out of ordinary CLI and server bootstrap.
858
+ const { runGenerateWatchSuite } = await import('./lib/generate-watch-runner')
859
+ const generatedFilesChanged = await runGenerateWatchSuite(quiet, plan, undefined, onOpenApiCascade)
876
860
  if (!generatedFilesChanged) {
877
861
  if (!quiet) {
878
862
  console.log('[generate] Generated outputs unchanged; skipping structural invalidation.')
@@ -882,7 +866,7 @@ async function runGeneratorSuiteWithStructuralInvalidation(quiet: boolean): Prom
882
866
  await runPostGenerateStructuralInvalidation(quiet)
883
867
  }
884
868
 
885
- async function runWatchGeneratorSuite(): Promise<void> {
869
+ async function runWatchGeneratorSuite(plan: GenerateWatchPlan | undefined, logCascade: boolean): Promise<void> {
886
870
  // Keep resolver setup behind command dispatch; other CLI modes do not need it.
887
871
  const { resolveEnvironment } = await import('./lib/resolver')
888
872
  const { rootDir, appDir } = resolveEnvironment()
@@ -890,64 +874,104 @@ async function runWatchGeneratorSuite(): Promise<void> {
890
874
  mercatoBin: resolveInstalledBinary([rootDir, appDir], '@open-mercato/cli/bin/mercato'),
891
875
  cwd: process.cwd(),
892
876
  quiet: true,
877
+ watchRequest: { plan, logCascade },
893
878
  })
894
879
  }
895
880
 
896
- /**
897
- * Builds the event-gated structural fingerprint runtime used by generate
898
- * watchers. Filesystem events mark the tree dirty; the existing full content
899
- * checksum remains the final authority and the fallback when watching fails.
900
- */
881
+ /** Shared snapshot and event runtime for standalone and embedded watchers. */
901
882
  async function createGenerateWatchRuntime(quiet = false) {
883
+ // Compiler-backed discovery is only needed by the generation watcher.
902
884
  const [
903
885
  { createResolver },
904
- { calculateGenerateWatchStructureChecksum },
886
+ {
887
+ collectGenerateWatchStructureSnapshot,
888
+ createGenerateWatchStructureCache,
889
+ diffGenerateWatchStructureSnapshots,
890
+ },
891
+ { planGenerateWatchChanges },
905
892
  { createGenerateWatchChangeSignal, resolveGenerateWatchTargets },
906
893
  { resolveStandaloneSourceMirrorBase },
894
+ { getOpenApiWatchInputs },
895
+ { getWebResearchAdapterWatchInputs },
907
896
  ] = await Promise.all([
908
897
  import('./lib/resolver'),
909
898
  import('./lib/generate-watch-structure'),
899
+ import('./lib/generate-watch-plan'),
910
900
  import('./lib/generate-watch-events'),
911
901
  import('./lib/generators/scanner'),
902
+ import('./lib/generators/openapi'),
903
+ import('./lib/generators/web-research-adapters'),
912
904
  ])
913
905
 
906
+ let latestSnapshot: GenerateWatchSnapshot | undefined
907
+ const structureCache = createGenerateWatchStructureCache()
908
+
914
909
  const collectWatchState = () => {
915
910
  const resolver = createResolver()
916
- const moduleRoots: Array<{
917
- appBase: string
918
- pkgBase: string
919
- watchPackageBase: boolean
920
- }> = []
911
+ const moduleRoots: Array<GenerateWatchModuleTarget & { moduleId: string; from?: string }> = []
912
+ const additionalInputs = new Set<string>()
913
+ const outputDirectories = new Set<string>([resolver.getOutputDir()])
914
+ for (const directory of [resolver.getRootDir(), resolver.getAppDir()]) {
915
+ for (const fileName of ['package.json', 'tsconfig.json', 'tsconfig.base.json', 'yarn.lock', 'package-lock.json', 'pnpm-lock.yaml']) {
916
+ additionalInputs.add(path.join(directory, fileName))
917
+ }
918
+ }
919
+ const adapterInputs = getWebResearchAdapterWatchInputs(resolver)
920
+ const openapiInputs = getOpenApiWatchInputs(resolver)
921
921
  const watchAppPackageFallbacks = resolver.isMonorepo()
922
922
  for (const entry of resolver.loadEnabledModules()) {
923
+ if (watchAppPackageFallbacks) {
924
+ outputDirectories.add(resolver.getPackageOutputDir(entry.from ?? '@open-mercato/core'))
925
+ }
923
926
  const roots = resolver.getModulePaths(entry)
927
+ const watchPackageBase = entry.from !== '@app' || watchAppPackageFallbacks
928
+ // Monorepo modules generate from source; their compiled dist trees are build output.
929
+ const compiledBase = watchAppPackageFallbacks && !roots.pkgBase.includes(`${path.sep}dist${path.sep}`) ? [] : ['dist']
930
+ const additionalModuleBases = watchPackageBase
931
+ ? ['src', ...compiledBase].map((folder) => path.join(resolver.getPackageRoot(entry.from), folder, 'modules', entry.id))
932
+ : []
924
933
  moduleRoots.push({
925
934
  ...roots,
926
- watchPackageBase: entry.from !== '@app' || watchAppPackageFallbacks,
935
+ moduleId: entry.id,
936
+ from: entry.from,
937
+ watchPackageBase,
938
+ additionalModuleBases,
927
939
  })
928
940
  }
929
941
  return {
930
942
  modulesFile: resolver.getModulesConfigPath(),
931
943
  moduleRoots,
944
+ additionalInputs: [...additionalInputs],
945
+ openapiInputs,
946
+ webResearchAdapterInputs: adapterInputs.manifestPaths,
947
+ webResearchAdapterFullReasons: adapterInputs.fullReasons,
948
+ shallowDirectories: adapterInputs.directoryPaths,
949
+ appSourceDir: path.join(resolver.getAppDir(), 'src'),
950
+ outputDir: resolver.getOutputDir(),
951
+ outputDirectories: [...outputDirectories].sort((left, right) => left.localeCompare(right)),
932
952
  }
933
953
  }
934
954
 
935
955
  return {
936
- computeStructureChecksum: async () => {
937
- return calculateGenerateWatchStructureChecksum(collectWatchState())
956
+ computeStructureChecksum: () =>
957
+ collectGenerateWatchStructureSnapshot(collectWatchState(), structureCache).checksum,
958
+ incremental: {
959
+ capture: () => {
960
+ latestSnapshot = collectGenerateWatchStructureSnapshot(collectWatchState(), structureCache)
961
+ return latestSnapshot
962
+ },
963
+ plan: (previous: GenerateWatchSnapshot, next: GenerateWatchSnapshot) =>
964
+ planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(previous, next), next.fullReasons),
938
965
  },
939
966
  changeSignal: createGenerateWatchChangeSignal({
940
967
  onSkippedDirectory: quiet
941
968
  ? undefined
942
969
  : (directory) => console.log(`[generate:watch] Skipping missing watch directory: ${directory}`),
943
- getWatchTargets: () => {
944
- const state = collectWatchState()
945
- return resolveGenerateWatchTargets({
946
- modulesFile: state.modulesFile,
947
- moduleRoots: state.moduleRoots,
948
- resolveSourceMirrorBase: resolveStandaloneSourceMirrorBase,
949
- })
950
- },
970
+ getWatchTargets: () => resolveGenerateWatchTargets({
971
+ ...collectWatchState(),
972
+ snapshot: latestSnapshot,
973
+ resolveSourceMirrorBase: resolveStandaloneSourceMirrorBase,
974
+ }),
951
975
  }),
952
976
  }
953
977
  }
@@ -2062,7 +2086,11 @@ export async function run(argv = process.argv) {
2062
2086
  const quiet = args.includes('--quiet') || args.includes('-q')
2063
2087
 
2064
2088
  if (!quiet) console.log('Running all generators...')
2065
- await runGeneratorSuiteWithStructuralInvalidation(quiet)
2089
+ const watchRequest = readGenerateWatchRequest()
2090
+ await runGeneratorSuiteWithStructuralInvalidation(quiet, watchRequest?.plan,
2091
+ watchRequest?.logCascade
2092
+ ? (reason) => console.log(`[generate:watch] Cascading; groups=openapi; reason=${reason}`)
2093
+ : undefined)
2066
2094
  if (!quiet) console.log('All generators completed.')
2067
2095
  },
2068
2096
  },
@@ -2081,7 +2109,9 @@ export async function run(argv = process.argv) {
2081
2109
  skipInitial,
2082
2110
  quiet,
2083
2111
  ...generateWatchRuntime,
2084
- runGenerators: runWatchGeneratorSuite,
2112
+ runGenerators: async (_reason, plan) => {
2113
+ await runWatchGeneratorSuite(plan, !quiet)
2114
+ },
2085
2115
  })
2086
2116
 
2087
2117
  const shutdownSignals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM']
@@ -2564,7 +2594,9 @@ export async function run(argv = process.argv) {
2564
2594
  skipInitial: true,
2565
2595
  quiet: false,
2566
2596
  ...generateWatchRuntime,
2567
- runGenerators: runWatchGeneratorSuite,
2597
+ runGenerators: async (_reason, plan) => {
2598
+ await runWatchGeneratorSuite(plan, true)
2599
+ },
2568
2600
  })
2569
2601
  } else {
2570
2602
  console.log('[server] Legacy out-of-process generate watcher selected via OM_DEV_GENERATE_WATCH_MODE=legacy — expect the dev orchestrator to spawn `mercato generate watch --skip-initial`.')