syncorejs 0.2.1 → 0.2.2

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 (135) hide show
  1. package/README.md +2 -1
  2. package/dist/_vendor/cli/app.d.mts.map +1 -1
  3. package/dist/_vendor/cli/app.mjs +323 -42
  4. package/dist/_vendor/cli/app.mjs.map +1 -1
  5. package/dist/_vendor/cli/context.mjs +27 -9
  6. package/dist/_vendor/cli/context.mjs.map +1 -1
  7. package/dist/_vendor/cli/doctor.mjs +513 -46
  8. package/dist/_vendor/cli/doctor.mjs.map +1 -1
  9. package/dist/_vendor/cli/messages.mjs +5 -4
  10. package/dist/_vendor/cli/messages.mjs.map +1 -1
  11. package/dist/_vendor/cli/project.mjs +110 -12
  12. package/dist/_vendor/cli/project.mjs.map +1 -1
  13. package/dist/_vendor/cli/render.mjs +57 -9
  14. package/dist/_vendor/cli/render.mjs.map +1 -1
  15. package/dist/_vendor/cli/targets.mjs +4 -3
  16. package/dist/_vendor/cli/targets.mjs.map +1 -1
  17. package/dist/_vendor/core/cli.d.mts +13 -3
  18. package/dist/_vendor/core/cli.d.mts.map +1 -1
  19. package/dist/_vendor/core/cli.mjs +242 -91
  20. package/dist/_vendor/core/cli.mjs.map +1 -1
  21. package/dist/_vendor/core/devtools-auth.mjs +60 -0
  22. package/dist/_vendor/core/devtools-auth.mjs.map +1 -0
  23. package/dist/_vendor/core/index.d.mts +5 -3
  24. package/dist/_vendor/core/index.mjs +22 -2
  25. package/dist/_vendor/core/index.mjs.map +1 -1
  26. package/dist/_vendor/core/runtime/components.d.mts +111 -0
  27. package/dist/_vendor/core/runtime/components.d.mts.map +1 -0
  28. package/dist/_vendor/core/runtime/components.mjs +186 -0
  29. package/dist/_vendor/core/runtime/components.mjs.map +1 -0
  30. package/dist/_vendor/core/runtime/devtools.d.mts +4 -4
  31. package/dist/_vendor/core/runtime/devtools.d.mts.map +1 -1
  32. package/dist/_vendor/core/runtime/devtools.mjs +52 -41
  33. package/dist/_vendor/core/runtime/devtools.mjs.map +1 -1
  34. package/dist/_vendor/core/runtime/functions.d.mts +10 -10
  35. package/dist/_vendor/core/runtime/functions.d.mts.map +1 -1
  36. package/dist/_vendor/core/runtime/functions.mjs +2 -2
  37. package/dist/_vendor/core/runtime/functions.mjs.map +1 -1
  38. package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs +77 -0
  39. package/dist/_vendor/core/runtime/internal/engines/devtoolsEngine.mjs.map +1 -0
  40. package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs +617 -0
  41. package/dist/_vendor/core/runtime/internal/engines/executionEngine.mjs.map +1 -0
  42. package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs +186 -0
  43. package/dist/_vendor/core/runtime/internal/engines/reactivityEngine.mjs.map +1 -0
  44. package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs +220 -0
  45. package/dist/_vendor/core/runtime/internal/engines/schedulerEngine.mjs.map +1 -0
  46. package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs +203 -0
  47. package/dist/_vendor/core/runtime/internal/engines/schemaEngine.mjs.map +1 -0
  48. package/dist/_vendor/core/runtime/internal/engines/shared.mjs +177 -0
  49. package/dist/_vendor/core/runtime/internal/engines/shared.mjs.map +1 -0
  50. package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs +144 -0
  51. package/dist/_vendor/core/runtime/internal/engines/storageEngine.mjs.map +1 -0
  52. package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs +220 -0
  53. package/dist/_vendor/core/runtime/internal/runtimeKernel.mjs.map +1 -0
  54. package/dist/_vendor/core/runtime/internal/runtimeStatus.mjs +32 -0
  55. package/dist/_vendor/core/runtime/internal/runtimeStatus.mjs.map +1 -0
  56. package/dist/_vendor/core/runtime/internal/systemMeta.mjs +61 -0
  57. package/dist/_vendor/core/runtime/internal/systemMeta.mjs.map +1 -0
  58. package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs +37 -0
  59. package/dist/_vendor/core/runtime/internal/transactionCoordinator.mjs.map +1 -0
  60. package/dist/_vendor/core/runtime/runtime.d.mts +159 -205
  61. package/dist/_vendor/core/runtime/runtime.d.mts.map +1 -1
  62. package/dist/_vendor/core/runtime/runtime.mjs +16 -1371
  63. package/dist/_vendor/core/runtime/runtime.mjs.map +1 -1
  64. package/dist/_vendor/core/transport.d.mts +111 -0
  65. package/dist/_vendor/core/transport.d.mts.map +1 -0
  66. package/dist/_vendor/core/transport.mjs +419 -0
  67. package/dist/_vendor/core/transport.mjs.map +1 -0
  68. package/dist/_vendor/devtools-protocol/index.d.ts +39 -1
  69. package/dist/_vendor/devtools-protocol/index.d.ts.map +1 -1
  70. package/dist/_vendor/devtools-protocol/index.js +25 -9
  71. package/dist/_vendor/devtools-protocol/index.js.map +1 -1
  72. package/dist/_vendor/next/index.d.ts +1 -1
  73. package/dist/_vendor/next/index.d.ts.map +1 -1
  74. package/dist/_vendor/next/index.js +31 -13
  75. package/dist/_vendor/next/index.js.map +1 -1
  76. package/dist/_vendor/platform-expo/index.d.ts +12 -12
  77. package/dist/_vendor/platform-expo/index.d.ts.map +1 -1
  78. package/dist/_vendor/platform-expo/index.js +4 -2
  79. package/dist/_vendor/platform-expo/index.js.map +1 -1
  80. package/dist/_vendor/platform-expo/react.d.ts.map +1 -1
  81. package/dist/_vendor/platform-expo/react.js +11 -10
  82. package/dist/_vendor/platform-expo/react.js.map +1 -1
  83. package/dist/_vendor/platform-node/index.d.mts +23 -19
  84. package/dist/_vendor/platform-node/index.d.mts.map +1 -1
  85. package/dist/_vendor/platform-node/index.mjs +13 -5
  86. package/dist/_vendor/platform-node/index.mjs.map +1 -1
  87. package/dist/_vendor/platform-node/ipc-react.d.mts.map +1 -1
  88. package/dist/_vendor/platform-node/ipc-react.mjs +15 -2
  89. package/dist/_vendor/platform-node/ipc-react.mjs.map +1 -1
  90. package/dist/_vendor/platform-node/ipc.d.mts +11 -35
  91. package/dist/_vendor/platform-node/ipc.d.mts.map +1 -1
  92. package/dist/_vendor/platform-node/ipc.mjs +3 -273
  93. package/dist/_vendor/platform-node/ipc.mjs.map +1 -1
  94. package/dist/_vendor/platform-web/external-change.d.ts +2 -1
  95. package/dist/_vendor/platform-web/external-change.d.ts.map +1 -1
  96. package/dist/_vendor/platform-web/external-change.js +2 -1
  97. package/dist/_vendor/platform-web/external-change.js.map +1 -1
  98. package/dist/_vendor/platform-web/index.d.ts +21 -21
  99. package/dist/_vendor/platform-web/index.d.ts.map +1 -1
  100. package/dist/_vendor/platform-web/index.js +44 -7
  101. package/dist/_vendor/platform-web/index.js.map +1 -1
  102. package/dist/_vendor/platform-web/react.d.ts.map +1 -1
  103. package/dist/_vendor/platform-web/react.js +29 -13
  104. package/dist/_vendor/platform-web/react.js.map +1 -1
  105. package/dist/_vendor/platform-web/worker.d.ts +11 -35
  106. package/dist/_vendor/platform-web/worker.d.ts.map +1 -1
  107. package/dist/_vendor/platform-web/worker.js +3 -267
  108. package/dist/_vendor/platform-web/worker.js.map +1 -1
  109. package/dist/_vendor/react/index.d.ts +36 -20
  110. package/dist/_vendor/react/index.d.ts.map +1 -1
  111. package/dist/_vendor/react/index.js +279 -57
  112. package/dist/_vendor/react/index.js.map +1 -1
  113. package/dist/_vendor/schema/definition.d.ts +48 -63
  114. package/dist/_vendor/schema/definition.d.ts.map +1 -1
  115. package/dist/_vendor/schema/definition.js +22 -39
  116. package/dist/_vendor/schema/definition.js.map +1 -1
  117. package/dist/_vendor/schema/index.d.ts +4 -4
  118. package/dist/_vendor/schema/index.js +2 -2
  119. package/dist/_vendor/schema/planner.d.ts +19 -2
  120. package/dist/_vendor/schema/planner.d.ts.map +1 -1
  121. package/dist/_vendor/schema/planner.js +79 -3
  122. package/dist/_vendor/schema/planner.js.map +1 -1
  123. package/dist/_vendor/schema/validators.d.ts +141 -121
  124. package/dist/_vendor/schema/validators.d.ts.map +1 -1
  125. package/dist/_vendor/schema/validators.js +300 -42
  126. package/dist/_vendor/schema/validators.js.map +1 -1
  127. package/dist/_vendor/svelte/index.d.ts +47 -19
  128. package/dist/_vendor/svelte/index.d.ts.map +1 -1
  129. package/dist/_vendor/svelte/index.js +250 -20
  130. package/dist/_vendor/svelte/index.js.map +1 -1
  131. package/dist/components.d.ts +2 -0
  132. package/dist/components.js +2 -0
  133. package/dist/index.d.ts +3 -2
  134. package/dist/index.js +2 -1
  135. package/package.json +8 -3
