@orangecharts/wrun-chart-host 0.9.0 → 0.11.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 (252) hide show
  1. package/README.md +2 -0
  2. package/dist/constants/feature-flags.constants.d.ts +15 -1
  3. package/dist/constants/feature-flags.constants.js +130 -24
  4. package/dist/constants/governed-exchanges.constants.d.ts +12 -0
  5. package/dist/constants/governed-exchanges.constants.js +16 -0
  6. package/dist/constants/opra-compliance.constants.d.ts +3 -2
  7. package/dist/constants/opra-compliance.constants.js +3 -2
  8. package/dist/constants/option-venues.constants.d.ts +2 -2
  9. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
  10. package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
  11. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
  12. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
  13. package/dist/constants/venue-presets.constants.d.ts +20 -20
  14. package/dist/constants/venue-presets.constants.js +24 -26
  15. package/dist/host-env.d.ts +21 -5
  16. package/dist/host-env.js +6 -0
  17. package/dist/host-ports.types.d.ts +102 -19
  18. package/dist/index.d.ts +18 -0
  19. package/dist/index.js +18 -0
  20. package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
  21. package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
  22. package/dist/interfaces/cme-realtime.interface.js +6 -3
  23. package/dist/interfaces/kscript-diagnostics.interface.d.ts +12 -0
  24. package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
  25. package/dist/interfaces/prediction-market.interface.d.ts +7 -0
  26. package/dist/interfaces/replay.interface.d.ts +8 -0
  27. package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
  28. package/dist/interfaces/stocks-realtime.interface.js +32 -0
  29. package/dist/interfaces/wrun-runtime.interface.d.ts +18 -2
  30. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +62 -94
  31. package/dist/kscript-data/controls/live-trades-merge.util.js +106 -171
  32. package/dist/market-data/billing.interface.d.ts +174 -36
  33. package/dist/market-data/billing.interface.js +58 -8
  34. package/dist/market-data/venue.d.ts +152 -7
  35. package/dist/market-data/venues/cme.contract.copy.json +66 -0
  36. package/dist/market-data/venues/cme.d.ts +126 -0
  37. package/dist/market-data/venues/cme.js +133 -0
  38. package/dist/market-data/venues/index.d.ts +294 -7
  39. package/dist/market-data/venues/index.js +49 -6
  40. package/dist/market-data/venues/opra.contract.copy.json +3 -2
  41. package/dist/market-data/venues/opra.d.ts +2 -2
  42. package/dist/market-data/venues/opra.js +5 -2
  43. package/dist/market-data/venues/stocks.contract.copy.json +64 -0
  44. package/dist/market-data/venues/stocks.d.ts +130 -0
  45. package/dist/market-data/venues/stocks.js +117 -0
  46. package/dist/settings-templates/footprint-rows.js +35 -2
  47. package/dist/settings-templates/form-rows.d.ts +2 -1
  48. package/dist/settings-templates/index.js +7 -3
  49. package/dist/settings-templates/indicator-fields.d.ts +5 -4
  50. package/dist/settings-templates/indicator-fields.js +79 -10
  51. package/dist/settings-templates/tool-rules.d.ts +32 -15
  52. package/dist/settings-templates/tool-rules.js +33 -11
  53. package/dist/settings-templates/tool-tables.generated.js +95 -31
  54. package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
  55. package/dist/utility/chart/book-live-bucket.util.js +47 -0
  56. package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
  57. package/dist/utility/chart/cme-cache-context.util.js +10 -6
  58. package/dist/utility/chart/cme-realtime.util.js +10 -0
  59. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
  60. package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
  61. package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
  62. package/dist/utility/chart/effective-chart-session.util.js +39 -0
  63. package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
  64. package/dist/utility/chart/host-bar-placement.util.js +170 -30
  65. package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
  66. package/dist/utility/chart/index-host-tier.util.js +7 -2
  67. package/dist/utility/chart/index-mode-admission.util.js +30 -3
  68. package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
  69. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
  70. package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
  71. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +9 -7
  72. package/dist/utility/chart/kscript-live-coalesce.util.js +13 -8
  73. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
  74. package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
  75. package/dist/utility/chart/kscript-provenance-keys.util.js +13 -0
  76. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +5 -1
  77. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
  78. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
  79. package/dist/utility/chart/kscript-venue-policy.util.d.ts +156 -43
  80. package/dist/utility/chart/kscript-venue-policy.util.js +249 -59
  81. package/dist/utility/chart/live-bucket.util.d.ts +24 -8
  82. package/dist/utility/chart/live-bucket.util.js +85 -27
  83. package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
  84. package/dist/utility/chart/market-session-schedule.util.js +16 -0
  85. package/dist/utility/chart/marketKind.util.js +5 -0
  86. package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
  87. package/dist/utility/chart/mixed-mode.util.js +14 -0
  88. package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
  89. package/dist/utility/chart/opra-read-access.leaf.js +5 -3
  90. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
  91. package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
  92. package/dist/utility/chart/rth-session.util.d.ts +12 -10
  93. package/dist/utility/chart/rth-session.util.js +25 -21
  94. package/dist/utility/chart/trading-day.util.d.ts +17 -0
  95. package/dist/utility/chart/trading-day.util.js +59 -0
  96. package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
  97. package/dist/utility/chart/window-geometry.leaf.js +22 -6
  98. package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
  99. package/dist/utility/chart/window-owner.leaf.js +45 -3
  100. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
  101. package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
  102. package/dist/utility/chart/wrun-run-result.util.d.ts +12 -0
  103. package/dist/utility/chart/wrun-run-result.util.js +141 -6
  104. package/dist/utility/intl-locale.util.js +5 -0
  105. package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
  106. package/dist/utility/options/option-bar-anchor.util.js +340 -0
  107. package/dist/utility/options/option-venue.util.d.ts +18 -0
  108. package/dist/utility/options/option-venue.util.js +27 -0
  109. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +4 -0
  110. package/dist/utility/v2/gate-plane.util.d.ts +12 -3
  111. package/dist/utility/v2/gate-plane.util.js +30 -4
  112. package/dist/utility/v2/gate-session-latch.util.js +1 -1
  113. package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
  114. package/dist/utility/v2/stocks-governed.util.js +34 -0
  115. package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
  116. package/dist/utility/wrun/derived-roots.leaf.js +27 -0
  117. package/dist/utility/wrun/derived-roots.util.d.ts +205 -0
  118. package/dist/utility/wrun/derived-roots.util.js +451 -0
  119. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +43 -7
  120. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
  121. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
  122. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
  123. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +4 -2
  124. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +4 -2
  125. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
  126. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
  127. package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
  128. package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
  129. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
  130. package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
  131. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
  132. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +2 -1
  133. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +3 -0
  134. package/dist/utility/wrun/sources/row-lanes/option_prints.js +19 -4
  135. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
  136. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +52 -13
  137. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +88 -19
  138. package/dist/utility/wrun/sources/row-lanes/option_surface.js +2 -1
  139. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
  140. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +24 -9
  141. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +41 -10
  142. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +111 -0
  143. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +133 -0
  144. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +15 -3
  145. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +22 -3
  146. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -0
  147. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +197 -13
  148. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +761 -27
  149. package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
  150. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
  151. package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
  152. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +60 -16
  153. package/dist/utility/wrun/wrun-chart-market-facts.util.js +113 -61
  154. package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
  155. package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
  156. package/dist/utility/wrun/wrun-download-meter.util.d.ts +15 -0
  157. package/dist/utility/wrun/wrun-download-meter.util.js +14 -2
  158. package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
  159. package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
  160. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
  161. package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
  162. package/dist/utility/wrun/wrun-frames.d.ts +27 -6
  163. package/dist/utility/wrun/wrun-frames.js +73 -10
  164. package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
  165. package/dist/utility/wrun/wrun-handles.util.js +9 -8
  166. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
  167. package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
  168. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +18 -4
  169. package/dist/utility/wrun/wrun-hud-looks.util.js +45 -13
  170. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
  171. package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
  172. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
  173. package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
  174. package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
  175. package/dist/utility/wrun/wrun-live-intake.util.d.ts +35 -15
  176. package/dist/utility/wrun/wrun-live-intake.util.js +243 -126
  177. package/dist/utility/wrun/wrun-live-tick.util.d.ts +13 -5
  178. package/dist/utility/wrun/wrun-live-tick.util.js +279 -99
  179. package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
  180. package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
  181. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +60 -11
  182. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +70 -5
  183. package/dist/utility/wrun/wrun-market-size-defaults.util.js +31 -5
  184. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
  185. package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
  186. package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
  187. package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
  188. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
  189. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
  190. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +23 -6
  191. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +47 -11
  192. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +86 -19
  193. package/dist/utility/wrun/wrun-option-strike-flow.util.js +168 -62
  194. package/dist/utility/wrun/wrun-option-views.util.d.ts +323 -28
  195. package/dist/utility/wrun/wrun-option-views.util.js +484 -71
  196. package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
  197. package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
  198. package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
  199. package/dist/utility/wrun/wrun-output-style.util.js +20 -2
  200. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +32 -2
  201. package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
  202. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
  203. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
  204. package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
  205. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +160 -42
  206. package/dist/utility/wrun/wrun-overlay-run.util.js +1244 -209
  207. package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
  208. package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
  209. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
  210. package/dist/utility/wrun/wrun-panel-mount.util.js +114 -19
  211. package/dist/utility/wrun/wrun-panel-style.util.d.ts +10 -9
  212. package/dist/utility/wrun/wrun-panel-style.util.js +58 -9
  213. package/dist/utility/wrun/wrun-param-map.util.d.ts +14 -11
  214. package/dist/utility/wrun/wrun-param-map.util.js +10 -5
  215. package/dist/utility/wrun/wrun-param-values.util.d.ts +14 -4
  216. package/dist/utility/wrun/wrun-param-values.util.js +4 -0
  217. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
  218. package/dist/utility/wrun/wrun-pin-spelling.util.js +39 -14
  219. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
  220. package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
  221. package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
  222. package/dist/utility/wrun/wrun-refusal.util.js +22 -0
  223. package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
  224. package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
  225. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
  226. package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
  227. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
  228. package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
  229. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
  230. package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
  231. package/dist/utility/wrun/wrun-run-interval.util.d.ts +43 -9
  232. package/dist/utility/wrun/wrun-run-interval.util.js +58 -15
  233. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +45 -1
  234. package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
  235. package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
  236. package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
  237. package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
  238. package/dist/utility/wrun/wrun-socket-row-source.js +118 -8
  239. package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -18
  240. package/dist/utility/wrun/wrun-source-rows.util.js +61 -27
  241. package/dist/utility/wrun/wrun-style-words.util.js +6 -4
  242. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
  243. package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
  244. package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
  245. package/dist/utility/wrun/wrun-tape-per-order.util.js +7 -0
  246. package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
  247. package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
  248. package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
  249. package/dist/utils/replay/replay-buffer-math.js +227 -20
  250. package/dist/workers/constants/socket-slots.d.ts +91 -6
  251. package/dist/workers/constants/socket-slots.js +85 -6
  252. package/package.json +5 -5
