anhedral 0.13.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/README.md +23 -229
  2. package/assets/patches/audit-deps.mjs +12 -2
  3. package/assets/stack/ai-schema.ts.txt +5 -0
  4. package/assets/stack/ai.ts.txt +30 -0
  5. package/assets/stack/api-index.ts.txt +15 -0
  6. package/assets/stack/auth-features.ts.txt +4 -0
  7. package/assets/stack/auth-journal.json.txt +13 -0
  8. package/assets/stack/auth-migration.sql.txt +53 -0
  9. package/assets/stack/auth-routes.ts.txt +11 -0
  10. package/assets/stack/auth-schema.ts.txt +64 -0
  11. package/assets/stack/auth-snapshot.json.txt +346 -0
  12. package/assets/stack/auth.ts.txt +32 -0
  13. package/assets/stack/billing-mode.ts.txt +8 -0
  14. package/assets/stack/billing-schema.ts.txt +11 -0
  15. package/assets/stack/desktop.rs.txt +21 -0
  16. package/assets/stack/entitlement-guard.ts.txt +32 -0
  17. package/assets/stack/entitlements.ts.txt +8 -0
  18. package/assets/stack/events-schema.ts.txt +12 -0
  19. package/assets/stack/events.ts.txt +59 -0
  20. package/assets/stack/mobile-auth.ts.txt +25 -0
  21. package/assets/stack/mobile-billing.tsx.txt +63 -0
  22. package/assets/stack/mobile-session.tsx.txt +83 -0
  23. package/assets/stack/native-button.tsx.txt +108 -0
  24. package/assets/stack/native-global.css.txt +4 -0
  25. package/assets/stack/native-lib-utils.ts.txt +5 -0
  26. package/assets/stack/native-metro.config.js.txt +6 -0
  27. package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
  28. package/assets/stack/native-tailwind.config.js.txt +73 -0
  29. package/assets/stack/native-text.tsx.txt +89 -0
  30. package/assets/stack/purchases.ts.txt +65 -0
  31. package/assets/stack/revenuecat.ts.txt +88 -0
  32. package/assets/stack/rtc-schema.ts.txt +10 -0
  33. package/assets/stack/rtc.ts.txt +122 -0
  34. package/assets/stack/security.ts.txt +31 -0
  35. package/assets/stack/storage.ts.txt +36 -0
  36. package/assets/stack/stripe.ts.txt +126 -0
  37. package/assets/stack/web-sign-in.tsx.txt +51 -0
  38. package/assets/ui/LICENSE.react-native-reusables +21 -0
  39. package/assets/ui/LICENSE.shadcn +21 -0
  40. package/assets/ui/UPSTREAM.json +39 -0
  41. package/assets/ui/catalog.json +891 -0
  42. package/assets/ui/extensions/registry.json +6 -0
  43. package/assets/ui/native/_controls.tsx +521 -0
  44. package/assets/ui/native/_core.tsx +118 -0
  45. package/assets/ui/native/_data.tsx +200 -0
  46. package/assets/ui/native/_display.tsx +453 -0
  47. package/assets/ui/native/_feedback.tsx +242 -0
  48. package/assets/ui/native/_legacy-dialog.tsx +38 -0
  49. package/assets/ui/native/_motion.tsx +520 -0
  50. package/assets/ui/native/_overlay.tsx +402 -0
  51. package/assets/ui/native/_selection.tsx +366 -0
  52. package/assets/ui/native/accordion.tsx +1 -0
  53. package/assets/ui/native/alert-dialog.tsx +11 -0
  54. package/assets/ui/native/alert.tsx +1 -0
  55. package/assets/ui/native/aspect-ratio.tsx +1 -0
  56. package/assets/ui/native/attachment.tsx +8 -0
  57. package/assets/ui/native/avatar.tsx +8 -0
  58. package/assets/ui/native/badge.tsx +1 -0
  59. package/assets/ui/native/breadcrumb.tsx +9 -0
  60. package/assets/ui/native/bubble.tsx +1 -0
  61. package/assets/ui/native/button-group.tsx +1 -0
  62. package/assets/ui/native/button.tsx +86 -0
  63. package/assets/ui/native/calendar.tsx +170 -0
  64. package/assets/ui/native/card.tsx +44 -0
  65. package/assets/ui/native/carousel.tsx +1 -0
  66. package/assets/ui/native/chart.tsx +193 -0
  67. package/assets/ui/native/checkbox.tsx +1 -0
  68. package/assets/ui/native/code-block.tsx +137 -0
  69. package/assets/ui/native/collapsible.tsx +1 -0
  70. package/assets/ui/native/combobox.tsx +1 -0
  71. package/assets/ui/native/command.tsx +11 -0
  72. package/assets/ui/native/context-menu.tsx +16 -0
  73. package/assets/ui/native/data-table.tsx +1 -0
  74. package/assets/ui/native/date-picker.tsx +43 -0
  75. package/assets/ui/native/dialog.tsx +15 -0
  76. package/assets/ui/native/direction.tsx +1 -0
  77. package/assets/ui/native/drawer.tsx +10 -0
  78. package/assets/ui/native/dropdown-menu.tsx +16 -0
  79. package/assets/ui/native/empty.tsx +8 -0
  80. package/assets/ui/native/field.tsx +13 -0
  81. package/assets/ui/native/hover-card.tsx +1 -0
  82. package/assets/ui/native/input-group.tsx +8 -0
  83. package/assets/ui/native/input-otp.tsx +1 -0
  84. package/assets/ui/native/input.tsx +28 -0
  85. package/assets/ui/native/item.tsx +12 -0
  86. package/assets/ui/native/kbd.tsx +1 -0
  87. package/assets/ui/native/label.tsx +4 -0
  88. package/assets/ui/native/layout.tsx +26 -0
  89. package/assets/ui/native/marker.tsx +1 -0
  90. package/assets/ui/native/menubar.tsx +17 -0
  91. package/assets/ui/native/message-scroller.tsx +6 -0
  92. package/assets/ui/native/message.tsx +10 -0
  93. package/assets/ui/native/native-select.tsx +1 -0
  94. package/assets/ui/native/navigation-menu.tsx +10 -0
  95. package/assets/ui/native/pagination.tsx +9 -0
  96. package/assets/ui/native/popover.tsx +1 -0
  97. package/assets/ui/native/progress.tsx +1 -0
  98. package/assets/ui/native/questionnaire.tsx +130 -0
  99. package/assets/ui/native/radio-group.tsx +1 -0
  100. package/assets/ui/native/registry.json +1103 -0
  101. package/assets/ui/native/resizable.tsx +1 -0
  102. package/assets/ui/native/scroll-area.tsx +1 -0
  103. package/assets/ui/native/select.tsx +11 -0
  104. package/assets/ui/native/separator.tsx +1 -0
  105. package/assets/ui/native/sheet.tsx +10 -0
  106. package/assets/ui/native/sidebar.tsx +22 -0
  107. package/assets/ui/native/skeleton.tsx +1 -0
  108. package/assets/ui/native/slider.tsx +1 -0
  109. package/assets/ui/native/spinner.tsx +1 -0
  110. package/assets/ui/native/switch.tsx +1 -0
  111. package/assets/ui/native/table.tsx +10 -0
  112. package/assets/ui/native/tabs.tsx +1 -0
  113. package/assets/ui/native/text.tsx +20 -0
  114. package/assets/ui/native/textarea.tsx +1 -0
  115. package/assets/ui/native/theme-switcher.tsx +22 -0
  116. package/assets/ui/native/toast.tsx +11 -0
  117. package/assets/ui/native/toggle-group.tsx +1 -0
  118. package/assets/ui/native/toggle.tsx +1 -0
  119. package/assets/ui/native/tooltip.tsx +1 -0
  120. package/assets/ui/native/trace.tsx +20 -0
  121. package/assets/ui/native/typography.tsx +15 -0
  122. package/assets/ui/theme-storage.ts +25 -0
  123. package/assets/ui/theme.tsx +66 -0
  124. package/assets/ui/web/button.tsx +59 -0
  125. package/assets/ui/web/input.tsx +21 -0
  126. package/assets/ui/web/label.tsx +19 -0
  127. package/dist/bin.js +7 -12
  128. package/dist/capabilities.d.ts +4 -33
  129. package/dist/capabilities.js +2 -84
  130. package/dist/capability-catalog.d.ts +83 -0
  131. package/dist/capability-catalog.js +121 -0
  132. package/dist/capability-command.d.ts +3 -0
  133. package/dist/capability-command.js +188 -0
  134. package/dist/capability-editor.d.ts +17 -0
  135. package/dist/capability-editor.js +97 -0
  136. package/dist/capability-recipes.d.ts +4 -0
  137. package/dist/capability-recipes.js +520 -0
  138. package/dist/capability-references.d.ts +4 -0
  139. package/dist/capability-references.js +7 -0
  140. package/dist/cli-commands.d.ts +1 -2
  141. package/dist/cli-commands.js +10 -104
  142. package/dist/cli-output.d.ts +1 -2
  143. package/dist/cli-output.js +6 -251
  144. package/dist/command-schema.js +40 -374
  145. package/dist/dependencies.d.ts +34 -62
  146. package/dist/dependencies.js +112 -199
  147. package/dist/index.d.ts +1 -45
  148. package/dist/index.js +1 -30
  149. package/dist/platforms/mobile.js +29 -139
  150. package/dist/platforms/web.d.ts +3 -0
  151. package/dist/platforms/web.js +251 -0
  152. package/dist/project-config.d.ts +2 -13
  153. package/dist/project-config.js +10 -83
  154. package/dist/registry/context.js +0 -1
  155. package/dist/registry/options.js +6 -40
  156. package/dist/registry/resolve.d.ts +3 -4
  157. package/dist/registry/resolve.js +18 -108
  158. package/dist/registry/types.d.ts +1 -7
  159. package/dist/registry/usage.js +3 -9
  160. package/dist/runtime-policy.d.ts +0 -2
  161. package/dist/runtime-policy.js +0 -16
  162. package/dist/scaffold/backend.d.ts +0 -4
  163. package/dist/scaffold/backend.js +1 -189
  164. package/dist/scaffold/bootstrap.d.ts +2 -3
  165. package/dist/scaffold/bootstrap.js +37 -43
  166. package/dist/scaffold/compose.js +2 -14
  167. package/dist/scaffold/database.d.ts +1 -1
  168. package/dist/scaffold/database.js +19 -126
  169. package/dist/scaffold/documentation.d.ts +0 -1
  170. package/dist/scaffold/documentation.js +82 -84
  171. package/dist/scaffold/expo-runtime.d.ts +2 -2
  172. package/dist/scaffold/expo-runtime.js +9 -101
  173. package/dist/scaffold/native-ui.d.ts +2 -0
  174. package/dist/scaffold/native-ui.js +74 -0
  175. package/dist/scaffold/stack-documentation.d.ts +0 -1
  176. package/dist/scaffold/stack-documentation.js +3 -49
  177. package/dist/scaffold/storage.d.ts +2 -0
  178. package/dist/scaffold/storage.js +21 -0
  179. package/dist/scaffold/styling.d.ts +1 -1
  180. package/dist/scaffold/styling.js +20 -28
  181. package/dist/scaffold/workspace.js +63 -199
  182. package/dist/stack-registry.d.ts +2 -58
  183. package/dist/stack-registry.js +22 -446
  184. package/dist/standard.js +7 -24
  185. package/dist/ui-catalog.d.ts +26 -0
  186. package/dist/ui-catalog.js +31 -0
  187. package/dist/ui-command.d.ts +3 -0
  188. package/dist/ui-command.js +219 -0
  189. package/dist/ui-project.d.ts +22 -0
  190. package/dist/ui-project.js +110 -0
  191. package/dist/version.d.ts +1 -1
  192. package/dist/version.js +1 -1
  193. package/docs/anhedral-stack.md +4 -119
  194. package/docs/capabilities.md +110 -0
  195. package/docs/native-ui.md +102 -0
  196. package/docs/software-factory.md +16 -577
  197. package/docs/stack-standard.md +11 -307
  198. package/docs/ui.md +33 -0
  199. package/docs/verification.md +511 -0
  200. package/package.json +26 -27
  201. package/dist/access.d.ts +0 -10
  202. package/dist/access.js +0 -93
  203. package/dist/auth-schema-snapshot.d.ts +0 -346
  204. package/dist/auth-schema-snapshot.js +0 -347
  205. package/dist/auth-schema.d.ts +0 -1
  206. package/dist/auth-schema.js +0 -57
  207. package/dist/capability-contract.d.ts +0 -47
  208. package/dist/capability-contract.js +0 -168
  209. package/dist/catalog-model.d.ts +0 -24
  210. package/dist/catalog-model.js +0 -1
  211. package/dist/catalog-registration.d.ts +0 -16
  212. package/dist/catalog-registration.js +0 -22
  213. package/dist/catalog-snapshot.d.ts +0 -5
  214. package/dist/catalog-snapshot.js +0 -97
  215. package/dist/cli-delivery.d.ts +0 -3
  216. package/dist/cli-delivery.js +0 -172
  217. package/dist/cloudflare.d.ts +0 -25
  218. package/dist/cloudflare.js +0 -226
  219. package/dist/delivery-evidence.d.ts +0 -62
  220. package/dist/delivery-evidence.js +0 -186
  221. package/dist/delivery.d.ts +0 -88
  222. package/dist/delivery.js +0 -570
  223. package/dist/inspector-model.d.ts +0 -123
  224. package/dist/inspector-model.js +0 -1
  225. package/dist/integration-service-readers.d.ts +0 -13
  226. package/dist/integration-service-readers.js +0 -173
  227. package/dist/lifecycle-model.d.ts +0 -15
  228. package/dist/lifecycle-model.js +0 -20
  229. package/dist/lifecycle.d.ts +0 -11
  230. package/dist/lifecycle.js +0 -91
  231. package/dist/management.d.ts +0 -3
  232. package/dist/management.js +0 -47
  233. package/dist/mobile-delivery.d.ts +0 -77
  234. package/dist/mobile-delivery.js +0 -366
  235. package/dist/neon-service-data.d.ts +0 -8
  236. package/dist/neon-service-data.js +0 -117
  237. package/dist/platforms/desktop.d.ts +0 -2
  238. package/dist/platforms/desktop.js +0 -415
  239. package/dist/platforms/extension.d.ts +0 -2
  240. package/dist/platforms/extension.js +0 -328
  241. package/dist/project-catalog.d.ts +0 -41
  242. package/dist/project-catalog.js +0 -288
  243. package/dist/project-inspector.d.ts +0 -4
  244. package/dist/project-inspector.js +0 -702
  245. package/dist/project-lifecycle.d.ts +0 -25
  246. package/dist/project-lifecycle.js +0 -57
  247. package/dist/project-state.d.ts +0 -49
  248. package/dist/project-state.js +0 -563
  249. package/dist/provider-auth.d.ts +0 -41
  250. package/dist/provider-auth.js +0 -215
  251. package/dist/provider-readiness.d.ts +0 -30
  252. package/dist/provider-readiness.js +0 -104
  253. package/dist/providers/adapters.d.ts +0 -17
  254. package/dist/providers/adapters.js +0 -278
  255. package/dist/providers/api.d.ts +0 -29
  256. package/dist/providers/api.js +0 -253
  257. package/dist/providers/config.d.ts +0 -15
  258. package/dist/providers/config.js +0 -182
  259. package/dist/providers/definitions.d.ts +0 -318
  260. package/dist/providers/definitions.js +0 -127
  261. package/dist/providers/provision.d.ts +0 -24
  262. package/dist/providers/provision.js +0 -76
  263. package/dist/providers/receipts.d.ts +0 -20
  264. package/dist/providers/receipts.js +0 -66
  265. package/dist/providers/recovery-verification.d.ts +0 -7
  266. package/dist/providers/recovery-verification.js +0 -112
  267. package/dist/providers/recovery.d.ts +0 -30
  268. package/dist/providers/recovery.js +0 -34
  269. package/dist/providers/runtime.d.ts +0 -10
  270. package/dist/providers/runtime.js +0 -265
  271. package/dist/providers/schema.d.ts +0 -28
  272. package/dist/providers/schema.js +0 -49
  273. package/dist/providers/state.d.ts +0 -55
  274. package/dist/providers/state.js +0 -289
  275. package/dist/provision.d.ts +0 -55
  276. package/dist/provision.js +0 -284
  277. package/dist/r2-service-data.d.ts +0 -2
  278. package/dist/r2-service-data.js +0 -136
  279. package/dist/readiness.d.ts +0 -23
  280. package/dist/readiness.js +0 -122
  281. package/dist/registry/add.d.ts +0 -24
  282. package/dist/registry/add.js +0 -270
  283. package/dist/registry/bootstrap.d.ts +0 -2
  284. package/dist/registry/bootstrap.js +0 -14
  285. package/dist/registry/commands.d.ts +0 -3
  286. package/dist/registry/commands.js +0 -85
  287. package/dist/registry/presets.d.ts +0 -4
  288. package/dist/registry/presets.js +0 -41
  289. package/dist/registry/preview.d.ts +0 -11
  290. package/dist/registry/preview.js +0 -91
  291. package/dist/registry/receipt.d.ts +0 -3
  292. package/dist/registry/receipt.js +0 -68
  293. package/dist/repository.d.ts +0 -24
  294. package/dist/repository.js +0 -96
  295. package/dist/scaffold/auth.d.ts +0 -3
  296. package/dist/scaffold/auth.js +0 -151
  297. package/dist/scaffold/billing-config.d.ts +0 -1
  298. package/dist/scaffold/billing-config.js +0 -73
  299. package/dist/scaffold/billing-contracts.d.ts +0 -2
  300. package/dist/scaffold/billing-contracts.js +0 -48
  301. package/dist/scaffold/billing-providers.d.ts +0 -1
  302. package/dist/scaffold/billing-providers.js +0 -249
  303. package/dist/scaffold/billing-schema.d.ts +0 -1
  304. package/dist/scaffold/billing-schema.js +0 -34
  305. package/dist/scaffold/billing-security.d.ts +0 -1
  306. package/dist/scaffold/billing-security.js +0 -46
  307. package/dist/scaffold/billing-server.d.ts +0 -1
  308. package/dist/scaffold/billing-server.js +0 -139
  309. package/dist/scaffold/billing-store.d.ts +0 -1
  310. package/dist/scaffold/billing-store.js +0 -72
  311. package/dist/scaffold/billing.d.ts +0 -2
  312. package/dist/scaffold/billing.js +0 -216
  313. package/dist/scaffold/cloudflare-services.d.ts +0 -8
  314. package/dist/scaffold/cloudflare-services.js +0 -198
  315. package/dist/scaffold/expo-auth.d.ts +0 -3
  316. package/dist/scaffold/expo-auth.js +0 -192
  317. package/dist/scaffold/expo-billing.d.ts +0 -3
  318. package/dist/scaffold/expo-billing.js +0 -292
  319. package/dist/scaffold/integrations.d.ts +0 -4
  320. package/dist/scaffold/integrations.js +0 -12
  321. package/dist/scaffold/lint.d.ts +0 -4
  322. package/dist/scaffold/lint.js +0 -56
  323. package/dist/scaffold/neon-realtime.d.ts +0 -2
  324. package/dist/scaffold/neon-realtime.js +0 -97
  325. package/dist/scaffold/services.d.ts +0 -5
  326. package/dist/scaffold/services.js +0 -108
  327. package/dist/scaffold/stream.d.ts +0 -2
  328. package/dist/scaffold/stream.js +0 -114
  329. package/dist/scaffold/void.d.ts +0 -4
  330. package/dist/scaffold/void.js +0 -264
  331. package/dist/scaffold/web.d.ts +0 -2
  332. package/dist/scaffold/web.js +0 -130
  333. package/dist/service-deletion.d.ts +0 -29
  334. package/dist/service-deletion.js +0 -195
  335. package/dist/service-descriptor.d.ts +0 -10
  336. package/dist/service-descriptor.js +0 -78
  337. package/dist/service-model.d.ts +0 -49
  338. package/dist/service-model.js +0 -8
  339. package/dist/service-operations.d.ts +0 -29
  340. package/dist/service-operations.js +0 -78
  341. package/dist/service-readers.d.ts +0 -8
  342. package/dist/service-readers.js +0 -247
  343. package/dist/services-command.d.ts +0 -39
  344. package/dist/services-command.js +0 -102
  345. package/dist/ship.d.ts +0 -348
  346. package/dist/ship.js +0 -239
  347. package/dist/vercel-project.d.ts +0 -101
  348. package/dist/vercel-project.js +0 -305
  349. package/dist/vercel.d.ts +0 -67
  350. package/dist/vercel.js +0 -581
  351. package/dist/vinext.d.ts +0 -2
  352. package/dist/vinext.js +0 -86
  353. package/dist/void-execution.d.ts +0 -10
  354. package/dist/void-execution.js +0 -94
  355. package/dist/void-migrations.d.ts +0 -6
  356. package/dist/void-migrations.js +0 -110
  357. package/dist/void-state.d.ts +0 -16
  358. package/dist/void-state.js +0 -65
  359. package/dist/void.d.ts +0 -3
  360. package/dist/void.js +0 -5
