@gloom-sh/terminal 0.20.17 → 0.20.18

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 (304) hide show
  1. package/package.json +3 -1
  2. package/src/account/auth-dialog.tsx +19 -1
  3. package/src/account/billing.ts +2 -1
  4. package/src/account/heard-from-question.tsx +235 -0
  5. package/src/account/heard-from.ts +97 -0
  6. package/src/api-client/data.ts +3 -2
  7. package/src/api-client/heard-from.ts +72 -0
  8. package/src/api-client/index.ts +63 -6
  9. package/src/api-client/mna.ts +18 -0
  10. package/src/api-client/supply-chain.ts +9 -0
  11. package/src/api-client/types/billing.ts +35 -1
  12. package/src/app/global-shortcuts.ts +5 -3
  13. package/src/app/pro-welcome/keys.ts +27 -0
  14. package/src/app/pro-welcome/model.ts +158 -0
  15. package/src/app/pro-welcome/row.tsx +176 -0
  16. package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
  17. package/src/app/runtime/external-profile-changes.ts +135 -0
  18. package/src/app.tsx +33 -2
  19. package/src/architecture/core-builtin-allowlist.json +1 -1
  20. package/src/architecture/floating-promise-allowlist.json +0 -1
  21. package/src/architecture/shortcut-labels-allowlist.json +1 -0
  22. package/src/cli/alert-listing.ts +98 -0
  23. package/src/cli/commands/market.ts +138 -22
  24. package/src/cli/commands/overview.ts +7 -1
  25. package/src/cli/commands/plugins.ts +3 -2
  26. package/src/cli/commands/search.ts +30 -6
  27. package/src/cli/context.ts +16 -5
  28. package/src/cli/csv-export.ts +2 -1
  29. package/src/cli/desktop-pane-shot.ts +72 -9
  30. package/src/cli/glossary.ts +64 -10
  31. package/src/cli/history-demergers.ts +117 -0
  32. package/src/cli/history-rows.ts +6 -2
  33. package/src/cli/index.ts +1 -0
  34. package/src/cli/known-gaps.ts +16 -0
  35. package/src/cli/known-us-stocks.ts +18 -0
  36. package/src/cli/listing-arg.ts +105 -15
  37. package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
  38. package/src/cli/pane-functions/catalog-snapshot.json +866 -0
  39. package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
  40. package/src/cli/pane-functions/catalog.ts +50 -16
  41. package/src/cli/pane-functions/data.ts +16 -4
  42. package/src/cli/pane-functions/dom.ts +24 -6
  43. package/src/cli/pane-functions/freshness.ts +17 -1
  44. package/src/cli/pane-functions/index.ts +100 -42
  45. package/src/cli/pane-functions/resolver.ts +8 -5
  46. package/src/cli/pane-functions/screenshot-assessment.ts +30 -7
  47. package/src/cli/pane-functions/screenshot-payload.ts +21 -0
  48. package/src/cli/pane-functions/screenshot-render.ts +3 -1
  49. package/src/cli/quote-answer.ts +32 -16
  50. package/src/cli/registry.ts +22 -2
  51. package/src/cli/result.ts +5 -4
  52. package/src/cli/series-search.ts +45 -6
  53. package/src/cli/shot-temp-dir.ts +4 -9
  54. package/src/components/chart/composite/legend.tsx +43 -18
  55. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
  56. package/src/components/chart/composite/price-axis-labels.tsx +7 -5
  57. package/src/components/chart-table/header.tsx +9 -0
  58. package/src/components/chart-table/layout.ts +11 -11
  59. package/src/components/command-bar/pane-templates/items.ts +17 -1
  60. package/src/components/command-bar/routes/root/provider-search.ts +10 -1
  61. package/src/components/command-bar/routes/root/results.ts +34 -2
  62. package/src/components/command-bar/routes/root/runtime.ts +8 -1
  63. package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
  64. package/src/components/command-bar/workflow/alert.ts +19 -8
  65. package/src/components/data-table/view.tsx +15 -2
  66. package/src/components/form-modal/content.tsx +9 -4
  67. package/src/components/index.ts +1 -1
  68. package/src/components/layout/header.tsx +9 -5
  69. package/src/components/layout/pane/capture-status.ts +6 -0
  70. package/src/components/layout/pane/footer/index.tsx +2 -0
  71. package/src/components/layout/pane/footer/model.ts +113 -15
  72. package/src/components/layout/pane/header.tsx +16 -2
  73. package/src/components/market-board/index.tsx +4 -2
  74. package/src/components/onboarding/onboarding-frame.tsx +6 -2
  75. package/src/components/onboarding/onboarding-keyboard.ts +7 -1
  76. package/src/components/onboarding/onboarding-wizard.tsx +3 -1
  77. package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
  78. package/src/components/onboarding/setup-cards.ts +36 -0
  79. package/src/components/onboarding/use-onboarding-progress.ts +22 -1
  80. package/src/components/onboarding/wizard-account.ts +6 -1
  81. package/src/components/onboarding/wizard-model.ts +32 -6
  82. package/src/components/onboarding/wizard-positions.ts +1 -1
  83. package/src/components/sign-in-gate.tsx +3 -1
  84. package/src/components/toggle-list.tsx +6 -8
  85. package/src/components/ui/confirm-dialog.tsx +47 -7
  86. package/src/components/ui/data-table/types.ts +8 -0
  87. package/src/components/ui/display.tsx +17 -2
  88. package/src/components/ui/index.ts +1 -1
  89. package/src/components/ui/stat-grid.tsx +4 -0
  90. package/src/components/ui/status.tsx +13 -1
  91. package/src/components/ui/table-layout.ts +2 -1
  92. package/src/components/use-pane-notice-footer.tsx +16 -3
  93. package/src/data/config/store/index.ts +31 -0
  94. package/src/data/config/store/node.ts +61 -11
  95. package/src/data/config/store/normalize.ts +4 -6
  96. package/src/data/config/store/shared-file.ts +309 -0
  97. package/src/data/profile-merge.ts +299 -0
  98. package/src/data/sqlite/checkpointer.ts +11 -1
  99. package/src/data/sqlite/database.ts +1 -1
  100. package/src/data/ticker-repository.ts +134 -10
  101. package/src/data/ticker-store.ts +67 -0
  102. package/src/data/ticker-writes.ts +5 -0
  103. package/src/i18n/es.ts +27 -0
  104. package/src/i18n/ja.ts +27 -0
  105. package/src/i18n/ko.ts +27 -0
  106. package/src/i18n/zh-cn.ts +27 -0
  107. package/src/i18n/zh-tw.ts +27 -0
  108. package/src/layout-marketplace/gallery-desktop.tsx +2 -2
  109. package/src/market-data/ah-pair.ts +103 -0
  110. package/src/market-data/depositary-pair.ts +6 -2
  111. package/src/market-data/hooks.tsx +33 -2
  112. package/src/market-data/market/change-basis.ts +2 -1
  113. package/src/market-data/market/header-market.ts +11 -0
  114. package/src/market-data/split-terms.ts +28 -0
  115. package/src/plugins/builtin/account-management/footer.ts +1 -1
  116. package/src/plugins/builtin/account-management/keyboard.ts +4 -0
  117. package/src/plugins/builtin/account-management/model.ts +1 -0
  118. package/src/plugins/builtin/account-management/pane.tsx +75 -7
  119. package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
  120. package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
  121. package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
  122. package/src/plugins/builtin/alerts/cli-move.ts +2 -2
  123. package/src/plugins/builtin/alerts/cli.ts +36 -30
  124. package/src/plugins/builtin/alerts/constants.ts +10 -0
  125. package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
  126. package/src/plugins/builtin/alerts/format.ts +24 -8
  127. package/src/plugins/builtin/alerts/index.tsx +38 -9
  128. package/src/plugins/builtin/alerts/move-checks.ts +7 -0
  129. package/src/plugins/builtin/alerts/pane.tsx +1 -1
  130. package/src/plugins/builtin/alerts/quotes.ts +26 -2
  131. package/src/plugins/builtin/alerts/scheduled.ts +6 -1
  132. package/src/plugins/builtin/alerts/types.ts +7 -0
  133. package/src/plugins/builtin/analytics/manual-value.ts +61 -0
  134. package/src/plugins/builtin/analytics/risk-book.ts +7 -7
  135. package/src/plugins/builtin/analytics/risk-client.ts +26 -13
  136. package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
  137. package/src/plugins/builtin/analytics/risk-model.ts +92 -4
  138. package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
  139. package/src/plugins/builtin/awards/pane.tsx +1 -1
  140. package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
  141. package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
  142. package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
  143. package/src/plugins/builtin/chart-composer/cli-options.ts +4 -2
  144. package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
  145. package/src/plugins/builtin/chart-composer/pane.tsx +5 -2
  146. package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
  147. package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
  148. package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
  149. package/src/plugins/builtin/company-kpis/headless.ts +9 -4
  150. package/src/plugins/builtin/company-kpis/latest.ts +45 -0
  151. package/src/plugins/builtin/company-kpis/model.ts +38 -8
  152. package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
  153. package/src/plugins/builtin/composite/alt-data.ts +20 -0
  154. package/src/plugins/builtin/composite/application.ts +14 -0
  155. package/src/plugins/builtin/composite/broker.ts +12 -0
  156. package/src/plugins/builtin/composite/credit.ts +33 -0
  157. package/src/plugins/builtin/composite/crypto.ts +10 -0
  158. package/src/plugins/builtin/composite/earnings.ts +12 -0
  159. package/src/plugins/builtin/composite/filings.ts +13 -0
  160. package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
  161. package/src/plugins/builtin/composite/global-markets.ts +12 -0
  162. package/src/plugins/builtin/composite/options-volatility.ts +23 -0
  163. package/src/plugins/builtin/composite/ownership.ts +23 -0
  164. package/src/plugins/builtin/composite/portfolio.ts +10 -0
  165. package/src/plugins/builtin/composite/quant.ts +15 -0
  166. package/src/plugins/builtin/composite/rates-macro.ts +30 -0
  167. package/src/plugins/builtin/composite/screeners.ts +11 -0
  168. package/src/plugins/builtin/composite/shared.ts +11 -0
  169. package/src/plugins/builtin/composite/ticker-core.ts +36 -0
  170. package/src/plugins/builtin/congress-trades/headless.ts +31 -3
  171. package/src/plugins/builtin/correlation/index.tsx +13 -17
  172. package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
  173. package/src/plugins/builtin/dividend-yield/client.ts +57 -16
  174. package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
  175. package/src/plugins/builtin/dividend-yield/model.ts +4 -3
  176. package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
  177. package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
  178. package/src/plugins/builtin/dividend-yield/types.ts +4 -0
  179. package/src/plugins/builtin/dividend-yield/view.ts +23 -12
  180. package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
  181. package/src/plugins/builtin/earnings/headless.ts +7 -4
  182. package/src/plugins/builtin/earnings/history-model.ts +6 -4
  183. package/src/plugins/builtin/earnings/history-table.ts +4 -3
  184. package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
  185. package/src/plugins/builtin/econ/calendar-model.ts +16 -0
  186. package/src/plugins/builtin/econ/index.tsx +3 -0
  187. package/src/plugins/builtin/equity-screener/headless.ts +4 -1
  188. package/src/plugins/builtin/equity-screener/model.ts +7 -6
  189. package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
  190. package/src/plugins/builtin/exposure/model.ts +10 -0
  191. package/src/plugins/builtin/exposure/pane.tsx +10 -3
  192. package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
  193. package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
  194. package/src/plugins/builtin/fx-matrix/index.tsx +23 -5
  195. package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
  196. package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
  197. package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
  198. package/src/plugins/builtin/mna/detail.tsx +67 -6
  199. package/src/plugins/builtin/mna/headless.ts +128 -13
  200. package/src/plugins/builtin/mna/model.ts +219 -16
  201. package/src/plugins/builtin/mna/pane.tsx +34 -6
  202. package/src/plugins/builtin/money-markets/model.ts +14 -5
  203. package/src/plugins/builtin/money-markets/pane.tsx +4 -3
  204. package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
  205. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
  206. package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
  207. package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
  208. package/src/plugins/builtin/pe-band/client.ts +13 -1
  209. package/src/plugins/builtin/pe-band/headless.ts +2 -2
  210. package/src/plugins/builtin/pe-band/model.ts +63 -10
  211. package/src/plugins/builtin/pe-band/pane.tsx +5 -5
  212. package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
  213. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
  214. package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
  215. package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
  216. package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
  217. package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
  218. package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
  219. package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
  220. package/src/plugins/builtin/research/corporate-actions-pane.tsx +5 -1
  221. package/src/plugins/builtin/research/event-model.ts +31 -13
  222. package/src/plugins/builtin/research/headless.ts +8 -1
  223. package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
  224. package/src/plugins/builtin/sectors/index.tsx +6 -9
  225. package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
  226. package/src/plugins/builtin/shared/earnings-report.ts +19 -4
  227. package/src/plugins/builtin/shared/report-freshness.ts +2 -3
  228. package/src/plugins/builtin/supply-chain/client.ts +34 -9
  229. package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
  230. package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
  231. package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
  232. package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
  233. package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
  234. package/src/plugins/builtin/supply-chain/headless.ts +19 -4
  235. package/src/plugins/builtin/supply-chain/model.ts +50 -6
  236. package/src/plugins/builtin/supply-chain/pane.tsx +76 -16
  237. package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
  238. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
  239. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +51 -1
  240. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +25 -14
  241. package/src/plugins/builtin/ticker-detail/overview/model.ts +17 -1
  242. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
  243. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +9 -2
  244. package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
  245. package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
  246. package/src/plugins/builtin/volatility/model.ts +17 -0
  247. package/src/plugins/builtin/volatility/pane.tsx +13 -4
  248. package/src/plugins/builtin/world-indices/index.tsx +2 -0
  249. package/src/plugins/builtin/world-indices/table.tsx +15 -0
  250. package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
  251. package/src/plugins/builtin/world-venue-map/headless.ts +28 -16
  252. package/src/plugins/builtin/world-venue-map/index.ts +19 -6
  253. package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
  254. package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
  255. package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
  256. package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
  257. package/src/plugins/builtin/world-venue-map/place.ts +119 -0
  258. package/src/plugins/catalog-data.ts +20 -0
  259. package/src/plugins/catalog-lazy.ts +51 -0
  260. package/src/plugins/catalog-ui.ts +16 -18
  261. package/src/plugins/host-smoke.ts +5 -2
  262. package/src/portfolio/allocation.ts +79 -19
  263. package/src/portfolio/cash-balances.ts +76 -0
  264. package/src/portfolio/mutations.ts +43 -8
  265. package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
  266. package/src/renderers/desktop/window-layouts.ts +14 -0
  267. package/src/renderers/dom/data-table/row.tsx +2 -0
  268. package/src/renderers/dom/host/tabs.tsx +57 -8
  269. package/src/renderers/dom/styles.css +13 -5
  270. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
  271. package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
  272. package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
  273. package/src/renderers/electrobun/shared/protocol.ts +4 -0
  274. package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
  275. package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
  276. package/src/series/standalone-catalog.ts +5 -4
  277. package/src/series/standalone.ts +13 -7
  278. package/src/sources/gloomberb-cloud/index.ts +14 -3
  279. package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
  280. package/src/sources/provider-router/financials.ts +20 -13
  281. package/src/sources/provider-router/index.ts +4 -0
  282. package/src/sources/provider-router/search.ts +1 -0
  283. package/src/sync/collections-contributor.ts +3 -1
  284. package/src/sync/config-merge.ts +10 -1
  285. package/src/sync/sanitize.ts +26 -2
  286. package/src/tickers/company-name-listing.ts +16 -2
  287. package/src/tickers/listing-fate.ts +12 -8
  288. package/src/tickers/renamed-listings.ts +43 -10
  289. package/src/tickers/search/home-listing.ts +28 -0
  290. package/src/tickers/search/index.ts +19 -7
  291. package/src/tickers/terminal-codes.ts +11 -1
  292. package/src/time-series/resolve.ts +3 -1
  293. package/src/time-series/spec.ts +2 -2
  294. package/src/time-series/types.ts +1 -1
  295. package/src/types/data-provider.ts +11 -0
  296. package/src/types/financials.ts +39 -3
  297. package/src/types/ticker.ts +10 -2
  298. package/src/utils/cli-output.ts +1 -1
  299. package/src/utils/declared-dividends.ts +13 -1
  300. package/src/utils/dividend-cash.ts +5 -1
  301. package/src/utils/forward-dividend.ts +4 -3
  302. package/src/utils/remove-folder.ts +37 -0
  303. package/src/utils/trailing-dividend.ts +1 -1
  304. package/src/plugins/builtin/composite-plugins.ts +0 -285
