@orangecharts/wrun-chart-host 0.4.0 → 0.6.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 (331) hide show
  1. package/README.md +17 -5
  2. package/dist/constants/exchange-names.leaf.d.ts +8 -0
  3. package/dist/constants/exchange-names.leaf.js +101 -0
  4. package/dist/constants/feature-flags.constants.js +7 -2
  5. package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +15 -0
  6. package/dist/constants/kscript-data-interval-restrictions.constants.js +40 -0
  7. package/dist/constants/opra-compliance.constants.d.ts +19 -0
  8. package/dist/constants/opra-compliance.constants.js +19 -0
  9. package/dist/constants/replay-ladder.leaf.d.ts +30 -0
  10. package/dist/constants/replay-ladder.leaf.js +99 -0
  11. package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +168 -0
  12. package/dist/constants/scriptEditor/cme-official-scripts.constants.js +398 -0
  13. package/dist/constants/scriptEditor/converted-script-id.leaf.d.ts +8 -0
  14. package/dist/constants/scriptEditor/converted-script-id.leaf.js +10 -0
  15. package/dist/constants/scriptEditor/execution.constants.d.ts +4 -0
  16. package/dist/constants/scriptEditor/execution.constants.js +14 -0
  17. package/dist/constants/wrun-prefix-safe.constants.d.ts +23 -0
  18. package/dist/constants/wrun-prefix-safe.constants.js +26 -0
  19. package/dist/host-env.d.ts +301 -22
  20. package/dist/host-env.js +15 -0
  21. package/dist/host-ports.types.d.ts +853 -29
  22. package/dist/index.d.ts +140 -2
  23. package/dist/index.js +140 -2
  24. package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +31 -0
  25. package/dist/instances/script-engine-worker-ohlcv-transfer.js +164 -0
  26. package/dist/interfaces/market-event.interface.d.ts +231 -0
  27. package/dist/interfaces/market-event.interface.js +15 -0
  28. package/dist/interfaces/opra-realtime.interface.d.ts +70 -134
  29. package/dist/interfaces/opra-realtime.interface.js +34 -59
  30. package/dist/interfaces/replay.interface.d.ts +285 -0
  31. package/dist/interfaces/replay.interface.js +1 -0
  32. package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
  33. package/dist/interfaces/wrun-runtime.interface.js +17 -3
  34. package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +1 -0
  35. package/dist/kscript-data/controls/live-ohlcv-merge.util.js +93 -0
  36. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +5 -1
  37. package/dist/kscript-data/controls/live-trades-merge.util.js +2 -2
  38. package/dist/market-data/billing.interface.d.ts +219 -0
  39. package/dist/market-data/billing.interface.js +58 -0
  40. package/dist/market-data/venue-governed.util.d.ts +2 -0
  41. package/dist/market-data/venue-governed.util.js +10 -0
  42. package/dist/market-data/venue.d.ts +122 -0
  43. package/dist/market-data/venue.js +1 -0
  44. package/dist/market-data/venues/index.d.ts +97 -0
  45. package/dist/market-data/venues/index.js +33 -0
  46. package/dist/market-data/venues/opra.contract.copy.json +35 -0
  47. package/dist/market-data/venues/opra.d.ts +70 -0
  48. package/dist/market-data/venues/opra.js +74 -0
  49. package/dist/replay/replayIndicatorRows.d.ts +31 -0
  50. package/dist/replay/replayIndicatorRows.js +117 -0
  51. package/dist/replay/replayLadder.d.ts +85 -0
  52. package/dist/replay/replayLadder.js +388 -0
  53. package/dist/utility/auth/server-clock.util.d.ts +81 -0
  54. package/dist/utility/auth/server-clock.util.js +238 -0
  55. package/dist/utility/chart/builtin-identity.util.d.ts +18 -0
  56. package/dist/utility/chart/builtin-identity.util.js +51 -0
  57. package/dist/utility/chart/cache-alignment.util.d.ts +454 -0
  58. package/dist/utility/chart/cache-alignment.util.js +926 -0
  59. package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +15 -0
  60. package/dist/utility/chart/chart-data-fetch-generation.util.js +22 -0
  61. package/dist/utility/chart/chart-mount-epoch.util.d.ts +17 -0
  62. package/dist/utility/chart/chart-mount-epoch.util.js +61 -0
  63. package/dist/utility/chart/chart-time-domain.util.d.ts +12 -0
  64. package/dist/utility/chart/chart-time-domain.util.js +23 -0
  65. package/dist/utility/chart/color-customization.leaf.d.ts +10 -0
  66. package/dist/utility/chart/color-customization.leaf.js +16 -0
  67. package/dist/utility/chart/footprint-tick-grid.util.d.ts +106 -0
  68. package/dist/utility/chart/footprint-tick-grid.util.js +167 -0
  69. package/dist/utility/chart/gesture-timing.leaf.d.ts +29 -0
  70. package/dist/utility/chart/gesture-timing.leaf.js +29 -0
  71. package/dist/utility/chart/governed-contract-coin.util.d.ts +22 -0
  72. package/dist/utility/chart/governed-contract-coin.util.js +39 -0
  73. package/dist/utility/chart/host-bar-placement.util.d.ts +107 -0
  74. package/dist/utility/chart/host-bar-placement.util.js +447 -0
  75. package/dist/utility/chart/index-host-tier.util.d.ts +31 -0
  76. package/dist/utility/chart/index-host-tier.util.js +118 -0
  77. package/dist/utility/chart/index-mode-admission.util.d.ts +34 -0
  78. package/dist/utility/chart/index-mode-admission.util.js +67 -0
  79. package/dist/utility/chart/indicator-error-message.util.d.ts +35 -0
  80. package/dist/utility/chart/indicator-error-message.util.js +44 -0
  81. package/dist/utility/chart/kscript-apply-fingerprint.util.d.ts +65 -0
  82. package/dist/utility/chart/kscript-apply-fingerprint.util.js +357 -0
  83. package/dist/utility/chart/kscript-chart-flush.leaf.d.ts +22 -0
  84. package/dist/utility/chart/kscript-chart-flush.leaf.js +13 -0
  85. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +6 -0
  86. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +27 -0
  87. package/dist/utility/chart/kscript-integration-decision.leaf.d.ts +89 -0
  88. package/dist/utility/chart/kscript-integration-decision.leaf.js +80 -0
  89. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +76 -0
  90. package/dist/utility/chart/kscript-live-coalesce.util.js +156 -0
  91. package/dist/utility/chart/kscript-live-rest-pace.util.d.ts +34 -0
  92. package/dist/utility/chart/kscript-live-rest-pace.util.js +134 -0
  93. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +98 -0
  94. package/dist/utility/chart/kscript-live-source-identity.util.js +121 -0
  95. package/dist/utility/chart/kscript-mounted-plot-set.leaf.d.ts +48 -0
  96. package/dist/utility/chart/kscript-mounted-plot-set.leaf.js +145 -0
  97. package/dist/utility/chart/kscript-perf-tracker.util.d.ts +243 -0
  98. package/dist/utility/chart/kscript-perf-tracker.util.js +522 -0
  99. package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +43 -0
  100. package/dist/utility/chart/kscript-run-interval-projection.util.js +471 -0
  101. package/dist/utility/chart/kscript-run-result-equality.util.d.ts +38 -0
  102. package/dist/utility/chart/kscript-run-result-equality.util.js +89 -0
  103. package/dist/utility/chart/kscript-settings-revision.leaf.d.ts +2 -0
  104. package/dist/utility/chart/kscript-settings-revision.leaf.js +12 -0
  105. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +63 -0
  106. package/dist/utility/chart/kscript-source-degrade.leaf.js +68 -0
  107. package/dist/utility/chart/kscript-source-retention.util.d.ts +134 -0
  108. package/dist/utility/chart/kscript-source-retention.util.js +218 -0
  109. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +57 -0
  110. package/dist/utility/chart/kscript-standin-identity.leaf.js +61 -0
  111. package/dist/utility/chart/kscript-titancharts-preparation.util.d.ts +15 -0
  112. package/dist/utility/chart/kscript-titancharts-preparation.util.js +376 -0
  113. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +9 -0
  114. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +130 -0
  115. package/dist/utility/chart/kscript-venue-policy.util.d.ts +217 -0
  116. package/dist/utility/chart/kscript-venue-policy.util.js +324 -0
  117. package/dist/utility/chart/live-cadence.util.d.ts +38 -0
  118. package/dist/utility/chart/live-cadence.util.js +37 -0
  119. package/dist/utility/chart/live-feed-series-match.leaf.d.ts +13 -0
  120. package/dist/utility/chart/live-feed-series-match.leaf.js +21 -0
  121. package/dist/utility/chart/local-engine-self-heal-backoff.util.d.ts +46 -0
  122. package/dist/utility/chart/local-engine-self-heal-backoff.util.js +46 -0
  123. package/dist/utility/chart/local-engine-uninit.leaf.d.ts +21 -0
  124. package/dist/utility/chart/local-engine-uninit.leaf.js +22 -0
  125. package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +62 -0
  126. package/dist/utility/chart/local-kscript-source-revalidation.util.js +123 -0
  127. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +214 -0
  128. package/dist/utility/chart/local-kscript-warmup-depth.util.js +376 -0
  129. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.d.ts +85 -0
  130. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.js +197 -0
  131. package/dist/utility/chart/local-technical-script-range.leaf.d.ts +72 -0
  132. package/dist/utility/chart/local-technical-script-range.leaf.js +126 -0
  133. package/dist/utility/chart/mixed-mode.util.d.ts +167 -0
  134. package/dist/utility/chart/mixed-mode.util.js +139 -0
  135. package/dist/utility/chart/ohlcv-row-readiness.util.d.ts +36 -0
  136. package/dist/utility/chart/ohlcv-row-readiness.util.js +90 -0
  137. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +19 -0
  138. package/dist/utility/chart/opra-user-scripts-gate.util.js +32 -0
  139. package/dist/utility/chart/overlay-execution-guard-key.leaf.d.ts +8 -0
  140. package/dist/utility/chart/overlay-execution-guard-key.leaf.js +10 -0
  141. package/dist/utility/chart/price-precision.util.d.ts +40 -0
  142. package/dist/utility/chart/price-precision.util.js +70 -0
  143. package/dist/utility/chart/profile-block-size.util.d.ts +64 -0
  144. package/dist/utility/chart/profile-block-size.util.js +141 -0
  145. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.d.ts +11 -0
  146. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.js +29 -0
  147. package/dist/utility/chart/protected-kscript-empty-output.util.d.ts +28 -0
  148. package/dist/utility/chart/protected-kscript-empty-output.util.js +84 -0
  149. package/dist/utility/chart/run-interval-unservable.leaf.d.ts +9 -0
  150. package/dist/utility/chart/run-interval-unservable.leaf.js +20 -0
  151. package/dist/utility/chart/run-interval-warmup.leaf.d.ts +19 -0
  152. package/dist/utility/chart/run-interval-warmup.leaf.js +35 -0
  153. package/dist/utility/chart/titan-constants.pin.d.ts +9 -5
  154. package/dist/utility/chart/titan-constants.pin.js +18 -5
  155. package/dist/utility/chart/warmup-backfill-retry.leaf.d.ts +9 -0
  156. package/dist/utility/chart/warmup-backfill-retry.leaf.js +9 -0
  157. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +11 -2
  158. package/dist/utility/chart/wrun-bar-session-facts.util.js +10 -3
  159. package/dist/utility/chart/wrun-run-result.util.d.ts +5 -1
  160. package/dist/utility/chart/wrun-run-result.util.js +20 -14
  161. package/dist/utility/common/data-processing.util.d.ts +138 -0
  162. package/dist/utility/common/data-processing.util.js +346 -0
  163. package/dist/utility/common/visible-timeout.util.d.ts +13 -4
  164. package/dist/utility/common/visible-timeout.util.js +23 -8
  165. package/dist/utility/exchange-format.leaf.d.ts +1 -0
  166. package/dist/utility/exchange-format.leaf.js +47 -0
  167. package/dist/utility/market-events/earnings-scope.util.d.ts +60 -0
  168. package/dist/utility/market-events/earnings-scope.util.js +92 -0
  169. package/dist/utility/market-events/market-events.util.d.ts +147 -0
  170. package/dist/utility/market-events/market-events.util.js +392 -0
  171. package/dist/utility/market-events/zoned-clock.util.d.ts +1 -0
  172. package/dist/utility/market-events/zoned-clock.util.js +11 -0
  173. package/dist/utility/options/option-venue-disclosure.util.d.ts +43 -0
  174. package/dist/utility/options/option-venue-disclosure.util.js +56 -0
  175. package/dist/utility/scriptEditor/package-semver.util.d.ts +51 -0
  176. package/dist/utility/scriptEditor/package-semver.util.js +120 -0
  177. package/dist/utility/scriptEditor/temp-script-id.util.d.ts +18 -0
  178. package/dist/utility/scriptEditor/temp-script-id.util.js +25 -0
  179. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.d.ts +20 -0
  180. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.js +81 -0
  181. package/dist/utility/v2/governed-tier.leaf.d.ts +103 -0
  182. package/dist/utility/v2/governed-tier.leaf.js +113 -0
  183. package/dist/utility/watchlist/import/import-request.leaf.d.ts +10 -0
  184. package/dist/utility/watchlist/import/import-request.leaf.js +10 -0
  185. package/dist/utility/wrun/sources/lanes/series.js +2 -2
  186. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +4 -4
  187. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +5 -6
  188. package/dist/utility/wrun/wrun-alert-outputs.registry.d.ts +166 -0
  189. package/dist/utility/wrun/wrun-alert-outputs.registry.js +219 -0
  190. package/dist/utility/wrun/wrun-bar-count.util.d.ts +94 -0
  191. package/dist/utility/wrun/wrun-bar-count.util.js +274 -0
  192. package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +84 -0
  193. package/dist/utility/wrun/wrun-chart-context-names.util.js +186 -0
  194. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +253 -0
  195. package/dist/utility/wrun/wrun-chart-market-facts.util.js +731 -0
  196. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.d.ts +28 -0
  197. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.js +45 -0
  198. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +18 -0
  199. package/dist/utility/wrun/wrun-coin-lane-live.util.js +47 -0
  200. package/dist/utility/wrun/wrun-deadline.util.js +2 -1
  201. package/dist/utility/wrun/wrun-debug-output.util.d.ts +39 -0
  202. package/dist/utility/wrun/wrun-debug-output.util.js +63 -0
  203. package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +113 -0
  204. package/dist/utility/wrun/wrun-declared-warmup.util.js +181 -0
  205. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +43 -0
  206. package/dist/utility/wrun/wrun-draft-legend-note.util.js +158 -0
  207. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +181 -0
  208. package/dist/utility/wrun/wrun-draft-overlay.util.js +357 -0
  209. package/dist/utility/wrun/wrun-draw-skipped.leaf.d.ts +16 -0
  210. package/dist/utility/wrun/wrun-draw-skipped.leaf.js +16 -0
  211. package/dist/utility/wrun/wrun-earnings-facts.util.d.ts +42 -0
  212. package/dist/utility/wrun/wrun-earnings-facts.util.js +131 -0
  213. package/dist/utility/wrun/wrun-first-run-depth.util.d.ts +32 -0
  214. package/dist/utility/wrun/wrun-first-run-depth.util.js +118 -0
  215. package/dist/utility/wrun/wrun-gate-plane-readers.util.d.ts +24 -0
  216. package/dist/utility/wrun/wrun-gate-plane-readers.util.js +31 -0
  217. package/dist/utility/wrun/wrun-held-lanes.util.d.ts +32 -0
  218. package/dist/utility/wrun/wrun-held-lanes.util.js +94 -0
  219. package/dist/utility/wrun/wrun-host-visible-clock.util.d.ts +2 -0
  220. package/dist/utility/wrun/wrun-host-visible-clock.util.js +17 -0
  221. package/dist/utility/wrun/wrun-host.service.d.ts +330 -0
  222. package/dist/utility/wrun/wrun-host.service.js +855 -0
  223. package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
  224. package/dist/utility/wrun/wrun-hover.util.js +25 -4
  225. package/dist/utility/wrun/wrun-inert-legend.util.d.ts +33 -0
  226. package/dist/utility/wrun/wrun-inert-legend.util.js +125 -0
  227. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +155 -0
  228. package/dist/utility/wrun/wrun-input-requirements.leaf.js +450 -0
  229. package/dist/utility/wrun/wrun-integration-route.util.d.ts +51 -0
  230. package/dist/utility/wrun/wrun-integration-route.util.js +59 -0
  231. package/dist/utility/wrun/wrun-latest-history.leaf.d.ts +8 -0
  232. package/dist/utility/wrun/wrun-latest-history.leaf.js +8 -0
  233. package/dist/utility/wrun/wrun-legend-hover.lazy.d.ts +12 -0
  234. package/dist/utility/wrun/wrun-legend-hover.lazy.js +96 -0
  235. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +21 -0
  236. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +21 -0
  237. package/dist/utility/wrun/wrun-live-hidden-hold.util.d.ts +23 -0
  238. package/dist/utility/wrun/wrun-live-hidden-hold.util.js +13 -0
  239. package/dist/utility/wrun/wrun-live-intake.util.d.ts +374 -0
  240. package/dist/utility/wrun/wrun-live-intake.util.js +2027 -0
  241. package/dist/utility/wrun/wrun-live-patch.util.d.ts +116 -0
  242. package/dist/utility/wrun/wrun-live-patch.util.js +523 -0
  243. package/dist/utility/wrun/wrun-live-tick.util.d.ts +619 -0
  244. package/dist/utility/wrun/wrun-live-tick.util.js +4974 -0
  245. package/dist/utility/wrun/wrun-loading-owner.util.d.ts +58 -0
  246. package/dist/utility/wrun/wrun-loading-owner.util.js +89 -0
  247. package/dist/utility/wrun/wrun-official-scope.leaf.d.ts +29 -0
  248. package/dist/utility/wrun/wrun-official-scope.leaf.js +36 -0
  249. package/dist/utility/wrun/wrun-oi-lane.util.d.ts +27 -0
  250. package/dist/utility/wrun/wrun-oi-lane.util.js +42 -0
  251. package/dist/utility/wrun/wrun-options-stop.util.d.ts +52 -0
  252. package/dist/utility/wrun/wrun-options-stop.util.js +123 -0
  253. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +719 -0
  254. package/dist/utility/wrun/wrun-overlay-drivers.util.js +1180 -0
  255. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +50 -0
  256. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +131 -0
  257. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +118 -0
  258. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +466 -0
  259. package/dist/utility/wrun/wrun-overlay-metadata.util.d.ts +45 -0
  260. package/dist/utility/wrun/wrun-overlay-metadata.util.js +112 -0
  261. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +114 -0
  262. package/dist/utility/wrun/wrun-overlay-recovery.util.js +971 -0
  263. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +858 -0
  264. package/dist/utility/wrun/wrun-overlay-run.util.js +11013 -0
  265. package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
  266. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +24 -9
  267. package/dist/utility/wrun/wrun-panel-mount.util.js +138 -43
  268. package/dist/utility/wrun/wrun-param-map.util.d.ts +19 -4
  269. package/dist/utility/wrun/wrun-param-map.util.js +40 -47
  270. package/dist/utility/wrun/wrun-param-values.util.d.ts +9 -3
  271. package/dist/utility/wrun/wrun-param-values.util.js +5 -5
  272. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +93 -0
  273. package/dist/utility/wrun/wrun-prefix-cohort.util.js +484 -0
  274. package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +114 -0
  275. package/dist/utility/wrun/wrun-prefix-lanes.util.js +486 -0
  276. package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +317 -0
  277. package/dist/utility/wrun/wrun-prefix-proof.util.js +630 -0
  278. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +73 -0
  279. package/dist/utility/wrun/wrun-refusal-surface.util.js +380 -0
  280. package/dist/utility/wrun/wrun-refusal-text.util.d.ts +15 -0
  281. package/dist/utility/wrun/wrun-refusal-text.util.js +40 -0
  282. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  283. package/dist/utility/wrun/wrun-replay-lane.util.d.ts +139 -0
  284. package/dist/utility/wrun/wrun-replay-lane.util.js +520 -0
  285. package/dist/utility/wrun/wrun-replay-rows.util.d.ts +21 -0
  286. package/dist/utility/wrun/wrun-replay-rows.util.js +172 -0
  287. package/dist/utility/wrun/wrun-row-source-factory.d.ts +53 -0
  288. package/dist/utility/wrun/wrun-row-source-factory.js +435 -0
  289. package/dist/utility/wrun/wrun-run-cells.util.d.ts +36 -0
  290. package/dist/utility/wrun/wrun-run-cells.util.js +46 -0
  291. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +133 -0
  292. package/dist/utility/wrun/wrun-run-interval-session.util.js +121 -0
  293. package/dist/utility/wrun/wrun-run-interval.util.d.ts +98 -0
  294. package/dist/utility/wrun/wrun-run-interval.util.js +207 -0
  295. package/dist/utility/wrun/wrun-run-retained.util.d.ts +122 -0
  296. package/dist/utility/wrun/wrun-run-retained.util.js +255 -0
  297. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +184 -0
  298. package/dist/utility/wrun/wrun-sandbox-row-source.js +444 -0
  299. package/dist/utility/wrun/wrun-script-inputs.util.js +4 -4
  300. package/dist/utility/wrun/wrun-series-stream.util.d.ts +86 -0
  301. package/dist/utility/wrun/wrun-series-stream.util.js +537 -0
  302. package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
  303. package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
  304. package/dist/utility/wrun/wrun-sheet-remembered.util.d.ts +21 -0
  305. package/dist/utility/wrun/wrun-sheet-remembered.util.js +36 -0
  306. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.d.ts +7 -0
  307. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.js +12 -0
  308. package/dist/utility/wrun/wrun-socket-row-source.js +4 -2
  309. package/dist/utility/wrun/wrun-source-rows.util.d.ts +175 -3
  310. package/dist/utility/wrun/wrun-source-rows.util.js +294 -8
  311. package/dist/utility/wrun/wrun-stats-strip.util.d.ts +46 -0
  312. package/dist/utility/wrun/wrun-stats-strip.util.js +87 -0
  313. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +163 -0
  314. package/dist/utility/wrun/wrun-table-chrome.util.js +557 -0
  315. package/dist/utility/wrun/wrun-text-params.util.d.ts +11 -6
  316. package/dist/utility/wrun/wrun-text-params.util.js +19 -30
  317. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +64 -0
  318. package/dist/utility/wrun/wrun-transient-rerun.util.js +317 -0
  319. package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +10 -0
  320. package/dist/utility/wrun/wrun-twin-lookback.util.js +43 -0
  321. package/dist/utility/wrun/wrun-warmup-head-store.util.d.ts +41 -0
  322. package/dist/utility/wrun/wrun-warmup-head-store.util.js +120 -0
  323. package/dist/utility/wrun-alert-params.leaf.d.ts +24 -0
  324. package/dist/utility/wrun-alert-params.leaf.js +24 -0
  325. package/dist/utils/replay/replay-buffer-math.d.ts +148 -0
  326. package/dist/utils/replay/replay-buffer-math.js +684 -0
  327. package/dist/workers/wrun/wrun-abi-host.d.ts +203 -0
  328. package/dist/workers/wrun/wrun-abi-host.js +1220 -0
  329. package/dist/workers/wrun/wrun-engine-handler.d.ts +20 -0
  330. package/dist/workers/wrun/wrun-engine-handler.js +380 -0
  331. package/package.json +3 -3
