@orangecharts/wrun-chart-host 0.15.0 → 0.16.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 (175) hide show
  1. package/README.md +1 -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 +10 -0
  5. package/dist/constants/feature-flags.constants.js +52 -4
  6. package/dist/constants/feature-limits.constants.d.ts +72 -4
  7. package/dist/constants/feature-limits.constants.js +98 -20
  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/typed-width-fold.leaf.d.ts +50 -0
  12. package/dist/constants/typed-width-fold.leaf.js +99 -0
  13. package/dist/constants/typed-width-source.leaf.d.ts +24 -0
  14. package/dist/constants/typed-width-source.leaf.js +126 -0
  15. package/dist/constants/typed-width.leaf.d.ts +57 -0
  16. package/dist/constants/typed-width.leaf.js +78 -0
  17. package/dist/host-env.d.ts +10 -0
  18. package/dist/host-env.js +7 -0
  19. package/dist/host-ports.types.d.ts +11 -0
  20. package/dist/index.d.ts +3 -0
  21. package/dist/index.js +3 -0
  22. package/dist/interfaces/kscript-diagnostics.interface.d.ts +28 -0
  23. package/dist/interfaces/wrun-runtime.interface.d.ts +63 -3
  24. package/dist/interfaces/wrun-runtime.interface.js +11 -0
  25. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +13 -0
  26. package/dist/kscript-data/controls/live-trades-merge.util.js +16 -1
  27. package/dist/market-data/billing.interface.d.ts +12 -45
  28. package/dist/market-data/billing.interface.js +2 -2
  29. package/dist/replay/replayLadder.js +7 -4
  30. package/dist/settings-templates/footprint-rows.d.ts +6 -0
  31. package/dist/settings-templates/footprint-rows.js +6 -0
  32. package/dist/settings-templates/frvp-fields.js +14 -0
  33. package/dist/settings-templates/indicator-fields.js +31 -0
  34. package/dist/settings-templates/tool-tables.generated.js +19 -1
  35. package/dist/utility/chart/__fixtures__/live-bucket-regular-golden.json +1706 -0
  36. package/dist/utility/chart/cache-alignment.util.d.ts +42 -0
  37. package/dist/utility/chart/cache-alignment.util.js +88 -18
  38. package/dist/utility/chart/calendar-interval.util.d.ts +83 -1
  39. package/dist/utility/chart/calendar-interval.util.js +152 -4
  40. package/dist/utility/chart/candle-bar-end.util.d.ts +11 -4
  41. package/dist/utility/chart/candle-bar-end.util.js +17 -6
  42. package/dist/utility/chart/chart-time-domain.util.d.ts +3 -0
  43. package/dist/utility/chart/chart-time-domain.util.js +13 -4
  44. package/dist/utility/chart/feed-interval.util.d.ts +4 -2
  45. package/dist/utility/chart/feed-interval.util.js +5 -2
  46. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +3 -1
  47. package/dist/utility/chart/fetch-dedupe-policy.util.js +19 -1
  48. package/dist/utility/chart/footprint-display-mode.util.d.ts +2 -0
  49. package/dist/utility/chart/footprint-display-mode.util.js +5 -0
  50. package/dist/utility/chart/governed-lanes-gate.util.d.ts +46 -0
  51. package/dist/utility/chart/governed-lanes-gate.util.js +71 -0
  52. package/dist/utility/chart/governed-lanes-reader-seat.d.ts +14 -0
  53. package/dist/utility/chart/governed-lanes-reader-seat.js +14 -0
  54. package/dist/utility/chart/history-wall.util.d.ts +13 -2
  55. package/dist/utility/chart/history-wall.util.js +11 -4
  56. package/dist/utility/chart/interval-ladder.util.d.ts +5 -2
  57. package/dist/utility/chart/interval-ladder.util.js +44 -4
  58. package/dist/utility/chart/interval-registry.util.d.ts +22 -1
  59. package/dist/utility/chart/interval-registry.util.js +50 -2
  60. package/dist/utility/chart/kscript-data-interval-restriction.leaf.d.ts +32 -4
  61. package/dist/utility/chart/kscript-data-interval-restriction.leaf.js +22 -5
  62. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +10 -0
  63. package/dist/utility/chart/kscript-drawing-safe-area.util.js +30 -3
  64. package/dist/utility/chart/kscript-legend-entries.util.d.ts +21 -4
  65. package/dist/utility/chart/kscript-legend-entries.util.js +27 -5
  66. package/dist/utility/chart/kscript-main-grid-stages.util.js +74 -24
  67. package/dist/utility/chart/kscript-row-name.leaf.d.ts +13 -0
  68. package/dist/utility/chart/kscript-row-name.leaf.js +18 -0
  69. package/dist/utility/chart/kscript-venue-policy.util.d.ts +61 -26
  70. package/dist/utility/chart/kscript-venue-policy.util.js +138 -37
  71. package/dist/utility/chart/live-bucket.util.d.ts +29 -4
  72. package/dist/utility/chart/live-bucket.util.js +45 -12
  73. package/dist/utility/chart/market-session.util.d.ts +62 -10
  74. package/dist/utility/chart/market-session.util.js +93 -13
  75. package/dist/utility/chart/marketKind.util.d.ts +1 -7
  76. package/dist/utility/chart/marketKind.util.js +6 -8
  77. package/dist/utility/chart/mixed-mode.util.d.ts +17 -0
  78. package/dist/utility/chart/om-target.util.js +6 -4
  79. package/dist/utility/chart/price-precision.util.d.ts +20 -6
  80. package/dist/utility/chart/price-precision.util.js +34 -7
  81. package/dist/utility/chart/profile-frame-window.util.d.ts +15 -0
  82. package/dist/utility/chart/profile-frame-window.util.js +12 -0
  83. package/dist/utility/chart/rth-session.util.d.ts +3 -1
  84. package/dist/utility/chart/rth-session.util.js +3 -1
  85. package/dist/utility/chart/script-source-session.util.d.ts +43 -0
  86. package/dist/utility/chart/script-source-session.util.js +61 -0
  87. package/dist/utility/chart/typed-width-grid.util.d.ts +23 -0
  88. package/dist/utility/chart/typed-width-grid.util.js +203 -0
  89. package/dist/utility/common/transformations.util.d.ts +6 -0
  90. package/dist/utility/common/transformations.util.js +28 -4
  91. package/dist/utility/number-format.util.d.ts +14 -1
  92. package/dist/utility/number-format.util.js +22 -4
  93. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +24 -1
  94. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +113 -0
  95. package/dist/utility/v2/v2-enums.leaf.js +3 -0
  96. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +9 -3
  97. package/dist/utility/wrun/wrun-batched-marks.util.js +65 -17
  98. package/dist/utility/wrun/wrun-canvases.util.d.ts +4 -2
  99. package/dist/utility/wrun/wrun-canvases.util.js +7 -12
  100. package/dist/utility/wrun/wrun-cap-notice.util.d.ts +5 -0
  101. package/dist/utility/wrun/wrun-cap-notice.util.js +23 -0
  102. package/dist/utility/wrun/wrun-card-style.util.d.ts +1 -1
  103. package/dist/utility/wrun/wrun-card-style.util.js +2 -2
  104. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +8 -0
  105. package/dist/utility/wrun/wrun-chart-market-facts.util.js +13 -1
  106. package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +10 -0
  107. package/dist/utility/wrun/wrun-child-overlay-id.util.js +24 -0
  108. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.d.ts +72 -0
  109. package/dist/utility/wrun/wrun-cloud-cme-stamp.util.js +151 -0
  110. package/dist/utility/wrun/wrun-color-facts.util.d.ts +3 -3
  111. package/dist/utility/wrun/wrun-color-facts.util.js +8 -5
  112. package/dist/utility/wrun/wrun-colour-tone.lazy.d.ts +20 -0
  113. package/dist/utility/wrun/wrun-colour-tone.lazy.js +23 -0
  114. package/dist/utility/wrun/wrun-colour-tone.util.d.ts +14 -0
  115. package/dist/utility/wrun/wrun-colour-tone.util.js +119 -0
  116. package/dist/utility/wrun/wrun-dark-pool.util.d.ts +3 -2
  117. package/dist/utility/wrun/wrun-dark-pool.util.js +5 -4
  118. package/dist/utility/wrun/wrun-frames.d.ts +1 -1
  119. package/dist/utility/wrun/wrun-frames.js +2 -2
  120. package/dist/utility/wrun/wrun-handles.util.d.ts +1 -1
  121. package/dist/utility/wrun/wrun-handles.util.js +1 -1
  122. package/dist/utility/wrun/wrun-host.service.d.ts +32 -2
  123. package/dist/utility/wrun/wrun-host.service.js +44 -2
  124. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +20 -0
  125. package/dist/utility/wrun/wrun-hosted-wire-caps.js +85 -2
  126. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +37 -0
  127. package/dist/utility/wrun/wrun-hosted-wire.util.js +54 -0
  128. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +1 -0
  129. package/dist/utility/wrun/wrun-hud-looks.util.js +6 -11
  130. package/dist/utility/wrun/wrun-integration-route.util.d.ts +24 -0
  131. package/dist/utility/wrun/wrun-integration-route.util.js +19 -0
  132. package/dist/utility/wrun/wrun-live-intake.util.js +17 -1
  133. package/dist/utility/wrun/wrun-live-patch.util.d.ts +6 -1
  134. package/dist/utility/wrun/wrun-live-patch.util.js +10 -4
  135. package/dist/utility/wrun/wrun-live-tick.util.js +59 -4
  136. package/dist/utility/wrun/wrun-overlay-drivers.util.js +3 -0
  137. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +15 -0
  138. package/dist/utility/wrun/wrun-overlay-run.util.js +274 -47
  139. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +1 -1
  140. package/dist/utility/wrun/wrun-panel-mount.util.js +42 -13
  141. package/dist/utility/wrun/wrun-pin-venues.util.js +5 -1
  142. package/dist/utility/wrun/wrun-refusal.util.d.ts +4 -0
  143. package/dist/utility/wrun/wrun-refusal.util.js +102 -13
  144. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  145. package/dist/utility/wrun/wrun-registry-errors.util.js +5 -3
  146. package/dist/utility/wrun/wrun-row-source-factory.js +17 -1
  147. package/dist/utility/wrun/wrun-row-source.d.ts +8 -1
  148. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +1 -1
  149. package/dist/utility/wrun/wrun-sandbox-row-source.js +9 -0
  150. package/dist/utility/wrun/wrun-setting-words.util.d.ts +12 -5
  151. package/dist/utility/wrun/wrun-setting-words.util.js +25 -8
  152. package/dist/utility/wrun/wrun-socket-row-source.d.ts +26 -1
  153. package/dist/utility/wrun/wrun-socket-row-source.js +125 -12
  154. package/dist/utility/wrun/wrun-source-rows.util.d.ts +3 -3
  155. package/dist/utility/wrun/wrun-source-rows.util.js +8 -7
  156. package/dist/utility/wrun/wrun-style-words.util.d.ts +31 -9
  157. package/dist/utility/wrun/wrun-style-words.util.js +46 -15
  158. package/dist/utility/wrun/wrun-trades-lane.util.js +2 -1
  159. package/dist/utility/wrun/wrun-trap-replay.util.d.ts +42 -0
  160. package/dist/utility/wrun/wrun-trap-replay.util.js +63 -0
  161. package/dist/utility/wrun/wrun-volume-profile.util.js +6 -5
  162. package/dist/utility/wrun-display-name.util.d.ts +10 -0
  163. package/dist/utility/wrun-display-name.util.js +21 -0
  164. package/dist/utils/replay/replay-buffer-math.d.ts +2 -0
  165. package/dist/utils/replay/replay-buffer-math.js +2 -0
  166. package/dist/workers/constants/socket-slots.d.ts +1 -1
  167. package/dist/workers/utils/time.worker.util.js +2 -2
  168. package/dist/workers/utils/volume-profile.worker.util.d.ts +9 -0
  169. package/dist/workers/utils/volume-profile.worker.util.js +20 -0
  170. package/dist/workers/wrun/wrun-abi-host.d.ts +3 -0
  171. package/dist/workers/wrun/wrun-abi-host.js +82 -5
  172. package/dist/workers/wrun/wrun-engine-handler.js +53 -4
  173. package/dist/workers/wrun/wrun-trap-frames.leaf.d.ts +28 -0
  174. package/dist/workers/wrun/wrun-trap-frames.leaf.js +108 -0
  175. package/package.json +11 -11
