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
@@ -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.299",
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
  }
@@ -19721,6 +19721,161 @@ function date4(params) {
19721
19721
  return _coercedDate(ZodDate, params);
19722
19722
  }
19723
19723
 
19724
+ // ../shared/dist/src/config/declaration-diagnostic.js
19725
+ import { randomUUID } from "node:crypto";
19726
+ function failProjectConfig(code, retryPrecondition, nextAction) {
19727
+ const diagnostic = Object.freeze({
19728
+ code,
19729
+ stage: "declaration",
19730
+ capability: "application",
19731
+ servingStarted: false,
19732
+ dataImpact: "none",
19733
+ projectFilesChanged: false,
19734
+ retryable: false,
19735
+ retryPrecondition,
19736
+ nextAction,
19737
+ correlationId: randomUUID()
19738
+ });
19739
+ throw Object.assign(new Error([
19740
+ `Code: ${diagnostic.code}`,
19741
+ `Stage: ${diagnostic.stage}`,
19742
+ `Capability: ${diagnostic.capability}`,
19743
+ "Serving started: no",
19744
+ "Data impact: none",
19745
+ "Project files/dependencies changed: no",
19746
+ "Retryable: no",
19747
+ `Retry precondition: ${diagnostic.retryPrecondition}`,
19748
+ `Next action: ${diagnostic.nextAction}`,
19749
+ `Correlation: ${diagnostic.correlationId}`
19750
+ ].join("\n")), { code, diagnostic });
19751
+ }
19752
+
19753
+ // ../shared/dist/src/codegen/domain/standalone-diagnostics.js
19754
+ import { randomUUID as randomUUID2 } from "node:crypto";
19755
+ function validateStandaloneOutput(config2) {
19756
+ if (!config2 || typeof config2 !== "object")
19757
+ return;
19758
+ const experimental = config2.experimental;
19759
+ if (!experimental || typeof experimental !== "object" || Array.isArray(experimental))
19760
+ return;
19761
+ const output2 = experimental.output;
19762
+ if (output2 === void 0 || output2 === "standalone")
19763
+ return;
19764
+ const diagnostic = {
19765
+ code: "RUNTIME_STANDALONE_TARGET_UNSUPPORTED",
19766
+ stage: "declaration",
19767
+ capability: "standalone",
19768
+ servingStarted: false,
19769
+ dataImpact: "none",
19770
+ projectFilesChanged: false,
19771
+ retryable: false,
19772
+ retryPrecondition: "Correct the experimental output declaration before retrying.",
19773
+ nextAction: 'Set experimental.output to "standalone" or remove it, then rerun gencow codegen.',
19774
+ correlationId: randomUUID2()
19775
+ };
19776
+ throw Object.assign(new Error([
19777
+ `Code: ${diagnostic.code}`,
19778
+ `Stage: ${diagnostic.stage}`,
19779
+ `Capability: ${diagnostic.capability}`,
19780
+ "Serving started: no",
19781
+ "Data impact: none",
19782
+ "Project files/dependencies changed: no",
19783
+ "Retryable: no",
19784
+ `Retry precondition: ${diagnostic.retryPrecondition}`,
19785
+ `Next action: ${diagnostic.nextAction}`,
19786
+ `Correlation: ${diagnostic.correlationId}`
19787
+ ].join("\n")), { code: diagnostic.code, diagnostic: Object.freeze(diagnostic) });
19788
+ }
19789
+
19790
+ // ../shared/dist/src/config/local-features.js
19791
+ var DEFAULT_LOCAL_STORAGE_PATH = "./.gencow/uploads";
19792
+ function isAzureBlobAccountUrl(value) {
19793
+ try {
19794
+ const url2 = new URL(value);
19795
+ return url2.protocol === "https:" && !url2.username && !url2.password && url2.pathname === "/" && !url2.search && !url2.hash;
19796
+ } catch {
19797
+ return false;
19798
+ }
19799
+ }
19800
+ var uploadLimits = {
19801
+ maxFileSizeBytes: external_exports.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional(),
19802
+ maxMultipartBodyBytes: external_exports.number().int().positive().max(Number.MAX_SAFE_INTEGER).optional(),
19803
+ maxFilesPerRequest: external_exports.number().int().positive().max(16).optional()
19804
+ };
19805
+ var localAdapterInputs = {
19806
+ database: external_exports.object({ adapter: external_exports.enum(["postgres", "pglite"]) }).strict().optional(),
19807
+ rag: external_exports.union([external_exports.boolean(), external_exports.object({ adapter: external_exports.literal("pgvector").optional() }).strict()]).optional(),
19808
+ search: external_exports.union([external_exports.boolean(), external_exports.object({ adapter: external_exports.literal("postgres").optional() }).strict()]).optional(),
19809
+ storage: external_exports.discriminatedUnion("adapter", [
19810
+ external_exports.object({ adapter: external_exports.literal("filesystem"), path: external_exports.string().trim().min(1).optional(), ...uploadLimits }).strict(),
19811
+ external_exports.object({
19812
+ adapter: external_exports.literal("azure-blob"),
19813
+ accountUrl: external_exports.string().url().refine(isAzureBlobAccountUrl),
19814
+ container: external_exports.string().trim().min(3).max(63).regex(/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u),
19815
+ ...uploadLimits
19816
+ }).strict()
19817
+ ]).optional()
19818
+ };
19819
+ var stableLocalFeaturesInput = external_exports.object({
19820
+ ...localAdapterInputs,
19821
+ dashboard: external_exports.union([external_exports.boolean(), external_exports.object({ enabled: external_exports.boolean().optional() }).strict()]).optional()
19822
+ }).optional();
19823
+ var legacyLocalFeaturesInput = external_exports.object({
19824
+ ...localAdapterInputs,
19825
+ dashboard: external_exports.object({
19826
+ enabled: external_exports.boolean().optional(),
19827
+ path: external_exports.string().min(1).optional(),
19828
+ port: external_exports.number().int().min(1).max(65535).optional()
19829
+ }).optional(),
19830
+ seed: external_exports.object({ enabled: external_exports.boolean().optional() }).optional(),
19831
+ reset: external_exports.object({ enabled: external_exports.boolean().optional() }).optional()
19832
+ }).optional();
19833
+ function validateStableLocalFeatures(config2) {
19834
+ if (!config2 || typeof config2 !== "object" || !Object.hasOwn(config2, "localFeatures"))
19835
+ return;
19836
+ const parsed = stableLocalFeaturesInput.safeParse(config2.localFeatures);
19837
+ if (parsed.success)
19838
+ return;
19839
+ const key = parsed.error.issues[0]?.path[0];
19840
+ const field = typeof key === "string" && (Object.hasOwn(localAdapterInputs, key) || key === "dashboard") ? key : void 0;
19841
+ failProjectConfig(field === "rag" ? "CONFIG_LOCAL_RAG_INVALID" : "CONFIG_LOCAL_FEATURES_INVALID", "Correct the local feature configuration before retrying.", field === "rag" ? 'Set localFeatures.rag to true, false, {}, or { adapter: "pgvector" } in gencow.config.js or gencow.config.ts, then rerun the command.' : `Correct localFeatures${field ? `.${field}` : ""} in gencow.config.js or gencow.config.ts, then rerun the command.`);
19842
+ }
19843
+ function normalizeLocalFeatures(config2) {
19844
+ const stable = config2.localFeatures;
19845
+ const legacy = config2.experimental?.localFeatures;
19846
+ const database = stable?.database ?? legacy?.database;
19847
+ const rag = stable?.rag ?? legacy?.rag;
19848
+ const search = stable?.search ?? legacy?.search;
19849
+ const dashboard = stable?.dashboard ?? legacy?.dashboard?.enabled ?? (legacy?.dashboard === void 0 ? void 0 : {});
19850
+ const storage = stable?.storage ?? legacy?.storage;
19851
+ return {
19852
+ ...database === void 0 ? {} : { database },
19853
+ ...rag === void 0 ? {} : { rag },
19854
+ ...search === void 0 ? {} : { search },
19855
+ ...dashboard === void 0 ? {} : { dashboard },
19856
+ ...storage === void 0 ? {} : {
19857
+ storage: storage.adapter === "filesystem" ? {
19858
+ ...storage,
19859
+ path: storage.path ?? (stable?.storage ? void 0 : config2.storage) ?? DEFAULT_LOCAL_STORAGE_PATH
19860
+ } : storage
19861
+ }
19862
+ };
19863
+ }
19864
+ function resolveLocalRuntimeFeatures(config2, environment) {
19865
+ const features = normalizeLocalFeatures(config2);
19866
+ return {
19867
+ ...features,
19868
+ database: features.database ?? {
19869
+ adapter: environment.DATABASE_URL?.trim() ? "postgres" : "pglite"
19870
+ },
19871
+ search: features.search ?? true,
19872
+ storage: features.storage ?? { adapter: "filesystem", path: config2.storage ?? DEFAULT_LOCAL_STORAGE_PATH },
19873
+ dashboard: {
19874
+ enabled: typeof features.dashboard === "boolean" ? features.dashboard : features.dashboard?.enabled !== false
19875
+ }
19876
+ };
19877
+ }
19878
+
19724
19879
  // ../shared/dist/src/config/index.js
