@orangecharts/wrun-chart-host 0.8.0 → 0.10.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 (246) hide show
  1. package/README.md +3 -1
  2. package/dist/constants/feature-flags.constants.d.ts +9 -0
  3. package/dist/constants/feature-flags.constants.js +86 -16
  4. package/dist/constants/marketCapabilities.constants.d.ts +14 -9
  5. package/dist/constants/marketCapabilities.constants.js +36 -13
  6. package/dist/constants/opra-compliance.constants.d.ts +15 -0
  7. package/dist/constants/opra-compliance.constants.js +15 -0
  8. package/dist/constants/option-venues.constants.d.ts +11 -6
  9. package/dist/constants/option-venues.constants.js +5 -2
  10. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
  11. package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
  12. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
  13. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
  14. package/dist/constants/venue-presets.constants.d.ts +20 -20
  15. package/dist/constants/venue-presets.constants.js +24 -26
  16. package/dist/host-env.d.ts +39 -9
  17. package/dist/host-env.js +6 -0
  18. package/dist/host-ports.types.d.ts +108 -18
  19. package/dist/index.d.ts +14 -0
  20. package/dist/index.js +14 -0
  21. package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
  22. package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
  23. package/dist/interfaces/opra-realtime.interface.js +10 -10
  24. package/dist/interfaces/replay.interface.d.ts +8 -0
  25. package/dist/interfaces/wrun-runtime.interface.d.ts +52 -15
  26. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +94 -14
  27. package/dist/kscript-data/controls/live-trades-merge.util.js +132 -22
  28. package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +56 -0
  29. package/dist/kscript-data/controls/live-trades-order-gate.util.js +107 -0
  30. package/dist/market-data/billing.interface.d.ts +227 -42
  31. package/dist/market-data/billing.interface.js +60 -12
  32. package/dist/market-data/venue.d.ts +88 -6
  33. package/dist/market-data/venues/cme.contract.copy.json +66 -0
  34. package/dist/market-data/venues/cme.d.ts +126 -0
  35. package/dist/market-data/venues/cme.js +133 -0
  36. package/dist/market-data/venues/index.d.ts +165 -8
  37. package/dist/market-data/venues/index.js +48 -6
  38. package/dist/market-data/venues/opra.contract.copy.json +5 -3
  39. package/dist/market-data/venues/opra.d.ts +3 -3
  40. package/dist/market-data/venues/opra.js +5 -4
  41. package/dist/replay/replayLadder.js +3 -1
  42. package/dist/settings-templates/index.js +7 -3
  43. package/dist/settings-templates/indicator-fields.d.ts +5 -4
  44. package/dist/settings-templates/indicator-fields.js +45 -6
  45. package/dist/settings-templates/tool-rules.d.ts +27 -17
  46. package/dist/settings-templates/tool-rules.js +27 -11
  47. package/dist/settings-templates/tool-tables.generated.js +91 -31
  48. package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
  49. package/dist/utility/chart/book-live-bucket.util.js +47 -0
  50. package/dist/utility/chart/crypto-index.leaf.d.ts +2 -2
  51. package/dist/utility/chart/crypto-index.leaf.js +2 -2
  52. package/dist/utility/chart/index-mode-admission.util.js +24 -3
  53. package/dist/utility/chart/index-mode.util.d.ts +5 -2
  54. package/dist/utility/chart/index-mode.util.js +23 -13
  55. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
  56. package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
  57. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +7 -2
  58. package/dist/utility/chart/kscript-live-coalesce.util.js +9 -3
  59. package/dist/utility/chart/kscript-provenance-keys.util.js +6 -0
  60. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
  61. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
  62. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
  63. package/dist/utility/chart/kscript-venue-policy.util.d.ts +53 -27
  64. package/dist/utility/chart/kscript-venue-policy.util.js +74 -32
  65. package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
  66. package/dist/utility/chart/market-session-schedule.util.js +16 -0
  67. package/dist/utility/chart/marketKind.util.d.ts +12 -10
  68. package/dist/utility/chart/marketKind.util.js +17 -7
  69. package/dist/utility/chart/om-panel-push-style.util.d.ts +7 -7
  70. package/dist/utility/chart/om-panel-push-style.util.js +17 -15
  71. package/dist/utility/chart/om-panel.util.js +6 -6
  72. package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
  73. package/dist/utility/chart/opra-read-access.leaf.js +5 -3
  74. package/dist/utility/chart/profile-block-size.util.d.ts +16 -0
  75. package/dist/utility/chart/profile-block-size.util.js +7 -0
  76. package/dist/utility/chart/quote-perp.leaf.d.ts +17 -0
  77. package/dist/utility/chart/quote-perp.leaf.js +20 -0
  78. package/dist/utility/chart/rth-session.util.d.ts +3 -2
  79. package/dist/utility/chart/rth-session.util.js +2 -1
  80. package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
  81. package/dist/utility/chart/window-geometry.leaf.js +22 -6
  82. package/dist/utility/chart/wrun-run-result.util.d.ts +17 -0
  83. package/dist/utility/chart/wrun-run-result.util.js +145 -7
  84. package/dist/utility/common/transformations.util.d.ts +7 -0
  85. package/dist/utility/common/transformations.util.js +11 -0
  86. package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
  87. package/dist/utility/options/option-bar-anchor.util.js +340 -0
  88. package/dist/utility/options/option-venue.util.d.ts +21 -3
  89. package/dist/utility/options/option-venue.util.js +30 -3
  90. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
  91. package/dist/utility/wrun/derived-roots.util.d.ts +213 -0
  92. package/dist/utility/wrun/derived-roots.util.js +471 -0
  93. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +41 -6
  94. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
  95. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
  96. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
  97. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +5 -3
  98. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +6 -4
  99. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +2 -2
  100. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +5 -1
  101. package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
  102. package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
  103. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
  104. package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
  105. package/dist/utility/wrun/sources/row-lane-registry.js +3 -2
  106. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
  107. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +9 -3
  108. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +15 -6
  109. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +14 -0
  110. package/dist/utility/wrun/sources/row-lanes/option_prints.js +82 -13
  111. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
  112. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +55 -8
  113. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +95 -14
  114. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +5 -2
  115. package/dist/utility/wrun/sources/row-lanes/option_surface.js +7 -3
  116. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
  117. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +35 -14
  118. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +70 -20
  119. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +64 -0
  120. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +89 -0
  121. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +45 -1
  122. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +114 -6
  123. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +56 -5
  124. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +224 -26
  125. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +822 -58
  126. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +16 -3
  127. package/dist/utility/wrun/wrun-batched-marks.util.js +30 -19
  128. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +37 -9
  129. package/dist/utility/wrun/wrun-batched-readout.util.js +61 -15
  130. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
  131. package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
  132. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -0
  133. package/dist/utility/wrun/wrun-cell-capacity.leaf.d.ts +66 -0
  134. package/dist/utility/wrun/wrun-cell-capacity.leaf.js +86 -0
  135. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +192 -13
  136. package/dist/utility/wrun/wrun-chart-market-facts.util.js +437 -55
  137. package/dist/utility/wrun/wrun-color-facts.util.d.ts +19 -9
  138. package/dist/utility/wrun/wrun-color-facts.util.js +24 -14
  139. package/dist/utility/wrun/wrun-color-settings.util.d.ts +15 -4
  140. package/dist/utility/wrun/wrun-color-settings.util.js +31 -12
  141. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.d.ts +17 -0
  142. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.js +9 -0
  143. package/dist/utility/wrun/wrun-download-meter.util.d.ts +107 -0
  144. package/dist/utility/wrun/wrun-download-meter.util.js +134 -0
  145. package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
  146. package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
  147. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
  148. package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
  149. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +6 -1
  150. package/dist/utility/wrun/wrun-draft-overlay.util.js +23 -3
  151. package/dist/utility/wrun/wrun-frames.d.ts +27 -6
  152. package/dist/utility/wrun/wrun-frames.js +78 -15
  153. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
  154. package/dist/utility/wrun/wrun-hosted-wire-caps.js +7 -0
  155. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
  156. package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
  157. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +51 -21
  158. package/dist/utility/wrun/wrun-hud-looks.util.js +74 -28
  159. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
  160. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +8 -6
  161. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +8 -6
  162. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -2
  163. package/dist/utility/wrun/wrun-live-intake.util.d.ts +19 -9
  164. package/dist/utility/wrun/wrun-live-intake.util.js +213 -45
  165. package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -0
  166. package/dist/utility/wrun/wrun-live-tick.util.js +246 -49
  167. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.d.ts +53 -0
  168. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.js +162 -0
  169. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +205 -48
  170. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +277 -34
  171. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +51 -7
  172. package/dist/utility/wrun/wrun-market-size-defaults.util.js +340 -56
  173. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
  174. package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
  175. package/dist/utility/wrun/wrun-option-prints.util.d.ts +41 -2
  176. package/dist/utility/wrun/wrun-option-prints.util.js +80 -13
  177. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
  178. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
  179. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +26 -6
  180. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +50 -11
  181. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +109 -19
  182. package/dist/utility/wrun/wrun-option-strike-flow.util.js +222 -61
  183. package/dist/utility/wrun/wrun-option-views.util.d.ts +96 -18
  184. package/dist/utility/wrun/wrun-option-views.util.js +246 -51
  185. package/dist/utility/wrun/wrun-options-stop.util.d.ts +2 -1
  186. package/dist/utility/wrun/wrun-options-stop.util.js +3 -2
  187. package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
  188. package/dist/utility/wrun/wrun-output-style.util.js +20 -2
  189. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +20 -0
  190. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +31 -14
  191. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +22 -0
  192. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
  193. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
  194. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +7 -0
  195. package/dist/utility/wrun/wrun-overlay-recovery.util.js +25 -1
  196. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +7 -1
  197. package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
  198. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +134 -37
  199. package/dist/utility/wrun/wrun-overlay-run.util.js +1118 -254
  200. package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +4 -4
  201. package/dist/utility/wrun/wrun-pack-widths.leaf.js +4 -4
  202. package/dist/utility/wrun/wrun-pack.util.d.ts +7 -3
  203. package/dist/utility/wrun/wrun-pack.util.js +20 -9
  204. package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
  205. package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
  206. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
  207. package/dist/utility/wrun/wrun-panel-mount.util.js +63 -13
  208. package/dist/utility/wrun/wrun-panel-style.util.d.ts +37 -24
  209. package/dist/utility/wrun/wrun-panel-style.util.js +100 -29
  210. package/dist/utility/wrun/wrun-param-map.util.d.ts +15 -11
  211. package/dist/utility/wrun/wrun-param-map.util.js +13 -5
  212. package/dist/utility/wrun/wrun-param-values.util.d.ts +21 -3
  213. package/dist/utility/wrun/wrun-param-values.util.js +6 -0
  214. package/dist/utility/wrun/wrun-pin-spelling.util.js +12 -11
  215. package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
  216. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
  217. package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
  218. package/dist/utility/wrun/wrun-refusal.util.js +10 -1
  219. package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
  220. package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
  221. package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
  222. package/dist/utility/wrun/wrun-run-interval.util.d.ts +4 -2
  223. package/dist/utility/wrun/wrun-run-interval.util.js +9 -6
  224. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +52 -1
  225. package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
  226. package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
  227. package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
  228. package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
  229. package/dist/utility/wrun/wrun-socket-row-source.js +113 -8
  230. package/dist/utility/wrun/wrun-source-rows.util.d.ts +9 -1
  231. package/dist/utility/wrun/wrun-source-rows.util.js +108 -43
  232. package/dist/utility/wrun/wrun-style-words.util.js +6 -4
  233. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
  234. package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
  235. package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
  236. package/dist/utility/wrun/wrun-tape-per-order.util.js +26 -0
  237. package/dist/utility/wrun/wrun-tape-source.util.d.ts +126 -50
  238. package/dist/utility/wrun/wrun-tape-source.util.js +193 -68
  239. package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +7 -5
  240. package/dist/utility/wrun/wrun-volume-profile-lane.util.js +8 -6
  241. package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
  242. package/dist/utils/replay/replay-buffer-math.js +227 -20
  243. package/dist/workers/utils/volume-profile.worker.util.d.ts +4 -1
  244. package/dist/workers/utils/volume-profile.worker.util.js +5 -2
  245. package/dist/workers/wrun/wrun-abi-host.js +3 -2
  246. package/package.json +5 -5
