@invinite-org/chartlang-runtime 1.2.0 → 1.3.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 (114) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/dist/buildComputeContext.d.ts.map +1 -1
  3. package/dist/buildComputeContext.js +6 -1
  4. package/dist/buildComputeContext.js.map +1 -1
  5. package/dist/createScriptRunner.d.ts.map +1 -1
  6. package/dist/createScriptRunner.js +37 -7
  7. package/dist/createScriptRunner.js.map +1 -1
  8. package/dist/dep/DepRunner.d.ts +7 -0
  9. package/dist/dep/DepRunner.d.ts.map +1 -1
  10. package/dist/dep/DepRunner.js +3 -0
  11. package/dist/dep/DepRunner.js.map +1 -1
  12. package/dist/emit/barcolor.d.ts +44 -0
  13. package/dist/emit/barcolor.d.ts.map +1 -0
  14. package/dist/emit/barcolor.js +40 -0
  15. package/dist/emit/barcolor.js.map +1 -0
  16. package/dist/emit/bgcolor.d.ts +44 -0
  17. package/dist/emit/bgcolor.d.ts.map +1 -0
  18. package/dist/emit/bgcolor.js +45 -0
  19. package/dist/emit/bgcolor.js.map +1 -0
  20. package/dist/emit/index.d.ts +2 -0
  21. package/dist/emit/index.d.ts.map +1 -1
  22. package/dist/emit/index.js +2 -0
  23. package/dist/emit/index.js.map +1 -1
  24. package/dist/emit/plot.d.ts +23 -1
  25. package/dist/emit/plot.d.ts.map +1 -1
  26. package/dist/emit/plot.js +32 -1
  27. package/dist/emit/plot.js.map +1 -1
  28. package/dist/execution/dispose.d.ts.map +1 -1
  29. package/dist/execution/dispose.js +3 -1
  30. package/dist/execution/dispose.js.map +1 -1
  31. package/dist/execution/runComputeStep.d.ts.map +1 -1
  32. package/dist/execution/runComputeStep.js +3 -1
  33. package/dist/execution/runComputeStep.js.map +1 -1
  34. package/dist/inputs/resolveInputs.js +1 -0
  35. package/dist/inputs/resolveInputs.js.map +1 -1
  36. package/dist/persistentStateStore.runtime.d.ts.map +1 -1
  37. package/dist/persistentStateStore.runtime.js +10 -5
  38. package/dist/persistentStateStore.runtime.js.map +1 -1
  39. package/dist/primitives.d.ts +1 -1
  40. package/dist/primitives.d.ts.map +1 -1
  41. package/dist/primitives.js +7 -1
  42. package/dist/primitives.js.map +1 -1
  43. package/dist/request/lowerTf.d.ts.map +1 -1
  44. package/dist/request/lowerTf.js +6 -0
  45. package/dist/request/lowerTf.js.map +1 -1
  46. package/dist/request/requestNamespace.d.ts.map +1 -1
  47. package/dist/request/requestNamespace.js +17 -3
  48. package/dist/request/requestNamespace.js.map +1 -1
  49. package/dist/request/security.d.ts +23 -6
  50. package/dist/request/security.d.ts.map +1 -1
  51. package/dist/request/security.js +64 -29
  52. package/dist/request/security.js.map +1 -1
  53. package/dist/request/securityExprRunner.d.ts +12 -8
  54. package/dist/request/securityExprRunner.d.ts.map +1 -1
  55. package/dist/request/securityExprRunner.js +32 -14
  56. package/dist/request/securityExprRunner.js.map +1 -1
  57. package/dist/ringBuffer.d.ts +19 -0
  58. package/dist/ringBuffer.d.ts.map +1 -1
  59. package/dist/ringBuffer.js +23 -0
  60. package/dist/ringBuffer.js.map +1 -1
  61. package/dist/runtimeContext.d.ts +49 -12
  62. package/dist/runtimeContext.d.ts.map +1 -1
  63. package/dist/runtimeContext.js.map +1 -1
  64. package/dist/state/arrayPersistence.d.ts +48 -0
  65. package/dist/state/arrayPersistence.d.ts.map +1 -0
  66. package/dist/state/arrayPersistence.js +88 -0
  67. package/dist/state/arrayPersistence.js.map +1 -0
  68. package/dist/state/arrayStateSlot.d.ts +78 -0
  69. package/dist/state/arrayStateSlot.d.ts.map +1 -0
  70. package/dist/state/arrayStateSlot.js +116 -0
  71. package/dist/state/arrayStateSlot.js.map +1 -0
  72. package/dist/state/index.d.ts +3 -1
  73. package/dist/state/index.d.ts.map +1 -1
  74. package/dist/state/index.js +3 -1
  75. package/dist/state/index.js.map +1 -1
  76. package/dist/state/lifecycle.d.ts +28 -0
  77. package/dist/state/lifecycle.d.ts.map +1 -1
  78. package/dist/state/lifecycle.js +36 -0
  79. package/dist/state/lifecycle.js.map +1 -1
  80. package/dist/state/stateNamespace.d.ts.map +1 -1
  81. package/dist/state/stateNamespace.js +27 -0
  82. package/dist/state/stateNamespace.js.map +1 -1
  83. package/dist/ta/sessionVolumeProfile.d.ts.map +1 -1
  84. package/dist/ta/sessionVolumeProfile.js +1 -17
  85. package/dist/ta/sessionVolumeProfile.js.map +1 -1
  86. package/dist/time-accessors/civil.d.ts +73 -0
  87. package/dist/time-accessors/civil.d.ts.map +1 -0
  88. package/dist/time-accessors/civil.js +105 -0
  89. package/dist/time-accessors/civil.js.map +1 -0
  90. package/dist/time-accessors/index.d.ts +8 -0
  91. package/dist/time-accessors/index.d.ts.map +1 -0
  92. package/dist/time-accessors/index.js +9 -0
  93. package/dist/time-accessors/index.js.map +1 -0
  94. package/dist/time-accessors/sessionAccessors.d.ts +50 -0
  95. package/dist/time-accessors/sessionAccessors.d.ts.map +1 -0
  96. package/dist/time-accessors/sessionAccessors.js +79 -0
  97. package/dist/time-accessors/sessionAccessors.js.map +1 -0
  98. package/dist/time-accessors/sessionWindow.d.ts +17 -0
  99. package/dist/time-accessors/sessionWindow.d.ts.map +1 -0
  100. package/dist/time-accessors/sessionWindow.js +41 -0
  101. package/dist/time-accessors/sessionWindow.js.map +1 -0
  102. package/dist/time-accessors/timeAccessors.d.ts +54 -0
  103. package/dist/time-accessors/timeAccessors.d.ts.map +1 -0
  104. package/dist/time-accessors/timeAccessors.js +132 -0
  105. package/dist/time-accessors/timeAccessors.js.map +1 -0
  106. package/dist/time-accessors/tzDiagnostic.d.ts +17 -0
  107. package/dist/time-accessors/tzDiagnostic.d.ts.map +1 -0
  108. package/dist/time-accessors/tzDiagnostic.js +34 -0
  109. package/dist/time-accessors/tzDiagnostic.js.map +1 -0
  110. package/dist/time-accessors/tzOffset.d.ts +31 -0
  111. package/dist/time-accessors/tzOffset.d.ts.map +1 -0
  112. package/dist/time-accessors/tzOffset.js +67 -0
  113. package/dist/time-accessors/tzOffset.js.map +1 -0
  114. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,76 @@
1
1
  # @invinite-org/chartlang-runtime
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e620ba8: Add `bgcolor(color, opts?)` and `barcolor(color, opts?)` — Pine-ergonomic
8
+ top-level aliases for the `bg-color` / `bar-color` plot styles. One call
9
+ (`bgcolor(close > open ? "#16a34a" : "#dc2626", { transp: 80 })`) replaces
10
+ the verbose `plot(NaN, { style: { kind: "bg-color", … } })`. Surfaced in the
11
+ generated primitive reference and taught in the chartlang-coding skill.
12
+
13
+ Deliverable 2 (per-bar dynamic color): `PlotEmission` gains an optional
14
+ `colorValue: Color | null` channel; the runtime resolves the `bgcolor` /
15
+ `barcolor` per-bar color into it (omitted on the static `plot` path → wire
16
+ byte-identical, every pinned `plot-hash` untouched), validates it
17
+ (non-empty color string or `null`), and dedups it last-write-wins per
18
+ `(slotId, bar)` like `value`. Adapters prefer `colorValue` over the static
19
+ `style.color` at render time — this precedence is now the normative
20
+ adapter-kit contract (`PlotEmission.colorValue` JSDoc) and is implemented in
21
+ the canvas2d reference renderer (`null` ⇒ paint-nothing gap; omitted ⇒ static
22
+ fallback). The Pine converter emits the real per-bar dynamic color
23
+ (`bgcolor(close > open ? "#16a34a" : "#dc2626")`) instead of a static
24
+ `plot(NaN, …)`, so `bgcolor`/`barcolor` round-trip with per-bar semantics
25
+ intact.
26
+
27
+ - 08cba38: Add `time.*` calendar accessors (`time.year/month/dayofmonth/dayofweek/hour/
28
+ minute/second/timestamp`), a `time.timeClose(t, tz?)` bar-close accessor
29
+ (Pine's `time_close()` = bar start + interval), a `session.isOpen(t, spec, tz?)`
30
+ helper, and an `input.session` kind. Calendar fields are derived from a `Time`
31
+ epoch via the host (authors stay sandboxed — `Date`/`Intl` remain banned). v1
32
+ is UTC + fixed-offset only; exchange-tz/DST is a scoped follow-up. The Pine
33
+ converter lowers `dayofweek` / `time()` / `time_close()` / `input.session`.
34
+ - 1efb49c: Add multi-symbol support to `request.security`. `request.security({ symbol,
35
+ interval })` now reads a **different instrument** (not just a higher
36
+ timeframe), e.g. `request.security({ symbol: "AMEX:SPY", interval: "1D" })`.
37
+ `symbol` is optional (defaults to the chart symbol) and must be a compile-time
38
+ literal (`input.symbol` / `input.enum` resolved). A new `multiSymbol` adapter
39
+ capability gates non-chart-symbol requests: a different-symbol request against
40
+ an adapter declaring `multiSymbol: false` degrades to an all-NaN
41
+ bar/series with a single deduped `multi-symbol-not-supported` diagnostic,
42
+ mirroring `multi-timeframe-not-supported` (the symbol gate precedes the
43
+ timeframe gate, so a both-different request emits only the symbol diagnostic).
44
+ The Pine converter now lowers `request.security("OTHER", tf, expr)`, and the
45
+ `chartlang scaffold-adapter` template advertises `multiSymbol`.
46
+ - 1efb49c: Add `state.array<T>(capacity)` — a persistent, bounded FIFO collection. Push
47
+ many values across bars (`a.push(v)`) into a fixed-capacity ring and read
48
+ them back by element (`a.get(0)` = newest, `a.last()`, `a.size`,
49
+ `a.capacity`, `a.clear()`). Bounded literal capacity keeps it
50
+ serialization-clean. The Pine converter lowers a bounded numeric
51
+ `var array<…>` Camp B ring to it.
52
+
53
+ The compiler guards the capacity: it must be a compile-time numeric literal
54
+ (a `const` numeric binding is accepted) that is a positive integer within
55
+ `MAX_STATE_ARRAY_CAPACITY` (100_000). A non-literal capacity errors
56
+ `state-array-capacity-not-literal`; an out-of-range / non-integer literal
57
+ errors `state-array-capacity-exceeds-max`.
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [189493a]
62
+ - Updated dependencies [8bc628e]
63
+ - Updated dependencies [ab8b218]
64
+ - Updated dependencies [8bc628e]
65
+ - Updated dependencies [ab8b218]
66
+ - Updated dependencies [189493a]
67
+ - Updated dependencies [e620ba8]
68
+ - Updated dependencies [08cba38]
69
+ - Updated dependencies [1efb49c]
70
+ - Updated dependencies [1efb49c]
71
+ - @invinite-org/chartlang-adapter-kit@1.6.0
72
+ - @invinite-org/chartlang-core@1.3.0
73
+
3
74
  ## 1.2.0
4
75
 
5
76
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"buildComputeContext.d.ts","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAO3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,CAsBtE"}
1
+ {"version":3,"file":"buildComputeContext.d.ts","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAQ3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,CA0BtE"}
@@ -1,10 +1,11 @@
1
1
  // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
