@typeonce/effect-machine 0.47.0 → 0.48.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 (334) hide show
  1. package/AGENTS.md +374 -22
  2. package/CLAUDE.md +374 -22
  3. package/README.md +56 -7
  4. package/ai-docs/src/10_modeling/01_create-a-machine.ts +3 -3
  5. package/ai-docs/src/10_modeling/index.md +64 -17
  6. package/ai-docs/src/20_root-api/index.md +2 -2
  7. package/ai-docs/src/35_cluster/index.md +213 -0
  8. package/ai-docs/src/37_new-host/index.md +90 -0
  9. package/dist/LocalMachine.d.ts +417 -0
  10. package/dist/LocalMachine.d.ts.map +1 -0
  11. package/dist/LocalMachine.js +193 -0
  12. package/dist/LocalMachine.js.map +1 -0
  13. package/dist/Machine.d.ts +1122 -814
  14. package/dist/Machine.d.ts.map +1 -1
  15. package/dist/Machine.js +195 -186
  16. package/dist/Machine.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/internal/machine/atom.d.ts +8 -10
  22. package/dist/internal/machine/atom.d.ts.map +1 -1
  23. package/dist/internal/machine/atom.js +7 -6
  24. package/dist/internal/machine/atom.js.map +1 -1
  25. package/dist/internal/machine/capability.d.ts +101 -0
  26. package/dist/internal/machine/capability.d.ts.map +1 -0
  27. package/dist/internal/machine/capability.js +70 -0
  28. package/dist/internal/machine/capability.js.map +1 -0
  29. package/dist/internal/machine/{invocationDefinition.d.ts → capturedInvocation.d.ts} +11 -11
  30. package/dist/internal/machine/capturedInvocation.d.ts.map +1 -0
  31. package/dist/internal/machine/{invocationDefinition.js → capturedInvocation.js} +2 -2
  32. package/dist/internal/machine/capturedInvocation.js.map +1 -0
  33. package/dist/internal/machine/child.d.ts +14 -0
  34. package/dist/internal/machine/child.d.ts.map +1 -0
  35. package/dist/internal/machine/child.js +19 -0
  36. package/dist/internal/machine/child.js.map +1 -0
  37. package/dist/internal/machine/childRegistry.d.ts +0 -2
  38. package/dist/internal/machine/childRegistry.d.ts.map +1 -1
  39. package/dist/internal/machine/childRegistry.js +2 -2
  40. package/dist/internal/machine/childRegistry.js.map +1 -1
  41. package/dist/internal/machine/cluster.d.ts +19 -4
  42. package/dist/internal/machine/cluster.d.ts.map +1 -1
  43. package/dist/internal/machine/cluster.js +263 -110
  44. package/dist/internal/machine/cluster.js.map +1 -1
  45. package/dist/internal/machine/clusterChild.d.ts +66 -0
  46. package/dist/internal/machine/clusterChild.d.ts.map +1 -0
  47. package/dist/internal/machine/clusterChild.js +105 -0
  48. package/dist/internal/machine/clusterChild.js.map +1 -0
  49. package/dist/internal/machine/clusterFailure.d.ts +14 -0
  50. package/dist/internal/machine/clusterFailure.d.ts.map +1 -0
  51. package/dist/internal/machine/clusterFailure.js +44 -0
  52. package/dist/internal/machine/clusterFailure.js.map +1 -0
  53. package/dist/internal/machine/clusterInstance.d.ts +194 -0
  54. package/dist/internal/machine/clusterInstance.d.ts.map +1 -0
  55. package/dist/internal/machine/clusterInstance.js +1076 -0
  56. package/dist/internal/machine/clusterInstance.js.map +1 -0
  57. package/dist/internal/machine/clusterKeepAlive.d.ts +47 -0
  58. package/dist/internal/machine/clusterKeepAlive.d.ts.map +1 -0
  59. package/dist/internal/machine/clusterKeepAlive.js +72 -0
  60. package/dist/internal/machine/clusterKeepAlive.js.map +1 -0
  61. package/dist/internal/machine/clusterProgress.d.ts +73 -0
  62. package/dist/internal/machine/clusterProgress.d.ts.map +1 -0
  63. package/dist/internal/machine/clusterProgress.js +116 -0
  64. package/dist/internal/machine/clusterProgress.js.map +1 -0
  65. package/dist/internal/machine/clusterProtocol.d.ts +37 -4
  66. package/dist/internal/machine/clusterProtocol.d.ts.map +1 -1
  67. package/dist/internal/machine/clusterProtocol.js +18 -4
  68. package/dist/internal/machine/clusterProtocol.js.map +1 -1
  69. package/dist/internal/machine/clusterProxy.d.ts +46 -0
  70. package/dist/internal/machine/clusterProxy.d.ts.map +1 -0
  71. package/dist/internal/machine/clusterProxy.js +150 -0
  72. package/dist/internal/machine/clusterProxy.js.map +1 -0
  73. package/dist/internal/machine/clusterRead.d.ts +61 -0
  74. package/dist/internal/machine/clusterRead.d.ts.map +1 -0
  75. package/dist/internal/machine/clusterRead.js +108 -0
  76. package/dist/internal/machine/clusterRead.js.map +1 -0
  77. package/dist/internal/machine/clusterSqlStorage.d.ts +16 -0
  78. package/dist/internal/machine/clusterSqlStorage.d.ts.map +1 -0
  79. package/dist/internal/machine/clusterSqlStorage.js +138 -0
  80. package/dist/internal/machine/clusterSqlStorage.js.map +1 -0
  81. package/dist/internal/machine/clusterStorageCheck.d.ts +19 -0
  82. package/dist/internal/machine/clusterStorageCheck.d.ts.map +1 -0
  83. package/dist/internal/machine/clusterStorageCheck.js +186 -0
  84. package/dist/internal/machine/clusterStorageCheck.js.map +1 -0
  85. package/dist/internal/machine/clusterTarget.d.ts +74 -0
  86. package/dist/internal/machine/clusterTarget.d.ts.map +1 -0
  87. package/dist/internal/machine/clusterTarget.js +81 -0
  88. package/dist/internal/machine/clusterTarget.js.map +1 -0
  89. package/dist/internal/machine/clusterTimer.d.ts +21 -0
  90. package/dist/internal/machine/clusterTimer.d.ts.map +1 -0
  91. package/dist/internal/machine/clusterTimer.js +50 -0
  92. package/dist/internal/machine/clusterTimer.js.map +1 -0
  93. package/dist/internal/machine/clusterWake.d.ts +61 -0
  94. package/dist/internal/machine/clusterWake.d.ts.map +1 -0
  95. package/dist/internal/machine/clusterWake.js +81 -0
  96. package/dist/internal/machine/clusterWake.js.map +1 -0
  97. package/dist/internal/machine/clusterWork.d.ts +130 -0
  98. package/dist/internal/machine/clusterWork.d.ts.map +1 -0
  99. package/dist/internal/machine/clusterWork.js +191 -0
  100. package/dist/internal/machine/clusterWork.js.map +1 -0
  101. package/dist/internal/machine/command.d.ts +4 -4
  102. package/dist/internal/machine/command.d.ts.map +1 -1
  103. package/dist/internal/machine/commandRuntime.d.ts +8 -6
  104. package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
  105. package/dist/internal/machine/commandRuntime.js +1 -5
  106. package/dist/internal/machine/commandRuntime.js.map +1 -1
  107. package/dist/internal/machine/configuration.d.ts +0 -13
  108. package/dist/internal/machine/configuration.d.ts.map +1 -1
  109. package/dist/internal/machine/configuration.js +0 -151
  110. package/dist/internal/machine/configuration.js.map +1 -1
  111. package/dist/internal/machine/errors.d.ts +11 -2
  112. package/dist/internal/machine/errors.d.ts.map +1 -1
  113. package/dist/internal/machine/errors.js +11 -2
  114. package/dist/internal/machine/errors.js.map +1 -1
  115. package/dist/internal/machine/executionPlan.d.ts +45 -3
  116. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  117. package/dist/internal/machine/executionPlan.js +328 -191
  118. package/dist/internal/machine/executionPlan.js.map +1 -1
  119. package/dist/internal/machine/implementation.d.ts +6 -6
  120. package/dist/internal/machine/implementation.d.ts.map +1 -1
  121. package/dist/internal/machine/inspectionRuntime.d.ts +1 -1
  122. package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -1
  123. package/dist/internal/machine/invocationChanges.d.ts +60 -0
  124. package/dist/internal/machine/invocationChanges.d.ts.map +1 -0
  125. package/dist/internal/machine/invocationChanges.js +54 -0
  126. package/dist/internal/machine/invocationChanges.js.map +1 -0
  127. package/dist/internal/machine/{activities.d.ts → invocationDefinitions.d.ts} +8 -8
  128. package/dist/internal/machine/invocationDefinitions.d.ts.map +1 -0
  129. package/dist/internal/machine/{activities.js → invocationDefinitions.js} +5 -5
  130. package/dist/internal/machine/invocationDefinitions.js.map +1 -0
  131. package/dist/internal/machine/invocationEvent.d.ts +16 -7
  132. package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
  133. package/dist/internal/machine/invocationEvent.js +26 -12
  134. package/dist/internal/machine/invocationEvent.js.map +1 -1
  135. package/dist/internal/machine/invocationOutcome.d.ts +89 -0
  136. package/dist/internal/machine/invocationOutcome.d.ts.map +1 -0
  137. package/dist/internal/machine/invocationOutcome.js +76 -0
  138. package/dist/internal/machine/invocationOutcome.js.map +1 -0
  139. package/dist/internal/machine/invocationResolution.d.ts +137 -0
  140. package/dist/internal/machine/invocationResolution.d.ts.map +1 -0
  141. package/dist/internal/machine/invocationResolution.js +150 -0
  142. package/dist/internal/machine/invocationResolution.js.map +1 -0
  143. package/dist/internal/machine/logicScope.d.ts +24 -0
  144. package/dist/internal/machine/logicScope.d.ts.map +1 -0
  145. package/dist/internal/machine/logicScope.js +33 -0
  146. package/dist/internal/machine/logicScope.js.map +1 -0
  147. package/dist/internal/machine/machine.d.ts +17 -23
  148. package/dist/internal/machine/machine.d.ts.map +1 -1
  149. package/dist/internal/machine/machine.js +24 -40
  150. package/dist/internal/machine/machine.js.map +1 -1
  151. package/dist/internal/machine/observation.d.ts +3 -0
  152. package/dist/internal/machine/observation.d.ts.map +1 -1
  153. package/dist/internal/machine/observation.js +56 -2
  154. package/dist/internal/machine/observation.js.map +1 -1
  155. package/dist/internal/machine/plannedSnapshot.d.ts.map +1 -1
  156. package/dist/internal/machine/plannedSnapshot.js +11 -20
  157. package/dist/internal/machine/plannedSnapshot.js.map +1 -1
  158. package/dist/internal/machine/planner.d.ts +36 -23
  159. package/dist/internal/machine/planner.d.ts.map +1 -1
  160. package/dist/internal/machine/planner.js +15 -8
  161. package/dist/internal/machine/planner.js.map +1 -1
  162. package/dist/internal/machine/process.d.ts +17 -9
  163. package/dist/internal/machine/process.d.ts.map +1 -1
  164. package/dist/internal/machine/process.js +43 -503
  165. package/dist/internal/machine/process.js.map +1 -1
  166. package/dist/internal/machine/protocol.d.ts +1 -1
  167. package/dist/internal/machine/protocol.d.ts.map +1 -1
  168. package/dist/internal/machine/protocol.js +48 -10
  169. package/dist/internal/machine/protocol.js.map +1 -1
  170. package/dist/internal/machine/runtime.d.ts +20 -16
  171. package/dist/internal/machine/runtime.d.ts.map +1 -1
  172. package/dist/internal/machine/runtime.js +93 -88
  173. package/dist/internal/machine/runtime.js.map +1 -1
  174. package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -1
  175. package/dist/internal/machine/runtimeCompiled.js +359 -120
  176. package/dist/internal/machine/runtimeCompiled.js.map +1 -1
  177. package/dist/internal/machine/runtimeProtocol.d.ts +151 -82
  178. package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
  179. package/dist/internal/machine/runtimeProtocol.js +236 -219
  180. package/dist/internal/machine/runtimeProtocol.js.map +1 -1
  181. package/dist/internal/machine/stateDefinition.d.ts +0 -1
  182. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  183. package/dist/internal/machine/stateDefinition.js +0 -1
  184. package/dist/internal/machine/stateDefinition.js.map +1 -1
  185. package/dist/internal/machine/step.d.ts +486 -0
  186. package/dist/internal/machine/step.d.ts.map +1 -0
  187. package/dist/internal/machine/step.js +957 -0
  188. package/dist/internal/machine/step.js.map +1 -0
  189. package/dist/internal/machine/stepHost.d.ts +33 -0
  190. package/dist/internal/machine/stepHost.d.ts.map +1 -0
  191. package/dist/internal/machine/stepHost.js +501 -0
  192. package/dist/internal/machine/stepHost.js.map +1 -0
  193. package/dist/internal/machine/symbols.d.ts +2 -11
  194. package/dist/internal/machine/symbols.d.ts.map +1 -1
  195. package/dist/internal/machine/symbols.js +2 -2
  196. package/dist/internal/machine/symbols.js.map +1 -1
  197. package/dist/internal/machine/transition.d.ts +7 -7
  198. package/dist/internal/machine/transition.d.ts.map +1 -1
  199. package/dist/internal/testing/machine/check.d.ts.map +1 -1
  200. package/dist/internal/testing/machine/check.js +217 -25
  201. package/dist/internal/testing/machine/check.js.map +1 -1
  202. package/dist/internal/testing/machine/exploration.d.ts +19 -2
  203. package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
  204. package/dist/internal/testing/machine/exploration.js +14 -3
  205. package/dist/internal/testing/machine/exploration.js.map +1 -1
  206. package/dist/internal/testing/machine/format.js.map +1 -1
  207. package/dist/internal/testing/machine/probe.d.ts.map +1 -1
  208. package/dist/internal/testing/machine/probe.js +1 -1
  209. package/dist/internal/testing/machine/probe.js.map +1 -1
  210. package/dist/internal/testing/machine/runtime.d.ts +2 -2
  211. package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
  212. package/dist/internal/testing/machine/runtime.js +10 -3
  213. package/dist/internal/testing/machine/runtime.js.map +1 -1
  214. package/dist/internal/testing/machine/trace.d.ts +38 -3
  215. package/dist/internal/testing/machine/trace.d.ts.map +1 -1
  216. package/dist/internal/testing/machine/trace.js +180 -33
  217. package/dist/internal/testing/machine/trace.js.map +1 -1
  218. package/dist/internal/testing/machine/transitionCoverage.d.ts +1 -1
  219. package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -1
  220. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  221. package/dist/internal/testing/machine/verification.js +9 -1
  222. package/dist/internal/testing/machine/verification.js.map +1 -1
  223. package/dist/internal/testing/machine/work.d.ts +47 -0
  224. package/dist/internal/testing/machine/work.d.ts.map +1 -0
  225. package/dist/internal/testing/machine/work.js +74 -0
  226. package/dist/internal/testing/machine/work.js.map +1 -0
  227. package/dist/testing/MachineTest.d.ts +253 -37
  228. package/dist/testing/MachineTest.d.ts.map +1 -1
  229. package/dist/testing/MachineTest.js +81 -9
  230. package/dist/testing/MachineTest.js.map +1 -1
  231. package/dist/unstable/cluster/ClusterMachine.d.ts +1071 -41
  232. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  233. package/dist/unstable/cluster/ClusterMachine.js +441 -12
  234. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  235. package/dist/unstable/cluster/ClusterMachineProxy.d.ts +257 -0
  236. package/dist/unstable/cluster/ClusterMachineProxy.d.ts.map +1 -0
  237. package/dist/unstable/cluster/ClusterMachineProxy.js +73 -0
  238. package/dist/unstable/cluster/ClusterMachineProxy.js.map +1 -0
  239. package/dist/unstable/cluster/SqlMachineStorage.d.ts +125 -0
  240. package/dist/unstable/cluster/SqlMachineStorage.d.ts.map +1 -0
  241. package/dist/unstable/cluster/SqlMachineStorage.js +62 -0
  242. package/dist/unstable/cluster/SqlMachineStorage.js.map +1 -0
  243. package/dist/unstable/cluster/index.d.ts +13 -0
  244. package/dist/unstable/cluster/index.d.ts.map +1 -1
  245. package/dist/unstable/cluster/index.js +13 -0
  246. package/dist/unstable/cluster/index.js.map +1 -1
  247. package/dist/unstable/reactivity/AtomMachine.d.ts +21 -26
  248. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  249. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  250. package/package.json +5 -3
  251. package/src/LocalMachine.ts +611 -0
  252. package/src/Machine.ts +1383 -1336
  253. package/src/index.ts +1 -0
  254. package/src/internal/machine/atom.ts +20 -49
  255. package/src/internal/machine/capability.ts +123 -0
  256. package/src/internal/machine/{invocationDefinition.ts → capturedInvocation.ts} +13 -13
  257. package/src/internal/machine/child.ts +25 -0
  258. package/src/internal/machine/childRegistry.ts +1 -4
  259. package/src/internal/machine/cluster.ts +420 -205
  260. package/src/internal/machine/clusterChild.ts +117 -0
  261. package/src/internal/machine/clusterFailure.ts +53 -0
  262. package/src/internal/machine/clusterInstance.ts +1779 -0
  263. package/src/internal/machine/clusterKeepAlive.ts +93 -0
  264. package/src/internal/machine/clusterProgress.ts +159 -0
  265. package/src/internal/machine/clusterProtocol.ts +46 -4
  266. package/src/internal/machine/clusterProxy.ts +233 -0
  267. package/src/internal/machine/clusterRead.ts +207 -0
  268. package/src/internal/machine/clusterSqlStorage.ts +181 -0
  269. package/src/internal/machine/clusterStorageCheck.ts +274 -0
  270. package/src/internal/machine/clusterTarget.ts +154 -0
  271. package/src/internal/machine/clusterTimer.ts +58 -0
  272. package/src/internal/machine/clusterWake.ts +100 -0
  273. package/src/internal/machine/clusterWork.ts +269 -0
  274. package/src/internal/machine/command.ts +4 -4
  275. package/src/internal/machine/commandRuntime.ts +12 -24
  276. package/src/internal/machine/configuration.ts +0 -181
  277. package/src/internal/machine/errors.ts +11 -2
  278. package/src/internal/machine/executionPlan.ts +493 -263
  279. package/src/internal/machine/implementation.ts +6 -6
  280. package/src/internal/machine/inspectionRuntime.ts +1 -1
  281. package/src/internal/machine/invocationChanges.ts +89 -0
  282. package/src/internal/machine/{activities.ts → invocationDefinitions.ts} +10 -10
  283. package/src/internal/machine/invocationEvent.ts +35 -12
  284. package/src/internal/machine/invocationOutcome.ts +145 -0
  285. package/src/internal/machine/invocationResolution.ts +307 -0
  286. package/src/internal/machine/logicScope.ts +47 -0
  287. package/src/internal/machine/machine.ts +35 -100
  288. package/src/internal/machine/observation.ts +67 -2
  289. package/src/internal/machine/plannedSnapshot.ts +17 -20
  290. package/src/internal/machine/planner.ts +75 -99
  291. package/src/internal/machine/process.ts +78 -722
  292. package/src/internal/machine/protocol.ts +70 -26
  293. package/src/internal/machine/runtime.ts +198 -195
  294. package/src/internal/machine/runtimeCompiled.ts +496 -171
  295. package/src/internal/machine/runtimeProtocol.ts +416 -305
  296. package/src/internal/machine/stateDefinition.ts +0 -5
  297. package/src/internal/machine/step.ts +1518 -0
  298. package/src/internal/machine/stepHost.ts +634 -0
  299. package/src/internal/machine/symbols.ts +3 -14
  300. package/src/internal/machine/transition.ts +11 -11
  301. package/src/internal/testing/machine/check.ts +240 -36
  302. package/src/internal/testing/machine/exploration.ts +42 -3
  303. package/src/internal/testing/machine/format.ts +1 -1
  304. package/src/internal/testing/machine/probe.ts +2 -1
  305. package/src/internal/testing/machine/runtime.ts +15 -5
  306. package/src/internal/testing/machine/trace.ts +261 -41
  307. package/src/internal/testing/machine/transitionCoverage.ts +1 -1
  308. package/src/internal/testing/machine/verification.ts +11 -5
  309. package/src/internal/testing/machine/work.ts +101 -0
  310. package/src/testing/MachineTest.ts +268 -44
  311. package/src/unstable/cluster/ClusterMachine.ts +1183 -59
  312. package/src/unstable/cluster/ClusterMachineProxy.ts +372 -0
  313. package/src/unstable/cluster/SqlMachineStorage.ts +136 -0
  314. package/src/unstable/cluster/index.ts +15 -0
  315. package/src/unstable/reactivity/AtomMachine.ts +27 -88
  316. package/dist/internal/machine/activities.d.ts.map +0 -1
  317. package/dist/internal/machine/activities.js.map +0 -1
  318. package/dist/internal/machine/invocation.d.ts +0 -33
  319. package/dist/internal/machine/invocation.d.ts.map +0 -1
  320. package/dist/internal/machine/invocation.js +0 -220
  321. package/dist/internal/machine/invocation.js.map +0 -1
  322. package/dist/internal/machine/invocationDefinition.d.ts.map +0 -1
  323. package/dist/internal/machine/invocationDefinition.js.map +0 -1
  324. package/dist/internal/machine/requirements.d.ts +0 -4
  325. package/dist/internal/machine/requirements.d.ts.map +0 -1
  326. package/dist/internal/machine/requirements.js +0 -2
  327. package/dist/internal/machine/requirements.js.map +0 -1
  328. package/dist/internal/machine/runtimeGeneric.d.ts +0 -3
  329. package/dist/internal/machine/runtimeGeneric.d.ts.map +0 -1
  330. package/dist/internal/machine/runtimeGeneric.js +0 -465
  331. package/dist/internal/machine/runtimeGeneric.js.map +0 -1
  332. package/src/internal/machine/invocation.ts +0 -376
  333. package/src/internal/machine/requirements.ts +0 -11
  334. package/src/internal/machine/runtimeGeneric.ts +0 -797
