@orangecharts/wrun-chart-host 0.15.0 → 0.17.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 (202) hide show
  1. package/README.md +2 -0
  2. package/dist/constants/economic.constants.d.ts +2 -0
  3. package/dist/constants/economic.constants.js +2 -0
  4. package/dist/constants/feature-flags.constants.d.ts +13 -5
  5. package/dist/constants/feature-flags.constants.js +76 -35
  6. package/dist/constants/feature-limits.constants.d.ts +72 -4
  7. package/dist/constants/feature-limits.constants.js +104 -24
  8. package/dist/constants/interval.constants.js +5 -0
  9. package/dist/constants/kscript-data-interval-restrictions.constants.d.ts +12 -0
  10. package/dist/constants/kscript-data-interval-restrictions.constants.js +14 -0
  11. package/dist/constants/marketCapabilities.constants.d.ts +9 -0
  12. package/dist/constants/marketCapabilities.constants.js +39 -11
  13. package/dist/constants/typed-indicator-source.leaf.d.ts +7 -0
  14. package/dist/constants/typed-indicator-source.leaf.js +47 -0
  15. package/dist/constants/typed-session-history-venue.leaf.d.ts +7 -0
  16. package/dist/constants/typed-session-history-venue.leaf.js +9 -0
  17. package/dist/constants/typed-width-fold.leaf.d.ts +52 -0
  18. package/dist/constants/typed-width-fold.leaf.js +101 -0
  19. package/dist/constants/typed-width-source.leaf.d.ts +24 -0
  20. package/dist/constants/typed-width-source.leaf.js +126 -0
  21. package/dist/constants/typed-width.leaf.d.ts +57 -0
  22. package/dist/constants/typed-width.leaf.js +78 -0
  23. package/dist/host-env.d.ts +10 -0
  24. package/dist/host-env.js +7 -0
  25. package/dist/host-ports.types.d.ts +23 -17
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.js +4 -0
  28. package/dist/interfaces/kscript-diagnostics.interface.d.ts +35 -0
  29. package/dist/interfaces/wrun-runtime.interface.d.ts +66 -3
  30. package/dist/interfaces/wrun-runtime.interface.js +11 -0
  31. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +13 -0
  32. package/dist/kscript-data/controls/live-trades-merge.util.js +16 -1
  33. package/dist/market-data/billing.interface.d.ts +12 -45
  34. package/dist/market-data/billing.interface.js +2 -2
  35. package/dist/replay/replayLadder.js +7 -4
  36. package/dist/settings-templates/footprint-rows.d.ts +6 -0
  37. package/dist/settings-templates/footprint-rows.js +6 -0
  38. package/dist/settings-templates/frvp-fields.js +14 -0
  39. package/dist/settings-templates/indicator-fields.js +36 -0
  40. package/dist/settings-templates/tool-tables.generated.js +19 -1
  41. package/dist/utility/chart/__fixtures__/live-bucket-regular-golden.json +1706 -0
  42. package/dist/utility/chart/cache-alignment.util.d.ts +42 -0
  43. package/dist/utility/chart/cache-alignment.util.js +88 -18
  44. package/dist/utility/chart/calendar-interval.util.d.ts +83 -1
  45. package/dist/utility/chart/calendar-interval.util.js +152 -4
  46. package/dist/utility/chart/candle-bar-end.util.d.ts +11 -4
  47. package/dist/utility/chart/candle-bar-end.util.js +17 -6
  48. package/dist/utility/chart/chart-time-domain.util.d.ts +3 -0
  49. package/dist/utility/chart/chart-time-domain.util.js +13 -4
  50. package/dist/utility/chart/feed-interval.util.d.ts +4 -2
  51. package/dist/utility/chart/feed-interval.util.js +5 -2
  52. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +3 -1
  53. package/dist/utility/chart/fetch-dedupe-policy.util.js +19 -1
  54. package/dist/utility/chart/footprint-display-mode.util.d.ts +2 -0
  55. package/dist/utility/chart/footprint-display-mode.util.js +5 -0
  56. package/dist/utility/chart/governed-lanes-gate.util.d.ts +46 -0
  57. package/dist/utility/chart/governed-lanes-gate.util.js +71 -0
  58. package/dist/utility/chart/governed-lanes-reader-seat.d.ts +14 -0
  59. package/dist/utility/chart/governed-lanes-reader-seat.js +14 -0
  60. package/dist/utility/chart/history-wall.util.d.ts +13 -2
  61. package/dist/utility/chart/history-wall.util.js +11 -4
  62. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  63. package/dist/utility/chart/index-mode.util.d.ts +2 -2
  64. package/dist/utility/chart/index-mode.util.js +12 -6
  65. package/dist/utility/chart/index-otc.leaf.d.ts +37 -0
  66. package/dist/utility/chart/index-otc.leaf.js +68 -0
  67. package/dist/utility/chart/interval-ladder.util.d.ts +5 -2
  68. package/dist/utility/chart/interval-ladder.util.js +44 -4
  69. package/dist/utility/chart/interval-registry.util.d.ts +22 -1
  70. package/dist/utility/chart/interval-registry.util.js +50 -2
  71. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +32 -4
  72. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +22 -5
  73. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +10 -0
  74. package/dist/utility/chart/kscript-drawing-safe-area.util.js +30 -3
  75. package/dist/utility/chart/kscript-legend-entries.util.d.ts +21 -4
  76. package/dist/utility/chart/kscript-legend-entries.util.js +27 -5
  77. package/dist/utility/chart/kscript-main-grid-stages.util.js +74 -24
  78. package/dist/utility/chart/kscript-provenance-keys.util.js +6 -0
  79. package/dist/utility/chart/kscript-row-name.leaf.d.ts +13 -0
  80. package/dist/utility/chart/kscript-row-name.leaf.js +18 -0
  81. package/dist/utility/chart/kscript-venue-policy.util.d.ts +61 -26
  82. package/dist/utility/chart/kscript-venue-policy.util.js +138 -37
  83. package/dist/utility/chart/live-bucket.util.d.ts +29 -4
  84. package/dist/utility/chart/live-bucket.util.js +45 -12
  85. package/dist/utility/chart/market-session-schedule.util.d.ts +19 -0
  86. package/dist/utility/chart/market-session-schedule.util.js +2 -1
  87. package/dist/utility/chart/market-session.util.d.ts +62 -10
  88. package/dist/utility/chart/market-session.util.js +93 -13
  89. package/dist/utility/chart/marketKind.util.d.ts +11 -12
  90. package/dist/utility/chart/marketKind.util.js +45 -13
  91. package/dist/utility/chart/mixed-mode.util.d.ts +18 -0
  92. package/dist/utility/chart/om-target.util.js +6 -4
  93. package/dist/utility/chart/price-precision.util.d.ts +20 -6
  94. package/dist/utility/chart/price-precision.util.js +34 -7
  95. package/dist/utility/chart/profile-frame-window.util.d.ts +15 -0
  96. package/dist/utility/chart/profile-frame-window.util.js +12 -0
  97. package/dist/utility/chart/rth-session.util.d.ts +3 -1
  98. package/dist/utility/chart/rth-session.util.js +3 -1
  99. package/dist/utility/chart/script-source-session.util.d.ts +43 -0
  100. package/dist/utility/chart/script-source-session.util.js +61 -0
  101. package/dist/utility/chart/typed-width-grid.util.d.ts +23 -0
  102. package/dist/utility/chart/typed-width-grid.util.js +203 -0
  103. package/dist/utility/common/transformations.util.d.ts +6 -0
  104. package/dist/utility/common/transformations.util.js +28 -4
  105. package/dist/utility/market-events/market-events.util.js +3 -0
  106. package/dist/utility/number-format.util.d.ts +14 -1
  107. package/dist/utility/number-format.util.js +22 -4
  108. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +24 -1
  109. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +115 -0
  110. package/dist/utility/v2/v2-enums.leaf.js +5 -0
  111. package/dist/utility/wrun/sources/row-lanes/dark_pool.d.ts +2 -1
  112. package/dist/utility/wrun/sources/row-lanes/dark_pool.js +4 -3
  113. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +13 -3
  114. package/dist/utility/wrun/wrun-batched-marks.util.js +96 -17
  115. package/dist/utility/wrun/wrun-canvases.util.d.ts +4 -2
  116. package/dist/utility/wrun/wrun-canvases.util.js +7 -12
  117. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +5 -0
  118. package/dist/utility/wrun/wrun-cap-notice.util.js +23 -0
  119. package/dist/utility/wrun/wrun-card-style.util.d.ts +1 -1
  120. package/dist/utility/wrun/wrun-card-style.util.js +2 -2
  121. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +23 -8
  122. package/dist/utility/wrun/wrun-chart-market-facts.util.js +24 -9
  123. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +10 -0
  124. package/dist/utility/wrun/wrun-child-overlay-id.util.js +24 -0
  125. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.d.ts +72 -0
  126. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.js +151 -0
  127. package/dist/utility/wrun/wrun-cme-root-specs.util.d.ts +10 -6
  128. package/dist/utility/wrun/wrun-cme-root-specs.util.js +19 -13
  129. package/dist/utility/wrun/wrun-color-facts.util.d.ts +3 -3
  130. package/dist/utility/wrun/wrun-color-facts.util.js +8 -5
  131. package/dist/utility/wrun/wrun-colour-tone.lazy.d.ts +20 -0
  132. package/dist/utility/wrun/wrun-colour-tone.lazy.js +23 -0
  133. package/dist/utility/wrun/wrun-colour-tone.util.d.ts +14 -0
  134. package/dist/utility/wrun/wrun-colour-tone.util.js +119 -0
  135. package/dist/utility/wrun/wrun-dark-pool.util.d.ts +3 -2
  136. package/dist/utility/wrun/wrun-dark-pool.util.js +5 -4
  137. package/dist/utility/wrun/wrun-frames.d.ts +1 -1
  138. package/dist/utility/wrun/wrun-frames.js +2 -2
  139. package/dist/utility/wrun/wrun-handles.util.d.ts +1 -1
  140. package/dist/utility/wrun/wrun-handles.util.js +1 -1
  141. package/dist/utility/wrun/wrun-host.service.d.ts +32 -2
  142. package/dist/utility/wrun/wrun-host.service.js +44 -2
  143. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +20 -0
  144. package/dist/utility/wrun/wrun-hosted-wire-caps.js +85 -2
  145. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +37 -0
  146. package/dist/utility/wrun/wrun-hosted-wire.util.js +54 -0
  147. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +1 -0
  148. package/dist/utility/wrun/wrun-hud-looks.util.js +6 -11
  149. package/dist/utility/wrun/wrun-integration-route.util.d.ts +24 -0
  150. package/dist/utility/wrun/wrun-integration-route.util.js +19 -0
  151. package/dist/utility/wrun/wrun-live-intake.util.js +17 -1
  152. package/dist/utility/wrun/wrun-live-patch.util.d.ts +6 -1
  153. package/dist/utility/wrun/wrun-live-patch.util.js +10 -4
  154. package/dist/utility/wrun/wrun-live-tick.util.js +64 -5
  155. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +40 -6
  156. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +2 -2
  157. package/dist/utility/wrun/wrun-market-size-defaults.util.js +10 -8
  158. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +3 -0
  159. package/dist/utility/wrun/wrun-overlay-drivers.util.js +3 -0
  160. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +17 -0
  161. package/dist/utility/wrun/wrun-overlay-run.util.js +318 -55
  162. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +1 -1
  163. package/dist/utility/wrun/wrun-panel-mount.util.js +42 -13
  164. package/dist/utility/wrun/wrun-pin-venues.util.d.ts +3 -2
  165. package/dist/utility/wrun/wrun-pin-venues.util.js +11 -4
  166. package/dist/utility/wrun/wrun-refusal.util.d.ts +4 -0
  167. package/dist/utility/wrun/wrun-refusal.util.js +102 -13
  168. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  169. package/dist/utility/wrun/wrun-registry-errors.util.js +5 -3
  170. package/dist/utility/wrun/wrun-row-source-factory.js +17 -1
  171. package/dist/utility/wrun/wrun-row-source.d.ts +8 -1
  172. package/dist/utility/wrun/wrun-run-health.util.js +1 -1
  173. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +1 -1
  174. package/dist/utility/wrun/wrun-sandbox-row-source.js +9 -0
  175. package/dist/utility/wrun/wrun-session-composition.util.d.ts +3 -2
  176. package/dist/utility/wrun/wrun-session-composition.util.js +3 -2
  177. package/dist/utility/wrun/wrun-setting-words.util.d.ts +12 -5
  178. package/dist/utility/wrun/wrun-setting-words.util.js +25 -8
  179. package/dist/utility/wrun/wrun-socket-row-source.d.ts +26 -1
  180. package/dist/utility/wrun/wrun-socket-row-source.js +125 -12
  181. package/dist/utility/wrun/wrun-source-rows.util.d.ts +3 -3
  182. package/dist/utility/wrun/wrun-source-rows.util.js +8 -7
  183. package/dist/utility/wrun/wrun-style-words.util.d.ts +31 -9
  184. package/dist/utility/wrun/wrun-style-words.util.js +46 -15
  185. package/dist/utility/wrun/wrun-trades-lane.util.js +2 -1
  186. package/dist/utility/wrun/wrun-trap-replay.util.d.ts +42 -0
  187. package/dist/utility/wrun/wrun-trap-replay.util.js +63 -0
  188. package/dist/utility/wrun/wrun-volume-profile.util.js +6 -5
  189. package/dist/utility/wrun-display-name.util.d.ts +10 -0
  190. package/dist/utility/wrun-display-name.util.js +21 -0
  191. package/dist/utils/replay/replay-buffer-math.d.ts +2 -0
  192. package/dist/utils/replay/replay-buffer-math.js +2 -0
  193. package/dist/workers/constants/socket-slots.d.ts +1 -1
  194. package/dist/workers/utils/time.worker.util.js +2 -2
  195. package/dist/workers/utils/volume-profile.worker.util.d.ts +9 -0
  196. package/dist/workers/utils/volume-profile.worker.util.js +20 -0
  197. package/dist/workers/wrun/wrun-abi-host.d.ts +3 -0
  198. package/dist/workers/wrun/wrun-abi-host.js +82 -5
  199. package/dist/workers/wrun/wrun-engine-handler.js +53 -4
  200. package/dist/workers/wrun/wrun-trap-frames.leaf.d.ts +28 -0
  201. package/dist/workers/wrun/wrun-trap-frames.leaf.js +108 -0
  202. package/package.json +11 -11