2
  // See the LICENSE file in the repo root for full license text.
3
- import { alert, draw, hline, plot, ta } from "./primitives.js";
3
+ import { alert, barcolor, bgcolor, draw, hline, plot, ta } from "./primitives.js";
4
4
  import { emitAlertCondition } from "./emit/alertConditionEmission.js";
5
5
  import { buildRuntimeNamespace } from "./emit/logEmission.js";
6
6
  import { buildRequestNamespace } from "./request/index.js";
7
7
  import { buildStateNamespace } from "./state/index.js";
8
+ import { buildSessionNamespace, buildTimeNamespace } from "./time-accessors/index.js";
8
9
  /**
9
10
  * Build the `ComputeContext` the runner hands the compiled script on
10
11
  * every step. Phase 1 returns the runtime's stable `BarView` (identity
@@ -29,12 +30,16 @@ export function buildComputeContext(state) {
29
30
  ta,
30
31
  plot,
31
32
  hline,
33
+ bgcolor,
34
+ barcolor,
32
35
  alert,
33
36
  draw,
34
37
  state: buildStateNamespace(),
35
38
  barstate: state.runtimeContext.views.barstate,
36
39
  syminfo: state.runtimeContext.views.syminfo,
37
40
  timeframe: state.runtimeContext.views.timeframe,
41
+ time: buildTimeNamespace(state.runtimeContext),
42
+ session: buildSessionNamespace(state.runtimeContext),
38
43
  request: buildRequestNamespace(),
39
44
  runtime: buildRuntimeNamespace(state.runtimeContext),
40
45
  };
@@ -1 +1 @@
1
- {"version":3,"file":"buildComputeContext.js","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAK/D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAkB;IAClD,MAAM,IAAI,GAAG;QACT,GAAG,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG;QACzB,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,cAAc;QAC3C,EAAE;QACF,IAAI;QACJ,KAAK;QACL,KAAK;QACL,IAAI;QACJ,KAAK,EAAE,mBAAmB,EAAE;QAC5B,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ;QAC7C,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO;QAC3C,SAAS,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS;QAC/C,OAAO,EAAE,qBAAqB,EAAE;QAChC,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,cAAc,CAAC;KACvD,CAAC;IACF,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,IAAI,CAAC;IAC1D,OAAO;QACH,GAAG,IAAI;QACP,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,CAC3B,kBAAkB,CAAC,KAAK,CAAC,cAAc,EAAE,WAAW,EAAE,KAAK,CAAC;KACnE,CAAC;AACN,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { ComputeContext } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"./createScriptRunner.js\";\nimport { alert, draw, hline, plot, ta } from \"./primitives.js\";\nimport { emitAlertCondition } from \"./emit/alertConditionEmission.js\";\nimport { buildRuntimeNamespace } from \"./emit/logEmission.js\";\nimport { buildRequestNamespace } from \"./request/index.js\";\nimport { buildStateNamespace } from \"./state/index.js\";\n\n/**\n * Build the `ComputeContext` the runner hands the compiled script on\n * every step. Phase 1 returns the runtime's stable `BarView` (identity\n * preserved across bars per PLAN §6.7), the mount-resolved frozen\n * `inputs` record, and the runtime primitive implementations.\n *\n * The `bar` field is the mutable `BarView` typed-narrowed to the\n * readonly `Bar` surface the script sees. Identity is stable, so a\n * `const { bar } = ctx` at the top of `compute` keeps seeing the live\n * scalars without re-binding per bar.\n *\n * @since 0.1\n * @example\n * // import { buildComputeContext } from \"@invinite-org/chartlang-runtime\";\n * // const ctx = buildComputeContext(state);\n * // void ctx.bar.close;\n */\nexport function buildComputeContext(state: RunnerState): ComputeContext {\n const base = {\n bar: state.mainStream.bar,\n inputs: state.runtimeContext.resolvedInputs,\n ta,\n plot,\n hline,\n alert,\n draw,\n state: buildStateNamespace(),\n barstate: state.runtimeContext.views.barstate,\n syminfo: state.runtimeContext.views.syminfo,\n timeframe: state.runtimeContext.views.timeframe,\n request: buildRequestNamespace(),\n runtime: buildRuntimeNamespace(state.runtimeContext),\n };\n if (state.manifest.kind !== \"alertCondition\") return base;\n return {\n ...base,\n signal: (conditionId, fired) =>\n emitAlertCondition(state.runtimeContext, conditionId, fired),\n };\n}\n"]}
1
+ {"version":3,"file":"buildComputeContext.js","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAK/D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEtF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAkB;IAClD,MAAM,IAAI,GAAG;QACT,GAAG,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG;QACzB,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,cAAc;QAC3C,EAAE;QACF,IAAI;QACJ,KAAK;QACL,OAAO;QACP,QAAQ;QACR,KAAK;QACL,IAAI;QACJ,KAAK,EAAE,mBAAmB,EAAE;QAC5B,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ;QAC7C,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO;QAC3C,SAAS,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS;QAC/C,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,cAAc,CAAC;QAC9C,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,cAAc,CAAC;QACpD,OAAO,EAAE,qBAAqB,EAAE;QAChC,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,cAAc,CAAC;KACvD,CAAC;IACF,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,IAAI,CAAC;IAC1D,OAAO;QACH,GAAG,IAAI;QACP,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,CAC3B,kBAAkB,CAAC,KAAK,CAAC,cAAc,EAAE,WAAW,EAAE,KAAK,CAAC;KACnE,CAAC;AACN,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { ComputeContext } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"./createScriptRunner.js\";\nimport { alert, barcolor, bgcolor, draw, hline, plot, ta } from \"./primitives.js\";\nimport { emitAlertCondition } from \"./emit/alertConditionEmission.js\";\nimport { buildRuntimeNamespace } from \"./emit/logEmission.js\";\nimport { buildRequestNamespace } from \"./request/index.js\";\nimport { buildStateNamespace } from \"./state/index.js\";\nimport { buildSessionNamespace, buildTimeNamespace } from \"./time-accessors/index.js\";\n\n/**\n * Build the `ComputeContext` the runner hands the compiled script on\n * every step. Phase 1 returns the runtime's stable `BarView` (identity\n * preserved across bars per PLAN §6.7), the mount-resolved frozen\n * `inputs` record, and the runtime primitive implementations.\n *\n * The `bar` field is the mutable `BarView` typed-narrowed to the\n * readonly `Bar` surface the script sees. Identity is stable, so a\n * `const { bar } = ctx` at the top of `compute` keeps seeing the live\n * scalars without re-binding per bar.\n *\n * @since 0.1\n * @example\n * // import { buildComputeContext } from \"@invinite-org/chartlang-runtime\";\n * // const ctx = buildComputeContext(state);\n * // void ctx.bar.close;\n */\nexport function buildComputeContext(state: RunnerState): ComputeContext {\n const base = {\n bar: state.mainStream.bar,\n inputs: state.runtimeContext.resolvedInputs,\n ta,\n plot,\n hline,\n bgcolor,\n barcolor,\n alert,\n draw,\n state: buildStateNamespace(),\n barstate: state.runtimeContext.views.barstate,\n syminfo: state.runtimeContext.views.syminfo,\n timeframe: state.runtimeContext.views.timeframe,\n time: buildTimeNamespace(state.runtimeContext),\n session: buildSessionNamespace(state.runtimeContext),\n request: buildRequestNamespace(),\n runtime: buildRuntimeNamespace(state.runtimeContext),\n };\n if (state.manifest.kind !== \"alertCondition\") return base;\n return {\n ...base,\n signal: (conditionId, fired) =>\n emitAlertCondition(state.runtimeContext, conditionId, fired),\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createScriptRunner.d.ts","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,eAAe,EAClB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACR,GAAG,EACH,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,EACT,cAAc,EACjB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,aAAa,EAKrB,MAAM,gBAAgB,CAAC;AAexB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAYtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,KAAK,cAAc,EAAuC,MAAM,kBAAkB,CAAC;AAE5F;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG;IACtB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,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AC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjF,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAC7F,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CACnE,CAAC;AAmRF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,YAAY,CA6E7E"}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
2
  // See the LICENSE file in the repo root for full license text.
3
- import { isCompiledScriptBundle } from "@invinite-org/chartlang-core";
3
+ import { feedKey, isCompiledScriptBundle } from "@invinite-org/chartlang-core";
4
4
  import { createDepOutputStore, createDepRunner, createSiblingRunner, installDepOutputGlobal, } from "./dep/index.js";
5
5
  import { pushDiagnostic, resolveDefaultPane, resolveScriptPane } from "./emit/index.js";
6
6
  import { dispose as disposeImpl, drain as drainImpl, onBarClose as onBarCloseImpl, onBarTick as onBarTickImpl, onHistory as onHistoryImpl, } from "./execution/index.js";
@@ -23,12 +23,31 @@ function resolveCapacity(manifest) {
23
23
  // past slot 0 returns NaN (the "forecast line never drawn" bug).
24
24
  return Math.max(1, ohlcv ?? fallback, dynamicFallback ?? 0);
25
25
  }
