@open-mercato/cli 0.10.1-develop.7756.1.8f5dec1b96 → 0.10.1-develop.7759.1.416727583e

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 (120) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/agentic/guides/module-facts.json +162 -162
  3. package/dist/agentic/guides/module-facts.v2.json +162 -162
  4. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  5. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  6. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  8. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  9. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  10. package/dist/agentic/guides/modules/auth/index.md +1 -1
  11. package/dist/agentic/guides/modules/availability/index.md +1 -1
  12. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  13. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  14. package/dist/agentic/guides/modules/cart/index.md +1 -1
  15. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  16. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  17. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  25. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  26. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  27. package/dist/agentic/guides/modules/configs/index.md +1 -1
  28. package/dist/agentic/guides/modules/content/index.md +1 -1
  29. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  30. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  31. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  32. package/dist/agentic/guides/modules/customers/index.md +1 -1
  33. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  34. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  35. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  36. package/dist/agentic/guides/modules/devices/index.md +1 -1
  37. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  38. package/dist/agentic/guides/modules/directory/index.md +1 -1
  39. package/dist/agentic/guides/modules/documents/index.md +1 -1
  40. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  41. package/dist/agentic/guides/modules/entities/index.md +1 -1
  42. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  43. package/dist/agentic/guides/modules/events/index.md +1 -1
  44. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  45. package/dist/agentic/guides/modules/forms/index.md +1 -1
  46. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  47. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  48. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  49. package/dist/agentic/guides/modules/generators/index.md +1 -1
  50. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  51. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  52. package/dist/agentic/guides/modules/messages/index.md +1 -1
  53. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  54. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  55. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  56. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  57. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  58. package/dist/agentic/guides/modules/planner/index.md +1 -1
  59. package/dist/agentic/guides/modules/portal/index.md +1 -1
  60. package/dist/agentic/guides/modules/progress/index.md +1 -1
  61. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  62. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  63. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  64. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  65. package/dist/agentic/guides/modules/resources/index.md +1 -1
  66. package/dist/agentic/guides/modules/sales/index.md +1 -1
  67. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  68. package/dist/agentic/guides/modules/search/index.md +1 -1
  69. package/dist/agentic/guides/modules/security/index.md +1 -1
  70. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  71. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  72. package/dist/agentic/guides/modules/sso/index.md +1 -1
  73. package/dist/agentic/guides/modules/staff/index.md +1 -1
  74. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  75. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  76. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  77. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  78. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  79. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  80. package/dist/agentic/guides/modules/translations/index.md +1 -1
  81. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  82. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  83. package/dist/agentic/guides/modules/wms/index.md +1 -1
  84. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  85. package/dist/agentic/guides/reference-module-facts.json +1 -1
  86. package/dist/agentic/guides/upstream/manifest.json +1 -1
  87. package/dist/lib/__integration__/TC-INT-007.spec.js +17 -0
  88. package/dist/lib/__integration__/TC-INT-007.spec.js.map +2 -2
  89. package/dist/lib/module-install.js +46 -8
  90. package/dist/lib/module-install.js.map +2 -2
  91. package/dist/lib/module-search-args.js +97 -0
  92. package/dist/lib/module-search-args.js.map +7 -0
  93. package/dist/lib/module-search-index.js +677 -0
  94. package/dist/lib/module-search-index.js.map +7 -0
  95. package/dist/lib/module-search.js +668 -0
  96. package/dist/lib/module-search.js.map +7 -0
  97. package/dist/lib/modules-config.js +105 -27
  98. package/dist/lib/modules-config.js.map +2 -2
  99. package/dist/lib/resolver.js +21 -1
  100. package/dist/lib/resolver.js.map +2 -2
  101. package/dist/mercato.js +32 -15
  102. package/dist/mercato.js.map +2 -2
  103. package/package.json +8 -7
  104. package/src/__tests__/mercato.test.ts +57 -0
  105. package/src/lib/__fixtures__/module-search/README.md +97 -0
  106. package/src/lib/__fixtures__/module-search/built-in.json +235 -0
  107. package/src/lib/__fixtures__/module-search/catalog-parity.json +4076 -0
  108. package/src/lib/__fixtures__/module-search/modules-index.json +1980 -0
  109. package/src/lib/__integration__/TC-INT-007.spec.ts +22 -0
  110. package/src/lib/__tests__/module-install.test.ts +220 -14
  111. package/src/lib/__tests__/module-search.test.ts +929 -0
  112. package/src/lib/__tests__/modules-config.test.ts +273 -1
  113. package/src/lib/__tests__/resolver.enterprise.test.ts +60 -0
  114. package/src/lib/module-install.ts +54 -10
  115. package/src/lib/module-search-args.ts +116 -0
  116. package/src/lib/module-search-index.ts +1033 -0
  117. package/src/lib/module-search.ts +952 -0
  118. package/src/lib/modules-config.ts +153 -36
  119. package/src/lib/resolver.ts +23 -1
  120. package/src/mercato.ts +36 -11