@@ -1 +1 @@
1
- {"version":3,"file":"app.mjs","names":[],"sources":["../src/app.ts"],"sourcesContent":["import { mkdir, readdir, readFile, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { Command } from \"commander\";\nimport type { SyncoreDevtoolsSubscriptionResultPayload } from \"@syncore/devtools-protocol\";\nimport {\n createSchemaSnapshot,\n diffSchemaSnapshots,\n renderMigrationSql\n} from \"@syncore/core\";\nimport {\n type SyncoreTemplateName,\n VALID_SYNCORE_TEMPLATES,\n applyProjectMigrations,\n detectProjectTemplate,\n formatError,\n getNextMigrationNumber,\n hasSyncoreProject,\n isLocalPortInUse,\n loadProjectSchema,\n readStoredSnapshot,\n resolveRequestedTemplate,\n runCodegen,\n runDevProjectBootstrap,\n scaffoldProject,\n slugify,\n startDevHub,\n writeStoredSnapshot\n} from \"@syncore/core/cli\";\nimport { CliContext, type CliChoice, type GlobalCliOptions, openTarget } from \"./context.js\";\nimport { runShellCommand, printCompactDevPhase, printDevSessionIntro, withConsoleCapture } from \"./dev-session.js\";\nimport { buildDoctorReport } from \"./doctor.js\";\nimport { applyRootHelp } from \"./help.js\";\nimport {\n buildDevBootstrapNextSteps,\n buildInitNextSteps,\n buildTargetCommandNextSteps,\n buildHubUnavailableNextSteps,\n templateUsesConnectedClients\n} from \"./messages.js\";\nimport {\n buildRuntimeLookup,\n type ClientRuntimeLookupEntry,\n type ClientTargetDescriptor,\n type TargetCapability,\n connectToProjectHub,\n createPublicRuntimeId,\n createManagedProjectClient,\n exportProjectData,\n importProjectData,\n isKnownTemplate,\n listAvailableTargets,\n listConnectedClientTargets,\n listProjectTables,\n loadImportDocumentBatches,\n readProjectTable,\n resolveDashboardUrl,\n resolveDevtoolsUrl,\n resolveDocsTarget,\n resolveProjectFunction,\n targetSupportsCapability,\n writeExportData\n} from \"./project.js\";\nimport {\n type JsonLikeFormat,\n type PersistedLogEntry,\n printDevReadySummary,\n printDoctorReport,\n printTargetsTable,\n renderOutput\n} from \"./render.js\";\nimport { resolveClientRuntime, resolveOperationalTarget } from \"./targets.js\";\n\ninterface InitCommandOptions {\n template: SyncoreTemplateName | \"auto\";\n force?: boolean;\n}\n\ninterface DevCommandOptions {\n template: string;\n once?: boolean;\n openDashboard?: boolean;\n untilSuccess?: boolean;\n run?: string;\n runSh?: string;\n}\n\ninterface RunCommandOptions {\n watch?: boolean;\n format: JsonLikeFormat;\n target?: string;\n runtime?: string;\n}\n\ninterface DataCommandOptions {\n limit: string;\n order?: \"asc\" | \"desc\";\n format: JsonLikeFormat;\n target?: string;\n runtime?: string;\n watch?: boolean;\n}\n\ninterface ImportCommandOptions {\n table?: string;\n target?: string;\n runtime?: string;\n}\n\ninterface ExportCommandOptions {\n path: string;\n table?: string;\n target?: string;\n runtime?: string;\n}\n\ninterface LogsCommandOptions {\n target?: string;\n runtime?: string;\n limit: string;\n watch?: boolean;\n kind?: \"query\" | \"mutation\" | \"action\" | \"system\";\n format: JsonLikeFormat;\n}\n\ninterface TargetsCommandOptions {\n onlineOnly?: boolean;\n capability?: TargetCapability;\n}\n\ninterface OpenCommandOptions {\n open?: boolean;\n}\n\nexport async function runSyncoreCli(argv = process.argv): Promise<void> {\n const program = buildProgram();\n\n if (argv.length <= 2) {\n argv = [...argv, \"--help\"];\n }\n\n try {\n await program.parseAsync(argv);\n } catch (error) {\n const context = new CliContext(parseGlobalOptionsFromArgv(argv));\n context.handleError(error);\n }\n}\n\nexport function buildProgram(): Command {\n const program = new Command();\n program\n .name(\"syncorejs\")\n .usage(\"<command> [options]\")\n .option(\"--cwd <path>\", \"Run the command as if started from the given directory\")\n .option(\"--json\", \"Emit machine-readable JSON output\")\n .option(\"--verbose\", \"Print additional diagnostics\")\n .option(\"--no-interactive\", \"Disable prompts and terminal UX\")\n .option(\"-y, --yes\", \"Assume yes for confirmations\")\n .showHelpAfterError()\n .showSuggestionAfterError()\n .helpCommand(\"help <command>\", \"Show help for a command\");\n applyRootHelp(program);\n\n addInitCommand(program);\n addCodegenCommand(program);\n addDoctorCommand(program);\n addTargetsCommand(program);\n addDevCommand(program);\n addMigrateCommand(program);\n addRunCommand(program);\n addDataCommand(program);\n addImportCommand(program);\n addExportCommand(program);\n addLogsCommand(program);\n addDashboardCommand(program);\n addDocsCommand(program);\n\n return program;\n}\n\nfunction addInitCommand(program: Command): void {\n program\n .command(\"init\")\n .summary(\"Scaffold Syncore into the current project\")\n .description(\"Scaffold Syncore files, scripts, and generated types into the selected directory.\")\n .option(\n \"--template <template>\",\n `Template to scaffold (${VALID_SYNCORE_TEMPLATES.join(\", \")}, or auto)`,\n \"auto\"\n )\n .option(\"--force\", \"Overwrite Syncore-managed files\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs init\",\n \" npx syncorejs init --template react-web\",\n \" npx syncorejs init --cwd ./examples/my-app\"\n ].join(\"\\n\")\n )\n .action(async (options: InitCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (\n !options.force &&\n !(await isDirectoryEmpty(ctx.cwd)) &&\n !(await ctx.confirm(\n \"The target directory is not empty. Continue scaffolding into it?\",\n false\n ))\n ) {\n ctx.fail(\"Scaffolding cancelled by user.\", 1);\n }\n\n let template = options.template;\n if (template === \"auto\") {\n const detectedTemplate = await detectProjectTemplate(ctx.cwd);\n template =\n detectedTemplate === \"minimal\" && ctx.interactive\n ? await promptForTemplate(ctx, detectedTemplate)\n : detectedTemplate;\n }\n\n if (!isKnownTemplate(template)) {\n ctx.fail(\n `Unknown template ${JSON.stringify(template)}. Expected one of ${VALID_SYNCORE_TEMPLATES.join(\", \")} or auto.`\n );\n }\n const resolvedTemplate: SyncoreTemplateName = template;\n\n const result = await ctx.withSpinner(\"Scaffolding Syncore\", async () =>\n scaffoldProject(ctx.cwd, {\n template: resolvedTemplate,\n ...(options.force ? { force: true } : {})\n })\n );\n await ctx.withSpinner(\"Generating typed references\", async () =>\n runCodegen(ctx.cwd)\n );\n\n ctx.printResult({\n summary: `Syncore scaffolded with the ${resolvedTemplate} template.`,\n command: \"init\",\n data: result,\n nextSteps: buildInitNextSteps(resolvedTemplate)\n });\n\n if (!ctx.json) {\n printScaffoldChanges(ctx, result);\n }\n });\n });\n}\n\nfunction addCodegenCommand(program: Command): void {\n program\n .command(\"codegen\")\n .summary(\"Generate typed Syncore references\")\n .description(\"Regenerate syncore/_generated from the current syncore/functions tree.\")\n .addHelpText(\n \"after\",\n [\"\", \"Examples:\", \" npx syncorejs codegen\", \" npx syncorejs codegen --cwd ./apps/web\"].join(\n \"\\n\"\n )\n )\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n await ctx.withSpinner(\"Generating typed references\", async () =>\n runCodegen(ctx.cwd)\n );\n ctx.printResult({\n summary: \"Generated syncore/_generated files.\",\n command: \"codegen\"\n });\n });\n });\n}\n\nfunction addDoctorCommand(program: Command): void {\n program\n .command(\"doctor\")\n .summary(\"Inspect the current Syncore project state\")\n .description(\"Check project structure, template capabilities, hub state, and available targets.\")\n .addHelpText(\n \"after\",\n [\"\", \"Examples:\", \" npx syncorejs doctor\", \" npx syncorejs doctor --json\"].join(\"\\n\")\n )\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const report = await buildDoctorReport(ctx.cwd);\n if (ctx.json) {\n ctx.printResult({\n command: \"doctor\",\n data: report\n });\n return;\n }\n\n ctx.info(`Detected template: ${report.template}`);\n ctx.info(`Project status: ${report.status}`);\n ctx.info(\n `Project target: ${report.projectTarget ? report.projectTarget.databasePath : \"not configured\"}`\n );\n ctx.info(`Devtools hub: ${report.hub.running ? report.hub.url : \"not running\"}`);\n printDoctorReport(report, {\n verbose: ctx.verbose\n });\n if (report.workspaceMatches.length > 0) {\n ctx.warn(\"You appear to be at a workspace root instead of inside an app package.\");\n for (const match of report.workspaceMatches) {\n process.stdout.write(\n ` - ${match.relativePath} (${match.template}) -> use --cwd ${match.relativePath}\\n`\n );\n }\n }\n for (const suggestion of report.suggestions) {\n ctx.nextStep(suggestion);\n }\n });\n });\n}\n\nfunction addTargetsCommand(program: Command): void {\n program\n .command(\"targets\")\n .summary(\"List available Syncore targets\")\n .description(\"Inspect project and connected client targets for run, data, import, export, and logs.\")\n .option(\"--online-only\", \"Only show online targets\")\n .option(\n \"--capability <capability>\",\n \"Filter targets by capability: run, readData, writeData, exportData, streamLogs\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs targets\",\n \" npx syncorejs targets --capability run\",\n \" npx syncorejs targets --json\"\n ].join(\"\\n\")\n )\n .action(async (options: TargetsCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.capability && !isTargetCapability(options.capability)) {\n ctx.fail(\n `Unknown capability ${JSON.stringify(options.capability)}. Expected run, readData, writeData, exportData, or streamLogs.`\n );\n }\n const targets = await listAvailableTargets(ctx.cwd);\n const filtered = targets.filter((target) => {\n if (options.onlineOnly && !target.online) {\n return false;\n }\n if (options.capability && !targetSupportsCapability(target, options.capability)) {\n return false;\n }\n return true;\n });\n\n ctx.printResult({\n command: \"targets\",\n summary: `Found ${filtered.length} target(s).`,\n data: filtered,\n nextSteps: buildTargetCommandNextSteps(filtered[0]?.id)\n });\n\n if (!ctx.json) {\n printTargetsTable(filtered, {\n verbose: ctx.verbose\n });\n }\n });\n });\n}\n\nfunction addDevCommand(program: Command): void {\n program\n .command(\"dev\")\n .summary(\"Run the Syncore development loop\")\n .description(\n \"Bootstrap the local Syncore project, start the hub, discover targets, and keep the local workflow in sync.\"\n )\n .option(\n \"--template <template>\",\n `Template to scaffold when Syncore is missing (${VALID_SYNCORE_TEMPLATES.join(\", \")}, or auto)`,\n \"auto\"\n )\n .option(\"--once\", \"Run bootstrap once and exit\")\n .option(\"--until-success\", \"Retry bootstrap until it succeeds\")\n .option(\"--run <function>\", \"Run a Syncore function after bootstrap succeeds\")\n .option(\"--run-sh <command>\", \"Run a shell command after bootstrap succeeds\")\n .option(\"--open-dashboard\", \"Open the dashboard URL even in non-interactive mode\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs dev\",\n \" npx syncorejs dev --once\",\n \" npx syncorejs dev --until-success\",\n \" npx syncorejs dev --run tasks/list\",\n \" npx syncorejs dev --open-dashboard\",\n \" npx syncorejs dev --run-sh \\\"npm run dev\\\"\"\n ].join(\"\\n\")\n )\n .action(async (options: DevCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.run && options.runSh) {\n ctx.fail(\"`syncorejs dev` accepts either --run or --run-sh, not both.\");\n }\n const shouldOpenDashboard =\n Boolean(options.openDashboard) || isRealInteractiveTerminal(ctx);\n await ensureLocalPortConfiguration(ctx);\n\n const template = await resolveRequestedTemplate(ctx.cwd, options.template);\n printDevSessionIntro(ctx);\n await ensureDevProjectExists(ctx, template);\n\n if (options.once) {\n await runDevBootstrapLoop(ctx, template, options.untilSuccess ?? false);\n await runDevFollowup(ctx, options);\n const targets = await listAvailableTargets(ctx.cwd);\n ctx.printResult({\n summary: \"Syncore dev bootstrap completed.\",\n command: \"dev\",\n nextSteps: buildDevBootstrapNextSteps()\n });\n if (!ctx.json) {\n printDevReadySummary(ctx, {\n template,\n projectTargetConfigured: targets.some((target) => target.kind === \"project\"),\n dashboardUrl: resolveDashboardUrl(),\n devtoolsUrl: resolveDevtoolsUrl(),\n targets\n });\n }\n return;\n }\n\n await runDevBootstrapLoop(ctx, template, options.untilSuccess ?? false);\n const targets = await listAvailableTargets(ctx.cwd);\n printDevReadySummary(ctx, {\n template,\n projectTargetConfigured: targets.some((target) => target.kind === \"project\"),\n dashboardUrl: resolveDashboardUrl(),\n devtoolsUrl: resolveDevtoolsUrl(),\n targets\n });\n\n await startManagedDevHub(ctx, template);\n await maybeOpenDashboard(ctx, shouldOpenDashboard);\n await monitorLiveDevSession(ctx, template);\n });\n });\n}\n\nfunction isRealInteractiveTerminal(context: CliContext): boolean {\n return context.interactive && Boolean(process.stdin.isTTY && process.stdout.isTTY);\n}\n\nasync function maybeOpenDashboard(\n context: CliContext,\n shouldOpenDashboard: boolean\n): Promise<void> {\n if (!shouldOpenDashboard) {\n return;\n }\n const opened = await openTarget(resolveDashboardUrl());\n if (opened) {\n context.info(`Opened dashboard at ${resolveDashboardUrl()}.`);\n return;\n }\n context.warn(\"Unable to open the dashboard automatically.\");\n}\n\nfunction addMigrateCommand(program: Command): void {\n const migrate = program\n .command(\"migrate\")\n .summary(\"Generate and apply local SQL migrations\")\n .description(\"Work with schema diffs, migration SQL, and the local Syncore database.\");\n\n migrate\n .command(\"status\")\n .summary(\"Show the current schema diff status\")\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const schema = await loadProjectSchema(ctx.cwd);\n const currentSnapshot = createSchemaSnapshot(schema);\n const storedSnapshot = await readStoredSnapshot(ctx.cwd);\n const plan = diffSchemaSnapshots(storedSnapshot, currentSnapshot);\n\n ctx.printResult({\n summary: \"Migration status computed.\",\n command: \"migrate status\",\n data: {\n currentSchemaHash: currentSnapshot.hash,\n storedSchemaHash: storedSnapshot?.hash ?? null,\n statements: plan.statements,\n warnings: plan.warnings,\n destructiveChanges: plan.destructiveChanges\n }\n });\n\n if (!ctx.json) {\n process.stdout.write(`Current schema hash: ${currentSnapshot.hash}\\n`);\n process.stdout.write(`Stored snapshot: ${storedSnapshot?.hash ?? \"none\"}\\n`);\n process.stdout.write(`Statements to generate: ${plan.statements.length}\\n`);\n process.stdout.write(`Warnings: ${plan.warnings.length}\\n`);\n process.stdout.write(`Destructive changes: ${plan.destructiveChanges.length}\\n`);\n for (const warning of plan.warnings) {\n ctx.warn(warning);\n }\n for (const change of plan.destructiveChanges) {\n ctx.error(change);\n }\n }\n });\n });\n\n migrate\n .command(\"generate\")\n .argument(\"[name]\", \"Optional migration name\", \"auto\")\n .summary(\"Generate a SQL migration from the current schema diff\")\n .action(\n async (name: string, _options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const schema = await loadProjectSchema(ctx.cwd);\n const currentSnapshot = createSchemaSnapshot(schema);\n const storedSnapshot = await readStoredSnapshot(ctx.cwd);\n const plan = diffSchemaSnapshots(storedSnapshot, currentSnapshot);\n\n if (plan.destructiveChanges.length > 0) {\n ctx.fail(\n `Destructive schema changes require a manual migration: ${plan.destructiveChanges.join(\"; \")}`\n );\n }\n if (plan.statements.length === 0 && plan.warnings.length === 0) {\n ctx.printResult({\n summary: \"No schema changes detected.\"\n });\n return;\n }\n\n const migrationsDirectory = path.join(ctx.cwd, \"syncore\", \"migrations\");\n await mkdir(migrationsDirectory, { recursive: true });\n const migrationNumber = await getNextMigrationNumber(migrationsDirectory);\n const slug = slugify(name);\n const fileName = `${String(migrationNumber).padStart(4, \"0\")}_${slug}.sql`;\n const migrationSql = renderMigrationSql(plan, {\n title: `Syncore migration ${fileName}`\n });\n await writeFile(path.join(migrationsDirectory, fileName), migrationSql);\n await writeStoredSnapshot(ctx.cwd, currentSnapshot);\n\n ctx.printResult({\n summary: `Generated syncore/migrations/${fileName}.`,\n command: \"migrate generate\",\n data: {\n path: path.join(\"syncore\", \"migrations\", fileName),\n statements: plan.statements,\n warnings: plan.warnings\n },\n nextSteps: [\"Run `npx syncorejs migrate apply` to apply pending migrations.\"]\n });\n });\n }\n );\n\n migrate\n .command(\"apply\")\n .summary(\"Apply SQL migrations to the local database\")\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const appliedCount = await ctx.withSpinner(\"Applying migrations\", async () =>\n applyProjectMigrations(ctx.cwd)\n );\n ctx.printResult({\n summary: `Applied ${appliedCount} migration(s).`,\n command: \"migrate apply\"\n });\n });\n });\n}\n\nfunction addRunCommand(program: Command): void {\n program\n .command(\"run\")\n .summary(\"Run a local Syncore function\")\n .description(\"Execute a query, mutation, or action against the local runtime.\")\n .argument(\"<functionName>\", \"Function name like tasks/list or api.tasks.list\")\n .argument(\"[args]\", \"JSON object of arguments\", \"{}\")\n .option(\"--watch\", \"Watch a query for local changes\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .option(\n \"--format <format>\",\n \"Output format: pretty, json, or jsonl\",\n \"pretty\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs run tasks/list\",\n \" npx syncorejs run api.tasks.create '{\\\"text\\\":\\\"Ship Syncore\\\"}' --target project\",\n \" npx syncorejs run tasks/list --watch --target 10427 --runtime 20318 --format json\"\n ].join(\"\\n\")\n )\n .action(\n async (\n functionName: string,\n argsText: string,\n options: RunCommandOptions,\n command: Command\n ) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs run --runtime` requires --target.\");\n }\n const resolved = await resolveProjectFunction(ctx.cwd, functionName);\n const args = parseJsonObject(argsText, \"Function arguments\");\n\n if (options.watch && resolved.definition.kind !== \"query\") {\n ctx.fail(\"`syncorejs run --watch` only supports query functions.\");\n }\n\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"run\",\n capability: \"run\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"run\"\n });\n ctx.info(\n options.watch\n ? `Watching ${resolved.name} on ${target.id}${runtime ? ` (${runtime.id} ${runtime.label})` : \"\"}.`\n : `Running ${resolved.name} on ${target.id}${runtime ? ` (${runtime.id} ${runtime.label})` : \"\"}.`\n );\n if (target.kind === \"project\") {\n const managed = await createManagedProjectClient(ctx.cwd);\n try {\n if (options.watch) {\n const watch = managed.client.watchQuery(\n resolved.reference as never,\n args\n );\n const render = () => {\n const error = watch.localQueryError();\n if (error) {\n ctx.handleError(error);\n return;\n }\n renderOutput(ctx, watch.localQueryResult(), options.format);\n };\n const unsubscribe = watch.onUpdate(render);\n ctx.info(\"Watching query. Press Ctrl+C to stop.\");\n await waitForSignal();\n unsubscribe();\n watch.dispose?.();\n return;\n }\n\n const result =\n resolved.definition.kind === \"query\"\n ? await managed.client.query(resolved.reference as never, args)\n : resolved.definition.kind === \"mutation\"\n ? await managed.client.mutation(\n resolved.reference as never,\n args\n )\n : await managed.client.action(resolved.reference as never, args);\n\n renderOutput(ctx, result, options.format);\n return;\n } finally {\n await managed.dispose();\n }\n }\n\n const hub = await requireHubConnection(ctx);\n try {\n if (options.watch) {\n const unsubscribe = hub.subscribe(runtime!.runtimeId, {\n kind: \"fn.watch\",\n functionName: resolved.name,\n functionType: \"query\",\n args\n }, {\n onData(payload) {\n if (payload.kind !== \"fn.watch.result\") {\n return;\n }\n if (payload.error) {\n ctx.handleError(new Error(payload.error));\n return;\n }\n renderOutput(ctx, payload.result, options.format);\n },\n onError(error) {\n ctx.handleError(new Error(error));\n }\n });\n ctx.info(`Watching query on ${target.id}. Press Ctrl+C to stop.`);\n await waitForSignal();\n unsubscribe();\n return;\n }\n\n const result = await hub.sendCommand(runtime!.runtimeId, {\n kind: \"fn.run\",\n functionName: resolved.name,\n functionType: resolved.definition.kind,\n args\n });\n if (result.kind === \"fn.run.result\") {\n if (result.error) {\n ctx.fail(result.error);\n }\n renderOutput(ctx, result.result, options.format);\n return;\n }\n if (result.kind === \"error\") {\n ctx.fail(result.message, 1, result);\n }\n ctx.fail(`Unexpected response from ${target.id}.`, 1, result);\n } finally {\n await hub.dispose();\n }\n });\n }\n );\n}\n\nfunction addDataCommand(program: Command): void {\n program\n .command(\"data\")\n .summary(\"Inspect local Syncore data\")\n .description(\"List tables or print local rows from a specific table.\")\n .argument(\"[table]\", \"Optional table to inspect\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .option(\"--limit <n>\", \"Maximum rows to print\", \"100\")\n .option(\"--order <choice>\", \"Order by _creationTime\", \"desc\")\n .option(\"--watch\", \"Watch a table for changes on the selected target\")\n .option(\n \"--format <format>\",\n \"Output format: pretty, json, or jsonl\",\n \"pretty\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs data\",\n \" npx syncorejs data tasks --target project --limit 10\",\n \" npx syncorejs data tasks --target 10427 --runtime 20318 --watch --format jsonl\"\n ].join(\"\\n\")\n )\n .action(\n async (\n table: string | undefined,\n options: DataCommandOptions,\n command: Command\n ) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs data --runtime` requires --target.\");\n }\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"data\",\n capability: \"readData\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"data\"\n });\n if (!table) {\n const tables =\n target.kind === \"project\"\n ? await listProjectTables(ctx.cwd)\n : await listRemoteTables(runtime!.runtimeId, ctx);\n ctx.printResult({\n summary: `Found ${tables.length} table(s) on ${target.id}.`,\n command: \"data\",\n data: tables,\n target: target.id\n });\n if (!ctx.json) {\n for (const entry of tables) {\n process.stdout.write(\n ` ${entry.name} (${entry.documentCount} document(s))\\n`\n );\n }\n }\n return;\n }\n\n if (target.kind === \"project\") {\n const payload = await readProjectTable(ctx.cwd, table, {\n limit: Number.parseInt(options.limit, 10),\n order: options.order === \"asc\" ? \"asc\" : \"desc\"\n });\n renderOutput(ctx, payload.rows, options.format);\n return;\n }\n\n const hub = await requireHubConnection(ctx);\n try {\n const payload = await readRemoteTable(hub, runtime!.runtimeId, table, {\n limit: Number.parseInt(options.limit, 10)\n });\n renderOutput(ctx, payload.rows, options.format);\n\n if (!options.watch) {\n return;\n }\n\n const unsubscribe = hub.subscribe(runtime!.runtimeId, {\n kind: \"data.table\",\n table,\n limit: Number.parseInt(options.limit, 10)\n }, {\n onData(result) {\n if (result.kind !== \"data.table.result\") {\n return;\n }\n renderOutput(ctx, result.rows, options.format);\n },\n onError(error) {\n ctx.handleError(new Error(error));\n }\n });\n ctx.info(\n `Watching table ${table} on ${target.id} (${runtime!.id} ${runtime!.label}). Press Ctrl+C to stop.`\n );\n await waitForSignal();\n unsubscribe();\n } finally {\n await hub.dispose();\n }\n });\n }\n );\n}\n\nfunction addImportCommand(program: Command): void {\n program\n .command(\"import\")\n .summary(\"Import local data into Syncore\")\n .description(\"Import JSON, JSONL, directory, or ZIP data into the local Syncore database.\")\n .argument(\"<path>\", \"Path to a .json, .jsonl, directory, or .zip input\")\n .option(\"--table <table>\", \"Destination table for single-file imports\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs import --table tasks sample.jsonl --target project\",\n \" npx syncorejs import --table tasks sample.json --target 10427 --runtime 20318\",\n \" npx syncorejs import backups/export.zip\"\n ].join(\"\\n\")\n )\n .action(\n async (\n sourcePath: string,\n options: ImportCommandOptions,\n command: Command\n ) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs import --runtime` requires --target.\");\n }\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"import\",\n capability: \"writeData\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"import\"\n });\n const preview = await previewImportPlan(ctx, sourcePath, options, target.id);\n if (\n ctx.interactive &&\n !(await ctx.confirm(\n `Import ${preview.totalRows} row(s) into ${target.id}?`,\n true\n ))\n ) {\n ctx.fail(\"Import cancelled by user.\");\n }\n const imported =\n target.kind === \"project\"\n ? await ctx.withSpinner(\"Importing local data\", async () =>\n importProjectData(ctx.cwd, sourcePath, {\n ...(options.table ? { table: options.table } : {})\n })\n )\n : await ctx.withSpinner(`Importing data into ${target.id}`, async () =>\n importIntoClientTarget(ctx, target, runtime!, sourcePath, options)\n );\n ctx.printResult({\n summary: `Imported ${imported.reduce((sum, entry) => sum + entry.importedCount, 0)} row(s).`,\n command: \"import\",\n data: imported,\n target: target.id\n });\n if (!ctx.json) {\n for (const entry of imported) {\n process.stdout.write(\n ` ${entry.table}: ${entry.importedCount} row(s)\\n`\n );\n }\n }\n });\n }\n );\n}\n\nfunction addExportCommand(program: Command): void {\n program\n .command(\"export\")\n .summary(\"Export local Syncore data\")\n .description(\"Export one or more local tables to JSON, JSONL, a directory, or a ZIP file.\")\n .requiredOption(\"--path <path>\", \"Output path (.json, .jsonl, directory, or .zip)\")\n .option(\"--table <table>\", \"Export a single table\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs export --table tasks --path tasks.jsonl --target project\",\n \" npx syncorejs export --path ./exports --target 10427 --runtime 20318\",\n \" npx syncorejs export --path ./exports.zip\"\n ].join(\"\\n\")\n )\n .action(async (options: ExportCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs export --runtime` requires --target.\");\n }\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"export\",\n capability: \"exportData\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"export\"\n });\n const result =\n target.kind === \"project\"\n ? await ctx.withSpinner(\"Exporting local data\", async () =>\n exportProjectData(ctx.cwd, options.path, {\n ...(options.table ? { table: options.table } : {})\n })\n )\n : await ctx.withSpinner(`Exporting data from ${target.id}`, async () =>\n exportClientTargetData(ctx, target, runtime!, options)\n );\n ctx.printResult({\n summary: `Exported ${result.tables.length} table(s) to ${result.path}.`,\n command: \"export\",\n data: result,\n target: target.id\n });\n });\n });\n}\n\nfunction addLogsCommand(program: Command): void {\n program\n .command(\"logs\")\n .summary(\"Inspect Syncore runtime logs\")\n .description(\"Read persisted hub logs and optionally watch live runtime events.\")\n .option(\"--target <target>\", \"Target id, or all\", \"all\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .option(\"--limit <n>\", \"Maximum log lines to print\", \"100\")\n .option(\"--watch\", \"Stream new logs from the local devtools hub\")\n .option(\"--kind <kind>\", \"Filter by event kind: query, mutation, action, system\")\n .option(\"--format <format>\", \"Output format: pretty, json, or jsonl\", \"pretty\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs logs\",\n \" npx syncorejs logs --target 10427 --runtime 20318 --watch\",\n \" npx syncorejs logs --kind mutation --format jsonl\"\n ].join(\"\\n\")\n )\n .action(async (options: LogsCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && (!options.target || options.target === \"all\")) {\n ctx.fail(\"`syncorejs logs --runtime` requires a specific --target.\");\n }\n await runLogsCommand(ctx, options);\n });\n });\n}\n\nfunction addDashboardCommand(program: Command): void {\n program\n .command(\"dashboard\")\n .summary(\"Print or open the local dashboard URL\")\n .description(\"Show the local Syncore dashboard URL, optionally opening it in the browser.\")\n .option(\"--open\", \"Open the dashboard URL\")\n .action(async (options: OpenCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const url = resolveDashboardUrl();\n if (options.open) {\n const opened = await openTarget(url);\n if (!opened) {\n ctx.warn(\"Unable to open the dashboard automatically.\");\n }\n }\n ctx.printResult({\n summary: \"Dashboard URL resolved.\",\n command: \"dashboard\",\n data: { url },\n nextSteps: [`Open ${url}`]\n });\n });\n });\n}\n\nfunction addDocsCommand(program: Command): void {\n program\n .command(\"docs\")\n .summary(\"Print or open the most relevant Syncore docs\")\n .description(\"Resolve the best local docs target for the detected template and optionally open it.\")\n .option(\"--open\", \"Open the docs target\")\n .action(async (options: OpenCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const url = await resolveDocsTarget(ctx.cwd);\n if (options.open) {\n const opened = await openTarget(url);\n if (!opened) {\n ctx.warn(\"Unable to open the docs target automatically.\");\n }\n }\n ctx.printResult({\n summary: \"Docs target resolved.\",\n command: \"docs\",\n data: { url }\n });\n });\n });\n}\n\nfunction createContext(command: Command): CliContext {\n const options = command.optsWithGlobals<GlobalCliOptions>();\n return new CliContext(options);\n}\n\nasync function executeCommand(\n context: CliContext,\n action: () => Promise<void>\n): Promise<void> {\n try {\n await action();\n } catch (error) {\n context.handleError(error);\n }\n}\n\nasync function ensureDevProjectExists(\n context: CliContext,\n template: SyncoreTemplateName\n): Promise<void> {\n if (await hasSyncoreProject(context.cwd)) {\n return;\n }\n\n if (!context.interactive) {\n context.fail(\n \"No Syncore project was found in this directory. Run `npx syncorejs init` first or rerun in an interactive terminal.\"\n );\n }\n\n const shouldScaffold = await context.confirm(\n \"No Syncore project was found. Scaffold one now?\",\n true\n );\n if (!shouldScaffold) {\n context.fail(\"Syncore dev cancelled because no project exists.\");\n }\n\n const result = await context.withSpinner(\"Scaffolding Syncore\", async () =>\n scaffoldProject(context.cwd, {\n template\n })\n );\n if (!context.json) {\n printScaffoldChanges(context, result);\n }\n}\n\ntype ConnectedHub = NonNullable<Awaited<ReturnType<typeof connectToProjectHub>>>;\n\nasync function ensureLocalPortConfiguration(context: CliContext): Promise<void> {\n const dashboardUrl = resolveDashboardUrl();\n const devtoolsUrl = resolveDevtoolsUrl();\n const dashboardPort = Number.parseInt(new URL(dashboardUrl).port, 10);\n const devtoolsPort = Number.parseInt(new URL(devtoolsUrl).port, 10);\n\n if (\n Number.isFinite(dashboardPort) &&\n Number.isFinite(devtoolsPort) &&\n dashboardPort === devtoolsPort\n ) {\n context.fail(\n [\n `Dashboard and devtools cannot share the same port (${dashboardPort}).`,\n \"Set different values for SYNCORE_DASHBOARD_PORT and SYNCORE_DEVTOOLS_PORT, then rerun `npx syncorejs dev`.\"\n ].join(\" \")\n );\n }\n\n if (\n Number.isFinite(dashboardPort) &&\n dashboardPort > 0 &&\n Number.isFinite(devtoolsPort) &&\n devtoolsPort > 0 &&\n (await isLocalPortInUse(dashboardPort)) &&\n !(await isLocalPortInUse(devtoolsPort))\n ) {\n context.warn(\n `Dashboard port ${dashboardPort} is already in use. If Syncore does not start cleanly, set SYNCORE_DASHBOARD_PORT to a different value.`\n );\n }\n}\n\nasync function runDevBootstrapLoop(\n context: CliContext,\n template: SyncoreTemplateName,\n untilSuccess: boolean\n): Promise<void> {\n while (true) {\n try {\n printCompactDevPhase(context, \"Project\");\n printCompactDevPhase(context, \"Codegen\");\n printCompactDevPhase(context, \"Schema\");\n await withConsoleCapture(\n (method, message) => {\n if (/destructive schema changes/i.test(message)) {\n context.error(\"Syncore dev blocked by destructive schema changes.\");\n return;\n }\n if (/Syncore dev warning:/i.test(message) || method === \"warn\") {\n context.warn(message.replace(/^Syncore dev warning:\\s*/i, \"\"));\n return;\n }\n if (/bootstrap failed/i.test(message) || method === \"error\") {\n context.error(message);\n }\n },\n async () => runDevProjectBootstrap(context.cwd, template)\n );\n return;\n } catch (error) {\n if (!untilSuccess) {\n throw error;\n }\n context.warn(`Syncore dev bootstrap failed, retrying: ${formatError(error)}`);\n await new Promise((resolve) => setTimeout(resolve, 1200));\n }\n }\n}\n\nasync function startManagedDevHub(\n context: CliContext,\n template: SyncoreTemplateName\n): Promise<void> {\n printCompactDevPhase(context, \"Hub\");\n printCompactDevPhase(context, \"Targets\");\n await withConsoleCapture(\n (method, message) => {\n if (/already running/i.test(message)) {\n context.info(message.replaceAll(\"127.0.0.1\", \"localhost\"));\n return;\n }\n if (/Dashboard shell:/i.test(message) || /devtools hub:/i.test(message)) {\n return;\n }\n if (/Watching syncore\\//i.test(message)) {\n context.info(\"Watching syncore/ for changes.\");\n return;\n }\n if (/runtime\\.disconnected/i.test(message)) {\n context.warn(message);\n return;\n }\n if (method === \"warn\") {\n context.warn(message);\n return;\n }\n if (method === \"error\") {\n context.error(message);\n }\n },\n async () =>\n startDevHub({\n cwd: context.cwd,\n template\n })\n );\n}\n\nasync function runDevFollowup(\n context: CliContext,\n options: DevCommandOptions\n): Promise<void> {\n if (options.run) {\n const target = await resolveOperationalTarget(context, undefined, {\n command: \"run\",\n capability: \"run\"\n });\n const resolved = await resolveProjectFunction(context.cwd, options.run);\n if (target.kind === \"project\") {\n const managed = await createManagedProjectClient(context.cwd);\n try {\n const result =\n resolved.definition.kind === \"query\"\n ? await managed.client.query(resolved.reference as never, {})\n : resolved.definition.kind === \"mutation\"\n ? await managed.client.mutation(resolved.reference as never, {})\n : await managed.client.action(resolved.reference as never, {});\n renderOutput(context, result, \"pretty\");\n } finally {\n await managed.dispose();\n }\n } else {\n const hub = await requireHubConnection(context);\n try {\n const result =\n await hub.sendCommand(target.runtimeId, {\n kind: \"fn.run\",\n functionName: resolved.name,\n functionType: resolved.definition.kind,\n args: {}\n });\n if (result.kind !== \"fn.run.result\") {\n context.fail(`Unexpected response from ${target.id}.`, 1, result);\n }\n if (result.error) {\n context.fail(result.error, 1, result);\n }\n renderOutput(context, result.result, \"pretty\");\n } finally {\n await hub.dispose();\n }\n }\n }\n\n if (options.runSh) {\n await runShellCommand(context, options.runSh);\n }\n}\n\nasync function monitorLiveDevSession(\n context: CliContext,\n template: SyncoreTemplateName\n): Promise<void> {\n if (!templateUsesConnectedClients(template)) {\n await waitForSignal();\n return;\n }\n\n let knownTargets = new Set<string>();\n let waitingNoticeVisible = false;\n const refreshTargets = async () => {\n const nextTargets = await listConnectedClientTargets();\n const nextIds = new Set(nextTargets.map((target) => target.id));\n\n for (const target of nextTargets) {\n if (!knownTargets.has(target.id)) {\n context.info(`Client target connected: ${target.id}`);\n }\n }\n for (const targetId of knownTargets) {\n if (!nextIds.has(targetId)) {\n context.warn(`Client target disconnected: ${targetId}`);\n }\n }\n\n if (nextTargets.length === 0 && !waitingNoticeVisible) {\n context.info(\"Hub ready. Start your app to connect a client target.\");\n waitingNoticeVisible = true;\n } else if (nextTargets.length > 0) {\n waitingNoticeVisible = false;\n }\n\n knownTargets = nextIds;\n };\n\n await refreshTargets();\n const interval = setInterval(() => {\n void refreshTargets();\n }, 1500);\n\n try {\n await waitForSignal();\n } finally {\n clearInterval(interval);\n }\n}\n\nasync function requireHubConnection(context: CliContext): Promise<ConnectedHub> {\n const hub = await connectToProjectHub();\n if (!hub) {\n context.fail(\n \"The local devtools hub is not running.\",\n 1,\n undefined,\n {\n category: \"hub\",\n nextSteps: buildHubUnavailableNextSteps()\n }\n );\n }\n return hub;\n}\n\nasync function listRemoteTables(\n runtimeId: string,\n context: CliContext\n): Promise<Array<{ name: string; documentCount: number }>> {\n const hub = await requireHubConnection(context);\n try {\n const result = await subscribeOnce(hub, runtimeId, {\n kind: \"schema.tables\"\n });\n if (result.kind !== \"schema.tables.result\") {\n context.fail(\"Unexpected response while listing remote tables.\", 1, result);\n }\n return result.tables.map((table) => ({\n name: table.name,\n documentCount: table.documentCount\n }));\n } finally {\n await hub.dispose();\n }\n}\n\nasync function readRemoteTable(\n hub: ConnectedHub,\n runtimeId: string,\n table: string,\n options: {\n limit: number;\n }\n): Promise<Extract<\n Awaited<ReturnType<typeof subscribeOnce>>,\n { kind: \"data.table.result\" }\n>> {\n const result = await subscribeOnce(hub, runtimeId, {\n kind: \"data.table\",\n table,\n limit: options.limit\n });\n if (result.kind !== \"data.table.result\") {\n throw new Error(`Unexpected response while reading table ${table}.`);\n }\n return result;\n}\n\nasync function importIntoClientTarget(\n context: CliContext,\n target: ClientTargetDescriptor,\n runtime: ClientTargetDescriptor[\"runtimes\"][number],\n sourcePath: string,\n options: ImportCommandOptions\n): Promise<Array<{ table: string; importedCount: number }>> {\n const batches = await loadImportDocumentBatches(context.cwd, sourcePath, {\n ...(options.table ? { table: options.table } : {})\n });\n const hub = await requireHubConnection(context);\n try {\n const results: Array<{ table: string; importedCount: number }> = [];\n for (const batch of batches) {\n let importedCount = 0;\n for (const row of batch.rows) {\n const payload = { ...row };\n delete payload._id;\n delete payload._creationTime;\n const result = await hub.sendCommand(runtime.runtimeId, {\n kind: \"data.insert\",\n table: batch.table,\n document: payload\n });\n if (result.kind !== \"data.mutate.result\" || !result.success) {\n const message =\n result.kind === \"data.mutate.result\"\n ? result.error ?? `Failed to import into ${batch.table}.`\n : `Unexpected response while importing into ${batch.table}.`;\n context.fail(message, 1, result);\n }\n importedCount += 1;\n }\n results.push({\n table: batch.table,\n importedCount\n });\n }\n return results;\n } finally {\n await hub.dispose();\n }\n}\n\nasync function exportClientTargetData(\n context: CliContext,\n target: ClientTargetDescriptor,\n runtime: ClientTargetDescriptor[\"runtimes\"][number],\n options: ExportCommandOptions\n): Promise<{\n path: string;\n tables: string[];\n format: \"json\" | \"jsonl\" | \"directory\" | \"zip\";\n}> {\n const hub = await requireHubConnection(context);\n try {\n const tables = options.table\n ? [options.table]\n : (await listRemoteTables(runtime.runtimeId, context)).map(\n (entry: { name: string }) => entry.name\n );\n const payloads = await Promise.all(\n tables.map(async (table) => ({\n table,\n rows: (await readRemoteTable(hub, runtime.runtimeId, table, {\n limit: Number.MAX_SAFE_INTEGER\n })).rows\n }))\n );\n return await writeExportData(path.resolve(context.cwd, options.path), payloads);\n } finally {\n await hub.dispose();\n }\n}\n\nasync function runLogsCommand(\n context: CliContext,\n options: LogsCommandOptions\n): Promise<void> {\n const availableTargets = await listAvailableTargets(context.cwd);\n const runtimeLookup = buildRuntimeLookup(availableTargets);\n const selectedTarget =\n options.target && options.target !== \"all\"\n ? availableTargets.find((target) => target.id === options.target)\n : undefined;\n if (options.target && options.target !== \"all\" && !selectedTarget) {\n context.fail(\n `Unknown target ${JSON.stringify(options.target)}. Available targets: ${availableTargets.map((target) => target.id).join(\", \")}`\n );\n }\n const selectedRuntime = selectedTarget\n ? resolveClientRuntime(selectedTarget, options.runtime, {\n command: \"logs\"\n })\n : null;\n const allowedRuntimeIds =\n selectedTarget?.kind === \"client\" ? new Set(selectedTarget.runtimeIds) : undefined;\n const entries = await readPersistedLogs(context.cwd);\n const filtered = entries\n .map((entry) => decoratePersistedLogEntry(entry, runtimeLookup))\n .filter((entry) =>\n options.target && options.target !== \"all\"\n ? entry.targetId === options.target ||\n (allowedRuntimeIds ? allowedRuntimeIds.has(entry.runtimeId) : false)\n : true\n )\n .filter((entry) =>\n selectedRuntime ? entry.runtimeId === selectedRuntime.runtimeId : true\n )\n .filter((entry) => (options.kind ? entry.category === options.kind : true))\n .slice(-Number.parseInt(options.limit, 10));\n\n renderOutput(context, filtered, options.format);\n\n if (!options.watch) {\n return;\n }\n\n const hub = await requireHubConnection(context);\n const unsubscribe = hub.onEvent((event) => {\n const entry = normalizeRuntimeEvent(\n event,\n runtimeLookup.get(event.runtimeId)\n );\n if (!entry) {\n return;\n }\n if (\n options.target &&\n options.target !== \"all\" &&\n entry.targetId !== options.target &&\n !(allowedRuntimeIds ? allowedRuntimeIds.has(entry.runtimeId) : false)\n ) {\n return;\n }\n if (options.kind && entry.category !== options.kind) {\n return;\n }\n if (selectedRuntime && entry.runtimeId !== selectedRuntime.runtimeId) {\n return;\n }\n renderOutput(context, entry, options.format);\n });\n context.info(\"Streaming logs. Press Ctrl+C to stop.\");\n await waitForSignal();\n unsubscribe();\n await hub.dispose();\n}\n\nasync function readPersistedLogs(cwd: string): Promise<PersistedLogEntry[]> {\n const logPath = path.join(cwd, \".syncore\", \"logs\", \"runtime.jsonl\");\n try {\n await stat(logPath);\n } catch {\n return [];\n }\n\n const source = await readFile(logPath, \"utf8\");\n return source\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter(Boolean)\n .map((line) => JSON.parse(line) as PersistedLogEntry)\n .filter((entry) => entry.version === 2)\n .filter((entry) => !shouldSuppressLogEntry(entry));\n}\n\nfunction normalizeRuntimeEvent(\n event: Record<string, unknown> & { type: string; runtimeId: string; timestamp: number },\n runtimeEntry?: ClientRuntimeLookupEntry\n): PersistedLogEntry | null {\n const functionName =\n typeof event.functionName === \"string\" ? event.functionName : \"unknown\";\n const logMessage =\n typeof event.message === \"string\" ? event.message : \"Syncore log\";\n const resolvedTargetId =\n event.runtimeId === \"syncore-dev-hub\"\n ? \"all\"\n : (runtimeEntry?.targetId ?? event.runtimeId);\n const runtimeLabel =\n event.runtimeId === \"syncore-dev-hub\"\n ? \"dashboard\"\n : (runtimeEntry?.label ?? \"runtime\");\n const publicRuntimeId =\n event.runtimeId === \"syncore-dev-hub\"\n ? undefined\n : (runtimeEntry?.id ?? createPublicRuntimeId(event.runtimeId));\n const targetLabel = runtimeEntry?.targetLabel;\n const origin =\n event.origin === \"dashboard\" || event.runtimeId === \"syncore-dev-hub\"\n ? \"dashboard\"\n : \"runtime\";\n const entryBase = {\n timestamp: event.timestamp,\n runtimeId: event.runtimeId,\n targetId: resolvedTargetId,\n ...(targetLabel ? { targetLabel } : {}),\n ...(publicRuntimeId ? { publicRuntimeId } : {}),\n ...(runtimeLabel ? { runtimeLabel } : {}),\n origin\n } satisfies Pick<\n PersistedLogEntry,\n | \"timestamp\"\n | \"runtimeId\"\n | \"targetId\"\n | \"targetLabel\"\n | \"publicRuntimeId\"\n | \"runtimeLabel\"\n | \"origin\"\n >;\n\n if (\n event.type === \"log\" &&\n shouldSuppressLogEntry({\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: logMessage,\n event\n })\n ) {\n return null;\n }\n\n switch (event.type) {\n case \"query.executed\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"query\",\n message: `${functionName} executed`,\n event\n };\n case \"query.invalidated\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: `${formatInvalidatedQueryId(event.queryId)} invalidated${typeof event.reason === \"string\" ? ` (${event.reason})` : \"\"}`,\n event\n };\n case \"mutation.committed\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"mutation\",\n message:\n Array.isArray(event.changedTables) && event.changedTables.length > 0\n ? `${functionName} committed (${event.changedTables.join(\", \")})`\n : `${functionName} committed`,\n event\n };\n case \"action.completed\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"action\",\n message:\n typeof event.error === \"string\" && event.error.length > 0\n ? `${functionName} failed: ${event.error}`\n : `${functionName} completed`,\n event\n };\n case \"runtime.connected\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: `${publicRuntimeId ?? \"runtime\"} ${runtimeLabel} connected`,\n event\n };\n case \"runtime.disconnected\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: `${publicRuntimeId ?? \"runtime\"} ${runtimeLabel} disconnected`,\n event\n };\n case \"storage.updated\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: `${typeof event.operation === \"string\" ? event.operation : \"update\"} ${typeof event.storageId === \"string\" ? event.storageId : \"storage\"}`,\n event\n };\n default:\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: event.type === \"log\" ? logMessage : humanizeRuntimeEvent(event),\n event\n };\n }\n}\n\nfunction decoratePersistedLogEntry(\n entry: PersistedLogEntry,\n runtimeLookup: ReturnType<typeof buildRuntimeLookup>\n): PersistedLogEntry {\n const runtime = runtimeLookup.get(entry.runtimeId);\n return {\n ...entry,\n targetId:\n entry.targetId === \"all\"\n ? \"all\"\n : runtime?.targetId ?? entry.targetId ?? entry.runtimeId,\n ...(runtime?.targetLabel ? { targetLabel: runtime.targetLabel } : {}),\n ...(runtime?.id ? { publicRuntimeId: runtime.id } : {}),\n ...(runtime?.label ? { runtimeLabel: runtime.label } : {}),\n ...(entry.origin ? {} : { origin: entry.runtimeId === \"syncore-dev-hub\" ? \"dashboard\" : \"runtime\" })\n };\n}\n\nfunction shouldSuppressLogEntry(entry: PersistedLogEntry): boolean {\n return (\n entry.eventType === \"log\" &&\n /syncore devtools hub is alive/i.test(entry.message)\n );\n}\n\nfunction formatInvalidatedQueryId(queryId: unknown): string {\n if (typeof queryId !== \"string\" || queryId.length === 0) {\n return \"query\";\n }\n const separatorIndex = queryId.indexOf(\":\");\n if (separatorIndex === -1) {\n return queryId;\n }\n return queryId.slice(0, separatorIndex);\n}\n\nfunction humanizeRuntimeEvent(\n event: Record<string, unknown> & { type: string }\n): string {\n if (event.type === \"scheduler.tick\" && Array.isArray(event.executedJobIds)) {\n return `scheduler tick (${event.executedJobIds.length} job(s))`;\n }\n return event.type.replaceAll(\".\", \" \");\n}\n\nasync function subscribeOnce(\n hub: ConnectedHub,\n runtimeId: string,\n payload: Parameters<ConnectedHub[\"subscribe\"]>[1]\n): Promise<SyncoreDevtoolsSubscriptionResultPayload> {\n return await new Promise((resolve, reject) => {\n const unsubscribe = hub.subscribe(runtimeId, payload, {\n onData(result) {\n unsubscribe();\n resolve(result);\n },\n onError(error) {\n unsubscribe();\n reject(new Error(error));\n }\n });\n });\n}\n\nasync function promptForTemplate(\n context: CliContext,\n detectedTemplate: string\n): Promise<SyncoreTemplateName> {\n const choices: CliChoice<SyncoreTemplateName>[] = VALID_SYNCORE_TEMPLATES.map(\n (template) =>\n template === detectedTemplate\n ? {\n label: template,\n value: template,\n description: \"Detected from the current project\"\n }\n : {\n label: template,\n value: template\n }\n );\n return await context.select(\n \"Choose a Syncore template for this directory.\",\n choices,\n isKnownTemplate(detectedTemplate) ? detectedTemplate : VALID_SYNCORE_TEMPLATES[0]\n );\n}\n\nasync function isDirectoryEmpty(directory: string): Promise<boolean> {\n try {\n const entries = await readdir(directory);\n return entries.length === 0;\n } catch {\n return true;\n }\n}\n\nfunction printScaffoldChanges(\n context: CliContext,\n result: Awaited<ReturnType<typeof scaffoldProject>>\n): void {\n if (result.created.length > 0) {\n context.info(`Created: ${result.created.join(\", \")}`);\n }\n if (result.updated.length > 0) {\n context.info(`Updated: ${result.updated.join(\", \")}`);\n }\n if (result.skipped.length > 0) {\n context.warn(`Kept existing: ${result.skipped.join(\", \")}`);\n }\n}\n\nfunction isTargetCapability(value: string): value is TargetCapability {\n return (\n value === \"run\" ||\n value === \"readData\" ||\n value === \"writeData\" ||\n value === \"exportData\" ||\n value === \"streamLogs\"\n );\n}\n\nasync function previewImportPlan(\n context: CliContext,\n sourcePath: string,\n options: ImportCommandOptions,\n targetId: string\n): Promise<{\n target: string;\n format: string;\n totalRows: number;\n batches: Array<{ table: string; rowCount: number }>;\n}> {\n const batches = await loadImportDocumentBatches(context.cwd, sourcePath, {\n ...(options.table ? { table: options.table } : {})\n });\n const preview = {\n target: targetId,\n format: path.extname(sourcePath).toLowerCase() || \"directory\",\n totalRows: batches.reduce((sum, batch) => sum + batch.rows.length, 0),\n batches: batches.map((batch) => ({\n table: batch.table,\n rowCount: batch.rows.length\n }))\n };\n\n if (!context.json && context.interactive) {\n process.stdout.write(\"Import preview:\\n\");\n process.stdout.write(` target: ${preview.target}\\n`);\n process.stdout.write(` source: ${sourcePath}\\n`);\n process.stdout.write(` format: ${preview.format}\\n`);\n for (const batch of preview.batches) {\n process.stdout.write(` - ${batch.table}: ${batch.rowCount} row(s)\\n`);\n }\n }\n\n return preview;\n}\n\nfunction parseJsonObject(input: string, label: string): Record<string, unknown> {\n let parsed: unknown;\n try {\n parsed = JSON.parse(input);\n } catch (error) {\n throw new Error(`${label} must be valid JSON: ${formatError(error)}`);\n }\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n throw new Error(`${label} must be a JSON object.`);\n }\n return parsed as Record<string, unknown>;\n}\n\nasync function waitForSignal(): Promise<void> {\n await new Promise<void>((resolve) => {\n const onSignal = () => {\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n resolve();\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n });\n}\n\nfunction parseGlobalOptionsFromArgv(argv: string[]): GlobalCliOptions {\n const parsed: GlobalCliOptions = {};\n for (let index = 0; index < argv.length; index += 1) {\n const value = argv[index];\n if (value === \"--cwd\") {\n const nextValue = argv[index + 1];\n if (nextValue) {\n parsed.cwd = nextValue;\n }\n index += 1;\n continue;\n }\n if (value === \"--json\") {\n parsed.json = true;\n continue;\n }\n if (value === \"--verbose\") {\n parsed.verbose = true;\n continue;\n }\n if (value === \"--no-interactive\") {\n parsed.interactive = false;\n continue;\n }\n if (value === \"--yes\" || value === \"-y\") {\n parsed.yes = true;\n }\n }\n return parsed;\n}\n"],"mappings":";;;;;;;;;;;;;;AAqIA,eAAsB,cAAc,OAAO,QAAQ,MAAqB;CACtE,MAAM,UAAU,cAAc;AAE9B,KAAI,KAAK,UAAU,EACjB,QAAO,CAAC,GAAG,MAAM,SAAS;AAG5B,KAAI;AACF,QAAM,QAAQ,WAAW,KAAK;UACvB,OAAO;AACE,MAAI,WAAW,2BAA2B,KAAK,CAAC,CACxD,YAAY,MAAM;;;AAI9B,SAAgB,eAAwB;CACtC,MAAM,UAAU,IAAI,SAAS;AAC7B,SACG,KAAK,YAAY,CACjB,MAAM,sBAAsB,CAC5B,OAAO,gBAAgB,yDAAyD,CAChF,OAAO,UAAU,oCAAoC,CACrD,OAAO,aAAa,+BAA+B,CACnD,OAAO,oBAAoB,kCAAkC,CAC7D,OAAO,aAAa,+BAA+B,CACnD,oBAAoB,CACpB,0BAA0B,CAC1B,YAAY,kBAAkB,0BAA0B;AAC3D,eAAc,QAAQ;AAEtB,gBAAe,QAAQ;AACvB,mBAAkB,QAAQ;AAC1B,kBAAiB,QAAQ;AACzB,mBAAkB,QAAQ;AAC1B,eAAc,QAAQ;AACtB,mBAAkB,QAAQ;AAC1B,eAAc,QAAQ;AACtB,gBAAe,QAAQ;AACvB,kBAAiB,QAAQ;AACzB,kBAAiB,QAAQ;AACzB,gBAAe,QAAQ;AACvB,qBAAoB,QAAQ;AAC5B,gBAAe,QAAQ;AAEvB,QAAO;;AAGT,SAAS,eAAe,SAAwB;AAC9C,SACG,QAAQ,OAAO,CACf,QAAQ,4CAA4C,CACpD,YAAY,oFAAoF,CAChG,OACC,yBACA,yBAAyB,wBAAwB,KAAK,KAAK,CAAC,aAC5D,OACD,C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,MAAM,uBAAuB,YAAY,MAAM,GAAG;;AAEvE,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,OAAO,CAChE,OAAM,IAAI,MAAM,GAAG,MAAM,yBAAyB;AAEpD,QAAO;;AAGT,eAAe,gBAA+B;AAC5C,OAAM,IAAI,SAAe,YAAY;EACnC,MAAM,iBAAiB;AACrB,WAAQ,IAAI,UAAU,SAAS;AAC/B,WAAQ,IAAI,WAAW,SAAS;AAChC,YAAS;;AAEX,UAAQ,GAAG,UAAU,SAAS;AAC9B,UAAQ,GAAG,WAAW,SAAS;GAC/B;;AAGJ,SAAS,2BAA2B,MAAkC;CACpE,MAAM,SAA2B,EAAE;AACnC,MAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;EACnD,MAAM,QAAQ,KAAK;AACnB,MAAI,UAAU,SAAS;GACrB,MAAM,YAAY,KAAK,QAAQ;AAC/B,OAAI,UACF,QAAO,MAAM;AAEf,YAAS;AACT;;AAEF,MAAI,UAAU,UAAU;AACtB,UAAO,OAAO;AACd;;AAEF,MAAI,UAAU,aAAa;AACzB,UAAO,UAAU;AACjB;;AAEF,MAAI,UAAU,oBAAoB;AAChC,UAAO,cAAc;AACrB;;AAEF,MAAI,UAAU,WAAW,UAAU,KACjC,QAAO,MAAM;;AAGjB,QAAO"}
1
+ {"version":3,"file":"app.mjs","names":["templateUsesConnectedClients"],"sources":["../src/app.ts"],"sourcesContent":["import { mkdir, readdir, readFile, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { spawn } from \"node:child_process\";\nimport { Command } from \"commander\";\nimport type { SyncoreDevtoolsSubscriptionResultPayload } from \"@syncore/devtools-protocol\";\nimport {\n createSchemaSnapshot,\n diffSchemaSnapshots,\n renderMigrationSql\n} from \"@syncore/core\";\nimport {\n type DevHubSessionState,\n type SyncoreTemplateName,\n VALID_SYNCORE_TEMPLATES,\n applyProjectMigrations,\n detectProjectTemplate,\n fileExists,\n formatError,\n getNextMigrationNumber,\n hasSyncoreProject,\n isLocalPortInUse,\n loadProjectSchema,\n readStoredSnapshot,\n resolveRequestedTemplate,\n runCodegen,\n runDevProjectBootstrap,\n scaffoldProject,\n slugify,\n startDevHub,\n writeStoredSnapshot\n} from \"@syncore/core/cli\";\nimport { CliContext, type CliChoice, type GlobalCliOptions, openTarget } from \"./context.js\";\nimport { runShellCommand, printCompactDevPhase, printDevSessionIntro, withConsoleCapture } from \"./dev-session.js\";\nimport { applyDoctorFixes, buildDoctorReport, type DoctorReport } from \"./doctor.js\";\nimport { applyRootHelp } from \"./help.js\";\nimport {\n buildDevBootstrapNextSteps,\n buildInitNextSteps,\n buildTargetCommandNextSteps,\n buildHubUnavailableNextSteps,\n templateUsesConnectedClients\n} from \"./messages.js\";\nimport {\n buildRuntimeLookup,\n type ClientRuntimeLookupEntry,\n type ClientTargetDescriptor,\n type TargetCapability,\n connectToProjectHub,\n createPublicRuntimeId,\n createManagedProjectClient,\n exportProjectData,\n importProjectData,\n isKnownTemplate,\n listAvailableTargets,\n listConnectedClientTargets,\n listProjectTables,\n resolveActiveDashboardUrl,\n loadImportDocumentBatches,\n readProjectTable,\n resolveDashboardUrl,\n resolveDevtoolsUrl,\n resolveDocsTarget,\n resolveProjectFunction,\n targetSupportsCapability,\n writeExportData\n} from \"./project.js\";\nimport {\n formatPersistedLogEntry,\n type JsonLikeFormat,\n type PersistedLogEntry,\n printDevReadySummary,\n printDoctorReport,\n printTargetsTable,\n renderOutput\n} from \"./render.js\";\nimport { resolveClientRuntime, resolveOperationalTarget } from \"./targets.js\";\n\ninterface InitCommandOptions {\n template: SyncoreTemplateName | \"auto\";\n force?: boolean;\n}\n\ninterface DevCommandOptions {\n template: string;\n once?: boolean;\n openDashboard?: boolean;\n untilSuccess?: boolean;\n run?: string;\n runSh?: string;\n typecheck: \"enable\" | \"try\" | \"disable\";\n tailLogs: \"always\" | \"errors\" | \"disable\";\n}\n\ninterface DoctorCommandOptions {\n fix?: boolean;\n}\n\ninterface RunCommandOptions {\n watch?: boolean;\n format: JsonLikeFormat;\n target?: string;\n runtime?: string;\n}\n\ninterface DataCommandOptions {\n limit: string;\n order?: \"asc\" | \"desc\";\n format: JsonLikeFormat;\n target?: string;\n runtime?: string;\n watch?: boolean;\n}\n\ninterface ImportCommandOptions {\n table?: string;\n target?: string;\n runtime?: string;\n}\n\ninterface ExportCommandOptions {\n path: string;\n table?: string;\n target?: string;\n runtime?: string;\n}\n\ninterface LogsCommandOptions {\n target?: string;\n runtime?: string;\n limit: string;\n watch?: boolean;\n kind?: \"query\" | \"mutation\" | \"action\" | \"system\";\n format: JsonLikeFormat;\n}\n\ninterface TargetsCommandOptions {\n onlineOnly?: boolean;\n capability?: TargetCapability;\n}\n\ninterface OpenCommandOptions {\n open?: boolean;\n}\n\nexport async function runSyncoreCli(argv = process.argv): Promise<void> {\n const program = buildProgram();\n\n if (argv.length <= 2) {\n argv = [...argv, \"--help\"];\n }\n\n try {\n await program.parseAsync(argv);\n } catch (error) {\n const context = new CliContext(parseGlobalOptionsFromArgv(argv));\n context.handleError(error);\n }\n}\n\nexport function buildProgram(): Command {\n const program = new Command();\n program\n .name(\"syncorejs\")\n .usage(\"<command> [options]\")\n .option(\"--cwd <path>\", \"Run the command as if started from the given directory\")\n .option(\"--json\", \"Emit machine-readable JSON output\")\n .option(\"--verbose\", \"Print additional diagnostics\")\n .option(\"--no-interactive\", \"Disable prompts and terminal UX\")\n .option(\"-y, --yes\", \"Assume yes for confirmations\")\n .showHelpAfterError()\n .showSuggestionAfterError()\n .helpCommand(\"help <command>\", \"Show help for a command\");\n applyRootHelp(program);\n\n addInitCommand(program);\n addCodegenCommand(program);\n addDoctorCommand(program);\n addTargetsCommand(program);\n addDevCommand(program);\n addMigrateCommand(program);\n addRunCommand(program);\n addDataCommand(program);\n addImportCommand(program);\n addExportCommand(program);\n addLogsCommand(program);\n addDashboardCommand(program);\n addDocsCommand(program);\n\n return program;\n}\n\nfunction addInitCommand(program: Command): void {\n program\n .command(\"init\")\n .summary(\"Scaffold Syncore into the current project\")\n .description(\"Scaffold Syncore files, scripts, and generated types into the selected directory.\")\n .option(\n \"--template <template>\",\n `Template to scaffold (${VALID_SYNCORE_TEMPLATES.join(\", \")}, or auto)`,\n \"auto\"\n )\n .option(\"--force\", \"Overwrite Syncore-managed files\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs init\",\n \" npx syncorejs init --template react-web\",\n \" npx syncorejs init --cwd ./examples/my-app\"\n ].join(\"\\n\")\n )\n .action(async (options: InitCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (\n !options.force &&\n !(await isDirectoryEmpty(ctx.cwd)) &&\n !(await ctx.confirm(\n \"The target directory is not empty. Continue scaffolding into it?\",\n false\n ))\n ) {\n ctx.fail(\"Scaffolding cancelled by user.\", 1);\n }\n\n let template = options.template;\n if (template === \"auto\") {\n const detectedTemplate = await detectProjectTemplate(ctx.cwd);\n template =\n detectedTemplate === \"minimal\" && ctx.interactive\n ? await promptForTemplate(ctx, detectedTemplate)\n : detectedTemplate;\n }\n\n if (!isKnownTemplate(template)) {\n ctx.fail(\n `Unknown template ${JSON.stringify(template)}. Expected one of ${VALID_SYNCORE_TEMPLATES.join(\", \")} or auto.`\n );\n }\n const resolvedTemplate: SyncoreTemplateName = template;\n\n const result = await ctx.withSpinner(\"Scaffolding Syncore\", async () =>\n scaffoldProject(ctx.cwd, {\n template: resolvedTemplate,\n ...(options.force ? { force: true } : {})\n })\n );\n await ctx.withSpinner(\"Generating typed references\", async () =>\n runCodegen(ctx.cwd)\n );\n\n ctx.printResult({\n summary: `Syncore scaffolded with the ${resolvedTemplate} template.`,\n command: \"init\",\n data: result,\n nextSteps: buildInitNextSteps(resolvedTemplate)\n });\n\n if (!ctx.json) {\n printScaffoldChanges(ctx, result);\n }\n });\n });\n}\n\nfunction addCodegenCommand(program: Command): void {\n program\n .command(\"codegen\")\n .summary(\"Generate typed Syncore references\")\n .description(\"Regenerate syncore/_generated from the current syncore/functions tree.\")\n .addHelpText(\n \"after\",\n [\"\", \"Examples:\", \" npx syncorejs codegen\", \" npx syncorejs codegen --cwd ./apps/web\"].join(\n \"\\n\"\n )\n )\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n await ctx.withSpinner(\"Generating typed references\", async () =>\n runCodegen(ctx.cwd)\n );\n ctx.printResult({\n summary: \"Generated syncore/_generated files.\",\n command: \"codegen\"\n });\n });\n });\n}\n\nfunction addDoctorCommand(program: Command): void {\n program\n .command(\"doctor\")\n .summary(\"Inspect the current Syncore project state\")\n .description(\"Check project structure, template capabilities, hub state, and available targets.\")\n .option(\"--fix\", \"Apply safe low-risk fixes like codegen and snapshot refresh\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs doctor\",\n \" npx syncorejs doctor --json\",\n \" npx syncorejs doctor --fix\"\n ].join(\"\\n\")\n )\n .action(async (options: DoctorCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n let report = await buildDoctorReport(ctx.cwd);\n let appliedFixes: string[] = [];\n if (options.fix) {\n appliedFixes = await applyDoctorFixes(ctx.cwd, report);\n report = await buildDoctorReport(ctx.cwd);\n }\n if (ctx.json) {\n ctx.printResult({\n command: \"doctor\",\n ...(options.fix && appliedFixes.length > 0\n ? { summary: `Applied ${appliedFixes.length} safe fix(es).` }\n : {}),\n data: {\n ...report,\n ...(options.fix ? { appliedFixes } : {})\n }\n });\n return;\n }\n\n ctx.info(report.primaryIssue.summary);\n if (options.fix) {\n if (appliedFixes.length > 0) {\n ctx.success(`Applied ${appliedFixes.length} safe fix(es).`);\n for (const fix of appliedFixes) {\n ctx.info(fix);\n }\n } else {\n ctx.info(\"No safe fixes were applied.\");\n }\n }\n printDoctorReport(report, {\n verbose: ctx.verbose\n });\n if (report.workspaceMatches.length > 0) {\n ctx.warn(\"You appear to be at a workspace root instead of inside an app package.\");\n for (const match of report.workspaceMatches) {\n process.stdout.write(\n ` - ${match.relativePath} (${match.template}) -> use --cwd ${match.relativePath}\\n`\n );\n }\n }\n for (const suggestion of report.suggestions) {\n ctx.nextStep(suggestion);\n }\n });\n });\n}\n\nfunction addTargetsCommand(program: Command): void {\n program\n .command(\"targets\")\n .summary(\"List available Syncore targets\")\n .description(\"Inspect project and connected client targets for run, data, import, export, and logs.\")\n .option(\"--online-only\", \"Only show online targets\")\n .option(\n \"--capability <capability>\",\n \"Filter targets by capability: run, readData, writeData, exportData, streamLogs\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs targets\",\n \" npx syncorejs targets --capability run\",\n \" npx syncorejs targets --json\"\n ].join(\"\\n\")\n )\n .action(async (options: TargetsCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.capability && !isTargetCapability(options.capability)) {\n ctx.fail(\n `Unknown capability ${JSON.stringify(options.capability)}. Expected run, readData, writeData, exportData, or streamLogs.`\n );\n }\n const targets = await listAvailableTargets(ctx.cwd);\n const filtered = targets.filter((target) => {\n if (options.onlineOnly && !target.online) {\n return false;\n }\n if (options.capability && !targetSupportsCapability(target, options.capability)) {\n return false;\n }\n return true;\n });\n\n ctx.printResult({\n command: \"targets\",\n summary: `Found ${filtered.length} target(s).`,\n data: filtered,\n nextSteps: buildTargetCommandNextSteps(filtered[0]?.id)\n });\n\n if (!ctx.json) {\n printTargetsTable(filtered, {\n verbose: ctx.verbose\n });\n }\n });\n });\n}\n\nfunction addDevCommand(program: Command): void {\n program\n .command(\"dev\")\n .summary(\"Run the Syncore development loop\")\n .description(\n \"Bootstrap the local Syncore project, start the hub, discover targets, and keep the local workflow in sync.\"\n )\n .option(\n \"--template <template>\",\n `Template to scaffold when Syncore is missing (${VALID_SYNCORE_TEMPLATES.join(\", \")}, or auto)`,\n \"auto\"\n )\n .option(\"--once\", \"Run bootstrap once and exit\")\n .option(\"--until-success\", \"Retry bootstrap until it succeeds\")\n .option(\"--run <function>\", \"Run a Syncore function after bootstrap succeeds\")\n .option(\"--run-sh <command>\", \"Run a shell command after bootstrap succeeds\")\n .option(\n \"--typecheck <mode>\",\n \"Run TypeScript typecheck before entering the local dev loop: enable, try, or disable\",\n \"try\"\n )\n .option(\n \"--tail-logs <mode>\",\n \"Control whether runtime logs appear in this terminal: always, errors, or disable\",\n \"errors\"\n )\n .option(\n \"--no-open-dashboard\",\n \"Do not open the dashboard automatically after the hub is ready\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs dev\",\n \" npx syncorejs dev --once\",\n \" npx syncorejs dev --until-success\",\n \" npx syncorejs dev --run tasks/list\",\n \" npx syncorejs dev --no-open-dashboard\",\n \" npx syncorejs dev --run-sh \\\"npm run dev\\\"\",\n \" npx syncorejs dev --typecheck enable\",\n \" npx syncorejs dev --tail-logs always\"\n ].join(\"\\n\")\n )\n .action(async (options: DevCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.run && options.runSh) {\n ctx.fail(\"`syncorejs dev` accepts either --run or --run-sh, not both.\");\n }\n const shouldOpenDashboard = options.openDashboard ?? true;\n await ensureLocalPortConfiguration(ctx);\n\n const template = await resolveRequestedTemplate(ctx.cwd, options.template);\n validateDevModes(ctx, options);\n printDevSessionIntro(ctx);\n await ensureDevProjectExists(ctx, template);\n const preflight = await buildDoctorReport(ctx.cwd);\n printDevPreflight(ctx, preflight);\n const typecheckResult = await runDevTypecheck(ctx, options.typecheck);\n\n if (options.once) {\n const bootstrapReport = await runDevBootstrapLoop(\n ctx,\n template,\n options.untilSuccess ?? false,\n options.tailLogs\n );\n await runDevFollowup(ctx, options);\n const targets = await listAvailableTargets(ctx.cwd);\n ctx.printResult({\n summary: \"Syncore dev bootstrap completed.\",\n command: \"dev\",\n nextSteps: buildDevBootstrapNextSteps()\n });\n if (!ctx.json) {\n printDevReadySummary(ctx, {\n template,\n projectTargetConfigured: targets.some((target) => target.kind === \"project\"),\n dashboardUrl: resolveDashboardUrl(),\n devtoolsUrl: resolveDevtoolsUrl(),\n targets,\n codegenStatus: \"refreshed\",\n driftStatus: describeDevDriftStatus(bootstrapReport),\n typecheckStatus: describeTypecheckStatus(typecheckResult)\n });\n }\n return;\n }\n\n const bootstrapReport = await runDevBootstrapLoop(\n ctx,\n template,\n options.untilSuccess ?? false,\n options.tailLogs\n );\n const targets = await listAvailableTargets(ctx.cwd);\n printDevReadySummary(ctx, {\n template,\n projectTargetConfigured: targets.some((target) => target.kind === \"project\"),\n dashboardUrl: resolveDashboardUrl(),\n devtoolsUrl: resolveDevtoolsUrl(),\n targets,\n codegenStatus: \"refreshed\",\n driftStatus: describeDevDriftStatus(bootstrapReport),\n typecheckStatus: describeTypecheckStatus(typecheckResult)\n });\n\n const hubSession = await startManagedDevHub(ctx, template);\n await maybeOpenDashboard(ctx, shouldOpenDashboard, hubSession);\n await monitorLiveDevSession(ctx, template, options.tailLogs);\n });\n });\n}\n\nasync function maybeOpenDashboard(\n context: CliContext,\n shouldOpenDashboard: boolean,\n hubSession?: DevHubSessionState\n): Promise<void> {\n if (!shouldOpenDashboard) {\n return;\n }\n const targetUrl =\n hubSession?.authenticatedDashboardUrl ??\n (await resolveActiveDashboardUrl(context.cwd));\n const ready = await waitForDashboardReady(targetUrl);\n if (!ready) {\n context.warn(\"Dashboard did not become ready in time, so it was not opened.\");\n return;\n }\n const opened = await openTarget(targetUrl);\n if (opened) {\n context.info(`Opened dashboard at ${targetUrl}.`);\n return;\n }\n context.warn(\"Unable to open the dashboard automatically.\");\n}\n\nfunction addMigrateCommand(program: Command): void {\n const migrate = program\n .command(\"migrate\")\n .summary(\"Generate and apply local SQL migrations\")\n .description(\"Work with schema diffs, migration SQL, and the local Syncore database.\");\n\n migrate\n .command(\"status\")\n .summary(\"Show the current schema diff status\")\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const schema = await loadProjectSchema(ctx.cwd);\n const currentSnapshot = createSchemaSnapshot(schema);\n const storedSnapshot = await readStoredSnapshot(ctx.cwd);\n const plan = diffSchemaSnapshots(storedSnapshot, currentSnapshot);\n\n ctx.printResult({\n summary: \"Migration status computed.\",\n command: \"migrate status\",\n data: {\n currentSchemaHash: currentSnapshot.hash,\n storedSchemaHash: storedSnapshot?.hash ?? null,\n statements: plan.statements,\n warnings: plan.warnings,\n destructiveChanges: plan.destructiveChanges\n }\n });\n\n if (!ctx.json) {\n process.stdout.write(`Current schema hash: ${currentSnapshot.hash}\\n`);\n process.stdout.write(`Stored snapshot: ${storedSnapshot?.hash ?? \"none\"}\\n`);\n process.stdout.write(`Statements to generate: ${plan.statements.length}\\n`);\n process.stdout.write(`Warnings: ${plan.warnings.length}\\n`);\n process.stdout.write(`Destructive changes: ${plan.destructiveChanges.length}\\n`);\n for (const warning of plan.warnings) {\n ctx.warn(warning);\n }\n for (const change of plan.destructiveChanges) {\n ctx.error(change);\n }\n }\n });\n });\n\n migrate\n .command(\"generate\")\n .argument(\"[name]\", \"Optional migration name\", \"auto\")\n .summary(\"Generate a SQL migration from the current schema diff\")\n .action(\n async (name: string, _options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const schema = await loadProjectSchema(ctx.cwd);\n const currentSnapshot = createSchemaSnapshot(schema);\n const storedSnapshot = await readStoredSnapshot(ctx.cwd);\n const plan = diffSchemaSnapshots(storedSnapshot, currentSnapshot);\n\n if (plan.destructiveChanges.length > 0) {\n ctx.fail(\n `Destructive schema changes require a manual migration: ${plan.destructiveChanges.join(\"; \")}`\n );\n }\n if (plan.statements.length === 0 && plan.warnings.length === 0) {\n ctx.printResult({\n summary: \"No schema changes detected.\"\n });\n return;\n }\n\n const migrationsDirectory = path.join(ctx.cwd, \"syncore\", \"migrations\");\n await mkdir(migrationsDirectory, { recursive: true });\n const migrationNumber = await getNextMigrationNumber(migrationsDirectory);\n const slug = slugify(name);\n const fileName = `${String(migrationNumber).padStart(4, \"0\")}_${slug}.sql`;\n const migrationSql = renderMigrationSql(plan, {\n title: `Syncore migration ${fileName}`\n });\n await writeFile(path.join(migrationsDirectory, fileName), migrationSql);\n await writeStoredSnapshot(ctx.cwd, currentSnapshot);\n\n ctx.printResult({\n summary: `Generated syncore/migrations/${fileName}.`,\n command: \"migrate generate\",\n data: {\n path: path.join(\"syncore\", \"migrations\", fileName),\n statements: plan.statements,\n warnings: plan.warnings\n },\n nextSteps: [\"Run `npx syncorejs migrate apply` to apply pending migrations.\"]\n });\n });\n }\n );\n\n migrate\n .command(\"apply\")\n .summary(\"Apply SQL migrations to the local database\")\n .action(async (_options: Record<string, never>, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const appliedCount = await ctx.withSpinner(\"Applying migrations\", async () =>\n applyProjectMigrations(ctx.cwd)\n );\n ctx.printResult({\n summary: `Applied ${appliedCount} migration(s).`,\n command: \"migrate apply\"\n });\n });\n });\n}\n\nfunction addRunCommand(program: Command): void {\n program\n .command(\"run\")\n .summary(\"Run a local Syncore function\")\n .description(\"Execute a query, mutation, or action against the local runtime.\")\n .argument(\"<functionName>\", \"Function name like tasks/list or api.tasks.list\")\n .argument(\"[args]\", \"JSON object of arguments\", \"{}\")\n .option(\"--watch\", \"Watch a query for local changes\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .option(\n \"--format <format>\",\n \"Output format: pretty, json, or jsonl\",\n \"pretty\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs run tasks/list\",\n \" npx syncorejs run api.tasks.create '{\\\"text\\\":\\\"Ship Syncore\\\"}' --target project\",\n \" npx syncorejs run tasks/list --watch --target 10427 --runtime 20318 --format json\"\n ].join(\"\\n\")\n )\n .action(\n async (\n functionName: string,\n argsText: string,\n options: RunCommandOptions,\n command: Command\n ) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs run --runtime` requires --target.\");\n }\n const resolved = await resolveProjectFunction(ctx.cwd, functionName);\n const args = parseJsonObject(argsText, \"Function arguments\");\n\n if (options.watch && resolved.definition.kind !== \"query\") {\n ctx.fail(\"`syncorejs run --watch` only supports query functions.\");\n }\n\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"run\",\n capability: \"run\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"run\"\n });\n ctx.info(\n options.watch\n ? `Watching ${resolved.name} on ${target.id}${runtime ? ` (${runtime.id} ${runtime.label})` : \"\"}.`\n : `Running ${resolved.name} on ${target.id}${runtime ? ` (${runtime.id} ${runtime.label})` : \"\"}.`\n );\n if (target.kind === \"project\") {\n const managed = await createManagedProjectClient(ctx.cwd);\n try {\n if (options.watch) {\n const watch = managed.client.watchQuery(\n resolved.reference as never,\n args\n );\n const render = () => {\n const error = watch.localQueryError();\n if (error) {\n ctx.handleError(error);\n return;\n }\n renderOutput(ctx, watch.localQueryResult(), options.format);\n };\n const unsubscribe = watch.onUpdate(render);\n ctx.info(\"Watching query. Press Ctrl+C to stop.\");\n await waitForSignal();\n unsubscribe();\n watch.dispose?.();\n return;\n }\n\n const result =\n resolved.definition.kind === \"query\"\n ? await managed.client.query(resolved.reference as never, args)\n : resolved.definition.kind === \"mutation\"\n ? await managed.client.mutation(\n resolved.reference as never,\n args\n )\n : await managed.client.action(resolved.reference as never, args);\n\n renderOutput(ctx, result, options.format);\n return;\n } finally {\n await managed.dispose();\n }\n }\n\n const hub = await requireHubConnection(ctx);\n try {\n if (options.watch) {\n const unsubscribe = hub.subscribe(runtime!.runtimeId, {\n kind: \"fn.watch\",\n functionName: resolved.name,\n functionType: \"query\",\n args\n }, {\n onData(payload) {\n if (payload.kind !== \"fn.watch.result\") {\n return;\n }\n if (payload.error) {\n ctx.handleError(new Error(payload.error));\n return;\n }\n renderOutput(ctx, payload.result, options.format);\n },\n onError(error) {\n ctx.handleError(new Error(error));\n }\n });\n ctx.info(`Watching query on ${target.id}. Press Ctrl+C to stop.`);\n await waitForSignal();\n unsubscribe();\n return;\n }\n\n const result = await hub.sendCommand(runtime!.runtimeId, {\n kind: \"fn.run\",\n functionName: resolved.name,\n functionType: resolved.definition.kind,\n args\n });\n if (result.kind === \"fn.run.result\") {\n if (result.error) {\n ctx.fail(result.error);\n }\n renderOutput(ctx, result.result, options.format);\n return;\n }\n if (result.kind === \"error\") {\n ctx.fail(result.message, 1, result);\n }\n ctx.fail(`Unexpected response from ${target.id}.`, 1, result);\n } finally {\n await hub.dispose();\n }\n });\n }\n );\n}\n\nfunction addDataCommand(program: Command): void {\n program\n .command(\"data\")\n .summary(\"Inspect local Syncore data\")\n .description(\"List tables or print local rows from a specific table.\")\n .argument(\"[table]\", \"Optional table to inspect\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .option(\"--limit <n>\", \"Maximum rows to print\", \"100\")\n .option(\"--order <choice>\", \"Order by _creationTime\", \"desc\")\n .option(\"--watch\", \"Watch a table for changes on the selected target\")\n .option(\n \"--format <format>\",\n \"Output format: pretty, json, or jsonl\",\n \"pretty\"\n )\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs data\",\n \" npx syncorejs data tasks --target project --limit 10\",\n \" npx syncorejs data tasks --target 10427 --runtime 20318 --watch --format jsonl\"\n ].join(\"\\n\")\n )\n .action(\n async (\n table: string | undefined,\n options: DataCommandOptions,\n command: Command\n ) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs data --runtime` requires --target.\");\n }\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"data\",\n capability: \"readData\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"data\"\n });\n if (!table) {\n const tables =\n target.kind === \"project\"\n ? await listProjectTables(ctx.cwd)\n : await listRemoteTables(runtime!.runtimeId, ctx);\n ctx.printResult({\n summary: `Found ${tables.length} table(s) on ${target.id}.`,\n command: \"data\",\n data: tables,\n target: target.id\n });\n if (!ctx.json) {\n for (const entry of tables) {\n const tableEntry = entry as {\n name: string;\n documentCount: number;\n displayName?: string;\n owner?: \"root\" | \"component\";\n componentPath?: string;\n };\n const label =\n typeof tableEntry.displayName === \"string\" &&\n tableEntry.displayName.length > 0 &&\n tableEntry.displayName !== tableEntry.name\n ? `${tableEntry.displayName} -> ${tableEntry.name}`\n : tableEntry.name;\n const owner =\n tableEntry.owner === \"component\"\n ? ` component:${String(tableEntry.componentPath ?? \"unknown\")}`\n : \"\";\n process.stdout.write(\n ` ${label} (${tableEntry.documentCount} document(s))${owner}\\n`\n );\n }\n }\n return;\n }\n\n if (target.kind === \"project\") {\n const payload = await readProjectTable(ctx.cwd, table, {\n limit: Number.parseInt(options.limit, 10),\n order: options.order === \"asc\" ? \"asc\" : \"desc\"\n });\n renderOutput(ctx, payload.rows, options.format);\n return;\n }\n\n const hub = await requireHubConnection(ctx);\n try {\n const payload = await readRemoteTable(hub, runtime!.runtimeId, table, {\n limit: Number.parseInt(options.limit, 10)\n });\n renderOutput(ctx, payload.rows, options.format);\n\n if (!options.watch) {\n return;\n }\n\n const unsubscribe = hub.subscribe(runtime!.runtimeId, {\n kind: \"data.table\",\n table,\n limit: Number.parseInt(options.limit, 10)\n }, {\n onData(result) {\n if (result.kind !== \"data.table.result\") {\n return;\n }\n renderOutput(ctx, result.rows, options.format);\n },\n onError(error) {\n ctx.handleError(new Error(error));\n }\n });\n ctx.info(\n `Watching table ${table} on ${target.id} (${runtime!.id} ${runtime!.label}). Press Ctrl+C to stop.`\n );\n await waitForSignal();\n unsubscribe();\n } finally {\n await hub.dispose();\n }\n });\n }\n );\n}\n\nfunction addImportCommand(program: Command): void {\n program\n .command(\"import\")\n .summary(\"Import local data into Syncore\")\n .description(\"Import JSON, JSONL, directory, or ZIP data into the local Syncore database.\")\n .argument(\"<path>\", \"Path to a .json, .jsonl, directory, or .zip input\")\n .option(\"--table <table>\", \"Destination table for single-file imports\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs import --table tasks sample.jsonl --target project\",\n \" npx syncorejs import --table tasks sample.json --target 10427 --runtime 20318\",\n \" npx syncorejs import backups/export.zip\"\n ].join(\"\\n\")\n )\n .action(\n async (\n sourcePath: string,\n options: ImportCommandOptions,\n command: Command\n ) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs import --runtime` requires --target.\");\n }\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"import\",\n capability: \"writeData\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"import\"\n });\n const preview = await previewImportPlan(ctx, sourcePath, options, target.id);\n if (\n ctx.interactive &&\n !(await ctx.confirm(\n `Import ${preview.totalRows} row(s) into ${target.id}?`,\n true\n ))\n ) {\n ctx.fail(\"Import cancelled by user.\");\n }\n const imported =\n target.kind === \"project\"\n ? await ctx.withSpinner(\"Importing local data\", async () =>\n importProjectData(ctx.cwd, sourcePath, {\n ...(options.table ? { table: options.table } : {})\n })\n )\n : await ctx.withSpinner(`Importing data into ${target.id}`, async () =>\n importIntoClientTarget(ctx, target, runtime!, sourcePath, options)\n );\n ctx.printResult({\n summary: `Imported ${imported.reduce((sum, entry) => sum + entry.importedCount, 0)} row(s).`,\n command: \"import\",\n data: imported,\n target: target.id\n });\n if (!ctx.json) {\n for (const entry of imported) {\n process.stdout.write(\n ` ${entry.table}: ${entry.importedCount} row(s)\\n`\n );\n }\n }\n });\n }\n );\n}\n\nfunction addExportCommand(program: Command): void {\n program\n .command(\"export\")\n .summary(\"Export local Syncore data\")\n .description(\"Export one or more local tables to JSON, JSONL, a directory, or a ZIP file.\")\n .requiredOption(\"--path <path>\", \"Output path (.json, .jsonl, directory, or .zip)\")\n .option(\"--table <table>\", \"Export a single table\")\n .option(\"--target <target>\", \"Target id: project or a 5-digit client target id\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs export --table tasks --path tasks.jsonl --target project\",\n \" npx syncorejs export --path ./exports --target 10427 --runtime 20318\",\n \" npx syncorejs export --path ./exports.zip\"\n ].join(\"\\n\")\n )\n .action(async (options: ExportCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && !options.target) {\n ctx.fail(\"`syncorejs export --runtime` requires --target.\");\n }\n const target = await resolveOperationalTarget(ctx, options.target, {\n command: \"export\",\n capability: \"exportData\"\n });\n const runtime = resolveClientRuntime(target, options.runtime, {\n command: \"export\"\n });\n const result =\n target.kind === \"project\"\n ? await ctx.withSpinner(\"Exporting local data\", async () =>\n exportProjectData(ctx.cwd, options.path, {\n ...(options.table ? { table: options.table } : {})\n })\n )\n : await ctx.withSpinner(`Exporting data from ${target.id}`, async () =>\n exportClientTargetData(ctx, target, runtime!, options)\n );\n ctx.printResult({\n summary: `Exported ${result.tables.length} table(s) to ${result.path}.`,\n command: \"export\",\n data: result,\n target: target.id\n });\n });\n });\n}\n\nfunction addLogsCommand(program: Command): void {\n program\n .command(\"logs\")\n .summary(\"Inspect Syncore runtime logs\")\n .description(\"Read persisted hub logs and optionally watch live runtime events.\")\n .option(\"--target <target>\", \"Target id, or all\", \"all\")\n .option(\"--runtime <runtime>\", \"Runtime id inside the selected client target\")\n .option(\"--limit <n>\", \"Maximum log lines to print\", \"100\")\n .option(\"--watch\", \"Stream new logs from the local devtools hub\")\n .option(\"--kind <kind>\", \"Filter by event kind: query, mutation, action, system\")\n .option(\"--format <format>\", \"Output format: pretty, json, or jsonl\", \"pretty\")\n .addHelpText(\n \"after\",\n [\n \"\",\n \"Examples:\",\n \" npx syncorejs logs\",\n \" npx syncorejs logs --target 10427 --runtime 20318 --watch\",\n \" npx syncorejs logs --kind mutation --format jsonl\"\n ].join(\"\\n\")\n )\n .action(async (options: LogsCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n if (options.runtime && (!options.target || options.target === \"all\")) {\n ctx.fail(\"`syncorejs logs --runtime` requires a specific --target.\");\n }\n await runLogsCommand(ctx, options);\n });\n });\n}\n\nfunction addDashboardCommand(program: Command): void {\n program\n .command(\"dashboard\")\n .summary(\"Print or open the local dashboard URL\")\n .description(\"Show the local Syncore dashboard URL, optionally opening it in the browser.\")\n .option(\"--open\", \"Open the dashboard URL\")\n .action(async (options: OpenCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const url = resolveDashboardUrl();\n const activeUrl = await resolveActiveDashboardUrl(ctx.cwd);\n if (options.open) {\n const ready = await waitForDashboardReady(activeUrl);\n const opened = ready ? await openTarget(activeUrl) : false;\n if (!opened) {\n ctx.warn(\"Unable to open the dashboard automatically.\");\n }\n }\n ctx.printResult({\n summary: \"Dashboard URL resolved.\",\n command: \"dashboard\",\n data: { url: activeUrl, baseUrl: url },\n nextSteps: [`Open ${activeUrl}`]\n });\n });\n });\n}\n\nfunction addDocsCommand(program: Command): void {\n program\n .command(\"docs\")\n .summary(\"Print or open the most relevant Syncore docs\")\n .description(\"Resolve the best local docs target for the detected template and optionally open it.\")\n .option(\"--open\", \"Open the docs target\")\n .action(async (options: OpenCommandOptions, command: Command) => {\n const ctx = createContext(command);\n await executeCommand(ctx, async () => {\n const url = await resolveDocsTarget(ctx.cwd);\n if (options.open) {\n const opened = await openTarget(url);\n if (!opened) {\n ctx.warn(\"Unable to open the docs target automatically.\");\n }\n }\n ctx.printResult({\n summary: \"Docs target resolved.\",\n command: \"docs\",\n data: { url }\n });\n });\n });\n}\n\nfunction createContext(command: Command): CliContext {\n const options = command.optsWithGlobals<GlobalCliOptions>();\n return new CliContext(options);\n}\n\nasync function executeCommand(\n context: CliContext,\n action: () => Promise<void>\n): Promise<void> {\n try {\n await action();\n } catch (error) {\n context.handleError(error);\n }\n}\n\nasync function ensureDevProjectExists(\n context: CliContext,\n template: SyncoreTemplateName\n): Promise<void> {\n if (await hasSyncoreProject(context.cwd)) {\n return;\n }\n\n if (!context.interactive) {\n context.fail(\n \"No Syncore project was found in this directory. Run `npx syncorejs init` first or rerun in an interactive terminal.\"\n );\n }\n\n const shouldScaffold = await context.confirm(\n \"No Syncore project was found. Scaffold one now?\",\n true\n );\n if (!shouldScaffold) {\n context.fail(\"Syncore dev cancelled because no project exists.\");\n }\n\n const result = await context.withSpinner(\"Scaffolding Syncore\", async () =>\n scaffoldProject(context.cwd, {\n template\n })\n );\n if (!context.json) {\n printScaffoldChanges(context, result);\n }\n}\n\ntype ConnectedHub = NonNullable<Awaited<ReturnType<typeof connectToProjectHub>>>;\n\nasync function ensureLocalPortConfiguration(context: CliContext): Promise<void> {\n const dashboardUrl = resolveDashboardUrl();\n const devtoolsUrl = resolveDevtoolsUrl();\n const dashboardPort = Number.parseInt(new URL(dashboardUrl).port, 10);\n const devtoolsPort = Number.parseInt(new URL(devtoolsUrl).port, 10);\n\n if (\n Number.isFinite(dashboardPort) &&\n Number.isFinite(devtoolsPort) &&\n dashboardPort === devtoolsPort\n ) {\n context.fail(\n [\n `Dashboard and devtools cannot share the same port (${dashboardPort}).`,\n \"Set different values for SYNCORE_DASHBOARD_PORT and SYNCORE_DEVTOOLS_PORT, then rerun `npx syncorejs dev`.\"\n ].join(\" \")\n );\n }\n\n if (\n Number.isFinite(dashboardPort) &&\n dashboardPort > 0 &&\n Number.isFinite(devtoolsPort) &&\n devtoolsPort > 0 &&\n (await isLocalPortInUse(dashboardPort)) &&\n !(await isLocalPortInUse(devtoolsPort))\n ) {\n context.warn(\n `Dashboard port ${dashboardPort} is already in use. If Syncore does not start cleanly, set SYNCORE_DASHBOARD_PORT to a different value.`\n );\n }\n}\n\nasync function runDevBootstrapLoop(\n context: CliContext,\n template: SyncoreTemplateName,\n untilSuccess: boolean,\n tailLogs: DevCommandOptions[\"tailLogs\"]\n): Promise<DoctorReport> {\n while (true) {\n try {\n let sawBootstrapFailure = false;\n printCompactDevPhase(context, \"Project\");\n printCompactDevPhase(context, \"Codegen\");\n printCompactDevPhase(context, \"Schema\");\n await withConsoleCapture(\n (method, message) => {\n if (/destructive schema changes/i.test(message)) {\n sawBootstrapFailure = true;\n context.error(\"Syncore dev blocked by destructive schema changes.\");\n return;\n }\n if (/Syncore dev warning:/i.test(message) || method === \"warn\") {\n context.warn(message.replace(/^Syncore dev warning:\\s*/i, \"\"));\n return;\n }\n if (/bootstrap failed/i.test(message) || method === \"error\") {\n sawBootstrapFailure = true;\n context.error(message);\n }\n },\n async () => runDevProjectBootstrap(context.cwd, template)\n );\n const report = await buildDoctorReport(context.cwd);\n if (sawBootstrapFailure || report.status === \"schema-destructive-drift\") {\n if (tailLogs === \"errors\") {\n await printRecentRuntimeSignals(context, context.cwd);\n }\n context.fail(\n report.primaryIssue.summary,\n 1,\n report,\n {\n category: \"runtime\",\n nextSteps: report.suggestions\n }\n );\n }\n return report;\n } catch (error) {\n if (!untilSuccess) {\n throw error;\n }\n context.warn(`Syncore dev bootstrap failed, retrying: ${formatError(error)}`);\n await new Promise((resolve) => setTimeout(resolve, 1200));\n }\n }\n}\n\nasync function startManagedDevHub(\n context: CliContext,\n template: SyncoreTemplateName\n): Promise<DevHubSessionState> {\n printCompactDevPhase(context, \"Hub\");\n printCompactDevPhase(context, \"Targets\");\n return await withConsoleCapture(\n (method, message) => {\n if (/already running/i.test(message)) {\n context.info(message.replaceAll(\"127.0.0.1\", \"localhost\"));\n return;\n }\n if (/Dashboard shell:/i.test(message) || /devtools hub:/i.test(message)) {\n return;\n }\n if (/Watching syncore\\//i.test(message)) {\n context.info(\"Watching syncore/ for changes.\");\n return;\n }\n if (/runtime\\.disconnected/i.test(message)) {\n context.warn(message);\n return;\n }\n if (method === \"warn\") {\n context.warn(message);\n return;\n }\n if (method === \"error\") {\n context.error(message);\n }\n },\n async () =>\n startDevHub({\n cwd: context.cwd,\n template\n })\n );\n}\n\nasync function waitForDashboardReady(\n url: string,\n options: { timeoutMs?: number; intervalMs?: number } = {}\n): Promise<boolean> {\n const timeoutMs = options.timeoutMs ?? 15_000;\n const intervalMs = options.intervalMs ?? 250;\n const deadline = Date.now() + timeoutMs;\n\n while (Date.now() < deadline) {\n try {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), intervalMs);\n try {\n const response = await fetch(url, {\n signal: controller.signal,\n redirect: \"manual\"\n });\n if (response.ok || response.status === 304) {\n return true;\n }\n } finally {\n clearTimeout(timeout);\n }\n } catch {\n // Keep polling until the dashboard responds or the timeout expires.\n }\n await new Promise((resolve) => setTimeout(resolve, intervalMs));\n }\n\n return false;\n}\n\nasync function runDevFollowup(\n context: CliContext,\n options: DevCommandOptions\n): Promise<void> {\n if (options.run) {\n const target = await resolveOperationalTarget(context, undefined, {\n command: \"run\",\n capability: \"run\"\n });\n const resolved = await resolveProjectFunction(context.cwd, options.run);\n if (target.kind === \"project\") {\n const managed = await createManagedProjectClient(context.cwd);\n try {\n const result =\n resolved.definition.kind === \"query\"\n ? await managed.client.query(resolved.reference as never, {})\n : resolved.definition.kind === \"mutation\"\n ? await managed.client.mutation(resolved.reference as never, {})\n : await managed.client.action(resolved.reference as never, {});\n renderOutput(context, result, \"pretty\");\n } finally {\n await managed.dispose();\n }\n } else {\n const hub = await requireHubConnection(context);\n try {\n const result =\n await hub.sendCommand(target.runtimeId, {\n kind: \"fn.run\",\n functionName: resolved.name,\n functionType: resolved.definition.kind,\n args: {}\n });\n if (result.kind !== \"fn.run.result\") {\n context.fail(`Unexpected response from ${target.id}.`, 1, result);\n }\n if (result.error) {\n context.fail(result.error, 1, result);\n }\n renderOutput(context, result.result, \"pretty\");\n } finally {\n await hub.dispose();\n }\n }\n }\n\n if (options.runSh) {\n await runShellCommand(context, options.runSh);\n }\n}\n\nasync function monitorLiveDevSession(\n context: CliContext,\n template: SyncoreTemplateName,\n tailLogs: DevCommandOptions[\"tailLogs\"]\n): Promise<void> {\n const stopTailing =\n tailLogs === \"always\" ? startRuntimeLogTail(context, context.cwd) : undefined;\n if (!templateUsesConnectedClients(template)) {\n try {\n await waitForSignal();\n return;\n } finally {\n stopTailing?.();\n }\n }\n\n let knownTargets = new Set<string>();\n let waitingNoticeVisible = false;\n const refreshTargets = async () => {\n const nextTargets = await listConnectedClientTargets();\n const nextIds = new Set(nextTargets.map((target) => target.id));\n\n for (const target of nextTargets) {\n if (!knownTargets.has(target.id)) {\n context.info(`Client target connected: ${target.id}`);\n }\n }\n for (const targetId of knownTargets) {\n if (!nextIds.has(targetId)) {\n context.warn(`Client target disconnected: ${targetId}`);\n if (tailLogs === \"errors\") {\n await printRecentRuntimeSignals(context, context.cwd);\n }\n }\n }\n\n if (nextTargets.length === 0 && !waitingNoticeVisible) {\n context.info(\"Hub ready. Start your app to connect a client target.\");\n waitingNoticeVisible = true;\n } else if (nextTargets.length > 0) {\n waitingNoticeVisible = false;\n }\n\n knownTargets = nextIds;\n };\n\n await refreshTargets();\n const interval = setInterval(() => {\n void refreshTargets();\n }, 1500);\n\n try {\n await waitForSignal();\n } finally {\n clearInterval(interval);\n stopTailing?.();\n }\n}\n\nfunction validateDevModes(context: CliContext, options: DevCommandOptions): void {\n if (![\"enable\", \"try\", \"disable\"].includes(options.typecheck)) {\n context.fail(\n `Unknown typecheck mode ${JSON.stringify(options.typecheck)}. Expected enable, try, or disable.`\n );\n }\n if (![\"always\", \"errors\", \"disable\"].includes(options.tailLogs)) {\n context.fail(\n `Unknown tail log mode ${JSON.stringify(options.tailLogs)}. Expected always, errors, or disable.`\n );\n }\n}\n\ninterface DevTypecheckResult {\n mode: DevCommandOptions[\"typecheck\"];\n attempted: boolean;\n ok: boolean;\n summary: string;\n details?: string;\n}\n\nfunction printDevPreflight(context: CliContext, report: DoctorReport): void {\n if (report.status === \"missing-generated\") {\n context.info(\"Preflight: generated Syncore files are missing; dev will refresh them.\");\n return;\n }\n if (report.status === \"schema-drift\") {\n context.info(\"Preflight: schema drift detected; dev will refresh local Syncore state where safe.\");\n return;\n }\n if (report.status === \"waiting-for-client\") {\n context.info(\"Preflight: this template uses client-managed runtimes; connect the app to unlock live targets.\");\n return;\n }\n context.info(\"Preflight: Syncore project structure and local runtime prerequisites were inspected.\");\n}\n\nasync function runDevTypecheck(\n context: CliContext,\n mode: DevCommandOptions[\"typecheck\"]\n): Promise<DevTypecheckResult> {\n if (mode === \"disable\") {\n return {\n mode,\n attempted: false,\n ok: true,\n summary: \"disabled\"\n };\n }\n\n const tsconfigPath = await findTypecheckConfig(context.cwd);\n if (!tsconfigPath) {\n if (mode === \"enable\") {\n context.fail(\"Typecheck was enabled but no tsconfig.json was found in this project.\");\n }\n context.warn(\"Typecheck skipped because no tsconfig.json was found.\");\n return {\n mode,\n attempted: false,\n ok: true,\n summary: \"skipped (no tsconfig)\"\n };\n }\n\n const tscPath = await findTypeScriptCompiler(context.cwd);\n if (!tscPath) {\n if (mode === \"enable\") {\n context.fail(\"Typecheck was enabled but no local TypeScript compiler was found.\");\n }\n context.warn(\"Typecheck skipped because TypeScript is not available in this workspace.\");\n return {\n mode,\n attempted: false,\n ok: true,\n summary: \"skipped (tsc unavailable)\"\n };\n }\n\n context.info(`Typecheck: running tsc --noEmit -p ${path.basename(tsconfigPath)}.`);\n const result = await runTypeScriptCompiler(context.cwd, tscPath, tsconfigPath);\n if (result.ok) {\n context.success(\"Typecheck passed.\");\n return {\n mode,\n attempted: true,\n ok: true,\n summary: \"passed\"\n };\n }\n\n const detail = summarizeCompilerOutput(result.output);\n if (mode === \"enable\") {\n context.fail(\n `Typecheck failed.${detail ? ` ${detail}` : \"\"}`,\n 1,\n result.output,\n {\n category: \"validation\"\n }\n );\n }\n context.warn(`Typecheck reported issues but dev will continue.${detail ? ` ${detail}` : \"\"}`);\n return {\n mode,\n attempted: true,\n ok: false,\n summary: \"warning\",\n ...(detail ? { details: detail } : {})\n };\n}\n\nasync function findTypecheckConfig(cwd: string): Promise<string | null> {\n for (const candidate of [\n \"tsconfig.json\",\n \"tsconfig.app.json\",\n \"tsconfig.main.json\",\n \"tsconfig.build.json\"\n ]) {\n const resolved = path.join(cwd, candidate);\n if (await fileExists(resolved)) {\n return resolved;\n }\n }\n return null;\n}\n\nasync function findTypeScriptCompiler(cwd: string): Promise<string | null> {\n const executableName = process.platform === \"win32\" ? \"tsc.cmd\" : \"tsc\";\n let current = cwd;\n while (true) {\n const candidate = path.join(current, \"node_modules\", \".bin\", executableName);\n if (await fileExists(candidate)) {\n return candidate;\n }\n const parent = path.dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n return null;\n}\n\nasync function runTypeScriptCompiler(\n cwd: string,\n compilerPath: string,\n tsconfigPath: string\n): Promise<{ ok: boolean; output: string }> {\n return await new Promise((resolve, reject) => {\n const isWindowsCmd =\n process.platform === \"win32\" && /\\.(cmd|bat)$/i.test(compilerPath);\n const child = spawn(compilerPath, [\"--noEmit\", \"-p\", tsconfigPath], {\n cwd,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n ...(isWindowsCmd ? { shell: true } : {})\n });\n let output = \"\";\n child.stdout.on(\"data\", (chunk: Buffer | string) => {\n output += chunk.toString();\n });\n child.stderr.on(\"data\", (chunk: Buffer | string) => {\n output += chunk.toString();\n });\n child.once(\"error\", reject);\n child.once(\"exit\", (code: number | null) => {\n resolve({\n ok: (code ?? 1) === 0,\n output: output.trim()\n });\n });\n });\n}\n\nfunction summarizeCompilerOutput(output: string): string | undefined {\n const firstMeaningfulLine = output\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find(Boolean);\n return firstMeaningfulLine;\n}\n\nfunction describeTypecheckStatus(result: DevTypecheckResult): string {\n return result.details ? `${result.summary} (${result.details})` : result.summary;\n}\n\nfunction describeDevDriftStatus(report: DoctorReport): string {\n switch (report.drift.state) {\n case \"clean\":\n return \"clean\";\n case \"missing-snapshot\":\n return \"snapshot refreshed\";\n case \"snapshot-outdated\":\n return \"snapshot refreshed\";\n case \"migration-pending\":\n return \"migration review pending\";\n case \"destructive\":\n return \"blocked\";\n default:\n return \"unavailable\";\n }\n}\n\nasync function requireHubConnection(context: CliContext): Promise<ConnectedHub> {\n const hub = await connectToProjectHub();\n if (!hub) {\n context.fail(\n \"The local devtools hub is not running.\",\n 1,\n undefined,\n {\n category: \"hub\",\n nextSteps: buildHubUnavailableNextSteps()\n }\n );\n }\n return hub;\n}\n\nasync function listRemoteTables(\n runtimeId: string,\n context: CliContext\n): Promise<Array<{ name: string; documentCount: number }>> {\n const hub = await requireHubConnection(context);\n try {\n const result = await subscribeOnce(hub, runtimeId, {\n kind: \"schema.tables\"\n });\n if (result.kind !== \"schema.tables.result\") {\n context.fail(\"Unexpected response while listing remote tables.\", 1, result);\n }\n return result.tables.map((table) => ({\n name: table.name,\n documentCount: table.documentCount\n }));\n } finally {\n await hub.dispose();\n }\n}\n\nasync function readRemoteTable(\n hub: ConnectedHub,\n runtimeId: string,\n table: string,\n options: {\n limit: number;\n }\n): Promise<Extract<\n Awaited<ReturnType<typeof subscribeOnce>>,\n { kind: \"data.table.result\" }\n>> {\n const result = await subscribeOnce(hub, runtimeId, {\n kind: \"data.table\",\n table,\n limit: options.limit\n });\n if (result.kind !== \"data.table.result\") {\n throw new Error(`Unexpected response while reading table ${table}.`);\n }\n return result;\n}\n\nasync function importIntoClientTarget(\n context: CliContext,\n target: ClientTargetDescriptor,\n runtime: ClientTargetDescriptor[\"runtimes\"][number],\n sourcePath: string,\n options: ImportCommandOptions\n): Promise<Array<{ table: string; importedCount: number }>> {\n const batches = await loadImportDocumentBatches(context.cwd, sourcePath, {\n ...(options.table ? { table: options.table } : {})\n });\n const hub = await requireHubConnection(context);\n try {\n const results: Array<{ table: string; importedCount: number }> = [];\n for (const batch of batches) {\n let importedCount = 0;\n for (const row of batch.rows) {\n const payload = { ...row };\n delete payload._id;\n delete payload._creationTime;\n const result = await hub.sendCommand(runtime.runtimeId, {\n kind: \"data.insert\",\n table: batch.table,\n document: payload\n });\n if (result.kind !== \"data.mutate.result\" || !result.success) {\n const message =\n result.kind === \"data.mutate.result\"\n ? result.error ?? `Failed to import into ${batch.table}.`\n : `Unexpected response while importing into ${batch.table}.`;\n context.fail(message, 1, result);\n }\n importedCount += 1;\n }\n results.push({\n table: batch.table,\n importedCount\n });\n }\n return results;\n } finally {\n await hub.dispose();\n }\n}\n\nasync function exportClientTargetData(\n context: CliContext,\n target: ClientTargetDescriptor,\n runtime: ClientTargetDescriptor[\"runtimes\"][number],\n options: ExportCommandOptions\n): Promise<{\n path: string;\n tables: string[];\n format: \"json\" | \"jsonl\" | \"directory\" | \"zip\";\n}> {\n const hub = await requireHubConnection(context);\n try {\n const tables = options.table\n ? [options.table]\n : (await listRemoteTables(runtime.runtimeId, context)).map(\n (entry: { name: string }) => entry.name\n );\n const payloads = await Promise.all(\n tables.map(async (table) => ({\n table,\n rows: (await readRemoteTable(hub, runtime.runtimeId, table, {\n limit: Number.MAX_SAFE_INTEGER\n })).rows\n }))\n );\n return await writeExportData(path.resolve(context.cwd, options.path), payloads);\n } finally {\n await hub.dispose();\n }\n}\n\nasync function runLogsCommand(\n context: CliContext,\n options: LogsCommandOptions\n): Promise<void> {\n const availableTargets = await listAvailableTargets(context.cwd);\n const runtimeLookup = buildRuntimeLookup(availableTargets);\n const selectedTarget =\n options.target && options.target !== \"all\"\n ? availableTargets.find((target) => target.id === options.target)\n : undefined;\n if (options.target && options.target !== \"all\" && !selectedTarget) {\n context.fail(\n `Unknown target ${JSON.stringify(options.target)}. Available targets: ${availableTargets.map((target) => target.id).join(\", \")}`\n );\n }\n const selectedRuntime = selectedTarget\n ? resolveClientRuntime(selectedTarget, options.runtime, {\n command: \"logs\"\n })\n : null;\n const allowedRuntimeIds =\n selectedTarget?.kind === \"client\" ? new Set(selectedTarget.runtimeIds) : undefined;\n const entries = await readPersistedLogs(context.cwd);\n const filtered = entries\n .map((entry) => decoratePersistedLogEntry(entry, runtimeLookup))\n .filter((entry) =>\n options.target && options.target !== \"all\"\n ? entry.targetId === options.target ||\n (allowedRuntimeIds ? allowedRuntimeIds.has(entry.runtimeId) : false)\n : true\n )\n .filter((entry) =>\n selectedRuntime ? entry.runtimeId === selectedRuntime.runtimeId : true\n )\n .filter((entry) => (options.kind ? entry.category === options.kind : true))\n .slice(-Number.parseInt(options.limit, 10));\n\n renderOutput(context, filtered, options.format);\n\n if (!options.watch) {\n return;\n }\n\n const hub = await requireHubConnection(context);\n const unsubscribe = hub.onEvent((event) => {\n const entry = normalizeRuntimeEvent(\n event,\n runtimeLookup.get(event.runtimeId)\n );\n if (!entry) {\n return;\n }\n if (\n options.target &&\n options.target !== \"all\" &&\n entry.targetId !== options.target &&\n !(allowedRuntimeIds ? allowedRuntimeIds.has(entry.runtimeId) : false)\n ) {\n return;\n }\n if (options.kind && entry.category !== options.kind) {\n return;\n }\n if (selectedRuntime && entry.runtimeId !== selectedRuntime.runtimeId) {\n return;\n }\n renderOutput(context, entry, options.format);\n });\n context.info(\"Streaming logs. Press Ctrl+C to stop.\");\n await waitForSignal();\n unsubscribe();\n await hub.dispose();\n}\n\nasync function readPersistedLogs(cwd: string): Promise<PersistedLogEntry[]> {\n const logPath = path.join(cwd, \".syncore\", \"logs\", \"runtime.jsonl\");\n try {\n await stat(logPath);\n } catch {\n return [];\n }\n\n const source = await readFile(logPath, \"utf8\");\n return source\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter(Boolean)\n .map((line) => JSON.parse(line) as PersistedLogEntry)\n .filter((entry) => entry.version === 2)\n .filter((entry) => !shouldSuppressLogEntry(entry));\n}\n\nasync function printRecentRuntimeSignals(\n context: CliContext,\n cwd: string,\n limit = 5\n): Promise<void> {\n const entries = await readPersistedLogs(cwd);\n const recent = entries.slice(-limit);\n if (recent.length === 0) {\n return;\n }\n context.info(\"Recent runtime signals:\");\n for (const entry of recent) {\n process.stdout.write(` ${formatPersistedLogEntry(entry)}\\n`);\n }\n}\n\nfunction startRuntimeLogTail(\n context: CliContext,\n cwd: string\n): () => void {\n let seenCount = 0;\n let disposed = false;\n const poll = async () => {\n if (disposed) {\n return;\n }\n const entries = await readPersistedLogs(cwd);\n const next = entries.slice(seenCount);\n for (const entry of next) {\n process.stdout.write(`${formatPersistedLogEntry(entry)}\\n`);\n }\n seenCount = entries.length;\n };\n const interval = setInterval(() => {\n void poll();\n }, 1200);\n void poll();\n return () => {\n disposed = true;\n clearInterval(interval);\n };\n}\n\nfunction normalizeRuntimeEvent(\n event: Record<string, unknown> & { type: string; runtimeId: string; timestamp: number },\n runtimeEntry?: ClientRuntimeLookupEntry\n): PersistedLogEntry | null {\n const functionName =\n typeof event.functionName === \"string\" ? event.functionName : \"unknown\";\n const functionComponent = resolveComponentInfoFromFunctionName(functionName);\n const queryComponent =\n typeof event.queryId === \"string\"\n ? resolveComponentInfoFromFunctionName(formatInvalidatedQueryId(event.queryId))\n : undefined;\n const storageComponent =\n typeof event.storageId === \"string\"\n ? resolveComponentInfoFromScopedValue(event.storageId)\n : undefined;\n const componentInfo =\n typeof event.componentPath === \"string\"\n ? {\n owner: \"component\" as const,\n componentPath: event.componentPath,\n ...(typeof event.componentName === \"string\"\n ? { componentName: event.componentName }\n : {})\n }\n : functionComponent ?? queryComponent ?? storageComponent;\n const logMessage =\n typeof event.message === \"string\" ? event.message : \"Syncore log\";\n const resolvedTargetId =\n event.runtimeId === \"syncore-dev-hub\"\n ? \"all\"\n : (runtimeEntry?.targetId ?? event.runtimeId);\n const runtimeLabel =\n event.runtimeId === \"syncore-dev-hub\"\n ? \"dashboard\"\n : (runtimeEntry?.label ?? \"runtime\");\n const publicRuntimeId =\n event.runtimeId === \"syncore-dev-hub\"\n ? undefined\n : (runtimeEntry?.id ?? createPublicRuntimeId(event.runtimeId));\n const targetLabel = runtimeEntry?.targetLabel;\n const origin =\n event.origin === \"dashboard\" || event.runtimeId === \"syncore-dev-hub\"\n ? \"dashboard\"\n : \"runtime\";\n const entryBase = {\n timestamp: event.timestamp,\n runtimeId: event.runtimeId,\n targetId: resolvedTargetId,\n ...(targetLabel ? { targetLabel } : {}),\n ...(publicRuntimeId ? { publicRuntimeId } : {}),\n ...(runtimeLabel ? { runtimeLabel } : {}),\n origin\n } satisfies Pick<\n PersistedLogEntry,\n | \"timestamp\"\n | \"runtimeId\"\n | \"targetId\"\n | \"targetLabel\"\n | \"publicRuntimeId\"\n | \"runtimeLabel\"\n | \"origin\"\n >;\n\n if (\n event.type === \"log\" &&\n shouldSuppressLogEntry({\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n ...(componentInfo ?? {}),\n message: logMessage,\n event\n })\n ) {\n return null;\n }\n\n switch (event.type) {\n case \"query.executed\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"query\",\n ...(componentInfo ?? {}),\n message: `${functionName} executed`,\n event\n };\n case \"query.invalidated\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n ...(componentInfo ?? {}),\n message: `${formatInvalidatedQueryId(event.queryId)} invalidated${typeof event.reason === \"string\" ? ` (${event.reason})` : \"\"}`,\n event\n };\n case \"mutation.committed\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"mutation\",\n ...(componentInfo ?? {}),\n message:\n Array.isArray(event.changedTables) && event.changedTables.length > 0\n ? `${functionName} committed (${event.changedTables.join(\", \")})`\n : `${functionName} committed`,\n event\n };\n case \"action.completed\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"action\",\n ...(componentInfo ?? {}),\n message:\n typeof event.error === \"string\" && event.error.length > 0\n ? `${functionName} failed: ${event.error}`\n : `${functionName} completed`,\n event\n };\n case \"runtime.connected\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: `${publicRuntimeId ?? \"runtime\"} ${runtimeLabel} connected`,\n event\n };\n case \"runtime.disconnected\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n message: `${publicRuntimeId ?? \"runtime\"} ${runtimeLabel} disconnected`,\n event\n };\n case \"storage.updated\":\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n ...(componentInfo ?? {}),\n message: `${typeof event.operation === \"string\" ? event.operation : \"update\"} ${typeof event.storageId === \"string\" ? event.storageId : \"storage\"}`,\n event\n };\n default:\n return {\n ...entryBase,\n eventType: event.type,\n category: \"system\",\n ...(componentInfo ?? {}),\n message: event.type === \"log\" ? logMessage : humanizeRuntimeEvent(event),\n event\n };\n }\n}\n\nfunction decoratePersistedLogEntry(\n entry: PersistedLogEntry,\n runtimeLookup: ReturnType<typeof buildRuntimeLookup>\n): PersistedLogEntry {\n const runtime = runtimeLookup.get(entry.runtimeId);\n return {\n ...entry,\n targetId:\n entry.targetId === \"all\"\n ? \"all\"\n : runtime?.targetId ?? entry.targetId ?? entry.runtimeId,\n ...(runtime?.targetLabel ? { targetLabel: runtime.targetLabel } : {}),\n ...(runtime?.id ? { publicRuntimeId: runtime.id } : {}),\n ...(runtime?.label ? { runtimeLabel: runtime.label } : {}),\n ...(entry.origin ? {} : { origin: entry.runtimeId === \"syncore-dev-hub\" ? \"dashboard\" : \"runtime\" })\n };\n}\n\nfunction shouldSuppressLogEntry(entry: PersistedLogEntry): boolean {\n return (\n entry.eventType === \"log\" &&\n /syncore devtools hub is alive/i.test(entry.message)\n );\n}\n\nfunction formatInvalidatedQueryId(queryId: unknown): string {\n if (typeof queryId !== \"string\" || queryId.length === 0) {\n return \"query\";\n }\n const separatorIndex = queryId.indexOf(\":\");\n if (separatorIndex === -1) {\n return queryId;\n }\n return queryId.slice(0, separatorIndex);\n}\n\nfunction resolveComponentInfoFromFunctionName(functionName: string):\n | {\n owner: \"component\";\n componentPath: string;\n }\n | undefined {\n const match = /^components\\/(.+)\\/(public|internal)\\/(.+)$/.exec(functionName);\n if (!match) {\n return undefined;\n }\n return {\n owner: \"component\",\n componentPath: match[1] ?? \"\"\n };\n}\n\nfunction resolveComponentInfoFromScopedValue(value: string):\n | {\n owner: \"component\";\n componentPath: string;\n }\n | undefined {\n const match = /^component:([^:]+):(.+)$/.exec(value);\n if (!match) {\n return undefined;\n }\n return {\n owner: \"component\",\n componentPath: match[1] ?? \"\"\n };\n}\n\nfunction humanizeRuntimeEvent(\n event: Record<string, unknown> & { type: string }\n): string {\n if (event.type === \"scheduler.tick\" && Array.isArray(event.executedJobIds)) {\n return `scheduler tick (${event.executedJobIds.length} job(s))`;\n }\n return event.type.replaceAll(\".\", \" \");\n}\n\nasync function subscribeOnce(\n hub: ConnectedHub,\n runtimeId: string,\n payload: Parameters<ConnectedHub[\"subscribe\"]>[1]\n): Promise<SyncoreDevtoolsSubscriptionResultPayload> {\n return await new Promise((resolve, reject) => {\n const unsubscribe = hub.subscribe(runtimeId, payload, {\n onData(result) {\n unsubscribe();\n resolve(result);\n },\n onError(error) {\n unsubscribe();\n reject(new Error(error));\n }\n });\n });\n}\n\nasync function promptForTemplate(\n context: CliContext,\n detectedTemplate: string\n): Promise<SyncoreTemplateName> {\n const choices: CliChoice<SyncoreTemplateName>[] = VALID_SYNCORE_TEMPLATES.map(\n (template) =>\n template === detectedTemplate\n ? {\n label: template,\n value: template,\n description: \"Detected from the current project\"\n }\n : {\n label: template,\n value: template\n }\n );\n return await context.select(\n \"Choose a Syncore template for this directory.\",\n choices,\n isKnownTemplate(detectedTemplate) ? detectedTemplate : VALID_SYNCORE_TEMPLATES[0]\n );\n}\n\nasync function isDirectoryEmpty(directory: string): Promise<boolean> {\n try {\n const entries = await readdir(directory);\n return entries.length === 0;\n } catch {\n return true;\n }\n}\n\nfunction printScaffoldChanges(\n context: CliContext,\n result: Awaited<ReturnType<typeof scaffoldProject>>\n): void {\n if (result.created.length > 0) {\n context.info(`Created: ${result.created.join(\", \")}`);\n }\n if (result.updated.length > 0) {\n context.info(`Updated: ${result.updated.join(\", \")}`);\n }\n if (result.skipped.length > 0) {\n context.warn(`Kept existing: ${result.skipped.join(\", \")}`);\n }\n}\n\nfunction isTargetCapability(value: string): value is TargetCapability {\n return (\n value === \"run\" ||\n value === \"readData\" ||\n value === \"writeData\" ||\n value === \"exportData\" ||\n value === \"streamLogs\"\n );\n}\n\nasync function previewImportPlan(\n context: CliContext,\n sourcePath: string,\n options: ImportCommandOptions,\n targetId: string\n): Promise<{\n target: string;\n format: string;\n totalRows: number;\n batches: Array<{ table: string; rowCount: number }>;\n}> {\n const batches = await loadImportDocumentBatches(context.cwd, sourcePath, {\n ...(options.table ? { table: options.table } : {})\n });\n const preview = {\n target: targetId,\n format: path.extname(sourcePath).toLowerCase() || \"directory\",\n totalRows: batches.reduce((sum, batch) => sum + batch.rows.length, 0),\n batches: batches.map((batch) => ({\n table: batch.table,\n rowCount: batch.rows.length\n }))\n };\n\n if (!context.json && context.interactive) {\n process.stdout.write(\"Import preview:\\n\");\n process.stdout.write(` target: ${preview.target}\\n`);\n process.stdout.write(` source: ${sourcePath}\\n`);\n process.stdout.write(` format: ${preview.format}\\n`);\n for (const batch of preview.batches) {\n process.stdout.write(` - ${batch.table}: ${batch.rowCount} row(s)\\n`);\n }\n }\n\n return preview;\n}\n\nfunction parseJsonObject(input: string, label: string): Record<string, unknown> {\n let parsed: unknown;\n try {\n parsed = JSON.parse(input);\n } catch (error) {\n throw new Error(`${label} must be valid JSON: ${formatError(error)}`);\n }\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n throw new Error(`${label} must be a JSON object.`);\n }\n return parsed as Record<string, unknown>;\n}\n\nasync function waitForSignal(): Promise<void> {\n await new Promise<void>((resolve) => {\n const onSignal = () => {\n process.off(\"SIGINT\", onSignal);\n process.off(\"SIGTERM\", onSignal);\n resolve();\n };\n process.on(\"SIGINT\", onSignal);\n process.on(\"SIGTERM\", onSignal);\n });\n}\n\nfunction parseGlobalOptionsFromArgv(argv: string[]): GlobalCliOptions {\n const parsed: GlobalCliOptions = {};\n for (let index = 0; index < argv.length; index += 1) {\n const value = argv[index];\n if (value === \"--cwd\") {\n const nextValue = argv[index + 1];\n if (nextValue) {\n parsed.cwd = nextValue;\n }\n index += 1;\n continue;\n }\n if (value === \"--json\") {\n parsed.json = true;\n continue;\n }\n if (value === \"--verbose\") {\n parsed.verbose = true;\n continue;\n }\n if (value === \"--no-interactive\") {\n parsed.interactive = false;\n continue;\n }\n if (value === \"--yes\" || value === \"-y\") {\n parsed.yes = true;\n }\n }\n return parsed;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgJA,eAAsB,cAAc,OAAO,QAAQ,MAAqB;CACtE,MAAM,UAAU,cAAc;AAE9B,KAAI,KAAK,UAAU,EACjB,QAAO,CAAC,GAAG,MAAM,SAAS;AAG5B,KAAI;AACF,QAAM,QAAQ,WAAW,KAAK;UACvB,OAAO;AACE,MAAI,WAAW,2BAA2B,KAAK,CAAC,CACxD,YAAY,MAAM;;;AAI9B,SAAgB,eAAwB;CACtC,MAAM,UAAU,IAAI,SAAS;AAC7B,SACG,KAAK,YAAY,CACjB,MAAM,sBAAsB,CAC5B,OAAO,gBAAgB,yDAAyD,CAChF,OAAO,UAAU,oCAAoC,CACrD,OAAO,aAAa,+BAA+B,CACnD,OAAO,oBAAoB,kCAAkC,CAC7D,OAAO,aAAa,+BAA+B,CACnD,oBAAoB,CACpB,0BAA0B,CAC1B,YAAY,kBAAkB,0BAA0B;AAC3D,eAAc,QAAQ;AAEtB,gBAAe,QAAQ;AACvB,mBAAkB,QAAQ;AAC1B,kBAAiB,QAAQ;AACzB,mBAAkB,QAAQ;AAC1B,eAAc,QAAQ;AACtB,mBAAkB,QAAQ;AAC1B,eAAc,QAAQ;AACtB,gBAAe,QAAQ;AACvB,kBAAiB,QAAQ;AACzB,kBAAiB,QAAQ;AACzB,gBAAe,QAAQ;AACvB,qBAAoB,QAAQ;AAC5B,gBAAe,QAAQ;AAEvB,QAAO;;AAGT,SAAS,eAAe,SAAwB;AAC9C,SACG,QAAQ,OAAO,CACf,QAAQ,4CAA4C,CACpD,YAAY,oFAAoF,CAChG,OACC,yBACA,yBAAyB,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AAU;AACjB;;AAEF,MAAI,UAAU,oBAAoB;AAChC,UAAO,cAAc;AACrB;;AAEF,MAAI,UAAU,WAAW,UAAU,KACjC,QAAO,MAAM;;AAGjB,QAAO"}
@@ -4,6 +4,24 @@ import { spawn } from "node:child_process";
4
4
  import process from "node:process";
5
5
  import readline from "node:readline/promises";
6
6
  //#region src/context.ts
7
+ const ANSI = {
8
+ reset: "\x1B[0m",
9
+ bold: "\x1B[1m",
10
+ yellow: "\x1B[33m",
11
+ cyan: "\x1B[36m",
12
+ green: "\x1B[32m",
13
+ red: "\x1B[31m",
14
+ magenta: "\x1B[35m",
15
+ dim: "\x1B[2m"
16
+ };
17
+ function supportsColor(stream) {
18
+ return Boolean(stream.isTTY) && process.env.NO_COLOR !== "1" && process.env.TERM !== "dumb";
19
+ }
20
+ function formatPrefix(stream, level) {
21
+ const plain = `[${level}]`;
22
+ if (!supportsColor(stream)) return plain;
23
+ return `${level === "info" ? ANSI.cyan : level === "done" ? ANSI.green : level === "warn" ? ANSI.yellow : level === "error" || level === "fail" ? ANSI.red : level === "next" ? ANSI.magenta : ANSI.dim}[${level}]${ANSI.reset}`;
24
+ }
7
25
  var CliContext = class {
8
26
  cwd;
9
27
  json;
@@ -18,19 +36,19 @@ var CliContext = class {
18
36
  this.interactive = options.interactive === false ? false : process.env.SYNCORE_FORCE_INTERACTIVE === "1" ? true : Boolean(process.stdin.isTTY && process.stdout.isTTY && !this.json);
19
37
  }
20
38
  info(message) {
21
- if (!this.json) process.stdout.write(`[info] ${message}\n`);
39
+ if (!this.json) process.stdout.write(`${formatPrefix(process.stdout, "info")} ${message}\n`);
22
40
  }
23
41
  success(message) {
24
- if (!this.json) process.stdout.write(`[done] ${message}\n`);
42
+ if (!this.json) process.stdout.write(`${formatPrefix(process.stdout, "done")} ${message}\n`);
25
43
  }
26
44
  warn(message) {
27
- if (!this.json) process.stderr.write(`[warn] ${message}\n`);
45
+ if (!this.json) process.stderr.write(`${formatPrefix(process.stderr, "warn")} ${message}\n`);
28
46
  }
29
47
  error(message) {
30
- if (!this.json) process.stderr.write(`[error] ${message}\n`);
48
+ if (!this.json) process.stderr.write(`${formatPrefix(process.stderr, "error")} ${message}\n`);
31
49
  }
32
50
  nextStep(message) {
33
- if (!this.json) process.stdout.write(`[next] ${message}\n`);
51
+ if (!this.json) process.stdout.write(`${formatPrefix(process.stdout, "next")} ${message}\n`);
34
52
  }
35
53
  printJson(payload) {
36
54
  process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
@@ -129,19 +147,19 @@ var CliContext = class {
129
147
  "/"
130
148
  ];
131
149
  let index = 0;
132
- process.stderr.write(`[work] ${label}`);
150
+ process.stderr.write(`${formatPrefix(process.stderr, "work")} ${label}`);
133
151
  const timer = setInterval(() => {
134
- process.stderr.write(`\r[${frames[index % frames.length]}] ${label}`);
152
+ process.stderr.write(`\r${formatPrefix(process.stderr, "work")} ${frames[index % frames.length]} ${label}`);
135
153
  index += 1;
136
154
  }, 80);
137
155
  try {
138
156
  const result = await action();
139
157
  clearInterval(timer);
140
- process.stderr.write(`\r[done] ${label}\n`);
158
+ process.stderr.write(`\r${formatPrefix(process.stderr, "done")} ${label}\n`);
141
159
  return result;
142
160
  } catch (error) {
143
161
  clearInterval(timer);
144
- process.stderr.write(`\r[fail] ${label}\n`);
162
+ process.stderr.write(`\r${formatPrefix(process.stderr, "fail")} ${label}\n`);
145
163
  throw error;
146
164
  }
147
165
  }