@@ -19,7 +19,7 @@ import {
19
19
  } from "./ticker-changes";
20
20
  import { isQuoteBeforeLatestSession, isQuoteStaleForCurrentSession } from "../market-data/quotes/freshness";
21
21
  import { formatMarketPriceWithCurrency, quoteFormatOptions } from "../market-data/market/format";
22
- import { canonicalExchange, isUsListingExchange, parsePublicTickerKey, resolveExchangeTimeZone } from "../utils/exchanges";
22
+ import { canonicalExchange, exchangeLabel, isUsListingExchange, parsePublicTickerKey, resolveExchangeTimeZone } from "../utils/exchanges";
23
23
  import { zonedDateKey } from "../utils/zoned-date-time";
24
24
  import { delistingLabel } from "../market-data/quotes/delisting";
25
25
 
@@ -295,19 +295,23 @@ export function isVenueAbroad(venue: string): boolean {
295
295
  }
296
296
 
297
297
  /**
298
- * "SXR8 -> XETRA" for a bare symbol the data service read on its home listing
299
- * abroad, as it reads a symbol with no US listing whose listings belong to one
300
- * company or fund: a row that shows the symbol as typed says which listing it
301
- * is. Null for a named or saved venue, and for a venue the app does not place
302
- * outside the US (a US exchange, OTC, a futures exchange).
298
+ * "Z74 has no US listing; it trades on Singapore Exchange (SGX), in SGD." for
299
+ * a bare symbol the data service read on its home listing abroad, as it reads
300
+ * a symbol with no US listing whose listings belong to one company or fund: a
301
+ * row that shows the symbol as typed says which listing it is, in the words
302
+ * `watchlist add` says it. Null for a named or saved venue, and for a venue
303
+ * the app does not place outside the US (a US exchange, OTC, a futures
304
+ * exchange).
303
305
  */
