@orangecharts/wrun-chart-host 0.19.1 → 0.20.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 (55) hide show
  1. package/README.md +1 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/settings-templates/frvp-fields.js +9 -3
  5. package/dist/settings-templates/index.d.ts +29 -4
  6. package/dist/settings-templates/index.js +82 -27
  7. package/dist/settings-templates/indicator-fields.d.ts +11 -0
  8. package/dist/settings-templates/indicator-fields.js +5 -4
  9. package/dist/settings-templates/market-bound.d.ts +93 -20
  10. package/dist/settings-templates/market-bound.js +229 -41
  11. package/dist/settings-templates/tool-rules.d.ts +197 -18
  12. package/dist/settings-templates/tool-rules.js +98 -4
  13. package/dist/settings-templates/tool-tables.generated.d.ts +2 -0
  14. package/dist/settings-templates/tool-tables.generated.js +194 -11
  15. package/dist/utility/chart/calendar-interval.util.d.ts +7 -0
  16. package/dist/utility/chart/calendar-interval.util.js +9 -0
  17. package/dist/utility/chart/index-mode.util.d.ts +11 -0
  18. package/dist/utility/chart/index-mode.util.js +24 -0
  19. package/dist/utility/chart/indicator-run-interval.util.d.ts +7 -3
  20. package/dist/utility/chart/indicator-run-interval.util.js +16 -5
  21. package/dist/utility/chart/market-session-schedule.util.d.ts +2 -0
  22. package/dist/utility/chart/market-session-schedule.util.js +2 -0
  23. package/dist/utility/chart/run-interval-warmup.leaf.d.ts +16 -1
  24. package/dist/utility/chart/run-interval-warmup.leaf.js +28 -2
  25. package/dist/utility/options/option-contract-market.leaf.d.ts +2 -0
  26. package/dist/utility/options/option-contract-market.leaf.js +21 -0
  27. package/dist/utility/options/option-trade-units.util.d.ts +35 -5
  28. package/dist/utility/options/option-trade-units.util.js +31 -5
  29. package/dist/utility/wrun/wrun-chart-market-facts.util.js +3 -3
  30. package/dist/utility/wrun/wrun-color-settings.util.d.ts +2 -13
  31. package/dist/utility/wrun/wrun-color-settings.util.js +3 -29
  32. package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +1 -1
  33. package/dist/utility/wrun/wrun-lane-warmup.util.js +8 -3
  34. package/dist/utility/wrun/wrun-live-intake.util.js +13 -6
  35. package/dist/utility/wrun/wrun-live-tick.util.js +35 -18
  36. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +34 -1
  37. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +57 -0
  38. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +76 -13
  39. package/dist/utility/wrun/wrun-market-size-defaults.util.js +286 -45
  40. package/dist/utility/wrun/wrun-market-size-rank.leaf.d.ts +75 -0
  41. package/dist/utility/wrun/wrun-market-size-rank.leaf.js +154 -0
  42. package/dist/utility/wrun/wrun-overlay-run.util.js +124 -21
  43. package/dist/utility/wrun/wrun-param-values.util.d.ts +2 -1
  44. package/dist/utility/wrun/wrun-param-values.util.js +3 -9
  45. package/dist/utility/wrun/wrun-row-scalars.leaf.d.ts +30 -0
  46. package/dist/utility/wrun/wrun-row-scalars.leaf.js +73 -0
  47. package/dist/utility/wrun/wrun-run-health.util.d.ts +24 -2
  48. package/dist/utility/wrun/wrun-run-health.util.js +39 -7
  49. package/dist/utility/wrun/wrun-run-interval-session.util.d.ts +18 -0
  50. package/dist/utility/wrun/wrun-run-interval-session.util.js +25 -0
  51. package/dist/utility/wrun/wrun-run-interval.util.d.ts +52 -5
  52. package/dist/utility/wrun/wrun-run-interval.util.js +88 -7
  53. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +4 -7
  54. package/dist/utility/wrun/wrun-script-inputs.util.js +6 -33
  55. package/package.json +1 -1
package/README.md CHANGED
@@ -128,6 +128,7 @@ What each published version holds. A host installs a version with the peers of i
128
128
 
129
129
  | Version | Peers | What changed |
130
130
  | --- | --- | --- |
131
+ | 0.20.0 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Wave 3 of the typed threshold contract (docs/features/kscript/wrun/wrun-chart-host.md, "Market-bound values"). A script row is bound by its package: `wrunMarketBoundParamsOf` (the coin and contract sizes of `WRUN_MARKET_SCALED_PARAMS`, by rule kind) and `boundFieldsOf(type, settings)` give a script `row` and `flat` units; a row unit parks and restores its value with its row's `defaultValue` and `carriedValue` (`BoundStashEntry.rows`, `takeBound(...).rows`) and signs only while typed. A native unit reads its own default (`DeclaredField.ownDefault`, `ReconcileMarketBoundOptions.ownDefaults`), so a market's own default is never parked. A script row's key is spelled as every other reconciled type's, with the candle size (`EXCHANGE-UNIT-SYMBOL-INTERVAL`): a size typed on one candle size stays on it. New: `isTypedUnit`, `holdsBoundState`, `savedBoundVerdict` and `BoundContentOrigin`; `TemplateContext.scriptPackage` and `origin`, `TemplatePatch.adoptBoundKey`; `DeclaredField.savedBound` (the FRVP threshold, gated in saved content only), and the FRVP field table's `boundMarketKey` row on the profile `default` lane (the saved defaults keep the threshold's market key). `templatePatch` keys a Fixed Range template in the unit its profile writes and holds that unit back with a refused threshold; `migrateTemplate` keeps a Fixed Range template's key. A template or saved default with no key is written only when it is the person's own and on its own market, once. `wrunMarketScaledRowChanged` moves to `utility/wrun/wrun-market-size-defaults.leaf` (re-exported from its old file and from `utility/wrun/wrun-script-inputs.util`). Also the first published version with what main added after 0.19.1: `TOOL_FIELD_RANGES` and `toolFieldRange` (a drawing type's own bounds for a number field), `wrunTimesDefaultOverChosenBase` (an untouched Whale is never under its factor times a Min the user chose), and `isOptionContractMarket`, `marketVolumeUnit`, `liveAmountInMarketUnit` and the market argument of `liveAmountUsd` (a CME contract's dollars by its root's point value, never a dollar a point). |
131
132
  | 0.19.1 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Three fixes to 0.19.0's typed threshold contract. `templatePatch` refuses a typed threshold's unit key (`currency`, `bigTradesThresholdUnit`) together with its refused values, so a destination's dollar amount never takes a coin unit; the new optional `TemplateContext.boundKeyParts` (the destination's `MarketBoundKeyParts`) rebuilds the destination's key in the unit the template writes, so a template on its own market in another unit writes its threshold with its unit (a host without it keeps the refusal). `reconcileMarketBound` no longer stashes a unit that holds its default (`options.defaults`, or no value) and drops an older entry for that key, so `BOUND_STASH_CAP` holds only typed values. `captureTemplate`, `toStoredEntry`, `migrateTemplate` and `templatePatch` handle `boundMarketKey` only for a type with a kept bound field, so a script input of that name stays an input. |
