worldvm 0.0.0-stage → 0.1.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 (426) hide show
  1. package/AUTHORING.md +833 -0
  2. package/README.md +154 -2
  3. package/bin/worldvm.mjs +3 -0
  4. package/dist/_internal/forma/index.d.ts +1 -0
  5. package/dist/_internal/forma/index.js +1 -0
  6. package/dist/_internal/forma/world/authoring-help.d.ts +25 -0
  7. package/dist/_internal/forma/world/authoring-help.js +130 -0
  8. package/dist/_internal/forma/world/citations.d.ts +3 -0
  9. package/dist/_internal/forma/world/citations.js +26 -0
  10. package/dist/_internal/forma/world/clock-bindings.d.ts +4 -0
  11. package/dist/_internal/forma/world/clock-bindings.js +45 -0
  12. package/dist/_internal/forma/world/compile.d.ts +13 -0
  13. package/dist/_internal/forma/world/compile.js +190 -0
  14. package/dist/_internal/forma/world/coverage.d.ts +10 -0
  15. package/dist/_internal/forma/world/coverage.js +242 -0
  16. package/dist/_internal/forma/world/digest.d.ts +1 -0
  17. package/dist/_internal/forma/world/digest.js +1 -0
  18. package/dist/_internal/forma/world/documentation.d.ts +3 -0
  19. package/dist/_internal/forma/world/documentation.js +38 -0
  20. package/dist/_internal/forma/world/homes.d.ts +4 -0
  21. package/dist/_internal/forma/world/homes.js +202 -0
  22. package/dist/_internal/forma/world/index.d.ts +6 -0
  23. package/dist/_internal/forma/world/index.js +5 -0
  24. package/dist/_internal/forma/world/lowering/accounts.d.ts +4 -0
  25. package/dist/_internal/forma/world/lowering/accounts.js +36 -0
  26. package/dist/_internal/forma/world/lowering/action-policy.d.ts +5 -0
  27. package/dist/_internal/forma/world/lowering/action-policy.js +16 -0
  28. package/dist/_internal/forma/world/lowering/agents.d.ts +6 -0
  29. package/dist/_internal/forma/world/lowering/agents.js +116 -0
  30. package/dist/_internal/forma/world/lowering/bundles.d.ts +3 -0
  31. package/dist/_internal/forma/world/lowering/bundles.js +13 -0
  32. package/dist/_internal/forma/world/lowering/child-parameters.d.ts +14 -0
  33. package/dist/_internal/forma/world/lowering/child-parameters.js +36 -0
  34. package/dist/_internal/forma/world/lowering/collects.d.ts +3 -0
  35. package/dist/_internal/forma/world/lowering/collects.js +51 -0
  36. package/dist/_internal/forma/world/lowering/component-operations.d.ts +6 -0
  37. package/dist/_internal/forma/world/lowering/component-operations.js +26 -0
  38. package/dist/_internal/forma/world/lowering/components.d.ts +7 -0
  39. package/dist/_internal/forma/world/lowering/components.js +236 -0
  40. package/dist/_internal/forma/world/lowering/connectors.d.ts +4 -0
  41. package/dist/_internal/forma/world/lowering/connectors.js +31 -0
  42. package/dist/_internal/forma/world/lowering/context.d.ts +80 -0
  43. package/dist/_internal/forma/world/lowering/context.js +316 -0
  44. package/dist/_internal/forma/world/lowering/contracts.d.ts +7 -0
  45. package/dist/_internal/forma/world/lowering/contracts.js +73 -0
  46. package/dist/_internal/forma/world/lowering/decisions.d.ts +3 -0
  47. package/dist/_internal/forma/world/lowering/decisions.js +164 -0
  48. package/dist/_internal/forma/world/lowering/derives.d.ts +3 -0
  49. package/dist/_internal/forma/world/lowering/derives.js +22 -0
  50. package/dist/_internal/forma/world/lowering/discretionary.d.ts +7 -0
  51. package/dist/_internal/forma/world/lowering/discretionary.js +15 -0
  52. package/dist/_internal/forma/world/lowering/documents.d.ts +3 -0
  53. package/dist/_internal/forma/world/lowering/documents.js +68 -0
  54. package/dist/_internal/forma/world/lowering/effective.d.ts +5 -0
  55. package/dist/_internal/forma/world/lowering/effective.js +26 -0
  56. package/dist/_internal/forma/world/lowering/entities.d.ts +3 -0
  57. package/dist/_internal/forma/world/lowering/entities.js +43 -0
  58. package/dist/_internal/forma/world/lowering/escalations.d.ts +6 -0
  59. package/dist/_internal/forma/world/lowering/escalations.js +31 -0
  60. package/dist/_internal/forma/world/lowering/evidence.d.ts +3 -0
  61. package/dist/_internal/forma/world/lowering/evidence.js +75 -0
  62. package/dist/_internal/forma/world/lowering/files.d.ts +4 -0
  63. package/dist/_internal/forma/world/lowering/files.js +56 -0
  64. package/dist/_internal/forma/world/lowering/holds.d.ts +6 -0
  65. package/dist/_internal/forma/world/lowering/holds.js +35 -0
  66. package/dist/_internal/forma/world/lowering/index.d.ts +89 -0
  67. package/dist/_internal/forma/world/lowering/index.js +115 -0
  68. package/dist/_internal/forma/world/lowering/interactions.d.ts +7 -0
  69. package/dist/_internal/forma/world/lowering/interactions.js +190 -0
  70. package/dist/_internal/forma/world/lowering/library.d.ts +5 -0
  71. package/dist/_internal/forma/world/lowering/library.js +41 -0
  72. package/dist/_internal/forma/world/lowering/milestones.d.ts +6 -0
  73. package/dist/_internal/forma/world/lowering/milestones.js +17 -0
  74. package/dist/_internal/forma/world/lowering/notices.d.ts +3 -0
  75. package/dist/_internal/forma/world/lowering/notices.js +33 -0
  76. package/dist/_internal/forma/world/lowering/param-bounds.d.ts +15 -0
  77. package/dist/_internal/forma/world/lowering/param-bounds.js +71 -0
  78. package/dist/_internal/forma/world/lowering/policies.d.ts +6 -0
  79. package/dist/_internal/forma/world/lowering/policies.js +95 -0
  80. package/dist/_internal/forma/world/lowering/principals.d.ts +62 -0
  81. package/dist/_internal/forma/world/lowering/principals.js +32 -0
  82. package/dist/_internal/forma/world/lowering/recurrences.d.ts +9 -0
  83. package/dist/_internal/forma/world/lowering/recurrences.js +56 -0
  84. package/dist/_internal/forma/world/lowering/renewal.d.ts +5 -0
  85. package/dist/_internal/forma/world/lowering/renewal.js +21 -0
  86. package/dist/_internal/forma/world/lowering/resources.d.ts +6 -0
  87. package/dist/_internal/forma/world/lowering/resources.js +19 -0
  88. package/dist/_internal/forma/world/lowering/reuse.d.ts +5 -0
  89. package/dist/_internal/forma/world/lowering/reuse.js +75 -0
  90. package/dist/_internal/forma/world/lowering/sources.d.ts +10 -0
  91. package/dist/_internal/forma/world/lowering/sources.js +47 -0
  92. package/dist/_internal/forma/world/lowering/syntax.d.ts +84 -0
  93. package/dist/_internal/forma/world/lowering/syntax.js +94 -0
  94. package/dist/_internal/forma/world/lowering/vaults.d.ts +11 -0
  95. package/dist/_internal/forma/world/lowering/vaults.js +148 -0
  96. package/dist/_internal/forma/world/prelude.generated.d.ts +1 -0
  97. package/dist/_internal/forma/world/prelude.generated.js +2 -0
  98. package/dist/_internal/forma/world/properties.d.ts +9 -0
  99. package/dist/_internal/forma/world/properties.js +387 -0
  100. package/dist/_internal/forma/world/scenarios.d.ts +10 -0
  101. package/dist/_internal/forma/world/scenarios.js +757 -0
  102. package/dist/_internal/forma/world/sensitivity.d.ts +3 -0
  103. package/dist/_internal/forma/world/sensitivity.js +118 -0
  104. package/dist/_internal/forma/world/source-syntax.d.ts +6 -0
  105. package/dist/_internal/forma/world/source-syntax.js +27 -0
  106. package/dist/_internal/forma/world/status-handling.d.ts +3 -0
  107. package/dist/_internal/forma/world/status-handling.js +143 -0
  108. package/dist/_internal/forma/world/surface.d.ts +30 -0
  109. package/dist/_internal/forma/world/surface.js +213 -0
  110. package/dist/_internal/forma/world/table-expressions.d.ts +3 -0
  111. package/dist/_internal/forma/world/table-expressions.js +41 -0
  112. package/dist/_internal/forma-tools/index.d.ts +17 -0
  113. package/dist/_internal/forma-tools/index.js +124 -0
  114. package/dist/_internal/ir-checks/advances.d.ts +7 -0
  115. package/dist/_internal/ir-checks/advances.js +6 -0
  116. package/dist/_internal/ir-checks/agent-reads.d.ts +14 -0
  117. package/dist/_internal/ir-checks/agent-reads.js +118 -0
  118. package/dist/_internal/ir-checks/amendments.d.ts +3 -0
  119. package/dist/_internal/ir-checks/amendments.js +21 -0
  120. package/dist/_internal/ir-checks/canonical-json.d.ts +3 -0
  121. package/dist/_internal/ir-checks/canonical-json.js +85 -0
  122. package/dist/_internal/ir-checks/child-parameters.d.ts +2 -0
  123. package/dist/_internal/ir-checks/child-parameters.js +43 -0
  124. package/dist/_internal/ir-checks/clock-bindings.d.ts +3 -0
  125. package/dist/_internal/ir-checks/clock-bindings.js +43 -0
  126. package/dist/_internal/ir-checks/collect-types.d.ts +14 -0
  127. package/dist/_internal/ir-checks/collect-types.js +34 -0
  128. package/dist/_internal/ir-checks/component-operations.d.ts +4 -0
  129. package/dist/_internal/ir-checks/component-operations.js +23 -0
  130. package/dist/_internal/ir-checks/content-digest.d.ts +4 -0
  131. package/dist/_internal/ir-checks/content-digest.js +78 -0
  132. package/dist/_internal/ir-checks/contract-validation.d.ts +3 -0
  133. package/dist/_internal/ir-checks/contract-validation.js +307 -0
  134. package/dist/_internal/ir-checks/contracts.d.ts +25 -0
  135. package/dist/_internal/ir-checks/contracts.js +80 -0
  136. package/dist/_internal/ir-checks/dates.d.ts +2 -0
  137. package/dist/_internal/ir-checks/dates.js +7 -0
  138. package/dist/_internal/ir-checks/documents.d.ts +3 -0
  139. package/dist/_internal/ir-checks/documents.js +45 -0
  140. package/dist/_internal/ir-checks/evidence.d.ts +20 -0
  141. package/dist/_internal/ir-checks/evidence.js +56 -0
  142. package/dist/_internal/ir-checks/files.d.ts +7 -0
  143. package/dist/_internal/ir-checks/files.js +47 -0
  144. package/dist/_internal/ir-checks/index.d.ts +59 -0
  145. package/dist/_internal/ir-checks/index.js +166 -0
  146. package/dist/_internal/ir-checks/instants.d.ts +7 -0
  147. package/dist/_internal/ir-checks/instants.js +61 -0
  148. package/dist/_internal/ir-checks/notices.d.ts +4 -0
  149. package/dist/_internal/ir-checks/notices.js +58 -0
  150. package/dist/_internal/ir-checks/policy-bounds.d.ts +5 -0
  151. package/dist/_internal/ir-checks/policy-bounds.js +28 -0
  152. package/dist/_internal/ir-checks/principals.d.ts +26 -0
  153. package/dist/_internal/ir-checks/principals.js +162 -0
  154. package/dist/_internal/ir-checks/prior-cycle.d.ts +41 -0
  155. package/dist/_internal/ir-checks/prior-cycle.js +21 -0
  156. package/dist/_internal/ir-checks/read-classification.d.ts +12 -0
  157. package/dist/_internal/ir-checks/read-classification.js +67 -0
  158. package/dist/_internal/ir-checks/read-types.d.ts +2 -0
  159. package/dist/_internal/ir-checks/read-types.js +40 -0
  160. package/dist/_internal/ir-checks/resource-proofs.d.ts +4 -0
  161. package/dist/_internal/ir-checks/resource-proofs.js +98 -0
  162. package/dist/_internal/ir-checks/resources.d.ts +3 -0
  163. package/dist/_internal/ir-checks/resources.js +30 -0
  164. package/dist/_internal/ir-checks/reuse.d.ts +10 -0
  165. package/dist/_internal/ir-checks/reuse.js +99 -0
  166. package/dist/_internal/ir-checks/sealing.d.ts +14 -0
  167. package/dist/_internal/ir-checks/sealing.js +123 -0
  168. package/dist/_internal/ir-checks/sensitive-flow.d.ts +4 -0
  169. package/dist/_internal/ir-checks/sensitive-flow.js +240 -0
  170. package/dist/_internal/ir-checks/sensitivity.d.ts +19 -0
  171. package/dist/_internal/ir-checks/sensitivity.js +133 -0
  172. package/dist/_internal/ir-checks/signatures.d.ts +4 -0
  173. package/dist/_internal/ir-checks/signatures.js +22 -0
  174. package/dist/_internal/ir-checks/vaults.d.ts +10 -0
  175. package/dist/_internal/ir-checks/vaults.js +140 -0
  176. package/dist/_internal/protocol/index.d.ts +1234 -0
  177. package/dist/_internal/protocol/index.js +215 -0
  178. package/dist/_internal/reconciler/action-intents.d.ts +17 -0
  179. package/dist/_internal/reconciler/action-intents.js +161 -0
  180. package/dist/_internal/reconciler/actions.d.ts +7 -0
  181. package/dist/_internal/reconciler/actions.js +134 -0
  182. package/dist/_internal/reconciler/amendments.d.ts +12 -0
  183. package/dist/_internal/reconciler/amendments.js +52 -0
  184. package/dist/_internal/reconciler/basis.d.ts +253 -0
  185. package/dist/_internal/reconciler/basis.js +16 -0
  186. package/dist/_internal/reconciler/bundles.d.ts +22 -0
  187. package/dist/_internal/reconciler/bundles.js +110 -0
  188. package/dist/_internal/reconciler/change-detection.d.ts +5 -0
  189. package/dist/_internal/reconciler/change-detection.js +82 -0
  190. package/dist/_internal/reconciler/collection-rules.d.ts +7 -0
  191. package/dist/_internal/reconciler/collection-rules.js +46 -0
  192. package/dist/_internal/reconciler/collection-state.d.ts +11 -0
  193. package/dist/_internal/reconciler/collection-state.js +62 -0
  194. package/dist/_internal/reconciler/collection-values.d.ts +5 -0
  195. package/dist/_internal/reconciler/collection-values.js +60 -0
  196. package/dist/_internal/reconciler/collections.d.ts +35 -0
  197. package/dist/_internal/reconciler/collections.js +141 -0
  198. package/dist/_internal/reconciler/commands.d.ts +60 -0
  199. package/dist/_internal/reconciler/commands.js +468 -0
  200. package/dist/_internal/reconciler/component-operations.d.ts +48 -0
  201. package/dist/_internal/reconciler/component-operations.js +256 -0
  202. package/dist/_internal/reconciler/context.d.ts +38 -0
  203. package/dist/_internal/reconciler/context.js +44 -0
  204. package/dist/_internal/reconciler/coverage.d.ts +31 -0
  205. package/dist/_internal/reconciler/coverage.js +124 -0
  206. package/dist/_internal/reconciler/dates.d.ts +38 -0
  207. package/dist/_internal/reconciler/dates.js +121 -0
  208. package/dist/_internal/reconciler/decide.d.ts +25 -0
  209. package/dist/_internal/reconciler/decide.js +263 -0
  210. package/dist/_internal/reconciler/decision-evaluation.d.ts +9 -0
  211. package/dist/_internal/reconciler/decision-evaluation.js +67 -0
  212. package/dist/_internal/reconciler/decision-records.d.ts +14 -0
  213. package/dist/_internal/reconciler/decision-records.js +77 -0
  214. package/dist/_internal/reconciler/decision-release.d.ts +3 -0
  215. package/dist/_internal/reconciler/decision-release.js +12 -0
  216. package/dist/_internal/reconciler/dependencies.d.ts +179 -0
  217. package/dist/_internal/reconciler/dependencies.js +372 -0
  218. package/dist/_internal/reconciler/discovery.d.ts +9 -0
  219. package/dist/_internal/reconciler/discovery.js +65 -0
  220. package/dist/_internal/reconciler/document-corrections.d.ts +18 -0
  221. package/dist/_internal/reconciler/document-corrections.js +59 -0
  222. package/dist/_internal/reconciler/documents.d.ts +26 -0
  223. package/dist/_internal/reconciler/documents.js +88 -0
  224. package/dist/_internal/reconciler/effective.d.ts +6 -0
  225. package/dist/_internal/reconciler/effective.js +17 -0
  226. package/dist/_internal/reconciler/escalations.d.ts +4 -0
  227. package/dist/_internal/reconciler/escalations.js +76 -0
  228. package/dist/_internal/reconciler/evaluation.d.ts +56 -0
  229. package/dist/_internal/reconciler/evaluation.js +704 -0
  230. package/dist/_internal/reconciler/evidence-authority.d.ts +6 -0
  231. package/dist/_internal/reconciler/evidence-authority.js +70 -0
  232. package/dist/_internal/reconciler/evidence-history.d.ts +5 -0
  233. package/dist/_internal/reconciler/evidence-history.js +22 -0
  234. package/dist/_internal/reconciler/evidence-validity.d.ts +17 -0
  235. package/dist/_internal/reconciler/evidence-validity.js +135 -0
  236. package/dist/_internal/reconciler/fact-validation.d.ts +5 -0
  237. package/dist/_internal/reconciler/fact-validation.js +49 -0
  238. package/dist/_internal/reconciler/files.d.ts +9 -0
  239. package/dist/_internal/reconciler/files.js +56 -0
  240. package/dist/_internal/reconciler/graph.d.ts +40 -0
  241. package/dist/_internal/reconciler/graph.js +298 -0
  242. package/dist/_internal/reconciler/holds.d.ts +6 -0
  243. package/dist/_internal/reconciler/holds.js +18 -0
  244. package/dist/_internal/reconciler/home-definitions.d.ts +11 -0
  245. package/dist/_internal/reconciler/home-definitions.js +25 -0
  246. package/dist/_internal/reconciler/homes.d.ts +6 -0
  247. package/dist/_internal/reconciler/homes.js +32 -0
  248. package/dist/_internal/reconciler/index.d.ts +42 -0
  249. package/dist/_internal/reconciler/index.js +58 -0
  250. package/dist/_internal/reconciler/instants.d.ts +17 -0
  251. package/dist/_internal/reconciler/instants.js +56 -0
  252. package/dist/_internal/reconciler/interaction-fields.d.ts +10 -0
  253. package/dist/_internal/reconciler/interaction-fields.js +30 -0
  254. package/dist/_internal/reconciler/invariants.d.ts +8 -0
  255. package/dist/_internal/reconciler/invariants.js +34 -0
  256. package/dist/_internal/reconciler/journal.d.ts +3 -0
  257. package/dist/_internal/reconciler/journal.js +4 -0
  258. package/dist/_internal/reconciler/linking.d.ts +10 -0
  259. package/dist/_internal/reconciler/linking.js +259 -0
  260. package/dist/_internal/reconciler/memory.d.ts +32 -0
  261. package/dist/_internal/reconciler/memory.js +190 -0
  262. package/dist/_internal/reconciler/milestones.d.ts +7 -0
  263. package/dist/_internal/reconciler/milestones.js +58 -0
  264. package/dist/_internal/reconciler/missing.d.ts +18 -0
  265. package/dist/_internal/reconciler/missing.js +79 -0
  266. package/dist/_internal/reconciler/model.d.ts +350 -0
  267. package/dist/_internal/reconciler/model.js +9 -0
  268. package/dist/_internal/reconciler/notices.d.ts +14 -0
  269. package/dist/_internal/reconciler/notices.js +80 -0
  270. package/dist/_internal/reconciler/occurrences.d.ts +3 -0
  271. package/dist/_internal/reconciler/occurrences.js +30 -0
  272. package/dist/_internal/reconciler/outputs.d.ts +12 -0
  273. package/dist/_internal/reconciler/outputs.js +132 -0
  274. package/dist/_internal/reconciler/parameters.d.ts +4 -0
  275. package/dist/_internal/reconciler/parameters.js +27 -0
  276. package/dist/_internal/reconciler/policies.d.ts +22 -0
  277. package/dist/_internal/reconciler/policies.js +94 -0
  278. package/dist/_internal/reconciler/policy-edits.d.ts +11 -0
  279. package/dist/_internal/reconciler/policy-edits.js +42 -0
  280. package/dist/_internal/reconciler/policy-linking.d.ts +4 -0
  281. package/dist/_internal/reconciler/policy-linking.js +104 -0
  282. package/dist/_internal/reconciler/principal-types.d.ts +2 -0
  283. package/dist/_internal/reconciler/principal-types.js +38 -0
  284. package/dist/_internal/reconciler/prior-decisions.d.ts +3 -0
  285. package/dist/_internal/reconciler/prior-decisions.js +34 -0
  286. package/dist/_internal/reconciler/projections.d.ts +4 -0
  287. package/dist/_internal/reconciler/projections.js +85 -0
  288. package/dist/_internal/reconciler/proofs.d.ts +9 -0
  289. package/dist/_internal/reconciler/proofs.js +24 -0
  290. package/dist/_internal/reconciler/properties.d.ts +25 -0
  291. package/dist/_internal/reconciler/properties.js +67 -0
  292. package/dist/_internal/reconciler/property-eval.d.ts +5 -0
  293. package/dist/_internal/reconciler/property-eval.js +101 -0
  294. package/dist/_internal/reconciler/property-generator.d.ts +9 -0
  295. package/dist/_internal/reconciler/property-generator.js +288 -0
  296. package/dist/_internal/reconciler/property-shrink.d.ts +14 -0
  297. package/dist/_internal/reconciler/property-shrink.js +183 -0
  298. package/dist/_internal/reconciler/provenance.d.ts +8 -0
  299. package/dist/_internal/reconciler/provenance.js +61 -0
  300. package/dist/_internal/reconciler/reconcile.d.ts +32 -0
  301. package/dist/_internal/reconciler/reconcile.js +164 -0
  302. package/dist/_internal/reconciler/recurrence.d.ts +9 -0
  303. package/dist/_internal/reconciler/recurrence.js +44 -0
  304. package/dist/_internal/reconciler/requirements.d.ts +5 -0
  305. package/dist/_internal/reconciler/requirements.js +331 -0
  306. package/dist/_internal/reconciler/resource-generation.d.ts +9 -0
  307. package/dist/_internal/reconciler/resource-generation.js +17 -0
  308. package/dist/_internal/reconciler/resource-scenarios.d.ts +26 -0
  309. package/dist/_internal/reconciler/resource-scenarios.js +78 -0
  310. package/dist/_internal/reconciler/resources.d.ts +24 -0
  311. package/dist/_internal/reconciler/resources.js +178 -0
  312. package/dist/_internal/reconciler/result-digest.d.ts +13 -0
  313. package/dist/_internal/reconciler/result-digest.js +66 -0
  314. package/dist/_internal/reconciler/reuse.d.ts +16 -0
  315. package/dist/_internal/reconciler/reuse.js +119 -0
  316. package/dist/_internal/reconciler/scenarios.d.ts +32 -0
  317. package/dist/_internal/reconciler/scenarios.js +442 -0
  318. package/dist/_internal/reconciler/scheduling.d.ts +9 -0
  319. package/dist/_internal/reconciler/scheduling.js +203 -0
  320. package/dist/_internal/reconciler/sha256.d.ts +1 -0
  321. package/dist/_internal/reconciler/sha256.js +1 -0
  322. package/dist/_internal/reconciler/signatures.d.ts +13 -0
  323. package/dist/_internal/reconciler/signatures.js +37 -0
  324. package/dist/_internal/reconciler/temporal.d.ts +10 -0
  325. package/dist/_internal/reconciler/temporal.js +46 -0
  326. package/dist/_internal/reconciler/upgrades.d.ts +6 -0
  327. package/dist/_internal/reconciler/upgrades.js +65 -0
  328. package/dist/_internal/reconciler/wire.d.ts +2 -0
  329. package/dist/_internal/reconciler/wire.js +5 -0
  330. package/dist/_internal/reconciler/work.d.ts +32 -0
  331. package/dist/_internal/reconciler/work.js +101 -0
  332. package/dist/_internal/world-ir/schema.generated.d.ts +180 -0
  333. package/dist/_internal/world-ir/schema.generated.js +1127 -0
  334. package/dist/_internal/world-ir/types.generated.d.ts +1011 -0
  335. package/dist/_internal/world-ir/types.generated.js +1 -0
  336. package/dist/authoring.d.ts +9 -0
  337. package/dist/authoring.js +10 -0
  338. package/dist/catalogue.d.ts +20 -0
  339. package/dist/catalogue.js +531 -0
  340. package/dist/cli.d.ts +2 -0
  341. package/dist/cli.js +553 -0
  342. package/dist/codegen.d.ts +6 -0
  343. package/dist/codegen.js +89 -0
  344. package/dist/coverage.d.ts +60 -0
  345. package/dist/coverage.js +128 -0
  346. package/dist/deploy.d.ts +21 -0
  347. package/dist/deploy.js +72 -0
  348. package/dist/diagnostics.d.ts +9 -0
  349. package/dist/diagnostics.js +37 -0
  350. package/dist/diff.d.ts +17 -0
  351. package/dist/diff.js +19 -0
  352. package/dist/durable-object.d.ts +14 -0
  353. package/dist/durable-object.js +30 -0
  354. package/dist/explain.d.ts +113 -0
  355. package/dist/explain.js +225 -0
  356. package/dist/fixes.d.ts +4 -0
  357. package/dist/fixes.js +70 -0
  358. package/dist/fmt.d.ts +12 -0
  359. package/dist/fmt.js +39 -0
  360. package/dist/handle/open.d.ts +18 -0
  361. package/dist/handle/open.js +28 -0
  362. package/dist/handle/protocol.d.ts +12 -0
  363. package/dist/handle/protocol.js +96 -0
  364. package/dist/handle/store.d.ts +31 -0
  365. package/dist/handle/store.js +11 -0
  366. package/dist/handle/types.d.ts +37 -0
  367. package/dist/handle/types.js +1 -0
  368. package/dist/handle/world.d.ts +190 -0
  369. package/dist/handle/world.js +533 -0
  370. package/dist/http.d.ts +3 -0
  371. package/dist/http.js +72 -0
  372. package/dist/impact.d.ts +21 -0
  373. package/dist/impact.js +57 -0
  374. package/dist/index.d.ts +30 -0
  375. package/dist/index.js +43 -0
  376. package/dist/init.d.ts +13 -0
  377. package/dist/init.js +99 -0
  378. package/dist/ir-schema.json +4213 -0
  379. package/dist/lints.d.ts +8 -0
  380. package/dist/lints.js +154 -0
  381. package/dist/lsp.d.ts +14 -0
  382. package/dist/lsp.js +380 -0
  383. package/dist/manual/catalog.d.ts +12 -0
  384. package/dist/manual/catalog.js +23 -0
  385. package/dist/manual/examples.d.ts +15 -0
  386. package/dist/manual/examples.js +39 -0
  387. package/dist/manual/projections.d.ts +77 -0
  388. package/dist/manual/projections.js +344 -0
  389. package/dist/manual/prose.d.ts +19 -0
  390. package/dist/manual/prose.js +215 -0
  391. package/dist/manual/render.d.ts +76 -0
  392. package/dist/manual/render.js +250 -0
  393. package/dist/manual/text.d.ts +7 -0
  394. package/dist/manual/text.js +15 -0
  395. package/dist/mcp.d.ts +32 -0
  396. package/dist/mcp.js +269 -0
  397. package/dist/mutate.d.ts +36 -0
  398. package/dist/mutate.js +123 -0
  399. package/dist/project.d.ts +26 -0
  400. package/dist/project.js +80 -0
  401. package/dist/refine.d.ts +18 -0
  402. package/dist/refine.js +197 -0
  403. package/dist/release/diff.d.ts +45 -0
  404. package/dist/release/diff.js +103 -0
  405. package/dist/release/impact.d.ts +83 -0
  406. package/dist/release/impact.js +214 -0
  407. package/dist/release/nodes.d.ts +20 -0
  408. package/dist/release/nodes.js +118 -0
  409. package/dist/render.d.ts +19 -0
  410. package/dist/render.js +43 -0
  411. package/dist/serve.d.ts +18 -0
  412. package/dist/serve.js +140 -0
  413. package/dist/snapshot.d.ts +19 -0
  414. package/dist/snapshot.js +45 -0
  415. package/dist/sqlite.d.ts +16 -0
  416. package/dist/sqlite.js +151 -0
  417. package/dist/test.d.ts +54 -0
  418. package/dist/test.js +131 -0
  419. package/dist/world.d.ts +7 -0
  420. package/dist/world.js +5 -0
  421. package/docs/authoring/vendor-risk/example.forma +11 -0
  422. package/docs/authoring/vendor-risk/library/vendor.forma +76 -0
  423. package/docs/authoring/vendor-risk/scenarios/reviews.forma +107 -0
  424. package/docs/protocol.md +195 -0
  425. package/docs/reference.md +258 -0
  426. package/package.json +81 -3