304
306
  export function bareListingNote(
305
307
  listing: { symbol: string; request: { exchange: string } },
306
- quote: Pick<Quote, "listingExchangeName" | "exchangeName"> | null | undefined,
308
+ quote: Pick<Quote, "listingExchangeName" | "exchangeName" | "currency"> | null | undefined,
307
309
  ): string | null {
308
310
  if (listing.request.exchange || !quote || !/^[A-Z0-9]{1,10}$/.test(listing.symbol)) return null;
309
311
  const venue = canonicalExchange(quote.listingExchangeName || quote.exchangeName);
310
- return isVenueAbroad(venue) ? `${listing.symbol} -> ${venue}` : null;
312
+ if (!isVenueAbroad(venue)) return null;
313
+ const unit = quote.currency?.trim();
314
+ return `${listing.symbol} has no US listing; it trades on ${exchangeLabel(venue)}${unit ? `, in ${unit}` : ""}.`;
311
315
  }
312
316
 
313
317
  /** `ListingFate` from a listing's quote (null when it has none) and its ticker changes. */
@@ -16,15 +16,27 @@ export interface RenamedListing {
16
16
  exchange: string;
17
17
  /** Its name now. */
18
18
  name: string;
19
- /** The names people still search for, the one it went by first: its brand, then its legal name. */
20
- formerNames: readonly [string, ...string[]];
19
+ /**
20
+ * The names people still search for, the one it went by first: its brand, then its legal name. Empty when the
21
+ * old name went with another company (Tata Motors Limited is now the demerged commercial-vehicle business), so
22
+ * only the old symbol, never a name, leads to this line.
23
+ */
24
+ formerNames: readonly string[];
25
+ /** What the old line is called in a sentence when no former name leads to it: "Tata Motors". */
26
+ formerLabel?: string;
27
+ /** How the new line is written in the app's own key (`TMPV:NSE`), where the venue's suffix is not how it is read. */
28
+ shownAs?: string;
21
29
  /** The day a class that no longer trades was converted into the `to` line (YYYY-MM-DD). */
22
30
  convertedOn?: string;
31
+ /** The day the venue renamed the line, when its notice says so (YYYY-MM-DD). */
32
+ renamedOn?: string;
33
+ /** A business demerged out of the line around the rename, listed on its own: the old symbol is never that company. */
34
+ demerged?: { symbol: string; name: string; business: string };
23
35
  }
