@orangecharts/wrun-chart-host 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/README.md +1 -0
  2. package/dist/constants/feature-flags.constants.d.ts +9 -0
  3. package/dist/constants/feature-flags.constants.js +67 -4
  4. package/dist/constants/governed-exchanges.constants.d.ts +12 -0
  5. package/dist/constants/governed-exchanges.constants.js +16 -0
  6. package/dist/constants/option-venues.constants.d.ts +2 -2
  7. package/dist/host-env.d.ts +1 -9
  8. package/dist/host-ports.types.d.ts +36 -7
  9. package/dist/index.d.ts +6 -1
  10. package/dist/index.js +6 -1
  11. package/dist/interfaces/cancel-reason.interface.d.ts +1 -1
  12. package/dist/interfaces/cme-realtime.interface.d.ts +16 -9
  13. package/dist/interfaces/cme-realtime.interface.js +6 -3
  14. package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
  15. package/dist/interfaces/opra-realtime.interface.d.ts +1 -5
  16. package/dist/interfaces/prediction-market.interface.d.ts +7 -0
  17. package/dist/interfaces/stocks-realtime.interface.d.ts +57 -0
  18. package/dist/interfaces/stocks-realtime.interface.js +32 -0
  19. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +48 -117
  20. package/dist/kscript-data/controls/live-trades-merge.util.js +97 -207
  21. package/dist/market-data/billing.interface.d.ts +86 -12
  22. package/dist/market-data/billing.interface.js +23 -4
  23. package/dist/market-data/venue.d.ts +65 -2
  24. package/dist/market-data/venues/index.d.ts +135 -5
  25. package/dist/market-data/venues/index.js +2 -1
  26. package/dist/market-data/venues/opra.contract.copy.json +3 -2
  27. package/dist/market-data/venues/opra.d.ts +2 -2
  28. package/dist/market-data/venues/opra.js +5 -2
  29. package/dist/market-data/venues/stocks.contract.copy.json +64 -0
  30. package/dist/market-data/venues/stocks.d.ts +130 -0
  31. package/dist/market-data/venues/stocks.js +117 -0
  32. package/dist/settings-templates/footprint-rows.js +35 -2
  33. package/dist/settings-templates/form-rows.d.ts +2 -1
  34. package/dist/settings-templates/indicator-fields.js +34 -4
  35. package/dist/settings-templates/tool-rules.d.ts +12 -5
  36. package/dist/settings-templates/tool-rules.js +11 -5
  37. package/dist/settings-templates/tool-tables.generated.js +4 -0
  38. package/dist/utility/chart/cme-cache-context.util.d.ts +5 -3
  39. package/dist/utility/chart/cme-cache-context.util.js +10 -6
  40. package/dist/utility/chart/cme-realtime.util.js +10 -0
  41. package/dist/utility/chart/cme-user-scripts-gate.util.d.ts +83 -0
  42. package/dist/utility/chart/cme-user-scripts-gate.util.js +142 -0
  43. package/dist/utility/chart/effective-chart-session.util.d.ts +14 -0
  44. package/dist/utility/chart/effective-chart-session.util.js +39 -0
  45. package/dist/utility/chart/host-bar-placement.util.d.ts +28 -0
  46. package/dist/utility/chart/host-bar-placement.util.js +170 -30
  47. package/dist/utility/chart/index-host-tier.util.d.ts +3 -1
  48. package/dist/utility/chart/index-host-tier.util.js +7 -2
  49. package/dist/utility/chart/index-mode-admission.util.js +25 -11
  50. package/dist/utility/chart/kscript-apply-fingerprint.util.js +1 -1
  51. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +6 -9
  52. package/dist/utility/chart/kscript-live-coalesce.util.js +8 -9
  53. package/dist/utility/chart/kscript-live-source-identity.util.d.ts +9 -0
  54. package/dist/utility/chart/kscript-live-source-identity.util.js +10 -1
  55. package/dist/utility/chart/kscript-provenance-keys.util.js +7 -0
  56. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
  57. package/dist/utility/chart/kscript-venue-policy.util.d.ts +115 -21
  58. package/dist/utility/chart/kscript-venue-policy.util.js +194 -40
  59. package/dist/utility/chart/live-bucket.util.d.ts +24 -8
  60. package/dist/utility/chart/live-bucket.util.js +85 -27
  61. package/dist/utility/chart/marketKind.util.js +5 -0
  62. package/dist/utility/chart/mixed-mode.util.d.ts +7 -0
  63. package/dist/utility/chart/mixed-mode.util.js +14 -0
  64. package/dist/utility/chart/opra-user-scripts-gate.util.d.ts +11 -16
  65. package/dist/utility/chart/opra-user-scripts-gate.util.js +12 -28
  66. package/dist/utility/chart/rth-session.util.d.ts +9 -8
  67. package/dist/utility/chart/rth-session.util.js +23 -20
  68. package/dist/utility/chart/trading-day.util.d.ts +17 -0
  69. package/dist/utility/chart/trading-day.util.js +59 -0
  70. package/dist/utility/chart/window-owner.leaf.d.ts +23 -2
  71. package/dist/utility/chart/window-owner.leaf.js +45 -3
  72. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +33 -15
  73. package/dist/utility/chart/wrun-bar-session-facts.util.js +70 -20
  74. package/dist/utility/intl-locale.util.js +5 -0
  75. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
  76. package/dist/utility/v2/gate-plane.util.d.ts +12 -3
  77. package/dist/utility/v2/gate-plane.util.js +30 -4
  78. package/dist/utility/v2/gate-session-latch.util.js +1 -1
  79. package/dist/utility/v2/stocks-governed.util.d.ts +16 -0
  80. package/dist/utility/v2/stocks-governed.util.js +34 -0
  81. package/dist/utility/wrun/derived-roots.leaf.d.ts +13 -0
  82. package/dist/utility/wrun/derived-roots.leaf.js +27 -0
  83. package/dist/utility/wrun/derived-roots.util.d.ts +1 -9
  84. package/dist/utility/wrun/derived-roots.util.js +3 -23
  85. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +4 -3
  86. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +24 -3
  87. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +46 -10
  88. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +2 -0
  89. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +63 -16
  90. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +58 -14
  91. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +34 -11
  92. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +106 -30
  93. package/dist/utility/wrun/wrun-browser-sources.leaf.js +1 -2
  94. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +7 -4
  95. package/dist/utility/wrun/wrun-chart-market-facts.util.js +12 -8
  96. package/dist/utility/wrun/wrun-color-settings.util.d.ts +9 -0
  97. package/dist/utility/wrun/wrun-color-settings.util.js +33 -0
  98. package/dist/utility/wrun/wrun-handles.util.d.ts +7 -3
  99. package/dist/utility/wrun/wrun-handles.util.js +9 -8
  100. package/dist/utility/wrun/wrun-input-requirements.leaf.d.ts +68 -0
  101. package/dist/utility/wrun/wrun-input-requirements.leaf.js +163 -7
  102. package/dist/utility/wrun/wrun-leg-close.util.d.ts +59 -23
  103. package/dist/utility/wrun/wrun-leg-close.util.js +186 -28
  104. package/dist/utility/wrun/wrun-live-intake.util.d.ts +26 -12
  105. package/dist/utility/wrun/wrun-live-intake.util.js +219 -155
  106. package/dist/utility/wrun/wrun-live-tick.util.d.ts +9 -5
  107. package/dist/utility/wrun/wrun-live-tick.util.js +130 -94
  108. package/dist/utility/wrun/wrun-market-facts.util.d.ts +13 -3
  109. package/dist/utility/wrun/wrun-market-facts.util.js +13 -3
  110. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +20 -10
  111. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +10 -5
  112. package/dist/utility/wrun/wrun-option-book-rows.util.d.ts +56 -0
  113. package/dist/utility/wrun/wrun-option-book-rows.util.js +96 -0
  114. package/dist/utility/wrun/wrun-option-views.util.d.ts +281 -20
  115. package/dist/utility/wrun/wrun-option-views.util.js +391 -50
  116. package/dist/utility/wrun/wrun-options-chain.util.d.ts +3 -3
  117. package/dist/utility/wrun/wrun-options-chain.util.js +2 -0
  118. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +15 -2
  119. package/dist/utility/wrun/wrun-overlay-drivers.util.js +13 -3
  120. package/dist/utility/wrun/wrun-overlay-recovery.util.js +3 -1
  121. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +60 -11
  122. package/dist/utility/wrun/wrun-overlay-run.util.js +529 -113
  123. package/dist/utility/wrun/wrun-panel-mount.util.js +51 -6
  124. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +15 -2
  125. package/dist/utility/wrun/wrun-pin-spelling.util.js +27 -3
  126. package/dist/utility/wrun/wrun-refusal.util.d.ts +3 -2
  127. package/dist/utility/wrun/wrun-refusal.util.js +22 -0
  128. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +26 -0
  129. package/dist/utility/wrun/wrun-registry-errors.util.js +34 -0
  130. package/dist/utility/wrun/wrun-replay-lane.util.js +3 -2
  131. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +20 -6
  132. package/dist/utility/wrun/wrun-run-interval-session.util.js +22 -7
  133. package/dist/utility/wrun/wrun-run-interval.util.d.ts +39 -7
  134. package/dist/utility/wrun/wrun-run-interval.util.js +49 -9
  135. package/dist/utility/wrun/wrun-socket-row-source.js +7 -2
  136. package/dist/utility/wrun/wrun-source-rows.util.d.ts +29 -22
  137. package/dist/utility/wrun/wrun-source-rows.util.js +62 -41
  138. package/dist/utility/wrun/wrun-tape-per-order.util.js +1 -20
  139. package/dist/utility/wrun/wrun-tape-source.util.d.ts +17 -9
  140. package/dist/utility/wrun/wrun-tape-source.util.js +20 -12
  141. package/dist/workers/constants/socket-slots.d.ts +91 -6
  142. package/dist/workers/constants/socket-slots.js +85 -6
  143. package/package.json +11 -11
  144. package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +0 -56
  145. package/dist/kscript-data/controls/live-trades-order-gate.util.js +0 -107
