@orangecharts/wrun-chart-host 0.5.0 → 0.6.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 (30) hide show
  1. package/README.md +5 -4
  2. package/dist/constants/feature-flags.constants.js +7 -2
  3. package/dist/host-env.d.ts +3 -19
  4. package/dist/host-ports.types.d.ts +1 -14
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/interfaces/wrun-runtime.interface.d.ts +88 -13
  8. package/dist/interfaces/wrun-runtime.interface.js +17 -3
  9. package/dist/utility/chart/chart-mount-epoch.util.d.ts +12 -0
  10. package/dist/utility/chart/chart-mount-epoch.util.js +32 -0
  11. package/dist/utility/wrun/wrun-bar-count.util.d.ts +17 -6
  12. package/dist/utility/wrun/wrun-bar-count.util.js +27 -12
  13. package/dist/utility/wrun/wrun-host.service.d.ts +114 -50
  14. package/dist/utility/wrun/wrun-host.service.js +351 -151
  15. package/dist/utility/wrun/wrun-hover.util.d.ts +3 -0
  16. package/dist/utility/wrun/wrun-hover.util.js +25 -4
  17. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +2 -2
  18. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +2 -2
  19. package/dist/utility/wrun/wrun-pack.util.d.ts +2 -1
  20. package/dist/utility/wrun/wrun-prefix-cohort.util.d.ts +1 -1
  21. package/dist/utility/wrun/wrun-prefix-cohort.util.js +1 -1
  22. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +5 -3
  23. package/dist/utility/wrun/wrun-sandbox-row-source.d.ts +2 -2
  24. package/dist/utility/wrun/wrun-sha256.leaf.d.ts +13 -0
  25. package/dist/utility/wrun/wrun-sha256.leaf.js +84 -0
  26. package/dist/workers/wrun/wrun-abi-host.d.ts +15 -2
  27. package/dist/workers/wrun/wrun-abi-host.js +31 -12
  28. package/dist/workers/wrun/wrun-engine-handler.d.ts +11 -28
  29. package/dist/workers/wrun/wrun-engine-handler.js +181 -12
  30. package/package.json +1 -1
