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
@@ -1,6 +1,9 @@
1
- import { STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE } from '../dependencies.js';
1
+ import { readProjectSection, writeProjectSection, hasProjectSection } from '../project-config.js';
2
+ import { STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE, SECURITY_OVERRIDE_DEPENDENCIES, GLOB_10_OVERRIDE_VERSION, GLOB_11_OVERRIDE_VERSION, BRACE_EXPANSION_1_OVERRIDE_VERSION, BRACE_EXPANSION_2_OVERRIDE_VERSION, BRACE_EXPANSION_5_OVERRIDE_VERSION, } from '../dependencies.js';
3
+ import { writeDependencyAudit } from '../dependency-patches.js';
4
+ import { usesVoidSelection } from '../runtime-policy.js';
5
+ import { VOID_NODE_ENGINE } from '../void.js';
2
6
  import { setPnpmPolicy } from '../pnpm-policy.js';
3
- import { writeSecurityBackports } from '../security-backports.js';
4
7
  import { BOOTSTRAP_COMMAND } from '../registry/bootstrap.js';
5
8
  import { appendGitignore } from '../util.js';
6
9
  import { PACKAGE_MANAGER } from '../dependencies.js';
@@ -9,38 +12,70 @@ import { json, put, readJson, patchPackage, } from './files.js';
9
12
  import { writeSetupDocumentation, workerBuildSuffix } from './documentation.js';
10
13
  import { writeStackDocumentation } from './stack-documentation.js';
11
14
  import { writeEnvironmentExample } from './environment.js';
15
+ import { providerConfigurationTemplate } from '../providers/config.js';
16
+ import { existsSync, readdirSync, rmSync } from 'node:fs';
17
+ import path from 'node:path';
12
18
  function securityOverrides(options) {
13
19
  const has = (value) => options.products.includes(value);
14
20
  return {
15
- ...(has('wxt') ? { '@wxt-dev/module-react>@vitejs/plugin-react': '5.2.0' } : {}),
16
- ...(has('next') || has('vinext') ? { 'sharp@<0.35.5': '0.35.5' } : {}),
21
+ ...(has('wxt')
22
+ ? {
23
+ '@wxt-dev/module-react>@vitejs/plugin-react': SECURITY_OVERRIDE_DEPENDENCIES['@vitejs/plugin-react'],
24
+ }
25
+ : {}),
26
+ ...(has('next') || has('vinext')
27
+ ? { 'sharp@<0.35.5': SECURITY_OVERRIDE_DEPENDENCIES.sharp }
28
+ : {}),
17
29
  ...(options.products.some((product) => ['vinext', 'next', 'expo', 'electron', 'wxt', 'neon', 'd1'].includes(product))
18
- ? { 'source-map-js@<1.2.2': '1.2.2' }
30
+ ? { 'source-map-js@<1.2.2': SECURITY_OVERRIDE_DEPENDENCIES['source-map-js'] }
19
31
  : {}),
20
32
  ...(has('next') && options.hosting === 'cloudflare'
21
- ? { 'glob@>=10.2.0 <10.5.0': '10.5.0', 'glob@>=11.0.0 <11.1.0': '11.1.0' }
33
+ ? {
34
+ 'glob@>=10.2.0 <10.5.0': GLOB_10_OVERRIDE_VERSION,
35
+ 'glob@>=11.0.0 <11.1.0': GLOB_11_OVERRIDE_VERSION,
36
+ }
22
37
  : {}),
23
38
  ...(has('wxt')
24
- ? { 'shell-quote@<1.12.0': '1.12.0', 'tmp@<0.2.7': '0.2.7', 'adm-zip@<0.6.1': '0.6.1' }
39
+ ? {
40
+ 'shell-quote@<1.12.0': SECURITY_OVERRIDE_DEPENDENCIES['shell-quote'],
41
+ 'tmp@<0.2.7': SECURITY_OVERRIDE_DEPENDENCIES.tmp,
42
+ 'adm-zip@<0.6.1': SECURITY_OVERRIDE_DEPENDENCIES['adm-zip'],
43
+ }
25
44
  : {}),
26
- 'baseline-browser-mapping@<2.11.0': '2.11.27',
27
- 'browserslist@<4.28.7': '4.29.3',
45
+ 'baseline-browser-mapping@<2.11.0': SECURITY_OVERRIDE_DEPENDENCIES['baseline-browser-mapping'],
46
+ 'browserslist@<4.28.7': SECURITY_OVERRIDE_DEPENDENCIES.browserslist,
28
47
  ...(((has('next') || has('vinext')) && options.hosting === 'cloudflare') ||
29
48
  has('hono') ||
30
49
  has('electron') ||
31
50
  has('wxt')
32
- ? { 'esbuild@<0.25.0': '0.25.12' }
51
+ ? { 'esbuild@<0.25.0': SECURITY_OVERRIDE_DEPENDENCIES.esbuild }
33
52
  : {}),
34
- 'brace-expansion@<2': '1.1.21',
35
- 'brace-expansion@>=2 <3': '2.1.7',
36
- 'brace-expansion@>=3 <4': '3.0.9',
37
- 'brace-expansion@>=4 <5.0.12': '5.0.12',
53
+ 'brace-expansion@<2': BRACE_EXPANSION_1_OVERRIDE_VERSION,
54
+ 'brace-expansion@>=2 <3': BRACE_EXPANSION_2_OVERRIDE_VERSION,
55
+ 'brace-expansion@>=4 <5.0.12': BRACE_EXPANSION_5_OVERRIDE_VERSION,
38
56
  };
39
57
  }