@@ -0,0 +1,1220 @@
1
+ /**
2
+ * The WRUN ABI executor: instantiates a `wrun-indicator` wasm module with the
3
+ * version-specific import object (wrun-1 scalar channel; wrun-2 adds the cell
4
+ * and string channels; wrun-3 adds the handle-keyed draw channel and the
5
+ * last-bar signal; wrun-4 adds run-level frame snapshots) and drives it bar
6
+ * by bar over a packed request.
7
+ *
8
+ * This is a faithful browser port of the om daemon's worker host
9
+ * (openmarket packages/cli/src/runner/wrun/runtime-worker.js), kept
10
+ * environment-agnostic on purpose: it runs inside `wrun-engine.worker.ts` in
11
+ * the app and directly under Node in the ABI drive specs, so the same
12
+ * behavior is what both the tests and the chart exercise.
13
+ *
14
+ * Contract highlights (docs/WRUN2_ABI.md and docs/WRUN3_ABI.md in the
15
+ * openmarket repo):
16
+ * - Four exports: init/state/finalize/reset; positional argument blocks
17
+ * served through `wrun.wrun_arg_*`; outputs through `wrun_output_f64` +
18
+ * `wrun_result_write`.
19
+ * - Cell channel (`wrun_arg_len`/`wrun_arg_bytes`) is state-phase only,
20
+ * wrun-2 and later, and copies IEEE 754 f64 cells into exported memory.
21
+ * - String channel (`wrun_output_str`) is finalize-phase only, wrun-2 and
22
+ * later, declared slots only, fatal UTF-8 validation, caps checked before
23
+ * any copy, never truncated.
24
+ * - Frame channel (`wrun_output_frame`, wrun-4 and later): finalize-phase
25
+ * only, declared slots only, fatal UTF-8 validation. A later write replaces
26
+ * the slot for the run, sharing the string channel's render-result cap.
27
+ * - Text channel (`wrun_param_len` / `wrun_param_bytes`, wrun-5 and later,
28
+ * docs/WRUN5_ABI.md): init-phase only, the cell channel's shape on params.
29
+ * The host holds every typed text setting's plain UTF-8 bytes by init slot
30
+ * (`textParams`); a slot without one answers -1 on both imports (the
31
+ * generated reader reads the declared default), an empty value answers 0
32
+ * (the reader reads ""), and the copy into
33
+ * exported memory is bounds-checked. Refusals by name:
34
+ * `wrun_text_param_phase` outside init(), `wrun_text_param_memory` for a
35
+ * copy outside the module's memory. An older ABI refuses the two imports
36
+ * by name before anything links.
37
+ * - Row count (`wrun_bar_count`, wrun-6 and later, docs/WRUN6_ABI.md): the
38
+ * bars the run holds while the row is evaluated, the forming bar included,
39
+ * callable in state() and finalize() (`wrun_bar_count_phase` otherwise).
40
+ * Every row of a block reads the bars the session holds once the block is
41
+ * in: a full run's row count, a live seed's, and on a same-bar revision the
42
+ * count already held. A NEW bar would make every held bar's count stale, so
43
+ * the session never extends a module that reads it: the main thread reopens
44
+ * it over every bar (the engine's re-seed), and a block that would extend it
45
+ * refuses by name. An older ABI refuses the import by name before anything
46
+ * links.
47
+ * - Draw channel (`wrun_draw_*`, wrun-3 and later): finalize-phase only, every
48
+ * call one op against the session's handle ledger
49
+ * (`utility/wrun/wrun-handles.util.ts`); caps and refusals by name.
50
+ * `wrun_bar_last` (state and finalize) answers 1 on the newest bar the
51
+ * request holds.
52
+ * - Strategy channel (`wrun_strategy_*`, wrun-3 and later, contract
53
+ * OM-WRUN3-STRATEGIES-CONTRACT sections 2 and 5): a package whose sheet
54
+ * declares `strategy` runs the engine's own broker beside the guest
55
+ * (the shared host package's broker, read through the realm's chart-host env, `sharedHost()`, and
56
+ * driven by its `WrunStrategyHost`). Per row, `broker.beginBar` runs BEFORE the guest's
57
+ * state() (fills for orders queued on earlier rows, equity marked at the
58
+ * close), the getters read the post-fill position during state() and
59
+ * finalize(), and the intents queue during finalize() with createdBar =
60
+ * the row. A full run confirms every bar, the newest included (the
61
+ * engine's own full-run rule); on the live lane the newest bar the
62
+ * request holds (the forming bar) runs on a structured clone of the
63
+ * committed broker (no fills, intents rejected and counted), a same-bar
64
+ * replay re-clones, and a bar close folds the closed bar into the
65
+ * committed broker (the close-confirm) before the new forming bar, so a
66
+ * live session equals a full run over its closed bars plus the forming
67
+ * bar's mark. The OHLC feed rides the block (`strategyBars`, the
68
+ * primary lane's own candles); the wire is the engine's StrategyOutput.
69
+ * A module importing a strategy import with no `strategy` sheet refuses
70
+ * at instantiation by name (`wrun_strategy_not_declared`).
71
+ * - No memory growth after init(); the 4 MiB memory ceiling holds throughout.
72
+ * - Live mode replays a revised forming bar by snapshot/restore of linear
73
+ * memory plus the exported `__wrun_g*` globals AND the ledger journal; a
74
+ * live block that opens past the forming bar close-confirms it first
75
+ * (re-evaluates it as a closed bar), so a live session's ledger equals a
76
+ * full run's.
77
+ *
78
+ * Two entry points share one executor:
79
+ * - `runWrunPackedRequest` drives a whole request against a fresh instance
80
+ * (the historical mount/pan compute pass), exactly as before.
81
+ * - `createWrunAbiSession` keeps the instantiated guest ALIVE between calls
82
+ * so a live forming-bar tick feeds only the new/revised rows: the session
83
+ * carries the guest's memory, the forming-bar snapshot, the ledger, and
84
+ * the string accounting and frame slots across calls, and history is
85
+ * never re-executed per tick.
86
+ */
87
+ import { wrunChartHostEnv } from '../../host-env.js';
88
+ import { abiAtLeast, WrunLiveOrderError, } from '../../interfaces/wrun-runtime.interface.js';
89
+ import { WRUN3_DRAW_REFUSALS, WrunDrawRefusalError, WrunHandleLedger, } from '../../utility/wrun/wrun-handles.util.js';
90
+ import { WRUN_RENDER_RESULT_LIMIT_BYTES } from '../../utility/wrun/wrun-render-select.util.js';
91
+ import { WRUN5_TEXT_IMPORTS, WRUN5_TEXT_REFUSALS, wrunPlainText } from '../../utility/wrun/wrun-text-params.util.js';
92
+ import { WRUN6_BAR_REFUSALS, wrunImportsBarCount } from '../../utility/wrun/wrun-bar-count.util.js';
93
+ import { WRUN_MEMORY_LIMIT_BYTES } from '../../utility/wrun/wrun-memory-clamp.util.js';
94
+ import { wrunRunCellsRefusal } from '../../utility/wrun/wrun-run-cells.util.js';
95
+ const WRUN_GLOBAL_PREFIX = '__wrun_g';
96
+ /** `strategyBars` stride: open, high, low, close per row. */
97
+ const STRATEGY_BAR_STRIDE = 4;
98
+ const STRATEGY_IMPORT_PREFIX = 'wrun_strategy_';
99
+ /** The memory ceiling: the clamp's own limit, which the engine worker's load (wrun-engine-handler.ts
100
+ * compileWrunModuleBytes) also stamps on every module as its memory maximum (wrun-memory-clamp.util), so the two can
101
+ * never drift. */
102
+ const WRUN_DEFAULT_MEMORY_LIMIT_BYTES = WRUN_MEMORY_LIMIT_BYTES;
103
+ const BYTES_PER_CELL = 8;
104
+ const BYTES_PER_POINT = 16;
105
+ const EMPTY_ARGS = [];
106
+ const EMPTY_SLOT_CAPS = new Int32Array(0);
107
+ const EMPTY_TEXT_PARAMS = {};
108
+ /** The text channel's import names without their `wrun:` module prefix. */
109
+ const TEXT_IMPORT_NAMES = new Set(WRUN5_TEXT_IMPORTS.map((key) => key.slice('wrun:'.length)));
110
+ // Fatal on purpose: wrun_output_str carries UTF-8 text only, validated at
111
+ // write time so an invalid byte refuses HERE by name instead of surfacing as
112
+ // replacement characters wherever the string is finally rendered.
113
+ const UTF8_FATAL = new TextDecoder('utf-8', { fatal: true });
114
+ const UTF8_ENCODER = new TextEncoder();
115
+ /** The string-slot bytes a module wrote, with the plain-text rule applied
116
+ * (newlines kept): the bytes themselves when nothing was stripped, else the
117
+ * clean text re-encoded (never longer than the write the caps admitted). */
118
+ function plainSlotBytes(bytes, text) {
119
+ const plain = wrunPlainText(text, { multiline: true });
120
+ return plain === text ? bytes : UTF8_ENCODER.encode(plain);
121
+ }
122
+ /** The row stamps restart past this value, so a stamp always stays a small
123
+ * integer (V8's Smi range); a session reaches it after a billion rows. */
124
+ const MAX_ROW_STAMP = 0x3fff_ffff;
125
+ /** The typed pre-evaluation ordering refusal lives with the wire types (the
126
+ * main-thread host rejects the coded response with the same class); kept
127
+ * exported here for the worker and the ABI drive specs. */
128
+ export { WrunLiveOrderError };
129
+ const now = () => (typeof performance !== 'undefined' ? performance.now() : Date.now());
130
+ const importListByModule = new WeakMap();
131
+ /** A compiled module's imports as the shared readers take them (`WrunModuleImport`, in
132
+ * WebAssembly.Module.imports() order), listed once per module and frozen: the engine worker's load answers this list
133
+ * on the module's handle, and every session of the module reads its import checks off the same list (the shared
134
+ * predicates of wrun-bar-count.util among them), so the main thread's handle and the worker's module answer alike. */
135
+ export function wrunModuleImportList(module) {
136
+ let list = importListByModule.get(module);
137
+ if (list === undefined) {
138
+ list = Object.freeze(WebAssembly.Module.imports(module).map(({ module: from, name }) => Object.freeze({ module: from, name })));
139
+ importListByModule.set(module, list);
140
+ }
141
+ return list;
142
+ }
143
+ /** A wrun-3 module whose sheet declares no `strategy` section must import
144
+ * no strategy import: refused at instantiation by name, the same rule as a
145
+ * draw call for a kind absent from `handles`, before anything links. */
146
+ function refuseUndeclaredStrategyImports(module) {
147
+ const names = wrunModuleImportList(module)
148
+ .filter((entry) => entry.module === 'wrun' && entry.name.startsWith(STRATEGY_IMPORT_PREFIX))
149
+ .map((entry) => entry.name);
150
+ if (names.length === 0)
151
+ return;
152
+ const { WrunStrategyRefusalError } = wrunChartHostEnv().sharedHost();
153
+ throw new WrunStrategyRefusalError('wrun_strategy_not_declared', `${names.join(', ')}: this package declares no strategy section`, `declare metadata strategy (an empty object enables the channel with the engine's defaults) under abi_version "wrun-3"`);
154
+ }
155
+ /** One row's OHLC out of the block's broker feed; a strategy package's
156
+ * block without one is a host bug, refused loudly rather than run as a
157
+ * NaN bar (which the broker would count as rejections). */
158
+ function strategyBarOf(block, row) {
159
+ const bars = block.strategyBars;
160
+ const at = row * STRATEGY_BAR_STRIDE;
161
+ if (bars === undefined || bars.length < at + STRATEGY_BAR_STRIDE) {
162
+ throw new Error(`WRUN strategy feed missing for row ${row}: a strategy package's rows block carries strategyBars ` +
163
+ `(open, high, low, close per row, the primary lane's own candles)`);
164
+ }
165
+ return { open: bars[at], high: bars[at + 1], low: bars[at + 2], close: bars[at + 3] };
166
+ }
167
+ export async function createWrunAbiSession(config) {
168
+ // The runtime caps are the kit's (om's one caps table, WRUN_CAPS), restated in the shared host's
169
+ // WRUN_HOST_ABI_TABLES and read here, as the session opens, through the realm's chart-host env (never at module
170
+ // load; both entries, `runWrunPackedRequest` and the worker's live start, open a session); never a number typed
171
+ // here, so a kit bump that moves a cap moves the executor with it. wrun-abi-host.kit-mirror.spec.ts holds each to
172
+ // its WRUN_CAPS row (docs/features/kscript/wrun/wrun-limits.md).
173
+ // The string caps are host-enforced per write with checked arithmetic BEFORE any
174
+ // allocation: per-slot max_bytes rides the request (schema-capped at 4096),
175
+ // these bound a row and a run, om's runtime-worker caps: every ABI keeps the
176
+ // string-only run limit, and wrun-4 shares one transport budget across its
177
+ // retained frames and row strings (WRUN_CAPS.frame_run_bytes).
178
+ // A live SESSION is one run for the caps:
179
+ // the total accumulates across its ticks, so a slot-writing package cannot
180
+ // stream unbounded text through an immortal session.
181
+ const sharedHost = wrunChartHostEnv().sharedHost();
182
+ const {
183
+ // Declared outputs one row may write (WRUN_CAPS.output_slots).
184
+ maxOutputWrites: MAX_OUTPUT_WRITES, stringRowLimitBytes: STRING_ROW_LIMIT_BYTES, stringRunLimitBytes: STRING_RUN_LIMIT_BYTES, frameRunLimitBytes: FRAME_RUN_LIMIT_BYTES, maxFrames: MAX_FRAME_SLOTS, } = sharedHost.WRUN_HOST_ABI_TABLES;
185
+ const memoryLimit = config.memoryLimitBytes ?? WRUN_DEFAULT_MEMORY_LIMIT_BYTES;
186
+ const outputCount = config.outputCount;
187
+ const stringMaxBytes = config.stringMaxBytes ?? EMPTY_SLOT_CAPS;
188
+ const stringSlotCount = stringMaxBytes.length;
189
+ const frameMaxBytes = config.frameMaxBytes ?? EMPTY_SLOT_CAPS;
190
+ const frameSlotCount = frameMaxBytes.length;
191
+ // wrun-4 shares one transport budget across frames and row strings
192
+ // (FRAME_RUN_LIMIT_BYTES); earlier ABIs keep the string-only run limit.
193
+ const wrun4 = abiAtLeast(config.abi, 'wrun-4');
194
+ // Frames can own every visual in a wrun-4 program, so that program has
195
+ // no numeric output columns. Earlier ABIs still require a numeric output.
196
+ const frameOnly = wrun4 && frameSlotCount > 0 && outputCount === 0;
197
+ if (!Number.isInteger(outputCount) || (outputCount < 1 && !frameOnly)) {
198
+ throw new Error('WRUN output count must be a positive integer');
199
+ }
200
+ if (frameSlotCount > MAX_FRAME_SLOTS) {
201
+ throw new Error(`WRUN frames declares ${frameSlotCount} slots; the maximum is ${MAX_FRAME_SLOTS}`);
202
+ }
203
+ if (!abiAtLeast(config.abi, 'wrun-4')) {
204
+ const importsFrame = wrunModuleImportList(config.module).some((entry) => entry.module === 'wrun' && entry.name === 'wrun_output_frame');
205
+ if (importsFrame) {
206
+ throw new Error(`WRUN wrun_output_frame requires abi_version "wrun-4" or later (declared "${config.abi}")`);
207
+ }
208
+ }
209
+ // Every older ABI refuses the text channel by name (docs/WRUN5_ABI.md): a
210
+ // module compiled from a param.text declaration never links under a host
211
+ // or a sheet that has not reached wrun-5.
212
+ if (!abiAtLeast(config.abi, 'wrun-5')) {
213
+ const textImports = wrunModuleImportList(config.module)
214
+ .filter((entry) => entry.module === 'wrun' && TEXT_IMPORT_NAMES.has(entry.name))
215
+ .map((entry) => entry.name);
216
+ if (textImports.length > 0) {
217
+ throw new Error(`WRUN ${textImports.join(', ')}: the text channel requires abi_version "wrun-5" or later ` +
218
+ `(declared "${config.abi}"); a param.text declaration derives it`);
219
+ }
220
+ }
221
+ // The row count is wrun-6's (docs/WRUN6_ABI.md): an older ABI refuses the
222
+ // import by name before anything links, the om hosts' way-in hint.
223
+ const importsBarCount = wrunImportsBarCount(wrunModuleImportList(config.module));
224
+ if (importsBarCount && !abiAtLeast(config.abi, 'wrun-6')) {
225
+ throw new Error(`WRUN wrun_bar_count: the row count requires abi_version "wrun-6" or later ` +
226
+ `(declared "${config.abi}"); a bar.count() call derives it`);
227
+ }
228
+ const readsBarCount = importsBarCount && abiAtLeast(config.abi, 'wrun-6');
229
+ // A write at or past MAX_OUTPUT_WRITES refuses, so no output beyond it is
230
+ // ever tracked (a larger declared count fails validation on its first row).
231
+ const trackedOutputs = Math.min(outputCount, MAX_OUTPUT_WRITES);
232
+ // Guest-call context. `phase` sequences the request: "instantiate" (module
233
+ // compile + start section) -> "init" -> per row "state" then "finalize" ->
234
+ // "idle" between calls. The cell imports are legal during "state" only and
235
+ // the string import during "finalize" only; each names the offending phase
236
+ // otherwise, so a start-section or init-time call fails safely by name.
237
+ // `packedRow` >= 0 means the argument block is that row of the CURRENT
238
+ // packed rows block; -1 means `args` (init params, or empty for finalize).
239
+ const host = {
240
+ phase: 'instantiate',
241
+ args: EMPTY_ARGS,
242
+ packedRow: -1,
243
+ outputs: new Float64Array(trackedOutputs),
244
+ writtenAt: new Uint32Array(trackedOutputs),
245
+ rowStamp: 0,
246
+ writtenCount: 0,
247
+ count: 0,
248
+ ready: false,
249
+ stringWrites: new Array(stringSlotCount).fill(null),
250
+ rowStringBytes: 0,
251
+ rowIndex: 0,
252
+ barLast: 0,
253
+ barCount: 0,
254
+ };
255
+ // The rows block the import closures currently serve from. Reassigned per
256
+ // runRows call; the phase guards make any host import call outside a
257
+ // running block fail by name before this is read.
258
+ let current = null;
259
+ // Input index -> column in the current block's cell tables (cellLens/
260
+ // cellOffsets are row-major over these columns, in cellIndexes order).
261
+ let cellColumns = new Map();
262
+ let cellColumnCount = 0;
263
+ // The instance is assigned only after WebAssembly.instantiate resolves; a
264
+ // start-section call into the cell channel therefore CANNOT reach exported
265
+ // memory (the phase guard fires first, and this ref is still null).
266
+ const instanceRef = { exports: null };
267
+ const floatArg = (index) => {
268
+ if (host.packedRow >= 0 && current) {
269
+ // Absent-slot semantics stay bit-identical to the object transport: a
270
+ // slot at or beyond the row's ORIGINAL argument count is absent (NaN
271
+ // here, 0 through the int accessors), even though the packed stride is
272
+ // padded to the widest row.
273
+ if (!Number.isInteger(index) || index < 0 || index >= current.argCounts[host.packedRow]) {
274
+ return Number.NaN;
275
+ }
276
+ return current.values[host.packedRow * current.stride + index];
277
+ }
278
+ const value = host.args[index];
279
+ return value === undefined ? Number.NaN : value;
280
+ };
281
+ const intArg = (index) => {
282
+ const value = floatArg(index);
283
+ return Number.isFinite(value) ? Math.trunc(value) : 0;
284
+ };
285
+ const requireCellColumn = (name, index) => {
286
+ if (host.phase !== 'state') {
287
+ throw new Error(`WRUN ${name} is callable during state() only (called during ${host.phase}); ` +
288
+ `read cell blocks inside state() and carry what finalize() needs in module state`);
289
+ }
290
+ const column = cellColumns.get(index);
291
+ if (column === undefined) {
292
+ const declared = [...cellColumns.keys()].join(', ');
293
+ throw new Error(`WRUN ${name}(${index}): input ${index} is not declared cellType "array" in metadata` +
294
+ (declared === '' ? ' (no inputs are)' : ` (declared cell inputs: ${declared})`));
295
+ }
296
+ return host.packedRow * cellColumnCount + column;
297
+ };
298
+ const importObject = {
299
+ env: {
300
+ // The guest's trap: a `throw`, a std-lib check (`~lib/array.ts` bounds), or the
301
+ // author's own abort(). asc passes the message and the source path as AssemblyScript
302
+ // strings in the guest's memory (null pointers when it has none: an explicit abort()
303
+ // carries no file and 0:0), so the error names them; the editor's Problems lane
304
+ // anchors the row on the buffer only when the path is src/indicator.ts
305
+ // (utility/scriptEditor/runtime-diagnostics.util.ts). Reads only: nothing here
306
+ // touches the memory ceiling or the no-growth rule.
307
+ abort(message, fileName, line, column) {
308
+ const memory = exportedMemory(instanceRef.exports);
309
+ throw new Error(formatAssemblyScriptAbort(readAssemblyScriptString(memory, message), readAssemblyScriptString(memory, fileName), line, column));
310
+ },
311
+ },
312
+ wrun: {
313
+ wrun_arg_count() {
314
+ return host.packedRow >= 0 && current ? current.argCounts[host.packedRow] : host.args.length;
315
+ },
316
+ wrun_arg_i32(index) {
317
+ return intArg(index);
318
+ },
319
+ wrun_arg_i64(index) {
320
+ return BigInt(intArg(index));
321
+ },
322
+ wrun_arg_f32(index) {
323
+ return floatArg(index);
324
+ },
325
+ wrun_arg_f64(index) {
326
+ return floatArg(index);
327
+ },
328
+ wrun_output_f64(index, value) {
329
+ if (!Number.isInteger(index) || index < 0 || index >= MAX_OUTPUT_WRITES) {
330
+ throw new Error(`WRUN output index ${index} out of bounds for ${MAX_OUTPUT_WRITES} tracked outputs`);
331
+ }
332
+ if (value === Infinity || value === -Infinity) {
333
+ throw new Error(`WRUN output ${index} is ${value}; guard the calculation and emit NaN when the value is undefined`);
334
+ }
335
+ // A write past the declared outputs (inside the tracked range) is
336
+ // legal and read by nothing, so only declared indexes are kept.
337
+ if (index < trackedOutputs) {
338
+ host.outputs[index] = value;
339
+ if (host.writtenAt[index] !== host.rowStamp) {
340
+ host.writtenAt[index] = host.rowStamp;
341
+ host.writtenCount += 1;
342
+ }
343
+ }
344
+ },
345
+ wrun_result_write(count) {
346
+ if (!Number.isInteger(count) || count < 0 || count > MAX_OUTPUT_WRITES) {
347
+ throw new Error(`WRUN output count ${count} out of bounds for ${MAX_OUTPUT_WRITES} tracked outputs`);
348
+ }
349
+ host.count = count;
350
+ host.ready = true;
351
+ },
352
+ },
353
+ };
354
+ // Run-level string accounting: the sum of every COMMITTED row's final byte
355
+ // total plus the in-flight row's, checked on every write so the run cap
356
+ // refuses at the offending write, never after megabytes of transport.
357
+ // Persists across a session's runRows calls (a session is one run).
358
+ let runStringBytes = 0;
359
+ // Frames retain only the latest write per slot across the whole run. They
360
+ // do not participate in the per-row reset or the forming-bar rollback.
361
+ const frameWrites = new Array(frameSlotCount).fill(undefined);
362
+ let runFrameBytes = 0;
363
+ // The import object is VERSION-SPECIFIC: a wrun-1 instantiation never
364
+ // carries the cell channel or the string channel, and wrun-3 and later
365
+ // instantiations link the draw channel, so even a module that slipped past
366
+ // validation fails to link rather than reaching a later ABI's behavior.
367
+ if (abiAtLeast(config.abi, 'wrun-2')) {
368
+ importObject.wrun.wrun_arg_len = (index) => {
369
+ const at = requireCellColumn('wrun_arg_len', index);
370
+ // The phase guard inside requireCellColumn proves a block is running.
371
+ const block = current;
372
+ // -1 = the bar carries no block for this input; 0 = a zero-cell bar.
373
+ return block.cellLens[at];
374
+ };
375
+ importObject.wrun.wrun_arg_bytes = (index, ptr) => {
376
+ const at = requireCellColumn('wrun_arg_bytes', index);
377
+ const block = current;
378
+ const len = block.cellLens[at];
379
+ if (len < 0)
380
+ return -1;
381
+ if (len === 0)
382
+ return 0;
383
+ const memory = exportedMemory(instanceRef.exports);
384
+ if (!memory) {
385
+ throw new Error('WRUN wrun_arg_bytes: module exports no memory for the host to copy cells into');
386
+ }
387
+ const byteLength = len * BYTES_PER_CELL;
388
+ if (!Number.isInteger(ptr) || ptr < 0 || ptr + byteLength > memory.buffer.byteLength) {
389
+ throw new Error(`WRUN wrun_arg_bytes(${index}, ${ptr}): ${byteLength} bytes do not fit the module's ` +
390
+ `exported memory of ${memory.buffer.byteLength} bytes; reserve max_cells * ${BYTES_PER_CELL} ` +
391
+ `bytes per celled input and pass a pointer inside that buffer`);
392
+ }
393
+ new Uint8Array(memory.buffer, ptr, byteLength).set(new Uint8Array(block.cells.buffer, block.cells.byteOffset + block.cellOffsets[at] * BYTES_PER_CELL, byteLength));
394
+ return byteLength;
395
+ };
396
+ // The wrun-2 string channel: one import, callable during finalize() only,
397
+ // writing UTF-8 bytes from exported memory into a DECLARED string slot.
398
+ // Caps are enforced with checked arithmetic BEFORE the bytes are copied.
399
+ // A slot never written this row is ABSENT (length -1 in the packed
400
+ // table), distinct from a present empty write.
401
+ importObject.wrun.wrun_output_str = (slot, ptr, len) => {
402
+ if (host.phase !== 'finalize') {
403
+ throw new Error(`WRUN wrun_output_str is callable during finalize() only (called during ${host.phase}); ` +
404
+ `compute per-bar values in state(), carry them in module state, and write each string ` +
405
+ `slot beside the numeric outputs in finalize()`);
406
+ }
407
+ if (stringSlotCount === 0) {
408
+ throw new Error(`WRUN wrun_output_str(${slot}, ...): this run declares no string slots ` +
409
+ `(declare metadata string_slots under abi_version "wrun-2")`);
410
+ }
411
+ if (!Number.isInteger(slot) || slot < 0 || slot >= stringSlotCount) {
412
+ throw new Error(`WRUN wrun_output_str(${slot}, ...): string slot ${slot} is not declared ` +
413
+ `(declared slots: 0..${stringSlotCount - 1})`);
414
+ }
415
+ if (!Number.isInteger(len) || len < 0) {
416
+ throw new Error(`WRUN wrun_output_str(${slot}, ...): length ${len} must be a nonnegative integer`);
417
+ }
418
+ const cap = stringMaxBytes[slot];
419
+ if (len > cap) {
420
+ throw new Error(`WRUN string slot ${slot} write of ${len} bytes exceeds the slot's max_bytes ${cap}; ` +
421
+ `strings are never truncated; shorten the text or raise max_bytes in metadata.string_slots`);
422
+ }
423
+ const previous = host.stringWrites[slot];
424
+ const rowTotal = host.rowStringBytes - (previous ? previous.byteLength : 0) + len;
425
+ if (rowTotal > STRING_ROW_LIMIT_BYTES) {
426
+ throw new Error(`WRUN string writes for one row total ${rowTotal} bytes, over the per-row limit ` +
427
+ `${STRING_ROW_LIMIT_BYTES}; emit less text per bar`);
428
+ }
429
+ if (runStringBytes + rowTotal > STRING_RUN_LIMIT_BYTES) {
430
+ throw new Error(`WRUN string writes for this run total ${runStringBytes + rowTotal} bytes, over the ` +
431
+ `per-run limit ${STRING_RUN_LIMIT_BYTES}; emit less text or fewer rows`);
432
+ }
433
+ const runTotal = runStringBytes + rowTotal + runFrameBytes;
434
+ if (wrun4 && runTotal > FRAME_RUN_LIMIT_BYTES) {
435
+ throw new Error(`WRUN string and frame writes for this run total ${runTotal} bytes, over the ` +
436
+ `per-run limit ${FRAME_RUN_LIMIT_BYTES}; emit less text or fewer rows`);
437
+ }
438
+ const memory = exportedMemory(instanceRef.exports);
439
+ if (!memory) {
440
+ throw new Error('WRUN wrun_output_str: module exports no memory for the host to read the string from');
441
+ }
442
+ if (!Number.isInteger(ptr) || ptr < 0 || ptr + len > memory.buffer.byteLength) {
443
+ throw new Error(`WRUN wrun_output_str(${slot}, ${ptr}): ${len} bytes do not fit the module's exported ` +
444
+ `memory of ${memory.buffer.byteLength} bytes; pass a pointer to the encoded UTF-8 ` +
445
+ `inside exported memory`);
446
+ }
447
+ const bytes = new Uint8Array(len);
448
+ bytes.set(new Uint8Array(memory.buffer, ptr, len));
449
+ let text;
450
+ try {
451
+ text = UTF8_FATAL.decode(bytes);
452
+ }
453
+ catch {
454
+ throw new Error(`WRUN string slot ${slot} write of ${len} bytes is not valid UTF-8; wrun_output_str ` +
455
+ `carries UTF-8 text only (encode before writing)`);
456
+ }
457
+ // The no-disguises rule at the slot boundary (guard G2, every host): the
458
+ // bidi controls, zero-width and control characters a module wrote never
459
+ // reach a reader (the packed string table, a label handle's text), newlines
460
+ // kept. The caps above were judged on the bytes as written; the clean bytes
461
+ // are never longer.
462
+ host.stringWrites[slot] = plainSlotBytes(bytes, text);
463
+ host.rowStringBytes = rowTotal;
464
+ };
465
+ }
466
+ // The wrun-5 text channel: the cell channel's shape on params, callable
467
+ // during init() only (the generated pt_<name>() readers run there). The
468
+ // host hands over plain text already within the param's max_bytes
469
+ // (wrun-text-params.util); a slot the request holds no bytes for is not a
470
+ // text param and answers -1, so the reader reads the declared default and
471
+ // refuses nothing.
472
+ if (abiAtLeast(config.abi, 'wrun-5')) {
473
+ const textParams = config.textParams ?? EMPTY_TEXT_PARAMS;
474
+ const textBytesAt = (name, index) => {
475
+ if (host.phase !== 'init') {
476
+ throw new Error(`WRUN ${name} (${WRUN5_TEXT_REFUSALS.phase}): a text setting is readable during init() only ` +
477
+ `(called during ${host.phase}); read it in init() / onStart() and carry it in module state`);
478
+ }
479
+ return Number.isInteger(index) && index >= 0 ? textParams[index] : undefined;
480
+ };
481
+ importObject.wrun.wrun_param_len = (index) => {
482
+ const bytes = textBytesAt('wrun_param_len', index);
483
+ return bytes === undefined ? -1 : bytes.byteLength;
484
+ };
485
+ importObject.wrun.wrun_param_bytes = (index, ptr) => {
486
+ const bytes = textBytesAt('wrun_param_bytes', index);
487
+ if (bytes === undefined)
488
+ return -1;
489
+ const len = bytes.byteLength;
490
+ if (len === 0)
491
+ return 0;
492
+ const memory = exportedMemory(instanceRef.exports);
493
+ if (!memory) {
494
+ throw new Error(`WRUN wrun_param_bytes (${WRUN5_TEXT_REFUSALS.memory}): module exports no memory for the host to copy ` +
495
+ `the text setting into`);
496
+ }
497
+ if (!Number.isInteger(ptr) || ptr < 0 || ptr + len > memory.buffer.byteLength) {
498
+ throw new Error(`WRUN wrun_param_bytes(${index}, ${ptr}) (${WRUN5_TEXT_REFUSALS.memory}): ${len} bytes do not fit the ` +
499
+ `module's exported memory of ${memory.buffer.byteLength} bytes; pass a pointer to a buffer of ` +
500
+ `wrun_param_len(${index}) bytes inside exported memory`);
501
+ }
502
+ new Uint8Array(memory.buffer, ptr, len).set(bytes);
503
+ return len;
504
+ };
505
+ }
506
+ // The wrun-6 row count: the bars the session holds while the row is
507
+ // evaluated, the forming bar included (runRows sets it per block).
508
+ // Callable during state() and finalize() only.
509
+ if (abiAtLeast(config.abi, 'wrun-6')) {
510
+ importObject.wrun.wrun_bar_count = () => {
511
+ if (host.phase !== 'state' && host.phase !== 'finalize') {
512
+ throw new Error(`WRUN wrun_bar_count (${WRUN6_BAR_REFUSALS.phase}): wrun_bar_count is callable during state() and ` +
513
+ `finalize() only (called during ${host.phase}); read the row count per bar, never at init`);
514
+ }
515
+ return host.barCount;
516
+ };
517
+ }
518
+ if (abiAtLeast(config.abi, 'wrun-4')) {
519
+ importObject.wrun.wrun_output_frame = (slot, ptr, len) => {
520
+ if (host.phase !== 'finalize') {
521
+ throw new Error(`WRUN wrun_output_frame is callable during finalize() only (called during ${host.phase}); ` +
522
+ `compute per-bar values in state(), carry them in module state, and write each frame ` +
523
+ `slot beside the numeric outputs in finalize()`);
524
+ }
525
+ if (frameSlotCount === 0) {
526
+ throw new Error(`WRUN wrun_output_frame(${slot}, ...): this run declares no frame slots ` +
527
+ `(declare metadata frames under abi_version "wrun-4")`);
528
+ }
529
+ if (!Number.isInteger(slot) || slot < 0 || slot >= frameSlotCount) {
530
+ throw new Error(`WRUN wrun_output_frame(${slot}, ...): frame slot ${slot} is not declared ` +
531
+ `(declared slots: 0..${frameSlotCount - 1})`);
532
+ }
533
+ if (!Number.isInteger(len) || len < 0) {
534
+ throw new Error(`WRUN wrun_output_frame(${slot}, ...): length ${len} must be a nonnegative integer`);
535
+ }
536
+ const cap = frameMaxBytes[slot];
537
+ if (len > cap) {
538
+ throw new Error(`WRUN frame slot ${slot} write of ${len} bytes exceeds the slot's max_bytes ${cap}; ` +
539
+ `frames are never truncated; shorten the frame or raise max_bytes in metadata.frames`);
540
+ }
541
+ const nextFrameBytes = runFrameBytes - (frameWrites[slot]?.byteLength ?? 0) + len;
542
+ const runTotal = runStringBytes + host.rowStringBytes + nextFrameBytes;
543
+ if (runTotal > FRAME_RUN_LIMIT_BYTES) {
544
+ throw new Error(`WRUN frame and string writes for this run total ${runTotal} bytes, over the ` +
545
+ `per-run limit ${FRAME_RUN_LIMIT_BYTES}; emit smaller frames or less text`);
546
+ }
547
+ const memory = exportedMemory(instanceRef.exports);
548
+ if (!memory) {
549
+ throw new Error('WRUN wrun_output_frame: module exports no memory for the host to read the frame from');
550
+ }
551
+ if (!Number.isInteger(ptr) || ptr < 0 || ptr + len > memory.buffer.byteLength) {
552
+ throw new Error(`WRUN wrun_output_frame(${slot}, ${ptr}): ${len} bytes do not fit the module's exported ` +
553
+ `memory of ${memory.buffer.byteLength} bytes; pass a pointer to the encoded UTF-8 ` +
554
+ `inside exported memory`);
555
+ }
556
+ const bytes = new Uint8Array(len);
557
+ bytes.set(new Uint8Array(memory.buffer, ptr, len));
558
+ try {
559
+ UTF8_FATAL.decode(bytes);
560
+ }
561
+ catch {
562
+ throw new Error(`WRUN frame slot ${slot} write of ${len} bytes is not valid UTF-8; wrun_output_frame ` +
563
+ `carries UTF-8 text only (encode before writing)`);
564
+ }
565
+ // A frame is JSON, kept byte for byte (its byte accounting is the
566
+ // channel's contract); the no-disguises rule applies where the frame is
567
+ // parsed (wrun-frame-host.ts), after the JSON decode, which catches an
568
+ // escaped character beside a raw one.
569
+ frameWrites[slot] = bytes;
570
+ runFrameBytes = nextFrameBytes;
571
+ };
572
+ }
573
+ // The wrun-3 draw channel: seven finalize-only ops against the session's
574
+ // handle ledger plus the last-bar signal. The ledger owns the op rules,
575
+ // caps, the skip-or-refuse verdict of every code and its precedence
576
+ // (utility/wrun/wrun-handles.util.ts); the host owns what needs the guest:
577
+ // the phase, the row index and time, the row's string slots, and a
578
+ // polyline's points in exported memory.
579
+ const ledger = abiAtLeast(config.abi, 'wrun-3') ? new WrunHandleLedger(config.handleDefaults) : null;
580
+ if (ledger) {
581
+ const requireDrawPhase = (name) => {
582
+ if (host.phase !== 'finalize') {
583
+ throw new WrunDrawRefusalError(WRUN3_DRAW_REFUSALS.phase, `${name} is callable during finalize() only (called during ${host.phase}); compute in state(), ` +
584
+ `carry what the drawing needs in module state, and draw beside the outputs in finalize()`, { call: name });
585
+ }
586
+ };
587
+ // The row's string slots as a label or a slot prop reads them: a slot's
588
+ // text is its bytes as written on THIS row at the time of the call (the
589
+ // ledger copies them into the handle), null while it is not written yet
590
+ // this row (absent), "" for a present empty write. The ledger judges an
591
+ // undeclared slot (refused) and an unwritten one (skipped) in the
592
+ // contract's order; slot -1 (a mark, DW29) reads nothing.
593
+ const rowSlots = {
594
+ count: stringSlotCount,
595
+ text: (slot) => {
596
+ const bytes = host.stringWrites[slot];
597
+ return bytes === null || bytes === undefined ? null : UTF8_FATAL.decode(bytes);
598
+ },
599
+ };
600
+ // `count` points, each two little-endian f64 (x epoch seconds, y price),
601
+ // read out of exported memory at `ptr` and copied into the handle. The
602
+ // ledger asks for them after its count checks (an oversize count never
603
+ // reads, an empty one skips) and before its caps: the module's memory and
604
+ // the pointer bounds are fatal checks.
605
+ const readPolylinePoints = (id, ptr, count) => {
606
+ const call = `wrun_draw_polyline(${id}, ${ptr}, ${count})`;
607
+ const element = { id, row: host.rowIndex, call: 'wrun_draw_polyline', arg: `ptr=${ptr}` };
608
+ const memory = exportedMemory(instanceRef.exports);
609
+ if (!memory) {
610
+ throw new WrunDrawRefusalError(WRUN3_DRAW_REFUSALS.polyline_out_of_bounds, `${call}: the module exports no memory for the host to read the points from`, element);
611
+ }
612
+ const byteLength = count * BYTES_PER_POINT;
613
+ if (!Number.isInteger(ptr) || ptr < 0 || ptr + byteLength > memory.buffer.byteLength) {
614
+ throw new WrunDrawRefusalError(WRUN3_DRAW_REFUSALS.polyline_out_of_bounds, `${call}: ${byteLength} bytes of points do not fit the module's exported memory of ` +
615
+ `${memory.buffer.byteLength} bytes; pass a pointer to count (x, y) f64 pairs inside exported memory`, element);
616
+ }
617
+ const view = new DataView(memory.buffer, ptr, byteLength);
618
+ const flat = new Float64Array(count * 2);
619
+ for (let at = 0; at < flat.length; at += 1)
620
+ flat[at] = view.getFloat64(at * 8, true);
621
+ return flat;
622
+ };
623
+ importObject.wrun.wrun_bar_last = () => {
624
+ if (host.phase !== 'state' && host.phase !== 'finalize') {
625
+ throw new WrunDrawRefusalError(WRUN3_DRAW_REFUSALS.phase, `wrun_bar_last is callable during state() and finalize() only (called during ${host.phase})`);
626
+ }
627
+ return host.barLast;
628
+ };
629
+ importObject.wrun.wrun_draw_line = (id, x1, y1, x2, y2) => {
630
+ requireDrawPhase('wrun_draw_line');
631
+ ledger.line(host.rowIndex, id, x1, y1, x2, y2);
632
+ };
633
+ importObject.wrun.wrun_draw_box = (id, left, top, right, bottom) => {
634
+ requireDrawPhase('wrun_draw_box');
635
+ ledger.box(host.rowIndex, id, left, top, right, bottom);
636
+ };
637
+ importObject.wrun.wrun_draw_label = (id, x, y, slot) => {
638
+ requireDrawPhase('wrun_draw_label');
639
+ ledger.label(host.rowIndex, id, x, y, { slot, slots: rowSlots });
640
+ };
641
+ importObject.wrun.wrun_draw_polyline = (id, ptr, count) => {
642
+ requireDrawPhase('wrun_draw_polyline');
643
+ ledger.polyline(host.rowIndex, id, { count, read: () => readPolylinePoints(id, ptr, count) });
644
+ };
645
+ importObject.wrun.wrun_draw_style = (id, prop, value) => {
646
+ requireDrawPhase('wrun_draw_style');
647
+ ledger.style(host.rowIndex, id, prop, value, rowSlots);
648
+ };
649
+ importObject.wrun.wrun_draw_color = (id, prop, rgba) => {
650
+ requireDrawPhase('wrun_draw_color');
651
+ ledger.color(host.rowIndex, id, prop, rgba);
652
+ };
653
+ importObject.wrun.wrun_draw_delete = (id) => {
654
+ requireDrawPhase('wrun_draw_delete');
655
+ ledger.delete(id, host.rowIndex);
656
+ };
657
+ }
658
+ // The wrun-3 strategy channel: the shared host's engine broker, driven by its
659
+ // own host (intent decoding, id interning, caps, the forming-bar clone and
660
+ // the close-confirm, event diffs). The driver owns every rule; this
661
+ // executor owns what needs the guest: the phase, exported memory for the
662
+ // (ptr, len) strings, the row index, the bar and its confirmation. A
663
+ // wrun-3 or later instantiation links the channel when the sheet declares
664
+ // `strategy`; a module importing it without the section refuses by
665
+ // name before anything links.
666
+ const strategyHost = abiAtLeast(config.abi, 'wrun-3') && config.strategy !== undefined
667
+ ? new sharedHost.WrunStrategyHost({
668
+ config: config.strategy.config,
669
+ ...(config.strategy.intervalMs !== undefined ? { intervalMs: config.strategy.intervalMs } : {}),
670
+ phase: () => host.phase,
671
+ memory: () => exportedMemory(instanceRef.exports),
672
+ events: config.strategy.events === true,
673
+ })
674
+ : null;
675
+ if (strategyHost)
676
+ Object.assign(importObject.wrun, strategyHost.imports);
677
+ else if (abiAtLeast(config.abi, 'wrun-3'))
678
+ refuseUndeclaredStrategyImports(config.module);
679
+ const instance = await WebAssembly.instantiate(config.module, importObject);
680
+ // Instantiated: the guest's first call (init) runs next, in this same turn.
681
+ config.onInstantiated?.();
682
+ instanceRef.exports = instance.exports;
683
+ const exports = instance.exports;
684
+ const init = requireFunction(exports.init, 'init');
685
+ const state = requireFunction(exports.state, 'state');
686
+ const finalize = requireFunction(exports.finalize, 'finalize');
687
+ requireFunction(exports.reset, 'reset');
688
+ resetHostResult(host);
689
+ guestCall(host, 'init', config.initArgs, -1, init);
690
+ checkMemoryLimit(exports, memoryLimit);
691
+ const memoryBaselineBytes = exportedMemoryByteLength(exports);
692
+ // The memory ceiling and the no-growth rule after EVERY guest call, with no
693
+ // `memory.buffer` read on the happy path: a held buffer that still reads
694
+ // the baseline proves the memory did not grow (growthWitness). Any other
695
+ // reading (a growth, or a memory.grow(0) that only swapped the buffer)
696
+ // takes the exact checks, same order and messages, and holds the buffer
697
+ // the memory has now. Without exported memory there is nothing to check.
698
+ const guestMemory = exportedMemory(exports);
699
+ let heldBuffer = growthWitness(guestMemory);
700
+ const checkMemoryAfterCall = () => {
701
+ if (guestMemory === null)
702
+ return;
703
+ if (heldBuffer !== null && heldBuffer.byteLength === memoryBaselineBytes)
704
+ return;
705
+ checkMemoryLimit(exports, memoryLimit);
706
+ checkMemoryGrowth(exports, memoryBaselineBytes);
707
+ heldBuffer = growthWitness(guestMemory);
708
+ };
709
+ // Live forming-bar state, carried ACROSS runRows calls: the timestamp the
710
+ // session last evaluated, the pre-evaluation snapshot that replays it, and
711
+ // (wrun-3 close-confirm) that row's inputs as last evaluated.
712
+ let liveTs = null;
713
+ let liveSnapshot = null;
714
+ let liveRow = null;
715
+ // Row indexes of the run window (the ledger's createdBar / mutatedBar): the
716
+ // index the next NEW timestamp takes, and the forming bar's index a live
717
+ // block may revise. A historical request is one block from row 0.
718
+ let nextRowIndex = 0;
719
+ let liveRowIndex = 0;
720
+ // Per block, not per row: every row of a block reads the same cell columns,
721
+ // so a row of the block already bound binds nothing (the close-confirm's
722
+ // one-row block and the block after it each bind once).
723
+ const bindBlock = (block) => {
724
+ if (block === current)
725
+ return;
726
+ current = block;
727
+ cellColumnCount = block.cellIndexes.length;
728
+ cellColumns = new Map();
729
+ for (let column = 0; column < cellColumnCount; column += 1) {
730
+ cellColumns.set(block.cellIndexes[column], column);
731
+ }
732
+ };
733
+ /** One row through state() and finalize(); the results stay in `host`
734
+ * for the caller to commit. False = the row is not ready. A strategy
735
+ * row begins on the broker FIRST (contract section 2, step 1: fills for
736
+ * orders queued on earlier rows, equity marked at the close), ready or
737
+ * not, so the equity series covers every bar. The broker confirms every
738
+ * bar of a full run (the engine's full-run rule: `isConfirmedBar` is
739
+ * false only for a live update's last bar); on the live lane the newest
740
+ * bar the request holds (`barLast`) is the forming bar and runs on a
741
+ * clone. `barLast` itself (the guest's `wrun_bar_last`) answers 1 on the
742
+ * newest bar in both modes. */
743
+ const evaluateRow = (block, row, rowIndex, barLast, mode) => {
744
+ bindBlock(block);
745
+ resetHostResult(host);
746
+ // The row's time rides every draw call it skips (the record's `ts`, the
747
+ // chart's row unit: epoch ms).
748
+ ledger?.beginRow(block.ts[row]);
749
+ host.rowIndex = rowIndex;
750
+ host.barLast = barLast;
751
+ const confirmed = mode === 'live' ? barLast === 0 : true;
752
+ strategyHost?.beginBar(rowIndex, block.ts[row], strategyBarOf(block, row), confirmed);
753
+ const stateResult = guestCall(host, 'state', EMPTY_ARGS, row, state);
754
+ checkMemoryAfterCall();
755
+ const readiness = typeof stateResult === 'number' ? stateResult : Number(stateResult ?? 0);
756
+ if (readiness < 1)
757
+ return false;
758
+ guestCall(host, 'finalize', EMPTY_ARGS, -1, finalize);
759
+ checkMemoryAfterCall();
760
+ validateDeclaredOutputs(host, outputCount);
761
+ return true;
762
+ };
763
+ const runRows = (block, mode) => {
764
+ const rowCount = block.rowCount;
765
+ // Live ordering is validated for the WHOLE block BEFORE any evaluation:
766
+ // a refused block must leave the guest state untouched (the typed error
767
+ // tells the worker the session survives).
768
+ if (mode === 'live') {
769
+ let expectedTs = liveTs;
770
+ for (let row = 0; row < rowCount; row += 1) {
771
+ const rowTs = block.ts[row];
772
+ if (expectedTs !== null && rowTs < expectedTs) {
773
+ throw new WrunLiveOrderError(`WRUN rows out of order: ${rowTs} < ${expectedTs}`);
774
+ }
775
+ expectedTs = rowTs;
776
+ }
777
+ }
778
+ // The wrun-6 row count every row of this block reads: the bars the session
779
+ // holds once the block is in. A historical block is all new bars; a live
780
+ // block adds the timestamps past the forming bar (a same-bar revision adds
781
+ // none). The pre-scan above has already ordered them.
782
+ let newBars = 0;
783
+ let newestTs = mode === 'live' ? liveTs : null;
784
+ for (let row = 0; row < rowCount; row += 1) {
785
+ const rowTs = block.ts[row];
786
+ if (mode !== 'live' || newestTs === null || rowTs > newestTs) {
787
+ newBars += 1;
788
+ newestTs = rowTs;
789
+ }
790
+ }
791
+ // A module reading the count never extends a session that already holds
792
+ // bars: a new bar changes the count every held bar read, which only a run
793
+ // over every bar again answers (the engine's re-seed). The main thread
794
+ // reopens the session instead; refused by name before any guest call.
795
+ if (readsBarCount && mode === 'live' && nextRowIndex > 0 && newBars > 0) {
796
+ throw new Error(`WRUN wrun_bar_count: a new bar runs a module that reads the row count again from its first ` +
797
+ `bar; the host reopens the session over every bar instead of extending it`);
798
+ }
799
+ // The block's buffer holds one cell per row and declared output: past the run allocation bound the
800
+ // block is refused by name BEFORE the buffer is allocated and before any guest call, so the session's
801
+ // state is untouched (wrun-run-cells.util).
802
+ const cellsRefusal = wrunRunCellsRefusal(rowCount, outputCount);
803
+ if (cellsRefusal !== null)
804
+ throw new Error(cellsRefusal);
805
+ host.barCount = nextRowIndex + newBars;
806
+ const ready = new Uint8Array(rowCount);
807
+ const outputs = new Float64Array(rowCount * outputCount);
808
+ // The packed string table (only when the run declares slots): row-major
809
+ // (row, slot) lengths (-1 = absent) and offsets into one concatenated
810
+ // byte buffer, assembled after the loop from the per-row commits.
811
+ const stringLens = stringSlotCount > 0 ? new Int32Array(rowCount * stringSlotCount).fill(-1) : null;
812
+ const stringOffsets = stringSlotCount > 0 ? new Int32Array(rowCount * stringSlotCount) : null;
813
+ const stringChunks = stringSlotCount > 0 ? [] : null;
814
+ let stringCursor = 0;
815
+ // The block's live accounting (answered on live-mode blocks only).
816
+ const startedAt = now();
817
+ let restored = 0;
818
+ let snapshotted = 0;
819
+ // A forming-bar restore: memory, globals, the ledger journal AND the
820
+ // run-level string accounting go back to the pre-evaluation state.
821
+ const restoreFormingBar = (snapshotValue) => {
822
+ restore(exports, snapshotValue);
823
+ ledger?.restore();
824
+ runStringBytes = snapshotValue.runStringBytes;
825
+ restored += 1;
826
+ config.onRestore?.();
827
+ };
828
+ try {
829
+ // Close-confirm (contract section 4): a live block that opens PAST the
830
+ // forming bar without re-sending it. That bar was evaluated as the
831
+ // newest bar (bar_last 1) while a full run evaluates it as a closed
832
+ // bar, so restore, re-evaluate it with bar_last 0 on its retained
833
+ // inputs, and commit that state (ledger included) before the new bar.
834
+ // Its replacement outputs have no row in this response to ride; the
835
+ // browser tick always re-sends the forming bar, where they ride the
836
+ // tick's own row through the replay branch below.
837
+ if (mode === 'live' && liveTs !== null && liveSnapshot && liveRow && rowCount > 0 && block.ts[0] > liveTs) {
838
+ restoreFormingBar(liveSnapshot);
839
+ if (evaluateRow(liveRow, 0, liveRowIndex, 0, mode))
840
+ runStringBytes += host.rowStringBytes;
841
+ liveSnapshot = null;
842
+ liveRow = null;
843
+ }
844
+ for (let row = 0; row < rowCount; row += 1) {
845
+ const rowTs = block.ts[row];
846
+ let rowIndex;
847
+ if (mode === 'live' && liveTs !== null && rowTs === liveTs) {
848
+ // A revised forming bar: back to the pre-evaluation state (memory,
849
+ // globals, ledger, string accounting), same row index. A row below
850
+ // the watermark cannot reach here: the pre-scan refused the whole
851
+ // block.
852
+ if (!liveSnapshot)
853
+ throw new Error('WRUN live restore requested before snapshot');
854
+ restoreFormingBar(liveSnapshot);
855
+ liveRow = sliceRow(block, row);
856
+ rowIndex = liveRowIndex;
857
+ }
858
+ else {
859
+ rowIndex = nextRowIndex;
860
+ nextRowIndex += 1;
861
+ // The ledger's baseline moves with every new bar on BOTH lanes: its
862
+ // journal is the ops of the current bar only (the live lane undoes
863
+ // them on a same-bar restore; the historical lane never restores,
864
+ // and without the per-row reset it would retain one op plus one
865
+ // replaced entry per draw call for the whole request).
866
+ ledger?.snapshot();
867
+ if (mode === 'live') {
868
+ // LAZY snapshot: only a row that can later be REPLAYED needs the
869
+ // pre-evaluation state saved: the block's LAST row (a future
870
+ // block may open with the same ts) or a row this same block
871
+ // revises (next ts equal). A historical prefix streamed through
872
+ // a live block therefore costs exactly ONE snapshot (its last
873
+ // row), not one per bar: the mount/pan cost path.
874
+ const nextTs = row + 1 < rowCount ? block.ts[row + 1] : null;
875
+ if (nextTs === null || nextTs === rowTs) {
876
+ liveSnapshot = snapshot(exports, runStringBytes);
877
+ liveRow = sliceRow(block, row);
878
+ snapshotted += 1;
879
+ config.onSnapshot?.();
880
+ }
881
+ else {
882
+ liveSnapshot = null;
883
+ liveRow = null;
884
+ }
885
+ liveTs = rowTs;
886
+ liveRowIndex = rowIndex;
887
+ }
888
+ }
889
+ // The last-bar signal: 1 exactly on the newest bar the request holds
890
+ // (a full run's row N, a live block's forming bar; a stale frame of
891
+ // that same bar is the same bar).
892
+ const barLast = rowTs === block.ts[rowCount - 1] ? 1 : 0;
893
+ if (!evaluateRow(block, row, rowIndex, barLast, mode))
894
+ continue;
895
+ ready[row] = 1;
896
+ // Validation proved every declared output was written this row.
897
+ const outputBase = row * outputCount;
898
+ for (let idx = 0; idx < outputCount; idx += 1) {
899
+ outputs[outputBase + idx] = host.outputs[idx];
900
+ }
901
+ if (stringLens !== null && stringOffsets !== null && stringChunks !== null) {
902
+ // Commit the row's final string writes: a live same-bar replay
903
+ // re-runs finalize after restore, so the LAST evaluation of a
904
+ // timestamp is the one whose strings ride out, exactly like its
905
+ // numeric outputs.
906
+ for (let slot = 0; slot < stringSlotCount; slot += 1) {
907
+ const bytes = host.stringWrites[slot];
908
+ const at = row * stringSlotCount + slot;
909
+ if (bytes === null) {
910
+ stringLens[at] = -1;
911
+ continue;
912
+ }
913
+ stringLens[at] = bytes.byteLength;
914
+ stringOffsets[at] = stringCursor;
915
+ stringChunks.push(bytes);
916
+ stringCursor += bytes.byteLength;
917
+ }
918
+ runStringBytes += host.rowStringBytes;
919
+ }
920
+ }
921
+ }
922
+ finally {
923
+ current = null;
924
+ }
925
+ // The ledger's full live set rides beside every block's rows (the wire
926
+ // replaces the drawing set wholesale), and so do the run's skipped calls
927
+ // when a call was skipped (journaled with the ledger, so a live session's
928
+ // equal a full run's); wrun-1 and wrun-2, and a run that skipped nothing,
929
+ // answer the exact shape they always did.
930
+ const handles = ledger ? { handles: ledger.records(), ...ledger.drawSkips() } : {};
931
+ const frames = frameSlotCount > 0
932
+ ? { frames: frameWrites.map((bytes) => (bytes === undefined ? undefined : UTF8_FATAL.decode(bytes))) }
933
+ : {};
934
+ // The strategy output after the block: the committed fold (plus the
935
+ // forming bar's mark on the live lane), replaced wholesale
936
+ // per response. Its bytes count against the same expanded render result
937
+ // as the ledger's (contract section 4).
938
+ const strategy = strategyHost ? strategyOutputOf(strategyHost, ledger, nextRowIndex, config.strategy?.events) : {};
939
+ // Live blocks answer their restore/snapshot accounting; a historical
940
+ // request keeps the exact shape it always had.
941
+ const live = mode === 'live'
942
+ ? {
943
+ live: {
944
+ restored,
945
+ snapshotted,
946
+ memoryBytes: exportedMemoryByteLength(exports) ?? 0,
947
+ evalMs: now() - startedAt,
948
+ rows: rowCount,
949
+ stringBytes: runStringBytes,
950
+ },
951
+ }
952
+ : {};
953
+ if (stringLens === null || stringOffsets === null || stringChunks === null) {
954
+ return { ready, outputs, strings: undefined, ...handles, ...strategy, ...frames, ...live };
955
+ }
956
+ const stringBytes = new Uint8Array(stringCursor);
957
+ let writeAt = 0;
958
+ for (const chunk of stringChunks) {
959
+ stringBytes.set(chunk, writeAt);
960
+ writeAt += chunk.byteLength;
961
+ }
962
+ return {
963
+ ready,
964
+ outputs,
965
+ strings: { lens: stringLens, offsets: stringOffsets, bytes: stringBytes },
966
+ ...handles,
967
+ ...strategy,
968
+ ...frames,
969
+ ...live,
970
+ };
971
+ };
972
+ return { runRows };
973
+ }
974
+ /** The strategy fields of a block's answer: the engine's StrategyOutput,
975
+ * refused by name when its wire bytes (plus the ledger's) exceed the
976
+ * expanded render result's cap, and with `events` on, the event streams and the
977
+ * reserved outputs over the `rowCount` rows the session has begun. */
978
+ function strategyOutputOf(strategyHost, ledger, rowCount, events) {
979
+ const output = strategyHost.finalize();
980
+ const { wrunStrategyWireBytes, WrunStrategyRefusalError } = wrunChartHostEnv().sharedHost();
981
+ const bytes = wrunStrategyWireBytes(output) + (ledger?.accountedBytes ?? 0);
982
+ if (bytes > WRUN_RENDER_RESULT_LIMIT_BYTES) {
983
+ throw new WrunStrategyRefusalError('wrun_render_result_too_large', `the strategy result (${output.trades.length} trades over ${output.equity.length} bars) and the drawings total ` +
984
+ `${bytes} bytes, over the ${WRUN_RENDER_RESULT_LIMIT_BYTES}-byte render result limit`, 'trade less often, draw less, or run the strategy over fewer bars');
985
+ }
986
+ if (events !== true)
987
+ return { strategy: output };
988
+ return {
989
+ strategy: output,
990
+ strategyEvents: strategyHost.events,
991
+ strategyReserved: strategyHost.reservedOutputs(rowCount),
992
+ };
993
+ }
994
+ /** One whole request against a fresh instance of the module the engine worker resolved for it (a resolved request:
995
+ * the wire request's module key and bytes already turned into the compiled module, never a wire request). */
996
+ export async function runWrunPackedRequest(request, options = {}) {
997
+ const session = await createWrunAbiSession({
998
+ module: request.module,
999
+ abi: request.abi,
1000
+ outputCount: request.outputCount,
1001
+ initArgs: request.initArgs,
1002
+ textParams: request.textParams,
1003
+ stringMaxBytes: request.stringMaxBytes,
1004
+ frameMaxBytes: request.frameMaxBytes,
1005
+ handleDefaults: request.handleDefaults,
1006
+ strategy: request.strategy,
1007
+ memoryLimitBytes: options.memoryLimitBytes,
1008
+ onInstantiated: options.onInstantiated,
1009
+ });
1010
+ return session.runRows(request, request.mode);
1011
+ }
1012
+ /** Run one guest export with the phase and argument block it is owed. A
1013
+ * guest trap leaves `phase` at the phase that trapped: the whole request
1014
+ * fails, and the error message (for the cell channel) names that phase. */
1015
+ function guestCall(host, phase, args, packedRow, fn) {
1016
+ host.phase = phase;
1017
+ host.args = args;
1018
+ host.packedRow = packedRow;
1019
+ const result = fn();
1020
+ host.phase = 'idle';
1021
+ host.args = EMPTY_ARGS;
1022
+ host.packedRow = -1;
1023
+ return result;
1024
+ }
1025
+ /** A fresh row in the session's own buffers: a new stamp un-writes every
1026
+ * output at once, and every string slot goes back to absent. */
1027
+ function resetHostResult(host) {
1028
+ if (host.rowStamp === MAX_ROW_STAMP) {
1029
+ host.writtenAt.fill(0);
1030
+ host.rowStamp = 0;
1031
+ }
1032
+ host.rowStamp += 1;
1033
+ host.writtenCount = 0;
1034
+ host.count = 0;
1035
+ host.ready = false;
1036
+ const stringWrites = host.stringWrites;
1037
+ for (let slot = 0; slot < stringWrites.length; slot += 1)
1038
+ stringWrites[slot] = null;
1039
+ host.rowStringBytes = 0;
1040
+ }
1041
+ function validateDeclaredOutputs(host, outputCount) {
1042
+ const returned = host.ready ? host.count : 0;
1043
+ // The happy path decides on the two counts, allocation-free: every
1044
+ // declared output written this row, and the returned count covering them.
1045
+ if (host.writtenCount === outputCount && returned >= outputCount)
1046
+ return;
1047
+ const missing = [];
1048
+ const truncated = [];
1049
+ for (let idx = 0; idx < outputCount; idx += 1) {
1050
+ if (host.writtenAt[idx] !== host.rowStamp) {
1051
+ missing.push(idx);
1052
+ continue;
1053
+ }
1054
+ if (idx >= returned)
1055
+ truncated.push(idx);
1056
+ }
1057
+ if (missing.length === 0 && truncated.length === 0)
1058
+ return;
1059
+ const problems = [];
1060
+ if (missing.length > 0)
1061
+ problems.push(`never wrote declared output(s) ${missing.join(', ')}`);
1062
+ if (truncated.length > 0) {
1063
+ problems.push(`left declared output(s) ${truncated.join(', ')} outside the returnOutput count ${returned}`);
1064
+ }
1065
+ throw new Error(`WRUN declared output validation failed: ${problems.join('; ')}; check setOutput indices and returnOutput count against metadata outputs`);
1066
+ }
1067
+ /** One row of a packed block as its own one-row block (the forming bar's
1068
+ * inputs, retained for a close-confirm re-evaluation): the scalar slice,
1069
+ * the row's cell blocks, copied contiguously, and its broker feed bar. */
1070
+ function sliceRow(block, row) {
1071
+ const columns = block.cellIndexes.length;
1072
+ const cellLens = block.cellLens.slice(row * columns, (row + 1) * columns);
1073
+ const cellOffsets = new Int32Array(columns);
1074
+ let total = 0;
1075
+ for (let column = 0; column < columns; column += 1)
1076
+ if (cellLens[column] > 0)
1077
+ total += cellLens[column];
1078
+ const cells = new Float64Array(total);
1079
+ let cursor = 0;
1080
+ for (let column = 0; column < columns; column += 1) {
1081
+ const len = cellLens[column];
1082
+ if (len <= 0)
1083
+ continue;
1084
+ const from = block.cellOffsets[row * columns + column];
1085
+ cells.set(block.cells.subarray(from, from + len), cursor);
1086
+ cellOffsets[column] = cursor;
1087
+ cursor += len;
1088
+ }
1089
+ const bars = block.strategyBars;
1090
+ return {
1091
+ rowCount: 1,
1092
+ stride: block.stride,
1093
+ ts: block.ts.slice(row, row + 1),
1094
+ argCounts: block.argCounts.slice(row, row + 1),
1095
+ values: block.values.slice(row * block.stride, (row + 1) * block.stride),
1096
+ cellIndexes: block.cellIndexes,
1097
+ cellLens,
1098
+ cellOffsets,
1099
+ cells,
1100
+ ...(bars !== undefined
1101
+ ? { strategyBars: bars.slice(row * STRATEGY_BAR_STRIDE, (row + 1) * STRATEGY_BAR_STRIDE) }
1102
+ : {}),
1103
+ };
1104
+ }
1105
+ /** Same-bar live restore semantics: copy linear memory plus the mutable
1106
+ * globals exported under __wrun_g*. The engine worker exports EVERY mutable
1107
+ * global under that prefix when it compiles the module (wrun-engine-handler
1108
+ * compileWrunModuleBytes), so a compiler's top-level scalars restore beside
1109
+ * the heap they index; a module must still export its memory if it keeps
1110
+ * state there (AssemblyScript does by default). */
1111
+ function snapshot(exports, runStringBytes) {
1112
+ const memory = exportedMemory(exports);
1113
+ const view = memory ? new Uint8Array(memory.buffer) : null;
1114
+ const globals = new Map();
1115
+ for (const [name, value] of Object.entries(exports)) {
1116
+ if (!name.startsWith(WRUN_GLOBAL_PREFIX))
1117
+ continue;
1118
+ if (value instanceof WebAssembly.Global) {
1119
+ globals.set(name, value.value);
1120
+ }
1121
+ }
1122
+ return { memory: view ? new Uint8Array(view) : null, globals, runStringBytes };
1123
+ }
1124
+ function restore(exports, snapshotValue) {
1125
+ if (snapshotValue.memory) {
1126
+ const memory = exportedMemory(exports);
1127
+ if (!memory)
1128
+ throw new Error('WRUN module has no memory export to restore');
1129
+ const view = new Uint8Array(memory.buffer);
1130
+ if (view.byteLength !== snapshotValue.memory.byteLength) {
1131
+ throw new Error('WRUN memory size changed between snapshot and restore');
1132
+ }
1133
+ view.set(snapshotValue.memory);
1134
+ }
1135
+ for (const [name, value] of snapshotValue.globals) {
1136
+ const exported = exports[name];
1137
+ if (!(exported instanceof WebAssembly.Global)) {
1138
+ throw new Error(`WRUN global ${name} is not restorable`);
1139
+ }
1140
+ try {
1141
+ exported.value = value;
1142
+ }
1143
+ catch (err) {
1144
+ const detail = err instanceof Error ? `: ${err.message}` : '';
1145
+ throw new Error(`WRUN global ${name} is not restorable${detail}`, { cause: err });
1146
+ }
1147
+ }
1148
+ }
1149
+ function exportedMemory(exports) {
1150
+ if (!exports)
1151
+ return null;
1152
+ const memory = exports.memory;
1153
+ return memory instanceof WebAssembly.Memory ? memory : null;
1154
+ }
1155
+ const UTF16LE = new TextDecoder('utf-16le');
1156
+ /** Longest abort message or path the host repeats (a runaway string is still one line). */
1157
+ const ABORT_STRING_MAX_CHARS = 512;
1158
+ /** An AssemblyScript `string` in the guest's memory: UTF-16LE code units at `ptr`, the byte
1159
+ * length as the u32 at `ptr - 4` (the managed object header's rtSize). Null for a null
1160
+ * pointer, no memory, or a header that does not fit the memory: a trap never traps twice. */
1161
+ export function readAssemblyScriptString(memory, ptr) {
1162
+ if (!memory || !Number.isInteger(ptr) || ptr < 4)
1163
+ return null;
1164
+ const { buffer } = memory;
1165
+ if (ptr > buffer.byteLength)
1166
+ return null;
1167
+ const byteLength = new DataView(buffer).getUint32(ptr - 4, true);
1168
+ if (byteLength > buffer.byteLength - ptr)
1169
+ return null;
1170
+ const text = UTF16LE.decode(new Uint8Array(buffer, ptr, byteLength & ~1));
1171
+ return text.length > ABORT_STRING_MAX_CHARS ? text.slice(0, ABORT_STRING_MAX_CHARS) : text;
1172
+ }
1173
+ /** `AssemblyScript abort: <message> at <path>:<line>:<column>`; the message part only when
1174
+ * the guest passed one, the position only when asc supplied one (a path, or a non-zero
1175
+ * line/column without a path, the position-only shape this host used to throw). */
1176
+ export function formatAssemblyScriptAbort(message, fileName, line, column) {
1177
+ const head = message ? `AssemblyScript abort: ${message}` : 'AssemblyScript abort';
1178
+ if (fileName)
1179
+ return `${head} at ${fileName}:${line}:${column}`;
1180
+ if (line > 0 || column > 0)
1181
+ return `${head} at ${line}:${column}`;
1182
+ return head;
1183
+ }
1184
+ function checkMemoryLimit(exports, limit) {
1185
+ const memory = exportedMemory(exports);
1186
+ if (!memory)
1187
+ return;
1188
+ if (memory.buffer.byteLength > limit) {
1189
+ throw new Error(`WRUN memory ${memory.buffer.byteLength} bytes exceeds limit ${limit} bytes`);
1190
+ }
1191
+ }
1192
+ function checkMemoryGrowth(exports, baselineBytes) {
1193
+ const currentBytes = exportedMemoryByteLength(exports);
1194
+ if (currentBytes === null || baselineBytes === null)
1195
+ return;
1196
+ if (currentBytes > baselineBytes) {
1197
+ throw new Error(`WRUN memory grew from ${baselineBytes} to ${currentBytes} bytes after init; allocate persistent state in init and keep per-bar state/finalize work allocation-free`);
1198
+ }
1199
+ }
1200
+ /** The buffer whose own length vouches that the memory has not grown since:
1201
+ * a non-shared memory's, because every growth (a memory.grow(0) included)
1202
+ * detaches the buffer the memory had and a detached buffer's byteLength
1203
+ * reads 0. Null for a shared memory (its old buffer keeps its length; read
1204
+ * by tag, so a buffer from another realm answers the same) and for a
1205
+ * zero-byte one (detached or not, it reads 0). */
1206
+ function growthWitness(memory) {
1207
+ if (memory === null)
1208
+ return null;
1209
+ const buffer = memory.buffer;
1210
+ return buffer.byteLength > 0 && Object.prototype.toString.call(buffer) === '[object ArrayBuffer]' ? buffer : null;
1211
+ }
1212
+ function exportedMemoryByteLength(exports) {
1213
+ const memory = exportedMemory(exports);
1214
+ return memory ? memory.buffer.byteLength : null;
1215
+ }
1216
+ function requireFunction(value, name) {
1217
+ if (typeof value !== 'function')
1218
+ throw new Error(`WRUN module missing function export '${name}'`);
1219
+ return value;
1220
+ }