package/AGENTS.md CHANGED
@@ -91,18 +91,20 @@ Start the implemented machine at the application boundary and send events
91
91
  through the exported descriptor:
92
92
 
93
93
  ```ts
94
+ import { LocalMachine } from "@typeonce/effect-machine"
94
95
  import { Effect } from "effect"
95
96
 
96
97
  const program = Effect.scoped(Effect.gen(function*() {
97
- const counter = yield* Machine.start(CounterMachine)
98
+ const counter = yield* LocalMachine.start(CounterMachine)
98
99
 
99
100
  yield* counter.send(CounterEvents.Start())
100
101
  yield* counter.send(CounterEvents.Increment())
101
102
  }))
102
103
  ```
103
104
 
104
- `Machine.start` requires a `Scope`. Closing it stops the machine and everything
105
- it owns; use `ref.stop` to stop earlier.
105
+ `LocalMachine` runs a machine in memory. `LocalMachine.start` requires a `Scope`.
106
+ Closing it stops the machine and everything it owns; use `ref.stop` to stop
107
+ earlier.
106
108
 
107
109
  ### Make impossible states unrepresentable
108
110
 
@@ -352,6 +354,20 @@ const LoadMachine = Machine.make({
352
354
  implemented machine type, so the runtime must provide them when it starts the
353
355
  machine.
354
356
 
357
+ The same requirements say what a machine needs of the host that runs it.
358
+ `Machine.InvocationSupport<"Stream">`, `<"Logic">`, and `<"Child">` mark a machine
359
+ whose states invoke that kind. `Machine.MachineRuntime` marks one whose work uses
360
+ `Machine.spawn`, or `Machine.sendTo` or `Machine.stopChild` with a child address,
361
+ and `Machine.ChildMachineRuntime` one whose work uses `Machine.sendTo` or
362
+ `Machine.stopChild` with the descriptor of a child machine. `LocalMachine` and
363
+ `AtomMachine` run all of them. `ClusterMachine.make` runs Effects, timers, and
364
+ child machines, and provides `Machine.ChildMachineRuntime`. It does not compile
365
+ for a machine that invokes a Stream or a `Logic`, or needs
366
+ `Machine.MachineRuntime`, and its error lists what to replace. Cluster stores
367
+ each step and runs work again after a crash, so it runs only work that ends with
368
+ one outcome: the progress of a Stream and the state of a `Logic` live in memory
369
+ and would be lost. Model such work as a child machine.
370
+
355
371
  Model a per-instance capability, such as a router or a callback owned by a UI
356
372
  component, as such a service. Do not put functions in state data or startup
357
373
  input: snapshots must remain encodable. A React owner provides the capability
@@ -361,11 +377,11 @@ through its own runtime, as described in
361
377
  Do not start a promise inside a transition callback. A transition has no
362
378
  lifetime in which to own that work. A state does.
363
379
 
364
- Invoked work starts while the event that entered its state is processed. It
365
- runs in the sender's turn until it first suspends, and its outcome is handled
366
- in a later turn, even when the work completes without suspending. A state that
367
- invokes work is therefore always observed before its outcome leaves it. Put a
368
- browser call that requires user activation, such as `window.open` or
380
+ A local machine, including one hosted by `AtomMachine`, starts invoked work while
381
+ the event that entered its state is processed. The work runs in the sender's turn
382
+ until it first suspends, and its outcome is handled in a later turn, even when the
383
+ work completes without suspending. A state that invokes work is therefore always
384
+ observed before its outcome leaves it. Put a browser call that requires user activation, such as `window.open` or
369
385
  `navigator.clipboard.writeText`, in the first step of the invoked Effect:
370
386
 
371
387
  ```ts
@@ -462,6 +478,14 @@ Do not read the clock, generate randomness, call a service, or await work while
462
478
  choosing a transition. Receive such values in an event or produce them through
463
479
  state-owned work first.
464
480
 
481
+ A transition that throws follows one rule on every host: the error goes to the
482
+ sender when one waits for the event to be processed, and otherwise the machine
483
+ fails with it. `send` of `LocalMachine` returns before the event is processed,
484
+ so the machine fails; a `ClusterMachine` client waits, so it is rejected and the
485
+ machine goes on. An event that its schema refuses is different: every host
486
+ rejects it at `send`, `LocalMachine` with `MachineSchemaDecodeError` and
487
+ `ClusterMachine` as `InvalidEvent`, and the machine keeps running.
488
+
465
489
  `resolve` is checked against `branches` in both directions, and each `select`
466
490
  call takes the values of the path it is given. An agent can edit this one
467
491
  transition without reading anything else: a missing entry, an entry that is never
@@ -534,9 +558,26 @@ const verifyCounter = Effect.gen(function*() {
534
558
  From a shell, `effect-machine check src/counter.ts --json` from
535
559
  `@typeonce/effect-machine-devtools` does the same for every machine a file exports.
536
560
 
537
- To fix a finding, keep the failing evidence first. Replay its events to reproduce
538
- it, make the smallest behavior change, then run the check again. Do not silence a
539
- finding by weakening a type or a test.
561
+ To fix a finding, keep the failing evidence first. Pass its `replay` to
562
+ `MachineTest.run` to reproduce it, make the smallest behavior change, then run
563
+ the check again. Do not silence a finding by weakening a type or a test.
564
+
565
+ The check takes the results of invoked work as further branches while that work
566
+ runs. A timer elapses without any option. An Effect's results are only a type,
567
+ so supply the values to try for each registered source in `outcomes`; each value
568
+ is one branch, and the compiler rejects an unknown source or a value of the
569
+ wrong type:
570
+
571
+ ```ts
572
+ const report = yield* MachineTest.check(LoadMachine, {
573
+ outcomes: {
574
+ loadDocument: { done: ["# Title"], failure: [new LoadError()] }
575
+ }
576
+ })
577
+ ```
578
+
579
+ A replay lists the steps in order: events, and the results of work such as
580
+ `done Loading#loadDocument "# Title"` or `elapsed Waiting#timeout`.
540
581
 
541
582
  | Law | Meaning | Fix |
542
583
  | ---------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------- |
@@ -546,13 +587,18 @@ finding by weakening a type or a test.
546
587
  | `planning.failed` | A planning callback threw or a value failed its schema. | Replay the events, then fix the callback or the value. |
547
588
  | `planning.verification` | A planner law failed. This usually means an Effect Machine bug. | Report it with the replay. |
548
589
  | `invariant.violated` | An invariant you supplied failed. | Replay the events, then fix the behavior or the invariant. |
549
- | `transition.notCovered` | Exploration never took a declared branch. This is a warning. | Cover it with a scenario, or remove it if it cannot happen. |
590
+ | `outcome.failsMachine` | A supplied result fails the machine, whose types were erased. | Add the missing `onFailure` or `onDone`. |
591
+ | `outcomes.invalid` | `outcomes` names no Effect source that a state invokes. | Fix the source name, or remove the entry. |
592
+ | `transition.notCovered` | Exploration never took a declared branch. This is a warning. | Cover it with a scenario or another outcome, or remove it. |
550
593
  | `schema.underivable` | Input or events could not be sampled from their schemas. | Pass `input` or `events` explicitly. |
551
594
 
552
595
  A report is `"exhaustive"` only when `limits` is empty. Otherwise a pass means
553
596
  nothing was found in what was explored. Keep sampled checks, bounded exploration,
554
- and proof distinct when reporting a result. Invocations do not run during planning,
555
- so test them on a started machine with `MachineTest.probe`.
597
+ and proof distinct when reporting a result. Supplied outcomes add the
598
+ `customOutcomes` limit. An Effect without outcomes adds `effectsWithoutOutcomes`,
599
+ and Streams, logic, and child machines add `streams`, `logic`, and `children`:
600
+ their results are not explored, so test them on a started machine with
601
+ `MachineTest.probe`.
556
602
 
557
603
  ### Test paths and invariants
558
604
 
@@ -592,9 +638,10 @@ const testProgram = Effect.gen(function*() {
592
638
  })
593
639
  ```
594
640
 
595
- Use pure planner traces for state and transition rules. Start a live machine
596
- and use `MachineTest.probe` when a test depends on timers, invoked work, raised
597
- events, or runtime scheduling.
641
+ Use pure planner traces for state and transition rules, including the results
642
+ of invoked work, which a scenario lists beside its events. Start a live machine
643
+ and use `MachineTest.probe` when a test depends on how the work actually runs,
644
+ on raised events, or on runtime scheduling.
598
645
 
599
646
  ### Choose observation deliberately
600
647
 
@@ -624,7 +671,7 @@ Declare the topology, the protocol, and the behavior, then start the result
624
671
  inside a Scope.
625
672
 
626
673
  ```ts
627
- import { Machine } from "@typeonce/effect-machine"
674
+ import { LocalMachine, Machine } from "@typeonce/effect-machine"
628
675
  import { Effect, Schema } from "effect"
629
676
 
630
677
  // The root declares the topology and the data each state owns.
@@ -661,10 +708,10 @@ export const CounterMachine = Machine.make({
661
708
  }
662
709
  })
663
710
 
664
- // `Machine.start` requires a Scope. Closing it stops the machine and everything
711
+ // `LocalMachine.start` requires a Scope. Closing it stops the machine and everything
665
712
  // the machine owns.
666
713
  export const program = Effect.scoped(Effect.gen(function*() {
667
- const counter = yield* Machine.start(CounterMachine)
714
+ const counter = yield* LocalMachine.start(CounterMachine)
668
715
 
669
716
  yield* counter.send(CounterEvents.Start())
670
717
  yield* counter.send(CounterEvents.Increment())
@@ -864,7 +911,7 @@ const Document = Machine.make({
864
911
  })
865
912
  ```
866
913
 
867
- Start with `Machine.start(Document, { locale: "en", documentId: "intro" })`.
914
+ Start with `LocalMachine.start(Document, { locale: "en", documentId: "intro" })`.
868
915
  Root construction runs before its initial child construction. Both receive the
869
916
  same validated input. `documentId` belongs only to Loading; it need not be stored
870
917
  in root data. Input is not retained as a reset value on the machine or snapshot.
@@ -1004,7 +1051,7 @@ history: {
1004
1051
 
1005
1052
  A fallback must explicitly construct a complete tree containing its owner,
1006
1053
  including required ancestors and parallel siblings. Its root data is state data,
1007
- not startup input. `Machine.resume` restores a validated snapshot without rerunning
1054
+ not startup input. `LocalMachine.resume` restores a validated snapshot without rerunning
1008
1055
  startup constructors.
1009
1056
 
1010
1057
  `guard` declines before construction. A resolver may return `select.decline()` only
@@ -1610,6 +1657,311 @@ Do not wrap hydrated forms in a Suspense boundary that a startup read can
1610
1657
  trigger. A suspended boundary replaces its server-rendered content with the
1611
1658
  fallback and later mounts new DOM nodes, discarding typed text and focus.
1612
1659
 
1660
+ ## Run a machine on Effect Cluster
1661
+
1662
+ `ClusterMachine` from `@typeonce/effect-machine/cluster` runs a machine as a
1663
+ persisted Cluster entity. It takes the same machine that `LocalMachine` runs.
1664
+ Nothing about how the machine is written changes.
1665
+
1666
+ ### Choose a host
1667
+
1668
+ | Host | Where the machine lives | What survives a crash |
1669
+ | ---------------- | --------------------------------------------- | ---------------------------------------- |
1670
+ | `LocalMachine` | in memory, owned by a `Scope` | nothing, unless you encode and resume it |
1671
+ | `AtomMachine` | in memory, owned by an `AtomRegistry` | nothing |
1672
+ | `ClusterMachine` | one entity per id, on any runner of a Cluster | every committed step, from `Storage` |
1673
+
1674
+ Use `ClusterMachine` when a machine must outlive the process that started it,
1675
+ be addressed by id from anywhere, or wait on timers longer than a process
1676
+ lives. Effect Cluster owns identity, placement, routing, and delivery.
1677
+ `ClusterMachine` owns only the step: it applies one input at a time and commits
1678
+ the result to `Storage`.
1679
+
1680
+ `ClusterMachine` needs `effect` 4.1.5 or later. Earlier versions answer the
1681
+ keep-alive request of an entity after about ten minutes, so a machine whose
1682
+ work runs or whose timer waits longer would not come up again after a crash.
1683
+
1684
+ ### Make an adapter
1685
+
1686
+ ```ts
1687
+ import { Machine } from "@typeonce/effect-machine"
1688
+ import { ClusterMachine, SqlMachineStorage } from "@typeonce/effect-machine/cluster"
1689
+ import { Layer } from "effect"
1690
+ import { SqlMessageStorage } from "effect/cluster"
1691
+
1692
+ const Invoice = ClusterMachine.make("Invoice", invoiceMachine, { version: "1" })
1693
+
1694
+ // Provide with a Cluster runner layer and an `SqlClient`.
1695
+ const InvoiceLive = Invoice.toLayer().pipe(
1696
+ Layer.provide(Layer.mergeAll(SqlMessageStorage.layer, SqlMachineStorage.layer))
1697
+ )
1698
+ ```
1699
+
1700
+ `version` is stored with every checkpoint. A checkpoint written by another
1701
+ definition id or version is refused, so change it together with a migration of
1702
+ the stored checkpoints. Pass `shardGroup` to `ClusterMachine.make` to route
1703
+ entities (and their invoked child entities) to named Cluster shard groups.
1704
+
1705
+ `adapter.toLayer(options)` forwards standard Effect Cluster `Entity.toLayer`
1706
+ options (`maxIdleTime`, `concurrency`, `mailboxCapacity`, `mailboxMetrics`,
1707
+ `disableFatalDefects`, `defectRetryPolicy`, `spanAttributes`) to the entity and
1708
+ its children. It also accepts transactional hooks that run inside the same
1709
+ `MessageStorage` transaction as the checkpoint write:
1710
+
1711
+ - `enqueue(event)` durably writes emitted events to an outbox table.
1712
+ - `onCommit({ entityId, checkpoint, snapshot })` runs after every committed
1713
+ checkpoint (active, done, failed), so SQL read-model projections or audit
1714
+ tables commit or roll back atomically with the machine state.
1715
+
1716
+ State values, completion outputs, startup input, and public input events must
1717
+ have JSON encoded forms. A schema that does not is a compile error that names
1718
+ the offending states, events, or input.
1719
+
1720
+ ### What runs, and how often
1721
+
1722
+ Each live entity keeps one machine in memory and applies requests, the ends
1723
+ of invoked effects, and timers one at a time. `Storage` is the truth and
1724
+ memory is a cache: an entity that comes up anywhere continues from its last
1725
+ checkpoint.
1726
+
1727
+ Invoked effects run at least once. Work starts once the step that entered its
1728
+ state is stored, and runs again after a crash, a move to another runner, or a
1729
+ restart, with `Machine.InitialEvent` as the event of its input mapper. Two
1730
+ copies can briefly run at the same time while a shard moves. Exactly one result
1731
+ is applied, and results are not stored. Make every invoked effect safe to
1732
+ repeat, for example with an idempotency key from the state.
1733
+
1734
+ Work that ends in a way the model does not handle fails the machine, as it
1735
+ does locally. The failure is stored as text with the last state, the
1736
+ snapshot reads `failed`, and every later request is rejected as
1737
+ `MachineFailed`. There is no hidden retry: a model that recovers declares
1738
+ `onFailure`. A failure of storage or of Cluster itself never fails the
1739
+ machine; it is retried.
1740
+
1741
+ ### Timers
1742
+
1743
+ A timer is stored as the time at which it is due, in the checkpoint of the step
1744
+ that enters its state. An entity that comes up again waits only for the time
1745
+ that remains, and completes a timer that is already due at once. A timer up to
1746
+ `DurableClock.InMemoryThreshold` (one minute by default) keeps its entity in
1747
+ memory. A longer one is saved as a delayed Cluster message, in the same
1748
+ transaction, so the entity may leave memory and is brought back when the timer
1749
+ is due, up to `entityMessagePollInterval` late.
1750
+
1751
+ This differs from `LocalMachine.resume`, which starts a timer's full duration
1752
+ again.
1753
+
1754
+ ### Children and messages between machines
1755
+
1756
+ A child machine invoked by a state runs as an entity of its own, of type
1757
+ `Type/childId` and id `entityId/childId/revision`, and starts and stops with
1758
+ the stored state. `onDone`, `onFailure`, and `onSnapshot` work as they do
1759
+ locally. A failure of a child fails its parent, even with `onFailure`, because
1760
+ the failure is stored as text.
1761
+
1762
+ `adapter.target(id)` names another Cluster machine. `enqueue.sendTo` with a
1763
+ target or with the descriptor of an invoked child saves the event with the
1764
+ checkpoint of the step, so it is sent if and only if the step is stored, and
1765
+ applied once. `enqueue.stop` with the descriptor of an invoked child stops the
1766
+ running child in the same transaction and settles its progress so it does not
1767
+ restart while its state stays active. Commands run before the work of the states
1768
+ a step enters starts, as they do locally, so both drop a child that the same step
1769
+ enters. Work sends with `Machine.sendTo` and stops a child with
1770
+ `Machine.stopChild`, given the child's descriptor, and an input mapper does the
1771
+ same with `children.sendTo` and `children.stop`. `children.spawn` fails the
1772
+ machine.
1773
+
1774
+ ### What is refused, and why
1775
+
1776
+ These do not compile with `ClusterMachine.make`. The error names the property
1777
+ `~effect/cluster/ClusterMachine/UnsupportedProcessLocal` and lists what to replace:
1778
+
1779
+ - a state that invokes a Stream or a `Logic`;
1780
+ - work that requires `Machine.MachineRuntime`, such as `Machine.spawn`, or
1781
+ `Machine.sendTo` and `Machine.stopChild` with a child address.
1782
+
1783
+ A checkpoint holds the state of a machine, and after a crash its work runs
1784
+ again from the start. An Effect or a timer ends with one outcome, so running it
1785
+ again changes nothing that was applied. A Stream ends after many elements, and
1786
+ how far it got lives only in memory; a `Logic` has a state and a mailbox of its
1787
+ own. Both would be lost. Model a source of many events as a child machine,
1788
+ whose every step is stored, or as an Effect that ends with one result and a
1789
+ state that is entered again for the next one.
1790
+
1791
+ ### Talk to a machine from outside
1792
+
1793
+ ```ts
1794
+ const program = Effect.gen(function*() {
1795
+ const client = (yield* Invoice.client)("invoice-1")
1796
+ yield* client.send(Events.Send({ invoiceId: "inv-1" }))
1797
+ const latest = yield* client.snapshot // Option of the last committed checkpoint
1798
+ const receipt = yield* client.join // waits for the output, or fails with MachineFailedError
1799
+ })
1800
+ ```
1801
+
1802
+ `start` initializes an entity with its per-entity startup input (or commits the
1803
+ initial state of a machine without input without needing an event). It is an
1804
+ idempotent no-op when the entity is already active, and rejects as
1805
+ `MachineFailed` if the entity failed or was stopped. A machine that declares
1806
+ `input` can omit a static default input in `ClusterMachine.make` so each entity
1807
+ is started with `client.start(input)` (sending an event before start rejects as
1808
+ `InvalidEvent`), or pass a default input so `send` can auto-start while
1809
+ `client.start(customInput)` still starts with per-entity input.
1810
+
1811
+ `send` decodes the event as a local reference does and waits until the step is
1812
+ committed. An event the machine refuses fails with `Rejected` and its reason.
1813
+ Failures of Cluster itself are `ClientError`s; a request that ended in one may
1814
+ still have been delivered, and is applied at most once when sent again.
1815
+
1816
+ `snapshot`, `changes`, and `join` read `Storage`, never the entity, so they
1817
+ work from any process that reaches the store and never wake the entity. A
1818
+ client is a remote view, narrower than a `MachineRef`: it sees committed
1819
+ checkpoints only, `changes` polls every `readInterval` (one second by default)
1820
+ and may skip checkpoints in between, a failure is text rather than a `Cause`,
1821
+ and nothing is read before the first event is committed.
1822
+
1823
+ ### Storage
1824
+
1825
+ `ClusterMachine.Storage` holds one checkpoint per entity and the ids of the
1826
+ requests it committed. `SqlMachineStorage` implements it for PostgreSQL and
1827
+ SQLite. Use it over the same `SqlClient` as `SqlMessageStorage`, so a
1828
+ checkpoint, the events it sends, and the reply commit in one transaction. Its
1829
+ `layer` runs migrations first; use `layerMigrations` in a deploy step and
1830
+ `layerStorage` at runtime to run them with another connection.
1831
+ `ClusterMachine.layerMemory` is for tests and is not durable.
1832
+
1833
+ To write a store of your own, run `ClusterMachine.checkStorage` against it in
1834
+ your tests, with the `withTransaction` of its `MessageStorage`. It fails with
1835
+ the first part of the contract the store breaks.
1836
+
1837
+ ### Run in a Web Worker or over RPC
1838
+
1839
+ `ClusterMachine` and `SqlMachineStorage` have no Node.js dependencies, so a
1840
+ single-node Cluster can run inside a Web Worker or `SharedWorker` with
1841
+ `SingleRunner.layer` and a browser SQL client such as `@effect/sql-sqlite-wasm`
1842
+ or `@effect/sql-pglite`.
1843
+
1844
+ When the runner and its database live in another thread or process, callers do
1845
+ not have direct access to `Sharding` or `ClusterMachine.Storage`.
1846
+ `ClusterMachineProxy` from `@typeonce/effect-machine/cluster` exposes `start`,
1847
+ `send`, `snapshot`, `changes`, and `join` over any `effect/rpc` transport (Web
1848
+ Workers, `SharedWorker`, Node worker threads, WebSockets, or HTTP):
1849
+
1850
+ ```ts
1851
+ // Inside the Web Worker: serve one machine over RpcServer.Protocol
1852
+ const WorkerLive = ClusterMachineProxy.toLayer(Invoice).pipe(
1853
+ Layer.provide(Invoice.toLayer()),
1854
+ Layer.provide(ClusterLive),
1855
+ Layer.provide(RpcServer.layerProtocolWorkerRunner)
1856
+ )
1857
+
1858
+ // On the main thread: zero Sharding, zero Storage, zero SQL
1859
+ const program = Effect.gen(function*() {
1860
+ const client = (yield* ClusterMachineProxy.client(Invoice))("invoice-1")
1861
+ yield* client.send(Events.Send({ invoiceId: "inv-1" }))
1862
+ const latest = yield* client.snapshot
1863
+ const receipt = yield* client.join
1864
+ })
1865
+ ```
1866
+
1867
+ To host several machines on one worker or server, merge their groups with
1868
+ `ClusterMachineProxy.toRpcGroup(A).merge(ClusterMachineProxy.toRpcGroup(B))` and
1869
+ provide each with `ClusterMachineProxy.layerHandlers`. When using
1870
+ `RpcClient.layerProtocolWorker` with `size: 1`, set `concurrency` above `1` (for
1871
+ example `{ size: 1, concurrency: 100 }`) so streaming `changes` or `join` calls
1872
+ do not block concurrent `send` calls.
1873
+
1874
+ ## Write a host for a new runtime
1875
+
1876
+ Applications run machines with `LocalMachine`, `AtomMachine`, or
1877
+ `ClusterMachine`. Use `Machine.toStep` only to run a machine somewhere these
1878
+ hosts do not reach, such as a UI store that keeps the state itself.
1879
+
1880
+ `Machine.toStep(machine, options)` returns pure functions. They run nothing and
1881
+ call no user code: each one returns the next state as a value, with the
1882
+ commands to carry out and the work to stop and to start.
1883
+
1884
+ ```ts
1885
+ const step = Machine.toStep(machine, { self, parent, children })
1886
+
1887
+ step.start(input) // Exit<Step, StartError>: the machine starts
1888
+ step.send(state, event) // Exit<Step, Rejection>: a public event arrives
1889
+ step.settle(state, work, exit) // Step: work ended, or could not start
1890
+ step.element(state, work, value) // Step: a running Stream produced a value
1891
+ step.report(state, work, snapshot) // Step: a running Logic or child machine reached a state
1892
+ step.stop(state) // Step: the owner stops the machine
1893
+ step.resume(snapshot, progress) // Exit<Step, MachineSchemaDecodeError>: from a decoded snapshot
1894
+ ```
1895
+
1896
+ The options are what the machine needs of its host:
1897
+
1898
+ - `self` is the host's own target. Transitions and input mappers receive it,
1899
+ so its `send` must plan the event in a later step.
1900
+ - `parent` is the target of the owner, for a machine that declares a parent.
1901
+ It is required when the parent is.
1902
+ - `children` are the operations on the children of the machine, which the host
1903
+ owns: `spawn`, `spawnLogic`, `sendTo`, and `stop`. They are required when work
1904
+ requires `Machine.MachineRuntime` or `Machine.ChildMachineRuntime`. Without
1905
+ them, every operation on children fails the machine with `ProcessLocalError`.
1906
+
1907
+ A host carries out each `Step` in this order: carry out `commands`, interrupt
1908
+ `stop`, publish `snapshot`, deliver `emitted`, start `start`, then interrupt
1909
+ `stopAfter`. Pass `step.state` to the next call.
1910
+
1911
+ - A failed `Exit` from `send`, `start`, or `resume` means nothing happened. An
1912
+ event is rejected because its schema refused it or because the machine has
1913
+ ended, and the state you passed still holds.
1914
+ - A machine that fails or ends still returns a `Step`. Its `exit` is set: when
1915
+ it reaches a final state, `stop` lists the work of exited states (interrupted
1916
+ before `snapshot` and `emitted`) and `stopAfter` lists the remaining work of
1917
+ states that stayed active (interrupted after `emitted`, latest first); when it
1918
+ fails or is stopped by its owner, `stop` lists every piece of work that still
1919
+ runs and `stopAfter` is empty.
1920
+ - `commands` are `Send` (call `target.send(event)`), `SendToChild`, and
1921
+ `StopChild`. A command to a child names the running `Logic` or child machine
1922
+ it selects as `work`. A stopped one no longer runs, and reports nothing. With
1923
+ no `work`, the command is for a child that work spawned.
1924
+ - `snapshot` and `microsteps` are built when first read. `event` is the event
1925
+ the step planned, for inspection.
1926
+
1927
+ Work is data. The host evaluates each piece as it starts it, in order, with the
1928
+ accessor of its kind. Each accessor calls the source and the input mapper at
1929
+ most once and returns an `Exit`:
1930
+
1931
+ - `Effect`: `work.effect()`, then run it and settle its `Exit`.
1932
+ - `Timer`: `work.duration()` holds how long to wait, then settle with
1933
+ `Exit.void`. It fails, like every accessor, when the timer cannot start,
1934
+ also when its input names no duration. `work.effect()` is the same timer as
1935
+ an Effect, for a host whose timers wait on fibers.
1936
+ - `Stream`: `work.stream()`. Report each element with `element`, pull the next
1937
+ element after that step, and settle with the end of the stream.
1938
+ - `Logic`: `work.logic()`. Run `initial` and `run` with contexts of the host,
1939
+ `report` each state it sets, and settle with the end of `run`.
1940
+ - `Child`: `work.input()` holds the arguments of its `start`. Host
1941
+ `work.child.machine` with `Machine.toStep` again, with this machine as its
1942
+ `parent`, `report` its snapshots, and settle with its `exit`.
1943
+
1944
+ A failed accessor means the work could not start: settle the work with that
1945
+ `Exit` at once. The machine fails and runs no more work, so do not start the rest
1946
+ of the step.
1947
+
1948
+ The state value records which entry of a state each piece of work belongs to.
1949
+ `settle`, `element`, and `report` ignore work whose state was exited, so the host
1950
+ never compares anything. Pass back the work object that a step listed: work is
1951
+ matched by identity, so a result from before a `resume` is ignored too.
1952
+
1953
+ A durable host passes `progress` to `resume`: `{ path, id, status }` for each
1954
+ invocation of an active state that `"Ended"` or is still `"Running"`. Ended work
1955
+ is not listed again. Running work is not in `start`; find it in `step.running`
1956
+ and settle it when it ends. To keep that progress, read `step.exited` and
1957
+ `step.entered`, the paths of the states a step left and entered, without
1958
+ building a snapshot: forget what you stored for the work of an exited state.
1959
+ A result that is ignored returns a step whose `state` is the state you passed.
1960
+ `ClusterMachine` is such a host.
1961
+
1962
+ A host that runs only some kinds of work refuses the others at compile time:
1963
+ `machine: M & Machine.MachineStep.Supported<M, "Stream">`.
1964
+
1613
1965
  ## Effect Machine implementation review
1614
1966
 
1615
1967
  Use this review after a machine and its UI adapter have been implemented. Look