@@ -1,13 +1,17 @@
1
- import { kScriptSourceAnswerRows } from '../../chart/kscript-source-answer-budget.leaf.js';
1
+ import { KSCRIPT_SOURCE_CELL_BYTES, kScriptSourceAnswerRows } from '../../chart/kscript-source-answer-budget.leaf.js';
2
+ import { wrunChartHostEnv } from '../../../host-env.js';
2
3
  import { wrunRowLaneByKey, wrunRowLaneOfClass, wrunRowLanes } from './row-lane-registry.js';
3
- import { assertWrunLaneChainPlaneReadable, stableJson, wrunChainLaneStop, wrunChartOpraPlane, wrunHostGridAsksWithinHorizon, wrunLaneNoChainRefusal, wrunOpraPlaneStopDetail, wrunPollLaneChainAsk, wrunPollLaneChainExchange, wrunPollLaneChainGovernedExchange, wrunPollLaneChainPlane, resolveWrunOptionSettingKnobs, wrunUnservedLaneInput, } from './wrun-poll-lanes.util.js';
4
+ import { assertWrunLaneChainPlaneReadable, stableJson, wrunChainLaneContext, wrunChainLaneStop, wrunChartOpraPlane, wrunHostGridAsksWithinHorizon, wrunLaneNoChainRefusal, wrunOpraPlaneStopDetail, wrunPollLaneChainAsk, wrunPollLaneChainExchange, wrunPollLaneChainGovernedExchange, wrunPollLaneChainPlane, resolveWrunOptionSettingKnobs, wrunUnservedLaneInput, } from './wrun-poll-lanes.util.js';
4
5
  import { WRUN_ROW_LANE_ID_PREFIX, } from './wrun-row-lane.types.js';
5
6
  import { assertWrunOpraLaneReadable } from '../wrun-opra-lane.util.js';
7
+ import { resolveWrunUnderlyingMarket, resolveWrunUnderlyingSettingKnob, wrunTakesUnderlying, wrunUnderlyingKnob, wrunUnderlyingLaneContext, wrunUnderlyingRootOf, wrunUnderlyingVenueWord, } from '../derived-roots.util.js';
6
8
  import { wrunSheetCellBlockTuples } from '../wrun-cell-capacity.leaf.js';
9
+ import { optionTradeDateClockOf, optionTradeDayByClock, optionTradeDayStartMsByClock, } from '../../options/option-trade-date.util.js';
7
10
  import { WRUN_OPTION_FLOW_TODAY_FIELD, wrunOptionFlowTodayFromOf } from '../wrun-option-contract-flow.util.js';
8
11
  import { wrunOptionInputTupleWidth, wrunOptionKitBarHasRows, wrunOptionLaneCarriesNext, wrunOptionLaneFirstPaintBudget, wrunOptionLaneTupleWidth, } from '../wrun-option-views.util.js';
9
12
  import { wrunPartialMarkerTuple, wrunPresentIsPartial, wrunTuplesMarkedPartial } from '../wrun-present-bits.util.js';
10
13
  import { wrunCellRowsWithPartialBars, wrunHostBarSpanOf, wrunHostGridAsks, wrunHostGridFallbackAsks, wrunLandCellRowsOnHostBars, } from '../wrun-tier-grid.util.js';
14
+ const MINUTE_MS = 60_000;
11
15
  /**
12
16
  * A row lane at the width an input's words or an instance's facets make its block (wrun-option-views.util
13
17
  * `wrunOptionInputTupleWidth`, `wrunOptionLaneTupleWidth`): the lane itself at its class's tuple width; at any other
@@ -111,7 +115,9 @@ function wrunRowLaneUnserved(lane, plane, indexMode, run, ctx) {
111
115
  * 3. the lane's identity, once per lane (the first admitted input's context names a refusal), then the input's
112
116
  * facets (awaited, in declaration order), each knob naming a setting first read as the setting's current value
113
117
  * (`resolveWrunOptionSettingKnobs` over `run.paramValues`), the context carrying the plan's facts beside the chart
114
- * (`WrunRowLanePlanFacts`); the instance is the identity and the facets together. A lane with
118
+ * (`WrunRowLanePlanFacts`); the instance is the identity and the facets together. An input naming another root
119
+ * (contract F's `underlying`, `planWrunRowLaneUnderlying`) is planned against that root's market instead, its
120
+ * identity once per lane and market. A lane with
115
121
  * `acquisitions: 'one'` refuses a second input whose acquisition differs (one fetch, one live fold per package). A
116
122
  * chart with no option chain (an identity or facets refusal seeded `no-options` / `chain`, `wrunLaneNoChainRefusal`:
117
123
  * a LINK perp, a forex pair) does not serve the feed either: the same one rule, its note naming the feed with the
@@ -127,7 +133,7 @@ export async function planWrunRowLanes(metadata, chart, run) {
127
133
  const indexMode = chart.isIndexModeExchange?.(chart.exchange) === true;
128
134
  const cryptoVenue = chart.isCryptoVenueExchange?.(chart.exchange);
129
135
  // The chart's OPRA plane facts, read once, as the poll lanes' planner reads them (`wrunChartOpraPlane`).
130
- const plane = wrunChartOpraPlane(chart.exchange, chart);
136
+ const plane = wrunChartOpraPlane(chart, chart);
131
137
  const params = metadata.params ?? [];
132
138
  const plannedInputs = planWrunRowLaneInputs(metadata);
133
139
  const laneMaxCells = wrunRowLaneMaxCellsByClass(plannedInputs);
@@ -151,7 +157,13 @@ export async function planWrunRowLanes(metadata, chart, run) {
151
157
  laneMaxCells: laneMaxCells.get(lane.sourceClass),
152
158
  params,
153
159
  ...(run?.paramValues !== undefined ? { paramValues: run.paramValues } : {}),
160
+ // A chain lane holds the planner's plane verdict where the run judged the plane, as a chain poll lane does: its
161
+ // chain there is the plane's own by coin, read without the gate.
162
+ ...(lane.chain !== undefined && chart.isOpraPlaneExchange !== undefined ? { opraPlane: plane.onPlane } : {}),
154
163
  };
164
+ // A chain lane reads the run's one options market: a stock twin's stock in place of the chart's
165
+ // (`wrunChainLaneContext`); every other lane, and every chain lane of any other chart, the chart's own context.
166
+ const chainCtx = lane.chain !== undefined ? wrunChainLaneContext(ctx, run?.options) : ctx;
155
167
  const unserved = {
156
168
  inputName: planned.inputName,
157
169
  sourceClass: lane.sourceClass,
@@ -162,7 +174,7 @@ export async function planWrunRowLanes(metadata, chart, run) {
162
174
  // where a known stop keeps them off the plane (`wrunChainLaneStop`, the chain poll lanes' one rule). Any other lane
163
175
  // is admitted by its plane or the chart's mode.
164
176
  const why = lane.chain !== undefined
165
- ? wrunChainLaneStop(plane, run, ctx)
177
+ ? wrunChainLaneStop(plane, run, chainCtx, planned.source.venue)
166
178
  : wrunRowLaneUnserved(lane, plane, indexMode, run, ctx);
167
179
  if (why !== undefined) {
168
180
  wrunUnservedLaneInput(missing, unserved, WRUN_ROW_LANE_UNSERVED_FILLS, why, cryptoVenue);
@@ -170,14 +182,27 @@ export async function planWrunRowLanes(metadata, chart, run) {
170
182
  }
171
183
  let extras;
172
184
  try {
173
- let identity = identities.get(lane.laneKey);
185
+ // Contract F: an input naming another root (`underlying`) is planned against that root's market
186
+ // (`planWrunRowLaneUnderlying`); "auto" (absent too) against the chart's, as every other lane's input.
187
+ const underlying = wrunTakesUnderlying(lane.sourceClass)
188
+ ? await planWrunRowLaneUnderlying(planned.source, chainCtx, run)
189
+ : undefined;
190
+ if (underlying !== undefined && 'why' in underlying) {
191
+ wrunUnservedLaneInput(missing, unserved, WRUN_ROW_LANE_UNSERVED_FILLS, underlying.why, cryptoVenue);
192
+ continue;
193
+ }
194
+ const laneCtx = underlying?.ctx ?? chainCtx;
195
+ const identityKey = underlying === undefined ? lane.laneKey : `${lane.laneKey}|${underlying.key}`;
196
+ let identity = identities.get(identityKey);
174
197
  if (identity === undefined) {
175
- identity = definedFields(await lane.identity?.(ctx));
176
- identities.set(lane.laneKey, identity);
198
+ identity = definedFields(await lane.identity?.(laneCtx));
199
+ identities.set(identityKey, identity);
177
200
  }
178
201
  // A knob naming a setting reads its current value first: a settings change re-plans and re-asks.
179
- const source = resolveWrunOptionSettingKnobs(ctx, planned.source, params, run?.paramValues);
180
- extras = { ...identity, ...definedFields(await lane.facets?.(source, ctx)) };
202
+ const read = resolveWrunOptionSettingKnobs(ctx, planned.source, params, run?.paramValues);
203
+ // A root the chart's own crypto venue lists reads that venue, unless the input declares a venue of its own.
204
+ const source = underlying === undefined ? read : { ...read, venue: wrunUnderlyingVenueWord(read.venue, underlying.market) };
205
+ extras = { ...identity, ...definedFields(await lane.facets?.(source, laneCtx)) };
181
206
  }
182
207
  catch (error) {
183
208
  // A chart with no option chain does not serve the feed (`wrunLaneNoChainRefusal`): the same one rule.
@@ -207,6 +232,41 @@ export async function planWrunRowLanes(metadata, chart, run) {
207
232
  }
208
233
  return { lanes: [...instances.values()], missingFeeds: [...missing.values()] };
209
234
  }
235
+ /**
236
+ * Contract F (SKYLIT-PARITY, derived-roots.util): one input of a lane that takes the `underlying` knob
237
+ * (`option_strikes`) naming another root ("SPX", "derived" for the derived table's default root of the chart's root, a
238
+ * setting picking one, read first: `resolveWrunUnderlyingSettingKnob`) is planned against that root's market, as if the
239
+ * chart were that market (`wrunUnderlyingLaneContext`): the lane's own identity and facets read the root's chain through
240
+ * the one chain resolver, so every venue and book word, wall and refusal of the lane holds, and the instance's
241
+ * acquisition names the root's chain. An OPRA root meets the OPRA wall before any read (`opra-official-only:<class>`),
242
+ * then, kept off the plane by a known stop (the `opra` flag dark), the stop's rule (`wrunUnservedLaneInput`, the chain
243
+ * lanes' own for a stopped chart); a CME root meets the CME display wall before any read too.
244
+ * A root no venue family lists refuses by name (`wrun_underlying_unresolved:<root>`, the no-chain seed). Undefined:
245
+ * "auto" (absent too), the chart's own chain.
246
+ */
247
+ async function planWrunRowLaneUnderlying(source, ctx, run) {
248
+ const read = resolveWrunUnderlyingSettingKnob(ctx, source, ctx.params ?? [], run?.paramValues);
249
+ const root = wrunUnderlyingRootOf(wrunUnderlyingKnob(read, ctx), ctx);
250
+ if (root === undefined)
251
+ return undefined;
252
+ const market = await resolveWrunUnderlyingMarket(root, ctx, run);
253
+ // A CME root's chain is CME options data whatever the chart: the display wall before any read (and after the facets,
254
+ // as for every chain instance). OpenMarket's own packages only, whatever the `cme-user-scripts` gate says (no implied
255
+ // expansion to CME options).
256
+ if (market.family === 'cme')
257
+ assertWrunLaneChainPlaneReadable('cme', market.exchange, run, ctx);
258
+ if (market.family === 'opra') {
259
+ assertWrunOpraLaneReadable(run, ctx);
260
+ if (market.opraStop !== undefined) {
261
+ return { why: { words: wrunOpraPlaneStopDetail(market.opraStop), stop: market.opraStop } };
262
+ }
263
+ }
264
+ return {
265
+ ctx: wrunUnderlyingLaneContext(ctx, market),
266
+ key: `${market.exchange}|${market.symbol}|${market.coin}|${market.venue ?? ''}`,
267
+ market,
268
+ };
269
+ }
210
270
  /** The most `max_cells` among a sheet's planned inputs of each row-lane class (`WrunRowLanePlanFacts.laneMaxCells`). */
