gencow 0.1.299 → 0.2.0

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 (149) hide show
  1. package/bin/gencow.mjs +0 -6
  2. package/core/package.json +1 -1
  3. package/docs/packaging.md +14 -4
  4. package/lib/cli-artifact-guard.mjs +53 -3
  5. package/lib/cli-dev-runtime.mjs +1 -0
  6. package/lib/cli-project-runtime.mjs +26 -14
  7. package/lib/codegen-command.mjs +16 -0
  8. package/lib/coding-guardrails.mjs +2 -0
  9. package/lib/dashboard-artifact.mjs +65 -0
  10. package/lib/dashboard-assets.mjs +20 -0
  11. package/lib/db-command.mjs +121 -80
  12. package/lib/db-migration-command-steps.mjs +19 -16
  13. package/lib/db-push-command.mjs +1 -1
  14. package/lib/deploy-codegen-preflight.mjs +1 -0
  15. package/lib/dev-cloud-command.mjs +1 -1
  16. package/lib/dev-local-command.mjs +19 -56
  17. package/lib/document-local-converter.mjs +11 -0
  18. package/lib/local-dashboard-plan.mjs +60 -0
  19. package/lib/local-database-commands.mjs +127 -0
  20. package/lib/local-development-migrations.mjs +157 -0
  21. package/lib/local-drizzle-database.config.mjs +10 -0
  22. package/lib/local-runtime-features.mjs +12 -0
  23. package/lib/rag-selection.mjs +7 -0
  24. package/lib/runtime-local-worker.mjs +116 -0
  25. package/lib/runtime-mode.mjs +3 -0
  26. package/lib/standalone-codegen-adapter.mjs +91 -0
  27. package/lib/ts-codegen-import-extension.mjs +228 -19
  28. package/package.json +16 -9
  29. package/runtime/config.mjs +218 -2
  30. package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
  31. package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
  32. package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
  33. package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
  34. package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
  35. package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
  36. package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
  37. package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
  38. package/runtime/engine/chunk-5575APCJ.mjs +215 -0
  39. package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
  40. package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
  41. package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
  42. package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
  43. package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
  44. package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
  45. package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
  46. package/runtime/engine/chunk-6W653LXI.mjs +13 -0
  47. package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
  48. package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
  49. package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
  50. package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
  51. package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
  52. package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
  53. package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
  54. package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
  55. package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
  56. package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
  57. package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
  58. package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
  59. package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
  60. package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
  61. package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
  62. package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
  63. package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
  64. package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
  65. package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
  66. package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
  67. package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
  68. package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
  69. package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
  70. package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
  71. package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
  72. package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
  73. package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
  74. package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
  75. package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
  76. package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
  77. package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
  78. package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
  79. package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
  80. package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
  81. package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
  82. package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
  83. package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
  84. package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
  85. package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
  86. package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
  87. package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
  88. package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
  89. package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
  90. package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
  91. package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
  92. package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
  93. package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
  94. package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
  95. package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
  96. package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
  97. package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
  98. package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
  99. package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
  100. package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
  101. package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
  102. package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
  103. package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
  104. package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
  105. package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
  106. package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
  107. package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
  108. package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
  109. package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
  110. package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
  111. package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
  112. package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
  113. package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
  114. package/runtime/engine/chunk-YRHM272W.mjs +528 -0
  115. package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
  116. package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
  117. package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
  118. package/runtime/engine/composition.mjs +325 -0
  119. package/runtime/engine/document-local.mjs +504 -0
  120. package/runtime/engine/graph.json +4134 -0
  121. package/runtime/engine/index.mjs +265 -0
  122. package/runtime/engine/local-postgres-support.mjs +69 -0
  123. package/runtime/engine/local.mjs +3275 -0
  124. package/runtime/engine/pglite-directory-lock.mjs +8 -0
  125. package/runtime/engine/rag.mjs +11 -0
  126. package/runtime/engine/search.mjs +18 -0
  127. package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
  128. package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
  129. package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
  130. package/runtime/framework-migrations/manifest.json +56 -0
  131. package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
  132. package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
  133. package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
  134. package/runtime/runtime-metadata.json +27 -0
  135. package/runtime/tooling.mjs +10399 -8951
  136. package/scripts/bundle-runtime-config.mjs +23 -0
  137. package/scripts/bundle-runtime.mjs +100 -0
  138. package/scripts/bundle-runtime.test.mjs +33 -0
  139. package/scripts/bundle-shared.mjs +3 -0
  140. package/scripts/copy-dashboard.mjs +16 -0
  141. package/scripts/pre-publish-check.mjs +23 -11
  142. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  143. package/templateFeature/tools/manifest.json +2 -1
  144. package/templateFeature/tools/tools.ts +3 -3
  145. package/runtime/server.mjs +0 -14389
  146. package/scripts/bundle-server.mjs +0 -223
  147. package/server/config.js +0 -1
  148. package/server/index.js +0 -1
  149. package/server/package.json +0 -6
