gloomberb 0.20.13 → 0.20.16

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 (275) hide show
  1. package/package.json +2 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
  3. package/src/account/auth-dialog.tsx +22 -4
  4. package/src/account/auth-form.tsx +6 -1
  5. package/src/account/checkout-handoff.tsx +7 -14
  6. package/src/account/device-signin-dialog.tsx +35 -24
  7. package/src/api-client/crypto-markets.ts +10 -0
  8. package/src/api-client/errors.ts +3 -1
  9. package/src/api-client/index.ts +54 -0
  10. package/src/api-client/install-experiments.ts +8 -7
  11. package/src/api-client/money-markets.ts +7 -0
  12. package/src/api-client/paths.ts +2 -1
  13. package/src/api-client/product-waitlist.ts +63 -0
  14. package/src/api-client/request.ts +16 -4
  15. package/src/api-client/types/billing.ts +45 -0
  16. package/src/api-client/yearly-plan.ts +132 -0
  17. package/src/app/global-shortcuts.ts +5 -3
  18. package/src/app/pane-runtime/index.tsx +2 -2
  19. package/src/app/pane-runtime/plugin-bindings.ts +3 -1
  20. package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
  21. package/src/app/since-last-visit/keys.ts +26 -0
  22. package/src/app/since-last-visit/model.ts +266 -0
  23. package/src/app/since-last-visit/strip.tsx +193 -0
  24. package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
  25. package/src/app/since-last-visit/visit-tracker.ts +191 -0
  26. package/src/app.tsx +15 -0
  27. package/src/architecture/floating-promise-allowlist.json +0 -1
  28. package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
  29. package/src/cli/commands/market.ts +103 -27
  30. package/src/cli/commands/overview.ts +18 -4
  31. package/src/cli/commands/system.ts +29 -1
  32. package/src/cli/commands/ticker.ts +12 -5
  33. package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
  34. package/src/cli/desktop-pane-shot-browser.ts +2 -1
  35. package/src/cli/desktop-pane-shot-view.ts +3 -7
  36. package/src/cli/desktop-pane-shot.ts +26 -28
  37. package/src/cli/errors.ts +3 -1
  38. package/src/cli/freshness.ts +7 -2
  39. package/src/cli/glossary.ts +10 -5
  40. package/src/cli/help.ts +1 -0
  41. package/src/cli/helpers.ts +8 -16
  42. package/src/cli/history-export.ts +4 -0
  43. package/src/cli/history-rows.ts +24 -0
  44. package/src/cli/index.ts +4 -0
  45. package/src/cli/known-gaps.ts +2 -2
  46. package/src/cli/listing-arg.ts +79 -11
  47. package/src/cli/not-a-ticker.ts +4 -0
  48. package/src/cli/options.ts +29 -1
  49. package/src/cli/pane-functions/catalog.ts +70 -12
  50. package/src/cli/pane-functions/function-help.ts +1 -1
  51. package/src/cli/pane-functions/headless.ts +68 -3
  52. package/src/cli/pane-functions/index.ts +2 -2
  53. package/src/cli/pane-functions/options.ts +7 -0
  54. package/src/cli/pane-functions/resolver.ts +104 -15
  55. package/src/cli/pane-functions/screenshot-payload.ts +3 -0
  56. package/src/cli/report-tables.ts +20 -5
  57. package/src/cli/result.ts +22 -4
  58. package/src/cli/shot-temp-dir.ts +30 -0
  59. package/src/cli/suffixed-listing-rows.ts +11 -0
  60. package/src/cli/symbol-args.ts +5 -3
  61. package/src/cli/symbol-list.ts +23 -10
  62. package/src/cli/symbol-rows.ts +135 -3
  63. package/src/cli/treasury-yields.ts +15 -1
  64. package/src/components/chart/composite/composite-chart.tsx +3 -3
  65. package/src/components/chart/composite/format.ts +2 -1
  66. package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
  67. package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
  68. package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
  69. package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
  70. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
  71. package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
  72. package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
  73. package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
  74. package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
  75. package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
  76. package/src/components/chart/composite/panel-surface/props.ts +79 -0
  77. package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
  78. package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
  79. package/src/components/chart/composite/panel-surface.tsx +81 -1177
  80. package/src/components/command-bar/commands/collection-list.ts +1 -0
  81. package/src/components/command-bar/commands/direct/index.ts +31 -8
  82. package/src/components/command-bar/commands/registry.ts +7 -0
  83. package/src/components/command-bar/routes/root/command-items.ts +8 -0
  84. package/src/components/command-bar/routes/root/results.ts +19 -2
  85. package/src/components/command-bar/routes/root/runtime.ts +3 -2
  86. package/src/components/command-bar/routes/root/selection.ts +3 -2
  87. package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
  88. package/src/components/company-logo.tsx +10 -3
  89. package/src/components/data-table/sections.ts +6 -1
  90. package/src/components/layout/pane/title.ts +16 -6
  91. package/src/components/layout/shell/index.tsx +5 -1
  92. package/src/components/layout/shell/ticker-link-menu.ts +12 -9
  93. package/src/components/pane-settings-dialog/tui.tsx +6 -3
  94. package/src/components/pane-settings-dialog.tsx +2 -1
  95. package/src/components/pane-template-wizard.tsx +2 -0
  96. package/src/components/ticker/badge/format.ts +12 -3
  97. package/src/components/ticker/badge/index.tsx +9 -3
  98. package/src/components/ticker/list-table-view.tsx +119 -17
  99. package/src/components/ui/choice-dialog.tsx +1 -1
  100. package/src/components/ui/confirm-dialog.tsx +3 -2
  101. package/src/components/ui/data-table/display-columns.ts +16 -0
  102. package/src/components/ui/data-table/index.tsx +40 -9
  103. package/src/components/ui/data-table/types.ts +14 -0
  104. package/src/components/ui/frame.tsx +7 -3
  105. package/src/components/ui/icon.tsx +4 -2
  106. package/src/components/ui/list-view.tsx +8 -0
  107. package/src/components/ui/number-prompt-dialog.tsx +2 -1
  108. package/src/components/use-pane-notice-footer.tsx +3 -1
  109. package/src/core/state/app/layout-reducer.ts +3 -1
  110. package/src/core/state/app/layout.ts +2 -2
  111. package/src/data/config/layout.ts +14 -0
  112. package/src/data/config/store/normalize.ts +11 -1
  113. package/src/docs/snapshot.json +2 -2
  114. package/src/i18n/es.ts +39 -0
  115. package/src/i18n/ja.ts +39 -0
  116. package/src/i18n/ko.ts +39 -0
  117. package/src/i18n/zh-cn.ts +39 -0
  118. package/src/i18n/zh-tw.ts +39 -0
  119. package/src/layout/pane-follow.ts +141 -4
  120. package/src/layout/pane-layout-move.ts +10 -7
  121. package/src/layout/ticker-navigation.ts +13 -19
  122. package/src/layout/ticker-retarget.ts +3 -2
  123. package/src/market-data/market/format.ts +35 -1
  124. package/src/market-data/market/index-level.ts +19 -0
  125. package/src/market-data/quotes/contributions.ts +13 -0
  126. package/src/market-data/quotes/export-identity.ts +36 -1
  127. package/src/market-data/quotes/resolution.ts +16 -0
  128. package/src/plugins/builtin/account-management/keyboard.ts +14 -0
  129. package/src/plugins/builtin/account-management/model.ts +2 -0
  130. package/src/plugins/builtin/account-management/pane.tsx +79 -7
  131. package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
  132. package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
  133. package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
  134. package/src/plugins/builtin/analytics/risk-client.ts +12 -2
  135. package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
  136. package/src/plugins/builtin/analytics/risk-math.ts +23 -6
  137. package/src/plugins/builtin/analytics/risk-model.ts +20 -9
  138. package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
  139. package/src/plugins/builtin/awards/pane.tsx +6 -8
  140. package/src/plugins/builtin/changelog/index.tsx +6 -44
  141. package/src/plugins/builtin/changelog/versions.ts +17 -68
  142. package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
  143. package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
  144. package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
  145. package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
  146. package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
  147. package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
  148. package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
  149. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  150. package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
  151. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
  152. package/src/plugins/builtin/cpi/headless.ts +6 -1
  153. package/src/plugins/builtin/cpi/model.ts +17 -0
  154. package/src/plugins/builtin/cpi/pane.tsx +4 -2
  155. package/src/plugins/builtin/crypto-board/client.ts +6 -1
  156. package/src/plugins/builtin/crypto-board/headless.ts +10 -2
  157. package/src/plugins/builtin/crypto-board/model.ts +89 -11
  158. package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
  159. package/src/plugins/builtin/debt-maturities/model.ts +1 -1
  160. package/src/plugins/builtin/dividend-yield/client.ts +24 -2
  161. package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
  162. package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
  163. package/src/plugins/builtin/dividend-yield/view.ts +5 -1
  164. package/src/plugins/builtin/earnings/board-table.ts +1 -1
  165. package/src/plugins/builtin/earnings/board.tsx +36 -16
  166. package/src/plugins/builtin/earnings/highlight.ts +47 -0
  167. package/src/plugins/builtin/earnings/history-table.ts +9 -1
  168. package/src/plugins/builtin/earnings/index.tsx +1 -1
  169. package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
  170. package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
  171. package/src/plugins/builtin/econ/calendar-model.ts +17 -1
  172. package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
  173. package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
  174. package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
  175. package/src/plugins/builtin/exposure/index.tsx +1 -1
  176. package/src/plugins/builtin/macro-day/headless.ts +21 -10
  177. package/src/plugins/builtin/macro-day/model.ts +42 -3
  178. package/src/plugins/builtin/macro-day/pane.tsx +26 -8
  179. package/src/plugins/builtin/macro-day/releases.ts +24 -1
  180. package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
  181. package/src/plugins/builtin/market-valuation/headless.ts +11 -4
  182. package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
  183. package/src/plugins/builtin/market-valuation/view.ts +14 -0
  184. package/src/plugins/builtin/money-markets/client.ts +4 -1
  185. package/src/plugins/builtin/money-markets/headless.ts +15 -4
  186. package/src/plugins/builtin/money-markets/index.tsx +1 -1
  187. package/src/plugins/builtin/money-markets/pane.tsx +7 -1
  188. package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
  189. package/src/plugins/builtin/pe-band/pane.tsx +1 -1
  190. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
  191. package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
  192. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
  193. package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
  194. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +178 -17
  195. package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
  196. package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
  197. package/src/plugins/builtin/portfolio-list/pane/index.tsx +95 -18
  198. package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
  199. package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
  200. package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
  201. package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
  202. package/src/plugins/builtin/portfolio-list/table.tsx +38 -16
  203. package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
  204. package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
  205. package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
  206. package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
  207. package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
  208. package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
  209. package/src/plugins/builtin/shared/headless-options.ts +1 -1
  210. package/src/plugins/builtin/social-mentions/model.ts +2 -2
  211. package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
  212. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
  213. package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
  214. package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
  215. package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
  216. package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
  217. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
  218. package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
  219. package/src/plugins/builtin/ticker-detail/headless.ts +280 -35
  220. package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
  221. package/src/plugins/builtin/ticker-detail/overview/model.ts +9 -2
  222. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
  223. package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
  224. package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
  225. package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
  226. package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
  227. package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
  228. package/src/portfolio/collection-name.ts +2 -1
  229. package/src/portfolio/column-values.ts +34 -12
  230. package/src/portfolio/listed-symbol.ts +4 -2
  231. package/src/portfolio/period-pnl.ts +51 -1
  232. package/src/portfolio/suffixed-listings.ts +3 -1
  233. package/src/portfolio/watchlist-groups.ts +212 -0
  234. package/src/react/ticker-source.ts +3 -1
  235. package/src/renderers/dom/dialog-host.tsx +5 -5
  236. package/src/renderers/dom/styles.css +7 -0
  237. package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
  238. package/src/renderers/opentui/dialog-host.tsx +3 -4
  239. package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
  240. package/src/sources/provider-router/history.ts +5 -2
  241. package/src/state/app/bootstrap.ts +11 -0
  242. package/src/state/app/context/index.tsx +6 -0
  243. package/src/sync/collections-contributor.ts +5 -2
  244. package/src/sync/config-merge.ts +10 -2
  245. package/src/sync/sanitize.ts +28 -0
  246. package/src/telemetry/usage-counts.ts +17 -0
  247. package/src/test-support/plugin-persistence.ts +12 -0
  248. package/src/tickers/company-name-listing.ts +4 -3
  249. package/src/tickers/company-name.ts +19 -1
  250. package/src/tickers/instrument-coverage.ts +27 -0
  251. package/src/tickers/search/home-listing.ts +38 -1
  252. package/src/tickers/search/index.ts +3 -2
  253. package/src/tickers/search/ranking.ts +21 -2
  254. package/src/time-series/base-series.ts +4 -0
  255. package/src/time-series/chart-seed.ts +1 -1
  256. package/src/time-series/financial-period-coverage.ts +4 -12
  257. package/src/time-series/parsed-history-cache.ts +1 -1
  258. package/src/time-series/resolve.ts +1 -1
  259. package/src/time-series/types.ts +5 -2
  260. package/src/time-series/use-chart-resolution.ts +6 -1
  261. package/src/types/config.ts +32 -0
  262. package/src/types/financials.ts +13 -0
  263. package/src/types/headless.ts +7 -0
  264. package/src/types/plugin-context.ts +5 -0
  265. package/src/types/ticker.ts +14 -0
  266. package/src/ui/ascii-font.ts +1 -4
  267. package/src/ui/dialog-stack.ts +17 -0
  268. package/src/ui/dialog.tsx +6 -2
  269. package/src/utils/async-deadline.ts +2 -2
  270. package/src/utils/crypto-pair.ts +9 -0
  271. package/src/utils/csv.ts +44 -5
  272. package/src/utils/exchanges.ts +13 -0
  273. package/src/utils/financial-statements.ts +60 -3
  274. package/src/utils/futures-generic.ts +17 -0
  275. package/src/utils/trailing-dividend.ts +13 -3