211
271
  function wrunRowLaneMaxCellsByClass(planned) {
212
272
  const most = new Map();
@@ -295,6 +355,66 @@ export function wrunRowLaneFetchOptions(lane) {
295
355
  }
296
356
  /** The payload field a tiered ask names its backend tier in (`landing.tiers`, the tier's key). */
297
357
  export const WRUN_ROW_LANE_TIER_FIELD = 'tier';
358
+ /** A row lane's window bounded at a replay cursor (`WrunRowLaneWindow.replayCursorMs`): a flow or snapshot lane's bars
359
+ * opening after the cursor are left out; a `latest` lane (the live row's snapshot), and a window naming no cursor,
360
+ * as they are. */
361
+ export function wrunRowLaneWindowAtReplayCursor(lane, window) {
362
+ const cursor = window.replayCursorMs;
363
+ if (lane.landing.kind === 'latest' || cursor === undefined || !Number.isFinite(cursor))
364
+ return window;
365
+ const barOpens = window.barOpens.filter((stampMs) => stampMs <= cursor);
366
+ return barOpens.length === window.barOpens.length ? window : { ...window, barOpens };
367
+ }
368
+ /** Whether a row lane instance reads per bar (a flow or snapshot landing): the lanes a replay's cursor bounds. */
369
+ function wrunRowLaneReadsPerBar(instance) {
370
+ const lane = wrunRowLaneByKey(instance.laneKey);
371
+ return lane !== undefined && lane.landing.kind !== 'latest';
372
+ }
373
+ /**
374
+ * The row lane instances a replay run reads through its cursor (`wrunRowLaneWindowAtReplayCursor`: the flow and snapshot
375
+ * lanes), by key: the session's coverage of each is the cursor, never the replay window's end its other lanes reach, so
376
+ * each replay step extends them (`wrunReplayRowLaneExtensions`) and the replay record keeps naming the window's end.
377
+ */
378
+ export function wrunRowLanesReplayBounded(instances) {
379
+ return new Set((instances ?? []).filter(wrunRowLaneReadsPerBar).map((instance) => instance.key));
380
+ }
381
+ /**
382
+ * What a replay step owes a session's row lanes before it computes the bars it reveals (SKYLIT-PARITY L6a): each flow
383
+ * or snapshot lane covered short of the step's cursor (`coveredThroughTs`, the newest bar its buffer holds), from the
384
+ * bar after its coverage (`fromTs`) through the cursor. A lane holding no coverage (the run degraded it) is left to its
385
+ * degrade, and a `latest` lane to its live-row snapshot.
386
+ */
387
+ export function wrunReplayRowLaneExtensions(instances, coveredThroughTs, cursorMs) {
388
+ if (!Number.isFinite(cursorMs))
389
+ return [];
390
+ const owed = [];
391
+ for (const instance of instances ?? []) {
392
+ if (!wrunRowLaneReadsPerBar(instance))
393
+ continue;
394
+ const covered = coveredThroughTs[instance.key];
395
+ if (typeof covered !== 'number' || !Number.isFinite(covered) || covered >= cursorMs)
396
+ continue;
397
+ owed.push({ key: instance.key, fromTs: covered + 1 });
398
+ }
399
+ return owed;
400
+ }
401
+ /** A replay step's answer merged into a row lane's held rows: one row per bar, ascending, the answer's row in place of
402
+ * a held one of the same bar (a replay holds no live-folded row an answer could lose). */
403
+ export function mergeWrunReplayRowLaneRows(held, answer) {
404
+ const byBar = new Map();
405
+ for (const rows of [held ?? [], answer]) {
406
+ for (const row of rows) {
407
+ const ts = Number(row[0]);
408
+ if (Number.isFinite(ts))
409
+ byBar.set(ts, row);
410
+ }
411
+ }
412
+ return [...byBar.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
413
+ }
414
+ /** The add a row lane read belongs to (`WrunRowLaneFetchOptions.addMemo`): the chart, the indicator, the instance. */
415
+ export function wrunRowLaneAddKey(chartIndex, indicatorId, instanceKey) {
416
+ return `${chartIndex}|${indicatorId}|${instanceKey}`;
417
+ }
298
418
  /**
299
419
  * A row lane's rows over a chart window `[barOpens[0], last bar's end)`: a flow or snapshot lane's asks under the
300
420
  * tier rule and the lane's `tierChoice` (one per run of bars on a tier, the tier's key as `tier` in the ask's
@@ -316,11 +436,35 @@ export const WRUN_ROW_LANE_TIER_FIELD = 'tier';
316
436
  * still out a macrotask later: the slice's rows, every older bar the projection reads rows for read partial
317
437
  * (wrun-row-lane-first-paint.util `wrunRowLaneFirstSliceHeldBars`), and the slice's first bar. Never when no cut falls
318
438
  * on a session's first bar (a session longer than the slice: the plain split, asked as today), for a block with no
319
- * `present` mask (it cannot read a bar as partial), a kit fold carrying the next bar (its pages ask one at a time), or
320
- * a snapshot whose empty bars ask a coarser tier (that pass would ask the slice's bars again).
439
+ * `present` mask (it cannot read a bar as partial), a kit fold carrying the next bar (its pages ask one at a time),
440
+ * Strike Footprint's per-(expiry, strike) rows (it learns its strike step over the whole run:
441
+ * wrun-row-lane-first-paint.util `wrunRowLaneDrawsFirstSlice`), or a snapshot whose empty bars ask a coarser tier (that
442
+ * pass would ask the slice's bars again).
443
+ *
444
+ * A row budget that leaves asked bars partial says so before any ask leaves (`opts.onBudgetCut`, and the debug ring).
445
+ *
446
+ * `opts.download` (a budgeted run, OPTLOAD W3 R2; `landWithinDownloadShare`): after the tier rule, the horizon and the
447
+ * row budget (the smaller cut wins), the read asks its newest slice first and alone, then the newest older bars its
448
+ * share fits by the slice's own wire bytes, and no others; every bar it leaves unasked reads partial (bit 14 with the
449
+ * marker tuple; an empty block on a class with no `present` mask), and the cut is named once the asks landed
450
+ * (`onBudgetCut`, `budget: 'download'`). No early handover in that mode. Absent: the plan's asks, over the bars the
451
+ * add's memo does not hold (`opts.addMemo`).
452
+ *
453
+ * A replay's window (`window.replayCursorMs`, plan L6a): a flow or snapshot lane's bars end at the replay's cursor
454
+ * (`wrunRowLaneWindowAtReplayCursor`), so nothing after it is asked, and the read keeps a replay memo (the add memo's
455
+ * machinery, `role: 'replay'`, never the add's own): a replay step's read of the bars it reveals
456
+ * (wrun-live-tick.util, `wrunReplayRowLaneExtensions`) and a reopened run reuse the bars landed whole and final and
457
+ * ask the rest. A read that names no cursor asks exactly as before.
458
+ *
459
+ * `ask` reports its answer's completion through its fourth argument (`whole`: the chart's fetch verdict,
460
+ * wrun-source-rows.util `wrunSourceVerdictWhole`); an ask that never reports is not whole. A memo admits a bar only from
461
+ * an ask reported whole, and the bars of every other ask are named to the caller (`opts.onUnconfirmed`), so a synthetic
462
+ * completion's empty or short answer is asked again, never remembered as the bar.
321
463
  */
322
- export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask, opts = {}) {
464
+ export async function fetchWrunRowLaneRows(lane, extras, askedWindow, fallback, ask, opts = {}) {
323
465
  const landing = lane.landing;
466
+ // A replay run's per-bar lane ends at the replay's cursor: no bar after it is asked.
467
+ const window = wrunRowLaneWindowAtReplayCursor(lane, askedWindow);
324
468
  // The instance's rows are its facets' (a strike kit fold's 14-value rows), read as plain tuples once landed; at
325
469
  // another width than the class's they carry no `present` mask (`wrunRowLaneAtWidth`).
326
470
  const sized = wrunRowLaneAtWidth(lane, wrunOptionLaneTupleWidth(lane.sourceClass, extras, lane.width));
@@ -332,48 +476,167 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask,
332
476
  // What the row budget and the first-paint slice project the window's bars under: the instance's payload with
333
477
  // `history` "today" dated off the window's newest bar as each ask's K control dates it (`wrunRowLaneBudgetAcquisition`).
334
478
  const budgetAcquisition = await wrunRowLaneBudgetAcquisition(lane, extras, window);
335
- const { asks, partialBars } = wrunRowLaneAsksWithinRowBudget(wrunRowLaneAsksWithinHorizon(wrunHostGridAsks({
479
+ const withinHorizon = wrunRowLaneAsksWithinHorizon(wrunHostGridAsks({
336
480
  tiers: landing.tiers,
337
481
  barOpens: window.barOpens,
338
482
  intervalMs: window.intervalMs,
339
483
  nowMs: window.nowMs,
340
484
  choice: landing.tierChoice,
341
485
  sessionGrid,
342
- }), window, lane.horizon?.(extras, window.nowMs), sessionGrid), window, lane.rowBudget, budgetAcquisition, sessionGrid);
486
+ }), window, lane.horizon?.(extras, window.nowMs), sessionGrid);
487
+ // Every projection of this read, the budget's and the first paint's, at least what the lane's reads measured.
488
+ const rowBudget = lane.rowBudget === undefined ? undefined : wrunRowLaneMeasuredBudget(lane, lane.rowBudget, extras);
489
+ const budgeted = wrunRowLaneAsksWithinRowBudget(withinHorizon, window, rowBudget, budgetAcquisition, sessionGrid);
490
+ const { asks, partialBars } = budgeted;
491
+ // The budget hands back the plan it was given unless it cut bars out of it.
492
+ if (budgeted !== withinHorizon && lane.rowBudget !== undefined) {
493
+ const cut = wrunRowLaneBudgetCutOf(lane.laneKey, lane.rowBudget, withinHorizon, budgeted, window, sessionGrid);
494
+ reportWrunRowLaneBudgetCut(cut, window.intervalMs, opts.onBudgetCut);
495
+ }
496
+ // One record per add (`opts.addMemo`, wrun-row-lane-add-memo.util): the bars a read of this add already landed whole
497
+ // and final are reused and only the rest is asked, whether or not a budget applies; the bars a budgeted read cut stay
498
+ // partial. A replay's read keeps its own memo, never the add's, so a later read at its cursor asks only the bars it
499
+ // lacks. When a bar's row is final is the acquisition's (`wrunRowLaneRowDependencyOf`): one whose rows no bar's clock
500
+ // settles keeps no memo at all.
501
+ const dependency = wrunRowLaneRowDependencyOf(lane, extras);
502
+ const memoDependency = dependency.kind === 'never' ? undefined : dependency;
503
+ const addMemo = memoDependency === undefined
504
+ ? undefined
505
+ : window.replayCursorMs !== undefined && Number.isFinite(window.replayCursorMs)
506
+ ? { key: `replay|${wrunRowLaneAddFingerprintOf(lane, extras, window)}`, role: 'replay' }
507
+ : opts.addMemo;
508
+ const memoUtil = addMemo === undefined ? undefined : await import('./wrun-row-lane-add-memo.util.js');
509
+ const memoFingerprint = addMemo === undefined ? '' : wrunRowLaneAddFingerprintOf(lane, extras, window);
510
+ const held = memoUtil === undefined || addMemo === undefined
511
+ ? undefined
512
+ : memoUtil.wrunRowLaneAddMemoOf(addMemo.key, memoFingerprint);
513
+ // A whole run (no `download`: its plan fits the budget, or the cut is off) still reuses the add's landed bars; it
514
+ // asks the bars a budgeted read cut and owes the budget nothing.
515
+ const memo = held !== undefined && memoUtil !== undefined && addMemo?.role === 'run' && opts.download === undefined
516
+ ? memoUtil.wrunRowLaneAddMemoWhole(held)
517
+ : held;
518
+ const heldCut = memo === undefined ? [] : window.barOpens.filter((stampMs) => memo.cut.has(stampMs) && !memo.landed.has(stampMs));
519
+ const freshAsks = memo === undefined || memoUtil === undefined
520
+ ? asks
521
+ : memoUtil.wrunRowLaneAsksOverBars(asks, (stampMs) => !memo.landed.has(stampMs) && !memo.cut.has(stampMs), window, sessionGrid);
522
+ const planPartial = heldCut.length === 0 ? partialBars : [...new Set([...partialBars, ...heldCut])].sort((a, b) => a - b);
343
523
  // A row-budget lane's newest bars are asked first and on their own (wrun-row-lane-first-paint.util, off the boot path),
344
524
  // and so are an instance's whose facets ask a per-bar word of the gateway (OPTLOAD G5: a surface pick, the strike kit
345
525
  // fold), sized by the rows its answer holds; every other instance asks as the tier rule made it.
346
- const sliceBudget = lane.rowBudget ?? wrunOptionLaneFirstPaintBudget(lane.sourceClass, extras, lane.width);
347
- const firstPaint = sliceBudget === undefined ? undefined : await import('./wrun-row-lane-first-paint.util.js');
526
+ const sliceBudget = rowBudget ?? wrunOptionLaneFirstPaintBudget(lane.sourceClass, extras, lane.width);
527
+ // A budgeted run of an add that already spent reads within what is left of the add's share (none named yet: its own).
528
+ const memoShareBytes = memo?.shareBytes;
529
+ const download = opts.download === undefined || memo === undefined || memoShareBytes === undefined
530
+ ? opts.download
531
+ : { ...opts.download, share: Math.max(0, memoShareBytes - memo.spentBytes) };
532
+ const firstPaint = sliceBudget === undefined && download === undefined ? undefined : await import('./wrun-row-lane-first-paint.util.js');
348
533
  // The slice is cut on a trade date's first bar wherever the chart reads trade dates (`window.tradeDateOf`), so it
349
534
  // holds whole sessions, on every run alike: a first paint asks the windows a later run asks (one cache entry each).
350
535
  const split = firstPaint === undefined || sliceBudget === undefined
351
536
  ? undefined
352
- : firstPaint.wrunRowLaneFirstPaintSplit(asks, window, sliceBudget, budgetAcquisition, sessionGrid, window.tradeDateOf);
353
- const ordered = split === undefined ? asks : [...split.first, ...split.older];
537
+ : firstPaint.wrunRowLaneFirstPaintSplit(freshAsks, window, sliceBudget, budgetAcquisition, sessionGrid, window.tradeDateOf);
538
+ const ordered = split === undefined ? freshAsks : [...split.first, ...split.older];
354
539
  // The bars the slice's early answer holds back (`opts.onFirstSlice`), or undefined when it has none.
355
540
  const coarserPass = landing.kind === 'snapshot' && landing.tiers !== undefined && landing.coarserWhenEmpty?.(extras) === true;
356
541
  const heldBack = opts.onFirstSlice === undefined ||
542
+ download !== undefined ||
357
543
  firstPaint === undefined ||
358
544
  split === undefined ||
359
545
  sliceBudget === undefined ||
360
546
  sized.presentMask === false ||
361
547
  coarserPass ||
362
- wrunOptionLaneCarriesNext(lane.sourceClass, extras)
548
+ wrunOptionLaneCarriesNext(lane.sourceClass, extras) ||
549
+ !firstPaint.wrunRowLaneDrawsFirstSlice(lane.sourceClass, extras)
363
550
  ? undefined
364
551
  : firstPaint.wrunRowLaneFirstSliceHeldBars(split, window, sliceBudget, budgetAcquisition, sessionGrid);
365
552
  const fold = landing.fold;
366
- // `askToMs` reads past the ask's own end (a kit fold's seam, below); only the ask's own bars ever land.
367
- const askAndLand = async (gridAsk, askToMs = gridAsk.toMs) => {
368
- const askExtras = gridAsk.tier === undefined ? extras : { ...extras, [WRUN_ROW_LANE_TIER_FIELD]: gridAsk.tier.key };
553
+ // The bars of every ask the chart's fetch did not confirm whole (`ask`'s verdict): no memo admits them.
554
+ const unconfirmed = new Set();
555
+ // `askToMs` reads past the ask's own end (a kit fold's seam, below); only the ask's own bars ever land. `more`: the
556
+ // fields a budgeted read's ask names beside the payload (a browser fold's row cap, FE-FOLD-CAP).
557
+ const askAndLand = async (gridAsk, askToMs = gridAsk.toMs, more) => {
558
+ const payload = more === undefined ? extras : { ...extras, ...more };
559
+ const askExtras = gridAsk.tier === undefined ? payload : { ...payload, [WRUN_ROW_LANE_TIER_FIELD]: gridAsk.tier.key };
560
+ const heard = { whole: false };
561
+ const answer = await ask(askExtras, gridAsk.fromMs, askToMs, (answered) => {
562
+ heard.whole = answered;
563
+ });
564
+ if (!heard.whole) {
565
+ for (const stampMs of window.barOpens) {
566
+ const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
567
+ if (fromMs >= gridAsk.fromMs && fromMs < gridAsk.toMs)
568
+ unconfirmed.add(stampMs);
569
+ }
570
+ }
369
571
  // Rows stamped at or past the ask's end belong to a bar the plan did not ask (a skipped newest bar): never land
370
572
  // them, whatever the control answered.
371
- const rows = (await ask(askExtras, gridAsk.fromMs, askToMs)).filter((row) => Number(row[0]) < gridAsk.toMs);
573
+ const rows = answer.filter((row) => Number(row[0]) < gridAsk.toMs);
372
574
  return wrunLandCellRowsOnHostBars(rows, landing.kind, { intervalMs: window.intervalMs, barGrid: window.barGrid, tierMs: gridAsk.tier?.ms, nowMs: window.nowMs }, fold === undefined ? undefined : (group) => fold(group, askExtras)).map((row) => wrunRowLanePlainRow(row, width));
373
575
  };
374
576
  const byBar = new Map();
577
+ // The add's landed bars come back as they landed (a copy: the memo's rows are never handed out to be written), each
578
+ // standing in for an ask only: never for a bar this read's plan leaves partial (past the lane's horizon or its row
579
+ // budget now), which a fresh read shows as a marker alone.
580
+ if (memo !== undefined) {
581
+ const inWindow = new Set(window.barOpens);
582
+ const leftPartial = new Set(planPartial);
583
+ for (const [stampMs, row] of memo.landed) {
584
+ if (row !== undefined && inWindow.has(stampMs) && !leftPartial.has(stampMs)) {
585
+ byBar.set(stampMs, row.map((cell) => (Array.isArray(cell) ? cell.slice() : cell)));
586
+ }
587
+ }
588
+ }
375
589
  const landAll = (gridAsks) => Promise.all(gridAsks.map((gridAsk) => askAndLand(gridAsk)));
376
- if (heldBack !== undefined && split !== undefined && opts.onFirstSlice !== undefined) {
590
+ // The asks the read sent and the bars it reads partial: the plan's, unless a budgeted read left older bars unasked.
591
+ let sentAsks = freshAsks;
592
+ let readPartial = planPartial;
593
+ if (download !== undefined && firstPaint !== undefined && freshAsks.length === 0) {
594
+ // Every bar of the window is the add's already (landed or cut): nothing is asked.
595
+ sentAsks = [];
596
+ }
597
+ else if (download !== undefined && firstPaint !== undefined) {
598
+ // OPTLOAD W3 R2: the newest slice first and alone, then the newest older bars the read's share fits by the slice's
599
+ // own wire bytes, and no others (`landWithinDownloadShare`). No early handover: the older asks leave once the
600
+ // slice landed, so the whole answer is the first picture.
601
+ const carriesNext = wrunOptionLaneCarriesNext(lane.sourceClass, extras);
602
+ const landGroup = async (gridAsks, more) => {
603
+ if (!carriesNext) {
604
+ const answers = await Promise.all(gridAsks.map((gridAsk) => askAndLand(gridAsk, gridAsk.toMs, more)));
605
+ for (const landed of answers)
606
+ for (const row of landed)
607
+ byBar.set(Number(row[0]), row);
608
+ return;
609
+ }
610
+ // A kit fold carrying the next bar: newest first, one at a time, each read through its seam (as below).
611
+ for (const gridAsk of [...gridAsks].sort((a, b) => b.fromMs - a.fromMs)) {
612
+ const end = wrunRowLaneSeamEndMs(gridAsk, byBar, window.intervalMs);
613
+ for (const row of await askAndLand(gridAsk, end, more))
614
+ byBar.set(Number(row[0]), row);
615
+ }
616
+ };
617
+ const within = await landWithinDownloadShare({
618
+ laneKey: lane.laneKey,
619
+ extras,
620
+ width,
621
+ window,
622
+ sessionGrid,
623
+ asks: freshAsks,
624
+ partialBars: planPartial,
625
+ budgetAcquisition,
626
+ sliceBudget,
627
+ download,
628
+ firstPaint,
629
+ land: landGroup,
630
+ landedData: (stampMs) => (byBar.get(stampMs) ?? [])
631
+ .slice(1)
632
+ .some((tuple) => Array.isArray(tuple) &&
633
+ tuple.length > 0 &&
634
+ (sized.presentMask === false || !wrunPresentIsPartial(Number(tuple[tuple.length - 1])))),
635
+ });
636
+ sentAsks = within.sent;
637
+ readPartial = within.partialBars;
638
+ }
639
+ else if (heldBack !== undefined && split !== undefined && opts.onFirstSlice !== undefined) {
377
640
  // Every ask leaves at once, as below; the slice's answer is handed over first while an older ask is still out.
378
641
  const onFirstSlice = opts.onFirstSlice;
379
642
  // The slice's first bar: the first bar the cut keeps (every bar before it is held).
@@ -434,7 +697,7 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask,
434
697
  // acquisition its lane says so of (`coarserWhenEmpty`: a CME surface's daily bar whose 5m tier holds no session
435
698
  // yet reads its settlement DAY row, never nothing); a fallback row fills only a bar still empty.
436
699
  if (landing.kind === 'snapshot' && landing.tiers !== undefined && landing.coarserWhenEmpty?.(extras) === true) {
437
- for (let pending = asks;;) {
700
+ for (let pending = sentAsks;;) {
438
701
  const fallback = wrunHostGridFallbackAsks({
439
702
  tiers: landing.tiers,
440
703
  asks: pending,
@@ -454,9 +717,348 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask,
454
717
  }
455
718
  }
456
719
  const landed = [...byBar.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
720
+ if (lane.rowBudget !== undefined) {
721
+ noteWrunRowLaneMeasured(lane.laneKey, extras, sentAsks, byBar, readPartial, window, sessionGrid, sized.presentMask);
722
+ }
723
+ const foldPartial = (download?.fold ?? lane.download?.fold) !== undefined && sized.presentMask !== false;
724
+ if (download !== undefined && opts.download !== undefined) {
725
+ // The download budget's cut, named once the asks landed: the bars the share left unread, and the bars a browser
726
+ // fold left partial under its cap (FE-FOLD-CAP), the source answer budget's own cut kept apart; the add's cut and
727
+ // its whole spend when a memo served the read.
728
+ const cut = wrunRowLaneDownloadCutOf({
729
+ laneKey: lane.laneKey,
730
+ width,
731
+ window,
732
+ sessionGrid,
733
+ asks,
734
+ before: partialBars,
735
+ after: readPartial,
736
+ byBar,
737
+ foldPartial,
738
+ spentBytes: (memo?.spentBytes ?? 0) + download.meter.spentBytes(),
739
+ shareBytes: opts.download.share,
740
+ });
741
+ if (cut.cutBars > 0)
742
+ reportWrunRowLaneBudgetCut(cut, window.intervalMs, opts.onBudgetCut);
743
+ }
744
+ // The asks the chart's fetch did not confirm whole, named once they all landed.
745
+ if (unconfirmed.size > 0)
746
+ opts.onUnconfirmed?.([...unconfirmed].sort((a, b) => a - b));
747
+ // The add's memo after this read: every read that names its add (a run's, a live read's, a replay's) leaves one,
748
+ // budgeted or not; a bar an unconfirmed ask answered joins none (asked again by the next read).
749
+ if (memoUtil !== undefined && addMemo !== undefined && memoDependency !== undefined) {
750
+ const asked = (stampMs) => {
751
+ const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
752
+ return sentAsks.some((gridAsk) => fromMs >= gridAsk.fromMs && fromMs < gridAsk.toMs);
753
+ };
754
+ const askedBars = window.barOpens.filter(asked);
755
+ memoUtil.rememberWrunRowLaneAdd(addMemo.key, memoUtil.wrunRowLaneAddMemoAfter({
756
+ previous: memo,
757
+ fingerprint: memoFingerprint,
758
+ dependency: memoDependency,
759
+ window,
760
+ sessionGrid,
761
+ askedBars,
762
+ landedRows: byBar,
763
+ partialBars: new Set([...readPartial, ...unconfirmed]),
764
+ marked: (row) => foldPartial && wrunRowLaneRowMarkedPartial(row),
765
+ cutBars: opts.download === undefined
766
+ ? []
767
+ : [
768
+ ...readPartial,
769
+ ...askedBars.filter((stampMs) => {
770
+ const row = byBar.get(stampMs);
771
+ return foldPartial && row !== undefined && wrunRowLaneRowMarkedPartial(row);
772
+ }),
773
+ ],
774
+ spentBytes: download?.meter.spentBytes() ?? 0,
775
+ shareBytes: opts.download?.share,
776
+ }));
777
+ }
457
778
  // A block with no `present` mask (its class's, or an instance's its facets widen) marks nothing: a partial bar asked
458
779
  // nothing and reads an empty block.
459
- return sized.presentMask === false ? landed : wrunCellRowsWithPartialBars(landed, partialBars, width);
780
+ return sized.presentMask === false ? landed : wrunCellRowsWithPartialBars(landed, readPartial, width);
781
+ }
782
+ /** Whether a landed row carries a partial mark (bit 14 on a tuple's `present`, its last cell). */
783
+ function wrunRowLaneRowMarkedPartial(row) {
784
+ return row.slice(1).some((tuple) => Array.isArray(tuple) && wrunPresentIsPartial(Number(tuple[tuple.length - 1])));
785
+ }
786
+ /**
787
+ * What one host bar's landed row depends on beyond its own span, read off a row lane instance's acquisition: the add
788
+ * memo's ONE eligibility rule (wrun-row-lane-add-memo.util `WrunRowLaneRowDependency`), so no read reuses a row a later
789
+ * read would answer otherwise (LIVE-REREAD review 2026-10-28). By the acquisition's own words, whatever the lane:
790
+ * - a window-wide cut (`newest`, and `newestTailMs` beside it: the window's N newest prints, option_prints): a bar's
791
+ * rows depend on every newer print of the read's window: `never`;
792
+ * - `history: "today"` (the flow lanes): which bars hold rows depends on the trade date of the chart's newest bar (the K
793
+ * control's `todayFromMs`), which no bar's clock settles: `never`;
794
+ * - `span: "session"` (the flow lanes): one sum per contract per trade date on the session's first bar, growing all
795
+ * session: `session`, its trade date's end on the chain's clock (`optionTradeDateClockOf`, the clock the worker
796
+ * twins group by); `never` for a chain the acquisition names no exchange of;
797
+ * - a kit fold carrying the next bar's strikes (`wrunOptionLaneCarriesNext`): `next-bar`, its rows read as the paging
798
+ * seam reads them (`wrunOptionKitBarHasRows`);
799
+ * - anything else: `bar`, final the lag after its own end.
800
+ * And by the lane's landing, an empty bar: quiet on a flow (nothing traded), never final on a snapshot (`emptyIsQuiet`
801
+ * false: a picture not shown yet, a failed read answered empty, a folded kit read's older bars past its cap, a CME
802
+ * surface bar whose settlement row is not published yet; LIVE-REREAD sweep 2026-10-28).
803
+ */
804
+ export function wrunRowLaneRowDependencyOf(lane, extras) {
805
+ if (extras.newest !== undefined || extras.newestTailMs !== undefined)
806
+ return { kind: 'never', why: 'window-newest' };
807
+ if (extras.history === 'today')
808
+ return { kind: 'never', why: 'history-today' };
809
+ const emptyIsQuiet = lane.landing.kind !== 'snapshot';
810
+ if (extras.span === 'session') {
811
+ const field = lane.chain?.exchangeField;
812
+ const exchange = field === undefined ? undefined : extras[field];
813
+ if (typeof exchange !== 'string' || exchange === '')
814
+ return { kind: 'never', why: 'session-without-clock' };
815
+ const clock = optionTradeDateClockOf({ exchange, coin: typeof extras.coin === 'string' ? extras.coin : '' });
816
+ return {
817
+ kind: 'session',
818
+ emptyIsQuiet,
819
+ // The first instant of the next trade date a bar's falls before (a weekend or a holiday skipped), else never.
820
+ sessionEndMs: (stampMs) => {
821
+ const day = optionTradeDayByClock(clock, stampMs);
822
+ for (let next = day + 1; next <= day + 4; next += 1) {
823
+ const startMs = optionTradeDayStartMsByClock(clock, next);
824
+ if (Number.isFinite(startMs))
825
+ return startMs;
826
+ }
827
+ return Number.POSITIVE_INFINITY;
828
+ },
829
+ };
830
+ }
831
+ if (wrunOptionLaneCarriesNext(lane.sourceClass, extras)) {
832
+ return { kind: 'next-bar', emptyIsQuiet, hasRows: (row) => wrunOptionKitBarHasRows(row.slice(1)) };
833
+ }
834
+ return { kind: 'bar', emptyIsQuiet };
835
+ }
836
+ /** The add memo's fingerprint (wrun-row-lane-add-memo.util): the lane, the acquisition without a per-ask field (the
837
+ * measured key's skips and the lane's fold cap), the bar span and the bar grid's session. A run's extras and a
838
+ * reconcile's recorded acquisition of the same instance print the same. Never the bar grid's whole record: the live
839
+ * session's market names no `transformations` where the chart's metadata does (INT 2026-10-23: every reconcile missed
840
+ * the run's memo). Its session, though, both name alike (the live market's is the chart's), and it decides what a bar
841
+ * holds under one stamp: a session switch (regular hours to the whole session) keeps the add, and a CME day bar keeps
842
+ * its stamp while its span moves, so a memo of one session never serves the other's bars. */
843
+ function wrunRowLaneAddFingerprintOf(lane, extras, window) {
844
+ const foldField = lane.download?.fold?.field;
845
+ const fields = {};
846
+ for (const [key, value] of Object.entries(extras))
847
+ if (key !== foldField)
848
+ fields[key] = value;
849
+ const session = window.barGrid?.sessionType;
850
+ return `${measuredKeyOf(lane.laneKey, fields, undefined, window.intervalMs)}|${typeof session === 'string' ? session : ''}`;
851
+ }
852
+ /** The newest projection a budgeted read measured (`landWithinDownloadShare`), by lane and acquisition: its wire bytes a
853
+ * millisecond of bars. In memory, the newest `MEASURED_KEPT`. */
854
+ const downloadDensity = new Map();
855
+ function rememberDownload(map, key, value) {
856
+ if (!(Number.isFinite(value) && value > 0))
857
+ return;
858
+ map.delete(key);
859
+ map.set(key, value);
860
+ while (map.size > MEASURED_KEPT)
861
+ map.delete(map.keys().next().value);
862
+ }
863
+ /** The first bar of the newest trade date the window reads (`window.tradeDateOf`), or undefined without one. */
864
+ function wrunRowLaneNewestSessionFromMs(window, sessionGrid) {
865
+ const { barOpens, tradeDateOf } = window;
866
+ const newest = barOpens[barOpens.length - 1];
867
+ if (tradeDateOf === undefined || newest === undefined)
868
+ return undefined;
869
+ const date = tradeDateOf(newest);
870
+ if (!Number.isFinite(date))
871
+ return undefined;
872
+ let fromMs;
873
+ for (let at = barOpens.length - 1; at >= 0 && tradeDateOf(barOpens[at]) === date; at -= 1) {
874
+ fromMs = wrunHostBarSpanOf(barOpens[at], window.intervalMs, sessionGrid).fromMs;
875
+ }
876
+ return fromMs;
877
+ }
878
+ /**
879
+ * A budgeted read's asks (OPTLOAD W3 R2, `WrunRowLaneFetchOptions.download`), landed through `land`:
880
+ * 1. its NEWEST SLICE, first and alone: the first-paint split of its asks (wrun-row-lane-first-paint.util) under the
881
+ * lane's own row budget, else a per-bar word's first-paint budget, else the kit's declared rows a bar (one heavy bar
882
+ * alone); a read summing a whole session per row (`span` "session") slices on its newest session's first bar, so no
883
+ * older ask reads that session again;
884
+ * 2. once it landed, its wire bytes over the slice's elapsed span (a bar still forming counts its elapsed part, at least
885
+ * a minute) project each older bar by its span; a slice no stamp measured (a cache) reads the read's last measured
886
+ * projection, else the declared rows a bar;
887
+ * 3. the newest older bars whose projections fit the share left after the slice are asked, as one run of bars, and no
888
+ * others: every older bar it leaves unasked joins the partial bars, except a bar its lane projects at nothing (before
889
+ * today under `history` "today": it reads nothing either way);
890
+ * 4. FE-FOLD-CAP: a lane folding contract rows in the browser (`download.fold`) bounds the READ, never each ask: a
891
+ * group of its asks (the slice, the older asks) lands newest first, one ask at a time, each naming the rows the
892
+ * bytes its group may still spend buy at the row's cells (the fold plan's own unit); once the group spent its bytes,
893
+ * its older asks are not sent and their bars read partial. The slice's bytes are the share, never under the first
894
+ * paint's (so it reads its newest bars); the older asks', what the slice left.
895
+ * The sent asks and the bars the read reads partial come back; what the slice measured is remembered for the next read.
896
+ */
897
+ async function landWithinDownloadShare(args) {
898
+ const { window, sessionGrid, asks, download, budgetAcquisition } = args;
899
+ const declared = download.declaredBarRows;
900
+ const sliceRows = args.sliceBudget ??
901
+ (declared !== undefined && declared > 0 ? { cellsPerRow: args.width, barRows: () => declared } : undefined);
902
+ const sessionFrom = args.extras.span === 'session' ? wrunRowLaneNewestSessionFromMs(window, sessionGrid) : undefined;
903
+ const split = sessionFrom !== undefined
904
+ ? args.firstPaint.wrunRowLaneSplitAt(asks, sessionFrom)
905
+ : args.firstPaint.wrunRowLaneFirstPaintSplit(asks, window, sliceRows, budgetAcquisition, sessionGrid);
906
+ const memoryKey = measuredKeyOf(args.laneKey, args.extras, undefined, 0);
907
+ const fold = download.fold;
908
+ const spanOf = (stampMs) => wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
909
+ const askOf = (stampMs, gridAsks) => {
910
+ const { fromMs } = spanOf(stampMs);
911
+ return gridAsks.find((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
912
+ };
913
+ const barsOf = (gridAsks) => window.barOpens.filter((stampMs) => askOf(stampMs, gridAsks) !== undefined);
914
+ // A group of asks within `bytes`: a lane with no fold lands it at once; a fold lands it newest first, one ask at a
915
+ // time, each naming the rows what is left of `bytes` buys at the row's cells, and sends no older ask once it is spent.
916
+ const landGroup = async (gridAsks, bytes) => {
917
+ if (fold === undefined) {
918
+ await args.land(gridAsks, undefined);
919
+ return { sent: [...gridAsks], unsent: [] };
920
+ }
921
+ const rowBytes = fold.cellsPerRow * KSCRIPT_SOURCE_CELL_BYTES;
922
+ const sent = [];
923
+ const unsent = [];
924
+ let left = bytes;
925
+ for (const gridAsk of [...gridAsks].sort((a, b) => b.fromMs - a.fromMs)) {
926
+ if (sent.length > 0 && left <= 0) {
927
+ unsent.push(gridAsk);
928
+ continue;
929
+ }
930
+ const before = download.meter.spentBytes();
931
+ await args.land([gridAsk], { [fold.field]: Math.max(1, Math.floor(Math.max(0, left) / rowBytes)) });
932
+ sent.push(gridAsk);
933
+ left -= Math.max(0, download.meter.spentBytes() - before);
934
+ }
935
+ return { sent, unsent };
936
+ };
937
+ const bytesBefore = download.meter.spentBytes();
938
+ // The slice reads at least its newest bars whatever the share: a fold's bytes there are never under the first paint's.
939
+ const sliceCap = Math.max(download.share, args.firstPaint.WRUN_ROW_LANE_FIRST_PAINT_BYTES);
940
+ const slice = await landGroup(split.first, sliceCap);
941
+ let sliceSent = slice.sent;
942
+ const sliceUnsent = barsOf(slice.unsent);
943
+ let olderPlan = split.older;
944
+ // A slice that landed no data (its newest bar holds none yet: a delayed route's first minutes of a session) reads the
945
+ // newest older bar beside it, once, so the first picture holds the newest bar with data and the older bars are
946
+ // projected from a measured bar (INT 2026-10-23 13:30Z: Spot Exposures' forming bar answered nothing, its 55 older
947
+ // bars were cut on the kit's declared rows, and the chart drew nothing).
948
+ if (olderPlan.length > 0 && !barsOf(slice.sent).some(args.landedData)) {
949
+ const newestOlder = barsOf(olderPlan).at(-1);
950
+ if (newestOlder !== undefined) {
951
+ const { fromMs, toMs } = spanOf(newestOlder);
952
+ const extension = olderPlan.flatMap((ask) => {
953
+ const askFrom = Math.max(ask.fromMs, fromMs);
954
+ const askTo = Math.min(ask.toMs, toMs);
955
+ return askFrom < askTo ? [{ ...ask, fromMs: askFrom, toMs: askTo }] : [];
956
+ });
957
+ const spent = Math.max(0, download.meter.spentBytes() - bytesBefore);
958
+ const extended = await landGroup(extension, Math.max(sliceCap - spent, args.firstPaint.WRUN_ROW_LANE_FIRST_PAINT_BYTES));
959
+ sliceSent = [...sliceSent, ...extended.sent];
960
+ sliceUnsent.push(...barsOf(extended.unsent));
961
+ olderPlan = olderPlan.flatMap((ask) => {
962
+ const askTo = Math.min(ask.toMs, fromMs);
963
+ return ask.fromMs < askTo ? [{ ...ask, toMs: askTo }] : [];
964
+ });
965
+ }
966
+ }
967
+ const sliceBytes = Math.max(0, download.meter.spentBytes() - bytesBefore);
968
+ if (olderPlan.length === 0) {
969
+ return { sent: sliceSent, partialBars: [...new Set([...args.partialBars, ...sliceUnsent])].sort((a, b) => a - b) };
970
+ }
971
+ // The slice's elapsed span over its bars that landed data (a bar still forming counts what has elapsed of it, at least
972
+ // a minute): a bar that answered nothing spent nothing, and counting it would price the older bars under what they cost.
973
+ let sliceMs = 0;
974
+ for (const stampMs of window.barOpens) {
975
+ if (askOf(stampMs, sliceSent) === undefined || !args.landedData(stampMs))
976
+ continue;
977
+ const span = spanOf(stampMs);
978
+ const whole = span.toMs - span.fromMs;
979
+ sliceMs += Math.max(Math.min(MINUTE_MS, whole), Math.min(span.toMs, window.nowMs) - span.fromMs);
980
+ }
981
+ if (sliceBytes > 0 && sliceMs > 0)
982
+ rememberDownload(downloadDensity, memoryKey, sliceBytes / sliceMs);
983
+ const density = sliceBytes > 0 && sliceMs > 0 ? sliceBytes / sliceMs : downloadDensity.get(memoryKey);
984
+ const declaredRowsOf = (stampMs, tier) => {
985
+ if (sliceRows === undefined)
986
+ return undefined;
987
+ const span = spanOf(stampMs);
988
+ const rows = sliceRows.barRows({ openMs: span.fromMs, endMs: span.toMs, tier }, window.nowMs, budgetAcquisition);
989
+ return Number.isFinite(rows) && rows > 0 ? rows : 0;
990
+ };
991
+ let left = download.share - sliceBytes;
992
+ let keptFrom = Number.POSITIVE_INFINITY;
993
+ let keptEnd = Number.NEGATIVE_INFINITY;
994
+ let stopped = false;
995
+ const cut = [];
996
+ const older = window.barOpens.filter((stampMs) => askOf(stampMs, olderPlan) !== undefined).sort((a, b) => b - a);
997
+ for (const stampMs of older) {
998
+ const tier = askOf(stampMs, olderPlan)?.tier;
999
+ const rows = declaredRowsOf(stampMs, tier);
1000
+ // A bar its lane projects at nothing reads nothing: never cut, never asked on its own.
1001
+ if (rows === 0)
1002
+ continue;
1003
+ const span = spanOf(stampMs);
1004
+ const bytes = density !== undefined
1005
+ ? density * (span.toMs - span.fromMs)
1006
+ : (rows ?? 0) * (sliceRows?.cellsPerRow ?? args.width) * KSCRIPT_SOURCE_CELL_BYTES;
1007
+ if (stopped || bytes > left) {
1008
+ stopped = true;
1009
+ cut.push(stampMs);
1010
+ continue;
1011
+ }
1012
+ left -= bytes;
1013
+ keptFrom = Math.min(keptFrom, span.fromMs);
1014
+ keptEnd = Math.max(keptEnd, span.toMs);
1015
+ }
1016
+ const olderAsks = olderPlan.flatMap((ask) => {
1017
+ const fromMs = Math.max(ask.fromMs, keptFrom);
1018
+ const toMs = Math.min(ask.toMs, keptEnd);
1019
+ return fromMs < toMs ? [{ ...ask, fromMs, toMs }] : [];
1020
+ });
1021
+ const olderLanded = olderAsks.length > 0 ? await landGroup(olderAsks, download.share - sliceBytes) : undefined;
1022
+ return {
1023
+ sent: [...sliceSent, ...(olderLanded?.sent ?? [])],
1024
+ partialBars: [...new Set([...args.partialBars, ...sliceUnsent, ...cut, ...barsOf(olderLanded?.unsent ?? [])])].sort((a, b) => a - b),
1025
+ };
1026
+ }
1027
+ /**
1028
+ * A budgeted read's cut once its asks landed (`WrunRowLaneBudgetCut`, `budget: 'download'`): of the bars the plan asked
1029
+ * (`asks`, the tier rule's, the horizon's and the answer budget's), the ones read whole and the ones the download budget
1030
+ * alone left partial: unasked (`after` beside `before`), or, for a browser fold under its cap (`foldPartial`), landed
1031
+ * partial. The oldest kept bar is the oldest of the newest run of whole bars.
1032
+ */
1033
+ function wrunRowLaneDownloadCutOf(args) {
1034
+ const before = new Set(args.before);
1035
+ const after = new Set(args.after);
1036
+ const marked = (row) => row !== undefined && wrunRowLaneRowMarkedPartial(row);
1037
+ const asked = args.window.barOpens.filter((stampMs) => {
1038
+ const { fromMs } = wrunHostBarSpanOf(stampMs, args.window.intervalMs, args.sessionGrid);
1039
+ return !before.has(stampMs) && args.asks.some((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
1040
+ });
1041
+ const isCut = (stampMs) => after.has(stampMs) || (args.foldPartial && marked(args.byBar.get(stampMs)));
1042
+ let keptFromTs;
1043
+ for (let at = asked.length - 1; at >= 0; at -= 1) {
1044
+ if (isCut(asked[at])) {
1045
+ if (keptFromTs !== undefined)
1046
+ break;
1047
+ continue;
1048
+ }
1049
+ keptFromTs = asked[at];
1050
+ }
1051
+ const cutBars = asked.filter(isCut).length;
1052
+ return {
1053
+ laneKey: args.laneKey,
1054
+ keptBars: asked.length - cutBars,
1055
+ cutBars,
1056
+ ...(keptFromTs !== undefined ? { keptFromTs } : {}),
1057
+ maxRows: wrunRowLaneMaxRows({ cellsPerRow: args.width }),
1058
+ budget: 'download',
1059
+ spentBytes: Math.round(args.spentBytes),
1060
+ shareBytes: Math.round(args.shareBytes),
1061
+ };
460
1062
  }
461
1063
  /**
462
1064
  * Where a kit fold page carrying the next bar's strikes is read to (the paging seam, OPTLOAD G5): through the end of the
@@ -595,6 +1197,138 @@ export function wrunRowLaneAsksWithinRowBudget(plan, window, budget, acquisition
595
1197
  partialBars: [...new Set([...plan.partialBars, ...cut])].sort((a, b) => a - b),
596
1198
  };
597
1199
  }
1200
+ /**
1201
+ * What row-budget lanes' reads measured (`wrunRowLaneProjectedBarRows`): the bars a read landed whole and the tuples
1202
+ * they held, by lane, acquisition, tier and bar width, a running sum weighing at most `MEASURED_BARS` bars, so a newer
1203
+ * read moves it and a short one (a live reconcile's newest bars) never replaces a whole window's. In memory, the
1204
+ * newest `MEASURED_KEPT` kept.
1205
+ */
1206
+ const measuredBars = new Map();
1207
+ const MEASURED_KEPT = 64;
1208
+ const MEASURED_BARS = 500;
1209
+ /** The ask's fields that never change what a bar holds: its tier (keyed apart), the routed tier and plane, the market
1210
+ * placeholders a recorded acquisition carries, today's first instant and the instance's own bound. Also the fields the
1211
+ * chart's fetch writes on the payload it is handed, which the run records as the lane's acquisition (titan-charts
1212
+ * `acquireKScriptSourceData`: the resolved market, and `interval`, the source's own interval; the bar span is keyed
1213
+ * apart): a run's extras and a reconcile's recorded acquisition print the same. With `interval` printed, the live start
1214
+ * missed the add's memo whenever a run had asked the lane (LIVE-REREAD 2026-10-28, ES1! 1h whole session, Premium by
1215
+ * Expiry: the forming bar's ask recorded `interval: '1h'`, and the live start read the window's 8 final bars again). */
1216
+ const MEASURED_SKIP = new Set([
1217
+ WRUN_ROW_LANE_TIER_FIELD,
1218
+ 'servedTier',
1219
+ 'wrunPlane',
1220
+ 'symbol',
1221
+ 'exchange',
1222
+ 'interval',
1223
+ WRUN_OPTION_FLOW_TODAY_FIELD,
1224
+ 'maxCells',
1225
+ ]);
1226
+ function measuredKeyOf(laneKey, extras, tierKey, widthMs) {
1227
+ const fields = {};
1228
+ for (const [key, value] of Object.entries(extras))
1229
+ if (!MEASURED_SKIP.has(key))
1230
+ fields[key] = value;
1231
+ return `${laneKey}|${tierKey ?? ''}|${widthMs}|${stableJson(fields)}`;
1232
+ }
1233
+ /** Test seam: forget every measurement. */
1234
+ export function __resetWrunRowLaneMeasurementsForTests() {
1235
+ measuredBars.clear();
1236
+ downloadDensity.clear();
1237
+ }
1238
+ /**
1239
+ * The rows a row-budget lane's next ask projects for one bar: its own projection (`rowBudget.barRows`: a proxy, the
1240
+ * strike flow's SPY bars at one width, the contract flow's SPY session at each tier) raised to the tuples a bar of the
1241
+ * same lane, acquisition, tier and width held in the reads that landed before, never past the instance's `maxCells`
1242
+ * (the most tuples a bar of it is read with, which option_strike_flow's facets name); a bar its projection reads
1243
+ * nothing for (before today under `history` "today") stays at nothing. A market busier than its proxy then reads fewer
1244
+ * bars on its next ask instead of an answer past the source answer budget, and a quieter one keeps the proxy. A
1245
+ * contract flow bar's measured tuples (its contracts) are no more than the raw rows it reads, so they only ever lift a
1246
+ * projection that was under them.
1247
+ */
1248
+ export function wrunRowLaneProjectedBarRows(lane, extras, bar, nowMs, acquisition = extras) {
1249
+ const projected = lane.rowBudget?.barRows(bar, nowMs, acquisition) ?? 0;
1250
+ if (!(projected > 0))
1251
+ return projected;
1252
+ const held = measuredBars.get(measuredKeyOf(lane.laneKey, extras, bar.tier?.key, bar.endMs - bar.openMs));
1253
+ const measured = held === undefined ? 0 : Math.ceil(held.tuples / held.bars);
1254
+ const most = extras.maxCells;
1255
+ return Math.min(Math.max(projected, measured), typeof most === 'number' && most >= 1 ? most : Infinity);
1256
+ }
1257
+ /** A lane's row budget projecting each bar through `wrunRowLaneProjectedBarRows` for one read's `extras`. */
1258
+ function wrunRowLaneMeasuredBudget(lane, budget, extras) {
1259
+ return {
1260
+ cellsPerRow: budget.cellsPerRow,
1261
+ barRows: (bar, nowMs, acquisition) => wrunRowLaneProjectedBarRows(lane, extras, bar, nowMs, acquisition),
1262
+ };
1263
+ }
1264
+ /**
1265
+ * One read's landed bars into the measurements (`wrunRowLaneProjectedBarRows`): every bar it holds whole, closed by the
1266
+ * clock, none of the plan's partial bars and no tuple marked partial (a bar still forming, or served in part, holds a
1267
+ * floor of its tuples), its tuples counted under the tier its ask read and its width.
1268
+ */
1269
+ function noteWrunRowLaneMeasured(laneKey, extras, asks, landed, partialBars, window, sessionGrid, presentMask) {
1270
+ const partial = new Set(partialBars);
1271
+ const marked = (tuple) => Array.isArray(tuple) && wrunPresentIsPartial(Number(tuple[tuple.length - 1]));
1272
+ const reads = new Map();
1273
+ for (const [stampMs, row] of landed) {
1274
+ const span = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
1275
+ const tuples = row.slice(1);
1276
+ if (partial.has(stampMs) || span.toMs > window.nowMs || tuples.length === 0)
1277
+ continue;
1278
+ if (presentMask !== false && tuples.some(marked))
1279
+ continue;
1280
+ // A bar no ask of this read named came from the add's memo: the read that landed it measured it.
1281
+ const ask = asks.find((gridAsk) => span.fromMs >= gridAsk.fromMs && span.fromMs < gridAsk.toMs);
1282
+ if (ask === undefined)
1283
+ continue;
1284
+ const key = measuredKeyOf(laneKey, extras, ask.tier?.key, span.toMs - span.fromMs);
1285
+ const read = reads.get(key) ?? { bars: 0, tuples: 0 };
1286
+ reads.set(key, { bars: read.bars + 1, tuples: read.tuples + tuples.length });
1287
+ }
1288
+ for (const [key, read] of reads) {
1289
+ const held = measuredBars.get(key) ?? { bars: 0, tuples: 0 };
1290
+ const bars = held.bars + read.bars;
1291
+ const weight = Math.min(1, MEASURED_BARS / bars);
1292
+ measuredBars.delete(key);
1293
+ measuredBars.set(key, { bars: bars * weight, tuples: (held.tuples + read.tuples) * weight });
1294
+ while (measuredBars.size > MEASURED_KEPT)
1295
+ measuredBars.delete(measuredBars.keys().next().value);
1296
+ }
1297
+ }
1298
+ /** The cut a row budget made (`wrunRowLaneAsksWithinRowBudget` over `before`, answering `after`): the asked bars it
1299
+ * reads whole and the bars it alone left partial. */
1300
+ function wrunRowLaneBudgetCutOf(laneKey, budget, before, after, window, sessionGrid) {
1301
+ const partialBefore = new Set(before.partialBars);
1302
+ const kept = window.barOpens.filter((stampMs) => {
1303
+ const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
1304
+ return after.asks.some((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
1305
+ });
1306
+ return {
1307
+ laneKey,
1308
+ keptBars: kept.length,
1309
+ cutBars: after.partialBars.filter((stampMs) => !partialBefore.has(stampMs)).length,
1310
+ ...(kept.length > 0 ? { keptFromTs: kept[0] } : {}),
1311
+ maxRows: wrunRowLaneMaxRows(budget),
1312
+ };
1313
+ }
1314
+ /** A budget cut to the debug ring and the caller. Both are advisory: a host with no ring, or a caller whose note
1315
+ * fails, costs the record, never the read. */
1316
+ function reportWrunRowLaneBudgetCut(cut, intervalMs, onBudgetCut) {
1317
+ try {
1318
+ const { diagnostics } = wrunChartHostEnv();
1319
+ if (diagnostics.debugEnabled())
1320
+ diagnostics.debug('wrun-row-lane-budget-cut', { ...cut, intervalMs });
1321
+ }
1322
+ catch {
1323
+ // No ring in this host.
1324
+ }
1325
+ try {
1326
+ onBudgetCut?.(cut);
1327
+ }
1328
+ catch {
1329
+ // The note is lost; the read goes on.
1330
+ }
1331
+ }
598
1332
  function finiteOrUndefined(value) {
599
1333
  return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
600
1334
  }