@gloom-sh/terminal 0.20.17 → 0.20.19

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 (453) 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/cot.ts +5 -6
  7. package/src/api-client/data.ts +14 -3
  8. package/src/api-client/heard-from.ts +72 -0
  9. package/src/api-client/index.ts +64 -6
  10. package/src/api-client/mna.ts +18 -0
  11. package/src/api-client/request.ts +162 -40
  12. package/src/api-client/supply-chain.ts +9 -0
  13. package/src/api-client/types/billing.ts +35 -1
  14. package/src/api-client/types/news.ts +45 -0
  15. package/src/api-client/types/world-venues.ts +9 -0
  16. package/src/app/global-shortcuts.ts +5 -3
  17. package/src/app/pro-welcome/keys.ts +27 -0
  18. package/src/app/pro-welcome/model.ts +158 -0
  19. package/src/app/pro-welcome/row.tsx +176 -0
  20. package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
  21. package/src/app/runtime/external-profile-changes.ts +135 -0
  22. package/src/app.tsx +37 -4
  23. package/src/architecture/core-builtin-allowlist.json +1 -1
  24. package/src/architecture/floating-promise-allowlist.json +1 -2
  25. package/src/architecture/shortcut-labels-allowlist.json +1 -0
  26. package/src/cli/alert-listing.ts +98 -0
  27. package/src/cli/commands/market.ts +191 -39
  28. package/src/cli/commands/overview.ts +7 -1
  29. package/src/cli/commands/plugins.ts +3 -2
  30. package/src/cli/commands/search.ts +30 -6
  31. package/src/cli/commands/ticker.ts +13 -6
  32. package/src/cli/context.ts +24 -5
  33. package/src/cli/csv-export.ts +2 -1
  34. package/src/cli/desktop-pane-shot-browser.ts +3 -1
  35. package/src/cli/desktop-pane-shot-view.ts +0 -1
  36. package/src/cli/desktop-pane-shot.ts +276 -52
  37. package/src/cli/errors.ts +3 -9
  38. package/src/cli/exit-codes.ts +1 -1
  39. package/src/cli/glossary.ts +65 -11
  40. package/src/cli/help.ts +1 -1
  41. package/src/cli/history-demergers.ts +117 -0
  42. package/src/cli/history-rows.ts +8 -4
  43. package/src/cli/index.ts +2 -1
  44. package/src/cli/known-gaps.ts +16 -0
  45. package/src/cli/known-us-stocks.ts +18 -0
  46. package/src/cli/listing-arg.ts +192 -38
  47. package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
  48. package/src/cli/pane-functions/catalog-snapshot.json +877 -0
  49. package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
  50. package/src/cli/pane-functions/catalog.ts +50 -16
  51. package/src/cli/pane-functions/data.ts +16 -4
  52. package/src/cli/pane-functions/dom.ts +54 -8
  53. package/src/cli/pane-functions/freshness.ts +39 -4
  54. package/src/cli/pane-functions/function-help.ts +3 -3
  55. package/src/cli/pane-functions/headless.ts +9 -1
  56. package/src/cli/pane-functions/index.ts +175 -50
  57. package/src/cli/pane-functions/report-notices.ts +10 -0
  58. package/src/cli/pane-functions/resolver.ts +11 -7
  59. package/src/cli/pane-functions/screenshot-assessment.ts +38 -10
  60. package/src/cli/pane-functions/screenshot-data-evidence.ts +7 -15
  61. package/src/cli/pane-functions/screenshot-payload.ts +36 -1
  62. package/src/cli/pane-functions/screenshot-render.ts +24 -9
  63. package/src/cli/pane-functions/screenshot-types.ts +9 -0
  64. package/src/cli/quote-answer.ts +33 -17
  65. package/src/cli/registry.ts +22 -2
  66. package/src/cli/result.ts +22 -4
  67. package/src/cli/scroll-truncation.ts +7 -2
  68. package/src/cli/series-search.ts +45 -6
  69. package/src/cli/shot-temp-dir.ts +4 -9
  70. package/src/cli/ticker-resolution.ts +1 -1
  71. package/src/cli/unreachable.ts +21 -0
  72. package/src/components/chart/composite/drawing-store.ts +11 -7
  73. package/src/components/chart/composite/format.ts +1 -0
  74. package/src/components/chart/composite/legend.tsx +48 -20
  75. package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
  76. package/src/components/chart/composite/panel-surface/plot-gestures.ts +9 -2
  77. package/src/components/chart/composite/panel-surface.tsx +1 -1
  78. package/src/components/chart/composite/price-axis-labels.tsx +7 -5
  79. package/src/components/chart/composite/tools.ts +164 -39
  80. package/src/components/chart-table/header.tsx +11 -2
  81. package/src/components/chart-table/layout.ts +16 -17
  82. package/src/components/command-bar/pane-templates/items.ts +17 -1
  83. package/src/components/command-bar/routes/root/provider-search.ts +10 -1
  84. package/src/components/command-bar/routes/root/results.ts +34 -2
  85. package/src/components/command-bar/routes/root/runtime.ts +19 -4
  86. package/src/components/command-bar/routes/ticker-search/results.ts +5 -0
  87. package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
  88. package/src/components/command-bar/selection-runtime.ts +29 -5
  89. package/src/components/command-bar/surface/index.tsx +4 -1
  90. package/src/components/command-bar/workflow/alert.ts +32 -13
  91. package/src/components/data-table/view.tsx +15 -2
  92. package/src/components/form-modal/content.tsx +9 -4
  93. package/src/components/index.ts +1 -1
  94. package/src/components/layout/header.tsx +9 -5
  95. package/src/components/layout/pane/capture-status.ts +6 -0
  96. package/src/components/layout/pane/footer/index.tsx +2 -0
  97. package/src/components/layout/pane/footer/model.ts +123 -17
  98. package/src/components/layout/pane/header.tsx +16 -2
  99. package/src/components/layout/pane/status-footer.ts +24 -0
  100. package/src/components/market-board/index.tsx +4 -2
  101. package/src/components/onboarding/onboarding-frame.tsx +6 -2
  102. package/src/components/onboarding/onboarding-keyboard.ts +7 -1
  103. package/src/components/onboarding/onboarding-wizard.tsx +3 -1
  104. package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
  105. package/src/components/onboarding/setup-cards.ts +36 -0
  106. package/src/components/onboarding/use-onboarding-progress.ts +22 -1
  107. package/src/components/onboarding/wizard-account.ts +6 -1
  108. package/src/components/onboarding/wizard-model.ts +32 -6
  109. package/src/components/onboarding/wizard-positions.ts +1 -1
  110. package/src/components/price-performance.tsx +26 -8
  111. package/src/components/reader/article-reader.tsx +12 -5
  112. package/src/components/sign-in-gate.tsx +3 -1
  113. package/src/components/toggle-list.tsx +6 -8
  114. package/src/components/ui/confirm-dialog.tsx +47 -7
  115. package/src/components/ui/data-table/opentui/index.tsx +7 -0
  116. package/src/components/ui/data-table/types.ts +8 -0
  117. package/src/components/ui/display.tsx +17 -2
  118. package/src/components/ui/index.ts +1 -1
  119. package/src/components/ui/stat-grid.tsx +4 -0
  120. package/src/components/ui/status.tsx +13 -1
  121. package/src/components/ui/table-layout.ts +34 -2
  122. package/src/components/use-pane-notice-footer.tsx +16 -3
  123. package/src/data/config/store/index.ts +31 -0
  124. package/src/data/config/store/node.ts +61 -11
  125. package/src/data/config/store/normalize.ts +4 -6
  126. package/src/data/config/store/shared-file.ts +309 -0
  127. package/src/data/profile-merge.ts +299 -0
  128. package/src/data/sqlite/checkpointer.ts +11 -1
  129. package/src/data/sqlite/database.ts +1 -1
  130. package/src/data/ticker-repository.ts +134 -10
  131. package/src/data/ticker-store.ts +67 -0
  132. package/src/data/ticker-writes.ts +5 -0
  133. package/src/i18n/es.ts +27 -0
  134. package/src/i18n/ja.ts +27 -0
  135. package/src/i18n/ko.ts +27 -0
  136. package/src/i18n/zh-cn.ts +27 -0
  137. package/src/i18n/zh-tw.ts +27 -0
  138. package/src/layout-marketplace/gallery-desktop.tsx +2 -2
  139. package/src/market-data/ah-pair.ts +122 -0
  140. package/src/market-data/coordinator/entries.ts +6 -4
  141. package/src/market-data/coordinator/index.ts +14 -3
  142. package/src/market-data/depositary-pair.ts +6 -2
  143. package/src/market-data/futures-board.ts +36 -29
  144. package/src/market-data/futures-contract.ts +37 -1
  145. package/src/market-data/hooks.tsx +33 -2
  146. package/src/market-data/market/change-basis.ts +11 -1
  147. package/src/market-data/market/header-market.ts +11 -0
  148. package/src/market-data/market/status.ts +40 -4
  149. package/src/market-data/performance.ts +127 -32
  150. package/src/market-data/quotes/time.ts +5 -2
  151. package/src/market-data/split-terms.ts +28 -0
  152. package/src/news/types.ts +28 -0
  153. package/src/notifications/app-badge.ts +2 -3
  154. package/src/notifications/app-notifier.ts +5 -0
  155. package/src/plugins/builtin/account-management/footer.ts +1 -1
  156. package/src/plugins/builtin/account-management/keyboard.ts +4 -0
  157. package/src/plugins/builtin/account-management/model.ts +1 -0
  158. package/src/plugins/builtin/account-management/pane.tsx +75 -7
  159. package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
  160. package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
  161. package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
  162. package/src/plugins/builtin/alerts/cli-move.ts +2 -2
  163. package/src/plugins/builtin/alerts/cli.ts +101 -48
  164. package/src/plugins/builtin/alerts/command.ts +39 -9
  165. package/src/plugins/builtin/alerts/constants.ts +10 -0
  166. package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
  167. package/src/plugins/builtin/alerts/event-rows.ts +9 -3
  168. package/src/plugins/builtin/alerts/events-pane.tsx +16 -10
  169. package/src/plugins/builtin/alerts/format.ts +24 -8
  170. package/src/plugins/builtin/alerts/headless.ts +12 -6
  171. package/src/plugins/builtin/alerts/index.tsx +97 -16
  172. package/src/plugins/builtin/alerts/move-checks.ts +7 -0
  173. package/src/plugins/builtin/alerts/option-contract.ts +197 -0
  174. package/src/plugins/builtin/alerts/pane.tsx +1 -1
  175. package/src/plugins/builtin/alerts/price.ts +30 -5
  176. package/src/plugins/builtin/alerts/pro-rules.ts +62 -0
  177. package/src/plugins/builtin/alerts/quotes.ts +26 -2
  178. package/src/plugins/builtin/alerts/research-builder.ts +5 -10
  179. package/src/plugins/builtin/alerts/scheduled.ts +6 -1
  180. package/src/plugins/builtin/alerts/types.ts +7 -0
  181. package/src/plugins/builtin/analytics/account-returns.ts +1 -1
  182. package/src/plugins/builtin/analytics/manual-value.ts +61 -0
  183. package/src/plugins/builtin/analytics/pane-model.ts +2 -2
  184. package/src/plugins/builtin/analytics/risk-book.ts +7 -7
  185. package/src/plugins/builtin/analytics/risk-client.ts +27 -14
  186. package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
  187. package/src/plugins/builtin/analytics/risk-model.ts +92 -4
  188. package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
  189. package/src/plugins/builtin/awards/pane.tsx +1 -1
  190. package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
  191. package/src/plugins/builtin/buildout/company/pane.tsx +4 -14
  192. package/src/plugins/builtin/catalysts/model.ts +2 -1
  193. package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
  194. package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
  195. package/src/plugins/builtin/chart-composer/chart-spec.ts +5 -0
  196. package/src/plugins/builtin/chart-composer/cli-options.ts +9 -5
  197. package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
  198. package/src/plugins/builtin/chart-composer/headless-schema.ts +14 -10
  199. package/src/plugins/builtin/chart-composer/headless.ts +2 -0
  200. package/src/plugins/builtin/chart-composer/index.tsx +17 -5
  201. package/src/plugins/builtin/chart-composer/pane.tsx +19 -6
  202. package/src/plugins/builtin/chart-composer/viewport-labels.ts +2 -17
  203. package/src/plugins/builtin/chat/controller/notifications.ts +1 -0
  204. package/src/plugins/builtin/chat/index.tsx +0 -1
  205. package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
  206. package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
  207. package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
  208. package/src/plugins/builtin/commodities-energy/index.tsx +1 -1
  209. package/src/plugins/builtin/company-kpis/headless.ts +10 -5
  210. package/src/plugins/builtin/company-kpis/latest.ts +45 -0
  211. package/src/plugins/builtin/company-kpis/model.ts +57 -15
  212. package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
  213. package/src/plugins/builtin/composite/alt-data.ts +20 -0
  214. package/src/plugins/builtin/composite/application.ts +14 -0
  215. package/src/plugins/builtin/composite/broker.ts +12 -0
  216. package/src/plugins/builtin/composite/credit.ts +33 -0
  217. package/src/plugins/builtin/composite/crypto.ts +10 -0
  218. package/src/plugins/builtin/composite/earnings.ts +12 -0
  219. package/src/plugins/builtin/composite/filings.ts +13 -0
  220. package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
  221. package/src/plugins/builtin/composite/global-markets.ts +12 -0
  222. package/src/plugins/builtin/composite/options-volatility.ts +23 -0
  223. package/src/plugins/builtin/composite/ownership.ts +23 -0
  224. package/src/plugins/builtin/composite/portfolio.ts +10 -0
  225. package/src/plugins/builtin/composite/quant.ts +15 -0
  226. package/src/plugins/builtin/composite/rates-macro.ts +30 -0
  227. package/src/plugins/builtin/composite/screeners.ts +11 -0
  228. package/src/plugins/builtin/composite/shared.ts +11 -0
  229. package/src/plugins/builtin/composite/ticker-core.ts +36 -0
  230. package/src/plugins/builtin/congress-trades/headless.ts +31 -3
  231. package/src/plugins/builtin/congress-trades/model.ts +9 -5
  232. package/src/plugins/builtin/correlation/index.tsx +13 -17
  233. package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
  234. package/src/plugins/builtin/cot/client.ts +2 -3
  235. package/src/plugins/builtin/cot/headless.ts +16 -16
  236. package/src/plugins/builtin/cot/index.tsx +6 -6
  237. package/src/plugins/builtin/cot/model.ts +25 -5
  238. package/src/plugins/builtin/cot/pane.tsx +11 -6
  239. package/src/plugins/builtin/cot/series.ts +11 -8
  240. package/src/plugins/builtin/cpi/model.ts +15 -4
  241. package/src/plugins/builtin/cpi/pane.tsx +29 -7
  242. package/src/plugins/builtin/dividend-yield/client.ts +57 -16
  243. package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
  244. package/src/plugins/builtin/dividend-yield/model.ts +4 -3
  245. package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
  246. package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
  247. package/src/plugins/builtin/dividend-yield/types.ts +4 -0
  248. package/src/plugins/builtin/dividend-yield/view.ts +23 -12
  249. package/src/plugins/builtin/doe/model.ts +30 -0
  250. package/src/plugins/builtin/doe/pane.tsx +8 -2
  251. package/src/plugins/builtin/earnings/board-table.ts +9 -4
  252. package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
  253. package/src/plugins/builtin/earnings/headless.ts +16 -6
  254. package/src/plugins/builtin/earnings/history-model.ts +6 -4
  255. package/src/plugins/builtin/earnings/history-table.ts +7 -4
  256. package/src/plugins/builtin/earnings-calls/calendar.tsx +4 -3
  257. package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
  258. package/src/plugins/builtin/earnings-ripple/pane.tsx +2 -2
  259. package/src/plugins/builtin/econ/calendar-model.ts +16 -0
  260. package/src/plugins/builtin/econ/index.tsx +7 -2
  261. package/src/plugins/builtin/equity-screener/headless.ts +4 -1
  262. package/src/plugins/builtin/equity-screener/model.ts +7 -6
  263. package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
  264. package/src/plugins/builtin/exposure/model.ts +10 -0
  265. package/src/plugins/builtin/exposure/pane.tsx +10 -3
  266. package/src/plugins/builtin/futures/model.ts +14 -1
  267. package/src/plugins/builtin/futures/series.ts +1 -8
  268. package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
  269. package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
  270. package/src/plugins/builtin/fx-matrix/index.tsx +25 -7
  271. package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
  272. package/src/plugins/builtin/insider/detail.tsx +36 -7
  273. package/src/plugins/builtin/insider/filing-stories.ts +110 -0
  274. package/src/plugins/builtin/insider/headless.ts +37 -2
  275. package/src/plugins/builtin/insider/index.tsx +79 -10
  276. package/src/plugins/builtin/insider/model.ts +43 -5
  277. package/src/plugins/builtin/ipo-calendar/client.ts +11 -1
  278. package/src/plugins/builtin/ipo-calendar/model.ts +3 -7
  279. package/src/plugins/builtin/jobs/headless.ts +2 -1
  280. package/src/plugins/builtin/jobs/model.ts +6 -0
  281. package/src/plugins/builtin/jobs/pane.tsx +8 -3
  282. package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
  283. package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
  284. package/src/plugins/builtin/mna/detail.tsx +67 -6
  285. package/src/plugins/builtin/mna/headless.ts +128 -13
  286. package/src/plugins/builtin/mna/model.ts +219 -16
  287. package/src/plugins/builtin/mna/pane.tsx +34 -6
  288. package/src/plugins/builtin/money-markets/model.ts +14 -5
  289. package/src/plugins/builtin/money-markets/pane.tsx +4 -3
  290. package/src/plugins/builtin/news/wire/news/detail-view.tsx +118 -10
  291. package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
  292. package/src/plugins/builtin/news/wire/news/story-evidence.ts +178 -0
  293. package/src/plugins/builtin/options/analytics.ts +1 -1
  294. package/src/plugins/builtin/options/view.tsx +18 -11
  295. package/src/plugins/builtin/options-positioning/model.ts +11 -0
  296. package/src/plugins/builtin/options-positioning/pane.tsx +22 -1
  297. package/src/plugins/builtin/options-scenario/client.ts +49 -8
  298. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
  299. package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
  300. package/src/plugins/builtin/options-scenario/headless.ts +7 -3
  301. package/src/plugins/builtin/options-scenario/model.ts +33 -2
  302. package/src/plugins/builtin/options-scenario/pane.tsx +3 -4
  303. package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
  304. package/src/plugins/builtin/pe-band/client.ts +13 -1
  305. package/src/plugins/builtin/pe-band/headless.ts +2 -2
  306. package/src/plugins/builtin/pe-band/model.ts +63 -10
  307. package/src/plugins/builtin/pe-band/pane.tsx +5 -5
  308. package/src/plugins/builtin/perps/cascade.ts +4 -3
  309. package/src/plugins/builtin/perps/markets-section.tsx +5 -2
  310. package/src/plugins/builtin/perps/model.ts +4 -3
  311. package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
  312. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
  313. package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
  314. package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
  315. package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
  316. package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
  317. package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
  318. package/src/plugins/builtin/portfolio-list/table.tsx +3 -2
  319. package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
  320. package/src/plugins/builtin/research/corporate-actions-pane.tsx +33 -14
  321. package/src/plugins/builtin/research/event-model.ts +43 -19
  322. package/src/plugins/builtin/research/headless.ts +8 -1
  323. package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
  324. package/src/plugins/builtin/research-search/index.tsx +3 -1
  325. package/src/plugins/builtin/scanner/denied.tsx +16 -4
  326. package/src/plugins/builtin/scanner/flow-pane.tsx +1 -1
  327. package/src/plugins/builtin/scanner/hilo-pane.tsx +1 -1
  328. package/src/plugins/builtin/sec/filing-display.tsx +14 -2
  329. package/src/plugins/builtin/sec/headless.ts +42 -4
  330. package/src/plugins/builtin/sec/index.tsx +21 -1
  331. package/src/plugins/builtin/sectors/index.tsx +6 -9
  332. package/src/plugins/builtin/sectors/sector-model.ts +1 -1
  333. package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
  334. package/src/plugins/builtin/shared/earnings-report.ts +49 -5
  335. package/src/plugins/builtin/shared/options-pro-copy.ts +34 -0
  336. package/src/plugins/builtin/shared/report-freshness.ts +2 -3
  337. package/src/plugins/builtin/shared/statement-currency.ts +23 -0
  338. package/src/plugins/builtin/shared/ticker-surface.ts +1 -1
  339. package/src/plugins/builtin/supply-chain/client.ts +34 -9
  340. package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
  341. package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
  342. package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
  343. package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
  344. package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
  345. package/src/plugins/builtin/supply-chain/headless.ts +19 -4
  346. package/src/plugins/builtin/supply-chain/model.ts +50 -6
  347. package/src/plugins/builtin/supply-chain/pane.tsx +79 -18
  348. package/src/plugins/builtin/themes/headless.ts +4 -4
  349. package/src/plugins/builtin/themes/model.ts +11 -8
  350. package/src/plugins/builtin/themes/pane.tsx +2 -2
  351. package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
  352. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
  353. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +51 -1
  354. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +25 -14
  355. package/src/plugins/builtin/ticker-detail/financials/model.ts +22 -32
  356. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +7 -9
  357. package/src/plugins/builtin/ticker-detail/headless-schema.ts +2 -0
  358. package/src/plugins/builtin/ticker-detail/headless.ts +28 -12
  359. package/src/plugins/builtin/ticker-detail/overview/board-lot.ts +21 -0
  360. package/src/plugins/builtin/ticker-detail/overview/model.ts +28 -2
  361. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +8 -0
  362. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +68 -13
  363. package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
  364. package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
  365. package/src/plugins/builtin/volatility/model.ts +17 -0
  366. package/src/plugins/builtin/volatility/pane.tsx +16 -7
  367. package/src/plugins/builtin/world-indices/index.tsx +2 -0
  368. package/src/plugins/builtin/world-indices/table.tsx +15 -0
  369. package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
  370. package/src/plugins/builtin/world-venue-map/headless.ts +32 -18
  371. package/src/plugins/builtin/world-venue-map/index.ts +19 -6
  372. package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
  373. package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
  374. package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
  375. package/src/plugins/builtin/world-venue-map/model.ts +6 -1
  376. package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
  377. package/src/plugins/builtin/world-venue-map/place.ts +119 -0
  378. package/src/plugins/builtin/world-venue-map/venue-header.tsx +5 -3
  379. package/src/plugins/catalog-browser.ts +10 -1
  380. package/src/plugins/catalog-data.ts +20 -0
  381. package/src/plugins/catalog-lazy.ts +51 -0
  382. package/src/plugins/catalog-ui.ts +16 -18
  383. package/src/plugins/host-smoke.ts +5 -2
  384. package/src/portfolio/allocation.ts +79 -19
  385. package/src/portfolio/cash-balances.ts +76 -0
  386. package/src/portfolio/mutations.ts +43 -8
  387. package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
  388. package/src/renderers/browser/activity.ts +16 -0
  389. package/src/renderers/browser/app-badge-host.ts +14 -0
  390. package/src/renderers/browser/main.tsx +5 -0
  391. package/src/renderers/browser/notifications.ts +103 -0
  392. package/src/renderers/browser/ui-host.tsx +4 -0
  393. package/src/renderers/desktop/window-layouts.ts +14 -0
  394. package/src/renderers/dom/data-table/index.tsx +27 -4
  395. package/src/renderers/dom/data-table/row.tsx +2 -0
  396. package/src/renderers/dom/host/tabs.tsx +57 -8
  397. package/src/renderers/dom/styles.css +13 -5
  398. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
  399. package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
  400. package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
  401. package/src/renderers/electrobun/shared/protocol.ts +4 -0
  402. package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
  403. package/src/renderers/electrobun/view/http-fetch.ts +3 -2
  404. package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
  405. package/src/series/standalone-catalog.ts +5 -4
  406. package/src/series/standalone.ts +13 -7
  407. package/src/sources/gloomberb-cloud/index.ts +22 -9
  408. package/src/sources/gloomberb-cloud/news.ts +35 -0
  409. package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
  410. package/src/sources/provider-errors.ts +34 -7
  411. package/src/sources/provider-router/financials.ts +20 -13
  412. package/src/sources/provider-router/history.ts +32 -6
  413. package/src/sources/provider-router/index.ts +4 -0
  414. package/src/sources/provider-router/search.ts +1 -0
  415. package/src/sync/collections-contributor.ts +3 -1
  416. package/src/sync/config-merge.ts +10 -1
  417. package/src/sync/sanitize.ts +26 -2
  418. package/src/tickers/company-name-listing.ts +16 -2
  419. package/src/tickers/listing-fate.ts +12 -8
  420. package/src/tickers/renamed-listings.ts +43 -10
  421. package/src/tickers/search/home-listing.ts +28 -0
  422. package/src/tickers/search/index.ts +19 -7
  423. package/src/tickers/terminal-codes.ts +11 -1
  424. package/src/time-series/base-series.ts +39 -6
  425. package/src/time-series/chart-seed.ts +2 -2
  426. package/src/time-series/history-quality.ts +4 -1
  427. package/src/time-series/hooks.ts +2 -0
  428. package/src/time-series/price-comparison.ts +17 -23
  429. package/src/time-series/reporting.ts +1 -1
  430. package/src/time-series/resolution.ts +13 -0
  431. package/src/time-series/resolve-context.ts +6 -0
  432. package/src/time-series/resolve.ts +42 -3
  433. package/src/time-series/spec.ts +2 -2
  434. package/src/time-series/types.ts +3 -2
  435. package/src/types/data-provider.ts +11 -0
  436. package/src/types/financials.ts +48 -4
  437. package/src/types/headless.ts +1 -0
  438. package/src/types/issuer-listings.ts +2 -0
  439. package/src/types/plugin-notifications.ts +3 -0
  440. package/src/types/price-history.ts +6 -4
  441. package/src/types/ticker.ts +10 -2
  442. package/src/ui/host.tsx +2 -0
  443. package/src/utils/cli-output.ts +1 -1
  444. package/src/utils/declared-dividends.ts +13 -1
  445. package/src/utils/dividend-cash.ts +5 -1
  446. package/src/utils/exchange-announcements.ts +7 -2
  447. package/src/utils/forward-dividend.ts +4 -3
  448. package/src/utils/fundamentals.ts +40 -0
  449. package/src/utils/network-failure.ts +2 -0
  450. package/src/utils/price-history-integrity.ts +9 -1
  451. package/src/utils/remove-folder.ts +37 -0
  452. package/src/utils/trailing-dividend.ts +1 -1
  453. package/src/plugins/builtin/composite-plugins.ts +0 -285