@@ -0,0 +1,212 @@
1
+ import type { AppConfig } from "../types/config";
2
+ import type { Watchlist, WatchlistGroup } from "../types/ticker";
3
+ import { parseCollectionRef } from "../team/collections";
4
+ import { isRecord } from "../utils/guards";
5
+
6
+ /** The longest name a group takes, so its header and the CLI's Group column stay readable. */
7
+ const MAX_GROUP_NAME_LENGTH = 40;
8
+
9
+ /** The section a list's tickers in no group show under; no group takes the name. */
10
+ export const UNGROUPED_LABEL = "Ungrouped";
11
+
12
+ const sameName = (left: string, right: string) => left.toLocaleLowerCase() === right.toLocaleLowerCase();
13
+
14
+ /**
15
+ * A list's groups as they are kept: names trimmed, two names that differ only
16
+ * in case one group under the first's name, each symbol in the first group
17
+ * that lists it, and a group left with no symbol dropped. Undefined when none
18
+ * remain, so a list without groups saves and syncs as it did before groups.
19
+ * Reads anything (a pulled or hand-edited config) and keeps what is well formed.
20
+ */
21
+ export function normalizeWatchlistGroups(value: unknown): WatchlistGroup[] | undefined {
22
+ if (!Array.isArray(value)) return undefined;
23
+ const groups: WatchlistGroup[] = [];
24
+ const placed = new Set<string>();
25
+ for (const entry of value) {
26
+ if (!isRecord(entry) || typeof entry.name !== "string" || !Array.isArray(entry.symbols)) continue;
27
+ const name = entry.name.trim();
28
+ if (!name) continue;
29
+ let group = groups.find((existing) => sameName(existing.name, name));
30
+ if (!group) {
31
+ group = { name, symbols: [] };
32
+ groups.push(group);
33
+ }
34
+ for (const symbol of entry.symbols) {
35
+ if (typeof symbol !== "string" || !symbol.trim() || placed.has(symbol)) continue;
36
+ placed.add(symbol);
37
+ group.symbols.push(symbol);
38
+ }
39
+ }
40
+ const kept = groups.filter((group) => group.symbols.length > 0);
41
+ return kept.length > 0 ? kept : undefined;
42
+ }
43
+
44
+ /** A list's groups, none for a list without; a config pulled from another device is read as it came, so this checks it. */
45
+ export function watchlistGroups(watchlist: Pick<Watchlist, "groups"> | null | undefined): WatchlistGroup[] {
46
+ return normalizeWatchlistGroups(watchlist?.groups) ?? [];
47
+ }
48
+
49
+ /** The name of the group a ticker of the list is in, by its key; null when it is in none. */
50
+ export function watchlistGroupOf(watchlist: Pick<Watchlist, "groups"> | null | undefined, symbol: string): string | null {
51
+ return watchlistGroups(watchlist).find((group) => group.symbols.includes(symbol))?.name ?? null;
52
+ }
53
+
54
+ /**
55
+ * Whether the list takes groups: a personal one. A team list is shared with
56
+ * everyone on the team and its items are the server's, so it has none.
57
+ */
58
+ export function watchlistTakesGroups(watchlist: Pick<Watchlist, "id" | "teamId">): boolean {
59
+ return !watchlist.teamId && parseCollectionRef(watchlist.id).scope !== "team";
60
+ }
61
+
62
+ /** A group name as typed, trimmed; throws saying why one cannot be used. */
63
+ export function parseWatchlistGroupName(input: string): string {
64
+ const name = input.trim().replace(/\s+/g, " ");
65
+ if (!name) throw new Error("A group needs a name.");
66
+ if (name.length > MAX_GROUP_NAME_LENGTH) throw new Error(`A group name is at most ${MAX_GROUP_NAME_LENGTH} characters.`);
67
+ if (sameName(name, UNGROUPED_LABEL)) throw new Error(`"${UNGROUPED_LABEL}" is where tickers in no group show; name the group something else.`);
68
+ return name;
69
+ }
70
+
71
+ function withGroups(config: AppConfig, watchlistId: string, groups: readonly WatchlistGroup[]): AppConfig {
72
+ const kept = normalizeWatchlistGroups(groups);
73
+ return {
74
+ ...config,
75
+ watchlists: config.watchlists.map((watchlist) => {
76
+ if (watchlist.id !== watchlistId) return watchlist;
77
+ const { groups: _groups, ...rest } = watchlist;
78
+ return kept ? { ...rest, groups: kept } : rest;
79
+ }),
80
+ };
81
+ }
82
+
83
+ /**
84
+ * Puts `symbols` (tickers' keys) in the list's group `group` names, matched in
85
+ * any case, taking each out of any other group of the list; a new group goes
86
+ * last. `null` takes them out of their group. `moved` names the symbols whose
87
+ * group changed, and `group` is the name they are under now; the config comes
88
+ * back as it was when none moved.
89
+ */
90
+ export function setWatchlistGroup(
91
+ config: AppConfig,
92
+ watchlistId: string,
93
+ symbols: readonly string[],
94
+ group: string | null,
95
+ ): { config: AppConfig; group: string | null; moved: string[] } {
96
+ const watchlist = config.watchlists.find((entry) => entry.id === watchlistId);
97
+ if (!watchlist) throw new Error("Watchlist not found.");
98
+ const groups = watchlistGroups(watchlist);
99
+ const target = group == null ? null : groups.find((entry) => sameName(entry.name, group))?.name ?? parseWatchlistGroupName(group);
100
+ const moving = [...new Set(symbols)].filter((symbol) => watchlistGroupOf(watchlist, symbol) !== target);
101
+ if (moving.length === 0) return { config, group: target, moved: [] };
102
+ const next = groups.map((entry) => ({ name: entry.name, symbols: entry.symbols.filter((symbol) => !moving.includes(symbol)) }));
103
+ if (target != null) {
104
+ const existing = next.find((entry) => entry.name === target);
105
+ if (existing) existing.symbols.push(...moving);
106
+ else next.push({ name: target, symbols: [...moving] });
107
+ }
108
+ return { config: withGroups(config, watchlistId, next), group: target, moved: moving };
109
+ }
110
+
111
+ /** The list's groups without `symbols`, tickers that left the list: one added back later starts in no group. */
112
+ export function withoutWatchlistGroupSymbols(config: AppConfig, watchlistId: string, symbols: readonly string[]): AppConfig {
113
+ const watchlist = config.watchlists.find((entry) => entry.id === watchlistId);
114
+ const groups = watchlistGroups(watchlist);
115
+ if (!groups.some((group) => group.symbols.some((symbol) => symbols.includes(symbol)))) return config;
116
+ return withGroups(config, watchlistId, groups.map((group) => ({ ...group, symbols: group.symbols.filter((symbol) => !symbols.includes(symbol)) })));
117
+ }
118
+
119
+ /**
120
+ * The config without group symbols whose ticker is loaded and no longer on
121
+ * the list: taken off it some other way (the command bar, another device, an
122
+ * older build), so one added back later starts in no group. A symbol with no
123
+ * loaded row is kept: a pull may not have written it yet, or its row did not
124
+ * read, and a symbol with no row shows nowhere anyway.
125
+ */
126
+ export function withoutStaleWatchlistGroupSymbols(
127
+ config: AppConfig,
128
+ tickers: Iterable<{ metadata: { ticker: string; watchlists: readonly string[] } }>,
129
+ ): AppConfig {
130
+ if (!config.watchlists.some((watchlist) => watchlist.groups)) return config;
131
+ const listsOf = new Map<string, readonly string[]>();
132
+ for (const ticker of tickers) listsOf.set(ticker.metadata.ticker, ticker.metadata.watchlists);
133
+ let next = config;
134
+ for (const watchlist of config.watchlists) {
135
+ const stale = watchlistGroups(watchlist).flatMap((group) => group.symbols.filter((symbol) => {
136
+ const lists = listsOf.get(symbol);
137
+ return lists != null && !lists.includes(watchlist.id);
138
+ }));
139
+ if (stale.length > 0) next = withoutWatchlistGroupSymbols(next, watchlist.id, stale);
140
+ }
141
+ return next;
142
+ }
143
+
144
+ /**
145
+ * Names a group of the list, matched in any case, `to` instead. A name another
146
+ * group has merges the two, where the first of them was.
147
+ */
148
+ export function renameWatchlistGroup(config: AppConfig, watchlistId: string, from: string, to: string): AppConfig {
149
+ const watchlist = config.watchlists.find((entry) => entry.id === watchlistId);
150
+ const groups = watchlistGroups(watchlist);
151
+ const renamed = parseWatchlistGroupName(to);
152
+ if (!groups.some((group) => sameName(group.name, from))) throw new Error(`"${watchlist?.name ?? watchlistId}" has no group "${from}".`);
153
+ return withGroups(config, watchlistId, groups.map((group) => (sameName(group.name, from) ? { ...group, name: renamed } : group)));
154
+ }
155
+
156
+ /**
157
+ * Group symbols saved under an old key moved to their listing's key
158
+ * (`mergeSuffixedListings`: GARAN.IS into GARAN:BIST), as target weights are.
159
+ * A listing already in a group keeps that group.
160
+ */
161
+ export function moveWatchlistGroupSymbols(config: AppConfig, moved: ReadonlyMap<string, string>): AppConfig {
162
+ let changed = false;
163
+ const watchlists = config.watchlists.map((watchlist) => {
164
+ const groups = watchlistGroups(watchlist);
165
+ if (!groups.some((group) => group.symbols.some((symbol) => moved.has(symbol)))) return watchlist;
166
+ changed = true;
167
+ const grouped = new Set(groups.flatMap((group) => group.symbols));
168
+ const next = normalizeWatchlistGroups(groups.map((group) => ({
169
+ ...group,
170
+ symbols: group.symbols.flatMap((symbol) => {
171
+ const to = moved.get(symbol);
172
+ return to == null ? [symbol] : grouped.has(to) ? [] : [to];
173
+ }),
174
+ })));
175
+ const { groups: _groups, ...rest } = watchlist;
176
+ return next ? { ...rest, groups: next } : rest;
177
+ });
178
+ return changed ? { ...config, watchlists } : config;
179
+ }
180
+
181
+ export interface WatchlistSection<T> {
182
+ /** The group's name; null for the tickers in no group. */
183
+ name: string | null;
184
+ items: T[];
185
+ }
186
+
187
+ /**
188
+ * Items of a list under their sections, each section in the order the items
189
+ * come: every group that holds one, in the list's order, then the items in no
190
+ * group. Null when no item is in a group, so a list without groups shows as it
191
+ * always has.
192
+ */
193
+ export function sectionWatchlistItems<T>(
194
+ groups: readonly WatchlistGroup[],
195
+ items: readonly T[],
196
+ keyOf: (item: T) => string,
197
+ ): WatchlistSection<T>[] | null {
198
+ const groupOf = new Map<string, number>();
199
+ groups.forEach((group, index) => group.symbols.forEach((symbol) => groupOf.set(symbol, index)));
200
+ const grouped: T[][] = groups.map(() => []);
201
+ const ungrouped: T[] = [];
202
+ for (const item of items) {
203
+ const index = groupOf.get(keyOf(item));
204
+ if (index == null) ungrouped.push(item);
205
+ else grouped[index]!.push(item);
206
+ }
207
+ if (ungrouped.length === items.length) return null;
208
+ return [
209
+ ...groups.flatMap((group, index) => grouped[index]!.length > 0 ? [{ name: group.name, items: grouped[index]! }] : []),
210
+ ...ungrouped.length > 0 ? [{ name: null, items: ungrouped }] : [],
211
+ ];
212
+ }
@@ -6,7 +6,8 @@ import { usePluginAppActions, usePluginTickerActions } from "../plugins/runtime"
6
6
 
