gencow 0.1.298 → 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 (169) hide show
  1. package/bin/gencow.mjs +0 -6
  2. package/core/index.js +261 -1447
  3. package/core/package.json +1 -1
  4. package/dashboard/assets/{index-BnBn8uo4.js → index-DYqUzCmS.js} +3 -3
  5. package/dashboard/assets/index-OH2xW1ZG.css +2 -0
  6. package/dashboard/index.html +2 -2
  7. package/docs/packaging.md +14 -4
  8. package/lib/cli-artifact-guard.mjs +53 -3
  9. package/lib/cli-command-runner.d.mts +11 -0
  10. package/lib/cli-dev-runtime.mjs +1 -0
  11. package/lib/cli-project-runtime.mjs +26 -14
  12. package/lib/codegen-command.mjs +16 -0
  13. package/lib/coding-guardrails.mjs +2 -0
  14. package/lib/component-readme.mjs +4 -4
  15. package/lib/dashboard-artifact.mjs +65 -0
  16. package/lib/dashboard-assets.mjs +20 -0
  17. package/lib/db-command.mjs +121 -80
  18. package/lib/db-migration-command-steps.mjs +19 -16
  19. package/lib/db-push-command.mjs +1 -1
  20. package/lib/deploy-codegen-preflight.mjs +1 -0
  21. package/lib/deploy-cron-manifest-diagnostic.mjs +93 -0
  22. package/lib/deploy-failure-diagnostic.mjs +4 -43
  23. package/lib/deploy-route-target-rejection-diagnostic.mjs +43 -0
  24. package/lib/dev-cloud-command.mjs +1 -1
  25. package/lib/dev-local-command.mjs +19 -56
  26. package/lib/document-local-converter.mjs +11 -0
  27. package/lib/jobs-command.mjs +33 -1
  28. package/lib/local-dashboard-plan.mjs +60 -0
  29. package/lib/local-database-commands.mjs +127 -0
  30. package/lib/local-development-migrations.mjs +157 -0
  31. package/lib/local-drizzle-database.config.mjs +10 -0
  32. package/lib/local-runtime-features.mjs +12 -0
  33. package/lib/rag-selection.mjs +7 -0
  34. package/lib/readme-codegen.mjs +2 -2
  35. package/lib/runtime-local-worker.mjs +116 -0
  36. package/lib/runtime-mode.mjs +3 -0
  37. package/lib/standalone-codegen-adapter.mjs +91 -0
  38. package/lib/ts-codegen-import-extension.mjs +228 -19
  39. package/package.json +16 -9
  40. package/runtime/config.mjs +218 -2
  41. package/runtime/dependency-lock.mjs +5 -1
  42. package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
  43. package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
  44. package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
  45. package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
  46. package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
  47. package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
  48. package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
  49. package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
  50. package/runtime/engine/chunk-5575APCJ.mjs +215 -0
  51. package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
  52. package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
  53. package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
  54. package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
  55. package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
  56. package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
  57. package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
  58. package/runtime/engine/chunk-6W653LXI.mjs +13 -0
  59. package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
  60. package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
  61. package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
  62. package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
  63. package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
  64. package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
  65. package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
  66. package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
  67. package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
  68. package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
  69. package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
  70. package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
  71. package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
  72. package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
  73. package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
  74. package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
  75. package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
  76. package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
  77. package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
  78. package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
  79. package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
  80. package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
  81. package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
  82. package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
  83. package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
  84. package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
  85. package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
  86. package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
  87. package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
  88. package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
  89. package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
  90. package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
  91. package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
  92. package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
  93. package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
  94. package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
  95. package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
  96. package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
  97. package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
  98. package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
  99. package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
  100. package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
  101. package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
  102. package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
  103. package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
  104. package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
  105. package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
  106. package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
  107. package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
  108. package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
  109. package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
  110. package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
  111. package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
  112. package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
  113. package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
  114. package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
  115. package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
  116. package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
  117. package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
  118. package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
  119. package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
  120. package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
  121. package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
  122. package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
  123. package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
  124. package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
  125. package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
  126. package/runtime/engine/chunk-YRHM272W.mjs +528 -0
  127. package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
  128. package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
  129. package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
  130. package/runtime/engine/composition.mjs +325 -0
  131. package/runtime/engine/document-local.mjs +504 -0
  132. package/runtime/engine/graph.json +4134 -0
  133. package/runtime/engine/index.mjs +265 -0
  134. package/runtime/engine/local-postgres-support.mjs +69 -0
  135. package/runtime/engine/local.mjs +3275 -0
  136. package/runtime/engine/pglite-directory-lock.mjs +8 -0
  137. package/runtime/engine/rag.mjs +11 -0
  138. package/runtime/engine/search.mjs +18 -0
  139. package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
  140. package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
  141. package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
  142. package/runtime/framework-migrations/manifest.json +56 -0
  143. package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
  144. package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
  145. package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
  146. package/runtime/runtime-metadata.json +27 -0
  147. package/runtime/tooling.mjs +10549 -10543
  148. package/scripts/bundle-runtime-config.mjs +23 -0
  149. package/scripts/bundle-runtime.mjs +100 -0
  150. package/scripts/bundle-runtime.test.mjs +33 -0
  151. package/scripts/bundle-shared.mjs +3 -0
  152. package/scripts/copy-dashboard.mjs +16 -0
  153. package/scripts/pre-publish-check.mjs +23 -11
  154. package/templateFeature/ai/ai-embedding-result.ts +82 -0
  155. package/templateFeature/ai/ai-facade.ts +24 -7
  156. package/templateFeature/ai/ai-provider.ts +17 -1
  157. package/templateFeature/ai/ai.ts +1 -0
  158. package/templateFeature/ai/manifest.json +4 -3
  159. package/templateFeature/reranker/manifest.json +1 -1
  160. package/templateFeature/reranker/reranker.ts +4 -3
  161. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  162. package/templateFeature/tools/manifest.json +2 -1
  163. package/templateFeature/tools/tools.ts +3 -3
  164. package/dashboard/assets/index-C6-BpKKR.css +0 -2
  165. package/runtime/server.mjs +0 -14320
  166. package/scripts/bundle-server.mjs +0 -223
  167. package/server/config.js +0 -1
  168. package/server/index.js +0 -1
  169. package/server/package.json +0 -6