@@ -1,18 +1,38 @@
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';
8
+ import { wrunSheetCellBlockTuples } from '../wrun-cell-capacity.leaf.js';
6
9
  import { WRUN_OPTION_FLOW_TODAY_FIELD, wrunOptionFlowTodayFromOf } from '../wrun-option-contract-flow.util.js';
7
10
  import { wrunOptionInputTupleWidth, wrunOptionKitBarHasRows, wrunOptionLaneCarriesNext, wrunOptionLaneFirstPaintBudget, wrunOptionLaneTupleWidth, } from '../wrun-option-views.util.js';
8
11
  import { wrunPartialMarkerTuple, wrunPresentIsPartial, wrunTuplesMarkedPartial } from '../wrun-present-bits.util.js';
9
12
  import { wrunCellRowsWithPartialBars, wrunHostBarSpanOf, wrunHostGridAsks, wrunHostGridFallbackAsks, wrunLandCellRowsOnHostBars, } from '../wrun-tier-grid.util.js';
13
+ const MINUTE_MS = 60_000;
10
14
  /**
11
- * The static plan: every input whose class a row lane serves, in declaration order, with its lane. Refused by
12
- * name: a scalar input (a row lane serves cell blocks) and a celled one with no `max_cells` (the bound its blocks
13
- * are packed under). Empty when the sheet reads no row-lane class. The lane's width follows the input's own words
14
- * (wrun-option-views.util `wrunOptionInputTupleWidth`, the SDK's one rule: the strike kit fold's 14-value rows), so
15
- * the row builder reads and hands on the block each input's words make.
15
+ * A row lane at the width an input's words or an instance's facets make its block (wrun-option-views.util
16
+ * `wrunOptionInputTupleWidth`, `wrunOptionLaneTupleWidth`): the lane itself at its class's tuple width; at any other
17
+ * width a VIEW BLOCK (a page view fold's rows, the strike kit fold's: column 0 each row's layout, the widest layout's
18
+ * fields after it), read as the SDK's adapter reads one (kit `wrunCellBlockIsViewRows`, `kscriptViewRows`): every row
19
+ * of the width whole, a member that is no finite number NaN (`finiteColumns: []`), and no `present` mask
20
+ * (`presentMask: false`), so nothing reads or writes bit 14 in its last column, a fold's field or padding. Under the
21
+ * class tuple's rules Top Contracts' totals row (ending with `put_change`) marked every other row of the block partial
22
+ * at a change of 20,000 (bit 14 set), and was dropped whole on a block its knobs keep empty (no strike: `low_strike`
23
+ * and `high_strike` NaN).
24
+ */
25
+ function wrunRowLaneAtWidth(lane, width) {
26
+ return width === lane.width ? lane : { ...lane, width, finiteColumns: [], presentMask: false };
27
+ }
28
+ /**
29
+ * The static plan: every input whose class a row lane serves, in declaration order, with its lane and its module's
30
+ * bound (`capacity`, `wrunSheetCellBlockTuples`). Refused by name: a scalar input (a row lane serves cell blocks), a
31
+ * celled one with no `max_cells` (the bound its blocks are packed under) and a capacity no build writes
32
+ * (`wrun_cell_capacity_invalid`). Empty when the sheet reads no row-lane class. The lane's width follows the input's
33
+ * own words (wrun-option-views.util `wrunOptionInputTupleWidth`, the SDK's one rule: a page view fold's view block,
34
+ * the strike kit fold's 14-value rows), so the row builder reads and hands on the block each input's words make; a
35
+ * block of another width than its class's is read as it is (`wrunRowLaneAtWidth`).
16
36
  */
17
37
  export function planWrunRowLaneInputs(metadata) {
18
38
  const planned = [];
@@ -38,8 +58,9 @@ export function planWrunRowLaneInputs(metadata) {
38
58
  inputIndex: input.index,
39
59
  inputName: input.name,
40
60
  source,
41
- lane: width === lane.width ? lane : { ...lane, width },
61
+ lane: wrunRowLaneAtWidth(lane, width),
42
62
  maxCells,
63
+ capacity: wrunSheetCellBlockTuples(metadata, input),
43
64
  });
44
65
  }
45
66
  return planned;
@@ -93,7 +114,9 @@ function wrunRowLaneUnserved(lane, plane, indexMode, run, ctx) {
93
114
  * 3. the lane's identity, once per lane (the first admitted input's context names a refusal), then the input's
94
115
  * facets (awaited, in declaration order), each knob naming a setting first read as the setting's current value
95
116
  * (`resolveWrunOptionSettingKnobs` over `run.paramValues`), the context carrying the plan's facts beside the chart
