@orangecharts/wrun-chart-host 0.3.0 → 0.5.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 (362) hide show
  1. package/README.md +23 -6
  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/kscript-data-interval-restrictions.constants.d.ts +15 -0
  5. package/dist/constants/kscript-data-interval-restrictions.constants.js +40 -0
  6. package/dist/constants/opra-compliance.constants.d.ts +19 -0
  7. package/dist/constants/opra-compliance.constants.js +19 -0
  8. package/dist/constants/replay-ladder.leaf.d.ts +30 -0
  9. package/dist/constants/replay-ladder.leaf.js +99 -0
  10. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +133 -0
  11. package/dist/constants/scriptEditor/builtin-script-snippets.js +451 -0
  12. package/dist/constants/scriptEditor/cme-official-scripts.constants.d.ts +168 -0
  13. package/dist/constants/scriptEditor/cme-official-scripts.constants.js +398 -0
  14. package/dist/constants/scriptEditor/converted-script-id.leaf.d.ts +8 -0
  15. package/dist/constants/scriptEditor/converted-script-id.leaf.js +10 -0
  16. package/dist/constants/scriptEditor/execution.constants.d.ts +4 -0
  17. package/dist/constants/scriptEditor/execution.constants.js +14 -0
  18. package/dist/constants/wrun-prefix-safe.constants.d.ts +23 -0
  19. package/dist/constants/wrun-prefix-safe.constants.js +26 -0
  20. package/dist/host-env.d.ts +321 -24
  21. package/dist/host-env.js +15 -0
  22. package/dist/host-ports.types.d.ts +857 -35
  23. package/dist/index.d.ts +149 -2
  24. package/dist/index.js +149 -2
  25. package/dist/instances/script-engine-worker-ohlcv-transfer.d.ts +31 -0
  26. package/dist/instances/script-engine-worker-ohlcv-transfer.js +164 -0
  27. package/dist/interfaces/market-event.interface.d.ts +231 -0
  28. package/dist/interfaces/market-event.interface.js +15 -0
  29. package/dist/interfaces/opra-realtime.interface.d.ts +70 -134
  30. package/dist/interfaces/opra-realtime.interface.js +34 -59
  31. package/dist/interfaces/replay.interface.d.ts +285 -0
  32. package/dist/interfaces/replay.interface.js +1 -0
  33. package/dist/kscript-data/controls/live-ohlcv-merge.util.d.ts +1 -0
  34. package/dist/kscript-data/controls/live-ohlcv-merge.util.js +93 -0
  35. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +5 -1
  36. package/dist/kscript-data/controls/live-trades-merge.util.js +2 -2
  37. package/dist/market-data/billing.interface.d.ts +219 -0
  38. package/dist/market-data/billing.interface.js +58 -0
  39. package/dist/market-data/venue-governed.util.d.ts +2 -0
  40. package/dist/market-data/venue-governed.util.js +10 -0
  41. package/dist/market-data/venue.d.ts +122 -0
  42. package/dist/market-data/venue.js +1 -0
  43. package/dist/market-data/venues/index.d.ts +97 -0
  44. package/dist/market-data/venues/index.js +33 -0
  45. package/dist/market-data/venues/opra.contract.copy.json +35 -0
  46. package/dist/market-data/venues/opra.d.ts +70 -0
  47. package/dist/market-data/venues/opra.js +74 -0
  48. package/dist/replay/replayIndicatorRows.d.ts +31 -0
  49. package/dist/replay/replayIndicatorRows.js +117 -0
  50. package/dist/replay/replayLadder.d.ts +85 -0
  51. package/dist/replay/replayLadder.js +388 -0
  52. package/dist/utility/auth/server-clock.util.d.ts +81 -0
  53. package/dist/utility/auth/server-clock.util.js +238 -0
  54. package/dist/utility/chart/builtin-identity.util.d.ts +18 -0
  55. package/dist/utility/chart/builtin-identity.util.js +51 -0
  56. package/dist/utility/chart/cache-alignment.util.d.ts +454 -0
  57. package/dist/utility/chart/cache-alignment.util.js +926 -0
  58. package/dist/utility/chart/chart-data-fetch-generation.util.d.ts +15 -0
  59. package/dist/utility/chart/chart-data-fetch-generation.util.js +22 -0
  60. package/dist/utility/chart/chart-mount-epoch.util.d.ts +5 -0
  61. package/dist/utility/chart/chart-mount-epoch.util.js +29 -0
  62. package/dist/utility/chart/chart-time-domain.util.d.ts +12 -0
  63. package/dist/utility/chart/chart-time-domain.util.js +23 -0
  64. package/dist/utility/chart/color-customization.leaf.d.ts +10 -0
  65. package/dist/utility/chart/color-customization.leaf.js +16 -0
  66. package/dist/utility/chart/date-labelled-interval.leaf.d.ts +15 -0
  67. package/dist/utility/chart/date-labelled-interval.leaf.js +19 -0
  68. package/dist/utility/chart/footprint-tick-grid.util.d.ts +106 -0
  69. package/dist/utility/chart/footprint-tick-grid.util.js +167 -0
  70. package/dist/utility/chart/gesture-timing.leaf.d.ts +29 -0
  71. package/dist/utility/chart/gesture-timing.leaf.js +29 -0
  72. package/dist/utility/chart/governed-contract-coin.util.d.ts +22 -0
  73. package/dist/utility/chart/governed-contract-coin.util.js +39 -0
  74. package/dist/utility/chart/host-bar-placement.util.d.ts +107 -0
  75. package/dist/utility/chart/host-bar-placement.util.js +447 -0
  76. package/dist/utility/chart/index-host-tier.util.d.ts +31 -0
  77. package/dist/utility/chart/index-host-tier.util.js +118 -0
  78. package/dist/utility/chart/index-mode-admission.util.d.ts +34 -0
  79. package/dist/utility/chart/index-mode-admission.util.js +67 -0
  80. package/dist/utility/chart/indicator-error-message.util.d.ts +35 -0
  81. package/dist/utility/chart/indicator-error-message.util.js +44 -0
  82. package/dist/utility/chart/indicator-run-interval.util.d.ts +130 -0
  83. package/dist/utility/chart/indicator-run-interval.util.js +268 -0
  84. package/dist/utility/chart/kscript-apply-fingerprint.util.d.ts +65 -0
  85. package/dist/utility/chart/kscript-apply-fingerprint.util.js +357 -0
  86. package/dist/utility/chart/kscript-chart-flush.leaf.d.ts +22 -0
  87. package/dist/utility/chart/kscript-chart-flush.leaf.js +13 -0
  88. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +6 -0
  89. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +27 -0
  90. package/dist/utility/chart/kscript-integration-decision.leaf.d.ts +89 -0
  91. package/dist/utility/chart/kscript-integration-decision.leaf.js +80 -0
  92. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +76 -0
  93. package/dist/utility/chart/kscript-live-coalesce.util.js +156 -0
  94. package/dist/utility/chart/kscript-live-rest-pace.util.d.ts +34 -0
  95. package/dist/utility/chart/kscript-live-rest-pace.util.js +134 -0
  96. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +98 -0
  97. package/dist/utility/chart/kscript-live-source-identity.util.js +121 -0
  98. package/dist/utility/chart/kscript-mounted-plot-set.leaf.d.ts +48 -0
  99. package/dist/utility/chart/kscript-mounted-plot-set.leaf.js +145 -0
  100. package/dist/utility/chart/kscript-perf-tracker.util.d.ts +243 -0
  101. package/dist/utility/chart/kscript-perf-tracker.util.js +522 -0
  102. package/dist/utility/chart/kscript-run-interval-projection.util.d.ts +43 -0
  103. package/dist/utility/chart/kscript-run-interval-projection.util.js +471 -0
  104. package/dist/utility/chart/kscript-run-result-equality.util.d.ts +38 -0
  105. package/dist/utility/chart/kscript-run-result-equality.util.js +89 -0
  106. package/dist/utility/chart/kscript-settings-revision.leaf.d.ts +2 -0
  107. package/dist/utility/chart/kscript-settings-revision.leaf.js +12 -0
  108. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +63 -0
  109. package/dist/utility/chart/kscript-source-degrade.leaf.js +68 -0
  110. package/dist/utility/chart/kscript-source-retention.util.d.ts +134 -0
  111. package/dist/utility/chart/kscript-source-retention.util.js +218 -0
  112. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +57 -0
  113. package/dist/utility/chart/kscript-standin-identity.leaf.js +61 -0
  114. package/dist/utility/chart/kscript-titancharts-preparation.util.d.ts +15 -0
  115. package/dist/utility/chart/kscript-titancharts-preparation.util.js +376 -0
  116. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +9 -0
  117. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +130 -0
  118. package/dist/utility/chart/kscript-venue-policy.util.d.ts +217 -0
  119. package/dist/utility/chart/kscript-venue-policy.util.js +324 -0
  120. package/dist/utility/chart/live-cadence.util.d.ts +38 -0
  121. package/dist/utility/chart/live-cadence.util.js +37 -0
  122. package/dist/utility/chart/live-feed-series-match.leaf.d.ts +13 -0
  123. package/dist/utility/chart/live-feed-series-match.leaf.js +21 -0
  124. package/dist/utility/chart/local-engine-self-heal-backoff.util.d.ts +46 -0
  125. package/dist/utility/chart/local-engine-self-heal-backoff.util.js +46 -0
  126. package/dist/utility/chart/local-engine-uninit.leaf.d.ts +21 -0
  127. package/dist/utility/chart/local-engine-uninit.leaf.js +22 -0
  128. package/dist/utility/chart/local-kscript-source-revalidation.util.d.ts +62 -0
  129. package/dist/utility/chart/local-kscript-source-revalidation.util.js +123 -0
  130. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +214 -0
  131. package/dist/utility/chart/local-kscript-warmup-depth.util.js +376 -0
  132. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.d.ts +85 -0
  133. package/dist/utility/chart/local-technical-script-live-apply-coalescer.util.js +197 -0
  134. package/dist/utility/chart/local-technical-script-range.leaf.d.ts +72 -0
  135. package/dist/utility/chart/local-technical-script-range.leaf.js +126 -0
  136. package/dist/utility/chart/mixed-mode.util.d.ts +167 -0
  137. package/dist/utility/chart/mixed-mode.util.js +139 -0
  138. package/dist/utility/chart/ohlcv-row-readiness.util.d.ts +36 -0
  139. package/dist/utility/chart/ohlcv-row-readiness.util.js +90 -0
  140. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +19 -0
  141. package/dist/utility/chart/opra-user-scripts-gate.util.js +32 -0
  142. package/dist/utility/chart/overlay-execution-guard-key.leaf.d.ts +8 -0
  143. package/dist/utility/chart/overlay-execution-guard-key.leaf.js +10 -0
  144. package/dist/utility/chart/price-precision.util.d.ts +40 -0
  145. package/dist/utility/chart/price-precision.util.js +70 -0
  146. package/dist/utility/chart/profile-block-size.util.d.ts +64 -0
  147. package/dist/utility/chart/profile-block-size.util.js +141 -0
  148. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.d.ts +11 -0
  149. package/dist/utility/chart/protected-kscript-degenerate-rows.leaf.js +29 -0
  150. package/dist/utility/chart/protected-kscript-empty-output.util.d.ts +28 -0
  151. package/dist/utility/chart/protected-kscript-empty-output.util.js +84 -0
  152. package/dist/utility/chart/run-interval-unservable.leaf.d.ts +9 -0
  153. package/dist/utility/chart/run-interval-unservable.leaf.js +20 -0
  154. package/dist/utility/chart/run-interval-warmup.leaf.d.ts +19 -0
  155. package/dist/utility/chart/run-interval-warmup.leaf.js +35 -0
  156. package/dist/utility/chart/titan-constants.pin.d.ts +9 -5
  157. package/dist/utility/chart/titan-constants.pin.js +18 -5
  158. package/dist/utility/chart/warmup-backfill-retry.leaf.d.ts +9 -0
  159. package/dist/utility/chart/warmup-backfill-retry.leaf.js +9 -0
  160. package/dist/utility/chart/window-geometry.leaf.d.ts +119 -0
  161. package/dist/utility/chart/window-geometry.leaf.js +391 -0
  162. package/dist/utility/chart/window-owner.leaf.d.ts +19 -0
  163. package/dist/utility/chart/window-owner.leaf.js +24 -0
  164. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +11 -2
  165. package/dist/utility/chart/wrun-bar-session-facts.util.js +10 -3
  166. package/dist/utility/chart/wrun-run-result.util.d.ts +5 -1
  167. package/dist/utility/chart/wrun-run-result.util.js +20 -14
  168. package/dist/utility/common/data-processing.util.d.ts +138 -0
  169. package/dist/utility/common/data-processing.util.js +346 -0
  170. package/dist/utility/common/visible-timeout.util.d.ts +13 -4
  171. package/dist/utility/common/visible-timeout.util.js +23 -8
  172. package/dist/utility/exchange-format.leaf.d.ts +1 -0
  173. package/dist/utility/exchange-format.leaf.js +47 -0
  174. package/dist/utility/html-escape.leaf.d.ts +11 -0
  175. package/dist/utility/html-escape.leaf.js +20 -0
  176. package/dist/utility/market-events/earnings-scope.util.d.ts +60 -0
  177. package/dist/utility/market-events/earnings-scope.util.js +92 -0
  178. package/dist/utility/market-events/market-events.util.d.ts +147 -0
  179. package/dist/utility/market-events/market-events.util.js +392 -0
  180. package/dist/utility/market-events/zoned-clock.util.d.ts +1 -0
  181. package/dist/utility/market-events/zoned-clock.util.js +11 -0
  182. package/dist/utility/options/option-venue-disclosure.util.d.ts +43 -0
  183. package/dist/utility/options/option-venue-disclosure.util.js +56 -0
  184. package/dist/utility/scriptEditor/package-semver.util.d.ts +51 -0
  185. package/dist/utility/scriptEditor/package-semver.util.js +120 -0
  186. package/dist/utility/scriptEditor/temp-script-id.util.d.ts +18 -0
  187. package/dist/utility/scriptEditor/temp-script-id.util.js +25 -0
  188. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.d.ts +20 -0
  189. package/dist/utility/symbol-selection/markets-request-from-symbols.leaf.js +81 -0
  190. package/dist/utility/v2/governed-tier.leaf.d.ts +103 -0
  191. package/dist/utility/v2/governed-tier.leaf.js +113 -0
  192. package/dist/utility/watchlist/import/import-request.leaf.d.ts +10 -0
  193. package/dist/utility/watchlist/import/import-request.leaf.js +10 -0
  194. package/dist/utility/wrun/sources/lanes/option_daily.d.ts +43 -15
  195. package/dist/utility/wrun/sources/lanes/option_daily.js +78 -20
  196. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +14 -10
  197. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +5 -4
  198. package/dist/utility/wrun/sources/lanes/series.js +2 -2
  199. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +22 -3
  200. package/dist/utility/wrun/sources/opra-option-lanes.util.js +38 -7
  201. package/dist/utility/wrun/sources/registry.js +31 -1
  202. package/dist/utility/wrun/sources/row-lane-registry.js +5 -5
  203. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +49 -0
  204. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +75 -20
  205. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +49 -0
  206. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +57 -47
  207. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +36 -4
  208. package/dist/utility/wrun/sources/row-lanes/option_surface.js +6 -12
  209. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +37 -3
  210. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +128 -2
  211. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +233 -51
  212. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +0 -8
  213. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +26 -24
  214. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +85 -104
  215. package/dist/utility/wrun/wrun-alert-outputs.registry.d.ts +166 -0
  216. package/dist/utility/wrun/wrun-alert-outputs.registry.js +219 -0
  217. package/dist/utility/wrun/wrun-bar-count.util.d.ts +83 -0
  218. package/dist/utility/wrun/wrun-bar-count.util.js +259 -0
  219. package/dist/utility/wrun/wrun-chart-context-names.util.d.ts +84 -0
  220. package/dist/utility/wrun/wrun-chart-context-names.util.js +186 -0
  221. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +253 -0
  222. package/dist/utility/wrun/wrun-chart-market-facts.util.js +731 -0
  223. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.d.ts +28 -0
  224. package/dist/utility/wrun/wrun-cloud-opra-stamp.util.js +45 -0
  225. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +18 -0
  226. package/dist/utility/wrun/wrun-coin-lane-live.util.js +47 -0
  227. package/dist/utility/wrun/wrun-deadline.util.js +2 -1
  228. package/dist/utility/wrun/wrun-debug-output.util.d.ts +39 -0
  229. package/dist/utility/wrun/wrun-debug-output.util.js +63 -0
  230. package/dist/utility/wrun/wrun-declared-warmup.util.d.ts +113 -0
  231. package/dist/utility/wrun/wrun-declared-warmup.util.js +181 -0
  232. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +43 -0
  233. package/dist/utility/wrun/wrun-draft-legend-note.util.js +158 -0
  234. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +181 -0
  235. package/dist/utility/wrun/wrun-draft-overlay.util.js +357 -0
  236. package/dist/utility/wrun/wrun-draw-skipped.leaf.d.ts +16 -0
  237. package/dist/utility/wrun/wrun-draw-skipped.leaf.js +16 -0
  238. package/dist/utility/wrun/wrun-earnings-facts.util.d.ts +42 -0
  239. package/dist/utility/wrun/wrun-earnings-facts.util.js +131 -0
  240. package/dist/utility/wrun/wrun-first-run-depth.util.d.ts +32 -0
  241. package/dist/utility/wrun/wrun-first-run-depth.util.js +118 -0
  242. package/dist/utility/wrun/wrun-gate-plane-readers.util.d.ts +24 -0
  243. package/dist/utility/wrun/wrun-gate-plane-readers.util.js +31 -0
  244. package/dist/utility/wrun/wrun-held-lanes.util.d.ts +32 -0
  245. package/dist/utility/wrun/wrun-held-lanes.util.js +94 -0
  246. package/dist/utility/wrun/wrun-host-visible-clock.util.d.ts +2 -0
  247. package/dist/utility/wrun/wrun-host-visible-clock.util.js +17 -0
  248. package/dist/utility/wrun/wrun-host.service.d.ts +266 -0
  249. package/dist/utility/wrun/wrun-host.service.js +655 -0
  250. package/dist/utility/wrun/wrun-inert-legend.util.d.ts +33 -0
  251. package/dist/utility/wrun/wrun-inert-legend.util.js +125 -0
  252. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +155 -0
  253. package/dist/utility/wrun/wrun-input-requirements.leaf.js +450 -0
  254. package/dist/utility/wrun/wrun-integration-route.util.d.ts +51 -0
  255. package/dist/utility/wrun/wrun-integration-route.util.js +59 -0
  256. package/dist/utility/wrun/wrun-latest-history.leaf.d.ts +8 -0
  257. package/dist/utility/wrun/wrun-latest-history.leaf.js +8 -0
  258. package/dist/utility/wrun/wrun-legend-hover.lazy.d.ts +12 -0
  259. package/dist/utility/wrun/wrun-legend-hover.lazy.js +96 -0
  260. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +21 -0
  261. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +21 -0
  262. package/dist/utility/wrun/wrun-live-hidden-hold.util.d.ts +23 -0
  263. package/dist/utility/wrun/wrun-live-hidden-hold.util.js +13 -0
  264. package/dist/utility/wrun/wrun-live-intake.util.d.ts +374 -0
  265. package/dist/utility/wrun/wrun-live-intake.util.js +2027 -0
  266. package/dist/utility/wrun/wrun-live-patch.util.d.ts +116 -0
  267. package/dist/utility/wrun/wrun-live-patch.util.js +523 -0
  268. package/dist/utility/wrun/wrun-live-tick.util.d.ts +619 -0
  269. package/dist/utility/wrun/wrun-live-tick.util.js +4974 -0
  270. package/dist/utility/wrun/wrun-loading-owner.util.d.ts +58 -0
  271. package/dist/utility/wrun/wrun-loading-owner.util.js +89 -0
  272. package/dist/utility/wrun/wrun-official-scope.leaf.d.ts +29 -0
  273. package/dist/utility/wrun/wrun-official-scope.leaf.js +36 -0
  274. package/dist/utility/wrun/wrun-oi-lane.util.d.ts +27 -0
  275. package/dist/utility/wrun/wrun-oi-lane.util.js +42 -0
  276. package/dist/utility/wrun/wrun-opra-stats.leaf.d.ts +29 -10
  277. package/dist/utility/wrun/wrun-opra-stats.leaf.js +29 -10
  278. package/dist/utility/wrun/wrun-options-stop.util.d.ts +52 -0
  279. package/dist/utility/wrun/wrun-options-stop.util.js +123 -0
  280. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +719 -0
  281. package/dist/utility/wrun/wrun-overlay-drivers.util.js +1180 -0
  282. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +50 -0
  283. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +131 -0
  284. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +118 -0
  285. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +466 -0
  286. package/dist/utility/wrun/wrun-overlay-metadata.util.d.ts +45 -0
  287. package/dist/utility/wrun/wrun-overlay-metadata.util.js +112 -0
  288. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +114 -0
  289. package/dist/utility/wrun/wrun-overlay-recovery.util.js +971 -0
  290. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +858 -0
  291. package/dist/utility/wrun/wrun-overlay-run.util.js +11013 -0
  292. package/dist/utility/wrun/wrun-panel-mount.lazy.d.ts +10 -0
  293. package/dist/utility/wrun/wrun-panel-mount.lazy.js +68 -0
  294. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +392 -0
  295. package/dist/utility/wrun/wrun-panel-mount.util.js +2346 -0
  296. package/dist/utility/wrun/wrun-param-map.util.d.ts +19 -4
  297. package/dist/utility/wrun/wrun-param-map.util.js +40 -47
  298. package/dist/utility/wrun/wrun-param-values.util.d.ts +9 -3
  299. package/dist/utility/wrun/wrun-param-values.util.js +5 -5
  300. package/dist/utility/wrun/wrun-pause-dim.util.d.ts +52 -0
  301. package/dist/utility/wrun/wrun-pause-dim.util.js +153 -0
  302. package/dist/utility/wrun/wrun-plot-gate.types.d.ts +23 -0
  303. package/dist/utility/wrun/wrun-plot-gate.types.js +7 -0
  304. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +93 -0
  305. package/dist/utility/wrun/wrun-prefix-cohort.util.js +484 -0
  306. package/dist/utility/wrun/wrun-prefix-lanes.util.d.ts +114 -0
  307. package/dist/utility/wrun/wrun-prefix-lanes.util.js +486 -0
  308. package/dist/utility/wrun/wrun-prefix-proof.util.d.ts +317 -0
  309. package/dist/utility/wrun/wrun-prefix-proof.util.js +630 -0
  310. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +73 -0
  311. package/dist/utility/wrun/wrun-refusal-surface.util.js +380 -0
  312. package/dist/utility/wrun/wrun-refusal-text.util.d.ts +15 -0
  313. package/dist/utility/wrun/wrun-refusal-text.util.js +40 -0
  314. package/dist/utility/wrun/wrun-replay-lane.util.d.ts +139 -0
  315. package/dist/utility/wrun/wrun-replay-lane.util.js +520 -0
  316. package/dist/utility/wrun/wrun-replay-rows.util.d.ts +21 -0
  317. package/dist/utility/wrun/wrun-replay-rows.util.js +172 -0
  318. package/dist/utility/wrun/wrun-row-source-factory.d.ts +53 -0
  319. package/dist/utility/wrun/wrun-row-source-factory.js +435 -0
  320. package/dist/utility/wrun/wrun-run-cells.util.d.ts +36 -0
  321. package/dist/utility/wrun/wrun-run-cells.util.js +46 -0
  322. package/dist/utility/wrun/wrun-run-interval-projection.types.d.ts +14 -0
  323. package/dist/utility/wrun/wrun-run-interval-projection.types.js +1 -0
  324. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +133 -0
  325. package/dist/utility/wrun/wrun-run-interval-session.util.js +121 -0
  326. package/dist/utility/wrun/wrun-run-interval.util.d.ts +98 -0
  327. package/dist/utility/wrun/wrun-run-interval.util.js +207 -0
  328. package/dist/utility/wrun/wrun-run-retained.util.d.ts +122 -0
  329. package/dist/utility/wrun/wrun-run-retained.util.js +255 -0
  330. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +184 -0
  331. package/dist/utility/wrun/wrun-sandbox-row-source.js +444 -0
  332. package/dist/utility/wrun/wrun-script-inputs.util.js +4 -4
  333. package/dist/utility/wrun/wrun-series-stream.util.d.ts +86 -0
  334. package/dist/utility/wrun/wrun-series-stream.util.js +537 -0
  335. package/dist/utility/wrun/wrun-sheet-remembered.util.d.ts +21 -0
  336. package/dist/utility/wrun/wrun-sheet-remembered.util.js +36 -0
  337. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.d.ts +7 -0
  338. package/dist/utility/wrun/wrun-signal-sound-reasons.leaf.js +12 -0
  339. package/dist/utility/wrun/wrun-socket-row-source.js +4 -2
  340. package/dist/utility/wrun/wrun-source-rows.util.d.ts +175 -3
  341. package/dist/utility/wrun/wrun-source-rows.util.js +294 -8
  342. package/dist/utility/wrun/wrun-stats-strip.util.d.ts +46 -0
  343. package/dist/utility/wrun/wrun-stats-strip.util.js +87 -0
  344. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +163 -0
  345. package/dist/utility/wrun/wrun-table-chrome.util.js +557 -0
  346. package/dist/utility/wrun/wrun-text-params.util.d.ts +11 -6
  347. package/dist/utility/wrun/wrun-text-params.util.js +19 -30
  348. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +64 -0
  349. package/dist/utility/wrun/wrun-transient-rerun.util.js +317 -0
  350. package/dist/utility/wrun/wrun-twin-lookback.util.d.ts +10 -0
  351. package/dist/utility/wrun/wrun-twin-lookback.util.js +43 -0
  352. package/dist/utility/wrun/wrun-warmup-head-store.util.d.ts +41 -0
  353. package/dist/utility/wrun/wrun-warmup-head-store.util.js +120 -0
  354. package/dist/utility/wrun-alert-params.leaf.d.ts +24 -0
  355. package/dist/utility/wrun-alert-params.leaf.js +24 -0
  356. package/dist/utils/replay/replay-buffer-math.d.ts +148 -0
  357. package/dist/utils/replay/replay-buffer-math.js +684 -0
  358. package/dist/workers/wrun/wrun-abi-host.d.ts +190 -0
  359. package/dist/workers/wrun/wrun-abi-host.js +1201 -0
  360. package/dist/workers/wrun/wrun-engine-handler.d.ts +37 -0
  361. package/dist/workers/wrun/wrun-engine-handler.js +211 -0
  362. package/package.json +3 -3
