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,331 @@
1
+ import { readReuse, reuseDecisionName } from "./reuse.js";
2
+ import { actionTargets } from "./work.js";
3
+ import { policyRequirements } from "./policies.js";
4
+ import { timeOrder, isPastDeadline, deadlineOrder, nextTime } from "./instants.js";
5
+ import { readRenewal } from "./evidence-validity.js";
6
+ import { evaluateMilestones } from "./milestones.js";
7
+ import { evaluateEscalations } from "./escalations.js";
8
+ import { evaluateActions } from "./actions.js";
9
+ import {} from "./basis.js";
10
+ import { contextOf } from "./context.js";
11
+ import {} from "./dates.js";
12
+ import { evaluateIn, timeOf, and, isDuration, isUnknown, legacyAcceptance, plus, selectedDecision, selectedAddition, truth, } from "./evaluation.js";
13
+ import { truthOf } from "./graph.js";
14
+ import { activeHolds, evaluateHolds } from "./holds.js";
15
+ import {} from "./model.js";
16
+ import { outputStatus, outputText } from "./outputs.js";
17
+ import { semanticJson } from "./result-digest.js";
18
+ import { readEffective } from "./effective.js";
19
+ import { readRecurrence } from "./recurrence.js";
20
+ import { Unknown } from "./model.js";
21
+ import { timed } from "./scheduling.js";
22
+ export function evaluate(ctx, inst) {
23
+ const done = ctx.results.get(inst.id);
24
+ if (done)
25
+ return done;
26
+ const p = ctx.programOf.get(inst.id);
27
+ const component = p.components.get(inst.component);
28
+ const cx = contextOf(ctx, inst);
29
+ const partial = new Map();
30
+ ctx.evaluating.set(inst.id, partial);
31
+ let requirements = evaluateRequirements(ctx, inst, cx, component, partial);
32
+ // Children before outputs: outputs read child statuses.
33
+ for (const slot of inst.children)
34
+ for (const id of slot.instances)
35
+ if (!ctx.evaluating.has(id))
36
+ evaluate(ctx, ctx.instances.get(id));
37
+ const outputs = component.outputs.map((o) => ({
38
+ name: o.name,
39
+ label: o.label ?? o.name,
40
+ expr: outputText(o),
41
+ status: outputStatus(ctx, inst, o),
42
+ at: o.at,
43
+ }));
44
+ const milestones = evaluateMilestones(ctx, cx, component);
45
+ for (const resource of component.resources ?? [])
46
+ timed(ctx, cx, ["resource", resource.name], `${resource.name}: release condition changes`, (c) => truth(evaluateIn(c, resource.releaseWhen)), String);
47
+ const holds = evaluateHolds(ctx, cx, component);
48
+ if (activeHolds(holds, "remind").length)
49
+ requirements = requirements.map((r) => (r.remindAt ? { ...r, remindAt: null } : r));
50
+ const escalations = evaluateEscalations(ctx, inst, cx, component, requirements, holds);
51
+ const { actions, workIntents } = evaluateActions(ctx, inst, cx, component, requirements, holds);
52
+ const blocked = requirements
53
+ .filter((r) => (r.status === "Open" || r.status === "Overdue") &&
54
+ !r.awaits &&
55
+ !actions.some((a) => actionTargets(a).includes(r.name)))
56
+ .map((r) => ({
57
+ requirement: r.name,
58
+ reason: `${r.label} is open and no declared action advances it`,
59
+ }));
60
+ ctx.blockedTotal += blocked.length;
61
+ let retention = null;
62
+ if (component.retention) {
63
+ const trace = { steps: [] };
64
+ retention = timed(ctx, { ...cx, trace }, ["retention"], "Retention becomes eligible for review", (c) => {
65
+ const value = evaluateIn(c, component.retention.until);
66
+ const until = isUnknown(value) ? null : String(value);
67
+ if (until)
68
+ c.temporal?.add(until);
69
+ return {
70
+ until,
71
+ eligible: until === null ? null : timeOrder(c.b.now, until) >= 0,
72
+ steps: c.trace?.steps ?? [],
73
+ unknown: isUnknown(value) ? value.why : null,
74
+ disposal: component.retention.disposal,
75
+ };
76
+ }, (value) => semanticJson([value.until, value.eligible]));
77
+ }
78
+ const result = {
79
+ ...(milestones.length ? { milestones } : {}),
80
+ ...(escalations.length ? { escalations } : {}),
81
+ ...(holds.length ? { holds } : {}),
82
+ instance: inst.id,
83
+ component: inst.component,
84
+ requirements,
85
+ outputs,
86
+ actions,
87
+ workIntents,
88
+ blocked,
89
+ wakeAt: null,
90
+ wakeReason: "",
91
+ retention,
92
+ };
93
+ ctx.evaluating.delete(inst.id);
94
+ ctx.results.set(inst.id, result);
95
+ return result;
96
+ }
97
+ export const evaluateRequirements = (ctx, inst, baseCx, component, partial) => {
98
+ const requirements = [];
99
+ for (const r of component.requirements) {
100
+ const effective = r.effective
101
+ ? timed(ctx, baseCx, ["requirement", r.name, "effective"], `${r.label ?? r.name}: effective window changes`, (c) => readEffective(c, r.effective))
102
+ : null;
103
+ const recurrence = r.recur
104
+ ? timed(ctx, baseCx, ["requirement", r.name, "recurrence"], `${r.label ?? r.name}: recurrence boundary`, (c) => readRecurrence(c, r.recur))
105
+ : null;
106
+ const cx = recurrence?.period
107
+ ? {
108
+ ...baseCx,
109
+ proofPeriod: recurrence.period,
110
+ occurrence: `${inst.id}/${r.name}@${recurrence.period.start}`,
111
+ }
112
+ : baseCx;
113
+ const b = cx.b;
114
+ const trace = { steps: [] };
115
+ const traced = { ...cx, trace };
116
+ const label = r.label ?? r.name;
117
+ const decision = (cx.p.ir.decisions ?? []).some((d) => d.of === inst.component && d.applies === (r.accepts?.with ?? r.name) && d.effect !== "add")
118
+ ? timed(ctx, cx, ["requirement", r.name, "decision"], `${label}: decision changes`, (c) => selectedDecision(c, r.name, (date) => c.temporal?.add(date)), semanticJson)
119
+ : null;
120
+ const addition = r.discretionary
121
+ ? timed(ctx, cx, ["requirement", r.name, "addition"], `${label}: addition changes`, (c) => selectedAddition(c, r.name, (date) => c.temporal?.add(date)), semanticJson)
122
+ : null;
123
+ const cycleValue = r.recur
124
+ ? (recurrence?.period?.start ?? new Unknown(recurrence.reason))
125
+ : r.cycle
126
+ ? timed(ctx, traced, ["requirement", r.name, "cycle"], `${label}: cycle changes`, (c) => evaluateIn(c, r.cycle), semanticJson, { enabled: () => applies.truth === true })
127
+ : null;
128
+ const occurrence = `${inst.id}/${r.name}${cycleValue !== null && !isUnknown(cycleValue) ? `@${String(cycleValue)}` : ""}`;
129
+ const applies = timed(ctx, traced, ["requirement", r.name, "applies"], `${label}: applicability changes`, (c) => {
130
+ const applicable = r.discretionary && !selectedAddition(c, r.name, (date) => c.temporal?.add(date))
131
+ ? { truth: false, reason: "No standing addition" }
132
+ : truthOf(c, r.appliesWhen);
133
+ return r.recur || r.effective
134
+ ? {
135
+ ...applicable,
136
+ truth: and([
137
+ applicable.truth,
138
+ r.recur ? readRecurrence(c, r.recur).truth : true,
139
+ r.effective ? readEffective(c, r.effective).truth : true,
140
+ ]),
141
+ }
142
+ : applicable;
143
+ }, (v) => String(v.truth));
144
+ const reasons = [];
145
+ if (effective)
146
+ reasons.push({
147
+ label: "Effective window",
148
+ outcome: effective.truth === true ? "passed" : effective.truth === false ? "failed" : "unknown",
149
+ detail: effective.reason,
150
+ at: r.effective.at,
151
+ });
152
+ if (recurrence)
153
+ reasons.push({
154
+ label: "Recurrence",
155
+ outcome: recurrence.truth === true ? "passed" : recurrence.truth === false ? "failed" : "unknown",
156
+ detail: recurrence.reason,
157
+ at: r.recur.at,
158
+ });
159
+ if (r.discretionary) {
160
+ if (addition)
161
+ for (const record of addition.votes ?? [addition.record])
162
+ reasons.push({
163
+ label: "Added work",
164
+ outcome: "passed",
165
+ detail: `${record.id}: added by ${record.by} on ${record.at}${record.reason === null ? "" : ` (${record.reason})`}`,
166
+ at: addition.definition.at,
167
+ });
168
+ else
169
+ reasons.push({
170
+ label: "Added work",
171
+ outcome: "failed",
172
+ detail: "No standing addition",
173
+ at: r.at,
174
+ });
175
+ }
176
+ if (r.appliesWhen)
177
+ reasons.push({
178
+ label: "Applies when",
179
+ outcome: applies.truth === true ? "passed" : applies.truth === false ? "failed" : "unknown",
180
+ detail: applies.reason,
181
+ at: r.appliesWhen.at,
182
+ });
183
+ let status;
184
+ let due = null;
185
+ let dueUnknown = null;
186
+ let dueSteps = [];
187
+ let remindAt = null;
188
+ let evidence = null;
189
+ let evidenceType = null;
190
+ let via = "";
191
+ let awaits = null;
192
+ if (applies.truth === false)
193
+ status = "NotApplicable";
194
+ else if (applies.truth === "unknown")
195
+ status = "Unknown";
196
+ else {
197
+ const acceptedFrom = legacyAcceptance(cx, r);
198
+ let sat;
199
+ let detail;
200
+ if ((decision?.definition.effect === "reject" &&
201
+ (!r.reuse ||
202
+ decision.definition.name !== reuseDecisionName(inst.component, r.name, "declined"))) ||
203
+ (decision?.definition.effect === "accept" && !r.reuse)) {
204
+ sat = decision.definition.effect === "accept";
205
+ via = `decision:${decision.record.id}`;
206
+ detail = `Decision ${decision.record.id} by ${decision.record.by}: ${decision.definition.effect}`;
207
+ }
208
+ else if (acceptedFrom?.decision === "accepted") {
209
+ sat = true;
210
+ via = "acceptance";
211
+ detail = `Carried over from ${acceptedFrom.from}, confirmed by ${acceptedFrom.by}`;
212
+ }
213
+ else {
214
+ const satTrace = { steps: [] };
215
+ const value = timed(ctx, { ...cx, trace: satTrace, occurrence }, ["requirement", r.name, "satisfied"], `${label}: satisfaction changes`, (c) => {
216
+ const value = evaluateIn(c, r.satisfiedBy);
217
+ return truth(value) === true || !r.reuse ? value : readReuse(c, r);
218
+ }, (v) => String(truth(v)));
219
+ sat = truth(value);
220
+ evidence = satTrace.witness?.evidence ?? null;
221
+ evidenceType = satTrace.witness?.type ?? null;
222
+ via = satTrace.witness?.via ?? "";
223
+ awaits = satTrace.awaits ?? null;
224
+ detail =
225
+ satTrace.witness?.detail ??
226
+ (isUnknown(value) ? `Unknown: ${value.why}` : sat === true ? "true" : "false");
227
+ if (sat !== true && evidence?.status === "attested")
228
+ evidence = null;
229
+ }
230
+ const lawSat = sat;
231
+ const policies = timed(ctx, cx, ["requirement", r.name, "policies"], `${label}: policy changes`, policyRequirements);
232
+ for (const { truth: _truth, ...reason } of policies)
233
+ reasons.push(reason);
234
+ sat = and([sat, ...policies.map((p) => p.truth)]);
235
+ reasons.push({
236
+ label: "Satisfied by",
237
+ outcome: lawSat === true ? "passed" : lawSat === false ? "failed" : "unknown",
238
+ detail,
239
+ at: r.satisfiedBy.at,
240
+ });
241
+ if (r.due) {
242
+ const dueTrace = { steps: [] };
243
+ const value = timed(ctx, { ...cx, trace: dueTrace }, ["requirement", r.name, "due"], `${label}: due date changes`, (c) => evaluateIn(c, r.due), semanticJson, { enabled: () => sat === false });
244
+ dueSteps = dueTrace.steps;
245
+ if (isUnknown(value))
246
+ dueUnknown = value.why;
247
+ else {
248
+ const point = timeOf(value);
249
+ if (isUnknown(point))
250
+ dueUnknown = point.why;
251
+ else
252
+ due = point;
253
+ }
254
+ }
255
+ if (due &&
256
+ decision?.definition.effect === "defer" &&
257
+ decision.record.deferredUntil &&
258
+ deadlineOrder(decision.record.deferredUntil, due) > 0)
259
+ due = decision.record.deferredUntil;
260
+ status =
261
+ decision?.definition.effect === "waive"
262
+ ? "Waived"
263
+ : sat === true
264
+ ? "Satisfied"
265
+ : sat === "unknown"
266
+ ? "Unknown"
267
+ : due !== null && isPastDeadline(b.now, due)
268
+ ? "Overdue"
269
+ : "Open";
270
+ if (r.remind && due) {
271
+ const remind = timed(ctx, traced, ["requirement", r.name, "reminder"], `${label}: reminder before due`, (c) => {
272
+ const duration = evaluateIn(c, r.remind);
273
+ const at = isDuration(duration) ? plus(due, duration, -1) : null;
274
+ if (at)
275
+ c.temporal?.add(at);
276
+ return { at, ready: at !== null && timeOrder(c.b.now, at) >= 0 };
277
+ }, semanticJson, { enabled: () => status === "Open" || status === "Overdue" });
278
+ remindAt = remind.at;
279
+ }
280
+ }
281
+ if (decision)
282
+ for (const record of decision.votes ?? [decision.record])
283
+ reasons.push({
284
+ label: "Decision",
285
+ outcome: decision.definition.effect === "reject" ? "failed" : "passed",
286
+ detail: `${record.id}: ${decision.definition.effect} by ${record.by}${record.reason === null ? "" : ` (${record.reason})`}`,
287
+ at: decision.definition.at,
288
+ });
289
+ const renewal = r.renewWithin && applies.truth === true
290
+ ? timed(ctx, cx, ["requirement", r.name, "renewal"], `${label}: renewal window changes`, (c) => readRenewal(c, r, occurrence))
291
+ : null;
292
+ // Open -> Overdue matters even when every action stays eligible and no consumer forecasts it.
293
+ const deadlineWake = status === "Open" && due ? nextTime(due) : null;
294
+ if (deadlineWake && timeOrder(deadlineWake, b.now) > 0)
295
+ cx.reads.add({
296
+ kind: "time",
297
+ instance: inst.id,
298
+ path: ["requirement", r.name, "deadline"],
299
+ value: { at: deadlineWake, why: `${label}: deadline passes` },
300
+ });
301
+ const result = {
302
+ ...(r.renewWithin ? { renewal } : {}),
303
+ ...(r.recur ? { recurrence: recurrence.period } : {}),
304
+ ...(addition
305
+ ? {
306
+ addition: addition.record,
307
+ ...(addition.votes ? { additionVotes: addition.votes } : {}),
308
+ }
309
+ : {}),
310
+ ...(decision ? { decision: decision.record } : {}),
311
+ ...(decision?.votes ? { decisionVotes: decision.votes } : {}),
312
+ name: r.name,
313
+ label,
314
+ occurrence,
315
+ status,
316
+ due,
317
+ dueSteps,
318
+ dueUnknown,
319
+ remindAt,
320
+ reasons,
321
+ evidence,
322
+ evidenceType,
323
+ via,
324
+ awaits,
325
+ at: r.at,
326
+ };
327
+ partial.set(r.name, result);
328
+ requirements.push(result);
329
+ }
330
+ return requirements;
331
+ };
@@ -0,0 +1,9 @@
1
+ import type { Basis } from "./basis.js";
2
+ import type { Instance, Program } from "./model.js";
3
+ export declare const resourceProgramDigest: (p: Program) => string;
4
+ export declare const resourceGeneration: (p: Program, b: Basis, inst: Instance) => number;
5
+ export declare const resourceMachineScope: (p: Program, b: Basis, inst: Instance, machine: string) => {
6
+ account: string;
7
+ generation: number;
8
+ } | undefined;
9
+ export declare const resourceProofRecords: (p: Program, b: Basis, inst: Instance, resource: string, type: string) => import("./basis.js").EvidenceRecord[];
@@ -0,0 +1,17 @@
1
+ import { resourceProofRequirement, contentDigest } from "../ir-checks/index.js";
2
+ export const resourceProgramDigest = (p) => contentDigest({ libraries: p.ir.libraries.map((l) => l.digest), account: p.account });
3
+ export const resourceGeneration = (p, b, inst) => {
4
+ const record = b.lifecycle?.(p.account.name, inst.id);
5
+ return record ? record.generation + (record.active ? 0 : 1) : 1;
6
+ };
7
+ export const resourceMachineScope = (p, b, inst, machine) => p.components.get(inst.component)?.resources?.some((r) => r.name === machine)
8
+ ? { account: p.account.name, generation: resourceGeneration(p, b, inst) }
9
+ : undefined;
10
+ export const resourceProofRecords = (p, b, inst, resource, type) => {
11
+ const producer = resourceProofRequirement(p.components.get(inst.component), resource, type);
12
+ return producer
13
+ ? b
14
+ .evidence(`${inst.id}/${producer.name}@${resourceGeneration(p, b, inst)}`)
15
+ .filter((e) => e.type === type)
16
+ : [];
17
+ };
@@ -0,0 +1,26 @@
1
+ import type * as IR from "../world-ir/types.generated.js";
2
+ import { type World } from "./memory.js";
3
+ import { type WorldReconciliation } from "./reconcile.js";
4
+ /** Finite authored fixture observations; no provider execution or host authority is implied. */
5
+ export declare const scenarioResources: (recon: WorldReconciliation, world: World, date: string) => {
6
+ program: import("./model.js").Program;
7
+ home: string;
8
+ recon: import("./model.js").SubjectReconciliation;
9
+ projection: {
10
+ readonly intents: readonly import("./basis.js").ResourceIntent[];
11
+ readonly views: readonly import("./resources.js").ResourceView[];
12
+ readonly lifecycleChanges: readonly import("./basis.js").LifecycleRecord[];
13
+ readonly dependsOn: ReadonlyMap<string, import("./dependencies.js").Dependency>;
14
+ readonly wakeAt: string | null;
15
+ };
16
+ }[];
17
+ export declare const observeScenarioLifecycles: (recon: WorldReconciliation, world: World, date: string) => World;
18
+ export declare const scenarioResourceObservation: (recon: WorldReconciliation, world: World, date: string, account: string, id: string, request: Extract<IR.ScenarioCommand, {
19
+ kind: "resource";
20
+ }>, commandId: string) => {
21
+ world: World;
22
+ outcome: {
23
+ accepted: boolean;
24
+ codes: readonly string[];
25
+ };
26
+ };
@@ -0,0 +1,78 @@
1
+ import { basis } from "./memory.js";
2
+ import { reconcileSubject } from "./reconcile.js";
3
+ import { occurrenceHome } from "./homes.js";
4
+ import { resourceProjection } from "./resources.js";
5
+ import { invokeOperation, operationsFor } from "./component-operations.js";
6
+ import { signal } from "./commands.js";
7
+ /** Finite authored fixture observations; no provider execution or host authority is implied. */
8
+ export const scenarioResources = (recon, world, date) => recon.programs.flatMap((p) => {
9
+ const homes = new Set([
10
+ ...(world.lifecycles ?? []).filter((r) => r.account === p.account.name).map((r) => r.home),
11
+ ...(world.resources ?? []).filter((r) => r.account === p.account.name).map((r) => r.home),
12
+ ...[...recon.instances.values()].flatMap((i) => i.account === p.account.name && p.components.get(i.component)?.resources?.length
13
+ ? [occurrenceHome(p, i, recon.instances)?.id].filter((h) => !!h)
14
+ : []),
15
+ ]), b = basis(world, date);
16
+ return [...homes].map((home) => {
17
+ const subject = reconcileSubject(p, b, home);
18
+ return {
19
+ program: p,
20
+ home,
21
+ recon: subject,
22
+ projection: resourceProjection(subject, b, { account: p.account.name, home }),
23
+ };
24
+ });
25
+ });
26
+ export const observeScenarioLifecycles = (recon, world, date) => {
27
+ const changes = scenarioResources(recon, world, date).flatMap((s) => s.projection.lifecycleChanges);
28
+ return changes.length
29
+ ? { ...world, lifecycles: [...(world.lifecycles ?? []), ...changes] }
30
+ : world;
31
+ };
32
+ export const scenarioResourceObservation = (recon, world, date, account, id, request, commandId) => {
33
+ const found = scenarioResources(recon, world, date).find((s) => s.program.account.name === account &&
34
+ s.projection.intents.some((i) => i.instance === id && i.resource === request.name && i.phase === request.phase)), intent = found?.projection.intents.find((i) => i.instance === id && i.resource === request.name && i.phase === request.phase);
35
+ if (!found || !intent || (request.phase === "release" && intent.handle !== request.handle))
36
+ return { world, outcome: { accepted: false, codes: ["resource-stale"] } };
37
+ if (request.phase === "acquire") {
38
+ const inst = found.recon.instances.get(id), c = found.program.components.get(inst.component), ops = operationsFor(found.recon, account, { instance: id }).operations, action = c.actions.find((a) => ops.some((o) => o.name === a.name) &&
39
+ a.via.kind === "connector" &&
40
+ a.via.connector === intent.connector &&
41
+ a.via.capability === intent.capability), projected = found.recon.results.get(id).actions.find((a) => a.action === action.name);
42
+ const admitted = invokeOperation(found.recon, world, date, {
43
+ id: commandId,
44
+ account,
45
+ target: { instance: id },
46
+ operation: action.name,
47
+ actor: { id: projected.assigneeId ?? "", kind: "service", groups: [] },
48
+ });
49
+ if (!admitted.accepted)
50
+ return { world: admitted.world, outcome: { accepted: false, codes: admitted.codes } };
51
+ world = admitted.world;
52
+ }
53
+ world = {
54
+ ...world,
55
+ resources: [
56
+ ...(world.resources ?? []),
57
+ {
58
+ ...intent,
59
+ handle: request.handle,
60
+ state: request.phase === "acquire" ? "acquired" : "released",
61
+ at: date,
62
+ by: request.by.k === "entity"
63
+ ? request.by.name
64
+ : request.by.k === "literal"
65
+ ? String(request.by.value)
66
+ : "scenario:resource-observation",
67
+ },
68
+ ],
69
+ };
70
+ if (request.state)
71
+ world = signal(found.recon, world, date, {
72
+ instance: id,
73
+ machine: request.name,
74
+ state: request.state,
75
+ by: intent.connector,
76
+ });
77
+ return { world, outcome: { accepted: true, codes: [] } };
78
+ };
@@ -0,0 +1,24 @@
1
+ import type { Basis, LifecycleRecord, ResourceIntent, ResourceRecord } from "./basis.js";
2
+ import { type Dependency } from "./dependencies.js";
3
+ import type { SubjectReconciliation } from "./model.js";
4
+ export interface ResourceView {
5
+ readonly instance: string;
6
+ readonly resource: string;
7
+ readonly generation: number;
8
+ readonly state: ResourceRecord["state"] | "waiting" | "unknown";
9
+ readonly handle?: string;
10
+ readonly reason: string;
11
+ }
12
+ /** Phase identity includes only pinned protocol metadata, never dynamic business values. */
13
+ export declare const resourceIntentKey: (base: Pick<ResourceIntent, "account" | "home" | "instance" | "resource" | "generation" | "policy" | "programDigest">, phase: ResourceIntent["phase"]) => string;
14
+ /** Passive desired work. Hosts record observations and execute these identities after commit. */
15
+ export declare const resourceProjection: (recon: SubjectReconciliation, snapshot: Basis, scope: {
16
+ readonly account: string;
17
+ readonly home: string;
18
+ }) => {
19
+ readonly intents: readonly ResourceIntent[];
20
+ readonly views: readonly ResourceView[];
21
+ readonly lifecycleChanges: readonly LifecycleRecord[];
22
+ readonly dependsOn: ReadonlyMap<string, Dependency>;
23
+ readonly wakeAt: string | null;
24
+ };
@@ -0,0 +1,178 @@
1
+ import { componentOperationNames, contentDigest } from "../ir-checks/index.js";
2
+ import { observeBasis, ReadSet } from "./dependencies.js";
3
+ import { assertSnapshot, evaluateIn, instanceContext, truth } from "./evaluation.js";
4
+ import { occurrenceHome } from "./homes.js";
5
+ import { resourceGeneration, resourceProgramDigest } from "./resource-generation.js";
6
+ import { sha256 } from "./sha256.js";
7
+ import { canonicalJson } from "./result-digest.js";
8
+ const identity = (instance, resource, generation) => JSON.stringify([instance, resource, generation]);
9
+ /** Phase identity includes only pinned protocol metadata, never dynamic business values. */
10
+ export const resourceIntentKey = (base, phase) => sha256(canonicalJson({
11
+ account: base.account,
12
+ home: base.home,
13
+ instance: base.instance,
14
+ resource: base.resource,
15
+ generation: base.generation,
16
+ policy: contentDigest(base.policy),
17
+ programDigest: base.programDigest,
18
+ phase,
19
+ }));
20
+ const intent = (base, phase) => ({
21
+ account: base.account,
22
+ home: base.home,
23
+ instance: base.instance,
24
+ resource: base.resource,
25
+ generation: base.generation,
26
+ policy: base.policy,
27
+ programDigest: base.programDigest,
28
+ ...(base.handle ? { handle: base.handle } : {}),
29
+ phase,
30
+ connector: base.policy[phase].connector,
31
+ capability: base.policy[phase].capability,
32
+ key: resourceIntentKey(base, phase),
33
+ });
34
+ /** Passive desired work. Hosts record observations and execute these identities after commit. */
35
+ export const resourceProjection = (recon, snapshot, scope) => {
36
+ assertSnapshot(snapshot, recon.now);
37
+ if (recon.home.id !== scope.home || recon.programs.some((p) => p.account.name !== scope.account))
38
+ throw new Error("Resource projection requires its reconciled home and account.");
39
+ const reads = new ReadSet();
40
+ reads.merge(recon.dependsOn);
41
+ const routing = [
42
+ ...new Map([...recon.dependsOn.values()].flatMap((d) => d.kind === "matching"
43
+ ? d.value.map((entity) => [
44
+ JSON.stringify([entity, d.attribute]),
45
+ { entity, attribute: d.attribute },
46
+ ])
47
+ : [])).values(),
48
+ ].sort((a, b) => canonicalJson(a) < canonicalJson(b) ? -1 : canonicalJson(a) > canonicalJson(b) ? 1 : 0);
49
+ const b = observeBasis(snapshot, reads), records = b.resourceRecords?.(scope.account, scope.home) ?? [], lifecycles = b.lifecycleRecords?.(scope.account, scope.home) ?? [], latest = new Map(), instances = new Map([...recon.instances].filter(([, i]) => i.account === scope.account &&
50
+ occurrenceHome(recon.programs.find((p) => p.account.name === scope.account), i, recon.instances)?.id === scope.home)), unresolved = recon.applicabilityUnknown ||
51
+ [...instances.values()].some((i) => i.children.some((s) => s.applies === "unknown")), lifecycleChanges = [], intents = [], views = [], visited = new Set();
52
+ for (const record of records)
53
+ if (record.account === scope.account && record.home === scope.home)
54
+ latest.set(identity(record.instance, record.resource, record.generation), record);
55
+ const stop = (record, unknown) => {
56
+ const view = {
57
+ instance: record.instance,
58
+ resource: record.resource,
59
+ generation: record.generation,
60
+ state: unknown && record.state !== "released" ? "unknown" : record.state,
61
+ ...(record.handle ? { handle: record.handle } : {}),
62
+ reason: record.state === "released"
63
+ ? "Cleanup confirmed"
64
+ : unknown
65
+ ? "Applicability is unknown"
66
+ : "The acquisition generation requires cleanup",
67
+ };
68
+ views.push(view);
69
+ if (record.state === "released")
70
+ return;
71
+ if (!unknown && record.state === "acquiring")
72
+ intents.push(intent(record, "acquire"));
73
+ if (!unknown && record.handle && !["uncertain", "timed-out"].includes(record.state))
74
+ intents.push(intent(record, "release"));
75
+ };
76
+ const lifecycle = (instance, generation, active) => {
77
+ const previous = b.lifecycle?.(scope.account, instance);
78
+ if (previous && previous.generation > generation)
79
+ return;
80
+ const captured = active ? routing : (previous?.routing ?? []);
81
+ if ((previous?.generation !== generation ||
82
+ previous.active !== active ||
83
+ (active && canonicalJson(previous.routing ?? []) !== canonicalJson(captured))) &&
84
+ !lifecycleChanges.some((r) => r.instance === instance && r.generation === generation && r.active === active))
85
+ lifecycleChanges.push({
86
+ ...scope,
87
+ instance,
88
+ generation,
89
+ active,
90
+ at: b.now,
91
+ ...(captured.length ? { routing: captured } : {}),
92
+ });
93
+ };
94
+ for (const inst of instances.values()) {
95
+ const p = recon.programs.find((p) => p.account.name === inst.account), defs = p.components.get(inst.component).resources ?? [];
96
+ if (!defs.length)
97
+ continue;
98
+ const generation = resourceGeneration(p, b, inst), programDigest = resourceProgramDigest(p);
99
+ lifecycle(inst.id, generation, true);
100
+ for (const policy of defs) {
101
+ const id = identity(inst.id, policy.name, generation), current = latest.get(id);
102
+ visited.add(id);
103
+ const predecessors = [...latest.values()].filter((r) => r.instance === inst.id && r.resource === policy.name && r.generation < generation);
104
+ let waiting = false;
105
+ for (const previous of predecessors) {
106
+ visited.add(identity(previous.instance, previous.resource, previous.generation));
107
+ stop(previous, false);
108
+ if (previous.state !== "released" && !(previous.state === "failed" && !previous.handle))
109
+ waiting = true;
110
+ }
111
+ const condition = truth(evaluateIn(instanceContext(recon, b, inst, reads), policy.releaseWhen)), pinned = current &&
112
+ (current.programDigest !== programDigest ||
113
+ contentDigest(current.policy) !== contentDigest(policy));
114
+ if (current && condition === true && !pinned && !unresolved) {
115
+ stop(current, false);
116
+ continue;
117
+ }
118
+ const action = p.components
119
+ .get(inst.component)
120
+ .actions.find((a) => componentOperationNames(p.ir, p.components.get(inst.component)).includes(a.name) &&
121
+ a.via.kind === "connector" &&
122
+ a.via.connector === policy.acquire.connector &&
123
+ a.via.capability === policy.acquire.capability), projected = recon.results.get(inst.id)?.actions.find((a) => a.action === action.name), unknown = condition === "unknown" || !!pinned || !!unresolved;
124
+ views.push({
125
+ instance: inst.id,
126
+ resource: policy.name,
127
+ generation,
128
+ state: unknown ? "unknown" : (current?.state ?? "waiting"),
129
+ ...(current?.handle ? { handle: current.handle } : {}),
130
+ reason: unknown
131
+ ? "The pinned policy or release condition is unknown"
132
+ : waiting
133
+ ? "A prior generation needs cleanup"
134
+ : "Current lifecycle",
135
+ });
136
+ if (current?.state === "acquiring" && !waiting && !unknown)
137
+ intents.push(intent(current, "acquire"));
138
+ if (current?.state === "releasing" && current.handle && !unknown)
139
+ intents.push(intent(current, "release"));
140
+ if (!current &&
141
+ !waiting &&
142
+ !unknown &&
143
+ condition === false &&
144
+ projected &&
145
+ ["eligible", "dispatched"].includes(projected.state))
146
+ intents.push(intent({
147
+ ...scope,
148
+ instance: inst.id,
149
+ resource: policy.name,
150
+ generation,
151
+ policy,
152
+ programDigest,
153
+ }, "acquire"));
154
+ }
155
+ }
156
+ for (const previous of lifecycles)
157
+ if (previous.active &&
158
+ !instances.has(previous.instance) &&
159
+ !unresolved &&
160
+ !previous.routing?.some((r) => !b.fact(r.entity, r.attribute)))
161
+ lifecycle(previous.instance, previous.generation, false);
162
+ for (const [id, record] of latest)
163
+ if (!visited.has(id)) {
164
+ const inst = instances.get(record.instance), previous = b.lifecycle?.(scope.account, record.instance), unknown = !inst &&
165
+ previous?.active !== false &&
166
+ (unresolved || !!previous?.routing?.some((r) => !b.fact(r.entity, r.attribute)));
167
+ stop(record, unknown);
168
+ if (!inst && !unknown)
169
+ lifecycle(record.instance, record.generation, false);
170
+ }
171
+ return {
172
+ intents: intents.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)),
173
+ views,
174
+ lifecycleChanges,
175
+ dependsOn: reads.snapshot(),
176
+ wakeAt: recon.wakeAt,
177
+ };
178
+ };