@@ -0,0 +1,127 @@
1
+ import { buildLocalExecutionFailureDiagnostic } from "./migration-client-diagnostic.mjs";
2
+ import { renderMigrationDiagnosticLines } from "./migration-diagnostic.mjs";
3
+ import { spawnSync } from "node:child_process";
4
+ import { dirname, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import {
7
+ applyLocalDevelopmentMigrations,
8
+ classifyLocalMigrationCommandFailure,
9
+ localMigrationDiagnostic,
10
+ localMigrationOutputFailure,
11
+ requireLocalPostgresUrl,
12
+ } from "./local-development-migrations.mjs";
13
+ import { resolveProjectSelection } from "./project-context.mjs";
14
+ import { resolveLocalRuntimeFeatures } from "./local-runtime-features.mjs";
15
+ import { runDrizzleGenerateWithFallback } from "./drizzle-generate.mjs";
16
+
17
+ const configPath = resolve(dirname(fileURLToPath(import.meta.url)), "local-drizzle-database.config.mjs");
18
+
19
+ function runPostgresPush(deps, env) {
20
+ const tool = deps.drizzleKitCmdImpl("push", { canonicalConfigPath: configPath });
21
+ let result;
22
+ try {
23
+ result = (deps.spawnSyncImpl ?? spawnSync)(tool.command, [...tool.args, "--force"], {
24
+ cwd: deps.cwdImpl(),
25
+ env: { ...env, ...tool.env },
26
+ stdio: "pipe",
27
+ shell: false,
28
+ });
29
+ } catch {
30
+ result = { error: true };
31
+ }
32
+ if (result.error || result.status !== 0) {
33
+ // Never leak a subprocess exception containing credentials or raw SQL.
34
+ const diagnostic = buildLocalExecutionFailureDiagnostic(crypto.randomUUID());
35
+ const failure = new Error(renderMigrationDiagnosticLines(diagnostic).join("\n"));
36
+ failure.diagnostic = diagnostic;
37
+ throw failure;
38
+ }
39
+ }
40
+
41
+ export async function runLocalDatabaseCommand({ command, config, deps, jsonMode = false }) {
42
+ const projectDir = deps.cwdImpl();
43
+ const env = deps.buildEnv(config, {
44
+ cwd: projectDir,
45
+ processEnv: deps.processEnv ?? process.env,
46
+ localStorage: config.localFeatures?.storage,
47
+ });
48
+ const { database } = await resolveLocalRuntimeFeatures(config, env);
49
+ if (database.adapter === "postgres") requireLocalPostgresUrl(env);
50
+ if (command === "db:push") {
51
+ if (database.adapter === "postgres") return runPostgresPush(deps, env);
52
+ runDrizzleGenerateWithFallback({
53
+ cwd: projectDir,
54
+ drizzleKitCmdImpl: deps.drizzleKitCmdImpl,
55
+ env,
56
+ execSyncImpl: deps.execSyncImpl,
57
+ stdio: jsonMode ? "pipe" : "inherit",
58
+ warnImpl: deps.warnImpl,
59
+ });
60
+ }
61
+ return (deps.applyLocalMigrationsImpl ?? applyLocalDevelopmentMigrations)({
62
+ projectDir,
63
+ config: { ...config, localFeatures: { ...config.localFeatures, database } },
64
+ environment: env,
65
+ });
66
+ }
67
+
68
+ export function createLocalDbMigrateCommand(deps) {
69
+ return async (...args) => {
70
+ const json = args.includes("--json");
71
+ let result;
72
+ try {
73
+ const config = await deps.loadConfig();
74
+ const projectDir = resolveProjectSelection({
75
+ allowMissingConfig: true,
76
+ cwd: deps.cwdImpl(),
77
+ existsSyncImpl: deps.existsSyncImpl,
78
+ resolvePathImpl: deps.resolvePathImpl,
79
+ processEnv: deps.processEnv ?? process.env,
80
+ }).projectDir;
81
+ if (!json) deps.infoImpl("Applying pending local migrations...");
82
+ const receipt = await runLocalDatabaseCommand({
83
+ command: "db:migrate",
84
+ config,
85
+ deps: { ...deps, cwdImpl: () => projectDir },
86
+ });
87
+ result = {
88
+ diagnosticVersion: 1,
89
+ ok: true,
90
+ command: "db:migrate",
91
+ target: "local",
92
+ databaseState: "APPLIED",
93
+ applicationImpact: receipt?.applicationImpact ?? "unknown",
94
+ frameworkImpact: "none",
95
+ ...(receipt?.correlationId ? { correlationId: receipt.correlationId } : {}),
96
+ warnings: [],
97
+ };
98
+ } catch (error) {
99
+ const failure = classifyLocalMigrationCommandFailure(error);
100
+ if (!json) throw failure;
101
+ result = {
102
+ diagnosticVersion: 1,
103
+ ok: false,
104
+ command: "db:migrate",
105
+ target: "local",
106
+ ...localMigrationDiagnostic(failure),
107
+ warnings: [],
108
+ };
109
+ }
110
+ // Rendering is outside execution: a broken output stream must never rerun SQL.
111
+ try {
112
+ if (json) deps.logImpl(JSON.stringify(result));
113
+ else {
114
+ deps.logImpl(
115
+ `Application impact: ${result.applicationImpact}\nFramework impact: none${result.correlationId ? `\nCorrelation ID: ${result.correlationId}` : ""}`,
116
+ );
117
+ deps.successImpl("Migrations applied!");
118
+ }
119
+ } catch {
120
+ throw localMigrationOutputFailure();
121
+ }
122
+ if (!result.ok) {
123
+ deps.exitImpl(1);
124
+ return 1;
125
+ }
126
+ };
127
+ }
@@ -0,0 +1,157 @@
1
+ import { createRequire } from "node:module";
2
+ import { resolve } from "node:path";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+ import { mkdirSync, unlinkSync } from "node:fs";
5
+ import { spawnSync } from "node:child_process";
6
+ import { randomUUID } from "node:crypto";
7
+ import { RuntimeDiagnosticError, runtimeDiagnostic } from "../runtime/engine/index.mjs";
8
+ import { configuredLocalDatabaseAdapter } from "./local-runtime-features.mjs";
9
+
10
+ export const localMigrationDiagnostic = (error) => runtimeDiagnostic(error);
11
+ function migrationFailure(kind = "unknown") {
12
+ const details = {
13
+ dependency: {
14
+ code: "RUNTIME_LOCAL_MIGRATION_DEPENDENCY_MISSING",
15
+ nextAction: "Install the project's dependencies, then run gencow db:migrate. Preserve applied migrations and data.",
16
+ retryPrecondition: "Install the missing project dependencies before retrying.",
17
+ },
18
+ sql: {
19
+ code: "RUNTIME_LOCAL_MIGRATION_SQL_FAILED",
20
+ nextAction: "Inspect the pending migration and database state before retrying gencow db:migrate. Preserve applied migrations and data; do not blindly replay mutations.",
21
+ retryPrecondition: "Resolve the pending migration error and inspect database state before retrying.",
22
+ },
23
+ unknown: {
24
+ code: "RUNTIME_LOCAL_MIGRATION_FAILED",
25
+ nextAction: "Check the local database connection and pending migrations, then run gencow db:migrate. Preserve applied migrations and data; do not blindly replay mutations.",
26
+ retryPrecondition: "Inspect the local migration failure and database state before retrying.",
27
+ },
28
+ }[kind] ?? null;
29
+ if (!details) return migrationFailure();
30
+ return new RuntimeDiagnosticError({
31
+ code: details.code,
32
+ stage: "migration",
33
+ capability: "database",
34
+ servingStarted: false,
35
+ dataImpact: "unknown",
36
+ applicationImpact: "unknown",
37
+ frameworkImpact: "none",
38
+ retryable: false,
39
+ correlationId: randomUUID(),
40
+ retryPrecondition: details.retryPrecondition,
41
+ nextAction: details.nextAction,
42
+ });
43
+ }
44
+ function migrationFailureKind(error) {
45
+ for (let current = error, depth = 0; current && depth < 5; current = current.cause, depth++) {
46
+ if (current.code === "MODULE_NOT_FOUND" || current.code === "ERR_MODULE_NOT_FOUND") return "dependency";
47
+ if (typeof current.code === "string" && /^(22|23|42)[0-9A-Z]{3}$/.test(current.code)) return "sql";
48
+ }
49
+ return "unknown";
50
+ }
51
+ export const classifyLocalMigrationCommandFailure = (error) =>
52
+ localMigrationDiagnostic(error) ? error : migrationFailure();
53
+ export const localMigrationOutputFailure = () => migrationFailure();
54
+
55
+ export function requireLocalPostgresUrl(environment) {
56
+ const value = environment.DATABASE_URL?.trim();
57
+ let valid = false;
58
+ try {
59
+ const url = new URL(value);
60
+ valid = (url.protocol === "postgres:" || url.protocol === "postgresql:") && !!url.hostname;
61
+ } catch {
62
+ // Render a safe diagnostic below rather than exposing the supplied URL.
63
+ }
64
+ if (!valid) throw new RuntimeDiagnosticError({
65
+ code: "RUNTIME_LOCAL_POSTGRES_URL_INVALID",
66
+ stage: "migration",
67
+ capability: "database",
68
+ servingStarted: false,
69
+ dataImpact: "none",
70
+ applicationImpact: "none",
71
+ frameworkImpact: "none",
72
+ retryable: false,
73
+ correlationId: randomUUID(),
74
+ retryPrecondition: "Configure a valid PostgreSQL DATABASE_URL for the intended local database.",
75
+ nextAction: "Set DATABASE_URL to the intended local PostgreSQL connection URL, then retry the command.",
76
+ });
77
+ return value;
78
+ }
79
+
80
+ /** Incumbent local behavior: Drizzle owns migration parsing, execution and history.
81
+ * No additional CLI policy, advisory lock, grant rewriting or outcome recovery.
82
+ */
83
+ export async function applyLocalDevelopmentMigrations(input) {
84
+ const { projectDir, config, environment = process.env } = input;
85
+ const postgres = configuredLocalDatabaseAdapter(config) === "postgres";
86
+ if (postgres) requireLocalPostgresUrl(environment);
87
+ if (!process.versions.bun) {
88
+ const child = spawnSync("bun", [fileURLToPath(import.meta.url)], {
89
+ cwd: projectDir,
90
+ env: environment,
91
+ input: JSON.stringify({ projectDir, config }),
92
+ encoding: "utf8",
93
+ stdio: ["pipe", "pipe", "pipe"],
94
+ });
95
+ if (child.error || child.status !== 0) {
96
+ let kind = "unknown";
97
+ try { kind = JSON.parse(child.stdout).kind; } catch { /* Unknown child failure. */ }
98
+ throw migrationFailure(kind);
99
+ }
100
+ return { applicationImpact: "unknown", frameworkImpact: "none", correlationId: randomUUID() };
101
+ }
102
+ const requireProject = createRequire(resolve(projectDir, "package.json"));
103
+ const load = (name) => import(pathToFileURL(requireProject.resolve(name)).href);
104
+ let client;
105
+ try {
106
+ let db, migrate;
107
+ if (postgres) {
108
+ const { SQL } = await import("bun");
109
+ const sdk = await load("drizzle-orm/bun-sql");
110
+ ({ migrate } = await load("drizzle-orm/bun-sql/migrator"));
111
+ client = new SQL(environment.DATABASE_URL);
112
+ db = sdk.drizzle({ client });
113
+ } else {
114
+ const dataDir = resolve(projectDir, config.db?.url ?? ".gencow/data");
115
+ mkdirSync(dataDir, { recursive: true });
116
+ // Deliberate parity with Server local startup, including its unsafe PID cleanup.
117
+ try {
118
+ unlinkSync(resolve(dataDir, "postmaster.pid"));
119
+ } catch {
120
+ /* Same as Server. */
121
+ }
122
+ const [{ PGlite }, sdk, { vector }, { pg_trgm }] = await Promise.all([
123
+ load("@electric-sql/pglite"),
124
+ load("drizzle-orm/pglite"),
125
+ load("@electric-sql/pglite/vector"),
126
+ load("@electric-sql/pglite/contrib/pg_trgm"),
127
+ ]);
128
+ ({ migrate } = await load("drizzle-orm/pglite/migrator"));
129
+ client = new PGlite({ dataDir, extensions: { vector, pg_trgm } });
130
+ await client.exec("CREATE EXTENSION IF NOT EXISTS vector; CREATE EXTENSION IF NOT EXISTS pg_trgm;");
131
+ db = sdk.drizzle({ client });
132
+ }
133
+ await migrate(db, { migrationsFolder: resolve(projectDir, config.rootDir ?? "gencow", "migrations") });
134
+ return { applicationImpact: "unknown", frameworkImpact: "none", correlationId: randomUUID() };
135
+ } catch (error) {
136
+ throw migrationFailure(migrationFailureKind(error));
137
+ } finally {
138
+ try {
139
+ await client?.close();
140
+ } catch {
141
+ throw migrationFailure();
142
+ }
143
+ }
144
+ }
145
+
146
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
147
+ try {
148
+ const input = await Bun.stdin.text();
149
+ await applyLocalDevelopmentMigrations(JSON.parse(input));
150
+ } catch (error) {
151
+ const code = localMigrationDiagnostic(error)?.code;
152
+ const kind = code === "RUNTIME_LOCAL_MIGRATION_DEPENDENCY_MISSING" ? "dependency" :
153
+ code === "RUNTIME_LOCAL_MIGRATION_SQL_FAILED" ? "sql" : "unknown";
154
+ process.stdout.write(JSON.stringify({ kind }));
155
+ process.exitCode = 1;
156
+ }
157
+ }
@@ -0,0 +1,10 @@
1
+ import generation from "./canonical-drizzle-generator.config.mjs";
2
+
3
+ // Generation always uses the portable schema-only contract. Database writes
4
+ // select their actual local provider here, never a repository runtime package.
5
+ const url = process.env.DATABASE_URL?.trim();
6
+ const { driver, dbCredentials, ...schema } = generation;
7
+ export default {
8
+ ...schema,
9
+ ...(url ? { dbCredentials: { url } } : { driver, dbCredentials }),
10
+ };
@@ -0,0 +1,12 @@
1
+ import { loadConfigModuleForRuntime } from "./cli-project-runtime.mjs";
2
+
3
+ /** Resolve defaults through the canonical Shared config implementation. */
4
+ export async function resolveLocalRuntimeFeatures(projectConfig, environment) {
5
+ const config = await loadConfigModuleForRuntime();
6
+ return config.resolveLocalRuntimeFeatures(projectConfig, environment);
7
+ }
8
+
9
+ /** Raw legacy declarations can still enter local DB commands through older callers. */
10
+ export function configuredLocalDatabaseAdapter(config) {
11
+ return config.localFeatures?.database?.adapter ?? config.experimental?.localFeatures?.database?.adapter;
12
+ }
@@ -0,0 +1,7 @@
1
+ import { captureRuntimeRagSelection } from "../runtime/engine/rag.mjs";
2
+
3
+ /** Select local RAG without altering generic Runtime provider contracts. */
4
+ export function selectRuntimeRag(selection) {
5
+ if (selection === undefined || selection === false) return undefined;
6
+ return captureRuntimeRagSelection(selection === true ? {} : selection);
7
+ }
@@ -0,0 +1,116 @@
1
+ /** Native Bun-watch entry: the same local Runtime startup is rerun after imports change.
2
+ * Like the incumbent Server, watch reload does not await asynchronous shutdown.
3
+ */
4
+ import { randomUUID } from "node:crypto";
5
+ import { loadConfig, buildEnv } from "./cli-project-runtime.mjs";
6
+ import { setCliInvocationSelection } from "./project-context.mjs";
7
+ import { resolveLocalRuntimeFeatures } from "./local-runtime-features.mjs";
8
+ import { assertLocalDashboardConfiguration, resolveLocalDashboardPlan } from "./local-dashboard-plan.mjs";
9
+ import {
10
+ applyLocalDevelopmentMigrations,
11
+ localMigrationDiagnostic,
12
+ } from "./local-development-migrations.mjs";
13
+ import { withServerCompatibleLocalStartup } from "../runtime/engine/local-postgres-support.mjs";
14
+ import { selectRuntimeRag } from "./rag-selection.mjs";
15
+ import { captureRuntimeSearchSelection } from "../runtime/engine/search.mjs";
16
+ import { formatRuntimeDiagnostic, runtimeDiagnostic } from "../runtime/engine/index.mjs";
17
+ import { error, info } from "./output.mjs";
18
+
19
+ let runtime;
20
+ const stop = async () => {
21
+ await runtime?.close();
22
+ process.exit(0);
23
+ };
24
+ process.on("SIGINT", () => {
25
+ void stop();
26
+ });
27
+ process.on("SIGTERM", () => {
28
+ void stop();
29
+ });
30
+ try {
31
+ if (process.argv[2]) setCliInvocationSelection(JSON.parse(process.argv[2]));
32
+ await withServerCompatibleLocalStartup(async () => {
33
+ const config = await loadConfig({ validateLoadedConfig: assertLocalDashboardConfiguration });
34
+ const projectDir = process.cwd();
35
+ const environment = buildEnv(config, {
36
+ cwd: projectDir,
37
+ runtimeOnly: true,
38
+ localStorage: config.localFeatures?.storage,
39
+ });
40
+ for (const [key, value] of Object.entries(environment))
41
+ if (typeof value === "string") process.env[key] = value;
42
+ if (environment.GENCOW_STORAGE === undefined) delete process.env.GENCOW_STORAGE;
43
+ const { rag: ragSelection, storage, ...localFeatures } = await resolveLocalRuntimeFeatures(config, environment);
44
+ // Match the old local Server startup; this default does not apply to standalone or hosted launches.
45
+ const rag = selectRuntimeRag(ragSelection ?? true);
46
+ const { path: storagePath, ...runtimeStorage } = storage;
47
+ const search = captureRuntimeSearchSelection(localFeatures.search);
48
+ if (search) localFeatures.search = search;
49
+ const dashboard = resolveLocalDashboardPlan({ config });
50
+ const applicationMigration = await applyLocalDevelopmentMigrations({
51
+ projectDir,
52
+ config: { ...config, localFeatures: { ...config.localFeatures, database: localFeatures.database } },
53
+ environment,
54
+ });
55
+ const { startLocalRuntime } = await import("../runtime/engine/local.mjs");
56
+ runtime = await startLocalRuntime({
57
+ applicationMigration,
58
+ projectDir,
59
+ rootDir: config.rootDir,
60
+ audit: {
61
+ implementation: config.auditor?.implementation,
62
+ schema: config.schema,
63
+ clientOutDir: config.codegen?.clientOutDir ?? config.codegen?.outDir,
64
+ serverPublishDir: config.codegen?.serverOutDir,
65
+ },
66
+ port: Number(environment.PORT || config.port || 5456),
67
+ databasePath: config.db?.url,
68
+ storagePath,
69
+ localFeatures: { ...localFeatures, storage: runtimeStorage },
70
+ environment,
71
+ standaloneEntryDir: config.experimental?.standaloneEntryDir,
72
+ frontendOrigins: config.frontendOrigins,
73
+ trustedOrigins: config.trustedOrigins,
74
+ generationId: randomUUID(),
75
+ ...(rag
76
+ ? {
77
+ rag,
78
+ async createDocumentConverter() {
79
+ const { createCliDocumentConverter } = await import("./document-local-converter.mjs");
80
+ const converter = createCliDocumentConverter();
81
+ return {
82
+ convert: (request) => converter.convert({ ...request, ...request.input }),
83
+ assertBasicSelection: (request) =>
84
+ converter.assertBasicSelection({ ...request, ...request.input }),
85
+ };
86
+ },
87
+ }
88
+ : {}),
89
+ ...(dashboard ? { dashboard, appEnvironmentKeys: Object.keys(environment) } : {}),
90
+ });
91
+ info("Local development is ready.");
92
+ if (dashboard) info(`Local dashboard: http://127.0.0.1:${runtime.port}/_dashboard/ (loopback only)`);
93
+ });
94
+ } catch (caught) {
95
+ const diagnostic = runtimeDiagnostic(caught) ?? localMigrationDiagnostic(caught);
96
+ if (diagnostic) {
97
+ // This launcher owns the bundled Runtime. Installing Runtime in the app
98
+ // cannot change the Workflow host used by gencow dev --local.
99
+ const presentation =
100
+ diagnostic.code === "LOCAL_WORKFLOW_HOST_INCOMPATIBLE"
101
+ ? {
102
+ ...diagnostic,
103
+ retryPrecondition:
104
+ "Use a Gencow CLI whose bundled Runtime is compatible with the app's Core Workflow contract.",
105
+ nextAction:
106
+ "Check `gencow --version` and `pnpm why @gencow/core`, install a compatible Gencow CLI, then restart with `gencow dev --local`. Earlier app import effects may remain.",
107
+ }
108
+ : diagnostic;
109
+ error(formatRuntimeDiagnostic(presentation));
110
+ } else {
111
+ error(
112
+ "RUNTIME_LOCAL_STARTUP_FAILED: Check the local configuration and database, then restart gencow dev --local. Preserve existing data and inspect prior operation outcomes.",
113
+ );
114
+ }
115
+ process.exitCode = 1;
116
+ }
@@ -24,5 +24,8 @@ export function hasWorkspaceSourceRuntime(options = {}) {
24
24
  }
