@orangecharts/wrun-chart-host 0.6.0 → 0.7.1

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 (142) hide show
  1. package/README.md +14 -5
  2. package/dist/constants/marketCapabilities.constants.d.ts +5 -0
  3. package/dist/constants/marketCapabilities.constants.js +16 -0
  4. package/dist/host-ports.types.d.ts +35 -3
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +11 -1
  7. package/dist/indicators/controls/tpo-session.util.js +42 -18
  8. package/dist/market-data/billing.interface.d.ts +2 -1
  9. package/dist/settings-templates/index.d.ts +2 -0
  10. package/dist/settings-templates/index.js +19 -5
  11. package/dist/settings-templates/indicator-fields.d.ts +2 -0
  12. package/dist/settings-templates/indicator-fields.js +10 -0
  13. package/dist/settings-templates/tool-rules.d.ts +12 -2
  14. package/dist/settings-templates/tool-rules.js +9 -2
  15. package/dist/settings-templates/tool-tables.generated.js +9 -0
  16. package/dist/utility/chart/crypto-index.leaf.d.ts +16 -0
  17. package/dist/utility/chart/crypto-index.leaf.js +19 -0
  18. package/dist/utility/chart/index-mode-admission.util.js +9 -1
  19. package/dist/utility/chart/index-mode.util.d.ts +11 -5
  20. package/dist/utility/chart/index-mode.util.js +22 -10
  21. package/dist/utility/chart/kscript-source-answer-budget.leaf.d.ts +36 -0
  22. package/dist/utility/chart/kscript-source-answer-budget.leaf.js +39 -0
  23. package/dist/utility/chart/kscript-source-degrade.leaf.d.ts +38 -1
  24. package/dist/utility/chart/kscript-source-degrade.leaf.js +39 -1
  25. package/dist/utility/chart/live-bucket.util.d.ts +2 -1
  26. package/dist/utility/chart/live-bucket.util.js +47 -15
  27. package/dist/utility/chart/local-kscript-warmup-depth.util.d.ts +15 -1
  28. package/dist/utility/chart/local-kscript-warmup-depth.util.js +9 -0
  29. package/dist/utility/chart/market-session-schedule.util.d.ts +3 -1
  30. package/dist/utility/chart/market-session-schedule.util.js +24 -2
  31. package/dist/utility/chart/marketKind.util.d.ts +12 -7
  32. package/dist/utility/chart/marketKind.util.js +15 -5
  33. package/dist/utility/chart/ny-calendar.util.d.ts +104 -0
  34. package/dist/utility/chart/ny-calendar.util.js +346 -0
  35. package/dist/utility/chart/om-panel.util.d.ts +14 -2
  36. package/dist/utility/chart/om-panel.util.js +108 -40
  37. package/dist/utility/chart/rth-session.util.d.ts +10 -7
  38. package/dist/utility/chart/rth-session.util.js +17 -22
  39. package/dist/utility/chart/trading-day.util.js +90 -18
  40. package/dist/utility/chart/us-equities-session.util.js +20 -67
  41. package/dist/utility/chart/wrun-bar-session-facts.util.js +14 -1
  42. package/dist/utility/common/time.util.d.ts +7 -1
  43. package/dist/utility/common/time.util.js +11 -41
  44. package/dist/utility/number-format.util.d.ts +17 -7
  45. package/dist/utility/number-format.util.js +18 -8
  46. package/dist/utility/options/option-symbol.util.js +13 -2
  47. package/dist/utility/symbol-selection/contract-expiry.util.js +9 -1
  48. package/dist/utility/watchlist/import/import-request.leaf.d.ts +4 -1
  49. package/dist/utility/watchlist/import/import-request.leaf.js +5 -2
  50. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +25 -4
  51. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +62 -4
  52. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +19 -0
  53. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +57 -0
  54. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +23 -0
  55. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +90 -0
  56. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.d.ts +39 -0
  57. package/dist/utility/wrun/run-schedule/wrun-lane-groups.util.js +60 -0
  58. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +77 -0
  59. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +195 -0
  60. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.d.ts +56 -0
  61. package/dist/utility/wrun/run-schedule/wrun-own-candles.util.js +70 -0
  62. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +53 -0
  63. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +239 -0
  64. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +16 -0
  65. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +14 -0
  66. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +43 -18
  67. package/dist/utility/wrun/sources/lanes/options_flow.js +209 -72
  68. package/dist/utility/wrun/sources/lanes/token_supply.js +5 -31
  69. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +3 -18
  70. package/dist/utility/wrun/sources/opra-option-lanes.util.js +12 -57
  71. package/dist/utility/wrun/sources/row-lane-registry.d.ts +1 -1
  72. package/dist/utility/wrun/sources/row-lane-registry.js +22 -8
  73. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +61 -0
  74. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +103 -8
  75. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +5 -0
  76. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +24 -12
  77. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +55 -0
  78. package/dist/utility/wrun/sources/row-lanes/option_prints.js +95 -18
  79. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +15 -1
  80. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +23 -8
  81. package/dist/utility/wrun/sources/row-lanes/option_surface.js +11 -11
  82. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +14 -2
  83. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +6 -3
  84. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +43 -8
  85. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +77 -11
  86. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +31 -16
  87. package/dist/utility/wrun/sources/wrun-row-lane.types.js +2 -0
  88. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +52 -12
  89. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +110 -46
  90. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +10 -0
  91. package/dist/utility/wrun/wrun-browser-sources.leaf.js +12 -0
  92. package/dist/utility/wrun/wrun-coin-lane-live.util.d.ts +3 -3
  93. package/dist/utility/wrun/wrun-coin-lane-live.util.js +53 -18
  94. package/dist/utility/wrun/wrun-color-settings.util.d.ts +6 -0
  95. package/dist/utility/wrun/wrun-color-settings.util.js +45 -0
  96. package/dist/utility/wrun/wrun-draft-overlay.util.js +14 -8
  97. package/dist/utility/wrun/wrun-failure-cause.d.ts +1 -1
  98. package/dist/utility/wrun/wrun-failure-cause.js +14 -0
  99. package/dist/utility/wrun/wrun-frames.js +6 -2
  100. package/dist/utility/wrun/wrun-host.service.d.ts +26 -18
  101. package/dist/utility/wrun/wrun-host.service.js +49 -52
  102. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +1 -1
  103. package/dist/utility/wrun/wrun-hosted-wire-caps.js +2 -0
  104. package/dist/utility/wrun/wrun-input-requirements.leaf.js +7 -4
  105. package/dist/utility/wrun/wrun-kit-run-tables.util.d.ts +24 -0
  106. package/dist/utility/wrun/wrun-kit-run-tables.util.js +87 -0
  107. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +2 -1
  108. package/dist/utility/wrun/wrun-live-tick.util.d.ts +8 -2
  109. package/dist/utility/wrun/wrun-live-tick.util.js +35 -16
  110. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +40 -13
  111. package/dist/utility/wrun/wrun-opra-flow.leaf.js +39 -12
  112. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +70 -21
  113. package/dist/utility/wrun/wrun-option-contract-flow.util.js +257 -112
  114. package/dist/utility/wrun/wrun-option-prints.util.d.ts +62 -22
  115. package/dist/utility/wrun/wrun-option-prints.util.js +148 -46
  116. package/dist/utility/wrun/wrun-option-views.util.d.ts +262 -0
  117. package/dist/utility/wrun/wrun-option-views.util.js +356 -0
  118. package/dist/utility/wrun/wrun-options-chain.util.d.ts +23 -2
  119. package/dist/utility/wrun/wrun-options-chain.util.js +37 -3
  120. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +18 -3
  121. package/dist/utility/wrun/wrun-overlay-drivers.util.js +32 -7
  122. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +9 -3
  123. package/dist/utility/wrun/wrun-overlay-recovery.util.js +146 -18
  124. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +50 -6
  125. package/dist/utility/wrun/wrun-overlay-run.util.js +816 -243
  126. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +5 -0
  127. package/dist/utility/wrun/wrun-pin-spelling.util.js +28 -12
  128. package/dist/utility/wrun/wrun-pin-venues.util.js +4 -6
  129. package/dist/utility/wrun/wrun-present-bits.util.d.ts +9 -0
  130. package/dist/utility/wrun/wrun-present-bits.util.js +39 -0
  131. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +3 -2
  132. package/dist/utility/wrun/wrun-refusal-surface.util.js +5 -4
  133. package/dist/utility/wrun/wrun-refusal.util.d.ts +66 -6
  134. package/dist/utility/wrun/wrun-refusal.util.js +335 -40
  135. package/dist/utility/wrun/wrun-source-rows.util.js +11 -0
  136. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +28 -3
  137. package/dist/utility/wrun/wrun-tier-grid.util.js +79 -19
  138. package/dist/utility/wrun/wrun-transient-rerun.util.d.ts +14 -3
  139. package/dist/utility/wrun/wrun-transient-rerun.util.js +33 -8
  140. package/package.json +5 -5
  141. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +0 -12
  142. package/dist/utility/wrun/wrun-opra-underlying.util.js +0 -1
