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,316 @@
1
+ import { sourceSyntax } from "../source-syntax.js";
2
+ import {} from "@forma-language/forma/descriptor";
3
+ import {} from "@forma-language/forma/reader";
4
+ import { sourceContext } from "./sources.js";
5
+ import { KERNEL_FUNCTIONS, LowerError, VALUE, headOf, children, isSym, option, items, spanOf, symName, typeRef, } from "./syntax.js";
6
+ export const makeSyntaxContext = (files, declarations) => {
7
+ const text = new Map(files.map((f) => [f.id, f.text]));
8
+ const syntax = new Map();
9
+ const authoredTypes = [];
10
+ for (const file of files) {
11
+ for (const form of sourceSyntax(file).forms) {
12
+ syntax.set(`${file.id}@${form.loc.start}`, form);
13
+ if (headOf(form) === "type" && isSym(items(form)[1]))
14
+ authoredTypes.push({
15
+ name: symName(items(form)[1]),
16
+ type: typeRef(items(form)[2]),
17
+ at: spanOf(file.id, form),
18
+ });
19
+ }
20
+ }
21
+ const byForm = (form) => declarations.filter((d) => d.formName === form);
22
+ const payload = (d) => d.payload;
23
+ const formOf = (d) => {
24
+ const found = syntax.get(`${d.sourceId}@${d.span.startOffset}`);
25
+ if (!found)
26
+ throw new Error(`No syntax for ${d.summary.name}`);
27
+ return found;
28
+ };
29
+ const at = (d, e) => spanOf(d.sourceId, e);
30
+ const source = (d, e) => text.get(d.sourceId).slice(e.loc.start, e.loc.end);
31
+ return { authoredTypes, byForm, payload, formOf, at, source };
32
+ };
33
+ export const createLoweringContext = (files, declarations) => {
34
+ const base = makeSyntaxContext(files, declarations);
35
+ const { authoredTypes, byForm, payload, formOf, at, source } = base;
36
+ const { references, citations } = sourceContext(base);
37
+ const roles = new Map(byForm("role").map((d) => [d.summary.name, payload(d)]));
38
+ const entities = new Map(byForm("entity").map((d) => [
39
+ d.summary.name,
40
+ payload(d),
41
+ ]));
42
+ const components = new Map(byForm("component").map((d) => [d.summary.name, payload(d)]));
43
+ const derives = new Map(byForm("derive").map((d) => [
44
+ d.summary.name,
45
+ payload(d),
46
+ ]));
47
+ const evidenceNames = new Set(byForm("evidence").map((d) => d.summary.name));
48
+ const decisionNames = new Set(byForm("decision").map((d) => d.summary.name));
49
+ const calendarNames = new Set(byForm("calendar").map((d) => d.summary.name));
50
+ const libraries = byForm("library").map((d) => payload(d));
51
+ const subject = libraries[0]?.subject;
52
+ const typeOf = (ref, seen = new Set()) => {
53
+ if (typeof ref === "string") {
54
+ const alias = authoredTypes.find((alias) => alias.name === ref);
55
+ if (alias && !seen.has(ref))
56
+ return typeOf(alias.type, new Set([...seen, ref]));
57
+ }
58
+ if (Array.isArray(ref)) {
59
+ const [head, arg] = ref;
60
+ if (head === "Option")
61
+ return typeOf(arg, seen);
62
+ if (head === "List")
63
+ return { t: "list", of: typeOf(arg, seen) };
64
+ if (head === "Id" && typeof arg === "string")
65
+ return roles.has(arg)
66
+ ? { t: "role", name: arg }
67
+ : entities.has(arg)
68
+ ? { t: "entity", name: arg }
69
+ : components.has(arg)
70
+ ? { t: "inst", name: arg }
71
+ : VALUE;
72
+ }
73
+ return VALUE;
74
+ };
75
+ const homeOf = (name, visiting = new Set()) => {
76
+ if (visiting.has(name))
77
+ return undefined;
78
+ const component = components.get(name);
79
+ const first = component.key[0];
80
+ const type = typeOf(component.inputs.find((f) => f.name === first)?.type);
81
+ if (first && (type.t === "role" || type.t === "entity"))
82
+ return { kind: "input", path: [first] };
83
+ if (first && type.t === "inst") {
84
+ const target = homeOf(type.name, new Set([...visiting, name]));
85
+ if (!target)
86
+ return undefined;
87
+ return {
88
+ kind: "input",
89
+ path: [first, ...target.path],
90
+ };
91
+ }
92
+ return undefined;
93
+ };
94
+ const fieldType = (owner, field) => {
95
+ if (owner.t === "role") {
96
+ const found = roles.get(owner.name)?.fields.find((f) => f.name === field);
97
+ return found ? typeOf(found.type) : undefined;
98
+ }
99
+ if (owner.t === "entity") {
100
+ const found = entities.get(owner.name)?.fields.find((f) => f.name === field);
101
+ return found ? typeOf(found.type) : undefined;
102
+ }
103
+ if (owner.t === "inst") {
104
+ const c = components.get(owner.name);
105
+ if (!c)
106
+ return undefined;
107
+ if (field === "attached")
108
+ return { t: "list", of: subject ? { t: "role", name: subject } : VALUE };
109
+ const input = c.inputs.find((f) => f.name === field);
110
+ if (input)
111
+ return typeOf(input.type);
112
+ if ([...c.requirements, ...c.outputs].some((r) => r.name === field))
113
+ return { t: "status" };
114
+ }
115
+ return undefined;
116
+ };
117
+ const componentScope = (name) => {
118
+ const c = components.get(name);
119
+ return new Map([
120
+ ...c.inputs.map((f) => [f.name, typeOf(f.type)]),
121
+ ...c.params.map((f) => [f.name, VALUE]),
122
+ ["self", { t: "inst", name }],
123
+ ["attached", { t: "list", of: subject ? { t: "role", name: subject } : VALUE }],
124
+ ["today", VALUE],
125
+ ["now", VALUE],
126
+ ...c.requirements.map((r) => [r.name, { t: "status" }]),
127
+ ...c.machines.map((m) => [m.name, { t: "machine" }]),
128
+ ]);
129
+ };
130
+ const fieldScope = (fields) => new Map([
131
+ ...fields.map((f) => [f.name, VALUE]),
132
+ ["today", VALUE],
133
+ ["now", VALUE],
134
+ ]);
135
+ // ── Expressions ──
136
+ const lowerExpr = (d, e, scope) => lowerTyped(d, e, scope).expr;
137
+ const lowerTyped = (d, e, scope, paramTypes = []) => {
138
+ const here = at(d, e);
139
+ switch (e._tag) {
140
+ case "Num":
141
+ return { expr: { k: "lit", v: Number(e.value), at: here }, type: VALUE };
142
+ case "Str":
143
+ case "Bool":
144
+ return { expr: { k: "lit", v: e.value, at: here }, type: VALUE };
145
+ case "Vector": {
146
+ const lowered = e.items.map((x) => lowerTyped(d, x, scope));
147
+ return {
148
+ expr: { k: "list", items: lowered.map((x) => x.expr), at: here },
149
+ type: { t: "list", of: lowered[0]?.type ?? VALUE },
150
+ };
151
+ }
152
+ case "Sym": {
153
+ if (e.name === "nil")
154
+ return { expr: { k: "lit", v: null, at: here }, type: VALUE };
155
+ if (e.name.startsWith(":"))
156
+ return { expr: { k: "kw", v: e.name.slice(1), at: here }, type: VALUE };
157
+ const [root, ...fields] = e.name.split(".");
158
+ let type = scope.get(root);
159
+ let expr;
160
+ if (type)
161
+ expr = { k: "var", name: root, at: here };
162
+ else if (fields.length === 0 && evidenceNames.has(e.name))
163
+ return { expr: { k: "ref", kind: "evidence", name: e.name, at: here }, type: VALUE };
164
+ else if (fields.length === 0 && byForm("notice").some((n) => n.summary.name === e.name))
165
+ return { expr: { k: "ref", kind: "notice", name: e.name, at: here }, type: VALUE };
166
+ else if (fields.length === 0 && decisionNames.has(e.name))
167
+ return { expr: { k: "ref", kind: "decision", name: e.name, at: here }, type: VALUE };
168
+ else if (fields.length === 0 && calendarNames.has(e.name))
169
+ return { expr: { k: "ref", kind: "calendar", name: e.name, at: here }, type: VALUE };
170
+ else
171
+ throw new LowerError("E_LOWER", `${e.name} is not in scope here.`, here);
172
+ let path = root;
173
+ for (const field of fields) {
174
+ path = `${path}.${field}`;
175
+ const next = fieldType(type, field);
176
+ if (!next || type.t === "list" || type.t === "value")
177
+ throw new LowerError("E_LOWER", `${path} does not name a field.`, here);
178
+ expr =
179
+ type.t === "role"
180
+ ? { k: "read", role: type.name, field, of: expr, meta: { path }, at: here }
181
+ : type.t === "entity"
182
+ ? {
183
+ k: "attr",
184
+ attr: `${entities.get(type.name).ns}/${field}`,
185
+ of: expr,
186
+ meta: { path },
187
+ at: here,
188
+ }
189
+ : { k: "inst", field, of: expr, at: here };
190
+ type = next;
191
+ }
192
+ return { expr, type: type };
193
+ }
194
+ case "List": {
195
+ const head = symName(e.items[0]);
196
+ const args = e.items.slice(1);
197
+ if (head === "table" && d.formName !== "derive")
198
+ throw new LowerError("E_TABLE_SCOPE", "Tables belong inside a derive.", here, "Move the table into a named derive and call it with the selector as a parameter.");
199
+ if (head === "added-on") {
200
+ const owner = d.formName === "component" ? d.summary.name : symName(option(formOf(d), "of"));
201
+ const declaration = byForm("component").find((c) => c.summary.name === owner);
202
+ const literal = symName(args[0]);
203
+ const target = literal?.startsWith(":") ? literal.slice(1) : undefined;
204
+ const targets = declaration
205
+ ? [
206
+ ...children(formOf(declaration), "requirement"),
207
+ ...children(formOf(declaration), "child"),
208
+ ]
209
+ : [];
210
+ if (args.length !== 1 ||
211
+ !targets.some((item) => symName(items(item)[1]) === target && option(item, "discretionary")))
212
+ throw new LowerError("E_DISCRETIONARY_TARGET", "added-on requires an owned discretionary item.", at(d, args[0] ?? e), "Use the literal keyword of an owned discretionary requirement or child, such as :review.");
213
+ return {
214
+ expr: {
215
+ k: "call",
216
+ fn: head,
217
+ args: [{ k: "kw", v: target, at: at(d, args[0]) }],
218
+ at: here,
219
+ },
220
+ type: VALUE,
221
+ };
222
+ }
223
+ if (head === "if") {
224
+ const [test, then, otherwise] = args.map((x) => lowerTyped(d, x, scope));
225
+ return {
226
+ expr: { k: "if", test: test.expr, then: then.expr, else: otherwise.expr, at: here },
227
+ type: then.type,
228
+ };
229
+ }
230
+ if (head === "fn") {
231
+ const params = items(args[0]).map((p) => symName(p));
232
+ const inner = new Map(scope);
233
+ params.forEach((p, i) => inner.set(p, paramTypes[i] ?? VALUE));
234
+ const body = lowerTyped(d, args[1], inner);
235
+ return { expr: { k: "fn", params, body: body.expr, at: here }, type: VALUE };
236
+ }
237
+ if (!head)
238
+ throw new LowerError("E_LOWER", "Expected a function call.", here);
239
+ if (head === "and" || head === "or" || head === "not") {
240
+ const operands = args.map((arg) => lowerTyped(d, arg, scope));
241
+ const values = operands.map((operand) => operand.expr);
242
+ const canonicalArgs = head === "not" || (operands.length === 1 && operands[0].type.t === "list")
243
+ ? values
244
+ : [{ k: "list", items: values, at: here }];
245
+ return {
246
+ expr: {
247
+ k: "call",
248
+ fn: head === "and" ? "all?" : head === "or" ? "any?" : "negate",
249
+ args: canonicalArgs,
250
+ at: here,
251
+ },
252
+ type: VALUE,
253
+ };
254
+ }
255
+ // != is an authoring alias of not=; lowering to not= keeps one IR spelling.
256
+ if (head === "!=")
257
+ return lowerTyped(d, { ...e, items: [{ ...e.items[0], name: "not=" }, ...e.items.slice(1)] }, scope, paramTypes);
258
+ // Higher-order calls: a function argument's parameter is an element of the list argument.
259
+ const listIndex = head === "spells" ? 0 : head === "map" || head === "filter" ? 1 : -1;
260
+ const listArg = listIndex >= 0 ? lowerTyped(d, args[listIndex], scope) : undefined;
261
+ const element = listArg?.type.t === "list" ? listArg.type.of : VALUE;
262
+ const lowered = args.map((x, i) => i === listIndex ? listArg : lowerTyped(d, x, scope, headOf(x) === "fn" ? [element] : []));
263
+ const derive = derives.get(head);
264
+ if (!derive && !KERNEL_FUNCTIONS.has(head))
265
+ throw new LowerError("E_LOWER", `${head} is not a kernel function or a derive.`, here);
266
+ const type = derive
267
+ ? typeOf(derive.returns)
268
+ : head === "map"
269
+ ? { t: "list", of: VALUE }
270
+ : head === "filter" || head === "spells"
271
+ ? { t: "list", of: head === "spells" ? (listArg?.type ?? VALUE) : element }
272
+ : VALUE;
273
+ return {
274
+ expr: {
275
+ k: "call",
276
+ fn: head,
277
+ args: lowered.map((x) => x.expr),
278
+ ...(derive ? { derive: true } : {}),
279
+ at: here,
280
+ },
281
+ type,
282
+ };
283
+ }
284
+ default:
285
+ throw new LowerError("E_LOWER", `Unsupported expression ${e._tag}.`, here);
286
+ }
287
+ };
288
+ const maybe = (d, e, scope) => e === undefined ? undefined : lowerExpr(d, e, scope);
289
+ const docOf = (doc) => (doc === undefined ? {} : { doc });
290
+ const labelOf = (label) => (label === undefined ? {} : { label });
291
+ // ── Declarations ──
292
+ return {
293
+ ...base,
294
+ references,
295
+ citations,
296
+ roles,
297
+ entities,
298
+ components,
299
+ derives,
300
+ evidenceNames,
301
+ decisionNames,
302
+ calendarNames,
303
+ libraries,
304
+ subject,
305
+ typeOf,
306
+ homeOf,
307
+ fieldType,
308
+ componentScope,
309
+ fieldScope,
310
+ lowerExpr,
311
+ lowerTyped,
312
+ maybe,
313
+ docOf,
314
+ labelOf,
315
+ };
316
+ };
@@ -0,0 +1,7 @@
1
+ import { componentContractSurface } from "../../../ir-checks/index.js";
2
+ import type * as IR from "../../../world-ir/types.generated.js";
3
+ import type { LoweringContext } from "./context.js";
4
+ export declare const lowerContracts: (cx: LoweringContext, ir: Parameters<typeof componentContractSurface>[0]) => {
5
+ componentImports?: readonly [IR.ComponentImport, ...IR.ComponentImport[]];
6
+ componentContracts?: readonly [IR.ComponentContract, ...IR.ComponentContract[]];
7
+ };
@@ -0,0 +1,73 @@
1
+ import { componentContractDigest, componentContractSurface } from "../../../ir-checks/index.js";
2
+ import { items, option, symName, LowerError } from "./syntax.js";
3
+ export const lowerContracts = (cx, ir) => {
4
+ const error = (d, value, message, code = "E_COMPONENT_CONTRACT") => {
5
+ throw new LowerError(code, message, cx.at(d, value), "Export an explicitly library-owned component with unique declared outputs, actions/decisions and connector services. Import its named contract from the exact provider library version.");
6
+ };
7
+ const contracts = cx.byForm("component-contract").map((d) => {
8
+ const form = cx.formOf(d), owner = option(form, "library"), target = option(form, "of");
9
+ const library = cx.libraries.find((l) => l.name === symName(owner)), component = ir.components.find((c) => c.name === symName(target));
10
+ if (!library)
11
+ error(d, owner, "The exporting library must be declared.");
12
+ if (!component || component.library !== library.name)
13
+ error(d, target, "Export a component owned by the named library.");
14
+ const names = (key, valid) => {
15
+ const value = option(form, key);
16
+ if (!value && key === "capabilities")
17
+ return [];
18
+ if (!value)
19
+ return error(d, form, `:${key} must be an explicit vector.`);
20
+ if (value._tag !== "Vector")
21
+ return error(d, value, `:${key} must be an explicit vector.`);
22
+ const result = [];
23
+ for (const item of items(value)) {
24
+ const name = symName(item);
25
+ if (!name || !valid.includes(name) || result.includes(name))
26
+ error(d, item, `:${key} needs unique declared names.`, key === "operations" ? "E_NOT_AN_OPERATION" : "E_COMPONENT_CONTRACT");
27
+ result.push(name);
28
+ }
29
+ return result;
30
+ };
31
+ const surface = componentContractSurface(ir, component, names("outputs", component.outputs.map((o) => o.name)), names("operations", [
32
+ ...(component.operations ?? [
33
+ ...component.actions.map((a) => a.name),
34
+ ...(ir.decisions ?? []).filter((x) => x.of === component.name).map((x) => x.name),
35
+ ]),
36
+ ]), names("capabilities", ir.connectors.map((c) => c.name)));
37
+ const contract = { name: d.summary.name, library: library.name, ...surface };
38
+ return {
39
+ ...contract,
40
+ ...cx.docOf(cx.payload(d).doc),
41
+ digest: componentContractDigest(contract),
42
+ at: cx.at(d, form),
43
+ };
44
+ });
45
+ const imports = cx.byForm("component-import").map((d) => {
46
+ const form = cx.formOf(d), get = (key) => option(form, key);
47
+ const consumer = symName(get("library")), provider = symName(get("from")), contract = contracts.find((c) => c.name === symName(get("contract")));
48
+ if (!cx.libraries.some((l) => l.name === consumer))
49
+ error(d, get("library"), "Declare the consuming library.", "E_COMPONENT_IMPORT");
50
+ if (!contract || contract.library !== provider)
51
+ error(d, get("contract"), "Import a named contract exported by this provider.", "E_COMPONENT_IMPORT");
52
+ const version = get("version");
53
+ if (version._tag !== "Str" ||
54
+ !cx.libraries.some((l) => l.name === provider && l.version === version.value))
55
+ error(d, version, "Pin the declared provider library version.", "E_COMPONENT_IMPORT");
56
+ return {
57
+ name: d.summary.name,
58
+ ...cx.docOf(cx.payload(d).doc),
59
+ library: consumer,
60
+ from: provider,
61
+ version: version.value,
62
+ contract: contract.name,
63
+ digest: contract.digest,
64
+ at: cx.at(d, form),
65
+ };
66
+ });
67
+ return {
68
+ ...(contracts.length
69
+ ? { componentContracts: [contracts[0], ...contracts.slice(1)] }
70
+ : {}),
71
+ ...(imports.length ? { componentImports: [imports[0], ...imports.slice(1)] } : {}),
72
+ };
73
+ };
@@ -0,0 +1,3 @@
1
+ import type * as IR from "../../../world-ir/types.generated.js";
2
+ import { type LoweringContext } from "./context.js";
3
+ export declare const lowerDecisions: (context: LoweringContext, componentIR: readonly IR.Component[]) => IR.Decision[];
@@ -0,0 +1,164 @@
1
+ import { priorCycleDecisions, reuseDecisions } from "../../../ir-checks/index.js";
2
+ import { inputHomeOf } from "../homes.js";
3
+ import { contentDigest } from "../digest.js";
4
+ import {} from "./context.js";
5
+ import { childNamed, items, LowerError, option, symName, typeRef } from "./syntax.js";
6
+ const closed = (component, name, e, bound = new Set()) => {
7
+ if (e.k === "var" &&
8
+ !bound.has(e.name) &&
9
+ component.inputs.some((i) => i.name === e.name) &&
10
+ !component.key.includes(e.name))
11
+ throw new LowerError("E_READ_OUTSIDE_KEY", `Decision ${name} reads non-key input ${e.name}.`, e.at, "Read only key inputs and their reference paths, or include this input in the component key.");
12
+ if (e.k === "fn")
13
+ closed(component, name, e.body, new Set([...bound, ...e.params]));
14
+ if (e.k === "call")
15
+ e.args.forEach((a) => closed(component, name, a, bound));
16
+ if (e.k === "list")
17
+ e.items.forEach((a) => closed(component, name, a, bound));
18
+ if (e.k === "if") {
19
+ closed(component, name, e.test, bound);
20
+ closed(component, name, e.then, bound);
21
+ closed(component, name, e.else, bound);
22
+ }
23
+ if (e.k === "read" || e.k === "attr" || e.k === "inst")
24
+ closed(component, name, e.of, bound);
25
+ };
26
+ export const lowerDecisions = (context, componentIR) => {
27
+ const { byForm, formOf, at, componentScope, lowerExpr, authoredTypes, docOf, payload, lowerTyped, citations, } = context;
28
+ const decisionIR = byForm("decision").map((d) => {
29
+ const form = formOf(d), name = d.summary.name, owner = symName(option(form, "of"));
30
+ const component = componentIR.find((c) => c.name === owner);
31
+ const applies = option(form, "applies"), effect = option(form, "effect");
32
+ const target = symName(applies);
33
+ const kind = symName(effect).replace(/^:/, "");
34
+ const targets = [
35
+ ...component.requirements,
36
+ ...component.slots.filter((s) => s.mode === "child"),
37
+ ].filter((r) => r.name === target);
38
+ if (kind === "add"
39
+ ? targets.length !== 1 || targets[0].discretionary !== name
40
+ : !component.requirements.some((r) => r.name === target))
41
+ throw new LowerError("E_DECISION_TARGET", `${owner}/${target} is not an owned target for this decision.`, at(d, applies), kind === "add"
42
+ ? "Choose one owned requirement or child whose :discretionary names this add decision."
43
+ : "Choose a requirement declared on the decision's :of component.");
44
+ if (!["approve", "reject", "waive", "defer", "accept", "add"].includes(kind))
45
+ throw new LowerError("E_DECISION_EFFECT", `Unsupported decision effect ${kind}.`, at(d, effect), "Choose :approve, :reject, :waive, :defer, :accept or :add.");
46
+ const scope = componentScope(owner);
47
+ const expression = (key) => {
48
+ const syntax = option(form, key);
49
+ if (!syntax)
50
+ return undefined;
51
+ const expr = lowerExpr(d, syntax, scope);
52
+ closed(component, name, expr);
53
+ return expr;
54
+ };
55
+ const by = expression("by"), when = expression("when"), until = expression("until"), expires = expression("expires"), approvals = expression("approvals");
56
+ if (approvals?.k === "lit" && (!Number.isSafeInteger(approvals.v) || Number(approvals.v) < 1))
57
+ throw new LowerError("E_DECISION_APPROVALS", "A decision requires a positive integer approval count.", approvals.at, "Use a positive integer or an Int expression that produces a positive count.");
58
+ const exclusions = option(form, "distinct-from");
59
+ if (exclusions && exclusions._tag !== "Vector")
60
+ throw new LowerError("E_DECISION_DISTINCT", "Decision exclusions must be a vector.", at(d, exclusions), "Use a vector of entity references, such as [person].");
61
+ const distinctFrom = exclusions
62
+ ? items(exclusions).map((syntax) => {
63
+ const lowered = lowerTyped(d, syntax, scope);
64
+ if (!["role", "entity"].includes(lowered.type.t))
65
+ throw new LowerError("E_DECISION_DISTINCT", "A decision exclusion must resolve to an entity reference.", at(d, syntax), "Use an entity reference from the component key or its reference paths.");
66
+ closed(component, name, lowered.expr);
67
+ return lowered.expr;
68
+ })
69
+ : undefined;
70
+ const byKind = ["role", "entity"].includes(lowerTyped(d, option(form, "by"), scope).type.t)
71
+ ? "individual"
72
+ : "group";
73
+ if (byKind === "individual" &&
74
+ distinctFrom?.some((e) => contentDigest(e) === contentDigest(by)))
75
+ throw new LowerError("E_SELF_APPROVAL", "The decision authority is explicitly excluded from signing.", at(d, option(form, "by")), "Choose a different principal or a reviewer group; the excluded person cannot approve their own work.");
76
+ const reason = option(form, "reason");
77
+ const supportedReason = (t, seen = new Set()) => {
78
+ if (Array.isArray(t)) {
79
+ if (t[0] === "Option" || t[0] === "Brand")
80
+ return t.length === 2 && supportedReason(t[1], seen);
81
+ return (t[0] === "Union" &&
82
+ t.length > 1 &&
83
+ t.slice(1).every((v) => typeof v === "string" && v.startsWith(":")));
84
+ }
85
+ if (typeof t !== "string" || seen.has(t))
86
+ return false;
87
+ const alias = authoredTypes.find((a) => a.name === t);
88
+ return alias
89
+ ? supportedReason(alias.type, new Set([...seen, t]))
90
+ : ["String", "Keyword", "Group", "Int", "Float", "Bool", "Date"].includes(t);
91
+ };
92
+ if (reason && !supportedReason(typeRef(reason)))
93
+ throw new LowerError("E_DECISION_REASON", "Unsupported decision reason type.", at(d, reason), "Use a scalar reason type, a keyword union, or an Option/Brand/alias of one; structured records belong in evidence.");
94
+ return {
95
+ name,
96
+ ...docOf(payload(d).doc),
97
+ of: owner,
98
+ by,
99
+ byKind,
100
+ applies: target,
101
+ effect: kind,
102
+ reason: reason ? typeRef(reason) : ["Option", "String"],
103
+ ...(when ? { when } : {}),
104
+ ...(until ? { until } : {}),
105
+ ...(expires ? { expires } : {}),
106
+ ...(approvals ? { approvals } : {}),
107
+ ...(distinctFrom ? { distinctFrom } : {}),
108
+ ...citations(d, form),
109
+ at: at(d, form),
110
+ };
111
+ });
112
+ for (const component of componentIR)
113
+ for (const requirement of component.requirements)
114
+ for (const definition of reuseDecisions(component, requirement))
115
+ if (!decisionIR.some((d) => d.name === definition.name && d.of === definition.of))
116
+ decisionIR.push(definition);
117
+ for (const component of componentIR)
118
+ for (const requirement of component.requirements)
119
+ if (requirement.accepts) {
120
+ if (requirement.accepts.with) {
121
+ const target = component.requirements.find((r) => r.name === requirement.accepts.with);
122
+ if (requirement.accepts.from || !target?.accepts?.from || target.accepts.with) {
123
+ const declaration = byForm("component").find((d) => d.summary.name === component.name);
124
+ const syntax = option(childNamed(formOf(declaration), "requirement", requirement.name), "accepts");
125
+ throw new LowerError("E_DECISION_TARGET", "Prior-cycle :with must name a direct owned confirmation.", at(declaration, syntax), "Use :from for an owned confirmation, or :with naming a direct owned confirmation with :from; do not combine them or chain aliases.");
126
+ }
127
+ continue;
128
+ }
129
+ if (!requirement.accepts.from)
130
+ continue;
131
+ const path = inputHomeOf(component).path;
132
+ let by = { k: "var", name: path[0], at: requirement.at };
133
+ for (const field of path.slice(1))
134
+ by = { k: "inst", of: by, field, at: requirement.at };
135
+ if (requirement.accepts.confirm)
136
+ by = requirement.accepts.confirm;
137
+ closed(component, `prior-cycle ${requirement.name}`, by);
138
+ if (requirement.accepts.within)
139
+ closed(component, `prior-cycle ${requirement.name}`, requirement.accepts.within);
140
+ const declaration = byForm("component").find((d) => d.summary.name === component.name);
141
+ const syntax = option(childNamed(formOf(declaration), "requirement", requirement.name), "accepts");
142
+ const confirm = option(syntax, "confirm");
143
+ const byKind = confirm &&
144
+ !["role", "entity"].includes(lowerTyped(declaration, confirm, componentScope(component.name)).type.t)
145
+ ? "group"
146
+ : "individual";
147
+ const explicit = decisionIR.filter((d) => d.of === component.name && d.applies === requirement.name && d.effect === "accept");
148
+ if (explicit.length > 1)
149
+ throw new LowerError("E_DECISION_TARGET", "Prior-cycle confirmation has multiple accept policies.", requirement.at, "Declare one accept decision per prior-cycle requirement so confirmation has a single authority policy.");
150
+ const defaults = priorCycleDecisions({
151
+ component: component.name,
152
+ requirement: requirement.name,
153
+ by,
154
+ byKind,
155
+ at: requirement.at,
156
+ ...(requirement.cites ? { cites: requirement.cites } : {}),
157
+ });
158
+ decisionIR.push(...(explicit[0]
159
+ ? [{ ...explicit[0], name: defaults[1].name, effect: "reject" }]
160
+ : defaults));
161
+ }
162
+ // Library identity is its content, not its spans.
163
+ return decisionIR;
164
+ };
@@ -0,0 +1,3 @@
1
+ import type * as IR from "../../../world-ir/types.generated.js";
2
+ import { type LoweringContext } from "./context.js";
3
+ export declare const lowerDerives: (context: LoweringContext) => IR.Derive[];
@@ -0,0 +1,22 @@
1
+ import {} from "./context.js";
2
+ import { items, VALUE } from "./syntax.js";
3
+ export const lowerDerives = (context) => {
4
+ const { byForm, derives, formOf, typeOf, docOf, lowerExpr, at } = context;
5
+ return byForm("derive").map((d) => {
6
+ const p = derives.get(d.summary.name);
7
+ const form = formOf(d);
8
+ const scope = new Map([
9
+ ...p.params.map((f) => [f.name, typeOf(f.type)]),
10
+ ["today", VALUE],
11
+ ["now", VALUE],
12
+ ]);
13
+ return {
14
+ name: d.summary.name,
15
+ ...docOf(p.doc),
16
+ params: p.params,
17
+ returns: p.returns,
18
+ body: lowerExpr(d, items(form).at(-1), scope),
19
+ at: at(d, form),
20
+ };
21
+ });
22
+ };
@@ -0,0 +1,7 @@
1
+ import type { ElaboratedDeclaration } from "@forma-language/forma/descriptor";
2
+ import type { SExpr } from "@forma-language/forma/reader";
3
+ import type { LoweringContext } from "./context.js";
4
+ /** One named operation owns authority and timing; the item only opts into that operation. */
5
+ export declare const lowerDiscretionary: (context: LoweringContext, owner: ElaboratedDeclaration, item: SExpr, target: string) => {
6
+ readonly discretionary?: string;
7
+ };
@@ -0,0 +1,15 @@
1
+ import { LowerError, option, symName } from "./syntax.js";
2
+ /** One named operation owns authority and timing; the item only opts into that operation. */
3
+ export const lowerDiscretionary = (context, owner, item, target) => {
4
+ const syntax = option(item, "discretionary");
5
+ if (!syntax)
6
+ return {};
7
+ const name = symName(syntax), decision = context.byForm("decision").find((d) => d.summary.name === name);
8
+ const form = decision ? context.formOf(decision) : undefined;
9
+ if (!form ||
10
+ symName(option(form, "of")) !== owner.summary.name ||
11
+ symName(option(form, "applies")) !== target ||
12
+ symName(option(form, "effect")) !== ":add")
13
+ throw new LowerError("E_DISCRETIONARY_TARGET", "Discretionary work must name its owned add decision.", context.at(owner, syntax), "Name an owned decision with :effect :add and :applies naming this requirement or child.");
14
+ return { discretionary: name };
15
+ };
@@ -0,0 +1,3 @@
1
+ import type * as IR from "../../../world-ir/types.generated.js";
2
+ import type { LoweringContext } from "./context.js";
3
+ export declare const lowerDocuments: (cx: LoweringContext, evidence: readonly IR.Evidence[]) => IR.Document[];