@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,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. */
@@ -44,9 +44,10 @@
44
44
  */
45
45
  import { ensureWrunChartHostSharedHost, wrunChartHostEnv } from '../../host-env.js';
46
46
  import { createWrunAbiSession, runWrunPackedRequest, WrunLiveOrderError, wrunModuleImportList, } from './wrun-abi-host.js';
47
- import { wrunModuleKey, } from '../../interfaces/wrun-runtime.interface.js';
47
+ import { attachWrunTrap, wrunModuleKey, wrunTrapOf, } from '../../interfaces/wrun-runtime.interface.js';
48
48
  import { clampWrunModuleMemory } from '../../utility/wrun/wrun-memory-clamp.util.js';
49
49
  import { wrunSha256Hex } from '../../utility/wrun/wrun-sha256.leaf.js';
50
+ import { parseWrunTrapFrames, WRUN_TRAP_STACK_LIMIT, wrunCodeSectionStart } from './wrun-trap-frames.leaf.js';
50
51
  /** How many compiled modules one engine worker keeps by `${sha256}|${abi}`: every package version, draft Run and REPL
51
52
  * compile mints a key, and a compiled module is mostly native memory the heap never shows. The client keeps its
52
53
  * handles in an LRU of the same size under the same name (wrun-host.service.ts); this one is the worker's own, and
@@ -73,12 +74,54 @@ class WrunModulePinMismatch extends Error {
73
74
  * change. Exported for the ABI drive specs that run a module exactly as the worker compiles it.
74
75
  */
75
76
  export async function compileWrunModuleBytes(bytes, abi) {
77
+ return WebAssembly.compile((await prepareWrunModuleBytes(bytes, abi)));
78
+ }
79
+ /** The bytes `compileWrunModuleBytes` compiles: clamped, then prepared for the ABI. */
80
+ async function prepareWrunModuleBytes(bytes, abi) {
76
81
  const bounded = clampWrunModuleMemory(bytes);
77
82
  const hostLoading = ensureWrunChartHostSharedHost();
78
83
  if (hostLoading)
79
84
  await hostLoading;
80
85
  const { prepareModuleBytes } = wrunChartHostEnv().sharedHost();
81
- return WebAssembly.compile(prepareModuleBytes(bounded, abi));
86
+ return prepareModuleBytes(bounded, abi);
87
+ }
88
+ /**
89
+ * The editor's trap replay (`trace-run`): the trace build's own bytes, checked against their own sha256 (never a
90
+ * sheet pin, never the module cache, never a live session), prepared exactly as a release module is prepared, run
91
+ * once over all rows. The stack limit is raised before the guest runs. A failure's trap record gains its call frames
92
+ * (`trap.frames`), each offset moved from the prepared bytes to the trace build's own by the code section delta (the
93
+ * clamp and the export rewrite both precede the code section and add no function, so one constant moves every code
94
+ * offset and function indexes hold). Answers like a full run.
95
+ */
96
+ async function runWrunTraceRequest(request, onInstantiated) {
97
+ const sha256 = wrunSha256Hex(request.traceBytes);
98
+ if (sha256 !== request.traceSha256) {
99
+ throw new WrunModulePinMismatch(`WRUN trace bytes (sha256 ${sha256}) do not match the trace build's sha256 ${request.traceSha256}`, sha256);
100
+ }
101
+ const prepared = await prepareWrunModuleBytes(request.traceBytes, request.abi);
102
+ const originalStart = wrunCodeSectionStart(request.traceBytes);
103
+ const preparedStart = wrunCodeSectionStart(prepared);
104
+ const delta = originalStart >= 0 && preparedStart >= 0 ? preparedStart - originalStart : null;
105
+ const module = await WebAssembly.compile(prepared);
106
+ const { kind: _kind, traceBytes: _traceBytes, traceSha256: _traceSha256, ...fields } = request;
107
+ // V8's stack depth knob (absent from the DOM types; an engine without it ignores the write).
108
+ const errorType = Error;
109
+ const previousLimit = errorType.stackTraceLimit;
110
+ errorType.stackTraceLimit = Math.max(previousLimit ?? 0, WRUN_TRAP_STACK_LIMIT);
111
+ try {
112
+ return await runWrunPackedRequest({ ...fields, module }, { onInstantiated });
113
+ }
114
+ catch (error) {
115
+ const trap = wrunTrapOf(error);
116
+ if (trap !== undefined && error instanceof Error) {
117
+ const frames = parseWrunTrapFrames(error.stack).map(({ offset, ...frame }) => offset !== undefined && delta !== null ? { ...frame, offset: offset - delta } : frame);
118
+ attachWrunTrap(error, { ...trap, frames });
119
+ }
120
+ throw error;
121
+ }
122
+ finally {
123
+ errorType.stackTraceLimit = previousLimit;
124
+ }
82
125
  }