@@ -18,6 +18,7 @@
18
18
  import { getExchangeFromSymbol } from '../../helpers/data.helpers.js';
19
19
  import { extractTokensFromTransformations } from '../common/transformations.util.js';
20
20
  import { checkIsIndexMode, checkIsPolygon } from './index-mode.util.js';
21
+ import { chartIntervalToMs, hasRthWindow, isChartRthActive } from './rth-session.util.js';
21
22
  // ============================================================================
22
23
  // CONSTANTS
23
24
  // ============================================================================
@@ -50,6 +51,13 @@ export const INDEX_FETCH_EXTRA_BAR = 1;
50
51
  * - Mixed timestamp-first: Main token is crypto, others include stocks (BTC + NVDA)
51
52
  * - Mixed index-first: Main token is stock, others include crypto (NVDA + BTC)
52
53
  *
54
+ * **Per-token sessions** (`tokenSessionTypes`, the worker resolves each leg's `tradingHour` from its entry, else the
55
+ * chart's `sessionType`): a Polygon leg rides the chart's session (regular unless extended); a leg with an RTH window
56
+ * that is not the chart's own market takes the comparison-leg rule (chart-rth.util `kOhlcvSessionPayloadFields`):
57
+ * 'regular' only while the CHART is RTH-active (`isChartRthActive` at the chart interval), else 'extended'. A crypto or
58
+ * equities chart stamps a meaningless 'regular' it has no control to change, which must never filter a CME leg of its
59
+ * formula to the cash session; the chart's own market reads the chart's session as before.
60
+ *
53
61
  * @param metadata - Chart metadata containing transformations and session settings
54
62
  * @param transformations - Expression string (e.g., "BINANCE|BTCUSDT + POLYGON|NVDA")
55
63
  * @returns Context object with token modes, session types, and mixed-mode flags
@@ -58,6 +66,7 @@ export function buildMixedModeContext(metadata, transformations) {
58
66
  const tokens = extractTokensFromTransformations(transformations);
59
67
  const tokenSessionTypes = {};
60
68
  const tokenExchanges = {};
69
+ let chartRthActive;
61
70
  const tokenModes = tokens.map((token) => {
62
71
  const resolvedExchange = getExchangeFromSymbol(token.exchange ?? '', token.symbol ?? '');
63
72
  const isIndex = checkIsIndexMode(resolvedExchange);
@@ -67,6 +76,11 @@ export function buildMixedModeContext(metadata, transformations) {
67
76
  const resolvedSessionType = metadata.sessionType ?? 'regular';
68
77
  tokenSessionTypes[token.token] = resolvedSessionType;
69
78
  }
79
+ else if (hasRthWindow(token.symbol, resolvedExchange) &&
80
+ !(resolvedExchange === metadata?.exchange && token.symbol === metadata?.symbol)) {
81
+ chartRthActive ??= isChartRthActive(metadata?.exchange, metadata?.symbol, metadata?.sessionType, chartIntervalToMs(metadata?.interval));
82
+ tokenSessionTypes[token.token] = chartRthActive ? 'regular' : 'extended';
83
+ }
70
84
  return {
71
85
  tokenKey: token.token,
72
86
  isIndex,
@@ -1,19 +1,14 @@
1
1
  /**
2
- * The `opra-user-scripts` runtime flag as the venue policy reads it (kscript-venue-policy.util, the one decider of
3
- * the governed walls). Dependency-free on purpose, the shape of exchange-visibility.util and telemetryGates: the
4
- * venue policy stays worker-safe and store-free, so the feature-flags store hands it readers instead.
5
- *
6
- * Two readers, one answer: the store registers its override-aware `isOn` as the fallback when it is created, and
7
- * publishes its reader again after every successful fetch. Until a fetch publishes, the fallback answers, so the dev
8
- * and internal `kiyo.flag-overrides` lens reaches the walls before the map lands and through a failed fetch, exactly
9
- * as it reaches `opraUserScriptsEnabled` (opra-options-gate.util) and the editor's Run wall: the walls and the
10
- * surfaces never disagree, and a restore that skipped the hydration wait on an override judges by that override. In
11
- * any context neither reached (a worker, a guest-less spec), the gate reads closed: fail dark, today's wall.
2
+ * The `opra-user-scripts` gate as the venue policy reads it (kscript-venue-policy.util, the one decider of the
3
+ * governed walls). LAUNCHED 2026-10-27 (Kyle: ship it directly): the OPRA licence covers user-authored scripting,
4
+ * so the gate answers open on every build, in every context (the main thread, a worker, a spec). The runtime flag
5
+ * record `opra-user-scripts` is retired: the feature-flags store still calls the two setters below after it is
6
+ * created and after every fetch, and they keep nothing, so a flipped record changes nothing. Rollback is a revert of
7
+ * this file and opra-options-gate.util, picked to production.
12
8
  */
13
- /** Called by the feature-flags store after a successful fetch (and by tests); null unpublishes. */
14
- export declare function publishOpraUserScriptsFlag(next: (() => boolean) | null): void;
15
- /** Called by the feature-flags store when it is created: its override-aware `isOn`, read until a fetch publishes. */
16
- export declare function setOpraUserScriptsFlagFallback(next: (() => boolean) | null): void;
17
- /** Whether the `opra-user-scripts` flag is on for this session: the published answer, else the store's own; closed
18
- * when neither can tell. */
9
+ /** Retired: the feature-flags store's publish after a fetch; the gate keeps no reader. */
10
+ export declare function publishOpraUserScriptsFlag(_next: (() => boolean) | null): void;
11
+ /** Retired: the feature-flags store's override-aware fallback; the gate keeps no reader. */
12
+ export declare function setOpraUserScriptsFlagFallback(_next: (() => boolean) | null): void;
13
+ /** Whether a user run may read the OPRA plane at the viewer's tier: always, since the launch. */
19
14
  export declare function isOpraUserScriptsFlagOn(): boolean;
@@ -1,32 +1,16 @@
1
1
  /**
2
- * The `opra-user-scripts` runtime flag as the venue policy reads it (kscript-venue-policy.util, the one decider of
3
- * the governed walls). Dependency-free on purpose, the shape of exchange-visibility.util and telemetryGates: the
4
- * venue policy stays worker-safe and store-free, so the feature-flags store hands it readers instead.
5
- *
6
- * Two readers, one answer: the store registers its override-aware `isOn` as the fallback when it is created, and
7
- * publishes its reader again after every successful fetch. Until a fetch publishes, the fallback answers, so the dev
8
- * and internal `kiyo.flag-overrides` lens reaches the walls before the map lands and through a failed fetch, exactly
9
- * as it reaches `opraUserScriptsEnabled` (opra-options-gate.util) and the editor's Run wall: the walls and the
10
- * surfaces never disagree, and a restore that skipped the hydration wait on an override judges by that override. In
11
- * any context neither reached (a worker, a guest-less spec), the gate reads closed: fail dark, today's wall.
2
+ * The `opra-user-scripts` gate as the venue policy reads it (kscript-venue-policy.util, the one decider of the
3
+ * governed walls). LAUNCHED 2026-10-27 (Kyle: ship it directly): the OPRA licence covers user-authored scripting,
4
+ * so the gate answers open on every build, in every context (the main thread, a worker, a spec). The runtime flag
5
+ * record `opra-user-scripts` is retired: the feature-flags store still calls the two setters below after it is
6
+ * created and after every fetch, and they keep nothing, so a flipped record changes nothing. Rollback is a revert of
7
+ * this file and opra-options-gate.util, picked to production.
12
8
  */
13
- let published = null;
14
- let fallback = null;
15
- /** Called by the feature-flags store after a successful fetch (and by tests); null unpublishes. */
16
- export function publishOpraUserScriptsFlag(next) {
17
- published = next;
18
- }
19
- /** Called by the feature-flags store when it is created: its override-aware `isOn`, read until a fetch publishes. */
20
- export function setOpraUserScriptsFlagFallback(next) {
21
- fallback = next;
22
- }
23
- /** Whether the `opra-user-scripts` flag is on for this session: the published answer, else the store's own; closed
24
- * when neither can tell. */
9
+ /** Retired: the feature-flags store's publish after a fetch; the gate keeps no reader. */
10
+ export function publishOpraUserScriptsFlag(_next) { }
11
+ /** Retired: the feature-flags store's override-aware fallback; the gate keeps no reader. */
12
+ export function setOpraUserScriptsFlagFallback(_next) { }
13
+ /** Whether a user run may read the OPRA plane at the viewer's tier: always, since the launch. */
25
14
  export function isOpraUserScriptsFlagOn() {
26
- try {
27
- return (published ?? fallback)?.() === true;
28
- }
29
- catch {
30
- return false;
31
- }
15
+ return true;
32
16
  }
@@ -28,14 +28,15 @@ export declare function futuresRootOf(symbol: unknown): string | null;
28
28
  */
29
29
  export declare function getRthWindowForSymbol(symbol: unknown): Readonly<RthWindow> | null;
30
30
  /**
31
- * The RTH window the kScript engine's venue-sessions table gives a symbol:
32
- * the platform window for every mapped root, NYMEX included (engine 3.0.94).
33
- * Script-facing session facts read this one (wrun `time.session`,
34
- * wrun-bar-session-facts.util), so a browser run of an indicator agrees with
35
- * its cloud run and with the engine's `inSession` / `vwap(session="rth")`;
36
- * every chart gate reads `getRthWindowForSymbol`. It moves to the exchange
37
- * windows only in a coordinated change of the engine, the WRUN-SESSIONS C3
38
- * golden and the cloud lanes. Null for an unmapped root.
31
+ * The RTH window the script-facing session facts read for a symbol (wrun
32
+ * `time.session`, wrun-bar-session-facts.util): the root's own window, the one
33
+ * every chart gate reads (`getRthWindowForSymbol`: 09:00 to 14:30 New York on
34
+ * the NYMEX energy roots, 09:30 to 16:15 on every other mapped root), so an
35
+ * indicator's session reads the bars the chart's RTH mode keeps. The shared
36
+ * host's venue layer (om session-facts-venues.ts) reads the same windows and
37
+ * the WRUN-SESSIONS C3 golden pins them, so the browser and cloud runs agree.
38
+ * The kScript engine's uniform table (the platform window on every root) is
39
+ * being retired and binds nothing. Null for an unmapped root.
39
40
  */
40
41
  export declare function engineRthWindowForSymbol(symbol: unknown): Readonly<RthWindow> | null;
41
42
  export declare const SESSION_HOURS_ETH: "eth";
@@ -18,19 +18,21 @@
18
18
  * rows through `isWithinRthWindow`, the live-feed service gates merges).
19
19
  *
20
20
  * The ROOT SET mirrors the engine's venue-sessions module
21
- * (`@orangecharts/kscript` `dist/kscript/venue-sessions.d.ts`): when a root
22
- * is added there, add it here in the same wave (and vice versa). The
23
- * published package ships ONLY the .d.ts for that subpath (the implementation
24
- * is bundled and mangled inside `dist/kscript-engine.js` and not re-exported
21
+ * (`@orangecharts/kscript` `dist/kscript/venue-sessions.d.ts`) and the shared
22
+ * host's venue layer (om `packages/sdk/src/wrun-host/session-facts-venues.ts`
23
+ * `RTH_ROOT_EXCHANGES`, the same root to listing-exchange table): when a root
24
+ * is added to one, add it to the others in the same wave. The published
25
+ * engine package ships ONLY the .d.ts for that subpath (the implementation is
26
+ * bundled and mangled inside `dist/kscript-engine.js` and not re-exported
25
27
  * from the main entry), so the runtime import cannot resolve; `futuresRootOf`
26
28
  * below is a verbatim mirror of the engine source. The WINDOWS follow the
27
- * wire, not the engine: the engine table (3.0.94) still gives the NYMEX
28
- * energy roots the uniform 09:30-16:15 window, so `inSession(session="rth")`
29
- * and `vwap(session="rth")` on those roots disagree with the chart until the
30
- * engine adopts the energy window; the wrun session facts stay on the
31
- * engine's table through `engineRthWindowForSymbol` so browser and cloud runs
32
- * agree. Swap these exports for re-exports of the engine subpath once a
33
- * release emits the module as importable JS and carries the same windows.
29
+ * wire, not the engine: the engine table (3.0.94) gives the NYMEX energy
30
+ * roots the uniform 09:30-16:15 window, and that table is being retired, so it
31
+ * binds nothing here. Every reader takes the root's own window from this
32
+ * table: the chart's gates (`getRthWindowForSymbol`) and the script-facing
33
+ * session facts (`engineRthWindowForSymbol`, wrun `time.session`), the energy
34
+ * pit session on NYMEX included, and the shared host's venue layer reads the
35
+ * same windows, so a browser run and a cloud run of one indicator agree.
34
36
  */
35
37
  import dayjs from 'dayjs';
36
38
  import timezone from 'dayjs/plugin/timezone.js';
@@ -190,17 +192,18 @@ export function getRthWindowForSymbol(symbol) {
190
192
  return root ? (RTH_WINDOW_BY_ROOT.get(root) ?? null) : null;
191
193
  }
192
194
  /**
193
- * The RTH window the kScript engine's venue-sessions table gives a symbol:
194
- * the platform window for every mapped root, NYMEX included (engine 3.0.94).
195
- * Script-facing session facts read this one (wrun `time.session`,
196
- * wrun-bar-session-facts.util), so a browser run of an indicator agrees with
197
- * its cloud run and with the engine's `inSession` / `vwap(session="rth")`;
198
- * every chart gate reads `getRthWindowForSymbol`. It moves to the exchange
199
- * windows only in a coordinated change of the engine, the WRUN-SESSIONS C3
200
- * golden and the cloud lanes. Null for an unmapped root.
195
+ * The RTH window the script-facing session facts read for a symbol (wrun
196
+ * `time.session`, wrun-bar-session-facts.util): the root's own window, the one
197
+ * every chart gate reads (`getRthWindowForSymbol`: 09:00 to 14:30 New York on
198
+ * the NYMEX energy roots, 09:30 to 16:15 on every other mapped root), so an
199
+ * indicator's session reads the bars the chart's RTH mode keeps. The shared
200
+ * host's venue layer (om session-facts-venues.ts) reads the same windows and
201
+ * the WRUN-SESSIONS C3 golden pins them, so the browser and cloud runs agree.
202
+ * The kScript engine's uniform table (the platform window on every root) is
203
+ * being retired and binds nothing. Null for an unmapped root.
201
204
  */
202
205
  export function engineRthWindowForSymbol(symbol) {
203
- return getRthWindowForSymbol(symbol) === null ? null : CME_PLATFORM_RTH;
206
+ return getRthWindowForSymbol(symbol);
204
207
  }
205
208
  /** Root of a `<ROOT>1!` continuous symbol, mirroring the engine's fallback. */
206
209
  function continuousRthRootOf(symbol) {
@@ -61,6 +61,23 @@ export type TradingDayPeriod = 'Session' | 'Week' | 'Month' | 'Year';
61
61
  * at the reopen print, with no venue holiday knowledge needed.
62
62
  */
63
63
  export declare function getTradingDayPeriodStartSec(timestampSec: number, period: TradingDayPeriod, anchor: TradingDayAnchor): number;
64
+ /** The calendar units a session period can run on trading dates. */
65
+ export type TradingPeriodUnit = 'week' | 'month';
66
+ /**
67
+ * The open (ms) of the `count`-unit calendar period holding the TRADING date
68
+ * of `tsMs`: weeks on the ISO Monday lattice, months from January 1970 (so 3
69
+ * is the calendar quarter and 12 the year), grouped as titan groups them
70
+ * (utils/tradingDay.ts calendarGroupIndex), opening with the trading day
71
+ * labeled by the period's first calendar date (Sunday 17:00 America/Chicago
72
+ * for a CME Monday). Titan's `tradingPeriodStartMs`, the grid a session
73
+ * profile folds its weekly and monthly cells on under `calendarPeriodAnchor:
74
+ * 'tradingDay'` (src/renderers/profile/sessionGrid.ts); the fetch-head decider
75
+ * and the history trim mirror it here. `getTradingDayPeriodStartSec` is the
76
+ * same rule for one week, one month and one year, in seconds.
77
+ */
78
+ export declare function tradingPeriodStartMs(tsMs: number, anchor: TradingDayAnchor, unit: TradingPeriodUnit, count: number): number;
79
+ /** The first period open strictly after `tsMs` (the end of the period holding it). */
80
+ export declare function nextTradingPeriodStartMs(tsMs: number, anchor: TradingDayAnchor, unit: TradingPeriodUnit, count: number): number;
64
81
  /**
65
82
  * The TPO custom-time-range projection of an anchor, or undefined when the
66
83
  * anchor is absent, invalid, or has no wire-expressible projection. The CME
@@ -289,6 +289,65 @@ export function getTradingDayPeriodStartSec(timestampSec, period, anchor) {
289
289
  const openDate = anchor.openMinutes >= 720 ? shiftCalendarDate(firstTradeDate, -1) : firstTradeDate;
290
290
  return wallInstantMs(anchor.timeZone, openDate, anchor.openMinutes) / 1000;
291
291
  }
292
+ /** 1970-01-01 (date index 0) is a Thursday: the Monday before it is index -3 (titan's lattice). */
293
+ const MONDAY_EPOCH_OFFSET_DAYS = 3;
294
+ const PERIOD_DAY_MS = 86_400_000;
295
+ function dateIndexOf(date) {
296
+ return Math.round(Date.UTC(date.y, date.m - 1, date.d) / PERIOD_DAY_MS);
297
+ }
298
+ function calendarDateOfIndex(index) {
299
+ const date = new Date(index * PERIOD_DAY_MS);
300
+ return { y: date.getUTCFullYear(), m: date.getUTCMonth() + 1, d: date.getUTCDate() };
301
+ }
302
+ /** titan's calendarGroupIndex for weeks (ISO weeks from Monday 1969-12-29) and months (from January 1970). */
303
+ function calendarGroupIndexOf(dateIndex, unit, count) {
304
+ const n = count >= 1 ? Math.floor(count) : 1;
305
+ if (unit === 'month') {
306
+ const date = new Date(dateIndex * PERIOD_DAY_MS);
307
+ return Math.floor(((date.getUTCFullYear() - 1970) * 12 + date.getUTCMonth()) / n);
308
+ }
309
+ return Math.floor(Math.floor((dateIndex + MONDAY_EPOCH_OFFSET_DAYS) / 7) / n);
310
+ }
311
+ /** titan's calendarGroupFirstDateIndex: the first date index of a calendar group. */
312
+ function calendarGroupFirstDateIndexOf(groupIndex, unit, count) {
313
+ const n = count >= 1 ? Math.floor(count) : 1;
314
+ if (unit === 'month') {
315
+ const monthIndex = groupIndex * n;
316
+ const year = 1970 + Math.floor(monthIndex / 12);
317
+ return Math.round(Date.UTC(year, monthIndex - (year - 1970) * 12, 1) / PERIOD_DAY_MS);
318
+ }
319
+ return groupIndex * n * 7 - MONDAY_EPOCH_OFFSET_DAYS;
320
+ }
321
+ /** The open (ms) of the trading day labeled by `date`: evening opens label the next date, so they open the day before. */
322
+ function tradingDateOpenMs(date, anchor) {
323
+ const openDate = anchor.openMinutes >= 720 ? shiftCalendarDate(date, -1) : date;
324
+ return wallInstantMs(anchor.timeZone, openDate, anchor.openMinutes);
325
+ }
326
+ /**
327
+ * The open (ms) of the `count`-unit calendar period holding the TRADING date
328
+ * of `tsMs`: weeks on the ISO Monday lattice, months from January 1970 (so 3
329
+ * is the calendar quarter and 12 the year), grouped as titan groups them
330
+ * (utils/tradingDay.ts calendarGroupIndex), opening with the trading day
331
+ * labeled by the period's first calendar date (Sunday 17:00 America/Chicago
332
+ * for a CME Monday). Titan's `tradingPeriodStartMs`, the grid a session
333
+ * profile folds its weekly and monthly cells on under `calendarPeriodAnchor:
334
+ * 'tradingDay'` (src/renderers/profile/sessionGrid.ts); the fetch-head decider
335
+ * and the history trim mirror it here. `getTradingDayPeriodStartSec` is the
336
+ * same rule for one week, one month and one year, in seconds.
337
+ */
338
+ export function tradingPeriodStartMs(tsMs, anchor, unit, count) {
339
+ if (!Number.isFinite(tsMs))
340
+ return Number.NaN;
341
+ const group = calendarGroupIndexOf(dateIndexOf(tradingDateOf(tsMs, anchor)), unit, count);
342
+ return tradingDateOpenMs(calendarDateOfIndex(calendarGroupFirstDateIndexOf(group, unit, count)), anchor);
343
+ }
344
+ /** The first period open strictly after `tsMs` (the end of the period holding it). */
345
+ export function nextTradingPeriodStartMs(tsMs, anchor, unit, count) {
346
+ if (!Number.isFinite(tsMs))
347
+ return Number.NaN;
348
+ const group = calendarGroupIndexOf(dateIndexOf(tradingDateOf(tsMs, anchor)), unit, count) + 1;
349
+ return tradingDateOpenMs(calendarDateOfIndex(calendarGroupFirstDateIndexOf(group, unit, count)), anchor);
350
+ }
292
351
  /**
293
352
  * The TPO custom-time-range projection of an anchor, or undefined when the
294
353
  * anchor is absent, invalid, or has no wire-expressible projection. The CME
@@ -10,12 +10,33 @@ export declare const WRUN_WINDOW_SETTING = "wrunWindow";
10
10
  * the flag is.
11
11
  */
12
12
  export declare const WRUN_WINDOW_SPLIT_SETTING = "wrunWindowSplit";
13
- /** An overlay as the window rules read it: its id and its settings bag. */
13
+ /**
14
+ * The built-in Indicators that own a window the way a wrun Indicator does, by indicator type: the nine of the Options
15
+ * panel (NATIVE-WINDOW, 2026-10-28). Another built-in joins by adding its type here; every seam reads this one list.
16
+ */
17
+ export declare const WINDOW_NATIVE_OWNER_TYPES: ReadonlySet<string>;
18
+ /**
19
+ * An overlay as the window rules read it: its id, its type and its settings bag. A workspace row names its Indicator
20
+ * by `type` (its settings hold no `ovType`: an identity key no row keeps); an engine meta by `settings.ovType` (its
21
+ * `type` is the side).
22
+ */
14
23
  export type WindowOwnerOverlay = {
15
24
  id?: unknown;
25
+ type?: unknown;
16
26
  settings?: Record<string, unknown> | null;
17
27
  } | null | undefined;
18
- /** A wrun Indicator overlay (registry, draft or hosted lane) that carries the owner flag. */
28
+ /** The type of a built-in of WINDOW_NATIVE_OWNER_TYPES: a row's `type`, else an engine meta's `settings.ovType`. */
29
+ export declare function windowNativeTypeOf(overlay: WindowOwnerOverlay): string | undefined;
30
+ /** Whether an overlay is a built-in that can own a window (WINDOW_NATIVE_OWNER_TYPES). */
31
+ export declare function isWindowNativeOverlay(overlay: WindowOwnerOverlay): boolean;
32
+ /**
33
+ * Whether a document row can own a window, flagged or not: a saved wrun Indicator (registry or hosted: an editor
34
+ * draft has no row, draft-window.util) or a built-in of WINDOW_NATIVE_OWNER_TYPES. The doors that offer or open a
35
+ * window and the flag writer read it.
36
+ */
37
+ export declare function canOwnWindow(overlay: WindowOwnerOverlay): boolean;
38
+ /** A wrun Indicator overlay (registry, draft or hosted lane) or a built-in of WINDOW_NATIVE_OWNER_TYPES that carries
39
+ * the owner flag. */
19
40
  export declare function isWrunWindowOwner(overlay: WindowOwnerOverlay): boolean;
20
41
  /**
21
42
  * An engine meta as the window's pane mark reads it. The window geometry (window-geometry.leaf, C5) hides an owner's
@@ -3,8 +3,12 @@
3
3
  * window contract) as a leaf with no app import: the owner flag's settings key, the saved split's settings key and
4
4
  * the owner test. The child mount (wrun-panel-mount.util) and the window geometry leaf read them, and they move into
5
5
  * the wrun chart-host package, which the cell readers' reactive draft windows (draft-window.util) may not reach.
6
+ *
7
+ * Two kinds of Indicator can own a window: a wrun Indicator (the feature's name: the flag key stays `wrunWindow`), and
8
+ * a built-in of WINDOW_NATIVE_OWNER_TYPES. Every window seam (the owner test, the doors, the flag writer, the content
9
+ * and name reads) asks this rule, never wrun identity alone.
6
10
  */
7
- import { isWrunPackageOverlaySettings } from '../wrun/wrun-overlay-identity.util.js';
11
+ import { isWrunPackageOverlaySettings, isWrunSavedPackageOverlaySettings } from '../wrun/wrun-overlay-identity.util.js';
8
12
  /** The owner flag's settings key (persisted: `settingsToSave`, indicator.constants). */
9
13
  export const WRUN_WINDOW_SETTING = 'wrunWindow';
10
14
  /**
@@ -17,10 +21,48 @@ export const WRUN_WINDOW_SETTING = 'wrunWindow';
17
21
  * the flag is.
18
22
  */
19
23
  export const WRUN_WINDOW_SPLIT_SETTING = 'wrunWindowSplit';
20
- /** A wrun Indicator overlay (registry, draft or hosted lane) that carries the owner flag. */
24
+ /**
25
+ * The built-in Indicators that own a window the way a wrun Indicator does, by indicator type: the nine of the Options
26
+ * panel (NATIVE-WINDOW, 2026-10-28). Another built-in joins by adding its type here; every seam reads this one list.
27
+ */
28
+ export const WINDOW_NATIVE_OWNER_TYPES = new Set([
29
+ 'OPTIONS_GEX',
30
+ 'OPTIONS_HEATMAP',
31
+ 'OPTIONS_FLOW',
32
+ 'OPTIONS_GEX_CURVE',
33
+ 'OPTIONS_FLOW_PULSE',
34
+ 'OPTIONS_FLOW_EXPIRY',
35
+ 'BINANCE_PUT_CALL_RATIO',
36
+ 'IMPLIED_VOLATILITY_TICKER',
37
+ 'VOLATILITY_INDEX',
38
+ ]);
39
+ /** The type of a built-in of WINDOW_NATIVE_OWNER_TYPES: a row's `type`, else an engine meta's `settings.ovType`. */
40
+ export function windowNativeTypeOf(overlay) {
41
+ for (const type of [overlay?.type, overlay?.settings?.ovType]) {
42
+ if (typeof type === 'string' && WINDOW_NATIVE_OWNER_TYPES.has(type))
43
+ return type;
44
+ }
45
+ return undefined;
46
+ }
47
+ /** Whether an overlay is a built-in that can own a window (WINDOW_NATIVE_OWNER_TYPES). */
48
+ export function isWindowNativeOverlay(overlay) {
49
+ return windowNativeTypeOf(overlay) !== undefined;
50
+ }
51
+ /**
52
+ * Whether a document row can own a window, flagged or not: a saved wrun Indicator (registry or hosted: an editor
53
+ * draft has no row, draft-window.util) or a built-in of WINDOW_NATIVE_OWNER_TYPES. The doors that offer or open a
54
+ * window and the flag writer read it.
55
+ */
56
+ export function canOwnWindow(overlay) {
57
+ return isWrunSavedPackageOverlaySettings(overlay?.settings) || isWindowNativeOverlay(overlay);
58
+ }
59
+ /** A wrun Indicator overlay (registry, draft or hosted lane) or a built-in of WINDOW_NATIVE_OWNER_TYPES that carries
60
+ * the owner flag. */
21
61
  export function isWrunWindowOwner(overlay) {
22
62
  const settings = overlay?.settings;
23
- return !!settings && settings[WRUN_WINDOW_SETTING] === true && isWrunPackageOverlaySettings(settings);
63
+ return (!!settings &&
64
+ settings[WRUN_WINDOW_SETTING] === true &&
65
+ (isWrunPackageOverlaySettings(settings) || isWindowNativeOverlay(overlay)));
24
66
  }
25
67
  /** Whether a meta's pane is hidden by its window (above) and not by the reader: a gate that holds a collapsed pane's
26
68
  * runs lets this owner run, since its runs feed the window's tables (wrun-overlay-recovery.util). */
@@ -3,8 +3,7 @@
3
3
  * C3): `time.trade_date` and `time.session`. Both are facts of the bar's
4
4
  * market (exchange, symbol), its interval and its open time ONLY, never of
5
5
  * the chart's RTH / extended mode, and every hour comes from the chart's own
6
- * session definitions, the RTH window from the kScript engine's table (see
7
- * NYMEX below).
6
+ * session definitions, the RTH window the root's own (see NYMEX below).
8
7
  *
9
8
  * Calendar bars (an interval of one day or longer: 1D, 3D, 1W, 1M) read the
10
9
  * UTC date of their open stamp and 1 on every market: the chart stamps them
@@ -16,27 +15,44 @@
16
15
  * alias): the chart's CME trade date, `cmeSessionBucketMs(t, 1d)`, so the
17
16
  * 17:00 Chicago open belongs to the NEXT date;
18
17
  * - US equities (`getMarketKind` 'tradfi'): the New York calendar date;
19
- * - everything else (crypto, forex, HIP-3, Polymarket, ...): the UTC date.
18
+ * - forex (`getMarketKind` 'forex': FX_OTC, POLYGON_FX): the New York
19
+ * trade date, which opens at 17:00 New York (the forex day runs 17:00 to
20
+ * 17:00 New York, 21:00Z in summer and 22:00Z in winter), so a bar from
21
+ * 17:00 New York on belongs to the NEXT date and Sunday 17:00 New York
22
+ * opens Monday's; the same minute `market.session_open()` fills
23
+ * (WRUN_MARKET_SESSION_OPEN_FOREX);
24
+ * - everything else (crypto, HIP-3, Polymarket, ...): the UTC date.
20
25
  * - session, 1 regular, 2 pre-market, 3 after-hours, 0 closed:
21
26
  * - US equities: `resolveUsEquitySessionPhase`;
22
27
  * - CME family: 0 while the weekly schedule says closed
23
28
  * (`getGovernedFuturesScheduleStatusForSymbol`, which carries the 24/7
24
- * roots); else 1 inside the engine's RTH window
25
- * (`engineRthWindowForSymbol`, 09:30 to 16:15 New York on every mapped
26
- * root; a root without a window is regular all session), 2 before its
27
- * trade date's RTH window and 3 after it;
28
- * - everything else: 1.
29
+ * roots); else 1 inside the root's RTH window
30
+ * (`engineRthWindowForSymbol`, the chart's own: 09:30 to 16:15 New York,
31
+ * 09:00 to 14:30 on the NYMEX energy roots; a root without a window is
32
+ * regular all session), 2 before its trade date's RTH window and 3 after
33
+ * it;
34
+ * - forex and everything else: 1 (forex has no phases; its closed hours
35
+ * print no bars).
36
+ *
37
+ * The chart's own trading-day anchor (trading-day.util `getTradingDayAnchor`,
38
+ * the gate TPO, VWAP, the session dividers and the previous close read) does
39
+ * not carry the forex day yet: like US equities, forex keeps the display day
40
+ * there until that gate gains a New York 17:00 anchor in its own change, so
41
+ * a forex Indicator's trade date rolls at 17:00 New York while the chart's
42
+ * native dividers still roll at midnight.
29
43
  *
