anhedral 0.17.0 → 0.19.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 (174) hide show
  1. package/README.md +33 -68
  2. package/assets/contracts/LICENSE +201 -0
  3. package/assets/contracts/LICENSE.environment +201 -0
  4. package/assets/contracts/LICENSE.operations +201 -0
  5. package/assets/contracts/deployment-provenance.json +15 -0
  6. package/assets/contracts/environment-provenance.json +11 -0
  7. package/assets/contracts/operations-provenance.json +12 -0
  8. package/assets/launch/application.server.ts.txt +13 -0
  9. package/assets/launch/auth-client.ts.txt +4 -0
  10. package/assets/launch/home.tsx.txt +20 -0
  11. package/assets/launch/minimal-application.server.ts.txt +5 -0
  12. package/assets/launch/minimal-server.ts.txt +7 -0
  13. package/assets/launch/oj/OJ.LICENSE +21 -0
  14. package/assets/launch/oj/run.mjs +82 -0
  15. package/assets/launch/oj/runtime.json +21 -0
  16. package/assets/launch/request-context.ts.txt +3 -0
  17. package/assets/launch/root.tsx.txt +26 -0
  18. package/assets/launch/router.tsx.txt +21 -0
  19. package/assets/launch/server.ts.txt +15 -0
  20. package/assets/launch/sign-in.tsx.txt +53 -0
  21. package/assets/launch/styles.css.txt +19 -0
  22. package/assets/security/credential-patterns.d.mts +3 -0
  23. package/assets/security/credential-patterns.mjs +59 -0
  24. package/assets/stack/api-index.ts.txt +6 -1
  25. package/assets/stack/stripe.ts.txt +30 -13
  26. package/assets/ui/catalog.json +36 -324
  27. package/dist/{platforms/web.d.ts → api-proxy.d.ts} +1 -3
  28. package/dist/api-proxy.js +48 -0
  29. package/dist/bin.js +55 -36
  30. package/dist/capability-catalog.d.ts +36 -57
  31. package/dist/capability-catalog.js +65 -67
  32. package/dist/capability-command.d.ts +3 -3
  33. package/dist/capability-command.js +146 -59
  34. package/dist/capability-editor.js +6 -5
  35. package/dist/capability-recipes.js +9 -296
  36. package/dist/cli-arguments.d.ts +2 -0
  37. package/dist/cli-arguments.js +101 -50
  38. package/dist/cli-commands.d.ts +1 -1
  39. package/dist/cli-commands.js +31 -5
  40. package/dist/cli-errors.d.ts +18 -0
  41. package/dist/cli-errors.js +63 -0
  42. package/dist/cli-output.d.ts +22 -0
  43. package/dist/cli-output.js +42 -7
  44. package/dist/command-runner.js +88 -0
  45. package/dist/command-schema.d.ts +16 -0
  46. package/dist/command-schema.js +496 -21
  47. package/dist/command-types.d.ts +1 -0
  48. package/dist/command-types.js +1 -0
  49. package/dist/completion.d.ts +2 -0
  50. package/dist/completion.js +201 -0
  51. package/dist/composition.d.ts +25 -0
  52. package/dist/composition.js +28 -0
  53. package/dist/contracts/cli-transport.d.ts +316 -0
  54. package/dist/contracts/cli-transport.js +236 -0
  55. package/dist/contracts/deployment.d.ts +233 -0
  56. package/dist/contracts/deployment.js +198 -0
  57. package/dist/contracts/environment-file.d.ts +7 -0
  58. package/dist/contracts/environment-file.js +112 -0
  59. package/dist/contracts/environment-transport.d.ts +79 -0
  60. package/dist/contracts/environment-transport.js +110 -0
  61. package/dist/contracts/production-transport.d.ts +71 -0
  62. package/dist/contracts/production-transport.js +56 -0
  63. package/dist/contracts/runtime-logs-transport.d.ts +127 -0
  64. package/dist/contracts/runtime-logs-transport.js +50 -0
  65. package/dist/contracts/source-bundle.d.ts +11 -0
  66. package/dist/contracts/source-bundle.js +197 -0
  67. package/dist/contracts/source-profile.d.ts +4 -0
  68. package/dist/contracts/source-profile.js +5 -0
  69. package/dist/contracts/staging-transport.d.ts +79 -0
  70. package/dist/contracts/staging-transport.js +43 -0
  71. package/dist/dependencies.d.ts +9 -27
  72. package/dist/dependencies.js +19 -66
  73. package/dist/index.d.ts +4 -2
  74. package/dist/index.js +3 -1
  75. package/dist/launch.d.ts +27 -0
  76. package/dist/launch.js +262 -0
  77. package/dist/platform-command.d.ts +9 -0
  78. package/dist/platform-command.js +787 -0
  79. package/dist/platform-environment.d.ts +18 -0
  80. package/dist/platform-environment.js +257 -0
  81. package/dist/platform-operations.d.ts +26 -0
  82. package/dist/platform-operations.js +155 -0
  83. package/dist/platform-production.d.ts +16 -0
  84. package/dist/platform-production.js +135 -0
  85. package/dist/platform-source.d.ts +8 -0
  86. package/dist/platform-source.js +111 -0
  87. package/dist/platform-state.d.ts +15 -0
  88. package/dist/platform-state.js +229 -0
  89. package/dist/platforms/tanstack.d.ts +10 -0
  90. package/dist/platforms/tanstack.js +248 -0
  91. package/dist/registry/usage.d.ts +4 -1
  92. package/dist/registry/usage.js +59 -4
  93. package/dist/scaffold/bootstrap.d.ts +3 -3
  94. package/dist/scaffold/styling.d.ts +3 -2
  95. package/dist/transaction.js +28 -3
  96. package/dist/ui-catalog.d.ts +3 -5
  97. package/dist/ui-catalog.js +8 -24
  98. package/dist/ui-command.d.ts +3 -1
  99. package/dist/ui-command.js +74 -72
  100. package/dist/ui-project.d.ts +4 -2
  101. package/dist/ui-project.js +40 -38
  102. package/dist/util.js +40 -61
  103. package/dist/version.d.ts +1 -1
  104. package/dist/version.js +1 -1
  105. package/docs/capabilities.md +23 -89
  106. package/docs/software-factory.md +208 -9
  107. package/docs/stack-standard.md +7 -17
  108. package/docs/ui.md +9 -22
  109. package/package.json +26 -22
  110. package/assets/stack/ai-schema.ts.txt +0 -5
  111. package/assets/stack/ai.ts.txt +0 -30
  112. package/assets/stack/desktop.rs.txt +0 -21
  113. package/assets/stack/events-schema.ts.txt +0 -12
  114. package/assets/stack/events.ts.txt +0 -59
  115. package/assets/stack/mobile-auth.ts.txt +0 -25
  116. package/assets/stack/mobile-billing.tsx.txt +0 -63
  117. package/assets/stack/mobile-session.tsx.txt +0 -83
  118. package/assets/stack/native-button.tsx.txt +0 -108
  119. package/assets/stack/native-global.css.txt +0 -4
  120. package/assets/stack/native-lib-utils.ts.txt +0 -5
  121. package/assets/stack/native-metro.config.js.txt +0 -6
  122. package/assets/stack/native-nativewind-env.d.ts.txt +0 -1
  123. package/assets/stack/native-tailwind.config.js.txt +0 -73
  124. package/assets/stack/native-text.tsx.txt +0 -89
  125. package/assets/stack/purchases.ts.txt +0 -65
  126. package/assets/stack/revenuecat.ts.txt +0 -88
  127. package/assets/stack/rtc-schema.ts.txt +0 -10
  128. package/assets/stack/rtc.ts.txt +0 -122
  129. package/assets/stack/web-sign-in.tsx.txt +0 -51
  130. package/dist/capabilities.d.ts +0 -11
  131. package/dist/capabilities.js +0 -14
  132. package/dist/dependency-order.d.ts +0 -2
  133. package/dist/dependency-order.js +0 -24
  134. package/dist/platforms/lint.d.ts +0 -1
  135. package/dist/platforms/lint.js +0 -5
  136. package/dist/platforms/web.js +0 -251
  137. package/dist/project-config.d.ts +0 -3
  138. package/dist/project-config.js +0 -16
  139. package/dist/registry/context.d.ts +0 -3
  140. package/dist/registry/context.js +0 -20
  141. package/dist/registry/options.d.ts +0 -2
  142. package/dist/registry/options.js +0 -44
  143. package/dist/registry/resolve.d.ts +0 -11
  144. package/dist/registry/resolve.js +0 -46
  145. package/dist/registry/types.d.ts +0 -60
  146. package/dist/scaffold/api.d.ts +0 -2
  147. package/dist/scaffold/api.js +0 -38
  148. package/dist/scaffold/backend.d.ts +0 -2
  149. package/dist/scaffold/backend.js +0 -36
  150. package/dist/scaffold/compose.d.ts +0 -4
  151. package/dist/scaffold/compose.js +0 -30
  152. package/dist/scaffold/database.d.ts +0 -2
  153. package/dist/scaffold/database.js +0 -41
  154. package/dist/scaffold/documentation.d.ts +0 -2
  155. package/dist/scaffold/documentation.js +0 -71
  156. package/dist/scaffold/environment.d.ts +0 -4
  157. package/dist/scaffold/environment.js +0 -22
  158. package/dist/scaffold/stack-documentation.d.ts +0 -2
  159. package/dist/scaffold/stack-documentation.js +0 -6
  160. package/dist/scaffold/storage.d.ts +0 -2
  161. package/dist/scaffold/storage.js +0 -21
  162. package/dist/scaffold/workspace.d.ts +0 -3
  163. package/dist/scaffold/workspace.js +0 -131
  164. package/dist/stack-registry.d.ts +0 -35
  165. package/dist/stack-registry.js +0 -189
  166. package/dist/standard.d.ts +0 -8
  167. package/dist/standard.js +0 -94
  168. package/dist/workspace-graph.d.ts +0 -7
  169. package/dist/workspace-graph.js +0 -74
  170. package/docs/anhedral-stack.md +0 -12
  171. package/docs/assets/anhedral-stack-light.png +0 -0
  172. package/docs/assets/anhedral-stack.png +0 -0
  173. package/docs/native-ui.md +0 -47
  174. /package/dist/{registry/types.js → command-runner.d.ts} +0 -0
