gencow 0.1.299 → 0.2.1

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 (151) 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 +15 -8
  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/ai/ai-facade.ts +38 -15
  143. package/templateFeature/ai/manifest.json +1 -0
  144. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  145. package/templateFeature/tools/manifest.json +5 -2
  146. package/templateFeature/tools/tools.ts +3 -3
  147. package/runtime/server.mjs +0 -14389
  148. package/scripts/bundle-server.mjs +0 -223
  149. package/server/config.js +0 -1
  150. package/server/index.js +0 -1
  151. package/server/package.json +0 -6
@@ -0,0 +1,125 @@
1
+ import {
2
+ RuntimeDiagnosticError,
3
+ runtimeDiagnostic
4
+ } from "./chunk-AEBW7XZJ.mjs";
5
+
6
+ // ../runtime/dist/adapters/storage/filesystem-errors.js
7
+ function filesystemErrorCode(error) {
8
+ return error && typeof error === "object" && "code" in error ? error.code : void 0;
9
+ }
10
+ function filesystemObjectNotFound() {
11
+ return new RuntimeDiagnosticError({
12
+ code: "RUNTIME_STORAGE_OBJECT_NOT_FOUND",
13
+ stage: "request",
14
+ capability: "storage",
15
+ servingStarted: "unchanged",
16
+ dataImpact: "none",
17
+ retryable: false,
18
+ retryPrecondition: "Use a stored object ID that exists in the selected catalog.",
19
+ nextAction: "Check the selected object with ctx.storage.getMeta before requesting a visibility update."
20
+ });
21
+ }
22
+ function filesystemMetadataInvalid() {
23
+ return new RuntimeDiagnosticError({
24
+ code: "RUNTIME_STORAGE_METADATA_INVALID",
25
+ stage: "request",
26
+ capability: "storage",
27
+ servingStarted: "unchanged",
28
+ dataImpact: "none",
29
+ retryable: false,
30
+ retryPrecondition: "Restore valid object metadata through its storage owner before repeating the operation.",
31
+ nextAction: "Have the trusted filesystem storage owner restore valid metadata from a verified backup; do not blindly repeat mutations."
32
+ });
33
+ }
34
+ function filesystemMetadataInputInvalid() {
35
+ return new RuntimeDiagnosticError({
36
+ code: "RUNTIME_LOCAL_FILES_INPUT_INVALID",
37
+ stage: "request",
38
+ capability: "storage",
39
+ servingStarted: "unchanged",
40
+ dataImpact: "none",
41
+ retryable: false,
42
+ retryPrecondition: "Provide string name and MIME type values whose complete serialized metadata sidecar fits within 64 KiB; invalid visibility values are stored as private. Before retrying a containing mutation, inspect any earlier effects through the selected Storage API or the application's operation status.",
43
+ nextAction: "Reduce the rejected object's combined name and MIME metadata to fit the 64 KiB sidecar bound. The rejected storage sub-operation wrote no object; inspect any earlier effects from the containing mutation through the selected Storage API or application status before a deliberate retry. Do not blindly replay the whole mutation."
44
+ });
45
+ }
46
+ function filesystemStorageInputInvalid() {
47
+ return new RuntimeDiagnosticError({
48
+ code: "RUNTIME_LOCAL_FILES_INPUT_INVALID",
49
+ stage: "request",
50
+ capability: "storage",
51
+ servingStarted: "unchanged",
52
+ dataImpact: "none",
53
+ retryable: false,
54
+ retryPrecondition: "Use a valid flat object ID and private or public visibility. Before retrying a containing mutation, inspect any earlier effects through the selected Storage API or the application's operation status.",
55
+ nextAction: "Use the selected Storage API with a valid flat object ID and private or public visibility. This rejected Core Storage sub-operation changed no file; inspect earlier effects from the containing mutation through the selected Storage API or application status before a deliberate retry. Do not blindly replay the whole mutation."
56
+ });
57
+ }
58
+ function filesystemMetadataUpdateLimitExceeded() {
59
+ return new RuntimeDiagnosticError({
60
+ code: "RUNTIME_STORAGE_METADATA_UPDATE_LIMIT_EXCEEDED",
61
+ stage: "request",
62
+ capability: "storage",
63
+ servingStarted: "unchanged",
64
+ dataImpact: "none",
65
+ retryable: false,
66
+ retryPrecondition: "Create a new object through the selected Storage API with shorter name and MIME type metadata, verify it with getMeta, then request visibility only if that new object is intended to be public.",
67
+ nextAction: "Keep the original object and private bytes unchanged. Re-store through the selected Storage API under a shorter filename and/or MIME type, verify the new ID with getMeta, then explicitly publish the new object only if intended. Do not edit sidecar metadata or blindly retry."
68
+ });
69
+ }
70
+ async function filesystemMutationWrite(operation) {
71
+ try {
72
+ return await operation();
73
+ } catch (error) {
74
+ const diagnostic = runtimeDiagnostic(error);
75
+ throw new RuntimeDiagnosticError({
76
+ ...diagnostic ?? {
77
+ code: "RUNTIME_STORAGE_PROVIDER_UNAVAILABLE",
78
+ stage: "request",
79
+ capability: "storage"
80
+ },
81
+ servingStarted: "unchanged",
82
+ dataImpact: diagnostic?.dataImpact === "committed" ? "committed" : "unknown",
83
+ retryable: false,
84
+ retryPrecondition: "Inspect the current object's metadata and visibility through the selected storage adapter before issuing another mutation.",
85
+ nextAction: "Use the selected storage adapter's getMeta result to inspect current state before a deliberate new change. Storage may have changed; do not blindly retry."
86
+ });
87
+ }
88
+ }
89
+ function filesystemFailure(error, write) {
90
+ if (runtimeDiagnostic(error))
91
+ return error;
92
+ const code = filesystemErrorCode(error);
93
+ if (code === "ENOENT")
94
+ return filesystemObjectNotFound();
95
+ const denied = code === "EACCES" || code === "EPERM" || code === "EROFS";
96
+ return new RuntimeDiagnosticError({
97
+ code: denied ? "RUNTIME_STORAGE_ACCESS_DENIED" : "RUNTIME_STORAGE_PROVIDER_UNAVAILABLE",
98
+ stage: "request",
99
+ capability: "storage",
100
+ servingStarted: "unchanged",
101
+ dataImpact: write ? "unknown" : "none",
102
+ retryable: !write && !denied,
103
+ retryPrecondition: "Restore verified filesystem storage availability and access; inspect existing effects before repeating a write.",
104
+ nextAction: denied ? "Have the trusted storage owner restore the configured directory and object permissions, then verify access before retrying." : "Check filesystem storage availability and the object's current state through its trusted owner; do not blindly repeat a write."
105
+ });
106
+ }
107
+ async function filesystemCall(write, operation) {
108
+ try {
109
+ return await operation();
110
+ } catch (error) {
111
+ throw filesystemFailure(error, write);
112
+ }
113
+ }
114
+
115
+ export {
116
+ filesystemErrorCode,
117
+ filesystemObjectNotFound,
118
+ filesystemMetadataInvalid,
119
+ filesystemMetadataInputInvalid,
120
+ filesystemStorageInputInvalid,
121
+ filesystemMetadataUpdateLimitExceeded,
122
+ filesystemMutationWrite,
123
+ filesystemFailure,
124
+ filesystemCall
125
+ };
@@ -0,0 +1,14 @@
1
+ // ../runtime/dist/local-development-compatibility.js
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ var serverLocalStartup = new AsyncLocalStorage();
4
+ function withServerCompatibleLocalStartup(start) {
5
+ return serverLocalStartup.run(true, start);
6
+ }
7
+ function isServerCompatibleLocalStartup() {
8
+ return serverLocalStartup.getStore() === true;
9
+ }
10
+
11
+ export {
12
+ withServerCompatibleLocalStartup,
13
+ isServerCompatibleLocalStartup
14
+ };
@@ -0,0 +1,106 @@
1
+ import {
2
+ RuntimeDiagnosticError,
3
+ formatRuntimeDiagnostic,
4
+ runtimeDiagnostic
5
+ } from "./chunk-AEBW7XZJ.mjs";
6
+
7
+ // ../runtime/dist/app/startup-errors.js
8
+ var runtimeCompositionErrors = /* @__PURE__ */ new WeakSet();
9
+ var RuntimeCompositionError = class extends Error {
10
+ diagnostic;
11
+ constructor(diagnostic) {
12
+ super(formatRuntimeDiagnostic(diagnostic));
13
+ this.name = "RuntimeCompositionError";
14
+ this.diagnostic = diagnostic;
15
+ runtimeCompositionErrors.add(this);
16
+ }
17
+ };
18
+ function isRuntimeCompositionError(error) {
19
+ return typeof error === "object" && error !== null && runtimeCompositionErrors.has(error);
20
+ }
21
+ function runtimeStartupError(code, nextAction, dataImpact = "none", capabilityOrCorrelationId) {
22
+ const correlationId = typeof capabilityOrCorrelationId === "string" && /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/iu.test(capabilityOrCorrelationId) ? capabilityOrCorrelationId : void 0;
23
+ const capability = correlationId ? void 0 : capabilityOrCorrelationId;
24
+ return new RuntimeCompositionError({
25
+ code,
26
+ stage: "startup",
27
+ servingStarted: false,
28
+ dataImpact,
29
+ ...capability ? { capability } : {},
30
+ retryable: false,
31
+ retryPrecondition: code === "RUNTIME_COMPONENT_DEPENDENCY_INVALID" ? "Correct the selected Runtime wiring/config before restarting." : "Correct the declared artifact or launch configuration before restarting.",
32
+ nextAction,
33
+ ...correlationId ? { correlationId } : {}
34
+ });
35
+ }
36
+ async function initializeRuntimeComponent(initialize) {
37
+ try {
38
+ return await initialize();
39
+ } catch (error) {
40
+ if (runtimeDiagnostic(error))
41
+ throw error;
42
+ throw runtimeStartupError("RUNTIME_COMPONENT_INITIALIZATION_FAILED", "Inspect selected provider readiness and any persistent initialization effects before restarting; cleanup only releases Runtime-owned resources.", "unknown");
43
+ }
44
+ }
45
+ function runtimeCompositionFailure(error) {
46
+ if (runtimeDiagnostic(error))
47
+ return error;
48
+ return runtimeStartupError("RUNTIME_COMPONENT_DEPENDENCY_INVALID", "Correct selected Runtime wiring/config before restarting; inspect any earlier initialization effects first.", "unknown");
49
+ }
50
+ function safeStartupPrimary(error) {
51
+ if (error instanceof Error && runtimeDiagnostic(error))
52
+ return error;
53
+ return new RuntimeDiagnosticError({
54
+ code: "RUNTIME_COMPONENT_INITIALIZATION_FAILED",
55
+ stage: "startup",
56
+ servingStarted: false,
57
+ dataImpact: "unknown",
58
+ retryable: false,
59
+ retryPrecondition: "Inspect selected provider readiness and persistent startup effects before restarting.",
60
+ nextAction: "Inspect the safe Runtime startup status and verify prior effects; do not blindly repeat initialization.",
61
+ capability: "application"
62
+ });
63
+ }
64
+ function reportCleanupFailure(logger, stage, correlationId) {
65
+ try {
66
+ logger.error("runtime.cleanup.failed", {
67
+ "runtime.stage": stage,
68
+ "runtime.public_code": "RUNTIME_RESOURCE_DISPOSAL_FAILED",
69
+ "runtime.serving_started": stage === "startup" ? false : "unchanged",
70
+ "runtime.data_impact": "unknown",
71
+ "runtime.retryable": false,
72
+ "runtime.retry_precondition": "Inspect the safe cleanup outcome and prior operation effects before restarting.",
73
+ "runtime.next_action": "Inspect safe generation/correlation status. Do not repeat completed mutations or resource disposal.",
74
+ ...correlationId ? { "request.id": correlationId } : {}
75
+ });
76
+ return true;
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ function reportRuntimeScopedWorkFailure(logger, correlationId) {
82
+ try {
83
+ logger.error("runtime.scoped_work.failed", {
84
+ "runtime.stage": "request",
85
+ "runtime.public_code": "RUNTIME_SCOPED_WORK_FAILED",
86
+ "runtime.serving_started": "unchanged",
87
+ "runtime.data_impact": "unknown",
88
+ "runtime.retryable": false,
89
+ "runtime.retry_precondition": "Inspect the request correlation and prior scoped-work effects before deliberately retrying.",
90
+ "runtime.next_action": "Inspect the original operation outcome; do not replay mutations or create replacement work.",
91
+ "request.id": correlationId
92
+ });
93
+ } catch {
94
+ }
95
+ }
96
+
97
+ export {
98
+ RuntimeCompositionError,
99
+ isRuntimeCompositionError,
100
+ runtimeStartupError,
101
+ initializeRuntimeComponent,
102
+ runtimeCompositionFailure,
103
+ safeStartupPrimary,
104
+ reportCleanupFailure,
105
+ reportRuntimeScopedWorkFailure
106
+ };
@@ -0,0 +1,128 @@
1
+ import {
2
+ RuntimeDatabaseRlsError,
3
+ RuntimeDiagnosticError,
4
+ validateRlsSessionContext
5
+ } from "./chunk-AEBW7XZJ.mjs";
6
+
7
+ // ../runtime/dist/app/request-input-snapshot.js
8
+ function requestContextInputError() {
9
+ return new RuntimeDatabaseRlsError("RUNTIME_DATABASE_RLS_CONTEXT_INVALID", "request", "Correct the trusted host identity-to-RLS mapper; do not use client-supplied identity values.", "none");
10
+ }
11
+ function freezeIdentityContainers(value, seen = /* @__PURE__ */ new WeakSet()) {
12
+ if (!value || typeof value !== "object" || seen.has(value))
13
+ return;
14
+ seen.add(value);
15
+ for (const field of Object.values(value))
16
+ freezeIdentityContainers(field, seen);
17
+ Object.freeze(value);
18
+ }
19
+ function snapshotRuntimeIdentity(identity) {
20
+ if (!identity)
21
+ return null;
22
+ const copy = structuredClone(identity);
23
+ freezeIdentityContainers(copy);
24
+ return copy;
25
+ }
26
+ function invalidAuthenticationEvidence() {
27
+ return new RuntimeDiagnosticError({
28
+ code: "RUNTIME_AUTH_SESSION_UNAVAILABLE",
29
+ stage: "request",
30
+ capability: "auth",
31
+ servingStarted: "unchanged",
32
+ dataImpact: "none",
33
+ retryable: false,
34
+ retryPrecondition: "Use one trusted authentication result with a coherent method and verified identity.",
35
+ nextAction: "Inspect the selected authentication provider's verified result shape and retry only after its identity/session evidence is corrected."
36
+ });
37
+ }
38
+ function snapshotRuntimeAuthentication(input) {
39
+ try {
40
+ if (!input || typeof input !== "object" || Array.isArray(input))
41
+ throw invalidAuthenticationEvidence();
42
+ const record = input;
43
+ const method = record.method;
44
+ if (method !== "session" && method !== "jwt" && method !== "host" && method !== "anonymous")
45
+ throw invalidAuthenticationEvidence();
46
+ if (!Object.hasOwn(record, "identity"))
47
+ throw invalidAuthenticationEvidence();
48
+ const allowedKeys = method === "session" ? ["method", "identity", "session", "credentialStatus"] : ["method", "identity", "credentialStatus"];
49
+ if (Object.keys(record).some((key) => !allowedKeys.includes(key)))
50
+ throw invalidAuthenticationEvidence();
51
+ const credentialStatus = record.credentialStatus;
52
+ if (credentialStatus !== void 0 && !["absent", "invalid", "verified", "unknown"].includes(credentialStatus))
53
+ throw invalidAuthenticationEvidence();
54
+ const rawIdentity = record.identity;
55
+ if (rawIdentity !== null && (!rawIdentity || typeof rawIdentity !== "object" || Array.isArray(rawIdentity)))
56
+ throw invalidAuthenticationEvidence();
57
+ const identity = snapshotRuntimeIdentity(rawIdentity);
58
+ if (identity && (typeof identity.id !== "string" || !identity.id.trim() || identity.email !== void 0 && (typeof identity.email !== "string" || !identity.email.trim()) || identity.name !== void 0 && typeof identity.name !== "string"))
59
+ throw invalidAuthenticationEvidence();
60
+ if (method === "anonymous" && identity !== null)
61
+ throw invalidAuthenticationEvidence();
62
+ if ((method === "session" || method === "jwt") && identity === null)
63
+ throw invalidAuthenticationEvidence();
64
+ if (method !== "session" && Object.hasOwn(record, "session"))
65
+ throw invalidAuthenticationEvidence();
66
+ if (method === "session") {
67
+ let session;
68
+ if (record.session === void 0) {
69
+ session = void 0;
70
+ } else {
71
+ if (!record.session || typeof record.session !== "object" || Array.isArray(record.session))
72
+ throw invalidAuthenticationEvidence();
73
+ const rawSession = record.session;
74
+ if (Object.keys(rawSession).some((key) => key !== "id" && key !== "expiresAt"))
75
+ throw invalidAuthenticationEvidence();
76
+ const id = rawSession.id;
77
+ const expiresAt = rawSession.expiresAt;
78
+ if (typeof id !== "string" || !id.trim() || id.length > 256)
79
+ throw invalidAuthenticationEvidence();
80
+ if (expiresAt !== void 0 && (typeof expiresAt !== "string" || expiresAt.length > 64 || !Number.isFinite(Date.parse(expiresAt))))
81
+ throw invalidAuthenticationEvidence();
82
+ session = Object.freeze({
83
+ id,
84
+ ...typeof expiresAt === "string" ? { expiresAt: new Date(expiresAt).toISOString() } : {}
85
+ });
86
+ }
87
+ if (credentialStatus !== void 0 && credentialStatus !== "verified")
88
+ throw invalidAuthenticationEvidence();
89
+ return Object.freeze({
90
+ method,
91
+ identity,
92
+ ...session ? { session } : {},
93
+ ...credentialStatus === void 0 ? {} : { credentialStatus }
94
+ });
95
+ }
96
+ if ((method === "jwt" || method === "host" && identity !== null) && credentialStatus !== void 0 && credentialStatus !== "verified")
97
+ throw invalidAuthenticationEvidence();
98
+ return Object.freeze({
99
+ method,
100
+ identity,
101
+ ...credentialStatus === void 0 ? {} : { credentialStatus }
102
+ });
103
+ } catch (error) {
104
+ if (error instanceof RuntimeDiagnosticError)
105
+ throw error;
106
+ throw invalidAuthenticationEvidence();
107
+ }
108
+ }
109
+ function snapshotRuntimeRls(input) {
110
+ try {
111
+ if (!input || typeof input !== "object" || Array.isArray(input))
112
+ throw new Error("invalid RLS record");
113
+ const copy = { ...input };
114
+ if (Object.values(copy).some((value) => typeof value !== "string"))
115
+ throw new Error("invalid RLS scalar");
116
+ validateRlsSessionContext(copy);
117
+ return Object.freeze(copy);
118
+ } catch {
119
+ throw requestContextInputError();
120
+ }
121
+ }
122
+
123
+ export {
124
+ requestContextInputError,
125
+ snapshotRuntimeIdentity,
126
+ snapshotRuntimeAuthentication,
127
+ snapshotRuntimeRls
128
+ };
@@ -0,0 +1,282 @@
1
+ // ../runtime/dist/database-setup/database-security-policy.js
2
+ import { createHash } from "node:crypto";
3
+ var ALL_FACTS = Object.freeze([
4
+ "shared-operational-principal",
5
+ "setup-shares-operational-principal",
6
+ "application-owns-nonsystem-table",
7
+ "application-reaches-rls-owner",
8
+ "application-privileged",
9
+ "serving-reaches-selected-rag-owner",
10
+ "application-reaches-framework-journal-owner",
11
+ "application-can-mutate-framework-journal",
12
+ "application-can-create-schema",
13
+ "maintenance-bypasses-rls",
14
+ "maintenance-unauthorized-elevation",
15
+ "setup-unauthorized-elevation"
16
+ ]);
17
+ var CLI_FACTS = Object.freeze([
18
+ "shared-operational-principal",
19
+ "setup-shares-operational-principal",
20
+ "application-owns-nonsystem-table",
21
+ "application-reaches-rls-owner",
22
+ "application-privileged",
23
+ "application-can-create-schema",
24
+ "maintenance-bypasses-rls",
25
+ "maintenance-unauthorized-elevation",
26
+ "setup-unauthorized-elevation"
27
+ ]);
28
+ var RESOURCE_ADMISSION_FACTS = Object.freeze([
29
+ "shared-operational-principal",
30
+ "application-owns-nonsystem-table",
31
+ "application-reaches-rls-owner",
32
+ "application-privileged",
33
+ "application-can-create-schema",
34
+ "maintenance-bypasses-rls",
35
+ "maintenance-unauthorized-elevation"
36
+ ]);
37
+ var REQUIRED_LOCAL_IDENTITY = Object.freeze([
38
+ "shared-operational-principal"
39
+ ]);
40
+ var EMPTY = Object.freeze([]);
41
+ var ALL_STAGES = Object.freeze([
42
+ "resource-admission",
43
+ "cli-prewrite",
44
+ "preparation",
45
+ "prewrite",
46
+ "precommit",
47
+ "readback"
48
+ ]);
49
+ function evidence(required, optional) {
50
+ return Object.freeze({ required: Object.freeze([...required]), optional: Object.freeze([...optional]) });
51
+ }
52
+ function stageEvidence(mode) {
53
+ const required = mode === "strict" ? ALL_FACTS : REQUIRED_LOCAL_IDENTITY;
54
+ const optional = mode === "strict" ? EMPTY : ALL_FACTS.filter((id) => !required.includes(id));
55
+ return Object.freeze({
56
+ "resource-admission": evidence(mode === "strict" ? RESOURCE_ADMISSION_FACTS : REQUIRED_LOCAL_IDENTITY, mode === "strict" ? EMPTY : RESOURCE_ADMISSION_FACTS.filter((id) => !required.includes(id))),
57
+ "cli-prewrite": evidence(mode === "strict" ? CLI_FACTS : REQUIRED_LOCAL_IDENTITY, mode === "strict" ? EMPTY : CLI_FACTS.filter((id) => !required.includes(id))),
58
+ preparation: evidence(required, optional),
59
+ prewrite: evidence(required, optional),
60
+ precommit: evidence(required, optional),
61
+ readback: evidence(required, optional)
62
+ });
63
+ }
64
+ function rules(mode) {
65
+ const ordinary = mode === "development" ? "warn" : "reject";
66
+ return Object.freeze({
67
+ "shared-operational-principal": ordinary,
68
+ "setup-shares-operational-principal": ordinary,
69
+ "application-owns-nonsystem-table": ordinary,
70
+ "application-reaches-rls-owner": ordinary,
71
+ "application-privileged": ordinary,
72
+ "serving-reaches-selected-rag-owner": ordinary,
73
+ "application-reaches-framework-journal-owner": ordinary,
74
+ "application-can-mutate-framework-journal": ordinary,
75
+ "application-can-create-schema": ordinary,
76
+ "maintenance-bypasses-rls": Object.freeze({
77
+ capability: "maintenanceBypassRls",
78
+ ifAdmitted: "allow",
79
+ otherwise: ordinary
80
+ }),
81
+ "maintenance-unauthorized-elevation": ordinary,
82
+ "setup-unauthorized-elevation": ordinary
83
+ });
84
+ }
85
+ function deepFreezeDefinition(definition) {
86
+ for (const item of Object.values(definition.evidence))
87
+ Object.freeze(item);
88
+ Object.freeze(definition.evidence);
89
+ Object.freeze(definition.rules);
90
+ return Object.freeze(definition);
91
+ }
92
+ var REGISTRY = Object.freeze({
93
+ "local-development": deepFreezeDefinition({
94
+ id: "local-development",
95
+ version: 1,
96
+ allowedHosts: Object.freeze(["standalone"]),
97
+ requiredEvidenceUnavailable: "reject",
98
+ optionalEvidenceUnavailable: "warn",
99
+ evidence: stageEvidence("development"),
100
+ rules: rules("development")
101
+ }),
102
+ "local-strict": deepFreezeDefinition({
103
+ id: "local-strict",
104
+ version: 1,
105
+ allowedHosts: Object.freeze(["standalone"]),
106
+ requiredEvidenceUnavailable: "reject",
107
+ optionalEvidenceUnavailable: "reject",
108
+ evidence: stageEvidence("strict"),
109
+ rules: rules("strict")
110
+ })
111
+ });
112
+ function exactRecord(value, keys) {
113
+ if (value === null || typeof value !== "object" || Array.isArray(value))
114
+ return void 0;
115
+ const prototype = Object.getPrototypeOf(value);
116
+ if (prototype !== Object.prototype && prototype !== null)
117
+ return void 0;
118
+ const ownKeys = Reflect.ownKeys(value);
119
+ if (ownKeys.length !== keys.length || ownKeys.some((key) => typeof key !== "string" || !keys.includes(key)))
120
+ return void 0;
121
+ const result = /* @__PURE__ */ Object.create(null);
122
+ for (const key of keys) {
123
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
124
+ if (!descriptor || !("value" in descriptor))
125
+ return void 0;
126
+ result[key] = descriptor.value;
127
+ }
128
+ return result;
129
+ }
130
+ function definitionDigest(definition) {
131
+ return createHash("sha256").update(JSON.stringify(definition)).digest("hex");
132
+ }
133
+ function capture(reference, defaultIfMissing) {
134
+ let id;
135
+ let version;
136
+ if (reference === void 0 && defaultIfMissing) {
137
+ id = "local-development";
138
+ version = 1;
139
+ } else {
140
+ const value = exactRecord(reference, ["id", "version"]);
141
+ if (!value)
142
+ return Object.freeze({ ok: false, reason: "reference-invalid" });
143
+ id = value.id;
144
+ version = value.version;
145
+ }
146
+ if (typeof id !== "string" || !Object.hasOwn(REGISTRY, id) || version !== 1)
147
+ return Object.freeze({ ok: false, reason: "unknown-policy" });
148
+ const definition = REGISTRY[id];
149
+ const policy = Object.freeze({
150
+ id: definition.id,
151
+ version: definition.version,
152
+ definitionDigest: definitionDigest(definition)
153
+ });
154
+ return Object.freeze({ ok: true, policy });
155
+ }
156
+ function captureDatabaseSecurityPolicy(reference) {
157
+ return capture(reference, true);
158
+ }
159
+ function verifyCapturedDatabaseSecurityPolicy(candidate, host = "standalone") {
160
+ const value = exactRecord(candidate, ["id", "version", "definitionDigest"]);
161
+ if (!value || typeof value.id !== "string" || !Number.isSafeInteger(value.version) || typeof value.definitionDigest !== "string")
162
+ return Object.freeze({ ok: false, reason: "reference-invalid" });
163
+ if (!Object.hasOwn(REGISTRY, value.id) || value.version !== 1)
164
+ return Object.freeze({ ok: false, reason: "unknown-policy" });
165
+ const definition = REGISTRY[value.id];
166
+ if (value.definitionDigest !== definitionDigest(definition))
167
+ return Object.freeze({ ok: false, reason: "definition-digest-mismatch" });
168
+ if (host !== "standalone" || !definition.allowedHosts.includes(host))
169
+ return Object.freeze({ ok: false, reason: "host-not-allowed" });
170
+ const policy = Object.freeze({
171
+ id: definition.id,
172
+ version: definition.version,
173
+ definitionDigest: value.definitionDigest
174
+ });
175
+ return Object.freeze({ ok: true, policy });
176
+ }
177
+ function safeFact(value) {
178
+ if (value === null || typeof value !== "object" || Array.isArray(value))
179
+ return void 0;
180
+ const descriptor = Object.getOwnPropertyDescriptor(value, "status");
181
+ if (!descriptor || !("value" in descriptor))
182
+ return void 0;
183
+ if (descriptor.value === "unavailable" || descriptor.value === "not-applicable") {
184
+ return exactRecord(value, ["status"]) ? Object.freeze({ status: descriptor.value }) : void 0;
185
+ }
186
+ if (descriptor.value !== "observed")
187
+ return void 0;
188
+ const record = exactRecord(value, ["status", "value"]);
189
+ if (!record || typeof record.value !== "boolean")
190
+ return void 0;
191
+ return Object.freeze({ status: "observed", value: record.value });
192
+ }
193
+ function safeSnapshot(value) {
194
+ const record = exactRecord(value, ["stage", "capabilities", "facts"]);
195
+ if (!record || typeof record.stage !== "string" || !ALL_STAGES.includes(record.stage))
196
+ return void 0;
197
+ const capabilities = exactRecord(record.capabilities, ["maintenanceBypassRls"]);
198
+ if (!capabilities || typeof capabilities.maintenanceBypassRls !== "boolean")
199
+ return void 0;
200
+ if (record.facts === null || typeof record.facts !== "object" || Array.isArray(record.facts))
201
+ return void 0;
202
+ const prototype = Object.getPrototypeOf(record.facts);
203
+ if (prototype !== Object.prototype && prototype !== null)
204
+ return void 0;
205
+ const facts = /* @__PURE__ */ Object.create(null);
206
+ for (const key of Reflect.ownKeys(record.facts)) {
207
+ if (typeof key !== "string" || !ALL_FACTS.includes(key))
208
+ return void 0;
209
+ const descriptor = Object.getOwnPropertyDescriptor(record.facts, key);
210
+ if (!descriptor || !("value" in descriptor))
211
+ return void 0;
212
+ const fact = safeFact(descriptor.value);
213
+ if (!fact)
214
+ return void 0;
215
+ facts[key] = fact;
216
+ }
217
+ return Object.freeze({
218
+ stage: record.stage,
219
+ capabilities: Object.freeze({ maintenanceBypassRls: capabilities.maintenanceBypassRls }),
220
+ facts: Object.freeze(facts)
221
+ });
222
+ }
223
+ var DEVELOPMENT_ACTION = "Review the local database role and ownership posture with its trusted database owner; preserve application data and applied migration history, then restart to recheck.";
224
+ var STRICT_ACTION = "Correct the local database role and ownership posture with its trusted database owner; preserve application data and applied migration history, then restart.";
225
+ var EVIDENCE_ACTION = "Restore PostgreSQL security metadata visibility and restart to recheck the current posture; do not edit migration history or schema objects.";
226
+ function evaluateDatabaseSecurityPolicy(candidate, input) {
227
+ const admitted = verifyCapturedDatabaseSecurityPolicy(candidate);
228
+ if (!admitted.ok)
229
+ return admitted;
230
+ const snapshot = safeSnapshot(input);
231
+ if (!snapshot)
232
+ return Object.freeze({ ok: false, reason: "facts-invalid" });
233
+ const definition = REGISTRY[admitted.policy.id];
234
+ const requirements = definition.evidence[snapshot.stage];
235
+ const expected = /* @__PURE__ */ new Set([...requirements.required, ...requirements.optional]);
236
+ const findings = [];
237
+ let complete = true;
238
+ for (const id of expected) {
239
+ const fact = snapshot.facts[id];
240
+ if (!fact || fact.status === "unavailable") {
241
+ complete = false;
242
+ const required = requirements.required.includes(id);
243
+ const disposition2 = required ? definition.requiredEvidenceUnavailable : definition.optionalEvidenceUnavailable;
244
+ findings.push(Object.freeze({
245
+ id: "security-evidence-unavailable",
246
+ factId: id,
247
+ stage: snapshot.stage,
248
+ disposition: disposition2,
249
+ nextAction: EVIDENCE_ACTION
250
+ }));
251
+ continue;
252
+ }
253
+ if (fact.status === "not-applicable" || !fact.value)
254
+ continue;
255
+ const rule = definition.rules[id];
256
+ const disposition = typeof rule === "string" ? rule : snapshot.capabilities.maintenanceBypassRls ? rule.ifAdmitted : rule.otherwise;
257
+ findings.push(Object.freeze({
258
+ id,
259
+ stage: snapshot.stage,
260
+ disposition,
261
+ nextAction: disposition === "reject" ? STRICT_ACTION : DEVELOPMENT_ACTION
262
+ }));
263
+ }
264
+ const frozenFindings = Object.freeze(findings);
265
+ const warnings = Object.freeze(findings.filter(({ disposition }) => disposition === "warn"));
266
+ const denials = Object.freeze(findings.filter(({ disposition }) => disposition === "reject"));
267
+ return Object.freeze({
268
+ ok: true,
269
+ policy: admitted.policy,
270
+ stage: snapshot.stage,
271
+ complete,
272
+ findings: frozenFindings,
273
+ warnings,
274
+ denials
275
+ });
276
+ }
277
+
278
+ export {
279
+ captureDatabaseSecurityPolicy,
280
+ verifyCapturedDatabaseSecurityPolicy,
281
+ evaluateDatabaseSecurityPolicy
282
+ };