7
7
  /**
8
8
  * Shared Enter routing for panes that publish a cursor symbol: reuse the Ticker Research pane
9
- * already bound to this one instead of stacking another pane on top of it.
9
+ * already bound to this one, or a pinned one the layout has, instead of stacking another pane on
10
+ * top of it (`resolveTickerActivation`).
10
11
  */
11
12
  export function useTickerSourceActivate(): (
12
13
  symbol: string,
@@ -27,6 +28,7 @@ export function useTickerSourceActivate(): (
27
28
  floating: options?.floating ?? true,
28
29
  forceNewPane: options?.newPane,
29
30
  paneType: TICKER_RESEARCH_PANE_ID,
31
+ ...(activation.reusePaneId ? { reusePaneId: activation.reusePaneId } : {}),
30
32
  });
31
33
  }, [focusPane, paneId, pinTicker, stateRef]);
32
34
  }
@@ -1,12 +1,12 @@
1
1
  /** @jsxImportSource react */
2
2
  import { useEffect, useRef, type ReactNode } from "react";
3
- import { DialogHostProvider } from "../../ui/dialog";
3
+ import { DialogHostProvider, type DialogOptions } from "../../ui/dialog";
4
4
  import {
5
5
  bridgeDialogContent,
6
6
  DialogBridgeRegistrationProvider,
7
7
  useDialogBridgeSlot,
8
8
  } from "../../ui/dialog-bridge";