@@ -8,8 +8,9 @@
8
8
  * corpus), and the theme-token packing every host restates (the draw ABI
9
9
  * sentinel, the wire text, the packed f64 form).
10
10
  *
11
- * Imports nothing (no vue, no DOM, no titan, no kit): main-thread and worker
12
- * safe. The om twin is packages/sdk/src/wrun-style-words.ts and
11
+ * Imports only the door to the mark colour maths (wrun-colour-tone.lazy,
12
+ * import-free; the maths stay off the pre-candle path): no vue, no DOM, no
13
+ * titan, no kit, main-thread and worker safe. The om twin is packages/sdk/src/wrun-style-words.ts and
13
14
  * wrun-value-format.ts; the two sides must agree on every word and byte.
14
15
  *
15
16
  * Theme tokens ride sheets, wire props and run outputs unresolved; they
@@ -17,15 +18,27 @@
17
18
  * wrunColorThemeOf(tc))` and re-resolve on a theme switch without a rerun
18
19
  * (`onWrunThemeChange`).
19
20
  */
21
+ import { wrunMarkSideColour } from './wrun-colour-tone.lazy.js';
20
22
  // Colour words
21
- /** The seven theme colour tokens a colour key may name as `theme.<token>`.
22
- * Token k of the packed forms below is `index + 1` in this order. */
23
- export const WRUN_THEME_COLOR_TOKENS = ['up', 'down', 'text', 'muted', 'bg', 'grid', 'accent'];
23
+ /** The nine theme colour tokens a colour key may name as `theme.<token>`.
24
+ * Token k of the packed forms below is `index + 1` in this order: the
25
+ * Big Trades looks round appended `up_mark` (k 8) and `down_mark` (k 9). */
26
+ export const WRUN_THEME_COLOR_TOKENS = [
27
+ 'up',
28
+ 'down',
29
+ 'text',
30
+ 'muted',
31
+ 'bg',
32
+ 'grid',
33
+ 'accent',
34
+ 'up_mark',
35
+ 'down_mark',
36
+ ];
24
37
  const WRUN_THEME_TOKEN_PREFIX = 'theme.';
25
38
  /** The sheet colour word: `#rrggbb` or `#rrggbbaa` (alpha in the last byte). */