132
133
  | 0.19.0 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Market-bound values in `settings-templates`: a value measured or typed on one market carries the market it belongs to. The heatmap scale leaf: `heatmapMarketKey`, `stampBoundKey`, `parseBoundKey`, `boundSignature`, `heatmapScaleSignature`, `stashBound`, `takeBound`, `BOUND_STASH_CAP` (row fields `settings.boundKey` and `settings.boundByMarket`). The typed threshold contract: each numeric field declares `quantity` (`relative`, `bound` or `amount`) and a kept bound one `keep`; `marketBoundKey(parts)` spells the key (exchange, unit, symbol, interval; a month is `1MO`); `reconcileMarketBound(type, settings, liveKey, options)` is the one decision at every door a row meets a market (its own key: unchanged; another key: the typed values are kept under their market and this market's remembered values or the caller's `defaults` come back; no stamp: trusted and stamped, or judged by `unkeyedAs`); `stampMarketBound` signs a user's edit; `unclassifiedNumericFields` feeds a host's classification guard. A host calls the reconcile at its mount, market switch, settings write and document doors, and the stamp on a user's edit; a script row is never settled. `templatePatch` writes a typed threshold only on the market it was saved on (`TemplateContext.boundKey`, kept in the bag as `boundMarketKey`); the schema version does not move, so a client before 0.19.0 lists that key as dropped and writes the threshold as before. The phone app's Big Trades (`BIG_TRADES`) gets a field table. |
133
134
  | 0.18.0 | `@orangecharts/indicator-kit` 0.121.0, `@orangecharts/orange-v2-pb-common` 12.86.0, `dayjs` 1.11.23, `lodash-es` 4.18.1 | Same peers. Four things a host acts on. The index and yield venue's official bars: the index leaf gains `INDEX_OTC_SERVER_BUILT_BARS_FROM_MS` and `barsAreServerBuilt(exchange, intervalMs)`, the root exports `chartBarsAreServerBuilt(market, intervalMs)` (`utility/chart/server-built-bars.util`, a formula leg counts), and the live intake refuses a live fold on such a chart; a host stops folding live prints and gap rows into a bar of one day or wider there and reads the newest bar again from the server. `FeatureFlag` loses `UsEquitiesFull`, `WrunConvergingPrefix`, `DrawingAlertOneClick`, `DrawingsUnderCandles`, `ChartDraftOrder` and `TypedServerFutures` (graduated on web) and gains `FuturesNinjaTraderDepth`. `MARKET_DATA_VENUES` now lists the US stocks venue beside OPRA (it left `FLAG_GATED_MARKET_DATA_VENUES`), so a host that holds stocks behind a switch of its own keeps that switch at its own door. The env gains the optional `isSignedIn()`: the licence and broker flags read as kill switches that default on for a signed-in session, and a host without the port reads every session as a guest. The package commits landed since 0.17.0 ride along (`git log 3ad609a1a4.. -- packages/wrun-chart-host` in the web repo). |
package/dist/index.d.ts CHANGED
@@ -342,6 +342,7 @@ export * from './utility/wrun/wrun-market-facts.util.js';
342
342
  export * from './utility/wrun/wrun-market-size-contract-carry.leaf.js';
343
343
  export * from './utility/wrun/wrun-market-size-defaults.leaf.js';
344
344
  export * from './utility/wrun/wrun-market-size-defaults.util.js';
345
+ export * from './utility/wrun/wrun-market-size-rank.leaf.js';
345
346
  export * from './utility/wrun/wrun-memory-clamp.util.js';
346
347
  export * from './utility/wrun/wrun-odds-template-market.util.js';
347
348
  export * from './utility/wrun/wrun-official-scope.leaf.js';
package/dist/index.js CHANGED
@@ -346,6 +346,7 @@ export * from './utility/wrun/wrun-market-facts.util.js';
346
346
  export * from './utility/wrun/wrun-market-size-contract-carry.leaf.js';
347
347
  export * from './utility/wrun/wrun-market-size-defaults.leaf.js';
348
348
  export * from './utility/wrun/wrun-market-size-defaults.util.js';
349
+ export * from './utility/wrun/wrun-market-size-rank.leaf.js';
349
350
  export * from './utility/wrun/wrun-memory-clamp.util.js';
350
351
  export * from './utility/wrun/wrun-odds-template-market.util.js';
351
352
  export * from './utility/wrun/wrun-official-scope.leaf.js';
@@ -35,11 +35,12 @@ const CONSTANT = { owner: 'profile', lanes: ['row'] };
35
35
  /** Stamped by the control on every mount (engine flags, the block-size status): nothing to save. */
36
36
  const STAMPED = { owner: 'profile', lanes: [] };
37
37
  // The quantity of each numeric key (indicator-fields' header): what its number measures. The FRVP's threshold is a
38
- // volume in the profile's unit, classified bound and never reconciled (left carried on purpose); its block size and
39
- // row height are price units, carried as they are.
38
+ // volume in the profile's unit, classified bound and never reconciled (left carried on purpose on a drawn box), but
39
+ // bound in saved content (`savedBound`: a template or the style memory writes it only on its market key); its block
40
+ // size and row height are price units, carried as they are.
40
41
  const BOX_STYLE_RELATIVE = { ...BOX_STYLE, quantity: 'relative' };
41
42
  const PREFERENCE_RELATIVE = { ...PREFERENCE, quantity: 'relative' };
42
- const PREFERENCE_BOUND = { ...PREFERENCE, quantity: 'bound' };
43
+ const PREFERENCE_BOUND = { ...PREFERENCE, quantity: 'bound', savedBound: true };
43
44
  const PER_BOX_RELATIVE = { ...PER_BOX, quantity: 'relative' };
44
45
  const PER_BOX_AMOUNT = { ...PER_BOX, quantity: 'amount' };
45
46
  const CONSTANT_RELATIVE = { ...CONSTANT, quantity: 'relative' };