25
25
 
26
26
  export function hasWorkspaceConfigSourceRuntime(options = {}) {
27
+ // Shared source uses .js-to-.ts specifiers that only Bun resolves at runtime.
28
+ const runtime = options.runtime ?? (globalThis.Bun ? "bun" : "node");
29
+ if (runtime !== "bun") return false;
27
30
  return isWorkspaceInternalSourceAvailable("config/index.ts", options);
28
31
  }
@@ -0,0 +1,91 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import { dirname, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ function adapterFailure(code, nextAction) {
8
+ const diagnostic = Object.freeze({
9
+ code,
10
+ stage: "declaration",
11
+ capability: "standalone",
12
+ servingStarted: false,
13
+ dataImpact: "none",
14
+ projectFilesChanged: false,
15
+ retryable: false,
16
+ retryPrecondition: "Correct the local build or project configuration before retrying.",
17
+ nextAction,
18
+ correlationId: randomUUID(),
19
+ });
20
+ return Object.assign(
21
+ new Error(
22
+ `${code}: ${nextAction} No project files or data changed. Correlation: ${diagnostic.correlationId}`,
23
+ ),
24
+ { code, diagnostic },
25
+ );
26
+ }
27
+
28
+ /** Supply generic package/process capabilities; Shared owns all generation decisions. */
29
+ export async function createStandaloneCodegenOptions({ config, cwd, bundled }, overrides = {}) {
30
+ const read = overrides.readFileSyncImpl ?? readFileSync;
31
+ const exists = overrides.existsSyncImpl ?? existsSync;
32
+ const metadataPath = resolve(dirname(fileURLToPath(import.meta.url)), "../runtime/runtime-metadata.json");
33
+ const packagePath = resolve(cwd, "package.json");
34
+ const lockPath = resolve(cwd, "pnpm-lock.yaml");
35
+ let catalog, packageJson, compilerCommand;
36
+ try {
37
+ catalog = JSON.parse(read(metadataPath, "utf8"));
38
+ } catch {
39
+ throw adapterFailure(
40
+ "RUNTIME_STANDALONE_DEPENDENCY_METADATA_MISSING",
41
+ "Rebuild or reinstall the CLI, then rerun gencow codegen.",
42
+ );
43
+ }
44
+ try {
45
+ packageJson = JSON.parse(read(packagePath, "utf8"));
46
+ } catch {
47
+ throw adapterFailure(
48
+ "RUNTIME_STANDALONE_PACKAGE_INVALID",
49
+ "Provide a valid project package.json, then rerun gencow codegen.",
50
+ );
51
+ }
52
+ try {
53
+ compilerCommand = (
54
+ overrides.resolveCompilerImpl ?? (() => createRequire(import.meta.url).resolve("esbuild/bin/esbuild"))
55
+ )();
56
+ } catch {
57
+ throw adapterFailure(
58
+ "RUNTIME_STANDALONE_COMPILER_MISSING",
59
+ "Rebuild or reinstall the CLI, then rerun gencow codegen.",
60
+ );
61
+ }
62
+ return {
63
+ catalog,
64
+ projectConfig: {
65
+ localFeatures: config.localFeatures,
66
+ storage: config.storage,
67
+ db: config.db,
68
+ frontendOrigins: config.frontendOrigins,
69
+ trustedOrigins: config.trustedOrigins,
70
+ codegen: { serverOutDir: config.codegen?.serverOutDir },
71
+ },
72
+ schemaDeclared: config.__gencowConfigMetadata?.schemaDeclared ?? Object.hasOwn(config, "schema"),
73
+ existingDependencies: packageJson.dependencies ?? {},
74
+ processRunner: bundled.createNodeProcessRunner?.(),
75
+ compilerCommand,
76
+ async syncDependencies({ projectRoot, dependencies }) {
77
+ if (resolve(projectRoot) !== resolve(cwd)) throw new Error("Dependency project mismatch");
78
+ const before = read(packagePath, "utf8");
79
+ const beforeLock = exists(lockPath) ? read(lockPath, "utf8") : null;
80
+ const current = JSON.parse(before);
81
+ const nextPackageJson = { ...current, dependencies: { ...current.dependencies, ...dependencies } };
82
+ const sync =
83
+ overrides.syncImpl ??
84
+ (await import("./project-dependency-lock-sync.mjs")).syncStandalonePackageAndLock;
85
+ await sync({ cwd, nextPackageJson });
86
+ const after = read(packagePath, "utf8");
87
+ const afterLock = exists(lockPath) ? read(lockPath, "utf8") : null;
88
+ return { changed: before !== after || beforeLock !== afterLock };
89
+ },
90
+ };
91
+ }