@@ -1,563 +0,0 @@
1
- import { hasProjectSection, readProjectSection, writeProjectSection } from './project-config.js';
2
- import { isDeepStrictEqual } from 'node:util';
3
- import { randomUUID } from 'node:crypto';
4
- import { AsyncLocalStorage } from 'node:async_hooks';
5
- import { existsSync, lstatSync, fstatSync, openSync, closeSync, unlinkSync, rmdirSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
6
- import { spawn } from 'node:child_process';
7
- import path from 'node:path';
8
- import { hostname } from 'node:os';
9
- import { readBoundedFile } from './bounded-file.js';
10
- import { validateSetupPlan } from './readiness.js';
11
- import { parse } from 'jsonc-parser';
12
- import { resolveCommand } from './command.js';
13
- const stateDirectory = '.anhedral';
14
- const accountPattern = /^[a-f0-9]{32}$/i;
15
- const workerPattern = /^[a-z0-9][a-z0-9-]{0,62}$/;
16
- export function atomicJson(file, value) {
17
- const temporary = `${file}.${randomUUID()}.tmp`;
18
- try {
19
- writeFileSync(temporary, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 });
20
- renameSync(temporary, file);
21
- }
22
- finally {
23
- rmSync(temporary, { force: true });
24
- }
25
- }
26
- export function configurationFile(directory) {
27
- const canonical = path.join(directory, 'anhedral.cloudflare.json');
28
- return existsSync(canonical) ? canonical : path.join(directory, 'wrangler.jsonc');
29
- }
30
- export function usesVoid(project) {
31
- return project.deliveryEngine === 'void';
32
- }
33
- function mergeVoidConfig(previous, resolved, authored) {
34
- if (isDeepStrictEqual(previous, authored))
35
- return resolved;
36
- if (Array.isArray(previous) && Array.isArray(resolved) && Array.isArray(authored)) {
37
- const identity = (value) => {
38
- if (value && typeof value === 'object')
39
- for (const key of ['binding', 'name', 'tag', 'class_name', 'pattern', 'route']) {
40
- const item = value[key];
41
- if (typeof item === 'string')
42
- return `${key}:${item}`;
43
- }
44
- return JSON.stringify(value);
45
- };
46
- return [
47
- ...authored.map((item) => {
48
- const before = previous.find((entry) => identity(entry) === identity(item));
49
- const after = resolved.find((entry) => identity(entry) === identity(item));
50
- return before !== undefined && after !== undefined
51
- ? mergeVoidConfig(before, after, item)
52
- : item;
53
- }),
54
- ...resolved.filter((item) => !previous.some((entry) => identity(entry) === identity(item)) &&
55
- !authored.some((entry) => identity(entry) === identity(item))),
56
- ];
57
- }
58
- const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
59
- if (object(previous) && object(resolved) && object(authored)) {
60
- const result = {};
61
- for (const key of new Set([
62
- ...Object.keys(previous),
63
- ...Object.keys(resolved),
64
- ...Object.keys(authored),
65
- ])) {
66
- if (key in authored)
67
- Object.defineProperty(result, key, {
68
- value: mergeVoidConfig(previous[key], resolved[key], authored[key]),
69
- enumerable: true,
70
- });
71
- else if (!(key in previous) && key in resolved)
72
- Object.defineProperty(result, key, { value: resolved[key], enumerable: true });
73
- }
74
- return result;
75
- }
76
- return authored;
77
- }
78
- export function resolveVoidCloudflareConfig(authored, lock) {
79
- const value = structuredClone(authored);
80
- if (lock.version !== 1 ||
81
- !lock.source ||
82
- typeof lock.source !== 'object' ||
83
- Array.isArray(lock.source) ||
84
- !lock.resolved ||
85
- typeof lock.resolved !== 'object' ||
86
- Array.isArray(lock.resolved) ||
87
- typeof lock.text !== 'string')
88
- throw new Error('Invalid pinned Void resource lock.');
89
- // The generated Void configuration omits resource-ID scaffolding placeholders.
90
- // Match that authored input when applying Void's resolved resource identities.
91
- for (const [field, key] of [
92
- ['d1_databases', 'database_id'],
93
- ['kv_namespaces', 'id'],
94
- ['pipelines', 'stream'],
95
- ]) {
96
- if (Array.isArray(value[field]))
97
- for (const entry of value[field]) {
98
- if (entry && typeof entry[key] === 'string' && entry[key].startsWith('REPLACE_WITH_'))
99
- delete entry[key];
100
- }
101
- }
102
- return mergeVoidConfig(lock.source, lock.resolved, value);
103
- }
104
- export function readConfig(directory) {
105
- const errors = [];
106
- const value = parse(readFileSync(configurationFile(directory), 'utf8'), errors);
107
- if (errors.length || !value || typeof value !== 'object' || Array.isArray(value))
108
- throw new Error('Invalid Wrangler JSONC configuration.');
109
- const lockFile = path.join(directory, 'void.lock.json');
110
- if (existsSync(path.join(directory, 'anhedral.cloudflare.json')) && existsSync(lockFile)) {
111
- const lock = JSON.parse(readFileSync(lockFile, 'utf8'));
112
- return resolveVoidCloudflareConfig(value, lock);
113
- }
114
- return value;
115
- }
116
- export function targetDirectory(root, target) {
117
- if (!/^apps\/[a-z0-9-]+$/.test(target.directory))
118
- throw new Error('Deployment targets must be direct apps/* directories.');
119
- const directory = realpathSync(path.join(root, target.directory));
120
- if (!directory.startsWith(realpathSync(root) + path.sep))
121
- throw new Error('Deployment target escapes the project.');
122
- return directory;
123
- }
124
- export function registerApplication(root, extendTargets = false) {
125
- root = realpathSync(root);
126
- const existing = hasProjectSection(root, 'cloudflare') ? readApplication(root) : undefined;
127
- if (existing && !extendTargets)
128
- return existing;
129
- const setup = readProjectSection(root, 'setup');
130
- validateSetupPlan(setup);
131
- const targets = readdirSync(path.join(root, 'apps'), { withFileTypes: true })
132
- .filter((entry) => entry.isDirectory())
133
- .filter((entry) => existsSync(configurationFile(path.join(root, 'apps', entry.name))))
134
- .map((entry) => {
135
- const workerName = readConfig(path.join(root, 'apps', entry.name)).name;
136
- if (typeof workerName !== 'string' || !workerPattern.test(workerName))
137
- throw new Error('Invalid Worker name.');
138
- return { id: entry.name, directory: `apps/${entry.name}`, workerName };
139
- })
140
- .sort((a, b) => {
141
- const rank = (id) => (id === 'web' ? 2 : id === 'mobile' ? 1 : 0);
142
- return rank(a.id) - rank(b.id) || a.id.localeCompare(b.id);
143
- });
144
- const selectedEngine = targets.length &&
145
- targets.every((target) => existsSync(path.join(root, target.directory, 'void.config.ts')))
146
- ? 'void'
147
- : 'wrangler';
148
- if (existing) {
149
- if (existing.targets.some((target) => !targets.some((candidate) => candidate.id === target.id &&
150
- candidate.directory === target.directory &&
151
- candidate.workerName === target.workerName)))
152
- throw new Error('Addition cannot replace existing delivery targets.');
153
- const extended = {
154
- ...existing,
155
- // A native-only registration has no Cloudflare runtime to preserve.
156
- // Select the first actual targets' engine while keeping project identity.
157
- deliveryEngine: existing.targets.length ? existing.deliveryEngine : selectedEngine,
158
- targets,
159
- };
160
- writeProjectSection(root, 'cloudflare', extended);
161
- return extended;
162
- }
163
- const project = {
164
- schemaVersion: 1,
165
- id: randomUUID(),
166
- name: JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')).name ?? path.basename(root),
167
- ownership: 'customer',
168
- provider: 'cloudflare',
169
- deliveryEngine: selectedEngine,
170
- accountId: null,
171
- audience: 'unconfigured',
172
- targets,
173
- };
174
- const ignoreFile = path.join(root, '.gitignore');
175
- const ignored = existsSync(ignoreFile) ? readFileSync(ignoreFile, 'utf8') : '';
176
- if (!ignored.split(/\r?\n/).includes('.anhedral/'))
177
- writeFileSync(ignoreFile, ignored + (ignored.endsWith('\n') || !ignored ? '' : '\n') + '.anhedral/\n');
178
- writeProjectSection(root, 'cloudflare', project);
179
- return project;
180
- }
181
- export function readApplication(root) {
182
- const project = readProjectSection(root, 'cloudflare');
183
- if (project.schemaVersion !== 1 ||
184
- typeof project.id !== 'string' ||
185
- !/^[a-f0-9-]{36}$/i.test(project.id) ||
186
- project.ownership !== 'customer' ||
187
- project.provider !== 'cloudflare' ||
188
- !['void', 'wrangler'].includes(project.deliveryEngine) ||
189
- !(project.accountId === null || accountPattern.test(project.accountId)) ||
190
- !['unconfigured', 'public', 'private'].includes(project.audience) ||
191
- !Array.isArray(project.targets))
192
- throw new Error('Invalid application manifest.');
193
- if (project.access &&
194
- (!Array.isArray(project.access.emails) ||
195
- project.access.emails.some((email) => typeof email !== 'string')))
196
- throw new Error('Invalid private audience configuration.');
197
- if (project.audience === 'private' && !project.access?.emails.length)
198
- throw new Error('Private delivery requires explicit allowed members.');
199
- const ids = new Set();
200
- const workers = new Set();
201
- for (const target of project.targets) {
202
- if (!target ||
203
- typeof target.id !== 'string' ||
204
- typeof target.workerName !== 'string' ||
205
- !/^[a-z0-9-]+$/.test(target.id) ||
206
- ids.has(target.id) ||
207
- workers.has(target.workerName) ||
208
- !workerPattern.test(target.workerName))
209
- throw new Error('Invalid or duplicate deployment target.');
210
- ids.add(target.id);
211
- workers.add(target.workerName);
212
- targetDirectory(root, target);
213
- }
214
- return project;
215
- }
216
- export const defaultRunner = (command, args, cwd, env, input) => new Promise((resolve, reject) => {
217
- const invocation = resolveCommand(command, args);
218
- const child = spawn(invocation.command, invocation.args, {
219
- cwd,
220
- env,
221
- detached: process.platform !== 'win32',
222
- stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],
223
- });
224
- if (input !== undefined) {
225
- child.stdin?.on('error', () => { });
226
- child.stdin?.end(input);
227
- }
228
- let output = '';
229
- let oversized = false;
230
- let interrupted = false;
231
- let timedOut = false;
232
- let forceTimer;
233
- const kill = (signal) => {
234
- if (!child.pid)
235
- return;
236
- if (process.platform === 'win32')
237
- spawn('taskkill', ['/pid', String(child.pid), '/t', '/f'], { stdio: 'ignore' });
238
- else {
239
- try {
240
- process.kill(-child.pid, signal);
241
- }
242
- catch {
243
- /* The process group already exited. */
244
- }
245
- }
246
- };
247
- const stop = () => {
248
- kill('SIGTERM');
249
- forceTimer ??= setTimeout(() => kill('SIGKILL'), 2000);
250
- forceTimer.unref();
251
- };
252
- const interrupt = () => {
253
- interrupted = true;
254
- stop();
255
- };
256
- process.once('SIGINT', interrupt);
257
- process.once('SIGTERM', interrupt);
258
- child.stdout?.on('data', (chunk) => {
259
- if (!oversized)
260
- output += chunk.toString();
261
- if (output.length > 8 * 1024 * 1024) {
262
- oversized = true;
263
- stop();
264
- }
265
- });
266
- // Do not persist raw build/provider output: it can contain credentials or customer data.
267
- child.stderr?.resume();
268
- const requestedDeadline = Number(env.ANHEDRAL_COMMAND_TIMEOUT_MS);
269
- const commandDeadline = Number.isInteger(requestedDeadline) &&
270
- requestedDeadline >= 1 &&
271
- requestedDeadline <= 20 * 60 * 1000
272
- ? requestedDeadline
273
- : 20 * 60 * 1000;
274
- const timer = setTimeout(() => {
275
- timedOut = true;
276
- stop();
277
- }, commandDeadline);
278
- const clean = () => {
279
- clearTimeout(timer);
280
- if (forceTimer)
281
- clearTimeout(forceTimer);
282
- process.removeListener('SIGINT', interrupt);
283
- process.removeListener('SIGTERM', interrupt);
284
- };
285
- child.on('error', () => {
286
- clean();
287
- reject(new Error(`Cannot run ${command}; check local tooling.`));
288
- });
289
- child.on('close', (code) => {
290
- clean();
291
- if (code === 0 && !oversized && !interrupted && !timedOut)
292
- resolve(output);
293
- else
294
- reject(new Error(`${command} ${args.slice(0, 3).join(' ')} ${interrupted ? 'was interrupted' : timedOut ? 'timed out' : 'failed'}; inspect the project command locally.`));
295
- });
296
- });
297
- export function environment(project) {
298
- if (!project.accountId)
299
- throw new Error('Connect the intended Cloudflare account first.');
300
- if (process.env.CLOUDFLARE_ACCOUNT_ID && process.env.CLOUDFLARE_ACCOUNT_ID !== project.accountId)
301
- throw new Error('Cloudflare environment account conflicts with the registered account.');
302
- if (process.env.CLOUDFLARE_ENV)
303
- throw new Error('Register a separate project configuration for the intended environment; CLOUDFLARE_ENV overrides are unsupported.');
304
- return {
305
- ...process.env,
306
- CLOUDFLARE_ACCOUNT_ID: project.accountId,
307
- CI: 'true',
308
- NO_COLOR: '1',
309
- FORCE_COLOR: '0',
310
- };
311
- }
312
- export async function authenticate(root, project, run) {
313
- const identity = JSON.parse(await run('pnpm', ['exec', 'wrangler', 'whoami', '--json'], targetDirectory(root, project.targets[0]), environment(project)));
314
- if (identity.loggedIn !== true ||
315
- !Array.isArray(identity.accounts) ||
316
- !identity.accounts.some((account) => account.id === project.accountId))
317
- throw new Error('Wrangler cannot access the registered Cloudflare account. Run wrangler login or configure scoped credentials.');
318
- }
319
- const applicationLocks = new AsyncLocalStorage();
320
- const lockBusy = () => new Error('Another delivery is running or was interrupted. Inspect provider status and use anhedral recover --lock only after reviewing the recorded operation.');
321
- const ownerChanged = () => new Error('Delivery lock ownership changed or is invalid. Preserve the lock and inspect local operation evidence before retrying.');
322
- function privateState(root) {
323
- const state = path.join(root, stateDirectory);
324
- try {
325
- mkdirSync(state, { recursive: true, mode: 0o700 });
326
- const stat = lstatSync(state);
327
- if (!stat.isDirectory() ||
328
- stat.isSymbolicLink() ||
329
- realpathSync(state) !== state ||
330
- (process.platform !== 'win32' && stat.mode & 0o022))
331
- throw new Error();
332
- return state;
333
- }
334
- catch {
335
- throw new Error('Delivery state must be a regular directory without shared write permissions.');
336
- }
337
- }
338
- function lockOwner() {
339
- return {
340
- schemaVersion: 1,
341
- pid: process.pid,
342
- host: hostname(),
343
- token: randomUUID(),
344
- createdAt: new Date().toISOString(),
345
- };
346
- }
347
- function privateOwner(file) {
348
- try {
349
- const stat = lstatSync(file);
350
- if (!stat.isFile() ||
351
- stat.isSymbolicLink() ||
352
- (process.platform !== 'win32' && (stat.mode & 0o077 || stat.uid !== process.getuid?.())))
353
- throw new Error();
354
- const value = JSON.parse(readBoundedFile(file, 4096).toString('utf8'));
355
- if (!value || typeof value !== 'object' || Array.isArray(value))
356
- throw new Error();
357
- const owner = value;
358
- if (Object.keys(owner).some((key) => !['schemaVersion', 'pid', 'host', 'token', 'createdAt'].includes(key)) ||
359
- owner.schemaVersion !== 1 ||
360
- !Number.isSafeInteger(owner.pid) ||
361
- owner.pid < 1 ||
362
- owner.pid > 2147483647 ||
363
- typeof owner.host !== 'string' ||
364
- !owner.host ||
365
- owner.host.length > 255 ||
366
- /[\x00-\x1f\x7f]/.test(owner.host) ||
367
- typeof owner.token !== 'string' ||
368
- !/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/.test(owner.token) ||
369
- typeof owner.createdAt !== 'string' ||
370
- !/^\d{4}-\d{2}-\d{2}T/.test(owner.createdAt) ||
371
- !Number.isFinite(Date.parse(owner.createdAt)))
372
- throw new Error();
373
- return owner;
374
- }
375
- catch {
376
- throw ownerChanged();
377
- }
378
- }
379
- function snapshotLock(lock) {
380
- try {
381
- const stat = lstatSync(lock);
382
- if (!stat.isDirectory() ||
383
- stat.isSymbolicLink() ||
384
- (process.platform !== 'win32' && (stat.mode & 0o077 || stat.uid !== process.getuid?.())) ||
385
- readdirSync(lock).join(',') !== 'owner.json')
386
- throw new Error();
387
- const file = path.join(lock, 'owner.json');
388
- const owner = privateOwner(file);
389
- const ownerStat = lstatSync(file);
390
- return {
391
- identity: {
392
- device: stat.dev,
393
- inode: stat.ino,
394
- ownerDevice: ownerStat.dev,
395
- ownerInode: ownerStat.ino,
396
- owner,
397
- },
398
- owner,
399
- };
400
- }
401
- catch {
402
- throw ownerChanged();
403
- }
404
- }
405
- function sameOwner(left, right) {
406
- return (left.pid === right.pid &&
407
- left.host === right.host &&
408
- left.token === right.token &&
409
- left.createdAt === right.createdAt);
410
- }
411
- function sameIdentity(left, right) {
412
- return (left.device === right.device &&
413
- left.inode === right.inode &&
414
- left.ownerDevice === right.ownerDevice &&
415
- left.ownerInode === right.ownerInode &&
416
- sameOwner(left.owner, right.owner));
417
- }
418
- class DeliveryGuardBusyError extends Error {
419
- constructor() {
420
- super('Delivery lock acquisition or recovery is busy. Inspect .anhedral/ship.guard before retrying.');
421
- }
422
- }
423
- /** This synchronous guard covers only filesystem transitions. An uncertain guard
424
- * after process termination is preserved for operator inspection, never auto-unlinked. */
425
- function withLockGuard(state, operation) {
426
- try {
427
- const stat = lstatSync(state);
428
- if (!stat.isDirectory() ||
429
- stat.isSymbolicLink() ||
430
- realpathSync(state) !== state ||
431
- (process.platform !== 'win32' && stat.mode & 0o022))
432
- throw new Error();
433
- }
434
- catch {
435
- throw ownerChanged();
436
- }
437
- const file = path.join(state, 'ship.guard');
438
- let descriptor;
439
- try {
440
- descriptor = openSync(file, 'wx', 0o600);
441
- }
442
- catch {
443
- throw new DeliveryGuardBusyError();
444
- }
445
- const stat = fstatSync(descriptor);
446
- const owner = lockOwner();
447
- try {
448
- writeFileSync(descriptor, JSON.stringify(owner) + '\n');
449
- return operation();
450
- }
451
- finally {
452
- closeSync(descriptor);
453
- // Another process must never lose its guard because this invocation finishes.
454
- let current;
455
- try {
456
- current = lstatSync(file);
457
- }
458
- catch {
459
- throw ownerChanged();
460
- }
461
- if (current.isSymbolicLink() ||
462
- current.dev !== stat.dev ||
463
- current.ino !== stat.ino ||
464
- !sameOwner(privateOwner(file), owner))
465
- throw ownerChanged();
466
- unlinkSync(file);
467
- }
468
- }
469
- function removeOwnedLock(lock, identity) {
470
- if (!sameIdentity(snapshotLock(lock).identity, identity))
471
- throw ownerChanged();
472
- // Never recursively remove a lock: unknown additional files are evidence.
473
- unlinkSync(path.join(lock, 'owner.json'));
474
- rmdirSync(lock);
475
- }
476
- async function releaseApplicationLock(state, lock, identity) {
477
- // A simultaneous operator inspection may briefly hold the guard. Preserve our
478
- // lock while waiting; never bypass a guard or reinterpret uncertain ownership.
479
- for (let attempt = 0;; attempt++) {
480
- try {
481
- withLockGuard(state, () => removeOwnedLock(lock, identity));
482
- return;
483
- }
484
- catch (error) {
485
- if (!(error instanceof DeliveryGuardBusyError) || attempt >= 4)
486
- throw error;
487
- await new Promise((resolve) => setTimeout(resolve, 25));
488
- }
489
- }
490
- }
491
- /** Explicit local cleanup only. A dead same-host PID is required; live, foreign,
492
- * malformed and legacy locks remain intact. Provider operations are never replayed. */
493
- export function recoverDeliveryLock(root) {
494
- root = realpathSync(root);
495
- const state = privateState(root);
496
- return withLockGuard(state, () => {
497
- const lock = path.join(state, 'ship.lock');
498
- if (!lstatSync(lock, { throwIfNoEntry: false }))
499
- return {
500
- schemaVersion: 1,
501
- state: 'unlocked',
502
- recovered: false,
503
- mutation: 'local-lock-only',
504
- providerReplay: false,
505
- };
506
- const snapshot = snapshotLock(lock);
507
- if (snapshot.owner.host !== hostname())
508
- throw new Error('Delivery lock belongs to another host; preserve it and inspect operation evidence.');
509
- let dead = false;
510
- try {
511
- process.kill(snapshot.owner.pid, 0);
512
- }
513
- catch (error) {
514
- if (error.code === 'ESRCH')
515
- dead = true;
516
- else
517
- throw new Error('Cannot prove the delivery lock owner exited; preserve the lock.');
518
- }
519
- if (!dead)
520
- throw new Error('Delivery lock owner is still running; no lock or provider state was changed.');
521
- removeOwnedLock(lock, snapshot.identity);
522
- return {
523
- schemaVersion: 1,
524
- state: 'lock-recovered',
525
- recovered: true,
526
- mutation: 'local-lock-only',
527
- providerReplay: false,
528
- nextAction: 'Inspect provider status and recorded receipts before retrying ship. No provider operation was replayed.',
529
- };
530
- });
531
- }
532
- export async function withApplicationLock(root, operation) {
533
- root = realpathSync(root);
534
- const held = applicationLocks.getStore();
535
- const state = privateState(root);
536
- const lock = path.join(state, 'ship.lock');
537
- if (held?.active && held.root === root) {
538
- if (!sameIdentity(snapshotLock(lock).identity, held.identity))
539
- throw ownerChanged();
540
- return operation();
541
- }
542
- const identity = withLockGuard(state, () => {
543
- try {
544
- mkdirSync(lock, { mode: 0o700 });
545
- }
546
- catch {
547
- throw lockBusy();
548
- }
549
- writeFileSync(path.join(lock, 'owner.json'), JSON.stringify(lockOwner()) + '\n', {
550
- flag: 'wx',
551
- mode: 0o600,
552
- });
553
- return snapshotLock(lock).identity;
554
- });
555
- const context = { root, active: true, identity };
556
- try {
557
- return await applicationLocks.run(context, operation);
558
- }
559
- finally {
560
- context.active = false;
561
- await releaseApplicationLock(state, lock, identity);
562
- }
563
- }
@@ -1,41 +0,0 @@
1
- import type { StandardProduct } from './stack-registry.js';
2
- import { type DeliveryRunner } from './project-state.js';
3
- export interface ProviderAuth {
4
- id: string;
5
- products: readonly StandardProduct[];
6
- login?: readonly string[];
7
- identity?: readonly string[];
8
- credential?: string;
9
- endpoint?: string;
10
- runtime?: {
11
- credential: string;
12
- endpoint: string;
13
- };
14
- regionalEndpoints?: Readonly<Record<string, string>>;
15
- setup: string;
16
- }
17
- /** Deployment access is separate from application-user authentication. */
18
- export declare const PROVIDER_AUTH: readonly ProviderAuth[];
19
- export declare function requiredProviders(root: string): ProviderAuth[];
20
- export type AuthState = 'verified' | 'missing' | 'insufficient-permissions' | 'unverified';
21
- export interface AuthCheck {
22
- provider: string;
23
- state: AuthState;
24
- evidence: 'cli-session' | 'api-access' | 'none';
25
- access: 'session' | 'management' | 'runtime' | 'none';
26
- nextAction: string;
27
- }
28
- export interface AuthOptions {
29
- provider?: string;
30
- status?: boolean;
31
- interactive?: boolean;
32
- }
33
- export type LoginRunner = (command: readonly string[], root: string) => Promise<void>;
34
- /** Never return provider output, tokens, user addresses or response bodies. */
35
- export declare function authenticateProviders(root: string, options?: AuthOptions, run?: DeliveryRunner, send?: typeof fetch, startLogin?: LoginRunner, environment?: NodeJS.ProcessEnv): Promise<{
36
- schemaVersion: number;
37
- checks: AuthCheck[];
38
- authenticated: boolean;
39
- provisioningReady: boolean;
40
- note: string;
41
- }>;