@@ -0,0 +1,83 @@
1
+ import type { WorldIR } from "../_internal/forma/world/index.js";
2
+ import { type World } from "../_internal/reconciler/index.js";
3
+ import { type IRNode } from "./nodes.js";
4
+ /** The component a node belongs to, for component-scoped nodes and component shells. */
5
+ export declare const nodeComponent: (node: IRNode) => string | null;
6
+ /**
7
+ * Direct references of every node. Any string equal to a declaration's name counts, which
8
+ * over-approximates (a coincidental match only widens the preview, never narrows it). Scoped
9
+ * nodes depend on their component shell and on same-component siblings they name; a shell
10
+ * depends on the siblings it names (outputs read requirement statuses).
11
+ */
12
+ export declare const nodeReferences: (nodes: ReadonlyMap<string, IRNode>) => ReadonlyMap<string, ReadonlySet<string>>;
13
+ /** A node's digest over itself and everything it transitively depends on. */
14
+ export declare const dependencyDigests: (ir: WorldIR) => ReadonlyMap<string, string>;
15
+ export interface AffectedDefinitions {
16
+ /** Node keys whose dependency digest changed, appeared or disappeared. */
17
+ readonly nodes: readonly string[];
18
+ readonly components: readonly string[];
19
+ /** Accounts whose own declaration changed: every occurrence they evaluate may move. */
20
+ readonly accounts: readonly string[];
21
+ }
22
+ export declare const affectedDefinitions: (before: WorldIR, after: WorldIR) => AffectedDefinitions;
23
+ export interface Population {
24
+ readonly accounts: readonly string[];
25
+ readonly world: World;
26
+ readonly at: string;
27
+ }
28
+ export interface OccurrenceState {
29
+ readonly account: string;
30
+ readonly instance: string;
31
+ readonly component: string;
32
+ readonly requirement: string;
33
+ readonly occurrence: string;
34
+ readonly subjects: readonly string[];
35
+ readonly status: string;
36
+ readonly due: string | null;
37
+ }
38
+ export interface OccurrenceChange {
39
+ readonly change: "gained" | "lost" | "status" | "due";
40
+ readonly before: OccurrenceState | null;
41
+ readonly after: OccurrenceState | null;
42
+ }
43
+ export interface WorkState {
44
+ readonly key: string;
45
+ readonly account: string;
46
+ readonly state: string;
47
+ readonly instances: readonly string[];
48
+ readonly subjects: readonly string[];
49
+ }
50
+ export interface WorkChange {
51
+ readonly change: "gained" | "lost" | "state";
52
+ readonly before: WorkState | null;
53
+ readonly after: WorkState | null;
54
+ }
55
+ export interface Impact {
56
+ readonly format: "worldvm/impact@1";
57
+ readonly at: string;
58
+ readonly affected: AffectedDefinitions;
59
+ readonly subjects: {
60
+ readonly total: number;
61
+ readonly considered: number;
62
+ readonly changed: number;
63
+ };
64
+ readonly occurrences: {
65
+ readonly total: number;
66
+ readonly considered: number;
67
+ readonly changes: readonly OccurrenceChange[];
68
+ };
69
+ readonly work: {
70
+ readonly before: number;
71
+ readonly after: number;
72
+ readonly changes: readonly WorkChange[];
73
+ };
74
+ /** Changes outside the dependency selection: must be empty, or the digests missed a dependency. */
75
+ readonly unexpected: readonly (OccurrenceChange | WorkChange)[];
76
+ readonly samples: Readonly<Record<string, readonly string[]>>;
77
+ }
78
+ /**
79
+ * Previews a release over a recorded population: which occurrences and work change and for
80
+ * whom. Dependency digests select what can change; every other occurrence is still compared,
81
+ * and any difference outside the selection is reported as unexpected rather than hidden.
82
+ */
83
+ export declare const previewImpact: (before: WorldIR, after: WorldIR, population: Population) => Impact;
@@ -0,0 +1,214 @@
1
+ import { basis, link, reconcile, sha256, workItems, } from "../_internal/reconciler/index.js";
2
+ import { nodeDigest, releaseNodes, semanticJson } from "./nodes.js";
3
+ const scoped = new Set(["requirement", "action", "invariant", "retention"]);
4
+ /** The component a node belongs to, for component-scoped nodes and component shells. */
5
+ export const nodeComponent = (node) => node.kind === "component" || node.kind === "retention"
6
+ ? node.name
7
+ : scoped.has(node.kind)
8
+ ? node.name.slice(0, node.name.indexOf("/"))
9
+ : null;
10
+ const strings = (value, out) => {
11
+ if (typeof value === "string")
12
+ out.add(value);
13
+ else if (Array.isArray(value))
14
+ value.forEach((v) => strings(v, out));
15
+ else if (value && typeof value === "object")
16
+ for (const [k, v] of Object.entries(value))
17
+ if (k !== "at")
18
+ strings(v, out);
19
+ return out;
20
+ };
21
+ /**
22
+ * Direct references of every node. Any string equal to a declaration's name counts, which
23
+ * over-approximates (a coincidental match only widens the preview, never narrows it). Scoped
24
+ * nodes depend on their component shell and on same-component siblings they name; a shell
25
+ * depends on the siblings it names (outputs read requirement statuses).
26
+ */
27
+ export const nodeReferences = (nodes) => {
28
+ const global = new Map(), local = new Map();
29
+ for (const node of nodes.values()) {
30
+ const component = nodeComponent(node);
31
+ if (scoped.has(node.kind) && component !== null && node.kind !== "retention") {
32
+ const short = `${component}\u0000${node.name.slice(component.length + 1)}`;
33
+ local.set(short, [...(local.get(short) ?? []), node.key]);
34
+ }
35
+ else if (node.kind !== "retention" && node.kind !== "library")
36
+ // A library's digest names the whole compiled unit; its meaning lives in its declarations.
37
+ global.set(node.name, [...(global.get(node.name) ?? []), node.key]);
38
+ }
39
+ const out = new Map();
40
+ for (const node of nodes.values()) {
41
+ const refs = new Set(), component = nodeComponent(node);
42
+ for (const s of strings(node.value, new Set())) {
43
+ for (const key of global.get(s) ?? [])
44
+ refs.add(key);
45
+ if (component !== null)
46
+ for (const key of local.get(`${component}\u0000${s}`) ?? [])
47
+ refs.add(key);
48
+ }
49
+ if (component !== null && node.kind !== "component")
50
+ refs.add(`component:${component}`);
51
+ refs.delete(node.key);
52
+ out.set(node.key, refs);
53
+ }
54
+ // Components read roles; the entities implementing a role decide what those reads observe.
55
+ for (const node of nodes.values())
56
+ if (node.kind === "entity")
57
+ for (const ref of out.get(node.key) ?? [])
58
+ if (ref.startsWith("role:"))
59
+ out.get(ref)?.add(node.key);
60
+ return out;
61
+ };
62
+ /** A node's digest over itself and everything it transitively depends on. */
63
+ export const dependencyDigests = (ir) => {
64
+ const nodes = releaseNodes(ir), refs = nodeReferences(nodes), own = new Map([...nodes.values()].map((n) => [n.key, nodeDigest(n)]));
65
+ const out = new Map();
66
+ for (const key of nodes.keys()) {
67
+ const closure = new Set([key]), queue = [key];
68
+ while (queue.length)
69
+ for (const next of refs.get(queue.pop()) ?? [])
70
+ if (!closure.has(next)) {
71
+ closure.add(next);
72
+ queue.push(next);
73
+ }
74
+ out.set(key, `sha256:${sha256(semanticJson([...closure].sort().map((k) => [k, own.get(k)])))}`);
75
+ }
76
+ return out;
77
+ };
78
+ export const affectedDefinitions = (before, after) => {
79
+ const a = dependencyDigests(before), b = dependencyDigests(after), nodes = [...new Set([...a.keys(), ...b.keys()])].filter((k) => a.get(k) !== b.get(k)).sort();
80
+ const oldNodes = releaseNodes(before), newNodes = releaseNodes(after);
81
+ const components = new Set(), accounts = new Set();
82
+ for (const key of nodes) {
83
+ const was = oldNodes.get(key), now = newNodes.get(key), node = (now ?? was);
84
+ const component = nodeComponent(node);
85
+ if (component !== null)
86
+ components.add(component);
87
+ // An account's closure reaches its roots; only a change to its own declaration moves all.
88
+ if (node.kind === "account" && (!was || !now || nodeDigest(was) !== nodeDigest(now)))
89
+ accounts.add(node.name);
90
+ }
91
+ return { nodes, components: [...components].sort(), accounts: [...accounts].sort() };
92
+ };
93
+ const occurrences = (recon) => {
94
+ const out = new Map();
95
+ for (const [instance, result] of recon.results) {
96
+ const inst = recon.instances.get(instance);
97
+ for (const q of result.requirements)
98
+ out.set(JSON.stringify([inst.account, q.occurrence]), {
99
+ account: inst.account,
100
+ instance,
101
+ component: inst.component,
102
+ requirement: q.name,
103
+ occurrence: q.occurrence,
104
+ subjects: [...inst.attached].sort(),
105
+ status: q.status,
106
+ due: q.due,
107
+ });
108
+ }
109
+ return out;
110
+ };
111
+ const work = (recon) => new Map(workItems(recon).map((w) => {
112
+ const instances = [...new Set(w.members.map((m) => m.instance))].sort();
113
+ return [
114
+ w.key,
115
+ {
116
+ key: w.key,
117
+ account: w.account,
118
+ state: w.state,
119
+ instances,
120
+ subjects: [
121
+ ...new Set(instances.flatMap((i) => recon.instances.get(i)?.attached ?? [])),
122
+ ].sort(),
123
+ },
124
+ ];
125
+ }));
126
+ const run = (ir, population) => reconcile(population.accounts.map((a) => link(ir, a)), basis(population.world, population.at), population.at);
127
+ /**
128
+ * Previews a release over a recorded population: which occurrences and work change and for
129
+ * whom. Dependency digests select what can change; every other occurrence is still compared,
130
+ * and any difference outside the selection is reported as unexpected rather than hidden.
131
+ */
132
+ export const previewImpact = (before, after, population) => {
133
+ const affected = affectedDefinitions(before, after), components = new Set(affected.components), accounts = new Set(affected.accounts);
134
+ const old = run(before, population), next = run(after, population);
135
+ const inScope = (account, component) => accounts.has(account) || components.has(component);
136
+ const o1 = occurrences(old), o2 = occurrences(next);
137
+ const occurrenceChanges = [];
138
+ for (const key of [...new Set([...o1.keys(), ...o2.keys()])].sort()) {
139
+ const a = o1.get(key) ?? null, b = o2.get(key) ?? null;
140
+ const change = !a
141
+ ? "gained"
142
+ : !b
143
+ ? "lost"
144
+ : a.status !== b.status
145
+ ? "status"
146
+ : a.due !== b.due
147
+ ? "due"
148
+ : null;
149
+ if (change)
150
+ occurrenceChanges.push({ change, before: a, after: b });
151
+ }
152
+ const w1 = work(old), w2 = work(next), instanceComponent = (account, instance) => (next.instances.get(instance) ?? old.instances.get(instance))?.component ?? "";
153
+ const workChanges = [];
154
+ for (const key of [...new Set([...w1.keys(), ...w2.keys()])].sort()) {
155
+ const a = w1.get(key) ?? null, b = w2.get(key) ?? null;
156
+ const change = !a
157
+ ? "gained"
158
+ : !b
159
+ ? "lost"
160
+ : a.state !== b.state
161
+ ? "state"
162
+ : null;
163
+ if (change)
164
+ workChanges.push({ change, before: a, after: b });
165
+ }
166
+ const occurrenceScoped = (c) => {
167
+ const s = (c.after ?? c.before);
168
+ return inScope(s.account, s.component);
169
+ };
170
+ const workScoped = (c) => {
171
+ const s = (c.after ?? c.before);
172
+ return s.instances.some((i) => inScope(s.account, instanceComponent(s.account, i)));
173
+ };
174
+ const considered = [
175
+ ...new Set([...o1.values(), ...o2.values()]
176
+ .filter((s) => inScope(s.account, s.component))
177
+ .map((s) => JSON.stringify([s.account, s.occurrence]))),
178
+ ];
179
+ const allSubjects = new Set([...o1.values(), ...o2.values()].flatMap((s) => s.subjects));
180
+ const consideredSubjects = new Set([...o1.values(), ...o2.values()]
181
+ .filter((s) => inScope(s.account, s.component))
182
+ .flatMap((s) => s.subjects));
183
+ const changedSubjects = new Set([
184
+ ...occurrenceChanges.flatMap((c) => (c.after ?? c.before).subjects),
185
+ ...workChanges.flatMap((c) => (c.after ?? c.before).subjects),
186
+ ]);
187
+ const sample = (items) => [...new Set(items)].slice(0, 5);
188
+ return {
189
+ format: "worldvm/impact@1",
190
+ at: population.at,
191
+ affected,
192
+ subjects: {
193
+ total: allSubjects.size,
194
+ considered: consideredSubjects.size,
195
+ changed: changedSubjects.size,
196
+ },
197
+ occurrences: {
198
+ total: new Set([...o1.keys(), ...o2.keys()]).size,
199
+ considered: considered.length,
200
+ changes: occurrenceChanges.filter(occurrenceScoped),
201
+ },
202
+ work: { before: w1.size, after: w2.size, changes: workChanges.filter(workScoped) },
203
+ unexpected: [
204
+ ...occurrenceChanges.filter((c) => !occurrenceScoped(c)),
205
+ ...workChanges.filter((c) => !workScoped(c)),
206
+ ],
207
+ samples: {
208
+ "work gained": sample(workChanges.filter((c) => c.change === "gained").flatMap((c) => c.after.subjects)),
209
+ "work lost": sample(workChanges.filter((c) => c.change === "lost").flatMap((c) => c.before.subjects)),
210
+ "status changed": sample(occurrenceChanges.filter((c) => c.change === "status").flatMap((c) => c.after.subjects)),
211
+ "due changed": sample(occurrenceChanges.filter((c) => c.change === "due").flatMap((c) => c.after.subjects)),
212
+ },
213
+ };
214
+ };
@@ -0,0 +1,20 @@
1
+ import type { Span, WorldIR } from "../_internal/forma/world/index.js";
2
+ /**
3
+ * One named declaration of a compiled world. Requirements, actions, invariants and retention are
4
+ * their own nodes so a diff and an impact preview can name the obligation that changed; the
5
+ * component node keeps the rest of the component (identity, inputs, home, slots, outputs).
6
+ */
7
+ export interface IRNode {
8
+ readonly key: string;
9
+ readonly kind: string;
10
+ readonly name: string;
11
+ readonly at: Span | null;
12
+ readonly value: unknown;
13
+ }
14
+ /** Canonical JSON without source spans: moving or reformatting source never changes meaning. */
15
+ export declare const semanticJson: (value: unknown) => string;
16
+ export declare const nodeDigest: (node: IRNode) => string;
17
+ export declare const behaviorDigest: (node: IRNode) => string;
18
+ /** Every release-relevant declaration. Scenarios and properties are examples, listed separately. */
19
+ export declare const releaseNodes: (ir: WorldIR) => ReadonlyMap<string, IRNode>;
20
+ export declare const exampleNodes: (ir: WorldIR) => ReadonlyMap<string, IRNode>;
@@ -0,0 +1,118 @@
1
+ import { sha256 } from "../_internal/reconciler/index.js";
2
+ const isSpan = (v) => !!v &&
3
+ typeof v === "object" &&
4
+ typeof v.src === "string" &&
5
+ typeof v.from === "number" &&
6
+ typeof v.line === "number";
7
+ /** Canonical JSON without source spans: moving or reformatting source never changes meaning. */
8
+ export const semanticJson = (value) => {
9
+ const visit = (v) => {
10
+ if (v === undefined)
11
+ return "null";
12
+ if (!v || typeof v !== "object")
13
+ return JSON.stringify(v);
14
+ if (Array.isArray(v))
15
+ return `[${v.map(visit).join(",")}]`;
16
+ const record = v;
17
+ return `{${Object.keys(record)
18
+ .filter((k) => record[k] !== undefined && !(k === "at" && isSpan(record[k])))
19
+ .sort()
20
+ .map((k) => `${JSON.stringify(k)}:${visit(record[k])}`)
21
+ .join(",")}}`;
22
+ };
23
+ return visit(value);
24
+ };
25
+ const presentation = new Set(["doc", "label", "title"]);
26
+ /** Removes prose that never reaches evaluation, so a diff can say a change is wording only. */
27
+ const withoutPresentation = (value) => {
28
+ if (Array.isArray(value))
29
+ return value.map(withoutPresentation);
30
+ if (!value || typeof value !== "object" || isSpan(value))
31
+ return value;
32
+ return Object.fromEntries(Object.entries(value)
33
+ .filter(([k]) => !presentation.has(k))
34
+ .map(([k, v]) => [k, withoutPresentation(v)]));
35
+ };
36
+ export const nodeDigest = (node) => `sha256:${sha256(semanticJson(node.value))}`;
37
+ export const behaviorDigest = (node) => `sha256:${sha256(semanticJson(withoutPresentation(node.value)))}`;
38
+ const named = (kind, items) => (items ?? []).map((item) => ({
39
+ key: `${kind}:${item.name}`,
40
+ kind,
41
+ name: item.name,
42
+ at: item.at ?? null,
43
+ value: item,
44
+ }));
45
+ /** Every release-relevant declaration. Scenarios and properties are examples, listed separately. */
46
+ export const releaseNodes = (ir) => {
47
+ const nodes = [
48
+ ...named("library", ir.libraries),
49
+ ...named("type", ir.types),
50
+ ...named("role", ir.roles),
51
+ ...named("entity", ir.entities),
52
+ ...named("calendar", ir.calendars),
53
+ ...named("derive", ir.derives),
54
+ ...named("evidence", ir.evidence),
55
+ ...named("interaction", ir.interactions),
56
+ ...named("layout", ir.layouts),
57
+ ...named("connector", ir.connectors),
58
+ ...named("machine", ir.machines),
59
+ ...named("contract", ir.componentContracts),
60
+ ...named("import", ir.componentImports),
61
+ ...named("decision", ir.decisions),
62
+ ...named("collect", ir.collects),
63
+ ...named("bundle", ir.bundles),
64
+ ...named("document", ir.documents),
65
+ ...named("notice", ir.notices),
66
+ ...named("vault", ir.vaults),
67
+ ...named("agent", ir.agents),
68
+ ...named("source", ir.references),
69
+ ...named("account", ir.accounts),
70
+ ];
71
+ for (const c of ir.components) {
72
+ const { requirements, actions, invariants, retention, ...shell } = c;
73
+ nodes.push({
74
+ key: `component:${c.name}`,
75
+ kind: "component",
76
+ name: c.name,
77
+ at: c.at,
78
+ value: shell,
79
+ });
80
+ for (const r of requirements)
81
+ nodes.push({
82
+ key: `requirement:${c.name}/${r.name}`,
83
+ kind: "requirement",
84
+ name: `${c.name}/${r.name}`,
85
+ at: r.at,
86
+ value: r,
87
+ });
88
+ for (const a of actions)
89
+ nodes.push({
90
+ key: `action:${c.name}/${a.name}`,
91
+ kind: "action",
92
+ name: `${c.name}/${a.name}`,
93
+ at: a.at,
94
+ value: a,
95
+ });
96
+ for (const i of invariants)
97
+ nodes.push({
98
+ key: `invariant:${c.name}/${i.name}`,
99
+ kind: "invariant",
100
+ name: `${c.name}/${i.name}`,
101
+ at: i.at,
102
+ value: i,
103
+ });
104
+ if (retention)
105
+ nodes.push({
106
+ key: `retention:${c.name}`,
107
+ kind: "retention",
108
+ name: c.name,
109
+ at: retention.at,
110
+ value: retention,
111
+ });
112
+ }
113
+ return new Map(nodes.map((n) => [n.key, n]));
114
+ };
115
+ export const exampleNodes = (ir) => new Map([...named("scenario", ir.scenarios), ...named("property", ir.properties)].map((n) => [
116
+ n.key,
117
+ n,
118
+ ]));
@@ -0,0 +1,19 @@
1
+ import { type CliDiagnostic } from "./project.js";
2
+ import { type Manual } from "./manual/render.js";
3
+ export type RenderFormat = "markdown" | "html";
4
+ export interface RenderOptions {
5
+ readonly format?: RenderFormat;
6
+ readonly account?: string;
7
+ }
8
+ export interface RenderReport {
9
+ readonly format: "worldvm/render@1";
10
+ readonly command: "render";
11
+ readonly directory: string;
12
+ readonly ok: boolean;
13
+ readonly output: RenderFormat;
14
+ readonly account: string | null;
15
+ readonly diagnostics: readonly CliDiagnostic[];
16
+ readonly manual: Manual | null;
17
+ readonly document: string | null;
18
+ }
19
+ export declare const renderDirectory: (directory: string, options?: RenderOptions) => Promise<RenderReport>;
package/dist/render.js ADDED
@@ -0,0 +1,43 @@
1
+ import { loadProject } from "./project.js";
2
+ import { buildManual, ManualAccountError, renderManualHtml, renderManualMarkdown, } from "./manual/render.js";
3
+ export const renderDirectory = async (directory, options = {}) => {
4
+ const project = await loadProject(directory), output = options.format ?? "markdown", base = {
5
+ format: "worldvm/render@1",
6
+ command: "render",
7
+ directory: project.directory,
8
+ output,
9
+ account: options.account ?? null,
10
+ };
11
+ const errors = project.diagnostics.some((d) => d.severity === "error");
12
+ if (!project.ir || errors)
13
+ return { ...base, ok: false, diagnostics: project.diagnostics, manual: null, document: null };
14
+ try {
15
+ const manual = buildManual(project.ir, project.files, options.account === undefined ? {} : { account: options.account });
16
+ return {
17
+ ...base,
18
+ ok: true,
19
+ diagnostics: project.diagnostics,
20
+ manual,
21
+ document: output === "html" ? renderManualHtml(manual) : renderManualMarkdown(manual),
22
+ };
23
+ }
24
+ catch (cause) {
25
+ if (!(cause instanceof ManualAccountError))
26
+ throw cause;
27
+ const diagnostic = {
28
+ code: "E_RENDER_ACCOUNT",
29
+ severity: "error",
30
+ message: cause.message,
31
+ at: null,
32
+ help: `Pass --account with one of: ${cause.available.join(", ") || "(no accounts declared)"}.`,
33
+ fix: null,
34
+ };
35
+ return {
36
+ ...base,
37
+ ok: false,
38
+ diagnostics: [...project.diagnostics, diagnostic],
39
+ manual: null,
40
+ document: null,
41
+ };
42
+ }
43
+ };
@@ -0,0 +1,18 @@
1
+ import type { World } from "./handle/world.js";
2
+ /** Schedule the next kernel wake, rescheduling after writes; no timer is owned by the handle. */
3
+ export declare const scheduleTicks: (world: World, onError?: (cause: unknown) => void) => (() => void);
4
+ export interface ServeOptions {
5
+ readonly source?: string;
6
+ readonly db: string;
7
+ readonly port?: number;
8
+ readonly clock?: () => string;
9
+ readonly ui?: boolean;
10
+ }
11
+ /** Optional local demo routes; deliberately separate from the protocol handler. */
12
+ export declare const createUiHandler: (world: Pick<World, "types">, protocol: (request: Request) => Promise<Response>) => ((request: Request) => Promise<Response>);
13
+ /** The only socket boundary; tests exercise createHandler directly. Binds loopback by default. */
14
+ export declare const serve: (options: ServeOptions) => Promise<{
15
+ world: World;
16
+ server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
17
+ close: () => Promise<void>;
18
+ }>;
package/dist/serve.js ADDED
@@ -0,0 +1,140 @@
1
+ import { createServer } from "node:http";
2
+ import { Readable } from "node:stream";
3
+ import { pipeline } from "node:stream/promises";
4
+ import { readFile } from "node:fs/promises";
5
+ import { createHandler } from "./http.js";
6
+ import { failure } from "./handle/protocol.js";
7
+ import { open } from "./handle/open.js";
8
+ import { deployDirectory } from "./deploy.js";
9
+ import { sqlite } from "./sqlite.js";
10
+ /** Schedule the next kernel wake, rescheduling after writes; no timer is owned by the handle. */
11
+ export const scheduleTicks = (world, onError = console.error) => {
12
+ let timer;
13
+ let stopped = false;
14
+ const schedule = () => {
15
+ if (stopped)
16
+ return;
17
+ clearTimeout(timer);
18
+ const wake = world.nextWake();
19
+ const delay = wake
20
+ ? Math.max(1, Math.min(60_000, Date.parse(wake) - Date.parse(world.now())))
21
+ : 60_000;
22
+ timer = setTimeout(async () => {
23
+ try {
24
+ await world.tick();
25
+ }
26
+ catch (cause) {
27
+ onError(cause);
28
+ }
29
+ finally {
30
+ schedule();
31
+ }
32
+ }, delay);
33
+ timer.unref();
34
+ };
35
+ const unsubscribe = world.subscribe(schedule);
36
+ schedule();
37
+ return () => {
38
+ stopped = true;
39
+ clearTimeout(timer);
40
+ unsubscribe();
41
+ };
42
+ };
43
+ /** Optional local demo routes; deliberately separate from the protocol handler. */
44
+ export const createUiHandler = (world, protocol) => {
45
+ let page;
46
+ return async (request) => {
47
+ const path = new URL(request.url).pathname;
48
+ if (path !== "/" && path !== "/ui/types")
49
+ return protocol(request);
50
+ if (request.method !== "GET" && request.method !== "HEAD")
51
+ return new Response("Use GET or HEAD.", { status: 405, headers: { allow: "GET, HEAD" } });
52
+ const response = path === "/ui/types"
53
+ ? Response.json(world.types)
54
+ : new Response(await (page ??= readFile(new URL("../static/ui.html", import.meta.url), "utf8")), {
55
+ headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-cache" },
56
+ });
57
+ return request.method === "HEAD"
58
+ ? new Response(null, { status: response.status, headers: response.headers })
59
+ : response;
60
+ };
61
+ };
62
+ /** The only socket boundary; tests exercise createHandler directly. Binds loopback by default. */
63
+ export const serve = async (options) => {
64
+ if (options.source) {
65
+ const report = await deployDirectory(options.source, { db: options.db });
66
+ if (!report.ok)
67
+ throw new Error(report.diagnostics.map((d) => `${d.code} ${d.message}`).join("; "));
68
+ }
69
+ const world = await open({
70
+ store: sqlite(options.db),
71
+ ...(options.clock ? { clock: options.clock } : {}),
72
+ });
73
+ const protocol = createHandler(world);
74
+ const handler = options.ui ? createUiHandler(world, protocol) : protocol;
75
+ const stopTicks = scheduleTicks(world);
76
+ const server = createServer(async (incoming, outgoing) => {
77
+ const abort = new AbortController();
78
+ outgoing.on("close", () => abort.abort());
79
+ try {
80
+ const chunks = [];
81
+ let size = 0;
82
+ for await (const chunk of incoming) {
83
+ size += chunk.length;
84
+ if (size > 1_048_576) {
85
+ outgoing.writeHead(413).end();
86
+ return;
87
+ }
88
+ chunks.push(Buffer.from(chunk));
89
+ }
90
+ const headers = new Headers();
91
+ for (const [key, value] of Object.entries(incoming.headers))
92
+ if (value !== undefined)
93
+ headers.set(key, Array.isArray(value) ? value.join(", ") : value);
94
+ const method = incoming.method ?? "GET";
95
+ const response = await handler(new Request(`http://localhost${incoming.url ?? "/"}`, {
96
+ method,
97
+ headers,
98
+ signal: abort.signal,
99
+ ...(method === "GET" || method === "HEAD" ? {} : { body: Buffer.concat(chunks) }),
100
+ }));
101
+ outgoing.writeHead(response.status, Object.fromEntries(response.headers));
102
+ if (response.body)
103
+ await pipeline(Readable.fromWeb(response.body), outgoing);
104
+ else
105
+ outgoing.end();
106
+ }
107
+ catch {
108
+ if (!outgoing.headersSent)
109
+ outgoing
110
+ .writeHead(500, { "content-type": "application/json" })
111
+ .end(JSON.stringify(failure("internal", "HTTP request failed.")));
112
+ else
113
+ outgoing.destroy();
114
+ }
115
+ });
116
+ try {
117
+ await new Promise((resolve, reject) => {
118
+ server.once("error", reject);
119
+ server.listen(options.port ?? 3000, "127.0.0.1", () => {
120
+ server.removeListener("error", reject);
121
+ resolve();
122
+ });
123
+ });
124
+ }
125
+ catch (cause) {
126
+ stopTicks();
127
+ await world.close();
128
+ throw cause;
129
+ }
130
+ return {
131
+ world,
132
+ server,
133
+ close: async () => {
134
+ stopTicks();
135
+ server.closeAllConnections();
136
+ await new Promise((resolve, reject) => server.close((e) => (e ? reject(e) : resolve())));
137
+ await world.close();
138
+ },
139
+ };
140
+ };
@@ -0,0 +1,19 @@
1
+ import type { IR, World } from "./_internal/reconciler/index.js";
2
+ import type { CliDiagnostic } from "./project.js";
3
+ /** An in-memory host snapshot; the CLI never reads a clock, so the instant is always explicit. */
4
+ export interface WorldSnapshot {
5
+ readonly format: "worldvm/world@1";
6
+ /** Accounts whose programs evaluate this world, in order. */
7
+ readonly accounts: readonly string[];
8
+ /** The release the exported records were last written under, when known. */
9
+ readonly release?: string;
10
+ readonly world: World;
11
+ }
12
+ /** Export committed records without opening a host or evaluating them under new rules. */
13
+ export declare const snapshotDatabase: (filename: string, account: string) => Promise<WorldSnapshot>;
14
+ /** Reads a snapshot and checks that every world it will be evaluated under declares its accounts. */
15
+ export declare const readSnapshot: (input: string, worlds: readonly IR.WorldIR[], code: string) => Promise<{
16
+ readonly snapshot: WorldSnapshot;
17
+ } | {
18
+ readonly diagnostic: CliDiagnostic;
19
+ }>;