96
- * (`WrunRowLanePlanFacts`); the instance is the identity and the facets together. A lane with
117
+ * (`WrunRowLanePlanFacts`); the instance is the identity and the facets together. An input naming another root
118
+ * (contract F's `underlying`, `planWrunRowLaneUnderlying`) is planned against that root's market instead, its
119
+ * identity once per lane and market. A lane with
97
120
  * `acquisitions: 'one'` refuses a second input whose acquisition differs (one fetch, one live fold per package). A
98
121
  * chart with no option chain (an identity or facets refusal seeded `no-options` / `chain`, `wrunLaneNoChainRefusal`:
99
122
  * a LINK perp, a forex pair) does not serve the feed either: the same one rule, its note naming the feed with the
@@ -109,7 +132,7 @@ export async function planWrunRowLanes(metadata, chart, run) {
109
132
  const indexMode = chart.isIndexModeExchange?.(chart.exchange) === true;
110
133
  const cryptoVenue = chart.isCryptoVenueExchange?.(chart.exchange);
111
134
  // The chart's OPRA plane facts, read once, as the poll lanes' planner reads them (`wrunChartOpraPlane`).
112
- const plane = wrunChartOpraPlane(chart.exchange, chart);
135
+ const plane = wrunChartOpraPlane(chart, chart);
113
136
  const params = metadata.params ?? [];
114
137
  const plannedInputs = planWrunRowLaneInputs(metadata);
115
138
  const laneMaxCells = wrunRowLaneMaxCellsByClass(plannedInputs);
@@ -133,7 +156,13 @@ export async function planWrunRowLanes(metadata, chart, run) {
133
156
  laneMaxCells: laneMaxCells.get(lane.sourceClass),
134
157
  params,
135
158
  ...(run?.paramValues !== undefined ? { paramValues: run.paramValues } : {}),
159
+ // A chain lane holds the planner's plane verdict where the run judged the plane, as a chain poll lane does: its
160
+ // chain there is the plane's own by coin, read without the gate.
161
+ ...(lane.chain !== undefined && chart.isOpraPlaneExchange !== undefined ? { opraPlane: plane.onPlane } : {}),
136
162
  };
163
+ // A chain lane reads the run's one options market: a stock twin's stock in place of the chart's
164
+ // (`wrunChainLaneContext`); every other lane, and every chain lane of any other chart, the chart's own context.
165
+ const chainCtx = lane.chain !== undefined ? wrunChainLaneContext(ctx, run?.options) : ctx;
137
166
  const unserved = {
138
167
  inputName: planned.inputName,
139
168
  sourceClass: lane.sourceClass,
@@ -144,7 +173,7 @@ export async function planWrunRowLanes(metadata, chart, run) {
144
173
  // where a known stop keeps them off the plane (`wrunChainLaneStop`, the chain poll lanes' one rule). Any other lane
145
174
  // is admitted by its plane or the chart's mode.
146
175
  const why = lane.chain !== undefined
147
- ? wrunChainLaneStop(plane, run, ctx)
176
+ ? wrunChainLaneStop(plane, run, chainCtx, planned.source.venue)
148
177
  : wrunRowLaneUnserved(lane, plane, indexMode, run, ctx);
149
178
  if (why !== undefined) {
150
179
  wrunUnservedLaneInput(missing, unserved, WRUN_ROW_LANE_UNSERVED_FILLS, why, cryptoVenue);
@@ -152,14 +181,27 @@ export async function planWrunRowLanes(metadata, chart, run) {
152
181
  }
153
182
  let extras;
154
183
  try {
155
- let identity = identities.get(lane.laneKey);
184
+ // Contract F: an input naming another root (`underlying`) is planned against that root's market
185
+ // (`planWrunRowLaneUnderlying`); "auto" (absent too) against the chart's, as every other lane's input.
186
+ const underlying = wrunTakesUnderlying(lane.sourceClass)
187
+ ? await planWrunRowLaneUnderlying(planned.source, chainCtx, run)
188
+ : undefined;
189
+ if (underlying !== undefined && 'why' in underlying) {
190
+ wrunUnservedLaneInput(missing, unserved, WRUN_ROW_LANE_UNSERVED_FILLS, underlying.why, cryptoVenue);
191
+ continue;
192
+ }
193
+ const laneCtx = underlying?.ctx ?? chainCtx;
194
+ const identityKey = underlying === undefined ? lane.laneKey : `${lane.laneKey}|${underlying.key}`;
195
+ let identity = identities.get(identityKey);
156
196
  if (identity === undefined) {
157
- identity = definedFields(await lane.identity?.(ctx));
158
- identities.set(lane.laneKey, identity);
197
+ identity = definedFields(await lane.identity?.(laneCtx));
198
+ identities.set(identityKey, identity);
159
199
  }
160
200
  // A knob naming a setting reads its current value first: a settings change re-plans and re-asks.
161
- const source = resolveWrunOptionSettingKnobs(ctx, planned.source, params, run?.paramValues);
162
- extras = { ...identity, ...definedFields(await lane.facets?.(source, ctx)) };
201
+ const read = resolveWrunOptionSettingKnobs(ctx, planned.source, params, run?.paramValues);
202
+ // A root the chart's own crypto venue lists reads that venue, unless the input declares a venue of its own.
203
+ const source = underlying === undefined ? read : { ...read, venue: wrunUnderlyingVenueWord(read.venue, underlying.market) };
204
+ extras = { ...identity, ...definedFields(await lane.facets?.(source, laneCtx)) };
163
205
  }
164
206
  catch (error) {
165
207
  // A chart with no option chain does not serve the feed (`wrunLaneNoChainRefusal`): the same one rule.
@@ -189,6 +231,40 @@ export async function planWrunRowLanes(metadata, chart, run) {
189
231
  }
190
232
  return { lanes: [...instances.values()], missingFeeds: [...missing.values()] };
191
233
  }
234
+ /**
235
+ * Contract F (SKYLIT-PARITY, derived-roots.util): one input of a lane that takes the `underlying` knob
236
+ * (`option_strikes`) naming another root ("SPX", "derived" for the derived table's default root of the chart's root, a
237
+ * setting picking one, read first: `resolveWrunUnderlyingSettingKnob`) is planned against that root's market, as if the
238
+ * chart were that market (`wrunUnderlyingLaneContext`): the lane's own identity and facets read the root's chain through
239
+ * the one chain resolver, so every venue and book word, wall and refusal of the lane holds, and the instance's
240
+ * acquisition names the root's chain. An OPRA root meets the OPRA wall before any read (`opra-official-only:<class>`),
241
+ * then, kept off the plane by a known stop (the `opra` flag dark), the stop's rule (`wrunUnservedLaneInput`, the chain
242
+ * lanes' own for a stopped chart); a CME root meets the CME display wall before any read too.
243
+ * A root no venue family lists refuses by name (`wrun_underlying_unresolved:<root>`, the no-chain seed). Undefined:
244
+ * "auto" (absent too), the chart's own chain.
245
+ */
246
+ async function planWrunRowLaneUnderlying(source, ctx, run) {
247
+ const read = resolveWrunUnderlyingSettingKnob(ctx, source, ctx.params ?? [], run?.paramValues);
248
+ const root = wrunUnderlyingRootOf(wrunUnderlyingKnob(read, ctx), ctx);
249
+ if (root === undefined)
250
+ return undefined;
251
+ const market = await resolveWrunUnderlyingMarket(root, ctx, run);
252
+ // A CME root's chain is CME options data whatever the chart: the display wall before any read (and after the facets,
253
+ // as for every chain instance).
254
+ if (market.family === 'cme')
255
+ assertWrunLaneChainPlaneReadable('cme', market.exchange, run, ctx);
256
+ if (market.family === 'opra') {
257
+ assertWrunOpraLaneReadable(run, ctx);
258
+ if (market.opraStop !== undefined) {
259
+ return { why: { words: wrunOpraPlaneStopDetail(market.opraStop), stop: market.opraStop } };
260
+ }
261
+ }
262
+ return {
263
+ ctx: wrunUnderlyingLaneContext(ctx, market),
264
+ key: `${market.exchange}|${market.symbol}|${market.coin}|${market.venue ?? ''}`,
265
+ market,
266
+ };
267
+ }
192
268
  /** The most `max_cells` among a sheet's planned inputs of each row-lane class (`WrunRowLanePlanFacts.laneMaxCells`). */
193
269
  function wrunRowLaneMaxCellsByClass(planned) {
194
270
  const most = new Map();
@@ -277,23 +353,119 @@ export function wrunRowLaneFetchOptions(lane) {
277
353
  }
278
354
  /** The payload field a tiered ask names its backend tier in (`landing.tiers`, the tier's key). */
279
355
  export const WRUN_ROW_LANE_TIER_FIELD = 'tier';
356
+ /** A row lane's window bounded at a replay cursor (`WrunRowLaneWindow.replayCursorMs`): a flow or snapshot lane's bars
357
+ * opening after the cursor are left out; a `latest` lane (the live row's snapshot), and a window naming no cursor,
358
+ * as they are. */
359
+ export function wrunRowLaneWindowAtReplayCursor(lane, window) {
360
+ const cursor = window.replayCursorMs;
361
+ if (lane.landing.kind === 'latest' || cursor === undefined || !Number.isFinite(cursor))
362
+ return window;
363
+ const barOpens = window.barOpens.filter((stampMs) => stampMs <= cursor);
364
+ return barOpens.length === window.barOpens.length ? window : { ...window, barOpens };
365
+ }
366
+ /** Whether a row lane instance reads per bar (a flow or snapshot landing): the lanes a replay's cursor bounds. */
367
+ function wrunRowLaneReadsPerBar(instance) {
368
+ const lane = wrunRowLaneByKey(instance.laneKey);
369
+ return lane !== undefined && lane.landing.kind !== 'latest';
370
+ }
371
+ /**
372
+ * The row lane instances a replay run reads through its cursor (`wrunRowLaneWindowAtReplayCursor`: the flow and snapshot
373
+ * lanes), by key: the session's coverage of each is the cursor, never the replay window's end its other lanes reach, so
374
+ * each replay step extends them (`wrunReplayRowLaneExtensions`) and the replay record keeps naming the window's end.
375
+ */
376
+ export function wrunRowLanesReplayBounded(instances) {
377
+ return new Set((instances ?? []).filter(wrunRowLaneReadsPerBar).map((instance) => instance.key));
378
+ }
379
+ /**
380
+ * What a replay step owes a session's row lanes before it computes the bars it reveals (SKYLIT-PARITY L6a): each flow
381
+ * or snapshot lane covered short of the step's cursor (`coveredThroughTs`, the newest bar its buffer holds), from the
382
+ * bar after its coverage (`fromTs`) through the cursor. A lane holding no coverage (the run degraded it) is left to its
383
+ * degrade, and a `latest` lane to its live-row snapshot.
384
+ */
385
+ export function wrunReplayRowLaneExtensions(instances, coveredThroughTs, cursorMs) {
386
+ if (!Number.isFinite(cursorMs))
387
+ return [];
388
+ const owed = [];
389
+ for (const instance of instances ?? []) {
390
+ if (!wrunRowLaneReadsPerBar(instance))
391
+ continue;
392
+ const covered = coveredThroughTs[instance.key];
393
+ if (typeof covered !== 'number' || !Number.isFinite(covered) || covered >= cursorMs)
394
+ continue;
395
+ owed.push({ key: instance.key, fromTs: covered + 1 });
396
+ }
397
+ return owed;
398
+ }
399
+ /** 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
400
+ * a held one of the same bar (a replay holds no live-folded row an answer could lose). */
401
+ export function mergeWrunReplayRowLaneRows(held, answer) {
402
+ const byBar = new Map();
403
+ for (const rows of [held ?? [], answer]) {
404
+ for (const row of rows) {
405
+ const ts = Number(row[0]);
406
+ if (Number.isFinite(ts))
407
+ byBar.set(ts, row);
408
+ }
409
+ }
410
+ return [...byBar.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
411
+ }
412
+ /** The add a row lane read belongs to (`WrunRowLaneFetchOptions.addMemo`): the chart, the indicator, the instance. */
413
+ export function wrunRowLaneAddKey(chartIndex, indicatorId, instanceKey) {
414
+ return `${chartIndex}|${indicatorId}|${instanceKey}`;
415
+ }
280
416
  /**
281
417
  * A row lane's rows over a chart window `[barOpens[0], last bar's end)`: a flow or snapshot lane's asks under the
282
418
  * 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
283
419
  * extras), cut to its horizon and its row budget, each answer landed on the host bars (`wrunLandCellRowsOnHostBars`,
284
420
  * the lane's own `fold` when it has one), a snapshot's bar its tier answered nothing for asked again one tier coarser
285
421
  * where one fits and retains it when the lane's `coarserWhenEmpty` says so of the acquisition (D12), and the bars no
286
- * tier retains (or the budget left out) marked partial (bit 14, a marker tuple when empty); a `latest` lane asked
287
- * once over `fallback`, its rows as they come. A flow sums every bucket inside its bar, so its plan reads the window's
288
- * bar grid as its session grid (wrun-tier-grid.util `wrunCmeSessionBarSpan`): a CME session bar of a day or longer
289
- * is fit, budgeted and asked over its Globex session, from the 17:00 Chicago open before its 00:00Z stamp, never from
290
- * a UTC day bucket; a snapshot keeps its stamps (D12's settlement DAY rows). `ask` is the caller's fetch (the full
291
- * run's, a reconcile's). Ascending, one row per host bar.
422
+ * tier retains (or the budget left out) marked partial (bit 14, a marker tuple when empty; never on an instance its
423
+ * facets widen, whose rows carry no mask: `wrunRowLaneAtWidth`); a `latest` lane asked once over `fallback`, its rows
424
+ * as they come. A flow sums every bucket inside its bar, so its plan reads the window's bar grid as its session grid
425
+ * (wrun-tier-grid.util `wrunCmeSessionBarSpan`): a CME session bar of a day or longer is fit, budgeted and asked over
426
+ * its Globex session, from the 17:00 Chicago open before its 00:00Z stamp, never from a UTC day bucket; a snapshot
427
+ * keeps its stamps (D12's settlement DAY rows). `ask` is the caller's fetch (the full run's, a reconcile's).
428
+ * Ascending, one row per host bar.
429
+ *
430
+ * A row-budget lane's first-paint slice is cut on a trade date's first bar wherever the chart reads trade dates
431
+ * (`window.tradeDateOf`), on every run, so it holds whole sessions and every run asks the same windows.
432
+ * `opts.onFirstSlice` (a full run's first paint): every ask still leaves at once and the promise still answers the
433
+ * whole window, but the slice's own answer is handed over first, once, if it lands with rows while an older ask is
434
+ * still out a macrotask later: the slice's rows, every older bar the projection reads rows for read partial
435
+ * (wrun-row-lane-first-paint.util `wrunRowLaneFirstSliceHeldBars`), and the slice's first bar. Never when no cut falls
436
+ * on a session's first bar (a session longer than the slice: the plain split, asked as today), for a block with no
437
+ * `present` mask (it cannot read a bar as partial), a kit fold carrying the next bar (its pages ask one at a time),
438
+ * Strike Footprint's per-(expiry, strike) rows (it learns its strike step over the whole run:
439
+ * wrun-row-lane-first-paint.util `wrunRowLaneDrawsFirstSlice`), or a snapshot whose empty bars ask a coarser tier (that
440
+ * pass would ask the slice's bars again).
441
+ *
442
+ * A row budget that leaves asked bars partial says so before any ask leaves (`opts.onBudgetCut`, and the debug ring).
443
+ *
444
+ * `opts.download` (a budgeted run, OPTLOAD W3 R2; `landWithinDownloadShare`): after the tier rule, the horizon and the
445
+ * row budget (the smaller cut wins), the read asks its newest slice first and alone, then the newest older bars its
446
+ * share fits by the slice's own wire bytes, and no others; every bar it leaves unasked reads partial (bit 14 with the
447
+ * marker tuple; an empty block on a class with no `present` mask), and the cut is named once the asks landed
448
+ * (`onBudgetCut`, `budget: 'download'`). No early handover in that mode. Absent: today's asks, exactly.
449
+ *
450
+ * A replay's window (`window.replayCursorMs`, plan L6a): a flow or snapshot lane's bars end at the replay's cursor
451
+ * (`wrunRowLaneWindowAtReplayCursor`), so nothing after it is asked, and the read keeps a replay memo (the add memo's
452
+ * machinery, `role: 'replay'`, never the add's own): a replay step's read of the bars it reveals
453
+ * (wrun-live-tick.util, `wrunReplayRowLaneExtensions`) and a reopened run reuse the bars landed whole and final and
454
+ * ask the rest. A read that names no cursor asks exactly as before.
455
+ *
456
+ * `ask` reports its answer's completion through its fourth argument (`whole`: the chart's fetch verdict,
457
+ * wrun-source-rows.util `wrunSourceVerdictWhole`); an ask that never reports is not whole. A memo admits a bar only from
458
+ * an ask reported whole, and the bars of every other ask are named to the caller (`opts.onUnconfirmed`), so a synthetic
459
+ * completion's empty or short answer is asked again, never remembered as the bar.
292
460
  */
293
- export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask) {
461
+ export async function fetchWrunRowLaneRows(lane, extras, askedWindow, fallback, ask, opts = {}) {
294
462
  const landing = lane.landing;
295
- // The instance's rows are its facets' (a strike kit fold's 14-value rows), read as plain tuples once landed.
296
- const width = wrunOptionLaneTupleWidth(lane.sourceClass, extras, lane.width);
463
+ // A replay run's per-bar lane ends at the replay's cursor: no bar after it is asked.
464
+ const window = wrunRowLaneWindowAtReplayCursor(lane, askedWindow);
465
+ // The instance's rows are its facets' (a strike kit fold's 14-value rows), read as plain tuples once landed; at
466
+ // another width than the class's they carry no `present` mask (`wrunRowLaneAtWidth`).
467
+ const sized = wrunRowLaneAtWidth(lane, wrunOptionLaneTupleWidth(lane.sourceClass, extras, lane.width));
468
+ const width = sized.width;
297
469
  if (landing.kind === 'latest') {
298
470
  return (await ask(extras, fallback.fromTs, fallback.toTs)).map((row) => wrunRowLanePlainRow(row, width));
299
471
  }
@@ -301,33 +473,197 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask)
301
473
  // What the row budget and the first-paint slice project the window's bars under: the instance's payload with
302
474
  // `history` "today" dated off the window's newest bar as each ask's K control dates it (`wrunRowLaneBudgetAcquisition`).
303
475
  const budgetAcquisition = await wrunRowLaneBudgetAcquisition(lane, extras, window);
304
- const { asks, partialBars } = wrunRowLaneAsksWithinRowBudget(wrunRowLaneAsksWithinHorizon(wrunHostGridAsks({
476
+ const withinHorizon = wrunRowLaneAsksWithinHorizon(wrunHostGridAsks({
305
477
  tiers: landing.tiers,
306
478
  barOpens: window.barOpens,
307
479
  intervalMs: window.intervalMs,
308
480
  nowMs: window.nowMs,
309
481
  choice: landing.tierChoice,
310
482
  sessionGrid,
311
- }), window, lane.horizon?.(extras, window.nowMs), sessionGrid), window, lane.rowBudget, budgetAcquisition, sessionGrid);
483
+ }), window, lane.horizon?.(extras, window.nowMs), sessionGrid);
484
+ // Every projection of this read, the budget's and the first paint's, at least what the lane's reads measured.
485
+ const rowBudget = lane.rowBudget === undefined ? undefined : wrunRowLaneMeasuredBudget(lane, lane.rowBudget, extras);
486
+ const budgeted = wrunRowLaneAsksWithinRowBudget(withinHorizon, window, rowBudget, budgetAcquisition, sessionGrid);
487
+ const { asks, partialBars } = budgeted;
488
+ // The budget hands back the plan it was given unless it cut bars out of it.
489
+ if (budgeted !== withinHorizon && lane.rowBudget !== undefined) {
490
+ const cut = wrunRowLaneBudgetCutOf(lane.laneKey, lane.rowBudget, withinHorizon, budgeted, window, sessionGrid);
491
+ reportWrunRowLaneBudgetCut(cut, window.intervalMs, opts.onBudgetCut);
492
+ }
493
+ // One download budget per add (`opts.addMemo`, wrun-row-lane-add-memo.util): the bars a budgeted read of this add
494
+ // already landed whole and final are reused, the bars its budget cut stay partial, and only the rest is asked. A
495
+ // replay's read keeps its own memo, never the add's, so a later read at its cursor asks only the bars it lacks.
496
+ const addMemo = window.replayCursorMs !== undefined && Number.isFinite(window.replayCursorMs)
497
+ ? { key: `replay|${wrunRowLaneAddFingerprintOf(lane, extras, window)}`, role: 'replay' }
498
+ : opts.addMemo;
499
+ const memoUtil = addMemo === undefined ? undefined : await import('./wrun-row-lane-add-memo.util.js');
500
+ const memoFingerprint = addMemo === undefined ? '' : wrunRowLaneAddFingerprintOf(lane, extras, window);
501
+ const wholeRun = addMemo?.role === 'run' && opts.download === undefined;
502
+ if (wholeRun && memoUtil !== undefined && addMemo !== undefined)
503
+ memoUtil.forgetWrunRowLaneAdd(addMemo.key);
504
+ const memo = memoUtil === undefined || addMemo === undefined || wholeRun
505
+ ? undefined
506
+ : memoUtil.wrunRowLaneAddMemoOf(addMemo.key, memoFingerprint);
507
+ const heldCut = memo === undefined ? [] : window.barOpens.filter((stampMs) => memo.cut.has(stampMs) && !memo.landed.has(stampMs));
508
+ const freshAsks = memo === undefined || memoUtil === undefined
509
+ ? asks
510
+ : memoUtil.wrunRowLaneAsksOverBars(asks, (stampMs) => !memo.landed.has(stampMs) && !memo.cut.has(stampMs), window, sessionGrid);
511
+ const planPartial = heldCut.length === 0 ? partialBars : [...new Set([...partialBars, ...heldCut])].sort((a, b) => a - b);
312
512
  // A row-budget lane's newest bars are asked first and on their own (wrun-row-lane-first-paint.util, off the boot path),
313
513
  // and so are an instance's whose facets ask a per-bar word of the gateway (OPTLOAD G5: a surface pick, the strike kit
314
514
  // fold), sized by the rows its answer holds; every other instance asks as the tier rule made it.
315
- const sliceBudget = lane.rowBudget ?? wrunOptionLaneFirstPaintBudget(lane.sourceClass, extras, lane.width);
316
- const ordered = sliceBudget === undefined
317
- ? asks
318
- : (await import('./wrun-row-lane-first-paint.util.js')).wrunRowLaneFirstPaintAsks(asks, window, sliceBudget, budgetAcquisition, sessionGrid);
515
+ const sliceBudget = rowBudget ?? wrunOptionLaneFirstPaintBudget(lane.sourceClass, extras, lane.width);
516
+ // A budgeted run of an add that already spent reads within what is left of the add's share.
517
+ const download = opts.download === undefined || memo === undefined
518
+ ? opts.download
519
+ : { ...opts.download, share: Math.max(0, memo.shareBytes - memo.spentBytes) };
520
+ const firstPaint = sliceBudget === undefined && download === undefined ? undefined : await import('./wrun-row-lane-first-paint.util.js');
521
+ // The slice is cut on a trade date's first bar wherever the chart reads trade dates (`window.tradeDateOf`), so it
522
+ // holds whole sessions, on every run alike: a first paint asks the windows a later run asks (one cache entry each).
523
+ const split = firstPaint === undefined || sliceBudget === undefined
524
+ ? undefined
525
+ : firstPaint.wrunRowLaneFirstPaintSplit(freshAsks, window, sliceBudget, budgetAcquisition, sessionGrid, window.tradeDateOf);
526
+ const ordered = split === undefined ? freshAsks : [...split.first, ...split.older];
527
+ // The bars the slice's early answer holds back (`opts.onFirstSlice`), or undefined when it has none.
528
+ const coarserPass = landing.kind === 'snapshot' && landing.tiers !== undefined && landing.coarserWhenEmpty?.(extras) === true;
529
+ const heldBack = opts.onFirstSlice === undefined ||
530
+ download !== undefined ||
531
+ firstPaint === undefined ||
532
+ split === undefined ||
533
+ sliceBudget === undefined ||
534
+ sized.presentMask === false ||
535
+ coarserPass ||
536
+ wrunOptionLaneCarriesNext(lane.sourceClass, extras) ||
537
+ !firstPaint.wrunRowLaneDrawsFirstSlice(lane.sourceClass, extras)
538
+ ? undefined
539
+ : firstPaint.wrunRowLaneFirstSliceHeldBars(split, window, sliceBudget, budgetAcquisition, sessionGrid);
319
540
  const fold = landing.fold;
320
- // `askToMs` reads past the ask's own end (a kit fold's seam, below); only the ask's own bars ever land.
321
- const askAndLand = async (gridAsk, askToMs = gridAsk.toMs) => {
322
- const askExtras = gridAsk.tier === undefined ? extras : { ...extras, [WRUN_ROW_LANE_TIER_FIELD]: gridAsk.tier.key };
541
+ // The bars of every ask the chart's fetch did not confirm whole (`ask`'s verdict): no memo admits them.
542
+ const unconfirmed = new Set();
543
+ // `askToMs` reads past the ask's own end (a kit fold's seam, below); only the ask's own bars ever land. `more`: the
544
+ // fields a budgeted read's ask names beside the payload (a browser fold's row cap, FE-FOLD-CAP).
545
+ const askAndLand = async (gridAsk, askToMs = gridAsk.toMs, more) => {
546
+ const payload = more === undefined ? extras : { ...extras, ...more };
547
+ const askExtras = gridAsk.tier === undefined ? payload : { ...payload, [WRUN_ROW_LANE_TIER_FIELD]: gridAsk.tier.key };
548
+ const heard = { whole: false };
549
+ const answer = await ask(askExtras, gridAsk.fromMs, askToMs, (answered) => {
550
+ heard.whole = answered;
551
+ });
552
+ if (!heard.whole) {
553
+ for (const stampMs of window.barOpens) {
554
+ const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
555
+ if (fromMs >= gridAsk.fromMs && fromMs < gridAsk.toMs)
556
+ unconfirmed.add(stampMs);
557
+ }
558
+ }
323
559
  // Rows stamped at or past the ask's end belong to a bar the plan did not ask (a skipped newest bar): never land
324
560
  // them, whatever the control answered.
325
- const rows = (await ask(askExtras, gridAsk.fromMs, askToMs)).filter((row) => Number(row[0]) < gridAsk.toMs);
561
+ const rows = answer.filter((row) => Number(row[0]) < gridAsk.toMs);
326
562
  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));
327
563
  };
328
564
  const byBar = new Map();
329
- if (!wrunOptionLaneCarriesNext(lane.sourceClass, extras)) {
330
- for (const landed of await Promise.all(ordered.map((gridAsk) => askAndLand(gridAsk)))) {
565
+ // The add's landed bars come back as they landed (a copy: the memo's rows are never handed out to be written).
566
+ if (memo !== undefined) {
567
+ const inWindow = new Set(window.barOpens);
568
+ for (const [stampMs, row] of memo.landed) {
569
+ if (row !== undefined && inWindow.has(stampMs)) {
570
+ byBar.set(stampMs, row.map((cell) => (Array.isArray(cell) ? cell.slice() : cell)));
571
+ }
572
+ }
573
+ }
574
+ const landAll = (gridAsks) => Promise.all(gridAsks.map((gridAsk) => askAndLand(gridAsk)));
575
+ // The asks the read sent and the bars it reads partial: the plan's, unless a budgeted read left older bars unasked.
576
+ let sentAsks = freshAsks;
577
+ let readPartial = planPartial;
578
+ if (download !== undefined && firstPaint !== undefined && freshAsks.length === 0) {
579
+ // Every bar of the window is the add's already (landed or cut): nothing is asked.
580
+ sentAsks = [];
581
+ }
582
+ else if (download !== undefined && firstPaint !== undefined) {
583
+ // OPTLOAD W3 R2: the newest slice first and alone, then the newest older bars the read's share fits by the slice's
584
+ // own wire bytes, and no others (`landWithinDownloadShare`). No early handover: the older asks leave once the
585
+ // slice landed, so the whole answer is the first picture.
586
+ const carriesNext = wrunOptionLaneCarriesNext(lane.sourceClass, extras);
587
+ const landGroup = async (gridAsks, more) => {
588
+ if (!carriesNext) {
589
+ const answers = await Promise.all(gridAsks.map((gridAsk) => askAndLand(gridAsk, gridAsk.toMs, more)));
590
+ for (const landed of answers)
591
+ for (const row of landed)
592
+ byBar.set(Number(row[0]), row);
593
+ return;
594
+ }
595
+ // A kit fold carrying the next bar: newest first, one at a time, each read through its seam (as below).
596
+ for (const gridAsk of [...gridAsks].sort((a, b) => b.fromMs - a.fromMs)) {
597
+ const end = wrunRowLaneSeamEndMs(gridAsk, byBar, window.intervalMs);
598
+ for (const row of await askAndLand(gridAsk, end, more))
599
+ byBar.set(Number(row[0]), row);
600
+ }
601
+ };
602
+ const within = await landWithinDownloadShare({
603
+ laneKey: lane.laneKey,
604
+ extras,
605
+ width,
606
+ window,
607
+ sessionGrid,
608
+ asks: freshAsks,
609
+ partialBars: planPartial,
610
+ budgetAcquisition,
611
+ sliceBudget,
612
+ download,
613
+ firstPaint,
614
+ land: landGroup,
615
+ landedData: (stampMs) => (byBar.get(stampMs) ?? [])
616
+ .slice(1)
617
+ .some((tuple) => Array.isArray(tuple) &&
618
+ tuple.length > 0 &&
619
+ (sized.presentMask === false || !wrunPresentIsPartial(Number(tuple[tuple.length - 1])))),
620
+ });
621
+ sentAsks = within.sent;
622
+ readPartial = within.partialBars;
623
+ }
624
+ else if (heldBack !== undefined && split !== undefined && opts.onFirstSlice !== undefined) {
625
+ // Every ask leaves at once, as below; the slice's answer is handed over first while an older ask is still out.
626
+ const onFirstSlice = opts.onFirstSlice;
627
+ // The slice's first bar: the first bar the cut keeps (every bar before it is held).
628
+ const cutMs = split.sliceFromMs ?? Number.POSITIVE_INFINITY;
629
+ const sliceFromTs = window.barOpens.find((stampMs) => wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid).fromMs >= cutMs);
630
+ const firstLanded = landAll(split.first);
631
+ const olderLanded = landAll(split.older);
632
+ let olderSettled = false;
633
+ void olderLanded.then(() => {
634
+ olderSettled = true;
635
+ }, () => {
636
+ olderSettled = true;
637
+ });
638
+ void firstLanded
639
+ .then(async (answers) => {
640
+ // One macrotask before the handover is judged: older asks that answered in the same turn (a cache) settle
641
+ // first, so a window already whole never draws half of itself and a rung to adopt the rest.
642
+ await new Promise((resolve) => setTimeout(resolve, 0));
643
+ if (olderSettled || sliceFromTs === undefined)
644
+ return;
645
+ const held = new Set(heldBack);
646
+ const slice = new Map();
647
+ for (const landed of answers) {
648
+ for (const row of landed)
649
+ if (!held.has(Number(row[0])))
650
+ slice.set(Number(row[0]), row);
651
+ }
652
+ if (slice.size === 0)
653
+ return;
654
+ const rows = [...slice.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
655
+ onFirstSlice(wrunCellRowsWithPartialBars(rows, [...new Set([...partialBars, ...heldBack])], width), sliceFromTs);
656
+ }, () => undefined)
657
+ // A failed handover only costs the early picture: the whole answer still comes.
658
+ .catch(() => undefined);
659
+ const [firstAnswers, olderAnswers] = await Promise.all([firstLanded, olderLanded]);
660
+ for (const landed of [...firstAnswers, ...olderAnswers]) {
661
+ for (const row of landed)
662
+ byBar.set(Number(row[0]), row);
663
+ }
664
+ }
665
+ else if (!wrunOptionLaneCarriesNext(lane.sourceClass, extras)) {
666
+ for (const landed of await landAll(ordered)) {
331
667
  for (const row of landed)
332
668
  byBar.set(Number(row[0]), row);
333
669
  }
@@ -346,7 +682,7 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask)
346
682
  // acquisition its lane says so of (`coarserWhenEmpty`: a CME surface's daily bar whose 5m tier holds no session
347
683
  // yet reads its settlement DAY row, never nothing); a fallback row fills only a bar still empty.
348
684
  if (landing.kind === 'snapshot' && landing.tiers !== undefined && landing.coarserWhenEmpty?.(extras) === true) {
349
- for (let pending = asks;;) {
685
+ for (let pending = sentAsks;;) {
350
686
  const fallback = wrunHostGridFallbackAsks({
351
687
  tiers: landing.tiers,
352
688
  asks: pending,
@@ -366,8 +702,296 @@ export async function fetchWrunRowLaneRows(lane, extras, window, fallback, ask)
366
702
  }
367
703
  }
368
704
  const landed = [...byBar.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row);
369
- // A class with no `present` mask marks nothing: a partial bar asked nothing and reads an empty block.
370
- return lane.presentMask === false ? landed : wrunCellRowsWithPartialBars(landed, partialBars, width);
705
+ if (lane.rowBudget !== undefined) {
706
+ noteWrunRowLaneMeasured(lane.laneKey, extras, sentAsks, byBar, readPartial, window, sessionGrid, sized.presentMask);
707
+ }
708
+ const foldPartial = (download?.fold ?? lane.download?.fold) !== undefined && sized.presentMask !== false;
709
+ if (download !== undefined && opts.download !== undefined) {
710
+ // The download budget's cut, named once the asks landed: the bars the share left unread, and the bars a browser
711
+ // fold left partial under its cap (FE-FOLD-CAP), the source answer budget's own cut kept apart; the add's cut and
712
+ // its whole spend when a memo served the read.
713
+ const cut = wrunRowLaneDownloadCutOf({
714
+ laneKey: lane.laneKey,
715
+ width,
716
+ window,
717
+ sessionGrid,
718
+ asks,
719
+ before: partialBars,
720
+ after: readPartial,
721
+ byBar,
722
+ foldPartial,
723
+ spentBytes: (memo?.spentBytes ?? 0) + download.meter.spentBytes(),
724
+ shareBytes: opts.download.share,
725
+ });
726
+ if (cut.cutBars > 0)
727
+ reportWrunRowLaneBudgetCut(cut, window.intervalMs, opts.onBudgetCut);
728
+ }
729
+ // The asks the chart's fetch did not confirm whole, named once they all landed.
730
+ if (unconfirmed.size > 0)
731
+ opts.onUnconfirmed?.([...unconfirmed].sort((a, b) => a - b));
732
+ // The add's memo after this read: a budgeted run's leaves one, a replay's read too (a whole read or not), and a read
733
+ // the memo served brings it up to date; a bar an unconfirmed ask answered joins none (asked again by the next read).
734
+ if (memoUtil !== undefined &&
735
+ addMemo !== undefined &&
736
+ (opts.download !== undefined || memo !== undefined || addMemo.role === 'replay')) {
737
+ const asked = (stampMs) => {
738
+ const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
739
+ return sentAsks.some((gridAsk) => fromMs >= gridAsk.fromMs && fromMs < gridAsk.toMs);
740
+ };
741
+ const askedBars = window.barOpens.filter(asked);
742
+ memoUtil.rememberWrunRowLaneAdd(addMemo.key, memoUtil.wrunRowLaneAddMemoAfter({
743
+ previous: memo,
744
+ fingerprint: memoFingerprint,
745
+ window,
746
+ sessionGrid,
747
+ askedBars,
748
+ landedRows: byBar,
749
+ partialBars: new Set([...readPartial, ...unconfirmed]),
750
+ marked: (row) => foldPartial && wrunRowLaneRowMarkedPartial(row),
751
+ cutBars: opts.download === undefined
752
+ ? []
753
+ : [
754
+ ...readPartial,
755
+ ...askedBars.filter((stampMs) => {
756
+ const row = byBar.get(stampMs);
757
+ return foldPartial && row !== undefined && wrunRowLaneRowMarkedPartial(row);
758
+ }),
759
+ ],
760
+ spentBytes: download?.meter.spentBytes() ?? 0,
761
+ shareBytes: opts.download?.share,
762
+ }));
763
+ }
764
+ // A block with no `present` mask (its class's, or an instance's its facets widen) marks nothing: a partial bar asked
765
+ // nothing and reads an empty block.
766
+ return sized.presentMask === false ? landed : wrunCellRowsWithPartialBars(landed, readPartial, width);
767
+ }
768
+ /** Whether a landed row carries a partial mark (bit 14 on a tuple's `present`, its last cell). */
769
+ function wrunRowLaneRowMarkedPartial(row) {
770
+ return row.slice(1).some((tuple) => Array.isArray(tuple) && wrunPresentIsPartial(Number(tuple[tuple.length - 1])));
771
+ }
772
+ /** The add memo's fingerprint (wrun-row-lane-add-memo.util): the lane, the acquisition without a per-ask field (the
773
+ * measured key's skips and the lane's fold cap) and the bar span. A run's extras and a reconcile's recorded acquisition
774
+ * of the same instance print the same. Never the bar grid's record: the live session's market names no
775
+ * `transformations` where the chart's metadata does (INT 2026-10-23: every reconcile missed the run's memo), and the
776
+ * memo's bars are matched by their stamps anyway. */
777
+ function wrunRowLaneAddFingerprintOf(lane, extras, window) {
778
+ const foldField = lane.download?.fold?.field;
779
+ const fields = {};
780
+ for (const [key, value] of Object.entries(extras))
781
+ if (key !== foldField)
782
+ fields[key] = value;
783
+ return measuredKeyOf(lane.laneKey, fields, undefined, window.intervalMs);
784
+ }
785
+ /** The newest projection a budgeted read measured (`landWithinDownloadShare`), by lane and acquisition: its wire bytes a
786
+ * millisecond of bars. In memory, the newest `MEASURED_KEPT`. */
787
+ const downloadDensity = new Map();
788
+ function rememberDownload(map, key, value) {
789
+ if (!(Number.isFinite(value) && value > 0))
790
+ return;
791
+ map.delete(key);
792
+ map.set(key, value);
793
+ while (map.size > MEASURED_KEPT)
794
+ map.delete(map.keys().next().value);
795
+ }
796
+ /** The first bar of the newest trade date the window reads (`window.tradeDateOf`), or undefined without one. */
797
+ function wrunRowLaneNewestSessionFromMs(window, sessionGrid) {
798
+ const { barOpens, tradeDateOf } = window;
799
+ const newest = barOpens[barOpens.length - 1];
800
+ if (tradeDateOf === undefined || newest === undefined)
801
+ return undefined;
802
+ const date = tradeDateOf(newest);
803
+ if (!Number.isFinite(date))
804
+ return undefined;
805
+ let fromMs;
806
+ for (let at = barOpens.length - 1; at >= 0 && tradeDateOf(barOpens[at]) === date; at -= 1) {
807
+ fromMs = wrunHostBarSpanOf(barOpens[at], window.intervalMs, sessionGrid).fromMs;
808
+ }
809
+ return fromMs;
810
+ }
811
+ /**
812
+ * A budgeted read's asks (OPTLOAD W3 R2, `WrunRowLaneFetchOptions.download`), landed through `land`:
813
+ * 1. its NEWEST SLICE, first and alone: the first-paint split of its asks (wrun-row-lane-first-paint.util) under the
814
+ * 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
815
+ * alone); a read summing a whole session per row (`span` "session") slices on its newest session's first bar, so no
816
+ * older ask reads that session again;
817
+ * 2. once it landed, its wire bytes over the slice's elapsed span (a bar still forming counts its elapsed part, at least
818
+ * a minute) project each older bar by its span; a slice no stamp measured (a cache) reads the read's last measured
819
+ * projection, else the declared rows a bar;
820
+ * 3. the newest older bars whose projections fit the share left after the slice are asked, as one run of bars, and no
821
+ * others: every older bar it leaves unasked joins the partial bars, except a bar its lane projects at nothing (before
822
+ * today under `history` "today": it reads nothing either way);
823
+ * 4. FE-FOLD-CAP: a lane folding contract rows in the browser (`download.fold`) bounds the READ, never each ask: a
824
+ * group of its asks (the slice, the older asks) lands newest first, one ask at a time, each naming the rows the
825
+ * bytes its group may still spend buy at the row's cells (the fold plan's own unit); once the group spent its bytes,
826
+ * its older asks are not sent and their bars read partial. The slice's bytes are the share, never under the first
827
+ * paint's (so it reads its newest bars); the older asks', what the slice left.
828
+ * The sent asks and the bars the read reads partial come back; what the slice measured is remembered for the next read.
829
+ */
830
+ async function landWithinDownloadShare(args) {
831
+ const { window, sessionGrid, asks, download, budgetAcquisition } = args;
832
+ const declared = download.declaredBarRows;
833
+ const sliceRows = args.sliceBudget ??
834
+ (declared !== undefined && declared > 0 ? { cellsPerRow: args.width, barRows: () => declared } : undefined);
835
+ const sessionFrom = args.extras.span === 'session' ? wrunRowLaneNewestSessionFromMs(window, sessionGrid) : undefined;
836
+ const split = sessionFrom !== undefined
837
+ ? args.firstPaint.wrunRowLaneSplitAt(asks, sessionFrom)
838
+ : args.firstPaint.wrunRowLaneFirstPaintSplit(asks, window, sliceRows, budgetAcquisition, sessionGrid);
839
+ const memoryKey = measuredKeyOf(args.laneKey, args.extras, undefined, 0);
840
+ const fold = download.fold;
841
+ const spanOf = (stampMs) => wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
842
+ const askOf = (stampMs, gridAsks) => {
843
+ const { fromMs } = spanOf(stampMs);
844
+ return gridAsks.find((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
845
+ };
846
+ const barsOf = (gridAsks) => window.barOpens.filter((stampMs) => askOf(stampMs, gridAsks) !== undefined);
847
+ // 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
848
+ // 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.
849
+ const landGroup = async (gridAsks, bytes) => {
850
+ if (fold === undefined) {
851
+ await args.land(gridAsks, undefined);
852
+ return { sent: [...gridAsks], unsent: [] };
853
+ }
854
+ const rowBytes = fold.cellsPerRow * KSCRIPT_SOURCE_CELL_BYTES;
855
+ const sent = [];
856
+ const unsent = [];
857
+ let left = bytes;
858
+ for (const gridAsk of [...gridAsks].sort((a, b) => b.fromMs - a.fromMs)) {
859
+ if (sent.length > 0 && left <= 0) {
860
+ unsent.push(gridAsk);
861
+ continue;
862
+ }
863
+ const before = download.meter.spentBytes();
864
+ await args.land([gridAsk], { [fold.field]: Math.max(1, Math.floor(Math.max(0, left) / rowBytes)) });
865
+ sent.push(gridAsk);
866
+ left -= Math.max(0, download.meter.spentBytes() - before);
867
+ }
868
+ return { sent, unsent };
869
+ };
870
+ const bytesBefore = download.meter.spentBytes();
871
+ // The slice reads at least its newest bars whatever the share: a fold's bytes there are never under the first paint's.
872
+ const sliceCap = Math.max(download.share, args.firstPaint.WRUN_ROW_LANE_FIRST_PAINT_BYTES);
873
+ const slice = await landGroup(split.first, sliceCap);
874
+ let sliceSent = slice.sent;
875
+ const sliceUnsent = barsOf(slice.unsent);
876
+ let olderPlan = split.older;
877
+ // A slice that landed no data (its newest bar holds none yet: a delayed route's first minutes of a session) reads the
878
+ // newest older bar beside it, once, so the first picture holds the newest bar with data and the older bars are
879
+ // projected from a measured bar (INT 2026-10-23 13:30Z: Spot Exposures' forming bar answered nothing, its 55 older
880
+ // bars were cut on the kit's declared rows, and the chart drew nothing).
881
+ if (olderPlan.length > 0 && !barsOf(slice.sent).some(args.landedData)) {
882
+ const newestOlder = barsOf(olderPlan).at(-1);
883
+ if (newestOlder !== undefined) {
884
+ const { fromMs, toMs } = spanOf(newestOlder);
885
+ const extension = olderPlan.flatMap((ask) => {
886
+ const askFrom = Math.max(ask.fromMs, fromMs);
887
+ const askTo = Math.min(ask.toMs, toMs);
888
+ return askFrom < askTo ? [{ ...ask, fromMs: askFrom, toMs: askTo }] : [];
889
+ });
890
+ const spent = Math.max(0, download.meter.spentBytes() - bytesBefore);
891
+ const extended = await landGroup(extension, Math.max(sliceCap - spent, args.firstPaint.WRUN_ROW_LANE_FIRST_PAINT_BYTES));
892
+ sliceSent = [...sliceSent, ...extended.sent];
893
+ sliceUnsent.push(...barsOf(extended.unsent));
894
+ olderPlan = olderPlan.flatMap((ask) => {
895
+ const askTo = Math.min(ask.toMs, fromMs);
896
+ return ask.fromMs < askTo ? [{ ...ask, toMs: askTo }] : [];
897
+ });
898
+ }
899
+ }
900
+ const sliceBytes = Math.max(0, download.meter.spentBytes() - bytesBefore);
901
+ if (olderPlan.length === 0) {
902
+ return { sent: sliceSent, partialBars: [...new Set([...args.partialBars, ...sliceUnsent])].sort((a, b) => a - b) };
903
+ }
904
+ // The slice's elapsed span over its bars that landed data (a bar still forming counts what has elapsed of it, at least
905
+ // a minute): a bar that answered nothing spent nothing, and counting it would price the older bars under what they cost.
906
+ let sliceMs = 0;
907
+ for (const stampMs of window.barOpens) {
908
+ if (askOf(stampMs, sliceSent) === undefined || !args.landedData(stampMs))
909
+ continue;
910
+ const span = spanOf(stampMs);
911
+ const whole = span.toMs - span.fromMs;
912
+ sliceMs += Math.max(Math.min(MINUTE_MS, whole), Math.min(span.toMs, window.nowMs) - span.fromMs);
913
+ }
914
+ if (sliceBytes > 0 && sliceMs > 0)
915
+ rememberDownload(downloadDensity, memoryKey, sliceBytes / sliceMs);
916
+ const density = sliceBytes > 0 && sliceMs > 0 ? sliceBytes / sliceMs : downloadDensity.get(memoryKey);
917
+ const declaredRowsOf = (stampMs, tier) => {
918
+ if (sliceRows === undefined)
919
+ return undefined;
920
+ const span = spanOf(stampMs);
921
+ const rows = sliceRows.barRows({ openMs: span.fromMs, endMs: span.toMs, tier }, window.nowMs, budgetAcquisition);
922
+ return Number.isFinite(rows) && rows > 0 ? rows : 0;
923
+ };
924
+ let left = download.share - sliceBytes;
925
+ let keptFrom = Number.POSITIVE_INFINITY;
926
+ let keptEnd = Number.NEGATIVE_INFINITY;
927
+ let stopped = false;
928
+ const cut = [];
929
+ const older = window.barOpens.filter((stampMs) => askOf(stampMs, olderPlan) !== undefined).sort((a, b) => b - a);
930
+ for (const stampMs of older) {
931
+ const tier = askOf(stampMs, olderPlan)?.tier;
932
+ const rows = declaredRowsOf(stampMs, tier);
933
+ // A bar its lane projects at nothing reads nothing: never cut, never asked on its own.
934
+ if (rows === 0)
935
+ continue;
936
+ const span = spanOf(stampMs);
937
+ const bytes = density !== undefined
938
+ ? density * (span.toMs - span.fromMs)
939
+ : (rows ?? 0) * (sliceRows?.cellsPerRow ?? args.width) * KSCRIPT_SOURCE_CELL_BYTES;
940
+ if (stopped || bytes > left) {
941
+ stopped = true;
942
+ cut.push(stampMs);
943
+ continue;
944
+ }
945
+ left -= bytes;
946
+ keptFrom = Math.min(keptFrom, span.fromMs);
947
+ keptEnd = Math.max(keptEnd, span.toMs);
948
+ }
949
+ const olderAsks = olderPlan.flatMap((ask) => {
950
+ const fromMs = Math.max(ask.fromMs, keptFrom);
951
+ const toMs = Math.min(ask.toMs, keptEnd);
952
+ return fromMs < toMs ? [{ ...ask, fromMs, toMs }] : [];
953
+ });
954
+ const olderLanded = olderAsks.length > 0 ? await landGroup(olderAsks, download.share - sliceBytes) : undefined;
955
+ return {
956
+ sent: [...sliceSent, ...(olderLanded?.sent ?? [])],
957
+ partialBars: [...new Set([...args.partialBars, ...sliceUnsent, ...cut, ...barsOf(olderLanded?.unsent ?? [])])].sort((a, b) => a - b),
958
+ };
959
+ }
960
+ /**
961
+ * A budgeted read's cut once its asks landed (`WrunRowLaneBudgetCut`, `budget: 'download'`): of the bars the plan asked
962
+ * (`asks`, the tier rule's, the horizon's and the answer budget's), the ones read whole and the ones the download budget
963
+ * alone left partial: unasked (`after` beside `before`), or, for a browser fold under its cap (`foldPartial`), landed
964
+ * partial. The oldest kept bar is the oldest of the newest run of whole bars.
965
+ */
966
+ function wrunRowLaneDownloadCutOf(args) {
967
+ const before = new Set(args.before);
968
+ const after = new Set(args.after);
969
+ const marked = (row) => row !== undefined && wrunRowLaneRowMarkedPartial(row);
970
+ const asked = args.window.barOpens.filter((stampMs) => {
971
+ const { fromMs } = wrunHostBarSpanOf(stampMs, args.window.intervalMs, args.sessionGrid);
972
+ return !before.has(stampMs) && args.asks.some((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
973
+ });
974
+ const isCut = (stampMs) => after.has(stampMs) || (args.foldPartial && marked(args.byBar.get(stampMs)));
975
+ let keptFromTs;
976
+ for (let at = asked.length - 1; at >= 0; at -= 1) {
977
+ if (isCut(asked[at])) {
978
+ if (keptFromTs !== undefined)
979
+ break;
980
+ continue;
981
+ }
982
+ keptFromTs = asked[at];
983
+ }
984
+ const cutBars = asked.filter(isCut).length;
985
+ return {
986
+ laneKey: args.laneKey,
987
+ keptBars: asked.length - cutBars,
988
+ cutBars,
989
+ ...(keptFromTs !== undefined ? { keptFromTs } : {}),
990
+ maxRows: wrunRowLaneMaxRows({ cellsPerRow: args.width }),
991
+ budget: 'download',
992
+ spentBytes: Math.round(args.spentBytes),
993
+ shareBytes: Math.round(args.shareBytes),
994
+ };
371
995
  }
372
996
  /**
373
997
  * Where a kit fold page carrying the next bar's strikes is read to (the paging seam, OPTLOAD G5): through the end of the
@@ -506,6 +1130,129 @@ export function wrunRowLaneAsksWithinRowBudget(plan, window, budget, acquisition
506
1130
  partialBars: [...new Set([...plan.partialBars, ...cut])].sort((a, b) => a - b),
507
1131
  };
508
1132
  }
1133
+ /**
1134
+ * What row-budget lanes' reads measured (`wrunRowLaneProjectedBarRows`): the bars a read landed whole and the tuples
1135
+ * they held, by lane, acquisition, tier and bar width, a running sum weighing at most `MEASURED_BARS` bars, so a newer
1136
+ * read moves it and a short one (a live reconcile's newest bars) never replaces a whole window's. In memory, the
1137
+ * newest `MEASURED_KEPT` kept.
1138
+ */
1139
+ const measuredBars = new Map();
1140
+ const MEASURED_KEPT = 64;
1141
+ const MEASURED_BARS = 500;
1142
+ /** The ask's fields that never change what a bar holds: its tier (keyed apart), the routed tier and plane, the market
1143
+ * placeholders a recorded acquisition carries, today's first instant and the instance's own bound. */
1144
+ const MEASURED_SKIP = new Set([
1145
+ WRUN_ROW_LANE_TIER_FIELD,
1146
+ 'servedTier',
1147
+ 'wrunPlane',
1148
+ 'symbol',
1149
+ 'exchange',
1150
+ WRUN_OPTION_FLOW_TODAY_FIELD,
1151
+ 'maxCells',
1152
+ ]);
1153
+ function measuredKeyOf(laneKey, extras, tierKey, widthMs) {
1154
+ const fields = {};
1155
+ for (const [key, value] of Object.entries(extras))
1156
+ if (!MEASURED_SKIP.has(key))
1157
+ fields[key] = value;
1158
+ return `${laneKey}|${tierKey ?? ''}|${widthMs}|${stableJson(fields)}`;
1159
+ }
1160
+ /** Test seam: forget every measurement. */
1161
+ export function __resetWrunRowLaneMeasurementsForTests() {
1162
+ measuredBars.clear();
1163
+ downloadDensity.clear();
1164
+ }
1165
+ /**
1166
+ * The rows a row-budget lane's next ask projects for one bar: its own projection (`rowBudget.barRows`: a proxy, the
1167
+ * 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
1168
+ * same lane, acquisition, tier and width held in the reads that landed before, never past the instance's `maxCells`
1169
+ * (the most tuples a bar of it is read with, which option_strike_flow's facets name); a bar its projection reads
1170
+ * nothing for (before today under `history` "today") stays at nothing. A market busier than its proxy then reads fewer
1171
+ * bars on its next ask instead of an answer past the source answer budget, and a quieter one keeps the proxy. A
1172
+ * contract flow bar's measured tuples (its contracts) are no more than the raw rows it reads, so they only ever lift a
1173
+ * projection that was under them.
1174
+ */
1175
+ export function wrunRowLaneProjectedBarRows(lane, extras, bar, nowMs, acquisition = extras) {
1176
+ const projected = lane.rowBudget?.barRows(bar, nowMs, acquisition) ?? 0;
1177
+ if (!(projected > 0))
1178
+ return projected;
1179
+ const held = measuredBars.get(measuredKeyOf(lane.laneKey, extras, bar.tier?.key, bar.endMs - bar.openMs));
1180
+ const measured = held === undefined ? 0 : Math.ceil(held.tuples / held.bars);
1181
+ const most = extras.maxCells;
1182
+ return Math.min(Math.max(projected, measured), typeof most === 'number' && most >= 1 ? most : Infinity);
1183
+ }
1184
+ /** A lane's row budget projecting each bar through `wrunRowLaneProjectedBarRows` for one read's `extras`. */
1185
+ function wrunRowLaneMeasuredBudget(lane, budget, extras) {
1186
+ return {
1187
+ cellsPerRow: budget.cellsPerRow,
1188
+ barRows: (bar, nowMs, acquisition) => wrunRowLaneProjectedBarRows(lane, extras, bar, nowMs, acquisition),
1189
+ };
1190
+ }
1191
+ /**
1192
+ * One read's landed bars into the measurements (`wrunRowLaneProjectedBarRows`): every bar it holds whole, closed by the
1193
+ * clock, none of the plan's partial bars and no tuple marked partial (a bar still forming, or served in part, holds a
1194
+ * floor of its tuples), its tuples counted under the tier its ask read and its width.
1195
+ */
1196
+ function noteWrunRowLaneMeasured(laneKey, extras, asks, landed, partialBars, window, sessionGrid, presentMask) {
1197
+ const partial = new Set(partialBars);
1198
+ const marked = (tuple) => Array.isArray(tuple) && wrunPresentIsPartial(Number(tuple[tuple.length - 1]));
1199
+ const reads = new Map();
1200
+ for (const [stampMs, row] of landed) {
1201
+ const span = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
1202
+ const tuples = row.slice(1);
1203
+ if (partial.has(stampMs) || span.toMs > window.nowMs || tuples.length === 0)
1204
+ continue;
1205
+ if (presentMask !== false && tuples.some(marked))
1206
+ continue;
1207
+ const tier = asks.find((ask) => span.fromMs >= ask.fromMs && span.fromMs < ask.toMs)?.tier;
1208
+ const key = measuredKeyOf(laneKey, extras, tier?.key, span.toMs - span.fromMs);
1209
+ const read = reads.get(key) ?? { bars: 0, tuples: 0 };
1210
+ reads.set(key, { bars: read.bars + 1, tuples: read.tuples + tuples.length });
1211
+ }
1212
+ for (const [key, read] of reads) {
1213
+ const held = measuredBars.get(key) ?? { bars: 0, tuples: 0 };
1214
+ const bars = held.bars + read.bars;
1215
+ const weight = Math.min(1, MEASURED_BARS / bars);
1216
+ measuredBars.delete(key);
1217
+ measuredBars.set(key, { bars: bars * weight, tuples: (held.tuples + read.tuples) * weight });
1218
+ while (measuredBars.size > MEASURED_KEPT)
1219
+ measuredBars.delete(measuredBars.keys().next().value);
1220
+ }
1221
+ }
1222
+ /** The cut a row budget made (`wrunRowLaneAsksWithinRowBudget` over `before`, answering `after`): the asked bars it
1223
+ * reads whole and the bars it alone left partial. */
1224
+ function wrunRowLaneBudgetCutOf(laneKey, budget, before, after, window, sessionGrid) {
1225
+ const partialBefore = new Set(before.partialBars);
1226
+ const kept = window.barOpens.filter((stampMs) => {
1227
+ const { fromMs } = wrunHostBarSpanOf(stampMs, window.intervalMs, sessionGrid);
1228
+ return after.asks.some((ask) => fromMs >= ask.fromMs && fromMs < ask.toMs);
1229
+ });
1230
+ return {
1231
+ laneKey,
1232
+ keptBars: kept.length,
1233
+ cutBars: after.partialBars.filter((stampMs) => !partialBefore.has(stampMs)).length,
1234
+ ...(kept.length > 0 ? { keptFromTs: kept[0] } : {}),
1235
+ maxRows: wrunRowLaneMaxRows(budget),
1236
+ };
1237
+ }
1238
+ /** A budget cut to the debug ring and the caller. Both are advisory: a host with no ring, or a caller whose note
1239
+ * fails, costs the record, never the read. */
1240
+ function reportWrunRowLaneBudgetCut(cut, intervalMs, onBudgetCut) {
1241
+ try {
1242
+ const { diagnostics } = wrunChartHostEnv();
1243
+ if (diagnostics.debugEnabled())
1244
+ diagnostics.debug('wrun-row-lane-budget-cut', { ...cut, intervalMs });
1245
+ }
1246
+ catch {
1247
+ // No ring in this host.
1248
+ }
1249
+ try {
1250
+ onBudgetCut?.(cut);
1251
+ }
1252
+ catch {
1253
+ // The note is lost; the read goes on.
1254
+ }
1255
+ }
509
1256
  function finiteOrUndefined(value) {
510
1257
  return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
511
1258
  }
@@ -570,9 +1317,10 @@ function wrunCellMember(member) {
570
1317
  /** A row's tuples as the host's exact adapter reads them: arrays of exactly `width` numbers, finite in every column
571
1318
  * (the kit's rule for an exact class: any other tuple is dropped whole), or, for a lane naming its `finiteColumns`,
572
1319
  * finite in those columns while any other column that is not a finite number reads NaN (om's adapter for such a
573
- * class: a null, a missing member or an infinity is NaN, never 0). A packed block (a Float64Array of `count x width`
574
- * values, a worker's transfer) reads as its tuples back to back, each under the same rule; a block that is no whole
575
- * number of tuples is skipped like any cell of another shape. */
1320
+ * class: a null, a missing member or an infinity is NaN, never 0; a view block names none, so every row of its width
1321
+ * is read, `wrunRowLaneAtWidth`). A packed block (a Float64Array of `count x width` values, a worker's transfer)
1322
+ * reads as its tuples back to back, each under the same rule; a block that is no whole number of tuples is skipped
1323
+ * like any cell of another shape. */
576
1324
  function exactTuples(row, lane) {
577
1325
  const { width, finiteColumns } = lane;
578
1326
  const tuples = [];
@@ -608,10 +1356,11 @@ function exactTuples(row, lane) {
608
1356
  * (bit 14 of the `present` mask, the last column): when any of the bar's tuples says partial (a bar no fitting tier
609
1357
  * retains, or the marker tuple of one that holds none), every tuple the projection keeps or rebuilds carries bit 14,
610
1358
  * and a block the projection empties reads the marker tuple, so a package never reads missing history as a quiet bar.
611
- * A class with no `present` mask (`presentMask: false`) is projected as it is: its last column is a value.
1359
+ * A block with no `present` mask (`presentMask: false`: its class's, or a view block's, `wrunRowLaneAtWidth`) is
1360
+ * projected as it is: its last column is a value.
612
1361
  */
613
- function wrunProjectedBlock(lane, tuples, input) {
614
- const projected = lane.cells ? lane.cells(tuples, input) : tuples;
1362
+ function wrunProjectedBlock(lane, tuples, input, bar) {
1363
+ const projected = lane.cells ? lane.cells(tuples, input, bar) : tuples;
615
1364
  if (lane.presentMask === false)
616
1365
  return projected;
617
1366
  if (!tuples.some((tuple) => wrunPresentIsPartial(tuple[tuple.length - 1])))
@@ -625,27 +1374,42 @@ function wrunProjectedBlock(lane, tuples, input) {
625
1374
  * bar the lane holds no row for reads a present EMPTY block). A PARTIAL bar stays partial through the projection
626
1375
  * (`wrunProjectedBlock`). A `latest` lane's newest row lands on the LIVE row alone (`liveTs`, the chart's last row;
627
1376
  * the options chain's rule) whatever its stamp, every other row reading an empty block. `afterTs` (a tail build's
628
- * carry) keeps the rows stamped after it, except a `latest` lane's newest.
1377
+ * carry) keeps the rows stamped after it, except a `latest` lane's newest. An input reading a window-level pass
1378
+ * (`cellsWindow`) reads every row the lane holds first, whatever `afterTs` keeps, and each bar's projection reads the
1379
+ * answer.
629
1380
  */
630
1381
  export function wrunRowLaneCellRows(lane, rows, input, opts = {}) {
631
- const project = (tuples) => wrunProjectedBlock(lane, tuples, input).flatMap((tuple) => [...tuple]);
1382
+ // The input's window-level pass, if it reads one: every held bar's exact tuples, read once, then each bar's
1383
+ // projection reads its answer.
1384
+ const windowPass = lane.cellsWindow?.(input);
1385
+ const bars = windowPass === undefined
1386
+ ? undefined
1387
+ : rows.map((row) => ({ openMs: Number(row[0]), tuples: exactTuples(row, lane) }));
1388
+ const window = windowPass === undefined || bars === undefined
1389
+ ? undefined
1390
+ : windowPass(bars.filter((bar) => Number.isFinite(bar.openMs)));
1391
+ const project = (at) => {
1392
+ const tuples = bars?.[at].tuples ?? exactTuples(rows[at], lane);
1393
+ const bar = bars === undefined ? undefined : { openMs: Number(rows[at][0]), window };
1394
+ return wrunProjectedBlock(lane, tuples, input, bar).flatMap((tuple) => [...tuple]);
1395
+ };
632
1396
  if (lane.landing.kind === 'latest') {
633
1397
  if (opts.liveTs === undefined || !Number.isFinite(opts.liveTs))
634
1398
  return [];
635
- let newest;
636
- for (const row of rows) {
1399
+ let newest = -1;
1400
+ rows.forEach((row, at) => {
637
1401
  const ts = Number(row[0]);
638
- if (Number.isFinite(ts) && (newest === undefined || ts > Number(newest[0])))
639
- newest = row;
640
- }
641
- return newest === undefined ? [] : [{ ts: opts.liveTs, cells: project(exactTuples(newest, lane)) }];
1402
+ if (Number.isFinite(ts) && (newest < 0 || ts > Number(rows[newest][0])))
1403
+ newest = at;
1404
+ });
1405
+ return newest < 0 ? [] : [{ ts: opts.liveTs, cells: project(newest) }];
642
1406
  }
643
1407
  const out = [];
644
- for (const row of rows) {
1408
+ rows.forEach((row, at) => {
645
1409
  const ts = Number(row[0]);
646
1410
  if (!Number.isFinite(ts) || (opts.afterTs !== undefined && ts <= opts.afterTs))
647
- continue;
648
- out.push({ ts, cells: project(exactTuples(row, lane)) });
649
- }
1411
+ return;
1412
+ out.push({ ts, cells: project(at) });
1413
+ });
650
1414
  return out;
651
1415
  }