package/README.md CHANGED
@@ -73,10 +73,10 @@ throw by name. 0.5.0 adds the phase 2 contract: 84 members and the `ui` and `eng
73
73
  session, the drivers, the engine and the executor read, and two optional members: `clock.watchHostSuspended` (a host
74
74
  that parks its chart while the page stays visible reports it, and the package's visible deadlines pause) and
75
75
  `chart.commonStore` (the go-to-date history flag the live tick reads in the caller's turn; without it every chart reads
76
- as live). It retires
77
- the three `run` loaders: they are optional at 0.5.0 (the package loads the lifecycle door, the refusal surface and the
78
- series stream itself) and go at 0.6.0. Their payload types and loader views are `host-ports.types`. The guide lists every member, what reads it and
79
- what web binds it.
76
+ as live). It retires the three `run` loaders: they are optional at 0.5.0 (the package loads the lifecycle door, the
77
+ refusal surface and the series stream itself), and 0.6.0 removes them with the `run` namespace: 131 members by the
78
+ contract's count (134 at 0.5.0), 133 in `host-env` with 0.5.0's two optional members. Their payload types and loader
79
+ views are `host-ports.types`. The guide lists every member, what reads it and what web binds it.
80
80
 
81
81
  A read before the set throws `wrun_chart_host_env_unset`. The env lives on the realm's global object under
82
82
  `Symbol.for('@orangecharts/wrun-chart-host/env')`, so every copy of the package in a realm reads the same one.
@@ -99,6 +99,7 @@ What each published version holds. A host installs a version with the peers of i
99
99
 
100
100
  | Version | Peers | What changed |
101
101
  | --- | --- | --- |
102
+ | 0.6.0 | `@orangecharts/indicator-kit` 0.87.0, `@orangecharts/orange-v2-pb-common` 12.69.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | The shared engine protocol: a module's bytes cross `postMessage` (the mobile app's portability rule) and the engine worker hashes them (`utility/wrun/wrun-sha256.leaf`), checks the sheet's pin, clamps, prepares and compiles them, caching up to 16 compiled modules per worker, so the main thread neither hashes nor compiles. `compileModule` becomes `loadModule`, which answers an opaque `WrunModuleHandle` (key, sha256, ABI, imports as `{ module, name }` pairs; no bytes); every full run and live-start carries the module's key, ABI and bytes (copied, never transferred), and the worker reuses its cached module or compiles the bytes on a miss, so a respawned worker compiles again. A request runs on two 20 s clocks, the start ceiling from the post (queue plus compile) and the run deadline from the worker's `running`; `loadModule` rejects a failed compile as a `WebAssembly.CompileError` with the worker's words and a pin mismatch with the words it had before 0.6.0. The `run` namespace goes with its three loaders (`run.loadOverlayLifecycleDoor`, `run.loadRefusalSurface`, `run.loadSeriesStream`, retired at 0.5.0), `WrunHostRun` and their three loader views in `host-ports.types`: 131 members by the contract's count, 133 with 0.5.0's two optional ones. Peers unchanged. |
102
103
  | 0.5.0 | `@orangecharts/indicator-kit` 0.87.0, `@orangecharts/orange-v2-pb-common` 12.69.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Phase 2: the live session (the live tick, intake, hidden-tab hold, coin lane live channels, series stream), the drivers and the heal ladder (the lifecycle door, `utility/wrun/wrun-overlay-lifecycle.lazy` by subpath, its runtime and the recovery ladders), the prefix runs, the engine (`workers/wrun/wrun-abi-host`, `workers/wrun/wrun-engine-handler`, the browser host), the host facts and the executor (`utility/wrun/wrun-overlay-run.util`, by subpath) with its row sources: 135 modules, 398 in all. The env gains the 84 phase 2 members, the `ui` and `engine` namespaces and the optional `clock.watchHostSuspended` and `chart.commonStore`; the three `run` loaders turn optional (gone at 0.6.0). The panel mount reads a host's planned pane heights on every cell and retranslates an unchanged child in place, keeping a reader's expanded pane through a retire. The entry no longer serves `utility/wrun/wrun-overlay-identity.util` (by subpath; above). The kit peer moves from 0.86.3 to 0.87.0 (`option_multiplier`); the other peers are unchanged. |
103
104
  | 0.4.0 | `@orangecharts/indicator-kit` 0.86.3, `@orangecharts/orange-v2-pb-common` 12.69.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Phase 1b: the panel mount (`utility/wrun/wrun-panel-mount.util`, by subpath) and its door (`utility/wrun/wrun-panel-mount.lazy`), the run interval rules (`utility/chart/indicator-run-interval.util`) with the builtin script snippets they type against, the pause dim and six leaves (the window owner and window geometry rules, the date-labelled interval rule, the HTML escape, the run interval projection and plot gate types): 11 modules, 262 in all. The mount reads the host through the env: the 12 members reserved until 0.4.0, `t` and `diagnostics.debug`. Peers unchanged. |
104
105
  | 0.3.0 | `@orangecharts/indicator-kit` 0.86.3, `@orangecharts/orange-v2-pb-common` 12.69.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Three programs ship together. The settings templates: the nested entry `@orangecharts/wrun-chart-host/settings-templates`, one declared settings schema for every template (`TEMPLATE_SCHEMA_VERSION` 2). The phase 1 host contract: 42 env members (`host-env`) with their payload types and loader views (`host-ports.types`), 22 read by 0.3.0 modules, the rest reserved. Phase 1a's move: the lane layer (both lane registries, read through generated indexes, the lane files and planners), the row builder, legs and pins, the cloud row source and the main-grid stages, with what they read: 142 modules, 250 in all. The kit peer moves from 0.80.0 to 0.86.3 (leg streams and per-span levels) and the protocol enums package joins the peers. |
@@ -40,8 +40,13 @@ export const FeatureFlag = {
40
40
  // paper"). Rides this key, read through `isOn` (`isPaperTradingOn`):
41
41
  // unminted, absent and guest all read off, so production ships it dark; an internal role reads it
42
42
  // on through the server's bypass, the dev/internal localStorage override lights it locally
43
- // (`kiyo.flag-overrides` -> `{"paper-trading": true}`). Mint it enabled to open it up. The build
44
- // switch `PAPER_TRADING_ENABLED` still takes the whole venue out of a build.
43
+ // (`kiyo.flag-overrides` -> `{"paper-trading": true}`). Mint it enabled to open it up. The same
44
+ // key also lights the three exchange venues launched dark (docs/features/cex-execution/README.md,
45
+ // "Dark launch, entities, passphrase"): OKX, Deribit, and Coinbase derivatives (the Deribit engine
46
+ // for non-US accounts), their discovery and new linking, read through `isOn` by `isCexVenueFlagOn`.
47
+ // A key this browser already holds for one of them keeps trading after the flag turns off. The
48
+ // build switch `PAPER_TRADING_ENABLED` takes only the paper venue out of a build, never the
49
+ // exchange venues.
45
50
  PaperTrading: 'paper-trading',
46
51
  // The trading hub (docs/features/trading-hub/README.md): one Trade door beside the avatar that
47
52
  // folds the desktop's linking, accounts and trade settings into one dialog. Rides the master
@@ -10,7 +10,7 @@
10
10
  * bundle that splits it, a spec that resets its module registry) reads the one the realm's entry set.
11
11
  */
12
12
  import type * as WrunKitHost from '@orangecharts/indicator-kit/host';
13
- import type { WrunAttemptOutcome, WrunAttemptStageMs, WrunAttemptToken, WrunChartHandle, WrunChartModeModule, WrunChartPaintMode, WrunChartPaintOptions, WrunChartPaintTarget, WrunChartRoutingModule, WrunChartStoreModule, WrunChartStoreView, WrunCommonStoreModule, WrunConsoleRefusalRun, WrunContinuousContractsModule, WrunContrastGuardContext, WrunDataFetchingModule, WrunDeclaredDepthAsk, WrunDeribitOptionsModule, WrunEditorShellModule, WrunEndOfDataMarkerReason, WrunEngineWorker, WrunEngineWorkerOptions, WrunFailureShow, WrunFeedStreamApi, WrunFeedsServiceModule, WrunHiddenLiveDrainOutcome, WrunHostOverlayRef, WrunIndicatorRegistryModule, WrunIndicatorTypesModule, WrunInputRequirement, WrunIntegrateOptions, WrunIntegrateResult, WrunKitModule, WrunKScriptErrorEnvelopeModule, WrunLegendHoverModule, WrunLiveCoalesceFlush, WrunLiveCoalesceTickDecision, WrunLiveFeedServiceModule, WrunLiveRefreshGateDecision, WrunMarketEventsStoreModule, WrunMetadataServiceModule, WrunOffchartGridHeightsModule, WrunOptionChainServiceModule, WrunOptionsChainVenuesModule, WrunOptionsChartSourceModule, WrunOptionsGateModule, WrunOptionsOverlayProvenanceModule, WrunOverlayLifecycleDoorModule, WrunOverlayMeasureResult, WrunPackEnsureInput, WrunPackEnsureResult, WrunPaneBudgetRankingModule, WrunPlotGateChart, WrunPlotGateRefusal, WrunPriceMarkerTarget, WrunRefreshRowsOptions, WrunRefreshRowsResult, WrunRefusalActionsModule, WrunRefusalSurfaceModule, WrunSearchPayloadToMarketsRequestModule, WrunSeriesStreamModule, WrunSignalSheetView, WrunSignalSoundCheck, WrunSocketChartRows, WrunSocketLoadSignals, WrunSocketTransport, WrunSocketTransportModule, WrunSourceCountMetadataLike, WrunSourceDegradeEntry, WrunSourceFetchOptions, WrunStandInTarget, WrunStandInWriteArgs, WrunStandInWriteOutcome, WrunSymbolDisplayModule, WrunTitanChartsModule, WrunTpoBlockCatalogModule, WrunTwinsRosterModule, WrunV2ServiceModule, WrunVenueLegsArgs, WrunVenueLegsResult, WrunWarmupBackfillAsk, WrunWarmupBackfillOutcome } from './host-ports.types.js';
13
+ import type { WrunAttemptOutcome, WrunAttemptStageMs, WrunAttemptToken, WrunChartHandle, WrunChartModeModule, WrunChartPaintMode, WrunChartPaintOptions, WrunChartPaintTarget, WrunChartRoutingModule, WrunChartStoreModule, WrunChartStoreView, WrunCommonStoreModule, WrunConsoleRefusalRun, WrunContinuousContractsModule, WrunContrastGuardContext, WrunDataFetchingModule, WrunDeclaredDepthAsk, WrunDeribitOptionsModule, WrunEditorShellModule, WrunEndOfDataMarkerReason, WrunEngineWorker, WrunEngineWorkerOptions, WrunFailureShow, WrunFeedStreamApi, WrunFeedsServiceModule, WrunHiddenLiveDrainOutcome, WrunHostOverlayRef, WrunIndicatorRegistryModule, WrunIndicatorTypesModule, WrunInputRequirement, WrunIntegrateOptions, WrunIntegrateResult, WrunKitModule, WrunKScriptErrorEnvelopeModule, WrunLegendHoverModule, WrunLiveCoalesceFlush, WrunLiveCoalesceTickDecision, WrunLiveFeedServiceModule, WrunLiveRefreshGateDecision, WrunMarketEventsStoreModule, WrunMetadataServiceModule, WrunOffchartGridHeightsModule, WrunOptionChainServiceModule, WrunOptionsChainVenuesModule, WrunOptionsChartSourceModule, WrunOptionsGateModule, WrunOptionsOverlayProvenanceModule, WrunOverlayMeasureResult, WrunPackEnsureInput, WrunPackEnsureResult, WrunPaneBudgetRankingModule, WrunPlotGateChart, WrunPlotGateRefusal, WrunPriceMarkerTarget, WrunRefreshRowsOptions, WrunRefreshRowsResult, WrunRefusalActionsModule, WrunSearchPayloadToMarketsRequestModule, WrunSignalSheetView, WrunSignalSoundCheck, WrunSocketChartRows, WrunSocketLoadSignals, WrunSocketTransport, WrunSocketTransportModule, WrunSourceCountMetadataLike, WrunSourceDegradeEntry, WrunSourceFetchOptions, WrunStandInTarget, WrunStandInWriteArgs, WrunStandInWriteOutcome, WrunSymbolDisplayModule, WrunTitanChartsModule, WrunTpoBlockCatalogModule, WrunTwinsRosterModule, WrunV2ServiceModule, WrunVenueLegsArgs, WrunVenueLegsResult, WrunWarmupBackfillAsk, WrunWarmupBackfillOutcome } from './host-ports.types.js';
14
14
  import type { CmeServedAccess } from './interfaces/cme-realtime.interface.js';
15
15
  import type { WrunDrawSkips, WrunOutputRow } from './interfaces/wrun-runtime.interface.js';
16
16
  import type { WrunLatestSnapshot } from './utility/wrun/wrun-latest-snapshot.js';
@@ -125,7 +125,8 @@ export interface WrunChartHostDiagnostics {
125
125
  * a sync call answering the Promise the executor awaits at :5762, :6642). */
126
126
  publishSkippedNotice(chartIndex: number, indicatorId: string, skips: WrunDrawSkips | undefined): Promise<void>;
127
127
  }
128
- /** What the layer reads from its host. */
128
+ /** What the layer reads from its host. REMOVED 0.6.0: the `run` namespace, whose three transitional loaders 0.5.0
129
+ * retired (the package imports the lifecycle door, the refusal surface and the series stream itself). */
129
130
  export interface WrunChartHostEnv {
130
131
  /** A user-facing string by its locale key (web: the i18n plugin). Reserved until 0.4.0 (the panel mount's legend
131
132
  * words). CHANGED 0.5.0: + `plural` (vue-i18n's third argument). web: (key, params, plural) => plural === undefined ?
@@ -154,9 +155,6 @@ export interface WrunChartHostEnv {
154
155
  market: WrunHostMarket;
155
156
  /** 0.3.0. */
156
157
  transport: WrunHostTransport;
157
- /** 0.3.0, transitional (D-4). Retired at 0.5.0: every member optional, none called by package code; removed at
158
- * 0.6.0. */
159
- run: WrunHostRun;
160
158
  /** 0.3.0, reserved until 0.5.0. */
161
159
  clock: WrunHostClock;
162
160
  /** 0.5.0. */
@@ -470,20 +468,6 @@ export interface WrunHostTransport {
470
468
  * factory :132, inside the socket module load's .then). */
471
469
  loadLiveFeedService(): Promise<WrunLiveFeedServiceModule>;
472
470
  }
473
- /** TRANSITIONAL (D-4): loaders into modules Phase 2 moved. Retired at 0.5.0: each is optional and no package code
474
- * calls it (the three modules are package modules, loaded package-internally with the same destructuring); removed
475
- * at 0.6.0. A host may keep binding them until then (web does, web-ports/boot.ts). */
476
- export interface WrunHostRun {
477
- /** 0.3.0, boot loader; retired at 0.5.0 (the socket row source imports ./wrun-overlay-lifecycle.lazy). web:
478
- * import('@/utility/wrun/wrun-overlay-lifecycle.lazy') viewed as { requestWrunOverlayRerun }. */
479
- loadOverlayLifecycleDoor?(): Promise<WrunOverlayLifecycleDoorModule>;
480
- /** 0.3.0, boot loader; retired at 0.5.0 (the socket row source imports ./wrun-refusal-surface.util). web:
481
- * import('@/utility/wrun/wrun-refusal-surface.util') viewed as { liveWrunRefusalAttempt }. */
482
- loadRefusalSurface?(): Promise<WrunRefusalSurfaceModule>;
483
- /** 0.3.0, boot loader; retired at 0.5.0 (the series lane imports ../../wrun-series-stream.util). web:
484
- * import('@/utility/wrun/wrun-series-stream.util') viewed as { openWrunSeriesStream }. */
485
- loadSeriesStream?(): Promise<WrunSeriesStreamModule>;
486
- }
487
471
  /** Page visibility (reserved until 0.5.0, boot; live at 0.5.0, the live tick reads both) and the hidden live pace
488
472
  * (0.5.0, boot). Timers and Date.now stay direct (D-10). */
489
473
  export interface WrunHostClock {
@@ -22,11 +22,10 @@ import type { HistoryWallKind } from './utility/chart/history-wall.util.js';
22
22
  import type { OverlayRunInterval as WrunOverlayRunInterval } from './utility/chart/indicator-run-interval.util.js';
23
23
  import type { WrunVisibilityChart } from './utility/chart/wrun-visibility-chart.util.js';
24
24
  import type { OptionSource as WrunOptionSource } from './utility/options/option-venue.util.js';
25
- import type { WrunPollLaneLiveAsk, WrunPollLaneLiveSink, WrunPollLaneLiveSubscription } from './utility/wrun/sources/wrun-poll-lane.types.js';
26
25
  import type { WrunOptionsChainCryptoVenues as WrunOptionsChainVenues, WrunOptionsChainCryptoVenueWord } from './utility/wrun/wrun-options-chain.util.js';
27
26
  import type { WrunRunReason } from './utility/wrun/wrun-lifecycle.contract.js';
28
27
  import type { WrunPaneFormatChart } from './utility/wrun/wrun-pane-format.util.js';
29
- import type { WrunRefusal, WrunRefusalAttemptToken, WrunRefusalClass, WrunRefusalOverlayTarget } from './utility/wrun/wrun-refusal.util.js';
28
+ import type { WrunRefusal, WrunRefusalClass, WrunRefusalOverlayTarget } from './utility/wrun/wrun-refusal.util.js';
30
29
  import type { WrunRowSourceIdentity } from './utility/wrun/wrun-row-source.js';
31
30
  import type { WrunSocketTransport } from './utility/wrun/wrun-socket-row-source.js';
32
31
  import type { WrunColorTheme } from './utility/wrun/wrun-style-words.util.js';
@@ -632,20 +631,8 @@ export interface WrunKScriptErrorEnvelopeModule {
632
631
  editorRun: boolean;
633
632
  }): RuntimeDiagnostic[];
634
633
  }
635
- /** Loader view of the overlay lifecycle door. */
636
- export interface WrunOverlayLifecycleDoorModule {
637
- requestWrunOverlayRerun(chartIndex: number, indicatorId: string, reason: 'source-recovery'): Promise<void> | false;
638
- }
639
- /** Loader view of the refusal surface. */
640
- export interface WrunRefusalSurfaceModule {
641
- liveWrunRefusalAttempt(chartIndex: number, indicatorId: string): WrunRefusalAttemptToken | null;
642
- }
643
634
  /** A lane's live channel ask, sink and handle (utility/wrun/sources/wrun-poll-lane.types.ts, moved in phase 1a). */
644
635
  export type { WrunPollLaneLiveAsk, WrunPollLaneLiveSink, WrunPollLaneLiveSubscription, } from './utility/wrun/sources/wrun-poll-lane.types.js';
645
- /** Loader view of the series stream. */
646
- export interface WrunSeriesStreamModule {
647
- openWrunSeriesStream(ask: WrunPollLaneLiveAsk, sink: WrunPollLaneLiveSink): Promise<WrunPollLaneLiveSubscription>;
648
- }
649
636
  /** The engine surface a paint request reaches (web: `KScriptChartPaintTarget`). */
650
637
  export interface WrunChartPaintTarget {
651
638
  requestLiveRecompute?(opts?: {
package/dist/index.d.ts CHANGED
@@ -339,6 +339,7 @@ export * from './utility/wrun/wrun-script-inputs.util.js';
339
339
  export * from './utility/wrun/wrun-series-stream.util.js';
340
340
  export * from './utility/wrun/wrun-setting-words.lazy.js';
341
341
  export * from './utility/wrun/wrun-setting-words.util.js';
342
+ export * from './utility/wrun/wrun-sha256.leaf.js';
342
343
  export * from './utility/wrun/wrun-sheet-remembered.util.js';
343
344
  export * from './utility/wrun/wrun-signal-sound-reasons.leaf.js';
344
345
  export * from './utility/wrun/wrun-socket-row-source.js';
package/dist/index.js CHANGED
@@ -342,6 +342,7 @@ export * from './utility/wrun/wrun-script-inputs.util.js';
342
342
  export * from './utility/wrun/wrun-series-stream.util.js';
343
343
  export * from './utility/wrun/wrun-setting-words.lazy.js';
344
344
  export * from './utility/wrun/wrun-setting-words.util.js';
345
+ export * from './utility/wrun/wrun-sha256.leaf.js';
345
346
  export * from './utility/wrun/wrun-sheet-remembered.util.js';
346
347
  export * from './utility/wrun/wrun-signal-sound-reasons.leaf.js';
347
348
  export * from './utility/wrun/wrun-socket-row-source.js';
@@ -14,9 +14,17 @@
14
14
  * when string slots are declared.
15
15
  * - Response: `ready` (Uint8Array) + `outputs` (Float64Array, row-major at
16
16
  * the output count), plus the packed string table when slots are declared.
17
- * - Every buffer is transferred, never structured-cloned; the compiled
18
- * `WebAssembly.Module` itself IS structured-cloned (browser spec allows
19
- * sharing compiled modules across agents in one cluster).
17
+ * - Every row and output buffer is transferred, never structured-cloned.
18
+ * - The module crosses as its original BYTES, never as a compiled
19
+ * `WebAssembly.Module` (the shared engine protocol, wrun-chart-host 0.6.0):
20
+ * `module-load` hands the worker the bytes once to hash, verify against the
21
+ * sheet's pin, clamp, prepare and compile, and answers the client's opaque
22
+ * handle (`WrunModuleHandle`); every full run and live-start names the
23
+ * compiled module by its key and carries the bytes again (copied by
24
+ * structured clone, never transferred), so a worker that lost its cache
25
+ * (a respawn, an eviction) compiles them again. The worker answers
26
+ * `{ id, running: true }` once the module is instantiated (the request
27
+ * executes from there), and the run's deadline starts there.
20
28
  */
21
29
  import type { WrunHandleDefaultsByKind, WrunHandleKind, WrunHandleRecord, WrunLabelPosition, WrunTextStyle } from '../utility/wrun/wrun-handles.util.js';
22
30
  import type { WrunParamHostFill, WrunWarmupWindow } from '@orangecharts/indicator-kit';
@@ -53,7 +61,14 @@ export interface WrunPackedRunRequest extends WrunPackedRowsBlock {
53
61
  /** 'live' arms same-bar snapshot/restore replay; 'historical' drives each
54
62
  * row exactly once. */
55
63
  mode: 'historical' | 'live';
56
- module: WebAssembly.Module;
64
+ /** The module's key in the worker's cache (`${sha256}|${abi}`, the handle's
65
+ * `key`): a worker holding it reuses its compiled module. */
66
+ moduleKey: string;
67
+ /** The module's original bytes: the host's private snapshot behind the
68
+ * handle, copied by structured clone (never transferred). The worker
69
+ * compiles them only on a miss (it never held the key, or let it go),
70
+ * after checking they hash to the key's digest. */
71
+ moduleBytes: Uint8Array;
57
72
  outputCount: number;
58
73
  /** init()'s positional argument block (declared params, in order). */
59
74
  initArgs: number[];
@@ -71,14 +86,67 @@ export interface WrunPackedRunRequest extends WrunPackedRowsBlock {
71
86
  * a text param with no entry reads as "" at the module. */
72
87
  textParams?: Readonly<Record<number, Uint8Array>>;
73
88
  }
89
+ /** One import of a module, as WebAssembly.Module.imports() lists it. */
90
+ export interface WrunModuleImport {
91
+ readonly module: string;
92
+ readonly name: string;
93
+ }
94
+ /** A module the engine worker verified and compiled: the client's opaque handle, never a WebAssembly.Module.
95
+ * The host keeps the original bytes privately (a WeakMap behind the handle); nothing outside the host reads them. */
96
+ export interface WrunModuleHandle {
97
+ /** `${sha256}|${abi}`: the worker's cache key. Minted by the worker's verified load, never by a caller. */
98
+ readonly key: string;
99
+ /** Hex sha256 of the ORIGINAL package bytes (the sheet's wasm_sha256 pin when it has one; computed otherwise). */
100
+ readonly sha256: string;
101
+ /** The ABI version the sheet declares (metadata.abi_version). */
102
+ readonly abi: WrunAbiVersion;
103
+ /** Every import in WebAssembly.Module.imports() order (the bar-count and stamp readers). */
104
+ readonly imports: readonly WrunModuleImport[];
105
+ }
106
+ /** A module's key in the engine worker's cache, the handle's `key`: the sha256 of its original bytes and the ABI it
107
+ * compiles for. The worker mints it from the digest it computed; the client keys its own cache of a pinned sheet's
108
+ * handle by the same spelling of the pin, so the two never drift apart. */
109
+ export declare function wrunModuleKey(sha256: string, abi: WrunAbiVersion): string;
110
+ /** main -> worker: hash, verify, prepare and compile a module; cache it under its key. */
111
+ export interface WrunModuleLoadRequest {
112
+ kind: 'module-load';
113
+ id: number;
114
+ abi: WrunAbiVersion;
115
+ /** The sheet's pin; a mismatch answers `module-pin-mismatch` (with the digest found) and caches nothing. */
116
+ sha256Pin?: string;
117
+ /** The original bytes. Copied, never transferred: the host keeps its own snapshot. */
118
+ bytes: Uint8Array;
119
+ }
120
+ export interface WrunModuleLoadResponse {
121
+ id: number;
122
+ ok: true;
123
+ kind: 'module-load';
124
+ key: string;
125
+ sha256: string;
126
+ imports: WrunModuleImport[];
127
+ }
128
+ /** worker -> main, once per run, live-start and live-rows request, once the module is instantiated, right before the
129
+ * guest's first call (or at once for live-rows): the run deadline starts. A terminal reply may come without it (a
130
+ * lost session, a refused load). */
131
+ export interface WrunWorkerRunningMessage {
132
+ id: number;
133
+ running: true;
134
+ }
135
+ /** A full run as the ABI host runs it (`runWrunPackedRequest`): the wire request minus the module's transport (its
136
+ * key and bytes) plus the module the engine worker resolved them to. An internal type the worker's handler builds;
137
+ * the wire type never carries a module. */
138
+ export type WrunResolvedRunRequest = Omit<WrunPackedRunRequest, 'moduleKey' | 'moduleBytes'> & {
139
+ module: WebAssembly.Module;
140
+ };
74
141
  /** Full run that also OPENS (or replaces) a live session under sessionKey. */
75
142
  export interface WrunLiveStartRequest extends WrunPackedRunRequest {
76
143
  kind: 'live-start';
77
144
  sessionKey: string;
78
145
  /** The live context generation opening this session. The worker keeps the
79
146
  * newest epoch per session key: a live-start whose epoch is no longer the
80
- * newest when its instantiation settles (a newer start or a live-end
81
- * arrived meanwhile) computes its block but installs no session, so a
147
+ * newest when its compile and instantiation settle (a newer start or a
148
+ * live-end arrived meanwhile; the worker reads the fence and the epoch as
149
+ * the start arrives) computes its block but installs no session, so a
82
150
  * torn-down overlay's pending start can never resurrect a session. Absent
83
151
  * on legacy callers: installs unconditionally after the live-end fence. */
84
152
  epoch?: number;
@@ -130,7 +198,7 @@ export interface WrunLiveEndRequest {
130
198
  }
131
199
  /** Everything the sandbox worker accepts. A bare WrunPackedRunRequest (no
132
200
  * `kind`) stays the classic one-shot run. */
133
- export type WrunWorkerRequest = WrunPackedRunRequest | WrunLiveStartRequest | WrunLiveRowsRequest | WrunLiveEndRequest;
201
+ export type WrunWorkerRequest = WrunPackedRunRequest | WrunLiveStartRequest | WrunLiveRowsRequest | WrunLiveEndRequest | WrunModuleLoadRequest;
134
202
  interface WrunPackedRunStrings {
135
203
  lens: Int32Array;
136
204
  offsets: Int32Array;
@@ -157,7 +225,7 @@ export type WrunWorkerResponse = {
157
225
  frames?: (string | undefined)[];
158
226
  /** Live-mode blocks only: the block's restore/snapshot accounting. */
159
227
  live?: WrunLiveBlockStats;
160
- } | {
228
+ } | WrunModuleLoadResponse | WrunWorkerRunningMessage | {
161
229
  id: number;
162
230
  ok: false;
163
231
  error: string;
@@ -165,11 +233,18 @@ export type WrunWorkerResponse = {
165
233
  * started, disposed, or lost to a worker respawn). The caller rebuilds
166
234
  * via a fresh live-start instead of treating this as a compute error. */
167
235
  sessionLost?: true;
168
- /** live-rows only: the block was refused before evaluation because its
169
- * rows run backwards (WrunLiveOrderError); the session survives, and
170
- * the caller reseeds it from its buffers (the worker and the context
171
- * disagree on the watermark) instead of retrying the same block. */
172
- code?: 'live-order';
236
+ /** `live-order` (live-rows only): the block was refused before
237
+ * evaluation because its rows run backwards (WrunLiveOrderError); the
238
+ * session survives, and the caller reseeds it from its buffers (the
239
+ * worker and the context disagree on the watermark) instead of retrying
240
+ * the same block. `module-pin-mismatch`: the bytes do not hash to the
241
+ * sheet's pin (a load) or to the run's module key (a full run or
242
+ * live-start compiling on a miss); nothing is cached. `module-compile-
243
+ * failed`: the engine refused to compile the module (a
244
+ * WebAssembly.CompileError); nothing is cached. */
245
+ code?: 'live-order' | 'module-pin-mismatch' | 'module-compile-failed';
246
+ /** `module-pin-mismatch` only: the hex sha256 the bytes hash to. */
247
+ sha256?: string;
173
248
  };
174
249
  /** One unpacked result row: `outputs` is null on a non-ready row; `strings`
175
250
  * entries are undefined for ABSENT slots and '' for present-empty writes. */
@@ -14,9 +14,17 @@
14
14
  * when string slots are declared.
15
15
  * - Response: `ready` (Uint8Array) + `outputs` (Float64Array, row-major at
16
16
  * the output count), plus the packed string table when slots are declared.
17
- * - Every buffer is transferred, never structured-cloned; the compiled
18
- * `WebAssembly.Module` itself IS structured-cloned (browser spec allows
19
- * sharing compiled modules across agents in one cluster).
17
+ * - Every row and output buffer is transferred, never structured-cloned.
18
+ * - The module crosses as its original BYTES, never as a compiled
19
+ * `WebAssembly.Module` (the shared engine protocol, wrun-chart-host 0.6.0):
20
+ * `module-load` hands the worker the bytes once to hash, verify against the
21
+ * sheet's pin, clamp, prepare and compile, and answers the client's opaque
22
+ * handle (`WrunModuleHandle`); every full run and live-start names the
23
+ * compiled module by its key and carries the bytes again (copied by
24
+ * structured clone, never transferred), so a worker that lost its cache
25
+ * (a respawn, an eviction) compiles them again. The worker answers
26
+ * `{ id, running: true }` once the module is instantiated (the request
27
+ * executes from there), and the run's deadline starts there.
20
28
  */
21
29
  const WRUN_ABI_ORDER = {
22
30
  'wrun-1': 1,
@@ -29,6 +37,12 @@ const WRUN_ABI_ORDER = {
29
37
  export function abiAtLeast(abi, floor) {
30
38
  return WRUN_ABI_ORDER[abi] >= WRUN_ABI_ORDER[floor];
31
39
  }
40
+ /** A module's key in the engine worker's cache, the handle's `key`: the sha256 of its original bytes and the ABI it
41
+ * compiles for. The worker mints it from the digest it computed; the client keys its own cache of a pinned sheet's
42
+ * handle by the same spelling of the pin, so the two never drift apart. */
43
+ export function wrunModuleKey(sha256, abi) {
44
+ return `${sha256}|${abi}`;
45
+ }
32
46
  /** A live rows block was refused BEFORE any evaluation because its rows run
33
47
  * backwards relative to the session watermark (or each other). The guest
34
48
  * state is untouched: the session stays valid, so the worker answers a
@@ -3,3 +3,15 @@ export declare function getChartMountEpoch(): number;
3
3
  export declare function bumpChartMountEpoch(): number;
4
4
  /** Captures the epoch now; the returned check reads false once a workspace switch moved it. */
5
5
  export declare function captureMountEpochOwner(): () => boolean;
6
+ /**
7
+ * Resolves once `owner` (a `captureMountEpochOwner` check) reads stale: at
8
+ * once when it already does, else at the bump that moves the epoch. A loop
9
+ * that awaits pane inits races it, so a mount a newer click cancelled returns
10
+ * at the cancel point instead of waiting out inits that build nothing
11
+ * (`mountWorkspaceCharts` in chart-area-bridge.util). `stop` drops the wait
12
+ * once the loop is done.
13
+ */
14
+ export declare function whenMountEpochStale(owner: () => boolean): {
15
+ stale: Promise<void>;
16
+ stop: () => void;
17
+ };
@@ -14,12 +14,16 @@
14
14
  * importing titan-charts (which re-exports both functions for its callers).
15
15
  */
16
16
  let chartMountEpoch = 0;
17
+ /** The waits raced against the epoch (`whenMountEpochStale`), woken at every bump. */
18
+ const bumpListeners = new Set();
17
19
  export function getChartMountEpoch() {
18
20
  return chartMountEpoch;
19
21
  }
20
22
  /** Makes every run or continuation that captured the epoch before this call stale at its next check. */
21
23
  export function bumpChartMountEpoch() {
22
24
  chartMountEpoch += 1;
25
+ for (const listener of [...bumpListeners])
26
+ listener();
23
27
  return chartMountEpoch;
24
28
  }
25
29
  /** Captures the epoch now; the returned check reads false once a workspace switch moved it. */
@@ -27,3 +31,31 @@ export function captureMountEpochOwner() {
27
31
  const epoch = chartMountEpoch;
28
32
  return () => epoch === chartMountEpoch;
29
33
  }
34
+ /**
35
+ * Resolves once `owner` (a `captureMountEpochOwner` check) reads stale: at
36
+ * once when it already does, else at the bump that moves the epoch. A loop
37
+ * that awaits pane inits races it, so a mount a newer click cancelled returns
38
+ * at the cancel point instead of waiting out inits that build nothing
39
+ * (`mountWorkspaceCharts` in chart-area-bridge.util). `stop` drops the wait
40
+ * once the loop is done.
41
+ */
42
+ export function whenMountEpochStale(owner) {
43
+ if (!owner())
44
+ return { stale: Promise.resolve(), stop: () => undefined };
45
+ let listener = () => undefined;
46
+ const stale = new Promise((resolve) => {
47
+ listener = () => {
48
+ if (owner())
49
+ return;
50
+ bumpListeners.delete(listener);
51
+ resolve();
52
+ };
53
+ });
54
+ bumpListeners.add(listener);
55
+ return {
56
+ stale,
57
+ stop: () => {
58
+ bumpListeners.delete(listener);
59
+ },
60
+ };
61
+ }
@@ -24,9 +24,14 @@
24
24
  * (`wrunWarmupSheetReadsCandlesOnly`): its hidden head is candles, so a book, a leg, a feed or a poll lane
25
25
  * would reach the head's bars without their rows.
26
26
  *
27
+ * Every reader takes the module's import list, never the compiled module: the main thread reads the list off the
28
+ * module's handle (`WrunModuleHandle.imports`, which the engine worker's load answered in WebAssembly.Module.imports()
29
+ * order; the main thread holds no WebAssembly.Module), and the worker's ABI host reads the same predicates over
30
+ * `WebAssembly.Module.imports(module)`, so the two sides cannot answer differently for one module.
31
+ *
27
32
  * Pure and worker-safe.
28
33
  */
29
- import { type WrunAbiVersion, type WrunHistoryWarmup } from '../../interfaces/wrun-runtime.interface.js';
34
+ import { type WrunAbiVersion, type WrunHistoryWarmup, type WrunModuleHandle, type WrunModuleImport } from '../../interfaces/wrun-runtime.interface.js';
30
35
  /** The import (the one the shared host links under wrun-6; wrun-bar-count.kit-mirror.spec.ts). */
31
36
  export declare const WRUN6_BAR_IMPORTS: readonly ["wrun:wrun_bar_count"];
32
37
  /** The refusal names a host raises on the row count (a code of the shared host's refusal table). */
@@ -34,12 +39,15 @@ export declare const WRUN6_BAR_REFUSALS: {
34
39
  /** wrun_bar_count called outside state() and finalize(). */
35
40
  readonly phase: "wrun_bar_count_phase";
36
41
  };
37
- /** Whether a module imports the row count (read once per module). */
38
- export declare function wrunModuleImportsBarCount(module: WebAssembly.Module): boolean;
42
+ /** Whether an import list carries the row count: `wrun_bar_count` under the `wrun` module, qualified on both (an
43
+ * import of the same name from another module is not the host's count). */
44
+ export declare function wrunImportsBarCount(imports: readonly WrunModuleImport[]): boolean;
45
+ /** Whether a module imports the row count (read once per handle). */
46
+ export declare function wrunModuleImportsBarCount(module: WrunModuleHandle): boolean;
39
47
  /** Whether a module READS the row count under its ABI: wrun-6 or later and the import declared.
40
48
  * Such a module's live session re-runs every bar when a bar appears; any other keeps the
41
49
  * close-confirm. */
42
- export declare function wrunModuleReadsBarCount(module: WebAssembly.Module, abi: WrunAbiVersion): boolean;
50
+ export declare function wrunModuleReadsBarCount(module: WrunModuleHandle, abi: WrunAbiVersion): boolean;
43
51
  /**
44
52
  * The import names a stamped module may carry: the kit's own list (`WRUN_HISTORY_INDEPENDENT_IMPORTS`,
45
53
  * wrun-history-independence.ts, kit 0.67.1), name for name, read as the kit's decision reads them
@@ -56,9 +64,12 @@ export declare function wrunModuleReadsBarCount(module: WebAssembly.Module, abi:
56
64
  * holds this list to exactly the names it admits).
57
65
  */
58
66
  export declare const WRUN_STAMP_IMPORTS: ReadonlySet<string>;
67
+ /** Whether every import of a list is on the kit's per-bar list (`WRUN_STAMP_IMPORTS`), by name alone (the kit's
68
+ * decision reads the names, whatever module each comes from). */
69
+ export declare function wrunImportsWithinStamp(imports: readonly WrunModuleImport[]): boolean;
59
70
  /** Whether every import of a module is on the kit's per-bar list (`WRUN_STAMP_IMPORTS`), read once per
60
- * module; a module the engine cannot read answers false. */
61
- export declare function wrunStampCorroborated(module: WebAssembly.Module): boolean;
71
+ * handle; a handle without a readable import list answers false. */
72
+ export declare function wrunStampCorroborated(module: WrunModuleHandle): boolean;
62
73
  /** The first sheet fact that reads or draws beyond the bar at hand, in the kit's own words
63
74
  * (`sheet:<fact>[:<name>]`); undefined when the sheet passes. */
64
75
  export declare function wrunStampSheetRefusal(sheet: unknown): string | undefined;
@@ -24,9 +24,14 @@
24
24
  * (`wrunWarmupSheetReadsCandlesOnly`): its hidden head is candles, so a book, a leg, a feed or a poll lane
25
25
  * would reach the head's bars without their rows.
26
26
  *
27
+ * Every reader takes the module's import list, never the compiled module: the main thread reads the list off the
28
+ * module's handle (`WrunModuleHandle.imports`, which the engine worker's load answered in WebAssembly.Module.imports()
29
+ * order; the main thread holds no WebAssembly.Module), and the worker's ABI host reads the same predicates over
30
+ * `WebAssembly.Module.imports(module)`, so the two sides cannot answer differently for one module.
31
+ *
27
32
  * Pure and worker-safe.
28
33
  */
29
- import { abiAtLeast } from '../../interfaces/wrun-runtime.interface.js';
34
+ import { abiAtLeast, } from '../../interfaces/wrun-runtime.interface.js';
30
35
  import { wrunHistoryWarmupOf } from './wrun-declared-warmup.util.js';
31
36
  import { isWrunLegStreamClass } from './wrun-leg-stream-classes.js';
32
37
  /** The import (the one the shared host links under wrun-6; wrun-bar-count.kit-mirror.spec.ts). */
@@ -37,13 +42,18 @@ export const WRUN6_BAR_REFUSALS = {
37
42
  phase: 'wrun_bar_count_phase',
38
43
  };
39
44
  const BAR_COUNT_IMPORT_NAME = WRUN6_BAR_IMPORTS[0].slice('wrun:'.length);
40
- const importsByModule = new WeakMap();
41
- /** Whether a module imports the row count (read once per module). */
45
+ /** Whether an import list carries the row count: `wrun_bar_count` under the `wrun` module, qualified on both (an
46
+ * import of the same name from another module is not the host's count). */
47
+ export function wrunImportsBarCount(imports) {
48
+ return imports.some((entry) => entry.module === 'wrun' && entry.name === BAR_COUNT_IMPORT_NAME);
49
+ }
50
+ const importsByHandle = new WeakMap();
51
+ /** Whether a module imports the row count (read once per handle). */
42
52
  export function wrunModuleImportsBarCount(module) {
43
- let imports = importsByModule.get(module);
53
+ let imports = importsByHandle.get(module);
44
54
  if (imports === undefined) {
45
- imports = WebAssembly.Module.imports(module).some((entry) => entry.module === 'wrun' && entry.name === BAR_COUNT_IMPORT_NAME);
46
- importsByModule.set(module, imports);
55
+ imports = wrunImportsBarCount(module.imports);
56
+ importsByHandle.set(module, imports);
47
57
  }
48
58
  return imports;
49
59
  }
@@ -82,21 +92,26 @@ export const WRUN_STAMP_IMPORTS = new Set([
82
92
  'wrun_param_len',
83
93
  'wrun_param_bytes',
84
94
  ]);
85
- const stampImportsByModule = new WeakMap();
95
+ /** Whether every import of a list is on the kit's per-bar list (`WRUN_STAMP_IMPORTS`), by name alone (the kit's
96
+ * decision reads the names, whatever module each comes from). */
97
+ export function wrunImportsWithinStamp(imports) {
98
+ return imports.every((entry) => WRUN_STAMP_IMPORTS.has(entry.name));
99
+ }
100
+ const stampImportsByHandle = new WeakMap();
86
101
  /** Whether every import of a module is on the kit's per-bar list (`WRUN_STAMP_IMPORTS`), read once per
87
- * module; a module the engine cannot read answers false. */
102
+ * handle; a handle without a readable import list answers false. */
88
103
  export function wrunStampCorroborated(module) {
89
- const known = stampImportsByModule.get(module);
104
+ const known = stampImportsByHandle.get(module);
90
105
  if (known !== undefined)
91
106
  return known;
92
107
  let within = false;
93
108
  try {
94
- within = WebAssembly.Module.imports(module).every((entry) => WRUN_STAMP_IMPORTS.has(entry.name));
109
+ within = wrunImportsWithinStamp(module.imports);
95
110
  }
96
111
  catch {
97
- // Not a module the engine can read: never corroborated.
112
+ // No import list to read: never corroborated.
98
113
  }
99
- stampImportsByModule.set(module, within);
114
+ stampImportsByHandle.set(module, within);
100
115
  return within;
101
116
  }
102
117
  // ---------------------------------------------------------------------------------------------------