@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
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Folds one writer's change to a saved profile document (config.json, a
3
+ * ticker row) into another copy of it, so two programs writing the same
4
+ * profile keep each other's edits: the app open in a terminal and a `gloom`
5
+ * command run beside it.
6
+ *
7
+ * `diffProfile` lists what changed between the copy a writer started from
8
+ * and the one it wrote; `applyProfileEdits` replays that list on any other
9
+ * copy. The edits are fine-grained, so unrelated changes never collide:
10
+ *
11
+ * - objects merge key by key;
12
+ * - lists of records with an `id` (or a pane's `instanceId`) merge record by
13
+ * record, keeping each side's additions, removals and order;
14
+ * - lists of plain values (symbols, ids) merge as sets;
15
+ * - a string that holds JSON (the alert lists) merges as the JSON it holds.
16
+ *
17
+ * When both sides changed the same value, the copy the edits land on keeps
18
+ * its own. A removal always lands: an alert or a watchlist one side deleted
19
+ * stays deleted, whatever the other changed in it meanwhile.
20
+ */
21
+
22
+ export type ProfileJson = null | boolean | number | string | ProfileJson[] | { [key: string]: ProfileJson };
23
+ type ProfileObject = { [key: string]: ProfileJson };
24
+
25
+ /** One step into a document: an object key, a record in a list by its id, or the JSON a string holds. */
26
+ type ProfileStep = { key: string } | { id: string } | { json: true };
27
+
28
+ export type ProfileEdit =
29
+ | { kind: "set"; path: ProfileStep[]; from: ProfileJson | undefined; to: ProfileJson }
30
+ | { kind: "remove"; path: ProfileStep[] }
31
+ | { kind: "members"; path: ProfileStep[]; from: ProfileJson[]; to: ProfileJson[]; add: ProfileJson[]; remove: ProfileJson[] }
32
+ | { kind: "insert"; path: ProfileStep[]; after: string | null; record: ProfileObject }
33
+ | { kind: "order"; path: ProfileStep[]; from: string[]; to: string[] };
34
+
35
+ const RECORD_KEYS = ["id", "instanceId"] as const;
36
+ type RecordKey = typeof RECORD_KEYS[number];
37
+
38
+ function isObject(value: unknown): value is ProfileObject {
39
+ return value !== null && typeof value === "object" && !Array.isArray(value);
40
+ }
41
+
42
+ export function sameProfileJson(a: unknown, b: unknown): boolean {
43
+ if (a === b) return true;
44
+ if (Array.isArray(a)) {
45
+ if (!Array.isArray(b) || a.length !== b.length) return false;
46
+ return a.every((entry, index) => sameProfileJson(entry, b[index]));
47
+ }
48
+ if (isObject(a)) {
49
+ if (!isObject(b)) return false;
50
+ const keys = Object.keys(a);
51
+ if (keys.length !== Object.keys(b).length) return false;
52
+ return keys.every((key) => Object.hasOwn(b, key) && sameProfileJson(a[key], b[key]));
53
+ }
54
+ return false;
55
+ }
56
+
57
+ /** The field that names each record of a list, when every entry is a record with a distinct one. */
58
+ function recordKeyOf(list: readonly ProfileJson[]): RecordKey | null {
59
+ if (list.length === 0) return null;
60
+ for (const key of RECORD_KEYS) {
61
+ const ids = new Set<string>();
62
+ if (list.every((entry) => isObject(entry) && typeof entry[key] === "string" && !ids.has(entry[key] as string) && ids.add(entry[key] as string))) {
63
+ return key;
64
+ }
65
+ }
66
+ return null;
67
+ }
68
+
69
+ /** Both lists' record field: empty lists take the other's. */
70
+ function sharedRecordKey(a: readonly ProfileJson[], b: readonly ProfileJson[]): RecordKey | null {
71
+ const aKey = recordKeyOf(a);
72
+ const bKey = recordKeyOf(b);
73
+ if (a.length === 0) return bKey;
74
+ if (b.length === 0) return aKey;
75
+ return aKey === bKey ? aKey : null;
76
+ }
77
+
78
+ function recordId(entry: ProfileJson, key: RecordKey | null): string | null {
79
+ if (!isObject(entry)) return null;
80
+ if (key) return typeof entry[key] === "string" ? entry[key] as string : null;
81
+ for (const field of RECORD_KEYS) if (typeof entry[field] === "string") return entry[field] as string;
82
+ return null;
83
+ }
84
+
85
+ function isPrimitive(value: ProfileJson): boolean {
86
+ return value === null || typeof value !== "object";
87
+ }
88
+
89
+ /** A list of plain values with no repeats, which merges as a set. */
90
+ function isValueSet(list: readonly ProfileJson[]): boolean {
91
+ return list.every(isPrimitive) && new Set(list).size === list.length;
92
+ }
93
+
94
+ function parseJsonText(value: string): ProfileJson | undefined {
95
+ const text = value.trimStart();
96
+ if (!text.startsWith("[") && !text.startsWith("{")) return undefined;
97
+ try {
98
+ return JSON.parse(value) as ProfileJson;
99
+ } catch {
100
+ // Intentional ignore: a string that only looks like JSON is compared as text.
101
+ return undefined;
102
+ }
103
+ }
104
+
105
+ /** The edits that turn `base` into `next`. */
106
+ export function diffProfile(base: ProfileJson | undefined, next: ProfileJson | undefined): ProfileEdit[] {
107
+ const edits: ProfileEdit[] = [];
108
+ diffInto(base, next, [], edits);
109
+ return edits;
110
+ }
111
+
112
+ function diffInto(base: ProfileJson | undefined, next: ProfileJson | undefined, path: ProfileStep[], edits: ProfileEdit[]): void {
113
+ if (sameProfileJson(base, next)) return;
114
+ if (next === undefined) {
115
+ edits.push({ kind: "remove", path });
116
+ return;
117
+ }
118
+ if (isObject(base) && isObject(next)) {
119
+ for (const key of Object.keys(base)) {
120
+ if (!Object.hasOwn(next, key)) edits.push({ kind: "remove", path: [...path, { key }] });
121
+ }
122
+ for (const key of Object.keys(next)) diffInto(base[key], next[key], [...path, { key }], edits);
123
+ return;
124
+ }
125
+ if (Array.isArray(base) && Array.isArray(next)) {
126
+ const key = sharedRecordKey(base, next);
127
+ if (key) {
128
+ diffRecords(base, next, key, path, edits);
129
+ return;
130
+ }
131
+ if (isValueSet(base) && isValueSet(next)) {
132
+ const add = next.filter((entry) => !base.includes(entry));
133
+ const remove = base.filter((entry) => !next.includes(entry));
134
+ edits.push(add.length === 0 && remove.length === 0
135
+ ? { kind: "set", path, from: base, to: next }
136
+ : { kind: "members", path, from: base, to: next, add, remove });
137
+ return;
138
+ }
139
+ }
140
+ if (typeof base === "string" && typeof next === "string") {
141
+ const baseJson = parseJsonText(base);
142
+ const nextJson = parseJsonText(next);
143
+ if (baseJson !== undefined && nextJson !== undefined) {
144
+ diffInto(baseJson, nextJson, [...path, { json: true }], edits);
145
+ return;
146
+ }
147
+ }
148
+ edits.push({ kind: "set", path, from: base, to: next });
149
+ }
150
+
151
+ function diffRecords(base: ProfileJson[], next: ProfileJson[], key: RecordKey, path: ProfileStep[], edits: ProfileEdit[]): void {
152
+ const baseById = new Map(base.map((entry) => [recordId(entry, key)!, entry]));
153
+ const nextIds = next.map((entry) => recordId(entry, key)!);
154
+ const nextIdSet = new Set(nextIds);
155
+ for (const id of baseById.keys()) {
156
+ if (!nextIdSet.has(id)) edits.push({ kind: "remove", path: [...path, { id }] });
157
+ }
158
+ next.forEach((entry, index) => {
159
+ const id = nextIds[index]!;
160
+ const before = baseById.get(id);
161
+ if (before === undefined) {
162
+ edits.push({ kind: "insert", path, after: index > 0 ? nextIds[index - 1]! : null, record: entry as ProfileObject });
163
+ } else {
164
+ diffInto(before, entry, [...path, { id }], edits);
165
+ }
166
+ });
167
+ const from = [...baseById.keys()].filter((id) => nextIdSet.has(id));
168
+ const to = nextIds.filter((id) => baseById.has(id));
169
+ if (from.some((id, index) => id !== to[index])) edits.push({ kind: "order", path, from, to });
170
+ }
171
+
172
+ const REMOVED = Symbol("removed");
173
+ type Updated = ProfileJson | undefined | typeof REMOVED;
174
+
175
+ export interface ApplyProfileEditsOptions {
176
+ /**
177
+ * Who keeps a value both sides changed: the target (`keep`, the default),
178
+ * or the side the edits came from (`take`).
179
+ */
180
+ conflicts?: "keep" | "take";
181
+ }
182
+
183
+ /** `target` with every edit replayed on it; the same object when none lands. */
184
+ export function applyProfileEdits<T extends ProfileJson>(target: T, edits: readonly ProfileEdit[], options: ApplyProfileEditsOptions = {}): T {
185
+ const take = options.conflicts === "take";
186
+ let result: ProfileJson = target;
187
+ for (const edit of edits) {
188
+ const next = updateAt(result, edit.path, 0, (current) => applyLeaf(current, edit, take));
189
+ if (next !== REMOVED && next !== undefined) result = next;
190
+ }
191
+ return result as T;
192
+ }
193
+
194
+ /**
195
+ * Rewrites the value at `path` with `update`. A step that no longer resolves
196
+ * (a record or key the target removed, a string that no longer holds JSON)
197
+ * leaves the target as it is: that side's removal wins.
198
+ */
199
+ function updateAt(value: ProfileJson | undefined, path: readonly ProfileStep[], index: number, update: (current: ProfileJson | undefined) => Updated): Updated {
200
+ if (index === path.length) return update(value);
201
+ const step = path[index]!;
202
+ if ("json" in step) {
203
+ if (typeof value !== "string") return value;
204
+ const parsed = parseJsonText(value);
205
+ if (parsed === undefined) return value;
206
+ const next = updateAt(parsed, path, index + 1, update);
207
+ if (next === parsed || next === REMOVED || next === undefined) return value;
208
+ return value.includes("\n") ? JSON.stringify(next, null, 2) : JSON.stringify(next);
209
+ }
210
+ if ("key" in step) {
211
+ if (!isObject(value)) return value;
212
+ const child = value[step.key];
213
+ // Below a key the target no longer has, there is nothing left to change.
214
+ if (child === undefined && index + 1 < path.length) return value;
215
+ const next = updateAt(child, path, index + 1, update);
216
+ if (next === child) return value;
217
+ if (next === REMOVED || next === undefined) {
218
+ if (!Object.hasOwn(value, step.key)) return value;
219
+ const { [step.key]: _removed, ...rest } = value;
220
+ return rest;
221
+ }
222
+ return { ...value, [step.key]: next };
223
+ }
224
+ if (!Array.isArray(value)) return value;
225
+ const position = value.findIndex((entry) => recordId(entry, null) === step.id);
226
+ if (position < 0) return value;
227
+ const child = value[position]!;
228
+ const next = updateAt(child, path, index + 1, update);
229
+ if (next === child) return value;
230
+ if (next === REMOVED || next === undefined) return value.filter((_, at) => at !== position);
231
+ return value.map((entry, at) => (at === position ? next : entry));
232
+ }
233
+
234
+ function applyLeaf(current: ProfileJson | undefined, edit: ProfileEdit, take: boolean): Updated {
235
+ switch (edit.kind) {
236
+ case "remove":
237
+ return current === undefined ? current : REMOVED;
238
+ case "set":
239
+ if (sameProfileJson(current, edit.to)) return current;
240
+ if (take || sameProfileJson(current, edit.from)) return edit.to;
241
+ // Both sides added the same key: keep this side's values and take what only the other has.
242
+ if (edit.from === undefined && isObject(current) && isObject(edit.to)) return fillMissing(current, edit.to);
243
+ return current;
244
+ case "members": {
245
+ if (sameProfileJson(current, edit.from)) return edit.to;
246
+ if (!Array.isArray(current)) return current;
247
+ const kept = current.filter((entry) => !edit.remove.some((removed) => sameProfileJson(removed, entry)));
248
+ const added = edit.add.filter((entry) => !kept.some((present) => sameProfileJson(present, entry)));
249
+ const next = [...kept, ...added];
250
+ return sameProfileJson(next, current) ? current : next;
251
+ }
252
+ case "insert": {
253
+ if (!Array.isArray(current)) return current;
254
+ const id = recordId(edit.record, null);
255
+ const existing = current.findIndex((entry) => recordId(entry, null) === id);
256
+ if (existing >= 0) {
257
+ const present = current[existing]!;
258
+ if (!isObject(present)) return current;
259
+ const filled = fillMissing(present, edit.record);
260
+ return filled === present ? current : current.map((entry, at) => (at === existing ? filled : entry));
261
+ }
262
+ const afterIndex = edit.after === null ? -1 : current.findIndex((entry) => recordId(entry, null) === edit.after);
263
+ const at = edit.after === null ? 0 : afterIndex >= 0 ? afterIndex + 1 : current.length;
264
+ return [...current.slice(0, at), edit.record, ...current.slice(at)];
265
+ }
266
+ case "order": {
267
+ if (!Array.isArray(current)) return current;
268
+ const wanted = new Set(edit.to);
269
+ const positions: number[] = [];
270
+ const present: string[] = [];
271
+ current.forEach((entry, at) => {
272
+ const id = recordId(entry, null);
273
+ if (id !== null && wanted.has(id)) {
274
+ positions.push(at);
275
+ present.push(id);
276
+ }
277
+ });
278
+ // A list this side reordered keeps its own order.
279
+ const fromOrder = edit.from.filter((id) => present.includes(id));
280
+ if (fromOrder.some((id, at) => id !== present[at])) return current;
281
+ const toOrder = edit.to.filter((id) => present.includes(id));
282
+ const byId = new Map(current.map((entry) => [recordId(entry, null), entry]));
283
+ const next = [...current];
284
+ positions.forEach((position, at) => { next[position] = byId.get(toOrder[at]!)!; });
285
+ return sameProfileJson(next, current) ? current : next;
286
+ }
287
+ }
288
+ }
289
+
290
+ /** `present` with the keys only `added` has, recursively. */
291
+ function fillMissing(present: ProfileObject, added: ProfileObject): ProfileObject {
292
+ let result = present;
293
+ for (const [key, value] of Object.entries(added)) {
294
+ const mine = present[key];
295
+ const next = mine === undefined ? value : isObject(mine) && isObject(value) ? fillMissing(mine, value) : mine;
296
+ if (next !== mine) result = { ...result, [key]: next };
297
+ }
298
+ return result;
299
+ }
@@ -87,11 +87,20 @@ self.onmessage = (event) => {
87
87
  };
88
88
  `;
89
89
 
90
+ /** What `PRAGMA wal_checkpoint` answers: frames in the WAL, and how many of them now sit in the database. */
91
+ export interface WalCheckpointResult {
92
+ busy?: number;
93
+ log?: number;
94
+ checkpointed?: number;
95
+ }
96
+
90
97
  export interface WalCheckpointerOptions {
91
98
  /** Overrides how long the thread may owe an answer before it counts as stuck. */
92
99
  stuckAfterMs?: number;
93
100
  /** Overrides the thread's code, so a test can run one that never answers. */
94
101
  workerSource?: string;
102
+ /** Runs on the app's thread after each checkpoint, so a test can wait for one instead of the clock. */
103
+ onCheckpoint?: (result: WalCheckpointResult) => void;
95
104
  }
96
105
 
97
106
  export interface WalCheckpointer {
@@ -107,7 +116,7 @@ interface WorkerMessage {
107
116
  ms?: number;
108
117
  startedAt?: number;
109
118
  endedAt?: number;
110
- result?: { busy?: number; log?: number; checkpointed?: number };
119
+ result?: WalCheckpointResult;
111
120
  }
112
121
 
113
122
  /**
@@ -251,6 +260,7 @@ export function startWalCheckpointer(
251
260
  endedAt: Math.round(message.endedAt ?? 0),
252
261
  }, { lastStep: false });
253
262
  if (pending) schedule();
263
+ options.onCheckpoint?.(message.result ?? {});
254
264
  }
255
265
  };
256
266
  worker.onerror = (event) => {
@@ -78,7 +78,7 @@ export interface SqliteDatabaseOptions {
78
78
  * another program's lock (see access.ts). Commands and tests wait it out.
79
79
  */
80
80
  interactive?: boolean;
81
- /** Tests only: the WAL checkpointer's thread and how long it may go silent. */
81
+ /** Tests only: the WAL checkpointer's thread, how long it may go silent, and what it reports. */
82
82
  checkpointer?: WalCheckpointerOptions;
83
83
  }
84
84
 
@@ -1,20 +1,60 @@
1
1
  import { logFailure } from "../utils/log-failure";
2
2
  import type { TickerRecord, TickerMetadata } from "../types/ticker";
3
- import type { TickerStore } from "./ticker-store";
3
+ import type { ResolvedTickerRow, TickerStore } from "./ticker-store";
4
4
  import { hydrateTickerMetadata } from "../tickers/metadata";
5
- import { runTickerWrite } from "./ticker-writes";
5
+ import { hasPendingTickerWrite, runTickerWrite } from "./ticker-writes";
6
+ import { serializeJson } from "./sqlite/json";
7
+ import { applyProfileEdits, diffProfile, type ProfileJson } from "./profile-merge";
6
8
 
7
9
  function parseTickerMetadata(json: string): TickerMetadata {
8
10
  return hydrateTickerMetadata(JSON.parse(json) as Record<string, unknown>);
9
11
  }
10
12
 
13
+ /**
14
+ * Ticker rows are shared like config.json: a `gloom watchlist add` or
15
+ * `portfolio position set` run beside the app writes the row the app holds a
16
+ * copy of, and another copy of the app (the desktop app beside the terminal
17
+ * one) can delete a row in its cleanup. Each row's copy is kept as it was read
18
+ * or last saved here. A save over a row another program changed since keeps
19
+ * that program's change and adds this one's (see `profile-merge.ts`); a save
20
+ * over a row another program deleted since leaves it deleted, as a removal
21
+ * always lands. Which of those it is gets decided in the write's own
22
+ * transaction, when it lands (`TickerStore.saveResolved`).
23
+ */
11
24
  export class TickerRepository {
25
+ /**
26
+ * Each row as this program's copy of it was read or last saved, by symbol:
27
+ * what the next save of it is compared with. Only a write that landed moves
28
+ * it, never one still queued or dropped for a later write of the same row.
29
+ */
30
+ private readonly copies = new Map<string, string>();
31
+ /**
32
+ * Rows this program holds a copy of that a read of every row found gone:
33
+ * another program deleted them. Their copies stay, so a save of the app's
34
+ * copy still leaves them deleted, until the app has dropped them from what
35
+ * it shows (`takeRowsDeletedElsewhere`) and lets them go.
36
+ */
37
+ private readonly goneElsewhere = new Set<string>();
38
+
12
39
  constructor(private readonly tickers: TickerStore) {}
13
40
 
41
+ /** Changes when another program commits to the database (see `TickerStore.changesElsewhere`). */
42
+ changesElsewhere(): number | null {
43
+ return this.tickers.changesElsewhere();
44
+ }
45
+
14
46
  async loadAllTickers(): Promise<TickerRecord[]> {
15
- return this.tickers.getAll().flatMap((row) => {
47
+ const rows = this.tickers.getAll();
48
+ // A row this program holds a copy of that is gone was deleted elsewhere, whoever wrote it last.
49
+ const present = new Set(rows.map((row) => row.symbol));
50
+ for (const symbol of this.copies.keys()) {
51
+ if (!present.has(symbol) && !this.writing(symbol)) this.goneElsewhere.add(symbol);
52
+ }
53
+ return rows.flatMap((row) => {
16
54
  try {
17
- return [{ metadata: parseTickerMetadata(row.metadata) }];
55
+ const record = { metadata: parseTickerMetadata(row.metadata) };
56
+ this.noteRead(row.symbol, row.metadata);
57
+ return [record];
18
58
  } catch (error) {
19
59
  logFailure("data.ticker-repository", "Reading stored ticker metadata failed")(error);
20
60
  return [];
@@ -24,9 +64,14 @@ export class TickerRepository {
24
64
 
25
65
  async loadTicker(symbol: string): Promise<TickerRecord | null> {
26
66
  const json = this.tickers.get(symbol);
27
- if (!json) return null;
67
+ if (!json) {
68
+ this.noteRead(symbol, null);
69
+ return null;
70
+ }
28
71
  try {
29
- return { metadata: parseTickerMetadata(json) };
72
+ const record = { metadata: parseTickerMetadata(json) };
73
+ this.noteRead(symbol, json);
74
+ return record;
30
75
  } catch (error) {
31
76
  logFailure("data.ticker-repository", "Reading stored ticker metadata failed")(error);
32
77
  return null;
@@ -35,26 +80,105 @@ export class TickerRepository {
35
80
 
36
81
  saveTicker(ticker: TickerRecord): Promise<void> {
37
82
  return runTickerWrite(this, ticker.metadata.ticker, () => {
38
- this.tickers.save(ticker.metadata.ticker, ticker.metadata);
83
+ this.tickers.saveResolved([this.rowToSave(ticker.metadata)]);
39
84
  });
40
85
  }
41
86
 
42
87
  /** Saves several tickers in one write. */
43
88
  saveTickers(tickers: readonly TickerRecord[]): Promise<void> {
44
89
  return runTickerWrite(this, tickers.map((ticker) => ticker.metadata.ticker), () => {
45
- this.tickers.saveMany(tickers.map((ticker) => ({ symbol: ticker.metadata.ticker, metadata: ticker.metadata })));
90
+ this.tickers.saveResolved(tickers.map((ticker) => this.rowToSave(ticker.metadata)));
46
91
  });
47
92
  }
48
93
 
49
94
  createTicker(metadata: TickerMetadata): Promise<TickerRecord> {
50
95
  const ticker: TickerRecord = { metadata };
51
96
  return runTickerWrite(this, metadata.ticker, () => {
52
- this.tickers.save(metadata.ticker, metadata);
97
+ this.tickers.saveResolved([this.rowToSave(metadata)]);
53
98
  return ticker;
54
99
  });
55
100
  }
56
101
 
57
102
  deleteTicker(symbol: string): Promise<void> {
58
- return runTickerWrite(this, symbol, () => this.tickers.delete(symbol));
103
+ return runTickerWrite(this, symbol, () => {
104
+ this.tickers.delete(symbol);
105
+ this.copies.delete(symbol);
106
+ this.goneElsewhere.delete(symbol);
107
+ });
108
+ }
109
+
110
+ /**
111
+ * The rows another program deleted that this program held, as reads of
112
+ * every row found them gone since the last call, for the app to drop from
113
+ * what it shows; their copies go with them, so a ticker added again after
114
+ * is a new row. A row with a save of it on its way is kept for a later
115
+ * call: that save is still compared with its copy.
116
+ */
117
+ takeRowsDeletedElsewhere(): string[] {
118
+ const taken = [...this.goneElsewhere].filter((symbol) => !this.writing(symbol));
119
+ for (const symbol of taken) {
120
+ this.goneElsewhere.delete(symbol);
121
+ this.copies.delete(symbol);
122
+ }
123
+ return taken;
124
+ }
125
+
126
+ /** Whether a save of `symbol` is on its way, or waits behind another program's lock. */
127
+ private writing(symbol: string): boolean {
128
+ return hasPendingTickerWrite(this, symbol) || this.tickers.isQueued(symbol);
129
+ }
130
+
131
+ /**
132
+ * A row read is what this program's copy of it is built on from now (null:
133
+ * there is none, so the next save writes a new row), but not while a save
134
+ * of the row is on its way or waits behind another program's lock: that
135
+ * save was built on the copy before, and is compared with that one, and
136
+ * what the read sees of the row is that save's own.
137
+ */
138
+ private noteRead(symbol: string, metadata: string | null): void {
139
+ if (this.writing(symbol)) return;
140
+ this.goneElsewhere.delete(symbol);
141
+ if (metadata === null) this.copies.delete(symbol);
142
+ else this.copies.set(symbol, metadata);
143
+ }
144
+
145
+ /**
146
+ * `metadata`, this program's copy, as a row the store resolves when the
147
+ * write lands, against the copy it was built on (`copies`, as it stands
148
+ * then):
149
+ * - no copy: a row this program has not read, written as it is;
150
+ * - the stored row is gone: another program deleted it since, and it stays
151
+ * deleted until the app has dropped it (`takeRowsDeletedElsewhere`) or
152
+ * reads that one row anew (`loadTicker`);
153
+ * - the stored row is the copy, or this very row: written as it is;
154
+ * - otherwise another program changed it, and that change is folded in.
155
+ * Once written, the copy is what this program built, so a later save of a
156
+ * copy that never read the change folds it in again.
157
+ */
158
+ private rowToSave(metadata: TickerMetadata): ResolvedTickerRow {
159
+ const symbol = metadata.ticker;
160
+ const mine = serializeJson(metadata);
161
+ return {
162
+ symbol,
163
+ preview: metadata,
164
+ resolve: (stored) => {
165
+ const base = this.copies.get(symbol);
166
+ if (base === undefined) return metadata;
167
+ if (stored === null) return null;
168
+ if (stored === base || stored === mine) return metadata;
169
+ try {
170
+ const edits = diffProfile(JSON.parse(base) as ProfileJson, JSON.parse(stored) as ProfileJson);
171
+ return applyProfileEdits(JSON.parse(mine) as ProfileJson, edits);
172
+ } catch (error) {
173
+ logFailure("data.ticker-repository", "Reading a ticker row another program changed failed")(error);
174
+ return metadata;
175
+ }
176
+ },
177
+ landed: (written) => {
178
+ if (written === null) return;
179
+ this.copies.set(symbol, mine);
180
+ this.goneElsewhere.delete(symbol);
181
+ },
182
+ };
59
183
  }
60
184
  }
@@ -12,6 +12,21 @@ interface PendingTicker {
12
12
  metadata: string | null;
13
13
  }
14
14
 
15
+ /**
16
+ * A row to save that was built on an earlier copy of it, so what it writes is
17
+ * only known once the write lands: `resolve` gets the row as stored at that
18
+ * moment (null when there is none) and returns what to write, or null to
19
+ * leave the row as it is. It can run more than once (a write the lock held up
20
+ * runs again), so it has no effects of its own; `landed` hears what was
21
+ * written, null for nothing. `preview` is what reads see while it waits.
22
+ */
23
+ export interface ResolvedTickerRow {
24
+ symbol: string;
25
+ preview: unknown;
26
+ resolve: (stored: string | null) => unknown;
27
+ landed?: (written: string | null) => void;
28
+ }
29
+
15
30
  export class TickerStore {
16
31
  /** Writes queued behind another program's lock, by symbol, read back until they land. */
17
32
  private readonly pending = new Map<string, PendingTicker>();
@@ -38,6 +53,27 @@ export class TickerStore {
38
53
  return [...bySymbol.values()].sort((a, b) => (a.symbol < b.symbol ? -1 : a.symbol > b.symbol ? 1 : 0));
39
54
  }
40
55
 
56
+ /**
57
+ * A number that changes when another program (a `gloom` command) commits
58
+ * to the database, and only then: SQLite's `data_version`. Null when the
59
+ * database cannot be read just now.
60
+ */
61
+ changesElsewhere(): number | null {
62
+ try {
63
+ return this.access.run("read data version", () => (
64
+ this.db.query<{ data_version: number }, []>("PRAGMA data_version").get()?.data_version ?? null
65
+ ));
66
+ } catch {
67
+ // Intentional ignore: an unreadable database is asked again on the next look.
68
+ return null;
69
+ }
70
+ }
71
+
72
+ /** Whether a write of `symbol` waits behind another program's lock: reads see it, the database does not yet. */
73
+ isQueued(symbol: string): boolean {
74
+ return this.pending.has(symbol);
75
+ }
76
+
41
77
  get(symbol: string): string | null {
42
78
  const pending = this.pending.get(symbol);
43
79
  if (pending) return pending.metadata;
@@ -75,6 +111,37 @@ export class TickerStore {
75
111
  );
76
112
  }
77
113
 
114
+ /**
115
+ * Saves rows whose content depends on the row stored when the write lands
116
+ * (`ResolvedTickerRow`): each is read, resolved and written in one
117
+ * immediate transaction, so another program's commit can never fall between
118
+ * the read and the write, whether the write lands now or later, behind
119
+ * another program's lock.
120
+ */
121
+ saveResolved(rows: readonly ResolvedTickerRow[]): void {
122
+ if (rows.length === 0) return;
123
+ this.write(
124
+ rows.length === 1 ? "save ticker" : "save tickers",
125
+ rows.map((row) => [row.symbol, { metadata: serializeJson(row.preview) }]),
126
+ () => {
127
+ const read = this.db.query<{ metadata: string }, [string]>("SELECT metadata FROM tickers WHERE symbol = ?");
128
+ const insert = this.db.query(
129
+ `INSERT OR REPLACE INTO tickers (symbol, metadata, updated_at)
130
+ VALUES (?, ?, ?)`,
131
+ );
132
+ const now = Date.now();
133
+ const written = this.db.transaction(() => rows.map((row) => {
134
+ const next = row.resolve(read.get(row.symbol)?.metadata ?? null);
135
+ if (next == null) return null;
136
+ const metadata = serializeJson(next);
137
+ insert.run(row.symbol, metadata, now);
138
+ return metadata;
139
+ })).immediate();
140
+ rows.forEach((row, index) => row.landed?.(written[index] ?? null));
141
+ },
142
+ );
143
+ }
144
+
78
145
  delete(symbol: string): void {
79
146
  this.write("delete ticker", [[symbol, { metadata: null }]], () => {
80
147
  this.db.query("DELETE FROM tickers WHERE symbol = ?").run(symbol);
@@ -71,6 +71,11 @@ export function hasPendingTickerWrites(repository: object): boolean {
71
71
  return (repositories.get(repository)?.pending.size ?? 0) > 0;
72
72
  }
73
73
 
74
+ /** Whether a write of `symbol` is requested and not yet done. */
75
+ export function hasPendingTickerWrite(repository: object, symbol: string): boolean {
76
+ return repositories.get(repository)?.tails.has(tickerKey(symbol)) ?? false;
77
+ }
78
+
74
79
  /** Let save-await callers publish their edits before cleanup reads the current rows. */
75
80
  export async function settleTickerWrites(repository: object): Promise<void> {
76
81
  const writes = writesFor(repository);
package/src/i18n/es.ts CHANGED
@@ -1615,6 +1615,12 @@ export const es: Record<string, string> = {
1615
1615
  "TICKERS": "TICKERS",
1616
1616
  "Which tickers do you follow?": "¿Qué tickers sigues?",
1617
1617
  "Pick up to 3 for your watchlist.": "Elige hasta 3 para tu lista de seguimiento.",
1618
+ // "Where did you hear about Gloom?", once, after an account signs up
1619
+ "Where did you hear about Gloom?": "¿Dónde conociste Gloom?",
1620
+ "AI assistant": "Asistente de IA",
1621
+ "Friend or colleague": "Un amigo o colega",
1622
+ "Article or newsletter": "Un artículo o newsletter",
1623
+ "Where?": "¿Dónde?",
1618
1624
  "Skip": "Omitir",
1619
1625
  "Equities": "Renta variable",
1620
1626
  "Futures & commodities": "Futuros y materias primas",
@@ -1825,4 +1831,25 @@ export const es: Record<string, string> = {
1825
1831
  "pre": "pre",
1826
1832
  "post": "post",
1827
1833
  "closed": "cerrado",
1834
+ // ── Pro: the first weeks' row and the paid cancel ──────────
1835
+ "Try Pro on your tickers": "Prueba Pro con tus tickers",
1836
+ "Try Pro": "Prueba Pro",
1837
+ "Stop suggesting Pro functions": "Dejar de sugerir funciones Pro",
1838
+ "Open {command}": "Abrir {command}",
1839
+ "Options flow": "Flujo de opciones",
1840
+ "X mentions": "Menciones en X",
1841
+ "Hiring": "Contratación",
1842
+ "8-K events": "Eventos 8-K",
1843
+ "Risk factors": "Factores de riesgo",
1844
+ "Cancel Pro": "Cancelar Pro",
1845
+ "Cancel Pro?": "¿Cancelar Pro?",
1846
+ "Keep Pro": "Mantener Pro",
1847
+ "Pro until {date}": "Pro hasta el {date}",
1848
+ "Cancelling...": "Cancelando...",
1849
+ "Cancel Subscription": "Cancelar suscripción",
1850
+ "Keep My Subscription": "Mantener mi suscripción",
1851
+ "Continue Cancellation": "Continuar con la cancelación",
1852
+ "Pro stays on until {date}.": "Pro sigue activo hasta el {date}.",
1853
+ "Pro stays on until {date}. Cancelling now stops the renewal after that date.": "Pro sigue activo hasta el {date}. Si cancelas ahora, no se renovará después de esa fecha.",
1854
+ "Cancelled. Pro stays on until {date}.": "Cancelado. Pro sigue activo hasta el {date}.",
1828
1855
  };