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,3 @@
1
+ import type * as IR from "../../world-ir/types.generated.js";
2
+ import type { SourceFile } from "./compile.js";
3
+ export declare const sensitivitySourceDiagnostics: (files: readonly SourceFile[]) => IR.Diagnostic[];
@@ -0,0 +1,118 @@
1
+ import { sourceSyntax } from "./source-syntax.js";
2
+ import {} from "@forma-language/forma/reader";
3
+ import { sensitivityOfType, sensitiveTypeHelp, sensitiveSealHelp } from "../../ir-checks/index.js";
4
+ import { headOf, items, isSym, spanOf, symName, mapPairs, option } from "./lowering/syntax.js";
5
+ /** Source maps are inspected before lowering can lose an unsupported type shape. */
6
+ const reference = (node) => {
7
+ if (isSym(node))
8
+ return node.name;
9
+ if (node._tag === "List" || node._tag === "Vector")
10
+ return node.items.map(reference);
11
+ if (node._tag === "Map")
12
+ return ["Record", ...node.pairs.map(([key, value]) => [reference(key), reference(value)])];
13
+ return "Literal";
14
+ };
15
+ export const sensitivitySourceDiagnostics = (files) => {
16
+ if (!files.some((f) => f.text.includes("Sensitive")))
17
+ return [];
18
+ const forms = files.flatMap((file) => {
19
+ const parsed = sourceSyntax(file);
20
+ return parsed.errors.length ? [] : parsed.forms.map((node) => ({ file, node }));
21
+ });
22
+ const definitions = forms
23
+ .filter(({ node }) => headOf(node) === "type")
24
+ .map(({ file, node }) => {
25
+ const parts = items(node), name = parts[1], body = parts[2];
26
+ return {
27
+ file,
28
+ node,
29
+ name: symName(name) ?? symName(items(name)[0]) ?? "",
30
+ body,
31
+ generic: !isSym(name),
32
+ };
33
+ })
34
+ .filter((d) => d.body && d.name);
35
+ const aliases = definitions.map((d) => ({
36
+ name: d.name,
37
+ type: reference(d.body),
38
+ at: spanOf(d.file.id, d.node),
39
+ }));
40
+ const errors = [];
41
+ const fail = (file, node, code, message) => errors.push({
42
+ code,
43
+ severity: "error",
44
+ message,
45
+ at: spanOf(file.id, node),
46
+ help: code === "E_UNSEALED_SENSITIVE" ? sensitiveSealHelp : sensitiveTypeHelp,
47
+ });
48
+ const containsMap = (node) => node._tag === "Map" || items(node).some(containsMap);
49
+ const shape = (file, node) => {
50
+ const parts = items(node);
51
+ if (headOf(node) === "Sensitive") {
52
+ const c = parts[1];
53
+ if (parts.length !== 3) {
54
+ fail(file, node, "E_SENSITIVE_TYPE", "Sensitive needs exactly a classification and base type.");
55
+ return;
56
+ }
57
+ const result = sensitivityOfType(["Sensitive", c ? reference(c) : "", "String"], []);
58
+ if (!result.ok) {
59
+ fail(file, c ?? node, "E_SENSITIVE_TYPE", result.message);
60
+ return;
61
+ }
62
+ if (parts[2]._tag !== "Sym" && parts[2]._tag !== "List" && parts[2]._tag !== "Vector")
63
+ fail(file, parts[2], "E_SENSITIVE_TYPE", "The sensitive base needs a representable canonical type.");
64
+ }
65
+ if (node._tag === "Map")
66
+ node.pairs.forEach(([, v]) => shape(file, v));
67
+ else
68
+ parts.forEach((p) => shape(file, p));
69
+ };
70
+ for (const d of definitions) {
71
+ shape(d.file, d.body);
72
+ const classification = sensitivityOfType(reference(d.body), aliases);
73
+ if (d.name === "Sensitive")
74
+ fail(d.file, d.node, "E_SENSITIVE_TYPE", "Sensitive is a reserved type constructor.");
75
+ else if (classification.ok &&
76
+ classification.classes.length &&
77
+ (d.generic || containsMap(d.body)))
78
+ fail(d.file, d.node, "E_SENSITIVE_TYPE", "This alias shape cannot preserve sensitive classification in canonical IR.");
79
+ }
80
+ if (errors.length)
81
+ return errors;
82
+ const fields = (file, node, sealed = new Set()) => {
83
+ for (const [key, type] of mapPairs(node)) {
84
+ shape(file, type);
85
+ const result = sensitivityOfType(reference(type), aliases);
86
+ if (result.ok && result.classes.length && !sealed.has((symName(key) ?? "").replace(/^:/, "")))
87
+ fail(file, type, "E_UNSEALED_SENSITIVE", "Sensitive data needs a supported sealing policy.");
88
+ }
89
+ };
90
+ for (const { file, node } of forms) {
91
+ const head = headOf(node);
92
+ if (["role", "entity", "evidence"].includes(head ?? "")) {
93
+ const fieldMap = items(node)
94
+ .filter((n) => n._tag === "Map")
95
+ .at(-1);
96
+ const seal = option(node, "sealed-by");
97
+ const sealed = new Set((head === "evidence" && seal ? mapPairs(fieldMap) : mapPairs(seal)).map(([key]) => (symName(key) ?? "").replace(/^:/, "")));
98
+ fields(file, items(node)
99
+ .filter((n) => n._tag === "Map")
100
+ .at(-1), sealed);
101
+ }
102
+ if (head === "component") {
103
+ fields(file, option(node, "inputs"));
104
+ fields(file, option(node, "params"));
105
+ }
106
+ if (head === "derive") {
107
+ fields(file, option(node, "params"));
108
+ const returns = option(node, "returns");
109
+ if (returns) {
110
+ shape(file, returns);
111
+ const result = sensitivityOfType(reference(returns), aliases);
112
+ if (result.ok && result.classes.length)
113
+ fail(file, returns, "E_UNSEALED_SENSITIVE", "A sensitive derived value needs a supported sealing policy.");
114
+ }
115
+ }
116
+ }
117
+ return errors;
118
+ };
@@ -0,0 +1,6 @@
1
+ import type { SourceFile } from "./compile.js";
2
+ /** Share reader work within a compile; edits to a reused source object invalidate it. */
3
+ export declare const sourceSyntax: (file: SourceFile) => {
4
+ errors: readonly import("@forma-language/forma/reader").ParseError[];
5
+ readonly forms: readonly import("@forma-language/forma/reader").SExpr[];
6
+ };
@@ -0,0 +1,27 @@
1
+ import { parse, toSExprMany } from "@forma-language/forma/reader";
2
+ const cache = new WeakMap();
3
+ const read = (text) => {
4
+ let parsed = parse(text);
5
+ const errors = parsed.errors;
6
+ let forms;
7
+ return {
8
+ errors,
9
+ // Some located checks intentionally inspect the reader's recovered tree before elaboration.
10
+ get forms() {
11
+ if (!forms) {
12
+ forms = toSExprMany(parsed.redTree);
13
+ parsed = undefined;
14
+ }
15
+ return forms;
16
+ },
17
+ };
18
+ };
19
+ /** Share reader work within a compile; edits to a reused source object invalidate it. */
20
+ export const sourceSyntax = (file) => {
21
+ const old = cache.get(file);
22
+ if (old?.text === file.text)
23
+ return old.result;
24
+ const result = read(file.text);
25
+ cache.set(file, { text: file.text, result });
26
+ return result;
27
+ };
@@ -0,0 +1,3 @@
1
+ import type * as IR from "../../world-ir/types.generated.js";
2
+ /** Conservative branch checking, not a proof engine. Built-in output folds retain all statuses. */
3
+ export declare const statusHandlingDiagnostics: (ir: IR.WorldIR) => readonly IR.Diagnostic[];
@@ -0,0 +1,143 @@
1
+ const exceptional = ["Unknown", "NotApplicable"];
2
+ const keyOf = (e) => JSON.stringify(e, (key, value) => (key === "at" ? undefined : value));
3
+ /** Conservative branch checking, not a proof engine. Built-in output folds retain all statuses. */
4
+ export const statusHandlingDiagnostics = (ir) => {
5
+ const components = new Map(ir.components.map((c) => [c.name, c])), diagnostics = new Map();
6
+ const unwrap = (t, seen = new Set()) => {
7
+ if (typeof t === "string") {
8
+ const alias = ir.types.find((a) => a.name === t);
9
+ if (alias && !seen.has(t))
10
+ return unwrap(alias.type, new Set([...seen, t]));
11
+ }
12
+ if (Array.isArray(t) && (t[0] === "Option" || t[0] === "Brand"))
13
+ return unwrap(t[1], seen);
14
+ return t;
15
+ };
16
+ const reference = (t) => {
17
+ const type = unwrap(t);
18
+ return Array.isArray(type) && type[0] === "Id" && typeof type[1] === "string"
19
+ ? type[1]
20
+ : undefined;
21
+ };
22
+ const typeOf = (e, scope) => {
23
+ if (e.k === "var")
24
+ return scope.get(e.name);
25
+ if (e.k === "inst") {
26
+ const target = components.get(reference(typeOf(e.of, scope)) ?? "");
27
+ return [...(target?.inputs ?? []), ...(target?.params ?? [])].find((f) => f.name === e.field)
28
+ ?.type;
29
+ }
30
+ if (e.k === "read")
31
+ return ir.roles.find((r) => r.name === e.role)?.fields.find((f) => f.name === e.field)?.type;
32
+ if (e.k === "attr")
33
+ return ir.entities
34
+ .find((r) => e.attr.startsWith(r.ns + "/"))
35
+ ?.fields.find((f) => f.attr === e.attr)?.type;
36
+ if (e.k === "list")
37
+ return ["List", e.items[0] ? (typeOf(e.items[0], scope) ?? "Unknown") : "Unknown"];
38
+ if (e.k === "if") {
39
+ const a = typeOf(e.then, scope), b = typeOf(e.else, scope);
40
+ return JSON.stringify(a) === JSON.stringify(b) ? a : undefined;
41
+ }
42
+ if (e.k === "call") {
43
+ if (e.fn === "filter")
44
+ return e.args[1] ? typeOf(e.args[1], scope) : undefined;
45
+ return ir.derives.find((d) => d.name === e.fn)?.returns;
46
+ }
47
+ return undefined;
48
+ };
49
+ const outputRead = (e, scope) => {
50
+ if (e.k !== "inst" || (e.of.k === "var" && e.of.name === "self"))
51
+ return false;
52
+ const target = components.get(reference(typeOf(e.of, scope)) ?? "");
53
+ return target
54
+ ? target.outputs.some((o) => o.name === e.field)
55
+ : ir.components.some((c) => c.outputs.some((o) => o.name === e.field));
56
+ };
57
+ const mark = (handled, key, statuses) => new Map([...handled, [key, new Set([...(handled.get(key) ?? []), ...statuses])]]);
58
+ const walk = (e, scope, handled) => {
59
+ if (outputRead(e, scope)) {
60
+ const missing = exceptional.filter((status) => !handled.get(keyOf(e))?.has(status));
61
+ if (missing.length)
62
+ diagnostics.set(JSON.stringify(e.at), {
63
+ code: "W_UNHANDLED_STATUS",
64
+ severity: "warning",
65
+ message: `Custom child-output expression does not explicitly handle ${missing.join(" and ")}.`,
66
+ at: e.at,
67
+ help: "Use all-of/any-of/status-of for output folds, or branch with (status-is? child.output :Unknown) and (status-is? child.output :NotApplicable) before consuming that same output. Helper expressions need the same branches; unsupported control flow is conservatively warned. No automatic fix can choose the intended result.",
68
+ });
69
+ }
70
+ if (e.k === "if") {
71
+ const test = e.test;
72
+ if (test.k === "call" &&
73
+ test.fn === "status-is?" &&
74
+ test.args.length === 2 &&
75
+ outputRead(test.args[0], scope) &&
76
+ test.args[1].k === "kw" &&
77
+ (test.args[1].v === "Unknown" || test.args[1].v === "NotApplicable")) {
78
+ const key = keyOf(test.args[0]), status = test.args[1].v;
79
+ walk(test, scope, mark(handled, key, exceptional));
80
+ walk(e.then, scope, mark(handled, key, exceptional));
81
+ walk(e.else, scope, mark(handled, key, [status]));
82
+ }
83
+ else {
84
+ walk(test, scope, handled);
85
+ walk(e.then, scope, handled);
86
+ walk(e.else, scope, handled);
87
+ }
88
+ }
89
+ else if (e.k === "call") {
90
+ for (const [i, arg] of e.args.entries()) {
91
+ if (arg.k === "fn" && i === 0 && (e.fn === "map" || e.fn === "filter")) {
92
+ const list = unwrap(e.args[1] ? typeOf(e.args[1], scope) : undefined), inner = new Map(scope);
93
+ arg.params.forEach((p) => inner.set(p, Array.isArray(list) && list[0] === "List" ? list[1] : "Unknown"));
94
+ walk(arg.body, inner, new Map());
95
+ }
96
+ else
97
+ walk(arg, scope, handled);
98
+ }
99
+ }
100
+ else if (e.k === "fn") {
101
+ const inner = new Map(scope);
102
+ e.params.forEach((p) => inner.delete(p));
103
+ walk(e.body, inner, new Map());
104
+ }
105
+ else if (e.k === "list")
106
+ e.items.forEach((item) => walk(item, scope, handled));
107
+ else if (e.k === "read" || e.k === "attr" || e.k === "inst")
108
+ walk(e.of, scope, handled);
109
+ };
110
+ const visit = (value, scope) => {
111
+ if (!value || typeof value !== "object")
112
+ return;
113
+ if ("k" in value)
114
+ walk(value, scope, new Map());
115
+ else
116
+ for (const [key, child] of Object.entries(value))
117
+ if (key !== "at")
118
+ visit(child, scope);
119
+ };
120
+ for (const component of ir.components) {
121
+ const scope = new Map([...component.inputs, ...component.params].map((f) => [f.name, f.type]));
122
+ scope.set("self", ["Id", component.name]);
123
+ scope.set("attached", ["List", ["Id", ir.libraries[0].subject]]);
124
+ visit(component, scope);
125
+ for (const d of ir.decisions ?? [])
126
+ if (d.of === component.name)
127
+ visit(d, scope);
128
+ for (const evidence of ir.evidence)
129
+ if (evidence.of === component.name) {
130
+ const fields = new Map([
131
+ ...scope,
132
+ ...evidence.fields.map((f) => [f.name, f.type]),
133
+ ]);
134
+ visit(evidence, fields);
135
+ for (const interaction of ir.interactions)
136
+ if (interaction.produces === evidence.name)
137
+ visit(interaction, fields);
138
+ }
139
+ }
140
+ for (const d of ir.derives)
141
+ walk(d.body, new Map(d.params.map((p) => [p.name, p.type])), new Map());
142
+ return [...diagnostics.values()];
143
+ };
@@ -0,0 +1,30 @@
1
+ import type { SourceFile } from "./compile.js";
2
+ import type * as IR from "../../world-ir/types.generated.js";
3
+ export declare const DIAGNOSTIC_RENAMES: Readonly<Record<string, string>>;
4
+ export declare const diagnosticCode: (code: string, severity: string) => string;
5
+ export declare const OLD_OPERATORS: Readonly<Record<string, string>>;
6
+ export interface SurfaceFix {
7
+ readonly src: string;
8
+ readonly from: number;
9
+ readonly to: number;
10
+ readonly text: string;
11
+ readonly expected: string;
12
+ }
13
+ export type SurfaceDiagnostic = IR.Diagnostic & {
14
+ readonly fix?: SurfaceFix;
15
+ };
16
+ /** One-release migration errors. Reader nodes keep strings, comments and identifiers untouched. */
17
+ export declare const operatorDiagnostics: (files: readonly SourceFile[]) => SurfaceDiagnostic[];
18
+ /** Forma expands Bool and/or/not before inference. Adapt Truth calls for that boundary,
19
+ * then map its locations back to the authored text. Lowering always reads original source. */
20
+ export declare const elaborationSource: (file: SourceFile) => {
21
+ source: string;
22
+ span: <T extends {
23
+ startOffset: number;
24
+ endOffset: number;
25
+ }>(span: T) => T;
26
+ };
27
+ /** Inspect declaration positions only: expression calls and scenario data are not forms. */
28
+ export declare const coreDiagnostics: (files: readonly SourceFile[]) => IR.Diagnostic[];
29
+ /** Keep operator spellings in canonical IR display text stable across source migrations. */
30
+ export declare const canonicalConditionText: (text: string) => string;
@@ -0,0 +1,213 @@
1
+ import { CHILD_FORMS, TOP_LEVEL_FORMS } from "./authoring-help.js";
2
+ import { sourceSyntax } from "./source-syntax.js";
3
+ import { headOf, items, spanOf, option, symName } from "./lowering/syntax.js";
4
+ export const DIAGNOSTIC_RENAMES = Object.fromEntries([
5
+ "read/syntax",
6
+ "parse/syntax",
7
+ "surface/invalid-form",
8
+ "artifact/untyped-runtime-declaration",
9
+ ...[
10
+ "unknown-form",
11
+ "hole-type",
12
+ "unknown-reference",
13
+ "reference-type",
14
+ "missing-slot",
15
+ "invalid-slot-value",
16
+ "malformed-form",
17
+ "duplicate-declaration",
18
+ "form-check",
19
+ "missing-identifier",
20
+ "validation-failed",
21
+ "action-definition",
22
+ "construct-failed",
23
+ "expansion-failed",
24
+ "form-definition",
25
+ "no-construct-hook",
26
+ "result-type-failed",
27
+ "unsupported-form",
28
+ ].map((s) => `elaborate/${s}`),
29
+ ].map((code) => [code, `E_${code.toUpperCase().replaceAll(/[/-]/g, "_")}`]));
30
+ export const diagnosticCode = (code, severity) => (Object.hasOwn(DIAGNOSTIC_RENAMES, code) ? DIAGNOSTIC_RENAMES[code] : undefined) ??
31
+ (/^[a-z]/.test(code)
32
+ ? `${severity === "warning" ? "W" : severity === "info" ? "I" : "E"}_${code.toUpperCase().replaceAll(/[^A-Z0-9]/g, "_")}`
33
+ : code);
34
+ export const OLD_OPERATORS = {
35
+ "all?": "and",
36
+ "any?": "or",
37
+ negate: "not",
38
+ "not=": "!=",
39
+ };
40
+ /** One-release migration errors. Reader nodes keep strings, comments and identifiers untouched. */
41
+ export const operatorDiagnostics = (files) => {
42
+ const diagnostics = [];
43
+ for (const file of files) {
44
+ const walk = (node) => {
45
+ const head = headOf(node), replacement = head && Object.hasOwn(OLD_OPERATORS, head) && OLD_OPERATORS[head];
46
+ if (replacement) {
47
+ const xs = items(node), name = xs[0];
48
+ const vector = xs.length === 2 && xs[1]?._tag === "Vector" && (head === "all?" || head === "any?")
49
+ ? xs[1]
50
+ : undefined;
51
+ const at = spanOf(file.id, vector ? node : name);
52
+ const text = vector
53
+ ? file.text.slice(node.loc.start, name.loc.start) +
54
+ replacement +
55
+ file.text.slice(name.loc.end, vector.loc.start) +
56
+ file.text.slice(vector.loc.start + 1, vector.loc.end - 1) +
57
+ file.text.slice(vector.loc.end, node.loc.end)
58
+ : replacement;
59
+ diagnostics.push({
60
+ code: "E_RENAMED_OPERATOR",
61
+ severity: "error",
62
+ message: `${head} was renamed to ${replacement}.`,
63
+ help: `Use ${replacement} in both requirements and properties.`,
64
+ at,
65
+ fix: {
66
+ src: file.id,
67
+ from: at.from,
68
+ to: at.to,
69
+ text,
70
+ expected: file.text.slice(at.from, at.to),
71
+ },
72
+ });
73
+ }
74
+ if (node._tag === "List" || node._tag === "Vector")
75
+ node.items.forEach(walk);
76
+ if (node._tag === "Map")
77
+ node.pairs.forEach(([k, v]) => {
78
+ walk(k);
79
+ walk(v);
80
+ });
81
+ };
82
+ sourceSyntax(file).forms.forEach(walk);
83
+ }
84
+ return diagnostics;
85
+ };
86
+ /** Forma expands Bool and/or/not before inference. Adapt Truth calls for that boundary,
87
+ * then map its locations back to the authored text. Lowering always reads original source. */
88
+ export const elaborationSource = (file) => {
89
+ const edits = [];
90
+ const walk = (node, bool = false) => {
91
+ const head = headOf(node), xs = items(node);
92
+ if (head === "property" || head === "scenario" || head === "type")
93
+ return;
94
+ if (node._tag === "List" && !bool && ["and", "or", "not"].includes(head ?? "")) {
95
+ edits.push({
96
+ from: xs[0].loc.start,
97
+ to: xs[0].loc.end,
98
+ text: head === "and" ? "all?" : head === "or" ? "any?" : "negate",
99
+ });
100
+ if (head !== "not") {
101
+ const collection = xs.length === 2;
102
+ if (!collection) {
103
+ const start = xs[1]?.loc.start ?? xs[0].loc.end;
104
+ edits.push({ from: start, to: start, text: xs[1] ? "[" : " [" });
105
+ edits.push({ from: node.loc.end - 1, to: node.loc.end - 1, text: "]" });
106
+ }
107
+ }
108
+ }
109
+ if (node._tag === "List" || node._tag === "Vector")
110
+ node.items.forEach((child, i) => walk(child, (head === "if" && (i === 1 || bool)) ||
111
+ (head === "filter" && i === 1) ||
112
+ (bool && ["and", "or", "not", "fn"].includes(head ?? ""))));
113
+ if (node._tag === "Map")
114
+ node.pairs.forEach(([k, v]) => {
115
+ walk(k);
116
+ walk(v);
117
+ });
118
+ };
119
+ sourceSyntax(file).forms.forEach((f) => {
120
+ if (headOf(f) === "derive" && symName(option(f, "returns")) === "Bool") {
121
+ const body = items(f).at(-1);
122
+ if (body)
123
+ walk(body, true);
124
+ }
125
+ else
126
+ walk(f);
127
+ });
128
+ edits.sort((a, b) => a.from - b.from || a.to - b.to);
129
+ let source = "", cursor = 0;
130
+ const offsets = [];
131
+ const append = (text, start, original) => {
132
+ for (let i = 0; i < text.length; i++)
133
+ offsets.push(start + (original ? i : 0));
134
+ source += text;
135
+ };
136
+ for (const edit of edits) {
137
+ append(file.text.slice(cursor, edit.from), cursor, true);
138
+ append(edit.text, edit.from, false);
139
+ cursor = edit.to;
140
+ }
141
+ append(file.text.slice(cursor), cursor, true);
142
+ offsets.push(file.text.length);
143
+ const offset = (n) => offsets[n] ?? file.text.length;
144
+ const location = (n) => {
145
+ const before = file.text.slice(0, n), lines = before.split("\n");
146
+ return { line: lines.length, col: lines.at(-1).length + 1 };
147
+ };
148
+ return {
149
+ source,
150
+ span: (span) => {
151
+ const startOffset = offset(span.startOffset), endOffset = offset(span.endOffset);
152
+ const start = location(startOffset), end = location(endOffset);
153
+ return {
154
+ ...span,
155
+ startOffset,
156
+ endOffset,
157
+ startLine: start.line,
158
+ startColumn: start.col,
159
+ endLine: end.line,
160
+ endColumn: end.col,
161
+ };
162
+ },
163
+ };
164
+ };
165
+ /** Inspect declaration positions only: expression calls and scenario data are not forms. */
166
+ export const coreDiagnostics = (files) => {
167
+ const diagnostics = [];
168
+ for (const file of files) {
169
+ const visit = (node, metadata) => {
170
+ const head = headOf(node), form = metadata.find((m) => m.name === head);
171
+ if (!form)
172
+ return;
173
+ if (form.tier === "extended")
174
+ diagnostics.push({
175
+ code: "I_EXTENDED_FORM",
176
+ severity: "info",
177
+ message: `${head} is an extended form.`,
178
+ help: "The core forms are source, entity, evidence, component, requirement, action, output, decision, scenario and property. See AUTHORING.md for extended forms.",
179
+ at: spanOf(file.id, items(node)[0]),
180
+ });
181
+ const children = CHILD_FORMS.metadata.get(head);
182
+ if (children)
183
+ items(node)
184
+ .slice(1)
185
+ .forEach((child) => visit(child, children));
186
+ };
187
+ sourceSyntax(file).forms.forEach((form) => visit(form, TOP_LEVEL_FORMS.metadata));
188
+ }
189
+ return diagnostics;
190
+ };
191
+ /** Keep operator spellings in canonical IR display text stable across source migrations. */
192
+ export const canonicalConditionText = (text) => {
193
+ const file = { id: "condition", text: elaborationSource({ id: "condition", text }).source };
194
+ const edits = [];
195
+ const visit = (node) => {
196
+ if (headOf(node) === "!=") {
197
+ const head = items(node)[0];
198
+ edits.push({ from: head.loc.start, to: head.loc.end });
199
+ }
200
+ if (node._tag === "List" || node._tag === "Vector")
201
+ node.items.forEach(visit);
202
+ if (node._tag === "Map")
203
+ node.pairs.forEach(([k, v]) => {
204
+ visit(k);
205
+ visit(v);
206
+ });
207
+ };
208
+ sourceSyntax(file).forms.forEach(visit);
209
+ let result = file.text;
210
+ for (const edit of edits.sort((a, b) => b.from - a.from))
211
+ result = result.slice(0, edit.from) + "not=" + result.slice(edit.to);
212
+ return result;
213
+ };
@@ -0,0 +1,3 @@
1
+ import { SimpleSemanticEnvironment } from "@forma-language/forma/descriptor";
2
+ /** Forma's public environment hook keeps native inference and lexical child scopes. */
3
+ export declare const tableEnvironment: (env?: SimpleSemanticEnvironment) => SimpleSemanticEnvironment;
@@ -0,0 +1,41 @@
1
+ import { SimpleSemanticEnvironment } from "@forma-language/forma/descriptor";
2
+ /** Only the inference view is sugar: authored syntax/spans remain the lowering input. */
3
+ const checkingView = (e) => {
4
+ const list = (items) => ({ _tag: "List", items, loc: e.loc });
5
+ const sym = (name) => ({ _tag: "Sym", name, loc: e.loc });
6
+ if (e._tag === "List" && e.items[0]?._tag === "Sym" && e.items[0].name === "table") {
7
+ const selector = e.items[1], rows = e.items.slice(2);
8
+ if (!selector || !rows.length || rows.length % 2)
9
+ return e;
10
+ // The checker visits every branch; runtime lookup (including unmatched/Unknown) is separate.
11
+ // Table Boolean literals denote Truth; use true? for a Bool result.
12
+ const branch = (value) => value._tag === "Bool"
13
+ ? list([sym("="), value, { _tag: "Bool", value: true, loc: value.loc }])
14
+ : checkingView(value);
15
+ let result = branch(rows.at(-1));
16
+ for (let i = rows.length - 4; i >= 0; i -= 2)
17
+ result = list([
18
+ sym("if"),
19
+ list([sym("true?"), list([sym("="), checkingView(selector), rows[i]])]),
20
+ branch(rows[i + 1]),
21
+ result,
22
+ ]);
23
+ return result;
24
+ }
25
+ if (e._tag === "List" || e._tag === "Vector" || e._tag === "Set") {
26
+ const items = e.items.map(checkingView);
27
+ return items.every((item, i) => item === e.items[i]) ? e : { ...e, items };
28
+ }
29
+ if (e._tag === "Map") {
30
+ const pairs = e.pairs.map(([k, v]) => [k, checkingView(v)]);
31
+ return pairs.every((pair, i) => pair[1] === e.pairs[i][1]) ? e : { ...e, pairs };
32
+ }
33
+ return e;
34
+ };
35
+ /** Forma's public environment hook keeps native inference and lexical child scopes. */
36
+ export const tableEnvironment = (env = new SimpleSemanticEnvironment()) => {
37
+ const infer = env.inferExpression.bind(env), child = env.childScope.bind(env);
38
+ env.inferExpression = (e) => infer(checkingView(e));
39
+ env.childScope = () => tableEnvironment(child());
40
+ return env;
41
+ };
@@ -0,0 +1,17 @@
1
+ /** Lossless token spelling and UTF-16 spans, including comments, from Forma's reader. */
2
+ export interface Syntax {
3
+ readonly kind: string;
4
+ readonly text: string;
5
+ readonly from: number;
6
+ readonly to: number;
7
+ readonly children: readonly Syntax[];
8
+ }
9
+ export declare const readForma: (source: string) => {
10
+ forms: readonly Syntax[];
11
+ valid: boolean;
12
+ };
13
+ /** Two spaces, 100 columns (soft for indivisible strings/tokens), LF and a final newline.
14
+ * Comments are kept verbatim on their own lines. Keyword/value and map pairs share a line.
15
+ * Invalid source is rejected so a formatter never silently repairs or drops a token.
16
+ */
17
+ export declare const formatForma: (source: string) => string;