@@ -26,7 +26,11 @@ interface PeBandWeek {
26
26
  }
27
27
 
28
28
  export interface PeBandRow extends EpsStep {
29
- /** The close of the week the figure became known, in price units. */
29
+ /**
30
+ * The close of the day the figure became known (the last session on or
31
+ * before it), in price units; before the daily closes on record, the close
32
+ * of the weekly bar dated on or before it.
33
+ */
30
34
  price: number | null;
31
35
  pe: number | null;
32
36
  /** Change from the figure a year earlier in the same currency, when both are positive. */
@@ -53,7 +57,18 @@ export interface PeBandModel {
53
57
  symbol: string;
54
58
  /** Price currency. */
55
59
  currency: string | null;
60
+ /**
61
+ * The weekly closes the percentile and range rank over, each dated by the
62
+ * session it closed on where the daily closes cover its week (a bar is
63
+ * dated by its first day, its close by its last).
64
+ */
56
65
  weeks: PeBandWeek[];
66
+ /**
67
+ * What the chart draws: the weeks, and the close of each day a figure in
68
+ * the table became known, so selecting its row puts the chart's cursor on
69
+ * that day and the price the row reads.
70
+ */
71
+ points: PeBandWeek[];
57
72
  /** Newest first. */
58
73
  rows: PeBandRow[];
59
74
  multiples: number[];
@@ -176,6 +191,32 @@ export function chooseMultiples(pes: readonly number[], current?: number | null)
176
191
  return [];
177
192
  }
178
193
 
194
+ /** Positive closes in time order; cached history can carry ISO strings for dates. */
195
+ function closesOf(history: readonly PricePoint[]): Array<{ date: Date; close: number }> {
196
+ return history.map((point) => ({ date: new Date(point.date), close: point.close }))
197
+ .filter((point) => Number.isFinite(point.date.getTime()) && Number.isFinite(point.close) && point.close > 0)
198
+ .sort((a, b) => a.date.getTime() - b.date.getTime());
199
+ }
200
+
201
+ /**
202
+ * Weekly bars dated by the session their close is from. A bar is dated by
203
+ * its week's first day, so DWSN's week of 9 Nov 2026 read 9 Nov with the
204
+ * close of Friday the 13th. Where the daily closes cover a week, the bar
205
+ * takes the date of the last daily close before the next bar; elsewhere it
206
+ * keeps its own.
207
+ */
208
+ function closingSessions<T extends { date: Date }>(weekly: readonly T[], daily: readonly { date: Date }[]): T[] {
209
+ let at = 0;
210
+ return weekly.map((bar, index) => {
211
+ const from = bar.date.getTime();
212
+ const until = weekly[index + 1]?.date.getTime() ?? Number.POSITIVE_INFINITY;
213
+ while (at < daily.length && daily[at]!.date.getTime() < from) at += 1;
214
+ let last: { date: Date } | null = null;
215
+ while (at < daily.length && daily[at]!.date.getTime() < until) last = daily[at++]!;
216
+ return last ? { ...bar, date: last.date } : bar;
217
+ });
218
+ }
219
+
179
220
  /** Percent of `values` at or below `value`. */
180
221
  function percentileRank(values: readonly number[], value: number): number | null {
181
222
  return values.length ? 100 * values.filter((other) => other <= value).length / values.length : null;
@@ -204,10 +245,12 @@ export function projectPeBand(
204
245
  fx?: ReadonlyMap<string, FxCloses>;
205
246
  /** Why a needed FX history is missing, said when it leaves today's EPS unconverted. */
206
247
  fxError?: string | null;
248
+ /** Daily closes for the recent years they are served for (see `weeks` and `PeBandRow.price`). */
249
+ daily?: readonly PricePoint[];
207
250
  },
208
251
  ): PeBandModel {
209
252
  const currency = financials?.quote?.currency ?? null;
210
- const empty: PeBandModel = { symbol: options.symbol, currency, weeks: [], rows: [], multiples: [], current: null, range: null, sample: null, bandCeiling: null,
253
+ const empty: PeBandModel = { symbol: options.symbol, currency, weeks: [], points: [], rows: [], multiples: [], current: null, range: null, sample: null, bandCeiling: null,
211
254
  undated: 0, unavailable: 0, conversion: null, error: null, notice: null };
212
255
  if (!financials) return { ...empty, error: "Fundamentals unavailable." };
213
256
  // A warrant's, a right's, a unit's or an unratioed receipt's price over its company's EPS is no P/E at any date.
@@ -246,22 +289,25 @@ export function projectPeBand(
246
289
  const now = options.now ?? Date.now();
247
290
  const firstKnown = allSteps.find((step) => step.eps != null)!.knownAt.getTime();
248
291
  const start = Math.max(firstKnown, options.lookbackYears > 0 ? now - options.lookbackYears * YEAR_MS : firstKnown);
249
- // Cached history can carry ISO strings for dates.
250
- const sorted = history.map((point) => ({ date: new Date(point.date), close: point.close }))
251
- .filter((point) => Number.isFinite(point.date.getTime()) && Number.isFinite(point.close) && point.close > 0)
252
- .sort((a, b) => a.date.getTime() - b.date.getTime());
253
- const weeks = sorted.filter((point) => point.date.getTime() >= start).map((point): PeBandWeek => {
292
+ const sorted = closesOf(history);
293
+ const daily = closesOf(options.daily ?? []);
294
+ const dailyStart = daily[0]?.date.getTime() ?? Number.POSITIVE_INFINITY;
295
+ /** A close as the chart reads it: with the EPS in force on its day, and the P/E they make. */
296
+ const reading = (point: { date: Date; close: number }): PeBandWeek => {
254
297
  // Converted at the FX close of the bar's date, the same date that picks the EPS in force, so each week's multiple
255
298
  // moves with the price and the currency together rather than with the rate of an old publication date.
256
299
  const eps = priced(stepAt(allSteps, point.date.getTime()), day(point.date))?.eps ?? null;
257
300
  const positive = eps != null && eps > 0 ? eps : null;
258
301
  return { date: point.date, close: point.close, eps: positive, pe: positive ? point.close / positive : null };
259
- });
302
+ };
303
+ const weeks = closingSessions(sorted, daily).filter((point) => point.date.getTime() >= start).map(reading);
260
304
 
305
+ /** The close of the day `time` falls on, or the last session before it, where the daily closes reach. */
306
+ const dayClose = (time: number) => time >= dailyStart ? daily.findLast((point) => point.date.getTime() <= time) ?? null : null;
261
307
  const steps = allSteps.filter((step) => step.knownAt.getTime() >= start);
262
308
  const rows = steps.filter((step) => step.eps != null).map((step): PeBandRow => {
263
309
  const time = step.knownAt.getTime();
264
- const price = sorted.findLast((point) => point.date.getTime() <= time)?.close ?? null;
310
+ const price = (dayClose(time) ?? sorted.findLast((point) => point.date.getTime() <= time))?.close ?? null;
265
311
  // Converted at the FX close of the day it became known.
266
312
  const converted = priced(step, day(step.knownAt));
267
313
  const eps = converted?.eps ?? null;
@@ -286,8 +332,15 @@ export function projectPeBand(
286
332
  const multiples = chooseMultiples(pes, currentPe);
287
333
  const above = currentPe == null ? undefined : multiples.find((multiple) => multiple >= currentPe);
288
334
  const highestClose = weeks.reduce((max, week) => Math.max(max, week.close), 0);
335
+ // Each dated row's day on the chart, the close it reads: its cursor lands there, not on the week around it.
336
+ const rowDays = rows.flatMap((row) => {
337
+ const close = row.dated ? dayClose(row.knownAt.getTime()) : null;
338
+ return close && close.date.getTime() >= start ? [reading(close)] : [];
339
+ });
340
+ const byTime = new Map([...weeks, ...rowDays].map((point) => [point.date.getTime(), point]));
341
+ const points = [...byTime.values()].sort((a, b) => a.date.getTime() - b.date.getTime());
289
342
  return {
290
- ...empty, weeks, rows, multiples,
343
+ ...empty, weeks, points, rows, multiples,
291
344
  conversion: latestFx ? { currency: latestFx.currency, latest: fxCloseOnOrBefore(latestFx, day(now))! } : null,
292
345
  sample: ranked.length ? { start: ranked[0]!.date, weeks: ranked.length } : null,
293
346
  bandCeiling: highestClose > 0 ? Math.max(highestClose * 1.5, above != null && currentEps != null ? above * currentEps : 0) : null,
@@ -68,14 +68,14 @@ function chartSeries(model: PeBandModel, colors: ReturnType<typeof useThemeColor
68
68
  // Cheap multiples toward the positive colour, rich ones toward the negative, both faded so the price stays on top.
69
69
  ...model.multiples.map((value, index) => staticSeries(
70
70
  // Values past the ceiling leave the chart, so a far line cannot stretch the axis away from the price.
71
- model.weeks.map((week) => {
71
+ model.points.map((week) => {
72
72
  const band = week.eps == null ? null : week.eps * value;
73
73
  return scalarPoint(week.date, band != null && model.bandCeiling != null && band > model.bandCeiling ? null : band);
74
74
  }),
75
75
  { id: `x${value}`, label: `${value}x`, calendarSpaced: true, color: blendHex(colors.bg,
76
76
  blendHex(colors.positive, colors.negative, last > 0 ? index / last : 0.5), 0.75) },
77
77
  )),
78
- staticSeries(model.weeks.map((week) => scalarPoint(week.date, week.close)), { id: "price", label: "Price", color: colors.textBright, calendarSpaced: true }),
78
+ staticSeries(model.points.map((week) => scalarPoint(week.date, week.close)), { id: "price", label: "Price", color: colors.textBright, calendarSpaced: true }),
79
79
  ];
80
80
  }
81
81
 
@@ -103,7 +103,7 @@ export function PeBandPane({ width, height, focused }: PaneProps) {
103
103
  const lookbackYears = Number(lookback);
104
104
  const model = useMemo(() => inputs.data
105
105
  ? projectPeBand(inputs.data.financials, inputs.data.history, { symbol: symbol ?? "", lookbackYears: Number.isFinite(lookbackYears) ? lookbackYears : 10,
106
- reports: inputs.data.reports, fx: inputs.data.fx, fxError: inputs.data.fxError })
106
+ reports: inputs.data.reports, fx: inputs.data.fx, fxError: inputs.data.fxError, daily: inputs.data.daily })
107
107
  : null, [inputs.data, lookbackYears, symbol]);
108
108
  const rows = model?.rows ?? [];
109
109
  const conversion = model?.conversion ?? null;
@@ -166,8 +166,8 @@ export function PeBandPane({ width, height, focused }: PaneProps) {
166
166
  selectedTextOverridesCellColor
167
167
  getExportMetadata={() => [["symbol", model.symbol], ["currency", model.currency ?? ""],
168
168
  ["units", conversion
169
- ? `EPS as reported in ${conversion.currency}; FX close of the day it became known; price in ${model.currency ?? ""}; P/E at that close and that week's close`
170
- : "EPS and price in the listing currency; P/E at the close of the week the EPS became known"]]}
169
+ ? `EPS as reported in ${conversion.currency}; FX close of the day it became known; price in ${model.currency ?? ""}; P/E at that day's close`
170
+ : "EPS and price in the listing currency; P/E at the close of the day the EPS became known"]]}
171
171
  renderCell={(row, column) => renderCell(row, column, colors)}
172
172
  rootBefore={<ChartTableHeader width={width} height={height} tableRows={rows.length} tableColumns={columns} query={query} figures={figures}
173
173
  chart={model.weeks.length >= 2 ? { series, formatValue: formatPrice, formatAxisValue: formatAxis, remoteKind: "pe-band", ...link } : null} />} />
@@ -2,7 +2,7 @@ import { MISSING_VALUE } from "../../../utils/format";
2
2
  import type { PerpDepthPayload, PerpDepthRow, PerpDepthSnapshot, PerpLiquidationMarket, PerpLiquidationPrint, PerpLiquidationsPayload } from "../../../api-client/perps";
3
3
  import type { DataTableCell, DataTableColumn, StatItem } from "../../../components";
4
4
  import { scalarPoint, staticSeries } from "../../../components/chart/static/series";
5
- import { getTableWidth } from "../../../components/ui/table-layout";
5
+ import { getTableWidth, markHiddenTableColumns } from "../../../components/ui/table-layout";
6
6
  import type { HeadlessPaneFreshness } from "../../../types/headless";
7
7
  import type { ThemeColors } from "../../../theme/colors";
8
8
  import { compact, price, venueName } from "./model";
@@ -23,12 +23,13 @@ const usd = (n: number | null | undefined) => n == null ? MISSING_VALUE : compac
23
23
  * shorts) goes together; the venue and the contract stay, since only both tell one venue's contracts apart.
24
24
  */
25
25
  function fit<Id extends string>(columns: Record<Id, DataTableColumn>, ids: readonly Id[], drops: readonly (readonly Id[])[], width: number): DataTableColumn[] {
26
- let kept = ids.map((id) => columns[id]);
26
+ const original = ids.map((id) => columns[id]);
27
+ let kept = original;
27
28
  for (const drop of drops) {
28
29
  if (getTableWidth(kept) <= width) break;
29
30
  kept = kept.filter((column) => !(drop as readonly string[]).includes(column.id));
30
31
  }
31
- return kept;
32
+ return markHiddenTableColumns(original, kept);
32
33
  }
33
34
 
34
35
  // ---- Liquidations ----
@@ -3,6 +3,7 @@ import { isAccessDenied } from "../../../api-client/errors";
3
3
  import { usePlanAccess } from "../../../api-client/plan-access";
4
4
  import type { PerpBoardRow } from "../../../api-client/perps";
5
5
  import { ActionRow, ColumnGrid, SectionHeading, type ColumnGridCell, type ColumnGridColumn } from "../../../components";
6
+ import { hiddenTableColumnText, markHiddenTableColumns } from "../../../components/ui/table-layout";
6
7
  import { t, tf } from "../../../i18n";
7
8
  import { useAsyncResource, useAutoRefresh } from "../../../public/react";
8
9
  import { useThemeColors } from "../../../theme/theme-context";
@@ -61,12 +62,13 @@ const GAP = 2;
61
62
  const span = (columns: readonly Column[]) => columns.reduce((sum, column) => sum + column.width, 0) + GAP * (columns.length - 1);
62
63
 
63
64
  function fitColumns(width: number, venueWidth: number): Column[] {
64
- let columns = COLUMNS.map((column) => column.id === "venue" ? { ...column, width: venueWidth } : column);
65
+ const original = COLUMNS.map((column) => column.id === "venue" ? { ...column, width: venueWidth } : column);
66
+ let columns = original;
65
67
  for (const id of DROP_ORDER) {
66
68
  if (span(columns) <= width) break;
67
69
  columns = columns.filter((column) => column.id !== id);
68
70
  }
69
- return columns;
71
+ return markHiddenTableColumns(original, columns);
70
72
  }
71
73
 
72
74
  /**
@@ -145,6 +147,7 @@ export function PerpMarketsSection({ symbol, exchange, instrumentType, quote, wi
145
147
  return (
146
148
  <Box flexDirection="column" data-gloom-role="perp-markets">
147
149
  <SectionHeading title={t("Perpetuals")} />
150
+ {hiddenTableColumnText(columns) && <Text fg={colors.textDim}>{hiddenTableColumnText(columns)}</Text>}
148
151
  <ColumnGrid columns={gridColumns} rows={[header, ...body]} width={width} role="perp-markets-grid" />
149
152
  {folded.length > 0 && (
150
153
  <ActionRow expanded={expanded} width={width}
@@ -1,7 +1,7 @@
1
1
  import type { PerpBoardRow, PerpHistoryPayload, PerpLongShortRatio, PerpRankingsPayload } from "../../../api-client/perps";
2
2
  import type { DataTableCell, DataTableColumn } from "../../../components";
3
3
  import { scalarPoint, staticSeries } from "../../../components/chart/static/series";
4
- import { getTableWidth } from "../../../components/ui/table-layout";
4
+ import { getTableWidth, markHiddenTableColumns } from "../../../components/ui/table-layout";
5
5
  import { MISSING_VALUE, formatCompact } from "../../../utils/format";
6
6
  import { isUsListingExchange, publicTickerKey } from "../../../utils/exchanges";
7
7
  import { isRecord } from "../../../utils/guards";
@@ -286,7 +286,8 @@ export const RANKING_COLUMNS: PerpColumnId[] = ["market", "venue", "value", "ope
286
286
 
287
287
  /** The columns that fit the pane, the least read going first; before the last of them goes, a long market name gives up its tail. */
288
288
  function fitPerpColumns(ids: readonly PerpColumnId[], drops: readonly PerpColumnId[], width: number): DataTableColumn[] {
289
- let kept = ids.map((id) => PERP_COLUMNS[id]);
289
+ const columns = ids.map((id) => PERP_COLUMNS[id]);
290
+ let kept = columns;
290
291
  const fits = () => getTableWidth(kept) <= width;
291
292
  for (const [index, drop] of drops.entries()) {
292
293
  if (fits()) break;
@@ -296,7 +297,7 @@ function fitPerpColumns(ids: readonly PerpColumnId[], drops: readonly PerpColumn
296
297
  }
297
298
  kept = kept.filter((column) => column.id !== drop);
298
299
  }
299
- return kept;
300
+ return markHiddenTableColumns(columns, kept);
300
301
  }
301
302
  export const boardColumns = (width: number) => fitPerpColumns(BOARD_COLUMNS, BOARD_DROPS, width);
302
303
  export const compareColumns = (width: number) => fitPerpColumns(COMPARE_COLUMNS, COMPARE_DROPS, width);
@@ -1,6 +1,7 @@
1
1
  import { summaryRowKey, type TickerTableSummaryRow } from "../../../components/ticker/list-table-view";
2
2
  import {
3
3
  CASH_SYMBOL,
4
+ cashLineLabel,
4
5
  formatAllocationDrift,
5
6
  formatAllocationWeight,
6
7
  type PortfolioAllocation,
@@ -31,24 +32,41 @@ function sumKnown(values: readonly (number | null | undefined)[]): number | null
31
32
  * The CASH and TOTAL rows under a book's holdings, as `portfolio show`
32
33
  * prints them. CASH has its value, weight, target, drift and, in TRADE VAL,
33
34
  * the amount that reaches its target: TRADE counts units, which cash has
34
- * none of, so it stays blank there. TOTAL adds up the allocation columns:
35
- * the weight, the targets, the drifts and the trades, so a book whose targets
36
- * cover it sums to zero. Its value, day and P&L are the header's, and stay
37
- * there. Null rows when the book has neither cash nor a target.
35
+ * none of, so it stays blank there. Cash held in several currencies first
36
+ * has a row per currency (CASH HKD, CASH USD) with its value and weight,
37
+ * and the CASH row under them is the whole line, as a ticker's position line
38
+ * is under its lots: the target belongs to all the cash. TOTAL adds up the
39
+ * allocation columns: the weight, the targets, the drifts and the trades, so
40
+ * a book whose targets cover it sums to zero. Its value, day and P&L are the
41
+ * header's, and stay there. Null rows when the book has neither cash nor a
42
+ * target.
38
43
  */
39
44
  export function allocationSummaryRows(
40
45
  allocation: Pick<PortfolioAllocation, "rows" | "cash" | "total" | "weightBasis" | "targetSum">,
41
- { cashCurrency, currency }: { cashCurrency?: string | null; currency: string },
46
+ { currency }: { currency: string },
42
47
  ): TickerTableSummaryRow[] {
43
48
  const rows: TickerTableSummaryRow[] = [];
44
49
  const { cash } = allocation;
50
+ const several = !!cash && cash.balances.length > 1;
51
+ if (cash && several) {
52
+ for (const balance of cash.balances) {
53
+ rows.push({
54
+ id: `cash:${balance.currency}`,
55
+ cells: {
56
+ ticker: { text: cashLineLabel(balance.currency, currency, true) },
57
+ mkt_value: { text: formatCompactAmount(balance.value ?? undefined), value: balance.value },
58
+ weight: { text: formatAllocationWeight(balance.weight), value: balance.weight },
59
+ },
60
+ });
61
+ }
62
+ }
45
63
  if (cash) {
46
64
  rows.push({
47
65
  id: "cash",
48
66
  selectable: true,
49
67
  cells: {
50
- ticker: { text: cashCurrency && cashCurrency !== currency ? `${CASH_SYMBOL} ${cashCurrency}` : CASH_SYMBOL },
51
- mkt_value: { text: formatCompactAmount(cash.value), value: cash.value },
68
+ ticker: { text: several ? CASH_SYMBOL : cashLineLabel(cash.balances[0]?.currency, currency) },
69
+ mkt_value: { text: formatCompactAmount(cash.value ?? undefined), value: cash.value },
52
70
  weight: { text: formatAllocationWeight(cash.weight), value: cash.weight },
53
71
  target_weight: { text: formatAllocationWeight(cash.targetWeight), value: cash.targetWeight },
54
72
  drift: signed(formatAllocationDrift(cash.drift), cash.drift),
@@ -57,6 +75,7 @@ export function allocationSummaryRows(
57
75
  });
58
76
  }
59
77
  const weight = allocation.weightBasis === "total" && allocation.total != null && allocation.total > 0 ? 100 : null;
78
+ // The whole cash line once, never each currency's row too.
60
79
  const lines = [...allocation.rows, ...(cash ? [cash] : [])];
61
80
  const drift = sumKnown(lines.map((line) => line.drift));
62
81
  const tradeValue = sumKnown(lines.map((line) => line.tradeValue));
@@ -15,7 +15,7 @@ import { futuresQuantityText, isFuturesTicker } from "../../../../portfolio/futu
15
15
  import { loadFuturesEntrySize } from "../../../../portfolio/futures-terms";
16
16
  import type { AppConfig } from "../../../../types/config";
17
17
  import type { CliCommandContext, CliCommandDef } from "../../../../types/plugin";
18
- import type { Portfolio, TickerRecord } from "../../../../types/ticker";
18
+ import type { Portfolio, PortfolioCash, TickerRecord } from "../../../../types/ticker";
19
19
  import type { TickerRepository } from "../../../../data/ticker-repository";
20
20
  import type { ConfigContext, MarketContext } from "../../../../cli/types";
21
21
  import { canonicalTickerKey, parsePublicTickerKey } from "../../../../utils/exchanges";
@@ -53,6 +53,7 @@ import { importedFromText } from "../imported-from";
53
53
  import { importPositionsFileCommand, POSITIONS_IMPORT_HELP, POSITIONS_IMPORT_USAGE, type PositionsImportOptions } from "./import-positions";
54
54
  import { savedListingCoinNote } from "../../../../cli/commands/crypto-hints";
55
55
  import { findNamedCollection } from "../../../../portfolio/collection-name";
56
+ import { portfolioCashBalances } from "../../../../portfolio/cash-balances";
56
57
  import { ambiguousQuantityProblem } from "../../../../portfolio/position-quantity";
57
58
  import {
58
59
  CLI_COST_FX_WORDING, loadPurchaseDateCostFx, readCostFxRate, readPurchaseDate, resolvePositionCostFx, type CostFxHistoryClient,
@@ -86,7 +87,7 @@ const ADD_USAGE = "Usage: gloom portfolio add <portfolio> <symbols...> [--file <
86
87
  const CREATE_USAGE = "Usage: gloom portfolio create <name> [--currency <code>]";
87
88
  const POSITION_USAGE = "Usage: gloom portfolio position set <portfolio> <ticker> <shares|contracts> <avg-cost> [currency] [--date <purchase date> | --cost-fx <rate>]";
88
89
  const REMOVE_USAGE = "Usage: gloom portfolio remove <portfolio> <symbols...> [--file <path>]";
89
- const CASH_USAGE = "Usage: gloom portfolio cash set <portfolio> <amount> [currency] | portfolio cash clear <portfolio>";
90
+ const CASH_USAGE = "Usage: gloom portfolio cash set <portfolio> <amount> [currency] | portfolio cash clear <portfolio> [currency]";
90
91
  const TARGET_USAGE = "Usage: gloom portfolio target set <portfolio> <symbol|CASH> <weight%> | target clear <portfolio> [symbol] | target show <portfolio>";
91
92
  const IMPORT_USAGE = "Usage: gloom portfolio import <file> [--name <portfolio>] [--merge | --replace] [--dry-run] | portfolio import --13f <CIK|fund name> [--top N] [--name <portfolio>] [--notional <amount>] [--replace]";
92
93
  const IMPORT_DEFAULT_TOP = 10;
@@ -479,7 +480,7 @@ async function setPositionCommand(
479
480
  function firstPositionCurrencyNote(portfolio: Portfolio, adopted: string): { text: string; warning: boolean } {
480
481
  const note = `"${portfolio.name}" now totals in ${adopted}, its first position's currency`;
481
482
  const held = [
482
- portfolio.cash && portfolio.cash.amount !== 0 ? "cash" : null,
483
+ portfolioCashBalances(portfolio).some((balance) => balance.amount !== 0) ? "cash" : null,
483
484
  Object.keys(portfolio.targetWeights ?? {}).length > 0 ? "targets" : null,
484
485
  ].filter((part): part is string => part !== null);
485
486
  if (held.length === 0) return { text: `${note}.`, warning: false };
@@ -542,17 +543,36 @@ function parseCashArgs(rest: string[], portfolios: readonly Portfolio[]): { name
542
543
  return null;
543
544
  }
544
545
 
546
+ /** Balances as a confirmation lists them: HK$39,000.00 and $1,200.00. */
547
+ function cashBalancesText(balances: readonly PortfolioCash[]): string {
548
+ const amounts = balances.map((balance) => formatAllocationMoney(balance.amount, balance.currency));
549
+ return amounts.length <= 1 ? amounts.join("") : `${amounts.slice(0, -1).join(", ")} and ${amounts.at(-1)!}`;
550
+ }
551
+
552
+ /** The line that says what cash a portfolio holds after a change, once it holds more than one currency's; else null. */
553
+ function cashHeldNote(portfolio: Portfolio, balances: readonly PortfolioCash[], totalsCurrency: string): string | null {
554
+ if (balances.length < 2) return null;
555
+ return `"${portfolio.name}" holds cash in ${balances.length} currencies, ${cashBalancesText(balances)}; reports convert each into ${totalsCurrency}.`;
556
+ }
557
+
545
558
  async function setCashCommand(rest: string[], ctx: CliCommandContext) {
546
559
  await withConfigData(ctx, async ({ config, persistence }) => {
547
560
  const parsed = parseCashArgs(rest, config.portfolios);
548
561
  if (!parsed?.name) ctx.fail(CASH_USAGE);
549
562
  try {
550
563
  const portfolio = requirePortfolio(config, parsed.name);
564
+ const totalsCurrency = resolvePortfolioTotalsCurrency(portfolio, config.baseCurrency);
551
565
  // An amount of a currency reads by its units: 500,000 USD is half a million, 1,234 KWD could be either.
552
- const currency = parsed.currency ?? resolvePortfolioTotalsCurrency(portfolio, config.baseCurrency);
566
+ const currency = parsed.currency ?? totalsCurrency;
553
567
  const amount = parseAmountArg(parsed.amount, "Cash amount", currency);
554
- await saveConfig(setPortfolioCash(config, portfolio.id, { amount, currency }));
555
- console.log(cliStyles.success(`Set cash in "${portfolio.name}" to ${formatAllocationMoney(amount, currency)}.`));
568
+ const { config: next, replaced, balances } = setPortfolioCash(config, portfolio.id, { amount, currency });
569
+ await saveConfig(next);
570
+ // Only this currency's balance changes: a portfolio holds one per currency, and the others stay.
571
+ const replacing = replaced ? `, replacing ${formatAllocationMoney(replaced.amount, replaced.currency)}` : "";
572
+ const which = balances.length > 1 ? `${currency} cash` : "cash";
573
+ console.log(cliStyles.success(`Set ${which} in "${portfolio.name}" to ${formatAllocationMoney(amount, currency)}${replacing}.`));
574
+ const held = cashHeldNote(portfolio, balances, totalsCurrency);
575
+ if (held) console.log(cliStyles.muted(held));
556
576
  const account = findCachedPortfolioAccount(config, portfolio, persistence.resources);
557
577
  if (account && Number.isFinite(account.totalCashValue)) {
558
578
  console.log(cliStyles.warning(
@@ -565,17 +585,47 @@ async function setCashCommand(rest: string[], ctx: CliCommandContext) {
565
585
  });
566
586
  }
567
587
 
568
- async function clearCashCommand(name: string, ctx: CliCommandContext) {
588
+ /**
589
+ * `<portfolio...> [currency]`: a last word that is a currency code, after
590
+ * words that name a portfolio, is the currency to clear; otherwise every word
591
+ * is the name (a portfolio called "Baht THB").
592
+ */
593
+ function parseCashClearArgs(rest: string[], portfolios: readonly Portfolio[]): { name: string; currency?: string } {
594
+ const last = rest.at(-1);
595
+ if (rest.length >= 2 && last && CURRENCY_CODE.test(last)) {
596
+ const name = rest.slice(0, -1).join(" ");
597
+ if (findNamedCollection(portfolios, name)) return { name, currency: last.toUpperCase() };
598
+ }
599
+ return { name: rest.join(" ") };
600
+ }
601
+
602
+ async function clearCashCommand(rest: string[], ctx: CliCommandContext) {
569
603
  await withConfigData(ctx, async ({ config }) => {
604
+ const { name, currency } = parseCashClearArgs(rest, config.portfolios);
570
605
  try {
571
606
  const portfolio = requirePortfolio(config, name);
572
- const result = clearPortfolioCash(config, portfolio.id);
573
- if (!result.changed) {
574
- console.log(cliStyles.warning(`"${portfolio.name}" has no cash recorded.`));
607
+ const totalsCurrency = resolvePortfolioTotalsCurrency(portfolio, config.baseCurrency);
608
+ const result = clearPortfolioCash(config, portfolio.id, currency);
609
+ if (result.removed.length === 0) {
610
+ const held = result.balances.length > 0 ? ` It holds ${result.balances.map((balance) => balance.currency).join(" and ")}.` : "";
611
+ console.log(cliStyles.warning(currency
612
+ ? `"${portfolio.name}" has no ${currency} cash recorded.${held}`
613
+ : `"${portfolio.name}" has no cash recorded.`));
575
614
  return;
576
615
  }
577
616
  await saveConfig(result.config);
578
- console.log(cliStyles.success(`Cleared the cash in "${portfolio.name}".`));
617
+ // One currency of several names it and what stays; all of it names each balance that went once there were several.
618
+ if (currency) {
619
+ const left = result.balances.length > 0 ? `; ${cashBalancesText(result.balances)} ${result.balances.length === 1 ? "stays" : "stay"}` : "";
620
+ const what = result.balances.length > 0 ? `${currency} cash` : "cash";
621
+ console.log(cliStyles.success(`Cleared the ${what} in "${portfolio.name}" (${cashBalancesText(result.removed)})${left}.`));
622
+ } else {
623
+ console.log(cliStyles.success(result.removed.length > 1
624
+ ? `Cleared the cash in "${portfolio.name}": ${cashBalancesText(result.removed)}.`
625
+ : `Cleared the cash in "${portfolio.name}".`));
626
+ }
627
+ const held = cashHeldNote(portfolio, result.balances, totalsCurrency);
628
+ if (held) console.log(cliStyles.muted(held));
579
629
  } catch (error) {
580
630
  failPortfolioCommand(ctx, error, `Failed to clear the cash in "${name}".`);
581
631
  }
@@ -1000,6 +1050,7 @@ const POSITION_HELP = {
1000
1050
  "A future's size is in contracts, at a price per unit of its contract (GC=F: per troy ounce); the contract size is read from its terms, as quote shows them.",
1001
1051
  "The cost is in the currency named after it (GBp or GBX for pence, gbp for pounds), else the listing's. A holding in another currency than the portfolio's (a US stock in a TRY portfolio) can be entered at its cost in the portfolio's currency (position set Lira BRK-B 10 20310 TRY), so P&L is in what was paid.",
1002
1052
  "Entered at its cost in its own currency, its P&L converts the cost at today's rate unless --date gives the purchase date, whose daily FX close is used, or --cost-fx gives the rate paid (portfolio currency per unit of the holding's: 32.15 TRY per USD); then the P&L carries the currency's move since. portfolio show names the holdings whose cost converts at today's rate.",
1053
+ "cash set sets the portfolio's cash in one currency, its own unless named, and keeps its cash in other currencies: HKD and USD can sit side by side, each converted into the portfolio's currency. It names the balance of that currency it replaced. cash clear <portfolio> <currency> clears one currency, cash clear <portfolio> all of it.",
1003
1054
  ],
1004
1055
  };
1005
1056
 
@@ -1039,7 +1090,7 @@ export const portfolioCliCommand: CliCommandDef = {
1039
1090
  "portfolio remove <portfolio> <symbols...> [--file <path>]",
1040
1091
  "portfolio position set <portfolio> <symbol> <shares|contracts> <avg-cost> [currency] [--date <purchase date> | --cost-fx <rate>]",
1041
1092
  "portfolio cash set <portfolio> <amount> [currency]",
1042
- "portfolio cash clear <portfolio>",
1093
+ "portfolio cash clear <portfolio> [currency]",
1043
1094
  "portfolio target set <portfolio> <symbol|CASH> <weight%>",
1044
1095
  "portfolio target clear <portfolio> [symbol|CASH]",
1045
1096
  "portfolio target show <portfolio>",
@@ -1080,6 +1131,8 @@ export const portfolioCliCommand: CliCommandDef = {
1080
1131
  "portfolio position set Lira BRK-B 10 410 USD --date 2024-03-01",
1081
1132
  "portfolio position set Lira KO 40 62.50 USD --cost-fx 32.15",
1082
1133
  "portfolio cash set Research 25000 USD",
1134
+ "portfolio cash set Research 195000 HKD",
1135
+ "portfolio cash clear Research HKD",
1083
1136
  "portfolio target set Research ASML 12.5%",
1084
1137
  "portfolio target set Research CASH 10",
1085
1138
  "portfolio show Research --close",
@@ -1230,7 +1283,7 @@ export const portfolioCliCommand: CliCommandDef = {
1230
1283
  return;
1231
1284
  }
1232
1285
  if (subaction === "clear" && rest.length > 0) {
1233
- await clearCashCommand(rest.join(" "), ctx);
1286
+ await clearCashCommand(rest, ctx);
1234
1287
  return;
1235
1288
  }
1236
1289
  ctx.fail(CASH_USAGE);