anhedral 0.17.0 → 0.18.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 (105) 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 +11 -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/request-context.ts.txt +3 -0
  14. package/assets/launch/root.tsx.txt +27 -0
  15. package/assets/launch/router.tsx.txt +21 -0
  16. package/assets/launch/server.ts.txt +13 -0
  17. package/assets/launch/sign-in.tsx.txt +53 -0
  18. package/assets/launch/styles.css.txt +19 -0
  19. package/assets/security/credential-patterns.d.mts +3 -0
  20. package/assets/security/credential-patterns.mjs +59 -0
  21. package/assets/stack/api-index.ts.txt +6 -1
  22. package/assets/stack/event-retention.sql.txt +10 -0
  23. package/assets/stack/stripe.ts.txt +30 -13
  24. package/dist/bin.js +55 -36
  25. package/dist/capabilities.d.ts +1 -1
  26. package/dist/capability-catalog.d.ts +44 -11
  27. package/dist/capability-catalog.js +96 -11
  28. package/dist/capability-command.d.ts +2 -2
  29. package/dist/capability-command.js +178 -27
  30. package/dist/capability-editor.js +6 -5
  31. package/dist/capability-recipes.js +54 -6
  32. package/dist/cli-arguments.d.ts +2 -0
  33. package/dist/cli-arguments.js +101 -50
  34. package/dist/cli-commands.d.ts +1 -1
  35. package/dist/cli-commands.js +30 -6
  36. package/dist/cli-errors.d.ts +18 -0
  37. package/dist/cli-errors.js +63 -0
  38. package/dist/cli-output.d.ts +22 -0
  39. package/dist/cli-output.js +42 -7
  40. package/dist/command-runner.d.ts +1 -0
  41. package/dist/command-runner.js +88 -0
  42. package/dist/command-schema.d.ts +16 -0
  43. package/dist/command-schema.js +390 -21
  44. package/dist/completion.d.ts +2 -0
  45. package/dist/completion.js +201 -0
  46. package/dist/composition.d.ts +35 -0
  47. package/dist/composition.js +28 -0
  48. package/dist/contracts/cli-transport.d.ts +217 -0
  49. package/dist/contracts/cli-transport.js +167 -0
  50. package/dist/contracts/deployment.d.ts +282 -0
  51. package/dist/contracts/deployment.js +234 -0
  52. package/dist/contracts/environment-file.d.ts +7 -0
  53. package/dist/contracts/environment-file.js +112 -0
  54. package/dist/contracts/environment-transport.d.ts +79 -0
  55. package/dist/contracts/environment-transport.js +110 -0
  56. package/dist/contracts/runtime-logs-transport.d.ts +127 -0
  57. package/dist/contracts/runtime-logs-transport.js +50 -0
  58. package/dist/contracts/source-bundle.d.ts +11 -0
  59. package/dist/contracts/source-bundle.js +197 -0
  60. package/dist/contracts/source-profile.d.ts +4 -0
  61. package/dist/contracts/source-profile.js +5 -0
  62. package/dist/contracts/staging-transport.d.ts +79 -0
  63. package/dist/contracts/staging-transport.js +43 -0
  64. package/dist/dependencies.d.ts +10 -1
  65. package/dist/dependencies.js +18 -1
  66. package/dist/index.d.ts +6 -0
  67. package/dist/index.js +4 -0
  68. package/dist/launch.d.ts +21 -0
  69. package/dist/launch.js +250 -0
  70. package/dist/platform-command.d.ts +9 -0
  71. package/dist/platform-command.js +584 -0
  72. package/dist/platform-environment.d.ts +18 -0
  73. package/dist/platform-environment.js +257 -0
  74. package/dist/platform-operations.d.ts +26 -0
  75. package/dist/platform-operations.js +155 -0
  76. package/dist/platform-source.d.ts +8 -0
  77. package/dist/platform-source.js +111 -0
  78. package/dist/platform-state.d.ts +13 -0
  79. package/dist/platform-state.js +207 -0
  80. package/dist/platforms/tanstack.d.ts +8 -0
  81. package/dist/platforms/tanstack.js +155 -0
  82. package/dist/registry/options.js +34 -31
  83. package/dist/registry/usage.d.ts +4 -1
  84. package/dist/registry/usage.js +58 -4
  85. package/dist/scaffold/styling.d.ts +1 -1
  86. package/dist/scaffold/workspace.js +11 -1
  87. package/dist/stack-registry.d.ts +2 -2
  88. package/dist/standard.js +21 -6
  89. package/dist/transaction.js +28 -3
  90. package/dist/ui-command.d.ts +4 -2
  91. package/dist/ui-command.js +79 -38
  92. package/dist/ui-project.d.ts +2 -0
  93. package/dist/ui-project.js +38 -8
  94. package/dist/util.js +40 -61
  95. package/dist/version.d.ts +1 -1
  96. package/dist/version.js +1 -1
  97. package/docs/capabilities.md +22 -88
  98. package/docs/software-factory.md +169 -9
  99. package/docs/stack-standard.md +7 -17
  100. package/docs/ui.md +9 -22
  101. package/package.json +27 -20
  102. package/docs/anhedral-stack.md +0 -12
  103. package/docs/assets/anhedral-stack-light.png +0 -0
  104. package/docs/assets/anhedral-stack.png +0 -0
  105. package/docs/native-ui.md +0 -47
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ export declare const projectEnvironmentSchema: z.ZodEnum<{
3
+ staging: "staging";
4
+ production: "production";
5
+ }>;
6
+ export declare const environmentNameSchema: z.ZodString;
7
+ export declare const environmentWriteSchema: z.ZodObject<{
8
+ name: z.ZodString;
9
+ environment: z.ZodEnum<{
10
+ staging: "staging";
11
+ production: "production";
12
+ }>;
13
+ kind: z.ZodEnum<{
14
+ secret: "secret";
15
+ config: "config";
16
+ }>;
17
+ value: z.ZodString;
18
+ note: z.ZodDefault<z.ZodString>;
19
+ expectedVersion: z.ZodNumber;
20
+ }, z.core.$strict>;
21
+ export declare const environmentDeleteSchema: z.ZodObject<{
22
+ name: z.ZodString;
23
+ environment: z.ZodEnum<{
24
+ staging: "staging";
25
+ production: "production";
26
+ }>;
27
+ expectedVersion: z.ZodNumber;
28
+ }, z.core.$strict>;
29
+ export declare const environmentImportSchema: z.ZodObject<{
30
+ requestId: z.ZodUUID;
31
+ environment: z.ZodEnum<{
32
+ staging: "staging";
33
+ production: "production";
34
+ }>;
35
+ variables: z.ZodArray<z.ZodObject<{
36
+ name: z.ZodString;
37
+ kind: z.ZodEnum<{
38
+ secret: "secret";
39
+ config: "config";
40
+ }>;
41
+ value: z.ZodString;
42
+ note: z.ZodDefault<z.ZodString>;
43
+ expectedVersion: z.ZodNumber;
44
+ }, z.core.$strict>>;
45
+ }, z.core.$strict>;
46
+ export declare const environmentImportReceiptSchema: z.ZodObject<{
47
+ requestId: z.ZodUUID;
48
+ imported: z.ZodArray<z.ZodObject<{
49
+ name: z.ZodString;
50
+ kind: z.ZodEnum<{
51
+ secret: "secret";
52
+ config: "config";
53
+ }>;
54
+ environment: z.ZodEnum<{
55
+ staging: "staging";
56
+ production: "production";
57
+ }>;
58
+ version: z.ZodNumber;
59
+ }, z.core.$strict>>;
60
+ }, z.core.$strict>;
61
+ export type EnvironmentImport = z.infer<typeof environmentImportSchema>;
62
+ export type EnvironmentWrite = z.infer<typeof environmentWriteSchema>;
63
+ export type EnvironmentDelete = z.infer<typeof environmentDeleteSchema>;
64
+ export declare const environmentMetadataSchema: z.ZodObject<{
65
+ variables: z.ZodArray<z.ZodObject<{
66
+ name: z.ZodString;
67
+ environment: z.ZodEnum<{
68
+ staging: "staging";
69
+ production: "production";
70
+ }>;
71
+ kind: z.ZodEnum<{
72
+ secret: "secret";
73
+ config: "config";
74
+ }>;
75
+ version: z.ZodNumber;
76
+ note: z.ZodString;
77
+ }, z.core.$strict>>;
78
+ }, z.core.$strict>;
79
+ export type EnvironmentMetadata = z.infer<typeof environmentMetadataSchema>;
@@ -0,0 +1,110 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from "zod";
3
+ export const projectEnvironmentSchema = z.enum(["staging", "production"]);
4
+ export const environmentNameSchema = z.string().regex(/^[A-Z][A-Z0-9_]{0,127}$/);
5
+ const versionSchema = z.number().int().min(0).max(2147483646);
6
+ const reserved = /^(ANHEDRAL_|CLOUDFLARE_|CF_|NODE_|npm_|PNPM_|PATH$|HOME$|PORT$|DATABASE_URL$|DB$|FILES$|ASSETS$|AUTH_SECRET$|BETTER_AUTH_|PUBLIC_APP_URL$|WORKER_SELF_REFERENCE$|RESOURCES$)/i;
7
+ export const environmentWriteSchema = z
8
+ .object({
9
+ name: environmentNameSchema,
10
+ environment: projectEnvironmentSchema,
11
+ kind: z.enum(["secret", "config"]),
12
+ value: z.string().min(1).max(16384),
13
+ note: z.string().max(500).default(""),
14
+ expectedVersion: versionSchema,
15
+ })
16
+ .strict()
17
+ .superRefine((input, ctx) => {
18
+ if (reserved.test(input.name))
19
+ ctx.addIssue({
20
+ code: "custom",
21
+ path: ["name"],
22
+ message: "This name is reserved for managed runtime configuration.",
23
+ });
24
+ if (input.kind === "secret" && /^(NEXT_PUBLIC_|VITE_|PUBLIC_|EXPO_PUBLIC_)/.test(input.name))
25
+ ctx.addIssue({
26
+ code: "custom",
27
+ path: ["name"],
28
+ message: "Public variables cannot contain secrets.",
29
+ });
30
+ });
31
+ export const environmentDeleteSchema = z
32
+ .object({
33
+ name: environmentNameSchema,
34
+ environment: projectEnvironmentSchema,
35
+ expectedVersion: versionSchema.refine((value) => value > 0),
36
+ })
37
+ .strict();
38
+ export const environmentImportSchema = z
39
+ .object({
40
+ requestId: z.uuid(),
41
+ environment: projectEnvironmentSchema,
42
+ variables: z
43
+ .array(z
44
+ .object({
45
+ name: environmentNameSchema,
46
+ kind: z.enum(["secret", "config"]),
47
+ value: z.string().min(1).max(16384),
48
+ note: z.string().max(500).default(""),
49
+ expectedVersion: versionSchema,
50
+ })
51
+ .strict())
52
+ .min(1)
53
+ .max(128),
54
+ })
55
+ .strict()
56
+ .superRefine((input, ctx) => {
57
+ const names = new Set();
58
+ input.variables.forEach((variable, index) => {
59
+ if (names.has(variable.name))
60
+ ctx.addIssue({
61
+ code: "custom",
62
+ path: ["variables", index, "name"],
63
+ message: "Variable names must be unique.",
64
+ });
65
+ names.add(variable.name);
66
+ const parsed = environmentWriteSchema.safeParse({
67
+ ...variable,
68
+ environment: input.environment,
69
+ });
70
+ if (!parsed.success)
71
+ for (const issue of parsed.error.issues)
72
+ ctx.addIssue({
73
+ code: "custom",
74
+ path: ["variables", index, ...issue.path],
75
+ message: issue.message,
76
+ });
77
+ });
78
+ if (new TextEncoder().encode(JSON.stringify(input)).length > 65536)
79
+ ctx.addIssue({ code: "custom", message: "Imports support at most 64 KiB." });
80
+ });
81
+ export const environmentImportReceiptSchema = z
82
+ .object({
83
+ requestId: z.uuid(),
84
+ imported: z
85
+ .array(z
86
+ .object({
87
+ name: environmentNameSchema,
88
+ kind: z.enum(["secret", "config"]),
89
+ environment: projectEnvironmentSchema,
90
+ version: z.number().int().positive(),
91
+ })
92
+ .strict())
93
+ .max(128),
94
+ })
95
+ .strict();
96
+ export const environmentMetadataSchema = z
97
+ .object({
98
+ variables: z
99
+ .array(z
100
+ .object({
101
+ name: environmentNameSchema,
102
+ environment: projectEnvironmentSchema,
103
+ kind: z.enum(["secret", "config"]),
104
+ version: z.number().int().positive(),
105
+ note: z.string().max(500),
106
+ })
107
+ .strict())
108
+ .max(512),
109
+ })
110
+ .strict();
@@ -0,0 +1,127 @@
1
+ import { z } from "zod";
2
+ export declare const runtimeLogEnvironmentSchema: z.ZodEnum<{
3
+ staging: "staging";
4
+ production: "production";
5
+ }>;
6
+ export declare const runtimeLogLevelSchema: z.ZodEnum<{
7
+ debug: "debug";
8
+ info: "info";
9
+ warn: "warn";
10
+ error: "error";
11
+ }>;
12
+ export declare const runtimeLogSourceSchema: z.ZodEnum<{
13
+ request: "request";
14
+ console: "console";
15
+ exception: "exception";
16
+ }>;
17
+ export declare const runtimeLogQuerySchema: z.ZodObject<{
18
+ environment: z.ZodDefault<z.ZodEnum<{
19
+ staging: "staging";
20
+ production: "production";
21
+ }>>;
22
+ deploymentId: z.ZodOptional<z.ZodUUID>;
23
+ level: z.ZodOptional<z.ZodEnum<{
24
+ debug: "debug";
25
+ info: "info";
26
+ warn: "warn";
27
+ error: "error";
28
+ }>>;
29
+ source: z.ZodOptional<z.ZodEnum<{
30
+ request: "request";
31
+ console: "console";
32
+ exception: "exception";
33
+ }>>;
34
+ range: z.ZodDefault<z.ZodEnum<{
35
+ "1h": "1h";
36
+ "24h": "24h";
37
+ "7d": "7d";
38
+ }>>;
39
+ search: z.ZodDefault<z.ZodString>;
40
+ cursor: z.ZodOptional<z.ZodString>;
41
+ }, z.core.$strict>;
42
+ export declare const runtimeLogEntrySchema: z.ZodObject<{
43
+ id: z.ZodUUID;
44
+ requestId: z.ZodUUID;
45
+ occurredAt: z.ZodString;
46
+ deploymentId: z.ZodUUID;
47
+ artifactId: z.ZodUUID;
48
+ environment: z.ZodEnum<{
49
+ staging: "staging";
50
+ production: "production";
51
+ }>;
52
+ component: z.ZodEnum<{
53
+ api: "api";
54
+ web: "web";
55
+ }>;
56
+ kind: z.ZodEnum<{
57
+ request: "request";
58
+ console: "console";
59
+ exception: "exception";
60
+ }>;
61
+ level: z.ZodEnum<{
62
+ debug: "debug";
63
+ info: "info";
64
+ warn: "warn";
65
+ error: "error";
66
+ }>;
67
+ message: z.ZodString;
68
+ method: z.ZodNullable<z.ZodString>;
69
+ status: z.ZodNullable<z.ZodNumber>;
70
+ outcome: z.ZodNullable<z.ZodString>;
71
+ durationMs: z.ZodNullable<z.ZodNumber>;
72
+ truncated: z.ZodBoolean;
73
+ }, z.core.$strict>;
74
+ export declare const runtimeLogPageSchema: z.ZodObject<{
75
+ state: z.ZodEnum<{
76
+ ready: "ready";
77
+ disabled: "disabled";
78
+ unavailable: "unavailable";
79
+ }>;
80
+ reason: z.ZodNullable<z.ZodString>;
81
+ environment: z.ZodEnum<{
82
+ staging: "staging";
83
+ production: "production";
84
+ }>;
85
+ coverage: z.ZodLiteral<"dynamic-workers">;
86
+ retentionDays: z.ZodLiteral<7>;
87
+ from: z.ZodString;
88
+ to: z.ZodString;
89
+ entries: z.ZodArray<z.ZodObject<{
90
+ id: z.ZodUUID;
91
+ requestId: z.ZodUUID;
92
+ occurredAt: z.ZodString;
93
+ deploymentId: z.ZodUUID;
94
+ artifactId: z.ZodUUID;
95
+ environment: z.ZodEnum<{
96
+ staging: "staging";
97
+ production: "production";
98
+ }>;
99
+ component: z.ZodEnum<{
100
+ api: "api";
101
+ web: "web";
102
+ }>;
103
+ kind: z.ZodEnum<{
104
+ request: "request";
105
+ console: "console";
106
+ exception: "exception";
107
+ }>;
108
+ level: z.ZodEnum<{
109
+ debug: "debug";
110
+ info: "info";
111
+ warn: "warn";
112
+ error: "error";
113
+ }>;
114
+ message: z.ZodString;
115
+ method: z.ZodNullable<z.ZodString>;
116
+ status: z.ZodNullable<z.ZodNumber>;
117
+ outcome: z.ZodNullable<z.ZodString>;
118
+ durationMs: z.ZodNullable<z.ZodNumber>;
119
+ truncated: z.ZodBoolean;
120
+ }, z.core.$strict>>;
121
+ nextCursor: z.ZodNullable<z.ZodString>;
122
+ dropped: z.ZodNumber;
123
+ lastReceivedAt: z.ZodNullable<z.ZodString>;
124
+ }, z.core.$strict>;
125
+ export type RuntimeLogQuery = z.infer<typeof runtimeLogQuerySchema>;
126
+ export type RuntimeLogEntry = z.infer<typeof runtimeLogEntrySchema>;
127
+ export type RuntimeLogPage = z.infer<typeof runtimeLogPageSchema>;
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { z } from "zod";
3
+ export const runtimeLogEnvironmentSchema = z.enum(["staging", "production"]);
4
+ export const runtimeLogLevelSchema = z.enum(["debug", "info", "warn", "error"]);
5
+ export const runtimeLogSourceSchema = z.enum(["request", "console", "exception"]);
6
+ export const runtimeLogQuerySchema = z
7
+ .object({
8
+ environment: runtimeLogEnvironmentSchema.default("production"),
9
+ deploymentId: z.uuid().optional(),
10
+ level: runtimeLogLevelSchema.optional(),
11
+ source: runtimeLogSourceSchema.optional(),
12
+ range: z.enum(["1h", "24h", "7d"]).default("24h"),
13
+ search: z.string().trim().max(200).default(""),
14
+ cursor: z.string().max(512).optional(),
15
+ })
16
+ .strict();
17
+ export const runtimeLogEntrySchema = z
18
+ .object({
19
+ id: z.uuid(),
20
+ requestId: z.uuid(),
21
+ occurredAt: z.string().datetime(),
22
+ deploymentId: z.uuid(),
23
+ artifactId: z.uuid(),
24
+ environment: runtimeLogEnvironmentSchema,
25
+ component: z.enum(["api", "web"]),
26
+ kind: runtimeLogSourceSchema,
27
+ level: runtimeLogLevelSchema,
28
+ message: z.string().max(2048),
29
+ method: z.string().max(16).nullable(),
30
+ status: z.number().int().min(100).max(599).nullable(),
31
+ outcome: z.string().max(80).nullable(),
32
+ durationMs: z.number().min(0).max(300000).nullable(),
33
+ truncated: z.boolean(),
34
+ })
35
+ .strict();
36
+ export const runtimeLogPageSchema = z
37
+ .object({
38
+ state: z.enum(["disabled", "unavailable", "ready"]),
39
+ reason: z.string().nullable(),
40
+ environment: runtimeLogEnvironmentSchema,
41
+ coverage: z.literal("dynamic-workers"),
42
+ retentionDays: z.literal(7),
43
+ from: z.string().datetime(),
44
+ to: z.string().datetime(),
45
+ entries: z.array(runtimeLogEntrySchema).max(100),
46
+ nextCursor: z.string().nullable(),
47
+ dropped: z.number().int().nonnegative(),
48
+ lastReceivedAt: z.string().datetime().nullable(),
49
+ })
50
+ .strict();
@@ -0,0 +1,11 @@
1
+ export declare function readSourceBounded(body: ReadableStream<Uint8Array> | null, maximum: number): Promise<Uint8Array<ArrayBuffer>>;
2
+ export declare function sourceFileExcluded(path: string): boolean;
3
+ export declare function sourceExecutable(files: Map<string, Uint8Array>, path: string): boolean;
4
+ export declare function validateSourcePath(path: string): string;
5
+ export declare function sourceInventory(files: Map<string, Uint8Array>): Promise<{
6
+ manifest: string;
7
+ digest: string;
8
+ }>;
9
+ export declare function packSource(files: Map<string, Uint8Array>): Promise<Uint8Array<ArrayBuffer>>;
10
+ export declare function unpackSource(compressed: Uint8Array, strict?: boolean): Promise<Map<string, Uint8Array<ArrayBufferLike>>>;
11
+ export declare function setSourceExecutable(files: Map<string, Uint8Array>, path: string, executable: boolean): void;
@@ -0,0 +1,197 @@
1
+ import { SOURCE_LIMITS, sourceContainsCredential, uploadExcluded, uploadSecret, } from "./cli-transport.js";
2
+ import { excludedSource as excluded, generatedSource as generated, INVENTORY_PROFILE, secretSource as secret, } from "./source-profile.js";
3
+ const digest = async (value) => {
4
+ const bytes = typeof value === "string" ? new TextEncoder().encode(value) : Uint8Array.from(value);
5
+ return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)), (b) => b.toString(16).padStart(2, "0")).join("");
6
+ };
7
+ export async function readSourceBounded(body, maximum) {
8
+ if (!body)
9
+ throw new Error("Response body is missing.");
10
+ const reader = body.getReader(), chunks = [];
11
+ let size = 0;
12
+ try {
13
+ while (true) {
14
+ const chunk = await reader.read();
15
+ if (chunk.done)
16
+ break;
17
+ size += chunk.value.byteLength;
18
+ if (size > maximum) {
19
+ await reader.cancel();
20
+ throw new Error("Response exceeds its storage limit.");
21
+ }
22
+ chunks.push(chunk.value);
23
+ }
24
+ }
25
+ finally {
26
+ reader.releaseLock();
27
+ }
28
+ const bytes = new Uint8Array(size);
29
+ let offset = 0;
30
+ for (const chunk of chunks) {
31
+ bytes.set(chunk, offset);
32
+ offset += chunk.byteLength;
33
+ }
34
+ return bytes;
35
+ }
36
+ const executableModes = new WeakMap();
37
+ const decoder = new TextDecoder("utf-8", { fatal: true });
38
+ export function sourceFileExcluded(path) {
39
+ return (excluded.test(path) ||
40
+ generated.test(path) ||
41
+ secret.test(path) ||
42
+ uploadExcluded.test(path) ||
43
+ uploadSecret.test(path));
44
+ }
45
+ export function sourceExecutable(files, path) {
46
+ return executableModes.get(files)?.get(path) ?? false;
47
+ }
48
+ export function validateSourcePath(path) {
49
+ if (!path ||
50
+ path.length > 240 ||
51
+ path.startsWith("/") ||
52
+ path.includes("\\") ||
53
+ path.includes("\0") ||
54
+ path.split("/").some((p) => !p || p === "." || p === "..") ||
55
+ excluded.test(path) ||
56
+ generated.test(path) ||
57
+ secret.test(path))
58
+ throw Error("Choose a regular authored source file.");
59
+ return path;
60
+ }
61
+ export async function sourceInventory(files) {
62
+ let total = 0;
63
+ if (files.size > SOURCE_LIMITS.files)
64
+ throw Error("Source file count exceeded.");
65
+ const entries = [];
66
+ for (const [path, bytes] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
67
+ validateSourcePath(path);
68
+ total += bytes.length;
69
+ if (total > SOURCE_LIMITS.bytes)
70
+ throw Error("Source byte limit exceeded.");
71
+ entries.push({
72
+ path,
73
+ size: bytes.length,
74
+ executable: sourceExecutable(files, path),
75
+ digest: await digest(bytes),
76
+ });
77
+ }
78
+ const manifest = JSON.stringify({ schemaVersion: 2, profile: INVENTORY_PROFILE, entries });
79
+ return { manifest, digest: await digest(manifest) };
80
+ }
81
+ export async function packSource(files) {
82
+ await sourceInventory(files);
83
+ const blocks = [];
84
+ const encode = new TextEncoder();
85
+ const add = (name, bytes, mode, kind = "0") => {
86
+ const header = new Uint8Array(512);
87
+ const put = (offset, text) => header.set(encode.encode(text), offset);
88
+ put(0, name);
89
+ put(100, mode.toString(8).padStart(7, "0") + "\0");
90
+ put(108, "0000000\0");
91
+ put(116, "0000000\0");
92
+ put(124, bytes.length.toString(8).padStart(11, "0") + "\0");
93
+ put(136, "00000000000\0");
94
+ header.fill(32, 148, 156);
95
+ put(156, kind);
96
+ put(257, "ustar\0");
97
+ put(263, "00");
98
+ const sum = header.reduce((a, b) => a + b, 0);
99
+ put(148, sum.toString(8).padStart(6, "0") + "\0 ");
100
+ blocks.push(header, bytes, new Uint8Array((512 - (bytes.length % 512)) % 512));
101
+ };
102
+ for (const [path, bytes] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
103
+ const name = `./${path}`;
104
+ if (encode.encode(name).length > 100) {
105
+ add("././@LongLink", encode.encode(name + "\0"), 0o644, "L");
106
+ add("long-source-name", bytes, sourceExecutable(files, path) ? 0o755 : 0o644);
107
+ }
108
+ else
109
+ add(name, bytes, sourceExecutable(files, path) ? 0o755 : 0o644);
110
+ }
111
+ blocks.push(new Uint8Array(1024));
112
+ const stream = new Blob(blocks.map((bytes) => Uint8Array.from(bytes).buffer))
113
+ .stream()
114
+ .pipeThrough(new CompressionStream("gzip"));
115
+ return readSourceBounded(stream, SOURCE_LIMITS.bytes);
116
+ }
117
+ export async function unpackSource(compressed, strict = false) {
118
+ const stream = new Blob([Uint8Array.from(compressed).buffer])
119
+ .stream()
120
+ .pipeThrough(new DecompressionStream("gzip"));
121
+ const bytes = await readSourceBounded(stream, SOURCE_LIMITS.archiveBytes), files = new Map(), modes = new Map();
122
+ let terminated = false;
123
+ const str = (offset, length) => decoder.decode(bytes.subarray(offset, offset + length)).split("\0")[0];
124
+ let count = 0, total = 0, longName = null;
125
+ for (let offset = 0; offset + 512 <= bytes.length;) {
126
+ if (bytes.subarray(offset, offset + 512).every((v) => v === 0)) {
127
+ terminated = true;
128
+ if (strict && bytes.subarray(offset).some((v) => v !== 0))
129
+ throw Error("Trailing archive data.");
130
+ break;
131
+ }
132
+ if (++count > 10000)
133
+ throw new Error("Archive member count exceeded.");
134
+ const checksum = parseInt(str(offset + 148, 8).trim() || "0", 8);
135
+ let actual = 0;
136
+ for (let i = 0; i < 512; i++)
137
+ actual += i >= 148 && i < 156 ? 32 : bytes[offset + i];
138
+ if (actual !== checksum)
139
+ throw new Error("Source archive checksum failed.");
140
+ const size = parseInt(str(offset + 124, 12).trim() || "0", 8), executable = Boolean(parseInt(str(offset + 100, 8).trim() || "0", 8) & 0o111), kind = str(offset + 156, 1), prefix = str(offset + 345, 155);
141
+ if (!Number.isSafeInteger(size) || size < 0 || offset + 512 + size > bytes.length)
142
+ throw new Error("Invalid archive member size.");
143
+ const content = bytes.subarray(offset + 512, offset + 512 + size);
144
+ let name = longName ?? [prefix, str(offset, 100)].filter(Boolean).join("/");
145
+ longName = null;
146
+ offset += 512 + Math.ceil(size / 512) * 512;
147
+ if (kind === "L") {
148
+ longName = decoder.decode(content).split("\0")[0];
149
+ continue;
150
+ }
151
+ if (kind === "x" || kind === "g")
152
+ throw new Error("PAX archives are outside the pinned source format.");
153
+ name = name.replace(/^(?:\.\/)+/, "").replace(/\/$/, "");
154
+ if (!name || name === ".")
155
+ continue;
156
+ if (name.startsWith("/") ||
157
+ name.includes("\\") ||
158
+ name.includes("\0") ||
159
+ name.split("/").some((p) => p === ".." || !p))
160
+ throw new Error("Unsafe archive path.");
161
+ if (secret.test(name))
162
+ throw new Error("Forbidden source secret.");
163
+ if (excluded.test(name) || generated.test(name)) {
164
+ if (strict)
165
+ throw Error("Excluded archive member.");
166
+ continue;
167
+ }
168
+ if (strict &&
169
+ (name.length > 240 ||
170
+ /[\x00-\x1f\x7f]/.test(name) ||
171
+ uploadExcluded.test(name) ||
172
+ uploadSecret.test(name)))
173
+ throw Error("Forbidden upload member.");
174
+ if (kind === "5")
175
+ continue;
176
+ if (kind !== "" && kind !== "0")
177
+ throw new Error("Only regular source files are allowed.");
178
+ if (files.has(name) ||
179
+ files.size >= SOURCE_LIMITS.files ||
180
+ (total += size) > SOURCE_LIMITS.bytes)
181
+ throw new Error("Source inventory exceeds limits or duplicates a path.");
182
+ if (strict && sourceContainsCredential(content))
183
+ throw Error("Credential material is forbidden in source uploads.");
184
+ files.set(name, content);
185
+ modes.set(name, executable);
186
+ }
187
+ if (strict && (!terminated || longName !== null))
188
+ throw Error("Incomplete source archive.");
189
+ executableModes.set(files, modes);
190
+ return files;
191
+ }
192
+ export function setSourceExecutable(files, path, executable) {
193
+ let modes = executableModes.get(files);
194
+ if (!modes)
195
+ executableModes.set(files, (modes = new Map()));
196
+ modes.set(path, executable);
197
+ }
@@ -0,0 +1,4 @@
1
+ export declare const INVENTORY_PROFILE = "anhedral-vinext-source-v2";
2
+ export declare const excludedSource: RegExp;
3
+ export declare const generatedSource: RegExp;
4
+ export declare const secretSource: RegExp;
@@ -0,0 +1,5 @@
1
+ // Shared by trusted Worker source tools and native checkpoint inventory.
2
+ export const INVENTORY_PROFILE = "anhedral-vinext-source-v2";
3
+ export const excludedSource = /(?:^|\/)(?:node_modules|\.git|\.anhedral|\.next|\.turbo|\.wrangler|dist|build)(?:\/|$)/;
4
+ export const generatedSource = /^(?:apps\/mobile\/(?:\.expo|\.output)(?:\/|$)|apps\/api\/worker-configuration\.d\.ts$|apps\/web\/\.(?:void|open-next|tanstack)(?:\/|$)|apps\/web\/src\/routeTree\.gen\.ts$|apps\/web\/\.void-wrangler\.jsonc$|apps\/web\/(?:next-env\.d\.ts|worker-configuration\.d\.ts|tsconfig\.tsbuildinfo)$)/;
5
+ export const secretSource = /(?:^|\/)(?:\.env[^/]*|\.dev\.vars[^/]*)(?:\/|$)/;
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ export declare const stagingCreateSchema: z.ZodObject<{
3
+ requestId: z.ZodUUID;
4
+ candidateId: z.ZodUUID;
5
+ expectedGeneration: z.ZodNumber;
6
+ }, z.core.$strict>;
7
+ export declare const stagingConfigurationSchema: z.ZodObject<{
8
+ snapshotId: z.ZodUUID;
9
+ digest: z.ZodString;
10
+ environment: z.ZodLiteral<"staging">;
11
+ }, z.core.$strict>;
12
+ export declare const stagingDeploymentSchema: z.ZodObject<{
13
+ id: z.ZodUUID;
14
+ developmentId: z.ZodUUID;
15
+ candidateId: z.ZodUUID;
16
+ generation: z.ZodNumber;
17
+ status: z.ZodEnum<{
18
+ queued: "queued";
19
+ preparing: "preparing";
20
+ ready: "ready";
21
+ deployed: "deployed";
22
+ failed: "failed";
23
+ superseded: "superseded";
24
+ }>;
25
+ summary: z.ZodNullable<z.ZodString>;
26
+ sourceRevision: z.ZodString;
27
+ configuration: z.ZodObject<{
28
+ snapshotId: z.ZodUUID;
29
+ digest: z.ZodString;
30
+ environment: z.ZodLiteral<"staging">;
31
+ }, z.core.$strict>;
32
+ createdAt: z.ZodString;
33
+ updatedAt: z.ZodString;
34
+ }, z.core.$strip>;
35
+ export declare const stagingStateSchema: z.ZodObject<{
36
+ enabled: z.ZodOptional<z.ZodBoolean>;
37
+ canDeploy: z.ZodBoolean;
38
+ generation: z.ZodNumber;
39
+ activeDeploymentId: z.ZodNullable<z.ZodUUID>;
40
+ desiredDeploymentId: z.ZodNullable<z.ZodUUID>;
41
+ deployments: z.ZodArray<z.ZodObject<{
42
+ id: z.ZodUUID;
43
+ developmentId: z.ZodUUID;
44
+ candidateId: z.ZodUUID;
45
+ generation: z.ZodNumber;
46
+ status: z.ZodEnum<{
47
+ queued: "queued";
48
+ preparing: "preparing";
49
+ ready: "ready";
50
+ deployed: "deployed";
51
+ failed: "failed";
52
+ superseded: "superseded";
53
+ }>;
54
+ summary: z.ZodNullable<z.ZodString>;
55
+ sourceRevision: z.ZodString;
56
+ configuration: z.ZodObject<{
57
+ snapshotId: z.ZodUUID;
58
+ digest: z.ZodString;
59
+ environment: z.ZodLiteral<"staging">;
60
+ }, z.core.$strict>;
61
+ createdAt: z.ZodString;
62
+ updatedAt: z.ZodString;
63
+ }, z.core.$strip>>;
64
+ }, z.core.$strip>;
65
+ export type StagingCreate = z.infer<typeof stagingCreateSchema>;
66
+ export type StagingDeployment = z.infer<typeof stagingDeploymentSchema>;
67
+ export type StagingState = z.infer<typeof stagingStateSchema>;
68
+ export declare const stagingCreateReceiptSchema: z.ZodObject<{
69
+ id: z.ZodUUID;
70
+ developmentId: z.ZodUUID;
71
+ candidateId: z.ZodUUID;
72
+ requestId: z.ZodUUID;
73
+ generation: z.ZodNumber;
74
+ configuration: z.ZodObject<{
75
+ snapshotId: z.ZodUUID;
76
+ digest: z.ZodString;
77
+ environment: z.ZodLiteral<"staging">;
78
+ }, z.core.$strict>;
79
+ }, z.core.$strict>;