anhedral 0.11.0 → 0.11.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 (148) hide show
  1. package/README.md +73 -157
  2. package/assets/patches/LICENSE.braces +21 -0
  3. package/assets/patches/LICENSE.node-forge +50 -0
  4. package/assets/patches/audit-deps.mjs +167 -0
  5. package/assets/patches/braces@3.0.3.patch +127 -0
  6. package/assets/patches/node-forge@1.4.0.patch +41 -0
  7. package/dist/auth-schema.js +3 -3
  8. package/dist/bin.js +15 -11
  9. package/dist/capabilities.d.ts +4 -4
  10. package/dist/capabilities.js +6 -2
  11. package/dist/capability-contract.js +22 -5
  12. package/dist/catalog-model.d.ts +24 -0
  13. package/dist/catalog-model.js +1 -0
  14. package/dist/catalog-registration.d.ts +16 -0
  15. package/dist/catalog-registration.js +22 -0
  16. package/dist/catalog-snapshot.d.ts +5 -0
  17. package/dist/catalog-snapshot.js +97 -0
  18. package/dist/cli-arguments.js +1 -1
  19. package/dist/cli-output.js +27 -2
  20. package/dist/cloudflare.d.ts +7 -1
  21. package/dist/cloudflare.js +36 -6
  22. package/dist/command-schema.js +49 -5
  23. package/dist/delivery.d.ts +10 -3
  24. package/dist/delivery.js +154 -37
  25. package/dist/dependencies.d.ts +24 -0
  26. package/dist/dependencies.js +48 -0
  27. package/dist/dependency-patches.d.ts +7 -0
  28. package/dist/dependency-patches.js +125 -0
  29. package/dist/index.d.ts +3 -0
  30. package/dist/index.js +2 -0
  31. package/dist/inspector-model.d.ts +9 -1
  32. package/dist/integration-service-readers.d.ts +13 -0
  33. package/dist/integration-service-readers.js +173 -0
  34. package/dist/lifecycle.d.ts +0 -1
  35. package/dist/lifecycle.js +0 -1
  36. package/dist/neon-service-data.d.ts +8 -0
  37. package/dist/neon-service-data.js +117 -0
  38. package/dist/pnpm-policy.d.ts +2 -2
  39. package/dist/pnpm-policy.js +19 -45
  40. package/dist/project-catalog.d.ts +41 -0
  41. package/dist/project-catalog.js +288 -0
  42. package/dist/project-config.d.ts +14 -0
  43. package/dist/project-config.js +89 -0
  44. package/dist/project-inspector.js +73 -17
  45. package/dist/project-lifecycle.d.ts +25 -0
  46. package/dist/project-lifecycle.js +57 -0
  47. package/dist/project-state.d.ts +5 -1
  48. package/dist/project-state.js +122 -16
  49. package/dist/provider-auth.js +2 -3
  50. package/dist/provider-readiness.js +27 -10
  51. package/dist/providers/adapters.js +4 -1
  52. package/dist/providers/api.d.ts +1 -0
  53. package/dist/providers/api.js +1 -0
  54. package/dist/providers/config.js +6 -8
  55. package/dist/providers/provision.js +1 -1
  56. package/dist/providers/recovery.d.ts +1 -1
  57. package/dist/providers/runtime.d.ts +1 -1
  58. package/dist/providers/runtime.js +46 -23
  59. package/dist/providers/state.d.ts +1 -2
  60. package/dist/providers/state.js +14 -54
  61. package/dist/provision.d.ts +9 -0
  62. package/dist/provision.js +30 -1
  63. package/dist/r2-service-data.d.ts +2 -0
  64. package/dist/r2-service-data.js +136 -0
  65. package/dist/readiness.js +9 -13
  66. package/dist/registry/add.js +64 -21
  67. package/dist/registry/commands.js +7 -9
  68. package/dist/registry/options.d.ts +1 -1
  69. package/dist/registry/options.js +4 -4
  70. package/dist/registry/receipt.d.ts +1 -0
  71. package/dist/registry/receipt.js +19 -4
  72. package/dist/registry/resolve.js +5 -1
  73. package/dist/registry/usage.js +1 -5
  74. package/dist/render.d.ts +2 -0
  75. package/dist/render.js +6 -0
  76. package/dist/runtime-policy.d.ts +4 -0
  77. package/dist/runtime-policy.js +21 -0
  78. package/dist/scaffold/bootstrap.js +2 -2
  79. package/dist/scaffold/compose.js +9 -3
  80. package/dist/scaffold/database.js +107 -25
  81. package/dist/scaffold/documentation.js +18 -13
  82. package/dist/scaffold/lint.d.ts +4 -0
  83. package/dist/scaffold/lint.js +56 -0
  84. package/dist/scaffold/neon-realtime.d.ts +2 -0
  85. package/dist/scaffold/neon-realtime.js +97 -0
  86. package/dist/scaffold/stack-documentation.js +1 -1
  87. package/dist/scaffold/void.d.ts +4 -0
  88. package/dist/scaffold/void.js +256 -0
  89. package/dist/scaffold/web.js +7 -1
  90. package/dist/scaffold/workspace.js +120 -29
  91. package/dist/service-deletion.d.ts +29 -0
  92. package/dist/service-deletion.js +195 -0
  93. package/dist/service-descriptor.d.ts +10 -0
  94. package/dist/service-descriptor.js +78 -0
  95. package/dist/service-model.d.ts +49 -0
  96. package/dist/service-model.js +8 -0
  97. package/dist/service-operations.d.ts +29 -0
  98. package/dist/service-operations.js +78 -0
  99. package/dist/service-readers.d.ts +8 -0
  100. package/dist/service-readers.js +247 -0
  101. package/dist/services-command.d.ts +39 -0
  102. package/dist/services-command.js +100 -0
  103. package/dist/ship.d.ts +36 -8
  104. package/dist/ship.js +39 -13
  105. package/dist/stack-registry.d.ts +4 -2
  106. package/dist/stack-registry.js +41 -11
  107. package/dist/standard.js +23 -4
  108. package/dist/transaction.d.ts +2 -0
  109. package/dist/transaction.js +10 -0
  110. package/dist/util.js +17 -2
  111. package/dist/vercel.d.ts +2 -0
  112. package/dist/vercel.js +69 -13
  113. package/dist/version.d.ts +1 -1
  114. package/dist/version.js +1 -1
  115. package/dist/vinext.d.ts +1 -0
  116. package/dist/vinext.js +13 -1
  117. package/dist/void-execution.d.ts +10 -0
  118. package/dist/void-execution.js +94 -0
  119. package/dist/void-migrations.d.ts +6 -0
  120. package/dist/void-migrations.js +110 -0
  121. package/dist/void-state.d.ts +16 -0
  122. package/dist/void-state.js +65 -0
  123. package/dist/void.d.ts +3 -0
  124. package/dist/void.js +5 -0
  125. package/docs/cli-design.md +2 -2
  126. package/docs/delivery-workflow.md +8 -7
  127. package/docs/plugin-ui.md +51 -10
  128. package/docs/provider-configuration.md +10 -11
  129. package/docs/stack-standard.md +175 -0
  130. package/docs/void-verification.md +185 -0
  131. package/package.json +22 -20
  132. package/assets/anhedral-mark.svg +0 -4
  133. package/assets/anhedral-stack-technical.svg +0 -322
  134. package/assets/anhedral-stack.svg +0 -322
  135. package/assets/anhedral.svg +0 -4
  136. package/assets/favicon.ico +0 -0
  137. package/assets/security/LICENSES.txt +0 -63
  138. package/assets/security/audit-deps.mjs +0 -300
  139. package/assets/security/braces-regression.mjs +0 -102
  140. package/assets/security/braces@3.0.3.patch +0 -285
  141. package/assets/security/decode-uri-component@0.2.2.patch +0 -149
  142. package/assets/security/decoder-regression.mjs +0 -37
  143. package/assets/security/forge-regression.mjs +0 -46
  144. package/assets/security/manifest.json +0 -53
  145. package/assets/security/node-forge@1.4.0.patch +0 -26
  146. package/dist/security-backports.d.ts +0 -3
  147. package/dist/security-backports.js +0 -26
  148. package/docs/application-stack-standard.md +0 -75