@@ -0,0 +1,99 @@
1
+ /**
2
+ * How a typed width (typed-width.leaf) reads an indicator the gateway does not serve at CUSTOM: the app asks for rows at
3
+ * the stored candle size the width is built from and folds them into the chart's bars itself. This leaf names that
4
+ * stored size. The cap on the widths that may fold volume-profile rows is `isTypedWidthProfileFoldAllowed`
5
+ * (typed-width.leaf). Dependency-free and off the boot path: workers and lazily loaded modules import it.
6
+ *
7
+ * It is also the one home of the closed-end rule (`typedClosedEndMs`, `keepBarsBeforeClosedEnd`) that every typed
8
+ * fold applies, the line workers (through typed-width-fold.worker.util) and the footprint workers alike.
9
+ */
10
+ import { isTypedWidth, isTypedWidthProfileFoldAllowed, STORED_BAR_SECONDS, TYPED_WIDTH_LABELS, TYPED_WIDTH_SECONDS, typedWidthSeconds, } from './typed-width.leaf.js';
11
+ /** The interval label of each stored candle size, by its length in seconds. */
12
+ const STORED_LABEL_BY_SECONDS = {
13
+ 60: '1m',
14
+ 300: '5m',
15
+ 900: '15m',
16
+ 3600: '1h',
17
+ 14400: '4h',
18
+ 86400: '1d',
19
+ 604800: '1w',
20
+ };
21
+ /** The coarsest stored candle size (seconds) that divides `seconds`; NaN when none does. */
22
+ export function storedBarSecondsDividing(seconds) {
23
+ let stored = NaN;
24
+ for (const size of STORED_BAR_SECONDS)
25
+ if (seconds % size === 0)
26
+ stored = size;
27
+ return stored;
28
+ }
29
+ /**
30
+ * The stored interval label a typed width is built from: 4m to 18m '1m'; 20m, 40m and 80m '5m'; 90m '15m'; 3h '1h';
31
+ * the day widths '1d'; the week widths '1w'. Undefined for any other label.
32
+ */
33
+ export function storedDivisorLabel(label) {
34
+ const seconds = typedWidthSeconds(label);
35
+ return seconds === undefined ? undefined : STORED_LABEL_BY_SECONDS[storedBarSecondsDividing(seconds)];
36
+ }
37
+ /**
38
+ * The stored size (seconds) a typed width reads volume-profile rows at, or undefined when the label is not a typed
39
+ * width or the cap refuses it (`isTypedWidthProfileFoldAllowed`).
40
+ */
41
+ export function typedWidthProfileSourceSeconds(label) {
42
+ if (!isTypedWidthProfileFoldAllowed(label))
43
+ return undefined;
44
+ return storedBarSecondsDividing(typedWidthSeconds(label));
45
+ }
46
+ /**
47
+ * The row interval (ms) a per-candle profile read asks for on a chart of `chartMs`: a typed width's stored size, and
48
+ * any other length unchanged. It maps every typed width, capped or not: the indicator verdict decides whether the read
49
+ * happens at all.
50
+ */
51
+ export function profileRowMsForChart(chartMs) {
52
+ return isTypedWidthLengthMs(chartMs) ? storedBarSecondsDividing(chartMs / 1000) * 1000 : chartMs;
53
+ }
54
+ /** True when a chart bar of `lengthMs` is a typed width (the footprint workers hold the chart length, not its label). */
55
+ export function isTypedWidthLengthMs(lengthMs) {
56
+ const seconds = lengthMs / 1000;
57
+ return TYPED_WIDTH_LABELS.some((label) => TYPED_WIDTH_SECONDS[label] === seconds);
58
+ }
59
+ /**
60
+ * The closed end of a typed read, in ms: the end of a window that closed before the server's now. The gateway's range
61
+ * includes its end (`bucket <= to`), so a closed window ending at T brings back the stored row AT T. On a typed width
62
+ * that row opens the NEXT typed bar, and the fold would turn it into a bar stamped T holding 1 of its k rows (a short
63
+ * sum, the first value instead of the last, the mean of one row). The next (newer) window starts at T and owns that bar
64
+ * whole, so the bar is dropped (`keepBarsBeforeClosedEnd`).
65
+ *
66
+ * `tf` is the chart's interval: a label (the line workers' `payload.tf`) or the bar length in ms (the footprint
67
+ * workers' `chartTfMs`). Both forms go through the one rule below.
68
+ *
69
+ * Undefined (nothing to drop) for:
70
+ * - an interval that is not a typed width, so regular intervals keep every row the wire sends;
71
+ * - a floating window (`fromSec` 0, the gateway's "latest period"), whose end moves with the server clock;
72
+ * - a window with no end (`periodSec` undefined);
73
+ * - a window that reaches the server's now (end at or after `nowSec`), which keeps its forming bar.
74
+ *
75
+ * `fromSec` and `periodSec` are the window as asked; flooring the start (`typedWindowSec`) does not move the end, so
76
+ * either the floored or the unfloored window gives the same answer. `nowSec` is the server's now (`serverNowMs()` in the
77
+ * caller), passed in so this helper stays pure.
78
+ */
79
+ export function typedClosedEndMs(fromSec, periodSec, tf, nowSec) {
80
+ const typed = typeof tf === 'number' ? isTypedWidthLengthMs(tf) : isTypedWidth(tf);
81
+ if (!typed || !(fromSec > 0) || periodSec === undefined)
82
+ return undefined;
83
+ const endSec = fromSec + periodSec;
84
+ return endSec < nowSec ? endSec * 1000 : undefined;
85
+ }
86
+ /**
87
+ * The folded bars that start before a closed end (`typedClosedEndMs`), in the bars' own unit (`unit`, default
88
+ * `'ms'`; `closedEndMs` is always in ms). A bar's time is its first element unless `timeOf` reads it. With no closed end
89
+ * (a regular label, a floating window, a window that reaches now) it returns the SAME array, untouched.
90
+ *
91
+ * Apply it where the folded rows are final for the request: after the fold, and before anything that reads one bar to
92
+ * shape the next (`transformData`, a forward-fill, a resident merge) or posts the rows.
93
+ */
94
+ export function keepBarsBeforeClosedEnd(bars, closedEndMs, unit = 'ms', timeOf = (bar) => bar[0]) {
95
+ if (closedEndMs === undefined)
96
+ return bars;
97
+ const end = unit === 's' ? closedEndMs / 1000 : closedEndMs;
98
+ return bars.filter((bar) => timeOf(bar) < end);
99
+ }
@@ -0,0 +1,24 @@
1
+ import type { LiveBucketVenue } from '../utility/chart/live-bucket.util.js';
2
+ import { type TypedGridKind } from '../utility/chart/typed-width-grid.util.js';
3
+ /** The served interval a custom size folds from, and the most of its rows one custom bar holds. */
4
+ export interface TypedWidthSource {
5
+ label: string;
6
+ rowsPerBar: number;
7
+ }
8
+ /** The most source rows one app-built custom bar may read. */
9
+ export declare const TYPED_SOURCE_MAX_ROWS = 20;
10
+ /** The candidate source intervals of a custom size, best first (deepest history, then fewest rows). */
11
+ export declare function typedWidthSourceCandidates(label: string): readonly string[];
12
+ /** The candidates of a custom size on one grid: the table less the ones whose bars straddle a custom edge there. */
13
+ export declare function typedWidthSourceCandidatesOn(label: string, kind: TypedGridKind): readonly string[];
14
+ /**
15
+ * The most rows of `sourceLabel` one bar of the custom size `label` holds on a grid: the width over the source length
16
+ * under a day; N for N days from 1d and for N weeks from 1w; for N weeks from 1d, 7N on the UTC grid (every day
17
+ * trades) and 5N on a session grid (a week holds five trade dates). NaN for a pair the table does not name.
18
+ */
19
+ export declare function typedSourceRowsPerBar(label: string, sourceLabel: string, kind: TypedGridKind): number;
20
+ /**
21
+ * The source of the custom size `label` on the chart's market: the first candidate the chart serves (`servable`)
22
+ * that needs at most TYPED_SOURCE_MAX_ROWS rows a bar. Null when the market has no interval to build it from.
23
+ */
24
+ export declare function typedWidthSource(label: string, venue: LiveBucketVenue | null | undefined, servable: (label: string) => boolean): TypedWidthSource | null;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Which served interval a custom size is built from in the app, and how many of its rows one custom bar can hold.
3
+ *
4
+ * The candidates are data, best first: the deepest history on the server, then the fewest rows a bar (the server keeps
5
+ * 15,000 bars of most sizes, 25,000 at 1h and 50,000 at 30m, so 90m reaches further from 30m than from anything
6
+ * finer). A candidate is kept on a grid only when none of its bars straddles a custom bar's edge there; the spec
7
+ * (tests/constants/typed-width-source.leaf.spec.ts) walks every candidate against the grid functions over a summer, a
8
+ * winter and both clock-change weeks, and the drops below are what that walk found. Nothing is scanned at run time.
9
+ *
10
+ * LAZY: loaded the first time a chart goes on a custom size the app builds. No eager module may import this file
11
+ * (tests/perf/typed-width-rules-lazy-closure.spec.ts).
12
+ */
13
+ import { typedWidthSeconds } from './typed-width.leaf.js';
14
+ import { typedGridKind } from '../utility/chart/typed-width-grid.util.js';
15
+ /** The most source rows one app-built custom bar may read. */
16
+ export const TYPED_SOURCE_MAX_ROWS = 20;
17
+ const MINUTE_S = 60;
18
+ const DAY_S = 86_400;
19
+ const WEEK_S = 604_800;
20
+ /** The served lengths a candidate can name, in seconds. */
21
+ const SOURCE_SECONDS = {
22
+ '1m': MINUTE_S,
23
+ '2m': 2 * MINUTE_S,
24
+ '3m': 3 * MINUTE_S,
25
+ '5m': 5 * MINUTE_S,
26
+ '10m': 10 * MINUTE_S,
27
+ '15m': 15 * MINUTE_S,
28
+ '30m': 30 * MINUTE_S,
29
+ '1h': 60 * MINUTE_S,
30
+ '1d': DAY_S,
31
+ '1w': WEEK_S,
32
+ };
33
+ /** The candidates of each custom size under a day, best first. */
34
+ const INTRADAY_CANDIDATES = {
35
+ '4m': ['2m', '1m'],
36
+ '6m': ['3m', '2m', '1m'],
37
+ '8m': ['2m', '1m'],
38
+ '9m': ['3m', '1m'],
39
+ '12m': ['3m', '2m', '1m'],
40
+ '16m': ['2m', '1m'],
41
+ '18m': ['3m', '2m', '1m'],
42
+ '20m': ['10m', '5m', '1m'],
43
+ '40m': ['10m', '5m'],
44
+ '80m': ['10m', '5m'],
45
+ '90m': ['30m', '15m', '5m'],
46
+ '3h': ['1h', '30m', '15m'],
47
+ };
48
+ const DAY_CANDIDATES = ['1d'];
49
+ const WEEK_CANDIDATES = ['1w', '1d'];
50
+ /**
51
+ * The candidates a grid cannot take, by custom size: their bars straddle a custom bar's edge there.
52
+ * - CME regular hours: the gateway keeps a regular-hours bucket of 30m or less whole by its start, so the 2m bucket
53
+ * at 16:14, the 10m one at 16:10 and the 30m one at 16:00 New York run past the 16:15 close that ends a custom bar
54
+ * (ES; the NYMEX 14:30 close sits on all three grids, but one table serves every CME product).
55
+ * - US stocks in regular hours and US options: an option's 1h bars sit on the UTC hour (the 09:00 New York bar holds
56
+ * the 09:30 open), where a regular-hours stock's sit on the 09:30 anchor; both grids take the same row, so 3h reads
57
+ * 30m on each (the stock's drop is held, not refuted: the spec names it). An option prints nothing after its 16:15 close, so a source bar that opens before it (the 16:10 10m
58
+ * bar) holds only rows of the session's short last bar.
59
+ */
60
+ const STRADDLING = {
61
+ 'cme-regular': {
62
+ '4m': ['2m'],
63
+ '6m': ['2m'],
64
+ '8m': ['2m'],
65
+ '12m': ['2m'],
66
+ '16m': ['2m'],
67
+ '18m': ['2m'],
68
+ '20m': ['10m'],
69
+ '40m': ['10m'],
70
+ '80m': ['10m'],
71
+ '90m': ['30m'],
72
+ '3h': ['30m'],
73
+ },
74
+ 'equity-regular': {
75
+ '3h': ['1h'],
76
+ },
77
+ options: {
78
+ '3h': ['1h'],
79
+ },
80
+ };
81
+ /** The candidate source intervals of a custom size, best first (deepest history, then fewest rows). */
82
+ export function typedWidthSourceCandidates(label) {
83
+ const seconds = typedWidthSeconds(label);
84
+ if (seconds === undefined)
85
+ return [];
86
+ if (seconds < DAY_S)
87
+ return INTRADAY_CANDIDATES[label] ?? [];
88
+ return seconds % WEEK_S === 0 ? WEEK_CANDIDATES : DAY_CANDIDATES;
89
+ }
90
+ /** The candidates of a custom size on one grid: the table less the ones whose bars straddle a custom edge there. */
91
+ export function typedWidthSourceCandidatesOn(label, kind) {
92
+ const dropped = STRADDLING[kind]?.[label];
93
+ const candidates = typedWidthSourceCandidates(label);
94
+ return dropped ? candidates.filter((candidate) => !dropped.includes(candidate)) : candidates;
95
+ }
96
+ /**
97
+ * The most rows of `sourceLabel` one bar of the custom size `label` holds on a grid: the width over the source length
98
+ * under a day; N for N days from 1d and for N weeks from 1w; for N weeks from 1d, 7N on the UTC grid (every day
99
+ * trades) and 5N on a session grid (a week holds five trade dates). NaN for a pair the table does not name.
100
+ */
101
+ export function typedSourceRowsPerBar(label, sourceLabel, kind) {
102
+ const seconds = typedWidthSeconds(label);
103
+ const sourceSeconds = SOURCE_SECONDS[sourceLabel];
104
+ if (seconds === undefined || sourceSeconds === undefined)
105
+ return Number.NaN;
106
+ if (seconds < DAY_S || sourceSeconds !== DAY_S || seconds % WEEK_S !== 0)
107
+ return seconds / sourceSeconds;
108
+ const weeks = seconds / WEEK_S;
109
+ return kind === 'utc' ? 7 * weeks : 5 * weeks;
110
+ }
111
+ /**
112
+ * The source of the custom size `label` on the chart's market: the first candidate the chart serves (`servable`)
113
+ * that needs at most TYPED_SOURCE_MAX_ROWS rows a bar. Null when the market has no interval to build it from.
114
+ */
115
+ export function typedWidthSource(label, venue, servable) {
116
+ const seconds = typedWidthSeconds(label);
117
+ if (seconds === undefined)
118
+ return null;
119
+ const kind = typedGridKind(seconds * 1000, venue);
120
+ for (const candidate of typedWidthSourceCandidatesOn(label, kind)) {
121
+ const rowsPerBar = typedSourceRowsPerBar(label, candidate, kind);
122
+ if (rowsPerBar <= TYPED_SOURCE_MAX_ROWS && servable(candidate) === true)
123
+ return { label: candidate, rowsPerBar };
124
+ }
125
+ return null;
126
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Typed widths: candle widths a person types that sit on no ladder rung. Under a day each is a whole divisor of a UTC
3
+ * day, so its bars lie on the plain epoch grid; from a day up each is whole days (2 to 20 days, 2 to 20 weeks), and
4
+ * its bars count from Monday 2000-01-03 (calendar-interval.util `fixedGridFloorMs`). The gateway serves one as the wire
5
+ * interval CUSTOM plus `barSeconds`, built from the coarsest stored candle size that divides it, and refuses a width
6
+ * that reads more than `TYPED_WIDTH_MAX_STORED_BARS` stored candles per bar. Dependency-free: workers and leaf modules
7
+ * import it.
8
+ */
9
+ type DayCount = 2 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20;
10
+ type WeekCount = 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20;
11
+ declare const INTRADAY_TYPED_WIDTH_SECONDS: {
12
+ readonly '4m': 240;
13
+ readonly '6m': 360;
14
+ readonly '8m': 480;
15
+ readonly '9m': 540;
16
+ readonly '12m': 720;
17
+ readonly '16m': 960;
18
+ readonly '18m': 1080;
19
+ readonly '20m': 1200;
20
+ readonly '40m': 2400;
21
+ readonly '80m': 4800;
22
+ readonly '90m': 5400;
23
+ readonly '3h': 10800;
24
+ };
25
+ export type TypedWidth = keyof typeof INTRADAY_TYPED_WIDTH_SECONDS | `${DayCount}d` | `${WeekCount}w`;
26
+ /**
27
+ * The typed widths and their lengths in seconds: the 12 under a day shortest first, then the day and week sizes by
28
+ * count (2d 2w 3w 4d 4w ...). One label per length: 7 days is the `1w` rung, 14 days `2w`, 3 days the `3d` rung. No
29
+ * reader relies on the order. Every one reads at most 20 stored candles a bar.
30
+ */
31
+ export declare const TYPED_WIDTH_SECONDS: Readonly<Record<TypedWidth, number>>;
32
+ export declare const TYPED_WIDTH_LABELS: readonly TypedWidth[];
33
+ /** The candle sizes the gateway stores (1m 5m 15m 1h 4h 1d 1w), in seconds, shortest first. */
34
+ export declare const STORED_BAR_SECONDS: readonly number[];
35
+ /** The gateway's limit: a typed width reads at most this many stored candles for one bar. */
36
+ export declare const TYPED_WIDTH_MAX_STORED_BARS = 20;
37
+ /** Stored candles one bar of `seconds` reads: the width over the coarsest stored size that divides it (NaN for none). */
38
+ export declare function storedBarsPerTypedWidth(seconds: number): number;
39
+ export declare const CUSTOM_WIRE_INTERVAL = 26;
40
+ export declare const CUSTOM_WIRE_INTERVAL_NAME = "CUSTOM";
41
+ export declare function isTypedWidth(label: unknown): label is TypedWidth;
42
+ /** The bar length a typed width asks the gateway for (`barSeconds`), undefined for any other label. */
43
+ export declare function typedWidthSeconds(label: unknown): number | undefined;
44
+ /**
45
+ * The most stored candles a typed width may fold into one bar of volume-profile rows (the range profiles, and
46
+ * footprints where they fold).
47
+ */
48
+ export declare const TYPED_WIDTH_PROFILE_FOLD_MAX_STORED_BARS = 8;
49
+ /**
50
+ * Whether a typed width may fold volume-profile rows (footprints, the range profiles), which the app reads at the
51
+ * stored size and adds up itself (typed-width-fold.leaf): at most 8 stored candles a bar, and among the day widths
52
+ * only 2d, since a stored daily profile row weighs about 30 one-minute rows. That is 4m 6m 8m 20m 40m 90m 3h, 2d and
53
+ * 2w to 8w. False for every other label. The one cap rule: the indicator verdict reads it, and the chart-type door
54
+ * does for a chart type that folds rows.
55
+ */
56
+ export declare function isTypedWidthProfileFoldAllowed(label: unknown): boolean;
57
+ export {};
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Typed widths: candle widths a person types that sit on no ladder rung. Under a day each is a whole divisor of a UTC
3
+ * day, so its bars lie on the plain epoch grid; from a day up each is whole days (2 to 20 days, 2 to 20 weeks), and
4
+ * its bars count from Monday 2000-01-03 (calendar-interval.util `fixedGridFloorMs`). The gateway serves one as the wire
5
+ * interval CUSTOM plus `barSeconds`, built from the coarsest stored candle size that divides it, and refuses a width
6
+ * that reads more than `TYPED_WIDTH_MAX_STORED_BARS` stored candles per bar. Dependency-free: workers and leaf modules
7
+ * import it.
8
+ */
9
+ const INTRADAY_TYPED_WIDTH_SECONDS = {
10
+ '4m': 240,
11
+ '6m': 360,
12
+ '8m': 480,
13
+ '9m': 540,
14
+ '12m': 720,
15
+ '16m': 960,
16
+ '18m': 1080,
17
+ '20m': 1200,
18
+ '40m': 2400,
19
+ '80m': 4800,
20
+ '90m': 5400,
21
+ '3h': 10800,
22
+ };
23
+ /**
24
+ * The typed widths and their lengths in seconds: the 12 under a day shortest first, then the day and week sizes by
25
+ * count (2d 2w 3w 4d 4w ...). One label per length: 7 days is the `1w` rung, 14 days `2w`, 3 days the `3d` rung. No
26
+ * reader relies on the order. Every one reads at most 20 stored candles a bar.
27
+ */
28
+ export const TYPED_WIDTH_SECONDS = { ...INTRADAY_TYPED_WIDTH_SECONDS };
29
+ for (let n = 2; n < 21; n++) {
30
+ const rows = TYPED_WIDTH_SECONDS;
31
+ if (n % 7 && n !== 3)
32
+ rows[n + 'd'] = n * 86_400;
33
+ rows[n + 'w'] = n * 604_800;
34
+ }
35
+ export const TYPED_WIDTH_LABELS = Object.keys(TYPED_WIDTH_SECONDS);
36
+ /** The candle sizes the gateway stores (1m 5m 15m 1h 4h 1d 1w), in seconds, shortest first. */
37
+ export const STORED_BAR_SECONDS = [60, 300, 900, 3600, 14400, 86400, 604800];
38
+ /** The gateway's limit: a typed width reads at most this many stored candles for one bar. */
39
+ export const TYPED_WIDTH_MAX_STORED_BARS = 20;
40
+ /** Stored candles one bar of `seconds` reads: the width over the coarsest stored size that divides it (NaN for none). */
41
+ export function storedBarsPerTypedWidth(seconds) {
42
+ let stored = NaN;
43
+ for (const size of STORED_BAR_SECONDS)
44
+ if (seconds % size === 0)
45
+ stored = size;
46
+ return seconds / stored;
47
+ }
48
+ // The shared pb-common package and its parity-pinned enum leaf stop at HALF_YEAR (25): CUSTOM is 26 on the gateway.
49
+ export const CUSTOM_WIRE_INTERVAL = 26;
50
+ export const CUSTOM_WIRE_INTERVAL_NAME = 'CUSTOM';
51
+ const hasOwn = (record, key) => Object.prototype.hasOwnProperty.call(record, key);
52
+ export function isTypedWidth(label) {
53
+ return typeof label === 'string' && hasOwn(TYPED_WIDTH_SECONDS, label);
54
+ }
55
+ /** The bar length a typed width asks the gateway for (`barSeconds`), undefined for any other label. */
56
+ export function typedWidthSeconds(label) {
57
+ return isTypedWidth(label) ? TYPED_WIDTH_SECONDS[label] : undefined;
58
+ }
59
+ /**
60
+ * The most stored candles a typed width may fold into one bar of volume-profile rows (the range profiles, and
61
+ * footprints where they fold).
62
+ */
63
+ export const TYPED_WIDTH_PROFILE_FOLD_MAX_STORED_BARS = 8;
64
+ /**
65
+ * Whether a typed width may fold volume-profile rows (footprints, the range profiles), which the app reads at the
66
+ * stored size and adds up itself (typed-width-fold.leaf): at most 8 stored candles a bar, and among the day widths
67
+ * only 2d, since a stored daily profile row weighs about 30 one-minute rows. That is 4m 6m 8m 20m 40m 90m 3h, 2d and
68
+ * 2w to 8w. False for every other label. The one cap rule: the indicator verdict reads it, and the chart-type door
69
+ * does for a chart type that folds rows.
70
+ */
71
+ export function isTypedWidthProfileFoldAllowed(label) {
72
+ const seconds = typedWidthSeconds(label);
73
+ if (seconds === undefined)
74
+ return false;
75
+ const bars = storedBarsPerTypedWidth(seconds);
76
+ return (bars <= TYPED_WIDTH_PROFILE_FOLD_MAX_STORED_BARS &&
77
+ (seconds % 86_400 !== 0 || seconds % 604_800 === 0 || bars === 2));
78
+ }
@@ -310,6 +310,12 @@ export interface WrunHostChart {
310
310
  /** 0.5.0, panel-mount binder. web: scheduleKScriptLiveChartPaint(chartIndex, tc, getLatestTc, opts)
311
311
  * (utility/chart/kscript-chart-paint.util.ts:106; web's live-paint wait map stays the owner, D-2c). */
312
312
  scheduleLivePaint(chartIndex: number, tc: WrunChartHandle, getLatestTc?: () => WrunChartHandle | null | undefined, options?: WrunChartPaintOptions): WrunChartPaintMode;
313
+ /** Optional, panel-mount binder. Run `run` (synchronous) with the host's history recording held off: the engine
314
+ * deletes the drawings on a pane the panel mount removes, one delete event each, and a host whose undo store records
315
+ * an engine delete as a step must not record those (Discord #138: one step per drawing, none of which could land).
316
+ * web: withoutUndoSteps(run) (store/undo-step-hold.ts). Absent: the call runs plainly (`wrunHostWithoutUndoSteps`
317
+ * is its one reader); the sandbox worker and the phone app never set it. */
318
+ withoutUndoSteps?<T>(run: () => T): T;
313
319
  /** 0.5.0, run. web: decideLocalKScriptLiveRefreshGate(args) (utility/chart/kscript-live-refresh-pace.util.ts:112;
314
320
  * kScript's gate maps stay web, D-2c). */
315
321
  decideLiveRefreshGate(args: {
@@ -639,6 +645,10 @@ export declare function wrunHostCarryWithBuild(): boolean;
639
645
  * sheet's words). Read when a surface names a line, never at module load; utility/wrun/wrun-output-words.util
640
646
  * `wrunOutputWords` is its one reader. */
641
647
  export declare function wrunHostBuiltinLineWords(builtIn: string, label: string): string | undefined;
648
+ /** Run `run` (synchronous) with the host's history recording held off (`WrunHostChart.withoutUndoSteps`): a host that
649
+ * never set the member, or a realm whose env is not set, runs it plainly. Read at the call, never at module load;
650
+ * wrun-panel-mount.util `removeChild` is its one reader. */
651
+ export declare function wrunHostWithoutUndoSteps<T>(run: () => T): T;
642
652
  /** The error a host's `sharedHost()` throws before its load. */
643
653
  export declare function wrunChartHostUnloadedError(): Error;
644
654
  /** The shared host now, or its load: `undefined` once the env's `sharedHost()` answers, else the env's
package/dist/host-env.js CHANGED
@@ -62,6 +62,13 @@ export function wrunHostBuiltinLineWords(builtIn, label) {
62
62
  return undefined;
63
63
  }
64
64
  }
65
+ /** Run `run` (synchronous) with the host's history recording held off (`WrunHostChart.withoutUndoSteps`): a host that
66
+ * never set the member, or a realm whose env is not set, runs it plainly. Read at the call, never at module load;
67
+ * wrun-panel-mount.util `removeChild` is its one reader. */
68
+ export function wrunHostWithoutUndoSteps(run) {
69
+ const chart = hasWrunChartHostEnv() ? wrunChartHostEnv().chart : undefined;
70
+ return typeof chart?.withoutUndoSteps === 'function' ? chart.withoutUndoSteps(run) : run();
71
+ }
65
72
  /** The error a host's `sharedHost()` throws before its load. */
66
73
  export function wrunChartHostUnloadedError() {
67
74
  return new Error('wrun_chart_host_unloaded');
@@ -865,6 +865,8 @@ export interface WrunIntegrateOptions {
865
865
  preserveMountedRowsOutsideWindow?: WrunPartialReplayWindow | null;
866
866
  suppressDrawings?: boolean;
867
867
  deferDrawingsToReplayLane?: boolean;
868
+ /** The result does not speak for the overlay's drawings: the mounted set and its record stay as they are. */
869
+ keepMountedDrawings?: boolean;
868
870
  postApply?: (runResult: unknown, sideEffects: WrunIntegrationSideEffects) => void;
869
871
  }
870
872
  /** The adapter's full integration answer (web: `SafeKScriptTitanChartsIntegrationResult`). */
@@ -896,6 +898,8 @@ export interface WrunRefreshRowsOptions {
896
898
  runInterval?: WrunOverlayRunInterval | null;
897
899
  suppressDrawings?: boolean;
898
900
  deferDrawingsToReplayLane?: boolean;
901
+ /** The result does not speak for the overlay's drawings: the mounted set and its record stay as they are. */
902
+ keepMountedDrawings?: boolean;
899
903
  ignoreUnmountedOutputKeys?: ReadonlySet<string>;
900
904
  mergeMountedRows?: boolean;
901
905
  liveTail?: WrunLiveTailWindow;
@@ -1288,6 +1292,13 @@ export interface WrunFailureShow {
1288
1292
  code: string;
1289
1293
  chip: string;
1290
1294
  };
1295
+ /** The source door's facts of a source it refused: the interval it judged, and the source's machine name the door
1296
+ * bounded (`unknown` for a name the build does not own). The builder (wrun-failure-shown.util) sends them only
1297
+ * when the interval is a typed width. */
1298
+ refused?: {
1299
+ interval?: unknown;
1300
+ source?: unknown;
1301
+ };
1291
1302
  }
1292
1303
  /** Loader view of the editor shell store: its open tabs (web: store/editor-shell.ts `useEditorShellStore`). */
1293
1304
  export interface WrunEditorShellModule {
package/dist/index.d.ts CHANGED
@@ -23,6 +23,8 @@ export * from './constants/scriptEditor/execution.constants.js';
23
23
  export * from './constants/scriptEditor/technicalIndicatorScriptKeys.constants.js';
24
24
  export * from './constants/stocks-compliance.constants.js';
25
25
  export * from './constants/tpo-color-schemes.constants.js';
26
+ export * from './constants/typed-width-fold.leaf.js';
27
+ export * from './constants/typed-width.leaf.js';
26
28
  export * from './constants/venue-presets.constants.js';
27
29
  export * from './constants/wrun-prefix-safe.constants.js';
28
30
  export * from './enums/chart.enum.js';
@@ -125,6 +127,7 @@ export * from './utility/chart/kscript-mounted-plot-set.leaf.js';
125
127
  export * from './utility/chart/kscript-output-role.util.js';
126
128
  export * from './utility/chart/kscript-perf-tracker.util.js';
127
129
  export * from './utility/chart/kscript-provenance-keys.util.js';
130
+ export * from './utility/chart/kscript-row-name.leaf.js';
128
131
  export * from './utility/chart/kscript-run-interval-projection.util.js';
129
132
  export * from './utility/chart/kscript-run-result-equality.util.js';
130
133
  export * from './utility/chart/kscript-run-result-normalize.util.js';
package/dist/index.js CHANGED
@@ -26,6 +26,8 @@ export * from './constants/scriptEditor/execution.constants.js';
26
26
  export * from './constants/scriptEditor/technicalIndicatorScriptKeys.constants.js';
27
27
  export * from './constants/stocks-compliance.constants.js';
28
28
  export * from './constants/tpo-color-schemes.constants.js';
29
+ export * from './constants/typed-width-fold.leaf.js';
30
+ export * from './constants/typed-width.leaf.js';
29
31
  export * from './constants/venue-presets.constants.js';
30
32
  export * from './constants/wrun-prefix-safe.constants.js';
31
33
  export * from './enums/chart.enum.js';
@@ -129,6 +131,7 @@ export * from './utility/chart/kscript-mounted-plot-set.leaf.js';
129
131
  export * from './utility/chart/kscript-output-role.util.js';
130
132
  export * from './utility/chart/kscript-perf-tracker.util.js';
131
133
  export * from './utility/chart/kscript-provenance-keys.util.js';
134
+ export * from './utility/chart/kscript-row-name.leaf.js';
132
135
  export * from './utility/chart/kscript-run-interval-projection.util.js';
133
136
  export * from './utility/chart/kscript-run-result-equality.util.js';
134
137
  export * from './utility/chart/kscript-run-result-normalize.util.js';
@@ -1,3 +1,4 @@
1
+ import type { WrunTrapKind, WrunTrapPhase } from './wrun-runtime.interface.js';
1
2
  export type RuntimeDiagnosticStage = 'resolve' | 'fetch' | 'compute' | 'render' | 'boundary';
2
3
  export type RuntimeDiagnosticSeverity = 'error' | 'warning' | 'info';
3
4
  export interface RuntimeDiagnostic {
@@ -34,6 +35,33 @@ export interface RuntimeDiagnostic {
34
35
  */
35
36
  cme?: true;
36
37
  }
38
+ /** What failed, decided from the trap record (never from the text): a std-lib check the host names
39
+ * (`index-out-of-range`, `key-not-found`, `array-empty`), the engine's `unreachable`, any other abort
40
+ * (`abort`: a throw, the author's abort()), any other engine trap (`native`), or a host refusal (`host`). */
41
+ export type WrunTrapReason = 'index-out-of-range' | 'key-not-found' | 'array-empty' | 'unreachable' | 'abort' | 'native' | 'host';
42
+ /** `details.trap` of a browser-run trap row (WRUN_ABORT, WRUN_UNREACHABLE_TRAP and the other run failure rows). */
43
+ export interface WrunTrapRowDetails {
44
+ kind: WrunTrapKind;
45
+ phase: WrunTrapPhase;
46
+ reason: WrunTrapReason;
47
+ /** The failing bar's epoch-ms timestamp; absent before bar processing starts. */
48
+ barTs?: number;
49
+ /** The library position the abort named (`~lib/array.ts:114:42`) when it is not the author's file. */
50
+ libSite?: string;
51
+ /** The replay seed's token (a sandbox full run or live start): the editor's trap replay takes the seed by it. */
52
+ token?: string;
53
+ /** Set once the editor's replay enriched the row (never replayed again): `full` (line, and function unless the
54
+ * source inlines), `names` (function names, no offsets: no line). */
55
+ replay?: 'full' | 'names';
56
+ /** The function the trap stopped in, as written in src/indicator.ts (absent when the attribution is uncertain). */
57
+ fn?: string;
58
+ /** The first mapped line of `fn` in src/indicator.ts (names only: where its one mark goes). */
59
+ fnLine?: number;
60
+ /** The caller's function and the line and column of its call. */
61
+ caller?: string;
62
+ callerLine?: number;
63
+ callerColumn?: number;
64
+ }
37
65
  /** `details` of a FE_KSCRIPT_PERF_SLOW row: what the chip and the compact card show. */
38
66
  export interface KScriptPerfSlowDetails {
39
67
  cost: 'render' | 'apply' | 'both';
@@ -199,7 +199,17 @@ export interface WrunLiveEndRequest {
199
199
  }
200
200
  /** Everything the sandbox worker accepts. A bare WrunPackedRunRequest (no
201
201
  * `kind`) stays the classic one-shot run. */
202
- export type WrunWorkerRequest = WrunPackedRunRequest | WrunLiveStartRequest | WrunLiveRowsRequest | WrunLiveEndRequest | WrunModuleLoadRequest;
202
+ /** The editor's trap replay (a private host's worker only): one whole run of a TRACE build (unoptimised, with names
203
+ * and a source map), never a release module. It carries the trace bytes and their own sha256 (checked before
204
+ * anything compiles); the handler prepares them as it prepares a release module, never reads its module cache, a
205
+ * live session or a sheet pin, and answers a failure's trap record with the call frames (`trap.frames`, offsets in
206
+ * the trace build's own bytes). */
207
+ export interface WrunTraceRunRequest extends Omit<WrunPackedRunRequest, 'moduleKey' | 'moduleBytes'> {
208
+ kind: 'trace-run';
209
+ traceBytes: Uint8Array;
210
+ traceSha256: string;
211
+ }
212
+ export type WrunWorkerRequest = WrunPackedRunRequest | WrunLiveStartRequest | WrunLiveRowsRequest | WrunLiveEndRequest | WrunModuleLoadRequest | WrunTraceRunRequest;
203
213
  interface WrunPackedRunStrings {
204
214
  lens: Int32Array;
205
215
  offsets: Int32Array;
@@ -246,7 +256,54 @@ export type WrunWorkerResponse = {
246
256
  code?: 'live-order' | 'module-pin-mismatch' | 'module-compile-failed';
247
257
  /** `module-pin-mismatch` only: the hex sha256 the bytes hash to. */
248
258
  sha256?: string;
259
+ /** A guest trap or a host failure inside a guest call: where it happened (the ABI host's record,
260
+ * `wrunTrapOf`). `error` keeps the host's words unchanged beside it. */
261
+ trap?: WrunTrapContext;
249
262
  };
263
+ /** How the guest stopped: `abort` (env.abort: a throw, a std-lib check, the author's abort()), `native` (the engine
264
+ * trapped: `unreachable`, a bad memory access, a divide by zero) or `host` (a host import or a host check after a
265
+ * guest call refused). */
266
+ export type WrunTrapKind = 'abort' | 'native' | 'host';
267
+ /** The guest call that was running: `start` (the module's start section, during instantiation), `init`, `state`,
268
+ * `finalize`, or `row-check` (the host's checks after a row's guest call: memory, declared outputs). */
269
+ export type WrunTrapPhase = 'start' | 'init' | 'state' | 'finalize' | 'row-check';
270
+ /** One wasm call frame as an engine prints it; each field only when the engine printed it. */
271
+ export interface WrunTrapFrame {
272
+ index?: number;
273
+ name?: string;
274
+ offset?: number;
275
+ }
276
+ /** What the ABI host knew when a guest call failed, captured at the guest-call boundary before any text is
277
+ * formatted. A plain object: it crosses the worker boundary as is. */
278
+ export interface WrunTrapContext {
279
+ kind: WrunTrapKind;
280
+ phase: WrunTrapPhase;
281
+ /** The row being evaluated (0-based index in the run, epoch-ms timestamp); absent before bar processing starts. */
282
+ bar?: {
283
+ index: number;
284
+ ts: number;
285
+ };
286
+ /** env.abort's arguments as the guest passed them (null when the guest passed none; 0 for no position). */
287
+ abort?: {
288
+ message: string | null;
289
+ path: string | null;
290
+ line: number;
291
+ column: number;
292
+ };
293
+ /** `native` only: the engine's own words for the trap (`unreachable`, `memory access out of bounds`). */
294
+ native?: {
295
+ message: string;
296
+ };
297
+ /** The call frames at the trap, innermost first (the trace replay's: `wrun-trap-frames.leaf`), each with what the
298
+ * engine printed: the function index, its name, the byte offset in the trace build's own bytes. Absent on a
299
+ * release run. */
300
+ frames?: ReadonlyArray<WrunTrapFrame>;
301
+ }
302
+ /** The trap record rides beside the Error it explains (like `attachWrunLive`), so the Error's message stays the
303
+ * host's words every other reader matches on. Kept with the wire types so the worker and the main thread share one
304
+ * registry. */
305
+ export declare function attachWrunTrap(error: unknown, trap: WrunTrapContext): void;
306
+ export declare function wrunTrapOf(error: unknown): WrunTrapContext | undefined;
250
307
  /** One unpacked result row: `outputs` is null on a non-ready row; `strings`
251
308
  * entries are undefined for ABSENT slots and '' for present-empty writes. */
252
309
  export interface WrunOutputRow {
@@ -2564,7 +2621,8 @@ export interface WrunMarkSize {
2564
2621
  * (round-2 fold 1); the chart derives the pixels exactly as Big Trades 0.3.2 did. */
2565
2622
  export interface WrunMarksSection extends WrunBatchedSectionCommon {
2566
2623
  stride: 3;
2567
- /** 0 Bubble, 1 Soft dot, 2 Ring, 3 Square, 4 Diamond (hollow, a 1 px edge; the word `diamond`) (default 0). */
2624
+ /** 0 Bubble, 1 Soft dot, 2 Ring, 3 Square, 4 Diamond (hollow, a 1 px edge; the word `diamond`), 5 Glass, 6 Solid
2625
+ * (the words `glass`, `solid`: the Big Trades looks round) (default 0). */
2568
2626
  look?: number;
2569
2627
  size?: WrunMarkSize;
2570
2628
  /** 0 Candle center, 1 Trade time (the record's `offset_ms` inside the bar). */
@@ -2575,12 +2633,14 @@ export interface WrunMarksSection extends WrunBatchedSectionCommon {
2575
2633
  opacity_pct?: number;
2576
2634
  /** The caption: mode 0 Off, 1 Big bubbles (the largest a bar), 2 All (default 1, `compact`, 22 px); its
2577
2635
  * format a word of WRUN_BATCHED_NUMBER_FORMATS (`usd` dollars, `units` the market's own unit: Big Trades
2578
- * 0.7.0's Size shown as paints one of the two). */
2636
+ * 0.7.0's Size shown as paints one of the two); its place 0 `inside` the mark (default) or 1 `beside` it (the Big
2637
+ * Trades looks round). */
2579
2638
  text?: {
2580
2639
  mode?: number;
2581
2640
  field?: 'qty';
2582
2641
  format?: WrunBatchedNumberFormat;
2583
2642
  min_px?: number;
2643
+ place?: number | 'inside' | 'beside';
2584
2644
  };
2585
2645
  }
2586
2646
  /** One `spans[]` entry (`plot.spans`): per bar, `slots` records of `[top, bottom, length, meta]`