@@ -0,0 +1,236 @@
1
+ import { z } from "zod";
2
+ import { cliArtifactSchema, deploymentManifestSchema } from "./deployment.js";
3
+ export const CLI_CLIENT_ID = "anhedral-cli";
4
+ export const SOURCE_LIMITS = {
5
+ bytes: 16 * 1024 * 1024,
6
+ archiveBytes: 24 * 1024 * 1024,
7
+ files: 2000,
8
+ chunkBytes: 1024 * 1024,
9
+ };
10
+ export const uploadExcluded = /(?:^|\/)(?:\.artifacts|coverage|\.cache|\.DS_Store)(?:\/|$)/;
11
+ export const uploadSecret = /(?:^|\/)(?:\.aws|\.ssh|\.gnupg|\.npmrc|\.netrc|\.pypirc|credentials(?:\.[^/]*)?|[^/]*\.(?:pem|key|p12|pfx))(?:\/|$)/i;
12
+ export const sourceHashSchema = z.string().regex(/^[a-f0-9]{64}$/);
13
+ export const cliDeviceSchema = z.object({
14
+ device_code: z.string().min(20).max(191),
15
+ user_code: z.string().min(4).max(40),
16
+ verification_uri: z.url(),
17
+ verification_uri_complete: z.url(),
18
+ expires_in: z.number().int().positive().max(600),
19
+ interval: z.number().int().min(1).max(30),
20
+ });
21
+ export const cliLoginSchema = z
22
+ .object({
23
+ protocol: z.literal(1),
24
+ token: z.string().regex(/^acl_[a-f0-9]{64}$/),
25
+ expiresAt: z.iso.datetime(),
26
+ })
27
+ .strict();
28
+ export const cliLinkSchema = z
29
+ .object({
30
+ protocol: z.literal(1),
31
+ projectId: z.uuid(),
32
+ teamId: z.uuid(),
33
+ principalId: z.uuid(),
34
+ name: z.string().min(1).max(200),
35
+ })
36
+ .strict();
37
+ /** Metadata-only project management; creation never initializes or provisions source.
38
+ * Pure factories keep unused wire schemas outside the immutable build-tool artifact. */
39
+ export const cliProjectListQuerySchema = /* @__PURE__ */ (() => z
40
+ .object({
41
+ limit: z.coerce.number().int().min(1).max(100).default(50),
42
+ cursor: z.uuid().optional(),
43
+ })
44
+ .strict())();
45
+ export const cliProjectCreateInputSchema = /* @__PURE__ */ (() => z
46
+ .object({
47
+ protocol: z.literal(1),
48
+ requestId: z.uuid(),
49
+ name: z.string().trim().min(1).max(160),
50
+ summary: z.string().trim().max(2000).default(""),
51
+ })
52
+ .strict())();
53
+ export const cliProjectSchema = /* @__PURE__ */ (() => z
54
+ .object({
55
+ projectId: z.uuid(),
56
+ teamId: z.uuid(),
57
+ name: z.string().min(1).max(200),
58
+ slug: z.string().min(1).max(200),
59
+ canLink: z.boolean(),
60
+ })
61
+ .strict())();
62
+ export const cliProjectListSchema = /* @__PURE__ */ (() => z
63
+ .object({
64
+ protocol: z.literal(1),
65
+ principalId: z.uuid(),
66
+ team: z
67
+ .object({ id: z.uuid(), name: z.string().min(1).max(200) })
68
+ .strict()
69
+ .nullable(),
70
+ availableTeams: z
71
+ .array(z.object({ id: z.uuid(), name: z.string().min(1).max(200) }).strict())
72
+ .max(100),
73
+ teamsTruncated: z.boolean(),
74
+ projects: z.array(cliProjectSchema).max(100),
75
+ nextCursor: z.uuid().nullable(),
76
+ })
77
+ .strict())();
78
+ export const cliProjectCreateReceiptSchema = /* @__PURE__ */ (() => cliProjectSchema
79
+ .extend({
80
+ protocol: z.literal(1),
81
+ requestId: z.uuid(),
82
+ principalId: z.uuid(),
83
+ summary: z.string().max(2000),
84
+ initialization: z.literal("source-upload"),
85
+ })
86
+ .strict()
87
+ .refine((value) => value.projectId === value.requestId, "Project identity differs from request."))();
88
+ export const sourceUploadInputSchema = z
89
+ .object({
90
+ protocol: z.literal(1),
91
+ requestId: z.uuid(),
92
+ projectId: z.uuid(),
93
+ teamId: z.uuid(),
94
+ archiveDigest: sourceHashSchema,
95
+ archiveBytes: z.number().int().positive().max(SOURCE_LIMITS.bytes),
96
+ inventoryDigest: sourceHashSchema,
97
+ cliVersion: z.string().regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/),
98
+ chunks: z.array(sourceHashSchema).min(1).max(16),
99
+ })
100
+ .strict()
101
+ .refine((v) => v.chunks.length === Math.ceil(v.archiveBytes / SOURCE_LIMITS.chunkBytes), "Chunk count differs from archive size.");
102
+ export const sourceUploadReceiptSchema = z
103
+ .object({
104
+ protocol: z.literal(1),
105
+ id: z.uuid(),
106
+ requestId: z.uuid(),
107
+ projectId: z.uuid(),
108
+ archiveDigest: sourceHashSchema,
109
+ inventoryDigest: sourceHashSchema,
110
+ received: z.array(z.number().int().min(0).max(15)).max(16),
111
+ state: z.enum(["uploading", "sealed", "cancelled"]),
112
+ expiresAt: z.iso.datetime(),
113
+ sourceRevision: sourceHashSchema.nullable(),
114
+ })
115
+ .strict();
116
+ /** High-confidence credential material must not enter a source checkpoint. */
117
+ export function sourceContainsCredential(bytes) {
118
+ return /\bacl_[a-f0-9]{64}\b|"device_code"\s*:\s*"[A-Za-z0-9_-]{20,191}"|-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----|\bAKIA[A-Z0-9]{16}\b|\bnpm_[A-Za-z0-9]{36}\b|\bsk-proj-[A-Za-z0-9_-]{30,}|\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{24,}/.test(new TextDecoder().decode(bytes));
119
+ }
120
+ /** Planning reserves source only. It cannot grant a runtime, preview or deployment. */
121
+ export const cliPlanInputSchema = z
122
+ .object({
123
+ protocol: z.literal(1),
124
+ requestId: z.uuid(),
125
+ uploadId: z.uuid(),
126
+ manifest: deploymentManifestSchema,
127
+ })
128
+ .strict();
129
+ export const cliPlanBlockerSchema = z.enum([
130
+ "HOSTED_ADMISSION_DISABLED",
131
+ "ARTIFACT_UNREVIEWED",
132
+ "CONFIGURATION_UNVERIFIED",
133
+ "RUNTIME_UNAVAILABLE",
134
+ "ARTIFACT_MISMATCH",
135
+ "SOURCE_VERSION_MISMATCH",
136
+ "DEPENDENCY_LOCK_MISMATCH",
137
+ ]);
138
+ export const cliPlanAdmissionSchema = z
139
+ .object({
140
+ version: z.literal(1),
141
+ expectedCliArtifact: cliArtifactSchema.nullable(),
142
+ supportedCompositions: z
143
+ .array(z
144
+ .object({
145
+ dependencyLockDigest: sourceHashSchema,
146
+ capabilities: z.array(z.enum(["hono", "database-auth", "r2", "stripe"])).max(4),
147
+ })
148
+ .strict())
149
+ .max(32),
150
+ diagnostics: z
151
+ .array(z
152
+ .object({
153
+ code: cliPlanBlockerSchema,
154
+ message: z.string().min(1).max(500),
155
+ action: z.string().min(1).max(500),
156
+ })
157
+ .strict())
158
+ .max(8),
159
+ })
160
+ .strict();
161
+ export const cliPlanSchema = z
162
+ .object({
163
+ protocol: z.literal(1),
164
+ id: z.uuid(),
165
+ requestId: z.uuid(),
166
+ projectId: z.uuid(),
167
+ uploadId: z.uuid(),
168
+ digest: sourceHashSchema,
169
+ manifest: deploymentManifestSchema,
170
+ sourceRevision: sourceHashSchema,
171
+ inventoryDigest: sourceHashSchema,
172
+ lockDigest: sourceHashSchema,
173
+ routing: z
174
+ .object({
175
+ generation: z.number().int().nonnegative(),
176
+ activeReleaseId: z.uuid().nullable(),
177
+ desiredReleaseId: z.uuid().nullable(),
178
+ })
179
+ .strict(),
180
+ routingRevision: sourceHashSchema,
181
+ expectedGeneration: z.number().int().nonnegative(),
182
+ policyDigest: sourceHashSchema,
183
+ migrationDigests: z.array(sourceHashSchema).max(100),
184
+ expiresAt: z.iso.datetime(),
185
+ runtimeImage: z.string().max(256).nullable(),
186
+ configurationRevision: z.null(),
187
+ artifactVerified: z.boolean(),
188
+ hostedAdmission: z.boolean(),
189
+ identityAction: z.literal("preserve"),
190
+ blockers: z.array(cliPlanBlockerSchema).max(8),
191
+ // Optional so parsing an old immutable plan never adds signed fields.
192
+ admission: cliPlanAdmissionSchema.optional(),
193
+ })
194
+ .strict();
195
+ export const cliPrepareInputSchema = z
196
+ .object({
197
+ protocol: z.literal(1),
198
+ requestId: z.uuid(),
199
+ planId: z.uuid(),
200
+ planDigest: sourceHashSchema,
201
+ })
202
+ .strict();
203
+ export const cliPreparationSchema = z
204
+ .object({
205
+ protocol: z.literal(1),
206
+ planId: z.uuid(),
207
+ planDigest: sourceHashSchema,
208
+ candidateId: z.uuid(),
209
+ sourceRevision: sourceHashSchema,
210
+ state: z.enum(["awaiting-runtime", "building", "built", "ready", "failed"]),
211
+ buildDigest: sourceHashSchema.nullable().optional(),
212
+ error: z.string().max(300).nullable().optional(),
213
+ admission: z
214
+ .object({
215
+ policyDigest: sourceHashSchema,
216
+ image: z.string().regex(/^registry\.[a-z0-9.-]+\/[a-zA-Z0-9/_.-]+@sha256:[a-f0-9]{64}$/),
217
+ scope: z.literal("candidate-workspace"),
218
+ })
219
+ .strict()
220
+ .nullable()
221
+ .optional(),
222
+ hostedAdmission: z.boolean(),
223
+ identityAction: z.literal("preserve"),
224
+ })
225
+ .strict();
226
+ /** Canonical JSON for immutable plan and request digests across SQL JSONB and clients. */
227
+ export function canonicalCliJson(value) {
228
+ if (Array.isArray(value))
229
+ return `[${value.map(canonicalCliJson).join(",")}]`;
230
+ if (value !== null && typeof value === "object")
231
+ return `{${Object.entries(value)
232
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
233
+ .map(([key, v]) => `${JSON.stringify(key)}:${canonicalCliJson(v)}`)
234
+ .join(",")}}`;
235
+ return JSON.stringify(value);
236
+ }
@@ -0,0 +1,233 @@
1
+ import { z } from "zod";
2
+ /** Portable transport contract. No database, framework or provider imports. */
3
+ export declare const deploymentContractVersion = 1;
4
+ export declare const deploymentDigestSchema: z.ZodString;
5
+ export declare const applicationIdentitySchema: z.ZodEnum<{
6
+ none: "none";
7
+ "better-auth-d1-v1": "better-auth-d1-v1";
8
+ }>;
9
+ export declare const deploymentCapabilitySchema: z.ZodEnum<{
10
+ hono: "hono";
11
+ "database-auth": "database-auth";
12
+ r2: "r2";
13
+ stripe: "stripe";
14
+ }>;
15
+ export declare const cliArtifactSchema: z.ZodObject<{
16
+ version: z.ZodString;
17
+ sourceRevision: z.ZodString;
18
+ packageIntegrity: z.ZodString;
19
+ }, z.core.$strict>;
20
+ export declare const deploymentIntentSchema: z.ZodObject<{
21
+ contractVersion: z.ZodLiteral<1>;
22
+ runtimeProfile: z.ZodLiteral<"anhedral-stack">;
23
+ environment: z.ZodEnum<{
24
+ production: "production";
25
+ preview: "preview";
26
+ }>;
27
+ visibility: z.ZodEnum<{
28
+ protected: "protected";
29
+ public: "public";
30
+ }>;
31
+ }, z.core.$strict>;
32
+ /** Source provenance only. Null versions preserve unknown legacy origins honestly. */
33
+ export declare const sourceCompositionSchema: z.ZodObject<{
34
+ contractVersion: z.ZodLiteral<2>;
35
+ foundation: z.ZodLiteral<"tanstack-start">;
36
+ generatorVersion: z.ZodNullable<z.ZodString>;
37
+ identity: z.ZodEnum<{
38
+ none: "none";
39
+ "better-auth-d1-v1": "better-auth-d1-v1";
40
+ }>;
41
+ capabilities: z.ZodRecord<z.ZodEnum<{
42
+ hono: "hono";
43
+ "database-auth": "database-auth";
44
+ r2: "r2";
45
+ stripe: "stripe";
46
+ }> & z.core.$partial, z.ZodNullable<z.ZodString>>;
47
+ }, z.core.$strict>;
48
+ export declare const deploymentManifestSchema: z.ZodObject<{
49
+ contractVersion: z.ZodLiteral<1>;
50
+ foundation: z.ZodLiteral<"tanstack-start">;
51
+ capabilities: z.ZodArray<z.ZodEnum<{
52
+ hono: "hono";
53
+ "database-auth": "database-auth";
54
+ r2: "r2";
55
+ stripe: "stripe";
56
+ }>>;
57
+ identity: z.ZodEnum<{
58
+ none: "none";
59
+ "better-auth-d1-v1": "better-auth-d1-v1";
60
+ }>;
61
+ cliArtifact: z.ZodObject<{
62
+ version: z.ZodString;
63
+ sourceRevision: z.ZodString;
64
+ packageIntegrity: z.ZodString;
65
+ }, z.core.$strict>;
66
+ intent: z.ZodObject<{
67
+ contractVersion: z.ZodLiteral<1>;
68
+ runtimeProfile: z.ZodLiteral<"anhedral-stack">;
69
+ environment: z.ZodEnum<{
70
+ production: "production";
71
+ preview: "preview";
72
+ }>;
73
+ visibility: z.ZodEnum<{
74
+ protected: "protected";
75
+ public: "public";
76
+ }>;
77
+ }, z.core.$strict>;
78
+ }, z.core.$strict>;
79
+ export declare const deploymentSourceSchema: z.ZodObject<{
80
+ inventoryVersion: z.ZodLiteral<2>;
81
+ inventoryProfile: z.ZodString;
82
+ sourceDigest: z.ZodString;
83
+ lockfileDigest: z.ZodString;
84
+ manifestDigest: z.ZodString;
85
+ }, z.core.$strict>;
86
+ export declare const deploymentPlanSchema: z.ZodObject<{
87
+ contractVersion: z.ZodLiteral<1>;
88
+ requestId: z.ZodUUID;
89
+ projectId: z.ZodUUID;
90
+ manifest: z.ZodObject<{
91
+ contractVersion: z.ZodLiteral<1>;
92
+ foundation: z.ZodLiteral<"tanstack-start">;
93
+ capabilities: z.ZodArray<z.ZodEnum<{
94
+ hono: "hono";
95
+ "database-auth": "database-auth";
96
+ r2: "r2";
97
+ stripe: "stripe";
98
+ }>>;
99
+ identity: z.ZodEnum<{
100
+ none: "none";
101
+ "better-auth-d1-v1": "better-auth-d1-v1";
102
+ }>;
103
+ cliArtifact: z.ZodObject<{
104
+ version: z.ZodString;
105
+ sourceRevision: z.ZodString;
106
+ packageIntegrity: z.ZodString;
107
+ }, z.core.$strict>;
108
+ intent: z.ZodObject<{
109
+ contractVersion: z.ZodLiteral<1>;
110
+ runtimeProfile: z.ZodLiteral<"anhedral-stack">;
111
+ environment: z.ZodEnum<{
112
+ production: "production";
113
+ preview: "preview";
114
+ }>;
115
+ visibility: z.ZodEnum<{
116
+ protected: "protected";
117
+ public: "public";
118
+ }>;
119
+ }, z.core.$strict>;
120
+ }, z.core.$strict>;
121
+ source: z.ZodObject<{
122
+ inventoryVersion: z.ZodLiteral<2>;
123
+ inventoryProfile: z.ZodString;
124
+ sourceDigest: z.ZodString;
125
+ lockfileDigest: z.ZodString;
126
+ manifestDigest: z.ZodString;
127
+ }, z.core.$strict>;
128
+ policyDigest: z.ZodString;
129
+ runtimeImage: z.ZodString;
130
+ configurationRevision: z.ZodString;
131
+ expectedGeneration: z.ZodNumber;
132
+ migrationDigests: z.ZodArray<z.ZodString>;
133
+ requiredAuthority: z.ZodEnum<{
134
+ preview: "preview";
135
+ "production-approval": "production-approval";
136
+ }>;
137
+ }, z.core.$strict>;
138
+ export declare const deploymentErrorSchema: z.ZodObject<{
139
+ code: z.ZodEnum<{
140
+ INVALID_MANIFEST: "INVALID_MANIFEST";
141
+ UNSUPPORTED_PROFILE: "UNSUPPORTED_PROFILE";
142
+ UNREVIEWED_ARTIFACT: "UNREVIEWED_ARTIFACT";
143
+ IDENTITY_ADAPTER_REQUIRED: "IDENTITY_ADAPTER_REQUIRED";
144
+ UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
145
+ STALE_PLAN: "STALE_PLAN";
146
+ AUTHORITY_REQUIRED: "AUTHORITY_REQUIRED";
147
+ OPERATION_PENDING: "OPERATION_PENDING";
148
+ DEPLOYMENT_FAILED: "DEPLOYMENT_FAILED";
149
+ }>;
150
+ message: z.ZodString;
151
+ recovery: z.ZodString;
152
+ stateChanged: z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"unknown">]>;
153
+ operationId: z.ZodNullable<z.ZodUUID>;
154
+ }, z.core.$strict>;
155
+ export declare const deploymentEventSchema: z.ZodObject<{
156
+ sequence: z.ZodNumber;
157
+ state: z.ZodEnum<{
158
+ queued: "queued";
159
+ preparing: "preparing";
160
+ ready: "ready";
161
+ failed: "failed";
162
+ uploading: "uploading";
163
+ building: "building";
164
+ verifying: "verifying";
165
+ "awaiting-approval": "awaiting-approval";
166
+ cancelled: "cancelled";
167
+ }>;
168
+ occurredAt: z.ZodISODateTime;
169
+ contractVersion: z.ZodLiteral<1>;
170
+ operationId: z.ZodUUID;
171
+ requestId: z.ZodUUID;
172
+ }, z.core.$strict>;
173
+ export declare const deploymentResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
174
+ status: z.ZodLiteral<"pending">;
175
+ state: z.ZodEnum<{
176
+ queued: "queued";
177
+ preparing: "preparing";
178
+ uploading: "uploading";
179
+ building: "building";
180
+ verifying: "verifying";
181
+ "awaiting-approval": "awaiting-approval";
182
+ }>;
183
+ contractVersion: z.ZodLiteral<1>;
184
+ operationId: z.ZodUUID;
185
+ requestId: z.ZodUUID;
186
+ }, z.core.$strict>, z.ZodObject<{
187
+ status: z.ZodLiteral<"ready">;
188
+ candidateId: z.ZodUUID;
189
+ sourceDigest: z.ZodString;
190
+ artifactDigest: z.ZodString;
191
+ configurationRevision: z.ZodString;
192
+ url: z.ZodURL;
193
+ contractVersion: z.ZodLiteral<1>;
194
+ operationId: z.ZodUUID;
195
+ requestId: z.ZodUUID;
196
+ }, z.core.$strict>, z.ZodObject<{
197
+ status: z.ZodLiteral<"failed">;
198
+ error: z.ZodObject<{
199
+ code: z.ZodEnum<{
200
+ INVALID_MANIFEST: "INVALID_MANIFEST";
201
+ UNSUPPORTED_PROFILE: "UNSUPPORTED_PROFILE";
202
+ UNREVIEWED_ARTIFACT: "UNREVIEWED_ARTIFACT";
203
+ IDENTITY_ADAPTER_REQUIRED: "IDENTITY_ADAPTER_REQUIRED";
204
+ UNSUPPORTED_CAPABILITY: "UNSUPPORTED_CAPABILITY";
205
+ STALE_PLAN: "STALE_PLAN";
206
+ AUTHORITY_REQUIRED: "AUTHORITY_REQUIRED";
207
+ OPERATION_PENDING: "OPERATION_PENDING";
208
+ DEPLOYMENT_FAILED: "DEPLOYMENT_FAILED";
209
+ }>;
210
+ message: z.ZodString;
211
+ recovery: z.ZodString;
212
+ stateChanged: z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<"unknown">]>;
213
+ operationId: z.ZodNullable<z.ZodUUID>;
214
+ }, z.core.$strict>;
215
+ contractVersion: z.ZodLiteral<1>;
216
+ operationId: z.ZodUUID;
217
+ requestId: z.ZodUUID;
218
+ }, z.core.$strict>, z.ZodObject<{
219
+ status: z.ZodLiteral<"cancelled">;
220
+ resourcesRetained: z.ZodBoolean;
221
+ contractVersion: z.ZodLiteral<1>;
222
+ operationId: z.ZodUUID;
223
+ requestId: z.ZodUUID;
224
+ }, z.core.$strict>], "status">;
225
+ export type DeploymentManifest = z.infer<typeof deploymentManifestSchema>;
226
+ export type DeploymentPlan = z.infer<typeof deploymentPlanSchema>;
227
+ export type DeploymentSource = z.infer<typeof deploymentSourceSchema>;
228
+ export type DeploymentIntent = z.infer<typeof deploymentIntentSchema>;
229
+ export type DeploymentEvent = z.infer<typeof deploymentEventSchema>;
230
+ export type DeploymentResult = z.infer<typeof deploymentResultSchema>;
231
+ export type DeploymentError = z.infer<typeof deploymentErrorSchema>;
232
+ export type SourceComposition = z.infer<typeof sourceCompositionSchema>;
233
+ export type CliArtifact = z.infer<typeof cliArtifactSchema>;
@@ -0,0 +1,198 @@
1
+ import { z } from "zod";
2
+ /** Portable transport contract. No database, framework or provider imports. */
3
+ export const deploymentContractVersion = 1;
4
+ export const deploymentDigestSchema = z.string().regex(/^[a-f0-9]{64}$/);
5
+ const revisionSchema = z.string().regex(/^[a-f0-9]{40}$/);
6
+ const versionSchema = z.string().regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
7
+ export const applicationIdentitySchema = z.enum(["none", "better-auth-d1-v1"]);
8
+ export const deploymentCapabilitySchema = z.enum(["hono", "database-auth", "r2", "stripe"]);
9
+ const capabilitiesSchema = z
10
+ .array(deploymentCapabilitySchema)
11
+ .max(4)
12
+ .refine((items) => new Set(items).size === items.length, "Duplicate capabilities.");
13
+ export const cliArtifactSchema = z
14
+ .object({
15
+ version: versionSchema,
16
+ sourceRevision: revisionSchema,
17
+ packageIntegrity: z.string().regex(/^sha512-[A-Za-z0-9+/]{86}==$/),
18
+ })
19
+ .strict();
20
+ export const deploymentIntentSchema = z
21
+ .object({
22
+ contractVersion: z.literal(1),
23
+ runtimeProfile: z.literal("anhedral-stack"),
24
+ environment: z.enum(["preview", "production"]),
25
+ visibility: z.enum(["protected", "public"]),
26
+ })
27
+ .strict();
28
+ /** Source provenance only. Null versions preserve unknown legacy origins honestly. */
29
+ export const sourceCompositionSchema = z
30
+ .object({
31
+ contractVersion: z.literal(2),
32
+ foundation: z.literal("tanstack-start"),
33
+ generatorVersion: versionSchema.nullable(),
34
+ identity: applicationIdentitySchema,
35
+ capabilities: z.partialRecord(deploymentCapabilitySchema, versionSchema.nullable()),
36
+ })
37
+ .strict();
38
+ export const deploymentManifestSchema = z
39
+ .object({
40
+ contractVersion: z.literal(1),
41
+ foundation: z.literal("tanstack-start"),
42
+ capabilities: capabilitiesSchema,
43
+ identity: applicationIdentitySchema,
44
+ cliArtifact: cliArtifactSchema,
45
+ intent: deploymentIntentSchema,
46
+ })
47
+ .strict()
48
+ .superRefine((value, ctx) => {
49
+ const selected = new Set(value.capabilities);
50
+ const tanstack = value.foundation === "tanstack-start";
51
+ if (tanstack !== (value.intent.runtimeProfile === "anhedral-stack"))
52
+ ctx.addIssue({
53
+ code: "custom",
54
+ path: ["intent", "runtimeProfile"],
55
+ message: "Anhedral Stack source requires the anhedral-stack runtime profile.",
56
+ });
57
+ if (tanstack) {
58
+ for (const id of value.capabilities)
59
+ if (!["hono", "database-auth", "r2", "stripe"].includes(id))
60
+ ctx.addIssue({
61
+ code: "custom",
62
+ path: ["capabilities"],
63
+ message: `${id} is outside the Anhedral Stack hosting contract.`,
64
+ });
65
+ if (selected.has("hono") !== selected.has("database-auth"))
66
+ ctx.addIssue({
67
+ code: "custom",
68
+ path: ["capabilities"],
69
+ message: "Anhedral Stack hosting requires Hono and database-auth together.",
70
+ });
71
+ if (value.identity !== (selected.has("database-auth") ? "better-auth-d1-v1" : "none"))
72
+ ctx.addIssue({
73
+ code: "custom",
74
+ path: ["identity"],
75
+ message: "Anhedral Stack hosting preserves standalone Better Auth/D1 identity.",
76
+ });
77
+ }
78
+ const prerequisites = {
79
+ "database-auth": ["hono"],
80
+ r2: ["database-auth"],
81
+ stripe: ["database-auth"],
82
+ };
83
+ for (const id of value.capabilities)
84
+ for (const parent of prerequisites[id] ?? [])
85
+ if (!selected.has(parent))
86
+ ctx.addIssue({
87
+ code: "custom",
88
+ path: ["capabilities"],
89
+ message: `${id} requires ${parent}.`,
90
+ });
91
+ if (selected.has("database-auth") !== (value.identity !== "none"))
92
+ ctx.addIssue({
93
+ code: "custom",
94
+ path: ["identity"],
95
+ message: "Identity must match database-auth source.",
96
+ });
97
+ });
98
+ export const deploymentSourceSchema = z
99
+ .object({
100
+ inventoryVersion: z.literal(2),
101
+ inventoryProfile: z.string().min(1).max(100),
102
+ sourceDigest: deploymentDigestSchema,
103
+ lockfileDigest: deploymentDigestSchema,
104
+ manifestDigest: deploymentDigestSchema,
105
+ })
106
+ .strict();
107
+ const runtimeImageSchema = z
108
+ .string()
109
+ .regex(/^registry\.[a-z0-9.-]+\/[a-zA-Z0-9/_.-]+@sha256:[a-f0-9]{64}$/);
110
+ export const deploymentPlanSchema = z
111
+ .object({
112
+ contractVersion: z.literal(1),
113
+ requestId: z.uuid(),
114
+ projectId: z.uuid(),
115
+ manifest: deploymentManifestSchema,
116
+ source: deploymentSourceSchema,
117
+ policyDigest: deploymentDigestSchema,
118
+ runtimeImage: runtimeImageSchema,
119
+ configurationRevision: deploymentDigestSchema,
120
+ expectedGeneration: z.number().int().nonnegative(),
121
+ migrationDigests: z.array(deploymentDigestSchema).max(100),
122
+ requiredAuthority: z.enum(["preview", "production-approval"]),
123
+ })
124
+ .strict()
125
+ .refine((plan) => plan.requiredAuthority ===
126
+ (plan.manifest.intent.environment === "production" ? "production-approval" : "preview"), "Production requires exact-candidate approval.");
127
+ export const deploymentErrorSchema = z
128
+ .object({
129
+ code: z.enum([
130
+ "INVALID_MANIFEST",
131
+ "UNSUPPORTED_PROFILE",
132
+ "UNREVIEWED_ARTIFACT",
133
+ "IDENTITY_ADAPTER_REQUIRED",
134
+ "UNSUPPORTED_CAPABILITY",
135
+ "STALE_PLAN",
136
+ "AUTHORITY_REQUIRED",
137
+ "OPERATION_PENDING",
138
+ "DEPLOYMENT_FAILED",
139
+ ]),
140
+ message: z.string().min(1).max(2000),
141
+ recovery: z.string().min(1).max(2000),
142
+ stateChanged: z.union([z.boolean(), z.literal("unknown")]),
143
+ operationId: z.uuid().nullable(),
144
+ })
145
+ .strict();
146
+ const operationStateSchema = z.enum([
147
+ "queued",
148
+ "uploading",
149
+ "building",
150
+ "preparing",
151
+ "verifying",
152
+ "awaiting-approval",
153
+ "ready",
154
+ "failed",
155
+ "cancelled",
156
+ ]);
157
+ const operationFields = {
158
+ contractVersion: z.literal(1),
159
+ operationId: z.uuid(),
160
+ requestId: z.uuid(),
161
+ };
162
+ export const deploymentEventSchema = z
163
+ .object({
164
+ ...operationFields,
165
+ sequence: z.number().int().nonnegative(),
166
+ state: operationStateSchema,
167
+ occurredAt: z.iso.datetime(),
168
+ })
169
+ .strict();
170
+ export const deploymentResultSchema = z.discriminatedUnion("status", [
171
+ z
172
+ .object({
173
+ ...operationFields,
174
+ status: z.literal("pending"),
175
+ state: operationStateSchema.exclude(["ready", "failed", "cancelled"]),
176
+ })
177
+ .strict(),
178
+ z
179
+ .object({
180
+ ...operationFields,
181
+ status: z.literal("ready"),
182
+ candidateId: z.uuid(),
183
+ sourceDigest: deploymentDigestSchema,
184
+ artifactDigest: deploymentDigestSchema,
185
+ configurationRevision: deploymentDigestSchema,
186
+ url: z.url().refine((value) => {
187
+ const url = new URL(value);
188
+ return url.protocol === "https:" && url.origin === value && !url.username && !url.password;
189
+ }),
190
+ })
191
+ .strict(),
192
+ z
193
+ .object({ ...operationFields, status: z.literal("failed"), error: deploymentErrorSchema })
194
+ .strict(),
195
+ z
196
+ .object({ ...operationFields, status: z.literal("cancelled"), resourcesRetained: z.boolean() })
197
+ .strict(),
198
+ ]);
@@ -0,0 +1,7 @@
1
+ /** Literal dotenv parsing only. Never evaluate a shell, interpolate variables,
2
+ * or include input values in errors. The same parser serves browser and CLI. */
3
+ export declare function parseEnvironmentFile(input: string): {
4
+ name: string;
5
+ value: string;
6
+ }[];
7
+ export declare function inferredEnvironmentKind(name: string): "config" | "secret";