24
36
 
25
37
  /** The name it went by: "Eletrobras". */
26
38
  function renamedListingFormerName(listing: RenamedListing): string {
27
- return listing.formerNames[0];
39
+ return listing.formerNames[0] ?? listing.formerLabel ?? listing.from;
28
40
  }
29
41
 
30
42
  /**
@@ -40,10 +52,22 @@ function renamedListingFormerName(listing: RenamedListing): string {
40
52
  */
41
53
  const ELETROBRAS = ["Eletrobras", "Centrais Elétricas Brasileiras"] as const;
42
54
  const AXIA_PREFERRED_CONVERTED = "2026-06-05";
55
+ /**
56
+ * NSE renamed Tata Motors' line, TATAMOTORS, to TMPV (Tata Motors Passenger
57
+ * Vehicles Limited) effective 24 Oct 2025 (NSE circular CML70875; NSE's
58
+ * symbol change list has the same row), and BSE renamed it the same day. The
59
+ * commercial-vehicle business was demerged out of it (record date 14 Oct
60
+ * 2025) and listed as TMCV on 12 Nov 2025; that company took the legal name
61
+ * Tata Motors Limited, so the old code follows the line, TMPV, never the
62
+ * name, and no name leads here.
63
+ */
64
+ const TATA_MOTORS = { to: "TMPV", name: "Tata Motors Passenger Vehicles", formerNames: [], formerLabel: "Tata Motors", renamedOn: "2025-10-24" } as const;
43
65
  const RENAMED_LISTINGS: readonly RenamedListing[] = [
44
66
  { from: "ELET3", to: "AXIA3", suffix: ".SA", exchange: "B3", name: "AXIA Energia", formerNames: ELETROBRAS },
45
67
  ...["ELET6", "AXIA6", "ELET5", "AXIA5"].map((from): RenamedListing => ({ from, to: "AXIA3", suffix: ".SA", exchange: "B3",
46
68
  name: "AXIA Energia", formerNames: ELETROBRAS, convertedOn: AXIA_PREFERRED_CONVERTED })),
69
+ { ...TATA_MOTORS, from: "TATAMOTORS", suffix: ".NS", exchange: "NSE", shownAs: "TMPV:NSE", demerged: { symbol: "TMCV:NSE", name: "Tata Motors Limited", business: "commercial-vehicle" } },
70
+ { ...TATA_MOTORS, from: "TATAMOTORS", suffix: ".BO", exchange: "BSE", shownAs: "TMPV:BSE", demerged: { symbol: "TMCV:BSE", name: "Tata Motors Limited", business: "commercial-vehicle" } },
47
71
  ];
48
72
 
49
73
  /** "5 Jun 2026". */
@@ -53,7 +77,7 @@ function conversionDay(date: string): string {
53
77
 
54
78
  /** `AXIA3.SA`: the new listing as `quote` takes it. */
55
79
  export function renamedListingSymbol(listing: RenamedListing): string {
56
- return `${listing.to}${listing.suffix}`;
80
+ return listing.shownAs ?? `${listing.to}${listing.suffix}`;
57
81
  }
58
82
 
59
83
  /**
@@ -78,9 +102,14 @@ export function renamedListingFor(query: string): RenamedListing | null {
78
102
  export function renamedListingHint(listing: RenamedListing): string {
79
103
  const now = renamedListingSymbol(listing);
80
104
  const named = `${now} (${listing.name}, formerly ${renamedListingFormerName(listing)})`;
81
- return listing.convertedOn
82
- ? `It was converted into ${named} on ${conversionDay(listing.convertedOn)}: \`gloom quote ${now}\`.`
83
- : `It is now ${named}: \`gloom quote ${now}\`.`;
105
+ if (listing.convertedOn) return `It was converted into ${named} on ${conversionDay(listing.convertedOn)}: \`gloom quote ${now}\`.`;
106
+ return `It is now ${named}${listing.demerged ? `; ${demergedClause(listing)}` : ""}: \`gloom quote ${now}\`.`;
107
+ }
108
+
109
+ /** "its commercial-vehicle business was demerged into TMCV:NSE (Tata Motors Limited)": the company the old code is not. */
110
+ function demergedClause(listing: RenamedListing): string {
111
+ const { business, symbol, name } = listing.demerged!;
112
+ return `its ${business} business was demerged into ${symbol} (${name})`;
84
113
  }
85
114
 
86
115
  /** What search says the new line was: "Eletrobras (ELET3)", or "Eletrobras (ELET6, converted 5 Jun 2026)". */
@@ -100,7 +129,11 @@ export function renamedListingReadAs(typed: string, listing: RenamedListing): st
100
129
  // A name is quoted, as every name read as a listing is; the CLI puts it back in the user's spelling.
101
130
  const shown = listing.formerNames.some((name) => normalizeSearchText(word) === normalizeSearchText(name)) ? `"${word}"` : word;
102
131
  const now = renamedListingSymbol(listing);
103
- return listing.convertedOn
104
- ? `Read ${shown} as ${now}: those preferred shares were converted into ${listing.name}'s common shares on ${conversionDay(listing.convertedOn)}.`
105
- : `Read ${shown} as ${now}: ${renamedListingFormerName(listing)} is ${listing.name} now.`;
132
+ if (listing.convertedOn) return `Read ${shown} as ${now}: those preferred shares were converted into ${listing.name}'s common shares on ${conversionDay(listing.convertedOn)}.`;
133
+ // One line: the rename, and the company the old code is not.
134
+ if (listing.renamedOn) {
135
+ return `Read ${shown} as ${now}: ${listing.exchange} renamed ${listing.from} ${listing.to} (${listing.name}) on ${conversionDay(listing.renamedOn)}`
136
+ + `${listing.demerged ? `; ${demergedClause(listing)}` : ""}.`;
137
+ }
138
+ return `Read ${shown} as ${now}: ${renamedListingFormerName(listing)} is ${listing.name} now.`;
106
139
  }
@@ -267,6 +267,34 @@ export function withNamedCompanyAfterUsLead<T extends TickerSearchCandidate>(ite
267
267
  return [...items.slice(0, at), ...named, ...rest];
268
268
  }