26
39
  const WRUN_HEX_COLOR_WORD_RE = /^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/;
27
40
  /** `theme.<token>` (a sheet word) or `theme.<token>/aa` (the wire form). */
28
- const WRUN_THEME_TOKEN_RE = /^theme\.([a-z]+)(?:\/([0-9a-fA-F]{2}))?$/;
41
+ const WRUN_THEME_TOKEN_RE = /^theme\.([a-z_]+)(?:\/([0-9a-fA-F]{2}))?$/;
29
42
  function wrunTokenOf(name) {
30
43
  return WRUN_THEME_COLOR_TOKENS.includes(name) ? name : undefined;
31
44
  }
@@ -35,8 +48,10 @@ function wrunTokenK(token) {
35
48
  function wrunTokenAlpha(alpha) {
36
49
  return Number.isFinite(alpha) ? Math.min(1, Math.max(0, alpha)) : 1;
37
50
  }
51
+ /** The tokens as a refusal lists them: `theme.up, theme.down, ...`. */
52
+ export const WRUN_THEME_TOKEN_WORDS_TEXT = WRUN_THEME_COLOR_TOKENS.map((token) => `theme.${token}`).join(', ');
38
53
  /** True for the convention-2 colour word: `#rrggbb`, `#rrggbbaa` or one of
39
- * the seven tokens spelled exactly (`theme.up`); the `/aa` wire form, any
54
+ * the nine tokens spelled exactly (`theme.up`); the `/aa` wire form, any
40
55
  * other `theme.` word and every non-string are not colour words. */
41
56
  export function isWrunColorWord(value) {
42
57
  if (typeof value !== 'string')
@@ -96,7 +111,9 @@ const WRUN_THEME_FALLBACK = {
96
111
  grid: '#2a2e39',
97
112
  accent: '#ff4608',
98
113
  };
99
- /** `muted` is the text colour at this fraction of its own alpha (X8). */
114
+ /** `muted` is the text colour at this fraction of its own alpha (X8);
115
+ * `up_mark` and `down_mark` are worked out from up, down and bg, so a bare
116
+ * chart answers them from the defaults above. */
100
117
  const WRUN_MUTED_ALPHA = 0.55;
101
118
  function wrunChannel(text) {
102
119
  const value = Number(text);
@@ -105,7 +122,7 @@ function wrunChannel(text) {
105
122
  /** A palette colour parsed: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`,
106
123
  * `rgb(r, g, b)` or `rgba(r, g, b, a)` (the forms the chart theme writes).
107
124
  * Anything else is no colour. */
108
- function parseWrunCssColor(value) {
125
+ export function parseWrunCssColor(value) {
109
126
  if (typeof value !== 'string')
110
127
  return undefined;
111
128
  const text = value.trim().toLowerCase();
@@ -167,20 +184,28 @@ const wrunThemeListeners = new Set();
167
184
  * pin without a theme answers the dark defaults): up and down from the
168
185
  * candle colours, text from the x axis font colour, muted = text at alpha
169
186
  * x 0.55, bg and grid from the theme, accent from `noteWrunThemeApplied`
170
- * (fallback '#ff4608'). */
187
+ * (fallback '#ff4608'), up_mark and down_mark the candle colours stepped
188
+ * one tone away from bg (`markSideColour`, through its door: the up and
189
+ * down colours until wrun-colour-tone.util has evaluated). Read at every mount and theme
190
+ * change, so the mark colours follow a theme switch with no rerun. */
171
191
  export function wrunColorThemeOf(tc) {
172
192
  const chart = wrunRecordAt(tc);
173
193
  const theme = wrunRecordAt(chart?.theme);
174
194
  const text = wrunColorField(wrunRecordAt(theme?.xAxis)?.fontColor) ?? WRUN_THEME_FALLBACK.text;
175
195
  const accent = chart === undefined ? undefined : wrunAccentByChart.get(chart);
196
+ const up = wrunColorField(theme?.bullishCandleColor) ?? WRUN_THEME_FALLBACK.up;
197
+ const down = wrunColorField(theme?.bearishCandleColor) ?? WRUN_THEME_FALLBACK.down;
198
+ const bg = wrunColorField(theme?.backgroundColor) ?? WRUN_THEME_FALLBACK.bg;
176
199
  return {
177
- up: wrunColorField(theme?.bullishCandleColor) ?? WRUN_THEME_FALLBACK.up,
178
- down: wrunColorField(theme?.bearishCandleColor) ?? WRUN_THEME_FALLBACK.down,
200
+ up,
201
+ down,
179
202
  text,
180
203
  muted: wrunMutedOf(text),
181
- bg: wrunColorField(theme?.backgroundColor) ?? WRUN_THEME_FALLBACK.bg,
204
+ bg,
182
205
  grid: wrunColorField(wrunRecordAt(theme?.grid)?.color) ?? WRUN_THEME_FALLBACK.grid,
183
206
  accent: wrunColorField(accent) ?? WRUN_THEME_FALLBACK.accent,
207
+ up_mark: wrunMarkSideColour(up, bg),
208
+ down_mark: wrunMarkSideColour(down, bg),
184
209
  };
185
210
  }
186
211
  /** Records the accent colour of a theme apply for `tc` (a WeakMap, so a
@@ -396,6 +421,12 @@ export function formatWrunNumber(value, spec = {}) {
396
421
  * {@link WRUN_THEME_COLOR_TOKENS} with its alpha in the blue byte. Every
397
422
  * other value is a plain colour. */
398
423
  export const WRUN3_THEME_TOKEN_MARKER = 0x7e;
424
+ /** The tokens the i32 sentinel carries: the first seven only. The mark tokens
425
+ * (k 8, 9) exist as sheet words and in the packed f64 form, never in the
426
+ * sentinel: every published package's compiled `rgba()` zeroes alpha-0
427
+ * colours only for green 1..7, so green 8 or 9 at alpha 0 is an invisible
428
+ * plain colour and must stay one (the om corpus pins `0x7E09FF00`). */
429
+ const WRUN3_SENTINEL_TOKEN_COUNT = 7;
399
430
  /** Decodes the draw ABI sentinel (`0xRRGGBBAA` as an i32 or u32): a token
400
431
  * when the alpha byte is 0, the red byte the marker and the green byte in
401
432
  * 1..7, else null (a plain colour, exactly as before the sentinel). */
@@ -403,7 +434,7 @@ export function wrunThemeTokenOfI32(rgba) {
403
434
  if ((rgba & 0xff) !== 0 || rgba >>> 24 !== WRUN3_THEME_TOKEN_MARKER)
404
435
  return null;
405
436
  const k = (rgba >>> 16) & 0xff;
406
- const token = k >= 1 ? WRUN_THEME_COLOR_TOKENS[k - 1] : undefined;
437
+ const token = k >= 1 && k <= WRUN3_SENTINEL_TOKEN_COUNT ? WRUN_THEME_COLOR_TOKENS[k - 1] : undefined;
407
438
  if (token === undefined)
408
439
  return null;
409
440
  return { token, alpha: ((rgba >>> 8) & 0xff) / 255 };
@@ -426,7 +457,7 @@ export function wrunDrawColorWire(rgba) {
426
457
  export function wrunPackedThemeToken(ref) {
427
458
  return -(wrunTokenK(ref.token) * 1024 + Math.round(wrunTokenAlpha(ref.alpha) * 1000));
428
459
  }
429
- /** Decodes a packed colour: a finite negative integer whose k lands in 1..7
460
+ /** Decodes a packed colour: a finite negative integer whose k lands in 1..9
430
461
  * and whose alpha part is at most 1000 is a token, anything else null. */
431
462
  export function wrunThemeTokenOfPacked(value) {
432
463
  if (!Number.isInteger(value) || value >= 0)
@@ -28,6 +28,7 @@
28
28
  * `wrunLegPlacementLeadMs`) are the pinned candle legs' too.
29
29
  */
30
30
  import { Intervals } from '../../constants/interval.constants.js';
31
+ import { intervalLabelForMs } from '../chart/interval-ladder.util.js';
31
32
  import { barEndMs, isCalendarIntervalMs } from '../chart/calendar-interval.util.js';
32
33
  import { indexHostFetchTierMs, sourceRowsStraddleHostBars } from '../chart/index-host-tier.util.js';
33
34
  import { liveBucketVenueOf } from '../chart/live-bucket.util.js';
@@ -103,7 +104,7 @@ export function wrunLegPlacementLeadMs(chart, legMs, market) {
103
104
  * spec pins the two over every interval). */
104
105
  function wrunLegTierIntervalKey(intervalMs) {
105
106
  const entry = Object.entries(Intervals.map_unit).find(([, ms]) => ms === intervalMs);
106
- return entry ? entry[0] : `${intervalMs}ms`;
107
+ return intervalLabelForMs(intervalMs) ?? (entry ? entry[0] : `${intervalMs}ms`);
107
108
  }
108
109
  /**
109
110
  * The request a trades leg lane is asked with over a window `[fromMs, toMs]` (the run window's first bar through its
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The seed of the editor's trap replay: what a failed sandbox run computed with (the request: the module handle, the
3
+ * sheet, the rows, the init arguments, the text params, the strategy feed), whether it opened a live session, and the
4
+ * trap record it failed with. The row source attaches it to the rejection (`attachWrunTrapSeed`, a full run or a live
5
+ * start only: a live tick carries one block and its session is gone); the run's failure seam parks it under a token
6
+ * stamped on the trap row (`details.trap.token`), and the editor's replay controller takes it once by that token.
7
+ * Only an editor draft run parks (the failure seam's test); a parked seed is released when its overlay is torn down
8
+ * (`releaseWrunTrapSeedsFor`), when the controller declines or forgets its row (`releaseWrunTrapSeed`) and when the
9
+ * editor's controller is disposed (`releaseAllWrunTrapSeeds`). At most WRUN_TRAP_SEED_SLOTS seeds stand: the newest
10
+ * wins. Plain references, never copied: nothing here touches the chart, a session or a cache.
11
+ */
12
+ import type { WrunModuleHandle, WrunTrapContext } from '../../interfaces/wrun-runtime.interface.js';
13
+ import type { WrunSandboxRunRequest } from './wrun-sandbox-row-source.js';
14
+ export interface WrunTrapSeed {
15
+ request: WrunSandboxRunRequest;
16
+ /** The run opened a live session (replayed in live mode over the same rows), else a cold run. */
17
+ live: boolean;
18
+ /** The failed run's own trap record: a replay reproduces it or enriches nothing. */
19
+ trap: WrunTrapContext;
20
+ }
21
+ /** How many parked seeds stand at once. */
22
+ export declare const WRUN_TRAP_SEED_SLOTS = 2;
23
+ /** The seed rides beside the rejection (the error's words stay the host's). Only an abort or a native trap seeds. */
24
+ export declare function attachWrunTrapSeed(error: unknown, seed: Omit<WrunTrapSeed, 'trap'>, trap: WrunTrapContext): void;
25
+ export declare function wrunTrapSeedOf(error: unknown): WrunTrapSeed | undefined;
26
+ /** Park a draft overlay's seed under a fresh token (the oldest of the slots goes when they are full); the token is
27
+ * the row's. */
28
+ export declare function parkWrunTrapSeed(seed: WrunTrapSeed, indicatorId: string): string;
29
+ /** Take a parked seed once (a second take answers undefined: one replay per token). */
30
+ export declare function takeWrunTrapSeed(token: string): WrunTrapSeed | undefined;
31
+ /** Release a seed no replay will take (a declined or forgotten row). */
32
+ export declare function releaseWrunTrapSeed(token: string): void;
33
+ /** Release every seed an overlay parked (its teardown). */
34
+ export declare function releaseWrunTrapSeedsFor(indicatorId: string): void;
35
+ /** Release every parked seed (the editor's controller went away: nothing consumes them). */
36
+ export declare function releaseAllWrunTrapSeeds(): void;
37
+ /** How many seeds stand (specs). */
38
+ export declare function wrunParkedTrapSeedCount(): number;
39
+ /** The module a seed ran. */
40
+ export declare function wrunTrapSeedModule(seed: WrunTrapSeed): WrunModuleHandle;
41
+ /** Spec hook. */
42
+ export declare function __resetWrunTrapSeedsForTests(): void;
@@ -0,0 +1,63 @@
1
+ /** How many parked seeds stand at once. */
2
+ export const WRUN_TRAP_SEED_SLOTS = 2;
3
+ const seedByError = new WeakMap();
4
+ const parked = new Map();
5
+ let tokenSeq = 0;
6
+ /** The seed rides beside the rejection (the error's words stay the host's). Only an abort or a native trap seeds. */
7
+ export function attachWrunTrapSeed(error, seed, trap) {
8
+ if (typeof error !== 'object' || error === null)
9
+ return;
10
+ if (trap.kind !== 'abort' && trap.kind !== 'native')
11
+ return;
12
+ seedByError.set(error, { ...seed, trap });
13
+ }
14
+ export function wrunTrapSeedOf(error) {
15
+ return typeof error === 'object' && error !== null ? seedByError.get(error) : undefined;
16
+ }
17
+ /** Park a draft overlay's seed under a fresh token (the oldest of the slots goes when they are full); the token is
18
+ * the row's. */
19
+ export function parkWrunTrapSeed(seed, indicatorId) {
20
+ tokenSeq += 1;
21
+ const token = `trap-${tokenSeq}`;
22
+ parked.set(token, { seed, indicatorId });
23
+ while (parked.size > WRUN_TRAP_SEED_SLOTS) {
24
+ const oldest = parked.keys().next().value;
25
+ if (oldest === undefined)
26
+ break;
27
+ parked.delete(oldest);
28
+ }
29
+ return token;
30
+ }
31
+ /** Take a parked seed once (a second take answers undefined: one replay per token). */
32
+ export function takeWrunTrapSeed(token) {
33
+ const entry = parked.get(token);
34
+ parked.delete(token);
35
+ return entry?.seed;
36
+ }
37
+ /** Release a seed no replay will take (a declined or forgotten row). */
38
+ export function releaseWrunTrapSeed(token) {
39
+ parked.delete(token);
40
+ }
41
+ /** Release every seed an overlay parked (its teardown). */
42
+ export function releaseWrunTrapSeedsFor(indicatorId) {
43
+ for (const [token, entry] of parked)
44
+ if (entry.indicatorId === indicatorId)
45
+ parked.delete(token);
46
+ }
47
+ /** Release every parked seed (the editor's controller went away: nothing consumes them). */
48
+ export function releaseAllWrunTrapSeeds() {
49
+ parked.clear();
50
+ }
51
+ /** How many seeds stand (specs). */
52
+ export function wrunParkedTrapSeedCount() {
53
+ return parked.size;
54
+ }
55
+ /** The module a seed ran. */
56
+ export function wrunTrapSeedModule(seed) {
57
+ return seed.request.module;
58
+ }
59
+ /** Spec hook. */
60
+ export function __resetWrunTrapSeedsForTests() {
61
+ parked.clear();
62
+ tokenSeq = 0;
63
+ }
@@ -15,8 +15,8 @@
15
15
  * door), every font word becomes its CSS stack (X14).
16
16
  */
17
17
  import { Intervals } from '../../constants/interval.constants.js';
18
- import { barEndMs, barStartMs } from '../chart/calendar-interval.util.js';
19
- import { intervalLabelForMs } from '../chart/interval-ladder.util.js';
18
+ import { barEndMs, periodStartMs } from '../chart/calendar-interval.util.js';
19
+ import { intervalLabelForMs, LENGTH_TABLE_INTERVAL_LABELS } from '../chart/interval-ladder.util.js';
20
20
  import { viewScaledProfileRowMultiplier } from '../chart/profile-row-height.util.js';
21
21
  import { marketSessionAtOrBefore, marketSessionNamed, profileRegionSessionKeys, } from '../chart/market-sessions.util.js';
22
22
  import { getSessionInterval } from '../chart/session-interval.util.js';
@@ -81,7 +81,8 @@ function intervalLabelOf(intervalMs) {
81
81
  return exact;
82
82
  let best;
83
83
  let bestMs = -1;
84
- for (const [label, length] of Object.entries(Intervals.map_unit)) {
84
+ for (const label of LENGTH_TABLE_INTERVAL_LABELS) {
85
+ const length = Intervals.map_unit[label];
85
86
  if (length <= intervalMs && length > bestMs) {
86
87
  best = label;
87
88
  bestMs = length;
@@ -157,7 +158,7 @@ function newestCloseMs(ctx, rows) {
157
158
  /** The rows of the session holding the newest bar (span "developing"): the
158
159
  * window of the session length that contains the newest row's timestamp, or
159
160
  * for a region its own session (the latest one opened by the newest row). A
160
- * month, quarter, half-year or year session is its calendar bar (`barStartMs`
161
+ * month, quarter, half-year or year session is its calendar bar (`periodStartMs`
161
162
  * to `barEndMs`): the epoch floor of the average length opened the March 2026
162
163
  * session on January 31 10:30 and handed it February's row too. */
163
164
  function developingRows(rows, keys) {
@@ -172,7 +173,7 @@ function developingRows(rows, keys) {
172
173
  return [];
173
174
  const regionWindow = keys.region !== undefined ? marketSessionNamed(keys.region) : null;
174
175
  const regionSession = regionWindow ? marketSessionAtOrBefore(regionWindow, newest) : null;
175
- const start = regionSession ? regionSession[0] : barStartMs(newest, sessionMs);
176
+ const start = regionSession ? regionSession[0] : periodStartMs(newest, sessionMs);
176
177
  const end = regionSession ? regionSession[1] : barEndMs(start, sessionMs);
177
178
  return rows.filter((row) => {
178
179
  const ts = rowTs(row);
@@ -31,3 +31,13 @@ export declare function isPlaceholderWrunTitle(title: unknown, address?: string
31
31
  /** The first candidate that is a name (`isPlaceholderWrunTitle` false for the package's `address`),
32
32
  * trimmed; else `fallback`, as given. */
33
33
  export declare function pickWrunDisplayName(candidates: ReadonlyArray<unknown>, fallback: string, address?: string | null): string;
34
+ /**
35
+ * Whether a chart row's saved `customName` is a stand-in its mount froze (the heal on restore may rename it), and
36
+ * not a name the user gave the row. The name must read as a placeholder (isPlaceholderWrunTitle), and so must the
37
+ * row's mount stamp `meta.plots[0]`, the name the row was added under (a fresh add, a twin conversion carrying a
38
+ * legacy rename, or the heal itself, which moves the stamp with the name): a placeholder name over a real stamp is a
39
+ * user's rename that only looks like one. A row saved without a stamp is judged by the placeholder rule alone. The
40
+ * one case the row cannot tell apart: a rename to a placeholder word made while the stamp was still a placeholder
41
+ * (never healed, or a twin converted from a legacy rename that was itself a placeholder word) is healed.
42
+ */
43
+ export declare function isFrozenWrunStandInName(settings: unknown, address?: string | null): boolean;
@@ -62,3 +62,24 @@ export function pickWrunDisplayName(candidates, fallback, address) {
62
62
  }
63
63
  return fallback;
64
64
  }
65
+ /**
66
+ * Whether a chart row's saved `customName` is a stand-in its mount froze (the heal on restore may rename it), and
67
+ * not a name the user gave the row. The name must read as a placeholder (isPlaceholderWrunTitle), and so must the
68
+ * row's mount stamp `meta.plots[0]`, the name the row was added under (a fresh add, a twin conversion carrying a
69
+ * legacy rename, or the heal itself, which moves the stamp with the name): a placeholder name over a real stamp is a
70
+ * user's rename that only looks like one. A row saved without a stamp is judged by the placeholder rule alone. The
71
+ * one case the row cannot tell apart: a rename to a placeholder word made while the stamp was still a placeholder
72
+ * (never healed, or a twin converted from a legacy rename that was itself a placeholder word) is healed.
73
+ */
74
+ export function isFrozenWrunStandInName(settings, address) {
75
+ if (settings === null || typeof settings !== 'object')
76
+ return false;
77
+ const { customName, meta } = settings;
78
+ if (typeof customName !== 'string' || customName.trim() === '')
79
+ return false;
80
+ if (!isPlaceholderWrunTitle(customName, address))
81
+ return false;
82
+ const plots = meta?.plots;
83
+ const stamp = Array.isArray(plots) ? plots[0] : undefined;
84
+ return typeof stamp !== 'string' || isPlaceholderWrunTitle(stamp, address);
85
+ }
@@ -140,6 +140,8 @@ export declare function replayResolutionSourceLabel(tf: ReplayResolution, chartI
140
140
  export declare function supportedReplaySourceInterval(intervalLabel: string): string;
141
141
  export declare function replayCandleSourceInterval(chartIntervalMs: number): string;
142
142
  export declare function alignProbeCursorMs(cursorMs: number, stepMs: number): number;
143
+ /** The epoch-grid origin of replay's chart buckets. Replay owns it and refuses a typed width (useReplayToggle), so
144
+ * the typed day and week grid from Monday 2000-01-03 never reaches it. */
143
145
  export declare function chartBucketOriginMs(chartIntervalMs: number): number;
144
146
  /**
145
147
  * The market a replay's chart bars are keyed for: the buffer's `barVenue` (the chart's own, its
@@ -602,6 +602,8 @@ export function alignProbeCursorMs(cursorMs, stepMs) {
602
602
  }
603
603
  return Math.max(0, Math.floor(cursorMs / stepMs) * stepMs);
604
604
  }
605
+ /** The epoch-grid origin of replay's chart buckets. Replay owns it and refuses a typed width (useReplayToggle), so
606
+ * the typed day and week grid from Monday 2000-01-03 never reaches it. */
605
607
  export function chartBucketOriginMs(chartIntervalMs) {
606
608
  if (chartIntervalMs === WEEK_MS) {
607
609
  return MONDAY_BUCKET_ORIGIN_MS;
@@ -58,7 +58,7 @@ export interface SlotSpec {
58
58
  subscribeParams: SlotSubscribeParams;
59
59
  workerKeepalive: SlotWorkerKeepalive;
60
60
  mainThreadKeepalive: SlotMainThreadKeepalive;
61
- /** GOING_AWAY handover target; a `WsSlotId` (validated by the table-shape spec), or null: no parking target (a gate slot bounces on the notice instead, a core reader only reports it). */
61
+ /** GOING_AWAY handover target; a `WsSlotId` (validated by the table-shape spec), or null: no parking target (a gate slot, core reader or /v3 lane bounces on the notice instead; a blk reader's connection moves it on the GOING_AWAY post). */
62
62
  parkingSlot: string | null;
63
63
  urlKey: SlotUrlKey;
64
64
  pathPrefix: SlotPathPrefix;
@@ -1,4 +1,4 @@
1
- import { barStartMs, isCalendarIntervalMs } from '../../utility/chart/calendar-interval.util.js';
1
+ import { barStartMs, fixedGridOffsetSec, isCalendarIntervalMs } from '../../utility/chart/calendar-interval.util.js';
2
2
  /**
3
3
  * Returns UTC midnight on the Monday that contains the supplied timestamp.
4
4
  * Kept worker-local so time bucketing does not load the chart engine.
@@ -19,6 +19,6 @@ export function findMonday(unixTimeStamp) {
19
19
  */
20
20
  export function periodToFormingBarSec(fromSec, nowSec, intervalMs) {
21
21
  if (!isCalendarIntervalMs(intervalMs))
22
- return nowSec - fromSec - (nowSec % (intervalMs / 1000));
22
+ return nowSec - fromSec - fixedGridOffsetSec(nowSec, intervalMs / 1000);
23
23
  return barStartMs(nowSec * 1000, intervalMs) / 1000 - fromSec;
24
24
  }
@@ -201,3 +201,12 @@ export declare function normalizeTicksPerBar(value: unknown): number;
201
201
  * absorbs float noise in the ratio — real ticksPerBar is always an integer, so N is too.
202
202
  */
203
203
  export declare function alignBucketsToGrid(liveBuckets: VolumeProfileBucket[], existingRows: (number | number[])[][]): VolumeProfileBucket[];
204
+ /**
205
+ * Prices coin-volume ladder rows in dollars: the dollar read of a session-held stock ladder, which the gateway serves
206
+ * in coins only (script-source-session.util). `step` is the served grid's width (the response's `series.blockSize`, or
207
+ * the metadata block size when the response names none): each cell is priced at the middle of its row, at most half a
208
+ * step over the price off (0.01 at $190 is 0.003 percent). With no width known (`step` 0) a cell is priced at its low,
209
+ * never at an invented width: under-priced by at most the cell's real width over its price. The rows are the gateway's
210
+ * native cells, priced before any rebucket or clamp. Writes new rows; `rows` is never mutated.
211
+ */
212
+ export declare function priceProfileRowsInDollars<T extends [number, ...Array<[number, number, number, number]>]>(rows: readonly T[], step: number): T[];
@@ -632,3 +632,23 @@ export function alignBucketsToGrid(liveBuckets, existingRows) {
632
632
  }
633
633
  return liveBuckets;
634
634
  }
635
+ /**
636
+ * Prices coin-volume ladder rows in dollars: the dollar read of a session-held stock ladder, which the gateway serves
637
+ * in coins only (script-source-session.util). `step` is the served grid's width (the response's `series.blockSize`, or
638
+ * the metadata block size when the response names none): each cell is priced at the middle of its row, at most half a
639
+ * step over the price off (0.01 at $190 is 0.003 percent). With no width known (`step` 0) a cell is priced at its low,
640
+ * never at an invented width: under-priced by at most the cell's real width over its price. The rows are the gateway's
641
+ * native cells, priced before any rebucket or clamp. Writes new rows; `rows` is never mutated.
642
+ */
643
+ export function priceProfileRowsInDollars(rows, step) {
644
+ const half = step > 0 ? step / 2 : 0;
645
+ return rows.map((row) => {
646
+ const out = [row[0]];
647
+ for (let at = 1; at < row.length; at += 1) {
648
+ const [low, high, buy, sell] = row[at];
649
+ const price = low + half;
650
+ out.push([low, high, buy * price, sell * price]);
651
+ }
652
+ return out;
653
+ });
654
+ }
@@ -96,6 +96,9 @@ export interface WrunStrategyRunConfig {
96
96
  config: StrategyDeclaredConfig;
97
97
  /** The chart interval, so `finalize()` populates the annualized stats. */
98
98
  intervalMs?: number;
99
+ /** The chart market's point value (`wrunStrategyPointValue`), handed to the broker as its `pointValue`; absent on a
100
+ * market with none, where the broker reads 1. */
101
+ pointValue?: number;
99
102
  /** Track and answer the `strategy.order` / `strategy.fill` event streams
100
103
  * and the reserved outputs (the corpus replay; the chart never needs
101
104
  * them). Off by default. */
@@ -85,7 +85,7 @@
85
85
  * never re-executed per tick.
86
86
  */
87
87
  import { wrunChartHostEnv } from '../../host-env.js';
88
- import { abiAtLeast, WrunLiveOrderError, } from '../../interfaces/wrun-runtime.interface.js';
88
+ import { abiAtLeast, attachWrunTrap, WrunLiveOrderError, wrunTrapOf, } from '../../interfaces/wrun-runtime.interface.js';
89
89
  import { WRUN3_DRAW_REFUSALS, WrunDrawRefusalError, WrunHandleLedger, } from '../../utility/wrun/wrun-handles.util.js';
90
90
  import { WRUN_RENDER_RESULT_LIMIT_BYTES } from '../../utility/wrun/wrun-render-select.util.js';
91
91
  import { WRUN5_TEXT_IMPORTS, WRUN5_TEXT_REFUSALS, wrunPlainText } from '../../utility/wrun/wrun-text-params.util.js';
@@ -251,6 +251,8 @@ export async function createWrunAbiSession(config) {
251
251
  rowIndex: 0,
252
252
  barLast: 0,
253
253
  barCount: 0,
254
+ trapBarIndex: -1,
255
+ trapBarTs: 0,
254
256
  };
255
257
  // The rows block the import closures currently serve from. Reassigned per
256
258
  // runRows call; the phase guards make any host import call outside a
@@ -304,9 +306,19 @@ export async function createWrunAbiSession(config) {
304
306
  // anchors the row on the buffer only when the path is src/indicator.ts
305
307
  // (utility/scriptEditor/runtime-diagnostics.util.ts). Reads only: nothing here
306
308
  // touches the memory ceiling or the no-growth rule.
309
+ // The record (what the guest passed, the phase, the bar) is taken here, before
310
+ // `formatAssemblyScriptAbort` builds the text: readers classify the record, never the text.
307
311
  abort(message, fileName, line, column) {
308
312
  const memory = exportedMemory(instanceRef.exports);
309
- throw new Error(formatAssemblyScriptAbort(readAssemblyScriptString(memory, message), readAssemblyScriptString(memory, fileName), line, column));
313
+ const abort = {
314
+ message: readAssemblyScriptString(memory, message),
315
+ path: readAssemblyScriptString(memory, fileName),
316
+ line,
317
+ column,
318
+ };
319
+ const error = new Error(formatAssemblyScriptAbort(abort.message, abort.path, line, column));
320
+ recordWrunTrap(host, error, abort);
321
+ throw error;
310
322
  },
311
323
  },
312
324
  wrun: {
@@ -668,6 +680,7 @@ export async function createWrunAbiSession(config) {
668
680
  ? new sharedHost.WrunStrategyHost({
669
681
  config: config.strategy.config,
670
682
  ...(config.strategy.intervalMs !== undefined ? { intervalMs: config.strategy.intervalMs } : {}),
683
+ pointValue: config.strategy.pointValue,
671
684
  phase: () => host.phase,
672
685
  memory: () => exportedMemory(instanceRef.exports),
673
686
  events: config.strategy.events === true,
@@ -677,7 +690,17 @@ export async function createWrunAbiSession(config) {
677
690
  Object.assign(importObject.wrun, strategyHost.imports);
678
691
  else if (abiAtLeast(config.abi, 'wrun-3'))
679
692
  refuseUndeclaredStrategyImports(config.module);
680
- const instance = await WebAssembly.instantiate(config.module, importObject);
693
+ let instance;
694
+ try {
695
+ instance = await WebAssembly.instantiate(config.module, importObject);
696
+ }
697
+ catch (error) {
698
+ // A start-section trap (or a host import it called) names the start phase; a link or compile refusal is no trap.
699
+ if (!(error instanceof WebAssembly.LinkError) && !(error instanceof WebAssembly.CompileError)) {
700
+ recordWrunTrap(host, error);
701
+ }
702
+ throw error;
703
+ }
681
704
  // Instantiated: the guest's first call (init) runs next, in this same turn.
682
705
  config.onInstantiated?.();
683
706
  instanceRef.exports = instance.exports;
@@ -687,7 +710,13 @@ export async function createWrunAbiSession(config) {
687
710
  const finalize = requireFunction(exports.finalize, 'finalize');
688
711
  requireFunction(exports.reset, 'reset');
689
712
  resetHostResult(host);
690
- guestCall(host, 'init', config.initArgs, -1, init);
713
+ try {
714
+ guestCall(host, 'init', config.initArgs, -1, init);
715
+ }
716
+ catch (error) {
717
+ recordWrunTrap(host, error);
718
+ throw error;
719
+ }
691
720
  checkMemoryLimit(exports, memoryLimit);
692
721
  const memoryBaselineBytes = exportedMemoryByteLength(exports);
693
722
  // The memory ceiling and the no-growth rule after EVERY guest call, with no
@@ -744,6 +773,10 @@ export async function createWrunAbiSession(config) {
744
773
  const evaluateRow = (block, row, rowIndex, barLast, mode) => {
745
774
  bindBlock(block);
746
775
  resetHostResult(host);
776
+ // The bar a trap in this row names (cleared on both returns below; a
777
+ // throw leaves it for the catch in runRows to read).
778
+ host.trapBarIndex = rowIndex;
779
+ host.trapBarTs = block.ts[row];
747
780
  // The row's time rides every draw call it skips (the record's `ts`, the
748
781
  // chart's row unit: epoch ms).
749
782
  ledger?.beginRow(block.ts[row]);
@@ -754,11 +787,14 @@ export async function createWrunAbiSession(config) {
754
787
  const stateResult = guestCall(host, 'state', EMPTY_ARGS, row, state);
755
788
  checkMemoryAfterCall();
756
789
  const readiness = typeof stateResult === 'number' ? stateResult : Number(stateResult ?? 0);
757
- if (readiness < 1)
790
+ if (readiness < 1) {
791
+ host.trapBarIndex = -1;
758
792
  return false;
793
+ }
759
794
  guestCall(host, 'finalize', EMPTY_ARGS, -1, finalize);
760
795
  checkMemoryAfterCall();
761
796
  validateDeclaredOutputs(host, outputCount);
797
+ host.trapBarIndex = -1;
762
798
  return true;
763
799
  };
764
800
  const runRows = (block, mode) => {
@@ -920,7 +956,13 @@ export async function createWrunAbiSession(config) {
920
956
  }
921
957
  }
922
958
  }
959
+ catch (error) {
960
+ // One catch for the whole block, outside the row loop: the trap's bar and phase as the failing row left them.
961
+ recordWrunTrap(host, error);
962
+ throw error;
963
+ }
923
964
  finally {
965
+ host.trapBarIndex = -1;
924
966
  current = null;
925
967
  }
926
968
  // The ledger's full live set rides beside every block's rows (the wire
@@ -1010,6 +1052,41 @@ export async function runWrunPackedRequest(request, options = {}) {
1010
1052
  });
1011
1053
  return session.runRows(request, request.mode);
1012
1054
  }
1055
+ /** The phase a failure names: the guest call that was running (a trap leaves `phase` where it trapped), else the
1056
+ * host's checks after a row's guest call while a row is being evaluated; null outside both (a refusal before any
1057
+ * row, a host step between rows): no trap. */
1058
+ function trapPhaseOf(host) {
1059
+ switch (host.phase) {
1060
+ case 'instantiate':
1061
+ return 'start';
1062
+ case 'init':
1063
+ case 'state':
1064
+ case 'finalize':
1065
+ return host.phase;
1066
+ default:
1067
+ return host.trapBarIndex >= 0 ? 'row-check' : null;
1068
+ }
1069
+ }
1070
+ /** Attach the trap record to a failure at the guest-call boundary, once (env.abort records first, with what the guest
1071
+ * passed; the catch that sees the same error later keeps that record). `native` is a WebAssembly.RuntimeError the
1072
+ * engine raised; every other error inside a guest call or a row check is the host's. The bar only while a row is
1073
+ * being evaluated. */
1074
+ function recordWrunTrap(host, error, abort) {
1075
+ if (wrunTrapOf(error) !== undefined)
1076
+ return;
1077
+ const phase = trapPhaseOf(host);
1078
+ if (phase === null)
1079
+ return;
1080
+ const native = abort === undefined && error instanceof WebAssembly.RuntimeError;
1081
+ const trap = {
1082
+ kind: abort !== undefined ? 'abort' : native ? 'native' : 'host',
1083
+ phase,
1084
+ ...(host.trapBarIndex >= 0 ? { bar: { index: host.trapBarIndex, ts: host.trapBarTs } } : {}),
1085
+ ...(abort !== undefined ? { abort } : {}),
1086
+ ...(native ? { native: { message: error.message } } : {}),
1087
+ };
1088
+ attachWrunTrap(error, trap);
1089
+ }
1013
1090
  /** Run one guest export with the phase and argument block it is owed. A
1014
1091
  * guest trap leaves `phase` at the phase that trapped: the whole request
1015
1092
  * fails, and the error message (for the cell channel) names that phase. */