@@ -131,6 +132,11 @@ export const FRVP_FIELD_ROWS = [
131
132
  // Not a setting: the stamp the saved defaults' profile half carries in the account's style memory, written with it
132
133
  // (FRVP_PROFILE_DEFAULTS_STAMP below). In the default lane so the memory keeps it; no panel, row or copy holds it.
133
134
  ['profileDefaultsVersion', { owner: 'profile', lanes: ['default'], quantity: 'relative' }],
135
+ // Not a setting: the market key the saved defaults' threshold was typed on (TEMPLATE_BOUND_KEY_FIELD, the key a saved
136
+ // bag names its market with). The threshold is bound in saved content (`savedBound`), so a new profile takes it only
137
+ // on that key (savedBoundVerdict). In the default lane so the style memory and the layout's saved defaults keep it;
138
+ // no panel, row, mirror or template holds it, and a mounted profile is never reconciled on it.
139
+ ['boundMarketKey', { owner: 'profile', lanes: ['default'] }],
134
140
  // Dynamic Profile parity (Exocharts, 2026-11-13). The profile's row text and imbalance marks, read with the session
135
141
  // volume profile's keys and words, and the candle the box draws for its range ('none' by default).
136
142
  ['rowText', PREFERENCE],
@@ -1,8 +1,8 @@
1
1
  import { type BoundCondition, type BoundKeep, type FieldQuantity } from './indicator-fields.js';
2
- import { type MarketBoundKeyParts } from './market-bound.js';
3
- import { type ToolTextRole } from './tool-rules.js';
4
- import { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS } from './tool-tables.generated.js';
5
- export { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS };
2
+ import { type BoundContentOrigin, type MarketBoundKeyParts } from './market-bound.js';
3
+ import { TOOL_FIELD_RANGES, type ToolTextRole } from './tool-rules.js';
4
+ import { TOOL_DEFAULT_STYLE, TOOL_START_STYLE, TOOL_TEMPLATE_KEYS } from './tool-tables.generated.js';
5
+ export { TOOL_DEFAULT_STYLE, TOOL_START_STYLE, TOOL_TEMPLATE_KEYS };
6
6
  export type { ToolTextRole };
7
7
  export type { BoundCondition, BoundKeep, FieldQuantity };
8
8
  export * from './market-bound.js';
@@ -30,6 +30,8 @@ export interface FieldSpec {
30
30
  boundWhen?: BoundCondition;
31
31
  /** On a kept bound field: the companion keys that travel with it as one unit. */
32
32
  with?: readonly string[];
33
+ /** On a bound field with no `keep`: gated in saved content by its market key, never reconciled on a row. */
34
+ savedBound?: boolean;
33
35
  }
34
36
  /**
35
37
  * Where a stored template keeps the market key it was captured on (inside the settings bag: the user service strips
@@ -59,6 +61,18 @@ export interface TemplateContext {
59
61
  * `boundKey` is compared as it is, and a template from another unit is refused with its unit. Optional since 0.19.1.
60
62
  */
61
63
  boundKeyParts?: MarketBoundKeyParts;
64
+ /**
65
+ * A technical script's package (its registry identity, `wrunRegistryRef.package`). Its params sized in coins or
66
+ * contracts (`wrunMarketBoundParamsOf`) are typed thresholds of the template: kept with `boundKey` on a capture,
67
+ * gated on a patch. Without it a script's inputs are never gated.
68
+ */
69
+ scriptPackage?: string;
70
+ /**
71
+ * Whose save a patch reads (savedBoundVerdict): `own` (the person's own saved default or template) or `foreign` (a
72
+ * board settings card, another person's layout). Absent reads `foreign`. Only an own save with no market key is
73
+ * trusted, once, on its `exchange|symbol` market (TemplatePatch.adoptBoundKey).
74
+ */
75
+ origin?: BoundContentOrigin;
62
76
  /** Reserved for host rules that depend on the chart interval; no rule here reads it. */
63
77
  intervalMs?: number;
64
78
  declaredInputs?: readonly string[];
@@ -90,6 +104,11 @@ export interface TemplatePatch {
90
104
  metaPatch: Record<string, unknown>;
91
105
  profilePatch?: Record<string, unknown>;
92
106
  dropped: readonly string[];
107
+ /**
108
+ * The market key to write back into the save: an own save with no key, trusted once on its `exchange|symbol` market
109
+ * (savedBoundVerdict), takes the key of the chart that first used it. Absent otherwise.
110
+ */
111
+ adoptBoundKey?: string;
93
112
  }
94
113
  /**
95
114
  * A stored template a door must not read: its schemaVersion is above this client's (a newer client wrote it) or is
@@ -110,6 +129,12 @@ export declare function isIntervalBoundTool(type: string): boolean;
110
129
  * tables were generated with, so the box never offers a label that a template drops.
111
130
  */
112
131
  export declare function toolTextRole(type: string): ToolTextRole | undefined;
132
+ export { TOOL_FIELD_RANGES };
133
+ /** A field as a drawing type offers it: the type's own bounds (TOOL_FIELD_RANGES) over the field's, the field itself
134
+ * where the type names none. Every host reads a number field's range through this. */
135
+ export declare function toolFieldRange<T extends {
136
+ key: string;
137
+ }>(type: string, field: T): T;
113
138
  /**
114
139
  * Every field a type declares, with what each lane keeps. For a technical script `ctx` adds its declared inputs and
115
140
  * viewer rows (a script's filing key, `TECHNICAL_SCRIPT:<identity>`, reads as its type). The specs are frozen.
@@ -20,8 +20,10 @@
20
20
  * named and equal; on another market it is skipped, not dropped.
21
21
  * - A kept bound field (a typed threshold: `quantity: 'bound'` with `keep`, ./market-bound) that is bound right now in
22
22
  * the unit the template writes is written only when the template's market key (`boundKey`, captured from
23
- * `ctx.boundKey`) equals the destination's (`ctx.boundKey`); when either key is missing, the template's `market` and
24
- * `ctx.market` decide, as for a market-bound field. Its group companions follow it, and so does its unit key (the
23
+ * `ctx.boundKey`) equals the destination's (`ctx.boundKey`); a template with no key is written only when it is the
24
+ * person's own (`ctx.origin` 'own') and its `market` is `ctx.market`, once: the patch names the key to write back
25
+ * (`adoptBoundKey`, savedBoundVerdict). A script's typed thresholds are its package's coin and contract sizes
26
+ * (`ctx.scriptPackage`). Its group companions follow it, and so does its unit key (the
25
27
  * `boundWhen` key): a refused value and its unit are refused together. Skipped, not dropped. With
26
28
  * `ctx.boundKeyParts` the destination's key is rebuilt in the unit the template writes, so a template on its own
27
29
  * market in another unit writes its threshold with its unit. A dollar amount (the field in a notional unit) is
@@ -54,12 +56,13 @@
54
56
  */
55
57
  import cloneDeep from 'lodash-es/cloneDeep.js';
56
58
  import { isWrunViewerRowKey } from '../utility/wrun/wrun-color-facts.util.js';
59
+ import { wrunMarketBoundParamsOf } from '../utility/wrun/wrun-market-size-defaults.leaf.js';
57
60
  import { FRVP_FIELD_ROWS, FRVP_TOOL_TYPE } from './frvp-fields.js';
58
61
  import { INDICATOR_COMMON_FIELDS, INDICATOR_TYPE_FIELDS, RESERVED_SCRIPT_INPUT_NAMES, SCRIPT_INDICATOR_TYPE, SCRIPT_INPUT_FIELD, VIEWER_ROW_FIELD, } from './indicator-fields.js';
59
- import { boundFieldsOf, isBoundNow, marketBoundKey } from './market-bound.js';
60
- import { textRoleOf, TOOL_TEMPLATE_RULES } from './tool-rules.js';
61
- import { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS } from './tool-tables.generated.js';
62
- export { TOOL_DEFAULT_STYLE, TOOL_TEMPLATE_KEYS };
62
+ import { boundFieldsOf, isBoundNow, marketBoundKey, savedBoundVerdict, } from './market-bound.js';
63
+ import { textRoleOf, TOOL_FIELD_RANGES, TOOL_TEMPLATE_RULES } from './tool-rules.js';
64
+ import { TOOL_DEFAULT_STYLE, TOOL_START_STYLE, TOOL_TEMPLATE_KEYS } from './tool-tables.generated.js';
65
+ export { TOOL_DEFAULT_STYLE, TOOL_START_STYLE, TOOL_TEMPLATE_KEYS };
63
66
  // The market key and stamp of market-bound values (a heatmap row's scale, a typed threshold) and the one reconcile:
64
67
  // served by this entry so a host reads the row rules and the stamp rules from one import.
65
68
  export * from './market-bound.js';
@@ -112,7 +115,19 @@ const isFrvpOwner = (owner) => owner === 'box' || owner === 'profile';
112
115
  * this one rule, so the key never takes a bag name from a type whose bag is not the package's own: a script's inputs
113
116
  * are the script's, and an input named `boundMarketKey` stays an input.
114
117
  */
115
- const carriesBoundKey = (kind, type) => kind === 'indicator' && boundFieldsOf(type).length > 0;
118
+ const carriesBoundKey = (kind, type) => (kind === 'indicator' && boundFieldsOf(type).length > 0) ||
119
+ ((kind === 'indicator' || isFrvp(kind, type)) && isSavedBound(baseSpecs(kind, type)));
120
+ /** Whether a field gates saved content by its market key: a kept bound field, or one bound in saved content only. */
121
+ const gatesSaved = (spec) => !!spec.keep || !!spec.savedBound;
122
+ const isSavedBound = (specs) => specs.some((spec) => !!spec.savedBound);
123
+ /**
124
+ * A script template's typed thresholds: its package's params sized in coins or contracts (`ctx.scriptPackage`), none
125
+ * for any other type or a script whose package names none. A script that declares an input named
126
+ * TEMPLATE_BOUND_KEY_FIELD keeps that input, and no key.
127
+ */
128
+ const scriptBoundParams = (kind, type, ctx) => isScript(kind, type) && !(ctx?.declaredInputs ?? []).includes(TEMPLATE_BOUND_KEY_FIELD)
129
+ ? wrunMarketBoundParamsOf(nonEmpty(ctx?.scriptPackage))
130
+ : [];
116
131
  /** The settings key that holds a row's unit: the unit part of marketBoundKey (MarketBoundKeyParts.currency). */
117
132
  const BOUND_KEY_UNIT_FIELD = 'currency';
118
133
  /** Whether a drawing type keeps the "Show on" intervals it was drawn with, whatever a template holds. */
@@ -128,6 +143,13 @@ export function isIntervalBoundTool(type) {
128
143
  export function toolTextRole(type) {
129
144
  return textRoleOf(type, ownRecord(TOOL_DEFAULT_STYLE, type));
130
145
  }
146
+ export { TOOL_FIELD_RANGES };
147
+ /** A field as a drawing type offers it: the type's own bounds (TOOL_FIELD_RANGES) over the field's, the field itself
148
+ * where the type names none. Every host reads a number field's range through this. */
149
+ export function toolFieldRange(type, field) {
150
+ const range = Object.hasOwn(TOOL_FIELD_RANGES, type) ? TOOL_FIELD_RANGES[type][field.key] : undefined;
151
+ return range ? { ...field, ...range } : field;
152
+ }
131
153
  function specOf(key, field) {
132
154
  const spec = { key, owner: field.owner ?? 'settings', lanes: Object.freeze([...field.lanes]) };
133
155
  if (field.instance)
@@ -146,6 +168,8 @@ function specOf(key, field) {
146
168
  spec.boundWhen = field.boundWhen;
147
169
  if (field.with)
148
170
  spec.with = Object.freeze([...field.with]);
171
+ if (field.savedBound)
172
+ spec.savedBound = true;
149
173
  return Object.freeze(spec);
150
174
  }
151
175
  /** An indicator type's fields: the shared rows, then its own (a row of the same owner and key replaces in place). */
@@ -323,13 +347,14 @@ const groupOf = (groups, owner) => owner === 'meta' ? groups.meta : owner === 'p
323
347
  */
324
348
  export function captureTemplate(kind, type, engineSettings, ctx) {
325
349
  const bag = isRecord(engineSettings) ? engineSettings : {};
326
- const specs = fieldSpecs(kind, type, isScript(kind, type)
350
+ const specsCtx = isScript(kind, type)
327
351
  ? {
328
352
  ...ctx,
329
353
  declaredInputs: ctx?.declaredInputs ?? inputNamesOf(bag),
330
354
  viewerKeys: ctx?.viewerKeys ?? viewerKeysOf(bag),
331
355
  }
332
- : ctx);
356
+ : ctx;
357
+ const specs = fieldSpecs(kind, type, specsCtx);
333
358
  const engineMeta = isRecord(bag.meta) ? bag.meta : {};
334
359
  const groups = { settings: {}, meta: {}, profile: {} };
335
360
  for (const spec of specs) {
@@ -340,10 +365,12 @@ export function captureTemplate(kind, type, engineSettings, ctx) {
340
365
  groupOf(groups, spec.owner)[spec.key] = value;
341
366
  }
342
367
  const doc = { schemaVersion: TEMPLATE_SCHEMA_VERSION, kind, type, settings: groups.settings };
343
- const market = kind === 'indicator' ? nonEmpty(ctx?.market) : undefined;
368
+ // A drawing keeps its market only where its saved content holds a bound field (the FRVP's threshold).
369
+ const market = kind === 'indicator' || carriesBoundKey(kind, type) ? nonEmpty(ctx?.market) : undefined;
344
370
  if (market)
345
371
  doc.market = market;
346
- const boundKey = carriesBoundKey(kind, type) ? nonEmpty(ctx?.boundKey) : undefined;
372
+ const keepsKey = carriesBoundKey(kind, type) || scriptBoundParams(kind, type, specsCtx).length > 0;
373
+ const boundKey = keepsKey ? nonEmpty(ctx?.boundKey) : undefined;
347
374
  if (boundKey)
348
375
  doc.boundKey = boundKey;
349
376
  if (Object.keys(groups.meta).length)
@@ -396,28 +423,39 @@ export function templatePatch(kind, type, live, template, ctx) {
396
423
  const sameMarket = !!templateMarket && templateMarket === nonEmpty(ctx?.market);
397
424
  // A kept bound field is written on the market key it was typed on; a template or a context with no key falls back to
398
425
  // the market (an in-memory older shape may still hold the key in its bag).
399
- const savedBoundKey = carriesBoundKey(kind, type) && !bagSpecs.has(TEMPLATE_BOUND_KEY_FIELD)
400
- ? saved[TEMPLATE_BOUND_KEY_FIELD]
401
- : undefined;
426
+ const scriptBound = isScript(kind, type) && !bagSpecs.has(TEMPLATE_BOUND_KEY_FIELD) ? scriptBoundParams(kind, type, ctx) : [];
427
+ const keepsKey = carriesBoundKey(kind, type) || scriptBound.length > 0;
428
+ const savedBoundKey = keepsKey && !bagSpecs.has(TEMPLATE_BOUND_KEY_FIELD) ? saved[TEMPLATE_BOUND_KEY_FIELD] : undefined;
402
429
  const templateBoundKey = nonEmpty(template?.boundKey) ?? nonEmpty(savedBoundKey);
403
430
  // The destination's key as it will be once the template's unit is written, when the host gives its parts: the key
404
431
  // holds the unit, so comparing the destination's current key would refuse a template on its own market for its unit.
405
432
  const parts = ctx?.boundKeyParts;
406
433
  const unitSpec = bagSpecs.get(BOUND_KEY_UNIT_FIELD);
407
- const writesUnit = !!unitSpec?.lanes.includes('template') && Object.hasOwn(saved, BOUND_KEY_UNIT_FIELD);
434
+ // Wherever the template holds its unit: the settings group, or an FRVP's profile group.
435
+ const unitSource = [saved, savedProfile].find((group) => Object.hasOwn(group, BOUND_KEY_UNIT_FIELD));
436
+ const writesUnit = !!unitSpec?.lanes.includes('template') && !!unitSource;
408
437
  const liveBoundKey = isRecord(parts)
409
438
  ? marketBoundKey({
410
439
  ...parts,
411
- currency: writesUnit ? saved[BOUND_KEY_UNIT_FIELD] : parts.currency,
440
+ currency: writesUnit && unitSource ? unitSource[BOUND_KEY_UNIT_FIELD] : parts.currency,
412
441
  })
413
442
  : nonEmpty(ctx?.boundKey);
414
- const sameBoundMarket = templateBoundKey && liveBoundKey ? templateBoundKey === liveBoundKey : sameMarket;
443
+ // One rule for every save (savedBoundVerdict): by key; a save with no key only when it is the person's own, on its
444
+ // own `exchange|symbol` market, once (the key is adopted).
445
+ const verdict = savedBoundVerdict({
446
+ savedKey: templateBoundKey,
447
+ savedMarket: templateMarket,
448
+ liveKey: liveBoundKey,
449
+ liveMarket: nonEmpty(ctx?.market),
450
+ origin: ctx?.origin === 'own' ? 'own' : 'foreign',
451
+ });
452
+ const sameBoundMarket = verdict.write;
415
453
  // The unit a template writes: its own value of the unit key, else the destination's.
416
- const writtenBag = { ...liveBag, ...saved };
454
+ const writtenBag = { ...liveBag, ...saved, ...savedProfile };
417
455
  const gated = new Set();
418
456
  if (!sameBoundMarket) {
419
457
  for (const spec of bagSpecs.values()) {
420
- if (!spec.keep || !isBoundNow(spec.boundWhen, writtenBag))
458
+ if (!gatesSaved(spec) || !isBoundNow(spec.boundWhen, writtenBag))
421
459
  continue;
422
460
  for (const key of [spec.key, ...(spec.with ?? [])])
423
461
  gated.add(key);
@@ -425,7 +463,17 @@ export function templatePatch(kind, type, live, template, ctx) {
425
463
  // the template's unit (a 250000 dollar threshold read as 250000 coins).
426
464
  if (spec.boundWhen)
427
465
  gated.add(spec.boundWhen.key);
466
+ // A field bound in every unit (`savedBound`, no `boundWhen`: the FRVP threshold) is typed in the unit key's unit:
467
+ // a refused one holds that unit back with it, so the destination's own value never takes the template's unit.
468
+ else if (spec.savedBound &&
469
+ unitSpec &&
470
+ (Object.hasOwn(saved, spec.key) || Object.hasOwn(savedProfile, spec.key))) {
471
+ gated.add(BOUND_KEY_UNIT_FIELD);
472
+ }
428
473
  }
474
+ // A script's coin and contract sizes: the bag holds them flat under their names (never their rows).
475
+ for (const name of scriptBound)
476
+ gated.add(name);
429
477
  }
430
478
  const groups = { settings: {}, meta: {}, profile: {} };
431
479
  const dropped = new Set();
@@ -474,6 +522,8 @@ export function templatePatch(kind, type, live, template, ctx) {
474
522
  const result = { patch: groups.settings, metaPatch: groups.meta, dropped: [...dropped] };
475
523
  if (isFrvp(kind, type))
476
524
  result.profilePatch = groups.profile;
525
+ if (keepsKey && verdict.adopt)
526
+ result.adoptBoundKey = verdict.adopt;
477
527
  return result;
478
528
  }
479
529
  /** A stored entry's schema version: none is version 1; one this client cannot read throws. */
@@ -511,6 +561,14 @@ _ctx) {
511
561
  if (Object.keys(meta).length)
512
562
  doc.meta = meta;
513
563
  }
564
+ // The key first: the FRVP field table declares `boundMarketKey` as a profile row (the saved defaults' key), so the
565
+ // profile split below would otherwise take a stored template's key into its profile group and lose it.
566
+ if (carriesBoundKey(kind, type) && Object.hasOwn(settings, TEMPLATE_BOUND_KEY_FIELD)) {
567
+ const boundKey = nonEmpty(settings[TEMPLATE_BOUND_KEY_FIELD]);
568
+ delete settings[TEMPLATE_BOUND_KEY_FIELD];
569
+ if (boundKey)
570
+ doc.boundKey = boundKey;
571
+ }
514
572
  if (isFrvp(kind, type)) {
515
573
  const profile = isRecord(source.profile) ? cloneDeep(source.profile) : {};
516
574
  for (const [key, field] of FRVP_FIELD_ROWS) {
@@ -527,13 +585,7 @@ _ctx) {
527
585
  const market = nonEmpty(source.market);
528
586
  if (market)
529
587
  doc.market = market;
530
- if (carriesBoundKey(kind, type) && Object.hasOwn(settings, TEMPLATE_BOUND_KEY_FIELD)) {
531
- const boundKey = nonEmpty(settings[TEMPLATE_BOUND_KEY_FIELD]);
532
- delete settings[TEMPLATE_BOUND_KEY_FIELD];
533
- if (boundKey)
534
- doc.boundKey = boundKey;
535
- }
536
- const entryBoundKey = kind === 'indicator' ? nonEmpty(source.boundKey) : undefined;
588
+ const entryBoundKey = kind === 'indicator' || carriesBoundKey(kind, type) ? nonEmpty(source.boundKey) : undefined;
537
589
  if (entryBoundKey)
538
590
  doc.boundKey = entryBoundKey;
539
591
  return doc;
@@ -558,7 +610,10 @@ export function toStoredEntry(doc) {
558
610
  const market = nonEmpty(doc.market);
559
611
  if (market)
560
612
  entry.market = market;
561
- const boundKey = carriesBoundKey(doc.kind, doc.type) ? nonEmpty(doc.boundKey) : undefined;
613
+ // A script's key rides its bag only where no input of the script holds that name (a capture keeps the key only then).
614
+ const keepsKey = carriesBoundKey(doc.kind, doc.type) ||
615
+ (isScript(doc.kind, doc.type) && !Object.hasOwn(settings, TEMPLATE_BOUND_KEY_FIELD));
616
+ const boundKey = keepsKey ? nonEmpty(doc.boundKey) : undefined;
562
617
  if (boundKey)
563
618
  settings[TEMPLATE_BOUND_KEY_FIELD] = boundKey;
564
619
  return entry;
@@ -62,6 +62,17 @@ export interface DeclaredField {
62
62
  readonly boundWhen?: BoundCondition;
63
63
  /** On a kept bound field: the keys that travel with it as one unit (a value and its market default). */
64
64
  readonly with?: readonly string[];
65
+ /**
66
+ * On a kept bound field: the sibling key that holds the field's own market default on the row (one of its `with`
67
+ * keys). The value at it reads untouched, so a reconcile never keeps a market's own default as a typed value.
68
+ */
69
+ readonly ownDefault?: string;
70
+ /**
71
+ * On a bound field with no `keep`: bound in SAVED content only (a template, a saved default), never reconciled on a
72
+ * mounted row. The template gate writes it only on the market key it was saved on (savedBoundVerdict), as a kept
73
+ * bound field; boundFieldsOf and reconcileMarketBound ignore it, so the row it is typed on keeps it.
74
+ */
75
+ readonly savedBound?: true;
65
76
  }
66
77
  /** One table row: a key and its declared field. */
67
78
  export type DeclaredFieldRow = readonly [key: string, field: DeclaredField];
@@ -1017,9 +1017,9 @@ const BIG_TRADES_RELATIVE = { lanes: [], quantity: 'relative' };
1017
1017
  const BIG_TRADES_FIELDS = [
1018
1018
  ['minCoins', BIG_TRADES_FLOOR],
1019
1019
  ['whaleCoins', BIG_TRADES_FLOOR],
1020
- ['minSize', { ...BIG_TRADES_FLOOR, with: ['minSizeDefault'] }],
1020
+ ['minSize', { ...BIG_TRADES_FLOOR, with: ['minSizeDefault'], ownDefault: 'minSizeDefault' }],
1021
1021
  ['minSizeDefault', BIG_TRADES_FLOOR_DEFAULT],
1022
- ['whaleSize', { ...BIG_TRADES_FLOOR, with: ['whaleSizeDefault'] }],
1022
+ ['whaleSize', { ...BIG_TRADES_FLOOR, with: ['whaleSizeDefault'], ownDefault: 'whaleSizeDefault' }],
1023
1023
  ['whaleSizeDefault', BIG_TRADES_FLOOR_DEFAULT],
1024
1024
  ['minValue', BIG_TRADES_DOLLARS],
1025
1025
  ['whaleValue', BIG_TRADES_DOLLARS],
@@ -1075,8 +1075,9 @@ export const INDICATOR_TYPE_FIELDS = {
1075
1075
  SESSION_VOLUME_PROFILE: PROFILE_THRESHOLD_FIELDS,
1076
1076
  AGGREGATED_SESSION_VOLUME_PROFILE: PROFILE_THRESHOLD_FIELDS,
1077
1077
  DEVELOPING_SESSION_PROFILE: PROFILE_THRESHOLD_FIELDS,
1078
- // The FRVP companion's threshold is a volume too, left carried on purpose (classified, never reconciled).
1079
- FIXED_RANGE_VOLUME_PROFILE: [['threshold', { ...PREFERENCE, quantity: 'bound' }]],
1078
+ // The FRVP companion's threshold is a volume too, left carried on purpose on a drawn box (classified, never
1079
+ // reconciled), but bound in saved content: a default or template writes it only on its market key (`savedBound`).
1080
+ FIXED_RANGE_VOLUME_PROFILE: [['threshold', { ...PREFERENCE, quantity: 'bound', savedBound: true }]],
1080
1081
  // Both footprints' typed volumes; the single-venue one's Big trades threshold is bound only in Native.
1081
1082
  VOLUME_FOOTPRINT: [
1082
1083
  ...FOOTPRINT_VOLUME_FIELDS,
@@ -20,8 +20,15 @@
20
20
  * meets a market: keep (OWN), swap for that market's remembered or default values (FOREIGN), or trust and stamp
21
21
  * (UNKEYED). A heatmap row keeps its own path (settleHeatmapScale on web): reconcileMarketBound leaves it alone.
22
22
  *
23
- * This file imports only the registry, holds no state and never mutates an input. Every input is read defensively: a
24
- * stored document can hold anything.
23
+ * A script row (wave 3) is bound by its package: the params of `WRUN_MARKET_SCALED_PARAMS` sized in coins or contracts
24
+ * (`wrunMarketBoundParamsOf`, by rule kind alone) are its units, each a `row` (a declared `scriptInputs` row: its value
25
+ * flat under its name, with that row's `defaultValue` and `carriedValue`, parked and given back together) or a `flat`
26
+ * value an older pin left with no row. A row unit reads as typed by the run head's own test
27
+ * (`wrunMarketScaledRowChanged`), so the run head's moves of an untouched default never break a stamp.
28
+ *
29
+ * This file imports the registry and three light leaves (the market size leaf, the row scalars under it, the overlay
30
+ * identity), never the script inputs module or the host env; it holds no state and never mutates an input. Every
31
+ * input is read defensively: a stored document can hold anything.
25
32
  */
26
33
  import { type BoundCondition, type BoundKeep } from './indicator-fields.js';
27
34
  /** What a heatmap's scale was measured on. Every part is passed in: the caller has already resolved them. */
@@ -81,22 +88,31 @@ export declare function heatmapScaleSignature(meta: {
81
88
  } | null | undefined): string;
82
89
  /** The most markets a row keeps typed values for. */
83
90
  export declare const BOUND_STASH_CAP = 8;
91
+ /** What a script row unit's `scriptInputs` row held beside its value: parked and given back with it. */
92
+ export interface BoundStashRow {
93
+ defaultValue?: unknown;
94
+ carriedValue?: number;
95
+ }
84
96
  /** The typed values a row held on one market it left, under that market's key. */
85
97
  export interface BoundStashEntry {
86
98
  key: string;
87
99
  values: Record<string, unknown>;
100
+ /** A script row unit's row companions, by param name (absent for a native row and a flat unit). */
101
+ rows?: Record<string, BoundStashRow>;
88
102
  }
89
103
  /**
90
104
  * A new stash list: any entry for `key` removed, the new entry appended last, and the oldest entries dropped past
91
105
  * BOUND_STASH_CAP. Malformed entries of the given list are dropped. Never mutates its inputs.
92
106
  */
93
- export declare function stashBound(list: readonly BoundStashEntry[] | null | undefined, key: string, values: Record<string, unknown>): BoundStashEntry[];
107
+ export declare function stashBound(list: readonly BoundStashEntry[] | null | undefined, key: string, values: Record<string, unknown>, rows?: Record<string, BoundStashRow> | null): BoundStashEntry[];
94
108
  /**
95
- * The stashed values for `key` (null when none) and a new list without that entry. Tolerates a malformed list (gives
96
- * null and []) and drops malformed entries. Never mutates its input.
109
+ * The stashed values for `key` (null when none), their row companions (only when the entry holds some) and a new list
110
+ * without that entry. Tolerates a malformed list (gives null and []) and drops malformed entries. Never mutates its
111
+ * input.
97
112
  */
98
113
  export declare function takeBound(list: unknown, key: string): {
99
114
  values: Record<string, unknown> | null;
115
+ rows?: Record<string, BoundStashRow>;
100
116
  list: BoundStashEntry[];
101
117
  };
102
118
  /** Whether a type's market-bound values are a heatmap's scale (wave 1's path, never reconcileMarketBound). */
@@ -137,13 +153,23 @@ export interface BoundFieldUnit {
137
153
  keep: BoundKeep;
138
154
  /** The native unit the field is bound in; absent means bound in every unit. */
139
155
  boundWhen?: BoundCondition;
156
+ /** A native unit: the sibling key holding the field's own market default on the row (DeclaredField.ownDefault). */
157
+ ownDefault?: string;
158
+ /**
159
+ * A script unit (a package param sized in coins or contracts): `row` when the row's `scriptInputs` declare the param
160
+ * (its value flat under its name, with that row's `defaultValue` and `carriedValue`), `flat` for a value an older
161
+ * pin left on the record with no row. Absent on a native unit.
162
+ */
163
+ input?: 'row' | 'flat';
140
164
  }
141
165
  /**
142
166
  * The reconciled units of a type, in the registry's declared order: every settings-bag field with `quantity: 'bound'`
143
167
  * and a `keep`, with its `with` companions (a companion is never a unit of its own). None for a heatmap type (its own
144
- * path), a technical script (its inputs are the script's) or a type without such a field. Frozen and cached.
168
+ * path) or a type without such a field. A technical script's units are its package's coin and contract sizes the row
169
+ * holds (scriptUnitsOf), read off `settings`; without `settings` a script has none. A native type's are frozen and
170
+ * cached, and never read `settings`.
145
171
  */
146
- export declare function boundFieldsOf(type: string): readonly BoundFieldUnit[];
172
+ export declare function boundFieldsOf(type: string, settings?: unknown): readonly BoundFieldUnit[];
147
173
  /**
148
174
  * Whether a condition holds on a settings bag: no condition always holds; otherwise the sibling's value (undefined
149
175
  * when the bag or the key is missing) is one of `oneOf` when that is named and none of `noneOf` when that is named.
@@ -151,30 +177,52 @@ export declare function boundFieldsOf(type: string): readonly BoundFieldUnit[];
151
177
  export declare function isBoundNow(condition: BoundCondition | null | undefined, settings: unknown): boolean;
152
178
  /** The units of a type that are bound right now on this bag (each unit's `boundWhen` read off the bag). */
153
179
  export declare function boundUnitsNow(type: string, settings: unknown): readonly BoundFieldUnit[];
180
+ /**
181
+ * Whether a unit holds a value the user typed on the market the row was on (the one test a reconcile parks by and a
182
+ * script signature signs by). A script `row` unit: the run head's own test (`wrunMarketScaledRowChanged`: off its
183
+ * row's default, or at its carried mark). A `flat` unit: a finite positive value. A native unit: off its own default,
184
+ * read from the row's companion (`ownDefault`) first, else `ownDefaults` (the leaving market's defaults, by field
185
+ * key), else no value at all. A measured unit is never typed.
186
+ */
187
+ export declare function isTypedUnit(unit: BoundFieldUnit, settings: unknown, ownDefaults?: Readonly<Record<string, unknown>> | null): boolean;
154
188
  /**
155
189
  * The signature of a threshold row: boundSignature over the values of the type's typed units that are bound right now,
156
- * each unit's keys in order, the units in the registry's declared order, a missing value as null. A non-record bag reads
157
- * as empty.
190
+ * each unit's keys in order, the units in the registry's declared order, a missing value as null. A script unit signs
191
+ * its value while it reads typed (isTypedUnit) and null while it does not, so the run head moving an untouched value
192
+ * and its default together leaves the stamp valid. A non-record bag reads as empty.
158
193
  */
159
194
  export declare function marketBoundSignature(type: string, settings: unknown): string;
160
195
  /**
161
196
  * The row after a user's edit of its bound values (they were just typed on the live market): `boundKey` stamped with
162
197
  * `liveKey` and the row's signature. The same object when the stamp is already that one, and for a type with no
163
- * reconciled unit or a bag that is no record.
198
+ * reconciled unit on this bag or a bag that is no record.
164
199
  */
165
200
  export declare function stampMarketBound<T extends object>(type: string, settings: T, liveKey: string): T;
166
201
  /**
167
- * What one reconcile did: `none` (no unit bound right now, a heatmap or a script, no live key, or a bag that is no
168
- * record), `own` (the stamp names the live market and signs the values), `key-mismatch` (the values belong to another
169
- * market and were swapped for the live market's), `unkeyed-stamped` (no valid stamp: the values are trusted here).
202
+ * Whether a row holds anything a reconcile judges. A native row: a value of a reconciled field, a stamp or a stash (a
203
+ * row that holds none, a workspace row its control fills at its init, has nothing typed on any market). A script row:
204
+ * a stamp, a stash or a typed unit (an untouched row follows the run head's market defaults and needs no stamp).
205
+ */
206
+ export declare function holdsBoundState(type: string, settings: unknown): boolean;
207
+ /**
208
+ * What one reconcile did: `none` (no unit bound right now, a heatmap, no live key, or a bag that is no record), `own`
209
+ * (the stamp names the live market and signs the values), `key-mismatch` (the values belong to another market and were
210
+ * swapped for the live market's), `unkeyed-stamped` (no valid stamp: the values are trusted here).
170
211
  */
171
212
  export type MarketBoundVerdict = 'none' | 'own' | 'key-mismatch' | 'unkeyed-stamped';
172
213
  export interface ReconcileMarketBoundOptions {
173
214
  /**
174
215
  * The values to write where the live market has none remembered, by field key (a group's companions by their own
175
- * keys). A unit whose field is not named here is removed, so its reader uses its own default.
216
+ * keys). A native unit whose field is not named here is removed, so its reader uses its own default. A script unit
217
+ * never reads it: its row's own default is its value.
176
218
  */
177
219
  defaults?: Readonly<Record<string, unknown>> | null;
220
+ /**
221
+ * The defaults of the market the row is leaving, by field key, when the caller knows them: a native unit that holds
222
+ * them is untouched and is never kept (isTypedUnit). A unit with its own default on the row (`ownDefault`) reads that
223
+ * first. Without either, the unit is compared with `defaults`.
224
+ */
225
+ ownDefaults?: Readonly<Record<string, unknown>> | null;
178
226
  /**
179
227
  * The market key an unkeyed row was saved on, when the caller knows it (a workspace or layout document that names its
180
228
  * market): the row is then read as stamped with it and judged OWN or FOREIGN.
@@ -197,16 +245,41 @@ export interface MarketBoundReconciliation<T> {
197
245
  * The one decision a reader makes when a threshold row meets the live market `liveKey` (contract section 6). Pure:
198
246
  * reads its inputs defensively and never mutates them.
199
247
  * - OWN (the stamp parses, its signature matches, its key is `liveKey`): unchanged, the same object.
200
- * - FOREIGN (the stamp parses and signs, another key): the typed units bound right now are kept under the stamp's key
201
- * in `boundByMarket` (measured ones are dropped, and so is a unit that holds what this reconcile restores where none
202
- * is remembered: its default or no value; with none kept, an older entry for the stamp's key goes); each unit takes the live market's remembered values out of the
203
- * stash, else `options.defaults`, else is removed; the row is stamped with `liveKey`. A group is one unit.
248
+ * - FOREIGN (the stamp parses and signs, another key): the typed units bound right now (isTypedUnit) are kept under the
249
+ * stamp's key in `boundByMarket`; a measured unit and an untouched one are not (with none kept, an older entry for
250
+ * the stamp's key goes). Each unit then takes the live market's remembered values out of the stash; else a native
251
+ * unit takes `options.defaults` or is removed, a script `row` unit that was typed takes its row's current default as
252
+ * its value and loses its carried mark (the run head then moves value and default to this market's), and a `flat`
253
+ * unit is written as null. A script row unit's row companions (`defaultValue`, `carriedValue`) are kept and given
254
+ * back with its value, `scriptInputs` written whole. The row is stamped with `liveKey`. A group is one unit.
204
255
  * - UNKEYED (no stamp, a malformed one, or a signature that does not match): the values are trusted on this market and
205
256
  * stamped with `liveKey`; with `options.unkeyedAs` the row is first read as stamped with that key (OWN or FOREIGN).
206
- * A field not bound right now (its unit is notional) is never kept, reset or signed. A heatmap type, a script, a type
207
- * without a reconciled unit and a row with no unit bound right now come back untouched (`none`).
257
+ * A field not bound right now (its unit is notional) is never kept, reset or signed. A heatmap type, a type without a
258
+ * reconciled unit and a row with no unit bound right now (and, for a script, no flat value remembered for `liveKey`)
259
+ * come back untouched (`none`).
208
260
  */
209
261
  export declare function reconcileMarketBound<T extends object>(type: string, settings: T, liveKey: string, options?: ReconcileMarketBoundOptions | null): MarketBoundReconciliation<T>;
262
+ /** Whose content a saved bag is: the person's own (a saved default, a template they saved) or anyone else's. */
263
+ export type BoundContentOrigin = 'own' | 'foreign';
264
+ /**
265
+ * Whether a saved bag's typed values (a template, a saved default, a layout's row) are written onto the live market,
266
+ * and the key to write back into the save when it is trusted once:
267
+ * - the saved key equals the live key: written, nothing to adopt;
268
+ * - a saved key that differs (or no live key to meet it): not written;
269
+ * - no saved key, the person's own save, and its `exchange|symbol` market is the live one: written once, and the live
270
+ * key is adopted (the host writes it into the save, so the next use is judged by key);
271
+ * - no saved key otherwise (another person's content, another market, or no live key): not written.
272
+ */
273
+ export declare function savedBoundVerdict(a: {
274
+ savedKey?: string | null;
275
+ savedMarket?: string | null;
276
+ liveKey?: string | null;
277
+ liveMarket?: string | null;
278
+ origin: BoundContentOrigin;
279
+ }): {
280
+ write: boolean;
281
+ adopt: string | null;
282
+ };
210
283
  /**
211
284
  * The paths of a sample settings bag that hold a number (or a container of numbers) and whose field declares no
212
285
  * quantity, or is not declared at all: what the classification guard reports. A meta object's keys are read as