@open-mercato/cli 0.6.4-canary.3993.1.739a4e21a9 → 0.6.4-develop.3926.1.c83e4d3395

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.
@@ -1,4 +1,4 @@
1
- [build:cli] found 74 entry points
1
+ [build:cli] found 73 entry points
2
2
  Copied create-app/agentic/ → dist/agentic/
3
3
  Discovered 16 standalone guides → dist/agentic/guides/
4
4
  [build:cli] built successfully
package/dist/mercato.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  import { parseModuleInstallArgs } from "./lib/module-install-args.js";
26
26
  import { resolveNextBuildIdCandidate } from "./lib/next-build-id.js";
27
27
  import { acquireServerStartLock } from "./lib/server-start-lock.js";
28
- import { createDevEnvReloader, watchDevEnvFiles } from "./lib/dev-env-reload.js";
28
+ import { createDevEnvReloader, watchDevEnvFiles, watchDevRuntimeFiles } from "./lib/dev-env-reload.js";
29
29
  const lazyIntegration = () => import("./lib/testing/integration.js");
30
30
  import path from "node:path";
31
31
  import fs from "node:fs";
@@ -246,102 +246,6 @@ function buildServerProcessEnvironment(environment) {
246
246
  }
247
247
  return runtimeEnv;
248
248
  }