40
58
  function writeTurboConfiguration(root, registry) {
41
- const turbo = readJson(root, 'turbo.json');
59
+ const turbo = existsSync(path.join(root, 'turbo.json'))
60
+ ? readJson(root, 'turbo.json')
61
+ : { tasks: {} };
62
+ turbo.$schema = 'https://turbo.build/schema.json';
63
+ turbo.globalDependencies = [
64
+ ...new Set([
65
+ ...(turbo.globalDependencies ?? []),
66
+ '**/.env',
67
+ '**/.env.*',
68
+ '**/.dev.vars',
69
+ '**/.dev.vars.*',
70
+ ]),
71
+ ];
42
72
  turbo.globalEnv = [
43
- ...new Set([...(turbo.globalEnv ?? []), ...registry.items.flatMap((item) => item.environment)]),
73
+ ...new Set([
74
+ ...(turbo.globalEnv ?? []),
75
+ 'VOID_CLOUDFLARE_DEPLOY_BUILD',
76
+ 'npm_execpath',
77
+ ...registry.items.flatMap((item) => item.environment),
78
+ ]),
44
79
  ].sort();
45
80
  turbo.tasks = {
46
81
  ...turbo.tasks,
@@ -48,10 +83,22 @@ function writeTurboConfiguration(root, registry) {
48
83
  lint: { ...turbo.tasks.lint, dependsOn: ['^lint'] },
49
84
  typecheck: { ...turbo.tasks.typecheck, dependsOn: ['^typecheck'] },
50
85
  test: { dependsOn: ['^build'], outputs: ['coverage/**'] },
86
+ 'db:generate': { cache: false },
87
+ 'db:migrate': {
88
+ cache: false,
89
+ passThroughEnv: ['CLOUDFLARE_API_TOKEN', 'CLOUDFLARE_ACCOUNT_ID'],
90
+ },
51
91
  build: {
52
92
  ...turbo.tasks.build,
53
93
  dependsOn: [...new Set(['^build', ...(turbo.tasks.build?.dependsOn ?? [])])],
54
- outputs: ['.next/**', '!.next/cache/**', '.open-next/**', 'dist/**', '.output/**'],
94
+ outputs: [
95
+ '.next/**',
96
+ '!.next/cache/**',
97
+ '!.next/dev/**',
98
+ '.open-next/**',
99
+ 'dist/**',
100
+ '.output/**',
101
+ ],
55
102
  },
56
103
  };
57
104
  json(root, 'turbo.json', turbo);
@@ -63,7 +110,11 @@ export function writeStandardRoot(root, options, registry, updating = false) {
63
110
  name: options.name,
64
111
  private: true,
65
112
  packageManager: PACKAGE_MANAGER,
66
- engines: { node: WORKSPACE_NODE_ENGINE },
113
+ engines: {
114
+ node: usesVoidSelection(options.products, options.hosting)
115
+ ? VOID_NODE_ENGINE
116
+ : WORKSPACE_NODE_ENGINE,
117
+ },
67
118
  scripts: {
68
119
  dev: 'turbo dev',
69
120
  build: 'turbo build',
@@ -73,18 +124,25 @@ export function writeStandardRoot(root, options, registry, updating = false) {
73
124
  lint: 'turbo lint',
74
125
  typecheck: 'turbo typecheck',
75
126
  test: 'turbo test',
127
+ ...(has('neon') || has('d1')
128
+ ? {
129
+ 'db:generate': 'turbo run db:generate --filter=@workspace/db',
130
+ 'db:migrate': 'turbo run db:migrate --filter=@workspace/db',
131
+ }
132
+ : {}),
76
133
  audit: 'node scripts/audit.mjs',
77
134
  'audit:full': 'fallow --fail-on-issues',
78
- 'audit:deps': 'node scripts/security/audit-deps.mjs',
135
+ 'audit:deps': 'node scripts/audit-deps.mjs',
79
136
  check: `pnpm lint && pnpm typecheck && pnpm run audit && pnpm audit:deps && pnpm test && pnpm build${workerBuildSuffix(options)}`,
80
137
  },
81
- devDependencies: { fallow: STACK_DEPENDENCIES['fallow'] },
138
+ devDependencies: { turbo: STACK_DEPENDENCIES['turbo'], fallow: STACK_DEPENDENCIES['fallow'] },
82
139
  // Upstream starter lockfiles can retain vulnerable transitive versions. Keep fixes within compatible majors.
83
140
  pnpm: {
84
141
  ...existing.pnpm,
85
142
  overrides: { ...existing.pnpm?.overrides, ...securityOverrides(options) },
86
143
  },
87
144
  });
145
+ writeDependencyAudit(root, updating);
88
146
  put(root, 'scripts/audit.mjs', `import { spawnSync } from 'node:child_process';
89
147
  const base = process.env.AUDIT_BASE;
90
148
  const hasBase = base || ['origin/main', 'main'].find((ref) => spawnSync('git', ['rev-parse', '--verify', ref], { stdio: 'ignore' }).status === 0);
@@ -96,7 +154,15 @@ if (result.error) throw result.error;
96
154
  process.exitCode = result.status ?? 1;
97
155
  `);
98
156
  json(root, '.fallowrc.json', {
99
- ...(has('electron') ? { entry: ['apps/desktop/src/main/preload.cts'] } : {}),
157
+ // Void loads these contracts outside the JavaScript import graph. Declare
158
+ // them as roots so their application dependencies remain fully audited.
159
+ entry: [
160
+ 'apps/*/void.config.ts',
161
+ 'apps/*/env.ts',
162
+ 'apps/*/src/void-entry.ts',
163
+ 'apps/*/crons/**/*.{ts,mts,js,mjs}',
164
+ ...(has('electron') ? ['apps/desktop/src/main/preload.cts'] : []),
165
+ ],
100
166
  // Expo web export and NativeWind load these runtime dependencies dynamically.
101
167
  ...(has('expo')
102
168
  ? {
@@ -109,9 +175,16 @@ process.exitCode = result.status ?? 1;
109
175
  }
110
176
  : {}),
111
177
  ignorePatterns: [
178
+ // Maintained bundled tooling is regression-tested in the CLI repository;
179
+ // app audits cover customer code without re-auditing vendored CLI helpers.
180
+ 'scripts/audit.mjs',
181
+ 'scripts/audit-deps.mjs',
182
+ 'scripts/void-migrations.mjs',
183
+ 'scripts/prepare-void-migrations.mjs',
112
184
  '**/next-env.d.ts',
113
185
  '**/.next/**',
114
186
  '**/.open-next/**',
187
+ '**/.vinext/**',
115
188
  '**/.wrangler/**',
116
189
  '**/dist/**',
117
190
  '**/worker-configuration.d.ts',
@@ -120,6 +193,8 @@ process.exitCode = result.status ?? 1;
120
193
  });
121
194
  writeTurboConfiguration(root, registry);
122
195
  setPnpmPolicy(root, {
196
+ ...(!updating ? { packages: ['apps/*', 'packages/*'] } : {}),
197
+ sharedWorkspaceLockfile: true,
123
198
  allowBuilds: undefined,
124
199
  onlyBuiltDependencies: [
125
200
  'esbuild',
@@ -129,11 +204,30 @@ process.exitCode = result.status ?? 1;
129
204
  ...(has('electron') ? ['electron'] : []),
130
205
  ],
131
206
  });
132
- writeSecurityBackports(root);
207
+ // Upstream app/package lockfiles would create competing dependency authorities.
208
+ if (!updating) {
209
+ for (const parent of ['apps', 'packages']) {
210
+ const directory = path.join(root, parent);
211
+ if (!existsSync(directory))
212
+ continue;
213
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
214
+ if (!entry.isDirectory())
215
+ continue;
216
+ for (const lock of ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock'])
217
+ rmSync(path.join(directory, entry.name, lock), { force: true });
218
+ }
219
+ }
220
+ for (const lock of ['package-lock.json', 'yarn.lock'])
221
+ rmSync(path.join(root, lock), { force: true });
222
+ }
133
223
  appendGitignore(root, [
134
224
  'node_modules/',
135
225
  '.open-next/',
226
+ '.vinext/',
136
227
  '.wrangler/',
228
+ '.void/',
229
+ '.void-wrangler.jsonc',
230
+ '/apps/*/db/migrations/',
137
231
  '.dev.vars',
138
232
  '.dev.vars.*',
139
233
  '!.dev.vars.example',
@@ -146,13 +240,13 @@ process.exitCode = result.status ?? 1;
146
240
  ]);
147
241
  writeEnvironmentExample(root, registry);
148
242
  writeStackDocumentation(root, registry);
149
- json(root, 'anhedral.standard.json', {
243
+ writeProjectSection(root, 'standard', {
150
244
  schemaVersion: 1,
151
245
  standard: 'anhedral-application-stack',
152
246
  products: options.products,
153
247
  hosting: has('next') || has('vinext') ? options.hosting : null,
154
248
  bootstrap: updating
155
- ? readJson(root, 'anhedral.standard.json').bootstrap
249
+ ? readProjectSection(root, 'standard').bootstrap
156
250
  : {
157
251
  command: BOOTSTRAP_COMMAND.join(' '),
158
252
  upstreamPackageManager: existing.packageManager,
@@ -160,7 +254,15 @@ process.exitCode = result.status ?? 1;
160
254
  status: 'starter',
161
255
  resourcesProvisioned: false,
162
256
  });
163
- json(root, 'anhedral.setup.json', createSetupPlan({ ...options, dryRun: false }, registry));
257
+ writeProjectSection(root, 'setup', createSetupPlan({ ...options, dryRun: false }, registry));
258
+ const providers = providerConfigurationTemplate(options.products, options.name);
259
+ const prior = updating && hasProjectSection(root, 'providers')
260
+ ? readProjectSection(root, 'providers')
261
+ : undefined;
262
+ writeProjectSection(root, 'providers', {
263
+ ...providers,
264
+ providers: { ...providers.providers, ...prior?.providers },
265
+ });
164
266
  if (!updating)
165
267
  writeSetupDocumentation(root, options);
166
268
  }
@@ -0,0 +1,29 @@
1
+ import type { CloudflareRequest } from './cloudflare.js';
2
+ export interface DeletionPlan {
3
+ token: string;
4
+ name: string;
5
+ accountId: string;
6
+ resourceId: string;
7
+ kind: string;
8
+ applications: string[];
9
+ expiresAt: string;
10
+ impact: string;
11
+ }
12
+ export declare class ServiceDeletionStore {
13
+ readonly directory: string;
14
+ constructor(directory: string);
15
+ plan(root: string, key: string, request: CloudflareRequest): Promise<DeletionPlan>;
16
+ execute(root: string, key: string, token: string, typedName: string, request: CloudflareRequest): Promise<{
17
+ state: "deleted";
18
+ resourceId: string;
19
+ message: string;
20
+ } | {
21
+ state: "uncertain";
22
+ resourceId: string;
23
+ message: string;
24
+ }>;
25
+ }
26
+ export declare function assertNoDeletedServices(root: string, resources: {
27
+ kind: string;
28
+ name: string;
29
+ }[]): void;
@@ -0,0 +1,195 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { existsSync, mkdirSync, realpathSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { z } from 'zod';
5
+ import { readBoundedFile } from './bounded-file.js';
6
+ import { atomicJson, readApplication, withApplicationLock } from './project-state.js';
7
+ import { inspectApplication } from './project-inspector.js';
8
+ import { resolveService } from './service-descriptor.js';
9
+ import { observeService, record, serviceEndpoint } from './service-readers.js';
10
+ const digest = (value) => createHash('sha256').update(value).digest('hex');
11
+ const actionSchema = z
12
+ .object({
13
+ schemaVersion: z.literal(1),
14
+ root: z.string(),
15
+ serviceKey: z.string().max(1024),
16
+ fingerprint: z.string().regex(/^[a-f0-9]{64}$/),
17
+ name: z.string().max(256),
18
+ expiresAt: z.number(),
19
+ state: z.enum(['prepared', 'pending', 'deleted', 'uncertain', 'rejected']),
20
+ })
21
+ .strict();
22
+ function fingerprint(root, service) {
23
+ const inspection = inspectApplication(root);
24
+ return digest(JSON.stringify({
25
+ service,
26
+ project: readApplication(root),
27
+ configuration: inspection.configuration,
28
+ receipts: inspection.cloudflareResources,
29
+ }));
30
+ }
31
+ async function assertDeletionScope(root, service, request) {
32
+ if (!['d1', 'kv'].includes(service.kind) ||
33
+ service.ownership !== 'created' ||
34
+ !service.name ||
35
+ service.applications.length > 1)
36
+ throw new Error('Deletion requires a supported, recorded project-created resource with at most one owning application. Reused, shared, or unverified resources cannot be deleted here.');
37
+ const observation = await observeService(service, request);
38
+ if (observation.state !== 'available' || observation.name !== service.name)
39
+ throw new Error('The exact resource identity must be confirmed before deletion.');
40
+ const scripts = await request('GET', '/workers/scripts?per_page=100');
41
+ if (!Array.isArray(scripts.result) ||
42
+ scripts.result.length >= 100 ||
43
+ (scripts.result_info?.total_pages ?? 1) > 1)
44
+ throw new Error('Worker dependency listing is incomplete; deletion is blocked.');
45
+ const project = readApplication(root);
46
+ const allowed = new Set(project.targets
47
+ .filter((target) => service.applications.includes(target.directory))
48
+ .map((target) => target.workerName));
49
+ for (const raw of scripts.result) {
50
+ const script = record(raw);
51
+ if (typeof script.id !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,62}$/.test(script.id))
52
+ throw new Error('Worker dependency identity is unavailable.');
53
+ const settings = record((await request('GET', `/workers/scripts/${script.id}/settings`)).result);
54
+ if (!Array.isArray(settings.bindings) || settings.bindings.length > 500)
55
+ throw new Error('Worker dependencies could not be verified.');
56
+ for (const rawBinding of settings.bindings) {
57
+ const binding = record(rawBinding);
58
+ if ((binding.type === 'd1' && typeof binding.id !== 'string') ||
59
+ (binding.type === 'kv_namespace' && typeof binding.namespace_id !== 'string'))
60
+ throw new Error('Worker dependency identities are incomplete.');
61
+ const uses = service.kind === 'd1'
62
+ ? binding.type === 'd1' && binding.id === service.id
63
+ : binding.type === 'kv_namespace' && binding.namespace_id === service.id;
64
+ if (uses && !allowed.has(script.id))
65
+ throw new Error('Another Worker uses this resource. Shared resources cannot be deleted here.');
66
+ }
67
+ }
68
+ }
69
+ export class ServiceDeletionStore {
70
+ directory;
71
+ constructor(directory) {
72
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
73
+ this.directory = realpathSync(directory);
74
+ }
75
+ async plan(root, key, request) {
76
+ root = realpathSync(root);
77
+ const service = resolveService(root, key);
78
+ const before = fingerprint(root, service);
79
+ await assertDeletionScope(root, service, request);
80
+ if (before !== fingerprint(root, resolveService(root, key)))
81
+ throw new Error('Source changed during deletion planning.');
82
+ const token = randomBytes(32).toString('base64url');
83
+ const expiresAt = Date.now() + 5 * 60_000;
84
+ writeFileSync(path.join(this.directory, `${digest(token)}.json`), JSON.stringify({
85
+ schemaVersion: 1,
86
+ root,
87
+ serviceKey: key,
88
+ fingerprint: before,
89
+ name: service.name,
90
+ expiresAt,
91
+ state: 'prepared',
92
+ }), { mode: 0o600, flag: 'wx' });
93
+ return {
94
+ token,
95
+ name: service.name,
96
+ accountId: service.accountId,
97
+ resourceId: service.id,
98
+ kind: service.kind,
99
+ applications: service.applications,
100
+ expiresAt: new Date(expiresAt).toISOString(),
101
+ impact: 'Permanently removes this resource and its stored data. Existing source bindings remain and must be reviewed before shipping.',
102
+ };
103
+ }
104
+ async execute(root, key, token, typedName, request) {
105
+ if (!/^[a-zA-Z0-9_-]{43}$/.test(token))
106
+ throw new Error('Invalid deletion confirmation.');
107
+ const file = path.join(this.directory, `${digest(token)}.json`);
108
+ return withApplicationLock(root, async () => {
109
+ const saved = actionSchema.parse(JSON.parse(readBoundedFile(file, 16384).toString('utf8')));
110
+ root = realpathSync(root);
111
+ if (saved.root !== root ||
112
+ saved.serviceKey !== key ||
113
+ saved.name !== typedName ||
114
+ saved.expiresAt < Date.now() ||
115
+ saved.state !== 'prepared')
116
+ throw new Error('Deletion confirmation is expired, already used, or does not match this resource.');
117
+ const service = resolveService(root, key);
118
+ if (saved.fingerprint !== fingerprint(root, service))
119
+ throw new Error('Service identity or dependencies changed. Review a new deletion plan.');
120
+ await assertDeletionScope(root, service, request);
121
+ if (saved.fingerprint !== fingerprint(root, resolveService(root, key)))
122
+ throw new Error('Source changed before deletion.');
123
+ saved.state = 'pending';
124
+ atomicJson(file, saved);
125
+ const journal = path.join(root, '.anhedral/service-deletions.json');
126
+ const writeReceipt = (state) => {
127
+ let entries = [];
128
+ if (existsSync(journal)) {
129
+ const previous = record(JSON.parse(readBoundedFile(journal, 256 * 1024).toString('utf8')));
130
+ if (previous.projectId !== service.projectId ||
131
+ previous.accountId !== service.accountId ||
132
+ !Array.isArray(previous.entries) ||
133
+ previous.entries.length >= 500)
134
+ throw new Error('Deletion journal is invalid or full.');
135
+ entries = previous.entries.filter((entry) => record(entry).resourceId !== service.id);
136
+ }
137
+ atomicJson(journal, {
138
+ schemaVersion: 1,
139
+ projectId: service.projectId,
140
+ accountId: service.accountId,
141
+ entries: [
142
+ ...entries,
143
+ {
144
+ resourceId: service.id,
145
+ kind: service.kind,
146
+ name: service.name,
147
+ state,
148
+ recordedAt: new Date().toISOString(),
149
+ },
150
+ ],
151
+ });
152
+ };
153
+ writeReceipt('pending');
154
+ try {
155
+ await request('DELETE', serviceEndpoint(service));
156
+ if ((await observeService(service, request)).state !== 'not-found')
157
+ throw new Error('Deletion could not be confirmed.');
158
+ saved.state = 'deleted';
159
+ atomicJson(file, saved);
160
+ writeReceipt('deleted');
161
+ return {
162
+ state: 'deleted',
163
+ resourceId: service.id,
164
+ message: 'Provider confirmed deletion. Review the remaining source bindings before shipping.',
165
+ };
166
+ }
167
+ catch {
168
+ saved.state = 'uncertain';
169
+ atomicJson(file, saved);
170
+ writeReceipt('uncertain');
171
+ return {
172
+ state: 'uncertain',
173
+ resourceId: service.id,
174
+ message: 'Deletion outcome is uncertain. Refresh provider status; no automatic deletion retry is performed.',
175
+ };
176
+ }
177
+ });
178
+ }
179
+ }
180
+ export function assertNoDeletedServices(root, resources) {
181
+ const file = path.join(root, '.anhedral/service-deletions.json');
182
+ if (!existsSync(file))
183
+ return;
184
+ const saved = record(JSON.parse(readBoundedFile(file, 256 * 1024).toString('utf8')));
185
+ const project = readApplication(root);
186
+ if (saved.projectId !== project.id ||
187
+ saved.accountId !== project.accountId ||
188
+ !Array.isArray(saved.entries))
189
+ throw new Error('Deletion history cannot be verified before provisioning.');
190
+ for (const raw of saved.entries) {
191
+ const entry = record(raw);
192
+ if (resources.some((resource) => resource.kind === entry.kind && resource.name === entry.name))
193
+ throw new Error('A selected resource has a recorded deletion attempt. Review source bindings and remote state before provisioning; deleted services are not recreated automatically.');
194
+ }
195
+ }
@@ -0,0 +1,10 @@
1
+ import type { ServiceDescriptor, ServiceKind } from './service-model.js';
2
+ import type { ProjectInspection } from './inspector-model.js';
3
+ export declare function unboundResourceSelectors(inspection: ProjectInspection): string[];
4
+ export declare function resolveService(root: string, key: string): ServiceDescriptor;
5
+ export declare function serviceCapabilities(kind: ServiceKind): {
6
+ status: boolean;
7
+ metrics: boolean;
8
+ data: boolean;
9
+ delete: boolean;
10
+ };
@@ -0,0 +1,78 @@
1
+ import { inspectApplication } from './project-inspector.js';
2
+ import { readApplication } from './project-state.js';
3
+ const kinds = {
4
+ D1: 'd1',
5
+ KV: 'kv',
6
+ R2: 'r2',
7
+ 'Queue producer': 'queue',
8
+ 'Queue consumer': 'queue',
9
+ };
10
+ export function unboundResourceSelectors(inspection) {
11
+ return inspection.cloudflareResources.data
12
+ .filter((resource) => !inspection.configuration.data.bindings.some((binding) => kinds[binding.kind] === resource.kind &&
13
+ (binding.resourceId === resource.id ||
14
+ (['r2', 'queue'].includes(resource.kind) && binding.resourceId === resource.name))))
15
+ .map((resource) => `receipt:${resource.kind}:${resource.id}`);
16
+ }
17
+ export function resolveService(root, key) {
18
+ const inspection = inspectApplication(root);
19
+ const project = readApplication(root);
20
+ if (!project.accountId ||
21
+ inspection.targets.state !== 'available' ||
22
+ inspection.configuration.state !== 'available')
23
+ throw new Error('Validated service configuration and a connected account are required.');
24
+ const target = inspection.targets.data.find((item) => key === `target:${item.provider}:${item.id}` && item.provider === 'cloudflare' && !item.error);
25
+ if (target) {
26
+ const configured = project.targets.find((item) => item.directory === target.application);
27
+ if (!configured)
28
+ throw new Error('Service target identity changed.');
29
+ return {
30
+ key,
31
+ kind: 'worker',
32
+ id: configured.workerName,
33
+ name: configured.workerName,
34
+ accountId: project.accountId,
35
+ projectId: project.id,
36
+ applications: [target.application],
37
+ ownership: 'unknown',
38
+ };
39
+ }
40
+ const binding = inspection.configuration.data.bindings.find((item) => key === `binding:${item.application}:${item.kind}:${item.name}`);
41
+ const record = inspection.cloudflareResources.data.find((item) => key === `receipt:${item.kind}:${item.id}`);
42
+ const kind = binding ? kinds[binding.kind] : record?.kind;
43
+ const id = binding?.resourceId ?? record?.id;
44
+ if (!kind ||
45
+ !['d1', 'kv', 'r2', 'queue'].includes(kind) ||
46
+ !id ||
47
+ !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,254}$/.test(id))
48
+ throw new Error('This service has no supported provider resource identity.');
49
+ const receipt = record ??
50
+ inspection.cloudflareResources.data.find((item) => item.kind === kind &&
51
+ (item.id === id || (['r2', 'queue'].includes(kind) && item.name === id)));
52
+ const references = inspection.configuration.data.bindings.filter((item) => kinds[item.kind] === kind &&
53
+ (item.resourceId === id ||
54
+ (receipt && [receipt.name, receipt.id].includes(item.resourceId ?? ''))));
55
+ return {
56
+ key,
57
+ kind,
58
+ id: receipt?.id ?? id,
59
+ name: receipt?.name ?? (kind === 'r2' ? id : null),
60
+ accountId: project.accountId,
61
+ projectId: project.id,
62
+ applications: [...new Set(references.map((item) => item.application))].sort(),
63
+ ownership: inspection.cloudflareResources.state === 'available' &&
64
+ (receipt?.createdByProject === true || receipt?.reused === false)
65
+ ? 'created'
66
+ : receipt?.reused === true
67
+ ? 'reused'
68
+ : 'unknown',
69
+ };
70
+ }
71
+ export function serviceCapabilities(kind) {
72
+ return {
73
+ status: true,
74
+ metrics: kind === 'd1' || kind === 'worker',
75
+ data: kind === 'd1' || kind === 'kv' || kind === 'r2',
76
+ delete: kind === 'd1' || kind === 'kv',
77
+ };
78
+ }
@@ -0,0 +1,49 @@
1
+ export declare const SERVICE_TOOL_ACTIONS: {
2
+ readonly refresh_service: "status";
3
+ readonly get_service_metrics: "metrics";
4
+ readonly list_service_tables: "tables";
5
+ readonly browse_service_data: "data";
6
+ readonly plan_service_deletion: "delete-plan";
7
+ readonly delete_service: "delete";
8
+ };
9
+ export type ServiceAction = (typeof SERVICE_TOOL_ACTIONS)[keyof typeof SERVICE_TOOL_ACTIONS];
10
+ export type ServiceKind = 'worker' | 'd1' | 'kv' | 'r2' | 'queue';
11
+ export interface ServiceDescriptor {
12
+ key: string;
13
+ kind: ServiceKind;
14
+ id: string;
15
+ name: string | null;
16
+ accountId: string;
17
+ projectId: string;
18
+ applications: string[];
19
+ ownership: 'created' | 'reused' | 'unknown';
20
+ }
21
+ export interface ServiceObservation {
22
+ state: 'available' | 'not-found' | 'permission-required' | 'unavailable';
23
+ fetchedAt: string;
24
+ name?: string;
25
+ storageBytes?: number;
26
+ message: string;
27
+ }
28
+ export interface ServiceMetrics {
29
+ fetchedAt: string;
30
+ start: string;
31
+ end: string;
32
+ timezone: 'UTC';
33
+ source: string;
34
+ sampled: boolean;
35
+ points: {
36
+ time: string;
37
+ values: Record<string, number>;
38
+ }[];
39
+ units: Record<string, string>;
40
+ }
41
+ export interface ServiceData {
42
+ fetchedAt: string;
43
+ columns: string[];
44
+ rows: (string | number | boolean | null)[][];
45
+ offset: number;
46
+ hasMore: boolean;
47
+ masked: boolean;
48
+ nextCursor?: string;
49
+ }
@@ -0,0 +1,8 @@
1
+ export const SERVICE_TOOL_ACTIONS = {
2
+ refresh_service: 'status',
3
+ get_service_metrics: 'metrics',
4
+ list_service_tables: 'tables',
5
+ browse_service_data: 'data',
6
+ plan_service_deletion: 'delete-plan',
7
+ delete_service: 'delete',
8
+ };