9
- import { useDialogStack } from "../../ui/dialog-stack";
9
+ import { closesOnClickOutside, useDialogStack } from "../../ui/dialog-stack";
10
10
  import { blendHex } from "../../theme/colors";
11
11
  import { useThemeColors } from "../../theme/theme-context";
12
12
  import { isEditableTarget, isInsideDialogSurface } from "./host/focus-scope";
@@ -14,7 +14,7 @@ import { isEditableTarget, isInsideDialogSurface } from "./host/focus-scope";
14
14
  interface DialogState {
15
15
  id: string;
16
16
  content: ReactNode | ((context: { dialogId: string; dismiss(): void; resolve(value: unknown): void }) => ReactNode);
17
- closeOnClickOutside: boolean;
17
+ closeOnClickOutside: DialogOptions["closeOnClickOutside"];
18
18
  returnFocus: HTMLElement | null;
19
19
  }
20
20
 
@@ -42,7 +42,7 @@ export function WebDialogHostProvider({ children }: { children: ReactNode }) {
42
42
  return {
43
43
  id,
44
44
  content: options.content as DialogState["content"],
45
- closeOnClickOutside: options.closeOnClickOutside === true,
45
+ closeOnClickOutside: options.closeOnClickOutside,
46
46
  returnFocus,
47
47
  };
48
48
  },