@@ -0,0 +1,288 @@
1
+ import { existsSync, lstatSync, openSync, closeSync, mkdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
2
+ import { randomUUID } from 'node:crypto';
3
+ import path from 'node:path';
4
+ import { hostname } from 'node:os';
5
+ import { z } from 'zod';
6
+ import { projectSnapshot, readCatalogSourceIdentity } from './catalog-snapshot.js';
7
+ import { readBoundedFile } from './bounded-file.js';
8
+ const catalogErrors = {
9
+ CATALOG_BUSY: {
10
+ message: 'The catalog is busy. Retry when the other operation has finished.',
11
+ nextAction: 'If an operation was interrupted, inspect the catalog lock and use the local recover-catalog-lock command.',
12
+ },
13
+ CATALOG_INVALID: {
14
+ message: 'Project catalog is invalid. Restore the local catalog before continuing.',
15
+ nextAction: 'Restore a valid catalog backup; no project files were changed.',
16
+ },
17
+ PROJECT_NOT_FOUND: {
18
+ message: 'This project is not in your catalog.',
19
+ nextAction: 'Refresh the project list and select a registered project.',
20
+ },
21
+ PROJECT_UNAVAILABLE: {
22
+ message: 'Registered source is unavailable.',
23
+ nextAction: 'Restore the registered source directory, then refresh.',
24
+ },
25
+ INVALID_INPUT: {
26
+ message: 'The catalog input is invalid.',
27
+ nextAction: 'Check the project ID and requested input, then retry.',
28
+ },
29
+ CATALOG_FAILURE: {
30
+ message: 'The catalog operation could not complete.',
31
+ nextAction: 'Check local catalog access and retry.',
32
+ },
33
+ };
34
+ export class CatalogError extends Error {
35
+ code;
36
+ constructor(code) {
37
+ super(catalogErrors[code].message);
38
+ this.code = code;
39
+ }
40
+ }
41
+ export function catalogFailure(error) {
42
+ const code = error instanceof CatalogError ? error.code : 'CATALOG_FAILURE';
43
+ return { code, ...catalogErrors[code] };
44
+ }
45
+ const entrySchema = z
46
+ .object({
47
+ id: z.string().uuid(),
48
+ root: z.string().min(1),
49
+ name: z.string().trim().min(1).max(80),
50
+ updatedAt: z.string().datetime(),
51
+ sourceIdentity: z.string().uuid().optional(),
52
+ })
53
+ .strict();
54
+ const catalogSchema = z
55
+ .object({
56
+ schemaVersion: z.literal(1),
57
+ projects: z.array(entrySchema).max(200),
58
+ view: z.enum(['list', 'grid']),
59
+ })
60
+ .strict();
61
+ const projectId = z.string().uuid();
62
+ const toolSchema = z.enum([
63
+ 'list_projects',
64
+ 'get_project',
65
+ 'rename_project',
66
+ 'forget_project',
67
+ 'set_view',
68
+ ]);
69
+ const inputSchemas = {
70
+ list_projects: z.object({}).strict(),
71
+ get_project: z.object({ id: projectId }).strict(),
72
+ rename_project: z.object({ id: projectId, name: z.string().trim().min(1).max(80) }).strict(),
73
+ forget_project: z.object({ id: projectId }).strict(),
74
+ set_view: z.object({ view: z.enum(['list', 'grid']) }).strict(),
75
+ };
76
+ const CATALOG_LIMIT = 1024 * 1024;
77
+ export class ProjectStore {
78
+ directory;
79
+ file;
80
+ constructor(directory) {
81
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
82
+ this.directory = realpathSync(directory);
83
+ this.file = path.join(this.directory, 'projects.json');
84
+ }
85
+ read() {
86
+ if (!existsSync(this.file))
87
+ return { schemaVersion: 1, projects: [], view: 'list' };
88
+ try {
89
+ const value = catalogSchema.parse(JSON.parse(readBoundedFile(this.file, CATALOG_LIMIT).toString('utf8')));
90
+ if (new Set(value.projects.map((project) => project.id)).size !== value.projects.length)
91
+ throw new Error();
92
+ return value;
93
+ }
94
+ catch {
95
+ throw new CatalogError('CATALOG_INVALID');
96
+ }
97
+ }
98
+ write(catalog) {
99
+ const temporary = path.join(this.directory, `${randomUUID()}.tmp`);
100
+ const bytes = JSON.stringify(catalogSchema.parse(catalog), null, 2) + '\n';
101
+ if (Buffer.byteLength(bytes) > CATALOG_LIMIT)
102
+ throw new Error('Project catalog exceeds its storage limit.');
103
+ writeFileSync(temporary, bytes, {
104
+ mode: 0o600,
105
+ flag: 'wx',
106
+ });
107
+ try {
108
+ renameSync(temporary, this.file);
109
+ }
110
+ finally {
111
+ rmSync(temporary, { force: true });
112
+ }
113
+ }
114
+ register(root, displayName) {
115
+ const resolved = realpathSync(root);
116
+ if (!statSync(resolved).isDirectory())
117
+ throw new Error('Choose a project directory.');
118
+ // Registration is an operator action; MCP tools cannot add arbitrary filesystem paths.
119
+ let packageName;
120
+ try {
121
+ packageName = z
122
+ .string()
123
+ .min(1)
124
+ .parse(JSON.parse(readBoundedFile(path.join(resolved, 'package.json'), 1024 * 1024).toString('utf8')).name);
125
+ }
126
+ catch {
127
+ throw new Error('Choose a project with a valid package.json name.');
128
+ }
129
+ const sourceIdentity = readCatalogSourceIdentity(resolved);
130
+ return this.mutate((catalog) => {
131
+ const previous = catalog.projects.find((project) => project.root === resolved && project.sourceIdentity === sourceIdentity);
132
+ if (previous)
133
+ return previous.id;
134
+ const entry = entrySchema.parse({
135
+ id: randomUUID(),
136
+ root: resolved,
137
+ name: displayName ?? packageName,
138
+ updatedAt: new Date().toISOString(),
139
+ ...(sourceIdentity ? { sourceIdentity } : {}),
140
+ });
141
+ catalog.projects.push(entry);
142
+ return entry.id;
143
+ });
144
+ }
145
+ mutate(operation) {
146
+ const lock = path.join(this.directory, 'projects.lock');
147
+ let descriptor;
148
+ try {
149
+ if (existsSync(path.join(this.directory, 'projects.recovery.lock')))
150
+ throw new Error();
151
+ descriptor = openSync(lock, 'wx', 0o600);
152
+ }
153
+ catch {
154
+ throw new CatalogError('CATALOG_BUSY');
155
+ }
156
+ try {
157
+ writeFileSync(descriptor, JSON.stringify({
158
+ schemaVersion: 1,
159
+ pid: process.pid,
160
+ host: hostname(),
161
+ token: randomUUID(),
162
+ createdAt: new Date().toISOString(),
163
+ }));
164
+ if (existsSync(path.join(this.directory, 'projects.recovery.lock')))
165
+ throw new CatalogError('CATALOG_BUSY');
166
+ const catalog = this.read();
167
+ const result = operation(catalog);
168
+ this.write(catalog);
169
+ return result;
170
+ }
171
+ finally {
172
+ closeSync(descriptor);
173
+ rmSync(lock, { force: true });
174
+ }
175
+ }
176
+ /** Explicit local operator recovery only; uncertain ownership never removes a lock. */
177
+ recoverCatalogLock() {
178
+ const guard = path.join(this.directory, 'projects.recovery.lock');
179
+ let descriptor;
180
+ try {
181
+ descriptor = openSync(guard, 'wx', 0o600);
182
+ }
183
+ catch {
184
+ throw new CatalogError('CATALOG_BUSY');
185
+ }
186
+ try {
187
+ const lock = path.join(this.directory, 'projects.lock');
188
+ if (!existsSync(lock))
189
+ return { recovered: false };
190
+ let owner;
191
+ try {
192
+ if (!lstatSync(lock).isFile() || lstatSync(lock).isSymbolicLink())
193
+ throw new Error();
194
+ owner = z
195
+ .object({
196
+ schemaVersion: z.literal(1),
197
+ pid: z.number().int().positive(),
198
+ host: z.string(),
199
+ token: z.string().uuid(),
200
+ createdAt: z.string().datetime(),
201
+ })
202
+ .strict()
203
+ .parse(JSON.parse(readBoundedFile(lock, 4096).toString('utf8')));
204
+ }
205
+ catch {
206
+ throw new CatalogError('CATALOG_BUSY');
207
+ }
208
+ if (owner.host !== hostname())
209
+ throw new CatalogError('CATALOG_BUSY');
210
+ try {
211
+ process.kill(owner.pid, 0);
212
+ }
213
+ catch (error) {
214
+ if (error.code === 'ESRCH') {
215
+ rmSync(lock);
216
+ return { recovered: true };
217
+ }
218
+ throw new CatalogError('CATALOG_BUSY');
219
+ }
220
+ throw new CatalogError('CATALOG_BUSY');
221
+ }
222
+ finally {
223
+ closeSync(descriptor);
224
+ rmSync(guard, { force: true });
225
+ }
226
+ }
227
+ context(id) {
228
+ const project = this.read().projects.find((project) => project.id === id);
229
+ if (!project)
230
+ throw new CatalogError('PROJECT_NOT_FOUND');
231
+ try {
232
+ if (realpathSync(project.root) !== project.root ||
233
+ project.sourceIdentity !== readCatalogSourceIdentity(project.root))
234
+ throw new Error();
235
+ }
236
+ catch {
237
+ throw new CatalogError('PROJECT_UNAVAILABLE');
238
+ }
239
+ return { id: project.id, name: project.name, directory: project.root };
240
+ }
241
+ snapshot(selectedId = null) {
242
+ const catalog = this.read();
243
+ return {
244
+ projects: catalog.projects
245
+ .map((entry) => projectSnapshot(entry, entry.id === selectedId))
246
+ .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)),
247
+ selectedId,
248
+ preferences: { view: catalog.view },
249
+ };
250
+ }
251
+ call(tool, raw) {
252
+ let args;
253
+ try {
254
+ args = inputSchemas[toolSchema.parse(tool)].parse(raw);
255
+ }
256
+ catch {
257
+ throw new CatalogError('INVALID_INPUT');
258
+ }
259
+ if (tool === 'list_projects')
260
+ return this.snapshot();
261
+ if (tool === 'get_project') {
262
+ if (!this.read().projects.some((project) => project.id === args.id))
263
+ throw new CatalogError('PROJECT_NOT_FOUND');
264
+ return this.snapshot(args.id);
265
+ }
266
+ const selectedId = this.mutate((catalog) => {
267
+ if (tool === 'set_view') {
268
+ if (!args.view)
269
+ throw new Error('Choose list or grid view.');
270
+ catalog.view = args.view;
271
+ return null;
272
+ }
273
+ const project = catalog.projects.find((project) => project.id === args.id);
274
+ if (!project)
275
+ throw new CatalogError('PROJECT_NOT_FOUND');
276
+ if (tool === 'rename_project') {
277
+ if (!args.name)
278
+ throw new Error('Enter a project name.');
279
+ project.name = args.name;
280
+ project.updatedAt = new Date().toISOString();
281
+ return project.id;
282
+ }
283
+ catalog.projects = catalog.projects.filter((entry) => entry.id !== project.id);
284
+ return null;
285
+ });
286
+ return this.snapshot(selectedId);
287
+ }
288
+ }
@@ -0,0 +1,14 @@
1
+ export declare const PROJECT_CONFIG_FILE = "anhedral.json";
2
+ export declare const PROJECT_CONFIG_MAX_BYTES: number;
3
+ export declare const PROJECT_CONFIG_SECTIONS: readonly ["identity", "standard", "setup", "providers", "cloudflare", "vercel", "registry"];
4
+ export type ProjectSection = (typeof PROJECT_CONFIG_SECTIONS)[number];
5
+ export type ProjectConfig = {
6
+ schemaVersion: 1;
7
+ } & Partial<Record<ProjectSection, unknown>>;
8
+ /** Validate the envelope independently; each domain validates its own selected section. */
9
+ export declare function parseProjectConfig(value: unknown): ProjectConfig;
10
+ export declare function projectConfigPath(root: string): string;
11
+ export declare function readProjectConfig(root: string): ProjectConfig;
12
+ export declare function hasProjectSection(root: string, section: ProjectSection): boolean;
13
+ export declare function readProjectSection<T = any>(root: string, section: ProjectSection): T;
14
+ export declare function writeProjectSection(root: string, section: ProjectSection, value: unknown): void;
@@ -0,0 +1,89 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { lstatSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { withSourceWriteLock } from './transaction.js';
5
+ import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
6
+ export const PROJECT_CONFIG_FILE = 'anhedral.json';
7
+ export const PROJECT_CONFIG_MAX_BYTES = MAX_PROJECT_JSON_BYTES;
8
+ export const PROJECT_CONFIG_SECTIONS = [
9
+ 'identity',
10
+ 'standard',
11
+ 'setup',
12
+ 'providers',
13
+ 'cloudflare',
14
+ 'vercel',
15
+ 'registry',
16
+ ];
17
+ /** Validate the envelope independently; each domain validates its own selected section. */
18
+ export function parseProjectConfig(value) {
19
+ if (!value ||
20
+ typeof value !== 'object' ||
21
+ Array.isArray(value) ||
22
+ value.schemaVersion !== 1 ||
23
+ Object.keys(value).some((key) => key !== 'schemaVersion' && !PROJECT_CONFIG_SECTIONS.includes(key)))
24
+ throw new Error('Invalid anhedral.json configuration.');
25
+ return value;
26
+ }
27
+ export function projectConfigPath(root) {
28
+ return path.join(root, PROJECT_CONFIG_FILE);
29
+ }
30
+ export function readProjectConfig(root) {
31
+ const source = readBoundedFile(projectConfigPath(root), PROJECT_CONFIG_MAX_BYTES).toString('utf8');
32
+ try {
33
+ return parseProjectConfig(JSON.parse(source));
34
+ }
35
+ catch {
36
+ throw new Error('Invalid anhedral.json configuration.');
37
+ }
38
+ }
39
+ function assertSection(section) {
40
+ if (!PROJECT_CONFIG_SECTIONS.includes(section))
41
+ throw new Error('Unknown anhedral.json section.');
42
+ }
43
+ export function hasProjectSection(root, section) {
44
+ assertSection(section);
45
+ if (!lstatSync(projectConfigPath(root), { throwIfNoEntry: false }))
46
+ return false;
47
+ return Object.hasOwn(readProjectConfig(root), section);
48
+ }
49
+ // Domain callers retain responsibility for validating their complete section contracts.
50
+ export function readProjectSection(root, section) {
51
+ assertSection(section);
52
+ const value = readProjectConfig(root)[section];
53
+ if (!value || typeof value !== 'object' || Array.isArray(value))
54
+ throw new Error(`Missing or invalid anhedral.json ${section} section.`);
55
+ return value;
56
+ }
57
+ /** Atomically replace one section while preserving other domains' configuration. */
58
+ function writeSection(root, section, value) {
59
+ assertSection(section);
60
+ if (!value || typeof value !== 'object' || Array.isArray(value))
61
+ throw new Error(`Invalid anhedral.json ${section} section.`);
62
+ const file = projectConfigPath(root);
63
+ const previous = lstatSync(file, { throwIfNoEntry: false }) ? readProjectConfig(root) : {};
64
+ const config = { ...previous, schemaVersion: 1, [section]: value };
65
+ const ordered = {
66
+ schemaVersion: 1,
67
+ ...Object.fromEntries(PROJECT_CONFIG_SECTIONS.filter((key) => Object.hasOwn(config, key)).map((key) => [
68
+ key,
69
+ config[key],
70
+ ])),
71
+ };
72
+ const bytes = JSON.stringify(ordered, null, 2) + '\n';
73
+ if (Buffer.byteLength(bytes) > PROJECT_CONFIG_MAX_BYTES)
74
+ throw new Error('anhedral.json exceeds its size limit.');
75
+ // Avoid changing source bytes or permissions when the requested section is unchanged.
76
+ if (lstatSync(file, { throwIfNoEntry: false }) && readFileSync(file, 'utf8') === bytes)
77
+ return;
78
+ const temporary = `${file}.${randomUUID()}.tmp`;
79
+ try {
80
+ writeFileSync(temporary, bytes, { mode: 0o600, flag: 'wx' });
81
+ renameSync(temporary, file);
82
+ }
83
+ finally {
84
+ rmSync(temporary, { force: true });
85
+ }
86
+ }
87
+ export function writeProjectSection(root, section, value) {
88
+ withSourceWriteLock(root, () => writeSection(root, section, value));
89
+ }
@@ -1,7 +1,10 @@
1
+ import { resolveVoidCloudflareConfig } from './project-state.js';
2
+ import { projectLifecycle } from './project-lifecycle.js';
1
3
  import path from 'node:path';
2
4
  import { existsSync, lstatSync, readdirSync, realpathSync } from 'node:fs';
3
5
  import { parse } from 'jsonc-parser';
4
- import { readBoundedFile } from './bounded-file.js';
6
+ import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
7
+ import { parseProjectConfig } from './project-config.js';
5
8
  import { inspectProject, validateSetupPlan } from './readiness.js';
6
9
  import { inspectWorkspaceGraph } from './workspace-graph.js';
7
10
  import { readLifecycleOperation } from './lifecycle.js';
@@ -157,6 +160,33 @@ export function inspectApplication(root) {
157
160
  documents.set(relative, result);
158
161
  return result;
159
162
  }
163
+ let configurationRead = false;
164
+ let projectConfiguration = null;
165
+ let configurationError;
166
+ function projectSection(section, required = false) {
167
+ if (!configurationRead) {
168
+ configurationRead = true;
169
+ try {
170
+ const source = content('anhedral.json', MAX_PROJECT_JSON_BYTES);
171
+ if (source !== null)
172
+ projectConfiguration = parseProjectConfig(JSON.parse(source));
173
+ }
174
+ catch (error) {
175
+ configurationError = error;
176
+ }
177
+ }
178
+ if (configurationError)
179
+ throw configurationError;
180
+ const value = projectConfiguration?.[section];
181
+ if (value === undefined) {
182
+ if (required)
183
+ throw new Error('Missing project configuration section.');
184
+ return null;
185
+ }
186
+ if (Buffer.byteLength(JSON.stringify(value)) > MAX_FILE)
187
+ throw new Error('Project configuration section exceeds inspection limit.');
188
+ return object(value);
189
+ }
160
190
  function apps() {
161
191
  const parent = localFile('apps');
162
192
  if (!parent)
@@ -176,7 +206,7 @@ export function inspectApplication(root) {
176
206
  /* Root identity is optional; sections remain inspectable. */
177
207
  }
178
208
  const selection = section({ cliVersion: null, products: [], hosting: null }, 'Project selection or scaffold provenance is unavailable. Use the recorded CLI version and inspect source.', () => {
179
- const setup = document('anhedral.setup.json', true);
209
+ const setup = projectSection('setup', true);
180
210
  if (typeof setup?.cliVersion !== 'string' || !/^\d+\.\d+\.\d+$/.test(setup.cliVersion))
181
211
  throw new Error('Invalid CLI version.');
182
212
  validateSetupPlan(setup);
@@ -268,7 +298,13 @@ export function inspectApplication(root) {
268
298
  });
269
299
  };
270
300
  for (const application of apps()) {
271
- const config = document(`${application}/wrangler.jsonc`);
301
+ const declaration = document(`${application}/anhedral.cloudflare.json`);
302
+ const lock = declaration ? document(`${application}/void.lock.json`) : null;
303
+ const config = declaration
304
+ ? lock
305
+ ? resolveVoidCloudflareConfig(declaration, lock)
306
+ : declaration
307
+ : document(`${application}/wrangler.jsonc`);
272
308
  if (config) {
273
309
  for (const [field, kind, idField] of [
274
310
  ['d1_databases', 'D1', 'database_id'],
@@ -313,7 +349,7 @@ export function inspectApplication(root) {
313
349
  schedules.push({ application, expression });
314
350
  }
315
351
  }
316
- for (const example of ['.env.example', '.dev.vars.example']) {
352
+ for (const example of ['env.example', '.env.example', '.dev.vars.example']) {
317
353
  const source = content(`${application}/${example}`);
318
354
  if (!source)
319
355
  continue;
@@ -339,7 +375,7 @@ export function inspectApplication(root) {
339
375
  return array(value.releases).map(object).slice(-50);
340
376
  }
341
377
  function release(value, url) {
342
- if (!['running', 'checked', 'deployed', 'failed'].includes(String(value.state)))
378
+ if (!['running', 'checked', 'deployed', 'configuration-required', 'failed'].includes(String(value.state)))
343
379
  throw new Error('Invalid release state.');
344
380
  return {
345
381
  id: identity(value.id),
@@ -396,11 +432,10 @@ export function inspectApplication(root) {
396
432
  function hostingTargets() {
397
433
  const targets = [];
398
434
  for (const provider of ['cloudflare', 'vercel']) {
399
- const manifest = provider === 'cloudflare' ? 'anhedral.project.json' : 'anhedral.web.json';
400
- if (!localFile(manifest))
401
- continue;
402
435
  try {
403
- const project = document(manifest, true);
436
+ const project = projectSection(provider);
437
+ if (!project)
438
+ continue;
404
439
  if (project.schemaVersion !== 1 ||
405
440
  project.provider !== provider ||
406
441
  project.ownership !== 'customer' ||
@@ -582,7 +617,7 @@ export function inspectApplication(root) {
582
617
  const value = document('.anhedral/resources.json');
583
618
  if (!value)
584
619
  return [];
585
- const project = document('anhedral.project.json', true);
620
+ const project = projectSection('cloudflare', true);
586
621
  if (value.schemaVersion !== 1 ||
587
622
  value.projectId !== project.id ||
588
623
  value.accountId !== project.accountId)
@@ -593,18 +628,37 @@ export function inspectApplication(root) {
593
628
  kind: name(entry.kind),
594
629
  name: name(entry.name),
595
630
  id: identity(entry.id),
631
+ createdByProject: typeof entry.createdByProject === 'boolean' ? entry.createdByProject : null,
596
632
  reused: typeof entry.reused === 'boolean' ? entry.reused : null,
597
633
  recordedAt: time(value.checkedAt),
598
634
  };
599
635
  });
600
636
  });
637
+ const serviceDeletions = section([], 'Service deletion records are unavailable or belong to another project.', () => {
638
+ const value = document('.anhedral/service-deletions.json');
639
+ if (!value)
640
+ return [];
641
+ const project = projectSection('cloudflare', true);
642
+ if (value.schemaVersion !== 1 ||
643
+ value.projectId !== project.id ||
644
+ value.accountId !== project.accountId)
645
+ throw new Error('Foreign deletion journal.');
646
+ return array(value.entries, 500).map((raw) => {
647
+ const entry = object(raw);
648
+ if (!['pending', 'deleted', 'uncertain'].includes(String(entry.state)))
649
+ throw new Error('Invalid deletion state.');
650
+ return {
651
+ resourceId: identity(entry.resourceId),
652
+ kind: name(entry.kind),
653
+ name: name(entry.name),
654
+ state: entry.state,
655
+ recordedAt: time(entry.recordedAt),
656
+ };
657
+ });
658
+ });
601
659
  const readiness = section({ localReady: false, checks: [] }, 'Local prerequisite checks are unavailable. Provider and product readiness are unknown.', () => {
602
- for (const file of [
603
- 'anhedral.setup.json',
604
- 'anhedral.standard.json',
605
- 'anhedral.registry.json',
606
- ])
607
- content(file);
660
+ for (const key of ['setup', 'standard', 'registry'])
661
+ projectSection(key);
608
662
  if (workspaces.state === 'unavailable')
609
663
  throw new Error('Unsafe workspace graph.');
610
664
  const result = inspectProject(root);
@@ -621,7 +675,7 @@ export function inspectApplication(root) {
621
675
  }
622
676
  return value;
623
677
  });
624
- return {
678
+ const inspection = {
625
679
  schemaVersion: 1,
626
680
  name: applicationName,
627
681
  inspectedAt: new Date().toISOString(),
@@ -640,7 +694,9 @@ export function inspectApplication(root) {
640
694
  targets,
641
695
  integrations,
642
696
  cloudflareResources,
697
+ serviceDeletions,
643
698
  readiness,
644
699
  operation,
645
700
  };
701
+ return { ...inspection, lifecycle: projectLifecycle(inspection) };
646
702
  }
@@ -0,0 +1,25 @@
1
+ import type { ProjectInspection } from './inspector-model.js';
2
+ export interface ProjectLifecycle {
3
+ supportedConfiguration: boolean;
4
+ init: {
5
+ state: 'configured' | 'needs-attention' | 'unavailable';
6
+ message: string;
7
+ };
8
+ auth: {
9
+ state: 'not-checked';
10
+ providers: string[];
11
+ accounts: {
12
+ provider: string;
13
+ reference: string;
14
+ }[];
15
+ message: string;
16
+ };
17
+ ship: {
18
+ state: 'not-recorded' | 'recorded' | 'needs-attention';
19
+ successfulTargets: number;
20
+ totalTargets: number;
21
+ message: string;
22
+ };
23
+ }
24
+ /** Derive lifecycle evidence from the CLI inspector. Never infer authentication or live health. */
25
+ export declare function projectLifecycle(inspection: ProjectInspection): ProjectLifecycle;
@@ -0,0 +1,57 @@
1
+ /** Derive lifecycle evidence from the CLI inspector. Never infer authentication or live health. */
2
+ export function projectLifecycle(inspection) {
3
+ const supportedConfiguration = inspection.selection.state === 'available' &&
4
+ Boolean(inspection.selection.data.cliVersion) &&
5
+ inspection.selection.data.products.length > 0;
6
+ const targets = inspection.targets.state === 'available' ? inspection.targets.data : [];
7
+ const successfulTargets = targets.filter((target) => target.lastSuccessful).length;
8
+ const accounts = targets
9
+ .flatMap((target) => target.accountReference
10
+ ? [{ provider: target.provider, reference: target.accountReference }]
11
+ : [])
12
+ .filter((account, index, values) => values.findIndex((value) => value.provider === account.provider && value.reference === account.reference) === index);
13
+ const blocked = inspection.targets.state === 'unavailable' ||
14
+ inspection.serviceDeletions?.state === 'unavailable' ||
15
+ Boolean(inspection.serviceDeletions?.data.length) ||
16
+ inspection.operation.state === 'unavailable' ||
17
+ Boolean(inspection.operation.data && inspection.operation.data.state !== 'completed') ||
18
+ targets.some((target) => target.error ||
19
+ target.delivery === 'scaffold-only' ||
20
+ (target.latestAttempt && target.latestAttempt.id !== target.lastSuccessful?.id));
21
+ const shipState = blocked
22
+ ? 'needs-attention'
23
+ : targets.length && successfulTargets === targets.length
24
+ ? 'recorded'
25
+ : 'not-recorded';
26
+ return {
27
+ supportedConfiguration,
28
+ init: {
29
+ state: !supportedConfiguration
30
+ ? 'unavailable'
31
+ : inspection.readiness.state === 'available' && inspection.readiness.data.localReady
32
+ ? 'configured'
33
+ : 'needs-attention',
34
+ message: !supportedConfiguration
35
+ ? 'No supported Anhedral stack configuration found. Registering a folder does not adopt its application.'
36
+ : 'Anhedral stack configuration recorded. Local checks describe source structure, not feature completeness.',
37
+ },
38
+ auth: {
39
+ state: 'not-checked',
40
+ providers: inspection.setupProviders.state === 'available'
41
+ ? inspection.setupProviders.data.map((provider) => provider.id)
42
+ : [],
43
+ accounts,
44
+ message: 'Account references are recorded selections. Provider sessions, permissions and billing eligibility require an explicit access check.',
45
+ },
46
+ ship: {
47
+ state: shipState,
48
+ successfulTargets,
49
+ totalTargets: targets.length,
50
+ message: blocked
51
+ ? 'Review incomplete, conflicting or deletion evidence before shipping. Prior successes remain history.'
52
+ : shipState === 'recorded'
53
+ ? 'Success receipts exist for the recorded targets. Current source, live health and product behavior require separate verification.'
54
+ : 'No complete set of successful target receipts is recorded. Review the delivery plan before provisioning or deploying.',
55
+ },
56
+ };
57
+ }
@@ -9,6 +9,7 @@ export interface ApplicationProject {
9
9
  name: string;
10
10
  ownership: 'customer';
11
11
  provider: 'cloudflare';
12
+ deliveryEngine: 'void' | 'wrangler';
12
13
  accountId: string | null;
13
14
  audience: 'unconfigured' | 'public' | 'private';
14
15
  access?: {
@@ -16,8 +17,11 @@ export interface ApplicationProject {
16
17
  };
17
18
  targets: DeploymentTarget[];
18
19
  }
19
- export type DeliveryRunner = (command: string, args: string[], cwd: string, env: NodeJS.ProcessEnv) => Promise<string>;
20
+ export type DeliveryRunner = (command: string, args: string[], cwd: string, env: NodeJS.ProcessEnv, input?: string) => Promise<string>;
20
21
  export declare function atomicJson(file: string, value: unknown): void;
22
+ export declare function configurationFile(directory: string): string;
23
+ export declare function usesVoid(project: ApplicationProject): boolean;
24
+ export declare function resolveVoidCloudflareConfig(authored: Record<string, unknown>, lock: Record<string, unknown>): Record<string, unknown>;
21
25
  export declare function readConfig(directory: string): Record<string, unknown>;
22
26
  export declare function targetDirectory(root: string, target: DeploymentTarget): string;
23
27
  export declare function registerApplication(root: string, extendTargets?: boolean): ApplicationProject;