19725
19880
  function isLocalHttpOrigin(url2) {
19726
19881
  return url2.protocol === "http:" && (url2.hostname === "localhost" || url2.hostname === "127.0.0.1") && url2.port !== "";
@@ -19795,7 +19950,50 @@ var cloudFeaturesInput = external_exports.object({
19795
19950
  ai: cloudFeatureToggleInput.optional(),
19796
19951
  admin: cloudFeatureToggleInput.optional()
19797
19952
  }).catchall(cloudFeatureToggleInput).optional();
19953
+ var experimentalInput = external_exports.object({
19954
+ output: external_exports.literal("standalone").optional(),
19955
+ standaloneEntryDir: external_exports.string().trim().min(1).optional(),
19956
+ localFeatures: legacyLocalFeaturesInput
19957
+ }).optional();
19958
+ function validateExperimentalConfig(config2) {
19959
+ if (!config2 || typeof config2 !== "object" || !Object.hasOwn(config2, "experimental"))
19960
+ return;
19961
+ const parsed = experimentalInput.safeParse(config2.experimental);
19962
+ if (parsed.success)
19963
+ return;
19964
+ const safeKeys = /* @__PURE__ */ new Set([
19965
+ "output",
19966
+ "standaloneEntryDir",
19967
+ "localFeatures",
19968
+ "database",
19969
+ "adapter",
19970
+ "rag",
19971
+ "search",
19972
+ "storage",
19973
+ "accountUrl",
19974
+ "container",
19975
+ "maxFileSizeBytes",
19976
+ "maxMultipartBodyBytes",
19977
+ "maxFilesPerRequest",
19978
+ "dashboard",
19979
+ "enabled",
19980
+ "path",
19981
+ "port",
19982
+ "seed",
19983
+ "reset"
19984
+ ]);
19985
+ const issuePath = parsed.error.issues[0]?.path ?? [];
19986
+ const field = issuePath.every((part) => typeof part === "string" && safeKeys.has(part)) ? ["experimental", ...issuePath].join(".") : "experimental";
19987
+ failProjectConfig("CONFIG_EXPERIMENTAL_INVALID", "Correct the experimental configuration before retrying.", `Correct ${field} in gencow.config.js or gencow.config.ts, then rerun the command.`);
19988
+ }
19989
+ function validateProjectFeatures(config2) {
19990
+ validateStandaloneOutput(config2);
19991
+ validateExperimentalConfig(config2);
19992
+ validateStableLocalFeatures(config2);
19993
+ }
19798
19994
  var rawConfigSchema = external_exports.object({
19995
+ experimental: experimentalInput,
19996
+ localFeatures: stableLocalFeaturesInput,
19799
19997
  rootDir: external_exports.string().optional(),
19800
19998
  functionsDir: external_exports.string().optional().describe("Deprecated \u2014 use `rootDir`."),
19801
19999
  envFile: external_exports.string().optional(),
@@ -19821,7 +20019,7 @@ var GENCOW_CONFIG_DEFAULTS = Object.freeze({
19821
20019
  envFile: "./gencow/.env",
19822
20020
  schema: "./gencow/schema.ts",
19823
20021
  codegen: { clientOutDir: "./src/gencow", authSchema: true, importExtension: "none" },
19824
- storage: "./.gencow/uploads",
20022
+ storage: DEFAULT_LOCAL_STORAGE_PATH,
19825
20023
  db: { url: "./.gencow/data" },
19826
20024
  port: 5456,
19827
20025
  frontendOrigins: [],
@@ -19901,6 +20099,20 @@ var gencowConfigSchema = rawConfigSchema.transform((v) => {
19901
20099
  frontendOrigins: (v.frontendOrigins ?? []).map((origin) => normalizeFrontendOrigin(origin)),
19902
20100
  trustedOrigins: v.trustedOrigins ?? []
19903
20101
  };
20102
+ const localFeatures = normalizeLocalFeatures(v);
20103
+ if (Object.keys(localFeatures).length)
20104
+ result.localFeatures = localFeatures;
20105
+ if (v.experimental) {
20106
+ const { localFeatures: legacy, ...experimental } = v.experimental;
20107
+ result.experimental = {
20108
+ ...experimental,
20109
+ ...legacy ? { localFeatures: {
20110
+ ...legacy.seed === void 0 ? {} : { seed: legacy.seed },
20111
+ ...legacy.reset === void 0 ? {} : { reset: legacy.reset }
20112
+ } } : {},
20113
+ ...experimental.output === "standalone" && experimental.standaloneEntryDir === void 0 ? { standaloneEntryDir: "./.gencow/build/gencow" } : {}
20114
+ };
20115
+ }
19904
20116
  if (clients?.length)
19905
20117
  result.clients = clients;
19906
20118
  if (v.deploy?.app)
@@ -19925,5 +20137,9 @@ export {
19925
20137
  isAnalyzerAuditorConfigured,
19926
20138
  normalizeFrontendOrigin,
19927
20139
  resolveConfiguredAuditorImplementation,
19928
- shouldSyncManagedDependencies
20140
+ resolveLocalRuntimeFeatures,
20141
+ shouldSyncManagedDependencies,
20142
+ validateExperimentalConfig,
20143
+ validateProjectFeatures,
20144
+ validateStandaloneOutput
19929
20145
  };