@@ -0,0 +1,926 @@
1
+ import { Intervals } from '../../constants/interval.constants.js';
2
+ import { serverNowMs } from '../auth/server-clock.util.js';
3
+ import { barEndMs, barStartMs, isCalendarIntervalMs } from './calendar-interval.util.js';
4
+ export const BARS_PER_BUCKET = 250;
5
+ export const BARS_PER_PIECE = 50;
6
+ const MIN_PERIOD_SECONDS = 60;
7
+ /**
8
+ * Returns the server's current time truncated to the second to avoid future requests
9
+ */
10
+ function getSafeNowUpperBound() {
11
+ return Math.floor(serverNowMs() / 1000) * 1000;
12
+ }
13
+ /**
14
+ * Aligns a timestamp to bucket boundaries for cache optimization
15
+ */
16
+ export function alignTimestampToBucket(timestampMs, intervalMs, direction = 'floor') {
17
+ const bucketSize = BARS_PER_BUCKET * intervalMs;
18
+ const result = direction === 'floor'
19
+ ? Math.floor(timestampMs / bucketSize) * bucketSize
20
+ : Math.ceil(timestampMs / bucketSize) * bucketSize;
21
+ return Math.round(result);
22
+ }
23
+ /**
24
+ * Complete-bucket stamps for a fetched window (data-loading plan A51): the
25
+ * canonical 250-bar bucket starts (unix SECONDS, the same grid
26
+ * getOptimizedFetchParams cuts on) that lie FULLY inside
27
+ * [fromSec, fromSec + periodSec) and whose bucket end is at or before
28
+ * `nowMs` (the server's now). The floating latest window (fromSec === 0) is never stamped: its
29
+ * absolute span is decided at the worker and it always ends on the forming
30
+ * bar. A partially covered bucket is never stamped; the caller writes the
31
+ * result only from a complete, non-aborted terminal.
32
+ */
33
+ export function completeBucketStartsForWindow(fromSec, periodSec, intervalMs, nowMs = serverNowMs()) {
34
+ if (!(fromSec > 0) || !(periodSec > 0) || !(intervalMs > 0))
35
+ return [];
36
+ const bucketSec = (BARS_PER_BUCKET * intervalMs) / 1000;
37
+ if (!(bucketSec > 0))
38
+ return [];
39
+ const windowEndSec = fromSec + periodSec;
40
+ const nowSec = Math.floor(nowMs / 1000);
41
+ const firstStart = Math.ceil(fromSec / bucketSec) * bucketSec;
42
+ const out = [];
43
+ for (let start = firstStart; start + bucketSec <= windowEndSec; start += bucketSec) {
44
+ if (start + bucketSec > nowSec)
45
+ break;
46
+ out.push(Math.round(start));
47
+ }
48
+ return out;
49
+ }
50
+ /**
51
+ * The wire frontier span one complete terminal earns for its asked window
52
+ * (fix 2 of the indicator re-fetch investigation, 2026-09-28): the window
53
+ * from its start through the open of the first bar it does NOT confirm, on
54
+ * the interval grid. The end is the earlier of the window's end and `nowMs`,
55
+ * floored to the grid: a window that reaches into the bar forming at `nowMs`
56
+ * confirms only the bars closed before it, so the forming bar never advances
57
+ * the frontier, and a window that ends inside a closed bar confirms only the
58
+ * bars before that one. Null for the floating latest window (`fromSec` 0:
59
+ * its absolute span is decided at the worker) and for a window that holds no
60
+ * whole bar. Seconds in, milliseconds out (the entry's own units). Calendar
61
+ * bars (1M 3M 6M 1Y) floor and close on their calendar boundaries: on the
62
+ * average-month grid October 6 floors to October 1 22:30Z, after the October
63
+ * open, and the forming month read as confirmed.
64
+ */
65
+ export function wireFrontierSpanForWindow(fromSec, periodSec, intervalMs, nowMs) {
66
+ if (!(fromSec > 0) || !(periodSec > 0) || !(intervalMs > 0) || !Number.isFinite(nowMs))
67
+ return null;
68
+ const fromMs = fromSec * 1000;
69
+ const endMs = Math.min((fromSec + periodSec) * 1000, nowMs);
70
+ const throughMs = barStartMs(endMs, intervalMs);
71
+ const fromBarMs = barStartMs(fromMs, intervalMs);
72
+ const firstBarMs = fromBarMs === fromMs ? fromMs : barEndMs(fromBarMs, intervalMs);
73
+ return barEndMs(firstBarMs, intervalMs) <= throughMs ? { fromMs, throughMs } : null;
74
+ }
75
+ /**
76
+ * The part of a planned window the wire was actually asked for (plan A51):
77
+ * a control's request payload may narrow the planned [fromSec, fromSec +
78
+ * periodSec) window (the book controls trim to the OB replay cap through
79
+ * applyObReplayCap, so nothing after the last 3-minute boundary is asked), and
80
+ * a complete-bucket stamp must never cover a tail that was never asked.
81
+ * A payload without a numeric absolute `from`/`period` (index-mode arrays,
82
+ * controls that carry no window) is taken to have asked the planned window;
83
+ * a floating payload (`from` 0) has no absolute span and returns null; a
84
+ * payload disjoint from the plan returns null. Seconds throughout.
85
+ */
86
+ export function askedWindowWithinPlanned(fromSec, periodSec, payload) {
87
+ if (!(fromSec > 0) || !(periodSec > 0))
88
+ return null;
89
+ const asked = payload && typeof payload === 'object' && !Array.isArray(payload)
90
+ ? payload
91
+ : null;
92
+ const askedFrom = typeof asked?.from === 'number' && Number.isFinite(asked.from) ? asked.from : null;
93
+ const askedPeriod = typeof asked?.period === 'number' && Number.isFinite(asked.period) ? asked.period : null;
94
+ if (askedFrom === null || askedPeriod === null)
95
+ return { fromSec, periodSec };
96
+ if (!(askedFrom > 0) || !(askedPeriod > 0))
97
+ return null;
98
+ const start = Math.max(fromSec, askedFrom);
99
+ const end = Math.min(fromSec + periodSec, askedFrom + askedPeriod);
100
+ if (!(end - start > 0))
101
+ return null;
102
+ return { fromSec: start, periodSec: end - start };
103
+ }
104
+ /**
105
+ * Calculates aligned time range for data fetching with cache optimization
106
+ *
107
+ * @param from - Start timestamp in seconds (0 means latest window)
108
+ * @param period - Time period in seconds
109
+ * @param interval - Chart interval ('1m', '5m', '1h', '1d', etc.)
110
+ * @returns Array of aligned timestamps ensuring valid integer values
111
+ *
112
+ * Remark:
113
+ * - Bucket: Large immutable data, always fetch for buckets in lazy load
114
+ * - Piece: Small immutable data, only fetch in first load. This is because data cache would have a short TTL if we fetch until now. Piece serves as a small cache before a bucket is formed.
115
+ * - Remnant: Small mutable data with short TTL, only fetch in first load.
116
+ */
117
+ export function getOptimizedFetchParams(from, period, interval) {
118
+ const intervalMs = Intervals.map_unit[interval];
119
+ const bucketSize = (BARS_PER_BUCKET * intervalMs) / 1000;
120
+ const pieceSize = (BARS_PER_PIECE * intervalMs) / 1000;
121
+ const isBucket = from % bucketSize === 0 && period === bucketSize;
122
+ // An already-canonical window leaves as ONE request. The floating latest
123
+ // window (from === 0) always does: the boot lanes (hoist, early dispatch)
124
+ // key their stand-down on that single-request plan. An ABSOLUTE
125
+ // piece-aligned window only skips the split while it fits in one bucket: a
126
+ // wider one (a lazy wave that coalesced several 250-bar rounds) falls
127
+ // through and fans out into buckets below, so every chunk is a stable key
128
+ // on the backend grid and on the bucket caches, which refuse anything over
129
+ // BARS_PER_BUCKET and would otherwise never persist the range.
130
+ const isPiece = from % pieceSize === 0 && period % pieceSize === 0 && (from === 0 || period <= bucketSize);
131
+ const isRemnant = from % pieceSize === 0 && period % pieceSize !== 0 && period < pieceSize;
132
+ if (isBucket || isPiece || isRemnant) {
133
+ return [
134
+ {
135
+ from,
136
+ period,
137
+ },
138
+ ];
139
+ }
140
+ const safeNow = getSafeNowUpperBound();
141
+ // Calculate time range in milliseconds
142
+ // Interpret from=0 as "latest window ending at safeNow"
143
+ const fromMs = from === 0 ? Math.max(0, safeNow - period * 1000) : from * 1000;
144
+ // Never let the end exceed the safeNow truncation
145
+ const toMs = Math.min(fromMs + period * 1000, safeNow);
146
+ // Align to bucket boundaries for cache efficiency
147
+ const alignedFromMs = alignTimestampToBucket(fromMs, intervalMs, 'floor');
148
+ const alignedToMs = Math.min(alignTimestampToBucket(toMs, intervalMs, 'ceil'), safeNow);
149
+ // Calculate period with safeguards against invalid values
150
+ const calculatedPeriod = (alignedToMs - alignedFromMs) / 1000;
151
+ const minPeriod = Math.max(MIN_PERIOD_SECONDS, Math.ceil(intervalMs / 1000)); // Minimum period should be at least 1 interval or 60 seconds
152
+ // Ensure valid integer period to prevent backend parsing errors
153
+ from = Math.floor(alignedFromMs / 1000);
154
+ period = calculatedPeriod < minPeriod ? minPeriod : Math.round(calculatedPeriod);
155
+ // Format response into an array of from & period
156
+ const res = [];
157
+ while (period > 0) {
158
+ let targetPeriod;
159
+ if (period > bucketSize) {
160
+ targetPeriod = bucketSize;
161
+ }
162
+ else if (period > pieceSize) {
163
+ targetPeriod = period - (period % pieceSize);
164
+ }
165
+ else {
166
+ targetPeriod = period;
167
+ }
168
+ res.push({
169
+ from,
170
+ period: targetPeriod,
171
+ });
172
+ from += targetPeriod;
173
+ period -= targetPeriod;
174
+ }
175
+ res.sort((a, b) => b.from - a.from); // Sort in descending order to fetch from latest to oldest
176
+ return res;
177
+ }
178
+ // An economic series' window at its calendar intervals: about a dozen bars,
179
+ // never the default 250. Economic builders serve no 6M.
180
+ const ECONOMIC_CALENDAR_WINDOW_SEC = new Map([
181
+ ['1M', 365 * 86_400],
182
+ ['3M', 3 * 365 * 86_400],
183
+ ['1Y', 10 * 365 * 86_400],
184
+ ]);
185
+ /**
186
+ * The main lane's default window (unix seconds) before a preserved span or an
187
+ * armed view widens it: `barsPeriodSec` (bars x interval, the period the boot
188
+ * lanes send as their floating `from: 0` window) back from `nowSec`.
189
+ * - A live market never starts before the epoch: 250 bars of 3M or longer
190
+ * reach before 1970, the gateway reads a start at or below zero as the
191
+ * floating window anyway, and a negative start splits on the bucket grid
192
+ * into overlapping floating asks. Clamped, the window IS the boot lanes'
193
+ * floating window (`from: 0`, the same period), so the two ask alike.
194
+ * - An economic series keeps a signed start (history before 1970) and asks
195
+ * its short window at a calendar interval.
196
+ */
197
+ export function defaultMainWindowSec(input) {
198
+ const periodSec = (input.economic ? ECONOMIC_CALENDAR_WINDOW_SEC.get(input.interval) : undefined) ?? input.barsPeriodSec;
199
+ const fromSec = Math.floor(input.nowSec - periodSec);
200
+ return { fromSec: input.economic ? fromSec : Math.max(0, fromSec), periodSec };
201
+ }
202
+ function pieceFloorSec(sec, pieceSec) {
203
+ return Math.floor(sec / pieceSec) * pieceSec;
204
+ }
205
+ function wholeAsk(window, why) {
206
+ return { kind: 'whole', from: window.fromSec, period: window.periodSec, why };
207
+ }
208
+ function withCommitWindow(ask) {
209
+ if (ask.kind === 'whole' || ask.kind === 'tail-boot')
210
+ return ask;
211
+ return { ...ask, commitWindow: { fromSec: ask.from, toSec: ask.from + ask.period } };
212
+ }
213
+ /**
214
+ * Split `[startSec, endSec)` (at most one bucket wide, `startSec` on the
215
+ * piece grid) into a piece-multiple ask and a remnant, each of which
216
+ * getOptimizedFetchParams leaves as one request. A remnant shorter than one
217
+ * bar or one minute is padded to that floor (the wire clamps to now).
218
+ */
219
+ function tailAsks(startSec, endSec, pieceSec, intervalSec, why) {
220
+ const out = [];
221
+ const span = endSec - startSec;
222
+ if (span <= 0)
223
+ return out;
224
+ const pieces = Math.floor(span / pieceSec);
225
+ if (pieces > 0)
226
+ out.push({ kind: 'piece', from: startSec, period: pieces * pieceSec, why });
227
+ const remnantFrom = startSec + pieces * pieceSec;
228
+ const remnant = endSec - remnantFrom;
229
+ if (remnant > 0) {
230
+ out.push({ kind: 'remnant', from: remnantFrom, period: Math.max(remnant, MIN_PERIOD_SECONDS, intervalSec), why });
231
+ }
232
+ return out;
233
+ }
234
+ /**
235
+ * The miss family's forming tail: from the bucket start to now on the 50-bar
236
+ * grid (the forming bar included), capped at the bucket end, so
237
+ * getOptimizedFetchParams leaves it as ONE request. The wire clamps to now and
238
+ * the gateway keys a window that reaches now under its fresh TTL.
239
+ */
240
+ function formingPieceSec(bucketStartSec, nowSec, pieceSec, bucketSec) {
241
+ return Math.min(bucketSec, (Math.floor((nowSec - bucketStartSec) / pieceSec) + 1) * pieceSec);
242
+ }
243
+ /**
244
+ * The receipts a paint is judged on: the read's coalesced receipts over the
245
+ * mounted rows when the caller hands them over, else the one chain from the
246
+ * first row that a frontier-only caller describes (`[firstTs,
247
+ * wireFrontierTs]`), else none.
248
+ */
249
+ function paintReceipts(paint) {
250
+ if (paint === null)
251
+ return [];
252
+ if (paint.wireReceipts)
253
+ return paint.wireReceipts;
254
+ const { firstTs, wireFrontierTs } = paint;
255
+ return typeof firstTs === 'number' &&
256
+ Number.isFinite(firstTs) &&
257
+ typeof wireFrontierTs === 'number' &&
258
+ Number.isFinite(wireFrontierTs)
259
+ ? [[firstTs, wireFrontierTs]]
260
+ : [];
261
+ }
262
+ /**
263
+ * Whether a receipt covers the paint's last row: one of `wireReceipts` holds
264
+ * it, else (a frontier-only caller) the chain from the first row reaches it.
265
+ */
266
+ function isPaintTailReceipted(paint) {
267
+ const lastTs = paint.lastTs;
268
+ if (typeof lastTs !== 'number' || !Number.isFinite(lastTs))
269
+ return false;
270
+ if (paint.wireReceipts)
271
+ return paint.wireReceipts.some(([fromTs, toTs]) => fromTs <= lastTs && toTs >= lastTs);
272
+ return typeof paint.wireFrontierTs === 'number' && paint.wireFrontierTs >= lastTs;
273
+ }
274
+ /**
275
+ * Heal asks over mounted rows no receipt covers (data-load-receipt-settle,
276
+ * the 2026-10-11 NQ1! report). A row the read mounts or stages that opens
277
+ * before `reachFromSec`, where the demand plan's own asks begin (the bucket
278
+ * holding the window start on the period lane, the window start itself on
279
+ * the dry lane), is never asked by that plan: the reporter's 3m pane painted
280
+ * the 10-09 12:00Z bar from disk on Sunday, outside the 21.9 h window, so
281
+ * neither a reload nor a pan-back asked it again. Each canonical 250-bar
282
+ * bucket holding such a row leaves once more, judged like a closed bucket of
283
+ * the period lane (whole, or from the piece holding the end of the receipt
284
+ * that holds its first bar, `coverEndMs`), never past the piece holding
285
+ * `reachFromSec`; its terminal receipts the rows, so the heal leaves once.
286
+ * Nothing else is added: not a bucket without such a row, not an
287
+ * identity-pending bucket, never the span from the entry to now. The demand
288
+ * window keeps its own lane, the dry lane included: widened back to the
289
+ * oldest such row, a closed session's plan lost the dry lane and sent one
290
+ * bucket per 250 bars from Friday's close to Sunday, all at once (the review
291
+ * of the receipt-settle round). Newest first. Pure; O(rows x receipts).
292
+ */
293
+ function unprovenMountHealAsks(input, receipts, reachFromSec, intervalSec) {
294
+ const rows = input.mountRows;
295
+ const paint = input.paint;
296
+ if (input.receiptSettle !== true ||
297
+ input.revisionProne === true ||
298
+ !rows?.length ||
299
+ !paint ||
300
+ paint.outcome === 'miss' ||
301
+ paint.beltPassed === false) {
302
+ return [];
303
+ }
304
+ const bucketSec = BARS_PER_BUCKET * intervalSec;
305
+ const pieceSec = BARS_PER_PIECE * intervalSec;
306
+ const reachMs = reachFromSec * 1000;
307
+ const buckets = new Set();
308
+ for (const row of rows) {
309
+ const ts = row[0];
310
+ if (typeof ts !== 'number' || !Number.isFinite(ts) || ts >= reachMs)
311
+ continue;
312
+ if (receipts.some(([fromTs, toTs]) => fromTs <= ts && ts <= toTs))
313
+ continue;
314
+ buckets.add(Math.floor(Math.floor(ts / 1000) / bucketSec) * bucketSec);
315
+ }
316
+ const firstTs = paint.firstTs;
317
+ const pending = input.identityPending ?? [];
318
+ const reachPieceEndSec = Math.ceil(reachFromSec / pieceSec) * pieceSec;
319
+ const asks = [];
320
+ for (const b of [...buckets].sort((x, y) => y - x)) {
321
+ const end = Math.min(b + bucketSec, reachPieceEndSec);
322
+ if (pending.some((p) => p.from <= b && end <= p.from + p.period))
323
+ continue;
324
+ // The ONE receipt holding the bucket's first bar (the period lane's rule):
325
+ // the rows it holds are proven, the ask starts at its last piece.
326
+ const cover = typeof firstTs === 'number' && b * 1000 >= firstTs
327
+ ? receipts.find(([from, to]) => from <= b * 1000 && to >= b * 1000)
328
+ : undefined;
329
+ if (cover !== undefined) {
330
+ const start = Math.max(b, pieceFloorSec(Math.floor(cover[1] / 1000), pieceSec));
331
+ asks.push(...tailAsks(start, end, pieceSec, intervalSec, 'not-wire-validated').map((ask) => withCommitWindow({ ...ask, coverEndMs: cover[1] })));
332
+ continue;
333
+ }
334
+ asks.push(withCommitWindow({
335
+ kind: end - b === bucketSec ? 'bucket' : 'piece',
336
+ from: b,
337
+ period: end - b,
338
+ why: 'not-wire-validated',
339
+ }));
340
+ }
341
+ return asks;
342
+ }
343
+ /** The heal's diagnostic field: the bucket starts its asks reach, absent when none leaves. */
344
+ function unprovenMountBucketsOf(heal, intervalSec) {
345
+ if (heal.length === 0)
346
+ return {};
347
+ const bucketSec = BARS_PER_BUCKET * intervalSec;
348
+ return { unprovenMountBuckets: [...new Set(heal.map((ask) => Math.floor(ask.from / bucketSec) * bucketSec))] };
349
+ }
350
+ /**
351
+ * The dry lane's KNOWN FRONTIER (fix-forward S2, the 2026-09-27 CME weekend
352
+ * dump: every 1m visit of a closed NQZ6 pane painted Friday's 250 rows and
353
+ * sent the 14-day walk-back again, 7 s apart). The walk-back exists to FIND
354
+ * the last traded bars; an entry that already holds them needs only the
355
+ * wire's word on the demand window. The tail of the entry (its receipt
356
+ * frontier, else its last row; ms) when all of this holds, else null:
357
+ * - the read is a hit that passed the belt, on a series that is not
358
+ * revision-prone;
359
+ * - the entry reaches the last known trade: no trade is known past its tail
360
+ * bar;
361
+ * - the tail lies before the demand window (rows inside the window are the
362
+ * period lane's case);
363
+ * - the wire answered for the series past that tail through the demand
364
+ * window's start (`paint.tailValidatedThroughMs`, fix-forward U1: the
365
+ * walk-back's newest-rows window, an earlier frontier ask's window). Then
366
+ * the window's answer covers everything since, and an empty reply proves
367
+ * the painted tail is the last trade. The entry's write time proves
368
+ * nothing: a comparison or historical read writes the same entry (Wednesday
369
+ * history written on Sunday), and an empty window over it would leave
370
+ * Wednesday's candles standing as the tail. Without that answer the entry
371
+ * keeps the walk-back, whose reply IS the answer for the next visit.
372
+ * - with `receiptSettle` on, a receipt covers the tail bar itself: an
373
+ * unreceipted tail (Friday's last bar read mid-bar, a live-built close) is
374
+ * asked again once by the walk-back, whose terminal receipts it; parked
375
+ * here, the window ask would never reach a bar older than its start.
376
+ */
377
+ function dryFrontierTailMs(input, intervalMs) {
378
+ const paint = input.paint;
379
+ if (!paint || paint.outcome === 'miss' || paint.beltPassed === false || input.revisionProne === true)
380
+ return null;
381
+ if (input.receiptSettle === true && !isPaintTailReceipted(paint))
382
+ return null;
383
+ const tails = [paint.wireFrontierTs, paint.lastTs].filter((ts) => typeof ts === 'number' && Number.isFinite(ts));
384
+ if (tails.length === 0)
385
+ return null;
386
+ const tailMs = Math.max(...tails);
387
+ const windowFromMs = input.window.fromSec * 1000;
388
+ if (!(tailMs < windowFromMs))
389
+ return null;
390
+ const lastTradeMs = input.dryIdentity?.lastKnownTradeMs;
391
+ if (typeof lastTradeMs !== 'number' || !Number.isFinite(lastTradeMs) || lastTradeMs >= tailMs + intervalMs) {
392
+ return null;
393
+ }
394
+ const throughMs = paint.tailValidatedThroughMs;
395
+ if (typeof throughMs !== 'number' || !Number.isFinite(throughMs))
396
+ return null;
397
+ return throughMs >= windowFromMs ? tailMs : null;
398
+ }
399
+ /**
400
+ * The instant (ms) through which validated windows answer for a series past
401
+ * its tail bar (fix-forward U1): the end of the span that holds the tail bar
402
+ * or starts at the very next bar (a served window past the last row touches
403
+ * it), else null. Pure; the caller gathers the spans (the wire terminals'
404
+ * windows, the coverage PLAN proved, the answered window a cancel keeps).
405
+ */
406
+ export function mainTailValidatedThroughMs(spans, tailMs, intervalMs) {
407
+ if (!Number.isFinite(tailMs) || !(intervalMs > 0))
408
+ return null;
409
+ let through = null;
410
+ for (const span of spans) {
411
+ if (!Number.isFinite(span.fromMs) || !Number.isFinite(span.toMs) || !(span.toMs > span.fromMs))
412
+ continue;
413
+ if (span.fromMs > tailMs + intervalMs || span.toMs <= tailMs)
414
+ continue;
415
+ if (through === null || span.toMs > through)
416
+ through = span.toMs;
417
+ }
418
+ return through;
419
+ }
420
+ /**
421
+ * How far behind its clock a wire answer may end and still count as reaching
422
+ * it (fix-forward X): a served window ends at the clock of its dispatch, and
423
+ * the terminal that judges it lands one round trip later.
424
+ */
425
+ export const MAIN_CLOSED_VERDICT_CLOCK_SLACK_MS = 60_000;
426
+ /**
427
+ * The tail verdict validated coverage earns (fix-forward X, the 2026-09-27
428
+ * 19:35Z dump: a 1h visit of a closed NQZ6 pane asked the span from its
429
+ * frontier to now in two asks, and the served-empty terminal of the first
430
+ * walked back 14 days over it). `spans` is the union of what the wire
431
+ * answered for the series: the terminals of this refetch, the coverage PLAN
432
+ * proved, the answer kept past the tail (the entry's provenance included).
433
+ * `emptySpans` are the windows among them the wire served empty.
434
+ * `servedNowMs` is the clock the wire serves through (the embargo bound on a
435
+ * delayed lane). Null when no span holds the tail. Pure.
436
+ */
437
+ export function resolveMainTailVerdict(input) {
438
+ const throughMs = mainTailValidatedThroughMs(input.spans, input.tailMs, input.intervalMs);
439
+ if (throughMs === null)
440
+ return null;
441
+ const dry = throughMs >= input.tailMs + 2 * input.intervalMs;
442
+ const clockMs = input.servedNowMs - MAIN_CLOSED_VERDICT_CLOCK_SLACK_MS;
443
+ const closed = dry &&
444
+ Number.isFinite(clockMs) &&
445
+ throughMs >= clockMs &&
446
+ input.emptySpans.some((span) => span.toMs > span.fromMs &&
447
+ span.toMs >= clockMs &&
448
+ span.toMs <= throughMs &&
449
+ span.toMs > input.tailMs + input.intervalMs);
450
+ return { tailTs: input.tailMs, throughMs, dry, closed };
451
+ }
452
+ /**
453
+ * A closed verdict still stands (fix-forward X): it was judged on the tail
454
+ * the reader holds, and it is younger than the probe spacing. It expires the
455
+ * way the served-empty probe does: past the spacing the demand window is
456
+ * asked once and its answer records the next verdict. Pure.
457
+ */
458
+ export function isMainClosedVerdictLive(verdict, tailMs, nowMs, spacingMs) {
459
+ if (!verdict || typeof tailMs !== 'number' || verdict.tailTs !== tailMs)
460
+ return false;
461
+ if (!Number.isFinite(verdict.recordedAtMs) || !(verdict.throughMs > tailMs))
462
+ return false;
463
+ const ageMs = nowMs - verdict.recordedAtMs;
464
+ return ageMs >= 0 && ageMs < spacingMs;
465
+ }
466
+ /**
467
+ * The window a closed-venue probe asks (fix-forward Z, the review of Y): the
468
+ * GAP from the instant the tail is validated through (`reachMs`: the closed
469
+ * verdict's reach, else the validated reach) to the clock the wire serves
470
+ * through, so the probe's window touches the coverage it extends and the
471
+ * continuity rule of lane Y holds for it. The poll chain spaces these probes
472
+ * five minutes apart; a 1m chart's 2-bar poll window started minutes past the
473
+ * verdict's reach, every probe was refused as a gap, the entry's validated
474
+ * instant stopped at the last visit and the next re-initialization walked
475
+ * back 14 days once the demand window had slid past it.
476
+ * - The whole gap (fix-forward AB, the review of Z): the caller splits it
477
+ * into bucket-bounded chunks (`splitMainClosedProbeWindow`) and sends them
478
+ * one after the other inside the one cycle, so the reach touches the clock
479
+ * after every probe. Capped at one bucket per probe, a 1s chart fell 50 s
480
+ * further behind on every probe (250 s of bucket against 300 s of spacing)
481
+ * and the verdict never closed again.
482
+ * - The floating 2-bar window (`from: 0`, `pollPeriodSec`) where that window
483
+ * already starts a bar before the reach (a 1h chart's two hours, a 1m probe
484
+ * inside the bar after the reach): its answer overlaps the coverage, so the
485
+ * probe of a held identity leaves on its cadence whether or not widening is
486
+ * needed, and the dry memo and the closed verdict keep refreshing.
487
+ * - Null when nothing is validated past the tail: the caller keeps its own
488
+ * window and its own gates.
489
+ * Pure; unix seconds.
490
+ */
491
+ export function resolveMainClosedProbeWindow(input) {
492
+ const { reachMs, servedNowMs, intervalMs, pollPeriodSec } = input;
493
+ if (typeof reachMs !== 'number' || !Number.isFinite(reachMs) || !Number.isFinite(servedNowMs))
494
+ return null;
495
+ if (!(intervalMs > 0))
496
+ return null;
497
+ const intervalSec = Math.max(1, Math.round(intervalMs / 1000));
498
+ const from = Math.floor(reachMs / 1000);
499
+ const gapSec = Math.ceil(servedNowMs / 1000) - from;
500
+ if (!(from > 0))
501
+ return null;
502
+ if (gapSec <= pollPeriodSec - intervalSec)
503
+ return { from: 0, period: pollPeriodSec };
504
+ return { from, period: Math.max(gapSec, intervalSec, MIN_PERIOD_SECONDS) };
505
+ }
506
+ /**
507
+ * The asks a closed-venue probe window leaves as (fix-forward AB, the review
508
+ * of Z): an absolute window longer than one canonical bucket is split into
509
+ * the fewest contiguous chunks of at most a bucket each, evenly (a gap one
510
+ * second past a bucket is two half-bucket asks, never a bucket and a
511
+ * sliver), the last ending where the window ends. The caller sends them one
512
+ * after the other, the way the split-child pipeline sends chunk children:
513
+ * each chunk's served-empty answer touches the coverage the chunk before it
514
+ * extended, so the continuity rule holds for every one and the verdict
515
+ * reaches the clock inside the cycle. The floating 2-bar window (`from: 0`)
516
+ * and a window without a bar interval leave whole. Pure; unix seconds.
517
+ */
518
+ export function splitMainClosedProbeWindow(window, intervalMs) {
519
+ if (!(window.from > 0) || !(intervalMs > 0) || !(window.period > 0))
520
+ return [window];
521
+ const bucketSec = BARS_PER_BUCKET * Math.max(1, Math.round(intervalMs / 1000));
522
+ const count = Math.ceil(window.period / bucketSec);
523
+ if (count <= 1)
524
+ return [window];
525
+ const chunkSec = Math.ceil(window.period / count);
526
+ const end = window.from + window.period;
527
+ const chunks = [];
528
+ for (let from = window.from; from < end; from += chunkSec) {
529
+ chunks.push({ from, period: Math.min(chunkSec, end - from) });
530
+ }
531
+ return chunks;
532
+ }
533
+ /**
534
+ * The record of a cache key after one more patch landed (fix-forward Z, the
535
+ * review of Y): patches of one tail MERGE, the way the store merges them. Two
536
+ * panes that share a key complete in either order, so a closed verdict that
537
+ * reaches less far than the record (inside the clock slack) is a closure the
538
+ * store took: the record keeps the furthest reach and the newest closure.
539
+ * Dropped whole, the closure stayed unrecorded and every terminal of that
540
+ * verdict wrote the entry again. A patch of another tail replaces the record.
541
+ * Pure.
542
+ */
543
+ export function mergeLandedMainTailVerdict(held, landed) {
544
+ if (!held || held.tailTs !== landed.tailTs)
545
+ return { ...landed };
546
+ const closedAtMs = held.closedAtMs === null || landed.closedAtMs === null
547
+ ? (landed.closedAtMs ?? held.closedAtMs)
548
+ : Math.max(held.closedAtMs, landed.closedAtMs);
549
+ return { tailTs: landed.tailTs, throughMs: Math.max(held.throughMs, landed.throughMs), closedAtMs };
550
+ }
551
+ export function planMainRefetchAsks(input) {
552
+ const { window } = input;
553
+ const none = {
554
+ skippedBuckets: [],
555
+ knownEmptyBuckets: [],
556
+ pendingBuckets: [],
557
+ covers: [],
558
+ };
559
+ if (!input.enabled) {
560
+ return { lane: 'whole', asks: [wholeAsk(window, 'unplanned')], ...none, reason: 'switch-off' };
561
+ }
562
+ const intervalMs = Intervals.map_unit[input.interval];
563
+ if (!(intervalMs > 0) || !(window.periodSec > 0)) {
564
+ return { lane: 'whole', asks: [wholeAsk(window, 'unplanned')], ...none, reason: 'no-interval' };
565
+ }
566
+ const intervalSec = Math.max(1, Math.round(intervalMs / 1000));
567
+ const nowSec = Math.floor(input.nowMs / 1000);
568
+ const paint = input.paint && input.paint.outcome !== 'miss' ? input.paint : null;
569
+ // Count lane (A11): one count ask anchored at now; bucket rules do not apply.
570
+ if (input.indexMode) {
571
+ const lane = input.countLane;
572
+ const cachedLastTs = paint ? (lane?.cachedLastTs ?? paint.lastTs) : undefined;
573
+ if (paint && typeof cachedLastTs === 'number' && Number.isFinite(cachedLastTs)) {
574
+ const barsSince = Math.max(0, Math.floor((input.nowMs - cachedLastTs) / intervalMs));
575
+ const fromSec = Math.floor(cachedLastTs / 1000);
576
+ return {
577
+ lane: 'count',
578
+ asks: [
579
+ {
580
+ kind: 'count',
581
+ from: nowSec,
582
+ period: 0,
583
+ limit: barsSince + 2,
584
+ why: 'forming-tail',
585
+ commitWindow: { fromSec, toSec: nowSec },
586
+ },
587
+ ],
588
+ ...none,
589
+ reason: 'count-hit',
590
+ };
591
+ }
592
+ const todayLimit = lane?.todayLimit ?? 0;
593
+ const cap = Math.max(lane?.numberOfCandles ?? 0, lane?.demandBars ?? 0);
594
+ const limit = cap > 0 ? Math.min(Math.max(todayLimit, 1), cap) : Math.max(todayLimit, 1);
595
+ return {
596
+ lane: 'count',
597
+ asks: [{ kind: 'count', from: nowSec, period: 0, limit, why: 'uncovered-closed-bucket' }],
598
+ ...none,
599
+ reason: 'count-miss',
600
+ };
601
+ }
602
+ // Dry identity (A19/A58, Codex C4): the tail-boot ask directly, for any
603
+ // market kind, one request at minimum; no calendar decides anything here.
604
+ const dry = input.dryIdentity;
605
+ const windowFromMs = window.fromSec * 1000;
606
+ const dryByMemo = Boolean(dry?.servedEmptyHeadLive);
607
+ const dryByTrade = Boolean(dry?.sessionBound &&
608
+ typeof dry.lastKnownTradeMs === 'number' &&
609
+ Number.isFinite(dry.lastKnownTradeMs) &&
610
+ dry.lastKnownTradeMs < windowFromMs);
611
+ if (dryByMemo || dryByTrade) {
612
+ // Probed (fix-forward E): the walk-back on this identity already answered
613
+ // empty inside the probe spacing and no row has landed since (rows clear
614
+ // the memo). This is the wire's verdict, not a calendar's, so the
615
+ // never-zero floor (Codex C4) does not apply: nothing leaves, and the poll
616
+ // chain's 5-minute probe keeps the identity live.
617
+ if (dryByMemo && dry?.probed) {
618
+ return { lane: 'tail-boot', asks: [], ...none, reason: 'dry-probed' };
619
+ }
620
+ // Known frontier (fix-forward S2): the entry holds the last traded tail,
621
+ // so the tail is planned like a warm switch whose window holds no bar:
622
+ // ONE ask of the demand window itself, merged inside it, never the
623
+ // walk-back. While the probe this ask records on a served-empty reply
624
+ // stands and the rows are on screen, nothing leaves.
625
+ const frontierTailMs = dryByTrade && window.fromSec < nowSec ? dryFrontierTailMs(input, intervalMs) : null;
626
+ if (frontierTailMs !== null) {
627
+ if (dry?.probed && input.paint?.onScreen === true) {
628
+ return { lane: 'dry-frontier', asks: [], ...none, reason: 'dry-probed' };
629
+ }
630
+ // Rows older than the window that no receipt covers heal beside it,
631
+ // bounded by the rows (`unprovenMountHealAsks`).
632
+ const heal = unprovenMountHealAsks(input, paintReceipts(paint), window.fromSec, intervalSec);
633
+ return {
634
+ lane: 'dry-frontier',
635
+ asks: [
636
+ {
637
+ kind: 'whole',
638
+ from: window.fromSec,
639
+ period: window.periodSec,
640
+ why: 'forming-tail',
641
+ commitWindow: { fromSec: window.fromSec, toSec: window.fromSec + window.periodSec },
642
+ verbatim: true,
643
+ },
644
+ ...heal,
645
+ ],
646
+ ...none,
647
+ ...unprovenMountBucketsOf(heal, intervalSec),
648
+ reason: 'dry-last-trade',
649
+ };
650
+ }
651
+ // The receipted-tail rule (receiptSettle) is what kept the lane from
652
+ // parking: named, so a dump tells the re-read of an unsettled tail from a
653
+ // tail never validated past.
654
+ const unreceiptedTail = dryByTrade &&
655
+ window.fromSec < nowSec &&
656
+ input.receiptSettle === true &&
657
+ dryFrontierTailMs({ ...input, receiptSettle: false }, intervalMs) !== null;
658
+ return {
659
+ lane: 'tail-boot',
660
+ asks: [{ kind: 'tail-boot', from: window.fromSec, period: window.periodSec, why: 'dry-identity' }],
661
+ ...none,
662
+ reason: dryByMemo ? 'dry-memo' : unreceiptedTail ? 'dry-tail-unreceipted' : 'dry-last-trade',
663
+ };
664
+ }
665
+ // Period lane: canonical buckets of the window minus what is proven.
666
+ const bucketSec = BARS_PER_BUCKET * intervalSec;
667
+ const pieceSec = BARS_PER_PIECE * intervalSec;
668
+ const windowEndSec = Math.min(window.fromSec + window.periodSec, nowSec);
669
+ if (windowEndSec <= window.fromSec) {
670
+ return { lane: 'whole', asks: [wholeAsk(window, 'not-wire-validated')], ...none, reason: 'window-in-future' };
671
+ }
672
+ // The receipts every bucket is judged on (per-bucket receipts, the
673
+ // 2026-10-02 08:59Z dump): the read's coalesced receipts over the mounted
674
+ // rows when the caller hands them over, else the one chain from the first
675
+ // row that a frontier-only caller describes (`[firstTs, wireFrontierTs]`),
676
+ // which plans exactly as the chain did before.
677
+ const firstRowTs = paint !== null && typeof paint.firstTs === 'number' && Number.isFinite(paint.firstTs) ? paint.firstTs : undefined;
678
+ const receipts = paintReceipts(paint);
679
+ const canSkip = paint !== null &&
680
+ paint.beltPassed !== false &&
681
+ input.revisionProne !== true &&
682
+ firstRowTs !== undefined &&
683
+ receipts.length > 0;
684
+ const firstTs = canSkip ? firstRowTs : undefined;
685
+ const spans = input.knownEmptySpans ?? [];
686
+ const pending = input.identityPending ?? [];
687
+ const asks = [];
688
+ const skippedBuckets = [];
689
+ const knownEmptyBuckets = [];
690
+ const pendingBuckets = [];
691
+ const covers = [];
692
+ let partialBuckets = 0;
693
+ for (let b = Math.floor(window.fromSec / bucketSec) * bucketSec; b < windowEndSec; b += bucketSec) {
694
+ const bEnd = b + bucketSec;
695
+ const lastBarMs = (bEnd - intervalSec) * 1000;
696
+ const bucketHeldFromFirstRow = firstTs !== undefined && b * 1000 >= firstTs;
697
+ // The ONE receipt holding the bucket's first bar: reaching the last bar
698
+ // it proves the bucket whole; ending inside it, it proves the bucket
699
+ // through its end only (a live-built tail, a hole split it). A receipt
700
+ // that starts after the first bar proves nothing about the bucket.
701
+ const cover = canSkip && bucketHeldFromFirstRow ? receipts.find(([from, to]) => from <= b * 1000 && to >= b * 1000) : undefined;
702
+ if (cover !== undefined && cover[1] >= lastBarMs) {
703
+ skippedBuckets.push(b);
704
+ covers.push({ bucket: b, coverEndMs: cover[1], skipped: true });
705
+ continue;
706
+ }
707
+ if (spans.some((s) => s.fromMs <= b * 1000 && bEnd * 1000 <= s.toMs)) {
708
+ knownEmptyBuckets.push(b);
709
+ continue;
710
+ }
711
+ if (pending.some((p) => p.from <= b && bEnd <= p.from + p.period)) {
712
+ pendingBuckets.push(b);
713
+ continue;
714
+ }
715
+ const end = Math.min(bEnd, nowSec);
716
+ if (cover !== undefined) {
717
+ // The receipt ends inside the bucket: re-ask from the start of the
718
+ // piece holding its last validated bar to the bucket's end (or now).
719
+ // Every ask carries the receipt's end: the poison detector compares
720
+ // the re-delivered overlap through it (the chain frontier may lie far
721
+ // before this bucket when the receipt is an island).
722
+ partialBuckets += 1;
723
+ covers.push({ bucket: b, coverEndMs: cover[1], skipped: false });
724
+ const start = Math.max(b, pieceFloorSec(Math.floor(cover[1] / 1000), pieceSec));
725
+ asks.push(...tailAsks(start, end, pieceSec, intervalSec, end >= nowSec ? 'forming-tail' : 'not-wire-validated').map((ask) => ({ ...ask, coverEndMs: cover[1] })));
726
+ continue;
727
+ }
728
+ if (end >= bEnd) {
729
+ asks.push({
730
+ kind: 'bucket',
731
+ from: b,
732
+ period: bucketSec,
733
+ why: paint && bucketHeldFromFirstRow ? 'not-wire-validated' : 'uncovered-closed-bucket',
734
+ });
735
+ continue;
736
+ }
737
+ if (!canSkip) {
738
+ // Nothing wire-validated anywhere (a miss, row 5, or an entry without
739
+ // receipts): the forming bucket is ONE piece to now, never a remnant.
740
+ asks.push({
741
+ kind: 'piece',
742
+ from: b,
743
+ period: formingPieceSec(b, nowSec, pieceSec, bucketSec),
744
+ why: 'forming-tail',
745
+ });
746
+ continue;
747
+ }
748
+ // Receipts, none holding the forming bucket's first bar: piece plus
749
+ // remnant to now.
750
+ asks.push(...tailAsks(b, end, pieceSec, intervalSec, 'forming-tail'));
751
+ }
752
+ const subtracted = skippedBuckets.length + knownEmptyBuckets.length + pendingBuckets.length;
753
+ const beltFailed = paint !== null && paint.beltPassed === false;
754
+ if (subtracted === 0 &&
755
+ partialBuckets === 0 &&
756
+ (input.wholeUnsplit === true || input.revisionProne === true || beltFailed)) {
757
+ // Nothing proven, and the family would not help: the transport sends the
758
+ // whole as one request anyway, the series is revision-prone, or the entry
759
+ // failed the read belt and the replace arm must rewrite it. The whole
760
+ // window leaves as today (the replace arm).
761
+ return {
762
+ lane: 'whole',
763
+ asks: [wholeAsk(window, paint ? 'not-wire-validated' : 'uncovered-closed-bucket')],
764
+ skippedBuckets,
765
+ knownEmptyBuckets,
766
+ pendingBuckets,
767
+ covers,
768
+ reason: paint ? (beltFailed ? 'belt-failed' : 'hit-unsplit') : 'miss-unsplit',
769
+ };
770
+ }
771
+ if (asks.length === 0) {
772
+ // Never zero (Codex C4): a window wholly under known-empty or pending
773
+ // coverage still sends the tail-boot ask, the floor for any identity.
774
+ return {
775
+ lane: 'tail-boot',
776
+ asks: [{ kind: 'tail-boot', from: window.fromSec, period: window.periodSec, why: 'tail-boot' }],
777
+ skippedBuckets,
778
+ knownEmptyBuckets,
779
+ pendingBuckets,
780
+ covers,
781
+ reason: 'all-subtracted',
782
+ };
783
+ }
784
+ asks.sort((a, b) => b.from - a.from);
785
+ // Rows older than the bucket holding the window start that no receipt
786
+ // covers heal after the demand asks, bounded by the rows.
787
+ const heal = unprovenMountHealAsks(input, receipts, Math.floor(window.fromSec / bucketSec) * bucketSec, intervalSec);
788
+ return {
789
+ lane: 'period',
790
+ asks: [...asks.map(withCommitWindow), ...heal],
791
+ skippedBuckets,
792
+ knownEmptyBuckets,
793
+ pendingBuckets,
794
+ covers,
795
+ ...unprovenMountBucketsOf(heal, intervalSec),
796
+ reason: skippedBuckets.length > 0
797
+ ? 'receipt-subtraction'
798
+ : subtracted > 0 || partialBuckets > 0
799
+ ? 'coverage-subtraction'
800
+ : paint
801
+ ? 'hit-without-receipts'
802
+ : 'miss',
803
+ };
804
+ }
805
+ /**
806
+ * The span a staged family mounts (fix-forward lane S1, the 2026-09-27 ETH
807
+ * to BTC production dump): the staged rows' span (first row to last row plus
808
+ * one bar, the row-to-range convention of `mainRowsToFetchRange`) united
809
+ * with the asks the plan sends into them. The family's last terminal mounts
810
+ * exactly this, so the overlay kick base reads it as the span main will
811
+ * mount before any terminal lands; the kicks then cover it and the post-main
812
+ * compare finds nothing to re-ask. A count ask (period 0) adds nothing. Null
813
+ * without staged rows or an interval, or when the rows are not a span.
814
+ */
815
+ export function stagedFamilyMountSpan(stagedRows, asks, intervalMs) {
816
+ if (!stagedRows.length || !(intervalMs > 0))
817
+ return null;
818
+ const firstTs = Number(stagedRows[0]?.[0]);
819
+ const lastTs = Number(stagedRows[stagedRows.length - 1]?.[0]);
820
+ if (!Number.isFinite(firstTs) || !Number.isFinite(lastTs) || lastTs < firstTs)
821
+ return null;
822
+ let from = Math.ceil(firstTs / 1000);
823
+ let end = from + Math.max(1, Math.floor((lastTs - firstTs + intervalMs) / 1000));
824
+ for (const ask of asks) {
825
+ if (!(ask.from > 0) || !(ask.period > 0))
826
+ continue;
827
+ from = Math.min(from, ask.from);
828
+ end = Math.max(end, ask.from + ask.period);
829
+ }
830
+ return end > from ? { from, period: end - from } : null;
831
+ }
832
+ const DEFAULT_VOLUME_EPSILON = 1e-6;
833
+ export function detectMainOverlapPoison(input) {
834
+ const { intervalMs } = input;
835
+ const result = {
836
+ verdict: 'clean',
837
+ compared: 0,
838
+ driftTs: [],
839
+ missingInReply: [],
840
+ missingInMounted: [],
841
+ };
842
+ if (!(intervalMs > 0) || input.mounted.length === 0 || input.reply.length === 0)
843
+ return result;
844
+ const hold = input.freshCloseHoldMs ?? 0;
845
+ const closedBefore = input.nowMs - hold;
846
+ const through = Math.min(input.windowToMs, input.compareThroughMs !== undefined ? input.compareThroughMs + 1 : Infinity);
847
+ const inRange = (ts) => ts >= input.windowFromMs && ts < through && barEndMs(ts, intervalMs) <= closedBefore;
848
+ const mountedByTs = new Map();
849
+ let phase;
850
+ let mixedPhase = false;
851
+ for (const row of input.mounted) {
852
+ const ts = row[0];
853
+ if (!Number.isFinite(ts) || !inRange(ts) || input.skipTs?.has(ts))
854
+ continue;
855
+ mountedByTs.set(ts, row);
856
+ const p = ((ts % intervalMs) + intervalMs) % intervalMs;
857
+ if (phase === undefined)
858
+ phase = p;
859
+ else if (p !== phase)
860
+ mixedPhase = true;
861
+ }
862
+ const replyByTs = new Map();
863
+ for (const row of input.reply) {
864
+ const ts = row[0];
865
+ if (!Number.isFinite(ts) || !inRange(ts) || input.skipTs?.has(ts))
866
+ continue;
867
+ replyByTs.set(ts, row);
868
+ }
869
+ if (mountedByTs.size === 0 || replyByTs.size === 0)
870
+ return result;
871
+ // Calendar bars (1M 3M 6M 1Y) have no fixed phase: every month sits at its
872
+ // own offset on the average-month length, so one mounted row would set a
873
+ // phase every other month fails, and the reply would evict a sound entry.
874
+ if (!mixedPhase && phase !== undefined && !isCalendarIntervalMs(intervalMs)) {
875
+ for (const ts of replyByTs.keys()) {
876
+ if (((ts % intervalMs) + intervalMs) % intervalMs !== phase) {
877
+ return { ...result, verdict: 'evict', reason: 'grid' };
878
+ }
879
+ }
880
+ }
881
+ // The timestamp set is compared inside the span BOTH sides cover.
882
+ const mountedTs = [...mountedByTs.keys()];
883
+ const replyTs = [...replyByTs.keys()];
884
+ const overlapFrom = Math.max(Math.min(...mountedTs), Math.min(...replyTs));
885
+ const overlapTo = Math.min(Math.max(...mountedTs), Math.max(...replyTs));
886
+ for (const ts of mountedTs) {
887
+ if (ts >= overlapFrom && ts <= overlapTo && !replyByTs.has(ts))
888
+ result.missingInReply.push(ts);
889
+ }
890
+ for (const ts of replyTs) {
891
+ if (ts >= overlapFrom && ts <= overlapTo && !mountedByTs.has(ts))
892
+ result.missingInMounted.push(ts);
893
+ }
894
+ if (result.missingInReply.length > 0 || result.missingInMounted.length > 0) {
895
+ return { ...result, verdict: 'evict', reason: 'timestamp-set' };
896
+ }
897
+ const tick = input.tickSize !== undefined && input.tickSize > 0 ? input.tickSize : 0;
898
+ const volumeEpsilon = input.volumeEpsilon ?? DEFAULT_VOLUME_EPSILON;
899
+ const sameValue = (a, b) => {
900
+ if (a === b)
901
+ return true;
902
+ if (!Number.isFinite(a) || !Number.isFinite(b))
903
+ return false;
904
+ return Math.abs(a - b) <= Math.max(tick, Math.abs(b) * 1e-9);
905
+ };
906
+ for (const [ts, held] of mountedByTs) {
907
+ const fresh = replyByTs.get(ts);
908
+ if (!fresh)
909
+ continue;
910
+ result.compared += 1;
911
+ let drift = false;
912
+ for (let i = 1; i <= 4; i++)
913
+ if (!sameValue(Number(held[i]), Number(fresh[i])))
914
+ drift = true;
915
+ const heldVolume = Number(held[5] ?? 0);
916
+ const freshVolume = Number(fresh[5] ?? 0);
917
+ if (Math.abs(heldVolume - freshVolume) > volumeEpsilon * Math.max(Math.abs(heldVolume), Math.abs(freshVolume), 1)) {
918
+ drift = true;
919
+ }
920
+ if (drift)
921
+ result.driftTs.push(ts);
922
+ }
923
+ if (result.driftTs.length > 0)
924
+ result.verdict = 'drift';
925
+ return result;
926
+ }