@@ -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
+ }
@@ -1,3 +1,4 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import { isLiteralConfigLineTerminator } from "./literal-config-syntax.mjs";
2
3
 
3
4
  function skipLineComment(source, start) {
@@ -134,7 +135,9 @@ function tokenize(source) {
134
135
  index = template.end;
135
136
  continue;
136
137
  }
137
- const identifier = source.slice(index).match(/^[\p{ID_Start}_$][\p{ID_Continue}$]*/u)?.[0];
138
+ const identifier = source.slice(index).match(
139
+ /^(?:[\p{ID_Start}_$]|\\u(?:[\da-fA-F]{4}|\{[\da-fA-F]{1,6}\}))(?:[\p{ID_Continue}$]|\\u(?:[\da-fA-F]{4}|\{[\da-fA-F]{1,6}\}))*/u,
140
+ )?.[0];
138
141
  if (identifier) {
139
142
  tokens.push({ kind: "identifier", value: identifier });
140
143
  index += identifier.length;
@@ -197,7 +200,12 @@ function propertyKey(token) {
197
200
  return null;
198
201
  }
199
202
 
200
- function lastDirectProperty(tokens, objectStart, name) {
203
+ function lastDirectProperty(tokens, objectStart, name, { rejectEscapedKeys = false } = {}) {
204
+ const undecodedKey = (token) =>
205
+ rejectEscapedKeys && propertyKey(token)?.includes("\\");
206
+ const undecodedKeyAt = (index) =>
207
+ undecodedKey(tokens[index]) ||
208
+ (rejectEscapedKeys && isPunctuation(tokens[index + 1], "\\"));
201
209
  const objectEnd = findMatchingDelimiter(tokens, objectStart);
202
210
  if (objectEnd < 0) return null;
203
211
  let result = { found: false, ambiguous: false };
@@ -216,7 +224,9 @@ function lastDirectProperty(tokens, objectStart, name) {
216
224
  const keyEnd = findMatchingDelimiter(tokens, index);
217
225
  if (keyEnd < 0) return { found: true, unsupported: true, ambiguous: false };
218
226
  const computedKey =
219
- keyEnd === index + 2 && tokens[index + 1]?.kind === "string" ? tokens[index + 1].value : null;
227
+ keyEnd === index + 2 && tokens[index + 1]?.kind === "string" && !undecodedKey(tokens[index + 1])
228
+ ? tokens[index + 1].value
229
+ : null;
220
230
  if (isPunctuation(tokens[keyEnd + 1], ":")) {
221
231
  if (computedKey === name) {
222
232
  const start = keyEnd + 2;
@@ -237,7 +247,10 @@ function lastDirectProperty(tokens, objectStart, name) {
237
247
  continue;
238
248
  }
239
249
  const key = propertyKey(tokens[index]);
240
- if (key === null) {
250
+ if (key === null || undecodedKeyAt(index)) {
251
+ // A raw escaped/unsupported key may name the sought property. A later
252
+ // proven direct property can settle this uncertainty via normal precedence.
253
+ if (rejectEscapedKeys) result.ambiguous = true;
241
254
  const boundary = findValueBoundary(tokens, index, objectEnd);
242
255
  index = boundary + (isPunctuation(tokens[boundary], ",") ? 1 : 0);
243
256
  continue;
@@ -250,6 +263,7 @@ function lastDirectProperty(tokens, objectStart, name) {
250
263
  continue;
251
264
  }
252
265
  if (accessor !== null) {
266
+ if (undecodedKeyAt(index + 1)) result.ambiguous = true;
253
267
  const boundary = findValueBoundary(tokens, index + 1, objectEnd);
254
268
  index = boundary + (isPunctuation(tokens[boundary], ",") ? 1 : 0);
255
269
  continue;
@@ -287,29 +301,29 @@ function literalValue(expression) {
287
301
  );
288
302
  }
289
303
 
290
- function rootConfigObject(tokens) {
304
+ function defaultExportValue(tokens) {
291
305
  for (let index = 0; index < tokens.length - 2; index += 1) {
292
306
  if (
293
- tokens[index].kind !== "identifier" ||
294
- tokens[index].value !== "export" ||
295
- tokens[index + 1].kind !== "identifier" ||
296
- tokens[index + 1].value !== "default"
297
- ) {
298
- continue;
299
- }
300
- if (isPunctuation(tokens[index + 2], "{")) return index + 2;
301
- if (
302
- tokens[index + 2].kind === "identifier" &&
303
- tokens[index + 2].value === "defineConfig" &&
304
- isPunctuation(tokens[index + 3], "(") &&
305
- isPunctuation(tokens[index + 4], "{")
307
+ tokens[index].kind === "identifier" && tokens[index].value === "export" &&
308
+ tokens[index + 1].kind === "identifier" && tokens[index + 1].value === "default"
306
309
  ) {
307
- return index + 4;
310
+ return index + 2;
308
311
  }
309
312
  }
310
313
  return -1;
311
314
  }
312
315
 
316
+ function isDefineConfigCall(tokens, index) {
317
+ return tokens[index]?.kind === "identifier" && tokens[index].value === "defineConfig" &&
318
+ isPunctuation(tokens[index + 1], "(");
319
+ }
320
+
321
+ function rootConfigObject(tokens) {
322
+ const index = defaultExportValue(tokens);
323
+ if (isPunctuation(tokens[index], "{")) return index;
324
+ return isDefineConfigCall(tokens, index) && isPunctuation(tokens[index + 2], "{") ? index + 2 : -1;
325
+ }
326
+
313
327
  /** Read only a direct literal codegen.importExtension from supported TS config shapes. */
314
328
  export function readTsCodegenImportExtension(source) {
315
329
  const tokens = tokenize(source);
@@ -333,3 +347,198 @@ export function readTsCodegenImportExtension(source) {
333
347
  }
334
348
  return literalValue(importExtension.valueTokens);
335
349
  }
350
+
351
+ function invalidExperimentalLiteral() {
352
+ invalidConfigLiteral(
353
+ "CONFIG_EXPERIMENTAL_NOT_LITERAL",
354
+ "Replace the computed experimental configuration before retrying.",
355
+ "Use literal experimental settings in gencow.config.ts or move computed configuration to gencow.config.js, then retry.",
356
+ );
357
+ }
358
+
359
+ function invalidLocalFeatureLiteral(field = "rag") {
360
+ invalidConfigLiteral(
361
+ field === "rag" ? "CONFIG_LOCAL_RAG_NOT_LITERAL" : "CONFIG_LOCAL_FEATURES_NOT_LITERAL",
362
+ "Make the local feature selection explicit before retrying.",
363
+ `Use a literal localFeatures.${field} setting in gencow.config.ts or move computed configuration to gencow.config.js, then retry.`,
364
+ );
365
+ }
366
+
367
+ function invalidConfigLiteral(code, retryPrecondition, nextAction) {
368
+ const diagnostic = Object.freeze({
369
+ code, stage: "declaration", capability: "application",
370
+ servingStarted: false, dataImpact: "none", projectFilesChanged: false, retryable: false,
371
+ retryPrecondition, nextAction,
372
+ correlationId: randomUUID(),
373
+ });
374
+ throw Object.assign(new Error([
375
+ `Code: ${diagnostic.code}`, `Stage: ${diagnostic.stage}`, `Capability: ${diagnostic.capability}`,
376
+ "Serving started: no", "Data impact: none", "Project files/dependencies changed: no", "Retryable: no",
377
+ `Retry precondition: ${diagnostic.retryPrecondition}`, `Next action: ${diagnostic.nextAction}`,
378
+ `Correlation: ${diagnostic.correlationId}`,
379
+ ].join("\n")), { code: diagnostic.code, diagnostic });
380
+ }
381
+
382
+ function readConfigLiteralValue(tokens, fail) {
383
+ if (isPunctuation(tokens?.[0], "{") && findMatchingDelimiter(tokens, 0) === tokens.length - 1) {
384
+ const properties = new Map();
385
+ const end = tokens.length - 1;
386
+ for (let index = 1; index < end;) {
387
+ if (isPunctuation(tokens[index], ",")) { index += 1; continue; }
388
+ let key = propertyKey(tokens[index]);
389
+ let colon = index + 1;
390
+ if (isPunctuation(tokens[index], "[")) {
391
+ const keyEnd = findMatchingDelimiter(tokens, index);
392
+ if (keyEnd !== index + 2 || tokens[index + 1]?.kind !== "string") fail();
393
+ key = tokens[index + 1].value;
394
+ colon = keyEnd + 1;
395
+ }
396
+ if (key === null || key.includes("\\") || !isPunctuation(tokens[colon], ":")) fail();
397
+ const boundary = findValueBoundary(tokens, colon + 1, end);
398
+ properties.set(key, tokens.slice(colon + 1, boundary));
399
+ index = boundary + (isPunctuation(tokens[boundary], ",") ? 1 : 0);
400
+ }
401
+ const result = {};
402
+ for (const [key, valueTokens] of properties) {
403
+ // Define own properties rather than invoking Object.prototype.__proto__.
404
+ Object.defineProperty(result, key, { value: readConfigLiteralValue(valueTokens, fail), writable: true, enumerable: true, configurable: true });
405
+ }
406
+ return result;
407
+ }
408
+ if (isPunctuation(tokens?.[0], "[") && findMatchingDelimiter(tokens, 0) === tokens.length - 1) {
409
+ const result = [];
410
+ const end = tokens.length - 1;
411
+ for (let index = 1; index < end;) {
412
+ const boundary = findValueBoundary(tokens, index, end);
413
+ result.push(readConfigLiteralValue(tokens.slice(index, boundary), fail));
414
+ index = boundary + (isPunctuation(tokens[boundary], ",") ? 1 : 0);
415
+ }
416
+ return result;
417
+ }
418
+ if (tokens?.length === 1) {
419
+ const [token] = tokens;
420
+ if (token.kind === "string") {
421
+ // The existing tokenizer preserves source escapes, so reject rather than
422
+ // silently change paths until it can decode string literals faithfully.
423
+ if (token.value.includes("\\")) fail();
424
+ return token.value;
425
+ }
426
+ if (token.kind === "number" && !token.value.endsWith("n")) return Number(token.value.replaceAll("_", ""));
427
+ if (token.kind === "identifier" && token.value === "true") return true;
428
+ if (token.kind === "identifier" && token.value === "false") return false;
429
+ if (token.kind === "identifier" && token.value === "null") return null;
430
+ }
431
+ if (tokens?.length === 2 && isPunctuation(tokens[0], "-") && tokens[1].kind === "number" && !tokens[1].value.endsWith("n")) {
432
+ return -Number(tokens[1].value.replaceAll("_", ""));
433
+ }
434
+ fail();
435
+ }
436
+
437
+ /** Decode only for identifying a declaration to reject, never to evaluate its value. */
438
+ function featureKeySpelling(token) {
439
+ return propertyKey(token)?.replace(
440
+ /\\(?:u\{([\da-fA-F]{1,6})\}|u([\da-fA-F]{4})|x([\da-fA-F]{2})|([^\r\n]))/gu,
441
+ (_, point, unit, byte, other) => {
442
+ if (other !== undefined) return /^[bfnrtv0-9]$/u.test(other) ? "\0" : other;
443
+ const codePoint = Number.parseInt(point ?? unit ?? byte, 16);
444
+ return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : "\0";
445
+ },
446
+ );
447
+ }
448
+
449
+ /** Look only at config objects reachable through simple local references, not unrelated strings or nested fields. */
450
+ function hasFeatureDeclaration(tokens, name) {
451
+ const bindings = new Map();
452
+ for (let i = 0; i < tokens.length - 3; i++) {
453
+ if (tokens[i].kind === "identifier" && ["const", "let", "var"].includes(tokens[i].value) &&
454
+ tokens[i + 1].kind === "identifier") {
455
+ const annotated = isPunctuation(tokens[i + 2], ":") && tokens[i + 3].kind === "identifier";
456
+ const assignment = i + (annotated ? 4 : 2);
457
+ if (isPunctuation(tokens[assignment], "=")) bindings.set(tokens[i + 1].value, assignment + 1);
458
+ }
459
+ // Nested declarations can shadow a module binding but cannot supply the default export.
460
+ if (tokens[i].kind === "punct" && matchingClose[tokens[i].value]) {
461
+ const end = findMatchingDelimiter(tokens, i);
462
+ if (end > i) i = end;
463
+ }
464
+ }
465
+ const pending = [defaultExportValue(tokens)];
466
+ const visited = new Set();
467
+ while (pending.length > 0) {
468
+ const start = pending.pop();
469
+ const token = tokens[start];
470
+ if (!token || visited.has(start)) continue;
471
+ visited.add(start);
472
+ if (isDefineConfigCall(tokens, start)) pending.push(start + 2);
473
+ else if (isPunctuation(token, "(")) pending.push(start + 1);
474
+ else if (token.kind === "identifier") pending.push(bindings.get(token.value));
475
+ else if (isPunctuation(token, "{")) {
476
+ const end = findMatchingDelimiter(tokens, start);
477
+ for (let index = start + 1; index < end;) {
478
+ if (isPunctuation(tokens[index], ",")) { index++; continue; }
479
+ if (isPunctuation(tokens[index], "...")) pending.push(index + 1);
480
+ else if (isPunctuation(tokens[index], "[") && findMatchingDelimiter(tokens, index) === index + 2) {
481
+ const key = tokens[index + 1];
482
+ const literal = key.kind === "identifier" ? tokens[bindings.get(key.value)] : key;
483
+ if (literal?.kind === "string" && featureKeySpelling(literal) === name) return true;
484
+ } else if (featureKeySpelling(tokens[index]) === name ||
485
+ (["get", "set", "async", "*"].includes(tokens[index].value) &&
486
+ featureKeySpelling(tokens[index + 1]) === name)) return true;
487
+ const boundary = findValueBoundary(tokens, index, end);
488
+ index = boundary + 1;
489
+ }
490
+ }
491
+ }
492
+ return false;
493
+ }
494
+
495
+ function projectFeatureProperty(tokens, rootObject, name, fail) {
496
+ const property = lastDirectProperty(tokens, rootObject, name, { rejectEscapedKeys: true });
497
+ if (property?.unsupported || (property?.found && property.ambiguous)) fail();
498
+ if (property?.found) return property;
499
+ // An opaque legacy export is not itself an opt-in. Refuse only if the
500
+ // TypeScript source also declares the new setting we cannot resolve.
501
+ if ((!property || property.ambiguous) && hasFeatureDeclaration(tokens, name)) fail();
502
+ return undefined;
503
+ }
504
+
505
+ function readExperimentalConfig(tokens, rootObject) {
506
+ const property = projectFeatureProperty(tokens, rootObject, "experimental", invalidExperimentalLiteral);
507
+ return property && readConfigLiteralValue(property.valueTokens, invalidExperimentalLiteral);
508
+ }
509
+
510
+ /** Read only the direct, literal experimental project configuration. */
511
+ export function readTsExperimentalConfig(source) {
512
+ const tokens = tokenize(source);
513
+ return readExperimentalConfig(tokens, rootConfigObject(tokens));
514
+ }
515
+
516
+ /** Read stable settings without treating unrelated old flat fields as supported. */
517
+ function readStableLocalFeatures(tokens, rootObject) {
518
+ const feature = projectFeatureProperty(tokens, rootObject, "localFeatures", invalidLocalFeatureLiteral);
519
+ if (!feature) return undefined;
520
+ const values = feature.valueTokens;
521
+ if (!isPunctuation(values?.[0], "{") || findMatchingDelimiter(values, 0) !== values.length - 1) {
522
+ return readConfigLiteralValue(values, invalidLocalFeatureLiteral);
523
+ }
524
+ const result = {};
525
+ for (const field of ["rag", "database", "search", "dashboard", "storage"]) {
526
+ const property = lastDirectProperty(values, 0, field, { rejectEscapedKeys: true });
527
+ if (!property || property.ambiguous || property.unsupported) invalidLocalFeatureLiteral(field);
528
+ if (property.found) {
529
+ result[field] = readConfigLiteralValue(property.valueTokens, () => invalidLocalFeatureLiteral(field));
530
+ }
531
+ }
532
+ return result;
533
+ }
534
+
535
+ export function readTsProjectFeatures(source) {
536
+ const tokens = tokenize(source);
537
+ const root = rootConfigObject(tokens);
538
+ const experimental = readExperimentalConfig(tokens, root);
539
+ const localFeatures = readStableLocalFeatures(tokens, root);
540
+ return {
541
+ ...(experimental === undefined ? {} : { experimental }),
542
+ ...(localFeatures === undefined ? {} : { localFeatures }),
543
+ };
544
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gencow",
3
- "version": "0.1.298",
3
+ "version": "0.2.0",
4
4
  "description": "Gencow — AI Backend Engine",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,21 +12,29 @@
12
12
  "!lib/codegen/",
13
13
  "runtime/",
14
14
  "!runtime/*.map",
15
+ "!runtime/server.mjs",
16
+ "!runtime/server.mjs.map",
15
17
  "docs/",
16
18
  "templateFeature/",
17
19
  "templates/",
18
- "server/",
20
+ "!server/",
19
21
  "core/",
20
22
  "scripts/",
23
+ "!scripts/bundle-server.mjs",
21
24
  "dashboard/"
22
25
  ],
23
26
  "dependencies": {
24
- "@gencow/migration-contract": "0.1.23",
27
+ "@better-auth/core": "1.7.11",
28
+ "@electric-sql/pglite": "^0.4.6",
29
+ "@gencow/migration-contract": "0.1.24",
25
30
  "@modelcontextprotocol/sdk": "^1.32.2",
31
+ "better-auth": "1.7.11",
26
32
  "drizzle-kit": "1.0.0-rc.5",
27
33
  "drizzle-orm": "1.0.0-rc.5",
28
34
  "esbuild": "^0.28.2",
35
+ "node-cron": "4.6.0",
29
36
  "open": "^11.0.4",
37
+ "postgres": "^3.4.9",
30
38
  "tar": "7.5.22",
31
39
  "ws": "^8.22.2",
32
40
  "zod": "^4.6.7"
@@ -38,18 +46,17 @@
38
46
  "@types/node": "^25.9.9",
39
47
  "@typescript/native": "npm:typescript@7.0.2",
40
48
  "ai": "^6.0.326",
41
- "better-auth": "1.7.11",
42
- "postgres": "^3.4.9",
43
49
  "@gencow/client": "0.2.9",
44
- "@gencow/core": "0.1.48",
45
50
  "@gencow/react": "0.2.9",
51
+ "@gencow/runtime": "0.1.0",
52
+ "@gencow/shared": "0.0.0",
46
53
  "@gencow/server": "0.1.3",
47
- "@gencow/shared": "0.0.0"
54
+ "@gencow/core": "0.2.0"
48
55
  },
49
56
  "scripts": {
50
- "build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
57
+ "build": "pnpm --dir ../.. run build:dashboard && node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-runtime.mjs && node scripts/copy-dashboard.mjs --required",
51
58
  "build:with-deps": "pnpm --filter {.}... run build",
52
- "build:runtime-bundles": "node scripts/bundle-core.mjs && node scripts/bundle-server.mjs",
59
+ "build:runtime-bundles": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-runtime.mjs && node scripts/copy-dashboard.mjs",
53
60
  "test:coverage": "node ../../scripts/run-package-coverage.mjs",
54
61
  "coverage:compare": "node ../../scripts/compare-package-coverage.mjs"
55
62
  }