@@ -0,0 +1,60 @@
1
+ /**
2
+ * A run's lane dispatch by group (run scheduling, 2026-10-20): every lane dispatches the moment ITS inputs are known,
3
+ * never after a plan it does not read.
4
+ *
5
+ * Why: the run planned every lane first and dispatched them together, so a lane whose inputs were known at the plan
6
+ * (a daily candle leg, a daily options stats poll lane) waited for every other lane's plan: a chain lane resolving
7
+ * the chart's options chain (one summary read, 1 to 7 s on INT), then the options chain lane's expiry directory. The
8
+ * first source request of an options indicator left a median 2.2 s after the add (74 of 90 measured cells over 1 s;
9
+ * INDICATOR-LOAD-BUDGET, "Frontend costs every add pays"). Now each group is added with the promise of its plan and
10
+ * dispatches through the run's own lane runner as that plan resolves:
11
+ *
12
+ * - `add(planned)`: a group's thunks once its plan resolved (undefined: nothing to dispatch). Groups are added in the
13
+ * order their plans were read before (the run's: the lanes it knows now, the poll lanes, the row lanes, the options
14
+ * chain), and that order decides which refusal wins.
15
+ * - `planned(retract)`: resolves once every plan resolved. The first plan to reject, in group order, is the run's
16
+ * refusal: no later group dispatches, every lane already dispatched is retracted (`retract`: the run lowers the
17
+ * pending mark it raised at dispatch, data-loading rule 3), and its read is abandoned, never aborted (its answer
18
+ * lands in the fetch cache). A plan that never answers keeps only its own lanes waiting.
19
+ * - `settled()`: every dispatched group's outcome, merged by the run (`merge`: declaration order, as one dispatch
20
+ * would have reported them).
21
+ *
22
+ * No timer is armed here: a group dispatches on its plan's own settle (a microtask after it), so a lane whose inputs
23
+ * are known at the plan is on the wire before anything the plans wait for answers (pinned by
24
+ * tests/utility/wrun/wrun-overlay-run.dispatch-at-mount.spec.ts under fake timers).
25
+ */
26
+ export function scheduleWrunLaneGroups(ports) {
27
+ let stopped = false;
28
+ const dispatched = [];
29
+ const groups = [];
30
+ return {
31
+ add(planned) {
32
+ const run = planned.then((thunks) => {
33
+ if (stopped || thunks === undefined)
34
+ return undefined;
35
+ dispatched.push(...ports.lanesOf(thunks));
36
+ return ports.run(thunks);
37
+ });
38
+ // Read by `settled` alone, after every plan resolved: never an unhandled rejection before.
39
+ void run.catch(() => undefined);
40
+ groups.push({ planned, run });
41
+ },
42
+ async planned(retract) {
43
+ for (const group of groups) {
44
+ try {
45
+ await group.planned;
46
+ }
47
+ catch (error) {
48
+ stopped = true;
49
+ for (const lane of dispatched.splice(0))
50
+ retract(lane);
51
+ throw error;
52
+ }
53
+ }
54
+ },
55
+ async settled() {
56
+ const runs = await Promise.all(groups.map((group) => group.run));
57
+ return ports.merge(runs.filter((run) => run !== undefined));
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The reads a run left out at a lane's degrade budget, which the source ladder joins or adopts instead of asking the
3
+ * same window again (run scheduling, 2026-10-20).
4
+ *
5
+ * The degrade budget (kscript-source-degrade.leaf `resolveSecondarySourceBudgetMs`: 10 s plus 2.5 s per 1,000 rows)
6
+ * stays the authority for the chip: at it the run marks the lane degraded and paints without it. The lane's read is
7
+ * abandoned, never aborted, so it is still on the wire. The ladder's rung used to run the overlay again 15 s later,
8
+ * and its lane asked the same window a second time beside the first (Options Market Stats and Market Share at 1h,
9
+ * 2026-10-20: painted empty at 14 to 15 s, painted with data at 31 s). Now:
10
+ *
11
+ * - the run notes each read it abandoned (`noteWrunLateRead`), by overlay and lane, with the identity of the ask (the
12
+ * run's window, market, chart data generation and settings revision) and a reader of the acquisition the run
13
+ * recorded for the lane (the payload its live session asks the lane again with);
14
+ * - the dispatch of a later run that asks the same lane with the same identity takes it (`takeWrunLateRead`): a read
15
+ * still out is JOINED (the lane waits on it under its own budget, and no second ask leaves), a read that answered
16
+ * with rows is ADOPTED (its rows, no ask); a failed read, or one asked another way, is no read and the lane asks;
17
+ * - the source ladder (wrun-overlay-recovery.util) fires its rung the moment the reads it waits on answer with rows,
18
+ * and a rung that comes due while one is still out waits for it instead of asking again (`onWrunLateReadSettled`).
19
+ *
20
+ * A read that never answers is bounded by the fetch's own deadline (wrun-deadline.util
21
+ * `WRUN_SOURCE_FETCH_DEADLINE_MS`, 45 s from its send) and by the transport's watchdog: it then fails, leaves this
22
+ * registry, and the next rung asks the wire. The degrade budget is a paint deadline, never a stall verdict: those two
23
+ * are. A read is taken once (a run that joined it notes it again if its own budget runs out first), a failed read and
24
+ * an answered one past `WRUN_LATE_READ_ADOPT_MS` are dropped, and every read of an overlay goes with it (teardown,
25
+ * suspend: `forgetWrunLateReads`). Pure module state: nothing here reads the host env.
26
+ */
27
+ /** The rows a lane read answers (the run's `WrunLaneRows`). */
28
+ export type WrunLateReadRows = ArrayLike<number>[];
29
+ /** How long an answered read stays adoptable: the source-row cache's freshness window (25 s), so an adopted read is
30
+ * never older than a row-cache hit would be. */
31
+ export declare const WRUN_LATE_READ_ADOPT_MS = 25000;
32
+ /** The most reads the registry keeps across every overlay: the oldest noted goes first past it. An overlay's own reads
33
+ * are one per lane and leave with it (`forgetWrunLateReads` on its teardown); the cap bounds the rows held for an
34
+ * overlay no ladder ever watches. */
35
+ export declare const WRUN_LATE_READS_KEPT = 64;
36
+ /** One abandoned read, as `noteWrunLateRead` takes it. */
37
+ export interface WrunLateReadNote {
38
+ indicatorId: string;
39
+ lane: string;
40
+ /** The ask the read answers: equal identities ask the same rows. */
41
+ identity: string;
42
+ /** The read itself: the lane's own answer, which the run stopped waiting for. */
43
+ answer: Promise<WrunLateReadRows>;
44
+ /** The acquisition the abandoning run recorded for the lane, read when a taker settles (a lane asked in pieces
45
+ * records it as its pieces leave). */
46
+ acquisition?: () => unknown;
47
+ }
48
+ /** What a later run takes: the rows (the read itself, or its answer) and the acquisition to record for the lane. */
49
+ export interface WrunLateReadTaken {
50
+ kind: 'joined' | 'adopted';
51
+ rows: Promise<WrunLateReadRows>;
52
+ acquisition: () => unknown;
53
+ }
54
+ /** Note a read the run left out at its lane's budget: the latest note of a lane replaces the one before it. */
55
+ export declare function noteWrunLateRead(note: WrunLateReadNote): void;
56
+ /**
57
+ * The read a run's dispatch joins or adopts for one lane: one with the same identity, still out (joined) or answered
58
+ * with rows inside the adopt window (adopted). Taken once: the entry leaves the registry either way. A read asked
59
+ * another way, failed or answered too long ago is dropped and answers undefined (the lane asks).
60
+ */
61
+ export declare function takeWrunLateRead(indicatorId: string, lane: string, identity: string): WrunLateReadTaken | undefined;
62
+ /** The lanes of `lanes` whose abandoned read is still out. */
63
+ export declare function wrunLateReadsOut(indicatorId: string, lanes: Iterable<string>): string[];
64
+ /** The lanes of `lanes` whose abandoned read answered with rows (adoptable now). */
65
+ export declare function wrunLateReadsAnswered(indicatorId: string, lanes: Iterable<string>): string[];
66
+ /** Called on every settle of one of the overlay's noted reads (answered or failed); answers the unsubscribe. */
67
+ export declare function onWrunLateReadSettled(indicatorId: string, listener: () => void): () => void;
68
+ /** Every read the overlay left out, and every listener on them, go with it (data-loading rule 3). */
69
+ export declare function forgetWrunLateReads(indicatorId: string): void;
70
+ /**
71
+ * A run's lane thunks with every lane joining or adopting its late read first (`take`, the run's own lookup by its
72
+ * ask identity): a lane with one never runs its thunk, so no second ask leaves. The run's shape: the builtin lanes by
73
+ * name (a function or undefined) and the lists of `[lane id, thunk]` pairs (trades legs, poll lanes, row lanes);
74
+ * everything else is returned as it is.
75
+ */
76
+ export declare function wrunJoinLateReads<T extends object>(thunks: T, take: (lane: string) => Promise<WrunLateReadRows> | undefined): T;
77
+ export declare function __resetWrunLateReadsForTests(): void;
@@ -0,0 +1,195 @@
1
+ /**
2
+ * The reads a run left out at a lane's degrade budget, which the source ladder joins or adopts instead of asking the
3
+ * same window again (run scheduling, 2026-10-20).
4
+ *
5
+ * The degrade budget (kscript-source-degrade.leaf `resolveSecondarySourceBudgetMs`: 10 s plus 2.5 s per 1,000 rows)
6
+ * stays the authority for the chip: at it the run marks the lane degraded and paints without it. The lane's read is
7
+ * abandoned, never aborted, so it is still on the wire. The ladder's rung used to run the overlay again 15 s later,
8
+ * and its lane asked the same window a second time beside the first (Options Market Stats and Market Share at 1h,
9
+ * 2026-10-20: painted empty at 14 to 15 s, painted with data at 31 s). Now:
10
+ *
11
+ * - the run notes each read it abandoned (`noteWrunLateRead`), by overlay and lane, with the identity of the ask (the
12
+ * run's window, market, chart data generation and settings revision) and a reader of the acquisition the run
13
+ * recorded for the lane (the payload its live session asks the lane again with);
14
+ * - the dispatch of a later run that asks the same lane with the same identity takes it (`takeWrunLateRead`): a read
15
+ * still out is JOINED (the lane waits on it under its own budget, and no second ask leaves), a read that answered
16
+ * with rows is ADOPTED (its rows, no ask); a failed read, or one asked another way, is no read and the lane asks;
17
+ * - the source ladder (wrun-overlay-recovery.util) fires its rung the moment the reads it waits on answer with rows,
18
+ * and a rung that comes due while one is still out waits for it instead of asking again (`onWrunLateReadSettled`).
19
+ *
20
+ * A read that never answers is bounded by the fetch's own deadline (wrun-deadline.util
21
+ * `WRUN_SOURCE_FETCH_DEADLINE_MS`, 45 s from its send) and by the transport's watchdog: it then fails, leaves this
22
+ * registry, and the next rung asks the wire. The degrade budget is a paint deadline, never a stall verdict: those two
23
+ * are. A read is taken once (a run that joined it notes it again if its own budget runs out first), a failed read and
24
+ * an answered one past `WRUN_LATE_READ_ADOPT_MS` are dropped, and every read of an overlay goes with it (teardown,
25
+ * suspend: `forgetWrunLateReads`). Pure module state: nothing here reads the host env.
26
+ */
27
+ /** How long an answered read stays adoptable: the source-row cache's freshness window (25 s), so an adopted read is
28
+ * never older than a row-cache hit would be. */
29
+ export const WRUN_LATE_READ_ADOPT_MS = 25_000;
30
+ /** The most reads the registry keeps across every overlay: the oldest noted goes first past it. An overlay's own reads
31
+ * are one per lane and leave with it (`forgetWrunLateReads` on its teardown); the cap bounds the rows held for an
32
+ * overlay no ladder ever watches. */
33
+ export const WRUN_LATE_READS_KEPT = 64;
34
+ const lateReads = new Map();
35
+ const settleListeners = new Map();
36
+ /** Every read in the order it was noted (entries a later note, a take or a forget already removed are skipped). */
37
+ let noteOrder = [];
38
+ /** Whether a noted read is still the registry's. */
39
+ function isKept(entry) {
40
+ return lateReads.get(entry.indicatorId)?.get(entry.lane) === entry.read;
41
+ }
42
+ /** Past `WRUN_LATE_READS_KEPT`, the oldest noted reads go first. */
43
+ function capWrunLateReads() {
44
+ noteOrder = noteOrder.filter(isKept);
45
+ while (noteOrder.length > WRUN_LATE_READS_KEPT) {
46
+ const oldest = noteOrder.shift();
47
+ if (oldest === undefined)
48
+ break;
49
+ const reads = lateReads.get(oldest.indicatorId);
50
+ reads?.delete(oldest.lane);
51
+ if (reads?.size === 0)
52
+ lateReads.delete(oldest.indicatorId);
53
+ }
54
+ }
55
+ function nowMs() {
56
+ return performance.now();
57
+ }
58
+ function notifySettled(indicatorId) {
59
+ for (const listener of [...(settleListeners.get(indicatorId) ?? [])])
60
+ listener();
61
+ }
62
+ /** Whether an answered read is past the adopt window (its rows are dropped, never adopted). */
63
+ function answeredTooLongAgo(read, now) {
64
+ return read.state === 'rows' && (read.answeredAt === undefined || now - read.answeredAt > WRUN_LATE_READ_ADOPT_MS);
65
+ }
66
+ /** Drop the overlay's answered reads past the adopt window: their rows are never held longer than a row-cache hit. */
67
+ function sweepWrunLateReads(indicatorId) {
68
+ const reads = lateReads.get(indicatorId);
69
+ if (reads === undefined)
70
+ return;
71
+ const now = nowMs();
72
+ for (const [lane, read] of reads)
73
+ if (answeredTooLongAgo(read, now))
74
+ reads.delete(lane);
75
+ if (reads.size === 0)
76
+ lateReads.delete(indicatorId);
77
+ }
78
+ /** Note a read the run left out at its lane's budget: the latest note of a lane replaces the one before it. */
79
+ export function noteWrunLateRead(note) {
80
+ sweepWrunLateReads(note.indicatorId);
81
+ let reads = lateReads.get(note.indicatorId);
82
+ if (reads === undefined) {
83
+ reads = new Map();
84
+ lateReads.set(note.indicatorId, reads);
85
+ }
86
+ const read = {
87
+ identity: note.identity,
88
+ answer: note.answer,
89
+ acquisition: note.acquisition ?? (() => undefined),
90
+ state: 'in-flight',
91
+ };
92
+ reads.delete(note.lane);
93
+ reads.set(note.lane, read);
94
+ noteOrder.push({ indicatorId: note.indicatorId, lane: note.lane, read });
95
+ capWrunLateReads();
96
+ const still = () => lateReads.get(note.indicatorId)?.get(note.lane) === read;
97
+ note.answer.then((rows) => {
98
+ read.state = 'rows';
99
+ read.rows = rows;
100
+ read.answeredAt = nowMs();
101
+ if (still())
102
+ notifySettled(note.indicatorId);
103
+ }, () => {
104
+ read.state = 'failed';
105
+ if (!still())
106
+ return;
107
+ lateReads.get(note.indicatorId)?.delete(note.lane);
108
+ notifySettled(note.indicatorId);
109
+ });
110
+ }
111
+ /**
112
+ * The read a run's dispatch joins or adopts for one lane: one with the same identity, still out (joined) or answered
113
+ * with rows inside the adopt window (adopted). Taken once: the entry leaves the registry either way. A read asked
114
+ * another way, failed or answered too long ago is dropped and answers undefined (the lane asks).
115
+ */
116
+ export function takeWrunLateRead(indicatorId, lane, identity) {
117
+ const reads = lateReads.get(indicatorId);
118
+ const read = reads?.get(lane);
119
+ if (reads === undefined || read === undefined)
120
+ return undefined;
121
+ reads.delete(lane);
122
+ if (reads.size === 0)
123
+ lateReads.delete(indicatorId);
124
+ if (read.identity !== identity || read.state === 'failed')
125
+ return undefined;
126
+ if (read.state === 'in-flight')
127
+ return { kind: 'joined', rows: read.answer, acquisition: read.acquisition };
128
+ if (answeredTooLongAgo(read, nowMs()))
129
+ return undefined;
130
+ return { kind: 'adopted', rows: Promise.resolve(read.rows ?? []), acquisition: read.acquisition };
131
+ }
132
+ /** The lanes of `lanes` whose abandoned read is still out. */
133
+ export function wrunLateReadsOut(indicatorId, lanes) {
134
+ const reads = lateReads.get(indicatorId);
135
+ if (reads === undefined)
136
+ return [];
137
+ return [...lanes].filter((lane) => reads.get(lane)?.state === 'in-flight');
138
+ }
139
+ /** The lanes of `lanes` whose abandoned read answered with rows (adoptable now). */
140
+ export function wrunLateReadsAnswered(indicatorId, lanes) {
141
+ const reads = lateReads.get(indicatorId);
142
+ if (reads === undefined)
143
+ return [];
144
+ const now = nowMs();
145
+ return [...lanes].filter((lane) => {
146
+ const read = reads.get(lane);
147
+ return read?.state === 'rows' && !answeredTooLongAgo(read, now);
148
+ });
149
+ }
150
+ /** Called on every settle of one of the overlay's noted reads (answered or failed); answers the unsubscribe. */
151
+ export function onWrunLateReadSettled(indicatorId, listener) {
152
+ let listeners = settleListeners.get(indicatorId);
153
+ if (listeners === undefined) {
154
+ listeners = new Set();
155
+ settleListeners.set(indicatorId, listeners);
156
+ }
157
+ listeners.add(listener);
158
+ return () => {
159
+ const known = settleListeners.get(indicatorId);
160
+ known?.delete(listener);
161
+ if (known?.size === 0)
162
+ settleListeners.delete(indicatorId);
163
+ };
164
+ }
165
+ /** Every read the overlay left out, and every listener on them, go with it (data-loading rule 3). */
166
+ export function forgetWrunLateReads(indicatorId) {
167
+ lateReads.delete(indicatorId);
168
+ settleListeners.delete(indicatorId);
169
+ }
170
+ /**
171
+ * A run's lane thunks with every lane joining or adopting its late read first (`take`, the run's own lookup by its
172
+ * ask identity): a lane with one never runs its thunk, so no second ask leaves. The run's shape: the builtin lanes by
173
+ * name (a function or undefined) and the lists of `[lane id, thunk]` pairs (trades legs, poll lanes, row lanes);
174
+ * everything else is returned as it is.
175
+ */
176
+ export function wrunJoinLateReads(thunks, take) {
177
+ const joined = (lane, run) => (abandoned) => take(lane) ?? run(abandoned);
178
+ const out = { ...thunks };
179
+ for (const [key, value] of Object.entries(out)) {
180
+ if (typeof value === 'function') {
181
+ out[key] = joined(key, value);
182
+ }
183
+ else if (Array.isArray(value)) {
184
+ out[key] = value.map((pair) => Array.isArray(pair) && typeof pair[0] === 'string' && typeof pair[1] === 'function'
185
+ ? [pair[0], joined(pair[0], pair[1])]
186
+ : pair);
187
+ }
188
+ }
189
+ return out;
190
+ }
191
+ export function __resetWrunLateReadsForTests() {
192
+ lateReads.clear();
193
+ settleListeners.clear();
194
+ noteOrder = [];
195
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * A run's candle ask for the chart's OWN series at the chart's OWN interval answers from the chart's rows, with no
3
+ * request (run scheduling, 2026-10-20).
4
+ *
5
+ * Why: the chart's main series IS that series: the candle lane fetched it from the same gateway series, the live
6
+ * feed writes the forming bar into it, and the polling lane corrects its tail. A wrun lane asked it again: a candles
7
+ * stream or a leg at the chart's interval on the chart's market, the forming pre-roll over bars a clamped window
8
+ * holds below its head. The kScript lane serves its own `ohlcv` source from the main rows inside the chart's fetch
9
+ * (kscript-source-rows-main-serve.util), but only on a timestamp-mode chart; every US stock and ETF chart (the
10
+ * options indicators' charts) is index mode, so the wrun ask went to the wire.
11
+ *
12
+ * The rule (`serveWrunOwnCandles`), judged before the ask leaves:
13
+ * - the ask: the candle lane (`ohlcv`), naming no other market (no payload extras but the chart's own exchange and
14
+ * symbol), at the chart's interval (no interval option, or the chart's), never a replay run's (its window reaches
15
+ * the replay's forward runway, past the rows the chart shows);
16
+ * - the window `[fromTs, toTs]` (the end an inclusive bar, as the chart's fetch reads it) held whole by the chart's
17
+ * bars (`held`: the chart's rows, copied, so the lane's buffer never shares the forming bar the live feed rewrites);
18
+ * anything else is null and the wire answers the window whole, exactly as before: a window opening before the
19
+ * chart's first bar (the chart holds no part older than its first bar, and the ask's shape stays the one the fetch
20
+ * caches and coalesces by), one reaching past the chart's newest bar, one the chart holds no bar of.
21
+ * - the rows: every chart row inside the window with a finite close (a missing bar the chart draws as a gap is no
22
+ * candle the wire answers).
23
+ *
24
+ * Pure: the caller reads the chart's rows and owns the ask (wrun-overlay-run.util `fetchLane`, the one door every
25
+ * lane of a run asks through). The call-site census (tests/utility/wrun/run-schedule/wrun-own-candles.census.spec.ts)
26
+ * fails a new source fetch door in the package that this rule does not stand in front of.
27
+ */
28
+ export interface WrunOwnCandlesAsk {
29
+ /** The fetch type of the ask (`ohlcv` is the candle lane). */
30
+ type: string;
31
+ /** The payload extras of the ask beyond the current-market placeholders (a pinned market's exchange and symbol). */
32
+ payloadExtras?: Readonly<Record<string, unknown>>;
33
+ /** The interval the ask rides (undefined: the chart's own). */
34
+ interval?: string;
35
+ /** A replay run's ask: never the chart's rows. */
36
+ replay: boolean;
37
+ /** The ask's window: its first bar's open and its last bar's open (inclusive), in ms. */
38
+ fromTs: number;
39
+ toTs: number;
40
+ chart: {
41
+ exchange?: string;
42
+ symbol?: string;
43
+ /** The chart's interval key (`1h`). */
44
+ interval: string;
45
+ intervalMs: number;
46
+ /** The chart's loaded candle rows, ascending (`[ts, open, high, low, close, volume]`). */
47
+ rows: ReadonlyArray<ArrayLike<number>>;
48
+ };
49
+ }
50
+ /** Every bar of the window, from the chart's rows; null: the wire answers the window. */
51
+ export type WrunOwnCandlesServe = {
52
+ kind: 'held';
53
+ rows: number[][];
54
+ } | null;
55
+ /** The chart's own candles for an ask of the chart's series at its interval (the module note), or null. */
56
+ export declare function serveWrunOwnCandles(ask: WrunOwnCandlesAsk): WrunOwnCandlesServe;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * A run's candle ask for the chart's OWN series at the chart's OWN interval answers from the chart's rows, with no
3
+ * request (run scheduling, 2026-10-20).
4
+ *
5
+ * Why: the chart's main series IS that series: the candle lane fetched it from the same gateway series, the live
6
+ * feed writes the forming bar into it, and the polling lane corrects its tail. A wrun lane asked it again: a candles
7
+ * stream or a leg at the chart's interval on the chart's market, the forming pre-roll over bars a clamped window
8
+ * holds below its head. The kScript lane serves its own `ohlcv` source from the main rows inside the chart's fetch
9
+ * (kscript-source-rows-main-serve.util), but only on a timestamp-mode chart; every US stock and ETF chart (the
10
+ * options indicators' charts) is index mode, so the wrun ask went to the wire.
11
+ *
12
+ * The rule (`serveWrunOwnCandles`), judged before the ask leaves:
13
+ * - the ask: the candle lane (`ohlcv`), naming no other market (no payload extras but the chart's own exchange and
14
+ * symbol), at the chart's interval (no interval option, or the chart's), never a replay run's (its window reaches
15
+ * the replay's forward runway, past the rows the chart shows);
16
+ * - the window `[fromTs, toTs]` (the end an inclusive bar, as the chart's fetch reads it) held whole by the chart's
17
+ * bars (`held`: the chart's rows, copied, so the lane's buffer never shares the forming bar the live feed rewrites);
18
+ * anything else is null and the wire answers the window whole, exactly as before: a window opening before the
19
+ * chart's first bar (the chart holds no part older than its first bar, and the ask's shape stays the one the fetch
20
+ * caches and coalesces by), one reaching past the chart's newest bar, one the chart holds no bar of.
21
+ * - the rows: every chart row inside the window with a finite close (a missing bar the chart draws as a gap is no
22
+ * candle the wire answers).
23
+ *
24
+ * Pure: the caller reads the chart's rows and owns the ask (wrun-overlay-run.util `fetchLane`, the one door every
25
+ * lane of a run asks through). The call-site census (tests/utility/wrun/run-schedule/wrun-own-candles.census.spec.ts)
26
+ * fails a new source fetch door in the package that this rule does not stand in front of.
27
+ */
28
+ /** Whether an ask names the chart's own market: no market extras, or exactly the chart's exchange and symbol. */
29
+ function asksChartMarket(ask) {
30
+ const extras = ask.payloadExtras;
31
+ if (extras === undefined)
32
+ return true;
33
+ for (const [key, value] of Object.entries(extras)) {
34
+ if (value === undefined)
35
+ continue;
36
+ if (key === 'exchange' && value === ask.chart.exchange)
37
+ continue;
38
+ if (key === 'symbol' && value === ask.chart.symbol)
39
+ continue;
40
+ return false;
41
+ }
42
+ return true;
43
+ }
44
+ /** The chart's own candles for an ask of the chart's series at its interval (the module note), or null. */
45
+ export function serveWrunOwnCandles(ask) {
46
+ if (ask.type !== 'ohlcv' || ask.replay)
47
+ return null;
48
+ if (ask.interval !== undefined && ask.interval !== ask.chart.interval)
49
+ return null;
50
+ if (!asksChartMarket(ask))
51
+ return null;
52
+ const { rows, intervalMs } = ask.chart;
53
+ if (rows.length === 0 || !(intervalMs > 0) || !(ask.toTs >= ask.fromTs))
54
+ return null;
55
+ const firstTs = Number(rows[0][0]);
56
+ const lastTs = Number(rows[rows.length - 1][0]);
57
+ // Older than the chart's first bar, or past its newest one: not the chart's to answer.
58
+ if (!(firstTs <= ask.fromTs) || !(ask.toTs < lastTs + intervalMs))
59
+ return null;
60
+ const held = [];
61
+ for (const row of rows) {
62
+ const ts = Number(row[0]);
63
+ if (ts < ask.fromTs || ts > ask.toTs)
64
+ continue;
65
+ if (!Number.isFinite(Number(row[4])))
66
+ continue;
67
+ held.push(Array.from(row));
68
+ }
69
+ return held.length > 0 ? { kind: 'held', rows: held } : null;
70
+ }
@@ -0,0 +1,53 @@
1
+ import type { WrunOverlayLiveContext } from '../wrun-overlay-drivers.util.js';
2
+ import type { WrunChartSourceRows } from '../wrun-source-rows.util.js';
3
+ import type { WrunPollLaneInstance } from '../sources/wrun-poll-lane.types.js';
4
+ import type { WrunRowLaneInstance } from '../sources/wrun-row-lane.types.js';
5
+ import { type WrunPrefixLaneClause, type WrunPrefixLaneEvidence, type WrunPrefixLanePages, type WrunPrefixLanePlan, type WrunPrefixLaneSplice } from '../wrun-prefix-lanes.util.js';
6
+ /** The clause that refuses a session (`lanes:<clause>`): the base rule's, or `row-budget` (the module note). */
7
+ export type WrunPrefixFeedClause = WrunPrefixLaneClause | 'row-budget';
8
+ /** What a page asks again: the base rule's lanes, the daily poll lanes, the row lanes asked by host bar, and the row
9
+ * lanes read empty on the page (a `latest` landing). */
10
+ export interface WrunPrefixFeedPlan extends WrunPrefixLanePlan {
11
+ daily: WrunPollLaneInstance[];
12
+ rows: WrunRowLaneInstance[];
13
+ emptyRows: WrunRowLaneInstance[];
14
+ }
15
+ /** The fetch-key suffix of a row lane instance's page ask: `rows-<instance id>`. */
16
+ export declare function wrunPrefixRowSuffix(instance: Pick<WrunRowLaneInstance, 'key'>): string;
17
+ /** The prefix feed rule (the module note): the clause that refuses, or what a page asks. */
18
+ export declare function planWrunPrefixFeeds(context: WrunOverlayLiveContext): {
19
+ refused: WrunPrefixFeedClause;
20
+ } | {
21
+ plan: WrunPrefixFeedPlan;
22
+ };
23
+ /** The feed rule's clause for a session, null when it admits (`planWrunPrefixFeeds`). */
24
+ export declare function wrunPrefixFeedClauseOf(context: WrunOverlayLiveContext): WrunPrefixFeedClause | null;
25
+ /** Whether a planned window reaches the session's live row while a lane that lands there alone holds a snapshot: the
26
+ * options chain (the base rule) or a row lane of a `latest` landing. */
27
+ export declare function wrunPrefixFeedsLiveRowRefused(context: WrunOverlayLiveContext, toMs: number): boolean;
28
+ /** The first row a daily lane's session buffer holds (its page asks the days before it), NaN when the buffer is empty. */
29
+ export declare function wrunPrefixDailyHeldFirstTs(context: WrunOverlayLiveContext, instance: WrunPollLaneInstance): number;
30
+ /**
31
+ * The window build's lane rows (the base rule's window split, `wrunPrefixWindowLanes`), and the daily and row lanes
32
+ * beside it: a daily lane reads its page, then every buffered day through the window's end; an asked row lane its page,
33
+ * then the session's rows over the overlap; a `latest` row lane reads empty. The lane evidence names every asked lane
34
+ * (the proof compares each inside the overlap, where both sides hold the session's own row objects).
35
+ */
36
+ export declare function wrunPrefixFeedWindowLanes(context: WrunOverlayLiveContext, plan: WrunPrefixFeedPlan, pages: WrunPrefixLanePages, firstRowTs: number, toMs: number): {
37
+ sourceRows: Partial<WrunChartSourceRows>;
38
+ lanes: WrunPrefixLaneEvidence[];
39
+ };
40
+ /** The session's buffers of the lanes a window's evidence names, as they stand now: the proof's mounted side. */
41
+ export declare function wrunPrefixFeedHeldLanes(context: WrunOverlayLiveContext, plan: WrunPrefixFeedPlan): WrunPrefixLaneEvidence[];
42
+ /** The buffers a landed page leaves its session: the base rule's, the daily lanes' (the page, then the whole buffer) and
43
+ * the asked row lanes' (the page, then the session's rows from its first row on). */
44
+ export interface WrunPrefixFeedSplice {
45
+ base: WrunPrefixLaneSplice;
46
+ daily: Record<string, ArrayLike<number>[]>;
47
+ rows: Record<string, ReadonlyArray<ReadonlyArray<unknown>>>;
48
+ }
49
+ /** The commit's splice, all or none (`wrunPrefixLaneSplice`): null when an asked lane has no buffer to splice. */
50
+ export declare function wrunPrefixFeedSplice(context: WrunOverlayLiveContext, plan: WrunPrefixFeedPlan, pages: WrunPrefixLanePages, firstRowTs: number): WrunPrefixFeedSplice | null;
51
+ /** Write a splice onto its session (synchronous; the buffers as new records, the reseed and the tail builder read the
52
+ * context's own). */
53
+ export declare function applyWrunPrefixFeedSplice(context: WrunOverlayLiveContext, splice: WrunPrefixFeedSplice): void;