anhedral 0.10.1 → 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 (183) hide show
  1. package/README.md +79 -124
  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 +284 -163
  9. package/dist/capabilities.d.ts +4 -4
  10. package/dist/capabilities.js +6 -2
  11. package/dist/capability-contract.d.ts +47 -0
  12. package/dist/capability-contract.js +153 -0
  13. package/dist/catalog-model.d.ts +24 -0
  14. package/dist/catalog-model.js +1 -0
  15. package/dist/catalog-registration.d.ts +16 -0
  16. package/dist/catalog-registration.js +22 -0
  17. package/dist/catalog-snapshot.d.ts +5 -0
  18. package/dist/catalog-snapshot.js +97 -0
  19. package/dist/cli-arguments.d.ts +16 -0
  20. package/dist/cli-arguments.js +115 -0
  21. package/dist/cli-output.d.ts +8 -0
  22. package/dist/cli-output.js +236 -0
  23. package/dist/cloudflare.d.ts +14 -3
  24. package/dist/cloudflare.js +196 -36
  25. package/dist/command-schema.d.ts +21 -0
  26. package/dist/command-schema.js +418 -0
  27. package/dist/delivery.d.ts +12 -5
  28. package/dist/delivery.js +173 -39
  29. package/dist/dependencies.d.ts +24 -0
  30. package/dist/dependencies.js +48 -0
  31. package/dist/dependency-patches.d.ts +7 -0
  32. package/dist/dependency-patches.js +125 -0
  33. package/dist/index.d.ts +26 -1
  34. package/dist/index.js +17 -1
  35. package/dist/inspector-model.d.ts +123 -0
  36. package/dist/inspector-model.js +1 -0
  37. package/dist/integration-service-readers.d.ts +13 -0
  38. package/dist/integration-service-readers.js +173 -0
  39. package/dist/lifecycle-model.d.ts +15 -0
  40. package/dist/lifecycle-model.js +20 -0
  41. package/dist/lifecycle.d.ts +11 -0
  42. package/dist/lifecycle.js +91 -0
  43. package/dist/mobile-delivery.d.ts +100 -0
  44. package/dist/mobile-delivery.js +319 -0
  45. package/dist/neon-service-data.d.ts +8 -0
  46. package/dist/neon-service-data.js +117 -0
  47. package/dist/platforms/mobile.js +8 -5
  48. package/dist/pnpm-policy.d.ts +2 -2
  49. package/dist/pnpm-policy.js +19 -45
  50. package/dist/project-catalog.d.ts +41 -0
  51. package/dist/project-catalog.js +288 -0
  52. package/dist/project-config.d.ts +14 -0
  53. package/dist/project-config.js +89 -0
  54. package/dist/project-inspector.d.ts +4 -0
  55. package/dist/project-inspector.js +702 -0
  56. package/dist/project-lifecycle.d.ts +25 -0
  57. package/dist/project-lifecycle.js +57 -0
  58. package/dist/project-state.d.ts +22 -1
  59. package/dist/project-state.js +361 -27
  60. package/dist/provider-auth.d.ts +41 -0
  61. package/dist/provider-auth.js +209 -0
  62. package/dist/provider-readiness.js +27 -10
  63. package/dist/providers/adapters.d.ts +17 -0
  64. package/dist/providers/adapters.js +272 -0
  65. package/dist/providers/api.d.ts +29 -0
  66. package/dist/providers/api.js +253 -0
  67. package/dist/providers/config.d.ts +15 -0
  68. package/dist/providers/config.js +182 -0
  69. package/dist/providers/definitions.d.ts +318 -0
  70. package/dist/providers/definitions.js +127 -0
  71. package/dist/providers/provision.d.ts +24 -0
  72. package/dist/providers/provision.js +76 -0
  73. package/dist/providers/receipts.d.ts +20 -0
  74. package/dist/providers/receipts.js +66 -0
  75. package/dist/providers/recovery-verification.d.ts +7 -0
  76. package/dist/providers/recovery-verification.js +112 -0
  77. package/dist/providers/recovery.d.ts +30 -0
  78. package/dist/providers/recovery.js +34 -0
  79. package/dist/providers/runtime.d.ts +10 -0
  80. package/dist/providers/runtime.js +254 -0
  81. package/dist/providers/schema.d.ts +28 -0
  82. package/dist/providers/schema.js +49 -0
  83. package/dist/providers/state.d.ts +55 -0
  84. package/dist/providers/state.js +289 -0
  85. package/dist/provision.d.ts +10 -1
  86. package/dist/provision.js +91 -4
  87. package/dist/r2-service-data.d.ts +2 -0
  88. package/dist/r2-service-data.js +136 -0
  89. package/dist/readiness.js +9 -13
  90. package/dist/registry/add.d.ts +6 -0
  91. package/dist/registry/add.js +93 -22
  92. package/dist/registry/commands.d.ts +3 -2
  93. package/dist/registry/commands.js +52 -15
  94. package/dist/registry/options.d.ts +1 -1
  95. package/dist/registry/options.js +5 -4
  96. package/dist/registry/preview.d.ts +11 -0
  97. package/dist/registry/preview.js +91 -0
  98. package/dist/registry/receipt.d.ts +1 -0
  99. package/dist/registry/receipt.js +19 -4
  100. package/dist/registry/resolve.js +5 -1
  101. package/dist/registry/usage.d.ts +10 -0
  102. package/dist/registry/usage.js +18 -37
  103. package/dist/render.d.ts +2 -0
  104. package/dist/render.js +6 -0
  105. package/dist/runtime-policy.d.ts +4 -0
  106. package/dist/runtime-policy.js +21 -0
  107. package/dist/scaffold/auth.js +3 -19
  108. package/dist/scaffold/bootstrap.js +2 -2
  109. package/dist/scaffold/compose.js +9 -3
  110. package/dist/scaffold/database.js +107 -25
  111. package/dist/scaffold/documentation.js +18 -13
  112. package/dist/scaffold/lint.d.ts +4 -0
  113. package/dist/scaffold/lint.js +56 -0
  114. package/dist/scaffold/neon-realtime.d.ts +2 -0
  115. package/dist/scaffold/neon-realtime.js +97 -0
  116. package/dist/scaffold/stack-documentation.js +1 -1
  117. package/dist/scaffold/void.d.ts +4 -0
  118. package/dist/scaffold/void.js +256 -0
  119. package/dist/scaffold/web.js +7 -1
  120. package/dist/scaffold/workspace.js +127 -25
  121. package/dist/service-deletion.d.ts +29 -0
  122. package/dist/service-deletion.js +195 -0
  123. package/dist/service-descriptor.d.ts +10 -0
  124. package/dist/service-descriptor.js +78 -0
  125. package/dist/service-model.d.ts +49 -0
  126. package/dist/service-model.js +8 -0
  127. package/dist/service-operations.d.ts +29 -0
  128. package/dist/service-operations.js +78 -0
  129. package/dist/service-readers.d.ts +8 -0
  130. package/dist/service-readers.js +247 -0
  131. package/dist/services-command.d.ts +39 -0
  132. package/dist/services-command.js +100 -0
  133. package/dist/ship.d.ts +348 -0
  134. package/dist/ship.js +237 -0
  135. package/dist/stack-registry.d.ts +4 -2
  136. package/dist/stack-registry.js +48 -12
  137. package/dist/standard.d.ts +2 -1
  138. package/dist/standard.js +33 -14
  139. package/dist/transaction.d.ts +2 -0
  140. package/dist/transaction.js +10 -0
  141. package/dist/util.js +17 -2
  142. package/dist/vercel.d.ts +5 -3
  143. package/dist/vercel.js +96 -14
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/dist/vinext.d.ts +1 -0
  147. package/dist/vinext.js +13 -1
  148. package/dist/void-execution.d.ts +10 -0
  149. package/dist/void-execution.js +94 -0
  150. package/dist/void-migrations.d.ts +6 -0
  151. package/dist/void-migrations.js +110 -0
  152. package/dist/void-state.d.ts +16 -0
  153. package/dist/void-state.js +65 -0
  154. package/dist/void.d.ts +3 -0
  155. package/dist/void.js +5 -0
  156. package/docs/cli-design.md +67 -0
  157. package/docs/delivery-workflow.md +32 -17
  158. package/docs/plugin-ui.md +102 -0
  159. package/docs/provider-configuration.md +116 -0
  160. package/docs/stack-standard.md +175 -0
  161. package/docs/void-verification.md +185 -0
  162. package/package.json +29 -23
  163. package/assets/anhedral-cli-init-technical.svg +0 -322
  164. package/assets/anhedral-cli-init.svg +0 -322
  165. package/assets/anhedral-mark.svg +0 -4
  166. package/assets/anhedral.svg +0 -4
  167. package/assets/favicon.ico +0 -0
  168. package/assets/security/LICENSES.txt +0 -63
  169. package/assets/security/audit-deps.mjs +0 -300
  170. package/assets/security/braces-regression.mjs +0 -102
  171. package/assets/security/braces@3.0.3.patch +0 -285
  172. package/assets/security/decode-uri-component@0.2.2.patch +0 -149
  173. package/assets/security/decoder-regression.mjs +0 -37
  174. package/assets/security/forge-regression.mjs +0 -46
  175. package/assets/security/manifest.json +0 -53
  176. package/assets/security/node-forge@1.4.0.patch +0 -26
  177. package/dist/managed-hosting.d.ts +0 -49
  178. package/dist/managed-hosting.js +0 -373
  179. package/dist/security-backports.d.ts +0 -3
  180. package/dist/security-backports.js +0 -26
  181. package/docs/application-stack-standard.md +0 -104
  182. package/docs/managed-hosting-architecture.md +0 -87
  183. package/docs/sponsorships.md +0 -25
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ import type { ProjectInspection } from './inspector-model.js';
2
+ /** Local read-only inspection. Each section has bounded allowlisted inputs and an
3
+ * independent error state. No secrets, commands, provider calls, or migrations. */
4
+ export declare function inspectApplication(root: string): ProjectInspection;