30
44
  * The golden vectors every other host (kscript-alerts, kscript-backend, om)
31
45
  * tests against are generated from this module:
32
46
  * src/fixtures/wrun-session-facts/golden.json.
33
47
  *
34
- * NYMEX: the chart judges RTH there on the energy pit session, 09:00 to 14:30
35
- * New York (rth-session.util `rthWindowForExchange`, the gateway's REGULAR
36
- * window), but wrun and kScript session facts on NYMEX follow the kScript
37
- * engine's table, 09:30 to 16:15, until a coordinated change moves the
38
- * engine, the golden and the cloud lanes together. Moving this browser lane
39
- * alone would split the browser and cloud runs of the same indicator.
48
+ * NYMEX: the facts follow the energy pit session, 09:00 to 14:30 New York, the
49
+ * window the chart judges RTH on there (rth-session.util
50
+ * `rthWindowForExchange`, the gateway's REGULAR window), so an indicator's
51
+ * `time.session` reads regular on exactly the bars an RTH chart keeps. The
52
+ * shared host's venue layer (om session-facts-venues.ts) reads the same
53
+ * windows and the golden pins them, so the browser and cloud runs of one
54
+ * indicator agree; the kScript engine's uniform 09:30 to 16:15 table is being
55
+ * retired and binds nothing.
40
56
  *
41
57
  * Cost: the definitions run at microseconds a call (the equities phase reads
42
58
  * dayjs timezone parts, about 30 us), so a 50k-bar run cannot afford one per
@@ -48,6 +64,8 @@
48
64
  * Chicago hours (16:00 and 17:00, the Saturday 02:00 to 04:00 window);
49
65
  * - the equities phase per New York (weekday, half hour): its boundaries are
50
66
  * 04:00, 09:30, 16:00 and 20:00;
67
+ * - the forex trade date per New York (date, hour): its one boundary is the
68
+ * whole hour 17:00;
51
69
  * - the CME RTH window per (window, trade date).
52
70
  * Both zones sit a whole number of hours off UTC, so a reader also keeps its
53
71
  * last answer per UTC hour (CME: the trade date and the schedule bit) or half
@@ -88,7 +106,7 @@ export interface WrunBarVenue {
88
106
  barGrid?: LiveBucketVenue;
89
107
  }
90
108
  /** Which C3 rule a market follows. */
91
- export type WrunBarFactsMarket = 'cme' | 'us_equities' | 'utc';
109
+ export type WrunBarFactsMarket = 'cme' | 'us_equities' | 'forex' | 'utc';
92
110
  export declare function wrunBarFactsMarketOf(exchange: string): WrunBarFactsMarket;
93
111
  /**
94
112
  * The venue of chart metadata (or a live context's market) at the series'