@@ -10,8 +10,12 @@ export type ModuleEntry = {
10
10
  type ModuleOccurrence = {
11
11
  entry: ModuleEntry
12
12
  node: ts.ObjectLiteralExpression
13
+ active: boolean
14
+ envFlags: string[] | null
13
15
  }
14
16
 
17
+ type EnvFlagScope = Map<string, string[] | null>
18
+
15
19
  type ModuleConfigShape = {
16
20
  arrayNode: ts.ArrayLiteralExpression
17
21
  occurrences: ModuleOccurrence[]
@@ -41,20 +45,15 @@ function parseModuleEntryFromObjectLiteral(node: ts.ObjectLiteralExpression): Mo
41
45
  }
42
46
  }
43
47
 
44
- function parseProcessEnvAccess(
45
- node: ts.Expression,
46
- env: NodeJS.ProcessEnv,
47
- ): { matched: boolean; value: string | undefined } {
48
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
49
- const target = node.expression
50
- if (
51
- ts.isPropertyAccessExpression(target)
52
- && ts.isIdentifier(target.expression)
53
- && target.expression.text === 'process'
54
- && target.name.text === 'env'
55
- ) {
56
- return { matched: true, value: env[node.name.text] }
57
- }
48
+ function readProcessEnvName(node: ts.Expression): string | null {
49
+ if (
50
+ ts.isPropertyAccessExpression(node)
51
+ && ts.isPropertyAccessExpression(node.expression)
52
+ && ts.isIdentifier(node.expression.expression)
53
+ && node.expression.expression.text === 'process'
54
+ && node.expression.name.text === 'env'
55
+ ) {
56
+ return node.name.text
58
57
  }
59
58
 
60
59
  if (
@@ -65,10 +64,10 @@ function parseProcessEnvAccess(
65
64
  && node.expression.name.text === 'env'
66
65
  && ts.isStringLiteralLike(node.argumentExpression)
67
66
  ) {
68
- return { matched: true, value: env[node.argumentExpression.text] }
67
+ return node.argumentExpression.text
69
68
  }
70
69
 
71
- return { matched: false, value: undefined }
70
+ return null
72
71
  }
73
72
 
74
73
  function evaluateStaticExpressionWithScope(
@@ -96,9 +95,9 @@ function evaluateStaticExpressionWithScope(
96
95
  if (node.kind === ts.SyntaxKind.FalseKeyword) return false
97
96
  if (node.kind === ts.SyntaxKind.NullKeyword) return null
98
97
 
99
- const envAccess = parseProcessEnvAccess(node, env)
100
- if (envAccess.matched) {
101
- return envAccess.value
98
+ const envName = readProcessEnvName(node)
99
+ if (envName) {
100
+ return env[envName]
102
101
  }
103
102
 
104
103
  if (ts.isPropertyAccessExpression(node)) {
@@ -202,28 +201,84 @@ function evaluateStaticCondition(
202
201
  return Boolean(evaluateStaticExpressionWithScope(node, env, scope))
203
202
  }
204
203
 
204
+ function mergeEnvFlags(left: string[] | null, right: string[] | null): string[] | null {
205
+ if (left === null || right === null) return null
206
+ return Array.from(new Set([...left, ...right]))
207
+ }
208
+
209
+ function collectEnablingEnvFlags(node: ts.Expression, envFlagScope: EnvFlagScope): string[] | null {
210
+ if (ts.isParenthesizedExpression(node)) {
211
+ return collectEnablingEnvFlags(node.expression, envFlagScope)
212
+ }
213
+
214
+ const envName = readProcessEnvName(node)
215
+ if (envName) return [envName]
216
+
217
+ if (ts.isIdentifier(node)) {
218
+ return envFlagScope.get(node.text) ?? null
219
+ }
220
+
221
+ if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
222
+ return mergeEnvFlags(
223
+ collectEnablingEnvFlags(node.left, envFlagScope),
224
+ collectEnablingEnvFlags(node.right, envFlagScope),
225
+ )
226
+ }
227
+
228
+ if (
229
+ ts.isCallExpression(node)
230
+ && ts.isIdentifier(node.expression)
231
+ && node.expression.text === 'parseBooleanWithDefault'
232
+ && node.arguments[0]
233
+ ) {
234
+ const envArgument = readProcessEnvName(node.arguments[0])
235
+ return envArgument ? [envArgument] : null
236
+ }
237
+
238
+ return null
239
+ }
240
+
241
+ type BranchContext = {
242
+ active: boolean
243
+ envFlags: string[] | null
244
+ }
245
+
205
246
  function collectPushEntriesFromStatement(
206
247
  statement: ts.Statement,
207
248
  env: NodeJS.ProcessEnv,
208
249
  targetVariableName: string,
209
250
  scope: Map<string, unknown>,
251
+ envFlagScope: EnvFlagScope,
252
+ branch: BranchContext = { active: true, envFlags: [] },
210
253
  ): ModuleOccurrence[] {
211
254
  if (ts.isBlock(statement)) {
212
255
  return statement.statements.flatMap((child) =>
213
- collectPushEntriesFromStatement(child, env, targetVariableName, scope),
256
+ collectPushEntriesFromStatement(child, env, targetVariableName, scope, envFlagScope, branch),
214
257
  )
215
258
  }
216
259
 
217
260
  if (ts.isIfStatement(statement)) {
218
- if (evaluateStaticCondition(statement.expression, env, scope)) {
219
- return collectPushEntriesFromStatement(statement.thenStatement, env, targetVariableName, scope)
220
- }
221
-
222
- if (statement.elseStatement) {
223
- return collectPushEntriesFromStatement(statement.elseStatement, env, targetVariableName, scope)
224
- }
225
-
226
- return []
261
+ const conditionMet = evaluateStaticCondition(statement.expression, env, scope)
262
+ const envFlags = mergeEnvFlags(branch.envFlags, collectEnablingEnvFlags(statement.expression, envFlagScope))
263
+ const thenEntries = collectPushEntriesFromStatement(
264
+ statement.thenStatement,
265
+ env,
266
+ targetVariableName,
267
+ scope,
268
+ envFlagScope,
269
+ { active: branch.active && conditionMet, envFlags },
270
+ )
271
+ const elseEntries = statement.elseStatement
272
+ ? collectPushEntriesFromStatement(
273
+ statement.elseStatement,
274
+ env,
275
+ targetVariableName,
276
+ scope,
277
+ envFlagScope,
278
+ { active: branch.active && !conditionMet, envFlags: null },
279
+ )
280
+ : []
281
+ return [...thenEntries, ...elseEntries]
227
282
  }
228
283
 
229
284
  if (!ts.isExpressionStatement(statement)) return []
@@ -243,10 +298,14 @@ function collectPushEntriesFromStatement(
243
298
  return expression.arguments.flatMap((argument) => {
244
299
  if (!ts.isObjectLiteralExpression(argument)) return []
245
300
  const entry = parseModuleEntryFromObjectLiteral(argument)
246
- return entry ? [{ entry, node: argument }] : []
301
+ return entry ? [{ entry, node: argument, active: branch.active, envFlags: branch.envFlags }] : []
247
302
  })
248
303
  }
249
304
 
305
+ function activeEntries(occurrences: ModuleOccurrence[]): ModuleEntry[] {
306
+ return occurrences.filter((occurrence) => occurrence.active).map((occurrence) => occurrence.entry)
307
+ }
308
+
250
309
  function parseModuleConfigShape(
251
310
  source: string,
252
311
  env: NodeJS.ProcessEnv = process.env,
@@ -255,6 +314,7 @@ function parseModuleConfigShape(
255
314
  const variableName = 'enabledModules'
256
315
  const occurrences: ModuleOccurrence[] = []
257
316
  const scope = new Map<string, unknown>()
317
+ const envFlagScope: EnvFlagScope = new Map()
258
318
  let arrayNode: ts.ArrayLiteralExpression | null = null
259
319
  let foundDeclaration = false
260
320
 
@@ -270,9 +330,9 @@ function parseModuleConfigShape(
270
330
  occurrences.push(...declaration.initializer.elements.flatMap((element) => {
271
331
  if (!ts.isObjectLiteralExpression(element)) return []
272
332
  const entry = parseModuleEntryFromObjectLiteral(element)
273
- return entry ? [{ entry, node: element }] : []
333
+ return entry ? [{ entry, node: element, active: true, envFlags: [] }] : []
274
334
  }))
275
- scope.set(variableName, occurrences.map((occurrence) => occurrence.entry))
335
+ scope.set(variableName, activeEntries(occurrences))
276
336
  foundDeclaration = true
277
337
  continue
278
338
  }
@@ -283,16 +343,17 @@ function parseModuleConfigShape(
283
343
  declaration.name.text,
284
344
  evaluateStaticExpressionWithScope(declaration.initializer, env, scope),
285
345
  )
346
+ envFlagScope.set(declaration.name.text, collectEnablingEnvFlags(declaration.initializer, envFlagScope))
286
347
  }
287
348
  continue
288
349
  }
289
350
 
290
351
  if (!foundDeclaration) continue
291
352
 
292
- const pushedOccurrences = collectPushEntriesFromStatement(statement, env, variableName, scope)
353
+ const pushedOccurrences = collectPushEntriesFromStatement(statement, env, variableName, scope, envFlagScope)
293
354
  if (pushedOccurrences.length > 0) {
294
355
  occurrences.push(...pushedOccurrences)
295
- scope.set(variableName, occurrences.map((occurrence) => occurrence.entry))
356
+ scope.set(variableName, activeEntries(occurrences))
296
357
  }
297
358
  }
298
359
 
@@ -394,6 +455,57 @@ function upsertModuleSource(objectLiteral: string, from: string): string {
394
455
  return objectLiteral.replace(/\}\s*$/, `, from: '${escapeSingleQuotedString(from)}' }`)
395
456
  }
396
457
 
458
+ export function readEnabledModules(modulesPath: string, env: NodeJS.ProcessEnv = process.env): ModuleEntry[] {
459
+ const source = fs.readFileSync(modulesPath, 'utf8')
460
+ // keeps only registrations whose condition holds; #8116 tags the others `active: false` instead of skipping them
461
+ return parseModuleConfigShape(source, env)
462
+ .occurrences.filter((occurrence) => !('active' in occurrence) || occurrence.active !== false)
463
+ .map((occurrence) => normalizeModuleEntry(occurrence.entry))
464
+ }
465
+
466
+ export class ModuleGatedOffError extends Error {
467
+ readonly code = 'MODULE_GATED_OFF'
468
+
469
+ constructor(
470
+ message: string,
471
+ readonly moduleId: string,
472
+ readonly envFlags: string[],
473
+ ) {
474
+ super(message)
475
+ this.name = 'ModuleGatedOffError'
476
+ }
477
+ }
478
+
479
+ function resolveFlagsToSet(occurrences: ModuleOccurrence[], env: NodeJS.ProcessEnv): string[] {
480
+ if (occurrences.some((occurrence) => occurrence.envFlags === null)) return []
481
+ const envFlags = Array.from(new Set(occurrences.flatMap((occurrence) => occurrence.envFlags ?? [])))
482
+ return envFlags.filter((flag) => !parseBooleanWithDefault(env[flag], false))
483
+ }
484
+
485
+ function buildModuleGatedOffError(
486
+ moduleId: string,
487
+ modulesPath: string,
488
+ occurrences: ModuleOccurrence[],
489
+ env: NodeJS.ProcessEnv = process.env,
490
+ ): ModuleGatedOffError {
491
+ const flagsToSet = resolveFlagsToSet(occurrences, env)
492
+ const prefix = `Module "${moduleId}" is already registered in ${modulesPath} behind a condition that is currently off, so no second entry was added.`
493
+ const message = flagsToSet.length === 0
494
+ ? `${prefix} Make that condition true to enable it.`
495
+ : `${prefix} Enable it by setting ${flagsToSet.map((flag) => `${flag}=true`).join(' and ')} in your environment (.env), then run \`yarn generate\`.`
496
+ return new ModuleGatedOffError(message, moduleId, flagsToSet)
497
+ }
498
+
499
+ export function assertModuleNotGatedOff(modulesPath: string, moduleId: string): void {
500
+ if (!fs.existsSync(modulesPath)) return
501
+
502
+ const config = parseModuleConfigShape(fs.readFileSync(modulesPath, 'utf8'))
503
+ const matches = config.occurrences.filter((occurrence) => occurrence.entry.id === moduleId)
504
+ if (matches.length > 0 && matches.every((occurrence) => !occurrence.active)) {
505
+ throw buildModuleGatedOffError(moduleId, modulesPath, matches)
506
+ }
507
+ }
508
+
397
509
  export function ensureModuleRegistration(
398
510
  modulesPath: string,
399
511
  entry: ModuleEntry,
@@ -406,7 +518,12 @@ export function ensureModuleRegistration(
406
518
  const sourceFile = ts.createSourceFile('modules.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
407
519
  const config = parseModuleConfigShape(source)
408
520
  const normalized = normalizeModuleEntry(entry)
409
- const matches = config.occurrences.filter((occurrence) => occurrence.entry.id === normalized.id)
521
+ const allMatches = config.occurrences.filter((occurrence) => occurrence.entry.id === normalized.id)
522
+ const matches = allMatches.filter((occurrence) => occurrence.active)
523
+
524
+ if (matches.length === 0 && allMatches.length > 0) {
525
+ throw buildModuleGatedOffError(normalized.id, modulesPath, allMatches)
526
+ }
410
527
 
411
528
  if (matches.length > 1) {
412
529
  throw new Error(
@@ -442,7 +559,7 @@ export function setModuleRegistrationSource(
442
559
 
443
560
  const source = fs.readFileSync(modulesPath, 'utf8')
444
561
  const config = parseModuleConfigShape(source)
445
- const matches = config.occurrences.filter((occurrence) => occurrence.entry.id === moduleId)
562
+ const matches = config.occurrences.filter((occurrence) => occurrence.active && occurrence.entry.id === moduleId)
446
563
 
447
564
  if (matches.length === 0) {
448
565
  throw new Error(
@@ -331,7 +331,29 @@ function parseModulesFromSource(source: string, env: NodeJS.ProcessEnv = process
331
331
  }
332
332
  }
333
333
 
334
- return modules
334
+ return dedupeModulesById(modules)
335
+ }
336
+
337
+ const reportedDuplicateModuleIds = new Set<string>()
338
+
339
+ function dedupeModulesById(modules: ModuleEntry[]): ModuleEntry[] {
340
+ const seen = new Map<string, ModuleEntry>()
341
+ for (const entry of modules) {
342
+ const existing = seen.get(entry.id)
343
+ if (!existing) {
344
+ seen.set(entry.id, entry)
345
+ continue
346
+ }
347
+ if (entry.devSupervisorRequiresFullBootstrap && !existing.devSupervisorRequiresFullBootstrap) {
348
+ seen.set(entry.id, { ...existing, devSupervisorRequiresFullBootstrap: true })
349
+ }
350
+ if (reportedDuplicateModuleIds.has(entry.id)) continue
351
+ reportedDuplicateModuleIds.add(entry.id)
352
+ console.warn(
353
+ `[resolver] Module "${entry.id}" is registered more than once in src/modules.ts (from "${existing.from ?? '@open-mercato/core'}" and "${entry.from ?? '@open-mercato/core'}"). Keeping the first registration; remove the duplicate entry.`,
354
+ )
355
+ }
356
+ return Array.from(seen.values())
335
357
  }
336
358
 
337
359
  export function readEnabledModulesFromConfig(cfgPath: string): ModuleEntry[] {
package/src/mercato.ts CHANGED
@@ -39,6 +39,7 @@ import {
39
39
  type GenerateWatcherMode,
40
40
  } from './lib/in-process-generate-watcher-mode'
41
41
  import { parseModuleInstallArgs } from './lib/module-install-args'
42
+ import type { ModuleCommandResult } from './lib/module-install'
42
43
  import { resolveNextBuildIdCandidate } from './lib/next-build-id'
43
44
  import { acquireServerStartLock } from './lib/server-start-lock'
44
45
  import { assertSingleInstanceStrategies } from './lib/single-instance-strategy-guard'
@@ -678,6 +679,22 @@ function ensureNextBuildIdInConfiguredDistDir(appDir: string): void {
678
679
  )
679
680
  }
680
681
 
682
+ function printModuleCommandResult(result: ModuleCommandResult, alreadyEnabledNote?: string): void {
683
+ if (!result.registrationChanged) {
684
+ console.log(`\nℹ️ Module "${result.moduleId}" from "${result.from}" is already enabled in modules.ts. Nothing to change.`)
685
+ if (alreadyEnabledNote) {
686
+ console.log(alreadyEnabledNote)
687
+ }
688
+ console.log('')
689
+ return
690
+ }
691
+
692
+ console.log(`\n✅ Module "${result.moduleId}" enabled from ${result.from}.\n`)
693
+ console.log('Next steps:')
694
+ console.log(' 1. Review generated files if needed: .mercato/generated/')
695
+ console.log(' 2. Start dev: yarn dev')
696
+ }
697
+
681
698
  async function handleDirectEjectCommand(args: string[]): Promise<number> {
682
699
  const { createResolver } = await import('./lib/resolver')
683
700
  const { listEjectableModules, ejectModule } = await import('./lib/eject')
@@ -933,13 +950,18 @@ const TOP_LEVEL_COMMAND_HELP: Record<string, string[]> = {
933
950
 
934
951
  // A help invocation must never materialize .env from .env.example — asking what the flags are
935
952
  // should not mutate the working tree, least of all with the example's placeholder DATABASE_URL.
953
+ // `module search` and `module info` only read the catalog, so they never create .env either, and
954
+ // their output stays clean: dotenv prints its `injected env` line on stdout, which breaks
955
+ // `--json | jq` and agents that parse the tools@1 contract. Any `--json` run stays quiet.
936
956
  export function resolveEnvBootstrapOptions(parts: string[]): { createIfMissing: boolean; quiet: boolean } {
937
957
  const first = parts[0]
938
958
  const opaqueEnvCommand = first === 'deploy' || first === 'telemetry'
959
+ const readOnlyModuleCommand = first === 'module' && (parts[1] === 'search' || parts[1] === 'info')
960
+ const jsonOutput = parts.includes('--json')
939
961
  const helpRequested = isHelpRequest(parts)
940
962
  return {
941
- createIfMissing: !helpRequested && !opaqueEnvCommand,
942
- quiet: helpRequested || opaqueEnvCommand,
963
+ createIfMissing: !helpRequested && !opaqueEnvCommand && !readOnlyModuleCommand,
964
+ quiet: helpRequested || opaqueEnvCommand || readOnlyModuleCommand || jsonOutput,
943
965
  }
944
966
  }
945
967
 
@@ -1451,13 +1473,22 @@ export async function run(argv = process.argv) {
1451
1473
  const commandArgs = remaining.filter(Boolean)
1452
1474
 
1453
1475
  if (!subcommand || subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
1454
- console.log('Usage: yarn mercato module <add|enable|eject> ...')
1476
+ console.log('Usage: yarn mercato module <add|enable|eject|search|info> ...')
1455
1477
  console.log(' yarn mercato module add <packageSpec> [--module <moduleId>] [--eject] [--allow-third-party]')
1456
1478
  console.log(' yarn mercato module enable <packageName> [--module <moduleId>] [--eject] [--allow-third-party]')
1457
1479
  console.log(' yarn mercato module eject <moduleId>')
1480
+ console.log(' yarn mercato module search [<query>] [--category <id>] [--kind <kind>] [--all-lines] [--limit <n>] [--json]')
1481
+ console.log(' yarn mercato module info <package-or-module-id> [--json]')
1458
1482
  return 0
1459
1483
  }
1460
1484
 
1485
+ if (subcommand === 'search' || subcommand === 'info') {
1486
+ const { runModuleSearch, runModuleInfo } = await import('./lib/module-search')
1487
+ const { readEnabledModules } = await import('./lib/modules-config')
1488
+ const deps = { readEnabledModules }
1489
+ return subcommand === 'search' ? await runModuleSearch(commandArgs, deps) : await runModuleInfo(commandArgs, deps)
1490
+ }
1491
+
1461
1492
  if (subcommand === 'add') {
1462
1493
  const { createResolver } = await import('./lib/resolver')
1463
1494
  const { addOfficialModule } = await import('./lib/module-install')
@@ -1469,10 +1500,7 @@ export async function run(argv = process.argv) {
1469
1500
  }
1470
1501
 
1471
1502
  const result = await addOfficialModule(createResolver(), packageSpec, eject, moduleId ?? undefined, allowThirdParty)
1472
- console.log(`\n✅ Module "${result.moduleId}" enabled from ${result.from}.\n`)
1473
- console.log('Next steps:')
1474
- console.log(' 1. Review generated files if needed: .mercato/generated/')
1475
- console.log(' 2. Start dev: yarn dev')
1503
+ printModuleCommandResult(result, 'If yarn add changed the package version, run "yarn mercato generate" to refresh generated files.')
1476
1504
  return 0
1477
1505
  }
1478
1506
 
@@ -1487,10 +1515,7 @@ export async function run(argv = process.argv) {
1487
1515
  const { enableOfficialModule } = await import('./lib/module-install')
1488
1516
  const { moduleId, eject, allowThirdParty } = parseModuleInstallArgs(commandArgs)
1489
1517
  const result = await enableOfficialModule(createResolver(), packageName, moduleId ?? undefined, eject, allowThirdParty)
1490
- console.log(`\n✅ Module "${result.moduleId}" enabled from ${result.from}.\n`)
1491
- console.log('Next steps:')
1492
- console.log(' 1. Review generated files if needed: .mercato/generated/')
1493
- console.log(' 2. Start dev: yarn dev')
1518
+ printModuleCommandResult(result)
1494
1519
  return 0
1495
1520
  }
1496
1521