269
269
 
270
+ /**
271
+ * The lines the service marks with the word as typed (or whose code it is) on
272
+ * the user's own market, ahead of every other row but the saved ones: for a
273
+ * desk whose market is Hong Kong (the header's Hang Seng, the default of a
274
+ * machine in Hong Kong), "aia" is AIA Group's 1299 before the iShares Asia 50
275
+ * ETF's AIA, "mtr" MTR Corporation's 0066 before Mesa Royalty Trust, "hsbc"
276
+ * HSBC's 0005 before its London line and its New York receipt, "catl" CATL's
277
+ * 3750 before Catalyst Acquisition and its Shenzhen line. Only a company's own
278
+ * shares on that venue lead (no receipt, fund or line quoting shares listed
279
+ * elsewhere), behind the saved rows the list opens with, and only for a word
280
+ * typed without a venue: `AIA:NASDAQ` and
281
+ * `AIA US` ask for that line. A market in the US changes nothing: a US ticker
282
+ * already leads (`withNamedCompanyAfterUsLead`).
283
+ */
284
+ export function withHomeVenueLead<T extends TickerSearchCandidate>(items: T[], query: string, homeVenue: string | null | undefined): T[] {
285
+ const venue = canonicalExchange(homeVenue ?? "");
286
+ if (!venue || isUsListingExchange(venue) || isQualifiedTickerQuery(query)) return items;
287
+ const typed = normalizeTickerSymbol(query);
288
+ const lead = items.filter((item) => isListedEquity(item) && item.instrumentClass === "equity" && !!item.result
289
+ && candidateExchange(item) === venue && listingDistance(item) === 0
290
+ && (namedByService(query, item.result) || normalizeTickerSymbol(item.symbol) === typed));
291
+ if (lead.length === 0) return items;
292
+ // Behind the saved rows the list opens with.
293
+ const rest = items.filter((item) => !lead.includes(item));
294
+ const at = rest.findIndex((item) => item.kind !== "ticker" && !item.saved);
295
+ return at < 0 ? [...rest, ...lead] : [...rest.slice(0, at), ...lead, ...rest.slice(at)];
296
+ }
297
+
270
298
  /** `items` with `home` moved just ahead of `lead`. */