249
- function resolveDevRuntimeBaseUrl(environment = process.env) {
250
- const configured = environment.APP_URL ?? environment.NEXT_PUBLIC_APP_URL ?? environment.NEXTAUTH_URL;
251
- if (configured?.trim()) {
252
- return configured.trim().replace(/\/+$/, "");
253
- }
254
- return `http://localhost:${environment.PORT?.trim() || "3000"}`;
255
- }
256
- function writeDevSplashChildState(state) {
257
- if (process.env.OM_DEV_SPLASH_RUNTIME_WRAPPER === "1") return;
258
- const stateFile = process.env.OM_DEV_SPLASH_CHILD_STATE_FILE;
259
- if (!stateFile?.trim()) return;
260
- try {
261
- fs.mkdirSync(path.dirname(stateFile), { recursive: true });
262
- fs.writeFileSync(stateFile, `${JSON.stringify({
263
- mode: process.env.OM_DEV_SPLASH_MODE || "dev",
264
- failed: false,
265
- failureLines: [],
266
- failureCommand: null,
267
- ...state
268
- }, null, 2)}
269
- `);
270
- } catch {
271
- }
272
- }
273
- function writeDevSplashRuntimeStarting(detail = "Starting Next.js dev server") {
274
- writeDevSplashChildState({
275
- phase: "Preparing app runtime",
276
- detail,
277
- ready: false,
278
- readyUrl: null,
279
- loginUrl: null,
280
- progressLabel: "Launching app runtime",
281
- activity: detail
282
- });
283
- }
284
- function resolveSplashProgressFallback() {
285
- const current = Number.parseInt(process.env.OM_DEV_SPLASH_STAGE_CURRENT ?? "", 10);
286
- const total = Number.parseInt(process.env.OM_DEV_SPLASH_STAGE_TOTAL ?? "", 10);
287
- if (Number.isFinite(current) && Number.isFinite(total) && total > 0) {
288
- return { current, total };
289
- }
290
- if (process.env.OM_DEV_SPLASH_MODE === "greenfield" || process.env.OM_DEV_SPLASH_MODE === "setup") {
291
- return { current: 5, total: 5 };
292
- }
293
- return { current: 3, total: 3 };
294
- }
295
- function writeDevSplashRuntimeRestarting(reason) {
296
- const progress = resolveSplashProgressFallback();
297
- writeDevSplashChildState({
298
- phase: "App runtime is restarting",
299
- detail: `Reason: ${reason}`,
300
- ready: false,
301
- readyUrl: null,
302
- loginUrl: null,
303
- progressCurrent: progress.current,
304
- progressTotal: progress.total,
305
- progressLabel: "Restarting app runtime",
306
- activity: `App runtime restart: ${reason}`
307
- });
308
- }
309
- function writeDevSplashRuntimeReady(reason) {
310
- const readyUrl = resolveDevRuntimeBaseUrl();
311
- const progress = resolveSplashProgressFallback();
312
- writeDevSplashChildState({
313
- phase: "App is ready",
314
- detail: reason ? `Restart completed after ${reason}` : "Next.js dev server is ready",
315
- ready: true,
316
- readyUrl,
317
- loginUrl: `${readyUrl}/login`,
318
- progressCurrent: progress.current,
319
- progressTotal: progress.total,
320
- progressPercent: 100,
321
- progressLabel: "App is ready",
322
- activity: reason ? `Restart completed after ${reason}` : "App runtime is ready"
323
- });
324
- }
325
- function resolveDevWarmupReadyTimeoutMs(environment = process.env) {
326
- const parsed = Number.parseInt(environment.OM_DEV_WARMUP_READY_TIMEOUT_MS ?? "", 10);
327
- if (Number.isFinite(parsed) && parsed >= 0) return parsed;
328
- return 3e5;
329
- }
330
- async function waitForDevWarmupReadyFile(filePath, options = {}) {
331
- const normalized = filePath?.trim();
332
- if (!normalized) return "ready";
333
- const timeoutMs = options.timeoutMs ?? resolveDevWarmupReadyTimeoutMs();
334
- const startedAt = Date.now();
335
- while (true) {
336
- if (options.signal?.aborted) return "aborted";
337
- try {
338
- if (fs.existsSync(normalized)) return "ready";
339
- } catch {
340
- }
341
- if (timeoutMs >= 0 && Date.now() - startedAt >= timeoutMs) return "timeout";
342
- await new Promise((resolve) => setTimeout(resolve, 250));
343
- }
344
- }
345
249
  function waitForManagedProcessExit(proc, label) {
346
250
  return new Promise((resolve) => {
347
251
  proc.on("exit", (code, signal) => {
@@ -541,17 +445,18 @@ async function runGeneratorSuite(quiet) {
541
445
  function createGenerateWatchChecksumFn() {
542
446
  return async () => {
543
447
  const { createResolver } = await import("./lib/resolver.js");
544
- const { calculateGenerateWatchStructureChecksum } = await import("./lib/generate-watch-structure.js");
448
+ const { calculateStructureChecksum } = await import("./lib/utils.js");
545
449
  const resolver = createResolver();
546
- const moduleRoots = [];
450
+ const tracked = /* @__PURE__ */ new Set([
451
+ path.join(resolver.getAppDir(), "src", "modules.ts"),
452
+ path.join(resolver.getAppDir(), "src", "modules")
453
+ ]);
547
454
  for (const entry of resolver.loadEnabledModules()) {
548
455
  const roots = resolver.getModulePaths(entry);
549
- moduleRoots.push({ appBase: roots.appBase, pkgBase: roots.pkgBase });
456
+ tracked.add(roots.appBase);
457
+ tracked.add(roots.pkgBase);
550
458
  }
551
- return calculateGenerateWatchStructureChecksum({
552
- modulesFile: path.join(resolver.getAppDir(), "src", "modules.ts"),
553
- moduleRoots
554
- });
459
+ return calculateStructureChecksum(Array.from(tracked));
555
460
  };
556
461
  }
557
462
  async function buildAllModules() {
@@ -1489,7 +1394,6 @@ async function run(argv = process.argv) {
1489
1394
  let activeLazySupervisor = null;
1490
1395
  let activeLazySchedulerSupervisor = null;
1491
1396
  let activeGenerateWatcher = null;
1492
- let lastRestartReason = null;
1493
1397
  const generateWatcherMode = resolveGenerateWatcherMode(process.env);
1494
1398
  const envReloader = createDevEnvReloader(appDir, process.env, initialProcessEnvironmentEntries);
1495
1399
  function cleanup() {
@@ -1568,68 +1472,54 @@ async function run(argv = process.argv) {
1568
1472
  filePath
1569
1473
  });
1570
1474
  });
1475
+ const stopRuntimeWatcher = watchDevRuntimeFiles(appDir, (filePath) => {
1476
+ devRestartPromiseResolve?.({
1477
+ label: "Runtime graph change",
1478
+ restart: true,
1479
+ filePath
1480
+ });
1481
+ });
1571
1482
  const waitForDevRestart = () => new Promise((resolve) => {
1572
1483
  devRestartPromiseResolve = resolve;
1573
1484
  });
1574
- const startNextDev = (runtimeEnv) => {
1575
- let readyResolve = () => void 0;
1576
- const readyPromise = new Promise((resolve) => {
1577
- readyResolve = resolve;
1485
+ const startNextDev = (runtimeEnv) => new Promise((resolve) => {
1486
+ const nextProcess = spawn("node", [nextBin, "dev", "--turbopack"], {
1487
+ stdio: ["inherit", "pipe", "pipe"],
1488
+ env: runtimeEnv,
1489
+ cwd: appDir
1578
1490
  });
1579
- const exitPromise = new Promise((resolve) => {
1580
- writeDevSplashRuntimeStarting(
1581
- lastRestartReason ? `Restarting Next.js dev server. Reason: ${lastRestartReason}` : "Starting Next.js dev server"
1582
- );
1583
- const nextProcess = spawn("node", [nextBin, "dev", "--turbopack"], {
1584
- stdio: ["inherit", "pipe", "pipe"],
1585
- env: runtimeEnv,
1586
- cwd: appDir
1587
- });
1588
- processes.push(nextProcess);
1589
- let combinedOutput = "";
1590
- let reportedReady = false;
1591
- const appendOutput = (chunk) => {
1592
- combinedOutput += chunk;
1593
- if (combinedOutput.length > 32768) {
1594
- combinedOutput = combinedOutput.slice(-32768);
1595
- }
1596
- if (!reportedReady && /\bready in\b/i.test(chunk)) {
1597
- reportedReady = true;
1598
- writeDevSplashRuntimeReady(lastRestartReason ?? void 0);
1599
- lastRestartReason = null;
1600
- readyResolve();
1601
- }
1602
- };
1603
- nextProcess.stdout?.on("data", (chunk) => {
1604
- const text = typeof chunk === "string" ? chunk : chunk.toString();
1605
- process.stdout.write(text);
1606
- appendOutput(text);
1607
- });
1608
- nextProcess.stderr?.on("data", (chunk) => {
1609
- const text = typeof chunk === "string" ? chunk : chunk.toString();
1610
- process.stderr.write(text);
1611
- appendOutput(text);
1612
- });
1613
- nextProcess.on("exit", async (code, signal) => {
1614
- if (!didRetryCorruptedTurbopackCache && isTurbopackCacheCorruption(combinedOutput)) {
1615
- didRetryCorruptedTurbopackCache = true;
1616
- lastRestartReason = "corrupted Turbopack dev cache";
1617
- writeDevSplashRuntimeRestarting(lastRestartReason);
1618
- console.log("[server] Detected corrupted Turbopack dev cache. Clearing .mercato/next/dev and restarting Next.js once...");
1619
- removeTurbopackDevCache(appDir);
1620
- const restarted = startNextDev(runtimeEnv);
1621
- restarted.readyPromise.then(readyResolve);
1622
- return resolve(await restarted.exitPromise);
1623
- }
1624
- resolve({
1625
- label: "Next.js dev server",
1626
- code,
1627
- signal
1628
- });
1491
+ processes.push(nextProcess);
1492
+ let combinedOutput = "";
1493
+ const appendOutput = (chunk) => {
1494
+ combinedOutput += chunk;
1495
+ if (combinedOutput.length > 32768) {
1496
+ combinedOutput = combinedOutput.slice(-32768);
1497
+ }
1498
+ };
1499
+ nextProcess.stdout?.on("data", (chunk) => {
1500
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
1501
+ process.stdout.write(text);
1502
+ appendOutput(text);
1503
+ });
1504
+ nextProcess.stderr?.on("data", (chunk) => {
1505
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
1506
+ process.stderr.write(text);
1507
+ appendOutput(text);
1508
+ });
1509
+ nextProcess.on("exit", async (code, signal) => {
1510
+ if (!didRetryCorruptedTurbopackCache && isTurbopackCacheCorruption(combinedOutput)) {
1511
+ didRetryCorruptedTurbopackCache = true;
1512
+ console.log("[server] Detected corrupted Turbopack dev cache. Clearing .mercato/next/dev and restarting Next.js once...");
1513
+ removeTurbopackDevCache(appDir);
1514
+ return resolve(await startNextDev(runtimeEnv));
1515
+ }
1516
+ resolve({
1517
+ label: "Next.js dev server",
1518
+ code,
1519
+ signal
1629
1520
  });
1630
1521
  });
1631
- return { exitPromise, readyPromise };
1632
- };
1522
+ });
1633
1523
  try {
1634
1524
  while (!stopping) {
1635
1525
  envReloader.reload();
@@ -1638,84 +1528,59 @@ async function run(argv = process.argv) {
1638
1528
  const autoSpawnSchedulerMode = resolveAutoSpawnSchedulerMode(process.env);
1639
1529
  const queueStrategy = process.env.QUEUE_STRATEGY || "local";
1640
1530
  const schedulerCommand = lookupModuleCommand(getCliModules(), "scheduler", "start");
1641
- const nextRuntime = startNextDev(runtimeEnv);
1642
- const restartPromise = waitForDevRestart();
1643
- const backgroundStartAbort = new AbortController();
1644
- const cancelBackgroundStart = () => backgroundStartAbort.abort();
1645
- nextRuntime.exitPromise.finally(cancelBackgroundStart);
1646
- restartPromise.then(cancelBackgroundStart);
1647
- let backgroundExitResolve = () => void 0;
1648
- const backgroundExitPromise = new Promise((resolve) => {
1649
- backgroundExitResolve = resolve;
1650
- });
1651
1531
  const managedExitPromises = [
1652
- nextRuntime.exitPromise,
1653
- restartPromise,
1654
- backgroundExitPromise
1532
+ startNextDev(runtimeEnv),
1533
+ waitForDevRestart()
1655
1534
  ];
1656
- const startBackgroundServices = async () => {
1657
- if (stopping || backgroundStartAbort.signal.aborted) return;
1658
- const warmupReady = await waitForDevWarmupReadyFile(process.env.OM_DEV_WARMUP_READY_FILE, {
1659
- timeoutMs: resolveDevWarmupReadyTimeoutMs(process.env),
1660
- signal: backgroundStartAbort.signal
1661
- });
1662
- if (warmupReady === "aborted" || stopping || backgroundStartAbort.signal.aborted) return;
1663
- if (warmupReady === "timeout") {
1664
- console.warn("[server] Timed out waiting for dev warmup marker; starting background services anyway.");
1665
- }
1666
- if (autoSpawnWorkersMode !== "off") {
1667
- const discoveredWorkers = getRegisteredCliWorkers();
1668
- const discoveredWorkerQueues = [...new Set(discoveredWorkers.map((worker) => worker.queue))];
1669
- if (discoveredWorkerQueues.length === 0) {
1670
- console.error("[server] AUTO_SPAWN_WORKERS is enabled, but no queues were discovered from CLI modules. Run `yarn generate` and verify `.mercato/generated/modules.cli.generated.ts` contains worker entries. Continuing without auto-spawned workers.");
1671
- } else if (autoSpawnWorkersMode === "lazy") {
1672
- console.log(`[server] Lazy worker auto-spawn enabled \u2014 workers will start on first job (${discoveredWorkerQueues.length} queue(s) watched).`);
1673
- activeLazySupervisor = startLazyWorkerSupervisor({
1674
- mercatoBin,
1675
- appDir,
1676
- runtimeEnv,
1677
- workers: discoveredWorkers,
1678
- pollMs: resolveLazyPollMs(process.env),
1679
- restartOnUnexpectedExit: resolveLazyRestart(process.env)
1680
- });
1681
- } else {
1682
- console.log("[server] Eager worker auto-spawn enabled - starting workers for all queues...");
1683
- const workerProcess = spawn("node", [mercatoBin, "queue", "worker", "--all"], {
1684
- stdio: "inherit",
1685
- env: runtimeEnv,
1686
- cwd: appDir
1687
- });
1688
- processes.push(workerProcess);
1689
- waitForManagedProcessExit(workerProcess, formatQueueWorkerLabel(discoveredWorkerQueues)).then(backgroundExitResolve);
1690
- }
1535
+ if (autoSpawnWorkersMode !== "off") {
1536
+ const discoveredWorkers = getRegisteredCliWorkers();
1537
+ const discoveredWorkerQueues = [...new Set(discoveredWorkers.map((worker) => worker.queue))];
1538
+ if (discoveredWorkerQueues.length === 0) {
1539
+ console.error("[server] AUTO_SPAWN_WORKERS is enabled, but no queues were discovered from CLI modules. Run `yarn generate` and verify `.mercato/generated/modules.cli.generated.ts` contains worker entries. Continuing without auto-spawned workers.");
1540
+ } else if (autoSpawnWorkersMode === "lazy") {
1541
+ console.log(`[server] Lazy worker auto-spawn enabled \u2014 workers will start on first job (${discoveredWorkerQueues.length} queue(s) watched).`);
1542
+ activeLazySupervisor = startLazyWorkerSupervisor({
1543
+ mercatoBin,
1544
+ appDir,
1545
+ runtimeEnv,
1546
+ workers: discoveredWorkers,
1547
+ pollMs: resolveLazyPollMs(process.env),
1548
+ restartOnUnexpectedExit: resolveLazyRestart(process.env)
1549
+ });
1550
+ } else {
1551
+ console.log("[server] Eager worker auto-spawn enabled - starting workers for all queues...");
1552
+ const workerProcess = spawn("node", [mercatoBin, "queue", "worker", "--all"], {
1553
+ stdio: "inherit",
1554
+ env: runtimeEnv,
1555
+ cwd: appDir
1556
+ });
1557
+ processes.push(workerProcess);
1558
+ managedExitPromises.push(waitForManagedProcessExit(workerProcess, formatQueueWorkerLabel(discoveredWorkerQueues)));
1691
1559
  }
1692
- if (autoSpawnSchedulerMode !== "off" && queueStrategy === "local") {
1693
- if (schedulerCommand.status !== "ok") {
1694
- console.log(`[server] Skipping scheduler auto-start \u2014 ${describeMissingModuleCommand(schedulerCommand)}`);
1695
- } else if (autoSpawnSchedulerMode === "lazy") {
1696
- console.log("[server] Lazy scheduler auto-spawn enabled - scheduler will start when an enabled schedule exists.");
1697
- activeLazySchedulerSupervisor = startLazySchedulerSupervisor({
1698
- mercatoBin,
1699
- appDir,
1700
- runtimeEnv,
1701
- pollMs: resolveLazySchedulerPollMs(process.env),
1702
- restartOnUnexpectedExit: resolveLazySchedulerRestart(process.env)
1703
- });
1704
- } else {
1705
- console.log("[server] Eager scheduler auto-spawn enabled - starting scheduler polling engine...");
1706
- const schedulerProcess = spawn("node", [mercatoBin, "scheduler", "start"], {
1707
- stdio: "inherit",
1708
- env: runtimeEnv,
1709
- cwd: appDir
1710
- });
1711
- processes.push(schedulerProcess);
1712
- waitForManagedProcessExit(schedulerProcess, "Scheduler polling engine").then(backgroundExitResolve);
1713
- }
1560
+ }
1561
+ if (autoSpawnSchedulerMode !== "off" && queueStrategy === "local") {
1562
+ if (schedulerCommand.status !== "ok") {
1563
+ console.log(`[server] Skipping scheduler auto-start \u2014 ${describeMissingModuleCommand(schedulerCommand)}`);
1564
+ } else if (autoSpawnSchedulerMode === "lazy") {
1565
+ console.log("[server] Lazy scheduler auto-spawn enabled - scheduler will start when an enabled schedule exists.");
1566
+ activeLazySchedulerSupervisor = startLazySchedulerSupervisor({
1567
+ mercatoBin,
1568
+ appDir,
1569
+ runtimeEnv,
1570
+ pollMs: resolveLazySchedulerPollMs(process.env),
1571
+ restartOnUnexpectedExit: resolveLazySchedulerRestart(process.env)
1572
+ });
1573
+ } else {
1574
+ console.log("[server] Eager scheduler auto-spawn enabled - starting scheduler polling engine...");
1575
+ const schedulerProcess = spawn("node", [mercatoBin, "scheduler", "start"], {
1576
+ stdio: "inherit",
1577
+ env: runtimeEnv,
1578
+ cwd: appDir
1579
+ });
1580
+ processes.push(schedulerProcess);
1581
+ managedExitPromises.push(waitForManagedProcessExit(schedulerProcess, "Scheduler polling engine"));
1714
1582
  }
1715
- };
1716
- nextRuntime.readyPromise.then(() => {
1717
- void startBackgroundServices();
1718
- });
1583
+ }
1719
1584
  if (generateWatcherMode === "in-process") {
1720
1585
  console.log("[server] In-process generate watcher enabled \u2014 structural changes will regenerate without a sidecar process.");
1721
1586
  activeGenerateWatcher = startInProcessGenerateWatcher({
@@ -1736,10 +1601,6 @@ async function run(argv = process.argv) {
1736
1601
  console.log("[server] Legacy out-of-process generate watcher selected via OM_DEV_GENERATE_WATCH_MODE=legacy \u2014 expect the dev orchestrator to spawn `mercato generate watch --skip-initial`.");
1737
1602
  }
1738
1603
  const firstExit = await Promise.race(managedExitPromises);
1739
- if (isDevServerRestartResult(firstExit)) {
1740
- lastRestartReason = `${firstExit.label.toLowerCase()} (${path.basename(firstExit.filePath)})`;
1741
- writeDevSplashRuntimeRestarting(lastRestartReason);
1742
- }
1743
1604
  await cleanupAndWait();
1744
1605
  devRestartPromiseResolve = null;
1745
1606
  if (isDevServerRestartResult(firstExit)) {
@@ -1753,6 +1614,7 @@ async function run(argv = process.argv) {
1753
1614
  }
1754
1615
  } finally {
1755
1616
  stopEnvWatcher();
1617
+ stopRuntimeWatcher();
1756
1618
  }
1757
1619
  }
1758
1620
  },