26
- function createSecondaryStreams(manifest, capacity) {
26
+ // A manifest produced BEFORE the multi-symbol feature has no `requestedFeeds`
27
+ // field but may carry `requestedIntervals`; projecting the interval list to
28
+ // symbol-omitted feeds keeps such a manifest mounting its main-symbol HTF
29
+ // streams. This `requestedFeeds ?? …` fallback is the apiVersion-1
30
+ // forward-compat seam; because `feedKey(undefined, iv) === iv`, the resulting
31
+ // keys equal today's interval keys exactly.
32
+ function legacyFeedsFromIntervals(manifest) {
33
+ return manifest.requestedIntervals.map((interval) => ({ interval }));
34
+ }
35
+ function createSecondaryStreams(manifest, capacity, chartSymbol) {
27
36
  const streams = new Map();
28
- for (const interval of manifest.requestedIntervals) {
29
- if (streams.has(interval))
37
+ const feeds = manifest.requestedFeeds ?? legacyFeedsFromIntervals(manifest);
38
+ for (const feed of feeds) {
39
+ // Collapse a feed whose symbol IS the chart symbol (omitted, or the
40
+ // author passed the chart's own ticker explicitly) to `undefined`
41
+ // BEFORE keying, mirroring `requestNamespace`'s resolution: `feedKey`
42
+ // then yields the bare interval, so both spellings hit one stream and
43
+ // the chart-symbol path stays byte-identical to the baseline. A
44
+ // genuinely different symbol survives as `"<symbol>@<interval>"`.
45
+ const resolved = feed.symbol === undefined || feed.symbol === chartSymbol ? undefined : feed.symbol;
46
+ const key = feedKey(resolved, feed.interval);
47
+ if (streams.has(key))
30
48
  continue;
31
- streams.set(interval, createStreamState({ interval, capacity, symbol: "" }));
49
+ const symbol = feed.symbol ?? chartSymbol;
50
+ streams.set(key, createStreamState({ interval: feed.interval, capacity, symbol }));
32
51
  }
33
52
  return streams;
34
53
  }
@@ -88,8 +107,13 @@ function primaryOf(compiled) {
88
107
  }
89
108
  function buildPrimaryState(args, primary) {
90
109
  const capacity = resolveCapacity(primary.manifest);
110
+ // The chart symbol is the adapter's `syminfo.ticker` when supplied — the
111
+ // single existing mount-time source (the main stream's `symbol` is `""`
112
+ // until bars flow). A symbol-omitted / explicit-chart-symbol request
113
+ // collapses against this value to the bare-interval feed key.
114
+ const chartSymbol = args.symInfo?.ticker ?? "";
91
115
  const mainStream = createStreamState({ interval: "", capacity, symbol: "" });
92
- const secondaryStreams = createSecondaryStreams(primary.manifest, capacity);
116
+ const secondaryStreams = createSecondaryStreams(primary.manifest, capacity, chartSymbol);
93
117
  const stateStore = args.stateStore ?? inMemoryStateStore();
94
118
  const now = args.now ?? Date.now;
95
119
  const views = createRuntimeViews({
@@ -137,12 +161,15 @@ function buildPrimaryState(args, primary) {
137
161
  scriptMaxDrawings: primary.manifest.maxDrawings ?? null,
138
162
  stateSlots: new Map(),
139
163
  seriesSlots: new Map(),
164
+ arraySlots: new Map(),
165
+ chartSymbol,
140
166
  secondaryStreams,
141
167
  requestSecurityBars: new Map(),
142
168
  requestSecurityAlignments: new Map(),
143
169
  requestSecurityAscendingBars: new Map(),
144
170
  requestLowerTfViews: new Map(),
145
171
  diagnosedRequestKeys: new Set(),
172
+ diagnosedTzKeys: new Set(),
146
173
  alertConditions,
147
174
  diagnosedAlertConditionKeys: new Set(),
148
175
  logBudget: 0,
@@ -169,7 +196,7 @@ function buildPrimaryState(args, primary) {
169
196
  Object.freeze({});
170
197
  const exprRunners = buildSecurityExprRunners(primary.manifest, state.runtimeContext, capacity);
171
198
  state.runtimeContext.securityExprRunners = exprRunners.bySlot;
172
- state.runtimeContext.securityExprRunnersByInterval = exprRunners.byInterval;
199
+ state.runtimeContext.securityExprRunnersByFeed = exprRunners.byFeed;
173
200
  state.runtimeContext.requestSecurityExprSeries = new Map();
174
201
  return state;
175
202
  }
@@ -191,10 +218,12 @@ function attachBundle(primary, bundle, capabilities, now) {
191
218
  })),
192
219
  ];
193
220
  const store = createDepOutputStore({ producers, capacity: storeCapacity });
221
+ const { chartSymbol } = primary.runtimeContext;
194
222
  const depRunners = bundle.dependencies.map((entry) => createDepRunner({
195
223
  compiled: entry.compiled,
196
224
  localId: entry.localId,
197
225
  parentCapabilities: capabilities,
226
+ chartSymbol,
198
227
  mainStream: primary.mainStream,
199
228
  secondaryStreams: primary.runtimeContext.secondaryStreams,
200
229
  depOutputStore: store,
@@ -205,6 +234,7 @@ function attachBundle(primary, bundle, capabilities, now) {
205
234
  compiled: entry.compiled,
206
235
  exportName: entry.exportName,
207
236
  parentCapabilities: capabilities,
237
+ chartSymbol,
208
238
  mainStream: primary.mainStream,
209
239
  secondaryStreams: primary.runtimeContext.secondaryStreams,
210
240
  depOutputStore: store,
@@ -1 +1 @@
1
- {"version":3,"file":"createScriptRunner.js","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAe/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAIH,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,EACH,OAAO,IAAI,WAAW,EACtB,KAAK,IAAI,SAAS,EAClB,UAAU,IAAI,cAAc,EAC5B,SAAS,IAAI,aAAa,EAC1B,SAAS,IAAI,aAAa,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EACH,wBAAwB,EACxB,wBAAwB,GAC3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAmB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAoB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAuB,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAyI5F,SAAS,eAAe,CAAC,QAAwB;IAC7C,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAC,gBAAgB,CAAC;IAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,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AE,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,CAAC,OAAO;YACT,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YACxD,WAAW,CAAC,KAAK,CAAC,CAAC;YACnB,MAAM,SAAS,CAAC;QACpB,CAAC;KACJ,CAAC,CAAC;AACP,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type {\n CandleEvent,\n Capabilities,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\nimport type {\n Bar,\n CompiledScriptBundle,\n CompiledScriptObject,\n ComputeFn,\n ScriptManifest,\n} from \"@invinite-org/chartlang-core\";\nimport { isCompiledScriptBundle } from \"@invinite-org/chartlang-core\";\n\nimport {\n type DepOutputStore,\n type DepRunner,\n type SiblingRunner,\n createDepOutputStore,\n createDepRunner,\n createSiblingRunner,\n installDepOutputGlobal,\n} from \"./dep/index.js\";\nimport { pushDiagnostic, resolveDefaultPane, resolveScriptPane } from \"./emit/index.js\";\nimport {\n dispose as disposeImpl,\n drain as drainImpl,\n onBarClose as onBarCloseImpl,\n onBarTick as onBarTickImpl,\n onHistory as onHistoryImpl,\n} from \"./execution/index.js\";\nimport {\n appendSecondaryBar,\n appendSecondaryHistory,\n replaceSecondaryHead,\n} from \"./execution/secondaryStream.js\";\nimport { resolveInputs } from \"./inputs/index.js\";\nimport type { PersistentStateStore } from \"./persistentStateStore.js\";\nimport {\n PERSISTENCE_INTERVAL_MS,\n maybeSaveStateSnapshot,\n restoreStateSnapshot,\n saveStateSnapshot,\n} from \"./persistentStateStore.runtime.js\";\nimport { validateSnapshot } from \"./persistentStateStore.validate.js\";\nimport {\n buildSecurityExprRunners,\n driveSecurityExpressions,\n} from \"./request/securityExprRunner.js\";\nimport type { MutableRunnerEmissions, RuntimeContext } from \"./runtimeContext.js\";\nimport { type StateStore, inMemoryStateStore } from \"./stateStore.js\";\nimport { type StreamState, createStreamState } from \"./streamState.js\";\nimport { type AdapterSymInfo, createRuntimeViews, makeSymInfoView } from \"./views/index.js\";\n\n/**\n * Internal handle the execution functions read and mutate per step. Lives\n * inside `createScriptRunner`'s closure; never exposed on the public\n * barrel. `barIndex` is the only mutable field — `onBarClose` increments\n * it; `onBarTick` does not.\n *\n * @since 0.1\n * @example\n * // RunnerState is internal — execution functions accept it as\n * // their first argument:\n * // await onBarClose(state, rawBar);\n */\nexport type RunnerState = {\n readonly manifest: ScriptManifest;\n readonly compute: ComputeFn;\n readonly capabilities: Capabilities;\n readonly stateStore: StateStore;\n readonly persistenceIntervalMs: number;\n readonly now: () => number;\n readonly mainStream: StreamState;\n readonly runtimeContext: RuntimeContext;\n readonly emissions: MutableRunnerEmissions;\n /**\n * Sub-runners for every private dep entry of a\n * `CompiledScriptBundle`. Empty array for single-script callers.\n * Walked in declaration order before the primary's compute each\n * bar. @since 0.7\n */\n readonly depRunners: ReadonlyArray<DepRunner>;\n /**\n * Sub-runners for every drawn named-export entry of a\n * `CompiledScriptBundle`. Empty for single-script callers.\n * Walked in declaration order after deps, before the primary's\n * compute. @since 0.7\n */\n readonly siblingRunners: ReadonlyArray<SiblingRunner>;\n /**\n * Shared titled-output buffer for the bundle. `null` for\n * single-script callers (no deps to read from). @since 0.7\n */\n readonly depOutputStore: DepOutputStore | null;\n /**\n * Per-bar flag set by `runDepStep` when any dep halts. Read by\n * `onBarClose` / `onBarTick` after the primary's compute returns,\n * clearing the primary's plot/drawing/alert queues. Reset at the\n * top of every bar. @since 0.7\n */\n depErroredThisBar: boolean;\n barIndex: number;\n};\n\n/**\n * The user-facing handle `createScriptRunner` returns. Hosts (Worker,\n * QuickJS, conformance harness) drive a `ScriptRunner` through the\n * standard lifecycle: `load → onHistory → onBarClose × N → onBarTick × M\n * → drain → dispose`. PLAN §6.1 fixes this shape; consumer-repo hosts\n * pin against it.\n *\n * `onHistory` / `onBarClose` / `onBarTick` return `Promise<void>` — the\n * runtime allows compute bodies to `await` (Phase 1 doesn't, but the\n * surface is forward-compatible with Phase-5 `request.security` warmup).\n *\n * @since 0.1\n * @example\n * // import { createScriptRunner }\n * // from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory(historicalBars);\n * // const emissions = runner.drain();\n * // runner.dispose();\n */\nexport type ScriptRunner = {\n onHistory(bars: ReadonlyArray<Bar>): Promise<void>;\n onBarClose(bar: Bar): Promise<void>;\n onBarTick(bar: Bar): Promise<void>;\n push(event: CandleEvent): Promise<void>;\n warmStart(currentMainBarTime: number): Promise<void>;\n drain(): RunnerEmissions;\n /**\n * Replace the per-slot presentation override map live. Cheap and\n * recompute-free — the swap takes effect on the NEXT push's\n * `compute`; the just-pushed bar's drain returns the pre-swap\n * emissions (already baked during that bar's `compute`). Entries\n * are frozen on assignment; overrides are presentation-only and\n * never feed `compute`.\n *\n * @since 0.8\n * @stable\n * @example\n * // runner.setPlotOverrides({ \"ema.chart.ts:12:5#0\": { visible: false } });\n */\n setPlotOverrides(next: Readonly<Record<string, PlotOverride>>): void;\n dispose(): Promise<void>;\n};\n\n/**\n * Constructor arguments for {@link createScriptRunner}. `stateStore`\n * defaults to {@link inMemoryStateStore} so callers without persistence\n * needs can omit it. `symInfo` defaults to empty sentinels and is gated\n * by `capabilities.symInfoFields` at mount. `resolveInputs` is called\n * once at mount with `manifest.name`; worker-backed callers can pass an\n * already structured-cloned `inputOverrides` record instead.\n * `persistentStateStore` is the PLAN §6.9 cross-mount snapshot store;\n * `persistenceIntervalMs` defaults to 60 seconds.\n *\n * @since 0.1\n * @example\n * // const args: CreateScriptRunnerArgs = {\n * // compiled,\n * // capabilities,\n * // stateStore: inMemoryStateStore(),\n * // };\n */\nexport type CreateScriptRunnerArgs = {\n /**\n * Either a single `CompiledScriptObject` (Phase-1 contract — preserved\n * byte-identically) or a `CompiledScriptBundle` whose primary script\n * is mounted alongside one `DepRunner` per private dep entry and one\n * `SiblingRunner` per drawn named export.\n *\n * @since 0.1 — widened to bundle in 0.7\n */\n readonly compiled: CompiledScriptObject | CompiledScriptBundle;\n readonly capabilities: Capabilities;\n readonly stateStore?: StateStore;\n readonly persistentStateStore?: PersistentStateStore;\n readonly persistenceIntervalMs?: number;\n readonly now?: () => number;\n readonly symInfo?: AdapterSymInfo;\n readonly resolveInputs?: (scriptId: string) => Readonly<Record<string, unknown>>;\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n readonly resolvePlotOverrides?: (scriptId: string) => Readonly<Record<string, PlotOverride>>;\n readonly plotOverrides?: Readonly<Record<string, PlotOverride>>;\n};\n\nfunction resolveCapacity(manifest: ScriptManifest): number {\n const { ohlcv, dynamicFallback } = manifest.seriesCapacities;\n const fallback = manifest.maxLookback + 1;\n // `dynamicFallback` is the compiler's §6.6 safety net: a non-literal\n // series index (e.g. `trend[LOOKBACK]` with `const LOOKBACK = 20`)\n // cannot be sized statically, so `extractMaxLookback` emits a 5000-slot\n // request instead of bumping `maxLookback`. Honour it here — otherwise\n // the buffer collapses to `maxLookback + 1` and every dynamic-index read\n // past slot 0 returns NaN (the \"forecast line never drawn\" bug).\n return Math.max(1, ohlcv ?? fallback, dynamicFallback ?? 0);\n}\n\nfunction createSecondaryStreams(\n manifest: ScriptManifest,\n capacity: number,\n): Map<string, StreamState> {\n const streams = new Map<string, StreamState>();\n for (const interval of manifest.requestedIntervals) {\n if (streams.has(interval)) continue;\n streams.set(interval, createStreamState({ interval, capacity, symbol: \"\" }));\n }\n return streams;\n}\n\nasync function pushMainEvent(state: RunnerState, event: CandleEvent): Promise<void> {\n switch (event.kind) {\n case \"history\":\n await onHistoryImpl(state, event.bars);\n return;\n case \"close\":\n await onBarCloseImpl(state, event.bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n return;\n case \"tick\":\n await onBarTickImpl(state, event.bar);\n return;\n }\n}\n\nfunction pushUnknownSecondaryDiagnostic(state: RunnerState, streamKey: string): void {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"unknown-secondary-stream\",\n message: `Secondary stream \"${streamKey}\" was not registered by the script manifest`,\n slotId: null,\n bar: state.barIndex,\n });\n}\n\nfunction pushSecondaryEvent(state: RunnerState, streamKey: string, event: CandleEvent): void {\n const stream = state.runtimeContext.secondaryStreams.get(streamKey);\n if (stream === undefined) {\n pushUnknownSecondaryDiagnostic(state, streamKey);\n return;\n }\n const ctx = state.runtimeContext;\n switch (event.kind) {\n case \"history\":\n // History bars are finalised HTF closes: fill the buffer, then\n // drive every registered runner once per bar in source order (a\n // no-op until the main compute captures the callback).\n appendSecondaryHistory(stream, event.bars);\n for (const bar of event.bars) {\n driveSecurityExpressions(ctx, streamKey, \"close\", bar);\n }\n return;\n case \"close\":\n appendSecondaryBar(stream, event.bar);\n driveSecurityExpressions(ctx, streamKey, \"close\", event.bar);\n return;\n case \"tick\":\n replaceSecondaryHead(stream, event.bar);\n driveSecurityExpressions(ctx, streamKey, \"tick\", event.bar);\n return;\n }\n}\n\nfunction primaryOf(compiled: CompiledScriptObject | CompiledScriptBundle): CompiledScriptObject {\n return isCompiledScriptBundle(compiled) ? compiled.primary : compiled;\n}\n\nfunction buildPrimaryState(\n args: CreateScriptRunnerArgs,\n primary: CompiledScriptObject,\n): RunnerState {\n const capacity = resolveCapacity(primary.manifest);\n const mainStream = createStreamState({ interval: \"\", capacity, symbol: \"\" });\n const secondaryStreams = createSecondaryStreams(primary.manifest, capacity);\n const stateStore = args.stateStore ?? inMemoryStateStore();\n const now = args.now ?? Date.now;\n const views = createRuntimeViews({\n syminfo: makeSymInfoView(args.symInfo ?? {}, args.capabilities.symInfoFields),\n });\n const emissions: MutableRunnerEmissions = {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: 0,\n toBar: 0,\n };\n const alertConditions = new Map(\n (primary.manifest.alertConditions ?? []).map((condition) => [condition.id, condition]),\n );\n\n const state: RunnerState = {\n manifest: primary.manifest,\n compute: primary.compute,\n capabilities: args.capabilities,\n stateStore,\n persistenceIntervalMs: args.persistenceIntervalMs ?? PERSISTENCE_INTERVAL_MS,\n now,\n mainStream,\n runtimeContext: {\n stream: mainStream,\n stateStore,\n ...(args.persistentStateStore === undefined\n ? {}\n : { persistentStateStore: args.persistentStateStore }),\n lastPersistTime: 0,\n capabilities: args.capabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: primary.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n seriesSlots: new Map(),\n secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(primary.manifest),\n scriptPane: resolveScriptPane(primary.manifest),\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: null,\n depErroredThisBar: false,\n barIndex: 0,\n };\n const overrides =\n args.inputOverrides ?? args.resolveInputs?.(primary.manifest.name) ?? Object.freeze({});\n state.runtimeContext.resolvedInputs = resolveInputs(\n primary.manifest,\n overrides,\n state.runtimeContext,\n );\n state.runtimeContext.plotOverrides =\n args.plotOverrides ??\n args.resolvePlotOverrides?.(primary.manifest.name) ??\n Object.freeze({});\n const exprRunners = buildSecurityExprRunners(primary.manifest, state.runtimeContext, capacity);\n state.runtimeContext.securityExprRunners = exprRunners.bySlot;\n state.runtimeContext.securityExprRunnersByInterval = exprRunners.byInterval;\n state.runtimeContext.requestSecurityExprSeries = new Map();\n return state;\n}\n\nfunction attachBundle(\n primary: RunnerState,\n bundle: CompiledScriptBundle,\n capabilities: Capabilities,\n now: () => number,\n): void {\n const consumerLookback = Math.max(\n primary.manifest.maxLookback,\n ...bundle.siblings.map((s) => s.compiled.manifest.maxLookback),\n );\n const storeCapacity = Math.max(1, consumerLookback + 1);\n const producers = [\n ...bundle.dependencies.map((d) => ({\n producerId: d.localId,\n outputs: (d.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ...bundle.siblings.map((s) => ({\n producerId: s.exportName,\n outputs: (s.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ];\n const store = createDepOutputStore({ producers, capacity: storeCapacity });\n const depRunners: DepRunner[] = bundle.dependencies.map((entry) =>\n createDepRunner({\n compiled: entry.compiled,\n localId: entry.localId,\n parentCapabilities: capabilities,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: entry.inputOverrides ?? Object.freeze({}),\n now,\n }),\n );\n const siblingRunners: SiblingRunner[] = bundle.siblings.map((entry) =>\n createSiblingRunner({\n compiled: entry.compiled,\n exportName: entry.exportName,\n parentCapabilities: capabilities,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: Object.freeze({}),\n now,\n }),\n );\n Object.assign(primary, {\n depRunners,\n siblingRunners,\n depOutputStore: store,\n });\n primary.runtimeContext.depOutputStore = store;\n installDepOutputGlobal();\n}\n\n/**\n * Build a `ScriptRunner` for a compiled chartlang script. The runner\n * owns one `StreamState`, one `MutableRunnerEmissions` queue set, and\n * the `RuntimeContext` Task 7-8 primitives read through\n * `ACTIVE_RUNTIME_CONTEXT`. Phase 1 ships a single-stream model; the\n * `requestedIntervals` field on the manifest is always empty.\n *\n * Capacity sizing follows PLAN §6.6: take the max of\n * `manifest.seriesCapacities.ohlcv` (compiler-emitted per-series\n * lookback) or the `manifest.maxLookback + 1` floor, and\n * `manifest.seriesCapacities.dynamicFallback` (the 5000-slot safety net the\n * compiler emits when a series is read at a non-literal index it cannot size\n * statically), clamped to a minimum of 1 so an empty-history script still has\n * a valid head slot.\n *\n * @since 0.1 — widened to accept `CompiledScriptBundle` in 0.7.\n * @example\n * // import { createScriptRunner } from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory([]);\n * // runner.drain();\n * // runner.dispose();\n */\nexport function createScriptRunner(args: CreateScriptRunnerArgs): ScriptRunner {\n const primary = primaryOf(args.compiled);\n const state = buildPrimaryState(args, primary);\n if (isCompiledScriptBundle(args.compiled)) {\n attachBundle(state, args.compiled, args.capabilities, state.now);\n }\n\n return Object.freeze({\n async onHistory(bars) {\n await onHistoryImpl(state, bars);\n },\n async onBarClose(bar) {\n await onBarCloseImpl(state, bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n },\n async onBarTick(bar) {\n await onBarTickImpl(state, bar);\n },\n async push(event) {\n if (event.streamKey === undefined) {\n await pushMainEvent(state, event);\n return;\n }\n pushSecondaryEvent(state, event.streamKey, event);\n },\n async warmStart(currentMainBarTime) {\n const store = state.runtimeContext.persistentStateStore;\n if (store === undefined) return;\n const snap = await store.load();\n if (snap === null) return;\n if (!validateSnapshot(snap)) return;\n if (snap.lastBarTime >= currentMainBarTime) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-future-dated\",\n message: \"persistent state snapshot is ahead of the current bar cursor\",\n slotId: null,\n bar: state.barIndex,\n });\n try {\n await store.clear();\n } catch (err) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-save-failed\",\n message: err instanceof Error ? err.message : String(err),\n slotId: null,\n bar: state.barIndex,\n });\n }\n return;\n }\n restoreStateSnapshot(state, snap);\n state.runtimeContext.lastPersistTime = snap.savedAt;\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"info\",\n code: \"state-snapshot-restored\",\n message: `persistent state snapshot restored through bar ${snap.lastBarTime}`,\n slotId: null,\n bar: state.barIndex,\n });\n },\n drain() {\n return drainImpl(state);\n },\n setPlotOverrides(next) {\n state.runtimeContext.plotOverrides = Object.freeze({ ...next });\n },\n async dispose() {\n const finalSave = saveStateSnapshot(state, state.now());\n disposeImpl(state);\n await finalSave;\n },\n });\n}\n"]}
1
+ {"version":3,"file":"createScriptRunner.js","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAgB/D,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAIH,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,EACH,OAAO,IAAI,WAAW,EACtB,KAAK,IAAI,SAAS,EAClB,UAAU,IAAI,cAAc,EAC5B,SAAS,IAAI,aAAa,EAC1B,SAAS,IAAI,aAAa,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EACH,wBAAwB,EACxB,wBAAwB,GAC3B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAmB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAoB,iBAAiB,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cAAc,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,CAAC,OAAO;YACT,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YACxD,WAAW,CAAC,KAAK,CAAC,CAAC;YACnB,MAAM,SAAS,CAAC;QACpB,CAAC;KACJ,CAAC,CAAC;AACP,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type {\n CandleEvent,\n Capabilities,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\nimport type {\n Bar,\n CompiledScriptBundle,\n CompiledScriptObject,\n ComputeFn,\n RequestedFeed,\n ScriptManifest,\n} from \"@invinite-org/chartlang-core\";\nimport { feedKey, isCompiledScriptBundle } from \"@invinite-org/chartlang-core\";\n\nimport {\n type DepOutputStore,\n type DepRunner,\n type SiblingRunner,\n createDepOutputStore,\n createDepRunner,\n createSiblingRunner,\n installDepOutputGlobal,\n} from \"./dep/index.js\";\nimport { pushDiagnostic, resolveDefaultPane, resolveScriptPane } from \"./emit/index.js\";\nimport {\n dispose as disposeImpl,\n drain as drainImpl,\n onBarClose as onBarCloseImpl,\n onBarTick as onBarTickImpl,\n onHistory as onHistoryImpl,\n} from \"./execution/index.js\";\nimport {\n appendSecondaryBar,\n appendSecondaryHistory,\n replaceSecondaryHead,\n} from \"./execution/secondaryStream.js\";\nimport { resolveInputs } from \"./inputs/index.js\";\nimport type { PersistentStateStore } from \"./persistentStateStore.js\";\nimport {\n PERSISTENCE_INTERVAL_MS,\n maybeSaveStateSnapshot,\n restoreStateSnapshot,\n saveStateSnapshot,\n} from \"./persistentStateStore.runtime.js\";\nimport { validateSnapshot } from \"./persistentStateStore.validate.js\";\nimport {\n buildSecurityExprRunners,\n driveSecurityExpressions,\n} from \"./request/securityExprRunner.js\";\nimport type { MutableRunnerEmissions, RuntimeContext } from \"./runtimeContext.js\";\nimport { type StateStore, inMemoryStateStore } from \"./stateStore.js\";\nimport { type StreamState, createStreamState } from \"./streamState.js\";\nimport { type AdapterSymInfo, createRuntimeViews, makeSymInfoView } from \"./views/index.js\";\n\n/**\n * Internal handle the execution functions read and mutate per step. Lives\n * inside `createScriptRunner`'s closure; never exposed on the public\n * barrel. `barIndex` is the only mutable field — `onBarClose` increments\n * it; `onBarTick` does not.\n *\n * @since 0.1\n * @example\n * // RunnerState is internal — execution functions accept it as\n * // their first argument:\n * // await onBarClose(state, rawBar);\n */\nexport type RunnerState = {\n readonly manifest: ScriptManifest;\n readonly compute: ComputeFn;\n readonly capabilities: Capabilities;\n readonly stateStore: StateStore;\n readonly persistenceIntervalMs: number;\n readonly now: () => number;\n readonly mainStream: StreamState;\n readonly runtimeContext: RuntimeContext;\n readonly emissions: MutableRunnerEmissions;\n /**\n * Sub-runners for every private dep entry of a\n * `CompiledScriptBundle`. Empty array for single-script callers.\n * Walked in declaration order before the primary's compute each\n * bar. @since 0.7\n */\n readonly depRunners: ReadonlyArray<DepRunner>;\n /**\n * Sub-runners for every drawn named-export entry of a\n * `CompiledScriptBundle`. Empty for single-script callers.\n * Walked in declaration order after deps, before the primary's\n * compute. @since 0.7\n */\n readonly siblingRunners: ReadonlyArray<SiblingRunner>;\n /**\n * Shared titled-output buffer for the bundle. `null` for\n * single-script callers (no deps to read from). @since 0.7\n */\n readonly depOutputStore: DepOutputStore | null;\n /**\n * Per-bar flag set by `runDepStep` when any dep halts. Read by\n * `onBarClose` / `onBarTick` after the primary's compute returns,\n * clearing the primary's plot/drawing/alert queues. Reset at the\n * top of every bar. @since 0.7\n */\n depErroredThisBar: boolean;\n barIndex: number;\n};\n\n/**\n * The user-facing handle `createScriptRunner` returns. Hosts (Worker,\n * QuickJS, conformance harness) drive a `ScriptRunner` through the\n * standard lifecycle: `load → onHistory → onBarClose × N → onBarTick × M\n * → drain → dispose`. PLAN §6.1 fixes this shape; consumer-repo hosts\n * pin against it.\n *\n * `onHistory` / `onBarClose` / `onBarTick` return `Promise<void>` — the\n * runtime allows compute bodies to `await` (Phase 1 doesn't, but the\n * surface is forward-compatible with Phase-5 `request.security` warmup).\n *\n * @since 0.1\n * @example\n * // import { createScriptRunner }\n * // from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory(historicalBars);\n * // const emissions = runner.drain();\n * // runner.dispose();\n */\nexport type ScriptRunner = {\n onHistory(bars: ReadonlyArray<Bar>): Promise<void>;\n onBarClose(bar: Bar): Promise<void>;\n onBarTick(bar: Bar): Promise<void>;\n push(event: CandleEvent): Promise<void>;\n warmStart(currentMainBarTime: number): Promise<void>;\n drain(): RunnerEmissions;\n /**\n * Replace the per-slot presentation override map live. Cheap and\n * recompute-free — the swap takes effect on the NEXT push's\n * `compute`; the just-pushed bar's drain returns the pre-swap\n * emissions (already baked during that bar's `compute`). Entries\n * are frozen on assignment; overrides are presentation-only and\n * never feed `compute`.\n *\n * @since 0.8\n * @stable\n * @example\n * // runner.setPlotOverrides({ \"ema.chart.ts:12:5#0\": { visible: false } });\n */\n setPlotOverrides(next: Readonly<Record<string, PlotOverride>>): void;\n dispose(): Promise<void>;\n};\n\n/**\n * Constructor arguments for {@link createScriptRunner}. `stateStore`\n * defaults to {@link inMemoryStateStore} so callers without persistence\n * needs can omit it. `symInfo` defaults to empty sentinels and is gated\n * by `capabilities.symInfoFields` at mount. `resolveInputs` is called\n * once at mount with `manifest.name`; worker-backed callers can pass an\n * already structured-cloned `inputOverrides` record instead.\n * `persistentStateStore` is the PLAN §6.9 cross-mount snapshot store;\n * `persistenceIntervalMs` defaults to 60 seconds.\n *\n * @since 0.1\n * @example\n * // const args: CreateScriptRunnerArgs = {\n * // compiled,\n * // capabilities,\n * // stateStore: inMemoryStateStore(),\n * // };\n */\nexport type CreateScriptRunnerArgs = {\n /**\n * Either a single `CompiledScriptObject` (Phase-1 contract — preserved\n * byte-identically) or a `CompiledScriptBundle` whose primary script\n * is mounted alongside one `DepRunner` per private dep entry and one\n * `SiblingRunner` per drawn named export.\n *\n * @since 0.1 — widened to bundle in 0.7\n */\n readonly compiled: CompiledScriptObject | CompiledScriptBundle;\n readonly capabilities: Capabilities;\n readonly stateStore?: StateStore;\n readonly persistentStateStore?: PersistentStateStore;\n readonly persistenceIntervalMs?: number;\n readonly now?: () => number;\n readonly symInfo?: AdapterSymInfo;\n readonly resolveInputs?: (scriptId: string) => Readonly<Record<string, unknown>>;\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n readonly resolvePlotOverrides?: (scriptId: string) => Readonly<Record<string, PlotOverride>>;\n readonly plotOverrides?: Readonly<Record<string, PlotOverride>>;\n};\n\nfunction resolveCapacity(manifest: ScriptManifest): number {\n const { ohlcv, dynamicFallback } = manifest.seriesCapacities;\n const fallback = manifest.maxLookback + 1;\n // `dynamicFallback` is the compiler's §6.6 safety net: a non-literal\n // series index (e.g. `trend[LOOKBACK]` with `const LOOKBACK = 20`)\n // cannot be sized statically, so `extractMaxLookback` emits a 5000-slot\n // request instead of bumping `maxLookback`. Honour it here — otherwise\n // the buffer collapses to `maxLookback + 1` and every dynamic-index read\n // past slot 0 returns NaN (the \"forecast line never drawn\" bug).\n return Math.max(1, ohlcv ?? fallback, dynamicFallback ?? 0);\n}\n\n// A manifest produced BEFORE the multi-symbol feature has no `requestedFeeds`\n// field but may carry `requestedIntervals`; projecting the interval list to\n// symbol-omitted feeds keeps such a manifest mounting its main-symbol HTF\n// streams. This `requestedFeeds ?? …` fallback is the apiVersion-1\n// forward-compat seam; because `feedKey(undefined, iv) === iv`, the resulting\n// keys equal today's interval keys exactly.\nfunction legacyFeedsFromIntervals(manifest: ScriptManifest): RequestedFeed[] {\n return manifest.requestedIntervals.map((interval) => ({ interval }));\n}\n\nfunction createSecondaryStreams(\n manifest: ScriptManifest,\n capacity: number,\n chartSymbol: string,\n): Map<string, StreamState> {\n const streams = new Map<string, StreamState>();\n const feeds = manifest.requestedFeeds ?? legacyFeedsFromIntervals(manifest);\n for (const feed of feeds) {\n // Collapse a feed whose symbol IS the chart symbol (omitted, or the\n // author passed the chart's own ticker explicitly) to `undefined`\n // BEFORE keying, mirroring `requestNamespace`'s resolution: `feedKey`\n // then yields the bare interval, so both spellings hit one stream and\n // the chart-symbol path stays byte-identical to the baseline. A\n // genuinely different symbol survives as `\"<symbol>@<interval>\"`.\n const resolved =\n feed.symbol === undefined || feed.symbol === chartSymbol ? undefined : feed.symbol;\n const key = feedKey(resolved, feed.interval);\n if (streams.has(key)) continue;\n const symbol = feed.symbol ?? chartSymbol;\n streams.set(key, createStreamState({ interval: feed.interval, capacity, symbol }));\n }\n return streams;\n}\n\nasync function pushMainEvent(state: RunnerState, event: CandleEvent): Promise<void> {\n switch (event.kind) {\n case \"history\":\n await onHistoryImpl(state, event.bars);\n return;\n case \"close\":\n await onBarCloseImpl(state, event.bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n return;\n case \"tick\":\n await onBarTickImpl(state, event.bar);\n return;\n }\n}\n\nfunction pushUnknownSecondaryDiagnostic(state: RunnerState, streamKey: string): void {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"unknown-secondary-stream\",\n message: `Secondary stream \"${streamKey}\" was not registered by the script manifest`,\n slotId: null,\n bar: state.barIndex,\n });\n}\n\nfunction pushSecondaryEvent(state: RunnerState, streamKey: string, event: CandleEvent): void {\n const stream = state.runtimeContext.secondaryStreams.get(streamKey);\n if (stream === undefined) {\n pushUnknownSecondaryDiagnostic(state, streamKey);\n return;\n }\n const ctx = state.runtimeContext;\n switch (event.kind) {\n case \"history\":\n // History bars are finalised HTF closes: fill the buffer, then\n // drive every registered runner once per bar in source order (a\n // no-op until the main compute captures the callback).\n appendSecondaryHistory(stream, event.bars);\n for (const bar of event.bars) {\n driveSecurityExpressions(ctx, streamKey, \"close\", bar);\n }\n return;\n case \"close\":\n appendSecondaryBar(stream, event.bar);\n driveSecurityExpressions(ctx, streamKey, \"close\", event.bar);\n return;\n case \"tick\":\n replaceSecondaryHead(stream, event.bar);\n driveSecurityExpressions(ctx, streamKey, \"tick\", event.bar);\n return;\n }\n}\n\nfunction primaryOf(compiled: CompiledScriptObject | CompiledScriptBundle): CompiledScriptObject {\n return isCompiledScriptBundle(compiled) ? compiled.primary : compiled;\n}\n\nfunction buildPrimaryState(\n args: CreateScriptRunnerArgs,\n primary: CompiledScriptObject,\n): RunnerState {\n const capacity = resolveCapacity(primary.manifest);\n // The chart symbol is the adapter's `syminfo.ticker` when supplied — the\n // single existing mount-time source (the main stream's `symbol` is `\"\"`\n // until bars flow). A symbol-omitted / explicit-chart-symbol request\n // collapses against this value to the bare-interval feed key.\n const chartSymbol = args.symInfo?.ticker ?? \"\";\n const mainStream = createStreamState({ interval: \"\", capacity, symbol: \"\" });\n const secondaryStreams = createSecondaryStreams(primary.manifest, capacity, chartSymbol);\n const stateStore = args.stateStore ?? inMemoryStateStore();\n const now = args.now ?? Date.now;\n const views = createRuntimeViews({\n syminfo: makeSymInfoView(args.symInfo ?? {}, args.capabilities.symInfoFields),\n });\n const emissions: MutableRunnerEmissions = {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: 0,\n toBar: 0,\n };\n const alertConditions = new Map(\n (primary.manifest.alertConditions ?? []).map((condition) => [condition.id, condition]),\n );\n\n const state: RunnerState = {\n manifest: primary.manifest,\n compute: primary.compute,\n capabilities: args.capabilities,\n stateStore,\n persistenceIntervalMs: args.persistenceIntervalMs ?? PERSISTENCE_INTERVAL_MS,\n now,\n mainStream,\n runtimeContext: {\n stream: mainStream,\n stateStore,\n ...(args.persistentStateStore === undefined\n ? {}\n : { persistentStateStore: args.persistentStateStore }),\n lastPersistTime: 0,\n capabilities: args.capabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: primary.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n seriesSlots: new Map(),\n arraySlots: new Map(),\n chartSymbol,\n secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n diagnosedTzKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(primary.manifest),\n scriptPane: resolveScriptPane(primary.manifest),\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: null,\n depErroredThisBar: false,\n barIndex: 0,\n };\n const overrides =\n args.inputOverrides ?? args.resolveInputs?.(primary.manifest.name) ?? Object.freeze({});\n state.runtimeContext.resolvedInputs = resolveInputs(\n primary.manifest,\n overrides,\n state.runtimeContext,\n );\n state.runtimeContext.plotOverrides =\n args.plotOverrides ??\n args.resolvePlotOverrides?.(primary.manifest.name) ??\n Object.freeze({});\n const exprRunners = buildSecurityExprRunners(primary.manifest, state.runtimeContext, capacity);\n state.runtimeContext.securityExprRunners = exprRunners.bySlot;\n state.runtimeContext.securityExprRunnersByFeed = exprRunners.byFeed;\n state.runtimeContext.requestSecurityExprSeries = new Map();\n return state;\n}\n\nfunction attachBundle(\n primary: RunnerState,\n bundle: CompiledScriptBundle,\n capabilities: Capabilities,\n now: () => number,\n): void {\n const consumerLookback = Math.max(\n primary.manifest.maxLookback,\n ...bundle.siblings.map((s) => s.compiled.manifest.maxLookback),\n );\n const storeCapacity = Math.max(1, consumerLookback + 1);\n const producers = [\n ...bundle.dependencies.map((d) => ({\n producerId: d.localId,\n outputs: (d.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ...bundle.siblings.map((s) => ({\n producerId: s.exportName,\n outputs: (s.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ];\n const store = createDepOutputStore({ producers, capacity: storeCapacity });\n const { chartSymbol } = primary.runtimeContext;\n const depRunners: DepRunner[] = bundle.dependencies.map((entry) =>\n createDepRunner({\n compiled: entry.compiled,\n localId: entry.localId,\n parentCapabilities: capabilities,\n chartSymbol,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: entry.inputOverrides ?? Object.freeze({}),\n now,\n }),\n );\n const siblingRunners: SiblingRunner[] = bundle.siblings.map((entry) =>\n createSiblingRunner({\n compiled: entry.compiled,\n exportName: entry.exportName,\n parentCapabilities: capabilities,\n chartSymbol,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: Object.freeze({}),\n now,\n }),\n );\n Object.assign(primary, {\n depRunners,\n siblingRunners,\n depOutputStore: store,\n });\n primary.runtimeContext.depOutputStore = store;\n installDepOutputGlobal();\n}\n\n/**\n * Build a `ScriptRunner` for a compiled chartlang script. The runner\n * owns one `StreamState`, one `MutableRunnerEmissions` queue set, and\n * the `RuntimeContext` Task 7-8 primitives read through\n * `ACTIVE_RUNTIME_CONTEXT`. Phase 1 ships a single-stream model; the\n * `requestedIntervals` field on the manifest is always empty.\n *\n * Capacity sizing follows PLAN §6.6: take the max of\n * `manifest.seriesCapacities.ohlcv` (compiler-emitted per-series\n * lookback) or the `manifest.maxLookback + 1` floor, and\n * `manifest.seriesCapacities.dynamicFallback` (the 5000-slot safety net the\n * compiler emits when a series is read at a non-literal index it cannot size\n * statically), clamped to a minimum of 1 so an empty-history script still has\n * a valid head slot.\n *\n * @since 0.1 — widened to accept `CompiledScriptBundle` in 0.7.\n * @example\n * // import { createScriptRunner } from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory([]);\n * // runner.drain();\n * // runner.dispose();\n */\nexport function createScriptRunner(args: CreateScriptRunnerArgs): ScriptRunner {\n const primary = primaryOf(args.compiled);\n const state = buildPrimaryState(args, primary);\n if (isCompiledScriptBundle(args.compiled)) {\n attachBundle(state, args.compiled, args.capabilities, state.now);\n }\n\n return Object.freeze({\n async onHistory(bars) {\n await onHistoryImpl(state, bars);\n },\n async onBarClose(bar) {\n await onBarCloseImpl(state, bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n },\n async onBarTick(bar) {\n await onBarTickImpl(state, bar);\n },\n async push(event) {\n if (event.streamKey === undefined) {\n await pushMainEvent(state, event);\n return;\n }\n pushSecondaryEvent(state, event.streamKey, event);\n },\n async warmStart(currentMainBarTime) {\n const store = state.runtimeContext.persistentStateStore;\n if (store === undefined) return;\n const snap = await store.load();\n if (snap === null) return;\n if (!validateSnapshot(snap)) return;\n if (snap.lastBarTime >= currentMainBarTime) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-future-dated\",\n message: \"persistent state snapshot is ahead of the current bar cursor\",\n slotId: null,\n bar: state.barIndex,\n });\n try {\n await store.clear();\n } catch (err) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-save-failed\",\n message: err instanceof Error ? err.message : String(err),\n slotId: null,\n bar: state.barIndex,\n });\n }\n return;\n }\n restoreStateSnapshot(state, snap);\n state.runtimeContext.lastPersistTime = snap.savedAt;\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"info\",\n code: \"state-snapshot-restored\",\n message: `persistent state snapshot restored through bar ${snap.lastBarTime}`,\n slotId: null,\n bar: state.barIndex,\n });\n },\n drain() {\n return drainImpl(state);\n },\n setPlotOverrides(next) {\n state.runtimeContext.plotOverrides = Object.freeze({ ...next });\n },\n async dispose() {\n const finalSave = saveStateSnapshot(state, state.now());\n disposeImpl(state);\n await finalSave;\n },\n });\n}\n"]}
@@ -72,6 +72,13 @@ export type SiblingRunner = Readonly<{
72
72
  export type CreateDepRunnerArgs = Readonly<{
73
73
  readonly compiled: CompiledScriptObject;
74
74
  readonly parentCapabilities: Capabilities;
75
+ /**
76
+ * The bundle's chart symbol (the parent runner's resolved
77
+ * `syminfo.ticker`). A `request.security` inside a dep / sibling resolves a
78
+ * symbol-omitted / explicit-chart-symbol request against it, exactly like
79
+ * the primary runner. @since 1.4
80
+ */
81
+ readonly chartSymbol: string;
75
82
  readonly mainStream: StreamState;
76
83
  readonly secondaryStreams: Map<string, StreamState>;
77
84
  readonly depOutputStore: DepOutputStore;
@@ -1 +1 @@
1
- {"version":3,"file":"DepRunner.d.ts","sourceRoot":"","sources":["../../src/dep/DepRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAE9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAO5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAO1D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC/B,CAAC,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;;;GAaG;AACH,wBAAsB,cAAc,CAChC,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,GAAG,EACX,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,OAAO,GAChB,OAAO,CAAC,IAAI,CAAC,CAyBf"}
@@ -51,12 +51,15 @@ function buildSubRunnerState(args, slotIdPrefix, isDep) {
51
51
  scriptMaxDrawings: args.compiled.manifest.maxDrawings ?? null,
52
52
  stateSlots: new Map(),
53
53
  seriesSlots: new Map(),
54
+ arraySlots: new Map(),
55
+ chartSymbol: args.chartSymbol,
54
56
  secondaryStreams: args.secondaryStreams,
55
57
  requestSecurityBars: new Map(),
56
58
  requestSecurityAlignments: new Map(),
57
59
  requestSecurityAscendingBars: new Map(),
58
60
  requestLowerTfViews: new Map(),
59
61
  diagnosedRequestKeys: new Set(),
62
+ diagnosedTzKeys: new Set(),
60
63
  alertConditions,
61
64
  diagnosedAlertConditionKeys: new Set(),
62
65
  logBudget: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"DepRunner.js","sourceRoot":"","sources":["../../src/dep/DepRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAM/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAGH,sBAAsB,GACzB,MAAM,qBAAqB,CAAC;AA+E7B,SAAS,cAAc,CAAC,QAAgB;IACpC,OAAO;QACH,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;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AAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,EAAE;YACV,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;SAC9B,CAAC,CAAC;QACH,2DAA2D;IAC/D,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,sBAAsB,CAClB,iBAAiB,CAAC,OAAO,CAAC,EAC1B,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,cAAc,CAC7B,CAAC;AACN,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { Capabilities } from \"@invinite-org/chartlang-adapter-kit\";\nimport type { Bar, CompiledScriptObject } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"../createScriptRunner.js\";\nimport { pushDiagnostic } from \"../emit/emissionsQueue.js\";\nimport { resolveDefaultPane, resolveScriptPane } from \"../emit/paneResolver.js\";\nimport { resetBarEmissions, runComputeBody } from \"../execution/runComputeStep.js\";\nimport { resolveInputs } from \"../inputs/resolveInputs.js\";\nimport type { MutableRunnerEmissions } from \"../runtimeContext.js\";\nimport { inMemoryStateStore } from \"../stateStore.js\";\nimport type { StreamState } from \"../streamState.js\";\nimport { createRuntimeViews } from \"../views/index.js\";\nimport type { EventKind } from \"../views/index.js\";\nimport type { DepOutputStore } from \"./DepOutputStore.js\";\nimport {\n type DepRunnerLike,\n type SiblingRunnerLike,\n applyDepEmissionPolicy,\n} from \"./emissionFilter.js\";\n\n/**\n * One mounted private dep — a `const X = defineIndicator(...)` binding\n * that another script in the same compiled bundle references via\n * `X.output(\"title\")`. Owns its own `RunnerState`; shares the parent's\n * `mainStream` + `secondaryStreams`. Plot emissions are dropped from\n * the parent's queue and captured into the shared\n * {@link DepOutputStore}.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\", ... });\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type DepRunner = Readonly<{\n readonly kind: \"dep\";\n readonly localId: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * One mounted drawn sibling — a `export const X = defineIndicator(...)`\n * binding whose emissions ARE forwarded to the parent's queue, with\n * slot ids prefixed by `export:<exportName>/`. Siblings can also expose\n * outputs consumed by the primary or by other siblings.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * // await runSiblingStep(sib, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type SiblingRunner = Readonly<{\n readonly kind: \"sibling\";\n readonly exportName: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * Constructor arguments for {@link createDepRunner} /\n * {@link createSiblingRunner}.\n *\n * `mainStream` + `secondaryStreams` are SHARED with the parent runner\n * (same OHLCV history); `depOutputStore` is also shared so every\n * sibling + dep + primary read from the same store. `inputOverrides`\n * is the merged effective-inputs record the compiler attached to the\n * dep's `DependencyDeclaration`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const args: CreateDepRunnerArgs = {\n * // compiled, localId: \"x\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: {}, now: Date.now,\n * // };\n * const x: number = 1;\n * void x;\n */\nexport type CreateDepRunnerArgs = Readonly<{\n readonly compiled: CompiledScriptObject;\n readonly parentCapabilities: Capabilities;\n readonly mainStream: StreamState;\n readonly secondaryStreams: Map<string, StreamState>;\n readonly depOutputStore: DepOutputStore;\n readonly inputOverrides: Readonly<Record<string, unknown>>;\n readonly now: () => number;\n}>;\n\nfunction freshEmissions(barIndex: number): MutableRunnerEmissions {\n return {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: barIndex,\n toBar: barIndex,\n };\n}\n\nfunction buildSubRunnerState(\n args: CreateDepRunnerArgs,\n slotIdPrefix: string,\n isDep: boolean,\n): RunnerState {\n const stateStore = inMemoryStateStore();\n const emissions = freshEmissions(0);\n const alertConditions = new Map(\n (args.compiled.manifest.alertConditions ?? []).map((c) => [c.id, c]),\n );\n const state: RunnerState = {\n manifest: args.compiled.manifest,\n compute: args.compiled.compute,\n capabilities: args.parentCapabilities,\n stateStore,\n persistenceIntervalMs: Number.POSITIVE_INFINITY,\n now: args.now,\n mainStream: args.mainStream,\n runtimeContext: {\n stream: args.mainStream,\n stateStore,\n lastPersistTime: 0,\n capabilities: args.parentCapabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: args.compiled.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n seriesSlots: new Map(),\n secondaryStreams: args.secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(args.compiled.manifest),\n scriptPane: resolveScriptPane(args.compiled.manifest),\n // Overrides target the primary script's slots only in v1;\n // dep-output plots are not host-overridable.\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views: createRuntimeViews(),\n slotIdPrefix,\n isDep,\n depOutputStore: args.depOutputStore,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: args.depOutputStore,\n depErroredThisBar: false,\n barIndex: 0,\n };\n state.runtimeContext.resolvedInputs = resolveInputs(\n args.compiled.manifest,\n args.inputOverrides,\n state.runtimeContext,\n );\n return state;\n}\n\nfunction declaredOutputTitles(compiled: CompiledScriptObject): ReadonlyArray<string> {\n return (compiled.manifest.outputs ?? []).map((o) => o.title);\n}\n\n/**\n * Construct a {@link DepRunner} for one private dep entry of a\n * `CompiledScriptBundle`. The runner shares the parent's `mainStream`\n * + `secondaryStreams`, owns a fresh `inMemoryStateStore`, and feeds\n * its plot emissions into the shared `DepOutputStore`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: { length: 20 }, now: Date.now });\n * const x: number = 1;\n * void x;\n */\nexport function createDepRunner(\n args: CreateDepRunnerArgs & { readonly localId: string },\n): DepRunner {\n const slotIdPrefix = `dep:${args.localId}/`;\n return Object.freeze({\n kind: \"dep\" as const,\n localId: args.localId,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, true),\n });\n}\n\n/**\n * Construct a {@link SiblingRunner} for one drawn named-export entry of\n * a `CompiledScriptBundle`. Shares streams + store with the parent;\n * emissions forward to the parent with `export:<exportName>/` slot-id\n * prefixes.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * const x: number = 1;\n * void x;\n */\nexport function createSiblingRunner(\n args: CreateDepRunnerArgs & { readonly exportName: string },\n): SiblingRunner {\n const slotIdPrefix = `export:${args.exportName}/`;\n return Object.freeze({\n kind: \"sibling\" as const,\n exportName: args.exportName,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, false),\n });\n}\n\nfunction depRunnerLike(dep: DepRunner): DepRunnerLike {\n return {\n kind: \"dep\",\n localId: dep.localId,\n slotIdPrefix: dep.slotIdPrefix,\n declaredOutputs: dep.declaredOutputs,\n emissions: dep.state.emissions,\n };\n}\n\nfunction siblingRunnerLike(sib: SiblingRunner): SiblingRunnerLike {\n return {\n kind: \"sibling\",\n exportName: sib.exportName,\n slotIdPrefix: sib.slotIdPrefix,\n declaredOutputs: sib.declaredOutputs,\n emissions: sib.state.emissions,\n };\n}\n\nasync function executeSubStep(\n state: RunnerState,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<{ readonly halted: boolean; readonly message: string }> {\n resetBarEmissions(state);\n try {\n const outcome = await runComputeBody({ state, eventKind, isTick });\n return outcome.kind === \"halt\"\n ? { halted: true, message: outcome.message }\n : { halted: false, message: \"\" };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { halted: true, message };\n }\n}\n\n/**\n * Drive one bar of execution for a {@link DepRunner}. Runs the dep's\n * `compute`, captures its titled-plot output into the shared\n * `DepOutputStore` via {@link applyDepEmissionPolicy}, namespaces\n * diagnostics with `dep:<localId>/`, and on halt sets\n * `parentState.depErroredThisBar = true` so the parent's primary\n * step drops its emissions for the bar (per task spec §6).\n *\n * @since 0.7\n * @stable\n * @example\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runDepStep(\n dep: DepRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runDepStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(dep.state, eventKind, isTick);\n if (result.halted) {\n // Use an empty slot id so the filter's prefix call produces the\n // runner's slotIdPrefix (`dep:<localId>/`) — preserves the\n // distinguished slotId in the parent's diagnostic queue.\n pushDiagnostic(dep.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: dep.state.barIndex,\n });\n parentState.depErroredThisBar = true;\n }\n if (!isTick) {\n dep.state.barIndex += 1;\n }\n applyDepEmissionPolicy(depRunnerLike(dep), parentState.emissions, parentState.depOutputStore);\n}\n\n/**\n * Drive one bar of execution for a {@link SiblingRunner}. Same shape\n * as {@link runDepStep} but the sibling's emissions are forwarded to\n * the parent with `export:<exportName>/` slot-id prefixes, and a\n * sibling halt does NOT clear the primary's emissions — only the\n * sibling's own bar emissions are lost.\n *\n * @since 0.7\n * @stable\n * @example\n * // await runSiblingStep(sibling, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runSiblingStep(\n sibling: SiblingRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runSiblingStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(sibling.state, eventKind, isTick);\n if (result.halted) {\n pushDiagnostic(sibling.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: sibling.state.barIndex,\n });\n // sibling halt does NOT set parentState.depErroredThisBar.\n }\n if (!isTick) {\n sibling.state.barIndex += 1;\n }\n applyDepEmissionPolicy(\n siblingRunnerLike(sibling),\n parentState.emissions,\n parentState.depOutputStore,\n );\n}\n"]}
1
+ {"version":3,"file":"DepRunner.js","sourceRoot":"","sources":["../../src/dep/DepRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAM/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAGH,sBAAsB,GACzB,MAAM,qBAAqB,CAA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AAS,EAAE,MAAM,CAAC,CAAC;IACtE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChB,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE;YACpC,IAAI,EAAE,YAAY;YAClB,QAAQ,EAAE,OAAO;YACjB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,EAAE;YACV,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;SAC9B,CAAC,CAAC;QACH,2DAA2D;IAC/D,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,sBAAsB,CAClB,iBAAiB,CAAC,OAAO,CAAC,EAC1B,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,cAAc,CAC7B,CAAC;AACN,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { Capabilities } from \"@invinite-org/chartlang-adapter-kit\";\nimport type { Bar, CompiledScriptObject } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"../createScriptRunner.js\";\nimport { pushDiagnostic } from \"../emit/emissionsQueue.js\";\nimport { resolveDefaultPane, resolveScriptPane } from \"../emit/paneResolver.js\";\nimport { resetBarEmissions, runComputeBody } from \"../execution/runComputeStep.js\";\nimport { resolveInputs } from \"../inputs/resolveInputs.js\";\nimport type { MutableRunnerEmissions } from \"../runtimeContext.js\";\nimport { inMemoryStateStore } from \"../stateStore.js\";\nimport type { StreamState } from \"../streamState.js\";\nimport { createRuntimeViews } from \"../views/index.js\";\nimport type { EventKind } from \"../views/index.js\";\nimport type { DepOutputStore } from \"./DepOutputStore.js\";\nimport {\n type DepRunnerLike,\n type SiblingRunnerLike,\n applyDepEmissionPolicy,\n} from \"./emissionFilter.js\";\n\n/**\n * One mounted private dep — a `const X = defineIndicator(...)` binding\n * that another script in the same compiled bundle references via\n * `X.output(\"title\")`. Owns its own `RunnerState`; shares the parent's\n * `mainStream` + `secondaryStreams`. Plot emissions are dropped from\n * the parent's queue and captured into the shared\n * {@link DepOutputStore}.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\", ... });\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type DepRunner = Readonly<{\n readonly kind: \"dep\";\n readonly localId: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * One mounted drawn sibling — a `export const X = defineIndicator(...)`\n * binding whose emissions ARE forwarded to the parent's queue, with\n * slot ids prefixed by `export:<exportName>/`. Siblings can also expose\n * outputs consumed by the primary or by other siblings.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * // await runSiblingStep(sib, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type SiblingRunner = Readonly<{\n readonly kind: \"sibling\";\n readonly exportName: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * Constructor arguments for {@link createDepRunner} /\n * {@link createSiblingRunner}.\n *\n * `mainStream` + `secondaryStreams` are SHARED with the parent runner\n * (same OHLCV history); `depOutputStore` is also shared so every\n * sibling + dep + primary read from the same store. `inputOverrides`\n * is the merged effective-inputs record the compiler attached to the\n * dep's `DependencyDeclaration`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const args: CreateDepRunnerArgs = {\n * // compiled, localId: \"x\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: {}, now: Date.now,\n * // };\n * const x: number = 1;\n * void x;\n */\nexport type CreateDepRunnerArgs = Readonly<{\n readonly compiled: CompiledScriptObject;\n readonly parentCapabilities: Capabilities;\n /**\n * The bundle's chart symbol (the parent runner's resolved\n * `syminfo.ticker`). A `request.security` inside a dep / sibling resolves a\n * symbol-omitted / explicit-chart-symbol request against it, exactly like\n * the primary runner. @since 1.4\n */\n readonly chartSymbol: string;\n readonly mainStream: StreamState;\n readonly secondaryStreams: Map<string, StreamState>;\n readonly depOutputStore: DepOutputStore;\n readonly inputOverrides: Readonly<Record<string, unknown>>;\n readonly now: () => number;\n}>;\n\nfunction freshEmissions(barIndex: number): MutableRunnerEmissions {\n return {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: barIndex,\n toBar: barIndex,\n };\n}\n\nfunction buildSubRunnerState(\n args: CreateDepRunnerArgs,\n slotIdPrefix: string,\n isDep: boolean,\n): RunnerState {\n const stateStore = inMemoryStateStore();\n const emissions = freshEmissions(0);\n const alertConditions = new Map(\n (args.compiled.manifest.alertConditions ?? []).map((c) => [c.id, c]),\n );\n const state: RunnerState = {\n manifest: args.compiled.manifest,\n compute: args.compiled.compute,\n capabilities: args.parentCapabilities,\n stateStore,\n persistenceIntervalMs: Number.POSITIVE_INFINITY,\n now: args.now,\n mainStream: args.mainStream,\n runtimeContext: {\n stream: args.mainStream,\n stateStore,\n lastPersistTime: 0,\n capabilities: args.parentCapabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: args.compiled.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n seriesSlots: new Map(),\n arraySlots: new Map(),\n chartSymbol: args.chartSymbol,\n secondaryStreams: args.secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n diagnosedTzKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(args.compiled.manifest),\n scriptPane: resolveScriptPane(args.compiled.manifest),\n // Overrides target the primary script's slots only in v1;\n // dep-output plots are not host-overridable.\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views: createRuntimeViews(),\n slotIdPrefix,\n isDep,\n depOutputStore: args.depOutputStore,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: args.depOutputStore,\n depErroredThisBar: false,\n barIndex: 0,\n };\n state.runtimeContext.resolvedInputs = resolveInputs(\n args.compiled.manifest,\n args.inputOverrides,\n state.runtimeContext,\n );\n return state;\n}\n\nfunction declaredOutputTitles(compiled: CompiledScriptObject): ReadonlyArray<string> {\n return (compiled.manifest.outputs ?? []).map((o) => o.title);\n}\n\n/**\n * Construct a {@link DepRunner} for one private dep entry of a\n * `CompiledScriptBundle`. The runner shares the parent's `mainStream`\n * + `secondaryStreams`, owns a fresh `inMemoryStateStore`, and feeds\n * its plot emissions into the shared `DepOutputStore`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: { length: 20 }, now: Date.now });\n * const x: number = 1;\n * void x;\n */\nexport function createDepRunner(\n args: CreateDepRunnerArgs & { readonly localId: string },\n): DepRunner {\n const slotIdPrefix = `dep:${args.localId}/`;\n return Object.freeze({\n kind: \"dep\" as const,\n localId: args.localId,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, true),\n });\n}\n\n/**\n * Construct a {@link SiblingRunner} for one drawn named-export entry of\n * a `CompiledScriptBundle`. Shares streams + store with the parent;\n * emissions forward to the parent with `export:<exportName>/` slot-id\n * prefixes.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * const x: number = 1;\n * void x;\n */\nexport function createSiblingRunner(\n args: CreateDepRunnerArgs & { readonly exportName: string },\n): SiblingRunner {\n const slotIdPrefix = `export:${args.exportName}/`;\n return Object.freeze({\n kind: \"sibling\" as const,\n exportName: args.exportName,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, false),\n });\n}\n\nfunction depRunnerLike(dep: DepRunner): DepRunnerLike {\n return {\n kind: \"dep\",\n localId: dep.localId,\n slotIdPrefix: dep.slotIdPrefix,\n declaredOutputs: dep.declaredOutputs,\n emissions: dep.state.emissions,\n };\n}\n\nfunction siblingRunnerLike(sib: SiblingRunner): SiblingRunnerLike {\n return {\n kind: \"sibling\",\n exportName: sib.exportName,\n slotIdPrefix: sib.slotIdPrefix,\n declaredOutputs: sib.declaredOutputs,\n emissions: sib.state.emissions,\n };\n}\n\nasync function executeSubStep(\n state: RunnerState,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<{ readonly halted: boolean; readonly message: string }> {\n resetBarEmissions(state);\n try {\n const outcome = await runComputeBody({ state, eventKind, isTick });\n return outcome.kind === \"halt\"\n ? { halted: true, message: outcome.message }\n : { halted: false, message: \"\" };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { halted: true, message };\n }\n}\n\n/**\n * Drive one bar of execution for a {@link DepRunner}. Runs the dep's\n * `compute`, captures its titled-plot output into the shared\n * `DepOutputStore` via {@link applyDepEmissionPolicy}, namespaces\n * diagnostics with `dep:<localId>/`, and on halt sets\n * `parentState.depErroredThisBar = true` so the parent's primary\n * step drops its emissions for the bar (per task spec §6).\n *\n * @since 0.7\n * @stable\n * @example\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runDepStep(\n dep: DepRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runDepStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(dep.state, eventKind, isTick);\n if (result.halted) {\n // Use an empty slot id so the filter's prefix call produces the\n // runner's slotIdPrefix (`dep:<localId>/`) — preserves the\n // distinguished slotId in the parent's diagnostic queue.\n pushDiagnostic(dep.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: dep.state.barIndex,\n });\n parentState.depErroredThisBar = true;\n }\n if (!isTick) {\n dep.state.barIndex += 1;\n }\n applyDepEmissionPolicy(depRunnerLike(dep), parentState.emissions, parentState.depOutputStore);\n}\n\n/**\n * Drive one bar of execution for a {@link SiblingRunner}. Same shape\n * as {@link runDepStep} but the sibling's emissions are forwarded to\n * the parent with `export:<exportName>/` slot-id prefixes, and a\n * sibling halt does NOT clear the primary's emissions — only the\n * sibling's own bar emissions are lost.\n *\n * @since 0.7\n * @stable\n * @example\n * // await runSiblingStep(sibling, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runSiblingStep(\n sibling: SiblingRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runSiblingStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(sibling.state, eventKind, isTick);\n if (result.halted) {\n pushDiagnostic(sibling.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: sibling.state.barIndex,\n });\n // sibling halt does NOT set parentState.depErroredThisBar.\n }\n if (!isTick) {\n sibling.state.barIndex += 1;\n }\n applyDepEmissionPolicy(\n siblingRunnerLike(sibling),\n parentState.emissions,\n parentState.depOutputStore,\n );\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import type { BarColorOpts, Color } from "@invinite-org/chartlang-core";
2
+ /**
3
+ * Tint the candle / bar for the current bar — the runtime impl of the
4
+ * Pine-ergonomic `barcolor` alias (script-facing overload).
5
+ *
6
+ * Same dual-signature contract as {@link plot}: scripts call
7
+ * `barcolor(color, opts?)`; the compiler's callsite-id transformer rewrites
8
+ * every call to `barcolor(slotId, color, opts?)` (the sibling overload).
9
+ * Direct invocation without a slot id throws the sentinel error.
10
+ *
11
+ * `barcolor` is Pine-ergonomic sugar — it builds the `bar-color` `PlotStyle`
12
+ * and dispatches to the shared {@link plotImpl} with `value = NaN` (→ wire
13
+ * `value: null`). The per-bar color rides the wire as
14
+ * `PlotEmission.colorValue` (the dynamic-color channel), so a single call
15
+ * recolors every bar by that bar's evaluated color; the static `style.color`
16
+ * remains the fallback. Adapters that do not declare the `bar-color`
17
+ * capability drop it with `unsupported-plot-kind`.
18
+ *
19
+ * @since 1.4
20
+ * @example
21
+ * import { defineIndicator, barcolor } from "@invinite-org/chartlang-core";
22
+ * export default defineIndicator({
23
+ * name: "Tint",
24
+ * apiVersion: 1,
25
+ * compute({ bar }) {
26
+ * barcolor(bar.close > bar.open ? "#16a34a" : "#dc2626");
27
+ * },
28
+ * });
29
+ */
30
+ export declare function barcolor(color: Color, opts?: BarColorOpts): void;
31
+ /**
32
+ * Tint the candle / bar for the current bar (compiler-injected overload).
33
+ * The callsite-id transformer rewrites script-side `barcolor(color, opts?)`
34
+ * into `barcolor(slotId, color, opts?)`.
35
+ *
36
+ * @since 1.4
37
+ * @example
38
+ * // Internal — the compiler rewrites every script callsite, e.g.
39
+ * // `barcolor("#000")` becomes `barcolor("demo.chart.ts:5:9#0", "#000")`.
40
+ * // const fn: typeof barcolor = barcolor;
41
+ * // void fn;
42
+ */
43
+ export declare function barcolor(slotId: string, color: Color, opts?: BarColorOpts): void;
44
+ //# sourceMappingURL=barcolor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barcolor.d.ts","sourceRoot":"","sources":["../../src/emit/barcolor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAY,MAAM,8BAA8B,CAAC;AAuBlF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;AAClE;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC"}