271
299
  function moveAhead<T>(items: readonly T[], home: T, lead: T): T[] {
272
300
  const rest = items.filter((item) => item !== home);
@@ -41,7 +41,7 @@ import { endsInLegalForm, readNearMissListing, readVenueFirstListing, readTermin
41
41
  import { isProviderBusy, ProviderBusyError, SEARCH_BUSY_MESSAGE } from "../../sources/provider-errors";
42
42
  import { settleWithin } from "../../utils/async-deadline";
43
43
  import { companyNameExtraWords } from "../company-name";
44
- import { withFundReceiptsAsFunds, withHomeListingLead, withNamedCompanyAfterUsLead } from "./home-listing";
44
+ import { withFundReceiptsAsFunds, withHomeListingLead, withHomeVenueLead, withNamedCompanyAfterUsLead } from "./home-listing";
45
45
  import { answeredInFull, rememberSearchAnswer, withKnownListings } from "./listing-index";
46
46
  import { savedAbroadForBareSymbol, savedUsListingOf } from "./bare-symbol";
47
47
  import { delistingLabel, parseListingWithdrawal, withdrawalLabel } from "../../market-data/quotes/delisting";
@@ -284,6 +284,7 @@ export async function searchTickerCandidates({
284
284
  totalLimit = 8,
285
285
  includeOptionContracts = true,
286
286
  onPartial,
287
+ homeVenue,
287
288
  }: {
288
289
  query: string;
289
290
  tickers: ReadonlyMap<string, TickerRecord>;
@@ -292,6 +293,8 @@ export async function searchTickerCandidates({
292
293
  localLimit?: number;
293
294
  totalLimit?: number;
294
295
  includeOptionContracts?: boolean;
296
+ /** The venue of the user's own market, whose lines of the company a word names lead (`withHomeVenueLead`). */
297
+ homeVenue?: string | null;
295
298
  /** Called when a slower, richer source improves results already returned. */
296
299
  onPartial?: (candidates: TickerSearchCandidate[]) => void;
297
300
  }): Promise<TickerSearchCandidate[]> {
@@ -304,6 +307,7 @@ export async function searchTickerCandidates({
304
307
  totalLimit,
305
308
  // A search that hides contracts still shows them when asked: "AAPL OPT".
306
309
  includeOptionContracts: includeOptionContracts || parseAssetClassQuery(query)?.code === "OPT",
310
+ homeVenue,
307
311
  });
308
312
  const renamed = renamedListingFor(rawQuery);
309
313
  const [searched, renamedRow] = await Promise.all([
@@ -339,6 +343,7 @@ export function buildTickerSearchCandidates({
339
343
  localLimit = 6,
340
344
  totalLimit = 8,
341
345
  includeOptionContracts = true,
346
+ homeVenue,
342
347
  }: {
343
348
  query: string;
344
349
  tickers: ReadonlyMap<string, TickerRecord>;
@@ -346,6 +351,8 @@ export function buildTickerSearchCandidates({
346
351
  localLimit?: number;
347
352
  totalLimit?: number;
348
353
  includeOptionContracts?: boolean;
354
+ /** The venue of the user's own market (`homeMarketVenue`): its lines of the company a word names lead (`withHomeVenueLead`). */
355
+ homeVenue?: string | null;
349
356
  }): TickerSearchCandidate[] {
350
357
  const filteredProviderResults = includeOptionContracts
351
358
  ? providerResults
@@ -363,10 +370,10 @@ export function buildTickerSearchCandidates({
363
370
  );
364
371
  // A receipt on a fund is the fund's line, never a company's primary listing over it (HK01 on SET for the Tracker Fund).
365
372
  const providerItems = withFundReceiptsAsFunds(createProviderTickerSearchCandidates(filteredProviderResults, tickers, candidateOptions));
366
- const ranked = withNamedCompanyAfterUsLead(
373
+ const ranked = withHomeVenueLead(withNamedCompanyAfterUsLead(
367
374
  withHomeListingLead(withSuccessorFirst(rankTickerSearchItems([...localItems, ...providerItems], query), query), query),
368
375
  query,
369
- );
376
+ ), query, homeVenue);
370
377
  return limitTickerSearchCandidates(companyListingsFirst(assignTickerSearchCategories(ranked, query), query), totalLimit, localLimit);
371
378
  }
372
379
 
@@ -816,7 +823,7 @@ async function searchProviderResults(
816
823
  };
817
824
  let busy = false;
818
825
  let unreachable: unknown = null;
819
- await Promise.all(searchQueries.map(async (searchQuery, index) => {
826
+ const ask = async (searchQuery: string, index: number) => {
820
827
  try {
821
828
  const results = await dataProvider.search(searchQuery, {
822
829
  ...searchContext,
@@ -838,7 +845,11 @@ async function searchProviderResults(
838
845
  else if (isProviderBusy(error)) busy = true;
839
846
  else logFailure("tickers-search", "Could not search ticker spelling")(error);
840
847
  }
841
- }));
848
+ };
849
+ // A share class written without its mark (BRKB for BRK.B) is guessed at beside the symbol's own search, unless the
850
+ // symbol is known to be a US stock: NVDA is Nvidia, and NVD-A and NVD.A are two more searches for nothing.
851
+ const notAsked = dataProvider.knownUsStock?.(query) ? new Set(compactShareClassAliases(query)) : new Set<string>();
852
+ await Promise.all(searchQueries.map((searchQuery, index) => notAsked.has(searchQuery) ? null : ask(searchQuery, index)));
842
853
 
843
854
  // Catalogues can omit exact market symbols or return a crypto pair from a
844
855
  // different venue. Verify the requested quote before accepting an alias.
@@ -949,12 +960,13 @@ function buildProviderSearchQueries(query: string): string[] {
949
960
 
950
961
  if (!symbolLike) queries.add(trimmedQuery);
951
962
  for (const alias of buildSymbolAliases(trimmedQuery)) queries.add(alias);
952
- for (const alias of buildCompactShareClassAliases(trimmedQuery)) queries.add(alias);
963
+ for (const alias of compactShareClassAliases(trimmedQuery)) queries.add(alias);
953
964
  queries.add(trimmedQuery);
954
965
  return [...queries].slice(0, 4);
955
966
  }
956
967
 
957
- function buildCompactShareClassAliases(query: string): string[] {
968
+ /** The share-class spellings a four or five letter code with a class letter at its end may be (NVDA: NVD-A, NVD.A). */
969
+ function compactShareClassAliases(query: string): string[] {
958
970
  const normalized = normalizeTickerSymbol(query);
959
971
  if (!/^[A-Z]{4,5}$/.test(normalized)) return [];
960
972
  const shareClass = normalized.slice(-1);
@@ -126,15 +126,25 @@ export const BLOOMBERG_MARKETS: Readonly<Record<string, BloombergMarket>> = {
126
126
  PM: { venues: [], name: "Philippine Stock Exchange" },
127
127
  AU: at("ASX"),
128
128
  NZ: at("NZX"),
129
- CN: at("TSX", "TSXV"),
129
+ CN: at("TSX", "TSXV", "CSE"),
130
130
  CT: at("TSX"),
131
131
  CV: at("TSXV"),
132
+ CF: at("CSE"),
132
133
  MM: at("BMV"),
133
134
  BZ: at("B3"),
134
135
  BS: at("B3"),
135
136
  AR: at("BYMA"),
136
137
  SJ: at("JSE"),
137
138
  IT: at("TASE"),
139
+ IR: at("ICEX"),
140
+ TI: at("BIST"),
141
+ AB: { venues: ["TADAWUL"], hint: "Bloomberg and Tadawul codes differ there: type the Tadawul code, such as 2222 AB for Saudi Aramco." },
142
+ QD: at("QE"),
143
+ BI: at("BHB"),
144
+ DB: at("DFM"),
145
+ OM: at("MSX"),
146
+ KK: at("KUWAIT"),
147
+ EY: at("EGX"),
138
148
  };
139
149
 
140
150
  /** Bloomberg's index tickers the quote sources carry, by the symbol each is quoted as. */
@@ -1148,7 +1148,9 @@ async function resolveChartSpecPass(
1148
1148
  { ...comparisonOptions, atSessionClose: timed.timing.atSessionClose, closedEnds: timed.timing.closedEnds });
1149
1149
  }
1150
1150
  const splitNotice = priceComparison?.legs ? await comparedSplitNotice(spec, priceComparison, rawSeries, loadDistributions, comparisonOptions.now) : null;
1151
- const displayBounds = comparisonDisplayBounds(bounds, priceComparison);
1151
+ const comparedBounds = comparisonDisplayBounds(bounds, priceComparison);
1152
+ const displayBounds = spec.viewport.dateWindow?.endAtLatestObservation && !requestBounds
1153
+ ? endAtNewestObservation(comparedBounds, rawSeries) : comparedBounds;
1152
1154
  const comparisonBounds = priceComparison && priceComparison.start !== null
1153
1155
  ? priceComparison : bounds;
1154
1156
  const baseSeries = rawSeries
@@ -191,7 +191,7 @@ function normalizeSource(value: unknown): ChartSeriesSource | null {
191
191
  };
192
192
  }
193
193
 
194
- function normalizedDateWindow(value: unknown): { start: string; end: string } | undefined {
194
+ function normalizedDateWindow(value: unknown): ChartSpec["viewport"]["dateWindow"] {
195
195
  const window = recordOrNull(value);
196
196
  const start = nonEmptyString(window?.start);
197
197
  const end = nonEmptyString(window?.end);
@@ -199,7 +199,7 @@ function normalizedDateWindow(value: unknown): { start: string; end: string } |
199
199
  const startTime = Date.parse(start);
200
200
  const endTime = Date.parse(end);
201
201
  if (!Number.isFinite(startTime) || !Number.isFinite(endTime) || startTime > endTime) return undefined;
202
- return { start, end };
202
+ return { start, end, ...(window?.endAtLatestObservation === true ? { endAtLatestObservation: true } : {}) };
203
203
  }
204
204
 
205
205
  function normalizePanel(value: unknown, index: number, seen: Set<string>): ChartPanelSpec | null {
@@ -105,7 +105,7 @@ export interface ChartPanelSpec {
105
105
  export interface ChartViewportSpec {
106
106
  range: TimeRange;
107
107
  resolution: ChartResolution;
108
- dateWindow?: { start: string; end: string };
108
+ dateWindow?: { start: string; end: string; endAtLatestObservation?: boolean };
109
109
  /** Optional latest-observation cap, useful for period-based financial views. */
110
110
  maxPoints?: number;
111
111
  /** Intraday market history includes pre-market and after-hours bars where the venue has them. */
@@ -231,6 +231,11 @@ export interface SearchRequestContext {
231
231
  * still waited for: its answer is the search's.
232
232
  */
233
233
  interactive?: boolean;
234
+ /**
235
+ * `always` asks for perpetual markets beside the listings for every query. Without it, a command that looks up
236
+ * one bare symbol the listings show to be a US stock does not ask for them.
237
+ */
238
+ perpetuals?: "always";
234
239
  /**
235
240
  * Rows to ask a catalogue for. Every listing of a symbol several companies
236
241
  * use (CAR: Avis, Carrefour, CAR Group) takes more than a keystroke's ten.
@@ -373,6 +378,12 @@ export interface AssetDataProvider {
373
378
  * all, or when another source (a connected broker) adds rows of its own.
374
379
  */
375
380
  searchBatch?(queries: string[], options?: { limit?: number; signal?: AbortSignal }): Promise<Map<string, InstrumentSearchResult[]> | null>;
381
+ /**
382
+ * True of a symbol known, before any request, to be a stock on a US exchange. A lookup of one is not searched for
383
+ * its share-class spellings (NVDA as NVD-A) and asks for no perpetual contracts. Set by a command line that
384
+ * ships the listings; absent elsewhere, where every lookup asks.
385
+ */
386
+ knownUsStock?(symbol: string): boolean;
376
387
  getEarningsCalendar?(symbols: string[], context?: MarketDataRequestContext): Promise<EarningsEvent[]>;
377
388
  getSecFilingDocuments?(filing: SecFilingItem): Promise<SecFilingDocument[]>;
378
389
  getSecFilingContent?(filing: SecFilingItem): Promise<string | null>;
@@ -666,6 +666,8 @@ export interface AnalystResearchData {
666
666
  export interface DividendAction {
667
667
  exDate: string;
668
668
  amount: number;
669
+ payDate?: string;
670
+ recordDate?: string;
669
671
  /**
670
672
  * Who published the row when it is not the listing's own history: a fund's
671
673
  * sponsor, for a distribution the history lacks (iShares, SPDR, J.P. Morgan,
@@ -676,13 +678,14 @@ export interface DividendAction {
676
678
 
677
679
  /**
678
680
  * A distribution the issuer has declared and not yet paid, as the source
679
- * states it. Kept apart from the paid `dividends`: no history, yield or growth
680
- * figure takes it.
681
+ * states it. Kept apart from paid `dividends`; issuer-confirmed declarations
682
+ * enter ex-date-based cash figures once ex-dated, with any conversion estimate.
681
683
  */
682
684
  export interface DeclaredDividendAction {
683
685
  exDate: string;
684
686
  /** Per share, in the listing's dividend currency (`currency`). */
685
687
  amount: number;
688
+ cashEstimate?: DividendCashEstimate;
686
689
  declarationDate?: string;
687
690
  recordDate?: string;
688
691
  payDate?: string;
@@ -690,6 +693,14 @@ export interface DeclaredDividendAction {
690
693
  special?: true;
691
694
  }
692
695
 
696
+ /** declaredAmount is in declaredCurrency's major unit; the enclosing amount keeps the history's currency/unit. */
697
+ export interface DividendCashEstimate {
698
+ declaredCurrency: string;
699
+ declaredAmount?: number;
700
+ fixingDate?: string;
701
+ basis: string;
702
+ }
703
+
693
704
  export interface SplitAction {
694
705
  date: string;
695
706
  description?: string;
@@ -757,12 +768,37 @@ export interface CorporateActionsData {
757
768
  dividendsAsOf?: string;
758
769
  splits: SplitAction[];
759
770
  earnings: EarningsAction[];
771
+ /** Businesses demerged out of the listing into companies of their own; absent where none is on record and from older servers. */
772
+ demergers?: DemergerAction[];
760
773
  }
761
774
 
762
- /** Paid rows as their company declared them, in `currency` (its major unit). */
775
+ /**
776
+ * A business demerged out of a listing (Tata Motors' commercial vehicles into
777
+ * TMCV): the listing's price falls by that business's value on the ex-date,
778
+ * which is no market move.
779
+ */
780
+ export interface DemergerAction {
781
+ /** The first session the listing traded without the business, YYYY-MM-DD. */
782
+ exDate: string;
783
+ recordDate?: string;
784
+ /** The company the business went to, as it lists, and the day it first traded (null until it lists). */
785
+ successor: { symbol: string; exchange?: string; name?: string; listedOn?: string | null };
786
+ /** What the business does: "commercial vehicles". */
787
+ business?: string;
788
+ /** Shares of the demerged company per share of the listing. */
789
+ ratio?: number;
790
+ source?: string;
791
+ }
792
+
793
+ /** Declaration amounts (rows and announced.amount) are in the major unit of `currency`.
794
+ * announced.paidAmount uses the corporate-action history's currency/unit, like dividends. */
763
795
  export interface DeclaredCash {
764
796
  currency: string;
765
797
  rows: DividendAction[];
798
+ announced?: { exDate: string; payDate: string; amount: number; paidAmount?: number; fixingDate?: string };
799
+ fetchedAt?: string;
800
+ stale?: boolean;
801
+ verification?: "unavailable";
766
802
  }
767
803
 
768
804
  export interface CompanyProfile {
@@ -79,10 +79,18 @@ export interface Portfolio {
79
79
  /** Set on paper portfolios shared with a team; the server holds the items. */
80
80
  teamId?: string;
81
81
  /**
82
- * Cash held beside the positions, entered by hand. A broker account that
83
- * reports its own cash is shown instead of this.
82
+ * Cash held beside the positions, entered by hand: the first balance, in one
83
+ * currency. A broker account that reports its own cash is shown instead of
84
+ * this. Builds before several currencies read only this one.
84
85
  */
85
86
  cash?: PortfolioCash;
87
+ /**
88
+ * The cash entered by hand in other currencies than `cash`'s, one balance
89
+ * per currency, never `cash`'s own: read them with `portfolioCashBalances`
90
+ * (portfolio/cash-balances.ts), which counts each once. Absent while the
91
+ * portfolio holds cash in one currency at most.
92
+ */
93
+ otherCash?: PortfolioCash[];
86
94
  /**
87
95
  * Target weights in percent of the total value, cash included, or of the
88
96
  * gross exposure in a book that holds a short (allocation.ts WeightBasis),
@@ -242,7 +242,7 @@ function stripAnsi(text: string): string {
242
242
  * break and the tab goes (withoutControlCharacters), so a name, a headline or
243
243
  * a note from a data source prints as the text it is.
244
244
  */
245
- function cliText(text: string): string {
245
+ export function cliText(text: string): string {
246
246
  if (!text.includes("\x1b")) return withoutControlCharacters(text);
247
247
  return text
248
248
  .split(ANSI_SPLIT)
@@ -1,10 +1,21 @@
1
1
  import type { CorporateActionsData, DeclaredDividendAction } from "../types/financials";
2
+ import { formatDistributionAmount } from "./format";
2
3
 
3
4
  const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
4
5
  /** A paid row this close to a declared one is that distribution, dated a day apart. */
5
6
  const SAME_DISTRIBUTION_DAYS = 3;
6
7
  const DAY_MS = 86_400_000;
7
8
 
9
+ export function declaredDividendCash(row: DeclaredDividendAction, currency?: string | null): { amount: string; estimate?: string } {
10
+ const cash = currency ? formatDistributionAmount(row.amount, currency) : String(row.amount);
11
+ const estimate = row.cashEstimate;
12
+ if (!estimate || estimate.declaredAmount == null) return { amount: cash };
13
+ return {
14
+ amount: `${formatDistributionAmount(estimate.declaredAmount, estimate.declaredCurrency)} ${estimate.declaredCurrency}`,
15
+ estimate: `${currency || "Cash"} estimated ${cash}; FX ${estimate.fixingDate ? `fixing ${estimate.fixingDate}` : "fixing unavailable"}${estimate.basis ? `; ${estimate.basis}` : ""}`,
16
+ };
17
+ }
18
+
8
19
  function isoDate(value: unknown): string | undefined {
9
20
  return typeof value === "string" && ISO_DATE.test(value) && Number.isFinite(Date.parse(`${value}T00:00:00Z`)) ? value : undefined;
10
21
  }
@@ -34,6 +45,7 @@ export function declaredDividends(
34
45
  const at = Date.parse(`${exDate}T00:00:00Z`);
35
46
  if (paid.some((time) => Math.abs(time - at) <= SAME_DISTRIBUTION_DAYS * DAY_MS)) return [];
36
47
  return [{ exDate, amount: row.amount, ...declarationDate ? { declarationDate } : {},
37
- ...recordDate ? { recordDate } : {}, ...payDate ? { payDate } : {}, ...row.special === true ? { special: true as const } : {} }];
48
+ ...recordDate ? { recordDate } : {}, ...payDate ? { payDate } : {}, ...row.special === true ? { special: true as const } : {},
49
+ ...row.cashEstimate ? { cashEstimate: row.cashEstimate } : {} }];
38
50
  }).sort((left, right) => left.exDate.localeCompare(right.exDate));
39
51
  }
@@ -23,7 +23,7 @@ export function atSourcePrecision(value: number): number {
23
23
  return value;
24
24
  }
25
25
 
26
- type CashHistory = Pick<CorporateActionsData, "currency" | "dividends" | "declaredDividends">;
26
+ type CashHistory = Pick<CorporateActionsData, "currency" | "dividends" | "declaredDividends" | "declaredCash">;
27
27
 
28
28
  /**
29
29
  * A distribution history with its cash in the major currency unit, at its
@@ -44,5 +44,9 @@ export function cashInMajorUnits<T extends CashHistory>(actions: T): T {
44
44
  currency: unit.currency,
45
45
  dividends: Array.isArray(actions.dividends) ? actions.dividends.map(major) : actions.dividends,
46
46
  ...(Array.isArray(actions.declaredDividends) ? { declaredDividends: actions.declaredDividends.map(major) } : {}),
47
+ ...(actions.declaredCash?.announced?.paidAmount != null ? { declaredCash: {
48
+ ...actions.declaredCash,
49
+ announced: { ...actions.declaredCash.announced, paidAmount: atSourcePrecision(actions.declaredCash.announced.paidAmount / unit.divisor) },
50
+ } } : {}),
47
51
  };
48
52
  }
@@ -1,6 +1,5 @@
1
1
  import type { CorporateActionsData, DeclaredDividendAction, Fundamentals } from "../types/financials";
2
- import { declaredDividends } from "./declared-dividends";
3
- import { formatDistributionAmount } from "./format";
2
+ import { declaredDividendCash, declaredDividends } from "./declared-dividends";
4
3
 
5
4
  /**
6
5
  * What a forward dividend yield is everywhere it shows (fundamentals, DVD,
@@ -47,7 +46,9 @@ interface DeclaredBasisOptions {
47
46
  /** The declared row on the rate's ex-date, as `$0.98`, with its pay date; null when none is stated. */
48
47
  function statedDeclaration(exDate: string, options: DeclaredBasisOptions): { amount: string; payDate: string | null } | null {
49
48
  const row = options.currency ? options.declared?.find((declared) => declared.exDate === exDate) : undefined;
50
- return row ? { amount: formatDistributionAmount(row.amount, options.currency!), payDate: isoDay(row.payDate) } : null;
49
+ if (!row) return null;
50
+ const cash = declaredDividendCash(row, options.currency);
51
+ return { amount: `${cash.amount}${cash.estimate ? ` (${cash.estimate})` : ""}`, payDate: isoDay(row.payDate) };
51
52
  }
52
53
 
53
54
  /**
@@ -0,0 +1,37 @@
1
+ import { rm } from "fs/promises";
2
+
3
+ type RemoveFolder = (path: string, options: { recursive: true; force: true }) => Promise<void>;
4
+
5
+ export interface RemoveFolderOptions {
6
+ /** How long to keep trying while the folder stays locked. */
7
+ budgetMs?: number;
8
+ /** The wait before the second try; it doubles each time, up to half a second. */
9
+ firstDelayMs?: number;
10
+ remove?: RemoveFolder;
11
+ }
12
+
13
+ /**
14
+ * Removes a folder, trying again while something still holds a file in it.
15
+ * Windows keeps a folder locked for a moment after the program that used it
16
+ * has gone: a browser's helper processes finishing, a virus scan of what was
17
+ * just written. Bun's `rm` takes `maxRetries` and `retryDelay` and ignores
18
+ * both (1.3.14), so the first EBUSY is final unless it is retried here.
19
+ *
20
+ * Never throws. Resolves null once the folder is gone, or the last error when
21
+ * it is still locked after `budgetMs`.
22
+ */
23
+ export async function removeFolder(path: string, options: RemoveFolderOptions = {}): Promise<unknown> {
24
+ const { budgetMs = 3_000, firstDelayMs = 50, remove = rm } = options;
25
+ const deadline = Date.now() + budgetMs;
26
+ let delayMs = firstDelayMs;
27
+ for (;;) {
28
+ try {
29
+ await remove(path, { recursive: true, force: true });
30
+ return null;
31
+ } catch (error) {
32
+ if (Date.now() + delayMs > deadline) return error;
33
+ }
34
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
35
+ delayMs = Math.min(delayMs * 2, 500);
36
+ }
37
+ }
@@ -73,7 +73,7 @@ export function inferCadence(payments: readonly Pick<CashDistribution, "exDate">
73
73
  * the window holds fewer than one year of payments. Irregular cash uses the
74
74
  * plain window, so special distributions are neither dropped nor extended.
75
75
  */
76
- function trailingPayments<Payment extends CashDistribution>(payments: readonly Payment[], asOf: Date): { counted: Payment[]; perYear: number | null; cadence: DistributionCadence | null } {
76
+ export function trailingPayments<Payment extends CashDistribution>(payments: readonly Payment[], asOf: Date): { counted: Payment[]; perYear: number | null; cadence: DistributionCadence | null } {
77
77
  const known = payments.filter((payment) => payment.exDate <= asOf && Number.isFinite(payment.amount) && payment.amount > 0)
78
78
  .sort((a, b) => a.exDate.getTime() - b.exDate.getTime());
79
79
  const cutoff = calendarMonthsBefore(asOf, 12);