83
126
  /** A full run as the ABI host runs it: the request's module key and bytes turned into the compiled module. */
84
127
  function resolvedRunRequest(request, module) {
@@ -86,7 +129,8 @@ function resolvedRunRequest(request, module) {
86
129
  return { ...fields, module };
87
130
  }
88
131
  /** A failure as the client reads it: the error's words, and the module codes (a pin mismatch with the digest found,
89
- * an engine compile refusal) the client maps back to today's error class and words. */
132
+ * an engine compile refusal) the client maps back to today's error class and words; a guest trap's record (the ABI
133
+ * host's, `wrunTrapOf`) rides beside the words as `trap`. */
90
134
  function failureOf(id, error) {
91
135
  const message = error instanceof Error ? error.message : String(error);
92
136
  if (error instanceof WrunModulePinMismatch) {
@@ -94,7 +138,8 @@ function failureOf(id, error) {
94
138
  }
95
139
  if (error instanceof WebAssembly.CompileError)
96
140
  return { id, ok: false, error: message, code: 'module-compile-failed' };
97
- return { id, ok: false, error: message };
141
+ const trap = wrunTrapOf(error);
142
+ return trap !== undefined ? { id, ok: false, error: message, trap } : { id, ok: false, error: message };
98
143
  }
99
144
  /** The engine worker's request handler, answering through `post`. The worker's entry makes one, after its env. */
100
145
  export function createWrunEngineHandler(post) {
@@ -205,6 +250,10 @@ export function createWrunEngineHandler(post) {
205
250
  await loadModule(request);
206
251
  return;
207
252
  }
253
+ if (request.kind === 'trace-run') {
254
+ postOutput(request.id, await runWrunTraceRequest(request, () => post({ id: request.id, running: true })));
255
+ return;
256
+ }
208
257
  if (request.kind === 'live-end') {
209
258
  const gate = liveEpochFor(request.sessionKey);
210
259
  if (request.epoch === undefined) {
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The wasm call frames of a trap's `error.stack`, in each engine's own words, and the code section start of a module
3
+ * (what the trace replay subtracts to move an engine offset from the prepared bytes to the trace build's own). An
4
+ * import-free leaf: the engine worker's handler parses with it, the specs read it directly.
5
+ *
6
+ * - V8 (Chrome): ` at src/indicator/lowestOf (wasm://wasm/7a6b2c1e:wasm-function[105]:0x1d5a)`, the hex being the
7
+ * module byte offset; Node prints the same frame as `(wasm://wasm/7a6b2c1e:1:7514)`, the column being the module
8
+ * byte offset plus 1. An unnamed function reads `at null.<anonymous> (...)` or `at <anonymous> (...)`.
9
+ * - SpiderMonkey (Firefox): `src/indicator/lowestOf@https://host/a.js line 2 > WebAssembly.instantiate:wasm-function[105]:0x1d5a`.
10
+ * - JavaScriptCore (Safari): `src/indicator/lowestOf@[wasm code]` or `<?>.wasm-function[105]@[wasm code]`: a name or
11
+ * an index, never an offset.
12
+ *
13
+ * `env.abort` builds its Error inside host code, so its stack starts with host frames: the leading host frames are
14
+ * skipped, the wasm frames that follow are collected, and the next host frame ends the list.
15
+ */
16
+ /** One wasm frame: each field only when the engine printed it. */
17
+ export interface WrunParsedTrapFrame {
18
+ index?: number;
19
+ name?: string;
20
+ offset?: number;
21
+ }
22
+ /** The deepest stack the trace replay asks for (raised before guest execution, never at the abort). */
23
+ export declare const WRUN_TRAP_STACK_LIMIT = 64;
24
+ /** The wasm frames of a stack, innermost first: leading host frames skipped, the first host frame after a wasm
25
+ * frame ends the list. Empty for a stack with none. */
26
+ export declare function parseWrunTrapFrames(stack: string | undefined): WrunParsedTrapFrame[];
27
+ /** The code section's payload start (a module byte offset), or -1 for bytes that are not a module or have none. */
28
+ export declare function wrunCodeSectionStart(bytes: Uint8Array): number;