@@ -99,7 +99,7 @@ export function WebDialogHostProvider({ children }: { children: ReactNode }) {
99
99
  data-topmost={isTopmost ? "true" : "false"}
100
100
  onMouseDown={(event) => {
101
101
  if (event.target !== event.currentTarget) return;
102
- if (isTopmost && dialogState.closeOnClickOutside) {
102
+ if (isTopmost && closesOnClickOutside(dialogState.closeOnClickOutside)) {
103
103
  close(dialogState.id, undefined);
104
104
  return;
105
105
  }
@@ -319,6 +319,13 @@ button, [data-gloom-interactive="true"] { cursor: pointer; }
319
319
  [data-gloom-role="status-bar"] span {
320
320
  line-height: var(--cell-h);
321
321
  }
322
+ /* The returning-user strip under the header: one row of shell chrome, ruled off from the layout. */
323
+ [data-gloom-role="since-last-visit"] {
324
+ flex: none;
325
+ align-items: center;
326
+ border-bottom: 1px solid var(--gloom-hairline);
327
+ font-size: var(--gloom-type-ui);
328
+ }
322
329
  [data-gloom-role="pane-body"] {
323
330
  overflow: hidden;
324
331
  }
@@ -42,7 +42,7 @@ export function createCapabilityInvoker(options: {
42
42
  ? withDeadline(
43
43
  request,
44
44
  options.timeoutMs,
45
- `Asset data request timed out after ${options.timeoutMs}ms: ${operationId}`,
45
+ `Asset data request timed out after ${options.timeoutMs}ms`,
46
46
  )
47
47
  : request;
48
48
  if (!invokeOptions.signal) {
@@ -17,7 +17,7 @@ import {
17
17
  useDialogBridgeSlot,
18
18
  type DialogContentBridge,
19
19
  } from "../../ui/dialog-bridge";
20
- import { useDialogStack, type DialogKind } from "../../ui/dialog-stack";
20
+ import { closesOnClickOutside, useDialogStack, type DialogKind } from "../../ui/dialog-stack";
21
21
 
22
22
  interface DialogRecord {
23
23
  id: string;
@@ -26,7 +26,7 @@ interface DialogRecord {
26
26
  size?: DialogOptions["size"];
27
27
  style?: DialogStyle;
28
28
  closeOnEscape?: boolean;
29
- closeOnClickOutside?: boolean;
29
+ closeOnClickOutside?: DialogOptions["closeOnClickOutside"];
30
30
  }
31
31
 
32
32
  function renderDialogContent(content: unknown, context: AlertContext | PromptContext<unknown>): ReactNode {
@@ -82,7 +82,6 @@ function DialogLayer({
82
82
  ? Math.max(1, Math.min(style.maxHeight, viewportHeight))
83
83
  : viewportHeight;
84
84
  const closeOnEscape = dialog.closeOnEscape ?? true;
85
- const closeOnClickOutside = dialog.closeOnClickOutside ?? false;
86
85
  const zIndex = 9_998 + index * 2;
87
86
 
88
87
  useKeyboard((event) => {
@@ -124,7 +123,7 @@ function DialogLayer({
124
123
  alignItems="center"
125
124
  justifyContent="center"
126
125
  onMouseDown={() => {
127
- if (isTopmost && closeOnClickOutside) close(dialog.id);
126
+ if (isTopmost && closesOnClickOutside(dialog.closeOnClickOutside)) close(dialog.id);
128
127
  }}
129
128
  >
130
129
  <box
@@ -124,6 +124,8 @@ export function mapQuote(
124
124
  delisting: parseListingDelisting(quote.delisting),
125
125
  intradayBar: readIntradayBar(quote.intradayBar),
126
126
  staleReason: readStaleReason(quote.staleReason),
127
+ // An exchange's name, shown as the quote's source: nothing longer or stranger is.
128
+ priceVenue: typeof quote.priceVenue === "string" && /^[A-Za-z][A-Za-z0-9 .-]{0,23}$/.test(quote.priceVenue) ? quote.priceVenue : undefined,
127
129
  priceBasis,
128
130
  priceObservation,
129
131
  currency: currency || quote.currency,
@@ -143,6 +145,9 @@ export function mapQuote(
143
145
  low52w: normalizePriceValueByDivisor(quote.low52w, divisor),
144
146
  // The service read the 52-week range from its stored daily bars, its source's being unusable.
145
147
  yearRangeBasis: quote.yearRangeBasis === "daily-bars" ? "daily-bars" : undefined,
148
+ // What a coin's day range and volume measure: the composite's, or one exchange's own day.
149
+ statsBasis: quote.statsBasis === "composite" || quote.statsBasis === "exchange" ? quote.statsBasis : undefined,
150
+ rangeWidened: quote.rangeWidened === true ? true : undefined,
146
151
  // No live quote: the close of the latest daily bar of this session.
147
152
  dailyClose: readDailyClose(quote.dailyClose),
148
153
  bid: normalizePriceValueByDivisor(quote.bid, divisor),
@@ -779,8 +779,11 @@ export class ProviderRouterHistoryRoutes {
779
779
  if (behind) throw new Error(`Latest history for ${target.symbol} is behind`);
780
780
  // A reason the service gave ("ADX listings have daily bars only.") says why; one that has no
781
781
  // listing for the symbol says it is not a ticker; otherwise no source answered. A coin trades
782
- // around the clock and its sources are there: they could not answer just now.
783
- throw noProviderError(coin ? `No source could load history for ${request.target.symbol} just now` : request.missingProviderError,
782
+ // around the clock and its sources are there: they could not answer just now. So could a
783
+ // source that failed (a timeout, a 5xx) rather than had nothing: that is no listing without
784
+ // history, and never reads as one ("No history provider available").
785
+ const failed = coin || attempts.misses.failure !== undefined;
786
+ throw noProviderError(failed ? `No source could load history for ${request.target.symbol} just now` : request.missingProviderError,
784
787
  attempts.misses, request.target.symbol);
785
788
  }
786
789
  // A window of dates no source could answer, because one failed rather than had nothing, is that failure:
@@ -15,6 +15,7 @@ import { getDockedPaneIds } from "../../layout/pane-manager";
15
15
  import { debugLog } from "../../utils/debug-log";
16
16
  import { measurePerf, measurePerfAsync } from "../../utils/perf-marks";
17
17
  import { mergeSavedSuffixedListings } from "../../portfolio/suffixed-listings";
18
+ import { withoutStaleWatchlistGroupSymbols } from "../../portfolio/watchlist-groups";
18
19
  import { saveConfigImmediately } from "../config-save-scheduler";
19
20
 
20
21
  export const DEFAULT_WATCHLIST_TICKERS: Array<Pick<TickerMetadata, "ticker" | "exchange" | "currency" | "name">> = [
@@ -276,6 +277,16 @@ export async function initializeAppState({
276
277
  startupLog.warn("suffixed listing merge failed", { message: error instanceof Error ? error.message : String(error) });
277
278
  }
278
279
 
280
+ // A ticker that left a list some other way than its own remove leaves the list's groups too.
281
+ const ungrouped = withoutStaleWatchlistGroupSymbols(config, tickers);
282
+ if (ungrouped !== config) {
283
+ config = ungrouped;
284
+ dispatch({ type: "SET_CONFIG", config });
285
+ await saveConfigImmediately(config).catch((error: unknown) => {
286
+ startupLog.warn("stale watchlist group symbols not saved", { message: error instanceof Error ? error.message : String(error) });
287
+ });
288
+ }
289
+
279
290
  // Seed default watchlist tickers on first run
280
291
  if (tickers.length === 0) {
281
292
  const defaultWatchlistId = config.watchlists[0]?.id ?? "watchlist";
@@ -14,6 +14,7 @@ import {
14
14
  } from "react";
15
15
  import type { AppSessionStorePort } from "../../../core/app-service-ports";
16
16
  import { ThemeProvider } from "../../../theme/theme-context";
17
+ import { setCsvDecimal } from "../../../utils/csv";
17
18
  import { syncFontScale } from "../../../theme/font-scale";
18
19
  import {
19
20
  findPaneInstance,
@@ -698,6 +699,11 @@ export function AppProvider({
698
699
  }
699
700
  }, [state.config.fontSize]);
700
701
 
702
+ // Every CSV the app exports (a table's Export CSV, the quote board's) writes the decimal mark the reader set.
703
+ useLayoutEffect(() => {
704
+ setCsvDecimal(state.config.csvDecimal);
705
+ }, [state.config.csvDecimal]);
706
+
701
707
  useLayoutEffect(() => {
702
708
  stateRef.current = state;
703
709
  for (const listener of listenersRef.current) {
@@ -8,6 +8,7 @@ import type { SyncContributor } from "./types";
8
8
  import { isRecord, recordOrNull } from "../utils/guards";
9
9
  import { withoutMissingWatchlists } from "../portfolio/mutations";
10
10
  import { mergeSuffixedListings, moveTargetWeights } from "../portfolio/suffixed-listings";
11
+ import { moveWatchlistGroupSymbols } from "../portfolio/watchlist-groups";
11
12
  import { knownBrokerHoldings } from "../brokers/broker-portfolio-sync";
12
13
  import {
13
14
  localOnlyScope,
@@ -23,7 +24,7 @@ import {
23
24
  } from "./analytics-payload";
24
25
  import { idEntries } from "./broker-instances";
25
26
  import { CORE_CONFIG_CONTRIBUTOR_ID, log } from "./config-contributor";
26
- import { sanitizePortfolio, sanitizeWatchlist } from "./sanitize";
27
+ import { sanitizePortfolio, sanitizeWatchlist, WATCHLISTS_CARRY_GROUPS } from "./sanitize";
27
28
  import {
28
29
  lastSyncedTickersById,
29
30
  latestBrokerPortfolioSyncs,
@@ -55,6 +56,8 @@ export function collectCoreCollectionsPayload(
55
56
  exchangeRates: { USD: 1 },
56
57
  portfolios: config.portfolios.map(sanitizePortfolio),
57
58
  watchlists: config.watchlists.map(sanitizeWatchlist),
59
+ // The lists carry their groups, as the config payload's do: a reader can tell a list without them from an older build's.
60
+ [WATCHLISTS_CARRY_GROUPS]: true,
58
61
  analyticsByPortfolio: collectAnalyticsByPortfolio(config, tickers, financials, exchangeRates, brokerAccounts),
59
62
  accountsByPortfolio: collectAccountsByPortfolio(config, brokerAccounts),
60
63
  tickers: records,
@@ -168,6 +171,6 @@ function mergePulledSuffixedListings(
168
171
  else changed.push(row);
169
172
  }
170
173
  for (const kept of merged.keptCustom) log.info("sync.suffixed-listing.custom-kept", kept);
171
- const next = moveTargetWeights(config, merged.moved);
174
+ const next = moveWatchlistGroupSymbols(moveTargetWeights(config, merged.moved), merged.moved);
172
175
  return { config: next === config ? null : next };
173
176
  }
@@ -1,7 +1,7 @@
1
1
  import { normalizeStoredBaseCurrency } from "../utils/base-currency";
2
2
  import { stableStringify } from "../utils/hash";
3
3
  import type { AppConfig, BrokerInstanceConfig } from "../types/config";
4
- import type { Portfolio } from "../types/ticker";
4
+ import type { Portfolio, Watchlist } from "../types/ticker";
5
5
  import {
6
6
  addLegacyBuiltinDisabledPluginAliases,
7
7
  addLegacyBuiltinPluginOwnerAliases,
@@ -33,7 +33,9 @@ import {
33
33
  sanitizePortfolio,
34
34
  sanitizeUnknown,
35
35
  sanitizeWatchlist,
36
+ WATCHLISTS_CARRY_GROUPS,
36
37
  withLocalPluginSecrets,
38
+ withLocalWatchlistGroups,
37
39
  } from "./sanitize";
38
40
 
39
41
  export function collectCoreConfigPayload(config: AppConfig) {
@@ -43,6 +45,7 @@ export function collectCoreConfigPayload(config: AppConfig) {
43
45
  refreshIntervalMinutes: config.refreshIntervalMinutes,
44
46
  portfolios: config.portfolios.map(sanitizePortfolio),
45
47
  watchlists: config.watchlists.map(sanitizeWatchlist),
48
+ [WATCHLISTS_CARRY_GROUPS]: true,
46
49
  ...collectLayoutPayload(config),
47
50
  brokerInstances: config.brokerInstances.map(sanitizeBrokerInstance),
48
51
  // This build merges profiles one by one before it pushes, so a profile
@@ -169,7 +172,12 @@ export function mergeConfigPayload(
169
172
  ? mergeLocalBrokerPortfolioIdentity(config.portfolios, syncedPortfolios as Portfolio[], next.brokerInstances)
170
173
  : syncedPortfolios as AppConfig["portfolios"];
171
174
  }
172
- assign("watchlists");
175
+ // An older build pushes its lists without their groups: they keep the groups they have here.
176
+ if ("watchlists" in payload && canApply("watchlists")) {
177
+ next.watchlists = Array.isArray(payload.watchlists)
178
+ ? withLocalWatchlistGroups(payload.watchlists, config.watchlists, payload[WATCHLISTS_CARRY_GROUPS] === true)
179
+ : payload.watchlists as Watchlist[];
180
+ }
173
181
  assign("disabledSources");
174
182
  assign("theme");
175
183
  assign("chartPreferences");
@@ -1,6 +1,7 @@
1
1
  import type { AppConfig, BrokerInstanceConfig } from "../types/config";
2
2
  import type { Portfolio, TickerPosition, Watchlist } from "../types/ticker";
3
3
  import { isRecord } from "../utils/guards";
4
+ import { normalizeWatchlistGroups } from "../portfolio/watchlist-groups";
4
5
 
5
6
  const SENSITIVE_KEY_PATTERN = /(token|secret|password|credential|private|api[_-]?key|access[_-]?key|refresh[_-]?key|session|cookie|dataDir|path|directory|localPath)/i;
6
7
 
@@ -77,11 +78,38 @@ export function sanitizePortfolio(portfolio: Portfolio): Portfolio {
77
78
  };
78
79
  }
79
80
 
81
+ /**
82
+ * Set on every payload this build pushes with watchlists: its lists carry their
83
+ * groups, so one without `groups` has none. An older build's lists never carry
84
+ * them, and taken as they came they would erase the groups here and then
85
+ * everywhere this device pushes to.
86
+ */
87
+ export const WATCHLISTS_CARRY_GROUPS = "watchlistsCarryGroups";
88
+
89
+ /**
90
+ * Pulled watchlists, each list an older build pushed (no `WATCHLISTS_CARRY_GROUPS`)
91
+ * keeping the groups it has here; a build that sends groups is taken as it
92
+ * came, so a group removed there is removed here.
93
+ */
94
+ export function withLocalWatchlistGroups(pulled: unknown[], local: readonly Watchlist[], carriesGroups: boolean): Watchlist[] {
95
+ if (carriesGroups) return pulled as Watchlist[];
96
+ return pulled.map((entry) => {
97
+ if (!isRecord(entry) || entry.groups !== undefined) return entry as unknown as Watchlist;
98
+ const groups = local.find((watchlist) => watchlist.id === entry.id)?.groups;
99
+ return (groups ? { ...entry, groups } : entry) as unknown as Watchlist;
100
+ });
101
+ }
102
+
80
103
  export function sanitizeWatchlist(watchlist: Watchlist): Watchlist {
104
+ // The user's own sections: a pulled list without them would erase them on this device. A list
105
+ // without groups goes as before. They are an array, never keyed by a name or symbol, which
106
+ // `sanitizeUnknown` would drop for reading like a secret (a Private group, the PATH ticker).
107
+ const groups = normalizeWatchlistGroups(watchlist.groups);
81
108
  return {
82
109
  id: watchlist.id,
83
110
  name: watchlist.name,
84
111
  description: watchlist.description,
112
+ ...(groups ? { groups } : {}),
85
113
  };
86
114
  }
87
115
 
@@ -241,6 +241,23 @@ export function recordRestoredFunctions(fns: readonly UsageFunction[]): void {
241
241
  }
242
242
  }
243
243
 
244
+ /**
245
+ * Counts a function that put itself on screen at launch, with nothing opened
246
+ * by the user (the since-last-visit strip): in `restored`, never `opened`, and
247
+ * no open listener hears of it. Unlike `recordRestoredFunctions` it can be
248
+ * called on its own, once the function knows it showed. Never throws.
249
+ */
250
+ export function recordFunctionShown(fn: UsageFunction): void {
251
+ try {
252
+ if (automationDepth > 0) return;
253
+ if (host && !host.isEnabled()) return;
254
+ count(fn, "restored");
255
+ scheduleFlush();
256
+ } catch (error) {
257
+ logFailure("telemetry-usage-counts", "Could not record a function shown at launch")(error);
258
+ }
259
+ }
260
+
244
261
  /** The install as its usage counts name it: the random install id, the surface and the OS. */
245
262
  export interface UsageInstall {
246
263
  installId: string;
@@ -1,6 +1,17 @@
1
1
  import type { PersistedResourceValue } from "../types/persistence";
2
2
  import type { PluginPersistence } from "../types/plugin";
3
3
 
4
+ /**
5
+ * A mid-morning UTC moment for a test to hold the clock at (`setSystemTime`),
6
+ * when it reads the time of day off a copy `seedResource` saved: that copy is
7
+ * dated a minute before the clock, so in the first minute of a day it is from
8
+ * the day before and reads with its date ("saved copy from 13 Nov 23:59")
9
+ * instead of "saved copy from 23:59". Its minutes and seconds are ones no time
10
+ * zone's midnight falls on, so the minute before it is never another day's
11
+ * wherever the test runs.
12
+ */
13
+ export const SAVED_COPY_TEST_NOW = Date.parse("2026-11-13T10:17:42Z");
14
+
4
15
  export class MemoryPluginPersistence implements PluginPersistence {
5
16
  private readonly state = new Map<string, { schemaVersion: number; value: unknown }>();
6
17
  private readonly resources = new Map<string, PersistedResourceValue<unknown>>();
@@ -83,6 +94,7 @@ export class MemoryPluginPersistence implements PluginPersistence {
83
94
  provenance?: unknown;
84
95
  } = {},
85
96
  ): void {
97
+ // A minute back: see SAVED_COPY_TEST_NOW for what a test that reads this copy's time of day holds the clock for.
86
98
  const now = Date.now();
87
99
  this.resources.set(this.resourceKey(kind, key, options.sourceKey), {
88
100
  value,
@@ -5,7 +5,7 @@ import type { InstrumentSearchResult } from "../types/instrument";
5
5
  import { canonicalExchange, isUsEquityExchange, isUsListingExchange, parsePublicTickerKey } from "../utils/exchanges";
6
6
  import { companyLines, companyNameExtraWords, companyNameMatch, foldNameLetters, namedByService, runTogether, sameCompany, shortCompanyName } from "./company-name";
7
7
  import { LISTING_SEARCH_LIMIT } from "./search";
8
- import { lineDistance, primaryCompanyLine } from "./search/home-listing";
8
+ import { isFundReceipt, lineDistance, primaryCompanyLine } from "./search/home-listing";
9
9
  import { classifyInstrumentKind, isCryptoInstrumentType } from "./search/ranking";
10
10
  import { isProviderBusy, type ProviderBusyError } from "../sources/provider-errors";
11
11
  import { readTerminalListingCode, type TerminalListing, type TerminalListingCode } from "./terminal-codes";
@@ -178,8 +178,9 @@ function rankCompanyLines(name: string, results: readonly InstrumentSearchResult
178
178
  || parsePublicTickerKey(result.symbol).exchange) return [];
179
179
  // A word alone names a company by these lines only; the company's other lines are still its lines.
180
180
  const namesCompany = !(options.oneWord && (match.abbreviated > 0 || isCryptoInstrumentType(type) || !(order === 0 || named || match.extra === 0)));
181
- // A receipt is a company's shares too, however search types it ("Depositary Receipt" or "American Depositary Receipt").
182
- const stock = classifyInstrumentKind(type) === "equity" || RECEIPT.test(type) ? 0 : 1;
181
+ // A receipt is a company's shares too, however search types it ("Depositary Receipt" or "American Depositary Receipt"),
182
+ // unless it is one on a fund search lists under its name: the Tracker Fund's Thai receipt is the fund's line.
183
+ const stock = RECEIPT.test(type) ? (isFundReceipt(result, results) ? 1 : 0) : classifyInstrumentKind(type) === "equity" ? 0 : 1;
183
184
  const home = result.homeListing === true;
184
185
  const line = home ? 0 : 1 + lineDistance(type, exchange, result.symbol);
185
186
  return [{
@@ -31,7 +31,10 @@ const NAME_NOISE = new Set([
31
31
  "anonim", "sirketi", "ortakligi",
32
32
  ]);
33
33
  // Turkish legal forms short enough to open another company's name (AO Smith, AO World): a legal form only as its last word.
34
- const LAST_WORD_NOISE = new Set(["ao", "tas"]);
34
+ // So is a partnership limited by shares (Hermès International SCA), whatever a venue spells out.
35
+ const LAST_WORD_NOISE = new Set(["ao", "tas", "sca"]);
36
+ // A legal form a venue spells out in words that are no legal form alone: Hermès International Société en commandite par actions.
37
+ const SPELLED_SCA = /\bsociete en commandite par actions\b/g;
35
38
  // Words a venue adds to the share it lists ("Microsoft Corporation Common Stock"), never part of whose it is.
36
39
  const SHARE_NOISE = new Set(["common", "ordinary", "stock", "shares", "share"]);
37
40
  // A venue's short form of a share class word, read as the word: "Volkswagen AG Pref. Share" in Zurich is its "Preferred Stock".
@@ -43,6 +46,7 @@ function companyKey(name: string): string {
43
46
  .replace(/\([^)]*\)/g, " ")
44
47
  .replace(/\b(?:(?:american|global) )?depositary (?:shares?|receipts?)\b/g, " ")
45
48
  .replace(/\./g, "")
49
+ .replace(SPELLED_SCA, "sca")
46
50
  .split(/[^\p{L}\p{N}]+/u)
47
51
  .map((word) => SHARE_WORD_FORMS[word] ?? word)
48
52
  .filter((word) => word && !NAME_NOISE.has(word));
@@ -333,6 +337,20 @@ function nameWord(word: string, opening: boolean, domain: boolean): string {
333
337
  return `${word.charAt(0)}${word.slice(1).toLowerCase()}`;
334
338
  }
335
339
 
340
+ /**
341
+ * The name a company is introduced by beside its lines on other venues
342
+ * ("Prudential plc trades on HKEX as 2378:HKEX", "HSBC Holdings plc also
343
+ * lists 0005:HKEX"): the name its home line is listed under, which tells
344
+ * Prudential plc from Prudential Financial, else its issuer's, cased. Without
345
+ * the comma or the full stop a listing's name can carry beside its legal form:
346
+ * "HSBC Holdings, plc." is HSBC Holdings plc.
347
+ */
348
+ export function companyLinesName(listedName: string | null | undefined, issuerName: string): string {
349
+ return (listedName?.trim() || companyNameCase(issuerName))
350
+ .replace(/,\s*(?=(?:plc|inc|ltd|limited|corp|sa|ag|nv|se)\b)/i, " ")
351
+ .replace(/\.$/, "");
352
+ }
353
+
336
354
  /**
337
355
  * A company name a source writes in capitals (an ETF's holdings file: "APPLE INC", "MERCK & CO INC") as it is
338
356
  * normally written: "Apple Inc", "Merck & Co Inc". Legal forms and short words take their usual case, initials